@neuraiproject/neurai-scripts 0.9.0 → 0.9.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.
- package/README.md +37 -9
- package/dist/NeuraiScripts.global.js +51 -32
- package/dist/NeuraiScripts.global.js.map +1 -1
- package/dist/browser.js +51 -32
- package/dist/browser.js.map +1 -1
- package/dist/core/opcodes.d.ts +12 -1
- package/dist/core/script-parser.d.ts +3 -10
- package/dist/covenants/partial-fill/script-pq.d.ts +1 -1
- package/dist/index.cjs +51 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1227 -0
- package/dist/index.js +51 -32
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +4 -4
- package/package.json +16 -8
package/dist/browser.js
CHANGED
|
@@ -241,20 +241,27 @@ const CHAINCONTEXT_CHAIN_ID = 0x03;
|
|
|
241
241
|
// Native Merkle inclusion verifier. Consumes (leaf, scheme_id, proof,
|
|
242
242
|
// root) and pushes a boolean. Flag off → bad-opcode.
|
|
243
243
|
const OP_CHECKMERKLEINCLUSION = 0xc1;
|
|
244
|
+
// NIP-041: (outputIndex -- witnessVersion || 32-byte program).
|
|
245
|
+
const OP_OUTPUTAUTHDEST = 0xc2;
|
|
246
|
+
// NIP-018: verifies an AuthScript proof and returns a boolean.
|
|
247
|
+
const OP_ZKVERIFY = 0xc3;
|
|
248
|
+
// NIP-043: spent-input field introspection, distinct from reference inputs.
|
|
249
|
+
const OP_INPUTFIELD = 0xc4;
|
|
244
250
|
// ---------- Byte manipulation (DePIN-Test) ----------
|
|
245
251
|
const OP_CAT = 0x7e;
|
|
246
252
|
const OP_SPLIT = 0xb7;
|
|
247
253
|
const OP_REVERSEBYTES = 0xbc;
|
|
248
254
|
// ---------- Selectors for OP_TXFIELD / OP_REFINPUTFIELD ----------
|
|
249
|
-
//
|
|
250
|
-
//
|
|
255
|
+
// OP_TXFIELD, OP_INPUTFIELD and OP_REFINPUTFIELD share selectors 0x01..0x03.
|
|
256
|
+
// NIP-041 adds 0x04 for a strict 33-byte AuthScript destination.
|
|
251
257
|
const TXFIELD_VALUE = 0x01;
|
|
252
258
|
const TXFIELD_AUTHSCRIPT_COMMITMENT = 0x02;
|
|
253
259
|
const TXFIELD_SCRIPTPUBKEY = 0x03;
|
|
260
|
+
const TXFIELD_AUTHDEST = 0x04;
|
|
254
261
|
// ---------- Bitmask selectors for OP_TXHASH ----------
|
|
255
|
-
//
|
|
256
|
-
//
|
|
257
|
-
//
|
|
262
|
+
// NIP-042 requires a two-byte little-endian selector, even for low masks.
|
|
263
|
+
// Bits 0..8 select fields for the tagged NeuraiTxHash digest. Valid masks
|
|
264
|
+
// are 0x001..0x1ff; zero and all higher bits are rejected by consensus.
|
|
258
265
|
const TXHASH_VERSION = 0x01;
|
|
259
266
|
const TXHASH_LOCKTIME = 0x02;
|
|
260
267
|
const TXHASH_INPUT_PREVOUTS = 0x04;
|
|
@@ -263,12 +270,11 @@ const TXHASH_OUTPUTS = 0x10;
|
|
|
263
270
|
const TXHASH_CURRENT_PREVOUT = 0x20;
|
|
264
271
|
const TXHASH_CURRENT_SEQUENCE = 0x40;
|
|
265
272
|
const TXHASH_CURRENT_INDEX = 0x80;
|
|
266
|
-
const
|
|
273
|
+
const TXHASH_REFINPUTS = 0x100;
|
|
274
|
+
const TXHASH_ALL = 0x1ff;
|
|
267
275
|
// ---------- Selectors for OP_OUTPUTASSETFIELD / OP_INPUTASSETFIELD / OP_REFINPUTASSETFIELD ----------
|
|
268
|
-
// All three opcodes share
|
|
269
|
-
//
|
|
270
|
-
// payload; 0x07 is the asset operation type. (This matches the asset-op
|
|
271
|
-
// encoding in `src/assets/assets.cpp` and the NIP spec §3.1.)
|
|
276
|
+
// All three opcodes share this selector table. 0x08 is gated by NIP-043
|
|
277
|
+
// and extracts the optional transfer message from a strict asset wrapper.
|
|
272
278
|
const ASSETFIELD_NAME = 0x01;
|
|
273
279
|
const ASSETFIELD_AMOUNT = 0x02;
|
|
274
280
|
const ASSETFIELD_UNITS = 0x03;
|
|
@@ -276,12 +282,20 @@ const ASSETFIELD_REISSUABLE = 0x04;
|
|
|
276
282
|
const ASSETFIELD_HAS_IPFS = 0x05;
|
|
277
283
|
const ASSETFIELD_IPFS_HASH = 0x06;
|
|
278
284
|
const ASSETFIELD_TYPE = 0x07;
|
|
285
|
+
const ASSETFIELD_MESSAGE = 0x08;
|
|
286
|
+
// NIP-031/043 Merkle inclusion scheme identifiers.
|
|
287
|
+
const MERKLE_SCHEME_BITCOIN_NEURAI = 0x01;
|
|
288
|
+
const MERKLE_SCHEME_SHA256_PLAIN = 0x02;
|
|
289
|
+
const MERKLE_SCHEME_KECCAK256_PLAIN = 0x03;
|
|
290
|
+
const MERKLE_SCHEME_BLAKE2B_PLAIN = 0x04;
|
|
291
|
+
const MERKLE_SCHEME_POSEIDON_BN254 = 0x05;
|
|
279
292
|
|
|
280
293
|
var opcodes = /*#__PURE__*/Object.freeze({
|
|
281
294
|
__proto__: null,
|
|
282
295
|
ASSETFIELD_AMOUNT: ASSETFIELD_AMOUNT,
|
|
283
296
|
ASSETFIELD_HAS_IPFS: ASSETFIELD_HAS_IPFS,
|
|
284
297
|
ASSETFIELD_IPFS_HASH: ASSETFIELD_IPFS_HASH,
|
|
298
|
+
ASSETFIELD_MESSAGE: ASSETFIELD_MESSAGE,
|
|
285
299
|
ASSETFIELD_NAME: ASSETFIELD_NAME,
|
|
286
300
|
ASSETFIELD_REISSUABLE: ASSETFIELD_REISSUABLE,
|
|
287
301
|
ASSETFIELD_TYPE: ASSETFIELD_TYPE,
|
|
@@ -289,6 +303,11 @@ var opcodes = /*#__PURE__*/Object.freeze({
|
|
|
289
303
|
CHAINCONTEXT_CHAIN_ID: CHAINCONTEXT_CHAIN_ID,
|
|
290
304
|
CHAINCONTEXT_HEIGHT: CHAINCONTEXT_HEIGHT,
|
|
291
305
|
CHAINCONTEXT_MTP: CHAINCONTEXT_MTP,
|
|
306
|
+
MERKLE_SCHEME_BITCOIN_NEURAI: MERKLE_SCHEME_BITCOIN_NEURAI,
|
|
307
|
+
MERKLE_SCHEME_BLAKE2B_PLAIN: MERKLE_SCHEME_BLAKE2B_PLAIN,
|
|
308
|
+
MERKLE_SCHEME_KECCAK256_PLAIN: MERKLE_SCHEME_KECCAK256_PLAIN,
|
|
309
|
+
MERKLE_SCHEME_POSEIDON_BN254: MERKLE_SCHEME_POSEIDON_BN254,
|
|
310
|
+
MERKLE_SCHEME_SHA256_PLAIN: MERKLE_SCHEME_SHA256_PLAIN,
|
|
292
311
|
OP_0: OP_0,
|
|
293
312
|
OP_0NOTEQUAL: OP_0NOTEQUAL,
|
|
294
313
|
OP_1: OP_1,
|
|
@@ -354,6 +373,7 @@ var opcodes = /*#__PURE__*/Object.freeze({
|
|
|
354
373
|
OP_IFDUP: OP_IFDUP,
|
|
355
374
|
OP_INPUTASSETFIELD: OP_INPUTASSETFIELD,
|
|
356
375
|
OP_INPUTCOUNT: OP_INPUTCOUNT,
|
|
376
|
+
OP_INPUTFIELD: OP_INPUTFIELD,
|
|
357
377
|
OP_INPUTVALUE: OP_INPUTVALUE,
|
|
358
378
|
OP_KECCAK256: OP_KECCAK256,
|
|
359
379
|
OP_LESSTHAN: OP_LESSTHAN,
|
|
@@ -375,6 +395,7 @@ var opcodes = /*#__PURE__*/Object.freeze({
|
|
|
375
395
|
OP_NUMNOTEQUAL: OP_NUMNOTEQUAL,
|
|
376
396
|
OP_OUTPUTASSETFIELD: OP_OUTPUTASSETFIELD,
|
|
377
397
|
OP_OUTPUTAUTHCOMMITMENT: OP_OUTPUTAUTHCOMMITMENT,
|
|
398
|
+
OP_OUTPUTAUTHDEST: OP_OUTPUTAUTHDEST,
|
|
378
399
|
OP_OUTPUTCOUNT: OP_OUTPUTCOUNT,
|
|
379
400
|
OP_OUTPUTSCRIPT: OP_OUTPUTSCRIPT,
|
|
380
401
|
OP_OUTPUTVALUE: OP_OUTPUTVALUE,
|
|
@@ -410,6 +431,8 @@ var opcodes = /*#__PURE__*/Object.freeze({
|
|
|
410
431
|
OP_VERIFY: OP_VERIFY,
|
|
411
432
|
OP_WITHIN: OP_WITHIN,
|
|
412
433
|
OP_XNA_ASSET: OP_XNA_ASSET,
|
|
434
|
+
OP_ZKVERIFY: OP_ZKVERIFY,
|
|
435
|
+
TXFIELD_AUTHDEST: TXFIELD_AUTHDEST,
|
|
413
436
|
TXFIELD_AUTHSCRIPT_COMMITMENT: TXFIELD_AUTHSCRIPT_COMMITMENT,
|
|
414
437
|
TXFIELD_SCRIPTPUBKEY: TXFIELD_SCRIPTPUBKEY,
|
|
415
438
|
TXFIELD_VALUE: TXFIELD_VALUE,
|
|
@@ -421,6 +444,7 @@ var opcodes = /*#__PURE__*/Object.freeze({
|
|
|
421
444
|
TXHASH_INPUT_SEQUENCES: TXHASH_INPUT_SEQUENCES,
|
|
422
445
|
TXHASH_LOCKTIME: TXHASH_LOCKTIME,
|
|
423
446
|
TXHASH_OUTPUTS: TXHASH_OUTPUTS,
|
|
447
|
+
TXHASH_REFINPUTS: TXHASH_REFINPUTS,
|
|
424
448
|
TXHASH_VERSION: TXHASH_VERSION
|
|
425
449
|
});
|
|
426
450
|
|
|
@@ -2096,16 +2120,9 @@ function readPushPositiveInt(c, label) {
|
|
|
2096
2120
|
return decodeScriptNum(data, label);
|
|
2097
2121
|
}
|
|
2098
2122
|
/**
|
|
2099
|
-
* Read a
|
|
2100
|
-
*
|
|
2101
|
-
*
|
|
2102
|
-
* - `0x01 <byte>` raw 1-byte push → any value 1..255.
|
|
2103
|
-
*
|
|
2104
|
-
* Values 0x80..0xff MUST use the raw-push form; the CScriptNum encoding
|
|
2105
|
-
* would need a 0x00 padding byte and become 2 bytes on-stack, which
|
|
2106
|
-
* consensus `OP_TXHASH` rejects. The builder in `script-pq.ts` emits the
|
|
2107
|
-
* raw-push form unconditionally; the parser stays lenient so covenants
|
|
2108
|
-
* built by older tools (using OP_N for small values) still round-trip.
|
|
2123
|
+
* Read a one-byte unsigned selector. This accepts OP_1..OP_16 shorthand
|
|
2124
|
+
* and a raw one-byte push for scripts that permit either form. NIP-042
|
|
2125
|
+
* TXHASH masks use a separate strict two-byte parser.
|
|
2109
2126
|
*/
|
|
2110
2127
|
function readPushUint8(c, label) {
|
|
2111
2128
|
if (c.pos >= c.bytes.length) {
|
|
@@ -2424,7 +2441,7 @@ function buildPartialFillScriptHex(params) {
|
|
|
2424
2441
|
* `./script.ts` for the three-branch layout description.
|
|
2425
2442
|
*/
|
|
2426
2443
|
const ASSET_NAME_MAX = 32;
|
|
2427
|
-
const DEFAULT_PQ_TXHASH_SELECTOR =
|
|
2444
|
+
const DEFAULT_PQ_TXHASH_SELECTOR = 0x1ff;
|
|
2428
2445
|
function assertCommitment(commitment) {
|
|
2429
2446
|
if (!(commitment instanceof Uint8Array) || commitment.length !== 32) {
|
|
2430
2447
|
throw new Error('pubKeyCommitment must be a 32-byte Uint8Array (SHA256 of pubKey)');
|
|
@@ -2453,11 +2470,11 @@ function assertPrice(priceSats) {
|
|
|
2453
2470
|
}
|
|
2454
2471
|
}
|
|
2455
2472
|
function assertSelector(selector) {
|
|
2456
|
-
if (!Number.isInteger(selector) || selector < 0 || selector >
|
|
2457
|
-
throw new Error('txHashSelector must be
|
|
2473
|
+
if (!Number.isInteger(selector) || selector < 0 || selector > 0x1ff) {
|
|
2474
|
+
throw new Error('txHashSelector must be in the NIP-042 range (0x001..0x1ff)');
|
|
2458
2475
|
}
|
|
2459
2476
|
if (selector === 0) {
|
|
2460
|
-
throw new Error('txHashSelector
|
|
2477
|
+
throw new Error('txHashSelector 0x000 is rejected by OP_TXHASH');
|
|
2461
2478
|
}
|
|
2462
2479
|
}
|
|
2463
2480
|
/**
|
|
@@ -2477,16 +2494,14 @@ function buildPartialFillScriptPQ(params) {
|
|
|
2477
2494
|
// scriptSig: <sigPQ> <pubKeyPQ> <1>
|
|
2478
2495
|
// After OP_IF consumes the flag: [ sig, pubKey ]
|
|
2479
2496
|
//
|
|
2480
|
-
//
|
|
2481
|
-
//
|
|
2482
|
-
// 1..127 but emit a 2-byte CScriptNum for 0x80..0xff (sign-disambiguation
|
|
2483
|
-
// pad), which makes OP_TXHASH fail with SCRIPT_ERR_TXHASH.
|
|
2497
|
+
// NIP-042 consumes exactly two raw little-endian bytes. CScriptNum and
|
|
2498
|
+
// OP_N encodings are invalid even when they represent the same mask.
|
|
2484
2499
|
b.op(OP_IF)
|
|
2485
2500
|
.op(OP_DUP) // [ sig, pubKey, pubKey ]
|
|
2486
2501
|
.op(OP_SHA256) // [ sig, pubKey, H(pubKey) ]
|
|
2487
2502
|
.pushBytes(pubKeyCommitment) // [ sig, pubKey, H(pubKey), commitment ]
|
|
2488
2503
|
.op(OP_EQUALVERIFY) // [ sig, pubKey ]
|
|
2489
|
-
.pushBytes(Uint8Array.of(txHashSelector)) // [ sig, pubKey, selector ]
|
|
2504
|
+
.pushBytes(Uint8Array.of(txHashSelector & 0xff, txHashSelector >> 8)) // [ sig, pubKey, selector ]
|
|
2490
2505
|
.op(OP_TXHASH) // [ sig, pubKey, txHash ]
|
|
2491
2506
|
.op(OP_SWAP) // [ sig, txHash, pubKey ]
|
|
2492
2507
|
.op(OP_CHECKSIGFROMSTACK) // [ 1 | 0 ]
|
|
@@ -2998,9 +3013,13 @@ function parsePartialFillScriptPQ(script, network = 'xna-test') {
|
|
|
2998
3013
|
throw new Error(`parse-pq: pubKeyCommitment must be 32 bytes, got ${pubKeyCommitment.length}`);
|
|
2999
3014
|
}
|
|
3000
3015
|
expectByte(c, OP_EQUALVERIFY, 'OP_EQUALVERIFY (cancel)');
|
|
3001
|
-
const
|
|
3002
|
-
if (
|
|
3003
|
-
throw new Error(`parse-pq: txHashSelector
|
|
3016
|
+
const selectorBytes = readPush(c, 'txHashSelector');
|
|
3017
|
+
if (selectorBytes.length !== 2) {
|
|
3018
|
+
throw new Error(`parse-pq: txHashSelector must be a two-byte LE push, got ${selectorBytes.length} bytes`);
|
|
3019
|
+
}
|
|
3020
|
+
const txHashSelector = selectorBytes[0] | (selectorBytes[1] << 8);
|
|
3021
|
+
if (txHashSelector === 0 || txHashSelector > 0x1ff) {
|
|
3022
|
+
throw new Error(`parse-pq: txHashSelector 0x${txHashSelector.toString(16)} is rejected by OP_TXHASH`);
|
|
3004
3023
|
}
|
|
3005
3024
|
expectByte(c, OP_TXHASH, 'OP_TXHASH');
|
|
3006
3025
|
expectByte(c, OP_SWAP, 'OP_SWAP');
|