Using EcKeyPair
Overview
EcKeyPair handles key generation, derivation, address generation, Taproot tweaking, multi-signature address creation, and address verification. It uses the secp256k1 curve with precomputed tables for optimized performance.
Refers to the EcKeyPair Reference section for technical information about the EcKeyPair class.
Code Examples
Import from WIF and generate a complete wallet
typescript
Import from WIF and generate a complete wallet
import { EcKeyPair } from '@btc-vision/transaction';
import { networks } from '@btc-vision/bitcoin';
const signer = EcKeyPair.fromWIF('L4rK1yDt...', networks.bitcoin);
const wallet = EcKeyPair.generateWallet(networks.bitcoin);
console.log('Classical address:', wallet.address);
console.log('Quantum public key:', wallet.quantumPublicKey);Create a 2-of-3 multisig
typescript
Create a 2-of-3 multisig
import { EcKeyPair } from '@btc-vision/transaction';
import { networks } from '@btc-vision/bitcoin';
const addr = EcKeyPair.generateMultiSigAddress(
[pubkey1, pubkey2, pubkey3],
2,
networks.bitcoin,
);
console.log('Multisig address:', addr); // bc1q... (P2WSH)Full workflow
typescript
Generate key pair, derive addresses
import { EcKeyPair } from '@btc-vision/transaction';
import { networks } from '@btc-vision/bitcoin';
const network = networks.bitcoin;
// Generate a random key pair
const signer = EcKeyPair.generateRandomKeyPair(network);
// Derive all address types
const taproot = EcKeyPair.getTaprootAddress(signer, network);
const segwit = EcKeyPair.getP2WPKHAddress(signer, network);
const legacy = EcKeyPair.getLegacyAddress(signer, network);
const nested = EcKeyPair.getLegacySegwitAddress(signer, network);
console.log('Taproot:', taproot); // bc1p...
console.log('SegWit:', segwit); // bc1q...
console.log('Legacy:', legacy); // 1...
console.log('Nested:', nested); // 3...