@frak-labs/nexus-sdk 0.0.9 → 0.0.11
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-7MVQQ2X6.js +381 -0
- package/dist/chunk-ETV4XYOV.cjs +7 -0
- package/dist/chunk-GUDT2W6I.js +70 -0
- package/dist/chunk-IQQTTKJL.cjs +70 -0
- package/dist/chunk-PKBMQBKP.js +7 -0
- package/dist/chunk-S5FVCA2E.cjs +86 -0
- package/dist/chunk-V3S6RBRJ.cjs +381 -0
- package/dist/client-C7u9zGwC.d.cts +332 -0
- package/dist/client-gE3fYzkD.d.ts +332 -0
- package/dist/core/actions/index.cjs +3 -3
- package/dist/core/actions/index.d.cts +21 -28
- package/dist/core/actions/index.d.ts +21 -28
- package/dist/core/actions/index.js +12 -12
- package/dist/core/index.cjs +3 -8
- package/dist/core/index.d.cts +8 -35
- package/dist/core/index.d.ts +8 -35
- package/dist/core/index.js +9 -14
- package/dist/core/interactions/index.cjs +13 -0
- package/dist/core/interactions/index.d.cts +53 -0
- package/dist/core/interactions/index.d.ts +53 -0
- package/dist/core/interactions/index.js +13 -0
- package/dist/error-C4Zm5nQe.d.cts +27 -0
- package/dist/error-C4Zm5nQe.d.ts +27 -0
- package/dist/interaction-D3-M3nBh.d.cts +22 -0
- package/dist/interaction-D3-M3nBh.d.ts +22 -0
- package/dist/react/index.cjs +279 -166
- package/dist/react/index.d.cts +80 -37
- package/dist/react/index.d.ts +80 -37
- package/dist/react/index.js +291 -178
- package/dist/sendTransaction-BZW627cT.d.cts +30 -0
- package/dist/sendTransaction-DpJTfGJc.d.ts +30 -0
- package/package.json +16 -7
- package/dist/chunk-AYZHGMEV.cjs +0 -171
- package/dist/chunk-PDR3CF3P.js +0 -86
- package/dist/chunk-SZUN32YC.js +0 -171
- package/dist/chunk-VK7GPKK4.js +0 -169
- package/dist/chunk-X4JNNWJ4.cjs +0 -86
- package/dist/chunk-ZOLP2FJZ.cjs +0 -169
- package/dist/client-BwzXSgqQ.d.cts +0 -278
- package/dist/client-BwzXSgqQ.d.ts +0 -278
- package/dist/watchUnlockStatus-DXClCYH9.d.cts +0 -43
- package/dist/watchUnlockStatus-WJxoDliF.d.ts +0 -43
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkETV4XYOVcjs = require('./chunk-ETV4XYOV.cjs');
|
|
4
|
+
|
|
5
|
+
// src/core/types/rpc/error.ts
|
|
6
|
+
var FrakRpcError = class extends Error {
|
|
7
|
+
constructor(code, message, data) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.data = data;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
var ClientNotFound = class extends FrakRpcError {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(RpcErrorCodes.clientNotConnected, "Client not found");
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var RpcErrorCodes = {
|
|
19
|
+
// Standard JSON-RPC 2.0 errors
|
|
20
|
+
parseError: -32700,
|
|
21
|
+
invalidRequest: -32600,
|
|
22
|
+
methodNotFound: -32601,
|
|
23
|
+
invalidParams: -32602,
|
|
24
|
+
internalError: -32603,
|
|
25
|
+
serverError: -32e3,
|
|
26
|
+
// Frak specific errors (from -32001 to -32099)
|
|
27
|
+
clientNotConnected: -32001,
|
|
28
|
+
configError: -32002,
|
|
29
|
+
corruptedResponse: -32003,
|
|
30
|
+
clientAborted: -32004,
|
|
31
|
+
walletNotConnected: -32005,
|
|
32
|
+
noInteractionSession: -32006
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// src/core/utils/Deferred.ts
|
|
36
|
+
var Deferred = class {
|
|
37
|
+
constructor() {
|
|
38
|
+
_chunkETV4XYOVcjs.__publicField.call(void 0, this, "_promise");
|
|
39
|
+
_chunkETV4XYOVcjs.__publicField.call(void 0, this, "_resolve");
|
|
40
|
+
_chunkETV4XYOVcjs.__publicField.call(void 0, this, "_reject");
|
|
41
|
+
_chunkETV4XYOVcjs.__publicField.call(void 0, this, "resolve", (value) => {
|
|
42
|
+
_optionalChain([this, 'access', _2 => _2._resolve, 'optionalCall', _3 => _3(value)]);
|
|
43
|
+
});
|
|
44
|
+
_chunkETV4XYOVcjs.__publicField.call(void 0, this, "reject", (reason) => {
|
|
45
|
+
_optionalChain([this, 'access', _4 => _4._reject, 'optionalCall', _5 => _5(reason)]);
|
|
46
|
+
});
|
|
47
|
+
this._promise = new Promise((resolve, reject) => {
|
|
48
|
+
this._resolve = resolve;
|
|
49
|
+
this._reject = reject;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
get promise() {
|
|
53
|
+
return this._promise;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// src/core/utils/compression/compress.ts
|
|
58
|
+
var _asynclzstring = require('async-lz-string');
|
|
59
|
+
var _jssha256 = require('js-sha256');
|
|
60
|
+
async function hashAndCompressData(data) {
|
|
61
|
+
const validationHash = _jssha256.sha256.call(void 0, JSON.stringify(data));
|
|
62
|
+
const hashProtectedData = {
|
|
63
|
+
...data,
|
|
64
|
+
validationHash
|
|
65
|
+
};
|
|
66
|
+
const compressed = await compressJson(hashProtectedData);
|
|
67
|
+
const compressedHash = _jssha256.sha256.call(void 0, compressed);
|
|
68
|
+
return {
|
|
69
|
+
compressed,
|
|
70
|
+
compressedHash
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async function compressJson(data) {
|
|
74
|
+
return _asynclzstring.compressToBase64.call(void 0, JSON.stringify(data));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/core/utils/compression/decompress.ts
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
async function decompressDataAndCheckHash(compressedData) {
|
|
81
|
+
if (!(_optionalChain([compressedData, 'optionalAccess', _6 => _6.compressed]) && _optionalChain([compressedData, 'optionalAccess', _7 => _7.compressedHash]))) {
|
|
82
|
+
throw new FrakRpcError(
|
|
83
|
+
RpcErrorCodes.corruptedResponse,
|
|
84
|
+
"Missing compressed data"
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
const parsedData = await decompressJson(
|
|
88
|
+
compressedData.compressed
|
|
89
|
+
);
|
|
90
|
+
if (!parsedData) {
|
|
91
|
+
throw new FrakRpcError(
|
|
92
|
+
RpcErrorCodes.corruptedResponse,
|
|
93
|
+
"Invalid compressed data"
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
if (!_optionalChain([parsedData, 'optionalAccess', _8 => _8.validationHash])) {
|
|
97
|
+
throw new FrakRpcError(
|
|
98
|
+
RpcErrorCodes.corruptedResponse,
|
|
99
|
+
"Missing validation hash"
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
const expectedCompressedHash = _jssha256.sha256.call(void 0, compressedData.compressed);
|
|
103
|
+
if (expectedCompressedHash !== compressedData.compressedHash) {
|
|
104
|
+
throw new FrakRpcError(
|
|
105
|
+
RpcErrorCodes.corruptedResponse,
|
|
106
|
+
"Invalid compressed hash"
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
const { validationHash: _, ...rawResultData } = parsedData;
|
|
110
|
+
const expectedValidationHash = _jssha256.sha256.call(void 0, JSON.stringify(rawResultData));
|
|
111
|
+
if (expectedValidationHash !== parsedData.validationHash) {
|
|
112
|
+
throw new FrakRpcError(
|
|
113
|
+
RpcErrorCodes.corruptedResponse,
|
|
114
|
+
"Invalid data validation hash"
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
return parsedData;
|
|
118
|
+
}
|
|
119
|
+
async function decompressJson(data) {
|
|
120
|
+
const decompressed = await _asynclzstring.decompressFromBase64.call(void 0, data);
|
|
121
|
+
try {
|
|
122
|
+
return JSON.parse(decompressed);
|
|
123
|
+
} catch (e) {
|
|
124
|
+
console.error("Invalid compressed data", e);
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/core/clients/transports/iframeChannelManager.ts
|
|
130
|
+
function createIFrameChannelManager() {
|
|
131
|
+
const channels = /* @__PURE__ */ new Map();
|
|
132
|
+
return {
|
|
133
|
+
// TODO: Better id system?? uid stuff?
|
|
134
|
+
createChannel: (resolver) => {
|
|
135
|
+
const id = Math.random().toString(36).substring(7);
|
|
136
|
+
channels.set(id, resolver);
|
|
137
|
+
return id;
|
|
138
|
+
},
|
|
139
|
+
getRpcResolver: (id) => channels.get(id),
|
|
140
|
+
removeChannel: (id) => channels.delete(id),
|
|
141
|
+
destroy: () => channels.clear()
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/core/utils/iframeHelper.ts
|
|
146
|
+
var baseIframeProps = {
|
|
147
|
+
id: "nexus-wallet",
|
|
148
|
+
name: "nexus-wallet",
|
|
149
|
+
allow: "publickey-credentials-get *; clipboard-write; web-share *",
|
|
150
|
+
style: {
|
|
151
|
+
width: "0",
|
|
152
|
+
height: "0",
|
|
153
|
+
border: "0",
|
|
154
|
+
position: "absolute",
|
|
155
|
+
zIndex: 1e3,
|
|
156
|
+
top: "-1000px",
|
|
157
|
+
left: "-1000px"
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
function createIframe({
|
|
161
|
+
walletBaseUrl
|
|
162
|
+
}) {
|
|
163
|
+
const alreadyCreatedIFrame = document.querySelector("#nexus-wallet");
|
|
164
|
+
if (alreadyCreatedIFrame) {
|
|
165
|
+
return Promise.resolve(void 0);
|
|
166
|
+
}
|
|
167
|
+
const iframe = document.createElement("iframe");
|
|
168
|
+
iframe.id = baseIframeProps.id;
|
|
169
|
+
iframe.name = baseIframeProps.name;
|
|
170
|
+
iframe.allow = baseIframeProps.allow;
|
|
171
|
+
iframe.style.zIndex = baseIframeProps.style.zIndex.toString();
|
|
172
|
+
changeIframeVisibility({ iframe, isVisible: false });
|
|
173
|
+
document.body.appendChild(iframe);
|
|
174
|
+
return new Promise((resolve) => {
|
|
175
|
+
_optionalChain([iframe, 'optionalAccess', _9 => _9.addEventListener, 'call', _10 => _10("load", () => resolve(iframe))]);
|
|
176
|
+
iframe.src = `${walletBaseUrl}/listener`;
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
function changeIframeVisibility({
|
|
180
|
+
iframe,
|
|
181
|
+
isVisible
|
|
182
|
+
}) {
|
|
183
|
+
if (!isVisible) {
|
|
184
|
+
iframe.style.width = "0";
|
|
185
|
+
iframe.style.height = "0";
|
|
186
|
+
iframe.style.border = "0";
|
|
187
|
+
iframe.style.position = "fixed";
|
|
188
|
+
iframe.style.top = "-1000px";
|
|
189
|
+
iframe.style.left = "-1000px";
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
iframe.style.position = "fixed";
|
|
193
|
+
iframe.style.top = "0";
|
|
194
|
+
iframe.style.left = "0";
|
|
195
|
+
iframe.style.width = "100%";
|
|
196
|
+
iframe.style.height = "100%";
|
|
197
|
+
iframe.style.pointerEvents = "auto";
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// src/core/clients/transports/iframeMessageHandler.ts
|
|
201
|
+
function createIFrameMessageHandler({
|
|
202
|
+
nexusWalletUrl,
|
|
203
|
+
metadata,
|
|
204
|
+
iframe,
|
|
205
|
+
channelManager
|
|
206
|
+
}) {
|
|
207
|
+
if (typeof window === "undefined") {
|
|
208
|
+
throw new FrakRpcError(
|
|
209
|
+
RpcErrorCodes.configError,
|
|
210
|
+
"iframe client should be used in the browser"
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
if (!iframe.contentWindow) {
|
|
214
|
+
throw new FrakRpcError(
|
|
215
|
+
RpcErrorCodes.configError,
|
|
216
|
+
"The iframe does not have a content window"
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
const contentWindow = iframe.contentWindow;
|
|
220
|
+
const isConnectedDeferred = new Deferred();
|
|
221
|
+
const msgHandler = async (event) => {
|
|
222
|
+
if (!event.origin) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (new URL(event.origin).origin.toLowerCase() !== new URL(nexusWalletUrl).origin.toLowerCase()) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if ("lifecycle" in event.data) {
|
|
229
|
+
switch (event.data.lifecycle) {
|
|
230
|
+
case "connected":
|
|
231
|
+
isConnectedDeferred.resolve(true);
|
|
232
|
+
break;
|
|
233
|
+
case "show":
|
|
234
|
+
case "hide":
|
|
235
|
+
changeIframeVisibility({
|
|
236
|
+
iframe,
|
|
237
|
+
isVisible: event.data.lifecycle === "show"
|
|
238
|
+
});
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const channel = event.data.id;
|
|
244
|
+
const resolver = channelManager.getRpcResolver(channel);
|
|
245
|
+
if (!resolver) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
await resolver(event.data);
|
|
249
|
+
};
|
|
250
|
+
window.addEventListener("message", msgHandler);
|
|
251
|
+
const sendEvent = (message) => {
|
|
252
|
+
contentWindow.postMessage(message, {
|
|
253
|
+
targetOrigin: nexusWalletUrl
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
const cleanup = () => {
|
|
257
|
+
window.removeEventListener("message", msgHandler);
|
|
258
|
+
};
|
|
259
|
+
const isConnected = injectCssOnConnect({
|
|
260
|
+
isConnected: isConnectedDeferred.promise,
|
|
261
|
+
metadata,
|
|
262
|
+
sendEvent
|
|
263
|
+
});
|
|
264
|
+
return {
|
|
265
|
+
isConnected,
|
|
266
|
+
sendEvent,
|
|
267
|
+
cleanup
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
function injectCssOnConnect({
|
|
271
|
+
isConnected,
|
|
272
|
+
metadata,
|
|
273
|
+
sendEvent
|
|
274
|
+
}) {
|
|
275
|
+
const css = _optionalChain([metadata, 'optionalAccess', _11 => _11.css]);
|
|
276
|
+
if (!css) {
|
|
277
|
+
return isConnected;
|
|
278
|
+
}
|
|
279
|
+
return isConnected.then((connected) => {
|
|
280
|
+
sendEvent({
|
|
281
|
+
lifecycle: "modal-css",
|
|
282
|
+
data: css
|
|
283
|
+
});
|
|
284
|
+
return connected;
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// src/core/clients/createIFrameNexusClient.ts
|
|
289
|
+
function createIFrameNexusClient({
|
|
290
|
+
config,
|
|
291
|
+
iframe
|
|
292
|
+
}) {
|
|
293
|
+
const channelManager = createIFrameChannelManager();
|
|
294
|
+
const messageHandler = createIFrameMessageHandler({
|
|
295
|
+
nexusWalletUrl: config.walletUrl,
|
|
296
|
+
metadata: config.metadata,
|
|
297
|
+
iframe,
|
|
298
|
+
channelManager
|
|
299
|
+
});
|
|
300
|
+
const request = async (args) => {
|
|
301
|
+
const isConnected = await messageHandler.isConnected;
|
|
302
|
+
if (!isConnected) {
|
|
303
|
+
throw new FrakRpcError(
|
|
304
|
+
RpcErrorCodes.clientNotConnected,
|
|
305
|
+
"The iframe provider isn't connected yet"
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
const result = new Deferred();
|
|
309
|
+
const channelId = channelManager.createChannel(async (message) => {
|
|
310
|
+
const decompressed = await decompressDataAndCheckHash(message.data);
|
|
311
|
+
if (decompressed.error) {
|
|
312
|
+
result.reject(
|
|
313
|
+
new FrakRpcError(
|
|
314
|
+
decompressed.error.code,
|
|
315
|
+
decompressed.error.message,
|
|
316
|
+
_optionalChain([decompressed, 'access', _12 => _12.error, 'optionalAccess', _13 => _13.data])
|
|
317
|
+
)
|
|
318
|
+
);
|
|
319
|
+
} else {
|
|
320
|
+
result.resolve(decompressed.result);
|
|
321
|
+
}
|
|
322
|
+
channelManager.removeChannel(channelId);
|
|
323
|
+
});
|
|
324
|
+
const compressedMessage = await hashAndCompressData(args);
|
|
325
|
+
messageHandler.sendEvent({
|
|
326
|
+
id: channelId,
|
|
327
|
+
// @ts-ignore, todo: idk why the fck it's needed
|
|
328
|
+
topic: args.method,
|
|
329
|
+
data: compressedMessage
|
|
330
|
+
});
|
|
331
|
+
return result.promise;
|
|
332
|
+
};
|
|
333
|
+
const listenerRequest = async (args, callback) => {
|
|
334
|
+
const isConnected = await messageHandler.isConnected;
|
|
335
|
+
if (!isConnected) {
|
|
336
|
+
throw new FrakRpcError(
|
|
337
|
+
RpcErrorCodes.clientNotConnected,
|
|
338
|
+
"The iframe provider isn't connected yet"
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
const channelId = channelManager.createChannel(async (message) => {
|
|
342
|
+
const decompressed = await decompressDataAndCheckHash(message.data);
|
|
343
|
+
if (decompressed.result) {
|
|
344
|
+
callback(decompressed.result);
|
|
345
|
+
} else {
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
const compressedMessage = await hashAndCompressData(args);
|
|
349
|
+
messageHandler.sendEvent({
|
|
350
|
+
id: channelId,
|
|
351
|
+
topic: args.method,
|
|
352
|
+
data: compressedMessage
|
|
353
|
+
});
|
|
354
|
+
};
|
|
355
|
+
const destroy = async () => {
|
|
356
|
+
channelManager.destroy();
|
|
357
|
+
messageHandler.cleanup();
|
|
358
|
+
iframe.remove();
|
|
359
|
+
};
|
|
360
|
+
return {
|
|
361
|
+
config,
|
|
362
|
+
waitForConnection: messageHandler.isConnected,
|
|
363
|
+
request,
|
|
364
|
+
listenerRequest,
|
|
365
|
+
destroy
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
exports.FrakRpcError = FrakRpcError; exports.ClientNotFound = ClientNotFound; exports.RpcErrorCodes = RpcErrorCodes; exports.Deferred = Deferred; exports.hashAndCompressData = hashAndCompressData; exports.compressJson = compressJson; exports.decompressDataAndCheckHash = decompressDataAndCheckHash; exports.decompressJson = decompressJson; exports.baseIframeProps = baseIframeProps; exports.createIframe = createIframe; exports.createIFrameNexusClient = createIFrameNexusClient;
|
|
@@ -0,0 +1,332 @@
|
|
|
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
|
+
* SSO Metadata
|
|
20
|
+
*/
|
|
21
|
+
type SsoMetadata = {
|
|
22
|
+
logoUrl: string;
|
|
23
|
+
homepageLink: string;
|
|
24
|
+
links?: {
|
|
25
|
+
confidentialityLink?: string;
|
|
26
|
+
helpLink?: string;
|
|
27
|
+
cguLink?: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Params to start a SSO
|
|
32
|
+
*/
|
|
33
|
+
type OpenSsoParamsType = {
|
|
34
|
+
redirectUrl?: string;
|
|
35
|
+
directExit?: boolean;
|
|
36
|
+
metadata: SsoMetadata;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Represent a generic modal step type
|
|
41
|
+
*/
|
|
42
|
+
type GenericModalStepType<TKey, TParams, TReturns> = {
|
|
43
|
+
key: TKey;
|
|
44
|
+
params: TParams extends never ? ModalStepMetadata : ModalStepMetadata & TParams;
|
|
45
|
+
returns: TReturns;
|
|
46
|
+
};
|
|
47
|
+
type ModalStepMetadata = {
|
|
48
|
+
metadata?: {
|
|
49
|
+
title?: string;
|
|
50
|
+
description?: string;
|
|
51
|
+
primaryActionText?: string;
|
|
52
|
+
secondaryActionText?: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
type LoginWithSso = {
|
|
57
|
+
allowSso: true;
|
|
58
|
+
ssoMetadata: SsoMetadata;
|
|
59
|
+
};
|
|
60
|
+
type LoginWithoutSso = {
|
|
61
|
+
allowSso?: false;
|
|
62
|
+
ssoMetadata?: never;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Generic type of modal we will display to the end user
|
|
66
|
+
*/
|
|
67
|
+
type LoginModalStepType = GenericModalStepType<"login", {
|
|
68
|
+
articleUrl?: string;
|
|
69
|
+
} & (LoginWithSso | LoginWithoutSso), {
|
|
70
|
+
wallet: Address;
|
|
71
|
+
}>;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Parameters of the send transaction rpc request
|
|
75
|
+
*/
|
|
76
|
+
type SiweAuthenticationParams = Omit<SiweMessage, "address" | "chainId">;
|
|
77
|
+
/**
|
|
78
|
+
* Return type of the send transaction rpc request
|
|
79
|
+
*/
|
|
80
|
+
type SiweAuthenticateReturnType = Readonly<{
|
|
81
|
+
signature: Hex;
|
|
82
|
+
message: string;
|
|
83
|
+
}>;
|
|
84
|
+
/**
|
|
85
|
+
* Generic type of modal we will display to the end user
|
|
86
|
+
*/
|
|
87
|
+
type SiweAuthenticateModalStepType = GenericModalStepType<"siweAuthenticate", {
|
|
88
|
+
siwe: SiweAuthenticationParams;
|
|
89
|
+
}, SiweAuthenticateReturnType>;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Generic format representing a tx to be sent
|
|
93
|
+
* todo: exploit the EIP-5792 here? https://eips.ethereum.org/EIPS/eip-5792
|
|
94
|
+
*/
|
|
95
|
+
type SendTransactionTxType = Readonly<{
|
|
96
|
+
to: Address;
|
|
97
|
+
data?: Hex;
|
|
98
|
+
value?: Hex;
|
|
99
|
+
}>;
|
|
100
|
+
/**
|
|
101
|
+
* Return type of the send transaction rpc request
|
|
102
|
+
*/
|
|
103
|
+
type SendTransactionReturnType = Readonly<{
|
|
104
|
+
hash: Hex;
|
|
105
|
+
}>;
|
|
106
|
+
type SendTransactionModalStepType = GenericModalStepType<"sendTransaction", {
|
|
107
|
+
tx: SendTransactionTxType | SendTransactionTxType[];
|
|
108
|
+
}, SendTransactionReturnType>;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Return type of the send transaction rpc request
|
|
112
|
+
*/
|
|
113
|
+
type OpenInteractionSessionReturnType = Readonly<{
|
|
114
|
+
startTimestamp: number;
|
|
115
|
+
endTimestamp: number;
|
|
116
|
+
}>;
|
|
117
|
+
/**
|
|
118
|
+
* Generic type of modal we will display to the end user
|
|
119
|
+
*/
|
|
120
|
+
type OpenInteractionSessionModalStepType = GenericModalStepType<"openSession", object, OpenInteractionSessionReturnType>;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Generic type of modal we will display to the end user
|
|
124
|
+
*/
|
|
125
|
+
type SuccessModalStepType = GenericModalStepType<"success", {
|
|
126
|
+
sharing?: {
|
|
127
|
+
popupTitle?: string;
|
|
128
|
+
text?: string;
|
|
129
|
+
link?: string;
|
|
130
|
+
};
|
|
131
|
+
}, object>;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Generic type of steps we will display in the modal to the end user
|
|
135
|
+
*/
|
|
136
|
+
type ModalStepTypes = LoginModalStepType | SiweAuthenticateModalStepType | SendTransactionModalStepType | OpenInteractionSessionModalStepType | SuccessModalStepType;
|
|
137
|
+
/**
|
|
138
|
+
* Type for the result of a modal request
|
|
139
|
+
*/
|
|
140
|
+
type ModalRpcStepsResultType<T extends ModalStepTypes[] = ModalStepTypes[]> = {
|
|
141
|
+
[K in T[number]["key"]]: Extract<T[number], {
|
|
142
|
+
key: K;
|
|
143
|
+
}>["returns"];
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Type for the RPC input of a modal
|
|
147
|
+
*/
|
|
148
|
+
type ModalRpcStepsInput<T extends ModalStepTypes[] = ModalStepTypes[]> = {
|
|
149
|
+
[K in T[number]["key"]]?: Extract<T[number], {
|
|
150
|
+
key: K;
|
|
151
|
+
}>["params"];
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* RPC metadata for the modal
|
|
155
|
+
*/
|
|
156
|
+
type ModalRpcMetadata = Readonly<{
|
|
157
|
+
header?: {
|
|
158
|
+
title?: string;
|
|
159
|
+
icon?: string;
|
|
160
|
+
};
|
|
161
|
+
context?: string;
|
|
162
|
+
}>;
|
|
163
|
+
/**
|
|
164
|
+
* Generic params used to display modals
|
|
165
|
+
*/
|
|
166
|
+
type DisplayModalParamsType<T extends ModalStepTypes[]> = {
|
|
167
|
+
steps: ModalRpcStepsInput<T>;
|
|
168
|
+
metadata?: ModalRpcMetadata;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
type WalletStatusReturnType = Readonly<WalletConnected | WalletNotConnected>;
|
|
172
|
+
type WalletConnected = {
|
|
173
|
+
key: "connected";
|
|
174
|
+
wallet: Address;
|
|
175
|
+
interactionSession?: {
|
|
176
|
+
startTimestamp: number;
|
|
177
|
+
endTimestamp: number;
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
type WalletNotConnected = {
|
|
181
|
+
key: "not-connected";
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* RPC interface that's used for the iframe communication
|
|
186
|
+
*/
|
|
187
|
+
type IFrameRpcSchema = [
|
|
188
|
+
/**
|
|
189
|
+
* Method used to listen to the wallet status
|
|
190
|
+
*/
|
|
191
|
+
{
|
|
192
|
+
Method: "frak_listenToWalletStatus";
|
|
193
|
+
Parameters?: undefined;
|
|
194
|
+
ReturnType: WalletStatusReturnType;
|
|
195
|
+
},
|
|
196
|
+
/**
|
|
197
|
+
* Method to transmit a user interaction
|
|
198
|
+
*/
|
|
199
|
+
{
|
|
200
|
+
Method: "frak_displayModal";
|
|
201
|
+
Parameters: [
|
|
202
|
+
requests: ModalRpcStepsInput,
|
|
203
|
+
name: string,
|
|
204
|
+
metadata?: ModalRpcMetadata
|
|
205
|
+
];
|
|
206
|
+
ReturnType: ModalRpcStepsResultType;
|
|
207
|
+
},
|
|
208
|
+
/**
|
|
209
|
+
* Method to transmit a user interaction
|
|
210
|
+
*/
|
|
211
|
+
{
|
|
212
|
+
Method: "frak_sendInteraction";
|
|
213
|
+
Parameters: [
|
|
214
|
+
contentId: Hex,
|
|
215
|
+
interaction: PreparedInteraction,
|
|
216
|
+
signature?: Hex
|
|
217
|
+
];
|
|
218
|
+
ReturnType: SendInteractionReturnType;
|
|
219
|
+
},
|
|
220
|
+
/**
|
|
221
|
+
* Method to start a SSO
|
|
222
|
+
*/
|
|
223
|
+
{
|
|
224
|
+
Method: "frak_sso";
|
|
225
|
+
Parameters: [
|
|
226
|
+
params: OpenSsoParamsType,
|
|
227
|
+
name: string,
|
|
228
|
+
customCss?: string
|
|
229
|
+
];
|
|
230
|
+
ReturnType: undefined;
|
|
231
|
+
}
|
|
232
|
+
];
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Type that extract the possible parameters from a RPC Schema
|
|
236
|
+
*/
|
|
237
|
+
type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema> = {
|
|
238
|
+
[K in keyof TRpcSchema]: Prettify<{
|
|
239
|
+
method: TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Method"] : string;
|
|
240
|
+
} & (TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Parameters"] extends undefined ? {
|
|
241
|
+
params?: never;
|
|
242
|
+
} : {
|
|
243
|
+
params: TRpcSchema[K]["Parameters"];
|
|
244
|
+
} : never)>;
|
|
245
|
+
}[number];
|
|
246
|
+
/**
|
|
247
|
+
* Type that extract the possible return type from a RPC Schema
|
|
248
|
+
*/
|
|
249
|
+
type ExtractedReturnTypeFromRpc<TRpcSchema extends RpcSchema, TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>> = ExtractedMethodFromRpc<TRpcSchema, TParameters["method"]>["ReturnType"];
|
|
250
|
+
/**
|
|
251
|
+
* Type that extract the possible return type from a RPC Schema
|
|
252
|
+
*/
|
|
253
|
+
type ExtractedMethodFromRpc<TRpcSchema extends RpcSchema, TMethod extends ExtractedParametersFromRpc<TRpcSchema>["method"] = ExtractedParametersFromRpc<TRpcSchema>["method"]> = Extract<TRpcSchema[number], {
|
|
254
|
+
Method: TMethod;
|
|
255
|
+
}>;
|
|
256
|
+
/**
|
|
257
|
+
* Raw response that we will receive after an rpc request
|
|
258
|
+
*/
|
|
259
|
+
type RpcResponse<TRpcSchema extends RpcSchema, TMethod extends TRpcSchema[number]["Method"] = TRpcSchema[number]["Method"]> = {
|
|
260
|
+
result: Extract<TRpcSchema[number], {
|
|
261
|
+
Method: TMethod;
|
|
262
|
+
}>["ReturnType"];
|
|
263
|
+
error?: never;
|
|
264
|
+
} | {
|
|
265
|
+
result?: never;
|
|
266
|
+
error: {
|
|
267
|
+
code: number;
|
|
268
|
+
message: string;
|
|
269
|
+
data?: unknown;
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* Type used for a one shot request function
|
|
274
|
+
*/
|
|
275
|
+
type RequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>, _ReturnType = ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>>(args: TParameters) => Promise<_ReturnType>;
|
|
276
|
+
/**
|
|
277
|
+
* Type used for a one shot request function
|
|
278
|
+
*/
|
|
279
|
+
type ListenerRequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>>(args: TParameters, callback: (result: ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>) => void) => Promise<void>;
|
|
280
|
+
/**
|
|
281
|
+
* IFrame transport interface
|
|
282
|
+
*/
|
|
283
|
+
type IFrameTransport = {
|
|
284
|
+
/**
|
|
285
|
+
* Wait for the connection to be established
|
|
286
|
+
*/
|
|
287
|
+
waitForConnection: Promise<boolean>;
|
|
288
|
+
/**
|
|
289
|
+
* Function used to perform a single request via the iframe transport
|
|
290
|
+
*/
|
|
291
|
+
request: RequestFn<IFrameRpcSchema>;
|
|
292
|
+
/**
|
|
293
|
+
* Function used to listen to a request response via the iframe transport
|
|
294
|
+
*/
|
|
295
|
+
listenerRequest: ListenerRequestFn<IFrameRpcSchema>;
|
|
296
|
+
/**
|
|
297
|
+
* Function used to destroy the iframe transport
|
|
298
|
+
*/
|
|
299
|
+
destroy: () => Promise<void>;
|
|
300
|
+
};
|
|
301
|
+
/**
|
|
302
|
+
* Represent an iframe event
|
|
303
|
+
*/
|
|
304
|
+
type IFrameEvent = IFrameRpcEvent | IFrameLifecycleEvent;
|
|
305
|
+
/**
|
|
306
|
+
* Represent an iframe rpc event
|
|
307
|
+
*/
|
|
308
|
+
type IFrameRpcEvent = {
|
|
309
|
+
id: string;
|
|
310
|
+
topic: ExtractedParametersFromRpc<IFrameRpcSchema>["method"];
|
|
311
|
+
data: {
|
|
312
|
+
compressed: string;
|
|
313
|
+
compressedHash: string;
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
type IFrameLifecycleEvent = {
|
|
317
|
+
lifecycle: "connected" | "show" | "hide";
|
|
318
|
+
data: never;
|
|
319
|
+
} | LifecycleEventCSS;
|
|
320
|
+
type LifecycleEventCSS = {
|
|
321
|
+
lifecycle: "modal-css";
|
|
322
|
+
data: string;
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Representing a Nexus client
|
|
327
|
+
*/
|
|
328
|
+
type NexusClient = {
|
|
329
|
+
config: NexusWalletSdkConfig;
|
|
330
|
+
} & IFrameTransport;
|
|
331
|
+
|
|
332
|
+
export type { 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, ExtractedReturnTypeFromRpc as r };
|