@btc-vision/transaction 1.7.0 → 1.7.1
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/index.js +1 -1
- package/browser/src/_version.d.ts +1 -1
- package/browser/src/mnemonic/BIPStandard.d.ts +8 -0
- package/browser/src/mnemonic/Mnemonic.d.ts +7 -2
- package/browser/src/opnet.d.ts +1 -0
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/mnemonic/BIPStandard.d.ts +8 -0
- package/build/mnemonic/BIPStandard.js +24 -0
- package/build/mnemonic/Mnemonic.d.ts +7 -2
- package/build/mnemonic/Mnemonic.js +48 -6
- package/build/opnet.d.ts +1 -0
- package/build/opnet.js +1 -0
- package/documentation/README.md +32 -0
- package/documentation/quantum-support/01-introduction.md +88 -0
- package/documentation/quantum-support/02-mnemonic-and-wallet.md +445 -0
- package/documentation/quantum-support/03-address-generation.md +329 -0
- package/documentation/quantum-support/04-message-signing.md +623 -0
- package/documentation/quantum-support/05-address-verification.md +307 -0
- package/documentation/quantum-support/README.md +65 -0
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/mnemonic/BIPStandard.ts +92 -0
- package/src/mnemonic/Mnemonic.ts +133 -8
- package/src/opnet.ts +1 -0
- package/test/derivePath.test.ts +280 -1
- package/doc/README.md +0 -0
- /package/{doc → documentation}/addresses/P2OP.md +0 -0
- /package/{doc → documentation}/addresses/P2WDA.md +0 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
# Address Generation Guide
|
|
2
|
+
|
|
3
|
+
## Table of Contents
|
|
4
|
+
- [Address Types Overview](#address-types-overview)
|
|
5
|
+
- [P2OP Addresses](#p2op-addresses)
|
|
6
|
+
- [Classical Addresses](#classical-addresses)
|
|
7
|
+
- [Address Class Usage](#address-class-usage)
|
|
8
|
+
- [Network Support](#network-support)
|
|
9
|
+
- [Address Comparison](#address-comparison)
|
|
10
|
+
|
|
11
|
+
## Address Types Overview
|
|
12
|
+
|
|
13
|
+
OPNet supports multiple address types for different use cases:
|
|
14
|
+
|
|
15
|
+
| Address Type | Format | Use Case | Quantum Support |
|
|
16
|
+
|-------------|--------|----------|----------------|
|
|
17
|
+
| **P2OP** | bc1s... (v16) | OPNet contract addresses | ✅ Quantum (contracts only) |
|
|
18
|
+
| **P2QRH** | TBD | Quantum-resistant user addresses | ✅ Quantum (NOT IMPLEMENTED) |
|
|
19
|
+
| **P2TR** | bc1p... (v1) | Taproot, privacy, efficiency | ❌ Classical |
|
|
20
|
+
| **P2WPKH** | bc1q... (v0) | SegWit, standard Bitcoin | ❌ Classical |
|
|
21
|
+
| **P2PKH** | 1... | Legacy Bitcoin | ❌ Classical |
|
|
22
|
+
| **P2SH** | 3... | Script hash, multi-sig | ❌ Classical |
|
|
23
|
+
| **P2WDA** | bc1q... (P2WSH) | Witness data authentication | ❌ Classical |
|
|
24
|
+
|
|
25
|
+
## P2OP Addresses
|
|
26
|
+
|
|
27
|
+
### What is P2OP?
|
|
28
|
+
|
|
29
|
+
**P2OP (Pay-to-OPNet)** is an address format for OPNet contract addresses:
|
|
30
|
+
|
|
31
|
+
- Uses **witness version 16** (OP_16)
|
|
32
|
+
- Encoded in **Bech32m format**
|
|
33
|
+
- Encodes the **quantum address** (SHA256 hash of ML-DSA public key) from `address.toHex()`
|
|
34
|
+
- Used exclusively for contract addresses on OPNet
|
|
35
|
+
- **Supports quantum** for contracts only
|
|
36
|
+
|
|
37
|
+
The quantum address (`address.toHex()`) is the user's universal public key - a 32-byte hash that can be encoded in various formats like P2OP.
|
|
38
|
+
|
|
39
|
+
> **Note:** For quantum-resistant user addresses, **P2QRH** (Pay-to-Quantum-Resistant-Hash) will be implemented in the future. P2OP currently only supports quantum for contract addresses.
|
|
40
|
+
|
|
41
|
+
## Classical Addresses
|
|
42
|
+
|
|
43
|
+
### P2TR (Taproot)
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
const wallet = mnemonic.derive(0);
|
|
47
|
+
|
|
48
|
+
// Mainnet Taproot
|
|
49
|
+
const p2trMainnet = wallet.p2tr;
|
|
50
|
+
console.log('P2TR Mainnet:', p2trMainnet);
|
|
51
|
+
// Output: bc1p...
|
|
52
|
+
|
|
53
|
+
// Testnet Taproot
|
|
54
|
+
const p2trTestnet = wallet.address.p2tr(networks.testnet);
|
|
55
|
+
console.log('P2TR Testnet:', p2trTestnet);
|
|
56
|
+
// Output: tb1p...
|
|
57
|
+
|
|
58
|
+
// Regtest Taproot
|
|
59
|
+
const p2trRegtest = wallet.address.p2tr(networks.regtest);
|
|
60
|
+
console.log('P2TR Regtest:', p2trRegtest);
|
|
61
|
+
// Output: bcrt1p...
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### P2WPKH (SegWit)
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
// Mainnet SegWit
|
|
68
|
+
const p2wpkhMainnet = wallet.p2wpkh;
|
|
69
|
+
console.log('P2WPKH Mainnet:', p2wpkhMainnet);
|
|
70
|
+
// Output: bc1q...
|
|
71
|
+
|
|
72
|
+
// Testnet SegWit
|
|
73
|
+
const p2wpkhTestnet = wallet.address.p2wpkh(networks.testnet);
|
|
74
|
+
console.log('P2WPKH Testnet:', p2wpkhTestnet);
|
|
75
|
+
// Output: tb1q...
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### P2PKH (Legacy)
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
// Mainnet Legacy
|
|
82
|
+
const p2pkhMainnet = wallet.p2pkh;
|
|
83
|
+
console.log('P2PKH Mainnet:', p2pkhMainnet);
|
|
84
|
+
// Output: 1...
|
|
85
|
+
|
|
86
|
+
// Testnet Legacy
|
|
87
|
+
const p2pkhTestnet = wallet.address.p2pkh(networks.testnet);
|
|
88
|
+
console.log('P2PKH Testnet:', p2pkhTestnet);
|
|
89
|
+
// Output: m... or n...
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### P2SH-P2WPKH (Wrapped SegWit)
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
// Mainnet Wrapped SegWit
|
|
96
|
+
const p2shMainnet = wallet.address.p2shp2wpkh(networks.bitcoin);
|
|
97
|
+
console.log('P2SH-P2WPKH Mainnet:', p2shMainnet);
|
|
98
|
+
// Output: 3...
|
|
99
|
+
|
|
100
|
+
// Testnet Wrapped SegWit
|
|
101
|
+
const p2shTestnet = wallet.address.p2shp2wpkh(networks.testnet);
|
|
102
|
+
console.log('P2SH-P2WPKH Testnet:', p2shTestnet);
|
|
103
|
+
// Output: 2...
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### P2WDA (Witness Data Authentication)
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
// P2WDA with authenticated data fields
|
|
110
|
+
const p2wdaAddress = wallet.address.p2wda(networks.bitcoin);
|
|
111
|
+
console.log('P2WDA:', p2wdaAddress);
|
|
112
|
+
// Output: P2WSH address (bc1q...) with special witness script
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Address Class Usage
|
|
116
|
+
|
|
117
|
+
### Creating Addresses Directly
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import { Address } from '@btc-vision/transaction';
|
|
121
|
+
import { networks } from '@btc-vision/bitcoin';
|
|
122
|
+
|
|
123
|
+
// From ML-DSA public key hash and classical public key
|
|
124
|
+
const mldsaHash = Buffer.alloc(32, 0x01); // SHA256 of ML-DSA public key
|
|
125
|
+
const classicalKey = Buffer.from('02...', 'hex'); // 33-byte compressed key
|
|
126
|
+
|
|
127
|
+
const address = new Address(mldsaHash, classicalKey);
|
|
128
|
+
|
|
129
|
+
// Generate addresses
|
|
130
|
+
const p2op = address.p2op(networks.bitcoin);
|
|
131
|
+
const p2tr = address.p2tr(networks.bitcoin);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### From String
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
// Create address from hex strings
|
|
138
|
+
const address = Address.fromString(
|
|
139
|
+
'0xabcdef1234567890...', // ML-DSA public key hash (32 bytes hex)
|
|
140
|
+
'0x02...' // Classical public key (33 bytes hex)
|
|
141
|
+
);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Dead Address
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
// Special "dead" address (all zeros)
|
|
148
|
+
const deadAddress = Address.dead();
|
|
149
|
+
console.log('Dead address:', deadAddress.toHex());
|
|
150
|
+
// Output: 0x0000000000000000000000000000000000000000000000000000000000000000
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Address Properties
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
const address = wallet.address;
|
|
157
|
+
|
|
158
|
+
// Quantum address (SHA256 hash of ML-DSA public key) - Universal public key
|
|
159
|
+
console.log('Quantum address:', address.toHex());
|
|
160
|
+
console.log('Quantum address buffer:', address.toBuffer());
|
|
161
|
+
|
|
162
|
+
// Classical public key
|
|
163
|
+
console.log('Classical key (hex):', address.tweakedToHex());
|
|
164
|
+
console.log('Classical key (buffer):', address.tweakedPublicKeyToBuffer());
|
|
165
|
+
|
|
166
|
+
// Original keys
|
|
167
|
+
console.log('Full ML-DSA public key:', address.mldsaPublicKey); // 1312-2592 bytes
|
|
168
|
+
console.log('Original classical key:', address.originalPublicKey);
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Network Support
|
|
172
|
+
|
|
173
|
+
### Mainnet
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
import { networks } from '@btc-vision/bitcoin';
|
|
177
|
+
|
|
178
|
+
const wallet = mnemonic.derive(0);
|
|
179
|
+
|
|
180
|
+
// All mainnet addresses
|
|
181
|
+
console.log('P2OP:', wallet.address.p2op(networks.bitcoin)); // bc1s...
|
|
182
|
+
console.log('P2TR:', wallet.address.p2tr(networks.bitcoin)); // bc1p...
|
|
183
|
+
console.log('P2WPKH:', wallet.address.p2wpkh(networks.bitcoin)); // bc1q...
|
|
184
|
+
console.log('P2PKH:', wallet.address.p2pkh(networks.bitcoin)); // 1...
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Testnet
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
// Testnet with different prefixes
|
|
191
|
+
const mnemonic = Mnemonic.generate(
|
|
192
|
+
undefined, // Default strength (24 words)
|
|
193
|
+
'', // No passphrase
|
|
194
|
+
networks.testnet, // Testnet network
|
|
195
|
+
MLDSASecurityLevel.LEVEL2 // Security level
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
const wallet = mnemonic.derive(0);
|
|
199
|
+
|
|
200
|
+
console.log('P2OP:', wallet.address.p2op(networks.testnet)); // tb1s...
|
|
201
|
+
console.log('P2TR:', wallet.address.p2tr(networks.testnet)); // tb1p...
|
|
202
|
+
console.log('P2WPKH:', wallet.address.p2wpkh(networks.testnet)); // tb1q...
|
|
203
|
+
console.log('P2PKH:', wallet.address.p2pkh(networks.testnet)); // m... or n...
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Regtest
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
// Regtest for local development
|
|
210
|
+
const regtestMnemonic = Mnemonic.generate(
|
|
211
|
+
undefined, // Default strength (24 words)
|
|
212
|
+
'', // No passphrase
|
|
213
|
+
networks.regtest, // Regtest network
|
|
214
|
+
MLDSASecurityLevel.LEVEL2 // Security level
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
const wallet = regtestMnemonic.derive(0);
|
|
218
|
+
|
|
219
|
+
console.log('P2OP:', wallet.address.p2op(networks.regtest)); // bcrt1s...
|
|
220
|
+
console.log('P2TR:', wallet.address.p2tr(networks.regtest)); // bcrt1p...
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Address Comparison
|
|
224
|
+
|
|
225
|
+
### Equality
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
const wallet1 = mnemonic.derive(0);
|
|
229
|
+
const wallet2 = mnemonic.derive(0);
|
|
230
|
+
const wallet3 = mnemonic.derive(1);
|
|
231
|
+
|
|
232
|
+
const addr1 = wallet1.address;
|
|
233
|
+
const addr2 = wallet2.address;
|
|
234
|
+
const addr3 = wallet3.address;
|
|
235
|
+
|
|
236
|
+
// Same derivation index = same address
|
|
237
|
+
console.log(addr1.equals(addr2)); // true
|
|
238
|
+
|
|
239
|
+
// Different index = different address
|
|
240
|
+
console.log(addr1.equals(addr3)); // false
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Ordering
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
const addresses = [
|
|
247
|
+
mnemonic.derive(5).address,
|
|
248
|
+
mnemonic.derive(2).address,
|
|
249
|
+
mnemonic.derive(8).address,
|
|
250
|
+
mnemonic.derive(1).address,
|
|
251
|
+
];
|
|
252
|
+
|
|
253
|
+
// Less than comparison
|
|
254
|
+
console.log(addresses[0].lessThan(addresses[1]));
|
|
255
|
+
|
|
256
|
+
// Greater than comparison
|
|
257
|
+
console.log(addresses[0].greaterThan(addresses[1]));
|
|
258
|
+
|
|
259
|
+
// Sort addresses
|
|
260
|
+
addresses.sort((a, b) => {
|
|
261
|
+
if (a.lessThan(b)) return -1;
|
|
262
|
+
if (a.greaterThan(b)) return 1;
|
|
263
|
+
return 0;
|
|
264
|
+
});
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## Time-Locked Addresses (CSV)
|
|
268
|
+
|
|
269
|
+
### CheckSequenceVerify Addresses
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
// Create time-locked address (100 blocks)
|
|
273
|
+
const duration = 100;
|
|
274
|
+
const csvAddress = wallet.address.toCSV(duration, networks.bitcoin);
|
|
275
|
+
|
|
276
|
+
console.log('CSV Address (100 blocks):', csvAddress);
|
|
277
|
+
|
|
278
|
+
// Different durations
|
|
279
|
+
const addr1Day = wallet.address.toCSV(144, networks.bitcoin); // ~1 day
|
|
280
|
+
const addr1Week = wallet.address.toCSV(1008, networks.bitcoin); // ~1 week
|
|
281
|
+
const addr1Month = wallet.address.toCSV(4320, networks.bitcoin); // ~1 month
|
|
282
|
+
|
|
283
|
+
// Valid range: 1 to 65535 blocks
|
|
284
|
+
const minLock = wallet.address.toCSV(1, networks.bitcoin);
|
|
285
|
+
const maxLock = wallet.address.toCSV(65535, networks.bitcoin);
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## Complete Example
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
import { Mnemonic, MLDSASecurityLevel } from '@btc-vision/transaction';
|
|
292
|
+
import { networks } from '@btc-vision/bitcoin';
|
|
293
|
+
|
|
294
|
+
// Generate wallet with ML-DSA support
|
|
295
|
+
const mnemonic = Mnemonic.generate(
|
|
296
|
+
undefined, // Default strength (24 words)
|
|
297
|
+
'', // No passphrase
|
|
298
|
+
networks.bitcoin, // Mainnet
|
|
299
|
+
MLDSASecurityLevel.LEVEL2 // Security level
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
const wallet = mnemonic.derive(0);
|
|
303
|
+
const address = wallet.address;
|
|
304
|
+
|
|
305
|
+
console.log('=== Universal Public Key (Quantum Address) ===');
|
|
306
|
+
console.log('Quantum Address:', address.toHex()); // SHA256 hash of ML-DSA public key
|
|
307
|
+
console.log('ML-DSA Key Size:', address.mldsaPublicKey?.length, 'bytes');
|
|
308
|
+
|
|
309
|
+
console.log('\n=== P2OP Address (Contract Address) ===');
|
|
310
|
+
console.log('P2OP:', address.p2op(networks.bitcoin)); // Encoded form of quantum address
|
|
311
|
+
|
|
312
|
+
console.log('\n=== Classical Addresses ===');
|
|
313
|
+
console.log('P2TR (Taproot):', address.p2tr(networks.bitcoin));
|
|
314
|
+
console.log('P2WPKH (SegWit):', address.p2wpkh(networks.bitcoin));
|
|
315
|
+
console.log('P2PKH (Legacy):', address.p2pkh(networks.bitcoin));
|
|
316
|
+
console.log('P2SH-P2WPKH:', address.p2shp2wpkh(networks.bitcoin));
|
|
317
|
+
|
|
318
|
+
console.log('\n=== Testnet Addresses ===');
|
|
319
|
+
console.log('P2OP:', address.p2op(networks.testnet));
|
|
320
|
+
console.log('P2TR:', address.p2tr(networks.testnet));
|
|
321
|
+
|
|
322
|
+
console.log('\n=== Time-Locked Address ===');
|
|
323
|
+
console.log('CSV (100 blocks):', address.toCSV(100, networks.bitcoin));
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
## Next Steps
|
|
327
|
+
|
|
328
|
+
- [Message Signing](./04-message-signing.md) - Sign messages with ML-DSA and Schnorr
|
|
329
|
+
- [Address Verification](./05-address-verification.md) - Validate addresses and keys
|