@neuraiproject/neurai-scripts 0.6.1 → 0.7.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/dist/NeuraiScripts.global.js +90 -1
- package/dist/NeuraiScripts.global.js.map +1 -1
- package/dist/browser.js +88 -2
- package/dist/browser.js.map +1 -1
- package/dist/covenants/index.d.ts +1 -1
- package/dist/covenants/partial-fill/index.d.ts +1 -0
- package/dist/covenants/partial-fill/witness.d.ts +38 -0
- package/dist/index.cjs +90 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +88 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -1979,8 +1979,13 @@ var NeuraiScriptsBundle = (function (exports) {
|
|
|
1979
1979
|
function appendExpirationGate(b, expiration) {
|
|
1980
1980
|
if (!expiration)
|
|
1981
1981
|
return;
|
|
1982
|
+
// Selectors 1 (HEIGHT) and 2 (MTP) must be pushed as OP_1 / OP_2 so the
|
|
1983
|
+
// resulting script is consensus-minimal (MINIMALDATA). `pushBytes(0x01 N)`
|
|
1984
|
+
// would emit `01 0N`, which the consensus rule rejects for N in 1..16.
|
|
1985
|
+
// Parser side stays lenient (`readPushUint8` accepts both forms) so old
|
|
1986
|
+
// covenants in the raw `01 0N` form keep round-tripping.
|
|
1982
1987
|
b.pushInt(expiration.value)
|
|
1983
|
-
.
|
|
1988
|
+
.pushInt(selectorForMode(expiration.mode))
|
|
1984
1989
|
.op(OP_CHAINCONTEXT, OP_GREATERTHAN, OP_VERIFY);
|
|
1985
1990
|
}
|
|
1986
1991
|
function readOptionalExpirationGate(c, nextOpcodeWithoutGate, label) {
|
|
@@ -2537,6 +2542,87 @@ var NeuraiScriptsBundle = (function (exports) {
|
|
|
2537
2542
|
return bytesToHex(buildCancelScriptSigPQ(sigPQ, pubKey));
|
|
2538
2543
|
}
|
|
2539
2544
|
|
|
2545
|
+
/**
|
|
2546
|
+
* Witness-stack builders for the Partial-Fill Sell Order covenant.
|
|
2547
|
+
*
|
|
2548
|
+
* When the covenant lives behind an AuthScript commitment (the only
|
|
2549
|
+
* asset-compatible deployment since the node's OP_XNA_ASSET placement rules
|
|
2550
|
+
* — bare covenant outputs can no longer carry assets), the unlock data goes
|
|
2551
|
+
* in the witness, not the scriptSig. The scriptSig builders in `spend.ts`
|
|
2552
|
+
* return a serialized script that PUSHES the elements; a witness needs the
|
|
2553
|
+
* elements THEMSELVES, one per stack slot, so those blobs cannot be reused
|
|
2554
|
+
* as a single `args` entry.
|
|
2555
|
+
*
|
|
2556
|
+
* These builders return the raw `args` stack (bottom → top), mirroring the
|
|
2557
|
+
* shapes documented in `spend.ts`:
|
|
2558
|
+
*
|
|
2559
|
+
* Full fill: [ <1>, <0> ]
|
|
2560
|
+
* Partial fill: [ <N>, <0>, <0> ]
|
|
2561
|
+
* Cancel: [ <sig>, <pubkey>, <1> ]
|
|
2562
|
+
*
|
|
2563
|
+
* Numbers are minimal CScriptNum stack values (0 = empty element). Wrap the
|
|
2564
|
+
* result with `buildAuthScriptWitnessNoAuth({ args, witnessScript: covenant })`
|
|
2565
|
+
* (from `standard/authscript.ts`) to get the final `[0x00, ...args, covenant]`
|
|
2566
|
+
* witness.
|
|
2567
|
+
*/
|
|
2568
|
+
const MAX_PQ_SCRIPT_ELEMENT_SIZE = 3072;
|
|
2569
|
+
/**
|
|
2570
|
+
* Witness `args` for the public fill branches. Same semantics and
|
|
2571
|
+
* validations as `buildFillScriptSig`.
|
|
2572
|
+
*/
|
|
2573
|
+
function buildFillWitnessStack(amount, total) {
|
|
2574
|
+
if (typeof amount !== 'bigint' || typeof total !== 'bigint') {
|
|
2575
|
+
throw new Error('amount and total must be bigint');
|
|
2576
|
+
}
|
|
2577
|
+
if (amount <= 0n) {
|
|
2578
|
+
throw new Error('fill amount must be > 0');
|
|
2579
|
+
}
|
|
2580
|
+
if (total <= 0n) {
|
|
2581
|
+
throw new Error('total must be > 0');
|
|
2582
|
+
}
|
|
2583
|
+
if (amount > total) {
|
|
2584
|
+
throw new Error('fill amount exceeds the covenant total');
|
|
2585
|
+
}
|
|
2586
|
+
if (amount === total) {
|
|
2587
|
+
// Full fill: covenant drains entirely; buyer does not push N.
|
|
2588
|
+
return [encodeScriptNum(1n), encodeScriptNum(0n)];
|
|
2589
|
+
}
|
|
2590
|
+
// Partial fill: N, then both flag values.
|
|
2591
|
+
return [encodeScriptNum(amount), encodeScriptNum(0n), encodeScriptNum(0n)];
|
|
2592
|
+
}
|
|
2593
|
+
/**
|
|
2594
|
+
* Witness `args` for the seller's ECDSA cancel branch. Same semantics and
|
|
2595
|
+
* validations as `buildCancelScriptSig`.
|
|
2596
|
+
*/
|
|
2597
|
+
function buildCancelWitnessStack(signatureDer, pubKey) {
|
|
2598
|
+
if (!(signatureDer instanceof Uint8Array) || signatureDer.length === 0) {
|
|
2599
|
+
throw new Error('signatureDer must be a non-empty Uint8Array');
|
|
2600
|
+
}
|
|
2601
|
+
if (!(pubKey instanceof Uint8Array) || (pubKey.length !== 33 && pubKey.length !== 65)) {
|
|
2602
|
+
throw new Error('pubKey must be a compressed (33B) or uncompressed (65B) secp256k1 key');
|
|
2603
|
+
}
|
|
2604
|
+
return [signatureDer, pubKey, encodeScriptNum(1n)];
|
|
2605
|
+
}
|
|
2606
|
+
/**
|
|
2607
|
+
* Witness `args` for the seller's PQ (ML-DSA-44) cancel branch. Same
|
|
2608
|
+
* semantics and validations as `buildCancelScriptSigPQ`.
|
|
2609
|
+
*/
|
|
2610
|
+
function buildCancelWitnessStackPQ(sigPQ, pubKey) {
|
|
2611
|
+
if (!(sigPQ instanceof Uint8Array) || sigPQ.length === 0) {
|
|
2612
|
+
throw new Error('sigPQ must be a non-empty Uint8Array');
|
|
2613
|
+
}
|
|
2614
|
+
if (sigPQ.length > MAX_PQ_SCRIPT_ELEMENT_SIZE) {
|
|
2615
|
+
throw new Error(`sigPQ of ${sigPQ.length} bytes exceeds MAX_PQ_SCRIPT_ELEMENT_SIZE (${MAX_PQ_SCRIPT_ELEMENT_SIZE})`);
|
|
2616
|
+
}
|
|
2617
|
+
if (!(pubKey instanceof Uint8Array) || pubKey.length === 0) {
|
|
2618
|
+
throw new Error('pubKey must be a non-empty Uint8Array');
|
|
2619
|
+
}
|
|
2620
|
+
if (pubKey.length > MAX_PQ_SCRIPT_ELEMENT_SIZE) {
|
|
2621
|
+
throw new Error(`pubKey of ${pubKey.length} bytes exceeds MAX_PQ_SCRIPT_ELEMENT_SIZE (${MAX_PQ_SCRIPT_ELEMENT_SIZE})`);
|
|
2622
|
+
}
|
|
2623
|
+
return [sigPQ, pubKey, encodeScriptNum(1n)];
|
|
2624
|
+
}
|
|
2625
|
+
|
|
2540
2626
|
/**
|
|
2541
2627
|
* Parser for the Partial-Fill Sell Order covenant (three-branch).
|
|
2542
2628
|
*
|
|
@@ -2866,8 +2952,11 @@ var NeuraiScriptsBundle = (function (exports) {
|
|
|
2866
2952
|
buildCancelScriptSigHex: buildCancelScriptSigHex,
|
|
2867
2953
|
buildCancelScriptSigPQ: buildCancelScriptSigPQ,
|
|
2868
2954
|
buildCancelScriptSigPQHex: buildCancelScriptSigPQHex,
|
|
2955
|
+
buildCancelWitnessStack: buildCancelWitnessStack,
|
|
2956
|
+
buildCancelWitnessStackPQ: buildCancelWitnessStackPQ,
|
|
2869
2957
|
buildFillScriptSig: buildFillScriptSig,
|
|
2870
2958
|
buildFillScriptSigHex: buildFillScriptSigHex,
|
|
2959
|
+
buildFillWitnessStack: buildFillWitnessStack,
|
|
2871
2960
|
buildPartialFillScript: buildPartialFillScript,
|
|
2872
2961
|
buildPartialFillScriptHex: buildPartialFillScriptHex,
|
|
2873
2962
|
buildPartialFillScriptPQ: buildPartialFillScriptPQ,
|