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

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