claimsstore

package
v0.0.0-...-cda998f Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2020 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LeafNode is string value signifying node is a leaf
	LeafNode = "leafnode"
	// MiddleNode is string value signifying node is not a leaf
	MiddleNode = "middlenode"
)

Variables

View Source
var (
	// PrefixRootMerkleTree prefix value for root tree
	PrefixRootMerkleTree = []byte("root_merkletree")
	// ErrTooLongDIDMethod did to binary is a bit fragile for now, fails when method is more than 15 bytes
	ErrTooLongDIDMethod = errors.New("method string is too long to fit in merkletree elembytes")
	// ErrWrongSizByteSliceDID if the slice is the wrong size can't convert it back to a did
	ErrWrongSizByteSliceDID = errors.New("binaryToDID expects a byte slice of length 32")
)
View Source
var (
	// ErrNoRootCommitForDID is an error for when no root claims are found
	ErrNoRootCommitForDID = errors.New("no rootclaims were in the snapshot")
)

Functions

func Concat

func Concat(vs ...[]byte) []byte

Concat is a internal method from iden3 db that seemed necessary to implement the interface

Types

type JWTClaimPGPersister

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

JWTClaimPGPersister is a postgres persister for JWT claims

func NewJWTClaimPGPersister

func NewJWTClaimPGPersister(db *gorm.DB, didJWTService *didjwt.Service) *JWTClaimPGPersister

NewJWTClaimPGPersister returns a new JWTClaimPGPersister

func (*JWTClaimPGPersister) AddJWT

func (p *JWTClaimPGPersister) AddJWT(tokenString string, senderDID *didlib.DID) (*jwt.Token, string, error)

AddJWT adds a new jwt claim to the db

func (*JWTClaimPGPersister) GetJWTByHash

func (p *JWTClaimPGPersister) GetJWTByHash(hash string) (*jwt.Token, error)

GetJWTByHash returns a jwt from it's hash

func (*JWTClaimPGPersister) GetJWTByMultihash

func (p *JWTClaimPGPersister) GetJWTByMultihash(mHash string) (*jwt.Token, error)

GetJWTByMultihash returns a jwt from it's multihash

func (*JWTClaimPGPersister) GetJWTBySubjectsOrIssuers

func (p *JWTClaimPGPersister) GetJWTBySubjectsOrIssuers(issuers []string,
	subjs []string) ([]*JWTClaimPostgres, error)

GetJWTBySubjectsOrIssuers takes a list of subjects and a list of issuers and returns all dids that match either

type JWTClaimPostgres

type JWTClaimPostgres struct {
	JWT      string `gorm:"not null"`
	Issuer   string `gorm:"not null;index:jwtissuer"`
	Subject  string
	Sender   string `gorm:"not null;index:jwtsender"`
	Hash     string `gorm:"primary_key"`
	Data     string
	Type     string
	IssuedAt int64
}

JWTClaimPostgres is a model for storing jwt type vcs

func TokenToJWTClaimPostgres

func TokenToJWTClaimPostgres(token *jwt.Token) (*JWTClaimPostgres, error)

TokenToJWTClaimPostgres turns a jwt token into the db model

func (JWTClaimPostgres) TableName

func (JWTClaimPostgres) TableName() string

TableName sets the name of the table in the db

type Node

type Node struct {
	gorm.Model
	Prefix       string
	NodeData     string
	NodeKey      string `gorm:"unique_index;not null;"`
	NodeType     string
	DID          string `gorm:"column:did"`
	ClaimType    string
	ClaimVersion uint32
}

Node is node in the merkle tree stored in this table

func (Node) TableName

func (Node) TableName() string

TableName sets the name of the corresponding table in the db

func (*Node) ToDataBytes

func (c *Node) ToDataBytes() ([]byte, error)

ToDataBytes returns just the data stored in the node as a byte slice

func (*Node) ToKV

