@opcat-labs/scrypt-ts-opcat 2.1.2 → 2.1.3
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/assets/.templates/smart-contract/builtin-libs/backtrace.scrypt.tpl +1 -1
- package/assets/.templates/smart-contract/builtin-libs/genesis.scrypt.tpl +2 -2
- package/assets/smart-contract/builtin-libs/backtrace.scrypt +14 -14
- package/assets/smart-contract/builtin-libs/byteStringReader.scrypt +5 -5
- package/assets/smart-contract/builtin-libs/byteStringWriter.scrypt +6 -6
- package/assets/smart-contract/builtin-libs/contextUtils.scrypt +16 -16
- package/assets/smart-contract/builtin-libs/genesis.scrypt +8 -8
- package/assets/smart-contract/builtin-libs/p2pk.scrypt +1 -1
- package/assets/smart-contract/builtin-libs/p2pkh.scrypt +1 -1
- package/assets/smart-contract/builtin-libs/stateLib.scrypt +1 -1
- package/assets/smart-contract/builtin-libs/stateUtils.scrypt +1 -1
- package/assets/smart-contract/builtin-libs/stdUtils.scrypt +12 -12
- package/assets/smart-contract/builtin-libs/txHashPreimageUtils.scrypt +7 -7
- package/assets/smart-contract/builtin-libs/txUtils.scrypt +12 -12
- package/assets/smart-contract/types/structs.scrypt +8 -8
- package/dist/cjs/smart-contract/abstractContract.js.map +1 -1
- package/dist/cjs/smart-contract/builtin-libs/backtrace.cjs +1 -1
- package/dist/cjs/smart-contract/builtin-libs/genesis.cjs +106 -13
- package/dist/cjs/smart-contract/builtin-libs/genesis.js.map +1 -1
- package/dist/cjs/smart-contract/methods/checkDataSig.cjs +55 -0
- package/dist/cjs/smart-contract/methods/checkDataSig.js.map +1 -0
- package/dist/cjs/smart-contract/methods/checkSHPreimage.cjs +33 -2
- package/dist/cjs/smart-contract/methods/checkSHPreimage.js.map +1 -1
- package/dist/cjs/smart-contract/smartContract.cjs +36 -0
- package/dist/cjs/smart-contract/smartContract.js.map +1 -1
- package/dist/cjs/utils/index.cjs +7 -1
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/sigUtils.cjs +171 -0
- package/dist/cjs/utils/sigUtils.js.map +1 -0
- package/dist/esm/smart-contract/abstractContract.js.map +1 -1
- package/dist/esm/smart-contract/builtin-libs/backtrace.js +1 -1
- package/dist/esm/smart-contract/builtin-libs/genesis.js +106 -13
- package/dist/esm/smart-contract/builtin-libs/genesis.js.map +1 -1
- package/dist/esm/smart-contract/methods/checkDataSig.js +51 -0
- package/dist/esm/smart-contract/methods/checkDataSig.js.map +1 -0
- package/dist/esm/smart-contract/methods/checkSHPreimage.js +34 -3
- package/dist/esm/smart-contract/methods/checkSHPreimage.js.map +1 -1
- package/dist/esm/smart-contract/smartContract.js +36 -0
- package/dist/esm/smart-contract/smartContract.js.map +1 -1
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/sigUtils.js +162 -0
- package/dist/esm/utils/sigUtils.js.map +1 -0
- package/dist/types/smart-contract/abstractContract.d.ts +16 -0
- package/dist/types/smart-contract/abstractContract.d.ts.map +1 -1
- package/dist/types/smart-contract/methods/checkDataSig.d.ts +22 -0
- package/dist/types/smart-contract/methods/checkDataSig.d.ts.map +1 -0
- package/dist/types/smart-contract/methods/checkSHPreimage.d.ts +9 -0
- package/dist/types/smart-contract/methods/checkSHPreimage.d.ts.map +1 -1
- package/dist/types/smart-contract/smartContract.d.ts +22 -0
- package/dist/types/smart-contract/smartContract.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/sigUtils.d.ts +106 -0
- package/dist/types/utils/sigUtils.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/smart-contract/builtin-libs/backtrace.ts +1 -1
- package/src/smart-contract/builtin-libs/genesis.ts +106 -13
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Off-chain signing utilities for preimage verification.
|
|
4
|
+
*
|
|
5
|
+
* This module provides functions to generate signatures off-chain using a
|
|
6
|
+
* hardcoded private key. The signatures can then be verified on-chain using
|
|
7
|
+
* checkDataSig, avoiding the need for on-chain signature generation which
|
|
8
|
+
* bloats script size.
|
|
9
|
+
*
|
|
10
|
+
* @module sigUtils
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.verifyPreimageSig = exports.signSHPreimageForCheckDataSig = exports.signData = exports.signDataWithInternalKey = exports.signSHPreimage = exports.signPreimage = void 0;
|
|
14
|
+
const opcat_1 = require("@opcat-labs/opcat");
|
|
15
|
+
const hashes_js_1 = require('../smart-contract/fns/hashes.cjs');
|
|
16
|
+
const primitives_js_1 = require('../smart-contract/types/primitives.cjs');
|
|
17
|
+
const contextUtils_js_1 = require('../smart-contract/builtin-libs/contextUtils.cjs');
|
|
18
|
+
const preimage_js_1 = require('./preimage.cjs');
|
|
19
|
+
const { ECDSA, Signature } = opcat_1.crypto;
|
|
20
|
+
/**
|
|
21
|
+
* The internal private key derived from ContextUtils.privKey.
|
|
22
|
+
* This ensures consistency between off-chain signing and on-chain verification.
|
|
23
|
+
*/
|
|
24
|
+
const INTERNAL_KEY = opcat_1.PrivateKey.fromHex(contextUtils_js_1.ContextUtils.privKey.toString(16).padStart(64, '0'), opcat_1.Networks.defaultNetwork);
|
|
25
|
+
/**
|
|
26
|
+
* Signs a serialized preimage off-chain using the internal private key (from ContextUtils).
|
|
27
|
+
*
|
|
28
|
+
* This function generates a DER-encoded ECDSA signature that can be verified
|
|
29
|
+
* on-chain using checkSig. The message is hashed with hash256 (double SHA256)
|
|
30
|
+
* to match the transaction interpreter's sighash calculation.
|
|
31
|
+
*
|
|
32
|
+
* Note: For checkDataSig (which uses single SHA256), a different signature
|
|
33
|
+
* would be needed. The JavaScript runtime uses this hash256 version for
|
|
34
|
+
* compatibility with checkSig verification.
|
|
35
|
+
*
|
|
36
|
+
* @param preimage - The serialized preimage bytes to sign
|
|
37
|
+
* @param sigHashType - The signature hash type (default: 0x01 for SIGHASH_ALL)
|
|
38
|
+
* @returns A DER-encoded signature with sigHashType appended
|
|
39
|
+
*/
|
|
40
|
+
function signPreimage(preimage, sigHashType = 0x01) {
|
|
41
|
+
// Compute hash256 of the preimage (double SHA256 for checkSig compatibility)
|
|
42
|
+
// Reverse the hash to match checkSigImpl's verification format
|
|
43
|
+
const hash = Buffer.from((0, hashes_js_1.hash256)(preimage), 'hex').reverse();
|
|
44
|
+
// Sign the hash using ECDSA with internal key
|
|
45
|
+
const signature = ECDSA.sign(hash, INTERNAL_KEY, 'little');
|
|
46
|
+
// Get DER encoded signature
|
|
47
|
+
const derSig = signature.toDER();
|
|
48
|
+
// Append sigHashType byte
|
|
49
|
+
const sigHashTypeByte = Buffer.from([sigHashType]);
|
|
50
|
+
const fullSig = Buffer.concat([derSig, sigHashTypeByte]);
|
|
51
|
+
return (0, primitives_js_1.Sig)(fullSig.toString('hex'));
|
|
52
|
+
}
|
|
53
|
+
exports.signPreimage = signPreimage;
|
|
54
|
+
/**
|
|
55
|
+
* Signs a SHPreimage off-chain by first serializing it.
|
|
56
|
+
*
|
|
57
|
+
* This is a convenience wrapper around signPreimage that handles
|
|
58
|
+
* the serialization of the SHPreimage struct.
|
|
59
|
+
*
|
|
60
|
+
* Note: Uses encodeSHPreimage (same as checkSigImpl) to ensure
|
|
61
|
+
* the signature matches what checkSig expects.
|
|
62
|
+
*
|
|
63
|
+
* @param shPreimage - The SHPreimage struct to sign
|
|
64
|
+
* @param sigHashType - The signature hash type (default: 0x01 for SIGHASH_ALL).
|
|
65
|
+
* Should match shPreimage.sigHashType for verification to succeed.
|
|
66
|
+
* @returns A DER-encoded signature with sigHashType appended
|
|
67
|
+
*/
|
|
68
|
+
function signSHPreimage(shPreimage, sigHashType = 0x01) {
|
|
69
|
+
// Serialize the SHPreimage using encodeSHPreimage (same as checkSigImpl uses)
|
|
70
|
+
const preimage = (0, preimage_js_1.encodeSHPreimage)(shPreimage);
|
|
71
|
+
return signPreimage(preimage, sigHashType);
|
|
72
|
+
}
|
|
73
|
+
exports.signSHPreimage = signSHPreimage;
|
|
74
|
+
/**
|
|
75
|
+
* Signs arbitrary data off-chain using the internal key (ContextUtils.privKey).
|
|
76
|
+
*
|
|
77
|
+
* This function generates a pure DER-encoded ECDSA signature (NO sighash type)
|
|
78
|
+
* that can be verified on-chain using checkDataSig. The message is hashed with
|
|
79
|
+
* single SHA256 to match OP_CHECKSIGFROMSTACK behavior.
|
|
80
|
+
*
|
|
81
|
+
* Note: This uses the internal key from ContextUtils. For signing with
|
|
82
|
+
* a custom private key (e.g., Oracle scenarios), use signData() instead.
|
|
83
|
+
*
|
|
84
|
+
* @param message - The message bytes to sign
|
|
85
|
+
* @returns A pure DER-encoded signature (no sighash type appended)
|
|
86
|
+
*/
|
|
87
|
+
function signDataWithInternalKey(message) {
|
|
88
|
+
return signData(INTERNAL_KEY, message);
|
|
89
|
+
}
|
|
90
|
+
exports.signDataWithInternalKey = signDataWithInternalKey;
|
|
91
|
+
/**
|
|
92
|
+
* Signs arbitrary data with a custom private key for use with checkDataSig (OP_CHECKSIGFROMSTACK).
|
|
93
|
+
*
|
|
94
|
+
* This function generates a pure DER-encoded ECDSA signature (NO sighash type)
|
|
95
|
+
* that can be verified on-chain using checkDataSig. The message is hashed with
|
|
96
|
+
* single SHA256 to match OP_CHECKSIGFROMSTACK behavior.
|
|
97
|
+
*
|
|
98
|
+
* Use this method for Oracle scenarios where you need to sign data with a specific
|
|
99
|
+
* private key that the contract will verify against.
|
|
100
|
+
*
|
|
101
|
+
* @param privateKey - The private key to sign with
|
|
102
|
+
* @param message - The message bytes to sign
|
|
103
|
+
* @returns A pure DER-encoded signature (no sighash type appended)
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* // Oracle signs price data
|
|
108
|
+
* const oraclePrivKey = PrivateKey.fromWIF('...');
|
|
109
|
+
* const priceData = toByteString('BTC/USD:50000', true);
|
|
110
|
+
* const sig = signData(oraclePrivKey, priceData);
|
|
111
|
+
*
|
|
112
|
+
* // Contract verifies using checkDataSig
|
|
113
|
+
* // assert(this.checkDataSig(sig, priceData, oraclePubKey));
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
function signData(privateKey, message) {
|
|
117
|
+
// Compute single SHA256 of the message for checkDataSig compatibility
|
|
118
|
+
// Reverse the hash for little-endian format (same as OP_CHECKSIGFROMSTACK)
|
|
119
|
+
const hash = Buffer.from((0, hashes_js_1.sha256)(message), 'hex').reverse();
|
|
120
|
+
// Sign the hash using ECDSA
|
|
121
|
+
const signature = ECDSA.sign(hash, privateKey, 'little');
|
|
122
|
+
// Get pure DER encoded signature (NO sighash type for OP_CHECKSIGFROMSTACK)
|
|
123
|
+
const derSig = signature.toDER();
|
|
124
|
+
return (0, primitives_js_1.Sig)(derSig.toString('hex'));
|
|
125
|
+
}
|
|
126
|
+
exports.signData = signData;
|
|
127
|
+
/**
|
|
128
|
+
* Signs a SHPreimage off-chain for use with checkDataSig (OP_CHECKSIGFROMSTACK).
|
|
129
|
+
*
|
|
130
|
+
* This is a convenience wrapper that serializes the SHPreimage and signs it
|
|
131
|
+
* using single SHA256 (matching checkDataSig behavior).
|
|
132
|
+
*
|
|
133
|
+
* @param shPreimage - The SHPreimage struct to sign
|
|
134
|
+
* @returns A pure DER-encoded signature (no sighash type appended)
|
|
135
|
+
*/
|
|
136
|
+
function signSHPreimageForCheckDataSig(shPreimage) {
|
|
137
|
+
// Serialize the SHPreimage using encodeSHPreimage
|
|
138
|
+
const preimage = (0, preimage_js_1.encodeSHPreimage)(shPreimage);
|
|
139
|
+
return signDataWithInternalKey(preimage);
|
|
140
|
+
}
|
|
141
|
+
exports.signSHPreimageForCheckDataSig = signSHPreimageForCheckDataSig;
|
|
142
|
+
/**
|
|
143
|
+
* Verifies a preimage signature off-chain.
|
|
144
|
+
*
|
|
145
|
+
* This function can be used to verify signatures before submitting
|
|
146
|
+
* transactions, ensuring the signature is valid.
|
|
147
|
+
*
|
|
148
|
+
* @param sig - The signature to verify
|
|
149
|
+
* @param preimage - The preimage that was signed
|
|
150
|
+
* @returns true if the signature is valid, false otherwise
|
|
151
|
+
*/
|
|
152
|
+
function verifyPreimageSig(sig, preimage) {
|
|
153
|
+
try {
|
|
154
|
+
// Compute SHA256 hash of the preimage
|
|
155
|
+
const hash = Buffer.from((0, hashes_js_1.sha256)(preimage), 'hex');
|
|
156
|
+
// Get the signature bytes (without sigHashType)
|
|
157
|
+
const sigBytes = Buffer.from(sig, 'hex');
|
|
158
|
+
const derSig = sigBytes.slice(0, sigBytes.length - 1);
|
|
159
|
+
// Parse the DER signature
|
|
160
|
+
const signature = Signature.fromDER(derSig);
|
|
161
|
+
// Get public key from ContextUtils
|
|
162
|
+
const publicKey = opcat_1.PublicKey.fromHex(contextUtils_js_1.ContextUtils.pubKey);
|
|
163
|
+
// Verify the signature
|
|
164
|
+
return ECDSA.verify(hash, signature, publicKey, 'little');
|
|
165
|
+
}
|
|
166
|
+
catch (e) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
exports.verifyPreimageSig = verifyPreimageSig;
|
|
171
|
+
//# sourceMappingURL=sigUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sigUtils.js","sourceRoot":"","sources":["../../../src/utils/sigUtils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,6CAA4E;AAC5E,+DAAkE;AAClE,yEAAyF;AAEzF,oFAA8E;AAC9E,+CAAiD;AAEjD,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,cAAM,CAAC;AAEpC;;;GAGG;AACH,MAAM,YAAY,GAAG,kBAAU,CAAC,OAAO,CACpC,8BAAY,CAAC,OAAkB,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,EAC/D,gBAAQ,CAAC,cAAc,CACxB,CAAC;AAEF;;;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AAS,EAAE,QAAQ,CAAC,CAAC;IAC5D,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AApBD,8CAoBC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstractContract.js","sourceRoot":"","sources":["../../../src/smart-contract/abstractContract.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,MAAM,OAAgB,gBAAgB;
|
|
1
|
+
{"version":3,"file":"abstractContract.js","sourceRoot":"","sources":["../../../src/smart-contract/abstractContract.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,MAAM,OAAgB,gBAAgB;IAiFpC;;;;;;OAMG;IACH,MAAM,CAAC,cAAc,CAAwB,MAAU;QACrD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAED,MAAM,CAAC,SAAS,CAAwB,MAAU;QAChD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;CA+BF"}
|
|
@@ -132,7 +132,7 @@ export class Backtrace extends SmartContractLib {
|
|
|
132
132
|
*
|
|
133
133
|
* @see packages/scrypt-ts-opcat/test/local-test/genesis.test.ts - GENESIS_SCRIPT_HASH validation tests
|
|
134
134
|
*/
|
|
135
|
-
Backtrace.GENESIS_SCRIPT_HASH = toByteString('
|
|
135
|
+
Backtrace.GENESIS_SCRIPT_HASH = toByteString('836c4b45ab7a625549ca7c799b02d3304adf996557929ee809613e602d26c1f8');
|
|
136
136
|
__decorate([
|
|
137
137
|
prop(),
|
|
138
138
|
__metadata("design:type", String)
|
|
@@ -400,12 +400,12 @@ export function genesisCheckDeploy() {
|
|
|
400
400
|
*/
|
|
401
401
|
const desc = {
|
|
402
402
|
version: 10,
|
|
403
|
-
compilerVersion: "1.
|
|
404
|
-
contract: "
|
|
405
|
-
md5: "
|
|
403
|
+
compilerVersion: "1.22.0+commit.47800da",
|
|
404
|
+
contract: "_opcat_labs_scrypt_ts_opcat_2_1_2__rs__Genesis",
|
|
405
|
+
md5: "b0f465a1dbe0e0ce8ee64e324bc94894",
|
|
406
406
|
structs: [
|
|
407
407
|
{
|
|
408
|
-
name: "
|
|
408
|
+
name: "_opcat_labs_scrypt_ts_opcat_2_1_2__rs__TxOut",
|
|
409
409
|
params: [
|
|
410
410
|
{
|
|
411
411
|
name: "scriptHash",
|
|
@@ -423,7 +423,29 @@ const desc = {
|
|
|
423
423
|
genericTypes: []
|
|
424
424
|
},
|
|
425
425
|
{
|
|
426
|
-
name: "
|
|
426
|
+
name: "_opcat_labs_scrypt_ts_opcat_2_1_2__rs__TxIn",
|
|
427
|
+
params: [
|
|
428
|
+
{
|
|
429
|
+
name: "prevTxHash",
|
|
430
|
+
type: "bytes"
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
name: "prevOutputIndex",
|
|
434
|
+
type: "int"
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
name: "sequence",
|
|
438
|
+
type: "int"
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
name: "scriptHash",
|
|
442
|
+
type: "bytes"
|
|
443
|
+
}
|
|
444
|
+
],
|
|
445
|
+
genericTypes: []
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
name: "_opcat_labs_scrypt_ts_opcat_2_1_2__rs__SHPreimage",
|
|
427
449
|
params: [
|
|
428
450
|
{
|
|
429
451
|
name: "nVersion",
|
|
@@ -483,23 +505,91 @@ const desc = {
|
|
|
483
505
|
}
|
|
484
506
|
],
|
|
485
507
|
genericTypes: []
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
name: "_opcat_labs_scrypt_ts_opcat_2_1_2__rs__Outpoint",
|
|
511
|
+
params: [
|
|
512
|
+
{
|
|
513
|
+
name: "txHash",
|
|
514
|
+
type: "bytes"
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
name: "outputIndex",
|
|
518
|
+
type: "int"
|
|
519
|
+
}
|
|
520
|
+
],
|
|
521
|
+
genericTypes: []
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
name: "_opcat_labs_scrypt_ts_opcat_2_1_2__rs__TxHashPreimage",
|
|
525
|
+
params: [
|
|
526
|
+
{
|
|
527
|
+
name: "version",
|
|
528
|
+
type: "bytes"
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
name: "inputList",
|
|
532
|
+
type: "bytes"
|
|
533
|
+
},
|
|
534
|
+
{
|
|
535
|
+
name: "outputList",
|
|
536
|
+
type: "bytes"
|
|
537
|
+
},
|
|
538
|
+
{
|
|
539
|
+
name: "nLockTime",
|
|
540
|
+
type: "bytes"
|
|
541
|
+
}
|
|
542
|
+
],
|
|
543
|
+
genericTypes: []
|
|
544
|
+
},
|
|
545
|
+
{
|
|
546
|
+
name: "_opcat_labs_scrypt_ts_opcat_2_1_2__rs__BacktraceInfo",
|
|
547
|
+
params: [
|
|
548
|
+
{
|
|
549
|
+
name: "prevTxInput",
|
|
550
|
+
type: "_opcat_labs_scrypt_ts_opcat_2_1_2__rs__TxIn"
|
|
551
|
+
},
|
|
552
|
+
{
|
|
553
|
+
name: "prevTxInputIndex",
|
|
554
|
+
type: "int"
|
|
555
|
+
},
|
|
556
|
+
{
|
|
557
|
+
name: "prevPrevTxPreimage",
|
|
558
|
+
type: "_opcat_labs_scrypt_ts_opcat_2_1_2__rs__TxHashPreimage"
|
|
559
|
+
}
|
|
560
|
+
],
|
|
561
|
+
genericTypes: []
|
|
562
|
+
},
|
|
563
|
+
{
|
|
564
|
+
name: "_opcat_labs_scrypt_ts_opcat_2_1_2__rs__ReadVarintResult",
|
|
565
|
+
params: [
|
|
566
|
+
{
|
|
567
|
+
name: "data",
|
|
568
|
+
type: "bytes"
|
|
569
|
+
},
|
|
570
|
+
{
|
|
571
|
+
name: "nextPos",
|
|
572
|
+
type: "int"
|
|
573
|
+
}
|
|
574
|
+
],
|
|
575
|
+
genericTypes: []
|
|
486
576
|
}
|
|
487
577
|
],
|
|
488
578
|
library: [
|
|
489
579
|
{
|
|
490
|
-
name: "
|
|
580
|
+
name: "_opcat_labs_scrypt_ts_opcat_2_1_2__rs__TxUtils",
|
|
491
581
|
params: [],
|
|
492
582
|
properties: [],
|
|
493
583
|
genericTypes: []
|
|
494
584
|
},
|
|
495
585
|
{
|
|
496
|
-
name: "
|
|
586
|
+
name: "_opcat_labs_scrypt_ts_opcat_2_1_2__rs__ContextUtils",
|
|
497
587
|
params: [],
|
|
498
588
|
properties: [],
|
|
499
589
|
genericTypes: []
|
|
500
590
|
},
|
|
501
591
|
{
|
|
502
|
-
name: "
|
|
592
|
+
name: "_opcat_labs_scrypt_ts_opcat_2_1_2__rs__StdUtils",
|
|
503
593
|
params: [],
|
|
504
594
|
properties: [],
|
|
505
595
|
genericTypes: []
|
|
@@ -514,7 +604,7 @@ const desc = {
|
|
|
514
604
|
params: [
|
|
515
605
|
{
|
|
516
606
|
name: "outputs",
|
|
517
|
-
type: "
|
|
607
|
+
type: "_opcat_labs_scrypt_ts_opcat_2_1_2__rs__TxOut[6]"
|
|
518
608
|
},
|
|
519
609
|
{
|
|
520
610
|
name: "outputCount",
|
|
@@ -522,7 +612,11 @@ const desc = {
|
|
|
522
612
|
},
|
|
523
613
|
{
|
|
524
614
|
name: "__scrypt_ts_shPreimage",
|
|
525
|
-
type: "
|
|
615
|
+
type: "_opcat_labs_scrypt_ts_opcat_2_1_2__rs__SHPreimage"
|
|
616
|
+
},
|
|
617
|
+
{
|
|
618
|
+
name: "__scrypt_ts_preimageSig",
|
|
619
|
+
type: "Sig"
|
|
526
620
|
},
|
|
527
621
|
{
|
|
528
622
|
name: "__scrypt_ts_spentAmounts",
|
|
@@ -541,9 +635,8 @@ const desc = {
|
|
|
541
635
|
],
|
|
542
636
|
stateProps: [],
|
|
543
637
|
buildType: "release",
|
|
544
|
-
file: "",
|
|
545
|
-
hex: "
|
|
546
|
-
sourceMapFile: ""
|
|
638
|
+
file: "../genesis.scrypt",
|
|
639
|
+
hex: "2102ba79df5f8ae7604a9830f03c7933028186aede0675a16f025dc4f8be8eec03825379547982778c7f75007f770112790112790112790112790112790112790112790112790112790112790112790112790112790112795d798277549d5c79827701209d5b79827701209d5a79827701209d597900a26958798277549d5779827701209d5679827701209d5579827701209d5479827701209d5379827701209d527900a2697800a26976519c6476529c6751686476539c67516864760281009c67516864760282009c67516864760283009c675168695d795d797e5c797e5b797e5a79767600a2637609ffffffffffffffff00a16700686976586e8b806e7c7f75007f6b6d6d6d6c7e59797e58797e57797e56797e55797e54797e5379546e8b806e7c7f75007f6b6d6d6c7e5279546e8b806e7c7f75007f6b6d6d6c7e7854807e6b6d6d6d6d6d6d6d6ca85279ba63537978ac6700686952795c7978aa7888785878827d77527997009d6e7c966b6d6d6c7752795c796f75aa527988765379012078827d77527997009d6e7c967777779d6d755779009d7656a16901137900a06301137956a1670068690125766b796c766b796c766b796c6d7c77000127766b796c766b796c766b796c75000119799f635279827700a06970707c527982777882777801209d7601209d537900a2695379767600a2637609ffffffffffffffff00a16700686976586e8b806e7c7f75007f6b6d6d6d6c55797e53797e6b6d6d6c777e547a7572537a53797500635479537987916968686d750124766b796c766b796c766b796c75510119799f635279827700a06970707c527982777882777801209d7601209d537900a2695379767600a2637609ffffffffffffffff00a16700686976586e8b806e7c7f75007f6b6d6d6d6c55797e53797e6b6d6d6c777e547a7572537a53797551635479537987916968686d750121766b796c766b796c766b796c75520119799f635279827700a06970707c527982777882777801209d7601209d537900a2695379767600a2637609ffffffffffffffff00a16700686976586e8b806e7c7f75007f6b6d6d6d6c55797e53797e6b6d6d6c777e547a7572537a53797551635479537987916968686d75011e766b796c766b796c766b796c75530119799f635279827700a06970707c527982777882777801209d7601209d537900a2695379767600a2637609ffffffffffffffff00a16700686976586e8b806e7c7f75007f6b6d6d6d6c55797e53797e6b6d6d6c777e547a7572537a53797551635479537987916968686d75011b766b796c766b796c766b796c75540119799f635279827700a06970707c527982777882777801209d7601209d537900a2695379767600a2637609ffffffffffffffff00a16700686976586e8b806e7c7f75007f6b6d6d6d6c55797e53797e6b6d6d6c777e547a7572537a5379755400a0635479537987916968686d750118766b796c766b796c766b796c75550119799f635279827700a06970707c527982777882777801209d7601209d537900a2695379767600a2637609ffffffffffffffff00a16700686976586e8b806e7c7f75007f6b6d6d6d6c55797e53797e6b6d6d6c777e547a7572537a5379755500a0635479537987916968686d750053799f635479006e8b0120957f75780120957f77777752797887916975685153799f635479516e8b0120957f75780120957f77777752797887916975685253799f635479526e8b0120957f75780120957f77777752797887916975685353799f635479536e8b0120957f75780120957f77777752797887916975685453799f635479546e8b0120957f75780120957f77777752797887916975685553799f635479556e8b0120957f75780120957f777777527978879169756876aa5b79876b6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6c"
|
|
547
640
|
};
|
|
548
641
|
Genesis.loadArtifact(desc);
|
|
549
642
|
//# sourceMappingURL=genesis.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"genesis.js","sourceRoot":"","sources":["../../../../src/smart-contract/builtin-libs/genesis.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAE1E,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAE1C;;;;;;;;;;;;;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,YAAY,EAAE,EAAE;SACjB;QACD;YACE,IAAI,EAAE,iDAAiD;YACvD,MAAM,EAAE,EAAE;YACV,UAAU,EAAE,EAAE;YACd,YAAY,EAAE,EAAE;SACjB;KACF;IACD,KAAK,EAAE,EAAE;IACT,GAAG,EAAE;QACH;YACE,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,aAAa;YACnB,KAAK,EAAE,CAAC;YACR,MAAM,EAAE;gBACN;oBACE,IAAI,EAAE,SAAS;oBACf,IAAI,EAAE,iDAAiD;iBACxD;gBACD;oBACE,IAAI,EAAE,aAAa;oBACnB,IAAI,EAAE,KAAK;iBACZ;gBACD;oBACE,IAAI,EAAE,wBAAwB;oBAC9B,IAAI,EAAE,mDAAmD;iBAC1D;gBACD;oBACE,IAAI,EAAE,yBAAyB;oBAC/B,IAAI,EAAE,KAAK;iBACZ;gBACD;oBACE,IAAI,EAAE,0BAA0B;oBAChC,IAAI,EAAE,OAAO;iBACd;gBACD;oBACE,IAAI,EAAE,+BAA+B;oBACrC,IAAI,EAAE,OAAO;iBACd;aACF;SACF;QACD;YACE,IAAI,EAAE,aAAa;YACnB,MAAM,EAAE,EAAE;SACX;KACF;IACD,UAAU,EAAE,EAAE;IACd,SAAS,EAAE,SAAS;IACpB,IAAI,EAAE,mBAAmB;IACzB,GAAG,EAAE,8vFAA8vF;CACpwF,CAAC;AAEF,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { crypto, PublicKey, Interpreter } from '@opcat-labs/opcat';
|
|
2
|
+
import { sha256, toByteString } from '../fns/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Verifies a signature against an explicit message and public key.
|
|
5
|
+
* Unlike checkSig which uses the transaction preimage as the implicit message,
|
|
6
|
+
* checkDataSig allows verifying signatures on arbitrary data.
|
|
7
|
+
*
|
|
8
|
+
* @ignore
|
|
9
|
+
* @param self - The contract instance (unused, kept for consistency with other check methods)
|
|
10
|
+
* @param signature - The signature to verify in hex format (pure DER encoded, NO sighash type)
|
|
11
|
+
* @param message - The message that was signed (will be SHA256 hashed once)
|
|
12
|
+
* @param publickey - The public key in hex format to verify the signature against
|
|
13
|
+
* @returns true if the signature is valid for the given message and public key,
|
|
14
|
+
* false if invalid or if encoding checks fail
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* - Uses SHA256 single hash on the message (not hash256 double hash)
|
|
18
|
+
* - Stack order for OP_CHECKSIGFROMSTACK: <sig> <msg> <pubKey> (bottom to top)
|
|
19
|
+
* - Unlike OP_CHECKSIG, OP_CHECKSIGFROMSTACK does NOT require sighash type appended to signature
|
|
20
|
+
*/
|
|
21
|
+
export function checkDataSigImpl(
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
23
|
+
self, signature, message, publickey) {
|
|
24
|
+
const bufSig = Buffer.from(toByteString(signature), 'hex');
|
|
25
|
+
const bufPubkey = Buffer.from(toByteString(publickey), 'hex');
|
|
26
|
+
// Use Interpreter instance for encoding validation (reuse opcat library methods)
|
|
27
|
+
const interpreter = new Interpreter();
|
|
28
|
+
interpreter.flags = Interpreter.DEFAULT_FLAGS;
|
|
29
|
+
if (!interpreter.checkDataSigSignatureEncoding(bufSig) ||
|
|
30
|
+
!interpreter.checkPubkeyEncoding(bufPubkey)) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
let fSuccess = false;
|
|
34
|
+
try {
|
|
35
|
+
// For OP_CHECKSIGFROMSTACK, signature is pure DER (no sighash type)
|
|
36
|
+
const sig = crypto.Signature.fromDER(bufSig);
|
|
37
|
+
const pubkey = PublicKey.fromBuffer(bufPubkey, false);
|
|
38
|
+
// Compute SHA256 of message (single hash, not double hash)
|
|
39
|
+
// This matches the OP_CHECKSIGFROMSTACK behavior
|
|
40
|
+
// Reverse to little-endian format (same as checkSigImpl) for signature verification
|
|
41
|
+
const hashbuf = Buffer.from(sha256(message), 'hex').reverse();
|
|
42
|
+
// Verify using ECDSA with little endian (same as OP_CHECKSIGFROMSTACK)
|
|
43
|
+
fSuccess = crypto.ECDSA.verify(hashbuf, sig, pubkey, 'little');
|
|
44
|
+
}
|
|
45
|
+
catch (_err) {
|
|
46
|
+
// invalid sig or pubkey
|
|
47
|
+
fSuccess = false;
|
|
48
|
+
}
|
|
49
|
+
return fSuccess;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=checkDataSig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkDataSig.js","sourceRoot":"","sources":["../../../../src/smart-contract/methods/checkDataSig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEnE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGvD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,gBAAgB;AAC9B,6DAA6D;AAC7D,IAAsB,EACtB,SAAc,EACd,OAAmB,EACnB,SAAiB;IAEjB,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,CAAC;IAC3D,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,CAAC;IAE9D,iFAAiF;IACjF,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;IACtC,WAAW,CAAC,KAAK,GAAG,WAAW,CAAC,aAAa,CAAC;IAE9C,IACE,CAAC,WAAW,CAAC,6BAA6B,CAAC,MAAM,CAAC;QAClD,CAAC,WAAW,CAAC,mBAAmB,CAAC,SAAS,CAAC,EAC3C,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,QAAQ,GAAG,KAAK,CAAC;IAErB,IAAI,CAAC;QACH,oEAAoE;QACpE,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7C,MAAM,MAAM,GAAG,SAAS,CAAC,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAEtD,2DAA2D;QAC3D,iDAAiD;QACjD,oFAAoF;QACpF,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;QAE9D,uEAAuE;QACvE,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IACjE,CAAC;IAAC,OAAO,IAAI,EAAE,CAAC;QACd,wBAAwB;QACxB,QAAQ,GAAG,KAAK,CAAC;IACnB,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -1,14 +1,45 @@
|
|
|
1
|
+
import { Sig } from '../types/index.js';
|
|
1
2
|
import { ContextUtils } from '../builtin-libs/contextUtils.js';
|
|
2
|
-
import {
|
|
3
|
+
import { sha256 } from '../fns/hashes.js';
|
|
4
|
+
import { slice, len } from '../fns/byteString.js';
|
|
5
|
+
import { encodeSHPreimage } from '../../utils/preimage.js';
|
|
3
6
|
/**
|
|
4
7
|
* Verifies a signature against the contract's public key using the provided SH preimage.
|
|
8
|
+
*
|
|
9
|
+
* This function uses a two-step verification process:
|
|
10
|
+
* 1. checkDataSig - verifies the signature against sha256(serialized_preimage)
|
|
11
|
+
* Since checkDataSig internally applies sha256, it becomes sha256(sha256(preimage)) = hash256(preimage)
|
|
12
|
+
* 2. checkSig - verifies the signature against the actual transaction preimage (hash256)
|
|
13
|
+
*
|
|
14
|
+
* The signature is expected to be pre-generated off-chain over hash256(preimage)
|
|
15
|
+
* and injected via the _injectedPreimageSig property on SmartContract instances.
|
|
16
|
+
*
|
|
5
17
|
* @ignore
|
|
6
18
|
* @param self - The contract instance to verify against
|
|
7
19
|
* @param shPreimage - The SH preimage containing the signature to verify
|
|
8
20
|
* @returns True if the signature is valid for this contract's public key
|
|
9
21
|
*/
|
|
10
22
|
export function checkSHPreimageImpl(self, shPreimage) {
|
|
11
|
-
|
|
12
|
-
|
|
23
|
+
// Get the injected signature from the SmartContract instance
|
|
24
|
+
const smartContract = self;
|
|
25
|
+
const sig = smartContract._injectedPreimageSig;
|
|
26
|
+
if (!sig) {
|
|
27
|
+
throw new Error('Preimage signature not injected. Ensure the method is called with proper context injection.');
|
|
28
|
+
}
|
|
29
|
+
// Use encodeSHPreimage which is the same serialization used in checkSigImpl
|
|
30
|
+
const preimage = encodeSHPreimage(shPreimage);
|
|
31
|
+
// For checkDataSig (OP_CHECKSIGFROMSTACK), we need pure DER signature without sighash type.
|
|
32
|
+
// The injected signature includes sighash type at the end, so we strip it using slice.
|
|
33
|
+
// This uses scrypt-ts slice function which works both in JS runtime and on-chain.
|
|
34
|
+
const pureDerSig = Sig(slice(sig, 0n, len(sig) - 1n));
|
|
35
|
+
// Verify using checkDataSig with sha256(preimage) as message
|
|
36
|
+
// The signature was created over hash256(preimage).reverse()
|
|
37
|
+
// checkDataSig internally applies sha256: sha256(sha256(preimage)) = hash256(preimage)
|
|
38
|
+
// Then reverses to match the signature format
|
|
39
|
+
const dataCheck = self.checkDataSig(pureDerSig, sha256(preimage), ContextUtils.pubKey);
|
|
40
|
+
// Verify using checkSig (signature against transaction preimage which uses hash256)
|
|
41
|
+
// checkSig expects signature with sighash type appended
|
|
42
|
+
const sigCheck = self.checkSig(sig, ContextUtils.pubKey);
|
|
43
|
+
return dataCheck && sigCheck;
|
|
13
44
|
}
|
|
14
45
|
//# sourceMappingURL=checkSHPreimage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkSHPreimage.js","sourceRoot":"","sources":["../../../../src/smart-contract/methods/checkSHPreimage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"checkSHPreimage.js","sourceRoot":"","sources":["../../../../src/sm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utputImpl } from './methods/buildOutput.js';
|
|
|
4
4
|
import { checkCtxImpl } from './methods/checkCtx.js';
|
|
5
5
|
import { checkSHPreimageImpl as checkSHPreimageImpl } from './methods/checkSHPreimage.js';
|
|
6
6
|
import { checkMultiSigImpl, checkSigImpl } from './methods/checkSig.js';
|
|
7
|
+
import { checkDataSigImpl } from './methods/checkDataSig.js';
|
|
7
8
|
import { ABICoder } from './abi.js';
|
|
8
9
|
import { Script } from './types/script.js';
|
|
9
10
|
import { uint8ArrayToHex, cloneDeep, isFinal, hexToUint8Array, ContractHeaderSerializer, calcArtifactHexMD5 } from '../utils/index.js';
|
|
@@ -16,6 +17,7 @@ import { deserializeState, serializeState } from './stateSerializer.js';
|
|
|
16
17
|
import { getUnRenamedSymbol } from './abiutils.js';
|
|
17
18
|
import { checkInputStateHashesImpl } from './methods/checkInputStateHashes.js';
|
|
18
19
|
import { toTxHashPreimage } from '../utils/proof.js';
|
|
20
|
+
import { signSHPreimage } from '../utils/sigUtils.js';
|
|
19
21
|
import { assert } from './fns/assert.js';
|
|
20
22
|
/**
|
|
21
23
|
* The main contract class. To write a contract, extend this class as such:
|
|
@@ -171,6 +173,24 @@ export class SmartContract extends AbstractContract {
|
|
|
171
173
|
checkMultiSig(signatures, publickeys) {
|
|
172
174
|
return checkMultiSigImpl(this, signatures, publickeys);
|
|
173
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Verifies an ECDSA signature against an explicit message and public key.
|
|
178
|
+
* Unlike checkSig which uses the transaction preimage as the implicit message,
|
|
179
|
+
* checkDataSig allows verifying signatures on arbitrary data.
|
|
180
|
+
*
|
|
181
|
+
* Uses OP_CHECKSIGFROMSTACK (0xba) under the hood.
|
|
182
|
+
* Stack order: <sig> <msg> <pubKey> (bottom to top)
|
|
183
|
+
*
|
|
184
|
+
* @param signature - The signature to verify (DER encoded with sighash type)
|
|
185
|
+
* @param message - The message that was signed (will be SHA256 hashed once)
|
|
186
|
+
* @param publickey - The public key to verify the signature against
|
|
187
|
+
* @returns true if the signature is valid, false otherwise
|
|
188
|
+
* @onchain
|
|
189
|
+
* @category Signature Verification
|
|
190
|
+
*/
|
|
191
|
+
checkDataSig(signature, message, publickey) {
|
|
192
|
+
return checkDataSigImpl(this, signature, message, publickey);
|
|
193
|
+
}
|
|
174
194
|
/**
|
|
175
195
|
* A built-in function to create an [change output]{@link https://en.bitcoin.it/wiki/Change}.
|
|
176
196
|
* @onchain
|
|
@@ -343,6 +363,18 @@ export class SmartContract extends AbstractContract {
|
|
|
343
363
|
}
|
|
344
364
|
_autoInject(method, args, autoCheckInputState) {
|
|
345
365
|
const { shPreimage, prevouts, prevout, spentScriptHashes, spentAmounts, spentDataHashes, inputCount, } = this.inputContext;
|
|
366
|
+
// Generate and store preimage signature BEFORE checkCtxImpl
|
|
367
|
+
// because checkCtxImpl calls checkSHPreimage which needs the signature.
|
|
368
|
+
//
|
|
369
|
+
// The signature is stored WITH sighash flag appended because:
|
|
370
|
+
// - checkSig (OP_CHECKSIG) requires signature with sighash flag
|
|
371
|
+
// - checkDataSig (OP_CHECKSIGFROMSTACK) requires pure DER signature without sighash flag
|
|
372
|
+
// (the sighash flag is stripped via slice in checkSHPreimageImpl and transpiled code)
|
|
373
|
+
//
|
|
374
|
+
// Extract the actual sighash type from shPreimage to support all sighash types
|
|
375
|
+
// (SIGHASH_ALL, SIGHASH_NONE, SIGHASH_SINGLE, with or without ANYONECANPAY)
|
|
376
|
+
const sigHashType = Number(shPreimage.sigHashType);
|
|
377
|
+
this._injectedPreimageSig = signSHPreimage(shPreimage, sigHashType);
|
|
346
378
|
checkCtxImpl(this, shPreimage, this._curInputIndex, prevouts, prevout, spentScriptHashes, spentAmounts, spentDataHashes);
|
|
347
379
|
const curState = this.state;
|
|
348
380
|
const abiEntity = this._abiCoder.artifact.abi.find((abiEntity) => {
|
|
@@ -390,6 +422,10 @@ export class SmartContract extends AbstractContract {
|
|
|
390
422
|
}
|
|
391
423
|
args.push(toTxHashPreimage(hexToUint8Array(this.utxo.txHashPreimage)));
|
|
392
424
|
}
|
|
425
|
+
else if (param.name === '__scrypt_ts_preimageSig') {
|
|
426
|
+
// Use the preimage signature that was already generated at the start of _autoInject
|
|
427
|
+
args.push(this._injectedPreimageSig);
|
|
428
|
+
}
|
|
393
429
|
});
|
|
394
430
|
}
|
|
395
431
|
}
|