-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtypes.ts
276 lines (238 loc) · 6.31 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
import { parseAbi } from 'abitype';
import { AccountManagerAbi } from './abi';
import { TypedContract } from 'ethers-abitype';
import { ethers } from 'ethers6';
import { ProviderRpcError } from 'viem';
import { ProxyWriteFunctionsByStrategy, WalletType } from './constants';
const wacAbi = parseAbi(AccountManagerAbi);
export type WebauthnContract = TypedContract<typeof wacAbi>;
export type Network = {
name: string;
id: number;
rpcUrl: string;
explorerUrl: string;
imageUrl?: string; // Icon of the chain for display in UI
currencySymbol?: string; // Symbol of the native currency (default is 'ETH')
currencyDecimals?: number; // Number of decimals of the native currency (default is 18)
};
export type SignatureCallback = (gaslessData: string) => Promise<{
signature: string;
gasLimit?: number;
gasPrice?: number;
timestamp: number;
error?: string;
}>;
export type AppParams = {
/**
* The Apillon integration UUID, obtained from the Apillon Developer Console
*/
clientId: string;
/**
* Network ID for network (chain) selected on first use
*/
defaultNetworkId?: number;
/**
* Configuration of available networks. Oasis Sapphire is always included (ids 23294 and 23295)
*
* @example
```ts
[
{
name: 'Moonbase Testnet',
id: 1287,
rpcUrl: 'https://rpc.testnet.moonbeam.network',
explorerUrl: 'https://moonbase.moonscan.io',
}
]
```
*/
networks?: Network[];
/**
* Method for authenticating with passkey to make it global.
*/
passkeyAuthMode?: AuthPasskeyMode;
};
export type AuthData = {
username: string;
password?: string;
hashedUsername?: Buffer | undefined;
privateKey?: string;
};
export type RegisterData = {
hashedUsername: Buffer | Uint8Array | string;
credentialId: Uint8Array | string;
pubkey: {
kty: number;
alg: number;
crv: number;
x: bigint | number;
y: bigint | number;
};
optionalPassword: string;
};
type AllValuesOf<T> = T extends any ? T[keyof T] : never;
export type AuthProxyWriteFns = AllValuesOf<
(typeof ProxyWriteFunctionsByStrategy)[keyof typeof ProxyWriteFunctionsByStrategy]
>;
export interface AuthStrategy {
getRegisterData(authData: AuthData): Promise<RegisterData | undefined>;
getProxyResponse(data: string, authData: AuthData): Promise<any>;
proxyWrite(
functionName: AuthProxyWriteFns,
data: string,
authData: AuthData,
txLabel?: string,
dontWait?: boolean
): Promise<any>;
}
export type AuthPasskeyMode = 'redirect' | 'popup' | 'tab_form';
export type AuthPasskeyModeInternal = 'iframe' | 'standalone';
export type AuthStrategyName = 'password' | 'passkey';
export type UserInfo = {
username: string;
strategy: AuthStrategyName;
publicAddress: string | ethers.Addressable;
accountContractAddress: string | ethers.Addressable;
};
export type AccountWalletTypes = (typeof WalletType)[keyof typeof WalletType];
export type AccountWallet = {
walletType: AccountWalletTypes;
address: string;
index: number;
};
export type PlainTransactionParams = {
strategy?: AuthStrategyName;
authData?: AuthData;
walletIndex?: number;
tx: ethers.TransactionLike<ethers.AddressLike>;
label?: string;
mustConfirm?: boolean;
resolve?: (result: { signedTxData: any; chainId?: number }) => void;
reject?: (reason?: any) => void;
};
export type SignMessageParams = {
strategy?: AuthStrategyName;
authData?: AuthData;
walletIndex?: number;
message: ethers.BytesLike | string;
data?: string;
mustConfirm?: boolean;
resolve?: (value: string) => void;
reject?: (reason?: any) => void;
};
export type ContractReadParams = {
contractAbi: ethers.InterfaceAbi;
contractFunctionName: string;
contractFunctionValues?: any[];
contractAddress: string;
chainId?: number;
};
export type ContractWriteParams = {
strategy?: AuthStrategyName;
authData?: AuthData;
walletIndex?: number;
label?: string;
mustConfirm?: boolean;
resolve?: (result: { signedTxData: any; chainId?: number }) => void;
reject?: (reason?: any) => void;
} & ContractReadParams;
export enum GaslessTxType {
CreateAccount,
ManageCredential,
ManageCredentialPassword,
AddWallet,
AddWalletPassword,
}
export type TransactionItem = {
hash: string;
label: string;
rawData: any;
owner: string;
status: 'pending' | 'confirmed' | 'failed';
chainId: number;
explorerUrl: string;
createdAt: number; // timestamp
internalLabel?: string;
internalData?: string;
};
export type Events = {
signatureRequest: SignMessageParams;
txApprove: { plain?: PlainTransactionParams; contractWrite?: ContractWriteParams };
txSubmitted: TransactionItem;
txDone: TransactionItem; // emitted by UI
dataUpdated: {
name:
| 'username'
| 'authStrategy'
| 'defaultNetworkId'
| 'sessionToken'
| 'wallets'
| 'walletIndex'
| 'address'
| 'contractAddress';
newValue: any;
oldValue: any;
};
/**
* Event for UI -- to enable programmatic opening
*/
open: boolean;
/**
* Event for UI -- programmatically add a token
*/
addToken: {
address: string;
name: string;
symbol: string;
decimals: number;
imageUrl?: string;
chainId?: number;
};
/**
* Event for UI -- programmatically add an NFT
*/
addTokenNft: {
address: string;
tokenId: number;
name?: string;
imageUrl?: string;
chainId?: number;
};
/**
* Feedback for `addToken` and `addTokenNft` events
*/
addTokenStatus: {
success: boolean;
info?: string;
token?: Events['addToken'];
nft?: Events['addTokenNft'];
};
/**
* Triggered in 'eth_requestAccounts' provider request handler.
* Receives resolver fn that should be invoked when user's account is available (after sign in / register)
*/
providerRequestAccounts: (address: string) => void;
/**
* Emitted when tx chainId is different from defaultNetworkId.
* Must be resolve()'d to continue with the tx execution.
*/
requestChainChange: { chainId: number; resolve: (confirmed: boolean) => void };
/**
* Provider event
* @chainId hex
*/
connect: { chainId: string };
/**
* Provider event
*/
disconnect: { error: ProviderRpcError };
/**
* Provider event
* @chainId hex
*/
chainChanged: { chainId: string };
/**
* Provider event
*/
accountsChanged: string[];
};