How to use the @ethersproject/hdnode.defaultPath function in @ethersproject/hdnode

To help you get started, we’ve selected a few @ethersproject/hdnode examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ethers-io / ethers.js / packages / json-wallets / lib / keystore.js View on Github external
if (address_1.getAddress(check) !== address) {
                                        throw new Error("address mismatch");
                                    }
                                }
                                account = {
                                    _isKeystoreAccount: true,
                                    address: address,
                                    privateKey: bytes_1.hexlify(privateKey)
                                };
                                // Version 0.1 x-ethers metadata must contain an encrypted mnemonic phrase
                                if (utils_1.searchPath(data, "x-ethers/version") === "0.1") {
                                    mnemonicCiphertext = utils_1.looseArrayify(utils_1.searchPath(data, "x-ethers/mnemonicCiphertext"));
                                    mnemonicIv = utils_1.looseArrayify(utils_1.searchPath(data, "x-ethers/mnemonicCounter"));
                                    mnemonicCounter = new aes_js_1.default.Counter(mnemonicIv);
                                    mnemonicAesCtr = new aes_js_1.default.ModeOfOperation.ctr(mnemonicKey, mnemonicCounter);
                                    path = utils_1.searchPath(data, "x-ethers/path") || hdnode_1.defaultPath;
                                    entropy = bytes_1.arrayify(mnemonicAesCtr.decrypt(mnemonicCiphertext));
                                    mnemonic = hdnode_1.entropyToMnemonic(entropy);
                                    node = hdnode_1.HDNode.fromMnemonic(mnemonic).derivePath(path);
                                    if (node.privateKey != account.privateKey) {
                                        throw new Error("mnemonic mismatch");
                                    }
                                    account.mnemonic = node.mnemonic;
                                    account.path = node.path;
                                }
                                return [2 /*return*/, new KeystoreAccount(account)];
                            });
                        });
github ethers-io / ethers.js / packages / json-wallets / lib / keystore.js View on Github external
// the options are optional, so adjust the call as needed
    if (typeof (options) === "function" && !progressCallback) {
        progressCallback = options;
        options = {};
    }
    if (!options) {
        options = {};
    }
    var privateKey = bytes_1.arrayify(account.privateKey);
    var passwordBytes = utils_1.getPassword(password);
    var entropy = null;
    var path = account.path;
    if (account.mnemonic) {
        entropy = bytes_1.arrayify(hdnode_1.mnemonicToEntropy(account.mnemonic));
        if (!path) {
            path = hdnode_1.defaultPath;
        }
    }
    var client = options.client;
    if (!client) {
        client = "ethers.js";
    }
    // Check/generate the salt
    var salt = null;
    if (options.salt) {
        salt = bytes_1.arrayify(options.salt);
    }
    else {
        salt = random_1.randomBytes(32);
        ;
    }
    // Override initialization vector
