@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 +8 -4
- package/dist/NeuraiScripts.global.js +34 -18
- package/dist/NeuraiScripts.global.js.map +1 -1
- package/dist/browser.js +34 -18
- package/dist/browser.js.map +1 -1
- package/dist/core/opcodes.d.ts +1 -0
- package/dist/covenants/partial-fill/script.d.ts +8 -4
- package/dist/index.cjs +34 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -187,6 +187,11 @@ const OP_XNA_ASSET = 0xc0;
|
|
|
187
187
|
const OP_REFINPUTFIELD = 0xd2;
|
|
188
188
|
const OP_REFINPUTASSETFIELD = 0xd3;
|
|
189
189
|
const OP_REFINPUTCOUNT = 0xd4;
|
|
190
|
+
// ---------- Output auth commitment introspection (NIP-023) ----------
|
|
191
|
+
// Pushes the 32-byte AuthScript v1 commitment of a selected output's
|
|
192
|
+
// scriptPubKey. Symmetric to TXFIELD_AUTHSCRIPT_COMMITMENT for inputs;
|
|
193
|
+
// ignores any trailing OP_XNA_ASSET asset wrapper bytes.
|
|
194
|
+
const OP_OUTPUTAUTHCOMMITMENT = 0xd5;
|
|
190
195
|
// ---------- Byte manipulation (DePIN-Test) ----------
|
|
191
196
|
const OP_CAT = 0x7e;
|
|
192
197
|
const OP_SPLIT = 0xb7;
|
|
@@ -309,6 +314,7 @@ var opcodes = /*#__PURE__*/Object.freeze({
|
|
|
309
314
|
OP_NUMEQUALVERIFY: OP_NUMEQUALVERIFY,
|
|
310
315
|
OP_NUMNOTEQUAL: OP_NUMNOTEQUAL,
|
|
311
316
|
OP_OUTPUTASSETFIELD: OP_OUTPUTASSETFIELD,
|
|
317
|
+
OP_OUTPUTAUTHCOMMITMENT: OP_OUTPUTAUTHCOMMITMENT,
|
|
312
318
|
OP_OUTPUTCOUNT: OP_OUTPUTCOUNT,
|
|
313
319
|
OP_OUTPUTSCRIPT: OP_OUTPUTSCRIPT,
|
|
314
320
|
OP_OUTPUTVALUE: OP_OUTPUTVALUE,
|
|
@@ -1752,12 +1758,16 @@ function splitAssetWrappedScriptPubKey(spkHex) {
|
|
|
1752
1758
|
*
|
|
1753
1759
|
* output[0] = XNA payment to seller (value >= N * unitPriceSats)
|
|
1754
1760
|
* output[1] = asset to buyer (tokenId, amount == N)
|
|
1755
|
-
* output[2] = covenant remainder (same
|
|
1761
|
+
* output[2] = covenant remainder (same AuthScript commitment, amount == in - N)
|
|
1756
1762
|
* output[3+] = optional buyer change (not constrained by the covenant)
|
|
1757
1763
|
*
|
|
1758
|
-
* The remainder UTXO reuses the spent
|
|
1759
|
-
* `
|
|
1760
|
-
*
|
|
1764
|
+
* The remainder UTXO reuses the spent covenant's AuthScript v1 commitment
|
|
1765
|
+
* via `OP_OUTPUTAUTHCOMMITMENT(2) == OP_TXFIELD(0x02)` (NIP-023). Comparing
|
|
1766
|
+
* commitments rather than full scriptPubKeys is mandatory here: the
|
|
1767
|
+
* remainder output's asset wrapper (`OP_XNA_ASSET ... OP_DROP`) encodes a
|
|
1768
|
+
* smaller `amountRaw` than the spent UTXO's wrapper, so the full-spk
|
|
1769
|
+
* equality used by earlier drafts was vacuously unsatisfiable on any
|
|
1770
|
+
* asset-wrapped covenant UTXO.
|
|
1761
1771
|
*
|
|
1762
1772
|
* The cancel branch uses classical ECDSA (`OP_HASH160 + OP_CHECKSIG`) and
|
|
1763
1773
|
* commits to a 20-byte PKH. As a consequence this variant only accepts
|
|
@@ -1854,11 +1864,14 @@ function buildPartialFillScript(params) {
|
|
|
1854
1864
|
.op(OP_OUTPUTASSETFIELD) // [ N, name_out1 ]
|
|
1855
1865
|
.pushBytes(tokenIdBytes)
|
|
1856
1866
|
.op(OP_EQUALVERIFY); // [ N ]
|
|
1857
|
-
// 5. Remainder covenant continuity (output 2): same
|
|
1867
|
+
// 5. Remainder covenant continuity (output 2): same AuthScript commitment
|
|
1868
|
+
// as spent. NIP-023: comparing 32-byte commitments rather than full
|
|
1869
|
+
// scriptPubKeys, because the remainder's asset wrapper carries a
|
|
1870
|
+
// different `amountRaw` than the spent UTXO's wrapper.
|
|
1858
1871
|
b.pushInt(2)
|
|
1859
|
-
.op(
|
|
1860
|
-
.pushInt(
|
|
1861
|
-
.op(OP_TXFIELD) // [ N,
|
|
1872
|
+
.op(OP_OUTPUTAUTHCOMMITMENT) // [ N, auth_out2 ]
|
|
1873
|
+
.pushInt(TXFIELD_AUTHSCRIPT_COMMITMENT)
|
|
1874
|
+
.op(OP_TXFIELD) // [ N, auth_out2, spent_auth ]
|
|
1862
1875
|
.op(OP_EQUALVERIFY); // [ N ]
|
|
1863
1876
|
// 6. Remainder output: same tokenId
|
|
1864
1877
|
b.pushInt(2)
|
|
@@ -2009,10 +2022,12 @@ function buildPartialFillScriptPQ(params) {
|
|
|
2009
2022
|
.op(OP_OUTPUTASSETFIELD)
|
|
2010
2023
|
.pushBytes(tokenIdBytes)
|
|
2011
2024
|
.op(OP_EQUALVERIFY);
|
|
2012
|
-
// 5. Remainder continuity (output 2) — same
|
|
2025
|
+
// 5. Remainder continuity (output 2) — same AuthScript commitment as spent
|
|
2026
|
+
// (NIP-023; see script.ts for why full-spk equality is unsatisfiable on
|
|
2027
|
+
// asset-wrapped covenant UTXOs).
|
|
2013
2028
|
b.pushInt(2)
|
|
2014
|
-
.op(
|
|
2015
|
-
.pushInt(
|
|
2029
|
+
.op(OP_OUTPUTAUTHCOMMITMENT)
|
|
2030
|
+
.pushInt(TXFIELD_AUTHSCRIPT_COMMITMENT)
|
|
2016
2031
|
.op(OP_TXFIELD)
|
|
2017
2032
|
.op(OP_EQUALVERIFY);
|
|
2018
2033
|
// 6. Remainder tokenId
|
|
@@ -2358,12 +2373,12 @@ function parsePartialFillScript(script, network = 'xna-test') {
|
|
|
2358
2373
|
expectByte(c, OP_OUTPUTASSETFIELD, 'OP_OUTPUTASSETFIELD (buyer name)');
|
|
2359
2374
|
const tokenIdBytes1 = readPush(c, 'tokenId #1');
|
|
2360
2375
|
expectByte(c, OP_EQUALVERIFY, 'OP_EQUALVERIFY (buyer name)');
|
|
2361
|
-
// ───── Remainder continuity: same
|
|
2376
|
+
// ───── Remainder continuity: same AuthScript commitment (NIP-023) ─────
|
|
2362
2377
|
expectByte(c, OP_2, 'OP_2 (remainder idx)');
|
|
2363
|
-
expectByte(c,
|
|
2364
|
-
expectByte(c,
|
|
2378
|
+
expectByte(c, OP_OUTPUTAUTHCOMMITMENT, 'OP_OUTPUTAUTHCOMMITMENT (remainder)');
|
|
2379
|
+
expectByte(c, OP_2, 'OP_2 (TXFIELD selector: AUTHSCRIPT_COMMITMENT)');
|
|
2365
2380
|
expectByte(c, OP_TXFIELD, 'OP_TXFIELD');
|
|
2366
|
-
expectByte(c, OP_EQUALVERIFY, 'OP_EQUALVERIFY (remainder
|
|
2381
|
+
expectByte(c, OP_EQUALVERIFY, 'OP_EQUALVERIFY (remainder auth)');
|
|
2367
2382
|
// ───── Remainder tokenId check ─────
|
|
2368
2383
|
expectByte(c, OP_2, 'OP_2 (remainder idx)');
|
|
2369
2384
|
expectByte(c, OP_1, 'OP_1 (NAME selector)');
|
|
@@ -2464,11 +2479,12 @@ function parsePartialFillScriptPQ(script, network = 'xna-test') {
|
|
|
2464
2479
|
expectByte(c, OP_OUTPUTASSETFIELD, 'OP_OUTPUTASSETFIELD (buyer name)');
|
|
2465
2480
|
const tokenIdBytes1 = readPush(c, 'tokenId #1');
|
|
2466
2481
|
expectByte(c, OP_EQUALVERIFY, 'OP_EQUALVERIFY (buyer name)');
|
|
2482
|
+
// Remainder continuity: same AuthScript commitment (NIP-023)
|
|
2467
2483
|
expectByte(c, OP_2, 'OP_2 (remainder idx)');
|
|
2468
|
-
expectByte(c,
|
|
2469
|
-
expectByte(c,
|
|
2484
|
+
expectByte(c, OP_OUTPUTAUTHCOMMITMENT, 'OP_OUTPUTAUTHCOMMITMENT (remainder)');
|
|
2485
|
+
expectByte(c, OP_2, 'OP_2 (TXFIELD selector: AUTHSCRIPT_COMMITMENT)');
|
|
2470
2486
|
expectByte(c, OP_TXFIELD, 'OP_TXFIELD');
|
|
2471
|
-
expectByte(c, OP_EQUALVERIFY, 'OP_EQUALVERIFY (remainder
|
|
2487
|
+
expectByte(c, OP_EQUALVERIFY, 'OP_EQUALVERIFY (remainder auth)');
|
|
2472
2488
|
expectByte(c, OP_2, 'OP_2 (remainder idx)');
|
|
2473
2489
|
expectByte(c, OP_1, 'OP_1 (NAME selector)');
|
|
2474
2490
|
expectByte(c, OP_OUTPUTASSETFIELD, 'OP_OUTPUTASSETFIELD (remainder name)');
|