blob: 8230f42bddfe535e9df844b2cd35f2ea3624c4dd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
import { isoBase64URL } from './iso/index.ts';
import type { Base64URLString } from '../deps.ts';
/**
* Decode an authenticator's base64url-encoded clientDataJSON to JSON
*/
export function decodeClientDataJSON(data: Base64URLString): ClientDataJSON {
const toString = isoBase64URL.toUTF8String(data);
const clientData: ClientDataJSON = JSON.parse(toString);
return _decodeClientDataJSONInternals.stubThis(clientData);
}
export type ClientDataJSON = {
type: string;
challenge: string;
origin: string;
crossOrigin?: boolean;
tokenBinding?: {
id?: string;
status: 'present' | 'supported' | 'not-supported';
};
};
// Make it possible to stub the return value during testing
export const _decodeClientDataJSONInternals = {
stubThis: (value: ClientDataJSON) => value,
};
|