@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.js
CHANGED
|
@@ -37,6 +37,7 @@ __export(index_exports, {
|
|
|
37
37
|
DefaultAdaptersInfo: () => DefaultAdaptersInfo,
|
|
38
38
|
MessageSigningProtocols: () => MessageSigningProtocols,
|
|
39
39
|
PermissionRequestParams: () => PermissionRequestParams,
|
|
40
|
+
ProviderPlatform: () => ProviderPlatform,
|
|
40
41
|
RpcErrorCode: () => RpcErrorCode,
|
|
41
42
|
RpcIdSchema: () => RpcIdSchema,
|
|
42
43
|
SatsConnectAdapter: () => SatsConnectAdapter,
|
|
@@ -232,70 +233,8 @@ __export(index_exports, {
|
|
|
232
233
|
});
|
|
233
234
|
module.exports = __toCommonJS(index_exports);
|
|
234
235
|
|
|
235
|
-
// src/request/index.ts
|
|
236
|
-
var v25 = __toESM(require("valibot"));
|
|
237
|
-
|
|
238
|
-
// src/provider/types.ts
|
|
239
|
-
var v4 = __toESM(require("valibot"));
|
|
240
|
-
|
|
241
|
-
// src/addresses/index.ts
|
|
242
|
-
var import_jsontokens = require("jsontokens");
|
|
243
|
-
|
|
244
|
-
// src/addresses/types.ts
|
|
245
|
-
var v2 = __toESM(require("valibot"));
|
|
246
|
-
|
|
247
|
-
// src/request/types/common.ts
|
|
248
|
-
var v = __toESM(require("valibot"));
|
|
249
|
-
var walletTypes = ["software", "ledger", "keystone"];
|
|
250
|
-
var walletTypeSchema = v.picklist(walletTypes);
|
|
251
|
-
|
|
252
|
-
// src/addresses/types.ts
|
|
253
|
-
var AddressPurpose = /* @__PURE__ */ ((AddressPurpose2) => {
|
|
254
|
-
AddressPurpose2["Ordinals"] = "ordinals";
|
|
255
|
-
AddressPurpose2["Payment"] = "payment";
|
|
256
|
-
AddressPurpose2["Stacks"] = "stacks";
|
|
257
|
-
AddressPurpose2["Starknet"] = "starknet";
|
|
258
|
-
AddressPurpose2["Spark"] = "spark";
|
|
259
|
-
return AddressPurpose2;
|
|
260
|
-
})(AddressPurpose || {});
|
|
261
|
-
var AddressType = /* @__PURE__ */ ((AddressType3) => {
|
|
262
|
-
AddressType3["p2pkh"] = "p2pkh";
|
|
263
|
-
AddressType3["p2sh"] = "p2sh";
|
|
264
|
-
AddressType3["p2wpkh"] = "p2wpkh";
|
|
265
|
-
AddressType3["p2wsh"] = "p2wsh";
|
|
266
|
-
AddressType3["p2tr"] = "p2tr";
|
|
267
|
-
AddressType3["stacks"] = "stacks";
|
|
268
|
-
AddressType3["starknet"] = "starknet";
|
|
269
|
-
AddressType3["spark"] = "spark";
|
|
270
|
-
return AddressType3;
|
|
271
|
-
})(AddressType || {});
|
|
272
|
-
var addressSchema = v2.object({
|
|
273
|
-
address: v2.string(),
|
|
274
|
-
publicKey: v2.string(),
|
|
275
|
-
purpose: v2.enum(AddressPurpose),
|
|
276
|
-
addressType: v2.enum(AddressType),
|
|
277
|
-
walletType: walletTypeSchema
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
// src/addresses/index.ts
|
|
281
|
-
var getAddress = async (options) => {
|
|
282
|
-
const provider = await getProviderOrThrow(options.getProvider);
|
|
283
|
-
const { purposes } = options.payload;
|
|
284
|
-
if (!purposes) {
|
|
285
|
-
throw new Error("Address purposes are required");
|
|
286
|
-
}
|
|
287
|
-
try {
|
|
288
|
-
const request2 = (0, import_jsontokens.createUnsecuredToken)(options.payload);
|
|
289
|
-
const response = await provider.connect(request2);
|
|
290
|
-
options.onFinish?.(response);
|
|
291
|
-
} catch (error) {
|
|
292
|
-
console.error("[Connect] Error during address request", error);
|
|
293
|
-
options.onCancel?.();
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
|
|
297
236
|
// src/types.ts
|
|
298
|
-
var
|
|
237
|
+
var v = __toESM(require("valibot"));
|
|
299
238
|
var BitcoinNetworkType = /* @__PURE__ */ ((BitcoinNetworkType2) => {
|
|
300
239
|
BitcoinNetworkType2["Mainnet"] = "Mainnet";
|
|
301
240
|
BitcoinNetworkType2["Testnet"] = "Testnet";
|
|
@@ -319,22 +258,22 @@ var SparkNetworkType = /* @__PURE__ */ ((SparkNetworkType2) => {
|
|
|
319
258
|
SparkNetworkType2["Regtest"] = "regtest";
|
|
320
259
|
return SparkNetworkType2;
|
|
321
260
|
})(SparkNetworkType || {});
|
|
322
|
-
var RpcIdSchema =
|
|
323
|
-
var rpcRequestMessageSchema =
|
|
324
|
-
jsonrpc:
|
|
325
|
-
method:
|
|
326
|
-
params:
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
261
|
+
var RpcIdSchema = v.optional(v.union([v.string(), v.number(), v.null()]));
|
|
262
|
+
var rpcRequestMessageSchema = v.object({
|
|
263
|
+
jsonrpc: v.literal("2.0"),
|
|
264
|
+
method: v.string(),
|
|
265
|
+
params: v.optional(
|
|
266
|
+
v.union([
|
|
267
|
+
v.array(v.unknown()),
|
|
268
|
+
v.looseObject({}),
|
|
330
269
|
// Note: This is to support current incorrect usage of RPC 2.0. Params need
|
|
331
270
|
// to be either an array or an object when provided. Changing this now would
|
|
332
271
|
// be a breaking change, so accepting null values for now. Tracking in
|
|
333
272
|
// https://linear.app/xverseapp/issue/ENG-4538.
|
|
334
|
-
|
|
273
|
+
v.null()
|
|
335
274
|
])
|
|
336
275
|
),
|
|
337
|
-
id:
|
|
276
|
+
id: v.unwrap(RpcIdSchema)
|
|
338
277
|
});
|
|
339
278
|
var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
|
|
340
279
|
RpcErrorCode2[RpcErrorCode2["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
|
|
@@ -347,180 +286,701 @@ var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
|
|
|
347
286
|
RpcErrorCode2[RpcErrorCode2["ACCESS_DENIED"] = -32002] = "ACCESS_DENIED";
|
|
348
287
|
return RpcErrorCode2;
|
|
349
288
|
})(RpcErrorCode || {});
|
|
350
|
-
var rpcSuccessResponseMessageSchema =
|
|
351
|
-
jsonrpc:
|
|
352
|
-
result:
|
|
289
|
+
var rpcSuccessResponseMessageSchema = v.object({
|
|
290
|
+
jsonrpc: v.literal("2.0"),
|
|
291
|
+
result: v.nonOptional(v.unknown()),
|
|
353
292
|
id: RpcIdSchema
|
|
354
293
|
});
|
|
355
|
-
var rpcErrorResponseMessageSchema =
|
|
356
|
-
jsonrpc:
|
|
357
|
-
error:
|
|
294
|
+
var rpcErrorResponseMessageSchema = v.object({
|
|
295
|
+
jsonrpc: v.literal("2.0"),
|
|
296
|
+
error: v.nonOptional(v.unknown()),
|
|
358
297
|
id: RpcIdSchema
|
|
359
298
|
});
|
|
360
|
-
var rpcResponseMessageSchema =
|
|
299
|
+
var rpcResponseMessageSchema = v.union([
|
|
361
300
|
rpcSuccessResponseMessageSchema,
|
|
362
301
|
rpcErrorResponseMessageSchema
|
|
363
302
|
]);
|
|
364
303
|
|
|
365
|
-
// src/
|
|
366
|
-
var
|
|
367
|
-
var
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
}),
|
|
377
|
-
stacks: v4.object({
|
|
378
|
-
name: v4.string()
|
|
379
|
-
}),
|
|
380
|
-
addresses: v4.optional(v4.array(addressSchema))
|
|
381
|
-
});
|
|
382
|
-
var disconnectEventName = "disconnect";
|
|
383
|
-
var disconnectSchema = v4.object({
|
|
384
|
-
type: v4.literal(disconnectEventName)
|
|
385
|
-
});
|
|
386
|
-
var walletEventSchema = v4.variant("type", [
|
|
387
|
-
accountChangeSchema,
|
|
388
|
-
networkChangeSchema,
|
|
389
|
-
disconnectSchema
|
|
390
|
-
]);
|
|
391
|
-
|
|
392
|
-
// src/provider/index.ts
|
|
393
|
-
async function getProviderOrThrow(getProvider) {
|
|
394
|
-
const provider = await getProvider?.() || window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
|
|
395
|
-
if (!provider) {
|
|
396
|
-
throw new Error("No Bitcoin wallet installed");
|
|
304
|
+
// src/runes/api.ts
|
|
305
|
+
var import_axios = __toESM(require("axios"));
|
|
306
|
+
var urlNetworkSuffix = {
|
|
307
|
+
["Mainnet" /* Mainnet */]: "",
|
|
308
|
+
["Testnet" /* Testnet */]: "-testnet",
|
|
309
|
+
["Testnet4" /* Testnet4 */]: "-testnet4",
|
|
310
|
+
["Signet" /* Signet */]: "-signet"
|
|
311
|
+
};
|
|
312
|
+
var ORDINALS_API_BASE_URL = (network = "Mainnet" /* Mainnet */) => {
|
|
313
|
+
if (network === "Regtest" /* Regtest */) {
|
|
314
|
+
throw new Error(`Ordinals API does not support ${network} network`);
|
|
397
315
|
}
|
|
398
|
-
return
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
}
|
|
419
|
-
function getSupportedWallets() {
|
|
420
|
-
const wallets = Object.values(DefaultAdaptersInfo).map((provider) => {
|
|
421
|
-
{
|
|
316
|
+
return `https://ordinals${urlNetworkSuffix[network]}.xverse.app/v1`;
|
|
317
|
+
};
|
|
318
|
+
var RunesApi = class {
|
|
319
|
+
client;
|
|
320
|
+
constructor(network) {
|
|
321
|
+
this.client = import_axios.default.create({
|
|
322
|
+
baseURL: ORDINALS_API_BASE_URL(network)
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
parseError = (error) => {
|
|
326
|
+
return {
|
|
327
|
+
code: error.response?.status,
|
|
328
|
+
message: JSON.stringify(error.response?.data)
|
|
329
|
+
};
|
|
330
|
+
};
|
|
331
|
+
estimateMintCost = async (mintParams) => {
|
|
332
|
+
try {
|
|
333
|
+
const response = await this.client.post("/runes/mint/estimate", {
|
|
334
|
+
...mintParams
|
|
335
|
+
});
|
|
422
336
|
return {
|
|
423
|
-
|
|
424
|
-
|
|
337
|
+
data: response.data
|
|
338
|
+
};
|
|
339
|
+
} catch (error) {
|
|
340
|
+
const err = error;
|
|
341
|
+
return {
|
|
342
|
+
error: this.parseError(err)
|
|
425
343
|
};
|
|
426
344
|
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
const filterPurposes = (purposes) => purposes?.filter(
|
|
442
|
-
(purpose) => purpose !== "spark" /* Spark */ && purpose !== "starknet" /* Starknet */
|
|
443
|
-
);
|
|
444
|
-
if (method === "wallet_connect") {
|
|
445
|
-
const typedParams = params;
|
|
446
|
-
if (!typedParams) {
|
|
447
|
-
return { method, params };
|
|
345
|
+
};
|
|
346
|
+
estimateEtchCost = async (etchParams) => {
|
|
347
|
+
try {
|
|
348
|
+
const response = await this.client.post("/runes/etch/estimate", {
|
|
349
|
+
...etchParams
|
|
350
|
+
});
|
|
351
|
+
return {
|
|
352
|
+
data: response.data
|
|
353
|
+
};
|
|
354
|
+
} catch (error) {
|
|
355
|
+
const err = error;
|
|
356
|
+
return {
|
|
357
|
+
error: this.parseError(err)
|
|
358
|
+
};
|
|
448
359
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
};
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
360
|
+
};
|
|
361
|
+
createMintOrder = async (mintOrderParams) => {
|
|
362
|
+
try {
|
|
363
|
+
const response = await this.client.post("/runes/mint/orders", {
|
|
364
|
+
...mintOrderParams
|
|
365
|
+
});
|
|
366
|
+
return {
|
|
367
|
+
data: response.data
|
|
368
|
+
};
|
|
369
|
+
} catch (error) {
|
|
370
|
+
const err = error;
|
|
371
|
+
return {
|
|
372
|
+
error: this.parseError(err)
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
createEtchOrder = async (etchOrderParams) => {
|
|
377
|
+
try {
|
|
378
|
+
const response = await this.client.post("/runes/etch/orders", {
|
|
379
|
+
...etchOrderParams
|
|
380
|
+
});
|
|
381
|
+
return {
|
|
382
|
+
data: response.data
|
|
383
|
+
};
|
|
384
|
+
} catch (error) {
|
|
385
|
+
const err = error;
|
|
386
|
+
return {
|
|
387
|
+
error: this.parseError(err)
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
executeMint = async (orderId, fundTransactionId) => {
|
|
392
|
+
try {
|
|
393
|
+
const response = await this.client.post(`/runes/mint/orders/${orderId}/execute`, {
|
|
394
|
+
fundTransactionId
|
|
395
|
+
});
|
|
396
|
+
return {
|
|
397
|
+
data: response.data
|
|
398
|
+
};
|
|
399
|
+
} catch (error) {
|
|
400
|
+
const err = error;
|
|
401
|
+
return {
|
|
402
|
+
error: this.parseError(err)
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
executeEtch = async (orderId, fundTransactionId) => {
|
|
407
|
+
try {
|
|
408
|
+
const response = await this.client.post(`/runes/etch/orders/${orderId}/execute`, {
|
|
409
|
+
fundTransactionId
|
|
410
|
+
});
|
|
411
|
+
return {
|
|
412
|
+
data: response.data
|
|
413
|
+
};
|
|
414
|
+
} catch (error) {
|
|
415
|
+
const err = error;
|
|
416
|
+
return {
|
|
417
|
+
error: this.parseError(err)
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
getOrder = async (orderId) => {
|
|
422
|
+
try {
|
|
423
|
+
const response = await this.client.get(`/orders/${orderId}`);
|
|
424
|
+
return {
|
|
425
|
+
data: response.data
|
|
426
|
+
};
|
|
427
|
+
} catch (error) {
|
|
428
|
+
const err = error;
|
|
429
|
+
return {
|
|
430
|
+
error: this.parseError(err)
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
rbfOrder = async (rbfRequest) => {
|
|
435
|
+
const { orderId, newFeeRate } = rbfRequest;
|
|
436
|
+
try {
|
|
437
|
+
const response = await this.client.post(`/orders/${orderId}/rbf-estimate`, {
|
|
438
|
+
newFeeRate
|
|
439
|
+
});
|
|
440
|
+
return {
|
|
441
|
+
data: response.data
|
|
442
|
+
};
|
|
443
|
+
} catch (error) {
|
|
444
|
+
const err = error;
|
|
445
|
+
return {
|
|
446
|
+
error: this.parseError(err)
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
};
|
|
451
|
+
var clients = {};
|
|
452
|
+
var getRunesApiClient = (network = "Mainnet" /* Mainnet */) => {
|
|
453
|
+
if (!clients[network]) {
|
|
454
|
+
clients[network] = new RunesApi(network);
|
|
455
|
+
}
|
|
456
|
+
return clients[network];
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
// src/adapters/satsConnectAdapter.ts
|
|
460
|
+
var SatsConnectAdapter = class {
|
|
461
|
+
async mintRunes(params) {
|
|
462
|
+
try {
|
|
463
|
+
const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
|
|
464
|
+
if (walletInfo && walletInfo.status === "success") {
|
|
465
|
+
const isMintSupported = walletInfo.result.methods?.includes("runes_mint");
|
|
466
|
+
if (isMintSupported) {
|
|
467
|
+
const response = await this.requestInternal("runes_mint", params);
|
|
468
|
+
if (response) {
|
|
469
|
+
if (response.status === "success") {
|
|
470
|
+
return response;
|
|
471
|
+
}
|
|
472
|
+
if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
|
|
473
|
+
return response;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
const mintRequest = {
|
|
479
|
+
destinationAddress: params.destinationAddress,
|
|
480
|
+
feeRate: params.feeRate,
|
|
481
|
+
refundAddress: params.refundAddress,
|
|
482
|
+
repeats: params.repeats,
|
|
483
|
+
runeName: params.runeName,
|
|
484
|
+
appServiceFee: params.appServiceFee,
|
|
485
|
+
appServiceFeeAddress: params.appServiceFeeAddress
|
|
486
|
+
};
|
|
487
|
+
const orderResponse = await new RunesApi(params.network).createMintOrder(mintRequest);
|
|
488
|
+
if (!orderResponse.data) {
|
|
489
|
+
return {
|
|
490
|
+
status: "error",
|
|
491
|
+
error: {
|
|
492
|
+
code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
493
|
+
message: orderResponse.error.message
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
const paymentResponse = await this.requestInternal("sendTransfer", {
|
|
498
|
+
recipients: [
|
|
499
|
+
{
|
|
500
|
+
address: orderResponse.data.fundAddress,
|
|
501
|
+
amount: orderResponse.data.fundAmount
|
|
502
|
+
}
|
|
503
|
+
]
|
|
504
|
+
});
|
|
505
|
+
if (paymentResponse.status !== "success") {
|
|
506
|
+
return paymentResponse;
|
|
507
|
+
}
|
|
508
|
+
await new RunesApi(params.network).executeMint(
|
|
509
|
+
orderResponse.data.orderId,
|
|
510
|
+
paymentResponse.result.txid
|
|
511
|
+
);
|
|
512
|
+
return {
|
|
513
|
+
status: "success",
|
|
514
|
+
result: {
|
|
515
|
+
orderId: orderResponse.data.orderId,
|
|
516
|
+
fundTransactionId: paymentResponse.result.txid,
|
|
517
|
+
fundingAddress: orderResponse.data.fundAddress
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
} catch (error) {
|
|
521
|
+
return {
|
|
522
|
+
status: "error",
|
|
523
|
+
error: {
|
|
524
|
+
code: -32603 /* INTERNAL_ERROR */,
|
|
525
|
+
message: error.message
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
async etchRunes(params) {
|
|
531
|
+
const etchRequest = {
|
|
532
|
+
destinationAddress: params.destinationAddress,
|
|
533
|
+
refundAddress: params.refundAddress,
|
|
534
|
+
feeRate: params.feeRate,
|
|
535
|
+
runeName: params.runeName,
|
|
536
|
+
divisibility: params.divisibility,
|
|
537
|
+
symbol: params.symbol,
|
|
538
|
+
premine: params.premine,
|
|
539
|
+
isMintable: params.isMintable,
|
|
540
|
+
terms: params.terms,
|
|
541
|
+
inscriptionDetails: params.inscriptionDetails,
|
|
542
|
+
delegateInscriptionId: params.delegateInscriptionId,
|
|
543
|
+
appServiceFee: params.appServiceFee,
|
|
544
|
+
appServiceFeeAddress: params.appServiceFeeAddress
|
|
545
|
+
};
|
|
546
|
+
try {
|
|
547
|
+
const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
|
|
548
|
+
if (walletInfo && walletInfo.status === "success") {
|
|
549
|
+
const isEtchSupported = walletInfo.result.methods?.includes("runes_etch");
|
|
550
|
+
if (isEtchSupported) {
|
|
551
|
+
const response = await this.requestInternal("runes_etch", params);
|
|
552
|
+
if (response) {
|
|
553
|
+
if (response.status === "success") {
|
|
554
|
+
return response;
|
|
555
|
+
}
|
|
556
|
+
if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
|
|
557
|
+
return response;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
const orderResponse = await new RunesApi(params.network).createEtchOrder(etchRequest);
|
|
563
|
+
if (!orderResponse.data) {
|
|
564
|
+
return {
|
|
565
|
+
status: "error",
|
|
566
|
+
error: {
|
|
567
|
+
code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
568
|
+
message: orderResponse.error.message
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
const paymentResponse = await this.requestInternal("sendTransfer", {
|
|
573
|
+
recipients: [
|
|
574
|
+
{
|
|
575
|
+
address: orderResponse.data.fundAddress,
|
|
576
|
+
amount: orderResponse.data.fundAmount
|
|
577
|
+
}
|
|
578
|
+
]
|
|
579
|
+
});
|
|
580
|
+
if (paymentResponse.status !== "success") {
|
|
581
|
+
return paymentResponse;
|
|
582
|
+
}
|
|
583
|
+
await new RunesApi(params.network).executeEtch(
|
|
584
|
+
orderResponse.data.orderId,
|
|
585
|
+
paymentResponse.result.txid
|
|
586
|
+
);
|
|
587
|
+
return {
|
|
588
|
+
status: "success",
|
|
589
|
+
result: {
|
|
590
|
+
orderId: orderResponse.data.orderId,
|
|
591
|
+
fundTransactionId: paymentResponse.result.txid,
|
|
592
|
+
fundingAddress: orderResponse.data.fundAddress
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
} catch (error) {
|
|
596
|
+
return {
|
|
597
|
+
status: "error",
|
|
598
|
+
error: {
|
|
599
|
+
code: -32603 /* INTERNAL_ERROR */,
|
|
600
|
+
message: error.message
|
|
601
|
+
}
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
async estimateMint(params) {
|
|
606
|
+
const estimateMintRequest = {
|
|
607
|
+
destinationAddress: params.destinationAddress,
|
|
608
|
+
feeRate: params.feeRate,
|
|
609
|
+
repeats: params.repeats,
|
|
610
|
+
runeName: params.runeName,
|
|
611
|
+
appServiceFee: params.appServiceFee,
|
|
612
|
+
appServiceFeeAddress: params.appServiceFeeAddress
|
|
613
|
+
};
|
|
614
|
+
const response = await getRunesApiClient(
|
|
615
|
+
params.network
|
|
616
|
+
).estimateMintCost(estimateMintRequest);
|
|
617
|
+
if (response.data) {
|
|
618
|
+
return {
|
|
619
|
+
status: "success",
|
|
620
|
+
result: response.data
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
return {
|
|
624
|
+
status: "error",
|
|
625
|
+
error: {
|
|
626
|
+
code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
627
|
+
message: response.error.message
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
async estimateEtch(params) {
|
|
632
|
+
const estimateEtchRequest = {
|
|
633
|
+
destinationAddress: params.destinationAddress,
|
|
634
|
+
feeRate: params.feeRate,
|
|
635
|
+
runeName: params.runeName,
|
|
636
|
+
divisibility: params.divisibility,
|
|
637
|
+
symbol: params.symbol,
|
|
638
|
+
premine: params.premine,
|
|
639
|
+
isMintable: params.isMintable,
|
|
640
|
+
terms: params.terms,
|
|
641
|
+
inscriptionDetails: params.inscriptionDetails,
|
|
642
|
+
delegateInscriptionId: params.delegateInscriptionId,
|
|
643
|
+
appServiceFee: params.appServiceFee,
|
|
644
|
+
appServiceFeeAddress: params.appServiceFeeAddress
|
|
645
|
+
};
|
|
646
|
+
const response = await getRunesApiClient(params.network).estimateEtchCost(estimateEtchRequest);
|
|
647
|
+
if (response.data) {
|
|
648
|
+
return {
|
|
649
|
+
status: "success",
|
|
650
|
+
result: response.data
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
return {
|
|
654
|
+
status: "error",
|
|
655
|
+
error: {
|
|
656
|
+
code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
657
|
+
message: response.error.message
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
async getOrder(params) {
|
|
662
|
+
const response = await getRunesApiClient(params.network).getOrder(params.id);
|
|
663
|
+
if (response.data) {
|
|
664
|
+
return {
|
|
665
|
+
status: "success",
|
|
666
|
+
result: response.data
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
return {
|
|
670
|
+
status: "error",
|
|
671
|
+
error: {
|
|
672
|
+
code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
673
|
+
message: response.error.message
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
async estimateRbfOrder(params) {
|
|
678
|
+
const rbfOrderRequest = {
|
|
679
|
+
newFeeRate: params.newFeeRate,
|
|
680
|
+
orderId: params.orderId
|
|
681
|
+
};
|
|
682
|
+
const response = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
|
|
683
|
+
if (response.data) {
|
|
684
|
+
return {
|
|
685
|
+
status: "success",
|
|
686
|
+
result: {
|
|
687
|
+
fundingAddress: response.data.fundingAddress,
|
|
688
|
+
rbfCost: response.data.rbfCost
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
return {
|
|
693
|
+
status: "error",
|
|
694
|
+
error: {
|
|
695
|
+
code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
696
|
+
message: response.error.message
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
async rbfOrder(params) {
|
|
701
|
+
try {
|
|
702
|
+
const rbfOrderRequest = {
|
|
703
|
+
newFeeRate: params.newFeeRate,
|
|
704
|
+
orderId: params.orderId
|
|
705
|
+
};
|
|
706
|
+
const orderResponse = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
|
|
707
|
+
if (!orderResponse.data) {
|
|
708
|
+
return {
|
|
709
|
+
status: "error",
|
|
710
|
+
error: {
|
|
711
|
+
code: orderResponse.error.code === 400 || orderResponse.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
712
|
+
message: orderResponse.error.message
|
|
713
|
+
}
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
const paymentResponse = await this.requestInternal("sendTransfer", {
|
|
717
|
+
recipients: [
|
|
718
|
+
{
|
|
719
|
+
address: orderResponse.data.fundingAddress,
|
|
720
|
+
amount: orderResponse.data.rbfCost
|
|
721
|
+
}
|
|
722
|
+
]
|
|
723
|
+
});
|
|
724
|
+
if (paymentResponse.status !== "success") {
|
|
725
|
+
return paymentResponse;
|
|
726
|
+
}
|
|
727
|
+
return {
|
|
728
|
+
status: "success",
|
|
729
|
+
result: {
|
|
730
|
+
fundingAddress: orderResponse.data.fundingAddress,
|
|
731
|
+
orderId: rbfOrderRequest.orderId,
|
|
732
|
+
fundRBFTransactionId: paymentResponse.result.txid
|
|
733
|
+
}
|
|
734
|
+
};
|
|
735
|
+
} catch (error) {
|
|
736
|
+
return {
|
|
737
|
+
status: "error",
|
|
738
|
+
error: {
|
|
739
|
+
code: -32603 /* INTERNAL_ERROR */,
|
|
740
|
+
message: error.message
|
|
741
|
+
}
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
async request(method, params) {
|
|
746
|
+
switch (method) {
|
|
747
|
+
case "runes_mint":
|
|
748
|
+
return this.mintRunes(params);
|
|
749
|
+
case "runes_etch":
|
|
750
|
+
return this.etchRunes(params);
|
|
751
|
+
case "runes_estimateMint":
|
|
752
|
+
return this.estimateMint(params);
|
|
753
|
+
case "runes_estimateEtch":
|
|
754
|
+
return this.estimateEtch(params);
|
|
755
|
+
case "runes_getOrder": {
|
|
756
|
+
return this.getOrder(params);
|
|
757
|
+
}
|
|
758
|
+
case "runes_estimateRbfOrder": {
|
|
759
|
+
return this.estimateRbfOrder(params);
|
|
760
|
+
}
|
|
761
|
+
case "runes_rbfOrder": {
|
|
762
|
+
return this.rbfOrder(params);
|
|
763
|
+
}
|
|
764
|
+
default:
|
|
765
|
+
return this.requestInternal(method, params);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
};
|
|
769
|
+
|
|
770
|
+
// src/provider/types.ts
|
|
771
|
+
var v4 = __toESM(require("valibot"));
|
|
772
|
+
|
|
773
|
+
// src/addresses/index.ts
|
|
774
|
+
var import_jsontokens = require("jsontokens");
|
|
775
|
+
|
|
776
|
+
// src/addresses/types.ts
|
|
777
|
+
var v3 = __toESM(require("valibot"));
|
|
778
|
+
|
|
779
|
+
// src/request/types/common.ts
|
|
780
|
+
var v2 = __toESM(require("valibot"));
|
|
781
|
+
var walletTypes = ["software", "ledger", "keystone"];
|
|
782
|
+
var walletTypeSchema = v2.picklist(walletTypes);
|
|
783
|
+
|
|
784
|
+
// src/addresses/types.ts
|
|
785
|
+
var AddressPurpose = /* @__PURE__ */ ((AddressPurpose2) => {
|
|
786
|
+
AddressPurpose2["Ordinals"] = "ordinals";
|
|
787
|
+
AddressPurpose2["Payment"] = "payment";
|
|
788
|
+
AddressPurpose2["Stacks"] = "stacks";
|
|
789
|
+
AddressPurpose2["Starknet"] = "starknet";
|
|
790
|
+
AddressPurpose2["Spark"] = "spark";
|
|
791
|
+
return AddressPurpose2;
|
|
792
|
+
})(AddressPurpose || {});
|
|
793
|
+
var AddressType = /* @__PURE__ */ ((AddressType3) => {
|
|
794
|
+
AddressType3["p2pkh"] = "p2pkh";
|
|
795
|
+
AddressType3["p2sh"] = "p2sh";
|
|
796
|
+
AddressType3["p2wpkh"] = "p2wpkh";
|
|
797
|
+
AddressType3["p2wsh"] = "p2wsh";
|
|
798
|
+
AddressType3["p2tr"] = "p2tr";
|
|
799
|
+
AddressType3["stacks"] = "stacks";
|
|
800
|
+
AddressType3["starknet"] = "starknet";
|
|
801
|
+
AddressType3["spark"] = "spark";
|
|
802
|
+
return AddressType3;
|
|
803
|
+
})(AddressType || {});
|
|
804
|
+
var addressSchema = v3.object({
|
|
805
|
+
address: v3.string(),
|
|
806
|
+
publicKey: v3.string(),
|
|
807
|
+
purpose: v3.enum(AddressPurpose),
|
|
808
|
+
addressType: v3.enum(AddressType),
|
|
809
|
+
walletType: walletTypeSchema
|
|
810
|
+
});
|
|
811
|
+
|
|
812
|
+
// src/addresses/index.ts
|
|
813
|
+
var getAddress = async (options) => {
|
|
814
|
+
const provider = await getProviderOrThrow(options.getProvider);
|
|
815
|
+
const { purposes } = options.payload;
|
|
816
|
+
if (!purposes) {
|
|
817
|
+
throw new Error("Address purposes are required");
|
|
818
|
+
}
|
|
819
|
+
try {
|
|
820
|
+
const request2 = (0, import_jsontokens.createUnsecuredToken)(options.payload);
|
|
821
|
+
const response = await provider.connect(request2);
|
|
822
|
+
options.onFinish?.(response);
|
|
823
|
+
} catch (error) {
|
|
824
|
+
console.error("[Connect] Error during address request", error);
|
|
825
|
+
options.onCancel?.();
|
|
826
|
+
}
|
|
827
|
+
};
|
|
828
|
+
|
|
829
|
+
// src/provider/types.ts
|
|
830
|
+
var accountChangeEventName = "accountChange";
|
|
831
|
+
var accountChangeSchema = v4.object({
|
|
832
|
+
type: v4.literal(accountChangeEventName),
|
|
833
|
+
addresses: v4.optional(v4.array(addressSchema))
|
|
834
|
+
});
|
|
835
|
+
var networkChangeEventName = "networkChange";
|
|
836
|
+
var networkChangeSchema = v4.object({
|
|
837
|
+
type: v4.literal(networkChangeEventName),
|
|
838
|
+
bitcoin: v4.object({
|
|
839
|
+
name: v4.enum(BitcoinNetworkType)
|
|
840
|
+
}),
|
|
841
|
+
stacks: v4.object({
|
|
842
|
+
name: v4.string()
|
|
843
|
+
}),
|
|
844
|
+
addresses: v4.optional(v4.array(addressSchema))
|
|
845
|
+
});
|
|
846
|
+
var disconnectEventName = "disconnect";
|
|
847
|
+
var disconnectSchema = v4.object({
|
|
848
|
+
type: v4.literal(disconnectEventName)
|
|
849
|
+
});
|
|
850
|
+
var walletEventSchema = v4.variant("type", [
|
|
851
|
+
accountChangeSchema,
|
|
852
|
+
networkChangeSchema,
|
|
853
|
+
disconnectSchema
|
|
854
|
+
]);
|
|
855
|
+
|
|
856
|
+
// src/provider/index.ts
|
|
857
|
+
async function getProviderOrThrow(getProvider) {
|
|
858
|
+
const provider = await getProvider?.() || window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
|
|
859
|
+
if (!provider) {
|
|
860
|
+
throw new Error("No Bitcoin wallet installed");
|
|
861
|
+
}
|
|
862
|
+
return provider;
|
|
863
|
+
}
|
|
864
|
+
function getProviders() {
|
|
865
|
+
if (!window.btc_providers) window.btc_providers = [];
|
|
866
|
+
return window.btc_providers;
|
|
867
|
+
}
|
|
868
|
+
function getProviderById(providerId) {
|
|
869
|
+
return providerId?.split(".").reduce((acc, part) => acc?.[part], window);
|
|
870
|
+
}
|
|
871
|
+
function isProviderInstalled(providerId) {
|
|
872
|
+
return !!getProviderById(providerId);
|
|
873
|
+
}
|
|
874
|
+
function setDefaultProvider(providerId) {
|
|
875
|
+
localStorage.setItem("sats-connect_defaultProvider", providerId);
|
|
876
|
+
}
|
|
877
|
+
function getDefaultProvider() {
|
|
878
|
+
return localStorage.getItem("sats-connect_defaultProvider");
|
|
879
|
+
}
|
|
880
|
+
function removeDefaultProvider() {
|
|
881
|
+
localStorage.removeItem("sats-connect_defaultProvider");
|
|
882
|
+
}
|
|
883
|
+
function getSupportedWallets() {
|
|
884
|
+
const wallets = Object.values(DefaultAdaptersInfo).map((provider) => {
|
|
885
|
+
{
|
|
886
|
+
return {
|
|
887
|
+
...provider,
|
|
888
|
+
isInstalled: isProviderInstalled(provider.id)
|
|
889
|
+
};
|
|
890
|
+
}
|
|
891
|
+
});
|
|
892
|
+
return wallets;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
// src/adapters/fordefi.ts
|
|
896
|
+
var FordefiAdapter = class extends SatsConnectAdapter {
|
|
897
|
+
id = DefaultAdaptersInfo.fordefi.id;
|
|
898
|
+
requestInternal = async (method, params) => {
|
|
899
|
+
const provider = getProviderById(this.id);
|
|
900
|
+
if (!provider) {
|
|
901
|
+
throw new Error("no wallet provider was found");
|
|
902
|
+
}
|
|
903
|
+
if (!method) {
|
|
904
|
+
throw new Error("A wallet method is required");
|
|
905
|
+
}
|
|
906
|
+
return await provider.request(method, params);
|
|
907
|
+
};
|
|
908
|
+
addListener = ({ eventName, cb }) => {
|
|
909
|
+
const provider = getProviderById(this.id);
|
|
910
|
+
if (!provider) {
|
|
911
|
+
throw new Error("no wallet provider was found");
|
|
912
|
+
}
|
|
913
|
+
if (!provider.addListener) {
|
|
914
|
+
console.error(
|
|
915
|
+
`The wallet provider you are using does not support the addListener method. Please update your wallet provider.`
|
|
916
|
+
);
|
|
917
|
+
return () => {
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
return provider.addListener(eventName, cb);
|
|
921
|
+
};
|
|
922
|
+
};
|
|
923
|
+
|
|
924
|
+
// src/adapters/unisat.ts
|
|
925
|
+
var import_bitcoin_address_validation = require("bitcoin-address-validation");
|
|
926
|
+
var import_buffer = require("buffer");
|
|
927
|
+
|
|
928
|
+
// src/request/index.ts
|
|
929
|
+
var v25 = __toESM(require("valibot"));
|
|
930
|
+
|
|
931
|
+
// src/request/types/btcMethods.ts
|
|
932
|
+
var v6 = __toESM(require("valibot"));
|
|
933
|
+
|
|
934
|
+
// src/request/types/walletMethods.ts
|
|
935
|
+
var v5 = __toESM(require("valibot"));
|
|
936
|
+
var accountActionsSchema = v5.object({
|
|
937
|
+
read: v5.optional(v5.boolean())
|
|
938
|
+
});
|
|
939
|
+
var walletActionsSchema = v5.object({
|
|
940
|
+
readNetwork: v5.optional(v5.boolean())
|
|
941
|
+
});
|
|
942
|
+
var accountPermissionSchema = v5.object({
|
|
943
|
+
type: v5.literal("account"),
|
|
944
|
+
resourceId: v5.string(),
|
|
945
|
+
clientId: v5.string(),
|
|
946
|
+
actions: accountActionsSchema
|
|
947
|
+
});
|
|
948
|
+
var walletPermissionSchema = v5.object({
|
|
949
|
+
type: v5.literal("wallet"),
|
|
950
|
+
resourceId: v5.string(),
|
|
951
|
+
clientId: v5.string(),
|
|
952
|
+
actions: walletActionsSchema
|
|
953
|
+
});
|
|
954
|
+
var PermissionRequestParams = v5.variant("type", [
|
|
955
|
+
v5.object({
|
|
956
|
+
...v5.omit(accountPermissionSchema, ["clientId"]).entries
|
|
957
|
+
}),
|
|
958
|
+
v5.object({
|
|
959
|
+
...v5.omit(walletPermissionSchema, ["clientId"]).entries
|
|
960
|
+
})
|
|
961
|
+
]);
|
|
962
|
+
var permission = v5.variant("type", [accountPermissionSchema, walletPermissionSchema]);
|
|
963
|
+
var requestPermissionsMethodName = "wallet_requestPermissions";
|
|
964
|
+
var requestPermissionsParamsSchema = v5.nullish(v5.array(PermissionRequestParams));
|
|
965
|
+
var requestPermissionsResultSchema = v5.literal(true);
|
|
966
|
+
var requestPermissionsRequestMessageSchema = v5.object({
|
|
967
|
+
...rpcRequestMessageSchema.entries,
|
|
968
|
+
...v5.object({
|
|
969
|
+
method: v5.literal(requestPermissionsMethodName),
|
|
970
|
+
params: requestPermissionsParamsSchema,
|
|
971
|
+
id: v5.string()
|
|
972
|
+
}).entries
|
|
973
|
+
});
|
|
974
|
+
var renouncePermissionsMethodName = "wallet_renouncePermissions";
|
|
975
|
+
var renouncePermissionsParamsSchema = v5.nullish(v5.null());
|
|
976
|
+
var renouncePermissionsResultSchema = v5.nullish(v5.null());
|
|
977
|
+
var renouncePermissionsRequestMessageSchema = v5.object({
|
|
978
|
+
...rpcRequestMessageSchema.entries,
|
|
979
|
+
...v5.object({
|
|
980
|
+
method: v5.literal(renouncePermissionsMethodName),
|
|
981
|
+
params: renouncePermissionsParamsSchema,
|
|
982
|
+
id: v5.string()
|
|
983
|
+
}).entries
|
|
524
984
|
});
|
|
525
985
|
var disconnectMethodName = "wallet_disconnect";
|
|
526
986
|
var disconnectParamsSchema = v5.nullish(v5.null());
|
|
@@ -685,6 +1145,11 @@ var addNetworkResultSchema = v5.object({
|
|
|
685
1145
|
});
|
|
686
1146
|
|
|
687
1147
|
// src/request/types/btcMethods.ts
|
|
1148
|
+
var ProviderPlatform = /* @__PURE__ */ ((ProviderPlatform2) => {
|
|
1149
|
+
ProviderPlatform2["Web"] = "web";
|
|
1150
|
+
ProviderPlatform2["Mobile"] = "mobile";
|
|
1151
|
+
return ProviderPlatform2;
|
|
1152
|
+
})(ProviderPlatform || {});
|
|
688
1153
|
var getInfoMethodName = "getInfo";
|
|
689
1154
|
var getInfoParamsSchema = v6.nullish(v6.null());
|
|
690
1155
|
var getInfoResultSchema = v6.object({
|
|
@@ -692,6 +1157,10 @@ var getInfoResultSchema = v6.object({
|
|
|
692
1157
|
* Version of the wallet.
|
|
693
1158
|
*/
|
|
694
1159
|
version: v6.string(),
|
|
1160
|
+
/**
|
|
1161
|
+
* The platform the wallet is running on (web or mobile).
|
|
1162
|
+
*/
|
|
1163
|
+
platform: v6.optional(v6.enum(ProviderPlatform)),
|
|
695
1164
|
/**
|
|
696
1165
|
* [WBIP](https://wbips.netlify.app/wbips/WBIP002) methods supported by the wallet.
|
|
697
1166
|
*/
|
|
@@ -1476,669 +1945,181 @@ var stxSignTransactionsParamsSchema = v23.object({
|
|
|
1476
1945
|
v23.minLength(1)
|
|
1477
1946
|
),
|
|
1478
1947
|
/**
|
|
1479
|
-
* Whether the signed transactions should be broadcast after signing. Defaults
|
|
1480
|
-
* to `true`.
|
|
1481
|
-
*/
|
|
1482
|
-
broadcast: v23.optional(v23.boolean())
|
|
1483
|
-
});
|
|
1484
|
-
var stxSignTransactionsResultSchema = v23.object({
|
|
1485
|
-
/**
|
|
1486
|
-
* The signed transactions as hex-encoded strings, in the same order as in the
|
|
1487
|
-
* sign request.
|
|
1488
|
-
*/
|
|
1489
|
-
transactions: v23.array(v23.string())
|
|
1490
|
-
});
|
|
1491
|
-
var stxSignTransactionsRequestMessageSchema = v23.object({
|
|
1492
|
-
...rpcRequestMessageSchema.entries,
|
|
1493
|
-
...v23.object({
|
|
1494
|
-
method: v23.literal(stxSignTransactionsMethodName),
|
|
1495
|
-
params: stxSignTransactionsParamsSchema,
|
|
1496
|
-
id: v23.string()
|
|
1497
|
-
}).entries
|
|
1498
|
-
});
|
|
1499
|
-
|
|
1500
|
-
// src/request/types/stxMethods/transferStx.ts
|
|
1501
|
-
var v24 = __toESM(require("valibot"));
|
|
1502
|
-
var stxTransferStxMethodName = "stx_transferStx";
|
|
1503
|
-
var stxTransferStxParamsSchema = v24.object({
|
|
1504
|
-
/**
|
|
1505
|
-
* Amount of STX tokens to transfer in microstacks as a string. Anything
|
|
1506
|
-
* parseable by `BigInt` is acceptable.
|
|
1507
|
-
*
|
|
1508
|
-
* Example,
|
|
1509
|
-
*
|
|
1510
|
-
* ```js
|
|
1511
|
-
* const amount1 = 1234;
|
|
1512
|
-
* const amount2 = 1234n;
|
|
1513
|
-
* const amount3 = '1234';
|
|
1514
|
-
* ```
|
|
1515
|
-
*/
|
|
1516
|
-
amount: v24.union([v24.number(), v24.string()]),
|
|
1517
|
-
/**
|
|
1518
|
-
* The recipient's principal.
|
|
1519
|
-
*/
|
|
1520
|
-
recipient: v24.string(),
|
|
1521
|
-
/**
|
|
1522
|
-
* A string representing the memo.
|
|
1523
|
-
*/
|
|
1524
|
-
memo: v24.optional(v24.string()),
|
|
1525
|
-
/**
|
|
1526
|
-
* Version of parameter format.
|
|
1527
|
-
*/
|
|
1528
|
-
version: v24.optional(v24.string()),
|
|
1529
|
-
/**
|
|
1530
|
-
* The mode of the post conditions.
|
|
1531
|
-
*/
|
|
1532
|
-
postConditionMode: v24.optional(v24.number()),
|
|
1533
|
-
/**
|
|
1534
|
-
* A hex-encoded string representing the post conditions.
|
|
1535
|
-
*
|
|
1536
|
-
* A post condition may be converted to it's hex representation using the `serializePostCondition` helper from the `@stacks/transactions` package,
|
|
1537
|
-
*
|
|
1538
|
-
* ```js
|
|
1539
|
-
* import { serializePostCondition } from '@stacks/transactions';
|
|
1540
|
-
*
|
|
1541
|
-
* const postCondition = somePostCondition;
|
|
1542
|
-
* const hexPostCondition = serializePostCondition(postCondition).toString('hex');
|
|
1543
|
-
* ```
|
|
1544
|
-
*/
|
|
1545
|
-
postConditions: v24.optional(v24.array(v24.string())),
|
|
1546
|
-
/**
|
|
1547
|
-
* The public key to sign the transaction with. The wallet may use any key
|
|
1548
|
-
* when not provided.
|
|
1549
|
-
*/
|
|
1550
|
-
pubkey: v24.optional(v24.string())
|
|
1551
|
-
});
|
|
1552
|
-
var stxTransferStxResultSchema = v24.object({
|
|
1553
|
-
/**
|
|
1554
|
-
* The ID of the transaction.
|
|
1555
|
-
*/
|
|
1556
|
-
txid: v24.string(),
|
|
1557
|
-
/**
|
|
1558
|
-
* A Stacks transaction as a hex-encoded string.
|
|
1948
|
+
* Whether the signed transactions should be broadcast after signing. Defaults
|
|
1949
|
+
* to `true`.
|
|
1559
1950
|
*/
|
|
1560
|
-
|
|
1561
|
-
});
|
|
1562
|
-
var
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1951
|
+
broadcast: v23.optional(v23.boolean())
|
|
1952
|
+
});
|
|
1953
|
+
var stxSignTransactionsResultSchema = v23.object({
|
|
1954
|
+
/**
|
|
1955
|
+
* The signed transactions as hex-encoded strings, in the same order as in the
|
|
1956
|
+
* sign request.
|
|
1957
|
+
*/
|
|
1958
|
+
transactions: v23.array(v23.string())
|
|
1959
|
+
});
|
|
1960
|
+
var stxSignTransactionsRequestMessageSchema = v23.object({
|
|
1961
|
+
...rpcRequestMessageSchema.entries,
|
|
1962
|
+
...v23.object({
|
|
1963
|
+
method: v23.literal(stxSignTransactionsMethodName),
|
|
1964
|
+
params: stxSignTransactionsParamsSchema,
|
|
1965
|
+
id: v23.string()
|
|
1966
|
+
}).entries
|
|
1569
1967
|
});
|
|
1570
1968
|
|
|
1571
|
-
// src/request/
|
|
1572
|
-
var
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
provider = getProviderById(providerId);
|
|
1648
|
-
}
|
|
1649
|
-
if (!provider) {
|
|
1650
|
-
throw new Error("no wallet provider was found");
|
|
1651
|
-
}
|
|
1652
|
-
if (!provider.addListener) {
|
|
1653
|
-
console.error(
|
|
1654
|
-
`The wallet provider you are using does not support the addListener method. Please update your wallet provider.`
|
|
1655
|
-
);
|
|
1656
|
-
return () => {
|
|
1657
|
-
};
|
|
1658
|
-
}
|
|
1659
|
-
return provider.addListener(listenerInfo);
|
|
1660
|
-
};
|
|
1661
|
-
|
|
1662
|
-
// src/runes/api.ts
|
|
1663
|
-
var import_axios = __toESM(require("axios"));
|
|
1664
|
-
var urlNetworkSuffix = {
|
|
1665
|
-
["Mainnet" /* Mainnet */]: "",
|
|
1666
|
-
["Testnet" /* Testnet */]: "-testnet",
|
|
1667
|
-
["Testnet4" /* Testnet4 */]: "-testnet4",
|
|
1668
|
-
["Signet" /* Signet */]: "-signet"
|
|
1669
|
-
};
|
|
1670
|
-
var ORDINALS_API_BASE_URL = (network = "Mainnet" /* Mainnet */) => {
|
|
1671
|
-
if (network === "Regtest" /* Regtest */) {
|
|
1672
|
-
throw new Error(`Ordinals API does not support ${network} network`);
|
|
1673
|
-
}
|
|
1674
|
-
return `https://ordinals${urlNetworkSuffix[network]}.xverse.app/v1`;
|
|
1675
|
-
};
|
|
1676
|
-
var RunesApi = class {
|
|
1677
|
-
client;
|
|
1678
|
-
constructor(network) {
|
|
1679
|
-
this.client = import_axios.default.create({
|
|
1680
|
-
baseURL: ORDINALS_API_BASE_URL(network)
|
|
1681
|
-
});
|
|
1682
|
-
}
|
|
1683
|
-
parseError = (error) => {
|
|
1684
|
-
return {
|
|
1685
|
-
code: error.response?.status,
|
|
1686
|
-
message: JSON.stringify(error.response?.data)
|
|
1687
|
-
};
|
|
1688
|
-
};
|
|
1689
|
-
estimateMintCost = async (mintParams) => {
|
|
1690
|
-
try {
|
|
1691
|
-
const response = await this.client.post("/runes/mint/estimate", {
|
|
1692
|
-
...mintParams
|
|
1693
|
-
});
|
|
1694
|
-
return {
|
|
1695
|
-
data: response.data
|
|
1696
|
-
};
|
|
1697
|
-
} catch (error) {
|
|
1698
|
-
const err = error;
|
|
1699
|
-
return {
|
|
1700
|
-
error: this.parseError(err)
|
|
1701
|
-
};
|
|
1702
|
-
}
|
|
1703
|
-
};
|
|
1704
|
-
estimateEtchCost = async (etchParams) => {
|
|
1705
|
-
try {
|
|
1706
|
-
const response = await this.client.post("/runes/etch/estimate", {
|
|
1707
|
-
...etchParams
|
|
1708
|
-
});
|
|
1709
|
-
return {
|
|
1710
|
-
data: response.data
|
|
1711
|
-
};
|
|
1712
|
-
} catch (error) {
|
|
1713
|
-
const err = error;
|
|
1714
|
-
return {
|
|
1715
|
-
error: this.parseError(err)
|
|
1716
|
-
};
|
|
1717
|
-
}
|
|
1718
|
-
};
|
|
1719
|
-
createMintOrder = async (mintOrderParams) => {
|
|
1720
|
-
try {
|
|
1721
|
-
const response = await this.client.post("/runes/mint/orders", {
|
|
1722
|
-
...mintOrderParams
|
|
1723
|
-
});
|
|
1724
|
-
return {
|
|
1725
|
-
data: response.data
|
|
1726
|
-
};
|
|
1727
|
-
} catch (error) {
|
|
1728
|
-
const err = error;
|
|
1729
|
-
return {
|
|
1730
|
-
error: this.parseError(err)
|
|
1731
|
-
};
|
|
1732
|
-
}
|
|
1733
|
-
};
|
|
1734
|
-
createEtchOrder = async (etchOrderParams) => {
|
|
1735
|
-
try {
|
|
1736
|
-
const response = await this.client.post("/runes/etch/orders", {
|
|
1737
|
-
...etchOrderParams
|
|
1738
|
-
});
|
|
1739
|
-
return {
|
|
1740
|
-
data: response.data
|
|
1741
|
-
};
|
|
1742
|
-
} catch (error) {
|
|
1743
|
-
const err = error;
|
|
1744
|
-
return {
|
|
1745
|
-
error: this.parseError(err)
|
|
1746
|
-
};
|
|
1747
|
-
}
|
|
1748
|
-
};
|
|
1749
|
-
executeMint = async (orderId, fundTransactionId) => {
|
|
1750
|
-
try {
|
|
1751
|
-
const response = await this.client.post(`/runes/mint/orders/${orderId}/execute`, {
|
|
1752
|
-
fundTransactionId
|
|
1753
|
-
});
|
|
1754
|
-
return {
|
|
1755
|
-
data: response.data
|
|
1756
|
-
};
|
|
1757
|
-
} catch (error) {
|
|
1758
|
-
const err = error;
|
|
1759
|
-
return {
|
|
1760
|
-
error: this.parseError(err)
|
|
1761
|
-
};
|
|
1762
|
-
}
|
|
1763
|
-
};
|
|
1764
|
-
executeEtch = async (orderId, fundTransactionId) => {
|
|
1765
|
-
try {
|
|
1766
|
-
const response = await this.client.post(`/runes/etch/orders/${orderId}/execute`, {
|
|
1767
|
-
fundTransactionId
|
|
1768
|
-
});
|
|
1769
|
-
return {
|
|
1770
|
-
data: response.data
|
|
1771
|
-
};
|
|
1772
|
-
} catch (error) {
|
|
1773
|
-
const err = error;
|
|
1774
|
-
return {
|
|
1775
|
-
error: this.parseError(err)
|
|
1776
|
-
};
|
|
1777
|
-
}
|
|
1778
|
-
};
|
|
1779
|
-
getOrder = async (orderId) => {
|
|
1780
|
-
try {
|
|
1781
|
-
const response = await this.client.get(`/orders/${orderId}`);
|
|
1782
|
-
return {
|
|
1783
|
-
data: response.data
|
|
1784
|
-
};
|
|
1785
|
-
} catch (error) {
|
|
1786
|
-
const err = error;
|
|
1787
|
-
return {
|
|
1788
|
-
error: this.parseError(err)
|
|
1789
|
-
};
|
|
1790
|
-
}
|
|
1791
|
-
};
|
|
1792
|
-
rbfOrder = async (rbfRequest) => {
|
|
1793
|
-
const { orderId, newFeeRate } = rbfRequest;
|
|
1794
|
-
try {
|
|
1795
|
-
const response = await this.client.post(`/orders/${orderId}/rbf-estimate`, {
|
|
1796
|
-
newFeeRate
|
|
1797
|
-
});
|
|
1798
|
-
return {
|
|
1799
|
-
data: response.data
|
|
1800
|
-
};
|
|
1801
|
-
} catch (error) {
|
|
1802
|
-
const err = error;
|
|
1803
|
-
return {
|
|
1804
|
-
error: this.parseError(err)
|
|
1805
|
-
};
|
|
1806
|
-
}
|
|
1807
|
-
};
|
|
1808
|
-
};
|
|
1809
|
-
var clients = {};
|
|
1810
|
-
var getRunesApiClient = (network = "Mainnet" /* Mainnet */) => {
|
|
1811
|
-
if (!clients[network]) {
|
|
1812
|
-
clients[network] = new RunesApi(network);
|
|
1813
|
-
}
|
|
1814
|
-
return clients[network];
|
|
1815
|
-
};
|
|
1816
|
-
|
|
1817
|
-
// src/adapters/satsConnectAdapter.ts
|
|
1818
|
-
var SatsConnectAdapter = class {
|
|
1819
|
-
async mintRunes(params) {
|
|
1820
|
-
try {
|
|
1821
|
-
const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
|
|
1822
|
-
if (walletInfo && walletInfo.status === "success") {
|
|
1823
|
-
const isMintSupported = walletInfo.result.methods?.includes("runes_mint");
|
|
1824
|
-
if (isMintSupported) {
|
|
1825
|
-
const response = await this.requestInternal("runes_mint", params);
|
|
1826
|
-
if (response) {
|
|
1827
|
-
if (response.status === "success") {
|
|
1828
|
-
return response;
|
|
1829
|
-
}
|
|
1830
|
-
if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
|
|
1831
|
-
return response;
|
|
1832
|
-
}
|
|
1833
|
-
}
|
|
1834
|
-
}
|
|
1835
|
-
}
|
|
1836
|
-
const mintRequest = {
|
|
1837
|
-
destinationAddress: params.destinationAddress,
|
|
1838
|
-
feeRate: params.feeRate,
|
|
1839
|
-
refundAddress: params.refundAddress,
|
|
1840
|
-
repeats: params.repeats,
|
|
1841
|
-
runeName: params.runeName,
|
|
1842
|
-
appServiceFee: params.appServiceFee,
|
|
1843
|
-
appServiceFeeAddress: params.appServiceFeeAddress
|
|
1844
|
-
};
|
|
1845
|
-
const orderResponse = await new RunesApi(params.network).createMintOrder(mintRequest);
|
|
1846
|
-
if (!orderResponse.data) {
|
|
1847
|
-
return {
|
|
1848
|
-
status: "error",
|
|
1849
|
-
error: {
|
|
1850
|
-
code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
1851
|
-
message: orderResponse.error.message
|
|
1852
|
-
}
|
|
1853
|
-
};
|
|
1854
|
-
}
|
|
1855
|
-
const paymentResponse = await this.requestInternal("sendTransfer", {
|
|
1856
|
-
recipients: [
|
|
1857
|
-
{
|
|
1858
|
-
address: orderResponse.data.fundAddress,
|
|
1859
|
-
amount: orderResponse.data.fundAmount
|
|
1860
|
-
}
|
|
1861
|
-
]
|
|
1862
|
-
});
|
|
1863
|
-
if (paymentResponse.status !== "success") {
|
|
1864
|
-
return paymentResponse;
|
|
1865
|
-
}
|
|
1866
|
-
await new RunesApi(params.network).executeMint(
|
|
1867
|
-
orderResponse.data.orderId,
|
|
1868
|
-
paymentResponse.result.txid
|
|
1869
|
-
);
|
|
1870
|
-
return {
|
|
1871
|
-
status: "success",
|
|
1872
|
-
result: {
|
|
1873
|
-
orderId: orderResponse.data.orderId,
|
|
1874
|
-
fundTransactionId: paymentResponse.result.txid,
|
|
1875
|
-
fundingAddress: orderResponse.data.fundAddress
|
|
1876
|
-
}
|
|
1877
|
-
};
|
|
1878
|
-
} catch (error) {
|
|
1879
|
-
return {
|
|
1880
|
-
status: "error",
|
|
1881
|
-
error: {
|
|
1882
|
-
code: -32603 /* INTERNAL_ERROR */,
|
|
1883
|
-
message: error.message
|
|
1884
|
-
}
|
|
1885
|
-
};
|
|
1886
|
-
}
|
|
1969
|
+
// src/request/types/stxMethods/transferStx.ts
|
|
1970
|
+
var v24 = __toESM(require("valibot"));
|
|
1971
|
+
var stxTransferStxMethodName = "stx_transferStx";
|
|
1972
|
+
var stxTransferStxParamsSchema = v24.object({
|
|
1973
|
+
/**
|
|
1974
|
+
* Amount of STX tokens to transfer in microstacks as a string. Anything
|
|
1975
|
+
* parseable by `BigInt` is acceptable.
|
|
1976
|
+
*
|
|
1977
|
+
* Example,
|
|
1978
|
+
*
|
|
1979
|
+
* ```js
|
|
1980
|
+
* const amount1 = 1234;
|
|
1981
|
+
* const amount2 = 1234n;
|
|
1982
|
+
* const amount3 = '1234';
|
|
1983
|
+
* ```
|
|
1984
|
+
*/
|
|
1985
|
+
amount: v24.union([v24.number(), v24.string()]),
|
|
1986
|
+
/**
|
|
1987
|
+
* The recipient's principal.
|
|
1988
|
+
*/
|
|
1989
|
+
recipient: v24.string(),
|
|
1990
|
+
/**
|
|
1991
|
+
* A string representing the memo.
|
|
1992
|
+
*/
|
|
1993
|
+
memo: v24.optional(v24.string()),
|
|
1994
|
+
/**
|
|
1995
|
+
* Version of parameter format.
|
|
1996
|
+
*/
|
|
1997
|
+
version: v24.optional(v24.string()),
|
|
1998
|
+
/**
|
|
1999
|
+
* The mode of the post conditions.
|
|
2000
|
+
*/
|
|
2001
|
+
postConditionMode: v24.optional(v24.number()),
|
|
2002
|
+
/**
|
|
2003
|
+
* A hex-encoded string representing the post conditions.
|
|
2004
|
+
*
|
|
2005
|
+
* A post condition may be converted to it's hex representation using the `serializePostCondition` helper from the `@stacks/transactions` package,
|
|
2006
|
+
*
|
|
2007
|
+
* ```js
|
|
2008
|
+
* import { serializePostCondition } from '@stacks/transactions';
|
|
2009
|
+
*
|
|
2010
|
+
* const postCondition = somePostCondition;
|
|
2011
|
+
* const hexPostCondition = serializePostCondition(postCondition).toString('hex');
|
|
2012
|
+
* ```
|
|
2013
|
+
*/
|
|
2014
|
+
postConditions: v24.optional(v24.array(v24.string())),
|
|
2015
|
+
/**
|
|
2016
|
+
* The public key to sign the transaction with. The wallet may use any key
|
|
2017
|
+
* when not provided.
|
|
2018
|
+
*/
|
|
2019
|
+
pubkey: v24.optional(v24.string())
|
|
2020
|
+
});
|
|
2021
|
+
var stxTransferStxResultSchema = v24.object({
|
|
2022
|
+
/**
|
|
2023
|
+
* The ID of the transaction.
|
|
2024
|
+
*/
|
|
2025
|
+
txid: v24.string(),
|
|
2026
|
+
/**
|
|
2027
|
+
* A Stacks transaction as a hex-encoded string.
|
|
2028
|
+
*/
|
|
2029
|
+
transaction: v24.string()
|
|
2030
|
+
});
|
|
2031
|
+
var stxTransferStxRequestMessageSchema = v24.object({
|
|
2032
|
+
...rpcRequestMessageSchema.entries,
|
|
2033
|
+
...v24.object({
|
|
2034
|
+
method: v24.literal(stxTransferStxMethodName),
|
|
2035
|
+
params: stxTransferStxParamsSchema,
|
|
2036
|
+
id: v24.string()
|
|
2037
|
+
}).entries
|
|
2038
|
+
});
|
|
2039
|
+
|
|
2040
|
+
// src/request/index.ts
|
|
2041
|
+
var request = async (method, params, providerId) => {
|
|
2042
|
+
let provider = window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
|
|
2043
|
+
if (providerId) {
|
|
2044
|
+
provider = await getProviderById(providerId);
|
|
1887
2045
|
}
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
destinationAddress: params.destinationAddress,
|
|
1891
|
-
refundAddress: params.refundAddress,
|
|
1892
|
-
feeRate: params.feeRate,
|
|
1893
|
-
runeName: params.runeName,
|
|
1894
|
-
divisibility: params.divisibility,
|
|
1895
|
-
symbol: params.symbol,
|
|
1896
|
-
premine: params.premine,
|
|
1897
|
-
isMintable: params.isMintable,
|
|
1898
|
-
terms: params.terms,
|
|
1899
|
-
inscriptionDetails: params.inscriptionDetails,
|
|
1900
|
-
delegateInscriptionId: params.delegateInscriptionId,
|
|
1901
|
-
appServiceFee: params.appServiceFee,
|
|
1902
|
-
appServiceFeeAddress: params.appServiceFeeAddress
|
|
1903
|
-
};
|
|
1904
|
-
try {
|
|
1905
|
-
const walletInfo = await this.requestInternal("getInfo", null).catch(() => null);
|
|
1906
|
-
if (walletInfo && walletInfo.status === "success") {
|
|
1907
|
-
const isEtchSupported = walletInfo.result.methods?.includes("runes_etch");
|
|
1908
|
-
if (isEtchSupported) {
|
|
1909
|
-
const response = await this.requestInternal("runes_etch", params);
|
|
1910
|
-
if (response) {
|
|
1911
|
-
if (response.status === "success") {
|
|
1912
|
-
return response;
|
|
1913
|
-
}
|
|
1914
|
-
if (response.status === "error" && response.error.code !== -32601 /* METHOD_NOT_FOUND */) {
|
|
1915
|
-
return response;
|
|
1916
|
-
}
|
|
1917
|
-
}
|
|
1918
|
-
}
|
|
1919
|
-
}
|
|
1920
|
-
const orderResponse = await new RunesApi(params.network).createEtchOrder(etchRequest);
|
|
1921
|
-
if (!orderResponse.data) {
|
|
1922
|
-
return {
|
|
1923
|
-
status: "error",
|
|
1924
|
-
error: {
|
|
1925
|
-
code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
1926
|
-
message: orderResponse.error.message
|
|
1927
|
-
}
|
|
1928
|
-
};
|
|
1929
|
-
}
|
|
1930
|
-
const paymentResponse = await this.requestInternal("sendTransfer", {
|
|
1931
|
-
recipients: [
|
|
1932
|
-
{
|
|
1933
|
-
address: orderResponse.data.fundAddress,
|
|
1934
|
-
amount: orderResponse.data.fundAmount
|
|
1935
|
-
}
|
|
1936
|
-
]
|
|
1937
|
-
});
|
|
1938
|
-
if (paymentResponse.status !== "success") {
|
|
1939
|
-
return paymentResponse;
|
|
1940
|
-
}
|
|
1941
|
-
await new RunesApi(params.network).executeEtch(
|
|
1942
|
-
orderResponse.data.orderId,
|
|
1943
|
-
paymentResponse.result.txid
|
|
1944
|
-
);
|
|
1945
|
-
return {
|
|
1946
|
-
status: "success",
|
|
1947
|
-
result: {
|
|
1948
|
-
orderId: orderResponse.data.orderId,
|
|
1949
|
-
fundTransactionId: paymentResponse.result.txid,
|
|
1950
|
-
fundingAddress: orderResponse.data.fundAddress
|
|
1951
|
-
}
|
|
1952
|
-
};
|
|
1953
|
-
} catch (error) {
|
|
1954
|
-
return {
|
|
1955
|
-
status: "error",
|
|
1956
|
-
error: {
|
|
1957
|
-
code: -32603 /* INTERNAL_ERROR */,
|
|
1958
|
-
message: error.message
|
|
1959
|
-
}
|
|
1960
|
-
};
|
|
1961
|
-
}
|
|
2046
|
+
if (!provider) {
|
|
2047
|
+
throw new Error("no wallet provider was found");
|
|
1962
2048
|
}
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
destinationAddress: params.destinationAddress,
|
|
1966
|
-
feeRate: params.feeRate,
|
|
1967
|
-
repeats: params.repeats,
|
|
1968
|
-
runeName: params.runeName,
|
|
1969
|
-
appServiceFee: params.appServiceFee,
|
|
1970
|
-
appServiceFeeAddress: params.appServiceFeeAddress
|
|
1971
|
-
};
|
|
1972
|
-
const response = await getRunesApiClient(
|
|
1973
|
-
params.network
|
|
1974
|
-
).estimateMintCost(estimateMintRequest);
|
|
1975
|
-
if (response.data) {
|
|
1976
|
-
return {
|
|
1977
|
-
status: "success",
|
|
1978
|
-
result: response.data
|
|
1979
|
-
};
|
|
1980
|
-
}
|
|
1981
|
-
return {
|
|
1982
|
-
status: "error",
|
|
1983
|
-
error: {
|
|
1984
|
-
code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
1985
|
-
message: response.error.message
|
|
1986
|
-
}
|
|
1987
|
-
};
|
|
2049
|
+
if (!method) {
|
|
2050
|
+
throw new Error("A wallet method is required");
|
|
1988
2051
|
}
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
destinationAddress: params.destinationAddress,
|
|
1992
|
-
feeRate: params.feeRate,
|
|
1993
|
-
runeName: params.runeName,
|
|
1994
|
-
divisibility: params.divisibility,
|
|
1995
|
-
symbol: params.symbol,
|
|
1996
|
-
premine: params.premine,
|
|
1997
|
-
isMintable: params.isMintable,
|
|
1998
|
-
terms: params.terms,
|
|
1999
|
-
inscriptionDetails: params.inscriptionDetails,
|
|
2000
|
-
delegateInscriptionId: params.delegateInscriptionId,
|
|
2001
|
-
appServiceFee: params.appServiceFee,
|
|
2002
|
-
appServiceFeeAddress: params.appServiceFeeAddress
|
|
2003
|
-
};
|
|
2004
|
-
const response = await getRunesApiClient(params.network).estimateEtchCost(estimateEtchRequest);
|
|
2005
|
-
if (response.data) {
|
|
2006
|
-
return {
|
|
2007
|
-
status: "success",
|
|
2008
|
-
result: response.data
|
|
2009
|
-
};
|
|
2010
|
-
}
|
|
2052
|
+
const response = await provider.request(method, params);
|
|
2053
|
+
if (v25.is(rpcErrorResponseMessageSchema, response)) {
|
|
2011
2054
|
return {
|
|
2012
2055
|
status: "error",
|
|
2013
|
-
error:
|
|
2014
|
-
code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
2015
|
-
message: response.error.message
|
|
2016
|
-
}
|
|
2056
|
+
error: response.error
|
|
2017
2057
|
};
|
|
2018
2058
|
}
|
|
2019
|
-
|
|
2020
|
-
const response = await getRunesApiClient(params.network).getOrder(params.id);
|
|
2021
|
-
if (response.data) {
|
|
2022
|
-
return {
|
|
2023
|
-
status: "success",
|
|
2024
|
-
result: response.data
|
|
2025
|
-
};
|
|
2026
|
-
}
|
|
2059
|
+
if (v25.is(rpcSuccessResponseMessageSchema, response)) {
|
|
2027
2060
|
return {
|
|
2028
|
-
status: "
|
|
2029
|
-
|
|
2030
|
-
code: response.error.code === 400 || response.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
2031
|
-
message: response.error.message
|
|
2032
|
-
}
|
|
2061
|
+
status: "success",
|
|
2062
|
+
result: response.result
|
|
2033
2063
|
};
|
|
2034
2064
|
}
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
if (response.data) {
|
|
2042
|
-
return {
|
|
2043
|
-
status: "success",
|
|
2044
|
-
result: {
|
|
2045
|
-
fundingAddress: response.data.fundingAddress,
|
|
2046
|
-
rbfCost: response.data.rbfCost
|
|
2047
|
-
}
|
|
2048
|
-
};
|
|
2065
|
+
return {
|
|
2066
|
+
status: "error",
|
|
2067
|
+
error: {
|
|
2068
|
+
code: -32603 /* INTERNAL_ERROR */,
|
|
2069
|
+
message: "Received unknown response from provider.",
|
|
2070
|
+
data: response
|
|
2049
2071
|
}
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
}
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
const rbfOrderRequest = {
|
|
2061
|
-
newFeeRate: params.newFeeRate,
|
|
2062
|
-
orderId: params.orderId
|
|
2063
|
-
};
|
|
2064
|
-
const orderResponse = await getRunesApiClient(params.network).rbfOrder(rbfOrderRequest);
|
|
2065
|
-
if (!orderResponse.data) {
|
|
2066
|
-
return {
|
|
2067
|
-
status: "error",
|
|
2068
|
-
error: {
|
|
2069
|
-
code: orderResponse.error.code === 400 || orderResponse.error.code === 404 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
2070
|
-
message: orderResponse.error.message
|
|
2071
|
-
}
|
|
2072
|
-
};
|
|
2073
|
-
}
|
|
2074
|
-
const paymentResponse = await this.requestInternal("sendTransfer", {
|
|
2075
|
-
recipients: [
|
|
2072
|
+
};
|
|
2073
|
+
};
|
|
2074
|
+
var addListener = (...rawArgs) => {
|
|
2075
|
+
const [listenerInfo, providerId] = (() => {
|
|
2076
|
+
if (rawArgs.length === 1) {
|
|
2077
|
+
return [rawArgs[0], void 0];
|
|
2078
|
+
}
|
|
2079
|
+
if (rawArgs.length === 2) {
|
|
2080
|
+
if (typeof rawArgs[1] === "function") {
|
|
2081
|
+
return [
|
|
2076
2082
|
{
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
}
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
return
|
|
2083
|
+
eventName: rawArgs[0],
|
|
2084
|
+
cb: rawArgs[1]
|
|
2085
|
+
},
|
|
2086
|
+
void 0
|
|
2087
|
+
];
|
|
2088
|
+
} else {
|
|
2089
|
+
return rawArgs;
|
|
2084
2090
|
}
|
|
2085
|
-
return {
|
|
2086
|
-
status: "success",
|
|
2087
|
-
result: {
|
|
2088
|
-
fundingAddress: orderResponse.data.fundingAddress,
|
|
2089
|
-
orderId: rbfOrderRequest.orderId,
|
|
2090
|
-
fundRBFTransactionId: paymentResponse.result.txid
|
|
2091
|
-
}
|
|
2092
|
-
};
|
|
2093
|
-
} catch (error) {
|
|
2094
|
-
return {
|
|
2095
|
-
status: "error",
|
|
2096
|
-
error: {
|
|
2097
|
-
code: -32603 /* INTERNAL_ERROR */,
|
|
2098
|
-
message: error.message
|
|
2099
|
-
}
|
|
2100
|
-
};
|
|
2101
2091
|
}
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
return this.estimateMint(params);
|
|
2111
|
-
case "runes_estimateEtch":
|
|
2112
|
-
return this.estimateEtch(params);
|
|
2113
|
-
case "runes_getOrder": {
|
|
2114
|
-
return this.getOrder(params);
|
|
2115
|
-
}
|
|
2116
|
-
case "runes_estimateRbfOrder": {
|
|
2117
|
-
return this.estimateRbfOrder(params);
|
|
2118
|
-
}
|
|
2119
|
-
case "runes_rbfOrder": {
|
|
2120
|
-
return this.rbfOrder(params);
|
|
2121
|
-
}
|
|
2122
|
-
default:
|
|
2123
|
-
return this.requestInternal(method, params);
|
|
2092
|
+
if (rawArgs.length === 3) {
|
|
2093
|
+
return [
|
|
2094
|
+
{
|
|
2095
|
+
eventName: rawArgs[0],
|
|
2096
|
+
cb: rawArgs[1]
|
|
2097
|
+
},
|
|
2098
|
+
rawArgs[2]
|
|
2099
|
+
];
|
|
2124
2100
|
}
|
|
2101
|
+
throw new Error("Unexpected number of arguments. Expecting 2 (or 3 for legacy requests).", {
|
|
2102
|
+
cause: rawArgs
|
|
2103
|
+
});
|
|
2104
|
+
})();
|
|
2105
|
+
let provider = window.XverseProviders?.BitcoinProvider || window.BitcoinProvider;
|
|
2106
|
+
if (providerId) {
|
|
2107
|
+
provider = getProviderById(providerId);
|
|
2125
2108
|
}
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2109
|
+
if (!provider) {
|
|
2110
|
+
throw new Error("no wallet provider was found");
|
|
2111
|
+
}
|
|
2112
|
+
if (!provider.addListener) {
|
|
2113
|
+
console.error(
|
|
2114
|
+
`The wallet provider you are using does not support the addListener method. Please update your wallet provider.`
|
|
2115
|
+
);
|
|
2116
|
+
return () => {
|
|
2117
|
+
};
|
|
2118
|
+
}
|
|
2119
|
+
return provider.addListener(listenerInfo);
|
|
2137
2120
|
};
|
|
2138
2121
|
|
|
2139
2122
|
// src/adapters/unisat.ts
|
|
2140
|
-
var import_bitcoin_address_validation = require("bitcoin-address-validation");
|
|
2141
|
-
var import_buffer = require("buffer");
|
|
2142
2123
|
function convertSignInputsToInputType(signInputs) {
|
|
2143
2124
|
let result = [];
|
|
2144
2125
|
if (!signInputs) {
|
|
@@ -2324,32 +2305,77 @@ var UnisatAdapter = class extends SatsConnectAdapter {
|
|
|
2324
2305
|
};
|
|
2325
2306
|
};
|
|
2326
2307
|
|
|
2327
|
-
// src/adapters/
|
|
2328
|
-
var
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
const
|
|
2332
|
-
if (
|
|
2333
|
-
|
|
2308
|
+
// src/adapters/xverse/sanitizeRequest.ts
|
|
2309
|
+
var sanitizeRequest = (method, params, providerInfo) => {
|
|
2310
|
+
try {
|
|
2311
|
+
const [major, minor, patch] = providerInfo.version.split(".").map((part) => parseInt(part, 10));
|
|
2312
|
+
const platform = providerInfo.platform;
|
|
2313
|
+
if (
|
|
2314
|
+
// platform is missing for versions < 1.5.0 on web and < 1.55.0 on mobile
|
|
2315
|
+
!platform || platform === "web" /* Web */ && major <= 1 && minor <= 4 || platform === "mobile" /* Mobile */ && major <= 1 && minor <= 54
|
|
2316
|
+
) {
|
|
2317
|
+
const v1Sanitized = sanitizeAddressPurposeRequest(method, params);
|
|
2318
|
+
method = v1Sanitized.method;
|
|
2319
|
+
params = v1Sanitized.params;
|
|
2334
2320
|
}
|
|
2335
|
-
|
|
2336
|
-
|
|
2321
|
+
} catch {
|
|
2322
|
+
}
|
|
2323
|
+
return { method, params };
|
|
2324
|
+
};
|
|
2325
|
+
var sanitizeAddressPurposeRequest = (method, params) => {
|
|
2326
|
+
const filterPurposes = (purposes) => purposes?.filter(
|
|
2327
|
+
(purpose) => purpose !== "spark" /* Spark */ && purpose !== "starknet" /* Starknet */
|
|
2328
|
+
);
|
|
2329
|
+
if (method === "wallet_connect") {
|
|
2330
|
+
const typedParams = params;
|
|
2331
|
+
if (!typedParams) {
|
|
2332
|
+
return { method, params };
|
|
2337
2333
|
}
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2334
|
+
const { addresses, ...rest } = typedParams;
|
|
2335
|
+
const overrideParams = {
|
|
2336
|
+
...rest,
|
|
2337
|
+
addresses: filterPurposes(addresses)
|
|
2338
|
+
};
|
|
2339
|
+
return { method, params: overrideParams };
|
|
2340
|
+
}
|
|
2341
|
+
if (method === "getAccounts") {
|
|
2342
|
+
const typedParams = params;
|
|
2343
|
+
const { purposes, ...rest } = typedParams;
|
|
2344
|
+
const overrideParams = { ...rest, purposes: filterPurposes(purposes) };
|
|
2345
|
+
return { method, params: overrideParams };
|
|
2346
|
+
}
|
|
2347
|
+
if (method === "getAddresses") {
|
|
2348
|
+
const typedParams = params;
|
|
2349
|
+
const { purposes, ...rest } = typedParams;
|
|
2350
|
+
const overrideParams = { ...rest, purposes: filterPurposes(purposes) };
|
|
2351
|
+
return { method, params: overrideParams };
|
|
2352
|
+
}
|
|
2353
|
+
return { method, params };
|
|
2354
|
+
};
|
|
2355
|
+
|
|
2356
|
+
// src/adapters/xverse/index.ts
|
|
2357
|
+
var XverseAdapter = class extends SatsConnectAdapter {
|
|
2358
|
+
id = DefaultAdaptersInfo.xverse.id;
|
|
2359
|
+
providerInfo;
|
|
2360
|
+
requestInternal = async (method, params) => {
|
|
2361
|
+
if (!this.providerInfo) {
|
|
2362
|
+
const infoResult = await request("getInfo", null, this.id);
|
|
2363
|
+
if (infoResult.status === "success") {
|
|
2364
|
+
this.providerInfo = infoResult.result;
|
|
2365
|
+
}
|
|
2344
2366
|
}
|
|
2345
|
-
if (
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2367
|
+
if (this.providerInfo) {
|
|
2368
|
+
const sanitized = sanitizeRequest(method, params, this.providerInfo);
|
|
2369
|
+
if (sanitized.overrideResponse) {
|
|
2370
|
+
return sanitized.overrideResponse;
|
|
2371
|
+
}
|
|
2372
|
+
method = sanitized.method;
|
|
2373
|
+
params = sanitized.params;
|
|
2351
2374
|
}
|
|
2352
|
-
return
|
|
2375
|
+
return request(method, params, this.id);
|
|
2376
|
+
};
|
|
2377
|
+
addListener = (listenerInfo) => {
|
|
2378
|
+
return addListener(listenerInfo, this.id);
|
|
2353
2379
|
};
|
|
2354
2380
|
};
|
|
2355
2381
|
|
|
@@ -2412,7 +2438,6 @@ var extractOrValidateCapabilities = (provider, reportedCapabilities) => {
|
|
|
2412
2438
|
return true;
|
|
2413
2439
|
};
|
|
2414
2440
|
const capabilityMap = {
|
|
2415
|
-
version: validateCapability("version"),
|
|
2416
2441
|
request: validateCapability("request"),
|
|
2417
2442
|
connect: validateCapability("connect"),
|
|
2418
2443
|
signMessage: validateCapability("signMessage"),
|
|
@@ -2617,6 +2642,7 @@ var signMultipleTransactions = async (options) => {
|
|
|
2617
2642
|
DefaultAdaptersInfo,
|
|
2618
2643
|
MessageSigningProtocols,
|
|
2619
2644
|
PermissionRequestParams,
|
|
2645
|
+
ProviderPlatform,
|
|
2620
2646
|
RpcErrorCode,
|
|
2621
2647
|
RpcIdSchema,
|
|
2622
2648
|
SatsConnectAdapter,
|