@sats-connect/core 0.0.3-9ea8b00 → 0.0.3-b1484d5

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
@@ -25,24 +25,26 @@ var RunesApi = class {
25
25
  baseURL: `${RUNES_API_BASE_URL(network)}`
26
26
  });
27
27
  }
28
- parseError = (error) => {
29
- return {
30
- code: error.response?.status,
31
- message: JSON.stringify(error.response?.data)
32
- };
33
- };
34
28
  estimateMintCost = async (mintParams) => {
35
29
  try {
36
30
  const response = await this.client.post("/mint/estimate", {
37
31
  ...mintParams
38
32
  });
39
33
  return {
40
- data: response.data
34
+ status: "success",
35
+ result: {
36
+ costBreakdown: response.data.costBreakdown,
37
+ totalCost: response.data.totalCost,
38
+ totalSize: response.data.totalSize
39
+ }
41
40
  };
42
41
  } catch (error) {
43
- const err = error;
44
42
  return {
45
- error: this.parseError(err)
43
+ status: "error",
44
+ error: {
45
+ code: -32603 /* INTERNAL_ERROR */,
46
+ message: error.message
47
+ }
46
48
  };
47
49
  }
48
50
  };
@@ -52,12 +54,20 @@ var RunesApi = class {
52
54
  ...etchParams
53
55
  });
54
56
  return {
55
- data: response.data
57
+ status: "success",
58
+ result: {
59
+ costBreakdown: response.data.costBreakdown,
60
+ totalCost: response.data.totalCost,
61
+ totalSize: response.data.totalSize
62
+ }
56
63
  };
57
64
  } catch (error) {
58
- const err = error;
59
65
  return {
60
- error: this.parseError(err)
66
+ status: "error",
67
+ error: {
68
+ code: -32603 /* INTERNAL_ERROR */,
69
+ message: error.data.message
70
+ }
61
71
  };
62
72
  }
63
73
  };
@@ -70,9 +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: this.parseError(err)
84
+ error: error.data.message
76
85
  };
77
86
  }
78
87
  };
@@ -85,9 +94,8 @@ var RunesApi = class {
85
94
  data: response.data
86
95
  };
87
96
  } catch (error) {
88
- const err = error;
89
97
  return {
90
- error: this.parseError(err)
98
+ error: error.data.message
91
99
  };
92
100
  }
93
101
  };
@@ -100,9 +108,8 @@ var RunesApi = class {
100
108
  data: response.data
101
109
  };
102
110
  } catch (error) {
103
- const err = error;
104
111
  return {
105
- error: this.parseError(err)
112
+ error: error.data.message
106
113
  };
107
114
  }
108
115
  };
@@ -115,59 +122,57 @@ var RunesApi = class {
115
122
  data: response.data
116
123
  };
117
124
  } catch (error) {
118
- const err = error;
119
125
  return {
120
- error: this.parseError(err)
126
+ error: error.data.message
121
127
  };
122
128
  }
123
129
  };
124
130
  };
125
- var testnetClient = new RunesApi("Testnet" /* Testnet */);
126
- var mainnetClient = new RunesApi("Mainnet" /* Mainnet */);
127
- var getRunesApiClient = (network = "Mainnet" /* Mainnet */) => network === "Mainnet" /* Mainnet */ ? mainnetClient : testnetClient;
128
131
 
129
132
  // src/adapters/satsConnectAdapter.ts
