@arkade-os/sdk 0.5.3 → 0.5.5
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 +138 -50
- package/dist/adapters/expo.cjs +10 -5
- package/dist/adapters/expo.d.cts +13 -8
- package/dist/adapters/expo.d.ts +13 -8
- package/dist/adapters/expo.js +4 -3
- package/dist/{asyncStorageTaskQueue-C9PkPcW_.d.cts → asyncStorageTaskQueue-BbH-THYJ.d.cts} +2 -2
- package/dist/{asyncStorageTaskQueue-B3U5gQ-i.d.ts → asyncStorageTaskQueue-BlvkJyTa.d.ts} +2 -2
- package/dist/base-C-Y5t_0F.d.cts +359 -0
- package/dist/base-C-Y5t_0F.d.ts +359 -0
- package/dist/{chunk-OPX2HRWM.js → chunk-4I53THL6.js} +210 -937
- package/dist/chunk-4I53THL6.js.map +1 -0
- package/dist/{chunk-5WRA66RV.cjs → chunk-5SYUEVJH.cjs} +10 -10
- package/dist/chunk-5SYUEVJH.cjs.map +1 -0
- package/dist/{chunk-6FL4N4S2.js → chunk-7GIKLFHC.js} +83 -20
- package/dist/chunk-7GIKLFHC.js.map +1 -0
- package/dist/{chunk-BYPBVHVA.cjs → chunk-AMH7Q3DF.cjs} +61 -935
- package/dist/chunk-AMH7Q3DF.cjs.map +1 -0
- package/dist/{chunk-P7B4LQ3H.js → chunk-BCA6D255.js} +18 -842
- package/dist/chunk-BCA6D255.js.map +1 -0
- package/dist/{chunk-T7C3E2HL.js → chunk-CE46RS6L.js} +20 -39
- package/dist/chunk-CE46RS6L.js.map +1 -0
- package/dist/chunk-DNFTHG73.js +829 -0
- package/dist/chunk-DNFTHG73.js.map +1 -0
- package/dist/chunk-FDJ734CH.js +882 -0
- package/dist/chunk-FDJ734CH.js.map +1 -0
- package/dist/chunk-FLPWNMX3.cjs +930 -0
- package/dist/chunk-FLPWNMX3.cjs.map +1 -0
- package/dist/{chunk-Y4BL3YYX.js → chunk-FVVXCDNE.js} +4 -4
- package/dist/chunk-FVVXCDNE.js.map +1 -0
- package/dist/{chunk-ZPF4I3K2.cjs → chunk-HQQ4NRXI.cjs} +29 -47
- package/dist/chunk-HQQ4NRXI.cjs.map +1 -0
- package/dist/chunk-JFJNB7ZH.cjs +884 -0
- package/dist/chunk-JFJNB7ZH.cjs.map +1 -0
- package/dist/{chunk-KW7ZEWYS.cjs → chunk-KCL5AVML.cjs} +223 -985
- package/dist/chunk-KCL5AVML.cjs.map +1 -0
- package/dist/{chunk-HAQAWBYG.js → chunk-OO2KEK64.js} +2860 -1366
- package/dist/chunk-OO2KEK64.js.map +1 -0
- package/dist/{chunk-OUTWUYJ4.cjs → chunk-T254PXSN.cjs} +3337 -1824
- package/dist/chunk-T254PXSN.cjs.map +1 -0
- package/dist/chunk-V3ZLL5VY.js +380 -0
- package/dist/chunk-V3ZLL5VY.js.map +1 -0
- package/dist/chunk-X6ZI53DZ.cjs +383 -0
- package/dist/chunk-X6ZI53DZ.cjs.map +1 -0
- package/dist/{chunk-ZMSM3NOH.cjs → chunk-XWUCNMPN.cjs} +98 -34
- package/dist/chunk-XWUCNMPN.cjs.map +1 -0
- package/dist/compiler.cjs +50 -0
- package/dist/compiler.cjs.map +1 -0
- package/dist/compiler.d.cts +38 -0
- package/dist/compiler.d.ts +38 -0
- package/dist/compiler.js +47 -0
- package/dist/compiler.js.map +1 -0
- package/dist/contracts/handlers/index.cjs +11 -9
- package/dist/contracts/handlers/index.d.cts +6 -4
- package/dist/contracts/handlers/index.d.ts +6 -4
- package/dist/contracts/handlers/index.js +4 -2
- package/dist/{delegate-Cd28gxpM.d.ts → delegate-gGkUnYpi.d.cts} +1 -1
- package/dist/{delegate-ByfKszb6.d.cts → delegate-iyDum4fw.d.ts} +1 -1
- package/dist/{index-B6X2E7W_.d.ts → index-BWwVnJhU.d.cts} +7 -272
- package/dist/{index-DgH_0j14.d.cts → index-Bx-iArDs.d.ts} +7 -272
- package/dist/{index-BURzbRup.d.cts → index-DCml4QJn.d.ts} +1090 -1140
- package/dist/{index-BURzbRup.d.ts → index-DkyzIzKL.d.cts} +1090 -1140
- package/dist/index.cjs +470 -371
- package/dist/index.d.cts +687 -410
- package/dist/index.d.ts +687 -410
- package/dist/index.js +7 -4
- package/dist/{wallet-BnmhohgZ.d.ts → keyringDescriptorProvider-CS4w4PWd.d.ts} +427 -372
- package/dist/{wallet-BjQugVUt.d.cts → keyringDescriptorProvider-CmHXrIXd.d.cts} +427 -372
- package/dist/program-BARSNg3X.d.ts +286 -0
- package/dist/program-znrWkxE4.d.cts +286 -0
- package/dist/repositories/realm/index.cjs +100 -51
- package/dist/repositories/realm/index.cjs.map +1 -1
- package/dist/repositories/realm/index.d.cts +25 -10
- package/dist/repositories/realm/index.d.ts +25 -10
- package/dist/repositories/realm/index.js +72 -24
- package/dist/repositories/realm/index.js.map +1 -1
- package/dist/repositories/sqlite/index.cjs +222 -131
- package/dist/repositories/sqlite/index.cjs.map +1 -1
- package/dist/repositories/sqlite/index.d.cts +36 -17
- package/dist/repositories/sqlite/index.d.ts +36 -17
- package/dist/repositories/sqlite/index.js +196 -107
- package/dist/repositories/sqlite/index.js.map +1 -1
- package/dist/{taskRunner-BaNCSxqK.d.ts → taskRunner-DgMLSk_O.d.ts} +4 -4
- package/dist/{taskRunner-i56-drQV.d.cts → taskRunner-buh6aFpG.d.cts} +4 -4
- package/dist/wallet/expo/background.cjs +17 -14
- package/dist/wallet/expo/background.cjs.map +1 -1
- package/dist/wallet/expo/background.d.cts +5 -4
- package/dist/wallet/expo/background.d.ts +5 -4
- package/dist/wallet/expo/background.js +10 -7
- package/dist/wallet/expo/background.js.map +1 -1
- package/dist/wallet/expo/index.cjs +29 -16
- package/dist/wallet/expo/index.cjs.map +1 -1
- package/dist/wallet/expo/index.d.cts +12 -7
- package/dist/wallet/expo/index.d.ts +12 -7
- package/dist/wallet/expo/index.js +20 -7
- package/dist/wallet/expo/index.js.map +1 -1
- package/dist/worker/expo/index.cjs +12 -9
- package/dist/worker/expo/index.cjs.map +1 -1
- package/dist/worker/expo/index.d.cts +6 -5
- package/dist/worker/expo/index.d.ts +6 -5
- package/dist/worker/expo/index.js +8 -5
- package/dist/worker/expo/index.js.map +1 -1
- package/package.json +16 -1
- package/dist/chunk-5WRA66RV.cjs.map +0 -1
- package/dist/chunk-6FL4N4S2.js.map +0 -1
- package/dist/chunk-BYPBVHVA.cjs.map +0 -1
- package/dist/chunk-HAQAWBYG.js.map +0 -1
- package/dist/chunk-KW7ZEWYS.cjs.map +0 -1
- package/dist/chunk-OPX2HRWM.js.map +0 -1
- package/dist/chunk-OUTWUYJ4.cjs.map +0 -1
- package/dist/chunk-P7B4LQ3H.js.map +0 -1
- package/dist/chunk-T7C3E2HL.js.map +0 -1
- package/dist/chunk-Y4BL3YYX.js.map +0 -1
- package/dist/chunk-ZMSM3NOH.cjs.map +0 -1
- package/dist/chunk-ZPF4I3K2.cjs.map +0 -1
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { deserializeArkadeContractParams, serializeArkadeContractParams, ArkadeProgramScript, computeArkadeScriptPublicKey, staticWitness, resolveCsvTimelock, resolveTimelockValue, ArkadeScript } from './chunk-DNFTHG73.js';
|
|
2
|
+
import { SCRIPT_QUERY_CHUNK_SIZE, getNormalizedVtxos, DEFAULT_PAGE_SIZE } from './chunk-4I53THL6.js';
|
|
3
|
+
import { VtxoScript, MultisigTapscript, CSVMultisigTapscript, timelockToSequence, sequenceToTimelock, ConditionMultisigTapscript, CLTVMultisigTapscript, ConditionCSVMultisigTapscript } from './chunk-FDJ734CH.js';
|
|
2
4
|
import { hex } from '@scure/base';
|
|
3
5
|
import { networks, expand } from '@bitcoinerlab/descriptors-scure';
|
|
4
|
-
import {
|
|
5
|
-
import * as P from 'micro-packed';
|
|
6
|
-
import { schnorr, secp256k1 } from '@noble/curves/secp256k1.js';
|
|
7
|
-
import { bytesToNumberBE } from '@noble/curves/utils.js';
|
|
8
|
-
import { equalBytes } from '@scure/btc-signer/utils.js';
|
|
6
|
+
import { Script } from '@scure/btc-signer';
|
|
9
7
|
|
|
10
8
|
// src/contracts/handlers/registry.ts
|
|
11
9
|
var ContractHandlerRegistry = class {
|
|
@@ -46,7 +44,7 @@ var ContractHandlerRegistry = class {
|
|
|
46
44
|
var contractHandlers = new ContractHandlerRegistry();
|
|
47
45
|
var DefaultVtxo;
|
|
48
46
|
((DefaultVtxo2) => {
|
|
49
|
-
class
|
|
47
|
+
class Script2 extends VtxoScript {
|
|
50
48
|
/** Create the default virtual output script with one forfeit path and one exit path. */
|
|
51
49
|
constructor(options) {
|
|
52
50
|
const { pubKey, serverPubKey, csvTimelock } = options;
|
|
@@ -79,7 +77,7 @@ var DefaultVtxo;
|
|
|
79
77
|
return this.findLeaf(this.exitScript);
|
|
80
78
|
}
|
|
81
79
|
}
|
|
82
|
-
DefaultVtxo2.Script =
|
|
80
|
+
DefaultVtxo2.Script = Script2;
|
|
83
81
|
})(DefaultVtxo || (DefaultVtxo = {}));
|
|
84
82
|
function isMainnetDescriptor(descriptor) {
|
|
85
83
|
return !descriptor.includes("tpub");
|
|
@@ -409,7 +407,7 @@ function deriveVhtlcTapscripts(script) {
|
|
|
409
407
|
const leaf = script.refundWithoutReceiver();
|
|
410
408
|
return {
|
|
411
409
|
forfeitTapLeafScript: leaf,
|
|
412
|
-
|
|
410
|
+
proofTapLeafScript: leaf,
|
|
413
411
|
tapTree: script.encode()
|
|
414
412
|
};
|
|
415
413
|
}
|
|
@@ -596,7 +594,7 @@ function discoverDefaultRange(entries, deps) {
|
|
|
596
594
|
}
|
|
597
595
|
var DelegateVtxo;
|
|
598
596
|
((DelegateVtxo2) => {
|
|
599
|
-
class
|
|
597
|
+
class Script2 extends VtxoScript {
|
|
600
598
|
/** Create a delegated virtual output script with forfeit, exit, and delegate paths. */
|
|
601
599
|
constructor(options) {
|
|
602
600
|
const defaultVtxo = new DefaultVtxo.Script(options);
|
|
@@ -625,7 +623,7 @@ var DelegateVtxo;
|
|
|
625
623
|
return this.findLeaf(this.delegateScript);
|
|
626
624
|
}
|
|
627
625
|
}
|
|
628
|
-
DelegateVtxo2.Script =
|
|
626
|
+
DelegateVtxo2.Script = Script2;
|
|
629
627
|
})(DelegateVtxo || (DelegateVtxo = {}));
|
|
630
628
|
|
|
631
629
|
// src/contracts/handlers/delegate.ts
|
|
@@ -696,331 +694,6 @@ function discoverDelegateRange(entries, deps) {
|
|
|
696
694
|
(c, index, descriptor) => ({ ...c, ...rotatedReceiveMetadata(index, descriptor) })
|
|
697
695
|
);
|
|
698
696
|
}
|
|
699
|
-
var ARKADE_OP = {
|
|
700
|
-
// Merkle Branch Verification (0xb3 — repurposed NOP4 slot)
|
|
701
|
-
MERKLEBRANCHVERIFY: 179,
|
|
702
|
-
PUT: 187,
|
|
703
|
-
// Digest (0xc3)
|
|
704
|
-
DIGEST: 195,
|
|
705
|
-
// SHA256 Streaming (0xc4-0xc6)
|
|
706
|
-
SHA256INITIALIZE: 196,
|
|
707
|
-
SHA256UPDATE: 197,
|
|
708
|
-
SHA256FINALIZE: 198,
|
|
709
|
-
// Input Introspection (0xc7-0xcb)
|
|
710
|
-
INSPECTINPUTOUTPOINT: 199,
|
|
711
|
-
INSPECTINPUTARKADESCRIPTHASH: 200,
|
|
712
|
-
INSPECTINPUTVALUE: 201,
|
|
713
|
-
INSPECTINPUTSCRIPTPUBKEY: 202,
|
|
714
|
-
INSPECTINPUTSEQUENCE: 203,
|
|
715
|
-
// Signatures (0xcc-0xcd)
|
|
716
|
-
CHECKSIGFROMSTACK: 204,
|
|
717
|
-
PUSHCURRENTINPUTINDEX: 205,
|
|
718
|
-
// Input Arkade Witness Introspection (0xce)
|
|
719
|
-
INSPECTINPUTARKADEWITNESSHASH: 206,
|
|
720
|
-
// Output Introspection (0xcf, 0xd1)
|
|
721
|
-
INSPECTOUTPUTVALUE: 207,
|
|
722
|
-
INSPECTOUTPUTSCRIPTPUBKEY: 209,
|
|
723
|
-
// Transaction Introspection (0xd2-0xd6)
|
|
724
|
-
INSPECTVERSION: 210,
|
|
725
|
-
INSPECTLOCKTIME: 211,
|
|
726
|
-
INSPECTNUMINPUTS: 212,
|
|
727
|
-
INSPECTNUMOUTPUTS: 213,
|
|
728
|
-
TXWEIGHT: 214,
|
|
729
|
-
// Byte/Number Conversion & Arithmetic (0xd7-0xda)
|
|
730
|
-
NUM2BIN: 215,
|
|
731
|
-
BIN2NUM: 216,
|
|
732
|
-
REVERSEBYTES: 217,
|
|
733
|
-
MODEXP: 218,
|
|
734
|
-
// VTXO Expiry & Emulator Clock (0xdb-0xdc)
|
|
735
|
-
PUSHEXPIRY: 219,
|
|
736
|
-
CHECKTIME: 220,
|
|
737
|
-
// 0xdd-0xdf are unassigned (OP_UNKNOWN221-223)
|
|
738
|
-
// EC Operations (0xe0-0xe2)
|
|
739
|
-
ECADD: 224,
|
|
740
|
-
ECMUL: 225,
|
|
741
|
-
ECPAIRING: 226,
|
|
742
|
-
// EC Operations (0xe3-0xe4)
|
|
743
|
-
ECMULSCALARVERIFY: 227,
|
|
744
|
-
TWEAKVERIFY: 228,
|
|
745
|
-
// Asset Groups (0xe5-0xf2)
|
|
746
|
-
INSPECTNUMASSETGROUPS: 229,
|
|
747
|
-
INSPECTASSETGROUPASSETID: 230,
|
|
748
|
-
INSPECTASSETGROUPCTRL: 231,
|
|
749
|
-
FINDASSETGROUPBYASSETID: 232,
|
|
750
|
-
INSPECTASSETGROUPMETADATAHASH: 233,
|
|
751
|
-
INSPECTASSETGROUPNUM: 234,
|
|
752
|
-
INSPECTASSETGROUP: 235,
|
|
753
|
-
INSPECTASSETGROUPSUM: 236,
|
|
754
|
-
INSPECTOUTASSETCOUNT: 237,
|
|
755
|
-
INSPECTOUTASSETAT: 238,
|
|
756
|
-
INSPECTOUTASSETLOOKUP: 239,
|
|
757
|
-
INSPECTINASSETCOUNT: 240,
|
|
758
|
-
INSPECTINASSETAT: 241,
|
|
759
|
-
INSPECTINASSETLOOKUP: 242,
|
|
760
|
-
// Transaction ID (0xf3)
|
|
761
|
-
TXID: 243,
|
|
762
|
-
// Packet Introspection (0xf4-0xf5) — added in emulator v0.0.1
|
|
763
|
-
INSPECTPACKET: 244,
|
|
764
|
-
INSPECTINPUTPACKET: 245,
|
|
765
|
-
// Signature Hash (0xf6)
|
|
766
|
-
SIGHASH: 246,
|
|
767
|
-
// Continuation & Intent Introspection (0xf7-0xf8)
|
|
768
|
-
TUNNEL: 247,
|
|
769
|
-
INSPECTINTENTMESSAGE: 248
|
|
770
|
-
};
|
|
771
|
-
var ARKADE_OPCODES = Object.values(ARKADE_OP);
|
|
772
|
-
var ARKADE_OPCODE_NAMES = Object.fromEntries(
|
|
773
|
-
Object.entries(ARKADE_OP).map(([name, value]) => [value, name])
|
|
774
|
-
);
|
|
775
|
-
var ARKADE_OPCODE_VALUES = Object.fromEntries(
|
|
776
|
-
Object.entries(ARKADE_OPCODE_NAMES).map(([value, name]) => [name, Number(value)])
|
|
777
|
-
);
|
|
778
|
-
function buildBitcoinOpcodeNames() {
|
|
779
|
-
const names = {};
|
|
780
|
-
for (const [key, value] of Object.entries(OP)) {
|
|
781
|
-
if (typeof value === "number") {
|
|
782
|
-
const name = key.startsWith("OP_") ? key : `OP_${key}`;
|
|
783
|
-
names[value] = name;
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
names[0] = "OP_0";
|
|
787
|
-
return names;
|
|
788
|
-
}
|
|
789
|
-
function buildBitcoinOpcodeValues() {
|
|
790
|
-
const values = {};
|
|
791
|
-
for (const [key, value] of Object.entries(OP)) {
|
|
792
|
-
if (typeof value === "number") {
|
|
793
|
-
const name = key.startsWith("OP_") ? key : `OP_${key}`;
|
|
794
|
-
values[name] = value;
|
|
795
|
-
values[key] = value;
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
return values;
|
|
799
|
-
}
|
|
800
|
-
var BITCOIN_OPCODE_NAMES = buildBitcoinOpcodeNames();
|
|
801
|
-
var BITCOIN_OPCODE_VALUES = buildBitcoinOpcodeValues();
|
|
802
|
-
var OPCODE_NAMES = {
|
|
803
|
-
...BITCOIN_OPCODE_NAMES,
|
|
804
|
-
// Add Arkade opcodes with OP_ prefix
|
|
805
|
-
...Object.fromEntries(
|
|
806
|
-
Object.entries(ARKADE_OPCODE_NAMES).map(([value, name]) => [Number(value), `OP_${name}`])
|
|
807
|
-
)
|
|
808
|
-
};
|
|
809
|
-
var OPCODE_VALUES = {
|
|
810
|
-
...BITCOIN_OPCODE_VALUES,
|
|
811
|
-
// Add Arkade opcodes with and without OP_ prefix
|
|
812
|
-
...ARKADE_OPCODE_VALUES,
|
|
813
|
-
...Object.fromEntries(
|
|
814
|
-
Object.entries(ARKADE_OPCODE_VALUES).map(([name, value]) => [`OP_${name}`, value])
|
|
815
|
-
)
|
|
816
|
-
};
|
|
817
|
-
function getOpcodeName(value) {
|
|
818
|
-
if (value >= 1 && value <= 75) {
|
|
819
|
-
return `OP_DATA_${value}`;
|
|
820
|
-
}
|
|
821
|
-
return OPCODE_NAMES[value];
|
|
822
|
-
}
|
|
823
|
-
function getOpcodeValue(name) {
|
|
824
|
-
const dataMatch = name.match(/^OP_DATA_(\d+)$/);
|
|
825
|
-
if (dataMatch) {
|
|
826
|
-
const n = parseInt(dataMatch[1], 10);
|
|
827
|
-
if (n >= 1 && n <= 75) {
|
|
828
|
-
return n;
|
|
829
|
-
}
|
|
830
|
-
return void 0;
|
|
831
|
-
}
|
|
832
|
-
return OPCODE_VALUES[name];
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
// src/arkade/bignum.ts
|
|
836
|
-
var bignum_exports = {};
|
|
837
|
-
__export(bignum_exports, {
|
|
838
|
-
BIGNUM_MAX_BYTES: () => BIGNUM_MAX_BYTES,
|
|
839
|
-
decode: () => decode,
|
|
840
|
-
encode: () => encode
|
|
841
|
-
});
|
|
842
|
-
var BIGNUM_MAX_BYTES = 520;
|
|
843
|
-
var codec = ScriptNum(
|
|
844
|
-
BIGNUM_MAX_BYTES,
|
|
845
|
-
/* forceMinimal */
|
|
846
|
-
true
|
|
847
|
-
);
|
|
848
|
-
function encode(value) {
|
|
849
|
-
const result = codec.encode(value);
|
|
850
|
-
if (result.length > BIGNUM_MAX_BYTES) {
|
|
851
|
-
throw new Error(`BigNum value exceeds 520 bytes (encoded to ${result.length} bytes)`);
|
|
852
|
-
}
|
|
853
|
-
return result;
|
|
854
|
-
}
|
|
855
|
-
function decode(value) {
|
|
856
|
-
return codec.decode(value);
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
// src/arkade/script.ts
|
|
860
|
-
var ARKADE_OPS = { ...OP, ...ARKADE_OP };
|
|
861
|
-
var ArkadeOPNames = {};
|
|
862
|
-
for (const [k, v] of Object.entries(ARKADE_OPS)) {
|
|
863
|
-
if (typeof v === "number") ArkadeOPNames[v] = k;
|
|
864
|
-
}
|
|
865
|
-
var ArkadeScript = P.wrap({
|
|
866
|
-
encodeStream: (w, value) => {
|
|
867
|
-
for (let o of value) {
|
|
868
|
-
if (typeof o === "string") {
|
|
869
|
-
const v = ARKADE_OPS[o];
|
|
870
|
-
if (v === void 0) throw new Error(`Unknown opcode=${o}`);
|
|
871
|
-
w.byte(v);
|
|
872
|
-
continue;
|
|
873
|
-
} else if (typeof o === "number" || typeof o === "bigint") {
|
|
874
|
-
const big = typeof o === "number" ? BigInt(o) : o;
|
|
875
|
-
o = encode(big);
|
|
876
|
-
}
|
|
877
|
-
if (!(o instanceof Uint8Array)) throw new Error(`Wrong Script OP=${o} (${typeof o})`);
|
|
878
|
-
const len = o.length;
|
|
879
|
-
if (len === 1 && o[0] >= 1 && o[0] <= 16) {
|
|
880
|
-
w.byte(OP.OP_1 - 1 + o[0]);
|
|
881
|
-
continue;
|
|
882
|
-
} else if (len === 1 && o[0] === 129) {
|
|
883
|
-
w.byte(OP["1NEGATE"]);
|
|
884
|
-
continue;
|
|
885
|
-
} else if (len < OP.PUSHDATA1) w.byte(len);
|
|
886
|
-
else if (len <= 255) {
|
|
887
|
-
w.byte(OP.PUSHDATA1);
|
|
888
|
-
w.byte(len);
|
|
889
|
-
} else if (len <= 65535) {
|
|
890
|
-
w.byte(OP.PUSHDATA2);
|
|
891
|
-
w.bytes(P.U16LE.encode(len));
|
|
892
|
-
} else {
|
|
893
|
-
w.byte(OP.PUSHDATA4);
|
|
894
|
-
w.bytes(P.U32LE.encode(len));
|
|
895
|
-
}
|
|
896
|
-
w.bytes(o);
|
|
897
|
-
}
|
|
898
|
-
},
|
|
899
|
-
decodeStream: (r) => {
|
|
900
|
-
const out = [];
|
|
901
|
-
while (!r.isEnd()) {
|
|
902
|
-
const cur = r.byte();
|
|
903
|
-
if (OP.OP_0 < cur && cur <= OP.PUSHDATA4) {
|
|
904
|
-
let len;
|
|
905
|
-
if (cur < OP.PUSHDATA1) len = cur;
|
|
906
|
-
else if (cur === OP.PUSHDATA1) len = P.U8.decodeStream(r);
|
|
907
|
-
else if (cur === OP.PUSHDATA2) len = P.U16LE.decodeStream(r);
|
|
908
|
-
else if (cur === OP.PUSHDATA4) len = P.U32LE.decodeStream(r);
|
|
909
|
-
else throw new Error("Should be not possible");
|
|
910
|
-
out.push(r.bytes(len));
|
|
911
|
-
} else if (cur === 0) {
|
|
912
|
-
out.push(0);
|
|
913
|
-
} else if (OP.OP_1 <= cur && cur <= OP.OP_16) {
|
|
914
|
-
out.push(cur - (OP.OP_1 - 1));
|
|
915
|
-
} else if (cur === OP["1NEGATE"]) {
|
|
916
|
-
out.push(-1);
|
|
917
|
-
} else {
|
|
918
|
-
const op = ArkadeOPNames[cur];
|
|
919
|
-
if (op === void 0) throw new Error(`Unknown opcode=${cur.toString(16)}`);
|
|
920
|
-
out.push(op);
|
|
921
|
-
}
|
|
922
|
-
}
|
|
923
|
-
return out;
|
|
924
|
-
}
|
|
925
|
-
});
|
|
926
|
-
function toASM(script) {
|
|
927
|
-
const parts = [];
|
|
928
|
-
for (const op of script) {
|
|
929
|
-
if (typeof op === "string") {
|
|
930
|
-
const name = op.startsWith("OP_") ? op : `OP_${op}`;
|
|
931
|
-
parts.push(name);
|
|
932
|
-
} else if (typeof op === "number" || typeof op === "bigint") {
|
|
933
|
-
if (op === 0 || op === 0n) {
|
|
934
|
-
parts.push("OP_0");
|
|
935
|
-
} else if (op >= 1 && op <= 16) {
|
|
936
|
-
parts.push(`OP_${op}`);
|
|
937
|
-
} else if (op === -1 || op === -1n) {
|
|
938
|
-
parts.push("OP_1NEGATE");
|
|
939
|
-
} else {
|
|
940
|
-
parts.push(hex.encode(encode(BigInt(op))));
|
|
941
|
-
}
|
|
942
|
-
} else {
|
|
943
|
-
parts.push(hex.encode(op));
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
return parts.join(" ");
|
|
947
|
-
}
|
|
948
|
-
function fromASM(asm) {
|
|
949
|
-
const tokens = asm.trim().split(/\s+/).filter(Boolean);
|
|
950
|
-
const out = [];
|
|
951
|
-
for (const token of tokens) {
|
|
952
|
-
if (token === "OP_0" || token === "OP_FALSE") {
|
|
953
|
-
out.push(0);
|
|
954
|
-
continue;
|
|
955
|
-
}
|
|
956
|
-
if (token === "OP_TRUE") {
|
|
957
|
-
out.push(1);
|
|
958
|
-
continue;
|
|
959
|
-
}
|
|
960
|
-
const numMatch = token.match(/^OP_(\d+)$/);
|
|
961
|
-
if (numMatch) {
|
|
962
|
-
const n = parseInt(numMatch[1], 10);
|
|
963
|
-
if (n >= 1 && n <= 16) {
|
|
964
|
-
out.push(n);
|
|
965
|
-
continue;
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
let key;
|
|
969
|
-
if (token.startsWith("OP_")) {
|
|
970
|
-
key = token.slice(3);
|
|
971
|
-
} else {
|
|
972
|
-
key = token;
|
|
973
|
-
}
|
|
974
|
-
if (key in ARKADE_OPS) {
|
|
975
|
-
out.push(key);
|
|
976
|
-
continue;
|
|
977
|
-
}
|
|
978
|
-
if (/^[0-9a-fA-F]+$/.test(token) && token.length % 2 === 0) {
|
|
979
|
-
try {
|
|
980
|
-
out.push(hex.decode(token));
|
|
981
|
-
continue;
|
|
982
|
-
} catch {
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
throw new Error(`Invalid ASM token: ${token}`);
|
|
986
|
-
}
|
|
987
|
-
return out;
|
|
988
|
-
}
|
|
989
|
-
function asmToBytes(asm) {
|
|
990
|
-
return ArkadeScript.encode(fromASM(asm));
|
|
991
|
-
}
|
|
992
|
-
function bytesToASM(script) {
|
|
993
|
-
return toASM(ArkadeScript.decode(script));
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
// src/utils/keys.ts
|
|
997
|
-
function toXOnly(key, label = "public key") {
|
|
998
|
-
if (key.length === 32) return key;
|
|
999
|
-
if (key.length === 33 && (key[0] === 2 || key[0] === 3)) return key.subarray(1);
|
|
1000
|
-
throw new Error(`${label} is not a compressed or x-only public key`);
|
|
1001
|
-
}
|
|
1002
|
-
|
|
1003
|
-
// src/arkade/tweak.ts
|
|
1004
|
-
var TAG_SCRIPT = "ArkScriptHash";
|
|
1005
|
-
var TAG_WITNESS = "ArkWitnessHash";
|
|
1006
|
-
function arkadeScriptHash(script) {
|
|
1007
|
-
return schnorr.utils.taggedHash(TAG_SCRIPT, script);
|
|
1008
|
-
}
|
|
1009
|
-
function arkadeWitnessHash(witness) {
|
|
1010
|
-
if (witness.length === 0) {
|
|
1011
|
-
return new Uint8Array(32);
|
|
1012
|
-
}
|
|
1013
|
-
return schnorr.utils.taggedHash(TAG_WITNESS, witness);
|
|
1014
|
-
}
|
|
1015
|
-
function computeArkadeScriptPublicKey(pubKey, script) {
|
|
1016
|
-
const hash = arkadeScriptHash(script);
|
|
1017
|
-
const point = schnorr.utils.lift_x(bytesToNumberBE(toXOnly(pubKey, "emulator key")));
|
|
1018
|
-
const scalar = bytesToNumberBE(hash) % secp256k1.Point.CURVE().n;
|
|
1019
|
-
const tweak = secp256k1.Point.BASE.multiply(scalar);
|
|
1020
|
-
return schnorr.utils.pointToBytes(point.add(tweak));
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
// src/script/vhtlc.ts
|
|
1024
697
|
var VHTLC;
|
|
1025
698
|
((VHTLC2) => {
|
|
1026
699
|
class BaseScript extends VtxoScript {
|
|
@@ -1211,12 +884,12 @@ var VHTLC;
|
|
|
1211
884
|
];
|
|
1212
885
|
}
|
|
1213
886
|
}
|
|
1214
|
-
class
|
|
887
|
+
class Script2 extends BaseScript {
|
|
1215
888
|
constructor(options) {
|
|
1216
889
|
super(options, preimageConditionScript);
|
|
1217
890
|
}
|
|
1218
891
|
}
|
|
1219
|
-
VHTLC2.Script =
|
|
892
|
+
VHTLC2.Script = Script2;
|
|
1220
893
|
class ScriptV2 extends BaseScript {
|
|
1221
894
|
constructor(options) {
|
|
1222
895
|
super(options, preimageConditionScriptV2);
|
|
@@ -1539,7 +1212,7 @@ var VHTLCV2ContractHandler = {
|
|
|
1539
1212
|
}
|
|
1540
1213
|
if (claim && refund && hex.encode(claim.emulatorPubkey) !== hex.encode(refund.emulatorPubkey)) {
|
|
1541
1214
|
throw new Error(
|
|
1542
|
-
"emulator covenant params name two different emulator pubkeys: the suite derives both
|
|
1215
|
+
"emulator covenant params name two different emulator pubkeys: the suite derives both covenants from ONE key, so this row cannot be rebuilt as a group"
|
|
1543
1216
|
);
|
|
1544
1217
|
}
|
|
1545
1218
|
if (params.assetTxid === void 0 !== (params.assetGroupIndex === void 0)) {
|
|
@@ -1638,6 +1311,7 @@ var VHTLCV2ContractHandler = {
|
|
|
1638
1311
|
};
|
|
1639
1312
|
var BoardingContractHandler = {
|
|
1640
1313
|
type: "boarding",
|
|
1314
|
+
defaultScope: "onchain",
|
|
1641
1315
|
createScript(params) {
|
|
1642
1316
|
return DefaultContractHandler.createScript(params);
|
|
1643
1317
|
},
|
|
@@ -1694,496 +1368,6 @@ var BoardingContractHandler = {
|
|
|
1694
1368
|
];
|
|
1695
1369
|
}
|
|
1696
1370
|
};
|
|
1697
|
-
var MinimalScriptNum = ScriptNum(void 0, true);
|
|
1698
|
-
var ARKADE_TYPE_ENCODINGS = {
|
|
1699
|
-
pubkey: "raw",
|
|
1700
|
-
signature: "schnorr-64",
|
|
1701
|
-
bytes: "raw",
|
|
1702
|
-
bytes20: "raw-20",
|
|
1703
|
-
bytes32: "raw-32",
|
|
1704
|
-
asset: "raw-32",
|
|
1705
|
-
int: "scriptnum",
|
|
1706
|
-
bool: "scriptnum",
|
|
1707
|
-
AssetGroup: "scriptnum"
|
|
1708
|
-
};
|
|
1709
|
-
var SUPPORTED_PROGRAM_VERSION = 1;
|
|
1710
|
-
var UnsupportedProgramVersionError = class extends Error {
|
|
1711
|
-
constructor(version, context) {
|
|
1712
|
-
super(
|
|
1713
|
-
`${context}: unsupported program version ${String(version)}; this SDK supports version ${SUPPORTED_PROGRAM_VERSION}. Recover it with an SDK that reads version ${String(version)}, re-create it with current params, or delete it.`
|
|
1714
|
-
);
|
|
1715
|
-
this.version = version;
|
|
1716
|
-
}
|
|
1717
|
-
version;
|
|
1718
|
-
name = "UnsupportedProgramVersionError";
|
|
1719
|
-
};
|
|
1720
|
-
function bindValue(bind, name) {
|
|
1721
|
-
const v = Object.hasOwn(bind, name) ? bind[name] : void 0;
|
|
1722
|
-
if (v === void 0) throw new Error(`unbound parameter '${name}'`);
|
|
1723
|
-
return v;
|
|
1724
|
-
}
|
|
1725
|
-
function resolveTimelockValue(value, args) {
|
|
1726
|
-
if (typeof value === "bigint") return value;
|
|
1727
|
-
if (value.startsWith("$")) {
|
|
1728
|
-
const v = bindValue(args, value.slice(1));
|
|
1729
|
-
if (typeof v === "bigint" || typeof v === "number") return BigInt(v);
|
|
1730
|
-
throw new Error(`timelock value '${value}' must resolve to a number`);
|
|
1731
|
-
}
|
|
1732
|
-
throw new Error(
|
|
1733
|
-
`invalid timelock value '${value}' \u2014 expected a bigint or a '$param' reference`
|
|
1734
|
-
);
|
|
1735
|
-
}
|
|
1736
|
-
function resolveCsvTimelock(csv, args) {
|
|
1737
|
-
const value = resolveTimelockValue(csv.value, args);
|
|
1738
|
-
if (csv.type !== "sequence") return { type: csv.type, value };
|
|
1739
|
-
const timelock = sequenceToCanonicalTimelock(value);
|
|
1740
|
-
if (!timelock) {
|
|
1741
|
-
throw new Error(
|
|
1742
|
-
`csv '${csv.value}' resolved to ${value}, which is not a canonical BIP68 sequence`
|
|
1743
|
-
);
|
|
1744
|
-
}
|
|
1745
|
-
return timelock;
|
|
1746
|
-
}
|
|
1747
|
-
function resolveAsm(asm, bind) {
|
|
1748
|
-
const tokens = asm.map((t) => {
|
|
1749
|
-
if (typeof t === "string" && t.startsWith("$")) {
|
|
1750
|
-
return bindValue(bind, t.slice(1));
|
|
1751
|
-
}
|
|
1752
|
-
if (t === "<SELF>") {
|
|
1753
|
-
throw new Error(
|
|
1754
|
-
"<SELF> is not a placeholder; use INSPECTINPUTSCRIPTPUBKEY for continuation covenants"
|
|
1755
|
-
);
|
|
1756
|
-
}
|
|
1757
|
-
return t;
|
|
1758
|
-
});
|
|
1759
|
-
return ArkadeScript.encode(tokens);
|
|
1760
|
-
}
|
|
1761
|
-
function witnessRefToBytes(ref, callArgs, programArgs) {
|
|
1762
|
-
if (ref instanceof Uint8Array) return ref;
|
|
1763
|
-
if (typeof ref === "number" || typeof ref === "bigint") {
|
|
1764
|
-
return MinimalScriptNum.encode(BigInt(ref));
|
|
1765
|
-
}
|
|
1766
|
-
const v = ref.startsWith("$") ? bindValue(programArgs, ref.slice(1)) : bindValue(callArgs, ref);
|
|
1767
|
-
if (v instanceof Uint8Array) return v;
|
|
1768
|
-
return MinimalScriptNum.encode(BigInt(v));
|
|
1769
|
-
}
|
|
1770
|
-
function validateTapscript(seg) {
|
|
1771
|
-
if (!seg.signers || seg.signers.length === 0) {
|
|
1772
|
-
throw new Error("tapscript: at least one signer is required");
|
|
1773
|
-
}
|
|
1774
|
-
if (seg.asm !== void 0 && seg.cltv !== void 0) {
|
|
1775
|
-
throw new Error(
|
|
1776
|
-
"tapscript: `asm` and `cltv` conflict \u2014 arkd has no condition+CLTV closure"
|
|
1777
|
-
);
|
|
1778
|
-
}
|
|
1779
|
-
if (seg.csv !== void 0 && seg.cltv !== void 0) {
|
|
1780
|
-
throw new Error("tapscript: `csv` and `cltv` conflict \u2014 use at most one timelock");
|
|
1781
|
-
}
|
|
1782
|
-
for (const t of seg.asm ?? []) {
|
|
1783
|
-
if (typeof t === "string" && t in ARKADE_OP) {
|
|
1784
|
-
throw new Error(
|
|
1785
|
-
`tapscript: arkade opcode '${t}' is not enforceable on-chain \u2014 move it to arkadeScript`
|
|
1786
|
-
);
|
|
1787
|
-
}
|
|
1788
|
-
}
|
|
1789
|
-
}
|
|
1790
|
-
function collectParamRefs(program) {
|
|
1791
|
-
const refs = /* @__PURE__ */ new Set();
|
|
1792
|
-
const collect = (items) => {
|
|
1793
|
-
for (const t of items ?? []) {
|
|
1794
|
-
if (typeof t === "string" && t.startsWith("$")) refs.add(t.slice(1));
|
|
1795
|
-
else if (isTweakedSigner(t) && t.tweak.startsWith("$")) refs.add(t.tweak.slice(1));
|
|
1796
|
-
}
|
|
1797
|
-
};
|
|
1798
|
-
for (const fn of Object.values(program.functions)) {
|
|
1799
|
-
const tap = fn.tapscript;
|
|
1800
|
-
collect(tap.signers);
|
|
1801
|
-
collect(tap.asm);
|
|
1802
|
-
collect(tap.witness);
|
|
1803
|
-
collect(tap.csv ? [tap.csv.value] : void 0);
|
|
1804
|
-
collect(tap.cltv !== void 0 ? [tap.cltv] : void 0);
|
|
1805
|
-
collect(fn.arkadeScript?.asm);
|
|
1806
|
-
collect(fn.arkadeScript?.witness);
|
|
1807
|
-
}
|
|
1808
|
-
return refs;
|
|
1809
|
-
}
|
|
1810
|
-
var TYPED_BYTE_LENGTHS = {
|
|
1811
|
-
pubkey: 32,
|
|
1812
|
-
signature: 64,
|
|
1813
|
-
bytes20: 20,
|
|
1814
|
-
bytes32: 32,
|
|
1815
|
-
asset: 32
|
|
1816
|
-
};
|
|
1817
|
-
function validateParamValue(def, value) {
|
|
1818
|
-
if (typeof def.type !== "string" || !Object.hasOwn(ARKADE_TYPE_ENCODINGS, def.type)) {
|
|
1819
|
-
throw new Error(`program parameter '${def.name}': unknown type '${def.type}'`);
|
|
1820
|
-
}
|
|
1821
|
-
if (ARKADE_TYPE_ENCODINGS[def.type] === "scriptnum") {
|
|
1822
|
-
if (typeof value !== "bigint" && typeof value !== "number") {
|
|
1823
|
-
throw new Error(`program parameter '${def.name}' expects ${def.type}, got bytes`);
|
|
1824
|
-
}
|
|
1825
|
-
if (typeof value === "number" && !Number.isSafeInteger(value)) {
|
|
1826
|
-
throw new Error(
|
|
1827
|
-
`program parameter '${def.name}' expects a safe integer; use bigint for larger values`
|
|
1828
|
-
);
|
|
1829
|
-
}
|
|
1830
|
-
if (def.type === "bool" && value !== 0 && value !== 1 && value !== 0n && value !== 1n) {
|
|
1831
|
-
throw new Error(`program parameter '${def.name}' expects a boolean encoded as 0 or 1`);
|
|
1832
|
-
}
|
|
1833
|
-
return;
|
|
1834
|
-
}
|
|
1835
|
-
if (!(value instanceof Uint8Array)) {
|
|
1836
|
-
throw new Error(
|
|
1837
|
-
`program parameter '${def.name}' expects ${def.type} bytes, got ${typeof value}`
|
|
1838
|
-
);
|
|
1839
|
-
}
|
|
1840
|
-
const length = TYPED_BYTE_LENGTHS[def.type];
|
|
1841
|
-
if (length !== void 0 && value.length !== length) {
|
|
1842
|
-
throw new Error(
|
|
1843
|
-
`program parameter '${def.name}' expects a ${length}-byte ${def.type}, got ${value.length} bytes`
|
|
1844
|
-
);
|
|
1845
|
-
}
|
|
1846
|
-
}
|
|
1847
|
-
function validateProgram(program, args) {
|
|
1848
|
-
const params = program.params ?? [];
|
|
1849
|
-
const declared = new Set(params.map((p) => p.name));
|
|
1850
|
-
for (const name of declared) {
|
|
1851
|
-
if (!Object.hasOwn(args, name) || args[name] === void 0) {
|
|
1852
|
-
throw new Error(`program parameter '${name}' is declared but not bound in args`);
|
|
1853
|
-
}
|
|
1854
|
-
}
|
|
1855
|
-
for (const ref of collectParamRefs(program)) {
|
|
1856
|
-
if (!declared.has(ref)) {
|
|
1857
|
-
throw new Error(`'$${ref}' is referenced but not declared in program params`);
|
|
1858
|
-
}
|
|
1859
|
-
}
|
|
1860
|
-
for (const p of params) {
|
|
1861
|
-
validateParamValue(p, args[p.name]);
|
|
1862
|
-
}
|
|
1863
|
-
for (const name of Object.keys(args)) {
|
|
1864
|
-
if (!declared.has(name)) throw new Error(`program: undeclared argument '${name}'`);
|
|
1865
|
-
}
|
|
1866
|
-
}
|
|
1867
|
-
function isTweakedSigner(ref) {
|
|
1868
|
-
if (typeof ref !== "object" || ref === null || ref instanceof Uint8Array) return false;
|
|
1869
|
-
const { tweak, fn } = ref;
|
|
1870
|
-
return typeof tweak === "string" && typeof fn === "string";
|
|
1871
|
-
}
|
|
1872
|
-
function resolveSigner(ref, args) {
|
|
1873
|
-
if (ref instanceof Uint8Array) return ref;
|
|
1874
|
-
if (typeof ref !== "string" || !ref.startsWith("$")) {
|
|
1875
|
-
throw new Error(`unknown signer reference '${ref}' \u2014 use a '$param' or key bytes`);
|
|
1876
|
-
}
|
|
1877
|
-
const v = bindValue(args, ref.slice(1));
|
|
1878
|
-
if (!(v instanceof Uint8Array)) {
|
|
1879
|
-
throw new Error(`signer ${ref} must be a pubkey (bytes)`);
|
|
1880
|
-
}
|
|
1881
|
-
return v;
|
|
1882
|
-
}
|
|
1883
|
-
function encodeTapscriptSegment(seg, pubkeys, args) {
|
|
1884
|
-
if (seg.csv) {
|
|
1885
|
-
const timelock = resolveCsvTimelock(seg.csv, args);
|
|
1886
|
-
if (seg.asm) {
|
|
1887
|
-
return ConditionCSVMultisigTapscript.encode({
|
|
1888
|
-
conditionScript: resolveAsm(seg.asm, args),
|
|
1889
|
-
timelock,
|
|
1890
|
-
pubkeys
|
|
1891
|
-
});
|
|
1892
|
-
}
|
|
1893
|
-
return CSVMultisigTapscript.encode({ timelock, pubkeys });
|
|
1894
|
-
}
|
|
1895
|
-
if (seg.cltv !== void 0) {
|
|
1896
|
-
return CLTVMultisigTapscript.encode({
|
|
1897
|
-
absoluteTimelock: resolveTimelockValue(seg.cltv, args),
|
|
1898
|
-
pubkeys
|
|
1899
|
-
});
|
|
1900
|
-
}
|
|
1901
|
-
if (seg.asm) {
|
|
1902
|
-
return ConditionMultisigTapscript.encode({
|
|
1903
|
-
conditionScript: resolveAsm(seg.asm, args),
|
|
1904
|
-
pubkeys
|
|
1905
|
-
});
|
|
1906
|
-
}
|
|
1907
|
-
return MultisigTapscript.encode({ pubkeys });
|
|
1908
|
-
}
|
|
1909
|
-
function compileFunctions(program, args, keys) {
|
|
1910
|
-
if (program.version !== SUPPORTED_PROGRAM_VERSION) {
|
|
1911
|
-
throw new UnsupportedProgramVersionError(program.version, "ArkadeContract");
|
|
1912
|
-
}
|
|
1913
|
-
const functions = program.functions;
|
|
1914
|
-
const names = Object.keys(functions);
|
|
1915
|
-
if (names.length === 0) {
|
|
1916
|
-
throw new Error("ArkadeContract: program has no functions");
|
|
1917
|
-
}
|
|
1918
|
-
validateProgram(program, args);
|
|
1919
|
-
if (args.server !== void 0 && (!(args.server instanceof Uint8Array) || !equalBytes(args.server, keys.serverKey))) {
|
|
1920
|
-
throw new Error(
|
|
1921
|
-
"ArkadeContract: reserved server parameter must match the contract server key"
|
|
1922
|
-
);
|
|
1923
|
-
}
|
|
1924
|
-
const defs = names.map((n) => functions[n]);
|
|
1925
|
-
const covenants = /* @__PURE__ */ new Map();
|
|
1926
|
-
for (const [name, def] of Object.entries(functions)) {
|
|
1927
|
-
if (!def.arkadeScript) continue;
|
|
1928
|
-
const script = resolveAsm(def.arkadeScript.asm, args);
|
|
1929
|
-
for (const target of [name, ...def.group ? [def.group] : []]) {
|
|
1930
|
-
const previous = covenants.get(target);
|
|
1931
|
-
if (previous && !equalBytes(previous, script)) {
|
|
1932
|
-
throw new Error(`ArkadeContract: ambiguous covenant '${target}'`);
|
|
1933
|
-
}
|
|
1934
|
-
covenants.set(target, script);
|
|
1935
|
-
}
|
|
1936
|
-
}
|
|
1937
|
-
const covenant = names.find(
|
|
1938
|
-
(_, i) => defs[i].arkadeScript && defs[i].tapscript.emulator !== null
|
|
1939
|
-
);
|
|
1940
|
-
if (covenant && !keys.emulatorKey) {
|
|
1941
|
-
throw new Error(
|
|
1942
|
-
`ArkadeContract: function '${covenant}' has an arkadeScript but no emulator is configured \u2014 pass an \`emulator\` to Arkade.connect`
|
|
1943
|
-
);
|
|
1944
|
-
}
|
|
1945
|
-
return defs.map((def, i) => {
|
|
1946
|
-
const pubkeys = def.tapscript.signers.map((signer) => {
|
|
1947
|
-
if (!isTweakedSigner(signer)) return resolveSigner(signer, args);
|
|
1948
|
-
const script = covenants.get(signer.fn);
|
|
1949
|
-
if (!script) {
|
|
1950
|
-
throw new Error(
|
|
1951
|
-
`ArkadeContract: function '${names[i]}' tweaks '${signer.fn}', which has no arkade script`
|
|
1952
|
-
);
|
|
1953
|
-
}
|
|
1954
|
-
return computeArkadeScriptPublicKey(resolveSigner(signer.tweak, args), script);
|
|
1955
|
-
});
|
|
1956
|
-
const arkadeScript = def.arkadeScript ? covenants.get(names[i]) : void 0;
|
|
1957
|
-
const leafPubkeys = [...pubkeys];
|
|
1958
|
-
if (arkadeScript && def.tapscript.emulator !== null) {
|
|
1959
|
-
const position = def.tapscript.emulatorIndex ?? pubkeys.length;
|
|
1960
|
-
if (!Number.isInteger(position) || position < 0 || position > pubkeys.length) {
|
|
1961
|
-
throw new Error(
|
|
1962
|
-
`ArkadeContract: function '${names[i]}' has an invalid emulator position ${position}`
|
|
1963
|
-
);
|
|
1964
|
-
}
|
|
1965
|
-
const target = def.group ? covenants.get(def.tapscript.emulator ?? def.group) : arkadeScript;
|
|
1966
|
-
if (!target || !equalBytes(target, arkadeScript)) {
|
|
1967
|
-
throw new Error(
|
|
1968
|
-
`ArkadeContract: function '${names[i]}' has an invalid emulator covenant '${def.tapscript.emulator}'`
|
|
1969
|
-
);
|
|
1970
|
-
}
|
|
1971
|
-
leafPubkeys.splice(
|
|
1972
|
-
position,
|
|
1973
|
-
0,
|
|
1974
|
-
computeArkadeScriptPublicKey(keys.emulatorKey, target)
|
|
1975
|
-
);
|
|
1976
|
-
} else if (def.tapscript.emulatorIndex !== void 0) {
|
|
1977
|
-
throw new Error(
|
|
1978
|
-
`ArkadeContract: function '${names[i]}' specifies an emulator position without an emulator`
|
|
1979
|
-
);
|
|
1980
|
-
}
|
|
1981
|
-
validateTapscript({ ...def.tapscript, signers: leafPubkeys });
|
|
1982
|
-
const leafScript = encodeTapscriptSegment(def.tapscript, leafPubkeys, args).script;
|
|
1983
|
-
return { name: names[i], def, leafScript, arkadeScript, signerKeys: pubkeys };
|
|
1984
|
-
});
|
|
1985
|
-
}
|
|
1986
|
-
var ArkadeProgramScript = class extends VtxoScript {
|
|
1987
|
-
constructor(program, args, keys) {
|
|
1988
|
-
const partial = compileFunctions(program, args, keys);
|
|
1989
|
-
super(partial.map((p) => p.leafScript));
|
|
1990
|
-
this.program = program;
|
|
1991
|
-
this.args = args;
|
|
1992
|
-
this.keys = keys;
|
|
1993
|
-
this.compiled = partial.map((p) => ({
|
|
1994
|
-
...p,
|
|
1995
|
-
tapLeafScript: this.findLeaf(hex.encode(p.leafScript))
|
|
1996
|
-
}));
|
|
1997
|
-
}
|
|
1998
|
-
program;
|
|
1999
|
-
args;
|
|
2000
|
-
keys;
|
|
2001
|
-
/** Spending paths in declaration order. */
|
|
2002
|
-
compiled;
|
|
2003
|
-
/** The compiled spending path with the given function name, if any. */
|
|
2004
|
-
functionByName(name) {
|
|
2005
|
-
return this.compiled.find((f) => f.name === name);
|
|
2006
|
-
}
|
|
2007
|
-
};
|
|
2008
|
-
function parseArtifact(artifact) {
|
|
2009
|
-
if (Array.isArray(artifact.functions)) {
|
|
2010
|
-
throw new Error(
|
|
2011
|
-
"parseArtifact: `functions` is an array, which is the arkadec artifact shape, not an SDK program \u2014 read it with programFromArtifact instead"
|
|
2012
|
-
);
|
|
2013
|
-
}
|
|
2014
|
-
if (typeof artifact.functions !== "object" || artifact.functions === null) {
|
|
2015
|
-
throw new Error("parseArtifact: `functions` must be an object keyed by function name");
|
|
2016
|
-
}
|
|
2017
|
-
const hexToken = (t) => typeof t === "string" && t.startsWith("0x") ? hex.decode(t.slice(2)) : t;
|
|
2018
|
-
const signerRef = (s) => {
|
|
2019
|
-
if (s instanceof Uint8Array || typeof s === "string") return hexToken(s);
|
|
2020
|
-
if (isTweakedSigner(s)) return { tweak: s.tweak, fn: s.fn };
|
|
2021
|
-
throw new Error("parseArtifact: a tweaked signer needs string `tweak` and `fn`");
|
|
2022
|
-
};
|
|
2023
|
-
const timelockValue = (v) => typeof v === "string" && v.startsWith("$") ? v : BigInt(v);
|
|
2024
|
-
if (artifact.version !== void 0 && artifact.version !== SUPPORTED_PROGRAM_VERSION) {
|
|
2025
|
-
throw new UnsupportedProgramVersionError(artifact.version, "parseArtifact");
|
|
2026
|
-
}
|
|
2027
|
-
const declarations = [artifact.params];
|
|
2028
|
-
for (const [name, fn] of Object.entries(artifact.functions)) {
|
|
2029
|
-
if (!fn || typeof fn !== "object" || Array.isArray(fn)) {
|
|
2030
|
-
throw new Error(`parseArtifact: function '${name}' must be an object`);
|
|
2031
|
-
}
|
|
2032
|
-
const tap = fn.tapscript;
|
|
2033
|
-
if (tap !== void 0 && (!tap || typeof tap !== "object" || Array.isArray(tap))) {
|
|
2034
|
-
throw new Error(`parseArtifact: function '${name}' tapscript must be an object`);
|
|
2035
|
-
}
|
|
2036
|
-
declarations.push(fn.inputs, tap?.signatures);
|
|
2037
|
-
if (tap?.emulatorIndex !== void 0 && (!Number.isInteger(tap.emulatorIndex) || tap.emulatorIndex < 0)) {
|
|
2038
|
-
throw new Error(`parseArtifact: function '${name}' has an invalid emulator position`);
|
|
2039
|
-
}
|
|
2040
|
-
}
|
|
2041
|
-
for (const defs of declarations) {
|
|
2042
|
-
if (defs === void 0) continue;
|
|
2043
|
-
if (!Array.isArray(defs)) {
|
|
2044
|
-
throw new Error(
|
|
2045
|
-
"parseArtifact: parameters, inputs and signatures require arrays of typed declarations"
|
|
2046
|
-
);
|
|
2047
|
-
}
|
|
2048
|
-
for (const def of defs) {
|
|
2049
|
-
if (!def || typeof def.name !== "string" || def.name.length === 0 || typeof def.type !== "string" || !Object.hasOwn(ARKADE_TYPE_ENCODINGS, def.type)) {
|
|
2050
|
-
throw new Error(
|
|
2051
|
-
"parseArtifact: parameters, inputs and signatures require typed { name, type } declarations"
|
|
2052
|
-
);
|
|
2053
|
-
}
|
|
2054
|
-
}
|
|
2055
|
-
}
|
|
2056
|
-
const functions = /* @__PURE__ */ Object.create(null);
|
|
2057
|
-
for (const [name, fn] of Object.entries(artifact.functions)) {
|
|
2058
|
-
const tap = fn.tapscript ?? {};
|
|
2059
|
-
const tapscript = {
|
|
2060
|
-
signers: (tap.signers ?? []).map(signerRef),
|
|
2061
|
-
...tap.signatures ? { signatures: tap.signatures } : {},
|
|
2062
|
-
...tap.asm ? { asm: tap.asm.map(hexToken) } : {},
|
|
2063
|
-
...tap.witness ? { witness: tap.witness.map(hexToken) } : {},
|
|
2064
|
-
...tap.csv ? { csv: { type: tap.csv.type, value: timelockValue(tap.csv.value) } } : {},
|
|
2065
|
-
...tap.cltv !== void 0 ? { cltv: timelockValue(tap.cltv) } : {},
|
|
2066
|
-
..."emulator" in tap ? { emulator: tap.emulator } : {},
|
|
2067
|
-
...tap.emulatorIndex !== void 0 ? { emulatorIndex: tap.emulatorIndex } : {}
|
|
2068
|
-
};
|
|
2069
|
-
const arkadeScript = fn.arkadeScript ? {
|
|
2070
|
-
asm: fn.arkadeScript.asm.map(hexToken),
|
|
2071
|
-
...fn.arkadeScript.witness ? { witness: fn.arkadeScript.witness.map(hexToken) } : {}
|
|
2072
|
-
} : void 0;
|
|
2073
|
-
functions[name] = {
|
|
2074
|
-
...fn.group !== void 0 ? { group: fn.group } : {},
|
|
2075
|
-
...fn.inputs ? { inputs: fn.inputs } : {},
|
|
2076
|
-
tapscript,
|
|
2077
|
-
...arkadeScript ? { arkadeScript } : {}
|
|
2078
|
-
};
|
|
2079
|
-
}
|
|
2080
|
-
return {
|
|
2081
|
-
version: artifact.version ?? SUPPORTED_PROGRAM_VERSION,
|
|
2082
|
-
...artifact.name !== void 0 ? { name: artifact.name } : {},
|
|
2083
|
-
...artifact.params ? { params: artifact.params } : {},
|
|
2084
|
-
functions
|
|
2085
|
-
};
|
|
2086
|
-
}
|
|
2087
|
-
function stringifyArtifact(program) {
|
|
2088
|
-
const token = (t) => {
|
|
2089
|
-
if (t instanceof Uint8Array) return "0x" + hex.encode(t);
|
|
2090
|
-
if (typeof t === "bigint") {
|
|
2091
|
-
if (t >= BigInt(Number.MIN_SAFE_INTEGER) && t <= BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
2092
|
-
return Number(t);
|
|
2093
|
-
}
|
|
2094
|
-
return "0x" + hex.encode(MinimalScriptNum.encode(t));
|
|
2095
|
-
}
|
|
2096
|
-
return t;
|
|
2097
|
-
};
|
|
2098
|
-
const functions = /* @__PURE__ */ Object.create(null);
|
|
2099
|
-
for (const [name, fn] of Object.entries(program.functions)) {
|
|
2100
|
-
const tap = fn.tapscript;
|
|
2101
|
-
functions[name] = {
|
|
2102
|
-
...fn.group !== void 0 ? { group: fn.group } : {},
|
|
2103
|
-
...fn.inputs ? { inputs: fn.inputs } : {},
|
|
2104
|
-
tapscript: {
|
|
2105
|
-
signers: tap.signers.map(token),
|
|
2106
|
-
...tap.signatures ? { signatures: tap.signatures } : {},
|
|
2107
|
-
...tap.asm ? { asm: tap.asm.map(token) } : {},
|
|
2108
|
-
...tap.witness ? { witness: tap.witness.map(token) } : {},
|
|
2109
|
-
...tap.csv ? { csv: { type: tap.csv.type, value: tap.csv.value.toString() } } : {},
|
|
2110
|
-
...tap.cltv !== void 0 ? { cltv: tap.cltv.toString() } : {},
|
|
2111
|
-
...tap.emulator !== void 0 ? { emulator: tap.emulator } : {},
|
|
2112
|
-
...tap.emulatorIndex !== void 0 ? { emulatorIndex: tap.emulatorIndex } : {}
|
|
2113
|
-
},
|
|
2114
|
-
...fn.arkadeScript ? {
|
|
2115
|
-
arkadeScript: {
|
|
2116
|
-
asm: fn.arkadeScript.asm.map(token),
|
|
2117
|
-
...fn.arkadeScript.witness ? { witness: fn.arkadeScript.witness.map(token) } : {}
|
|
2118
|
-
}
|
|
2119
|
-
} : {}
|
|
2120
|
-
};
|
|
2121
|
-
}
|
|
2122
|
-
return JSON.stringify({
|
|
2123
|
-
version: program.version,
|
|
2124
|
-
...program.name !== void 0 ? { name: program.name } : {},
|
|
2125
|
-
...program.params ? { params: program.params } : {},
|
|
2126
|
-
functions
|
|
2127
|
-
});
|
|
2128
|
-
}
|
|
2129
|
-
function serializeArgValue(v) {
|
|
2130
|
-
if (v instanceof Uint8Array) return "0x" + hex.encode(v);
|
|
2131
|
-
if (typeof v === "bigint") return v.toString();
|
|
2132
|
-
return v;
|
|
2133
|
-
}
|
|
2134
|
-
function parseTypedArgValue(name, type, v) {
|
|
2135
|
-
if (ARKADE_TYPE_ENCODINGS[type] === "scriptnum") {
|
|
2136
|
-
if (typeof v === "number") return v;
|
|
2137
|
-
if (typeof v === "string") return BigInt(v);
|
|
2138
|
-
throw new Error(
|
|
2139
|
-
`arkade contract params: '${name}' expects ${type}, got ${JSON.stringify(v)}`
|
|
2140
|
-
);
|
|
2141
|
-
}
|
|
2142
|
-
if (typeof v === "string" && v.startsWith("0x")) return hex.decode(v.slice(2));
|
|
2143
|
-
throw new Error(
|
|
2144
|
-
`arkade contract params: '${name}' expects ${type} as 0x-prefixed hex, got ${JSON.stringify(v)}`
|
|
2145
|
-
);
|
|
2146
|
-
}
|
|
2147
|
-
function serializeArkadeContractParams(typed) {
|
|
2148
|
-
const args = /* @__PURE__ */ Object.create(null);
|
|
2149
|
-
for (const [k, v] of Object.entries(typed.args)) {
|
|
2150
|
-
args[k] = serializeArgValue(v);
|
|
2151
|
-
}
|
|
2152
|
-
return {
|
|
2153
|
-
program: stringifyArtifact(typed.program),
|
|
2154
|
-
args: JSON.stringify(args),
|
|
2155
|
-
serverKey: hex.encode(typed.serverKey),
|
|
2156
|
-
...typed.userKey ? { userKey: hex.encode(typed.userKey) } : {},
|
|
2157
|
-
...typed.emulatorKey ? { emulatorKey: hex.encode(typed.emulatorKey) } : {}
|
|
2158
|
-
};
|
|
2159
|
-
}
|
|
2160
|
-
function deserializeArkadeContractParams(params) {
|
|
2161
|
-
if (!params.program) {
|
|
2162
|
-
throw new Error("arkade contract params: missing 'program'");
|
|
2163
|
-
}
|
|
2164
|
-
if (!params.serverKey) {
|
|
2165
|
-
throw new Error("arkade contract params: missing 'serverKey'");
|
|
2166
|
-
}
|
|
2167
|
-
const program = parseArtifact(JSON.parse(params.program));
|
|
2168
|
-
const paramTypes = new Map((program.params ?? []).map((p) => [p.name, p.type]));
|
|
2169
|
-
const args = /* @__PURE__ */ Object.create(null);
|
|
2170
|
-
if (params.args) {
|
|
2171
|
-
for (const [k, v] of Object.entries(JSON.parse(params.args))) {
|
|
2172
|
-
const type = paramTypes.get(k);
|
|
2173
|
-
if (!type) throw new Error(`arkade contract params: undeclared argument '${k}'`);
|
|
2174
|
-
args[k] = parseTypedArgValue(k, type, v);
|
|
2175
|
-
}
|
|
2176
|
-
}
|
|
2177
|
-
return {
|
|
2178
|
-
program,
|
|
2179
|
-
args,
|
|
2180
|
-
serverKey: hex.decode(params.serverKey),
|
|
2181
|
-
...params.userKey ? { userKey: hex.decode(params.userKey) } : {},
|
|
2182
|
-
...params.emulatorKey ? { emulatorKey: hex.decode(params.emulatorKey) } : {}
|
|
2183
|
-
};
|
|
2184
|
-
}
|
|
2185
|
-
|
|
2186
|
-
// src/contracts/handlers/arkade.ts
|
|
2187
1371
|
function walletKeyFrom(context) {
|
|
2188
1372
|
if (!context.walletDescriptor) return void 0;
|
|
2189
1373
|
try {
|
|
@@ -2192,21 +1376,13 @@ function walletKeyFrom(context) {
|
|
|
2192
1376
|
return void 0;
|
|
2193
1377
|
}
|
|
2194
1378
|
}
|
|
2195
|
-
function staticWitness(fn, script) {
|
|
2196
|
-
const refs = fn.def.tapscript.witness ?? [];
|
|
2197
|
-
try {
|
|
2198
|
-
return refs.map((w) => witnessRefToBytes(w, {}, script.args));
|
|
2199
|
-
} catch {
|
|
2200
|
-
return null;
|
|
2201
|
-
}
|
|
2202
|
-
}
|
|
2203
1379
|
function pathsFor(script, context, opts) {
|
|
2204
1380
|
const walletKey = walletKeyFrom(context);
|
|
2205
1381
|
const serverHex = hex.encode(script.keys.serverKey);
|
|
2206
1382
|
const paths = [];
|
|
2207
1383
|
for (const fn of script.compiled) {
|
|
2208
1384
|
if (fn.arkadeScript) continue;
|
|
2209
|
-
const witness = staticWitness(fn, script);
|
|
1385
|
+
const witness = staticWitness(fn.def.tapscript.witness, script.args);
|
|
2210
1386
|
if (witness === null) continue;
|
|
2211
1387
|
const signerHexes = fn.signerKeys.map((s) => hex.encode(s));
|
|
2212
1388
|
const requiresServer = signerHexes.includes(serverHex);
|
|
@@ -2297,7 +1473,7 @@ var ArkadeContractHandler = {
|
|
|
2297
1473
|
const leaf = collaborative[0]?.leaf ?? script.compiled.find((f) => f.arkadeScript)?.tapLeafScript ?? script.compiled[0].tapLeafScript;
|
|
2298
1474
|
return {
|
|
2299
1475
|
forfeitTapLeafScript: leaf,
|
|
2300
|
-
|
|
1476
|
+
proofTapLeafScript: leaf,
|
|
2301
1477
|
tapTree: script.encode()
|
|
2302
1478
|
};
|
|
2303
1479
|
}
|
|
@@ -2311,6 +1487,6 @@ contractHandlers.register(VHTLCV2ContractHandler);
|
|
|
2311
1487
|
contractHandlers.register(BoardingContractHandler);
|
|
2312
1488
|
contractHandlers.register(ArkadeContractHandler);
|
|
2313
1489
|
|
|
2314
|
-
export {
|
|
2315
|
-
//# sourceMappingURL=chunk-
|
|
2316
|
-
//# sourceMappingURL=chunk-
|
|
1490
|
+
export { ArkadeContractHandler, BoardingContractHandler, DefaultContractHandler, DefaultVtxo, DelegateContractHandler, DelegateVtxo, VHTLC, VHTLCContractHandler, VHTLCV2ContractHandler, WALLET_RECEIVE_SOURCE, contractHandlers, deriveDescriptorLeafCompressedPubKey, deriveDescriptorLeafPubKey, descriptorIsOurs, exitSequence, extractPubKey, identityDescriptor, isCltvSatisfied, isCsvSpendable, isMainnetDescriptor, normalizeToDescriptor, parseHDDescriptor, speculativeReceiveMetadata };
|
|
1491
|
+
//# sourceMappingURL=chunk-BCA6D255.js.map
|
|
1492
|
+
//# sourceMappingURL=chunk-BCA6D255.js.map
|