Skip to content

Keyring

Gung De Surya edited this page Jul 7, 2020 · 1 revision

Keyring

Use Keyring to create HD Wallet using BIP32. We implementing ed25519 elliptic-curve to create the derivation

generateRandomPhrase()

Use this function to create securely random passphrase using bip39 library

Typescript

import { ZooKeyring } from "zoobc-wallet-sdk";
const passphrase = ZooKeyring.generateRandomPhrase();

Return string of passphrase

Example Result

bread raise token empower antique canyon risk trap artwork grunt trial gown awesome sword glare level faith minor regret prize deal extra achieve fever

isPassphraseValid()

Function for validating weather the passphrase is correct or not

Typescript

import { ZooKeyring } from "zoobc-wallet-sdk";
const passphrase = "bread raise token empower antique canyon risk trap artwork grunt trial gown awesome sword glare level faith minor regret prize deal extra achieve fever"
console.log(ZooKeyring.isPassphraseValid(passphrase));

Return boolean

new ZooKeyring()

Create this class to generate new BIP32 Interface using passphrase that we create earlier

Typescript

import { ZooKeyring } from "zoobc-wallet-sdk";
const keyring = new ZooKeyring(passphrase, password);

Parameters

  1. passphrase: passphrase to open the wallet
  2. password: (optional) password to salt the passphrase to make root key more unpredictable

Return object of ZooKeyring

Example

const passphrase =
  "bread raise token empower antique canyon risk trap artwork grunt trial gown awesome sword glare level faith minor regret prize deal extra achieve fever";
const pass = "p4ssphr4se";

const keyring = new ZooKeyring(passphrase, pass);

calcDerivationPath()

Using implementation of HD Wallet, we can derive path using this function to get new child seed. With this child seed, we can sign a transaction

Typescript

// generate bip32 root key first in keyring variable
const childSeed = keyring.calcDerivationPath(accountPath);

Parameters

  1. accountPath: is the 3rd section of derivation path format (m / purpose' / coin_type' / account' / change / address_index). For example if accountPath = 3 it mean m/44'/148'/3'

Return BIP32Interface

Example

const passphrase = "bread raise token empower antique canyon risk trap artwork grunt trial gown awesome sword glare level faith minor regret prize deal extra achieve fever";
const pass = "p4ssphr4se";

const keyring = new ZooKeyring(passphrase, pass);
const childSeed = keyring.calcDerivationPath(3);

After get the child seed, you can do all function that BIP32Interface can do, like signing the transaction using childSeed.sign(buffer) function

Clone this wiki locally