@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.
package/README.md CHANGED
@@ -292,9 +292,13 @@ custodial DEX, no off-chain matching, no second signature from the
292
292
  seller.
293
293
 
294
294
  The covenant is **stateful via UTXO continuity**. The output at `vout[2]`
295
- of every fill must carry the same `scriptPubKey` as the input being
296
- spent (enforced on the fly by `OP_OUTPUTSCRIPT == OP_TXFIELD 0x03`), so
297
- the covenant self-replicates without hardcoding its own hash. The
295
+ of every fill must carry the same AuthScript v1 commitment as the input
296
+ being spent (enforced on the fly by
297
+ `OP_OUTPUTAUTHCOMMITMENT == OP_TXFIELD 0x02`, NIP-023), so the covenant
298
+ self-replicates without hardcoding its own hash. Earlier drafts compared
299
+ full scriptPubKeys via `OP_OUTPUTSCRIPT`, but that is unsatisfiable on
300
+ asset-wrapped covenant UTXOs because the remainder's asset wrapper
301
+ encodes a different `amountRaw` than the spent UTXO's. The
298
302
  remaining asset quantity is read directly from the input via
299
303
  `OP_INPUTASSETFIELD` and the subtraction `inputAmount − N` is verified,
300
304
  so the same script works for any remainder as the lot drains. Asset
@@ -402,7 +406,7 @@ OP_ELSE
402
406
  <0> OP_OUTPUTSCRIPT <sellerP2PKH> OP_EQUALVERIFY // payment dest
403
407
  OP_DUP <1> <0x02> OP_OUTPUTASSETFIELD OP_EQUALVERIFY // buyer amount == N
404
408
  <1> <0x01> OP_OUTPUTASSETFIELD <tokenId> OP_EQUALVERIFY // buyer name == tokenId
405
- <2> OP_OUTPUTSCRIPT <0x03> OP_TXFIELD OP_EQUALVERIFY // continuity
409
+ <2> OP_OUTPUTAUTHCOMMITMENT <0x02> OP_TXFIELD OP_EQUALVERIFY // continuity (NIP-023)
406
410
  <2> <0x01> OP_OUTPUTASSETFIELD <tokenId> OP_EQUALVERIFY // remainder name
407
411
  <2> <0x02> OP_OUTPUTASSETFIELD OP_OVER
408
412
  <0> <0x02> OP_INPUTASSETFIELD OP_SWAP OP_SUB OP_EQUALVERIFY // remainder = in - N
