1.0.0 • Published 1 year ago

@xxnetwork/wasm-crypto v1.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

@xxnetwork/wasm-crypto

Wrapper around crypto hashing functions

Usage

Install the package (also requires @polkadot/util for TextEncoder polyfills - not included here as a dependency to keep the tree lean).

In order to generate sleeve wallets, also import @polkadot/wasm-crypto to create BIP39 seeds and standard (sr25519 or ed25519) wallets.

yarn add @xxnetwork/wasm-crypto @polkadot/wasm-crypto @polkadot/util

Use it -

import { u8aToHex } from '@polkadot/util';
import { waitReadyPolkadot, bip39ToSeed, bip39Generate } from '@polkadot/wasm-crypto';
import { waitReady, generateSleeve } from '@xxnetwork/wasm-crypto';

// first wait until the WASM has been loaded (async init)
await waitReadyPolkadot();
await waitReady();

// generate quantum seed
const quantum: string = bip39Generate(24);

// generate standard seed
const standard = generateSleeve(quantum);

// get seed from standard phrase
const seed = bip39ToSeed(standard, '');

// display
console.log('quantum phrase:', quantum);
console.log('standard phrase:', standard);
console.log('seed:', u8aToHex(seed));