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

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