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 | 1x 1x 150x 150x 150x 4x 150x 2x 3x 1x 2x 140x 3x 1x 2x 2x 416x 416x 1x 1x | "use strict"; /** * 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. */ Object.defineProperty(exports, "__esModule", { value: true }); // internal dependencies const index_1 = require("../index"); /** * Class `Wallet` describes a hierarchical deterministic Wallet that * produces _Catapult-ED25519_-compatible accounts. * * This class provides with a bridge between BIP32-ED25519 compatible * key pairs and symbol ready private and public keys. * * @example Usage of hierarchical deterministic wallets * * ```typescript * const xkey = ExtendedKey.createFromSeed('000102030405060708090a0b0c0d0e0f'); * const wallet = new Wallet(xkey); * * // get master account * const masterAccount = wallet.getAccountPrivateKey(); * * // get DEFAULT WALLET * const defaultWallet = wallet.getChildAccountPrivateKey(); * * // derive specific child path * const childWallet = wallet.getChildAccountPrivateKey('m/44\'/4343\'/0\'/0\'/0\''); * ``` * * @see https://github.com/nemtech/NIP/issues/12 * @since 0.3.0 */ class Wallet { /** * Construct a `Wallet` object from an extended key. * * @param extendedKey {ExtendedKey} */ constructor(/** * The extended key. * @var {ExtendedKey} */ extendedKey) { this.extendedKey = extendedKey; /** * Whether the wallet is read-only or not. * @var {boolean} */ this.readOnly = false; // with an extended public key we have a read-only wallet if (extendedKey.isNeutered()) { this.readOnly = true; } this.publicKey = extendedKey.getPublicKey(index_1.KeyEncoding.ENC_BIN); } /** * Return whether the current wallet is read-only, or not. * * In case of an initialization with an extended *public* key, * the wallet is set to be read-only. * * @return {boolean} */ isReadOnly() { return this.readOnly; } /** * Get a symbol private key string with the extended * key property. * * No derivation is done in this step. Derivation must be done either before * calling this method or using the `getChildAccount` method. * * @return {string} main account private key. * @throws {Error} On call of this method with a read-only wallet. */ getAccountPrivateKey() { // in case of read-only wallet, not possible to initiate Account // only PublicAccount can be used, see getPublicAccount(). if (this.readOnly) { throw new Error('Missing private key, please use method getAccountPublicKey().'); } // note: do not store private key in memory longer than function call return this.extendedKey.getPrivateKey(index_1.KeyEncoding.ENC_HEX); } /** * Get a symbol public key string with the extended key property. * * No derivation is done in this step. Derivation must be done either before * calling this method or using the `getChildPublicAccount` method. * * @return {string} the account public key. */ getAccountPublicKey() { return this.publicKey.toString('hex'); } /** * Get a symbol private key string with the derived child account. * * In case no derivation path is provided, the default wallet path * will be used, see `Wallet.DEFAULT_WALLET_PATH`. * * @see Wallet.DEFAULT_WALLET_PATH * @param path {string} Child derivation path, default to `Wallet.DEFAULT_WALLET_PATH`. * @return {string} the private key * @throws {Error} On call of this method with a read-only wallet. */ getChildAccountPrivateKey(path = Wallet.DEFAULT_WALLET_PATH) { // in case of read-only wallet, get PublicAccount instance if (this.readOnly) { throw new Error('Missing private key, please use method getChildAccountPublicKey().'); } // child key derivation with `ExtendedKeyNode.derivePath()` const childKeyNode = this.extendedKey.derivePath(path); // non-read-only, get Account instance return childKeyNode.getPrivateKey(index_1.KeyEncoding.ENC_HEX); } /** * Get a symbol public key with the derived child account. * * In case no derivation path is provided, the default wallet path * will be used, see `Wallet.DEFAULT_WALLET_PATH`. * * @see Wallet.DEFAULT_WALLET_PATH * @param path {string} Child derivation path, default to `Wallet.DEFAULT_WALLET_PATH`. * @return string the child public key. */ getChildAccountPublicKey(path = Wallet.DEFAULT_WALLET_PATH) { // child key derivation with `ExtendedKeyNode.derivePath()` const childKeyNode = this.extendedKey.derivePath(path); return childKeyNode.getPublicKey(index_1.KeyEncoding.ENC_HEX); } } exports.Wallet = Wallet; /** * The default wallet derivaton path. * @var {string} */ Wallet.DEFAULT_WALLET_PATH = 'm/44\'/4343\'/0\'/0\'/0\''; |