How to use the @ethersproject/hdnode.entropyToMnemonic 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
}
                                }
                                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 / src.ts / keystore.ts View on Github external
address: address,
            privateKey: hexlify(privateKey)
        };

        // Version 0.1 x-ethers metadata must contain an encrypted mnemonic phrase
        if (searchPath(data, "x-ethers/version") === "0.1") {
            const mnemonicCiphertext = looseArrayify(searchPath(data, "x-ethers/mnemonicCiphertext"));
            const mnemonicIv = looseArrayify(searchPath(data, "x-ethers/mnemonicCounter"));

            const mnemonicCounter = new aes.Counter(mnemonicIv);
            const mnemonicAesCtr = new aes.ModeOfOperation.ctr(mnemonicKey, mnemonicCounter);

            const path = searchPath(data, "x-ethers/path") || defaultPath;

            const entropy = arrayify(mnemonicAesCtr.decrypt(mnemonicCiphertext));
            const mnemonic = entropyToMnemonic(entropy);

            const node = HDNode.fromMnemonic(mnemonic).derivePath(path);

            if (node.privateKey != account.privateKey) {
                throw new Error("mnemonic mismatch");
            }

            account.mnemonic = node.mnemonic;
            account.path = node.path;
        }

        return new KeystoreAccount(account);
    }
github ethers-io / ethers.js / packages / json-wallets / lib.esm / keystore.js View on Github external
}
                }
                const account = {
                    _isKeystoreAccount: true,
                    address: address,
                    privateKey: hexlify(privateKey)
                };
                // Version 0.1 x-ethers metadata must contain an encrypted mnemonic phrase
                if (searchPath(data, "x-ethers/version") === "0.1") {
                    const mnemonicCiphertext = looseArrayify(searchPath(data, "x-ethers/mnemonicCiphertext"));
                    const mnemonicIv = looseArrayify(searchPath(data, "x-ethers/mnemonicCounter"));
                    const mnemonicCounter = new aes.Counter(mnemonicIv);
                    const mnemonicAesCtr = new aes.ModeOfOperation.ctr(mnemonicKey, mnemonicCounter);
                    const path = searchPath(data, "x-ethers/path") || defaultPath;
                    const entropy = arrayify(mnemonicAesCtr.decrypt(mnemonicCiphertext));
                    const mnemonic = entropyToMnemonic(entropy);
                    const node = HDNode.fromMnemonic(mnemonic).derivePath(path);
                    if (node.privateKey != account.privateKey) {
                        throw new Error("mnemonic mismatch");
                    }
                    account.mnemonic = node.mnemonic;
                    account.path = node.path;
                }
                return new KeystoreAccount(account);
            });
        };
github 3box / 3box-js / src / 3id / index.js View on Github external
return new ThreeId(provider, ipfs, opts)
    } else {
      const normalizedAddress = address.toLowerCase()
      let serialized3id = localstorage.get(STORAGE_KEY + normalizedAddress)
      if (serialized3id) {
        if (opts.consentCallback) opts.consentCallback(false)
      } else {
        let sig
        if (opts.contentSignature) {
          sig = opts.contentSignature
        } else {
          sig = await utils.openBoxConsent(normalizedAddress, provider)
        }
        if (opts.consentCallback) opts.consentCallback(true)
        const entropy = '0x' + utils.sha256(sig.slice(2))
        const mnemonic = entropyToMnemonic(entropy)
        const seed = mnemonicToSeed(mnemonic)
        serialized3id = JSON.stringify({
          managementAddress: normalizedAddress,
          seed,
          spaceSeeds: {}
        })
      }
      const threeId = new ThreeId(provider, ipfs, opts)
      threeId._initKeys(serialized3id)
      await threeId._initDID()
      return threeId
    }
  }
}
github ethers-io / ethers.js / packages / wallet / src.ts / index.ts View on Github external
static createRandom(options?: any): Wallet {
        let entropy: Uint8Array = randomBytes(16);

        if (!options) { options = { }; }

        if (options.extraEntropy) {
            entropy = arrayify(hexDataSlice(keccak256(concat([ entropy, options.extraEntropy ])), 0, 16));
        }

        const mnemonic = entropyToMnemonic(entropy, options.locale);
        return Wallet.fromMnemonic(mnemonic, options.path, options.locale);
    }
github ethers-io / ethers.js / packages / wallet / lib.esm / index.js View on Github external
static createRandom(options) {
        let entropy = randomBytes(16);
        if (!options) {
            options = {};
        }
        if (options.extraEntropy) {
            entropy = arrayify(hexDataSlice(keccak256(concat([entropy, options.extraEntropy])), 0, 16));
        }
        const mnemonic = entropyToMnemonic(entropy, options.locale);
        return Wallet.fromMnemonic(mnemonic, options.path, options.locale);
    }
    static fromEncryptedJson(json, password, progressCallback) {
github ethers-io / ethers.js / packages / wallet / index.js View on Github external
Wallet.createRandom = function (options) {
        var entropy = random_1.randomBytes(16);
        if (!options) {
            options = {};
        }
        if (options.extraEntropy) {
            entropy = bytes_1.arrayify(bytes_1.hexDataSlice(keccak256_1.keccak256(bytes_1.concat([entropy, options.extraEntropy])), 0, 16));
        }
        var mnemonic = hdnode_1.entropyToMnemonic(entropy, options.locale);
        return Wallet.fromMnemonic(mnemonic, options.path, options.locale);
    };
    Wallet.fromEncryptedJson = function (json, password, progressCallback) {