const signChallenge = (challenge: UserActionSignatureChallenge) => {
/*
challenge.allowCredentials.key is an array of registered credentials. If you have
more than one Key credential, you may need to use challenge.allowCredentials.key[N].id to locate
the key you're using. For example, you could have made your ID the base64url encoded name of the key on disk or in AWS KMS.
In this example, we assume the user registered a single Key credential.
*/
const clientData = { type: 'key.get', challenge: challenge.challenge }
const clientDataBytes: Buffer = Buffer.from(JSON.stringify(clientData))
const signature = crypto.sign(undefined, clientDataBytes, apiKeyPrivateKey)
return {
credId: challenge.allowCredentials.key[0].id,
clientData: clientData.toString('base64url'),
signature: signature.toString('base64url'),
}
}