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 CEXContent
- type CEXInputs
- type Certificate
- type Content
- type DEXContent
- type DEXInputs
- type EncryptedCertificate
- type FFEncoder
- type Hash
- type HolderCommitment
- type IssuedCertificate
- type KYCContent
- type KYCInputs
- type KYCVerificationLevel
- type ProviderData
- type REYContent
- type REYInputs
- type RegistrationDetails
- type SimpleJSON
- type SimpleJSONContent
- type Standard
- type TelegramContent
- type TelegramInputs
- type Timestamp
- type TwitterContent
- type TwitterInputs
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 CEXContent ¶ added in v1.11.0
type CEXContent struct { TotalSwapVolume *big.Int `json:"totalSwapVolume"` SwapVolumeYear *big.Int `json:"swapVolumeYear"` SwapVolumeHalfYear *big.Int `json:"swapVolumeHalfYear"` }
CEXContent represent the hashed content of CEXInputs data.
func (CEXContent) Hash ¶ added in v1.11.0
func (u CEXContent) Hash() (Hash, error)
Hash implements Content.
func (CEXContent) Standard ¶ added in v1.11.0
func (u CEXContent) Standard() Standard
Standard implements Content. It always returns StandardCEX.
type CEXInputs ¶ added in v1.11.0
type CEXInputs struct { TotalSwapVolume decimal.Decimal `json:"totalSwapVolume" validate:"required,decimal_gt_0"` SwapVolumeYear decimal.Decimal `json:"swapVolumeYear"` SwapVolumeHalfYear decimal.Decimal `json:"swapVolumeHalfYear"` }
CEXInputs represent the input data for verification of trading on a centralized exchange.
func (*CEXInputs) FFEncode ¶ added in v1.11.0
func (u *CEXInputs) FFEncode() (CEXContent, error)
FFEncode implements FFEncoder.
func (*CEXInputs) UnmarshalJSON ¶ added in v1.11.0
UnmarshalJSON implements json.Unmarshaler.
type Certificate ¶
type Certificate[T Content] 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 DeserializeCertificateJSON ¶ added in v1.8.1
func DeserializeCertificateJSON(r io.Reader) (Certificate[Content], error)
DeserializeCertificateJSON deserializes Certificate from the given io.Reader. As it is not possible to determine type of content in compile time, the returned content type is always Content.
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 DEXContent ¶ added in v1.11.0
type DEXContent struct { Address Hash `json:"address"` TotalSwapVolume *big.Int `json:"totalSwapVolume"` SwapVolumeYear *big.Int `json:"swapVolumeYear"` SwapVolumeHalfYear *big.Int `json:"swapVolumeHalfYear"` }
DEXContent represent the hashed content of DEXInputs data.
func (DEXContent) Hash ¶ added in v1.11.0
func (u DEXContent) Hash() (Hash, error)
Hash implements Content.
func (DEXContent) Standard ¶ added in v1.11.0
func (u DEXContent) Standard() Standard
Standard implements Content. It always returns StandardDEX.
type DEXInputs ¶ added in v1.11.0
type DEXInputs struct { Address string `json:"address" validate:"required,eth_addr"` TotalSwapVolume decimal.Decimal `json:"totalSwapVolume"` SwapVolumeYear decimal.Decimal `json:"swapVolumeYear"` SwapVolumeHalfYear decimal.Decimal `json:"swapVolumeHalfYear"` }
DEXInputs represent the input data for verification of trading on a decentralized exchange.
func (*DEXInputs) FFEncode ¶ added in v1.11.0
func (u *DEXInputs) FFEncode() (DEXContent, error)
FFEncode implements FFEncoder.
func (*DEXInputs) UnmarshalJSON ¶ added in v1.11.0
UnmarshalJSON implements json.Unmarshaler.
type EncryptedCertificate ¶ added in v1.8.0
type EncryptedCertificate struct { encryption.EncryptedMessage `json:",inline"` HolderCommitment Hash `json:"holderCommitment"` }
EncryptedCertificate is a Certificate that has been encrypted.
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 Content] 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.
func DeserializeIssuedCertificateJSON ¶ added in v1.8.1
func DeserializeIssuedCertificateJSON(r io.Reader) (IssuedCertificate[Content], error)
DeserializeIssuedCertificateJSON deserializes IssuedCertificate from the given io.Reader. As it is not possible to determine type of content in compile time, the returned content type is always Content.
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) IDHash ¶ added in v1.6.0
func (c *KYCContent) IDHash() (Hash, error)
IDHash computes and returns a user's ID hash for registration of the HumanID salt hash.
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 REYContent ¶ added in v1.6.0
type REYContent struct { XID Hash `json:"x_id"` XUsername Hash `json:"x_username"` REYScoreAll uint `json:"rey_score_all"` REYScoreGalactica uint `json:"rey_score_galactica"` REYFaction uint `json:"rey_faction"` }
REYContent represents the hashed content of REYInputs data.
func (REYContent) Hash ¶ added in v1.6.0
func (c REYContent) Hash() (Hash, error)
Hash implements Content.
func (REYContent) Standard ¶ added in v1.6.0
func (c REYContent) Standard() Standard
Standard implements Content. It always returns StandardREY.
type REYInputs ¶ added in v1.6.0
type REYInputs struct { XID string `json:"x_id" validate:"required,number"` XUsername string `json:"x_username" validate:"required,min=4,max=15"` REYScoreAll uint `json:"rey_score_all"` REYScoreGalactica uint `json:"rey_score_galactica"` REYFaction uint `json:"rey_faction"` }
REYInputs represents the input data for the REY verification.
func (*REYInputs) FFEncode ¶ added in v1.6.0
func (r *REYInputs) FFEncode() (REYContent, error)
FFEncode implements FFEncoder.
func (*REYInputs) UnmarshalJSON ¶ added in v1.6.0
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 TelegramContent ¶ added in v1.13.0
type TelegramContent struct { ActiveDaysCount uint `json:"activeDaysCount"` ContactWithAtLeast10MessagesCount uint `json:"contactWithAtLeast10MessagesCount"` CreatedAt int64 `json:"createdAt"` MeanMonthlyMessageCount uint `json:"meanMonthlyMessageCount"` }
TelegramContent represents the hashed content of TelegramInputs data.
func (TelegramContent) Hash ¶ added in v1.13.0
func (t TelegramContent) Hash() (Hash, error)
Hash implements Content.
func (TelegramContent) Standard ¶ added in v1.13.0
func (t TelegramContent) Standard() Standard
Standard implements Content. It always returns StandardTelegram.
type TelegramInputs ¶ added in v1.13.0
type TelegramInputs struct { ActiveDaysCount uint `json:"activeDaysCount" validate:"required"` ContactWithAtLeast10MessagesCount uint `json:"contactWithAtLeast10MessagesCount"` CreatedAt time.Time `json:"createdAt" validate:"required,lt"` MeanMonthlyMessageCount uint `json:"meanMonthlyMessageCount" validate:"required"` }
TelegramInputs represents the input data for verification of Telegram account.
func (TelegramInputs) FFEncode ¶ added in v1.13.0
func (t TelegramInputs) FFEncode() (TelegramContent, error)
FFEncode implements FFEncoder.
func (*TelegramInputs) UnmarshalJSON ¶ added in v1.13.0
func (t *TelegramInputs) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
func (*TelegramInputs) Validate ¶ added in v1.13.0
func (t *TelegramInputs) Validate() error
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.
type TwitterContent ¶ added in v1.6.0
type TwitterContent struct { CreatedAt int64 `json:"createdAt"` ID Hash `json:"id"` FollowersCount uint `json:"followersCount"` FollowingCount uint `json:"followingCount"` ListedCount uint `json:"listedCount"` TweetCount uint `json:"tweetCount"` Username Hash `json:"username"` Verified bool `json:"verified"` }
TwitterContent represents the hashed content of TwitterInputs data.
func (TwitterContent) Hash ¶ added in v1.6.0
func (t TwitterContent) Hash() (Hash, error)
Hash implements Content.
func (TwitterContent) Standard ¶ added in v1.6.0
func (t TwitterContent) Standard() Standard
Standard implements Content. It always returns StandardTwitter.
type TwitterInputs ¶ added in v1.6.0
type TwitterInputs struct { CreatedAt time.Time `json:"createdAt" validate:"required,lt"` ID string `json:"id" validate:"required,number"` FollowersCount uint `json:"followersCount"` FollowingCount uint `json:"followingCount"` ListedCount uint `json:"listedCount"` TweetCount uint `json:"tweetCount"` Username string `json:"username" validate:"required,min=4,max=15"` Verified bool `json:"verified"` }
TwitterInputs represents the input data for X/Twitter verification.
func (TwitterInputs) FFEncode ¶ added in v1.6.0
func (t TwitterInputs) FFEncode() (TwitterContent, error)
FFEncode implements FFEncoder.
func (*TwitterInputs) UnmarshalJSON ¶ added in v1.6.0
func (t *TwitterInputs) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
func (*TwitterInputs) Validate ¶ added in v1.6.0
func (t *TwitterInputs) Validate() error