@btc-vision/transaction 1.7.7 → 1.7.11

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 (174) hide show
  1. package/browser/_version.d.ts +1 -0
  2. package/browser/chain/ChainData.d.ts +4 -0
  3. package/browser/{src/epoch → epoch}/interfaces/IChallengeSolution.d.ts +4 -4
  4. package/browser/{src/generators → generators}/Features.d.ts +6 -1
  5. package/browser/{src/generators → generators}/Generator.d.ts +1 -0
  6. package/browser/generators/MLDSAData.d.ts +15 -0
  7. package/browser/index.js +1 -1
  8. package/browser/{src/keypair → keypair}/Address.d.ts +9 -3
  9. package/browser/{src/keypair → keypair}/MessageSigner.d.ts +9 -0
  10. package/browser/{src/opnet.d.ts → opnet.d.ts} +1 -0
  11. package/browser/{src/transaction → transaction}/browser/Web3Provider.d.ts +15 -4
  12. package/browser/transaction/browser/types/OPWallet.d.ts +6 -0
  13. package/browser/{src/transaction → transaction}/builders/CustomScriptTransaction.d.ts +1 -0
  14. package/browser/{src/transaction → transaction}/builders/DeploymentTransaction.d.ts +1 -0
  15. package/browser/{src/transaction → transaction}/builders/TransactionBuilder.d.ts +4 -0
  16. package/browser/{src/transaction → transaction}/interfaces/ITransactionParameters.d.ts +3 -0
  17. package/browser/{src/transaction → transaction}/shared/TweakedTransaction.d.ts +6 -0
  18. package/browser/{src/utxo → utxo}/OPNetLimitedProvider.d.ts +1 -0
  19. package/build/_version.d.ts +1 -1
  20. package/build/_version.js +1 -1
  21. package/build/chain/ChainData.d.ts +4 -0
  22. package/build/chain/ChainData.js +20 -0
  23. package/build/epoch/ChallengeSolution.js +4 -4
  24. package/build/epoch/interfaces/IChallengeSolution.d.ts +4 -4
  25. package/build/generators/Features.d.ts +6 -1
  26. package/build/generators/Features.js +1 -0
  27. package/build/generators/Generator.d.ts +1 -0
  28. package/build/generators/Generator.js +24 -2
  29. package/build/generators/MLDSAData.d.ts +15 -0
  30. package/build/generators/MLDSAData.js +19 -0
  31. package/build/generators/builders/CalldataGenerator.js +1 -1
  32. package/build/generators/builders/DeploymentGenerator.js +1 -1
  33. package/build/generators/builders/P2WDAGenerator.js +1 -1
  34. package/build/keypair/Address.d.ts +9 -3
  35. package/build/keypair/Address.js +63 -38
  36. package/build/keypair/MessageSigner.d.ts +9 -0
  37. package/build/keypair/MessageSigner.js +101 -3
  38. package/build/opnet.d.ts +1 -0
  39. package/build/opnet.js +1 -0
  40. package/build/transaction/TransactionFactory.js +3 -0
  41. package/build/transaction/browser/Web3Provider.d.ts +15 -4
  42. package/build/transaction/browser/types/OPWallet.d.ts +2 -10
  43. package/build/transaction/browser/types/OPWallet.js +4 -2
  44. package/build/transaction/builders/CustomScriptTransaction.d.ts +1 -0
  45. package/build/transaction/builders/CustomScriptTransaction.js +3 -0
  46. package/build/transaction/builders/DeploymentTransaction.d.ts +1 -0
  47. package/build/transaction/builders/DeploymentTransaction.js +26 -1
  48. package/build/transaction/builders/InteractionTransaction.js +14 -1
  49. package/build/transaction/builders/InteractionTransactionP2WDA.js +14 -1
  50. package/build/transaction/builders/TransactionBuilder.d.ts +4 -0
  51. package/build/transaction/builders/TransactionBuilder.js +77 -0
  52. package/build/transaction/interfaces/ITransactionParameters.d.ts +3 -0
  53. package/build/transaction/shared/P2TR_MS.js +1 -0
  54. package/build/transaction/shared/TweakedTransaction.d.ts +6 -0
  55. package/build/transaction/shared/TweakedTransaction.js +19 -1
  56. package/build/utxo/OPNetLimitedProvider.d.ts +1 -0
  57. package/build/utxo/OPNetLimitedProvider.js +11 -1
  58. package/eslint.config.js +2 -1
  59. package/package.json +2 -1
  60. package/src/_version.ts +1 -1
  61. package/src/chain/ChainData.ts +32 -0
  62. package/src/deterministic/DeterministicSet.ts +2 -1
  63. package/src/epoch/ChallengeSolution.ts +4 -4
  64. package/src/epoch/interfaces/IChallengeSolution.ts +4 -4
  65. package/src/generators/Features.ts +8 -2
  66. package/src/generators/Generator.ts +35 -2
  67. package/src/generators/MLDSAData.ts +30 -0
  68. package/src/generators/builders/CalldataGenerator.ts +1 -1
  69. package/src/generators/builders/DeploymentGenerator.ts +2 -1
  70. package/src/generators/builders/LegacyCalldataGenerator.ts +1 -0
  71. package/src/generators/builders/P2WDAGenerator.ts +5 -1
  72. package/src/keypair/Address.ts +78 -38
  73. package/src/keypair/MessageSigner.ts +214 -15
  74. package/src/opnet.ts +2 -0
  75. package/src/transaction/TransactionFactory.ts +3 -0
  76. package/src/transaction/browser/Web3Provider.ts +64 -4
  77. package/src/transaction/browser/types/OPWallet.ts +6 -53
  78. package/src/transaction/builders/CustomScriptTransaction.ts +4 -0
  79. package/src/transaction/builders/DeploymentTransaction.ts +36 -8
  80. package/src/transaction/builders/InteractionTransaction.ts +17 -7
  81. package/src/transaction/builders/InteractionTransactionP2WDA.ts +17 -7
  82. package/src/transaction/builders/TransactionBuilder.ts +107 -0
  83. package/src/transaction/interfaces/ITransactionParameters.ts +12 -0
  84. package/src/transaction/shared/P2TR_MS.ts +1 -0
  85. package/src/transaction/shared/TweakedTransaction.ts +35 -2
  86. package/src/utxo/OPNetLimitedProvider.ts +19 -2
  87. package/test/address.test.ts +18 -20
  88. package/test/addressmap.test.ts +783 -0
  89. package/test/addressverificator-mldsa.test.ts +40 -16
  90. package/test/messagesigner-mldsa.test.ts +50 -50
  91. package/test/messagesigner-schnorr.test.ts +40 -40
  92. package/tsconfig.webpack.json +2 -6
  93. package/webpack.config.js +1 -1
  94. package/browser/src/_version.d.ts +0 -1
  95. package/browser/src/transaction/browser/types/OPWallet.d.ts +0 -14
  96. package/browser/test/address.test.d.ts +0 -1
  97. package/browser/test/addressverificator-mldsa.test.d.ts +0 -1
  98. package/browser/test/derivePath.test.d.ts +0 -1
  99. package/browser/test/fastmap-setall.test.d.ts +0 -1
  100. package/browser/test/fastmap.test.d.ts +0 -1
  101. package/browser/test/messagesigner-mldsa.test.d.ts +0 -1
  102. package/browser/test/messagesigner-schnorr.test.d.ts +0 -1
  103. package/browser/test/network-awareness.test.d.ts +0 -1
  104. package/browser/test/old/FastBigIntMap.d.ts +0 -18
  105. package/browser/test/oldfastmap.test.d.ts +0 -1
  106. /package/browser/{src/abi → abi}/ABICoder.d.ts +0 -0
  107. /package/browser/{src/buffer → buffer}/BinaryReader.d.ts +0 -0
  108. /package/browser/{src/buffer → buffer}/BinaryWriter.d.ts +0 -0
  109. /package/browser/{src/bytecode → bytecode}/Compressor.d.ts +0 -0
  110. /package/browser/{src/consensus → consensus}/Consensus.d.ts +0 -0
  111. /package/browser/{src/consensus → consensus}/ConsensusConfig.d.ts +0 -0
  112. /package/browser/{src/consensus → consensus}/metadata/RoswellConsensus.d.ts +0 -0
  113. /package/browser/{src/crypto → crypto}/crypto-browser.d.ts +0 -0
  114. /package/browser/{src/crypto → crypto}/crypto.d.ts +0 -0
  115. /package/browser/{src/deterministic → deterministic}/AddressMap.d.ts +0 -0
  116. /package/browser/{src/deterministic → deterministic}/AddressSet.d.ts +0 -0
  117. /package/browser/{src/deterministic → deterministic}/CustomMap.d.ts +0 -0
  118. /package/browser/{src/deterministic → deterministic}/DeterministicMap.d.ts +0 -0
  119. /package/browser/{src/deterministic → deterministic}/DeterministicSet.d.ts +0 -0
  120. /package/browser/{src/deterministic → deterministic}/FastMap.d.ts +0 -0
  121. /package/browser/{src/epoch → epoch}/ChallengeSolution.d.ts +0 -0
  122. /package/browser/{src/epoch → epoch}/validator/EpochValidator.d.ts +0 -0
  123. /package/browser/{src/event → event}/NetEvent.d.ts +0 -0
  124. /package/browser/{src/generators → generators}/AddressGenerator.d.ts +0 -0
  125. /package/browser/{src/generators → generators}/builders/CalldataGenerator.d.ts +0 -0
  126. /package/browser/{src/generators → generators}/builders/CustomGenerator.d.ts +0 -0
  127. /package/browser/{src/generators → generators}/builders/DeploymentGenerator.d.ts +0 -0
  128. /package/browser/{src/generators → generators}/builders/LegacyCalldataGenerator.d.ts +0 -0
  129. /package/browser/{src/generators → generators}/builders/MultiSignGenerator.d.ts +0 -0
  130. /package/browser/{src/generators → generators}/builders/P2WDAGenerator.d.ts +0 -0
  131. /package/browser/{src/index.d.ts → index.d.ts} +0 -0
  132. /package/browser/{src/keypair → keypair}/AddressVerificator.d.ts +0 -0
  133. /package/browser/{src/keypair → keypair}/EcKeyPair.d.ts +0 -0
  134. /package/browser/{src/keypair → keypair}/Secp256k1PointDeriver.d.ts +0 -0
  135. /package/browser/{src/keypair → keypair}/Wallet.d.ts +0 -0
  136. /package/browser/{src/keypair → keypair}/interfaces/IWallet.d.ts +0 -0
  137. /package/browser/{src/metadata → metadata}/ContractBaseMetadata.d.ts +0 -0
  138. /package/browser/{src/metadata → metadata}/tokens.d.ts +0 -0
  139. /package/browser/{src/mnemonic → mnemonic}/BIPStandard.d.ts +0 -0
  140. /package/browser/{src/mnemonic → mnemonic}/Mnemonic.d.ts +0 -0
  141. /package/browser/{src/mnemonic → mnemonic}/MnemonicStrength.d.ts +0 -0
  142. /package/browser/{src/network → network}/ChainId.d.ts +0 -0
  143. /package/browser/{src/p2wda → p2wda}/P2WDADetector.d.ts +0 -0
  144. /package/browser/{src/signer → signer}/SignerUtils.d.ts +0 -0
  145. /package/browser/{src/signer → signer}/TweakedSigner.d.ts +0 -0
  146. /package/browser/{src/transaction → transaction}/ContractAddress.d.ts +0 -0
  147. /package/browser/{src/transaction → transaction}/TransactionFactory.d.ts +0 -0
  148. /package/browser/{src/transaction → transaction}/browser/BrowserSignerBase.d.ts +0 -0
  149. /package/browser/{src/transaction → transaction}/browser/extensions/UnisatSigner.d.ts +0 -0
  150. /package/browser/{src/transaction → transaction}/browser/extensions/XverseSigner.d.ts +0 -0
  151. /package/browser/{src/transaction → transaction}/browser/types/Unisat.d.ts +0 -0
  152. /package/browser/{src/transaction → transaction}/browser/types/Xverse.d.ts +0 -0
  153. /package/browser/{src/transaction → transaction}/builders/CancelTransaction.d.ts +0 -0
  154. /package/browser/{src/transaction → transaction}/builders/ChallengeSolutionTransaction.d.ts +0 -0
  155. /package/browser/{src/transaction → transaction}/builders/FundingTransaction.d.ts +0 -0
  156. /package/browser/{src/transaction → transaction}/builders/InteractionTransaction.d.ts +0 -0
  157. /package/browser/{src/transaction → transaction}/builders/InteractionTransactionP2WDA.d.ts +0 -0
  158. /package/browser/{src/transaction → transaction}/builders/MultiSignTransaction.d.ts +0 -0
  159. /package/browser/{src/transaction → transaction}/builders/SharedInteractionTransaction.d.ts +0 -0
  160. /package/browser/{src/transaction → transaction}/enums/TransactionType.d.ts +0 -0
  161. /package/browser/{src/transaction → transaction}/interfaces/Tap.d.ts +0 -0
  162. /package/browser/{src/transaction → transaction}/mineable/IP2WSHAddress.d.ts +0 -0
  163. /package/browser/{src/transaction → transaction}/mineable/TimelockGenerator.d.ts +0 -0
  164. /package/browser/{src/transaction → transaction}/processor/PsbtTransaction.d.ts +0 -0
  165. /package/browser/{src/transaction → transaction}/psbt/PSBTTypes.d.ts +0 -0
  166. /package/browser/{src/transaction → transaction}/shared/P2TR_MS.d.ts +0 -0
  167. /package/browser/{src/utils → utils}/BitcoinUtils.d.ts +0 -0
  168. /package/browser/{src/utils → utils}/BufferHelper.d.ts +0 -0
  169. /package/browser/{src/utils → utils}/StringToBuffer.d.ts +0 -0
  170. /package/browser/{src/utils → utils}/lengths.d.ts +0 -0
  171. /package/browser/{src/utils → utils}/types.d.ts +0 -0
  172. /package/browser/{src/utxo → utxo}/interfaces/BroadcastResponse.d.ts +0 -0
  173. /package/browser/{src/utxo → utxo}/interfaces/IUTXO.d.ts +0 -0
  174. /package/browser/{src/verification → verification}/TapscriptVerificator.d.ts +0 -0
