@opcat-labs/scrypt-ts-opcat 2.0.2 → 2.1.0

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.
Files changed (105) hide show
  1. package/assets/.templates/smart-contract/builtin-libs/backtrace.scrypt.map +1 -1
  2. package/assets/.templates/smart-contract/builtin-libs/backtrace.scrypt.tpl +4 -0
  3. package/assets/.templates/smart-contract/builtin-libs/genesis.scrypt.map +1 -0
  4. package/assets/.templates/smart-contract/builtin-libs/genesis.scrypt.tpl +42 -0
  5. package/assets/.templates/smart-contract/builtin-libs/genesis.transformer.json +9 -0
  6. package/assets/.templates/smart-contract/builtin-libs/p2pk.scrypt.map +1 -1
  7. package/assets/.templates/smart-contract/builtin-libs/p2pk.scrypt.tpl +3 -0
  8. package/assets/.templates/smart-contract/builtin-libs/p2pkh.scrypt.map +1 -1
  9. package/assets/.templates/smart-contract/builtin-libs/p2pkh.scrypt.tpl +3 -0
  10. package/assets/smart-contract/builtin-libs/backtrace.scrypt +16 -12
  11. package/assets/smart-contract/builtin-libs/byteStringReader.scrypt +5 -5
  12. package/assets/smart-contract/builtin-libs/byteStringWriter.scrypt +6 -6
  13. package/assets/smart-contract/builtin-libs/contextUtils.scrypt +16 -16
  14. package/assets/smart-contract/builtin-libs/genesis.scrypt +44 -0
  15. package/assets/smart-contract/builtin-libs/p2pk.scrypt +4 -1
  16. package/assets/smart-contract/builtin-libs/p2pkh.scrypt +4 -1
  17. package/assets/smart-contract/builtin-libs/stateLib.scrypt +1 -1
  18. package/assets/smart-contract/builtin-libs/stateUtils.scrypt +1 -1
  19. package/assets/smart-contract/builtin-libs/stdUtils.scrypt +12 -12
  20. package/assets/smart-contract/builtin-libs/txHashPreimageUtils.scrypt +7 -7
  21. package/assets/smart-contract/builtin-libs/txUtils.scrypt +12 -12
  22. package/assets/smart-contract/types/structs.scrypt +8 -8
  23. package/dist/cjs/features/deployGenesis.cjs +84 -31
  24. package/dist/cjs/features/deployGenesis.js.map +1 -1
  25. package/dist/cjs/providers/dryRunProvider.cjs +57 -0
  26. package/dist/cjs/providers/dryRunProvider.js.map +1 -0
  27. package/dist/cjs/providers/dummyProvider.cjs +10 -0
  28. package/dist/cjs/providers/dummyProvider.js.map +1 -1
  29. package/dist/cjs/providers/index.cjs +4 -1
  30. package/dist/cjs/providers/index.js.map +1 -1
  31. package/dist/cjs/providers/mempoolProvider.cjs +44 -0
  32. package/dist/cjs/providers/mempoolProvider.js.map +1 -1
  33. package/dist/cjs/providers/rpcProvider.cjs +46 -3
  34. package/dist/cjs/providers/rpcProvider.js.map +1 -1
  35. package/dist/cjs/providers/utxoProvider.cjs +9 -1
  36. package/dist/cjs/providers/utxoProvider.js.map +1 -1
  37. package/dist/cjs/psbt/extPsbt.cjs +8 -1
  38. package/dist/cjs/psbt/extPsbt.js.map +1 -1
  39. package/dist/cjs/psbt/psbt.cjs +3 -1
  40. package/dist/cjs/psbt/psbt.js.map +1 -1
  41. package/dist/cjs/smart-contract/builtin-libs/backtrace.cjs +59 -2
  42. package/dist/cjs/smart-contract/builtin-libs/backtrace.js.map +1 -1
  43. package/dist/cjs/smart-contract/builtin-libs/genesis.cjs +553 -0
  44. package/dist/cjs/smart-contract/builtin-libs/genesis.js.map +1 -0
  45. package/dist/cjs/smart-contract/builtin-libs/index.cjs +5 -1
  46. package/dist/cjs/smart-contract/builtin-libs/index.js.map +1 -1
  47. package/dist/cjs/smart-contract/smartContract.cjs +22 -0
  48. package/dist/cjs/smart-contract/smartContract.js.map +1 -1
  49. package/dist/esm/features/deployGenesis.js +84 -31
  50. package/dist/esm/features/deployGenesis.js.map +1 -1
  51. package/dist/esm/providers/dryRunProvider.js +53 -0
  52. package/dist/esm/providers/dryRunProvider.js.map +1 -0
  53. package/dist/esm/providers/dummyProvider.js +10 -0
  54. package/dist/esm/providers/dummyProvider.js.map +1 -1
  55. package/dist/esm/providers/index.js +2 -1
  56. package/dist/esm/providers/index.js.map +1 -1
  57. package/dist/esm/providers/mempoolProvider.js +44 -0
  58. package/dist/esm/providers/mempoolProvider.js.map +1 -1
  59. package/dist/esm/providers/rpcProvider.js +45 -2
  60. package/dist/esm/providers/rpcProvider.js.map +1 -1
  61. package/dist/esm/providers/utxoProvider.js +7 -0
  62. package/dist/esm/providers/utxoProvider.js.map +1 -1
  63. package/dist/esm/psbt/extPsbt.js +8 -1
  64. package/dist/esm/psbt/extPsbt.js.map +1 -1
  65. package/dist/esm/psbt/psbt.js +3 -1
  66. package/dist/esm/psbt/psbt.js.map +1 -1
  67. package/dist/esm/smart-contract/builtin-libs/backtrace.js +61 -4
  68. package/dist/esm/smart-contract/builtin-libs/backtrace.js.map +1 -1
  69. package/dist/esm/smart-contract/builtin-libs/genesis.js +549 -0
  70. package/dist/esm/smart-contract/builtin-libs/genesis.js.map +1 -0
  71. package/dist/esm/smart-contract/builtin-libs/index.js +1 -0
  72. package/dist/esm/smart-contract/builtin-libs/index.js.map +1 -1
  73. package/dist/esm/smart-contract/smartContract.js +23 -1
  74. package/dist/esm/smart-contract/smartContract.js.map +1 -1
  75. package/dist/types/features/deployGenesis.d.ts +39 -12
  76. package/dist/types/features/deployGenesis.d.ts.map +1 -1
  77. package/dist/types/providers/chainProvider.d.ts +12 -0
  78. package/dist/types/providers/chainProvider.d.ts.map +1 -1
  79. package/dist/types/providers/dryRunProvider.d.ts +4 -0
  80. package/dist/types/providers/dryRunProvider.d.ts.map +1 -0
  81. package/dist/types/providers/dummyProvider.d.ts +4 -2
  82. package/dist/types/providers/dummyProvider.d.ts.map +1 -1
  83. package/dist/types/providers/index.d.ts +2 -1
  84. package/dist/types/providers/index.d.ts.map +1 -1
  85. package/dist/types/providers/mempoolProvider.d.ts +4 -2
  86. package/dist/types/providers/mempoolProvider.d.ts.map +1 -1
  87. package/dist/types/providers/rpcProvider.d.ts +4 -2
  88. package/dist/types/providers/rpcProvider.d.ts.map +1 -1
  89. package/dist/types/providers/utxoProvider.d.ts +3 -0
  90. package/dist/types/providers/utxoProvider.d.ts.map +1 -1
  91. package/dist/types/psbt/extPsbt.d.ts.map +1 -1
  92. package/dist/types/psbt/psbt.d.ts.map +1 -1
  93. package/dist/types/smart-contract/builtin-libs/backtrace.d.ts +49 -0
  94. package/dist/types/smart-contract/builtin-libs/backtrace.d.ts.map +1 -1
  95. package/dist/types/smart-contract/builtin-libs/genesis.d.ts +252 -0
  96. package/dist/types/smart-contract/builtin-libs/genesis.d.ts.map +1 -0
  97. package/dist/types/smart-contract/builtin-libs/index.d.ts +1 -0
  98. package/dist/types/smart-contract/builtin-libs/index.d.ts.map +1 -1
  99. package/dist/types/smart-contract/smartContract.d.ts +20 -0
  100. package/dist/types/smart-contract/smartContract.d.ts.map +1 -1
  101. package/package.json +5 -3
  102. package/scrypt.index.json +4 -0
  103. package/src/smart-contract/builtin-libs/backtrace.ts +62 -3
  104. package/src/smart-contract/builtin-libs/genesis.ts +569 -0
  105. package/src/smart-contract/builtin-libs/index.ts +2 -1
