summaryrefslogtreecommitdiffhomepage
path: root/packages/server/src/helpers/decodeAuthenticatorExtensions.ts
diff options
context:
space:
mode:
authorEiji Kitamura <agektmr@google.com>2022-07-22 15:35:41 +0900
committerEiji Kitamura <agektmr@google.com>2022-07-22 15:35:41 +0900
commit53dd14e4dc21b1d97224f6b8b5f36285ed72283a (patch)
tree418a31a7b3e870b3ec2b5b1b6ee784a21aa5d231 /packages/server/src/helpers/decodeAuthenticatorExtensions.ts
parent7fdfa35dd57b3998f0fbe78f2111434de3c3afc9 (diff)
Fixes to reflect comments
- Rename `decodeExtensions` to `decodeAuthenticatorExtensions` - Mention authenticator extension - Include decoding in `parseAuthenticatorData` - Add tests for `decodeAuthenticatorExtensions`
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..d4a71ea
--- /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 default function decodeAuthenticatorExtensionData(
+ extensionData: Buffer
+): AuthenticationExtensionsAuthenticatorOutputs | undefined {
+ let toCBOR: AuthenticationExtensionsAuthenticatorOutputs | undefined;
+ try {
+ toCBOR = cbor.decodeAllSync(extensionData)[0];
+ } catch (e) {
+ console.error(e);
+ toCBOR = undefined;
+ }
+ return toCBOR;
+}
+
+export type AuthenticationExtensionsAuthenticatorOutputs = {
+ devicePublicKey?: DevicePublicKeyJSON;
+ uvm?: UvmJSON;
+}
+
+export type DevicePublicKeyJSON = {
+ dpk?: Buffer;
+ scp?: Buffer;
+ sig?: string;
+ aaguid?: Buffer;
+}
+
+// TODO: Need to verify this format
+// https://w3c.github.io/webauthn/#sctn-uvm-extension.
+export type UvmJSON = {
+ uvm?: Buffer[]
+}