func (c *Node) ToKV() (db.KV, error)

ToKV converts the node into the KV type used by iden3

func (*Node) UpdateKVAndPrefix

func (c *Node) UpdateKVAndPrefix(kv db.KV, prefix []byte) error

UpdateKVAndPrefix takes a KV and updates the values on the node

type NodePGPersister

type NodePGPersister struct {
	DB *gorm.DB
}

NodePGPersister is a persister for saving the nodes into postgress

func NewNodePGPersisterWithDB

func NewNodePGPersisterWithDB(db *gorm.DB) *NodePGPersister

NewNodePGPersisterWithDB uses an existing gorm.DB struct to create a new GormPGPersister. This is useful if we want to reuse existing connections

func (*NodePGPersister) Batch

func (c *NodePGPersister) Batch(cache *kvMap, prefix []byte) error

Batch updates many nodes at once from the cached kv values used to update all the middle nodes when a leaf is added or changed

func (*NodePGPersister) Get

func (c *NodePGPersister) Get(key []byte) (*Node, error)

Get a node from the db

func (*NodePGPersister) GetAll

func (c *NodePGPersister) GetAll() ([]db.KV, error)

GetAll returns all the nodes in all trees

func (*NodePGPersister) GetAllForPrefix

func (c *NodePGPersister) GetAllForPrefix(prefixBytes []byte, limit int) ([]db.KV, error)

GetAllForPrefix returns the nodes associated with a particular prefix tree

func (*NodePGPersister) GetLatestRootClaimInSnapshot

func (c *NodePGPersister) GetLatestRootClaimInSnapshot(did *didlib.DID,
	tree *merkletree.MerkleTree) (*claimtypes.ClaimSetRootKeyDID, error)

GetLatestRootClaimInSnapshot returns the root claim in the snapshot with the highest version number

func (*NodePGPersister) GetLatestRootClaimNodes

func (c *NodePGPersister) GetLatestRootClaimNodes(did *didlib.DID) (*[]Node, error)

GetLatestRootClaimNodes returns the rootclaims nodes for a did sorted by their version number

func (*NodePGPersister) GetNextRootClaimVersion

func (c *NodePGPersister) GetNextRootClaimVersion(did *didlib.DID) (uint32, error)

GetNextRootClaimVersion gets the next root claim version for a did

func (*NodePGPersister) Info

func (c *NodePGPersister) Info() string

Info returns basic info about the table

type PGStore

type PGStore struct {
	NodePersister *NodePGPersister
	// contains filtered or unexported fields
}

PGStore is an implementation of the iden3 storage interface that uses postgres as its backend

func NewPGStore

func NewPGStore(nodePersister *NodePGPersister) *PGStore

NewPGStore returns a new postgress store

func (PGStore) Close

func (s PGStore) Close()

Close closes the db

func (*PGStore) Get

func (s *PGStore) Get(b []byte) ([]byte, error)

Get gets the data from a node with the given key from the db

func (*PGStore) Info

func (s *PGStore) Info() string

Info prints general information about all trees in the db

func (*PGStore) Iterate

func (s *PGStore) Iterate(f func([]byte, []byte) (bool, error)) error

Iterate performs a function on all nodes in all trees

func (*PGStore) List

func (s *PGStore) List(limit int) ([]db.KV, error)

List lists all nodes for prefix/did

func (*PGStore) NewTx

func (s *PGStore) NewTx() (db.Tx, error)

NewTx creates a new transaction

func (*PGStore) WithPrefix

func (s *PGStore) WithPrefix(prefix []byte) db.Storage

WithPrefix returns a new instance of the pgstore using the passed in prefix

type PGTX

type PGTX struct {
	*PGStore
	// contains filtered or unexported fields
}

PGTX implements the iden3 transaction interface to use a postgress store

func (*PGTX) Add

func (t *PGTX) Add(atx db.Tx)

Add copies all nodes from one transaction to this one

