@btc-vision/transaction 1.6.19 → 1.7.0

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.
Files changed (141) hide show
  1. package/browser/index.js +1 -1
  2. package/browser/index.js.LICENSE.txt +2 -0
  3. package/browser/src/_version.d.ts +1 -0
  4. package/browser/{epoch → src/epoch}/interfaces/IChallengeSolution.d.ts +2 -0
  5. package/browser/{keypair → src/keypair}/Address.d.ts +7 -4
  6. package/browser/{keypair → src/keypair}/AddressVerificator.d.ts +3 -0
  7. package/browser/{keypair → src/keypair}/EcKeyPair.d.ts +3 -2
  8. package/browser/{keypair → src/keypair}/MessageSigner.d.ts +9 -0
  9. package/browser/src/keypair/Wallet.d.ts +47 -0
  10. package/browser/{keypair → src/keypair}/interfaces/IWallet.d.ts +2 -0
  11. package/browser/src/mnemonic/Mnemonic.d.ts +29 -0
  12. package/browser/src/mnemonic/MnemonicStrength.d.ts +7 -0
  13. package/browser/{opnet.d.ts → src/opnet.d.ts} +4 -0
  14. package/browser/src/transaction/browser/types/OPWallet.d.ts +14 -0
  15. package/browser/test/address.test.d.ts +1 -0
  16. package/browser/test/addressverificator-mldsa.test.d.ts +1 -0
  17. package/browser/test/derivePath.test.d.ts +1 -0
  18. package/browser/test/messagesigner-mldsa.test.d.ts +1 -0
  19. package/browser/test/messagesigner-schnorr.test.d.ts +1 -0
  20. package/browser/test/network-awareness.test.d.ts +1 -0
  21. package/build/_version.d.ts +1 -1
  22. package/build/_version.js +1 -1
  23. package/build/crypto/crypto-browser.d.ts +11 -0
  24. package/build/crypto/crypto-browser.js +56 -0
  25. package/build/epoch/ChallengeSolution.js +3 -2
  26. package/build/epoch/interfaces/IChallengeSolution.d.ts +2 -0
  27. package/build/keypair/Address.d.ts +7 -4
  28. package/build/keypair/Address.js +88 -37
  29. package/build/keypair/AddressVerificator.d.ts +3 -0
  30. package/build/keypair/AddressVerificator.js +49 -1
  31. package/build/keypair/EcKeyPair.d.ts +3 -2
  32. package/build/keypair/EcKeyPair.js +17 -3
  33. package/build/keypair/MessageSigner.d.ts +9 -0
  34. package/build/keypair/MessageSigner.js +23 -0
  35. package/build/keypair/Wallet.d.ts +20 -3
  36. package/build/keypair/Wallet.js +108 -9
  37. package/build/keypair/interfaces/IWallet.d.ts +2 -0
  38. package/build/mnemonic/Mnemonic.d.ts +29 -0
  39. package/build/mnemonic/Mnemonic.js +98 -0
  40. package/build/mnemonic/MnemonicStrength.d.ts +7 -0
  41. package/build/mnemonic/MnemonicStrength.js +8 -0
  42. package/build/opnet.d.ts +4 -0
  43. package/build/opnet.js +4 -0
  44. package/build/transaction/browser/types/OPWallet.d.ts +14 -0
  45. package/build/transaction/browser/types/OPWallet.js +6 -0
  46. package/gulpfile.js +2 -2
  47. package/package.json +25 -17
  48. package/src/_version.ts +1 -1
  49. package/src/epoch/ChallengeSolution.ts +3 -2
  50. package/src/epoch/interfaces/IChallengeSolution.ts +2 -0
  51. package/src/keypair/Address.ts +145 -43
  52. package/src/keypair/AddressVerificator.ts +87 -2
  53. package/src/keypair/EcKeyPair.ts +58 -6
  54. package/src/keypair/MessageSigner.ts +58 -0
  55. package/src/keypair/Wallet.ts +339 -57
  56. package/src/keypair/interfaces/IWallet.ts +13 -3
  57. package/src/mnemonic/Mnemonic.ts +340 -0
  58. package/src/mnemonic/MnemonicStrength.ts +12 -0
  59. package/src/network/ChainId.ts +1 -4
  60. package/src/opnet.ts +16 -0
  61. package/src/transaction/browser/types/OPWallet.ts +73 -0
  62. package/test/address.test.ts +1068 -0
  63. package/test/addressverificator-mldsa.test.ts +473 -0
  64. package/test/derivePath.test.ts +234 -0
  65. package/test/messagesigner-mldsa.test.ts +1060 -0
  66. package/test/messagesigner-schnorr.test.ts +1011 -0
  67. package/test/network-awareness.test.ts +163 -0
  68. package/tsconfig.json +1 -1
  69. package/vitest.config.ts +21 -0
  70. package/browser/_version.d.ts +0 -1
  71. package/browser/keypair/Wallet.d.ts +0 -30
  72. /package/browser/{abi → src/abi}/ABICoder.d.ts +0 -0
  73. /package/browser/{buffer → src/buffer}/BinaryReader.d.ts +0 -0
  74. /package/browser/{buffer → src/buffer}/BinaryWriter.d.ts +0 -0
  75. /package/browser/{bytecode → src/bytecode}/Compressor.d.ts +0 -0
  76. /package/browser/{consensus → src/consensus}/Consensus.d.ts +0 -0
  77. /package/browser/{consensus → src/consensus}/ConsensusConfig.d.ts +0 -0
  78. /package/browser/{consensus → src/consensus}/metadata/RoswellConsensus.d.ts +0 -0
  79. /package/browser/{crypto → src/crypto}/crypto-browser.d.ts +0 -0
  80. /package/browser/{crypto → src/crypto}/crypto.d.ts +0 -0
  81. /package/browser/{deterministic → src/deterministic}/AddressMap.d.ts +0 -0
  82. /package/browser/{deterministic → src/deterministic}/AddressSet.d.ts +0 -0
  83. /package/browser/{deterministic → src/deterministic}/DeterministicMap.d.ts +0 -0
  84. /package/browser/{deterministic → src/deterministic}/DeterministicSet.d.ts +0 -0
  85. /package/browser/{deterministic → src/deterministic}/Map.d.ts +0 -0
  86. /package/browser/{epoch → src/epoch}/ChallengeSolution.d.ts +0 -0
  87. /package/browser/{epoch → src/epoch}/validator/EpochValidator.d.ts +0 -0
  88. /package/browser/{event → src/event}/NetEvent.d.ts +0 -0
  89. /package/browser/{generators → src/generators}/AddressGenerator.d.ts +0 -0
  90. /package/browser/{generators → src/generators}/Features.d.ts +0 -0
  91. /package/browser/{generators → src/generators}/Generator.d.ts +0 -0
  92. /package/browser/{generators → src/generators}/builders/CalldataGenerator.d.ts +0 -0
  93. /package/browser/{generators → src/generators}/builders/CustomGenerator.d.ts +0 -0
  94. /package/browser/{generators → src/generators}/builders/DeploymentGenerator.d.ts +0 -0
  95. /package/browser/{generators → src/generators}/builders/LegacyCalldataGenerator.d.ts +0 -0
  96. /package/browser/{generators → src/generators}/builders/MultiSignGenerator.d.ts +0 -0
  97. /package/browser/{generators → src/generators}/builders/P2WDAGenerator.d.ts +0 -0
  98. /package/browser/{index.d.ts → src/index.d.ts} +0 -0
  99. /package/browser/{keypair → src/keypair}/Secp256k1PointDeriver.d.ts +0 -0
  100. /package/browser/{metadata → src/metadata}/ContractBaseMetadata.d.ts +0 -0
  101. /package/browser/{metadata → src/metadata}/tokens.d.ts +0 -0
  102. /package/browser/{network → src/network}/ChainId.d.ts +0 -0
  103. /package/browser/{p2wda → src/p2wda}/P2WDADetector.d.ts +0 -0
  104. /package/browser/{signer → src/signer}/SignerUtils.d.ts +0 -0
  105. /package/browser/{signer → src/signer}/TweakedSigner.d.ts +0 -0
  106. /package/browser/{transaction → src/transaction}/ContractAddress.d.ts +0 -0
  107. /package/browser/{transaction → src/transaction}/TransactionFactory.d.ts +0 -0
  108. /package/browser/{transaction → src/transaction}/browser/BrowserSignerBase.d.ts +0 -0
  109. /package/browser/{transaction → src/transaction}/browser/Web3Provider.d.ts +0 -0
  110. /package/browser/{transaction → src/transaction}/browser/extensions/UnisatSigner.d.ts +0 -0
  111. /package/browser/{transaction → src/transaction}/browser/extensions/XverseSigner.d.ts +0 -0
  112. /package/browser/{transaction → src/transaction}/browser/types/Unisat.d.ts +0 -0
  113. /package/browser/{transaction → src/transaction}/browser/types/Xverse.d.ts +0 -0
  114. /package/browser/{transaction → src/transaction}/builders/CancelTransaction.d.ts +0 -0
  115. /package/browser/{transaction → src/transaction}/builders/ChallengeSolutionTransaction.d.ts +0 -0
  116. /package/browser/{transaction → src/transaction}/builders/CustomScriptTransaction.d.ts +0 -0
  117. /package/browser/{transaction → src/transaction}/builders/DeploymentTransaction.d.ts +0 -0
  118. /package/browser/{transaction → src/transaction}/builders/FundingTransaction.d.ts +0 -0
  119. /package/browser/{transaction → src/transaction}/builders/InteractionTransaction.d.ts +0 -0
  120. /package/browser/{transaction → src/transaction}/builders/InteractionTransactionP2WDA.d.ts +0 -0
  121. /package/browser/{transaction → src/transaction}/builders/MultiSignTransaction.d.ts +0 -0
  122. /package/browser/{transaction → src/transaction}/builders/SharedInteractionTransaction.d.ts +0 -0
  123. /package/browser/{transaction → src/transaction}/builders/TransactionBuilder.d.ts +0 -0
  124. /package/browser/{transaction → src/transaction}/enums/TransactionType.d.ts +0 -0
  125. /package/browser/{transaction → src/transaction}/interfaces/ITransactionParameters.d.ts +0 -0
  126. /package/browser/{transaction → src/transaction}/interfaces/Tap.d.ts +0 -0
  127. /package/browser/{transaction → src/transaction}/mineable/IP2WSHAddress.d.ts +0 -0
  128. /package/browser/{transaction → src/transaction}/mineable/TimelockGenerator.d.ts +0 -0
  129. /package/browser/{transaction → src/transaction}/processor/PsbtTransaction.d.ts +0 -0
  130. /package/browser/{transaction → src/transaction}/psbt/PSBTTypes.d.ts +0 -0
  131. /package/browser/{transaction → src/transaction}/shared/P2TR_MS.d.ts +0 -0
  132. /package/browser/{transaction → src/transaction}/shared/TweakedTransaction.d.ts +0 -0
  133. /package/browser/{utils → src/utils}/BitcoinUtils.d.ts +0 -0
  134. /package/browser/{utils → src/utils}/BufferHelper.d.ts +0 -0
  135. /package/browser/{utils → src/utils}/StringToBuffer.d.ts +0 -0
  136. /package/browser/{utils → src/utils}/lengths.d.ts +0 -0
  137. /package/browser/{utils → src/utils}/types.d.ts +0 -0
  138. /package/browser/{utxo → src/utxo}/OPNetLimitedProvider.d.ts +0 -0
  139. /package/browser/{utxo → src/utxo}/interfaces/BroadcastResponse.d.ts +0 -0
  140. /package/browser/{utxo → src/utxo}/interfaces/IUTXO.d.ts +0 -0
  141. /package/browser/{verification → src/verification}/TapscriptVerificator.d.ts +0 -0
