zkidentity

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: ISC Imports: 11 Imported by: 0

Documentation

Overview

zkidentity package manages public and private identities.

Index

Constants

View Source
const (
	IdentitySize = sha256.Size
)

Variables

View Source
var (
	ErrNotEqual = errors.New("not equal")
	ErrVerify   = errors.New("verify error")
)

Functions

func Byte2ID

func Byte2ID(to []byte) (*[32]byte, error)

func Fingerprint

func Fingerprint(id [IdentitySize]byte) string

func IdentityFromPub

func IdentityFromPub(pub *sntrup4591761.PublicKey) *[32]byte

func String2ID

func String2ID(to string) (*[32]byte, error)

Types

type FixedSizeDigest

type FixedSizeDigest = ShortID

FixedSizeDigest is a 32-byte, fixed size sha256 digest.

type FixedSizeEd25519PrivateKey

type FixedSizeEd25519PrivateKey = FixedSizeSignature

FixedSizeEd25519PrivateKey is a 64-byte, fixed size private key.

type FixedSizeEd25519PublicKey

type FixedSizeEd25519PublicKey = ShortID

FixedSizeEd25519PublicKey is a 32-byte, fixed size ed25519 public key.

type FixedSizeSignature

type FixedSizeSignature [64]byte

FixedSizeSignature is a 64-byte, fixed size signature. This is used as an alternative for 64-byte signatures to ensure compact encoding into json.

func (*FixedSizeSignature) FromBytes

func (u *FixedSizeSignature) FromBytes(b []byte) error

FromBytes copies the signature from the given byte slice. The passed slice must have the correct length.

func (*FixedSizeSignature) FromString

func (u *FixedSizeSignature) FromString(s string) error

FromString decodes s into an FixedSizeSignature. s must contain an hex-encoded signature of the correct length.

func (FixedSizeSignature) MarshalJSON

func (u FixedSizeSignature) MarshalJSON() ([]byte, error)

MarshalJSON marshals the id into a json string.

func (FixedSizeSignature) String

func (u FixedSizeSignature) String() string

String returns the hex encoding of the FixedSizeSignature.

func (*FixedSizeSignature) UnmarshalJSON

func (u *FixedSizeSignature) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the json representation of an FixedSizeSignature.

type FixedSizeSntrupCiphertext

type FixedSizeSntrupCiphertext [sntrup4591761.CiphertextSize]byte

FixedSizeSntrupCiphertext is a fixed size byte slice capable of holding a sntrup4591761 cipher text that encodes as an hex string in json.

func (*FixedSizeSntrupCiphertext) FromBytes

func (u *FixedSizeSntrupCiphertext) FromBytes(b []byte) error

FromBytes copies the short id from the given byte slice. The passed slice must have the correct length.

func (*FixedSizeSntrupCiphertext) FromString

func (u *FixedSizeSntrupCiphertext) FromString(s string) error

FromString decodes s into an FixedSizeSntrupCiphertext. s must contain an hex-encoded ID of the correct length.

func (FixedSizeSntrupCiphertext) MarshalJSON

func (u FixedSizeSntrupCiphertext) MarshalJSON() ([]byte, error)

MarshalJSON marshals the id into a json string.

func (FixedSizeSntrupCiphertext) String

func (u FixedSizeSntrupCiphertext) String() string

String returns the hex encoding of the FixedSizeSntrupCiphertext.

func (*FixedSizeSntrupCiphertext) UnmarshalJSON

func (u *FixedSizeSntrupCiphertext) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the json representation of a FixedSizeSntrupCiphertext.

type FixedSizeSntrupPrivateKey

type FixedSizeSntrupPrivateKey [sntrup4591761.PrivateKeySize]byte

FixedSizeSntrupPrivateKey is a fixed size sntrup private key.

func (*FixedSizeSntrupPrivateKey) FromBytes

func (u *FixedSizeSntrupPrivateKey) FromBytes(b []byte) error

FromBytes copies the key from the given byte slice. The passed slice must have the correct length.

func (*FixedSizeSntrupPrivateKey) FromString

func (u *FixedSizeSntrupPrivateKey) FromString(s string) error

FromString decodes s into an FixedSizeSntrupPrivateKey. s must contain an hex-encoded ID of the correct length.

func (FixedSizeSntrupPrivateKey) MarshalJSON

func (u FixedSizeSntrupPrivateKey) MarshalJSON() ([]byte, error)

MarshalJSON marshals the id into a json string.

func (FixedSizeSntrupPrivateKey) String

func (u FixedSizeSntrupPrivateKey) String() string

String returns the hex encoding of the FixedSizeSntrupPrivateKey.

func (*FixedSizeSntrupPrivateKey) UnmarshalJSON

func (u *FixedSizeSntrupPrivateKey) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the json representation of an FixedSizeSntrupPrivateKey.

type FixedSizeSntrupPublicKey

type FixedSizeSntrupPublicKey [sntrup4591761.PublicKeySize]byte

