@sats-connect/core 0.0.3 → 0.0.4-c8131da
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 +107 -5
- package/dist/index.mjs +357 -22
- package/package.json +2 -1
package/dist/index.d.mts
CHANGED
|
@@ -381,6 +381,94 @@ type GetAccountsParams = {
|
|
|
381
381
|
type GetAccountResult = Address$1[];
|
|
382
382
|
type GetAccounts = MethodParamsAndResult<GetAccountsParams, GetAccountResult>;
|
|
383
383
|
|
|
384
|
+
type CreateMintOrderRequest = {
|
|
385
|
+
runeName: string;
|
|
386
|
+
repeats: number;
|
|
387
|
+
refundAddress: string;
|
|
388
|
+
destinationAddress: string;
|
|
389
|
+
feeRate: number;
|
|
390
|
+
appServiceFee?: number;
|
|
391
|
+
appServiceFeeAddress?: string;
|
|
392
|
+
};
|
|
393
|
+
type EstimateMintOrderRequest = Omit<CreateMintOrderRequest, 'refundAddress'>;
|
|
394
|
+
type EstimateOrderResponse = {
|
|
395
|
+
totalSize: number;
|
|
396
|
+
totalCost: number;
|
|
397
|
+
costBreakdown: {
|
|
398
|
+
postage: number;
|
|
399
|
+
networkFee: number;
|
|
400
|
+
serviceFee: number;
|
|
401
|
+
appServiceFee: number;
|
|
402
|
+
};
|
|
403
|
+
};
|
|
404
|
+
type CreateEtchOrderRequest = {
|
|
405
|
+
runeName: string;
|
|
406
|
+
divisibility?: number;
|
|
407
|
+
symbol?: string;
|
|
408
|
+
premine?: string;
|
|
409
|
+
isMintable: boolean;
|
|
410
|
+
terms?: {
|
|
411
|
+
amount?: string;
|
|
412
|
+
cap?: string;
|
|
413
|
+
heightStart?: string;
|
|
414
|
+
heightEnd?: string;
|
|
415
|
+
offsetStart?: string;
|
|
416
|
+
offsetEnd?: string;
|
|
417
|
+
};
|
|
418
|
+
inscriptionDetails?: {
|
|
419
|
+
contentType: string;
|
|
420
|
+
contentBase64: string;
|
|
421
|
+
};
|
|
422
|
+
delegateInscriptionId?: string;
|
|
423
|
+
destinationAddress: string;
|
|
424
|
+
refundAddress: string;
|
|
425
|
+
feeRate: number;
|
|
426
|
+
appServiceFee?: number;
|
|
427
|
+
appServiceFeeAddress?: string;
|
|
428
|
+
};
|
|
429
|
+
type EstimateEtchOrderRequest = Omit<CreateEtchOrderRequest, 'refundAddress'>;
|
|
430
|
+
type GetOrderRequest = {
|
|
431
|
+
id: string;
|
|
432
|
+
};
|
|
433
|
+
type GetOrderResponse = {
|
|
434
|
+
id: string;
|
|
435
|
+
orderType: 'rune_mint' | 'rune_etch';
|
|
436
|
+
state: 'new' | 'pending' | 'executing' | 'complete' | 'failed' | 'refunded' | 'stale';
|
|
437
|
+
reason?: string;
|
|
438
|
+
createdAt: string;
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
interface EstimateRunesMintParams extends EstimateMintOrderRequest {
|
|
442
|
+
network?: BitcoinNetworkType;
|
|
443
|
+
}
|
|
444
|
+
type EstimateRunesMintResult = EstimateOrderResponse;
|
|
445
|
+
type EstimateRunesMint = MethodParamsAndResult<EstimateRunesMintParams, EstimateRunesMintResult>;
|
|
446
|
+
interface MintRunesParams extends CreateMintOrderRequest {
|
|
447
|
+
network?: BitcoinNetworkType;
|
|
448
|
+
}
|
|
449
|
+
type MintRunesResult = {
|
|
450
|
+
orderId: string;
|
|
451
|
+
fundTransactionId: string;
|
|
452
|
+
};
|
|
453
|
+
type MintRunes = MethodParamsAndResult<MintRunesParams, MintRunesResult>;
|
|
454
|
+
interface EstimateRunesEtchParams extends EstimateEtchOrderRequest {
|
|
455
|
+
network?: BitcoinNetworkType;
|
|
456
|
+
}
|
|
457
|
+
type EstimateRunesEtchResult = EstimateOrderResponse;
|
|
458
|
+
type EstimateRunesEtch = MethodParamsAndResult<EstimateRunesEtchParams, EstimateRunesEtchResult>;
|
|
459
|
+
interface EtchRunesParams extends CreateEtchOrderRequest {
|
|
460
|
+
network?: BitcoinNetworkType;
|
|
461
|
+
}
|
|
462
|
+
type EtchRunesResult = {
|
|
463
|
+
orderId: string;
|
|
464
|
+
fundTransactionId: string;
|
|
465
|
+
};
|
|
466
|
+
type EtchRunes = MethodParamsAndResult<EtchRunesParams, EtchRunesResult>;
|
|
467
|
+
interface GetOrderParams extends GetOrderRequest {
|
|
468
|
+
network?: BitcoinNetworkType;
|
|
469
|
+
}
|
|
470
|
+
type GetOrder = MethodParamsAndResult<GetOrderParams, GetOrderResponse>;
|
|
471
|
+
|
|
384
472
|
interface Pubkey {
|
|
385
473
|
/**
|
|
386
474
|
* When sending a transfer STX request to a wallet, users can generally
|
|
@@ -581,21 +669,35 @@ interface BtcRequests {
|
|
|
581
669
|
signPsbt: SignPsbt;
|
|
582
670
|
}
|
|
583
671
|
type BtcRequestMethod = keyof BtcRequests;
|
|
584
|
-
|
|
672
|
+
interface RunesRequests {
|
|
673
|
+
runes_estimateMint: EstimateRunesMint;
|
|
674
|
+
runes_mint: MintRunes;
|
|
675
|
+
runes_estimateEtch: EstimateRunesEtch;
|
|
676
|
+
runes_etch: EtchRunes;
|
|
677
|
+
runes_getOrder: GetOrder;
|
|
678
|
+
}
|
|
679
|
+
type RunesRequestMethod = keyof RunesRequests;
|
|
680
|
+
type Requests = BtcRequests & StxRequests & RunesRequests;
|
|
585
681
|
type Return<Method> = Method extends keyof Requests ? Requests[Method]['result'] : never;
|
|
586
682
|
type Params<Method> = Method extends keyof Requests ? Requests[Method]['params'] : never;
|
|
587
683
|
|
|
588
|
-
declare const request: <Method extends keyof BtcRequests | keyof StxRequests>(method: Method, params: Params<Method>, providerId?: string) => Promise<RpcResult<Method>>;
|
|
684
|
+
declare const request: <Method extends keyof BtcRequests | keyof StxRequests | keyof RunesRequests>(method: Method, params: Params<Method>, providerId?: string) => Promise<RpcResult<Method>>;
|
|
589
685
|
|
|
590
686
|
declare abstract class SatsConnectAdapter {
|
|
591
687
|
abstract readonly id: string;
|
|
592
|
-
|
|
688
|
+
private mintRunes;
|
|
689
|
+
private etchRunes;
|
|
690
|
+
private estimateMint;
|
|
691
|
+
private estimateEtch;
|
|
692
|
+
private getOrder;
|
|
693
|
+
request<Method extends keyof Requests>(method: Method, params: Params<Method>): Promise<RpcResult<Method> | undefined>;
|
|
694
|
+
protected abstract requestInternal<Method extends keyof Requests>(method: Method, params: Params<Method>): Promise<RpcResult<Method> | undefined>;
|
|
593
695
|
}
|
|
594
696
|
|
|
595
697
|
declare class BaseAdapter extends SatsConnectAdapter {
|
|
596
698
|
id: string;
|
|
597
699
|
constructor(providerId: string);
|
|
598
|
-
|
|
700
|
+
requestInternal: <Method extends keyof BtcRequests | keyof StxRequests | keyof RunesRequests>(method: Method, params: Params<Method>) => Promise<RpcResult<Method> | undefined>;
|
|
599
701
|
}
|
|
600
702
|
|
|
601
703
|
declare const DefaultAdaptersInfo: Record<string, Provider>;
|
|
@@ -606,4 +708,4 @@ interface Config {
|
|
|
606
708
|
}
|
|
607
709
|
declare function createDefaultConfig(providers: SupportedWallet[]): Config;
|
|
608
710
|
|
|
609
|
-
export { type Address$1 as Address, AddressPurpose, AddressType, BaseAdapter, type BitcoinNetwork, BitcoinNetworkType, type BitcoinProvider, type BtcRequestMethod, type BtcRequests, type CallContractParams, type CallContractResult, type Capability, type Config, type CreateInscriptionOptions, type CreateInscriptionPayload, type CreateInscriptionResponse, type CreateRepeatInscriptionsOptions, type CreateRepeatInscriptionsPayload, type CreateRepeatInscriptionsResponse, DefaultAdaptersInfo, type DeployContractParams, type DeployContractResult, type GetAccountResult, type GetAccounts, type GetAccountsParams, type GetAccountsResult, type GetAddressOptions, type GetAddressPayload, type GetAddressResponse, type GetAddresses, type GetAddressesParams, type GetAddressesResult, type GetCapabilitiesOptions, type GetCapabilitiesPayload, type GetCapabilitiesResponse, type GetInfo, type InputToSign, type MethodParamsAndResult, type Params, type Provider, type PsbtPayload, type Recipient$2 as Recipient, type RequestOptions, type RequestPayload, type Requests, type Return, type RpcBase, type RpcError, RpcErrorCode, type RpcErrorResponse, type RpcId, type RpcRequest, type RpcResponse, type RpcResult, type RpcSuccessResponse, SatsConnectAdapter, type SendBtcTransactionOptions, type SendBtcTransactionPayload, type SendBtcTransactionResponse, type SendTransfer, type SendTransferParams, type SerializedRecipient, type SerializedSendBtcTransactionPayload, type SignMessage, type SignMessageOptions, type SignMessageParams, type SignMessagePayload, type SignMessageResponse, type SignMultiplePsbtPayload, type SignMultipleTransactionOptions, type SignMultipleTransactionsPayload, type SignMultipleTransactionsResponse, type SignPsbt, type SignPsbtParams, type SignPsbtResult, type SignStructuredMessageResult, type SignStxMessageParams, type SignStxMessageResult, type SignTransactionOptions, type SignTransactionParams, type SignTransactionPayload, type SignTransactionResponse, type SignTransactionResult, type StxCallContract, type StxDeployContract, type StxGetAccounts, type StxGetAddresses, type StxRequestMethod, type StxRequests, type StxSignStructuredMessage, type StxSignStxMessage, type StxSignTransaction, type StxTransferStx, type SupportedWallet, type TransferStxParams, type TransferStxResult, createDefaultConfig, createInscription, createRepeatInscriptions, defaultAdapters, getAddress, getCapabilities, getDefaultProvider, getProviderById, getProviderOrThrow, getProviders, getSupportedWallets, isProviderInstalled, removeDefaultProvider, request, sendBtcTransaction, setDefaultProvider, signMessage, signMultipleTransactions, signTransaction };
|
|
711
|
+
export { type Address$1 as Address, AddressPurpose, AddressType, BaseAdapter, type BitcoinNetwork, BitcoinNetworkType, type BitcoinProvider, type BtcRequestMethod, type BtcRequests, type CallContractParams, type CallContractResult, type Capability, type Config, type CreateInscriptionOptions, type CreateInscriptionPayload, type CreateInscriptionResponse, type CreateRepeatInscriptionsOptions, type CreateRepeatInscriptionsPayload, type CreateRepeatInscriptionsResponse, DefaultAdaptersInfo, type DeployContractParams, type DeployContractResult, type GetAccountResult, type GetAccounts, type GetAccountsParams, type GetAccountsResult, type GetAddressOptions, type GetAddressPayload, type GetAddressResponse, type GetAddresses, type GetAddressesParams, type GetAddressesResult, type GetCapabilitiesOptions, type GetCapabilitiesPayload, type GetCapabilitiesResponse, type GetInfo, type InputToSign, type MethodParamsAndResult, type Params, type Provider, type PsbtPayload, type Recipient$2 as Recipient, type RequestOptions, type RequestPayload, type Requests, type Return, type RpcBase, type RpcError, RpcErrorCode, type RpcErrorResponse, type RpcId, type RpcRequest, type RpcResponse, type RpcResult, type RpcSuccessResponse, type RunesRequestMethod, type RunesRequests, SatsConnectAdapter, type SendBtcTransactionOptions, type SendBtcTransactionPayload, type SendBtcTransactionResponse, type SendTransfer, type SendTransferParams, type SerializedRecipient, type SerializedSendBtcTransactionPayload, type SignMessage, type SignMessageOptions, type SignMessageParams, type SignMessagePayload, type SignMessageResponse, type SignMultiplePsbtPayload, type SignMultipleTransactionOptions, type SignMultipleTransactionsPayload, type SignMultipleTransactionsResponse, type SignPsbt, type SignPsbtParams, type SignPsbtResult, type SignStructuredMessageResult, type SignStxMessageParams, type SignStxMessageResult, type SignTransactionOptions, type SignTransactionParams, type SignTransactionPayload, type SignTransactionResponse, type SignTransactionResult, type StxCallContract, type StxDeployContract, type StxGetAccounts, type StxGetAddresses, type StxRequestMethod, type StxRequests, type StxSignStructuredMessage, type StxSignStxMessage, type StxSignTransaction, type StxTransferStx, type SupportedWallet, type TransferStxParams, type TransferStxResult, createDefaultConfig, createInscription, createRepeatInscriptions, defaultAdapters, getAddress, getCapabilities, getDefaultProvider, getProviderById, getProviderOrThrow, getProviders, getSupportedWallets, isProviderInstalled, removeDefaultProvider, request, sendBtcTransaction, setDefaultProvider, signMessage, signMultipleTransactions, signTransaction };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,359 @@
|
|
|
1
|
+
// src/types.ts
|
|
2
|
+
var BitcoinNetworkType = /* @__PURE__ */ ((BitcoinNetworkType2) => {
|
|
3
|
+
BitcoinNetworkType2["Mainnet"] = "Mainnet";
|
|
4
|
+
BitcoinNetworkType2["Testnet"] = "Testnet";
|
|
5
|
+
return BitcoinNetworkType2;
|
|
6
|
+
})(BitcoinNetworkType || {});
|
|
7
|
+
var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
|
|
8
|
+
RpcErrorCode2[RpcErrorCode2["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
|
|
9
|
+
RpcErrorCode2[RpcErrorCode2["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
|
|
10
|
+
RpcErrorCode2[RpcErrorCode2["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
|
|
11
|
+
RpcErrorCode2[RpcErrorCode2["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
|
|
12
|
+
RpcErrorCode2[RpcErrorCode2["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
|
|
13
|
+
RpcErrorCode2[RpcErrorCode2["USER_REJECTION"] = -32e3] = "USER_REJECTION";
|
|
14
|
+
RpcErrorCode2[RpcErrorCode2["METHOD_NOT_SUPPORTED"] = -32001] = "METHOD_NOT_SUPPORTED";
|
|
15
|
+
return RpcErrorCode2;
|
|
16
|
+
})(RpcErrorCode || {});
|
|
17
|
+
|
|
18
|
+
// src/runes/index.ts
|
|
19
|
+
import axios from "axios";
|
|
20
|
+
var ORDINALS_API_BASE_URL = (network = "Mainnet" /* Mainnet */) => `https://ordinals${network === "Testnet" /* Testnet */ ? "-testnet" : ""}.xverse.app/v1`;
|
|
21
|
+
var RunesApi = class {
|
|
22
|
+
client;
|
|
23
|
+
constructor(network) {
|
|
24
|
+
this.client = axios.create({
|
|
25
|
+
baseURL: ORDINALS_API_BASE_URL(network)
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
parseError = (error) => {
|
|
29
|
+
return {
|
|
30
|
+
code: error.response?.status,
|
|
31
|
+
message: JSON.stringify(error.response?.data)
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
estimateMintCost = async (mintParams) => {
|
|
35
|
+
try {
|
|
36
|
+
const response = await this.client.post("/runes/mint/estimate", {
|
|
37
|
+
...mintParams
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
data: response.data
|
|
41
|
+
};
|
|
42
|
+
} catch (error) {
|
|
43
|
+
const err = error;
|
|
44
|
+
return {
|
|
45
|
+
error: this.parseError(err)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
estimateEtchCost = async (etchParams) => {
|
|
50
|
+
try {
|
|
51
|
+
const response = await this.client.post("/runes/etch/estimate", {
|
|
52
|
+
...etchParams
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
data: response.data
|
|
56
|
+
};
|
|
57
|
+
} catch (error) {
|
|
58
|
+
const err = error;
|
|
59
|
+
return {
|
|
60
|
+
error: this.parseError(err)
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
createMintOrder = async (mintOrderParams) => {
|
|
65
|
+
try {
|
|
66
|
+
const response = await this.client.post("/runes/mint/orders", {
|
|
67
|
+
...mintOrderParams
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
data: response.data
|
|
71
|
+
};
|
|
72
|
+
} catch (error) {
|
|
73
|
+
const err = error;
|
|
74
|
+
return {
|
|
75
|
+
error: this.parseError(err)
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
createEtchOrder = async (etchOrderParams) => {
|
|
80
|
+
try {
|
|
81
|
+
const response = await this.client.post("/runes/etch/orders", {
|
|
82
|
+
...etchOrderParams
|
|
83
|
+
});
|
|
84
|
+
return {
|
|
85
|
+
data: response.data
|
|
86
|
+
};
|
|
87
|
+
} catch (error) {
|
|
88
|
+
const err = error;
|
|
89
|
+
return {
|
|
90
|
+
error: this.parseError(err)
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
executeMint = async (orderId, fundTransactionId) => {
|
|
95
|
+
try {
|
|
96
|
+
const response = await this.client.post(`/runes/mint/orders/${orderId}/execute`, {
|
|
97
|
+
fundTransactionId
|
|
98
|
+
});
|
|
99
|
+
return {
|
|
100
|
+
data: response.data
|
|
101
|
+
};
|
|
102
|
+
} catch (error) {
|
|
103
|
+
const err = error;
|
|
104
|
+
return {
|
|
105
|
+
error: this.parseError(err)
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
executeEtch = async (orderId, fundTransactionId) => {
|
|
110
|
+
try {
|
|
111
|
+
const response = await this.client.post(`/runes/etch/orders/${orderId}/execute`, {
|
|
112
|
+
fundTransactionId
|
|
113
|
+
});
|
|
114
|
+
return {
|
|
115
|
+
data: response.data
|
|
116
|
+
};
|
|
117
|
+
} catch (error) {
|
|
118
|
+
const err = error;
|
|
119
|
+
return {
|
|
120
|
+
error: this.parseError(err)
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
getOrder = async (orderId) => {
|
|
125
|
+
try {
|
|
126
|
+
const response = await this.client.get(`/orders/${orderId}`);
|
|
127
|
+
return {
|
|
128
|
+
data: response.data
|
|
129
|
+
};
|
|
130
|
+
} catch (error) {
|
|
131
|
+
const err = error;
|
|
132
|
+
return {
|
|
133
|
+
error: this.parseError(err)
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
var testnetClient = new RunesApi("Testnet" /* Testnet */);
|
|
139
|
+
var mainnetClient = new RunesApi("Mainnet" /* Mainnet */);
|
|
140
|
+
var getRunesApiClient = (network = "Mainnet" /* Mainnet */) => network === "Mainnet" /* Mainnet */ ? mainnetClient : testnetClient;
|
|
141
|
+
|
|
1
142
|
// src/adapters/satsConnectAdapter.ts
|
|
2
143
|
var SatsConnectAdapter = class {
|
|
144
|
+
async mintRunes(params) {
|
|
145
|
+
try {
|
|
146
|
+
const mintRequest = {
|
|
147
|
+
destinationAddress: params.destinationAddress,
|
|
148
|
+
feeRate: params.feeRate,
|
|
149
|
+
refundAddress: params.refundAddress,
|
|
150
|
+
repeats: params.repeats,
|
|
151
|
+
runeName: params.runeName,
|
|
152
|
+
appServiceFee: params.appServiceFee,
|
|
153
|
+
appServiceFeeAddress: params.appServiceFeeAddress
|
|
154
|
+
};
|
|
155
|
+
const orderResponse = await new RunesApi(params.network).createMintOrder(mintRequest);
|
|
156
|
+
if (!orderResponse.data) {
|
|
157
|
+
return {
|
|
158
|
+
status: "error",
|
|
159
|
+
error: {
|
|
160
|
+
code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
161
|
+
message: orderResponse.error.message
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
const paymentResponse = await this.requestInternal("sendTransfer", {
|
|
166
|
+
recipients: [
|
|
167
|
+
{
|
|
168
|
+
address: orderResponse.data.fundAddress,
|
|
169
|
+
amount: orderResponse.data.fundAmount
|
|
170
|
+
}
|
|
171
|
+
]
|
|
172
|
+
});
|
|
173
|
+
if (paymentResponse?.status !== "success") {
|
|
174
|
+
return {
|
|
175
|
+
status: "error",
|
|
176
|
+
error: {
|
|
177
|
+
code: -32e3 /* USER_REJECTION */,
|
|
178
|
+
message: "User rejected the payment request"
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
await new RunesApi(params.network).executeMint(
|
|
183
|
+
orderResponse.data.orderId,
|
|
184
|
+
paymentResponse.result.txid
|
|
185
|
+
);
|
|
186
|
+
return {
|
|
187
|
+
status: "success",
|
|
188
|
+
result: {
|
|
189
|
+
orderId: orderResponse.data.orderId,
|
|
190
|
+
fundTransactionId: paymentResponse.result.txid
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
} catch (error) {
|
|
194
|
+
return {
|
|
195
|
+
status: "error",
|
|
196
|
+
error: {
|
|
197
|
+
code: -32603 /* INTERNAL_ERROR */,
|
|
198
|
+
message: error.message
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
async etchRunes(params) {
|
|
204
|
+
const etchRequest = {
|
|
205
|
+
destinationAddress: params.destinationAddress,
|
|
206
|
+
refundAddress: params.refundAddress,
|
|
207
|
+
feeRate: params.feeRate,
|
|
208
|
+
runeName: params.runeName,
|
|
209
|
+
divisibility: params.divisibility,
|
|
210
|
+
symbol: params.symbol,
|
|
211
|
+
premine: params.premine,
|
|
212
|
+
isMintable: params.isMintable,
|
|
213
|
+
terms: params.terms,
|
|
214
|
+
inscriptionDetails: params.inscriptionDetails,
|
|
215
|
+
delegateInscriptionId: params.delegateInscriptionId,
|
|
216
|
+
appServiceFee: params.appServiceFee,
|
|
217
|
+
appServiceFeeAddress: params.appServiceFeeAddress
|
|
218
|
+
};
|
|
219
|
+
try {
|
|
220
|
+
const orderResponse = await new RunesApi(params.network).createEtchOrder(etchRequest);
|
|
221
|
+
if (!orderResponse.data) {
|
|
222
|
+
return {
|
|
223
|
+
status: "error",
|
|
224
|
+
error: {
|
|
225
|
+
code: orderResponse.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
226
|
+
message: orderResponse.error.message
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
const paymentResponse = await this.requestInternal("sendTransfer", {
|
|
231
|
+
recipients: [
|
|
232
|
+
{
|
|
233
|
+
address: orderResponse.data.fundAddress,
|
|
234
|
+
amount: orderResponse.data.fundAmount
|
|
235
|
+
}
|
|
236
|
+
]
|
|
237
|
+
});
|
|
238
|
+
if (paymentResponse?.status !== "success") {
|
|
239
|
+
return {
|
|
240
|
+
status: "error",
|
|
241
|
+
error: {
|
|
242
|
+
code: -32e3 /* USER_REJECTION */,
|
|
243
|
+
message: "User rejected the payment request"
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
await new RunesApi(params.network).executeEtch(
|
|
248
|
+
orderResponse.data.orderId,
|
|
249
|
+
paymentResponse.result.txid
|
|
250
|
+
);
|
|
251
|
+
return {
|
|
252
|
+
status: "success",
|
|
253
|
+
result: {
|
|
254
|
+
orderId: orderResponse.data.orderId,
|
|
255
|
+
fundTransactionId: paymentResponse.result.txid
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
} catch (error) {
|
|
259
|
+
return {
|
|
260
|
+
status: "error",
|
|
261
|
+
error: {
|
|
262
|
+
code: -32603 /* INTERNAL_ERROR */,
|
|
263
|
+
message: error.message
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
async estimateMint(params) {
|
|
269
|
+
const estimateMintRequest = {
|
|
270
|
+
destinationAddress: params.destinationAddress,
|
|
271
|
+
feeRate: params.feeRate,
|
|
272
|
+
repeats: params.repeats,
|
|
273
|
+
runeName: params.runeName,
|
|
274
|
+
appServiceFee: params.appServiceFee,
|
|
275
|
+
appServiceFeeAddress: params.appServiceFeeAddress
|
|
276
|
+
};
|
|
277
|
+
const response = await getRunesApiClient(
|
|
278
|
+
params.network
|
|
279
|
+
).estimateMintCost(estimateMintRequest);
|
|
280
|
+
if (response.data) {
|
|
281
|
+
return {
|
|
282
|
+
status: "success",
|
|
283
|
+
result: response.data
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
return {
|
|
287
|
+
status: "error",
|
|
288
|
+
error: {
|
|
289
|
+
code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
290
|
+
message: response.error.message
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
async estimateEtch(params) {
|
|
295
|
+
const estimateEtchRequest = {
|
|
296
|
+
destinationAddress: params.destinationAddress,
|
|
297
|
+
feeRate: params.feeRate,
|
|
298
|
+
runeName: params.runeName,
|
|
299
|
+
divisibility: params.divisibility,
|
|
300
|
+
symbol: params.symbol,
|
|
301
|
+
premine: params.premine,
|
|
302
|
+
isMintable: params.isMintable,
|
|
303
|
+
terms: params.terms,
|
|
304
|
+
inscriptionDetails: params.inscriptionDetails,
|
|
305
|
+
delegateInscriptionId: params.delegateInscriptionId,
|
|
306
|
+
appServiceFee: params.appServiceFee,
|
|
307
|
+
appServiceFeeAddress: params.appServiceFeeAddress
|
|
308
|
+
};
|
|
309
|
+
const response = await getRunesApiClient(params.network).estimateEtchCost(estimateEtchRequest);
|
|
310
|
+
if (response.data) {
|
|
311
|
+
return {
|
|
312
|
+
status: "success",
|
|
313
|
+
result: response.data
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
return {
|
|
317
|
+
status: "error",
|
|
318
|
+
error: {
|
|
319
|
+
code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
320
|
+
message: response.error.message
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
async getOrder(params) {
|
|
325
|
+
const response = await getRunesApiClient(params.network).getOrder(params.id);
|
|
326
|
+
if (response.data) {
|
|
327
|
+
return {
|
|
328
|
+
status: "success",
|
|
329
|
+
result: response.data
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
return {
|
|
333
|
+
status: "error",
|
|
334
|
+
error: {
|
|
335
|
+
code: response.error.code === 400 ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */,
|
|
336
|
+
message: response.error.message
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
async request(method, params) {
|
|
341
|
+
switch (method) {
|
|
342
|
+
case "runes_mint":
|
|
343
|
+
return this.mintRunes(params);
|
|
344
|
+
case "runes_etch":
|
|
345
|
+
return this.etchRunes(params);
|
|
346
|
+
case "runes_estimateMint":
|
|
347
|
+
return this.estimateMint(params);
|
|
348
|
+
case "runes_estimateEtch":
|
|
349
|
+
return this.estimateEtch(params);
|
|
350
|
+
case "runes_getOrder": {
|
|
351
|
+
return this.getOrder(params);
|
|
352
|
+
}
|
|
353
|
+
default:
|
|
354
|
+
return this.requestInternal(method, params);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
3
357
|
};
|
|
4
358
|
|
|
5
359
|
// src/provider/index.ts
|
|
@@ -78,32 +432,13 @@ var isRpcSuccessResponse = (response) => {
|
|
|
78
432
|
// src/adapters/xverse.ts
|
|
79
433
|
var XverseAdapter = class extends SatsConnectAdapter {
|
|
80
434
|
id = DefaultAdaptersInfo.xverse.id;
|
|
81
|
-
|
|
435
|
+
requestInternal = async (method, params) => {
|
|
82
436
|
return request(method, params, this.id);
|
|
83
437
|
};
|
|
84
438
|
};
|
|
85
439
|
|
|
86
440
|
// src/adapters/unisat.ts
|
|
87
441
|
import { Buffer } from "buffer";
|
|
88
|
-
|
|
89
|
-
// src/types.ts
|
|
90
|
-
var BitcoinNetworkType = /* @__PURE__ */ ((BitcoinNetworkType2) => {
|
|
91
|
-
BitcoinNetworkType2["Mainnet"] = "Mainnet";
|
|
92
|
-
BitcoinNetworkType2["Testnet"] = "Testnet";
|
|
93
|
-
return BitcoinNetworkType2;
|
|
94
|
-
})(BitcoinNetworkType || {});
|
|
95
|
-
var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
|
|
96
|
-
RpcErrorCode2[RpcErrorCode2["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
|
|
97
|
-
RpcErrorCode2[RpcErrorCode2["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
|
|
98
|
-
RpcErrorCode2[RpcErrorCode2["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
|
|
99
|
-
RpcErrorCode2[RpcErrorCode2["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
|
|
100
|
-
RpcErrorCode2[RpcErrorCode2["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
|
|
101
|
-
RpcErrorCode2[RpcErrorCode2["USER_REJECTION"] = -32e3] = "USER_REJECTION";
|
|
102
|
-
RpcErrorCode2[RpcErrorCode2["METHOD_NOT_SUPPORTED"] = -32001] = "METHOD_NOT_SUPPORTED";
|
|
103
|
-
return RpcErrorCode2;
|
|
104
|
-
})(RpcErrorCode || {});
|
|
105
|
-
|
|
106
|
-
// src/adapters/unisat.ts
|
|
107
442
|
import { AddressType as AddressType2, getAddressInfo } from "bitcoin-address-validation";
|
|
108
443
|
|
|
109
444
|
// src/addresses/index.ts
|
|
@@ -240,7 +575,7 @@ var UnisatAdapter = class extends SatsConnectAdapter {
|
|
|
240
575
|
psbt: psbtHex
|
|
241
576
|
};
|
|
242
577
|
}
|
|
243
|
-
|
|
578
|
+
requestInternal = async (method, params) => {
|
|
244
579
|
try {
|
|
245
580
|
switch (method) {
|
|
246
581
|
case "getAccounts": {
|
|
@@ -306,7 +641,7 @@ var BaseAdapter = class extends SatsConnectAdapter {
|
|
|
306
641
|
super();
|
|
307
642
|
this.id = providerId;
|
|
308
643
|
}
|
|
309
|
-
|
|
644
|
+
requestInternal = async (method, params) => {
|
|
310
645
|
return request(method, params, this.id);
|
|
311
646
|
};
|
|
312
647
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sats-connect/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4-c8131da",
|
|
4
4
|
"main": "dist/index.mjs",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.mts",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
]
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
+
"axios": "1.6.8",
|
|
27
28
|
"bitcoin-address-validation": "2.2.3",
|
|
28
29
|
"buffer": "6.0.3",
|
|
29
30
|
"jsontokens": "4.0.1",
|