@@ -0,0 +1,340 @@
1
+ import * as bip39 from 'bip39';
2
+ import {
3
+ BIP32Factory,
4
+ BIP32Interface,
5
+ MLDSASecurityLevel,
6
+ QuantumBIP32Factory,
7
+ QuantumBIP32Interface,
8
+ } from '@btc-vision/bip32';
9
+ import * as ecc from '@bitcoinerlab/secp256k1';
10
+ import { initEccLib, Network, networks } from '@btc-vision/bitcoin';
11
+ import { Wallet } from '../keypair/Wallet.js';
12
+ import { MnemonicStrength } from './MnemonicStrength.js';
13
+
14
+ initEccLib(ecc);
15
+
16
+ const bip32 = BIP32Factory(ecc);
17
+
18
+ /**
19
+ * Mnemonic class for managing BIP39 mnemonic phrases with BIP360 quantum support
20
+ *
21
+ * This class provides methods to generate, validate, and derive wallets from mnemonic phrases.
22
+ * It supports both classical Bitcoin derivation paths (BIP44, BIP84, etc.) and quantum-resistant
23
+ * ML-DSA keys via BIP360.
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * // Generate a new mnemonic
28
+ * const mnemonic = Mnemonic.generate();
29
+ *
30
+ * // Derive a wallet at index 0
31
+ * const wallet = mnemonic.derive(0);
32
+ *
33
+ * // Derive multiple wallets
34
+ * const wallets = mnemonic.deriveMultiple(5);
35
+ *
36
+ * // Load from existing mnemonic
37
+ * const existingMnemonic = new Mnemonic('your twelve word mnemonic phrase here...');
38
+ * ```
39
+ */
40
+ export class Mnemonic {
41
+ /**
42
+ * The BIP39 mnemonic phrase
43
+ */
44
+ private readonly _phrase: string;
45
+
46
+ /**
47
+ * Optional BIP39 passphrase for additional security
48
+ */
49
+ private readonly _passphrase: string;
50
+
51
+ /**
52
+ * The network to use for derivation
53
+ */
54
+ private readonly _network: Network;
55
+
56
+ /**
57
+ * The ML-DSA security level for quantum keys
58
+ */
59
+ private readonly _securityLevel: MLDSASecurityLevel;
60
+
61
+ /**
62
+ * The seed derived from the mnemonic
63
+ */
64
+ private readonly _seed: Buffer;
65
+
66
+ /**
67
+ * The classical BIP32 root for Bitcoin keys
68
+ */
69
+ private readonly _classicalRoot: BIP32Interface;
70
+
71
+ /**
72
+ * The quantum BIP32 root for ML-DSA keys
73
+ */
74
+ private readonly _quantumRoot: QuantumBIP32Interface;
75
+
76
+ /**
77
+ * Create a new Mnemonic instance from an existing phrase
78
+ *
79
+ * @param phrase - The BIP39 mnemonic phrase (12, 15, 18, 21, or 24 words)
80
+ * @param passphrase - Optional BIP39 passphrase for additional security (default: '')
81
+ * @param network - The Bitcoin network to use (default: bitcoin mainnet)
82
+ * @param securityLevel - The ML-DSA security level for quantum keys (default: LEVEL2/44)
83
+ * @throws {Error} If the mnemonic phrase is invalid
84
+ */
85
+ constructor(
86
+ phrase: string,
87
+ passphrase: string = '',
88
+ network: Network = networks.bitcoin,
89
+ securityLevel: MLDSASecurityLevel = MLDSASecurityLevel.LEVEL2,
90
+ ) {
91
+ if (!bip39.validateMnemonic(phrase)) {
92
+ throw new Error('Invalid mnemonic phrase');
93
+ }
94
+
95
+ this._phrase = phrase;
96
+ this._passphrase = passphrase;
97
+ this._network = network;
98
+ this._securityLevel = securityLevel;
99
+
100
+ // Derive the seed from the mnemonic
101
+ this._seed = bip39.mnemonicToSeedSync(this._phrase, this._passphrase);
102
+
103
+ // Create the classical BIP32 root
104
+ this._classicalRoot = bip32.fromSeed(this._seed, this._network);
105
+
106
+ // Create the quantum BIP32 root with network parameter
107
+ this._quantumRoot = QuantumBIP32Factory.fromSeed(
108
+ this._seed,
109
+ this._network,
110
+ this._securityLevel,
111
+ );
112
+ }
113
+
114
+ /**
115
+ * Get the mnemonic phrase
116
+ *
117
+ * @warning This phrase is highly sensitive and can be used to derive all keys in the wallet.
118
+ * Handle with extreme care, never log or transmit insecurely, and store only in secure environments.
119
+ *
120
+ * @returns The BIP39 mnemonic phrase
121
+ */
122
+ public get phrase(): string {
123
+ return this._phrase;
124
+ }
125
+
126
+ /**
127
+ * Get the network
128
+ */
129
+ public get network(): Network {
130
+ return this._network;
131
+ }
132
+
133
+ /**
134
+ * Get the ML-DSA security level
135
+ */
136
+ public get securityLevel(): MLDSASecurityLevel {
137
+ return this._securityLevel;
138
+ }
139
+
140
+ /**
141
+ * Get the seed derived from the mnemonic phrase
142
+ *
143
+ * @warning This seed is highly sensitive and can be used to derive all keys in the wallet.
144
+ * Handle with extreme care, never log or transmit insecurely, and store only in secure environments.
145
+ *
146
+ * @returns A copy of the seed buffer to prevent external modification
147
+ */
148
+ public get seed(): Buffer {
149
+ return Buffer.from(this._seed);
150
+ }
151
+
152
+ /**
153
+ * Generate a new mnemonic phrase
154
+ *
155
+ * @param strength - The entropy strength in bits (default: 256 for 24 words)
156
+ * @returns A new random mnemonic phrase
157
+ */
158
+ public static generatePhrase(strength: MnemonicStrength = MnemonicStrength.MAXIMUM): string {
159
+ return bip39.generateMnemonic(strength);
160
+ }
161
+
162
+ /**
163
+ * Generate a new Mnemonic instance with a random phrase
164
+ *
165
+ * @param strength - The entropy strength in bits (default: 256 for 24 words)
166
+ * @param passphrase - Optional BIP39 passphrase for additional security (default: '')
167
+ * @param network - The Bitcoin network to use (default: bitcoin mainnet)
168
+ * @param securityLevel - The ML-DSA security level for quantum keys (default: LEVEL2/44)
169
+ * @returns A new Mnemonic instance
170
+ */
171
+ public static generate(
172
+ strength: MnemonicStrength = MnemonicStrength.MAXIMUM,
173
+ passphrase: string = '',
174
+ network: Network = networks.bitcoin,
175
+ securityLevel: MLDSASecurityLevel = MLDSASecurityLevel.LEVEL2,
176
+ ): Mnemonic {
177
+ const phrase = bip39.generateMnemonic(strength);
178
+ return new Mnemonic(phrase, passphrase, network, securityLevel);
179
+ }
180
+
181
+ /**
182
+ * Validate a mnemonic phrase
183
+ *
184
+ * @param phrase - The mnemonic phrase to validate
185
+ * @returns True if the phrase is valid, false otherwise
186
+ */
187
+ public static validate(phrase: string): boolean {
188
+ return bip39.validateMnemonic(phrase);
189
+ }
190
+
191
+ /**
192
+ * Derive a wallet at a specific index using BIP360 (quantum) and BIP84 (classical) paths
193
+ *
194
+ * This method derives both classical ECDSA/Schnorr keys and quantum-resistant ML-DSA keys
195
+ * for the wallet, providing hybrid post-quantum security.
196
+ *
197
+ * @param index - The address index to derive (default: 0)
198
+ * @param account - The account index (default: 0)
199
+ * @param isChange - Whether this is a change address (default: false)
200
+ * @returns A Wallet instance with both classical and quantum keys
201
+ */
202
+ public derive(index: number = 0, account: number = 0, isChange: boolean = false): Wallet {
203
+ // Derive classical key using BIP84 (Native SegWit)
204
+ const classicalPath = this.buildClassicalPath(account, index, isChange);
205
+ const classicalChild = this._classicalRoot.derivePath(classicalPath);
206
+
207
+ if (!classicalChild.privateKey) {
208
+ throw new Error(`Failed to derive classical private key at index ${index}`);
209
+ }
210
+
211
+ // Derive quantum key using BIP360
212
+ const quantumPath = this.buildQuantumPath(account, index, isChange);
213
+ const quantumChild = this._quantumRoot.derivePath(quantumPath);
214
+
215
+ if (!quantumChild.privateKey) {
216
+ throw new Error(`Failed to derive quantum private key at index ${index}`);
217
+ }
218
+
219
+ // Create a wallet with both keys
220
+ return new Wallet(
221
+ Buffer.from(classicalChild.privateKey).toString('hex'),
222
+ Buffer.from(quantumChild.privateKey).toString('hex'),
223
+ this._network,
224
+ this._securityLevel,
225
+ );
226
+ }
227
+
228
+ /**
229
+ * Derive multiple wallets with sequential indices
230
+ *
231
+ * @param count - The number of wallets to derive
232
+ * @param startIndex - The starting address index (default: 0)
233
+ * @param account - The account index (default: 0)
234
+ * @param isChange - Whether these are change addresses (default: false)
235
+ * @returns An array of Wallet instances
236
+ */
237
+ public deriveMultiple(
238
+ count: number,
239
+ startIndex: number = 0,
240
+ account: number = 0,
241
+ isChange: boolean = false,
242
+ ): Wallet[] {
243
+ const wallets: Wallet[] = [];
244
+
245
+ for (let i = 0; i < count; i++) {
246
+ wallets.push(this.derive(startIndex + i, account, isChange));
247
+ }
248
+
249
+ return wallets;
250
+ }
251
+
252
+ /**
253
+ * Derive a wallet using a custom derivation path
254
+ *
255
+ * @param classicalPath - The BIP32 path for classical keys (e.g., "m/84'/0'/0'/0/0")
256
+ * @param quantumPath - The BIP360 path for quantum keys (e.g., "m/360'/0'/0'/0/0")
257
+ * @returns A Wallet instance
258
+ */
259
+ public deriveCustomPath(classicalPath: string, quantumPath: string): Wallet {
260
+ const classicalChild = this._classicalRoot.derivePath(classicalPath);
261
+ const quantumChild = this._quantumRoot.derivePath(quantumPath);
262
+
263
+ if (!classicalChild.privateKey) {
264
+ throw new Error(`Failed to derive classical private key at path ${classicalPath}`);
265
+ }
266
+
267
+ if (!quantumChild.privateKey) {
268
+ throw new Error(`Failed to derive quantum private key at path ${quantumPath}`);
269
+ }
270
+
271
+ // Create wallet with both classical and ML-DSA private keys
272
+ return new Wallet(
273
+ Buffer.from(classicalChild.privateKey).toString('hex'),
274
+ Buffer.from(quantumChild.privateKey).toString('hex'),
275
+ this._network,
276
+ this._securityLevel,
277
+ );
278
+ }
279
+
280
+ /**
281
+ * Get the classical BIP32 root
282
+ *
283
+ * @returns The classical BIP32Interface for manual derivation
284
+ */
285
+ public getClassicalRoot(): BIP32Interface {
286
+ return this._classicalRoot;
287
+ }
288
+
289
+ /**
290
+ * Get the quantum BIP32 root
291
+ *
292
+ * @returns The quantum BIP32Interface for manual derivation
293
+ */
294
+ public getQuantumRoot(): QuantumBIP32Interface {
295
+ return this._quantumRoot;
296
+ }
297
+
298
+ /**
299
+ * Build a classical derivation path (BIP84 for Native SegWit)
300
+ *
301
+ * @param account - The account index
302
+ * @param index - The address index
303
+ * @param isChange - Whether this is a change address
304
+ * @returns The derivation path string
305
+ */
306
+ private buildClassicalPath(account: number, index: number, isChange: boolean): string {
307
+ const coinType = this.getCoinType();
308
+ const change = isChange ? 1 : 0;
309
+ return `m/84'/${coinType}'/${account}'/${change}/${index}`;
310
+ }
311
+
312
+ /**
313
+ * Build a quantum derivation path (BIP360)
314
+ *
315
+ * @param account - The account index
316
+ * @param index - The address index
317
+ * @param isChange - Whether this is a change address
318
+ * @returns The derivation path string
319
+ */
320
+ private buildQuantumPath(account: number, index: number, isChange: boolean): string {
321
+ const coinType = this.getCoinType();
322
+ const change = isChange ? 1 : 0;
323
+ return `m/360'/${coinType}'/${account}'/${change}/${index}`;
324
+ }
325
+
326
+ /**
327
+ * Get the coin type based on the network
328
+ *
329
+ * @returns The coin type (0 for mainnet, 1 for testnet/regtest)
330
+ */
331
+ private getCoinType(): number {
332
+ if (
333
+ this._network.bech32 === networks.testnet.bech32 ||
334
+ this._network.bech32 === networks.regtest.bech32
335
+ ) {
336
+ return 1;
337
+ }
338
+ return 0;
339
+ }
340
+ }
@@ -0,0 +1,12 @@
1
+ export enum MnemonicStrength {
2
+ /** 128 bits of entropy - 12 words */
3
+ MINIMUM = 128,
4
+ /** 160 bits of entropy - 15 words */
5
+ LOW = 160,
6
+ /** 192 bits of entropy - 18 words */
7
+ MEDIUM = 192,
8
+ /** 224 bits of entropy - 21 words */
9
+ HIGH = 224,
10
+ /** 256 bits of entropy - 24 words */
11
+ MAXIMUM = 256,
12
+ }
@@ -1,7 +1,4 @@
1
-
2
-
3
-
4
1
  export enum ChainId {
5
2
  Bitcoin = 0,
6
3
  Fractal = 1,
7
- }
4
+ }
package/src/opnet.ts CHANGED
@@ -30,6 +30,21 @@ export * from './keypair/interfaces/IWallet.js';
30
30
  export * from './keypair/MessageSigner.js';
