This commit is contained in:
Nasa Nguyen
2019-12-30 16:20:00 +07:00
parent d0e4411234
commit bf46839a3d
6 changed files with 217 additions and 138 deletions

View File

@@ -1,6 +1,6 @@
## Create Genesis Block Proof with Node.js ## Create Genesis Block Proof of Work with Node.js
**Tested with Node.js version 8.x.x** **Tested with Node.js version 12.x.x**
## setup ## setup

View File

@@ -21,7 +21,7 @@ var defaults = {
locktime: 0 locktime: 0
} }
const argv = require('yargs') require('yargs')
.alias('t', 'time') .alias('t', 'time')
.alias('z', 'timestamp') .alias('z', 'timestamp')
.alias('n', 'nonce') .alias('n', 'nonce')
@@ -34,6 +34,7 @@ const argv = require('yargs')
.help() .help()
.command('*', 'create genesis block', () => { }, (argv) => { .command('*', 'create genesis block', () => { }, (argv) => {
// console.log(argv); // console.log(argv);
var options = Object.assign({}, defaults, argv); var options = Object.assign({}, defaults, argv);
// console.log(options); // console.log(options);
@@ -48,6 +49,7 @@ const argv = require('yargs')
console.log("merkle root hash: %s", $.reverseBuffer(merkle_root).toString('hex')); console.log("merkle root hash: %s", $.reverseBuffer(merkle_root).toString('hex'));
PoW(genesisblock, options); PoW(genesisblock, options);
//console.log("genesis block: %s", genesisblock.toString('hex')); //console.log("genesis block: %s", genesisblock.toString('hex'));
// console.log($.reverseBuffer(hash_merkle_root).toString('hex')); // console.log($.reverseBuffer(hash_merkle_root).toString('hex'));
@@ -69,6 +71,7 @@ function createOutputScript(options) {
function createTx(options) { function createTx(options) {
var input = createInputScript(options); var input = createInputScript(options);
var out = createOutputScript(options); var out = createOutputScript(options);
@@ -87,26 +90,32 @@ function createTx(options) {
var tx = Buffer.alloc(size); var tx = Buffer.alloc(size);
var position = 0; var position = 0;
tx.writeIntLE(1, position, true);
tx.writeIntLE(1, position += 4, true); tx.writeInt32LE(1, position);
tx.write(new Buffer(32).toString('hex'), position += 1, 32, 'hex'); tx.writeInt32LE(1, position += 4);
tx.writeInt32LE(0xFFFFFFFF, position += 32, true); tx.write(Buffer.alloc(32).toString('hex'), position += 1, 32, 'hex');
tx.writeIntLE(input.length, position += 4, true); //tx.writeInt32LE(0xFFFFFFFF, position += 32, 4);
tx.writeDoubleLE(0xFFFFFFFF, position += 32, 4);
tx.writeInt32LE(input.length, position += 4);
tx.write(input.toString('hex'), position += 1, input.length, "hex"); tx.write(input.toString('hex'), position += 1, input.length, "hex");
tx.writeInt32LE(0xFFFFFFFF, position += input.length, true); //tx.writeInt32LE(0xFFFFFFFF, position += input.length, 4);
tx.writeIntLE(1, position += 4); tx.writeDoubleLE(0xFFFFFFFF, position += input.length);
tx.writeInt32LE(1, position += 4);
tx.write(Buffer.from($.numToBytes(options.value)).toString('hex'), position += 1, 8, 'hex'); // 50 * coin tx.write(Buffer.from($.numToBytes(options.value)).toString('hex'), position += 1, 8, 'hex'); // 50 * coin
tx.writeInt32LE(0x43, position += 8); tx.writeInt32LE(0x43, position += 8);
//tx.write(input.toString('hex'), position += 1, input.length, "hex"); //tx.write(input.toString('hex'), position += 1, input.length, "hex");
tx.write(out.toString('hex'), position += 1, out.length, "hex"); tx.write(out.toString('hex'), position += 1, out.length, "hex");
tx.writeIntLE(options.locktime, position += out.length); tx.writeInt32LE(options.locktime, position += out.length);
// console.log(tx.toString('hex')); // console.log(tx.toString('hex'));
return tx; return tx;
}; };
@@ -115,8 +124,8 @@ function createBlock(merkleRoot, options) {
var block = Buffer.alloc(80); var block = Buffer.alloc(80);
var position = 0; var position = 0;
block.writeIntLE(1, position); //version block.writeInt32LE(1, position); //version
block.write(new Buffer(32).toString('hex'), position += 4, 32, 'hex'); //previousblockhash block.write(Buffer.alloc(32).toString('hex'), position += 4, 32, 'hex'); //previousblockhash
block.write(merkleRoot.toString('hex'), position += 32, 32, 'hex'); block.write(merkleRoot.toString('hex'), position += 32, 32, 'hex');
block.writeInt32LE(options.time, position += 32); block.writeInt32LE(options.time, position += 32);
//block.write(Buffer.from($.numToBytes(options.time)).toString('hex'), position += 32, 4, 'hex'); //block.write(Buffer.from($.numToBytes(options.time)).toString('hex'), position += 32, 4, 'hex');
@@ -124,7 +133,7 @@ function createBlock(merkleRoot, options) {
block.writeInt32LE(options.bits, position += 4); block.writeInt32LE(options.bits, position += 4);
//block.write(Buffer.from($.numToBytes(options.bits)).toString('hex'), position += 4, 4, 'hex'); //block.write(Buffer.from($.numToBytes(options.bits)).toString('hex'), position += 4, 4, 'hex');
block.writeIntLE(options.nonce, position += 4); block.writeInt32LE(options.nonce, position += 4);
return block; return block;

293
package-lock.json generated
View File

@@ -15,9 +15,12 @@
"integrity": "sha512-x247jIuy60/+FtMRvscqfxtVHQf8AGx2hm9c6btkgC0x/hp9yt+teISNhvF8WlwRkCc5yF2fDECH8SIMe8j+GA==" "integrity": "sha512-x247jIuy60/+FtMRvscqfxtVHQf8AGx2hm9c6btkgC0x/hp9yt+teISNhvF8WlwRkCc5yF2fDECH8SIMe8j+GA=="
}, },
"bindings": { "bindings": {
"version": "1.3.0", "version": "1.5.0",
"resolved": "https://registry.npmjs.org/bindings/-/bindings-1.3.0.tgz", "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz",
"integrity": "sha512-DpLh5EzMR2kzvX1KIlVC0VkC3iZtHKTgdtZ0a3pglBZdaQFjt5S9g9xd1lE+YvXyfd6mtCeRnrUfOLYiTMlNSw==" "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==",
"requires": {
"file-uri-to-path": "1.0.0"
}
}, },
"bn.js": { "bn.js": {
"version": "4.11.8", "version": "4.11.8",
@@ -29,7 +32,7 @@
"resolved": "https://registry.npmjs.org/bytebuffer/-/bytebuffer-5.0.1.tgz", "resolved": "https://registry.npmjs.org/bytebuffer/-/bytebuffer-5.0.1.tgz",
"integrity": "sha1-WC7qSxqHO20CCkjVjfhfC7ps/d0=", "integrity": "sha1-WC7qSxqHO20CCkjVjfhfC7ps/d0=",
"requires": { "requires": {
"long": "3.2.0" "long": "~3"
} }
}, },
"camelcase": { "camelcase": {
@@ -38,13 +41,13 @@
"integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=" "integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0="
}, },
"cliui": { "cliui": {
"version": "4.0.0", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/cliui/-/cliui-4.0.0.tgz", "resolved": "https://registry.npmjs.org/cliui/-/cliui-4.1.0.tgz",
"integrity": "sha512-nY3W5Gu2racvdDk//ELReY+dHjb9PlIcVDFXP72nVIhq2Gy3LuVXYwJoPVudwQnv1shtohpgkdCKT2YaKY0CKw==", "integrity": "sha512-4FG+RSG9DL7uEwRUZXZn3SS34DiDPfzP0VOiEwtUWlE+AR2EIg+hSyvrIgUUfhdgR/UkAeW2QHgeP+hWrXs7jQ==",
"requires": { "requires": {
"string-width": "2.1.1", "string-width": "^2.1.1",
"strip-ansi": "4.0.0", "strip-ansi": "^4.0.0",
"wrap-ansi": "2.1.0" "wrap-ansi": "^2.0.0"
} }
}, },
"code-point-at": { "code-point-at": {
@@ -53,13 +56,15 @@
"integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=" "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c="
}, },
"cross-spawn": { "cross-spawn": {
"version": "5.1.0", "version": "6.0.5",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz",
"integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=", "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==",
"requires": { "requires": {
"lru-cache": "4.1.2", "nice-try": "^1.0.4",
"shebang-command": "1.2.0", "path-key": "^2.0.1",
"which": "1.3.0" "semver": "^5.5.0",
"shebang-command": "^1.2.0",
"which": "^1.2.9"
} }
}, },
"crypto": { "crypto": {
@@ -72,42 +77,58 @@
"resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz",
"integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=" "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA="
}, },
"execa": { "end-of-stream": {
"version": "0.7.0", "version": "1.4.4",
"resolved": "https://registry.npmjs.org/execa/-/execa-0.7.0.tgz", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz",
"integrity": "sha1-lEvs00zEHuMqY6n68nrVpl/Fl3c=", "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==",
"requires": { "requires": {
"cross-spawn": "5.1.0", "once": "^1.4.0"
"get-stream": "3.0.0",
"is-stream": "1.1.0",
"npm-run-path": "2.0.2",
"p-finally": "1.0.0",
"signal-exit": "3.0.2",
"strip-eof": "1.0.0"
} }
}, },
"execa": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz",
"integrity": "sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA==",
"requires": {
"cross-spawn": "^6.0.0",
"get-stream": "^4.0.0",
"is-stream": "^1.1.0",
"npm-run-path": "^2.0.0",
"p-finally": "^1.0.0",
"signal-exit": "^3.0.0",
"strip-eof": "^1.0.0"
}
},
"file-uri-to-path": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
"integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw=="
},
"find-up": { "find-up": {
"version": "2.1.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz",
"integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=",
"requires": { "requires": {
"locate-path": "2.0.0" "locate-path": "^2.0.0"
} }
}, },
"get-caller-file": { "get-caller-file": {
"version": "1.0.2", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.2.tgz", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz",
"integrity": "sha1-9wLmMSfn4jHBYKgMFVSstw1QR+U=" "integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w=="
}, },
"get-stream": { "get-stream": {
"version": "3.0.0", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz",
"integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=" "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==",
"requires": {
"pump": "^3.0.0"
}
}, },
"invert-kv": { "invert-kv": {
"version": "1.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-1.0.0.tgz", "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-2.0.0.tgz",
"integrity": "sha1-EEqOSqym09jNFXqO+L+rLXo//bY=" "integrity": "sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA=="
}, },
"is-fullwidth-code-point": { "is-fullwidth-code-point": {
"version": "2.0.0", "version": "2.0.0",
@@ -125,11 +146,11 @@
"integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA="
}, },
"lcid": { "lcid": {
"version": "1.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/lcid/-/lcid-1.0.0.tgz", "resolved": "https://registry.npmjs.org/lcid/-/lcid-2.0.0.tgz",
"integrity": "sha1-MIrMr6C8SDo4Z7S28rlQYlHRuDU=", "integrity": "sha512-avPEb8P8EGnwXKClwsNUgryVjllcRqtMYa49NTsbQagYuT1DcXnl1915oxWjoyGrXR6zH/Y0Zc96xWsPcoDKeA==",
"requires": { "requires": {
"invert-kv": "1.0.0" "invert-kv": "^2.0.0"
} }
}, },
"locate-path": { "locate-path": {
@@ -137,8 +158,8 @@
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz",
"integrity": "sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=", "integrity": "sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=",
"requires": { "requires": {
"p-locate": "2.0.0", "p-locate": "^2.0.0",
"path-exists": "3.0.0" "path-exists": "^3.0.0"
} }
}, },
"long": { "long": {
@@ -146,50 +167,57 @@
"resolved": "https://registry.npmjs.org/long/-/long-3.2.0.tgz", "resolved": "https://registry.npmjs.org/long/-/long-3.2.0.tgz",
"integrity": "sha1-2CG3E4yhy1gcFymQ7xTbIAtcR0s=" "integrity": "sha1-2CG3E4yhy1gcFymQ7xTbIAtcR0s="
}, },
"lru-cache": { "map-age-cleaner": {
"version": "4.1.2", "version": "0.1.3",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.2.tgz", "resolved": "https://registry.npmjs.org/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz",
"integrity": "sha512-wgeVXhrDwAWnIF/yZARsFnMBtdFXOg1b8RIrhilp+0iDYN4mdQcNZElDZ0e4B64BhaxeQ5zN7PMyvu7we1kPeQ==", "integrity": "sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w==",
"requires": { "requires": {
"pseudomap": "1.0.2", "p-defer": "^1.0.0"
"yallist": "2.1.2"
} }
}, },
"mem": { "mem": {
"version": "1.1.0", "version": "4.3.0",
"resolved": "https://registry.npmjs.org/mem/-/mem-1.1.0.tgz", "resolved": "https://registry.npmjs.org/mem/-/mem-4.3.0.tgz",
"integrity": "sha1-Xt1StIXKHZAP5kiVUFOZoN+kX3Y=", "integrity": "sha512-qX2bG48pTqYRVmDB37rn/6PT7LcR8T7oAX3bf99u1Tt1nzxYfxkgqDwUwolPlXweM0XzBOBFzSx4kfp7KP1s/w==",
"requires": { "requires": {
"mimic-fn": "1.2.0" "map-age-cleaner": "^0.1.1",
"mimic-fn": "^2.0.0",
"p-is-promise": "^2.0.0"
} }
}, },
"mimic-fn": { "mimic-fn": {
"version": "1.2.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz",
"integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==" "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg=="
}, },
"multi-hashing": { "multi-hashing": {
"version": "git+https://github.com/nasa8x/node-multi-hashing.git#d04972dd1dfa014f18a6c032199bf7239ed98d5f", "version": "git+https://github.com/nasa8x/node-multi-hashing.git#25517b7c7896c9c2b5e342a4e0c835adb0b11951",
"from": "git+https://github.com/nasa8x/node-multi-hashing.git",
"requires": { "requires": {
"bignumber.js": "6.0.0", "bignumber.js": "^6.0.0",
"bindings": "1.3.0", "bindings": "^1.5.0",
"bn.js": "4.11.8", "bn.js": "^4.11.8",
"bytebuffer": "5.0.1", "bytebuffer": "^5.0.1",
"nan": "2.10.0", "nan": "^2.14.0",
"yargs": "11.0.0" "yargs": "^11.1.1"
} }
}, },
"nan": { "nan": {
"version": "2.10.0", "version": "2.14.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.10.0.tgz", "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz",
"integrity": "sha512-bAdJv7fBLhWC+/Bls0Oza+mvTaNQtP+1RyhhhvD95pgUJz6XM5IzgmxOkItJ9tkoCiplvAnXI1tNmmUD/eScyA==" "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg=="
},
"nice-try": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz",
"integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ=="
}, },
"npm-run-path": { "npm-run-path": {
"version": "2.0.2", "version": "2.0.2",
"resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz", "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz",
"integrity": "sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=", "integrity": "sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=",
"requires": { "requires": {
"path-key": "2.0.1" "path-key": "^2.0.0"
} }
}, },
"number-is-nan": { "number-is-nan": {
@@ -197,27 +225,45 @@
"resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz",
"integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0="
}, },
"os-locale": { "once": {
"version": "2.1.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/os-locale/-/os-locale-2.1.0.tgz", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha512-3sslG3zJbEYcaC4YVAvDorjGxc7tv6KVATnLPZONiljsUncvihe9BQoVCEs0RZ1kmf4Hk9OBqlZfJZWI4GanKA==", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"requires": { "requires": {
"execa": "0.7.0", "wrappy": "1"
"lcid": "1.0.0",
"mem": "1.1.0"
} }
}, },
"os-locale": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/os-locale/-/os-locale-3.1.0.tgz",
"integrity": "sha512-Z8l3R4wYWM40/52Z+S265okfFj8Kt2cC2MKY+xNi3kFs+XGI7WXu/I309QQQYbRW4ijiZ+yxs9pqEhJh0DqW3Q==",
"requires": {
"execa": "^1.0.0",
"lcid": "^2.0.0",
"mem": "^4.0.0"
}
},
"p-defer": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz",
"integrity": "sha1-n26xgvbJqozXQwBKfU+WsZaw+ww="
},
"p-finally": { "p-finally": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz",
"integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=" "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4="
}, },
"p-is-promise": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-2.1.0.tgz",
"integrity": "sha512-Y3W0wlRPK8ZMRbNq97l4M5otioeA5lm1z7bkNkxCka8HSPjR0xRWmpCmc9utiaLP9Jb1eD8BgeIxTW4AIF45Pg=="
},
"p-limit": { "p-limit": {
"version": "1.2.0", "version": "1.3.0",
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.2.0.tgz", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz",
"integrity": "sha512-Y/OtIaXtUPr4/YpMv1pCL5L5ed0rumAaAeBSj12F+bSlMdys7i8oQF/GUJmfpTS/QoaRrS/k6pma29haJpsMng==", "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==",
"requires": { "requires": {
"p-try": "1.0.0" "p-try": "^1.0.0"
} }
}, },
"p-locate": { "p-locate": {
@@ -225,7 +271,7 @@
"resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz",
"integrity": "sha1-IKAQOyIqcMj9OcwuWAaA893l7EM=", "integrity": "sha1-IKAQOyIqcMj9OcwuWAaA893l7EM=",
"requires": { "requires": {
"p-limit": "1.2.0" "p-limit": "^1.1.0"
} }
}, },
"p-try": { "p-try": {
@@ -243,10 +289,14 @@
"resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz",
"integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=" "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A="
}, },
"pseudomap": { "pump": {
"version": "1.0.2", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
"integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=" "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==",
"requires": {
"end-of-stream": "^1.1.0",
"once": "^1.3.1"
}
}, },
"require-directory": { "require-directory": {
"version": "2.1.1", "version": "2.1.1",
@@ -258,6 +308,11 @@
"resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-1.0.1.tgz", "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-1.0.1.tgz",
"integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=" "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE="
}, },
"semver": {
"version": "5.7.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz",
"integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ=="
},
"set-blocking": { "set-blocking": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
@@ -268,7 +323,7 @@
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz",
"integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=",
"requires": { "requires": {
"shebang-regex": "1.0.0" "shebang-regex": "^1.0.0"
} }
}, },
"shebang-regex": { "shebang-regex": {
@@ -286,8 +341,8 @@
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
"integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==",
"requires": { "requires": {
"is-fullwidth-code-point": "2.0.0", "is-fullwidth-code-point": "^2.0.0",
"strip-ansi": "4.0.0" "strip-ansi": "^4.0.0"
} }
}, },
"strip-ansi": { "strip-ansi": {
@@ -295,7 +350,7 @@
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz",
"integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=",
"requires": { "requires": {
"ansi-regex": "3.0.0" "ansi-regex": "^3.0.0"
} }
}, },
"strip-eof": { "strip-eof": {
@@ -304,11 +359,11 @@
"integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=" "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8="
}, },
"which": { "which": {
"version": "1.3.0", "version": "1.3.1",
"resolved": "https://registry.npmjs.org/which/-/which-1.3.0.tgz", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz",
"integrity": "sha512-xcJpopdamTuY5duC/KnTTNBraPK54YwpenP4lzxU8H91GudWpFv38u0CKjclE1Wi2EH2EDz5LRcHcKbCIzqGyg==", "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==",
"requires": { "requires": {
"isexe": "2.0.0" "isexe": "^2.0.0"
} }
}, },
"which-module": { "which-module": {
@@ -321,8 +376,8 @@
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz",
"integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=", "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=",
"requires": { "requires": {
"string-width": "1.0.2", "string-width": "^1.0.1",
"strip-ansi": "3.0.1" "strip-ansi": "^3.0.1"
}, },
"dependencies": { "dependencies": {
"ansi-regex": { "ansi-regex": {
@@ -335,7 +390,7 @@
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz",
"integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=",
"requires": { "requires": {
"number-is-nan": "1.0.1" "number-is-nan": "^1.0.0"
} }
}, },
"string-width": { "string-width": {
@@ -343,9 +398,9 @@
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
"integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
"requires": { "requires": {
"code-point-at": "1.1.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "1.0.0", "is-fullwidth-code-point": "^1.0.0",
"strip-ansi": "3.0.1" "strip-ansi": "^3.0.0"
} }
}, },
"strip-ansi": { "strip-ansi": {
@@ -353,38 +408,38 @@
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
"requires": { "requires": {
"ansi-regex": "2.1.1" "ansi-regex": "^2.0.0"
} }
} }
} }
}, },
"wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
},
"y18n": { "y18n": {
"version": "3.2.1", "version": "3.2.1",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.1.tgz", "resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.1.tgz",
"integrity": "sha1-bRX7qITAhnnA136I53WegR4H+kE=" "integrity": "sha1-bRX7qITAhnnA136I53WegR4H+kE="
}, },
"yallist": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz",
"integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI="
},
"yargs": { "yargs": {
"version": "11.0.0", "version": "11.1.1",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-11.0.0.tgz", "resolved": "https://registry.npmjs.org/yargs/-/yargs-11.1.1.tgz",
"integrity": "sha512-Rjp+lMYQOWtgqojx1dEWorjCofi1YN7AoFvYV7b1gx/7dAAeuI4kN5SZiEvr0ZmsZTOpDRcCqrpI10L31tFkBw==", "integrity": "sha512-PRU7gJrJaXv3q3yQZ/+/X6KBswZiaQ+zOmdprZcouPYtQgvNU35i+68M4b1ZHLZtYFT5QObFLV+ZkmJYcwKdiw==",
"requires": { "requires": {
"cliui": "4.0.0", "cliui": "^4.0.0",
"decamelize": "1.2.0", "decamelize": "^1.1.1",
"find-up": "2.1.0", "find-up": "^2.1.0",
"get-caller-file": "1.0.2", "get-caller-file": "^1.0.1",
"os-locale": "2.1.0", "os-locale": "^3.1.0",
"require-directory": "2.1.1", "require-directory": "^2.1.1",
"require-main-filename": "1.0.1", "require-main-filename": "^1.0.1",
"set-blocking": "2.0.0", "set-blocking": "^2.0.0",
"string-width": "2.1.1", "string-width": "^2.0.0",
"which-module": "2.0.0", "which-module": "^2.0.0",
"y18n": "3.2.1", "y18n": "^3.2.1",
"yargs-parser": "9.0.2" "yargs-parser": "^9.0.2"
} }
}, },
"yargs-parser": { "yargs-parser": {
@@ -392,7 +447,7 @@
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-9.0.2.tgz", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-9.0.2.tgz",
"integrity": "sha1-nM9qQ0YP5O1Aqbto9I1DuKaMwHc=", "integrity": "sha1-nM9qQ0YP5O1Aqbto9I1DuKaMwHc=",
"requires": { "requires": {
"camelcase": "4.1.0" "camelcase": "^4.1.0"
} }
} }
} }