@@ -190,6 +190,11 @@ var NeuraiScriptsBundle = (function (exports) {
190
190
  const OP_REFINPUTFIELD = 0xd2;
191
191
  const OP_REFINPUTASSETFIELD = 0xd3;
192
192
  const OP_REFINPUTCOUNT = 0xd4;
193
+ // ---------- Output auth commitment introspection (NIP-023) ----------
194
+ // Pushes the 32-byte AuthScript v1 commitment of a selected output's
195
+ // scriptPubKey. Symmetric to TXFIELD_AUTHSCRIPT_COMMITMENT for inputs;
196
+ // ignores any trailing OP_XNA_ASSET asset wrapper bytes.
197
+ const OP_OUTPUTAUTHCOMMITMENT = 0xd5;
193
198
  // ---------- Byte manipulation (DePIN-Test) ----------
194
199
  const OP_CAT = 0x7e;
195
200
  const OP_SPLIT = 0xb7;
@@ -312,6 +317,7 @@ var NeuraiScriptsBundle = (function (exports) {
312
317
  OP_NUMEQUALVERIFY: OP_NUMEQUALVERIFY,
313
318
  OP_NUMNOTEQUAL: OP_NUMNOTEQUAL,
314
319
  OP_OUTPUTASSETFIELD: OP_OUTPUTASSETFIELD,
320
+ OP_OUTPUTAUTHCOMMITMENT: OP_OUTPUTAUTHCOMMITMENT,
315
321
  OP_OUTPUTCOUNT: OP_OUTPUTCOUNT,
316
322
  OP_OUTPUTSCRIPT: OP_OUTPUTSCRIPT,
317
323
  OP_OUTPUTVALUE: OP_OUTPUTVALUE,
@@ -1755,12 +1761,16 @@ var NeuraiScriptsBundle = (function (exports) {
1755
1761
  *
1756
1762
  * output[0] = XNA payment to seller (value >= N * unitPriceSats)
1757
1763
  * output[1] = asset to buyer (tokenId, amount == N)
1758
- * output[2] = covenant remainder (same scriptPubKey, amount == in - N)
1764
+ * output[2] = covenant remainder (same AuthScript commitment, amount == in - N)
1759
1765
  * output[3+] = optional buyer change (not constrained by the covenant)
1760
1766
  *
1761
- * The remainder UTXO reuses the spent scriptPubKey via
1762
- * `OP_OUTPUTSCRIPT == OP_TXFIELD 0x03`, so the covenant is self-replicating
1763
- * without hardcoding its own hash.
1767
+ * The remainder UTXO reuses the spent covenant's AuthScript v1 commitment
1768
+ * via `OP_OUTPUTAUTHCOMMITMENT(2) == OP_TXFIELD(0x02)` (NIP-023). Comparing
1769
+ * commitments rather than full scriptPubKeys is mandatory here: the
1770
+ * remainder output's asset wrapper (`OP_XNA_ASSET ... OP_DROP`) encodes a
1771
+ * smaller `amountRaw` than the spent UTXO's wrapper, so the full-spk
1772
+ * equality used by earlier drafts was vacuously unsatisfiable on any
1773
+ * asset-wrapped covenant UTXO.
1764
1774
  *
1765
1775
  * The cancel branch uses classical ECDSA (`OP_HASH160 + OP_CHECKSIG`) and
1766
1776
  * commits to a 20-byte PKH. As a consequence this variant only accepts
@@ -1857,11 +1867,14 @@ var NeuraiScriptsBundle = (function (exports) {
1857
1867
  .op(OP_OUTPUTASSETFIELD) // [ N, name_out1 ]
1858
1868
  .pushBytes(tokenIdBytes)
1859
1869
  .op(OP_EQUALVERIFY); // [ N ]
1860
- // 5. Remainder covenant continuity (output 2): same scriptPubKey as spent
1870
+ // 5. Remainder covenant continuity (output 2): same AuthScript commitment
1871
+ // as spent. NIP-023: comparing 32-byte commitments rather than full
1872
+ // scriptPubKeys, because the remainder's asset wrapper carries a
1873
+ // different `amountRaw` than the spent UTXO's wrapper.
1861
1874
  b.pushInt(2)
1862
- .op(OP_OUTPUTSCRIPT) // [ N, spk_out2 ]
1863
- .pushInt(TXFIELD_SCRIPTPUBKEY)
1864
- .op(OP_TXFIELD) // [ N, spk_out2, spent_spk ]
1875
+ .op(OP_OUTPUTAUTHCOMMITMENT) // [ N, auth_out2 ]
1876
+ .pushInt(TXFIELD_AUTHSCRIPT_COMMITMENT)
1877
+ .op(OP_TXFIELD) // [ N, auth_out2, spent_auth ]
1865
1878
  .op(OP_EQUALVERIFY); // [ N ]
1866
1879
  // 6. Remainder output: same tokenId
1867
1880
  b.pushInt(2)
@@ -2012,10 +2025,12 @@ var NeuraiScriptsBundle = (function (exports) {
2012
2025
  .op(OP_OUTPUTASSETFIELD)
2013
2026
  .pushBytes(tokenIdBytes)
2014
2027
  .op(OP_EQUALVERIFY);
2015
- // 5. Remainder continuity (output 2) — same scriptPubKey as spent
2028
+ // 5. Remainder continuity (output 2) — same AuthScript commitment as spent
2029
+ // (NIP-023; see script.ts for why full-spk equality is unsatisfiable on
2030
+ // asset-wrapped covenant UTXOs).
2016
2031
  b.pushInt(2)
2017
- .op(OP_OUTPUTSCRIPT)
2018
- .pushInt(TXFIELD_SCRIPTPUBKEY)
2032
+ .op(OP_OUTPUTAUTHCOMMITMENT)
2033
+ .pushInt(TXFIELD_AUTHSCRIPT_COMMITMENT)
2019
2034
  .op(OP_TXFIELD)
2020
2035
  .op(OP_EQUALVERIFY);
2021
2036
  // 6. Remainder tokenId
@@ -2361,12 +2376,12 @@ var NeuraiScriptsBundle = (function (exports) {
2361
2376
  expectByte(c, OP_OUTPUTASSETFIELD, 'OP_OUTPUTASSETFIELD (buyer name)');
2362
2377
  const tokenIdBytes1 = readPush(c, 'tokenId #1');
2363
2378
  expectByte(c, OP_EQUALVERIFY, 'OP_EQUALVERIFY (buyer name)');
2364
- // ───── Remainder continuity: same scriptPubKey ─────
2379
+ // ───── Remainder continuity: same AuthScript commitment (NIP-023) ─────
2365
2380
  expectByte(c, OP_2, 'OP_2 (remainder idx)');
2366
- expectByte(c, OP_OUTPUTSCRIPT, 'OP_OUTPUTSCRIPT (remainder)');
2367
- expectByte(c, OP_3, 'OP_3 (TXFIELD selector)');
2381
+ expectByte(c, OP_OUTPUTAUTHCOMMITMENT, 'OP_OUTPUTAUTHCOMMITMENT (remainder)');
2382
+ expectByte(c, OP_2, 'OP_2 (TXFIELD selector: AUTHSCRIPT_COMMITMENT)');
2368
2383
  expectByte(c, OP_TXFIELD, 'OP_TXFIELD');
2369
- expectByte(c, OP_EQUALVERIFY, 'OP_EQUALVERIFY (remainder spk)');
2384
+ expectByte(c, OP_EQUALVERIFY, 'OP_EQUALVERIFY (remainder auth)');
2370
2385
  // ───── Remainder tokenId check ─────
2371
2386
  expectByte(c, OP_2, 'OP_2 (remainder idx)');
2372
2387
  expectByte(c, OP_1, 'OP_1 (NAME selector)');
@@ -2467,11 +2482,12 @@ var NeuraiScriptsBundle = (function (exports) {
2467
2482
  expectByte(c, OP_OUTPUTASSETFIELD, 'OP_OUTPUTASSETFIELD (buyer name)');
2468
2483
  const tokenIdBytes1 = readPush(c, 'tokenId #1');
2469
2484
  expectByte(c, OP_EQUALVERIFY, 'OP_EQUALVERIFY (buyer name)');
2485
+ // Remainder continuity: same AuthScript commitment (NIP-023)
2470
2486
  expectByte(c, OP_2, 'OP_2 (remainder idx)');
2471
- expectByte(c, OP_OUTPUTSCRIPT, 'OP_OUTPUTSCRIPT (remainder)');
2472
- expectByte(c, OP_3, 'OP_3 (TXFIELD selector)');
2487
+ expectByte(c, OP_OUTPUTAUTHCOMMITMENT, 'OP_OUTPUTAUTHCOMMITMENT (remainder)');
2488
+ expectByte(c, OP_2, 'OP_2 (TXFIELD selector: AUTHSCRIPT_COMMITMENT)');
2473
2489
  expectByte(c, OP_TXFIELD, 'OP_TXFIELD');
2474
- expectByte(c, OP_EQUALVERIFY, 'OP_EQUALVERIFY (remainder spk)');
2490
+ expectByte(c, OP_EQUALVERIFY, 'OP_EQUALVERIFY (remainder auth)');
2475
2491
  expectByte(c, OP_2, 'OP_2 (remainder idx)');
2476
2492
  expectByte(c, OP_1, 'OP_1 (NAME selector)');
2477
2493
  expectByte(c, OP_OUTPUTASSETFIELD, 'OP_OUTPUTASSETFIELD (remainder name)');