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

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,6 +672,8 @@ declare abstract class SatsConnectAdapter {
672
672
  abstract readonly id: string;
673
673
  private mintRunes;
674
674
  private etchRunes;
675
+ private estimateMint;
676
+ private estimateEtch;
675
677
  request<Method extends keyof Requests>(method: Method, params: Params<Method>): Promise<RpcResult<Method> | undefined>;
676
678
  protected abstract requestInternal<Method extends keyof Requests>(method: Method, params: Params<Method>): Promise<RpcResult<Method> | undefined>;
677
679
  }
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__ */ ((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;
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;
16
16
  })(RpcErrorCode || {});
17
17
 
18
18
  // src/runes/index.ts
@@ -25,26 +25,24 @@ 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
+ };
28
34
  estimateMintCost = async (mintParams) => {
29
35
  try {
30
36
  const response = await this.client.post("/mint/estimate", {
31
37
  ...mintParams
32
38
  });
33
39
  return {
34
- status: "success",
35
- result: {
36
- costBreakdown: response.data.costBreakdown,
37
- totalCost: response.data.totalCost,
38
- totalSize: response.data.totalSize
39
- }
40
+ data: response.data
40
41
  };
41
42
  } catch (error) {
43
+ const err = error;
42
44
  return {
43
- status: "error",
44
- error: {
45
- code: -32603 /* INTERNAL_ERROR */,
46
- message: error.message
47
- }
45
+ error: this.parseError(err)
48
46
  };
49
47
  }
50
48
  };
@@ -54,20 +52,12 @@ var RunesApi = class {
54
52
  ...etchParams
55
53
  });
56
54
  return {
57
- status: "success",
58
- result: {
59
- costBreakdown: response.data.costBreakdown,
60
- totalCost: response.data.totalCost,
61
- totalSize: response.data.totalSize
62
- }
55
+ data: response.data
63
56
  };
64
57
  } catch (error) {
58
+ const err = error;
65
59
  return {
66
- status: "error",
67
- error: {
68
- code: -32603 /* INTERNAL_ERROR */,
69
- message: error.data.message
70
- }
60
+ error: this.parseError(err)
71
61
  };
72
62
  }
73
63
  };
@@ -80,8 +70,9 @@ var RunesApi = class {
80
70
  data: response.data
81
71
  };
82
72
  } catch (error) {
73
+ const err = error;
83
74
  return {
84
- error: error.data.message
75
+ error: this.parseError(err)
85
76
  };
86
77
  }
87
78
  };
@@ -94,8 +85,9 @@ var RunesApi = class {
94
85
  data: response.data
95
86
  };
96
87
  } catch (error) {
88
+ const err = error;
97
89
  return {
98
- error: error.data.message
90
+ error: this.parseError(err)
99
91
  };
100
92
  }
101
93
  };
@@ -108,8 +100,9 @@ var RunesApi = class {
108
100
  data: response.data
109
101
  };
110
102
  } catch (error) {
103
+ const err = error;
111
104
  return {
112
- error: error.data.message
105
+ error: this.parseError(err)
113
106
  };
114
107
  }
115
108
  };
@@ -122,57 +115,68 @@ var RunesApi = class {
122
115
  data: response.data
123
116
  };
124
117
  } catch (error) {
118
+ const err = error;
125
119
  return {
126
- error: error.data.message
120
+ error: this.parseError(err)
127
121
  };
128
122
  }
129
123
  };
130
124
  };
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;
131
128
 
132
129
  // src/adapters/satsConnectAdapter.ts
