core

package module
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2021 License: GPL-3.0 Imports: 11 Imported by: 17

README

go-iden3-core

Go implementation of the iden3 system.

Go Report Card

Install

$ go get github.com/iden3/go-iden3-core

Documentation

Go Modules documentation:

  • GoDoc go-iden3-core

Testing

go test ./...

WARNING

All code here is experimental and WIP

License

go-iden3-core is part of the iden3 project copyright 2018 0kims association and published with GPL-3 license, please check the LICENSE file for more details.

Documentation

Index

Constants

View Source
const (
	SlotNameIndexA = SlotName("IndexA")
	SlotNameIndexB = SlotName("IndexB")
	SlotNameValueA = SlotName("ValueA")
	SlotNameValueB = SlotName("ValueB")
)

Variables

View Source
var ErrDataOverflow = errors.New("data does not fits SNARK size")
View Source
var ErrIncorrectIDPosition = errors.New("incorrect ID position")
View Source
var ErrNoID = errors.New("ID is not set")
View Source
var (

	// TypeBJP0 specifies the BJ-P0
	// - first 2 bytes: `00000000 00000000`
	// - curve of k_op: babyjubjub
	// - hash function: `Poseidon` with 4+4 elements
	TypeBJP0 = [2]byte{0x00, 0x00}
)

Functions

func CalculateChecksum

func CalculateChecksum(typ [2]byte, genesis [27]byte) [2]byte

CalculateChecksum, returns the checksum for a given type and genesis_root, where checksum: hash( [type | root_genesis ] )

func CheckChecksum

func CheckChecksum(id ID) bool

CheckChecksum returns a bool indicating if the ID.Checksum is consistent with the rest of the ID data

func DecomposeID

func DecomposeID(id ID) ([2]byte, [27]byte, [2]byte, error)

DecomposeID returns type, genesis and checksum from an ID

func IdenState

func IdenState(clr *merkletree.Hash, rer *merkletree.Hash, ror *merkletree.Hash) *merkletree.Hash

IdenState calculates the Identity State from the Claims Tree Root, Revocation Tree Root and Roots Tree Root.

Types

type Claim

type Claim struct {
	// contains filtered or unexported fields
}

func NewClaim

func NewClaim(schemaHash SchemaHash, options ...Option) (*Claim, error)

func (*Claim) Clone

func (c *Claim) Clone() *Claim

func (*Claim) GetExpirationDate

func (c *Claim) GetExpirationDate() (time.Time, bool)

GetExpirationDate returns expiration date and flag. Flag is true if expiration date is present, false if null.

func (*Claim) GetFlagUpdatable

func (c *Claim) GetFlagUpdatable() bool

func (*Claim) GetID

func (c *Claim) GetID() (ID, error)

func (*Claim) GetRevocationNonce

func (c *Claim) GetRevocationNonce() uint64

func (*Claim) GetSchemaHash

func (c *Claim) GetSchemaHash() SchemaHash

func (*Claim) GetVersion

func (c *Claim) GetVersion() uint32

func (*Claim) ResetExpirationDate

func (c *Claim) ResetExpirationDate()

func (*Claim) ResetID

func (c *Claim) ResetID()

func (*Claim) SetExpirationDate

func (c *Claim) SetExpirationDate(dt time.Time)

func (*Claim) SetFlagUpdatable

func (c *Claim) SetFlagUpdatable(val bool)

func (*Claim) SetIndexData

func (c *Claim) SetIndexData(slotA, slotB DataSlot) error

func (*Claim) SetIndexDataBytes

func (c *Claim) SetIndexDataBytes(slotA, slotB []byte) error

func (*Claim) SetIndexDataInts

func (c *Claim) SetIndexDataInts(slotA, slotB *big.Int) error

func (*Claim) SetIndexID

func (c *Claim) SetIndexID(id ID)

func (*Claim) SetRevocationNonce

func (c *Claim) SetRevocationNonce(nonce uint64)

func (*Claim) SetSchemaHash

func (c *Claim) SetSchemaHash(schema SchemaHash)

func (*Claim) SetValueData

func (c *Claim) SetValueData(slotA, slotB DataSlot) error

func (*Claim) SetValueDataBytes

func (c *Claim) SetValueDataBytes(slotA, slotB []byte) error

func (*Claim) SetValueDataInts

