authenticatorAttachment = $authenticatorAttachment; return $this; } /** * @deprecated since v4.1. Please use setResidentKey instead */ public function setRequireResidentKey(bool $requireResidentKey): self { $this->requireResidentKey = $requireResidentKey; //$this->residentKey = $requireResidentKey ? self::RESIDENT_KEY_REQUIREMENT_REQUIRED : self::RESIDENT_KEY_REQUIREMENT_DISCOURAGED; return $this; } public function setUserVerification(string $userVerification): self { $this->userVerification = $userVerification; return $this; } public function setResidentKey(null|string $residentKey): self { $this->residentKey = $residentKey; //$this->requireResidentKey = $residentKey === self::RESIDENT_KEY_REQUIREMENT_REQUIRED; return $this; } public function getAuthenticatorAttachment(): ?string { return $this->authenticatorAttachment; } /** * @deprecated Will be removed in 5.0. Please use getResidentKey() instead */ public function isRequireResidentKey(): bool { return $this->requireResidentKey; } public function getUserVerification(): string { return $this->userVerification; } public function getResidentKey(): null|string { return $this->residentKey; } public static function createFromString(string $data): self { $data = json_decode($data, true, 512, JSON_THROW_ON_ERROR); return self::createFromArray($data); } /** * @param mixed[] $json */ public static function createFromArray(array $json): self { $authenticatorAttachment = $json['authenticatorAttachment'] ?? null; $requireResidentKey = $json['requireResidentKey'] ?? false; $userVerification = $json['userVerification'] ?? self::USER_VERIFICATION_REQUIREMENT_PREFERRED; $residentKey = $json['residentKey'] ?? self::RESIDENT_KEY_REQUIREMENT_PREFERRED; $authenticatorAttachment === null || is_string($authenticatorAttachment) || throw InvalidDataException::create( $json, 'Invalid "authenticatorAttachment" value' ); is_bool($requireResidentKey) || throw InvalidDataException::create( $json, 'Invalid "requireResidentKey" value' ); is_string($userVerification) || throw InvalidDataException::create($json, 'Invalid "userVerification" value'); is_string($residentKey) || throw InvalidDataException::create($json, 'Invalid "residentKey" value'); return self::create() ->setAuthenticatorAttachment($authenticatorAttachment) ->setRequireResidentKey($requireResidentKey) ->setUserVerification($userVerification) ->setResidentKey($residentKey); } /** * @return mixed[] */ public function jsonSerialize(): array { $json = [ 'requireResidentKey' => $this->requireResidentKey, 'userVerification' => $this->userVerification, // 'residentKey' => $this->residentKey, // TODO: On hold. Waiting for issue clarification. See https://github.com/fido-alliance/conformance-test-tools-resources/issues/676 ]; if ($this->authenticatorAttachment !== null) { $json['authenticatorAttachment'] = $this->authenticatorAttachment; } return $json; } }