@btc-vision/transaction 1.7.28 → 1.7.30

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 (134) hide show
  1. package/browser/_version.d.ts +1 -1
  2. package/browser/btc-vision-bitcoin.js +1610 -1609
  3. package/browser/consensus/ConsensusConfig.d.ts +1 -5
  4. package/browser/consensus/IConsensusConfig.d.ts +6 -0
  5. package/browser/consensus/metadata/RoswellConsensus.d.ts +1 -1
  6. package/browser/epoch/interfaces/IChallengeSolution.d.ts +15 -1
  7. package/browser/generators/builders/CalldataGenerator.d.ts +2 -2
  8. package/browser/generators/builders/DeploymentGenerator.d.ts +2 -2
  9. package/browser/generators/builders/P2WDAGenerator.d.ts +2 -2
  10. package/browser/index.js +876 -1055
  11. package/browser/opnet.d.ts +10 -3
  12. package/browser/signer/AddressRotation.d.ts +2 -3
  13. package/browser/signer/IRotationSigner.d.ts +8 -0
  14. package/browser/transaction/TransactionFactory.d.ts +4 -27
  15. package/browser/transaction/browser/WalletNetworks.d.ts +14 -0
  16. package/browser/transaction/browser/Web3Provider.d.ts +2 -25
  17. package/browser/transaction/browser/extensions/UnisatSigner.d.ts +2 -1
  18. package/browser/transaction/browser/types/Unisat.d.ts +5 -18
  19. package/browser/transaction/builders/CancelTransaction.d.ts +1 -4
  20. package/browser/transaction/builders/ConsolidatedInteractionTransaction.d.ts +3 -3
  21. package/browser/transaction/builders/CustomScriptTransaction.d.ts +2 -8
  22. package/browser/transaction/builders/DeploymentTransaction.d.ts +3 -3
  23. package/browser/transaction/builders/InteractionTransactionP2WDA.d.ts +2 -2
  24. package/browser/transaction/builders/SharedInteractionTransaction.d.ts +3 -3
  25. package/browser/transaction/interfaces/ICancelTransactionParameters.d.ts +4 -0
  26. package/browser/transaction/interfaces/ICustomTransactionParameters.d.ts +8 -0
  27. package/browser/transaction/interfaces/ITransactionParameters.d.ts +6 -6
  28. package/browser/transaction/interfaces/ITransactionResponses.d.ts +26 -0
  29. package/browser/transaction/interfaces/ITweakedTransactionData.d.ts +17 -0
  30. package/browser/transaction/interfaces/IWeb3ProviderTypes.d.ts +24 -0
  31. package/browser/transaction/shared/TweakedTransaction.d.ts +2 -14
  32. package/browser/transaction/utils/WitnessUtils.d.ts +1 -0
  33. package/browser/utxo/OPNetLimitedProvider.d.ts +1 -1
  34. package/browser/utxo/interfaces/IUTXO.d.ts +2 -2
  35. package/browser/vendors.js +90 -90
  36. package/browser/verification/TapscriptVerificator.d.ts +2 -2
  37. package/build/_version.d.ts +1 -1
  38. package/build/_version.js +1 -1
  39. package/build/consensus/ConsensusConfig.d.ts +1 -5
  40. package/build/consensus/IConsensusConfig.d.ts +6 -0
  41. package/build/consensus/IConsensusConfig.js +1 -0
  42. package/build/consensus/metadata/RoswellConsensus.d.ts +1 -1
  43. package/build/epoch/interfaces/IChallengeSolution.d.ts +15 -1
  44. package/build/epoch/validator/EpochValidator.js +35 -3
  45. package/build/generators/builders/CalldataGenerator.d.ts +2 -2
  46. package/build/generators/builders/DeploymentGenerator.d.ts +2 -2
  47. package/build/generators/builders/P2WDAGenerator.d.ts +2 -2
  48. package/build/opnet.d.ts +10 -3
  49. package/build/opnet.js +8 -2
  50. package/build/signer/AddressRotation.d.ts +2 -3
  51. package/build/signer/IRotationSigner.d.ts +8 -0
  52. package/build/signer/IRotationSigner.js +1 -0
  53. package/build/transaction/TransactionFactory.d.ts +4 -27
  54. package/build/transaction/TransactionFactory.js +1 -1
  55. package/build/transaction/browser/WalletNetworks.d.ts +14 -0
  56. package/build/transaction/browser/WalletNetworks.js +16 -0
  57. package/build/transaction/browser/Web3Provider.d.ts +2 -25
  58. package/build/transaction/browser/extensions/UnisatSigner.d.ts +2 -1
  59. package/build/transaction/browser/extensions/UnisatSigner.js +4 -4
  60. package/build/transaction/browser/types/Unisat.d.ts +5 -18
  61. package/build/transaction/browser/types/Unisat.js +0 -16
  62. package/build/transaction/builders/CancelTransaction.d.ts +1 -4
  63. package/build/transaction/builders/ConsolidatedInteractionTransaction.d.ts +3 -3
  64. package/build/transaction/builders/CustomScriptTransaction.d.ts +2 -8
  65. package/build/transaction/builders/DeploymentTransaction.d.ts +3 -3
  66. package/build/transaction/builders/InteractionTransactionP2WDA.d.ts +2 -2
  67. package/build/transaction/builders/SharedInteractionTransaction.d.ts +3 -3
  68. package/build/transaction/builders/TransactionBuilder.js +3 -21
  69. package/build/transaction/interfaces/ICancelTransactionParameters.d.ts +4 -0
  70. package/build/transaction/interfaces/ICancelTransactionParameters.js +1 -0
  71. package/build/transaction/interfaces/ICustomTransactionParameters.d.ts +8 -0
  72. package/build/transaction/interfaces/ICustomTransactionParameters.js +1 -0
  73. package/build/transaction/interfaces/ITransactionParameters.d.ts +6 -6
  74. package/build/transaction/interfaces/ITransactionResponses.d.ts +26 -0
  75. package/build/transaction/interfaces/ITransactionResponses.js +1 -0
  76. package/build/transaction/interfaces/ITweakedTransactionData.d.ts +17 -0
  77. package/build/transaction/interfaces/ITweakedTransactionData.js +1 -0
  78. package/build/transaction/interfaces/IWeb3ProviderTypes.d.ts +24 -0
  79. package/build/transaction/interfaces/IWeb3ProviderTypes.js +1 -0
  80. package/build/transaction/shared/TweakedTransaction.d.ts +2 -14
  81. package/build/transaction/shared/TweakedTransaction.js +3 -3
  82. package/build/transaction/utils/WitnessUtils.d.ts +1 -0
  83. package/build/transaction/utils/WitnessUtils.js +23 -0
  84. package/build/tsconfig.build.tsbuildinfo +1 -1
  85. package/build/utxo/OPNetLimitedProvider.d.ts +1 -1
  86. package/build/utxo/OPNetLimitedProvider.js +1 -1
  87. package/build/utxo/interfaces/IUTXO.d.ts +2 -2
  88. package/build/verification/TapscriptVerificator.d.ts +2 -2
  89. package/package.json +6 -3
  90. package/src/_version.ts +1 -1
  91. package/src/consensus/ConsensusConfig.ts +1 -28
  92. package/src/consensus/IConsensusConfig.ts +29 -0
  93. package/src/consensus/metadata/RoswellConsensus.ts +1 -1
  94. package/src/epoch/interfaces/IChallengeSolution.ts +13 -1
  95. package/src/epoch/validator/EpochValidator.ts +54 -3
  96. package/src/generators/builders/CalldataGenerator.ts +3 -3
  97. package/src/generators/builders/DeploymentGenerator.ts +3 -3
  98. package/src/generators/builders/P2WDAGenerator.ts +2 -2
  99. package/src/keypair/MessageSigner.ts +1 -1
  100. package/src/opnet.ts +10 -5
  101. package/src/signer/AddressRotation.ts +3 -4
  102. package/src/signer/IRotationSigner.ts +35 -0
  103. package/src/transaction/TransactionFactory.ts +14 -38
  104. package/src/transaction/browser/WalletNetworks.ts +15 -0
  105. package/src/transaction/browser/Web3Provider.ts +14 -78
  106. package/src/transaction/browser/extensions/UnisatSigner.ts +7 -5
  107. package/src/transaction/browser/types/Unisat.ts +5 -20
  108. package/src/transaction/builders/CancelTransaction.ts +2 -11
  109. package/src/transaction/builders/ConsolidatedInteractionTransaction.ts +3 -3
  110. package/src/transaction/builders/CustomScriptTransaction.ts +1 -15
  111. package/src/transaction/builders/DeploymentTransaction.ts +3 -3
  112. package/src/transaction/builders/InteractionTransactionP2WDA.ts +3 -3
  113. package/src/transaction/builders/SharedInteractionTransaction.ts +3 -3
  114. package/src/transaction/builders/TransactionBuilder.ts +2 -28
  115. package/src/transaction/interfaces/ICancelTransactionParameters.ts +8 -0
  116. package/src/transaction/interfaces/ICustomTransactionParameters.ts +15 -0
  117. package/src/transaction/interfaces/ITransactionParameters.ts +6 -6
  118. package/src/transaction/interfaces/ITransactionResponses.ts +29 -0
  119. package/src/transaction/interfaces/ITweakedTransactionData.ts +24 -0
  120. package/src/transaction/interfaces/IWeb3ProviderTypes.ts +74 -0
  121. package/src/transaction/offline/TransactionReconstructor.ts +1 -1
  122. package/src/transaction/shared/TweakedTransaction.ts +6 -30
  123. package/src/transaction/utils/WitnessUtils.ts +36 -0
  124. package/src/utxo/OPNetLimitedProvider.ts +3 -1
  125. package/src/utxo/interfaces/IUTXO.ts +2 -2
  126. package/src/verification/TapscriptVerificator.ts +2 -2
  127. package/browser/metadata/tokens.d.ts +0 -39
  128. package/browser/transaction/processor/PsbtTransaction.d.ts +0 -25
  129. package/build/metadata/tokens.d.ts +0 -39
  130. package/build/metadata/tokens.js +0 -100
  131. package/build/transaction/processor/PsbtTransaction.d.ts +0 -25
  132. package/build/transaction/processor/PsbtTransaction.js +0 -80
  133. package/src/metadata/tokens.ts +0 -139
  134. package/src/transaction/processor/PsbtTransaction.ts +0 -179
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@btc-vision/transaction",
3
3
  "type": "module",
