summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/assertion/generateAssertionCredentials.ts27
-rw-r--r--src/index.ts4
2 files changed, 30 insertions, 1 deletions
diff --git a/src/assertion/generateAssertionCredentials.ts b/src/assertion/generateAssertionCredentials.ts
new file mode 100644
index 0000000..fc43097
--- /dev/null
+++ b/src/assertion/generateAssertionCredentials.ts
@@ -0,0 +1,27 @@
+import base64url from 'base64url';
+
+/**
+ * Prepare credentials for user registration via navigator.credentials.get(...)
+ *
+ * @param challenge Random string the authenticator needs to sign and pass back
+ * @param credentialIDs 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,
+ credentialIDs: string[],
+ timeout: number = 60000,
+) {
+ return {
+ publicKey: {
+ challenge: Uint8Array.from(challenge, c => c.charCodeAt(0)),
+ allowCredentials: credentialIDs.map(id => ({
+ id: base64url.toBuffer(id),
+ type: 'public-key',
+ transports: ['usb', 'ble', 'nfc'],
+ })),
+ timeout,
+ },
+ };
+}
diff --git a/src/index.ts b/src/index.ts
index bbe3ec4..d20824a 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,5 +1,7 @@
-import generateAttestationCredentials from "./attestation/generateAttestationCredentials";
+import generateAttestationCredentials from './attestation/generateAttestationCredentials';
+import generateAssertionCredentials from './assertion/generateAssertionCredentials';
export {
generateAttestationCredentials,
+ generateAssertionCredentials,
};