@@ -9,7 +9,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
10
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
11
  };
12
- var _Address_p2tr, _Address_p2op, _Address_network, _Address_originalPublicKey, _Address_keyPair, _Address_uncompressed, _Address_tweakedUncompressed, _Address_p2wda, _Address_mldsaPublicKey, _Address_cachedBigInt, _Address_cachedUint64Array;
12
+ var _Address_p2tr, _Address_p2op, _Address_network, _Address_originalPublicKey, _Address_keyPair, _Address_uncompressed, _Address_tweakedUncompressed, _Address_p2wda, _Address_mldsaPublicKey, _Address_cachedBigInt, _Address_cachedUint64Array, _Address_originalMDLSAPublicKey, _Address_mldsaLevel;
13
13
  import { decompressPublicKey, toXOnly } from '@btc-vision/bitcoin';
14
14
  import { ADDRESS_BYTE_LENGTH } from '../utils/lengths.js';
15
15
  import { AddressVerificator } from './AddressVerificator.js';
@@ -33,15 +33,29 @@ export class Address extends Uint8Array {
33
33
  _Address_mldsaPublicKey.set(this, void 0);
34
34
  _Address_cachedBigInt.set(this, void 0);
35
35
  _Address_cachedUint64Array.set(this, void 0);
36
+ _Address_originalMDLSAPublicKey.set(this, void 0);
37
+ _Address_mldsaLevel.set(this, void 0);
36
38
  if (!mldsaPublicKey) {
37
39
  return;
38
40
  }
39
41
  if (publicKeyOrTweak) {
40
- this.classicPublicKey = new Uint8Array(publicKeyOrTweak.length);
41
- this.classicPublicKey.set(publicKeyOrTweak);
42
+ this.legacyPublicKey = new Uint8Array(publicKeyOrTweak.length);
43
+ this.legacyPublicKey.set(publicKeyOrTweak);
42
44
  }
43
45
  this.set(mldsaPublicKey);
44
46
  }
