@btc-vision/transaction 1.6.19 → 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.
Files changed (155) 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/BIPStandard.d.ts +8 -0
  12. package/browser/src/mnemonic/Mnemonic.d.ts +34 -0
  13. package/browser/src/mnemonic/MnemonicStrength.d.ts +7 -0
  14. package/browser/{opnet.d.ts → src/opnet.d.ts} +5 -0
  15. package/browser/src/transaction/browser/types/OPWallet.d.ts +14 -0
  16. package/browser/test/address.test.d.ts +1 -0
  17. package/browser/test/addressverificator-mldsa.test.d.ts +1 -0
  18. package/browser/test/derivePath.test.d.ts +1 -0
  19. package/browser/test/messagesigner-mldsa.test.d.ts +1 -0
  20. package/browser/test/messagesigner-schnorr.test.d.ts +1 -0
  21. package/browser/test/network-awareness.test.d.ts +1 -0
  22. package/build/_version.d.ts +1 -1
  23. package/build/_version.js +1 -1
  24. package/build/crypto/crypto-browser.d.ts +11 -0
  25. package/build/crypto/crypto-browser.js +56 -0
  26. package/build/epoch/ChallengeSolution.js +3 -2
  27. package/build/epoch/interfaces/IChallengeSolution.d.ts +2 -0
  28. package/build/keypair/Address.d.ts +7 -4
  29. package/build/keypair/Address.js +88 -37
  30. package/build/keypair/AddressVerificator.d.ts +3 -0
  31. package/build/keypair/AddressVerificator.js +49 -1
  32. package/build/keypair/EcKeyPair.d.ts +3 -2
  33. package/build/keypair/EcKeyPair.js +17 -3
  34. package/build/keypair/MessageSigner.d.ts +9 -0
  35. package/build/keypair/MessageSigner.js +23 -0
  36. package/build/keypair/Wallet.d.ts +20 -3
  37. package/build/keypair/Wallet.js +108 -9
  38. package/build/keypair/interfaces/IWallet.d.ts +2 -0
  39. package/build/mnemonic/BIPStandard.d.ts +8 -0
  40. package/build/mnemonic/BIPStandard.js +24 -0
  41. package/build/mnemonic/Mnemonic.d.ts +34 -0
  42. package/build/mnemonic/Mnemonic.js +140 -0
  43. package/build/mnemonic/MnemonicStrength.d.ts +7 -0
  44. package/build/mnemonic/MnemonicStrength.js +8 -0
  45. package/build/opnet.d.ts +5 -0
  46. package/build/opnet.js +5 -0
  47. package/build/transaction/browser/types/OPWallet.d.ts +14 -0
  48. package/build/transaction/browser/types/OPWallet.js +6 -0
  49. package/documentation/README.md +32 -0
  50. package/documentation/quantum-support/01-introduction.md +88 -0
  51. package/documentation/quantum-support/02-mnemonic-and-wallet.md +445 -0
  52. package/documentation/quantum-support/03-address-generation.md +329 -0
  53. package/documentation/quantum-support/04-message-signing.md +623 -0
  54. package/documentation/quantum-support/05-address-verification.md +307 -0
  55. package/documentation/quantum-support/README.md +65 -0
  56. package/gulpfile.js +2 -2
  57. package/package.json +25 -17
  58. package/src/_version.ts +1 -1
  59. package/src/epoch/ChallengeSolution.ts +3 -2
  60. package/src/epoch/interfaces/IChallengeSolution.ts +2 -0
  61. package/src/keypair/Address.ts +145 -43
  62. package/src/keypair/AddressVerificator.ts +87 -2
  63. package/src/keypair/EcKeyPair.ts +58 -6
  64. package/src/keypair/MessageSigner.ts +58 -0
  65. package/src/keypair/Wallet.ts +339 -57
  66. package/src/keypair/interfaces/IWallet.ts +13 -3
  67. package/src/mnemonic/BIPStandard.ts +92 -0
  68. package/src/mnemonic/Mnemonic.ts +465 -0
  69. package/src/mnemonic/MnemonicStrength.ts +12 -0
  70. package/src/network/ChainId.ts +1 -4
  71. package/src/opnet.ts +17 -0
  72. package/src/transaction/browser/types/OPWallet.ts +73 -0
  73. package/test/address.test.ts +1068 -0
  74. package/test/addressverificator-mldsa.test.ts +473 -0
  75. package/test/derivePath.test.ts +513 -0
  76. package/test/messagesigner-mldsa.test.ts +1060 -0
  77. package/test/messagesigner-schnorr.test.ts +1011 -0
  78. package/test/network-awareness.test.ts +163 -0
  79. package/tsconfig.json +1 -1
  80. package/vitest.config.ts +21 -0
  81. package/browser/_version.d.ts +0 -1
  82. package/browser/keypair/Wallet.d.ts +0 -30
  83. package/doc/README.md +0 -0
  84. /package/browser/{abi → src/abi}/ABICoder.d.ts +0 -0
  85. /package/browser/{buffer → src/buffer}/BinaryReader.d.ts +0 -0
  86. /package/browser/{buffer → src/buffer}/BinaryWriter.d.ts +0 -0
  87. /package/browser/{bytecode → src/bytecode}/Compressor.d.ts +0 -0
  88. /package/browser/{consensus → src/consensus}/Consensus.d.ts +0 -0
  89. /package/browser/{consensus → src/consensus}/ConsensusConfig.d.ts +0 -0
  90. /package/browser/{consensus → src/consensus}/metadata/RoswellConsensus.d.ts +0 -0
  91. /package/browser/{crypto → src/crypto}/crypto-browser.d.ts +0 -0
  92. /package/browser/{crypto → src/crypto}/crypto.d.ts +0 -0
  93. /package/browser/{deterministic → src/deterministic}/AddressMap.d.ts +0 -0
  94. /package/browser/{deterministic → src/deterministic}/AddressSet.d.ts +0 -0
  95. /package/browser/{deterministic → src/deterministic}/DeterministicMap.d.ts +0 -0
  96. /package/browser/{deterministic → src/deterministic}/DeterministicSet.d.ts +0 -0
  97. /package/browser/{deterministic → src/deterministic}/Map.d.ts +0 -0
  98. /package/browser/{epoch → src/epoch}/ChallengeSolution.d.ts +0 -0
  99. /package/browser/{epoch → src/epoch}/validator/EpochValidator.d.ts +0 -0
  100. /package/browser/{event → src/event}/NetEvent.d.ts +0 -0
  101. /package/browser/{generators → src/generators}/AddressGenerator.d.ts +0 -0
  102. /package/browser/{generators → src/generators}/Features.d.ts +0 -0
  103. /package/browser/{generators → src/generators}/Generator.d.ts +0 -0
  104. /package/browser/{generators → src/generators}/builders/CalldataGenerator.d.ts +0 -0
  105. /package/browser/{generators → src/generators}/builders/CustomGenerator.d.ts +0 -0
  106. /package/browser/{generators → src/generators}/builders/DeploymentGenerator.d.ts +0 -0
  107. /package/browser/{generators → src/generators}/builders/LegacyCalldataGenerator.d.ts +0 -0
  108. /package/browser/{generators → src/generators}/builders/MultiSignGenerator.d.ts +0 -0
  109. /package/browser/{generators → src/generators}/builders/P2WDAGenerator.d.ts +0 -0
  110. /package/browser/{index.d.ts → src/index.d.ts} +0 -0
  111. /package/browser/{keypair → src/keypair}/Secp256k1PointDeriver.d.ts +0 -0
  112. /package/browser/{metadata → src/metadata}/ContractBaseMetadata.d.ts +0 -0
  113. /package/browser/{metadata → src/metadata}/tokens.d.ts +0 -0
  114. /package/browser/{network → src/network}/ChainId.d.ts +0 -0
  115. /package/browser/{p2wda → src/p2wda}/P2WDADetector.d.ts +0 -0
  116. /package/browser/{signer → src/signer}/SignerUtils.d.ts +0 -0
  117. /package/browser/{signer → src/signer}/TweakedSigner.d.ts +0 -0
  118. /package/browser/{transaction → src/transaction}/ContractAddress.d.ts +0 -0
  119. /package/browser/{transaction → src/transaction}/TransactionFactory.d.ts +0 -0
  120. /package/browser/{transaction → src/transaction}/browser/BrowserSignerBase.d.ts +0 -0
  121. /package/browser/{transaction → src/transaction}/browser/Web3Provider.d.ts +0 -0
  122. /package/browser/{transaction → src/transaction}/browser/extensions/UnisatSigner.d.ts +0 -0
  123. /package/browser/{transaction → src/transaction}/browser/extensions/XverseSigner.d.ts +0 -0
  124. /package/browser/{transaction → src/transaction}/browser/types/Unisat.d.ts +0 -0
  125. /package/browser/{transaction → src/transaction}/browser/types/Xverse.d.ts +0 -0
  126. /package/browser/{transaction → src/transaction}/builders/CancelTransaction.d.ts +0 -0
  127. /package/browser/{transaction → src/transaction}/builders/ChallengeSolutionTransaction.d.ts +0 -0
  128. /package/browser/{transaction → src/transaction}/builders/CustomScriptTransaction.d.ts +0 -0
  129. /package/browser/{transaction → src/transaction}/builders/DeploymentTransaction.d.ts +0 -0
  130. /package/browser/{transaction → src/transaction}/builders/FundingTransaction.d.ts +0 -0
  131. /package/browser/{transaction → src/transaction}/builders/InteractionTransaction.d.ts +0 -0
  132. /package/browser/{transaction → src/transaction}/builders/InteractionTransactionP2WDA.d.ts +0 -0
  133. /package/browser/{transaction → src/transaction}/builders/MultiSignTransaction.d.ts +0 -0
  134. /package/browser/{transaction → src/transaction}/builders/SharedInteractionTransaction.d.ts +0 -0
  135. /package/browser/{transaction → src/transaction}/builders/TransactionBuilder.d.ts +0 -0
  136. /package/browser/{transaction → src/transaction}/enums/TransactionType.d.ts +0 -0
  137. /package/browser/{transaction → src/transaction}/interfaces/ITransactionParameters.d.ts +0 -0
  138. /package/browser/{transaction → src/transaction}/interfaces/Tap.d.ts +0 -0
  139. /package/browser/{transaction → src/transaction}/mineable/IP2WSHAddress.d.ts +0 -0
  140. /package/browser/{transaction → src/transaction}/mineable/TimelockGenerator.d.ts +0 -0
  141. /package/browser/{transaction → src/transaction}/processor/PsbtTransaction.d.ts +0 -0
  142. /package/browser/{transaction → src/transaction}/psbt/PSBTTypes.d.ts +0 -0
  143. /package/browser/{transaction → src/transaction}/shared/P2TR_MS.d.ts +0 -0
  144. /package/browser/{transaction → src/transaction}/shared/TweakedTransaction.d.ts +0 -0
  145. /package/browser/{utils → src/utils}/BitcoinUtils.d.ts +0 -0
  146. /package/browser/{utils → src/utils}/BufferHelper.d.ts +0 -0
  147. /package/browser/{utils → src/utils}/StringToBuffer.d.ts +0 -0
  148. /package/browser/{utils → src/utils}/lengths.d.ts +0 -0
  149. /package/browser/{utils → src/utils}/types.d.ts +0 -0
  150. /package/browser/{utxo → src/utxo}/OPNetLimitedProvider.d.ts +0 -0
  151. /package/browser/{utxo → src/utxo}/interfaces/BroadcastResponse.d.ts +0 -0
  152. /package/browser/{utxo → src/utxo}/interfaces/IUTXO.d.ts +0 -0
  153. /package/browser/{verification → src/verification}/TapscriptVerificator.d.ts +0 -0
  154. /package/{doc → documentation}/addresses/P2OP.md +0 -0
  155. /package/{doc → documentation}/addresses/P2WDA.md +0 -0
