@sats-connect/core 0.8.1-a6a42ae → 0.8.1-b5b5706
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 +1889 -1883
- package/dist/index.d.ts +1889 -1883
- package/dist/index.js +924 -898
- package/dist/index.mjs +923 -898
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,67 +1,5 @@
|
|
|
1
|
-
// src/request/index.ts
|
|
2
|
-
import * as v25 from "valibot";
|
|
3
|
-
|
|
4
|
-
// src/provider/types.ts
|
|
5
|
-
import * as v4 from "valibot";
|
|
6
|
-
|
|
7
|
-
// src/addresses/index.ts
|
|
8
|
-
import { createUnsecuredToken } from "jsontokens";
|
|
9
|
-
|
|
10
|
-
// src/addresses/types.ts
|
|
11
|
-
import * as v2 from "valibot";
|
|
12
|
-
|
|
13
|
-
// src/request/types/common.ts
|
|
14
|
-
import * as v from "valibot";
|
|
15
|
-
var walletTypes = ["software", "ledger", "keystone"];
|
|
16
|
-
var walletTypeSchema = v.picklist(walletTypes);
|
|
17
|
-
|
|
18
|
-
// src/addresses/types.ts
|
|
19
|
-
var AddressPurpose = /* @__PURE__ */ ((AddressPurpose2) => {
|
|
20
|
-
AddressPurpose2["Ordinals"] = "ordinals";
|
|
21
|
-
AddressPurpose2["Payment"] = "payment";
|
|
22
|
-
AddressPurpose2["Stacks"] = "stacks";
|
|
23
|
-
AddressPurpose2["Starknet"] = "starknet";
|
|
24
|
-
AddressPurpose2["Spark"] = "spark";
|
|
25
|
-
return AddressPurpose2;
|
|
26
|
-
})(AddressPurpose || {});
|
|
27
|
-
var AddressType = /* @__PURE__ */ ((AddressType3) => {
|
|
28
|
-
AddressType3["p2pkh"] = "p2pkh";
|
|
29
|
-
AddressType3["p2sh"] = "p2sh";
|
|
30
|
-
AddressType3["p2wpkh"] = "p2wpkh";
|
|
31
|
-
AddressType3["p2wsh"] = "p2wsh";
|
|
32
|
-
AddressType3["p2tr"] = "p2tr";
|
|
33
|
-
AddressType3["stacks"] = "stacks";
|
|
34
|
-
AddressType3["starknet"] = "starknet";
|
|
35
|
-
AddressType3["spark"] = "spark";
|
|
36
|
-
return AddressType3;
|
|
37
|
-
})(AddressType || {});
|
|
38
|
-
var addressSchema = v2.object({
|
|
39
|
-
address: v2.string(),
|
|
40
|
-
publicKey: v2.string(),
|
|
41
|
-
purpose: v2.enum(AddressPurpose),
|
|
42
|
-
addressType: v2.enum(AddressType),
|
|
43
|
-
walletType: walletTypeSchema
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// src/addresses/index.ts
|
|
47
|
-
var getAddress = async (options) => {
|
|
48
|
-
const provider = await getProviderOrThrow(options.getProvider);
|
|
49
|
-
const { purposes } = options.payload;
|
|
50
|
-
if (!purposes) {
|
|
51
|
-
throw new Error("Address purposes are required");
|
|
52
|
-
}
|
|
53
|
-
try {
|
|
54
|
-
const request2 = createUnsecuredToken(options.payload);
|
|
55
|
-
const response = await provider.connect(request2);
|
|
56
|
-
options.onFinish?.(response);
|
|
57
|
-
} catch (error) {
|
|
58
|
-
console.error("[Connect] Error during address request", error);
|
|
59
|
-
options.onCancel?.();
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
1
|
// src/types.ts
|
|
64
|
-
import * as
|
|
2
|
+
import * as v from "valibot";
|
|
65
3
|
var BitcoinNetworkType = /* @__PURE__ */ ((BitcoinNetworkType2) => {
|
|
66
4
|
BitcoinNetworkType2["Mainnet"] = "Mainnet";
|
|
67
5
|
BitcoinNetworkType2["Testnet"] = "Testnet";
|
|
@@ -85,22 +23,22 @@ var SparkNetworkType = /* @__PURE__ */ ((SparkNetworkType2) => {
|
|
|
85
23
|
SparkNetworkType2["Regtest"] = "regtest";
|
|
86
24
|
return SparkNetworkType2;
|
|
87
25
|
})(SparkNetworkType || {});
|
|
88
|
-
var RpcIdSchema =
|
|
89
|
-
var rpcRequestMessageSchema =
|
|
90
|
-
jsonrpc:
|
|
91
|
-
method:
|
|
92
|
-
params:
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
26
|
+
var RpcIdSchema = v.optional(v.union([v.string(), v.number(), v.null()]));
|
|
27
|
+
var rpcRequestMessageSchema = v.object({
|
|
28
|
+
jsonrpc: v.literal("2.0"),
|
|
29
|
+
method: v.string(),
|
|
30
|
+
params: v.optional(
|
|
31
|
+
v.union([
|
|
32
|
+
v.array(v.unknown()),
|
|
33
|
+
v.looseObject({}),
|
|
96
34
|
// Note: This is to support current incorrect usage of RPC 2.0. Params need
|
|
97
35
|
// to be either an array or an object when provided. Changing this now would
|
|
98
36
|
// be a breaking change, so accepting null values for now. Tracking in
|
|
99
37
|
// https://linear.app/xverseapp/issue/ENG-4538.
|
|
100
|
-
|
|
38
|
+
v.null()
|
|
101
39
|
])
|
|
102
40
|
),
|
|
103
|
-
id:
|
|
41
|
+
id: v.unwrap(RpcIdSchema)
|
|
104
42
|
});
|
|
105
43
|
var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
|
|
106
44
|
RpcErrorCode2[RpcErrorCode2["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
|
|
@@ -113,180 +51,701 @@ var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
|
|
|
113
51
|
RpcErrorCode2[RpcErrorCode2["ACCESS_DENIED"] = -32002] = "ACCESS_DENIED";
|
|
114
52
|
return RpcErrorCode2;
|
|
115
53
|
})(RpcErrorCode || {});
|
|
116
|
-
var rpcSuccessResponseMessageSchema =
|
|
117
|
-
jsonrpc:
|
|
118
|
-
result:
|
|
54
|
+
var rpcSuccessResponseMessageSchema = v.object({
|
|
55
|
+
jsonrpc: v.literal("2.0"),
|
|
56
|
+
result: v.nonOptional(v.unknown()),
|
|
119
57
|
id: RpcIdSchema
|
|
120
58
|
});
|
|
121
|
-
var rpcErrorResponseMessageSchema =
|
|
122
|
-
jsonrpc:
|
|
123
|
-
error:
|
|
59
|
+
var rpcErrorResponseMessageSchema = v.object({
|
|
60
|
+
jsonrpc: v.literal("2.0"),
|
|
61
|
+
error: v.nonOptional(v.unknown()),
|
|
124
62
|
id: RpcIdSchema
|
|
125
63
|
});
|
|
126
|
-
var rpcResponseMessageSchema =
|
|
64
|
+
var rpcResponseMessageSchema = v.union([
|
|
127
65
|
rpcSuccessResponseMessageSchema,
|
|
128
66
|
rpcErrorResponseMessageSchema
|
|
129
67
|
]);
|
|
130
68
|
|
|
131
|
-
// src/
|
|
132
|
-
|
|
133
|
-
var
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}),
|
|
143
|
-
stacks: v4.object({
|
|
144
|
-
name: v4.string()
|
|
145
|
-
}),
|
|
146
|
-
addresses: v4.optional(v4.array(addressSchema))
|
|
147
|
-
});
|
|
148
|
-
var disconnectEventName = "disconnect";
|
|
149
|
-
var disconnectSchema = v4.object({
|
|
150
|
-
type: v4.literal(disconnectEventName)
|
|
151
|
-
});
|
|
152
|
-
var walletEventSchema = v4.variant("type", [
|
|
153
|
-
accountChangeSchema,
|
|
154
|
-
networkChangeSchema,
|
|
155
|
-
disconnectSchema
|
|
156
|
-
]);
|
|
157
|
-
|
|
158
|
-
// src/provider/index.ts
|
|
159
|
-
async function getProviderOrThrow(getProvider) {
|
|
160
|
-
const provider = await getProvider?.() || window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
|
|
161
|
-
if (!provider) {
|
|
162
|
-
throw new Error("No Bitcoin wallet installed");
|
|
69
|
+
// src/runes/api.ts
|
|
70
|
+
import axios from "axios";
|
|
71
|
+
var urlNetworkSuffix = {
|
|
72
|
+
["Mainnet" /* Mainnet */]: "",
|
|
73
|
+
["Testnet" /* Testnet */]: "-testnet",
|
|
74
|
+
["Testnet4" /* Testnet4 */]: "-testnet4",
|
|
75
|
+
["Signet" /* Signet */]: "-signet"
|
|
76
|
+
};
|
|
77
|
+
var ORDINALS_API_BASE_URL = (network = "Mainnet" /* Mainnet */) => {
|
|
78
|
+
if (network === "Regtest" /* Regtest */) {
|
|
79
|
+
throw new Error(`Ordinals API does not support ${network} network`);
|
|
163
80
|
}
|
|
164
|
-
return
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
function getSupportedWallets() {
|
|
186
|
-
const wallets = Object.values(DefaultAdaptersInfo).map((provider) => {
|
|
187
|
-
{
|
|
81
|
+
return `https://ordinals${urlNetworkSuffix[network]}.xverse.app/v1`;
|
|
82
|
+
};
|
|
83
|
+
var RunesApi = class {
|
|
84
|
+
client;
|
|
85
|
+
constructor(network) {
|
|
86
|
+
this.client = axios.create({
|
|
87
|
+
baseURL: ORDINALS_API_BASE_URL(network)
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
parseError = (error) => {
|
|
91
|
+
return {
|
|
92
|
+
code: error.response?.status,
|
|
93
|
+
message: JSON.stringify(error.response?.data)
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
estimateMintCost = async (mintParams) => {
|
|
97
|
+
try {
|
|
98
|
+
const response = await this.client.post("/runes/mint/estimate", {
|
|
99
|
+
...mintParams
|
|
100
|
+
});
|
|
188
101
|
return {
|
|
189
|
-
|
|
190
|
-
|
|
102
|
+
data: response.data
|
|
103
|
+
};
|
|
104
|
+
} catch (error) {
|
|
105
|
+
const err = error;
|
|
106
|
+
return {
|
|
107
|
+
error: this.parseError(err)
|
|
191
108
|
};
|
|
192
109
|
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const filterPurposes = (purposes) => purposes?.filter(
|
|
208
|
-
(purpose) => purpose !== "spark" /* Spark */ && purpose !== "starknet" /* Starknet */
|
|
209
|
-
);
|
|
210
|
-
if (method === "wallet_connect") {
|
|
211
|
-
const typedParams = params;
|
|
212
|
-
if (!typedParams) {
|
|
213
|
-
return { method, params };
|
|
110
|
+
};
|
|
111
|
+
estimateEtchCost = async (etchParams) => {
|
|
112
|
+
try {
|
|
113
|
+
const response = await this.client.post("/runes/etch/estimate", {
|
|
114
|
+
...etchParams
|
|
115
|
+
});
|
|
116
|
+
return {
|
|
117
|
+
data: response.data
|
|
118
|
+
};
|
|
119
|
+
} catch (error) {
|
|
120
|
+
const err = error;
|
|
121
|
+
return {
|
|
122
|
+
error: this.parseError(err)
|
|
123
|
+
};
|
|
214
124
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
125
|
+
};
|
|
126
|
+
createMintOrder = async (mintOrderParams) => {
|
|
127
|
+
try {
|
|
128
|
+
const response = await this.client.post("/runes/mint/orders", {
|
|
129
|
+
...mintOrderParams
|
|
130
|
+
});
|
|
131
|
+
return {
|
|
132
|
+
data: response.data
|
|
133
|
+
};
|
|
134
|
+
} catch (error) {
|
|
135
|
+
const err = error;
|
|
136
|
+
return {
|
|
137
|
+
error: this.parseError(err)
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
createEtchOrder = async (etchOrderParams) => {
|
|
142
|
+
try {
|
|
143
|
+
const response = await this.client.post("/runes/etch/orders", {
|
|
144
|
+
...etchOrderParams
|
|
145
|
+
});
|
|
146
|
+
return {
|
|
147
|
+
data: response.data
|
|
148
|
+
};
|
|
149
|
+
} catch (error) {
|
|
150
|
+
const err = error;
|
|
151
|
+
return {
|
|
152
|
+
error: this.parseError(err)
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
executeMint = async (orderId, fundTransactionId) => {
|
|
157
|
+
try {
|
|
158
|
+
const response = await this.client.post(`/runes/mint/orders/${orderId}/execute`, {
|
|
159
|
+
fundTransactionId
|
|
160
|
+
});
|
|
161
|
+
return {
|
|
162
|
+
data: response.data
|
|
163
|
+
};
|
|
164
|
+
} catch (error) {
|
|
165
|
+
const err = error;
|
|
166
|
+
return {
|
|
167
|
+
error: this.parseError(err)
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
executeEtch = async (orderId, fundTransactionId) => {
|
|
172
|
+
try {
|
|
173
|
+
const response = await this.client.post(`/runes/etch/orders/${orderId}/execute`, {
|
|
174
|
+
fundTransactionId
|
|
175
|
+
});
|
|
176
|
+
return {
|
|
177
|
+
data: response.data
|
|
178
|
+
};
|
|
179
|
+
} catch (error) {
|
|
180
|
+
const err = error;
|
|
181
|
+
return {
|
|
182
|
+
error: this.parseError(err)
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
getOrder = async (orderId) => {
|
|
187
|
+
try {
|
|
188
|
+
const response = await this.client.get(`/orders/${orderId}`);
|
|
189
|
+
return {
|
|
190
|
+
data: response.data
|
|
191
|
+
};
|
|
192
|
+
} catch (error) {
|
|
193
|
+
const err = error;
|
|
194
|
+
return {
|
|
195
|
+
error: this.parseError(err)
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
rbfOrder = async (rbfRequest) => {
|
|
200
|
+
const { orderId, newFeeRate } = rbfRequest;
|
|
201
|
+
try {
|
|
202
|
+
const response = await this.client.post(`/orders/${orderId}/rbf-estimate`, {
|
|
203
|
+
newFeeRate
|
|
204
|
+
});
|
|
205
|
+
return {
|
|
206
|
+
data: response.data
|
|
207
|
+
};
|
|
208
|
+
} catch (error) {
|
|
209
|
+
const err = error;
|
|
210
|
+
return {
|
|
211
|
+
error: this.parseError(err)
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
var clients = {};
|
|
217
|
+
var getRunesApiClient = (network = "Mainnet" /* Mainnet */) => {
|
|
218
|
+
if (!clients[network]) {
|
|
219
|
+
clients[network] = new RunesApi(network);
|
|
220
|
+
}
|
|
221
|
+
return clients[network];
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
// src/adapters/satsConnectAdapter.ts
|
|
225
|
+
var SatsConnectAdapter = class {
|
|
226
|
+
async mintRunes(params) {
|
|
227
|
+
try {
|
|
228
|
+
const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
|
|
229
|
+
if (walletInfo && walletInfo.status === "success") {
|
|
230
|
+
const isMintSupported = walletInfo.result.methods?.includes("runes_mint");
|
|
231
|
+
if (isMintSupported) {
|
|
232
|
+
const response = await this.requestInternal("runes_mint", params);
|
|
233
|
+
if (response) {
|
|
234
|
+
if (response.status === "success") {
|
|
235
|
+
return response;
|
|
236
|
+
}
|
|
237
|
+
if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
|
|
238
|
+
return response;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const mintRequest = {
|
|
244
|
+
destinationAddress: params.destinationAddress,
|
|
245
|
+
feeRate: params.feeRate,
|
|
246
|
+
refundAddress: params.refundAddress,
|
|
247
|
+
repeats: params.repeats,
|
|
248
|
+
runeName: params.runeName,
|
|
249
|
+
appServiceFee: params.appServiceFee,
|
|
250
|
+
appServiceFeeAddress: params.appServiceFeeAddress
|
|
251
|
+
};
|
|
252
|
+
const orderResponse = await new RunesApi(params.network).createMintOrder(mintRequest);
|
|
253
|
+
if (!orderResponse.data) {
|
|
254
|
+
return {
|
|
255
|
+
status: "error",
|
|
256
|
+
error: {
|
|
257
|
+
code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
258
|
+
message: orderResponse.error.message
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
const paymentResponse = await this.requestInternal("sendTransfer", {
|
|
263
|
+
recipients: [
|
|
264
|
+
{
|
|
265
|
+
address: orderResponse.data.fundAddress,
|
|
266
|
+
amount: orderResponse.data.fundAmount
|
|
267
|
+
}
|
|
268
|
+
]
|
|
269
|
+
});
|
|
270
|
+
if (paymentResponse.status !== "success") {
|
|
271
|
+
return paymentResponse;
|
|
272
|
+
}
|
|
273
|
+
await new RunesApi(params.network).executeMint(
|
|
274
|
+
orderResponse.data.orderId,
|
|
275
|
+
paymentResponse.result.txid
|
|
276
|
+
);
|
|
277
|
+
return {
|
|
278
|
+
status: "success",
|
|
279
|
+
result: {
|
|
280
|
+
orderId: orderResponse.data.orderId,
|
|
281
|
+
fundTransactionId: paymentResponse.result.txid,
|
|
282
|
+
fundingAddress: orderResponse.data.fundAddress
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
} catch (error) {
|
|
286
|
+
return {
|
|
287
|
+
status: "error",
|
|
288
|
+
error: {
|
|
289
|
+
code: -32603 /* INTERNAL_ERROR */,
|
|
290
|
+
message: error.message
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
async etchRunes(params) {
|
|
296
|
+
const etchRequest = {
|
|
297
|
+
destinationAddress: params.destinationAddress,
|
|
298
|
+
refundAddress: params.refundAddress,
|
|
299
|
+
feeRate: params.feeRate,
|
|
300
|
+
runeName: params.runeName,
|
|
301
|
+
divisibility: params.divisibility,
|
|
302
|
+
symbol: params.symbol,
|
|
303
|
+
premine: params.premine,
|
|
304
|
+
isMintable: params.isMintable,
|
|
305
|
+
terms: params.terms,
|
|
306
|
+
inscriptionDetails: params.inscriptionDetails,
|
|
307
|
+
delegateInscriptionId: params.delegateInscriptionId,
|
|
308
|
+
appServiceFee: params.appServiceFee,
|
|
309
|
+
appServiceFeeAddress: params.appServiceFeeAddress
|
|
310
|
+
};
|
|
311
|
+
try {
|
|
312
|
+
const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
|
|
313
|
+
if (walletInfo && walletInfo.status === "success") {
|
|
314
|
+
const isEtchSupported = walletInfo.result.methods?.includes("runes_etch");
|
|
315
|
+
if (isEtchSupported) {
|
|
316
|
+
const response = await this.requestInternal("runes_etch", params);
|
|
317
|
+
if (response) {
|
|
318
|
+
if (response.status === "success") {
|
|
319
|
+
return response;
|
|
320
|
+
}
|
|
321
|
+
if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
|
|
322
|
+
return response;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
const orderResponse = await new RunesApi(params.network).createEtchOrder(etchRequest);
|
|
328
|
+
if (!orderResponse.data) {
|
|
329
|
+
return {
|
|
330
|
+
status: "error",
|
|
331
|
+
error: {
|
|
332
|
+
code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
333
|
+
message: orderResponse.error.message
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
const paymentResponse = await this.requestInternal("sendTransfer", {
|
|
338
|
+
recipients: [
|
|
339
|
+
{
|
|
340
|
+
address: orderResponse.data.fundAddress,
|
|
341
|
+
amount: orderResponse.data.fundAmount
|
|
342
|
+
}
|
|
343
|
+
]
|
|
344
|
+
});
|
|
345
|
+
if (paymentResponse.status !== "success") {
|
|
346
|
+
return paymentResponse;
|
|
347
|
+
}
|
|
348
|
+
await new RunesApi(params.network).executeEtch(
|
|
349
|
+
orderResponse.data.orderId,
|
|
350
|
+
paymentResponse.result.txid
|
|
351
|
+
);
|
|
352
|
+
return {
|
|
353
|
+
status: "success",
|
|
354
|
+
result: {
|
|
355
|
+
orderId: orderResponse.data.orderId,
|
|
356
|
+
fundTransactionId: paymentResponse.result.txid,
|
|
357
|
+
fundingAddress: orderResponse.data.fundAddress
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
} catch (error) {
|
|
361
|
+
return {
|
|
362
|
+
status: "error",
|
|
363
|
+
error: {
|
|
364
|
+
code: -32603 /* INTERNAL_ERROR */,
|
|
365
|
+
message: error.message
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
async estimateMint(params) {
|
|
371
|
+
const estimateMintRequest = {
|
|
372
|
+
destinationAddress: params.destinationAddress,
|
|
373
|
+
feeRate: params.feeRate,
|
|
374
|
+
repeats: params.repeats,
|
|
375
|
+
runeName: params.runeName,
|
|
376
|
+
appServiceFee: params.appServiceFee,
|
|
377
|
+
appServiceFeeAddress: params.appServiceFeeAddress
|
|
378
|
+
};
|
|
379
|
+
const response = await getRunesApiClient(
|
|
380
|
+
params.network
|
|
381
|
+
).estimateMintCost(estimateMintRequest);
|
|
382
|
+
if (response.data) {
|
|
383
|
+
return {
|
|
384
|
+
status: "success",
|
|
385
|
+
result: response.data
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
return {
|
|
389
|
+
status: "error",
|
|
390
|
+
error: {
|
|
391
|
+
code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
392
|
+
message: response.error.message
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
async estimateEtch(params) {
|
|
397
|
+
const estimateEtchRequest = {
|
|
398
|
+
destinationAddress: params.destinationAddress,
|
|
399
|
+
feeRate: params.feeRate,
|
|
400
|
+
runeName: params.runeName,
|
|
401
|
+
divisibility: params.divisibility,
|
|
402
|
+
symbol: params.symbol,
|
|
403
|
+
premine: params.premine,
|
|
404
|
+
isMintable: params.isMintable,
|
|
405
|
+
terms: params.terms,
|
|
406
|
+
inscriptionDetails: params.inscriptionDetails,
|
|
407
|
+
delegateInscriptionId: params.delegateInscriptionId,
|
|
408
|
+
appServiceFee: params.appServiceFee,
|
|
409
|
+
appServiceFeeAddress: params.appServiceFeeAddress
|
|
410
|
+
};
|
|
411
|
+
const response = await getRunesApiClient(params.network).estimateEtchCost(estimateEtchRequest);
|
|
412
|
+
if (response.data) {
|
|
413
|
+
return {
|
|
414
|
+
status: "success",
|
|
415
|
+
result: response.data
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
return {
|
|
419
|
+
status: "error",
|
|
420
|
+
error: {
|
|
421
|
+
code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
422
|
+
message: response.error.message
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
async getOrder(params) {
|
|
427
|
+
const response = await getRunesApiClient(params.network).getOrder(params.id);
|
|
428
|
+
if (response.data) {
|
|
429
|
+
return {
|
|
430
|
+
status: "success",
|
|
431
|
+
result: response.data
|
|
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 estimateRbfOrder(params) {
|
|
443
|
+
const rbfOrderRequest = {
|
|
444
|
+
newFeeRate: params.newFeeRate,
|
|
445
|
+
orderId: params.orderId
|
|
446
|
+
};
|
|
447
|
+
const response = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
|
|
448
|
+
if (response.data) {
|
|
449
|
+
return {
|
|
450
|
+
status: "success",
|
|
451
|
+
result: {
|
|
452
|
+
fundingAddress: response.data.fundingAddress,
|
|
453
|
+
rbfCost: response.data.rbfCost
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
return {
|
|
458
|
+
status: "error",
|
|
459
|
+
error: {
|
|
460
|
+
code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
461
|
+
message: response.error.message
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
async rbfOrder(params) {
|
|
466
|
+
try {
|
|
467
|
+
const rbfOrderRequest = {
|
|
468
|
+
newFeeRate: params.newFeeRate,
|
|
469
|
+
orderId: params.orderId
|
|
470
|
+
};
|
|
471
|
+
const orderResponse = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
|
|
472
|
+
if (!orderResponse.data) {
|
|
473
|
+
return {
|
|
474
|
+
status: "error",
|
|
475
|
+
error: {
|
|
476
|
+
code: orderResponse.error.code === 400 || orderResponse.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
477
|
+
message: orderResponse.error.message
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
const paymentResponse = await this.requestInternal("sendTransfer", {
|
|
482
|
+
recipients: [
|
|
483
|
+
{
|
|
484
|
+
address: orderResponse.data.fundingAddress,
|
|
485
|
+
amount: orderResponse.data.rbfCost
|
|
486
|
+
}
|
|
487
|
+
]
|
|
488
|
+
});
|
|
489
|
+
if (paymentResponse.status !== "success") {
|
|
490
|
+
return paymentResponse;
|
|
491
|
+
}
|
|
492
|
+
return {
|
|
493
|
+
status: "success",
|
|
494
|
+
result: {
|
|
495
|
+
fundingAddress: orderResponse.data.fundingAddress,
|
|
496
|
+
orderId: rbfOrderRequest.orderId,
|
|
497
|
+
fundRBFTransactionId: paymentResponse.result.txid
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
} catch (error) {
|
|
501
|
+
return {
|
|
502
|
+
status: "error",
|
|
503
|
+
error: {
|
|
504
|
+
code: -32603 /* INTERNAL_ERROR */,
|
|
505
|
+
message: error.message
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
async request(method, params) {
|
|
511
|
+
switch (method) {
|
|
512
|
+
case "runes_mint":
|
|
513
|
+
return this.mintRunes(params);
|
|
514
|
+
case "runes_etch":
|
|
515
|
+
return this.etchRunes(params);
|
|
516
|
+
case "runes_estimateMint":
|
|
517
|
+
return this.estimateMint(params);
|
|
518
|
+
case "runes_estimateEtch":
|
|
519
|
+
return this.estimateEtch(params);
|
|
520
|
+
case "runes_getOrder": {
|
|
521
|
+
return this.getOrder(params);
|
|
522
|
+
}
|
|
523
|
+
case "runes_estimateRbfOrder": {
|
|
524
|
+
return this.estimateRbfOrder(params);
|
|
525
|
+
}
|
|
526
|
+
case "runes_rbfOrder": {
|
|
527
|
+
return this.rbfOrder(params);
|
|
528
|
+
}
|
|
529
|
+
default:
|
|
530
|
+
return this.requestInternal(method, params);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
// src/provider/types.ts
|
|
536
|
+
import * as v4 from "valibot";
|
|
537
|
+
|
|
538
|
+
// src/addresses/index.ts
|
|
539
|
+
import { createUnsecuredToken } from "jsontokens";
|
|
540
|
+
|
|
541
|
+
// src/addresses/types.ts
|
|
542
|
+
import * as v3 from "valibot";
|
|
543
|
+
|
|
544
|
+
// src/request/types/common.ts
|
|
545
|
+
import * as v2 from "valibot";
|
|
546
|
+
var walletTypes = ["software", "ledger", "keystone"];
|
|
547
|
+
var walletTypeSchema = v2.picklist(walletTypes);
|
|
548
|
+
|
|
549
|
+
// src/addresses/types.ts
|
|
550
|
+
var AddressPurpose = /* @__PURE__ */ ((AddressPurpose2) => {
|
|
551
|
+
AddressPurpose2["Ordinals"] = "ordinals";
|
|
552
|
+
AddressPurpose2["Payment"] = "payment";
|
|
553
|
+
AddressPurpose2["Stacks"] = "stacks";
|
|
554
|
+
AddressPurpose2["Starknet"] = "starknet";
|
|
555
|
+
AddressPurpose2["Spark"] = "spark";
|
|
556
|
+
return AddressPurpose2;
|
|
557
|
+
})(AddressPurpose || {});
|
|
558
|
+
var AddressType = /* @__PURE__ */ ((AddressType3) => {
|
|
559
|
+
AddressType3["p2pkh"] = "p2pkh";
|
|
560
|
+
AddressType3["p2sh"] = "p2sh";
|
|
561
|
+
AddressType3["p2wpkh"] = "p2wpkh";
|
|
562
|
+
AddressType3["p2wsh"] = "p2wsh";
|
|
563
|
+
AddressType3["p2tr"] = "p2tr";
|
|
564
|
+
AddressType3["stacks"] = "stacks";
|
|
565
|
+
AddressType3["starknet"] = "starknet";
|
|
566
|
+
AddressType3["spark"] = "spark";
|
|
567
|
+
return AddressType3;
|
|
568
|
+
})(AddressType || {});
|
|
569
|
+
var addressSchema = v3.object({
|
|
570
|
+
address: v3.string(),
|
|
571
|
+
publicKey: v3.string(),
|
|
572
|
+
purpose: v3.enum(AddressPurpose),
|
|
573
|
+
addressType: v3.enum(AddressType),
|
|
574
|
+
walletType: walletTypeSchema
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
// src/addresses/index.ts
|
|
578
|
+
var getAddress = async (options) => {
|
|
579
|
+
const provider = await getProviderOrThrow(options.getProvider);
|
|
580
|
+
const { purposes } = options.payload;
|
|
581
|
+
if (!purposes) {
|
|
582
|
+
throw new Error("Address purposes are required");
|
|
583
|
+
}
|
|
584
|
+
try {
|
|
585
|
+
const request2 = createUnsecuredToken(options.payload);
|
|
586
|
+
const response = await provider.connect(request2);
|
|
587
|
+
options.onFinish?.(response);
|
|
588
|
+
} catch (error) {
|
|
589
|
+
console.error("[Connect] Error during address request", error);
|
|
590
|
+
options.onCancel?.();
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
// src/provider/types.ts
|
|
595
|
+
var accountChangeEventName = "accountChange";
|
|
596
|
+
var accountChangeSchema = v4.object({
|
|
597
|
+
type: v4.literal(accountChangeEventName),
|
|
598
|
+
addresses: v4.optional(v4.array(addressSchema))
|
|
599
|
+
});
|
|
600
|
+
var networkChangeEventName = "networkChange";
|
|
601
|
+
var networkChangeSchema = v4.object({
|
|
602
|
+
type: v4.literal(networkChangeEventName),
|
|
603
|
+
bitcoin: v4.object({
|
|
604
|
+
name: v4.enum(BitcoinNetworkType)
|
|
605
|
+
}),
|
|
606
|
+
stacks: v4.object({
|
|
607
|
+
name: v4.string()
|
|
608
|
+
}),
|
|
609
|
+
addresses: v4.optional(v4.array(addressSchema))
|
|
610
|
+
});
|
|
611
|
+
var disconnectEventName = "disconnect";
|
|
612
|
+
var disconnectSchema = v4.object({
|
|
613
|
+
type: v4.literal(disconnectEventName)
|
|
614
|
+
});
|
|
615
|
+
var walletEventSchema = v4.variant("type", [
|
|
616
|
+
accountChangeSchema,
|
|
617
|
+
networkChangeSchema,
|
|
618
|
+
disconnectSchema
|
|
619
|
+
]);
|
|
620
|
+
|
|
621
|
+
// src/provider/index.ts
|
|
622
|
+
async function getProviderOrThrow(getProvider) {
|
|
623
|
+
const provider = await getProvider?.() || window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
|
|
624
|
+
if (!provider) {
|
|
625
|
+
throw new Error("No Bitcoin wallet installed");
|
|
626
|
+
}
|
|
627
|
+
return provider;
|
|
628
|
+
}
|
|
629
|
+
function getProviders() {
|
|
630
|
+
if (!window.btc_providers) window.btc_providers = [];
|
|
631
|
+
return window.btc_providers;
|
|
632
|
+
}
|
|
633
|
+
function getProviderById(providerId) {
|
|
634
|
+
return providerId?.split(".").reduce((acc, part) => acc?.[part], window);
|
|
635
|
+
}
|
|
636
|
+
function isProviderInstalled(providerId) {
|
|
637
|
+
return !!getProviderById(providerId);
|
|
638
|
+
}
|
|
639
|
+
function setDefaultProvider(providerId) {
|
|
640
|
+
localStorage.setItem("sats-connect_defaultProvider", providerId);
|
|
641
|
+
}
|
|
642
|
+
function getDefaultProvider() {
|
|
643
|
+
return localStorage.getItem("sats-connect_defaultProvider");
|
|
644
|
+
}
|
|
645
|
+
function removeDefaultProvider() {
|
|
646
|
+
localStorage.removeItem("sats-connect_defaultProvider");
|
|
647
|
+
}
|
|
648
|
+
function getSupportedWallets() {
|
|
649
|
+
const wallets = Object.values(DefaultAdaptersInfo).map((provider) => {
|
|
650
|
+
{
|
|
651
|
+
return {
|
|
652
|
+
...provider,
|
|
653
|
+
isInstalled: isProviderInstalled(provider.id)
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
return wallets;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
// src/adapters/fordefi.ts
|
|
661
|
+
var FordefiAdapter = class extends SatsConnectAdapter {
|
|
662
|
+
id = DefaultAdaptersInfo.fordefi.id;
|
|
663
|
+
requestInternal = async (method, params) => {
|
|
664
|
+
const provider = getProviderById(this.id);
|
|
665
|
+
if (!provider) {
|
|
666
|
+
throw new Error("no wallet provider was found");
|
|
667
|
+
}
|
|
668
|
+
if (!method) {
|
|
669
|
+
throw new Error("A wallet method is required");
|
|
670
|
+
}
|
|
671
|
+
return await provider.request(method, params);
|
|
672
|
+
};
|
|
673
|
+
addListener = ({ eventName, cb }) => {
|
|
674
|
+
const provider = getProviderById(this.id);
|
|
675
|
+
if (!provider) {
|
|
676
|
+
throw new Error("no wallet provider was found");
|
|
677
|
+
}
|
|
678
|
+
if (!provider.addListener) {
|
|
679
|
+
console.error(
|
|
680
|
+
`The wallet provider you are using does not support the addListener method. Please update your wallet provider.`
|
|
681
|
+
);
|
|
682
|
+
return () => {
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
return provider.addListener(eventName, cb);
|
|
686
|
+
};
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
// src/adapters/unisat.ts
|
|
690
|
+
import { AddressType as AddressType2, getAddressInfo } from "bitcoin-address-validation";
|
|
691
|
+
import { Buffer } from "buffer";
|
|
692
|
+
|
|
693
|
+
// src/request/index.ts
|
|
694
|
+
import * as v25 from "valibot";
|
|
695
|
+
|
|
696
|
+
// src/request/types/btcMethods.ts
|
|
697
|
+
import * as v6 from "valibot";
|
|
698
|
+
|
|
699
|
+
// src/request/types/walletMethods.ts
|
|
700
|
+
import * as v5 from "valibot";
|
|
701
|
+
var accountActionsSchema = v5.object({
|
|
702
|
+
read: v5.optional(v5.boolean())
|
|
703
|
+
});
|
|
704
|
+
var walletActionsSchema = v5.object({
|
|
705
|
+
readNetwork: v5.optional(v5.boolean())
|
|
706
|
+
});
|
|
707
|
+
var accountPermissionSchema = v5.object({
|
|
708
|
+
type: v5.literal("account"),
|
|
709
|
+
resourceId: v5.string(),
|
|
710
|
+
clientId: v5.string(),
|
|
711
|
+
actions: accountActionsSchema
|
|
712
|
+
});
|
|
713
|
+
var walletPermissionSchema = v5.object({
|
|
714
|
+
type: v5.literal("wallet"),
|
|
715
|
+
resourceId: v5.string(),
|
|
716
|
+
clientId: v5.string(),
|
|
717
|
+
actions: walletActionsSchema
|
|
718
|
+
});
|
|
719
|
+
var PermissionRequestParams = v5.variant("type", [
|
|
720
|
+
v5.object({
|
|
721
|
+
...v5.omit(accountPermissionSchema, ["clientId"]).entries
|
|
722
|
+
}),
|
|
723
|
+
v5.object({
|
|
724
|
+
...v5.omit(walletPermissionSchema, ["clientId"]).entries
|
|
725
|
+
})
|
|
726
|
+
]);
|
|
727
|
+
var permission = v5.variant("type", [accountPermissionSchema, walletPermissionSchema]);
|
|
728
|
+
var requestPermissionsMethodName = "wallet_requestPermissions";
|
|
729
|
+
var requestPermissionsParamsSchema = v5.nullish(v5.array(PermissionRequestParams));
|
|
730
|
+
var requestPermissionsResultSchema = v5.literal(true);
|
|
731
|
+
var requestPermissionsRequestMessageSchema = v5.object({
|
|
732
|
+
...rpcRequestMessageSchema.entries,
|
|
733
|
+
...v5.object({
|
|
734
|
+
method: v5.literal(requestPermissionsMethodName),
|
|
735
|
+
params: requestPermissionsParamsSchema,
|
|
736
|
+
id: v5.string()
|
|
737
|
+
}).entries
|
|
738
|
+
});
|
|
739
|
+
var renouncePermissionsMethodName = "wallet_renouncePermissions";
|
|
740
|
+
var renouncePermissionsParamsSchema = v5.nullish(v5.null());
|
|
741
|
+
var renouncePermissionsResultSchema = v5.nullish(v5.null());
|
|
742
|
+
var renouncePermissionsRequestMessageSchema = v5.object({
|
|
743
|
+
...rpcRequestMessageSchema.entries,
|
|
744
|
+
...v5.object({
|
|
745
|
+
method: v5.literal(renouncePermissionsMethodName),
|
|
746
|
+
params: renouncePermissionsParamsSchema,
|
|
747
|
+
id: v5.string()
|
|
748
|
+
}).entries
|
|
290
749
|
});
|
|
291
750
|
var disconnectMethodName = "wallet_disconnect";
|
|
292
751
|
var disconnectParamsSchema = v5.nullish(v5.null());
|
|
@@ -451,6 +910,11 @@ var addNetworkResultSchema = v5.object({
|
|
|
451
910
|
});
|
|
452
911
|
|
|
453
912
|
// src/request/types/btcMethods.ts
|
|
913
|
+
var ProviderPlatform = /* @__PURE__ */ ((ProviderPlatform2) => {
|
|
914
|
+
ProviderPlatform2["Web"] = "web";
|
|
915
|
+
ProviderPlatform2["Mobile"] = "mobile";
|
|
916
|
+
return ProviderPlatform2;
|
|
917
|
+
})(ProviderPlatform || {});
|
|
454
918
|
var getInfoMethodName = "getInfo";
|
|
455
919
|
var getInfoParamsSchema = v6.nullish(v6.null());
|
|
456
920
|
var getInfoResultSchema = v6.object({
|
|
@@ -458,6 +922,10 @@ var getInfoResultSchema = v6.object({
|
|
|
458
922
|
* Version of the wallet.
|
|
459
923
|
*/
|
|
460
924
|
version: v6.string(),
|
|
925
|
+
/**
|
|
926
|
+
* The platform the wallet is running on (web or mobile).
|
|
927
|
+
*/
|
|
928
|
+
platform: v6.optional(v6.enum(ProviderPlatform)),
|
|
461
929
|
/**
|
|
462
930
|
* [WBIP](https://wbips.netlify.app/wbips/WBIP002) methods supported by the wallet.
|
|
463
931
|
*/
|
|
@@ -1242,669 +1710,181 @@ var stxSignTransactionsParamsSchema = v23.object({
|
|
|
1242
1710
|
v23.minLength(1)
|
|
1243
1711
|
),
|
|
1244
1712
|
/**
|
|
1245
|
-
* Whether the signed transactions should be broadcast after signing. Defaults
|
|
1246
|
-
* to `true`.
|
|
1247
|
-
*/
|
|
1248
|
-
broadcast: v23.optional(v23.boolean())
|
|
1249
|
-
});
|
|
1250
|
-
var stxSignTransactionsResultSchema = v23.object({
|
|
1251
|
-
/**
|
|
1252
|
-
* The signed transactions as hex-encoded strings, in the same order as in the
|
|
1253
|
-
* sign request.
|
|
1254
|
-
*/
|
|
1255
|
-
transactions: v23.array(v23.string())
|
|
1256
|
-
});
|
|
1257
|
-
var stxSignTransactionsRequestMessageSchema = v23.object({
|
|
1258
|
-
...rpcRequestMessageSchema.entries,
|
|
1259
|
-
...v23.object({
|
|
1260
|
-
method: v23.literal(stxSignTransactionsMethodName),
|
|
1261
|
-
params: stxSignTransactionsParamsSchema,
|
|
1262
|
-
id: v23.string()
|
|
1263
|
-
}).entries
|
|
1264
|
-
});
|
|
1265
|
-
|
|
1266
|
-
// src/request/types/stxMethods/transferStx.ts
|
|
1267
|
-
import * as v24 from "valibot";
|
|
1268
|
-
var stxTransferStxMethodName = "stx_transferStx";
|
|
1269
|
-
var stxTransferStxParamsSchema = v24.object({
|
|
1270
|
-
/**
|
|
1271
|
-
* Amount of STX tokens to transfer in microstacks as a string. Anything
|
|
1272
|
-
* parseable by `BigInt` is acceptable.
|
|
1273
|
-
*
|
|
1274
|
-
* Example,
|
|
1275
|
-
*
|
|
1276
|
-
* ```js
|
|
1277
|
-
* const amount1 = 1234;
|
|
1278
|
-
* const amount2 = 1234n;
|
|
1279
|
-
* const amount3 = '1234';
|
|
1280
|
-
* ```
|
|
1281
|
-
*/
|
|
1282
|
-
amount: v24.union([v24.number(), v24.string()]),
|
|
1283
|
-
/**
|
|
1284
|
-
* The recipient's principal.
|
|
1285
|
-
*/
|
|
1286
|
-
recipient: v24.string(),
|
|
1287
|
-
/**
|
|
1288
|
-
* A string representing the memo.
|
|
1289
|
-
*/
|
|
1290
|
-
memo: v24.optional(v24.string()),
|
|
1291
|
-
/**
|
|
1292
|
-
* Version of parameter format.
|
|
1293
|
-
*/
|
|
1294
|
-
version: v24.optional(v24.string()),
|
|
1295
|
-
/**
|
|
1296
|
-
* The mode of the post conditions.
|
|
1297
|
-
*/
|
|
1298
|
-
postConditionMode: v24.optional(v24.number()),
|
|
1299
|
-
/**
|
|
1300
|
-
* A hex-encoded string representing the post conditions.
|
|
1301
|
-
*
|
|
1302
|
-
* A post condition may be converted to it's hex representation using the `serializePostCondition` helper from the `@stacks/transactions` package,
|
|
1303
|
-
*
|
|
1304
|
-
* ```js
|
|
1305
|
-
* import { serializePostCondition } from '@stacks/transactions';
|
|
1306
|
-
*
|
|
1307
|
-
* const postCondition = somePostCondition;
|
|
1308
|
-
* const hexPostCondition = serializePostCondition(postCondition).toString('hex');
|
|
1309
|
-
* ```
|
|
1310
|
-
*/
|
|
1311
|
-
postConditions: v24.optional(v24.array(v24.string())),
|
|
1312
|
-
/**
|
|
1313
|
-
* The public key to sign the transaction with. The wallet may use any key
|
|
1314
|
-
* when not provided.
|
|
1315
|
-
*/
|
|
1316
|
-
pubkey: v24.optional(v24.string())
|
|
1317
|
-
});
|
|
1318
|
-
var stxTransferStxResultSchema = v24.object({
|
|
1319
|
-
/**
|
|
1320
|
-
* The ID of the transaction.
|
|
1321
|
-
*/
|
|
1322
|
-
txid: v24.string(),
|
|
1323
|
-
/**
|
|
1324
|
-
* A Stacks transaction as a hex-encoded string.
|
|
1713
|
+
* Whether the signed transactions should be broadcast after signing. Defaults
|
|
1714
|
+
* to `true`.
|
|
1325
1715
|
*/
|
|
1326
|
-
|
|
1327
|
-
});
|
|
1328
|
-
var
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1716
|
+
broadcast: v23.optional(v23.boolean())
|
|
1717
|
+
});
|
|
1718
|
+
var stxSignTransactionsResultSchema = v23.object({
|
|
1719
|
+
/**
|
|
1720
|
+
* The signed transactions as hex-encoded strings, in the same order as in the
|
|
1721
|
+
* sign request.
|
|
1722
|
+
*/
|
|
1723
|
+
transactions: v23.array(v23.string())
|
|
1724
|
+
});
|
|
1725
|
+
var stxSignTransactionsRequestMessageSchema = v23.object({
|
|
1726
|
+
...rpcRequestMessageSchema.entries,
|
|
1727
|
+
...v23.object({
|
|
1728
|
+
method: v23.literal(stxSignTransactionsMethodName),
|
|
1729
|
+
params: stxSignTransactionsParamsSchema,
|
|
1730
|
+
id: v23.string()
|
|
1731
|
+
}).entries
|
|
1335
1732
|
});
|
|
1336
1733
|
|
|
1337
|
-
// src/request/
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
provider = getProviderById(providerId);
|
|
1414
|
-
}
|
|
1415
|
-
if (!provider) {
|
|
1416
|
-
throw new Error("no wallet provider was found");
|
|
1417
|
-
}
|
|
1418
|
-
if (!provider.addListener) {
|
|
1419
|
-
console.error(
|
|
1420
|
-
`The wallet provider you are using does not support the addListener method. Please update your wallet provider.`
|
|
1421
|
-
);
|
|
1422
|
-
return () => {
|
|
1423
|
-
};
|
|
1424
|
-
}
|
|
1425
|
-
return provider.addListener(listenerInfo);
|
|
1426
|
-
};
|
|
1427
|
-
|
|
1428
|
-
// src/runes/api.ts
|
|
1429
|
-
import axios from "axios";
|
|
1430
|
-
var urlNetworkSuffix = {
|
|
1431
|
-
["Mainnet" /* Mainnet */]: "",
|
|
1432
|
-
["Testnet" /* Testnet */]: "-testnet",
|
|
1433
|
-
["Testnet4" /* Testnet4 */]: "-testnet4",
|
|
1434
|
-
["Signet" /* Signet */]: "-signet"
|
|
1435
|
-
};
|
|
1436
|
-
var ORDINALS_API_BASE_URL = (network = "Mainnet" /* Mainnet */) => {
|
|
1437
|
-
if (network === "Regtest" /* Regtest */) {
|
|
1438
|
-
throw new Error(`Ordinals API does not support ${network} network`);
|
|
1439
|
-
}
|
|
1440
|
-
return `https://ordinals${urlNetworkSuffix[network]}.xverse.app/v1`;
|
|
1441
|
-
};
|
|
1442
|
-
var RunesApi = class {
|
|
1443
|
-
client;
|
|
1444
|
-
constructor(network) {
|
|
1445
|
-
this.client = axios.create({
|
|
1446
|
-
baseURL: ORDINALS_API_BASE_URL(network)
|
|
1447
|
-
});
|
|
1448
|
-
}
|
|
1449
|
-
parseError = (error) => {
|
|
1450
|
-
return {
|
|
1451
|
-
code: error.response?.status,
|
|
1452
|
-
message: JSON.stringify(error.response?.data)
|
|
1453
|
-
};
|
|
1454
|
-
};
|
|
1455
|
-
estimateMintCost = async (mintParams) => {
|
|
1456
|
-
try {
|
|
1457
|
-
const response = await this.client.post("/runes/mint/estimate", {
|
|
1458
|
-
...mintParams
|
|
1459
|
-
});
|
|
1460
|
-
return {
|
|
1461
|
-
data: response.data
|
|
1462
|
-
};
|
|
1463
|
-
} catch (error) {
|
|
1464
|
-
const err = error;
|
|
1465
|
-
return {
|
|
1466
|
-
error: this.parseError(err)
|
|
1467
|
-
};
|
|
1468
|
-
}
|
|
1469
|
-
};
|
|
1470
|
-
estimateEtchCost = async (etchParams) => {
|
|
1471
|
-
try {
|
|
1472
|
-
const response = await this.client.post("/runes/etch/estimate", {
|
|
1473
|
-
...etchParams
|
|
1474
|
-
});
|
|
1475
|
-
return {
|
|
1476
|
-
data: response.data
|
|
1477
|
-
};
|
|
1478
|
-
} catch (error) {
|
|
1479
|
-
const err = error;
|
|
1480
|
-
return {
|
|
1481
|
-
error: this.parseError(err)
|
|
1482
|
-
};
|
|
1483
|
-
}
|
|
1484
|
-
};
|
|
1485
|
-
createMintOrder = async (mintOrderParams) => {
|
|
1486
|
-
try {
|
|
1487
|
-
const response = await this.client.post("/runes/mint/orders", {
|
|
1488
|
-
...mintOrderParams
|
|
1489
|
-
});
|
|
1490
|
-
return {
|
|
1491
|
-
data: response.data
|
|
1492
|
-
};
|
|
1493
|
-
} catch (error) {
|
|
1494
|
-
const err = error;
|
|
1495
|
-
return {
|
|
1496
|
-
error: this.parseError(err)
|
|
1497
|
-
};
|
|
1498
|
-
}
|
|
1499
|
-
};
|
|
1500
|
-
createEtchOrder = async (etchOrderParams) => {
|
|
1501
|
-
try {
|
|
1502
|
-
const response = await this.client.post("/runes/etch/orders", {
|
|
1503
|
-
...etchOrderParams
|
|
1504
|
-
});
|
|
1505
|
-
return {
|
|
1506
|
-
data: response.data
|
|
1507
|
-
};
|
|
1508
|
-
} catch (error) {
|
|
1509
|
-
const err = error;
|
|
1510
|
-
return {
|
|
1511
|
-
error: this.parseError(err)
|
|
1512
|
-
};
|
|
1513
|
-
}
|
|
1514
|
-
};
|
|
1515
|
-
executeMint = async (orderId, fundTransactionId) => {
|
|
1516
|
-
try {
|
|
1517
|
-
const response = await this.client.post(`/runes/mint/orders/${orderId}/execute`, {
|
|
1518
|
-
fundTransactionId
|
|
1519
|
-
});
|
|
1520
|
-
return {
|
|
1521
|
-
data: response.data
|
|
1522
|
-
};
|
|
1523
|
-
} catch (error) {
|
|
1524
|
-
const err = error;
|
|
1525
|
-
return {
|
|
1526
|
-
error: this.parseError(err)
|
|
1527
|
-
};
|
|
1528
|
-
}
|
|
1529
|
-
};
|
|
1530
|
-
executeEtch = async (orderId, fundTransactionId) => {
|
|
1531
|
-
try {
|
|
1532
|
-
const response = await this.client.post(`/runes/etch/orders/${orderId}/execute`, {
|
|
1533
|
-
fundTransactionId
|
|
1534
|
-
});
|
|
1535
|
-
return {
|
|
1536
|
-
data: response.data
|
|
1537
|
-
};
|
|
1538
|
-
} catch (error) {
|
|
1539
|
-
const err = error;
|
|
1540
|
-
return {
|
|
1541
|
-
error: this.parseError(err)
|
|
1542
|
-
};
|
|
1543
|
-
}
|
|
1544
|
-
};
|
|
1545
|
-
getOrder = async (orderId) => {
|
|
1546
|
-
try {
|
|
1547
|
-
const response = await this.client.get(`/orders/${orderId}`);
|
|
1548
|
-
return {
|
|
1549
|
-
data: response.data
|
|
1550
|
-
};
|
|
1551
|
-
} catch (error) {
|
|
1552
|
-
const err = error;
|
|
1553
|
-
return {
|
|
1554
|
-
error: this.parseError(err)
|
|
1555
|
-
};
|
|
1556
|
-
}
|
|
1557
|
-
};
|
|
1558
|
-
rbfOrder = async (rbfRequest) => {
|
|
1559
|
-
const { orderId, newFeeRate } = rbfRequest;
|
|
1560
|
-
try {
|
|
1561
|
-
const response = await this.client.post(`/orders/${orderId}/rbf-estimate`, {
|
|
1562
|
-
newFeeRate
|
|
1563
|
-
});
|
|
1564
|
-
return {
|
|
1565
|
-
data: response.data
|
|
1566
|
-
};
|
|
1567
|
-
} catch (error) {
|
|
1568
|
-
const err = error;
|
|
1569
|
-
return {
|
|
1570
|
-
error: this.parseError(err)
|
|
1571
|
-
};
|
|
1572
|
-
}
|
|
1573
|
-
};
|
|
1574
|
-
};
|
|
1575
|
-
var clients = {};
|
|
1576
|
-
var getRunesApiClient = (network = "Mainnet" /* Mainnet */) => {
|
|
1577
|
-
if (!clients[network]) {
|
|
1578
|
-
clients[network] = new RunesApi(network);
|
|
1579
|
-
}
|
|
1580
|
-
return clients[network];
|
|
1581
|
-
};
|
|
1582
|
-
|
|
1583
|
-
// src/adapters/satsConnectAdapter.ts
|
|
1584
|
-
var SatsConnectAdapter = class {
|
|
1585
|
-
async mintRunes(params) {
|
|
1586
|
-
try {
|
|
1587
|
-
const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
|
|
1588
|
-
if (walletInfo && walletInfo.status === "success") {
|
|
1589
|
-
const isMintSupported = walletInfo.result.methods?.includes("runes_mint");
|
|
1590
|
-
if (isMintSupported) {
|
|
1591
|
-
const response = await this.requestInternal("runes_mint", params);
|
|
1592
|
-
if (response) {
|
|
1593
|
-
if (response.status === "success") {
|
|
1594
|
-
return response;
|
|
1595
|
-
}
|
|
1596
|
-
if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
|
|
1597
|
-
return response;
|
|
1598
|
-
}
|
|
1599
|
-
}
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
const mintRequest = {
|
|
1603
|
-
destinationAddress: params.destinationAddress,
|
|
1604
|
-
feeRate: params.feeRate,
|
|
1605
|
-
refundAddress: params.refundAddress,
|
|
1606
|
-
repeats: params.repeats,
|
|
1607
|
-
runeName: params.runeName,
|
|
1608
|
-
appServiceFee: params.appServiceFee,
|
|
1609
|
-
appServiceFeeAddress: params.appServiceFeeAddress
|
|
1610
|
-
};
|
|
1611
|
-
const orderResponse = await new RunesApi(params.network).createMintOrder(mintRequest);
|
|
1612
|
-
if (!orderResponse.data) {
|
|
1613
|
-
return {
|
|
1614
|
-
status: "error",
|
|
1615
|
-
error: {
|
|
1616
|
-
code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
1617
|
-
message: orderResponse.error.message
|
|
1618
|
-
}
|
|
1619
|
-
};
|
|
1620
|
-
}
|
|
1621
|
-
const paymentResponse = await this.requestInternal("sendTransfer", {
|
|
1622
|
-
recipients: [
|
|
1623
|
-
{
|
|
1624
|
-
address: orderResponse.data.fundAddress,
|
|
1625
|
-
amount: orderResponse.data.fundAmount
|
|
1626
|
-
}
|
|
1627
|
-
]
|
|
1628
|
-
});
|
|
1629
|
-
if (paymentResponse.status !== "success") {
|
|
1630
|
-
return paymentResponse;
|
|
1631
|
-
}
|
|
1632
|
-
await new RunesApi(params.network).executeMint(
|
|
1633
|
-
orderResponse.data.orderId,
|
|
1634
|
-
paymentResponse.result.txid
|
|
1635
|
-
);
|
|
1636
|
-
return {
|
|
1637
|
-
status: "success",
|
|
1638
|
-
result: {
|
|
1639
|
-
orderId: orderResponse.data.orderId,
|
|
1640
|
-
fundTransactionId: paymentResponse.result.txid,
|
|
1641
|
-
fundingAddress: orderResponse.data.fundAddress
|
|
1642
|
-
}
|
|
1643
|
-
};
|
|
1644
|
-
} catch (error) {
|
|
1645
|
-
return {
|
|
1646
|
-
status: "error",
|
|
1647
|
-
error: {
|
|
1648
|
-
code: -32603 /* INTERNAL_ERROR */,
|
|
1649
|
-
message: error.message
|
|
1650
|
-
}
|
|
1651
|
-
};
|
|
1652
|
-
}
|
|
1734
|
+
// src/request/types/stxMethods/transferStx.ts
|
|
1735
|
+
import * as v24 from "valibot";
|
|
1736
|
+
var stxTransferStxMethodName = "stx_transferStx";
|
|
1737
|
+
var stxTransferStxParamsSchema = v24.object({
|
|
1738
|
+
/**
|
|
1739
|
+
* Amount of STX tokens to transfer in microstacks as a string. Anything
|
|
1740
|
+
* parseable by `BigInt` is acceptable.
|
|
1741
|
+
*
|
|
1742
|
+
* Example,
|
|
1743
|
+
*
|
|
1744
|
+
* ```js
|
|
1745
|
+
* const amount1 = 1234;
|
|
1746
|
+
* const amount2 = 1234n;
|
|
1747
|
+
* const amount3 = '1234';
|
|
1748
|
+
* ```
|
|
1749
|
+
*/
|
|
1750
|
+
amount: v24.union([v24.number(), v24.string()]),
|
|
1751
|
+
/**
|
|
1752
|
+
* The recipient's principal.
|
|
1753
|
+
*/
|
|
1754
|
+
recipient: v24.string(),
|
|
1755
|
+
/**
|
|
1756
|
+
* A string representing the memo.
|
|
1757
|
+
*/
|
|
1758
|
+
memo: v24.optional(v24.string()),
|
|
1759
|
+
/**
|
|
1760
|
+
* Version of parameter format.
|
|
1761
|
+
*/
|
|
1762
|
+
version: v24.optional(v24.string()),
|
|
1763
|
+
/**
|
|
1764
|
+
* The mode of the post conditions.
|
|
1765
|
+
*/
|
|
1766
|
+
postConditionMode: v24.optional(v24.number()),
|
|
1767
|
+
/**
|
|
1768
|
+
* A hex-encoded string representing the post conditions.
|
|
1769
|
+
*
|
|
1770
|
+
* A post condition may be converted to it's hex representation using the `serializePostCondition` helper from the `@stacks/transactions` package,
|
|
1771
|
+
*
|
|
1772
|
+
* ```js
|
|
1773
|
+
* import { serializePostCondition } from '@stacks/transactions';
|
|
1774
|
+
*
|
|
1775
|
+
* const postCondition = somePostCondition;
|
|
1776
|
+
* const hexPostCondition = serializePostCondition(postCondition).toString('hex');
|
|
1777
|
+
* ```
|
|
1778
|
+
*/
|
|
1779
|
+
postConditions: v24.optional(v24.array(v24.string())),
|
|
1780
|
+
/**
|
|
1781
|
+
* The public key to sign the transaction with. The wallet may use any key
|
|
1782
|
+
* when not provided.
|
|
1783
|
+
*/
|
|
1784
|
+
pubkey: v24.optional(v24.string())
|
|
1785
|
+
});
|
|
1786
|
+
var stxTransferStxResultSchema = v24.object({
|
|
1787
|
+
/**
|
|
1788
|
+
* The ID of the transaction.
|
|
1789
|
+
*/
|
|
1790
|
+
txid: v24.string(),
|
|
1791
|
+
/**
|
|
1792
|
+
* A Stacks transaction as a hex-encoded string.
|
|
1793
|
+
*/
|
|
1794
|
+
transaction: v24.string()
|
|
1795
|
+
});
|
|
1796
|
+
var stxTransferStxRequestMessageSchema = v24.object({
|
|
1797
|
+
...rpcRequestMessageSchema.entries,
|
|
1798
|
+
...v24.object({
|
|
1799
|
+
method: v24.literal(stxTransferStxMethodName),
|
|
1800
|
+
params: stxTransferStxParamsSchema,
|
|
1801
|
+
id: v24.string()
|
|
1802
|
+
}).entries
|
|
1803
|
+
});
|
|
1804
|
+
|
|
1805
|
+
// src/request/index.ts
|
|
1806
|
+
var request = async (method, params, providerId) => {
|
|
1807
|
+
let provider = window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
|
|
1808
|
+
if (providerId) {
|
|
1809
|
+
provider = await getProviderById(providerId);
|
|
1653
1810
|
}
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
destinationAddress: params.destinationAddress,
|
|
1657
|
-
refundAddress: params.refundAddress,
|
|
1658
|
-
feeRate: params.feeRate,
|
|
1659
|
-
runeName: params.runeName,
|
|
1660
|
-
divisibility: params.divisibility,
|
|
1661
|
-
symbol: params.symbol,
|
|
1662
|
-
premine: params.premine,
|
|
1663
|
-
isMintable: params.isMintable,
|
|
1664
|
-
terms: params.terms,
|
|
1665
|
-
inscriptionDetails: params.inscriptionDetails,
|
|
1666
|
-
delegateInscriptionId: params.delegateInscriptionId,
|
|
1667
|
-
appServiceFee: params.appServiceFee,
|
|
1668
|
-
appServiceFeeAddress: params.appServiceFeeAddress
|
|
1669
|
-
};
|
|
1670
|
-
try {
|
|
1671
|
-
const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
|
|
1672
|
-
if (walletInfo && walletInfo.status === "success") {
|
|
1673
|
-
const isEtchSupported = walletInfo.result.methods?.includes("runes_etch");
|
|
1674
|
-
if (isEtchSupported) {
|
|
1675
|
-
const response = await this.requestInternal("runes_etch", params);
|
|
1676
|
-
if (response) {
|
|
1677
|
-
if (response.status === "success") {
|
|
1678
|
-
return response;
|
|
1679
|
-
}
|
|
1680
|
-
if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
|
|
1681
|
-
return response;
|
|
1682
|
-
}
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
}
|
|
1686
|
-
const orderResponse = await new RunesApi(params.network).createEtchOrder(etchRequest);
|
|
1687
|
-
if (!orderResponse.data) {
|
|
1688
|
-
return {
|
|
1689
|
-
status: "error",
|
|
1690
|
-
error: {
|
|
1691
|
-
code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
1692
|
-
message: orderResponse.error.message
|
|
1693
|
-
}
|
|
1694
|
-
};
|
|
1695
|
-
}
|
|
1696
|
-
const paymentResponse = await this.requestInternal("sendTransfer", {
|
|
1697
|
-
recipients: [
|
|
1698
|
-
{
|
|
1699
|
-
address: orderResponse.data.fundAddress,
|
|
1700
|
-
amount: orderResponse.data.fundAmount
|
|
1701
|
-
}
|
|
1702
|
-
]
|
|
1703
|
-
});
|
|
1704
|
-
if (paymentResponse.status !== "success") {
|
|
1705
|
-
return paymentResponse;
|
|
1706
|
-
}
|
|
1707
|
-
await new RunesApi(params.network).executeEtch(
|
|
1708
|
-
orderResponse.data.orderId,
|
|
1709
|
-
paymentResponse.result.txid
|
|
1710
|
-
);
|
|
1711
|
-
return {
|
|
1712
|
-
status: "success",
|
|
1713
|
-
result: {
|
|
1714
|
-
orderId: orderResponse.data.orderId,
|
|
1715
|
-
fundTransactionId: paymentResponse.result.txid,
|
|
1716
|
-
fundingAddress: orderResponse.data.fundAddress
|
|
1717
|
-
}
|
|
1718
|
-
};
|
|
1719
|
-
} catch (error) {
|
|
1720
|
-
return {
|
|
1721
|
-
status: "error",
|
|
1722
|
-
error: {
|
|
1723
|
-
code: -32603 /* INTERNAL_ERROR */,
|
|
1724
|
-
message: error.message
|
|
1725
|
-
}
|
|
1726
|
-
};
|
|
1727
|
-
}
|
|
1811
|
+
if (!provider) {
|
|
1812
|
+
throw new Error("no wallet provider was found");
|
|
1728
1813
|
}
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
destinationAddress: params.destinationAddress,
|
|
1732
|
-
feeRate: params.feeRate,
|
|
1733
|
-
repeats: params.repeats,
|
|
1734
|
-
runeName: params.runeName,
|
|
1735
|
-
appServiceFee: params.appServiceFee,
|
|
1736
|
-
appServiceFeeAddress: params.appServiceFeeAddress
|
|
1737
|
-
};
|
|
1738
|
-
const response = await getRunesApiClient(
|
|
1739
|
-
params.network
|
|
1740
|
-
).estimateMintCost(estimateMintRequest);
|
|
1741
|
-
if (response.data) {
|
|
1742
|
-
return {
|
|
1743
|
-
status: "success",
|
|
1744
|
-
result: response.data
|
|
1745
|
-
};
|
|
1746
|
-
}
|
|
1747
|
-
return {
|
|
1748
|
-
status: "error",
|
|
1749
|
-
error: {
|
|
1750
|
-
code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
1751
|
-
message: response.error.message
|
|
1752
|
-
}
|
|
1753
|
-
};
|
|
1814
|
+
if (!method) {
|
|
1815
|
+
throw new Error("A wallet method is required");
|
|
1754
1816
|
}
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
destinationAddress: params.destinationAddress,
|
|
1758
|
-
feeRate: params.feeRate,
|
|
1759
|
-
runeName: params.runeName,
|
|
1760
|
-
divisibility: params.divisibility,
|
|
1761
|
-
symbol: params.symbol,
|
|
1762
|
-
premine: params.premine,
|
|
1763
|
-
isMintable: params.isMintable,
|
|
1764
|
-
terms: params.terms,
|
|
1765
|
-
inscriptionDetails: params.inscriptionDetails,
|
|
1766
|
-
delegateInscriptionId: params.delegateInscriptionId,
|
|
1767
|
-
appServiceFee: params.appServiceFee,
|
|
1768
|
-
appServiceFeeAddress: params.appServiceFeeAddress
|
|
1769
|
-
};
|
|
1770
|
-
const response = await getRunesApiClient(params.network).estimateEtchCost(estimateEtchRequest);
|
|
1771
|
-
if (response.data) {
|
|
1772
|
-
return {
|
|
1773
|
-
status: "success",
|
|
1774
|
-
result: response.data
|
|
1775
|
-
};
|
|
1776
|
-
}
|
|
1817
|
+
const response = await provider.request(method, params);
|
|
1818
|
+
if (v25.is(rpcErrorResponseMessageSchema, response)) {
|
|
1777
1819
|
return {
|
|
1778
1820
|
status: "error",
|
|
1779
|
-
error:
|
|
1780
|
-
code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
1781
|
-
message: response.error.message
|
|
1782
|
-
}
|
|
1821
|
+
error: response.error
|
|
1783
1822
|
};
|
|
1784
1823
|
}
|
|
1785
|
-
|
|
1786
|
-
const response = await getRunesApiClient(params.network).getOrder(params.id);
|
|
1787
|
-
if (response.data) {
|
|
1788
|
-
return {
|
|
1789
|
-
status: "success",
|
|
1790
|
-
result: response.data
|
|
1791
|
-
};
|
|
1792
|
-
}
|
|
1824
|
+
if (v25.is(rpcSuccessResponseMessageSchema, response)) {
|
|
1793
1825
|
return {
|
|
1794
|
-
status: "
|
|
1795
|
-
|
|
1796
|
-
code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
1797
|
-
message: response.error.message
|
|
1798
|
-
}
|
|
1826
|
+
status: "success",
|
|
1827
|
+
result: response.result
|
|
1799
1828
|
};
|
|
1800
1829
|
}
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
if (response.data) {
|
|
1808
|
-
return {
|
|
1809
|
-
status: "success",
|
|
1810
|
-
result: {
|
|
1811
|
-
fundingAddress: response.data.fundingAddress,
|
|
1812
|
-
rbfCost: response.data.rbfCost
|
|
1813
|
-
}
|
|
1814
|
-
};
|
|
1830
|
+
return {
|
|
1831
|
+
status: "error",
|
|
1832
|
+
error: {
|
|
1833
|
+
code: -32603 /* INTERNAL_ERROR */,
|
|
1834
|
+
message: "Received unknown response from provider.",
|
|
1835
|
+
data: response
|
|
1815
1836
|
}
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
}
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
const rbfOrderRequest = {
|
|
1827
|
-
newFeeRate: params.newFeeRate,
|
|
1828
|
-
orderId: params.orderId
|
|
1829
|
-
};
|
|
1830
|
-
const orderResponse = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
|
|
1831
|
-
if (!orderResponse.data) {
|
|
1832
|
-
return {
|
|
1833
|
-
status: "error",
|
|
1834
|
-
error: {
|
|
1835
|
-
code: orderResponse.error.code === 400 || orderResponse.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
1836
|
-
message: orderResponse.error.message
|
|
1837
|
-
}
|
|
1838
|
-
};
|
|
1839
|
-
}
|
|
1840
|
-
const paymentResponse = await this.requestInternal("sendTransfer", {
|
|
1841
|
-
recipients: [
|
|
1837
|
+
};
|
|
1838
|
+
};
|
|
1839
|
+
var addListener = (...rawArgs) => {
|
|
1840
|
+
const [listenerInfo, providerId] = (() => {
|
|
1841
|
+
if (rawArgs.length === 1) {
|
|
1842
|
+
return [rawArgs[0], void 0];
|
|
1843
|
+
}
|
|
1844
|
+
if (rawArgs.length === 2) {
|
|
1845
|
+
if (typeof rawArgs[1] === "function") {
|
|
1846
|
+
return [
|
|
1842
1847
|
{
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
}
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
return
|
|
1848
|
+
eventName: rawArgs[0],
|
|
1849
|
+
cb: rawArgs[1]
|
|
1850
|
+
},
|
|
1851
|
+
void 0
|
|
1852
|
+
];
|
|
1853
|
+
} else {
|
|
1854
|
+
return rawArgs;
|
|
1850
1855
|
}
|
|
1851
|
-
return {
|
|
1852
|
-
status: "success",
|
|
1853
|
-
result: {
|
|
1854
|
-
fundingAddress: orderResponse.data.fundingAddress,
|
|
1855
|
-
orderId: rbfOrderRequest.orderId,
|
|
1856
|
-
fundRBFTransactionId: paymentResponse.result.txid
|
|
1857
|
-
}
|
|
1858
|
-
};
|
|
1859
|
-
} catch (error) {
|
|
1860
|
-
return {
|
|
1861
|
-
status: "error",
|
|
1862
|
-
error: {
|
|
1863
|
-
code: -32603 /* INTERNAL_ERROR */,
|
|
1864
|
-
message: error.message
|
|
1865
|
-
}
|
|
1866
|
-
};
|
|
1867
1856
|
}
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
return this.estimateMint(params);
|
|
1877
|
-
case "runes_estimateEtch":
|
|
1878
|
-
return this.estimateEtch(params);
|
|
1879
|
-
case "runes_getOrder": {
|
|
1880
|
-
return this.getOrder(params);
|
|
1881
|
-
}
|
|
1882
|
-
case "runes_estimateRbfOrder": {
|
|
1883
|
-
return this.estimateRbfOrder(params);
|
|
1884
|
-
}
|
|
1885
|
-
case "runes_rbfOrder": {
|
|
1886
|
-
return this.rbfOrder(params);
|
|
1887
|
-
}
|
|
1888
|
-
default:
|
|
1889
|
-
return this.requestInternal(method, params);
|
|
1857
|
+
if (rawArgs.length === 3) {
|
|
1858
|
+
return [
|
|
1859
|
+
{
|
|
1860
|
+
eventName: rawArgs[0],
|
|
1861
|
+
cb: rawArgs[1]
|
|
1862
|
+
},
|
|
1863
|
+
rawArgs[2]
|
|
1864
|
+
];
|
|
1890
1865
|
}
|
|
1866
|
+
throw new Error("Unexpected number of arguments. Expecting 2 (or 3 for legacy requests).", {
|
|
1867
|
+
cause: rawArgs
|
|
1868
|
+
});
|
|
1869
|
+
})();
|
|
1870
|
+
let provider = window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
|
|
1871
|
+
if (providerId) {
|
|
1872
|
+
provider = getProviderById(providerId);
|
|
1891
1873
|
}
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1874
|
+
if (!provider) {
|
|
1875
|
+
throw new Error("no wallet provider was found");
|
|
1876
|
+
}
|
|
1877
|
+
if (!provider.addListener) {
|
|
1878
|
+
console.error(
|
|
1879
|
+
`The wallet provider you are using does not support the addListener method. Please update your wallet provider.`
|
|
1880
|
+
);
|
|
1881
|
+
return () => {
|
|
1882
|
+
};
|
|
1883
|
+
}
|
|
1884
|
+
return provider.addListener(listenerInfo);
|
|
1903
1885
|
};
|
|
1904
1886
|
|
|
1905
1887
|
// src/adapters/unisat.ts
|
|
1906
|
-
import { AddressType as AddressType2, getAddressInfo } from "bitcoin-address-validation";
|
|
1907
|
-
import { Buffer } from "buffer";
|
|
1908
1888
|
function convertSignInputsToInputType(signInputs) {
|
|
1909
1889
|
let result = [];
|
|
1910
1890
|
if (!signInputs) {
|
|
@@ -2090,32 +2070,77 @@ var UnisatAdapter = class extends SatsConnectAdapter {
|
|
|
2090
2070
|
};
|
|
2091
2071
|
};
|
|
2092
2072
|
|
|
2093
|
-
// src/adapters/
|
|
2094
|
-
var
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
const
|
|
2098
|
-
if (
|
|
2099
|
-
|
|
2073
|
+
// src/adapters/xverse/sanitizeRequest.ts
|
|
2074
|
+
var sanitizeRequest = (method, params, providerInfo) => {
|
|
2075
|
+
try {
|
|
2076
|
+
const [major, minor, patch] = providerInfo.version.split(".").map((part) => parseInt(part, 10));
|
|
2077
|
+
const platform = providerInfo.platform;
|
|
2078
|
+
if (
|
|
2079
|
+
// platform is missing for versions < 1.5.0 on web and < 1.55.0 on mobile
|
|
2080
|
+
!platform || platform === "web" /* Web */ && major <= 1 && minor <= 4 || platform === "mobile" /* Mobile */ && major <= 1 && minor <= 54
|
|
2081
|
+
) {
|
|
2082
|
+
const v1Sanitized = sanitizeAddressPurposeRequest(method, params);
|
|
2083
|
+
method = v1Sanitized.method;
|
|
2084
|
+
params = v1Sanitized.params;
|
|
2100
2085
|
}
|
|
2101
|
-
|
|
2102
|
-
|
|
2086
|
+
} catch {
|
|
2087
|
+
}
|
|
2088
|
+
return { method, params };
|
|
2089
|
+
};
|
|
2090
|
+
var sanitizeAddressPurposeRequest = (method, params) => {
|
|
2091
|
+
const filterPurposes = (purposes) => purposes?.filter(
|
|
2092
|
+
(purpose) => purpose !== "spark" /* Spark */ && purpose !== "starknet" /* Starknet */
|
|
2093
|
+
);
|
|
2094
|
+
if (method === "wallet_connect") {
|
|
2095
|
+
const typedParams = params;
|
|
2096
|
+
if (!typedParams) {
|
|
2097
|
+
return { method, params };
|
|
2103
2098
|
}
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2099
|
+
const { addresses, ...rest } = typedParams;
|
|
2100
|
+
const overrideParams = {
|
|
2101
|
+
...rest,
|
|
2102
|
+
addresses: filterPurposes(addresses)
|
|
2103
|
+
};
|
|
2104
|
+
return { method, params: overrideParams };
|
|
2105
|
+
}
|
|
2106
|
+
if (method === "getAccounts") {
|
|
2107
|
+
const typedParams = params;
|
|
2108
|
+
const { purposes, ...rest } = typedParams;
|
|
2109
|
+
const overrideParams = { ...rest, purposes: filterPurposes(purposes) };
|
|
2110
|
+
return { method, params: overrideParams };
|
|
2111
|
+
}
|
|
2112
|
+
if (method === "getAddresses") {
|
|
2113
|
+
const typedParams = params;
|
|
2114
|
+
const { purposes, ...rest } = typedParams;
|
|
2115
|
+
const overrideParams = { ...rest, purposes: filterPurposes(purposes) };
|
|
2116
|
+
return { method, params: overrideParams };
|
|
2117
|
+
}
|
|
2118
|
+
return { method, params };
|
|
2119
|
+
};
|
|
2120
|
+
|
|
2121
|
+
// src/adapters/xverse/index.ts
|
|
2122
|
+
var XverseAdapter = class extends SatsConnectAdapter {
|
|
2123
|
+
id = DefaultAdaptersInfo.xverse.id;
|
|
2124
|
+
providerInfo;
|
|
2125
|
+
requestInternal = async (method, params) => {
|
|
2126
|
+
if (!this.providerInfo) {
|
|
2127
|
+
const infoResult = await request("getInfo", null, this.id);
|
|
2128
|
+
if (infoResult.status === "success") {
|
|
2129
|
+
this.providerInfo = infoResult.result;
|
|
2130
|
+
}
|
|
2110
2131
|
}
|
|
2111
|
-
if (
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2132
|
+
if (this.providerInfo) {
|
|
2133
|
+
const sanitized = sanitizeRequest(method, params, this.providerInfo);
|
|
2134
|
+
if (sanitized.overrideResponse) {
|
|
2135
|
+
return sanitized.overrideResponse;
|
|
2136
|
+
}
|
|
2137
|
+
method = sanitized.method;
|
|
2138
|
+
params = sanitized.params;
|
|
2117
2139
|
}
|
|
2118
|
-
return
|
|
2140
|
+
return request(method, params, this.id);
|
|
2141
|
+
};
|
|
2142
|
+
addListener = (listenerInfo) => {
|
|
2143
|
+
return addListener(listenerInfo, this.id);
|
|
2119
2144
|
};
|
|
2120
2145
|
};
|
|
2121
2146
|
|
|
@@ -2178,7 +2203,6 @@ var extractOrValidateCapabilities = (provider, reportedCapabilities) => {
|
|
|
2178
2203
|
return true;
|
|
2179
2204
|
};
|
|
2180
2205
|
const capabilityMap = {
|
|
2181
|
-
version: validateCapability("version"),
|
|
2182
2206
|
request: validateCapability("request"),
|
|
2183
2207
|
connect: validateCapability("connect"),
|
|
2184
2208
|
signMessage: validateCapability("signMessage"),
|
|
@@ -2382,6 +2406,7 @@ export {
|
|
|
2382
2406
|
DefaultAdaptersInfo,
|
|
2383
2407
|
MessageSigningProtocols,
|
|
2384
2408
|
PermissionRequestParams,
|
|
2409
|
+
ProviderPlatform,
|
|
2385
2410
|
RpcErrorCode,
|
|
2386
2411
|
RpcIdSchema,
|
|
2387
2412
|
SatsConnectAdapter,
|