@sats-connect/core 0.4.0-590a696 → 0.4.0-68f1213

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