How to use the @polkadot/util-crypto.schnorrkelKeypairFromSeed function in @polkadot/util-crypto

To help you get started, we’ve selected a few @polkadot/util-crypto 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 polkadot-js / common / packages / keyring / src / keyring.ts View on Github external
if ([12, 15, 18, 21, 24].includes(parts.length)) {
        // FIXME This keeps compat with older versions, but breaks compat with subkey
        // seed = type === 'sr25519'
        //   ? mnemonicToMiniSecret(phrase, password)
        //   : mnemonicToSeed(phrase, password);
        seed = mnemonicToMiniSecret(phrase, password);
      } else {
        assert(str.length <= 32, 'specified phrase is not a valid mnemonic and is invalid as a raw seed at > 32 bytes');

        seed = stringToU8a(str.padEnd(32));
      }
    }

    const keypair = type === 'sr25519'
      ? schnorrkelFromSeed(seed)
      : naclFromSeed(seed);
    const derived = keyFromPath(keypair, path, type);

    return createPair(type, derived, meta, null);
  }
github paritytech / substrate-light-ui / packages / light-apps / src / Onboarding / Welcome / SetupNominator.tsx View on Github external
const confirmCreate = () => {
    const stashAddress = schnorrkelKeypairFromSeed(mnemonicToSeed(stashMnemonic));
    const controllerAddress = schnorrkelKeypairFromSeed(mnemonicToSeed(controllerMnemonic));

    keyring.encodeAddress(
      stashAddress.publicKey
    );

    keyring.encodeAddress(
      controllerAddress.publicKey
    );

    keyring.addUri(`${stashMnemonic.trim()}`, stashPassword, { name: 'Stash', type: 'stash' }, DEFAULT_ACCOUNT_TYPE);
    const controllerResult = keyring.addUri(`${controllerMnemonic.trim()}`, controllerPassword, { name: 'Controller', type: 'controller' }, DEFAULT_ACCOUNT_TYPE);

    props.history.push(`/transfer/${controllerResult.pair.address()}`);
  };
github paritytech / substrate-light-ui / packages / light-apps / src / Onboarding / Welcome / SetupNominator.tsx View on Github external
const confirmCreate = () => {
    const stashAddress = schnorrkelKeypairFromSeed(mnemonicToSeed(stashMnemonic));
    const controllerAddress = schnorrkelKeypairFromSeed(mnemonicToSeed(controllerMnemonic));

    keyring.encodeAddress(
      stashAddress.publicKey
    );

    keyring.encodeAddress(
      controllerAddress.publicKey
    );

    keyring.addUri(`${stashMnemonic.trim()}`, stashPassword, { name: 'Stash', type: 'stash' }, DEFAULT_ACCOUNT_TYPE);
    const controllerResult = keyring.addUri(`${controllerMnemonic.trim()}`, controllerPassword, { name: 'Controller', type: 'controller' }, DEFAULT_ACCOUNT_TYPE);

    props.history.push(`/transfer/${controllerResult.pair.address()}`);
  };
github polkadot-js / apps / packages / app-accounts / src / bipWorker.ts View on Github external
ctx.onmessage = async ({ data: { pairType } }): Promise => {
  await cryptoWaitReady();

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

  ctx.postMessage({
    publicKey,
    seed
  });
};
github polkadot-js / common / packages / keyring / src / pair / index.ts View on Github external
const fromSeed = (type: KeypairType, seed: Uint8Array): Keypair =>
  isSr25519(type)
    ? schnorrkelFromSeed(seed)
    : naclFromSeed(seed);
github polkadot-js / apps / packages / app-accounts / src / vanitygen / generate.ts View on Github external
export default function generator (test: string[][], options: GeneratorOptions): GeneratorMatch {
  const mnemonic = options.withHex
    ? undefined
    : mnemonicGenerate(12);
  const seed = mnemonic
    ? mnemonicToMiniSecret(mnemonic)
    : randomAsU8a();
  const pair = options.type === 'sr25519'
    ? schnorrkelKeypairFromSeed(seed)
    : naclKeypairFromSeed(seed);
  const address = encodeAddress(pair.publicKey);
  const { count, offset } = calculate(test, address, options);

  return {
    address,
    count,
    mnemonic,
    offset,
    seed
  };
}
github polkadot-js / common / packages / keyring / src / keyring.ts View on Github external
public addFromSeed (seed: Uint8Array, meta: KeyringPair$Meta = {}, type: KeypairType = this.type): KeyringPair {
    const keypair = type === 'sr25519'
      ? schnorrkelFromSeed(seed)
      : naclFromSeed(seed);

    return this.addPair(createPair(type, keypair, meta, null));
  }