public static function decodeCredential(string $json, string $responseType) : PublicKeyCredential
    {
        $decoded = json_decode($json, true, 10);
        if ($decoded === false) {
            throw new ParseException('Failed to decode PublicKeyCredential Json');
        }

        if (($decoded['type'] ?? null) !== PublicKeyCredentialType::PUBLIC_KEY) {
            throw new ParseException("Expecting type 'public-key'");
        }

        if (empty($decoded['id'])) {
            throw new ParseException('Missing id in json data');
        }
        $id = $decoded['id'];
        if (!is_string($id)) {
            throw new ParseException('Id in json data should be string');
        }

        $rawId = Base64UrlEncoding::decode($id);

        $responseData = $decoded['response'] ?? null;
        if (!is_array($responseData)) {
            throw new ParseException('Expecting array data for response');
        }

        $response = self::decodeResponse($responseData, $responseType);


        // TODO: clientExtensionResults

        return new PublicKeyCredential(new ByteBuffer($rawId), $response);
    }
public static function decodeCredential(string $json, string $responseType) : PublicKeyCredential
    {
        $decoded = json_decode($json, true, 10);
        if ($decoded === false) {
            throw new ParseException('Failed to decode PublicKeyCredential Json');
        }

        if (($decoded['type'] ?? null) !== PublicKeyCredentialType::PUBLIC_KEY) {
            throw new ParseException("Expecting type 'public-key'");
        }

        if (empty($decoded['id'])) {
            throw new ParseException('Missing id in json data');
        }
        $id = $decoded['id'];
        if (!is_string($id)) {
            throw new ParseException('Id in json data should be string');
        }

        $rawId = Base64UrlEncoding::decode($id);

        $responseData = $decoded['response'] ?? null;
        if (!is_array($responseData)) {
            throw new ParseException('Expecting array data for response');
        }

        $response = self::decodeResponse($responseData, $responseType);


        // TODO: clientExtensionResults

        return new PublicKeyCredential(new ByteBuffer($rawId), $response);
    }
public static function decodeCredential ( string $ json , string $ responseType ) : PublicKeyCredential { $ decoded = json_decode ( $ json , true , 10 ) ; if ( $ decoded === false ) { throw new ParseException ( 'Failed to decode PublicKeyCredential Json' ) ; } if ( ( $ decoded [ 'type' ] ?? null ) !== PublicKeyCredentialType :: PUBLIC_KEY ) { throw new ParseException ( "Expecting type 'public-key'" ) ; } if ( empty ( $ decoded [ 'id' ] ) ) { throw new ParseException ( 'Missing id in json data' ) ; } $ id = $ decoded [ 'id' ] ; if ( ! is_string ( $ id ) ) { throw new ParseException ( 'Id in json data should be string' ) ; } $ rawId = Base64UrlEncoding :: decode ( $ id ) ; $ responseData = $ decoded [ 'response' ] ?? null ; if ( ! is_array ( $ responseData ) ) { throw new ParseException ( 'Expecting array data for response' ) ; } $ response = self :: decodeResponse ( $ responseData , $ responseType ) ; // TODO: clientExtensionResults return new PublicKeyCredential ( new ByteBuffer ( $ rawId ) , $ response ) ; }
Parses a JSON string containing a credential returned from the JS credential API's credentials.get or
credentials.create. The JSOn structure matches the PublicKeyCredential interface from the WebAuthn specifications
closely but since it contains ArrayBuffers it cannot be directly converted to a JSON equivalent. Fields that
are ArrayBuffers are assumed to be base64url encoded.

Also, the response field of the PublicKeyCredential can contain either an attestation or assertion response.
To determine which one to parse the $responseType parameter must be set to 'attestation' or 'assertion'.

The required JSON structure is:
```
{
"type": "public-key",
"id": "base64url encoded ArrayBuffer",
"response" : << authenticator response >>,
"getClientExtensionResults" : << output of credential.getClientExtensionResults() >>
}
```

Where the authenticator response for attestation is:
```
{
attestationObject: "base64url encoded ArrayBuffer"
}
```
and for assertion response is:
```
{
authenticatorData : "base64url encoded ArrayBuffer",
signature: "base64url encoded ArrayBuffer",
userHandle: "base64url encoded ArrayBuffer"
}
```

@param string $json
@param string $responseType Expected type of response in the public key's response field.
Either 'attestation' for attestation responses or 'assertion' for assertion responses.
@return PublicKeyCredential
@throws ParseException
@see https://www.w3.org/TR/webauthn/#publickeycredential
Parses a JSON string containing a credential returned from the JS credential API s credentials . get or credentials . create . The JSOn structure matches the PublicKeyCredential interface from the WebAuthn specifications closely but since it contains ArrayBuffers it cannot be directly converted to a JSON equivalent . Fields that are ArrayBuffers are assumed to be base64url encoded .