@fourt/sdk 0.5.0 → 1.1.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/index.cjs +281 -192
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +97 -60
- package/dist/index.d.ts +97 -60
- package/dist/index.js +271 -192
- package/dist/index.js.map +1 -1
- package/package.json +10 -8
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -24,60 +34,6 @@ __export(src_exports, {
|
|
|
24
34
|
});
|
|
25
35
|
module.exports = __toCommonJS(src_exports);
|
|
26
36
|
|
|
27
|
-
// src/signer/web.ts
|
|
28
|
-
var import_webauthn_stamper = require("@turnkey/webauthn-stamper");
|
|
29
|
-
var import_iframe_stamper = require("@turnkey/iframe-stamper");
|
|
30
|
-
|
|
31
|
-
// src/signer/index.ts
|
|
32
|
-
var import_http = require("@turnkey/http");
|
|
33
|
-
|
|
34
|
-
// src/errors/SDKError.ts
|
|
35
|
-
var SDKError = class extends Error {
|
|
36
|
-
_props;
|
|
37
|
-
constructor(message, props) {
|
|
38
|
-
super(message);
|
|
39
|
-
this._props = props;
|
|
40
|
-
}
|
|
41
|
-
get message() {
|
|
42
|
-
return this._props.message;
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// src/errors/UnauthorizedError.ts
|
|
47
|
-
var UnauthorizedError = class _UnauthorizedError extends SDKError {
|
|
48
|
-
constructor(props) {
|
|
49
|
-
super(_UnauthorizedError.name, props);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// src/errors/NotFoundError.ts
|
|
54
|
-
var NotFoundError = class _NotFoundError extends SDKError {
|
|
55
|
-
constructor(props) {
|
|
56
|
-
super(_NotFoundError.name, props);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// src/errors/GenericError.ts
|
|
61
|
-
var GenericError = class _GenericError extends SDKError {
|
|
62
|
-
constructor(props) {
|
|
63
|
-
super(_GenericError.name, props);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
// src/errors/UnauthenticatedError.ts
|
|
68
|
-
var UnauthenticatedError = class _UnauthenticatedError extends SDKError {
|
|
69
|
-
constructor(props) {
|
|
70
|
-
super(_UnauthenticatedError.name, props);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// src/errors/BadRequestError.ts
|
|
75
|
-
var BadRequestError = class _BadRequestError extends SDKError {
|
|
76
|
-
constructor(props) {
|
|
77
|
-
super(_BadRequestError.name, props);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
37
|
// src/session/index.ts
|
|
82
38
|
var import_zustand = require("zustand");
|
|
83
39
|
var import_middleware = require("zustand/middleware");
|
|
@@ -201,6 +157,255 @@ var SessionStore = class {
|
|
|
201
157
|
}
|
|
202
158
|
};
|
|
203
159
|
|
|
160
|
+
// src/modules/auth/email.ts
|
|
161
|
+
var EmailModule = class {
|
|
162
|
+
constructor(_webSignerClient) {
|
|
163
|
+
this._webSignerClient = _webSignerClient;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Initialize user authentication process using email.
|
|
167
|
+
*
|
|
168
|
+
* @param params {EmailInitializeAuthParams} params to initialize the user authentication process.
|
|
169
|
+
* @returns {Promise<void>} promise that resolves to the result of the authentication process.
|
|
170
|
+
*/
|
|
171
|
+
async initialize(params) {
|
|
172
|
+
return this._webSignerClient.emailAuth(params);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Completes authentication with bundle after user receives the bundle and subOrgId as URL params.
|
|
176
|
+
*
|
|
177
|
+
* @param params {CompleteAuthWithBundleParams} params received as URL params necessary to complete authentication process.
|
|
178
|
+
* @returns {Promise<void>} promise that completes the authentication process.
|
|
179
|
+
*/
|
|
180
|
+
async complete(params) {
|
|
181
|
+
return this._webSignerClient.completeAuthWithBundle({
|
|
182
|
+
...params,
|
|
183
|
+
sessionType: "email" /* Email */
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
// src/modules/auth/passkeys.ts
|
|
189
|
+
var PasskeysModule = class {
|
|
190
|
+
constructor(_webSignerClient) {
|
|
191
|
+
this._webSignerClient = _webSignerClient;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Signs in a user using Passkeys.
|
|
195
|
+
*
|
|
196
|
+
* @param params {WebauthnSignInParams} params for the sign-in process.
|
|
197
|
+
* @returns {Promise<void>} promise that resolves to the result of the sign-in process.
|
|
198
|
+
*/
|
|
199
|
+
async signIn(params) {
|
|
200
|
+
return this._webSignerClient.webauthnSignIn(params);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
// src/modules/auth/oauth/google.ts
|
|
205
|
+
var jose = __toESM(require("jose"), 1);
|
|
206
|
+
var import_sha = require("sha.js");
|
|
207
|
+
|
|
208
|
+
// src/errors/SDKError.ts
|
|
209
|
+
var SDKError = class extends Error {
|
|
210
|
+
_props;
|
|
211
|
+
constructor(message, props) {
|
|
212
|
+
super(message);
|
|
213
|
+
this._props = props;
|
|
214
|
+
}
|
|
215
|
+
get message() {
|
|
216
|
+
return this._props.message;
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
// src/errors/BadRequestError.ts
|
|
221
|
+
var BadRequestError = class _BadRequestError extends SDKError {
|
|
222
|
+
constructor(props) {
|
|
223
|
+
super(_BadRequestError.name, props);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
// src/modules/auth/oauth/google.ts
|
|
228
|
+
var GoogleModule = class {
|
|
229
|
+
constructor(_webSignerClient) {
|
|
230
|
+
this._webSignerClient = _webSignerClient;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
*
|
|
234
|
+
* @returns
|
|
235
|
+
*/
|
|
236
|
+
async init() {
|
|
237
|
+
if (!this._webSignerClient.oauthConfiguration?.google) {
|
|
238
|
+
throw new BadRequestError({ message: "Google OAuth is not configured" });
|
|
239
|
+
}
|
|
240
|
+
const url = new URL("https://accounts.google.com/o/oauth2/v2/auth");
|
|
241
|
+
url.searchParams.set(
|
|
242
|
+
"client_id",
|
|
243
|
+
this._webSignerClient.oauthConfiguration?.google?.clientId
|
|
244
|
+
);
|
|
245
|
+
url.searchParams.set("response_type", "code");
|
|
246
|
+
url.searchParams.set("scope", "openid email");
|
|
247
|
+
const internalUrl = new URL(
|
|
248
|
+
"v1/oauth",
|
|
249
|
+
this._webSignerClient.configuration.apiUrl
|
|
250
|
+
).href;
|
|
251
|
+
url.searchParams.set("redirect_uri", internalUrl);
|
|
252
|
+
const publicKey = await this._webSignerClient.getIframePublicKey();
|
|
253
|
+
const nonce = new import_sha.sha256().update(publicKey).digest("hex");
|
|
254
|
+
url.searchParams.set("nonce", nonce);
|
|
255
|
+
const state = new jose.UnsecuredJWT({
|
|
256
|
+
apiKey: this._webSignerClient.configuration.apiKey,
|
|
257
|
+
redirectUrl: this._webSignerClient.oauthConfiguration.common.redirectUrl,
|
|
258
|
+
targetPublicKey: publicKey,
|
|
259
|
+
internalUrl,
|
|
260
|
+
origin: window.location.origin
|
|
261
|
+
}).encode();
|
|
262
|
+
url.searchParams.set("state", state);
|
|
263
|
+
return url.toString();
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
// src/modules/auth/oauth.ts
|
|
268
|
+
var OAuthModule = class {
|
|
269
|
+
constructor(_webSignerClient) {
|
|
270
|
+
this._webSignerClient = _webSignerClient;
|
|
271
|
+
this._googleModule = new GoogleModule(this._webSignerClient);
|
|
272
|
+
}
|
|
273
|
+
_googleModule;
|
|
274
|
+
get google() {
|
|
275
|
+
return this._googleModule;
|
|
276
|
+
}
|
|
277
|
+
async complete({ bundle, subOrgId }) {
|
|
278
|
+
await this._webSignerClient.completeAuthWithBundle({
|
|
279
|
+
bundle,
|
|
280
|
+
subOrgId,
|
|
281
|
+
sessionType: "oauth" /* OAuth */
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
// src/modules/auth/index.ts
|
|
287
|
+
var AuthModule = class {
|
|
288
|
+
/**
|
|
289
|
+
* Initializes a new instance of the `AuthModule` class.
|
|
290
|
+
*
|
|
291
|
+
* @param {WebSignerClient} _webSignerClient underlying WebSigner client instance.
|
|
292
|
+
*/
|
|
293
|
+
constructor(_webSignerClient) {
|
|
294
|
+
this._webSignerClient = _webSignerClient;
|
|
295
|
+
this._passkeys = new PasskeysModule(this._webSignerClient);
|
|
296
|
+
this._email = new EmailModule(this._webSignerClient);
|
|
297
|
+
this._oauth = new OAuthModule(this._webSignerClient);
|
|
298
|
+
}
|
|
299
|
+
_passkeys;
|
|
300
|
+
_email;
|
|
301
|
+
_oauth;
|
|
302
|
+
/**
|
|
303
|
+
* A module for interacting with the Passkeys authentication methods.
|
|
304
|
+
*/
|
|
305
|
+
get passkeys() {
|
|
306
|
+
return this._passkeys;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* A module for interacting with the Passkeys authentication methods.
|
|
310
|
+
*/
|
|
311
|
+
get email() {
|
|
312
|
+
return this._email;
|
|
313
|
+
}
|
|
314
|
+
get oauth() {
|
|
315
|
+
return this._oauth;
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
// src/modules/user/index.ts
|
|
320
|
+
var UserModule = class {
|
|
321
|
+
/**
|
|
322
|
+
* Initializes a new instance of the `UserModule` class.
|
|
323
|
+
*
|
|
324
|
+
* @param {WebSignerClient} _webSignerClient underlying WebSigner client instance.
|
|
325
|
+
*/
|
|
326
|
+
constructor(_webSignerClient) {
|
|
327
|
+
this._webSignerClient = _webSignerClient;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Gets the user information.
|
|
331
|
+
*
|
|
332
|
+
* @returns {User | undefined} user information.
|
|
333
|
+
*/
|
|
334
|
+
get info() {
|
|
335
|
+
return this._webSignerClient.user;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Logs out the user.
|
|
339
|
+
*
|
|
340
|
+
* @returns {void}
|
|
341
|
+
*/
|
|
342
|
+
logout() {
|
|
343
|
+
return this._webSignerClient.logout();
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
// src/signer/web.ts
|
|
348
|
+
var import_http2 = require("@turnkey/http");
|
|
349
|
+
var import_iframe_stamper = require("@turnkey/iframe-stamper");
|
|
350
|
+
var import_webauthn_stamper = require("@turnkey/webauthn-stamper");
|
|
351
|
+
|
|
352
|
+
// src/lib/base64.ts
|
|
353
|
+
var import_buffer = require("buffer");
|
|
354
|
+
var LibBase64 = class {
|
|
355
|
+
static fromBuffer(buffer) {
|
|
356
|
+
return import_buffer.Buffer.from(buffer).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
357
|
+
}
|
|
358
|
+
static toBuffer(base64) {
|
|
359
|
+
return import_buffer.Buffer.from(base64, "base64");
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
// src/lib/bytes.ts
|
|
364
|
+
var LibBytes = class {
|
|
365
|
+
static generateRandomBuffer = () => {
|
|
366
|
+
const arr = new Uint8Array(32);
|
|
367
|
+
crypto.getRandomValues(arr);
|
|
368
|
+
return arr.buffer;
|
|
369
|
+
};
|
|
370
|
+
static takeBytes = (bytes, params = {}) => {
|
|
371
|
+
const { offset, count } = params;
|
|
372
|
+
const start = (offset ? offset * 2 : 0) + 2;
|
|
373
|
+
const end = count ? start + count * 2 : void 0;
|
|
374
|
+
return `0x${bytes.slice(start, end)}`;
|
|
375
|
+
};
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
// src/signer/index.ts
|
|
379
|
+
var import_http = require("@turnkey/http");
|
|
380
|
+
|
|
381
|
+
// src/errors/UnauthorizedError.ts
|
|
382
|
+
var UnauthorizedError = class _UnauthorizedError extends SDKError {
|
|
383
|
+
constructor(props) {
|
|
384
|
+
super(_UnauthorizedError.name, props);
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
// src/errors/NotFoundError.ts
|
|
389
|
+
var NotFoundError = class _NotFoundError extends SDKError {
|
|
390
|
+
constructor(props) {
|
|
391
|
+
super(_NotFoundError.name, props);
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
// src/errors/GenericError.ts
|
|
396
|
+
var GenericError = class _GenericError extends SDKError {
|
|
397
|
+
constructor(props) {
|
|
398
|
+
super(_GenericError.name, props);
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
// src/errors/UnauthenticatedError.ts
|
|
403
|
+
var UnauthenticatedError = class _UnauthenticatedError extends SDKError {
|
|
404
|
+
constructor(props) {
|
|
405
|
+
super(_UnauthenticatedError.name, props);
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
|
|
204
409
|
// src/types/Routes.ts
|
|
205
410
|
var ROUTE_METHOD_MAP = {
|
|
206
411
|
"/v1/signup": "POST",
|
|
@@ -228,8 +433,8 @@ var SignerClient = class {
|
|
|
228
433
|
);
|
|
229
434
|
this._configuration = {
|
|
230
435
|
...requiredConfiguration,
|
|
231
|
-
apiUrl: apiUrl ?? "https://auth.api.
|
|
232
|
-
paymasterRpcUrl: paymasterRpcUrl ?? "https://management.api.
|
|
436
|
+
apiUrl: apiUrl ?? "https://auth.api.fourt.io/",
|
|
437
|
+
paymasterRpcUrl: paymasterRpcUrl ?? "https://management.api.fourt.io/"
|
|
233
438
|
};
|
|
234
439
|
this._sessionStore = new SessionStore();
|
|
235
440
|
}
|
|
@@ -366,36 +571,10 @@ var SignerClient = class {
|
|
|
366
571
|
}
|
|
367
572
|
};
|
|
368
573
|
|
|
369
|
-
// src/lib/base64.ts
|
|
370
|
-
var import_buffer = require("buffer");
|
|
371
|
-
var LibBase64 = class {
|
|
372
|
-
static fromBuffer(buffer) {
|
|
373
|
-
return import_buffer.Buffer.from(buffer).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
374
|
-
}
|
|
375
|
-
static toBuffer(base64) {
|
|
376
|
-
return import_buffer.Buffer.from(base64, "base64");
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
|
-
|
|
380
|
-
// src/lib/bytes.ts
|
|
381
|
-
var LibBytes = class {
|
|
382
|
-
static generateRandomBuffer = () => {
|
|
383
|
-
const arr = new Uint8Array(32);
|
|
384
|
-
crypto.getRandomValues(arr);
|
|
385
|
-
return arr.buffer;
|
|
386
|
-
};
|
|
387
|
-
static takeBytes = (bytes, params = {}) => {
|
|
388
|
-
const { offset, count } = params;
|
|
389
|
-
const start = (offset ? offset * 2 : 0) + 2;
|
|
390
|
-
const end = count ? start + count * 2 : void 0;
|
|
391
|
-
return `0x${bytes.slice(start, end)}`;
|
|
392
|
-
};
|
|
393
|
-
};
|
|
394
|
-
|
|
395
574
|
// src/signer/web.ts
|
|
396
|
-
var import_http2 = require("@turnkey/http");
|
|
397
575
|
var WebSignerClient = class extends SignerClient {
|
|
398
576
|
_stampers;
|
|
577
|
+
oauthConfiguration;
|
|
399
578
|
/**
|
|
400
579
|
* Initializes a new instance of the `WebSignerClient` class.
|
|
401
580
|
*
|
|
@@ -404,7 +583,8 @@ var WebSignerClient = class extends SignerClient {
|
|
|
404
583
|
constructor({
|
|
405
584
|
configuration,
|
|
406
585
|
webauthn,
|
|
407
|
-
iframe
|
|
586
|
+
iframe,
|
|
587
|
+
oauth
|
|
408
588
|
}) {
|
|
409
589
|
const iframeContainerId = iframe?.iframeContainerId ?? "fourt-signer-iframe-container";
|
|
410
590
|
const iframeContainer = document.createElement("div");
|
|
@@ -426,6 +606,7 @@ var WebSignerClient = class extends SignerClient {
|
|
|
426
606
|
webauthn: webauthnStamper,
|
|
427
607
|
iframe: iframeStamper
|
|
428
608
|
};
|
|
609
|
+
this.oauthConfiguration = oauth;
|
|
429
610
|
}
|
|
430
611
|
async signRawMessage(msg) {
|
|
431
612
|
await this.updateStamper();
|
|
@@ -441,7 +622,7 @@ var WebSignerClient = class extends SignerClient {
|
|
|
441
622
|
*
|
|
442
623
|
*/
|
|
443
624
|
async updateStamper() {
|
|
444
|
-
if (this._sessionStore.type === void 0
|
|
625
|
+
if (this._sessionStore.type === void 0 && (this._sessionStore.bundle === void 0 || this._sessionStore.token === void 0))
|
|
445
626
|
return;
|
|
446
627
|
if (this._sessionStore.type === "passkeys" /* Passkeys */) {
|
|
447
628
|
this.stamper = this._stampers.webauthn;
|
|
@@ -449,7 +630,8 @@ var WebSignerClient = class extends SignerClient {
|
|
|
449
630
|
this.stamper = this._stampers.iframe;
|
|
450
631
|
await this.completeAuthWithBundle({
|
|
451
632
|
bundle: this._sessionStore.bundle,
|
|
452
|
-
subOrgId: this.user?.subOrgId
|
|
633
|
+
subOrgId: this.user?.subOrgId,
|
|
634
|
+
sessionType: this._sessionStore.type
|
|
453
635
|
});
|
|
454
636
|
}
|
|
455
637
|
}
|
|
@@ -491,6 +673,9 @@ var WebSignerClient = class extends SignerClient {
|
|
|
491
673
|
await this._signInWithEmail(params);
|
|
492
674
|
}
|
|
493
675
|
}
|
|
676
|
+
async getIframePublicKey() {
|
|
677
|
+
return await this._initIframeStamper();
|
|
678
|
+
}
|
|
494
679
|
/**
|
|
495
680
|
* Signs in a user with email.
|
|
496
681
|
*
|
|
@@ -501,10 +686,9 @@ var WebSignerClient = class extends SignerClient {
|
|
|
501
686
|
expirationSeconds,
|
|
502
687
|
redirectUrl
|
|
503
688
|
}) {
|
|
504
|
-
const publicKey = await this._initIframeStamper();
|
|
505
689
|
return this.request("/v1/email-auth", {
|
|
506
690
|
email,
|
|
507
|
-
targetPublicKey:
|
|
691
|
+
targetPublicKey: await this.getIframePublicKey(),
|
|
508
692
|
expirationSeconds,
|
|
509
693
|
redirectUrl: redirectUrl.toString()
|
|
510
694
|
});
|
|
@@ -512,11 +696,12 @@ var WebSignerClient = class extends SignerClient {
|
|
|
512
696
|
/**
|
|
513
697
|
* Completes the authentication process with a credential bundle.
|
|
514
698
|
*
|
|
515
|
-
* @param {
|
|
699
|
+
* @param {CompleteAuthWithBundleParams} params params for the completion of the auth process
|
|
516
700
|
*/
|
|
517
701
|
async completeAuthWithBundle({
|
|
518
702
|
bundle,
|
|
519
|
-
subOrgId
|
|
703
|
+
subOrgId,
|
|
704
|
+
sessionType
|
|
520
705
|
}) {
|
|
521
706
|
await this._initIframeStamper();
|
|
522
707
|
const result = await this._stampers.iframe.injectCredentialBundle(bundle);
|
|
@@ -524,7 +709,7 @@ var WebSignerClient = class extends SignerClient {
|
|
|
524
709
|
throw new Error("Failed to inject credential bundle");
|
|
525
710
|
}
|
|
526
711
|
await this.whoAmI(subOrgId);
|
|
527
|
-
this._sessionStore.type =
|
|
712
|
+
this._sessionStore.type = sessionType;
|
|
528
713
|
this._sessionStore.bundle = bundle;
|
|
529
714
|
}
|
|
530
715
|
/**
|
|
@@ -555,6 +740,7 @@ var WebSignerClient = class extends SignerClient {
|
|
|
555
740
|
smartAccountAddress,
|
|
556
741
|
credentialId: attestation.credentialId
|
|
557
742
|
};
|
|
743
|
+
this._sessionStore.user = this.user;
|
|
558
744
|
this._sessionStore.type = "passkeys" /* Passkeys */;
|
|
559
745
|
this._sessionStore.token = token;
|
|
560
746
|
}
|
|
@@ -565,11 +751,10 @@ var WebSignerClient = class extends SignerClient {
|
|
|
565
751
|
*/
|
|
566
752
|
async _createEmailAccount(params) {
|
|
567
753
|
const { email, expirationSeconds, redirectUrl } = params;
|
|
568
|
-
const publicKey = await this._initIframeStamper();
|
|
569
754
|
const response = await this.request("/v1/signup", {
|
|
570
755
|
email,
|
|
571
756
|
iframe: {
|
|
572
|
-
targetPublicKey:
|
|
757
|
+
targetPublicKey: await this.getIframePublicKey(),
|
|
573
758
|
expirationSeconds,
|
|
574
759
|
redirectUrl: redirectUrl.toString()
|
|
575
760
|
}
|
|
@@ -710,103 +895,6 @@ var ViemModule = class {
|
|
|
710
895
|
}
|
|
711
896
|
};
|
|
712
897
|
|
|
713
|
-
// src/modules/auth/email.ts
|
|
714
|
-
var EmailModule = class {
|
|
715
|
-
constructor(_webSignerClient) {
|
|
716
|
-
this._webSignerClient = _webSignerClient;
|
|
717
|
-
}
|
|
718
|
-
/**
|
|
719
|
-
* Initialize user authentication process using email.
|
|
720
|
-
*
|
|
721
|
-
* @param params {EmailInitializeAuthParams} params to initialize the user authentication process.
|
|
722
|
-
* @returns {Promise<void>} promise that resolves to the result of the authentication process.
|
|
723
|
-
*/
|
|
724
|
-
async initialize(params) {
|
|
725
|
-
return this._webSignerClient.emailAuth(params);
|
|
726
|
-
}
|
|
727
|
-
/**
|
|
728
|
-
* Completes authentication with bundle after user receives the bundle and subOrgId as URL params.
|
|
729
|
-
*
|
|
730
|
-
* @param params {EmailCompleteAuthWithBundleParams} params received as URL params necessary to complete authentication process.
|
|
731
|
-
* @returns {Promise<void>} promise that completes the authentication process.
|
|
732
|
-
*/
|
|
733
|
-
async complete(params) {
|
|
734
|
-
return this._webSignerClient.completeAuthWithBundle(params);
|
|
735
|
-
}
|
|
736
|
-
};
|
|
737
|
-
|
|
738
|
-
// src/modules/auth/passkeys.ts
|
|
739
|
-
var PasskeysModule = class {
|
|
740
|
-
constructor(_webSignerClient) {
|
|
741
|
-
this._webSignerClient = _webSignerClient;
|
|
742
|
-
}
|
|
743
|
-
/**
|
|
744
|
-
* Signs in a user using Passkeys.
|
|
745
|
-
*
|
|
746
|
-
* @param params {WebauthnSignInParams} params for the sign-in process.
|
|
747
|
-
* @returns {Promise<void>} promise that resolves to the result of the sign-in process.
|
|
748
|
-
*/
|
|
749
|
-
async signIn(params) {
|
|
750
|
-
return this._webSignerClient.webauthnSignIn(params);
|
|
751
|
-
}
|
|
752
|
-
};
|
|
753
|
-
|
|
754
|
-
// src/modules/auth/index.ts
|
|
755
|
-
var AuthModule = class {
|
|
756
|
-
/**
|
|
757
|
-
* Initializes a new instance of the `AuthModule` class.
|
|
758
|
-
*
|
|
759
|
-
* @param {WebSignerClient} _webSignerClient underlying WebSigner client instance.
|
|
760
|
-
*/
|
|
761
|
-
constructor(_webSignerClient) {
|
|
762
|
-
this._webSignerClient = _webSignerClient;
|
|
763
|
-
this._passkeys = new PasskeysModule(this._webSignerClient);
|
|
764
|
-
this._email = new EmailModule(this._webSignerClient);
|
|
765
|
-
}
|
|
766
|
-
_passkeys;
|
|
767
|
-
_email;
|
|
768
|
-
/**
|
|
769
|
-
* A module for interacting with the Passkeys authentication methods.
|
|
770
|
-
*/
|
|
771
|
-
get passkeys() {
|
|
772
|
-
return this._passkeys;
|
|
773
|
-
}
|
|
774
|
-
/**
|
|
775
|
-
* A module for interacting with the Passkeys authentication methods.
|
|
776
|
-
*/
|
|
777
|
-
get email() {
|
|
778
|
-
return this._email;
|
|
779
|
-
}
|
|
780
|
-
};
|
|
781
|
-
|
|
782
|
-
// src/modules/user/index.ts
|
|
783
|
-
var UserModule = class {
|
|
784
|
-
/**
|
|
785
|
-
* Initializes a new instance of the `UserModule` class.
|
|
786
|
-
*
|
|
787
|
-
* @param {WebSignerClient} _webSignerClient underlying WebSigner client instance.
|
|
788
|
-
*/
|
|
789
|
-
constructor(_webSignerClient) {
|
|
790
|
-
this._webSignerClient = _webSignerClient;
|
|
791
|
-
}
|
|
792
|
-
/**
|
|
793
|
-
* Gets the user information.
|
|
794
|
-
*
|
|
795
|
-
* @returns {User | undefined} user information.
|
|
796
|
-
*/
|
|
797
|
-
get info() {
|
|
798
|
-
return this._webSignerClient.user;
|
|
799
|
-
}
|
|
800
|
-
/**
|
|
801
|
-
* Logs out the user.
|
|
802
|
-
*
|
|
803
|
-
* @returns {void}
|
|
804
|
-
*/
|
|
805
|
-
logout() {
|
|
806
|
-
return this._webSignerClient.logout();
|
|
807
|
-
}
|
|
808
|
-
};
|
|
809
|
-
|
|
810
898
|
// src/index.ts
|
|
811
899
|
var FourtWebSigner = class {
|
|
812
900
|
_webSignerClient;
|
|
@@ -834,12 +922,13 @@ var FourtWebSigner = class {
|
|
|
834
922
|
*/
|
|
835
923
|
constructor({
|
|
836
924
|
configuration,
|
|
837
|
-
auth: { webauthn, iframe }
|
|
925
|
+
auth: { webauthn, iframe, oauth }
|
|
838
926
|
}) {
|
|
839
927
|
this._webSignerClient = new WebSignerClient({
|
|
840
928
|
configuration,
|
|
841
929
|
webauthn,
|
|
842
|
-
iframe
|
|
930
|
+
iframe,
|
|
931
|
+
oauth
|
|
843
932
|
});
|
|
844
933
|
this._modules = {
|
|
845
934
|
viem: new ViemModule(this._webSignerClient),
|