@sats-connect/core 0.0.3-194d10e → 0.0.3-3e6a21d
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 +2 -0
- package/dist/index.mjs +139 -103
- package/package.json +2 -2
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__ */ ((
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return
|
|
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
|
|
@@ -31,19 +31,14 @@ var RunesApi = class {
|
|
|
31
31
|
...mintParams
|
|
32
32
|
});
|
|
33
33
|
return {
|
|
34
|
-
|
|
35
|
-
result: {
|
|
36
|
-
costBreakdown: response.data.costBreakdown,
|
|
37
|
-
totalCost: response.data.totalCost,
|
|
38
|
-
totalSize: response.data.totalSize
|
|
39
|
-
}
|
|
34
|
+
data: response.data
|
|
40
35
|
};
|
|
41
36
|
} catch (error) {
|
|
37
|
+
const err = error;
|
|
42
38
|
return {
|
|
43
|
-
status: "error",
|
|
44
39
|
error: {
|
|
45
|
-
code:
|
|
46
|
-
message: error.message
|
|
40
|
+
code: err.response?.status,
|
|
41
|
+
message: error.data.message
|
|
47
42
|
}
|
|
48
43
|
};
|
|
49
44
|
}
|
|
@@ -54,18 +49,13 @@ var RunesApi = class {
|
|
|
54
49
|
...etchParams
|
|
55
50
|
});
|
|
56
51
|
return {
|
|
57
|
-
|
|
58
|
-
result: {
|
|
59
|
-
costBreakdown: response.data.costBreakdown,
|
|
60
|
-
totalCost: response.data.totalCost,
|
|
61
|
-
totalSize: response.data.totalSize
|
|
62
|
-
}
|
|
52
|
+
data: response.data
|
|
63
53
|
};
|
|
64
54
|
} catch (error) {
|
|
55
|
+
const err = error;
|
|
65
56
|
return {
|
|
66
|
-
status: "error",
|
|
67
57
|
error: {
|
|
68
|
-
code:
|
|
58
|
+
code: err.response?.status,
|
|
69
59
|
message: error.data.message
|
|
70
60
|
}
|
|
71
61
|
};
|
|
@@ -80,8 +70,12 @@ var RunesApi = class {
|
|
|
80
70
|
data: response.data
|
|
81
71
|
};
|
|
82
72
|
} catch (error) {
|
|
73
|
+
const err = error;
|
|
83
74
|
return {
|
|
84
|
-
error:
|
|
75
|
+
error: {
|
|
76
|
+
code: err.response?.status,
|
|
77
|
+
message: error.data.message
|
|
78
|
+
}
|
|
85
79
|
};
|
|
86
80
|
}
|
|
87
81
|
};
|
|
@@ -94,8 +88,12 @@ var RunesApi = class {
|
|
|
94
88
|
data: response.data
|
|
95
89
|
};
|
|
96
90
|
} catch (error) {
|
|
91
|
+
const err = error;
|
|
97
92
|
return {
|
|
98
|
-
error:
|
|
93
|
+
error: {
|
|
94
|
+
code: err.response?.status,
|
|
95
|
+
message: error.data.message
|
|
96
|
+
}
|
|
99
97
|
};
|
|
100
98
|
}
|
|
101
99
|
};
|
|
@@ -108,8 +106,12 @@ var RunesApi = class {
|
|
|
108
106
|
data: response.data
|
|
109
107
|
};
|
|
110
108
|
} catch (error) {
|
|
109
|
+
const err = error;
|
|
111
110
|
return {
|
|
112
|
-
error:
|
|
111
|
+
error: {
|
|
112
|
+
code: err.response?.status,
|
|
113
|
+
message: error.data.message
|
|
114
|
+
}
|
|
113
115
|
};
|
|
114
116
|
}
|
|
115
117
|
};
|
|
@@ -122,57 +124,62 @@ var RunesApi = class {
|
|
|
122
124
|
data: response.data
|
|
123
125
|
};
|
|
124
126
|
} catch (error) {
|
|
127
|
+
const err = error;
|
|
125
128
|
return {
|
|
126
|
-
error:
|
|
129
|
+
error: {
|
|
130
|
+
code: err.response?.status,
|
|
131
|
+
message: error.data.message
|
|
132
|
+
}
|
|
127
133
|
};
|
|
128
134
|
}
|
|
129
135
|
};
|
|
130
136
|
};
|
|
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;
|
|
131
140
|
|
|
132
141
|
// src/adapters/satsConnectAdapter.ts
|
|
133
142
|
var SatsConnectAdapter = class {
|
|
134
143
|
async mintRunes(params) {
|
|
135
144
|
try {
|
|
136
145
|
const orderResponse = await new RunesApi(params.network).createMintOrder(params);
|
|
137
|
-
if (orderResponse.data) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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 {
|
|
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") {
|
|
168
164
|
return {
|
|
169
165
|
status: "error",
|
|
170
166
|
error: {
|
|
171
|
-
code: -
|
|
172
|
-
message:
|
|
167
|
+
code: -32e3 /* USER_REJECTION */,
|
|
168
|
+
message: "User rejected the payment request"
|
|
173
169
|
}
|
|
174
170
|
};
|
|
175
171
|
}
|
|
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
|
+
};
|
|
176
183
|
} catch (error) {
|
|
177
184
|
return {
|
|
178
185
|
status: "error",
|
|
@@ -186,45 +193,43 @@ var SatsConnectAdapter = class {
|
|
|
186
193
|
async etchRunes(params) {
|
|
187
194
|
try {
|
|
188
195
|
const orderResponse = await new RunesApi(params.network).createEtchOrder(params);
|
|
189
|
-
if (orderResponse.data) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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 {
|
|
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") {
|
|
220
214
|
return {
|
|
221
215
|
status: "error",
|
|
222
216
|
error: {
|
|
223
|
-
code: -
|
|
224
|
-
message:
|
|
217
|
+
code: -32e3 /* USER_REJECTION */,
|
|
218
|
+
message: "User rejected the payment request"
|
|
225
219
|
}
|
|
226
220
|
};
|
|
227
221
|
}
|
|
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
|
+
};
|
|
228
233
|
} catch (error) {
|
|
229
234
|
return {
|
|
230
235
|
status: "error",
|
|
@@ -235,6 +240,42 @@ var SatsConnectAdapter = class {
|
|
|
235
240
|
};
|
|
236
241
|
}
|
|
237
242
|
}
|
|
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
|
+
}
|
|
238
279
|
async request(method, params) {
|
|
239
280
|
switch (method) {
|
|
240
281
|
case "runes_mint":
|
|
@@ -242,13 +283,9 @@ var SatsConnectAdapter = class {
|
|
|
242
283
|
case "runes_etch":
|
|
243
284
|
return this.etchRunes(params);
|
|
244
285
|
case "runes_estimateMint":
|
|
245
|
-
return
|
|
246
|
-
params
|
|
247
|
-
);
|
|
286
|
+
return this.estimateMint(params);
|
|
248
287
|
case "runes_estimateEtch":
|
|
249
|
-
return
|
|
250
|
-
params
|
|
251
|
-
);
|
|
288
|
+
return this.estimateEtch(params);
|
|
252
289
|
default:
|
|
253
290
|
return this.requestInternal(method, params);
|
|
254
291
|
}
|
|
@@ -332,7 +369,6 @@ var isRpcSuccessResponse = (response) => {
|
|
|
332
369
|
var XverseAdapter = class extends SatsConnectAdapter {
|
|
333
370
|
id = DefaultAdaptersInfo.xverse.id;
|
|
334
371
|
requestInternal = async (method, params) => {
|
|
335
|
-
console.log("XverseAdapter requestInternal", method, params);
|
|
336
372
|
return request(method, params, this.id);
|
|
337
373
|
};
|
|
338
374
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sats-connect/core",
|
|
3
|
-
"version": "0.0.3-
|
|
3
|
+
"version": "0.0.3-3e6a21d",
|
|
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": "
|
|
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",
|