@arkade-os/sdk 0.5.4 → 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.
Files changed (112) hide show
  1. package/README.md +103 -17
  2. package/dist/adapters/expo.cjs +7 -6
  3. package/dist/adapters/expo.d.cts +4 -3
  4. package/dist/adapters/expo.d.ts +4 -3
  5. package/dist/adapters/expo.js +4 -3
  6. package/dist/{asyncStorageTaskQueue-DTBa8EH7.d.cts → asyncStorageTaskQueue-BbH-THYJ.d.cts} +1 -1
  7. package/dist/{asyncStorageTaskQueue-DHMIxY04.d.ts → asyncStorageTaskQueue-BlvkJyTa.d.ts} +1 -1
  8. package/dist/base-C-Y5t_0F.d.cts +359 -0
  9. package/dist/base-C-Y5t_0F.d.ts +359 -0
  10. package/dist/{chunk-AG4TFD6F.js → chunk-4I53THL6.js} +79 -884
  11. package/dist/chunk-4I53THL6.js.map +1 -0
  12. package/dist/{chunk-B6VNKGIH.cjs → chunk-5SYUEVJH.cjs} +10 -10
  13. package/dist/{chunk-B6VNKGIH.cjs.map → chunk-5SYUEVJH.cjs.map} +1 -1
  14. package/dist/{chunk-BTRCN4JJ.js → chunk-7GIKLFHC.js} +64 -4
  15. package/dist/chunk-7GIKLFHC.js.map +1 -0
  16. package/dist/{chunk-E6OOJEHL.cjs → chunk-AMH7Q3DF.cjs} +60 -934
  17. package/dist/chunk-AMH7Q3DF.cjs.map +1 -0
  18. package/dist/{chunk-6CUP6ZIF.js → chunk-BCA6D255.js} +17 -841
  19. package/dist/chunk-BCA6D255.js.map +1 -0
  20. package/dist/{chunk-TUOLZBNC.js → chunk-CE46RS6L.js} +5 -4
  21. package/dist/chunk-CE46RS6L.js.map +1 -0
  22. package/dist/chunk-DNFTHG73.js +829 -0
  23. package/dist/chunk-DNFTHG73.js.map +1 -0
  24. package/dist/chunk-FDJ734CH.js +882 -0
  25. package/dist/chunk-FDJ734CH.js.map +1 -0
  26. package/dist/chunk-FLPWNMX3.cjs +930 -0
  27. package/dist/chunk-FLPWNMX3.cjs.map +1 -0
  28. package/dist/{chunk-MWVAWFX6.js → chunk-FVVXCDNE.js} +4 -4
  29. package/dist/{chunk-MWVAWFX6.js.map → chunk-FVVXCDNE.js.map} +1 -1
  30. package/dist/{chunk-DNITZVNG.cjs → chunk-HQQ4NRXI.cjs} +18 -17
  31. package/dist/chunk-HQQ4NRXI.cjs.map +1 -0
  32. package/dist/chunk-JFJNB7ZH.cjs +884 -0
  33. package/dist/chunk-JFJNB7ZH.cjs.map +1 -0
  34. package/dist/{chunk-GHUUT54D.cjs → chunk-KCL5AVML.cjs} +89 -933
  35. package/dist/chunk-KCL5AVML.cjs.map +1 -0
  36. package/dist/{chunk-ZJHLLDBP.js → chunk-OO2KEK64.js} +2624 -1277
  37. package/dist/chunk-OO2KEK64.js.map +1 -0
  38. package/dist/{chunk-F3FAE7VJ.cjs → chunk-T254PXSN.cjs} +3115 -1752
  39. package/dist/chunk-T254PXSN.cjs.map +1 -0
  40. package/dist/chunk-V3ZLL5VY.js +380 -0
  41. package/dist/chunk-V3ZLL5VY.js.map +1 -0
  42. package/dist/chunk-X6ZI53DZ.cjs +383 -0
  43. package/dist/chunk-X6ZI53DZ.cjs.map +1 -0
  44. package/dist/{chunk-WXNSISXK.cjs → chunk-XWUCNMPN.cjs} +79 -18
  45. package/dist/chunk-XWUCNMPN.cjs.map +1 -0
  46. package/dist/compiler.cjs +50 -0
  47. package/dist/compiler.cjs.map +1 -0
  48. package/dist/compiler.d.cts +38 -0
  49. package/dist/compiler.d.ts +38 -0
  50. package/dist/compiler.js +47 -0
  51. package/dist/compiler.js.map +1 -0
  52. package/dist/contracts/handlers/index.cjs +11 -9
  53. package/dist/contracts/handlers/index.d.cts +6 -4
  54. package/dist/contracts/handlers/index.d.ts +6 -4
  55. package/dist/contracts/handlers/index.js +4 -2
  56. package/dist/{delegate-xrSBNybC.d.ts → delegate-gGkUnYpi.d.cts} +1 -1
  57. package/dist/{delegate-f4_t864Z.d.cts → delegate-iyDum4fw.d.ts} +1 -1
  58. package/dist/{index-BJDz15ms.d.ts → index-BWwVnJhU.d.cts} +5 -270
  59. package/dist/{index-BjiVGtp8.d.cts → index-Bx-iArDs.d.ts} +5 -270
  60. package/dist/{index-DRwe0UDN.d.ts → index-DCml4QJn.d.ts} +1593 -1711
  61. package/dist/{index-DRwe0UDN.d.cts → index-DkyzIzKL.d.cts} +1593 -1711
  62. package/dist/index.cjs +457 -378
  63. package/dist/index.d.cts +633 -378
  64. package/dist/index.d.ts +633 -378
  65. package/dist/index.js +7 -4
  66. package/dist/{wallet-jVBDQl6R.d.cts → keyringDescriptorProvider-CS4w4PWd.d.ts} +412 -361
  67. package/dist/{wallet-Oc3Wd5gv.d.ts → keyringDescriptorProvider-CmHXrIXd.d.cts} +412 -361
  68. package/dist/program-BARSNg3X.d.ts +286 -0
  69. package/dist/program-znrWkxE4.d.cts +286 -0
  70. package/dist/repositories/realm/index.cjs +71 -51
  71. package/dist/repositories/realm/index.cjs.map +1 -1
  72. package/dist/repositories/realm/index.d.cts +20 -9
  73. package/dist/repositories/realm/index.d.ts +20 -9
  74. package/dist/repositories/realm/index.js +42 -23
  75. package/dist/repositories/realm/index.js.map +1 -1
  76. package/dist/repositories/sqlite/index.cjs +81 -56
  77. package/dist/repositories/sqlite/index.cjs.map +1 -1
  78. package/dist/repositories/sqlite/index.d.cts +17 -8
  79. package/dist/repositories/sqlite/index.d.ts +17 -8
  80. package/dist/repositories/sqlite/index.js +55 -31
  81. package/dist/repositories/sqlite/index.js.map +1 -1
  82. package/dist/{taskRunner-CDlNeth0.d.ts → taskRunner-DgMLSk_O.d.ts} +1 -1
  83. package/dist/{taskRunner-BPPU-YHG.d.cts → taskRunner-buh6aFpG.d.cts} +1 -1
  84. package/dist/wallet/expo/background.cjs +17 -14
  85. package/dist/wallet/expo/background.cjs.map +1 -1
  86. package/dist/wallet/expo/background.d.cts +5 -4
  87. package/dist/wallet/expo/background.d.ts +5 -4
  88. package/dist/wallet/expo/background.js +9 -6
  89. package/dist/wallet/expo/background.js.map +1 -1
  90. package/dist/wallet/expo/index.cjs +29 -16
  91. package/dist/wallet/expo/index.cjs.map +1 -1
  92. package/dist/wallet/expo/index.d.cts +12 -7
  93. package/dist/wallet/expo/index.d.ts +12 -7
  94. package/dist/wallet/expo/index.js +19 -6
  95. package/dist/wallet/expo/index.js.map +1 -1
  96. package/dist/worker/expo/index.cjs +12 -9
  97. package/dist/worker/expo/index.cjs.map +1 -1
  98. package/dist/worker/expo/index.d.cts +6 -5
  99. package/dist/worker/expo/index.d.ts +6 -5
  100. package/dist/worker/expo/index.js +8 -5
  101. package/dist/worker/expo/index.js.map +1 -1
  102. package/package.json +16 -1
  103. package/dist/chunk-6CUP6ZIF.js.map +0 -1
  104. package/dist/chunk-AG4TFD6F.js.map +0 -1
  105. package/dist/chunk-BTRCN4JJ.js.map +0 -1
  106. package/dist/chunk-DNITZVNG.cjs.map +0 -1
  107. package/dist/chunk-E6OOJEHL.cjs.map +0 -1
  108. package/dist/chunk-F3FAE7VJ.cjs.map +0 -1
  109. package/dist/chunk-GHUUT54D.cjs.map +0 -1
  110. package/dist/chunk-TUOLZBNC.js.map +0 -1
  111. package/dist/chunk-WXNSISXK.cjs.map +0 -1
  112. package/dist/chunk-ZJHLLDBP.js.map +0 -1
