diff options
author | Matthew Miller <matthew@millerti.me> | 2020-05-20 08:44:12 -0700 |
---|---|---|
committer | Matthew Miller <matthew@millerti.me> | 2020-05-20 08:44:12 -0700 |
commit | 2c51287bec3592ebf7d40d886c41da8fb51cbc21 (patch) | |
tree | 603ec65541ea461cbe78c198c34574238eebd10a /packages/server/src/assertion/generateAssertionCredentials.ts | |
parent | d9074ec54935aa2155151d2dd9dea0974f33da29 (diff) |
Initialize lerna project and move code to `server`
Diffstat (limited to 'packages/server/src/assertion/generateAssertionCredentials.ts')
-rw-r--r-- | packages/server/src/assertion/generateAssertionCredentials.ts | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/packages/server/src/assertion/generateAssertionCredentials.ts b/packages/server/src/assertion/generateAssertionCredentials.ts new file mode 100644 index 0000000..71f9e44 --- /dev/null +++ b/packages/server/src/assertion/generateAssertionCredentials.ts @@ -0,0 +1,29 @@ +import base64url from 'base64url'; + +import { AssertionCredentials } from '@libTypes'; + +/** + * Prepare credentials for user registration via navigator.credentials.get(...) + * + * @param challenge Random string the authenticator needs to sign and pass back + * @param base64CredentialIDs Array of base64-encoded authenticator IDs registered by the user for + * assertion + * @param timeout How long (in ms) the user can take to complete attestation + */ +export default function generateAssertionCredentials( + challenge: string, + base64CredentialIDs: string[], + timeout: number = 60000, +): AssertionCredentials { + return { + publicKey: { + challenge: Uint8Array.from(challenge, c => c.charCodeAt(0)), + allowCredentials: base64CredentialIDs.map(id => ({ + id: base64url.toBuffer(id), + type: 'public-key', + transports: ['usb', 'ble', 'nfc'], + })), + timeout, + }, + }; +} |