@neuraiproject/neurai-scripts 0.3.0 → 0.4.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.
@@ -121,6 +121,7 @@ export declare const OP_XNA_ASSET = 192;
121
121
  export declare const OP_REFINPUTFIELD = 210;
122
122
  export declare const OP_REFINPUTASSETFIELD = 211;
123
123
  export declare const OP_REFINPUTCOUNT = 212;
124
+ export declare const OP_OUTPUTAUTHCOMMITMENT = 213;
124
125
  export declare const OP_CAT = 126;
125
126
  export declare const OP_SPLIT = 183;
126
127
  export declare const OP_REVERSEBYTES = 188;
@@ -13,12 +13,16 @@
13
13
  *
14
14
  * output[0] = XNA payment to seller (value >= N * unitPriceSats)
15
15
  * output[1] = asset to buyer (tokenId, amount == N)
16
- * output[2] = covenant remainder (same scriptPubKey, amount == in - N)
16
+ * output[2] = covenant remainder (same AuthScript commitment, amount == in - N)
17
17
  * output[3+] = optional buyer change (not constrained by the covenant)
18
18
  *
19
- * The remainder UTXO reuses the spent scriptPubKey via
20
- * `OP_OUTPUTSCRIPT == OP_TXFIELD 0x03`, so the covenant is self-replicating
21
- * without hardcoding its own hash.
19
+ * The remainder UTXO reuses the spent covenant's AuthScript v1 commitment
20
+ * via `OP_OUTPUTAUTHCOMMITMENT(2) == OP_TXFIELD(0x02)` (NIP-023). Comparing
21
+ * commitments rather than full scriptPubKeys is mandatory here: the
22
+ * remainder output's asset wrapper (`OP_XNA_ASSET ... OP_DROP`) encodes a
23
+ * smaller `amountRaw` than the spent UTXO's wrapper, so the full-spk
24
+ * equality used by earlier drafts was vacuously unsatisfiable on any
25
+ * asset-wrapped covenant UTXO.
22
26
  *
23
27
  * The cancel branch uses classical ECDSA (`OP_HASH160 + OP_CHECKSIG`) and
24
28
  * commits to a 20-byte PKH. As a consequence this variant only accepts
package/dist/index.cjs CHANGED
@@ -189,6 +189,11 @@ const OP_XNA_ASSET = 0xc0;
189
189
  const OP_REFINPUTFIELD = 0xd2;
190
190
  const OP_REFINPUTASSETFIELD = 0xd3;
191
191
  const OP_REFINPUTCOUNT = 0xd4;
192
+ // ---------- Output auth commitment introspection (NIP-023) ----------
193
+ // Pushes the 32-byte AuthScript v1 commitment of a selected output's
194
+ // scriptPubKey. Symmetric to TXFIELD_AUTHSCRIPT_COMMITMENT for inputs;
195
+ // ignores any trailing OP_XNA_ASSET asset wrapper bytes.
196
+ const OP_OUTPUTAUTHCOMMITMENT = 0xd5;
192
197
  // ---------- Byte manipulation (DePIN-Test) ----------
193
198
  const OP_CAT = 0x7e;
194
199
  const OP_SPLIT = 0xb7;