FixedSizeSntrupPublicKey is a fixed size sntrup public key.

func (*FixedSizeSntrupPublicKey) FromBytes

func (u *FixedSizeSntrupPublicKey) FromBytes(b []byte) error

FromBytes copies the key from the given byte slice. The passed slice must have the correct length.

func (*FixedSizeSntrupPublicKey) FromString

func (u *FixedSizeSntrupPublicKey) FromString(s string) error

FromString decodes s into an FixedSizeSntrupPublicKey. s must contain an hex-encoded FixedSizeSntrupPrivateKey of the correct length.

func (FixedSizeSntrupPublicKey) MarshalJSON

func (u FixedSizeSntrupPublicKey) MarshalJSON() ([]byte, error)

MarshalJSON marshals the id into a json string.

func (FixedSizeSntrupPublicKey) String

func (u FixedSizeSntrupPublicKey) String() string

String returns the hex encoding of the FixedSizeSntrupPublicKey.

func (*FixedSizeSntrupPublicKey) UnmarshalJSON

func (u *FixedSizeSntrupPublicKey) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the json representation of an FixedSizeSntrupPublicKey.

type FullIdentity

type FullIdentity struct {
	Public        PublicIdentity             `json:"publicIdentity"`
	PrivateSigKey FixedSizeEd25519PrivateKey `json:"privateSigKey"`
	PrivateKey    FixedSizeSntrupPrivateKey  `json:"privateKey"`
}

func MustNew

func MustNew(name, nick string) *FullIdentity

MustNew generates a new identity or panics.

func New

func New(name, nick string) (*FullIdentity, error)

func NewWithRNG

func NewWithRNG(name, nick string, prng io.Reader) (*FullIdentity, error)

func (*FullIdentity) RecalculateDigest

func (fi *FullIdentity) RecalculateDigest() error

func (FullIdentity) SignMessage

func (fi FullIdentity) SignMessage(message []byte) [ed25519.SignatureSize]byte

type PublicIdentity

type PublicIdentity struct {
	Name      string                    `json:"name"`
	Nick      string                    `json:"nick"`
	SigKey    FixedSizeEd25519PublicKey `json:"sigKey"`
	Key       FixedSizeSntrupPublicKey  `json:"key"`
	Identity  ShortID                   `json:"identity"`
	Digest    FixedSizeDigest           `json:"digest"`    // digest of name, keys and identity
	Signature FixedSizeSignature        `json:"signature"` // signature of Digest
}

A zkc public identity consists of a name and nick (e.g "John Doe" and "jd" respectively), a ed25519 public signature key, and a NTRU Prime public key (used to derive symmetric encryption keys). An extra Identity field, taken as the SHA256 of the NTRU public key, is used as a short handle to uniquely identify a user in various zkc structures.

func (PublicIdentity) Fingerprint

func (p PublicIdentity) Fingerprint() string

func (PublicIdentity) String

func (p PublicIdentity) String() string

func (PublicIdentity) Verify

func (p PublicIdentity) Verify() bool

func (PublicIdentity) VerifyIdentity

func (p PublicIdentity) VerifyIdentity() bool

func (PublicIdentity) VerifyMessage

func (p PublicIdentity) VerifyMessage(msg []byte, sig [ed25519.SignatureSize]byte) bool

type ShortID

type ShortID [32]byte

ShortID is a 32-byte global ID. This is used as an alias for all 32-byte arrays that are interpreted as unique IDs.

func (ShortID) Bytes added in v0.1.4

func (u ShortID) Bytes() []byte

Bytes returns the ID as a slice of bytes.

func (ShortID) ConstantTimeEq

func (u ShortID) ConstantTimeEq(other *ShortID) bool

ConstantTimeEq returns 1 when the two ids are equal. The comparison is done in constant time.

func (*ShortID) FromBytes

func (u *ShortID) FromBytes(b []byte) error

FromBytes copies the short id from the given byte slice. The passed slice must have the correct length.

func (*ShortID) FromString

func (u *ShortID) FromString(s string) error

FromString decodes s into an ShortID. s must contain an hex-encoded ID of the correct length.

func (ShortID) IsEmpty

func (u ShortID) IsEmpty() bool

IsEmpty returns true if the short ID is empty (i.e. all zero).

func (*ShortID) Less

func (u *ShortID) Less(other *ShortID) bool

Less returns whether this is less then the passed ID. other must be non-nil, otherwise this panics. The comparison is made in a big-endian way.

func (ShortID) MarshalJSON

func (u ShortID) MarshalJSON() ([]byte, error)

MarshalJSON marshals the id into a json string.

func (ShortID) ShortLogID

func (u ShortID) ShortLogID() string

ShortLogID returns the first 8 bytes in hex format (16 chars), useful as a short log ID.

func (ShortID) String

func (u ShortID) String() string

String returns the hex encoding of the ShortID.

func (*ShortID) UnmarshalJSON

func (u *ShortID) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the json representation of a ShortID.

Jump to

Keyboard shortcuts

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