4
- "version": "1.7.28",
4
+ "version": "1.7.30",
5
5
  "author": "BlobMaster41",
6
6
  "description": "OPNet transaction library allows you to create and sign transactions for the OPNet network.",
7
7
  "engines": {
@@ -143,7 +143,9 @@
143
143
  "test": "npm run build && vitest run",
144
144
  "test:watch": "npm run build && vitest",
145
145
  "test:ui": "npm run build && vitest --ui",
146
- "test:coverage": "npm run build && vitest run --coverage"
146
+ "test:coverage": "npm run build && vitest run --coverage",
147
+ "check:circular": "madge --circular --extensions ts,tsx src/",
148
+ "prebuild": "npm run check:circular"
147
149
  },
148
150
  "devDependencies": {
149
151
  "@babel/core": "^7.28.5",
@@ -160,6 +162,7 @@
160
162
  "@vitest/ui": "^4.0.8",
161
163
  "eslint": "^9.39.1",
162
164
  "https-browserify": "^1.0.0",
165
+ "madge": "^8.0.0",
163
166
  "os-browserify": "^0.3.0",
164
167
  "prettier": "^3.6.2",
165
168
  "stream-browserify": "^3.0.0",
@@ -176,7 +179,7 @@
176
179
  "@babel/plugin-proposal-object-rest-spread": "^7.20.7",
177
180
  "@bitcoinerlab/secp256k1": "^1.2.0",
178
181
  "@btc-vision/bip32": "^6.0.3",
179
- "@btc-vision/bitcoin": "^6.5.3",
182
+ "@btc-vision/bitcoin": "^6.5.4",
180
183
  "@btc-vision/bitcoin-rpc": "^1.0.6",
181
184
  "@btc-vision/logger": "^1.0.8",
182
185
  "@btc-vision/post-quantum": "^0.5.3",
package/src/_version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.7.28';
1
+ export const version = '1.7.30';
@@ -1,34 +1,7 @@
1
1
  import { Consensus } from './Consensus.js';
2
+ import { ConsensusConfig } from './IConsensusConfig.js';
2
3
  import { RoswellConsensus } from './metadata/RoswellConsensus.js';
3
4
 
4
- export interface ConsensusConfig<T extends Consensus> {
5
- // The consensus type.
6
- readonly CONSENSUS: T;
7
-
8
- // The consensus name.
9
- readonly CONSENSUS_NAME: string;
10
-
11
- // The block height at which this consensus was enabled.
12
- readonly ENABLED_AT_BLOCK: bigint;
13
-
14
- /** WBTC vaults */
15
- // Defines the minimum amount that can be consolidated in a single transaction.
16
- //readonly VAULT_MINIMUM_AMOUNT: bigint;
17
-
18
- // Defines the requested minimum acceptance for joining UTXOs when an unwrap is being done.
19
- // If the consolidate output going back to the vault is lower than this amount, the transaction will be rejected.
20
- // User must pay for the consolidation, this help the network by having fewer UTXOs.
21
- //readonly VAULT_NETWORK_CONSOLIDATION_ACCEPTANCE: bigint;
22
-
23
- // Everytime an user wrap bitcoin, he prepays the fees for the consolidation at a maximum fee rate of the following determined value.
24
- // If the fees are lower, the user will be refunded the difference.
25
- // If the fees are higher, the user must pay the difference.
26
- //readonly UNWRAP_CONSOLIDATION_PREPAID_FEES: bigint;
27
-
28
- // The maximum fee rate for the consolidation.
29
- //readonly UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT: bigint;
30
- }
31
-
32
5
  export const OPNetConsensusConfig: { [key in Consensus]?: ConsensusConfig<key> } = {
33
6
  [Consensus.Roswell]: RoswellConsensus,
34
7
  };
@@ -0,0 +1,29 @@
1
+ import { Consensus } from './Consensus.js';
2
+
3
+ export interface ConsensusConfig<T extends Consensus> {
4
+ // The consensus type.
5
+ readonly CONSENSUS: T;
6
+
7
+ // The consensus name.
8
+ readonly CONSENSUS_NAME: string;
9
+
10
+ // The block height at which this consensus was enabled.
11
+ readonly ENABLED_AT_BLOCK: bigint;
12
+
13
+ /** WBTC vaults */
14
+ // Defines the minimum amount that can be consolidated in a single transaction.
15
+ //readonly VAULT_MINIMUM_AMOUNT: bigint;
16
+
17
+ // Defines the requested minimum acceptance for joining UTXOs when an unwrap is being done.
18
+ // If the consolidate output going back to the vault is lower than this amount, the transaction will be rejected.
19
+ // User must pay for the consolidation, this help the network by having fewer UTXOs.
20
+ //readonly VAULT_NETWORK_CONSOLIDATION_ACCEPTANCE: bigint;
21
+
22
+ // Everytime an user wrap bitcoin, he prepays the fees for the consolidation at a maximum fee rate of the following determined value.
23
+ // If the fees are lower, the user will be refunded the difference.
24
+ // If the fees are higher, the user must pay the difference.
25
+ //readonly UNWRAP_CONSOLIDATION_PREPAID_FEES: bigint;
26
+
27
+ // The maximum fee rate for the consolidation.
28
+ //readonly UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT: bigint;
29
+ }
@@ -1,4 +1,4 @@
1
- import { ConsensusConfig } from '../ConsensusConfig.js';
1
+ import { ConsensusConfig } from '../IConsensusConfig.js';
2
2
  import { Consensus } from '../Consensus.js';
3
3
 
4
4
  export const RoswellConsensus: ConsensusConfig<Consensus.Roswell> = {
@@ -18,6 +18,16 @@ export interface IChallengeSolution {
18
18
  readonly graffiti: Buffer;
19
19
  readonly difficulty: number;
20
20
  readonly verification: IChallengeVerification;
21
+
22
+ verifySubmissionSignature(): boolean;
23
+ getSubmission(): IChallengeSubmission | undefined;
24
+ toRaw(): RawChallenge;
25
+ verify(): boolean;
26
+ toBuffer(): Buffer;
27
+ toHex(): string;
28
+ calculateSolution(): Buffer;
29
+ checkDifficulty(minDifficulty: number): { valid: boolean; difficulty: number };
30
+ getMiningTargetBlock(): bigint | null;
21
31
  }
22
32
 
23
33
  export interface RawChallengeVerification {
@@ -41,8 +51,10 @@ export interface RawChallengeSubmission {
41
51
  export interface IChallengeSubmission {
42
52
  readonly publicKey: Address;
43
53
  readonly solution: Buffer;
44
- readonly graffiti?: Buffer;
54
+ readonly graffiti: Buffer | undefined;
45
55
  readonly signature: Buffer;
56
+ readonly epochNumber: bigint;
57
+ verifySignature(): boolean;
46
58
  }
47
59
 
48
60
  export interface RawChallenge {
@@ -1,6 +1,7 @@
1
1
  import { IChallengeSolution, RawChallenge } from '../interfaces/IChallengeSolution.js';
2
- import { ChallengeSolution } from '../ChallengeSolution.js';
3
2
  import { crypto } from '@btc-vision/bitcoin';
3
+ import { Address } from '../../keypair/Address.js';
4
+ import { stringToBuffer } from '../../utils/StringToBuffer.js';
4
5
 
5
6
  export class EpochValidator {
6
7
  private static readonly BLOCKS_PER_EPOCH: bigint = 5n;
@@ -131,8 +132,58 @@ export class EpochValidator {
131
132
  * Validate epoch winner from raw data
132
133
  */
133
134
  public static validateEpochWinner(epochData: RawChallenge): boolean {
134
- const preimage = new ChallengeSolution(epochData);
135
- return this.verifySolution(preimage);
135
+ try {
136
+ const epochNumber = BigInt(epochData.epochNumber);
137
+ const publicKey = Address.fromString(
138
+ epochData.mldsaPublicKey,
139
+ epochData.legacyPublicKey,
140
+ );
141
+ const solution = stringToBuffer(epochData.solution);
142
+ const salt = stringToBuffer(epochData.salt);
143
+ const difficulty = epochData.difficulty;
144
+
145
+ const verification = {
146
+ epochHash: stringToBuffer(epochData.verification.epochHash),
147
+ epochRoot: stringToBuffer(epochData.verification.epochRoot),
148
+ targetHash: stringToBuffer(epochData.verification.targetHash),
149
+ targetChecksum: stringToBuffer(epochData.verification.targetChecksum),
150
+ startBlock: BigInt(epochData.verification.startBlock),
151
+ endBlock: BigInt(epochData.verification.endBlock),
152
+ proofs: Object.freeze(epochData.verification.proofs.map((p) => stringToBuffer(p))),
153
+ };
154
+
155
+ const calculatedPreimage = this.calculatePreimage(
156
+ verification.targetChecksum,
157
+ publicKey.toBuffer(),
158
+ salt,
159
+ );
160
+
161
+ const computedSolution = this.sha1(calculatedPreimage);
162
+ const computedSolutionBuffer = this.uint8ArrayToBuffer(computedSolution);
163
+
164
+ if (!computedSolutionBuffer.equals(solution)) {
165
+ return false;
166
+ }
167
+
168
+ const matchingBits = this.countMatchingBits(
169
+ computedSolutionBuffer,
170
+ verification.targetHash,
171
+ );
172
+
173
+ if (matchingBits !== difficulty) {
174
+ return false;
175
+ }
176
+
177
+ const expectedStartBlock = epochNumber * this.BLOCKS_PER_EPOCH;
178
+ const expectedEndBlock = expectedStartBlock + this.BLOCKS_PER_EPOCH - 1n;
179
+
180
+ return !(
181
+ verification.startBlock !== expectedStartBlock ||
182
+ verification.endBlock !== expectedEndBlock
183
+ );
184
+ } catch {
185
+ return false;
186
+ }
136
187
  }
137
188
 
138
189
  /**
@@ -4,7 +4,7 @@ import { Compressor } from '../../bytecode/Compressor.js';
4
4
  import { EcKeyPair } from '../../keypair/EcKeyPair.js';
5
5
  import { Feature, Features } from '../Features.js';
6
6
  import { Generator } from '../Generator.js';
7
- import { ChallengeSolution } from '../../epoch/ChallengeSolution.js';
7
+ import { IChallengeSolution } from '../../epoch/interfaces/IChallengeSolution.js';
8
8
  import { BinaryWriter } from '../../buffer/BinaryWriter.js';
9
9
 
10
10
  /**
@@ -58,7 +58,7 @@ export class CalldataGenerator extends Generator {
58
58
  * Compile an interaction bitcoin script
59
59
  * @param {Buffer} calldata - The calldata to use
60
60
  * @param {Buffer} contractSecret - The contract secret
61
- * @param {ChallengeSolution} challenge
61
+ * @param {IChallengeSolution} challenge
62
62
  * @param maxPriority - Amount of satoshis to spend max on priority fee
63
63
  * @param {Feature<Features>[]} featuresRaw - The features to use
64
64
  * @returns {Buffer} - The compiled script
@@ -67,7 +67,7 @@ export class CalldataGenerator extends Generator {
67
67
  public compile(
68
68
  calldata: Buffer,
69
69
  contractSecret: Buffer,
70
- challenge: ChallengeSolution,
70
+ challenge: IChallengeSolution,
71
71
  maxPriority: bigint,
72
72
  featuresRaw: Feature<Features>[] = [],
73
73
  ): Buffer {
@@ -1,7 +1,7 @@
1
1
  import { crypto, Network, networks, opcodes, script } from '@btc-vision/bitcoin';
2
2
  import { Generator } from '../Generator.js';
3
3
  import { Feature, Features } from '../Features.js';
4
- import { ChallengeSolution } from '../../epoch/ChallengeSolution.js';
4
+ import { IChallengeSolution } from '../../epoch/interfaces/IChallengeSolution.js';
5
5
  import { BinaryWriter } from '../../buffer/BinaryWriter.js';
6
6
 
7
7
  export const OPNET_DEPLOYMENT_VERSION = 0x00;
@@ -29,7 +29,7 @@ export class DeploymentGenerator extends Generator {
29
29
  public compile(
30
30
  contractBytecode: Buffer,
31
31
  contractSalt: Buffer,
32
- challenge: ChallengeSolution,
32
+ challenge: IChallengeSolution,
33
33
  maxPriority: bigint,
34
34
  calldata?: Buffer,
35
35
  features?: Feature<Features>[],
@@ -59,7 +59,7 @@ export class DeploymentGenerator extends Generator {
59
59
  private getAsm(
60
60
  contractBytecode: Buffer,
61
61
  contractSalt: Buffer,
62
- challenge: ChallengeSolution,
62
+ challenge: IChallengeSolution,
63
63
  maxPriority: bigint,
64
64
  calldata?: Buffer,
65
65
  featuresRaw?: Feature<Features>[],
@@ -2,7 +2,7 @@ import { Network, networks } from '@btc-vision/bitcoin';
2
2
  import { BinaryWriter } from '../../buffer/BinaryWriter.js';
3
3
  import { Feature, Features } from '../Features.js';
4
4
  import { Generator } from '../Generator.js';
5
- import { ChallengeSolution } from '../../epoch/ChallengeSolution.js';
5
+ import { IChallengeSolution } from '../../epoch/interfaces/IChallengeSolution.js';
6
6
 
7
7
  /**
8
8
  * @category Generators
@@ -62,7 +62,7 @@ export class P2WDAGenerator extends Generator {
62
62
  public compile(
63
63
  calldata: Buffer,
64
64
  contractSecret: Buffer,
65
- challenge: ChallengeSolution,
65
+ challenge: IChallengeSolution,
66
66
  maxPriority: bigint,
67
67
  featuresRaw: Feature<Features>[] = [],
68
68
  ): Buffer {
@@ -5,7 +5,7 @@ import { TweakedSigner } from '../signer/TweakedSigner.js';
5
5
  import { EcKeyPair } from './EcKeyPair.js';
6
6
  import { MLDSASecurityLevel, QuantumBIP32Interface } from '@btc-vision/bip32';
7
7
  import { isOPWallet, OPWallet } from '../transaction/browser/types/OPWallet.js';
8
- import { MLDSASignature } from '../transaction/browser/Web3Provider.js';
8
+ import { MLDSASignature } from '../transaction/interfaces/IWeb3ProviderTypes.js';
9
9
 
10
10
  export interface SignedMessage {
11
11
  readonly signature: Uint8Array;
package/src/opnet.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Unisat } from './transaction/browser/types/Unisat.js';
2
+ import { OPWallet } from './transaction/browser/types/OPWallet.js';
2
3
 
3
4
  export { version } from './_version.js';
4
5
 
@@ -55,12 +56,18 @@ export * from './network/ChainId.js';
55
56
 
56
57
  /** Signer */
57
58
  export * from './signer/TweakedSigner.js';
59
+ export * from './signer/IRotationSigner.js';
58
60
  export * from './signer/AddressRotation.js';
59
61
 
60
62
  /** Transaction */
61
63
  export * from './transaction/enums/TransactionType.js';
62
64
  export * from './transaction/interfaces/ITransactionParameters.js';
63
65
  export * from './transaction/interfaces/IConsolidatedTransactionParameters.js';
66
+ export * from './transaction/interfaces/ITransactionResponses.js';
67
+ export * from './transaction/interfaces/IWeb3ProviderTypes.js';
68
+ export * from './transaction/interfaces/ICancelTransactionParameters.js';
69
+ export * from './transaction/interfaces/ICustomTransactionParameters.js';
70
+ export * from './transaction/interfaces/ITweakedTransactionData.js';
64
71
  export * from './transaction/interfaces/Tap.js';
65
72
  export * from './transaction/TransactionFactory.js';
66
73
 
@@ -100,9 +107,6 @@ export * from './utils/lengths.js';
100
107
  export * from './utxo/interfaces/IUTXO.js';
101
108
  export * from './utxo/OPNetLimitedProvider.js';
102
109
 
103
- /** Processor */
104
- export * from './transaction/processor/PsbtTransaction.js';
105
-
106
110
  /** Shared */
107
111
  export * from './transaction/psbt/PSBTTypes.js';
108
112
  export * from './transaction/shared/TweakedTransaction.js';
@@ -112,6 +116,7 @@ export * from './transaction/shared/P2TR_MS.js';
112
116
 
113
117
  /** Consensus */
114
118
  export * from './consensus/Consensus.js';
119
+ export * from './consensus/IConsensusConfig.js';
115
120
  export * from './consensus/ConsensusConfig.js';
116
121
  export * from './consensus/metadata/RoswellConsensus.js';
117
122
 
@@ -135,8 +140,8 @@ export * from './transaction/browser/extensions/XverseSigner.js';
135
140
  export * from './transaction/browser/types/Unisat.js';
136
141
  export * from './transaction/browser/types/Xverse.js';
137
142
  export * from './transaction/browser/types/OPWallet.js';
143
+ export * from './transaction/browser/WalletNetworks.js';
138
144
 
139
- export * from './metadata/tokens.js';
140
145
  export * from './transaction/browser/Web3Provider.js';
141
146
 
142
147
  export * from './keypair/Secp256k1PointDeriver.js';
@@ -148,6 +153,6 @@ export * from './deterministic/CustomMap.js';
148
153
  declare global {
149
154
  interface Window {
150
155
  unisat?: Unisat;
151
- opnet?: Unisat;
156
+ opnet?: OPWallet;
152
157
  }
153
158
  }
@@ -1,11 +1,10 @@
1
- import { Signer } from '@btc-vision/bitcoin';
2
- import { ECPairInterface } from 'ecpair';
1
+ import { RotationSignerBase } from './IRotationSigner.js';
3
2
  import { UnisatSigner } from '../transaction/browser/extensions/UnisatSigner.js';
4
3
 
5
4
  /**
6
- * Supported signer types for address rotation
5
+ * Supported signer types for address rotation (includes browser signers)
7
6
  */
8
- export type RotationSigner = Signer | ECPairInterface | UnisatSigner;
7
+ export type RotationSigner = RotationSignerBase | UnisatSigner;
9
8
 
10
9
  /**
11
10
  * Map of addresses to their respective signers for address rotation mode.
@@ -0,0 +1,35 @@
1
+ import { Signer } from '@btc-vision/bitcoin';
2
+ import { ECPairInterface } from 'ecpair';
3
+
4
+ /**
5
+ * Base signer type for address rotation.
6
+ * This is the minimal interface required for UTXO signing.
7
+ * UnisatSigner extends this through the CustomKeypair base class.
8
+ */
9
+ export type RotationSignerBase = Signer | ECPairInterface;
10
+
11
+ /**
12
+ * Map of addresses to their respective signers for address rotation mode.
13
+ * Each UTXO address can have its own dedicated signer.
14
+ */
15
+ export type SignerMapBase = Map<string, RotationSignerBase>;
16
+
17
+ /**
18
+ * Configuration for address rotation mode (base version without browser signers).
19
+ * When enabled, each UTXO can be signed by a different signer based on its address.
20
+ */
21
+ export interface AddressRotationConfigBase {
22
+ /**
23
+ * Whether address rotation mode is enabled.
24
+ * When true, the signerMap will be used to find the appropriate signer for each UTXO.
25
+ * When false, the default single signer will be used for all inputs.
26
+ */
27
+ readonly enabled: boolean;
28
+
29
+ /**
30
+ * Map of addresses to their respective signers.
31
+ * The key is the address (from UTXO.scriptPubKey.address).
32
+ * The value is the signer that controls that address.
33
+ */
34
+ readonly signerMap: SignerMapBase;
35
+ }
@@ -1,10 +1,7 @@
1
1
  import { Transaction, TxOutput } from '@btc-vision/bitcoin';
2
2
  import { currentConsensus } from '../consensus/ConsensusConfig.js';
3
3
  import { UTXO } from '../utxo/interfaces/IUTXO.js';
4
- import {
5
- CustomScriptTransaction,
6
- ICustomTransactionParameters,
7
- } from './builders/CustomScriptTransaction.js';
4
+ import { CustomScriptTransaction } from './builders/CustomScriptTransaction.js';
8
5
  import { DeploymentTransaction } from './builders/DeploymentTransaction.js';
9
6
  import { FundingTransaction } from './builders/FundingTransaction.js';
10
7
  import { InteractionTransaction } from './builders/InteractionTransaction.js';
@@ -22,26 +19,23 @@ import {
22
19
  ICustomTransactionWithoutSigner,
23
20
  IDeploymentParametersWithoutSigner,
24
21
  InteractionParametersWithoutSigner,
25
- } from './browser/Web3Provider.js';
22
+ } from './interfaces/IWeb3ProviderTypes.js';
26
23
  import { WindowWithWallets } from './browser/extensions/UnisatSigner.js';
27
- import { RawChallenge } from '../epoch/interfaces/IChallengeSolution.js';
24
+ import { IChallengeSolution, RawChallenge } from '../epoch/interfaces/IChallengeSolution.js';
28
25
  import { P2WDADetector } from '../p2wda/P2WDADetector.js';
29
26
  import { InteractionTransactionP2WDA } from './builders/InteractionTransactionP2WDA.js';
30
- import { ChallengeSolution } from '../epoch/ChallengeSolution.js';
31
27
  import { Address } from '../keypair/Address.js';
32
28
  import { BitcoinUtils } from '../utils/BitcoinUtils.js';
33
- import { CancelTransaction, ICancelTransactionParameters } from './builders/CancelTransaction.js';
29
+ import { CancelTransaction } from './builders/CancelTransaction.js';
34
30
  import { ConsolidatedInteractionTransaction } from './builders/ConsolidatedInteractionTransaction.js';
35
31
  import { IConsolidatedInteractionParameters } from './interfaces/IConsolidatedTransactionParameters.js';
36
-
37
- export interface DeploymentResult {
38
- readonly transaction: [string, string];
39
- readonly contractAddress: string;
40
- readonly contractPubKey: string;
41
- readonly challenge: RawChallenge;
42
- readonly utxos: UTXO[];
43
- readonly inputUtxos: UTXO[];
44
- }
32
+ import {
33
+ CancelledTransaction,
34
+ DeploymentResult,
35
+ InteractionResponse,
36
+ } from './interfaces/ITransactionResponses.js';
37
+ import { ICancelTransactionParameters } from './interfaces/ICancelTransactionParameters.js';
38
+ import { ICustomTransactionParameters } from './interfaces/ICustomTransactionParameters.js';
45
39
 
46
40
  export interface FundingTransactionResponse {
47
41
  readonly tx: Transaction;
@@ -58,28 +52,10 @@ export interface BitcoinTransferBase {
58
52
  readonly inputUtxos: UTXO[];
59
53
  }
60
54
 
61
- export interface InteractionResponse {
62
- readonly fundingTransaction: string | null;
63
- readonly interactionTransaction: string;
64
- readonly estimatedFees: bigint;
65
- readonly nextUTXOs: UTXO[];
66
- readonly fundingUTXOs: UTXO[];
67
- readonly fundingInputUtxos: UTXO[];
68
- readonly challenge: RawChallenge;
69
- readonly interactionAddress: string | null;
70
- readonly compiledTargetScript: string | null;
71
- }
72
-
73
55
  export interface BitcoinTransferResponse extends BitcoinTransferBase {
74
56
  readonly original: FundingTransaction;
75
57
  }
76
58
 
77
- export interface CancelledTransaction {
78
- readonly transaction: string;
79
- readonly nextUTXOs: UTXO[];
80
- readonly inputUtxos: UTXO[];
81
- }
82
-
83
59
  /**
84
60
  * Response from signConsolidatedInteraction.
85
61
  * Contains both setup and reveal transactions for the CHCT system.
@@ -835,7 +811,7 @@ export class TransactionFactory {
835
811
  * @param {new (params: P) => T} TransactionClass - The transaction class constructor
836
812
  * @param {(tx: T) => Promise<bigint>} calculateAmount - Function to calculate required amount
837
813
  * @param {string} debugPrefix - Prefix for debug logging
838
- * @returns {Promise<{finalTransaction: T, estimatedAmount: bigint, challenge: ChallengeSolution | null}>} - The final transaction and estimated amount
814
+ * @returns {Promise<{finalTransaction: T, estimatedAmount: bigint, challenge: IChallengeSolution | null}>} - The final transaction and estimated amount
839
815
  */
840
816
  private async iterateFundingAmount<
841
817
  T extends InteractionTransaction | DeploymentTransaction | CustomScriptTransaction,
@@ -848,7 +824,7 @@ export class TransactionFactory {
848
824
  ): Promise<{
849
825
  finalTransaction: T;
850
826
  estimatedAmount: bigint;
851
- challenge: ChallengeSolution | null;
827
+ challenge: IChallengeSolution | null;
852
828
  }> {
853
829
  const randomBytes =
854
830
  'randomBytes' in params
@@ -861,7 +837,7 @@ export class TransactionFactory {
861
837
  let previousAmount = 0n;
862
838
  let iterations = 0;
863
839
  let finalPreTransaction: T | null = null;
864
- let challenge: ChallengeSolution | null = null;
840
+ let challenge: IChallengeSolution | null = null;
865
841
 
866
842
  while (iterations < this.MAX_ITERATIONS && estimatedFundingAmount !== previousAmount) {
867
843
  previousAmount = estimatedFundingAmount;
@@ -0,0 +1,15 @@
1
+ export enum WalletNetworks {
2
+ testnet = 'testnet',
3
+ mainnet = 'mainnet',
4
+ regtest = 'regtest',
5
+ }
6
+
7
+ export enum UnisatChainType {
8
+ BITCOIN_MAINNET = 'BITCOIN_MAINNET',
9
+ BITCOIN_TESTNET = 'BITCOIN_TESTNET',
10
+ BITCOIN_TESTNET4 = 'BITCOIN_TESTNET4',
11
+ BITCOIN_REGTEST = 'BITCOIN_REGTEST',
12
+ BITCOIN_SIGNET = 'BITCOIN_SIGNET',
13
+ FRACTAL_BITCOIN_MAINNET = 'FRACTAL_BITCOIN_MAINNET',
14
+ FRACTAL_BITCOIN_TESTNET = 'FRACTAL_BITCOIN_TESTNET',
15
+ }
@@ -1,82 +1,18 @@
1
- import {
2
- IDeploymentParameters,
3
- IInteractionParameters,
4
- } from '../interfaces/ITransactionParameters.js';
5
1
  import { UTXO } from '../../utxo/interfaces/IUTXO.js';
6
- import { CancelledTransaction, DeploymentResult, InteractionResponse } from '../TransactionFactory';
7
- import { ICustomTransactionParameters } from '../builders/CustomScriptTransaction.js';
8
- import { ICancelTransactionParameters } from '../builders/CancelTransaction.js';
9
- import { MLDSASecurityLevel } from '@btc-vision/bip32';
10
-
11
- export type InteractionParametersWithoutSigner = Omit<
12
- IInteractionParameters,
13
- 'signer' | 'challenge' | 'mldsaSigner'
14
- >;
15
-
16
- export type IDeploymentParametersWithoutSigner = Omit<
17
- IDeploymentParameters,
18
- 'signer' | 'network' | 'challenge' | 'mldsaSigner'
19
- >;
20
-
21
- export type ICustomTransactionWithoutSigner = Omit<
22
- ICustomTransactionParameters,
23
- 'signer' | 'challenge' | 'mldsaSigner'
24
- >;
25
-
26
- export type ICancelTransactionParametersWithoutSigner = Omit<
27
- ICancelTransactionParameters,
28
- 'signer' | 'challenge' | 'network' | 'mldsaSigner'
29
- >;
30
-
31
- export interface BroadcastTransactionOptions {
32
- raw: string;
33
- psbt: boolean;
34
- }
35
-
36
- export interface BroadcastedTransaction {
37
- /** Whether the transaction was successfully broadcasted. */
38
- readonly success: boolean;
39
-
40
- /**
41
- * The result of the broadcasted transaction.
42
- */
43
- readonly result?: string;
44
-
45
- /**
46
- * The error message if the transaction was not successfully broadcasted.
47
- */
48
- readonly error?: string;
49
-
50
- /**
51
- * The number of peers that the transaction was broadcasted to.
52
- */
53
- readonly peers?: number;
54
- }
55
-
56
- /**
57
- * ML-DSA signature result
58
- */
59
- export interface MLDSASignature {
60
- /**
61
- * The ML-DSA signature in hex format
62
- */
63
- readonly signature: string;
64
-
65
- /**
66
- * The ML-DSA public key used for signing in hex format
67
- */
68
- readonly publicKey: string;
69
-
70
- /**
71
- * The security level used (44, 65, or 87)
72
- */
73
- readonly securityLevel: MLDSASecurityLevel;
74
-
75
- /**
76
- * The message hash that was signed
77
- */
78
- readonly messageHash: string;
79
- }
2
+ import {
3
+ CancelledTransaction,
4
+ DeploymentResult,
5
+ InteractionResponse,
6
+ } from '../interfaces/ITransactionResponses.js';
7
+ import {
8
+ BroadcastedTransaction,
9
+ BroadcastTransactionOptions,
10
+ ICancelTransactionParametersWithoutSigner,
11
+ ICustomTransactionWithoutSigner,
12
+ IDeploymentParametersWithoutSigner,
13
+ InteractionParametersWithoutSigner,
14
+ MLDSASignature,
15
+ } from '../interfaces/IWeb3ProviderTypes.js';
80
16
 
81
17
  export interface Web3Provider {
82
18
  signInteraction(
@@ -12,11 +12,13 @@ import { ECPairInterface } from 'ecpair';
12
12
  import { EcKeyPair } from '../../../keypair/EcKeyPair.js';
13
13
  import { canSignNonTaprootInput, isTaprootInput } from '../../../signer/SignerUtils.js';
14
14
  import { CustomKeypair } from '../BrowserSignerBase.js';
15
- import { PsbtSignatureOptions, SignatureType, Unisat, UnisatNetwork } from '../types/Unisat.js';
15
+ import { PsbtSignatureOptions, SignatureType, Unisat } from '../types/Unisat.js';
16
+ import { WalletNetworks } from '../WalletNetworks.js';
17
+ import { OPWallet } from '../types/OPWallet.js';
16
18
 
17
19
  export interface WindowWithWallets {
18
20
  unisat?: Unisat;
19
- opnet?: Unisat;
21
+ opnet?: OPWallet;
20
22
  }
21
23
 
22
24
  export class UnisatSigner extends CustomKeypair {
@@ -105,13 +107,13 @@ export class UnisatSigner extends CustomKeypair {
105
107
 
106
108
  const network = await this.unisat.getNetwork();
107
109
  switch (network) {
108
- case UnisatNetwork.mainnet:
110
+ case WalletNetworks.mainnet:
109
111
  this._network = networks.bitcoin;
110
112
  break;
111
- case UnisatNetwork.testnet:
113
+ case WalletNetworks.testnet:
112
114
  this._network = networks.testnet;
113
115
  break;
114
- case UnisatNetwork.regtest:
116
+ case WalletNetworks.regtest:
115
117
  this._network = networks.regtest;
116
118
  break;
117
119
  default: