@sats-connect/core 0.4.0-7721c7c → 0.4.0-7a3cb13

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,2285 @@
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: v2.unwrap(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"]).entries
901
+ }),
902
+ v14.object({
903
+ ...v14.omit(import_xverse_core.permissions.resources.wallet.walletPermissionSchema, ["clientId"]).entries
904
+ })
905
+ ]);
906
+ var requestPermissionsMethodName = "wallet_requestPermissions";
907
+ var requestPermissionsParamsSchema = v14.nullish(v14.array(permissionTemplate));
908
+ var requestPermissionsResultSchema = v14.literal(true);
909
+ var requestPermissionsRequestMessageSchema = v14.object({
910
+ ...rpcRequestMessageSchema.entries,
911
+ ...v14.object({
912
+ method: v14.literal(requestPermissionsMethodName),
913
+ params: requestPermissionsParamsSchema,
914
+ id: v14.string()
915
+ }).entries
916
+ });
917
+ var renouncePermissionsMethodName = "wallet_renouncePermissions";
918
+ var renouncePermissionsParamsSchema = v14.nullish(v14.null());
919
+ var renouncePermissionsResultSchema = v14.nullish(v14.null());
920
+ var renouncePermissionsRequestMessageSchema = v14.object({
921
+ ...rpcRequestMessageSchema.entries,
922
+ ...v14.object({
923
+ method: v14.literal(renouncePermissionsMethodName),
924
+ params: renouncePermissionsParamsSchema,
925
+ id: v14.string()
926
+ }).entries
927
+ });
928
+ var disconnectMethodName = "wallet_disconnect";
929
+ var disconnectParamsSchema = v14.nullish(v14.null());
930
+ var disconnectResultSchema = v14.nullish(v14.null());
931
+ var disconnectRequestMessageSchema = v14.object({
932
+ ...rpcRequestMessageSchema.entries,
933
+ ...v14.object({
934
+ method: v14.literal(disconnectMethodName),
935
+ params: disconnectParamsSchema,
936
+ id: v14.string()
937
+ }).entries
938
+ });
939
+ var getWalletTypeMethodName = "wallet_getWalletType";
940
+ var getWalletTypeParamsSchema = v14.nullish(v14.null());
941
+ var getWalletTypeResultSchema = walletTypeSchema;
942
+ var getWalletTypeRequestMessageSchema = v14.object({
943
+ ...rpcRequestMessageSchema.entries,
944
+ ...v14.object({
945
+ method: v14.literal(getWalletTypeMethodName),
946
+ params: getWalletTypeParamsSchema,
947
+ id: v14.string()
948
+ }).entries
949
+ });
950
+ var getCurrentPermissionsMethodName = "wallet_getCurrentPermissions";
951
+ var getCurrentPermissionsParamsSchema = v14.nullish(v14.null());
952
+ var getCurrentPermissionsResultSchema = v14.array(import_xverse_core.permissions.store.permission);
953
+ var getCurrentPermissionsRequestMessageSchema = v14.object({
954
+ ...rpcRequestMessageSchema.entries,
955
+ ...v14.object({
956
+ method: v14.literal(getCurrentPermissionsMethodName),
957
+ params: getCurrentPermissionsParamsSchema,
958
+ id: v14.string()
959
+ }).entries
960
+ });
961
+ var getAccountMethodName = "wallet_getAccount";
962
+ var getAccountParamsSchema = v14.nullish(v14.null());
963
+ var getAccountResultSchema = v14.object({
964
+ id: import_xverse_core.permissions.utils.account.accountIdSchema,
965
+ addresses: v14.array(addressSchema),
966
+ walletType: walletTypeSchema
967
+ });
968
+ var getAccountRequestMessageSchema = v14.object({
969
+ ...rpcRequestMessageSchema.entries,
970
+ ...v14.object({
971
+ method: v14.literal(getAccountMethodName),
972
+ params: getAccountParamsSchema,
973
+ id: v14.string()
974
+ }).entries
975
+ });
976
+ var connectMethodName = "wallet_connect";
977
+ var connectParamsSchema = v14.nullish(
978
+ v14.object({
979
+ permissions: v14.optional(v14.array(permissionTemplate))
980
+ })
981
+ );
982
+ var connectResultSchema = getAccountResultSchema;
983
+ var connectRequestMessageSchema = v14.object({
984
+ ...rpcRequestMessageSchema.entries,
985
+ ...v14.object({
986
+ method: v14.literal(connectMethodName),
987
+ params: connectParamsSchema,
988
+ id: v14.string()
989
+ }).entries
990
+ });
991
+
992
+ // src/request/types/runesMethods/etch.ts
993
+ var v15 = __toESM(require("valibot"));
994
+ var runesEtchMethodName = "runes_etch";
995
+ var etchTermsSchema = v15.object({
996
+ amount: v15.string(),
997
+ cap: v15.string(),
998
+ heightStart: v15.optional(v15.string()),
999
+ heightEnd: v15.optional(v15.string()),
1000
+ offsetStart: v15.optional(v15.string()),
1001
+ offsetEnd: v15.optional(v15.string())
1002
+ });
1003
+ var inscriptionDetailsSchema = v15.object({
1004
+ contentType: v15.string(),
1005
+ contentBase64: v15.string()
1006
+ });
1007
+ var runesEtchParamsSchema = v15.object({
1008
+ runeName: v15.string(),
1009
+ divisibility: v15.optional(v15.number()),
1010
+ symbol: v15.optional(v15.string()),
1011
+ premine: v15.optional(v15.string()),
1012
+ isMintable: v15.boolean(),
1013
+ delegateInscriptionId: v15.optional(v15.string()),
1014
+ destinationAddress: v15.string(),
1015
+ refundAddress: v15.string(),
1016
+ feeRate: v15.number(),
1017
+ appServiceFee: v15.optional(v15.number()),
1018
+ appServiceFeeAddress: v15.optional(v15.string()),
1019
+ terms: v15.optional(etchTermsSchema),
1020
+ inscriptionDetails: v15.optional(inscriptionDetailsSchema),
1021
+ network: v15.optional(v15.enum(BitcoinNetworkType))
1022
+ });
1023
+ var runesEtchResultSchema = v15.object({
1024
+ orderId: v15.string(),
1025
+ fundTransactionId: v15.string(),
1026
+ fundingAddress: v15.string()
1027
+ });
1028
+ var runesEtchRequestMessageSchema = v15.object({
1029
+ ...rpcRequestMessageSchema.entries,
1030
+ ...v15.object({
1031
+ method: v15.literal(runesEtchMethodName),
1032
+ params: runesEtchParamsSchema,
1033
+ id: v15.string()
1034
+ }).entries
1035
+ });
1036
+
1037
+ // src/request/types/runesMethods/getBalance.ts
1038
+ var v16 = __toESM(require("valibot"));
1039
+ var runesGetBalanceMethodName = "runes_getBalance";
1040
+ var runesGetBalanceParamsSchema = v16.nullish(v16.null());
1041
+ var runesGetBalanceResultSchema = v16.object({
1042
+ balances: v16.array(
1043
+ v16.object({
1044
+ runeName: v16.string(),
1045
+ amount: v16.string(),
1046
+ divisibility: v16.number(),
1047
+ symbol: v16.string(),
1048
+ inscriptionId: v16.nullish(v16.string())
1049
+ })
1050
+ )
1051
+ });
1052
+ var runesGetBalanceRequestMessageSchema = v16.object({
1053
+ ...rpcRequestMessageSchema.entries,
1054
+ ...v16.object({
1055
+ method: v16.literal(runesGetBalanceMethodName),
1056
+ params: runesGetBalanceParamsSchema,
1057
+ id: v16.string()
1058
+ }).entries
1059
+ });
1060
+
1061
+ // src/request/types/runesMethods/mint.ts
1062
+ var v17 = __toESM(require("valibot"));
1063
+ var runesMintMethodName = "runes_mint";
1064
+ var runesMintParamsSchema = v17.object({
1065
+ appServiceFee: v17.optional(v17.number()),
1066
+ appServiceFeeAddress: v17.optional(v17.string()),
1067
+ destinationAddress: v17.string(),
1068
+ feeRate: v17.number(),
1069
+ refundAddress: v17.string(),
1070
+ repeats: v17.number(),
1071
+ runeName: v17.string(),
1072
+ network: v17.optional(v17.enum(BitcoinNetworkType))
1073
+ });
1074
+ var runesMintResultSchema = v17.object({
1075
+ orderId: v17.string(),
1076
+ fundTransactionId: v17.string(),
1077
+ fundingAddress: v17.string()
1078
+ });
1079
+ var runesMintRequestMessageSchema = v17.object({
1080
+ ...rpcRequestMessageSchema.entries,
1081
+ ...v17.object({
1082
+ method: v17.literal(runesMintMethodName),
1083
+ params: runesMintParamsSchema,
1084
+ id: v17.string()
1085
+ }).entries
1086
+ });
1087
+
1088
+ // src/request/types/runesMethods/transfer.ts
1089
+ var v18 = __toESM(require("valibot"));
1090
+ var runesTransferMethodName = "runes_transfer";
1091
+ var runesTransferParamsSchema = v18.object({
1092
+ recipients: v18.array(
1093
+ v18.object({
1094
+ runeName: v18.string(),
1095
+ amount: v18.string(),
1096
+ address: v18.string()
1097
+ })
1098
+ )
1099
+ });
1100
+ var runesTransferResultSchema = v18.object({
1101
+ txid: v18.string()
1102
+ });
1103
+ var runesTransferRequestMessageSchema = v18.object({
1104
+ ...rpcRequestMessageSchema.entries,
1105
+ ...v18.object({
1106
+ method: v18.literal(runesTransferMethodName),
1107
+ params: runesTransferParamsSchema,
1108
+ id: v18.string()
1109
+ }).entries
1110
+ });
1111
+
1112
+ // src/request/types/ordinalsMethods.ts
1113
+ var v19 = __toESM(require("valibot"));
1114
+ var getInscriptionsMethodName = "ord_getInscriptions";
1115
+ var getInscriptionsParamsSchema = v19.object({
1116
+ offset: v19.number(),
1117
+ limit: v19.number()
1118
+ });
1119
+ var getInscriptionsResultSchema = v19.object({
1120
+ total: v19.number(),
1121
+ limit: v19.number(),
1122
+ offset: v19.number(),
1123
+ inscriptions: v19.array(
1124
+ v19.object({
1125
+ inscriptionId: v19.string(),
1126
+ inscriptionNumber: v19.string(),
1127
+ address: v19.string(),
1128
+ collectionName: v19.optional(v19.string()),
1129
+ postage: v19.string(),
1130
+ contentLength: v19.string(),
1131
+ contentType: v19.string(),
1132
+ timestamp: v19.number(),
1133
+ offset: v19.number(),
1134
+ genesisTransaction: v19.string(),
1135
+ output: v19.string()
1136
+ })
1137
+ )
1138
+ });
1139
+ var getInscriptionsRequestMessageSchema = v19.object({
1140
+ ...rpcRequestMessageSchema.entries,
1141
+ ...v19.object({
1142
+ method: v19.literal(getInscriptionsMethodName),
1143
+ params: getInscriptionsParamsSchema,
1144
+ id: v19.string()
1145
+ }).entries
1146
+ });
1147
+ var sendInscriptionsMethodName = "ord_sendInscriptions";
1148
+ var sendInscriptionsParamsSchema = v19.object({
1149
+ transfers: v19.array(
1150
+ v19.object({
1151
+ address: v19.string(),
1152
+ inscriptionId: v19.string()
1153
+ })
1154
+ )
1155
+ });
1156
+ var sendInscriptionsResultSchema = v19.object({
1157
+ txid: v19.string()
1158
+ });
1159
+ var sendInscriptionsRequestMessageSchema = v19.object({
1160
+ ...rpcRequestMessageSchema.entries,
1161
+ ...v19.object({
1162
+ method: v19.literal(sendInscriptionsMethodName),
1163
+ params: sendInscriptionsParamsSchema,
1164
+ id: v19.string()
1165
+ }).entries
1166
+ });
1167
+
1168
+ // src/request/index.ts
1169
+ var request = async (method, params, providerId) => {
1170
+ let provider = window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
1171
+ if (providerId) {
1172
+ provider = await getProviderById(providerId);
1173
+ }
1174
+ if (!provider) {
1175
+ throw new Error("no wallet provider was found");
1176
+ }
1177
+ if (!method) {
1178
+ throw new Error("A wallet method is required");
1179
+ }
1180
+ const response = await provider.request(method, params);
1181
+ if (v20.is(rpcErrorResponseMessageSchema, response)) {
1182
+ return {
1183
+ status: "error",
1184
+ error: response.error
1185
+ };
1186
+ }
1187
+ if (v20.is(rpcSuccessResponseMessageSchema, response)) {
1188
+ return {
1189
+ status: "success",
1190
+ result: response.result
1191
+ };
1192
+ }
1193
+ return {
1194
+ status: "error",
1195
+ error: {
1196
+ code: -32603 /* INTERNAL_ERROR */,
1197
+ message: "Received unknown response from provider.",
1198
+ data: response
1199
+ }
1200
+ };
1201
+ };
1202
+ var addListener = (event, cb, providerId) => {
1203
+ let provider = window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
1204
+ if (providerId) {
1205
+ provider = getProviderById(providerId);
1206
+ }
1207
+ if (!provider) {
1208
+ throw new Error("no wallet provider was found");
1209
+ }
1210
+ if (!provider.addListener) {
1211
+ console.error(
1212
+ `The wallet provider you are using does not support the addListener method. Please update your wallet provider.`
1213
+ );
1214
+ return () => {
1215
+ };
1216
+ }
1217
+ return provider.addListener(event, cb);
1218
+ };
1219
+
1220
+ // src/runes/api.ts
1221
+ var import_axios = __toESM(require("axios"));
1222
+ var urlNetworkSuffix = {
1223
+ ["Mainnet" /* Mainnet */]: "",
1224
+ ["Testnet" /* Testnet */]: "-testnet",
1225
+ ["Signet" /* Signet */]: "-signet"
1226
+ };
1227
+ var ORDINALS_API_BASE_URL = (network = "Mainnet" /* Mainnet */) => `https://ordinals${urlNetworkSuffix[network]}.xverse.app/v1`;
1228
+ var RunesApi = class {
1229
+ client;
1230
+ constructor(network) {
1231
+ this.client = import_axios.default.create({
1232
+ baseURL: ORDINALS_API_BASE_URL(network)
1233
+ });
1234
+ }
1235
+ parseError = (error) => {
1236
+ return {
1237
+ code: error.response?.status,
1238
+ message: JSON.stringify(error.response?.data)
1239
+ };
1240
+ };
1241
+ estimateMintCost = async (mintParams) => {
1242
+ try {
1243
+ const response = await this.client.post("/runes/mint/estimate", {
1244
+ ...mintParams
1245
+ });
1246
+ return {
1247
+ data: response.data
1248
+ };
1249
+ } catch (error) {
1250
+ const err = error;
1251
+ return {
1252
+ error: this.parseError(err)
1253
+ };
1254
+ }
1255
+ };
1256
+ estimateEtchCost = async (etchParams) => {
1257
+ try {
1258
+ const response = await this.client.post("/runes/etch/estimate", {
1259
+ ...etchParams
1260
+ });
1261
+ return {
1262
+ data: response.data
1263
+ };
1264
+ } catch (error) {
1265
+ const err = error;
1266
+ return {
1267
+ error: this.parseError(err)
1268
+ };
1269
+ }
1270
+ };
1271
+ createMintOrder = async (mintOrderParams) => {
1272
+ try {
1273
+ const response = await this.client.post("/runes/mint/orders", {
1274
+ ...mintOrderParams
1275
+ });
1276
+ return {
1277
+ data: response.data
1278
+ };
1279
+ } catch (error) {
1280
+ const err = error;
1281
+ return {
1282
+ error: this.parseError(err)
1283
+ };
1284
+ }
1285
+ };
1286
+ createEtchOrder = async (etchOrderParams) => {
1287
+ try {
1288
+ const response = await this.client.post("/runes/etch/orders", {
1289
+ ...etchOrderParams
1290
+ });
1291
+ return {
1292
+ data: response.data
1293
+ };
1294
+ } catch (error) {
1295
+ const err = error;
1296
+ return {
1297
+ error: this.parseError(err)
1298
+ };
1299
+ }
1300
+ };
1301
+ executeMint = async (orderId, fundTransactionId) => {
1302
+ try {
1303
+ const response = await this.client.post(`/runes/mint/orders/${orderId}/execute`, {
1304
+ fundTransactionId
1305
+ });
1306
+ return {
1307
+ data: response.data
1308
+ };
1309
+ } catch (error) {
1310
+ const err = error;
1311
+ return {
1312
+ error: this.parseError(err)
1313
+ };
1314
+ }
1315
+ };
1316
+ executeEtch = async (orderId, fundTransactionId) => {
1317
+ try {
1318
+ const response = await this.client.post(`/runes/etch/orders/${orderId}/execute`, {
1319
+ fundTransactionId
1320
+ });
1321
+ return {
1322
+ data: response.data
1323
+ };
1324
+ } catch (error) {
1325
+ const err = error;
1326
+ return {
1327
+ error: this.parseError(err)
1328
+ };
1329
+ }
1330
+ };
1331
+ getOrder = async (orderId) => {
1332
+ try {
1333
+ const response = await this.client.get(`/orders/${orderId}`);
1334
+ return {
1335
+ data: response.data
1336
+ };
1337
+ } catch (error) {
1338
+ const err = error;
1339
+ return {
1340
+ error: this.parseError(err)
1341
+ };
1342
+ }
1343
+ };
1344
+ rbfOrder = async (rbfRequest) => {
1345
+ const { orderId, newFeeRate } = rbfRequest;
1346
+ try {
1347
+ const response = await this.client.post(`/orders/${orderId}/rbf-estimate`, {
1348
+ newFeeRate
1349
+ });
1350
+ return {
1351
+ data: response.data
1352
+ };
1353
+ } catch (error) {
1354
+ const err = error;
1355
+ return {
1356
+ error: this.parseError(err)
1357
+ };
1358
+ }
1359
+ };
1360
+ };
1361
+ var clients = {};
1362
+ var getRunesApiClient = (network = "Mainnet" /* Mainnet */) => {
1363
+ if (!clients[network]) {
1364
+ clients[network] = new RunesApi(network);
1365
+ }
1366
+ return clients[network];
1367
+ };
1368
+
1369
+ // src/adapters/satsConnectAdapter.ts
1370
+ var SatsConnectAdapter = class {
1371
+ async mintRunes(params) {
1372
+ try {
1373
+ const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
1374
+ if (walletInfo && walletInfo.status === "success") {
1375
+ const isMintSupported = walletInfo.result.methods?.includes("runes_mint");
1376
+ if (isMintSupported) {
1377
+ const response = await this.requestInternal("runes_mint", params);
1378
+ if (response) {
1379
+ if (response.status === "success") {
1380
+ return response;
1381
+ }
1382
+ if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
1383
+ return response;
1384
+ }
1385
+ }
1386
+ }
1387
+ }
1388
+ const mintRequest = {
1389
+ destinationAddress: params.destinationAddress,
1390
+ feeRate: params.feeRate,
1391
+ refundAddress: params.refundAddress,
1392
+ repeats: params.repeats,
1393
+ runeName: params.runeName,
1394
+ appServiceFee: params.appServiceFee,
1395
+ appServiceFeeAddress: params.appServiceFeeAddress
1396
+ };
1397
+ const orderResponse = await new RunesApi(params.network).createMintOrder(mintRequest);
1398
+ if (!orderResponse.data) {
1399
+ return {
1400
+ status: "error",
1401
+ error: {
1402
+ code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
1403
+ message: orderResponse.error.message
1404
+ }
1405
+ };
1406
+ }
1407
+ const paymentResponse = await this.requestInternal("sendTransfer", {
1408
+ recipients: [
1409
+ {
1410
+ address: orderResponse.data.fundAddress,
1411
+ amount: orderResponse.data.fundAmount
1412
+ }
1413
+ ]
1414
+ });
1415
+ if (paymentResponse.status !== "success") {
1416
+ return paymentResponse;
1417
+ }
1418
+ await new RunesApi(params.network).executeMint(
1419
+ orderResponse.data.orderId,
1420
+ paymentResponse.result.txid
1421
+ );
1422
+ return {
1423
+ status: "success",
1424
+ result: {
1425
+ orderId: orderResponse.data.orderId,
1426
+ fundTransactionId: paymentResponse.result.txid,
1427
+ fundingAddress: orderResponse.data.fundAddress
1428
+ }
1429
+ };
1430
+ } catch (error) {
1431
+ return {
1432
+ status: "error",
1433
+ error: {
1434
+ code: -32603 /* INTERNAL_ERROR */,
1435
+ message: error.message
1436
+ }
1437
+ };
1438
+ }
1439
+ }
1440
+ async etchRunes(params) {
1441
+ const etchRequest = {
1442
+ destinationAddress: params.destinationAddress,
1443
+ refundAddress: params.refundAddress,
1444
+ feeRate: params.feeRate,
1445
+ runeName: params.runeName,
1446
+ divisibility: params.divisibility,
1447
+ symbol: params.symbol,
1448
+ premine: params.premine,
1449
+ isMintable: params.isMintable,
1450
+ terms: params.terms,
1451
+ inscriptionDetails: params.inscriptionDetails,
1452
+ delegateInscriptionId: params.delegateInscriptionId,
1453
+ appServiceFee: params.appServiceFee,
1454
+ appServiceFeeAddress: params.appServiceFeeAddress
1455
+ };
1456
+ try {
1457
+ const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
1458
+ if (walletInfo && walletInfo.status === "success") {
1459
+ const isEtchSupported = walletInfo.result.methods?.includes("runes_etch");
1460
+ if (isEtchSupported) {
1461
+ const response = await this.requestInternal("runes_etch", params);
1462
+ if (response) {
1463
+ if (response.status === "success") {
1464
+ return response;
1465
+ }
1466
+ if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
1467
+ return response;
1468
+ }
1469
+ }
1470
+ }
1471
+ }
1472
+ const orderResponse = await new RunesApi(params.network).createEtchOrder(etchRequest);
1473
+ if (!orderResponse.data) {
1474
+ return {
1475
+ status: "error",
1476
+ error: {
1477
+ code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
1478
+ message: orderResponse.error.message
1479
+ }
1480
+ };
1481
+ }
1482
+ const paymentResponse = await this.requestInternal("sendTransfer", {
1483
+ recipients: [
1484
+ {
1485
+ address: orderResponse.data.fundAddress,
1486
+ amount: orderResponse.data.fundAmount
1487
+ }
1488
+ ]
1489
+ });
1490
+ if (paymentResponse.status !== "success") {
1491
+ return paymentResponse;
1492
+ }
1493
+ await new RunesApi(params.network).executeEtch(
1494
+ orderResponse.data.orderId,
1495
+ paymentResponse.result.txid
1496
+ );
1497
+ return {
1498
+ status: "success",
1499
+ result: {
1500
+ orderId: orderResponse.data.orderId,
1501
+ fundTransactionId: paymentResponse.result.txid,
1502
+ fundingAddress: orderResponse.data.fundAddress
1503
+ }
1504
+ };
1505
+ } catch (error) {
1506
+ return {
1507
+ status: "error",
1508
+ error: {
1509
+ code: -32603 /* INTERNAL_ERROR */,
1510
+ message: error.message
1511
+ }
1512
+ };
1513
+ }
1514
+ }
1515
+ async estimateMint(params) {
1516
+ const estimateMintRequest = {
1517
+ destinationAddress: params.destinationAddress,
1518
+ feeRate: params.feeRate,
1519
+ repeats: params.repeats,
1520
+ runeName: params.runeName,
1521
+ appServiceFee: params.appServiceFee,
1522
+ appServiceFeeAddress: params.appServiceFeeAddress
1523
+ };
1524
+ const response = await getRunesApiClient(
1525
+ params.network
1526
+ ).estimateMintCost(estimateMintRequest);
1527
+ if (response.data) {
1528
+ return {
1529
+ status: "success",
1530
+ result: response.data
1531
+ };
1532
+ }
1533
+ return {
1534
+ status: "error",
1535
+ error: {
1536
+ code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
1537
+ message: response.error.message
1538
+ }
1539
+ };
1540
+ }
1541
+ async estimateEtch(params) {
1542
+ const estimateEtchRequest = {
1543
+ destinationAddress: params.destinationAddress,
1544
+ feeRate: params.feeRate,
1545
+ runeName: params.runeName,
1546
+ divisibility: params.divisibility,
1547
+ symbol: params.symbol,
1548
+ premine: params.premine,
1549
+ isMintable: params.isMintable,
1550
+ terms: params.terms,
1551
+ inscriptionDetails: params.inscriptionDetails,
1552
+ delegateInscriptionId: params.delegateInscriptionId,
1553
+ appServiceFee: params.appServiceFee,
1554
+ appServiceFeeAddress: params.appServiceFeeAddress
1555
+ };
1556
+ const response = await getRunesApiClient(params.network).estimateEtchCost(estimateEtchRequest);
1557
+ if (response.data) {
1558
+ return {
1559
+ status: "success",
1560
+ result: response.data
1561
+ };
1562
+ }
1563
+ return {
1564
+ status: "error",
1565
+ error: {
1566
+ code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
1567
+ message: response.error.message
1568
+ }
1569
+ };
1570
+ }
1571
+ async getOrder(params) {
1572
+ const response = await getRunesApiClient(params.network).getOrder(params.id);
1573
+ if (response.data) {
1574
+ return {
1575
+ status: "success",
1576
+ result: response.data
1577
+ };
1578
+ }
1579
+ return {
1580
+ status: "error",
1581
+ error: {
1582
+ code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
1583
+ message: response.error.message
1584
+ }
1585
+ };
1586
+ }
1587
+ async estimateRbfOrder(params) {
1588
+ const rbfOrderRequest = {
1589
+ newFeeRate: params.newFeeRate,
1590
+ orderId: params.orderId
1591
+ };
1592
+ const response = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
1593
+ if (response.data) {
1594
+ return {
1595
+ status: "success",
1596
+ result: {
1597
+ fundingAddress: response.data.fundingAddress,
1598
+ rbfCost: response.data.rbfCost
1599
+ }
1600
+ };
1601
+ }
1602
+ return {
1603
+ status: "error",
1604
+ error: {
1605
+ code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
1606
+ message: response.error.message
1607
+ }
1608
+ };
1609
+ }
1610
+ async rbfOrder(params) {
1611
+ try {
1612
+ const rbfOrderRequest = {
1613
+ newFeeRate: params.newFeeRate,
1614
+ orderId: params.orderId
1615
+ };
1616
+ const orderResponse = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
1617
+ if (!orderResponse.data) {
1618
+ return {
1619
+ status: "error",
1620
+ error: {
1621
+ code: orderResponse.error.code === 400 || orderResponse.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
1622
+ message: orderResponse.error.message
1623
+ }
1624
+ };
1625
+ }
1626
+ const paymentResponse = await this.requestInternal("sendTransfer", {
1627
+ recipients: [
1628
+ {
1629
+ address: orderResponse.data.fundingAddress,
1630
+ amount: orderResponse.data.rbfCost
1631
+ }
1632
+ ]
1633
+ });
1634
+ if (paymentResponse.status !== "success") {
1635
+ return paymentResponse;
1636
+ }
1637
+ return {
1638
+ status: "success",
1639
+ result: {
1640
+ fundingAddress: orderResponse.data.fundingAddress,
1641
+ orderId: rbfOrderRequest.orderId,
1642
+ fundRBFTransactionId: paymentResponse.result.txid
1643
+ }
1644
+ };
1645
+ } catch (error) {
1646
+ return {
1647
+ status: "error",
1648
+ error: {
1649
+ code: -32603 /* INTERNAL_ERROR */,
1650
+ message: error.message
1651
+ }
1652
+ };
1653
+ }
1654
+ }
1655
+ async request(method, params) {
1656
+ switch (method) {
1657
+ case "runes_mint":
1658
+ return this.mintRunes(params);
1659
+ case "runes_etch":
1660
+ return this.etchRunes(params);
1661
+ case "runes_estimateMint":
1662
+ return this.estimateMint(params);
1663
+ case "runes_estimateEtch":
1664
+ return this.estimateEtch(params);
1665
+ case "runes_getOrder": {
1666
+ return this.getOrder(params);
1667
+ }
1668
+ case "runes_estimateRbfOrder": {
1669
+ return this.estimateRbfOrder(params);
1670
+ }
1671
+ case "runes_rbfOrder": {
1672
+ return this.rbfOrder(params);
1673
+ }
1674
+ default:
1675
+ return this.requestInternal(method, params);
1676
+ }
1677
+ }
1678
+ };
1679
+
1680
+ // src/adapters/xverse.ts
1681
+ var XverseAdapter = class extends SatsConnectAdapter {
1682
+ id = DefaultAdaptersInfo.xverse.id;
1683
+ requestInternal = async (method, params) => {
1684
+ return request(method, params, this.id);
1685
+ };
1686
+ addListener = (event, cb) => {
1687
+ return addListener(
1688
+ event,
1689
+ // The types of the `addListener` function being called here are not
1690
+ // entirely accurate.
1691
+ cb,
1692
+ this.id
1693
+ );
1694
+ };
1695
+ };
1696
+
1697
+ // src/adapters/unisat.ts
1698
+ var import_bitcoin_address_validation = require("bitcoin-address-validation");
1699
+ var import_buffer = require("buffer");
1700
+ function convertSignInputsToInputType(signInputs) {
1701
+ let result = [];
1702
+ for (let address in signInputs) {
1703
+ let indexes = signInputs[address];
1704
+ for (let index of indexes) {
1705
+ result.push({
1706
+ index,
1707
+ address
1708
+ });
1709
+ }
1710
+ }
1711
+ return result;
1712
+ }
1713
+ var UnisatAdapter = class extends SatsConnectAdapter {
1714
+ id = DefaultAdaptersInfo.unisat.id;
1715
+ async getAccounts(params) {
1716
+ const { purposes } = params;
1717
+ if (purposes.includes("stacks" /* Stacks */)) {
1718
+ throw new Error("Only bitcoin addresses are supported");
1719
+ }
1720
+ const accounts = await window.unisat.requestAccounts();
1721
+ const publicKey = await window.unisat.getPublicKey();
1722
+ const address = accounts[0];
1723
+ const addressType = (0, import_bitcoin_address_validation.getAddressInfo)(accounts[0]).type;
1724
+ const pk = addressType === import_bitcoin_address_validation.AddressType.p2tr ? publicKey.slice(2) : publicKey;
1725
+ const paymentAddress = {
1726
+ address,
1727
+ publicKey: pk,
1728
+ addressType,
1729
+ purpose: "payment" /* Payment */
1730
+ };
1731
+ const ordinalsAddress = {
1732
+ address,
1733
+ publicKey: pk,
1734
+ addressType,
1735
+ purpose: "ordinals" /* Ordinals */
1736
+ };
1737
+ const response = [];
1738
+ if (purposes.includes("payment" /* Payment */)) {
1739
+ response.push({ ...paymentAddress, walletType: "software" });
1740
+ }
1741
+ if (purposes.includes("ordinals" /* Ordinals */)) {
1742
+ response.push({ ...ordinalsAddress, walletType: "software" });
1743
+ }
1744
+ return response;
1745
+ }
1746
+ async signMessage(params) {
1747
+ const { message, address } = params;
1748
+ const addressType = (0, import_bitcoin_address_validation.getAddressInfo)(address).type;
1749
+ const Bip322supportedTypes = [import_bitcoin_address_validation.AddressType.p2wpkh, import_bitcoin_address_validation.AddressType.p2tr];
1750
+ if (Bip322supportedTypes.includes(addressType)) {
1751
+ const response2 = await window.unisat.signMessage(message, "bip322-simple");
1752
+ return {
1753
+ address,
1754
+ messageHash: "",
1755
+ signature: response2,
1756
+ protocol: "BIP322" /* BIP322 */
1757
+ };
1758
+ }
1759
+ const response = await window.unisat.signMessage(message, "ecdsa");
1760
+ return {
1761
+ address,
1762
+ messageHash: "",
1763
+ signature: response,
1764
+ protocol: "ECDSA" /* ECDSA */
1765
+ };
1766
+ }
1767
+ async sendTransfer(params) {
1768
+ const { recipients } = params;
1769
+ if (recipients.length > 1) {
1770
+ throw new Error("Only one recipient is supported by this wallet provider");
1771
+ }
1772
+ const txid = await window.unisat.sendBitcoin(recipients[0].address, recipients[0].amount);
1773
+ return {
1774
+ txid
1775
+ };
1776
+ }
1777
+ async signPsbt(params) {
1778
+ const { psbt, signInputs, broadcast } = params;
1779
+ const psbtHex = import_buffer.Buffer.from(psbt, "base64").toString("hex");
1780
+ const signedPsbt = await window.unisat.signPsbt(psbtHex, {
1781
+ autoFinalized: broadcast,
1782
+ toSignInputs: convertSignInputsToInputType(signInputs)
1783
+ });
1784
+ if (broadcast) {
1785
+ const txid = await window.unisat.pushPsbt(psbtHex);
1786
+ return {
1787
+ psbt: signedPsbt,
1788
+ txid
1789
+ };
1790
+ }
1791
+ return {
1792
+ psbt: psbtHex
1793
+ };
1794
+ }
1795
+ requestInternal = async (method, params) => {
1796
+ try {
1797
+ switch (method) {
1798
+ case "getAccounts": {
1799
+ const response = await this.getAccounts(
1800
+ params
1801
+ );
1802
+ return {
1803
+ status: "success",
1804
+ result: response
1805
+ };
1806
+ }
1807
+ case "sendTransfer": {
1808
+ const response = await this.sendTransfer(params);
1809
+ return {
1810
+ status: "success",
1811
+ result: response
1812
+ };
1813
+ }
1814
+ case "signMessage": {
1815
+ const response = await this.signMessage(params);
1816
+ return {
1817
+ status: "success",
1818
+ result: response
1819
+ };
1820
+ }
1821
+ case "signPsbt": {
1822
+ const response = await this.signPsbt(params);
1823
+ return {
1824
+ status: "success",
1825
+ result: response
1826
+ };
1827
+ }
1828
+ default: {
1829
+ const error = {
1830
+ code: -32001 /* METHOD_NOT_SUPPORTED */,
1831
+ message: "Method not supported by the selected wallet"
1832
+ };
1833
+ console.error("Error calling the method", error);
1834
+ return {
1835
+ status: "error",
1836
+ error
1837
+ };
1838
+ }
1839
+ }
1840
+ } catch (error) {
1841
+ console.error("Error calling the method", error);
1842
+ return {
1843
+ status: "error",
1844
+ error: {
1845
+ code: error.code === 4001 ? -32e3 /* USER_REJECTION */ : -32603 /* INTERNAL_ERROR */,
1846
+ message: error.message ? error.message : "Wallet method call error",
1847
+ data: error
1848
+ }
1849
+ };
1850
+ }
1851
+ };
1852
+ addListener = (eventName, cb) => {
1853
+ switch (eventName) {
1854
+ case "accountChange": {
1855
+ const handler = () => {
1856
+ cb({ type: "accountChange" });
1857
+ };
1858
+ window.unisat.on("accountsChanged", handler);
1859
+ return () => {
1860
+ window.unisat.removeListener("accountsChanged", handler);
1861
+ };
1862
+ }
1863
+ case "networkChange": {
1864
+ const handler = () => {
1865
+ cb({ type: "networkChange" });
1866
+ };
1867
+ window.unisat.on("networkChanged", handler);
1868
+ return () => {
1869
+ window.unisat.removeListener("networkChanged", handler);
1870
+ };
1871
+ }
1872
+ default: {
1873
+ console.error("Event not supported by the selected wallet");
1874
+ return () => {
1875
+ };
1876
+ }
1877
+ }
1878
+ };
1879
+ };
1880
+
1881
+ // src/adapters/BaseAdapter.ts
1882
+ var BaseAdapter = class extends SatsConnectAdapter {
1883
+ id = "";
1884
+ constructor(providerId) {
1885
+ super();
1886
+ this.id = providerId;
1887
+ }
1888
+ requestInternal = async (method, params) => {
1889
+ return request(method, params, this.id);
1890
+ };
1891
+ addListener = (..._args) => {
1892
+ throw new Error("Method not supported for `BaseAdapter`.");
1893
+ };
1894
+ };
1895
+
1896
+ // src/adapters/index.ts
1897
+ var DefaultAdaptersInfo = {
1898
+ xverse: {
1899
+ id: "XverseProviders.BitcoinProvider",
1900
+ name: "Xverse",
1901
+ webUrl: "https://www.xverse.app/",
1902
+ googlePlayStoreUrl: "https://play.google.com/store/apps/details?id=com.secretkeylabs.xverse",
1903
+ iOSAppStoreUrl: "https://apps.apple.com/app/xverse-bitcoin-web3-wallet/id1552272513",
1904
+ chromeWebStoreUrl: "https://chromewebstore.google.com/detail/xverse-wallet/idnnbdplmphpflfnlkomgpfbpcgelopg",
1905
+ icon: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAyIiBoZWlnaHQ9IjEwMiIgdmlld0JveD0iMCAwIDEwMiAxMDIiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxnIGlkPSJJY29uX0FydCAoRWRpdCBNZSkiPgo8cmVjdCB3aWR0aD0iMTAyIiBoZWlnaHQ9IjEwMiIgZmlsbD0iIzE4MTgxOCIvPgo8ZyBpZD0iTG9nby9FbWJsZW0iIGNsaXAtcGF0aD0idXJsKCNjbGlwMF8yMF8xMjIzKSI+CjxwYXRoIGlkPSJWZWN0b3IiIGQ9Ik03NC42NTQyIDczLjg4ODNWNjUuMjMxMkM3NC42NTQyIDY0Ljg4OCA3NC41MTc3IDY0LjU2MDYgNzQuMjc0NSA2NC4zMTc0TDM3LjQzOTcgMjcuNDgyNUMzNy4xOTY1IDI3LjIzOTIgMzYuODY5MSAyNy4xMDI4IDM2LjUyNTggMjcuMTAyOEgyNy44NjlDMjcuNDQxNiAyNy4xMDI4IDI3LjA5MzggMjcuNDUwNiAyNy4wOTM4IDI3Ljg3OFYzNS45MjExQzI3LjA5MzggMzYuMjY0NCAyNy4yMzAyIDM2LjU5MTcgMjcuNDczNCAzNi44MzVMNDAuNjk1MiA1MC4wNTY3QzQwLjk5NzUgNTAuMzU5MSA0MC45OTc1IDUwLjg1MDEgNDAuNjk1MiA1MS4xNTI0TDI3LjMyMTEgNjQuNTI2NUMyNy4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0Ny43IiBmaWxsPSJ3aGl0ZSIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMzIgMTYpIi8+CjwvY2xpcFBhdGg+CjwvZGVmcz4KPC9zdmc+Cg=="
1912
+ }
1913
+ };
1914
+ var defaultAdapters = {
1915
+ [DefaultAdaptersInfo.xverse.id]: XverseAdapter,
1916
+ [DefaultAdaptersInfo.unisat.id]: UnisatAdapter
1917
+ };
1918
+
1919
+ // src/capabilities/index.ts
1920
+ var import_jsontokens2 = require("jsontokens");
1921
+ var extractOrValidateCapabilities = (provider, reportedCapabilities) => {
1922
+ const validateCapability = (capability) => {
1923
+ if (!provider[capability]) {
1924
+ return false;
1925
+ }
1926
+ if (reportedCapabilities && !reportedCapabilities.has(capability)) {
1927
+ return false;
1928
+ }
1929
+ return true;
1930
+ };
1931
+ const capabilityMap = {
1932
+ request: validateCapability("request"),
1933
+ connect: validateCapability("connect"),
1934
+ signMessage: validateCapability("signMessage"),
1935
+ signTransaction: validateCapability("signTransaction"),
1936
+ sendBtcTransaction: validateCapability("sendBtcTransaction"),
1937
+ createInscription: validateCapability("createInscription"),
1938
+ createRepeatInscriptions: validateCapability("createRepeatInscriptions"),
1939
+ signMultipleTransactions: validateCapability("signMultipleTransactions"),
1940
+ addListener: validateCapability("addListener")
1941
+ };
1942
+ return Object.entries(capabilityMap).reduce((acc, [capability, value]) => {
1943
+ if (value)
1944
+ return [...acc, capability];
1945
+ return acc;
1946
+ }, []);
1947
+ };
1948
+ var getCapabilities = async (options) => {
1949
+ const provider = await getProviderOrThrow(options.getProvider);
1950
+ const request2 = (0, import_jsontokens2.createUnsecuredToken)(options.payload);
1951
+ if (provider.getCapabilities) {
1952
+ try {
1953
+ const response = await provider.getCapabilities(request2);
1954
+ options.onFinish?.(extractOrValidateCapabilities(provider, new Set(response)));
1955
+ } catch (error) {
1956
+ console.error("[Connect] Error during capabilities request", error);
1957
+ }
1958
+ }
1959
+ try {
1960
+ const inferredCapabilities = extractOrValidateCapabilities(provider);
1961
+ options.onFinish?.(inferredCapabilities);
1962
+ } catch (error) {
1963
+ console.error("[Connect] Error during capabilities request", error);
1964
+ options.onCancel?.();
1965
+ }
1966
+ };
1967
+
1968
+ // src/inscriptions/createInscription.ts
1969
+ var import_jsontokens3 = require("jsontokens");
1970
+
1971
+ // src/inscriptions/utils.ts
1972
+ var MAX_CONTENT_LENGTH_MAINNET = 4e5;
1973
+ var MAX_CONTENT_LENGTH_TESTNET = 6e4;
1974
+ var validateInscriptionPayload = (payload) => {
1975
+ const { contentType, content, payloadType, network, appFeeAddress, appFee } = payload;
1976
+ if (!/^[a-z]+\/[a-z0-9\-\.\+]+(?=;.*|$)/.test(contentType)) {
1977
+ throw new Error("Invalid content type detected");
1978
+ }
1979
+ if (!content || content.length === 0) {
1980
+ throw new Error("Empty content not allowed");
1981
+ }
1982
+ if (!payloadType || payloadType !== "BASE_64" && payloadType !== "PLAIN_TEXT") {
1983
+ throw new Error("Empty invalid payloadType specified");
1984
+ }
1985
+ if (content.length > (network.type === "Mainnet" ? MAX_CONTENT_LENGTH_MAINNET : MAX_CONTENT_LENGTH_TESTNET)) {
1986
+ throw new Error("Content too large");
1987
+ }
1988
+ if ((appFeeAddress?.length ?? 0) > 0 && (appFee ?? 0) <= 0) {
1989
+ throw new Error("Invalid combination of app fee address and fee provided");
1990
+ }
1991
+ };
1992
+
1993
+ // src/inscriptions/createInscription.ts
1994
+ var createInscription = async (options) => {
1995
+ const { getProvider } = options;
1996
+ const provider = await getProviderOrThrow(getProvider);
1997
+ validateInscriptionPayload(options.payload);
1998
+ try {
1999
+ const request2 = (0, import_jsontokens3.createUnsecuredToken)(options.payload);
2000
+ const response = await provider.createInscription(request2);
2001
+ options.onFinish?.(response);
2002
+ } catch (error) {
2003
+ console.error("[Connect] Error during create inscription", error);
2004
+ options.onCancel?.();
2005
+ }
2006
+ };
2007
+
2008
+ // src/inscriptions/createRepeatInscriptions.ts
2009
+ var import_jsontokens4 = require("jsontokens");
2010
+ var createRepeatInscriptions = async (options) => {
2011
+ const { getProvider } = options;
2012
+ const provider = await getProviderOrThrow(getProvider);
2013
+ validateInscriptionPayload(options.payload);
2014
+ try {
2015
+ const request2 = (0, import_jsontokens4.createUnsecuredToken)(options.payload);
2016
+ const response = await provider.createRepeatInscriptions(request2);
2017
+ options.onFinish?.(response);
2018
+ } catch (error) {
2019
+ console.error("[Connect] Error during create repeat inscriptions", error);
2020
+ options.onCancel?.();
2021
+ }
2022
+ };
2023
+
2024
+ // src/messages/index.ts
2025
+ var import_jsontokens5 = require("jsontokens");
2026
+ var signMessage = async (options) => {
2027
+ const provider = await getProviderOrThrow(options.getProvider);
2028
+ const { address, message } = options.payload;
2029
+ if (!address) {
2030
+ throw new Error("An address is required to sign a message");
2031
+ }
2032
+ if (!message) {
2033
+ throw new Error("A message to be signed is required");
2034
+ }
2035
+ try {
2036
+ const request2 = (0, import_jsontokens5.createUnsecuredToken)(options.payload);
2037
+ const response = await provider.signMessage(request2);
2038
+ options.onFinish?.(response);
2039
+ } catch (error) {
2040
+ console.error("[Connect] Error during sign message request", error);
2041
+ options.onCancel?.();
2042
+ }
2043
+ };
2044
+
2045
+ // src/transactions/sendBtcTransaction.ts
2046
+ var import_jsontokens6 = require("jsontokens");
2047
+ var serializer = (recipient) => {
2048
+ return recipient.map((value) => {
2049
+ const { address, amountSats } = value;
2050
+ return {
2051
+ address,
2052
+ amountSats: amountSats.toString()
2053
+ };
2054
+ });
2055
+ };
2056
+ var sendBtcTransaction = async (options) => {
2057
+ const provider = await getProviderOrThrow(options.getProvider);
2058
+ const { recipients, senderAddress, network, message } = options.payload;
2059
+ if (!recipients || recipients.length === 0) {
2060
+ throw new Error("At least one recipient is required");
2061
+ }
2062
+ if (recipients.some(
2063
+ (item) => typeof item.address !== "string" || typeof item.amountSats !== "bigint"
2064
+ )) {
2065
+ throw new Error("Incorrect recipient format");
2066
+ }
2067
+ if (!senderAddress) {
2068
+ throw new Error("The sender address is required");
2069
+ }
2070
+ try {
2071
+ const serializedRecipients = serializer(recipients);
2072
+ const serializedPayload = {
2073
+ network,
2074
+ senderAddress,
2075
+ message,
2076
+ recipients: serializedRecipients
2077
+ };
2078
+ const request2 = (0, import_jsontokens6.createUnsecuredToken)(serializedPayload);
2079
+ const response = await provider.sendBtcTransaction(request2);
2080
+ options.onFinish?.(response);
2081
+ } catch (error) {
2082
+ console.error("[Connect] Error during send BTC transaction request", error);
2083
+ options.onCancel?.();
2084
+ }
2085
+ };
2086
+
2087
+ // src/transactions/signTransaction.ts
2088
+ var import_jsontokens7 = require("jsontokens");
2089
+ var signTransaction = async (options) => {
2090
+ const provider = await getProviderOrThrow(options.getProvider);
2091
+ const { psbtBase64, inputsToSign } = options.payload;
2092
+ if (!psbtBase64) {
2093
+ throw new Error("A value for psbtBase64 representing the tx hash is required");
2094
+ }
2095
+ if (!inputsToSign) {
2096
+ throw new Error("An array specifying the inputs to be signed by the wallet is required");
2097
+ }
2098
+ try {
2099
+ const request2 = (0, import_jsontokens7.createUnsecuredToken)(options.payload);
2100
+ const response = await provider.signTransaction(request2);
2101
+ options.onFinish?.(response);
2102
+ } catch (error) {
2103
+ console.error("[Connect] Error during sign transaction request", error);
2104
+ options.onCancel?.();
2105
+ }
2106
+ };
2107
+
2108
+ // src/transactions/signMultipleTransactions.ts
2109
+ var import_jsontokens8 = require("jsontokens");
2110
+ var signMultipleTransactions = async (options) => {
2111
+ const provider = await getProviderOrThrow(options.getProvider);
2112
+ const { psbts } = options.payload;
2113
+ if (!psbts || !psbts.length) {
2114
+ throw new Error("psbts array is required");
2115
+ }
2116
+ if (psbts.length > 100) {
2117
+ throw new Error("psbts array must contain less than 100 psbts");
2118
+ }
2119
+ try {
2120
+ const request2 = (0, import_jsontokens8.createUnsecuredToken)(options.payload);
2121
+ const response = await provider.signMultipleTransactions(request2);
2122
+ options.onFinish?.(response);
2123
+ } catch (error) {
2124
+ console.error("[Connect] Error during sign Multiple transactions request", error);
2125
+ options.onCancel?.();
2126
+ }
2127
+ };
2128
+ // Annotate the CommonJS export names for ESM import in node:
2129
+ 0 && (module.exports = {
2130
+ AddressPurpose,
2131
+ AddressType,
2132
+ BaseAdapter,
2133
+ BitcoinNetworkType,
2134
+ DefaultAdaptersInfo,
2135
+ MessageSigningProtocols,
2136
+ RpcErrorCode,
2137
+ RpcIdSchema,
2138
+ SatsConnectAdapter,
2139
+ accountChangeEventName,
2140
+ accountChangeSchema,
2141
+ addListener,
2142
+ addressSchema,
2143
+ connectMethodName,
2144
+ connectParamsSchema,
2145
+ connectRequestMessageSchema,
2146
+ connectResultSchema,
2147
+ createInscription,
2148
+ createRepeatInscriptions,
2149
+ defaultAdapters,
2150
+ disconnectEventName,
2151
+ disconnectMethodName,
2152
+ disconnectParamsSchema,
2153
+ disconnectRequestMessageSchema,
2154
+ disconnectResultSchema,
2155
+ disconnectSchema,
2156
+ getAccountMethodName,
2157
+ getAccountParamsSchema,
2158
+ getAccountRequestMessageSchema,
2159
+ getAccountResultSchema,
2160
+ getAccountsMethodName,
2161
+ getAccountsParamsSchema,
2162
+ getAccountsRequestMessageSchema,
2163
+ getAccountsResultSchema,
2164
+ getAddress,
2165
+ getAddressesMethodName,
2166
+ getAddressesParamsSchema,
2167
+ getAddressesRequestMessageSchema,
2168
+ getAddressesResultSchema,
2169
+ getBalanceMethodName,
2170
+ getBalanceParamsSchema,
2171
+ getBalanceRequestMessageSchema,
2172
+ getBalanceResultSchema,
2173
+ getCapabilities,
2174
+ getCurrentPermissionsMethodName,
2175
+ getCurrentPermissionsParamsSchema,
2176
+ getCurrentPermissionsRequestMessageSchema,
2177
+ getCurrentPermissionsResultSchema,
2178
+ getDefaultProvider,
2179
+ getInfoMethodName,
2180
+ getInfoParamsSchema,
2181
+ getInfoRequestMessageSchema,
2182
+ getInfoResultSchema,
2183
+ getInscriptionsMethodName,
2184
+ getInscriptionsParamsSchema,
2185
+ getInscriptionsRequestMessageSchema,
2186
+ getInscriptionsResultSchema,
2187
+ getProviderById,
2188
+ getProviderOrThrow,
2189
+ getProviders,
2190
+ getSupportedWallets,
2191
+ getWalletTypeMethodName,
2192
+ getWalletTypeParamsSchema,
2193
+ getWalletTypeRequestMessageSchema,
2194
+ getWalletTypeResultSchema,
2195
+ isProviderInstalled,
2196
+ networkChangeEventName,
2197
+ networkChangeSchema,
2198
+ permissionTemplate,
2199
+ removeDefaultProvider,
2200
+ renouncePermissionsMethodName,
2201
+ renouncePermissionsParamsSchema,
2202
+ renouncePermissionsRequestMessageSchema,
2203
+ renouncePermissionsResultSchema,
2204
+ request,
2205
+ requestPermissionsMethodName,
2206
+ requestPermissionsParamsSchema,
2207
+ requestPermissionsRequestMessageSchema,
2208
+ requestPermissionsResultSchema,
2209
+ rpcErrorResponseMessageSchema,
2210
+ rpcRequestMessageSchema,
2211
+ rpcResponseMessageSchema,
2212
+ rpcSuccessResponseMessageSchema,
2213
+ runesEtchMethodName,
2214
+ runesEtchParamsSchema,
2215
+ runesEtchRequestMessageSchema,
2216
+ runesEtchResultSchema,
2217
+ runesGetBalanceMethodName,
2218
+ runesGetBalanceParamsSchema,
2219
+ runesGetBalanceRequestMessageSchema,
2220
+ runesGetBalanceResultSchema,
2221
+ runesMintMethodName,
2222
+ runesMintParamsSchema,
2223
+ runesMintRequestMessageSchema,
2224
+ runesMintResultSchema,
2225
+ runesTransferMethodName,
2226
+ runesTransferParamsSchema,
2227
+ runesTransferRequestMessageSchema,
2228
+ runesTransferResultSchema,
2229
+ sendBtcTransaction,
2230
+ sendInscriptionsMethodName,
2231
+ sendInscriptionsParamsSchema,
2232
+ sendInscriptionsRequestMessageSchema,
2233
+ sendInscriptionsResultSchema,
2234
+ sendTransferMethodName,
2235
+ sendTransferParamsSchema,
2236
+ sendTransferRequestMessageSchema,
2237
+ sendTransferResultSchema,
2238
+ setDefaultProvider,
2239
+ signMessage,
2240
+ signMessageMethodName,
2241
+ signMessageParamsSchema,
2242
+ signMessageRequestMessageSchema,
2243
+ signMessageResultSchema,
2244
+ signMultipleTransactions,
2245
+ signPsbtMethodName,
2246
+ signPsbtParamsSchema,
2247
+ signPsbtRequestMessageSchema,
2248
+ signPsbtResultSchema,
2249
+ signTransaction,
2250
+ stxCallContractMethodName,
2251
+ stxCallContractParamsSchema,
2252
+ stxCallContractRequestMessageSchema,
2253
+ stxCallContractResultSchema,
2254
+ stxDeployContractMethodName,
2255
+ stxDeployContractParamsSchema,
2256
+ stxDeployContractRequestMessageSchema,
2257
+ stxDeployContractResultSchema,
2258
+ stxGetAccountsMethodName,
2259
+ stxGetAccountsParamsSchema,
2260
+ stxGetAccountsRequestMessageSchema,
2261
+ stxGetAccountsResultSchema,
2262
+ stxGetAddressesMethodName,
2263
+ stxGetAddressesParamsSchema,
2264
+ stxGetAddressesRequestMessageSchema,
2265
+ stxGetAddressesResultSchema,
2266
+ stxSignMessageMethodName,
2267
+ stxSignMessageParamsSchema,
2268
+ stxSignMessageRequestMessageSchema,
2269
+ stxSignMessageResultSchema,
2270
+ stxSignStructuredMessageMethodName,
2271
+ stxSignStructuredMessageParamsSchema,
2272
+ stxSignStructuredMessageRequestMessageSchema,
2273
+ stxSignStructuredMessageResultSchema,
2274
+ stxSignTransactionMethodName,
2275
+ stxSignTransactionParamsSchema,
2276
+ stxSignTransactionRequestMessageSchema,
2277
+ stxSignTransactionResultSchema,
2278
+ stxTransferStxMethodName,
2279
+ stxTransferStxParamsSchema,
2280
+ stxTransferStxRequestMessageSchema,
2281
+ stxTransferStxResultSchema,
2282
+ walletEventSchema,
2283
+ walletTypeSchema,
2284
+ walletTypes
2285
+ });