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