Creación de una nueva clave bip32 derivada del blockchain

De blockchain_create_bip32_derivation.js

// Importa o cliente Dinamo HSM
const {hsm} = require("@dinamonetworks/hsm-dinamo");

// Define os parâmetros de conexão com o HSM
const options = {
host: "127.0.0.1",
authUsernamePassword: {
username: "master",
password: "12345678"
}
};

async function keyDerivation() {
// Connecta ao HSM
const conn = await hsm.connect(options);

// Nome da chave
const keyName = "parentKey"

// Cria a chave pai
const created = await conn.blockchain.create(
keyName, // Nome da chave
hsm.enums.BLOCKCHAIN_KEYS.BIP32_XPRV, // Tipo da chave
true, // Se é exportável
true, // Se é temporária
hsm.enums.VERSION_OPTIONS.BIP32_MAIN_NET // Versão
)

// Verifica se a chave pai foi criada
if (created) {
console.log("Parent key created")
} else {
console.log("Parent key not created")
}

// Nome da chave filha
const childName = "childKey"

// Deriva a chave
const childKey = await conn.blockchain.createBip32ChildKeyDerivation(
hsm.enums.VERSION_OPTIONS.BIP32_MAIN_NET, // Versão
hsm.enums.BCHAIN_SECURE_BIP32_INDEX.BASE, // Index da chave
true, // Se é exportável
true, // Se é temporária
keyName, // Nome da chave pai
childName, // Nome da chave filha
)
console.log("Key derived successfully", childKey)

// Desconecta do HSM
await conn.disconnect();
}

// Execute a função keyDerivation
keyDerivation();