@frak-labs/nexus-sdk 0.0.10 → 0.0.12
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/chunk-5CFD5FM2.js +86 -0
- package/dist/chunk-BJ3CCN5P.cjs +424 -0
- package/dist/{chunk-72IEHEQX.js → chunk-GUDT2W6I.js} +32 -10
- package/dist/chunk-HXVDI2IY.js +424 -0
- package/dist/{chunk-NIFJZD3M.cjs → chunk-IQQTTKJL.cjs} +30 -8
- package/dist/chunk-S5FVCA2E.cjs +86 -0
- package/dist/client-B6_BIGc3.d.ts +357 -0
- package/dist/client-Oily5ph8.d.cts +357 -0
- package/dist/core/actions/index.cjs +2 -7
- package/dist/core/actions/index.d.cts +16 -35
- package/dist/core/actions/index.d.ts +16 -35
- package/dist/core/actions/index.js +5 -10
- package/dist/core/index.cjs +2 -4
- package/dist/core/index.d.cts +19 -19
- package/dist/core/index.d.ts +19 -19
- package/dist/core/index.js +2 -4
- package/dist/core/interactions/index.cjs +6 -2
- package/dist/core/interactions/index.d.cts +20 -6
- package/dist/core/interactions/index.d.ts +20 -6
- package/dist/core/interactions/index.js +7 -3
- package/dist/{interaction-D_CzyqRE.d.cts → interaction-D3-M3nBh.d.cts} +2 -2
- package/dist/{interaction-D_CzyqRE.d.ts → interaction-D3-M3nBh.d.ts} +2 -2
- package/dist/react/index.cjs +156 -158
- package/dist/react/index.d.cts +44 -51
- package/dist/react/index.d.ts +44 -51
- package/dist/react/index.js +162 -164
- package/dist/sendTransaction-BHqCq_9X.d.ts +30 -0
- package/dist/sendTransaction-BKKYEt8p.d.cts +30 -0
- package/package.json +8 -5
- package/dist/chunk-3T2FNW6E.cjs +0 -100
- package/dist/chunk-BPFJZRJ6.cjs +0 -152
- package/dist/chunk-HOX3RRO6.js +0 -199
- package/dist/chunk-SGLR6RFA.cjs +0 -199
- package/dist/chunk-T54VMWHQ.js +0 -100
- package/dist/chunk-TPC5PMRC.js +0 -152
- package/dist/client--U_6SK0l.d.cts +0 -339
- package/dist/client-6_BJp7Ub.d.ts +0 -339
- package/dist/watchUnlockStatus-CxnibdQx.d.cts +0 -43
- package/dist/watchUnlockStatus-g8wIxpeM.d.ts +0 -43
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import { Address, Hex, RpcSchema } from 'viem';
|
|
2
|
+
import { Prettify } from 'viem/chains';
|
|
3
|
+
import { SiweMessage } from 'viem/siwe';
|
|
4
|
+
import { P as PreparedInteraction, a as SendInteractionReturnType } from './interaction-D3-M3nBh.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Configuration for the Nexus Wallet SDK
|
|
8
|
+
*/
|
|
9
|
+
type NexusWalletSdkConfig = Readonly<{
|
|
10
|
+
walletUrl: string;
|
|
11
|
+
metadata: {
|
|
12
|
+
name: string;
|
|
13
|
+
css?: string;
|
|
14
|
+
};
|
|
15
|
+
domain: string;
|
|
16
|
+
}>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Event related to the iframe lifecycle
|
|
20
|
+
*/
|
|
21
|
+
type IFrameLifecycleEvent = {
|
|
22
|
+
iframeLifecycle: "connected" | "show" | "hide";
|
|
23
|
+
data?: never;
|
|
24
|
+
} | DoBackupEvent;
|
|
25
|
+
type DoBackupEvent = {
|
|
26
|
+
iframeLifecycle: "do-backup";
|
|
27
|
+
data: {
|
|
28
|
+
backup?: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Event related to the iframe lifecycle
|
|
34
|
+
*/
|
|
35
|
+
type ClientLifecycleEvent = CustomCssEvent | RestoreBackupEvent;
|
|
36
|
+
type CustomCssEvent = {
|
|
37
|
+
clientLifecycle: "modal-css";
|
|
38
|
+
data: {
|
|
39
|
+
cssLink: string;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
type RestoreBackupEvent = {
|
|
43
|
+
clientLifecycle: "restore-backup";
|
|
44
|
+
data: {
|
|
45
|
+
backup: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* SSO Metadata
|
|
51
|
+
*/
|
|
52
|
+
type SsoMetadata = {
|
|
53
|
+
logoUrl: string;
|
|
54
|
+
homepageLink: string;
|
|
55
|
+
links?: {
|
|
56
|
+
confidentialityLink?: string;
|
|
57
|
+
helpLink?: string;
|
|
58
|
+
cguLink?: string;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Params to start a SSO
|
|
63
|
+
*/
|
|
64
|
+
type OpenSsoParamsType = {
|
|
65
|
+
redirectUrl?: string;
|
|
66
|
+
directExit?: boolean;
|
|
67
|
+
metadata: SsoMetadata;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Represent a generic modal step type
|
|
72
|
+
*/
|
|
73
|
+
type GenericModalStepType<TKey, TParams, TReturns> = {
|
|
74
|
+
key: TKey;
|
|
75
|
+
params: TParams extends never ? ModalStepMetadata : ModalStepMetadata & TParams;
|
|
76
|
+
returns: TReturns;
|
|
77
|
+
};
|
|
78
|
+
type ModalStepMetadata = {
|
|
79
|
+
metadata?: {
|
|
80
|
+
title?: string;
|
|
81
|
+
description?: string;
|
|
82
|
+
primaryActionText?: string;
|
|
83
|
+
secondaryActionText?: string;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
type LoginWithSso = {
|
|
88
|
+
allowSso: true;
|
|
89
|
+
ssoMetadata: SsoMetadata;
|
|
90
|
+
};
|
|
91
|
+
type LoginWithoutSso = {
|
|
92
|
+
allowSso?: false;
|
|
93
|
+
ssoMetadata?: never;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Generic type of modal we will display to the end user
|
|
97
|
+
*/
|
|
98
|
+
type LoginModalStepType = GenericModalStepType<"login", LoginWithSso | LoginWithoutSso, {
|
|
99
|
+
wallet: Address;
|
|
100
|
+
}>;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Parameters of the send transaction rpc request
|
|
104
|
+
*/
|
|
105
|
+
type SiweAuthenticationParams = Omit<SiweMessage, "address" | "chainId">;
|
|
106
|
+
/**
|
|
107
|
+
* Return type of the send transaction rpc request
|
|
108
|
+
*/
|
|
109
|
+
type SiweAuthenticateReturnType = Readonly<{
|
|
110
|
+
signature: Hex;
|
|
111
|
+
message: string;
|
|
112
|
+
}>;
|
|
113
|
+
/**
|
|
114
|
+
* Generic type of modal we will display to the end user
|
|
115
|
+
*/
|
|
116
|
+
type SiweAuthenticateModalStepType = GenericModalStepType<"siweAuthenticate", {
|
|
117
|
+
siwe: SiweAuthenticationParams;
|
|
118
|
+
}, SiweAuthenticateReturnType>;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Generic format representing a tx to be sent
|
|
122
|
+
* todo: exploit the EIP-5792 here? https://eips.ethereum.org/EIPS/eip-5792
|
|
123
|
+
*/
|
|
124
|
+
type SendTransactionTxType = Readonly<{
|
|
125
|
+
to: Address;
|
|
126
|
+
data?: Hex;
|
|
127
|
+
value?: Hex;
|
|
128
|
+
}>;
|
|
129
|
+
/**
|
|
130
|
+
* Return type of the send transaction rpc request
|
|
131
|
+
*/
|
|
132
|
+
type SendTransactionReturnType = Readonly<{
|
|
133
|
+
hash: Hex;
|
|
134
|
+
}>;
|
|
135
|
+
type SendTransactionModalStepType = GenericModalStepType<"sendTransaction", {
|
|
136
|
+
tx: SendTransactionTxType | SendTransactionTxType[];
|
|
137
|
+
}, SendTransactionReturnType>;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Return type of the send transaction rpc request
|
|
141
|
+
*/
|
|
142
|
+
type OpenInteractionSessionReturnType = Readonly<{
|
|
143
|
+
startTimestamp: number;
|
|
144
|
+
endTimestamp: number;
|
|
145
|
+
}>;
|
|
146
|
+
/**
|
|
147
|
+
* Generic type of modal we will display to the end user
|
|
148
|
+
*/
|
|
149
|
+
type OpenInteractionSessionModalStepType = GenericModalStepType<"openSession", object, OpenInteractionSessionReturnType>;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Generic type of modal we will display to the end user
|
|
153
|
+
*/
|
|
154
|
+
type SuccessModalStepType = GenericModalStepType<"success", {
|
|
155
|
+
sharing?: {
|
|
156
|
+
popupTitle?: string;
|
|
157
|
+
text?: string;
|
|
158
|
+
link?: string;
|
|
159
|
+
};
|
|
160
|
+
}, object>;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Generic type of steps we will display in the modal to the end user
|
|
164
|
+
*/
|
|
165
|
+
type ModalStepTypes = LoginModalStepType | SiweAuthenticateModalStepType | SendTransactionModalStepType | OpenInteractionSessionModalStepType | SuccessModalStepType;
|
|
166
|
+
/**
|
|
167
|
+
* Type for the result of a modal request
|
|
168
|
+
*/
|
|
169
|
+
type ModalRpcStepsResultType<T extends ModalStepTypes[] = ModalStepTypes[]> = {
|
|
170
|
+
[K in T[number]["key"]]: Extract<T[number], {
|
|
171
|
+
key: K;
|
|
172
|
+
}>["returns"];
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Type for the RPC input of a modal
|
|
176
|
+
*/
|
|
177
|
+
type ModalRpcStepsInput<T extends ModalStepTypes[] = ModalStepTypes[]> = {
|
|
178
|
+
[K in T[number]["key"]]?: Extract<T[number], {
|
|
179
|
+
key: K;
|
|
180
|
+
}>["params"];
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* RPC metadata for the modal
|
|
184
|
+
*/
|
|
185
|
+
type ModalRpcMetadata = Readonly<{
|
|
186
|
+
header?: {
|
|
187
|
+
title?: string;
|
|
188
|
+
icon?: string;
|
|
189
|
+
};
|
|
190
|
+
context?: string;
|
|
191
|
+
}>;
|
|
192
|
+
/**
|
|
193
|
+
* Generic params used to display modals
|
|
194
|
+
*/
|
|
195
|
+
type DisplayModalParamsType<T extends ModalStepTypes[]> = {
|
|
196
|
+
steps: ModalRpcStepsInput<T>;
|
|
197
|
+
metadata?: ModalRpcMetadata;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
type WalletStatusReturnType = Readonly<WalletConnected | WalletNotConnected>;
|
|
201
|
+
type WalletConnected = {
|
|
202
|
+
key: "connected";
|
|
203
|
+
wallet: Address;
|
|
204
|
+
interactionSession?: {
|
|
205
|
+
startTimestamp: number;
|
|
206
|
+
endTimestamp: number;
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
type WalletNotConnected = {
|
|
210
|
+
key: "not-connected";
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* RPC interface that's used for the iframe communication
|
|
215
|
+
*/
|
|
216
|
+
type IFrameRpcSchema = [
|
|
217
|
+
/**
|
|
218
|
+
* Method used to listen to the wallet status
|
|
219
|
+
*/
|
|
220
|
+
{
|
|
221
|
+
Method: "frak_listenToWalletStatus";
|
|
222
|
+
Parameters?: undefined;
|
|
223
|
+
ReturnType: WalletStatusReturnType;
|
|
224
|
+
},
|
|
225
|
+
/**
|
|
226
|
+
* Method to transmit a user interaction
|
|
227
|
+
*/
|
|
228
|
+
{
|
|
229
|
+
Method: "frak_displayModal";
|
|
230
|
+
Parameters: [
|
|
231
|
+
requests: ModalRpcStepsInput,
|
|
232
|
+
name: string,
|
|
233
|
+
metadata?: ModalRpcMetadata
|
|
234
|
+
];
|
|
235
|
+
ReturnType: ModalRpcStepsResultType;
|
|
236
|
+
},
|
|
237
|
+
/**
|
|
238
|
+
* Method to transmit a user interaction
|
|
239
|
+
*/
|
|
240
|
+
{
|
|
241
|
+
Method: "frak_sendInteraction";
|
|
242
|
+
Parameters: [
|
|
243
|
+
contentId: Hex,
|
|
244
|
+
interaction: PreparedInteraction,
|
|
245
|
+
signature?: Hex
|
|
246
|
+
];
|
|
247
|
+
ReturnType: SendInteractionReturnType;
|
|
248
|
+
},
|
|
249
|
+
/**
|
|
250
|
+
* Method to start a SSO
|
|
251
|
+
*/
|
|
252
|
+
{
|
|
253
|
+
Method: "frak_sso";
|
|
254
|
+
Parameters: [
|
|
255
|
+
params: OpenSsoParamsType,
|
|
256
|
+
name: string,
|
|
257
|
+
customCss?: string
|
|
258
|
+
];
|
|
259
|
+
ReturnType: undefined;
|
|
260
|
+
}
|
|
261
|
+
];
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Type that extract the possible parameters from a RPC Schema
|
|
265
|
+
*/
|
|
266
|
+
type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema> = {
|
|
267
|
+
[K in keyof TRpcSchema]: Prettify<{
|
|
268
|
+
method: TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Method"] : string;
|
|
269
|
+
} & (TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Parameters"] extends undefined ? {
|
|
270
|
+
params?: never;
|
|
271
|
+
} : {
|
|
272
|
+
params: TRpcSchema[K]["Parameters"];
|
|
273
|
+
} : never)>;
|
|
274
|
+
}[number];
|
|
275
|
+
/**
|
|
276
|
+
* Type that extract the possible return type from a RPC Schema
|
|
277
|
+
*/
|
|
278
|
+
type ExtractedReturnTypeFromRpc<TRpcSchema extends RpcSchema, TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>> = ExtractedMethodFromRpc<TRpcSchema, TParameters["method"]>["ReturnType"];
|
|
279
|
+
/**
|
|
280
|
+
* Type that extract the possible return type from a RPC Schema
|
|
281
|
+
*/
|
|
282
|
+
type ExtractedMethodFromRpc<TRpcSchema extends RpcSchema, TMethod extends ExtractedParametersFromRpc<TRpcSchema>["method"] = ExtractedParametersFromRpc<TRpcSchema>["method"]> = Extract<TRpcSchema[number], {
|
|
283
|
+
Method: TMethod;
|
|
284
|
+
}>;
|
|
285
|
+
/**
|
|
286
|
+
* Raw response that we will receive after an rpc request
|
|
287
|
+
*/
|
|
288
|
+
type RpcResponse<TRpcSchema extends RpcSchema, TMethod extends TRpcSchema[number]["Method"] = TRpcSchema[number]["Method"]> = {
|
|
289
|
+
result: Extract<TRpcSchema[number], {
|
|
290
|
+
Method: TMethod;
|
|
291
|
+
}>["ReturnType"];
|
|
292
|
+
error?: never;
|
|
293
|
+
} | {
|
|
294
|
+
result?: never;
|
|
295
|
+
error: {
|
|
296
|
+
code: number;
|
|
297
|
+
message: string;
|
|
298
|
+
data?: unknown;
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
/**
|
|
302
|
+
* Type used for a one shot request function
|
|
303
|
+
*/
|
|
304
|
+
type RequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>, _ReturnType = ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>>(args: TParameters) => Promise<_ReturnType>;
|
|
305
|
+
/**
|
|
306
|
+
* Type used for a one shot request function
|
|
307
|
+
*/
|
|
308
|
+
type ListenerRequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>, _ReturnType = ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>>(args: TParameters, callback: (result: _ReturnType) => void) => Promise<void>;
|
|
309
|
+
/**
|
|
310
|
+
* IFrame transport interface
|
|
311
|
+
*/
|
|
312
|
+
type IFrameTransport = {
|
|
313
|
+
/**
|
|
314
|
+
* Wait for the connection to be established
|
|
315
|
+
*/
|
|
316
|
+
waitForConnection: Promise<boolean>;
|
|
317
|
+
/**
|
|
318
|
+
* Wait for the setup to be done
|
|
319
|
+
*/
|
|
320
|
+
waitForSetup: Promise<void>;
|
|
321
|
+
/**
|
|
322
|
+
* Function used to perform a single request via the iframe transport
|
|
323
|
+
*/
|
|
324
|
+
request: RequestFn<IFrameRpcSchema>;
|
|
325
|
+
/**
|
|
326
|
+
* Function used to listen to a request response via the iframe transport
|
|
327
|
+
*/
|
|
328
|
+
listenerRequest: ListenerRequestFn<IFrameRpcSchema>;
|
|
329
|
+
/**
|
|
330
|
+
* Function used to destroy the iframe transport
|
|
331
|
+
*/
|
|
332
|
+
destroy: () => Promise<void>;
|
|
333
|
+
};
|
|
334
|
+
/**
|
|
335
|
+
* Represent an iframe event
|
|
336
|
+
*/
|
|
337
|
+
type IFrameEvent = IFrameRpcEvent | IFrameLifecycleEvent | ClientLifecycleEvent;
|
|
338
|
+
/**
|
|
339
|
+
* Represent an iframe rpc event
|
|
340
|
+
*/
|
|
341
|
+
type IFrameRpcEvent = {
|
|
342
|
+
id: string;
|
|
343
|
+
topic: ExtractedParametersFromRpc<IFrameRpcSchema>["method"];
|
|
344
|
+
data: {
|
|
345
|
+
compressed: string;
|
|
346
|
+
compressedHash: string;
|
|
347
|
+
};
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Representing a Nexus client
|
|
352
|
+
*/
|
|
353
|
+
type NexusClient = {
|
|
354
|
+
config: NexusWalletSdkConfig;
|
|
355
|
+
} & IFrameTransport;
|
|
356
|
+
|
|
357
|
+
export type { ClientLifecycleEvent as C, DisplayModalParamsType as D, ExtractedParametersFromRpc as E, IFrameRpcSchema as I, LoginModalStepType as L, ModalRpcMetadata as M, NexusClient as N, OpenSsoParamsType as O, RpcResponse as R, SiweAuthenticationParams as S, WalletStatusReturnType as W, SiweAuthenticateReturnType as a, SendTransactionModalStepType as b, SendTransactionReturnType as c, ModalStepTypes as d, ModalRpcStepsResultType as e, NexusWalletSdkConfig as f, SuccessModalStepType as g, SsoMetadata as h, ModalRpcStepsInput as i, ModalStepMetadata as j, SiweAuthenticateModalStepType as k, SendTransactionTxType as l, OpenInteractionSessionReturnType as m, OpenInteractionSessionModalStepType as n, IFrameTransport as o, IFrameRpcEvent as p, IFrameEvent as q, IFrameLifecycleEvent as r, ExtractedReturnTypeFromRpc as s };
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import { Address, Hex, RpcSchema } from 'viem';
|
|
2
|
+
import { Prettify } from 'viem/chains';
|
|
3
|
+
import { SiweMessage } from 'viem/siwe';
|
|
4
|
+
import { P as PreparedInteraction, a as SendInteractionReturnType } from './interaction-D3-M3nBh.cjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Configuration for the Nexus Wallet SDK
|
|
8
|
+
*/
|
|
9
|
+
type NexusWalletSdkConfig = Readonly<{
|
|
10
|
+
walletUrl: string;
|
|
11
|
+
metadata: {
|
|
12
|
+
name: string;
|
|
13
|
+
css?: string;
|
|
14
|
+
};
|
|
15
|
+
domain: string;
|
|
16
|
+
}>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Event related to the iframe lifecycle
|
|
20
|
+
*/
|
|
21
|
+
type IFrameLifecycleEvent = {
|
|
22
|
+
iframeLifecycle: "connected" | "show" | "hide";
|
|
23
|
+
data?: never;
|
|
24
|
+
} | DoBackupEvent;
|
|
25
|
+
type DoBackupEvent = {
|
|
26
|
+
iframeLifecycle: "do-backup";
|
|
27
|
+
data: {
|
|
28
|
+
backup?: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Event related to the iframe lifecycle
|
|
34
|
+
*/
|
|
35
|
+
type ClientLifecycleEvent = CustomCssEvent | RestoreBackupEvent;
|
|
36
|
+
type CustomCssEvent = {
|
|
37
|
+
clientLifecycle: "modal-css";
|
|
38
|
+
data: {
|
|
39
|
+
cssLink: string;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
type RestoreBackupEvent = {
|
|
43
|
+
clientLifecycle: "restore-backup";
|
|
44
|
+
data: {
|
|
45
|
+
backup: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* SSO Metadata
|
|
51
|
+
*/
|
|
52
|
+
type SsoMetadata = {
|
|
53
|
+
logoUrl: string;
|
|
54
|
+
homepageLink: string;
|
|
55
|
+
links?: {
|
|
56
|
+
confidentialityLink?: string;
|
|
57
|
+
helpLink?: string;
|
|
58
|
+
cguLink?: string;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Params to start a SSO
|
|
63
|
+
*/
|
|
64
|
+
type OpenSsoParamsType = {
|
|
65
|
+
redirectUrl?: string;
|
|
66
|
+
directExit?: boolean;
|
|
67
|
+
metadata: SsoMetadata;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Represent a generic modal step type
|
|
72
|
+
*/
|
|
73
|
+
type GenericModalStepType<TKey, TParams, TReturns> = {
|
|
74
|
+
key: TKey;
|
|
75
|
+
params: TParams extends never ? ModalStepMetadata : ModalStepMetadata & TParams;
|
|
76
|
+
returns: TReturns;
|
|
77
|
+
};
|
|
78
|
+
type ModalStepMetadata = {
|
|
79
|
+
metadata?: {
|
|
80
|
+
title?: string;
|
|
81
|
+
description?: string;
|
|
82
|
+
primaryActionText?: string;
|
|
83
|
+
secondaryActionText?: string;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
type LoginWithSso = {
|
|
88
|
+
allowSso: true;
|
|
89
|
+
ssoMetadata: SsoMetadata;
|
|
90
|
+
};
|
|
91
|
+
type LoginWithoutSso = {
|
|
92
|
+
allowSso?: false;
|
|
93
|
+
ssoMetadata?: never;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Generic type of modal we will display to the end user
|
|
97
|
+
*/
|
|
98
|
+
type LoginModalStepType = GenericModalStepType<"login", LoginWithSso | LoginWithoutSso, {
|
|
99
|
+
wallet: Address;
|
|
100
|
+
}>;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Parameters of the send transaction rpc request
|
|
104
|
+
*/
|
|
105
|
+
type SiweAuthenticationParams = Omit<SiweMessage, "address" | "chainId">;
|
|
106
|
+
/**
|
|
107
|
+
* Return type of the send transaction rpc request
|
|
108
|
+
*/
|
|
109
|
+
type SiweAuthenticateReturnType = Readonly<{
|
|
110
|
+
signature: Hex;
|
|
111
|
+
message: string;
|
|
112
|
+
}>;
|
|
113
|
+
/**
|
|
114
|
+
* Generic type of modal we will display to the end user
|
|
115
|
+
*/
|
|
116
|
+
type SiweAuthenticateModalStepType = GenericModalStepType<"siweAuthenticate", {
|
|
117
|
+
siwe: SiweAuthenticationParams;
|
|
118
|
+
}, SiweAuthenticateReturnType>;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Generic format representing a tx to be sent
|
|
122
|
+
* todo: exploit the EIP-5792 here? https://eips.ethereum.org/EIPS/eip-5792
|
|
123
|
+
*/
|
|
124
|
+
type SendTransactionTxType = Readonly<{
|
|
125
|
+
to: Address;
|
|
126
|
+
data?: Hex;
|
|
127
|
+
value?: Hex;
|
|
128
|
+
}>;
|
|
129
|
+
/**
|
|
130
|
+
* Return type of the send transaction rpc request
|
|
131
|
+
*/
|
|
132
|
+
type SendTransactionReturnType = Readonly<{
|
|
133
|
+
hash: Hex;
|
|
134
|
+
}>;
|
|
135
|
+
type SendTransactionModalStepType = GenericModalStepType<"sendTransaction", {
|
|
136
|
+
tx: SendTransactionTxType | SendTransactionTxType[];
|
|
137
|
+
}, SendTransactionReturnType>;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Return type of the send transaction rpc request
|
|
141
|
+
*/
|
|
142
|
+
type OpenInteractionSessionReturnType = Readonly<{
|
|
143
|
+
startTimestamp: number;
|
|
144
|
+
endTimestamp: number;
|
|
145
|
+
}>;
|
|
146
|
+
/**
|
|
147
|
+
* Generic type of modal we will display to the end user
|
|
148
|
+
*/
|
|
149
|
+
type OpenInteractionSessionModalStepType = GenericModalStepType<"openSession", object, OpenInteractionSessionReturnType>;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Generic type of modal we will display to the end user
|
|
153
|
+
*/
|
|
154
|
+
type SuccessModalStepType = GenericModalStepType<"success", {
|
|
155
|
+
sharing?: {
|
|
156
|
+
popupTitle?: string;
|
|
157
|
+
text?: string;
|
|
158
|
+
link?: string;
|
|
159
|
+
};
|
|
160
|
+
}, object>;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Generic type of steps we will display in the modal to the end user
|
|
164
|
+
*/
|
|
165
|
+
type ModalStepTypes = LoginModalStepType | SiweAuthenticateModalStepType | SendTransactionModalStepType | OpenInteractionSessionModalStepType | SuccessModalStepType;
|
|
166
|
+
/**
|
|
167
|
+
* Type for the result of a modal request
|
|
168
|
+
*/
|
|
169
|
+
type ModalRpcStepsResultType<T extends ModalStepTypes[] = ModalStepTypes[]> = {
|
|
170
|
+
[K in T[number]["key"]]: Extract<T[number], {
|
|
171
|
+
key: K;
|
|
172
|
+
}>["returns"];
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Type for the RPC input of a modal
|
|
176
|
+
*/
|
|
177
|
+
type ModalRpcStepsInput<T extends ModalStepTypes[] = ModalStepTypes[]> = {
|
|
178
|
+
[K in T[number]["key"]]?: Extract<T[number], {
|
|
179
|
+
key: K;
|
|
180
|
+
}>["params"];
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* RPC metadata for the modal
|
|
184
|
+
*/
|
|
185
|
+
type ModalRpcMetadata = Readonly<{
|
|
186
|
+
header?: {
|
|
187
|
+
title?: string;
|
|
188
|
+
icon?: string;
|
|
189
|
+
};
|
|
190
|
+
context?: string;
|
|
191
|
+
}>;
|
|
192
|
+
/**
|
|
193
|
+
* Generic params used to display modals
|
|
194
|
+
*/
|
|
195
|
+
type DisplayModalParamsType<T extends ModalStepTypes[]> = {
|
|
196
|
+
steps: ModalRpcStepsInput<T>;
|
|
197
|
+
metadata?: ModalRpcMetadata;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
type WalletStatusReturnType = Readonly<WalletConnected | WalletNotConnected>;
|
|
201
|
+
type WalletConnected = {
|
|
202
|
+
key: "connected";
|
|
203
|
+
wallet: Address;
|
|
204
|
+
interactionSession?: {
|
|
205
|
+
startTimestamp: number;
|
|
206
|
+
endTimestamp: number;
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
type WalletNotConnected = {
|
|
210
|
+
key: "not-connected";
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* RPC interface that's used for the iframe communication
|
|
215
|
+
*/
|
|
216
|
+
type IFrameRpcSchema = [
|
|
217
|
+
/**
|
|
218
|
+
* Method used to listen to the wallet status
|
|
219
|
+
*/
|
|
220
|
+
{
|
|
221
|
+
Method: "frak_listenToWalletStatus";
|
|
222
|
+
Parameters?: undefined;
|
|
223
|
+
ReturnType: WalletStatusReturnType;
|
|
224
|
+
},
|
|
225
|
+
/**
|
|
226
|
+
* Method to transmit a user interaction
|
|
227
|
+
*/
|
|
228
|
+
{
|
|
229
|
+
Method: "frak_displayModal";
|
|
230
|
+
Parameters: [
|
|
231
|
+
requests: ModalRpcStepsInput,
|
|
232
|
+
name: string,
|
|
233
|
+
metadata?: ModalRpcMetadata
|
|
234
|
+
];
|
|
235
|
+
ReturnType: ModalRpcStepsResultType;
|
|
236
|
+
},
|
|
237
|
+
/**
|
|
238
|
+
* Method to transmit a user interaction
|
|
239
|
+
*/
|
|
240
|
+
{
|
|
241
|
+
Method: "frak_sendInteraction";
|
|
242
|
+
Parameters: [
|
|
243
|
+
contentId: Hex,
|
|
244
|
+
interaction: PreparedInteraction,
|
|
245
|
+
signature?: Hex
|
|
246
|
+
];
|
|
247
|
+
ReturnType: SendInteractionReturnType;
|
|
248
|
+
},
|
|
249
|
+
/**
|
|
250
|
+
* Method to start a SSO
|
|
251
|
+
*/
|
|
252
|
+
{
|
|
253
|
+
Method: "frak_sso";
|
|
254
|
+
Parameters: [
|
|
255
|
+
params: OpenSsoParamsType,
|
|
256
|
+
name: string,
|
|
257
|
+
customCss?: string
|
|
258
|
+
];
|
|
259
|
+
ReturnType: undefined;
|
|
260
|
+
}
|
|
261
|
+
];
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Type that extract the possible parameters from a RPC Schema
|
|
265
|
+
*/
|
|
266
|
+
type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema> = {
|
|
267
|
+
[K in keyof TRpcSchema]: Prettify<{
|
|
268
|
+
method: TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Method"] : string;
|
|
269
|
+
} & (TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Parameters"] extends undefined ? {
|
|
270
|
+
params?: never;
|
|
271
|
+
} : {
|
|
272
|
+
params: TRpcSchema[K]["Parameters"];
|
|
273
|
+
} : never)>;
|
|
274
|
+
}[number];
|
|
275
|
+
/**
|
|
276
|
+
* Type that extract the possible return type from a RPC Schema
|
|
277
|
+
*/
|
|
278
|
+
type ExtractedReturnTypeFromRpc<TRpcSchema extends RpcSchema, TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>> = ExtractedMethodFromRpc<TRpcSchema, TParameters["method"]>["ReturnType"];
|
|
279
|
+
/**
|
|
280
|
+
* Type that extract the possible return type from a RPC Schema
|
|
281
|
+
*/
|
|
282
|
+
type ExtractedMethodFromRpc<TRpcSchema extends RpcSchema, TMethod extends ExtractedParametersFromRpc<TRpcSchema>["method"] = ExtractedParametersFromRpc<TRpcSchema>["method"]> = Extract<TRpcSchema[number], {
|
|
283
|
+
Method: TMethod;
|
|
284
|
+
}>;
|
|
285
|
+
/**
|
|
286
|
+
* Raw response that we will receive after an rpc request
|
|
287
|
+
*/
|
|
288
|
+
type RpcResponse<TRpcSchema extends RpcSchema, TMethod extends TRpcSchema[number]["Method"] = TRpcSchema[number]["Method"]> = {
|
|
289
|
+
result: Extract<TRpcSchema[number], {
|
|
290
|
+
Method: TMethod;
|
|
291
|
+
}>["ReturnType"];
|
|
292
|
+
error?: never;
|
|
293
|
+
} | {
|
|
294
|
+
result?: never;
|
|
295
|
+
error: {
|
|
296
|
+
code: number;
|
|
297
|
+
message: string;
|
|
298
|
+
data?: unknown;
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
/**
|
|
302
|
+
* Type used for a one shot request function
|
|
303
|
+
*/
|
|
304
|
+
type RequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>, _ReturnType = ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>>(args: TParameters) => Promise<_ReturnType>;
|
|
305
|
+
/**
|
|
306
|
+
* Type used for a one shot request function
|
|
307
|
+
*/
|
|
308
|
+
type ListenerRequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>, _ReturnType = ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>>(args: TParameters, callback: (result: _ReturnType) => void) => Promise<void>;
|
|
309
|
+
/**
|
|
310
|
+
* IFrame transport interface
|
|
311
|
+
*/
|
|
312
|
+
type IFrameTransport = {
|
|
313
|
+
/**
|
|
314
|
+
* Wait for the connection to be established
|
|
315
|
+
*/
|
|
316
|
+
waitForConnection: Promise<boolean>;
|
|
317
|
+
/**
|
|
318
|
+
* Wait for the setup to be done
|
|
319
|
+
*/
|
|
320
|
+
waitForSetup: Promise<void>;
|
|
321
|
+
/**
|
|
322
|
+
* Function used to perform a single request via the iframe transport
|
|
323
|
+
*/
|
|
324
|
+
request: RequestFn<IFrameRpcSchema>;
|
|
325
|
+
/**
|
|
326
|
+
* Function used to listen to a request response via the iframe transport
|
|
327
|
+
*/
|
|
328
|
+
listenerRequest: ListenerRequestFn<IFrameRpcSchema>;
|
|
329
|
+
/**
|
|
330
|
+
* Function used to destroy the iframe transport
|
|
331
|
+
*/
|
|
332
|
+
destroy: () => Promise<void>;
|
|
333
|
+
};
|
|
334
|
+
/**
|
|
335
|
+
* Represent an iframe event
|
|
336
|
+
*/
|
|
337
|
+
type IFrameEvent = IFrameRpcEvent | IFrameLifecycleEvent | ClientLifecycleEvent;
|
|
338
|
+
/**
|
|
339
|
+
* Represent an iframe rpc event
|
|
340
|
+
*/
|
|
341
|
+
type IFrameRpcEvent = {
|
|
342
|
+
id: string;
|
|
343
|
+
topic: ExtractedParametersFromRpc<IFrameRpcSchema>["method"];
|
|
344
|
+
data: {
|
|
345
|
+
compressed: string;
|
|
346
|
+
compressedHash: string;
|
|
347
|
+
};
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Representing a Nexus client
|
|
352
|
+
*/
|
|
353
|
+
type NexusClient = {
|
|
354
|
+
config: NexusWalletSdkConfig;
|
|
355
|
+
} & IFrameTransport;
|
|
356
|
+
|
|
357
|
+
export type { ClientLifecycleEvent as C, DisplayModalParamsType as D, ExtractedParametersFromRpc as E, IFrameRpcSchema as I, LoginModalStepType as L, ModalRpcMetadata as M, NexusClient as N, OpenSsoParamsType as O, RpcResponse as R, SiweAuthenticationParams as S, WalletStatusReturnType as W, SiweAuthenticateReturnType as a, SendTransactionModalStepType as b, SendTransactionReturnType as c, ModalStepTypes as d, ModalRpcStepsResultType as e, NexusWalletSdkConfig as f, SuccessModalStepType as g, SsoMetadata as h, ModalRpcStepsInput as i, ModalStepMetadata as j, SiweAuthenticateModalStepType as k, SendTransactionTxType as l, OpenInteractionSessionReturnType as m, OpenInteractionSessionModalStepType as n, IFrameTransport as o, IFrameRpcEvent as p, IFrameEvent as q, IFrameLifecycleEvent as r, ExtractedReturnTypeFromRpc as s };
|