@sats-connect/core 0.4.0-e7d3e8d → 0.4.0-e8e6a66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,1888 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ AddressPurpose: () => AddressPurpose,
34
+ AddressType: () => AddressType,
35
+ BaseAdapter: () => BaseAdapter,
36
+ BitcoinNetworkType: () => BitcoinNetworkType,
37
+ DefaultAdaptersInfo: () => DefaultAdaptersInfo,
38
+ MessageSigningProtocols: () => MessageSigningProtocols,
39
+ RpcErrorCode: () => RpcErrorCode,
40
+ RpcIdSchema: () => RpcIdSchema,
41
+ SatsConnectAdapter: () => SatsConnectAdapter,
42
+ TransferRunesResultSchema: () => TransferRunesResultSchema,
43
+ accountChangeEventName: () => accountChangeEventName,
44
+ accountChangeSchema: () => accountChangeSchema,
45
+ addListener: () => addListener,
46
+ addressSchema: () => addressSchema,
47
+ connectMethodName: () => connectMethodName,
48
+ connectParamsSchema: () => connectParamsSchema,
49
+ connectRequestMessageSchema: () => connectRequestMessageSchema,
50
+ connectResultSchema: () => connectResultSchema,
51
+ createInscription: () => createInscription,
52
+ createRepeatInscriptions: () => createRepeatInscriptions,
53
+ defaultAdapters: () => defaultAdapters,
54
+ disconnectEventName: () => disconnectEventName,
55
+ disconnectMethodName: () => disconnectMethodName,
56
+ disconnectParamsSchema: () => disconnectParamsSchema,
57
+ disconnectRequestMessageSchema: () => disconnectRequestMessageSchema,
58
+ disconnectResultSchema: () => disconnectResultSchema,
59
+ disconnectSchema: () => disconnectSchema,
60
+ getAccountMethodName: () => getAccountMethodName,
61
+ getAccountParamsSchema: () => getAccountParamsSchema,
62
+ getAccountRequestMessageSchema: () => getAccountRequestMessageSchema,
63
+ getAccountResultSchema: () => getAccountResultSchema,
64
+ getAccountsMethodName: () => getAccountsMethodName,
65
+ getAccountsParamsSchema: () => getAccountsParamsSchema,
66
+ getAccountsRequestMessageSchema: () => getAccountsRequestMessageSchema,
67
+ getAccountsResultSchema: () => getAccountsResultSchema,
68
+ getAddress: () => getAddress,
69
+ getAddressesMethodName: () => getAddressesMethodName,
70
+ getAddressesParamsSchema: () => getAddressesParamsSchema,
71
+ getAddressesRequestMessageSchema: () => getAddressesRequestMessageSchema,
72
+ getAddressesResultSchema: () => getAddressesResultSchema,
73
+ getBalanceMethodName: () => getBalanceMethodName,
74
+ getBalanceParamsSchema: () => getBalanceParamsSchema,
75
+ getBalanceRequestMessageSchema: () => getBalanceRequestMessageSchema,
76
+ getBalanceResultSchema: () => getBalanceResultSchema,
77
+ getCapabilities: () => getCapabilities,
78
+ getCurrentPermissionsMethodName: () => getCurrentPermissionsMethodName,
79
+ getCurrentPermissionsParamsSchema: () => getCurrentPermissionsParamsSchema,
80
+ getCurrentPermissionsRequestMessageSchema: () => getCurrentPermissionsRequestMessageSchema,
81
+ getCurrentPermissionsResultSchema: () => getCurrentPermissionsResultSchema,
82
+ getDefaultProvider: () => getDefaultProvider,
83
+ getInfoMethodName: () => getInfoMethodName,
84
+ getInfoParamsSchema: () => getInfoParamsSchema,
85
+ getInfoRequestMessageSchema: () => getInfoRequestMessageSchema,
86
+ getInfoResultSchema: () => getInfoResultSchema,
87
+ getInscriptionsMethodName: () => getInscriptionsMethodName,
88
+ getInscriptionsParamsSchema: () => getInscriptionsParamsSchema,
89
+ getInscriptionsResultSchema: () => getInscriptionsResultSchema,
90
+ getInscriptionsSchema: () => getInscriptionsSchema,
91
+ getProviderById: () => getProviderById,
92
+ getProviderOrThrow: () => getProviderOrThrow,
93
+ getProviders: () => getProviders,
94
+ getRunesBalanceMethodName: () => getRunesBalanceMethodName,
95
+ getRunesBalanceParamsSchema: () => getRunesBalanceParamsSchema,
96
+ getRunesBalanceRequestMessageSchema: () => getRunesBalanceRequestMessageSchema,
97
+ getRunesBalanceResultSchema: () => getRunesBalanceResultSchema,
98
+ getSupportedWallets: () => getSupportedWallets,
99
+ getWalletTypeMethodName: () => getWalletTypeMethodName,
100
+ getWalletTypeParamsSchema: () => getWalletTypeParamsSchema,
101
+ getWalletTypeRequestMessageSchema: () => getWalletTypeRequestMessageSchema,
102
+ getWalletTypeResultSchema: () => getWalletTypeResultSchema,
103
+ isProviderInstalled: () => isProviderInstalled,
104
+ networkChangeEventName: () => networkChangeEventName,
105
+ networkChangeSchema: () => networkChangeSchema,
106
+ permissionTemplate: () => permissionTemplate,
107
+ removeDefaultProvider: () => removeDefaultProvider,
108
+ renouncePermissionsMethodName: () => renouncePermissionsMethodName,
109
+ renouncePermissionsParamsSchema: () => renouncePermissionsParamsSchema,
110
+ renouncePermissionsRequestMessageSchema: () => renouncePermissionsRequestMessageSchema,
111
+ renouncePermissionsResultSchema: () => renouncePermissionsResultSchema,
112
+ request: () => request,
113
+ requestPermissionsMethodName: () => requestPermissionsMethodName,
114
+ requestPermissionsParamsSchema: () => requestPermissionsParamsSchema,
115
+ requestPermissionsRequestMessageSchema: () => requestPermissionsRequestMessageSchema,
116
+ requestPermissionsResultSchema: () => requestPermissionsResultSchema,
117
+ rpcErrorResponseMessageSchema: () => rpcErrorResponseMessageSchema,
118
+ rpcRequestMessageSchema: () => rpcRequestMessageSchema,
119
+ rpcResponseMessageSchema: () => rpcResponseMessageSchema,
120
+ rpcSuccessResponseMessageSchema: () => rpcSuccessResponseMessageSchema,
121
+ sendBtcTransaction: () => sendBtcTransaction,
122
+ sendInscriptionsMethodName: () => sendInscriptionsMethodName,
123
+ sendInscriptionsParamsSchema: () => sendInscriptionsParamsSchema,
124
+ sendInscriptionsResultSchema: () => sendInscriptionsResultSchema,
125
+ sendInscriptionsSchema: () => sendInscriptionsSchema,
126
+ sendTransferMethodName: () => sendTransferMethodName,
127
+ sendTransferParamsSchema: () => sendTransferParamsSchema,
128
+ sendTransferRequestMessageSchema: () => sendTransferRequestMessageSchema,
129
+ sendTransferResultSchema: () => sendTransferResultSchema,
130
+ setDefaultProvider: () => setDefaultProvider,
131
+ signMessage: () => signMessage,
132
+ signMessageMethodName: () => signMessageMethodName,
133
+ signMessageParamsSchema: () => signMessageParamsSchema,
134
+ signMessageRequestMessageSchema: () => signMessageRequestMessageSchema,
135
+ signMessageResultSchema: () => signMessageResultSchema,
136
+ signMultipleTransactions: () => signMultipleTransactions,
137
+ signPsbtMethodName: () => signPsbtMethodName,
138
+ signPsbtParamsSchema: () => signPsbtParamsSchema,
139
+ signPsbtRequestMessageSchema: () => signPsbtRequestMessageSchema,
140
+ signPsbtResultSchema: () => signPsbtResultSchema,
141
+ signTransaction: () => signTransaction,
142
+ stxGetAddressesMethodName: () => stxGetAddressesMethodName,
143
+ stxGetAddressesParamsSchema: () => stxGetAddressesParamsSchema,
144
+ stxGetAddressesRequestMessageSchema: () => stxGetAddressesRequestMessageSchema,
145
+ stxGetAddressesResultSchema: () => stxGetAddressesResultSchema,
146
+ stxSignTransactionMethodName: () => stxSignTransactionMethodName,
147
+ stxSignTransactionParamsSchema: () => stxSignTransactionParamsSchema,
148
+ stxSignTransactionRequestMessageSchema: () => stxSignTransactionRequestMessageSchema,
149
+ stxSignTransactionResultSchema: () => stxSignTransactionResultSchema,
150
+ transferRunesMethodName: () => transferRunesMethodName,
151
+ transferRunesParamsSchema: () => transferRunesParamsSchema,
152
+ transferRunesRequestSchema: () => transferRunesRequestSchema,
153
+ walletEventSchema: () => walletEventSchema,
154
+ walletTypeSchema: () => walletTypeSchema,
155
+ walletTypes: () => walletTypes
156
+ });
157
+ module.exports = __toCommonJS(src_exports);
158
+
159
+ // src/provider/types.ts
160
+ var v = __toESM(require("valibot"));
161
+ var accountChangeEventName = "accountChange";
162
+ var accountChangeSchema = v.object({
163
+ type: v.literal(accountChangeEventName)
164
+ });
165
+ var networkChangeEventName = "networkChange";
166
+ var networkChangeSchema = v.object({
167
+ type: v.literal(networkChangeEventName)
168
+ });
169
+ var disconnectEventName = "disconnect";
170
+ var disconnectSchema = v.object({
171
+ type: v.literal(disconnectEventName)
172
+ });
173
+ var walletEventSchema = v.variant("type", [
174
+ accountChangeSchema,
175
+ networkChangeSchema,
176
+ disconnectSchema
177
+ ]);
178
+
179
+ // src/provider/index.ts
180
+ async function getProviderOrThrow(getProvider) {
181
+ const provider = await getProvider?.() || window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
182
+ if (!provider) {
183
+ throw new Error("No Bitcoin wallet installed");
184
+ }
185
+ return provider;
186
+ }
187
+ function getProviders() {
188
+ if (!window.btc_providers)
189
+ window.btc_providers = [];
190
+ return window.btc_providers;
191
+ }
192
+ function getProviderById(providerId) {
193
+ return providerId?.split(".").reduce((acc, part) => acc?.[part], window);
194
+ }
195
+ function isProviderInstalled(providerId) {
196
+ return !!getProviderById(providerId);
197
+ }
198
+ function setDefaultProvider(providerId) {
199
+ localStorage.setItem("sats-connect_defaultProvider", providerId);
200
+ }
201
+ function getDefaultProvider() {
202
+ return localStorage.getItem("sats-connect_defaultProvider");
203
+ }
204
+ function removeDefaultProvider() {
205
+ localStorage.removeItem("sats-connect_defaultProvider");
206
+ }
207
+ function getSupportedWallets() {
208
+ const ambientProviders = getProviders();
209
+ const { xverse, ...defaultProviders } = DefaultAdaptersInfo;
210
+ const allProviders = [...ambientProviders, ...Object.values(defaultProviders)];
211
+ const wallets = allProviders.map((provider) => {
212
+ {
213
+ return {
214
+ ...provider,
215
+ isInstalled: isProviderInstalled(provider.id)
216
+ };
217
+ }
218
+ });
219
+ return wallets;
220
+ }
221
+
222
+ // src/types.ts
223
+ var v2 = __toESM(require("valibot"));
224
+ var BitcoinNetworkType = /* @__PURE__ */ ((BitcoinNetworkType3) => {
225
+ BitcoinNetworkType3["Mainnet"] = "Mainnet";
226
+ BitcoinNetworkType3["Testnet"] = "Testnet";
227
+ BitcoinNetworkType3["Signet"] = "Signet";
228
+ return BitcoinNetworkType3;
229
+ })(BitcoinNetworkType || {});
230
+ var RpcIdSchema = v2.optional(v2.union([v2.string(), v2.number(), v2.null()]));
231
+ var rpcRequestMessageSchema = v2.object({
232
+ jsonrpc: v2.literal("2.0"),
233
+ method: v2.string(),
234
+ params: v2.optional(
235
+ v2.union([
236
+ v2.array(v2.unknown()),
237
+ v2.looseObject({}),
238
+ // Note: This is to support current incorrect usage of RPC 2.0. Params need
239
+ // to be either an array or an object when provided. Changing this now would
240
+ // be a breaking change, so accepting null values for now. Tracking in
241
+ // https://linear.app/xverseapp/issue/ENG-4538.
242
+ v2.null()
243
+ ])
244
+ ),
245
+ id: RpcIdSchema
246
+ });
247
+ var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
248
+ RpcErrorCode2[RpcErrorCode2["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
249
+ RpcErrorCode2[RpcErrorCode2["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
250
+ RpcErrorCode2[RpcErrorCode2["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
251
+ RpcErrorCode2[RpcErrorCode2["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
252
+ RpcErrorCode2[RpcErrorCode2["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
253
+ RpcErrorCode2[RpcErrorCode2["USER_REJECTION"] = -32e3] = "USER_REJECTION";
254
+ RpcErrorCode2[RpcErrorCode2["METHOD_NOT_SUPPORTED"] = -32001] = "METHOD_NOT_SUPPORTED";
255
+ RpcErrorCode2[RpcErrorCode2["ACCESS_DENIED"] = -32002] = "ACCESS_DENIED";
256
+ return RpcErrorCode2;
257
+ })(RpcErrorCode || {});
258
+ var rpcSuccessResponseMessageSchema = v2.object({
259
+ jsonrpc: v2.literal("2.0"),
260
+ result: v2.nonOptional(v2.unknown()),
261
+ id: RpcIdSchema
262
+ });
263
+ var rpcErrorResponseMessageSchema = v2.object({
264
+ jsonrpc: v2.literal("2.0"),
265
+ error: v2.nonOptional(v2.unknown()),
266
+ id: RpcIdSchema
267
+ });
268
+ var rpcResponseMessageSchema = v2.union([
269
+ rpcSuccessResponseMessageSchema,
270
+ rpcErrorResponseMessageSchema
271
+ ]);
272
+
273
+ // src/request/index.ts
274
+ var v10 = __toESM(require("valibot"));
275
+
276
+ // src/request/types/stxMethods.ts
277
+ var v4 = __toESM(require("valibot"));
278
+
279
+ // src/addresses/index.ts
280
+ var import_jsontokens = require("jsontokens");
281
+
282
+ // src/addresses/types.ts
283
+ var v3 = __toESM(require("valibot"));
284
+ var AddressPurpose = /* @__PURE__ */ ((AddressPurpose2) => {
285
+ AddressPurpose2["Ordinals"] = "ordinals";
286
+ AddressPurpose2["Payment"] = "payment";
287
+ AddressPurpose2["Stacks"] = "stacks";
288
+ return AddressPurpose2;
289
+ })(AddressPurpose || {});
290
+ var AddressType = /* @__PURE__ */ ((AddressType3) => {
291
+ AddressType3["p2pkh"] = "p2pkh";
292
+ AddressType3["p2sh"] = "p2sh";
293
+ AddressType3["p2wpkh"] = "p2wpkh";
294
+ AddressType3["p2wsh"] = "p2wsh";
295
+ AddressType3["p2tr"] = "p2tr";
296
+ AddressType3["stacks"] = "stacks";
297
+ return AddressType3;
298
+ })(AddressType || {});
299
+ var addressSchema = v3.object({
300
+ address: v3.string(),
301
+ publicKey: v3.string(),
302
+ purpose: v3.enum(AddressPurpose),
303
+ addressType: v3.enum(AddressType)
304
+ });
305
+
306
+ // src/addresses/index.ts
307
+ var getAddress = async (options) => {
308
+ const provider = await getProviderOrThrow(options.getProvider);
309
+ const { purposes } = options.payload;
310
+ if (!purposes) {
311
+ throw new Error("Address purposes are required");
312
+ }
313
+ try {
314
+ const request2 = (0, import_jsontokens.createUnsecuredToken)(options.payload);
315
+ const response = await provider.connect(request2);
316
+ options.onFinish?.(response);
317
+ } catch (error) {
318
+ console.error("[Connect] Error during address request", error);
319
+ options.onCancel?.();
320
+ }
321
+ };
322
+
323
+ // src/request/types/stxMethods.ts
324
+ var stxGetAddressesMethodName = "stx_getAddresses";
325
+ var stxGetAddressesParamsSchema = v4.nullish(
326
+ v4.object({
327
+ /**
328
+ * A message to be displayed to the user in the request prompt.
329
+ */
330
+ message: v4.optional(v4.string())
331
+ })
332
+ );
333
+ var stxGetAddressesResultSchema = v4.object({
334
+ /**
335
+ * The addresses generated for the given purposes.
336
+ */
337
+ addresses: v4.array(addressSchema)
338
+ });
339
+ var stxGetAddressesRequestMessageSchema = v4.object({
340
+ ...rpcRequestMessageSchema.entries,
341
+ ...v4.object({
342
+ method: v4.literal(stxGetAddressesMethodName),
343
+ params: stxGetAddressesParamsSchema,
344
+ id: v4.string()
345
+ }).entries
346
+ });
347
+ var stxSignTransactionMethodName = "stx_signTransaction";
348
+ var stxSignTransactionParamsSchema = v4.object({
349
+ /**
350
+ * The transaction to sign as a hex-encoded string.
351
+ */
352
+ transaction: v4.string(),
353
+ /**
354
+ * The public key to sign the transaction with. The wallet may use any key
355
+ * when not provided.
356
+ */
357
+ pubkey: v4.optional(v4.string()),
358
+ /**
359
+ * Whether to broadcast the transaction after signing. Defaults to `true`.
360
+ */
361
+ broadcast: v4.optional(v4.boolean())
362
+ });
363
+ var stxSignTransactionResultSchema = v4.object({
364
+ /**
365
+ * The signed transaction as a hex-encoded string.
366
+ */
367
+ transaction: v4.string()
368
+ });
369
+ var stxSignTransactionRequestMessageSchema = v4.object({
370
+ ...rpcRequestMessageSchema.entries,
371
+ ...v4.object({
372
+ method: v4.literal(stxSignTransactionMethodName),
373
+ params: stxSignTransactionParamsSchema,
374
+ id: v4.string()
375
+ }).entries
376
+ });
377
+
378
+ // src/request/types/btcMethods.ts
379
+ var v6 = __toESM(require("valibot"));
380
+
381
+ // src/request/types/common.ts
382
+ var v5 = __toESM(require("valibot"));
383
+ var walletTypes = ["software", "ledger"];
384
+ var walletTypeSchema = v5.picklist(walletTypes);
385
+
386
+ // src/request/types/btcMethods.ts
387
+ var getInfoMethodName = "getInfo";
388
+ var getInfoParamsSchema = v6.nullish(v6.null());
389
+ var getInfoResultSchema = v6.object({
390
+ /**
391
+ * Version of the wallet.
392
+ */
393
+ version: v6.string(),
394
+ /**
395
+ * [WBIP](https://wbips.netlify.app/wbips/WBIP002) methods supported by the wallet.
396
+ */
397
+ methods: v6.optional(v6.array(v6.string())),
398
+ /**
399
+ * List of WBIP standards supported by the wallet. Not currently used.
400
+ */
401
+ supports: v6.array(v6.string())
402
+ });
403
+ var getInfoRequestMessageSchema = v6.object({
404
+ ...rpcRequestMessageSchema.entries,
405
+ ...v6.object({
406
+ method: v6.literal(getInfoMethodName),
407
+ params: getInfoParamsSchema,
408
+ id: v6.string()
409
+ }).entries
410
+ });
411
+ var getAddressesMethodName = "getAddresses";
412
+ var getAddressesParamsSchema = v6.object({
413
+ /**
414
+ * The purposes for which to generate addresses. See
415
+ * {@linkcode AddressPurpose} for available purposes.
416
+ */
417
+ purposes: v6.array(v6.enum(AddressPurpose)),
418
+ /**
419
+ * A message to be displayed to the user in the request prompt.
420
+ */
421
+ message: v6.optional(v6.string())
422
+ });
423
+ var getAddressesResultSchema = v6.object({
424
+ /**
425
+ * The addresses generated for the given purposes.
426
+ */
427
+ addresses: v6.array(addressSchema)
428
+ });
429
+ var getAddressesRequestMessageSchema = v6.object({
430
+ ...rpcRequestMessageSchema.entries,
431
+ ...v6.object({
432
+ method: v6.literal(getAddressesMethodName),
433
+ params: getAddressesParamsSchema,
434
+ id: v6.string()
435
+ }).entries
436
+ });
437
+ var signMessageMethodName = "signMessage";
438
+ var MessageSigningProtocols = /* @__PURE__ */ ((MessageSigningProtocols2) => {
439
+ MessageSigningProtocols2["ECDSA"] = "ECDSA";
440
+ MessageSigningProtocols2["BIP322"] = "BIP322";
441
+ return MessageSigningProtocols2;
442
+ })(MessageSigningProtocols || {});
443
+ var signMessageParamsSchema = v6.object({
444
+ /**
445
+ * The address used for signing.
446
+ **/
447
+ address: v6.string(),
448
+ /**
449
+ * The message to sign.
450
+ **/
451
+ message: v6.string(),
452
+ /**
453
+ * The protocol to use for signing the message.
454
+ */
455
+ protocol: v6.optional(v6.enum(MessageSigningProtocols))
456
+ });
457
+ var signMessageResultSchema = v6.object({
458
+ /**
459
+ * The signature of the message.
460
+ */
461
+ signature: v6.string(),
462
+ /**
463
+ * hash of the message.
464
+ */
465
+ messageHash: v6.string(),
466
+ /**
467
+ * The address used for signing.
468
+ */
469
+ address: v6.string(),
470
+ /**
471
+ * The protocol to use for signing the message.
472
+ */
473
+ protocol: v6.enum(MessageSigningProtocols)
474
+ });
475
+ var signMessageRequestMessageSchema = v6.object({
476
+ ...rpcRequestMessageSchema.entries,
477
+ ...v6.object({
478
+ method: v6.literal(signMessageMethodName),
479
+ params: signMessageParamsSchema,
480
+ id: v6.string()
481
+ }).entries
482
+ });
483
+ var sendTransferMethodName = "sendTransfer";
484
+ var sendTransferParamsSchema = v6.object({
485
+ /**
486
+ * Array of recipients to send to.
487
+ * The amount to send to each recipient is in satoshis.
488
+ */
489
+ recipients: v6.array(
490
+ v6.object({
491
+ address: v6.string(),
492
+ amount: v6.number()
493
+ })
494
+ )
495
+ });
496
+ var sendTransferResultSchema = v6.object({
497
+ /**
498
+ * The transaction id as a hex-encoded string.
499
+ */
500
+ txid: v6.string()
501
+ });
502
+ var sendTransferRequestMessageSchema = v6.object({
503
+ ...rpcRequestMessageSchema.entries,
504
+ ...v6.object({
505
+ method: v6.literal(sendTransferMethodName),
506
+ params: sendTransferParamsSchema,
507
+ id: v6.string()
508
+ }).entries
509
+ });
510
+ var signPsbtMethodName = "signPsbt";
511
+ var signPsbtParamsSchema = v6.object({
512
+ /**
513
+ * The base64 encoded PSBT to sign.
514
+ */
515
+ psbt: v6.string(),
516
+ /**
517
+ * The inputs to sign.
518
+ * The key is the address and the value is an array of indexes of the inputs to sign.
519
+ */
520
+ signInputs: v6.record(v6.string(), v6.array(v6.number())),
521
+ /**
522
+ * Whether to broadcast the transaction after signing.
523
+ **/
524
+ broadcast: v6.optional(v6.boolean())
525
+ });
526
+ var signPsbtResultSchema = v6.object({
527
+ /**
528
+ * The base64 encoded PSBT after signing.
529
+ */
530
+ psbt: v6.string(),
531
+ /**
532
+ * The transaction id as a hex-encoded string.
533
+ * This is only returned if the transaction was broadcast.
534
+ **/
535
+ txid: v6.optional(v6.string())
536
+ });
537
+ var signPsbtRequestMessageSchema = v6.object({
538
+ ...rpcRequestMessageSchema.entries,
539
+ ...v6.object({
540
+ method: v6.literal(signPsbtMethodName),
541
+ params: signPsbtParamsSchema,
542
+ id: v6.string()
543
+ }).entries
544
+ });
545
+ var getAccountsMethodName = "getAccounts";
546
+ var getAccountsParamsSchema = v6.object({
547
+ /**
548
+ * The purposes for which to generate addresses. See
549
+ * {@linkcode AddressPurpose} for available purposes.
550
+ */
551
+ purposes: v6.array(v6.enum(AddressPurpose)),
552
+ /**
553
+ * A message to be displayed to the user in the request prompt.
554
+ */
555
+ message: v6.optional(v6.string())
556
+ });
557
+ var getAccountsResultSchema = v6.array(
558
+ v6.object({
559
+ ...addressSchema.entries,
560
+ ...v6.object({
561
+ walletType: walletTypeSchema
562
+ }).entries
563
+ })
564
+ );
565
+ var getAccountsRequestMessageSchema = v6.object({
566
+ ...rpcRequestMessageSchema.entries,
567
+ ...v6.object({
568
+ method: v6.literal(getAccountsMethodName),
569
+ params: getAccountsParamsSchema,
570
+ id: v6.string()
571
+ }).entries
572
+ });
573
+ var getBalanceMethodName = "getBalance";
574
+ var getBalanceParamsSchema = v6.nullish(v6.null());
575
+ var getBalanceResultSchema = v6.object({
576
+ /**
577
+ * The confirmed balance of the wallet in sats. Using a string due to chrome
578
+ * messages not supporting bigint
579
+ * (https://issues.chromium.org/issues/40116184).
580
+ */
581
+ confirmed: v6.string(),
582
+ /**
583
+ * The unconfirmed balance of the wallet in sats. Using a string due to chrome
584
+ * messages not supporting bigint
585
+ * (https://issues.chromium.org/issues/40116184).
586
+ */
587
+ unconfirmed: v6.string(),
588
+ /**
589
+ * The total balance (both confirmed and unconfrimed UTXOs) of the wallet in
590
+ * sats. Using a string due to chrome messages not supporting bigint
591
+ * (https://issues.chromium.org/issues/40116184).
592
+ */
593
+ total: v6.string()
594
+ });
595
+ var getBalanceRequestMessageSchema = v6.object({
596
+ ...rpcRequestMessageSchema.entries,
597
+ ...v6.object({
598
+ method: v6.literal(getBalanceMethodName),
599
+ id: v6.string()
600
+ }).entries
601
+ });
602
+
603
+ // src/request/types/walletMethods.ts
604
+ var v7 = __toESM(require("valibot"));
605
+ var import_xverse_core = require("@secretkeylabs/xverse-core");
606
+ var permissionTemplate = v7.variant("type", [
607
+ v7.object({
608
+ ...v7.omit(import_xverse_core.permissions.resources.account.accountPermissionSchema, ["clientId", "actions"]).entries,
609
+ actions: v7.partial(import_xverse_core.permissions.resources.account.accountActionsSchema)
610
+ }),
611
+ v7.object({
612
+ ...v7.omit(import_xverse_core.permissions.resources.wallet.walletPermissionSchema, ["clientId"]).entries,
613
+ actions: v7.partial(import_xverse_core.permissions.resources.wallet.walletActionsSchema)
614
+ })
615
+ ]);
616
+ var requestPermissionsMethodName = "wallet_requestPermissions";
617
+ var requestPermissionsParamsSchema = v7.nullish(v7.array(permissionTemplate));
618
+ var requestPermissionsResultSchema = v7.literal(true);
619
+ var requestPermissionsRequestMessageSchema = v7.object({
620
+ ...rpcRequestMessageSchema.entries,
621
+ ...v7.object({
622
+ method: v7.literal(requestPermissionsMethodName),
623
+ params: requestPermissionsParamsSchema,
624
+ id: v7.string()
625
+ }).entries
626
+ });
627
+ var renouncePermissionsMethodName = "wallet_renouncePermissions";
628
+ var renouncePermissionsParamsSchema = v7.nullish(v7.null());
629
+ var renouncePermissionsResultSchema = v7.nullish(v7.null());
630
+ var renouncePermissionsRequestMessageSchema = v7.object({
631
+ ...rpcRequestMessageSchema.entries,
632
+ ...v7.object({
633
+ method: v7.literal(renouncePermissionsMethodName),
634
+ params: renouncePermissionsParamsSchema,
635
+ id: v7.string()
636
+ }).entries
637
+ });
638
+ var disconnectMethodName = "wallet_disconnect";
639
+ var disconnectParamsSchema = v7.nullish(v7.null());
640
+ var disconnectResultSchema = v7.nullish(v7.null());
641
+ var disconnectRequestMessageSchema = v7.object({
642
+ ...rpcRequestMessageSchema.entries,
643
+ ...v7.object({
644
+ method: v7.literal(disconnectMethodName),
645
+ params: disconnectParamsSchema,
646
+ id: v7.string()
647
+ }).entries
648
+ });
649
+ var getWalletTypeMethodName = "wallet_getWalletType";
650
+ var getWalletTypeParamsSchema = v7.nullish(v7.null());
651
+ var getWalletTypeResultSchema = walletTypeSchema;
652
+ var getWalletTypeRequestMessageSchema = v7.object({
653
+ ...rpcRequestMessageSchema.entries,
654
+ ...v7.object({
655
+ method: v7.literal(getWalletTypeMethodName),
656
+ params: getWalletTypeParamsSchema,
657
+ id: v7.string()
658
+ }).entries
659
+ });
660
+ var getCurrentPermissionsMethodName = "wallet_getCurrentPermissions";
661
+ var getCurrentPermissionsParamsSchema = v7.nullish(v7.null());
662
+ var getCurrentPermissionsResultSchema = v7.array(import_xverse_core.permissions.store.permission);
663
+ var getCurrentPermissionsRequestMessageSchema = v7.object({
664
+ ...rpcRequestMessageSchema.entries,
665
+ ...v7.object({
666
+ method: v7.literal(getCurrentPermissionsMethodName),
667
+ params: getCurrentPermissionsParamsSchema,
668
+ id: v7.string()
669
+ }).entries
670
+ });
671
+ var getAccountMethodName = "wallet_getAccount";
672
+ var getAccountParamsSchema = v7.nullish(v7.null());
673
+ var getAccountResultSchema = v7.object({
674
+ id: import_xverse_core.permissions.utils.account.accountIdSchema,
675
+ addresses: v7.array(addressSchema),
676
+ walletType: walletTypeSchema
677
+ });
678
+ var getAccountRequestMessageSchema = v7.object({
679
+ ...rpcRequestMessageSchema.entries,
680
+ ...v7.object({
681
+ method: v7.literal(getAccountMethodName),
682
+ params: getAccountParamsSchema,
683
+ id: v7.string()
684
+ }).entries
685
+ });
686
+ var connectMethodName = "wallet_connect";
687
+ var connectParamsSchema = v7.nullish(
688
+ v7.object({
689
+ permissions: v7.optional(v7.array(permissionTemplate))
690
+ })
691
+ );
692
+ var connectResultSchema = getAccountResultSchema;
693
+ var connectRequestMessageSchema = v7.object({
694
+ ...rpcRequestMessageSchema.entries,
695
+ ...v7.object({
696
+ method: v7.literal(connectMethodName),
697
+ params: connectParamsSchema,
698
+ id: v7.string()
699
+ }).entries
700
+ });
701
+
702
+ // src/request/types/runesMethods.ts
703
+ var v8 = __toESM(require("valibot"));
704
+ var getRunesBalanceMethodName = "runes_getBalance";
705
+ var getRunesBalanceParamsSchema = v8.nullish(v8.null());
706
+ var getRunesBalanceResultSchema = v8.object({
707
+ balances: v8.array(
708
+ v8.object({
709
+ runeName: v8.string(),
710
+ amount: v8.string(),
711
+ divisibility: v8.number(),
712
+ symbol: v8.string(),
713
+ inscriptionId: v8.nullish(v8.string())
714
+ })
715
+ )
716
+ });
717
+ var getRunesBalanceRequestMessageSchema = v8.object({
718
+ ...rpcRequestMessageSchema.entries,
719
+ ...v8.object({
720
+ method: v8.literal(getRunesBalanceMethodName),
721
+ params: getRunesBalanceParamsSchema,
722
+ id: v8.string()
723
+ }).entries
724
+ });
725
+ var transferRunesMethodName = "runes_transfer";
726
+ var transferRunesParamsSchema = v8.object({
727
+ recipients: v8.array(
728
+ v8.object({
729
+ runeName: v8.string(),
730
+ amount: v8.string(),
731
+ address: v8.string()
732
+ })
733
+ )
734
+ });
735
+ var transferRunesRequestSchema = v8.object({
736
+ ...rpcRequestMessageSchema.entries,
737
+ ...v8.object({
738
+ method: v8.literal(transferRunesMethodName),
739
+ params: transferRunesParamsSchema,
740
+ id: v8.string()
741
+ }).entries
742
+ });
743
+ var TransferRunesResultSchema = v8.object({
744
+ txid: v8.string()
745
+ });
746
+
747
+ // src/request/types/ordinalsMethods.ts
748
+ var v9 = __toESM(require("valibot"));
749
+ var getInscriptionsMethodName = "ord_getInscriptions";
750
+ var getInscriptionsParamsSchema = v9.object({
751
+ offset: v9.number(),
752
+ limit: v9.number()
753
+ });
754
+ var getInscriptionsResultSchema = v9.object({
755
+ total: v9.number(),
756
+ limit: v9.number(),
757
+ offset: v9.number(),
758
+ inscriptions: v9.array(
759
+ v9.object({
760
+ inscriptionId: v9.string(),
761
+ inscriptionNumber: v9.string(),
762
+ address: v9.string(),
763
+ collectionName: v9.optional(v9.string()),
764
+ postage: v9.string(),
765
+ contentLength: v9.string(),
766
+ contentType: v9.string(),
767
+ timestamp: v9.number(),
768
+ offset: v9.number(),
769
+ genesisTransaction: v9.string(),
770
+ output: v9.string()
771
+ })
772
+ )
773
+ });
774
+ var getInscriptionsSchema = v9.object({
775
+ ...rpcRequestMessageSchema.entries,
776
+ ...v9.object({
777
+ method: v9.literal(getInscriptionsMethodName),
778
+ params: getInscriptionsParamsSchema,
779
+ id: v9.string()
780
+ }).entries
781
+ });
782
+ var sendInscriptionsMethodName = "ord_sendInscriptions";
783
+ var sendInscriptionsParamsSchema = v9.object({
784
+ transfers: v9.array(
785
+ v9.object({
786
+ address: v9.string(),
787
+ inscriptionId: v9.string()
788
+ })
789
+ )
790
+ });
791
+ var sendInscriptionsResultSchema = v9.object({
792
+ txid: v9.string()
793
+ });
794
+ var sendInscriptionsSchema = v9.object({
795
+ ...rpcRequestMessageSchema.entries,
796
+ ...v9.object({
797
+ method: v9.literal(sendInscriptionsMethodName),
798
+ params: sendInscriptionsParamsSchema,
799
+ id: v9.string()
800
+ }).entries
801
+ });
802
+
803
+ // src/request/index.ts
804
+ var request = async (method, params, providerId) => {
805
+ let provider = window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
806
+ if (providerId) {
807
+ provider = await getProviderById(providerId);
808
+ }
809
+ if (!provider) {
810
+ throw new Error("no wallet provider was found");
811
+ }
812
+ if (!method) {
813
+ throw new Error("A wallet method is required");
814
+ }
815
+ const response = await provider.request(method, params);
816
+ if (v10.is(rpcErrorResponseMessageSchema, response)) {
817
+ return {
818
+ status: "error",
819
+ error: response.error
820
+ };
821
+ }
822
+ if (v10.is(rpcSuccessResponseMessageSchema, response)) {
823
+ return {
824
+ status: "success",
825
+ result: response.result
826
+ };
827
+ }
828
+ return {
829
+ status: "error",
830
+ error: {
831
+ code: -32603 /* INTERNAL_ERROR */,
832
+ message: "Received unknown response from provider.",
833
+ data: response
834
+ }
835
+ };
836
+ };
837
+ var addListener = (event, cb, providerId) => {
838
+ let provider = window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
839
+ if (providerId) {
840
+ provider = getProviderById(providerId);
841
+ }
842
+ if (!provider) {
843
+ throw new Error("no wallet provider was found");
844
+ }
845
+ if (!provider.addListener) {
846
+ console.error(
847
+ `The wallet provider you are using does not support the addListener method. Please update your wallet provider.`
848
+ );
849
+ return () => {
850
+ };
851
+ }
852
+ return provider.addListener(event, cb);
853
+ };
854
+
855
+ // src/runes/api.ts
856
+ var import_axios = __toESM(require("axios"));
857
+ var urlNetworkSuffix = {
858
+ ["Mainnet" /* Mainnet */]: "",
859
+ ["Testnet" /* Testnet */]: "-testnet",
860
+ ["Signet" /* Signet */]: "-signet"
861
+ };
862
+ var ORDINALS_API_BASE_URL = (network = "Mainnet" /* Mainnet */) => `https://ordinals${urlNetworkSuffix[network]}.xverse.app/v1`;
863
+ var RunesApi = class {
864
+ client;
865
+ constructor(network) {
866
+ this.client = import_axios.default.create({
867
+ baseURL: ORDINALS_API_BASE_URL(network)
868
+ });
869
+ }
870
+ parseError = (error) => {
871
+ return {
872
+ code: error.response?.status,
873
+ message: JSON.stringify(error.response?.data)
874
+ };
875
+ };
876
+ estimateMintCost = async (mintParams) => {
877
+ try {
878
+ const response = await this.client.post("/runes/mint/estimate", {
879
+ ...mintParams
880
+ });
881
+ return {
882
+ data: response.data
883
+ };
884
+ } catch (error) {
885
+ const err = error;
886
+ return {
887
+ error: this.parseError(err)
888
+ };
889
+ }
890
+ };
891
+ estimateEtchCost = async (etchParams) => {
892
+ try {
893
+ const response = await this.client.post("/runes/etch/estimate", {
894
+ ...etchParams
895
+ });
896
+ return {
897
+ data: response.data
898
+ };
899
+ } catch (error) {
900
+ const err = error;
901
+ return {
902
+ error: this.parseError(err)
903
+ };
904
+ }
905
+ };
906
+ createMintOrder = async (mintOrderParams) => {
907
+ try {
908
+ const response = await this.client.post("/runes/mint/orders", {
909
+ ...mintOrderParams
910
+ });
911
+ return {
912
+ data: response.data
913
+ };
914
+ } catch (error) {
915
+ const err = error;
916
+ return {
917
+ error: this.parseError(err)
918
+ };
919
+ }
920
+ };
921
+ createEtchOrder = async (etchOrderParams) => {
922
+ try {
923
+ const response = await this.client.post("/runes/etch/orders", {
924
+ ...etchOrderParams
925
+ });
926
+ return {
927
+ data: response.data
928
+ };
929
+ } catch (error) {
930
+ const err = error;
931
+ return {
932
+ error: this.parseError(err)
933
+ };
934
+ }
935
+ };
936
+ executeMint = async (orderId, fundTransactionId) => {
937
+ try {
938
+ const response = await this.client.post(`/runes/mint/orders/${orderId}/execute`, {
939
+ fundTransactionId
940
+ });
941
+ return {
942
+ data: response.data
943
+ };
944
+ } catch (error) {
945
+ const err = error;
946
+ return {
947
+ error: this.parseError(err)
948
+ };
949
+ }
950
+ };
951
+ executeEtch = async (orderId, fundTransactionId) => {
952
+ try {
953
+ const response = await this.client.post(`/runes/etch/orders/${orderId}/execute`, {
954
+ fundTransactionId
955
+ });
956
+ return {
957
+ data: response.data
958
+ };
959
+ } catch (error) {
960
+ const err = error;
961
+ return {
962
+ error: this.parseError(err)
963
+ };
964
+ }
965
+ };
966
+ getOrder = async (orderId) => {
967
+ try {
968
+ const response = await this.client.get(`/orders/${orderId}`);
969
+ return {
970
+ data: response.data
971
+ };
972
+ } catch (error) {
973
+ const err = error;
974
+ return {
975
+ error: this.parseError(err)
976
+ };
977
+ }
978
+ };
979
+ rbfOrder = async (rbfRequest) => {
980
+ const { orderId, newFeeRate } = rbfRequest;
981
+ try {
982
+ const response = await this.client.post(`/orders/${orderId}/rbf-estimate`, {
983
+ newFeeRate
984
+ });
985
+ return {
986
+ data: response.data
987
+ };
988
+ } catch (error) {
989
+ const err = error;
990
+ return {
991
+ error: this.parseError(err)
992
+ };
993
+ }
994
+ };
995
+ };
996
+ var clients = {};
997
+ var getRunesApiClient = (network = "Mainnet" /* Mainnet */) => {
998
+ if (!clients[network]) {
999
+ clients[network] = new RunesApi(network);
1000
+ }
1001
+ return clients[network];
1002
+ };
1003
+
1004
+ // src/adapters/satsConnectAdapter.ts
1005
+ var SatsConnectAdapter = class {
1006
+ async mintRunes(params) {
1007
+ try {
1008
+ const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
1009
+ if (walletInfo && walletInfo.status === "success") {
1010
+ const isMintSupported = walletInfo.result.methods?.includes("runes_mint");
1011
+ if (isMintSupported) {
1012
+ const response = await this.requestInternal("runes_mint", params);
1013
+ if (response) {
1014
+ if (response.status === "success") {
1015
+ return response;
1016
+ }
1017
+ if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
1018
+ return response;
1019
+ }
1020
+ }
1021
+ }
1022
+ }
1023
+ const mintRequest = {
1024
+ destinationAddress: params.destinationAddress,
1025
+ feeRate: params.feeRate,
1026
+ refundAddress: params.refundAddress,
1027
+ repeats: params.repeats,
1028
+ runeName: params.runeName,
1029
+ appServiceFee: params.appServiceFee,
1030
+ appServiceFeeAddress: params.appServiceFeeAddress
1031
+ };
1032
+ const orderResponse = await new RunesApi(params.network).createMintOrder(mintRequest);
1033
+ if (!orderResponse.data) {
1034
+ return {
1035
+ status: "error",
1036
+ error: {
1037
+ code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
1038
+ message: orderResponse.error.message
1039
+ }
1040
+ };
1041
+ }
1042
+ const paymentResponse = await this.requestInternal("sendTransfer", {
1043
+ recipients: [
1044
+ {
1045
+ address: orderResponse.data.fundAddress,
1046
+ amount: orderResponse.data.fundAmount
1047
+ }
1048
+ ]
1049
+ });
1050
+ if (paymentResponse.status !== "success") {
1051
+ return paymentResponse;
1052
+ }
1053
+ await new RunesApi(params.network).executeMint(
1054
+ orderResponse.data.orderId,
1055
+ paymentResponse.result.txid
1056
+ );
1057
+ return {
1058
+ status: "success",
1059
+ result: {
1060
+ orderId: orderResponse.data.orderId,
1061
+ fundTransactionId: paymentResponse.result.txid,
1062
+ fundingAddress: orderResponse.data.fundAddress
1063
+ }
1064
+ };
1065
+ } catch (error) {
1066
+ return {
1067
+ status: "error",
1068
+ error: {
1069
+ code: -32603 /* INTERNAL_ERROR */,
1070
+ message: error.message
1071
+ }
1072
+ };
1073
+ }
1074
+ }
1075
+ async etchRunes(params) {
1076
+ const etchRequest = {
1077
+ destinationAddress: params.destinationAddress,
1078
+ refundAddress: params.refundAddress,
1079
+ feeRate: params.feeRate,
1080
+ runeName: params.runeName,
1081
+ divisibility: params.divisibility,
1082
+ symbol: params.symbol,
1083
+ premine: params.premine,
1084
+ isMintable: params.isMintable,
1085
+ terms: params.terms,
1086
+ inscriptionDetails: params.inscriptionDetails,
1087
+ delegateInscriptionId: params.delegateInscriptionId,
1088
+ appServiceFee: params.appServiceFee,
1089
+ appServiceFeeAddress: params.appServiceFeeAddress
1090
+ };
1091
+ try {
1092
+ const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
1093
+ if (walletInfo && walletInfo.status === "success") {
1094
+ const isEtchSupported = walletInfo.result.methods?.includes("runes_etch");
1095
+ if (isEtchSupported) {
1096
+ const response = await this.requestInternal("runes_etch", params);
1097
+ if (response) {
1098
+ if (response.status === "success") {
1099
+ return response;
1100
+ }
1101
+ if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
1102
+ return response;
1103
+ }
1104
+ }
1105
+ }
1106
+ }
1107
+ const orderResponse = await new RunesApi(params.network).createEtchOrder(etchRequest);
1108
+ if (!orderResponse.data) {
1109
+ return {
1110
+ status: "error",
1111
+ error: {
1112
+ code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
1113
+ message: orderResponse.error.message
1114
+ }
1115
+ };
1116
+ }
1117
+ const paymentResponse = await this.requestInternal("sendTransfer", {
1118
+ recipients: [
1119
+ {
1120
+ address: orderResponse.data.fundAddress,
1121
+ amount: orderResponse.data.fundAmount
1122
+ }
1123
+ ]
1124
+ });
1125
+ if (paymentResponse.status !== "success") {
1126
+ return paymentResponse;
1127
+ }
1128
+ await new RunesApi(params.network).executeEtch(
1129
+ orderResponse.data.orderId,
1130
+ paymentResponse.result.txid
1131
+ );
1132
+ return {
1133
+ status: "success",
1134
+ result: {
1135
+ orderId: orderResponse.data.orderId,
1136
+ fundTransactionId: paymentResponse.result.txid,
1137
+ fundingAddress: orderResponse.data.fundAddress
1138
+ }
1139
+ };
1140
+ } catch (error) {
1141
+ return {
1142
+ status: "error",
1143
+ error: {
1144
+ code: -32603 /* INTERNAL_ERROR */,
1145
+ message: error.message
1146
+ }
1147
+ };
1148
+ }
1149
+ }
1150
+ async estimateMint(params) {
1151
+ const estimateMintRequest = {
1152
+ destinationAddress: params.destinationAddress,
1153
+ feeRate: params.feeRate,
1154
+ repeats: params.repeats,
1155
+ runeName: params.runeName,
1156
+ appServiceFee: params.appServiceFee,
1157
+ appServiceFeeAddress: params.appServiceFeeAddress
1158
+ };
1159
+ const response = await getRunesApiClient(
1160
+ params.network
1161
+ ).estimateMintCost(estimateMintRequest);
1162
+ if (response.data) {
1163
+ return {
1164
+ status: "success",
1165
+ result: response.data
1166
+ };
1167
+ }
1168
+ return {
1169
+ status: "error",
1170
+ error: {
1171
+ code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
1172
+ message: response.error.message
1173
+ }
1174
+ };
1175
+ }
1176
+ async estimateEtch(params) {
1177
+ const estimateEtchRequest = {
1178
+ destinationAddress: params.destinationAddress,
1179
+ feeRate: params.feeRate,
1180
+ runeName: params.runeName,
1181
+ divisibility: params.divisibility,
1182
+ symbol: params.symbol,
1183
+ premine: params.premine,
1184
+ isMintable: params.isMintable,
1185
+ terms: params.terms,
1186
+ inscriptionDetails: params.inscriptionDetails,
1187
+ delegateInscriptionId: params.delegateInscriptionId,
1188
+ appServiceFee: params.appServiceFee,
1189
+ appServiceFeeAddress: params.appServiceFeeAddress
1190
+ };
1191
+ const response = await getRunesApiClient(params.network).estimateEtchCost(estimateEtchRequest);
1192
+ if (response.data) {
1193
+ return {
1194
+ status: "success",
1195
+ result: response.data
1196
+ };
1197
+ }
1198
+ return {
1199
+ status: "error",
1200
+ error: {
1201
+ code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
1202
+ message: response.error.message
1203
+ }
1204
+ };
1205
+ }
1206
+ async getOrder(params) {
1207
+ const response = await getRunesApiClient(params.network).getOrder(params.id);
1208
+ if (response.data) {
1209
+ return {
1210
+ status: "success",
1211
+ result: response.data
1212
+ };
1213
+ }
1214
+ return {
1215
+ status: "error",
1216
+ error: {
1217
+ code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
1218
+ message: response.error.message
1219
+ }
1220
+ };
1221
+ }
1222
+ async estimateRbfOrder(params) {
1223
+ const rbfOrderRequest = {
1224
+ newFeeRate: params.newFeeRate,
1225
+ orderId: params.orderId
1226
+ };
1227
+ const response = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
1228
+ if (response.data) {
1229
+ return {
1230
+ status: "success",
1231
+ result: {
1232
+ fundingAddress: response.data.fundingAddress,
1233
+ rbfCost: response.data.rbfCost
1234
+ }
1235
+ };
1236
+ }
1237
+ return {
1238
+ status: "error",
1239
+ error: {
1240
+ code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
1241
+ message: response.error.message
1242
+ }
1243
+ };
1244
+ }
1245
+ async rbfOrder(params) {
1246
+ try {
1247
+ const rbfOrderRequest = {
1248
+ newFeeRate: params.newFeeRate,
1249
+ orderId: params.orderId
1250
+ };
1251
+ const orderResponse = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
1252
+ if (!orderResponse.data) {
1253
+ return {
1254
+ status: "error",
1255
+ error: {
1256
+ code: orderResponse.error.code === 400 || orderResponse.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
1257
+ message: orderResponse.error.message
1258
+ }
1259
+ };
1260
+ }
1261
+ const paymentResponse = await this.requestInternal("sendTransfer", {
1262
+ recipients: [
1263
+ {
1264
+ address: orderResponse.data.fundingAddress,
1265
+ amount: orderResponse.data.rbfCost
1266
+ }
1267
+ ]
1268
+ });
1269
+ if (paymentResponse.status !== "success") {
1270
+ return paymentResponse;
1271
+ }
1272
+ return {
1273
+ status: "success",
1274
+ result: {
1275
+ fundingAddress: orderResponse.data.fundingAddress,
1276
+ orderId: rbfOrderRequest.orderId,
1277
+ fundRBFTransactionId: paymentResponse.result.txid
1278
+ }
1279
+ };
1280
+ } catch (error) {
1281
+ return {
1282
+ status: "error",
1283
+ error: {
1284
+ code: -32603 /* INTERNAL_ERROR */,
1285
+ message: error.message
1286
+ }
1287
+ };
1288
+ }
1289
+ }
1290
+ async request(method, params) {
1291
+ switch (method) {
1292
+ case "runes_mint":
1293
+ return this.mintRunes(params);
1294
+ case "runes_etch":
1295
+ return this.etchRunes(params);
1296
+ case "runes_estimateMint":
1297
+ return this.estimateMint(params);
1298
+ case "runes_estimateEtch":
1299
+ return this.estimateEtch(params);
1300
+ case "runes_getOrder": {
1301
+ return this.getOrder(params);
1302
+ }
1303
+ case "runes_estimateRbfOrder": {
1304
+ return this.estimateRbfOrder(params);
1305
+ }
1306
+ case "runes_rbfOrder": {
1307
+ return this.rbfOrder(params);
1308
+ }
1309
+ default:
1310
+ return this.requestInternal(method, params);
1311
+ }
1312
+ }
1313
+ };
1314
+
1315
+ // src/adapters/xverse.ts
1316
+ var XverseAdapter = class extends SatsConnectAdapter {
1317
+ id = DefaultAdaptersInfo.xverse.id;
1318
+ requestInternal = async (method, params) => {
1319
+ return request(method, params, this.id);
1320
+ };
1321
+ addListener = (event, cb) => {
1322
+ return addListener(
1323
+ event,
1324
+ // The types of the `addListener` function being called here are not
1325
+ // entirely accurate.
1326
+ cb,
1327
+ this.id
1328
+ );
1329
+ };
1330
+ };
1331
+
1332
+ // src/adapters/unisat.ts
1333
+ var import_bitcoin_address_validation = require("bitcoin-address-validation");
1334
+ var import_buffer = require("buffer");
1335
+ function convertSignInputsToInputType(signInputs) {
1336
+ let result = [];
1337
+ for (let address in signInputs) {
1338
+ let indexes = signInputs[address];
1339
+ for (let index of indexes) {
1340
+ result.push({
1341
+ index,
1342
+ address
1343
+ });
1344
+ }
1345
+ }
1346
+ return result;
1347
+ }
1348
+ var UnisatAdapter = class extends SatsConnectAdapter {
1349
+ id = DefaultAdaptersInfo.unisat.id;
1350
+ async getAccounts(params) {
1351
+ const { purposes } = params;
1352
+ if (purposes.includes("stacks" /* Stacks */)) {
1353
+ throw new Error("Only bitcoin addresses are supported");
1354
+ }
1355
+ const accounts = await window.unisat.requestAccounts();
1356
+ const publicKey = await window.unisat.getPublicKey();
1357
+ const address = accounts[0];
1358
+ const addressType = (0, import_bitcoin_address_validation.getAddressInfo)(accounts[0]).type;
1359
+ const pk = addressType === import_bitcoin_address_validation.AddressType.p2tr ? publicKey.slice(2) : publicKey;
1360
+ const paymentAddress = {
1361
+ address,
1362
+ publicKey: pk,
1363
+ addressType,
1364
+ purpose: "payment" /* Payment */
1365
+ };
1366
+ const ordinalsAddress = {
1367
+ address,
1368
+ publicKey: pk,
1369
+ addressType,
1370
+ purpose: "ordinals" /* Ordinals */
1371
+ };
1372
+ const response = [];
1373
+ if (purposes.includes("payment" /* Payment */)) {
1374
+ response.push({ ...paymentAddress, walletType: "software" });
1375
+ }
1376
+ if (purposes.includes("ordinals" /* Ordinals */)) {
1377
+ response.push({ ...ordinalsAddress, walletType: "software" });
1378
+ }
1379
+ return response;
1380
+ }
1381
+ async signMessage(params) {
1382
+ const { message, address } = params;
1383
+ const addressType = (0, import_bitcoin_address_validation.getAddressInfo)(address).type;
1384
+ const Bip322supportedTypes = [import_bitcoin_address_validation.AddressType.p2wpkh, import_bitcoin_address_validation.AddressType.p2tr];
1385
+ if (Bip322supportedTypes.includes(addressType)) {
1386
+ const response2 = await window.unisat.signMessage(message, "bip322-simple");
1387
+ return {
1388
+ address,
1389
+ messageHash: "",
1390
+ signature: response2,
1391
+ protocol: "BIP322" /* BIP322 */
1392
+ };
1393
+ }
1394
+ const response = await window.unisat.signMessage(message, "ecdsa");
1395
+ return {
1396
+ address,
1397
+ messageHash: "",
1398
+ signature: response,
1399
+ protocol: "ECDSA" /* ECDSA */
1400
+ };
1401
+ }
1402
+ async sendTransfer(params) {
1403
+ const { recipients } = params;
1404
+ if (recipients.length > 1) {
1405
+ throw new Error("Only one recipient is supported by this wallet provider");
1406
+ }
1407
+ const txid = await window.unisat.sendBitcoin(recipients[0].address, recipients[0].amount);
1408
+ return {
1409
+ txid
1410
+ };
1411
+ }
1412
+ async signPsbt(params) {
1413
+ const { psbt, signInputs, broadcast } = params;
1414
+ const psbtHex = import_buffer.Buffer.from(psbt, "base64").toString("hex");
1415
+ const signedPsbt = await window.unisat.signPsbt(psbtHex, {
1416
+ autoFinalized: broadcast,
1417
+ toSignInputs: convertSignInputsToInputType(signInputs)
1418
+ });
1419
+ if (broadcast) {
1420
+ const txid = await window.unisat.pushPsbt(psbtHex);
1421
+ return {
1422
+ psbt: signedPsbt,
1423
+ txid
1424
+ };
1425
+ }
1426
+ return {
1427
+ psbt: psbtHex
1428
+ };
1429
+ }
1430
+ requestInternal = async (method, params) => {
1431
+ try {
1432
+ switch (method) {
1433
+ case "getAccounts": {
1434
+ const response = await this.getAccounts(
1435
+ params
1436
+ );
1437
+ return {
1438
+ status: "success",
1439
+ result: response
1440
+ };
1441
+ }
1442
+ case "sendTransfer": {
1443
+ const response = await this.sendTransfer(params);
1444
+ return {
1445
+ status: "success",
1446
+ result: response
1447
+ };
1448
+ }
1449
+ case "signMessage": {
1450
+ const response = await this.signMessage(params);
1451
+ return {
1452
+ status: "success",
1453
+ result: response
1454
+ };
1455
+ }
1456
+ case "signPsbt": {
1457
+ const response = await this.signPsbt(params);
1458
+ return {
1459
+ status: "success",
1460
+ result: response
1461
+ };
1462
+ }
1463
+ default: {
1464
+ const error = {
1465
+ code: -32001 /* METHOD_NOT_SUPPORTED */,
1466
+ message: "Method not supported by the selected wallet"
1467
+ };
1468
+ console.error("Error calling the method", error);
1469
+ return {
1470
+ status: "error",
1471
+ error
1472
+ };
1473
+ }
1474
+ }
1475
+ } catch (error) {
1476
+ console.error("Error calling the method", error);
1477
+ return {
1478
+ status: "error",
1479
+ error: {
1480
+ code: error.code === 4001 ? -32e3 /* USER_REJECTION */ : -32603 /* INTERNAL_ERROR */,
1481
+ message: error.message ? error.message : "Wallet method call error",
1482
+ data: error
1483
+ }
1484
+ };
1485
+ }
1486
+ };
1487
+ addListener = (eventName, cb) => {
1488
+ switch (eventName) {
1489
+ case "accountChange": {
1490
+ const handler = () => {
1491
+ cb({ type: "accountChange" });
1492
+ };
1493
+ window.unisat.on("accountsChanged", handler);
1494
+ return () => {
1495
+ window.unisat.removeListener("accountsChanged", handler);
1496
+ };
1497
+ }
1498
+ case "networkChange": {
1499
+ const handler = () => {
1500
+ cb({ type: "networkChange" });
1501
+ };
1502
+ window.unisat.on("networkChanged", handler);
1503
+ return () => {
1504
+ window.unisat.removeListener("networkChanged", handler);
1505
+ };
1506
+ }
1507
+ default: {
1508
+ console.error("Event not supported by the selected wallet");
1509
+ return () => {
1510
+ };
1511
+ }
1512
+ }
1513
+ };
1514
+ };
1515
+
1516
+ // src/adapters/BaseAdapter.ts
1517
+ var BaseAdapter = class extends SatsConnectAdapter {
1518
+ id = "";
1519
+ constructor(providerId) {
1520
+ super();
1521
+ this.id = providerId;
1522
+ }
1523
+ requestInternal = async (method, params) => {
1524
+ return request(method, params, this.id);
1525
+ };
1526
+ addListener = (..._args) => {
1527
+ throw new Error("Method not supported for `BaseAdapter`.");
1528
+ };
1529
+ };
1530
+
1531
+ // src/adapters/index.ts
1532
+ var DefaultAdaptersInfo = {
1533
+ xverse: {
1534
+ id: "XverseProviders.BitcoinProvider",
1535
+ name: "Xverse",
1536
+ webUrl: "https://www.xverse.app/",
1537
+ googlePlayStoreUrl: "https://play.google.com/store/apps/details?id=com.secretkeylabs.xverse",
1538
+ iOSAppStoreUrl: "https://apps.apple.com/app/xverse-bitcoin-web3-wallet/id1552272513",
1539
+ chromeWebStoreUrl: "https://chromewebstore.google.com/detail/xverse-wallet/idnnbdplmphpflfnlkomgpfbpcgelopg",
1540
+ icon: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAyIiBoZWlnaHQ9IjEwMiIgdmlld0JveD0iMCAwIDEwMiAxMDIiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxnIGlkPSJJY29uX0FydCAoRWRpdCBNZSkiPgo8cmVjdCB3aWR0aD0iMTA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LWNvbG9yPSIjRjRGQjUyIi8+CjwvbGluZWFyR3JhZGllbnQ+CjxyYWRpYWxHcmFkaWVudCBpZD0icGFpbnQyX3JhZGlhbF8xMDA1MF80MTcxIiBjeD0iMCIgY3k9IjAiIHI9IjEiIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIiBncmFkaWVudFRyYW5zZm9ybT0idHJhbnNsYXRlKDg1LjAwOTkgNjEuODM5Mikgc2NhbGUoMTEuMTMpIj4KPHN0b3Agc3RvcC1jb2xvcj0iI0Y0Qjg1MiIvPgo8c3RvcCBvZmZzZXQ9IjAuMzMiIHN0b3AtY29sb3I9IiNFQTgxMDEiLz4KPHN0b3Agb2Zmc2V0PSIwLjY0IiBzdG9wLWNvbG9yPSIjNzczOTBEIi8+CjxzdG9wIG9mZnNldD0iMSIgc3RvcC1jb2xvcj0iIzIxMUMxRCIvPgo8L3JhZGlhbEdyYWRpZW50Pgo8Y2xpcFBhdGggaWQ9ImNsaXAwXzEwMDUwXzQxNzEiPgo8cmVjdCB3aWR0aD0iMTE1Ljc3IiBoZWlnaHQ9IjE0Ny43IiBmaWxsPSJ3aGl0ZSIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMzIgMTYpIi8+CjwvY2xpcFBhdGg+CjwvZGVmcz4KPC9zdmc+Cg=="
1547
+ }
1548
+ };
1549
+ var defaultAdapters = {
1550
+ [DefaultAdaptersInfo.xverse.id]: XverseAdapter,
1551
+ [DefaultAdaptersInfo.unisat.id]: UnisatAdapter
1552
+ };
1553
+
1554
+ // src/capabilities/index.ts
1555
+ var import_jsontokens2 = require("jsontokens");
1556
+ var extractOrValidateCapabilities = (provider, reportedCapabilities) => {
1557
+ const validateCapability = (capability) => {
1558
+ if (!provider[capability]) {
1559
+ return false;
1560
+ }
1561
+ if (reportedCapabilities && !reportedCapabilities.has(capability)) {
1562
+ return false;
1563
+ }
1564
+ return true;
1565
+ };
1566
+ const capabilityMap = {
1567
+ request: validateCapability("request"),
1568
+ connect: validateCapability("connect"),
1569
+ signMessage: validateCapability("signMessage"),
1570
+ signTransaction: validateCapability("signTransaction"),
1571
+ sendBtcTransaction: validateCapability("sendBtcTransaction"),
1572
+ createInscription: validateCapability("createInscription"),
1573
+ createRepeatInscriptions: validateCapability("createRepeatInscriptions"),
1574
+ signMultipleTransactions: validateCapability("signMultipleTransactions"),
1575
+ addListener: validateCapability("addListener")
1576
+ };
1577
+ return Object.entries(capabilityMap).reduce((acc, [capability, value]) => {
1578
+ if (value)
1579
+ return [...acc, capability];
1580
+ return acc;
1581
+ }, []);
1582
+ };
1583
+ var getCapabilities = async (options) => {
1584
+ const provider = await getProviderOrThrow(options.getProvider);
1585
+ const request2 = (0, import_jsontokens2.createUnsecuredToken)(options.payload);
1586
+ if (provider.getCapabilities) {
1587
+ try {
1588
+ const response = await provider.getCapabilities(request2);
1589
+ options.onFinish?.(extractOrValidateCapabilities(provider, new Set(response)));
1590
+ } catch (error) {
1591
+ console.error("[Connect] Error during capabilities request", error);
1592
+ }
1593
+ }
1594
+ try {
1595
+ const inferredCapabilities = extractOrValidateCapabilities(provider);
1596
+ options.onFinish?.(inferredCapabilities);
1597
+ } catch (error) {
1598
+ console.error("[Connect] Error during capabilities request", error);
1599
+ options.onCancel?.();
1600
+ }
1601
+ };
1602
+
1603
+ // src/inscriptions/createInscription.ts
1604
+ var import_jsontokens3 = require("jsontokens");
1605
+
1606
+ // src/inscriptions/utils.ts
1607
+ var MAX_CONTENT_LENGTH_MAINNET = 4e5;
1608
+ var MAX_CONTENT_LENGTH_TESTNET = 6e4;
1609
+ var validateInscriptionPayload = (payload) => {
1610
+ const { contentType, content, payloadType, network, appFeeAddress, appFee } = payload;
1611
+ if (!/^[a-z]+\/[a-z0-9\-\.\+]+(?=;.*|$)/.test(contentType)) {
1612
+ throw new Error("Invalid content type detected");
1613
+ }
1614
+ if (!content || content.length === 0) {
1615
+ throw new Error("Empty content not allowed");
1616
+ }
1617
+ if (!payloadType || payloadType !== "BASE_64" && payloadType !== "PLAIN_TEXT") {
1618
+ throw new Error("Empty invalid payloadType specified");
1619
+ }
1620
+ if (content.length > (network.type === "Mainnet" ? MAX_CONTENT_LENGTH_MAINNET : MAX_CONTENT_LENGTH_TESTNET)) {
1621
+ throw new Error("Content too large");
1622
+ }
1623
+ if ((appFeeAddress?.length ?? 0) > 0 && (appFee ?? 0) <= 0) {
1624
+ throw new Error("Invalid combination of app fee address and fee provided");
1625
+ }
1626
+ };
1627
+
1628
+ // src/inscriptions/createInscription.ts
1629
+ var createInscription = async (options) => {
1630
+ const { getProvider } = options;
1631
+ const provider = await getProviderOrThrow(getProvider);
1632
+ validateInscriptionPayload(options.payload);
1633
+ try {
1634
+ const request2 = (0, import_jsontokens3.createUnsecuredToken)(options.payload);
1635
+ const response = await provider.createInscription(request2);
1636
+ options.onFinish?.(response);
1637
+ } catch (error) {
1638
+ console.error("[Connect] Error during create inscription", error);
1639
+ options.onCancel?.();
1640
+ }
1641
+ };
1642
+
1643
+ // src/inscriptions/createRepeatInscriptions.ts
1644
+ var import_jsontokens4 = require("jsontokens");
1645
+ var createRepeatInscriptions = async (options) => {
1646
+ const { getProvider } = options;
1647
+ const provider = await getProviderOrThrow(getProvider);
1648
+ validateInscriptionPayload(options.payload);
1649
+ try {
1650
+ const request2 = (0, import_jsontokens4.createUnsecuredToken)(options.payload);
1651
+ const response = await provider.createRepeatInscriptions(request2);
1652
+ options.onFinish?.(response);
1653
+ } catch (error) {
1654
+ console.error("[Connect] Error during create repeat inscriptions", error);
1655
+ options.onCancel?.();
1656
+ }
1657
+ };
1658
+
1659
+ // src/messages/index.ts
1660
+ var import_jsontokens5 = require("jsontokens");
1661
+ var signMessage = async (options) => {
1662
+ const provider = await getProviderOrThrow(options.getProvider);
1663
+ const { address, message } = options.payload;
1664
+ if (!address) {
1665
+ throw new Error("An address is required to sign a message");
1666
+ }
1667
+ if (!message) {
1668
+ throw new Error("A message to be signed is required");
1669
+ }
1670
+ try {
1671
+ const request2 = (0, import_jsontokens5.createUnsecuredToken)(options.payload);
1672
+ const response = await provider.signMessage(request2);
1673
+ options.onFinish?.(response);
1674
+ } catch (error) {
1675
+ console.error("[Connect] Error during sign message request", error);
1676
+ options.onCancel?.();
1677
+ }
1678
+ };
1679
+
1680
+ // src/transactions/sendBtcTransaction.ts
1681
+ var import_jsontokens6 = require("jsontokens");
1682
+ var serializer = (recipient) => {
1683
+ return recipient.map((value) => {
1684
+ const { address, amountSats } = value;
1685
+ return {
1686
+ address,
1687
+ amountSats: amountSats.toString()
1688
+ };
1689
+ });
1690
+ };
1691
+ var sendBtcTransaction = async (options) => {
1692
+ const provider = await getProviderOrThrow(options.getProvider);
1693
+ const { recipients, senderAddress, network, message } = options.payload;
1694
+ if (!recipients || recipients.length === 0) {
1695
+ throw new Error("At least one recipient is required");
1696
+ }
1697
+ if (recipients.some(
1698
+ (item) => typeof item.address !== "string" || typeof item.amountSats !== "bigint"
1699
+ )) {
1700
+ throw new Error("Incorrect recipient format");
1701
+ }
1702
+ if (!senderAddress) {
1703
+ throw new Error("The sender address is required");
1704
+ }
1705
+ try {
1706
+ const serializedRecipients = serializer(recipients);
1707
+ const serializedPayload = {
1708
+ network,
1709
+ senderAddress,
1710
+ message,
1711
+ recipients: serializedRecipients
1712
+ };
1713
+ const request2 = (0, import_jsontokens6.createUnsecuredToken)(serializedPayload);
1714
+ const response = await provider.sendBtcTransaction(request2);
1715
+ options.onFinish?.(response);
1716
+ } catch (error) {
1717
+ console.error("[Connect] Error during send BTC transaction request", error);
1718
+ options.onCancel?.();
1719
+ }
1720
+ };
1721
+
1722
+ // src/transactions/signTransaction.ts
1723
+ var import_jsontokens7 = require("jsontokens");
1724
+ var signTransaction = async (options) => {
1725
+ const provider = await getProviderOrThrow(options.getProvider);
1726
+ const { psbtBase64, inputsToSign } = options.payload;
1727
+ if (!psbtBase64) {
1728
+ throw new Error("A value for psbtBase64 representing the tx hash is required");
1729
+ }
1730
+ if (!inputsToSign) {
1731
+ throw new Error("An array specifying the inputs to be signed by the wallet is required");
1732
+ }
1733
+ try {
1734
+ const request2 = (0, import_jsontokens7.createUnsecuredToken)(options.payload);
1735
+ const response = await provider.signTransaction(request2);
1736
+ options.onFinish?.(response);
1737
+ } catch (error) {
1738
+ console.error("[Connect] Error during sign transaction request", error);
1739
+ options.onCancel?.();
1740
+ }
1741
+ };
1742
+
1743
+ // src/transactions/signMultipleTransactions.ts
1744
+ var import_jsontokens8 = require("jsontokens");
1745
+ var signMultipleTransactions = async (options) => {
1746
+ const provider = await getProviderOrThrow(options.getProvider);
1747
+ const { psbts } = options.payload;
1748
+ if (!psbts || !psbts.length) {
1749
+ throw new Error("psbts array is required");
1750
+ }
1751
+ if (psbts.length > 100) {
1752
+ throw new Error("psbts array must contain less than 100 psbts");
1753
+ }
1754
+ try {
1755
+ const request2 = (0, import_jsontokens8.createUnsecuredToken)(options.payload);
1756
+ const response = await provider.signMultipleTransactions(request2);
1757
+ options.onFinish?.(response);
1758
+ } catch (error) {
1759
+ console.error("[Connect] Error during sign Multiple transactions request", error);
1760
+ options.onCancel?.();
1761
+ }
1762
+ };
1763
+ // Annotate the CommonJS export names for ESM import in node:
1764
+ 0 && (module.exports = {
1765
+ AddressPurpose,
1766
+ AddressType,
1767
+ BaseAdapter,
1768
+ BitcoinNetworkType,
1769
+ DefaultAdaptersInfo,
1770
+ MessageSigningProtocols,
1771
+ RpcErrorCode,
1772
+ RpcIdSchema,
1773
+ SatsConnectAdapter,
1774
+ TransferRunesResultSchema,
1775
+ accountChangeEventName,
1776
+ accountChangeSchema,
1777
+ addListener,
1778
+ addressSchema,
1779
+ connectMethodName,
1780
+ connectParamsSchema,
1781
+ connectRequestMessageSchema,
1782
+ connectResultSchema,
1783
+ createInscription,
1784
+ createRepeatInscriptions,
1785
+ defaultAdapters,
1786
+ disconnectEventName,
1787
+ disconnectMethodName,
1788
+ disconnectParamsSchema,
1789
+ disconnectRequestMessageSchema,
1790
+ disconnectResultSchema,
1791
+ disconnectSchema,
1792
+ getAccountMethodName,
1793
+ getAccountParamsSchema,
1794
+ getAccountRequestMessageSchema,
1795
+ getAccountResultSchema,
1796
+ getAccountsMethodName,
1797
+ getAccountsParamsSchema,
1798
+ getAccountsRequestMessageSchema,
1799
+ getAccountsResultSchema,
1800
+ getAddress,
1801
+ getAddressesMethodName,
1802
+ getAddressesParamsSchema,
1803
+ getAddressesRequestMessageSchema,
1804
+ getAddressesResultSchema,
1805
+ getBalanceMethodName,
1806
+ getBalanceParamsSchema,
1807
+ getBalanceRequestMessageSchema,
1808
+ getBalanceResultSchema,
1809
+ getCapabilities,
1810
+ getCurrentPermissionsMethodName,
1811
+ getCurrentPermissionsParamsSchema,
1812
+ getCurrentPermissionsRequestMessageSchema,
1813
+ getCurrentPermissionsResultSchema,
1814
+ getDefaultProvider,
1815
+ getInfoMethodName,
1816
+ getInfoParamsSchema,
1817
+ getInfoRequestMessageSchema,
1818
+ getInfoResultSchema,
1819
+ getInscriptionsMethodName,
1820
+ getInscriptionsParamsSchema,
1821
+ getInscriptionsResultSchema,
1822
+ getInscriptionsSchema,
1823
+ getProviderById,
1824
+ getProviderOrThrow,
1825
+ getProviders,
1826
+ getRunesBalanceMethodName,
1827
+ getRunesBalanceParamsSchema,
1828
+ getRunesBalanceRequestMessageSchema,
1829
+ getRunesBalanceResultSchema,
1830
+ getSupportedWallets,
1831
+ getWalletTypeMethodName,
1832
+ getWalletTypeParamsSchema,
1833
+ getWalletTypeRequestMessageSchema,
1834
+ getWalletTypeResultSchema,
1835
+ isProviderInstalled,
1836
+ networkChangeEventName,
1837
+ networkChangeSchema,
1838
+ permissionTemplate,
1839
+ removeDefaultProvider,
1840
+ renouncePermissionsMethodName,
1841
+ renouncePermissionsParamsSchema,
1842
+ renouncePermissionsRequestMessageSchema,
1843
+ renouncePermissionsResultSchema,
1844
+ request,
1845
+ requestPermissionsMethodName,
1846
+ requestPermissionsParamsSchema,
1847
+ requestPermissionsRequestMessageSchema,
1848
+ requestPermissionsResultSchema,
1849
+ rpcErrorResponseMessageSchema,
1850
+ rpcRequestMessageSchema,
1851
+ rpcResponseMessageSchema,
1852
+ rpcSuccessResponseMessageSchema,
1853
+ sendBtcTransaction,
1854
+ sendInscriptionsMethodName,
1855
+ sendInscriptionsParamsSchema,
1856
+ sendInscriptionsResultSchema,
1857
+ sendInscriptionsSchema,
1858
+ sendTransferMethodName,
1859
+ sendTransferParamsSchema,
1860
+ sendTransferRequestMessageSchema,
1861
+ sendTransferResultSchema,
1862
+ setDefaultProvider,
1863
+ signMessage,
1864
+ signMessageMethodName,
1865
+ signMessageParamsSchema,
1866
+ signMessageRequestMessageSchema,
1867
+ signMessageResultSchema,
1868
+ signMultipleTransactions,
1869
+ signPsbtMethodName,
1870
+ signPsbtParamsSchema,
1871
+ signPsbtRequestMessageSchema,
1872
+ signPsbtResultSchema,
1873
+ signTransaction,
1874
+ stxGetAddressesMethodName,
1875
+ stxGetAddressesParamsSchema,
1876
+ stxGetAddressesRequestMessageSchema,
1877
+ stxGetAddressesResultSchema,
1878
+ stxSignTransactionMethodName,
1879
+ stxSignTransactionParamsSchema,
1880
+ stxSignTransactionRequestMessageSchema,
1881
+ stxSignTransactionResultSchema,
1882
+ transferRunesMethodName,
1883
+ transferRunesParamsSchema,
1884
+ transferRunesRequestSchema,
1885
+ walletEventSchema,
1886
+ walletTypeSchema,
1887
+ walletTypes
1888
+ });