@btc-vision/transaction 1.8.0-rc.1 → 1.8.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/_version.d.ts +1 -1
- package/browser/_version.d.ts.map +1 -1
- package/browser/btc-vision-bitcoin.js +3560 -3170
- package/browser/buffer/BinaryWriter.d.ts +1 -1
- package/browser/buffer/BinaryWriter.d.ts.map +1 -1
- package/browser/bytecode/Compressor.d.ts +6 -6
- package/browser/bytecode/Compressor.d.ts.map +1 -1
- package/browser/epoch/ChallengeSolution.d.ts +14 -14
- package/browser/epoch/ChallengeSolution.d.ts.map +1 -1
- package/browser/generators/MLDSAData.d.ts +4 -4
- package/browser/generators/MLDSAData.d.ts.map +1 -1
- package/browser/index.js +966 -967
- package/browser/noble-curves.js +1 -1
- package/browser/noble-hashes.js +867 -1758
- package/browser/transaction/browser/types/Unisat.d.ts +1 -1
- package/browser/transaction/browser/types/Unisat.d.ts.map +1 -1
- package/browser/transaction/builders/CustomScriptTransaction.d.ts +1 -1
- package/browser/transaction/builders/DeploymentTransaction.d.ts +2 -2
- package/browser/transaction/builders/MultiSignTransaction.d.ts +5 -5
- package/browser/transaction/builders/SharedInteractionTransaction.d.ts +5 -5
- package/browser/transaction/builders/TransactionBuilder.d.ts +4 -4
- package/browser/transaction/offline/OfflineTransactionManager.d.ts +1 -1
- package/browser/transaction/shared/P2TR_MS.d.ts +1 -1
- package/browser/transaction/shared/TweakedTransaction.d.ts +2 -2
- package/browser/transaction/shared/TweakedTransaction.d.ts.map +1 -1
- package/browser/utils/BitcoinUtils.d.ts +5 -5
- package/browser/utils/BitcoinUtils.d.ts.map +1 -1
- package/browser/utils/BufferHelper.d.ts +1 -1
- package/browser/utils/BufferHelper.d.ts.map +1 -1
- package/browser/utils/StringToBuffer.d.ts +1 -1
- package/browser/utils/StringToBuffer.d.ts.map +1 -1
- package/browser/utils/types.d.ts +1 -1
- package/browser/utils/types.d.ts.map +1 -1
- package/browser/utxo/OPNetLimitedProvider.d.ts.map +1 -1
- package/browser/vendors.js +7732 -13160
- package/build/_version.d.ts +1 -1
- package/build/_version.d.ts.map +1 -1
- package/build/_version.js +1 -1
- package/build/_version.js.map +1 -1
- package/build/abi/ABICoder.js +3 -3
- package/build/abi/ABICoder.js.map +1 -1
- package/build/buffer/BinaryReader.js +1 -1
- package/build/buffer/BinaryReader.js.map +1 -1
- package/build/buffer/BinaryWriter.d.ts +1 -1
- package/build/buffer/BinaryWriter.d.ts.map +1 -1
- package/build/buffer/BinaryWriter.js.map +1 -1
- package/build/bytecode/Compressor.d.ts +6 -6
- package/build/bytecode/Compressor.d.ts.map +1 -1
- package/build/bytecode/Compressor.js +6 -6
- package/build/bytecode/Compressor.js.map +1 -1
- package/build/epoch/ChallengeSolution.d.ts +14 -14
- package/build/epoch/ChallengeSolution.d.ts.map +1 -1
- package/build/epoch/ChallengeSolution.js +11 -10
- package/build/epoch/ChallengeSolution.js.map +1 -1
- package/build/generators/MLDSAData.d.ts +4 -4
- package/build/generators/MLDSAData.d.ts.map +1 -1
- package/build/transaction/browser/types/Unisat.d.ts +1 -1
- package/build/transaction/browser/types/Unisat.d.ts.map +1 -1
- package/build/transaction/builders/CancelTransaction.js +1 -1
- package/build/transaction/builders/CancelTransaction.js.map +1 -1
- package/build/transaction/builders/ChallengeSolutionTransaction.js +5 -5
- package/build/transaction/builders/CustomScriptTransaction.d.ts +1 -1
- package/build/transaction/builders/CustomScriptTransaction.js +1 -1
- package/build/transaction/builders/DeploymentTransaction.d.ts +2 -2
- package/build/transaction/builders/DeploymentTransaction.js +2 -2
- package/build/transaction/builders/MultiSignTransaction.d.ts +5 -5
- package/build/transaction/builders/MultiSignTransaction.js +5 -5
- package/build/transaction/builders/SharedInteractionTransaction.d.ts +5 -5
- package/build/transaction/builders/SharedInteractionTransaction.js +5 -5
- package/build/transaction/builders/TransactionBuilder.d.ts +4 -4
- package/build/transaction/builders/TransactionBuilder.js +4 -4
- package/build/transaction/offline/OfflineTransactionManager.d.ts +1 -1
- package/build/transaction/offline/OfflineTransactionManager.js +1 -1
- package/build/transaction/shared/P2TR_MS.d.ts +1 -1
- package/build/transaction/shared/P2TR_MS.js +1 -1
- package/build/transaction/shared/TweakedTransaction.d.ts +2 -2
- package/build/transaction/shared/TweakedTransaction.d.ts.map +1 -1
- package/build/transaction/shared/TweakedTransaction.js +2 -13
- package/build/transaction/shared/TweakedTransaction.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/build/utils/BitcoinUtils.d.ts +5 -5
- package/build/utils/BitcoinUtils.d.ts.map +1 -1
- package/build/utils/BitcoinUtils.js +7 -7
- package/build/utils/BitcoinUtils.js.map +1 -1
- package/build/utils/BufferHelper.d.ts +1 -1
- package/build/utils/BufferHelper.d.ts.map +1 -1
- package/build/utils/BufferHelper.js.map +1 -1
- package/build/utils/StringToBuffer.d.ts +1 -1
- package/build/utils/StringToBuffer.d.ts.map +1 -1
- package/build/utils/StringToBuffer.js +2 -1
- package/build/utils/StringToBuffer.js.map +1 -1
- package/build/utils/types.d.ts +1 -1
- package/build/utils/types.d.ts.map +1 -1
- package/build/utxo/OPNetLimitedProvider.d.ts +1 -1
- package/build/utxo/OPNetLimitedProvider.d.ts.map +1 -1
- package/build/utxo/OPNetLimitedProvider.js +2 -1
- package/build/utxo/OPNetLimitedProvider.js.map +1 -1
- package/documentation/README.md +322 -25
- package/documentation/abi/abi-coder.md +440 -0
- package/documentation/addresses/address-types.md +459 -0
- package/documentation/api-reference/interfaces.md +806 -0
- package/documentation/api-reference/response-types.md +480 -0
- package/documentation/api-reference/transaction-types.md +348 -0
- package/documentation/binary/binary-reader.md +526 -0
- package/documentation/binary/binary-writer.md +484 -0
- package/documentation/browser/wallet-extensions.md +278 -0
- package/documentation/browser/web3-provider.md +300 -0
- package/documentation/deterministic/deterministic-collections.md +489 -0
- package/documentation/epoch/challenge-solution.md +462 -0
- package/documentation/epoch/epoch-validator.md +316 -0
- package/documentation/generators/generators.md +636 -0
- package/documentation/getting-started/installation.md +256 -0
- package/documentation/getting-started/overview.md +348 -0
- package/documentation/getting-started/quick-start.md +582 -0
- package/documentation/keypair/address-verificator.md +459 -0
- package/documentation/keypair/address.md +702 -0
- package/documentation/keypair/ec-keypair.md +558 -0
- package/documentation/keypair/message-signer.md +840 -0
- package/documentation/keypair/mnemonic.md +560 -0
- package/documentation/keypair/wallet.md +401 -0
- package/documentation/offline/offline-transaction-signing.md +819 -0
- package/documentation/quantum-support/04-message-signing.md +244 -10
- package/documentation/signer/address-rotation.md +419 -0
- package/documentation/signer/parallel-signer.md +245 -0
- package/documentation/signer/tweaked-signer.md +214 -0
- package/documentation/transaction-building/cancel-transactions.md +285 -0
- package/documentation/transaction-building/consolidated-transactions.md +441 -0
- package/documentation/transaction-building/custom-script-transactions.md +280 -0
- package/documentation/transaction-building/deployment-transactions.md +241 -0
- package/documentation/transaction-building/funding-transactions.md +282 -0
- package/documentation/transaction-building/interaction-transactions.md +292 -0
- package/documentation/transaction-building/multisig-transactions.md +340 -0
- package/documentation/transaction-building/transaction-factory-interfaces.md +726 -0
- package/documentation/transaction-building/transaction-factory.md +746 -0
- package/documentation/utils/bitcoin-utils.md +196 -0
- package/documentation/utils/buffer-helper.md +259 -0
- package/documentation/utils/compressor.md +182 -0
- package/documentation/utils/types-and-constants.md +259 -0
- package/documentation/utxo/opnet-limited-provider.md +363 -0
- package/package.json +4 -4
- package/src/_version.ts +1 -1
- package/src/abi/ABICoder.ts +4 -4
- package/src/buffer/BinaryReader.ts +1 -1
- package/src/buffer/BinaryWriter.ts +1 -1
- package/src/bytecode/Compressor.ts +8 -8
- package/src/epoch/ChallengeSolution.ts +23 -22
- package/src/generators/MLDSAData.ts +4 -4
- package/src/shims/zlib-browser.js +4 -4
- package/src/transaction/browser/types/Unisat.ts +1 -1
- package/src/transaction/builders/CancelTransaction.ts +1 -1
- package/src/transaction/builders/ChallengeSolutionTransaction.ts +5 -5
- package/src/transaction/builders/CustomScriptTransaction.ts +1 -1
- package/src/transaction/builders/DeploymentTransaction.ts +2 -2
- package/src/transaction/builders/MultiSignTransaction.ts +5 -5
- package/src/transaction/builders/SharedInteractionTransaction.ts +5 -5
- package/src/transaction/builders/TransactionBuilder.ts +4 -4
- package/src/transaction/offline/OfflineTransactionManager.ts +1 -1
- package/src/transaction/shared/P2TR_MS.ts +1 -1
- package/src/transaction/shared/TweakedTransaction.ts +3 -15
- package/src/utils/BitcoinUtils.ts +11 -11
- package/src/utils/BufferHelper.ts +1 -1
- package/src/utils/StringToBuffer.ts +4 -2
- package/src/utils/types.ts +1 -1
- package/src/utxo/OPNetLimitedProvider.ts +2 -2
- package/documentation/offline-transaction-signing.md +0 -652
- package/documentation/transaction-building.md +0 -603
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
# Wallet
|
|
2
|
+
|
|
3
|
+
Manages both classical (ECDSA/Schnorr) and quantum-resistant (ML-DSA) key pairs in a unified interface. The `Wallet` class encapsulates key derivation, address generation for all Bitcoin address types, and secure disposal of private key material. It integrates with the `Mnemonic` class for BIP39/BIP360 hierarchical deterministic derivation.
|
|
4
|
+
|
|
5
|
+
The `Wallet` implements `Disposable` for secure zeroing of private key buffers.
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Import](#import)
|
|
10
|
+
- [Constructor](#constructor)
|
|
11
|
+
- [Static Factory Methods](#static-factory-methods)
|
|
12
|
+
- [Wallet.fromWif()](#walletfromwif)
|
|
13
|
+
- [Wallet.fromPrivateKeys()](#walletfromprivatekeys)
|
|
14
|
+
- [Wallet.generate()](#walletgenerate)
|
|
15
|
+
- [Address Properties](#address-properties)
|
|
16
|
+
- [Key Properties](#key-properties)
|
|
17
|
+
- [Instance Methods](#instance-methods)
|
|
18
|
+
- [toWIF()](#towif)
|
|
19
|
+
- [toPrivateKeyHex()](#toprivatekeyhex)
|
|
20
|
+
- [toPublicKeyHex()](#topublickeyhex)
|
|
21
|
+
- [toQuantumBase58()](#toquantumbase58)
|
|
22
|
+
- [derivePath()](#derivepath)
|
|
23
|
+
- [zeroize()](#zeroize)
|
|
24
|
+
- [\[Symbol.dispose\]()](#symboldispose)
|
|
25
|
+
- [Integration with Mnemonic](#integration-with-mnemonic)
|
|
26
|
+
- [Code Examples](#code-examples)
|
|
27
|
+
- [Best Practices](#best-practices)
|
|
28
|
+
- [Related Documentation](#related-documentation)
|
|
29
|
+
|
|
30
|
+
## Import
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { Wallet } from '@btc-vision/transaction';
|
|
34
|
+
import { MLDSASecurityLevel } from '@btc-vision/bip32';
|
|
35
|
+
import { networks } from '@btc-vision/bitcoin';
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Constructor
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
new Wallet(
|
|
42
|
+
privateKeyOrWif: string,
|
|
43
|
+
mldsaPrivateKeyOrBase58: string,
|
|
44
|
+
network?: Network,
|
|
45
|
+
securityLevel?: MLDSASecurityLevel,
|
|
46
|
+
chainCode?: Uint8Array,
|
|
47
|
+
)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Creates a new Wallet instance from both a classical private key and a quantum ML-DSA private key.
|
|
51
|
+
|
|
52
|
+
| Parameter | Type | Required | Default | Description |
|
|
53
|
+
|-----------|------|----------|---------|-------------|
|
|
54
|
+
| `privateKeyOrWif` | `string` | Yes | -- | The classical private key. Accepts `0x`-prefixed hex, raw hex, or WIF-encoded format. |
|
|
55
|
+
| `mldsaPrivateKeyOrBase58` | `string` | Yes | -- | The ML-DSA private key. Accepts `0x`-prefixed hex, raw hex, or base58-encoded quantum key (from `toBase58()`). |
|
|
56
|
+
| `network` | `Network` | No | `networks.bitcoin` | The Bitcoin network. |
|
|
57
|
+
| `securityLevel` | `MLDSASecurityLevel` | No | `MLDSASecurityLevel.LEVEL2` | The ML-DSA security level. Ignored if `mldsaPrivateKeyOrBase58` is base58 (level is embedded). |
|
|
58
|
+
| `chainCode` | `Uint8Array` | No | `new Uint8Array(32)` | The 32-byte BIP32 chain code for hierarchical derivation. |
|
|
59
|
+
|
|
60
|
+
The constructor:
|
|
61
|
+
1. Parses the classical private key (hex or WIF) and creates an ECDSA signer.
|
|
62
|
+
2. Parses the ML-DSA private key (hex or base58) and creates a quantum signer.
|
|
63
|
+
3. Creates an `Address` from both public keys.
|
|
64
|
+
4. Pre-computes all address formats (P2TR, P2WPKH, P2PKH, P2SH-P2WPKH, P2WDA).
|
|
65
|
+
|
|
66
|
+
**Throws:**
|
|
67
|
+
- `Error` if the ML-DSA key length does not match the expected size for the given security level.
|
|
68
|
+
- `Error` if the chain code is provided but is not exactly 32 bytes.
|
|
69
|
+
|
|
70
|
+
## Static Factory Methods
|
|
71
|
+
|
|
72
|
+
### Wallet.fromWif()
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
static fromWif(
|
|
76
|
+
wif: string,
|
|
77
|
+
quantumPrivateKeyHex: string,
|
|
78
|
+
network?: Network,
|
|
79
|
+
securityLevel?: MLDSASecurityLevel,
|
|
80
|
+
chainCode?: Uint8Array,
|
|
81
|
+
): Wallet
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Creates a Wallet from a WIF-encoded classical private key and a hex-encoded quantum private key. This is a convenience wrapper around the constructor.
|
|
85
|
+
|
|
86
|
+
| Parameter | Type | Required | Default | Description |
|
|
87
|
+
|-----------|------|----------|---------|-------------|
|
|
88
|
+
| `wif` | `string` | Yes | -- | The WIF-encoded classical private key. |
|
|
89
|
+
| `quantumPrivateKeyHex` | `string` | Yes | -- | The ML-DSA private key in hex format. |
|
|
90
|
+
| `network` | `Network` | No | `networks.bitcoin` | The Bitcoin network. |
|
|
91
|
+
| `securityLevel` | `MLDSASecurityLevel` | No | `LEVEL2` | The ML-DSA security level. |
|
|
92
|
+
| `chainCode` | `Uint8Array` | No | -- | Optional BIP32 chain code. |
|
|
93
|
+
|
|
94
|
+
**Returns:** `Wallet`
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
const wallet = Wallet.fromWif(
|
|
98
|
+
'L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrisoyY1',
|
|
99
|
+
'0xaabbccdd...',
|
|
100
|
+
networks.bitcoin,
|
|
101
|
+
);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Wallet.fromPrivateKeys()
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
static fromPrivateKeys(
|
|
108
|
+
privateKeyHexOrWif: string,
|
|
109
|
+
mldsaPrivateKeyOrBase58: string,
|
|
110
|
+
network?: Network,
|
|
111
|
+
securityLevel?: MLDSASecurityLevel,
|
|
112
|
+
chainCode?: Uint8Array,
|
|
113
|
+
): Wallet
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Creates a Wallet from either hex or WIF classical private keys and either hex or base58 quantum private keys. This is the most flexible factory method.
|
|
117
|
+
|
|
118
|
+
| Parameter | Type | Required | Default | Description |
|
|
119
|
+
|-----------|------|----------|---------|-------------|
|
|
120
|
+
| `privateKeyHexOrWif` | `string` | Yes | -- | Classical private key (hex or WIF). |
|
|
121
|
+
| `mldsaPrivateKeyOrBase58` | `string` | Yes | -- | ML-DSA private key (hex or base58). |
|
|
122
|
+
| `network` | `Network` | No | `networks.bitcoin` | The Bitcoin network. |
|
|
123
|
+
| `securityLevel` | `MLDSASecurityLevel` | No | `LEVEL2` | The ML-DSA security level. |
|
|
124
|
+
| `chainCode` | `Uint8Array` | No | -- | Optional BIP32 chain code. |
|
|
125
|
+
|
|
126
|
+
**Returns:** `Wallet`
|
|
127
|
+
|
|
128
|
+
### Wallet.generate()
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
static generate(network?: Network, securityLevel?: MLDSASecurityLevel): Wallet
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Generates a completely new random wallet with both classical and quantum key pairs.
|
|
135
|
+
|
|
136
|
+
| Parameter | Type | Required | Default | Description |
|
|
137
|
+
|-----------|------|----------|---------|-------------|
|
|
138
|
+
| `network` | `Network` | No | `networks.bitcoin` | The Bitcoin network. |
|
|
139
|
+
| `securityLevel` | `MLDSASecurityLevel` | No | `LEVEL2` | The ML-DSA security level. |
|
|
140
|
+
|
|
141
|
+
**Returns:** `Wallet`
|
|
142
|
+
|
|
143
|
+
**Throws:** `Error` if quantum key generation fails.
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
const wallet = Wallet.generate(networks.bitcoin, MLDSASecurityLevel.LEVEL2);
|
|
147
|
+
console.log(wallet.p2tr); // 'bc1p...'
|
|
148
|
+
console.log(wallet.p2wpkh); // 'bc1q...'
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Address Properties
|
|
152
|
+
|
|
153
|
+
All address properties are pre-computed at construction time and cached.
|
|
154
|
+
|
|
155
|
+
| Property | Type | Description |
|
|
156
|
+
|----------|------|-------------|
|
|
157
|
+
| `address` | `Address` | The unified `Address` object containing both ML-DSA hash and classical tweaked key. |
|
|
158
|
+
| `p2tr` | `string` | The Taproot (P2TR) address (e.g., `bc1p...`). |
|
|
159
|
+
| `p2wpkh` | `string` | The native SegWit (P2WPKH) address (e.g., `bc1q...`). |
|
|
160
|
+
| `legacy` | `string` | The legacy (P2PKH) address (e.g., `1...`). |
|
|
161
|
+
| `segwitLegacy` | `string` | The nested SegWit (P2SH-P2WPKH) address (e.g., `3...`). |
|
|
162
|
+
| `p2wda` | `IP2WSHAddress` | The P2WDA address object with `address` and `witnessScript`. |
|
|
163
|
+
| `addresses` | `string[]` | Array of all four standard address formats: `[p2wpkh, p2tr, legacy, segwitLegacy]`. |
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
const wallet = Wallet.generate();
|
|
167
|
+
console.log(wallet.p2tr); // 'bc1p...'
|
|
168
|
+
console.log(wallet.p2wpkh); // 'bc1q...'
|
|
169
|
+
console.log(wallet.legacy); // '1...'
|
|
170
|
+
console.log(wallet.segwitLegacy); // '3...'
|
|
171
|
+
|
|
172
|
+
// Get the unified Address object
|
|
173
|
+
const addr = wallet.address;
|
|
174
|
+
console.log(addr.toHex()); // ML-DSA hash (32 bytes, 0x-prefixed)
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Key Properties
|
|
178
|
+
|
|
179
|
+
| Property | Type | Description |
|
|
180
|
+
|----------|------|-------------|
|
|
181
|
+
| `keypair` | `UniversalSigner` | The classical ECDSA/Schnorr key pair. Can sign and verify. |
|
|
182
|
+
| `mldsaKeypair` | `QuantumBIP32Interface` | The quantum ML-DSA key pair. Supports BIP32-style derivation. |
|
|
183
|
+
| `publicKey` | `Uint8Array` | The 33-byte compressed classical public key. |
|
|
184
|
+
| `tweakedPubKeyKey` | `Uint8Array` | The 32-byte x-only tweaked classical public key. |
|
|
185
|
+
| `xOnly` | `Uint8Array` | The x-only (32-byte) classical public key (before tweaking). |
|
|
186
|
+
| `quantumPublicKey` | `Uint8Array` | The raw ML-DSA public key bytes (copy). |
|
|
187
|
+
| `quantumPrivateKey` | `Uint8Array` | The raw ML-DSA private key bytes (copy). Throws if not available. |
|
|
188
|
+
| `quantumPublicKeyHex` | `string` | The ML-DSA public key as a hex string. |
|
|
189
|
+
| `quantumPrivateKeyHex` | `string` | The ML-DSA private key as a hex string. Throws if not available. |
|
|
190
|
+
| `securityLevel` | `MLDSASecurityLevel` | The ML-DSA security level of this wallet. |
|
|
191
|
+
| `chainCode` | `Uint8Array` | The 32-byte BIP32 chain code. |
|
|
192
|
+
| `network` | `Network` | The Bitcoin network this wallet is configured for. |
|
|
193
|
+
|
|
194
|
+
## Instance Methods
|
|
195
|
+
|
|
196
|
+
### toWIF()
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
toWIF(): string
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Exports the classical private key in Wallet Import Format (WIF).
|
|
203
|
+
|
|
204
|
+
**Returns:** `string` -- the WIF-encoded classical private key.
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
const wif = wallet.toWIF();
|
|
208
|
+
console.log(wif); // 'L4rK1yDt...'
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### toPrivateKeyHex()
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
toPrivateKeyHex(): string
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Exports the classical private key as a hex string.
|
|
218
|
+
|
|
219
|
+
**Returns:** `string`
|
|
220
|
+
|
|
221
|
+
**Throws:** `Error` if the private key is not available.
|
|
222
|
+
|
|
223
|
+
### toPublicKeyHex()
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
toPublicKeyHex(): string
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Exports the classical public key as a hex string.
|
|
230
|
+
|
|
231
|
+
**Returns:** `string`
|
|
232
|
+
|
|
233
|
+
### toQuantumBase58()
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
toQuantumBase58(): string
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Exports the quantum ML-DSA key pair in base58 encoding. This format includes the chain code and security level, making it suitable for storage and re-import.
|
|
240
|
+
|
|
241
|
+
**Returns:** `string`
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
const base58 = wallet.toQuantumBase58();
|
|
245
|
+
// Later, reconstruct:
|
|
246
|
+
const restored = new Wallet('...wif...', base58, networks.bitcoin);
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### derivePath()
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
derivePath(path: string): Wallet
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Derives a child wallet at the given BIP32 path. Both the classical and quantum keys are derived along the same path.
|
|
256
|
+
|
|
257
|
+
| Parameter | Type | Required | Description |
|
|
258
|
+
|-----------|------|----------|-------------|
|
|
259
|
+
| `path` | `string` | Yes | A BIP32 derivation path (e.g., `"m/84'/0'/0'/0/0"`). |
|
|
260
|
+
|
|
261
|
+
**Returns:** `Wallet` -- a new child wallet.
|
|
262
|
+
|
|
263
|
+
**Throws:** `Error` if the wallet has no private key (watch-only) or if derivation fails.
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
const child = wallet.derivePath("m/84'/0'/0'/0/0");
|
|
267
|
+
console.log(child.p2wpkh); // derived SegWit address
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### zeroize()
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
zeroize(): void
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
Zeroes all private key material in-place. This includes the classical private key, the quantum private key, and the chain code. After calling `zeroize()`, the wallet can no longer sign transactions.
|
|
277
|
+
|
|
278
|
+
> **Note:** JavaScript runtime constraints mean that copies made by the runtime (e.g., during garbage collection) cannot be zeroed. This method eliminates the primary references.
|
|
279
|
+
|
|
280
|
+
### \[Symbol.dispose\]()
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
[Symbol.dispose](): void
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Implements the `Disposable` interface. Calls `zeroize()` to securely clear all private key material.
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
{
|
|
290
|
+
using wallet = Wallet.generate();
|
|
291
|
+
const signed = wallet.keypair.sign(messageHash);
|
|
292
|
+
// ... use wallet
|
|
293
|
+
} // wallet.zeroize() called automatically
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## Integration with Mnemonic
|
|
297
|
+
|
|
298
|
+
The `Wallet` class is the primary output of `Mnemonic.derive()`. When you derive wallets from a mnemonic phrase, each derived wallet contains both classical and quantum keys at the specified index.
|
|
299
|
+
|
|
300
|
+
```typescript
|
|
301
|
+
import { Mnemonic } from '@btc-vision/transaction';
|
|
302
|
+
|
|
303
|
+
const mnemonic = Mnemonic.generate();
|
|
304
|
+
|
|
305
|
+
// Derive the first wallet (index 0)
|
|
306
|
+
const wallet = mnemonic.derive(0);
|
|
307
|
+
|
|
308
|
+
// Access all address formats
|
|
309
|
+
console.log('Taproot:', wallet.p2tr);
|
|
310
|
+
console.log('SegWit:', wallet.p2wpkh);
|
|
311
|
+
console.log('Legacy:', wallet.legacy);
|
|
312
|
+
|
|
313
|
+
// Access key pairs for signing
|
|
314
|
+
const classicalSigner = wallet.keypair;
|
|
315
|
+
const quantumSigner = wallet.mldsaKeypair;
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
## Code Examples
|
|
319
|
+
|
|
320
|
+
### Creating a wallet from existing keys
|
|
321
|
+
|
|
322
|
+
```typescript
|
|
323
|
+
import { Wallet } from '@btc-vision/transaction';
|
|
324
|
+
import { networks } from '@btc-vision/bitcoin';
|
|
325
|
+
|
|
326
|
+
const wallet = Wallet.fromPrivateKeys(
|
|
327
|
+
'0xe8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35',
|
|
328
|
+
'0xaabbccddee...', // ML-DSA private key hex
|
|
329
|
+
networks.bitcoin,
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
console.log('P2TR:', wallet.p2tr);
|
|
333
|
+
console.log('Address hex:', wallet.address.toHex());
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
### Generating a new wallet
|
|
337
|
+
|
|
338
|
+
```typescript
|
|
339
|
+
import { Wallet } from '@btc-vision/transaction';
|
|
340
|
+
import { MLDSASecurityLevel } from '@btc-vision/bip32';
|
|
341
|
+
|
|
342
|
+
const wallet = Wallet.generate(networks.bitcoin, MLDSASecurityLevel.LEVEL2);
|
|
343
|
+
|
|
344
|
+
// Save keys for later
|
|
345
|
+
const wif = wallet.toWIF();
|
|
346
|
+
const quantumBase58 = wallet.toQuantumBase58();
|
|
347
|
+
|
|
348
|
+
console.log('Save this WIF:', wif);
|
|
349
|
+
console.log('Save this quantum key:', quantumBase58);
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
### Exporting and restoring
|
|
353
|
+
|
|
354
|
+
```typescript
|
|
355
|
+
// Export
|
|
356
|
+
const wif = wallet.toWIF();
|
|
357
|
+
const quantumBase58 = wallet.toQuantumBase58();
|
|
358
|
+
|
|
359
|
+
// Restore
|
|
360
|
+
const restored = Wallet.fromWif(wif, quantumBase58, networks.bitcoin);
|
|
361
|
+
console.log(restored.p2tr === wallet.p2tr); // true
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
### Secure disposal pattern
|
|
365
|
+
|
|
366
|
+
```typescript
|
|
367
|
+
{
|
|
368
|
+
using wallet = Wallet.fromPrivateKeys(classicalHex, quantumHex, networks.bitcoin);
|
|
369
|
+
|
|
370
|
+
// Sign a transaction
|
|
371
|
+
const signature = wallet.keypair.sign(txHash);
|
|
372
|
+
|
|
373
|
+
// ... broadcast transaction
|
|
374
|
+
} // Private keys are automatically zeroed here
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
### Deriving child wallets
|
|
378
|
+
|
|
379
|
+
```typescript
|
|
380
|
+
const parentWallet = new Wallet(classicalWif, quantumBase58, networks.bitcoin);
|
|
381
|
+
const child0 = parentWallet.derivePath("m/84'/0'/0'/0/0");
|
|
382
|
+
const child1 = parentWallet.derivePath("m/84'/0'/0'/0/1");
|
|
383
|
+
|
|
384
|
+
console.log(child0.p2wpkh); // Different from child1
|
|
385
|
+
console.log(child1.p2wpkh);
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
## Best Practices
|
|
389
|
+
|
|
390
|
+
1. **Always use `[Symbol.dispose]` or call `zeroize()`** when done with a wallet to minimize exposure of private key material in memory.
|
|
391
|
+
2. **Prefer `Wallet.generate()` for new wallets** to ensure both classical and quantum keys are properly generated together.
|
|
392
|
+
3. **Store quantum keys in base58 format** (via `toQuantumBase58()`) since it includes the chain code and security level, making restoration simpler.
|
|
393
|
+
4. **Never log or expose private keys** in production environments. Use WIF for classical key storage and base58 for quantum key storage.
|
|
394
|
+
5. **Use the `Mnemonic` class for deterministic wallets** rather than storing individual private keys when managing multiple accounts.
|
|
395
|
+
|
|
396
|
+
## Related Documentation
|
|
397
|
+
|
|
398
|
+
- [Address](./address.md) -- Quantum-resistant address representation
|
|
399
|
+
- [EcKeyPair](./ec-keypair.md) -- Classical ECDSA/Schnorr key pair utilities
|
|
400
|
+
- [Mnemonic](./mnemonic.md) -- BIP39 + BIP360 quantum wallet derivation
|
|
401
|
+
- [AddressVerificator](./address-verificator.md) -- Address validation utilities
|