View File

@@ -22,6 +22,6 @@
"dependencies": { "dependencies": {
"crypto": "^1.0.1", "crypto": "^1.0.1",
"multi-hashing": "git+https://github.com/nasa8x/node-multi-hashing.git", "multi-hashing": "git+https://github.com/nasa8x/node-multi-hashing.git",
"yargs": "^11.1.0" "yargs": "^11.1.1"
} }
} }

8
test.js Normal file
View File

@@ -0,0 +1,8 @@
var number = parseInt();
var buff = Buffer.alloc(8);
buff.writeDoubleLE(0xFFFFFFFF, 0);
console.log(buff);

View File

@@ -10,6 +10,12 @@ function swapHex(value) {
return s2; return s2;
} }
function intToHex(integer) {
let number = integer.toString(16).toUpperCase()
if( (number.length % 2) > 0 ) { number= "0" + number }
return number
}
function numToBytes(num, bytes) { function numToBytes(num, bytes) {
if (bytes === undefined) bytes = 8; if (bytes === undefined) bytes = 8;
if (bytes == 0) return []; if (bytes == 0) return [];
@@ -59,6 +65,7 @@ function reverseBuffer(buff) {
}; };
module.exports = { module.exports = {
intToHex,
swapHex, swapHex,
numToBytes, numToBytes,
numToVarInt, numToVarInt,