47
+ get mldsaLevel() {
48
+ return __classPrivateFieldGet(this, _Address_mldsaLevel, "f");
49
+ }
50
+ set mldsaLevel(level) {
51
+ __classPrivateFieldSet(this, _Address_mldsaLevel, level, "f");
52
+ }
53
+ get originalMDLSAPublicKey() {
54
+ return __classPrivateFieldGet(this, _Address_originalMDLSAPublicKey, "f");
55
+ }
56
+ set originalMDLSAPublicKey(key) {
57
+ __classPrivateFieldSet(this, _Address_originalMDLSAPublicKey, new Uint8Array(key), "f");
58
+ }
45
59
  get originalPublicKey() {
46
60
  return __classPrivateFieldGet(this, _Address_originalPublicKey, "f");
47
61
  }
@@ -50,14 +64,14 @@ export class Address extends Uint8Array {
50
64
  }
51
65
  get keyPair() {
52
66
  if (!__classPrivateFieldGet(this, _Address_keyPair, "f")) {
53
- throw new Error('Classical public key not set for address');
67
+ throw new Error('Legacy public key not set for address');
54
68
  }
55
69
  return __classPrivateFieldGet(this, _Address_keyPair, "f");
56
70
  }
57
71
  static dead() {
58
72
  return Address.fromString('0x0000000000000000000000000000000000000000000000000000000000000000', '0x04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f');
59
73
  }
