@opcat-labs/scrypt-ts-opcat 2.0.1-beta-4e9e00a1-20251208 → 2.0.2

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 (72) hide show
  1. package/assets/.templates/smart-contract/builtin-libs/p2pk.scrypt.map +1 -1
  2. package/assets/.templates/smart-contract/builtin-libs/p2pk.scrypt.tpl +0 -3
  3. package/assets/.templates/smart-contract/builtin-libs/p2pkh.scrypt.map +1 -1
  4. package/assets/.templates/smart-contract/builtin-libs/p2pkh.scrypt.tpl +0 -3
  5. package/assets/smart-contract/builtin-libs/backtrace.scrypt +12 -12
  6. package/assets/smart-contract/builtin-libs/byteStringReader.scrypt +5 -5
  7. package/assets/smart-contract/builtin-libs/byteStringWriter.scrypt +6 -6
  8. package/assets/smart-contract/builtin-libs/contextUtils.scrypt +16 -16
  9. package/assets/smart-contract/builtin-libs/p2pk.scrypt +1 -4
  10. package/assets/smart-contract/builtin-libs/p2pkh.scrypt +1 -4
  11. package/assets/smart-contract/builtin-libs/stateLib.scrypt +1 -1
  12. package/assets/smart-contract/builtin-libs/stateUtils.scrypt +1 -1
  13. package/assets/smart-contract/builtin-libs/stdUtils.scrypt +12 -12
  14. package/assets/smart-contract/builtin-libs/txHashPreimageUtils.scrypt +7 -7
  15. package/assets/smart-contract/builtin-libs/txUtils.scrypt +12 -12
  16. package/assets/smart-contract/types/structs.scrypt +8 -8
  17. package/dist/cjs/providers/dummyProvider.cjs +0 -10
  18. package/dist/cjs/providers/dummyProvider.js.map +1 -1
  19. package/dist/cjs/providers/mempoolProvider.cjs +0 -44
  20. package/dist/cjs/providers/mempoolProvider.js.map +1 -1
  21. package/dist/cjs/providers/rpcProvider.cjs +3 -46
  22. package/dist/cjs/providers/rpcProvider.js.map +1 -1
  23. package/dist/cjs/psbt/extPsbt.cjs +1 -8
  24. package/dist/cjs/psbt/extPsbt.js.map +1 -1
  25. package/dist/cjs/psbt/psbt.cjs +1 -3
  26. package/dist/cjs/psbt/psbt.js.map +1 -1
  27. package/dist/cjs/smart-contract/builtin-libs/index.cjs +1 -5
  28. package/dist/cjs/smart-contract/builtin-libs/index.js.map +1 -1
  29. package/dist/cjs/smart-contract/smartContract.cjs +0 -22
  30. package/dist/cjs/smart-contract/smartContract.js.map +1 -1
  31. package/dist/esm/providers/dummyProvider.js +0 -10
  32. package/dist/esm/providers/dummyProvider.js.map +1 -1
  33. package/dist/esm/providers/mempoolProvider.js +0 -44
  34. package/dist/esm/providers/mempoolProvider.js.map +1 -1
  35. package/dist/esm/providers/rpcProvider.js +2 -45
  36. package/dist/esm/providers/rpcProvider.js.map +1 -1
  37. package/dist/esm/psbt/extPsbt.js +1 -8
  38. package/dist/esm/psbt/extPsbt.js.map +1 -1
  39. package/dist/esm/psbt/psbt.js +1 -3
  40. package/dist/esm/psbt/psbt.js.map +1 -1
  41. package/dist/esm/smart-contract/builtin-libs/index.js +0 -1
  42. package/dist/esm/smart-contract/builtin-libs/index.js.map +1 -1
  43. package/dist/esm/smart-contract/smartContract.js +1 -23
  44. package/dist/esm/smart-contract/smartContract.js.map +1 -1
  45. package/dist/types/providers/chainProvider.d.ts +0 -12
  46. package/dist/types/providers/chainProvider.d.ts.map +1 -1
  47. package/dist/types/providers/dummyProvider.d.ts +2 -4
  48. package/dist/types/providers/dummyProvider.d.ts.map +1 -1
  49. package/dist/types/providers/mempoolProvider.d.ts +2 -4
  50. package/dist/types/providers/mempoolProvider.d.ts.map +1 -1
  51. package/dist/types/providers/rpcProvider.d.ts +2 -4
  52. package/dist/types/providers/rpcProvider.d.ts.map +1 -1
  53. package/dist/types/psbt/extPsbt.d.ts.map +1 -1
  54. package/dist/types/psbt/psbt.d.ts.map +1 -1
  55. package/dist/types/smart-contract/builtin-libs/index.d.ts +0 -1
  56. package/dist/types/smart-contract/builtin-libs/index.d.ts.map +1 -1
  57. package/dist/types/smart-contract/smartContract.d.ts +0 -20
  58. package/dist/types/smart-contract/smartContract.d.ts.map +1 -1
  59. package/package.json +3 -4
  60. package/scrypt.index.json +0 -4
  61. package/src/smart-contract/builtin-libs/index.ts +1 -2
  62. package/assets/.templates/smart-contract/builtin-libs/genesis.scrypt.map +0 -1
  63. package/assets/.templates/smart-contract/builtin-libs/genesis.scrypt.tpl +0 -32
  64. package/assets/.templates/smart-contract/builtin-libs/genesis.transformer.json +0 -9
  65. package/assets/smart-contract/builtin-libs/genesis.scrypt +0 -34
  66. package/dist/cjs/smart-contract/builtin-libs/genesis.cjs +0 -201
  67. package/dist/cjs/smart-contract/builtin-libs/genesis.js.map +0 -1
  68. package/dist/esm/smart-contract/builtin-libs/genesis.js +0 -197
  69. package/dist/esm/smart-contract/builtin-libs/genesis.js.map +0 -1
  70. package/dist/types/smart-contract/builtin-libs/genesis.d.ts +0 -67
  71. package/dist/types/smart-contract/builtin-libs/genesis.d.ts.map +0 -1
  72. package/src/smart-contract/builtin-libs/genesis.ts +0 -203