github ethers-io / ethers.js / packages / json-wallets / lib / keystore.js View on Github external
function encrypt(account, password, options, progressCallback) {
    try {
        if (address_1.getAddress(account.address) !== transactions_1.computeAddress(account.privateKey)) {
            throw new Error("address/privateKey mismatch");
        }
        if (account.mnemonic != null) {
            var node = hdnode_1.HDNode.fromMnemonic(account.mnemonic).derivePath(account.path || hdnode_1.defaultPath);
            if (node.privateKey != account.privateKey) {
                throw new Error("mnemonic mismatch");
            }
        }
        else if (account.path != null) {
            throw new Error("cannot specify path without mnemonic");
        }
    }
    catch (e) {
        return Promise.reject(e);
    }
    // the options are optional, so adjust the call as needed
    if (typeof (options) === "function" && !progressCallback) {
        progressCallback = options;
        options = {};
    }
github ethers-io / ethers.js / packages / wallet / index.js View on Github external
Wallet.fromMnemonic = function (mnemonic, path, wordlist) {
        if (!path) {
            path = hdnode_1.defaultPath;
        }
        return new Wallet(hdnode_1.HDNode.fromMnemonic(mnemonic, null, wordlist).derivePath(path));
    };
    return Wallet;
github ethers-io / ethers.js / packages / wallet / index.js View on Github external
function Wallet(privateKey, provider) {
        var _newTarget = this.constructor;
        var _this = this;
        logger.checkNew(_newTarget, Wallet);
        _this = _super.call(this) || this;
        if (isAccount(privateKey)) {
            var signingKey_1 = new signing_key_1.SigningKey(privateKey.privateKey);
            properties_1.defineReadOnly(_this, "_signingKey", function () { return signingKey_1; });
            properties_1.defineReadOnly(_this, "address", transactions_1.computeAddress(_this.publicKey));
            if (_this.address !== address_1.getAddress(privateKey.address)) {
                logger.throwArgumentError("privateKey/address mismatch", "privateKey", "[REDCACTED]");
            }
            if (privateKey.mnemonic != null) {
                var mnemonic_1 = privateKey.mnemonic;
                var path = privateKey.path || hdnode_1.defaultPath;
                properties_1.defineReadOnly(_this, "_mnemonic", function () { return mnemonic_1; });
                properties_1.defineReadOnly(_this, "path", privateKey.path);
                var node = hdnode_1.HDNode.fromMnemonic(mnemonic_1).derivePath(path);
                if (transactions_1.computeAddress(node.privateKey) !== _this.address) {
                    logger.throwArgumentError("mnemonic/address mismatch", "privateKey", "[REDCACTED]");
                }
            }
            else {
                properties_1.defineReadOnly(_this, "_mnemonic", function () { return null; });
                properties_1.defineReadOnly(_this, "path", null);
            }
        }
        else {
            if (signing_key_1.SigningKey.isSigningKey(privateKey)) {
                if (privateKey.curve !== "secp256k1") {
                    logger.throwArgumentError("unsupported curve; must be secp256k1", "privateKey", "[REDACTED]");
github ethers-io / ethers.js / packages / ethers / utils.js View on Github external
exports.hexlify = bytes_1.hexlify;
exports.hexStripZeros = bytes_1.hexStripZeros;
exports.hexValue = bytes_1.hexValue;
exports.hexZeroPad = bytes_1.hexZeroPad;
exports.isHexString = bytes_1.isHexString;
exports.joinSignature = bytes_1.joinSignature;
exports.zeroPad = bytes_1.zeroPad;
exports.splitSignature = bytes_1.splitSignature;
exports.stripZeros = bytes_1.stripZeros;
var hash_1 = require("@ethersproject/hash");
exports.hashMessage = hash_1.hashMessage;
exports.id = hash_1.id;
exports.isValidName = hash_1.isValidName;
exports.namehash = hash_1.namehash;
var hdnode_1 = require("@ethersproject/hdnode");
exports.defaultPath = hdnode_1.defaultPath;
exports.entropyToMnemonic = hdnode_1.entropyToMnemonic;
exports.HDNode = hdnode_1.HDNode;
exports.isValidMnemonic = hdnode_1.isValidMnemonic;
exports.mnemonicToEntropy = hdnode_1.mnemonicToEntropy;
exports.mnemonicToSeed = hdnode_1.mnemonicToSeed;
var json_wallets_1 = require("@ethersproject/json-wallets");
exports.getJsonWalletAddress = json_wallets_1.getJsonWalletAddress;
var keccak256_1 = require("@ethersproject/keccak256");
exports.keccak256 = keccak256_1.keccak256;
var logger_1 = require("@ethersproject/logger");
exports.Logger = logger_1.Logger;
var sha2_1 = require("@ethersproject/sha2");
exports.sha256 = sha2_1.sha256;
var solidity_1 = require("@ethersproject/solidity");
exports.solidityKeccak256 = solidity_1.keccak256;
exports.solidityPack = solidity_1.pack;