@sats-connect/core 0.1.2 → 0.2.0
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 +52 -1
- package/dist/index.mjs +793 -725
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,24 +1,84 @@
|
|
|
1
|
-
// src/
|
|
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 =
|
|
10
|
-
var rpcRequestMessageSchema =
|
|
11
|
-
jsonrpc:
|
|
12
|
-
method:
|
|
13
|
-
params:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
81
|
+
v2.null()
|
|
22
82
|
])
|
|
23
83
|
),
|
|
24
84
|
id: RpcIdSchema
|
|
@@ -34,687 +94,181 @@ var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
|
|
|
34
94
|
RpcErrorCode2[RpcErrorCode2["ACCESS_DENIED"] = -32002] = "ACCESS_DENIED";
|
|
35
95
|
return RpcErrorCode2;
|
|
36
96
|
})(RpcErrorCode || {});
|
|
37
|
-
var rpcSuccessResponseMessageSchema =
|
|
38
|
-
jsonrpc:
|
|
39
|
-
result:
|
|
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 =
|
|
43
|
-
jsonrpc:
|
|
44
|
-
error:
|
|
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 =
|
|
107
|
+
var rpcResponseMessageSchema = v2.union([
|
|
48
108
|
rpcSuccessResponseMessageSchema,
|
|
49
109
|
rpcErrorResponseMessageSchema
|
|
50
110
|
]);
|
|
51
111
|
|
|
52
|
-
// src/
|
|
53
|
-
import
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
var
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
|
160
|
+
import * as v4 from "valibot";
|
|
607
161
|
var stxGetAddressesMethodName = "stx_getAddresses";
|
|
608
|
-
var stxGetAddressesParamsSchema =
|
|
609
|
-
|
|
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:
|
|
167
|
+
message: v4.optional(v4.string())
|
|
614
168
|
})
|
|
615
169
|
);
|
|
616
|
-
var stxGetAddressesResultSchema =
|
|
170
|
+
var stxGetAddressesResultSchema = v4.object({
|
|
617
171
|
/**
|
|
618
172
|
* The addresses generated for the given purposes.
|
|
619
173
|
*/
|
|
620
|
-
addresses:
|
|
174
|
+
addresses: v4.array(addressSchema)
|
|
621
175
|
});
|
|
622
|
-
var stxGetAddressesRequestMessageSchema =
|
|
176
|
+
var stxGetAddressesRequestMessageSchema = v4.object({
|
|
623
177
|
...rpcRequestMessageSchema.entries,
|
|
624
|
-
...
|
|
625
|
-
method:
|
|
178
|
+
...v4.object({
|
|
179
|
+
method: v4.literal(stxGetAddressesMethodName),
|
|
626
180
|
params: stxGetAddressesParamsSchema,
|
|
627
|
-
id:
|
|
181
|
+
id: v4.string()
|
|
628
182
|
}).entries
|
|
629
183
|
});
|
|
630
184
|
var stxSignTransactionMethodName = "stx_signTransaction";
|
|
631
|
-
var stxSignTransactionParamsSchema =
|
|
185
|
+
var stxSignTransactionParamsSchema = v4.object({
|
|
632
186
|
/**
|
|
633
187
|
* The transaction to sign as a hex-encoded string.
|
|
634
188
|
*/
|
|
635
|
-
transaction:
|
|
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:
|
|
194
|
+
pubkey: v4.optional(v4.string()),
|
|
641
195
|
/**
|
|
642
196
|
* Whether to broadcast the transaction after signing. Defaults to `true`.
|
|
643
197
|
*/
|
|
644
|
-
broadcast:
|
|
198
|
+
broadcast: v4.optional(v4.boolean())
|
|
645
199
|
});
|
|
646
|
-
var stxSignTransactionResultSchema =
|
|
200
|
+
var stxSignTransactionResultSchema = v4.object({
|
|
647
201
|
/**
|
|
648
202
|
* The signed transaction as a hex-encoded string.
|
|
649
203
|
*/
|
|
650
|
-
transaction:
|
|
204
|
+
transaction: v4.string()
|
|
651
205
|
});
|
|
652
|
-
var stxSignTransactionRequestMessageSchema =
|
|
206
|
+
var stxSignTransactionRequestMessageSchema = v4.object({
|
|
653
207
|
...rpcRequestMessageSchema.entries,
|
|
654
|
-
...
|
|
655
|
-
method:
|
|
208
|
+
...v4.object({
|
|
209
|
+
method: v4.literal(stxSignTransactionMethodName),
|
|
656
210
|
params: stxSignTransactionParamsSchema,
|
|
657
|
-
id:
|
|
211
|
+
id: v4.string()
|
|
658
212
|
}).entries
|
|
659
213
|
});
|
|
660
214
|
|
|
661
215
|
// src/request/types/btcMethods.ts
|
|
662
|
-
import * as
|
|
216
|
+
import * as v6 from "valibot";
|
|
663
217
|
|
|
664
218
|
// src/request/types/common.ts
|
|
665
|
-
import * as
|
|
219
|
+
import * as v5 from "valibot";
|
|
666
220
|
var walletTypes = ["software", "ledger"];
|
|
667
|
-
var walletTypeSchema =
|
|
221
|
+
var walletTypeSchema = v5.picklist(walletTypes);
|
|
668
222
|
|
|
669
223
|
// src/request/types/btcMethods.ts
|
|
670
224
|
var getInfoMethodName = "getInfo";
|
|
671
|
-
var getInfoParamsSchema =
|
|
672
|
-
var getInfoResultSchema =
|
|
225
|
+
var getInfoParamsSchema = v6.nullish(v6.null());
|
|
226
|
+
var getInfoResultSchema = v6.object({
|
|
673
227
|
/**
|
|
674
228
|
* Version of the wallet.
|
|
675
229
|
*/
|
|
676
|
-
version:
|
|
230
|
+
version: v6.string(),
|
|
677
231
|
/**
|
|
678
232
|
* [WBIP](https://wbips.netlify.app/wbips/WBIP002) methods supported by the wallet.
|
|
679
233
|
*/
|
|
680
|
-
methods:
|
|
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:
|
|
238
|
+
supports: v6.array(v6.string())
|
|
685
239
|
});
|
|
686
|
-
var getInfoRequestMessageSchema =
|
|
240
|
+
var getInfoRequestMessageSchema = v6.object({
|
|
687
241
|
...rpcRequestMessageSchema.entries,
|
|
688
|
-
...
|
|
689
|
-
method:
|
|
242
|
+
...v6.object({
|
|
243
|
+
method: v6.literal(getInfoMethodName),
|
|
690
244
|
params: getInfoParamsSchema,
|
|
691
|
-
id:
|
|
245
|
+
id: v6.string()
|
|
692
246
|
}).entries
|
|
693
247
|
});
|
|
694
248
|
var getAddressesMethodName = "getAddresses";
|
|
695
|
-
var getAddressesParamsSchema =
|
|
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:
|
|
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:
|
|
258
|
+
message: v6.optional(v6.string())
|
|
705
259
|
});
|
|
706
|
-
var getAddressesResultSchema =
|
|
260
|
+
var getAddressesResultSchema = v6.object({
|
|
707
261
|
/**
|
|
708
262
|
* The addresses generated for the given purposes.
|
|
709
263
|
*/
|
|
710
|
-
addresses:
|
|
264
|
+
addresses: v6.array(addressSchema)
|
|
711
265
|
});
|
|
712
|
-
var getAddressesRequestMessageSchema =
|
|
266
|
+
var getAddressesRequestMessageSchema = v6.object({
|
|
713
267
|
...rpcRequestMessageSchema.entries,
|
|
714
|
-
...
|
|
715
|
-
method:
|
|
268
|
+
...v6.object({
|
|
269
|
+
method: v6.literal(getAddressesMethodName),
|
|
716
270
|
params: getAddressesParamsSchema,
|
|
717
|
-
id:
|
|
271
|
+
id: v6.string()
|
|
718
272
|
}).entries
|
|
719
273
|
});
|
|
720
274
|
var signMessageMethodName = "signMessage";
|
|
@@ -723,216 +277,237 @@ var MessageSigningProtocols = /* @__PURE__ */ ((MessageSigningProtocols2) => {
|
|
|
723
277
|
MessageSigningProtocols2["BIP322"] = "BIP322";
|
|
724
278
|
return MessageSigningProtocols2;
|
|
725
279
|
})(MessageSigningProtocols || {});
|
|
726
|
-
var signMessageParamsSchema =
|
|
280
|
+
var signMessageParamsSchema = v6.object({
|
|
727
281
|
/**
|
|
728
282
|
* The address used for signing.
|
|
729
283
|
**/
|
|
730
|
-
address:
|
|
284
|
+
address: v6.string(),
|
|
731
285
|
/**
|
|
732
286
|
* The message to sign.
|
|
733
287
|
**/
|
|
734
|
-
message:
|
|
288
|
+
message: v6.string(),
|
|
735
289
|
/**
|
|
736
290
|
* The protocol to use for signing the message.
|
|
737
291
|
*/
|
|
738
|
-
protocol:
|
|
292
|
+
protocol: v6.optional(v6.enum(MessageSigningProtocols))
|
|
739
293
|
});
|
|
740
|
-
var signMessageResultSchema =
|
|
294
|
+
var signMessageResultSchema = v6.object({
|
|
741
295
|
/**
|
|
742
296
|
* The signature of the message.
|
|
743
297
|
*/
|
|
744
|
-
signature:
|
|
298
|
+
signature: v6.string(),
|
|
745
299
|
/**
|
|
746
300
|
* hash of the message.
|
|
747
301
|
*/
|
|
748
|
-
messageHash:
|
|
302
|
+
messageHash: v6.string(),
|
|
749
303
|
/**
|
|
750
304
|
* The address used for signing.
|
|
751
305
|
*/
|
|
752
|
-
address:
|
|
306
|
+
address: v6.string(),
|
|
753
307
|
/**
|
|
754
308
|
* The protocol to use for signing the message.
|
|
755
309
|
*/
|
|
756
|
-
protocol:
|
|
310
|
+
protocol: v6.enum(MessageSigningProtocols)
|
|
757
311
|
});
|
|
758
|
-
var signMessageRequestMessageSchema =
|
|
312
|
+
var signMessageRequestMessageSchema = v6.object({
|
|
759
313
|
...rpcRequestMessageSchema.entries,
|
|
760
|
-
...
|
|
761
|
-
method:
|
|
314
|
+
...v6.object({
|
|
315
|
+
method: v6.literal(signMessageMethodName),
|
|
762
316
|
params: signMessageParamsSchema,
|
|
763
|
-
id:
|
|
317
|
+
id: v6.string()
|
|
764
318
|
}).entries
|
|
765
319
|
});
|
|
766
320
|
var getAccountsMethodName = "getAccounts";
|
|
767
|
-
var getAccountsParamsSchema =
|
|
321
|
+
var getAccountsParamsSchema = v6.object({
|
|
768
322
|
/**
|
|
769
323
|
* The purposes for which to generate addresses. See
|
|
770
324
|
* {@linkcode AddressPurpose} for available purposes.
|
|
771
325
|
*/
|
|
772
|
-
purposes:
|
|
326
|
+
purposes: v6.array(v6.enum(AddressPurpose)),
|
|
773
327
|
/**
|
|
774
328
|
* A message to be displayed to the user in the request prompt.
|
|
775
329
|
*/
|
|
776
|
-
message:
|
|
330
|
+
message: v6.optional(v6.string())
|
|
777
331
|
});
|
|
778
|
-
var getAccountsResultSchema =
|
|
779
|
-
|
|
332
|
+
var getAccountsResultSchema = v6.array(
|
|
333
|
+
v6.object({
|
|
780
334
|
...addressSchema.entries,
|
|
781
|
-
...
|
|
335
|
+
...v6.object({
|
|
782
336
|
walletType: walletTypeSchema
|
|
783
337
|
}).entries
|
|
784
338
|
})
|
|
785
339
|
);
|
|
786
|
-
var getAccountsRequestMessageSchema =
|
|
340
|
+
var getAccountsRequestMessageSchema = v6.object({
|
|
787
341
|
...rpcRequestMessageSchema.entries,
|
|
788
|
-
...
|
|
789
|
-
method:
|
|
342
|
+
...v6.object({
|
|
343
|
+
method: v6.literal(getAccountsMethodName),
|
|
790
344
|
params: getAccountsParamsSchema,
|
|
791
|
-
id:
|
|
345
|
+
id: v6.string()
|
|
792
346
|
}).entries
|
|
793
347
|
});
|
|
794
348
|
var getBalanceMethodName = "getBalance";
|
|
795
|
-
var getBalanceParamsSchema =
|
|
796
|
-
var getBalanceResultSchema =
|
|
349
|
+
var getBalanceParamsSchema = v6.nullish(v6.null());
|
|
350
|
+
var getBalanceResultSchema = v6.object({
|
|
797
351
|
/**
|
|
798
352
|
* The confirmed balance of the wallet in sats. Using a string due to chrome
|
|
799
353
|
* messages not supporting bigint
|
|
800
354
|
* (https://issues.chromium.org/issues/40116184).
|
|
801
355
|
*/
|
|
802
|
-
confirmed:
|
|
356
|
+
confirmed: v6.string(),
|
|
803
357
|
/**
|
|
804
358
|
* The unconfirmed balance of the wallet in sats. Using a string due to chrome
|
|
805
359
|
* messages not supporting bigint
|
|
806
360
|
* (https://issues.chromium.org/issues/40116184).
|
|
807
361
|
*/
|
|
808
|
-
unconfirmed:
|
|
362
|
+
unconfirmed: v6.string(),
|
|
809
363
|
/**
|
|
810
364
|
* The total balance (both confirmed and unconfrimed UTXOs) of the wallet in
|
|
811
365
|
* sats. Using a string due to chrome messages not supporting bigint
|
|
812
366
|
* (https://issues.chromium.org/issues/40116184).
|
|
813
367
|
*/
|
|
814
|
-
total:
|
|
368
|
+
total: v6.string()
|
|
815
369
|
});
|
|
816
|
-
var getBalanceRequestMessageSchema =
|
|
370
|
+
var getBalanceRequestMessageSchema = v6.object({
|
|
817
371
|
...rpcRequestMessageSchema.entries,
|
|
818
|
-
...
|
|
819
|
-
method:
|
|
820
|
-
id:
|
|
372
|
+
...v6.object({
|
|
373
|
+
method: v6.literal(getBalanceMethodName),
|
|
374
|
+
id: v6.string()
|
|
821
375
|
}).entries
|
|
822
376
|
});
|
|
823
377
|
|
|
824
378
|
// src/request/types/walletMethods.ts
|
|
825
|
-
import * as
|
|
379
|
+
import * as v7 from "valibot";
|
|
826
380
|
var requestPermissionsMethodName = "wallet_requestPermissions";
|
|
827
|
-
var requestPermissionsParamsSchema =
|
|
828
|
-
var requestPermissionsResultSchema =
|
|
829
|
-
var requestPermissionsRequestMessageSchema =
|
|
381
|
+
var requestPermissionsParamsSchema = v7.undefined();
|
|
382
|
+
var requestPermissionsResultSchema = v7.literal(true);
|
|
383
|
+
var requestPermissionsRequestMessageSchema = v7.object({
|
|
830
384
|
...rpcRequestMessageSchema.entries,
|
|
831
|
-
...
|
|
832
|
-
method:
|
|
385
|
+
...v7.object({
|
|
386
|
+
method: v7.literal(requestPermissionsMethodName),
|
|
833
387
|
params: requestPermissionsParamsSchema,
|
|
834
|
-
id:
|
|
388
|
+
id: v7.string()
|
|
835
389
|
}).entries
|
|
836
390
|
});
|
|
837
391
|
var renouncePermissionsMethodName = "wallet_renouncePermissions";
|
|
838
|
-
var renouncePermissionsParamsSchema =
|
|
839
|
-
var renouncePermissionsResultSchema =
|
|
840
|
-
var renouncePermissionsRequestMessageSchema =
|
|
392
|
+
var renouncePermissionsParamsSchema = v7.undefined();
|
|
393
|
+
var renouncePermissionsResultSchema = v7.literal(true);
|
|
394
|
+
var renouncePermissionsRequestMessageSchema = v7.object({
|
|
841
395
|
...rpcRequestMessageSchema.entries,
|
|
842
|
-
...
|
|
843
|
-
method:
|
|
396
|
+
...v7.object({
|
|
397
|
+
method: v7.literal(renouncePermissionsMethodName),
|
|
844
398
|
params: renouncePermissionsParamsSchema,
|
|
845
|
-
id:
|
|
399
|
+
id: v7.string()
|
|
846
400
|
}).entries
|
|
847
401
|
});
|
|
848
402
|
var getWalletTypeMethodName = "wallet_getWalletType";
|
|
849
|
-
var getWalletTypeParamsSchema =
|
|
403
|
+
var getWalletTypeParamsSchema = v7.nullish(v7.null());
|
|
850
404
|
var getWalletTypeResultSchema = walletTypeSchema;
|
|
851
|
-
var getWalletTypeRequestMessageSchema =
|
|
405
|
+
var getWalletTypeRequestMessageSchema = v7.object({
|
|
852
406
|
...rpcRequestMessageSchema.entries,
|
|
853
|
-
...
|
|
854
|
-
method:
|
|
855
|
-
id:
|
|
407
|
+
...v7.object({
|
|
408
|
+
method: v7.literal(getWalletTypeMethodName),
|
|
409
|
+
id: v7.string()
|
|
856
410
|
}).entries
|
|
857
411
|
});
|
|
858
412
|
|
|
859
413
|
// src/request/types/runesMethods.ts
|
|
860
|
-
import * as
|
|
414
|
+
import * as v8 from "valibot";
|
|
861
415
|
var getRunesBalanceMethodName = "runes_getBalance";
|
|
862
|
-
var getRunesBalanceParamsSchema =
|
|
863
|
-
var getRunesBalanceResultSchema =
|
|
864
|
-
balances:
|
|
865
|
-
|
|
866
|
-
runeName:
|
|
867
|
-
amount:
|
|
868
|
-
divisibility:
|
|
869
|
-
symbol:
|
|
870
|
-
inscriptionId:
|
|
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())
|
|
871
425
|
})
|
|
872
426
|
)
|
|
873
427
|
});
|
|
874
|
-
var getRunesBalanceRequestMessageSchema =
|
|
428
|
+
var getRunesBalanceRequestMessageSchema = v8.object({
|
|
875
429
|
...rpcRequestMessageSchema.entries,
|
|
876
|
-
...
|
|
877
|
-
method:
|
|
430
|
+
...v8.object({
|
|
431
|
+
method: v8.literal(getRunesBalanceMethodName),
|
|
878
432
|
params: getRunesBalanceParamsSchema,
|
|
879
|
-
id:
|
|
433
|
+
id: v8.string()
|
|
434
|
+
}).entries
|
|
435
|
+
});
|
|
436
|
+
var transferRunesMethodName = "runes_transfer";
|
|
437
|
+
var transferRunesParamsSchema = v8.object({
|
|
438
|
+
recipients: v8.array(
|
|
439
|
+
v8.object({
|
|
440
|
+
runeName: v8.string(),
|
|
441
|
+
amount: v8.string(),
|
|
442
|
+
address: v8.string()
|
|
443
|
+
})
|
|
444
|
+
)
|
|
445
|
+
});
|
|
446
|
+
var transferRunesRequestSchema = v8.object({
|
|
447
|
+
...rpcRequestMessageSchema.entries,
|
|
448
|
+
...v8.object({
|
|
449
|
+
method: v8.literal(transferRunesMethodName),
|
|
450
|
+
params: transferRunesParamsSchema,
|
|
451
|
+
id: v8.string()
|
|
880
452
|
}).entries
|
|
881
453
|
});
|
|
454
|
+
var TransferRunesResultSchema = v8.object({
|
|
455
|
+
txid: v8.string()
|
|
456
|
+
});
|
|
882
457
|
|
|
883
458
|
// src/request/types/ordinalsMethods.ts
|
|
884
|
-
import * as
|
|
459
|
+
import * as v9 from "valibot";
|
|
885
460
|
var getInscriptionsMethodName = "ord_getInscriptions";
|
|
886
|
-
var getInscriptionsParamsSchema =
|
|
887
|
-
offset:
|
|
888
|
-
limit:
|
|
461
|
+
var getInscriptionsParamsSchema = v9.object({
|
|
462
|
+
offset: v9.number(),
|
|
463
|
+
limit: v9.number()
|
|
889
464
|
});
|
|
890
|
-
var getInscriptionsResultSchema =
|
|
891
|
-
total:
|
|
892
|
-
limit:
|
|
893
|
-
offset:
|
|
894
|
-
inscriptions:
|
|
895
|
-
|
|
896
|
-
inscriptionId:
|
|
897
|
-
inscriptionNumber:
|
|
898
|
-
address:
|
|
899
|
-
collectionName:
|
|
900
|
-
postage:
|
|
901
|
-
contentLength:
|
|
902
|
-
contentType:
|
|
903
|
-
timestamp:
|
|
904
|
-
offset:
|
|
905
|
-
genesisTransaction:
|
|
906
|
-
output:
|
|
465
|
+
var getInscriptionsResultSchema = v9.object({
|
|
466
|
+
total: v9.number(),
|
|
467
|
+
limit: v9.number(),
|
|
468
|
+
offset: v9.number(),
|
|
469
|
+
inscriptions: v9.array(
|
|
470
|
+
v9.object({
|
|
471
|
+
inscriptionId: v9.string(),
|
|
472
|
+
inscriptionNumber: v9.string(),
|
|
473
|
+
address: v9.string(),
|
|
474
|
+
collectionName: v9.optional(v9.string()),
|
|
475
|
+
postage: v9.string(),
|
|
476
|
+
contentLength: v9.string(),
|
|
477
|
+
contentType: v9.string(),
|
|
478
|
+
timestamp: v9.number(),
|
|
479
|
+
offset: v9.number(),
|
|
480
|
+
genesisTransaction: v9.string(),
|
|
481
|
+
output: v9.string()
|
|
907
482
|
})
|
|
908
483
|
)
|
|
909
484
|
});
|
|
910
|
-
var getInscriptionsSchema =
|
|
485
|
+
var getInscriptionsSchema = v9.object({
|
|
911
486
|
...rpcRequestMessageSchema.entries,
|
|
912
|
-
...
|
|
913
|
-
method:
|
|
487
|
+
...v9.object({
|
|
488
|
+
method: v9.literal(getInscriptionsMethodName),
|
|
914
489
|
params: getInscriptionsParamsSchema,
|
|
915
|
-
id:
|
|
490
|
+
id: v9.string()
|
|
916
491
|
}).entries
|
|
917
492
|
});
|
|
918
493
|
var sendInscriptionsMethodName = "ord_sendInscriptions";
|
|
919
|
-
var sendInscriptionsParamsSchema =
|
|
920
|
-
transfers:
|
|
921
|
-
|
|
922
|
-
address:
|
|
923
|
-
inscriptionId:
|
|
494
|
+
var sendInscriptionsParamsSchema = v9.object({
|
|
495
|
+
transfers: v9.array(
|
|
496
|
+
v9.object({
|
|
497
|
+
address: v9.string(),
|
|
498
|
+
inscriptionId: v9.string()
|
|
924
499
|
})
|
|
925
500
|
)
|
|
926
501
|
});
|
|
927
|
-
var sendInscriptionsResultSchema =
|
|
928
|
-
txid:
|
|
502
|
+
var sendInscriptionsResultSchema = v9.object({
|
|
503
|
+
txid: v9.string()
|
|
929
504
|
});
|
|
930
|
-
var sendInscriptionsSchema =
|
|
505
|
+
var sendInscriptionsSchema = v9.object({
|
|
931
506
|
...rpcRequestMessageSchema.entries,
|
|
932
|
-
...
|
|
933
|
-
method:
|
|
507
|
+
...v9.object({
|
|
508
|
+
method: v9.literal(sendInscriptionsMethodName),
|
|
934
509
|
params: sendInscriptionsParamsSchema,
|
|
935
|
-
id:
|
|
510
|
+
id: v9.string()
|
|
936
511
|
}).entries
|
|
937
512
|
});
|
|
938
513
|
|
|
@@ -942,33 +517,503 @@ var request = async (method, params, providerId) => {
|
|
|
942
517
|
if (providerId) {
|
|
943
518
|
provider = await getProviderById(providerId);
|
|
944
519
|
}
|
|
945
|
-
if (!provider) {
|
|
946
|
-
throw new Error("no wallet provider was found");
|
|
520
|
+
if (!provider) {
|
|
521
|
+
throw new Error("no wallet provider was found");
|
|
522
|
+
}
|
|
523
|
+
if (!method) {
|
|
524
|
+
throw new Error("A wallet method is required");
|
|
525
|
+
}
|
|
526
|
+
const response = await provider.request(method, params);
|
|
527
|
+
if (v10.is(rpcErrorResponseMessageSchema, response)) {
|
|
528
|
+
return {
|
|
529
|
+
status: "error",
|
|
530
|
+
error: response.error
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
if (v10.is(rpcSuccessResponseMessageSchema, response)) {
|
|
534
|
+
return {
|
|
535
|
+
status: "success",
|
|
536
|
+
result: response.result
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
return {
|
|
540
|
+
status: "error",
|
|
541
|
+
error: {
|
|
542
|
+
code: -32603 /* INTERNAL_ERROR */,
|
|
543
|
+
message: "Received unknown response from provider.",
|
|
544
|
+
data: response
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
};
|
|
548
|
+
var addListener = (event, cb, providerId) => {
|
|
549
|
+
let provider = window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
|
|
550
|
+
if (providerId) {
|
|
551
|
+
provider = getProviderById(providerId);
|
|
552
|
+
}
|
|
553
|
+
if (!provider) {
|
|
554
|
+
throw new Error("no wallet provider was found");
|
|
555
|
+
}
|
|
556
|
+
return provider.addListener(event, cb);
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
// src/runes/api.ts
|
|
560
|
+
import axios from "axios";
|
|
561
|
+
var urlNetworkSuffix = {
|
|
562
|
+
["Mainnet" /* Mainnet */]: "",
|
|
563
|
+
["Testnet" /* Testnet */]: "-testnet",
|
|
564
|
+
["Signet" /* Signet */]: "-signet"
|
|
565
|
+
};
|
|
566
|
+
var ORDINALS_API_BASE_URL = (network = "Mainnet" /* Mainnet */) => `https://ordinals${urlNetworkSuffix[network]}.xverse.app/v1`;
|
|
567
|
+
var RunesApi = class {
|
|
568
|
+
client;
|
|
569
|
+
constructor(network) {
|
|
570
|
+
this.client = axios.create({
|
|
571
|
+
baseURL: ORDINALS_API_BASE_URL(network)
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
parseError = (error) => {
|
|
575
|
+
return {
|
|
576
|
+
code: error.response?.status,
|
|
577
|
+
message: JSON.stringify(error.response?.data)
|
|
578
|
+
};
|
|
579
|
+
};
|
|
580
|
+
estimateMintCost = async (mintParams) => {
|
|
581
|
+
try {
|
|
582
|
+
const response = await this.client.post("/runes/mint/estimate", {
|
|
583
|
+
...mintParams
|
|
584
|
+
});
|
|
585
|
+
return {
|
|
586
|
+
data: response.data
|
|
587
|
+
};
|
|
588
|
+
} catch (error) {
|
|
589
|
+
const err = error;
|
|
590
|
+
return {
|
|
591
|
+
error: this.parseError(err)
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
estimateEtchCost = async (etchParams) => {
|
|
596
|
+
try {
|
|
597
|
+
const response = await this.client.post("/runes/etch/estimate", {
|
|
598
|
+
...etchParams
|
|
599
|
+
});
|
|
600
|
+
return {
|
|
601
|
+
data: response.data
|
|
602
|
+
};
|
|
603
|
+
} catch (error) {
|
|
604
|
+
const err = error;
|
|
605
|
+
return {
|
|
606
|
+
error: this.parseError(err)
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
createMintOrder = async (mintOrderParams) => {
|
|
611
|
+
try {
|
|
612
|
+
const response = await this.client.post("/runes/mint/orders", {
|
|
613
|
+
...mintOrderParams
|
|
614
|
+
});
|
|
615
|
+
return {
|
|
616
|
+
data: response.data
|
|
617
|
+
};
|
|
618
|
+
} catch (error) {
|
|
619
|
+
const err = error;
|
|
620
|
+
return {
|
|
621
|
+
error: this.parseError(err)
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
createEtchOrder = async (etchOrderParams) => {
|
|
626
|
+
try {
|
|
627
|
+
const response = await this.client.post("/runes/etch/orders", {
|
|
628
|
+
...etchOrderParams
|
|
629
|
+
});
|
|
630
|
+
return {
|
|
631
|
+
data: response.data
|
|
632
|
+
};
|
|
633
|
+
} catch (error) {
|
|
634
|
+
const err = error;
|
|
635
|
+
return {
|
|
636
|
+
error: this.parseError(err)
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
executeMint = async (orderId, fundTransactionId) => {
|
|
641
|
+
try {
|
|
642
|
+
const response = await this.client.post(`/runes/mint/orders/${orderId}/execute`, {
|
|
643
|
+
fundTransactionId
|
|
644
|
+
});
|
|
645
|
+
return {
|
|
646
|
+
data: response.data
|
|
647
|
+
};
|
|
648
|
+
} catch (error) {
|
|
649
|
+
const err = error;
|
|
650
|
+
return {
|
|
651
|
+
error: this.parseError(err)
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
executeEtch = async (orderId, fundTransactionId) => {
|
|
656
|
+
try {
|
|
657
|
+
const response = await this.client.post(`/runes/etch/orders/${orderId}/execute`, {
|
|
658
|
+
fundTransactionId
|
|
659
|
+
});
|
|
660
|
+
return {
|
|
661
|
+
data: response.data
|
|
662
|
+
};
|
|
663
|
+
} catch (error) {
|
|
664
|
+
const err = error;
|
|
665
|
+
return {
|
|
666
|
+
error: this.parseError(err)
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
getOrder = async (orderId) => {
|
|
671
|
+
try {
|
|
672
|
+
const response = await this.client.get(`/orders/${orderId}`);
|
|
673
|
+
return {
|
|
674
|
+
data: response.data
|
|
675
|
+
};
|
|
676
|
+
} catch (error) {
|
|
677
|
+
const err = error;
|
|
678
|
+
return {
|
|
679
|
+
error: this.parseError(err)
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
rbfOrder = async (rbfRequest) => {
|
|
684
|
+
const { orderId, newFeeRate } = rbfRequest;
|
|
685
|
+
try {
|
|
686
|
+
const response = await this.client.post(`/orders/${orderId}/rbf-estimate`, {
|
|
687
|
+
newFeeRate
|
|
688
|
+
});
|
|
689
|
+
return {
|
|
690
|
+
data: response.data
|
|
691
|
+
};
|
|
692
|
+
} catch (error) {
|
|
693
|
+
const err = error;
|
|
694
|
+
return {
|
|
695
|
+
error: this.parseError(err)
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
};
|
|
700
|
+
var clients = {};
|
|
701
|
+
var getRunesApiClient = (network = "Mainnet" /* Mainnet */) => {
|
|
702
|
+
if (!clients[network]) {
|
|
703
|
+
clients[network] = new RunesApi(network);
|
|
704
|
+
}
|
|
705
|
+
return clients[network];
|
|
706
|
+
};
|
|
707
|
+
|
|
708
|
+
// src/adapters/satsConnectAdapter.ts
|
|
709
|
+
var SatsConnectAdapter = class {
|
|
710
|
+
async mintRunes(params) {
|
|
711
|
+
try {
|
|
712
|
+
const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
|
|
713
|
+
if (walletInfo && walletInfo.status === "success") {
|
|
714
|
+
const isMintSupported = walletInfo.result.methods?.includes("runes_mint");
|
|
715
|
+
if (isMintSupported) {
|
|
716
|
+
const response = await this.requestInternal("runes_mint", params);
|
|
717
|
+
if (response) {
|
|
718
|
+
if (response.status === "success") {
|
|
719
|
+
return response;
|
|
720
|
+
}
|
|
721
|
+
if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
|
|
722
|
+
return response;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
const mintRequest = {
|
|
728
|
+
destinationAddress: params.destinationAddress,
|
|
729
|
+
feeRate: params.feeRate,
|
|
730
|
+
refundAddress: params.refundAddress,
|
|
731
|
+
repeats: params.repeats,
|
|
732
|
+
runeName: params.runeName,
|
|
733
|
+
appServiceFee: params.appServiceFee,
|
|
734
|
+
appServiceFeeAddress: params.appServiceFeeAddress
|
|
735
|
+
};
|
|
736
|
+
const orderResponse = await new RunesApi(params.network).createMintOrder(mintRequest);
|
|
737
|
+
if (!orderResponse.data) {
|
|
738
|
+
return {
|
|
739
|
+
status: "error",
|
|
740
|
+
error: {
|
|
741
|
+
code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
742
|
+
message: orderResponse.error.message
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
const paymentResponse = await this.requestInternal("sendTransfer", {
|
|
747
|
+
recipients: [
|
|
748
|
+
{
|
|
749
|
+
address: orderResponse.data.fundAddress,
|
|
750
|
+
amount: orderResponse.data.fundAmount
|
|
751
|
+
}
|
|
752
|
+
]
|
|
753
|
+
});
|
|
754
|
+
if (paymentResponse.status !== "success") {
|
|
755
|
+
return paymentResponse;
|
|
756
|
+
}
|
|
757
|
+
await new RunesApi(params.network).executeMint(
|
|
758
|
+
orderResponse.data.orderId,
|
|
759
|
+
paymentResponse.result.txid
|
|
760
|
+
);
|
|
761
|
+
return {
|
|
762
|
+
status: "success",
|
|
763
|
+
result: {
|
|
764
|
+
orderId: orderResponse.data.orderId,
|
|
765
|
+
fundTransactionId: paymentResponse.result.txid,
|
|
766
|
+
fundingAddress: orderResponse.data.fundAddress
|
|
767
|
+
}
|
|
768
|
+
};
|
|
769
|
+
} catch (error) {
|
|
770
|
+
return {
|
|
771
|
+
status: "error",
|
|
772
|
+
error: {
|
|
773
|
+
code: -32603 /* INTERNAL_ERROR */,
|
|
774
|
+
message: error.message
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
async etchRunes(params) {
|
|
780
|
+
const etchRequest = {
|
|
781
|
+
destinationAddress: params.destinationAddress,
|
|
782
|
+
refundAddress: params.refundAddress,
|
|
783
|
+
feeRate: params.feeRate,
|
|
784
|
+
runeName: params.runeName,
|
|
785
|
+
divisibility: params.divisibility,
|
|
786
|
+
symbol: params.symbol,
|
|
787
|
+
premine: params.premine,
|
|
788
|
+
isMintable: params.isMintable,
|
|
789
|
+
terms: params.terms,
|
|
790
|
+
inscriptionDetails: params.inscriptionDetails,
|
|
791
|
+
delegateInscriptionId: params.delegateInscriptionId,
|
|
792
|
+
appServiceFee: params.appServiceFee,
|
|
793
|
+
appServiceFeeAddress: params.appServiceFeeAddress
|
|
794
|
+
};
|
|
795
|
+
try {
|
|
796
|
+
const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
|
|
797
|
+
if (walletInfo && walletInfo.status === "success") {
|
|
798
|
+
const isEtchSupported = walletInfo.result.methods?.includes("runes_etch");
|
|
799
|
+
if (isEtchSupported) {
|
|
800
|
+
const response = await this.requestInternal("runes_etch", params);
|
|
801
|
+
if (response) {
|
|
802
|
+
if (response.status === "success") {
|
|
803
|
+
return response;
|
|
804
|
+
}
|
|
805
|
+
if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
|
|
806
|
+
return response;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
const orderResponse = await new RunesApi(params.network).createEtchOrder(etchRequest);
|
|
812
|
+
if (!orderResponse.data) {
|
|
813
|
+
return {
|
|
814
|
+
status: "error",
|
|
815
|
+
error: {
|
|
816
|
+
code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
817
|
+
message: orderResponse.error.message
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
const paymentResponse = await this.requestInternal("sendTransfer", {
|
|
822
|
+
recipients: [
|
|
823
|
+
{
|
|
824
|
+
address: orderResponse.data.fundAddress,
|
|
825
|
+
amount: orderResponse.data.fundAmount
|
|
826
|
+
}
|
|
827
|
+
]
|
|
828
|
+
});
|
|
829
|
+
if (paymentResponse.status !== "success") {
|
|
830
|
+
return paymentResponse;
|
|
831
|
+
}
|
|
832
|
+
await new RunesApi(params.network).executeEtch(
|
|
833
|
+
orderResponse.data.orderId,
|
|
834
|
+
paymentResponse.result.txid
|
|
835
|
+
);
|
|
836
|
+
return {
|
|
837
|
+
status: "success",
|
|
838
|
+
result: {
|
|
839
|
+
orderId: orderResponse.data.orderId,
|
|
840
|
+
fundTransactionId: paymentResponse.result.txid,
|
|
841
|
+
fundingAddress: orderResponse.data.fundAddress
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
} catch (error) {
|
|
845
|
+
return {
|
|
846
|
+
status: "error",
|
|
847
|
+
error: {
|
|
848
|
+
code: -32603 /* INTERNAL_ERROR */,
|
|
849
|
+
message: error.message
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
}
|
|
947
853
|
}
|
|
948
|
-
|
|
949
|
-
|
|
854
|
+
async estimateMint(params) {
|
|
855
|
+
const estimateMintRequest = {
|
|
856
|
+
destinationAddress: params.destinationAddress,
|
|
857
|
+
feeRate: params.feeRate,
|
|
858
|
+
repeats: params.repeats,
|
|
859
|
+
runeName: params.runeName,
|
|
860
|
+
appServiceFee: params.appServiceFee,
|
|
861
|
+
appServiceFeeAddress: params.appServiceFeeAddress
|
|
862
|
+
};
|
|
863
|
+
const response = await getRunesApiClient(
|
|
864
|
+
params.network
|
|
865
|
+
).estimateMintCost(estimateMintRequest);
|
|
866
|
+
if (response.data) {
|
|
867
|
+
return {
|
|
868
|
+
status: "success",
|
|
869
|
+
result: response.data
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
return {
|
|
873
|
+
status: "error",
|
|
874
|
+
error: {
|
|
875
|
+
code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
876
|
+
message: response.error.message
|
|
877
|
+
}
|
|
878
|
+
};
|
|
950
879
|
}
|
|
951
|
-
|
|
952
|
-
|
|
880
|
+
async estimateEtch(params) {
|
|
881
|
+
const estimateEtchRequest = {
|
|
882
|
+
destinationAddress: params.destinationAddress,
|
|
883
|
+
feeRate: params.feeRate,
|
|
884
|
+
runeName: params.runeName,
|
|
885
|
+
divisibility: params.divisibility,
|
|
886
|
+
symbol: params.symbol,
|
|
887
|
+
premine: params.premine,
|
|
888
|
+
isMintable: params.isMintable,
|
|
889
|
+
terms: params.terms,
|
|
890
|
+
inscriptionDetails: params.inscriptionDetails,
|
|
891
|
+
delegateInscriptionId: params.delegateInscriptionId,
|
|
892
|
+
appServiceFee: params.appServiceFee,
|
|
893
|
+
appServiceFeeAddress: params.appServiceFeeAddress
|
|
894
|
+
};
|
|
895
|
+
const response = await getRunesApiClient(params.network).estimateEtchCost(estimateEtchRequest);
|
|
896
|
+
if (response.data) {
|
|
897
|
+
return {
|
|
898
|
+
status: "success",
|
|
899
|
+
result: response.data
|
|
900
|
+
};
|
|
901
|
+
}
|
|
953
902
|
return {
|
|
954
903
|
status: "error",
|
|
955
|
-
error:
|
|
904
|
+
error: {
|
|
905
|
+
code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
906
|
+
message: response.error.message
|
|
907
|
+
}
|
|
956
908
|
};
|
|
957
909
|
}
|
|
958
|
-
|
|
910
|
+
async getOrder(params) {
|
|
911
|
+
const response = await getRunesApiClient(params.network).getOrder(params.id);
|
|
912
|
+
if (response.data) {
|
|
913
|
+
return {
|
|
914
|
+
status: "success",
|
|
915
|
+
result: response.data
|
|
916
|
+
};
|
|
917
|
+
}
|
|
959
918
|
return {
|
|
960
|
-
status: "
|
|
961
|
-
|
|
919
|
+
status: "error",
|
|
920
|
+
error: {
|
|
921
|
+
code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
922
|
+
message: response.error.message
|
|
923
|
+
}
|
|
962
924
|
};
|
|
963
925
|
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
926
|
+
async estimateRbfOrder(params) {
|
|
927
|
+
const rbfOrderRequest = {
|
|
928
|
+
newFeeRate: params.newFeeRate,
|
|
929
|
+
orderId: params.orderId
|
|
930
|
+
};
|
|
931
|
+
const response = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
|
|
932
|
+
if (response.data) {
|
|
933
|
+
return {
|
|
934
|
+
status: "success",
|
|
935
|
+
result: {
|
|
936
|
+
fundingAddress: response.data.fundingAddress,
|
|
937
|
+
rbfCost: response.data.rbfCost
|
|
938
|
+
}
|
|
939
|
+
};
|
|
970
940
|
}
|
|
971
|
-
|
|
941
|
+
return {
|
|
942
|
+
status: "error",
|
|
943
|
+
error: {
|
|
944
|
+
code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
945
|
+
message: response.error.message
|
|
946
|
+
}
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
async rbfOrder(params) {
|
|
950
|
+
try {
|
|
951
|
+
const rbfOrderRequest = {
|
|
952
|
+
newFeeRate: params.newFeeRate,
|
|
953
|
+
orderId: params.orderId
|
|
954
|
+
};
|
|
955
|
+
const orderResponse = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
|
|
956
|
+
if (!orderResponse.data) {
|
|
957
|
+
return {
|
|
958
|
+
status: "error",
|
|
959
|
+
error: {
|
|
960
|
+
code: orderResponse.error.code === 400 || orderResponse.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
961
|
+
message: orderResponse.error.message
|
|
962
|
+
}
|
|
963
|
+
};
|
|
964
|
+
}
|
|
965
|
+
const paymentResponse = await this.requestInternal("sendTransfer", {
|
|
966
|
+
recipients: [
|
|
967
|
+
{
|
|
968
|
+
address: orderResponse.data.fundingAddress,
|
|
969
|
+
amount: orderResponse.data.rbfCost
|
|
970
|
+
}
|
|
971
|
+
]
|
|
972
|
+
});
|
|
973
|
+
if (paymentResponse.status !== "success") {
|
|
974
|
+
return paymentResponse;
|
|
975
|
+
}
|
|
976
|
+
return {
|
|
977
|
+
status: "success",
|
|
978
|
+
result: {
|
|
979
|
+
fundingAddress: orderResponse.data.fundingAddress,
|
|
980
|
+
orderId: rbfOrderRequest.orderId,
|
|
981
|
+
fundRBFTransactionId: paymentResponse.result.txid
|
|
982
|
+
}
|
|
983
|
+
};
|
|
984
|
+
} catch (error) {
|
|
985
|
+
return {
|
|
986
|
+
status: "error",
|
|
987
|
+
error: {
|
|
988
|
+
code: -32603 /* INTERNAL_ERROR */,
|
|
989
|
+
message: error.message
|
|
990
|
+
}
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
async request(method, params) {
|
|
995
|
+
switch (method) {
|
|
996
|
+
case "runes_mint":
|
|
997
|
+
return this.mintRunes(params);
|
|
998
|
+
case "runes_etch":
|
|
999
|
+
return this.etchRunes(params);
|
|
1000
|
+
case "runes_estimateMint":
|
|
1001
|
+
return this.estimateMint(params);
|
|
1002
|
+
case "runes_estimateEtch":
|
|
1003
|
+
return this.estimateEtch(params);
|
|
1004
|
+
case "runes_getOrder": {
|
|
1005
|
+
return this.getOrder(params);
|
|
1006
|
+
}
|
|
1007
|
+
case "runes_estimateRbfOrder": {
|
|
1008
|
+
return this.estimateRbfOrder(params);
|
|
1009
|
+
}
|
|
1010
|
+
case "runes_rbfOrder": {
|
|
1011
|
+
return this.rbfOrder(params);
|
|
1012
|
+
}
|
|
1013
|
+
default:
|
|
1014
|
+
return this.requestInternal(method, params);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
972
1017
|
};
|
|
973
1018
|
|
|
974
1019
|
// src/adapters/xverse.ts
|
|
@@ -977,6 +1022,15 @@ var XverseAdapter = class extends SatsConnectAdapter {
|
|
|
977
1022
|
requestInternal = async (method, params) => {
|
|
978
1023
|
return request(method, params, this.id);
|
|
979
1024
|
};
|
|
1025
|
+
addListener = (event, cb) => {
|
|
1026
|
+
return addListener(
|
|
1027
|
+
event,
|
|
1028
|
+
// The types of the `addListener` function being called here are not
|
|
1029
|
+
// entirely accurate.
|
|
1030
|
+
cb,
|
|
1031
|
+
this.id
|
|
1032
|
+
);
|
|
1033
|
+
};
|
|
980
1034
|
};
|
|
981
1035
|
|
|
982
1036
|
// src/adapters/unisat.ts
|
|
@@ -1145,6 +1199,9 @@ var BaseAdapter = class extends SatsConnectAdapter {
|
|
|
1145
1199
|
requestInternal = async (method, params) => {
|
|
1146
1200
|
return request(method, params, this.id);
|
|
1147
1201
|
};
|
|
1202
|
+
addListener = (..._args) => {
|
|
1203
|
+
throw new Error("Method not supported for `BaseAdapter`.");
|
|
1204
|
+
};
|
|
1148
1205
|
};
|
|
1149
1206
|
|
|
1150
1207
|
// src/adapters/index.ts
|
|
@@ -1190,7 +1247,8 @@ var extractOrValidateCapabilities = (provider, reportedCapabilities) => {
|
|
|
1190
1247
|
sendBtcTransaction: validateCapability("sendBtcTransaction"),
|
|
1191
1248
|
createInscription: validateCapability("createInscription"),
|
|
1192
1249
|
createRepeatInscriptions: validateCapability("createRepeatInscriptions"),
|
|
1193
|
-
signMultipleTransactions: validateCapability("signMultipleTransactions")
|
|
1250
|
+
signMultipleTransactions: validateCapability("signMultipleTransactions"),
|
|
1251
|
+
addListener: validateCapability("addListener")
|
|
1194
1252
|
};
|
|
1195
1253
|
return Object.entries(capabilityMap).reduce((acc, [capability, value]) => {
|
|
1196
1254
|
if (value)
|
|
@@ -1388,6 +1446,10 @@ export {
|
|
|
1388
1446
|
RpcErrorCode,
|
|
1389
1447
|
RpcIdSchema,
|
|
1390
1448
|
SatsConnectAdapter,
|
|
1449
|
+
TransferRunesResultSchema,
|
|
1450
|
+
accountChangeEventName,
|
|
1451
|
+
accountChangeSchema,
|
|
1452
|
+
addListener,
|
|
1391
1453
|
addressSchema,
|
|
1392
1454
|
createInscription,
|
|
1393
1455
|
createRepeatInscriptions,
|
|
@@ -1428,6 +1490,8 @@ export {
|
|
|
1428
1490
|
getWalletTypeRequestMessageSchema,
|
|
1429
1491
|
getWalletTypeResultSchema,
|
|
1430
1492
|
isProviderInstalled,
|
|
1493
|
+
networkChangeEventName,
|
|
1494
|
+
networkChangeSchema,
|
|
1431
1495
|
removeDefaultProvider,
|
|
1432
1496
|
renouncePermissionsMethodName,
|
|
1433
1497
|
renouncePermissionsParamsSchema,
|
|
@@ -1463,6 +1527,10 @@ export {
|
|
|
1463
1527
|
stxSignTransactionParamsSchema,
|
|
1464
1528
|
stxSignTransactionRequestMessageSchema,
|
|
1465
1529
|
stxSignTransactionResultSchema,
|
|
1530
|
+
transferRunesMethodName,
|
|
1531
|
+
transferRunesParamsSchema,
|
|
1532
|
+
transferRunesRequestSchema,
|
|
1533
|
+
walletEventSchema,
|
|
1466
1534
|
walletTypeSchema,
|
|
1467
1535
|
walletTypes
|
|
1468
1536
|
};
|