All files / dist/src Network.js

100% Statements 9/9
75% Branches 3/4
100% Functions 2/2
100% Lines 9/9

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  1x                                           1x                                                                               11x 11x 11x                   2x         1x                 1x                   1x      
"use strict";
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.
 */
// internal dependencies
const index_1 = require("../index");
/**
 * Class `Network` describes an extended key prefix of 4 bytes. This object
 * is defined by `public` and `private` fields containing the unsigned
 * integer value of the prefix.
 *
 * For the BITCOIN protocol, the prefixes result to `xprv` and `xpub`
 * for the mainnet network.
 *
 * For the CATAPULT protocol, we will be using the same prefixes and
 * extended key sizes and formats.
 *
 * @see https://github.com/bitcoinjs/bip32/blob/master/src/bip32.js#L19
 * @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 Network {
    /**
     * Construct an `Network` object out of its' base58 payload.
     *
     * Result in Base58 notation to `xpub` and `xprv`.
     *
     * @param   base58Payload   {string}
     */
    constructor(/**
                 * Prefix for extended public key (4 bytes unsigned integer)
                 * @var {number}
                 */ publicKeyPrefix, 
    /**
     * Prefix for extended private key (4 bytes unsigned integer)
     * @var {number}
     */
    privateKeyPrefix, 
    /**
     * The ellyptic curve algorithm
     * @var {CurveAlgorithm}
     */
    curve = index_1.CurveAlgorithm.secp256k1) {
        this.publicKeyPrefix = publicKeyPrefix;
        this.privateKeyPrefix = privateKeyPrefix;
        this.curve = curve;
    }
    /**
     * Checks whether current network instance **is identical**
     * to given `b` network instance.
     *
     * @param   b       {Network}   The network object to compare against
     * @return  {boolean}   Returns whether the two objects are identical
     */
    equals(b) {
        return this.privateKeyPrefix === b.privateKeyPrefix
            && this.publicKeyPrefix === b.publicKeyPrefix
            && this.curve === b.curve;
    }
}
exports.Network = Network;
/**
 * BITCOIN protocol extended key prefixes
 *
 * Result in Base58 notation to `xpub` and `xprv`.
 *
 * @see https://github.com/bitcoinjs/bip32/blob/master/src/bip32.js#L19
 * @var {Network}
 */
Network.BITCOIN = new Network(0x0488b21e, // base58 'xpub'
0x0488ade4, // base58 'xprv'
index_1.CurveAlgorithm.secp256k1);
/**
 * SYMBOL public network protocol extended key prefixes
 *
 * Result in Base58 notation to `xpub` and `xprv`.
 *
 * @var {Network}
 */
Network.SYMBOL = new Network(0x0488b21e, // base58 'xpub'
0x0488ade4, // base58 'xprv'
index_1.CurveAlgorithm.ed25519);