@@ -1,905 +1,12 @@
1
1
  'use strict';
2
2
 
3
- var utils_js = require('@scure/btc-signer/utils.js');
4
- var base = require('@scure/base');
5
- var script_js = require('@scure/btc-signer/script.js');
6
- var bip68 = require('bip68');
3
+ var chunkFLPWNMX3_cjs = require('./chunk-FLPWNMX3.cjs');
7
4
  var btcSigner = require('@scure/btc-signer');
8
- var payment_js = require('@scure/btc-signer/payment.js');
9
- var P = require('micro-packed');
10
5
  var psbt_js = require('@scure/btc-signer/psbt.js');
6
+ var utils_js = require('@scure/btc-signer/utils.js');
11
7
  var secp256k1_js = require('@noble/curves/secp256k1.js');
8
+ var base = require('@scure/base');
12
9
 
13
- function _interopNamespace(e) {
14
- if (e && e.__esModule) return e;
15
- var n = Object.create(null);
16
- if (e) {
17
- Object.keys(e).forEach(function (k) {
18
- if (k !== 'default') {
19
- var d = Object.getOwnPropertyDescriptor(e, k);
20
- Object.defineProperty(n, k, d.get ? d : {
21
- enumerable: true,
22
- get: function () { return e[k]; }
23
- });
24
- }
25
- });
26
- }
27
- n.default = e;
28
- return Object.freeze(n);
29
- }
30
-
31
- var bip68__namespace = /*#__PURE__*/_interopNamespace(bip68);
32
- var P__namespace = /*#__PURE__*/_interopNamespace(P);
33
-
34
- var __defProp = Object.defineProperty;
35
- var __export = (target, all) => {
36
- for (var name in all)
37
- __defProp(target, name, { get: all[name], enumerable: true });
38
- };
39
- var getNetwork = (network) => {
40
- const found = networks[network];
41
- if (!found) throw new Error(`Unsupported network: ${network}`);
42
- return found;
43
- };
44
- var networkFromOperatorInfo = (info) => getNetwork(info.network);
45
- var networkFromArkadeInfo = networkFromOperatorInfo;
46
- var networks = {
47
- bitcoin: withArkPrefix(utils_js.NETWORK, "ark", "bitcoin"),
48
- testnet: withArkPrefix(utils_js.TEST_NETWORK, "tark", "testnet"),
49
- signet: withArkPrefix(utils_js.TEST_NETWORK, "tark", "signet"),
50
- mutinynet: withArkPrefix(utils_js.TEST_NETWORK, "tark", "mutinynet"),
51
- regtest: withArkPrefix(
52
- {
53
- ...utils_js.TEST_NETWORK,
54
- bech32: "bcrt",
55
- pubKeyHash: 111,
56
- scriptHash: 196
57
- },
58
- "tark",
59
- "regtest"
60
- )
61
- };
62
- function withArkPrefix(network, prefix, name) {
63
- return {
64
- ...network,
65
- hrp: prefix,
66
- name
67
- };
68
- }
69
- var DEFAULT_ARKADE_SERVER_URL = "https://arkade.computer";
70
- var DEFAULT_ARKADE_EMULATOR_URL = "https://emulator.arkade.computer";
71
- var DEFAULT_NETWORK = networks.bitcoin;
72
- var DEFAULT_NETWORK_NAME = "bitcoin";
73
- var COMPRESSED_PUBKEY = /^0[23][0-9a-f]{64}$/;
74
- var BITCOIN_EMULATOR_PUBKEY = "0239c196415da47b26456a101daaa12ba9e445bfe153197f1e2b750bf40e52092e";
75
- var MUTINYNET_EMULATOR_PUBKEY = "03f823b9b2febc81f4af967e77aed2f541cbd3397c6d8f5a72e32eb7b471af889a";
76
- var REGTEST_EMULATOR_PUBKEY = "02999413c46fa10ada5cbc4bcc79a1d09160c2ba3cfc812705d7a13e5e545fb2a9";
77
- var EMULATOR_PUBKEYS = {
78
- bitcoin: BITCOIN_EMULATOR_PUBKEY,
79
- mutinynet: MUTINYNET_EMULATOR_PUBKEY,
80
- regtest: REGTEST_EMULATOR_PUBKEY
81
- };
82
- function defaultEmulatorPubkey(network) {
83
- const pinned = network.name ? EMULATOR_PUBKEYS[network.name] : void 0;
84
- if (!pinned) {
85
- const cause = network.name ? `no emulator is deployed for ${network.name}` : `this Network carries no name, so it cannot be matched (build it with getNetwork(...) rather than by hand)`;
86
- throw new Error(
87
- `No emulator co-signer key is pinned for this network: ${cause}; pass emulatorPubkey: "<33-byte compressed hex>" to Arkade.connect to co-sign with your own emulator instead. Pinned networks: ${Object.keys(EMULATOR_PUBKEYS).join(", ")}`
88
- );
89
- }
90
- return pinned;
91
- }
92
- function resolveEmulatorPubkey(network, override) {
93
- if (override === void 0) return defaultEmulatorPubkey(network);
94
- if (!COMPRESSED_PUBKEY.test(override)) {
95
- throw new Error(
96
- `Emulator pubkey override must be 33-byte compressed secp256k1 hex (66 lowercase chars, 02/03 prefix), got ${JSON.stringify(override)}.`
97
- );
98
- }
99
- return override;
100
- }
101
- var ArkAddress = class _ArkAddress {
102
- /**
103
- * Create an Arkade address from its server public key, Taproot output key, and prefix.
104
- *
105
- * @param serverPubKey - 32-byte Arkade server public key
106
- * @param vtxoTaprootKey - 32-byte Taproot output key (a.k.a. tweaked public key)
107
- * @param hrp - Bech32 human-readable prefix
108
- * @param version - Address version byte
109
- * @defaultValue `version = 0`
110
- * @throws Error if either public key is not 32 bytes long
111
- */
112
- constructor(serverPubKey, vtxoTaprootKey, hrp = DEFAULT_NETWORK.hrp, version2 = 0) {
113
- this.serverPubKey = serverPubKey;
114
- this.vtxoTaprootKey = vtxoTaprootKey;
115
- this.hrp = hrp;
116
- this.version = version2;
117
- if (serverPubKey.length !== 32) {
118
- throw new Error(
119
- "Invalid server public key length, expected 32 bytes, got " + serverPubKey.length
120
- );
121
- }
122
- if (vtxoTaprootKey.length !== 32) {
123
- throw new Error(
124
- "Invalid vtxo taproot public key length, expected 32 bytes, got " + vtxoTaprootKey.length
125
- );
126
- }
127
- }
128
- serverPubKey;
129
- vtxoTaprootKey;
130
- hrp;
131
- version;
132
- /**
133
- * Decode an Arkade address from its bech32m string form.
134
- *
135
- * @param address - Bech32m-encoded Arkade address
136
- * @returns Decoded Arkade address
137
- * @throws Error if the address is malformed or has an invalid payload length
138
- * @see encode
139
- */
140
- static decode(address) {
141
- const decoded = base.bech32m.decodeUnsafe(address, 1023);
142
- if (!decoded) {
143
- throw new Error("Invalid address");
144
- }
145
- const data = new Uint8Array(base.bech32m.fromWords(decoded.words));
146
- if (data.length !== 1 + 32 + 32) {
147
- throw new Error("Invalid data length, expected 65 bytes, got " + data.length);
148
- }
149
- const version2 = data[0];
150
- const serverPubKey = data.slice(1, 33);
151
- const vtxoTaprootPubKey = data.slice(33, 65);
152
- return new _ArkAddress(serverPubKey, vtxoTaprootPubKey, decoded.prefix, version2);
153
- }
154
- /**
155
- * Encode the address to its bech32m string form.
156
- *
157
- * @returns Bech32m-encoded Arkade address
158
- * @see decode
159
- */
160
- encode() {
161
- const data = new Uint8Array(1 + 32 + 32);
162
- data[0] = this.version;
163
- data.set(this.serverPubKey, 1);
164
- data.set(this.vtxoTaprootKey, 33);
165
- const words = base.bech32m.toWords(data);
166
- return base.bech32m.encode(this.hrp, words, 1023);
167
- }
168
- /** ScriptPubKey used to send non-dust funds to the address. */
169
- get pkScript() {
170
- return script_js.Script.encode(["OP_1", this.vtxoTaprootKey]);
171
- }
172
- /** ScriptPubKey used to send sub-dust funds to the address. */
173
- get subdustPkScript() {
174
- return script_js.Script.encode(["RETURN", this.vtxoTaprootKey]);
175
- }
176
- };
177
- function timelockToSequence(timelock) {
178
- return bip68__namespace.encode(
179
- timelock.type === "blocks" ? { blocks: Number(timelock.value) } : { seconds: Number(timelock.value) }
180
- );
181
- }
182
- function sequenceToTimelock(sequence) {
183
- const decoded = bip68__namespace.decode(sequence);
184
- if ("blocks" in decoded && decoded.blocks !== void 0) {
185
- return { type: "blocks", value: BigInt(decoded.blocks) };
186
- }
187
- if ("seconds" in decoded && decoded.seconds !== void 0) {
188
- return { type: "seconds", value: BigInt(decoded.seconds) };
189
- }
190
- throw new Error(`Invalid BIP68 sequence: ${sequence}`);
191
- }
192
- function sequenceToCanonicalTimelock(sequence) {
193
- if (sequence < 0n || sequence >= 0x80000000n) return void 0;
194
- const timelock = sequenceToTimelock(Number(sequence));
195
- return BigInt(timelockToSequence(timelock)) === sequence ? timelock : void 0;
196
- }
197
- var MinimalScriptNum = btcSigner.ScriptNum(void 0, true);
198
- function decodeTapscript(script) {
199
- const types = [
200
- exports.MultisigTapscript,
201
- exports.CSVMultisigTapscript,
202
- exports.ConditionCSVMultisigTapscript,
203
- exports.ConditionMultisigTapscript,
204
- exports.CLTVMultisigTapscript
205
- ];
206
- for (const type of types) {
207
- try {
208
- return type.decode(script);
209
- } catch (error) {
210
- continue;
211
- }
212
- }
213
- throw new Error(`Failed to decode: script ${base.hex.encode(script)} is not a valid tapscript`);
214
- }
215
- exports.MultisigTapscript = void 0;
216
- ((MultisigTapscript2) => {
217
- ((MultisigType2) => {
218
- MultisigType2[MultisigType2["CHECKSIG"] = 0] = "CHECKSIG";
219
- MultisigType2[MultisigType2["CHECKSIGADD"] = 1] = "CHECKSIGADD";
220
- })(MultisigTapscript2.MultisigType || (MultisigTapscript2.MultisigType = {}));
221
- function encode2(params) {
222
- if (params.pubkeys.length === 0) {
223
- throw new Error("At least 1 pubkey is required");
224
- }
225
- for (const pubkey of params.pubkeys) {
226
- if (pubkey.length !== 32) {
227
- throw new Error(`Invalid pubkey length: expected 32, got ${pubkey.length}`);
228
- }
229
- }
230
- if (!params.type) {
231
- params.type = 0 /* CHECKSIG */;
232
- }
233
- if (params.type === 1 /* CHECKSIGADD */) {
234
- return {
235
- type: "multisig" /* Multisig */,
236
- params,
237
- script: btcSigner.p2tr_ms(params.pubkeys.length, params.pubkeys).script
238
- };
239
- }
240
- const asm = [];
241
- for (let i = 0; i < params.pubkeys.length; i++) {
242
- asm.push(params.pubkeys[i]);
243
- if (i < params.pubkeys.length - 1) {
244
- asm.push("CHECKSIGVERIFY");
245
- } else {
246
- asm.push("CHECKSIG");
247
- }
248
- }
249
- return {
250
- type: "multisig" /* Multisig */,
251
- params,
252
- script: btcSigner.Script.encode(asm)
253
- };
254
- }
255
- MultisigTapscript2.encode = encode2;
256
- function decode2(script) {
257
- if (script.length === 0) {
258
- throw new Error("Failed to decode: script is empty");
259
- }
260
- try {
261
- return decodeChecksigAdd(script);
262
- } catch (error) {
263
- try {
264
- return decodeChecksig(script);
265
- } catch (error2) {
266
- throw new Error(
267
- `Failed to decode script: ${error2 instanceof Error ? error2.message : String(error2)}`
268
- );
269
- }
270
- }
271
- }
272
- MultisigTapscript2.decode = decode2;
273
- function decodeChecksigAdd(script) {
274
- const asm = btcSigner.Script.decode(script);
275
- const pubkeys = [];
276
- let foundNumEqual = false;
277
- for (let i = 0; i < asm.length; i++) {
278
- const op = asm[i];
279
- if (typeof op !== "string" && typeof op !== "number") {
280
- if (op.length !== 32) {
281
- throw new Error(`Invalid pubkey length: expected 32, got ${op.length}`);
282
- }
283
- pubkeys.push(op);
284
- if (i + 1 >= asm.length || asm[i + 1] !== "CHECKSIGADD" && asm[i + 1] !== "CHECKSIG") {
285
- throw new Error("Expected CHECKSIGADD or CHECKSIG after pubkey");
286
- }
287
- i++;
288
- continue;
289
- }
290
- if (i === asm.length - 1) {
291
- if (op !== "NUMEQUAL") {
292
- throw new Error("Expected NUMEQUAL at end of script");
293
- }
294
- foundNumEqual = true;
295
- }
296
- }
297
- if (!foundNumEqual) {
298
- throw new Error("Missing NUMEQUAL operation");
299
- }
300
- if (pubkeys.length === 0) {
301
- throw new Error("Invalid script: must have at least 1 pubkey");
302
- }
303
- const reconstructed = encode2({
304
- pubkeys,
305
- type: 1 /* CHECKSIGADD */
306
- });
307
- if (base.hex.encode(reconstructed.script) !== base.hex.encode(script)) {
308
- throw new Error("Invalid script format: script reconstruction mismatch");
309
- }
310
- return {
311
- type: "multisig" /* Multisig */,
312
- params: { pubkeys, type: 1 /* CHECKSIGADD */ },
313
- script
314
- };
315
- }
316
- function decodeChecksig(script) {
317
- const asm = btcSigner.Script.decode(script);
318
- const pubkeys = [];
319
- for (let i = 0; i < asm.length; i++) {
320
- const op = asm[i];
321
- if (typeof op !== "string" && typeof op !== "number") {
322
- if (op.length !== 32) {
323
- throw new Error(`Invalid pubkey length: expected 32, got ${op.length}`);
324
- }
325
- pubkeys.push(op);
326
- if (i + 1 >= asm.length) {
327
- throw new Error("Unexpected end of script");
328
- }
329
- const nextOp = asm[i + 1];
330
- if (nextOp !== "CHECKSIGVERIFY" && nextOp !== "CHECKSIG") {
331
- throw new Error("Expected CHECKSIGVERIFY or CHECKSIG after pubkey");
332
- }
333
- if (i === asm.length - 2 && nextOp !== "CHECKSIG") {
334
- throw new Error("Last operation must be CHECKSIG");
335
- }
336
- i++;
337
- continue;
338
- }
339
- }
340
- if (pubkeys.length === 0) {
341
- throw new Error("Invalid script: must have at least 1 pubkey");
342
- }
343
- const reconstructed = encode2({ pubkeys, type: 0 /* CHECKSIG */ });
344
- if (base.hex.encode(reconstructed.script) !== base.hex.encode(script)) {
345
- throw new Error("Invalid script format: script reconstruction mismatch");
346
- }
347
- return {
348
- type: "multisig" /* Multisig */,
349
- params: { pubkeys, type: 0 /* CHECKSIG */ },
350
- script
351
- };
352
- }
353
- function is(tapscript) {
354
- return tapscript.type === "multisig" /* Multisig */;
355
- }
356
- MultisigTapscript2.is = is;
357
- })(exports.MultisigTapscript || (exports.MultisigTapscript = {}));
358
- exports.CSVMultisigTapscript = void 0;
359
- ((CSVMultisigTapscript2) => {
360
- function encode2(params) {
361
- for (const pubkey of params.pubkeys) {
362
- if (pubkey.length !== 32) {
363
- throw new Error(`Invalid pubkey length: expected 32, got ${pubkey.length}`);
364
- }
365
- }
366
- const sequence = MinimalScriptNum.encode(BigInt(timelockToSequence(params.timelock)));
367
- const asm = [
368
- sequence.length === 1 ? sequence[0] : sequence,
369
- "CHECKSEQUENCEVERIFY",
370
- "DROP"
371
- ];
372
- const multisigScript = exports.MultisigTapscript.encode(params);
373
- const script = new Uint8Array([...btcSigner.Script.encode(asm), ...multisigScript.script]);
374
- return {
375
- type: "csv-multisig" /* CSVMultisig */,
376
- params,
377
- script
378
- };
379
- }
380
- CSVMultisigTapscript2.encode = encode2;
381
- function decode2(script) {
382
- if (script.length === 0) {
383
- throw new Error("Failed to decode: script is empty");
384
- }
385
- const isValid = isScriptValid(script);
386
- if (isValid instanceof Error) {
387
- throw isValid;
388
- }
389
- const asm = btcSigner.Script.decode(script);
390
- const sequence = asm[0];
391
- const multisigScript = new Uint8Array(btcSigner.Script.encode(asm.slice(3)));
392
- let multisig;
393
- try {
394
- multisig = exports.MultisigTapscript.decode(multisigScript);
395
- } catch (error) {
396
- throw new Error(
397
- `Invalid multisig script: ${error instanceof Error ? error.message : String(error)}`
398
- );
399
- }
400
- let sequenceNum;
401
- if (typeof sequence === "number") {
402
- sequenceNum = sequence;
403
- } else {
404
- sequenceNum = Number(MinimalScriptNum.decode(sequence));
405
- }
406
- const timelock = sequenceToTimelock(sequenceNum);
407
- const reconstructed = encode2({
408
- timelock,
409
- ...multisig.params
410
- });
411
- if (base.hex.encode(reconstructed.script) !== base.hex.encode(script)) {
412
- throw new Error("Invalid script format: script reconstruction mismatch");
413
- }
414
- return {
415
- type: "csv-multisig" /* CSVMultisig */,
416
- params: {
417
- timelock,
418
- ...multisig.params
419
- },
420
- script
421
- };
422
- }
423
- CSVMultisigTapscript2.decode = decode2;
424
- function is(tapscript) {
425
- return tapscript.type === "csv-multisig" /* CSVMultisig */;
426
- }
427
- CSVMultisigTapscript2.is = is;
428
- function isScriptValid(script) {
429
- const asm = btcSigner.Script.decode(script);
430
- if (asm.length < 3) {
431
- return new Error(`Invalid script: too short (expected at least 3)`);
432
- }
433
- const sequence = asm[0];
434
- if (typeof sequence === "string") {
435
- return new Error("Invalid script: expected sequence number");
436
- }
437
- if (asm[1] !== "CHECKSEQUENCEVERIFY" || asm[2] !== "DROP") {
438
- return new Error("Invalid script: expected CHECKSEQUENCEVERIFY DROP");
439
- }
440
- return true;
441
- }
442
- CSVMultisigTapscript2.isScriptValid = isScriptValid;
443
- })(exports.CSVMultisigTapscript || (exports.CSVMultisigTapscript = {}));
444
- function isConditionScriptValid(script) {
445
- const asm = btcSigner.Script.decode(script);
446
- if (asm.length < 1) {
447
- return new Error(`Invalid script: too short (expected at least 1)`);
448
- }
449
- if (asm.lastIndexOf("VERIFY") === -1) {
450
- return new Error("Invalid script: missing VERIFY operation");
451
- }
452
- return true;
453
- }
454
- exports.ConditionCSVMultisigTapscript = void 0;
455
- ((ConditionCSVMultisigTapscript2) => {
456
- function encode2(params) {
457
- const script = new Uint8Array([
458
- ...params.conditionScript,
459
- ...btcSigner.Script.encode(["VERIFY"]),
460
- ...exports.CSVMultisigTapscript.encode(params).script
461
- ]);
462
- return {
463
- type: "condition-csv-multisig" /* ConditionCSVMultisig */,
464
- params,
465
- script
466
- };
467
- }
468
- ConditionCSVMultisigTapscript2.encode = encode2;
469
- function decode2(script) {
470
- if (script.length === 0) {
471
- throw new Error("Failed to decode: script is empty");
472
- }
473
- const isValid = isScriptValid(script);
474
- if (isValid instanceof Error) {
475
- throw isValid;
476
- }
477
- const asm = btcSigner.Script.decode(script);
478
- const verifyIndex = asm.lastIndexOf("VERIFY");
479
- if (verifyIndex === -1) {
480
- throw Error("Invalid script: missing VERIFY operation");
481
- }
482
- const conditionScript = new Uint8Array(btcSigner.Script.encode(asm.slice(0, verifyIndex)));
483
- const csvMultisigScript = new Uint8Array(btcSigner.Script.encode(asm.slice(verifyIndex + 1)));
484
- let csvMultisig;
485
- try {
486
- csvMultisig = exports.CSVMultisigTapscript.decode(csvMultisigScript);
487
- } catch (error) {
488
- throw new Error(
489
- `Invalid CSV multisig script: ${error instanceof Error ? error.message : String(error)}`
490
- );
491
- }
492
- const reconstructed = encode2({
493
- conditionScript,
494
- ...csvMultisig.params
495
- });
496
- if (base.hex.encode(reconstructed.script) !== base.hex.encode(script)) {
497
- throw new Error("Invalid script format: script reconstruction mismatch");
498
- }
499
- return {
500
- type: "condition-csv-multisig" /* ConditionCSVMultisig */,
501
- params: {
502
- conditionScript,
503
- ...csvMultisig.params
504
- },
505
- script
506
- };
507
- }
508
- ConditionCSVMultisigTapscript2.decode = decode2;
509
- function is(tapscript) {
510
- return tapscript.type === "condition-csv-multisig" /* ConditionCSVMultisig */;
511
- }
512
- ConditionCSVMultisigTapscript2.is = is;
513
- function isScriptValid(script) {
514
- return isConditionScriptValid(script);
515
- }
516
- ConditionCSVMultisigTapscript2.isScriptValid = isScriptValid;
517
- })(exports.ConditionCSVMultisigTapscript || (exports.ConditionCSVMultisigTapscript = {}));
518
- exports.ConditionMultisigTapscript = void 0;
519
- ((ConditionMultisigTapscript2) => {
520
- function encode2(params) {
521
- const script = new Uint8Array([
522
- ...params.conditionScript,
523
- ...btcSigner.Script.encode(["VERIFY"]),
524
- ...exports.MultisigTapscript.encode(params).script
525
- ]);
526
- return {
527
- type: "condition-multisig" /* ConditionMultisig */,
528
- params,
529
- script
530
- };
531
- }
532
- ConditionMultisigTapscript2.encode = encode2;
533
- function decode2(script) {
534
- if (script.length === 0) {
535
- throw new Error("Failed to decode: script is empty");
536
- }
537
- const isValid = isScriptValid(script);
538
- if (isValid instanceof Error) {
539
- throw isValid;
540
- }
541
- const asm = btcSigner.Script.decode(script);
542
- const verifyIndex = asm.lastIndexOf("VERIFY");
543
- if (verifyIndex === -1) {
544
- throw Error("Invalid script: missing VERIFY operation");
545
- }
546
- const conditionScript = new Uint8Array(btcSigner.Script.encode(asm.slice(0, verifyIndex)));
547
- const multisigScript = new Uint8Array(btcSigner.Script.encode(asm.slice(verifyIndex + 1)));
548
- let multisig;
549
- try {
550
- multisig = exports.MultisigTapscript.decode(multisigScript);
551
- } catch (error) {
552
- throw new Error(
553
- `Invalid multisig script: ${error instanceof Error ? error.message : String(error)}`
554
- );
555
- }
556
- const reconstructed = encode2({
557
- conditionScript,
558
- ...multisig.params
559
- });
560
- if (base.hex.encode(reconstructed.script) !== base.hex.encode(script)) {
561
- throw new Error("Invalid script format: script reconstruction mismatch");
562
- }
563
- return {
564
- type: "condition-multisig" /* ConditionMultisig */,
565
- params: {
566
- conditionScript,
567
- ...multisig.params
568
- },
569
- script
570
- };
571
- }
572
- ConditionMultisigTapscript2.decode = decode2;
573
- function is(tapscript) {
574
- return tapscript.type === "condition-multisig" /* ConditionMultisig */;
575
- }
576
- ConditionMultisigTapscript2.is = is;
577
- function isScriptValid(script) {
578
- return isConditionScriptValid(script);
579
- }
580
- ConditionMultisigTapscript2.isScriptValid = isScriptValid;
581
- })(exports.ConditionMultisigTapscript || (exports.ConditionMultisigTapscript = {}));
582
- exports.CLTVMultisigTapscript = void 0;
583
- ((CLTVMultisigTapscript2) => {
584
- function encode2(params) {
585
- const locktime = MinimalScriptNum.encode(params.absoluteTimelock);
586
- const asm = [
587
- locktime.length === 1 ? locktime[0] : locktime,
588
- "CHECKLOCKTIMEVERIFY",
589
- "DROP"
590
- ];
591
- const timelockedScript = btcSigner.Script.encode(asm);
592
- const script = new Uint8Array([
593
- ...timelockedScript,
594
- ...exports.MultisigTapscript.encode(params).script
595
- ]);
596
- return {
597
- type: "cltv-multisig" /* CLTVMultisig */,
598
- params,
599
- script
600
- };
601
- }
602
- CLTVMultisigTapscript2.encode = encode2;
603
- function decode2(script) {
604
- if (script.length === 0) {
605
- throw new Error("Failed to decode: script is empty");
606
- }
607
- const isValid = isScriptValid(script);
608
- if (isValid instanceof Error) {
609
- throw isValid;
610
- }
611
- const asm = btcSigner.Script.decode(script);
612
- const locktime = asm[0];
613
- if (typeof locktime === "string") {
614
- throw new Error("Invalid script: expected locktime number");
615
- }
616
- if (asm[1] !== "CHECKLOCKTIMEVERIFY" || asm[2] !== "DROP") {
617
- throw new Error("Invalid script: expected CHECKLOCKTIMEVERIFY DROP");
618
- }
619
- const multisigScript = new Uint8Array(btcSigner.Script.encode(asm.slice(3)));
620
- let multisig;
621
- try {
622
- multisig = exports.MultisigTapscript.decode(multisigScript);
623
- } catch (error) {
624
- throw new Error(
625
- `Invalid multisig script: ${error instanceof Error ? error.message : String(error)}`
626
- );
627
- }
628
- let absoluteTimelock;
629
- if (typeof locktime === "number") {
630
- absoluteTimelock = BigInt(locktime);
631
- } else {
632
- absoluteTimelock = MinimalScriptNum.decode(locktime);
633
- }
634
- const reconstructed = encode2({
635
- absoluteTimelock,
636
- ...multisig.params
637
- });
638
- if (base.hex.encode(reconstructed.script) !== base.hex.encode(script)) {
639
- throw new Error("Invalid script format: script reconstruction mismatch");
640
- }
641
- return {
642
- type: "cltv-multisig" /* CLTVMultisig */,
643
- params: {
644
- absoluteTimelock,
645
- ...multisig.params
646
- },
647
- script
648
- };
649
- }
650
- CLTVMultisigTapscript2.decode = decode2;
651
- function is(tapscript) {
652
- return tapscript.type === "cltv-multisig" /* CLTVMultisig */;
653
- }
654
- CLTVMultisigTapscript2.is = is;
655
- function isScriptValid(script) {
656
- const asm = btcSigner.Script.decode(script);
657
- if (asm.length < 3) {
658
- return new Error(`Invalid script: too short (expected at least 3)`);
659
- }
660
- const locktime = asm[0];
661
- if (typeof locktime === "string") {
662
- return new Error("Invalid script: expected locktime as number or bytes");
663
- }
664
- if (asm[1] !== "CHECKLOCKTIMEVERIFY" || asm[2] !== "DROP") {
665
- return new Error("Invalid script: expected CHECKLOCKTIMEVERIFY DROP");
666
- }
667
- return true;
668
- }
669
- CLTVMultisigTapscript2.isScriptValid = isScriptValid;
670
- })(exports.CLTVMultisigTapscript || (exports.CLTVMultisigTapscript = {}));
671
- function assembleBtcdTaprootTree(scripts) {
672
- if (scripts.length === 0) {
673
- throw new Error("assembleBtcdTaprootTree: empty scripts list");
674
- }
675
- const leaves = scripts.map((script) => ({
676
- script,
677
- leafVersion: payment_js.TAP_LEAF_VERSION
678
- }));
679
- if (leaves.length === 1) {
680
- return leaves[0];
681
- }
682
- const branches = [];
683
- for (let i = 0; i < leaves.length; i += 2) {
684
- if (i === leaves.length - 1) {
685
- const last = branches.pop();
686
- if (last === void 0) {
687
- throw new Error(
688
- `assembleBtcdTaprootTree: unexpected odd leaf at i=${i} with no prior branch`
689
- );
690
- }
691
- branches.push([last, leaves[i]]);
692
- } else {
693
- branches.push([leaves[i], leaves[i + 1]]);
694
- }
695
- }
696
- while (branches.length >= 2) {
697
- const left = branches.shift();
698
- const right = branches.shift();
699
- branches.push([left, right]);
700
- }
701
- return branches[0];
702
- }
703
- function btcdLeafLayout(count) {
704
- const placeholders = Array.from({ length: count }, () => new Uint8Array());
705
- const indexOf = new Map(placeholders.map((script, index) => [script, index]));
706
- const layout = [];
707
- const walk = (node, depth) => {
708
- if (Array.isArray(node)) {
709
- walk(node[0], depth + 1);
710
- walk(node[1], depth + 1);
711
- } else {
712
- layout.push({ index: indexOf.get(node.script), depth });
713
- }
714
- };
715
- walk(assembleBtcdTaprootTree(placeholders), 0);
716
- return layout;
717
- }
718
- var TapTreeCoder = P__namespace.array(
719
- null,
720
- P__namespace.struct({ depth: P__namespace.U8, version: P__namespace.U8, script: script_js.VarBytes })
721
- );
722
- function scriptFromTapLeafScript(leaf) {
723
- return leaf[1].subarray(0, leaf[1].length - 1);
724
- }
725
- var VtxoScript = class _VtxoScript {
726
- /**
727
- * Create a virtual output script from its tapleaf scripts.
728
- *
729
- * The Taproot script tree is assembled using btcd's algorithm
730
- * (`txscript.AssembleTaprootScriptTree`) so the derived taproot output
731
- * key agrees with arkd for any leaf count. `@scure/btc-signer`'s
732
- * default `taprootListToTree` is a Huffman builder that only agrees
733
- * with arkd for power-of-2 leaf counts.
734
- *
735
- * @param scripts - Raw tapscript bytes for each leaf
736
- * @throws Error if the provided leaves cannot produce a valid Taproot tree
737
- */
738
- constructor(scripts) {
739
- this.scripts = scripts;
740
- const tapTree = assembleBtcdTaprootTree(scripts);
741
- const payment = btcSigner.p2tr(btcSigner.taprootNumsKey(), tapTree, void 0, true);
742
- if (!payment.tapLeafScript || payment.tapLeafScript.length !== scripts.length) {
743
- throw new Error("invalid scripts");
744
- }
745
- this.leaves = payment.tapLeafScript;
746
- this.tweakedPublicKey = payment.tweakedPubkey;
747
- this.pkScript = payment.script;
748
- }
749
- scripts;
750
- leaves;
751
- tweakedPublicKey;
752
- pkScript;
753
- /**
754
- * Decode a virtual output script from an encoded TapTree.
755
- *
756
- * Leaves are normally read in construction order and their depths
757
- * ignored: that covers the {@link encode} form (every depth 1) and the
758
- * placeholder depths other writers use, such as arkd's. The exception is
759
- * the BIP-371 form {@link toBIP371TapTree} writes, whose leaves are in the
760
- * tree's DFS order: for some leaf counts (6, 7, 10, ...) that differs from
761
- * construction order. A tree whose depths are exactly the shape
762
- * `assembleBtcdTaprootTree` builds is that form, so its leaves are mapped
763
- * back to construction order first. No construction-order writer produces
764
- * that depth sequence when the two orders differ, so this never reorders
765
- * a tree that decoded correctly before.
766
- *
767
- * Every leaf must carry the base tapscript version: the tree is rebuilt
768
- * with {@link TAP_LEAF_VERSION} leaves, so any other version would
769
- * silently derive a different taproot key.
770
- *
771
- * @param tapTree - Encoded TapTree bytes
772
- * @returns Decoded virtual output script
773
- * @throws Error if the TapTree cannot be decoded into a valid script set
774
- * or a leaf carries a version other than {@link TAP_LEAF_VERSION}
775
- * @see encode
776
- */
777
- static decode(tapTree) {
778
- const leaves = TapTreeCoder.decode(tapTree);
779
- const foreign = leaves.find((leaf) => leaf.version !== payment_js.TAP_LEAF_VERSION);
780
- if (foreign) {
781
- throw new Error(`unsupported tap leaf version 0x${foreign.version.toString(16)}`);
782
- }
783
- const scripts = leaves.map((leaf) => leaf.script);
784
- if (leaves.every((leaf) => leaf.depth === 1)) {
785
- return new _VtxoScript(scripts);
786
- }
787
- const layout = btcdLeafLayout(leaves.length);
788
- if (layout.some((slot, i) => slot.depth !== leaves[i].depth)) {
789
- return new _VtxoScript(scripts);
790
- }
791
- const ordered = new Array(leaves.length);
792
- layout.forEach((slot, i) => {
793
- ordered[slot.index] = scripts[i];
794
- });
795
- return new _VtxoScript(ordered);
796
- }
797
- /**
798
- * Encode the virtual output script to a TapTree byte representation.
799
- *
800
- * @returns Encoded TapTree bytes
801
- * @see decode
802
- */
803
- encode() {
804
- const tapTree = TapTreeCoder.encode(
805
- this.scripts.map((script) => ({
806
- depth: 1,
807
- version: payment_js.TAP_LEAF_VERSION,
808
- script
809
- }))
810
- );
811
- return tapTree;
812
- }
813
- /**
814
- * Build the Arkade address corresponding to this virtual output script.
815
- *
816
- * @param prefix - Bech32 human-readable prefix
817
- * @param serverPubKey - 32-byte Arkade server public key
818
- * @returns Arkade address for this script
819
- * @see ArkAddress
820
- */
821
- address(prefix = DEFAULT_NETWORK.hrp, serverPubKey) {
822
- return new ArkAddress(serverPubKey, this.tweakedPublicKey, prefix);
823
- }
824
- /**
825
- * Build the Taproot onchain address corresponding to this virtual output script.
826
- *
827
- * @param network - Bitcoin network descriptor
828
- * @returns Taproot onchain address
829
- * @see address
830
- */
831
- onchainAddress(network = DEFAULT_NETWORK) {
832
- return btcSigner.Address(network).encode({
833
- type: "tr",
834
- pubkey: this.tweakedPublicKey
835
- });
836
- }
837
- /**
838
- * Look up a tapleaf script by its hex-encoded tapscript body.
839
- *
840
- * @param scriptHex - Hex-encoded tapscript body without the leaf version byte
841
- * @returns Matching tapleaf script
842
- * @throws Error if no matching leaf exists
843
- */
844
- findLeaf(scriptHex) {
845
- const leaf = this.leaves.find(
846
- (leaf2) => base.hex.encode(scriptFromTapLeafScript(leaf2)) === scriptHex
847
- );
848
- if (!leaf) {
849
- throw new Error(`leaf '${scriptHex}' not found`);
850
- }
851
- return leaf;
852
- }
853
- /**
854
- * Return all unilateral exit paths embedded in the virtual output script.
855
- *
856
- * @returns CSV-based exit paths found in the leaves
857
- * @see getSequence
858
- */
859
- exitPaths() {
860
- const paths = [];
861
- for (const leaf of this.leaves) {
862
- try {
863
- const script = scriptFromTapLeafScript(leaf);
864
- if (exports.CSVMultisigTapscript.isScriptValid(script) === true) {
865
- const tapScript = exports.CSVMultisigTapscript.decode(script);
866
- paths.push(tapScript);
867
- } else if (exports.ConditionCSVMultisigTapscript.isScriptValid(script) === true) {
868
- const tapScript = exports.ConditionCSVMultisigTapscript.decode(script);
869
- paths.push(tapScript);
870
- }
871
- } catch (e) {
872
- console.debug("Failed to decode script", e);
873
- }
874
- }
875
- return paths;
876
- }
877
- };
878
- function toBIP371TapTree(tapTree) {
879
- const scripts = TapTreeCoder.decode(tapTree).map((leaf) => leaf.script);
880
- const vtxoScript = new VtxoScript(scripts);
881
- return vtxoScript.leaves.map((leaf) => ({
882
- depth: leaf[0].merklePath.length,
883
- version: payment_js.TAP_LEAF_VERSION,
884
- script: scriptFromTapLeafScript(leaf)
885
- }));
886
- }
887
- function getSequence(tapLeafScript) {
888
- let sequence = void 0;
889
- try {
890
- const scriptWithLeafVersion = tapLeafScript[1];
891
- const script = scriptWithLeafVersion.subarray(0, scriptWithLeafVersion.length - 1);
892
- try {
893
- const params = exports.CSVMultisigTapscript.decode(script).params;
894
- sequence = timelockToSequence(params.timelock);
895
- } catch {
896
- const params = exports.CLTVMultisigTapscript.decode(script).params;
897
- sequence = Number(params.absoluteTimelock);
898
- }
899
- } catch {
900
- }
901
- return sequence;
902
- }
903
10
  var Transaction = class extends btcSigner.Transaction {
904
11
  static ARK_TX_OPTS = {
905
12
  unknown: "ignore",
@@ -963,13 +70,13 @@ function legacyTapTreeToBIP371(value) {
963
70
  }
964
71
  let leaves;
965
72
  try {
966
- leaves = TapTreeCoder.decode(value);
73
+ leaves = chunkFLPWNMX3_cjs.TapTreeCoder.decode(value);
967
74
  } catch {
968
75
  return void 0;
969
76
  }
970
77
  if (leaves.length === 0 || leaves.some((leaf) => leaf.depth !== 1)) return void 0;
971
78
  try {
972
- return TapTreeCoder.encode(toBIP371TapTree(value));
79
+ return chunkFLPWNMX3_cjs.TapTreeCoder.encode(chunkFLPWNMX3_cjs.toBIP371TapTree(value));
973
80
  } catch {
974
81
  return void 0;
975
82
  }
@@ -1170,7 +277,7 @@ var VtxoTreeExpiry = {
1170
277
  if (!checkKeyMatch(unknown[0], "expiry" /* VtxoTreeExpiry */)) return null;
1171
278
  const v = btcSigner.ScriptNum(6, true).decode(unknown[1]);
1172
279
  if (!v) return null;
1173
- return sequenceToTimelock(Number(v));
280
+ return chunkFLPWNMX3_cjs.sequenceToTimelock(Number(v));
1174
281
  })
1175
282
  };
