@btc-vision/transaction 1.7.18 → 1.7.22
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/LICENSE +190 -21
- package/README.md +1 -1
- package/browser/_version.d.ts +1 -1
- package/browser/generators/builders/HashCommitmentGenerator.d.ts +49 -0
- package/browser/index.js +1 -1
- package/browser/keypair/Address.d.ts +3 -1
- package/browser/opnet.d.ts +6 -1
- package/browser/signer/AddressRotation.d.ts +12 -0
- package/browser/transaction/TransactionFactory.d.ts +14 -0
- package/browser/transaction/builders/ConsolidatedInteractionTransaction.d.ts +44 -0
- package/browser/transaction/enums/TransactionType.d.ts +3 -1
- package/browser/transaction/interfaces/IConsolidatedTransactionParameters.d.ts +31 -0
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +2 -0
- package/browser/transaction/offline/OfflineTransactionManager.d.ts +69 -0
- package/browser/transaction/offline/TransactionReconstructor.d.ts +28 -0
- package/browser/transaction/offline/TransactionSerializer.d.ts +50 -0
- package/browser/transaction/offline/TransactionStateCapture.d.ts +52 -0
- package/browser/transaction/offline/index.d.ts +5 -0
- package/browser/transaction/offline/interfaces/ISerializableState.d.ts +62 -0
- package/browser/transaction/offline/interfaces/ITypeSpecificData.d.ts +62 -0
- package/browser/transaction/offline/interfaces/index.d.ts +2 -0
- package/browser/transaction/shared/TweakedTransaction.d.ts +12 -1
- package/browser/utxo/interfaces/IUTXO.d.ts +2 -0
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/generators/builders/HashCommitmentGenerator.d.ts +49 -0
- package/build/generators/builders/HashCommitmentGenerator.js +229 -0
- package/build/keypair/Address.d.ts +3 -1
- package/build/keypair/Address.js +87 -54
- package/build/opnet.d.ts +6 -1
- package/build/opnet.js +6 -1
- package/build/signer/AddressRotation.d.ts +12 -0
- package/build/signer/AddressRotation.js +16 -0
- package/build/transaction/TransactionFactory.d.ts +14 -0
- package/build/transaction/TransactionFactory.js +36 -0
- package/build/transaction/builders/ConsolidatedInteractionTransaction.d.ts +44 -0
- package/build/transaction/builders/ConsolidatedInteractionTransaction.js +259 -0
- package/build/transaction/builders/TransactionBuilder.js +2 -0
- package/build/transaction/enums/TransactionType.d.ts +3 -1
- package/build/transaction/enums/TransactionType.js +2 -0
- package/build/transaction/interfaces/IConsolidatedTransactionParameters.d.ts +31 -0
- package/build/transaction/interfaces/IConsolidatedTransactionParameters.js +1 -0
- package/build/transaction/interfaces/ITransactionParameters.d.ts +2 -0
- package/build/transaction/offline/OfflineTransactionManager.d.ts +69 -0
- package/build/transaction/offline/OfflineTransactionManager.js +255 -0
- package/build/transaction/offline/TransactionReconstructor.d.ts +28 -0
- package/build/transaction/offline/TransactionReconstructor.js +243 -0
- package/build/transaction/offline/TransactionSerializer.d.ts +50 -0
- package/build/transaction/offline/TransactionSerializer.js +700 -0
- package/build/transaction/offline/TransactionStateCapture.d.ts +52 -0
- package/build/transaction/offline/TransactionStateCapture.js +275 -0
- package/build/transaction/offline/index.d.ts +5 -0
- package/build/transaction/offline/index.js +5 -0
- package/build/transaction/offline/interfaces/ISerializableState.d.ts +62 -0
- package/build/transaction/offline/interfaces/ISerializableState.js +2 -0
- package/build/transaction/offline/interfaces/ITypeSpecificData.d.ts +62 -0
- package/build/transaction/offline/interfaces/ITypeSpecificData.js +19 -0
- package/build/transaction/offline/interfaces/index.d.ts +2 -0
- package/build/transaction/offline/interfaces/index.js +2 -0
- package/build/transaction/shared/TweakedTransaction.d.ts +12 -1
- package/build/transaction/shared/TweakedTransaction.js +75 -8
- package/build/utxo/interfaces/IUTXO.d.ts +2 -0
- package/documentation/README.md +5 -0
- package/documentation/offline-transaction-signing.md +650 -0
- package/documentation/transaction-building.md +603 -0
- package/package.json +2 -2
- package/src/_version.ts +1 -1
- package/src/generators/builders/HashCommitmentGenerator.ts +495 -0
- package/src/keypair/Address.ts +123 -70
- package/src/opnet.ts +8 -1
- package/src/signer/AddressRotation.ts +72 -0
- package/src/transaction/TransactionFactory.ts +94 -1
- package/src/transaction/builders/CancelTransaction.ts +4 -2
- package/src/transaction/builders/ConsolidatedInteractionTransaction.ts +568 -0
- package/src/transaction/builders/CustomScriptTransaction.ts +4 -2
- package/src/transaction/builders/MultiSignTransaction.ts +4 -2
- package/src/transaction/builders/TransactionBuilder.ts +8 -2
- package/src/transaction/enums/TransactionType.ts +2 -0
- package/src/transaction/interfaces/IConsolidatedTransactionParameters.ts +78 -0
- package/src/transaction/interfaces/ITransactionParameters.ts +8 -0
- package/src/transaction/offline/OfflineTransactionManager.ts +630 -0
- package/src/transaction/offline/TransactionReconstructor.ts +402 -0
- package/src/transaction/offline/TransactionSerializer.ts +920 -0
- package/src/transaction/offline/TransactionStateCapture.ts +469 -0
- package/src/transaction/offline/index.ts +8 -0
- package/src/transaction/offline/interfaces/ISerializableState.ts +141 -0
- package/src/transaction/offline/interfaces/ITypeSpecificData.ts +172 -0
- package/src/transaction/offline/interfaces/index.ts +2 -0
- package/src/transaction/shared/TweakedTransaction.ts +156 -9
- package/src/utxo/interfaces/IUTXO.ts +8 -0
- package/test/address-rotation.test.ts +553 -0
- package/test/offline-transaction.test.ts +2065 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { TransactionType } from '../enums/TransactionType.js';
|
|
2
|
+
import { ISerializableTransactionState, PrecomputedData } from './interfaces/ISerializableState.js';
|
|
3
|
+
import { IDeploymentParameters, IFundingTransactionParameters, IInteractionParameters, ITransactionParameters } from '../interfaces/ITransactionParameters.js';
|
|
4
|
+
export interface CaptureParams {
|
|
5
|
+
params: ITransactionParameters;
|
|
6
|
+
type: TransactionType;
|
|
7
|
+
precomputed?: Partial<PrecomputedData>;
|
|
8
|
+
}
|
|
9
|
+
export declare class TransactionStateCapture {
|
|
10
|
+
static fromFunding(params: IFundingTransactionParameters, precomputed?: Partial<PrecomputedData>): ISerializableTransactionState;
|
|
11
|
+
static fromDeployment(params: IDeploymentParameters, precomputed: Partial<PrecomputedData> & {
|
|
12
|
+
compiledTargetScript: string;
|
|
13
|
+
randomBytes: string;
|
|
14
|
+
}): ISerializableTransactionState;
|
|
15
|
+
static fromInteraction(params: IInteractionParameters, precomputed: Partial<PrecomputedData> & {
|
|
16
|
+
compiledTargetScript: string;
|
|
17
|
+
randomBytes: string;
|
|
18
|
+
}): ISerializableTransactionState;
|
|
19
|
+
static fromMultiSig(params: ITransactionParameters & {
|
|
20
|
+
pubkeys: Buffer[];
|
|
21
|
+
minimumSignatures: number;
|
|
22
|
+
receiver: string;
|
|
23
|
+
requestedAmount: bigint;
|
|
24
|
+
refundVault: string;
|
|
25
|
+
originalInputCount?: number;
|
|
26
|
+
existingPsbtBase64?: string;
|
|
27
|
+
}, precomputed?: Partial<PrecomputedData>): ISerializableTransactionState;
|
|
28
|
+
static fromCustomScript(params: ITransactionParameters & {
|
|
29
|
+
scriptElements: (Buffer | number)[];
|
|
30
|
+
witnesses: Buffer[];
|
|
31
|
+
annex?: Buffer;
|
|
32
|
+
}, precomputed?: Partial<PrecomputedData>): ISerializableTransactionState;
|
|
33
|
+
static fromCancel(params: ITransactionParameters & {
|
|
34
|
+
compiledTargetScript: Buffer | string;
|
|
35
|
+
}, precomputed?: Partial<PrecomputedData>): ISerializableTransactionState;
|
|
36
|
+
private static captureState;
|
|
37
|
+
private static createHeader;
|
|
38
|
+
private static extractBaseParams;
|
|
39
|
+
private static extractSignerMappings;
|
|
40
|
+
private static extractTypeSpecificData;
|
|
41
|
+
private static extractFundingData;
|
|
42
|
+
private static extractDeploymentData;
|
|
43
|
+
private static extractInteractionData;
|
|
44
|
+
private static extractMultiSigData;
|
|
45
|
+
private static extractCustomScriptData;
|
|
46
|
+
private static extractCancelData;
|
|
47
|
+
private static buildPrecomputedData;
|
|
48
|
+
private static serializeUTXOs;
|
|
49
|
+
private static serializeOutputs;
|
|
50
|
+
private static networkToName;
|
|
51
|
+
private static networkToChainId;
|
|
52
|
+
}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { ChainId } from '../../network/ChainId.js';
|
|
2
|
+
import { currentConsensus } from '../../consensus/ConsensusConfig.js';
|
|
3
|
+
import { TransactionType } from '../enums/TransactionType.js';
|
|
4
|
+
import { SERIALIZATION_FORMAT_VERSION, } from './interfaces/ISerializableState.js';
|
|
5
|
+
export class TransactionStateCapture {
|
|
6
|
+
static fromFunding(params, precomputed) {
|
|
7
|
+
return this.captureState({
|
|
8
|
+
params,
|
|
9
|
+
type: TransactionType.FUNDING,
|
|
10
|
+
precomputed,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
static fromDeployment(params, precomputed) {
|
|
14
|
+
return this.captureState({
|
|
15
|
+
params: params,
|
|
16
|
+
type: TransactionType.DEPLOYMENT,
|
|
17
|
+
precomputed,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
static fromInteraction(params, precomputed) {
|
|
21
|
+
return this.captureState({
|
|
22
|
+
params,
|
|
23
|
+
type: TransactionType.INTERACTION,
|
|
24
|
+
precomputed,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
static fromMultiSig(params, precomputed) {
|
|
28
|
+
return this.captureState({
|
|
29
|
+
params,
|
|
30
|
+
type: TransactionType.MULTI_SIG,
|
|
31
|
+
precomputed,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
static fromCustomScript(params, precomputed) {
|
|
35
|
+
return this.captureState({
|
|
36
|
+
params,
|
|
37
|
+
type: TransactionType.CUSTOM_CODE,
|
|
38
|
+
precomputed,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
static fromCancel(params, precomputed) {
|
|
42
|
+
return this.captureState({
|
|
43
|
+
params,
|
|
44
|
+
type: TransactionType.CANCEL,
|
|
45
|
+
precomputed,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
static captureState(capture) {
|
|
49
|
+
const { params, type, precomputed } = capture;
|
|
50
|
+
return {
|
|
51
|
+
header: this.createHeader(type, params.network, params.chainId),
|
|
52
|
+
baseParams: this.extractBaseParams(params),
|
|
53
|
+
utxos: this.serializeUTXOs(params.utxos),
|
|
54
|
+
optionalInputs: this.serializeUTXOs(params.optionalInputs || []),
|
|
55
|
+
optionalOutputs: this.serializeOutputs(params.optionalOutputs || []),
|
|
56
|
+
addressRotationEnabled: params.addressRotation?.enabled ?? false,
|
|
57
|
+
signerMappings: this.extractSignerMappings(params),
|
|
58
|
+
typeSpecificData: this.extractTypeSpecificData(type, params),
|
|
59
|
+
precomputedData: this.buildPrecomputedData(precomputed),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
static createHeader(type, network, chainId) {
|
|
63
|
+
return {
|
|
64
|
+
formatVersion: SERIALIZATION_FORMAT_VERSION,
|
|
65
|
+
consensusVersion: currentConsensus,
|
|
66
|
+
transactionType: type,
|
|
67
|
+
chainId: chainId ?? this.networkToChainId(network),
|
|
68
|
+
timestamp: Date.now(),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
static extractBaseParams(params) {
|
|
72
|
+
const note = params.note
|
|
73
|
+
? Buffer.isBuffer(params.note)
|
|
74
|
+
? params.note.toString('hex')
|
|
75
|
+
: Buffer.from(params.note).toString('hex')
|
|
76
|
+
: undefined;
|
|
77
|
+
const priorityFee = params.priorityFee ?? 0n;
|
|
78
|
+
const gasSatFee = params.gasSatFee ?? 0n;
|
|
79
|
+
return {
|
|
80
|
+
from: params.from || '',
|
|
81
|
+
to: params.to,
|
|
82
|
+
feeRate: params.feeRate,
|
|
83
|
+
priorityFee: priorityFee.toString(),
|
|
84
|
+
gasSatFee: gasSatFee.toString(),
|
|
85
|
+
networkName: this.networkToName(params.network),
|
|
86
|
+
txVersion: params.txVersion ?? 2,
|
|
87
|
+
note,
|
|
88
|
+
anchor: params.anchor ?? false,
|
|
89
|
+
debugFees: params.debugFees,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
static extractSignerMappings(params) {
|
|
93
|
+
if (!params.addressRotation?.enabled) {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
const mappings = [];
|
|
97
|
+
const addressToIndices = new Map();
|
|
98
|
+
params.utxos.forEach((utxo, index) => {
|
|
99
|
+
const address = utxo.scriptPubKey?.address;
|
|
100
|
+
if (address) {
|
|
101
|
+
const existing = addressToIndices.get(address);
|
|
102
|
+
if (existing) {
|
|
103
|
+
existing.push(index);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
addressToIndices.set(address, [index]);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const utxoCount = params.utxos.length;
|
|
111
|
+
(params.optionalInputs || []).forEach((utxo, index) => {
|
|
112
|
+
const address = utxo.scriptPubKey?.address;
|
|
113
|
+
if (address) {
|
|
114
|
+
const existing = addressToIndices.get(address);
|
|
115
|
+
if (existing) {
|
|
116
|
+
existing.push(utxoCount + index);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
addressToIndices.set(address, [utxoCount + index]);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
addressToIndices.forEach((indices, address) => {
|
|
124
|
+
mappings.push({ address, inputIndices: indices });
|
|
125
|
+
});
|
|
126
|
+
return mappings;
|
|
127
|
+
}
|
|
128
|
+
static extractTypeSpecificData(type, params) {
|
|
129
|
+
switch (type) {
|
|
130
|
+
case TransactionType.FUNDING:
|
|
131
|
+
return this.extractFundingData(params);
|
|
132
|
+
case TransactionType.DEPLOYMENT:
|
|
133
|
+
return this.extractDeploymentData(params);
|
|
134
|
+
case TransactionType.INTERACTION:
|
|
135
|
+
return this.extractInteractionData(params);
|
|
136
|
+
case TransactionType.MULTI_SIG:
|
|
137
|
+
return this.extractMultiSigData(params);
|
|
138
|
+
case TransactionType.CUSTOM_CODE:
|
|
139
|
+
return this.extractCustomScriptData(params);
|
|
140
|
+
case TransactionType.CANCEL:
|
|
141
|
+
return this.extractCancelData(params);
|
|
142
|
+
default:
|
|
143
|
+
throw new Error(`Unsupported transaction type: ${type}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
static extractFundingData(params) {
|
|
147
|
+
return {
|
|
148
|
+
type: TransactionType.FUNDING,
|
|
149
|
+
amount: params.amount.toString(),
|
|
150
|
+
splitInputsInto: params.splitInputsInto ?? 1,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
static extractDeploymentData(params) {
|
|
154
|
+
return {
|
|
155
|
+
type: TransactionType.DEPLOYMENT,
|
|
156
|
+
bytecode: params.bytecode.toString('hex'),
|
|
157
|
+
calldata: params.calldata?.toString('hex'),
|
|
158
|
+
challenge: params.challenge.toRaw(),
|
|
159
|
+
revealMLDSAPublicKey: params.revealMLDSAPublicKey,
|
|
160
|
+
linkMLDSAPublicKeyToAddress: params.linkMLDSAPublicKeyToAddress,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
static extractInteractionData(params) {
|
|
164
|
+
return {
|
|
165
|
+
type: TransactionType.INTERACTION,
|
|
166
|
+
calldata: params.calldata.toString('hex'),
|
|
167
|
+
contract: params.contract,
|
|
168
|
+
challenge: params.challenge.toRaw(),
|
|
169
|
+
loadedStorage: params.loadedStorage,
|
|
170
|
+
isCancellation: params.isCancellation,
|
|
171
|
+
disableAutoRefund: params.disableAutoRefund,
|
|
172
|
+
revealMLDSAPublicKey: params.revealMLDSAPublicKey,
|
|
173
|
+
linkMLDSAPublicKeyToAddress: params.linkMLDSAPublicKeyToAddress,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
static extractMultiSigData(params) {
|
|
177
|
+
return {
|
|
178
|
+
type: TransactionType.MULTI_SIG,
|
|
179
|
+
pubkeys: (params.pubkeys || []).map((pk) => pk.toString('hex')),
|
|
180
|
+
minimumSignatures: params.minimumSignatures || 0,
|
|
181
|
+
receiver: params.receiver || '',
|
|
182
|
+
requestedAmount: (params.requestedAmount || 0n).toString(),
|
|
183
|
+
refundVault: params.refundVault || '',
|
|
184
|
+
originalInputCount: params.originalInputCount || params.utxos.length,
|
|
185
|
+
existingPsbtBase64: params.existingPsbtBase64,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
static extractCustomScriptData(params) {
|
|
189
|
+
const scriptElements = (params.scriptElements || []).map((element) => {
|
|
190
|
+
if (Buffer.isBuffer(element)) {
|
|
191
|
+
return {
|
|
192
|
+
elementType: 'buffer',
|
|
193
|
+
value: element.toString('hex'),
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
return {
|
|
198
|
+
elementType: 'opcode',
|
|
199
|
+
value: element,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
return {
|
|
204
|
+
type: TransactionType.CUSTOM_CODE,
|
|
205
|
+
scriptElements,
|
|
206
|
+
witnesses: (params.witnesses || []).map((w) => w.toString('hex')),
|
|
207
|
+
annex: params.annex?.toString('hex'),
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
static extractCancelData(params) {
|
|
211
|
+
const script = params.compiledTargetScript;
|
|
212
|
+
const scriptHex = script ? (Buffer.isBuffer(script) ? script.toString('hex') : script) : '';
|
|
213
|
+
return {
|
|
214
|
+
type: TransactionType.CANCEL,
|
|
215
|
+
compiledTargetScript: scriptHex,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
static buildPrecomputedData(precomputed) {
|
|
219
|
+
return {
|
|
220
|
+
compiledTargetScript: precomputed?.compiledTargetScript,
|
|
221
|
+
randomBytes: precomputed?.randomBytes,
|
|
222
|
+
estimatedFees: precomputed?.estimatedFees,
|
|
223
|
+
contractSeed: precomputed?.contractSeed,
|
|
224
|
+
contractAddress: precomputed?.contractAddress,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
static serializeUTXOs(utxos) {
|
|
228
|
+
return utxos.map((utxo) => ({
|
|
229
|
+
transactionId: utxo.transactionId,
|
|
230
|
+
outputIndex: utxo.outputIndex,
|
|
231
|
+
value: utxo.value.toString(),
|
|
232
|
+
scriptPubKeyHex: utxo.scriptPubKey.hex,
|
|
233
|
+
scriptPubKeyAddress: utxo.scriptPubKey.address,
|
|
234
|
+
redeemScript: utxo.redeemScript
|
|
235
|
+
? Buffer.isBuffer(utxo.redeemScript)
|
|
236
|
+
? utxo.redeemScript.toString('hex')
|
|
237
|
+
: utxo.redeemScript
|
|
238
|
+
: undefined,
|
|
239
|
+
witnessScript: utxo.witnessScript
|
|
240
|
+
? Buffer.isBuffer(utxo.witnessScript)
|
|
241
|
+
? utxo.witnessScript.toString('hex')
|
|
242
|
+
: utxo.witnessScript
|
|
243
|
+
: undefined,
|
|
244
|
+
nonWitnessUtxo: utxo.nonWitnessUtxo
|
|
245
|
+
? Buffer.isBuffer(utxo.nonWitnessUtxo)
|
|
246
|
+
? utxo.nonWitnessUtxo.toString('hex')
|
|
247
|
+
: utxo.nonWitnessUtxo
|
|
248
|
+
: undefined,
|
|
249
|
+
}));
|
|
250
|
+
}
|
|
251
|
+
static serializeOutputs(outputs) {
|
|
252
|
+
return outputs.map((output) => {
|
|
253
|
+
const address = 'address' in output ? output.address : undefined;
|
|
254
|
+
const script = 'script' in output ? output.script : undefined;
|
|
255
|
+
return {
|
|
256
|
+
value: output.value,
|
|
257
|
+
address,
|
|
258
|
+
script: script ? script.toString('hex') : undefined,
|
|
259
|
+
tapInternalKey: output.tapInternalKey
|
|
260
|
+
? output.tapInternalKey.toString('hex')
|
|
261
|
+
: undefined,
|
|
262
|
+
};
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
static networkToName(network) {
|
|
266
|
+
if (network.bech32 === 'bc')
|
|
267
|
+
return 'mainnet';
|
|
268
|
+
if (network.bech32 === 'tb')
|
|
269
|
+
return 'testnet';
|
|
270
|
+
return 'regtest';
|
|
271
|
+
}
|
|
272
|
+
static networkToChainId(network) {
|
|
273
|
+
return ChainId.Bitcoin;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export * from './interfaces/index.js';
|
|
2
|
+
export { TransactionSerializer } from './TransactionSerializer.js';
|
|
3
|
+
export { TransactionStateCapture, CaptureParams } from './TransactionStateCapture.js';
|
|
4
|
+
export { TransactionReconstructor, ReconstructionOptions } from './TransactionReconstructor.js';
|
|
5
|
+
export { OfflineTransactionManager, ExportOptions } from './OfflineTransactionManager.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export * from './interfaces/index.js';
|
|
2
|
+
export { TransactionSerializer } from './TransactionSerializer.js';
|
|
3
|
+
export { TransactionStateCapture } from './TransactionStateCapture.js';
|
|
4
|
+
export { TransactionReconstructor } from './TransactionReconstructor.js';
|
|
5
|
+
export { OfflineTransactionManager } from './OfflineTransactionManager.js';
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { TransactionType } from '../../enums/TransactionType.js';
|
|
2
|
+
import { ChainId } from '../../../network/ChainId.js';
|
|
3
|
+
import { TypeSpecificData } from './ITypeSpecificData.js';
|
|
4
|
+
export declare const SERIALIZATION_FORMAT_VERSION = 1;
|
|
5
|
+
export declare const SERIALIZATION_MAGIC_BYTE = 66;
|
|
6
|
+
export interface SerializationHeader {
|
|
7
|
+
readonly formatVersion: number;
|
|
8
|
+
readonly consensusVersion: number;
|
|
9
|
+
readonly transactionType: TransactionType;
|
|
10
|
+
readonly chainId: ChainId;
|
|
11
|
+
readonly timestamp: number;
|
|
12
|
+
}
|
|
13
|
+
export interface SerializedUTXO {
|
|
14
|
+
readonly transactionId: string;
|
|
15
|
+
readonly outputIndex: number;
|
|
16
|
+
readonly value: string;
|
|
17
|
+
readonly scriptPubKeyHex: string;
|
|
18
|
+
readonly scriptPubKeyAddress?: string;
|
|
19
|
+
readonly redeemScript?: string;
|
|
20
|
+
readonly witnessScript?: string;
|
|
21
|
+
readonly nonWitnessUtxo?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface SerializedOutput {
|
|
24
|
+
readonly value: number;
|
|
25
|
+
readonly address?: string;
|
|
26
|
+
readonly script?: string;
|
|
27
|
+
readonly tapInternalKey?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface SerializedSignerMapping {
|
|
30
|
+
readonly address: string;
|
|
31
|
+
readonly inputIndices: number[];
|
|
32
|
+
}
|
|
33
|
+
export interface SerializedBaseParams {
|
|
34
|
+
readonly from: string;
|
|
35
|
+
readonly to?: string;
|
|
36
|
+
readonly feeRate: number;
|
|
37
|
+
readonly priorityFee: string;
|
|
38
|
+
readonly gasSatFee: string;
|
|
39
|
+
readonly networkName: 'mainnet' | 'testnet' | 'regtest';
|
|
40
|
+
readonly txVersion: number;
|
|
41
|
+
readonly note?: string;
|
|
42
|
+
readonly anchor: boolean;
|
|
43
|
+
readonly debugFees?: boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface PrecomputedData {
|
|
46
|
+
readonly compiledTargetScript?: string;
|
|
47
|
+
readonly randomBytes?: string;
|
|
48
|
+
readonly estimatedFees?: string;
|
|
49
|
+
readonly contractSeed?: string;
|
|
50
|
+
readonly contractAddress?: string;
|
|
51
|
+
}
|
|
52
|
+
export interface ISerializableTransactionState {
|
|
53
|
+
readonly header: SerializationHeader;
|
|
54
|
+
readonly baseParams: SerializedBaseParams;
|
|
55
|
+
readonly utxos: SerializedUTXO[];
|
|
56
|
+
readonly optionalInputs: SerializedUTXO[];
|
|
57
|
+
readonly optionalOutputs: SerializedOutput[];
|
|
58
|
+
readonly addressRotationEnabled: boolean;
|
|
59
|
+
readonly signerMappings: SerializedSignerMapping[];
|
|
60
|
+
readonly typeSpecificData: TypeSpecificData;
|
|
61
|
+
readonly precomputedData: PrecomputedData;
|
|
62
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { TransactionType } from '../../enums/TransactionType.js';
|
|
2
|
+
import { RawChallenge } from '../../../epoch/interfaces/IChallengeSolution.js';
|
|
3
|
+
export type TypeSpecificData = FundingSpecificData | DeploymentSpecificData | InteractionSpecificData | MultiSigSpecificData | CustomScriptSpecificData | CancelSpecificData;
|
|
4
|
+
export interface FundingSpecificData {
|
|
5
|
+
readonly type: TransactionType.FUNDING;
|
|
6
|
+
readonly amount: string;
|
|
7
|
+
readonly splitInputsInto: number;
|
|
8
|
+
}
|
|
9
|
+
export interface DeploymentSpecificData {
|
|
10
|
+
readonly type: TransactionType.DEPLOYMENT;
|
|
11
|
+
readonly bytecode: string;
|
|
12
|
+
readonly calldata?: string;
|
|
13
|
+
readonly challenge: RawChallenge;
|
|
14
|
+
readonly revealMLDSAPublicKey?: boolean;
|
|
15
|
+
readonly linkMLDSAPublicKeyToAddress?: boolean;
|
|
16
|
+
readonly hashedPublicKey?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface InteractionSpecificData {
|
|
19
|
+
readonly type: TransactionType.INTERACTION;
|
|
20
|
+
readonly calldata: string;
|
|
21
|
+
readonly contract?: string;
|
|
22
|
+
readonly challenge: RawChallenge;
|
|
23
|
+
readonly loadedStorage?: SerializedLoadedStorage;
|
|
24
|
+
readonly isCancellation?: boolean;
|
|
25
|
+
readonly disableAutoRefund?: boolean;
|
|
26
|
+
readonly revealMLDSAPublicKey?: boolean;
|
|
27
|
+
readonly linkMLDSAPublicKeyToAddress?: boolean;
|
|
28
|
+
readonly hashedPublicKey?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface SerializedLoadedStorage {
|
|
31
|
+
[key: string]: string[];
|
|
32
|
+
}
|
|
33
|
+
export interface MultiSigSpecificData {
|
|
34
|
+
readonly type: TransactionType.MULTI_SIG;
|
|
35
|
+
readonly pubkeys: string[];
|
|
36
|
+
readonly minimumSignatures: number;
|
|
37
|
+
readonly receiver: string;
|
|
38
|
+
readonly requestedAmount: string;
|
|
39
|
+
readonly refundVault: string;
|
|
40
|
+
readonly originalInputCount: number;
|
|
41
|
+
readonly existingPsbtBase64?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface SerializedScriptElement {
|
|
44
|
+
readonly elementType: 'buffer' | 'opcode';
|
|
45
|
+
readonly value: string | number;
|
|
46
|
+
}
|
|
47
|
+
export interface CustomScriptSpecificData {
|
|
48
|
+
readonly type: TransactionType.CUSTOM_CODE;
|
|
49
|
+
readonly scriptElements: SerializedScriptElement[];
|
|
50
|
+
readonly witnesses: string[];
|
|
51
|
+
readonly annex?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface CancelSpecificData {
|
|
54
|
+
readonly type: TransactionType.CANCEL;
|
|
55
|
+
readonly compiledTargetScript: string;
|
|
56
|
+
}
|
|
57
|
+
export declare function isFundingSpecificData(data: TypeSpecificData): data is FundingSpecificData;
|
|
58
|
+
export declare function isDeploymentSpecificData(data: TypeSpecificData): data is DeploymentSpecificData;
|
|
59
|
+
export declare function isInteractionSpecificData(data: TypeSpecificData): data is InteractionSpecificData;
|
|
60
|
+
export declare function isMultiSigSpecificData(data: TypeSpecificData): data is MultiSigSpecificData;
|
|
61
|
+
export declare function isCustomScriptSpecificData(data: TypeSpecificData): data is CustomScriptSpecificData;
|
|
62
|
+
export declare function isCancelSpecificData(data: TypeSpecificData): data is CancelSpecificData;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TransactionType } from '../../enums/TransactionType.js';
|
|
2
|
+
export function isFundingSpecificData(data) {
|
|
3
|
+
return data.type === TransactionType.FUNDING;
|
|
4
|
+
}
|
|
5
|
+
export function isDeploymentSpecificData(data) {
|
|
6
|
+
return data.type === TransactionType.DEPLOYMENT;
|
|
7
|
+
}
|
|
8
|
+
export function isInteractionSpecificData(data) {
|
|
9
|
+
return data.type === TransactionType.INTERACTION;
|
|
10
|
+
}
|
|
11
|
+
export function isMultiSigSpecificData(data) {
|
|
12
|
+
return data.type === TransactionType.MULTI_SIG;
|
|
13
|
+
}
|
|
14
|
+
export function isCustomScriptSpecificData(data) {
|
|
15
|
+
return data.type === TransactionType.CUSTOM_CODE;
|
|
16
|
+
}
|
|
17
|
+
export function isCancelSpecificData(data) {
|
|
18
|
+
return data.type === TransactionType.CANCEL;
|
|
19
|
+
}
|
|
@@ -7,6 +7,7 @@ import { ChainId } from '../../network/ChainId.js';
|
|
|
7
7
|
import { UnisatSigner } from '../browser/extensions/UnisatSigner.js';
|
|
8
8
|
import { Buffer } from 'buffer';
|
|
9
9
|
import { QuantumBIP32Interface } from '@btc-vision/bip32';
|
|
10
|
+
import { AddressRotationConfig, RotationSigner, SignerMap } from '../../signer/AddressRotation.js';
|
|
10
11
|
export type SupportedTransactionVersion = 1 | 2 | 3;
|
|
11
12
|
export interface ITweakedTransactionData {
|
|
12
13
|
readonly mldsaSigner: QuantumBIP32Interface | null;
|
|
@@ -17,6 +18,7 @@ export interface ITweakedTransactionData {
|
|
|
17
18
|
readonly noSignatures?: boolean;
|
|
18
19
|
readonly unlockScript?: Buffer[];
|
|
19
20
|
readonly txVersion?: SupportedTransactionVersion;
|
|
21
|
+
readonly addressRotation?: AddressRotationConfig;
|
|
20
22
|
}
|
|
21
23
|
export declare enum TransactionSequence {
|
|
22
24
|
REPLACE_BY_FEE = 4294967293,
|
|
@@ -51,6 +53,10 @@ export declare abstract class TweakedTransaction extends Logger {
|
|
|
51
53
|
protected txVersion: SupportedTransactionVersion;
|
|
52
54
|
protected readonly _mldsaSigner: QuantumBIP32Interface | null;
|
|
53
55
|
protected readonly _hashedPublicKey: Buffer | null;
|
|
56
|
+
protected readonly addressRotationEnabled: boolean;
|
|
57
|
+
protected readonly signerMap: SignerMap;
|
|
58
|
+
protected readonly inputSignerMap: Map<number, RotationSigner>;
|
|
59
|
+
protected readonly tweakedSignerCache: Map<number, ECPairInterface | undefined>;
|
|
54
60
|
protected constructor(data: ITweakedTransactionData);
|
|
55
61
|
protected get mldsaSigner(): QuantumBIP32Interface;
|
|
56
62
|
protected get hashedPublicKey(): Buffer;
|
|
@@ -58,6 +64,7 @@ export declare abstract class TweakedTransaction extends Logger {
|
|
|
58
64
|
static preEstimateTaprootTransactionFees(feeRate: bigint, numInputs: bigint, numOutputs: bigint, numWitnessElements: bigint, witnessElementSize: bigint, emptyWitness: bigint, taprootControlWitnessSize?: bigint, taprootScriptSize?: bigint): bigint;
|
|
59
65
|
protected static signInput(transaction: Psbt, input: PsbtInput, i: number, signer: Signer | ECPairInterface, sighashTypes: number[]): void;
|
|
60
66
|
protected static calculateSignHash(sighashTypes: number[]): number;
|
|
67
|
+
isAddressRotationEnabled(): boolean;
|
|
61
68
|
ignoreSignatureError(): void;
|
|
62
69
|
getScriptAddress(): string;
|
|
63
70
|
getTransaction(): Transaction;
|
|
@@ -65,6 +72,10 @@ export declare abstract class TweakedTransaction extends Logger {
|
|
|
65
72
|
disableRBF(): void;
|
|
66
73
|
getTweakerHash(): Buffer | undefined;
|
|
67
74
|
preEstimateTransactionFees(feeRate: bigint, numInputs: bigint, numOutputs: bigint, numSignatures: bigint, numPubkeys: bigint): bigint;
|
|
75
|
+
protected getSignerForInput(inputIndex: number): RotationSigner;
|
|
76
|
+
protected registerInputSigner(inputIndex: number, utxo: UTXO): void;
|
|
77
|
+
protected internalPubKeyToXOnlyForInput(inputIndex: number): Buffer;
|
|
78
|
+
protected getTweakedSignerForInput(inputIndex: number, useTweakedHash?: boolean): ECPairInterface | undefined;
|
|
68
79
|
protected generateTapData(): P2TRPayment;
|
|
69
80
|
protected generateScriptAddress(): P2TRPayment;
|
|
70
81
|
protected getSignerKey(): Signer | ECPairInterface;
|
|
@@ -81,7 +92,7 @@ export declare abstract class TweakedTransaction extends Logger {
|
|
|
81
92
|
redeemScript: Buffer;
|
|
82
93
|
outputScript: Buffer;
|
|
83
94
|
} | undefined;
|
|
84
|
-
protected generateP2SHP2PKHRedeemScript(inputAddr: string): {
|
|
95
|
+
protected generateP2SHP2PKHRedeemScript(inputAddr: string, inputIndex?: number): {
|
|
85
96
|
redeemScript: Buffer;
|
|
86
97
|
outputScript: Buffer;
|
|
87
98
|
} | undefined;
|