@arkade-os/sdk 0.5.12 → 0.5.13
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/adapters/expo.cjs +7 -7
- package/dist/adapters/expo.d.cts +2 -2
- package/dist/adapters/expo.d.ts +2 -2
- package/dist/adapters/expo.js +4 -4
- package/dist/{asyncStorageTaskQueue-Bsty8W7d.d.ts → asyncStorageTaskQueue-Dhbe00Ya.d.ts} +1 -1
- package/dist/{asyncStorageTaskQueue-DTNS2qfN.d.cts → asyncStorageTaskQueue-Y4BlVm41.d.cts} +1 -1
- package/dist/{chunk-YAVF2PR6.cjs → chunk-6TBTL42M.cjs} +87 -2
- package/dist/chunk-6TBTL42M.cjs.map +1 -0
- package/dist/{chunk-CJUVKHK4.cjs → chunk-6WPP4UGN.cjs} +9846 -8606
- package/dist/chunk-6WPP4UGN.cjs.map +1 -0
- package/dist/{chunk-HNLC6F73.cjs → chunk-6XVTGWQK.cjs} +20 -20
- package/dist/{chunk-HNLC6F73.cjs.map → chunk-6XVTGWQK.cjs.map} +1 -1
- package/dist/{chunk-JA4SYFC7.cjs → chunk-ACIQZLWL.cjs} +379 -20
- package/dist/chunk-ACIQZLWL.cjs.map +1 -0
- package/dist/{chunk-5NY5EOS2.js → chunk-BA36SQY2.js} +4 -4
- package/dist/{chunk-5NY5EOS2.js.map → chunk-BA36SQY2.js.map} +1 -1
- package/dist/{chunk-BA3GPO5C.js → chunk-BP4NA7HK.js} +5 -5
- package/dist/{chunk-BA3GPO5C.js.map → chunk-BP4NA7HK.js.map} +1 -1
- package/dist/{chunk-3RO63OPW.js → chunk-D4QH6L54.js} +4 -4
- package/dist/{chunk-3RO63OPW.js.map → chunk-D4QH6L54.js.map} +1 -1
- package/dist/{chunk-2YXVU5TK.js → chunk-GB67AGXG.js} +81 -3
- package/dist/chunk-GB67AGXG.js.map +1 -0
- package/dist/{chunk-4X4SY3RH.cjs → chunk-HS7TKVOZ.cjs} +23 -19
- package/dist/chunk-HS7TKVOZ.cjs.map +1 -0
- package/dist/{chunk-4TMJBLJT.js → chunk-LHLRG2BE.js} +16 -13
- package/dist/chunk-LHLRG2BE.js.map +1 -0
- package/dist/{chunk-4OY5BCIE.js → chunk-QSERJPTT.js} +628 -23
- package/dist/chunk-QSERJPTT.js.map +1 -0
- package/dist/{chunk-C3NKBKRY.cjs → chunk-TD4PKK2I.cjs} +680 -68
- package/dist/chunk-TD4PKK2I.cjs.map +1 -0
- package/dist/{chunk-QDX2HUBK.cjs → chunk-TYSUFG2K.cjs} +11 -11
- package/dist/{chunk-QDX2HUBK.cjs.map → chunk-TYSUFG2K.cjs.map} +1 -1
- package/dist/{chunk-QV7AOZZN.cjs → chunk-WFJPLXOE.cjs} +21 -21
- package/dist/{chunk-QV7AOZZN.cjs.map → chunk-WFJPLXOE.cjs.map} +1 -1
- package/dist/{chunk-3ABF4EMM.js → chunk-X57WKONW.js} +369 -10
- package/dist/chunk-X57WKONW.js.map +1 -0
- package/dist/{chunk-WBZYYRAB.js → chunk-Y3AWLHQP.js} +9390 -8153
- package/dist/chunk-Y3AWLHQP.js.map +1 -0
- package/dist/compiler.cjs +3 -4
- package/dist/compiler.cjs.map +1 -1
- package/dist/compiler.js +2 -3
- package/dist/compiler.js.map +1 -1
- package/dist/contracts/handlers/index.cjs +15 -11
- package/dist/contracts/handlers/index.d.cts +5 -5
- package/dist/contracts/handlers/index.d.ts +5 -5
- package/dist/contracts/handlers/index.js +4 -4
- package/dist/{index-BBmZXXqk.d.cts → index-BQwrHcOh.d.cts} +523 -22
- package/dist/{index-DenQfCn1.d.cts → index-BaTItxPx.d.cts} +1 -1
- package/dist/{index-D_zLtU-F.d.ts → index-BapVvuoI.d.ts} +1 -1
- package/dist/{index-DJ32LpfD.d.ts → index-DuXylQrN.d.ts} +523 -22
- package/dist/index.cjs +403 -368
- package/dist/index.d.cts +78 -67
- package/dist/index.d.ts +78 -67
- package/dist/index.js +6 -7
- package/dist/repositories/realm/index.cjs +39 -40
- package/dist/repositories/realm/index.cjs.map +1 -1
- package/dist/repositories/realm/index.d.cts +2 -2
- package/dist/repositories/realm/index.d.ts +2 -2
- package/dist/repositories/realm/index.js +7 -8
- package/dist/repositories/realm/index.js.map +1 -1
- package/dist/repositories/sqlite/index.cjs +37 -38
- package/dist/repositories/sqlite/index.cjs.map +1 -1
- package/dist/repositories/sqlite/index.d.cts +2 -2
- package/dist/repositories/sqlite/index.d.ts +2 -2
- package/dist/repositories/sqlite/index.js +7 -8
- package/dist/repositories/sqlite/index.js.map +1 -1
- package/dist/{taskRunner-Cck24OnC.d.ts → taskRunner-BxOmg-O6.d.ts} +1 -1
- package/dist/{taskRunner-BBGaN4cq.d.cts → taskRunner-D2itCXf6.d.cts} +1 -1
- package/dist/wallet/expo/background.cjs +16 -17
- package/dist/wallet/expo/background.cjs.map +1 -1
- package/dist/wallet/expo/background.d.cts +3 -3
- package/dist/wallet/expo/background.d.ts +3 -3
- package/dist/wallet/expo/background.js +8 -9
- package/dist/wallet/expo/background.js.map +1 -1
- package/dist/wallet/expo/index.cjs +17 -18
- package/dist/wallet/expo/index.cjs.map +1 -1
- package/dist/wallet/expo/index.d.cts +2 -2
- package/dist/wallet/expo/index.d.ts +2 -2
- package/dist/wallet/expo/index.js +7 -8
- package/dist/wallet/expo/index.js.map +1 -1
- package/dist/worker/expo/index.cjs +11 -12
- package/dist/worker/expo/index.cjs.map +1 -1
- package/dist/worker/expo/index.d.cts +4 -4
- package/dist/worker/expo/index.d.ts +4 -4
- package/dist/worker/expo/index.js +7 -8
- package/dist/worker/expo/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-2YXVU5TK.js.map +0 -1
- package/dist/chunk-3ABF4EMM.js.map +0 -1
- package/dist/chunk-4OY5BCIE.js.map +0 -1
- package/dist/chunk-4TMJBLJT.js.map +0 -1
- package/dist/chunk-4X4SY3RH.cjs.map +0 -1
- package/dist/chunk-C3NKBKRY.cjs.map +0 -1
- package/dist/chunk-CJUVKHK4.cjs.map +0 -1
- package/dist/chunk-JA4SYFC7.cjs.map +0 -1
- package/dist/chunk-PHOJF7OK.cjs +0 -376
- package/dist/chunk-PHOJF7OK.cjs.map +0 -1
- package/dist/chunk-UXLETBNK.js +0 -373
- package/dist/chunk-UXLETBNK.js.map +0 -1
- package/dist/chunk-WBZYYRAB.js.map +0 -1
- package/dist/chunk-YAVF2PR6.cjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __export, sequenceToCanonicalTimelock, VtxoScript, ConditionCSVMultisigTapscript, CSVMultisigTapscript, CLTVMultisigTapscript, ConditionMultisigTapscript, MultisigTapscript } from './chunk-
|
|
1
|
+
import { __export, toXOnly, sequenceToCanonicalTimelock, VtxoScript, ConditionCSVMultisigTapscript, CSVMultisigTapscript, CLTVMultisigTapscript, ConditionMultisigTapscript, MultisigTapscript } from './chunk-GB67AGXG.js';
|
|
2
2
|
import { hex } from '@scure/base';
|
|
3
3
|
import { ScriptNum, OP } from '@scure/btc-signer';
|
|
4
4
|
import { equalBytes } from '@scure/btc-signer/utils.js';
|
|
@@ -6,12 +6,6 @@ import * as P from 'micro-packed';
|
|
|
6
6
|
import { schnorr, secp256k1 } from '@noble/curves/secp256k1.js';
|
|
7
7
|
import { bytesToNumberBE } from '@noble/curves/utils.js';
|
|
8
8
|
|
|
9
|
-
// src/utils/keys.ts
|
|
10
|
-
function toXOnly(key, label = "public key") {
|
|
11
|
-
if (key.length === 32) return key;
|
|
12
|
-
if (key.length === 33 && (key[0] === 2 || key[0] === 3)) return key.subarray(1);
|
|
13
|
-
throw new Error(`${label} is not a compressed or x-only public key`);
|
|
14
|
-
}
|
|
15
9
|
var ARKADE_OP = {
|
|
16
10
|
// Merkle Branch Verification (0xb3 — repurposed NOP4 slot)
|
|
17
11
|
MERKLEBRANCHVERIFY: 179,
|
|
@@ -825,7 +819,372 @@ function deserializeArkadeContractParams(params) {
|
|
|
825
819
|
...params.emulatorKey ? { emulatorKey: hex.decode(params.emulatorKey) } : {}
|
|
826
820
|
};
|
|
827
821
|
}
|
|
822
|
+
var NATIVE_STRUCTS = {
|
|
823
|
+
AssetId: [
|
|
824
|
+
["txid", "bytes32"],
|
|
825
|
+
["gidx", "int"]
|
|
826
|
+
],
|
|
827
|
+
Outpoint: [
|
|
828
|
+
["txid", "bytes32"],
|
|
829
|
+
["vout", "int"]
|
|
830
|
+
],
|
|
831
|
+
ECPoint: [
|
|
832
|
+
["x", "int"],
|
|
833
|
+
["y", "int"]
|
|
834
|
+
],
|
|
835
|
+
ScriptPubKey: [
|
|
836
|
+
["program", "bytes"],
|
|
837
|
+
["version", "int"]
|
|
838
|
+
],
|
|
839
|
+
AssetEntry: [
|
|
840
|
+
["assetId", "AssetId"],
|
|
841
|
+
["amount", "int"]
|
|
842
|
+
],
|
|
843
|
+
AssetLookup: [
|
|
844
|
+
["amount", "int"],
|
|
845
|
+
["found", "bool"]
|
|
846
|
+
],
|
|
847
|
+
G2Point: [
|
|
848
|
+
["xC1", "int"],
|
|
849
|
+
["xC0", "int"],
|
|
850
|
+
["yC1", "int"],
|
|
851
|
+
["yC0", "int"]
|
|
852
|
+
]
|
|
853
|
+
};
|
|
854
|
+
var HASH_OPCODES = /* @__PURE__ */ new Set(["OP_SHA256", "OP_HASH160", "OP_HASH256", "OP_RIPEMD160"]);
|
|
855
|
+
function isRecord(value) {
|
|
856
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
857
|
+
}
|
|
858
|
+
function isNamed(value) {
|
|
859
|
+
return isRecord(value) && typeof value.name === "string" && value.name.length > 0 && typeof value.type === "string" && value.type.length > 0;
|
|
860
|
+
}
|
|
861
|
+
function isContractArtifact(value) {
|
|
862
|
+
if (!isRecord(value) || typeof value.contractName !== "string") return false;
|
|
863
|
+
if (!Array.isArray(value.constructorInputs)) return false;
|
|
864
|
+
if (value.structs !== void 0 && !Array.isArray(value.structs)) return false;
|
|
865
|
+
if (!Array.isArray(value.functions) || value.functions.length === 0) return false;
|
|
866
|
+
return value.functions.every(
|
|
867
|
+
(group) => isRecord(group) && typeof group.name === "string" && group.name.length > 0 && Array.isArray(group.leaves) && group.leaves.length > 0
|
|
868
|
+
);
|
|
869
|
+
}
|
|
870
|
+
function fail(detail) {
|
|
871
|
+
throw new Error(`programFromArtifact: ${detail}`);
|
|
872
|
+
}
|
|
873
|
+
var isPair = (value) => Array.isArray(value) && value.length === 2 && value.every((n) => Number.isInteger(n) && n >= 0);
|
|
874
|
+
function sourceMaps(artifact, debug) {
|
|
875
|
+
if (!isRecord(debug) || !isRecord(debug.functions)) fail("debug file needs a functions object");
|
|
876
|
+
if (debug.formatVersion !== 1) {
|
|
877
|
+
fail(`unsupported debug format version ${debug.formatVersion}; expected 1`);
|
|
878
|
+
}
|
|
879
|
+
if (artifact.fingerprint === void 0 || debug.artifactFingerprint !== artifact.fingerprint) {
|
|
880
|
+
fail(
|
|
881
|
+
`debug file fingerprint ${debug.artifactFingerprint ?? "(missing)"} does not match the artifact's ${artifact.fingerprint ?? "(missing)"}`
|
|
882
|
+
);
|
|
883
|
+
}
|
|
884
|
+
const maps = /* @__PURE__ */ new Map();
|
|
885
|
+
for (const [name, entry] of Object.entries(debug.functions)) {
|
|
886
|
+
const asm = artifact.functions.find((group) => isRecord(group) && group.name === name)?.arkade?.asm;
|
|
887
|
+
if (!Array.isArray(asm)) fail(`debug file maps no covenant '${name}'`);
|
|
888
|
+
if (!isRecord(entry) || !Array.isArray(entry.sourceMap)) {
|
|
889
|
+
fail(`debug file: covenant '${name}' needs a sourceMap array`);
|
|
890
|
+
}
|
|
891
|
+
const copies = entry.sourceMap.map((range) => {
|
|
892
|
+
if (!isRecord(range) || !isPair(range.asm) || !isPair(range.start) || !isPair(range.end) || range.asm[0] > range.asm[1] || range.asm[1] > asm.length || range.message !== void 0 && typeof range.message !== "string") {
|
|
893
|
+
fail(
|
|
894
|
+
`debug file: covenant '${name}' has a malformed range ${JSON.stringify(range)}`
|
|
895
|
+
);
|
|
896
|
+
}
|
|
897
|
+
return { ...range, asm: [...range.asm], start: [...range.start], end: [...range.end] };
|
|
898
|
+
});
|
|
899
|
+
maps.set(name, copies);
|
|
900
|
+
}
|
|
901
|
+
return maps;
|
|
902
|
+
}
|
|
903
|
+
function claim(seen, name, kind) {
|
|
904
|
+
if (seen.has(name)) fail(`duplicate ${kind} '${name}'`);
|
|
905
|
+
seen.add(name);
|
|
906
|
+
}
|
|
907
|
+
function inputDef(name, type) {
|
|
908
|
+
return { name, type: argType(type) };
|
|
909
|
+
}
|
|
910
|
+
function argType(arkType) {
|
|
911
|
+
if (!Object.hasOwn(ARKADE_TYPE_ENCODINGS, arkType)) fail(`unknown type '${arkType}'`);
|
|
912
|
+
return arkType;
|
|
913
|
+
}
|
|
914
|
+
function arrayParts(type) {
|
|
915
|
+
const open = type.indexOf("[");
|
|
916
|
+
if (open < 0 || !type.endsWith("]")) return [type, 0];
|
|
917
|
+
const length = Number(type.slice(open + 1, -1));
|
|
918
|
+
return Number.isSafeInteger(length) && length > 0 && /^\d+$/.test(type.slice(open + 1, -1)) ? [type.slice(0, open), length] : [type, 0];
|
|
919
|
+
}
|
|
920
|
+
var MAX_LAYOUT_CHARS = 1 << 18;
|
|
921
|
+
function flatten(param, structs, budget, stack = []) {
|
|
922
|
+
if (!isNamed(param)) fail("parameter needs a name and a type");
|
|
923
|
+
const [element, length] = arrayParts(param.type);
|
|
924
|
+
budget.left -= param.name.length;
|
|
925
|
+
if (budget.left < length) fail(`layouts exceed ${MAX_LAYOUT_CHARS} name characters`);
|
|
926
|
+
if (length > 0) {
|
|
927
|
+
return Array.from(
|
|
928
|
+
{ length },
|
|
929
|
+
(_, index) => flatten({ name: `${param.name}.${index}`, type: element }, structs, budget, stack)
|
|
930
|
+
).flat();
|
|
931
|
+
}
|
|
932
|
+
if (param.type.includes("[") || param.type.includes("]")) {
|
|
933
|
+
fail(`invalid array type '${param.type}'`);
|
|
934
|
+
}
|
|
935
|
+
if (Object.hasOwn(NATIVE_STRUCTS, param.type)) {
|
|
936
|
+
return NATIVE_STRUCTS[param.type].flatMap(
|
|
937
|
+
([field, type]) => flatten({ name: `${param.name}.${field}`, type }, structs, budget, stack)
|
|
938
|
+
);
|
|
939
|
+
}
|
|
940
|
+
const declared = structs.get(param.type);
|
|
941
|
+
if (declared) {
|
|
942
|
+
if (stack.includes(param.type)) fail(`recursive struct layout '${param.type}'`);
|
|
943
|
+
return declared.fields.flatMap(
|
|
944
|
+
(field) => flatten({ name: `${param.name}.${field.name}`, type: field.type }, structs, budget, [
|
|
945
|
+
...stack,
|
|
946
|
+
param.type
|
|
947
|
+
])
|
|
948
|
+
);
|
|
949
|
+
}
|
|
950
|
+
return [inputDef(param.name, param.type)];
|
|
951
|
+
}
|
|
952
|
+
function opcodeToken(token) {
|
|
953
|
+
const base = token.slice(3);
|
|
954
|
+
const name = base === "0" || /^([1-9]|1[0-6])$/.test(base) ? token : base;
|
|
955
|
+
if (!Object.hasOwn(ARKADE_OPS, name)) {
|
|
956
|
+
fail(`opcode '${token}' is not in this SDK's table`);
|
|
957
|
+
}
|
|
958
|
+
return name;
|
|
959
|
+
}
|
|
960
|
+
function instantiationParam(body) {
|
|
961
|
+
return `contract_${body.replace(/[^A-Za-z0-9]+/g, "_")}`.replace(/_+$/, "");
|
|
962
|
+
}
|
|
963
|
+
function asmToken(token, instantiations) {
|
|
964
|
+
if (token.startsWith("OP_")) return opcodeToken(token);
|
|
965
|
+
if (token.startsWith("<") && token.endsWith(">")) {
|
|
966
|
+
const inner = token.slice(1, -1);
|
|
967
|
+
if (inner.startsWith("CONTRACT:")) {
|
|
968
|
+
const body = inner.slice("CONTRACT:".length);
|
|
969
|
+
const name = instantiationParam(body);
|
|
970
|
+
const seen = instantiations.get(name);
|
|
971
|
+
if (seen !== void 0 && seen !== body) {
|
|
972
|
+
fail(`instantiations '${seen}' and '${body}' both map to parameter '${name}'`);
|
|
973
|
+
}
|
|
974
|
+
instantiations.set(name, body);
|
|
975
|
+
return `$${name}`;
|
|
976
|
+
}
|
|
977
|
+
if (inner.startsWith("VTXO:")) {
|
|
978
|
+
fail(`'${token}' is not a placeholder; the compiler emits <CONTRACT:\u2026>`);
|
|
979
|
+
}
|
|
980
|
+
if (inner === "SERVER_KEY" || inner.startsWith("EMULATOR_KEY:")) {
|
|
981
|
+
fail(`${token} is a signer role and cannot appear in a covenant`);
|
|
982
|
+
}
|
|
983
|
+
return `$${inner}`;
|
|
984
|
+
}
|
|
985
|
+
if (token.startsWith("0x")) return hex.decode(token.slice(2));
|
|
986
|
+
try {
|
|
987
|
+
return BigInt(token);
|
|
988
|
+
} catch {
|
|
989
|
+
fail(`unrecognized assembly token '${token}'`);
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
function providedWitness(witness) {
|
|
993
|
+
if (witness === void 0) return [];
|
|
994
|
+
if (!Array.isArray(witness)) fail("leaf witness must be an array");
|
|
995
|
+
return witness.filter((item) => {
|
|
996
|
+
if (!isNamed(item)) fail("witness item needs a name and a type");
|
|
997
|
+
const type = argType(item.type);
|
|
998
|
+
if (item.injected !== void 0 && typeof item.injected !== "boolean")
|
|
999
|
+
fail(`witness '${item.name}': injected must be boolean`);
|
|
1000
|
+
if (item.injected && item.type !== "signature")
|
|
1001
|
+
fail(`witness '${item.name}': only infrastructure signatures can be injected`);
|
|
1002
|
+
if (item.encoding !== void 0 && item.encoding !== ARKADE_TYPE_ENCODINGS[type])
|
|
1003
|
+
fail(
|
|
1004
|
+
`witness '${item.name}': encoding '${item.encoding}' does not match type '${item.type}'`
|
|
1005
|
+
);
|
|
1006
|
+
return !item.injected && item.type !== "signature";
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
function csvTimelock(leafName, operand) {
|
|
1010
|
+
if (typeof operand === "string") return { type: "sequence", value: operand };
|
|
1011
|
+
const timelock = sequenceToCanonicalTimelock(operand);
|
|
1012
|
+
if (!timelock) {
|
|
1013
|
+
fail(`leaf '${leafName}': CSV literal ${operand} is not a canonical BIP68 sequence`);
|
|
1014
|
+
}
|
|
1015
|
+
return timelock;
|
|
1016
|
+
}
|
|
1017
|
+
function parseLeaf(leaf, hasCovenant, instantiations, extras) {
|
|
1018
|
+
const asm = leaf.asm;
|
|
1019
|
+
let index = 0;
|
|
1020
|
+
let condition;
|
|
1021
|
+
const hashIndex = asm[0] === "OP_SIZE" && (asm[1] === "20" || asm[1] === "32") && asm[2] === "OP_EQUALVERIFY" ? 3 : 0;
|
|
1022
|
+
if (HASH_OPCODES.has(asm[hashIndex]) && asm[hashIndex + 2] === "OP_EQUAL") {
|
|
1023
|
+
if (asm[hashIndex + 3] !== "OP_VERIFY")
|
|
1024
|
+
fail(`leaf '${leaf.name}': hash condition must end in OP_VERIFY`);
|
|
1025
|
+
condition = asm.slice(0, hashIndex + 3).map((token) => asmToken(token, instantiations));
|
|
1026
|
+
index = hashIndex + 4;
|
|
1027
|
+
}
|
|
1028
|
+
let csv;
|
|
1029
|
+
let cltv;
|
|
1030
|
+
if (asm.length >= index + 3 && asm[index + 2] === "OP_DROP") {
|
|
1031
|
+
const operand = asm[index].startsWith("<") && asm[index].endsWith(">") ? `$${asm[index].slice(1, -1)}` : BigInt(asm[index]);
|
|
1032
|
+
if (asm[index + 1] === "OP_CHECKSEQUENCEVERIFY") csv = csvTimelock(leaf.name, operand);
|
|
1033
|
+
else if (asm[index + 1] === "OP_CHECKLOCKTIMEVERIFY") cltv = operand;
|
|
1034
|
+
else fail(`leaf '${leaf.name}': unexpected timelock opcode ${asm[index + 1]}`);
|
|
1035
|
+
index += 3;
|
|
1036
|
+
}
|
|
1037
|
+
const signers = [];
|
|
1038
|
+
let emulator;
|
|
1039
|
+
let emulatorIndex;
|
|
1040
|
+
while (index < asm.length) {
|
|
1041
|
+
const key = asm[index];
|
|
1042
|
+
const terminator = asm[index + 1];
|
|
1043
|
+
const last = terminator === "OP_CHECKSIG";
|
|
1044
|
+
if (last !== (index + 2 === asm.length)) {
|
|
1045
|
+
fail(`leaf '${leaf.name}': only the final signer must end in OP_CHECKSIG`);
|
|
1046
|
+
}
|
|
1047
|
+
if (!last && terminator !== "OP_CHECKSIGVERIFY") {
|
|
1048
|
+
fail(`leaf '${leaf.name}': expected CHECKSIG after '${key}', found '${terminator}'`);
|
|
1049
|
+
}
|
|
1050
|
+
if (!key.startsWith("<") || !key.endsWith(">")) {
|
|
1051
|
+
fail(`leaf '${leaf.name}': unsupported key operand '${key}'`);
|
|
1052
|
+
}
|
|
1053
|
+
const inner = key.slice(1, -1);
|
|
1054
|
+
if (inner === "SERVER_KEY") signers.push("$server");
|
|
1055
|
+
else if (inner.startsWith("TWEAK:")) {
|
|
1056
|
+
const [, base, fn] = inner.match(/^TWEAK:([^:]+):([^:]+)$/) ?? [];
|
|
1057
|
+
if (!base || !fn) fail(`leaf '${leaf.name}': malformed tweak '${key}'`);
|
|
1058
|
+
signers.push({ tweak: `$${base}`, fn });
|
|
1059
|
+
} else if (inner.startsWith("EMULATOR_KEY:")) {
|
|
1060
|
+
if (!hasCovenant) fail(`leaf '${leaf.name}': ${key} needs a covenant`);
|
|
1061
|
+
if (emulator !== void 0) fail(`leaf '${leaf.name}': duplicate emulator signer`);
|
|
1062
|
+
emulator = inner.slice("EMULATOR_KEY:".length);
|
|
1063
|
+
emulatorIndex = signers.length;
|
|
1064
|
+
} else signers.push(`$${inner}`);
|
|
1065
|
+
index += 2;
|
|
1066
|
+
}
|
|
1067
|
+
const constructorTweak = signers.some((signer) => typeof signer !== "string");
|
|
1068
|
+
if (hasCovenant && emulator === void 0 && !constructorTweak) {
|
|
1069
|
+
fail(
|
|
1070
|
+
`leaf '${leaf.name}': covenant leaf must sign with the emulator or a tweaked constructor key`
|
|
1071
|
+
);
|
|
1072
|
+
}
|
|
1073
|
+
if (signers.length === 0 && emulator === void 0)
|
|
1074
|
+
fail(`leaf '${leaf.name}': at least one named signer is required`);
|
|
1075
|
+
return {
|
|
1076
|
+
signers,
|
|
1077
|
+
...emulator !== void 0 ? { emulator } : hasCovenant ? { emulator: null } : {},
|
|
1078
|
+
...emulatorIndex !== void 0 ? { emulatorIndex } : {},
|
|
1079
|
+
...condition ? { asm: condition } : {},
|
|
1080
|
+
...csv ? { csv } : {},
|
|
1081
|
+
...cltv !== void 0 ? { cltv } : {},
|
|
1082
|
+
...extras.length > 0 ? {
|
|
1083
|
+
inputs: extras.map((item) => inputDef(item.name, item.type)),
|
|
1084
|
+
witness: extras.map((item) => item.name)
|
|
1085
|
+
} : {}
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
function programFromArtifact(artifact, debug) {
|
|
1089
|
+
if (!isContractArtifact(artifact)) {
|
|
1090
|
+
fail(
|
|
1091
|
+
"expected a complete arkadec artifact with contractName, constructorInputs, and non-empty functions"
|
|
1092
|
+
);
|
|
1093
|
+
}
|
|
1094
|
+
if (artifact.formatVersion !== void 0 && artifact.formatVersion !== 1) {
|
|
1095
|
+
fail(`unsupported artifact format version ${artifact.formatVersion}; expected 1`);
|
|
1096
|
+
}
|
|
1097
|
+
const maps = debug === void 0 ? void 0 : sourceMaps(artifact, debug);
|
|
1098
|
+
const structs = artifact.structs ?? [];
|
|
1099
|
+
const structNames = /* @__PURE__ */ new Set();
|
|
1100
|
+
for (const struct of structs) {
|
|
1101
|
+
if (!isRecord(struct) || typeof struct.name !== "string" || !Array.isArray(struct.fields)) {
|
|
1102
|
+
fail("struct needs a name and fields array");
|
|
1103
|
+
}
|
|
1104
|
+
const fields = /* @__PURE__ */ new Set();
|
|
1105
|
+
for (const field of struct.fields) {
|
|
1106
|
+
if (!isNamed(field)) fail(`struct '${struct.name}': field needs a name and type`);
|
|
1107
|
+
claim(fields, field.name, "struct field");
|
|
1108
|
+
}
|
|
1109
|
+
if (Object.hasOwn(ARKADE_TYPE_ENCODINGS, struct.name) || Object.hasOwn(NATIVE_STRUCTS, struct.name)) {
|
|
1110
|
+
fail(`struct name '${struct.name}' shadows a built-in type`);
|
|
1111
|
+
}
|
|
1112
|
+
claim(structNames, struct.name, "struct");
|
|
1113
|
+
}
|
|
1114
|
+
const structsByName = new Map(structs.map((struct) => [struct.name, struct]));
|
|
1115
|
+
const budget = { left: MAX_LAYOUT_CHARS };
|
|
1116
|
+
const instantiations = /* @__PURE__ */ new Map();
|
|
1117
|
+
const functions = /* @__PURE__ */ Object.create(null);
|
|
1118
|
+
const groups = /* @__PURE__ */ new Set();
|
|
1119
|
+
const leafNames = /* @__PURE__ */ new Set();
|
|
1120
|
+
for (const group of artifact.functions) {
|
|
1121
|
+
claim(groups, group.name, "spend group");
|
|
1122
|
+
if (group.arkade !== void 0 && (!isRecord(group.arkade) || !Array.isArray(group.arkade.inputs) || !Array.isArray(group.arkade.asm) || !group.arkade.asm.every((t) => typeof t === "string"))) {
|
|
1123
|
+
fail(`group '${group.name}': covenant needs inputs and string assembly arrays`);
|
|
1124
|
+
}
|
|
1125
|
+
const covenantInputs = (group.arkade?.inputs ?? []).flatMap(
|
|
1126
|
+
(input) => flatten(input, structsByName, budget)
|
|
1127
|
+
);
|
|
1128
|
+
const sourceMap = maps?.get(group.name);
|
|
1129
|
+
const arkadeScript = group.arkade ? {
|
|
1130
|
+
asm: group.arkade.asm.map((token) => asmToken(token, instantiations)),
|
|
1131
|
+
...covenantInputs.length > 0 ? { inputs: covenantInputs } : {},
|
|
1132
|
+
// Covenant witness is reverse declaration order.
|
|
1133
|
+
witness: covenantInputs.map((field) => field.name).reverse(),
|
|
1134
|
+
...sourceMap ? { sourceMap } : {}
|
|
1135
|
+
} : void 0;
|
|
1136
|
+
const covenantNames = /* @__PURE__ */ new Set();
|
|
1137
|
+
for (const input of covenantInputs) claim(covenantNames, input.name, "covenant input");
|
|
1138
|
+
for (const leaf of group.leaves) {
|
|
1139
|
+
if (!isRecord(leaf) || typeof leaf.name !== "string" || leaf.name.length === 0 || !Array.isArray(leaf.asm) || leaf.asm.length === 0 || !leaf.asm.every((t) => typeof t === "string")) {
|
|
1140
|
+
fail(`group '${group.name}': leaf needs a name and non-empty string assembly`);
|
|
1141
|
+
}
|
|
1142
|
+
const name = leaf.name;
|
|
1143
|
+
claim(leafNames, name, "function name");
|
|
1144
|
+
const extras = providedWitness(leaf.witness);
|
|
1145
|
+
for (const input of extras) {
|
|
1146
|
+
if (leaf.asm.includes(`<${input.name}>`)) {
|
|
1147
|
+
fail(
|
|
1148
|
+
`leaf '${leaf.name}': call input '${input.name}' is a script operand; it must be a constructor binding to derive a fixed Taproot tree`
|
|
1149
|
+
);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
const witnessNames = /* @__PURE__ */ new Set();
|
|
1153
|
+
for (const item of leaf.witness ?? []) claim(witnessNames, item.name, "leaf witness");
|
|
1154
|
+
const tapscript = parseLeaf(leaf, group.arkade !== void 0, instantiations, extras);
|
|
1155
|
+
if (tapscript.emulator !== void 0 && tapscript.emulator !== null && tapscript.emulator !== group.name) {
|
|
1156
|
+
fail(
|
|
1157
|
+
`leaf '${leaf.name}': emulator covenant '${tapscript.emulator}' must match group '${group.name}'`
|
|
1158
|
+
);
|
|
1159
|
+
}
|
|
1160
|
+
const signatures = (leaf.witness ?? []).filter((item) => item.type === "signature" && !item.injected).map((item) => inputDef(item.name, item.type));
|
|
1161
|
+
if (signatures.length > 0) tapscript.signatures = signatures;
|
|
1162
|
+
functions[name] = {
|
|
1163
|
+
group: group.name,
|
|
1164
|
+
tapscript,
|
|
1165
|
+
...arkadeScript ? { arkadeScript } : {}
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
const params = [
|
|
1170
|
+
...artifact.constructorInputs.flatMap((input) => flatten(input, structsByName, budget)),
|
|
1171
|
+
{ name: "server", type: "pubkey" },
|
|
1172
|
+
...Object.values(functions).some((fn) => fn.tapscript.csv?.value === "$SERVER_EXIT_DELAY") ? [{ name: "SERVER_EXIT_DELAY", type: "int" }] : [],
|
|
1173
|
+
...[...instantiations.keys()].map((name) => ({
|
|
1174
|
+
name,
|
|
1175
|
+
type: "bytes32"
|
|
1176
|
+
}))
|
|
1177
|
+
];
|
|
1178
|
+
const paramNames = /* @__PURE__ */ new Set();
|
|
1179
|
+
for (const param of params) claim(paramNames, param.name, "program parameter");
|
|
1180
|
+
return {
|
|
1181
|
+
version: SUPPORTED_PROGRAM_VERSION,
|
|
1182
|
+
name: artifact.contractName,
|
|
1183
|
+
params,
|
|
1184
|
+
functions
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
828
1187
|
|
|
829
|
-
export { ARKADE_OP, ARKADE_OPCODES, ARKADE_OPCODE_NAMES, ARKADE_OPCODE_VALUES, ARKADE_OPS,
|
|
830
|
-
//# sourceMappingURL=chunk-
|
|
831
|
-
//# sourceMappingURL=chunk-
|
|
1188
|
+
export { ARKADE_OP, ARKADE_OPCODES, ARKADE_OPCODE_NAMES, ARKADE_OPCODE_VALUES, ARKADE_OPS, ArkadeProgramScript, ArkadeScript, OPCODE_NAMES, OPCODE_VALUES, SUPPORTED_PROGRAM_VERSION, UnsupportedProgramVersionError, arkadeScriptHash, arkadeWitnessHash, asmToBytes, bignum_exports, bytesToASM, computeArkadeScriptPublicKey, deserializeArkadeContractParams, fromASM, getOpcodeName, getOpcodeValue, isContractArtifact, parseArtifact, programFromArtifact, resolveAsm, resolveCsvTimelock, resolveTimelockValue, serializeArkadeContractParams, staticWitness, stringifyArtifact, toASM, validateParamValue, validateProgram, witnessRefToBytes };
|
|
1189
|
+
//# sourceMappingURL=chunk-X57WKONW.js.map
|
|
1190
|
+
//# sourceMappingURL=chunk-X57WKONW.js.map
|