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

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