130
133
  var SatsConnectAdapter = class {
131
134
  async mintRunes(params) {
132
135
  try {
133
136
  const orderResponse = await new RunesApi(params.network).createMintOrder(params);
134
- if (!orderResponse.data) {
135
- return {
136
- status: "error",
137
- error: {
138
- code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
139
- message: orderResponse.error.message
140
- }
141
- };
142
- }
143
- const paymentResponse = await this.requestInternal("sendTransfer", {
144
- recipients: [
145
- {
146
- address: orderResponse.data.fundAddress,
147
- amount: orderResponse.data.fundAmount
148
- }
149
- ]
150
- });
151
- 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 {
152
168
  return {
153
169
  status: "error",
154
170
  error: {
155
- code: -32e3 /* USER_REJECTION */,
156
- message: "User rejected the payment request"
171
+ code: -32603 /* INTERNAL_ERROR */,
172
+ message: orderResponse.error
157
173
  }
158
174
  };
159
175
  }
160
- await new RunesApi(params.network).executeMint(
161
- orderResponse.data.orderId,
162
- paymentResponse.result.txid
163
- );
164
- return {
165
- status: "success",
166
- result: {
167
- orderId: orderResponse.data.orderId,
168
- fundTransactionId: paymentResponse.result.txid
169
- }
170
- };
171
176
  } catch (error) {
172
177
  return {
173
178
  status: "error",
@@ -181,43 +186,45 @@ var SatsConnectAdapter = class {
181
186
  async etchRunes(params) {
182
187
  try {
183
188
  const orderResponse = await new RunesApi(params.network).createEtchOrder(params);
184
- if (!orderResponse.data) {
185
- return {
186
- status: "error",
187
- error: {
188
- code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
189
- message: orderResponse.error.message
190
- }
191
- };
192
- }
193
- const paymentResponse = await this.requestInternal("sendTransfer", {
194
- recipients: [
195
- {
196
- address: orderResponse.data.fundAddress,
197
- amount: orderResponse.data.fundAmount
198
- }
199
- ]
200
- });
201
- 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 {
202
220
  return {
203
221
  status: "error",
204
222
  error: {
205
- code: -32e3 /* USER_REJECTION */,
206
- message: "User rejected the payment request"
223
+ code: -32603 /* INTERNAL_ERROR */,
224
+ message: orderResponse.error
207
225
  }
208
226
  };
209
227
  }
210
- await new RunesApi(params.network).executeEtch(
211
- orderResponse.data.orderId,
212
- paymentResponse.result.txid
213
- );
214
- return {
215
- status: "success",
216
- result: {
217
- orderId: orderResponse.data.orderId,
218
- fundTransactionId: paymentResponse.result.txid
219
- }
220
- };
221
228
  } catch (error) {
222
229
  return {
223
230
  status: "error",
@@ -228,42 +235,6 @@ var SatsConnectAdapter = class {
228
235
  };
229
236
  }
230
237
  }
231
- async estimateMint(params) {
232
- const response = await getRunesApiClient(
233
- params.network
234
- ).estimateMintCost(params);
235
- if (response.data) {
236
- return {
237
- status: "success",
238
- result: response.data
239
- };
240
- }
241
- return {
242
- status: "error",
243
- error: {
244
- code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
245
- message: response.error.message
246
- }
247
- };
248
- }
249
- async estimateEtch(params) {
250
- const response = await getRunesApiClient(
251
- params.network
252
- ).estimateEtchCost(params);
253
- if (response.data) {
254
- return {
255
- status: "success",
256
- result: response.data
257
- };
258
- }
259
- return {
260
- status: "error",
261
- error: {
262
- code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
263
- message: response.error.message
264
- }
265
- };
266
- }
267
238
  async request(method, params) {
268
239
  switch (method) {
269
240
  case "runes_mint":
@@ -271,9 +242,13 @@ var SatsConnectAdapter = class {
271
242
  case "runes_etch":
272
243
  return this.etchRunes(params);
273
244
  case "runes_estimateMint":
274
- return this.estimateMint(params);
245
+ return new RunesApi(params.network).estimateMintCost(
246
+ params
247
+ );
275
248
  case "runes_estimateEtch":
276
- return this.estimateEtch(params);
249
+ return new RunesApi(params.network).estimateEtchCost(
250
+ params
251
+ );
277
252
  default:
278
253
  return this.requestInternal(method, params);
279
254
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sats-connect/core",
3
- "version": "0.0.3-9ea8b00",
3
+ "version": "0.0.3-b1484d5",
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",