Skip to content

Commit 8edb21b

Browse files
committed
feat: update eip-1193-provider version
1 parent ecabd78 commit 8edb21b

File tree

2 files changed

+40
-41
lines changed

2 files changed

+40
-41
lines changed
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const VERSION = "@turnkey/eip-1193-provider@3.1.5";
1+
export const VERSION = "@turnkey/eip-1193-provider@3.2.0";

packages/sdk-browser/src/__clients__/browser-clients.ts

+39-40
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
108108
organizationId?: string;
109109
}): Promise<SdkApiTypes.TCreateReadOnlySessionResponse> => {
110110
const readOnlySessionResult = await this.createReadOnlySession(
111-
config || {},
111+
config || {}
112112
);
113113
await saveSession(readOnlySessionResult, this.authClient);
114114

@@ -128,12 +128,12 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
128128
refereshSession = async (
129129
sessionType: SessionType = SessionType.READ_WRITE,
130130
targetPublicKey?: string, // TODO: eventually we want to automatically pull this from localStorage/iframe
131-
expirationSeconds: string = DEFAULT_SESSION_EXPIRATION_IN_SECONDS,
131+
expirationSeconds: string = DEFAULT_SESSION_EXPIRATION_IN_SECONDS
132132
): Promise<void> => {
133133
if (sessionType === SessionType.READ_ONLY) {
134134
if (this! instanceof TurnkeyPasskeyClient) {
135135
throw new Error(
136-
"You must use a passkey client to refresh a read session",
136+
"You must use a passkey client to refresh a read session"
137137
); // TODO: support wallet clients perhaps?
138138
}
139139
const readOnlySessionResult = await this.createReadOnlySession({});
@@ -150,7 +150,7 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
150150
if (sessionType === SessionType.READ_WRITE) {
151151
if (!targetPublicKey) {
152152
throw new Error(
153-
"You must provide a targetPublicKey to refresh a read-write session.",
153+
"You must provide a targetPublicKey to refresh a read-write session."
154154
);
155155
}
156156
const readWriteSessionResult = await this.createReadWriteSession({
@@ -170,7 +170,7 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
170170
} else {
171171
// Throw an error if the client is not an iframe client
172172
throw new Error(
173-
"You must use an iframe client to refresh a read-write session",
173+
"You must use an iframe client to refresh a read-write session"
174174
); //should we default to a "localStorage" client?
175175
}
176176
await storeSession(session, AuthClient.Iframe);
@@ -187,14 +187,14 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
187187
*/
188188
loginWithBundle = async (
189189
bundle: string, // we need a way to get the expiry of this token. Either it lives in the token itself or is returned from the server action and passed again here
190-
expirationSeconds: string, // we need a way to get the expiry of this token. Either it lives in the token itself or is returned from the server action and passed again here
190+
expirationSeconds: string // we need a way to get the expiry of this token. Either it lives in the token itself or is returned from the server action and passed again here
191191
): Promise<void> => {
192192
if (this! instanceof TurnkeyIframeClient) {
193193
await this.injectCredentialBundle(bundle);
194194
} else {
195195
// Throw an error if the client is not an iframe client
196196
throw new Error(
197-
"You must use an iframe client to log in with a session.",
197+
"You must use an iframe client to log in with a session."
198198
); //should we default to a "localStorage" client?
199199
}
200200
const whoAmI = await this.getWhoami();
@@ -215,15 +215,15 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
215215
* To be used in conjunction with an `iframeStamper`.
216216
*
217217
* @param session
218-
* @returns {Promise<SdkApiTypes.void>}
218+
* @returns {Promise<void>}
219219
*/
220220
loginWithSession = async (session: Session): Promise<void> => {
221221
if (this instanceof TurnkeyIframeClient) {
222222
await this.injectCredentialBundle(session.token!);
223223
} else {
224224
// Throw an error if the client is not an iframe client
225225
throw new Error(
226-
"You must use an iframe client to log in with a session.",
226+
"You must use an iframe client to log in with a session."
227227
); //should we default to a "localStorage" client?
228228
}
229229
await storeSession(session, AuthClient.Iframe);
@@ -240,8 +240,7 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
240240
sessionType: SessionType = SessionType.READ_WRITE,
241241
iframeClient: TurnkeyIframeClient,
242242
targetPublicKey?: string, // TODO: eventually we want to automatically pull this from localStorage/iframe
243-
244-
expirationSeconds: string = DEFAULT_SESSION_EXPIRATION_IN_SECONDS,
243+
expirationSeconds: string = DEFAULT_SESSION_EXPIRATION_IN_SECONDS
245244
): Promise<void> => {
246245
// Create a read-only session
247246
if (sessionType === SessionType.READ_ONLY) {
@@ -261,7 +260,7 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
261260
if (sessionType === SessionType.READ_WRITE) {
262261
if (!targetPublicKey) {
263262
throw new Error(
264-
"You must provide a targetPublicKey to create a read-write session.",
263+
"You must provide a targetPublicKey to create a read-write session."
265264
);
266265
}
267266

@@ -280,7 +279,7 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
280279

281280
if (!iframeClient) {
282281
throw new Error(
283-
"You must provide an iframe client to log in with a passkey.",
282+
"You must provide an iframe client to log in with a passkey."
284283
);
285284
}
286285
await iframeClient.injectCredentialBundle(session.token!);
@@ -304,7 +303,7 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
304303
loginWithReadWriteSession = async (
305304
targetEmbeddedKey: string,
306305
expirationSeconds: string = DEFAULT_SESSION_EXPIRATION_IN_SECONDS,
307-
userId?: string,
306+
userId?: string
308307
): Promise<SdkApiTypes.TCreateReadWriteSessionResponse> => {
309308
const readWriteSessionResult = await this.createReadWriteSession({
310309
targetPublicKey: targetEmbeddedKey,
@@ -334,7 +333,7 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
334333
*/
335334
loginWithAuthBundle = async (
336335
credentialBundle: string,
337-
expirationSeconds: string = DEFAULT_SESSION_EXPIRATION_IN_SECONDS,
336+
expirationSeconds: string = DEFAULT_SESSION_EXPIRATION_IN_SECONDS
338337
): Promise<any> => {
339338
try {
340339
const whoAmIResult = await this.getWhoami();
@@ -348,7 +347,7 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
348347
await saveSession(readWriteSessionResultWithSession, this.authClient);
349348
return true;
350349
} catch {
351-
return false;
350+
throw new Error("Unable to log in with the provided auth bundle.");
352351
}
353352
};
354353

@@ -388,20 +387,20 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
388387

389388
if (phoneNumber) {
390389
promises.push(
391-
this.updateUser({ userId, userPhoneNumber: "", userTagIds: [] }),
390+
this.updateUser({ userId, userPhoneNumber: "", userTagIds: [] })
392391
);
393392
}
394393
if (email) {
395394
promises.push(
396-
this.updateUser({ userId, userEmail: "", userTagIds: [] }),
395+
this.updateUser({ userId, userEmail: "", userTagIds: [] })
397396
);
398397
}
399398
if (authenticatorIds && authenticatorIds.length > 0) {
400399
promises.push(this.deleteAuthenticators({ userId, authenticatorIds }));
401400
}
402401
if (oauthProviderIds && oauthProviderIds.length > 0) {
403402
promises.push(
404-
this.deleteOauthProviders({ userId, providerIds: oauthProviderIds }),
403+
this.deleteOauthProviders({ userId, providerIds: oauthProviderIds })
405404
);
406405
}
407406
if (apiKeyIds && apiKeyIds.length > 0) {
@@ -456,12 +455,12 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
456455
userId,
457456
userPhoneNumber: phoneNumber,
458457
userTagIds: [],
459-
}),
458+
})
460459
);
461460
}
462461
if (email) {
463462
promises.push(
464-
this.updateUser({ userId, userEmail: email, userTagIds: [] }),
463+
this.updateUser({ userId, userEmail: email, userTagIds: [] })
465464
);
466465
}
467466
if (authenticators && authenticators.length > 0) {
@@ -526,7 +525,7 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
526525
}
527526
if (Object.keys(userUpdates).length > 0) {
528527
promises.push(
529-
this.updateUser({ userId, ...userUpdates, userTagIds: [] }),
528+
this.updateUser({ userId, ...userUpdates, userTagIds: [] })
530529
);
531530
}
532531

@@ -537,15 +536,15 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
537536
this.createAuthenticators({
538537
userId,
539538
authenticators: authenticators.add,
540-
}),
539+
})
541540
);
542541
}
543542
if (authenticators.deleteIds?.length) {
544543
promises.push(
545544
this.deleteAuthenticators({
546545
userId,
547546
authenticatorIds: authenticators.deleteIds,
548-
}),
547+
})
549548
);
550549
}
551550
}
@@ -557,15 +556,15 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
557556
this.createOauthProviders({
558557
userId,
559558
oauthProviders: oauthProviders.add,
560-
}),
559+
})
561560
);
562561
}
563562
if (oauthProviders.deleteIds?.length) {
564563
promises.push(
565564
this.deleteOauthProviders({
566565
userId,
567566
providerIds: oauthProviders.deleteIds,
568-
}),
567+
})
569568
);
570569
}
571570
}
@@ -577,15 +576,15 @@ export class TurnkeyBrowserClient extends TurnkeyBaseClient {
577576
this.createApiKeys({
578577
userId,
579578
apiKeys: apiKeys.add,
580-
}),
579+
})
581580
);
582581
}
583582
if (apiKeys.deleteIds?.length) {
584583
promises.push(
585584
this.deleteApiKeys({
586585
userId,
587586
apiKeyIds: apiKeys.deleteIds,
588-
}),
587+
})
589588
);
590589
}
591590
}
@@ -614,7 +613,7 @@ export class TurnkeyPasskeyClient extends TurnkeyBrowserClient {
614613
* @returns {Promise<Passkey>}
615614
*/
616615
createUserPasskey = async (
617-
config: Record<any, any> = {},
616+
config: Record<any, any> = {}
618617
): Promise<Passkey> => {
619618
const challenge = generateRandomBuffer();
620619
const encodedChallenge = base64UrlEncode(challenge);
@@ -694,15 +693,15 @@ export class TurnkeyPasskeyClient extends TurnkeyBrowserClient {
694693
userId: string,
695694
targetEmbeddedKey: string,
696695
expirationSeconds: string = DEFAULT_SESSION_EXPIRATION_IN_SECONDS,
697-
organizationId?: string,
696+
organizationId?: string
698697
): Promise<ReadWriteSession> => {
699698
const user = await getStorageValue(StorageKeys.UserSession);
700699
organizationId = organizationId ?? user?.organization.organizationId;
701700
userId = userId ?? user?.userId;
702701

703702
if (!organizationId) {
704703
throw new Error(
705-
"Error creating passkey session: Organization ID is required",
704+
"Error creating passkey session: Organization ID is required"
706705
);
707706
}
708707

@@ -738,7 +737,7 @@ export class TurnkeyPasskeyClient extends TurnkeyBrowserClient {
738737
credentialBundle,
739738
sessionExpiry: expiry,
740739
},
741-
this.authClient,
740+
this.authClient
742741
);
743742

744743
return {
@@ -763,44 +762,44 @@ export class TurnkeyIframeClient extends TurnkeyBrowserClient {
763762
}
764763

765764
injectCredentialBundle = async (
766-
credentialBundle: string,
765+
credentialBundle: string
767766
): Promise<boolean> => {
768767
return await (this.stamper as IframeStamper).injectCredentialBundle(
769-
credentialBundle,
768+
credentialBundle
770769
);
771770
};
772771

773772
injectWalletExportBundle = async (
774773
credentialBundle: string,
775-
organizationId: string,
774+
organizationId: string
776775
): Promise<boolean> => {
777776
return await (this.stamper as IframeStamper).injectWalletExportBundle(
778777
credentialBundle,
779-
organizationId,
778+
organizationId
780779
);
781780
};
782781

783782
injectKeyExportBundle = async (
784783
credentialBundle: string,
785784
organizationId: string,
786-
keyFormat?: KeyFormat | undefined,
785+
keyFormat?: KeyFormat | undefined
787786
): Promise<boolean> => {
788787
return await (this.stamper as IframeStamper).injectKeyExportBundle(
789788
credentialBundle,
790789
organizationId,
791-
keyFormat,
790+
keyFormat
792791
);
793792
};
794793

795794
injectImportBundle = async (
796795
bundle: string,
797796
organizationId: string,
798-
userId: string,
797+
userId: string
799798
): Promise<boolean> => {
800799
return await (this.stamper as IframeStamper).injectImportBundle(
801800
bundle,
802801
organizationId,
803-
userId,
802+
userId
804803
);
805804
};
806805

0 commit comments

Comments
 (0)