@neuraiproject/neurai-scripts 0.8.2 → 0.9.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.
@@ -1,8 +1,15 @@
1
1
  /**
2
- * AuthScript (witness v1) scriptPubKey + witness-stack builders.
2
+ * AuthScript scriptPubKey + witness-stack builders.
3
3
  *
4
- * AuthScript outputs encode a 32-byte commitment in a witness v1 program:
5
- * scriptPubKey = OP_1 0x20 <32-byte program>
4
+ * AuthScript outputs encode a 32-byte commitment in a witness program:
5
+ * scriptPubKey = OP_n 0x20 <32-byte program>
6
+ *
7
+ * OP_1 generic AuthScript v1 (nc1p… / tnc1p…): any auth type, any witnessScript
8
+ * OP_2 strict PQ v2 (pq1z… / tpq1z…): auth type 0x01, witnessScript OP_TRUE
9
+ * OP_3 strict ECDSA v3 (nq1r… / tnq1r…): auth type 0x02, witnessScript OP_TRUE
10
+ *
11
+ * The witness version is also the first byte of the commitment preimage:
12
+ * tagged_hash("NeuraiAuthScript", version || auth_descriptor || SHA256(witnessScript))
6
13
  *
7
14
  * The program is `HASH160`/`SHA256` over a descriptor that depends on the
8
15
  * `auth_type` byte carried as the first witness-stack element at spend time.
@@ -28,7 +35,13 @@ export declare const AUTHSCRIPT_LEGACY = 2;
28
35
  /** NIP-015: reference-script spend mode. Not yet activated in consensus. */
29
36
  export declare const AUTHSCRIPT_REF = 3;
30
37
  export type AuthType = typeof AUTHSCRIPT_NOAUTH | typeof AUTHSCRIPT_PQ | typeof AUTHSCRIPT_LEGACY | typeof AUTHSCRIPT_REF;
