@btc-vision/transaction 1.7.28 → 1.7.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/btc-vision-bitcoin.js +1610 -1609
- package/browser/consensus/ConsensusConfig.d.ts +1 -5
- package/browser/consensus/IConsensusConfig.d.ts +6 -0
- package/browser/consensus/metadata/RoswellConsensus.d.ts +1 -1
- package/browser/epoch/interfaces/IChallengeSolution.d.ts +15 -1
- package/browser/generators/builders/CalldataGenerator.d.ts +2 -2
- package/browser/generators/builders/DeploymentGenerator.d.ts +2 -2
- package/browser/generators/builders/P2WDAGenerator.d.ts +2 -2
- package/browser/index.js +876 -1055
- package/browser/opnet.d.ts +7 -2
- package/browser/signer/AddressRotation.d.ts +2 -3
- package/browser/signer/IRotationSigner.d.ts +8 -0
- package/browser/transaction/TransactionFactory.d.ts +4 -27
- package/browser/transaction/browser/Web3Provider.d.ts +2 -25
- package/browser/transaction/builders/CancelTransaction.d.ts +1 -4
- package/browser/transaction/builders/ConsolidatedInteractionTransaction.d.ts +3 -3
- package/browser/transaction/builders/CustomScriptTransaction.d.ts +2 -8
- package/browser/transaction/builders/DeploymentTransaction.d.ts +3 -3
- package/browser/transaction/builders/InteractionTransactionP2WDA.d.ts +2 -2
- package/browser/transaction/builders/SharedInteractionTransaction.d.ts +3 -3
- package/browser/transaction/interfaces/ICancelTransactionParameters.d.ts +4 -0
- package/browser/transaction/interfaces/ICustomTransactionParameters.d.ts +8 -0
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +6 -6
- package/browser/transaction/interfaces/ITransactionResponses.d.ts +26 -0
- package/browser/transaction/interfaces/ITweakedTransactionData.d.ts +17 -0
- package/browser/transaction/interfaces/IWeb3ProviderTypes.d.ts +24 -0
- package/browser/transaction/shared/TweakedTransaction.d.ts +2 -14
- package/browser/transaction/utils/WitnessUtils.d.ts +1 -0
- package/browser/utxo/OPNetLimitedProvider.d.ts +1 -1
- package/browser/utxo/interfaces/IUTXO.d.ts +2 -2
- package/browser/vendors.js +90 -90
- package/browser/verification/TapscriptVerificator.d.ts +2 -2
- package/build/consensus/ConsensusConfig.d.ts +1 -5
- package/build/consensus/IConsensusConfig.d.ts +6 -0
- package/build/consensus/IConsensusConfig.js +1 -0
- package/build/consensus/metadata/RoswellConsensus.d.ts +1 -1
- package/build/epoch/interfaces/IChallengeSolution.d.ts +15 -1
- package/build/epoch/validator/EpochValidator.js +35 -3
- package/build/generators/builders/CalldataGenerator.d.ts +2 -2
- package/build/generators/builders/DeploymentGenerator.d.ts +2 -2
- package/build/generators/builders/P2WDAGenerator.d.ts +2 -2
- package/build/opnet.d.ts +7 -2
- package/build/opnet.js +7 -2
- package/build/signer/AddressRotation.d.ts +2 -3
- package/build/signer/IRotationSigner.d.ts +8 -0
- package/build/signer/IRotationSigner.js +1 -0
- package/build/transaction/TransactionFactory.d.ts +4 -27
- package/build/transaction/TransactionFactory.js +1 -1
- package/build/transaction/browser/Web3Provider.d.ts +2 -25
- package/build/transaction/builders/CancelTransaction.d.ts +1 -4
- package/build/transaction/builders/ConsolidatedInteractionTransaction.d.ts +3 -3
- package/build/transaction/builders/CustomScriptTransaction.d.ts +2 -8
- package/build/transaction/builders/DeploymentTransaction.d.ts +3 -3
- package/build/transaction/builders/InteractionTransactionP2WDA.d.ts +2 -2
- package/build/transaction/builders/SharedInteractionTransaction.d.ts +3 -3
- package/build/transaction/builders/TransactionBuilder.js +3 -21
- package/build/transaction/interfaces/ICancelTransactionParameters.d.ts +4 -0
- package/build/transaction/interfaces/ICancelTransactionParameters.js +1 -0
- package/build/transaction/interfaces/ICustomTransactionParameters.d.ts +8 -0
- package/build/transaction/interfaces/ICustomTransactionParameters.js +1 -0
- package/build/transaction/interfaces/ITransactionParameters.d.ts +6 -6
- package/build/transaction/interfaces/ITransactionResponses.d.ts +26 -0
- package/build/transaction/interfaces/ITransactionResponses.js +1 -0
- package/build/transaction/interfaces/ITweakedTransactionData.d.ts +17 -0
- package/build/transaction/interfaces/ITweakedTransactionData.js +1 -0
- package/build/transaction/interfaces/IWeb3ProviderTypes.d.ts +24 -0
- package/build/transaction/interfaces/IWeb3ProviderTypes.js +1 -0
- package/build/transaction/shared/TweakedTransaction.d.ts +2 -14
- package/build/transaction/shared/TweakedTransaction.js +3 -3
- package/build/transaction/utils/WitnessUtils.d.ts +1 -0
- package/build/transaction/utils/WitnessUtils.js +23 -0
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/build/utxo/OPNetLimitedProvider.d.ts +1 -1
- package/build/utxo/OPNetLimitedProvider.js +1 -1
- package/build/utxo/interfaces/IUTXO.d.ts +2 -2
- package/build/verification/TapscriptVerificator.d.ts +2 -2
- package/package.json +6 -3
- package/src/consensus/ConsensusConfig.ts +1 -28
- package/src/consensus/IConsensusConfig.ts +29 -0
- package/src/consensus/metadata/RoswellConsensus.ts +1 -1
- package/src/epoch/interfaces/IChallengeSolution.ts +13 -1
- package/src/epoch/validator/EpochValidator.ts +54 -3
- package/src/generators/builders/CalldataGenerator.ts +3 -3
- package/src/generators/builders/DeploymentGenerator.ts +3 -3
- package/src/generators/builders/P2WDAGenerator.ts +2 -2
- package/src/keypair/MessageSigner.ts +1 -1
- package/src/opnet.ts +7 -4
- package/src/signer/AddressRotation.ts +3 -4
- package/src/signer/IRotationSigner.ts +35 -0
- package/src/transaction/TransactionFactory.ts +14 -38
- package/src/transaction/browser/Web3Provider.ts +14 -78
- package/src/transaction/builders/CancelTransaction.ts +2 -11
- package/src/transaction/builders/ConsolidatedInteractionTransaction.ts +3 -3
- package/src/transaction/builders/CustomScriptTransaction.ts +1 -15
- package/src/transaction/builders/DeploymentTransaction.ts +3 -3
- package/src/transaction/builders/InteractionTransactionP2WDA.ts +3 -3
- package/src/transaction/builders/SharedInteractionTransaction.ts +3 -3
- package/src/transaction/builders/TransactionBuilder.ts +2 -28
- package/src/transaction/interfaces/ICancelTransactionParameters.ts +8 -0
- package/src/transaction/interfaces/ICustomTransactionParameters.ts +15 -0
- package/src/transaction/interfaces/ITransactionParameters.ts +6 -6
- package/src/transaction/interfaces/ITransactionResponses.ts +29 -0
- package/src/transaction/interfaces/ITweakedTransactionData.ts +24 -0
- package/src/transaction/interfaces/IWeb3ProviderTypes.ts +74 -0
- package/src/transaction/offline/TransactionReconstructor.ts +1 -1
- package/src/transaction/shared/TweakedTransaction.ts +6 -30
- package/src/transaction/utils/WitnessUtils.ts +36 -0
- package/src/utxo/OPNetLimitedProvider.ts +3 -1
- package/src/utxo/interfaces/IUTXO.ts +2 -2
- package/src/verification/TapscriptVerificator.ts +2 -2
- package/browser/metadata/tokens.d.ts +0 -39
- package/browser/transaction/processor/PsbtTransaction.d.ts +0 -25
- package/build/metadata/tokens.d.ts +0 -39
- package/build/metadata/tokens.js +0 -100
- package/build/transaction/processor/PsbtTransaction.d.ts +0 -25
- package/build/transaction/processor/PsbtTransaction.js +0 -80
- package/src/metadata/tokens.ts +0 -139
- 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.
|
|
4
|
+
"version": "1.7.29",
|
|
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.
|
|
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",
|
|
@@ -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
|
+
}
|
|
@@ -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
|
|
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
|
-
|
|
135
|
-
|
|
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 {
|
|
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 {
|
|
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:
|
|
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 {
|
|
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:
|
|
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:
|
|
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 {
|
|
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:
|
|
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/
|
|
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
|
@@ -55,12 +55,18 @@ export * from './network/ChainId.js';
|
|
|
55
55
|
|
|
56
56
|
/** Signer */
|
|
57
57
|
export * from './signer/TweakedSigner.js';
|
|
58
|
+
export * from './signer/IRotationSigner.js';
|
|
58
59
|
export * from './signer/AddressRotation.js';
|
|
59
60
|
|
|
60
61
|
/** Transaction */
|
|
61
62
|
export * from './transaction/enums/TransactionType.js';
|
|
62
63
|
export * from './transaction/interfaces/ITransactionParameters.js';
|
|
63
64
|
export * from './transaction/interfaces/IConsolidatedTransactionParameters.js';
|
|
65
|
+
export * from './transaction/interfaces/ITransactionResponses.js';
|
|
66
|
+
export * from './transaction/interfaces/IWeb3ProviderTypes.js';
|
|
67
|
+
export * from './transaction/interfaces/ICancelTransactionParameters.js';
|
|
68
|
+
export * from './transaction/interfaces/ICustomTransactionParameters.js';
|
|
69
|
+
export * from './transaction/interfaces/ITweakedTransactionData.js';
|
|
64
70
|
export * from './transaction/interfaces/Tap.js';
|
|
65
71
|
export * from './transaction/TransactionFactory.js';
|
|
66
72
|
|
|
@@ -100,9 +106,6 @@ export * from './utils/lengths.js';
|
|
|
100
106
|
export * from './utxo/interfaces/IUTXO.js';
|
|
101
107
|
export * from './utxo/OPNetLimitedProvider.js';
|
|
102
108
|
|
|
103
|
-
/** Processor */
|
|
104
|
-
export * from './transaction/processor/PsbtTransaction.js';
|
|
105
|
-
|
|
106
109
|
/** Shared */
|
|
107
110
|
export * from './transaction/psbt/PSBTTypes.js';
|
|
108
111
|
export * from './transaction/shared/TweakedTransaction.js';
|
|
@@ -112,6 +115,7 @@ export * from './transaction/shared/P2TR_MS.js';
|
|
|
112
115
|
|
|
113
116
|
/** Consensus */
|
|
114
117
|
export * from './consensus/Consensus.js';
|
|
118
|
+
export * from './consensus/IConsensusConfig.js';
|
|
115
119
|
export * from './consensus/ConsensusConfig.js';
|
|
116
120
|
export * from './consensus/metadata/RoswellConsensus.js';
|
|
117
121
|
|
|
@@ -136,7 +140,6 @@ export * from './transaction/browser/types/Unisat.js';
|
|
|
136
140
|
export * from './transaction/browser/types/Xverse.js';
|
|
137
141
|
export * from './transaction/browser/types/OPWallet.js';
|
|
138
142
|
|
|
139
|
-
export * from './metadata/tokens.js';
|
|
140
143
|
export * from './transaction/browser/Web3Provider.js';
|
|
141
144
|
|
|
142
145
|
export * from './keypair/Secp256k1PointDeriver.js';
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
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 =
|
|
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 './
|
|
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
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
840
|
+
let challenge: IChallengeSolution | null = null;
|
|
865
841
|
|
|
866
842
|
while (iterations < this.MAX_ITERATIONS && estimatedFundingAmount !== previousAmount) {
|
|
867
843
|
previousAmount = estimatedFundingAmount;
|
|
@@ -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 {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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(
|
|
@@ -2,19 +2,10 @@ import { TransactionType } from '../enums/TransactionType.js';
|
|
|
2
2
|
import { P2TRPayment, PaymentType, Psbt, PsbtInput, Taptree } from '@btc-vision/bitcoin';
|
|
3
3
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
4
4
|
import { TapLeafScript } from '../interfaces/Tap.js';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
SharedInteractionParameters,
|
|
8
|
-
} from '../interfaces/ITransactionParameters.js';
|
|
5
|
+
import { SharedInteractionParameters } from '../interfaces/ITransactionParameters.js';
|
|
6
|
+
import { ICancelTransactionParameters } from '../interfaces/ICancelTransactionParameters.js';
|
|
9
7
|
import { UnisatSigner } from '../browser/extensions/UnisatSigner.js';
|
|
10
8
|
|
|
11
|
-
export interface ICancelTransactionParameters extends Omit<
|
|
12
|
-
ITransactionParameters,
|
|
13
|
-
'priorityFee' | 'gasSatFee'
|
|
14
|
-
> {
|
|
15
|
-
readonly compiledTargetScript: string | Buffer;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
9
|
export class CancelTransaction extends TransactionBuilder<TransactionType.CANCEL> {
|
|
19
10
|
public type: TransactionType.CANCEL = TransactionType.CANCEL;
|
|
20
11
|
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
} from '../interfaces/IConsolidatedTransactionParameters.js';
|
|
15
15
|
import { IP2WSHAddress } from '../mineable/IP2WSHAddress.js';
|
|
16
16
|
import { TimeLockGenerator } from '../mineable/TimelockGenerator.js';
|
|
17
|
-
import {
|
|
17
|
+
import { IChallengeSolution } from '../../epoch/interfaces/IChallengeSolution.js';
|
|
18
18
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
19
19
|
import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
|
|
20
20
|
import { Compressor } from '../../bytecode/Compressor.js';
|
|
@@ -77,7 +77,7 @@ export class ConsolidatedInteractionTransaction extends TransactionBuilder<Trans
|
|
|
77
77
|
/** The compressed calldata (same as InteractionTransaction) */
|
|
78
78
|
protected readonly calldata: Buffer;
|
|
79
79
|
/** Challenge solution for epoch (same as InteractionTransaction) */
|
|
80
|
-
protected readonly challenge:
|
|
80
|
+
protected readonly challenge: IChallengeSolution;
|
|
81
81
|
/** Epoch challenge P2WSH address (same as InteractionTransaction) */
|
|
82
82
|
protected readonly epochChallenge: IP2WSHAddress;
|
|
83
83
|
/** Script signer for interaction (same as InteractionTransaction) */
|
|
@@ -225,7 +225,7 @@ export class ConsolidatedInteractionTransaction extends TransactionBuilder<Trans
|
|
|
225
225
|
/**
|
|
226
226
|
* Get the challenge solution (same as InteractionTransaction).
|
|
227
227
|
*/
|
|
228
|
-
public getChallenge():
|
|
228
|
+
public getChallenge(): IChallengeSolution {
|
|
229
229
|
return this.challenge;
|
|
230
230
|
}
|
|
231
231
|
|