summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/assertion/generateAssertionCredentials.ts4
-rw-r--r--src/attestation/generateAttestationCredentials.ts4
-rw-r--r--src/helpers/constants.ts7
-rw-r--r--src/helpers/decodeAttestationObject.ts11
-rw-r--r--src/helpers/decodeClientDataJSON.ts4
-rw-r--r--src/types.ts40
6 files changed, 46 insertions, 24 deletions
diff --git a/src/assertion/generateAssertionCredentials.ts b/src/assertion/generateAssertionCredentials.ts
index 05efc08..f79d901 100644
--- a/src/assertion/generateAssertionCredentials.ts
+++ b/src/assertion/generateAssertionCredentials.ts
@@ -1,8 +1,6 @@
import base64url from 'base64url';
-export type AssertionCredentials = {
- publicKey: PublicKeyCredentialRequestOptions,
-}
+import { AssertionCredentials } from '@types';
/**
* Prepare credentials for user registration via navigator.credentials.get(...)
diff --git a/src/attestation/generateAttestationCredentials.ts b/src/attestation/generateAttestationCredentials.ts
index 901ee8b..24a085f 100644
--- a/src/attestation/generateAttestationCredentials.ts
+++ b/src/attestation/generateAttestationCredentials.ts
@@ -1,6 +1,4 @@
-export type AttestationCredentials = {
- publicKey: PublicKeyCredentialCreationOptions,
-}
+import { AttestationCredentials } from '@types';
/**
* Prepare credentials for user registration via navigator.credentials.create(...)
diff --git a/src/helpers/constants.ts b/src/helpers/constants.ts
index f2df278..5168671 100644
--- a/src/helpers/constants.ts
+++ b/src/helpers/constants.ts
@@ -1,10 +1,3 @@
-export enum ATTESTATION_FORMATS {
- FIDO_U2F = 'fido-u2f',
- PACKED = 'packed',
- ANDROID_SAFETYNET = 'android-safetynet',
- NONE = 'none',
-};
-
/**
* U2F Presence constant
*/
diff --git a/src/helpers/decodeAttestationObject.ts b/src/helpers/decodeAttestationObject.ts
index a03fefd..1c353d9 100644
--- a/src/helpers/decodeAttestationObject.ts
+++ b/src/helpers/decodeAttestationObject.ts
@@ -1,16 +1,7 @@
import base64url from 'base64url';
import cbor from 'cbor';
-import { ATTESTATION_FORMATS } from './constants';
-
-type AttestationObject = {
- fmt: ATTESTATION_FORMATS,
- attStmt: {
- sig?: Buffer,
- x5c?: Buffer,
- },
- authData: Buffer,
-};
+import { AttestationObject } from '@types';
/**
*
diff --git a/src/helpers/decodeClientDataJSON.ts b/src/helpers/decodeClientDataJSON.ts
index b957d60..2b5bbbd 100644
--- a/src/helpers/decodeClientDataJSON.ts
+++ b/src/helpers/decodeClientDataJSON.ts
@@ -1,3 +1,5 @@
+import { ClientDataJSON } from '@types';
+
import asciiToBinary from './asciiToBinary';
/**
@@ -6,7 +8,7 @@ import asciiToBinary from './asciiToBinary';
* @param data
* @returns {Object} - the data as JSON
*/
-export default function decodeClientDataJSON(data: string) {
+export default function decodeClientDataJSON(data: string): ClientDataJSON {
const toString = asciiToBinary(data);
return JSON.parse(toString);
}
diff --git a/src/types.ts b/src/types.ts
new file mode 100644
index 0000000..b3d7d60
--- /dev/null
+++ b/src/types.ts
@@ -0,0 +1,40 @@
+export type AttestationCredentials = {
+ publicKey: PublicKeyCredentialCreationOptions,
+};
+
+export type AssertionCredentials = {
+ publicKey: PublicKeyCredentialRequestOptions,
+};
+
+/**
+ * A slightly-modified AuthenticatorAttestationResponse to simplify working with ArrayBuffers that
+ * are base64-encoded in the browser so that they can be sent as JSON to the server.
+ */
+export interface EncodedAuthenticatorAttestationResponse extends Omit<
+AuthenticatorAttestationResponse, 'clientDataJSON' | 'attestationObject'
+> {
+ clientDataJSON: string,
+ attestationObject: string;
+}
+
+export enum ATTESTATION_FORMATS {
+ FIDO_U2F = 'fido-u2f',
+ PACKED = 'packed',
+ ANDROID_SAFETYNET = 'android-safetynet',
+ NONE = 'none',
+};
+
+export type AttestationObject = {
+ fmt: ATTESTATION_FORMATS,
+ attStmt: {
+ sig?: Buffer,
+ x5c?: Buffer,
+ },
+ authData: Buffer,
+};
+
+export type ClientDataJSON = {
+ type: string;
+ challenge: string;
+ origin: string;
+};