# @oneledger/hd-vault

> Oneledger SDK - HD wallet. Currently support OneLedger, BitCoin and Ethereum

Latest version **1.0.0-beta** (published 2022-07-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install @oneledger/hd-vault
pnpm add @oneledger/hd-vault
yarn add @oneledger/hd-vault
bun add @oneledger/hd-vault
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-beta |
| Published | 2022-07-25 |
| First published | 2022-07-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 13 |
| Unpacked size | 137.5 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| Maintainers | dev1dor |

## Links

- npm: https://www.npmjs.com/package/@oneledger/hd-vault
- npm.io page: https://npm.io/package/@oneledger/hd-vault

## Dependencies (13)

- [sjcl](https://npm.io/package/sjcl.md) 1.0.8
- [bip32](https://npm.io/package/bip32.md) 2.0.4
- [bip39](https://npm.io/package/bip39.md) 3.0.2
- [secp256k1](https://npm.io/package/secp256k1.md) 3.7.1
- [tweetnacl](https://npm.io/package/tweetnacl.md) 1.0.1
- [bitcoinjs-lib](https://npm.io/package/bitcoinjs-lib.md) 5.1.7
- [ethereumjs-tx](https://npm.io/package/ethereumjs-tx.md) 2.1.1
- [ed25519-hd-key](https://npm.io/package/ed25519-hd-key.md) 1.0.0
- [tweetnacl-util](https://npm.io/package/tweetnacl-util.md) 0.15.0
- [ethereum-hdwallet](https://npm.io/package/ethereum-hdwallet.md) 0.0.21
- [ethereumjs-wallet](https://npm.io/package/ethereumjs-wallet.md) 0.6.3
- [wallet-address-validator](https://npm.io/package/wallet-address-validator.md) 0.2.4
- [@oneledger/middle_utility](https://npm.io/package/@oneledger/middle_utility.md) ^1.0.0-beta

## Recent versions

- 1.0.0-beta (latest) — 2022-07-25

## README

# HD-Vault

Core module of Oneledger HD wallet.  
Currently, we support **OneLedger**, **BitCoin** and **Ethereum** key derivation.

Oneledger HD vault provides functionalities to derive master key, Oneledger key, BitCoin key and Ethereum key, it also provides functionalities to sign Oneledger, BitCoin and Ethereum txs.

## Usage

import
```javascript
    const HDVault = require('hd-vault');
```

#### Master Key Derivation
```javascript
    const yourMasterKeyPassword = "xxxxxx"; // This is the password to encrypt your master key
    const mnemonicWords = HDVault.mnemonicUtil.mnemonicGenerator24();
    const masterKey = new HDVault.MasterKeySeedManager(mnemonicWords, yourMasterKeyPassword);
    const {encryptedMasterKeySeed} = masterKey.getMasterKeySeedInfo(); // You need to store this encryptedMasterKeySeed for later usage
```

#### Oneledger Key Derivation
```javascript
    const derivedKeyData = {
        keyType: "OLT",
        keyIndex: 0, // key index
        password: yourMasterKeyPassword,
        encryptedMasterKeySeed: encryptedMasterKeySeed
    };
    const {response} = await HDVault.derivedKeyManager.deriveNewKeyPair(derivedKeyData).catch(error => {
        // handler error here
    });
    const {keyIndex, address, publicKey} = response; // Address is the Oneledger address derived based on key index, publicKey is the public key associated to this address
```

#### Sign tx with Oneledger Key
```javascript
    const signData = {
        message: rawTx, // Base64 encoded Oneledger rawTx
        keyType: "OLT",
        keyIndex: 0, // To sign with Oneledger address derived before, please using the same key index here
        password: yourMasterKeyPassword,
        encryptedMasterKeySeed: encryptedMasterKeySeed
    };
    const {response} = await HDVault.derivedKeyManager.signTx(signData).catch(error => {
        // handler error here
    });
    const {signature} = response; // Get Oneledger tx signature
```

Use the `signature` with `publicKey` to broadcast Oneledger tx.   
Please note, for broadcast, the `publicKey` and `signature` have to be generated by the same key index.

---
_Source: https://npm.io/package/@oneledger/hd-vault · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
