@sats-connect/core 0.1.2-dded197 → 0.2.0-3e4af84
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 +40 -9
- package/dist/index.mjs +797 -740
- 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,230 +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()
|
|
880
434
|
}).entries
|
|
881
435
|
});
|
|
882
|
-
var
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
)
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
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()
|
|
452
|
+
}).entries
|
|
892
453
|
});
|
|
893
|
-
var TransferRunesResultSchema =
|
|
894
|
-
txid:
|
|
454
|
+
var TransferRunesResultSchema = v8.object({
|
|
455
|
+
txid: v8.string()
|
|
895
456
|
});
|
|
896
457
|
|
|
897
458
|
// src/request/types/ordinalsMethods.ts
|
|
898
|
-
import * as
|
|
459
|
+
import * as v9 from "valibot";
|
|
899
460
|
var getInscriptionsMethodName = "ord_getInscriptions";
|
|
900
|
-
var getInscriptionsParamsSchema =
|
|
901
|
-
offset:
|
|
902
|
-
limit:
|
|
461
|
+
var getInscriptionsParamsSchema = v9.object({
|
|
462
|
+
offset: v9.number(),
|
|
463
|
+
limit: v9.number()
|
|
903
464
|
});
|
|
904
|
-
var getInscriptionsResultSchema =
|
|
905
|
-
total:
|
|
906
|
-
limit:
|
|
907
|
-
offset:
|
|
908
|
-
inscriptions:
|
|
909
|
-
|
|
910
|
-
inscriptionId:
|
|
911
|
-
inscriptionNumber:
|
|
912
|
-
address:
|
|
913
|
-
collectionName:
|
|
914
|
-
postage:
|
|
915
|
-
contentLength:
|
|
916
|
-
contentType:
|
|
917
|
-
timestamp:
|
|
918
|
-
offset:
|
|
919
|
-
genesisTransaction:
|
|
920
|
-
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()
|
|
921
482
|
})
|
|
922
483
|
)
|
|
923
484
|
});
|
|
924
|
-
var getInscriptionsSchema =
|
|
485
|
+
var getInscriptionsSchema = v9.object({
|
|
925
486
|
...rpcRequestMessageSchema.entries,
|
|
926
|
-
...
|
|
927
|
-
method:
|
|
487
|
+
...v9.object({
|
|
488
|
+
method: v9.literal(getInscriptionsMethodName),
|
|
928
489
|
params: getInscriptionsParamsSchema,
|
|
929
|
-
id:
|
|
490
|
+
id: v9.string()
|
|
930
491
|
}).entries
|
|
931
492
|
});
|
|
932
493
|
var sendInscriptionsMethodName = "ord_sendInscriptions";
|
|
933
|
-
var sendInscriptionsParamsSchema =
|
|
934
|
-
transfers:
|
|
935
|
-
|
|
936
|
-
address:
|
|
937
|
-
inscriptionId:
|
|
494
|
+
var sendInscriptionsParamsSchema = v9.object({
|
|
495
|
+
transfers: v9.array(
|
|
496
|
+
v9.object({
|
|
497
|
+
address: v9.string(),
|
|
498
|
+
inscriptionId: v9.string()
|
|
938
499
|
})
|
|
939
500
|
)
|
|
940
501
|
});
|
|
941
|
-
var sendInscriptionsResultSchema =
|
|
942
|
-
txid:
|
|
502
|
+
var sendInscriptionsResultSchema = v9.object({
|
|
503
|
+
txid: v9.string()
|
|
943
504
|
});
|
|
944
|
-
var sendInscriptionsSchema =
|
|
505
|
+
var sendInscriptionsSchema = v9.object({
|
|
945
506
|
...rpcRequestMessageSchema.entries,
|
|
946
|
-
...
|
|
947
|
-
method:
|
|
507
|
+
...v9.object({
|
|
508
|
+
method: v9.literal(sendInscriptionsMethodName),
|
|
948
509
|
params: sendInscriptionsParamsSchema,
|
|
949
|
-
id:
|
|
510
|
+
id: v9.string()
|
|
950
511
|
}).entries
|
|
951
512
|
});
|
|
952
513
|
|
|
@@ -956,33 +517,510 @@ var request = async (method, params, providerId) => {
|
|
|
956
517
|
if (providerId) {
|
|
957
518
|
provider = await getProviderById(providerId);
|
|
958
519
|
}
|
|
959
|
-
if (!provider) {
|
|
960
|
-
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
|
+
if (!provider.addListener) {
|
|
557
|
+
console.error(
|
|
558
|
+
`The wallet provider you are using does not support the addListener method. Please update your wallet provider.`
|
|
559
|
+
);
|
|
560
|
+
return () => {
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
return provider.addListener(event, cb);
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
// src/runes/api.ts
|
|
567
|
+
import axios from "axios";
|
|
568
|
+
var urlNetworkSuffix = {
|
|
569
|
+
["Mainnet" /* Mainnet */]: "",
|
|
570
|
+
["Testnet" /* Testnet */]: "-testnet",
|
|
571
|
+
["Signet" /* Signet */]: "-signet"
|
|
572
|
+
};
|
|
573
|
+
var ORDINALS_API_BASE_URL = (network = "Mainnet" /* Mainnet */) => `https://ordinals${urlNetworkSuffix[network]}.xverse.app/v1`;
|
|
574
|
+
var RunesApi = class {
|
|
575
|
+
client;
|
|
576
|
+
constructor(network) {
|
|
577
|
+
this.client = axios.create({
|
|
578
|
+
baseURL: ORDINALS_API_BASE_URL(network)
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
parseError = (error) => {
|
|
582
|
+
return {
|
|
583
|
+
code: error.response?.status,
|
|
584
|
+
message: JSON.stringify(error.response?.data)
|
|
585
|
+
};
|
|
586
|
+
};
|
|
587
|
+
estimateMintCost = async (mintParams) => {
|
|
588
|
+
try {
|
|
589
|
+
const response = await this.client.post("/runes/mint/estimate", {
|
|
590
|
+
...mintParams
|
|
591
|
+
});
|
|
592
|
+
return {
|
|
593
|
+
data: response.data
|
|
594
|
+
};
|
|
595
|
+
} catch (error) {
|
|
596
|
+
const err = error;
|
|
597
|
+
return {
|
|
598
|
+
error: this.parseError(err)
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
estimateEtchCost = async (etchParams) => {
|
|
603
|
+
try {
|
|
604
|
+
const response = await this.client.post("/runes/etch/estimate", {
|
|
605
|
+
...etchParams
|
|
606
|
+
});
|
|
607
|
+
return {
|
|
608
|
+
data: response.data
|
|
609
|
+
};
|
|
610
|
+
} catch (error) {
|
|
611
|
+
const err = error;
|
|
612
|
+
return {
|
|
613
|
+
error: this.parseError(err)
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
createMintOrder = async (mintOrderParams) => {
|
|
618
|
+
try {
|
|
619
|
+
const response = await this.client.post("/runes/mint/orders", {
|
|
620
|
+
...mintOrderParams
|
|
621
|
+
});
|
|
622
|
+
return {
|
|
623
|
+
data: response.data
|
|
624
|
+
};
|
|
625
|
+
} catch (error) {
|
|
626
|
+
const err = error;
|
|
627
|
+
return {
|
|
628
|
+
error: this.parseError(err)
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
createEtchOrder = async (etchOrderParams) => {
|
|
633
|
+
try {
|
|
634
|
+
const response = await this.client.post("/runes/etch/orders", {
|
|
635
|
+
...etchOrderParams
|
|
636
|
+
});
|
|
637
|
+
return {
|
|
638
|
+
data: response.data
|
|
639
|
+
};
|
|
640
|
+
} catch (error) {
|
|
641
|
+
const err = error;
|
|
642
|
+
return {
|
|
643
|
+
error: this.parseError(err)
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
executeMint = async (orderId, fundTransactionId) => {
|
|
648
|
+
try {
|
|
649
|
+
const response = await this.client.post(`/runes/mint/orders/${orderId}/execute`, {
|
|
650
|
+
fundTransactionId
|
|
651
|
+
});
|
|
652
|
+
return {
|
|
653
|
+
data: response.data
|
|
654
|
+
};
|
|
655
|
+
} catch (error) {
|
|
656
|
+
const err = error;
|
|
657
|
+
return {
|
|
658
|
+
error: this.parseError(err)
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
executeEtch = async (orderId, fundTransactionId) => {
|
|
663
|
+
try {
|
|
664
|
+
const response = await this.client.post(`/runes/etch/orders/${orderId}/execute`, {
|
|
665
|
+
fundTransactionId
|
|
666
|
+
});
|
|
667
|
+
return {
|
|
668
|
+
data: response.data
|
|
669
|
+
};
|
|
670
|
+
} catch (error) {
|
|
671
|
+
const err = error;
|
|
672
|
+
return {
|
|
673
|
+
error: this.parseError(err)
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
getOrder = async (orderId) => {
|
|
678
|
+
try {
|
|
679
|
+
const response = await this.client.get(`/orders/${orderId}`);
|
|
680
|
+
return {
|
|
681
|
+
data: response.data
|
|
682
|
+
};
|
|
683
|
+
} catch (error) {
|
|
684
|
+
const err = error;
|
|
685
|
+
return {
|
|
686
|
+
error: this.parseError(err)
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
rbfOrder = async (rbfRequest) => {
|
|
691
|
+
const { orderId, newFeeRate } = rbfRequest;
|
|
692
|
+
try {
|
|
693
|
+
const response = await this.client.post(`/orders/${orderId}/rbf-estimate`, {
|
|
694
|
+
newFeeRate
|
|
695
|
+
});
|
|
696
|
+
return {
|
|
697
|
+
data: response.data
|
|
698
|
+
};
|
|
699
|
+
} catch (error) {
|
|
700
|
+
const err = error;
|
|
701
|
+
return {
|
|
702
|
+
error: this.parseError(err)
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
};
|
|
707
|
+
var clients = {};
|
|
708
|
+
var getRunesApiClient = (network = "Mainnet" /* Mainnet */) => {
|
|
709
|
+
if (!clients[network]) {
|
|
710
|
+
clients[network] = new RunesApi(network);
|
|
711
|
+
}
|
|
712
|
+
return clients[network];
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
// src/adapters/satsConnectAdapter.ts
|
|
716
|
+
var SatsConnectAdapter = class {
|
|
717
|
+
async mintRunes(params) {
|
|
718
|
+
try {
|
|
719
|
+
const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
|
|
720
|
+
if (walletInfo && walletInfo.status === "success") {
|
|
721
|
+
const isMintSupported = walletInfo.result.methods?.includes("runes_mint");
|
|
722
|
+
if (isMintSupported) {
|
|
723
|
+
const response = await this.requestInternal("runes_mint", params);
|
|
724
|
+
if (response) {
|
|
725
|
+
if (response.status === "success") {
|
|
726
|
+
return response;
|
|
727
|
+
}
|
|
728
|
+
if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
|
|
729
|
+
return response;
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
const mintRequest = {
|
|
735
|
+
destinationAddress: params.destinationAddress,
|
|
736
|
+
feeRate: params.feeRate,
|
|
737
|
+
refundAddress: params.refundAddress,
|
|
738
|
+
repeats: params.repeats,
|
|
739
|
+
runeName: params.runeName,
|
|
740
|
+
appServiceFee: params.appServiceFee,
|
|
741
|
+
appServiceFeeAddress: params.appServiceFeeAddress
|
|
742
|
+
};
|
|
743
|
+
const orderResponse = await new RunesApi(params.network).createMintOrder(mintRequest);
|
|
744
|
+
if (!orderResponse.data) {
|
|
745
|
+
return {
|
|
746
|
+
status: "error",
|
|
747
|
+
error: {
|
|
748
|
+
code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
749
|
+
message: orderResponse.error.message
|
|
750
|
+
}
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
const paymentResponse = await this.requestInternal("sendTransfer", {
|
|
754
|
+
recipients: [
|
|
755
|
+
{
|
|
756
|
+
address: orderResponse.data.fundAddress,
|
|
757
|
+
amount: orderResponse.data.fundAmount
|
|
758
|
+
}
|
|
759
|
+
]
|
|
760
|
+
});
|
|
761
|
+
if (paymentResponse.status !== "success") {
|
|
762
|
+
return paymentResponse;
|
|
763
|
+
}
|
|
764
|
+
await new RunesApi(params.network).executeMint(
|
|
765
|
+
orderResponse.data.orderId,
|
|
766
|
+
paymentResponse.result.txid
|
|
767
|
+
);
|
|
768
|
+
return {
|
|
769
|
+
status: "success",
|
|
770
|
+
result: {
|
|
771
|
+
orderId: orderResponse.data.orderId,
|
|
772
|
+
fundTransactionId: paymentResponse.result.txid,
|
|
773
|
+
fundingAddress: orderResponse.data.fundAddress
|
|
774
|
+
}
|
|
775
|
+
};
|
|
776
|
+
} catch (error) {
|
|
777
|
+
return {
|
|
778
|
+
status: "error",
|
|
779
|
+
error: {
|
|
780
|
+
code: -32603 /* INTERNAL_ERROR */,
|
|
781
|
+
message: error.message
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
async etchRunes(params) {
|
|
787
|
+
const etchRequest = {
|
|
788
|
+
destinationAddress: params.destinationAddress,
|
|
789
|
+
refundAddress: params.refundAddress,
|
|
790
|
+
feeRate: params.feeRate,
|
|
791
|
+
runeName: params.runeName,
|
|
792
|
+
divisibility: params.divisibility,
|
|
793
|
+
symbol: params.symbol,
|
|
794
|
+
premine: params.premine,
|
|
795
|
+
isMintable: params.isMintable,
|
|
796
|
+
terms: params.terms,
|
|
797
|
+
inscriptionDetails: params.inscriptionDetails,
|
|
798
|
+
delegateInscriptionId: params.delegateInscriptionId,
|
|
799
|
+
appServiceFee: params.appServiceFee,
|
|
800
|
+
appServiceFeeAddress: params.appServiceFeeAddress
|
|
801
|
+
};
|
|
802
|
+
try {
|
|
803
|
+
const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
|
|
804
|
+
if (walletInfo && walletInfo.status === "success") {
|
|
805
|
+
const isEtchSupported = walletInfo.result.methods?.includes("runes_etch");
|
|
806
|
+
if (isEtchSupported) {
|
|
807
|
+
const response = await this.requestInternal("runes_etch", params);
|
|
808
|
+
if (response) {
|
|
809
|
+
if (response.status === "success") {
|
|
810
|
+
return response;
|
|
811
|
+
}
|
|
812
|
+
if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
|
|
813
|
+
return response;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
const orderResponse = await new RunesApi(params.network).createEtchOrder(etchRequest);
|
|
819
|
+
if (!orderResponse.data) {
|
|
820
|
+
return {
|
|
821
|
+
status: "error",
|
|
822
|
+
error: {
|
|
823
|
+
code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
824
|
+
message: orderResponse.error.message
|
|
825
|
+
}
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
const paymentResponse = await this.requestInternal("sendTransfer", {
|
|
829
|
+
recipients: [
|
|
830
|
+
{
|
|
831
|
+
address: orderResponse.data.fundAddress,
|
|
832
|
+
amount: orderResponse.data.fundAmount
|
|
833
|
+
}
|
|
834
|
+
]
|
|
835
|
+
});
|
|
836
|
+
if (paymentResponse.status !== "success") {
|
|
837
|
+
return paymentResponse;
|
|
838
|
+
}
|
|
839
|
+
await new RunesApi(params.network).executeEtch(
|
|
840
|
+
orderResponse.data.orderId,
|
|
841
|
+
paymentResponse.result.txid
|
|
842
|
+
);
|
|
843
|
+
return {
|
|
844
|
+
status: "success",
|
|
845
|
+
result: {
|
|
846
|
+
orderId: orderResponse.data.orderId,
|
|
847
|
+
fundTransactionId: paymentResponse.result.txid,
|
|
848
|
+
fundingAddress: orderResponse.data.fundAddress
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
} catch (error) {
|
|
852
|
+
return {
|
|
853
|
+
status: "error",
|
|
854
|
+
error: {
|
|
855
|
+
code: -32603 /* INTERNAL_ERROR */,
|
|
856
|
+
message: error.message
|
|
857
|
+
}
|
|
858
|
+
};
|
|
859
|
+
}
|
|
961
860
|
}
|
|
962
|
-
|
|
963
|
-
|
|
861
|
+
async estimateMint(params) {
|
|
862
|
+
const estimateMintRequest = {
|
|
863
|
+
destinationAddress: params.destinationAddress,
|
|
864
|
+
feeRate: params.feeRate,
|
|
865
|
+
repeats: params.repeats,
|
|
866
|
+
runeName: params.runeName,
|
|
867
|
+
appServiceFee: params.appServiceFee,
|
|
868
|
+
appServiceFeeAddress: params.appServiceFeeAddress
|
|
869
|
+
};
|
|
870
|
+
const response = await getRunesApiClient(
|
|
871
|
+
params.network
|
|
872
|
+
).estimateMintCost(estimateMintRequest);
|
|
873
|
+
if (response.data) {
|
|
874
|
+
return {
|
|
875
|
+
status: "success",
|
|
876
|
+
result: response.data
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
return {
|
|
880
|
+
status: "error",
|
|
881
|
+
error: {
|
|
882
|
+
code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
883
|
+
message: response.error.message
|
|
884
|
+
}
|
|
885
|
+
};
|
|
964
886
|
}
|
|
965
|
-
|
|
966
|
-
|
|
887
|
+
async estimateEtch(params) {
|
|
888
|
+
const estimateEtchRequest = {
|
|
889
|
+
destinationAddress: params.destinationAddress,
|
|
890
|
+
feeRate: params.feeRate,
|
|
891
|
+
runeName: params.runeName,
|
|
892
|
+
divisibility: params.divisibility,
|
|
893
|
+
symbol: params.symbol,
|
|
894
|
+
premine: params.premine,
|
|
895
|
+
isMintable: params.isMintable,
|
|
896
|
+
terms: params.terms,
|
|
897
|
+
inscriptionDetails: params.inscriptionDetails,
|
|
898
|
+
delegateInscriptionId: params.delegateInscriptionId,
|
|
899
|
+
appServiceFee: params.appServiceFee,
|
|
900
|
+
appServiceFeeAddress: params.appServiceFeeAddress
|
|
901
|
+
};
|
|
902
|
+
const response = await getRunesApiClient(params.network).estimateEtchCost(estimateEtchRequest);
|
|
903
|
+
if (response.data) {
|
|
904
|
+
return {
|
|
905
|
+
status: "success",
|
|
906
|
+
result: response.data
|
|
907
|
+
};
|
|
908
|
+
}
|
|
967
909
|
return {
|
|
968
910
|
status: "error",
|
|
969
|
-
error:
|
|
911
|
+
error: {
|
|
912
|
+
code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
913
|
+
message: response.error.message
|
|
914
|
+
}
|
|
970
915
|
};
|
|
971
916
|
}
|
|
972
|
-
|
|
917
|
+
async getOrder(params) {
|
|
918
|
+
const response = await getRunesApiClient(params.network).getOrder(params.id);
|
|
919
|
+
if (response.data) {
|
|
920
|
+
return {
|
|
921
|
+
status: "success",
|
|
922
|
+
result: response.data
|
|
923
|
+
};
|
|
924
|
+
}
|
|
973
925
|
return {
|
|
974
|
-
status: "
|
|
975
|
-
|
|
926
|
+
status: "error",
|
|
927
|
+
error: {
|
|
928
|
+
code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
929
|
+
message: response.error.message
|
|
930
|
+
}
|
|
976
931
|
};
|
|
977
932
|
}
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
933
|
+
async estimateRbfOrder(params) {
|
|
934
|
+
const rbfOrderRequest = {
|
|
935
|
+
newFeeRate: params.newFeeRate,
|
|
936
|
+
orderId: params.orderId
|
|
937
|
+
};
|
|
938
|
+
const response = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
|
|
939
|
+
if (response.data) {
|
|
940
|
+
return {
|
|
941
|
+
status: "success",
|
|
942
|
+
result: {
|
|
943
|
+
fundingAddress: response.data.fundingAddress,
|
|
944
|
+
rbfCost: response.data.rbfCost
|
|
945
|
+
}
|
|
946
|
+
};
|
|
984
947
|
}
|
|
985
|
-
|
|
948
|
+
return {
|
|
949
|
+
status: "error",
|
|
950
|
+
error: {
|
|
951
|
+
code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
952
|
+
message: response.error.message
|
|
953
|
+
}
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
async rbfOrder(params) {
|
|
957
|
+
try {
|
|
958
|
+
const rbfOrderRequest = {
|
|
959
|
+
newFeeRate: params.newFeeRate,
|
|
960
|
+
orderId: params.orderId
|
|
961
|
+
};
|
|
962
|
+
const orderResponse = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
|
|
963
|
+
if (!orderResponse.data) {
|
|
964
|
+
return {
|
|
965
|
+
status: "error",
|
|
966
|
+
error: {
|
|
967
|
+
code: orderResponse.error.code === 400 || orderResponse.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
968
|
+
message: orderResponse.error.message
|
|
969
|
+
}
|
|
970
|
+
};
|
|
971
|
+
}
|
|
972
|
+
const paymentResponse = await this.requestInternal("sendTransfer", {
|
|
973
|
+
recipients: [
|
|
974
|
+
{
|
|
975
|
+
address: orderResponse.data.fundingAddress,
|
|
976
|
+
amount: orderResponse.data.rbfCost
|
|
977
|
+
}
|
|
978
|
+
]
|
|
979
|
+
});
|
|
980
|
+
if (paymentResponse.status !== "success") {
|
|
981
|
+
return paymentResponse;
|
|
982
|
+
}
|
|
983
|
+
return {
|
|
984
|
+
status: "success",
|
|
985
|
+
result: {
|
|
986
|
+
fundingAddress: orderResponse.data.fundingAddress,
|
|
987
|
+
orderId: rbfOrderRequest.orderId,
|
|
988
|
+
fundRBFTransactionId: paymentResponse.result.txid
|
|
989
|
+
}
|
|
990
|
+
};
|
|
991
|
+
} catch (error) {
|
|
992
|
+
return {
|
|
993
|
+
status: "error",
|
|
994
|
+
error: {
|
|
995
|
+
code: -32603 /* INTERNAL_ERROR */,
|
|
996
|
+
message: error.message
|
|
997
|
+
}
|
|
998
|
+
};
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
async request(method, params) {
|
|
1002
|
+
switch (method) {
|
|
1003
|
+
case "runes_mint":
|
|
1004
|
+
return this.mintRunes(params);
|
|
1005
|
+
case "runes_etch":
|
|
1006
|
+
return this.etchRunes(params);
|
|
1007
|
+
case "runes_estimateMint":
|
|
1008
|
+
return this.estimateMint(params);
|
|
1009
|
+
case "runes_estimateEtch":
|
|
1010
|
+
return this.estimateEtch(params);
|
|
1011
|
+
case "runes_getOrder": {
|
|
1012
|
+
return this.getOrder(params);
|
|
1013
|
+
}
|
|
1014
|
+
case "runes_estimateRbfOrder": {
|
|
1015
|
+
return this.estimateRbfOrder(params);
|
|
1016
|
+
}
|
|
1017
|
+
case "runes_rbfOrder": {
|
|
1018
|
+
return this.rbfOrder(params);
|
|
1019
|
+
}
|
|
1020
|
+
default:
|
|
1021
|
+
return this.requestInternal(method, params);
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
986
1024
|
};
|
|
987
1025
|
|
|
988
1026
|
// src/adapters/xverse.ts
|
|
@@ -991,6 +1029,15 @@ var XverseAdapter = class extends SatsConnectAdapter {
|
|
|
991
1029
|
requestInternal = async (method, params) => {
|
|
992
1030
|
return request(method, params, this.id);
|
|
993
1031
|
};
|
|
1032
|
+
addListener = (event, cb) => {
|
|
1033
|
+
return addListener(
|
|
1034
|
+
event,
|
|
1035
|
+
// The types of the `addListener` function being called here are not
|
|
1036
|
+
// entirely accurate.
|
|
1037
|
+
cb,
|
|
1038
|
+
this.id
|
|
1039
|
+
);
|
|
1040
|
+
};
|
|
994
1041
|
};
|
|
995
1042
|
|
|
996
1043
|
// src/adapters/unisat.ts
|
|
@@ -1159,6 +1206,9 @@ var BaseAdapter = class extends SatsConnectAdapter {
|
|
|
1159
1206
|
requestInternal = async (method, params) => {
|
|
1160
1207
|
return request(method, params, this.id);
|
|
1161
1208
|
};
|
|
1209
|
+
addListener = (..._args) => {
|
|
1210
|
+
throw new Error("Method not supported for `BaseAdapter`.");
|
|
1211
|
+
};
|
|
1162
1212
|
};
|
|
1163
1213
|
|
|
1164
1214
|
// src/adapters/index.ts
|
|
@@ -1204,7 +1254,8 @@ var extractOrValidateCapabilities = (provider, reportedCapabilities) => {
|
|
|
1204
1254
|
sendBtcTransaction: validateCapability("sendBtcTransaction"),
|
|
1205
1255
|
createInscription: validateCapability("createInscription"),
|
|
1206
1256
|
createRepeatInscriptions: validateCapability("createRepeatInscriptions"),
|
|
1207
|
-
signMultipleTransactions: validateCapability("signMultipleTransactions")
|
|
1257
|
+
signMultipleTransactions: validateCapability("signMultipleTransactions"),
|
|
1258
|
+
addListener: validateCapability("addListener")
|
|
1208
1259
|
};
|
|
1209
1260
|
return Object.entries(capabilityMap).reduce((acc, [capability, value]) => {
|
|
1210
1261
|
if (value)
|
|
@@ -1401,11 +1452,11 @@ export {
|
|
|
1401
1452
|
MessageSigningProtocols,
|
|
1402
1453
|
RpcErrorCode,
|
|
1403
1454
|
RpcIdSchema,
|
|
1404
|
-
RuneTransferRecipientsSchema,
|
|
1405
1455
|
SatsConnectAdapter,
|
|
1406
|
-
TransferRunesMethodName,
|
|
1407
|
-
TransferRunesParamsSchema,
|
|
1408
1456
|
TransferRunesResultSchema,
|
|
1457
|
+
accountChangeEventName,
|
|
1458
|
+
accountChangeSchema,
|
|
1459
|
+
addListener,
|
|
1409
1460
|
addressSchema,
|
|
1410
1461
|
createInscription,
|
|
1411
1462
|
createRepeatInscriptions,
|
|
@@ -1446,6 +1497,8 @@ export {
|
|
|
1446
1497
|
getWalletTypeRequestMessageSchema,
|
|
1447
1498
|
getWalletTypeResultSchema,
|
|
1448
1499
|
isProviderInstalled,
|
|
1500
|
+
networkChangeEventName,
|
|
1501
|
+
networkChangeSchema,
|
|
1449
1502
|
removeDefaultProvider,
|
|
1450
1503
|
renouncePermissionsMethodName,
|
|
1451
1504
|
renouncePermissionsParamsSchema,
|
|
@@ -1481,6 +1534,10 @@ export {
|
|
|
1481
1534
|
stxSignTransactionParamsSchema,
|
|
1482
1535
|
stxSignTransactionRequestMessageSchema,
|
|
1483
1536
|
stxSignTransactionResultSchema,
|
|
1537
|
+
transferRunesMethodName,
|
|
1538
|
+
transferRunesParamsSchema,
|
|
1539
|
+
transferRunesRequestSchema,
|
|
1540
|
+
walletEventSchema,
|
|
1484
1541
|
walletTypeSchema,
|
|
1485
1542
|
walletTypes
|
|
1486
1543
|
};
|