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

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