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()
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)
wallet.walletDataFromMnemonic(mnemonic)
Generates a wallet seed from an existing mnemonic phrase.
π₯ Parameters
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)
wallet.hdWallet(seed)
Creates an HD wallet (Hierarchical Deterministic Wallet) from a seed.
π₯ Parameters
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)
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
hdWallet
HDKey
An HD wallet object
index
number
The index to derive the key at
β Returns
HDKey
β a key pair (containspublicKey
andprivateKey
).
π 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
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