@polkadot/util-crypto#mnemonicGenerate TypeScript Examples

The following examples show how to use @polkadot/util-crypto#mnemonicGenerate. 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: bipWorker.ts    From crust-apps with Apache License 2.0 6 votes vote down vote up
ctx.onmessage = async ({ data: { pairType } }): Promise<void> => {
  await cryptoWaitReady();

  const seed = mnemonicGenerate();
  const miniSecret = mnemonicToMiniSecret(seed);
  const { publicKey } = pairType === 'sr25519'
    ? schnorrkelKeypairFromSeed(miniSecret)
    : naclKeypairFromSeed(miniSecret);

  ctx.postMessage({
    publicKey,
    seed
  });
};
Example #2
Source File: Create.tsx    From crust-apps with Apache License 2.0 6 votes vote down vote up
function newSeed (seed: string | undefined | null, seedType: SeedType): string {
  switch (seedType) {
    case 'bip':
      return mnemonicGenerate();
    case 'dev':
      return DEV_PHRASE;
    default:
      return seed || u8aToHex(randomAsU8a());
  }
}
Example #3
Source File: Keyring.ts    From gear-js with GNU General Public License v3.0 6 votes vote down vote up
static async create(
    name: string,
    passphrase?: string,
  ): Promise<{
    keyring: KeyringPair;
    mnemonic: string;
    seed: string;
    json: KeyringPair$Json;
  }> {
    const mnemonic = mnemonicGenerate();
    const seed = mnemonicToMiniSecret(mnemonic);
    const keyring = await GearKeyring.fromSeed(seed, name);
    return {
      keyring,
      mnemonic: mnemonic,
      seed: u8aToHex(seed),
      json: keyring.toJson(passphrase),
    };
  }
Example #4
Source File: keyring.ts    From sdk with Apache License 2.0 6 votes vote down vote up
/**
 * Generate a set of new mnemonic.
 */
async function gen(mnemonic: string, ss58Format: number, cryptoType: KeypairType, derivePath: string) {
  const key = mnemonic || mnemonicGenerate();
  if (!mnemonicValidate(key)) return null;

  const keyPair = keyring.addFromMnemonic(key + (derivePath || ""), {}, cryptoType || "sr25519");
  const address = encodeAddress(keyPair.publicKey, ss58Format || 0);
  const icons = await account.genIcons([address]);
  return {
    mnemonic: key,
    address,
    svg: icons[0][1],
  };
}
Example #5
Source File: Keyring.ts    From gear-js with GNU General Public License v3.0 5 votes vote down vote up
static generateMnemonic(): string {
    return mnemonicGenerate();
  }
Example #6
Source File: Keyring.ts    From gear-js with GNU General Public License v3.0 5 votes vote down vote up
static generateSeed(mnemonic?: string): { seed: `0x${string}`; mnemonic: string } {
    if (!mnemonic) {
      mnemonic = mnemonicGenerate();
    }
    return { seed: u8aToHex(mnemonicToMiniSecret(mnemonic)), mnemonic };
  }
Example #7
Source File: helpers.ts    From interbtc-api with Apache License 2.0 5 votes vote down vote up
export function makeRandomPolkadotKeyPair(keyring: Keyring): KeyringPair {
    const mnemonic = mnemonicGenerate(12);
    return keyring.addFromUri(mnemonic);
}