bip39#mnemonicToSeedSync TypeScript Examples
The following examples show how to use
bip39#mnemonicToSeedSync.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: accounts-from-mnemonic.ts From rubic-sdk with GNU General Public License v3.0 | 6 votes |
export function generateAccountsFromMnemonic(mnemonic: string, count: number) {
const seed = mnemonicToSeedSync(mnemonic);
const hdwallet = hdkey.fromMasterSeed(seed);
const walletHdpath = "m/44'/60'/0'/0/";
const accounts = [];
for (let i = 0; i < count; i++) {
const wallet = hdwallet.derivePath(walletHdpath + i).getWallet();
const address = `0x${wallet.getAddress().toString('hex')}`;
const privateKey = wallet.getPrivateKey().toString('hex');
accounts.push({ address, privateKey });
}
return accounts;
}
Example #2
Source File: index.ts From no-bad-chihuahua with MIT License | 6 votes |
run = async () => {
const { chainType, authType, authString, continueFlag } = await prompt();
const selectedChainInformation: ChainInformation | undefined = SUPPORT_CHAIN_LIST.find((chain) => chain.ticker === chainType);
if (selectedChainInformation === undefined) {
return;
}
// validation check, should remove authType after privateKey supported
if (continueFlag) {
let privateKey: Buffer;
if (authType === 'mnemonic') {
const seed = mnemonicToSeedSync(authString);
const node = fromSeed(seed);
const child = node.derivePath(`m/44'/${COIN_TYPE}'/0'/0/0`);
if (child.privateKey !== undefined) {
privateKey = child.privateKey;
}
} else {
privateKey = convertHexStringToBuffer(authString.startsWith('0x') ? authString.slice(2) : authString);
}
schedule.scheduleJob(cycleTime, async () => {
await autoStaking(privateKey, selectedChainInformation);
});
}
}
Example #3
Source File: moon-key.ts From moonbeam with GNU General Public License v3.0 | 6 votes |
main = async () => {
const hdwallet = hdkey.fromMasterSeed(mnemonicToSeedSync(mnemonic));
const path = `m/44'/60'/0'/0/${account_index}`;
const wallet = hdwallet.derivePath(path).getWallet();
console.log(`Address: ${wallet.getAddressString()}`);
console.log(`Mnemonic: ${mnemonic}`);
console.log(`Private Key: ${wallet.getPrivateKeyString()}`);
console.log(`Path: ${path}`);
}
Example #4
Source File: wallet.service.ts From Elastos.Essentials.App with MIT License | 6 votes |
/**
* Creates a new standard master wallet using a given mnemonic.
* The new master wallet is saved to storage, and instanciated/added to the local model.
*/
public async newStandardWalletWithMnemonic(
masterId: string,
walletName: string,
mnemonicStr: string,
mnemonicPassphrase: string,
payPassword: string,
networkOptions: WalletNetworkOptions[], // elastos -> single address
walletCreator: WalletCreator,
activateAfterCreation = true
): Promise<MasterWallet> {
Logger.log('wallet', "Importing new master wallet with mnemonic");
let hasPassphrase = false;
if (mnemonicPassphrase && mnemonicPassphrase.length > 0) {
Logger.log('wallet', "A passphrase is being used");
hasPassphrase = true;
}
// Calculate the seed key from mnemonic + passphrase
let seed = mnemonicToSeedSync(mnemonicStr, mnemonicPassphrase).toString('hex');
let masterWalletInfo: SerializedStandardMasterWallet = {
type: WalletType.STANDARD,
id: masterId,
name: walletName,
theme: defaultWalletTheme(),
seed: await AESEncrypt(seed, payPassword),
mnemonic: await AESEncrypt(mnemonicStr, payPassword),
hasPassphrase,
networkOptions,
creator: walletCreator
}
return this.createMasterWalletFromSerializedInfo(masterWalletInfo, activateAfterCreation);
}
Example #5
Source File: multisig.ts From ldk with MIT License | 6 votes |
constructor(args: IdentityOpts<MultisigOpts>) {
checkIdentityType(args.type, IdentityType.Multisig);
checkMnemonic(args.opts.signer.mnemonic);
const walletSeed = mnemonicToSeedSync(args.opts.signer.mnemonic);
const network = (networks as Record<string, Network>)[args.chain];
const masterPrivateKeyNode = BIP32Factory(args.ecclib).fromSeed(
walletSeed,
network
);
const baseNode = masterPrivateKeyNode.derivePath(
args.opts.signer.baseDerivationPath || DEFAULT_BASE_DERIVATION_PATH
);
super({
...args,
opts: {
...args.opts,
cosigners: args.opts.cosigners.concat([args.opts.signer]),
},
type: IdentityType.MultisigWatchOnly,
});
this.baseDerivationPath =
args.opts.signer.baseDerivationPath || DEFAULT_BASE_DERIVATION_PATH;
this.baseNode = baseNode;
this.scriptToPath = {};
}
Example #6
Source File: multisigWatchOnly.ts From ldk with MIT License | 6 votes |
function cosignerToXPub(
cosigner: CosignerMultisig,
network: networks.Network,
ecclib: TinySecp256k1Interface
): XPub {
if (typeof cosigner === 'string') return cosigner;
const walletSeed = mnemonicToSeedSync(cosigner.mnemonic);
const bip32 = BIP32Factory(ecclib);
const baseNode = bip32
.fromSeed(walletSeed, network)
.derivePath(cosigner.baseDerivationPath || DEFAULT_BASE_DERIVATION_PATH);
return toXpub(
bip32
.fromPublicKey(baseNode.publicKey, baseNode.chainCode, network)
.toBase58()
);
}
Example #7
Source File: main.ts From moonbeam with GNU General Public License v3.0 | 5 votes |
hdkeyGenerator = hdkey.fromMasterSeed(mnemonicToSeedSync(params.WORKERS_MNEMONIC))
Example #8
Source File: solana.wallet.ts From tatum-js with MIT License | 5 votes |
generateAddressFromMnemonic = (mnemonic: string, index: number) => {
const seed = mnemonicToSeedSync(mnemonic).toString('hex')
const { key } = derivePath(`${DERIVATION_PATH.SOL}/${index}'`, seed)
const keypair = Keypair.fromSeed(key)
return { address: keypair.publicKey.toBase58(), privateKey: encode(keypair.secretKey) }
}
Example #9
Source File: mnemonic.identity.test.ts From ldk with MIT License | 5 votes |
seedFromValidMnemonic = mnemonicToSeedSync(validOpts.opts.mnemonic)