@sats-connect/core 0.1.2-3c27b78 → 0.1.2-515ef3b

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,24 +1,84 @@
1
- // src/types.ts
1
+ // src/provider/index.ts
2
+ import omit from "lodash.omit";
3
+
4
+ // src/provider/types.ts
2
5
  import * as v from "valibot";
6
+ var accountChangeEventName = "accountChange";
7
+ var accountChangeSchema = v.object({
8
+ type: v.literal(accountChangeEventName)
9
+ });
10
+ var networkChangeEventName = "networkChange";
11
+ var networkChangeSchema = v.object({
12
+ type: v.literal(networkChangeEventName)
13
+ });
14
+ var walletEventSchema = v.variant("type", [accountChangeSchema, networkChangeSchema]);
15
+
16
+ // src/provider/index.ts
17
+ async function getProviderOrThrow(getProvider) {
18
+ const provider = await getProvider?.() || window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
19
+ if (!provider) {
20
+ throw new Error("No Bitcoin wallet installed");
21
+ }
22
+ return provider;
23
+ }
24
+ function getProviders() {
25
+ if (!window.btc_providers)
26
+ window.btc_providers = [];
27
+ return window.btc_providers;
28
+ }
29
+ function getProviderById(providerId) {
30
+ return providerId?.split(".").reduce((acc, part) => acc?.[part], window);
31
+ }
32
+ function isProviderInstalled(providerId) {
33
+ return !!getProviderById(providerId);
34
+ }
35
+ function setDefaultProvider(providerId) {
36
+ localStorage.setItem("sats-connect_defaultProvider", providerId);
37
+ }
38
+ function getDefaultProvider() {
39
+ return localStorage.getItem("sats-connect_defaultProvider");
40
+ }
41
+ function removeDefaultProvider() {
42
+ localStorage.removeItem("sats-connect_defaultProvider");
43
+ }
44
+ function getSupportedWallets() {
45
+ const btc_providers = getProviders();
46
+ const allProviders = [...btc_providers];
47
+ for (const key in omit(DefaultAdaptersInfo, ["xverse"])) {
48
+ allProviders.push(DefaultAdaptersInfo[key]);
49
+ }
50
+ const wallets = allProviders.map((provider) => {
51
+ {
52
+ return {
53
+ ...provider,
54
+ isInstalled: isProviderInstalled(provider.id)
55
+ };
56
+ }
57
+ });
58
+ return wallets;
59
+ }
60
+
61
+ // src/types.ts
62
+ import * as v2 from "valibot";
3
63
  var BitcoinNetworkType = /* @__PURE__ */ ((BitcoinNetworkType3) => {
4
64
  BitcoinNetworkType3["Mainnet"] = "Mainnet";
5
65
  BitcoinNetworkType3["Testnet"] = "Testnet";
6
66
  BitcoinNetworkType3["Signet"] = "Signet";
7
67
  return BitcoinNetworkType3;
8
68
  })(BitcoinNetworkType || {});
