summaryrefslogtreecommitdiffhomepage
path: root/packages/server/src/helpers/decodeAuthenticatorExtensions.ts
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2022-07-22 19:11:46 -0700
committerGitHub <noreply@github.com>2022-07-22 19:11:46 -0700
commitea6ced40a0edbdd7c9be9270bb168b7f117547bd (patch)
tree23d64ae95264edecd19590c3612046d86e2e8ddc /packages/server/src/helpers/decodeAuthenticatorExtensions.ts
parentcfa689214f772a6375dcc385714982209ddf1f08 (diff)
parentc532f52e265ab272762f872f70346ce2f66f0199 (diff)
Merge pull request #230 from agektmr/dev
Return `AuthenticationExtensionsAuthenticatorOutputs` as part of registration and authentication
Diffstat (limited to 'packages/server/src/helpers/decodeAuthenticatorExtensions.ts')
-rw-r--r--packages/server/src/helpers/decodeAuthenticatorExtensions.ts37
1 files changed, 37 insertions, 0 deletions
diff --git a/packages/server/src/helpers/decodeAuthenticatorExtensions.ts b/packages/server/src/helpers/decodeAuthenticatorExtensions.ts
new file mode 100644
index 0000000..a0dc5c2
--- /dev/null
+++ b/packages/server/src/helpers/decodeAuthenticatorExtensions.ts
@@ -0,0 +1,37 @@
+import cbor from 'cbor';
+
+/**
+ * Convert authenticator extension data buffer to a proper object
+ *
+ * @param extensionData Authenticator Extension Data buffer
+ */
+export function decodeAuthenticatorExtensions(
+ extensionData: Buffer
+): AuthenticationExtensionsAuthenticatorOutputs | undefined {
+ let toCBOR: AuthenticationExtensionsAuthenticatorOutputs | undefined;
+ try {
+ toCBOR = cbor.decodeAllSync(extensionData)[0];
+ } catch (err) {
+ const _err = err as Error;
+ throw new Error(`Error decoding authenticator extensions: ${_err.message}`);
+ }
+ return toCBOR;
+}
+
+export type AuthenticationExtensionsAuthenticatorOutputs = {
+ devicePublicKey?: DevicePublicKeyAuthenticatorOutput;
+ uvm?: UVMAuthenticatorOutput;
+}
+
+export type DevicePublicKeyAuthenticatorOutput = {
+ dpk?: Buffer;
+ scp?: Buffer;
+ sig?: string;
+ aaguid?: Buffer;
+}
+
+// TODO: Need to verify this format
+// https://w3c.github.io/webauthn/#sctn-uvm-extension.
+export type UVMAuthenticatorOutput = {
+ uvm?: Buffer[]
+}