@@ -311,6 +316,7 @@ var opcodes = /*#__PURE__*/Object.freeze({
311
316
  OP_NUMEQUALVERIFY: OP_NUMEQUALVERIFY,
312
317
  OP_NUMNOTEQUAL: OP_NUMNOTEQUAL,
313
318
  OP_OUTPUTASSETFIELD: OP_OUTPUTASSETFIELD,
319
+ OP_OUTPUTAUTHCOMMITMENT: OP_OUTPUTAUTHCOMMITMENT,
314
320
  OP_OUTPUTCOUNT: OP_OUTPUTCOUNT,
315
321
  OP_OUTPUTSCRIPT: OP_OUTPUTSCRIPT,
316
322
  OP_OUTPUTVALUE: OP_OUTPUTVALUE,
@@ -1754,12 +1760,16 @@ function splitAssetWrappedScriptPubKey(spkHex) {
1754
1760
  *
1755
1761
  * output[0] = XNA payment to seller (value >= N * unitPriceSats)
1756
1762
  * output[1] = asset to buyer (tokenId, amount == N)
1757
- * output[2] = covenant remainder (same scriptPubKey, amount == in - N)
1763
+ * output[2] = covenant remainder (same AuthScript commitment, amount == in - N)
1758
1764
  * output[3+] = optional buyer change (not constrained by the covenant)
1759
1765
  *
1760
- * The remainder UTXO reuses the spent scriptPubKey via
1761
- * `OP_OUTPUTSCRIPT == OP_TXFIELD 0x03`, so the covenant is self-replicating
1762
- * without hardcoding its own hash.
1766
+ * The remainder UTXO reuses the spent covenant's AuthScript v1 commitment
1767
+ * via `OP_OUTPUTAUTHCOMMITMENT(2) == OP_TXFIELD(0x02)` (NIP-023). Comparing
1768
+ * commitments rather than full scriptPubKeys is mandatory here: the
1769
+ * remainder output's asset wrapper (`OP_XNA_ASSET ... OP_DROP`) encodes a
1770
+ * smaller `amountRaw` than the spent UTXO's wrapper, so the full-spk
1771
+ * equality used by earlier drafts was vacuously unsatisfiable on any
1772
+ * asset-wrapped covenant UTXO.
1763
1773
  *
1764
1774
  * The cancel branch uses classical ECDSA (`OP_HASH160 + OP_CHECKSIG`) and
1765
1775
  * commits to a 20-byte PKH. As a consequence this variant only accepts
@@ -1856,11 +1866,14 @@ function buildPartialFillScript(params) {
1856
1866
  .op(OP_OUTPUTASSETFIELD) // [ N, name_out1 ]
1857
1867
  .pushBytes(tokenIdBytes)
1858
1868
  .op(OP_EQUALVERIFY); // [ N ]
1859
- // 5. Remainder covenant continuity (output 2): same scriptPubKey as spent
1869
+ // 5. Remainder covenant continuity (output 2): same AuthScript commitment
1870
+ // as spent. NIP-023: comparing 32-byte commitments rather than full
1871
+ // scriptPubKeys, because the remainder's asset wrapper carries a
1872
+ // different `amountRaw` than the spent UTXO's wrapper.
1860
1873
  b.pushInt(2)
1861
- .op(OP_OUTPUTSCRIPT) // [ N, spk_out2 ]
1862
- .pushInt(TXFIELD_SCRIPTPUBKEY)
1863
- .op(OP_TXFIELD) // [ N, spk_out2, spent_spk ]
1874
+ .op(OP_OUTPUTAUTHCOMMITMENT) // [ N, auth_out2 ]
1875
+ .pushInt(TXFIELD_AUTHSCRIPT_COMMITMENT)
1876
+ .op(OP_TXFIELD) // [ N, auth_out2, spent_auth ]
1864
1877
  .op(OP_EQUALVERIFY); // [ N ]
1865
1878
  // 6. Remainder output: same tokenId
1866
1879
  b.pushInt(2)
@@ -2011,10 +2024,12 @@ function buildPartialFillScriptPQ(params) {
2011
2024
  .op(OP_OUTPUTASSETFIELD)
2012
2025
  .pushBytes(tokenIdBytes)
2013
2026
  .op(OP_EQUALVERIFY);
2014
- // 5. Remainder continuity (output 2) — same scriptPubKey as spent
2027
+ // 5. Remainder continuity (output 2) — same AuthScript commitment as spent
2028
+ // (NIP-023; see script.ts for why full-spk equality is unsatisfiable on
2029
+ // asset-wrapped covenant UTXOs).
2015
2030
  b.pushInt(2)
2016
- .op(OP_OUTPUTSCRIPT)
2017
- .pushInt(TXFIELD_SCRIPTPUBKEY)
2031
+ .op(OP_OUTPUTAUTHCOMMITMENT)
2032
+ .pushInt(TXFIELD_AUTHSCRIPT_COMMITMENT)
2018
2033
  .op(OP_TXFIELD)
2019
2034
  .op(OP_EQUALVERIFY);
2020
2035
  // 6. Remainder tokenId
@@ -2360,12 +2375,12 @@ function parsePartialFillScript(script, network = 'xna-test') {
2360
2375
  expectByte(c, OP_OUTPUTASSETFIELD, 'OP_OUTPUTASSETFIELD (buyer name)');
2361
2376
  const tokenIdBytes1 = readPush(c, 'tokenId #1');
2362
2377
  expectByte(c, OP_EQUALVERIFY, 'OP_EQUALVERIFY (buyer name)');
2363
- // ───── Remainder continuity: same scriptPubKey ─────
2378
+ // ───── Remainder continuity: same AuthScript commitment (NIP-023) ─────
2364
2379
  expectByte(c, OP_2, 'OP_2 (remainder idx)');
2365
- expectByte(c, OP_OUTPUTSCRIPT, 'OP_OUTPUTSCRIPT (remainder)');
2366
- expectByte(c, OP_3, 'OP_3 (TXFIELD selector)');
2380
+ expectByte(c, OP_OUTPUTAUTHCOMMITMENT, 'OP_OUTPUTAUTHCOMMITMENT (remainder)');
2381
+ expectByte(c, OP_2, 'OP_2 (TXFIELD selector: AUTHSCRIPT_COMMITMENT)');
2367
2382
  expectByte(c, OP_TXFIELD, 'OP_TXFIELD');
2368
- expectByte(c, OP_EQUALVERIFY, 'OP_EQUALVERIFY (remainder spk)');
2383
+ expectByte(c, OP_EQUALVERIFY, 'OP_EQUALVERIFY (remainder auth)');
2369
2384
  // ───── Remainder tokenId check ─────
2370
2385
  expectByte(c, OP_2, 'OP_2 (remainder idx)');
2371
2386
  expectByte(c, OP_1, 'OP_1 (NAME selector)');
@@ -2466,11 +2481,12 @@ function parsePartialFillScriptPQ(script, network = 'xna-test') {
2466
2481
  expectByte(c, OP_OUTPUTASSETFIELD, 'OP_OUTPUTASSETFIELD (buyer name)');
2467
2482
  const tokenIdBytes1 = readPush(c, 'tokenId #1');
2468
2483
  expectByte(c, OP_EQUALVERIFY, 'OP_EQUALVERIFY (buyer name)');
2484
+ // Remainder continuity: same AuthScript commitment (NIP-023)
2469
2485
  expectByte(c, OP_2, 'OP_2 (remainder idx)');
2470
- expectByte(c, OP_OUTPUTSCRIPT, 'OP_OUTPUTSCRIPT (remainder)');
2471
- expectByte(c, OP_3, 'OP_3 (TXFIELD selector)');
2486
+ expectByte(c, OP_OUTPUTAUTHCOMMITMENT, 'OP_OUTPUTAUTHCOMMITMENT (remainder)');
2487
+ expectByte(c, OP_2, 'OP_2 (TXFIELD selector: AUTHSCRIPT_COMMITMENT)');
2472
2488
  expectByte(c, OP_TXFIELD, 'OP_TXFIELD');
2473
- expectByte(c, OP_EQUALVERIFY, 'OP_EQUALVERIFY (remainder spk)');
2489
+ expectByte(c, OP_EQUALVERIFY, 'OP_EQUALVERIFY (remainder auth)');
2474
2490
  expectByte(c, OP_2, 'OP_2 (remainder idx)');
2475
2491
  expectByte(c, OP_1, 'OP_1 (NAME selector)');
2476
2492
  expectByte(c, OP_OUTPUTASSETFIELD, 'OP_OUTPUTASSETFIELD (remainder name)');