@neuraiproject/neurai-scripts 0.10.0 → 0.11.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.
@@ -109,6 +109,7 @@ export declare const OP_SHA3_256 = 202;
109
109
  export declare const OP_SHA512 = 203;
110
110
  export declare const OP_CHECKSIG_ED25519 = 221;
111
111
  export declare const OP_CHECKSIGADD = 222;
112
+ export declare const OP_CHECKASSETAUTH = 223;
112
113
  export declare const OP_NOP1 = 176;
113
114
  export declare const OP_NOP9 = 184;
114
115
  export declare const OP_NOP10 = 185;
@@ -0,0 +1,6 @@
1
+ export { ASSETAUTH_POLICY_VERSION, ASSETAUTH_MAX_ROLES, buildAssetAuthPolicyScript, parseAssetAuthPolicyScript, buildAssetAuthArgs } from './policy.js';
2
+ export type { AssetAuthPolicy, AssetAuthArgs } from './policy.js';
3
+ export { ASSETAUTH_CHAIN_IDS, buildAssetAuthProposalMessage, assetAuthProposalHash } from './proposal.js';
4
+ export type { AssetAuthChain, AssetAuthProposal } from './proposal.js';
5
+ export { buildAssetAuthVoteLockScript, buildAssetAuthVoteExecuteArgs, buildAssetAuthVoteReturnArgs } from './vote.js';
6
+ export type { AssetAuthVoteLockParams } from './vote.js';
@@ -0,0 +1,47 @@
1
+ /**
2
+ * NIP-054 P2AH custody policy (`OP_CHECKASSETAUTH`, AuthScript only).
3
+ *
4
+ * The policy is the witnessScript of a generic AuthScript v1 (NoAuth)
5
+ * address. A spend of that address needs M of the N owner-token roles of the
6
+ * list to approve it (G of them when an owner token held by the custody
7
+ * leaves it):
8
+ *
9
+ * policy: <1> <M> <G> <role_1> ... <role_n> <n> OP_CHECKASSETAUTH
10
+ * witness: [0x00, <c>, <a>, <b>, <T>, policy]
11
+ *
12
+ * Build the four arguments with `buildAssetAuthArgs` and wrap them with
13
+ * `buildAuthScriptWitnessNoAuth({ args, witnessScript: policy })`. A role
14
+ * approves either by spending its owner token from P2PKH or a strict
15
+ * AuthScript address with a SIGHASH_ALL signature (synchronous spend, every
16
+ * argument 0), or by a vote (see `vote.ts` and `proposal.ts`).
17
+ */
18
+ /** The only policy version defined by NIP-054. */
19
+ export declare const ASSETAUTH_POLICY_VERSION = 1;
20
+ /** Highest number of roles in one policy. */
21
+ export declare const ASSETAUTH_MAX_ROLES = 16;
22
+ export interface AssetAuthPolicy {
23
+ /** Roles that must approve a spend. */
24
+ M: number;
25
+ /** Roles that must approve when an owner token held by the custody leaves it (M <= G). */
26
+ G: number;
27
+ /** Owner token names (`NAME!`, `&NAME!`). Any order: the script lists them sorted by bytes. */
28
+ roles: string[];
29
+ }
30
+ export interface AssetAuthArgs {
31
+ /** Proposal inputs: inputs 0..c-1 are committed by the proposal hash. */
32
+ c: number;
33
+ /** Proposal output prefix: outputs 0..a-1. */
34
+ a: number;
35
+ /** Proposal output suffix: the last b outputs. */
36
+ b: number;
37
+ /** Expiry height of the votes. */
38
+ T: number;
39
+ }
40
+ export declare function buildAssetAuthPolicyScript(policy: AssetAuthPolicy): Uint8Array;
41
+ /** Inverse of `buildAssetAuthPolicyScript`; rejects any other script. */
42
+ export declare function parseAssetAuthPolicyScript(script: Uint8Array): AssetAuthPolicy;
43
+ /**
44
+ * Witness `args` [<c>, <a>, <b>, <T>] for the custody input: minimal script
45
+ * numbers, 0 as the empty element. All default to 0, the synchronous spend.
46
+ */
47
+ export declare function buildAssetAuthArgs({ c, a, b, T }?: Partial<AssetAuthArgs>): Uint8Array[];
@@ -0,0 +1,28 @@
1
+ /**
2
+ * NIP-054 proposal hash H, the message a vote carries.
3
+ *
4
+ * H = TaggedHash("NeuraiAssetAuthProposal", m)
5
+ * m = chainId (u8) || nVersion (i32) || nLockTime (u32) || T (u32)
6
+ * || compact(c) || compact(a) || compact(b)
7
+ * || (outpoint, nSequence) of inputs 0..c-1
8
+ * || outputs 0..a-1 || the last b outputs
9
+ * || compact(#refs) || reference inputs (version 3 only)
10
+ *
11
+ * Inputs from index c on and the outputs between the prefix and the suffix
12
+ * (approvals, returns, fees, change) are left to the executor, so a skeleton
13
+ * transaction with only the proposal inputs and outputs gives the same H as
14
+ * the execution. Votes carry H as is, as the 32-byte (64-hex) message of
15
+ * their owner-token transfer: `bytesToHex(hash)`.
16
+ */
17
+ import type { AssetAuthArgs } from './policy.js';
18
+ export type AssetAuthChain = 'mainnet' | 'testnet' | 'regtest';
19
+ /** The chain identifier the node commits to (OP_CHAINCONTEXT selector 0x03). */
20
+ export declare const ASSETAUTH_CHAIN_IDS: Readonly<Record<AssetAuthChain, number>>;
21
+ export interface AssetAuthProposal extends AssetAuthArgs {
22
+ /** The execution, or a skeleton with its proposal inputs and outputs (hex). */
23
+ rawTx: string;
24
+ chain: AssetAuthChain;
25
+ }
26
+ export declare function buildAssetAuthProposalMessage(proposal: AssetAuthProposal): Uint8Array;
27
+ /** H: 32 bytes, in the order a vote carries it. */
28
+ export declare function assetAuthProposalHash(proposal: AssetAuthProposal): Uint8Array;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * NIP-054 vote lock: a wallet template (not part of the opcode) that holds a
3
+ * role's owner token while it votes for a proposal.
4
+ *
5
+ * The holder sends the owner token, with the proposal hash H as its transfer
6
+ * message, to the generic AuthScript v1 (NoAuth) address of this script:
7
+ *
8
+ * OP_IF execute, up to height T
9
+ * OP_1 OP_CHAINCONTEXT <T> OP_LESSTHANOREQUAL OP_VERIFY
10
+ * OP_SWAP OP_4 OP_INPUTFIELD <0x01 || C> OP_EQUALVERIFY
11
+ * OP_OUTPUTSCRIPT <return> OP_EQUAL
12
+ * OP_ELSE give it back, after T
13
+ * OP_1 OP_CHAINCONTEXT <T> OP_GREATERTHAN OP_VERIFY
14
+ * OP_NIP OP_OUTPUTSCRIPT <return> OP_EQUAL
15
+ * OP_ENDIF
16
+ *
17
+ * Both branches send the token back to its owner (`return`, the full output
18
+ * script). The execute branch also needs the custody, commitment C, at the
19
+ * input it names. It must use OP_INPUTFIELD selector 04, the full
20
+ * version-plus-commitment: selector 02 only reads the first 34 bytes of the
21
+ * spent script, which a forged anyone-can-spend custody can match.
22
+ */
23
+ export interface AssetAuthVoteLockParams {
24
+ /** Expiry height of the proposal the vote is for. */
25
+ T: number;
26
+ /** 32-byte AuthScript commitment C of the custody, as in its scriptPubKey `OP_1 <C>` (hex or bytes). */
27
+ custodyCommitment: string | Uint8Array;
28
+ /** The output script that gives the owner token back to its holder (hex or bytes). */
29
+ returnScriptPubKey: string | Uint8Array;
30
+ }
31
+ export declare function buildAssetAuthVoteLockScript(params: AssetAuthVoteLockParams): Uint8Array;
32
+ /**
33
+ * Witness `args` of the execute branch: the index of the custody input and
34
+ * the index of the output that returns the token.
35
+ */
36
+ export declare function buildAssetAuthVoteExecuteArgs(params: {
37
+ custodyInput: number;
38
+ returnOutput: number;
39
+ }): Uint8Array[];
40
+ /** Witness `args` of the return branch, after T. */
41
+ export declare function buildAssetAuthVoteReturnArgs(params: {
42
+ returnOutput: number;
43
+ }): Uint8Array[];
@@ -1 +1,3 @@
1
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
+ export { ASSETAUTH_POLICY_VERSION, ASSETAUTH_MAX_ROLES, ASSETAUTH_CHAIN_IDS, buildAssetAuthPolicyScript, parseAssetAuthPolicyScript, buildAssetAuthArgs, buildAssetAuthProposalMessage, assetAuthProposalHash, buildAssetAuthVoteLockScript, buildAssetAuthVoteExecuteArgs, buildAssetAuthVoteReturnArgs } from './asset-auth/index.js';
3
+ export type { AssetAuthPolicy, AssetAuthArgs, AssetAuthChain, AssetAuthProposal, AssetAuthVoteLockParams } from './asset-auth/index.js';