@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/core/opcodes.d.ts
CHANGED
|
@@ -136,12 +136,16 @@ export declare const CHAINCONTEXT_HEIGHT = 1;
|
|
|
136
136
|
export declare const CHAINCONTEXT_MTP = 2;
|
|
137
137
|
export declare const CHAINCONTEXT_CHAIN_ID = 3;
|
|
138
138
|
export declare const OP_CHECKMERKLEINCLUSION = 193;
|
|
139
|
+
export declare const OP_OUTPUTAUTHDEST = 194;
|
|
140
|
+
export declare const OP_ZKVERIFY = 195;
|
|
141
|
+
export declare const OP_INPUTFIELD = 196;
|
|
139
142
|
export declare const OP_CAT = 126;
|
|
140
143
|
export declare const OP_SPLIT = 183;
|
|
141
144
|
export declare const OP_REVERSEBYTES = 188;
|
|
142
145
|
export declare const TXFIELD_VALUE = 1;
|
|
143
146
|
export declare const TXFIELD_AUTHSCRIPT_COMMITMENT = 2;
|
|
144
147
|
export declare const TXFIELD_SCRIPTPUBKEY = 3;
|
|
148
|
+
export declare const TXFIELD_AUTHDEST = 4;
|
|
145
149
|
export declare const TXHASH_VERSION = 1;
|
|
146
150
|
export declare const TXHASH_LOCKTIME = 2;
|
|
147
151
|
export declare const TXHASH_INPUT_PREVOUTS = 4;
|
|
@@ -150,7 +154,8 @@ export declare const TXHASH_OUTPUTS = 16;
|
|
|
150
154
|
export declare const TXHASH_CURRENT_PREVOUT = 32;
|
|
151
155
|
export declare const TXHASH_CURRENT_SEQUENCE = 64;
|
|
152
156
|
export declare const TXHASH_CURRENT_INDEX = 128;
|
|
153
|
-
export declare const
|
|
157
|
+
export declare const TXHASH_REFINPUTS = 256;
|
|
158
|
+
export declare const TXHASH_ALL = 511;
|
|
154
159
|
export declare const ASSETFIELD_NAME = 1;
|
|
155
160
|
export declare const ASSETFIELD_AMOUNT = 2;
|
|
156
161
|
export declare const ASSETFIELD_UNITS = 3;
|
|
@@ -158,3 +163,9 @@ export declare const ASSETFIELD_REISSUABLE = 4;
|
|
|
158
163
|
export declare const ASSETFIELD_HAS_IPFS = 5;
|
|
159
164
|
export declare const ASSETFIELD_IPFS_HASH = 6;
|
|
160
165
|
export declare const ASSETFIELD_TYPE = 7;
|
|
166
|
+
export declare const ASSETFIELD_MESSAGE = 8;
|
|
167
|
+
export declare const MERKLE_SCHEME_BITCOIN_NEURAI = 1;
|
|
168
|
+
export declare const MERKLE_SCHEME_SHA256_PLAIN = 2;
|
|
169
|
+
export declare const MERKLE_SCHEME_KECCAK256_PLAIN = 3;
|
|
170
|
+
export declare const MERKLE_SCHEME_BLAKE2B_PLAIN = 4;
|
|
171
|
+
export declare const MERKLE_SCHEME_POSEIDON_BN254 = 5;
|
|
@@ -34,15 +34,8 @@ export declare function decodeScriptNum(data: Uint8Array, label: string): bigint
|
|
|
34
34
|
*/
|
|
35
35
|
export declare function readPushPositiveInt(c: Cursor, label: string): bigint;
|
|
36
36
|
/**
|
|
37
|
-
* Read a
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* - `0x01 <byte>` raw 1-byte push → any value 1..255.
|
|
41
|
-
*
|
|
42
|
-
* Values 0x80..0xff MUST use the raw-push form; the CScriptNum encoding
|
|
43
|
-
* would need a 0x00 padding byte and become 2 bytes on-stack, which
|
|
44
|
-
* consensus `OP_TXHASH` rejects. The builder in `script-pq.ts` emits the
|
|
45
|
-
* raw-push form unconditionally; the parser stays lenient so covenants
|
|
46
|
-
* built by older tools (using OP_N for small values) still round-trip.
|
|
37
|
+
* Read a one-byte unsigned selector. This accepts OP_1..OP_16 shorthand
|
|
38
|
+
* and a raw one-byte push for scripts that permit either form. NIP-042
|
|
39
|
+
* TXHASH masks use a separate strict two-byte parser.
|
|
47
40
|
*/
|
|
48
41
|
export declare function readPushUint8(c: Cursor, label: string): number;
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* `./script.ts` for the three-branch layout description.
|
|
27
27
|
*/
|
|
28
28
|
import type { PartialFillOrderPQParams } from '../../types.js';
|
|
29
|
-
export declare const DEFAULT_PQ_TXHASH_SELECTOR =
|
|
29
|
+
export declare const DEFAULT_PQ_TXHASH_SELECTOR = 511;
|
|
30
30
|
/**
|
|
31
31
|
* Build the scriptPubKey of a PQ Partial-Fill Sell Order covenant UTXO.
|
|
32
32
|
*/
|
package/dist/index.cjs
CHANGED
|
@@ -243,20 +243,27 @@ const CHAINCONTEXT_CHAIN_ID = 0x03;
|
|
|
243
243
|
// Native Merkle inclusion verifier. Consumes (leaf, scheme_id, proof,
|
|
244
244
|
// root) and pushes a boolean. Flag off → bad-opcode.
|
|
245
245
|
const OP_CHECKMERKLEINCLUSION = 0xc1;
|
|
246
|
+
// NIP-041: (outputIndex -- witnessVersion || 32-byte program).
|
|
247
|
+
const OP_OUTPUTAUTHDEST = 0xc2;
|
|
248
|
+
// NIP-018: verifies an AuthScript proof and returns a boolean.
|
|
249
|
+
const OP_ZKVERIFY = 0xc3;
|
|
250
|
+
// NIP-043: spent-input field introspection, distinct from reference inputs.
|
|
251
|
+
const OP_INPUTFIELD = 0xc4;
|
|
246
252
|
// ---------- Byte manipulation (DePIN-Test) ----------
|
|
247
253
|
const OP_CAT = 0x7e;
|
|
248
254
|
const OP_SPLIT = 0xb7;
|
|
249
255
|
const OP_REVERSEBYTES = 0xbc;
|
|
250
256
|
// ---------- Selectors for OP_TXFIELD / OP_REFINPUTFIELD ----------
|
|
251
|
-
//
|
|
252
|
-
//
|
|
257
|
+
// OP_TXFIELD, OP_INPUTFIELD and OP_REFINPUTFIELD share selectors 0x01..0x03.
|
|
258
|
+
// NIP-041 adds 0x04 for a strict 33-byte AuthScript destination.
|
|
253
259
|
const TXFIELD_VALUE = 0x01;
|
|
254
260
|
const TXFIELD_AUTHSCRIPT_COMMITMENT = 0x02;
|
|
255
261
|
const TXFIELD_SCRIPTPUBKEY = 0x03;
|
|
262
|
+
const TXFIELD_AUTHDEST = 0x04;
|
|
256
263
|
// ---------- Bitmask selectors for OP_TXHASH ----------
|
|
257
|
-
//
|
|
258
|
-
//
|
|
259
|
-
//
|
|
264
|
+
// NIP-042 requires a two-byte little-endian selector, even for low masks.
|
|
265
|
+
// Bits 0..8 select fields for the tagged NeuraiTxHash digest. Valid masks
|
|
266
|
+
// are 0x001..0x1ff; zero and all higher bits are rejected by consensus.
|
|
260
267
|
const TXHASH_VERSION = 0x01;
|
|
261
268
|
const TXHASH_LOCKTIME = 0x02;
|
|
262
269
|
const TXHASH_INPUT_PREVOUTS = 0x04;
|
|
@@ -265,12 +272,11 @@ const TXHASH_OUTPUTS = 0x10;
|
|
|
265
272
|
const TXHASH_CURRENT_PREVOUT = 0x20;
|
|
266
273
|
const TXHASH_CURRENT_SEQUENCE = 0x40;
|
|
267
274
|
const TXHASH_CURRENT_INDEX = 0x80;
|
|
268
|
-
const
|
|
275
|
+
const TXHASH_REFINPUTS = 0x100;
|
|
276
|
+
const TXHASH_ALL = 0x1ff;
|
|
269
277
|
// ---------- Selectors for OP_OUTPUTASSETFIELD / OP_INPUTASSETFIELD / OP_REFINPUTASSETFIELD ----------
|
|
270
|
-
// All three opcodes share
|
|
271
|
-
//
|
|
272
|
-
// payload; 0x07 is the asset operation type. (This matches the asset-op
|
|
273
|
-
// encoding in `src/assets/assets.cpp` and the NIP spec §3.1.)
|
|
278
|
+
// All three opcodes share this selector table. 0x08 is gated by NIP-043
|
|
279
|
+
// and extracts the optional transfer message from a strict asset wrapper.
|
|
274
280
|
const ASSETFIELD_NAME = 0x01;
|
|
275
281
|
const ASSETFIELD_AMOUNT = 0x02;
|
|
276
282
|
const ASSETFIELD_UNITS = 0x03;
|
|
@@ -278,12 +284,20 @@ const ASSETFIELD_REISSUABLE = 0x04;
|
|
|
278
284
|
const ASSETFIELD_HAS_IPFS = 0x05;
|
|
279
285
|
const ASSETFIELD_IPFS_HASH = 0x06;
|
|
280
286
|
const ASSETFIELD_TYPE = 0x07;
|
|
287
|
+
const ASSETFIELD_MESSAGE = 0x08;
|
|
288
|
+
// NIP-031/043 Merkle inclusion scheme identifiers.
|
|
289
|
+
const MERKLE_SCHEME_BITCOIN_NEURAI = 0x01;
|
|
290
|
+
const MERKLE_SCHEME_SHA256_PLAIN = 0x02;
|
|
291
|
+
const MERKLE_SCHEME_KECCAK256_PLAIN = 0x03;
|
|
292
|
+
const MERKLE_SCHEME_BLAKE2B_PLAIN = 0x04;
|
|
293
|
+
const MERKLE_SCHEME_POSEIDON_BN254 = 0x05;
|
|
281
294
|
|
|
282
295
|
var opcodes = /*#__PURE__*/Object.freeze({
|
|
283
296
|
__proto__: null,
|
|
284
297
|
ASSETFIELD_AMOUNT: ASSETFIELD_AMOUNT,
|
|
285
298
|
ASSETFIELD_HAS_IPFS: ASSETFIELD_HAS_IPFS,
|
|
286
299
|
ASSETFIELD_IPFS_HASH: ASSETFIELD_IPFS_HASH,
|
|
300
|
+
ASSETFIELD_MESSAGE: ASSETFIELD_MESSAGE,
|
|
287
301
|
ASSETFIELD_NAME: ASSETFIELD_NAME,
|
|
288
302
|
ASSETFIELD_REISSUABLE: ASSETFIELD_REISSUABLE,
|
|
289
303
|
ASSETFIELD_TYPE: ASSETFIELD_TYPE,
|
|
@@ -291,6 +305,11 @@ var opcodes = /*#__PURE__*/Object.freeze({
|
|
|
291
305
|
CHAINCONTEXT_CHAIN_ID: CHAINCONTEXT_CHAIN_ID,
|
|
292
306
|
CHAINCONTEXT_HEIGHT: CHAINCONTEXT_HEIGHT,
|
|
293
307
|
CHAINCONTEXT_MTP: CHAINCONTEXT_MTP,
|
|
308
|
+
MERKLE_SCHEME_BITCOIN_NEURAI: MERKLE_SCHEME_BITCOIN_NEURAI,
|
|
309
|
+
MERKLE_SCHEME_BLAKE2B_PLAIN: MERKLE_SCHEME_BLAKE2B_PLAIN,
|
|
310
|
+
MERKLE_SCHEME_KECCAK256_PLAIN: MERKLE_SCHEME_KECCAK256_PLAIN,
|
|
311
|
+
MERKLE_SCHEME_POSEIDON_BN254: MERKLE_SCHEME_POSEIDON_BN254,
|
|
312
|
+
MERKLE_SCHEME_SHA256_PLAIN: MERKLE_SCHEME_SHA256_PLAIN,
|
|
294
313
|
OP_0: OP_0,
|
|
295
314
|
OP_0NOTEQUAL: OP_0NOTEQUAL,
|
|
296
315
|
OP_1: OP_1,
|
|
@@ -356,6 +375,7 @@ var opcodes = /*#__PURE__*/Object.freeze({
|
|
|
356
375
|
OP_IFDUP: OP_IFDUP,
|
|
357
376
|
OP_INPUTASSETFIELD: OP_INPUTASSETFIELD,
|
|
358
377
|
OP_INPUTCOUNT: OP_INPUTCOUNT,
|
|
378
|
+
OP_INPUTFIELD: OP_INPUTFIELD,
|
|
359
379
|
OP_INPUTVALUE: OP_INPUTVALUE,
|
|
360
380
|
OP_KECCAK256: OP_KECCAK256,
|
|
361
381
|
OP_LESSTHAN: OP_LESSTHAN,
|
|
@@ -377,6 +397,7 @@ var opcodes = /*#__PURE__*/Object.freeze({
|
|
|
377
397
|
OP_NUMNOTEQUAL: OP_NUMNOTEQUAL,
|
|
378
398
|
OP_OUTPUTASSETFIELD: OP_OUTPUTASSETFIELD,
|
|
379
399
|
OP_OUTPUTAUTHCOMMITMENT: OP_OUTPUTAUTHCOMMITMENT,
|
|
400
|
+
OP_OUTPUTAUTHDEST: OP_OUTPUTAUTHDEST,
|
|
380
401
|
OP_OUTPUTCOUNT: OP_OUTPUTCOUNT,
|
|
381
402
|
OP_OUTPUTSCRIPT: OP_OUTPUTSCRIPT,
|
|
382
403
|
OP_OUTPUTVALUE: OP_OUTPUTVALUE,
|
|
@@ -412,6 +433,8 @@ var opcodes = /*#__PURE__*/Object.freeze({
|
|
|
412
433
|
OP_VERIFY: OP_VERIFY,
|
|
413
434
|
OP_WITHIN: OP_WITHIN,
|
|
414
435
|
OP_XNA_ASSET: OP_XNA_ASSET,
|
|
436
|
+
OP_ZKVERIFY: OP_ZKVERIFY,
|
|
437
|
+
TXFIELD_AUTHDEST: TXFIELD_AUTHDEST,
|
|
415
438
|
TXFIELD_AUTHSCRIPT_COMMITMENT: TXFIELD_AUTHSCRIPT_COMMITMENT,
|
|
416
439
|
TXFIELD_SCRIPTPUBKEY: TXFIELD_SCRIPTPUBKEY,
|
|
417
440
|
TXFIELD_VALUE: TXFIELD_VALUE,
|
|
@@ -423,6 +446,7 @@ var opcodes = /*#__PURE__*/Object.freeze({
|
|
|
423
446
|
TXHASH_INPUT_SEQUENCES: TXHASH_INPUT_SEQUENCES,
|
|
424
447
|
TXHASH_LOCKTIME: TXHASH_LOCKTIME,
|
|
425
448
|
TXHASH_OUTPUTS: TXHASH_OUTPUTS,
|
|
449
|
+
TXHASH_REFINPUTS: TXHASH_REFINPUTS,
|
|
426
450
|
TXHASH_VERSION: TXHASH_VERSION
|
|
427
451
|
});
|
|
428
452
|
|
|
@@ -2098,16 +2122,9 @@ function readPushPositiveInt(c, label) {
|
|
|
2098
2122
|
return decodeScriptNum(data, label);
|
|
2099
2123
|
}
|
|
2100
2124
|
/**
|
|
2101
|
-
* Read a
|
|
2102
|
-
*
|
|
2103
|
-
*
|
|
2104
|
-
* - `0x01 <byte>` raw 1-byte push → any value 1..255.
|
|
2105
|
-
*
|
|
2106
|
-
* Values 0x80..0xff MUST use the raw-push form; the CScriptNum encoding
|
|
2107
|
-
* would need a 0x00 padding byte and become 2 bytes on-stack, which
|
|
2108
|
-
* consensus `OP_TXHASH` rejects. The builder in `script-pq.ts` emits the
|
|
2109
|
-
* raw-push form unconditionally; the parser stays lenient so covenants
|
|
2110
|
-
* built by older tools (using OP_N for small values) still round-trip.
|
|
2125
|
+
* Read a one-byte unsigned selector. This accepts OP_1..OP_16 shorthand
|
|
2126
|
+
* and a raw one-byte push for scripts that permit either form. NIP-042
|
|
2127
|
+
* TXHASH masks use a separate strict two-byte parser.
|
|
2111
2128
|
*/
|
|
2112
2129
|
function readPushUint8(c, label) {
|
|
2113
2130
|
if (c.pos >= c.bytes.length) {
|
|
@@ -2426,7 +2443,7 @@ function buildPartialFillScriptHex(params) {
|
|
|
2426
2443
|
* `./script.ts` for the three-branch layout description.
|
|
2427
2444
|
*/
|
|
2428
2445
|
const ASSET_NAME_MAX = 32;
|
|
2429
|
-
const DEFAULT_PQ_TXHASH_SELECTOR =
|
|
2446
|
+
const DEFAULT_PQ_TXHASH_SELECTOR = 0x1ff;
|
|
2430
2447
|
function assertCommitment(commitment) {
|
|
2431
2448
|
if (!(commitment instanceof Uint8Array) || commitment.length !== 32) {
|
|
2432
2449
|
throw new Error('pubKeyCommitment must be a 32-byte Uint8Array (SHA256 of pubKey)');
|
|
@@ -2455,11 +2472,11 @@ function assertPrice(priceSats) {
|
|
|
2455
2472
|
}
|
|
2456
2473
|
}
|
|
2457
2474
|
function assertSelector(selector) {
|
|
2458
|
-
if (!Number.isInteger(selector) || selector < 0 || selector >
|
|
2459
|
-
throw new Error('txHashSelector must be
|
|
2475
|
+
if (!Number.isInteger(selector) || selector < 0 || selector > 0x1ff) {
|
|
2476
|
+
throw new Error('txHashSelector must be in the NIP-042 range (0x001..0x1ff)');
|
|
2460
2477
|
}
|
|
2461
2478
|
if (selector === 0) {
|
|
2462
|
-
throw new Error('txHashSelector
|
|
2479
|
+
throw new Error('txHashSelector 0x000 is rejected by OP_TXHASH');
|
|
2463
2480
|
}
|
|
2464
2481
|
}
|
|
2465
2482
|
/**
|
|
@@ -2479,16 +2496,14 @@ function buildPartialFillScriptPQ(params) {
|
|
|
2479
2496
|
// scriptSig: <sigPQ> <pubKeyPQ> <1>
|
|
2480
2497
|
// After OP_IF consumes the flag: [ sig, pubKey ]
|
|
2481
2498
|
//
|
|
2482
|
-
//
|
|
2483
|
-
//
|
|
2484
|
-
// 1..127 but emit a 2-byte CScriptNum for 0x80..0xff (sign-disambiguation
|
|
2485
|
-
// pad), which makes OP_TXHASH fail with SCRIPT_ERR_TXHASH.
|
|
2499
|
+
// NIP-042 consumes exactly two raw little-endian bytes. CScriptNum and
|
|
2500
|
+
// OP_N encodings are invalid even when they represent the same mask.
|
|
2486
2501
|
b.op(OP_IF)
|
|
2487
2502
|
.op(OP_DUP) // [ sig, pubKey, pubKey ]
|
|
2488
2503
|
.op(OP_SHA256) // [ sig, pubKey, H(pubKey) ]
|
|
2489
2504
|
.pushBytes(pubKeyCommitment) // [ sig, pubKey, H(pubKey), commitment ]
|
|
2490
2505
|
.op(OP_EQUALVERIFY) // [ sig, pubKey ]
|
|
2491
|
-
.pushBytes(Uint8Array.of(txHashSelector)) // [ sig, pubKey, selector ]
|
|
2506
|
+
.pushBytes(Uint8Array.of(txHashSelector & 0xff, txHashSelector >> 8)) // [ sig, pubKey, selector ]
|
|
2492
2507
|
.op(OP_TXHASH) // [ sig, pubKey, txHash ]
|
|
2493
2508
|
.op(OP_SWAP) // [ sig, txHash, pubKey ]
|
|
2494
2509
|
.op(OP_CHECKSIGFROMSTACK) // [ 1 | 0 ]
|
|
@@ -3000,9 +3015,13 @@ function parsePartialFillScriptPQ(script, network = 'xna-test') {
|
|
|
3000
3015
|
throw new Error(`parse-pq: pubKeyCommitment must be 32 bytes, got ${pubKeyCommitment.length}`);
|
|
3001
3016
|
}
|
|
3002
3017
|
expectByte(c, OP_EQUALVERIFY, 'OP_EQUALVERIFY (cancel)');
|
|
3003
|
-
const
|
|
3004
|
-
if (
|
|
3005
|
-
throw new Error(`parse-pq: txHashSelector
|
|
3018
|
+
const selectorBytes = readPush(c, 'txHashSelector');
|
|
3019
|
+
if (selectorBytes.length !== 2) {
|
|
3020
|
+
throw new Error(`parse-pq: txHashSelector must be a two-byte LE push, got ${selectorBytes.length} bytes`);
|
|
3021
|
+
}
|
|
3022
|
+
const txHashSelector = selectorBytes[0] | (selectorBytes[1] << 8);
|
|
3023
|
+
if (txHashSelector === 0 || txHashSelector > 0x1ff) {
|
|
3024
|
+
throw new Error(`parse-pq: txHashSelector 0x${txHashSelector.toString(16)} is rejected by OP_TXHASH`);
|
|
3006
3025
|
}
|
|
3007
3026
|
expectByte(c, OP_TXHASH, 'OP_TXHASH');
|
|
3008
3027
|
expectByte(c, OP_SWAP, 'OP_SWAP');
|