blob: fb909cf66ecae82611b7ae56fc65c7db1a66d1b9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
import { ClientDataJSON } from '@simplewebauthn/typescript-types';
import asciiToBinary from './asciiToBinary';
/**
* Decode an authenticator's base64-encoded clientDataJSON to JSON
*/
export default function decodeClientDataJSON(data: string): ClientDataJSON {
const toString = asciiToBinary(data);
const clientData: ClientDataJSON = JSON.parse(toString);
// `challenge` will be Base64-encoded here. Decode it for easier comparisons with what is provided
// as the expected value
clientData.challenge = Buffer.from(clientData.challenge, 'base64').toString('ascii');
return clientData;
}
|