Wallet

πŸ“– Wallet Module

The wallet module in the ono-web package provides utilities to generate and manage ONO wallets using BIP39 mnemonics and HD (Hierarchical Deterministic) key derivation.


πŸ“¦ Importing

To use the wallet module, import it as follows:

const { wallet } = require('ono-web');

πŸš€ Functions

1. wallet.newWalletData()

Generates a new wallet with a mnemonic phrase and a seed.

βœ… Returns

  • Promise<WalletData> β€” an object containing:

    • mnemonic: The generated mnemonic phrase (BIP39).

    • seed: The seed derived from the mnemonic (hex string).

πŸ“ Example

const walletData = await wallet.newWalletData();
console.log(walletData.mnemonic); // Human-readable mnemonic phrase
console.log(walletData.seed);     // Hexadecimal seed

2. wallet.walletDataFromMnemonic(mnemonic)

Generates a wallet seed from an existing mnemonic phrase.

πŸ“₯ Parameters

Name
Type
Description

mnemonic

string

A valid BIP39 mnemonic phrase

βœ… Returns

  • Promise<WalletData> β€” an object containing:

    • mnemonic: The input mnemonic phrase.

    • seed: The derived seed (hex string).

πŸ“ Example

const mnemonic = "example mnemonic phrase here";
const walletData = await wallet.walletDataFromMnemonic(mnemonic);
console.log(walletData.seed); // Hexadecimal seed from mnemonic

3. wallet.hdWallet(seed)

Creates an HD wallet (Hierarchical Deterministic Wallet) from a seed.

πŸ“₯ Parameters

Name
Type
Description

seed

string

Seed in hexadecimal format

βœ… Returns

  • HDKey β€” an HD wallet object that can be used to derive key pairs.

πŸ“ Example

const hd = wallet.hdWallet(walletData.seed);

4. wallet.generateKeyPair(hdWallet, index)

Generates a key pair (private/public key) from an HD wallet at a specific index using the ONO HD path m/44'/2909'/0'/0/index.

πŸ“₯ Parameters

Name
Type
Description

hdWallet

HDKey

An HD wallet object

index

number

The index to derive the key at

βœ… Returns

  • HDKey β€” a key pair (contains publicKey and privateKey).

πŸ“ Example

const keyPair = wallet.generateKeyPair(hd, 0);
console.log(keyPair.publicKey.toString('hex'));  // Public key in hex
console.log(keyPair.privateKey.toString('hex')); // Private key in hex

πŸ“š Types

WalletData

{
  mnemonic: string;
  seed: string;
}
  • mnemonic: BIP39 mnemonic phrase.

  • seed: Hexadecimal string derived from mnemonic.


βš™οΈ HD Path

The ONO blockchain uses the following HD derivation path:

m/44'/2909'/0'/0/index
  • 2909 β€” Coin type index reserved for ONO.

  • index β€” Allows multiple accounts/addresses under the same seed.


πŸ’‘ Usage Example (Full Flow)

const { wallet } = require('ono-web');

(async () => {
    // Generate new wallet
    const walletData = await wallet.newWalletData();
    console.log("Mnemonic:", walletData.mnemonic);
    console.log("Seed:", walletData.seed);

    // Create HD wallet
    const hd = wallet.hdWallet(walletData.seed);

    // Generate first key pair
    const keyPair = wallet.generateKeyPair(hd, 0);
    console.log("Public Key:", keyPair.publicKey.toString('hex'));
    console.log("Private Key:", keyPair.privateKey.toString('hex'));
})();

🚨 Notes

  • Always back up your mnemonic phrase securely. It is the only way to recover your wallet.

  • Never share your private key; anyone with access to it can control your funds.

  • For forging ONO coins, remember to burn at least 100 ONO coins from the wallet address you plan to use.

Last updated