31
31
  export * from './keypair/Wallet.js';
32
32
 
33
+ /** Mnemonic */
34
+ export * from './mnemonic/Mnemonic.js';
35
+ export * from './mnemonic/MnemonicStrength.js';
36
+
37
+ /** Quantum (ML-DSA) */
38
+ export {
39
+ MLDSASecurityLevel,
40
+ MLDSAKeyPair,
41
+ QuantumBIP32Interface,
42
+ QuantumBIP32API,
43
+ QuantumSigner,
44
+ QuantumBIP32Factory,
45
+ QuantumDerivationPath,
46
+ } from '@btc-vision/bip32';
47
+
33
48
  /** Metadata */
34
49
  export * from './metadata/ContractBaseMetadata.js';
35
50
  export * from './network/ChainId.js';
@@ -101,6 +116,7 @@ export * from './transaction/browser/extensions/UnisatSigner.js';
101
116
  export * from './transaction/browser/extensions/XverseSigner.js';
102
117
  export * from './transaction/browser/types/Unisat.js';
103
118
  export * from './transaction/browser/types/Xverse.js';
119
+ export * from './transaction/browser/types/OPWallet.js';
104
120
 
105
121
  export * from './metadata/tokens.js';
106
122
  export * from './transaction/browser/Web3Provider.js';
