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