1176
283
  var encodedPsbtFieldKey = Object.fromEntries(
@@ -1195,7 +302,7 @@ function checkKeyMatch(key, arkPsbtFieldKey, prefixOnly = false) {
1195
302
  }
1196
303
 
1197
304
  // package.json
1198
- var version = "0.5.4";
305
+ var version = "0.5.5";
1199
306
 
1200
307
  // src/utils/fetch.ts
1201
308
  var buildVersion = "0.9.9";
@@ -1384,7 +491,8 @@ var ArkErrorName = {
1384
491
  * timestamp**, not wall clock, so a prompt spend is rejected until a later block lands.
1385
492
  */
1386
493
  FORFEIT_CLOSURE_LOCKED: "FORFEIT_CLOSURE_LOCKED",
1387
- INVALID_INTENT_PROOF: "INVALID_INTENT_PROOF"
494
+ INVALID_INTENT_PROOF: "INVALID_INTENT_PROOF",
495
+ INTERNAL_ERROR: "INTERNAL_ERROR"
1388
496
  };
1389
497
  function isArkError(error, name) {
1390
498
  return error instanceof ArkError && (name === void 0 || error.name === name);
@@ -1606,8 +714,8 @@ function prepareProofInput(coin) {
1606
714
  if (!("tapTree" in coin)) {
1607
715
  return coin;
1608
716
  }
1609
- const vtxoScript = VtxoScript.decode(coin.tapTree);
1610
- const sequence = getSequence(coin.intentTapLeafScript);
717
+ const vtxoScript = chunkFLPWNMX3_cjs.VtxoScript.decode(coin.tapTree);
718
+ const sequence = chunkFLPWNMX3_cjs.getSequence(chunkFLPWNMX3_cjs.proofTapLeafScriptOf(coin));
1611
719
  const unknown = [VtxoTaprootTree.encode(coin.tapTree)];
1612
720
  if (coin.extraWitness) {
1613
721
  unknown.push(ConditionWitness.encode(coin.extraWitness));
@@ -1623,7 +731,7 @@ function prepareProofInput(coin) {
1623
731
  script: vtxoScript.pkScript
1624
732
  },
1625
733
  sequence,
1626
- tapLeafScript: [coin.intentTapLeafScript],
734
+ tapLeafScript: [chunkFLPWNMX3_cjs.proofTapLeafScriptOf(coin)],
1627
735
  unknown
1628
736
  };
1629
737
  }
@@ -1886,6 +994,35 @@ var DigestMismatchError = class extends Error {
1886
994
  this.name = "DigestMismatchError";
1887
995
  }
1888
996
  };
997
+ var ONCHAIN_COSIGN_UNSUPPORTED_PREFIX = "Arkade server does not support onchain cosigning";
998
+ var ONCHAIN_COSIGN_REJECTED_PREFIX = "Arkade server refused to cosign onchain tx: ";
999
+ var OnchainCosignUnsupportedError = class extends Error {
1000
+ constructor() {
1001
+ super(ONCHAIN_COSIGN_UNSUPPORTED_PREFIX);
1002
+ this.name = "OnchainCosignUnsupportedError";
1003
+ }
1004
+ };
1005
+ var OnchainCosignRejectedError = class extends Error {
1006
+ constructor(serverMessage, arkErrorName) {
1007
+ super(
1008
+ `${ONCHAIN_COSIGN_REJECTED_PREFIX}${arkErrorName ? `[${arkErrorName}] ` : ""}${serverMessage}`
1009
+ );
1010
+ this.serverMessage = serverMessage;
1011
+ this.arkErrorName = arkErrorName;
1012
+ this.name = "OnchainCosignRejectedError";
1013
+ }
1014
+ serverMessage;
1015
+ arkErrorName;
1016
+ };
1017
+ var ONCHAIN_COSIGN_AMBIGUOUS_PREFIX = "Onchain cosign outcome unknown, the transaction may have been broadcast: ";
1018
+ var OnchainCosignAmbiguousError = class extends Error {
1019
+ constructor(detail, options) {
1020
+ super(`${ONCHAIN_COSIGN_AMBIGUOUS_PREFIX}${detail}`, options);
1021
+ this.detail = detail;
1022
+ this.name = "OnchainCosignAmbiguousError";
1023
+ }
1024
+ detail;
1025
+ };
1889
1026
  var SettlementEventType = /* @__PURE__ */ ((SettlementEventType2) => {
1890
1027
  SettlementEventType2["BatchStarted"] = "batch_started";
1891
1028
  SettlementEventType2["BatchFinalization"] = "batch_finalization";
@@ -1904,7 +1041,7 @@ function advertisedLimit(fromServer) {
1904
1041
  return limit > 0n ? limit : void 0;
1905
1042
  }
1906
1043
  var RestOperatorProvider = class {
1907
- constructor(serverUrl = DEFAULT_ARKADE_SERVER_URL, options = {}) {
1044
+ constructor(serverUrl = chunkFLPWNMX3_cjs.DEFAULT_ARKADE_SERVER_URL, options = {}) {
1908
1045
  this.serverUrl = serverUrl;
1909
1046
  this.eventSource = options.eventSource;
1910
1047
  }
@@ -1917,6 +1054,7 @@ var RestOperatorProvider = class {
1917
1054
  * stale. Empty until the first {@link getInfo}.
1918
1055
  */
1919
1056
  _digest = "";
1057
+ _onchainCosignUnsupported = false;
1920
1058
  _hasServerInfo = false;
1921
1059
  _suppressNextGetInfoChangeEmit = false;
1922
1060
  _serverInfoListeners = /* @__PURE__ */ new Set();
@@ -1932,6 +1070,7 @@ var RestOperatorProvider = class {
1932
1070
  };
1933
1071
  }
1934
1072
  emitServerInfoChanged(info) {
1073
+ this._onchainCosignUnsupported = false;
1935
1074
  for (const listener of this._serverInfoListeners) {
1936
1075
  try {
1937
1076
  listener(info);
@@ -1975,7 +1114,7 @@ var RestOperatorProvider = class {
1975
1114
  return response;
1976
1115
  }
1977
1116
  const arkError = maybeArkError(new Error(body));
1978
- if (!arkError) throwIfHttpUnavailable(response, "arkade");
1117
+ if (!arkError && response.status !== 501) throwIfHttpUnavailable(response, "arkade");
1979
1118
  if (!isArkError(arkError, ArkErrorName.DIGEST_MISMATCH)) return response;
1980
1119
  this._digest = "";
1981
1120
  this._suppressNextGetInfoChangeEmit = true;
@@ -2087,6 +1226,41 @@ var RestOperatorProvider = class {
2087
1226
  signedCheckpointTxs: data.signedCheckpointTxs
2088
1227
  };
2089
1228
  }
1229
+ async cosignOnchainTx(psbtB64) {
1230
+ if (this._onchainCosignUnsupported) throw new OnchainCosignUnsupportedError();
1231
+ let response;
1232
+ let text;
1233
+ try {
1234
+ response = await this.authedFetch(`${this.serverUrl}/v1/tx/onchain/cosign`, {
1235
+ method: "POST",
1236
+ headers: { "Content-Type": "application/json" },
1237
+ body: JSON.stringify({ tx: psbtB64 })
1238
+ });
1239
+ if (response.ok) {
1240
+ const { txid } = await response.json();
1241
+ if (typeof txid !== "string" || !txid)
1242
+ throw new Error("cosign response has no txid");
1243
+ return txid;
1244
+ }
1245
+ text = await response.text();
1246
+ } catch (e) {
1247
+ if (e instanceof DigestMismatchError) throw e;
1248
+ throw new OnchainCosignAmbiguousError(e instanceof Error ? e.message : String(e), {
1249
+ cause: e
1250
+ });
1251
+ }
1252
+ const arkError = maybeArkError(new Error(text));
1253
+ if (!arkError && (response.status === 404 || response.status === 501)) {
1254
+ this._onchainCosignUnsupported = true;
1255
+ throw new OnchainCosignUnsupportedError();
1256
+ }
1257
+ if (!arkError || arkError.name === ArkErrorName.INTERNAL_ERROR) {
1258
+ throw new OnchainCosignAmbiguousError(
1259
+ arkError?.message ?? `${response.status} ${text}`
1260
+ );
1261
+ }
1262
+ throw new OnchainCosignRejectedError(arkError.message, arkError.name);
1263
+ }
2090
1264
  async finalizeTx(arkTxid, finalCheckpointTxs) {
2091
1265
  const url = `${this.serverUrl}/v1/tx/finalize`;
2092
1266
  await this.postJson(
@@ -2663,18 +1837,12 @@ function isVirtualCoin(input) {
2663
1837
  }
2664
1838
 
2665
1839
  exports.ARKADE_VERSION_HEADERS = ARKADE_VERSION_HEADERS;
2666
- exports.ArkAddress = ArkAddress;
2667
1840
  exports.ArkError = ArkError;
2668
1841
  exports.ArkErrorName = ArkErrorName;
2669
1842
  exports.ArkPsbtFieldKey = ArkPsbtFieldKey;
2670
1843
  exports.ArkPsbtFieldKeyType = ArkPsbtFieldKeyType;
2671
- exports.BITCOIN_EMULATOR_PUBKEY = BITCOIN_EMULATOR_PUBKEY;
2672
1844
  exports.ConditionWitness = ConditionWitness;
2673
1845
  exports.CosignerPublicKey = CosignerPublicKey;
2674
- exports.DEFAULT_ARKADE_EMULATOR_URL = DEFAULT_ARKADE_EMULATOR_URL;
2675
- exports.DEFAULT_ARKADE_SERVER_URL = DEFAULT_ARKADE_SERVER_URL;
2676
- exports.DEFAULT_NETWORK = DEFAULT_NETWORK;
2677
- exports.DEFAULT_NETWORK_NAME = DEFAULT_NETWORK_NAME;
2678
1846
  exports.DEFAULT_PAGE_SIZE = DEFAULT_PAGE_SIZE;
2679
1847
  exports.DigestMismatchError = DigestMismatchError;
2680
1848
  exports.EXPIRY_MIN_PLAUSIBLE_MS = EXPIRY_MIN_PLAUSIBLE_MS;
@@ -2682,25 +1850,26 @@ exports.EventSourceUnavailableError = EventSourceUnavailableError;
2682
1850
  exports.FetchError = FetchError;
2683
1851
  exports.INFO_FETCH_TIMEOUT_MS = INFO_FETCH_TIMEOUT_MS;
2684
1852
  exports.Intent = Intent;
2685
- exports.MUTINYNET_EMULATOR_PUBKEY = MUTINYNET_EMULATOR_PUBKEY;
1853
+ exports.ONCHAIN_COSIGN_AMBIGUOUS_PREFIX = ONCHAIN_COSIGN_AMBIGUOUS_PREFIX;
1854
+ exports.ONCHAIN_COSIGN_REJECTED_PREFIX = ONCHAIN_COSIGN_REJECTED_PREFIX;
1855
+ exports.ONCHAIN_COSIGN_UNSUPPORTED_PREFIX = ONCHAIN_COSIGN_UNSUPPORTED_PREFIX;
2686
1856
  exports.OP_RETURN_EMPTY_PKSCRIPT = OP_RETURN_EMPTY_PKSCRIPT;
1857
+ exports.OUTPOINT_QUERY_CHUNK_SIZE = OUTPOINT_QUERY_CHUNK_SIZE;
1858
+ exports.OnchainCosignAmbiguousError = OnchainCosignAmbiguousError;
1859
+ exports.OnchainCosignRejectedError = OnchainCosignRejectedError;
1860
+ exports.OnchainCosignUnsupportedError = OnchainCosignUnsupportedError;
2687
1861
  exports.PrevArkTxField = PrevArkTxField;
2688
1862
  exports.PrevoutTxField = PrevoutTxField;
2689
1863
  exports.ProviderUnavailableError = ProviderUnavailableError;
2690
1864
  exports.READ_TIMEOUT_MS = READ_TIMEOUT_MS;
2691
- exports.REGTEST_EMULATOR_PUBKEY = REGTEST_EMULATOR_PUBKEY;
2692
1865
  exports.RestArkProvider = RestArkProvider;
2693
1866
  exports.RestOperatorProvider = RestOperatorProvider;
2694
1867
  exports.SCRIPT_QUERY_CHUNK_SIZE = SCRIPT_QUERY_CHUNK_SIZE;
2695
1868
  exports.ServerResponseMismatchError = ServerResponseMismatchError;
2696
1869
  exports.SettlementEventType = SettlementEventType;
2697
- exports.TapTreeCoder = TapTreeCoder;
2698
1870
  exports.Transaction = Transaction;
2699
- exports.VtxoScript = VtxoScript;
2700
1871
  exports.VtxoTaprootTree = VtxoTaprootTree;
2701
1872
  exports.VtxoTreeExpiry = VtxoTreeExpiry;
2702
- exports.__export = __export;
2703
- exports.assembleBtcdTaprootTree = assembleBtcdTaprootTree;
2704
1873
  exports.assertAllowedSighashTypes = assertAllowedSighashTypes;
2705
1874
  exports.assertNonNegativeMs = assertNonNegativeMs;
2706
1875
  exports.assertTimerMs = assertTimerMs;
@@ -2712,17 +1881,13 @@ exports.canSweepOnchain = canSweepOnchain;
2712
1881
  exports.configureEventSource = configureEventSource;
2713
1882
  exports.convertVtxo = convertVtxo;
2714
1883
  exports.craftToSpendTx = craftToSpendTx;
2715
- exports.decodeTapscript = decodeTapscript;
2716
- exports.defaultEmulatorPubkey = defaultEmulatorPubkey;
2717
1884
  exports.eventSourceIterator = eventSourceIterator;
2718
1885
  exports.fetchVtxoCreatedAtByTxid = fetchVtxoCreatedAtByTxid;
2719
1886
  exports.formatSighash = formatSighash;
2720
1887
  exports.getAllNormalizedVtxos = getAllNormalizedVtxos;
2721
1888
  exports.getArkPsbtFields = getArkPsbtFields;
2722
1889
  exports.getConfiguredEventSource = getConfiguredEventSource;
2723
- exports.getNetwork = getNetwork;
2724
1890
  exports.getNormalizedVtxos = getNormalizedVtxos;
2725
- exports.getSequence = getSequence;
2726
1891
  exports.isArkError = isArkError;
2727
1892
  exports.isEventSourceError = isEventSourceError;
2728
1893
  exports.isEventSourceUnavailableError = isEventSourceUnavailableError;
@@ -2732,26 +1897,17 @@ exports.isRetryableProviderError = isRetryableProviderError;
2732
1897
  exports.isVirtualCoin = isVirtualCoin;
2733
1898
  exports.isVtxoSpent = isVtxoSpent;
2734
1899
  exports.maybeArkError = maybeArkError;
2735
- exports.networkFromArkadeInfo = networkFromArkadeInfo;
2736
- exports.networkFromOperatorInfo = networkFromOperatorInfo;
2737
- exports.networks = networks;
2738
1900
  exports.normalizeVtxo = normalizeVtxo;
2739
1901
  exports.rateGate = rateGate;
2740
1902
  exports.readSseFrames = readSseFrames;
2741
1903
  exports.requiresForfeit = requiresForfeit;
2742
- exports.resolveEmulatorPubkey = resolveEmulatorPubkey;
2743
1904
  exports.resolveEventSource = resolveEventSource;
2744
1905
  exports.resolveTimeHeight = resolveTimeHeight;
2745
- exports.scriptFromTapLeafScript = scriptFromTapLeafScript;
2746
1906
  exports.sdkVersion = sdkVersion;
2747
- exports.sequenceToCanonicalTimelock = sequenceToCanonicalTimelock;
2748
- exports.sequenceToTimelock = sequenceToTimelock;
2749
1907
  exports.setArkPsbtField = setArkPsbtField;
2750
1908
  exports.streamFailureError = streamFailureError;
2751
1909
  exports.throwIfHttpUnavailable = throwIfHttpUnavailable;
2752
- exports.timelockToSequence = timelockToSequence;
2753
- exports.toBIP371TapTree = toBIP371TapTree;
2754
1910
  exports.toOffchainInputFeeParams = toOffchainInputFeeParams;
2755
1911
  exports.toProviderUnavailable = toProviderUnavailable;
2756
- //# sourceMappingURL=chunk-GHUUT54D.cjs.map
2757
- //# sourceMappingURL=chunk-GHUUT54D.cjs.map
1912
+ //# sourceMappingURL=chunk-KCL5AVML.cjs.map
1913
+ //# sourceMappingURL=chunk-KCL5AVML.cjs.map