func (*PGTX) Close

func (t *PGTX) Close()

Close deletes the cache of the transaction

func (*PGTX) Commit

func (t *PGTX) Commit() error

Commit writes all nodes in the cache to the db

func (*PGTX) Get

func (t *PGTX) Get(b []byte) ([]byte, error)

Get returns the data from a node that is either in the cache or in the db

func (*PGTX) Put

func (t *PGTX) Put(k, v []byte)

Put adds a new node to the cache

type RootCommit

type RootCommit struct {
	gorm.Model
	Root             string `gorm:"primary_key"`
	BlockNumber      int64
	Prefix           string
	TransactionHash  string
	ContractAddress  string
	CommitterAddress string
}

RootCommit stores information about a root saved to the contract

func (RootCommit) TableName

func (RootCommit) TableName() string

TableName sets the table name for signed claims

type RootCommitsPGPersister

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

RootCommitsPGPersister persister model for root commits

func NewRootCommitsPGPersister

func NewRootCommitsPGPersister(db *gorm.DB) *RootCommitsPGPersister

NewRootCommitsPGPersister returns a new RootCommitsPGPersister

func (*RootCommitsPGPersister) Get

func (p *RootCommitsPGPersister) Get(rootHash string) (*RootCommit, error)

Get returns the information about a root commit given a root hash

func (*RootCommitsPGPersister) GetLatest

func (p *RootCommitsPGPersister) GetLatest() (*RootCommit, error)

GetLatest returns the most recent root committed to the tree

func (*RootCommitsPGPersister) Save

func (p *RootCommitsPGPersister) Save(root *RootCommit) error

Save saves a new root commit to the db

type SignedClaimPGPersister

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

SignedClaimPGPersister persister model for signed claims

func NewSignedClaimPGPersister

func NewSignedClaimPGPersister(db *gorm.DB) *SignedClaimPGPersister

NewSignedClaimPGPersister returns a new SignedClaimPGPersister

func (*SignedClaimPGPersister) AddCredential

func (p *SignedClaimPGPersister) AddCredential(claim claimtypes.Credential) (string, error)

AddCredential takes a credential and adds it to the db

func (*SignedClaimPGPersister) GetCredentialByHash

func (p *SignedClaimPGPersister) GetCredentialByHash(hash string) (claimtypes.Credential,
	error)

GetCredentialByHash returns a credential from a hash taken from the associated merkle tree claim

func (*SignedClaimPGPersister) GetCredentialByMultihash

func (p *SignedClaimPGPersister) GetCredentialByMultihash(mHash string) (claimtypes.Credential,
	error)

GetCredentialByMultihash returns a credential from a multihash

type SignedClaimPostgres

type SignedClaimPostgres struct {
	IssuanceDate      time.Time
	Type              claimtypes.CredentialType
	CredentialSubject postgres.Jsonb `gorm:"not null"`
	Issuer            string         `gorm:"not null;index:issuer"`
	Proof             postgres.Jsonb `gorm:"not null"`
	Hash              string         `gorm:"primary_key"`
}

SignedClaimPostgres represents the schema for signed claims

func (*SignedClaimPostgres) FromContentCredential

func (c *SignedClaimPostgres) FromContentCredential(cred *claimtypes.ContentCredential) error

FromContentCredential populates the db type from a model

func (*SignedClaimPostgres) FromLicenseCredential

func (c *SignedClaimPostgres) FromLicenseCredential(cred *claimtypes.LicenseCredential) error

FromLicenseCredential populates a signed claim postgres model from a license claim

func (SignedClaimPostgres) TableName

func (SignedClaimPostgres) TableName() string

TableName sets the table name for signed claims

func (*SignedClaimPostgres) ToCredential

func (c *SignedClaimPostgres) ToCredential() (claimtypes.Credential, error)

ToCredential converts the db type to the model

Jump to

Keyboard shortcuts

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