Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(protocol-kit): Improve passkeys typing #1063

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
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
Loading