├── .gitignore ├── README.md ├── genesis.js ├── package-lock.json ├── package.json ├── test.js └── utils.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | dist/* 4 | dist 5 | build 6 | .vscode 7 | *.log 8 | *.rar 9 | *.zip 10 | .svn/* 11 | obj/* 12 | *.bak 13 | config.js 14 | **/env/prod.js 15 | note.txt 16 | term.txt 17 | /coverage 18 | coverage.json 19 | temp -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Create Genesis Block Proof of Work with Node.js 2 | 3 | **Tested with Node.js version 12.x.x** 4 | 5 | ## setup 6 | 7 | ```js 8 | git clone https://github.com/nasa8x/node-genesis-block.git genesis-block 9 | cd genesis-block 10 | npm install 11 | ``` 12 | 13 | ## help 14 | 15 | ```js 16 | Options: 17 | -t TIME, --time=TIME the (unix) time when the genesisblock is created 18 | -z TIMESTAMP, --timestamp=TIMESTAMP 19 | the pszTimestamp found in the coinbase of the genesisblock 20 | -n NONCE, --nonce=NONCE 21 | the first value of the nonce that will be incremented 22 | when searching the genesis hash 23 | -a ALGORITHM, --algorithm=ALGORITHM 24 | the PoW algorithm: [x11|neoscrypt|quark|qubit|keccak|lyra2re] 25 | -p PUBKEY, --pubkey=PUBKEY 26 | the pubkey found in the output script 27 | -v VALUE, --value=VALUE 28 | the value in coins for the output, full value (exp. in bitcoin 5000000000 - To get other coins value: Block Value * 100000000) 29 | -b BITS, --bits=BITS 30 | the target in compact representation, associated to a difficulty of 1 31 | ``` 32 | 33 | 34 | ## algorithms 35 | ---------- 36 | * x11 37 | * x13 38 | * x15 39 | * x16r 40 | * nist5 41 | * neoscrypt 42 | * scrypt 43 | * keccak 44 | * quark 45 | * bcrypt 46 | * skein 47 | * groestl 48 | * groestlmyriad 49 | * blake 50 | * fugue 51 | * qubit 52 | * hefty1 53 | * shavite3 54 | * cryptonight 55 | * boolberry 56 | * yescrypt 57 | * fresh 58 | 59 | 60 | ## x11 61 | 62 | ```js 63 | node genesis -a x11 -z "Don't work for weekends, work for our goals - 18/Jan/2018." -p "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f" 64 | --------------- 65 | // result: 66 | algorithm: x11 67 | pzTimestamp: Don't work for weekends, work for our goals - 18/Jan/2018. 68 | pubkey: 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f 69 | bits: 504365040 70 | time: 1521537891 71 | merkle root hash: 77fc7d6cfbc4ec91703444a515955092d4b7c04dbb8f23be59deb42a39ec0057 72 | Searching for genesis hash... 73 | nonce: 1827816 74 | genesis hash: 0000084e98003628c45719136940cf7068805f4024419a51d6259fb676c299da 75 | 76 | ``` 77 | ## quark 78 | ```js 79 | node genesis -a quark 80 | --------------- 81 | // result: 82 | algorithm: quark 83 | pzTimestamp: Don't work for weekends, work for our goals. 84 | pubkey: 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f 85 | bits: 504365040 86 | time: 1521539113 87 | merkle root hash: f5239467dd2a9dd0fce7a3babc03c7985eab2229c62e3d5670375f305753c9cc 88 | Searching for genesis hash... 89 | nonce: 516895 90 | genesis hash: 00000a560e5488e24c7b2d83a7fd1d707321d57d0b8aa8164f35c5e67ed3a0f0 91 | ``` 92 | 93 | ## keccak 94 | ```js 95 | nasa8x$ node genesis -a keccak -t 1521538330 96 | --------------- 97 | algorithm: keccak 98 | pzTimestamp: Don't work for weekends, work for our goals. 99 | pubkey: 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f 100 | bits: 504365040 101 | time: 1521538330 102 | merkle root hash: f5239467dd2a9dd0fce7a3babc03c7985eab2229c62e3d5670375f305753c9cc 103 | Searching for genesis hash... 104 | nonce: 1509118 105 | genesis hash: 0000040fceaa8f6eda22f0caecc8c59a6ed82012e640d1c77348e3bf6c8d706f 106 | ``` 107 | 108 | ## donate 109 | [![](https://i.imgur.com/z0p6RvA.png)](http://vrl.to/ec5cfbae)[![](https://i.imgur.com/bEUNBGz.png)](http://vrl.to/ec5cfbae) -------------------------------------------------------------------------------- /genesis.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var $ = require("./utils"); 4 | var Hash = require('multi-hashing'); 5 | 6 | var defaults = { 7 | //the (unix) time when the genesisblock is created 8 | time: Math.round((new Date()).getTime() / 1000), 9 | //the pszTimestamp found in the coinbase of the genesisblock 10 | timestamp: "Don't work for weekends, work for our goals.", 11 | //the first value of the nonce that will be incremented when searching the genesis hash 12 | nonce: 1, 13 | //the PoW algorithm: [x11|x13|x15|geek|quark|keccak|qubit|neoscrypt|lyra2re...] 14 | algorithm: 'geek', 15 | //the pubkey found in the output script 16 | pubkey: '04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f', 17 | //the value in coins for the output, full value (exp. in bitcoin 5000000000 - To get other coins value: Block Value * 100000000) 18 | value: 5000000000, 19 | //the target in compact representation, associated to a difficulty of 1 20 | bits: 0x1e0ffff0, 21 | locktime: 0 22 | } 23 | 24 | require('yargs') 25 | .alias('t', 'time') 26 | .alias('z', 'timestamp') 27 | .alias('n', 'nonce') 28 | .alias('a', 'algorithm') 29 | .alias('p', 'pubkey') 30 | .alias('v', 'value') 31 | .alias('b', 'bits') 32 | .alias('l', 'locktime') 33 | .alias('h', 'help') 34 | .help() 35 | .command('*', 'create genesis block', () => { }, (argv) => { 36 | // console.log(argv); 37 | 38 | var options = Object.assign({}, defaults, argv); 39 | // console.log(options); 40 | 41 | var merkle_root = $.sha256d(createTx(options)); 42 | var genesisblock = createBlock(merkle_root, options); 43 | console.log("---------------"); 44 | console.log("algorithm: %s", options.algorithm); 45 | console.log("pzTimestamp: %s", options.timestamp); 46 | console.log("pubkey: %s", options.pubkey); 47 | console.log("bits: %s", options.bits); 48 | console.log("time: %s", options.time); 49 | console.log("merkle root hash: %s", $.reverseBuffer(merkle_root).toString('hex')); 50 | 51 | PoW(genesisblock, options); 52 | 53 | //console.log("genesis block: %s", genesisblock.toString('hex')); 54 | // console.log($.reverseBuffer(hash_merkle_root).toString('hex')); 55 | 56 | }) 57 | .argv; 58 | 59 | 60 | function createInputScript(options) { 61 | var tz = options.timestamp; 62 | var psz_prefix = tz.length > 76 ? '4c' : ''; 63 | var script_prefix = '04ffff001d0104' + psz_prefix + Buffer.from(String.fromCharCode(tz.length)).toString('hex'); 64 | return Buffer.from(script_prefix + Buffer.from(tz).toString('hex'), 'hex'); 65 | } 66 | 67 | function createOutputScript(options) { 68 | return Buffer.from('41' + options.pubkey + 'ac', 'hex'); 69 | } 70 | 71 | 72 | function createTx(options) { 73 | 74 | 75 | var input = createInputScript(options); 76 | var out = createOutputScript(options); 77 | 78 | var size = 4 // tx version 79 | + 1 // number of inputs 80 | + 32 // hash of previous output 81 | + 4 // previous output's index 82 | + 1 // 1 byte for the size of scriptSig 83 | + input.length 84 | + 4 // size of sequence 85 | + 1 // number of outputs 86 | + 8 // 8 bytes for coin value 87 | + 1 // 1 byte to represent size of the pubkey Script 88 | + out.length 89 | + 4; // 4 bytes for lock time 90 | 91 | 92 | var tx = Buffer.alloc(size); 93 | 94 | var position = 0; 95 | 96 | tx.writeInt32LE(1, position); 97 | tx.writeInt32LE(1, position += 4); 98 | tx.write(Buffer.alloc(32).toString('hex'), position += 1, 32, 'hex'); 99 | //tx.writeInt32LE(0xFFFFFFFF, position += 32, 4); 100 | tx.writeDoubleLE(0xFFFFFFFF, position += 32, 4); 101 | tx.writeInt32LE(input.length, position += 4); 102 | tx.write(input.toString('hex'), position += 1, input.length, "hex"); 103 | //tx.writeInt32LE(0xFFFFFFFF, position += input.length, 4); 104 | tx.writeDoubleLE(0xFFFFFFFF, position += input.length); 105 | tx.writeInt32LE(1, position += 4); 106 | tx.write(Buffer.from($.numToBytes(options.value)).toString('hex'), position += 1, 8, 'hex'); // 50 * coin 107 | tx.writeInt32LE(0x43, position += 8); 108 | //tx.write(input.toString('hex'), position += 1, input.length, "hex"); 109 | tx.write(out.toString('hex'), position += 1, out.length, "hex"); 110 | tx.writeInt32LE(options.locktime, position += out.length); 111 | 112 | 113 | // console.log(tx.toString('hex')); 114 | 115 | return tx; 116 | 117 | 118 | 119 | }; 120 | 121 | 122 | function createBlock(merkleRoot, options) { 123 | 124 | var block = Buffer.alloc(80); 125 | var position = 0; 126 | 127 | block.writeInt32LE(1, position); //version 128 | block.write(Buffer.alloc(32).toString('hex'), position += 4, 32, 'hex'); //previousblockhash 129 | block.write(merkleRoot.toString('hex'), position += 32, 32, 'hex'); 130 | block.writeInt32LE(options.time, position += 32); 131 | //block.write(Buffer.from($.numToBytes(options.time)).toString('hex'), position += 32, 4, 'hex'); 132 | 133 | block.writeInt32LE(options.bits, position += 4); 134 | //block.write(Buffer.from($.numToBytes(options.bits)).toString('hex'), position += 4, 4, 'hex'); 135 | 136 | block.writeInt32LE(options.nonce, position += 4); 137 | 138 | return block; 139 | 140 | }; 141 | 142 | function PoW(data, options) { 143 | 144 | console.log('Searching for genesis hash...'); 145 | var nonce = options.nonce; 146 | 147 | //var target = $.numToBytes((options.bits & 0xffffff) * 2 ** (8 * ((options.bits >> 24) - 3))); 148 | // console.log('' + target.toString('hex')); 149 | 150 | while (true) { 151 | 152 | var hash = $.reverseBuffer(Hash[options.algorithm](data)).toString('hex'); 153 | // var hash2 = $.reverseBuffer(hash).toString('hex'); 154 | // var val = parseInt(hash2, 16); 155 | 156 | if (hash.match(/^00000/)) { 157 | console.log("nonce: %s", nonce); 158 | console.log("genesis hash: %s", hash); 159 | return; 160 | } else { 161 | 162 | nonce += 1; 163 | // if (nonce % 2000 == 0) { 164 | // console.log("nonce: %s | hash: %s ", nonce, hash.toString('hex')); 165 | // } 166 | data.writeInt32LE(nonce, data.length - 4); 167 | } 168 | 169 | } 170 | 171 | } -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "genesis-block", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "ansi-regex": { 8 | "version": "3.0.0", 9 | "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", 10 | "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=" 11 | }, 12 | "bignumber.js": { 13 | "version": "6.0.0", 14 | "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-6.0.0.tgz", 15 | "integrity": "sha512-x247jIuy60/+FtMRvscqfxtVHQf8AGx2hm9c6btkgC0x/hp9yt+teISNhvF8WlwRkCc5yF2fDECH8SIMe8j+GA==" 16 | }, 17 | "bindings": { 18 | "version": "1.5.0", 19 | "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", 20 | "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", 21 | "requires": { 22 | "file-uri-to-path": "1.0.0" 23 | } 24 | }, 25 | "bn.js": { 26 | "version": "4.11.8", 27 | "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz", 28 | "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==" 29 | }, 30 | "bytebuffer": { 31 | "version": "5.0.1", 32 | "resolved": "https://registry.npmjs.org/bytebuffer/-/bytebuffer-5.0.1.tgz", 33 | "integrity": "sha1-WC7qSxqHO20CCkjVjfhfC7ps/d0=", 34 | "requires": { 35 | "long": "~3" 36 | } 37 | }, 38 | "camelcase": { 39 | "version": "4.1.0", 40 | "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-4.1.0.tgz", 41 | "integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=" 42 | }, 43 | "cliui": { 44 | "version": "4.1.0", 45 | "resolved": "https://registry.npmjs.org/cliui/-/cliui-4.1.0.tgz", 46 | "integrity": "sha512-4FG+RSG9DL7uEwRUZXZn3SS34DiDPfzP0VOiEwtUWlE+AR2EIg+hSyvrIgUUfhdgR/UkAeW2QHgeP+hWrXs7jQ==", 47 | "requires": { 48 | "string-width": "^2.1.1", 49 | "strip-ansi": "^4.0.0", 50 | "wrap-ansi": "^2.0.0" 51 | } 52 | }, 53 | "code-point-at": { 54 | "version": "1.1.0", 55 | "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", 56 | "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=" 57 | }, 58 | "cross-spawn": { 59 | "version": "6.0.5", 60 | "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", 61 | "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", 62 | "requires": { 63 | "nice-try": "^1.0.4", 64 | "path-key": "^2.0.1", 65 | "semver": "^5.5.0", 66 | "shebang-command": "^1.2.0", 67 | "which": "^1.2.9" 68 | } 69 | }, 70 | "crypto": { 71 | "version": "1.0.1", 72 | "resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz", 73 | "integrity": "sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig==" 74 | }, 75 | "decamelize": { 76 | "version": "1.2.0", 77 | "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", 78 | "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=" 79 | }, 80 | "end-of-stream": { 81 | "version": "1.4.4", 82 | "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", 83 | "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", 84 | "requires": { 85 | "once": "^1.4.0" 86 | } 87 | }, 88 | "execa": { 89 | "version": "1.0.0", 90 | "resolved": "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz", 91 | "integrity": "sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA==", 92 | "requires": { 93 | "cross-spawn": "^6.0.0", 94 | "get-stream": "^4.0.0", 95 | "is-stream": "^1.1.0", 96 | "npm-run-path": "^2.0.0", 97 | "p-finally": "^1.0.0", 98 | "signal-exit": "^3.0.0", 99 | "strip-eof": "^1.0.0" 100 | } 101 | }, 102 | "file-uri-to-path": { 103 | "version": "1.0.0", 104 | "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", 105 | "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==" 106 | }, 107 | "find-up": { 108 | "version": "2.1.0", 109 | "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", 110 | "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", 111 | "requires": { 112 | "locate-path": "^2.0.0" 113 | } 114 | }, 115 | "get-caller-file": { 116 | "version": "1.0.3", 117 | "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz", 118 | "integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==" 119 | }, 120 | "get-stream": { 121 | "version": "4.1.0", 122 | "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", 123 | "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==", 124 | "requires": { 125 | "pump": "^3.0.0" 126 | } 127 | }, 128 | "invert-kv": { 129 | "version": "2.0.0", 130 | "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-2.0.0.tgz", 131 | "integrity": "sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA==" 132 | }, 133 | "is-fullwidth-code-point": { 134 | "version": "2.0.0", 135 | "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", 136 | "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=" 137 | }, 138 | "is-stream": { 139 | "version": "1.1.0", 140 | "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", 141 | "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" 142 | }, 143 | "isexe": { 144 | "version": "2.0.0", 145 | "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", 146 | "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" 147 | }, 148 | "lcid": { 149 | "version": "2.0.0", 150 | "resolved": "https://registry.npmjs.org/lcid/-/lcid-2.0.0.tgz", 151 | "integrity": "sha512-avPEb8P8EGnwXKClwsNUgryVjllcRqtMYa49NTsbQagYuT1DcXnl1915oxWjoyGrXR6zH/Y0Zc96xWsPcoDKeA==", 152 | "requires": { 153 | "invert-kv": "^2.0.0" 154 | } 155 | }, 156 | "locate-path": { 157 | "version": "2.0.0", 158 | "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", 159 | "integrity": "sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=", 160 | "requires": { 161 | "p-locate": "^2.0.0", 162 | "path-exists": "^3.0.0" 163 | } 164 | }, 165 | "long": { 166 | "version": "3.2.0", 167 | "resolved": "https://registry.npmjs.org/long/-/long-3.2.0.tgz", 168 | "integrity": "sha1-2CG3E4yhy1gcFymQ7xTbIAtcR0s=" 169 | }, 170 | "map-age-cleaner": { 171 | "version": "0.1.3", 172 | "resolved": "https://registry.npmjs.org/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz", 173 | "integrity": "sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w==", 174 | "requires": { 175 | "p-defer": "^1.0.0" 176 | } 177 | }, 178 | "mem": { 179 | "version": "4.3.0", 180 | "resolved": "https://registry.npmjs.org/mem/-/mem-4.3.0.tgz", 181 | "integrity": "sha512-qX2bG48pTqYRVmDB37rn/6PT7LcR8T7oAX3bf99u1Tt1nzxYfxkgqDwUwolPlXweM0XzBOBFzSx4kfp7KP1s/w==", 182 | "requires": { 183 | "map-age-cleaner": "^0.1.1", 184 | "mimic-fn": "^2.0.0", 185 | "p-is-promise": "^2.0.0" 186 | } 187 | }, 188 | "mimic-fn": { 189 | "version": "2.1.0", 190 | "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", 191 | "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==" 192 | }, 193 | "multi-hashing": { 194 | "version": "git+https://github.com/nasa8x/node-multi-hashing.git#25517b7c7896c9c2b5e342a4e0c835adb0b11951", 195 | "from": "git+https://github.com/nasa8x/node-multi-hashing.git", 196 | "requires": { 197 | "bignumber.js": "^6.0.0", 198 | "bindings": "^1.5.0", 199 | "bn.js": "^4.11.8", 200 | "bytebuffer": "^5.0.1", 201 | "nan": "^2.14.0", 202 | "yargs": "^11.1.1" 203 | } 204 | }, 205 | "nan": { 206 | "version": "2.14.0", 207 | "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz", 208 | "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==" 209 | }, 210 | "nice-try": { 211 | "version": "1.0.5", 212 | "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", 213 | "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==" 214 | }, 215 | "npm-run-path": { 216 | "version": "2.0.2", 217 | "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz", 218 | "integrity": "sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=", 219 | "requires": { 220 | "path-key": "^2.0.0" 221 | } 222 | }, 223 | "number-is-nan": { 224 | "version": "1.0.1", 225 | "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", 226 | "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" 227 | }, 228 | "once": { 229 | "version": "1.4.0", 230 | "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", 231 | "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", 232 | "requires": { 233 | "wrappy": "1" 234 | } 235 | }, 236 | "os-locale": { 237 | "version": "3.1.0", 238 | "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-3.1.0.tgz", 239 | "integrity": "sha512-Z8l3R4wYWM40/52Z+S265okfFj8Kt2cC2MKY+xNi3kFs+XGI7WXu/I309QQQYbRW4ijiZ+yxs9pqEhJh0DqW3Q==", 240 | "requires": { 241 | "execa": "^1.0.0", 242 | "lcid": "^2.0.0", 243 | "mem": "^4.0.0" 244 | } 245 | }, 246 | "p-defer": { 247 | "version": "1.0.0", 248 | "resolved": "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz", 249 | "integrity": "sha1-n26xgvbJqozXQwBKfU+WsZaw+ww=" 250 | }, 251 | "p-finally": { 252 | "version": "1.0.0", 253 | "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", 254 | "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=" 255 | }, 256 | "p-is-promise": { 257 | "version": "2.1.0", 258 | "resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-2.1.0.tgz", 259 | "integrity": "sha512-Y3W0wlRPK8ZMRbNq97l4M5otioeA5lm1z7bkNkxCka8HSPjR0xRWmpCmc9utiaLP9Jb1eD8BgeIxTW4AIF45Pg==" 260 | }, 261 | "p-limit": { 262 | "version": "1.3.0", 263 | "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", 264 | "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==", 265 | "requires": { 266 | "p-try": "^1.0.0" 267 | } 268 | }, 269 | "p-locate": { 270 | "version": "2.0.0", 271 | "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", 272 | "integrity": "sha1-IKAQOyIqcMj9OcwuWAaA893l7EM=", 273 | "requires": { 274 | "p-limit": "^1.1.0" 275 | } 276 | }, 277 | "p-try": { 278 | "version": "1.0.0", 279 | "resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz", 280 | "integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=" 281 | }, 282 | "path-exists": { 283 | "version": "3.0.0", 284 | "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", 285 | "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=" 286 | }, 287 | "path-key": { 288 | "version": "2.0.1", 289 | "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", 290 | "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=" 291 | }, 292 | "pump": { 293 | "version": "3.0.0", 294 | "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", 295 | "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", 296 | "requires": { 297 | "end-of-stream": "^1.1.0", 298 | "once": "^1.3.1" 299 | } 300 | }, 301 | "require-directory": { 302 | "version": "2.1.1", 303 | "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", 304 | "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=" 305 | }, 306 | "require-main-filename": { 307 | "version": "1.0.1", 308 | "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-1.0.1.tgz", 309 | "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=" 310 | }, 311 | "semver": { 312 | "version": "5.7.1", 313 | "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", 314 | "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" 315 | }, 316 | "set-blocking": { 317 | "version": "2.0.0", 318 | "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", 319 | "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=" 320 | }, 321 | "shebang-command": { 322 | "version": "1.2.0", 323 | "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", 324 | "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", 325 | "requires": { 326 | "shebang-regex": "^1.0.0" 327 | } 328 | }, 329 | "shebang-regex": { 330 | "version": "1.0.0", 331 | "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", 332 | "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=" 333 | }, 334 | "signal-exit": { 335 | "version": "3.0.2", 336 | "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", 337 | "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=" 338 | }, 339 | "string-width": { 340 | "version": "2.1.1", 341 | "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", 342 | "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", 343 | "requires": { 344 | "is-fullwidth-code-point": "^2.0.0", 345 | "strip-ansi": "^4.0.0" 346 | } 347 | }, 348 | "strip-ansi": { 349 | "version": "4.0.0", 350 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", 351 | "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", 352 | "requires": { 353 | "ansi-regex": "^3.0.0" 354 | } 355 | }, 356 | "strip-eof": { 357 | "version": "1.0.0", 358 | "resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", 359 | "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=" 360 | }, 361 | "which": { 362 | "version": "1.3.1", 363 | "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", 364 | "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", 365 | "requires": { 366 | "isexe": "^2.0.0" 367 | } 368 | }, 369 | "which-module": { 370 | "version": "2.0.0", 371 | "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", 372 | "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=" 373 | }, 374 | "wrap-ansi": { 375 | "version": "2.1.0", 376 | "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", 377 | "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=", 378 | "requires": { 379 | "string-width": "^1.0.1", 380 | "strip-ansi": "^3.0.1" 381 | }, 382 | "dependencies": { 383 | "ansi-regex": { 384 | "version": "2.1.1", 385 | "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", 386 | "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" 387 | }, 388 | "is-fullwidth-code-point": { 389 | "version": "1.0.0", 390 | "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", 391 | "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", 392 | "requires": { 393 | "number-is-nan": "^1.0.0" 394 | } 395 | }, 396 | "string-width": { 397 | "version": "1.0.2", 398 | "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", 399 | "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", 400 | "requires": { 401 | "code-point-at": "^1.0.0", 402 | "is-fullwidth-code-point": "^1.0.0", 403 | "strip-ansi": "^3.0.0" 404 | } 405 | }, 406 | "strip-ansi": { 407 | "version": "3.0.1", 408 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", 409 | "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", 410 | "requires": { 411 | "ansi-regex": "^2.0.0" 412 | } 413 | } 414 | } 415 | }, 416 | "wrappy": { 417 | "version": "1.0.2", 418 | "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", 419 | "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" 420 | }, 421 | "y18n": { 422 | "version": "3.2.1", 423 | "resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.1.tgz", 424 | "integrity": "sha1-bRX7qITAhnnA136I53WegR4H+kE=" 425 | }, 426 | "yargs": { 427 | "version": "11.1.1", 428 | "resolved": "https://registry.npmjs.org/yargs/-/yargs-11.1.1.tgz", 429 | "integrity": "sha512-PRU7gJrJaXv3q3yQZ/+/X6KBswZiaQ+zOmdprZcouPYtQgvNU35i+68M4b1ZHLZtYFT5QObFLV+ZkmJYcwKdiw==", 430 | "requires": { 431 | "cliui": "^4.0.0", 432 | "decamelize": "^1.1.1", 433 | "find-up": "^2.1.0", 434 | "get-caller-file": "^1.0.1", 435 | "os-locale": "^3.1.0", 436 | "require-directory": "^2.1.1", 437 | "require-main-filename": "^1.0.1", 438 | "set-blocking": "^2.0.0", 439 | "string-width": "^2.0.0", 440 | "which-module": "^2.0.0", 441 | "y18n": "^3.2.1", 442 | "yargs-parser": "^9.0.2" 443 | } 444 | }, 445 | "yargs-parser": { 446 | "version": "9.0.2", 447 | "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-9.0.2.tgz", 448 | "integrity": "sha1-nM9qQ0YP5O1Aqbto9I1DuKaMwHc=", 449 | "requires": { 450 | "camelcase": "^4.1.0" 451 | } 452 | } 453 | } 454 | } 455 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "genesis-block", 3 | "version": "1.0.0", 4 | "description": "Create Genesis Block Proof of Work for Bitcoin, Dash, Litecoin, Zcash...", 5 | "main": "genesis.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/nasa8x/node-genesis-block.git" 12 | }, 13 | "keywords": [ 14 | "genesisblock" 15 | ], 16 | "author": "Nasa8x", 17 | "license": "MIT", 18 | "bugs": { 19 | "url": "https://github.com/nasa8x/node-genesis-block/issues" 20 | }, 21 | "homepage": "https://github.com/nasa8x/node-genesis-block#readme", 22 | "dependencies": { 23 | "crypto": "^1.0.1", 24 | "multi-hashing": "git+https://github.com/nasa8x/node-multi-hashing.git", 25 | "yargs": "^11.1.1" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var number = parseInt(); 4 | 5 | 6 | var buff = Buffer.alloc(8); 7 | buff.writeDoubleLE(0xFFFFFFFF, 0); 8 | console.log(buff); -------------------------------------------------------------------------------- /utils.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var crypto = require('crypto'); 3 | 4 | function swapHex(value) { 5 | let s = value.toString(16); 6 | s = s.replace(/^(.(..)*)$/, "0$1"); 7 | var a = s.match(/../g); 8 | a.reverse(); 9 | var s2 = a.join(""); 10 | return s2; 11 | } 12 | 13 | function intToHex(integer) { 14 | let number = integer.toString(16).toUpperCase() 15 | if( (number.length % 2) > 0 ) { number= "0" + number } 16 | return number 17 | } 18 | 19 | function numToBytes(num, bytes) { 20 | if (bytes === undefined) bytes = 8; 21 | if (bytes == 0) return []; 22 | else return [num % 256].concat(numToBytes(Math.floor(num / 256), bytes - 1)); 23 | } 24 | 25 | function numToVarInt(num) { 26 | if (num < 253) return [num]; 27 | else if (num < 65536) return [253].concat(numToBytes(num, 2)); 28 | else if (num < 4294967296) return [254].concat(numToBytes(num, 4)); 29 | else return [253].concat(numToBytes(num, 8)); 30 | } 31 | 32 | function hexToBytes(hex) { 33 | for (var bytes = [], c = 0; c < hex.length; c += 2) 34 | bytes.push(parseInt(hex.substr(c, 2), 16)); 35 | return bytes; 36 | } 37 | 38 | function bytesToHex(bytes) { 39 | for (var hex = [], i = 0; i < bytes.length; i++) { 40 | hex.push((bytes[i] >>> 4).toString(16)); 41 | hex.push((bytes[i] & 0xf).toString(16)); 42 | } 43 | return hex.join(""); 44 | } 45 | function bytesLen(num) { 46 | return Math.ceil(num.toString(2).length / 8); 47 | } 48 | 49 | 50 | function sha256(buffer) { 51 | var hash1 = crypto.createHash('sha256'); 52 | hash1.update(buffer); 53 | return hash1.digest(); 54 | }; 55 | 56 | function sha256d(buffer) { 57 | return sha256(sha256(buffer)); 58 | }; 59 | 60 | function reverseBuffer(buff) { 61 | var reversed = Buffer.alloc(buff.length); 62 | for (var i = buff.length - 1; i >= 0; i--) 63 | reversed[buff.length - i - 1] = buff[i]; 64 | return reversed; 65 | }; 66 | 67 | module.exports = { 68 | intToHex, 69 | swapHex, 70 | numToBytes, 71 | numToVarInt, 72 | hexToBytes, 73 | bytesToHex, 74 | bytesLen, 75 | sha256, 76 | sha256d, 77 | reverseBuffer 78 | }; --------------------------------------------------------------------------------