2025-06-19 18:17:54 +02:00
|
|
|
package crypto
|
|
|
|
|
|
2025-07-03 15:55:58 +02:00
|
|
|
// Public Key
|
|
|
|
|
|
2025-06-19 18:17:54 +02:00
|
|
|
type PublicKey interface {
|
2025-06-24 14:05:42 +02:00
|
|
|
// Equal returns true if other is the same PublicKey
|
2025-06-19 18:17:54 +02:00
|
|
|
Equal(other PublicKey) bool
|
|
|
|
|
|
2025-06-24 14:05:42 +02:00
|
|
|
// ToPublicKeyMultibase format the PublicKey into a string compatible with a PublicKeyMultibase field
|
|
|
|
|
// in a DID Document.
|
2025-06-19 18:17:54 +02:00
|
|
|
ToPublicKeyMultibase() string
|
2025-06-24 14:05:42 +02:00
|
|
|
|
|
|
|
|
// ToX509DER serializes the PublicKey into the X.509 DER (binary) format.
|
2025-06-19 18:17:54 +02:00
|
|
|
ToX509DER() []byte
|
2025-06-24 14:05:42 +02:00
|
|
|
|
|
|
|
|
// ToX509PEM serializes the PublicKey into the X.509 PEM (string) format.
|
2025-06-19 18:17:54 +02:00
|
|
|
ToX509PEM() string
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-03 15:55:58 +02:00
|
|
|
type PublicKeyToBytes interface {
|
|
|
|
|
PublicKey
|
|
|
|
|
|
|
|
|
|
// ToBytes serializes the PublicKey into "raw bytes", without metadata or structure.
|
|
|
|
|
// This format can make some assumptions and may not be what you expect.
|
|
|
|
|
// Ideally, this format is defined by the same specification as the underlying crypto scheme.
|
|
|
|
|
ToBytes() []byte
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type PublicKeySigning interface {
|
|
|
|
|
PublicKey
|
|
|
|
|
|
|
|
|
|
// VerifyBytes checks a signature in the "raw bytes" format.
|
|
|
|
|
// This format can make some assumptions and may not be what you expect.
|
|
|
|
|
// Ideally, this format is defined by the same specification as the underlying crypto scheme.
|
|
|
|
|
VerifyBytes(message, signature []byte) bool
|
|
|
|
|
|
|
|
|
|
// VerifyASN1 checks a signature in the ASN.1 format.
|
|
|
|
|
VerifyASN1(message, signature []byte) bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Private Key
|
|
|
|
|
|
2025-06-19 18:17:54 +02:00
|
|
|
type PrivateKey interface {
|
2025-06-24 14:05:42 +02:00
|
|
|
// Equal returns true if other is the same PrivateKey
|
2025-06-19 18:17:54 +02:00
|
|
|
Equal(other PrivateKey) bool
|
2025-06-24 14:05:42 +02:00
|
|
|
|
|
|
|
|
// Public returns the matching PublicKey.
|
2025-06-19 18:17:54 +02:00
|
|
|
Public() PublicKey
|
|
|
|
|
|
2025-06-24 14:05:42 +02:00
|
|
|
// ToPKCS8DER serializes the PrivateKey into the PKCS#8 DER (binary) format.
|
2025-06-19 18:17:54 +02:00
|
|
|
ToPKCS8DER() []byte
|
2025-06-24 14:05:42 +02:00
|
|
|
|
|
|
|
|
// ToPKCS8PEM serializes the PrivateKey into the PKCS#8 PEM (string) format.
|
2025-06-19 18:17:54 +02:00
|
|
|
ToPKCS8PEM() string
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-03 15:55:58 +02:00
|
|
|
type PrivateKeyToBytes interface {
|
|
|
|
|
PrivateKey
|
2025-06-19 18:17:54 +02:00
|
|
|
|
2025-07-03 15:55:58 +02:00
|
|
|
// ToBytes serializes the PrivateKey into "raw bytes", without metadata or structure.
|
2025-06-24 14:05:42 +02:00
|
|
|
// This format can make some assumptions and may not be what you expect.
|
|
|
|
|
// Ideally, this format is defined by the same specification as the underlying crypto scheme.
|
2025-07-03 15:55:58 +02:00
|
|
|
ToBytes() []byte
|
2025-06-19 18:17:54 +02:00
|
|
|
}
|
|
|
|
|
|
2025-07-03 15:55:58 +02:00
|
|
|
type PrivateKeySigning interface {
|
2025-06-19 18:17:54 +02:00
|
|
|
PrivateKey
|
|
|
|
|
|
2025-06-24 14:05:42 +02:00
|
|
|
// SignToBytes creates a signature in the "raw bytes" format.
|
|
|
|
|
// This format can make some assumptions and may not be what you expect.
|
|
|
|
|
// Ideally, this format is defined by the same specification as the underlying crypto scheme.
|
2025-06-23 14:13:48 +02:00
|
|
|
SignToBytes(message []byte) ([]byte, error)
|
2025-06-24 14:05:42 +02:00
|
|
|
|
|
|
|
|
// SignToASN1 creates a signature in the ASN.1 format.
|
2025-06-23 14:13:48 +02:00
|
|
|
SignToASN1(message []byte) ([]byte, error)
|
2025-06-19 18:17:54 +02:00
|
|
|
}
|
|
|
|
|
|
2025-07-03 15:55:58 +02:00
|
|
|
type PrivateKeyKeyExchange interface {
|
2025-06-24 14:05:42 +02:00
|
|
|
PrivateKey
|
2025-06-19 18:17:54 +02:00
|
|
|
|
2025-06-24 14:05:42 +02:00
|
|
|
// PublicKeyIsCompatible checks that the given PublicKey is compatible to perform key exchange.
|
|
|
|
|
PublicKeyIsCompatible(remote PublicKey) bool
|
2025-06-19 18:17:54 +02:00
|
|
|
|
2025-06-24 14:05:42 +02:00
|
|
|
// KeyExchange computes the shared key using the given PublicKey.
|
|
|
|
|
KeyExchange(remote PublicKey) ([]byte, error)
|
2025-06-19 18:17:54 +02:00
|
|
|
}
|