zkcertificate

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func DID

func DID(standard Standard, leafHash Hash) string

DID is a method to generate a Decentralized Identifier (DID) by combining a given standard and leaf hash.

func IsStandard

func IsStandard(value string) bool

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.

func VerifySignature

func VerifySignature(
	providerKey *babyjub.PublicKey,
	contentHash Hash,
	commitmentHash Hash,
	signature *babyjub.Signature,
) (bool, error)

VerifySignature verifies the digital signature of a certificate using the provider's public 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"`
	Provider         ProviderData `json:"providerData"`
	RandomSalt       int64        `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,
) (*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

type Hash big.Int

Hash represents a cryptographic hash value obtained by Poseidon algorithm.

func HashFromBigInt

func HashFromBigInt(n *big.Int) Hash

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,
) (Hash, error)

LeafHash computes the hash of a certificate's components and additional data to create a leaf hash.

func (Hash) BigInt

func (h Hash) BigInt() *big.Int

BigInt converts a Hash value to a big.Int.

func (Hash) Bytes32

func (h Hash) Bytes32() [32]byte

Bytes32 converts a Hash value to a 32-byte array.

func (Hash) MarshalText

func (h Hash) MarshalText() (text []byte, err error)

MarshalText implements encoding.TextMarshaler.

func (Hash) String

func (h Hash) String() string

String returns the string representation of the Hash value.

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(text []byte) error

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      uint16               `json:"monthOfBirth"`
	DayOfBirth        uint16               `json:"dayOfBirth"`
	VerificationLevel KYCVerificationLevel `json:"verificationLevel"`
	ExpirationDate    Timestamp            `json:"expirationDate"`
	StreetAndNumber   Hash                 `json:"streetAndNumber"`
	Postcode          Hash                 `json:"postcode"`
	Town              Hash                 `json:"town"`
	Region            Hash                 `json:"region"`
	Country           Hash                 `json:"country"`
	Citizenship       Hash                 `json:"citizenship"`
	PassportID        Hash                 `json:"passportID"`
}

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      uint16               `json:"monthOfBirth" validate:"required,gte=1,lte=12"`
	DayOfBirth        uint16               `json:"dayOfBirth" validate:"required,gte=1,lte=31"`
	Citizenship       string               `json:"citizenship" validate:"required,iso3166_1_alpha3"`
	VerificationLevel KYCVerificationLevel `json:"verificationLevel"`
	ExpirationDate    Timestamp            `json:"expirationDate"`
	StreetAndNumber   string               `json:"streetAndNumber" validate:"required"`
	Postcode          string               `json:"postcode" validate:"required"`
	Town              string               `json:"town" validate:"required"`
	Region            string               `json:"region" validate:"omitempty,iso3166_2"`
	Country           string               `json:"country" validate:"required,iso3166_1_alpha3"`
	PassportID        string               `json:"passportID" validate:"required"`
}

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

func (k *KYCInputs) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*KYCInputs) Validate

func (k *KYCInputs) Validate() error

Validate performs validation on the KYCInputs instance using the struct tags specified for field validation. It checks that the fields of the KYCInputs struct adhere to the defined validation rules.

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

type ProviderData struct {
	PublicKey babyjub.PublicKey
	Signature babyjub.Signature
}

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"`
	Revocable bool           `json:"revocable"`
	LeafIndex int            `json:"leafIndex"`
}

RegistrationDetails represents details related to the registration of a certificate.

type Standard

type Standard string

Standard represents a string that indicates the standard of Zero Knowledge certificates.

const StandardKYC Standard = "gip69"

func (Standard) MarshalText

func (s Standard) MarshalText() (text []byte, err error)

MarshalText implements encoding.TextMarshaler.

func (Standard) String

func (s Standard) String() string

String returns the string representation of the Standard value.

func (*Standard) UnmarshalText

func (s *Standard) UnmarshalText(value []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Timestamp

type Timestamp time.Time

Timestamp represents a type that holds a time.Time value that is serialized as Unix timestamp.

func (Timestamp) MarshalJSON

func (t Timestamp) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Timestamp) Unix

func (t Timestamp) Unix() int64

Unix returns the Unix timestamp of the Timestamp.

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(bytes []byte) error

UnmarshalJSON implements json.Unmarshaler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL