@btc-vision/transaction 1.7.16 → 1.7.18
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/Generator.d.ts +2 -1
- package/browser/generators/builders/P2WDAGenerator.d.ts +0 -1
- package/browser/index.js +1 -1
- package/browser/transaction/TransactionFactory.d.ts +6 -1
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/generators/Generator.d.ts +2 -1
- package/build/generators/Generator.js +10 -10
- package/build/generators/builders/CalldataGenerator.js +6 -5
- package/build/generators/builders/DeploymentGenerator.js +5 -4
- package/build/generators/builders/LegacyCalldataGenerator.js +6 -5
- package/build/generators/builders/P2WDAGenerator.d.ts +0 -1
- package/build/generators/builders/P2WDAGenerator.js +1 -18
- package/build/transaction/TransactionFactory.d.ts +6 -1
- package/build/transaction/TransactionFactory.js +20 -7
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/generators/Generator.ts +15 -15
- package/src/generators/builders/CalldataGenerator.ts +10 -7
- package/src/generators/builders/DeploymentGenerator.ts +6 -6
- package/src/generators/builders/LegacyCalldataGenerator.ts +10 -7
- package/src/generators/builders/P2WDAGenerator.ts +1 -57
- package/src/transaction/TransactionFactory.ts +96 -33
|
@@ -14,17 +14,20 @@ export interface DeploymentResult {
|
|
|
14
14
|
readonly contractPubKey: string;
|
|
15
15
|
readonly challenge: RawChallenge;
|
|
16
16
|
readonly utxos: UTXO[];
|
|
17
|
+
readonly inputUtxos: UTXO[];
|
|
17
18
|
}
|
|
18
19
|
export interface FundingTransactionResponse {
|
|
19
20
|
readonly tx: Transaction;
|
|
20
21
|
readonly original: FundingTransaction;
|
|
21
22
|
readonly estimatedFees: bigint;
|
|
22
23
|
readonly nextUTXOs: UTXO[];
|
|
24
|
+
readonly inputUtxos: UTXO[];
|
|
23
25
|
}
|
|
24
26
|
export interface BitcoinTransferBase {
|
|
25
27
|
readonly tx: string;
|
|
26
28
|
readonly estimatedFees: bigint;
|
|
27
29
|
readonly nextUTXOs: UTXO[];
|
|
30
|
+
readonly inputUtxos: UTXO[];
|
|
28
31
|
}
|
|
29
32
|
export interface InteractionResponse {
|
|
30
33
|
readonly fundingTransaction: string | null;
|
|
@@ -32,6 +35,7 @@ export interface InteractionResponse {
|
|
|
32
35
|
readonly estimatedFees: bigint;
|
|
33
36
|
readonly nextUTXOs: UTXO[];
|
|
34
37
|
readonly fundingUTXOs: UTXO[];
|
|
38
|
+
readonly fundingInputUtxos: UTXO[];
|
|
35
39
|
readonly challenge: RawChallenge;
|
|
36
40
|
readonly interactionAddress: string | null;
|
|
37
41
|
readonly compiledTargetScript: string | null;
|
|
@@ -42,6 +46,7 @@ export interface BitcoinTransferResponse extends BitcoinTransferBase {
|
|
|
42
46
|
export interface CancelledTransaction {
|
|
43
47
|
readonly transaction: string;
|
|
44
48
|
readonly nextUTXOs: UTXO[];
|
|
49
|
+
readonly inputUtxos: UTXO[];
|
|
45
50
|
}
|
|
46
51
|
export declare class TransactionFactory {
|
|
47
52
|
debug: boolean;
|
|
@@ -50,7 +55,7 @@ export declare class TransactionFactory {
|
|
|
50
55
|
private readonly INITIAL_FUNDING_ESTIMATE;
|
|
51
56
|
private readonly MAX_ITERATIONS;
|
|
52
57
|
createCancellableTransaction(params: ICancelTransactionParameters | ICancelTransactionParametersWithoutSigner): Promise<CancelledTransaction>;
|
|
53
|
-
createCustomScriptTransaction(interactionParameters: ICustomTransactionParameters | ICustomTransactionWithoutSigner): Promise<[string, string, UTXO[]]>;
|
|
58
|
+
createCustomScriptTransaction(interactionParameters: ICustomTransactionParameters | ICustomTransactionWithoutSigner): Promise<[string, string, UTXO[], UTXO[]]>;
|
|
54
59
|
signInteraction(interactionParameters: IInteractionParameters | InteractionParametersWithoutSigner): Promise<InteractionResponse>;
|
|
55
60
|
signDeployment(deploymentParameters: IDeploymentParameters): Promise<DeploymentResult>;
|
|
56
61
|
createBTCTransfer(parameters: IFundingTransactionParameters): Promise<BitcoinTransferResponse>;
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.7.
|
|
1
|
+
export declare const version = "1.7.18";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.7.
|
|
1
|
+
export const version = '1.7.18';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Network } from '@btc-vision/bitcoin';
|
|
2
|
+
import { BinaryWriter } from '../buffer/BinaryWriter.js';
|
|
2
3
|
import { Feature, Features } from './Features.js';
|
|
3
4
|
export declare abstract class Generator {
|
|
4
5
|
static readonly DATA_CHUNK_SIZE: number;
|
|
@@ -12,7 +13,7 @@ export declare abstract class Generator {
|
|
|
12
13
|
getHeader(maxPriority: bigint, features?: Features[]): Buffer;
|
|
13
14
|
abstract compile(...args: unknown[]): Buffer;
|
|
14
15
|
protected splitBufferIntoChunks(buffer: Buffer, chunkSize?: number): Array<Buffer[]>;
|
|
15
|
-
protected encodeFeature(feature: Feature<Features
|
|
16
|
+
protected encodeFeature(feature: Feature<Features>, finalBuffer: BinaryWriter): void;
|
|
16
17
|
private encodeAccessListFeature;
|
|
17
18
|
private encodeChallengeSubmission;
|
|
18
19
|
private encodeLinkRequest;
|
|
@@ -38,22 +38,22 @@ export class Generator {
|
|
|
38
38
|
}
|
|
39
39
|
return chunks;
|
|
40
40
|
}
|
|
41
|
-
encodeFeature(feature) {
|
|
41
|
+
encodeFeature(feature, finalBuffer) {
|
|
42
42
|
switch (feature.opcode) {
|
|
43
43
|
case Features.ACCESS_LIST: {
|
|
44
|
-
return this.
|
|
44
|
+
return this.encodeAccessListFeature(feature, finalBuffer);
|
|
45
45
|
}
|
|
46
46
|
case Features.EPOCH_SUBMISSION: {
|
|
47
|
-
return this.
|
|
47
|
+
return this.encodeChallengeSubmission(feature, finalBuffer);
|
|
48
48
|
}
|
|
49
49
|
case Features.MLDSA_LINK_PUBKEY: {
|
|
50
|
-
return this.
|
|
50
|
+
return this.encodeLinkRequest(feature, finalBuffer);
|
|
51
51
|
}
|
|
52
52
|
default:
|
|
53
53
|
throw new Error(`Unknown feature type: ${feature.opcode}`);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
encodeAccessListFeature(feature) {
|
|
56
|
+
encodeAccessListFeature(feature, finalBuffer) {
|
|
57
57
|
const writer = new BinaryWriter();
|
|
58
58
|
writer.writeU16(Object.keys(feature.data).length);
|
|
59
59
|
for (const contract in feature.data) {
|
|
@@ -69,9 +69,9 @@ export class Generator {
|
|
|
69
69
|
writer.writeBytes(pointerBuffer);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
|
|
72
|
+
finalBuffer.writeBytesWithLength(Compressor.compress(Buffer.from(writer.getBuffer())));
|
|
73
73
|
}
|
|
74
|
-
encodeChallengeSubmission(feature) {
|
|
74
|
+
encodeChallengeSubmission(feature, finalBuffer) {
|
|
75
75
|
if ('verifySignature' in feature.data && !feature.data.verifySignature()) {
|
|
76
76
|
throw new Error('Invalid signature in challenge submission feature');
|
|
77
77
|
}
|
|
@@ -81,9 +81,9 @@ export class Generator {
|
|
|
81
81
|
if (feature.data.graffiti) {
|
|
82
82
|
writer.writeBytesWithLength(feature.data.graffiti);
|
|
83
83
|
}
|
|
84
|
-
|
|
84
|
+
finalBuffer.writeBytesWithLength(writer.getBuffer());
|
|
85
85
|
}
|
|
86
|
-
encodeLinkRequest(feature) {
|
|
86
|
+
encodeLinkRequest(feature, finalBuffer) {
|
|
87
87
|
const data = feature.data;
|
|
88
88
|
const writer = new BinaryWriter();
|
|
89
89
|
writer.writeU8(data.level);
|
|
@@ -100,7 +100,7 @@ export class Generator {
|
|
|
100
100
|
throw new Error('Legacy signature must be exactly 64 bytes');
|
|
101
101
|
}
|
|
102
102
|
writer.writeBytes(data.legacySignature);
|
|
103
|
-
|
|
103
|
+
finalBuffer.writeBytesWithLength(writer.getBuffer());
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
Generator.DATA_CHUNK_SIZE = 512;
|
|
@@ -2,6 +2,7 @@ import { crypto, networks, opcodes, script } from '@btc-vision/bitcoin';
|
|
|
2
2
|
import { Compressor } from '../../bytecode/Compressor.js';
|
|
3
3
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
4
4
|
import { Generator } from '../Generator.js';
|
|
5
|
+
import { BinaryWriter } from '../../buffer/BinaryWriter.js';
|
|
5
6
|
export class CalldataGenerator extends Generator {
|
|
6
7
|
constructor(senderPubKey, contractSaltPubKey, network = networks.bitcoin) {
|
|
7
8
|
super(senderPubKey, contractSaltPubKey, network);
|
|
@@ -32,15 +33,15 @@ export class CalldataGenerator extends Generator {
|
|
|
32
33
|
throw new Error('No data chunks found');
|
|
33
34
|
const featuresList = [];
|
|
34
35
|
const featureData = [];
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
if (featuresRaw && featuresRaw.length) {
|
|
37
|
+
const features = featuresRaw.sort((a, b) => a.priority - b.priority);
|
|
38
|
+
const finalBuffer = new BinaryWriter();
|
|
37
39
|
for (let i = 0; i < features.length; i++) {
|
|
38
40
|
const feature = features[i];
|
|
39
41
|
featuresList.push(feature.opcode);
|
|
40
|
-
|
|
41
|
-
featureData.push(...data);
|
|
42
|
-
featureData.push(opcodes.OP_0);
|
|
42
|
+
this.encodeFeature(feature, finalBuffer);
|
|
43
43
|
}
|
|
44
|
+
featureData.push(...this.splitBufferIntoChunks(Buffer.from(finalBuffer.getBuffer())));
|
|
44
45
|
}
|
|
45
46
|
let compiledData = [
|
|
46
47
|
this.getHeader(maxPriority, featuresList),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { crypto, networks, opcodes, script } from '@btc-vision/bitcoin';
|
|
2
2
|
import { Generator } from '../Generator.js';
|
|
3
|
+
import { BinaryWriter } from '../../buffer/BinaryWriter.js';
|
|
3
4
|
export const OPNET_DEPLOYMENT_VERSION = 0x00;
|
|
4
5
|
export const versionBuffer = Buffer.from([OPNET_DEPLOYMENT_VERSION]);
|
|
5
6
|
export class DeploymentGenerator extends Generator {
|
|
@@ -22,15 +23,15 @@ export class DeploymentGenerator extends Generator {
|
|
|
22
23
|
const calldataChunks = calldata ? this.splitBufferIntoChunks(calldata) : [];
|
|
23
24
|
const featuresList = [];
|
|
24
25
|
const featureData = [];
|
|
25
|
-
if (featuresRaw) {
|
|
26
|
+
if (featuresRaw && featuresRaw.length) {
|
|
26
27
|
const features = featuresRaw.sort((a, b) => a.priority - b.priority);
|
|
28
|
+
const finalBuffer = new BinaryWriter();
|
|
27
29
|
for (let i = 0; i < features.length; i++) {
|
|
28
30
|
const feature = features[i];
|
|
29
31
|
featuresList.push(feature.opcode);
|
|
30
|
-
|
|
31
|
-
featureData.push(...data);
|
|
32
|
-
featureData.push(opcodes.OP_0);
|
|
32
|
+
this.encodeFeature(feature, finalBuffer);
|
|
33
33
|
}
|
|
34
|
+
featureData.push(...this.splitBufferIntoChunks(Buffer.from(finalBuffer.getBuffer())));
|
|
34
35
|
}
|
|
35
36
|
const compiledData = [
|
|
36
37
|
this.getHeader(maxPriority, featuresList),
|
|
@@ -2,6 +2,7 @@ import { crypto, networks, opcodes, script } from '@btc-vision/bitcoin';
|
|
|
2
2
|
import { Compressor } from '../../bytecode/Compressor.js';
|
|
3
3
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
4
4
|
import { Generator } from '../Generator.js';
|
|
5
|
+
import { BinaryWriter } from '../../buffer/BinaryWriter.js';
|
|
5
6
|
export class LegacyCalldataGenerator extends Generator {
|
|
6
7
|
constructor(senderPubKey, network = networks.bitcoin) {
|
|
7
8
|
super(senderPubKey, Buffer.alloc(0), network);
|
|
@@ -30,15 +31,15 @@ export class LegacyCalldataGenerator extends Generator {
|
|
|
30
31
|
throw new Error('No data chunks found');
|
|
31
32
|
const featuresList = [];
|
|
32
33
|
const featureData = [];
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
if (featuresRaw && featuresRaw.length) {
|
|
35
|
+
const features = featuresRaw.sort((a, b) => a.priority - b.priority);
|
|
36
|
+
const finalBuffer = new BinaryWriter();
|
|
35
37
|
for (let i = 0; i < features.length; i++) {
|
|
36
38
|
const feature = features[i];
|
|
37
39
|
featuresList.push(feature.opcode);
|
|
38
|
-
|
|
39
|
-
featureData.push(...data);
|
|
40
|
-
featureData.push(opcodes.OP_0);
|
|
40
|
+
this.encodeFeature(feature, finalBuffer);
|
|
41
41
|
}
|
|
42
|
+
featureData.push(...this.splitBufferIntoChunks(Buffer.from(finalBuffer.getBuffer())));
|
|
42
43
|
}
|
|
43
44
|
let compiledData = [
|
|
44
45
|
this.getHeader(maxPriority, featuresList),
|
|
@@ -9,5 +9,4 @@ export declare class P2WDAGenerator extends Generator {
|
|
|
9
9
|
compile(calldata: Buffer, contractSecret: Buffer, challenge: ChallengeSolution, maxPriority: bigint, featuresRaw?: Feature<Features>[]): Buffer;
|
|
10
10
|
getHeader(maxPriority: bigint, features?: Features[]): Buffer;
|
|
11
11
|
private writeFeatures;
|
|
12
|
-
private encodeFeatureData;
|
|
13
12
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { networks } from '@btc-vision/bitcoin';
|
|
2
2
|
import { BinaryWriter } from '../../buffer/BinaryWriter.js';
|
|
3
|
-
import { Features } from '../Features.js';
|
|
4
3
|
import { Generator } from '../Generator.js';
|
|
5
4
|
export class P2WDAGenerator extends Generator {
|
|
6
5
|
constructor(senderPubKey, contractSaltPubKey, network = networks.bitcoin) {
|
|
@@ -40,23 +39,7 @@ export class P2WDAGenerator extends Generator {
|
|
|
40
39
|
writer.writeU16(features.length);
|
|
41
40
|
for (const feature of features) {
|
|
42
41
|
writer.writeU8(feature.opcode);
|
|
43
|
-
|
|
44
|
-
writer.writeU32(encodedData.length);
|
|
45
|
-
writer.writeBytes(encodedData);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
encodeFeatureData(feature) {
|
|
49
|
-
switch (feature.opcode) {
|
|
50
|
-
case Features.ACCESS_LIST: {
|
|
51
|
-
const chunks = this.encodeFeature(feature);
|
|
52
|
-
return Buffer.concat(chunks.flat());
|
|
53
|
-
}
|
|
54
|
-
case Features.EPOCH_SUBMISSION: {
|
|
55
|
-
const chunks = this.encodeFeature(feature);
|
|
56
|
-
return Buffer.concat(chunks.flat());
|
|
57
|
-
}
|
|
58
|
-
default:
|
|
59
|
-
throw new Error(`Unknown feature type: ${feature.opcode}`);
|
|
42
|
+
this.encodeFeature(feature, writer);
|
|
60
43
|
}
|
|
61
44
|
}
|
|
62
45
|
}
|
|
@@ -14,17 +14,20 @@ export interface DeploymentResult {
|
|
|
14
14
|
readonly contractPubKey: string;
|
|
15
15
|
readonly challenge: RawChallenge;
|
|
16
16
|
readonly utxos: UTXO[];
|
|
17
|
+
readonly inputUtxos: UTXO[];
|
|
17
18
|
}
|
|
18
19
|
export interface FundingTransactionResponse {
|
|
19
20
|
readonly tx: Transaction;
|
|
20
21
|
readonly original: FundingTransaction;
|
|
21
22
|
readonly estimatedFees: bigint;
|
|
22
23
|
readonly nextUTXOs: UTXO[];
|
|
24
|
+
readonly inputUtxos: UTXO[];
|
|
23
25
|
}
|
|
24
26
|
export interface BitcoinTransferBase {
|
|
25
27
|
readonly tx: string;
|
|
26
28
|
readonly estimatedFees: bigint;
|
|
27
29
|
readonly nextUTXOs: UTXO[];
|
|
30
|
+
readonly inputUtxos: UTXO[];
|
|
28
31
|
}
|
|
29
32
|
export interface InteractionResponse {
|
|
30
33
|
readonly fundingTransaction: string | null;
|
|
@@ -32,6 +35,7 @@ export interface InteractionResponse {
|
|
|
32
35
|
readonly estimatedFees: bigint;
|
|
33
36
|
readonly nextUTXOs: UTXO[];
|
|
34
37
|
readonly fundingUTXOs: UTXO[];
|
|
38
|
+
readonly fundingInputUtxos: UTXO[];
|
|
35
39
|
readonly challenge: RawChallenge;
|
|
36
40
|
readonly interactionAddress: string | null;
|
|
37
41
|
readonly compiledTargetScript: string | null;
|
|
@@ -42,6 +46,7 @@ export interface BitcoinTransferResponse extends BitcoinTransferBase {
|
|
|
42
46
|
export interface CancelledTransaction {
|
|
43
47
|
readonly transaction: string;
|
|
44
48
|
readonly nextUTXOs: UTXO[];
|
|
49
|
+
readonly inputUtxos: UTXO[];
|
|
45
50
|
}
|
|
46
51
|
export declare class TransactionFactory {
|
|
47
52
|
debug: boolean;
|
|
@@ -50,7 +55,7 @@ export declare class TransactionFactory {
|
|
|
50
55
|
private readonly INITIAL_FUNDING_ESTIMATE;
|
|
51
56
|
private readonly MAX_ITERATIONS;
|
|
52
57
|
createCancellableTransaction(params: ICancelTransactionParameters | ICancelTransactionParametersWithoutSigner): Promise<CancelledTransaction>;
|
|
53
|
-
createCustomScriptTransaction(interactionParameters: ICustomTransactionParameters | ICustomTransactionWithoutSigner): Promise<[string, string, UTXO[]]>;
|
|
58
|
+
createCustomScriptTransaction(interactionParameters: ICustomTransactionParameters | ICustomTransactionWithoutSigner): Promise<[string, string, UTXO[], UTXO[]]>;
|
|
54
59
|
signInteraction(interactionParameters: IInteractionParameters | InteractionParametersWithoutSigner): Promise<InteractionResponse>;
|
|
55
60
|
signDeployment(deploymentParameters: IDeploymentParameters): Promise<DeploymentResult>;
|
|
56
61
|
createBTCTransfer(parameters: IFundingTransactionParameters): Promise<BitcoinTransferResponse>;
|
|
@@ -14,10 +14,7 @@ export class TransactionFactory {
|
|
|
14
14
|
constructor() {
|
|
15
15
|
this.debug = false;
|
|
16
16
|
this.DUMMY_PUBKEY = Buffer.alloc(32, 1);
|
|
17
|
-
this.P2TR_SCRIPT = Buffer.concat([
|
|
18
|
-
Buffer.from([0x51, 0x20]),
|
|
19
|
-
this.DUMMY_PUBKEY,
|
|
20
|
-
]);
|
|
17
|
+
this.P2TR_SCRIPT = Buffer.concat([Buffer.from([0x51, 0x20]), this.DUMMY_PUBKEY]);
|
|
21
18
|
this.INITIAL_FUNDING_ESTIMATE = 2000n;
|
|
22
19
|
this.MAX_ITERATIONS = 10;
|
|
23
20
|
}
|
|
@@ -44,6 +41,7 @@ export class TransactionFactory {
|
|
|
44
41
|
return {
|
|
45
42
|
transaction: rawTx,
|
|
46
43
|
nextUTXOs: this.getUTXOAsTransaction(signed, params.from, 0),
|
|
44
|
+
inputUtxos: params.utxos,
|
|
47
45
|
};
|
|
48
46
|
}
|
|
49
47
|
async createCustomScriptTransaction(interactionParameters) {
|
|
@@ -101,6 +99,7 @@ export class TransactionFactory {
|
|
|
101
99
|
signedTransaction.tx.toHex(),
|
|
102
100
|
outTx.toHex(),
|
|
103
101
|
this.getUTXOAsTransaction(signedTransaction.tx, interactionParameters.from, 1),
|
|
102
|
+
interactionParameters.utxos,
|
|
104
103
|
];
|
|
105
104
|
}
|
|
106
105
|
async signInteraction(interactionParameters) {
|
|
@@ -174,6 +173,7 @@ export class TransactionFactory {
|
|
|
174
173
|
nextUTXOs: this.getUTXOAsTransaction(signedTransaction.tx, interactionParameters.from, 1),
|
|
175
174
|
challenge: challenge.toRaw(),
|
|
176
175
|
fundingUTXOs: fundingUTXO,
|
|
176
|
+
fundingInputUtxos: interactionParameters.utxos,
|
|
177
177
|
compiledTargetScript: interactionTx.exportCompiledTargetScript().toString('hex'),
|
|
178
178
|
};
|
|
179
179
|
}
|
|
@@ -254,6 +254,7 @@ export class TransactionFactory {
|
|
|
254
254
|
contractPubKey: deploymentTx.contractPubKey,
|
|
255
255
|
utxos: [refundUTXO],
|
|
256
256
|
challenge: challenge.toRaw(),
|
|
257
|
+
inputUtxos: deploymentParameters.utxos,
|
|
257
258
|
};
|
|
258
259
|
}
|
|
259
260
|
async createBTCTransfer(parameters) {
|
|
@@ -266,6 +267,7 @@ export class TransactionFactory {
|
|
|
266
267
|
original: resp.original,
|
|
267
268
|
tx: resp.tx.toHex(),
|
|
268
269
|
nextUTXOs: this.getAllNewUTXOs(resp.original, resp.tx, parameters.from),
|
|
270
|
+
inputUtxos: parameters.utxos,
|
|
269
271
|
};
|
|
270
272
|
}
|
|
271
273
|
getAllNewUTXOs(original, tx, to) {
|
|
@@ -314,7 +316,10 @@ export class TransactionFactory {
|
|
|
314
316
|
if (!interaction) {
|
|
315
317
|
throw new Error('Could not sign interaction transaction.');
|
|
316
318
|
}
|
|
317
|
-
return
|
|
319
|
+
return {
|
|
320
|
+
...interaction,
|
|
321
|
+
inputUtxos: interaction.inputUtxos ?? interactionParameters.utxos,
|
|
322
|
+
};
|
|
318
323
|
}
|
|
319
324
|
async detectInteractionOPWallet(interactionParameters) {
|
|
320
325
|
if (typeof window === 'undefined') {
|
|
@@ -332,7 +337,10 @@ export class TransactionFactory {
|
|
|
332
337
|
if (!interaction) {
|
|
333
338
|
throw new Error('Could not sign interaction transaction.');
|
|
334
339
|
}
|
|
335
|
-
return
|
|
340
|
+
return {
|
|
341
|
+
...interaction,
|
|
342
|
+
fundingInputUtxos: interaction.fundingInputUtxos ?? interactionParameters.utxos,
|
|
343
|
+
};
|
|
336
344
|
}
|
|
337
345
|
async detectDeploymentOPWallet(deploymentParameters) {
|
|
338
346
|
if (typeof window === 'undefined') {
|
|
@@ -350,7 +358,10 @@ export class TransactionFactory {
|
|
|
350
358
|
if (!deployment) {
|
|
351
359
|
throw new Error('Could not sign interaction transaction.');
|
|
352
360
|
}
|
|
353
|
-
return
|
|
361
|
+
return {
|
|
362
|
+
...deployment,
|
|
363
|
+
inputUtxos: deployment.inputUtxos ?? deploymentParameters.utxos,
|
|
364
|
+
};
|
|
354
365
|
}
|
|
355
366
|
async createFundTransaction(parameters) {
|
|
356
367
|
if (!parameters.to)
|
|
@@ -365,6 +376,7 @@ export class TransactionFactory {
|
|
|
365
376
|
original: fundingTransaction,
|
|
366
377
|
estimatedFees: fundingTransaction.estimatedFees,
|
|
367
378
|
nextUTXOs: this.getUTXOAsTransaction(signedTransaction, parameters.to, 0),
|
|
379
|
+
inputUtxos: parameters.utxos,
|
|
368
380
|
};
|
|
369
381
|
}
|
|
370
382
|
hasP2WDAInputs(utxos) {
|
|
@@ -398,6 +410,7 @@ export class TransactionFactory {
|
|
|
398
410
|
estimatedFees: p2wdaTransaction.estimatedFees,
|
|
399
411
|
nextUTXOs: this.getUTXOAsTransaction(signedTx, interactionParameters.from, signedTx.outs.length - 1),
|
|
400
412
|
fundingUTXOs: [...interactionParameters.utxos, ...inputs],
|
|
413
|
+
fundingInputUtxos: interactionParameters.utxos,
|
|
401
414
|
challenge: interactionParameters.challenge.toRaw(),
|
|
402
415
|
compiledTargetScript: null,
|
|
403
416
|
};
|
package/package.json
CHANGED
package/src/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.7.
|
|
1
|
+
export const version = '1.7.18';
|
|
@@ -105,29 +105,26 @@ export abstract class Generator {
|
|
|
105
105
|
return chunks;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
protected encodeFeature(feature: Feature<Features
|
|
108
|
+
protected encodeFeature(feature: Feature<Features>, finalBuffer: BinaryWriter): void {
|
|
109
109
|
switch (feature.opcode) {
|
|
110
110
|
case Features.ACCESS_LIST: {
|
|
111
|
-
return this.
|
|
112
|
-
this.encodeAccessListFeature(feature as AccessListFeature),
|
|
113
|
-
);
|
|
111
|
+
return this.encodeAccessListFeature(feature as AccessListFeature, finalBuffer);
|
|
114
112
|
}
|
|
115
113
|
case Features.EPOCH_SUBMISSION: {
|
|
116
|
-
return this.
|
|
117
|
-
|
|
114
|
+
return this.encodeChallengeSubmission(
|
|
115
|
+
feature as EpochSubmissionFeature,
|
|
116
|
+
finalBuffer,
|
|
118
117
|
);
|
|
119
118
|
}
|
|
120
119
|
case Features.MLDSA_LINK_PUBKEY: {
|
|
121
|
-
return this.
|
|
122
|
-
this.encodeLinkRequest(feature as MLDSALinkRequest),
|
|
123
|
-
);
|
|
120
|
+
return this.encodeLinkRequest(feature as MLDSALinkRequest, finalBuffer);
|
|
124
121
|
}
|
|
125
122
|
default:
|
|
126
123
|
throw new Error(`Unknown feature type: ${feature.opcode}`);
|
|
127
124
|
}
|
|
128
125
|
}
|
|
129
126
|
|
|
130
|
-
private encodeAccessListFeature(feature: AccessListFeature):
|
|
127
|
+
private encodeAccessListFeature(feature: AccessListFeature, finalBuffer: BinaryWriter): void {
|
|
131
128
|
const writer = new BinaryWriter();
|
|
132
129
|
|
|
133
130
|
writer.writeU16(Object.keys(feature.data).length);
|
|
@@ -150,10 +147,13 @@ export abstract class Generator {
|
|
|
150
147
|
}
|
|
151
148
|
}
|
|
152
149
|
|
|
153
|
-
|
|
150
|
+
finalBuffer.writeBytesWithLength(Compressor.compress(Buffer.from(writer.getBuffer())));
|
|
154
151
|
}
|
|
155
152
|
|
|
156
|
-
private encodeChallengeSubmission(
|
|
153
|
+
private encodeChallengeSubmission(
|
|
154
|
+
feature: EpochSubmissionFeature,
|
|
155
|
+
finalBuffer: BinaryWriter,
|
|
156
|
+
): void {
|
|
157
157
|
if ('verifySignature' in feature.data && !feature.data.verifySignature()) {
|
|
158
158
|
throw new Error('Invalid signature in challenge submission feature');
|
|
159
159
|
}
|
|
@@ -166,10 +166,10 @@ export abstract class Generator {
|
|
|
166
166
|
writer.writeBytesWithLength(feature.data.graffiti);
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
|
|
169
|
+
finalBuffer.writeBytesWithLength(writer.getBuffer());
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
private encodeLinkRequest(feature: MLDSALinkRequest):
|
|
172
|
+
private encodeLinkRequest(feature: MLDSALinkRequest, finalBuffer: BinaryWriter): void {
|
|
173
173
|
const data = feature.data;
|
|
174
174
|
|
|
175
175
|
const writer = new BinaryWriter();
|
|
@@ -194,6 +194,6 @@ export abstract class Generator {
|
|
|
194
194
|
|
|
195
195
|
writer.writeBytes(data.legacySignature);
|
|
196
196
|
|
|
197
|
-
|
|
197
|
+
finalBuffer.writeBytesWithLength(writer.getBuffer());
|
|
198
198
|
}
|
|
199
199
|
}
|
|
@@ -5,6 +5,7 @@ import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
|
5
5
|
import { Feature, Features } from '../Features.js';
|
|
6
6
|
import { Generator } from '../Generator.js';
|
|
7
7
|
import { ChallengeSolution } from '../../epoch/ChallengeSolution.js';
|
|
8
|
+
import { BinaryWriter } from '../../buffer/BinaryWriter.js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Class to generate bitcoin script for interaction transactions
|
|
@@ -78,18 +79,20 @@ export class CalldataGenerator extends Generator {
|
|
|
78
79
|
const featuresList: Features[] = [];
|
|
79
80
|
const featureData: (number | Buffer | Buffer[])[] = [];
|
|
80
81
|
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
if (featuresRaw && featuresRaw.length) {
|
|
83
|
+
const features: Feature<Features>[] = featuresRaw.sort(
|
|
84
|
+
(a, b) => a.priority - b.priority,
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const finalBuffer = new BinaryWriter();
|
|
83
88
|
for (let i = 0; i < features.length; i++) {
|
|
84
89
|
const feature = features[i];
|
|
85
90
|
featuresList.push(feature.opcode);
|
|
86
91
|
|
|
87
|
-
|
|
88
|
-
featureData.push(...data);
|
|
89
|
-
|
|
90
|
-
// Separator between features so decoder knows where each ends
|
|
91
|
-
featureData.push(opcodes.OP_0);
|
|
92
|
+
this.encodeFeature(feature, finalBuffer);
|
|
92
93
|
}
|
|
94
|
+
|
|
95
|
+
featureData.push(...this.splitBufferIntoChunks(Buffer.from(finalBuffer.getBuffer())));
|
|
93
96
|
}
|
|
94
97
|
|
|
95
98
|
let compiledData: (number | Buffer | Buffer[])[] = [
|
|
@@ -2,6 +2,7 @@ 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
4
|
import { ChallengeSolution } from '../../epoch/ChallengeSolution.js';
|
|
5
|
+
import { BinaryWriter } from '../../buffer/BinaryWriter.js';
|
|
5
6
|
|
|
6
7
|
export const OPNET_DEPLOYMENT_VERSION = 0x00;
|
|
7
8
|
export const versionBuffer = Buffer.from([OPNET_DEPLOYMENT_VERSION]);
|
|
@@ -71,21 +72,20 @@ export class DeploymentGenerator extends Generator {
|
|
|
71
72
|
const featuresList: Features[] = [];
|
|
72
73
|
const featureData: (number | Buffer | Buffer[])[] = [];
|
|
73
74
|
|
|
74
|
-
if (featuresRaw) {
|
|
75
|
+
if (featuresRaw && featuresRaw.length) {
|
|
75
76
|
const features: Feature<Features>[] = featuresRaw.sort(
|
|
76
77
|
(a, b) => a.priority - b.priority,
|
|
77
78
|
);
|
|
78
79
|
|
|
80
|
+
const finalBuffer = new BinaryWriter();
|
|
79
81
|
for (let i = 0; i < features.length; i++) {
|
|
80
82
|
const feature = features[i];
|
|
81
83
|
featuresList.push(feature.opcode);
|
|
82
84
|
|
|
83
|
-
|
|
84
|
-
featureData.push(...data);
|
|
85
|
-
|
|
86
|
-
// Separator between features so decoder knows where each ends
|
|
87
|
-
featureData.push(opcodes.OP_0);
|
|
85
|
+
this.encodeFeature(feature, finalBuffer);
|
|
88
86
|
}
|
|
87
|
+
|
|
88
|
+
featureData.push(...this.splitBufferIntoChunks(Buffer.from(finalBuffer.getBuffer())));
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
const compiledData = [
|
|
@@ -4,6 +4,7 @@ import { Compressor } from '../../bytecode/Compressor.js';
|
|
|
4
4
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
5
5
|
import { Generator } from '../Generator.js';
|
|
6
6
|
import { Feature, Features } from '../Features.js';
|
|
7
|
+
import { BinaryWriter } from '../../buffer/BinaryWriter.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Class to generate bitcoin script for interaction transactions
|
|
@@ -71,19 +72,21 @@ export class LegacyCalldataGenerator extends Generator {
|
|
|
71
72
|
|
|
72
73
|
const featuresList: Features[] = [];
|
|
73
74
|
const featureData: (number | Buffer | Buffer[])[] = [];
|
|
74
|
-
const features: Feature<Features>[] = featuresRaw.sort((a, b) => a.priority - b.priority);
|
|
75
75
|
|
|
76
|
-
if (
|
|
76
|
+
if (featuresRaw && featuresRaw.length) {
|
|
77
|
+
const features: Feature<Features>[] = featuresRaw.sort(
|
|
78
|
+
(a, b) => a.priority - b.priority,
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const finalBuffer = new BinaryWriter();
|
|
77
82
|
for (let i = 0; i < features.length; i++) {
|
|
78
83
|
const feature = features[i];
|
|
79
84
|
featuresList.push(feature.opcode);
|
|
80
85
|
|
|
81
|
-
|
|
82
|
-
featureData.push(...data);
|
|
83
|
-
|
|
84
|
-
// Separator between features so decoder knows where each ends
|
|
85
|
-
featureData.push(opcodes.OP_0);
|
|
86
|
+
this.encodeFeature(feature, finalBuffer);
|
|
86
87
|
}
|
|
88
|
+
|
|
89
|
+
featureData.push(...this.splitBufferIntoChunks(Buffer.from(finalBuffer.getBuffer())));
|
|
87
90
|
}
|
|
88
91
|
|
|
89
92
|
let compiledData = [
|