Skip to main content
@thru/crypto gives you the two building blocks for wallet onboarding flows: generate or validate a mnemonic, then derive Thru accounts from the resulting 64-byte seed.

Install

npm install @thru/crypto

Import

import { MnemonicGenerator, ThruHDWallet, getWebCrypto } from '@thru/crypto';

Exports

ExportWhat it does
MnemonicGeneratorGenerate a 12-word mnemonic, validate a phrase, and convert it to a 64-byte seed.
ThruHDWalletDerive Thru account keys and addresses from a seed using SLIP-0010 Ed25519 derivation.
getWebCryptoRe-exported helper for resolving Web Crypto support through @thru/helpers.

When to use it

Use @thru/crypto when you need wallet onboarding primitives: mnemonics, seeds, and deterministic account derivation. Use @thru/helpers when you only need address or signature encoding, byte conversion, or Web Crypto access.

Quick decision

NeedUse
Create or validate a seed phraseMnemonicGenerator
Derive one or more Thru accounts from a seedThruHDWallet
Check browser Web Crypto supportgetWebCrypto

Mnemonic generation

MnemonicGenerator works with the English BIP39 wordlist.
  • generate() returns a new 12-word mnemonic.
  • validate(phrase) checks whether a phrase is valid.
  • toSeed(phrase, passphrase?) converts a valid phrase into a 64-byte seed.
  • getWordCount(phrase) returns the number of words in a phrase.

Account derivation

ThruHDWallet derives accounts from a 64-byte seed using the Thru coin type 9999.
  • THRU_COIN_TYPE is 9999.
  • THRU_DERIVATION_PATH is m/44'/9999'.
  • getAccount(seed, accountIndex?, change?) returns the derived address, public key, private key, secret key, and path.
  • deriveAccounts(seed, count) returns a list of derived accounts starting at index 0.
  • isValidPath(path) checks whether a derivation path is syntactically valid.
getAccount() requires a 64-byte seed and a non-negative account index. The derived path format is m/44'/9999'/{accountIndex}'/{change}'.

Example

const phrase = MnemonicGenerator.generate();
const seed = MnemonicGenerator.toSeed( phrase );
const account = await ThruHDWallet.getAccount( seed, 0 );

console.log( account.address );
console.log( account.path );