func (c *Claim) SetValueDataInts(slotA, slotB *big.Int) error

func (*Claim) SetValueID

func (c *Claim) SetValueID(id ID)

func (*Claim) SetVersion

func (c *Claim) SetVersion(ver uint32)

func (*Claim) TreeEntry

func (c *Claim) TreeEntry() merkletree.Entry

type DataSlot

type DataSlot [32]byte

DataSlot length is 253 bits, highest 3 bits should be zeros

func NewDataSlotFromInt

func NewDataSlotFromInt(i *big.Int) (DataSlot, error)

func (*DataSlot) SetInt

func (ds *DataSlot) SetInt(value *big.Int) error

func (DataSlot) ToInt

func (ds DataSlot) ToInt() *big.Int

type ErrSlotOverflow

type ErrSlotOverflow struct {
	Field SlotName
}

func (ErrSlotOverflow) Error

func (e ErrSlotOverflow) Error() string

type ID

type ID [31]byte

ID is a byte array with [ type | root_genesis | checksum ] [2 bytes | 27 bytes | 2 bytes ] where the root_genesis are the first 28 bytes from the hash root_genesis

func CalculateGenesisID

func CalculateGenesisID(clr *merkletree.Hash) (*ID, error)

CalculateGenesisID calculate genesis id based on provided claims tree root

func IDFromBytes

func IDFromBytes(b []byte) (ID, error)

IDFromBytes returns the ID from a given byte array

func IDFromString

func IDFromString(s string) (ID, error)

IDFromString returns the ID from a given string

func IdGenesisFromIdenState

func IdGenesisFromIdenState(hash *merkletree.Hash) *ID

IdGenesisFromIdenState calculates the genesis Id from an Identity State.

func NewID

func NewID(typ [2]byte, genesis [27]byte) ID

NewID creates a new ID from a type and genesis

func (*ID) BigInt

func (id *ID) BigInt() *big.Int

func (*ID) Bytes

func (id *ID) Bytes() []byte

Bytes returns the bytes from the ID

func (*ID) Equal

func (id1 *ID) Equal(id2 *ID) bool

func (*ID) Equals

func (id1 *ID) Equals(id2 *ID) bool

func (ID) MarshalText

func (id ID) MarshalText() ([]byte, error)

func (*ID) String

func (id *ID) String() string

String returns a base58 from the ID

func (*ID) UnmarshalText

func (id *ID) UnmarshalText(b []byte) error

type IDPosition

type IDPosition uint8
const (
	// IDPositionIndex means ID value is in index slots
	IDPositionIndex IDPosition = iota + 1 // value 0 is position undefined
	// IDPositionValue means ID value is in value slots
	IDPositionValue
)

type Option

type Option func(*Claim) error

func WithExpirationDate

func WithExpirationDate(dt time.Time) Option

func WithFlagUpdatable

func WithFlagUpdatable(val bool) Option

func WithID

func WithID(id ID, pos IDPosition) Option

func WithIndexData

func WithIndexData(slotA, slotB DataSlot) Option

func WithIndexDataBytes

func WithIndexDataBytes(slotA, slotB []byte) Option

func WithIndexDataInts

func WithIndexDataInts(slotA, slotB *big.Int) Option

func WithIndexID

func WithIndexID(id ID) Option

func WithRevocationNonce

func WithRevocationNonce(nonce uint64) Option

func WithValueData

func WithValueData(slotA, slotB DataSlot) Option

func WithValueDataBytes

func WithValueDataBytes(slotA, slotB []byte) Option

func WithValueDataInts

func WithValueDataInts(slotA, slotB *big.Int) Option

func WithValueID

func WithValueID(id ID) Option

func WithVersion

func WithVersion(ver uint32) Option

type SchemaHash

type SchemaHash [schemaHashLn]byte

func (SchemaHash) MarshalText

func (sc SchemaHash) MarshalText() ([]byte, error)

type SlotName

type SlotName string

type Subject

type Subject byte
const (
	SubjectSelf           Subject = iota // 000
	SubjectInvalid                       // 001
	SubjectOtherIdenIndex                // 010
	SubjectOtherIdenValue                // 011
	SubjectObjectIndex                   // 100
	SubjectObjectValue                   // 101
)

Jump to

Keyboard shortcuts

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