@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.js CHANGED
@@ -37,7 +37,6 @@ __export(index_exports, {
37
37
  DefaultAdaptersInfo: () => DefaultAdaptersInfo,
38
38
  MessageSigningProtocols: () => MessageSigningProtocols,
39
39
  PermissionRequestParams: () => PermissionRequestParams,
40
- ProviderPlatform: () => ProviderPlatform,
41
40
  RpcErrorCode: () => RpcErrorCode,
42
41
  RpcIdSchema: () => RpcIdSchema,
43
42
  SatsConnectAdapter: () => SatsConnectAdapter,
@@ -173,6 +172,22 @@ __export(index_exports, {
173
172
  signPsbtRequestMessageSchema: () => signPsbtRequestMessageSchema,
174
173
  signPsbtResultSchema: () => signPsbtResultSchema,
175
174
  signTransaction: () => signTransaction,
175
+ sparkFlashnetAddLiquidityIntentSchema: () => sparkFlashnetAddLiquidityIntentSchema,
176
+ sparkFlashnetClawbackIntentSchema: () => sparkFlashnetClawbackIntentSchema,
177
+ sparkFlashnetConfirmInitialDepositIntentSchema: () => sparkFlashnetConfirmInitialDepositIntentSchema,
178
+ sparkFlashnetCreateConstantProductPoolIntentSchema: () => sparkFlashnetCreateConstantProductPoolIntentSchema,
179
+ sparkFlashnetCreateSingleSidedPoolIntentSchema: () => sparkFlashnetCreateSingleSidedPoolIntentSchema,
180
+ sparkFlashnetGetJwtMethodName: () => sparkFlashnetGetJwtMethodName,
181
+ sparkFlashnetGetJwtParamsSchema: () => sparkFlashnetGetJwtParamsSchema,
182
+ sparkFlashnetGetJwtRequestMessageSchema: () => sparkFlashnetGetJwtRequestMessageSchema,
183
+ sparkFlashnetGetJwtResultSchema: () => sparkFlashnetGetJwtResultSchema,
184
+ sparkFlashnetRemoveLiquidityIntentSchema: () => sparkFlashnetRemoveLiquidityIntentSchema,
185
+ sparkFlashnetRouteSwapIntentSchema: () => sparkFlashnetRouteSwapIntentSchema,
186
+ sparkFlashnetSignIntentMethodName: () => sparkFlashnetSignIntentMethodName,
187
+ sparkFlashnetSignIntentParamsSchema: () => sparkFlashnetSignIntentParamsSchema,
188
+ sparkFlashnetSignIntentRequestMessageSchema: () => sparkFlashnetSignIntentRequestMessageSchema,
189
+ sparkFlashnetSignIntentResultSchema: () => sparkFlashnetSignIntentResultSchema,
190
+ sparkFlashnetSwapIntentSchema: () => sparkFlashnetSwapIntentSchema,
176
191
  sparkGetAddressesMethodName: () => sparkGetAddressesMethodName,
177
192
  sparkGetAddressesParamsSchema: () => sparkGetAddressesParamsSchema,
178
193
  sparkGetAddressesRequestMessageSchema: () => sparkGetAddressesRequestMessageSchema,
@@ -233,8 +248,67 @@ __export(index_exports, {
233
248
  });
234
249
  module.exports = __toCommonJS(index_exports);
235
250
 
236
- // src/types.ts
251
+ // src/provider/types.ts
252
+ var v4 = __toESM(require("valibot"));
253
+
254
+ // src/addresses/index.ts
255
+ var import_jsontokens = require("jsontokens");
256
+
257
+ // src/addresses/types.ts
258
+ var v2 = __toESM(require("valibot"));
259
+
260
+ // src/request/types/common.ts
237
261
  var v = __toESM(require("valibot"));
262
+ var walletTypes = ["software", "ledger", "keystone"];
263
+ var walletTypeSchema = v.picklist(walletTypes);
264
+
265
+ // src/addresses/types.ts
266
+ var AddressPurpose = /* @__PURE__ */ ((AddressPurpose2) => {
267
+ AddressPurpose2["Ordinals"] = "ordinals";
268
+ AddressPurpose2["Payment"] = "payment";
269
+ AddressPurpose2["Stacks"] = "stacks";
270
+ AddressPurpose2["Starknet"] = "starknet";
271
+ AddressPurpose2["Spark"] = "spark";
272
+ return AddressPurpose2;
273
+ })(AddressPurpose || {});
274
+ var AddressType = /* @__PURE__ */ ((AddressType3) => {
275
+ AddressType3["p2pkh"] = "p2pkh";
276
+ AddressType3["p2sh"] = "p2sh";
277
+ AddressType3["p2wpkh"] = "p2wpkh";
278
+ AddressType3["p2wsh"] = "p2wsh";
279
+ AddressType3["p2tr"] = "p2tr";
280
+ AddressType3["stacks"] = "stacks";
281
+ AddressType3["starknet"] = "starknet";
282
+ AddressType3["spark"] = "spark";
283
+ return AddressType3;
284
+ })(AddressType || {});
285
+ var addressSchema = v2.object({
286
+ address: v2.string(),
287
+ publicKey: v2.string(),
288
+ purpose: v2.enum(AddressPurpose),
289
+ addressType: v2.enum(AddressType),
290
+ walletType: walletTypeSchema
291
+ });
292
+
293
+ // src/addresses/index.ts
294
+ var getAddress = async (options) => {
295
+ const provider = await getProviderOrThrow(options.getProvider);
296
+ const { purposes } = options.payload;
297
+ if (!purposes) {
298
+ throw new Error("Address purposes are required");
299
+ }
300
+ try {
301
+ const request2 = (0, import_jsontokens.createUnsecuredToken)(options.payload);
302
+ const response = await provider.connect(request2);
303
+ options.onFinish?.(response);
304
+ } catch (error) {
305
+ console.error("[Connect] Error during address request", error);
306
+ options.onCancel?.();
307
+ }
308
+ };
309
+
310
+ // src/types.ts
311
+ var v3 = __toESM(require("valibot"));
238
312
  var BitcoinNetworkType = /* @__PURE__ */ ((BitcoinNetworkType2) => {
239
313
  BitcoinNetworkType2["Mainnet"] = "Mainnet";
240
314
  BitcoinNetworkType2["Testnet"] = "Testnet";
@@ -258,22 +332,22 @@ var SparkNetworkType = /* @__PURE__ */ ((SparkNetworkType2) => {
258
332
  SparkNetworkType2["Regtest"] = "regtest";
259
333
  return SparkNetworkType2;
260
334
  })(SparkNetworkType || {});
261
- var RpcIdSchema = v.optional(v.union([v.string(), v.number(), v.null()]));
262
- var rpcRequestMessageSchema = v.object({
263
- jsonrpc: v.literal("2.0"),
264
- method: v.string(),
265
- params: v.optional(
266
- v.union([
267
- v.array(v.unknown()),
268
- v.looseObject({}),
335
+ var RpcIdSchema = v3.optional(v3.union([v3.string(), v3.number(), v3.null()]));
336
+ var rpcRequestMessageSchema = v3.object({
337
+ jsonrpc: v3.literal("2.0"),
338
+ method: v3.string(),
339
+ params: v3.optional(
340
+ v3.union([
341
+ v3.array(v3.unknown()),
342
+ v3.looseObject({}),
269
343
  // Note: This is to support current incorrect usage of RPC 2.0. Params need
270
344
  // to be either an array or an object when provided. Changing this now would
271
345
  // be a breaking change, so accepting null values for now. Tracking in
272
346
  // https://linear.app/xverseapp/issue/ENG-4538.
273
- v.null()
347
+ v3.null()
274
348
  ])
275
349
  ),
276
- id: v.unwrap(RpcIdSchema)
350
+ id: v3.unwrap(RpcIdSchema)
277
351
  });
278
352
  var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
279
353
  RpcErrorCode2[RpcErrorCode2["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
@@ -286,647 +360,89 @@ var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
286
360
  RpcErrorCode2[RpcErrorCode2["ACCESS_DENIED"] = -32002] = "ACCESS_DENIED";
287
361
  return RpcErrorCode2;
288
362
  })(RpcErrorCode || {});
289
- var rpcSuccessResponseMessageSchema = v.object({
290
- jsonrpc: v.literal("2.0"),
291
- result: v.nonOptional(v.unknown()),
363
+ var rpcSuccessResponseMessageSchema = v3.object({
364
+ jsonrpc: v3.literal("2.0"),
365
+ result: v3.nonOptional(v3.unknown()),
292
366
  id: RpcIdSchema
293
367
  });
294
- var rpcErrorResponseMessageSchema = v.object({
295
- jsonrpc: v.literal("2.0"),
296
- error: v.nonOptional(v.unknown()),
368
+ var rpcErrorResponseMessageSchema = v3.object({
369
+ jsonrpc: v3.literal("2.0"),
370
+ error: v3.nonOptional(v3.unknown()),
297
371
  id: RpcIdSchema
298
372
  });
299
- var rpcResponseMessageSchema = v.union([
373
+ var rpcResponseMessageSchema = v3.union([
300
374
  rpcSuccessResponseMessageSchema,
301
375
  rpcErrorResponseMessageSchema
302
376
  ]);
303
377
 
304
- // src/runes/api.ts
305
- var import_axios = __toESM(require("axios"));
306
- var urlNetworkSuffix = {
307
- ["Mainnet" /* Mainnet */]: "",
308
- ["Testnet" /* Testnet */]: "-testnet",
309
- ["Testnet4" /* Testnet4 */]: "-testnet4",
310
- ["Signet" /* Signet */]: "-signet"
311
- };
312
- var ORDINALS_API_BASE_URL = (network = "Mainnet" /* Mainnet */) => {
313
- if (network === "Regtest" /* Regtest */) {
314
- throw new Error(`Ordinals API does not support ${network} network`);
315
- }
316
- return `https://ordinals${urlNetworkSuffix[network]}.xverse.app/v1`;
317
- };
318
- var RunesApi = class {
319
- client;
320
- constructor(network) {
321
- this.client = import_axios.default.create({
322
- baseURL: ORDINALS_API_BASE_URL(network)
323
- });
378
+ // src/provider/types.ts
379
+ var accountChangeEventName = "accountChange";
380
+ var accountChangeSchema = v4.object({
381
+ type: v4.literal(accountChangeEventName),
382
+ addresses: v4.optional(v4.array(addressSchema))
383
+ });
384
+ var networkChangeEventName = "networkChange";
385
+ var networkChangeSchema = v4.object({
386
+ type: v4.literal(networkChangeEventName),
387
+ bitcoin: v4.object({
388
+ name: v4.enum(BitcoinNetworkType)
389
+ }),
390
+ stacks: v4.object({
391
+ name: v4.string()
392
+ }),
393
+ addresses: v4.optional(v4.array(addressSchema))
394
+ });
395
+ var disconnectEventName = "disconnect";
396
+ var disconnectSchema = v4.object({
397
+ type: v4.literal(disconnectEventName)
398
+ });
399
+ var walletEventSchema = v4.variant("type", [
400
+ accountChangeSchema,
401
+ networkChangeSchema,
402
+ disconnectSchema
403
+ ]);
404
+
405
+ // src/provider/index.ts
406
+ async function getProviderOrThrow(getProvider) {
407
+ const provider = await getProvider?.() || window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
408
+ if (!provider) {
409
+ throw new Error("No Bitcoin wallet installed");
324
410
  }
325
- parseError = (error) => {
326
- return {
327
- code: error.response?.status,
328
- message: JSON.stringify(error.response?.data)
329
- };
330
- };
331
- estimateMintCost = async (mintParams) => {
332
- try {
333
- const response = await this.client.post("/runes/mint/estimate", {
334
- ...mintParams
335
- });
336
- return {
337
- data: response.data
338
- };
339
- } catch (error) {
340
- const err = error;
341
- return {
342
- error: this.parseError(err)
343
- };
344
- }
345
- };
346
- estimateEtchCost = async (etchParams) => {
347
- try {
348
- const response = await this.client.post("/runes/etch/estimate", {
349
- ...etchParams
350
- });
351
- return {
352
- data: response.data
353
- };
354
- } catch (error) {
355
- const err = error;
356
- return {
357
- error: this.parseError(err)
358
- };
359
- }
360
- };
361
- createMintOrder = async (mintOrderParams) => {
362
- try {
363
- const response = await this.client.post("/runes/mint/orders", {
364
- ...mintOrderParams
365
- });
366
- return {
367
- data: response.data
368
- };
369
- } catch (error) {
370
- const err = error;
371
- return {
372
- error: this.parseError(err)
373
- };
374
- }
375
- };
376
- createEtchOrder = async (etchOrderParams) => {
377
- try {
378
- const response = await this.client.post("/runes/etch/orders", {
379
- ...etchOrderParams
380
- });
381
- return {
382
- data: response.data
383
- };
384
- } catch (error) {
385
- const err = error;
386
- return {
387
- error: this.parseError(err)
388
- };
389
- }
390
- };
391
- executeMint = async (orderId, fundTransactionId) => {
392
- try {
393
- const response = await this.client.post(`/runes/mint/orders/${orderId}/execute`, {
394
- fundTransactionId
395
- });
396
- return {
397
- data: response.data
398
- };
399
- } catch (error) {
400
- const err = error;
401
- return {
402
- error: this.parseError(err)
403
- };
404
- }
405
- };
406
- executeEtch = async (orderId, fundTransactionId) => {
407
- try {
408
- const response = await this.client.post(`/runes/etch/orders/${orderId}/execute`, {
409
- fundTransactionId
410
- });
411
- return {
412
- data: response.data
413
- };
414
- } catch (error) {
415
- const err = error;
416
- return {
417
- error: this.parseError(err)
418
- };
419
- }
420
- };
421
- getOrder = async (orderId) => {
422
- try {
423
- const response = await this.client.get(`/orders/${orderId}`);
424
- return {
425
- data: response.data
426
- };
427
- } catch (error) {
428
- const err = error;
429
- return {
430
- error: this.parseError(err)
431
- };
432
- }
433
- };
434
- rbfOrder = async (rbfRequest) => {
435
- const { orderId, newFeeRate } = rbfRequest;
436
- try {
437
- const response = await this.client.post(`/orders/${orderId}/rbf-estimate`, {
438
- newFeeRate
439
- });
440
- return {
441
- data: response.data
442
- };
443
- } catch (error) {
444
- const err = error;
411
+ return provider;
412
+ }
413
+ function getProviders() {
414
+ if (!window.btc_providers) window.btc_providers = [];
415
+ return window.btc_providers;
416
+ }
417
+ function getProviderById(providerId) {
418
+ return providerId?.split(".").reduce((acc, part) => acc?.[part], window);
419
+ }
420
+ function isProviderInstalled(providerId) {
421
+ return !!getProviderById(providerId);
422
+ }
423
+ function setDefaultProvider(providerId) {
424
+ localStorage.setItem("sats-connect_defaultProvider", providerId);
425
+ }
426
+ function getDefaultProvider() {
427
+ return localStorage.getItem("sats-connect_defaultProvider");
428
+ }
429
+ function removeDefaultProvider() {
430
+ localStorage.removeItem("sats-connect_defaultProvider");
431
+ }
432
+ function getSupportedWallets() {
433
+ const wallets = Object.values(DefaultAdaptersInfo).map((provider) => {
434
+ {
445
435
  return {
446
- error: this.parseError(err)
447
- };
448
- }
449
- };
450
- };
451
- var clients = {};
452
- var getRunesApiClient = (network = "Mainnet" /* Mainnet */) => {
453
- if (!clients[network]) {
454
- clients[network] = new RunesApi(network);
455
- }
456
- return clients[network];
457
- };
458
-
459
- // src/adapters/satsConnectAdapter.ts
460
- var SatsConnectAdapter = class {
461
- async mintRunes(params) {
462
- try {
463
- const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
464
- if (walletInfo && walletInfo.status === "success") {
465
- const isMintSupported = walletInfo.result.methods?.includes("runes_mint");
466
- if (isMintSupported) {
467
- const response = await this.requestInternal("runes_mint", params);
468
- if (response) {
469
- if (response.status === "success") {
470
- return response;
471
- }
472
- if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
473
- return response;
474
- }
475
- }
476
- }
477
- }
478
- const mintRequest = {
479
- destinationAddress: params.destinationAddress,
480
- feeRate: params.feeRate,
481
- refundAddress: params.refundAddress,
482
- repeats: params.repeats,
483
- runeName: params.runeName,
484
- appServiceFee: params.appServiceFee,
485
- appServiceFeeAddress: params.appServiceFeeAddress
486
- };
487
- const orderResponse = await new RunesApi(params.network).createMintOrder(mintRequest);
488
- if (!orderResponse.data) {
489
- return {
490
- status: "error",
491
- error: {
492
- code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
493
- message: orderResponse.error.message
494
- }
495
- };
496
- }
497
- const paymentResponse = await this.requestInternal("sendTransfer", {
498
- recipients: [
499
- {
500
- address: orderResponse.data.fundAddress,
501
- amount: orderResponse.data.fundAmount
502
- }
503
- ]
504
- });
505
- if (paymentResponse.status !== "success") {
506
- return paymentResponse;
507
- }
508
- await new RunesApi(params.network).executeMint(
509
- orderResponse.data.orderId,
510
- paymentResponse.result.txid
511
- );
512
- return {
513
- status: "success",
514
- result: {
515
- orderId: orderResponse.data.orderId,
516
- fundTransactionId: paymentResponse.result.txid,
517
- fundingAddress: orderResponse.data.fundAddress
518
- }
519
- };
520
- } catch (error) {
521
- return {
522
- status: "error",
523
- error: {
524
- code: -32603 /* INTERNAL_ERROR */,
525
- message: error.message
526
- }
527
- };
528
- }
529
- }
530
- async etchRunes(params) {
531
- const etchRequest = {
532
- destinationAddress: params.destinationAddress,
533
- refundAddress: params.refundAddress,
534
- feeRate: params.feeRate,
535
- runeName: params.runeName,
536
- divisibility: params.divisibility,
537
- symbol: params.symbol,
538
- premine: params.premine,
539
- isMintable: params.isMintable,
540
- terms: params.terms,
541
- inscriptionDetails: params.inscriptionDetails,
542
- delegateInscriptionId: params.delegateInscriptionId,
543
- appServiceFee: params.appServiceFee,
544
- appServiceFeeAddress: params.appServiceFeeAddress
545
- };
546
- try {
547
- const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
548
- if (walletInfo && walletInfo.status === "success") {
549
- const isEtchSupported = walletInfo.result.methods?.includes("runes_etch");
550
- if (isEtchSupported) {
551
- const response = await this.requestInternal("runes_etch", params);
552
- if (response) {
553
- if (response.status === "success") {
554
- return response;
555
- }
556
- if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
557
- return response;
558
- }
559
- }
560
- }
561
- }
562
- const orderResponse = await new RunesApi(params.network).createEtchOrder(etchRequest);
563
- if (!orderResponse.data) {
564
- return {
565
- status: "error",
566
- error: {
567
- code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
568
- message: orderResponse.error.message
569
- }
570
- };
571
- }
572
- const paymentResponse = await this.requestInternal("sendTransfer", {
573
- recipients: [
574
- {
575
- address: orderResponse.data.fundAddress,
576
- amount: orderResponse.data.fundAmount
577
- }
578
- ]
579
- });
580
- if (paymentResponse.status !== "success") {
581
- return paymentResponse;
582
- }
583
- await new RunesApi(params.network).executeEtch(
584
- orderResponse.data.orderId,
585
- paymentResponse.result.txid
586
- );
587
- return {
588
- status: "success",
589
- result: {
590
- orderId: orderResponse.data.orderId,
591
- fundTransactionId: paymentResponse.result.txid,
592
- fundingAddress: orderResponse.data.fundAddress
593
- }
594
- };
595
- } catch (error) {
596
- return {
597
- status: "error",
598
- error: {
599
- code: -32603 /* INTERNAL_ERROR */,
600
- message: error.message
601
- }
602
- };
603
- }
604
- }
605
- async estimateMint(params) {
606
- const estimateMintRequest = {
607
- destinationAddress: params.destinationAddress,
608
- feeRate: params.feeRate,
609
- repeats: params.repeats,
610
- runeName: params.runeName,
611
- appServiceFee: params.appServiceFee,
612
- appServiceFeeAddress: params.appServiceFeeAddress
613
- };
614
- const response = await getRunesApiClient(
615
- params.network
616
- ).estimateMintCost(estimateMintRequest);
617
- if (response.data) {
618
- return {
619
- status: "success",
620
- result: response.data
621
- };
622
- }
623
- return {
624
- status: "error",
625
- error: {
626
- code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
627
- message: response.error.message
628
- }
629
- };
630
- }
631
- async estimateEtch(params) {
632
- const estimateEtchRequest = {
633
- destinationAddress: params.destinationAddress,
634
- feeRate: params.feeRate,
635
- runeName: params.runeName,
636
- divisibility: params.divisibility,
637
- symbol: params.symbol,
638
- premine: params.premine,
639
- isMintable: params.isMintable,
640
- terms: params.terms,
641
- inscriptionDetails: params.inscriptionDetails,
642
- delegateInscriptionId: params.delegateInscriptionId,
643
- appServiceFee: params.appServiceFee,
644
- appServiceFeeAddress: params.appServiceFeeAddress
645
- };
646
- const response = await getRunesApiClient(params.network).estimateEtchCost(estimateEtchRequest);
647
- if (response.data) {
648
- return {
649
- status: "success",
650
- result: response.data
651
- };
652
- }
653
- return {
654
- status: "error",
655
- error: {
656
- code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
657
- message: response.error.message
658
- }
659
- };
660
- }
661
- async getOrder(params) {
662
- const response = await getRunesApiClient(params.network).getOrder(params.id);
663
- if (response.data) {
664
- return {
665
- status: "success",
666
- result: response.data
667
- };
668
- }
669
- return {
670
- status: "error",
671
- error: {
672
- code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
673
- message: response.error.message
674
- }
675
- };
676
- }
677
- async estimateRbfOrder(params) {
678
- const rbfOrderRequest = {
679
- newFeeRate: params.newFeeRate,
680
- orderId: params.orderId
681
- };
682
- const response = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
683
- if (response.data) {
684
- return {
685
- status: "success",
686
- result: {
687
- fundingAddress: response.data.fundingAddress,
688
- rbfCost: response.data.rbfCost
689
- }
690
- };
691
- }
692
- return {
693
- status: "error",
694
- error: {
695
- code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
696
- message: response.error.message
697
- }
698
- };
699
- }
700
- async rbfOrder(params) {
701
- try {
702
- const rbfOrderRequest = {
703
- newFeeRate: params.newFeeRate,
704
- orderId: params.orderId
705
- };
706
- const orderResponse = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
707
- if (!orderResponse.data) {
708
- return {
709
- status: "error",
710
- error: {
711
- code: orderResponse.error.code === 400 || orderResponse.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
712
- message: orderResponse.error.message
713
- }
714
- };
715
- }
716
- const paymentResponse = await this.requestInternal("sendTransfer", {
717
- recipients: [
718
- {
719
- address: orderResponse.data.fundingAddress,
720
- amount: orderResponse.data.rbfCost
721
- }
722
- ]
723
- });
724
- if (paymentResponse.status !== "success") {
725
- return paymentResponse;
726
- }
727
- return {
728
- status: "success",
729
- result: {
730
- fundingAddress: orderResponse.data.fundingAddress,
731
- orderId: rbfOrderRequest.orderId,
732
- fundRBFTransactionId: paymentResponse.result.txid
733
- }
734
- };
735
- } catch (error) {
736
- return {
737
- status: "error",
738
- error: {
739
- code: -32603 /* INTERNAL_ERROR */,
740
- message: error.message
741
- }
742
- };
743
- }
744
- }
745
- async request(method, params) {
746
- switch (method) {
747
- case "runes_mint":
748
- return this.mintRunes(params);
749
- case "runes_etch":
750
- return this.etchRunes(params);
751
- case "runes_estimateMint":
752
- return this.estimateMint(params);
753
- case "runes_estimateEtch":
754
- return this.estimateEtch(params);
755
- case "runes_getOrder": {
756
- return this.getOrder(params);
757
- }
758
- case "runes_estimateRbfOrder": {
759
- return this.estimateRbfOrder(params);
760
- }
761
- case "runes_rbfOrder": {
762
- return this.rbfOrder(params);
763
- }
764
- default:
765
- return this.requestInternal(method, params);
766
- }
767
- }
768
- };
769
-
770
- // src/provider/types.ts
771
- var v4 = __toESM(require("valibot"));
772
-
773
- // src/addresses/index.ts
774
- var import_jsontokens = require("jsontokens");
775
-
776
- // src/addresses/types.ts
777
- var v3 = __toESM(require("valibot"));
778
-
779
- // src/request/types/common.ts
780
- var v2 = __toESM(require("valibot"));
781
- var walletTypes = ["software", "ledger", "keystone"];
782
- var walletTypeSchema = v2.picklist(walletTypes);
783
-
784
- // src/addresses/types.ts
785
- var AddressPurpose = /* @__PURE__ */ ((AddressPurpose2) => {
786
- AddressPurpose2["Ordinals"] = "ordinals";
787
- AddressPurpose2["Payment"] = "payment";
788
- AddressPurpose2["Stacks"] = "stacks";
789
- AddressPurpose2["Starknet"] = "starknet";
790
- AddressPurpose2["Spark"] = "spark";
791
- return AddressPurpose2;
792
- })(AddressPurpose || {});
793
- var AddressType = /* @__PURE__ */ ((AddressType3) => {
794
- AddressType3["p2pkh"] = "p2pkh";
795
- AddressType3["p2sh"] = "p2sh";
796
- AddressType3["p2wpkh"] = "p2wpkh";
797
- AddressType3["p2wsh"] = "p2wsh";
798
- AddressType3["p2tr"] = "p2tr";
799
- AddressType3["stacks"] = "stacks";
800
- AddressType3["starknet"] = "starknet";
801
- AddressType3["spark"] = "spark";
802
- return AddressType3;
803
- })(AddressType || {});
804
- var addressSchema = v3.object({
805
- address: v3.string(),
806
- publicKey: v3.string(),
807
- purpose: v3.enum(AddressPurpose),
808
- addressType: v3.enum(AddressType),
809
- walletType: walletTypeSchema
810
- });
811
-
812
- // src/addresses/index.ts
813
- var getAddress = async (options) => {
814
- const provider = await getProviderOrThrow(options.getProvider);
815
- const { purposes } = options.payload;
816
- if (!purposes) {
817
- throw new Error("Address purposes are required");
818
- }
819
- try {
820
- const request2 = (0, import_jsontokens.createUnsecuredToken)(options.payload);
821
- const response = await provider.connect(request2);
822
- options.onFinish?.(response);
823
- } catch (error) {
824
- console.error("[Connect] Error during address request", error);
825
- options.onCancel?.();
826
- }
827
- };
828
-
829
- // src/provider/types.ts
830
- var accountChangeEventName = "accountChange";
831
- var accountChangeSchema = v4.object({
832
- type: v4.literal(accountChangeEventName),
833
- addresses: v4.optional(v4.array(addressSchema))
834
- });
835
- var networkChangeEventName = "networkChange";
836
- var networkChangeSchema = v4.object({
837
- type: v4.literal(networkChangeEventName),
838
- bitcoin: v4.object({
839
- name: v4.enum(BitcoinNetworkType)
840
- }),
841
- stacks: v4.object({
842
- name: v4.string()
843
- }),
844
- addresses: v4.optional(v4.array(addressSchema))
845
- });
846
- var disconnectEventName = "disconnect";
847
- var disconnectSchema = v4.object({
848
- type: v4.literal(disconnectEventName)
849
- });
850
- var walletEventSchema = v4.variant("type", [
851
- accountChangeSchema,
852
- networkChangeSchema,
853
- disconnectSchema
854
- ]);
855
-
856
- // src/provider/index.ts
857
- async function getProviderOrThrow(getProvider) {
858
- const provider = await getProvider?.() || window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
859
- if (!provider) {
860
- throw new Error("No Bitcoin wallet installed");
861
- }
862
- return provider;
863
- }
864
- function getProviders() {
865
- if (!window.btc_providers) window.btc_providers = [];
866
- return window.btc_providers;
867
- }
868
- function getProviderById(providerId) {
869
- return providerId?.split(".").reduce((acc, part) => acc?.[part], window);
870
- }
871
- function isProviderInstalled(providerId) {
872
- return !!getProviderById(providerId);
873
- }
874
- function setDefaultProvider(providerId) {
875
- localStorage.setItem("sats-connect_defaultProvider", providerId);
876
- }
877
- function getDefaultProvider() {
878
- return localStorage.getItem("sats-connect_defaultProvider");
879
- }
880
- function removeDefaultProvider() {
881
- localStorage.removeItem("sats-connect_defaultProvider");
882
- }
883
- function getSupportedWallets() {
884
- const wallets = Object.values(DefaultAdaptersInfo).map((provider) => {
885
- {
886
- return {
887
- ...provider,
888
- isInstalled: isProviderInstalled(provider.id)
436
+ ...provider,
437
+ isInstalled: isProviderInstalled(provider.id)
889
438
  };
890
439
  }
891
440
  });
892
441
  return wallets;
893
442
  }
894
443
 
895
- // src/adapters/fordefi.ts
896
- var FordefiAdapter = class extends SatsConnectAdapter {
897
- id = DefaultAdaptersInfo.fordefi.id;
898
- requestInternal = async (method, params) => {
899
- const provider = getProviderById(this.id);
900
- if (!provider) {
901
- throw new Error("no wallet provider was found");
902
- }
903
- if (!method) {
904
- throw new Error("A wallet method is required");
905
- }
906
- return await provider.request(method, params);
907
- };
908
- addListener = ({ eventName, cb }) => {
909
- const provider = getProviderById(this.id);
910
- if (!provider) {
911
- throw new Error("no wallet provider was found");
912
- }
913
- if (!provider.addListener) {
914
- console.error(
915
- `The wallet provider you are using does not support the addListener method. Please update your wallet provider.`
916
- );
917
- return () => {
918
- };
919
- }
920
- return provider.addListener(eventName, cb);
921
- };
922
- };
923
-
924
- // src/adapters/unisat.ts
925
- var import_bitcoin_address_validation = require("bitcoin-address-validation");
926
- var import_buffer = require("buffer");
927
-
928
444
  // src/request/index.ts
929
- var v25 = __toESM(require("valibot"));
445
+ var v35 = __toESM(require("valibot"));
930
446
 
931
447
  // src/request/types/btcMethods.ts
932
448
  var v6 = __toESM(require("valibot"));
@@ -1145,11 +661,6 @@ var addNetworkResultSchema = v5.object({
1145
661
  });
1146
662
 
1147
663
  // src/request/types/btcMethods.ts
1148
- var ProviderPlatform = /* @__PURE__ */ ((ProviderPlatform2) => {
1149
- ProviderPlatform2["Web"] = "web";
1150
- ProviderPlatform2["Mobile"] = "mobile";
1151
- return ProviderPlatform2;
1152
- })(ProviderPlatform || {});
1153
664
  var getInfoMethodName = "getInfo";
1154
665
  var getInfoParamsSchema = v6.nullish(v6.null());
1155
666
  var getInfoResultSchema = v6.object({
@@ -1157,10 +668,6 @@ var getInfoResultSchema = v6.object({
1157
668
  * Version of the wallet.
1158
669
  */
1159
670
  version: v6.string(),
1160
- /**
1161
- * The platform the wallet is running on (web or mobile).
1162
- */
1163
- platform: v6.optional(v6.enum(ProviderPlatform)),
1164
671
  /**
1165
672
  * [WBIP](https://wbips.netlify.app/wbips/WBIP002) methods supported by the wallet.
1166
673
  */
@@ -1548,10 +1055,10 @@ var runesTransferRequestMessageSchema = v11.object({
1548
1055
  }).entries
1549
1056
  });
1550
1057
 
1551
- // src/request/types/sparkMethods/getAddresses.ts
1058
+ // src/request/types/sparkMethods/flashnetMethods/getJwt.ts
1552
1059
  var v12 = __toESM(require("valibot"));
1553
- var sparkGetAddressesMethodName = "spark_getAddresses";
1554
- var sparkGetAddressesParamsSchema = v12.nullish(
1060
+ var sparkFlashnetGetJwtMethodName = "spark_flashnet_getJwt";
1061
+ var sparkFlashnetGetJwtParamsSchema = v12.nullish(
1555
1062
  v12.object({
1556
1063
  /**
1557
1064
  * A message to be displayed to the user in the request prompt.
@@ -1559,135 +1066,315 @@ var sparkGetAddressesParamsSchema = v12.nullish(
1559
1066
  message: v12.optional(v12.string())
1560
1067
  })
1561
1068
  );
1562
- var sparkGetAddressesResultSchema = v12.object({
1069
+ var sparkFlashnetGetJwtResultSchema = v12.object({
1070
+ /**
1071
+ * The JWT token for authenticated requests to the Flashnet API.
1072
+ */
1073
+ jwt: v12.string()
1074
+ });
1075
+ var sparkFlashnetGetJwtRequestMessageSchema = v12.object({
1076
+ ...rpcRequestMessageSchema.entries,
1077
+ ...v12.object({
1078
+ method: v12.literal(sparkFlashnetGetJwtMethodName),
1079
+ params: sparkFlashnetGetJwtParamsSchema,
1080
+ id: v12.string()
1081
+ }).entries
1082
+ });
1083
+
1084
+ // src/request/types/sparkMethods/flashnetMethods/intents/addLiquidity.ts
1085
+ var v13 = __toESM(require("valibot"));
1086
+ var sparkFlashnetAddLiquidityIntentSchema = v13.object({
1087
+ type: v13.literal("addLiquidity"),
1088
+ data: v13.object({
1089
+ userPublicKey: v13.string(),
1090
+ poolId: v13.string(),
1091
+ assetAAmount: v13.string(),
1092
+ assetBAmount: v13.string(),
1093
+ assetAMinAmountIn: v13.string(),
1094
+ assetBMinAmountIn: v13.string(),
1095
+ assetATransferId: v13.string(),
1096
+ assetBTransferId: v13.string(),
1097
+ nonce: v13.string()
1098
+ })
1099
+ });
1100
+
1101
+ // src/request/types/sparkMethods/flashnetMethods/intents/clawback.ts
1102
+ var v14 = __toESM(require("valibot"));
1103
+ var sparkFlashnetClawbackIntentSchema = v14.object({
1104
+ type: v14.literal("clawback"),
1105
+ data: v14.object({
1106
+ senderPublicKey: v14.string(),
1107
+ sparkTransferId: v14.string(),
1108
+ lpIdentityPublicKey: v14.string(),
1109
+ nonce: v14.string()
1110
+ })
1111
+ });
1112
+
1113
+ // src/request/types/sparkMethods/flashnetMethods/intents/confirmInitialDeposit.ts
1114
+ var v15 = __toESM(require("valibot"));
1115
+ var sparkFlashnetConfirmInitialDepositIntentSchema = v15.object({
1116
+ type: v15.literal("confirmInitialDeposit"),
1117
+ data: v15.object({
1118
+ poolId: v15.string(),
1119
+ assetASparkTransferId: v15.string(),
1120
+ poolOwnerPublicKey: v15.string(),
1121
+ nonce: v15.string()
1122
+ })
1123
+ });
1124
+
1125
+ // src/request/types/sparkMethods/flashnetMethods/intents/createConstantProductPool.ts
1126
+ var v16 = __toESM(require("valibot"));
1127
+ var sparkFlashnetCreateConstantProductPoolIntentSchema = v16.object({
1128
+ type: v16.literal("createConstantProductPool"),
1129
+ data: v16.object({
1130
+ poolOwnerPublicKey: v16.string(),
1131
+ assetAAddress: v16.string(),
1132
+ assetBAddress: v16.string(),
1133
+ lpFeeRateBps: v16.number(),
1134
+ totalHostFeeRateBps: v16.number(),
1135
+ nonce: v16.string()
1136
+ })
1137
+ });
1138
+
1139
+ // src/request/types/sparkMethods/flashnetMethods/intents/createSingleSidedPool.ts
1140
+ var v17 = __toESM(require("valibot"));
1141
+ var sparkFlashnetCreateSingleSidedPoolIntentSchema = v17.object({
1142
+ type: v17.literal("createSingleSidedPool"),
1143
+ data: v17.object({
1144
+ assetAAddress: v17.string(),
1145
+ assetBAddress: v17.string(),
1146
+ assetAInitialReserve: v17.string(),
1147
+ virtualReserveA: v17.union([v17.number(), v17.string()]),
1148
+ virtualReserveB: v17.union([v17.number(), v17.string()]),
1149
+ threshold: v17.union([v17.number(), v17.string()]),
1150
+ lpFeeRateBps: v17.number(),
1151
+ totalHostFeeRateBps: v17.number(),
1152
+ poolOwnerPublicKey: v17.string(),
1153
+ nonce: v17.string()
1154
+ })
1155
+ });
1156
+
1157
+ // src/request/types/sparkMethods/flashnetMethods/intents/removeLiquidity.ts
1158
+ var v18 = __toESM(require("valibot"));
1159
+ var sparkFlashnetRemoveLiquidityIntentSchema = v18.object({
1160
+ type: v18.literal("removeLiquidity"),
1161
+ data: v18.object({
1162
+ userPublicKey: v18.string(),
1163
+ poolId: v18.string(),
1164
+ lpTokensToRemove: v18.string(),
1165
+ nonce: v18.string()
1166
+ })
1167
+ });
1168
+
1169
+ // src/request/types/sparkMethods/flashnetMethods/intents/routeSwap.ts
1170
+ var v19 = __toESM(require("valibot"));
1171
+ var sparkFlashnetRouteSwapIntentSchema = v19.object({
1172
+ type: v19.literal("executeRouteSwap"),
1173
+ data: v19.object({
1174
+ userPublicKey: v19.string(),
1175
+ initialSparkTransferId: v19.string(),
1176
+ hops: v19.array(
1177
+ v19.object({
1178
+ poolId: v19.string(),
1179
+ assetInAddress: v19.string(),
1180
+ assetOutAddress: v19.string(),
1181
+ hopIntegratorFeeRateBps: v19.optional(v19.number())
1182
+ })
1183
+ ),
1184
+ inputAmount: v19.string(),
1185
+ maxRouteSlippageBps: v19.number(),
1186
+ minAmountOut: v19.string(),
1187
+ defaultIntegratorFeeRateBps: v19.optional(v19.number()),
1188
+ nonce: v19.string()
1189
+ })
1190
+ });
1191
+
1192
+ // src/request/types/sparkMethods/flashnetMethods/intents/swap.ts
1193
+ var v20 = __toESM(require("valibot"));
1194
+ var sparkFlashnetSwapIntentSchema = v20.object({
1195
+ type: v20.literal("executeSwap"),
1196
+ data: v20.object({
1197
+ userPublicKey: v20.string(),
1198
+ poolId: v20.string(),
1199
+ transferId: v20.string(),
1200
+ assetInAddress: v20.string(),
1201
+ assetOutAddress: v20.string(),
1202
+ amountIn: v20.string(),
1203
+ maxSlippageBps: v20.number(),
1204
+ minAmountOut: v20.string(),
1205
+ totalIntegratorFeeRateBps: v20.optional(v20.number()),
1206
+ nonce: v20.string()
1207
+ })
1208
+ });
1209
+
1210
+ // src/request/types/sparkMethods/flashnetMethods/signIntent.ts
1211
+ var v21 = __toESM(require("valibot"));
1212
+ var sparkFlashnetSignIntentMethodName = "spark_flashnet_signIntent";
1213
+ var sparkFlashnetSignIntentParamsSchema = v21.union([
1214
+ sparkFlashnetSwapIntentSchema,
1215
+ sparkFlashnetRouteSwapIntentSchema,
1216
+ sparkFlashnetAddLiquidityIntentSchema,
1217
+ sparkFlashnetClawbackIntentSchema,
1218
+ sparkFlashnetConfirmInitialDepositIntentSchema,
1219
+ sparkFlashnetCreateConstantProductPoolIntentSchema,
1220
+ sparkFlashnetCreateSingleSidedPoolIntentSchema,
1221
+ sparkFlashnetRemoveLiquidityIntentSchema
1222
+ ]);
1223
+ var sparkFlashnetSignIntentResultSchema = v21.object({
1224
+ /**
1225
+ * The signed intent as a hex string.
1226
+ */
1227
+ signature: v21.string()
1228
+ });
1229
+ var sparkFlashnetSignIntentRequestMessageSchema = v21.object({
1230
+ ...rpcRequestMessageSchema.entries,
1231
+ ...v21.object({
1232
+ method: v21.literal(sparkFlashnetSignIntentMethodName),
1233
+ params: sparkFlashnetSignIntentParamsSchema,
1234
+ id: v21.string()
1235
+ }).entries
1236
+ });
1237
+
1238
+ // src/request/types/sparkMethods/getAddresses.ts
1239
+ var v22 = __toESM(require("valibot"));
1240
+ var sparkGetAddressesMethodName = "spark_getAddresses";
1241
+ var sparkGetAddressesParamsSchema = v22.nullish(
1242
+ v22.object({
1243
+ /**
1244
+ * A message to be displayed to the user in the request prompt.
1245
+ */
1246
+ message: v22.optional(v22.string())
1247
+ })
1248
+ );
1249
+ var sparkGetAddressesResultSchema = v22.object({
1563
1250
  /**
1564
1251
  * The addresses generated for the given purposes.
1565
1252
  */
1566
- addresses: v12.array(addressSchema),
1253
+ addresses: v22.array(addressSchema),
1567
1254
  network: getNetworkResultSchema
1568
1255
  });
1569
- var sparkGetAddressesRequestMessageSchema = v12.object({
1256
+ var sparkGetAddressesRequestMessageSchema = v22.object({
1570
1257
  ...rpcRequestMessageSchema.entries,
1571
- ...v12.object({
1572
- method: v12.literal(sparkGetAddressesMethodName),
1258
+ ...v22.object({
1259
+ method: v22.literal(sparkGetAddressesMethodName),
1573
1260
  params: sparkGetAddressesParamsSchema,
1574
- id: v12.string()
1261
+ id: v22.string()
1575
1262
  }).entries
1576
1263
  });
1577
1264
 
1578
1265
  // src/request/types/sparkMethods/getBalance.ts
1579
- var v13 = __toESM(require("valibot"));
1266
+ var v23 = __toESM(require("valibot"));
1580
1267
  var sparkGetBalanceMethodName = "spark_getBalance";
1581
- var sparkGetBalanceParamsSchema = v13.nullish(v13.null());
1582
- var sparkGetBalanceResultSchema = v13.object({
1268
+ var sparkGetBalanceParamsSchema = v23.nullish(v23.null());
1269
+ var sparkGetBalanceResultSchema = v23.object({
1583
1270
  /**
1584
1271
  * The Spark Bitcoin address balance in sats in string form.
1585
1272
  */
1586
- balance: v13.string(),
1587
- tokenBalances: v13.array(
1588
- v13.object({
1273
+ balance: v23.string(),
1274
+ tokenBalances: v23.array(
1275
+ v23.object({
1589
1276
  /* The address balance of the token in string form as it can overflow a js number */
1590
- balance: v13.string(),
1591
- tokenMetadata: v13.object({
1592
- tokenIdentifier: v13.string(),
1593
- tokenName: v13.string(),
1594
- tokenTicker: v13.string(),
1595
- decimals: v13.number(),
1596
- maxSupply: v13.string()
1277
+ balance: v23.string(),
1278
+ tokenMetadata: v23.object({
1279
+ tokenIdentifier: v23.string(),
1280
+ tokenName: v23.string(),
1281
+ tokenTicker: v23.string(),
1282
+ decimals: v23.number(),
1283
+ maxSupply: v23.string()
1597
1284
  })
1598
1285
  })
1599
1286
  )
1600
1287
  });
1601
- var sparkGetBalanceRequestMessageSchema = v13.object({
1288
+ var sparkGetBalanceRequestMessageSchema = v23.object({
1602
1289
  ...rpcRequestMessageSchema.entries,
1603
- ...v13.object({
1604
- method: v13.literal(sparkGetBalanceMethodName),
1290
+ ...v23.object({
1291
+ method: v23.literal(sparkGetBalanceMethodName),
1605
1292
  params: sparkGetBalanceParamsSchema,
1606
- id: v13.string()
1293
+ id: v23.string()
1607
1294
  }).entries
1608
1295
  });
1609
1296
 
1610
1297
  // src/request/types/sparkMethods/transfer.ts
1611
- var v14 = __toESM(require("valibot"));
1298
+ var v24 = __toESM(require("valibot"));
1612
1299
  var sparkTransferMethodName = "spark_transfer";
1613
- var sparkTransferParamsSchema = v14.object({
1300
+ var sparkTransferParamsSchema = v24.object({
1614
1301
  /**
1615
1302
  * Amount of SATS to transfer as a string or number.
1616
1303
  */
1617
- amountSats: v14.union([v14.number(), v14.string()]),
1304
+ amountSats: v24.union([v24.number(), v24.string()]),
1618
1305
  /**
1619
1306
  * The recipient's spark address.
1620
1307
  */
1621
- receiverSparkAddress: v14.string()
1308
+ receiverSparkAddress: v24.string()
1622
1309
  });
1623
- var sparkTransferResultSchema = v14.object({
1310
+ var sparkTransferResultSchema = v24.object({
1624
1311
  /**
1625
1312
  * The ID of the transaction.
1626
1313
  */
1627
- id: v14.string()
1314
+ id: v24.string()
1628
1315
  });
1629
- var sparkTransferRequestMessageSchema = v14.object({
1316
+ var sparkTransferRequestMessageSchema = v24.object({
1630
1317
  ...rpcRequestMessageSchema.entries,
1631
- ...v14.object({
1632
- method: v14.literal(sparkTransferMethodName),
1318
+ ...v24.object({
1319
+ method: v24.literal(sparkTransferMethodName),
1633
1320
  params: sparkTransferParamsSchema,
1634
- id: v14.string()
1321
+ id: v24.string()
1635
1322
  }).entries
1636
1323
  });
1637
1324
 
1638
1325
  // src/request/types/sparkMethods/transferToken.ts
1639
- var v15 = __toESM(require("valibot"));
1326
+ var v25 = __toESM(require("valibot"));
1640
1327
  var sparkTransferTokenMethodName = "spark_transferToken";
1641
- var sparkTransferTokenParamsSchema = v15.object({
1328
+ var sparkTransferTokenParamsSchema = v25.object({
1642
1329
  /**
1643
1330
  * Amount of units of the token to transfer as a string or number.
1644
1331
  */
1645
- tokenAmount: v15.union([v15.number(), v15.string()]),
1332
+ tokenAmount: v25.union([v25.number(), v25.string()]),
1646
1333
  /**
1647
1334
  * The Bech32m token identifier.
1648
1335
  */
1649
- tokenIdentifier: v15.string(),
1336
+ tokenIdentifier: v25.string(),
1650
1337
  /**
1651
1338
  * The recipient's spark address.
1652
1339
  */
1653
- receiverSparkAddress: v15.string()
1340
+ receiverSparkAddress: v25.string()
1654
1341
  });
1655
- var sparkTransferTokenResultSchema = v15.object({
1342
+ var sparkTransferTokenResultSchema = v25.object({
1656
1343
  /**
1657
1344
  * The ID of the transaction.
1658
1345
  */
1659
- id: v15.string()
1346
+ id: v25.string()
1660
1347
  });
1661
- var sparkTransferTokenRequestMessageSchema = v15.object({
1348
+ var sparkTransferTokenRequestMessageSchema = v25.object({
1662
1349
  ...rpcRequestMessageSchema.entries,
1663
- ...v15.object({
1664
- method: v15.literal(sparkTransferTokenMethodName),
1350
+ ...v25.object({
1351
+ method: v25.literal(sparkTransferTokenMethodName),
1665
1352
  params: sparkTransferTokenParamsSchema,
1666
- id: v15.string()
1353
+ id: v25.string()
1667
1354
  }).entries
1668
1355
  });
1669
1356
 
1670
1357
  // src/request/types/stxMethods/callContract.ts
1671
- var v16 = __toESM(require("valibot"));
1358
+ var v26 = __toESM(require("valibot"));
1672
1359
  var stxCallContractMethodName = "stx_callContract";
1673
- var stxCallContractParamsSchema = v16.object({
1360
+ var stxCallContractParamsSchema = v26.object({
1674
1361
  /**
1675
1362
  * The contract principal.
1676
1363
  *
1677
1364
  * E.g. `"SPKE...GD5C.my-contract"`
1678
1365
  */
1679
- contract: v16.string(),
1366
+ contract: v26.string(),
1680
1367
  /**
1681
1368
  * The name of the function to call.
1682
1369
  *
1683
1370
  * Note: spec changes ongoing,
1684
1371
  * https://github.com/stacksgov/sips/pull/166#pullrequestreview-1914236999
1685
1372
  */
1686
- functionName: v16.string(),
1373
+ functionName: v26.string(),
1687
1374
  /**
1688
1375
  * @deprecated in favor of `functionArgs` for @stacks/connect compatibility
1689
1376
  */
1690
- arguments: v16.optional(v16.array(v16.string())),
1377
+ arguments: v26.optional(v26.array(v26.string())),
1691
1378
  /**
1692
1379
  * The function's arguments. The arguments are expected to be hex-encoded
1693
1380
  * strings of Clarity values.
@@ -1702,274 +1389,274 @@ var stxCallContractParamsSchema = v16.object({
1702
1389
  * const hexArgs = functionArgs.map(cvToHex);
1703
1390
  * ```
1704
1391
  */
1705
- functionArgs: v16.optional(v16.array(v16.string())),
1392
+ functionArgs: v26.optional(v26.array(v26.string())),
1706
1393
  /**
1707
1394
  * The post conditions to apply to the contract call.
1708
1395
  */
1709
- postConditions: v16.optional(v16.array(v16.string())),
1396
+ postConditions: v26.optional(v26.array(v26.string())),
1710
1397
  /**
1711
1398
  * The mode to apply to the post conditions.
1712
1399
  */
1713
- postConditionMode: v16.optional(v16.union([v16.literal("allow"), v16.literal("deny")]))
1400
+ postConditionMode: v26.optional(v26.union([v26.literal("allow"), v26.literal("deny")]))
1714
1401
  });
1715
- var stxCallContractResultSchema = v16.object({
1402
+ var stxCallContractResultSchema = v26.object({
1716
1403
  /**
1717
1404
  * The ID of the transaction.
1718
1405
  */
1719
- txid: v16.string(),
1406
+ txid: v26.string(),
1720
1407
  /**
1721
1408
  * A Stacks transaction as a hex-encoded string.
1722
1409
  */
1723
- transaction: v16.string()
1410
+ transaction: v26.string()
1724
1411
  });
1725
- var stxCallContractRequestMessageSchema = v16.object({
1412
+ var stxCallContractRequestMessageSchema = v26.object({
1726
1413
  ...rpcRequestMessageSchema.entries,
1727
- ...v16.object({
1728
- method: v16.literal(stxCallContractMethodName),
1414
+ ...v26.object({
1415
+ method: v26.literal(stxCallContractMethodName),
1729
1416
  params: stxCallContractParamsSchema,
1730
- id: v16.string()
1417
+ id: v26.string()
1731
1418
  }).entries
1732
1419
  });
1733
1420
 
1734
1421
  // src/request/types/stxMethods/deployContract.ts
1735
- var v17 = __toESM(require("valibot"));
1422
+ var v27 = __toESM(require("valibot"));
1736
1423
  var stxDeployContractMethodName = "stx_deployContract";
1737
- var stxDeployContractParamsSchema = v17.object({
1424
+ var stxDeployContractParamsSchema = v27.object({
1738
1425
  /**
1739
1426
  * Name of the contract.
1740
1427
  */
1741
- name: v17.string(),
1428
+ name: v27.string(),
1742
1429
  /**
1743
1430
  * The source code of the Clarity contract.
1744
1431
  */
1745
- clarityCode: v17.string(),
1432
+ clarityCode: v27.string(),
1746
1433
  /**
1747
1434
  * The version of the Clarity contract.
1748
1435
  */
1749
- clarityVersion: v17.optional(v17.number()),
1436
+ clarityVersion: v27.optional(v27.number()),
1750
1437
  /**
1751
1438
  * The post conditions to apply to the contract call.
1752
1439
  */
1753
- postConditions: v17.optional(v17.array(v17.string())),
1440
+ postConditions: v27.optional(v27.array(v27.string())),
1754
1441
  /**
1755
1442
  * The mode to apply to the post conditions.
1756
1443
  */
1757
- postConditionMode: v17.optional(v17.union([v17.literal("allow"), v17.literal("deny")]))
1444
+ postConditionMode: v27.optional(v27.union([v27.literal("allow"), v27.literal("deny")]))
1758
1445
  });
1759
- var stxDeployContractResultSchema = v17.object({
1446
+ var stxDeployContractResultSchema = v27.object({
1760
1447
  /**
1761
1448
  * The ID of the transaction.
1762
1449
  */
1763
- txid: v17.string(),
1450
+ txid: v27.string(),
1764
1451
  /**
1765
1452
  * A Stacks transaction as a hex-encoded string.
1766
1453
  */
1767
- transaction: v17.string()
1454
+ transaction: v27.string()
1768
1455
  });
1769
- var stxDeployContractRequestMessageSchema = v17.object({
1456
+ var stxDeployContractRequestMessageSchema = v27.object({
1770
1457
  ...rpcRequestMessageSchema.entries,
1771
- ...v17.object({
1772
- method: v17.literal(stxDeployContractMethodName),
1458
+ ...v27.object({
1459
+ method: v27.literal(stxDeployContractMethodName),
1773
1460
  params: stxDeployContractParamsSchema,
1774
- id: v17.string()
1461
+ id: v27.string()
1775
1462
  }).entries
1776
1463
  });
1777
1464
 
1778
1465
  // src/request/types/stxMethods/getAccounts.ts
1779
- var v18 = __toESM(require("valibot"));
1466
+ var v28 = __toESM(require("valibot"));
1780
1467
  var stxGetAccountsMethodName = "stx_getAccounts";
1781
- var stxGetAccountsParamsSchema = v18.nullish(v18.null());
1782
- var stxGetAccountsResultSchema = v18.object({
1468
+ var stxGetAccountsParamsSchema = v28.nullish(v28.null());
1469
+ var stxGetAccountsResultSchema = v28.object({
1783
1470
  /**
1784
1471
  * The addresses generated for the given purposes.
1785
1472
  */
1786
- addresses: v18.array(
1787
- v18.object({
1788
- address: v18.string(),
1789
- publicKey: v18.string(),
1790
- gaiaHubUrl: v18.string(),
1791
- gaiaAppKey: v18.string()
1473
+ addresses: v28.array(
1474
+ v28.object({
1475
+ address: v28.string(),
1476
+ publicKey: v28.string(),
1477
+ gaiaHubUrl: v28.string(),
1478
+ gaiaAppKey: v28.string()
1792
1479
  })
1793
1480
  ),
1794
1481
  network: getNetworkResultSchema
1795
1482
  });
1796
- var stxGetAccountsRequestMessageSchema = v18.object({
1483
+ var stxGetAccountsRequestMessageSchema = v28.object({
1797
1484
  ...rpcRequestMessageSchema.entries,
1798
- ...v18.object({
1799
- method: v18.literal(stxGetAccountsMethodName),
1485
+ ...v28.object({
1486
+ method: v28.literal(stxGetAccountsMethodName),
1800
1487
  params: stxGetAccountsParamsSchema,
1801
- id: v18.string()
1488
+ id: v28.string()
1802
1489
  }).entries
1803
1490
  });
1804
1491
 
1805
1492
  // src/request/types/stxMethods/getAddresses.ts
1806
- var v19 = __toESM(require("valibot"));
1493
+ var v29 = __toESM(require("valibot"));
1807
1494
  var stxGetAddressesMethodName = "stx_getAddresses";
1808
- var stxGetAddressesParamsSchema = v19.nullish(
1809
- v19.object({
1495
+ var stxGetAddressesParamsSchema = v29.nullish(
1496
+ v29.object({
1810
1497
  /**
1811
1498
  * A message to be displayed to the user in the request prompt.
1812
1499
  */
1813
- message: v19.optional(v19.string())
1500
+ message: v29.optional(v29.string())
1814
1501
  })
1815
1502
  );
1816
- var stxGetAddressesResultSchema = v19.object({
1503
+ var stxGetAddressesResultSchema = v29.object({
1817
1504
  /**
1818
1505
  * The addresses generated for the given purposes.
1819
1506
  */
1820
- addresses: v19.array(addressSchema),
1507
+ addresses: v29.array(addressSchema),
1821
1508
  network: getNetworkResultSchema
1822
1509
  });
1823
- var stxGetAddressesRequestMessageSchema = v19.object({
1510
+ var stxGetAddressesRequestMessageSchema = v29.object({
1824
1511
  ...rpcRequestMessageSchema.entries,
1825
- ...v19.object({
1826
- method: v19.literal(stxGetAddressesMethodName),
1512
+ ...v29.object({
1513
+ method: v29.literal(stxGetAddressesMethodName),
1827
1514
  params: stxGetAddressesParamsSchema,
1828
- id: v19.string()
1515
+ id: v29.string()
1829
1516
  }).entries
1830
1517
  });
1831
1518
 
1832
1519
  // src/request/types/stxMethods/signMessage.ts
1833
- var v20 = __toESM(require("valibot"));
1520
+ var v30 = __toESM(require("valibot"));
1834
1521
  var stxSignMessageMethodName = "stx_signMessage";
1835
- var stxSignMessageParamsSchema = v20.object({
1522
+ var stxSignMessageParamsSchema = v30.object({
1836
1523
  /**
1837
1524
  * The message to sign.
1838
1525
  */
1839
- message: v20.string()
1526
+ message: v30.string()
1840
1527
  });
1841
- var stxSignMessageResultSchema = v20.object({
1528
+ var stxSignMessageResultSchema = v30.object({
1842
1529
  /**
1843
1530
  * The signature of the message.
1844
1531
  */
1845
- signature: v20.string(),
1532
+ signature: v30.string(),
1846
1533
  /**
1847
1534
  * The public key used to sign the message.
1848
1535
  */
1849
- publicKey: v20.string()
1536
+ publicKey: v30.string()
1850
1537
  });
1851
- var stxSignMessageRequestMessageSchema = v20.object({
1538
+ var stxSignMessageRequestMessageSchema = v30.object({
1852
1539
  ...rpcRequestMessageSchema.entries,
1853
- ...v20.object({
1854
- method: v20.literal(stxSignMessageMethodName),
1540
+ ...v30.object({
1541
+ method: v30.literal(stxSignMessageMethodName),
1855
1542
  params: stxSignMessageParamsSchema,
1856
- id: v20.string()
1543
+ id: v30.string()
1857
1544
  }).entries
1858
1545
  });
1859
1546
 
1860
1547
  // src/request/types/stxMethods/signStructuredMessage.ts
1861
- var v21 = __toESM(require("valibot"));
1548
+ var v31 = __toESM(require("valibot"));
1862
1549
  var stxSignStructuredMessageMethodName = "stx_signStructuredMessage";
1863
- var stxSignStructuredMessageParamsSchema = v21.object({
1550
+ var stxSignStructuredMessageParamsSchema = v31.object({
1864
1551
  /**
1865
1552
  * The domain to be signed.
1866
1553
  */
1867
- domain: v21.string(),
1554
+ domain: v31.string(),
1868
1555
  /**
1869
1556
  * Message payload to be signed.
1870
1557
  */
1871
- message: v21.string(),
1558
+ message: v31.string(),
1872
1559
  /**
1873
1560
  * The public key to sign the message with.
1874
1561
  */
1875
- publicKey: v21.optional(v21.string())
1562
+ publicKey: v31.optional(v31.string())
1876
1563
  });
1877
- var stxSignStructuredMessageResultSchema = v21.object({
1564
+ var stxSignStructuredMessageResultSchema = v31.object({
1878
1565
  /**
1879
1566
  * Signature of the message.
1880
1567
  */
1881
- signature: v21.string(),
1568
+ signature: v31.string(),
1882
1569
  /**
1883
1570
  * Public key as hex-encoded string.
1884
1571
  */
1885
- publicKey: v21.string()
1572
+ publicKey: v31.string()
1886
1573
  });
1887
- var stxSignStructuredMessageRequestMessageSchema = v21.object({
1574
+ var stxSignStructuredMessageRequestMessageSchema = v31.object({
1888
1575
  ...rpcRequestMessageSchema.entries,
1889
- ...v21.object({
1890
- method: v21.literal(stxSignStructuredMessageMethodName),
1576
+ ...v31.object({
1577
+ method: v31.literal(stxSignStructuredMessageMethodName),
1891
1578
  params: stxSignStructuredMessageParamsSchema,
1892
- id: v21.string()
1579
+ id: v31.string()
1893
1580
  }).entries
1894
1581
  });
1895
1582
 
1896
1583
  // src/request/types/stxMethods/signTransaction.ts
1897
- var v22 = __toESM(require("valibot"));
1584
+ var v32 = __toESM(require("valibot"));
1898
1585
  var stxSignTransactionMethodName = "stx_signTransaction";
1899
- var stxSignTransactionParamsSchema = v22.object({
1586
+ var stxSignTransactionParamsSchema = v32.object({
1900
1587
  /**
1901
1588
  * The transaction to sign as a hex-encoded string.
1902
1589
  */
1903
- transaction: v22.string(),
1590
+ transaction: v32.string(),
1904
1591
  /**
1905
1592
  * The public key to sign the transaction with. The wallet may use any key
1906
1593
  * when not provided.
1907
1594
  */
1908
- pubkey: v22.optional(v22.string()),
1595
+ pubkey: v32.optional(v32.string()),
1909
1596
  /**
1910
1597
  * Whether to broadcast the transaction after signing. Defaults to `true`.
1911
1598
  */
1912
- broadcast: v22.optional(v22.boolean())
1599
+ broadcast: v32.optional(v32.boolean())
1913
1600
  });
1914
- var stxSignTransactionResultSchema = v22.object({
1601
+ var stxSignTransactionResultSchema = v32.object({
1915
1602
  /**
1916
1603
  * The signed transaction as a hex-encoded string.
1917
1604
  */
1918
- transaction: v22.string()
1605
+ transaction: v32.string()
1919
1606
  });
1920
- var stxSignTransactionRequestMessageSchema = v22.object({
1607
+ var stxSignTransactionRequestMessageSchema = v32.object({
1921
1608
  ...rpcRequestMessageSchema.entries,
1922
- ...v22.object({
1923
- method: v22.literal(stxSignTransactionMethodName),
1609
+ ...v32.object({
1610
+ method: v32.literal(stxSignTransactionMethodName),
1924
1611
  params: stxSignTransactionParamsSchema,
1925
- id: v22.string()
1612
+ id: v32.string()
1926
1613
  }).entries
1927
1614
  });
1928
1615
 
1929
1616
  // src/request/types/stxMethods/signTransactions.ts
1930
- var v23 = __toESM(require("valibot"));
1617
+ var v33 = __toESM(require("valibot"));
1931
1618
  var stxSignTransactionsMethodName = "stx_signTransactions";
1932
- var stxSignTransactionsParamsSchema = v23.object({
1619
+ var stxSignTransactionsParamsSchema = v33.object({
1933
1620
  /**
1934
1621
  * The transactions to sign as hex-encoded strings.
1935
1622
  */
1936
- transactions: v23.pipe(
1937
- v23.array(
1938
- v23.pipe(
1939
- v23.string(),
1940
- v23.check((hex) => {
1623
+ transactions: v33.pipe(
1624
+ v33.array(
1625
+ v33.pipe(
1626
+ v33.string(),
1627
+ v33.check((hex) => {
1941
1628
  return true;
1942
1629
  }, "Invalid hex-encoded Stacks transaction.")
1943
1630
  )
1944
1631
  ),
1945
- v23.minLength(1)
1632
+ v33.minLength(1)
1946
1633
  ),
1947
1634
  /**
1948
1635
  * Whether the signed transactions should be broadcast after signing. Defaults
1949
1636
  * to `true`.
1950
1637
  */
1951
- broadcast: v23.optional(v23.boolean())
1638
+ broadcast: v33.optional(v33.boolean())
1952
1639
  });
1953
- var stxSignTransactionsResultSchema = v23.object({
1640
+ var stxSignTransactionsResultSchema = v33.object({
1954
1641
  /**
1955
1642
  * The signed transactions as hex-encoded strings, in the same order as in the
1956
1643
  * sign request.
1957
1644
  */
1958
- transactions: v23.array(v23.string())
1645
+ transactions: v33.array(v33.string())
1959
1646
  });
1960
- var stxSignTransactionsRequestMessageSchema = v23.object({
1647
+ var stxSignTransactionsRequestMessageSchema = v33.object({
1961
1648
  ...rpcRequestMessageSchema.entries,
1962
- ...v23.object({
1963
- method: v23.literal(stxSignTransactionsMethodName),
1649
+ ...v33.object({
1650
+ method: v33.literal(stxSignTransactionsMethodName),
1964
1651
  params: stxSignTransactionsParamsSchema,
1965
- id: v23.string()
1652
+ id: v33.string()
1966
1653
  }).entries
1967
1654
  });
1968
1655
 
1969
1656
  // src/request/types/stxMethods/transferStx.ts
1970
- var v24 = __toESM(require("valibot"));
1657
+ var v34 = __toESM(require("valibot"));
1971
1658
  var stxTransferStxMethodName = "stx_transferStx";
1972
- var stxTransferStxParamsSchema = v24.object({
1659
+ var stxTransferStxParamsSchema = v34.object({
1973
1660
  /**
1974
1661
  * Amount of STX tokens to transfer in microstacks as a string. Anything
1975
1662
  * parseable by `BigInt` is acceptable.
@@ -1982,23 +1669,23 @@ var stxTransferStxParamsSchema = v24.object({
1982
1669
  * const amount3 = '1234';
1983
1670
  * ```
1984
1671
  */
1985
- amount: v24.union([v24.number(), v24.string()]),
1672
+ amount: v34.union([v34.number(), v34.string()]),
1986
1673
  /**
1987
1674
  * The recipient's principal.
1988
1675
  */
1989
- recipient: v24.string(),
1676
+ recipient: v34.string(),
1990
1677
  /**
1991
1678
  * A string representing the memo.
1992
1679
  */
1993
- memo: v24.optional(v24.string()),
1680
+ memo: v34.optional(v34.string()),
1994
1681
  /**
1995
1682
  * Version of parameter format.
1996
1683
  */
1997
- version: v24.optional(v24.string()),
1684
+ version: v34.optional(v34.string()),
1998
1685
  /**
1999
1686
  * The mode of the post conditions.
2000
1687
  */
2001
- postConditionMode: v24.optional(v24.number()),
1688
+ postConditionMode: v34.optional(v34.number()),
2002
1689
  /**
2003
1690
  * A hex-encoded string representing the post conditions.
2004
1691
  *
@@ -2011,29 +1698,29 @@ var stxTransferStxParamsSchema = v24.object({
2011
1698
  * const hexPostCondition = serializePostCondition(postCondition).toString('hex');
2012
1699
  * ```
2013
1700
  */
2014
- postConditions: v24.optional(v24.array(v24.string())),
1701
+ postConditions: v34.optional(v34.array(v34.string())),
2015
1702
  /**
2016
1703
  * The public key to sign the transaction with. The wallet may use any key
2017
1704
  * when not provided.
2018
1705
  */
2019
- pubkey: v24.optional(v24.string())
1706
+ pubkey: v34.optional(v34.string())
2020
1707
  });
2021
- var stxTransferStxResultSchema = v24.object({
1708
+ var stxTransferStxResultSchema = v34.object({
2022
1709
  /**
2023
1710
  * The ID of the transaction.
2024
1711
  */
2025
- txid: v24.string(),
1712
+ txid: v34.string(),
2026
1713
  /**
2027
1714
  * A Stacks transaction as a hex-encoded string.
2028
1715
  */
2029
- transaction: v24.string()
1716
+ transaction: v34.string()
2030
1717
  });
2031
- var stxTransferStxRequestMessageSchema = v24.object({
1718
+ var stxTransferStxRequestMessageSchema = v34.object({
2032
1719
  ...rpcRequestMessageSchema.entries,
2033
- ...v24.object({
2034
- method: v24.literal(stxTransferStxMethodName),
1720
+ ...v34.object({
1721
+ method: v34.literal(stxTransferStxMethodName),
2035
1722
  params: stxTransferStxParamsSchema,
2036
- id: v24.string()
1723
+ id: v34.string()
2037
1724
  }).entries
2038
1725
  });
2039
1726
 
@@ -2043,83 +1730,562 @@ var request = async (method, params, providerId) => {
2043
1730
  if (providerId) {
2044
1731
  provider = await getProviderById(providerId);
2045
1732
  }
2046
- if (!provider) {
2047
- throw new Error("no wallet provider was found");
1733
+ if (!provider) {
1734
+ throw new Error("no wallet provider was found");
1735
+ }
1736
+ if (!method) {
1737
+ throw new Error("A wallet method is required");
1738
+ }
1739
+ const response = await provider.request(method, params);
1740
+ if (v35.is(rpcErrorResponseMessageSchema, response)) {
1741
+ return {
1742
+ status: "error",
1743
+ error: response.error
1744
+ };
1745
+ }
1746
+ if (v35.is(rpcSuccessResponseMessageSchema, response)) {
1747
+ return {
1748
+ status: "success",
1749
+ result: response.result
1750
+ };
1751
+ }
1752
+ return {
1753
+ status: "error",
1754
+ error: {
1755
+ code: -32603 /* INTERNAL_ERROR */,
1756
+ message: "Received unknown response from provider.",
1757
+ data: response
1758
+ }
1759
+ };
1760
+ };
1761
+ var addListener = (...rawArgs) => {
1762
+ const [listenerInfo, providerId] = (() => {
1763
+ if (rawArgs.length === 1) {
1764
+ return [rawArgs[0], void 0];
1765
+ }
1766
+ if (rawArgs.length === 2) {
1767
+ if (typeof rawArgs[1] === "function") {
1768
+ return [
1769
+ {
1770
+ eventName: rawArgs[0],
1771
+ cb: rawArgs[1]
1772
+ },
1773
+ void 0
1774
+ ];
1775
+ } else {
1776
+ return rawArgs;
1777
+ }
1778
+ }
1779
+ if (rawArgs.length === 3) {
1780
+ return [
1781
+ {
1782
+ eventName: rawArgs[0],
1783
+ cb: rawArgs[1]
1784
+ },
1785
+ rawArgs[2]
1786
+ ];
1787
+ }
1788
+ throw new Error("Unexpected number of arguments. Expecting 2 (or 3 for legacy requests).", {
1789
+ cause: rawArgs
1790
+ });
1791
+ })();
1792
+ let provider = window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
1793
+ if (providerId) {
1794
+ provider = getProviderById(providerId);
1795
+ }
1796
+ if (!provider) {
1797
+ throw new Error("no wallet provider was found");
1798
+ }
1799
+ if (!provider.addListener) {
1800
+ console.error(
1801
+ `The wallet provider you are using does not support the addListener method. Please update your wallet provider.`
1802
+ );
1803
+ return () => {
1804
+ };
1805
+ }
1806
+ return provider.addListener(listenerInfo);
1807
+ };
1808
+
1809
+ // src/runes/api.ts
1810
+ var import_axios = __toESM(require("axios"));
1811
+ var urlNetworkSuffix = {
1812
+ ["Mainnet" /* Mainnet */]: "",
1813
+ ["Testnet" /* Testnet */]: "-testnet",
1814
+ ["Testnet4" /* Testnet4 */]: "-testnet4",
1815
+ ["Signet" /* Signet */]: "-signet"
1816
+ };
1817
+ var ORDINALS_API_BASE_URL = (network = "Mainnet" /* Mainnet */) => {
1818
+ if (network === "Regtest" /* Regtest */) {
1819
+ throw new Error(`Ordinals API does not support ${network} network`);
1820
+ }
1821
+ return `https://ordinals${urlNetworkSuffix[network]}.xverse.app/v1`;
1822
+ };
1823
+ var RunesApi = class {
1824
+ client;
1825
+ constructor(network) {
1826
+ this.client = import_axios.default.create({
1827
+ baseURL: ORDINALS_API_BASE_URL(network)
1828
+ });
1829
+ }
1830
+ parseError = (error) => {
1831
+ return {
1832
+ code: error.response?.status,
1833
+ message: JSON.stringify(error.response?.data)
1834
+ };
1835
+ };
1836
+ estimateMintCost = async (mintParams) => {
1837
+ try {
1838
+ const response = await this.client.post("/runes/mint/estimate", {
1839
+ ...mintParams
1840
+ });
1841
+ return {
1842
+ data: response.data
1843
+ };
1844
+ } catch (error) {
1845
+ const err = error;
1846
+ return {
1847
+ error: this.parseError(err)
1848
+ };
1849
+ }
1850
+ };
1851
+ estimateEtchCost = async (etchParams) => {
1852
+ try {
1853
+ const response = await this.client.post("/runes/etch/estimate", {
1854
+ ...etchParams
1855
+ });
1856
+ return {
1857
+ data: response.data
1858
+ };
1859
+ } catch (error) {
1860
+ const err = error;
1861
+ return {
1862
+ error: this.parseError(err)
1863
+ };
1864
+ }
1865
+ };
1866
+ createMintOrder = async (mintOrderParams) => {
1867
+ try {
1868
+ const response = await this.client.post("/runes/mint/orders", {
1869
+ ...mintOrderParams
1870
+ });
1871
+ return {
1872
+ data: response.data
1873
+ };
1874
+ } catch (error) {
1875
+ const err = error;
1876
+ return {
1877
+ error: this.parseError(err)
1878
+ };
1879
+ }
1880
+ };
1881
+ createEtchOrder = async (etchOrderParams) => {
1882
+ try {
1883
+ const response = await this.client.post("/runes/etch/orders", {
1884
+ ...etchOrderParams
1885
+ });
1886
+ return {
1887
+ data: response.data
1888
+ };
1889
+ } catch (error) {
1890
+ const err = error;
1891
+ return {
1892
+ error: this.parseError(err)
1893
+ };
1894
+ }
1895
+ };
1896
+ executeMint = async (orderId, fundTransactionId) => {
1897
+ try {
1898
+ const response = await this.client.post(`/runes/mint/orders/${orderId}/execute`, {
1899
+ fundTransactionId
1900
+ });
1901
+ return {
1902
+ data: response.data
1903
+ };
1904
+ } catch (error) {
1905
+ const err = error;
1906
+ return {
1907
+ error: this.parseError(err)
1908
+ };
1909
+ }
1910
+ };
1911
+ executeEtch = async (orderId, fundTransactionId) => {
1912
+ try {
1913
+ const response = await this.client.post(`/runes/etch/orders/${orderId}/execute`, {
1914
+ fundTransactionId
1915
+ });
1916
+ return {
1917
+ data: response.data
1918
+ };
1919
+ } catch (error) {
1920
+ const err = error;
1921
+ return {
1922
+ error: this.parseError(err)
1923
+ };
1924
+ }
1925
+ };
1926
+ getOrder = async (orderId) => {
1927
+ try {
1928
+ const response = await this.client.get(`/orders/${orderId}`);
1929
+ return {
1930
+ data: response.data
1931
+ };
1932
+ } catch (error) {
1933
+ const err = error;
1934
+ return {
1935
+ error: this.parseError(err)
1936
+ };
1937
+ }
1938
+ };
1939
+ rbfOrder = async (rbfRequest) => {
1940
+ const { orderId, newFeeRate } = rbfRequest;
1941
+ try {
1942
+ const response = await this.client.post(`/orders/${orderId}/rbf-estimate`, {
1943
+ newFeeRate
1944
+ });
1945
+ return {
1946
+ data: response.data
1947
+ };
1948
+ } catch (error) {
1949
+ const err = error;
1950
+ return {
1951
+ error: this.parseError(err)
1952
+ };
1953
+ }
1954
+ };
1955
+ };
1956
+ var clients = {};
1957
+ var getRunesApiClient = (network = "Mainnet" /* Mainnet */) => {
1958
+ if (!clients[network]) {
1959
+ clients[network] = new RunesApi(network);
1960
+ }
1961
+ return clients[network];
1962
+ };
1963
+
1964
+ // src/adapters/satsConnectAdapter.ts
1965
+ var SatsConnectAdapter = class {
1966
+ async mintRunes(params) {
1967
+ try {
1968
+ const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
1969
+ if (walletInfo && walletInfo.status === "success") {
1970
+ const isMintSupported = walletInfo.result.methods?.includes("runes_mint");
1971
+ if (isMintSupported) {
1972
+ const response = await this.requestInternal("runes_mint", params);
1973
+ if (response) {
1974
+ if (response.status === "success") {
1975
+ return response;
1976
+ }
1977
+ if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
1978
+ return response;
1979
+ }
1980
+ }
1981
+ }
1982
+ }
1983
+ const mintRequest = {
1984
+ destinationAddress: params.destinationAddress,
1985
+ feeRate: params.feeRate,
1986
+ refundAddress: params.refundAddress,
1987
+ repeats: params.repeats,
1988
+ runeName: params.runeName,
1989
+ appServiceFee: params.appServiceFee,
1990
+ appServiceFeeAddress: params.appServiceFeeAddress
1991
+ };
1992
+ const orderResponse = await new RunesApi(params.network).createMintOrder(mintRequest);
1993
+ if (!orderResponse.data) {
1994
+ return {
1995
+ status: "error",
1996
+ error: {
1997
+ code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
1998
+ message: orderResponse.error.message
1999
+ }
2000
+ };
2001
+ }
2002
+ const paymentResponse = await this.requestInternal("sendTransfer", {
2003
+ recipients: [
2004
+ {
2005
+ address: orderResponse.data.fundAddress,
2006
+ amount: orderResponse.data.fundAmount
2007
+ }
2008
+ ]
2009
+ });
2010
+ if (paymentResponse.status !== "success") {
2011
+ return paymentResponse;
2012
+ }
2013
+ await new RunesApi(params.network).executeMint(
2014
+ orderResponse.data.orderId,
2015
+ paymentResponse.result.txid
2016
+ );
2017
+ return {
2018
+ status: "success",
2019
+ result: {
2020
+ orderId: orderResponse.data.orderId,
2021
+ fundTransactionId: paymentResponse.result.txid,
2022
+ fundingAddress: orderResponse.data.fundAddress
2023
+ }
2024
+ };
2025
+ } catch (error) {
2026
+ return {
2027
+ status: "error",
2028
+ error: {
2029
+ code: -32603 /* INTERNAL_ERROR */,
2030
+ message: error.message
2031
+ }
2032
+ };
2033
+ }
2048
2034
  }
2049
- if (!method) {
2050
- throw new Error("A wallet method is required");
2035
+ async etchRunes(params) {
2036
+ const etchRequest = {
2037
+ destinationAddress: params.destinationAddress,
2038
+ refundAddress: params.refundAddress,
2039
+ feeRate: params.feeRate,
2040
+ runeName: params.runeName,
2041
+ divisibility: params.divisibility,
2042
+ symbol: params.symbol,
2043
+ premine: params.premine,
2044
+ isMintable: params.isMintable,
2045
+ terms: params.terms,
2046
+ inscriptionDetails: params.inscriptionDetails,
2047
+ delegateInscriptionId: params.delegateInscriptionId,
2048
+ appServiceFee: params.appServiceFee,
2049
+ appServiceFeeAddress: params.appServiceFeeAddress
2050
+ };
2051
+ try {
2052
+ const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
2053
+ if (walletInfo && walletInfo.status === "success") {
2054
+ const isEtchSupported = walletInfo.result.methods?.includes("runes_etch");
2055
+ if (isEtchSupported) {
2056
+ const response = await this.requestInternal("runes_etch", params);
2057
+ if (response) {
2058
+ if (response.status === "success") {
2059
+ return response;
2060
+ }
2061
+ if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
2062
+ return response;
2063
+ }
2064
+ }
2065
+ }
2066
+ }
2067
+ const orderResponse = await new RunesApi(params.network).createEtchOrder(etchRequest);
2068
+ if (!orderResponse.data) {
2069
+ return {
2070
+ status: "error",
2071
+ error: {
2072
+ code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
2073
+ message: orderResponse.error.message
2074
+ }
2075
+ };
2076
+ }
2077
+ const paymentResponse = await this.requestInternal("sendTransfer", {
2078
+ recipients: [
2079
+ {
2080
+ address: orderResponse.data.fundAddress,
2081
+ amount: orderResponse.data.fundAmount
2082
+ }
2083
+ ]
2084
+ });
2085
+ if (paymentResponse.status !== "success") {
2086
+ return paymentResponse;
2087
+ }
2088
+ await new RunesApi(params.network).executeEtch(
2089
+ orderResponse.data.orderId,
2090
+ paymentResponse.result.txid
2091
+ );
2092
+ return {
2093
+ status: "success",
2094
+ result: {
2095
+ orderId: orderResponse.data.orderId,
2096
+ fundTransactionId: paymentResponse.result.txid,
2097
+ fundingAddress: orderResponse.data.fundAddress
2098
+ }
2099
+ };
2100
+ } catch (error) {
2101
+ return {
2102
+ status: "error",
2103
+ error: {
2104
+ code: -32603 /* INTERNAL_ERROR */,
2105
+ message: error.message
2106
+ }
2107
+ };
2108
+ }
2051
2109
  }
2052
- const response = await provider.request(method, params);
2053
- if (v25.is(rpcErrorResponseMessageSchema, response)) {
2110
+ async estimateMint(params) {
2111
+ const estimateMintRequest = {
2112
+ destinationAddress: params.destinationAddress,
2113
+ feeRate: params.feeRate,
2114
+ repeats: params.repeats,
2115
+ runeName: params.runeName,
2116
+ appServiceFee: params.appServiceFee,
2117
+ appServiceFeeAddress: params.appServiceFeeAddress
2118
+ };
2119
+ const response = await getRunesApiClient(
2120
+ params.network
2121
+ ).estimateMintCost(estimateMintRequest);
2122
+ if (response.data) {
2123
+ return {
2124
+ status: "success",
2125
+ result: response.data
2126
+ };
2127
+ }
2054
2128
  return {
2055
2129
  status: "error",
2056
- error: response.error
2130
+ error: {
2131
+ code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
2132
+ message: response.error.message
2133
+ }
2057
2134
  };
2058
2135
  }
2059
- if (v25.is(rpcSuccessResponseMessageSchema, response)) {
2136
+ async estimateEtch(params) {
2137
+ const estimateEtchRequest = {
2138
+ destinationAddress: params.destinationAddress,
2139
+ feeRate: params.feeRate,
2140
+ runeName: params.runeName,
2141
+ divisibility: params.divisibility,
2142
+ symbol: params.symbol,
2143
+ premine: params.premine,
2144
+ isMintable: params.isMintable,
2145
+ terms: params.terms,
2146
+ inscriptionDetails: params.inscriptionDetails,
2147
+ delegateInscriptionId: params.delegateInscriptionId,
2148
+ appServiceFee: params.appServiceFee,
2149
+ appServiceFeeAddress: params.appServiceFeeAddress
2150
+ };
2151
+ const response = await getRunesApiClient(params.network).estimateEtchCost(estimateEtchRequest);
2152
+ if (response.data) {
2153
+ return {
2154
+ status: "success",
2155
+ result: response.data
2156
+ };
2157
+ }
2060
2158
  return {
2061
- status: "success",
2062
- result: response.result
2159
+ status: "error",
2160
+ error: {
2161
+ code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
2162
+ message: response.error.message
2163
+ }
2063
2164
  };
2064
2165
  }
2065
- return {
2066
- status: "error",
2067
- error: {
2068
- code: -32603 /* INTERNAL_ERROR */,
2069
- message: "Received unknown response from provider.",
2070
- data: response
2166
+ async getOrder(params) {
2167
+ const response = await getRunesApiClient(params.network).getOrder(params.id);
2168
+ if (response.data) {
2169
+ return {
2170
+ status: "success",
2171
+ result: response.data
2172
+ };
2071
2173
  }
2072
- };
2073
- };
2074
- var addListener = (...rawArgs) => {
2075
- const [listenerInfo, providerId] = (() => {
2076
- if (rawArgs.length === 1) {
2077
- return [rawArgs[0], void 0];
2174
+ return {
2175
+ status: "error",
2176
+ error: {
2177
+ code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
2178
+ message: response.error.message
2179
+ }
2180
+ };
2181
+ }
2182
+ async estimateRbfOrder(params) {
2183
+ const rbfOrderRequest = {
2184
+ newFeeRate: params.newFeeRate,
2185
+ orderId: params.orderId
2186
+ };
2187
+ const response = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
2188
+ if (response.data) {
2189
+ return {
2190
+ status: "success",
2191
+ result: {
2192
+ fundingAddress: response.data.fundingAddress,
2193
+ rbfCost: response.data.rbfCost
2194
+ }
2195
+ };
2078
2196
  }
2079
- if (rawArgs.length === 2) {
2080
- if (typeof rawArgs[1] === "function") {
2081
- return [
2197
+ return {
2198
+ status: "error",
2199
+ error: {
2200
+ code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
2201
+ message: response.error.message
2202
+ }
2203
+ };
2204
+ }
2205
+ async rbfOrder(params) {
2206
+ try {
2207
+ const rbfOrderRequest = {
2208
+ newFeeRate: params.newFeeRate,
2209
+ orderId: params.orderId
2210
+ };
2211
+ const orderResponse = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
2212
+ if (!orderResponse.data) {
2213
+ return {
2214
+ status: "error",
2215
+ error: {
2216
+ code: orderResponse.error.code === 400 || orderResponse.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
2217
+ message: orderResponse.error.message
2218
+ }
2219
+ };
2220
+ }
2221
+ const paymentResponse = await this.requestInternal("sendTransfer", {
2222
+ recipients: [
2082
2223
  {
2083
- eventName: rawArgs[0],
2084
- cb: rawArgs[1]
2085
- },
2086
- void 0
2087
- ];
2088
- } else {
2089
- return rawArgs;
2224
+ address: orderResponse.data.fundingAddress,
2225
+ amount: orderResponse.data.rbfCost
2226
+ }
2227
+ ]
2228
+ });
2229
+ if (paymentResponse.status !== "success") {
2230
+ return paymentResponse;
2090
2231
  }
2232
+ return {
2233
+ status: "success",
2234
+ result: {
2235
+ fundingAddress: orderResponse.data.fundingAddress,
2236
+ orderId: rbfOrderRequest.orderId,
2237
+ fundRBFTransactionId: paymentResponse.result.txid
2238
+ }
2239
+ };
2240
+ } catch (error) {
2241
+ return {
2242
+ status: "error",
2243
+ error: {
2244
+ code: -32603 /* INTERNAL_ERROR */,
2245
+ message: error.message
2246
+ }
2247
+ };
2091
2248
  }
2092
- if (rawArgs.length === 3) {
2093
- return [
2094
- {
2095
- eventName: rawArgs[0],
2096
- cb: rawArgs[1]
2097
- },
2098
- rawArgs[2]
2099
- ];
2100
- }
2101
- throw new Error("Unexpected number of arguments. Expecting 2 (or 3 for legacy requests).", {
2102
- cause: rawArgs
2103
- });
2104
- })();
2105
- let provider = window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
2106
- if (providerId) {
2107
- provider = getProviderById(providerId);
2108
2249
  }
2109
- if (!provider) {
2110
- throw new Error("no wallet provider was found");
2111
- }
2112
- if (!provider.addListener) {
2113
- console.error(
2114
- `The wallet provider you are using does not support the addListener method. Please update your wallet provider.`
2115
- );
2116
- return () => {
2117
- };
2250
+ async request(method, params) {
2251
+ switch (method) {
2252
+ case "runes_mint":
2253
+ return this.mintRunes(params);
2254
+ case "runes_etch":
2255
+ return this.etchRunes(params);
2256
+ case "runes_estimateMint":
2257
+ return this.estimateMint(params);
2258
+ case "runes_estimateEtch":
2259
+ return this.estimateEtch(params);
2260
+ case "runes_getOrder": {
2261
+ return this.getOrder(params);
2262
+ }
2263
+ case "runes_estimateRbfOrder": {
2264
+ return this.estimateRbfOrder(params);
2265
+ }
2266
+ case "runes_rbfOrder": {
2267
+ return this.rbfOrder(params);
2268
+ }
2269
+ default:
2270
+ return this.requestInternal(method, params);
2271
+ }
2118
2272
  }
2119
- return provider.addListener(listenerInfo);
2273
+ };
2274
+
2275
+ // src/adapters/xverse.ts
2276
+ var XverseAdapter = class extends SatsConnectAdapter {
2277
+ id = DefaultAdaptersInfo.xverse.id;
2278
+ requestInternal = async (method, params) => {
2279
+ return request(method, params, this.id);
2280
+ };
2281
+ addListener = (listenerInfo) => {
2282
+ return addListener(listenerInfo, this.id);
2283
+ };
2120
2284
  };
2121
2285
 
2122
2286
  // src/adapters/unisat.ts
2287
+ var import_bitcoin_address_validation = require("bitcoin-address-validation");
2288
+ var import_buffer = require("buffer");
2123
2289
  function convertSignInputsToInputType(signInputs) {
2124
2290
  let result = [];
2125
2291
  if (!signInputs) {
@@ -2305,77 +2471,32 @@ var UnisatAdapter = class extends SatsConnectAdapter {
2305
2471
  };
2306
2472
  };
2307
2473
 
2308
- // src/adapters/xverse/sanitizeRequest.ts
2309
- var sanitizeRequest = (method, params, providerInfo) => {
2310
- try {
2311
- const [major, minor, patch] = providerInfo.version.split(".").map((part) => parseInt(part, 10));
2312
- const platform = providerInfo.platform;
2313
- if (
2314
- // platform is missing for versions < 1.5.0 on web and < 1.55.0 on mobile
2315
- !platform || platform === "web" /* Web */ && major <= 1 && minor <= 4 || platform === "mobile" /* Mobile */ && major <= 1 && minor <= 54
2316
- ) {
2317
- const v1Sanitized = sanitizeAddressPurposeRequest(method, params);
2318
- method = v1Sanitized.method;
2319
- params = v1Sanitized.params;
2320
- }
2321
- } catch {
2322
- }
2323
- return { method, params };
2324
- };
2325
- var sanitizeAddressPurposeRequest = (method, params) => {
2326
- const filterPurposes = (purposes) => purposes?.filter(
2327
- (purpose) => purpose !== "spark" /* Spark */ && purpose !== "starknet" /* Starknet */
2328
- );
2329
- if (method === "wallet_connect") {
2330
- const typedParams = params;
2331
- if (!typedParams) {
2332
- return { method, params };
2333
- }
2334
- const { addresses, ...rest } = typedParams;
2335
- const overrideParams = {
2336
- ...rest,
2337
- addresses: filterPurposes(addresses)
2338
- };
2339
- return { method, params: overrideParams };
2340
- }
2341
- if (method === "getAccounts") {
2342
- const typedParams = params;
2343
- const { purposes, ...rest } = typedParams;
2344
- const overrideParams = { ...rest, purposes: filterPurposes(purposes) };
2345
- return { method, params: overrideParams };
2346
- }
2347
- if (method === "getAddresses") {
2348
- const typedParams = params;
2349
- const { purposes, ...rest } = typedParams;
2350
- const overrideParams = { ...rest, purposes: filterPurposes(purposes) };
2351
- return { method, params: overrideParams };
2352
- }
2353
- return { method, params };
2354
- };
2355
-
2356
- // src/adapters/xverse/index.ts
2357
- var XverseAdapter = class extends SatsConnectAdapter {
2358
- id = DefaultAdaptersInfo.xverse.id;
2359
- providerInfo;
2474
+ // src/adapters/fordefi.ts
2475
+ var FordefiAdapter = class extends SatsConnectAdapter {
2476
+ id = DefaultAdaptersInfo.fordefi.id;
2360
2477
  requestInternal = async (method, params) => {
2361
- if (!this.providerInfo) {
2362
- const infoResult = await request("getInfo", null, this.id);
2363
- if (infoResult.status === "success") {
2364
- this.providerInfo = infoResult.result;
2365
- }
2478
+ const provider = getProviderById(this.id);
2479
+ if (!provider) {
2480
+ throw new Error("no wallet provider was found");
2366
2481
  }
2367
- if (this.providerInfo) {
2368
- const sanitized = sanitizeRequest(method, params, this.providerInfo);
2369
- if (sanitized.overrideResponse) {
2370
- return sanitized.overrideResponse;
2371
- }
2372
- method = sanitized.method;
2373
- params = sanitized.params;
2482
+ if (!method) {
2483
+ throw new Error("A wallet method is required");
2374
2484
  }
2375
- return request(method, params, this.id);
2485
+ return await provider.request(method, params);
2376
2486
  };
2377
- addListener = (listenerInfo) => {
2378
- return addListener(listenerInfo, this.id);
2487
+ addListener = ({ eventName, cb }) => {
2488
+ const provider = getProviderById(this.id);
2489
+ if (!provider) {
2490
+ throw new Error("no wallet provider was found");
2491
+ }
2492
+ if (!provider.addListener) {
2493
+ console.error(
2494
+ `The wallet provider you are using does not support the addListener method. Please update your wallet provider.`
2495
+ );
2496
+ return () => {
2497
+ };
2498
+ }
2499
+ return provider.addListener(eventName, cb);
2379
2500
  };
2380
2501
  };
2381
2502
 
@@ -2642,7 +2763,6 @@ var signMultipleTransactions = async (options) => {
2642
2763
  DefaultAdaptersInfo,
2643
2764
  MessageSigningProtocols,
2644
2765
  PermissionRequestParams,
2645
- ProviderPlatform,
2646
2766
  RpcErrorCode,
2647
2767
  RpcIdSchema,
2648
2768
  SatsConnectAdapter,
@@ -2778,6 +2898,22 @@ var signMultipleTransactions = async (options) => {
2778
2898
  signPsbtRequestMessageSchema,
2779
2899
  signPsbtResultSchema,
2780
2900
  signTransaction,
2901
+ sparkFlashnetAddLiquidityIntentSchema,
2902
+ sparkFlashnetClawbackIntentSchema,
2903
+ sparkFlashnetConfirmInitialDepositIntentSchema,
2904
+ sparkFlashnetCreateConstantProductPoolIntentSchema,
2905
+ sparkFlashnetCreateSingleSidedPoolIntentSchema,
2906
+ sparkFlashnetGetJwtMethodName,
2907
+ sparkFlashnetGetJwtParamsSchema,
2908
+ sparkFlashnetGetJwtRequestMessageSchema,
2909
+ sparkFlashnetGetJwtResultSchema,
2910
+ sparkFlashnetRemoveLiquidityIntentSchema,
2911
+ sparkFlashnetRouteSwapIntentSchema,
2912
+ sparkFlashnetSignIntentMethodName,
2913
+ sparkFlashnetSignIntentParamsSchema,
2914
+ sparkFlashnetSignIntentRequestMessageSchema,
2915
+ sparkFlashnetSignIntentResultSchema,
2916
+ sparkFlashnetSwapIntentSchema,
2781
2917
  sparkGetAddressesMethodName,
2782
2918
  sparkGetAddressesParamsSchema,
2783
2919
  sparkGetAddressesRequestMessageSchema,