$data */ public function __construct(array $data) { foreach ([self::DATA_CURVE, self::TYPE] as $key) { if (is_numeric($data[$key])) { $data[$key] = (int) $data[$key]; } } parent::__construct($data); if ($data[self::TYPE] !== self::TYPE_OKP && $data[self::TYPE] !== self::TYPE_NAME_OKP) { throw new InvalidArgumentException('Invalid OKP key. The key type does not correspond to an OKP key'); } if (! isset($data[self::DATA_CURVE], $data[self::DATA_X])) { throw new InvalidArgumentException('Invalid EC2 key. The curve or the "x" coordinate is missing'); } if (is_numeric($data[self::DATA_CURVE])) { if (! in_array((int) $data[self::DATA_CURVE], self::SUPPORTED_CURVES_INT, true)) { throw new InvalidArgumentException('The curve is not supported'); } } elseif (! in_array($data[self::DATA_CURVE], self::SUPPORTED_CURVES_NAME, true)) { throw new InvalidArgumentException('The curve is not supported'); } } /** * @param array $data */ public static function create(array $data): self { return new self($data); } public function x(): string { return $this->get(self::DATA_X); } public function isPrivate(): bool { return array_key_exists(self::DATA_D, $this->getData()); } public function d(): string { if (! $this->isPrivate()) { throw new InvalidArgumentException('The key is not private.'); } return $this->get(self::DATA_D); } public function curve(): int|string { return $this->get(self::DATA_CURVE); } }