@sats-connect/core 0.8.1-b5b5706 → 0.8.1-d85ba2a

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.mjs CHANGED
@@ -1,5 +1,64 @@
1
- // src/types.ts
1
+ // src/provider/types.ts
2
+ import * as v4 from "valibot";
3
+
4
+ // src/addresses/index.ts
5
+ import { createUnsecuredToken } from "jsontokens";
6
+
7
+ // src/addresses/types.ts
8
+ import * as v2 from "valibot";
9
+
10
+ // src/request/types/common.ts
2
11
  import * as v from "valibot";
12
+ var walletTypes = ["software", "ledger", "keystone"];
13
+ var walletTypeSchema = v.picklist(walletTypes);
14
+
15
+ // src/addresses/types.ts
16
+ var AddressPurpose = /* @__PURE__ */ ((AddressPurpose2) => {
17
+ AddressPurpose2["Ordinals"] = "ordinals";
18
+ AddressPurpose2["Payment"] = "payment";
19
+ AddressPurpose2["Stacks"] = "stacks";
20
+ AddressPurpose2["Starknet"] = "starknet";
21
+ AddressPurpose2["Spark"] = "spark";
22
+ return AddressPurpose2;
23
+ })(AddressPurpose || {});
24
+ var AddressType = /* @__PURE__ */ ((AddressType3) => {
25
+ AddressType3["p2pkh"] = "p2pkh";
26
+ AddressType3["p2sh"] = "p2sh";
27
+ AddressType3["p2wpkh"] = "p2wpkh";
28
+ AddressType3["p2wsh"] = "p2wsh";
29
+ AddressType3["p2tr"] = "p2tr";
30
+ AddressType3["stacks"] = "stacks";
31
+ AddressType3["starknet"] = "starknet";
32
+ AddressType3["spark"] = "spark";
33
+ return AddressType3;
34
+ })(AddressType || {});
35
+ var addressSchema = v2.object({
36
+ address: v2.string(),
37
+ publicKey: v2.string(),
38
+ purpose: v2.enum(AddressPurpose),
39
+ addressType: v2.enum(AddressType),
40
+ walletType: walletTypeSchema
41
+ });
42
+
43
+ // src/addresses/index.ts
44
+ var getAddress = async (options) => {
45
+ const provider = await getProviderOrThrow(options.getProvider);
46
+ const { purposes } = options.payload;
47
+ if (!purposes) {
48
+ throw new Error("Address purposes are required");
49
+ }
50
+ try {
51
+ const request2 = createUnsecuredToken(options.payload);
52
+ const response = await provider.connect(request2);
53
+ options.onFinish?.(response);
54
+ } catch (error) {
55
+ console.error("[Connect] Error during address request", error);
56
+ options.onCancel?.();
57
+ }
58
+ };
59
+
60
+ // src/types.ts
61
+ import * as v3 from "valibot";
3
62
  var BitcoinNetworkType = /* @__PURE__ */ ((BitcoinNetworkType2) => {
4
63
  BitcoinNetworkType2["Mainnet"] = "Mainnet";
5
64
  BitcoinNetworkType2["Testnet"] = "Testnet";
@@ -23,22 +82,22 @@ var SparkNetworkType = /* @__PURE__ */ ((SparkNetworkType2) => {
23
82
  SparkNetworkType2["Regtest"] = "regtest";
24
83
  return SparkNetworkType2;
25
84
  })(SparkNetworkType || {});
26
- var RpcIdSchema = v.optional(v.union([v.string(), v.number(), v.null()]));
27
- var rpcRequestMessageSchema = v.object({
28
- jsonrpc: v.literal("2.0"),
29
- method: v.string(),
30
- params: v.optional(
31
- v.union([
32
- v.array(v.unknown()),
33
- v.looseObject({}),
85
+ var RpcIdSchema = v3.optional(v3.union([v3.string(), v3.number(), v3.null()]));
86
+ var rpcRequestMessageSchema = v3.object({
87
+ jsonrpc: v3.literal("2.0"),
88
+ method: v3.string(),
89
+ params: v3.optional(
90
+ v3.union([
91
+ v3.array(v3.unknown()),
92
+ v3.looseObject({}),
34
93
  // Note: This is to support current incorrect usage of RPC 2.0. Params need
35
94
  // to be either an array or an object when provided. Changing this now would
36
95
  // be a breaking change, so accepting null values for now. Tracking in
37
96
  // https://linear.app/xverseapp/issue/ENG-4538.
38
- v.null()
97
+ v3.null()
39
98
  ])
40
99
  ),
41
- id: v.unwrap(RpcIdSchema)
100
+ id: v3.unwrap(RpcIdSchema)
42
101
  });
43
102
  var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
44
103
  RpcErrorCode2[RpcErrorCode2["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
@@ -51,647 +110,89 @@ var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
51
110
  RpcErrorCode2[RpcErrorCode2["ACCESS_DENIED"] = -32002] = "ACCESS_DENIED";
52
111
  return RpcErrorCode2;
53
112
  })(RpcErrorCode || {});
54
- var rpcSuccessResponseMessageSchema = v.object({
55
- jsonrpc: v.literal("2.0"),
56
- result: v.nonOptional(v.unknown()),
113
+ var rpcSuccessResponseMessageSchema = v3.object({
114
+ jsonrpc: v3.literal("2.0"),
115
+ result: v3.nonOptional(v3.unknown()),
57
116
  id: RpcIdSchema
58
117
  });
59
- var rpcErrorResponseMessageSchema = v.object({
60
- jsonrpc: v.literal("2.0"),
61
- error: v.nonOptional(v.unknown()),
118
+ var rpcErrorResponseMessageSchema = v3.object({
119
+ jsonrpc: v3.literal("2.0"),
120
+ error: v3.nonOptional(v3.unknown()),
62
121
  id: RpcIdSchema
63
122
  });
64
- var rpcResponseMessageSchema = v.union([
123
+ var rpcResponseMessageSchema = v3.union([
65
124
  rpcSuccessResponseMessageSchema,
66
125
  rpcErrorResponseMessageSchema
67
126
  ]);
68
127
 
69
- // src/runes/api.ts
70
- import axios from "axios";
71
- var urlNetworkSuffix = {
72
- ["Mainnet" /* Mainnet */]: "",
73
- ["Testnet" /* Testnet */]: "-testnet",
74
- ["Testnet4" /* Testnet4 */]: "-testnet4",
75
- ["Signet" /* Signet */]: "-signet"
76
- };
77
- var ORDINALS_API_BASE_URL = (network = "Mainnet" /* Mainnet */) => {
78
- if (network === "Regtest" /* Regtest */) {
79
- throw new Error(`Ordinals API does not support ${network} network`);
80
- }
81
- return `https://ordinals${urlNetworkSuffix[network]}.xverse.app/v1`;
82
- };
83
- var RunesApi = class {
84
- client;
85
- constructor(network) {
86
- this.client = axios.create({
87
- baseURL: ORDINALS_API_BASE_URL(network)
88
- });
128
+ // src/provider/types.ts
129
+ var accountChangeEventName = "accountChange";
130
+ var accountChangeSchema = v4.object({
131
+ type: v4.literal(accountChangeEventName),
132
+ addresses: v4.optional(v4.array(addressSchema))
133
+ });
134
+ var networkChangeEventName = "networkChange";
135
+ var networkChangeSchema = v4.object({
136
+ type: v4.literal(networkChangeEventName),
137
+ bitcoin: v4.object({
138
+ name: v4.enum(BitcoinNetworkType)
139
+ }),
140
+ stacks: v4.object({
141
+ name: v4.string()
142
+ }),
143
+ addresses: v4.optional(v4.array(addressSchema))
144
+ });
145
+ var disconnectEventName = "disconnect";
146
+ var disconnectSchema = v4.object({
147
+ type: v4.literal(disconnectEventName)
148
+ });
149
+ var walletEventSchema = v4.variant("type", [
150
+ accountChangeSchema,
151
+ networkChangeSchema,
152
+ disconnectSchema
153
+ ]);
154
+
155
+ // src/provider/index.ts
156
+ async function getProviderOrThrow(getProvider) {
157
+ const provider = await getProvider?.() || window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
158
+ if (!provider) {
159
+ throw new Error("No Bitcoin wallet installed");
89
160
  }
90
- parseError = (error) => {
91
- return {
92
- code: error.response?.status,
93
- message: JSON.stringify(error.response?.data)
94
- };
95
- };
96
- estimateMintCost = async (mintParams) => {
97
- try {
98
- const response = await this.client.post("/runes/mint/estimate", {
99
- ...mintParams
100
- });
101
- return {
102
- data: response.data
103
- };
104
- } catch (error) {
105
- const err = error;
106
- return {
107
- error: this.parseError(err)
108
- };
109
- }
110
- };
111
- estimateEtchCost = async (etchParams) => {
112
- try {
113
- const response = await this.client.post("/runes/etch/estimate", {
114
- ...etchParams
115
- });
116
- return {
117
- data: response.data
118
- };
119
- } catch (error) {
120
- const err = error;
121
- return {
122
- error: this.parseError(err)
123
- };
124
- }
125
- };
126
- createMintOrder = async (mintOrderParams) => {
127
- try {
128
- const response = await this.client.post("/runes/mint/orders", {
129
- ...mintOrderParams
130
- });
131
- return {
132
- data: response.data
133
- };
134
- } catch (error) {
135
- const err = error;
136
- return {
137
- error: this.parseError(err)
138
- };
139
- }
140
- };
141
- createEtchOrder = async (etchOrderParams) => {
142
- try {
143
- const response = await this.client.post("/runes/etch/orders", {
144
- ...etchOrderParams
145
- });
146
- return {
147
- data: response.data
148
- };
149
- } catch (error) {
150
- const err = error;
151
- return {
152
- error: this.parseError(err)
153
- };
154
- }
155
- };
156
- executeMint = async (orderId, fundTransactionId) => {
157
- try {
158
- const response = await this.client.post(`/runes/mint/orders/${orderId}/execute`, {
159
- fundTransactionId
160
- });
161
- return {
162
- data: response.data
163
- };
164
- } catch (error) {
165
- const err = error;
166
- return {
167
- error: this.parseError(err)
168
- };
169
- }
170
- };
171
- executeEtch = async (orderId, fundTransactionId) => {
172
- try {
173
- const response = await this.client.post(`/runes/etch/orders/${orderId}/execute`, {
174
- fundTransactionId
175
- });
176
- return {
177
- data: response.data
178
- };
179
- } catch (error) {
180
- const err = error;
181
- return {
182
- error: this.parseError(err)
183
- };
184
- }
185
- };
186
- getOrder = async (orderId) => {
187
- try {
188
- const response = await this.client.get(`/orders/${orderId}`);
189
- return {
190
- data: response.data
191
- };
192
- } catch (error) {
193
- const err = error;
194
- return {
195
- error: this.parseError(err)
196
- };
197
- }
198
- };
199
- rbfOrder = async (rbfRequest) => {
200
- const { orderId, newFeeRate } = rbfRequest;
201
- try {
202
- const response = await this.client.post(`/orders/${orderId}/rbf-estimate`, {
203
- newFeeRate
204
- });
205
- return {
206
- data: response.data
207
- };
208
- } catch (error) {
209
- const err = error;
161
+ return provider;
162
+ }
163
+ function getProviders() {
164
+ if (!window.btc_providers) window.btc_providers = [];
165
+ return window.btc_providers;
166
+ }
167
+ function getProviderById(providerId) {
168
+ return providerId?.split(".").reduce((acc, part) => acc?.[part], window);
169
+ }
170
+ function isProviderInstalled(providerId) {
171
+ return !!getProviderById(providerId);
172
+ }
173
+ function setDefaultProvider(providerId) {
174
+ localStorage.setItem("sats-connect_defaultProvider", providerId);
175
+ }
176
+ function getDefaultProvider() {
177
+ return localStorage.getItem("sats-connect_defaultProvider");
178
+ }
179
+ function removeDefaultProvider() {
180
+ localStorage.removeItem("sats-connect_defaultProvider");
181
+ }
182
+ function getSupportedWallets() {
183
+ const wallets = Object.values(DefaultAdaptersInfo).map((provider) => {
184
+ {
210
185
  return {
211
- error: this.parseError(err)
212
- };
213
- }
214
- };
215
- };
216
- var clients = {};
217
- var getRunesApiClient = (network = "Mainnet" /* Mainnet */) => {
218
- if (!clients[network]) {
219
- clients[network] = new RunesApi(network);
220
- }
221
- return clients[network];
222
- };
223
-
224
- // src/adapters/satsConnectAdapter.ts
225
- var SatsConnectAdapter = class {
226
- async mintRunes(params) {
227
- try {
228
- const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
229
- if (walletInfo && walletInfo.status === "success") {
230
- const isMintSupported = walletInfo.result.methods?.includes("runes_mint");
231
- if (isMintSupported) {
232
- const response = await this.requestInternal("runes_mint", params);
233
- if (response) {
234
- if (response.status === "success") {
235
- return response;
236
- }
237
- if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
238
- return response;
239
- }
240
- }
241
- }
242
- }
243
- const mintRequest = {
244
- destinationAddress: params.destinationAddress,
245
- feeRate: params.feeRate,
246
- refundAddress: params.refundAddress,
247
- repeats: params.repeats,
248
- runeName: params.runeName,
249
- appServiceFee: params.appServiceFee,
250
- appServiceFeeAddress: params.appServiceFeeAddress
251
- };
252
- const orderResponse = await new RunesApi(params.network).createMintOrder(mintRequest);
253
- if (!orderResponse.data) {
254
- return {
255
- status: "error",
256
- error: {
257
- code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
258
- message: orderResponse.error.message
259
- }
260
- };
261
- }
262
- const paymentResponse = await this.requestInternal("sendTransfer", {
263
- recipients: [
264
- {
265
- address: orderResponse.data.fundAddress,
266
- amount: orderResponse.data.fundAmount
267
- }
268
- ]
269
- });
270
- if (paymentResponse.status !== "success") {
271
- return paymentResponse;
272
- }
273
- await new RunesApi(params.network).executeMint(
274
- orderResponse.data.orderId,
275
- paymentResponse.result.txid
276
- );
277
- return {
278
- status: "success",
279
- result: {
280
- orderId: orderResponse.data.orderId,
281
- fundTransactionId: paymentResponse.result.txid,
282
- fundingAddress: orderResponse.data.fundAddress
283
- }
284
- };
285
- } catch (error) {
286
- return {
287
- status: "error",
288
- error: {
289
- code: -32603 /* INTERNAL_ERROR */,
290
- message: error.message
291
- }
292
- };
293
- }
294
- }
295
- async etchRunes(params) {
296
- const etchRequest = {
297
- destinationAddress: params.destinationAddress,
298
- refundAddress: params.refundAddress,
299
- feeRate: params.feeRate,
300
- runeName: params.runeName,
301
- divisibility: params.divisibility,
302
- symbol: params.symbol,
303
- premine: params.premine,
304
- isMintable: params.isMintable,
305
- terms: params.terms,
306
- inscriptionDetails: params.inscriptionDetails,
307
- delegateInscriptionId: params.delegateInscriptionId,
308
- appServiceFee: params.appServiceFee,
309
- appServiceFeeAddress: params.appServiceFeeAddress
310
- };
311
- try {
312
- const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
313
- if (walletInfo && walletInfo.status === "success") {
314
- const isEtchSupported = walletInfo.result.methods?.includes("runes_etch");
315
- if (isEtchSupported) {
316
- const response = await this.requestInternal("runes_etch", params);
317
- if (response) {
318
- if (response.status === "success") {
319
- return response;
320
- }
321
- if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
322
- return response;
323
- }
324
- }
325
- }
326
- }
327
- const orderResponse = await new RunesApi(params.network).createEtchOrder(etchRequest);
328
- if (!orderResponse.data) {
329
- return {
330
- status: "error",
331
- error: {
332
- code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
333
- message: orderResponse.error.message
334
- }
335
- };
336
- }
337
- const paymentResponse = await this.requestInternal("sendTransfer", {
338
- recipients: [
339
- {
340
- address: orderResponse.data.fundAddress,
341
- amount: orderResponse.data.fundAmount
342
- }
343
- ]
344
- });
345
- if (paymentResponse.status !== "success") {
346
- return paymentResponse;
347
- }
348
- await new RunesApi(params.network).executeEtch(
349
- orderResponse.data.orderId,
350
- paymentResponse.result.txid
351
- );
352
- return {
353
- status: "success",
354
- result: {
355
- orderId: orderResponse.data.orderId,
356
- fundTransactionId: paymentResponse.result.txid,
357
- fundingAddress: orderResponse.data.fundAddress
358
- }
359
- };
360
- } catch (error) {
361
- return {
362
- status: "error",
363
- error: {
364
- code: -32603 /* INTERNAL_ERROR */,
365
- message: error.message
366
- }
367
- };
368
- }
369
- }
370
- async estimateMint(params) {
371
- const estimateMintRequest = {
372
- destinationAddress: params.destinationAddress,
373
- feeRate: params.feeRate,
374
- repeats: params.repeats,
375
- runeName: params.runeName,
376
- appServiceFee: params.appServiceFee,
377
- appServiceFeeAddress: params.appServiceFeeAddress
378
- };
379
- const response = await getRunesApiClient(
380
- params.network
381
- ).estimateMintCost(estimateMintRequest);
382
- if (response.data) {
383
- return {
384
- status: "success",
385
- result: response.data
386
- };
387
- }
388
- return {
389
- status: "error",
390
- error: {
391
- code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
392
- message: response.error.message
393
- }
394
- };
395
- }
396
- async estimateEtch(params) {
397
- const estimateEtchRequest = {
398
- destinationAddress: params.destinationAddress,
399
- feeRate: params.feeRate,
400
- runeName: params.runeName,
401
- divisibility: params.divisibility,
402
- symbol: params.symbol,
403
- premine: params.premine,
404
- isMintable: params.isMintable,
405
- terms: params.terms,
406
- inscriptionDetails: params.inscriptionDetails,
407
- delegateInscriptionId: params.delegateInscriptionId,
408
- appServiceFee: params.appServiceFee,
409
- appServiceFeeAddress: params.appServiceFeeAddress
410
- };
411
- const response = await getRunesApiClient(params.network).estimateEtchCost(estimateEtchRequest);
412
- if (response.data) {
413
- return {
414
- status: "success",
415
- result: response.data
416
- };
417
- }
418
- return {
419
- status: "error",
420
- error: {
421
- code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
422
- message: response.error.message
423
- }
424
- };
425
- }
426
- async getOrder(params) {
427
- const response = await getRunesApiClient(params.network).getOrder(params.id);
428
- if (response.data) {
429
- return {
430
- status: "success",
431
- result: response.data
432
- };
433
- }
434
- return {
435
- status: "error",
436
- error: {
437
- code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
438
- message: response.error.message
439
- }
440
- };
441
- }
442
- async estimateRbfOrder(params) {
443
- const rbfOrderRequest = {
444
- newFeeRate: params.newFeeRate,
445
- orderId: params.orderId
446
- };
447
- const response = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
448
- if (response.data) {
449
- return {
450
- status: "success",
451
- result: {
452
- fundingAddress: response.data.fundingAddress,
453
- rbfCost: response.data.rbfCost
454
- }
455
- };
456
- }
457
- return {
458
- status: "error",
459
- error: {
460
- code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
461
- message: response.error.message
462
- }
463
- };
464
- }
465
- async rbfOrder(params) {
466
- try {
467
- const rbfOrderRequest = {
468
- newFeeRate: params.newFeeRate,
469
- orderId: params.orderId
470
- };
471
- const orderResponse = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
472
- if (!orderResponse.data) {
473
- return {
474
- status: "error",
475
- error: {
476
- code: orderResponse.error.code === 400 || orderResponse.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
477
- message: orderResponse.error.message
478
- }
479
- };
480
- }
481
- const paymentResponse = await this.requestInternal("sendTransfer", {
482
- recipients: [
483
- {
484
- address: orderResponse.data.fundingAddress,
485
- amount: orderResponse.data.rbfCost
486
- }
487
- ]
488
- });
489
- if (paymentResponse.status !== "success") {
490
- return paymentResponse;
491
- }
492
- return {
493
- status: "success",
494
- result: {
495
- fundingAddress: orderResponse.data.fundingAddress,
496
- orderId: rbfOrderRequest.orderId,
497
- fundRBFTransactionId: paymentResponse.result.txid
498
- }
499
- };
500
- } catch (error) {
501
- return {
502
- status: "error",
503
- error: {
504
- code: -32603 /* INTERNAL_ERROR */,
505
- message: error.message
506
- }
507
- };
508
- }
509
- }
510
- async request(method, params) {
511
- switch (method) {
512
- case "runes_mint":
513
- return this.mintRunes(params);
514
- case "runes_etch":
515
- return this.etchRunes(params);
516
- case "runes_estimateMint":
517
- return this.estimateMint(params);
518
- case "runes_estimateEtch":
519
- return this.estimateEtch(params);
520
- case "runes_getOrder": {
521
- return this.getOrder(params);
522
- }
523
- case "runes_estimateRbfOrder": {
524
- return this.estimateRbfOrder(params);
525
- }
526
- case "runes_rbfOrder": {
527
- return this.rbfOrder(params);
528
- }
529
- default:
530
- return this.requestInternal(method, params);
531
- }
532
- }
533
- };
534
-
535
- // src/provider/types.ts
536
- import * as v4 from "valibot";
537
-
538
- // src/addresses/index.ts
539
- import { createUnsecuredToken } from "jsontokens";
540
-
541
- // src/addresses/types.ts
542
- import * as v3 from "valibot";
543
-
544
- // src/request/types/common.ts
545
- import * as v2 from "valibot";
546
- var walletTypes = ["software", "ledger", "keystone"];
547
- var walletTypeSchema = v2.picklist(walletTypes);
548
-
549
- // src/addresses/types.ts
550
- var AddressPurpose = /* @__PURE__ */ ((AddressPurpose2) => {
551
- AddressPurpose2["Ordinals"] = "ordinals";
552
- AddressPurpose2["Payment"] = "payment";
553
- AddressPurpose2["Stacks"] = "stacks";
554
- AddressPurpose2["Starknet"] = "starknet";
555
- AddressPurpose2["Spark"] = "spark";
556
- return AddressPurpose2;
557
- })(AddressPurpose || {});
558
- var AddressType = /* @__PURE__ */ ((AddressType3) => {
559
- AddressType3["p2pkh"] = "p2pkh";
560
- AddressType3["p2sh"] = "p2sh";
561
- AddressType3["p2wpkh"] = "p2wpkh";
562
- AddressType3["p2wsh"] = "p2wsh";
563
- AddressType3["p2tr"] = "p2tr";
564
- AddressType3["stacks"] = "stacks";
565
- AddressType3["starknet"] = "starknet";
566
- AddressType3["spark"] = "spark";
567
- return AddressType3;
568
- })(AddressType || {});
569
- var addressSchema = v3.object({
570
- address: v3.string(),
571
- publicKey: v3.string(),
572
- purpose: v3.enum(AddressPurpose),
573
- addressType: v3.enum(AddressType),
574
- walletType: walletTypeSchema
575
- });
576
-
577
- // src/addresses/index.ts
578
- var getAddress = async (options) => {
579
- const provider = await getProviderOrThrow(options.getProvider);
580
- const { purposes } = options.payload;
581
- if (!purposes) {
582
- throw new Error("Address purposes are required");
583
- }
584
- try {
585
- const request2 = createUnsecuredToken(options.payload);
586
- const response = await provider.connect(request2);
587
- options.onFinish?.(response);
588
- } catch (error) {
589
- console.error("[Connect] Error during address request", error);
590
- options.onCancel?.();
591
- }
592
- };
593
-
594
- // src/provider/types.ts
595
- var accountChangeEventName = "accountChange";
596
- var accountChangeSchema = v4.object({
597
- type: v4.literal(accountChangeEventName),
598
- addresses: v4.optional(v4.array(addressSchema))
599
- });
600
- var networkChangeEventName = "networkChange";
601
- var networkChangeSchema = v4.object({
602
- type: v4.literal(networkChangeEventName),
603
- bitcoin: v4.object({
604
- name: v4.enum(BitcoinNetworkType)
605
- }),
606
- stacks: v4.object({
607
- name: v4.string()
608
- }),
609
- addresses: v4.optional(v4.array(addressSchema))
610
- });
611
- var disconnectEventName = "disconnect";
612
- var disconnectSchema = v4.object({
613
- type: v4.literal(disconnectEventName)
614
- });
615
- var walletEventSchema = v4.variant("type", [
616
- accountChangeSchema,
617
- networkChangeSchema,
618
- disconnectSchema
619
- ]);
620
-
621
- // src/provider/index.ts
622
- async function getProviderOrThrow(getProvider) {
623
- const provider = await getProvider?.() || window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
624
- if (!provider) {
625
- throw new Error("No Bitcoin wallet installed");
626
- }
627
- return provider;
628
- }
629
- function getProviders() {
630
- if (!window.btc_providers) window.btc_providers = [];
631
- return window.btc_providers;
632
- }
633
- function getProviderById(providerId) {
634
- return providerId?.split(".").reduce((acc, part) => acc?.[part], window);
635
- }
636
- function isProviderInstalled(providerId) {
637
- return !!getProviderById(providerId);
638
- }
639
- function setDefaultProvider(providerId) {
640
- localStorage.setItem("sats-connect_defaultProvider", providerId);
641
- }
642
- function getDefaultProvider() {
643
- return localStorage.getItem("sats-connect_defaultProvider");
644
- }
645
- function removeDefaultProvider() {
646
- localStorage.removeItem("sats-connect_defaultProvider");
647
- }
648
- function getSupportedWallets() {
649
- const wallets = Object.values(DefaultAdaptersInfo).map((provider) => {
650
- {
651
- return {
652
- ...provider,
653
- isInstalled: isProviderInstalled(provider.id)
186
+ ...provider,
187
+ isInstalled: isProviderInstalled(provider.id)
654
188
  };
655
189
  }
656
190
  });
657
191
  return wallets;
658
192
  }
659
193
 
660
- // src/adapters/fordefi.ts
661
- var FordefiAdapter = class extends SatsConnectAdapter {
662
- id = DefaultAdaptersInfo.fordefi.id;
663
- requestInternal = async (method, params) => {
664
- const provider = getProviderById(this.id);
665
- if (!provider) {
666
- throw new Error("no wallet provider was found");
667
- }
668
- if (!method) {
669
- throw new Error("A wallet method is required");
670
- }
671
- return await provider.request(method, params);
672
- };
673
- addListener = ({ eventName, cb }) => {
674
- const provider = getProviderById(this.id);
675
- if (!provider) {
676
- throw new Error("no wallet provider was found");
677
- }
678
- if (!provider.addListener) {
679
- console.error(
680
- `The wallet provider you are using does not support the addListener method. Please update your wallet provider.`
681
- );
682
- return () => {
683
- };
684
- }
685
- return provider.addListener(eventName, cb);
686
- };
687
- };
688
-
689
- // src/adapters/unisat.ts
690
- import { AddressType as AddressType2, getAddressInfo } from "bitcoin-address-validation";
691
- import { Buffer } from "buffer";
692
-
693
194
  // src/request/index.ts
694
- import * as v25 from "valibot";
195
+ import * as v35 from "valibot";
695
196
 
696
197
  // src/request/types/btcMethods.ts
697
198
  import * as v6 from "valibot";
@@ -910,11 +411,6 @@ var addNetworkResultSchema = v5.object({
910
411
  });
911
412
 
912
413
  // src/request/types/btcMethods.ts
913
- var ProviderPlatform = /* @__PURE__ */ ((ProviderPlatform2) => {
914
- ProviderPlatform2["Web"] = "web";
915
- ProviderPlatform2["Mobile"] = "mobile";
916
- return ProviderPlatform2;
917
- })(ProviderPlatform || {});
918
414
  var getInfoMethodName = "getInfo";
919
415
  var getInfoParamsSchema = v6.nullish(v6.null());
920
416
  var getInfoResultSchema = v6.object({
@@ -922,10 +418,6 @@ var getInfoResultSchema = v6.object({
922
418
  * Version of the wallet.
923
419
  */
924
420
  version: v6.string(),
925
- /**
926
- * The platform the wallet is running on (web or mobile).
927
- */
928
- platform: v6.optional(v6.enum(ProviderPlatform)),
929
421
  /**
930
422
  * [WBIP](https://wbips.netlify.app/wbips/WBIP002) methods supported by the wallet.
931
423
  */
@@ -1313,10 +805,10 @@ var runesTransferRequestMessageSchema = v11.object({
1313
805
  }).entries
1314
806
  });
1315
807
 
1316
- // src/request/types/sparkMethods/getAddresses.ts
808
+ // src/request/types/sparkMethods/flashnetMethods/getJwt.ts
1317
809
  import * as v12 from "valibot";
1318
- var sparkGetAddressesMethodName = "spark_getAddresses";
1319
- var sparkGetAddressesParamsSchema = v12.nullish(
810
+ var sparkFlashnetGetJwtMethodName = "spark_flashnet_getJwt";
811
+ var sparkFlashnetGetJwtParamsSchema = v12.nullish(
1320
812
  v12.object({
1321
813
  /**
1322
814
  * A message to be displayed to the user in the request prompt.
@@ -1324,135 +816,315 @@ var sparkGetAddressesParamsSchema = v12.nullish(
1324
816
  message: v12.optional(v12.string())
1325
817
  })
1326
818
  );
1327
- var sparkGetAddressesResultSchema = v12.object({
819
+ var sparkFlashnetGetJwtResultSchema = v12.object({
820
+ /**
821
+ * The JWT token for authenticated requests to the Flashnet API.
822
+ */
823
+ jwt: v12.string()
824
+ });
825
+ var sparkFlashnetGetJwtRequestMessageSchema = v12.object({
826
+ ...rpcRequestMessageSchema.entries,
827
+ ...v12.object({
828
+ method: v12.literal(sparkFlashnetGetJwtMethodName),
829
+ params: sparkFlashnetGetJwtParamsSchema,
830
+ id: v12.string()
831
+ }).entries
832
+ });
833
+
834
+ // src/request/types/sparkMethods/flashnetMethods/intents/addLiquidity.ts
835
+ import * as v13 from "valibot";
836
+ var sparkFlashnetAddLiquidityIntentSchema = v13.object({
837
+ type: v13.literal("addLiquidity"),
838
+ data: v13.object({
839
+ userPublicKey: v13.string(),
840
+ poolId: v13.string(),
841
+ assetAAmount: v13.string(),
842
+ assetBAmount: v13.string(),
843
+ assetAMinAmountIn: v13.string(),
844
+ assetBMinAmountIn: v13.string(),
845
+ assetATransferId: v13.string(),
846
+ assetBTransferId: v13.string(),
847
+ nonce: v13.string()
848
+ })
849
+ });
850
+
851
+ // src/request/types/sparkMethods/flashnetMethods/intents/clawback.ts
852
+ import * as v14 from "valibot";
853
+ var sparkFlashnetClawbackIntentSchema = v14.object({
854
+ type: v14.literal("clawback"),
855
+ data: v14.object({
856
+ senderPublicKey: v14.string(),
857
+ sparkTransferId: v14.string(),
858
+ lpIdentityPublicKey: v14.string(),
859
+ nonce: v14.string()
860
+ })
861
+ });
862
+
863
+ // src/request/types/sparkMethods/flashnetMethods/intents/confirmInitialDeposit.ts
864
+ import * as v15 from "valibot";
865
+ var sparkFlashnetConfirmInitialDepositIntentSchema = v15.object({
866
+ type: v15.literal("confirmInitialDeposit"),
867
+ data: v15.object({
868
+ poolId: v15.string(),
869
+ assetASparkTransferId: v15.string(),
870
+ poolOwnerPublicKey: v15.string(),
871
+ nonce: v15.string()
872
+ })
873
+ });
874
+
875
+ // src/request/types/sparkMethods/flashnetMethods/intents/createConstantProductPool.ts
876
+ import * as v16 from "valibot";
877
+ var sparkFlashnetCreateConstantProductPoolIntentSchema = v16.object({
878
+ type: v16.literal("createConstantProductPool"),
879
+ data: v16.object({
880
+ poolOwnerPublicKey: v16.string(),
881
+ assetAAddress: v16.string(),
882
+ assetBAddress: v16.string(),
883
+ lpFeeRateBps: v16.number(),
884
+ totalHostFeeRateBps: v16.number(),
885
+ nonce: v16.string()
886
+ })
887
+ });
888
+
889
+ // src/request/types/sparkMethods/flashnetMethods/intents/createSingleSidedPool.ts
890
+ import * as v17 from "valibot";
891
+ var sparkFlashnetCreateSingleSidedPoolIntentSchema = v17.object({
892
+ type: v17.literal("createSingleSidedPool"),
893
+ data: v17.object({
894
+ assetAAddress: v17.string(),
895
+ assetBAddress: v17.string(),
896
+ assetAInitialReserve: v17.string(),
897
+ virtualReserveA: v17.union([v17.number(), v17.string()]),
898
+ virtualReserveB: v17.union([v17.number(), v17.string()]),
899
+ threshold: v17.union([v17.number(), v17.string()]),
900
+ lpFeeRateBps: v17.number(),
901
+ totalHostFeeRateBps: v17.number(),
902
+ poolOwnerPublicKey: v17.string(),
903
+ nonce: v17.string()
904
+ })
905
+ });
906
+
907
+ // src/request/types/sparkMethods/flashnetMethods/intents/removeLiquidity.ts
908
+ import * as v18 from "valibot";
909
+ var sparkFlashnetRemoveLiquidityIntentSchema = v18.object({
910
+ type: v18.literal("removeLiquidity"),
911
+ data: v18.object({
912
+ userPublicKey: v18.string(),
913
+ poolId: v18.string(),
914
+ lpTokensToRemove: v18.string(),
915
+ nonce: v18.string()
916
+ })
917
+ });
918
+
919
+ // src/request/types/sparkMethods/flashnetMethods/intents/routeSwap.ts
920
+ import * as v19 from "valibot";
921
+ var sparkFlashnetRouteSwapIntentSchema = v19.object({
922
+ type: v19.literal("executeRouteSwap"),
923
+ data: v19.object({
924
+ userPublicKey: v19.string(),
925
+ initialSparkTransferId: v19.string(),
926
+ hops: v19.array(
927
+ v19.object({
928
+ poolId: v19.string(),
929
+ assetInAddress: v19.string(),
930
+ assetOutAddress: v19.string(),
931
+ hopIntegratorFeeRateBps: v19.optional(v19.number())
932
+ })
933
+ ),
934
+ inputAmount: v19.string(),
935
+ maxRouteSlippageBps: v19.number(),
936
+ minAmountOut: v19.string(),
937
+ defaultIntegratorFeeRateBps: v19.optional(v19.number()),
938
+ nonce: v19.string()
939
+ })
940
+ });
941
+
942
+ // src/request/types/sparkMethods/flashnetMethods/intents/swap.ts
943
+ import * as v20 from "valibot";
944
+ var sparkFlashnetSwapIntentSchema = v20.object({
945
+ type: v20.literal("executeSwap"),
946
+ data: v20.object({
947
+ userPublicKey: v20.string(),
948
+ poolId: v20.string(),
949
+ transferId: v20.string(),
950
+ assetInAddress: v20.string(),
951
+ assetOutAddress: v20.string(),
952
+ amountIn: v20.string(),
953
+ maxSlippageBps: v20.number(),
954
+ minAmountOut: v20.string(),
955
+ totalIntegratorFeeRateBps: v20.optional(v20.number()),
956
+ nonce: v20.string()
957
+ })
958
+ });
959
+
960
+ // src/request/types/sparkMethods/flashnetMethods/signIntent.ts
961
+ import * as v21 from "valibot";
962
+ var sparkFlashnetSignIntentMethodName = "spark_flashnet_signIntent";
963
+ var sparkFlashnetSignIntentParamsSchema = v21.union([
964
+ sparkFlashnetSwapIntentSchema,
965
+ sparkFlashnetRouteSwapIntentSchema,
966
+ sparkFlashnetAddLiquidityIntentSchema,
967
+ sparkFlashnetClawbackIntentSchema,
968
+ sparkFlashnetConfirmInitialDepositIntentSchema,
969
+ sparkFlashnetCreateConstantProductPoolIntentSchema,
970
+ sparkFlashnetCreateSingleSidedPoolIntentSchema,
971
+ sparkFlashnetRemoveLiquidityIntentSchema
972
+ ]);
973
+ var sparkFlashnetSignIntentResultSchema = v21.object({
974
+ /**
975
+ * The signed intent as a hex string.
976
+ */
977
+ signature: v21.string()
978
+ });
979
+ var sparkFlashnetSignIntentRequestMessageSchema = v21.object({
980
+ ...rpcRequestMessageSchema.entries,
981
+ ...v21.object({
982
+ method: v21.literal(sparkFlashnetSignIntentMethodName),
983
+ params: sparkFlashnetSignIntentParamsSchema,
984
+ id: v21.string()
985
+ }).entries
986
+ });
987
+
988
+ // src/request/types/sparkMethods/getAddresses.ts
989
+ import * as v22 from "valibot";
990
+ var sparkGetAddressesMethodName = "spark_getAddresses";
991
+ var sparkGetAddressesParamsSchema = v22.nullish(
992
+ v22.object({
993
+ /**
994
+ * A message to be displayed to the user in the request prompt.
995
+ */
996
+ message: v22.optional(v22.string())
997
+ })
998
+ );
999
+ var sparkGetAddressesResultSchema = v22.object({
1328
1000
  /**
1329
1001
  * The addresses generated for the given purposes.
1330
1002
  */
1331
- addresses: v12.array(addressSchema),
1003
+ addresses: v22.array(addressSchema),
1332
1004
  network: getNetworkResultSchema
1333
1005
  });
1334
- var sparkGetAddressesRequestMessageSchema = v12.object({
1006
+ var sparkGetAddressesRequestMessageSchema = v22.object({
1335
1007
  ...rpcRequestMessageSchema.entries,
1336
- ...v12.object({
1337
- method: v12.literal(sparkGetAddressesMethodName),
1008
+ ...v22.object({
1009
+ method: v22.literal(sparkGetAddressesMethodName),
1338
1010
  params: sparkGetAddressesParamsSchema,
1339
- id: v12.string()
1011
+ id: v22.string()
1340
1012
  }).entries
1341
1013
  });
1342
1014
 
1343
1015
  // src/request/types/sparkMethods/getBalance.ts
1344
- import * as v13 from "valibot";
1016
+ import * as v23 from "valibot";
1345
1017
  var sparkGetBalanceMethodName = "spark_getBalance";
1346
- var sparkGetBalanceParamsSchema = v13.nullish(v13.null());
1347
- var sparkGetBalanceResultSchema = v13.object({
1018
+ var sparkGetBalanceParamsSchema = v23.nullish(v23.null());
1019
+ var sparkGetBalanceResultSchema = v23.object({
1348
1020
  /**
1349
1021
  * The Spark Bitcoin address balance in sats in string form.
1350
1022
  */
1351
- balance: v13.string(),
1352
- tokenBalances: v13.array(
1353
- v13.object({
1023
+ balance: v23.string(),
1024
+ tokenBalances: v23.array(
1025
+ v23.object({
1354
1026
  /* The address balance of the token in string form as it can overflow a js number */
1355
- balance: v13.string(),
1356
- tokenMetadata: v13.object({
1357
- tokenIdentifier: v13.string(),
1358
- tokenName: v13.string(),
1359
- tokenTicker: v13.string(),
1360
- decimals: v13.number(),
1361
- maxSupply: v13.string()
1027
+ balance: v23.string(),
1028
+ tokenMetadata: v23.object({
1029
+ tokenIdentifier: v23.string(),
1030
+ tokenName: v23.string(),
1031
+ tokenTicker: v23.string(),
1032
+ decimals: v23.number(),
1033
+ maxSupply: v23.string()
1362
1034
  })
1363
1035
  })
1364
1036
  )
1365
1037
  });
1366
- var sparkGetBalanceRequestMessageSchema = v13.object({
1038
+ var sparkGetBalanceRequestMessageSchema = v23.object({
1367
1039
  ...rpcRequestMessageSchema.entries,
1368
- ...v13.object({
1369
- method: v13.literal(sparkGetBalanceMethodName),
1040
+ ...v23.object({
1041
+ method: v23.literal(sparkGetBalanceMethodName),
1370
1042
  params: sparkGetBalanceParamsSchema,
1371
- id: v13.string()
1043
+ id: v23.string()
1372
1044
  }).entries
1373
1045
  });
1374
1046
 
1375
1047
  // src/request/types/sparkMethods/transfer.ts
1376
- import * as v14 from "valibot";
1048
+ import * as v24 from "valibot";
1377
1049
  var sparkTransferMethodName = "spark_transfer";
1378
- var sparkTransferParamsSchema = v14.object({
1050
+ var sparkTransferParamsSchema = v24.object({
1379
1051
  /**
1380
1052
  * Amount of SATS to transfer as a string or number.
1381
1053
  */
1382
- amountSats: v14.union([v14.number(), v14.string()]),
1054
+ amountSats: v24.union([v24.number(), v24.string()]),
1383
1055
  /**
1384
1056
  * The recipient's spark address.
1385
1057
  */
1386
- receiverSparkAddress: v14.string()
1058
+ receiverSparkAddress: v24.string()
1387
1059
  });
1388
- var sparkTransferResultSchema = v14.object({
1060
+ var sparkTransferResultSchema = v24.object({
1389
1061
  /**
1390
1062
  * The ID of the transaction.
1391
1063
  */
1392
- id: v14.string()
1064
+ id: v24.string()
1393
1065
  });
1394
- var sparkTransferRequestMessageSchema = v14.object({
1066
+ var sparkTransferRequestMessageSchema = v24.object({
1395
1067
  ...rpcRequestMessageSchema.entries,
1396
- ...v14.object({
1397
- method: v14.literal(sparkTransferMethodName),
1068
+ ...v24.object({
1069
+ method: v24.literal(sparkTransferMethodName),
1398
1070
  params: sparkTransferParamsSchema,
1399
- id: v14.string()
1071
+ id: v24.string()
1400
1072
  }).entries
1401
1073
  });
1402
1074
 
1403
1075
  // src/request/types/sparkMethods/transferToken.ts
1404
- import * as v15 from "valibot";
1076
+ import * as v25 from "valibot";
1405
1077
  var sparkTransferTokenMethodName = "spark_transferToken";
1406
- var sparkTransferTokenParamsSchema = v15.object({
1078
+ var sparkTransferTokenParamsSchema = v25.object({
1407
1079
  /**
1408
1080
  * Amount of units of the token to transfer as a string or number.
1409
1081
  */
1410
- tokenAmount: v15.union([v15.number(), v15.string()]),
1082
+ tokenAmount: v25.union([v25.number(), v25.string()]),
1411
1083
  /**
1412
1084
  * The Bech32m token identifier.
1413
1085
  */
1414
- tokenIdentifier: v15.string(),
1086
+ tokenIdentifier: v25.string(),
1415
1087
  /**
1416
1088
  * The recipient's spark address.
1417
1089
  */
1418
- receiverSparkAddress: v15.string()
1090
+ receiverSparkAddress: v25.string()
1419
1091
  });
1420
- var sparkTransferTokenResultSchema = v15.object({
1092
+ var sparkTransferTokenResultSchema = v25.object({
1421
1093
  /**
1422
1094
  * The ID of the transaction.
1423
1095
  */
1424
- id: v15.string()
1096
+ id: v25.string()
1425
1097
  });
1426
- var sparkTransferTokenRequestMessageSchema = v15.object({
1098
+ var sparkTransferTokenRequestMessageSchema = v25.object({
1427
1099
  ...rpcRequestMessageSchema.entries,
1428
- ...v15.object({
1429
- method: v15.literal(sparkTransferTokenMethodName),
1100
+ ...v25.object({
1101
+ method: v25.literal(sparkTransferTokenMethodName),
1430
1102
  params: sparkTransferTokenParamsSchema,
1431
- id: v15.string()
1103
+ id: v25.string()
1432
1104
  }).entries
1433
1105
  });
1434
1106
 
1435
1107
  // src/request/types/stxMethods/callContract.ts
1436
- import * as v16 from "valibot";
1108
+ import * as v26 from "valibot";
1437
1109
  var stxCallContractMethodName = "stx_callContract";
1438
- var stxCallContractParamsSchema = v16.object({
1110
+ var stxCallContractParamsSchema = v26.object({
1439
1111
  /**
1440
1112
  * The contract principal.
1441
1113
  *
1442
1114
  * E.g. `"SPKE...GD5C.my-contract"`
1443
1115
  */
1444
- contract: v16.string(),
1116
+ contract: v26.string(),
1445
1117
  /**
1446
1118
  * The name of the function to call.
1447
1119
  *
1448
1120
  * Note: spec changes ongoing,
1449
1121
  * https://github.com/stacksgov/sips/pull/166#pullrequestreview-1914236999
1450
1122
  */
1451
- functionName: v16.string(),
1123
+ functionName: v26.string(),
1452
1124
  /**
1453
1125
  * @deprecated in favor of `functionArgs` for @stacks/connect compatibility
1454
1126
  */
1455
- arguments: v16.optional(v16.array(v16.string())),
1127
+ arguments: v26.optional(v26.array(v26.string())),
1456
1128
  /**
1457
1129
  * The function's arguments. The arguments are expected to be hex-encoded
1458
1130
  * strings of Clarity values.
@@ -1467,274 +1139,274 @@ var stxCallContractParamsSchema = v16.object({
1467
1139
  * const hexArgs = functionArgs.map(cvToHex);
1468
1140
  * ```
1469
1141
  */
1470
- functionArgs: v16.optional(v16.array(v16.string())),
1142
+ functionArgs: v26.optional(v26.array(v26.string())),
1471
1143
  /**
1472
1144
  * The post conditions to apply to the contract call.
1473
1145
  */
1474
- postConditions: v16.optional(v16.array(v16.string())),
1146
+ postConditions: v26.optional(v26.array(v26.string())),
1475
1147
  /**
1476
1148
  * The mode to apply to the post conditions.
1477
1149
  */
1478
- postConditionMode: v16.optional(v16.union([v16.literal("allow"), v16.literal("deny")]))
1150
+ postConditionMode: v26.optional(v26.union([v26.literal("allow"), v26.literal("deny")]))
1479
1151
  });
1480
- var stxCallContractResultSchema = v16.object({
1152
+ var stxCallContractResultSchema = v26.object({
1481
1153
  /**
1482
1154
  * The ID of the transaction.
1483
1155
  */
1484
- txid: v16.string(),
1156
+ txid: v26.string(),
1485
1157
  /**
1486
1158
  * A Stacks transaction as a hex-encoded string.
1487
1159
  */
1488
- transaction: v16.string()
1160
+ transaction: v26.string()
1489
1161
  });
1490
- var stxCallContractRequestMessageSchema = v16.object({
1162
+ var stxCallContractRequestMessageSchema = v26.object({
1491
1163
  ...rpcRequestMessageSchema.entries,
1492
- ...v16.object({
1493
- method: v16.literal(stxCallContractMethodName),
1164
+ ...v26.object({
1165
+ method: v26.literal(stxCallContractMethodName),
1494
1166
  params: stxCallContractParamsSchema,
1495
- id: v16.string()
1167
+ id: v26.string()
1496
1168
  }).entries
1497
1169
  });
1498
1170
 
1499
1171
  // src/request/types/stxMethods/deployContract.ts
1500
- import * as v17 from "valibot";
1172
+ import * as v27 from "valibot";
1501
1173
  var stxDeployContractMethodName = "stx_deployContract";
1502
- var stxDeployContractParamsSchema = v17.object({
1174
+ var stxDeployContractParamsSchema = v27.object({
1503
1175
  /**
1504
1176
  * Name of the contract.
1505
1177
  */
1506
- name: v17.string(),
1178
+ name: v27.string(),
1507
1179
  /**
1508
1180
  * The source code of the Clarity contract.
1509
1181
  */
1510
- clarityCode: v17.string(),
1182
+ clarityCode: v27.string(),
1511
1183
  /**
1512
1184
  * The version of the Clarity contract.
1513
1185
  */
1514
- clarityVersion: v17.optional(v17.number()),
1186
+ clarityVersion: v27.optional(v27.number()),
1515
1187
  /**
1516
1188
  * The post conditions to apply to the contract call.
1517
1189
  */
1518
- postConditions: v17.optional(v17.array(v17.string())),
1190
+ postConditions: v27.optional(v27.array(v27.string())),
1519
1191
  /**
1520
1192
  * The mode to apply to the post conditions.
1521
1193
  */
1522
- postConditionMode: v17.optional(v17.union([v17.literal("allow"), v17.literal("deny")]))
1194
+ postConditionMode: v27.optional(v27.union([v27.literal("allow"), v27.literal("deny")]))
1523
1195
  });
1524
- var stxDeployContractResultSchema = v17.object({
1196
+ var stxDeployContractResultSchema = v27.object({
1525
1197
  /**
1526
1198
  * The ID of the transaction.
1527
1199
  */
1528
- txid: v17.string(),
1200
+ txid: v27.string(),
1529
1201
  /**
1530
1202
  * A Stacks transaction as a hex-encoded string.
1531
1203
  */
1532
- transaction: v17.string()
1204
+ transaction: v27.string()
1533
1205
  });
1534
- var stxDeployContractRequestMessageSchema = v17.object({
1206
+ var stxDeployContractRequestMessageSchema = v27.object({
1535
1207
  ...rpcRequestMessageSchema.entries,
1536
- ...v17.object({
1537
- method: v17.literal(stxDeployContractMethodName),
1208
+ ...v27.object({
1209
+ method: v27.literal(stxDeployContractMethodName),
1538
1210
  params: stxDeployContractParamsSchema,
1539
- id: v17.string()
1211
+ id: v27.string()
1540
1212
  }).entries
1541
1213
  });
1542
1214
 
1543
1215
  // src/request/types/stxMethods/getAccounts.ts
1544
- import * as v18 from "valibot";
1216
+ import * as v28 from "valibot";
1545
1217
  var stxGetAccountsMethodName = "stx_getAccounts";
1546
- var stxGetAccountsParamsSchema = v18.nullish(v18.null());
1547
- var stxGetAccountsResultSchema = v18.object({
1218
+ var stxGetAccountsParamsSchema = v28.nullish(v28.null());
1219
+ var stxGetAccountsResultSchema = v28.object({
1548
1220
  /**
1549
1221
  * The addresses generated for the given purposes.
1550
1222
  */
1551
- addresses: v18.array(
1552
- v18.object({
1553
- address: v18.string(),
1554
- publicKey: v18.string(),
1555
- gaiaHubUrl: v18.string(),
1556
- gaiaAppKey: v18.string()
1223
+ addresses: v28.array(
1224
+ v28.object({
1225
+ address: v28.string(),
1226
+ publicKey: v28.string(),
1227
+ gaiaHubUrl: v28.string(),
1228
+ gaiaAppKey: v28.string()
1557
1229
  })
1558
1230
  ),
1559
1231
  network: getNetworkResultSchema
1560
1232
  });
1561
- var stxGetAccountsRequestMessageSchema = v18.object({
1233
+ var stxGetAccountsRequestMessageSchema = v28.object({
1562
1234
  ...rpcRequestMessageSchema.entries,
1563
- ...v18.object({
1564
- method: v18.literal(stxGetAccountsMethodName),
1235
+ ...v28.object({
1236
+ method: v28.literal(stxGetAccountsMethodName),
1565
1237
  params: stxGetAccountsParamsSchema,
1566
- id: v18.string()
1238
+ id: v28.string()
1567
1239
  }).entries
1568
1240
  });
1569
1241
 
1570
1242
  // src/request/types/stxMethods/getAddresses.ts
1571
- import * as v19 from "valibot";
1243
+ import * as v29 from "valibot";
1572
1244
  var stxGetAddressesMethodName = "stx_getAddresses";
1573
- var stxGetAddressesParamsSchema = v19.nullish(
1574
- v19.object({
1245
+ var stxGetAddressesParamsSchema = v29.nullish(
1246
+ v29.object({
1575
1247
  /**
1576
1248
  * A message to be displayed to the user in the request prompt.
1577
1249
  */
1578
- message: v19.optional(v19.string())
1250
+ message: v29.optional(v29.string())
1579
1251
  })
1580
1252
  );
1581
- var stxGetAddressesResultSchema = v19.object({
1253
+ var stxGetAddressesResultSchema = v29.object({
1582
1254
  /**
1583
1255
  * The addresses generated for the given purposes.
1584
1256
  */
1585
- addresses: v19.array(addressSchema),
1257
+ addresses: v29.array(addressSchema),
1586
1258
  network: getNetworkResultSchema
1587
1259
  });
1588
- var stxGetAddressesRequestMessageSchema = v19.object({
1260
+ var stxGetAddressesRequestMessageSchema = v29.object({
1589
1261
  ...rpcRequestMessageSchema.entries,
1590
- ...v19.object({
1591
- method: v19.literal(stxGetAddressesMethodName),
1262
+ ...v29.object({
1263
+ method: v29.literal(stxGetAddressesMethodName),
1592
1264
  params: stxGetAddressesParamsSchema,
1593
- id: v19.string()
1265
+ id: v29.string()
1594
1266
  }).entries
1595
1267
  });
1596
1268
 
1597
1269
  // src/request/types/stxMethods/signMessage.ts
1598
- import * as v20 from "valibot";
1270
+ import * as v30 from "valibot";
1599
1271
  var stxSignMessageMethodName = "stx_signMessage";
1600
- var stxSignMessageParamsSchema = v20.object({
1272
+ var stxSignMessageParamsSchema = v30.object({
1601
1273
  /**
1602
1274
  * The message to sign.
1603
1275
  */
1604
- message: v20.string()
1276
+ message: v30.string()
1605
1277
  });
1606
- var stxSignMessageResultSchema = v20.object({
1278
+ var stxSignMessageResultSchema = v30.object({
1607
1279
  /**
1608
1280
  * The signature of the message.
1609
1281
  */
1610
- signature: v20.string(),
1282
+ signature: v30.string(),
1611
1283
  /**
1612
1284
  * The public key used to sign the message.
1613
1285
  */
1614
- publicKey: v20.string()
1286
+ publicKey: v30.string()
1615
1287
  });
1616
- var stxSignMessageRequestMessageSchema = v20.object({
1288
+ var stxSignMessageRequestMessageSchema = v30.object({
1617
1289
  ...rpcRequestMessageSchema.entries,
1618
- ...v20.object({
1619
- method: v20.literal(stxSignMessageMethodName),
1290
+ ...v30.object({
1291
+ method: v30.literal(stxSignMessageMethodName),
1620
1292
  params: stxSignMessageParamsSchema,
1621
- id: v20.string()
1293
+ id: v30.string()
1622
1294
  }).entries
1623
1295
  });
1624
1296
 
1625
1297
  // src/request/types/stxMethods/signStructuredMessage.ts
1626
- import * as v21 from "valibot";
1298
+ import * as v31 from "valibot";
1627
1299
  var stxSignStructuredMessageMethodName = "stx_signStructuredMessage";
1628
- var stxSignStructuredMessageParamsSchema = v21.object({
1300
+ var stxSignStructuredMessageParamsSchema = v31.object({
1629
1301
  /**
1630
1302
  * The domain to be signed.
1631
1303
  */
1632
- domain: v21.string(),
1304
+ domain: v31.string(),
1633
1305
  /**
1634
1306
  * Message payload to be signed.
1635
1307
  */
1636
- message: v21.string(),
1308
+ message: v31.string(),
1637
1309
  /**
1638
1310
  * The public key to sign the message with.
1639
1311
  */
1640
- publicKey: v21.optional(v21.string())
1312
+ publicKey: v31.optional(v31.string())
1641
1313
  });
1642
- var stxSignStructuredMessageResultSchema = v21.object({
1314
+ var stxSignStructuredMessageResultSchema = v31.object({
1643
1315
  /**
1644
1316
  * Signature of the message.
1645
1317
  */
1646
- signature: v21.string(),
1318
+ signature: v31.string(),
1647
1319
  /**
1648
1320
  * Public key as hex-encoded string.
1649
1321
  */
1650
- publicKey: v21.string()
1322
+ publicKey: v31.string()
1651
1323
  });
1652
- var stxSignStructuredMessageRequestMessageSchema = v21.object({
1324
+ var stxSignStructuredMessageRequestMessageSchema = v31.object({
1653
1325
  ...rpcRequestMessageSchema.entries,
1654
- ...v21.object({
1655
- method: v21.literal(stxSignStructuredMessageMethodName),
1326
+ ...v31.object({
1327
+ method: v31.literal(stxSignStructuredMessageMethodName),
1656
1328
  params: stxSignStructuredMessageParamsSchema,
1657
- id: v21.string()
1329
+ id: v31.string()
1658
1330
  }).entries
1659
1331
  });
1660
1332
 
1661
1333
  // src/request/types/stxMethods/signTransaction.ts
1662
- import * as v22 from "valibot";
1334
+ import * as v32 from "valibot";
1663
1335
  var stxSignTransactionMethodName = "stx_signTransaction";
1664
- var stxSignTransactionParamsSchema = v22.object({
1336
+ var stxSignTransactionParamsSchema = v32.object({
1665
1337
  /**
1666
1338
  * The transaction to sign as a hex-encoded string.
1667
1339
  */
1668
- transaction: v22.string(),
1340
+ transaction: v32.string(),
1669
1341
  /**
1670
1342
  * The public key to sign the transaction with. The wallet may use any key
1671
1343
  * when not provided.
1672
1344
  */
1673
- pubkey: v22.optional(v22.string()),
1345
+ pubkey: v32.optional(v32.string()),
1674
1346
  /**
1675
1347
  * Whether to broadcast the transaction after signing. Defaults to `true`.
1676
1348
  */
1677
- broadcast: v22.optional(v22.boolean())
1349
+ broadcast: v32.optional(v32.boolean())
1678
1350
  });
1679
- var stxSignTransactionResultSchema = v22.object({
1351
+ var stxSignTransactionResultSchema = v32.object({
1680
1352
  /**
1681
1353
  * The signed transaction as a hex-encoded string.
1682
1354
  */
1683
- transaction: v22.string()
1355
+ transaction: v32.string()
1684
1356
  });
1685
- var stxSignTransactionRequestMessageSchema = v22.object({
1357
+ var stxSignTransactionRequestMessageSchema = v32.object({
1686
1358
  ...rpcRequestMessageSchema.entries,
1687
- ...v22.object({
1688
- method: v22.literal(stxSignTransactionMethodName),
1359
+ ...v32.object({
1360
+ method: v32.literal(stxSignTransactionMethodName),
1689
1361
  params: stxSignTransactionParamsSchema,
1690
- id: v22.string()
1362
+ id: v32.string()
1691
1363
  }).entries
1692
1364
  });
1693
1365
 
1694
1366
  // src/request/types/stxMethods/signTransactions.ts
1695
- import * as v23 from "valibot";
1367
+ import * as v33 from "valibot";
1696
1368
  var stxSignTransactionsMethodName = "stx_signTransactions";
1697
- var stxSignTransactionsParamsSchema = v23.object({
1369
+ var stxSignTransactionsParamsSchema = v33.object({
1698
1370
  /**
1699
1371
  * The transactions to sign as hex-encoded strings.
1700
1372
  */
1701
- transactions: v23.pipe(
1702
- v23.array(
1703
- v23.pipe(
1704
- v23.string(),
1705
- v23.check((hex) => {
1373
+ transactions: v33.pipe(
1374
+ v33.array(
1375
+ v33.pipe(
1376
+ v33.string(),
1377
+ v33.check((hex) => {
1706
1378
  return true;
1707
1379
  }, "Invalid hex-encoded Stacks transaction.")
1708
1380
  )
1709
1381
  ),
1710
- v23.minLength(1)
1382
+ v33.minLength(1)
1711
1383
  ),
1712
1384
  /**
1713
1385
  * Whether the signed transactions should be broadcast after signing. Defaults
1714
1386
  * to `true`.
1715
1387
  */
1716
- broadcast: v23.optional(v23.boolean())
1388
+ broadcast: v33.optional(v33.boolean())
1717
1389
  });
1718
- var stxSignTransactionsResultSchema = v23.object({
1390
+ var stxSignTransactionsResultSchema = v33.object({
1719
1391
  /**
1720
1392
  * The signed transactions as hex-encoded strings, in the same order as in the
1721
1393
  * sign request.
1722
1394
  */
1723
- transactions: v23.array(v23.string())
1395
+ transactions: v33.array(v33.string())
1724
1396
  });
1725
- var stxSignTransactionsRequestMessageSchema = v23.object({
1397
+ var stxSignTransactionsRequestMessageSchema = v33.object({
1726
1398
  ...rpcRequestMessageSchema.entries,
1727
- ...v23.object({
1728
- method: v23.literal(stxSignTransactionsMethodName),
1399
+ ...v33.object({
1400
+ method: v33.literal(stxSignTransactionsMethodName),
1729
1401
  params: stxSignTransactionsParamsSchema,
1730
- id: v23.string()
1402
+ id: v33.string()
1731
1403
  }).entries
1732
1404
  });
1733
1405
 
1734
1406
  // src/request/types/stxMethods/transferStx.ts
1735
- import * as v24 from "valibot";
1407
+ import * as v34 from "valibot";
1736
1408
  var stxTransferStxMethodName = "stx_transferStx";
1737
- var stxTransferStxParamsSchema = v24.object({
1409
+ var stxTransferStxParamsSchema = v34.object({
1738
1410
  /**
1739
1411
  * Amount of STX tokens to transfer in microstacks as a string. Anything
1740
1412
  * parseable by `BigInt` is acceptable.
@@ -1747,23 +1419,23 @@ var stxTransferStxParamsSchema = v24.object({
1747
1419
  * const amount3 = '1234';
1748
1420
  * ```
1749
1421
  */
1750
- amount: v24.union([v24.number(), v24.string()]),
1422
+ amount: v34.union([v34.number(), v34.string()]),
1751
1423
  /**
1752
1424
  * The recipient's principal.
1753
1425
  */
1754
- recipient: v24.string(),
1426
+ recipient: v34.string(),
1755
1427
  /**
1756
1428
  * A string representing the memo.
1757
1429
  */
1758
- memo: v24.optional(v24.string()),
1430
+ memo: v34.optional(v34.string()),
1759
1431
  /**
1760
1432
  * Version of parameter format.
1761
1433
  */
1762
- version: v24.optional(v24.string()),
1434
+ version: v34.optional(v34.string()),
1763
1435
  /**
1764
1436
  * The mode of the post conditions.
1765
1437
  */
1766
- postConditionMode: v24.optional(v24.number()),
1438
+ postConditionMode: v34.optional(v34.number()),
1767
1439
  /**
1768
1440
  * A hex-encoded string representing the post conditions.
1769
1441
  *
@@ -1776,29 +1448,29 @@ var stxTransferStxParamsSchema = v24.object({
1776
1448
  * const hexPostCondition = serializePostCondition(postCondition).toString('hex');
1777
1449
  * ```
1778
1450
  */
1779
- postConditions: v24.optional(v24.array(v24.string())),
1451
+ postConditions: v34.optional(v34.array(v34.string())),
1780
1452
  /**
1781
1453
  * The public key to sign the transaction with. The wallet may use any key
1782
1454
  * when not provided.
1783
1455
  */
1784
- pubkey: v24.optional(v24.string())
1456
+ pubkey: v34.optional(v34.string())
1785
1457
  });
1786
- var stxTransferStxResultSchema = v24.object({
1458
+ var stxTransferStxResultSchema = v34.object({
1787
1459
  /**
1788
1460
  * The ID of the transaction.
1789
1461
  */
1790
- txid: v24.string(),
1462
+ txid: v34.string(),
1791
1463
  /**
1792
1464
  * A Stacks transaction as a hex-encoded string.
1793
1465
  */
1794
- transaction: v24.string()
1466
+ transaction: v34.string()
1795
1467
  });
1796
- var stxTransferStxRequestMessageSchema = v24.object({
1468
+ var stxTransferStxRequestMessageSchema = v34.object({
1797
1469
  ...rpcRequestMessageSchema.entries,
1798
- ...v24.object({
1799
- method: v24.literal(stxTransferStxMethodName),
1470
+ ...v34.object({
1471
+ method: v34.literal(stxTransferStxMethodName),
1800
1472
  params: stxTransferStxParamsSchema,
1801
- id: v24.string()
1473
+ id: v34.string()
1802
1474
  }).entries
1803
1475
  });
1804
1476
 
@@ -1808,83 +1480,562 @@ var request = async (method, params, providerId) => {
1808
1480
  if (providerId) {
1809
1481
  provider = await getProviderById(providerId);
1810
1482
  }
1811
- if (!provider) {
1812
- throw new Error("no wallet provider was found");
1483
+ if (!provider) {
1484
+ throw new Error("no wallet provider was found");
1485
+ }
1486
+ if (!method) {
1487
+ throw new Error("A wallet method is required");
1488
+ }
1489
+ const response = await provider.request(method, params);
1490
+ if (v35.is(rpcErrorResponseMessageSchema, response)) {
1491
+ return {
1492
+ status: "error",
1493
+ error: response.error
1494
+ };
1495
+ }
1496
+ if (v35.is(rpcSuccessResponseMessageSchema, response)) {
1497
+ return {
1498
+ status: "success",
1499
+ result: response.result
1500
+ };
1501
+ }
1502
+ return {
1503
+ status: "error",
1504
+ error: {
1505
+ code: -32603 /* INTERNAL_ERROR */,
1506
+ message: "Received unknown response from provider.",
1507
+ data: response
1508
+ }
1509
+ };
1510
+ };
1511
+ var addListener = (...rawArgs) => {
1512
+ const [listenerInfo, providerId] = (() => {
1513
+ if (rawArgs.length === 1) {
1514
+ return [rawArgs[0], void 0];
1515
+ }
1516
+ if (rawArgs.length === 2) {
1517
+ if (typeof rawArgs[1] === "function") {
1518
+ return [
1519
+ {
1520
+ eventName: rawArgs[0],
1521
+ cb: rawArgs[1]
1522
+ },
1523
+ void 0
1524
+ ];
1525
+ } else {
1526
+ return rawArgs;
1527
+ }
1528
+ }
1529
+ if (rawArgs.length === 3) {
1530
+ return [
1531
+ {
1532
+ eventName: rawArgs[0],
1533
+ cb: rawArgs[1]
1534
+ },
1535
+ rawArgs[2]
1536
+ ];
1537
+ }
1538
+ throw new Error("Unexpected number of arguments. Expecting 2 (or 3 for legacy requests).", {
1539
+ cause: rawArgs
1540
+ });
1541
+ })();
1542
+ let provider = window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
1543
+ if (providerId) {
1544
+ provider = getProviderById(providerId);
1545
+ }
1546
+ if (!provider) {
1547
+ throw new Error("no wallet provider was found");
1548
+ }
1549
+ if (!provider.addListener) {
1550
+ console.error(
1551
+ `The wallet provider you are using does not support the addListener method. Please update your wallet provider.`
1552
+ );
1553
+ return () => {
1554
+ };
1555
+ }
1556
+ return provider.addListener(listenerInfo);
1557
+ };
1558
+
1559
+ // src/runes/api.ts
1560
+ import axios from "axios";
1561
+ var urlNetworkSuffix = {
1562
+ ["Mainnet" /* Mainnet */]: "",
1563
+ ["Testnet" /* Testnet */]: "-testnet",
1564
+ ["Testnet4" /* Testnet4 */]: "-testnet4",
1565
+ ["Signet" /* Signet */]: "-signet"
1566
+ };
1567
+ var ORDINALS_API_BASE_URL = (network = "Mainnet" /* Mainnet */) => {
1568
+ if (network === "Regtest" /* Regtest */) {
1569
+ throw new Error(`Ordinals API does not support ${network} network`);
1570
+ }
1571
+ return `https://ordinals${urlNetworkSuffix[network]}.xverse.app/v1`;
1572
+ };
1573
+ var RunesApi = class {
1574
+ client;
1575
+ constructor(network) {
1576
+ this.client = axios.create({
1577
+ baseURL: ORDINALS_API_BASE_URL(network)
1578
+ });
1579
+ }
1580
+ parseError = (error) => {
1581
+ return {
1582
+ code: error.response?.status,
1583
+ message: JSON.stringify(error.response?.data)
1584
+ };
1585
+ };
1586
+ estimateMintCost = async (mintParams) => {
1587
+ try {
1588
+ const response = await this.client.post("/runes/mint/estimate", {
1589
+ ...mintParams
1590
+ });
1591
+ return {
1592
+ data: response.data
1593
+ };
1594
+ } catch (error) {
1595
+ const err = error;
1596
+ return {
1597
+ error: this.parseError(err)
1598
+ };
1599
+ }
1600
+ };
1601
+ estimateEtchCost = async (etchParams) => {
1602
+ try {
1603
+ const response = await this.client.post("/runes/etch/estimate", {
1604
+ ...etchParams
1605
+ });
1606
+ return {
1607
+ data: response.data
1608
+ };
1609
+ } catch (error) {
1610
+ const err = error;
1611
+ return {
1612
+ error: this.parseError(err)
1613
+ };
1614
+ }
1615
+ };
1616
+ createMintOrder = async (mintOrderParams) => {
1617
+ try {
1618
+ const response = await this.client.post("/runes/mint/orders", {
1619
+ ...mintOrderParams
1620
+ });
1621
+ return {
1622
+ data: response.data
1623
+ };
1624
+ } catch (error) {
1625
+ const err = error;
1626
+ return {
1627
+ error: this.parseError(err)
1628
+ };
1629
+ }
1630
+ };
1631
+ createEtchOrder = async (etchOrderParams) => {
1632
+ try {
1633
+ const response = await this.client.post("/runes/etch/orders", {
1634
+ ...etchOrderParams
1635
+ });
1636
+ return {
1637
+ data: response.data
1638
+ };
1639
+ } catch (error) {
1640
+ const err = error;
1641
+ return {
1642
+ error: this.parseError(err)
1643
+ };
1644
+ }
1645
+ };
1646
+ executeMint = async (orderId, fundTransactionId) => {
1647
+ try {
1648
+ const response = await this.client.post(`/runes/mint/orders/${orderId}/execute`, {
1649
+ fundTransactionId
1650
+ });
1651
+ return {
1652
+ data: response.data
1653
+ };
1654
+ } catch (error) {
1655
+ const err = error;
1656
+ return {
1657
+ error: this.parseError(err)
1658
+ };
1659
+ }
1660
+ };
1661
+ executeEtch = async (orderId, fundTransactionId) => {
1662
+ try {
1663
+ const response = await this.client.post(`/runes/etch/orders/${orderId}/execute`, {
1664
+ fundTransactionId
1665
+ });
1666
+ return {
1667
+ data: response.data
1668
+ };
1669
+ } catch (error) {
1670
+ const err = error;
1671
+ return {
1672
+ error: this.parseError(err)
1673
+ };
1674
+ }
1675
+ };
1676
+ getOrder = async (orderId) => {
1677
+ try {
1678
+ const response = await this.client.get(`/orders/${orderId}`);
1679
+ return {
1680
+ data: response.data
1681
+ };
1682
+ } catch (error) {
1683
+ const err = error;
1684
+ return {
1685
+ error: this.parseError(err)
1686
+ };
1687
+ }
1688
+ };
1689
+ rbfOrder = async (rbfRequest) => {
1690
+ const { orderId, newFeeRate } = rbfRequest;
1691
+ try {
1692
+ const response = await this.client.post(`/orders/${orderId}/rbf-estimate`, {
1693
+ newFeeRate
1694
+ });
1695
+ return {
1696
+ data: response.data
1697
+ };
1698
+ } catch (error) {
1699
+ const err = error;
1700
+ return {
1701
+ error: this.parseError(err)
1702
+ };
1703
+ }
1704
+ };
1705
+ };
1706
+ var clients = {};
1707
+ var getRunesApiClient = (network = "Mainnet" /* Mainnet */) => {
1708
+ if (!clients[network]) {
1709
+ clients[network] = new RunesApi(network);
1710
+ }
1711
+ return clients[network];
1712
+ };
1713
+
1714
+ // src/adapters/satsConnectAdapter.ts
1715
+ var SatsConnectAdapter = class {
1716
+ async mintRunes(params) {
1717
+ try {
1718
+ const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
1719
+ if (walletInfo && walletInfo.status === "success") {
1720
+ const isMintSupported = walletInfo.result.methods?.includes("runes_mint");
1721
+ if (isMintSupported) {
1722
+ const response = await this.requestInternal("runes_mint", params);
1723
+ if (response) {
1724
+ if (response.status === "success") {
1725
+ return response;
1726
+ }
1727
+ if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
1728
+ return response;
1729
+ }
1730
+ }
1731
+ }
1732
+ }
1733
+ const mintRequest = {
1734
+ destinationAddress: params.destinationAddress,
1735
+ feeRate: params.feeRate,
1736
+ refundAddress: params.refundAddress,
1737
+ repeats: params.repeats,
1738
+ runeName: params.runeName,
1739
+ appServiceFee: params.appServiceFee,
1740
+ appServiceFeeAddress: params.appServiceFeeAddress
1741
+ };
1742
+ const orderResponse = await new RunesApi(params.network).createMintOrder(mintRequest);
1743
+ if (!orderResponse.data) {
1744
+ return {
1745
+ status: "error",
1746
+ error: {
1747
+ code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
1748
+ message: orderResponse.error.message
1749
+ }
1750
+ };
1751
+ }
1752
+ const paymentResponse = await this.requestInternal("sendTransfer", {
1753
+ recipients: [
1754
+ {
1755
+ address: orderResponse.data.fundAddress,
1756
+ amount: orderResponse.data.fundAmount
1757
+ }
1758
+ ]
1759
+ });
1760
+ if (paymentResponse.status !== "success") {
1761
+ return paymentResponse;
1762
+ }
1763
+ await new RunesApi(params.network).executeMint(
1764
+ orderResponse.data.orderId,
1765
+ paymentResponse.result.txid
1766
+ );
1767
+ return {
1768
+ status: "success",
1769
+ result: {
1770
+ orderId: orderResponse.data.orderId,
1771
+ fundTransactionId: paymentResponse.result.txid,
1772
+ fundingAddress: orderResponse.data.fundAddress
1773
+ }
1774
+ };
1775
+ } catch (error) {
1776
+ return {
1777
+ status: "error",
1778
+ error: {
1779
+ code: -32603 /* INTERNAL_ERROR */,
1780
+ message: error.message
1781
+ }
1782
+ };
1783
+ }
1813
1784
  }
1814
- if (!method) {
1815
- throw new Error("A wallet method is required");
1785
+ async etchRunes(params) {
1786
+ const etchRequest = {
1787
+ destinationAddress: params.destinationAddress,
1788
+ refundAddress: params.refundAddress,
1789
+ feeRate: params.feeRate,
1790
+ runeName: params.runeName,
1791
+ divisibility: params.divisibility,
1792
+ symbol: params.symbol,
1793
+ premine: params.premine,
1794
+ isMintable: params.isMintable,
1795
+ terms: params.terms,
1796
+ inscriptionDetails: params.inscriptionDetails,
1797
+ delegateInscriptionId: params.delegateInscriptionId,
1798
+ appServiceFee: params.appServiceFee,
1799
+ appServiceFeeAddress: params.appServiceFeeAddress
1800
+ };
1801
+ try {
1802
+ const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
1803
+ if (walletInfo && walletInfo.status === "success") {
1804
+ const isEtchSupported = walletInfo.result.methods?.includes("runes_etch");
1805
+ if (isEtchSupported) {
1806
+ const response = await this.requestInternal("runes_etch", params);
1807
+ if (response) {
1808
+ if (response.status === "success") {
1809
+ return response;
1810
+ }
1811
+ if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
1812
+ return response;
1813
+ }
1814
+ }
1815
+ }
1816
+ }
1817
+ const orderResponse = await new RunesApi(params.network).createEtchOrder(etchRequest);
1818
+ if (!orderResponse.data) {
1819
+ return {
1820
+ status: "error",
1821
+ error: {
1822
+ code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
1823
+ message: orderResponse.error.message
1824
+ }
1825
+ };
1826
+ }
1827
+ const paymentResponse = await this.requestInternal("sendTransfer", {
1828
+ recipients: [
1829
+ {
1830
+ address: orderResponse.data.fundAddress,
1831
+ amount: orderResponse.data.fundAmount
1832
+ }
1833
+ ]
1834
+ });
1835
+ if (paymentResponse.status !== "success") {
1836
+ return paymentResponse;
1837
+ }
1838
+ await new RunesApi(params.network).executeEtch(
1839
+ orderResponse.data.orderId,
1840
+ paymentResponse.result.txid
1841
+ );
1842
+ return {
1843
+ status: "success",
1844
+ result: {
1845
+ orderId: orderResponse.data.orderId,
1846
+ fundTransactionId: paymentResponse.result.txid,
1847
+ fundingAddress: orderResponse.data.fundAddress
1848
+ }
1849
+ };
1850
+ } catch (error) {
1851
+ return {
1852
+ status: "error",
1853
+ error: {
1854
+ code: -32603 /* INTERNAL_ERROR */,
1855
+ message: error.message
1856
+ }
1857
+ };
1858
+ }
1816
1859
  }
1817
- const response = await provider.request(method, params);
1818
- if (v25.is(rpcErrorResponseMessageSchema, response)) {
1860
+ async estimateMint(params) {
1861
+ const estimateMintRequest = {
1862
+ destinationAddress: params.destinationAddress,
1863
+ feeRate: params.feeRate,
1864
+ repeats: params.repeats,
1865
+ runeName: params.runeName,
1866
+ appServiceFee: params.appServiceFee,
1867
+ appServiceFeeAddress: params.appServiceFeeAddress
1868
+ };
1869
+ const response = await getRunesApiClient(
1870
+ params.network
1871
+ ).estimateMintCost(estimateMintRequest);
1872
+ if (response.data) {
1873
+ return {
1874
+ status: "success",
1875
+ result: response.data
1876
+ };
1877
+ }
1819
1878
  return {
1820
1879
  status: "error",
1821
- error: response.error
1880
+ error: {
1881
+ code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
1882
+ message: response.error.message
1883
+ }
1822
1884
  };
1823
1885
  }
1824
- if (v25.is(rpcSuccessResponseMessageSchema, response)) {
1886
+ async estimateEtch(params) {
1887
+ const estimateEtchRequest = {
1888
+ destinationAddress: params.destinationAddress,
1889
+ feeRate: params.feeRate,
1890
+ runeName: params.runeName,
1891
+ divisibility: params.divisibility,
1892
+ symbol: params.symbol,
1893
+ premine: params.premine,
1894
+ isMintable: params.isMintable,
1895
+ terms: params.terms,
1896
+ inscriptionDetails: params.inscriptionDetails,
1897
+ delegateInscriptionId: params.delegateInscriptionId,
1898
+ appServiceFee: params.appServiceFee,
1899
+ appServiceFeeAddress: params.appServiceFeeAddress
1900
+ };
1901
+ const response = await getRunesApiClient(params.network).estimateEtchCost(estimateEtchRequest);
1902
+ if (response.data) {
1903
+ return {
1904
+ status: "success",
1905
+ result: response.data
1906
+ };
1907
+ }
1825
1908
  return {
1826
- status: "success",
1827
- result: response.result
1909
+ status: "error",
1910
+ error: {
1911
+ code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
1912
+ message: response.error.message
1913
+ }
1828
1914
  };
1829
1915
  }
1830
- return {
1831
- status: "error",
1832
- error: {
1833
- code: -32603 /* INTERNAL_ERROR */,
1834
- message: "Received unknown response from provider.",
1835
- data: response
1916
+ async getOrder(params) {
1917
+ const response = await getRunesApiClient(params.network).getOrder(params.id);
1918
+ if (response.data) {
1919
+ return {
1920
+ status: "success",
1921
+ result: response.data
1922
+ };
1836
1923
  }
1837
- };
1838
- };
1839
- var addListener = (...rawArgs) => {
1840
- const [listenerInfo, providerId] = (() => {
1841
- if (rawArgs.length === 1) {
1842
- return [rawArgs[0], void 0];
1924
+ return {
1925
+ status: "error",
1926
+ error: {
1927
+ code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
1928
+ message: response.error.message
1929
+ }
1930
+ };
1931
+ }
1932
+ async estimateRbfOrder(params) {
1933
+ const rbfOrderRequest = {
1934
+ newFeeRate: params.newFeeRate,
1935
+ orderId: params.orderId
1936
+ };
1937
+ const response = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
1938
+ if (response.data) {
1939
+ return {
1940
+ status: "success",
1941
+ result: {
1942
+ fundingAddress: response.data.fundingAddress,
1943
+ rbfCost: response.data.rbfCost
1944
+ }
1945
+ };
1843
1946
  }
1844
- if (rawArgs.length === 2) {
1845
- if (typeof rawArgs[1] === "function") {
1846
- return [
1947
+ return {
1948
+ status: "error",
1949
+ error: {
1950
+ code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
1951
+ message: response.error.message
1952
+ }
1953
+ };
1954
+ }
1955
+ async rbfOrder(params) {
1956
+ try {
1957
+ const rbfOrderRequest = {
1958
+ newFeeRate: params.newFeeRate,
1959
+ orderId: params.orderId
1960
+ };
1961
+ const orderResponse = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
1962
+ if (!orderResponse.data) {
1963
+ return {
1964
+ status: "error",
1965
+ error: {
1966
+ code: orderResponse.error.code === 400 || orderResponse.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
1967
+ message: orderResponse.error.message
1968
+ }
1969
+ };
1970
+ }
1971
+ const paymentResponse = await this.requestInternal("sendTransfer", {
1972
+ recipients: [
1847
1973
  {
1848
- eventName: rawArgs[0],
1849
- cb: rawArgs[1]
1850
- },
1851
- void 0
1852
- ];
1853
- } else {
1854
- return rawArgs;
1974
+ address: orderResponse.data.fundingAddress,
1975
+ amount: orderResponse.data.rbfCost
1976
+ }
1977
+ ]
1978
+ });
1979
+ if (paymentResponse.status !== "success") {
1980
+ return paymentResponse;
1855
1981
  }
1982
+ return {
1983
+ status: "success",
1984
+ result: {
1985
+ fundingAddress: orderResponse.data.fundingAddress,
1986
+ orderId: rbfOrderRequest.orderId,
1987
+ fundRBFTransactionId: paymentResponse.result.txid
1988
+ }
1989
+ };
1990
+ } catch (error) {
1991
+ return {
1992
+ status: "error",
1993
+ error: {
1994
+ code: -32603 /* INTERNAL_ERROR */,
1995
+ message: error.message
1996
+ }
1997
+ };
1856
1998
  }
1857
- if (rawArgs.length === 3) {
1858
- return [
1859
- {
1860
- eventName: rawArgs[0],
1861
- cb: rawArgs[1]
1862
- },
1863
- rawArgs[2]
1864
- ];
1865
- }
1866
- throw new Error("Unexpected number of arguments. Expecting 2 (or 3 for legacy requests).", {
1867
- cause: rawArgs
1868
- });
1869
- })();
1870
- let provider = window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
1871
- if (providerId) {
1872
- provider = getProviderById(providerId);
1873
1999
  }
1874
- if (!provider) {
1875
- throw new Error("no wallet provider was found");
1876
- }
1877
- if (!provider.addListener) {
1878
- console.error(
1879
- `The wallet provider you are using does not support the addListener method. Please update your wallet provider.`
1880
- );
1881
- return () => {
1882
- };
2000
+ async request(method, params) {
2001
+ switch (method) {
2002
+ case "runes_mint":
2003
+ return this.mintRunes(params);
2004
+ case "runes_etch":
2005
+ return this.etchRunes(params);
2006
+ case "runes_estimateMint":
2007
+ return this.estimateMint(params);
2008
+ case "runes_estimateEtch":
2009
+ return this.estimateEtch(params);
2010
+ case "runes_getOrder": {
2011
+ return this.getOrder(params);
2012
+ }
2013
+ case "runes_estimateRbfOrder": {
2014
+ return this.estimateRbfOrder(params);
2015
+ }
2016
+ case "runes_rbfOrder": {
2017
+ return this.rbfOrder(params);
2018
+ }
2019
+ default:
2020
+ return this.requestInternal(method, params);
2021
+ }
1883
2022
  }
1884
- return provider.addListener(listenerInfo);
2023
+ };
2024
+
2025
+ // src/adapters/xverse.ts
2026
+ var XverseAdapter = class extends SatsConnectAdapter {
2027
+ id = DefaultAdaptersInfo.xverse.id;
2028
+ requestInternal = async (method, params) => {
2029
+ return request(method, params, this.id);
2030
+ };
2031
+ addListener = (listenerInfo) => {
2032
+ return addListener(listenerInfo, this.id);
2033
+ };
1885
2034
  };
1886
2035
 
1887
2036
  // src/adapters/unisat.ts
2037
+ import { AddressType as AddressType2, getAddressInfo } from "bitcoin-address-validation";
2038
+ import { Buffer } from "buffer";
1888
2039
  function convertSignInputsToInputType(signInputs) {
1889
2040
  let result = [];
1890
2041
  if (!signInputs) {
@@ -2070,77 +2221,32 @@ var UnisatAdapter = class extends SatsConnectAdapter {
2070
2221
  };
2071
2222
  };
2072
2223
 
2073
- // src/adapters/xverse/sanitizeRequest.ts
2074
- var sanitizeRequest = (method, params, providerInfo) => {
2075
- try {
2076
- const [major, minor, patch] = providerInfo.version.split(".").map((part) => parseInt(part, 10));
2077
- const platform = providerInfo.platform;
2078
- if (
2079
- // platform is missing for versions < 1.5.0 on web and < 1.55.0 on mobile
2080
- !platform || platform === "web" /* Web */ && major <= 1 && minor <= 4 || platform === "mobile" /* Mobile */ && major <= 1 && minor <= 54
2081
- ) {
2082
- const v1Sanitized = sanitizeAddressPurposeRequest(method, params);
2083
- method = v1Sanitized.method;
2084
- params = v1Sanitized.params;
2085
- }
2086
- } catch {
2087
- }
2088
- return { method, params };
2089
- };
2090
- var sanitizeAddressPurposeRequest = (method, params) => {
2091
- const filterPurposes = (purposes) => purposes?.filter(
2092
- (purpose) => purpose !== "spark" /* Spark */ && purpose !== "starknet" /* Starknet */
2093
- );
2094
- if (method === "wallet_connect") {
2095
- const typedParams = params;
2096
- if (!typedParams) {
2097
- return { method, params };
2098
- }
2099
- const { addresses, ...rest } = typedParams;
2100
- const overrideParams = {
2101
- ...rest,
2102
- addresses: filterPurposes(addresses)
2103
- };
2104
- return { method, params: overrideParams };
2105
- }
2106
- if (method === "getAccounts") {
2107
- const typedParams = params;
2108
- const { purposes, ...rest } = typedParams;
2109
- const overrideParams = { ...rest, purposes: filterPurposes(purposes) };
2110
- return { method, params: overrideParams };
2111
- }
2112
- if (method === "getAddresses") {
2113
- const typedParams = params;
2114
- const { purposes, ...rest } = typedParams;
2115
- const overrideParams = { ...rest, purposes: filterPurposes(purposes) };
2116
- return { method, params: overrideParams };
2117
- }
2118
- return { method, params };
2119
- };
2120
-
2121
- // src/adapters/xverse/index.ts
2122
- var XverseAdapter = class extends SatsConnectAdapter {
2123
- id = DefaultAdaptersInfo.xverse.id;
2124
- providerInfo;
2224
+ // src/adapters/fordefi.ts
2225
+ var FordefiAdapter = class extends SatsConnectAdapter {
2226
+ id = DefaultAdaptersInfo.fordefi.id;
2125
2227
  requestInternal = async (method, params) => {
2126
- if (!this.providerInfo) {
2127
- const infoResult = await request("getInfo", null, this.id);
2128
- if (infoResult.status === "success") {
2129
- this.providerInfo = infoResult.result;
2130
- }
2228
+ const provider = getProviderById(this.id);
2229
+ if (!provider) {
2230
+ throw new Error("no wallet provider was found");
2131
2231
  }
2132
- if (this.providerInfo) {
2133
- const sanitized = sanitizeRequest(method, params, this.providerInfo);
2134
- if (sanitized.overrideResponse) {
2135
- return sanitized.overrideResponse;
2136
- }
2137
- method = sanitized.method;
2138
- params = sanitized.params;
2232
+ if (!method) {
2233
+ throw new Error("A wallet method is required");
2139
2234
  }
2140
- return request(method, params, this.id);
2235
+ return await provider.request(method, params);
2141
2236
  };
2142
- addListener = (listenerInfo) => {
2143
- return addListener(listenerInfo, this.id);
2237
+ addListener = ({ eventName, cb }) => {
2238
+ const provider = getProviderById(this.id);
2239
+ if (!provider) {
2240
+ throw new Error("no wallet provider was found");
2241
+ }
2242
+ if (!provider.addListener) {
2243
+ console.error(
2244
+ `The wallet provider you are using does not support the addListener method. Please update your wallet provider.`
2245
+ );
2246
+ return () => {
2247
+ };
2248
+ }
2249
+ return provider.addListener(eventName, cb);
2144
2250
  };
2145
2251
  };
2146
2252
 
@@ -2406,7 +2512,6 @@ export {
2406
2512
  DefaultAdaptersInfo,
2407
2513
  MessageSigningProtocols,
2408
2514
  PermissionRequestParams,
2409
- ProviderPlatform,
2410
2515
  RpcErrorCode,
2411
2516
  RpcIdSchema,
2412
2517
  SatsConnectAdapter,
@@ -2542,6 +2647,22 @@ export {
2542
2647
  signPsbtRequestMessageSchema,
2543
2648
  signPsbtResultSchema,
2544
2649
  signTransaction,
2650
+ sparkFlashnetAddLiquidityIntentSchema,
2651
+ sparkFlashnetClawbackIntentSchema,
2652
+ sparkFlashnetConfirmInitialDepositIntentSchema,
2653
+ sparkFlashnetCreateConstantProductPoolIntentSchema,
2654
+ sparkFlashnetCreateSingleSidedPoolIntentSchema,
2655
+ sparkFlashnetGetJwtMethodName,
2656
+ sparkFlashnetGetJwtParamsSchema,
2657
+ sparkFlashnetGetJwtRequestMessageSchema,
2658
+ sparkFlashnetGetJwtResultSchema,
2659
+ sparkFlashnetRemoveLiquidityIntentSchema,
2660
+ sparkFlashnetRouteSwapIntentSchema,
2661
+ sparkFlashnetSignIntentMethodName,
2662
+ sparkFlashnetSignIntentParamsSchema,
2663
+ sparkFlashnetSignIntentRequestMessageSchema,
2664
+ sparkFlashnetSignIntentResultSchema,
2665
+ sparkFlashnetSwapIntentSchema,
2545
2666
  sparkGetAddressesMethodName,
2546
2667
  sparkGetAddressesParamsSchema,
2547
2668
  sparkGetAddressesRequestMessageSchema,