summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2020-05-17 21:03:04 -0700
committerMatthew Miller <matthew@millerti.me>2020-05-17 21:03:04 -0700
commit256a20719b493d9e5116beb5344e1eaf74f469fd (patch)
treee5292f66935126a319d13a2aa2d59fda2a506a40 /src
parent834aa3ac2d0e9907487fc73ada8be78a196fad90 (diff)
Add generateAssertionCredentials
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,
};