UNPKG

@zerochain/sdk

Version:

The Züs JS SDK is a JavaScript client library that provides a convenient interface for interacting with the Züs Network. It allows developers to perform various operations such as creating and managing allocations, uploading and downloading files, executi

35 lines (29 loc) 1.23 kB
import { getBls, hexStringToByte } from '@/utils' import { generateMnemonic, mnemonicToSeed } from 'bip39' import sha3 from 'js-sha3' export const getBip39MnemonicSeedBuffer = async ( customBip39Mnemonic?: string ): Promise<{ mnemonic: string; buffer: Uint8Array<ArrayBufferLike> }> => { const mnemonic = customBip39Mnemonic || generateMnemonic(256) const seed = await mnemonicToSeed(mnemonic, '0chain-client-split-key') const buffer = new Uint8Array(seed) return { mnemonic, buffer } } export const getBlsKeys = async ( bip39MnemonicSeedBuffer: Uint8Array<ArrayBufferLike> ): Promise<{ publicKey: string; privateKey: string }> => { const bls = await getBls() const blsSecret = new bls.SecretKey() bls.setRandFunc(bip39MnemonicSeedBuffer) blsSecret.setLittleEndian(bip39MnemonicSeedBuffer) const publicKey = blsSecret.getPublicKey().serializeToHexStr() as string const privateKey = blsSecret.serializeToHexStr() as string return { publicKey, privateKey } } export const getSha3HashFromHexString = (hexString: string): string => { return sha3.sha3_256(hexStringToByte(hexString)) } export const isHash = (str: string): boolean => { const regexExp = /^[a-f0-9]{64}$/gi return regexExp.test(str) }