@oneledger/hd-vault
v1.0.0-beta
Published
Oneledger SDK - HD wallet. Currently support OneLedger, BitCoin and Ethereum
Downloads
5
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
const HDVault = require('hd-vault');
Master Key Derivation
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
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
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.