@btc-vision/transaction 1.6.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/_version.d.ts +1 -1
- package/browser/epoch/validator/EpochValidator.d.ts +2 -2
- package/browser/generators/builders/DeploymentGenerator.d.ts +1 -1
- package/browser/generators/builders/LegacyCalldataGenerator.d.ts +1 -1
- package/browser/index.js +1 -1
- package/browser/transaction/TransactionFactory.d.ts +2 -2
- package/browser/transaction/builders/DeploymentTransaction.d.ts +1 -1
- package/browser/utxo/OPNetLimitedProvider.d.ts +0 -4
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/epoch/ChallengeSolution.js +1 -1
- package/build/epoch/validator/EpochValidator.d.ts +2 -2
- package/build/epoch/validator/EpochValidator.js +8 -8
- package/build/generators/builders/DeploymentGenerator.d.ts +1 -1
- package/build/generators/builders/DeploymentGenerator.js +5 -5
- package/build/generators/builders/LegacyCalldataGenerator.d.ts +1 -1
- package/build/generators/builders/LegacyCalldataGenerator.js +2 -2
- package/build/transaction/TransactionFactory.d.ts +2 -2
- package/build/transaction/TransactionFactory.js +2 -2
- package/build/transaction/builders/DeploymentTransaction.d.ts +1 -1
- package/build/transaction/builders/DeploymentTransaction.js +4 -4
- package/build/utxo/OPNetLimitedProvider.d.ts +0 -4
- package/build/utxo/OPNetLimitedProvider.js +0 -7
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/epoch/ChallengeSolution.ts +7 -7
- package/src/epoch/validator/EpochValidator.ts +9 -9
- package/src/generators/builders/DeploymentGenerator.ts +6 -6
- package/src/generators/builders/LegacyCalldataGenerator.ts +3 -3
- package/src/transaction/TransactionFactory.ts +4 -4
- package/src/transaction/builders/DeploymentTransaction.ts +5 -5
- package/src/utxo/OPNetLimitedProvider.ts +0 -17
|
@@ -11,7 +11,7 @@ export interface DeploymentResult {
|
|
|
11
11
|
readonly transaction: [string, string];
|
|
12
12
|
readonly contractAddress: string;
|
|
13
13
|
readonly contractPubKey: string;
|
|
14
|
-
readonly
|
|
14
|
+
readonly challenge: RawChallenge;
|
|
15
15
|
readonly utxos: UTXO[];
|
|
16
16
|
}
|
|
17
17
|
export interface FundingTransactionResponse {
|
|
@@ -30,7 +30,7 @@ export interface InteractionResponse {
|
|
|
30
30
|
readonly interactionTransaction: string;
|
|
31
31
|
readonly estimatedFees: bigint;
|
|
32
32
|
readonly nextUTXOs: UTXO[];
|
|
33
|
-
readonly
|
|
33
|
+
readonly challenge: RawChallenge;
|
|
34
34
|
}
|
|
35
35
|
export interface BitcoinTransferResponse extends BitcoinTransferBase {
|
|
36
36
|
readonly original: FundingTransaction;
|
|
@@ -9,7 +9,7 @@ import { ChallengeSolution } from '../../epoch/ChallengeSolution.js';
|
|
|
9
9
|
export declare class DeploymentTransaction extends TransactionBuilder<TransactionType.DEPLOYMENT> {
|
|
10
10
|
static readonly MAXIMUM_CONTRACT_SIZE: number;
|
|
11
11
|
type: TransactionType.DEPLOYMENT;
|
|
12
|
-
protected readonly
|
|
12
|
+
protected readonly challenge: ChallengeSolution;
|
|
13
13
|
protected readonly epochChallenge: ITimeLockOutput;
|
|
14
14
|
protected readonly _contractAddress: Address;
|
|
15
15
|
protected tapLeafScript: TapLeafScript | null;
|
|
@@ -7,9 +7,6 @@ export interface WalletUTXOs {
|
|
|
7
7
|
readonly pending: RawUTXOResponse[];
|
|
8
8
|
readonly spentTransactions: RawUTXOResponse[];
|
|
9
9
|
}
|
|
10
|
-
export interface PreimageData {
|
|
11
|
-
readonly preimage: Buffer;
|
|
12
|
-
}
|
|
13
10
|
export declare class OPNetLimitedProvider {
|
|
14
11
|
private readonly opnetAPIUrl;
|
|
15
12
|
private readonly utxoPath;
|
|
@@ -18,7 +15,6 @@ export declare class OPNetLimitedProvider {
|
|
|
18
15
|
fetchUTXO(settings: FetchUTXOParams): Promise<UTXO[]>;
|
|
19
16
|
fetchUTXOMultiAddr(settings: FetchUTXOParamsMultiAddress): Promise<UTXO[]>;
|
|
20
17
|
broadcastTransaction(transaction: string, psbt: boolean): Promise<BroadcastResponse | undefined>;
|
|
21
|
-
getPreimage(): Promise<PreimageData | undefined>;
|
|
22
18
|
splitUTXOs(wallet: Wallet, network: Network, splitInputsInto: number, amountPerUTXO: bigint): Promise<BroadcastResponse | {
|
|
23
19
|
error: string;
|
|
24
20
|
}>;
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.6.
|
|
1
|
+
export declare const version = "1.6.1";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.6.
|
|
1
|
+
export const version = '1.6.1';
|
|
@@ -7,10 +7,10 @@ export declare class EpochValidator {
|
|
|
7
7
|
static sha1(data: Uint8Array): Promise<Uint8Array>;
|
|
8
8
|
static calculatePreimage(checksumRoot: Buffer, publicKey: Buffer, salt: Buffer): Buffer;
|
|
9
9
|
static countMatchingBits(hash1: Buffer, hash2: Buffer): number;
|
|
10
|
-
static verifySolution(
|
|
10
|
+
static verifySolution(challenge: IChallengeSolution, log?: boolean): Promise<boolean>;
|
|
11
11
|
static getMiningTargetBlock(epochNumber: bigint): bigint | null;
|
|
12
12
|
static validateEpochWinner(epochData: RawChallenge): Promise<boolean>;
|
|
13
|
-
static
|
|
13
|
+
static validateChallengeSolution(challenge: IChallengeSolution): Promise<boolean>;
|
|
14
14
|
static calculateSolution(targetChecksum: Buffer, publicKey: Buffer, salt: Buffer): Promise<Buffer>;
|
|
15
15
|
static checkDifficulty(solution: Buffer, targetHash: Buffer, minDifficulty: number): {
|
|
16
16
|
valid: boolean;
|
|
@@ -45,20 +45,20 @@ export class EpochValidator {
|
|
|
45
45
|
}
|
|
46
46
|
return matchingBits;
|
|
47
47
|
}
|
|
48
|
-
static async verifySolution(
|
|
48
|
+
static async verifySolution(challenge, log = false) {
|
|
49
49
|
try {
|
|
50
|
-
const verification =
|
|
51
|
-
const calculatedPreimage = this.calculatePreimage(verification.targetChecksum,
|
|
50
|
+
const verification = challenge.verification;
|
|
51
|
+
const calculatedPreimage = this.calculatePreimage(verification.targetChecksum, challenge.publicKey.toBuffer(), challenge.salt);
|
|
52
52
|
const computedSolution = await this.sha1(this.bufferToUint8Array(calculatedPreimage));
|
|
53
53
|
const computedSolutionBuffer = this.uint8ArrayToBuffer(computedSolution);
|
|
54
|
-
if (!computedSolutionBuffer.equals(
|
|
54
|
+
if (!computedSolutionBuffer.equals(challenge.solution)) {
|
|
55
55
|
return false;
|
|
56
56
|
}
|
|
57
57
|
const matchingBits = this.countMatchingBits(computedSolutionBuffer, verification.targetHash);
|
|
58
|
-
if (matchingBits !==
|
|
58
|
+
if (matchingBits !== challenge.difficulty) {
|
|
59
59
|
return false;
|
|
60
60
|
}
|
|
61
|
-
const expectedStartBlock =
|
|
61
|
+
const expectedStartBlock = challenge.epochNumber * this.BLOCKS_PER_EPOCH;
|
|
62
62
|
const expectedEndBlock = expectedStartBlock + this.BLOCKS_PER_EPOCH - 1n;
|
|
63
63
|
return !(verification.startBlock !== expectedStartBlock ||
|
|
64
64
|
verification.endBlock !== expectedEndBlock);
|
|
@@ -79,8 +79,8 @@ export class EpochValidator {
|
|
|
79
79
|
const preimage = new ChallengeSolution(epochData);
|
|
80
80
|
return await this.verifySolution(preimage);
|
|
81
81
|
}
|
|
82
|
-
static async
|
|
83
|
-
return await this.verifySolution(
|
|
82
|
+
static async validateChallengeSolution(challenge) {
|
|
83
|
+
return await this.verifySolution(challenge);
|
|
84
84
|
}
|
|
85
85
|
static async calculateSolution(targetChecksum, publicKey, salt) {
|
|
86
86
|
const preimage = this.calculatePreimage(targetChecksum, publicKey, salt);
|
|
@@ -6,6 +6,6 @@ export declare const OPNET_DEPLOYMENT_VERSION = 0;
|
|
|
6
6
|
export declare const versionBuffer: Buffer<ArrayBuffer>;
|
|
7
7
|
export declare class DeploymentGenerator extends Generator {
|
|
8
8
|
constructor(senderPubKey: Buffer, contractSaltPubKey: Buffer, network?: Network);
|
|
9
|
-
compile(contractBytecode: Buffer, contractSalt: Buffer,
|
|
9
|
+
compile(contractBytecode: Buffer, contractSalt: Buffer, challenge: ChallengeSolution, maxPriority: bigint, calldata?: Buffer, features?: Feature<Features>[]): Buffer;
|
|
10
10
|
private getAsm;
|
|
11
11
|
}
|
|
@@ -6,8 +6,8 @@ export class DeploymentGenerator extends Generator {
|
|
|
6
6
|
constructor(senderPubKey, contractSaltPubKey, network = networks.bitcoin) {
|
|
7
7
|
super(senderPubKey, contractSaltPubKey, network);
|
|
8
8
|
}
|
|
9
|
-
compile(contractBytecode, contractSalt,
|
|
10
|
-
const asm = this.getAsm(contractBytecode, contractSalt,
|
|
9
|
+
compile(contractBytecode, contractSalt, challenge, maxPriority, calldata, features) {
|
|
10
|
+
const asm = this.getAsm(contractBytecode, contractSalt, challenge, maxPriority, calldata, features);
|
|
11
11
|
const compiled = script.compile(asm);
|
|
12
12
|
const decompiled = script.decompile(compiled);
|
|
13
13
|
if (!decompiled) {
|
|
@@ -15,7 +15,7 @@ export class DeploymentGenerator extends Generator {
|
|
|
15
15
|
}
|
|
16
16
|
return compiled;
|
|
17
17
|
}
|
|
18
|
-
getAsm(contractBytecode, contractSalt,
|
|
18
|
+
getAsm(contractBytecode, contractSalt, challenge, maxPriority, calldata, features) {
|
|
19
19
|
if (!this.contractSaltPubKey)
|
|
20
20
|
throw new Error('Contract salt public key not set');
|
|
21
21
|
const dataChunks = this.splitBufferIntoChunks(contractBytecode);
|
|
@@ -33,9 +33,9 @@ export class DeploymentGenerator extends Generator {
|
|
|
33
33
|
const compiledData = [
|
|
34
34
|
this.getHeader(maxPriority, featuresList),
|
|
35
35
|
opcodes.OP_TOALTSTACK,
|
|
36
|
-
|
|
36
|
+
challenge.publicKey.originalPublicKeyBuffer(),
|
|
37
37
|
opcodes.OP_TOALTSTACK,
|
|
38
|
-
|
|
38
|
+
challenge.solution,
|
|
39
39
|
opcodes.OP_TOALTSTACK,
|
|
40
40
|
this.xSenderPubKey,
|
|
41
41
|
opcodes.OP_DUP,
|
|
@@ -4,5 +4,5 @@ import { Feature, Features } from '../Features.js';
|
|
|
4
4
|
export declare class LegacyCalldataGenerator extends Generator {
|
|
5
5
|
constructor(senderPubKey: Buffer, network?: Network);
|
|
6
6
|
static getPubKeyAsBuffer(witnessKeys: Buffer[], network: Network): Buffer;
|
|
7
|
-
compile(calldata: Buffer, contractSecret: Buffer,
|
|
7
|
+
compile(calldata: Buffer, contractSecret: Buffer, challenge: Buffer, maxPriority: bigint, features?: Feature<Features>[]): Buffer;
|
|
8
8
|
}
|
|
@@ -24,7 +24,7 @@ export class LegacyCalldataGenerator extends Generator {
|
|
|
24
24
|
}
|
|
25
25
|
return compressed;
|
|
26
26
|
}
|
|
27
|
-
compile(calldata, contractSecret,
|
|
27
|
+
compile(calldata, contractSecret, challenge, maxPriority, features = []) {
|
|
28
28
|
const dataChunks = this.splitBufferIntoChunks(calldata);
|
|
29
29
|
if (!dataChunks.length)
|
|
30
30
|
throw new Error('No data chunks found');
|
|
@@ -39,7 +39,7 @@ export class LegacyCalldataGenerator extends Generator {
|
|
|
39
39
|
let compiledData = [
|
|
40
40
|
this.getHeader(maxPriority, featuresList),
|
|
41
41
|
opcodes.OP_TOALTSTACK,
|
|
42
|
-
|
|
42
|
+
challenge,
|
|
43
43
|
opcodes.OP_TOALTSTACK,
|
|
44
44
|
this.senderPubKey,
|
|
45
45
|
opcodes.OP_DUP,
|
|
@@ -11,7 +11,7 @@ export interface DeploymentResult {
|
|
|
11
11
|
readonly transaction: [string, string];
|
|
12
12
|
readonly contractAddress: string;
|
|
13
13
|
readonly contractPubKey: string;
|
|
14
|
-
readonly
|
|
14
|
+
readonly challenge: RawChallenge;
|
|
15
15
|
readonly utxos: UTXO[];
|
|
16
16
|
}
|
|
17
17
|
export interface FundingTransactionResponse {
|
|
@@ -30,7 +30,7 @@ export interface InteractionResponse {
|
|
|
30
30
|
readonly interactionTransaction: string;
|
|
31
31
|
readonly estimatedFees: bigint;
|
|
32
32
|
readonly nextUTXOs: UTXO[];
|
|
33
|
-
readonly
|
|
33
|
+
readonly challenge: RawChallenge;
|
|
34
34
|
}
|
|
35
35
|
export interface BitcoinTransferResponse extends BitcoinTransferBase {
|
|
36
36
|
readonly original: FundingTransaction;
|
|
@@ -133,7 +133,7 @@ export class TransactionFactory {
|
|
|
133
133
|
interactionTransaction: outTx.toHex(),
|
|
134
134
|
estimatedFees: preTransaction.estimatedFees,
|
|
135
135
|
nextUTXOs: this.getUTXOAsTransaction(signedTransaction.tx, interactionParameters.from, 1),
|
|
136
|
-
|
|
136
|
+
challenge: preTransaction.getPreimage().toRaw(),
|
|
137
137
|
};
|
|
138
138
|
}
|
|
139
139
|
async signDeployment(deploymentParameters) {
|
|
@@ -211,7 +211,7 @@ export class TransactionFactory {
|
|
|
211
211
|
contractAddress: finalTransaction.getContractAddress(),
|
|
212
212
|
contractPubKey: finalTransaction.contractPubKey,
|
|
213
213
|
utxos: [refundUTXO],
|
|
214
|
-
|
|
214
|
+
challenge: preTransaction.getPreimage().toRaw(),
|
|
215
215
|
};
|
|
216
216
|
}
|
|
217
217
|
async createBTCTransfer(parameters) {
|
|
@@ -9,7 +9,7 @@ import { ChallengeSolution } from '../../epoch/ChallengeSolution.js';
|
|
|
9
9
|
export declare class DeploymentTransaction extends TransactionBuilder<TransactionType.DEPLOYMENT> {
|
|
10
10
|
static readonly MAXIMUM_CONTRACT_SIZE: number;
|
|
11
11
|
type: TransactionType.DEPLOYMENT;
|
|
12
|
-
protected readonly
|
|
12
|
+
protected readonly challenge: ChallengeSolution;
|
|
13
13
|
protected readonly epochChallenge: ITimeLockOutput;
|
|
14
14
|
protected readonly _contractAddress: Address;
|
|
15
15
|
protected tapLeafScript: TapLeafScript | null;
|
|
@@ -45,12 +45,12 @@ export class DeploymentTransaction extends TransactionBuilder {
|
|
|
45
45
|
if (!parameters.challenge)
|
|
46
46
|
throw new Error('Challenge solution is required');
|
|
47
47
|
this.randomBytes = parameters.randomBytes || BitcoinUtils.rndBytes();
|
|
48
|
-
this.
|
|
49
|
-
this.epochChallenge = TimeLockGenerator.generateTimeLockAddress(this.
|
|
48
|
+
this.challenge = parameters.challenge;
|
|
49
|
+
this.epochChallenge = TimeLockGenerator.generateTimeLockAddress(this.challenge.publicKey.originalPublicKeyBuffer(), this.network);
|
|
50
50
|
this.contractSeed = this.getContractSeed();
|
|
51
51
|
this.contractSigner = EcKeyPair.fromSeedKeyPair(this.contractSeed, this.network);
|
|
52
52
|
this.deploymentGenerator = new DeploymentGenerator(Buffer.from(this.signer.publicKey), this.contractSignerXOnlyPubKey(), this.network);
|
|
53
|
-
this.compiledTargetScript = this.deploymentGenerator.compile(this.bytecode, this.randomBytes, this.
|
|
53
|
+
this.compiledTargetScript = this.deploymentGenerator.compile(this.bytecode, this.randomBytes, this.challenge, this.priorityFee, this.calldata, this.generateFeatures(parameters));
|
|
54
54
|
this.scriptTree = this.getScriptTree();
|
|
55
55
|
this.internalInit();
|
|
56
56
|
this._contractPubKey = '0x' + this.contractSeed.toString('hex');
|
|
@@ -69,7 +69,7 @@ export class DeploymentTransaction extends TransactionBuilder {
|
|
|
69
69
|
return this.randomBytes;
|
|
70
70
|
}
|
|
71
71
|
getPreimage() {
|
|
72
|
-
return this.
|
|
72
|
+
return this.challenge;
|
|
73
73
|
}
|
|
74
74
|
getContractAddress() {
|
|
75
75
|
if (this._computedAddress) {
|
|
@@ -7,9 +7,6 @@ export interface WalletUTXOs {
|
|
|
7
7
|
readonly pending: RawUTXOResponse[];
|
|
8
8
|
readonly spentTransactions: RawUTXOResponse[];
|
|
9
9
|
}
|
|
10
|
-
export interface PreimageData {
|
|
11
|
-
readonly preimage: Buffer;
|
|
12
|
-
}
|
|
13
10
|
export declare class OPNetLimitedProvider {
|
|
14
11
|
private readonly opnetAPIUrl;
|
|
15
12
|
private readonly utxoPath;
|
|
@@ -18,7 +15,6 @@ export declare class OPNetLimitedProvider {
|
|
|
18
15
|
fetchUTXO(settings: FetchUTXOParams): Promise<UTXO[]>;
|
|
19
16
|
fetchUTXOMultiAddr(settings: FetchUTXOParamsMultiAddress): Promise<UTXO[]>;
|
|
20
17
|
broadcastTransaction(transaction: string, psbt: boolean): Promise<BroadcastResponse | undefined>;
|
|
21
|
-
getPreimage(): Promise<PreimageData | undefined>;
|
|
22
18
|
splitUTXOs(wallet: Wallet, network: Network, splitInputsInto: number, amountPerUTXO: bigint): Promise<BroadcastResponse | {
|
|
23
19
|
error: string;
|
|
24
20
|
}>;
|
|
@@ -103,13 +103,6 @@ export class OPNetLimitedProvider {
|
|
|
103
103
|
}
|
|
104
104
|
return result;
|
|
105
105
|
}
|
|
106
|
-
async getPreimage() {
|
|
107
|
-
const result = await this.rpcMethod('btc_preimage', []);
|
|
108
|
-
if (!result) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
return result;
|
|
112
|
-
}
|
|
113
106
|
async splitUTXOs(wallet, network, splitInputsInto, amountPerUTXO) {
|
|
114
107
|
const utxoSetting = {
|
|
115
108
|
addresses: [wallet.p2wpkh, wallet.p2tr],
|
package/package.json
CHANGED
package/src/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.6.
|
|
1
|
+
export const version = '1.6.1';
|
|
@@ -115,16 +115,16 @@ export class ChallengeSolution implements IChallengeSolution {
|
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
/**
|
|
118
|
-
* Verify this
|
|
119
|
-
* @returns {Promise<boolean>} True if the
|
|
118
|
+
* Verify this challenge
|
|
119
|
+
* @returns {Promise<boolean>} True if the challenge is valid
|
|
120
120
|
*/
|
|
121
121
|
public async verify(): Promise<boolean> {
|
|
122
|
-
return EpochValidator.
|
|
122
|
+
return EpochValidator.validateChallengeSolution(this);
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
/**
|
|
126
|
-
* Get the preimage
|
|
127
|
-
* @returns {Buffer} The solution/
|
|
126
|
+
* Get the preimage challenge
|
|
127
|
+
* @returns {Buffer} The solution/challenge as a buffer
|
|
128
128
|
*/
|
|
129
129
|
public toBuffer(): Buffer {
|
|
130
130
|
return this.solution;
|
|
@@ -162,7 +162,7 @@ export class ChallengeSolution implements IChallengeSolution {
|
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
/**
|
|
165
|
-
* Calculate the expected solution hash for this
|
|
165
|
+
* Calculate the expected solution hash for this challenge
|
|
166
166
|
* @returns {Promise<Buffer>} The calculated solution hash
|
|
167
167
|
*/
|
|
168
168
|
public async calculateSolution(): Promise<Buffer> {
|
|
@@ -174,7 +174,7 @@ export class ChallengeSolution implements IChallengeSolution {
|
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
/**
|
|
177
|
-
* Check if the
|
|
177
|
+
* Check if the challenge meets a specific difficulty requirement
|
|
178
178
|
* @param {number} minDifficulty The minimum difficulty required
|
|
179
179
|
* @returns {Promise<{valid: boolean; difficulty: number}>} Validation result
|
|
180
180
|
*/
|
|
@@ -79,21 +79,21 @@ export class EpochValidator {
|
|
|
79
79
|
* Verify an epoch solution using IPreimage
|
|
80
80
|
*/
|
|
81
81
|
public static async verifySolution(
|
|
82
|
-
|
|
82
|
+
challenge: IChallengeSolution,
|
|
83
83
|
log: boolean = false,
|
|
84
84
|
): Promise<boolean> {
|
|
85
85
|
try {
|
|
86
|
-
const verification =
|
|
86
|
+
const verification = challenge.verification;
|
|
87
87
|
const calculatedPreimage = this.calculatePreimage(
|
|
88
88
|
verification.targetChecksum,
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
challenge.publicKey.toBuffer(),
|
|
90
|
+
challenge.salt,
|
|
91
91
|
);
|
|
92
92
|
|
|
93
93
|
const computedSolution = await this.sha1(this.bufferToUint8Array(calculatedPreimage));
|
|
94
94
|
const computedSolutionBuffer = this.uint8ArrayToBuffer(computedSolution);
|
|
95
95
|
|
|
96
|
-
if (!computedSolutionBuffer.equals(
|
|
96
|
+
if (!computedSolutionBuffer.equals(challenge.solution)) {
|
|
97
97
|
return false;
|
|
98
98
|
}
|
|
99
99
|
|
|
@@ -102,11 +102,11 @@ export class EpochValidator {
|
|
|
102
102
|
verification.targetHash,
|
|
103
103
|
);
|
|
104
104
|
|
|
105
|
-
if (matchingBits !==
|
|
105
|
+
if (matchingBits !== challenge.difficulty) {
|
|
106
106
|
return false;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
const expectedStartBlock =
|
|
109
|
+
const expectedStartBlock = challenge.epochNumber * this.BLOCKS_PER_EPOCH;
|
|
110
110
|
const expectedEndBlock = expectedStartBlock + this.BLOCKS_PER_EPOCH - 1n;
|
|
111
111
|
|
|
112
112
|
return !(
|
|
@@ -142,8 +142,8 @@ export class EpochValidator {
|
|
|
142
142
|
/**
|
|
143
143
|
* Validate epoch winner from Preimage instance
|
|
144
144
|
*/
|
|
145
|
-
public static async
|
|
146
|
-
return await this.verifySolution(
|
|
145
|
+
public static async validateChallengeSolution(challenge: IChallengeSolution): Promise<boolean> {
|
|
146
|
+
return await this.verifySolution(challenge);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
/**
|
|
@@ -19,7 +19,7 @@ export class DeploymentGenerator extends Generator {
|
|
|
19
19
|
* Compile a bitcoin script representing a contract deployment
|
|
20
20
|
* @param {Buffer} contractBytecode - The contract bytecode
|
|
21
21
|
* @param {Buffer} contractSalt - The contract salt
|
|
22
|
-
* @param {ChallengeSolution}
|
|
22
|
+
* @param {ChallengeSolution} challenge - The challenge for reward
|
|
23
23
|
* @param {bigint} maxPriority - The maximum priority for the contract
|
|
24
24
|
* @param {Buffer} [calldata] - The calldata to be passed to the contract
|
|
25
25
|
* @param {Feature<Features>[]} [features] - Optional features to include in the script
|
|
@@ -28,7 +28,7 @@ export class DeploymentGenerator extends Generator {
|
|
|
28
28
|
public compile(
|
|
29
29
|
contractBytecode: Buffer,
|
|
30
30
|
contractSalt: Buffer,
|
|
31
|
-
|
|
31
|
+
challenge: ChallengeSolution,
|
|
32
32
|
maxPriority: bigint,
|
|
33
33
|
calldata?: Buffer,
|
|
34
34
|
features?: Feature<Features>[],
|
|
@@ -36,7 +36,7 @@ export class DeploymentGenerator extends Generator {
|
|
|
36
36
|
const asm = this.getAsm(
|
|
37
37
|
contractBytecode,
|
|
38
38
|
contractSalt,
|
|
39
|
-
|
|
39
|
+
challenge,
|
|
40
40
|
maxPriority,
|
|
41
41
|
calldata,
|
|
42
42
|
features,
|
|
@@ -57,7 +57,7 @@ export class DeploymentGenerator extends Generator {
|
|
|
57
57
|
private getAsm(
|
|
58
58
|
contractBytecode: Buffer,
|
|
59
59
|
contractSalt: Buffer,
|
|
60
|
-
|
|
60
|
+
challenge: ChallengeSolution,
|
|
61
61
|
maxPriority: bigint,
|
|
62
62
|
calldata?: Buffer,
|
|
63
63
|
features?: Feature<Features>[],
|
|
@@ -85,10 +85,10 @@ export class DeploymentGenerator extends Generator {
|
|
|
85
85
|
opcodes.OP_TOALTSTACK,
|
|
86
86
|
|
|
87
87
|
// CHALLENGE PREIMAGE FOR REWARD,
|
|
88
|
-
|
|
88
|
+
challenge.publicKey.originalPublicKeyBuffer(),
|
|
89
89
|
opcodes.OP_TOALTSTACK,
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
challenge.solution,
|
|
92
92
|
opcodes.OP_TOALTSTACK,
|
|
93
93
|
|
|
94
94
|
this.xSenderPubKey,
|
|
@@ -52,7 +52,7 @@ export class LegacyCalldataGenerator extends Generator {
|
|
|
52
52
|
* Compile an interaction bitcoin script
|
|
53
53
|
* @param {Buffer} calldata - The calldata to use
|
|
54
54
|
* @param {Buffer} contractSecret - The contract secret
|
|
55
|
-
* @param {Buffer}
|
|
55
|
+
* @param {Buffer} challenge - The challenge to use
|
|
56
56
|
* @param {bigint} maxPriority - The maximum priority
|
|
57
57
|
* @param {number[]} [features=[]] - The features to use (optional)
|
|
58
58
|
* @returns {Buffer} - The compiled script
|
|
@@ -61,7 +61,7 @@ export class LegacyCalldataGenerator extends Generator {
|
|
|
61
61
|
public compile(
|
|
62
62
|
calldata: Buffer,
|
|
63
63
|
contractSecret: Buffer,
|
|
64
|
-
|
|
64
|
+
challenge: Buffer,
|
|
65
65
|
maxPriority: bigint,
|
|
66
66
|
features: Feature<Features>[] = [],
|
|
67
67
|
): Buffer {
|
|
@@ -83,7 +83,7 @@ export class LegacyCalldataGenerator extends Generator {
|
|
|
83
83
|
opcodes.OP_TOALTSTACK,
|
|
84
84
|
|
|
85
85
|
// CHALLENGE PREIMAGE FOR REWARD,
|
|
86
|
-
|
|
86
|
+
challenge,
|
|
87
87
|
opcodes.OP_TOALTSTACK,
|
|
88
88
|
|
|
89
89
|
this.senderPubKey,
|
|
@@ -29,7 +29,7 @@ export interface DeploymentResult {
|
|
|
29
29
|
|
|
30
30
|
readonly contractAddress: string;
|
|
31
31
|
readonly contractPubKey: string;
|
|
32
|
-
readonly
|
|
32
|
+
readonly challenge: RawChallenge;
|
|
33
33
|
|
|
34
34
|
readonly utxos: UTXO[];
|
|
35
35
|
}
|
|
@@ -52,7 +52,7 @@ export interface InteractionResponse {
|
|
|
52
52
|
readonly interactionTransaction: string;
|
|
53
53
|
readonly estimatedFees: bigint;
|
|
54
54
|
readonly nextUTXOs: UTXO[];
|
|
55
|
-
readonly
|
|
55
|
+
readonly challenge: RawChallenge;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
export interface BitcoinTransferResponse extends BitcoinTransferBase {
|
|
@@ -253,7 +253,7 @@ export class TransactionFactory {
|
|
|
253
253
|
interactionParameters.from,
|
|
254
254
|
1,
|
|
255
255
|
), // always 1
|
|
256
|
-
|
|
256
|
+
challenge: preTransaction.getPreimage().toRaw(),
|
|
257
257
|
};
|
|
258
258
|
}
|
|
259
259
|
|
|
@@ -358,7 +358,7 @@ export class TransactionFactory {
|
|
|
358
358
|
contractAddress: finalTransaction.getContractAddress(), //finalTransaction.contractAddress.p2tr(deploymentParameters.network),
|
|
359
359
|
contractPubKey: finalTransaction.contractPubKey,
|
|
360
360
|
utxos: [refundUTXO],
|
|
361
|
-
|
|
361
|
+
challenge: preTransaction.getPreimage().toRaw(),
|
|
362
362
|
};
|
|
363
363
|
}
|
|
364
364
|
|
|
@@ -36,7 +36,7 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
36
36
|
|
|
37
37
|
public type: TransactionType.DEPLOYMENT = TransactionType.DEPLOYMENT;
|
|
38
38
|
|
|
39
|
-
protected readonly
|
|
39
|
+
protected readonly challenge: ChallengeSolution;
|
|
40
40
|
protected readonly epochChallenge: ITimeLockOutput;
|
|
41
41
|
|
|
42
42
|
/**
|
|
@@ -128,10 +128,10 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
128
128
|
if (!parameters.challenge) throw new Error('Challenge solution is required');
|
|
129
129
|
|
|
130
130
|
this.randomBytes = parameters.randomBytes || BitcoinUtils.rndBytes();
|
|
131
|
-
this.
|
|
131
|
+
this.challenge = parameters.challenge;
|
|
132
132
|
|
|
133
133
|
this.epochChallenge = TimeLockGenerator.generateTimeLockAddress(
|
|
134
|
-
this.
|
|
134
|
+
this.challenge.publicKey.originalPublicKeyBuffer(),
|
|
135
135
|
this.network,
|
|
136
136
|
);
|
|
137
137
|
|
|
@@ -147,7 +147,7 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
147
147
|
this.compiledTargetScript = this.deploymentGenerator.compile(
|
|
148
148
|
this.bytecode,
|
|
149
149
|
this.randomBytes,
|
|
150
|
-
this.
|
|
150
|
+
this.challenge,
|
|
151
151
|
this.priorityFee,
|
|
152
152
|
this.calldata,
|
|
153
153
|
this.generateFeatures(parameters),
|
|
@@ -195,7 +195,7 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
195
195
|
* @returns {Buffer} The contract bytecode
|
|
196
196
|
*/
|
|
197
197
|
public getPreimage(): ChallengeSolution {
|
|
198
|
-
return this.
|
|
198
|
+
return this.challenge;
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
public getContractAddress(): string {
|
|
@@ -14,10 +14,6 @@ export interface WalletUTXOs {
|
|
|
14
14
|
readonly spentTransactions: RawUTXOResponse[];
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export interface PreimageData {
|
|
18
|
-
readonly preimage: Buffer;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
17
|
/**
|
|
22
18
|
* Allows to fetch UTXO data from any OPNET node
|
|
23
19
|
*/
|
|
@@ -181,19 +177,6 @@ export class OPNetLimitedProvider {
|
|
|
181
177
|
return result as BroadcastResponse;
|
|
182
178
|
}
|
|
183
179
|
|
|
184
|
-
/**
|
|
185
|
-
* Fetches the preimage from the OPNET node
|
|
186
|
-
* @returns {Promise<PreimageData | undefined>} - The preimage fetched
|
|
187
|
-
*/
|
|
188
|
-
public async getPreimage(): Promise<PreimageData | undefined> {
|
|
189
|
-
const result = await this.rpcMethod('btc_preimage', []);
|
|
190
|
-
if (!result) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return result as PreimageData;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
180
|
/**
|
|
198
181
|
* Splits UTXOs into smaller UTXOs
|
|
199
182
|
* @param {Wallet} wallet - The wallet to split UTXOs
|