summaryrefslogtreecommitdiffhomepage
path: root/packages/server/src/helpers/decodeAttestationObject.ts
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2022-12-10 22:40:45 -0800
committerGitHub <noreply@github.com>2022-12-10 22:40:45 -0800
commit461b67c0c6fadfb55c1da6c9c8ab2693ba4c9a03 (patch)
treeae713d608966ac977390e7bbfbeab5ea79a191bc /packages/server/src/helpers/decodeAttestationObject.ts
parent33528afe001d4aca62052dce204c0398c3127ffd (diff)
parent90dd7f247182329987a8e23f476d9280d8d5c265 (diff)
Merge pull request #299 from MasterKale/feat/isomorphic
feat/isomorphic
Diffstat (limited to 'packages/server/src/helpers/decodeAttestationObject.ts')
-rw-r--r--packages/server/src/helpers/decodeAttestationObject.ts33
1 files changed, 19 insertions, 14 deletions
diff --git a/packages/server/src/helpers/decodeAttestationObject.ts b/packages/server/src/helpers/decodeAttestationObject.ts
index 5385106..afdd7a4 100644
--- a/packages/server/src/helpers/decodeAttestationObject.ts
+++ b/packages/server/src/helpers/decodeAttestationObject.ts
@@ -1,13 +1,12 @@
-import cbor from 'cbor';
+import { isoCBOR } from './iso';
/**
* Convert an AttestationObject buffer to a proper object
*
* @param base64AttestationObject Attestation Object buffer
*/
-export function decodeAttestationObject(attestationObject: Buffer): AttestationObject {
- const toCBOR: AttestationObject = cbor.decodeAllSync(attestationObject)[0];
- return toCBOR;
+export function decodeAttestationObject(attestationObject: Uint8Array): AttestationObject {
+ return isoCBOR.decodeFirst<AttestationObject>(attestationObject);
}
export type AttestationFormat =
@@ -20,17 +19,23 @@ export type AttestationFormat =
| 'none';
export type AttestationObject = {
- fmt: AttestationFormat;
- attStmt: AttestationStatement;
- authData: Buffer;
+ get(key: 'fmt'): AttestationFormat;
+ get(key: 'attStmt'): AttestationStatement;
+ get(key: 'authData'): Uint8Array;
};
+/**
+ * `AttestationStatement` will be an instance of `Map`, but these keys help make finite the list of
+ * possible values within it.
+ */
export type AttestationStatement = {
- sig?: Buffer;
- x5c?: Buffer[];
- response?: Buffer;
- alg?: number;
- ver?: string;
- certInfo?: Buffer;
- pubArea?: Buffer;
+ get(key: 'sig'): Uint8Array | undefined;
+ get(key: 'x5c'): Uint8Array[] | undefined;
+ get(key: 'response'): Uint8Array | undefined;
+ get(key: 'alg'): number | undefined;
+ get(key: 'ver'): string | undefined;
+ get(key: 'certInfo'): Uint8Array | undefined;
+ get(key: 'pubArea'): Uint8Array | undefined;
+ // `Map` properties
+ get size(): number;
};