> For the complete documentation index, see [llms.txt](https://berinis-organization.gitbook.io/ono/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://berinis-organization.gitbook.io/ono/integration/wallet.md).

# 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:

```javascript
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**

```javascript
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**

```javascript
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**

```javascript
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**

```javascript
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`

```typescript
{
  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)

```javascript
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.