9
- var RpcIdSchema = v.optional(v.union([v.string(), v.number(), v.null()]));
10
- var rpcRequestMessageSchema = v.object({
11
- jsonrpc: v.literal("2.0"),
12
- method: v.string(),
13
- params: v.optional(
14
- v.union([
15
- v.array(v.unknown()),
16
- v.looseObject({}),
69
+ var RpcIdSchema = v2.optional(v2.union([v2.string(), v2.number(), v2.null()]));
70
+ var rpcRequestMessageSchema = v2.object({
71
+ jsonrpc: v2.literal("2.0"),
72
+ method: v2.string(),
73
+ params: v2.optional(
74
+ v2.union([
75
+ v2.array(v2.unknown()),
76
+ v2.looseObject({}),
17
77
  // Note: This is to support current incorrect usage of RPC 2.0. Params need
18
78
  // to be either an array or an object when provided. Changing this now would
19
79
  // be a breaking change, so accepting null values for now. Tracking in
20
80
  // https://linear.app/xverseapp/issue/ENG-4538.
21
- v.null()
81
+ v2.null()
22
82
  ])
23
83
  ),
24
84
  id: RpcIdSchema
@@ -34,872 +94,399 @@ var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
34
94
  RpcErrorCode2[RpcErrorCode2["ACCESS_DENIED"] = -32002] = "ACCESS_DENIED";
35
95
  return RpcErrorCode2;
36
96
  })(RpcErrorCode || {});
37
- var rpcSuccessResponseMessageSchema = v.object({
38
- jsonrpc: v.literal("2.0"),
39
- result: v.nonOptional(v.unknown()),
97
+ var rpcSuccessResponseMessageSchema = v2.object({
98
+ jsonrpc: v2.literal("2.0"),
99
+ result: v2.nonOptional(v2.unknown()),
40
100
  id: RpcIdSchema
41
101
  });
42
- var rpcErrorResponseMessageSchema = v.object({
43
- jsonrpc: v.literal("2.0"),
44
- error: v.nonOptional(v.unknown()),
102
+ var rpcErrorResponseMessageSchema = v2.object({
103
+ jsonrpc: v2.literal("2.0"),
104
+ error: v2.nonOptional(v2.unknown()),
45
105
  id: RpcIdSchema
46
106
  });
47
- var rpcResponseMessageSchema = v.union([
107
+ var rpcResponseMessageSchema = v2.union([
48
108
  rpcSuccessResponseMessageSchema,
49
109
  rpcErrorResponseMessageSchema
50
110
  ]);
51
111
 
52
- // src/runes/api.ts
53
- import axios from "axios";
54
- var urlNetworkSuffix = {
55
- ["Mainnet" /* Mainnet */]: "",
56
- ["Testnet" /* Testnet */]: "-testnet",
57
- ["Signet" /* Signet */]: "-signet"
58
- };
59
- var ORDINALS_API_BASE_URL = (network = "Mainnet" /* Mainnet */) => `https://ordinals${urlNetworkSuffix[network]}.xverse.app/v1`;
60
- var RunesApi = class {
61
- client;
62
- constructor(network) {
63
- this.client = axios.create({
64
- baseURL: ORDINALS_API_BASE_URL(network)
65
- });
112
+ // src/request/index.ts
113
+ import * as v10 from "valibot";
114
+
115
+ // src/addresses/index.ts
116
+ import { createUnsecuredToken } from "jsontokens";
117
+
118
+ // src/addresses/types.ts
119
+ import * as v3 from "valibot";
120
+ var AddressPurpose = /* @__PURE__ */ ((AddressPurpose2) => {
121
+ AddressPurpose2["Ordinals"] = "ordinals";
122
+ AddressPurpose2["Payment"] = "payment";
123
+ AddressPurpose2["Stacks"] = "stacks";
124
+ return AddressPurpose2;
125
+ })(AddressPurpose || {});
126
+ var AddressType = /* @__PURE__ */ ((AddressType3) => {
127
+ AddressType3["p2pkh"] = "p2pkh";
128
+ AddressType3["p2sh"] = "p2sh";
129
+ AddressType3["p2wpkh"] = "p2wpkh";
130
+ AddressType3["p2wsh"] = "p2wsh";
131
+ AddressType3["p2tr"] = "p2tr";
132
+ AddressType3["stacks"] = "stacks";
133
+ return AddressType3;
134
+ })(AddressType || {});
135
+ var addressSchema = v3.object({
136
+ address: v3.string(),
137
+ publicKey: v3.string(),
138
+ purpose: v3.enum(AddressPurpose),
139
+ addressType: v3.enum(AddressType)
140
+ });
141
+
142
+ // src/addresses/index.ts
143
+ var getAddress = async (options) => {
144
+ const provider = await getProviderOrThrow(options.getProvider);
145
+ const { purposes } = options.payload;
146
+ if (!purposes) {
147
+ throw new Error("Address purposes are required");
66
148
  }
67
- parseError = (error) => {
68
- return {
69
- code: error.response?.status,
70
- message: JSON.stringify(error.response?.data)
71
- };
72
- };
73
- estimateMintCost = async (mintParams) => {
74
- try {
75
- const response = await this.client.post("/runes/mint/estimate", {
76
- ...mintParams
77
- });
78
- return {
79
- data: response.data
80
- };
81
- } catch (error) {
82
- const err = error;
83
- return {
84
- error: this.parseError(err)
85
- };
86
- }
87
- };
88
- estimateEtchCost = async (etchParams) => {
89
- try {
90
- const response = await this.client.post("/runes/etch/estimate", {
91
- ...etchParams
92
- });
93
- return {
94
- data: response.data
95
- };
96
- } catch (error) {
97
- const err = error;
98
- return {
99
- error: this.parseError(err)
100
- };
101
- }
102
- };
103
- createMintOrder = async (mintOrderParams) => {
104
- try {
105
- const response = await this.client.post("/runes/mint/orders", {
106
- ...mintOrderParams
107
- });
108
- return {
109
- data: response.data
110
- };
111
- } catch (error) {
112
- const err = error;
113
- return {
114
- error: this.parseError(err)
115
- };
116
- }
117
- };
118
- createEtchOrder = async (etchOrderParams) => {
119
- try {
120
- const response = await this.client.post("/runes/etch/orders", {
121
- ...etchOrderParams
122
- });
123
- return {
124
- data: response.data
125
- };
126
- } catch (error) {
127
- const err = error;
128
- return {
129
- error: this.parseError(err)
130
- };
131
- }
132
- };
133
- executeMint = async (orderId, fundTransactionId) => {
134
- try {
135
- const response = await this.client.post(`/runes/mint/orders/${orderId}/execute`, {
136
- fundTransactionId
137
- });
138
- return {
139
- data: response.data
140
- };
141
- } catch (error) {
142
- const err = error;
143
- return {
144
- error: this.parseError(err)
145
- };
146
- }
147
- };
148
- executeEtch = async (orderId, fundTransactionId) => {
149
- try {
150
- const response = await this.client.post(`/runes/etch/orders/${orderId}/execute`, {
151
- fundTransactionId
152
- });
153
- return {
154
- data: response.data
155
- };
156
- } catch (error) {
157
- const err = error;
158
- return {
159
- error: this.parseError(err)
160
- };
161
- }
162
- };
163
- getOrder = async (orderId) => {
164
- try {
165
- const response = await this.client.get(`/orders/${orderId}`);
166
- return {
167
- data: response.data
168
- };
169
- } catch (error) {
170
- const err = error;
171
- return {
172
- error: this.parseError(err)
173
- };
174
- }
175
- };
176
- rbfOrder = async (rbfRequest) => {
177
- const { orderId, newFeeRate } = rbfRequest;
178
- try {
179
- const response = await this.client.post(`/orders/${orderId}/rbf-estimate`, {
180
- newFeeRate
181
- });
182
- return {
183
- data: response.data
184
- };
185
- } catch (error) {
186
- const err = error;
187
- return {
188
- error: this.parseError(err)
189
- };
190
- }
191
- };
192
- };
193
- var clients = {};
194
- var getRunesApiClient = (network = "Mainnet" /* Mainnet */) => {
195
- if (!clients[network]) {
196
- clients[network] = new RunesApi(network);
197
- }
198
- return clients[network];
199
- };
200
-
201
- // src/adapters/satsConnectAdapter.ts
202
- var SatsConnectAdapter = class {
203
- async mintRunes(params) {
204
- try {
205
- const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
206
- if (walletInfo && walletInfo.status === "success") {
207
- const isMintSupported = walletInfo.result.methods?.includes("runes_mint");
208
- if (isMintSupported) {
209
- const response = await this.requestInternal("runes_mint", params);
210
- if (response) {
211
- if (response.status === "success") {
212
- return response;
213
- }
214
- if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
215
- return response;
216
- }
217
- }
218
- }
219
- }
220
- const mintRequest = {
221
- destinationAddress: params.destinationAddress,
222
- feeRate: params.feeRate,
223
- refundAddress: params.refundAddress,
224
- repeats: params.repeats,
225
- runeName: params.runeName,
226
- appServiceFee: params.appServiceFee,
227
- appServiceFeeAddress: params.appServiceFeeAddress
228
- };
229
- const orderResponse = await new RunesApi(params.network).createMintOrder(mintRequest);
230
- if (!orderResponse.data) {
231
- return {
232
- status: "error",
233
- error: {
234
- code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
235
- message: orderResponse.error.message
236
- }
237
- };
238
- }
239
- const paymentResponse = await this.requestInternal("sendTransfer", {
240
- recipients: [
241
- {
242
- address: orderResponse.data.fundAddress,
243
- amount: orderResponse.data.fundAmount
244
- }
245
- ]
246
- });
247
- if (paymentResponse.status !== "success") {
248
- return paymentResponse;
249
- }
250
- await new RunesApi(params.network).executeMint(
251
- orderResponse.data.orderId,
252
- paymentResponse.result.txid
253
- );
254
- return {
255
- status: "success",
256
- result: {
257
- orderId: orderResponse.data.orderId,
258
- fundTransactionId: paymentResponse.result.txid,
259
- fundingAddress: orderResponse.data.fundAddress
260
- }
261
- };
262
- } catch (error) {
263
- return {
264
- status: "error",
265
- error: {
266
- code: -32603 /* INTERNAL_ERROR */,
267
- message: error.message
268
- }
269
- };
270
- }
271
- }
272
- async etchRunes(params) {
273
- const etchRequest = {
274
- destinationAddress: params.destinationAddress,
275
- refundAddress: params.refundAddress,
276
- feeRate: params.feeRate,
277
- runeName: params.runeName,
278
- divisibility: params.divisibility,
279
- symbol: params.symbol,
280
- premine: params.premine,
281
- isMintable: params.isMintable,
282
- terms: params.terms,
283
- inscriptionDetails: params.inscriptionDetails,
284
- delegateInscriptionId: params.delegateInscriptionId,
285
- appServiceFee: params.appServiceFee,
286
- appServiceFeeAddress: params.appServiceFeeAddress
287
- };
288
- try {
289
- const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
290
- if (walletInfo && walletInfo.status === "success") {
291
- const isEtchSupported = walletInfo.result.methods?.includes("runes_etch");
292
- if (isEtchSupported) {
293
- const response = await this.requestInternal("runes_etch", params);
294
- if (response) {
295
- if (response.status === "success") {
296
- return response;
297
- }
298
- if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
299
- return response;
300
- }
301
- }
302
- }
303
- }
304
- const orderResponse = await new RunesApi(params.network).createEtchOrder(etchRequest);
305
- if (!orderResponse.data) {
306
- return {
307
- status: "error",
308
- error: {
309
- code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
310
- message: orderResponse.error.message
311
- }
312
- };
313
- }
314
- const paymentResponse = await this.requestInternal("sendTransfer", {
315
- recipients: [
316
- {
317
- address: orderResponse.data.fundAddress,
318
- amount: orderResponse.data.fundAmount
319
- }
320
- ]
321
- });
322
- if (paymentResponse.status !== "success") {
323
- return paymentResponse;
324
- }
325
- await new RunesApi(params.network).executeEtch(
326
- orderResponse.data.orderId,
327
- paymentResponse.result.txid
328
- );
329
- return {
330
- status: "success",
331
- result: {
332
- orderId: orderResponse.data.orderId,
333
- fundTransactionId: paymentResponse.result.txid,
334
- fundingAddress: orderResponse.data.fundAddress
335
- }
336
- };
337
- } catch (error) {
338
- return {
339
- status: "error",
340
- error: {
341
- code: -32603 /* INTERNAL_ERROR */,
342
- message: error.message
343
- }
344
- };
345
- }
346
- }
347
- async estimateMint(params) {
348
- const estimateMintRequest = {
349
- destinationAddress: params.destinationAddress,
350
- feeRate: params.feeRate,
351
- repeats: params.repeats,
352
- runeName: params.runeName,
353
- appServiceFee: params.appServiceFee,
354
- appServiceFeeAddress: params.appServiceFeeAddress
355
- };
356
- const response = await getRunesApiClient(
357
- params.network
358
- ).estimateMintCost(estimateMintRequest);
359
- if (response.data) {
360
- return {
361
- status: "success",
362
- result: response.data
363
- };
364
- }
365
- return {
366
- status: "error",
367
- error: {
368
- code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
369
- message: response.error.message
370
- }
371
- };
372
- }
373
- async estimateEtch(params) {
374
- const estimateEtchRequest = {
375
- destinationAddress: params.destinationAddress,
376
- feeRate: params.feeRate,
377
- runeName: params.runeName,
378
- divisibility: params.divisibility,
379
- symbol: params.symbol,
380
- premine: params.premine,
381
- isMintable: params.isMintable,
382
- terms: params.terms,
383
- inscriptionDetails: params.inscriptionDetails,
384
- delegateInscriptionId: params.delegateInscriptionId,
385
- appServiceFee: params.appServiceFee,
386
- appServiceFeeAddress: params.appServiceFeeAddress
387
- };
388
- const response = await getRunesApiClient(params.network).estimateEtchCost(estimateEtchRequest);
389
- if (response.data) {
390
- return {
391
- status: "success",
392
- result: response.data
393
- };
394
- }
395
- return {
396
- status: "error",
397
- error: {
398
- code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
399
- message: response.error.message
400
- }
401
- };
402
- }
403
- async getOrder(params) {
404
- const response = await getRunesApiClient(params.network).getOrder(params.id);
405
- if (response.data) {
406
- return {
407
- status: "success",
408
- result: response.data
409
- };
410
- }
411
- return {
412
- status: "error",
413
- error: {
414
- code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
415
- message: response.error.message
416
- }
417
- };
418
- }
419
- async estimateRbfOrder(params) {
420
- const rbfOrderRequest = {
421
- newFeeRate: params.newFeeRate,
422
- orderId: params.orderId
423
- };
424
- const response = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
425
- if (response.data) {
426
- return {
427
- status: "success",
428
- result: {
429
- fundingAddress: response.data.fundingAddress,
430
- rbfCost: response.data.rbfCost
431
- }
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 rbfOrder(params) {
443
- try {
444
- const rbfOrderRequest = {
445
- newFeeRate: params.newFeeRate,
446
- orderId: params.orderId
447
- };
448
- const orderResponse = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
449
- if (!orderResponse.data) {
450
- return {
451
- status: "error",
452
- error: {
453
- code: orderResponse.error.code === 400 || orderResponse.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
454
- message: orderResponse.error.message
455
- }
456
- };
457
- }
458
- const paymentResponse = await this.requestInternal("sendTransfer", {
459
- recipients: [
460
- {
461
- address: orderResponse.data.fundingAddress,
462
- amount: orderResponse.data.rbfCost
463
- }
464
- ]
465
- });
466
- if (paymentResponse.status !== "success") {
467
- return paymentResponse;
468
- }
469
- return {
470
- status: "success",
471
- result: {
472
- fundingAddress: orderResponse.data.fundingAddress,
473
- orderId: rbfOrderRequest.orderId,
474
- fundRBFTransactionId: paymentResponse.result.txid
475
- }
476
- };
477
- } catch (error) {
478
- return {
479
- status: "error",
480
- error: {
481
- code: -32603 /* INTERNAL_ERROR */,
482
- message: error.message
483
- }
484
- };
485
- }
486
- }
487
- async request(method, params) {
488
- switch (method) {
489
- case "runes_mint":
490
- return this.mintRunes(params);
491
- case "runes_etch":
492
- return this.etchRunes(params);
493
- case "runes_estimateMint":
494
- return this.estimateMint(params);
495
- case "runes_estimateEtch":
496
- return this.estimateEtch(params);
497
- case "runes_getOrder": {
498
- return this.getOrder(params);
499
- }
500
- case "runes_estimateRbfOrder": {
501
- return this.estimateRbfOrder(params);
502
- }
503
- case "runes_rbfOrder": {
504
- return this.rbfOrder(params);
505
- }
506
- default:
507
- return this.requestInternal(method, params);
508
- }
509
- }
510
- };
511
-
512
- // src/provider/index.ts
513
- import omit from "lodash.omit";
514
- async function getProviderOrThrow(getProvider) {
515
- const provider = await getProvider?.() || window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
516
- if (!provider) {
517
- throw new Error("No Bitcoin wallet installed");
518
- }
519
- return provider;
520
- }
521
- function getProviders() {
522
- if (!window.btc_providers)
523
- window.btc_providers = [];
524
- return window.btc_providers;
525
- }
526
- function getProviderById(providerId) {
527
- return providerId?.split(".").reduce((acc, part) => acc?.[part], window);
528
- }
529
- function isProviderInstalled(providerId) {
530
- return !!getProviderById(providerId);
531
- }
532
- function setDefaultProvider(providerId) {
533
- localStorage.setItem("sats-connect_defaultProvider", providerId);
534
- }
535
- function getDefaultProvider() {
536
- return localStorage.getItem("sats-connect_defaultProvider");
537
- }
538
- function removeDefaultProvider() {
539
- localStorage.removeItem("sats-connect_defaultProvider");
540
- }
541
- function getSupportedWallets() {
542
- const btc_providers = getProviders();
543
- const allProviders = [...btc_providers];
544
- for (const key in omit(DefaultAdaptersInfo, ["xverse"])) {
545
- allProviders.push(DefaultAdaptersInfo[key]);
546
- }
547
- const wallets = allProviders.map((provider) => {
548
- {
549
- return {
550
- ...provider,
551
- isInstalled: isProviderInstalled(provider.id)
552
- };
553
- }
554
- });
555
- return wallets;
556
- }
557
-
558
- // src/request/index.ts
559
- import * as v9 from "valibot";
560
-
561
- // src/addresses/index.ts
562
- import { createUnsecuredToken } from "jsontokens";
563
-
564
- // src/addresses/types.ts
565
- import * as v2 from "valibot";
566
- var AddressPurpose = /* @__PURE__ */ ((AddressPurpose2) => {
567
- AddressPurpose2["Ordinals"] = "ordinals";
568
- AddressPurpose2["Payment"] = "payment";
569
- AddressPurpose2["Stacks"] = "stacks";
570
- return AddressPurpose2;
571
- })(AddressPurpose || {});
572
- var AddressType = /* @__PURE__ */ ((AddressType3) => {
573
- AddressType3["p2pkh"] = "p2pkh";
574
- AddressType3["p2sh"] = "p2sh";
575
- AddressType3["p2wpkh"] = "p2wpkh";
576
- AddressType3["p2wsh"] = "p2wsh";
577
- AddressType3["p2tr"] = "p2tr";
578
- AddressType3["stacks"] = "stacks";
579
- return AddressType3;
580
- })(AddressType || {});
581
- var addressSchema = v2.object({
582
- address: v2.string(),
583
- publicKey: v2.string(),
584
- purpose: v2.enum(AddressPurpose),
585
- addressType: v2.enum(AddressType)
586
- });
587
-
588
- // src/addresses/index.ts
589
- var getAddress = async (options) => {
590
- const provider = await getProviderOrThrow(options.getProvider);
591
- const { purposes } = options.payload;
592
- if (!purposes) {
593
- throw new Error("Address purposes are required");
594
- }
595
- try {
596
- const request2 = createUnsecuredToken(options.payload);
597
- const response = await provider.connect(request2);
598
- options.onFinish?.(response);
599
- } catch (error) {
600
- console.error("[Connect] Error during address request", error);
601
- options.onCancel?.();
149
+ try {
150
+ const request2 = createUnsecuredToken(options.payload);
151
+ const response = await provider.connect(request2);
152
+ options.onFinish?.(response);
153
+ } catch (error) {
154
+ console.error("[Connect] Error during address request", error);
155
+ options.onCancel?.();
602
156
  }
603
157
  };
604
158
 
605
159
  // src/request/types/stxMethods.ts
606
- import * as v3 from "valibot";
160
+ import * as v4 from "valibot";
607
161
  var stxGetAddressesMethodName = "stx_getAddresses";
608
- var stxGetAddressesParamsSchema = v3.nullish(
609
- v3.object({
162
+ var stxGetAddressesParamsSchema = v4.nullish(
163
+ v4.object({
610
164
  /**
611
165
  * A message to be displayed to the user in the request prompt.
612
166
  */
613
- message: v3.optional(v3.string())
167
+ message: v4.optional(v4.string())
614
168
  })
615
169
  );
616
- var stxGetAddressesResultSchema = v3.object({
170
+ var stxGetAddressesResultSchema = v4.object({
617
171
  /**
618
172
  * The addresses generated for the given purposes.
619
173
  */
620
- addresses: v3.array(addressSchema)
174
+ addresses: v4.array(addressSchema)
621
175
  });
622
- var stxGetAddressesRequestMessageSchema = v3.object({
176
+ var stxGetAddressesRequestMessageSchema = v4.object({
623
177
  ...rpcRequestMessageSchema.entries,
624
- ...v3.object({
625
- method: v3.literal(stxGetAddressesMethodName),
178
+ ...v4.object({
179
+ method: v4.literal(stxGetAddressesMethodName),
626
180
  params: stxGetAddressesParamsSchema,
627
- id: v3.string()
181
+ id: v4.string()
628
182
  }).entries
629
183
  });
630
184
  var stxSignTransactionMethodName = "stx_signTransaction";
631
- var stxSignTransactionParamsSchema = v3.object({
185
+ var stxSignTransactionParamsSchema = v4.object({
632
186
  /**
633
187
  * The transaction to sign as a hex-encoded string.
634
188
  */
635
- transaction: v3.string(),
189
+ transaction: v4.string(),
636
190
  /**
637
191
  * The public key to sign the transaction with. The wallet may use any key
638
192
  * when not provided.
639
193
  */
640
- pubkey: v3.optional(v3.string()),
194
+ pubkey: v4.optional(v4.string()),
641
195
  /**
642
196
  * Whether to broadcast the transaction after signing. Defaults to `true`.
643
197
  */
644
- broadcast: v3.optional(v3.boolean())
198
+ broadcast: v4.optional(v4.boolean())
645
199
  });
646
- var stxSignTransactionResultSchema = v3.object({
200
+ var stxSignTransactionResultSchema = v4.object({
647
201
  /**
648
202
  * The signed transaction as a hex-encoded string.
649
203
  */
650
- transaction: v3.string()
204
+ transaction: v4.string()
651
205
  });
652
- var stxSignTransactionRequestMessageSchema = v3.object({
206
+ var stxSignTransactionRequestMessageSchema = v4.object({
653
207
  ...rpcRequestMessageSchema.entries,
654
- ...v3.object({
655
- method: v3.literal(stxSignTransactionMethodName),
208
+ ...v4.object({
209
+ method: v4.literal(stxSignTransactionMethodName),
656
210
  params: stxSignTransactionParamsSchema,
657
- id: v3.string()
211
+ id: v4.string()
658
212
  }).entries
659
213
  });
660
214
 
661
215
  // src/request/types/btcMethods.ts
662
- import * as v5 from "valibot";
216
+ import * as v6 from "valibot";
663
217
 
664
218
  // src/request/types/common.ts
665
- import * as v4 from "valibot";
219
+ import * as v5 from "valibot";
666
220
  var walletTypes = ["software", "ledger"];
667
- var walletTypeSchema = v4.picklist(walletTypes);
221
+ var walletTypeSchema = v5.picklist(walletTypes);
668
222
 
669
223
  // src/request/types/btcMethods.ts
670
224
  var getInfoMethodName = "getInfo";
671
- var getInfoParamsSchema = v5.nullish(v5.null());
672
- var getInfoResultSchema = v5.object({
225
+ var getInfoParamsSchema = v6.nullish(v6.null());
226
+ var getInfoResultSchema = v6.object({
673
227
  /**
674
228
  * Version of the wallet.
675
229
  */
676
- version: v5.string(),
230
+ version: v6.string(),
677
231
  /**
678
232
  * [WBIP](https://wbips.netlify.app/wbips/WBIP002) methods supported by the wallet.
679
233
  */
680
- methods: v5.optional(v5.array(v5.string())),
234
+ methods: v6.optional(v6.array(v6.string())),
681
235
  /**
682
236
  * List of WBIP standards supported by the wallet. Not currently used.
683
237
  */
684
- supports: v5.array(v5.string())
238
+ supports: v6.array(v6.string())
685
239
  });
686
- var getInfoRequestMessageSchema = v5.object({
240
+ var getInfoRequestMessageSchema = v6.object({
687
241
  ...rpcRequestMessageSchema.entries,
688
- ...v5.object({
689
- method: v5.literal(getInfoMethodName),
242
+ ...v6.object({
243
+ method: v6.literal(getInfoMethodName),
690
244
  params: getInfoParamsSchema,
691
- id: v5.string()
245
+ id: v6.string()
692
246
  }).entries
693
247
  });
694
248
  var getAddressesMethodName = "getAddresses";
695
- var getAddressesParamsSchema = v5.object({
249
+ var getAddressesParamsSchema = v6.object({
696
250
  /**
697
251
  * The purposes for which to generate addresses. See
698
252
  * {@linkcode AddressPurpose} for available purposes.
699
253
  */
700
- purposes: v5.array(v5.enum(AddressPurpose)),
254
+ purposes: v6.array(v6.enum(AddressPurpose)),
701
255
  /**
702
256
  * A message to be displayed to the user in the request prompt.
703
257
  */
704
- message: v5.optional(v5.string())
258
+ message: v6.optional(v6.string())
705
259
  });
706
- var getAddressesResultSchema = v5.object({
260
+ var getAddressesResultSchema = v6.object({
707
261
  /**
708
262
  * The addresses generated for the given purposes.
709
263
  */
710
- addresses: v5.array(addressSchema)
264
+ addresses: v6.array(addressSchema)
711
265
  });
712
- var getAddressesRequestMessageSchema = v5.object({
266
+ var getAddressesRequestMessageSchema = v6.object({
713
267
  ...rpcRequestMessageSchema.entries,
714
- ...v5.object({
715
- method: v5.literal(getAddressesMethodName),
268
+ ...v6.object({
269
+ method: v6.literal(getAddressesMethodName),
716
270
  params: getAddressesParamsSchema,
717
- id: v5.string()
271
+ id: v6.string()
718
272
  }).entries
719
273
  });
720
274
  var signMessageMethodName = "signMessage";
721
- var signMessageParamsSchema = v5.object({
275
+ var MessageSigningProtocols = /* @__PURE__ */ ((MessageSigningProtocols2) => {
276
+ MessageSigningProtocols2["ECDSA"] = "ECDSA";
277
+ MessageSigningProtocols2["BIP322"] = "BIP322";
278
+ return MessageSigningProtocols2;
279
+ })(MessageSigningProtocols || {});
280
+ var signMessageParamsSchema = v6.object({
722
281
  /**
723
282
  * The address used for signing.
724
283
  **/
725
- address: v5.string(),
284
+ address: v6.string(),
726
285
  /**
727
286
  * The message to sign.
728
287
  **/
729
- message: v5.string()
288
+ message: v6.string(),
289
+ /**
290
+ * The protocol to use for signing the message.
291
+ */
292
+ protocol: v6.optional(v6.enum(MessageSigningProtocols))
730
293
  });
731
- var signMessageResultSchema = v5.object({
294
+ var signMessageResultSchema = v6.object({
732
295
  /**
733
296
  * The signature of the message.
734
297
  */
735
- signature: v5.string(),
298
+ signature: v6.string(),
736
299
  /**
737
300
  * hash of the message.
738
301
  */
739
- messageHash: v5.string(),
302
+ messageHash: v6.string(),
740
303
  /**
741
304
  * The address used for signing.
742
305
  */
743
- address: v5.string()
306
+ address: v6.string(),
307
+ /**
308
+ * The protocol to use for signing the message.
309
+ */
310
+ protocol: v6.enum(MessageSigningProtocols)
744
311
  });
745
- var signMessageRequestMessageSchema = v5.object({
312
+ var signMessageRequestMessageSchema = v6.object({
746
313
  ...rpcRequestMessageSchema.entries,
747
- ...v5.object({
748
- method: v5.literal(signMessageMethodName),
314
+ ...v6.object({
315
+ method: v6.literal(signMessageMethodName),
749
316
  params: signMessageParamsSchema,
750
- id: v5.string()
317
+ id: v6.string()
751
318
  }).entries
752
319
  });
753
320
  var getAccountsMethodName = "getAccounts";
754
- var getAccountsParamsSchema = v5.object({
321
+ var getAccountsParamsSchema = v6.object({
755
322
  /**
756
323
  * The purposes for which to generate addresses. See
757
324
  * {@linkcode AddressPurpose} for available purposes.
758
325
  */
759
- purposes: v5.array(v5.enum(AddressPurpose)),
326
+ purposes: v6.array(v6.enum(AddressPurpose)),
760
327
  /**
761
328
  * A message to be displayed to the user in the request prompt.
762
329
  */
763
- message: v5.optional(v5.string())
330
+ message: v6.optional(v6.string())
764
331
  });
765
- var getAccountsResultSchema = v5.array(
766
- v5.object({
332
+ var getAccountsResultSchema = v6.array(
333
+ v6.object({
767
334
  ...addressSchema.entries,
768
- ...v5.object({
335
+ ...v6.object({
769
336
  walletType: walletTypeSchema
770
337
  }).entries
771
338
  })
772
339
  );
773
- var getAccountsRequestMessageSchema = v5.object({
340
+ var getAccountsRequestMessageSchema = v6.object({
774
341
  ...rpcRequestMessageSchema.entries,
775
- ...v5.object({
776
- method: v5.literal(getAccountsMethodName),
342
+ ...v6.object({
343
+ method: v6.literal(getAccountsMethodName),
777
344
  params: getAccountsParamsSchema,
778
- id: v5.string()
345
+ id: v6.string()
779
346
  }).entries
780
347
  });
781
348
  var getBalanceMethodName = "getBalance";
782
- var getBalanceParamsSchema = v5.nullish(v5.null());
783
- var getBalanceResultSchema = v5.object({
349
+ var getBalanceParamsSchema = v6.nullish(v6.null());
350
+ var getBalanceResultSchema = v6.object({
784
351
  /**
785
352
  * The confirmed balance of the wallet in sats. Using a string due to chrome
786
353
  * messages not supporting bigint
787
354
  * (https://issues.chromium.org/issues/40116184).
788
355
  */
789
- confirmed: v5.string(),
356
+ confirmed: v6.string(),
790
357
  /**
791
358
  * The unconfirmed balance of the wallet in sats. Using a string due to chrome
792
359
  * messages not supporting bigint
793
360
  * (https://issues.chromium.org/issues/40116184).
794
361
  */
795
- unconfirmed: v5.string(),
362
+ unconfirmed: v6.string(),
796
363
  /**
797
364
  * The total balance (both confirmed and unconfrimed UTXOs) of the wallet in
798
365
  * sats. Using a string due to chrome messages not supporting bigint
799
366
  * (https://issues.chromium.org/issues/40116184).
800
367
  */
801
- total: v5.string()
368
+ total: v6.string()
802
369
  });
803
- var getBalanceRequestMessageSchema = v5.object({
370
+ var getBalanceRequestMessageSchema = v6.object({
804
371
  ...rpcRequestMessageSchema.entries,
805
- ...v5.object({
806
- method: v5.literal(getBalanceMethodName),
807
- id: v5.string()
372
+ ...v6.object({
373
+ method: v6.literal(getBalanceMethodName),
374
+ id: v6.string()
808
375
  }).entries
809
376
  });
810
377
 
811
378
  // src/request/types/walletMethods.ts
812
- import * as v6 from "valibot";
379
+ import * as v7 from "valibot";
813
380
  var requestPermissionsMethodName = "wallet_requestPermissions";
814
- var requestPermissionsParamsSchema = v6.undefined();
815
- var requestPermissionsResultSchema = v6.literal(true);
816
- var requestPermissionsRequestMessageSchema = v6.object({
381
+ var requestPermissionsParamsSchema = v7.undefined();
382
+ var requestPermissionsResultSchema = v7.literal(true);
383
+ var requestPermissionsRequestMessageSchema = v7.object({
817
384
  ...rpcRequestMessageSchema.entries,
818
- ...v6.object({
819
- method: v6.literal(requestPermissionsMethodName),
385
+ ...v7.object({
386
+ method: v7.literal(requestPermissionsMethodName),
820
387
  params: requestPermissionsParamsSchema,
821
- id: v6.string()
388
+ id: v7.string()
822
389
  }).entries
823
390
  });
824
391
  var renouncePermissionsMethodName = "wallet_renouncePermissions";
825
- var renouncePermissionsParamsSchema = v6.undefined();
826
- var renouncePermissionsResultSchema = v6.literal(true);
827
- var renouncePermissionsRequestMessageSchema = v6.object({
392
+ var renouncePermissionsParamsSchema = v7.undefined();
393
+ var renouncePermissionsResultSchema = v7.literal(true);
394
+ var renouncePermissionsRequestMessageSchema = v7.object({
828
395
  ...rpcRequestMessageSchema.entries,
829
- ...v6.object({
830
- method: v6.literal(renouncePermissionsMethodName),
396
+ ...v7.object({
397
+ method: v7.literal(renouncePermissionsMethodName),
831
398
  params: renouncePermissionsParamsSchema,
832
- id: v6.string()
399
+ id: v7.string()
833
400
  }).entries
834
401
  });
835
402
  var getWalletTypeMethodName = "wallet_getWalletType";
836
- var getWalletTypeParamsSchema = v6.nullish(v6.null());
403
+ var getWalletTypeParamsSchema = v7.nullish(v7.null());
837
404
  var getWalletTypeResultSchema = walletTypeSchema;
838
- var getWalletTypeRequestMessageSchema = v6.object({
405
+ var getWalletTypeRequestMessageSchema = v7.object({
839
406
  ...rpcRequestMessageSchema.entries,
840
- ...v6.object({
841
- method: v6.literal(getWalletTypeMethodName),
842
- id: v6.string()
407
+ ...v7.object({
408
+ method: v7.literal(getWalletTypeMethodName),
409
+ id: v7.string()
843
410
  }).entries
844
411
  });
845
412
 
846
413
  // src/request/types/runesMethods.ts
847
- import * as v7 from "valibot";
414
+ import * as v8 from "valibot";
848
415
  var getRunesBalanceMethodName = "runes_getBalance";
849
- var getRunesBalanceParamsSchema = v7.nullish(v7.null());
850
- var getRunesBalanceResultSchema = v7.object({
851
- balances: v7.array(
852
- v7.object({
853
- runeName: v7.string(),
854
- amount: v7.string(),
855
- divisibility: v7.number(),
856
- symbol: v7.string(),
857
- inscriptionId: v7.nullish(v7.string())
416
+ var getRunesBalanceParamsSchema = v8.nullish(v8.null());
417
+ var getRunesBalanceResultSchema = v8.object({
418
+ balances: v8.array(
419
+ v8.object({
420
+ runeName: v8.string(),
421
+ amount: v8.string(),
422
+ divisibility: v8.number(),
423
+ symbol: v8.string(),
424
+ inscriptionId: v8.nullish(v8.string())
858
425
  })
859
426
  )
860
427
  });
861
- var getRunesBalanceRequestMessageSchema = v7.object({
428
+ var getRunesBalanceRequestMessageSchema = v8.object({
862
429
  ...rpcRequestMessageSchema.entries,
863
- ...v7.object({
864
- method: v7.literal(getRunesBalanceMethodName),
430
+ ...v8.object({
431
+ method: v8.literal(getRunesBalanceMethodName),
865
432
  params: getRunesBalanceParamsSchema,
866
- id: v7.string()
433
+ id: v8.string()
867
434
  }).entries
868
435
  });
869
436
 
870
437
  // src/request/types/ordinalsMethods.ts
871
- import * as v8 from "valibot";
438
+ import * as v9 from "valibot";
872
439
  var getInscriptionsMethodName = "ord_getInscriptions";
873
- var getInscriptionsParamsSchema = v8.object({
874
- offset: v8.number(),
875
- limit: v8.number()
440
+ var getInscriptionsParamsSchema = v9.object({
441
+ offset: v9.number(),
442
+ limit: v9.number()
876
443
  });
877
- var getInscriptionsResultSchema = v8.object({
878
- total: v8.number(),
879
- limit: v8.number(),
880
- offset: v8.number(),
881
- inscriptions: v8.array(
882
- v8.object({
883
- inscriptionId: v8.string(),
884
- inscriptionNumber: v8.string(),
885
- address: v8.string(),
886
- collectionName: v8.optional(v8.string()),
887
- postage: v8.string(),
888
- contentLength: v8.string(),
889
- contentType: v8.string(),
890
- timestamp: v8.number(),
891
- offset: v8.number(),
892
- genesisTransaction: v8.string(),
893
- output: v8.string()
444
+ var getInscriptionsResultSchema = v9.object({
445
+ total: v9.number(),
446
+ limit: v9.number(),
447
+ offset: v9.number(),
448
+ inscriptions: v9.array(
449
+ v9.object({
450
+ inscriptionId: v9.string(),
451
+ inscriptionNumber: v9.string(),
452
+ address: v9.string(),
453
+ collectionName: v9.optional(v9.string()),
454
+ postage: v9.string(),
455
+ contentLength: v9.string(),
456
+ contentType: v9.string(),
457
+ timestamp: v9.number(),
458
+ offset: v9.number(),
459
+ genesisTransaction: v9.string(),
460
+ output: v9.string()
894
461
  })
895
462
  )
896
463
  });
897
- var getInscriptionsSchema = v8.object({
464
+ var getInscriptionsSchema = v9.object({
898
465
  ...rpcRequestMessageSchema.entries,
899
- ...v8.object({
900
- method: v8.literal(getInscriptionsMethodName),
466
+ ...v9.object({
467
+ method: v9.literal(getInscriptionsMethodName),
901
468
  params: getInscriptionsParamsSchema,
902
- id: v8.string()
469
+ id: v9.string()
470
+ }).entries
471
+ });
472
+ var sendInscriptionsMethodName = "ord_sendInscriptions";
473
+ var sendInscriptionsParamsSchema = v9.object({
474
+ transfers: v9.array(
475
+ v9.object({
476
+ address: v9.string(),
477
+ inscriptionId: v9.string()
478
+ })
479
+ )
480
+ });
481
+ var sendInscriptionsResultSchema = v9.object({
482
+ txid: v9.string()
483
+ });
484
+ var sendInscriptionsSchema = v9.object({
485
+ ...rpcRequestMessageSchema.entries,
486
+ ...v9.object({
487
+ method: v9.literal(sendInscriptionsMethodName),
488
+ params: sendInscriptionsParamsSchema,
489
+ id: v9.string()
903
490
  }).entries
904
491
  });
905
492
 
@@ -909,33 +496,503 @@ var request = async (method, params, providerId) => {
909
496
  if (providerId) {
910
497
  provider = await getProviderById(providerId);
911
498
  }
912
- if (!provider) {
913
- throw new Error("no wallet provider was found");
499
+ if (!provider) {
500
+ throw new Error("no wallet provider was found");
501
+ }
502
+ if (!method) {
503
+ throw new Error("A wallet method is required");
504
+ }
505
+ const response = await provider.request(method, params);
506
+ if (v10.is(rpcErrorResponseMessageSchema, response)) {
507
+ return {
508
+ status: "error",
509
+ error: response.error
510
+ };
511
+ }
512
+ if (v10.is(rpcSuccessResponseMessageSchema, response)) {
513
+ return {
514
+ status: "success",
515
+ result: response.result
516
+ };
517
+ }
518
+ return {
519
+ status: "error",
520
+ error: {
521
+ code: -32603 /* INTERNAL_ERROR */,
522
+ message: "Received unknown response from provider.",
523
+ data: response
524
+ }
525
+ };
526
+ };
527
+ var addListener = (event, cb, providerId) => {
528
+ let provider = window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
529
+ if (providerId) {
530
+ provider = getProviderById(providerId);
531
+ }
532
+ if (!provider) {
533
+ throw new Error("no wallet provider was found");
534
+ }
535
+ return provider.addListener(event, cb);
536
+ };
537
+
538
+ // src/runes/api.ts
539
+ import axios from "axios";
540
+ var urlNetworkSuffix = {
541
+ ["Mainnet" /* Mainnet */]: "",
542
+ ["Testnet" /* Testnet */]: "-testnet",
543
+ ["Signet" /* Signet */]: "-signet"
544
+ };
545
+ var ORDINALS_API_BASE_URL = (network = "Mainnet" /* Mainnet */) => `https://ordinals${urlNetworkSuffix[network]}.xverse.app/v1`;
546
+ var RunesApi = class {
547
+ client;
548
+ constructor(network) {
549
+ this.client = axios.create({
550
+ baseURL: ORDINALS_API_BASE_URL(network)
551
+ });
552
+ }
553
+ parseError = (error) => {
554
+ return {
555
+ code: error.response?.status,
556
+ message: JSON.stringify(error.response?.data)
557
+ };
558
+ };
559
+ estimateMintCost = async (mintParams) => {
560
+ try {
561
+ const response = await this.client.post("/runes/mint/estimate", {
562
+ ...mintParams
563
+ });
564
+ return {
565
+ data: response.data
566
+ };
567
+ } catch (error) {
568
+ const err = error;
569
+ return {
570
+ error: this.parseError(err)
571
+ };
572
+ }
573
+ };
574
+ estimateEtchCost = async (etchParams) => {
575
+ try {
576
+ const response = await this.client.post("/runes/etch/estimate", {
577
+ ...etchParams
578
+ });
579
+ return {
580
+ data: response.data
581
+ };
582
+ } catch (error) {
583
+ const err = error;
584
+ return {
585
+ error: this.parseError(err)
586
+ };
587
+ }
588
+ };
589
+ createMintOrder = async (mintOrderParams) => {
590
+ try {
591
+ const response = await this.client.post("/runes/mint/orders", {
592
+ ...mintOrderParams
593
+ });
594
+ return {
595
+ data: response.data
596
+ };
597
+ } catch (error) {
598
+ const err = error;
599
+ return {
600
+ error: this.parseError(err)
601
+ };
602
+ }
603
+ };
604
+ createEtchOrder = async (etchOrderParams) => {
605
+ try {
606
+ const response = await this.client.post("/runes/etch/orders", {
607
+ ...etchOrderParams
608
+ });
609
+ return {
610
+ data: response.data
611
+ };
612
+ } catch (error) {
613
+ const err = error;
614
+ return {
615
+ error: this.parseError(err)
616
+ };
617
+ }
618
+ };
619
+ executeMint = async (orderId, fundTransactionId) => {
620
+ try {
621
+ const response = await this.client.post(`/runes/mint/orders/${orderId}/execute`, {
622
+ fundTransactionId
623
+ });
624
+ return {
625
+ data: response.data
626
+ };
627
+ } catch (error) {
628
+ const err = error;
629
+ return {
630
+ error: this.parseError(err)
631
+ };
632
+ }
633
+ };
634
+ executeEtch = async (orderId, fundTransactionId) => {
635
+ try {
636
+ const response = await this.client.post(`/runes/etch/orders/${orderId}/execute`, {
637
+ fundTransactionId
638
+ });
639
+ return {
640
+ data: response.data
641
+ };
642
+ } catch (error) {
643
+ const err = error;
644
+ return {
645
+ error: this.parseError(err)
646
+ };
647
+ }
648
+ };
649
+ getOrder = async (orderId) => {
650
+ try {
651
+ const response = await this.client.get(`/orders/${orderId}`);
652
+ return {
653
+ data: response.data
654
+ };
655
+ } catch (error) {
656
+ const err = error;
657
+ return {
658
+ error: this.parseError(err)
659
+ };
660
+ }
661
+ };
662
+ rbfOrder = async (rbfRequest) => {
663
+ const { orderId, newFeeRate } = rbfRequest;
664
+ try {
665
+ const response = await this.client.post(`/orders/${orderId}/rbf-estimate`, {
666
+ newFeeRate
667
+ });
668
+ return {
669
+ data: response.data
670
+ };
671
+ } catch (error) {
672
+ const err = error;
673
+ return {
674
+ error: this.parseError(err)
675
+ };
676
+ }
677
+ };
678
+ };
679
+ var clients = {};
680
+ var getRunesApiClient = (network = "Mainnet" /* Mainnet */) => {
681
+ if (!clients[network]) {
682
+ clients[network] = new RunesApi(network);
683
+ }
684
+ return clients[network];
685
+ };
686
+
687
+ // src/adapters/satsConnectAdapter.ts
688
+ var SatsConnectAdapter = class {
689
+ async mintRunes(params) {
690
+ try {
691
+ const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
692
+ if (walletInfo && walletInfo.status === "success") {
693
+ const isMintSupported = walletInfo.result.methods?.includes("runes_mint");
694
+ if (isMintSupported) {
695
+ const response = await this.requestInternal("runes_mint", params);
696
+ if (response) {
697
+ if (response.status === "success") {
698
+ return response;
699
+ }
700
+ if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
701
+ return response;
702
+ }
703
+ }
704
+ }
705
+ }
706
+ const mintRequest = {
707
+ destinationAddress: params.destinationAddress,
708
+ feeRate: params.feeRate,
709
+ refundAddress: params.refundAddress,
710
+ repeats: params.repeats,
711
+ runeName: params.runeName,
712
+ appServiceFee: params.appServiceFee,
713
+ appServiceFeeAddress: params.appServiceFeeAddress
714
+ };
715
+ const orderResponse = await new RunesApi(params.network).createMintOrder(mintRequest);
716
+ if (!orderResponse.data) {
717
+ return {
718
+ status: "error",
719
+ error: {
720
+ code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
721
+ message: orderResponse.error.message
722
+ }
723
+ };
724
+ }
725
+ const paymentResponse = await this.requestInternal("sendTransfer", {
726
+ recipients: [
727
+ {
728
+ address: orderResponse.data.fundAddress,
729
+ amount: orderResponse.data.fundAmount
730
+ }
731
+ ]
732
+ });
733
+ if (paymentResponse.status !== "success") {
734
+ return paymentResponse;
735
+ }
736
+ await new RunesApi(params.network).executeMint(
737
+ orderResponse.data.orderId,
738
+ paymentResponse.result.txid
739
+ );
740
+ return {
741
+ status: "success",
742
+ result: {
743
+ orderId: orderResponse.data.orderId,
744
+ fundTransactionId: paymentResponse.result.txid,
745
+ fundingAddress: orderResponse.data.fundAddress
746
+ }
747
+ };
748
+ } catch (error) {
749
+ return {
750
+ status: "error",
751
+ error: {
752
+ code: -32603 /* INTERNAL_ERROR */,
753
+ message: error.message
754
+ }
755
+ };
756
+ }
757
+ }
758
+ async etchRunes(params) {
759
+ const etchRequest = {
760
+ destinationAddress: params.destinationAddress,
761
+ refundAddress: params.refundAddress,
762
+ feeRate: params.feeRate,
763
+ runeName: params.runeName,
764
+ divisibility: params.divisibility,
765
+ symbol: params.symbol,
766
+ premine: params.premine,
767
+ isMintable: params.isMintable,
768
+ terms: params.terms,
769
+ inscriptionDetails: params.inscriptionDetails,
770
+ delegateInscriptionId: params.delegateInscriptionId,
771
+ appServiceFee: params.appServiceFee,
772
+ appServiceFeeAddress: params.appServiceFeeAddress
773
+ };
774
+ try {
775
+ const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
776
+ if (walletInfo && walletInfo.status === "success") {
777
+ const isEtchSupported = walletInfo.result.methods?.includes("runes_etch");
778
+ if (isEtchSupported) {
779
+ const response = await this.requestInternal("runes_etch", params);
780
+ if (response) {
781
+ if (response.status === "success") {
782
+ return response;
783
+ }
784
+ if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
785
+ return response;
786
+ }
787
+ }
788
+ }
789
+ }
790
+ const orderResponse = await new RunesApi(params.network).createEtchOrder(etchRequest);
791
+ if (!orderResponse.data) {
792
+ return {
793
+ status: "error",
794
+ error: {
795
+ code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
796
+ message: orderResponse.error.message
797
+ }
798
+ };
799
+ }
800
+ const paymentResponse = await this.requestInternal("sendTransfer", {
801
+ recipients: [
802
+ {
803
+ address: orderResponse.data.fundAddress,
804
+ amount: orderResponse.data.fundAmount
805
+ }
806
+ ]
807
+ });
808
+ if (paymentResponse.status !== "success") {
809
+ return paymentResponse;
810
+ }
811
+ await new RunesApi(params.network).executeEtch(
812
+ orderResponse.data.orderId,
813
+ paymentResponse.result.txid
814
+ );
815
+ return {
816
+ status: "success",
817
+ result: {
818
+ orderId: orderResponse.data.orderId,
819
+ fundTransactionId: paymentResponse.result.txid,
820
+ fundingAddress: orderResponse.data.fundAddress
821
+ }
822
+ };
823
+ } catch (error) {
824
+ return {
825
+ status: "error",
826
+ error: {
827
+ code: -32603 /* INTERNAL_ERROR */,
828
+ message: error.message
829
+ }
830
+ };
831
+ }
914
832
  }
915
- if (!method) {
916
- throw new Error("A wallet method is required");
833
+ async estimateMint(params) {
834
+ const estimateMintRequest = {
835
+ destinationAddress: params.destinationAddress,
836
+ feeRate: params.feeRate,
837
+ repeats: params.repeats,
838
+ runeName: params.runeName,
839
+ appServiceFee: params.appServiceFee,
840
+ appServiceFeeAddress: params.appServiceFeeAddress
841
+ };
842
+ const response = await getRunesApiClient(
843
+ params.network
844
+ ).estimateMintCost(estimateMintRequest);
845
+ if (response.data) {
846
+ return {
847
+ status: "success",
848
+ result: response.data
849
+ };
850
+ }
851
+ return {
852
+ status: "error",
853
+ error: {
854
+ code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
855
+ message: response.error.message
856
+ }
857
+ };
917
858
  }
918
- const response = await provider.request(method, params);
919
- if (v9.is(rpcErrorResponseMessageSchema, response)) {
859
+ async estimateEtch(params) {
860
+ const estimateEtchRequest = {
861
+ destinationAddress: params.destinationAddress,
862
+ feeRate: params.feeRate,
863
+ runeName: params.runeName,
864
+ divisibility: params.divisibility,
865
+ symbol: params.symbol,
866
+ premine: params.premine,
867
+ isMintable: params.isMintable,
868
+ terms: params.terms,
869
+ inscriptionDetails: params.inscriptionDetails,
870
+ delegateInscriptionId: params.delegateInscriptionId,
871
+ appServiceFee: params.appServiceFee,
872
+ appServiceFeeAddress: params.appServiceFeeAddress
873
+ };
874
+ const response = await getRunesApiClient(params.network).estimateEtchCost(estimateEtchRequest);
875
+ if (response.data) {
876
+ return {
877
+ status: "success",
878
+ result: response.data
879
+ };
880
+ }
920
881
  return {
921
882
  status: "error",
922
- error: response.error
883
+ error: {
884
+ code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
885
+ message: response.error.message
886
+ }
923
887
  };
924
888
  }
925
- if (v9.is(rpcSuccessResponseMessageSchema, response)) {
889
+ async getOrder(params) {
890
+ const response = await getRunesApiClient(params.network).getOrder(params.id);
891
+ if (response.data) {
892
+ return {
893
+ status: "success",
894
+ result: response.data
895
+ };
896
+ }
926
897
  return {
927
- status: "success",
928
- result: response.result
898
+ status: "error",
899
+ error: {
900
+ code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
901
+ message: response.error.message
902
+ }
929
903
  };
930
904
  }
931
- return {
932
- status: "error",
933
- error: {
934
- code: -32603 /* INTERNAL_ERROR */,
935
- message: "Received unknown response from provider.",
936
- data: response
905
+ async estimateRbfOrder(params) {
906
+ const rbfOrderRequest = {
907
+ newFeeRate: params.newFeeRate,
908
+ orderId: params.orderId
909
+ };
910
+ const response = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
911
+ if (response.data) {
912
+ return {
913
+ status: "success",
914
+ result: {
915
+ fundingAddress: response.data.fundingAddress,
916
+ rbfCost: response.data.rbfCost
917
+ }
918
+ };
937
919
  }
938
- };
920
+ return {
921
+ status: "error",
922
+ error: {
923
+ code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
924
+ message: response.error.message
925
+ }
926
+ };
927
+ }
928
+ async rbfOrder(params) {
929
+ try {
930
+ const rbfOrderRequest = {
931
+ newFeeRate: params.newFeeRate,
932
+ orderId: params.orderId
933
+ };
934
+ const orderResponse = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
935
+ if (!orderResponse.data) {
936
+ return {
937
+ status: "error",
938
+ error: {
939
+ code: orderResponse.error.code === 400 || orderResponse.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
940
+ message: orderResponse.error.message
941
+ }
942
+ };
943
+ }
944
+ const paymentResponse = await this.requestInternal("sendTransfer", {
945
+ recipients: [
946
+ {
947
+ address: orderResponse.data.fundingAddress,
948
+ amount: orderResponse.data.rbfCost
949
+ }
950
+ ]
951
+ });
952
+ if (paymentResponse.status !== "success") {
953
+ return paymentResponse;
954
+ }
955
+ return {
956
+ status: "success",
957
+ result: {
958
+ fundingAddress: orderResponse.data.fundingAddress,
959
+ orderId: rbfOrderRequest.orderId,
960
+ fundRBFTransactionId: paymentResponse.result.txid
961
+ }
962
+ };
963
+ } catch (error) {
964
+ return {
965
+ status: "error",
966
+ error: {
967
+ code: -32603 /* INTERNAL_ERROR */,
968
+ message: error.message
969
+ }
970
+ };
971
+ }
972
+ }
973
+ async request(method, params) {
974
+ switch (method) {
975
+ case "runes_mint":
976
+ return this.mintRunes(params);
977
+ case "runes_etch":
978
+ return this.etchRunes(params);
979
+ case "runes_estimateMint":
980
+ return this.estimateMint(params);
981
+ case "runes_estimateEtch":
982
+ return this.estimateEtch(params);
983
+ case "runes_getOrder": {
984
+ return this.getOrder(params);
985
+ }
986
+ case "runes_estimateRbfOrder": {
987
+ return this.estimateRbfOrder(params);
988
+ }
989
+ case "runes_rbfOrder": {
990
+ return this.rbfOrder(params);
991
+ }
992
+ default:
993
+ return this.requestInternal(method, params);
994
+ }
995
+ }
939
996
  };
940
997
 
941
998
  // src/adapters/xverse.ts
@@ -944,6 +1001,15 @@ var XverseAdapter = class extends SatsConnectAdapter {
944
1001
  requestInternal = async (method, params) => {
945
1002
  return request(method, params, this.id);
946
1003
  };
1004
+ addListener = (event, cb) => {
1005
+ return addListener(
1006
+ event,
1007
+ // The types of the `addListener` function being called here are not
1008
+ // entirely accurate.
1009
+ cb,
1010
+ this.id
1011
+ );
1012
+ };
947
1013
  };
948
1014
 
949
1015
  // src/adapters/unisat.ts
@@ -1112,6 +1178,9 @@ var BaseAdapter = class extends SatsConnectAdapter {
1112
1178
  requestInternal = async (method, params) => {
1113
1179
  return request(method, params, this.id);
1114
1180
  };
1181
+ addListener = (..._args) => {
1182
+ throw new Error("Method not supported for `BaseAdapter`.");
1183
+ };
1115
1184
  };
1116
1185
 
1117
1186
  // src/adapters/index.ts
@@ -1157,7 +1226,8 @@ var extractOrValidateCapabilities = (provider, reportedCapabilities) => {
1157
1226
  sendBtcTransaction: validateCapability("sendBtcTransaction"),
1158
1227
  createInscription: validateCapability("createInscription"),
1159
1228
  createRepeatInscriptions: validateCapability("createRepeatInscriptions"),
1160
- signMultipleTransactions: validateCapability("signMultipleTransactions")
1229
+ signMultipleTransactions: validateCapability("signMultipleTransactions"),
1230
+ addListener: validateCapability("addListener")
1161
1231
  };
1162
1232
  return Object.entries(capabilityMap).reduce((acc, [capability, value]) => {
1163
1233
  if (value)
@@ -1351,9 +1421,13 @@ export {
1351
1421
  BaseAdapter,
1352
1422
  BitcoinNetworkType,
1353
1423
  DefaultAdaptersInfo,
1424
+ MessageSigningProtocols,
1354
1425
  RpcErrorCode,
1355
1426
  RpcIdSchema,
1356
1427
  SatsConnectAdapter,
1428
+ accountChangeEventName,
1429
+ accountChangeSchema,
1430
+ addListener,
1357
1431
  addressSchema,
1358
1432
  createInscription,
1359
1433
  createRepeatInscriptions,
@@ -1394,6 +1468,8 @@ export {
1394
1468
  getWalletTypeRequestMessageSchema,
1395
1469
  getWalletTypeResultSchema,
1396
1470
  isProviderInstalled,
1471
+ networkChangeEventName,
1472
+ networkChangeSchema,
1397
1473
  removeDefaultProvider,
1398
1474
  renouncePermissionsMethodName,
1399
1475
  renouncePermissionsParamsSchema,
@@ -1409,6 +1485,10 @@ export {
1409
1485
  rpcResponseMessageSchema,
1410
1486
  rpcSuccessResponseMessageSchema,
1411
1487
  sendBtcTransaction,
1488
+ sendInscriptionsMethodName,
1489
+ sendInscriptionsParamsSchema,
1490
+ sendInscriptionsResultSchema,
1491
+ sendInscriptionsSchema,
1412
1492
  setDefaultProvider,
1413
1493
  signMessage,
1414
1494
  signMessageMethodName,
@@ -1425,6 +1505,7 @@ export {
1425
1505
  stxSignTransactionParamsSchema,
1426
1506
  stxSignTransactionRequestMessageSchema,
1427
1507
  stxSignTransactionResultSchema,
1508
+ walletEventSchema,
1428
1509
  walletTypeSchema,
1429
1510
  walletTypes
1430
1511
  };