@@ -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
+ }
@@ -0,0 +1,34 @@
1
+ import { BIP32Interface, MLDSASecurityLevel, QuantumBIP32Interface } from '@btc-vision/bip32';
2
+ import { Network } from '@btc-vision/bitcoin';
3
+ import { Wallet } from '../keypair/Wallet.js';
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';
8
+ export declare class Mnemonic {
9
+ private readonly _phrase;
10
+ private readonly _passphrase;
11
+ private readonly _network;
12
+ private readonly _securityLevel;
13
+ private readonly _seed;
14
+ private readonly _classicalRoot;
15
+ private readonly _quantumRoot;
16
+ constructor(phrase: string, passphrase?: string, network?: Network, securityLevel?: MLDSASecurityLevel);
17
+ get phrase(): string;
18
+ get network(): Network;
19
+ get securityLevel(): MLDSASecurityLevel;
20
+ get seed(): Buffer;
21
+ static generatePhrase(strength?: MnemonicStrength): string;
22
+ static generate(strength?: MnemonicStrength, passphrase?: string, network?: Network, securityLevel?: MLDSASecurityLevel): Mnemonic;
23
+ static validate(phrase: string): boolean;
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[];
28
+ deriveCustomPath(classicalPath: string, quantumPath: string): Wallet;
29
+ getClassicalRoot(): BIP32Interface;
30
+ getQuantumRoot(): QuantumBIP32Interface;
31
+ private buildClassicalPath;
32
+ private buildQuantumPath;
33
+ private getCoinType;
34
+ }
@@ -0,0 +1,140 @@
1
+ import * as bip39 from 'bip39';
2
+ import { BIP32Factory, MLDSASecurityLevel, QuantumBIP32Factory, } from '@btc-vision/bip32';
3
+ import * as ecc from '@bitcoinerlab/secp256k1';
4
+ import { initEccLib, networks } from '@btc-vision/bitcoin';
5
+ import { Wallet } from '../keypair/Wallet.js';
6
+ import { MnemonicStrength } from './MnemonicStrength.js';
7
+ import { BIPStandard, buildBIPPath } from './BIPStandard.js';
8
+ import { AddressTypes } from '../keypair/AddressVerificator.js';
9
+ initEccLib(ecc);
10
+ const bip32 = BIP32Factory(ecc);
11
+ export { BIPStandard, getBIPDescription } from './BIPStandard.js';
12
+ export class Mnemonic {
13
+ constructor(phrase, passphrase = '', network = networks.bitcoin, securityLevel = MLDSASecurityLevel.LEVEL2) {
14
+ if (!bip39.validateMnemonic(phrase)) {
15
+ throw new Error('Invalid mnemonic phrase');
16
+ }
17
+ this._phrase = phrase;
18
+ this._passphrase = passphrase;
19
+ this._network = network;
20
+ this._securityLevel = securityLevel;
21
+ this._seed = bip39.mnemonicToSeedSync(this._phrase, this._passphrase);
22
+ this._classicalRoot = bip32.fromSeed(this._seed, this._network);
23
+ this._quantumRoot = QuantumBIP32Factory.fromSeed(this._seed, this._network, this._securityLevel);
24
+ }
25
+ get phrase() {
26
+ return this._phrase;
27
+ }
28
+ get network() {
29
+ return this._network;
30
+ }
31
+ get securityLevel() {
32
+ return this._securityLevel;
33
+ }
34
+ get seed() {
35
+ return Buffer.from(this._seed);
36
+ }
37
+ static generatePhrase(strength = MnemonicStrength.MAXIMUM) {
38
+ return bip39.generateMnemonic(strength);
39
+ }
40
+ static generate(strength = MnemonicStrength.MAXIMUM, passphrase = '', network = networks.bitcoin, securityLevel = MLDSASecurityLevel.LEVEL2) {
41
+ const phrase = bip39.generateMnemonic(strength);
42
+ return new Mnemonic(phrase, passphrase, network, securityLevel);
43
+ }
44
+ static validate(phrase) {
45
+ return bip39.validateMnemonic(phrase);
46
+ }
47
+ derive(index = 0, account = 0, isChange = false, bipStandard = BIPStandard.BIP84) {
48
+ const classicalPath = this.buildClassicalPath(account, index, isChange, bipStandard);
49
+ const classicalChild = this._classicalRoot.derivePath(classicalPath);
50
+ if (!classicalChild.privateKey) {
51
+ throw new Error(`Failed to derive classical private key at index ${index}`);
52
+ }
53
+ const quantumPath = this.buildQuantumPath(account, index, isChange);
54
+ const quantumChild = this._quantumRoot.derivePath(quantumPath);
55
+ if (!quantumChild.privateKey) {
56
+ throw new Error(`Failed to derive quantum private key at index ${index}`);
57
+ }
58
+ return new Wallet(Buffer.from(classicalChild.privateKey).toString('hex'), Buffer.from(quantumChild.privateKey).toString('hex'), this._network, this._securityLevel);
59
+ }
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) {
100
+ const wallets = [];
101
+ for (let i = 0; i < count; i++) {
102
+ wallets.push(this.derive(startIndex + i, account, isChange, bipStandard));
103
+ }
104
+ return wallets;
105
+ }
106
+ deriveCustomPath(classicalPath, quantumPath) {
107
+ const classicalChild = this._classicalRoot.derivePath(classicalPath);
108
+ const quantumChild = this._quantumRoot.derivePath(quantumPath);
109
+ if (!classicalChild.privateKey) {
110
+ throw new Error(`Failed to derive classical private key at path ${classicalPath}`);
111
+ }
112
+ if (!quantumChild.privateKey) {
113
+ throw new Error(`Failed to derive quantum private key at path ${quantumPath}`);
114
+ }
115
+ return new Wallet(Buffer.from(classicalChild.privateKey).toString('hex'), Buffer.from(quantumChild.privateKey).toString('hex'), this._network, this._securityLevel);
116
+ }
117
+ getClassicalRoot() {
118
+ return this._classicalRoot;
119
+ }
120
+ getQuantumRoot() {
121
+ return this._quantumRoot;
122
+ }
123
+ buildClassicalPath(account, index, isChange, bipStandard = BIPStandard.BIP84) {
124
+ const coinType = this.getCoinType();
125
+ const change = isChange ? 1 : 0;
126
+ return buildBIPPath(bipStandard, coinType, account, change, index);
127
+ }
128
+ buildQuantumPath(account, index, isChange) {
129
+ const coinType = this.getCoinType();
130
+ const change = isChange ? 1 : 0;
131
+ return `m/360'/${coinType}'/${account}'/${change}/${index}`;
132
+ }
133
+ getCoinType() {
134
+ if (this._network.bech32 === networks.testnet.bech32 ||
135
+ this._network.bech32 === networks.regtest.bech32) {
136
+ return 1;
137
+ }
138
+ return 0;
139
+ }
140
+ }
@@ -0,0 +1,7 @@
1
+ export declare enum MnemonicStrength {
2
+ MINIMUM = 128,
3
+ LOW = 160,
4
+ MEDIUM = 192,
5
+ HIGH = 224,
6
+ MAXIMUM = 256
7
+ }
@@ -0,0 +1,8 @@
1
+ export var MnemonicStrength;
2
+ (function (MnemonicStrength) {
3
+ MnemonicStrength[MnemonicStrength["MINIMUM"] = 128] = "MINIMUM";
4
+ MnemonicStrength[MnemonicStrength["LOW"] = 160] = "LOW";
5
+ MnemonicStrength[MnemonicStrength["MEDIUM"] = 192] = "MEDIUM";
6
+ MnemonicStrength[MnemonicStrength["HIGH"] = 224] = "HIGH";
7
+ MnemonicStrength[MnemonicStrength["MAXIMUM"] = 256] = "MAXIMUM";
8
+ })(MnemonicStrength || (MnemonicStrength = {}));
package/build/opnet.d.ts CHANGED
@@ -19,6 +19,10 @@ export * from './keypair/EcKeyPair.js';
19
19
  export * from './keypair/interfaces/IWallet.js';
