@sats-connect/core 0.4.0-069d601 → 0.4.0-20feed3

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