Documentation ¶
Overview ¶
Package zkcertificate provides a comprehensive framework for managing zero-knowledge certificates.
Currently, the only one standard is KYC (Know Your Customer) certificate. It encompasses various types and methods designed for creating, validating, and handling certificates, as well as generating Merkle proofs for certificate issuance. The package supports a flexible set of standards, offering a versatile solution for cryptographic certificate management and data privacy. It includes functionality for handling cryptographic operations, certificate content encoding, and validation checks, providing a robust toolkit for privacy-preserving certificate workflows.
Index ¶
- func DID(standard Standard, leafHash Hash) string
- func IsStandard(value string) bool
- func SignCertificate(providerKey babyjub.PrivateKey, contentHash Hash, commitmentHash Hash) (*babyjub.Signature, error)
- func VerifySignature(providerKey *babyjub.PublicKey, contentHash Hash, commitmentHash Hash, ...) (bool, error)
- type Certificate
- type Content
- type FFEncoder
- type Hash
- type HolderCommitment
- type IssuedCertificate
- type KYCContent
- type KYCInputs
- type KYCVerificationLevel
- type ProviderData
- type RegistrationDetails
- type SimpleJSON
- type SimpleJSONContent
- type Standard
- type Timestamp
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DID ¶
DID is a method to generate a Decentralized Identifier (DID) by combining a given standard and leaf hash.
func IsStandard ¶
IsStandard returns true if given value is a valid Standard.
func SignCertificate ¶
func SignCertificate( providerKey babyjub.PrivateKey, contentHash Hash, commitmentHash Hash, ) (*babyjub.Signature, error)
SignCertificate generates a digital signature for a certificate using the provider's private key.
Types ¶
type Certificate ¶
type Certificate[T any] struct { HolderCommitment Hash `json:"holderCommitment"` LeafHash Hash `json:"leafHash"` DID string `json:"did"` Standard Standard `json:"zkCertStandard"` Content T `json:"content"` ContentHash Hash `json:"contentHash"` ExpirationDate Timestamp `json:"expirationDate"` Provider ProviderData `json:"providerData"` RandomSalt string `json:"randomSalt"` }
Certificate represents a zero knowledge certificate structure that can hold different types of content. It is parameterized by the type T for the content field. Certificate content must be directly determined by the certificate Standard.
func New ¶
func New[T Content]( holderCommitment Hash, content T, providerPublicKey *babyjub.PublicKey, providerSignature *babyjub.Signature, salt int64, expirationDate time.Time, ) (*Certificate[T], error)
New creates a new certificate instance with the provided parameters and content. It computes the content hash, verifies if the content was actually signed with providers public key, and generates a leaf hash.
type Content ¶
type Content interface { // Hash computes and returns the Poseidon hash of the certificate content. Hash() (Hash, error) // Standard returns the standard to which the certificate content adheres. Standard() Standard }
Content is an interface that represents the content of a certificate. It defines methods for calculating the content's hash and obtaining the standard it adheres to.
type FFEncoder ¶
type FFEncoder[T Content] interface { // FFEncode performs Finite Field (FF) encoding and returns the result that can be used as certificate content. FFEncode() (T, error) }
FFEncoder is an interface for objects that can perform encoding to Finite Field (FF).
type Hash ¶
Hash represents a cryptographic hash value obtained by Poseidon algorithm.
func HashFromBigInt ¶
HashFromBigInt creates a Hash from a given big.Int value.
func LeafHash ¶
func LeafHash( contentHash Hash, providerPublicKey *babyjub.PublicKey, signature *babyjub.Signature, commitmentHash Hash, salt int64, expirationDate time.Time, ) (Hash, error)
LeafHash computes the hash of a certificate's components and additional data to create a leaf hash.
func (Hash) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Hash) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type HolderCommitment ¶
type HolderCommitment struct { CommitmentHash Hash `json:"holderCommitment" validate:"required"` EncryptionKey []byte `json:"encryptionPubKey" validate:"required,len=32"` }
HolderCommitment represents a structure containing a commitment hash and an encryption key.
func (*HolderCommitment) UnmarshalJSON ¶
func (c *HolderCommitment) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
func (HolderCommitment) Validate ¶
func (c HolderCommitment) Validate() error
Validate performs validation on the HolderCommitment instance using the struct tags specified for field validation. It checks that the fields of the HolderCommitment struct adhere to the defined validation rules.
type IssuedCertificate ¶
type IssuedCertificate[T any] struct { Certificate[T] `json:",inline"` Registration RegistrationDetails `json:"registration"` MerkleProof merkle.Proof `json:"merkleProof"` }
IssuedCertificate represents a certificate that has been issued and includes registration details.
type KYCContent ¶
type KYCContent struct { Surname Hash `json:"surname"` Forename Hash `json:"forename"` MiddleName Hash `json:"middlename"` YearOfBirth uint16 `json:"yearOfBirth"` MonthOfBirth uint8 `json:"monthOfBirth"` DayOfBirth uint8 `json:"dayOfBirth"` VerificationLevel KYCVerificationLevel `json:"verificationLevel"` StreetAndNumber Hash `json:"streetAndNumber"` Postcode Hash `json:"postcode"` Town Hash `json:"town"` Region Hash `json:"region"` Country Hash `json:"country"` Citizenship Hash `json:"citizenship"` }
KYCContent represents the hashed content of KYC (Know Your Customer) data. It contains hashed values for various fields related to identity and verification.
func (KYCContent) Hash ¶
func (c KYCContent) Hash() (Hash, error)
Hash computes and returns the hash of the KYCContent instance.
func (KYCContent) Standard ¶
func (c KYCContent) Standard() Standard
Standard returns the standard associated with the KYCContent, which is StandardKYC.
type KYCInputs ¶
type KYCInputs struct { Surname string `json:"surname" validate:"required"` Forename string `json:"forename" validate:"required"` MiddleName string `json:"middlename" validate:"omitempty"` YearOfBirth uint16 `json:"yearOfBirth" validate:"required"` MonthOfBirth uint8 `json:"monthOfBirth" validate:"required,gte=1,lte=12"` DayOfBirth uint8 `json:"dayOfBirth" validate:"required,gte=1,lte=31"` Citizenship string `json:"citizenship" validate:"required,iso3166_1_alpha3"` VerificationLevel KYCVerificationLevel `json:"verificationLevel"` StreetAndNumber string `json:"streetAndNumber"` Postcode string `json:"postcode"` Town string `json:"town"` Region string `json:"region" validate:"omitempty,iso3166_2"` Country string `json:"country" validate:"required,iso3166_1_alpha3"` }
KYCInputs represents the input data for Know Your Customer (KYC) verification. It contains various fields required for identity verification and validation.
func (KYCInputs) FFEncode ¶
func (k KYCInputs) FFEncode() (KYCContent, error)
FFEncode implements FFEncoder.
func (*KYCInputs) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type KYCVerificationLevel ¶
type KYCVerificationLevel int
KYCVerificationLevel represents the different levels of verification in a KYC (Know Your Customer) process.
const ( KYCVerificationLevelNoKYC KYCVerificationLevel = iota KYCVerificationLevelPassedKYC KYCVerificationLevelQualifiedInvestor )
func (KYCVerificationLevel) MarshalText ¶
func (v KYCVerificationLevel) MarshalText() (text []byte, err error)
MarshalText implements encoding.TextMarshaler.
func (*KYCVerificationLevel) UnmarshalText ¶
func (v *KYCVerificationLevel) UnmarshalText(text []byte) error
UnmarshalText implements encoding.TextUnmarshaler.
type ProviderData ¶
ProviderData represents the public key and signature data of a certificate provider.
func (ProviderData) MarshalJSON ¶
func (p ProviderData) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (*ProviderData) UnmarshalJSON ¶
func (p *ProviderData) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
type RegistrationDetails ¶
type RegistrationDetails struct { Address common.Address `json:"address"` ChainID *big.Int `json:"chainID"` Revocable bool `json:"revocable"` LeafIndex int `json:"leafIndex"` }
RegistrationDetails represents details related to the registration of a certificate.
type SimpleJSON ¶ added in v1.1.0
SimpleJSON represents the input data for data that consists of simple JSON fields: strings only.
func (SimpleJSON) FFEncode ¶ added in v1.1.0
func (c SimpleJSON) FFEncode() (SimpleJSONContent, error)
FFEncode implements FFEncoder.
func (*SimpleJSON) UnmarshalJSON ¶ added in v1.1.0
func (c *SimpleJSON) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
func (*SimpleJSON) Validate ¶ added in v1.1.0
func (c *SimpleJSON) Validate() error
Validate performs validation on the SimpleJSON instance.
type SimpleJSONContent ¶ added in v1.1.0
type SimpleJSONContent []Hash
SimpleJSONContent represents the hashed content of SimpleJSON data. It ordered by the SimpleJSON data key's natural order.
func (SimpleJSONContent) Hash ¶ added in v1.1.0
func (c SimpleJSONContent) Hash() (Hash, error)
Hash computes and returns the hash of the SimpleJSONContent instance.
func (SimpleJSONContent) Standard ¶ added in v1.1.0
func (c SimpleJSONContent) Standard() Standard
Standard returns the standard associated with the SimpleJSONContent, which is StandardSimpleJSON.
type Standard ¶
type Standard string
Standard represents a string that indicates the standard of Zero Knowledge certificates.
func (Standard) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Standard) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Timestamp ¶
Timestamp represents a type that holds a time.Time value that is serialized as Unix timestamp.
func (Timestamp) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Timestamp) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.