Skip to content

Commit

Permalink
Improve passkey typing
Browse files Browse the repository at this point in the history
  • Loading branch information
yagopv committed Dec 2, 2024
1 parent e0317d5 commit 32852dc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/protocol-kit/src/Safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1704,9 +1704,11 @@ class Safe {
/**
* This method creates a signer to be used with the init method
* @param {Credential} credential - The credential to be used to create the signer. Can be generated in the web with navigator.credentials.create
* @returns {PasskeyArgType} - The signer to be used with the init method
* @returns {Pick<PasskeyArgType, 'rawId' | 'coordinates'>} - The signer to be used with the init method
*/
static createPasskeySigner = async (credential: Credential): Promise<PasskeyArgType> => {
static createPasskeySigner = async (
credential: Credential
): Promise<Pick<PasskeyArgType, 'rawId' | 'coordinates'>> => {
return extractPasskeyData(credential)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,14 @@ export async function decodePublicKey(
* Extracts and returns the passkey data (coordinates and rawId) from a given passkey Credential.
*
* @param {Credential} passkeyCredential - The passkey credential generated via `navigator.credentials.create()` or other method in another platforms.
* @returns {Promise<PasskeyArgType>} A promise that resolves to an object containing the coordinates and the rawId derived from the passkey.
* @returns {Promise<Pick<PasskeyArgType, 'rawId' | 'coordinates'>>} A promise that resolves to an object containing the coordinates and the rawId derived from the passkey.
* This is the important information in the Safe account context and should be stored securely as it is used to verify the passkey and to instantiate the SDK
* as a signer (`Safe.init())
* @throws {Error} Throws an error if the coordinates could not be extracted
*/
export async function extractPasskeyData(passkeyCredential: Credential): Promise<PasskeyArgType> {
export async function extractPasskeyData(
passkeyCredential: Credential
): Promise<Pick<PasskeyArgType, 'rawId' | 'coordinates'>> {
const passkeyPublicKeyCredential = passkeyCredential as PublicKeyCredential

const rawId = Buffer.from(passkeyPublicKeyCredential.rawId).toString('hex')
Expand Down

0 comments on commit 32852dc

Please sign in to comment.