bipWorker.ts 811 B

1234567891011121314151617181920212223242526
  1. // Copyright 2017-2019 @polkadot/app-accounts authors & contributors
  2. // This software may be modified and distributed under the terms
  3. // of the Apache-2.0 license. See the LICENSE file for details.
  4. import { cryptoWaitReady, mnemonicGenerate, mnemonicToMiniSecret, naclKeypairFromSeed, schnorrkelKeypairFromSeed } from '@polkadot/util-crypto';
  5. const ctx: Worker = self as unknown as Worker;
  6. cryptoWaitReady().catch((): void => {
  7. // ignore
  8. });
  9. ctx.onmessage = async ({ data: { pairType } }): Promise<void> => {
  10. await cryptoWaitReady();
  11. const seed = mnemonicGenerate();
  12. const miniSecret = mnemonicToMiniSecret(seed);
  13. const { publicKey } = pairType === 'sr25519'
  14. ? schnorrkelKeypairFromSeed(miniSecret)
  15. : naclKeypairFromSeed(miniSecret);
  16. ctx.postMessage({
  17. publicKey,
  18. seed
  19. });
  20. };