@@ -1,203 +0,0 @@
1
- import { SmartContract } from '../smartContract.js';
2
- import { method, tags } from '../decorators.js';
3
- import { assert, toByteString, len, sha256, fill } from '../fns/index.js';
4
- import { FixedArray, TxOut } from '../types/index.js';
5
- import { TxUtils } from './txUtils.js';
6
- import { ContractCall } from '../../psbt/types.js';
7
- import { uint8ArrayToHex } from '../../utils/common.js';
8
-
9
- /**
10
- * Maximum number of outputs to check during genesis deployment
11
- */
12
- export const MAX_GENESIS_CHECK_OUTPUT = 3;
13
-
14
- /**
15
- * Genesis contract for validating initial deployment outputs.
16
- *
17
- * This contract ensures that during deployment, all non-empty outputs have
18
- * distinct script hashes, preventing duplicate deployments to the same address.
19
- * Empty scriptHashes (represented by empty ByteString) are treated as placeholders
20
- * and are not validated for uniqueness.
21
- *
22
- * @category Contract
23
- * @category Genesis
24
- * @onchain
25
- */
26
- @tags(['GENESIS'])
27
- export class Genesis extends SmartContract {
28
- constructor() {
29
- // eslint-disable-next-line prefer-rest-params
30
- super(...arguments);
31
- }
32
-
33
- /**
34
- * Validates the deployment transaction outputs.
35
- *
36
- * This method performs the following checks:
37
- * 1. Serializes all non-empty output data (scriptHash, satoshis, dataHash)
38
- * 2. Ensures all non-empty script hashes are unique
39
- * 3. Verifies the serialized outputs match the transaction context
40
- *
41
- * Empty scriptHashes (len == 0) are treated as placeholders and are skipped
42
- * in both serialization and uniqueness validation.
43
- *
44
- * @param outputs - Fixed array of 3 transaction outputs to validate
45
- * @throws {Error} If any two non-empty outputs have the same scriptHash
46
- * @throws {Error} If outputs don't match the transaction context
47
- * @onchain
48
- */
49
- @method()
50
- public checkDeploy(outputs: FixedArray<TxOut, typeof MAX_GENESIS_CHECK_OUTPUT>) {
51
- // Serialize all outputs
52
- let outputBytes = toByteString('');
53
- for (let index = 0; index < MAX_GENESIS_CHECK_OUTPUT; index++) {
54
- const _output = outputs[index];
55
- if (len(_output.scriptHash) > 0n) {
56
- outputBytes += TxUtils.buildDataOutput(
57
- _output.scriptHash,
58
- _output.satoshis,
59
- _output.dataHash,
60
- );
61
- }
62
- }
63
-
64
- // Ensure all non-empty script hashes are unique (no duplicate deployments)
65
- // Empty scriptHashes (len == 0) are placeholders and should be skipped
66
- if (len(outputs[0].scriptHash) > 0n && len(outputs[1].scriptHash) > 0n) {
67
- assert(
68
- outputs[0].scriptHash != outputs[1].scriptHash,
69
- 'Duplicate scriptHash: outputs[0] and outputs[1] have the same scriptHash',
70
- );
71
- }
72
- if (len(outputs[0].scriptHash) > 0n && len(outputs[2].scriptHash) > 0n) {
73
- assert(
74
- outputs[0].scriptHash != outputs[2].scriptHash,
75
- 'Duplicate scriptHash: outputs[0] and outputs[2] have the same scriptHash',
76
- );
77
- }
78
- if (len(outputs[1].scriptHash) > 0n && len(outputs[2].scriptHash) > 0n) {
79
- assert(
80
- outputs[1].scriptHash != outputs[2].scriptHash,
81
- 'Duplicate scriptHash: outputs[1] and outputs[2] have the same scriptHash',
82
- );
83
- }
84
-
85
- // Verify outputs match the transaction context
86
- assert(this.checkOutputs(outputBytes), 'Outputs mismatch with the transaction context');
87
- }
88
- }
89
-
90
- /**
91
- * Creates a contract call function for Genesis.checkDeploy that automatically
92
- * builds the TxOut array from the transaction outputs.
93
- *
94
- * This function handles the conversion of transaction outputs to the TxOut format
95
- * required by the Genesis contract, including:
96
- * - Creating empty placeholders for unused output slots
97
- * - Computing scriptHash and dataHash for each output
98
- * - Limiting to MAX_GENESIS_CHECK_OUTPUT (3) outputs
99
- *
100
- * @returns A ContractCall function that can be used with ExtPsbt.addContractInput
101
- *
102
- * @example
103
- * ```typescript
104
- * const genesis = new Genesis();
105
- * genesis.bindToUtxo(genesisUtxo);
106
- *
107
- * const deployPsbt = new ExtPsbt({ network })
108
- * .addContractInput(genesis, genesisCheckDeploy())
109
- * .addContractOutput(minter, Postage.MINTER_POSTAGE)
110
- * .change(changeAddress, feeRate)
111
- * .seal();
112
- * ```
113
- *
114
- * @category Genesis
115
- */
116
- export function genesisCheckDeploy(): ContractCall<Genesis> {
117
- return (contract, psbt) => {
118
- // Create output array with empty placeholders
119
- const emptyOutput: TxOut = {
120
- scriptHash: toByteString(''),
121
- satoshis: 0n,
122
- dataHash: sha256(toByteString('')),
123
- };
124
- const outputs: TxOut[] = fill(emptyOutput, MAX_GENESIS_CHECK_OUTPUT);
125
-
126
- // Fill with actual outputs from the transaction
127
- const txOutputs = psbt.txOutputs;
128
- for (let i = 0; i < txOutputs.length && i < MAX_GENESIS_CHECK_OUTPUT; i++) {
129
- const output = txOutputs[i];
130
- outputs[i] = {
131
- scriptHash: sha256(toByteString(uint8ArrayToHex(output.script))),
132
- satoshis: BigInt(output.value),
133
- dataHash: sha256(toByteString(uint8ArrayToHex(output.data))),
134
- };
135
- }
136
-
137
- contract.checkDeploy(outputs as FixedArray<TxOut, typeof MAX_GENESIS_CHECK_OUTPUT>);
138
- };
139
- }
140
-
141
- // Embedded artifact for Genesis contract
142
- const desc = {
143
- version: 10,
144
- compilerVersion: '1.21.0+commit.2ada378',
145
- contract: 'Genesis',
146
- md5: 'd3404c4b368255eec0f93e2d868e4510',
147
- structs: [
148
- {
149
- name: 'TxOut',
150
- params: [
151
- { name: 'scriptHash', type: 'bytes' },
152
- { name: 'dataHash', type: 'bytes' },
153
- { name: 'satoshis', type: 'int' },
154
- ],
155
- genericTypes: [],
156
- },
157
- {
158
- name: 'SHPreimage',
159
- params: [
160
- { name: 'nVersion', type: 'bytes' },
161
- { name: 'hashPrevouts', type: 'bytes' },
162
- { name: 'spentScriptHash', type: 'bytes' },
163
- { name: 'spentDataHash', type: 'bytes' },
164
- { name: 'value', type: 'int' },
165
- { name: 'nSequence', type: 'bytes' },
166
- { name: 'hashSpentAmounts', type: 'bytes' },
167
- { name: 'hashSpentScriptHashes', type: 'bytes' },
168
- { name: 'hashSpentDataHashes', type: 'bytes' },
169
- { name: 'hashSequences', type: 'bytes' },
170
- { name: 'hashOutputs', type: 'bytes' },
171
- { name: 'inputIndex', type: 'int' },
172
- { name: 'nLockTime', type: 'int' },
173
- { name: 'sigHashType', type: 'int' },
174
- ],
175
- genericTypes: [],
176
- },
177
- ],
178
- library: [
179
- { name: 'TxUtils', params: [], properties: [], genericTypes: [] },
180
- { name: 'ContextUtils', params: [], properties: [], genericTypes: [] },
181
- { name: 'StdUtils', params: [], properties: [], genericTypes: [] },
182
- ],
183
- alias: [],
184
- abi: [
185
- {
186
- type: 'function',
187
- name: 'checkDeploy',
188
- index: 0,
189
- params: [
190
- { name: 'outputs', type: 'TxOut[3]' },
191
- { name: '__scrypt_ts_shPreimage', type: 'SHPreimage' },
192
- ],
193
- },
194
- { type: 'constructor', params: [] },
195
- ],
196
- stateProps: [],
197
- buildType: 'release',
198
- file: '',
199
- hex: '512097dfd76851bf465e8f715593b217714858bbe9570ff3bd5e33840a34e20ff0262102ba79df5f8ae7604a9830f03c7933028186aede0675a16f025dc4f8be8eec0382201008ce7480da41702918d1ec8e6849ba32b4d65b1e40dc669c31a1e6306b266c0111790111790111790111790111790111790111790111790111790111790111790111790111790111795d798277549d5c79827701209d5b79827701209d5a79827701209d597900a26958798277549d5779827701209d5679827701209d5579827701209d5479827701209d5379827701209d527900a2697800a26976519c6476529c6751686476539c67516864760281009c67516864760282009c67516864760283009c675168695d795d797e5c797e5b797e5a79767600a2637609ffffffffffffffff00a16700686976586e8b806e7c7f75007f6b6d6d6d6c7e59797e58797e57797e56797e55797e54797e5379546e8b806e7c7f75007f6b6d6d6c7e5279546e8b806e7c7f75007f6b6d6d6c7e7854807e6b6d6d6d6d6d6d6d6c54797855795579210ac407f0e4bd44bfc207355a778b046225a7068fc59ee7eda43ad905aadbffc800206c266b30e6a1319c66dc401e5bd6b432ba49688eecd118297041da8074ce0810577956795679aa7676517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01007e817757795679567956795679537956795479577995939521414136d08c5ed2bf3ba048afe6dcaebafeffffffffffffffffffffffffffffff006e6e9776009f636e936776687777777b757c6e5296a0636e7c947b757c6853798277527982775379012080517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01205279947f77545379935279930130787e527e54797e58797e527e53797e52797e57797e6b6d6d6d6d6d6d6c765779ac6b6d6d6d6d6d6c776900011b766b796c766b796c766b796c755279827700a06370707c527982777882777801209d7601209d537900a2695379767600a2637609ffffffffffffffff00a16700686976586e8b806e7c7f75007f6b6d6d6d6c55797e53797e6b6d6d6c777e547a7572537a537975686d750118766b796c766b796c766b796c755279827700a06370707c527982777882777801209d7601209d537900a2695379767600a2637609ffffffffffffffff00a16700686976586e8b806e7c7f75007f6b6d6d6d6c55797e53797e6b6d6d6c777e547a7572537a537975686d750115766b796c766b796c766b796c755279827700a06370707c527982777882777801209d7601209d537900a2695379767600a2637609ffffffffffffffff00a16700686976586e8b806e7c7f75007f6b6d6d6d6c55797e53797e6b6d6d6c777e547a7572537a537975686d75011b766b796c766b796c766b796c6d7c77827700a0630118766b796c766b796c766b796c6d7c77827700a067006863011b766b796c766b796c766b796c6d7c770119766b796c766b796c766b796c6d7c7787916968011b766b796c766b796c766b796c6d7c77827700a0630115766b796c766b796c766b796c6d7c77827700a067006863011b766b796c766b796c766b796c6d7c770116766b796c766b796c766b796c6d7c77879169680118766b796c766b796c766b796c6d7c77827700a0630115766b796c766b796c766b796c6d7c77827700a0670068630118766b796c766b796c766b796c6d7c770116766b796c766b796c766b796c6d7c778791696876aa5979876b6d6d6d6d6d6d6d6d6d6d6d6d6d6d6c',
200
- sourceMapFile: '',
201
- };
202
-
203
- Genesis.loadArtifact(desc);