Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Testing every permutation of methods and sequences
  • Loading branch information
bfollington committed Feb 25, 2025
commit aed155e4daf461044798c83b623b25b77693f04c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ interface AuthenticationContextType {
// The authenticated user/persona.
user: Identity | void;
// Call PassKey registration.
passkeyRegister: (name: string, displayName: string) => Promise<PublicKeyCredential>;
passkeyRegister: (name: string, displayName: string) => Promise<PassKey>;
// Authenticate the user via passkey.
passkeyAuthenticate: (descriptor?: PublicKeyCredentialDescriptor) => Promise<void>;
passkeyAuthenticate: (descriptor?: PublicKeyCredentialDescriptor) => Promise<PassKey>;
// Generate a passphrase for a new user
passphraseRegister: () => Promise<string>;
// Authenticate via passphrase.
Expand Down Expand Up @@ -89,13 +89,14 @@ export const AuthenticationProvider: React.FC<{ children: React.ReactNode }> = (
const passkeyAuthenticate = useCallback(
async (key?: PublicKeyCredentialDescriptor) => {
if (!keyStore) {
return;
throw new Error("Key store not initialized");
}
// Pass the keyName to PassKey.get() if provided
const passkey = await PassKey.get({ allowCredentials: key ? [key] : [] });
const root = await passkey.createRootKey();
await keyStore.set(ROOT_KEY, root);
setRoot(root);
return passkey;
},
[keyStore],
);
Expand Down
46 changes: 46 additions & 0 deletions typescript/packages/jumble/src/utils/credentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
export interface StoredCredential {
id: string;
type: "public-key" | "passphrase";
method: "passkey" | "passphrase";
}

export function getStoredCredential(): StoredCredential | null {
const stored = localStorage.getItem("storedCredential");
return stored ? JSON.parse(stored) : null;
}

export function saveCredential(credential: StoredCredential): void {
localStorage.setItem("storedCredential", JSON.stringify(credential));
}

export function clearStoredCredential(): void {
localStorage.removeItem("storedCredential");
}

export function createPasskeyCredential(id: string): StoredCredential {
return {
id,
type: "public-key",
method: "passkey",
};
}

export function createPassphraseCredential(): StoredCredential {
return {
id: crypto.randomUUID(),
type: "passphrase",
method: "passphrase",
};
}

export function getPublicKeyCredentialDescriptor(
storedCredential: StoredCredential | null,
): PublicKeyCredentialDescriptor | undefined {
if (storedCredential?.type === "public-key") {
return {
id: Uint8Array.from(atob(storedCredential.id), (c) => c.charCodeAt(0)),
type: "public-key" as PublicKeyCredentialType,
};
}
return undefined;
}
Loading