derivation

package
v0.0.0-...-a65a15d Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package derivation provides the derivation logic for KERI

Derivaitons are data blobs that have been hashed or encrypted using a pre-defined set of algorithms. These data blobs are used to as the foundation of a variety functionality (for example prefixes) within KERI. Derivaitons are typically represented as Base64 encoded strings with a specific 1, 2 or 4 character prefix, making them self describing. This packages provides an accessible way to encode/decode the data bytes to a given KERI defined derivaiton.

Index

Constants

This section is empty.

Variables

Functions

func Base64ToIndex

func Base64ToIndex(index string) (uint16, error)

Base64ToIndex converts a 2 character base64 index string into an int Currently it only supports index strings up to 2 characters long

func IndexToBase64

func IndexToBase64(index uint16) (string, error)

IndexToBase64 takes the provided index int and converts it to the correct 2 character base64 representation Currently the index has to be less than 4095, which is the max encdoed value for a two character base64 representation

func ParseSignatureCount

func ParseSignatureCount(count string) (uint16, error)

ParseSignatureCount takes a well formated 4 character signature derivation code and returns the decoded count

func VerifyWithAttachedSignature

func VerifyWithAttachedSignature(key, signature *Derivation, msg []byte) error

VerifyWithAttachedSignature takes the key and signature derivations and verifies the provided message bytes using the correct sig alg.

Types

type Code

type Code int
const (
	Ed25519Seed Code = iota
	Ed25519NT
	X25519
	Ed25519
	Blake3256
	Blake2b256
	Blake2s256
	SHA3256
	SHA2256
	RandomSeed128
	Ed25519Sig
	EcDSASig
	Blake3512
	SHA3512
	Blake2b512
	SHA2512
	Ed25519Attached
	EcDSAAttached
)

Code constants represent the available hashing and encryptions algorithms for the derivations.

func (Code) AttachedSignature

func (c Code) AttachedSignature() bool

AttachedSignature derivation

func (Code) Basic

func (c Code) Basic() bool

Basic derivations

func (Code) DataLength

func (c Code) DataLength() int

DataLength of the derived data

func (Code) Default

func (c Code) Default() string

Default derivation data: used for calculating total data length in some KERI functions

func (Code) Length

func (c Code) Length() int

Length of the code representing the derivation (1, 2 or 4)

func (Code) Name

func (c Code) Name() string

Human readable name of the underlying algorithim used in the derivation

func (Code) PrefixBase64Length

func (c Code) PrefixBase64Length() int

PrefixBase64Lenghth of the derived data after it has been bsae64 encoded and the appropriate code has be prepended

func (Code) PrefixDataLength

func (c Code) PrefixDataLength() int

PrefixDataLength of the data with the code prepended

func (Code) SelfAddressing

func (c Code) SelfAddressing() bool

SelfAdressing derivaitons

func (Code) SelfSigning

func (c Code) SelfSigning() bool

SelfSigning derivaitons

func (Code) String

func (c Code) String() string

String returns the 1, 2 or 4 character representation of the encoding. This code string should be pre-pended to a base64 representation of the derived data to make it self-describing

type CountCode

type CountCode int
const (
	ControllerSigCountCode CountCode = iota
	WitnessSigCountCode
	NonTransferableRctCountCode
	TransferableRctCountCode
	FirstSeenReplayCountCode
	MessageDataGroupCountCode
	AttachedMaterialCountCode
	MessageDataMaterialCountCode
	CombinedMaterialCountCode
	MaterialGroupCountCode
	MaterialCountCode

	SigCountLen = 2
)

type CountOpt

type CountOpt func(*Counter) error

func WithCount

func WithCount(count int) CountOpt

type Counter

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

func NewSigCounter

func NewSigCounter(code CountCode, opts ...CountOpt) (*Counter, error)

func (*Counter) Incr

func (r *Counter) Incr() uint16

func (*Counter) IncrBy

func (r *Counter) IncrBy(i uint16) uint16

func (*Counter) String

func (r *Counter) String() (string, error)

type Derivation

type Derivation struct {
	Code Code // The code for this derivation

	Raw      []byte // The Raw derived data
	KeyIndex uint16 // For Attached Signature Derivation - the index of the key for the signature
	// contains filtered or unexported fields
}

Derivation

func FromAttachedSignature

func FromAttachedSignature(sig string) (*Derivation, error)

FromAttachedSignature parses an attached signature and returns the appropriate type. These derivation codes are similar to prefix derivation codes (i.e. they start with similar letters) but are handled differently in the context of an attached signature (namely they are two letter derivation codes but do not start with a "0" like the prefix derivation codes do)

func FromPrefix

func FromPrefix(data string) (*Derivation, error)

FromPrefix takes a prefix as input and returns the appropriate drivation and raw (base64 unencoded) data represented by the prefix.

func New

func New(options ...DerivationOption) (*Derivation, error)

New returns a derivation of the provided Code

func ParseAttachedSignatures

func ParseAttachedSignatures(buf io.Reader) ([]Derivation, error)

ParseAttachedSignatures takes an attached signatures string and parses into individual derivations. This will return any unused bytes that remain after parsing the the number of signatures indicated in the sig count. It will error if there are not enough bytes for the number of signatures, or if any individual signature is not sucessfully parsed.

func ParsePrefix

func ParsePrefix(buf io.Reader) (*Derivation, error)

ParsePrefix takes a prefix as input and returns the appropriate drivation and raw (base64 unencoded) data represented by the prefix.

func (*Derivation) AsPrefix

func (d *Derivation) AsPrefix() string

AsPrefix returns the derivation's raw data as a base 64 encoded string with the correct derivation code prepended

func (*Derivation) Derive

func (d *Derivation) Derive(data []byte) ([]byte, error)

Derive runs the derivation algorithm over the provided bytes returning the derived data

type DerivationOption

type DerivationOption func(*Derivation) error

DerivationOption is a genric configuration function for derivations

func WithCode

func WithCode(code Code) DerivationOption

WithCode allows you to provide a derviation code for the derivation

func WithRaw

func WithRaw(data []byte) DerivationOption

WithRaw allows you to provide raw derivation data

func WithSigner

func WithSigner(signer Signer) DerivationOption

WithSigner uses the provided signing function to do the derivation

type Ordinal

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

func NewOrdinal

func NewOrdinal(val uint16) *Ordinal

func ParseOrdinal

func ParseOrdinal(r io.Reader) (*Ordinal, error)

func (*Ordinal) Base64

func (r *Ordinal) Base64() []byte

func (*Ordinal) Num

func (r *Ordinal) Num() int

type Signer

type Signer func(raw []byte) ([]byte, error)

Signer function for signing self-signing derivations KERI does not want to access any private key data directly. This function can take the provided input bytes, sign it using the appropriate key and return the signed data. The Signer function has the same signature as, and will be used in place of, the deriver

Jump to

Keyboard shortcuts

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