@fourt/sdk 1.0.0 → 1.1.1
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 +384 -192
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +123 -60
- package/dist/index.d.ts +123 -60
- package/dist/index.js +374 -192
- package/dist/index.js.map +1 -1
- package/package.json +10 -8
package/dist/index.js
CHANGED
|
@@ -1,57 +1,3 @@
|
|
|
1
|
-
// src/signer/web.ts
|
|
2
|
-
import { WebauthnStamper } from "@turnkey/webauthn-stamper";
|
|
3
|
-
import { IframeStamper } from "@turnkey/iframe-stamper";
|
|
4
|
-
|
|
5
|
-
// src/signer/index.ts
|
|
6
|
-
import { TurnkeyClient } from "@turnkey/http";
|
|
7
|
-
|
|
8
|
-
// src/errors/SDKError.ts
|
|
9
|
-
var SDKError = class extends Error {
|
|
10
|
-
_props;
|
|
11
|
-
constructor(message, props) {
|
|
12
|
-
super(message);
|
|
13
|
-
this._props = props;
|
|
14
|
-
}
|
|
15
|
-
get message() {
|
|
16
|
-
return this._props.message;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
// src/errors/UnauthorizedError.ts
|
|
21
|
-
var UnauthorizedError = class _UnauthorizedError extends SDKError {
|
|
22
|
-
constructor(props) {
|
|
23
|
-
super(_UnauthorizedError.name, props);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// src/errors/NotFoundError.ts
|
|
28
|
-
var NotFoundError = class _NotFoundError extends SDKError {
|
|
29
|
-
constructor(props) {
|
|
30
|
-
super(_NotFoundError.name, props);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// src/errors/GenericError.ts
|
|
35
|
-
var GenericError = class _GenericError extends SDKError {
|
|
36
|
-
constructor(props) {
|
|
37
|
-
super(_GenericError.name, props);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// src/errors/UnauthenticatedError.ts
|
|
42
|
-
var UnauthenticatedError = class _UnauthenticatedError extends SDKError {
|
|
43
|
-
constructor(props) {
|
|
44
|
-
super(_UnauthenticatedError.name, props);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
// src/errors/BadRequestError.ts
|
|
49
|
-
var BadRequestError = class _BadRequestError extends SDKError {
|
|
50
|
-
constructor(props) {
|
|
51
|
-
super(_BadRequestError.name, props);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
1
|
// src/session/index.ts
|
|
56
2
|
import { createStore } from "zustand";
|
|
57
3
|
import { createJSONStorage, persist } from "zustand/middleware";
|
|
@@ -175,6 +121,358 @@ var SessionStore = class {
|
|
|
175
121
|
}
|
|
176
122
|
};
|
|
177
123
|
|
|
124
|
+
// src/modules/auth/email.ts
|
|
125
|
+
var EmailModule = class {
|
|
126
|
+
constructor(_webSignerClient) {
|
|
127
|
+
this._webSignerClient = _webSignerClient;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Initialize user authentication process using email.
|
|
131
|
+
*
|
|
132
|
+
* @param params {EmailInitializeAuthParams} params to initialize the user authentication process.
|
|
133
|
+
* @returns {Promise<void>} promise that resolves to the result of the authentication process.
|
|
134
|
+
*/
|
|
135
|
+
async initialize(params) {
|
|
136
|
+
return this._webSignerClient.emailAuth(params);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Completes authentication with bundle after user receives the bundle and subOrgId as URL params.
|
|
140
|
+
*
|
|
141
|
+
* @param params {CompleteAuthWithBundleParams} params received as URL params necessary to complete authentication process.
|
|
142
|
+
* @returns {Promise<void>} promise that completes the authentication process.
|
|
143
|
+
*/
|
|
144
|
+
async complete(params) {
|
|
145
|
+
return this._webSignerClient.completeAuthWithBundle({
|
|
146
|
+
...params,
|
|
147
|
+
sessionType: "email" /* Email */
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// src/modules/auth/passkeys.ts
|
|
153
|
+
var PasskeysModule = class {
|
|
154
|
+
constructor(_webSignerClient) {
|
|
155
|
+
this._webSignerClient = _webSignerClient;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Signs in a user using Passkeys.
|
|
159
|
+
*
|
|
160
|
+
* @param params {WebauthnSignInParams} params for the sign-in process.
|
|
161
|
+
* @returns {Promise<void>} promise that resolves to the result of the sign-in process.
|
|
162
|
+
*/
|
|
163
|
+
async signIn(params) {
|
|
164
|
+
return this._webSignerClient.webauthnSignIn(params);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// src/modules/auth/oauth/google.ts
|
|
169
|
+
import * as jose from "jose";
|
|
170
|
+
import { sha256 } from "sha.js";
|
|
171
|
+
|
|
172
|
+
// src/errors/SDKError.ts
|
|
173
|
+
var SDKError = class extends Error {
|
|
174
|
+
_props;
|
|
175
|
+
constructor(message, props) {
|
|
176
|
+
super(message);
|
|
177
|
+
this._props = props;
|
|
178
|
+
}
|
|
179
|
+
get message() {
|
|
180
|
+
return this._props.message;
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// src/errors/BadRequestError.ts
|
|
185
|
+
var BadRequestError = class _BadRequestError extends SDKError {
|
|
186
|
+
constructor(props) {
|
|
187
|
+
super(_BadRequestError.name, props);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// src/modules/auth/oauth/google.ts
|
|
192
|
+
var GoogleModule = class {
|
|
193
|
+
constructor(_webSignerClient) {
|
|
194
|
+
this._webSignerClient = _webSignerClient;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
*
|
|
198
|
+
* @returns
|
|
199
|
+
*/
|
|
200
|
+
async init() {
|
|
201
|
+
if (!this._webSignerClient.oauthConfiguration?.google) {
|
|
202
|
+
throw new BadRequestError({ message: "Google OAuth is not configured" });
|
|
203
|
+
}
|
|
204
|
+
const url = new URL("https://accounts.google.com/o/oauth2/v2/auth");
|
|
205
|
+
url.searchParams.set(
|
|
206
|
+
"client_id",
|
|
207
|
+
this._webSignerClient.oauthConfiguration.google.id
|
|
208
|
+
);
|
|
209
|
+
url.searchParams.set("response_type", "code");
|
|
210
|
+
url.searchParams.set("scope", "openid email");
|
|
211
|
+
const internalUrl = new URL(
|
|
212
|
+
"v1/oauth",
|
|
213
|
+
this._webSignerClient.configuration.apiUrl
|
|
214
|
+
).href;
|
|
215
|
+
url.searchParams.set("redirect_uri", internalUrl);
|
|
216
|
+
const publicKey = await this._webSignerClient.getIframePublicKey();
|
|
217
|
+
const nonce = new sha256().update(publicKey).digest("hex");
|
|
218
|
+
url.searchParams.set("nonce", nonce);
|
|
219
|
+
const state = new jose.UnsecuredJWT({
|
|
220
|
+
apiKey: this._webSignerClient.configuration.apiKey,
|
|
221
|
+
redirectUrl: this._webSignerClient.oauthConfiguration.common.redirectUrl,
|
|
222
|
+
targetPublicKey: publicKey,
|
|
223
|
+
internalUrl,
|
|
224
|
+
origin: window.location.origin,
|
|
225
|
+
provider: "google"
|
|
226
|
+
}).encode();
|
|
227
|
+
url.searchParams.set("state", state);
|
|
228
|
+
return url.toString();
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
// src/modules/auth/oauth/facebook.ts
|
|
233
|
+
import * as jose2 from "jose";
|
|
234
|
+
var FacebookModule = class {
|
|
235
|
+
constructor(_webSignerClient) {
|
|
236
|
+
this._webSignerClient = _webSignerClient;
|
|
237
|
+
}
|
|
238
|
+
async init() {
|
|
239
|
+
if (!this._webSignerClient.oauthConfiguration?.facebook) {
|
|
240
|
+
throw new BadRequestError({ message: "Facebook OAuth is not configured" });
|
|
241
|
+
}
|
|
242
|
+
const publicKey = await this._webSignerClient.getIframePublicKey();
|
|
243
|
+
const internalUrl = new URL(
|
|
244
|
+
"v1/oauth",
|
|
245
|
+
this._webSignerClient.configuration.apiUrl
|
|
246
|
+
).href;
|
|
247
|
+
const jwt = new jose2.UnsecuredJWT({
|
|
248
|
+
apiKey: this._webSignerClient.configuration.apiKey,
|
|
249
|
+
redirectUrl: this._webSignerClient.oauthConfiguration.common.redirectUrl,
|
|
250
|
+
targetPublicKey: publicKey,
|
|
251
|
+
internalUrl,
|
|
252
|
+
origin: window.location.origin,
|
|
253
|
+
provider: "facebook"
|
|
254
|
+
}).encode();
|
|
255
|
+
const response = await fetch(internalUrl, {
|
|
256
|
+
method: "POST",
|
|
257
|
+
headers: { "Content-Type": "application/json" },
|
|
258
|
+
body: JSON.stringify({
|
|
259
|
+
state: jwt
|
|
260
|
+
})
|
|
261
|
+
});
|
|
262
|
+
if (!response.ok) {
|
|
263
|
+
throw new BadRequestError({
|
|
264
|
+
message: `Failed to create OAuth state. Error: ${response.statusText}`
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
const { authUrl } = await response.json();
|
|
268
|
+
if (!authUrl) {
|
|
269
|
+
throw new BadRequestError({
|
|
270
|
+
message: response.statusText
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
return authUrl;
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
// src/modules/auth/oauth/apple.ts
|
|
278
|
+
import * as jose3 from "jose";
|
|
279
|
+
import { sha256 as sha2562 } from "sha.js";
|
|
280
|
+
var AppleModule = class {
|
|
281
|
+
constructor(_webSignerClient) {
|
|
282
|
+
this._webSignerClient = _webSignerClient;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
*
|
|
286
|
+
* @returns
|
|
287
|
+
*/
|
|
288
|
+
async init() {
|
|
289
|
+
if (!this._webSignerClient.oauthConfiguration?.apple) {
|
|
290
|
+
throw new BadRequestError({ message: "Apple OAuth is not configured" });
|
|
291
|
+
}
|
|
292
|
+
const url = new URL("https://appleid.apple.com/auth/authorize");
|
|
293
|
+
url.searchParams.set(
|
|
294
|
+
"client_id",
|
|
295
|
+
this._webSignerClient.oauthConfiguration.apple.id
|
|
296
|
+
);
|
|
297
|
+
url.searchParams.set("response_type", "code");
|
|
298
|
+
url.searchParams.set("response_mode", "form_post");
|
|
299
|
+
url.searchParams.set("scope", "email");
|
|
300
|
+
console.log(
|
|
301
|
+
"Apple OAuth initialization started",
|
|
302
|
+
this._webSignerClient.oauthConfiguration.common.redirectUrl
|
|
303
|
+
);
|
|
304
|
+
const internalUrl = new URL(
|
|
305
|
+
"v1/oauth/apple",
|
|
306
|
+
this._webSignerClient.configuration.apiUrl
|
|
307
|
+
).href;
|
|
308
|
+
url.searchParams.set("redirect_uri", internalUrl);
|
|
309
|
+
const publicKey = await this._webSignerClient.getIframePublicKey();
|
|
310
|
+
const nonce = new sha2562().update(publicKey).digest("hex");
|
|
311
|
+
url.searchParams.set("nonce", nonce);
|
|
312
|
+
const state = new jose3.UnsecuredJWT({
|
|
313
|
+
apiKey: this._webSignerClient.configuration.apiKey,
|
|
314
|
+
redirectUrl: this._webSignerClient.oauthConfiguration.common.redirectUrl,
|
|
315
|
+
targetPublicKey: publicKey,
|
|
316
|
+
internalUrl,
|
|
317
|
+
origin: window.location.origin
|
|
318
|
+
}).encode();
|
|
319
|
+
url.searchParams.set("state", state);
|
|
320
|
+
return url.toString();
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
// src/modules/auth/oauth.ts
|
|
325
|
+
var OAuthModule = class {
|
|
326
|
+
constructor(_webSignerClient) {
|
|
327
|
+
this._webSignerClient = _webSignerClient;
|
|
328
|
+
this._googleModule = new GoogleModule(this._webSignerClient);
|
|
329
|
+
this._facebookModule = new FacebookModule(this._webSignerClient);
|
|
330
|
+
this._appleModule = new AppleModule(this._webSignerClient);
|
|
331
|
+
}
|
|
332
|
+
_googleModule;
|
|
333
|
+
_facebookModule;
|
|
334
|
+
_appleModule;
|
|
335
|
+
get google() {
|
|
336
|
+
return this._googleModule;
|
|
337
|
+
}
|
|
338
|
+
get facebook() {
|
|
339
|
+
return this._facebookModule;
|
|
340
|
+
}
|
|
341
|
+
get apple() {
|
|
342
|
+
return this._appleModule;
|
|
343
|
+
}
|
|
344
|
+
async complete({ bundle, subOrgId }) {
|
|
345
|
+
await this._webSignerClient.completeAuthWithBundle({
|
|
346
|
+
bundle,
|
|
347
|
+
subOrgId,
|
|
348
|
+
sessionType: "oauth" /* OAuth */
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
// src/modules/auth/index.ts
|
|
354
|
+
var AuthModule = class {
|
|
355
|
+
/**
|
|
356
|
+
* Initializes a new instance of the `AuthModule` class.
|
|
357
|
+
*
|
|
358
|
+
* @param {WebSignerClient} _webSignerClient underlying WebSigner client instance.
|
|
359
|
+
*/
|
|
360
|
+
constructor(_webSignerClient) {
|
|
361
|
+
this._webSignerClient = _webSignerClient;
|
|
362
|
+
this._passkeys = new PasskeysModule(this._webSignerClient);
|
|
363
|
+
this._email = new EmailModule(this._webSignerClient);
|
|
364
|
+
this._oauth = new OAuthModule(this._webSignerClient);
|
|
365
|
+
}
|
|
366
|
+
_passkeys;
|
|
367
|
+
_email;
|
|
368
|
+
_oauth;
|
|
369
|
+
/**
|
|
370
|
+
* A module for interacting with the Passkeys authentication methods.
|
|
371
|
+
*/
|
|
372
|
+
get passkeys() {
|
|
373
|
+
return this._passkeys;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* A module for interacting with the Passkeys authentication methods.
|
|
377
|
+
*/
|
|
378
|
+
get email() {
|
|
379
|
+
return this._email;
|
|
380
|
+
}
|
|
381
|
+
get oauth() {
|
|
382
|
+
return this._oauth;
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
// src/modules/user/index.ts
|
|
387
|
+
var UserModule = class {
|
|
388
|
+
/**
|
|
389
|
+
* Initializes a new instance of the `UserModule` class.
|
|
390
|
+
*
|
|
391
|
+
* @param {WebSignerClient} _webSignerClient underlying WebSigner client instance.
|
|
392
|
+
*/
|
|
393
|
+
constructor(_webSignerClient) {
|
|
394
|
+
this._webSignerClient = _webSignerClient;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Gets the user information.
|
|
398
|
+
*
|
|
399
|
+
* @returns {User | undefined} user information.
|
|
400
|
+
*/
|
|
401
|
+
get info() {
|
|
402
|
+
return this._webSignerClient.user;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Logs out the user.
|
|
406
|
+
*
|
|
407
|
+
* @returns {void}
|
|
408
|
+
*/
|
|
409
|
+
logout() {
|
|
410
|
+
return this._webSignerClient.logout();
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
// src/signer/web.ts
|
|
415
|
+
import { getWebAuthnAttestation } from "@turnkey/http";
|
|
416
|
+
import { IframeStamper } from "@turnkey/iframe-stamper";
|
|
417
|
+
import { WebauthnStamper } from "@turnkey/webauthn-stamper";
|
|
418
|
+
|
|
419
|
+
// src/lib/base64.ts
|
|
420
|
+
import { Buffer } from "buffer";
|
|
421
|
+
var LibBase64 = class {
|
|
422
|
+
static fromBuffer(buffer) {
|
|
423
|
+
return Buffer.from(buffer).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
424
|
+
}
|
|
425
|
+
static toBuffer(base64) {
|
|
426
|
+
return Buffer.from(base64, "base64");
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
// src/lib/bytes.ts
|
|
431
|
+
var LibBytes = class {
|
|
432
|
+
static generateRandomBuffer = () => {
|
|
433
|
+
const arr = new Uint8Array(32);
|
|
434
|
+
crypto.getRandomValues(arr);
|
|
435
|
+
return arr.buffer;
|
|
436
|
+
};
|
|
437
|
+
static takeBytes = (bytes, params = {}) => {
|
|
438
|
+
const { offset, count } = params;
|
|
439
|
+
const start = (offset ? offset * 2 : 0) + 2;
|
|
440
|
+
const end = count ? start + count * 2 : void 0;
|
|
441
|
+
return `0x${bytes.slice(start, end)}`;
|
|
442
|
+
};
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
// src/signer/index.ts
|
|
446
|
+
import { TurnkeyClient } from "@turnkey/http";
|
|
447
|
+
|
|
448
|
+
// src/errors/UnauthorizedError.ts
|
|
449
|
+
var UnauthorizedError = class _UnauthorizedError extends SDKError {
|
|
450
|
+
constructor(props) {
|
|
451
|
+
super(_UnauthorizedError.name, props);
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
// src/errors/NotFoundError.ts
|
|
456
|
+
var NotFoundError = class _NotFoundError extends SDKError {
|
|
457
|
+
constructor(props) {
|
|
458
|
+
super(_NotFoundError.name, props);
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
// src/errors/GenericError.ts
|
|
463
|
+
var GenericError = class _GenericError extends SDKError {
|
|
464
|
+
constructor(props) {
|
|
465
|
+
super(_GenericError.name, props);
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
// src/errors/UnauthenticatedError.ts
|
|
470
|
+
var UnauthenticatedError = class _UnauthenticatedError extends SDKError {
|
|
471
|
+
constructor(props) {
|
|
472
|
+
super(_UnauthenticatedError.name, props);
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
|
|
178
476
|
// src/types/Routes.ts
|
|
179
477
|
var ROUTE_METHOD_MAP = {
|
|
180
478
|
"/v1/signup": "POST",
|
|
@@ -202,8 +500,8 @@ var SignerClient = class {
|
|
|
202
500
|
);
|
|
203
501
|
this._configuration = {
|
|
204
502
|
...requiredConfiguration,
|
|
205
|
-
apiUrl: apiUrl ?? "https://auth.api.
|
|
206
|
-
paymasterRpcUrl: paymasterRpcUrl ?? "https://management.api.
|
|
503
|
+
apiUrl: apiUrl ?? "https://auth.api.fourt.io/",
|
|
504
|
+
paymasterRpcUrl: paymasterRpcUrl ?? "https://management.api.fourt.io/"
|
|
207
505
|
};
|
|
208
506
|
this._sessionStore = new SessionStore();
|
|
209
507
|
}
|
|
@@ -340,36 +638,10 @@ var SignerClient = class {
|
|
|
340
638
|
}
|
|
341
639
|
};
|
|
342
640
|
|
|
343
|
-
// src/lib/base64.ts
|
|
344
|
-
import { Buffer } from "buffer";
|
|
345
|
-
var LibBase64 = class {
|
|
346
|
-
static fromBuffer(buffer) {
|
|
347
|
-
return Buffer.from(buffer).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
348
|
-
}
|
|
349
|
-
static toBuffer(base64) {
|
|
350
|
-
return Buffer.from(base64, "base64");
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
// src/lib/bytes.ts
|
|
355
|
-
var LibBytes = class {
|
|
356
|
-
static generateRandomBuffer = () => {
|
|
357
|
-
const arr = new Uint8Array(32);
|
|
358
|
-
crypto.getRandomValues(arr);
|
|
359
|
-
return arr.buffer;
|
|
360
|
-
};
|
|
361
|
-
static takeBytes = (bytes, params = {}) => {
|
|
362
|
-
const { offset, count } = params;
|
|
363
|
-
const start = (offset ? offset * 2 : 0) + 2;
|
|
364
|
-
const end = count ? start + count * 2 : void 0;
|
|
365
|
-
return `0x${bytes.slice(start, end)}`;
|
|
366
|
-
};
|
|
367
|
-
};
|
|
368
|
-
|
|
369
641
|
// src/signer/web.ts
|
|
370
|
-
import { getWebAuthnAttestation } from "@turnkey/http";
|
|
371
642
|
var WebSignerClient = class extends SignerClient {
|
|
372
643
|
_stampers;
|
|
644
|
+
oauthConfiguration;
|
|
373
645
|
/**
|
|
374
646
|
* Initializes a new instance of the `WebSignerClient` class.
|
|
375
647
|
*
|
|
@@ -378,7 +650,8 @@ var WebSignerClient = class extends SignerClient {
|
|
|
378
650
|
constructor({
|
|
379
651
|
configuration,
|
|
380
652
|
webauthn,
|
|
381
|
-
iframe
|
|
653
|
+
iframe,
|
|
654
|
+
oauth
|
|
382
655
|
}) {
|
|
383
656
|
const iframeContainerId = iframe?.iframeContainerId ?? "fourt-signer-iframe-container";
|
|
384
657
|
const iframeContainer = document.createElement("div");
|
|
@@ -400,6 +673,7 @@ var WebSignerClient = class extends SignerClient {
|
|
|
400
673
|
webauthn: webauthnStamper,
|
|
401
674
|
iframe: iframeStamper
|
|
402
675
|
};
|
|
676
|
+
this.oauthConfiguration = oauth;
|
|
403
677
|
}
|
|
404
678
|
async signRawMessage(msg) {
|
|
405
679
|
await this.updateStamper();
|
|
@@ -415,7 +689,7 @@ var WebSignerClient = class extends SignerClient {
|
|
|
415
689
|
*
|
|
416
690
|
*/
|
|
417
691
|
async updateStamper() {
|
|
418
|
-
if (this._sessionStore.type === void 0
|
|
692
|
+
if (this._sessionStore.type === void 0 && (this._sessionStore.bundle === void 0 || this._sessionStore.token === void 0))
|
|
419
693
|
return;
|
|
420
694
|
if (this._sessionStore.type === "passkeys" /* Passkeys */) {
|
|
421
695
|
this.stamper = this._stampers.webauthn;
|
|
@@ -423,7 +697,8 @@ var WebSignerClient = class extends SignerClient {
|
|
|
423
697
|
this.stamper = this._stampers.iframe;
|
|
424
698
|
await this.completeAuthWithBundle({
|
|
425
699
|
bundle: this._sessionStore.bundle,
|
|
426
|
-
subOrgId: this.user?.subOrgId
|
|
700
|
+
subOrgId: this.user?.subOrgId,
|
|
701
|
+
sessionType: this._sessionStore.type
|
|
427
702
|
});
|
|
428
703
|
}
|
|
429
704
|
}
|
|
@@ -465,6 +740,9 @@ var WebSignerClient = class extends SignerClient {
|
|
|
465
740
|
await this._signInWithEmail(params);
|
|
466
741
|
}
|
|
467
742
|
}
|
|
743
|
+
async getIframePublicKey() {
|
|
744
|
+
return await this._initIframeStamper();
|
|
745
|
+
}
|
|
468
746
|
/**
|
|
469
747
|
* Signs in a user with email.
|
|
470
748
|
*
|
|
@@ -475,10 +753,9 @@ var WebSignerClient = class extends SignerClient {
|
|
|
475
753
|
expirationSeconds,
|
|
476
754
|
redirectUrl
|
|
477
755
|
}) {
|
|
478
|
-
const publicKey = await this._initIframeStamper();
|
|
479
756
|
return this.request("/v1/email-auth", {
|
|
480
757
|
email,
|
|
481
|
-
targetPublicKey:
|
|
758
|
+
targetPublicKey: await this.getIframePublicKey(),
|
|
482
759
|
expirationSeconds,
|
|
483
760
|
redirectUrl: redirectUrl.toString()
|
|
484
761
|
});
|
|
@@ -486,11 +763,12 @@ var WebSignerClient = class extends SignerClient {
|
|
|
486
763
|
/**
|
|
487
764
|
* Completes the authentication process with a credential bundle.
|
|
488
765
|
*
|
|
489
|
-
* @param {
|
|
766
|
+
* @param {CompleteAuthWithBundleParams} params params for the completion of the auth process
|
|
490
767
|
*/
|
|
491
768
|
async completeAuthWithBundle({
|
|
492
769
|
bundle,
|
|
493
|
-
subOrgId
|
|
770
|
+
subOrgId,
|
|
771
|
+
sessionType
|
|
494
772
|
}) {
|
|
495
773
|
await this._initIframeStamper();
|
|
496
774
|
const result = await this._stampers.iframe.injectCredentialBundle(bundle);
|
|
@@ -498,7 +776,7 @@ var WebSignerClient = class extends SignerClient {
|
|
|
498
776
|
throw new Error("Failed to inject credential bundle");
|
|
499
777
|
}
|
|
500
778
|
await this.whoAmI(subOrgId);
|
|
501
|
-
this._sessionStore.type =
|
|
779
|
+
this._sessionStore.type = sessionType;
|
|
502
780
|
this._sessionStore.bundle = bundle;
|
|
503
781
|
}
|
|
504
782
|
/**
|
|
@@ -529,6 +807,7 @@ var WebSignerClient = class extends SignerClient {
|
|
|
529
807
|
smartAccountAddress,
|
|
530
808
|
credentialId: attestation.credentialId
|
|
531
809
|
};
|
|
810
|
+
this._sessionStore.user = this.user;
|
|
532
811
|
this._sessionStore.type = "passkeys" /* Passkeys */;
|
|
533
812
|
this._sessionStore.token = token;
|
|
534
813
|
}
|
|
@@ -539,11 +818,10 @@ var WebSignerClient = class extends SignerClient {
|
|
|
539
818
|
*/
|
|
540
819
|
async _createEmailAccount(params) {
|
|
541
820
|
const { email, expirationSeconds, redirectUrl } = params;
|
|
542
|
-
const publicKey = await this._initIframeStamper();
|
|
543
821
|
const response = await this.request("/v1/signup", {
|
|
544
822
|
email,
|
|
545
823
|
iframe: {
|
|
546
|
-
targetPublicKey:
|
|
824
|
+
targetPublicKey: await this.getIframePublicKey(),
|
|
547
825
|
expirationSeconds,
|
|
548
826
|
redirectUrl: redirectUrl.toString()
|
|
549
827
|
}
|
|
@@ -694,103 +972,6 @@ var ViemModule = class {
|
|
|
694
972
|
}
|
|
695
973
|
};
|
|
696
974
|
|
|
697
|
-
// src/modules/auth/email.ts
|
|
698
|
-
var EmailModule = class {
|
|
699
|
-
constructor(_webSignerClient) {
|
|
700
|
-
this._webSignerClient = _webSignerClient;
|
|
701
|
-
}
|
|
702
|
-
/**
|
|
703
|
-
* Initialize user authentication process using email.
|
|
704
|
-
*
|
|
705
|
-
* @param params {EmailInitializeAuthParams} params to initialize the user authentication process.
|
|
706
|
-
* @returns {Promise<void>} promise that resolves to the result of the authentication process.
|
|
707
|
-
*/
|
|
708
|
-
async initialize(params) {
|
|
709
|
-
return this._webSignerClient.emailAuth(params);
|
|
710
|
-
}
|
|
711
|
-
/**
|
|
712
|
-
* Completes authentication with bundle after user receives the bundle and subOrgId as URL params.
|
|
713
|
-
*
|
|
714
|
-
* @param params {EmailCompleteAuthWithBundleParams} params received as URL params necessary to complete authentication process.
|
|
715
|
-
* @returns {Promise<void>} promise that completes the authentication process.
|
|
716
|
-
*/
|
|
717
|
-
async complete(params) {
|
|
718
|
-
return this._webSignerClient.completeAuthWithBundle(params);
|
|
719
|
-
}
|
|
720
|
-
};
|
|
721
|
-
|
|
722
|
-
// src/modules/auth/passkeys.ts
|
|
723
|
-
var PasskeysModule = class {
|
|
724
|
-
constructor(_webSignerClient) {
|
|
725
|
-
this._webSignerClient = _webSignerClient;
|
|
726
|
-
}
|
|
727
|
-
/**
|
|
728
|
-
* Signs in a user using Passkeys.
|
|
729
|
-
*
|
|
730
|
-
* @param params {WebauthnSignInParams} params for the sign-in process.
|
|
731
|
-
* @returns {Promise<void>} promise that resolves to the result of the sign-in process.
|
|
732
|
-
*/
|
|
733
|
-
async signIn(params) {
|
|
734
|
-
return this._webSignerClient.webauthnSignIn(params);
|
|
735
|
-
}
|
|
736
|
-
};
|
|
737
|
-
|
|
738
|
-
// src/modules/auth/index.ts
|
|
739
|
-
var AuthModule = class {
|
|
740
|
-
/**
|
|
741
|
-
* Initializes a new instance of the `AuthModule` class.
|
|
742
|
-
*
|
|
743
|
-
* @param {WebSignerClient} _webSignerClient underlying WebSigner client instance.
|
|
744
|
-
*/
|
|
745
|
-
constructor(_webSignerClient) {
|
|
746
|
-
this._webSignerClient = _webSignerClient;
|
|
747
|
-
this._passkeys = new PasskeysModule(this._webSignerClient);
|
|
748
|
-
this._email = new EmailModule(this._webSignerClient);
|
|
749
|
-
}
|
|
750
|
-
_passkeys;
|
|
751
|
-
_email;
|
|
752
|
-
/**
|
|
753
|
-
* A module for interacting with the Passkeys authentication methods.
|
|
754
|
-
*/
|
|
755
|
-
get passkeys() {
|
|
756
|
-
return this._passkeys;
|
|
757
|
-
}
|
|
758
|
-
/**
|
|
759
|
-
* A module for interacting with the Passkeys authentication methods.
|
|
760
|
-
*/
|
|
761
|
-
get email() {
|
|
762
|
-
return this._email;
|
|
763
|
-
}
|
|
764
|
-
};
|
|
765
|
-
|
|
766
|
-
// src/modules/user/index.ts
|
|
767
|
-
var UserModule = class {
|
|
768
|
-
/**
|
|
769
|
-
* Initializes a new instance of the `UserModule` class.
|
|
770
|
-
*
|
|
771
|
-
* @param {WebSignerClient} _webSignerClient underlying WebSigner client instance.
|
|
772
|
-
*/
|
|
773
|
-
constructor(_webSignerClient) {
|
|
774
|
-
this._webSignerClient = _webSignerClient;
|
|
775
|
-
}
|
|
776
|
-
/**
|
|
777
|
-
* Gets the user information.
|
|
778
|
-
*
|
|
779
|
-
* @returns {User | undefined} user information.
|
|
780
|
-
*/
|
|
781
|
-
get info() {
|
|
782
|
-
return this._webSignerClient.user;
|
|
783
|
-
}
|
|
784
|
-
/**
|
|
785
|
-
* Logs out the user.
|
|
786
|
-
*
|
|
787
|
-
* @returns {void}
|
|
788
|
-
*/
|
|
789
|
-
logout() {
|
|
790
|
-
return this._webSignerClient.logout();
|
|
791
|
-
}
|
|
792
|
-
};
|
|
793
|
-
|
|
794
975
|
// src/index.ts
|
|
795
976
|
var FourtWebSigner = class {
|
|
796
977
|
_webSignerClient;
|
|
@@ -818,12 +999,13 @@ var FourtWebSigner = class {
|
|
|
818
999
|
*/
|
|
819
1000
|
constructor({
|
|
820
1001
|
configuration,
|
|
821
|
-
auth: { webauthn, iframe }
|
|
1002
|
+
auth: { webauthn, iframe, oauth }
|
|
822
1003
|
}) {
|
|
823
1004
|
this._webSignerClient = new WebSignerClient({
|
|
824
1005
|
configuration,
|
|
825
1006
|
webauthn,
|
|
826
|
-
iframe
|
|
1007
|
+
iframe,
|
|
1008
|
+
oauth
|
|
827
1009
|
});
|
|
828
1010
|
this._modules = {
|
|
829
1011
|
viem: new ViemModule(this._webSignerClient),
|