@btc-vision/transaction 1.0.110 → 1.0.111
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/generators/builders/DeploymentGenerator.d.ts +1 -1
- package/browser/index.js +1 -1
- package/browser/transaction/builders/DeploymentTransaction.d.ts +3 -0
- package/browser/transaction/builders/SharedInteractionTransaction.d.ts +1 -0
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +1 -0
- package/browser/verification/TapscriptVerificator.d.ts +1 -0
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/generators/builders/DeploymentGenerator.d.ts +1 -1
- package/build/generators/builders/DeploymentGenerator.js +6 -3
- package/build/transaction/builders/DeploymentTransaction.d.ts +3 -0
- package/build/transaction/builders/DeploymentTransaction.js +20 -5
- package/build/transaction/builders/SharedInteractionTransaction.d.ts +1 -0
- package/build/transaction/builders/SharedInteractionTransaction.js +1 -0
- package/build/transaction/interfaces/ITransactionParameters.d.ts +1 -0
- package/build/verification/TapscriptVerificator.d.ts +1 -0
- package/build/verification/TapscriptVerificator.js +1 -1
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/generators/builders/DeploymentGenerator.ts +12 -4
- package/src/transaction/builders/DeploymentTransaction.ts +30 -3
- package/src/transaction/builders/SharedInteractionTransaction.ts +2 -0
- package/src/transaction/interfaces/ITransactionParameters.ts +2 -0
- package/src/verification/TapscriptVerificator.ts +2 -0
|
@@ -16,6 +16,7 @@ export declare class DeploymentTransaction extends TransactionBuilder<Transactio
|
|
|
16
16
|
private deploymentGenerator;
|
|
17
17
|
private readonly contractSeed;
|
|
18
18
|
private readonly bytecode;
|
|
19
|
+
private readonly calldata?;
|
|
19
20
|
private readonly contractSigner;
|
|
20
21
|
private readonly randomBytes;
|
|
21
22
|
constructor(parameters: IDeploymentParameters);
|
|
@@ -27,6 +28,8 @@ export declare class DeploymentTransaction extends TransactionBuilder<Transactio
|
|
|
27
28
|
protected signInputs(transaction: Psbt): Promise<void>;
|
|
28
29
|
protected generateScriptAddress(): Payment;
|
|
29
30
|
protected generateTapData(): Payment;
|
|
31
|
+
private verifyCalldata;
|
|
32
|
+
private verifyBytecode;
|
|
30
33
|
private getContractSeed;
|
|
31
34
|
private customFinalizer;
|
|
32
35
|
private getPubKeys;
|
|
@@ -7,6 +7,7 @@ import { TransactionType } from '../enums/TransactionType.js';
|
|
|
7
7
|
import { CalldataGenerator } from '../../generators/builders/CalldataGenerator.js';
|
|
8
8
|
import { SharedInteractionParameters } from '../interfaces/ITransactionParameters.js';
|
|
9
9
|
export declare abstract class SharedInteractionTransaction<T extends TransactionType> extends TransactionBuilder<T> {
|
|
10
|
+
static readonly MAXIMUM_CALLDATA_SIZE: number;
|
|
10
11
|
readonly randomBytes: Buffer;
|
|
11
12
|
protected targetScriptRedeem: Payment | null;
|
|
12
13
|
protected leftOverFundsScriptRedeem: Payment | null;
|
|
@@ -42,5 +42,6 @@ export interface IUnwrapParameters extends Omit<SharedInteractionParameters, 'op
|
|
|
42
42
|
}
|
|
43
43
|
export interface IDeploymentParameters extends Omit<ITransactionParameters, 'to'> {
|
|
44
44
|
readonly bytecode: Buffer;
|
|
45
|
+
readonly calldata?: Buffer;
|
|
45
46
|
readonly randomBytes?: Buffer;
|
|
46
47
|
}
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.0.
|
|
1
|
+
export declare const version = "1.0.111";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.111';
|
|
@@ -2,6 +2,6 @@ import { Network } from 'bitcoinjs-lib';
|
|
|
2
2
|
import { Generator } from '../Generator.js';
|
|
3
3
|
export declare class DeploymentGenerator extends Generator {
|
|
4
4
|
constructor(senderPubKey: Buffer, contractSaltPubKey: Buffer, network?: Network);
|
|
5
|
-
compile(contractBytecode: Buffer, contractSalt: Buffer): Buffer;
|
|
5
|
+
compile(contractBytecode: Buffer, contractSalt: Buffer, calldata?: Buffer): Buffer;
|
|
6
6
|
private getAsm;
|
|
7
7
|
}
|
|
@@ -4,8 +4,8 @@ export class DeploymentGenerator extends Generator {
|
|
|
4
4
|
constructor(senderPubKey, contractSaltPubKey, network = networks.bitcoin) {
|
|
5
5
|
super(senderPubKey, contractSaltPubKey, network);
|
|
6
6
|
}
|
|
7
|
-
compile(contractBytecode, contractSalt) {
|
|
8
|
-
const asm = this.getAsm(contractBytecode, contractSalt);
|
|
7
|
+
compile(contractBytecode, contractSalt, calldata) {
|
|
8
|
+
const asm = this.getAsm(contractBytecode, contractSalt, calldata);
|
|
9
9
|
const compiled = script.compile(asm);
|
|
10
10
|
const decompiled = script.decompile(compiled);
|
|
11
11
|
if (!decompiled) {
|
|
@@ -13,10 +13,11 @@ export class DeploymentGenerator extends Generator {
|
|
|
13
13
|
}
|
|
14
14
|
return compiled;
|
|
15
15
|
}
|
|
16
|
-
getAsm(contractBytecode, contractSalt) {
|
|
16
|
+
getAsm(contractBytecode, contractSalt, calldata) {
|
|
17
17
|
if (!this.contractSaltPubKey)
|
|
18
18
|
throw new Error('Contract salt public key not set');
|
|
19
19
|
const dataChunks = this.splitBufferIntoChunks(contractBytecode);
|
|
20
|
+
const calldataChunks = calldata ? this.splitBufferIntoChunks(calldata) : [];
|
|
20
21
|
return [
|
|
21
22
|
this.senderPubKey,
|
|
22
23
|
opcodes.OP_CHECKSIGVERIFY,
|
|
@@ -33,6 +34,8 @@ export class DeploymentGenerator extends Generator {
|
|
|
33
34
|
opcodes.OP_NUMEQUAL,
|
|
34
35
|
opcodes.OP_IF,
|
|
35
36
|
Generator.MAGIC,
|
|
37
|
+
opcodes.OP_0,
|
|
38
|
+
...calldataChunks,
|
|
36
39
|
opcodes.OP_1NEGATE,
|
|
37
40
|
...dataChunks,
|
|
38
41
|
opcodes.OP_ELSE,
|
|
@@ -16,6 +16,7 @@ export declare class DeploymentTransaction extends TransactionBuilder<Transactio
|
|
|
16
16
|
private deploymentGenerator;
|
|
17
17
|
private readonly contractSeed;
|
|
18
18
|
private readonly bytecode;
|
|
19
|
+
private readonly calldata?;
|
|
19
20
|
private readonly contractSigner;
|
|
20
21
|
private readonly randomBytes;
|
|
21
22
|
constructor(parameters: IDeploymentParameters);
|
|
@@ -27,6 +28,8 @@ export declare class DeploymentTransaction extends TransactionBuilder<Transactio
|
|
|
27
28
|
protected signInputs(transaction: Psbt): Promise<void>;
|
|
28
29
|
protected generateScriptAddress(): Payment;
|
|
29
30
|
protected generateTapData(): Payment;
|
|
31
|
+
private verifyCalldata;
|
|
32
|
+
private verifyBytecode;
|
|
30
33
|
private getContractSeed;
|
|
31
34
|
private customFinalizer;
|
|
32
35
|
private getPubKeys;
|
|
@@ -7,6 +7,7 @@ import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
|
7
7
|
import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
|
|
8
8
|
import { Compressor } from '../../bytecode/Compressor.js';
|
|
9
9
|
import { AddressGenerator } from '../../generators/AddressGenerator.js';
|
|
10
|
+
import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
|
|
10
11
|
export class DeploymentTransaction extends TransactionBuilder {
|
|
11
12
|
constructor(parameters) {
|
|
12
13
|
super(parameters);
|
|
@@ -35,15 +36,16 @@ export class DeploymentTransaction extends TransactionBuilder {
|
|
|
35
36
|
};
|
|
36
37
|
};
|
|
37
38
|
this.bytecode = Compressor.compress(parameters.bytecode);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
this.verifyBytecode();
|
|
40
|
+
if (parameters.calldata) {
|
|
41
|
+
this.calldata = parameters.calldata;
|
|
42
|
+
this.verifyCalldata();
|
|
43
|
+
}
|
|
42
44
|
this.randomBytes = parameters.randomBytes || BitcoinUtils.rndBytes();
|
|
43
45
|
this.contractSeed = this.getContractSeed();
|
|
44
46
|
this.contractSigner = EcKeyPair.fromSeedKeyPair(this.contractSeed, this.network);
|
|
45
47
|
this.deploymentGenerator = new DeploymentGenerator(this.internalPubKeyToXOnly(), this.contractSignerXOnlyPubKey(), this.network);
|
|
46
|
-
this.compiledTargetScript = this.deploymentGenerator.compile(this.bytecode, this.randomBytes);
|
|
48
|
+
this.compiledTargetScript = this.deploymentGenerator.compile(this.bytecode, this.randomBytes, this.calldata);
|
|
47
49
|
this.scriptTree = this.getScriptTree();
|
|
48
50
|
this.internalInit();
|
|
49
51
|
this._contractAddress = AddressGenerator.generatePKSH(this.contractSeed, this.network);
|
|
@@ -130,6 +132,19 @@ export class DeploymentTransaction extends TransactionBuilder {
|
|
|
130
132
|
redeem: selectedRedeem,
|
|
131
133
|
};
|
|
132
134
|
}
|
|
135
|
+
verifyCalldata() {
|
|
136
|
+
if (this.calldata &&
|
|
137
|
+
this.calldata.length > SharedInteractionTransaction.MAXIMUM_CALLDATA_SIZE) {
|
|
138
|
+
throw new Error('Calldata size overflow.');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
verifyBytecode() {
|
|
142
|
+
if (!this.bytecode)
|
|
143
|
+
throw new Error('Bytecode is required');
|
|
144
|
+
if (this.bytecode.length > DeploymentTransaction.MAXIMUM_CONTRACT_SIZE) {
|
|
145
|
+
throw new Error('Contract size overflow.');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
133
148
|
getContractSeed() {
|
|
134
149
|
if (!this.bytecode) {
|
|
135
150
|
throw new Error('Bytecode is required');
|
|
@@ -7,6 +7,7 @@ import { TransactionType } from '../enums/TransactionType.js';
|
|
|
7
7
|
import { CalldataGenerator } from '../../generators/builders/CalldataGenerator.js';
|
|
8
8
|
import { SharedInteractionParameters } from '../interfaces/ITransactionParameters.js';
|
|
9
9
|
export declare abstract class SharedInteractionTransaction<T extends TransactionType> extends TransactionBuilder<T> {
|
|
10
|
+
static readonly MAXIMUM_CALLDATA_SIZE: number;
|
|
10
11
|
readonly randomBytes: Buffer;
|
|
11
12
|
protected targetScriptRedeem: Payment | null;
|
|
12
13
|
protected leftOverFundsScriptRedeem: Payment | null;
|
|
@@ -42,5 +42,6 @@ export interface IUnwrapParameters extends Omit<SharedInteractionParameters, 'op
|
|
|
42
42
|
}
|
|
43
43
|
export interface IDeploymentParameters extends Omit<ITransactionParameters, 'to'> {
|
|
44
44
|
readonly bytecode: Buffer;
|
|
45
|
+
readonly calldata?: Buffer;
|
|
45
46
|
readonly randomBytes?: Buffer;
|
|
46
47
|
}
|
|
@@ -7,7 +7,7 @@ export class TapscriptVerificator {
|
|
|
7
7
|
static getContractAddress(params) {
|
|
8
8
|
const network = params.network || networks.bitcoin;
|
|
9
9
|
const scriptBuilder = new DeploymentGenerator(params.deployerPubKeyXOnly, toXOnly(params.contractSaltPubKey), network);
|
|
10
|
-
const compiledTargetScript = scriptBuilder.compile(params.bytecode, params.originalSalt);
|
|
10
|
+
const compiledTargetScript = scriptBuilder.compile(params.bytecode, params.originalSalt, params.calldata);
|
|
11
11
|
const scriptTree = [
|
|
12
12
|
{
|
|
13
13
|
output: compiledTargetScript,
|
package/package.json
CHANGED
package/src/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.111';
|
|
@@ -14,10 +14,11 @@ export class DeploymentGenerator extends Generator {
|
|
|
14
14
|
* Compile a bitcoin script representing a contract deployment
|
|
15
15
|
* @param {Buffer} contractBytecode - The contract bytecode
|
|
16
16
|
* @param {Buffer} contractSalt - The contract salt
|
|
17
|
+
* @param {Buffer} [calldata] - The calldata to be passed to the contract
|
|
17
18
|
* @returns {Buffer} - The compiled script
|
|
18
19
|
*/
|
|
19
|
-
public compile(contractBytecode: Buffer, contractSalt: Buffer): Buffer {
|
|
20
|
-
const asm = this.getAsm(contractBytecode, contractSalt);
|
|
20
|
+
public compile(contractBytecode: Buffer, contractSalt: Buffer, calldata?: Buffer): Buffer {
|
|
21
|
+
const asm = this.getAsm(contractBytecode, contractSalt, calldata);
|
|
21
22
|
const compiled = script.compile(asm);
|
|
22
23
|
|
|
23
24
|
/**
|
|
@@ -31,10 +32,15 @@ export class DeploymentGenerator extends Generator {
|
|
|
31
32
|
return compiled;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
private getAsm(
|
|
35
|
+
private getAsm(
|
|
36
|
+
contractBytecode: Buffer,
|
|
37
|
+
contractSalt: Buffer,
|
|
38
|
+
calldata?: Buffer,
|
|
39
|
+
): (number | Buffer)[] {
|
|
35
40
|
if (!this.contractSaltPubKey) throw new Error('Contract salt public key not set');
|
|
36
41
|
|
|
37
|
-
const dataChunks = this.splitBufferIntoChunks(contractBytecode);
|
|
42
|
+
const dataChunks: Buffer[][] = this.splitBufferIntoChunks(contractBytecode);
|
|
43
|
+
const calldataChunks: Buffer[][] = calldata ? this.splitBufferIntoChunks(calldata) : [];
|
|
38
44
|
|
|
39
45
|
return [
|
|
40
46
|
this.senderPubKey,
|
|
@@ -57,6 +63,8 @@ export class DeploymentGenerator extends Generator {
|
|
|
57
63
|
opcodes.OP_IF,
|
|
58
64
|
|
|
59
65
|
Generator.MAGIC,
|
|
66
|
+
opcodes.OP_0,
|
|
67
|
+
...calldataChunks,
|
|
60
68
|
opcodes.OP_1NEGATE,
|
|
61
69
|
...dataChunks,
|
|
62
70
|
|
|
@@ -12,6 +12,7 @@ import { PsbtInput } from 'bip174/src/lib/interfaces.js';
|
|
|
12
12
|
import { Compressor } from '../../bytecode/Compressor.js';
|
|
13
13
|
import { AddressGenerator } from '../../generators/AddressGenerator.js';
|
|
14
14
|
import { Address } from '@btc-vision/bsi-binary';
|
|
15
|
+
import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
|
|
15
16
|
|
|
16
17
|
export class DeploymentTransaction extends TransactionBuilder<TransactionType.DEPLOYMENT> {
|
|
17
18
|
public static readonly MAXIMUM_CONTRACT_SIZE = 128 * 1024;
|
|
@@ -64,6 +65,12 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
64
65
|
*/
|
|
65
66
|
private readonly bytecode: Buffer;
|
|
66
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Constructor calldata
|
|
70
|
+
* @private
|
|
71
|
+
*/
|
|
72
|
+
private readonly calldata?: Buffer;
|
|
73
|
+
|
|
67
74
|
/**
|
|
68
75
|
* The contract signer
|
|
69
76
|
* @private
|
|
@@ -80,10 +87,12 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
80
87
|
super(parameters);
|
|
81
88
|
|
|
82
89
|
this.bytecode = Compressor.compress(parameters.bytecode);
|
|
83
|
-
|
|
90
|
+
this.verifyBytecode();
|
|
84
91
|
|
|
85
|
-
if (
|
|
86
|
-
|
|
92
|
+
if (parameters.calldata) {
|
|
93
|
+
this.calldata = parameters.calldata;
|
|
94
|
+
this.verifyCalldata();
|
|
95
|
+
}
|
|
87
96
|
|
|
88
97
|
this.randomBytes = parameters.randomBytes || BitcoinUtils.rndBytes();
|
|
89
98
|
|
|
@@ -99,6 +108,7 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
99
108
|
this.compiledTargetScript = this.deploymentGenerator.compile(
|
|
100
109
|
this.bytecode,
|
|
101
110
|
this.randomBytes,
|
|
111
|
+
this.calldata,
|
|
102
112
|
);
|
|
103
113
|
|
|
104
114
|
this.scriptTree = this.getScriptTree();
|
|
@@ -243,6 +253,23 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
|
|
|
243
253
|
};
|
|
244
254
|
}
|
|
245
255
|
|
|
256
|
+
private verifyCalldata(): void {
|
|
257
|
+
if (
|
|
258
|
+
this.calldata &&
|
|
259
|
+
this.calldata.length > SharedInteractionTransaction.MAXIMUM_CALLDATA_SIZE
|
|
260
|
+
) {
|
|
261
|
+
throw new Error('Calldata size overflow.');
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
private verifyBytecode(): void {
|
|
266
|
+
if (!this.bytecode) throw new Error('Bytecode is required');
|
|
267
|
+
|
|
268
|
+
if (this.bytecode.length > DeploymentTransaction.MAXIMUM_CONTRACT_SIZE) {
|
|
269
|
+
throw new Error('Contract size overflow.');
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
246
273
|
/**
|
|
247
274
|
* Generate the contract seed for the deployment
|
|
248
275
|
* @private
|
|
@@ -18,6 +18,8 @@ import { toXOnly } from 'bitcoinjs-lib/src/psbt/bip371.js';
|
|
|
18
18
|
export abstract class SharedInteractionTransaction<
|
|
19
19
|
T extends TransactionType,
|
|
20
20
|
> extends TransactionBuilder<T> {
|
|
21
|
+
public static readonly MAXIMUM_CALLDATA_SIZE = 1024 * 1024; // 1MB
|
|
22
|
+
|
|
21
23
|
/**
|
|
22
24
|
* Random salt for the interaction
|
|
23
25
|
* @type {Buffer}
|
|
@@ -5,6 +5,7 @@ import { ITweakedTransactionData } from '../shared/TweakedTransaction.js';
|
|
|
5
5
|
import { VaultUTXOs } from '../processor/PsbtTransaction.js';
|
|
6
6
|
import { ChainId } from '../../network/ChainId.js';
|
|
7
7
|
import { PsbtOutputExtended } from './Tap.js';
|
|
8
|
+
|
|
8
9
|
export interface ITransactionParameters extends ITweakedTransactionData {
|
|
9
10
|
readonly from?: Address;
|
|
10
11
|
readonly to?: Address;
|
|
@@ -58,6 +59,7 @@ export interface IUnwrapParameters extends Omit<SharedInteractionParameters, 'op
|
|
|
58
59
|
|
|
59
60
|
export interface IDeploymentParameters extends Omit<ITransactionParameters, 'to'> {
|
|
60
61
|
readonly bytecode: Buffer;
|
|
62
|
+
readonly calldata?: Buffer;
|
|
61
63
|
|
|
62
64
|
readonly randomBytes?: Buffer;
|
|
63
65
|
}
|
|
@@ -10,6 +10,7 @@ export interface ContractAddressVerificationParams {
|
|
|
10
10
|
readonly contractSaltPubKey: Buffer;
|
|
11
11
|
readonly originalSalt: Buffer;
|
|
12
12
|
readonly bytecode: Buffer;
|
|
13
|
+
readonly calldata?: Buffer;
|
|
13
14
|
readonly network?: Network;
|
|
14
15
|
}
|
|
15
16
|
|
|
@@ -29,6 +30,7 @@ export class TapscriptVerificator {
|
|
|
29
30
|
const compiledTargetScript: Buffer = scriptBuilder.compile(
|
|
30
31
|
params.bytecode,
|
|
31
32
|
params.originalSalt,
|
|
33
|
+
params.calldata,
|
|
32
34
|
);
|
|
33
35
|
|
|
34
36
|
const scriptTree: Taptree = [
|