20
20
  export * from './keypair/MessageSigner.js';
21
21
  export * from './keypair/Wallet.js';
22
+ export * from './mnemonic/Mnemonic.js';
23
+ export * from './mnemonic/MnemonicStrength.js';
24
+ export * from './mnemonic/BIPStandard.js';
25
+ export { MLDSASecurityLevel, MLDSAKeyPair, QuantumBIP32Interface, QuantumBIP32API, QuantumSigner, QuantumBIP32Factory, QuantumDerivationPath, } from '@btc-vision/bip32';
22
26
  export * from './metadata/ContractBaseMetadata.js';
23
27
  export * from './network/ChainId.js';
24
28
  export * from './signer/TweakedSigner.js';
@@ -66,6 +70,7 @@ export * from './transaction/browser/extensions/UnisatSigner.js';
66
70
  export * from './transaction/browser/extensions/XverseSigner.js';
67
71
  export * from './transaction/browser/types/Unisat.js';
68
72
  export * from './transaction/browser/types/Xverse.js';
73
+ export * from './transaction/browser/types/OPWallet.js';
69
74
  export * from './metadata/tokens.js';
70
75
  export * from './transaction/browser/Web3Provider.js';
71
76
  export * from './keypair/Secp256k1PointDeriver.js';
package/build/opnet.js CHANGED
@@ -18,6 +18,10 @@ export * from './keypair/EcKeyPair.js';
18
18
  export * from './keypair/interfaces/IWallet.js';
