@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
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.7.
|
|
1
|
+
export declare const version = "1.7.1";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare enum BIPStandard {
|
|
2
|
+
BIP44 = 44,
|
|
3
|
+
BIP49 = 49,
|
|
4
|
+
BIP84 = 84,
|
|
5
|
+
BIP86 = 86
|
|
6
|
+
}
|
|
7
|
+
export declare function getBIPDescription(standard: BIPStandard): string;
|
|
8
|
+
export declare function buildBIPPath(standard: BIPStandard, coinType: number, account: number, change: number, addressIndex: number): string;
|
|
@@ -2,6 +2,9 @@ import { BIP32Interface, MLDSASecurityLevel, QuantumBIP32Interface } from '@btc-
|
|
|
2
2
|
import { Network } from '@btc-vision/bitcoin';
|
|
3
3
|
import { Wallet } from '../keypair/Wallet.js';
|
|
4
4
|
import { MnemonicStrength } from './MnemonicStrength.js';
|
|
5
|
+
import { BIPStandard } from './BIPStandard.js';
|
|
6
|
+
import { AddressTypes } from '../keypair/AddressVerificator.js';
|
|
7
|
+
export { BIPStandard, getBIPDescription } from './BIPStandard.js';
|
|
5
8
|
export declare class Mnemonic {
|
|
6
9
|
private readonly _phrase;
|
|
7
10
|
private readonly _passphrase;
|
|
@@ -18,8 +21,10 @@ export declare class Mnemonic {
|
|
|
18
21
|
static generatePhrase(strength?: MnemonicStrength): string;
|
|
19
22
|
static generate(strength?: MnemonicStrength, passphrase?: string, network?: Network, securityLevel?: MLDSASecurityLevel): Mnemonic;
|
|
20
23
|
static validate(phrase: string): boolean;
|
|
21
|
-
derive(index?: number, account?: number, isChange?: boolean): Wallet;
|
|
22
|
-
|
|
24
|
+
derive(index?: number, account?: number, isChange?: boolean, bipStandard?: BIPStandard): Wallet;
|
|
25
|
+
deriveUnisat(addressType?: AddressTypes, index?: number, account?: number, isChange?: boolean): Wallet;
|
|
26
|
+
deriveMultipleUnisat(addressType?: AddressTypes, count?: number, startIndex?: number, account?: number, isChange?: boolean): Wallet[];
|
|
27
|
+
deriveMultiple(count: number, startIndex?: number, account?: number, isChange?: boolean, bipStandard?: BIPStandard): Wallet[];
|
|
23
28
|
deriveCustomPath(classicalPath: string, quantumPath: string): Wallet;
|
|
24
29
|
getClassicalRoot(): BIP32Interface;
|
|
25
30
|
getQuantumRoot(): QuantumBIP32Interface;
|
package/browser/src/opnet.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export * from './keypair/MessageSigner.js';
|
|
|
21
21
|
export * from './keypair/Wallet.js';
|
|
22
22
|
export * from './mnemonic/Mnemonic.js';
|
|
23
23
|
export * from './mnemonic/MnemonicStrength.js';
|
|
24
|
+
export * from './mnemonic/BIPStandard.js';
|
|
24
25
|
export { MLDSASecurityLevel, MLDSAKeyPair, QuantumBIP32Interface, QuantumBIP32API, QuantumSigner, QuantumBIP32Factory, QuantumDerivationPath, } from '@btc-vision/bip32';
|
|
25
26
|
export * from './metadata/ContractBaseMetadata.js';
|
|
26
27
|
export * from './network/ChainId.js';
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.7.
|
|
1
|
+
export declare const version = "1.7.1";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.7.
|
|
1
|
+
export const version = '1.7.1';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare enum BIPStandard {
|
|
2
|
+
BIP44 = 44,
|
|
3
|
+
BIP49 = 49,
|
|
4
|
+
BIP84 = 84,
|
|
5
|
+
BIP86 = 86
|
|
6
|
+
}
|
|
7
|
+
export declare function getBIPDescription(standard: BIPStandard): string;
|
|
8
|
+
export declare function buildBIPPath(standard: BIPStandard, coinType: number, account: number, change: number, addressIndex: number): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export var BIPStandard;
|
|
2
|
+
(function (BIPStandard) {
|
|
3
|
+
BIPStandard[BIPStandard["BIP44"] = 44] = "BIP44";
|
|
4
|
+
BIPStandard[BIPStandard["BIP49"] = 49] = "BIP49";
|
|
5
|
+
BIPStandard[BIPStandard["BIP84"] = 84] = "BIP84";
|
|
6
|
+
BIPStandard[BIPStandard["BIP86"] = 86] = "BIP86";
|
|
7
|
+
})(BIPStandard || (BIPStandard = {}));
|
|
8
|
+
export function getBIPDescription(standard) {
|
|
9
|
+
switch (standard) {
|
|
10
|
+
case BIPStandard.BIP44:
|
|
11
|
+
return 'BIP44: Legacy addresses (P2PKH), widely used by Unisat and other wallets';
|
|
12
|
+
case BIPStandard.BIP49:
|
|
13
|
+
return 'BIP49: Wrapped SegWit addresses (P2SH-P2WPKH)';
|
|
14
|
+
case BIPStandard.BIP84:
|
|
15
|
+
return 'BIP84: Native SegWit addresses (P2WPKH) - DEFAULT';
|
|
16
|
+
case BIPStandard.BIP86:
|
|
17
|
+
return 'BIP86: Taproot addresses (P2TR)';
|
|
18
|
+
default:
|
|
19
|
+
return 'Unknown BIP standard';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function buildBIPPath(standard, coinType, account, change, addressIndex) {
|
|
23
|
+
return `m/${standard}'/${coinType}'/${account}'/${change}/${addressIndex}`;
|
|
24
|
+
}
|
|
@@ -2,6 +2,9 @@ import { BIP32Interface, MLDSASecurityLevel, QuantumBIP32Interface } from '@btc-
|
|
|
2
2
|
import { Network } from '@btc-vision/bitcoin';
|
|
3
3
|
import { Wallet } from '../keypair/Wallet.js';
|
|
4
4
|
import { MnemonicStrength } from './MnemonicStrength.js';
|
|
5
|
+
import { BIPStandard } from './BIPStandard.js';
|
|
6
|
+
import { AddressTypes } from '../keypair/AddressVerificator.js';
|
|
7
|
+
export { BIPStandard, getBIPDescription } from './BIPStandard.js';
|
|
5
8
|
export declare class Mnemonic {
|
|
6
9
|
private readonly _phrase;
|
|
7
10
|
private readonly _passphrase;
|
|
@@ -18,8 +21,10 @@ export declare class Mnemonic {
|
|
|
18
21
|
static generatePhrase(strength?: MnemonicStrength): string;
|
|
19
22
|
static generate(strength?: MnemonicStrength, passphrase?: string, network?: Network, securityLevel?: MLDSASecurityLevel): Mnemonic;
|
|
20
23
|
static validate(phrase: string): boolean;
|
|
21
|
-
derive(index?: number, account?: number, isChange?: boolean): Wallet;
|
|
22
|
-
|
|
24
|
+
derive(index?: number, account?: number, isChange?: boolean, bipStandard?: BIPStandard): Wallet;
|
|
25
|
+
deriveUnisat(addressType?: AddressTypes, index?: number, account?: number, isChange?: boolean): Wallet;
|
|
26
|
+
deriveMultipleUnisat(addressType?: AddressTypes, count?: number, startIndex?: number, account?: number, isChange?: boolean): Wallet[];
|
|
27
|
+
deriveMultiple(count: number, startIndex?: number, account?: number, isChange?: boolean, bipStandard?: BIPStandard): Wallet[];
|
|
23
28
|
deriveCustomPath(classicalPath: string, quantumPath: string): Wallet;
|
|
24
29
|
getClassicalRoot(): BIP32Interface;
|
|
25
30
|
getQuantumRoot(): QuantumBIP32Interface;
|
|
@@ -4,8 +4,11 @@ import * as ecc from '@bitcoinerlab/secp256k1';
|
|
|
4
4
|
import { initEccLib, networks } from '@btc-vision/bitcoin';
|
|
5
5
|
import { Wallet } from '../keypair/Wallet.js';
|
|
6
6
|
import { MnemonicStrength } from './MnemonicStrength.js';
|
|
7
|
+
import { BIPStandard, buildBIPPath } from './BIPStandard.js';
|
|
8
|
+
import { AddressTypes } from '../keypair/AddressVerificator.js';
|
|
7
9
|
initEccLib(ecc);
|
|
8
10
|
const bip32 = BIP32Factory(ecc);
|
|
11
|
+
export { BIPStandard, getBIPDescription } from './BIPStandard.js';
|
|
9
12
|
export class Mnemonic {
|
|
10
13
|
constructor(phrase, passphrase = '', network = networks.bitcoin, securityLevel = MLDSASecurityLevel.LEVEL2) {
|
|
11
14
|
if (!bip39.validateMnemonic(phrase)) {
|
|
@@ -41,8 +44,8 @@ export class Mnemonic {
|
|
|
41
44
|
static validate(phrase) {
|
|
42
45
|
return bip39.validateMnemonic(phrase);
|
|
43
46
|
}
|
|
44
|
-
derive(index = 0, account = 0, isChange = false) {
|
|
45
|
-
const classicalPath = this.buildClassicalPath(account, index, isChange);
|
|
47
|
+
derive(index = 0, account = 0, isChange = false, bipStandard = BIPStandard.BIP84) {
|
|
48
|
+
const classicalPath = this.buildClassicalPath(account, index, isChange, bipStandard);
|
|
46
49
|
const classicalChild = this._classicalRoot.derivePath(classicalPath);
|
|
47
50
|
if (!classicalChild.privateKey) {
|
|
48
51
|
throw new Error(`Failed to derive classical private key at index ${index}`);
|
|
@@ -54,10 +57,49 @@ export class Mnemonic {
|
|
|
54
57
|
}
|
|
55
58
|
return new Wallet(Buffer.from(classicalChild.privateKey).toString('hex'), Buffer.from(quantumChild.privateKey).toString('hex'), this._network, this._securityLevel);
|
|
56
59
|
}
|
|
57
|
-
|
|
60
|
+
deriveUnisat(addressType = AddressTypes.P2TR, index = 0, account = 0, isChange = false) {
|
|
61
|
+
let purpose;
|
|
62
|
+
switch (addressType) {
|
|
63
|
+
case AddressTypes.P2PKH:
|
|
64
|
+
purpose = 44;
|
|
65
|
+
break;
|
|
66
|
+
case AddressTypes.P2SH_OR_P2SH_P2WPKH:
|
|
67
|
+
purpose = 49;
|
|
68
|
+
break;
|
|
69
|
+
case AddressTypes.P2WPKH:
|
|
70
|
+
purpose = 84;
|
|
71
|
+
break;
|
|
72
|
+
case AddressTypes.P2TR:
|
|
73
|
+
purpose = 86;
|
|
74
|
+
break;
|
|
75
|
+
default:
|
|
76
|
+
throw new Error(`Unsupported address type: ${addressType}`);
|
|
77
|
+
}
|
|
78
|
+
const coinType = this.getCoinType();
|
|
79
|
+
const change = isChange ? 1 : 0;
|
|
80
|
+
const classicalPath = `m/${purpose}'/0'/${account}'/${change}/${index}`;
|
|
81
|
+
const classicalChild = this._classicalRoot.derivePath(classicalPath);
|
|
82
|
+
if (!classicalChild.privateKey) {
|
|
83
|
+
throw new Error(`Failed to derive classical private key at path ${classicalPath}`);
|
|
84
|
+
}
|
|
85
|
+
const quantumPath = `m/360'/${coinType}'/${account}'/${change}/${index}`;
|
|
86
|
+
const quantumChild = this._quantumRoot.derivePath(quantumPath);
|
|
87
|
+
if (!quantumChild.privateKey) {
|
|
88
|
+
throw new Error(`Failed to derive quantum private key at path ${quantumPath}`);
|
|
89
|
+
}
|
|
90
|
+
return new Wallet(Buffer.from(classicalChild.privateKey).toString('hex'), Buffer.from(quantumChild.privateKey).toString('hex'), this._network, this._securityLevel);
|
|
91
|
+
}
|
|
92
|
+
deriveMultipleUnisat(addressType = AddressTypes.P2TR, count = 5, startIndex = 0, account = 0, isChange = false) {
|
|
93
|
+
const wallets = [];
|
|
94
|
+
for (let i = 0; i < count; i++) {
|
|
95
|
+
wallets.push(this.deriveUnisat(addressType, startIndex + i, account, isChange));
|
|
96
|
+
}
|
|
97
|
+
return wallets;
|
|
98
|
+
}
|
|
99
|
+
deriveMultiple(count, startIndex = 0, account = 0, isChange = false, bipStandard = BIPStandard.BIP84) {
|
|
58
100
|
const wallets = [];
|
|
59
101
|
for (let i = 0; i < count; i++) {
|
|
60
|
-
wallets.push(this.derive(startIndex + i, account, isChange));
|
|
102
|
+
wallets.push(this.derive(startIndex + i, account, isChange, bipStandard));
|
|
61
103
|
}
|
|
62
104
|
return wallets;
|
|
63
105
|
}
|
|
@@ -78,10 +120,10 @@ export class Mnemonic {
|
|
|
78
120
|
getQuantumRoot() {
|
|
79
121
|
return this._quantumRoot;
|
|
80
122
|
}
|
|
81
|
-
buildClassicalPath(account, index, isChange) {
|
|
123
|
+
buildClassicalPath(account, index, isChange, bipStandard = BIPStandard.BIP84) {
|
|
82
124
|
const coinType = this.getCoinType();
|
|
83
125
|
const change = isChange ? 1 : 0;
|
|
84
|
-
return
|
|
126
|
+
return buildBIPPath(bipStandard, coinType, account, change, index);
|
|
85
127
|
}
|
|
86
128
|
buildQuantumPath(account, index, isChange) {
|
|
87
129
|
const coinType = this.getCoinType();
|
package/build/opnet.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export * from './keypair/MessageSigner.js';
|
|
|
21
21
|
export * from './keypair/Wallet.js';
|
|
22
22
|
export * from './mnemonic/Mnemonic.js';
|
|
23
23
|
export * from './mnemonic/MnemonicStrength.js';
|
|
24
|
+
export * from './mnemonic/BIPStandard.js';
|
|
24
25
|
export { MLDSASecurityLevel, MLDSAKeyPair, QuantumBIP32Interface, QuantumBIP32API, QuantumSigner, QuantumBIP32Factory, QuantumDerivationPath, } from '@btc-vision/bip32';
|
|
25
26
|
export * from './metadata/ContractBaseMetadata.js';
|
|
26
27
|
export * from './network/ChainId.js';
|
package/build/opnet.js
CHANGED
|
@@ -20,6 +20,7 @@ export * from './keypair/MessageSigner.js';
|
|
|
20
20
|
export * from './keypair/Wallet.js';
|
|
21
21
|
export * from './mnemonic/Mnemonic.js';
|
|
22
22
|
export * from './mnemonic/MnemonicStrength.js';
|
|
23
|
+
export * from './mnemonic/BIPStandard.js';
|
|
23
24
|
export { MLDSASecurityLevel, QuantumBIP32Factory, QuantumDerivationPath, } from '@btc-vision/bip32';
|
|
24
25
|
export * from './metadata/ContractBaseMetadata.js';
|
|
25
26
|
export * from './network/ChainId.js';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# OPNet Transaction Library Documentation
|
|
2
|
+
|
|
3
|
+
Complete documentation for the OPNet Transaction Library - Bitcoin transaction building with quantum-resistant cryptography support.
|
|
4
|
+
|
|
5
|
+
## Documentation Index
|
|
6
|
+
|
|
7
|
+
### Core Concepts
|
|
8
|
+
|
|
9
|
+
#### Address Types
|
|
10
|
+
- **[P2OP](./addresses/P2OP.md)** - Pay-to-OPNet contract addresses (witness v16, quantum support for contracts only)
|
|
11
|
+
- **P2QRH** - Pay-to-Quantum-Resistant-Hash user addresses (NOT IMPLEMENTED)
|
|
12
|
+
- **P2WDA** - Pay-to-Witness-Data-Authentication addresses
|
|
13
|
+
- **P2TR** - Pay-to-Taproot addresses (witness v1)
|
|
14
|
+
- **P2WPKH** - Pay-to-Witness-PubKey-Hash (SegWit v0)
|
|
15
|
+
- **P2PKH** - Pay-to-PubKey-Hash (legacy)
|
|
16
|
+
- **P2SH** - Pay-to-Script-Hash
|
|
17
|
+
|
|
18
|
+
#### Quantum Address
|
|
19
|
+
- **Universal Public Key** - `address.toHex()` returns the SHA256 hash of ML-DSA public key (32 bytes)
|
|
20
|
+
- This is the user's universal identifier across the OPNet protocol
|
|
21
|
+
|
|
22
|
+
### Quantum Support (ML-DSA)
|
|
23
|
+
|
|
24
|
+
**[Complete Quantum Support Guide](./quantum-support/README.md)**
|
|
25
|
+
|
|
26
|
+
- [Introduction to ML-DSA](./quantum-support/01-introduction.md) - Post-quantum cryptography overview
|
|
27
|
+
- [Mnemonic & Wallet Management](./quantum-support/02-mnemonic-and-wallet.md) - BIP39 + BIP360 quantum wallets
|
|
28
|
+
- [Address Generation](./quantum-support/03-address-generation.md) - All address types
|
|
29
|
+
- [Message Signing](./quantum-support/04-message-signing.md) - ML-DSA and Schnorr signatures
|
|
30
|
+
- [Address Verification](./quantum-support/05-address-verification.md) - Validation and type detection
|
|
31
|
+
- [Complete Examples](./quantum-support/06-complete-examples.md) - Production-ready code
|
|
32
|
+
- [Complete Message Signing Example](./quantum-support/complete-message-signing-example.md) - Full working example with proper typings
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# ML-DSA Quantum Support - Introduction
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
OPNet now supports **ML-DSA (Module-Lattice-Based Digital Signature Algorithm)**, also known as FIPS 204, providing quantum-resistant cryptography alongside traditional ECDSA/Schnorr signatures. This hybrid approach ensures your transactions and signatures remain secure even when quantum computers become capable of breaking classical cryptographic schemes.
|
|
6
|
+
|
|
7
|
+
## What is ML-DSA?
|
|
8
|
+
|
|
9
|
+
ML-DSA is a **post-quantum cryptographic algorithm** standardized by NIST as FIPS 204. It uses lattice-based mathematics that are believed to be resistant to attacks by both classical and quantum computers.
|
|
10
|
+
|
|
11
|
+
## Security Levels
|
|
12
|
+
|
|
13
|
+
ML-DSA offers three security levels with different key sizes and security guarantees:
|
|
14
|
+
|
|
15
|
+
| Level | Name | Public Key Size | Signature Size | Security Equivalent | Status |
|
|
16
|
+
|-------|------|----------------|----------------|-------------------|--------|
|
|
17
|
+
| **LEVEL2** | ML-DSA-44 | 1,312 bytes | 2,420 bytes | AES-128 | ✅ **RECOMMENDED DEFAULT (BIP360)** |
|
|
18
|
+
| **LEVEL3** | ML-DSA-65 | 1,952 bytes | 3,309 bytes | AES-192 | Optional |
|
|
19
|
+
| **LEVEL5** | ML-DSA-87 | 2,592 bytes | 4,627 bytes | AES-256 | Optional (maximum security) |
|
|
20
|
+
|
|
21
|
+
**Recommendation**: Use **LEVEL2** (ML-DSA-44) - this is the **BIP360 default** and provides strong quantum resistance with reasonable key sizes. Use LEVEL3 or LEVEL5 only if you need higher security for specific high-value applications.
|
|
22
|
+
|
|
23
|
+
## Hybrid Architecture
|
|
24
|
+
|
|
25
|
+
OPNet uses a **dual-key system** for maximum compatibility and security:
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
┌─────────────────────────────────────────────────────────┐
|
|
29
|
+
│ OPNet Wallet │
|
|
30
|
+
├─────────────────────────────────────────────────────────┤
|
|
31
|
+
│ │
|
|
32
|
+
│ Classical Keys (ECDSA/Schnorr) Quantum Keys (ML-DSA)│
|
|
33
|
+
│ ├─ 32-byte private key ├─ Private key │
|
|
34
|
+
│ ├─ 33-byte public key ├─ 1312-2592 byte │
|
|
35
|
+
│ ├─ Bitcoin script execution │ public key │
|
|
36
|
+
│ └─ P2TR, P2WPKH addresses └─ Quantum address │
|
|
37
|
+
│ │
|
|
38
|
+
│ SHA256 Hash of ML-DSA Public Key → Universal Public Key│
|
|
39
|
+
│ (address.toHex() - 32 bytes) │
|
|
40
|
+
│ │
|
|
41
|
+
└─────────────────────────────────────────────────────────┘
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### How It Works
|
|
45
|
+
|
|
46
|
+
1. **Universal Public Key**: ML-DSA public keys are **SHA256-hashed to 32 bytes** via `address.toHex()` - this is the user's universal identifier
|
|
47
|
+
2. **Classical Keys**: Maintained separately for Bitcoin transaction signing (P2TR, P2WPKH, etc.)
|
|
48
|
+
3. **Quantum Keys**: Provide quantum-resistant authentication and signatures
|
|
49
|
+
4. **P2OP Addresses**: Contract address format (witness version 16) - for OPNet contracts ONLY, not for user addresses
|
|
50
|
+
|
|
51
|
+
## Quick Start
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { Mnemonic, MessageSigner, MLDSASecurityLevel } from '@btc-vision/transaction';
|
|
55
|
+
import { networks } from '@btc-vision/bitcoin';
|
|
56
|
+
|
|
57
|
+
// Generate a new quantum-resistant wallet
|
|
58
|
+
const mnemonic = Mnemonic.generate(undefined, '', networks.bitcoin, MLDSASecurityLevel.LEVEL2);
|
|
59
|
+
|
|
60
|
+
// Derive a wallet
|
|
61
|
+
const wallet = mnemonic.derive(0);
|
|
62
|
+
|
|
63
|
+
// Get quantum address (universal public key)
|
|
64
|
+
const quantumAddress = wallet.address.toHex();
|
|
65
|
+
console.log('Quantum Address:', quantumAddress);
|
|
66
|
+
|
|
67
|
+
// Sign a message with ML-DSA
|
|
68
|
+
const message = 'Hello, Quantum World!';
|
|
69
|
+
const signature = MessageSigner.signMLDSAMessage(wallet.mldsaKeypair, message);
|
|
70
|
+
console.log('ML-DSA Signature:', Buffer.from(signature.signature).toString('hex'));
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## What's New
|
|
74
|
+
|
|
75
|
+
This implementation adds:
|
|
76
|
+
|
|
77
|
+
1. **Mnemonic Support** - BIP39 + BIP360 for quantum key derivation
|
|
78
|
+
2. **Wallet Management** - Hybrid classical + quantum key management
|
|
79
|
+
3. **Universal Public Key** - `address.toHex()` provides the user's quantum address (SHA256 of ML-DSA public key)
|
|
80
|
+
4. **Message Signing** - ML-DSA and Schnorr signature support
|
|
81
|
+
5. **Address Verification** - Validation for ML-DSA public keys and classical address types
|
|
82
|
+
6. **Security Levels** - Three levels of quantum resistance (LEVEL2, LEVEL3, LEVEL5)
|
|
83
|
+
|
|
84
|
+
## Next Steps
|
|
85
|
+
|
|
86
|
+
- [Mnemonic & Wallet Guide](./02-mnemonic-and-wallet.md) - Learn to generate and manage quantum wallets
|
|
87
|
+
- [Address Generation](./03-address-generation.md) - Generate P2OP and other addresses
|
|
88
|
+
- [Message Signing](./04-message-signing.md) - Sign and verify messages
|