31
- export declare function encodeAuthScriptScriptPubKey(program: Uint8Array): Uint8Array;
38
+ /** AuthScript witness version: 1 generic, 2 strict PQ, 3 strict ECDSA. */
39
+ export type AuthScriptWitnessVersion = 1 | 2 | 3;
40
+ /**
41
+ * `OP_n 0x20 <program>` for witness version `n`. Defaults to the generic
42
+ * AuthScript v1 (`OP_1`), which is what every covenant commits to.
43
+ */
44
+ export declare function encodeAuthScriptScriptPubKey(program: Uint8Array, witnessVersion?: AuthScriptWitnessVersion): Uint8Array;
32
45
  export interface AuthScriptWitnessLegacyInput {
33
46
  /** DER-encoded secp256k1 signature WITH trailing sighash byte. */
34
47
  signature: Uint8Array;
@@ -70,6 +83,34 @@ export declare function buildAuthScriptWitnessLegacy(input: AuthScriptWitnessLeg
70
83
  * stack elements and may each be up to 3072 B.
71
84
  */
72
85
  export declare function buildAuthScriptWitnessPQ(input: AuthScriptWitnessPQInput): Uint8Array[];
86
+ /** Length of the versioned ML-DSA-44 pubkey the node expects (0x05 prefix + 1312 B). */
87
+ export declare const STRICT_PQ_PUBKEY_LENGTH = 1313;
88
+ /** Version prefix of an ML-DSA-44 pubkey on the witness stack. */
89
+ export declare const PQ_PUBKEY_PREFIX = 5;
90
+ export interface StrictWitnessPQInput {
91
+ /** ML-DSA-44 signature WITH trailing sighash byte. */
92
+ signature: Uint8Array;
93
+ /** Versioned PQ pubkey: 0x05 prefix + 1312-byte ML-DSA-44 key (1313 B). */
94
+ pubKey: Uint8Array;
95
+ }
96
+ export interface StrictWitnessECDSAInput {
97
+ /** DER-encoded secp256k1 signature WITH trailing sighash byte. */
98
+ signature: Uint8Array;
99
+ /** Compressed secp256k1 public key (33 B). */
100
+ pubKey: Uint8Array;
101
+ }
102
+ /**
103
+ * Witness stack for spending a strict PQ witness v2 output (`pq1z…`):
104
+ * exactly `[0x01, sig, pubKey, OP_TRUE]`. The node rejects any other
105
+ * shape (extra arguments, another witnessScript) for the strict families.
106
+ */
107
+ export declare function buildStrictWitnessPQ(input: StrictWitnessPQInput): Uint8Array[];
108
+ /**
109
+ * Witness stack for spending a strict ECDSA witness v3 output (`nq1r…`):
110
+ * exactly `[0x02, sig, pubKey33, OP_TRUE]`. The node rejects uncompressed
111
+ * keys for this family.
112
+ */
113
+ export declare function buildStrictWitnessECDSA(input: StrictWitnessECDSAInput): Uint8Array[];
73
114
  /**
74
115
  * Build the witness stack for a NoAuth AuthScript spend. The spend is gated
75
116
  * by the witnessScript alone (covenants, hash-locks, time-locks, ...); no
@@ -1,8 +1,8 @@
1
1
  export { encodeP2PKHScriptPubKey } from './p2pkh.js';
2
2
  export { encodeP2WPKHScriptPubKey } from './p2wpkh.js';
3
3
  export { encodeP2WSHScriptPubKey } from './p2wsh.js';
4
- export { encodeAuthScriptScriptPubKey, buildAuthScriptWitnessLegacy, buildAuthScriptWitnessPQ, buildAuthScriptWitnessNoAuth, buildAuthScriptWitnessRef, AUTHSCRIPT_NOAUTH, AUTHSCRIPT_PQ, AUTHSCRIPT_LEGACY, AUTHSCRIPT_REF } from './authscript.js';
5
- export type { AuthType, AuthScriptWitnessLegacyInput, AuthScriptWitnessPQInput, AuthScriptWitnessNoAuthInput, AuthScriptWitnessRefInput } from './authscript.js';
4
+ export { encodeAuthScriptScriptPubKey, buildAuthScriptWitnessLegacy, buildAuthScriptWitnessPQ, buildAuthScriptWitnessNoAuth, buildAuthScriptWitnessRef, buildStrictWitnessPQ, buildStrictWitnessECDSA, AUTHSCRIPT_NOAUTH, AUTHSCRIPT_PQ, AUTHSCRIPT_LEGACY, AUTHSCRIPT_REF, STRICT_PQ_PUBKEY_LENGTH, PQ_PUBKEY_PREFIX } from './authscript.js';
5
+ export type { AuthType, AuthScriptWitnessVersion, AuthScriptWitnessLegacyInput, AuthScriptWitnessPQInput, AuthScriptWitnessNoAuthInput, AuthScriptWitnessRefInput, StrictWitnessPQInput, StrictWitnessECDSAInput } from './authscript.js';
6
6
  export { encodeNullDataScript, NULLDATA_STANDARD_MAX_SIZE } from './nulldata.js';
7
7
  export type { EncodeNullDataOptions } from './nulldata.js';
8
8
  export { encodeMultisigRedeemScript, encodeMultisigRedeemScriptHex, encodeP2SHScriptPubKey, MULTISIG_MAX_PUBKEYS } from './multisig.js';
package/dist/types.d.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  /**
2
- * Neurai network discriminator.
2
+ * Neurai chain discriminator: `xna` = mainnet, `xna-test` = testnet/regtest.
3
+ *
4
+ * Only the chain matters here. In neurai-key 5 the label `xna` also names
5
+ * the ECDSA witness v3 address type; parsed P2PKH hashes are formatted as
6
+ * Legacy Base58 (neurai-key `xna-legacy` / `xna-legacy-test`) whatever this
7
+ * label says.
3
8
  *
4
9
  * This type intentionally appears only on the **parse side** of the API —
5
10
  * as an optional argument to the parsers and as a field on the parsed
@@ -44,10 +49,11 @@ export interface PartialFillOrderParams {
44
49
  /**
45
50
  * Seller destination. Must be a legacy P2PKH address (base58check,
46
51
  * "t..." on testnet, "N..." on mainnet). The legacy covenant uses
47
- * `OP_HASH160 + OP_CHECKSIG` in its cancel branch, so AuthScript
48
- * bech32m addresses are rejected — use `buildPartialFillScriptPQ` for
49
- * post-quantum / AuthScript destinations. The decoded 20-byte PKH is
50
- * hardcoded into the covenant (cancel branch + payment scriptPubKey).
52
+ * `OP_HASH160 + OP_CHECKSIG` in its cancel branch, so every bech32m
53
+ * address (AuthScript v1 `nc1p…`, PQ v2 `pq1z…` and ECDSA v3 `nq1r…`,
54
+ * whose program is a commitment, not a key hash) is rejected — use
55
+ * `buildPartialFillScriptPQ` for those destinations. The decoded 20-byte
56
+ * PKH is hardcoded into the covenant (cancel branch + payment scriptPubKey).
51
57
  */
52
58
  sellerAddress: string;
53
59
  /** Name of the asset being sold (e.g. "CAT"). */
@@ -111,9 +117,11 @@ export interface TxInputRef {
111
117
  */
112
118
  export interface PartialFillOrderPQParams {
113
119
  /**
114
- * Destination for the XNA payment to the seller. Can be legacy P2PKH
115
- * (`N.../t...`) OR AuthScript bech32m v1 (`nq1.../tnq1...`). The covenant
116
- * hardcodes the full scriptPubKey bytes either way.
120
+ * Destination for the XNA payment to the seller: legacy P2PKH
121
+ * (`N.../t...`), generic AuthScript v1 (`nc1p.../tnc1p...`), strict PQ v2
122
+ * (`pq1z.../tpq1z...`) or strict ECDSA v3 (`nq1r.../tnq1r...`). The
123
+ * covenant hardcodes the full scriptPubKey bytes (`OP_1`/`OP_2`/`OP_3`
124
+ * prefix included) either way.
117
125
  */
118
126
  paymentAddress: string;
119
127
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neuraiproject/neurai-scripts",
3
- "version": "0.8.2",
3
+ "version": "0.9.0",
4
4
  "description": "Script-assembly library for Neurai: opcode constants, ScriptBuilder, standard scripts (P2PKH, P2WPKH, P2WSH, AuthScript, multisig, OP_RETURN) and covenants (partial-fill sell orders, legacy + PQ) targeting the DePIN-Test opcode set",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -36,7 +36,7 @@
36
36
  "test:watch": "vitest"
37
37
  },
38
38
  "dependencies": {
39
- "@neuraiproject/neurai-create-transaction": "^0.8.1"
39
+ "@neuraiproject/neurai-create-transaction": "^0.9.0"
40
40
  },
41
41
  "keywords": [
42
42
  "neurai",
@@ -60,7 +60,7 @@
60
60
  ],
61
61
  "license": "MIT",
62
62
  "devDependencies": {
63
- "@neuraiproject/neurai-key": "^4.0.1",
63
+ "@neuraiproject/neurai-key": "^5.0.1",
64
64
  "@rollup/plugin-commonjs": "^28.0.8",
65
65
  "@rollup/plugin-node-resolve": "^16.0.3",
66
66
  "bech32": "^2.0.0",