mini-fair-repo/inc/keys/class-key.php
Ryan McCue f6d211be32 Add Key abstraction class
Signed-off-by: Ryan McCue <me@ryanmccue.info>
2025-06-13 01:56:03 +01:00

62 lines
1.7 KiB
PHP

<?php
namespace MiniFAIR\Keys;
interface Key {
/**
* Does this key represent a private key?
*
* @return bool True if the key is a private keypair, false if it is a public key.
*/
public function is_private() : bool;
/**
* Sign data using the private key.
*
* @param string $data The data to sign, as a hex-encoded string.
* @return string The signature encoded as a hex-encoded string.
*/
public function sign( string $data ) : string;
/**
* Convert a key to a multibase private key string.
*
* @see https://atproto.com/specs/cryptography
*
* @throws Exception If the curve is not supported.
* @return string The multibase private key string (starts with z).
*/
public function encode_public() : string;
/**
* Convert a key to a multibase private key string.
*
* @see https://atproto.com/specs/cryptography
*
* @throws Exception If the curve is not supported.
* @return string The multibase private key string (starts with z).
*/
public function encode_private() : string;
/**
* Convert a multibase public key string to a key.
*
* @see https://atproto.com/specs/cryptography
*
* @throws Exception If the curve is not supported.
* @param string $key The multibase public key string (starts with z).
* @return Key The key object.
*/
public static function from_public( string $key ) : static;
/**
* Convert a multibase private key string to a key.
*
* @see https://atproto.com/specs/cryptography
*
* @throws Exception If the curve is not supported.
* @param string $key The multibase public key string (starts with z).
* @return Key The key object.
*/
public static function from_private( string $key ) : static;
}