@@ -0,0 +1,73 @@
1
+ import { Unisat } from './Unisat.js';
2
+ import { MLDSASecurityLevel } from '@btc-vision/bip32';
3
+
4
+ /**
5
+ * ML-DSA signature result
6
+ */
7
+ export interface MLDSASignature {
8
+ /**
9
+ * The ML-DSA signature in hex format
10
+ */
11
+ readonly signature: string;
12
+
13
+ /**
14
+ * The ML-DSA public key used for signing in hex format
15
+ */
16
+ readonly publicKey: string;
17
+
18
+ /**
19
+ * The security level used (44, 65, or 87)
20
+ */
21
+ readonly securityLevel: MLDSASecurityLevel;
22
+
23
+ /**
24
+ * The message hash that was signed
25
+ */
26
+ readonly messageHash: string;
27
+ }
28
+
29
+ /**
30
+ * OPWallet interface extending Unisat with ML-DSA (FIPS 204) support
31
+ *
32
+ * SECURITY NOTE: All methods only expose public keys and signatures.
33
+ * Private keys are NEVER exposed through this interface.
34
+ */
35
+ export interface OPWallet extends Unisat {
36
+ /**
37
+ * Get the ML-DSA public key for the current account
38
+ *
39
+ * @returns The ML-DSA public key in hex format (never exposes private keys)
40
+ * @throws {Error} If the wallet is not connected
41
+ */
42
+ getMLDSAPublicKey(): Promise<string>;
43
+
44
+ /**
45
+ * Sign a message using ML-DSA signature
46
+ *
47
+ * @param message - The message to sign
48
+ * @returns The ML-DSA signature
49
+ * @throws {Error} If signing fails or wallet is not connected
50
+ */
51
+ signMLDSAMessage(message: string): Promise<MLDSASignature>;
52
+
53
+ /**
54
+ * Verify an ML-DSA signature
55
+ *
56
+ * @param message - The original message
57
+ * @param signature - The ML-DSA signature to verify
58
+ * @returns True if the signature is valid
59
+ */
60
+ verifyMLDSASignature(message: string, signature: MLDSASignature): Promise<boolean>;
61
+ }
62
+
63
+ /**
64
+ * Type guard to check if a wallet supports OPWallet features
65
+ */
66
+ export function isOPWallet(wallet: unknown): wallet is OPWallet {
67
+ return (
68
+ typeof wallet === 'object' &&
69
+ wallet !== null &&
70
+ 'getMLDSAPublicKey' in wallet &&
71
+ 'signMLDSAMessage' in wallet
72
+ );
73
+ }