133
130
  var SatsConnectAdapter = class {
134
131
  async mintRunes(params) {
135
132
  try {
136
- const orderResponse = await new RunesApi(params.network).createMintOrder(params);
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 {
133
+ const mintRequest = {
134
+ destinationAddress: params.destinationAddress,
135
+ feeRate: params.feeRate,
136
+ refundAddress: params.refundAddress,
137
+ repeats: params.repeats,
138
+ runeName: params.runeName,
139
+ appServiceFee: params.appServiceFee,
140
+ appServiceFeeAddress: params.appServiceFeeAddress
141
+ };
142
+ const orderResponse = await new RunesApi(params.network).createMintOrder(mintRequest);
143
+ if (!orderResponse.data) {
144
+ return {
145
+ status: "error",
146
+ error: {
147
+ code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
148
+ message: orderResponse.error.message
149
+ }
150
+ };
151
+ }
152
+ const paymentResponse = await this.requestInternal("sendTransfer", {
153
+ recipients: [
154
+ {
155
+ address: orderResponse.data.fundAddress,
156
+ amount: orderResponse.data.fundAmount
157
+ }
158
+ ]
159
+ });
160
+ if (paymentResponse?.status !== "success") {
168
161
  return {
169
162
  status: "error",
170
163
  error: {
171
- code: -32603 /* INTERNAL_ERROR */,
172
- message: orderResponse.error
164
+ code: -32e3 /* USER_REJECTION */,
165
+ message: "User rejected the payment request"
173
166
  }
174
167
  };
175
168
  }
169
+ await new RunesApi(params.network).executeMint(
170
+ orderResponse.data.orderId,
171
+ paymentResponse.result.txid
172
+ );
173
+ return {
174
+ status: "success",
175
+ result: {
176
+ orderId: orderResponse.data.orderId,
177
+ fundTransactionId: paymentResponse.result.txid
178
+ }
179
+ };
176
180
  } catch (error) {
177
181
  return {
178
182
  status: "error",
@@ -184,47 +188,60 @@ var SatsConnectAdapter = class {
184
188
  }
185
189
  }
186
190
  async etchRunes(params) {
191
+ const etchRequest = {
192
+ destinationAddress: params.destinationAddress,
193
+ refundAddress: params.refundAddress,
194
+ feeRate: params.feeRate,
195
+ runeName: params.runeName,
196
+ divisibility: params.divisibility,
197
+ symbol: params.symbol,
198
+ premine: params.premine,
199
+ isMintable: params.isMintable,
200
+ terms: params.terms,
201
+ inscriptionDetails: params.inscriptionDetails,
202
+ delegateInscriptionId: params.delegateInscriptionId,
203
+ appServiceFee: params.appServiceFee,
204
+ appServiceFeeAddress: params.appServiceFeeAddress
205
+ };
187
206
  try {
188
- const orderResponse = await new RunesApi(params.network).createEtchOrder(params);
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 {
207
+ const orderResponse = await new RunesApi(params.network).createEtchOrder(etchRequest);
208
+ if (!orderResponse.data) {
220
209
  return {
221
210
  status: "error",
222
211
  error: {
223
- code: -32603 /* INTERNAL_ERROR */,
224
- message: orderResponse.error
212
+ code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
213
+ message: orderResponse.error.message
225
214
  }
226
215
  };
227
216
  }
217
+ const paymentResponse = await this.requestInternal("sendTransfer", {
218
+ recipients: [
219
+ {
220
+ address: orderResponse.data.fundAddress,
221
+ amount: orderResponse.data.fundAmount
222
+ }
223
+ ]
224
+ });
225
+ if (paymentResponse?.status !== "success") {
226
+ return {
227
+ status: "error",
228
+ error: {
229
+ code: -32e3 /* USER_REJECTION */,
230
+ message: "User rejected the payment request"
231
+ }
232
+ };
233
+ }
234
+ await new RunesApi(params.network).executeEtch(
235
+ orderResponse.data.orderId,
236
+ paymentResponse.result.txid
237
+ );
238
+ return {
239
+ status: "success",
240
+ result: {
241
+ orderId: orderResponse.data.orderId,
242
+ fundTransactionId: paymentResponse.result.txid
243
+ }
244
+ };
228
245
  } catch (error) {
229
246
  return {
230
247
  status: "error",
@@ -235,6 +252,62 @@ var SatsConnectAdapter = class {
235
252
  };
236
253
  }
237
254
  }
255
+ async estimateMint(params) {
256
+ const estimateMintRequest = {
257
+ destinationAddress: params.destinationAddress,
258
+ feeRate: params.feeRate,
259
+ repeats: params.repeats,
260
+ runeName: params.runeName,
261
+ appServiceFee: params.appServiceFee,
262
+ appServiceFeeAddress: params.appServiceFeeAddress
263
+ };
264
+ const response = await getRunesApiClient(
265
+ params.network
266
+ ).estimateMintCost(estimateMintRequest);
267
+ if (response.data) {
268
+ return {
269
+ status: "success",
270
+ result: response.data
271
+ };
272
+ }
273
+ return {
274
+ status: "error",
275
+ error: {
276
+ code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
277
+ message: response.error.message
278
+ }
279
+ };
280
+ }
281
+ async estimateEtch(params) {
282
+ const estimateEtchRequest = {
283
+ destinationAddress: params.destinationAddress,
284
+ feeRate: params.feeRate,
285
+ runeName: params.runeName,
286
+ divisibility: params.divisibility,
287
+ symbol: params.symbol,
288
+ premine: params.premine,
289
+ isMintable: params.isMintable,
290
+ terms: params.terms,
291
+ inscriptionDetails: params.inscriptionDetails,
292
+ delegateInscriptionId: params.delegateInscriptionId,
293
+ appServiceFee: params.appServiceFee,
294
+ appServiceFeeAddress: params.appServiceFeeAddress
295
+ };
296
+ const response = await getRunesApiClient(params.network).estimateEtchCost(estimateEtchRequest);
297
+ if (response.data) {
298
+ return {
299
+ status: "success",
300
+ result: response.data
301
+ };
302
+ }
303
+ return {
304
+ status: "error",
305
+ error: {
306
+ code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
307
+ message: response.error.message
308
+ }
309
+ };
310
+ }
238
311
  async request(method, params) {
239
312
  switch (method) {
240
313
  case "runes_mint":
@@ -242,13 +315,9 @@ var SatsConnectAdapter = class {
242
315
  case "runes_etch":
243
316
  return this.etchRunes(params);
244
317
  case "runes_estimateMint":
245
- return new RunesApi(params.network).estimateMintCost(
246
- params
247
- );
318
+ return this.estimateMint(params);
248
319
  case "runes_estimateEtch":
249
- return new RunesApi(params.network).estimateEtchCost(
250
- params
251
- );
320
+ return this.estimateEtch(params);
252
321
  default:
253
322
  return this.requestInternal(method, params);
254
323
  }
@@ -332,7 +401,6 @@ var isRpcSuccessResponse = (response) => {
332
401
  var XverseAdapter = class extends SatsConnectAdapter {
333
402
  id = DefaultAdaptersInfo.xverse.id;
334
403
  requestInternal = async (method, params) => {
335
- console.log("XverseAdapter requestInternal", method, params);
336
404
  return request(method, params, this.id);
337
405
  };
338
406
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sats-connect/core",
3
- "version": "0.0.3-e7448df",
3
+ "version": "0.0.3-f7e8b0c",
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",