@neuraiproject/neurai-scripts 0.6.2 → 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 +84 -0
- package/dist/NeuraiScripts.global.js.map +1 -1
- package/dist/browser.js +82 -1
- 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 +84 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +82 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -8,4 +8,4 @@ export { encodeSellerScriptPubKey } from './address.js';
|
|
|
8
8
|
export type { SellerAddressKind, SellerScriptPubKey } from './address.js';
|
|
9
9
|
export { splitAssetWrappedScriptPubKey } from './asset-wrapper.js';
|
|
10
10
|
export type { AssetTransferPayload, SplitAssetWrappedResult } from './asset-wrapper.js';
|
|
11
|
-
export { buildPartialFillScript, buildPartialFillScriptHex, buildFillScriptSig, buildFillScriptSigHex, buildCancelScriptSig, buildCancelScriptSigHex, parsePartialFillScript, buildPartialFillScriptPQ, buildPartialFillScriptPQHex, buildCancelScriptSigPQ, buildCancelScriptSigPQHex, parsePartialFillScriptPQ, isPartialFillScriptPQ, DEFAULT_PQ_TXHASH_SELECTOR } from './covenants/index.js';
|
|
11
|
+
export { buildPartialFillScript, buildPartialFillScriptHex, buildFillScriptSig, buildFillScriptSigHex, buildCancelScriptSig, buildCancelScriptSigHex, parsePartialFillScript, buildPartialFillScriptPQ, buildPartialFillScriptPQHex, buildCancelScriptSigPQ, buildCancelScriptSigPQHex, parsePartialFillScriptPQ, isPartialFillScriptPQ, DEFAULT_PQ_TXHASH_SELECTOR, buildFillWitnessStack, buildCancelWitnessStack, buildCancelWitnessStackPQ } from './covenants/index.js';
|
package/dist/index.js
CHANGED
|
@@ -2539,6 +2539,87 @@ function buildCancelScriptSigPQHex(sigPQ, pubKey) {
|
|
|
2539
2539
|
return bytesToHex(buildCancelScriptSigPQ(sigPQ, pubKey));
|
|
2540
2540
|
}
|
|
2541
2541
|
|
|
2542
|
+
/**
|
|
2543
|
+
* Witness-stack builders for the Partial-Fill Sell Order covenant.
|
|
2544
|
+
*
|
|
2545
|
+
* When the covenant lives behind an AuthScript commitment (the only
|
|
2546
|
+
* asset-compatible deployment since the node's OP_XNA_ASSET placement rules
|
|
2547
|
+
* — bare covenant outputs can no longer carry assets), the unlock data goes
|
|
2548
|
+
* in the witness, not the scriptSig. The scriptSig builders in `spend.ts`
|
|
2549
|
+
* return a serialized script that PUSHES the elements; a witness needs the
|
|
2550
|
+
* elements THEMSELVES, one per stack slot, so those blobs cannot be reused
|
|
2551
|
+
* as a single `args` entry.
|
|
2552
|
+
*
|
|
2553
|
+
* These builders return the raw `args` stack (bottom → top), mirroring the
|
|
2554
|
+
* shapes documented in `spend.ts`:
|
|
2555
|
+
*
|
|
2556
|
+
* Full fill: [ <1>, <0> ]
|
|
2557
|
+
* Partial fill: [ <N>, <0>, <0> ]
|
|
2558
|
+
* Cancel: [ <sig>, <pubkey>, <1> ]
|
|
2559
|
+
*
|
|
2560
|
+
* Numbers are minimal CScriptNum stack values (0 = empty element). Wrap the
|
|
2561
|
+
* result with `buildAuthScriptWitnessNoAuth({ args, witnessScript: covenant })`
|
|
2562
|
+
* (from `standard/authscript.ts`) to get the final `[0x00, ...args, covenant]`
|
|
2563
|
+
* witness.
|
|
2564
|
+
*/
|
|
2565
|
+
const MAX_PQ_SCRIPT_ELEMENT_SIZE = 3072;
|
|
2566
|
+
/**
|
|
2567
|
+
* Witness `args` for the public fill branches. Same semantics and
|
|
2568
|
+
* validations as `buildFillScriptSig`.
|
|
2569
|
+
*/
|
|
2570
|
+
function buildFillWitnessStack(amount, total) {
|
|
2571
|
+
if (typeof amount !== 'bigint' || typeof total !== 'bigint') {
|
|
2572
|
+
throw new Error('amount and total must be bigint');
|
|
2573
|
+
}
|
|
2574
|
+
if (amount <= 0n) {
|
|
2575
|
+
throw new Error('fill amount must be > 0');
|
|
2576
|
+
}
|
|
2577
|
+
if (total <= 0n) {
|
|
2578
|
+
throw new Error('total must be > 0');
|
|
2579
|
+
}
|
|
2580
|
+
if (amount > total) {
|
|
2581
|
+
throw new Error('fill amount exceeds the covenant total');
|
|
2582
|
+
}
|
|
2583
|
+
if (amount === total) {
|
|
2584
|
+
// Full fill: covenant drains entirely; buyer does not push N.
|
|
2585
|
+
return [encodeScriptNum(1n), encodeScriptNum(0n)];
|
|
2586
|
+
}
|
|
2587
|
+
// Partial fill: N, then both flag values.
|
|
2588
|
+
return [encodeScriptNum(amount), encodeScriptNum(0n), encodeScriptNum(0n)];
|
|
2589
|
+
}
|
|
2590
|
+
/**
|
|
2591
|
+
* Witness `args` for the seller's ECDSA cancel branch. Same semantics and
|
|
2592
|
+
* validations as `buildCancelScriptSig`.
|
|
2593
|
+
*/
|
|
2594
|
+
function buildCancelWitnessStack(signatureDer, pubKey) {
|
|
2595
|
+
if (!(signatureDer instanceof Uint8Array) || signatureDer.length === 0) {
|
|
2596
|
+
throw new Error('signatureDer must be a non-empty Uint8Array');
|
|
2597
|
+
}
|
|
2598
|
+
if (!(pubKey instanceof Uint8Array) || (pubKey.length !== 33 && pubKey.length !== 65)) {
|
|
2599
|
+
throw new Error('pubKey must be a compressed (33B) or uncompressed (65B) secp256k1 key');
|
|
2600
|
+
}
|
|
2601
|
+
return [signatureDer, pubKey, encodeScriptNum(1n)];
|
|
2602
|
+
}
|
|
2603
|
+
/**
|
|
2604
|
+
* Witness `args` for the seller's PQ (ML-DSA-44) cancel branch. Same
|
|
2605
|
+
* semantics and validations as `buildCancelScriptSigPQ`.
|
|
2606
|
+
*/
|
|
2607
|
+
function buildCancelWitnessStackPQ(sigPQ, pubKey) {
|
|
2608
|
+
if (!(sigPQ instanceof Uint8Array) || sigPQ.length === 0) {
|
|
2609
|
+
throw new Error('sigPQ must be a non-empty Uint8Array');
|
|
2610
|
+
}
|
|
2611
|
+
if (sigPQ.length > MAX_PQ_SCRIPT_ELEMENT_SIZE) {
|
|
2612
|
+
throw new Error(`sigPQ of ${sigPQ.length} bytes exceeds MAX_PQ_SCRIPT_ELEMENT_SIZE (${MAX_PQ_SCRIPT_ELEMENT_SIZE})`);
|
|
2613
|
+
}
|
|
2614
|
+
if (!(pubKey instanceof Uint8Array) || pubKey.length === 0) {
|
|
2615
|
+
throw new Error('pubKey must be a non-empty Uint8Array');
|
|
2616
|
+
}
|
|
2617
|
+
if (pubKey.length > MAX_PQ_SCRIPT_ELEMENT_SIZE) {
|
|
2618
|
+
throw new Error(`pubKey of ${pubKey.length} bytes exceeds MAX_PQ_SCRIPT_ELEMENT_SIZE (${MAX_PQ_SCRIPT_ELEMENT_SIZE})`);
|
|
2619
|
+
}
|
|
2620
|
+
return [sigPQ, pubKey, encodeScriptNum(1n)];
|
|
2621
|
+
}
|
|
2622
|
+
|
|
2542
2623
|
/**
|
|
2543
2624
|
* Parser for the Partial-Fill Sell Order covenant (three-branch).
|
|
2544
2625
|
*
|
|
@@ -2848,5 +2929,5 @@ function parsePartialFillScriptPQ(script, network = 'xna-test') {
|
|
|
2848
2929
|
};
|
|
2849
2930
|
}
|
|
2850
2931
|
|
|
2851
|
-
export { AUTHSCRIPT_LEGACY, AUTHSCRIPT_NOAUTH, AUTHSCRIPT_PQ, AUTHSCRIPT_REF, DEFAULT_PQ_TXHASH_SELECTOR, MULTISIG_MAX_PUBKEYS, NULLDATA_STANDARD_MAX_SIZE, ScriptBuilder, buildAuthScriptWitnessLegacy, buildAuthScriptWitnessNoAuth, buildAuthScriptWitnessPQ, buildAuthScriptWitnessRef, buildCancelScriptSig, buildCancelScriptSigHex, buildCancelScriptSigPQ, buildCancelScriptSigPQHex, buildFillScriptSig, buildFillScriptSigHex, buildPartialFillScript, buildPartialFillScriptHex, buildPartialFillScriptPQ, buildPartialFillScriptPQHex, bytesEqual, bytesToHex, concatBytes, encodeAuthScriptScriptPubKey, encodeMultisigRedeemScript, encodeMultisigRedeemScriptHex, encodeNullDataScript, encodeP2PKHScriptPubKey, encodeP2SHScriptPubKey, encodeP2WPKHScriptPubKey, encodeP2WSHScriptPubKey, encodeScriptNum, encodeSellerScriptPubKey, ensureHex, hexToBytes, isPartialFillScriptPQ, opcodes, parsePartialFillScript, parsePartialFillScriptPQ, pushBytes, pushHex, pushInt, splitAssetWrappedScriptPubKey };
|
|
2932
|
+
export { AUTHSCRIPT_LEGACY, AUTHSCRIPT_NOAUTH, AUTHSCRIPT_PQ, AUTHSCRIPT_REF, DEFAULT_PQ_TXHASH_SELECTOR, MULTISIG_MAX_PUBKEYS, NULLDATA_STANDARD_MAX_SIZE, ScriptBuilder, buildAuthScriptWitnessLegacy, buildAuthScriptWitnessNoAuth, buildAuthScriptWitnessPQ, buildAuthScriptWitnessRef, buildCancelScriptSig, buildCancelScriptSigHex, buildCancelScriptSigPQ, buildCancelScriptSigPQHex, buildCancelWitnessStack, buildCancelWitnessStackPQ, buildFillScriptSig, buildFillScriptSigHex, buildFillWitnessStack, buildPartialFillScript, buildPartialFillScriptHex, buildPartialFillScriptPQ, buildPartialFillScriptPQHex, bytesEqual, bytesToHex, concatBytes, encodeAuthScriptScriptPubKey, encodeMultisigRedeemScript, encodeMultisigRedeemScriptHex, encodeNullDataScript, encodeP2PKHScriptPubKey, encodeP2SHScriptPubKey, encodeP2WPKHScriptPubKey, encodeP2WSHScriptPubKey, encodeScriptNum, encodeSellerScriptPubKey, ensureHex, hexToBytes, isPartialFillScriptPQ, opcodes, parsePartialFillScript, parsePartialFillScriptPQ, pushBytes, pushHex, pushInt, splitAssetWrappedScriptPubKey };
|
|
2852
2933
|
//# sourceMappingURL=index.js.map
|