@@ -0,0 +1,553 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.genesisCheckDeploy = exports.Genesis = exports.MAX_GENESIS_CHECK_OUTPUT = exports.MAX_GENESIS_CHECK_INPUT = void 0;
13
+ const smartContract_js_1 = require('../smartContract.cjs');
14
+ const decorators_js_1 = require('../decorators.cjs');
15
+ const index_js_1 = require('../fns/index.cjs');
16
+ const txUtils_js_1 = require('./txUtils.cjs');
17
+ const contextUtils_js_1 = require('./contextUtils.cjs');
18
+ const common_js_1 = require('../../utils/common.cjs');
19
+ /**
20
+ * Maximum number of inputs allowed during genesis deployment.
21
+ *
22
+ * ## Purpose
23
+ * Limits the number of inputs validated to prevent script size bloat while
24
+ * maintaining sufficient security coverage.
25
+ *
26
+ * ## Why 6?
27
+ * - **Typical deployments**: 1-3 inputs (Genesis UTXO + fee UTXOs)
28
+ * - **Edge case coverage**: Handles multi-input deployment scenarios
29
+ * - **Script size**: Each input check adds ~50 bytes; 6 is optimal balance
30
+ * - **Security**: Validates all inputs in normal cases
31
+ * - **sCrypt constraint**: Bitcoin Script loops must be unrolled at compile time
32
+ *
33
+ * ## Security Implications
34
+ * Transactions with more than 6 inputs will be **rejected by the contract**.
35
+ * This prevents attackers from hiding duplicate scriptHashes in unchecked input
36
+ * indices beyond the validation limit.
37
+ *
38
+ * @constant
39
+ * @see {@link Genesis.checkDeploy} - Uses this constant for input validation
40
+ * @category Genesis
41
+ */
42
+ exports.MAX_GENESIS_CHECK_INPUT = 6;
43
+ /**
44
+ * Maximum number of outputs to check during genesis deployment.
45
+ *
46
+ * ## Purpose
47
+ * Limits the number of outputs validated during deployment to match input
48
+ * validation coverage and support typical deployment patterns.
49
+ *
50
+ * ## Usage Scenarios
51
+ * - **1 output**: Deploy single contract
52
+ * - **2-3 outputs**: Deploy contract + change outputs
53
+ * - **4-6 outputs**: Multi-contract deployment or complex output structures
54
+ *
55
+ * ## Validation Scope
56
+ * Only `output[0]` must be unique. Other outputs (1-5) can have duplicate
57
+ * scriptHashes as long as they differ from `output[0]`.
58
+ *
59
+ * @constant
60
+ * @see {@link Genesis.checkDeploy} - Uses this constant for output validation
61
+ * @see {@link MAX_GENESIS_CHECK_INPUT} - Corresponding input limit
62
+ * @category Genesis
63
+ */
64
+ exports.MAX_GENESIS_CHECK_OUTPUT = 6;
65
+ /**
66
+ * Genesis contract for validating initial deployment outputs.
67
+ *
68
+ * ## Purpose
69
+ * The Genesis contract ensures that deployed contracts have unique scriptHashes,
70
+ * preventing duplicate deployments and establishing a verifiable deployment origin.
71
+ * It acts as a "genesis UTXO" that validates the first deployment of a contract.
72
+ *
73
+ * ## Deployment Validation Rules
74
+ * 1. **Genesis position**: Genesis must be unlocked at input index 0
75
+ * 2. **Output uniqueness**: Contract at `output[0]` must have unique scriptHash among all outputs
76
+ * 3. **Input differentiation**: Contract at `output[0]` must differ from all input scriptHashes
77
+ * 4. **Input limit**: Transaction must have ≤ {@link MAX_GENESIS_CHECK_INPUT} inputs
78
+ * 5. **Output limit**: Transaction must specify ≤ {@link MAX_GENESIS_CHECK_OUTPUT} outputs
79
+ *
80
+ * ## Why output[0]?
81
+ * Only `output[0]` requires uniqueness validation. This design allows:
82
+ * - Deploying the **primary contract** at output[0] with guaranteed uniqueness
83
+ * - Including **auxiliary contracts** or **change outputs** at indices 1-5
84
+ * - **Multi-output deployments** where only the main contract needs uniqueness
85
+ *
86
+ * ## Empty Placeholders
87
+ * When fewer than {@link MAX_GENESIS_CHECK_OUTPUT} outputs exist, use empty
88
+ * placeholders (scriptHash = empty ByteString) for unused slots. These are
89
+ * ignored during validation.
90
+ *
91
+ * @example
92
+ * **Basic single contract deployment:**
93
+ * ```typescript
94
+ * import { Genesis, genesisCheckDeploy } from '@opcat-labs/scrypt-ts-opcat';
95
+ * import { ExtPsbt } from '@opcat-labs/scrypt-ts-opcat';
96
+ *
97
+ * // 1. Create and bind Genesis contract
98
+ * const genesis = new Genesis();
99
+ * genesis.bindToUtxo(genesisUtxo);
100
+ *
101
+ * // 2. Create the contract to deploy
102
+ * const minter = new CAT20Minter(...);
103
+ *
104
+ * // 3. Build deployment transaction
105
+ * const psbt = new ExtPsbt({ network })
106
+ * .addContractInput(genesis, genesisCheckDeploy()) // Genesis validates deployment
107
+ * .addContractOutput(minter, 1000n) // Deploy at output[0]
108
+ * .change(changeAddress, feeRate)
109
+ * .seal();
110
+ *
111
+ * // 4. Finalize and broadcast
112
+ * await psbt.finalizeAllInputs();
113
+ * const txid = await psbt.broadcast();
114
+ * console.log(`Contract deployed at ${txid}:0`);
115
+ * ```
116
+ *
117
+ * @category Contract
118
+ * @category Genesis
119
+ * @see {@link genesisCheckDeploy} - Helper function for easier deployment
120
+ * @see {@link MAX_GENESIS_CHECK_INPUT} - Maximum inputs validated
121
+ * @see {@link MAX_GENESIS_CHECK_OUTPUT} - Maximum outputs validated
122
+ * @onchain
123
+ */
124
+ let Genesis = class Genesis extends smartContract_js_1.SmartContract {
125
+ constructor() {
126
+ // eslint-disable-next-line prefer-rest-params
127
+ super(...arguments);
128
+ }
129
+ /**
130
+ * Validates the deployment transaction outputs.
131
+ *
132
+ * ## Validation Process
133
+ * This method performs a **two-phase validation**:
134
+ *
135
+ * **Phase 1: Output Serialization & Uniqueness** (lines 168-183)
136
+ * - Iterates through all outputs up to MAX_GENESIS_CHECK_OUTPUT
137
+ * - Serializes valid outputs (index < outputCount) for context matching
138
+ * - Validates `output[0]` scriptHash is unique among all outputs
139
+ * - Ensures no duplicate contracts are deployed in a single transaction
140
+ *
141
+ * **Phase 2: Input Differentiation** (lines 185-195)
142
+ * - Checks `output[0]` differs from all input scriptHashes
143
+ * - Prevents redeployment attacks using existing contract UTXOs
144
+ * - Validates only inputs within MAX_GENESIS_CHECK_INPUT limit
145
+ *
146
+ * ## Why Two Separate Loops?
147
+ * 1. **Output loop**: Dual-purpose (serialize + validate uniqueness)
148
+ * 2. **Input loop**: Independent validation after outputs are processed
149
+ * 3. **sCrypt constraint**: Loops must be unrolled at compile time
150
+ *
151
+ * @param outputs - Fixed array of 6 outputs; fill unused slots with empty placeholders
152
+ * @param outputCount - Number of actual outputs (1-6); outputs beyond this are ignored
153
+ *
154
+ * @throws {Error} 'Genesis must be unlocked at input index 0' - Genesis not at input 0
155
+ * @throws {Error} 'Too many inputs to validate' - More than MAX_GENESIS_CHECK_INPUT inputs
156
+ * @throws {Error} 'Invalid outputCount' - outputCount out of range [1, 6]
157
+ * @throws {Error} 'Output scriptHash must be non-empty' - Empty scriptHash in valid output
158
+ * @throws {Error} 'output[0] must be unique among all outputs' - Duplicate scriptHash in outputs
159
+ * @throws {Error} 'output[0] must differ from all input scriptHashes' - Matches an input
160
+ * @throws {Error} 'Outputs mismatch with the transaction context' - Serialization mismatch
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * // Advanced: Direct method call (most users should use genesisCheckDeploy helper)
165
+ * const genesis = new Genesis();
166
+ * genesis.bindToUtxo(genesisUtxo);
167
+ *
168
+ * // Create output array with empty placeholders
169
+ * const outputs: TxOut[] = [
170
+ * { scriptHash: sha256(contractScript), satoshis: 1000n, dataHash: sha256('') },
171
+ * ...fill({ scriptHash: toByteString(''), satoshis: 0n, dataHash: sha256('') }, 5)
172
+ * ];
173
+ *
174
+ * await genesis.methods.checkDeploy(
175
+ * outputs as FixedArray<TxOut, 6>,
176
+ * 1n // Only 1 real output, rest are placeholders
177
+ * );
178
+ * ```
179
+ *
180
+ * @see {@link genesisCheckDeploy} - Helper function for easier usage
181
+ * @see {@link MAX_GENESIS_CHECK_INPUT} - Maximum inputs validated
182
+ * @see {@link MAX_GENESIS_CHECK_OUTPUT} - Maximum outputs validated
183
+ * @onchain
184
+ */
185
+ checkDeploy(outputs, outputCount) {
186
+ // === PRELIMINARY CHECKS ===
187
+ // Ensure Genesis is unlocked at input index 0
188
+ // This guarantees Genesis validates the deployment and prevents position-based attacks
189
+ (0, index_js_1.assert)(this.ctx.inputIndex == 0n, 'Genesis must be unlocked at input index 0');
190
+ // Ensure input count does not exceed the maximum we can check
191
+ // SECURITY: Prevents attackers from hiding duplicate scriptHashes in unchecked input indices
192
+ (0, index_js_1.assert)(this.ctx.inputCount <= BigInt(exports.MAX_GENESIS_CHECK_INPUT), 'Too many inputs to validate');
193
+ // Validate outputCount is within valid range [1, MAX_GENESIS_CHECK_OUTPUT]
194
+ (0, index_js_1.assert)(outputCount > 0n && outputCount <= BigInt(exports.MAX_GENESIS_CHECK_OUTPUT), 'Invalid outputCount: must be between 1 and MAX_GENESIS_CHECK_OUTPUT');
195
+ // Cache output[0] scriptHash for comparison in validation loops
196
+ // This is more efficient than repeatedly accessing outputs[0].scriptHash
197
+ const output0ScriptHash = outputs[0].scriptHash;
198
+ // === PHASE 1: SERIALIZE OUTPUTS & VALIDATE UNIQUENESS ===
199
+ // Loop through all output slots to:
200
+ // 1. Serialize valid outputs for context matching
201
+ // 2. Validate output[0] uniqueness among all outputs
202
+ // Note: Loop is unrolled at compile time (sCrypt constraint)
203
+ let outputBytes = (0, index_js_1.toByteString)('');
204
+ for (let index = 0; index < exports.MAX_GENESIS_CHECK_OUTPUT; index++) {
205
+ const _output = outputs[index];
206
+ if (index < outputCount) {
207
+ // Validate: All valid outputs must have non-empty scriptHash
208
+ (0, index_js_1.assert)((0, index_js_1.len)(_output.scriptHash) > 0n, 'Output scriptHash must be non-empty for valid outputs');
209
+ // Serialize this output for later context verification
210
+ outputBytes += txUtils_js_1.TxUtils.buildDataOutput(_output.scriptHash, _output.satoshis, _output.dataHash);
211
+ // Validate: output[0] must be unique among all outputs
212
+ // Skip index 0 (can't compare output[0] with itself)
213
+ if (index > 0) {
214
+ (0, index_js_1.assert)(output0ScriptHash != _output.scriptHash, 'output[0] must be unique among all outputs');
215
+ }
216
+ }
217
+ // Else: index >= outputCount, this is an empty placeholder, skip it
218
+ }
219
+ // === PHASE 2: VALIDATE INPUT DIFFERENTIATION ===
220
+ // Ensure output[0] scriptHash differs from all input scriptHashes
221
+ // SECURITY: Prevents redeployment using existing contract UTXOs as inputs
222
+ for (let index = 0; index < exports.MAX_GENESIS_CHECK_INPUT; index++) {
223
+ if (index < this.ctx.inputCount) {
224
+ // Extract scriptHash of input at this index
225
+ const inputScriptHash = contextUtils_js_1.ContextUtils.getSpentScriptHash(this.ctx.spentScriptHashes, BigInt(index));
226
+ // Validate: output[0] must differ from this input
227
+ (0, index_js_1.assert)(output0ScriptHash != inputScriptHash, 'output[0] must differ from all input scriptHashes');
228
+ }
229
+ // Else: index >= inputCount, no input at this index, skip it
230
+ }
231
+ // === FINAL CHECK: CONTEXT VERIFICATION ===
232
+ // Verify that our serialized outputs match the transaction's actual outputs
233
+ // This ensures the outputs array passed to this method is truthful
234
+ (0, index_js_1.assert)(this.checkOutputs(outputBytes), 'Outputs mismatch with the transaction context');
235
+ }
236
+ };
237
+ exports.Genesis = Genesis;
238
+ __decorate([
239
+ (0, decorators_js_1.method)(),
240
+ __metadata("design:type", Function),
241
+ __metadata("design:paramtypes", [Object, BigInt]),
242
+ __metadata("design:returntype", void 0)
243
+ ], Genesis.prototype, "checkDeploy", null);
244
+ exports.Genesis = Genesis = __decorate([
245
+ (0, decorators_js_1.tags)(['GENESIS']),
246
+ __metadata("design:paramtypes", [])
247
+ ], Genesis);
248
+ /**
249
+ * Creates a contract call function for Genesis.checkDeploy that automatically
250
+ * builds the TxOut array from transaction outputs.
251
+ *
252
+ * ## What it does
253
+ * This helper function simplifies Genesis deployment by:
254
+ * 1. **Extracting outputs** from the PSBT transaction
255
+ * 2. **Computing hashes** (scriptHash and dataHash) for each output
256
+ * 3. **Creating placeholders** for unused output slots (up to 6 total)
257
+ * 4. **Invoking checkDeploy** with properly formatted parameters
258
+ *
259
+ * ## When to use
260
+ * - **Recommended**: Use this helper when building deployment transactions with ExtPsbt
261
+ * - **Advanced**: Call {@link Genesis.checkDeploy} directly for manual control
262
+ *
263
+ * ## Output Handling
264
+ * - Processes up to {@link MAX_GENESIS_CHECK_OUTPUT} (6) outputs
265
+ * - Automatically limits `outputCount` via `Math.min(txOutputs.length, 6)`
266
+ * - Fills unused slots with empty placeholders (scriptHash = empty ByteString)
267
+ *
268
+ * @returns A ContractCall function compatible with ExtPsbt.addContractInput
269
+ *
270
+ * @example
271
+ * **Basic single contract deployment:**
272
+ * ```typescript
273
+ * import { Genesis, genesisCheckDeploy } from '@opcat-labs/scrypt-ts-opcat';
274
+ * import { ExtPsbt } from '@opcat-labs/scrypt-ts-opcat';
275
+ *
276
+ * // 1. Setup Genesis contract
277
+ * const genesis = new Genesis();
278
+ * genesis.bindToUtxo(genesisUtxo);
279
+ *
280
+ * // 2. Create contract to deploy
281
+ * const minter = new CAT20Minter(...);
282
+ *
283
+ * // 3. Build deployment transaction
284
+ * const psbt = new ExtPsbt({ network })
285
+ * .addContractInput(genesis, genesisCheckDeploy()) // Genesis validates
286
+ * .addContractOutput(minter, 1000n) // Deploy at output[0]
287
+ * .change(changeAddress, feeRate) // Change output
288
+ * .seal();
289
+ *
290
+ * // 4. Finalize and broadcast
291
+ * await psbt.finalizeAllInputs();
292
+ * const txid = await psbt.broadcast();
293
+ * console.log(`Contract deployed at ${txid}:0`);
294
+ * ```
295
+ *
296
+ * @example
297
+ * **Multi-output deployment:**
298
+ * ```typescript
299
+ * // Deploy primary contract + auxiliary contracts
300
+ * const psbt = new ExtPsbt({ network })
301
+ * .addContractInput(genesis, genesisCheckDeploy())
302
+ * .addContractOutput(primaryContract, 2000n) // output[0] - must be unique
303
+ * .addContractOutput(helperContract, 1000n) // output[1] - can match output[2+]
304
+ * .addContractOutput(anotherHelper, 1000n) // output[2] - can match output[1]
305
+ * .change(changeAddress, feeRate)
306
+ * .seal();
307
+ * ```
308
+ *
309
+ * @example
310
+ * **Error handling:**
311
+ * ```typescript
312
+ * try {
313
+ * const psbt = new ExtPsbt({ network })
314
+ * .addContractInput(genesis, genesisCheckDeploy())
315
+ * .addContractOutput(contract1, 1000n) // output[0]
316
+ * .addContractOutput(contract1, 1000n) // ❌ Same as output[0] - will fail!
317
+ * .seal();
318
+ * await psbt.finalizeAllInputs();
319
+ * await psbt.broadcast();
320
+ * } catch (error) {
321
+ * // Error: output[0] must be unique among all outputs
322
+ * console.error('Deployment failed:', error.message);
323
+ * }
324
+ * ```
325
+ *
326
+ * @category Genesis
327
+ * @see {@link Genesis.checkDeploy} - The underlying contract method
328
+ * @see {@link MAX_GENESIS_CHECK_OUTPUT} - Maximum outputs validated
329
+ */
330
+ function genesisCheckDeploy() {
331
+ return (contract, psbt) => {
332
+ // Create empty placeholder for unused output slots
333
+ // Empty scriptHash signals "no output" to the Genesis contract
334
+ const emptyOutput = {
335
+ scriptHash: (0, index_js_1.toByteString)(''), // Empty = placeholder
336
+ satoshis: 0n, // Placeholder value
337
+ dataHash: (0, index_js_1.sha256)((0, index_js_1.toByteString)('')), // Hash of empty data
338
+ };
339
+ // Initialize array with 6 empty placeholders
340
+ // Genesis contract requires exactly 6 output slots (sCrypt FixedArray constraint)
341
+ const outputs = (0, index_js_1.fill)(emptyOutput, exports.MAX_GENESIS_CHECK_OUTPUT);
342
+ // Extract actual outputs from the transaction being built
343
+ const txOutputs = psbt.txOutputs;
344
+ // Limit to MAX_GENESIS_CHECK_OUTPUT to prevent validation errors
345
+ // If tx has >6 outputs, only first 6 are validated (rare edge case)
346
+ const outputCount = Math.min(txOutputs.length, exports.MAX_GENESIS_CHECK_OUTPUT);
347
+ // Fill the output array with actual transaction outputs
348
+ for (let i = 0; i < outputCount; i++) {
349
+ const output = txOutputs[i];
350
+ outputs[i] = {
351
+ // Compute scriptHash: SHA256 of the output's locking script
352
+ scriptHash: (0, index_js_1.sha256)((0, index_js_1.toByteString)((0, common_js_1.uint8ArrayToHex)(output.script))),
353
+ // Output amount in satoshis
354
+ satoshis: BigInt(output.value),
355
+ // Compute dataHash: SHA256 of the output's data field (if any)
356
+ dataHash: (0, index_js_1.sha256)((0, index_js_1.toByteString)((0, common_js_1.uint8ArrayToHex)(output.data))),
357
+ };
358
+ }
359
+ // Remaining slots (i >= outputCount) remain as empty placeholders
360
+ contract.checkDeploy(outputs, BigInt(outputCount));
361
+ };
362
+ }
363
+ exports.genesisCheckDeploy = genesisCheckDeploy;
364
+ /**
365
+ * Embedded contract artifact for the Genesis contract.
366
+ *
367
+ * ## What is this?
368
+ * This object contains the compiled sCrypt bytecode and metadata for the Genesis contract.
369
+ * It includes:
370
+ * - **Compiled bytecode** (hex, asm fields) - Executable Bitcoin Script
371
+ * - **Contract ABI** - Method signatures and parameter types
372
+ * - **Struct definitions** (TxOut, SHPreimage) - Type information for complex data structures
373
+ * - **Compiler metadata** - Version, MD5 hash for artifact validation
374
+ *
375
+ * ## Auto-generation
376
+ * This artifact is **automatically generated and updated** by the build script:
377
+ * ```bash
378
+ * npm run gen:contract Genesis
379
+ * ```
380
+ *
381
+ * This command:
382
+ * 1. Compiles the Genesis contract using `npx tspc`
383
+ * 2. Generates artifact JSON in `test/fixtures/genesis.json`
384
+ * 3. Embeds the artifact into this source file (via `updateContractDesc.ts`)
385
+ * 4. Cleans up intermediate compilation files
386
+ *
387
+ * ## Why embedded in source?
388
+ * Embedding the artifact directly in the source file provides:
389
+ * - **Zero-config usage** - No need to load external JSON files
390
+ * - **Type safety** - TypeScript can validate the artifact structure
391
+ * - **Bundler compatibility** - Works seamlessly with webpack, rollup, etc.
392
+ * - **Single-file distribution** - Easier to import and use
393
+ *
394
+ * ## When to update
395
+ * The artifact must be regenerated whenever:
396
+ * - The Genesis contract logic changes
397
+ * - Struct definitions (TxOut, SHPreimage) are modified
398
+ * - The sCrypt compiler version is updated
399
+ *
400
+ * ⚠️ **DO NOT manually edit this object** - Changes will be overwritten on next compilation.
401
+ * To update: modify the contract code above, then run `npm run gen:contract Genesis`.
402
+ *
403
+ * @see {@link updateContractDesc} - Script that embeds this artifact (scripts/updateContractDesc.ts)
404
+ */
405
+ const desc = {
406
+ version: 10,
407
+ compilerVersion: "1.21.0+commit.2ada378",
408
+ contract: "Genesis",
409
+ md5: "0b1e184a0aecd042ae661eb8d44a0483",
410
+ structs: [
411
+ {
412
+ name: "TxOut",
413
+ params: [
414
+ {
415
+ name: "scriptHash",
416
+ type: "bytes"
417
+ },
418
+ {
419
+ name: "dataHash",
420
+ type: "bytes"
421
+ },
422
+ {
423
+ name: "satoshis",
424
+ type: "int"
425
+ }
426
+ ],
427
+ genericTypes: []
428
+ },
429
+ {
430
+ name: "SHPreimage",
431
+ params: [
432
+ {
433
+ name: "nVersion",
434
+ type: "bytes"
435
+ },
436
+ {
437
+ name: "hashPrevouts",
438
+ type: "bytes"
439
+ },
440
+ {
441
+ name: "spentScriptHash",
442
+ type: "bytes"
443
+ },
444
+ {
445
+ name: "spentDataHash",
446
+ type: "bytes"
447
+ },
448
+ {
449
+ name: "value",
450
+ type: "int"
451
+ },
452
+ {
453
+ name: "nSequence",
454
+ type: "bytes"
455
+ },
456
+ {
457
+ name: "hashSpentAmounts",
458
+ type: "bytes"
459
+ },
460
+ {
461
+ name: "hashSpentScriptHashes",
462
+ type: "bytes"
463
+ },
464
+ {
465
+ name: "hashSpentDataHashes",
466
+ type: "bytes"
467
+ },
468
+ {
469
+ name: "hashSequences",
470
+ type: "bytes"
471
+ },
472
+ {
473
+ name: "hashOutputs",
474
+ type: "bytes"
475
+ },
476
+ {
477
+ name: "inputIndex",
478
+ type: "int"
479
+ },
480
+ {
481
+ name: "nLockTime",
482
+ type: "int"
483
+ },
484
+ {
485
+ name: "sigHashType",
486
+ type: "int"
487
+ }
488
+ ],
489
+ genericTypes: []
490
+ }
491
+ ],
492
+ library: [
493
+ {
494
+ name: "TxUtils",
495
+ params: [],
496
+ properties: [],
497
+ genericTypes: []
498
+ },
499
+ {
500
+ name: "ContextUtils",
501
+ params: [],
502
+ properties: [],
503
+ genericTypes: []
504
+ },
505
+ {
506
+ name: "StdUtils",
507
+ params: [],
508
+ properties: [],
509
+ genericTypes: []
510
+ }
511
+ ],
512
+ alias: [],
513
+ abi: [
514
+ {
515
+ type: "function",
516
+ name: "checkDeploy",
517
+ index: 0,
518
+ params: [
519
+ {
520
+ name: "outputs",
521
+ type: "TxOut[6]"
522
+ },
523
+ {
524
+ name: "outputCount",
525
+ type: "int"
526
+ },
527
+ {
528
+ name: "__scrypt_ts_shPreimage",
529
+ type: "SHPreimage"
530
+ },
531
+ {
532
+ name: "__scrypt_ts_spentAmounts",
533
+ type: "bytes"
534
+ },
535
+ {
536
+ name: "__scrypt_ts_spentScriptHashes",
537
+ type: "bytes"
538
+ }
539
+ ]
540
+ },
541
+ {
542
+ type: "constructor",
543
+ params: []
544
+ }
545
+ ],
546
+ stateProps: [],
547
+ buildType: "release",
548
+ file: "",
549
+ hex: "512097dfd76851bf465e8f715593b217714858bbe9570ff3bd5e33840a34e20ff0262102ba79df5f8ae7604a9830f03c7933028186aede0675a16f025dc4f8be8eec0382201008ce7480da41702918d1ec8e6849ba32b4d65b1e40dc669c31a1e6306b266c6161011379011379011379011379011379011379011379011379011379011379011379011379011379011379615d798277549c695c79827701209c695b79827701209c695a79827701209c69597900a26958798277549c695779827701209c695679827701209c695579827701209c695479827701209c695379827701209c69527900a269517900a2690079519c640079529c675168640079539c6751686400790281009c6751686400790282009c6751686400790283009c675168695d795d797e5c797e5b797e5a7961007961007900a263007909ffffffffffffffff00a1670068690079586151795179519380007952797f75007f77517a75517a75517a7561517a7561517a75617e59797e58797e57797e56797e55797e54797e5379546151795179519380007952797f75007f77517a75517a75517a75617e5279546151795179519380007952797f75007f77517a75517a75517a75617e517954807e0079517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a7561547961517955795579210ac407f0e4bd44bfc207355a778b046225a7068fc59ee7eda43ad905aadbffc800206c266b30e6a1319c66dc401e5bd6b432ba49688eecd118297041da8074ce081057795679615679aa0079610079517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01007e81517a75615779567956795679567961537956795479577995939521414136d08c5ed2bf3ba048afe6dcaebafeffffffffffffffffffffffffffffff00517951796151795179970079009f63007952799367007968517a75517a75517a7561527a75517a517951795296a0630079527994527a75517a6853798277527982775379012080517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01205279947f7754537993527993013051797e527e54797e58797e527e53797e52797e57797e0079517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a756100795779ac517a75517a75517a75517a75517a75517a75517a75517a75517a7561517a75517a75616955795e79615179aa5179876951795861517982770079527997009c690079527996517a75517a75517a7561517a75517a756155795e795279615279aa5279876900795379012061517982770079527997009c690079527996517a75517a75517a75619c6951517a75517a75517a7561755979009c69007956a16901157900a06301157956a167006869006101286b6c766b796c766b796c766b796c7500011a799f635279827700a0695379537952795479615279827751798277517901209c69007901209c69537900a269537961007961007900a263007909ffffffffffffffff00a1670068690079586151795179519380007952797f75007f77517a75517a75517a7561517a7561517a756155797e53797e517a75517a75517a75517a75517a75617e547a75537a537a537a537975687575756101256b6c766b796c766b796c766b796c7551011a799f635279827700a0695379537952795479615279827751798277517901209c69007901209c69537900a269537961007961007900a263007909ffffffffffffffff00a1670068690079586151795179519380007952797f75007f77517a75517a75517a7561517a7561517a756155797e53797e517a75517a75517a75517a75517a75617e547a75537a537a537a537975687575756101226b6c766b796c766b796c766b796c7552011a799f635279827700a0695379537952795479615279827751798277517901209c69007901209c69537900a269537961007961007900a263007909ffffffffffffffff00a1670068690079586151795179519380007952797f75007f77517a75517a75517a7561517a7561517a756155797e53797e517a75517a75517a75517a75517a75617e547a75537a537a537a5379756875757561011f6b6c766b796c766b796c766b796c7553011a799f635279827700a0695379537952795479615279827751798277517901209c69007901209c69537900a269537961007961007900a263007909ffffffffffffffff00a1670068690079586151795179519380007952797f75007f77517a75517a75517a7561517a7561517a756155797e53797e517a75517a75517a75517a75517a75617e547a75537a537a537a5379756875757561011c6b6c766b796c766b796c766b796c7554011a799f635279827700a0695379537952795479615279827751798277517901209c69007901209c69537900a269537961007961007900a263007909ffffffffffffffff00a1670068690079586151795179519380007952797f75007f77517a75517a75517a7561517a7561517a756155797e53797e517a75517a75517a75517a75517a75617e547a75537a537a537a537975687575756101196b6c766b796c766b796c766b796c7555011a799f635279827700a0695379537952795479615279827751798277517901209c69007901209c69537900a269537961007961007900a263007909ffffffffffffffff00a1670068690079586151795179519380007952797f75007f77517a75517a75517a7561517a7561517a756155797e53797e517a75517a75517a75517a75517a75617e547a75537a537a537a5379756875757501286b6c766b796c766b796c766b796c75527a527a527a7575610053799f63577900615179517951930120957f7551790120957f77517a75517a7561517951798791697568615153799f63577951615179517951930120957f7551790120957f77517a75517a7561517951798791697568615253799f63577952615179517951930120957f7551790120957f77517a75517a7561517951798791697568615353799f63577953615179517951930120957f7551790120957f77517a75517a7561517951798791697568615453799f63577954615179517951930120957f7551790120957f77517a75517a7561517951798791697568615553799f63577955615179517951930120957f7551790120957f77517a75517a756151795179879169756801177951a063007901276b6c766b796c766b796c766b796c75527a527a527a75758791696801177952a063007901246b6c766b796c766b796c766b796c75527a527a527a75758791696801177953a063007901216b6c766b796c766b796c766b796c75527a527a527a75758791696801177954a0630079011e6b6c766b796c766b796c766b796c75527a527a527a75758791696801177955a0630079011b6b6c766b796c766b796c766b796c75527a527a527a7575879169685179aa5d7987777777777777777777777777777777777777777777777777777777777777777777777777777777777777",
550
+ sourceMapFile: ""
551
+ };
552
+ Genesis.loadArtifact(desc);
553
+ //# sourceMappingURL=genesis.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"genesis.js","sourceRoot":"","sources":["../../../../src/smart-contract/builtin-libs/genesis.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0DAAoD;AACpD,oDAAgD;AAChD,8CAA0E;AAE1E,6CAAuC;AACvC,uDAAiD;AAEjD,qDAAwD;AAExD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACU,QAAA,uBAAuB,GAAG,CAAC,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;GAoBG;A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U,EAAE,EAAE;IACd,SAAS,EAAE,SAAS;IACpB,IAAI,EAAE,EAAE;IACR,GAAG,EAAE,86KAA86K;IACn7K,aAAa,EAAE,EAAE;CAClB,CAAC;AAEF,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TxHashPreimageUtils = exports.StateLib = exports.Backtrace = exports.StdUtils = exports.StateUtils = exports.TxUtils = exports.ContextUtils = void 0;
3
+ exports.genesisCheckDeploy = exports.MAX_GENESIS_CHECK_OUTPUT = exports.Genesis = exports.TxHashPreimageUtils = exports.StateLib = exports.Backtrace = exports.StdUtils = exports.StateUtils = exports.TxUtils = exports.ContextUtils = void 0;
4
4
  var contextUtils_js_1 = require('./contextUtils.cjs');
