@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.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,358 @@ 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.id
|
|
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
|
+
provider: "google"
|
|
262
|
+
}).encode();
|
|
263
|
+
url.searchParams.set("state", state);
|
|
264
|
+
return url.toString();
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
// src/modules/auth/oauth/facebook.ts
|
|
269
|
+
var jose2 = __toESM(require("jose"), 1);
|
|
270
|
+
var FacebookModule = class {
|
|
271
|
+
constructor(_webSignerClient) {
|
|
272
|
+
this._webSignerClient = _webSignerClient;
|
|
273
|
+
}
|
|
274
|
+
async init() {
|
|
275
|
+
if (!this._webSignerClient.oauthConfiguration?.facebook) {
|
|
276
|
+
throw new BadRequestError({ message: "Facebook OAuth is not configured" });
|
|
277
|
+
}
|
|
278
|
+
const publicKey = await this._webSignerClient.getIframePublicKey();
|
|
279
|
+
const internalUrl = new URL(
|
|
280
|
+
"v1/oauth",
|
|
281
|
+
this._webSignerClient.configuration.apiUrl
|
|
282
|
+
).href;
|
|
283
|
+
const jwt = new jose2.UnsecuredJWT({
|
|
284
|
+
apiKey: this._webSignerClient.configuration.apiKey,
|
|
285
|
+
redirectUrl: this._webSignerClient.oauthConfiguration.common.redirectUrl,
|
|
286
|
+
targetPublicKey: publicKey,
|
|
287
|
+
internalUrl,
|
|
288
|
+
origin: window.location.origin,
|
|
289
|
+
provider: "facebook"
|
|
290
|
+
}).encode();
|
|
291
|
+
const response = await fetch(internalUrl, {
|
|
292
|
+
method: "POST",
|
|
293
|
+
headers: { "Content-Type": "application/json" },
|
|
294
|
+
body: JSON.stringify({
|
|
295
|
+
state: jwt
|
|
296
|
+
})
|
|
297
|
+
});
|
|
298
|
+
if (!response.ok) {
|
|
299
|
+
throw new BadRequestError({
|
|
300
|
+
message: `Failed to create OAuth state. Error: ${response.statusText}`
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
const { authUrl } = await response.json();
|
|
304
|
+
if (!authUrl) {
|
|
305
|
+
throw new BadRequestError({
|
|
306
|
+
message: response.statusText
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
return authUrl;
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
// src/modules/auth/oauth/apple.ts
|
|
314
|
+
var jose3 = __toESM(require("jose"), 1);
|
|
315
|
+
var import_sha2 = require("sha.js");
|
|
316
|
+
var AppleModule = class {
|
|
317
|
+
constructor(_webSignerClient) {
|
|
318
|
+
this._webSignerClient = _webSignerClient;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
*
|
|
322
|
+
* @returns
|
|
323
|
+
*/
|
|
324
|
+
async init() {
|
|
325
|
+
if (!this._webSignerClient.oauthConfiguration?.apple) {
|
|
326
|
+
throw new BadRequestError({ message: "Apple OAuth is not configured" });
|
|
327
|
+
}
|
|
328
|
+
const url = new URL("https://appleid.apple.com/auth/authorize");
|
|
329
|
+
url.searchParams.set(
|
|
330
|
+
"client_id",
|
|
331
|
+
this._webSignerClient.oauthConfiguration.apple.id
|
|
332
|
+
);
|
|
333
|
+
url.searchParams.set("response_type", "code");
|
|
334
|
+
url.searchParams.set("response_mode", "form_post");
|
|
335
|
+
url.searchParams.set("scope", "email");
|
|
336
|
+
console.log(
|
|
337
|
+
"Apple OAuth initialization started",
|
|
338
|
+
this._webSignerClient.oauthConfiguration.common.redirectUrl
|
|
339
|
+
);
|
|
340
|
+
const internalUrl = new URL(
|
|
341
|
+
"v1/oauth/apple",
|
|
342
|
+
this._webSignerClient.configuration.apiUrl
|
|
343
|
+
).href;
|
|
344
|
+
url.searchParams.set("redirect_uri", internalUrl);
|
|
345
|
+
const publicKey = await this._webSignerClient.getIframePublicKey();
|
|
346
|
+
const nonce = new import_sha2.sha256().update(publicKey).digest("hex");
|
|
347
|
+
url.searchParams.set("nonce", nonce);
|
|
348
|
+
const state = new jose3.UnsecuredJWT({
|
|
349
|
+
apiKey: this._webSignerClient.configuration.apiKey,
|
|
350
|
+
redirectUrl: this._webSignerClient.oauthConfiguration.common.redirectUrl,
|
|
351
|
+
targetPublicKey: publicKey,
|
|
352
|
+
internalUrl,
|
|
353
|
+
origin: window.location.origin
|
|
354
|
+
}).encode();
|
|
355
|
+
url.searchParams.set("state", state);
|
|
356
|
+
return url.toString();
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
// src/modules/auth/oauth.ts
|
|
361
|
+
var OAuthModule = class {
|
|
362
|
+
constructor(_webSignerClient) {
|
|
363
|
+
this._webSignerClient = _webSignerClient;
|
|
364
|
+
this._googleModule = new GoogleModule(this._webSignerClient);
|
|
365
|
+
this._facebookModule = new FacebookModule(this._webSignerClient);
|
|
366
|
+
this._appleModule = new AppleModule(this._webSignerClient);
|
|
367
|
+
}
|
|
368
|
+
_googleModule;
|
|
369
|
+
_facebookModule;
|
|
370
|
+
_appleModule;
|
|
371
|
+
get google() {
|
|
372
|
+
return this._googleModule;
|
|
373
|
+
}
|
|
374
|
+
get facebook() {
|
|
375
|
+
return this._facebookModule;
|
|
376
|
+
}
|
|
377
|
+
get apple() {
|
|
378
|
+
return this._appleModule;
|
|
379
|
+
}
|
|
380
|
+
async complete({ bundle, subOrgId }) {
|
|
381
|
+
await this._webSignerClient.completeAuthWithBundle({
|
|
382
|
+
bundle,
|
|
383
|
+
subOrgId,
|
|
384
|
+
sessionType: "oauth" /* OAuth */
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
// src/modules/auth/index.ts
|
|
390
|
+
var AuthModule = class {
|
|
391
|
+
/**
|
|
392
|
+
* Initializes a new instance of the `AuthModule` class.
|
|
393
|
+
*
|
|
394
|
+
* @param {WebSignerClient} _webSignerClient underlying WebSigner client instance.
|
|
395
|
+
*/
|
|
396
|
+
constructor(_webSignerClient) {
|
|
397
|
+
this._webSignerClient = _webSignerClient;
|
|
398
|
+
this._passkeys = new PasskeysModule(this._webSignerClient);
|
|
399
|
+
this._email = new EmailModule(this._webSignerClient);
|
|
400
|
+
this._oauth = new OAuthModule(this._webSignerClient);
|
|
401
|
+
}
|
|
402
|
+
_passkeys;
|
|
403
|
+
_email;
|
|
404
|
+
_oauth;
|
|
405
|
+
/**
|
|
406
|
+
* A module for interacting with the Passkeys authentication methods.
|
|
407
|
+
*/
|
|
408
|
+
get passkeys() {
|
|
409
|
+
return this._passkeys;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* A module for interacting with the Passkeys authentication methods.
|
|
413
|
+
*/
|
|
414
|
+
get email() {
|
|
415
|
+
return this._email;
|
|
416
|
+
}
|
|
417
|
+
get oauth() {
|
|
418
|
+
return this._oauth;
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
// src/modules/user/index.ts
|
|
423
|
+
var UserModule = class {
|
|
424
|
+
/**
|
|
425
|
+
* Initializes a new instance of the `UserModule` class.
|
|
426
|
+
*
|
|
427
|
+
* @param {WebSignerClient} _webSignerClient underlying WebSigner client instance.
|
|
428
|
+
*/
|
|
429
|
+
constructor(_webSignerClient) {
|
|
430
|
+
this._webSignerClient = _webSignerClient;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Gets the user information.
|
|
434
|
+
*
|
|
435
|
+
* @returns {User | undefined} user information.
|
|
436
|
+
*/
|
|
437
|
+
get info() {
|
|
438
|
+
return this._webSignerClient.user;
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Logs out the user.
|
|
442
|
+
*
|
|
443
|
+
* @returns {void}
|
|
444
|
+
*/
|
|
445
|
+
logout() {
|
|
446
|
+
return this._webSignerClient.logout();
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
// src/signer/web.ts
|
|
451
|
+
var import_http2 = require("@turnkey/http");
|
|
452
|
+
var import_iframe_stamper = require("@turnkey/iframe-stamper");
|
|
453
|
+
var import_webauthn_stamper = require("@turnkey/webauthn-stamper");
|
|
454
|
+
|
|
455
|
+
// src/lib/base64.ts
|
|
456
|
+
var import_buffer = require("buffer");
|
|
457
|
+
var LibBase64 = class {
|
|
458
|
+
static fromBuffer(buffer) {
|
|
459
|
+
return import_buffer.Buffer.from(buffer).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
460
|
+
}
|
|
461
|
+
static toBuffer(base64) {
|
|
462
|
+
return import_buffer.Buffer.from(base64, "base64");
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
// src/lib/bytes.ts
|
|
467
|
+
var LibBytes = class {
|
|
468
|
+
static generateRandomBuffer = () => {
|
|
469
|
+
const arr = new Uint8Array(32);
|
|
470
|
+
crypto.getRandomValues(arr);
|
|
471
|
+
return arr.buffer;
|
|
472
|
+
};
|
|
473
|
+
static takeBytes = (bytes, params = {}) => {
|
|
474
|
+
const { offset, count } = params;
|
|
475
|
+
const start = (offset ? offset * 2 : 0) + 2;
|
|
476
|
+
const end = count ? start + count * 2 : void 0;
|
|
477
|
+
return `0x${bytes.slice(start, end)}`;
|
|
478
|
+
};
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
// src/signer/index.ts
|
|
482
|
+
var import_http = require("@turnkey/http");
|
|
483
|
+
|
|
484
|
+
// src/errors/UnauthorizedError.ts
|
|
485
|
+
var UnauthorizedError = class _UnauthorizedError extends SDKError {
|
|
486
|
+
constructor(props) {
|
|
487
|
+
super(_UnauthorizedError.name, props);
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
// src/errors/NotFoundError.ts
|
|
492
|
+
var NotFoundError = class _NotFoundError extends SDKError {
|
|
493
|
+
constructor(props) {
|
|
494
|
+
super(_NotFoundError.name, props);
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
// src/errors/GenericError.ts
|
|
499
|
+
var GenericError = class _GenericError extends SDKError {
|
|
500
|
+
constructor(props) {
|
|
501
|
+
super(_GenericError.name, props);
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
// src/errors/UnauthenticatedError.ts
|
|
506
|
+
var UnauthenticatedError = class _UnauthenticatedError extends SDKError {
|
|
507
|
+
constructor(props) {
|
|
508
|
+
super(_UnauthenticatedError.name, props);
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
|
|
204
512
|
// src/types/Routes.ts
|
|
205
513
|
var ROUTE_METHOD_MAP = {
|
|
206
514
|
"/v1/signup": "POST",
|
|
@@ -228,8 +536,8 @@ var SignerClient = class {
|
|
|
228
536
|
);
|
|
229
537
|
this._configuration = {
|
|
230
538
|
...requiredConfiguration,
|
|
231
|
-
apiUrl: apiUrl ?? "https://auth.api.
|
|
232
|
-
paymasterRpcUrl: paymasterRpcUrl ?? "https://management.api.
|
|
539
|
+
apiUrl: apiUrl ?? "https://auth.api.fourt.io/",
|
|
540
|
+
paymasterRpcUrl: paymasterRpcUrl ?? "https://management.api.fourt.io/"
|
|
233
541
|
};
|
|
234
542
|
this._sessionStore = new SessionStore();
|
|
235
543
|
}
|
|
@@ -366,36 +674,10 @@ var SignerClient = class {
|
|
|
366
674
|
}
|
|
367
675
|
};
|
|
368
676
|
|
|
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
677
|
// src/signer/web.ts
|
|
396
|
-
var import_http2 = require("@turnkey/http");
|
|
397
678
|
var WebSignerClient = class extends SignerClient {
|
|
398
679
|
_stampers;
|
|
680
|
+
oauthConfiguration;
|
|
399
681
|
/**
|
|
400
682
|
* Initializes a new instance of the `WebSignerClient` class.
|
|
401
683
|
*
|
|
@@ -404,7 +686,8 @@ var WebSignerClient = class extends SignerClient {
|
|
|
404
686
|
constructor({
|
|
405
687
|
configuration,
|
|
406
688
|
webauthn,
|
|
407
|
-
iframe
|
|
689
|
+
iframe,
|
|
690
|
+
oauth
|
|
408
691
|
}) {
|
|
409
692
|
const iframeContainerId = iframe?.iframeContainerId ?? "fourt-signer-iframe-container";
|
|
410
693
|
const iframeContainer = document.createElement("div");
|
|
@@ -426,6 +709,7 @@ var WebSignerClient = class extends SignerClient {
|
|
|
426
709
|
webauthn: webauthnStamper,
|
|
427
710
|
iframe: iframeStamper
|
|
428
711
|
};
|
|
712
|
+
this.oauthConfiguration = oauth;
|
|
429
713
|
}
|
|
430
714
|
async signRawMessage(msg) {
|
|
431
715
|
await this.updateStamper();
|
|
@@ -441,7 +725,7 @@ var WebSignerClient = class extends SignerClient {
|
|
|
441
725
|
*
|
|
442
726
|
*/
|
|
443
727
|
async updateStamper() {
|
|
444
|
-
if (this._sessionStore.type === void 0
|
|
728
|
+
if (this._sessionStore.type === void 0 && (this._sessionStore.bundle === void 0 || this._sessionStore.token === void 0))
|
|
445
729
|
return;
|
|
446
730
|
if (this._sessionStore.type === "passkeys" /* Passkeys */) {
|
|
447
731
|
this.stamper = this._stampers.webauthn;
|
|
@@ -449,7 +733,8 @@ var WebSignerClient = class extends SignerClient {
|
|
|
449
733
|
this.stamper = this._stampers.iframe;
|
|
450
734
|
await this.completeAuthWithBundle({
|
|
451
735
|
bundle: this._sessionStore.bundle,
|
|
452
|
-
subOrgId: this.user?.subOrgId
|
|
736
|
+
subOrgId: this.user?.subOrgId,
|
|
737
|
+
sessionType: this._sessionStore.type
|
|
453
738
|
});
|
|
454
739
|
}
|
|
455
740
|
}
|
|
@@ -491,6 +776,9 @@ var WebSignerClient = class extends SignerClient {
|
|
|
491
776
|
await this._signInWithEmail(params);
|
|
492
777
|
}
|
|
493
778
|
}
|
|
779
|
+
async getIframePublicKey() {
|
|
780
|
+
return await this._initIframeStamper();
|
|
781
|
+
}
|
|
494
782
|
/**
|
|
495
783
|
* Signs in a user with email.
|
|
496
784
|
*
|
|
@@ -501,10 +789,9 @@ var WebSignerClient = class extends SignerClient {
|
|
|
501
789
|
expirationSeconds,
|
|
502
790
|
redirectUrl
|
|
503
791
|
}) {
|
|
504
|
-
const publicKey = await this._initIframeStamper();
|
|
505
792
|
return this.request("/v1/email-auth", {
|
|
506
793
|
email,
|
|
507
|
-
targetPublicKey:
|
|
794
|
+
targetPublicKey: await this.getIframePublicKey(),
|
|
508
795
|
expirationSeconds,
|
|
509
796
|
redirectUrl: redirectUrl.toString()
|
|
510
797
|
});
|
|
@@ -512,11 +799,12 @@ var WebSignerClient = class extends SignerClient {
|
|
|
512
799
|
/**
|
|
513
800
|
* Completes the authentication process with a credential bundle.
|
|
514
801
|
*
|
|
515
|
-
* @param {
|
|
802
|
+
* @param {CompleteAuthWithBundleParams} params params for the completion of the auth process
|
|
516
803
|
*/
|
|
517
804
|
async completeAuthWithBundle({
|
|
518
805
|
bundle,
|
|
519
|
-
subOrgId
|
|
806
|
+
subOrgId,
|
|
807
|
+
sessionType
|
|
520
808
|
}) {
|
|
521
809
|
await this._initIframeStamper();
|
|
522
810
|
const result = await this._stampers.iframe.injectCredentialBundle(bundle);
|
|
@@ -524,7 +812,7 @@ var WebSignerClient = class extends SignerClient {
|
|
|
524
812
|
throw new Error("Failed to inject credential bundle");
|
|
525
813
|
}
|
|
526
814
|
await this.whoAmI(subOrgId);
|
|
527
|
-
this._sessionStore.type =
|
|
815
|
+
this._sessionStore.type = sessionType;
|
|
528
816
|
this._sessionStore.bundle = bundle;
|
|
529
817
|
}
|
|
530
818
|
/**
|
|
@@ -555,6 +843,7 @@ var WebSignerClient = class extends SignerClient {
|
|
|
555
843
|
smartAccountAddress,
|
|
556
844
|
credentialId: attestation.credentialId
|
|
557
845
|
};
|
|
846
|
+
this._sessionStore.user = this.user;
|
|
558
847
|
this._sessionStore.type = "passkeys" /* Passkeys */;
|
|
559
848
|
this._sessionStore.token = token;
|
|
560
849
|
}
|
|
@@ -565,11 +854,10 @@ var WebSignerClient = class extends SignerClient {
|
|
|
565
854
|
*/
|
|
566
855
|
async _createEmailAccount(params) {
|
|
567
856
|
const { email, expirationSeconds, redirectUrl } = params;
|
|
568
|
-
const publicKey = await this._initIframeStamper();
|
|
569
857
|
const response = await this.request("/v1/signup", {
|
|
570
858
|
email,
|
|
571
859
|
iframe: {
|
|
572
|
-
targetPublicKey:
|
|
860
|
+
targetPublicKey: await this.getIframePublicKey(),
|
|
573
861
|
expirationSeconds,
|
|
574
862
|
redirectUrl: redirectUrl.toString()
|
|
575
863
|
}
|
|
@@ -710,103 +998,6 @@ var ViemModule = class {
|
|
|
710
998
|
}
|
|
711
999
|
};
|
|
712
1000
|
|
|
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
1001
|
// src/index.ts
|
|
811
1002
|
var FourtWebSigner = class {
|
|
812
1003
|
_webSignerClient;
|
|
@@ -834,12 +1025,13 @@ var FourtWebSigner = class {
|
|
|
834
1025
|
*/
|
|
835
1026
|
constructor({
|
|
836
1027
|
configuration,
|
|
837
|
-
auth: { webauthn, iframe }
|
|
1028
|
+
auth: { webauthn, iframe, oauth }
|
|
838
1029
|
}) {
|
|
839
1030
|
this._webSignerClient = new WebSignerClient({
|
|
840
1031
|
configuration,
|
|
841
1032
|
webauthn,
|
|
842
|
-
iframe
|
|
1033
|
+
iframe,
|
|
1034
|
+
oauth
|
|
843
1035
|
});
|
|
844
1036
|
this._modules = {
|
|
845
1037
|
viem: new ViemModule(this._webSignerClient),
|