@avalabs/vm-module-types 0.12.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/balance.d.cts +2 -1
- package/dist/balance.d.ts +2 -1
- package/dist/chunk-2DSAT5RW.js +3 -0
- package/dist/{chunk-YB5EN6FL.cjs → chunk-ATL7CLLW.cjs} +1 -1
- package/dist/chunk-IQHOBS5Y.cjs +9 -0
- package/dist/chunk-IQHOBS5Y.cjs.map +1 -0
- package/dist/{chunk-A4YEBDMG.js → chunk-RINP3JFP.js} +2 -2
- package/dist/chunk-RINP3JFP.js.map +1 -0
- package/dist/{chunk-74SNNWSF.cjs → chunk-SYE3TX4L.cjs} +2 -2
- package/dist/chunk-SYE3TX4L.cjs.map +1 -0
- package/dist/chunk-T3QBBZUZ.js +5 -0
- package/dist/chunk-T3QBBZUZ.js.map +1 -0
- package/dist/coingecko.d.cts +4 -4
- package/dist/coingecko.d.ts +4 -4
- package/dist/index.cjs +7 -7
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/manifest.cjs +2 -2
- package/dist/manifest.d.cts +7 -0
- package/dist/manifest.d.ts +7 -0
- package/dist/manifest.js +1 -1
- package/dist/module.cjs +1 -1
- package/dist/module.d.cts +3 -3
- package/dist/module.d.ts +3 -3
- package/dist/module.js +1 -1
- package/dist/rpc-ab7acd4d.d.ts +334 -0
- package/dist/rpc-c6776d81.d.ts +334 -0
- package/dist/rpc.cjs +4 -4
- package/dist/rpc.d.cts +7 -275
- package/dist/rpc.d.ts +7 -275
- package/dist/rpc.js +1 -1
- package/dist/transaction-simulation.d.cts +10 -27
- package/dist/transaction-simulation.d.ts +10 -27
- package/package.json +4 -3
- package/dist/chunk-5R4OCUZW.js +0 -5
- package/dist/chunk-5R4OCUZW.js.map +0 -1
- package/dist/chunk-74SNNWSF.cjs.map +0 -1
- package/dist/chunk-A4YEBDMG.js.map +0 -1
- package/dist/chunk-GF7C4PA6.js +0 -3
- package/dist/chunk-RXEAQKSD.cjs +0 -9
- package/dist/chunk-RXEAQKSD.cjs.map +0 -1
- /package/dist/{chunk-GF7C4PA6.js.map → chunk-2DSAT5RW.js.map} +0 -0
- /package/dist/{chunk-YB5EN6FL.cjs.map → chunk-ATL7CLLW.cjs.map} +0 -0
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import { TransactionRequest } from 'ethers';
|
|
2
|
+
import { BitcoinInputUTXO, BitcoinOutputUTXO, Avalanche } from '@avalabs/core-wallets-sdk';
|
|
3
|
+
import { Caip2ChainId, Hex } from './common.js';
|
|
4
|
+
import { JsonRpcError, OptionalDataWithOptionalCause, EthereumProviderError } from '@metamask/rpc-errors';
|
|
5
|
+
import { TokenWithBalanceBTC } from './balance.js';
|
|
6
|
+
import { VMABI, TransactionPayload } from 'hypersdk-client';
|
|
7
|
+
import { NetworkContractToken, NetworkToken } from './token.js';
|
|
8
|
+
|
|
9
|
+
type BalanceChange = {
|
|
10
|
+
ins: TokenDiff[];
|
|
11
|
+
outs: TokenDiff[];
|
|
12
|
+
};
|
|
13
|
+
type TokenDiff = {
|
|
14
|
+
token: NetworkContractToken | NetworkToken;
|
|
15
|
+
items: TokenDiffItem[];
|
|
16
|
+
};
|
|
17
|
+
type TokenDiffItem = {
|
|
18
|
+
displayValue: string;
|
|
19
|
+
usdPrice: string | undefined;
|
|
20
|
+
};
|
|
21
|
+
type TokenApproval = {
|
|
22
|
+
token: NetworkContractToken;
|
|
23
|
+
spenderAddress: string;
|
|
24
|
+
value?: string;
|
|
25
|
+
usdPrice?: string;
|
|
26
|
+
logoUri?: string;
|
|
27
|
+
};
|
|
28
|
+
type TokenApprovals = {
|
|
29
|
+
isEditable: boolean;
|
|
30
|
+
approvals: TokenApproval[];
|
|
31
|
+
};
|
|
32
|
+
type TransactionSimulationResult = {
|
|
33
|
+
alert?: Alert;
|
|
34
|
+
balanceChange?: BalanceChange;
|
|
35
|
+
tokenApprovals?: TokenApprovals;
|
|
36
|
+
isSimulationSuccessful: boolean;
|
|
37
|
+
estimatedGasLimit?: number;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
declare enum RpcMethod {
|
|
41
|
+
BITCOIN_SEND_TRANSACTION = "bitcoin_sendTransaction",
|
|
42
|
+
BITCOIN_SIGN_TRANSACTION = "bitcoin_signTransaction",
|
|
43
|
+
ETH_SEND_TRANSACTION = "eth_sendTransaction",
|
|
44
|
+
ETH_SEND_TRANSACTION_BATCH = "eth_sendTransactionBatch",
|
|
45
|
+
SIGN_TYPED_DATA_V3 = "eth_signTypedData_v3",
|
|
46
|
+
SIGN_TYPED_DATA_V4 = "eth_signTypedData_v4",
|
|
47
|
+
SIGN_TYPED_DATA_V1 = "eth_signTypedData_v1",
|
|
48
|
+
SIGN_TYPED_DATA = "eth_signTypedData",
|
|
49
|
+
PERSONAL_SIGN = "personal_sign",
|
|
50
|
+
ETH_SIGN = "eth_sign",
|
|
51
|
+
AVALANCHE_SIGN_MESSAGE = "avalanche_signMessage",
|
|
52
|
+
AVALANCHE_SEND_TRANSACTION = "avalanche_sendTransaction",
|
|
53
|
+
AVALANCHE_SIGN_TRANSACTION = "avalanche_signTransaction",
|
|
54
|
+
HVM_SIGN_TRANSACTION = "hvm_signTransaction"
|
|
55
|
+
}
|
|
56
|
+
type DappInfo = {
|
|
57
|
+
name: string;
|
|
58
|
+
url: string;
|
|
59
|
+
icon: string;
|
|
60
|
+
};
|
|
61
|
+
type RpcRequest = {
|
|
62
|
+
requestId: string;
|
|
63
|
+
sessionId: string;
|
|
64
|
+
method: RpcMethod;
|
|
65
|
+
chainId: Caip2ChainId;
|
|
66
|
+
params: unknown;
|
|
67
|
+
dappInfo: DappInfo;
|
|
68
|
+
context?: Record<string, unknown>;
|
|
69
|
+
};
|
|
70
|
+
type RpcError = JsonRpcError<OptionalDataWithOptionalCause> | EthereumProviderError<OptionalDataWithOptionalCause>;
|
|
71
|
+
type RpcResponse<R = unknown, E extends RpcError = JsonRpcError<OptionalDataWithOptionalCause>> = {
|
|
72
|
+
result: R;
|
|
73
|
+
} | {
|
|
74
|
+
error: E;
|
|
75
|
+
};
|
|
76
|
+
interface MessageTypeProperty {
|
|
77
|
+
name: string;
|
|
78
|
+
type: string;
|
|
79
|
+
}
|
|
80
|
+
interface MessageTypes {
|
|
81
|
+
EIP712Domain: MessageTypeProperty[];
|
|
82
|
+
[additionalProperties: string]: MessageTypeProperty[];
|
|
83
|
+
}
|
|
84
|
+
interface TypedData<T extends MessageTypes> {
|
|
85
|
+
types: T;
|
|
86
|
+
primaryType: keyof T;
|
|
87
|
+
domain: Record<string, unknown>;
|
|
88
|
+
message: Record<string, unknown>;
|
|
89
|
+
}
|
|
90
|
+
type TypedDataV1 = {
|
|
91
|
+
name: string;
|
|
92
|
+
type: string;
|
|
93
|
+
value: unknown;
|
|
94
|
+
}[];
|
|
95
|
+
type DetailSection = {
|
|
96
|
+
title?: string;
|
|
97
|
+
items: DetailItem[];
|
|
98
|
+
};
|
|
99
|
+
type BaseDetailItem = {
|
|
100
|
+
label: string;
|
|
101
|
+
};
|
|
102
|
+
declare enum DetailItemType {
|
|
103
|
+
TEXT = "text",
|
|
104
|
+
ADDRESS = "address",
|
|
105
|
+
NODE_ID = "nodeID",
|
|
106
|
+
CURRENCY = "currency",
|
|
107
|
+
FUNDS_RECIPIENT = "fundsRecipient",
|
|
108
|
+
DATA = "data",
|
|
109
|
+
DATE = "date",
|
|
110
|
+
LINK = "link"
|
|
111
|
+
}
|
|
112
|
+
type FundsRecipientItem = BaseDetailItem & {
|
|
113
|
+
type: DetailItemType.FUNDS_RECIPIENT;
|
|
114
|
+
amount: bigint;
|
|
115
|
+
maxDecimals: number;
|
|
116
|
+
symbol: string;
|
|
117
|
+
};
|
|
118
|
+
type TextItem = BaseDetailItem & {
|
|
119
|
+
type: DetailItemType.TEXT;
|
|
120
|
+
value: string;
|
|
121
|
+
alignment: 'vertical' | 'horizontal';
|
|
122
|
+
};
|
|
123
|
+
type AddressItem = BaseDetailItem & {
|
|
124
|
+
type: DetailItemType.ADDRESS;
|
|
125
|
+
value: string;
|
|
126
|
+
};
|
|
127
|
+
type NodeIDItem = BaseDetailItem & {
|
|
128
|
+
type: DetailItemType.NODE_ID;
|
|
129
|
+
value: string;
|
|
130
|
+
};
|
|
131
|
+
type CurrencyItem = BaseDetailItem & {
|
|
132
|
+
type: DetailItemType.CURRENCY;
|
|
133
|
+
value: bigint;
|
|
134
|
+
maxDecimals: number;
|
|
135
|
+
symbol: string;
|
|
136
|
+
};
|
|
137
|
+
type DataItem = BaseDetailItem & {
|
|
138
|
+
type: DetailItemType.DATA;
|
|
139
|
+
value: string;
|
|
140
|
+
};
|
|
141
|
+
type DateItem = BaseDetailItem & {
|
|
142
|
+
type: DetailItemType.DATE;
|
|
143
|
+
value: string;
|
|
144
|
+
};
|
|
145
|
+
type LinkItemValue = {
|
|
146
|
+
url: string;
|
|
147
|
+
name?: string;
|
|
148
|
+
icon?: string;
|
|
149
|
+
};
|
|
150
|
+
type LinkItem = BaseDetailItem & {
|
|
151
|
+
type: DetailItemType.LINK;
|
|
152
|
+
value: LinkItemValue;
|
|
153
|
+
};
|
|
154
|
+
type DetailItem = string | TextItem | AddressItem | NodeIDItem | CurrencyItem | DataItem | DateItem | LinkItem | FundsRecipientItem;
|
|
155
|
+
type DisplayData = {
|
|
156
|
+
title: string;
|
|
157
|
+
dAppInfo?: {
|
|
158
|
+
name: string;
|
|
159
|
+
action: string;
|
|
160
|
+
logoUri?: string;
|
|
161
|
+
};
|
|
162
|
+
network: {
|
|
163
|
+
chainId: number;
|
|
164
|
+
name: string;
|
|
165
|
+
logoUri?: string;
|
|
166
|
+
};
|
|
167
|
+
account?: string;
|
|
168
|
+
details: DetailSection[];
|
|
169
|
+
networkFeeSelector?: boolean;
|
|
170
|
+
disclaimer?: string;
|
|
171
|
+
alert?: Alert;
|
|
172
|
+
balanceChange?: BalanceChange;
|
|
173
|
+
tokenApprovals?: TokenApprovals;
|
|
174
|
+
isSimulationSuccessful?: boolean;
|
|
175
|
+
};
|
|
176
|
+
declare enum AlertType {
|
|
177
|
+
WARNING = "Warning",
|
|
178
|
+
DANGER = "Danger",
|
|
179
|
+
INFO = "Info"
|
|
180
|
+
}
|
|
181
|
+
type AlertDetails = {
|
|
182
|
+
title: string;
|
|
183
|
+
description: string;
|
|
184
|
+
detailedDescription?: string;
|
|
185
|
+
actionTitles?: {
|
|
186
|
+
proceed: string;
|
|
187
|
+
reject: string;
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
type Alert = {
|
|
191
|
+
type: AlertType;
|
|
192
|
+
details: AlertDetails;
|
|
193
|
+
};
|
|
194
|
+
type BitcoinExecuteTxData = {
|
|
195
|
+
to: string;
|
|
196
|
+
amount: number;
|
|
197
|
+
feeRate: number;
|
|
198
|
+
fee: number;
|
|
199
|
+
gasLimit: number;
|
|
200
|
+
balance: TokenWithBalanceBTC;
|
|
201
|
+
inputs: BitcoinInputUTXO[];
|
|
202
|
+
outputs: BitcoinOutputUTXO[];
|
|
203
|
+
};
|
|
204
|
+
type BitcoingSignTxData = {
|
|
205
|
+
inputs: BitcoinInputUTXO[];
|
|
206
|
+
outputs: BitcoinOutputUTXO[];
|
|
207
|
+
};
|
|
208
|
+
type SigningData = {
|
|
209
|
+
type: RpcMethod.BITCOIN_SEND_TRANSACTION;
|
|
210
|
+
account: string;
|
|
211
|
+
data: BitcoinExecuteTxData;
|
|
212
|
+
} | {
|
|
213
|
+
type: RpcMethod.BITCOIN_SIGN_TRANSACTION;
|
|
214
|
+
account: string;
|
|
215
|
+
data: BitcoingSignTxData;
|
|
216
|
+
} | SigningData_EthSendTx | {
|
|
217
|
+
type: RpcMethod.ETH_SIGN | RpcMethod.PERSONAL_SIGN;
|
|
218
|
+
account: string;
|
|
219
|
+
data: string;
|
|
220
|
+
} | {
|
|
221
|
+
type: RpcMethod.SIGN_TYPED_DATA | RpcMethod.SIGN_TYPED_DATA_V1;
|
|
222
|
+
account: string;
|
|
223
|
+
data: TypedData<MessageTypes> | TypedDataV1;
|
|
224
|
+
} | {
|
|
225
|
+
type: RpcMethod.SIGN_TYPED_DATA_V3 | RpcMethod.SIGN_TYPED_DATA_V4;
|
|
226
|
+
account: string;
|
|
227
|
+
data: TypedData<MessageTypes>;
|
|
228
|
+
} | {
|
|
229
|
+
type: RpcMethod.AVALANCHE_SIGN_MESSAGE;
|
|
230
|
+
data: string;
|
|
231
|
+
accountIndex?: number;
|
|
232
|
+
} | {
|
|
233
|
+
type: RpcMethod.AVALANCHE_SEND_TRANSACTION;
|
|
234
|
+
unsignedTxJson: string;
|
|
235
|
+
data: Avalanche.Tx;
|
|
236
|
+
vm: 'EVM' | 'AVM' | 'PVM';
|
|
237
|
+
externalIndices?: number[];
|
|
238
|
+
internalIndices?: number[];
|
|
239
|
+
} | {
|
|
240
|
+
type: RpcMethod.AVALANCHE_SIGN_TRANSACTION;
|
|
241
|
+
unsignedTxJson: string;
|
|
242
|
+
data: Avalanche.Tx;
|
|
243
|
+
vm: 'EVM' | 'AVM' | 'PVM';
|
|
244
|
+
ownSignatureIndices: [number, number][];
|
|
245
|
+
} | {
|
|
246
|
+
type: RpcMethod.HVM_SIGN_TRANSACTION;
|
|
247
|
+
data: {
|
|
248
|
+
abi: VMABI;
|
|
249
|
+
txPayload: TransactionPayload;
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
type SigningData_EthSendTx = {
|
|
253
|
+
type: RpcMethod.ETH_SEND_TRANSACTION;
|
|
254
|
+
account: string;
|
|
255
|
+
data: TransactionRequest;
|
|
256
|
+
};
|
|
257
|
+
type EvmTxBatchUpdateFn = (data: {
|
|
258
|
+
maxFeeRate?: bigint;
|
|
259
|
+
maxTipRate?: bigint;
|
|
260
|
+
}, txIndex: number) => {
|
|
261
|
+
displayData: DisplayData;
|
|
262
|
+
signingRequests: {
|
|
263
|
+
displayData: DisplayData;
|
|
264
|
+
signingData: SigningData_EthSendTx;
|
|
265
|
+
}[];
|
|
266
|
+
};
|
|
267
|
+
type EvmTxUpdateFn = (data: {
|
|
268
|
+
maxFeeRate?: bigint;
|
|
269
|
+
maxTipRate?: bigint;
|
|
270
|
+
approvalLimit?: Hex;
|
|
271
|
+
}) => {
|
|
272
|
+
displayData: DisplayData;
|
|
273
|
+
signingData: SigningData_EthSendTx;
|
|
274
|
+
};
|
|
275
|
+
type BtcTxUpdateFn = (data: {
|
|
276
|
+
feeRate?: number;
|
|
277
|
+
}) => {
|
|
278
|
+
displayData: DisplayData;
|
|
279
|
+
signingData: Extract<SigningData, {
|
|
280
|
+
type: RpcMethod.BITCOIN_SEND_TRANSACTION;
|
|
281
|
+
}>;
|
|
282
|
+
};
|
|
283
|
+
type SigningRequest<Data = SigningData> = {
|
|
284
|
+
displayData: DisplayData;
|
|
285
|
+
signingData: Data;
|
|
286
|
+
updateTx?: EvmTxUpdateFn | BtcTxUpdateFn;
|
|
287
|
+
};
|
|
288
|
+
type ApprovalParams = {
|
|
289
|
+
request: RpcRequest;
|
|
290
|
+
} & SigningRequest;
|
|
291
|
+
type BatchApprovalParams = {
|
|
292
|
+
request: RpcRequest;
|
|
293
|
+
signingRequests: SigningRequest<SigningData_EthSendTx>[];
|
|
294
|
+
displayData: DisplayData;
|
|
295
|
+
updateTx: EvmTxBatchUpdateFn;
|
|
296
|
+
};
|
|
297
|
+
/**
|
|
298
|
+
* We want to accept both a signed data (tx/message) and a tx hash as a response
|
|
299
|
+
* coming in from the client apps, hence the XORs here.
|
|
300
|
+
*
|
|
301
|
+
* The reason we need to support both is because extension allows importing
|
|
302
|
+
* external software wallets, such as Fireblocks or other apps that support
|
|
303
|
+
* the WalletConnect protocol.
|
|
304
|
+
*
|
|
305
|
+
* My experience is that WalletConnect apps rarely, if ever, support
|
|
306
|
+
* "eth_signTransaction" requests and more often only allow sending
|
|
307
|
+
* "eth_sendTransaction" calls, which means that all we'll get in response
|
|
308
|
+
* from them is the transaction hash (not a signed tx).
|
|
309
|
+
*/
|
|
310
|
+
type SignedData = {
|
|
311
|
+
signedData: string;
|
|
312
|
+
};
|
|
313
|
+
type BroadcastedTx = {
|
|
314
|
+
txHash: string;
|
|
315
|
+
};
|
|
316
|
+
type SigningResult = SignedData | BroadcastedTx;
|
|
317
|
+
type ApprovalResponse = {
|
|
318
|
+
error: RpcError;
|
|
319
|
+
} | SigningResult;
|
|
320
|
+
type BatchApprovalResponse = {
|
|
321
|
+
error: RpcError;
|
|
322
|
+
} | {
|
|
323
|
+
result: SignedData[];
|
|
324
|
+
};
|
|
325
|
+
interface ApprovalController {
|
|
326
|
+
requestApproval: (params: ApprovalParams) => Promise<ApprovalResponse>;
|
|
327
|
+
onTransactionConfirmed: (txHash: Hex, requestId: string) => void;
|
|
328
|
+
onTransactionReverted: (txHash: Hex, requestId: string) => void;
|
|
329
|
+
}
|
|
330
|
+
interface BatchApprovalController extends ApprovalController {
|
|
331
|
+
requestBatchApproval: (params: BatchApprovalParams) => Promise<BatchApprovalResponse>;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export { AddressItem as A, BaseDetailItem as B, CurrencyItem as C, DappInfo as D, EvmTxBatchUpdateFn as E, FundsRecipientItem as F, BatchApprovalResponse as G, ApprovalController as H, BatchApprovalController as I, BalanceChange as J, TokenDiff as K, LinkItemValue as L, MessageTypeProperty as M, NodeIDItem as N, TokenDiffItem as O, TokenApproval as P, TokenApprovals as Q, RpcMethod as R, SigningData as S, TypedData as T, TransactionSimulationResult as U, RpcRequest as a, RpcError as b, RpcResponse as c, MessageTypes as d, TypedDataV1 as e, DetailSection as f, DetailItemType as g, TextItem as h, DataItem as i, DateItem as j, LinkItem as k, DetailItem as l, DisplayData as m, AlertType as n, AlertDetails as o, Alert as p, BitcoinExecuteTxData as q, BitcoingSignTxData as r, SigningData_EthSendTx as s, EvmTxUpdateFn as t, BtcTxUpdateFn as u, SigningRequest as v, ApprovalParams as w, BatchApprovalParams as x, SigningResult as y, ApprovalResponse as z };
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import { TransactionRequest } from 'ethers';
|
|
2
|
+
import { BitcoinInputUTXO, BitcoinOutputUTXO, Avalanche } from '@avalabs/core-wallets-sdk';
|
|
3
|
+
import { Caip2ChainId, Hex } from './common.cjs';
|
|
4
|
+
import { JsonRpcError, OptionalDataWithOptionalCause, EthereumProviderError } from '@metamask/rpc-errors';
|
|
5
|
+
import { TokenWithBalanceBTC } from './balance.cjs';
|
|
6
|
+
import { VMABI, TransactionPayload } from 'hypersdk-client';
|
|
7
|
+
import { NetworkContractToken, NetworkToken } from './token.cjs';
|
|
8
|
+
|
|
9
|
+
type BalanceChange = {
|
|
10
|
+
ins: TokenDiff[];
|
|
11
|
+
outs: TokenDiff[];
|
|
12
|
+
};
|
|
13
|
+
type TokenDiff = {
|
|
14
|
+
token: NetworkContractToken | NetworkToken;
|
|
15
|
+
items: TokenDiffItem[];
|
|
16
|
+
};
|
|
17
|
+
type TokenDiffItem = {
|
|
18
|
+
displayValue: string;
|
|
19
|
+
usdPrice: string | undefined;
|
|
20
|
+
};
|
|
21
|
+
type TokenApproval = {
|
|
22
|
+
token: NetworkContractToken;
|
|
23
|
+
spenderAddress: string;
|
|
24
|
+
value?: string;
|
|
25
|
+
usdPrice?: string;
|
|
26
|
+
logoUri?: string;
|
|
27
|
+
};
|
|
28
|
+
type TokenApprovals = {
|
|
29
|
+
isEditable: boolean;
|
|
30
|
+
approvals: TokenApproval[];
|
|
31
|
+
};
|
|
32
|
+
type TransactionSimulationResult = {
|
|
33
|
+
alert?: Alert;
|
|
34
|
+
balanceChange?: BalanceChange;
|
|
35
|
+
tokenApprovals?: TokenApprovals;
|
|
36
|
+
isSimulationSuccessful: boolean;
|
|
37
|
+
estimatedGasLimit?: number;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
declare enum RpcMethod {
|
|
41
|
+
BITCOIN_SEND_TRANSACTION = "bitcoin_sendTransaction",
|
|
42
|
+
BITCOIN_SIGN_TRANSACTION = "bitcoin_signTransaction",
|
|
43
|
+
ETH_SEND_TRANSACTION = "eth_sendTransaction",
|
|
44
|
+
ETH_SEND_TRANSACTION_BATCH = "eth_sendTransactionBatch",
|
|
45
|
+
SIGN_TYPED_DATA_V3 = "eth_signTypedData_v3",
|
|
46
|
+
SIGN_TYPED_DATA_V4 = "eth_signTypedData_v4",
|
|
47
|
+
SIGN_TYPED_DATA_V1 = "eth_signTypedData_v1",
|
|
48
|
+
SIGN_TYPED_DATA = "eth_signTypedData",
|
|
49
|
+
PERSONAL_SIGN = "personal_sign",
|
|
50
|
+
ETH_SIGN = "eth_sign",
|
|
51
|
+
AVALANCHE_SIGN_MESSAGE = "avalanche_signMessage",
|
|
52
|
+
AVALANCHE_SEND_TRANSACTION = "avalanche_sendTransaction",
|
|
53
|
+
AVALANCHE_SIGN_TRANSACTION = "avalanche_signTransaction",
|
|
54
|
+
HVM_SIGN_TRANSACTION = "hvm_signTransaction"
|
|
55
|
+
}
|
|
56
|
+
type DappInfo = {
|
|
57
|
+
name: string;
|
|
58
|
+
url: string;
|
|
59
|
+
icon: string;
|
|
60
|
+
};
|
|
61
|
+
type RpcRequest = {
|
|
62
|
+
requestId: string;
|
|
63
|
+
sessionId: string;
|
|
64
|
+
method: RpcMethod;
|
|
65
|
+
chainId: Caip2ChainId;
|
|
66
|
+
params: unknown;
|
|
67
|
+
dappInfo: DappInfo;
|
|
68
|
+
context?: Record<string, unknown>;
|
|
69
|
+
};
|
|
70
|
+
type RpcError = JsonRpcError<OptionalDataWithOptionalCause> | EthereumProviderError<OptionalDataWithOptionalCause>;
|
|
71
|
+
type RpcResponse<R = unknown, E extends RpcError = JsonRpcError<OptionalDataWithOptionalCause>> = {
|
|
72
|
+
result: R;
|
|
73
|
+
} | {
|
|
74
|
+
error: E;
|
|
75
|
+
};
|
|
76
|
+
interface MessageTypeProperty {
|
|
77
|
+
name: string;
|
|
78
|
+
type: string;
|
|
79
|
+
}
|
|
80
|
+
interface MessageTypes {
|
|
81
|
+
EIP712Domain: MessageTypeProperty[];
|
|
82
|
+
[additionalProperties: string]: MessageTypeProperty[];
|
|
83
|
+
}
|
|
84
|
+
interface TypedData<T extends MessageTypes> {
|
|
85
|
+
types: T;
|
|
86
|
+
primaryType: keyof T;
|
|
87
|
+
domain: Record<string, unknown>;
|
|
88
|
+
message: Record<string, unknown>;
|
|
89
|
+
}
|
|
90
|
+
type TypedDataV1 = {
|
|
91
|
+
name: string;
|
|
92
|
+
type: string;
|
|
93
|
+
value: unknown;
|
|
94
|
+
}[];
|
|
95
|
+
type DetailSection = {
|
|
96
|
+
title?: string;
|
|
97
|
+
items: DetailItem[];
|
|
98
|
+
};
|
|
99
|
+
type BaseDetailItem = {
|
|
100
|
+
label: string;
|
|
101
|
+
};
|
|
102
|
+
declare enum DetailItemType {
|
|
103
|
+
TEXT = "text",
|
|
104
|
+
ADDRESS = "address",
|
|
105
|
+
NODE_ID = "nodeID",
|
|
106
|
+
CURRENCY = "currency",
|
|
107
|
+
FUNDS_RECIPIENT = "fundsRecipient",
|
|
108
|
+
DATA = "data",
|
|
109
|
+
DATE = "date",
|
|
110
|
+
LINK = "link"
|
|
111
|
+
}
|
|
112
|
+
type FundsRecipientItem = BaseDetailItem & {
|
|
113
|
+
type: DetailItemType.FUNDS_RECIPIENT;
|
|
114
|
+
amount: bigint;
|
|
115
|
+
maxDecimals: number;
|
|
116
|
+
symbol: string;
|
|
117
|
+
};
|
|
118
|
+
type TextItem = BaseDetailItem & {
|
|
119
|
+
type: DetailItemType.TEXT;
|
|
120
|
+
value: string;
|
|
121
|
+
alignment: 'vertical' | 'horizontal';
|
|
122
|
+
};
|
|
123
|
+
type AddressItem = BaseDetailItem & {
|
|
124
|
+
type: DetailItemType.ADDRESS;
|
|
125
|
+
value: string;
|
|
126
|
+
};
|
|
127
|
+
type NodeIDItem = BaseDetailItem & {
|
|
128
|
+
type: DetailItemType.NODE_ID;
|
|
129
|
+
value: string;
|
|
130
|
+
};
|
|
131
|
+
type CurrencyItem = BaseDetailItem & {
|
|
132
|
+
type: DetailItemType.CURRENCY;
|
|
133
|
+
value: bigint;
|
|
134
|
+
maxDecimals: number;
|
|
135
|
+
symbol: string;
|
|
136
|
+
};
|
|
137
|
+
type DataItem = BaseDetailItem & {
|
|
138
|
+
type: DetailItemType.DATA;
|
|
139
|
+
value: string;
|
|
140
|
+
};
|
|
141
|
+
type DateItem = BaseDetailItem & {
|
|
142
|
+
type: DetailItemType.DATE;
|
|
143
|
+
value: string;
|
|
144
|
+
};
|
|
145
|
+
type LinkItemValue = {
|
|
146
|
+
url: string;
|
|
147
|
+
name?: string;
|
|
148
|
+
icon?: string;
|
|
149
|
+
};
|
|
150
|
+
type LinkItem = BaseDetailItem & {
|
|
151
|
+
type: DetailItemType.LINK;
|
|
152
|
+
value: LinkItemValue;
|
|
153
|
+
};
|
|
154
|
+
type DetailItem = string | TextItem | AddressItem | NodeIDItem | CurrencyItem | DataItem | DateItem | LinkItem | FundsRecipientItem;
|
|
155
|
+
type DisplayData = {
|
|
156
|
+
title: string;
|
|
157
|
+
dAppInfo?: {
|
|
158
|
+
name: string;
|
|
159
|
+
action: string;
|
|
160
|
+
logoUri?: string;
|
|
161
|
+
};
|
|
162
|
+
network: {
|
|
163
|
+
chainId: number;
|
|
164
|
+
name: string;
|
|
165
|
+
logoUri?: string;
|
|
166
|
+
};
|
|
167
|
+
account?: string;
|
|
168
|
+
details: DetailSection[];
|
|
169
|
+
networkFeeSelector?: boolean;
|
|
170
|
+
disclaimer?: string;
|
|
171
|
+
alert?: Alert;
|
|
172
|
+
balanceChange?: BalanceChange;
|
|
173
|
+
tokenApprovals?: TokenApprovals;
|
|
174
|
+
isSimulationSuccessful?: boolean;
|
|
175
|
+
};
|
|
176
|
+
declare enum AlertType {
|
|
177
|
+
WARNING = "Warning",
|
|
178
|
+
DANGER = "Danger",
|
|
179
|
+
INFO = "Info"
|
|
180
|
+
}
|
|
181
|
+
type AlertDetails = {
|
|
182
|
+
title: string;
|
|
183
|
+
description: string;
|
|
184
|
+
detailedDescription?: string;
|
|
185
|
+
actionTitles?: {
|
|
186
|
+
proceed: string;
|
|
187
|
+
reject: string;
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
type Alert = {
|
|
191
|
+
type: AlertType;
|
|
192
|
+
details: AlertDetails;
|
|
193
|
+
};
|
|
194
|
+
type BitcoinExecuteTxData = {
|
|
195
|
+
to: string;
|
|
196
|
+
amount: number;
|
|
197
|
+
feeRate: number;
|
|
198
|
+
fee: number;
|
|
199
|
+
gasLimit: number;
|
|
200
|
+
balance: TokenWithBalanceBTC;
|
|
201
|
+
inputs: BitcoinInputUTXO[];
|
|
202
|
+
outputs: BitcoinOutputUTXO[];
|
|
203
|
+
};
|
|
204
|
+
type BitcoingSignTxData = {
|
|
205
|
+
inputs: BitcoinInputUTXO[];
|
|
206
|
+
outputs: BitcoinOutputUTXO[];
|
|
207
|
+
};
|
|
208
|
+
type SigningData = {
|
|
209
|
+
type: RpcMethod.BITCOIN_SEND_TRANSACTION;
|
|
210
|
+
account: string;
|
|
211
|
+
data: BitcoinExecuteTxData;
|
|
212
|
+
} | {
|
|
213
|
+
type: RpcMethod.BITCOIN_SIGN_TRANSACTION;
|
|
214
|
+
account: string;
|
|
215
|
+
data: BitcoingSignTxData;
|
|
216
|
+
} | SigningData_EthSendTx | {
|
|
217
|
+
type: RpcMethod.ETH_SIGN | RpcMethod.PERSONAL_SIGN;
|
|
218
|
+
account: string;
|
|
219
|
+
data: string;
|
|
220
|
+
} | {
|
|
221
|
+
type: RpcMethod.SIGN_TYPED_DATA | RpcMethod.SIGN_TYPED_DATA_V1;
|
|
222
|
+
account: string;
|
|
223
|
+
data: TypedData<MessageTypes> | TypedDataV1;
|
|
224
|
+
} | {
|
|
225
|
+
type: RpcMethod.SIGN_TYPED_DATA_V3 | RpcMethod.SIGN_TYPED_DATA_V4;
|
|
226
|
+
account: string;
|
|
227
|
+
data: TypedData<MessageTypes>;
|
|
228
|
+
} | {
|
|
229
|
+
type: RpcMethod.AVALANCHE_SIGN_MESSAGE;
|
|
230
|
+
data: string;
|
|
231
|
+
accountIndex?: number;
|
|
232
|
+
} | {
|
|
233
|
+
type: RpcMethod.AVALANCHE_SEND_TRANSACTION;
|
|
234
|
+
unsignedTxJson: string;
|
|
235
|
+
data: Avalanche.Tx;
|
|
236
|
+
vm: 'EVM' | 'AVM' | 'PVM';
|
|
237
|
+
externalIndices?: number[];
|
|
238
|
+
internalIndices?: number[];
|
|
239
|
+
} | {
|
|
240
|
+
type: RpcMethod.AVALANCHE_SIGN_TRANSACTION;
|
|
241
|
+
unsignedTxJson: string;
|
|
242
|
+
data: Avalanche.Tx;
|
|
243
|
+
vm: 'EVM' | 'AVM' | 'PVM';
|
|
244
|
+
ownSignatureIndices: [number, number][];
|
|
245
|
+
} | {
|
|
246
|
+
type: RpcMethod.HVM_SIGN_TRANSACTION;
|
|
247
|
+
data: {
|
|
248
|
+
abi: VMABI;
|
|
249
|
+
txPayload: TransactionPayload;
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
type SigningData_EthSendTx = {
|
|
253
|
+
type: RpcMethod.ETH_SEND_TRANSACTION;
|
|
254
|
+
account: string;
|
|
255
|
+
data: TransactionRequest;
|
|
256
|
+
};
|
|
257
|
+
type EvmTxBatchUpdateFn = (data: {
|
|
258
|
+
maxFeeRate?: bigint;
|
|
259
|
+
maxTipRate?: bigint;
|
|
260
|
+
}, txIndex: number) => {
|
|
261
|
+
displayData: DisplayData;
|
|
262
|
+
signingRequests: {
|
|
263
|
+
displayData: DisplayData;
|
|
264
|
+
signingData: SigningData_EthSendTx;
|
|
265
|
+
}[];
|
|
266
|
+
};
|
|
267
|
+
type EvmTxUpdateFn = (data: {
|
|
268
|
+
maxFeeRate?: bigint;
|
|
269
|
+
maxTipRate?: bigint;
|
|
270
|
+
approvalLimit?: Hex;
|
|
271
|
+
}) => {
|
|
272
|
+
displayData: DisplayData;
|
|
273
|
+
signingData: SigningData_EthSendTx;
|
|
274
|
+
};
|
|
275
|
+
type BtcTxUpdateFn = (data: {
|
|
276
|
+
feeRate?: number;
|
|
277
|
+
}) => {
|
|
278
|
+
displayData: DisplayData;
|
|
279
|
+
signingData: Extract<SigningData, {
|
|
280
|
+
type: RpcMethod.BITCOIN_SEND_TRANSACTION;
|
|
281
|
+
}>;
|
|
282
|
+
};
|
|
283
|
+
type SigningRequest<Data = SigningData> = {
|
|
284
|
+
displayData: DisplayData;
|
|
285
|
+
signingData: Data;
|
|
286
|
+
updateTx?: EvmTxUpdateFn | BtcTxUpdateFn;
|
|
287
|
+
};
|
|
288
|
+
type ApprovalParams = {
|
|
289
|
+
request: RpcRequest;
|
|
290
|
+
} & SigningRequest;
|
|
291
|
+
type BatchApprovalParams = {
|
|
292
|
+
request: RpcRequest;
|
|
293
|
+
signingRequests: SigningRequest<SigningData_EthSendTx>[];
|
|
294
|
+
displayData: DisplayData;
|
|
295
|
+
updateTx: EvmTxBatchUpdateFn;
|
|
296
|
+
};
|
|
297
|
+
/**
|
|
298
|
+
* We want to accept both a signed data (tx/message) and a tx hash as a response
|
|
299
|
+
* coming in from the client apps, hence the XORs here.
|
|
300
|
+
*
|
|
301
|
+
* The reason we need to support both is because extension allows importing
|
|
302
|
+
* external software wallets, such as Fireblocks or other apps that support
|
|
303
|
+
* the WalletConnect protocol.
|
|
304
|
+
*
|
|
305
|
+
* My experience is that WalletConnect apps rarely, if ever, support
|
|
306
|
+
* "eth_signTransaction" requests and more often only allow sending
|
|
307
|
+
* "eth_sendTransaction" calls, which means that all we'll get in response
|
|
308
|
+
* from them is the transaction hash (not a signed tx).
|
|
309
|
+
*/
|
|
310
|
+
type SignedData = {
|
|
311
|
+
signedData: string;
|
|
312
|
+
};
|
|
313
|
+
type BroadcastedTx = {
|
|
314
|
+
txHash: string;
|
|
315
|
+
};
|
|
316
|
+
type SigningResult = SignedData | BroadcastedTx;
|
|
317
|
+
type ApprovalResponse = {
|
|
318
|
+
error: RpcError;
|
|
319
|
+
} | SigningResult;
|
|
320
|
+
type BatchApprovalResponse = {
|
|
321
|
+
error: RpcError;
|
|
322
|
+
} | {
|
|
323
|
+
result: SignedData[];
|
|
324
|
+
};
|
|
325
|
+
interface ApprovalController {
|
|
326
|
+
requestApproval: (params: ApprovalParams) => Promise<ApprovalResponse>;
|
|
327
|
+
onTransactionConfirmed: (txHash: Hex, requestId: string) => void;
|
|
328
|
+
onTransactionReverted: (txHash: Hex, requestId: string) => void;
|
|
329
|
+
}
|
|
330
|
+
interface BatchApprovalController extends ApprovalController {
|
|
331
|
+
requestBatchApproval: (params: BatchApprovalParams) => Promise<BatchApprovalResponse>;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export { AddressItem as A, BaseDetailItem as B, CurrencyItem as C, DappInfo as D, EvmTxBatchUpdateFn as E, FundsRecipientItem as F, BatchApprovalResponse as G, ApprovalController as H, BatchApprovalController as I, BalanceChange as J, TokenDiff as K, LinkItemValue as L, MessageTypeProperty as M, NodeIDItem as N, TokenDiffItem as O, TokenApproval as P, TokenApprovals as Q, RpcMethod as R, SigningData as S, TypedData as T, TransactionSimulationResult as U, RpcRequest as a, RpcError as b, RpcResponse as c, MessageTypes as d, TypedDataV1 as e, DetailSection as f, DetailItemType as g, TextItem as h, DataItem as i, DateItem as j, LinkItem as k, DetailItem as l, DisplayData as m, AlertType as n, AlertDetails as o, Alert as p, BitcoinExecuteTxData as q, BitcoingSignTxData as r, SigningData_EthSendTx as s, EvmTxUpdateFn as t, BtcTxUpdateFn as u, SigningRequest as v, ApprovalParams as w, BatchApprovalParams as x, SigningResult as y, ApprovalResponse as z };
|
package/dist/rpc.cjs
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkIQHOBS5Y_cjs = require('./chunk-IQHOBS5Y.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
Object.defineProperty(exports, 'AlertType', {
|
|
8
8
|
enumerable: true,
|
|
9
|
-
get: function () { return
|
|
9
|
+
get: function () { return chunkIQHOBS5Y_cjs.c; }
|
|
10
10
|
});
|
|
11
11
|
Object.defineProperty(exports, 'DetailItemType', {
|
|
12
12
|
enumerable: true,
|
|
13
|
-
get: function () { return
|
|
13
|
+
get: function () { return chunkIQHOBS5Y_cjs.b; }
|
|
14
14
|
});
|
|
15
15
|
Object.defineProperty(exports, 'RpcMethod', {
|
|
16
16
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
17
|
+
get: function () { return chunkIQHOBS5Y_cjs.a; }
|
|
18
18
|
});
|
|
19
19
|
//# sourceMappingURL=out.js.map
|
|
20
20
|
//# sourceMappingURL=rpc.cjs.map
|