@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.
- package/README.md +72 -1
- package/dist/NeuraiScripts.global.js +1142 -41
- package/dist/NeuraiScripts.global.js.map +1 -1
- package/dist/browser.js +1128 -38
- package/dist/browser.js.map +1 -1
- package/dist/core/opcodes.d.ts +1 -0
- package/dist/covenants/asset-auth/index.d.ts +6 -0
- package/dist/covenants/asset-auth/policy.d.ts +47 -0
- package/dist/covenants/asset-auth/proposal.d.ts +28 -0
- package/dist/covenants/asset-auth/vote.d.ts +43 -0
- package/dist/covenants/index.d.ts +2 -0
- package/dist/index.cjs +1142 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +126 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1128 -38
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.d.cts
CHANGED
|
@@ -341,6 +341,7 @@ declare const OP_SHA3_256 = 202;
|
|
|
341
341
|
declare const OP_SHA512 = 203;
|
|
342
342
|
declare const OP_CHECKSIG_ED25519 = 221;
|
|
343
343
|
declare const OP_CHECKSIGADD = 222;
|
|
344
|
+
declare const OP_CHECKASSETAUTH = 223;
|
|
344
345
|
declare const OP_NOP1 = 176;
|
|
345
346
|
declare const OP_NOP9 = 184;
|
|
346
347
|
declare const OP_NOP10 = 185;
|
|
@@ -453,6 +454,7 @@ declare const opcodes_d_OP_BOOLAND: typeof OP_BOOLAND;
|
|
|
453
454
|
declare const opcodes_d_OP_BOOLOR: typeof OP_BOOLOR;
|
|
454
455
|
declare const opcodes_d_OP_CAT: typeof OP_CAT;
|
|
455
456
|
declare const opcodes_d_OP_CHAINCONTEXT: typeof OP_CHAINCONTEXT;
|
|
457
|
+
declare const opcodes_d_OP_CHECKASSETAUTH: typeof OP_CHECKASSETAUTH;
|
|
456
458
|
declare const opcodes_d_OP_CHECKLOCKTIMEVERIFY: typeof OP_CHECKLOCKTIMEVERIFY;
|
|
457
459
|
declare const opcodes_d_OP_CHECKMERKLEINCLUSION: typeof OP_CHECKMERKLEINCLUSION;
|
|
458
460
|
declare const opcodes_d_OP_CHECKMULTISIG: typeof OP_CHECKMULTISIG;
|
|
@@ -609,6 +611,7 @@ declare namespace opcodes_d {
|
|
|
609
611
|
opcodes_d_OP_BOOLOR as OP_BOOLOR,
|
|
610
612
|
opcodes_d_OP_CAT as OP_CAT,
|
|
611
613
|
opcodes_d_OP_CHAINCONTEXT as OP_CHAINCONTEXT,
|
|
614
|
+
opcodes_d_OP_CHECKASSETAUTH as OP_CHECKASSETAUTH,
|
|
612
615
|
opcodes_d_OP_CHECKLOCKTIMEVERIFY as OP_CHECKLOCKTIMEVERIFY,
|
|
613
616
|
opcodes_d_OP_CHECKMERKLEINCLUSION as OP_CHECKMERKLEINCLUSION,
|
|
614
617
|
opcodes_d_OP_CHECKMULTISIG as OP_CHECKMULTISIG,
|
|
@@ -1239,5 +1242,126 @@ declare function isPartialFillScriptPQ(script: Uint8Array | string): boolean;
|
|
|
1239
1242
|
*/
|
|
1240
1243
|
declare function parsePartialFillScriptPQ(script: Uint8Array | string, network?: Network): ParsedPartialFillOrderPQ;
|
|
1241
1244
|
|
|
1242
|
-
|
|
1243
|
-
|
|
1245
|
+
/**
|
|
1246
|
+
* NIP-054 P2AH custody policy (`OP_CHECKASSETAUTH`, AuthScript only).
|
|
1247
|
+
*
|
|
1248
|
+
* The policy is the witnessScript of a generic AuthScript v1 (NoAuth)
|
|
1249
|
+
* address. A spend of that address needs M of the N owner-token roles of the
|
|
1250
|
+
* list to approve it (G of them when an owner token held by the custody
|
|
1251
|
+
* leaves it):
|
|
1252
|
+
*
|
|
1253
|
+
* policy: <1> <M> <G> <role_1> ... <role_n> <n> OP_CHECKASSETAUTH
|
|
1254
|
+
* witness: [0x00, <c>, <a>, <b>, <T>, policy]
|
|
1255
|
+
*
|
|
1256
|
+
* Build the four arguments with `buildAssetAuthArgs` and wrap them with
|
|
1257
|
+
* `buildAuthScriptWitnessNoAuth({ args, witnessScript: policy })`. A role
|
|
1258
|
+
* approves either by spending its owner token from P2PKH or a strict
|
|
1259
|
+
* AuthScript address with a SIGHASH_ALL signature (synchronous spend, every
|
|
1260
|
+
* argument 0), or by a vote (see `vote.ts` and `proposal.ts`).
|
|
1261
|
+
*/
|
|
1262
|
+
/** The only policy version defined by NIP-054. */
|
|
1263
|
+
declare const ASSETAUTH_POLICY_VERSION = 1;
|
|
1264
|
+
/** Highest number of roles in one policy. */
|
|
1265
|
+
declare const ASSETAUTH_MAX_ROLES = 16;
|
|
1266
|
+
interface AssetAuthPolicy {
|
|
1267
|
+
/** Roles that must approve a spend. */
|
|
1268
|
+
M: number;
|
|
1269
|
+
/** Roles that must approve when an owner token held by the custody leaves it (M <= G). */
|
|
1270
|
+
G: number;
|
|
1271
|
+
/** Owner token names (`NAME!`, `&NAME!`). Any order: the script lists them sorted by bytes. */
|
|
1272
|
+
roles: string[];
|
|
1273
|
+
}
|
|
1274
|
+
interface AssetAuthArgs {
|
|
1275
|
+
/** Proposal inputs: inputs 0..c-1 are committed by the proposal hash. */
|
|
1276
|
+
c: number;
|
|
1277
|
+
/** Proposal output prefix: outputs 0..a-1. */
|
|
1278
|
+
a: number;
|
|
1279
|
+
/** Proposal output suffix: the last b outputs. */
|
|
1280
|
+
b: number;
|
|
1281
|
+
/** Expiry height of the votes. */
|
|
1282
|
+
T: number;
|
|
1283
|
+
}
|
|
1284
|
+
declare function buildAssetAuthPolicyScript(policy: AssetAuthPolicy): Uint8Array;
|
|
1285
|
+
/** Inverse of `buildAssetAuthPolicyScript`; rejects any other script. */
|
|
1286
|
+
declare function parseAssetAuthPolicyScript(script: Uint8Array): AssetAuthPolicy;
|
|
1287
|
+
/**
|
|
1288
|
+
* Witness `args` [<c>, <a>, <b>, <T>] for the custody input: minimal script
|
|
1289
|
+
* numbers, 0 as the empty element. All default to 0, the synchronous spend.
|
|
1290
|
+
*/
|
|
1291
|
+
declare function buildAssetAuthArgs({ c, a, b, T }?: Partial<AssetAuthArgs>): Uint8Array[];
|
|
1292
|
+
|
|
1293
|
+
/**
|
|
1294
|
+
* NIP-054 proposal hash H, the message a vote carries.
|
|
1295
|
+
*
|
|
1296
|
+
* H = TaggedHash("NeuraiAssetAuthProposal", m)
|
|
1297
|
+
* m = chainId (u8) || nVersion (i32) || nLockTime (u32) || T (u32)
|
|
1298
|
+
* || compact(c) || compact(a) || compact(b)
|
|
1299
|
+
* || (outpoint, nSequence) of inputs 0..c-1
|
|
1300
|
+
* || outputs 0..a-1 || the last b outputs
|
|
1301
|
+
* || compact(#refs) || reference inputs (version 3 only)
|
|
1302
|
+
*
|
|
1303
|
+
* Inputs from index c on and the outputs between the prefix and the suffix
|
|
1304
|
+
* (approvals, returns, fees, change) are left to the executor, so a skeleton
|
|
1305
|
+
* transaction with only the proposal inputs and outputs gives the same H as
|
|
1306
|
+
* the execution. Votes carry H as is, as the 32-byte (64-hex) message of
|
|
1307
|
+
* their owner-token transfer: `bytesToHex(hash)`.
|
|
1308
|
+
*/
|
|
1309
|
+
|
|
1310
|
+
type AssetAuthChain = 'mainnet' | 'testnet' | 'regtest';
|
|
1311
|
+
/** The chain identifier the node commits to (OP_CHAINCONTEXT selector 0x03). */
|
|
1312
|
+
declare const ASSETAUTH_CHAIN_IDS: Readonly<Record<AssetAuthChain, number>>;
|
|
1313
|
+
interface AssetAuthProposal extends AssetAuthArgs {
|
|
1314
|
+
/** The execution, or a skeleton with its proposal inputs and outputs (hex). */
|
|
1315
|
+
rawTx: string;
|
|
1316
|
+
chain: AssetAuthChain;
|
|
1317
|
+
}
|
|
1318
|
+
declare function buildAssetAuthProposalMessage(proposal: AssetAuthProposal): Uint8Array;
|
|
1319
|
+
/** H: 32 bytes, in the order a vote carries it. */
|
|
1320
|
+
declare function assetAuthProposalHash(proposal: AssetAuthProposal): Uint8Array;
|
|
1321
|
+
|
|
1322
|
+
/**
|
|
1323
|
+
* NIP-054 vote lock: a wallet template (not part of the opcode) that holds a
|
|
1324
|
+
* role's owner token while it votes for a proposal.
|
|
1325
|
+
*
|
|
1326
|
+
* The holder sends the owner token, with the proposal hash H as its transfer
|
|
1327
|
+
* message, to the generic AuthScript v1 (NoAuth) address of this script:
|
|
1328
|
+
*
|
|
1329
|
+
* OP_IF execute, up to height T
|
|
1330
|
+
* OP_1 OP_CHAINCONTEXT <T> OP_LESSTHANOREQUAL OP_VERIFY
|
|
1331
|
+
* OP_SWAP OP_4 OP_INPUTFIELD <0x01 || C> OP_EQUALVERIFY
|
|
1332
|
+
* OP_OUTPUTSCRIPT <return> OP_EQUAL
|
|
1333
|
+
* OP_ELSE give it back, after T
|
|
1334
|
+
* OP_1 OP_CHAINCONTEXT <T> OP_GREATERTHAN OP_VERIFY
|
|
1335
|
+
* OP_NIP OP_OUTPUTSCRIPT <return> OP_EQUAL
|
|
1336
|
+
* OP_ENDIF
|
|
1337
|
+
*
|
|
1338
|
+
* Both branches send the token back to its owner (`return`, the full output
|
|
1339
|
+
* script). The execute branch also needs the custody, commitment C, at the
|
|
1340
|
+
* input it names. It must use OP_INPUTFIELD selector 04, the full
|
|
1341
|
+
* version-plus-commitment: selector 02 only reads the first 34 bytes of the
|
|
1342
|
+
* spent script, which a forged anyone-can-spend custody can match.
|
|
1343
|
+
*/
|
|
1344
|
+
interface AssetAuthVoteLockParams {
|
|
1345
|
+
/** Expiry height of the proposal the vote is for. */
|
|
1346
|
+
T: number;
|
|
1347
|
+
/** 32-byte AuthScript commitment C of the custody, as in its scriptPubKey `OP_1 <C>` (hex or bytes). */
|
|
1348
|
+
custodyCommitment: string | Uint8Array;
|
|
1349
|
+
/** The output script that gives the owner token back to its holder (hex or bytes). */
|
|
1350
|
+
returnScriptPubKey: string | Uint8Array;
|
|
1351
|
+
}
|
|
1352
|
+
declare function buildAssetAuthVoteLockScript(params: AssetAuthVoteLockParams): Uint8Array;
|
|
1353
|
+
/**
|
|
1354
|
+
* Witness `args` of the execute branch: the index of the custody input and
|
|
1355
|
+
* the index of the output that returns the token.
|
|
1356
|
+
*/
|
|
1357
|
+
declare function buildAssetAuthVoteExecuteArgs(params: {
|
|
1358
|
+
custodyInput: number;
|
|
1359
|
+
returnOutput: number;
|
|
1360
|
+
}): Uint8Array[];
|
|
1361
|
+
/** Witness `args` of the return branch, after T. */
|
|
1362
|
+
declare function buildAssetAuthVoteReturnArgs(params: {
|
|
1363
|
+
returnOutput: number;
|
|
1364
|
+
}): Uint8Array[];
|
|
1365
|
+
|
|
1366
|
+
export { ASSETAUTH_CHAIN_IDS, ASSETAUTH_MAX_ROLES, ASSETAUTH_POLICY_VERSION, AUTHSCRIPT_LEGACY, AUTHSCRIPT_NOAUTH, AUTHSCRIPT_PQ, AUTHSCRIPT_REF, DEFAULT_PQ_TXHASH_SELECTOR, MULTISIG_MAX_PUBKEYS, NULLDATA_STANDARD_MAX_SIZE, PQ_PUBKEY_PREFIX, STRICT_PQ_PUBKEY_LENGTH, ScriptBuilder, assetAuthProposalHash, buildAssetAuthArgs, buildAssetAuthPolicyScript, buildAssetAuthProposalMessage, buildAssetAuthVoteExecuteArgs, buildAssetAuthVoteLockScript, buildAssetAuthVoteReturnArgs, buildAuthScriptWitnessLegacy, buildAuthScriptWitnessNoAuth, buildAuthScriptWitnessPQ, buildAuthScriptWitnessRef, buildCancelScriptSig, buildCancelScriptSigHex, buildCancelScriptSigPQ, buildCancelScriptSigPQHex, buildCancelWitnessStack, buildCancelWitnessStackPQ, buildFillScriptSig, buildFillScriptSigHex, buildFillWitnessStack, buildPartialFillScript, buildPartialFillScriptHex, buildPartialFillScriptPQ, buildPartialFillScriptPQHex, buildStrictWitnessECDSA, buildStrictWitnessPQ, bytesEqual, bytesToHex, concatBytes, encodeAuthScriptScriptPubKey, encodeMultisigRedeemScript, encodeMultisigRedeemScriptHex, encodeNullDataScript, encodeP2PKHScriptPubKey, encodeP2SHScriptPubKey, encodeP2WPKHScriptPubKey, encodeP2WSHScriptPubKey, encodeScriptNum, encodeSellerScriptPubKey, ensureHex, hexToBytes, isPartialFillScriptPQ, opcodes_d as opcodes, parseAssetAuthPolicyScript, parsePartialFillScript, parsePartialFillScriptPQ, pushBytes, pushHex, pushInt, splitAssetWrappedScriptPubKey };
|
|
1367
|
+
export type { AssetAuthArgs, AssetAuthChain, AssetAuthPolicy, AssetAuthProposal, AssetAuthVoteLockParams, AssetMarker, AssetTransferPayload, AuthScriptWitnessLegacyInput, AuthScriptWitnessNoAuthInput, AuthScriptWitnessPQInput, AuthScriptWitnessRefInput, AuthScriptWitnessVersion, AuthType, EncodeNullDataOptions, MultisigParams, Network, OrderUtxo, ParsedPartialFillOrder, ParsedPartialFillOrderPQ, PartialFillExpiration, PartialFillExpirationMode, PartialFillOrderPQParams, PartialFillOrderParams, SellerAddressKind, SellerScriptPubKey, SplitAssetWrappedResult, StrictWitnessECDSAInput, StrictWitnessPQInput, TxInputRef };
|
package/dist/index.d.ts
CHANGED
|
@@ -8,4 +8,5 @@ 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 { AssetMarker, 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, buildFillWitnessStack, buildCancelWitnessStack, buildCancelWitnessStackPQ } 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, ASSETAUTH_POLICY_VERSION, ASSETAUTH_MAX_ROLES, ASSETAUTH_CHAIN_IDS, buildAssetAuthPolicyScript, parseAssetAuthPolicyScript, buildAssetAuthArgs, buildAssetAuthProposalMessage, assetAuthProposalHash, buildAssetAuthVoteLockScript, buildAssetAuthVoteExecuteArgs, buildAssetAuthVoteReturnArgs } from './covenants/index.js';
|
|
12
|
+
export type { AssetAuthPolicy, AssetAuthArgs, AssetAuthChain, AssetAuthProposal, AssetAuthVoteLockParams } from './covenants/index.js';
|