Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | 1x 1x 1x 4x 1x 1x 1x 1x 1x 1x 709x 709x 709x 5x 2x 2x 3x 3x 165x 156x 156x 9x 7x 475x 474x 450x 24x 188x 7x 7x 7x 7x 41x 41x 21x 20x 36x 28x 1x 27x 607x 607x 4x 607x 634x 482x 152x 1x 1x | "use strict"; var __importStar = (this && this.__importStar) || function (mod) { Iif (mod && mod.__esModule) return mod; var result = {}; Eif (mod != null) for (var k in mod) Eif (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", { value: true }); /** * Copyright 2019 NEM * * Licensed under the BSD 2-Clause License (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://opensource.org/licenses/BSD-2-Clause * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ const bip32 = __importStar(require("bip32")); // internal dependencies const index_1 = require("../index"); const bs58check = require('bs58check'); /** * Class `ExtendedKey` describes a hierarchical deterministic extended * key that can be derived. This hierarchical deterministic child key * derivation feature is described in the Bitcoin BIP32 standard which * can be found at following URL: * * https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki * * This class *uses* features provided by the `bitcoinjs/bip32` package * and therefor is licensed under the BSD-2 Clause License as mentioned * [here](https://github.com/bitcoinjs/bip32/blob/master/LICENSE). * * @see https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki * @see https://github.com/bitcoinjs/bip32 * @see https://github.com/nemtech/NIP/issues/12 * @since 0.1.0 */ class ExtendedKey { /** * Construct an `ExtendedKey` object out of its' base58 payload. * * @see https://github.com/bitcoinjs/bip32/blob/master/ts-src/bip32.ts * @param node {BIP32} */ constructor(/** * The hyper-deterministic node. * @var {BIP32 | NodeEd25519} */ node, /** * The hyper-deterministic node network. * @var {Network} */ network, /** * The Message Authentication Code type to use. * Possible values include HMAC and KMAC. * @var {MACType} */ macType = index_1.MACType.HMAC) { this.node = node; this.network = network; this.macType = macType; } /** * Create an extended key hyper-deterministic node by its' Base58 * payload. * * This method uses the `bitcoinjs/bip32` function named `fromBase58` * and creates an extended key node by parsing the Base58 binary * representation. * * @param payload */ static createFromBase58(payload, network, macType = index_1.MACType.HMAC) { if (network === index_1.Network.SYMBOL) { // use NodeEd25519 node implementation // interpret payload const ed25519Node = index_1.NodeEd25519.fromBase58(payload, network); // instanciate our ExtendedKey return new ExtendedKey(ed25519Node, network, macType); } // else { // use BIP32 node implementation // interpret payload const bip32Node = bip32.fromBase58(payload); // instanciate our ExtendedKey return new ExtendedKey(bip32Node, network, macType); } /** * Create an extended key hyper-deterministic node with the master * seed. * * This method uses the `bitcoinjs/bip32` function named `fromSeed` * and creates an extended key node by creating HMAC-SHA512 hash * of the words 'Bitcoin seed' appended with the `seed` binary * representation. * * The result is split in 2 parts where the left most 32 bytes are * the private and right most 32 bytes are the public key. * * @see https://github.com/bitcoinjs/bip32/blob/master/src/bip32.js#L265 * @param seed {string} * @param network {Network} * @return {ExtendedKey} */ static createFromSeed(seed, network, macType = index_1.MACType.HMAC) { if (network === index_1.Network.SYMBOL) { // use NodeEd25519 node implementation // use hexadecimal seed const ed25519Node = index_1.NodeEd25519.fromSeed(Buffer.from(seed, 'hex'), network, macType); // instantiate our ExtendedKey return new ExtendedKey(ed25519Node, network, macType); } // else { // use BIP32 node implementation // use hexadecimal seed const bip32Node = bip32.fromSeed(Buffer.from(seed, 'hex')); // instanciate our ExtendedKey return new ExtendedKey(bip32Node, network, macType); } /** * Derive hyper-deterministic node by `path`. * * Default account layer should derive path `m/44'/43'/0'/0/0`. * * @see https://github.com/nemtech/NIP/issues/12 * @param path */ derivePath(path) { // derive path with specialized `derivePath` const derived = this.node.derivePath(path); if (derived instanceof index_1.NodeEd25519) { // use NodeEd25519 node implementation return new ExtendedKey(derived, this.network, this.macType); } // else { // use BIP32 node implementation return new ExtendedKey(derived, this.network, this.macType); } /** * Return whether an extended key node is neutered or not. * * Neutered = Public Key only * Not Neutered = Private Key available * * @return {boolean} */ isNeutered() { // forward to `bitcoinjs/bip32` return this.node.isNeutered(); } /** * Return whether the current `node` is a master key node or not. * * @return {boolean} */ isMaster() { // XXX read parentFingerprint instead of decode const base58 = this.node.toBase58(); const buffer = bs58check.decode(base58); const parent = buffer.readUInt32BE(5); return parent === 0x00000000; } /** * Get a neutered hyper-deterministic node. This corresponds to * a public key only extended key. * * From a neutered HD-node, users can only generate **public child * keys** and no **private child keys**. * * @see https://github.com/bitcoinjs/bip32/blob/master/ts-src/bip32.ts#L118 * @return {ExtendedKey} The neutered HD-node */ getPublicNode() { // create new node from neutered const node = this.node.neutered(); if (node instanceof index_1.NodeEd25519) { // use NodeEd25519 node implementation return new ExtendedKey(node, this.network, this.macType); } // else { // use BIP32 node implementation return new ExtendedKey(node, this.network, this.macType); } /** * This method proxies the conversion to base58 format * to the `bitcoinjs/bip32` library. * * @return {string} */ toBase58() { // forward to `bitcoinjs/bip32` return this.node.toBase58(); } /** * Get the private key of the HD-node. * * This method defaults to returning the hexadecimal notation of * the key. Use `KeyEncoding.ENC_BIN` if you need the binary form. * * @see {KeyEncoding} * @return {string} * @throws {Error} On use of this method with neutered extended keys (public keys). */ getPrivateKey(encoding = index_1.KeyEncoding.ENC_HEX) { if (this.isNeutered()) { throw new Error('Cannot read private key out of extended public key.'); } // return encoded private key (default hexadecimal format) return this.encodeAs(this.node.privateKey, encoding); } /** * Get the public key in hexadecimal notation. * * This method defaults to returning the hexadecimal notation of * the key. Use `KeyEncoding.ENC_BIN` if you need the binary form. * * @see {KeyEncoding} * @return {string} * @throws {Error} On use of this method with neutered extended keys (public keys). */ getPublicKey(encoding = index_1.KeyEncoding.ENC_HEX) { // @see https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki // ser-p(P) serializes the coordinate and prepends either 0x02 or 0x03 to it. // drop first byte for 32-bytes public key let publicKey = this.node.publicKey; if (this.node.publicKey.byteLength === 33) { publicKey = this.node.publicKey.slice(1); } // return encoded public key (default hexadecimal format) return this.encodeAs(publicKey, encoding); } /** * Encode a key into `encoding`. Default `encoding` is `KeyEncoding.ENC_HEX` * which results in a hexadecimal notation of the key. * * @param key * @param encoding */ encodeAs(key, encoding = index_1.KeyEncoding.ENC_HEX) { if (encoding === index_1.KeyEncoding.ENC_HEX) { // return hexadecimal notation return key.toString('hex'); } // return binary Buffer return key; } } exports.ExtendedKey = ExtendedKey; /** * Static property to define which type of * message authentication code must be used. * * @var {MACType} */ ExtendedKey.DEFAULT_MAC_TYPE = index_1.MACType.HMAC; |