@sats-connect/core 0.0.3-aae39fb → 0.0.3-e7448df

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.d.mts CHANGED
@@ -672,8 +672,6 @@ declare abstract class SatsConnectAdapter {
672
672
  abstract readonly id: string;
673
673
  private mintRunes;
674
674
  private etchRunes;
675
- private estimateMint;
676
- private estimateEtch;
677
675
  request<Method extends keyof Requests>(method: Method, params: Params<Method>): Promise<RpcResult<Method> | undefined>;
678
676
  protected abstract requestInternal<Method extends keyof Requests>(method: Method, params: Params<Method>): Promise<RpcResult<Method> | undefined>;
679
677
  }
package/dist/index.mjs CHANGED
@@ -4,15 +4,15 @@ var BitcoinNetworkType = /* @__PURE__ */ ((BitcoinNetworkType2) => {
4
4
  BitcoinNetworkType2["Testnet"] = "Testnet";
5
5
  return BitcoinNetworkType2;
6
6
  })(BitcoinNetworkType || {});
7
- var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode3) => {
8
- RpcErrorCode3[RpcErrorCode3["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
9
- RpcErrorCode3[RpcErrorCode3["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
10
- RpcErrorCode3[RpcErrorCode3["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
11
- RpcErrorCode3[RpcErrorCode3["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
12
- RpcErrorCode3[RpcErrorCode3["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
13
- RpcErrorCode3[RpcErrorCode3["USER_REJECTION"] = -32e3] = "USER_REJECTION";
14
- RpcErrorCode3[RpcErrorCode3["METHOD_NOT_SUPPORTED"] = -32001] = "METHOD_NOT_SUPPORTED";
15
- return RpcErrorCode3;
7
+ var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
8
+ RpcErrorCode2[RpcErrorCode2["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
9
+ RpcErrorCode2[RpcErrorCode2["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
10
+ RpcErrorCode2[RpcErrorCode2["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
11
+ RpcErrorCode2[RpcErrorCode2["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
12
+ RpcErrorCode2[RpcErrorCode2["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
13
+ RpcErrorCode2[RpcErrorCode2["USER_REJECTION"] = -32e3] = "USER_REJECTION";
14
+ RpcErrorCode2[RpcErrorCode2["METHOD_NOT_SUPPORTED"] = -32001] = "METHOD_NOT_SUPPORTED";
15
+ return RpcErrorCode2;
16
16
  })(RpcErrorCode || {});
17
17
 
18
18
  // src/runes/index.ts
@@ -31,14 +31,19 @@ var RunesApi = class {
31
31
  ...mintParams
32
32
  });
33
33
  return {
34
- data: response.data
34
+ status: "success",
35
+ result: {
36
+ costBreakdown: response.data.costBreakdown,
37
+ totalCost: response.data.totalCost,
38
+ totalSize: response.data.totalSize
39
+ }
35
40
  };
36
41
  } catch (error) {
37
- const err = error;
38
42
  return {
43
+ status: "error",
39
44
  error: {
40
- code: err.response?.status,
41
- message: err.response?.data
45
+ code: -32603 /* INTERNAL_ERROR */,
46
+ message: error.message
42
47
  }
43
48
  };
44
49
  }
@@ -49,14 +54,19 @@ var RunesApi = class {
49
54
  ...etchParams
50
55
  });
51
56
  return {
52
- data: response.data
57
+ status: "success",
58
+ result: {
59
+ costBreakdown: response.data.costBreakdown,
60
+ totalCost: response.data.totalCost,
61
+ totalSize: response.data.totalSize
62
+ }
53
63
  };
54
64
  } catch (error) {
55
- const err = error;
56
65
  return {
66
+ status: "error",
57
67
  error: {
58
- code: err.response?.status,
59
- message: err.response?.data
68
+ code: -32603 /* INTERNAL_ERROR */,
69
+ message: error.data.message
60
70
  }
61
71
  };
62
72
  }
@@ -70,12 +80,8 @@ var RunesApi = class {
70
80
  data: response.data
71
81
  };
72
82
  } catch (error) {
73
- const err = error;
74
83
  return {
75
- error: {
76
- code: err.response?.status,
77
- message: err.response?.data
78
- }
84
+ error: error.data.message
79
85
  };
80
86
  }
81
87
  };
@@ -88,12 +94,8 @@ var RunesApi = class {
88
94
  data: response.data
89
95
  };
90
96
  } catch (error) {
91
- const err = error;
92
97
  return {
93
- error: {
94
- code: err.response?.status,
95
- message: err.response?.data
96
- }
98
+ error: error.data.message
97
99
  };
98
100
  }
99
101
  };
@@ -106,12 +108,8 @@ var RunesApi = class {
106
108
  data: response.data
107
109
  };
108
110
  } catch (error) {
109
- const err = error;
110
111
  return {
111
- error: {
112
- code: err.response?.status,
113
- message: err.response?.data
114
- }
112
+ error: error.data.message
115
113
  };
116
114
  }
117
115
  };
@@ -124,62 +122,57 @@ var RunesApi = class {
124
122
  data: response.data
125
123
  };
126
124
  } catch (error) {
127
- const err = error;
128
125
  return {
129
- error: {
130
- code: err.response?.status,
131
- message: err.response?.data
132
- }
126
+ error: error.data.message
133
127
  };
134
128
  }
135
129
  };
136
130
  };
137
- var testnetClient = new RunesApi("Testnet" /* Testnet */);
138
- var mainnetClient = new RunesApi("Mainnet" /* Mainnet */);
139
- var getRunesApiClient = (network = "Mainnet" /* Mainnet */) => network === "Mainnet" /* Mainnet */ ? mainnetClient : testnetClient;
140
131
 
141
132
  // src/adapters/satsConnectAdapter.ts
142
133
  var SatsConnectAdapter = class {
143
134
  async mintRunes(params) {
144
135
  try {
145
136
  const orderResponse = await new RunesApi(params.network).createMintOrder(params);
146
- if (!orderResponse.data) {
147
- return {
148
- status: "error",
149
- error: {
150
- code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
151
- message: orderResponse.error.message
152
- }
153
- };
154
- }
155
- const paymentResponse = await this.requestInternal("sendTransfer", {
156
- recipients: [
157
- {
158
- address: orderResponse.data.fundAddress,
159
- amount: orderResponse.data.fundAmount
160
- }
161
- ]
162
- });
163
- if (paymentResponse?.status !== "success") {
137
+ if (orderResponse.data) {
138
+ const paymentResponse = await this.requestInternal("sendTransfer", {
139
+ recipients: [
140
+ {
141
+ address: orderResponse.data.fundAddress,
142
+ amount: orderResponse.data.fundAmount
143
+ }
144
+ ]
145
+ });
146
+ if (paymentResponse?.status === "success") {
147
+ await new RunesApi(params.network).executeMint(
148
+ orderResponse.data.orderId,
149
+ paymentResponse.result.txid
150
+ );
151
+ return {
152
+ status: "success",
153
+ result: {
154
+ orderId: orderResponse.data.orderId,
155
+ fundTransactionId: paymentResponse.result.txid
156
+ }
157
+ };
158
+ } else {
159
+ return {
160
+ status: "error",
161
+ error: {
162
+ code: -32e3 /* USER_REJECTION */,
163
+ message: "User rejected the payment request"
164
+ }
165
+ };
166
+ }
167
+ } else {
164
168
  return {
165
169
  status: "error",
166
170
  error: {
167
- code: -32e3 /* USER_REJECTION */,
168
- message: "User rejected the payment request"
171
+ code: -32603 /* INTERNAL_ERROR */,
172
+ message: orderResponse.error
169
173
  }
170
174
  };
171
175
  }
172
- await new RunesApi(params.network).executeMint(
173
- orderResponse.data.orderId,
174
- paymentResponse.result.txid
175
- );
176
- return {
177
- status: "success",
178
- result: {
179
- orderId: orderResponse.data.orderId,
180
- fundTransactionId: paymentResponse.result.txid
181
- }
182
- };
183
176
  } catch (error) {
184
177
  return {
185
178
  status: "error",
@@ -193,43 +186,45 @@ var SatsConnectAdapter = class {
193
186
  async etchRunes(params) {
194
187
  try {
195
188
  const orderResponse = await new RunesApi(params.network).createEtchOrder(params);
196
- if (!orderResponse.data) {
197
- return {
198
- status: "error",
199
- error: {
200
- code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
201
- message: orderResponse.error.message
202
- }
203
- };
204
- }
205
- const paymentResponse = await this.requestInternal("sendTransfer", {
206
- recipients: [
207
- {
208
- address: orderResponse.data.fundAddress,
209
- amount: orderResponse.data.fundAmount
210
- }
211
- ]
212
- });
213
- if (paymentResponse?.status !== "success") {
189
+ if (orderResponse.data) {
190
+ const paymentResponse = await this.requestInternal("sendTransfer", {
191
+ recipients: [
192
+ {
193
+ address: orderResponse.data.fundAddress,
194
+ amount: orderResponse.data.fundAmount
195
+ }
196
+ ]
197
+ });
198
+ if (paymentResponse?.status === "success") {
199
+ await new RunesApi(params.network).executeEtch(
200
+ orderResponse.data.orderId,
201
+ paymentResponse.result.txid
202
+ );
203
+ return {
204
+ status: "success",
205
+ result: {
206
+ orderId: orderResponse.data.orderId,
207
+ fundTransactionId: paymentResponse.result.txid
208
+ }
209
+ };
210
+ } else {
211
+ return {
212
+ status: "error",
213
+ error: {
214
+ code: -32e3 /* USER_REJECTION */,
215
+ message: "User rejected the payment request"
216
+ }
217
+ };
218
+ }
219
+ } else {
214
220
  return {
215
221
  status: "error",
216
222
  error: {
217
- code: -32e3 /* USER_REJECTION */,
218
- message: "User rejected the payment request"
223
+ code: -32603 /* INTERNAL_ERROR */,
224
+ message: orderResponse.error
219
225
  }
220
226
  };
221
227
  }
222
- await new RunesApi(params.network).executeEtch(
223
- orderResponse.data.orderId,
224
- paymentResponse.result.txid
225
- );
226
- return {
227
- status: "success",
228
- result: {
229
- orderId: orderResponse.data.orderId,
230
- fundTransactionId: paymentResponse.result.txid
231
- }
232
- };
233
228
  } catch (error) {
234
229
  return {
235
230
  status: "error",
@@ -240,42 +235,6 @@ var SatsConnectAdapter = class {
240
235
  };
241
236
  }
242
237
  }
243
- async estimateMint(params) {
244
- const response = await getRunesApiClient(
245
- params.network
246
- ).estimateMintCost(params);
247
- if (response.data) {
248
- return {
249
- status: "success",
250
- result: response.data
251
- };
252
- }
253
- return {
254
- status: "error",
255
- error: {
256
- code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
257
- message: response.error.message
258
- }
259
- };
260
- }
261
- async estimateEtch(params) {
262
- const response = await getRunesApiClient(
263
- params.network
264
- ).estimateEtchCost(params);
265
- if (response.data) {
266
- return {
267
- status: "success",
268
- result: response.data
269
- };
270
- }
271
- return {
272
- status: "error",
273
- error: {
274
- code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
275
- message: response.error.message
276
- }
277
- };
278
- }
279
238
  async request(method, params) {
280
239
  switch (method) {
281
240
  case "runes_mint":
@@ -283,9 +242,13 @@ var SatsConnectAdapter = class {
283
242
  case "runes_etch":
284
243
  return this.etchRunes(params);
285
244
  case "runes_estimateMint":
286
- return this.estimateMint(params);
245
+ return new RunesApi(params.network).estimateMintCost(
246
+ params
247
+ );
287
248
  case "runes_estimateEtch":
288
- return this.estimateEtch(params);
249
+ return new RunesApi(params.network).estimateEtchCost(
250
+ params
251
+ );
289
252
  default:
290
253
  return this.requestInternal(method, params);
291
254
  }
@@ -369,6 +332,7 @@ var isRpcSuccessResponse = (response) => {
369
332
  var XverseAdapter = class extends SatsConnectAdapter {
370
333
  id = DefaultAdaptersInfo.xverse.id;
371
334
  requestInternal = async (method, params) => {
335
+ console.log("XverseAdapter requestInternal", method, params);
372
336
  return request(method, params, this.id);
373
337
  };
374
338
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sats-connect/core",
3
- "version": "0.0.3-aae39fb",
3
+ "version": "0.0.3-e7448df",
4
4
  "main": "dist/index.mjs",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.mts",
@@ -24,7 +24,7 @@
24
24
  ]
25
25
  },
26
26
  "dependencies": {
27
- "axios": "1.6.8",
27
+ "axios": "^1.6.8",
28
28
  "bitcoin-address-validation": "2.2.3",
29
29
  "buffer": "6.0.3",
30
30
  "jsontokens": "4.0.1",