diff options
Diffstat (limited to 'packages/browser/src/helpers/toPublicKeyCredentialDescriptor.ts')
-rw-r--r-- | packages/browser/src/helpers/toPublicKeyCredentialDescriptor.ts | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/packages/browser/src/helpers/toPublicKeyCredentialDescriptor.ts b/packages/browser/src/helpers/toPublicKeyCredentialDescriptor.ts new file mode 100644 index 0000000..ad166a5 --- /dev/null +++ b/packages/browser/src/helpers/toPublicKeyCredentialDescriptor.ts @@ -0,0 +1,16 @@ +import base64js from 'base64-js'; +import type { PublicKeyCredentialDescriptorJSON } from '@webauthntine/typescript-types'; + +export default function toPublicKeyCredentialDescriptor( + descriptor: PublicKeyCredentialDescriptorJSON, +): PublicKeyCredentialDescriptor { + // Make sure the Base64'd credential ID length is a multiple of 4 or else toByteArray will throw + const { id } = descriptor; + const padLength = 4 - (id.length % 4); + const paddedId = id.padEnd(id.length + padLength, '='); + + return { + ...descriptor, + id: base64js.toByteArray(paddedId), + }; +} |