60
- static fromString(mldsaPublicKey, classicPublicKey) {
74
+ static fromString(mldsaPublicKey, legacyPublicKey) {
61
75
  if (!mldsaPublicKey) {
62
76
  throw new Error('Invalid public key');
63
77
  }
@@ -68,14 +82,14 @@ export class Address extends Uint8Array {
68
82
  throw new Error('You must only pass public keys in hexadecimal format. If you have an address such as bc1q... you must convert it to a public key first. Please refer to await provider.getPublicKeyInfo("bc1q..."). If the public key associated with the address is not found, you must force the user to enter the destination public key. It looks like: 0x020373626d317ae8788ce3280b491068610d840c23ecb64c14075bbb9f670af52c.');
69
83
  }
70
84
  let classicBuffer;
71
- if (classicPublicKey) {
72
- if (classicPublicKey.startsWith('0x')) {
73
- classicPublicKey = classicPublicKey.slice(2);
85
+ if (legacyPublicKey) {
86
+ if (legacyPublicKey.startsWith('0x')) {
87
+ legacyPublicKey = legacyPublicKey.slice(2);
74
88
  }
75
- if (!BitcoinUtils.isValidHex(classicPublicKey)) {
89
+ if (!BitcoinUtils.isValidHex(legacyPublicKey)) {
76
90
  throw new Error('You must only pass classical public keys in hexadecimal format. If you have an address such as bc1q... you must convert it to a public key first. Please refer to await provider.getPublicKeyInfo("bc1q..."). If the public key associated with the address is not found, you must force the user to enter the destination public key. It looks like: 0x020373626d317ae8788ce3280b491068610d840c23ecb64c14075bbb9f670af52c.');
77
91
  }
78
- classicBuffer = Buffer.from(classicPublicKey, 'hex');
92
+ classicBuffer = Buffer.from(legacyPublicKey, 'hex');
79
93
  }
80
94
  return new Address(Buffer.from(mldsaPublicKey, 'hex'), classicBuffer);
81
95
  }
@@ -122,51 +136,59 @@ export class Address extends Uint8Array {
122
136
  ], "f");
123
137
  return __classPrivateFieldGet(this, _Address_cachedUint64Array, "f");
124
138
  }
139
+ isDead() {
140
+ for (let i = 0; i < ADDRESS_BYTE_LENGTH; i++) {
141
+ if (this[i] !== 0) {
142
+ return false;
143
+ }
144
+ }
145
+ return true;
146
+ }
125
147
  toHex() {
126
148
  return '0x' + Buffer.from(this).toString('hex');
127
149
  }
128
150
  tweakedToHex() {
129
- if (!this.classicPublicKey) {
130
- throw new Error('Classical public key not set');
151
+ if (!this.legacyPublicKey) {
152
+ throw new Error('Legacy public key not set');
131
153
  }
132
- return '0x' + Buffer.from(this.classicPublicKey).toString('hex');
154
+ return '0x' + Buffer.from(this.legacyPublicKey).toString('hex');
133
155
  }
134
156
  toBuffer() {
135
157
  return Buffer.from(this);
136
158
  }
137
159
  tweakedPublicKeyToBuffer() {
138
- if (!this.classicPublicKey) {
139
- throw new Error('Classical public key not set');
160
+ if (!this.legacyPublicKey) {
161
+ throw new Error('Legacy public key not set');
140
162
  }
141
- return Buffer.from(this.classicPublicKey);
163
+ return Buffer.from(this.legacyPublicKey);
142
164
  }
143
165
  toUncompressedHex() {
144
166
  if (!__classPrivateFieldGet(this, _Address_uncompressed, "f")) {
145
- throw new Error('Classical public key not set');
167
+ throw new Error('Legacy public key not set');
146
168
  }
147
169
  return '0x' + __classPrivateFieldGet(this, _Address_uncompressed, "f").uncompressed.toString('hex');
148
170
  }
149
171
  toUncompressedBuffer() {
150
172
  if (!__classPrivateFieldGet(this, _Address_uncompressed, "f")) {
151
- throw new Error('Classical public key not set');
173
+ throw new Error('Legacy public key not set');
152
174
  }
153
175
  return __classPrivateFieldGet(this, _Address_uncompressed, "f").uncompressed;
154
176
  }
155
177
  toHybridPublicKeyHex() {
156
178
  if (!__classPrivateFieldGet(this, _Address_uncompressed, "f")) {
157
- throw new Error('Classical public key not set');
179
+ throw new Error('Legacy public key not set');
158
180
  }
159
181
  return '0x' + __classPrivateFieldGet(this, _Address_uncompressed, "f").hybrid.toString('hex');
160
182
  }
161
183
  toHybridPublicKeyBuffer() {
162
184
  if (!__classPrivateFieldGet(this, _Address_uncompressed, "f")) {
163
- throw new Error('Classical public key not set');
185
+ throw new Error('Legacy public key not set');
164
186
  }
165
187
  return __classPrivateFieldGet(this, _Address_uncompressed, "f").hybrid;
166
188
  }
167
189
  originalPublicKeyBuffer() {
168
190
  if (!__classPrivateFieldGet(this, _Address_originalPublicKey, "f")) {
169
- throw new Error('Classical public key not set');
191
+ throw new Error('Legacy public key not set');
170
192
  }
171
193
  return Buffer.from(__classPrivateFieldGet(this, _Address_originalPublicKey, "f"));
172
194
  }
@@ -222,18 +244,18 @@ export class Address extends Uint8Array {
222
244
  return false;
223
245
  }
224
246
  set(mldsaPublicKey) {
225
- if (this.classicPublicKey) {
247
+ if (this.legacyPublicKey) {
226
248
  const validLengths = [ADDRESS_BYTE_LENGTH, 33, 65];
227
- if (!validLengths.includes(this.classicPublicKey.length)) {
228
- throw new Error(`Invalid public key length ${this.classicPublicKey.length}`);
249
+ if (!validLengths.includes(this.legacyPublicKey.length)) {
250
+ throw new Error(`Invalid public key length ${this.legacyPublicKey.length}`);
229
251
  }
230
- if (this.classicPublicKey.length === ADDRESS_BYTE_LENGTH) {
252
+ if (this.legacyPublicKey.length === ADDRESS_BYTE_LENGTH) {
231
253
  const buf = Buffer.alloc(ADDRESS_BYTE_LENGTH);
232
- buf.set(this.classicPublicKey);
254
+ buf.set(this.legacyPublicKey);
233
255
  __classPrivateFieldSet(this, _Address_tweakedUncompressed, ContractAddress.generateHybridKeyFromHash(buf), "f");
234
256
  }
235
257
  else {
236
- this.autoFormat(this.classicPublicKey);
258
+ this.autoFormat(this.legacyPublicKey);
237
259
  }
238
260
  }
239
261
  if (mldsaPublicKey.length === ADDRESS_BYTE_LENGTH) {
@@ -255,8 +277,11 @@ export class Address extends Uint8Array {
255
277
  super.set(buf);
256
278
  }
257
279
  }
258
- isValid(network) {
259
- return AddressVerificator.isValidPublicKey(Buffer.from(this).toString('hex'), network);
280
+ isValidLegacyPublicKey(network) {
281
+ if (!this.legacyPublicKey) {
282
+ throw new Error(`Legacy key not set.`);
283
+ }
284
+ return AddressVerificator.isValidPublicKey(Buffer.from(this.legacyPublicKey).toString('hex'), network);
260
285
  }
261
286
  p2pk() {
262
287
  return this.toHex();
@@ -277,19 +302,19 @@ export class Address extends Uint8Array {
277
302
  return this.toHex();
278
303
  }
279
304
  p2tr(network) {
280
- if (!this.classicPublicKey) {
281
- throw new Error('Classical public key not set');
305
+ if (!this.legacyPublicKey) {
306
+ throw new Error('Legacy public key not set');
282
307
  }
283
308
  if (__classPrivateFieldGet(this, _Address_p2tr, "f") && __classPrivateFieldGet(this, _Address_network, "f") === network) {
284
309
  return __classPrivateFieldGet(this, _Address_p2tr, "f");
285
310
  }
286
- const p2trAddy = EcKeyPair.tweakedPubKeyBufferToAddress(this.classicPublicKey, network);
311
+ const p2trAddy = EcKeyPair.tweakedPubKeyBufferToAddress(this.legacyPublicKey, network);
287
312
  if (p2trAddy) {
288
313
  __classPrivateFieldSet(this, _Address_network, network, "f");
289
314
  __classPrivateFieldSet(this, _Address_p2tr, p2trAddy, "f");
290
315
  return p2trAddy;
291
316
  }
292
- throw new Error('Classical public key not set');
317
+ throw new Error('Legacy public key not set');
293
318
  }
294
319
  p2wda(network) {
295
320
  if (__classPrivateFieldGet(this, _Address_p2wda, "f") && __classPrivateFieldGet(this, _Address_network, "f") === network) {
@@ -340,13 +365,13 @@ export class Address extends Uint8Array {
340
365
  }
341
366
  toTweakedHybridPublicKeyHex() {
342
367
  if (!__classPrivateFieldGet(this, _Address_tweakedUncompressed, "f")) {
343
- throw new Error('Classical public key not set');
368
+ throw new Error('Legacy public key not set');
344
369
  }
345
370
  return '0x' + __classPrivateFieldGet(this, _Address_tweakedUncompressed, "f").toString('hex');
346
371
  }
347
372
  toTweakedHybridPublicKeyBuffer() {
348
373
  if (!__classPrivateFieldGet(this, _Address_tweakedUncompressed, "f")) {
349
- throw new Error('Classical public key not set');
374
+ throw new Error('Legacy public key not set');
350
375
  }
351
376
  return __classPrivateFieldGet(this, _Address_tweakedUncompressed, "f");
352
377
  }
@@ -362,8 +387,8 @@ export class Address extends Uint8Array {
362
387
  __classPrivateFieldSet(this, _Address_uncompressed, decompressPublicKey(__classPrivateFieldGet(this, _Address_originalPublicKey, "f")), "f");
363
388
  const tweakedBytes = toXOnly(EcKeyPair.tweakPublicKey(Buffer.from(__classPrivateFieldGet(this, _Address_originalPublicKey, "f"))));
364
389
  __classPrivateFieldSet(this, _Address_tweakedUncompressed, ContractAddress.generateHybridKeyFromHash(tweakedBytes), "f");
365
- this.classicPublicKey = new Uint8Array(ADDRESS_BYTE_LENGTH);
366
- this.classicPublicKey.set(tweakedBytes);
390
+ this.legacyPublicKey = new Uint8Array(ADDRESS_BYTE_LENGTH);
391
+ this.legacyPublicKey.set(tweakedBytes);
367
392
  }
368
393
  }
369
- _Address_p2tr = new WeakMap(), _Address_p2op = new WeakMap(), _Address_network = new WeakMap(), _Address_originalPublicKey = new WeakMap(), _Address_keyPair = new WeakMap(), _Address_uncompressed = new WeakMap(), _Address_tweakedUncompressed = new WeakMap(), _Address_p2wda = new WeakMap(), _Address_mldsaPublicKey = new WeakMap(), _Address_cachedBigInt = new WeakMap(), _Address_cachedUint64Array = new WeakMap();
394
+ _Address_p2tr = new WeakMap(), _Address_p2op = new WeakMap(), _Address_network = new WeakMap(), _Address_originalPublicKey = new WeakMap(), _Address_keyPair = new WeakMap(), _Address_uncompressed = new WeakMap(), _Address_tweakedUncompressed = new WeakMap(), _Address_p2wda = new WeakMap(), _Address_mldsaPublicKey = new WeakMap(), _Address_cachedBigInt = new WeakMap(), _Address_cachedUint64Array = new WeakMap(), _Address_originalMDLSAPublicKey = new WeakMap(), _Address_mldsaLevel = new WeakMap();
@@ -13,12 +13,21 @@ export interface MLDSASignedMessage {
13
13
  }
14
14
  declare class MessageSignerBase {
15
15
  sha256(message: Buffer | Uint8Array): Buffer;
16
+ trySignSchnorrWithOPWallet(message: Uint8Array | Buffer | string): Promise<SignedMessage | null>;
17
+ trySignMLDSAWithOPWallet(message: Uint8Array | Buffer | string): Promise<MLDSASignedMessage | null>;
18
+ signMessageAuto(message: Uint8Array | Buffer | string, keypair?: ECPairInterface): Promise<SignedMessage>;
19
+ tweakAndSignMessageAuto(message: Uint8Array | Buffer | string, keypair?: ECPairInterface, network?: Network): Promise<SignedMessage>;
20
+ signMLDSAMessageAuto(message: Uint8Array | Buffer | string, mldsaKeypair?: QuantumBIP32Interface): Promise<MLDSASignedMessage>;
21
+ verifyMLDSAWithOPWallet(message: Uint8Array | Buffer | string, signature: MLDSASignedMessage): Promise<boolean | null>;
22
+ getMLDSAPublicKeyFromOPWallet(): Promise<Buffer | null>;
16
23
  tweakAndSignMessage(keypair: ECPairInterface, message: Uint8Array | Buffer | string, network: Network): SignedMessage;
17
24
  signMessage(keypair: ECPairInterface, message: Uint8Array | Buffer | string): SignedMessage;
18
25
  verifySignature(publicKey: Uint8Array | Buffer, message: Uint8Array | Buffer | string, signature: Uint8Array | Buffer): boolean;
19
26
  tweakAndVerifySignature(publicKey: Uint8Array | Buffer, message: Uint8Array | Buffer | string, signature: Uint8Array | Buffer): boolean;
20
27
  signMLDSAMessage(mldsaKeypair: QuantumBIP32Interface, message: Uint8Array | Buffer | string): MLDSASignedMessage;
21
28
  verifyMLDSASignature(mldsaKeypair: QuantumBIP32Interface, message: Uint8Array | Buffer | string, signature: Uint8Array | Buffer): boolean;
29
+ isOPWalletAvailable(): boolean;
30
+ private getOPWallet;
22
31
  }
23
32
  export declare const MessageSigner: MessageSignerBase;
24
33
  export {};
@@ -2,14 +2,99 @@ import * as ecc from '@bitcoinerlab/secp256k1';
2
2
  import { crypto, toXOnly } from '@btc-vision/bitcoin';
3
3
  import { TweakedSigner } from '../signer/TweakedSigner.js';
4
4
  import { EcKeyPair } from './EcKeyPair.js';
5
+ import { isOPWallet } from '../transaction/browser/types/OPWallet.js';
5
6
  class MessageSignerBase {
6
7
  sha256(message) {
7
8
  return crypto.sha256(Buffer.from(message));
8
9
  }
10
+ async trySignSchnorrWithOPWallet(message) {
11
+ const wallet = this.getOPWallet();
12
+ if (!wallet) {
13
+ return null;
14
+ }
15
+ const messageBuffer = typeof message === 'string' ? Buffer.from(message, 'utf-8') : Buffer.from(message);
16
+ const hashedMessage = this.sha256(messageBuffer);
17
+ const messageHex = hashedMessage.toString('hex');
18
+ const signatureHex = await wallet.web3.signSchnorr(messageHex);
19
+ return {
20
+ signature: Buffer.from(signatureHex, 'hex'),
21
+ message: hashedMessage,
22
+ };
23
+ }
24
+ async trySignMLDSAWithOPWallet(message) {
25
+ const wallet = this.getOPWallet();
26
+ if (!wallet) {
27
+ return null;
28
+ }
29
+ const messageBuffer = typeof message === 'string' ? Buffer.from(message, 'utf-8') : Buffer.from(message);
30
+ const hashedMessage = this.sha256(messageBuffer);
31
+ const messageHex = hashedMessage.toString('hex');
32
+ const result = await wallet.web3.signMLDSAMessage(messageHex);
33
+ return {
34
+ signature: Buffer.from(result.signature, 'hex'),
35
+ message: hashedMessage,
36
+ publicKey: Buffer.from(result.publicKey, 'hex'),
37
+ securityLevel: result.securityLevel,
38
+ };
39
+ }
40
+ async signMessageAuto(message, keypair) {
41
+ if (!keypair) {
42
+ const walletResult = await this.trySignSchnorrWithOPWallet(message);
43
+ if (walletResult) {
44
+ return walletResult;
45
+ }
46
+ throw new Error('No keypair provided and OP_WALLET is not available.');
47
+ }
48
+ return this.signMessage(keypair, message);
49
+ }
50
+ async tweakAndSignMessageAuto(message, keypair, network) {
51
+ if (!keypair) {
52
+ const walletResult = await this.trySignSchnorrWithOPWallet(message);
53
+ if (walletResult) {
54
+ return walletResult;
55
+ }
56
+ throw new Error('No keypair provided and OP_WALLET is not available.');
57
+ }
58
+ if (!network) {
59
+ throw new Error('Network is required when signing with a local keypair.');
60
+ }
61
+ return this.tweakAndSignMessage(keypair, message, network);
62
+ }
63
+ async signMLDSAMessageAuto(message, mldsaKeypair) {
64
+ if (!mldsaKeypair) {
65
+ const walletResult = await this.trySignMLDSAWithOPWallet(message);
66
+ if (walletResult) {
67
+ return walletResult;
68
+ }
69
+ throw new Error('No ML-DSA keypair provided and OP_WALLET is not available.');
70
+ }
71
+ return this.signMLDSAMessage(mldsaKeypair, message);
72
+ }
73
+ async verifyMLDSAWithOPWallet(message, signature) {
74
+ const wallet = this.getOPWallet();
75
+ if (!wallet) {
76
+ return null;
77
+ }
78
+ const messageBuffer = typeof message === 'string' ? Buffer.from(message, 'utf-8') : Buffer.from(message);
79
+ const hashedMessage = this.sha256(messageBuffer);
80
+ const mldsaSignature = {
81
+ signature: Buffer.from(signature.signature).toString('hex'),
82
+ publicKey: Buffer.from(signature.publicKey).toString('hex'),
83
+ securityLevel: signature.securityLevel,
84
+ messageHash: hashedMessage.toString('hex'),
85
+ };
86
+ return wallet.web3.verifyMLDSASignature(hashedMessage.toString('hex'), mldsaSignature);
87
+ }
88
+ async getMLDSAPublicKeyFromOPWallet() {
89
+ const wallet = this.getOPWallet();
90
+ if (!wallet) {
91
+ return null;
92
+ }
93
+ const publicKeyHex = await wallet.web3.getMLDSAPublicKey();
94
+ return Buffer.from(publicKeyHex, 'hex');
95
+ }
9
96
  tweakAndSignMessage(keypair, message, network) {
10
- const tweaked = TweakedSigner.tweakSigner(keypair, {
11
- network,
12
- });
97
+ const tweaked = TweakedSigner.tweakSigner(keypair, { network });
13
98
  return this.signMessage(tweaked, message);
14
99
  }
15
100
  signMessage(keypair, message) {
@@ -62,5 +147,18 @@ class MessageSignerBase {
62
147
  const hashedMessage = this.sha256(message);
63
148
  return mldsaKeypair.verify(hashedMessage, signature);
64
149
  }
150
+ isOPWalletAvailable() {
151
+ return this.getOPWallet() !== null;
152
+ }
153
+ getOPWallet() {
154
+ if (typeof window === 'undefined') {
155
+ return null;
156
+ }
157
+ const _window = window;
158
+ if (!_window.opnet || !isOPWallet(_window.opnet)) {
159
+ return null;
160
+ }
161
+ return _window.opnet;
162
+ }
65
163
  }
66
164
  export const MessageSigner = new MessageSignerBase();
package/build/opnet.d.ts CHANGED
@@ -23,6 +23,7 @@ export * from './mnemonic/Mnemonic.js';
23
23
  export * from './mnemonic/MnemonicStrength.js';
24
24
  export * from './mnemonic/BIPStandard.js';
25
25
  export { MLDSASecurityLevel, MLDSAKeyPair, QuantumBIP32Interface, QuantumBIP32API, QuantumSigner, QuantumBIP32Factory, QuantumDerivationPath, } from '@btc-vision/bip32';
26
+ export * from './generators/MLDSAData.js';
26
27
  export * from './metadata/ContractBaseMetadata.js';
27
28
  export * from './network/ChainId.js';
28
29
  export * from './signer/TweakedSigner.js';
package/build/opnet.js CHANGED
@@ -22,6 +22,7 @@ export * from './mnemonic/Mnemonic.js';
22
22
  export * from './mnemonic/MnemonicStrength.js';
23
23
  export * from './mnemonic/BIPStandard.js';
24
24
  export { MLDSASecurityLevel, QuantumBIP32Factory, QuantumDerivationPath, } from '@btc-vision/bip32';
25
+ export * from './generators/MLDSAData.js';
25
26
  export * from './metadata/ContractBaseMetadata.js';
26
27
  export * from './network/ChainId.js';
27
28
  export * from './signer/TweakedSigner.js';
@@ -92,6 +92,7 @@ export class TransactionFactory {
92
92
  randomBytes: finalTransaction.getRndBytes(),
93
93
  nonWitnessUtxo: signedTransaction.tx.toBuffer(),
94
94
  estimatedFees: finalTransaction.estimatedFees,
95
+ compiledTargetScript: finalTransaction.exportCompiledTargetScript(),
95
96
  optionalInputs: inputs,
96
97
  };
97
98
  const customTransaction = new CustomScriptTransaction(newParams);
@@ -158,6 +159,7 @@ export class TransactionFactory {
158
159
  utxos: fundingUTXO,
159
160
  randomBytes: finalTransaction.getRndBytes(),
160
161
  challenge: challenge,
162
+ compiledTargetScript: finalTransaction.exportCompiledTargetScript(),
161
163
  nonWitnessUtxo: signedTransaction.tx.toBuffer(),
162
164
  estimatedFees: finalTransaction.estimatedFees,
163
165
  optionalInputs: inputs,
@@ -228,6 +230,7 @@ export class TransactionFactory {
228
230
  ...deploymentParameters,
229
231
  utxos: [newUtxo],
230
232
  randomBytes: finalTransaction.getRndBytes(),
233
+ compiledTargetScript: finalTransaction.exportCompiledTargetScript(),
231
234
  challenge: challenge,
232
235
  nonWitnessUtxo: signedTransaction.toBuffer(),
233
236
  estimatedFees: finalTransaction.estimatedFees,
@@ -3,10 +3,11 @@ import { UTXO } from '../../utxo/interfaces/IUTXO.js';
3
3
  import { CancelledTransaction, DeploymentResult, InteractionResponse } from '../TransactionFactory';
4
4
  import { ICustomTransactionParameters } from '../builders/CustomScriptTransaction.js';
5
5
  import { ICancelTransactionParameters } from '../builders/CancelTransaction.js';
6
- export type InteractionParametersWithoutSigner = Omit<IInteractionParameters, 'signer' | 'challenge'>;
7
- export type IDeploymentParametersWithoutSigner = Omit<IDeploymentParameters, 'signer' | 'network' | 'challenge'>;
8
- export type ICustomTransactionWithoutSigner = Omit<ICustomTransactionParameters, 'signer' | 'challenge'>;
9
- export type ICancelTransactionParametersWithoutSigner = Omit<ICancelTransactionParameters, 'signer' | 'challenge' | 'network'>;
6
+ import { MLDSASecurityLevel } from '@btc-vision/bip32';
7
+ export type InteractionParametersWithoutSigner = Omit<IInteractionParameters, 'signer' | 'challenge' | 'mldsaSigner'>;
8
+ export type IDeploymentParametersWithoutSigner = Omit<IDeploymentParameters, 'signer' | 'network' | 'challenge' | 'mldsaSigner'>;
9
+ export type ICustomTransactionWithoutSigner = Omit<ICustomTransactionParameters, 'signer' | 'challenge' | 'mldsaSigner'>;
10
+ export type ICancelTransactionParametersWithoutSigner = Omit<ICancelTransactionParameters, 'signer' | 'challenge' | 'network' | 'mldsaSigner'>;
10
11
  export interface BroadcastTransactionOptions {
11
12
  raw: string;
12
13
  psbt: boolean;
@@ -17,6 +18,12 @@ export interface BroadcastedTransaction {
17
18
  readonly error?: string;
18
19
  readonly peers?: number;
19
20
  }
21
+ export interface MLDSASignature {
22
+ readonly signature: string;
23
+ readonly publicKey: string;
24
+ readonly securityLevel: MLDSASecurityLevel;
25
+ readonly messageHash: string;
26
+ }
20
27
  export interface Web3Provider {
21
28
  signInteraction(interactionParameters: InteractionParametersWithoutSigner): Promise<InteractionResponse>;
22
29
  signAndBroadcastInteraction(interactionParameters: InteractionParametersWithoutSigner): Promise<[BroadcastedTransaction, BroadcastedTransaction, UTXO[], string]>;
@@ -24,4 +31,8 @@ export interface Web3Provider {
24
31
  customTransaction(params: ICustomTransactionWithoutSigner): Promise<BroadcastedTransaction>;
25
32
  deployContract(params: IDeploymentParametersWithoutSigner): Promise<DeploymentResult>;
26
33
  broadcast(transactions: BroadcastTransactionOptions[]): Promise<BroadcastedTransaction[]>;
34
+ signSchnorr(message: string): Promise<string>;
35
+ getMLDSAPublicKey(): Promise<string>;
36
+ signMLDSAMessage(message: string): Promise<MLDSASignature>;
37
+ verifyMLDSASignature(message: string, signature: MLDSASignature): Promise<boolean>;
27
38
  }
@@ -1,14 +1,6 @@
1
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
- }
2
+ import { Web3Provider } from '../Web3Provider.js';
9
3
  export interface OPWallet extends Unisat {
10
- getMLDSAPublicKey(): Promise<string>;
11
- signMLDSAMessage(message: string): Promise<MLDSASignature>;
12
- verifyMLDSASignature(message: string, signature: MLDSASignature): Promise<boolean>;
4
+ web3: Web3Provider;
13
5
  }
14
6
  export declare function isOPWallet(wallet: unknown): wallet is OPWallet;
@@ -1,6 +1,8 @@
1
1
  export function isOPWallet(wallet) {
2
2
  return (typeof wallet === 'object' &&
3
3
  wallet !== null &&
4
- 'getMLDSAPublicKey' in wallet &&
5
- 'signMLDSAMessage' in wallet);
4
+ 'web3' in wallet &&
5
+ typeof wallet.web3 === 'object' &&
6
+ 'getMLDSAPublicKey' in wallet.web3 &&
7
+ 'signMLDSAMessage' in wallet.web3);
6
8
  }
@@ -26,6 +26,7 @@ export declare class CustomScriptTransaction extends TransactionBuilder<Transact
26
26
  constructor(parameters: ICustomTransactionParameters);
27
27
  get scriptAddress(): string;
28
28
  get p2trAddress(): string;
29
+ exportCompiledTargetScript(): Buffer;
29
30
  getRndBytes(): Buffer;
30
31
  protected contractSignerXOnlyPubKey(): Buffer;
31
32
  protected buildTransaction(): Promise<void>;
@@ -51,6 +51,9 @@ export class CustomScriptTransaction extends TransactionBuilder {
51
51
  get p2trAddress() {
52
52
  return this.to || this.getScriptAddress();
53
53
  }
54
+ exportCompiledTargetScript() {
55
+ return this.compiledTargetScript;
56
+ }
54
57
  getRndBytes() {
55
58
  return this.randomBytes;
56
59
  }
@@ -30,6 +30,7 @@ export declare class DeploymentTransaction extends TransactionBuilder<Transactio
30
30
  get contractPubKey(): string;
31
31
  get contractAddress(): Address;
32
32
  get p2trAddress(): string;
33
+ exportCompiledTargetScript(): Buffer;
33
34
  getRndBytes(): Buffer;
34
35
  getChallenge(): ChallengeSolution;
35
36
  getContractAddress(): string;
@@ -36,6 +36,9 @@ export class DeploymentTransaction extends TransactionBuilder {
36
36
  finalScriptWitness: TransactionBuilder.witnessStackToScriptWitness(witness),
37
37
  };
38
38
  };
39
+ if (!this.hashedPublicKey) {
40
+ throw new Error('MLDSA signer must be defined to deploy a contract.');
41
+ }
39
42
  this.bytecode = Compressor.compress(Buffer.concat([versionBuffer, parameters.bytecode]));
40
43
  this.verifyBytecode();
41
44
  if (parameters.calldata) {
@@ -51,7 +54,20 @@ export class DeploymentTransaction extends TransactionBuilder {
51
54
  this.contractSeed = this.getContractSeed();
52
55
  this.contractSigner = EcKeyPair.fromSeedKeyPair(this.contractSeed, this.network);
53
56
  this.deploymentGenerator = new DeploymentGenerator(Buffer.from(this.signer.publicKey), this.contractSignerXOnlyPubKey(), this.network);
54
- this.compiledTargetScript = this.deploymentGenerator.compile(this.bytecode, this.randomBytes, this.challenge, this.priorityFee, this.calldata, this.generateFeatures(parameters));
57
+ if (parameters.compiledTargetScript) {
58
+ if (Buffer.isBuffer(parameters.compiledTargetScript)) {
59
+ this.compiledTargetScript = parameters.compiledTargetScript;
60
+ }
61
+ else if (typeof parameters.compiledTargetScript === 'string') {
62
+ this.compiledTargetScript = Buffer.from(parameters.compiledTargetScript, 'hex');
63
+ }
64
+ else {
65
+ throw new Error('Invalid compiled target script format.');
66
+ }
67
+ }
68
+ else {
69
+ this.compiledTargetScript = this.deploymentGenerator.compile(this.bytecode, this.randomBytes, this.challenge, this.priorityFee, this.calldata, this.generateFeatures(parameters));
70
+ }
55
71
  this.scriptTree = this.getScriptTree();
56
72
  this.internalInit();
57
73
  this._contractPubKey = '0x' + this.contractSeed.toString('hex');
@@ -66,6 +82,9 @@ export class DeploymentTransaction extends TransactionBuilder {
66
82
  get p2trAddress() {
67
83
  return this.to || this.getScriptAddress();
68
84
  }
85
+ exportCompiledTargetScript() {
86
+ return this.compiledTargetScript;
87
+ }
69
88
  getRndBytes() {
70
89
  return this.randomBytes;
71
90
  }
@@ -187,6 +206,12 @@ export class DeploymentTransaction extends TransactionBuilder {
187
206
  data: submission,
188
207
  });
189
208
  }
209
+ if (parameters.revealMLDSAPublicKey && !parameters.linkMLDSAPublicKeyToAddress) {
210
+ throw new Error('To reveal the MLDSA public key, you must set linkMLDSAPublicKeyToAddress to true.');
211
+ }
212
+ if (parameters.linkMLDSAPublicKeyToAddress) {
213
+ this.generateMLDSALinkRequest(parameters, features);
214
+ }
190
215
  return features;
191
216
  }
192
217
  verifyCalldata() {
@@ -13,7 +13,20 @@ export class InteractionTransaction extends SharedInteractionTransaction {
13
13
  if (this.contractSecret.length !== 32) {
14
14
  throw new Error('Invalid contract secret length. Expected 32 bytes.');
15
15
  }
16
- this.compiledTargetScript = this.calldataGenerator.compile(this.calldata, this.contractSecret, this.challenge, this.priorityFee, this.generateFeatures(parameters));
16
+ if (parameters.compiledTargetScript) {
17
+ if (Buffer.isBuffer(parameters.compiledTargetScript)) {
18
+ this.compiledTargetScript = parameters.compiledTargetScript;
19
+ }
20
+ else if (typeof parameters.compiledTargetScript === 'string') {
21
+ this.compiledTargetScript = Buffer.from(parameters.compiledTargetScript, 'hex');
22
+ }
23
+ else {
24
+ throw new Error('Invalid compiled target script format.');
25
+ }
26
+ }
27
+ else {
28
+ this.compiledTargetScript = this.calldataGenerator.compile(this.calldata, this.contractSecret, this.challenge, this.priorityFee, this.generateFeatures(parameters));
29
+ }
17
30
  this.scriptTree = this.getScriptTree();
18
31
  this.internalInit();
19
32
  }
@@ -41,7 +41,20 @@ export class InteractionTransactionP2WDA extends TransactionBuilder {
41
41
  }
42
42
  this.epochChallenge = TimeLockGenerator.generateTimeLockAddress(this.challenge.publicKey.originalPublicKeyBuffer(), this.network);
43
43
  this.validateP2WDAInputs();
44
- this.compiledOperationData = this.p2wdaGenerator.compile(this.calldata, this.contractSecret, this.challenge, this.priorityFee, this.generateFeatures(parameters));
44
+ if (parameters.compiledTargetScript) {
45
+ if (Buffer.isBuffer(parameters.compiledTargetScript)) {
46
+ this.compiledOperationData = parameters.compiledTargetScript;
47
+ }
48
+ else if (typeof parameters.compiledTargetScript === 'string') {
49
+ this.compiledOperationData = Buffer.from(parameters.compiledTargetScript, 'hex');
50
+ }
51
+ else {
52
+ throw new Error('Invalid compiled target script format.');
53
+ }
54
+ }
55
+ else {
56
+ this.compiledOperationData = this.p2wdaGenerator.compile(this.calldata, this.contractSecret, this.challenge, this.priorityFee, this.generateFeatures(parameters));
57
+ }
45
58
  this.validateOperationDataSize();
46
59
  this.internalInit();
47
60
  }
@@ -7,6 +7,7 @@ import { ECPairInterface } from 'ecpair';
7
7
  import { TweakedTransaction } from '../shared/TweakedTransaction.js';
8
8
  import { UnisatSigner } from '../browser/extensions/UnisatSigner.js';
9
9
  import { IP2WSHAddress } from '../mineable/IP2WSHAddress.js';
10
+ import { Feature, Features } from '../../generators/Features.js';
10
11
  export declare const MINIMUM_AMOUNT_REWARD: bigint;
11
12
  export declare const MINIMUM_AMOUNT_CA: bigint;
12
13
  export declare const ANCHOR_SCRIPT: Buffer<ArrayBuffer>;
@@ -64,6 +65,9 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
64
65
  protected addRefundOutput(amountSpent: bigint, expectRefund?: boolean): Promise<void>;
65
66
  protected defineLockScript(): Buffer;
66
67
  protected addValueToToOutput(value: number | bigint): void;
68
+ protected generateLegacySignature(): Buffer;
69
+ protected generateMLDSASignature(): Buffer;
70
+ protected generateMLDSALinkRequest(parameters: ITransactionParameters, features: Feature<Features>[]): void;
67
71
  protected getTransactionOPNetFee(): bigint;
68
72
  protected calculateTotalUTXOAmount(): bigint;
69
73
  protected calculateTotalVOutAmount(): bigint;