@sats-connect/core 0.4.0-9b65d1d → 0.4.0-bce9762

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