19
19
  export * from './keypair/MessageSigner.js';
20
20
  export * from './keypair/Wallet.js';
21
+ export * from './mnemonic/Mnemonic.js';
22
+ export * from './mnemonic/MnemonicStrength.js';
23
+ export * from './mnemonic/BIPStandard.js';
24
+ export { MLDSASecurityLevel, QuantumBIP32Factory, QuantumDerivationPath, } from '@btc-vision/bip32';
21
25
  export * from './metadata/ContractBaseMetadata.js';
22
26
  export * from './network/ChainId.js';
23
27
  export * from './signer/TweakedSigner.js';
@@ -65,6 +69,7 @@ export * from './transaction/browser/extensions/UnisatSigner.js';
65
69
  export * from './transaction/browser/extensions/XverseSigner.js';
66
70
  export * from './transaction/browser/types/Unisat.js';
67
71
  export * from './transaction/browser/types/Xverse.js';
72
+ export * from './transaction/browser/types/OPWallet.js';
68
73
  export * from './metadata/tokens.js';
69
74
  export * from './transaction/browser/Web3Provider.js';
70
75
  export * from './keypair/Secp256k1PointDeriver.js';
@@ -0,0 +1,14 @@
1
+ import { Unisat } from './Unisat.js';
2
+ import { MLDSASecurityLevel } from '@btc-vision/bip32';
3
+ export interface MLDSASignature {
4
+ readonly signature: string;
5
+ readonly publicKey: string;
6
+ readonly securityLevel: MLDSASecurityLevel;
7
+ readonly messageHash: string;
8
+ }
9
+ export interface OPWallet extends Unisat {
10
+ getMLDSAPublicKey(): Promise<string>;
11
+ signMLDSAMessage(message: string): Promise<MLDSASignature>;
12
+ verifyMLDSASignature(message: string, signature: MLDSASignature): Promise<boolean>;
13
+ }
14
+ export declare function isOPWallet(wallet: unknown): wallet is OPWallet;
@@ -0,0 +1,6 @@
1
+ export function isOPWallet(wallet) {
2
+ return (typeof wallet === 'object' &&
3
+ wallet !== null &&
4
+ 'getMLDSAPublicKey' in wallet &&
5
+ 'signMLDSAMessage' in wallet);
6
+ }
@@ -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