5
5
  Object.defineProperty(exports, "ContextUtils", { enumerable: true, get: function () { return contextUtils_js_1.ContextUtils; } });
6
6
  var txUtils_js_1 = require('./txUtils.cjs');
@@ -15,4 +15,8 @@ var stateLib_js_1 = require('./stateLib.cjs');
15
15
  Object.defineProperty(exports, "StateLib", { enumerable: true, get: function () { return stateLib_js_1.StateLib; } });
16
16
  var txHashPreimageUtils_js_1 = require('./txHashPreimageUtils.cjs');
17
17
  Object.defineProperty(exports, "TxHashPreimageUtils", { enumerable: true, get: function () { return txHashPreimageUtils_js_1.TxHashPreimageUtils; } });
18
+ var genesis_js_1 = require('./genesis.cjs');
19
+ Object.defineProperty(exports, "Genesis", { enumerable: true, get: function () { return genesis_js_1.Genesis; } });
20
+ Object.defineProperty(exports, "MAX_GENESIS_CHECK_OUTPUT", { enumerable: true, get: function () { return genesis_js_1.MAX_GENESIS_CHECK_OUTPUT; } });
21
+ Object.defineProperty(exports, "genesisCheckDeploy", { enumerable: true, get: function () { return genesis_js_1.genesisCheckDeploy; } });
18
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/smart-contract/builtin-libs/index.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AAAxC,+GAAA,YAAY,OAAA;AACrB,2CAAuC;AAA9B,qGAAA,OAAO,OAAA;AAChB,iDAA6C;AAApC,2GAAA,UAAU,OAAA;AACnB,6CAAyC;AAAhC,uGAAA,QAAQ,OAAA;AACjB,+CAAuE;AAA9D,yGAAA,SAAS,OAAA;AAClB,6CAAyC;AAAhC,uGAAA,QAAQ,OAAA;AACjB,mEAA+D;AAAtD,6HAAA,mBAAmB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/smart-contract/builtin-libs/index.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AAAxC,+GAAA,YAAY,OAAA;AACrB,2CAAuC;AAA9B,qGAAA,OAAO,OAAA;AAChB,iDAA6C;AAApC,2GAAA,UAAU,OAAA;AACnB,6CAAyC;AAAhC,uGAAA,QAAQ,OAAA;AACjB,+CAAuE;AAA9D,yGAAA,SAAS,OAAA;AAClB,6CAAyC;AAAhC,uGAAA,QAAQ,OAAA;AACjB,mEAA+D;AAAtD,6HAAA,mBAAmB,OAAA;AAC5B,2CAAqF;AAA5E,qGAAA,OAAO,OAAA;AAAE,sHAAA,wBAAwB,OAAA;AAAE,gHAAA,kBAAkB,OAAA"}
@@ -40,6 +40,26 @@ class SmartContract extends abstractContract_js_1.AbstractContract {
40
40
  const clazz = this.constructor;
41
41
  return clazz.stateType;
42
42
  }
43
+ /**
44
+ * Get the data of the contract.
45
+ * @returns the data of the contract
46
+ */
47
+ get data() {
48
+ return this._data;
49
+ }
50
+ /**
51
+ * Set the data of the contract.
52
+ * Only stateless contracts (without stateType) can set data.
53
+ * Stateful contracts should use the state property instead.
54
+ * @param value the data to set
55
+ */
56
+ set data(value) {
57
+ if (this.getStateType() !== undefined) {
58
+ throw new Error(`Cannot set data on stateful contract '${this.constructor.name}'. ` +
59
+ `Use 'state' property instead for stateful contracts.`);
60
+ }
61
+ this._data = value;
62
+ }
43
63
  /**
44
64
  * This function is usually called on the frontend.
45
65
  * The contract class needs to call this function before instantiating.
@@ -74,6 +94,8 @@ class SmartContract extends abstractContract_js_1.AbstractContract {
74
94
  if (!SmartContract.newFromCreate) {
75
95
  this.initLockingScript(...args);
76
96
  }
97
+ // init
98
+ this._data = (0, byteString_js_1.toByteString)('');
77
99
  }
78
100
  /**
79
101
  * @ignore