aa

package
v1.0.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package aa provides Go functions to access the Authenticated Attributes API.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNeedsKey = errors.New("needs encryption key")
	ErrNotFound = errors.New("requested item not found")
)

Functions

func AddRelationship

func AddRelationship(cid, relType, relationType, relCid string) error

AddRelationship adds a relationship to the database.

relType must be either "children" or "parents".

relationType is the adjective to use, like "related".

See AA docs for details: https://github.com/starlinglab/authenticated-attributes/blob/main/docs/http.md#post-relcid

func AppendAttestation

func AppendAttestation(cid, attr string, val any) error

AppendAttestation appends to an array stored at attr.

See https://github.com/starlinglab/authenticated-attributes/blob/main/docs/http.md#post-ccidattr

func GetAttestationRaw

func GetAttestationRaw(cid, attr string, opts GetAttOpts) ([]byte, error)

GetAttestationRaw returns the raw bytes for the attribute from AA.

If an encryption key was needed (to decrypt value for sig verify) but not provided a ErrNeedsKey is returned. ErrNotFound is returned if the CID-attribute pair doesn't exist in the database.

func GetAttestations

func GetAttestations(cid string) (map[string]*AttEntry, error)

GetAttestations returns all attestations for the provided CID from AA.

func GetCIDs

func GetCIDs() ([]string, error)

GetCIDs returns a slice of all the CIDs stored in the database, as strings.

func IndexListQuery

func IndexListQuery(attr string) ([]string, error)

IndexListQuery queries the AA index for any values that have been indexed for the given attribute.

func IndexMatchQuery

func IndexMatchQuery(attr, val, valType string) ([]string, error)

IndexMatchQuery queries the AA index for any CIDs with the provided attribute-value pair. See the API docs for more information: https://github.com/starlinglab/authenticated-attributes/blob/main/docs/http.md#get-i

func SetAttestations

func SetAttestations(cid string, index bool, kvs []PostKV) error

Types

type AttEntry

type AttEntry struct {
	Signature struct {
		PubKey [32]byte
		Sig    [64]byte
		Msg    CborCID
	}
	Timestamp struct {
		OTS struct {
			Proof    []byte
			Upgraded bool
			Msg      CborCID
		}
	}
	Attestation struct {
		CID       CborCID
		Value     any
		Encrypted bool
		Timestamp time.Time
	}
	Version string
}

Attestation as stored in the database in DAG-CBOR. See https://github.com/starlinglab/authenticated-attributes/blob/main/docs/database.md#schema

This does not encode into the same CBOR it was decoded from, but that's okay as encoding this struct should be not required anywhere.

func GetAttestation

func GetAttestation(cid, attr string, opts GetAttOpts) (*AttEntry, error)

GetAttestation returns the attestation for the provided attribute from AA.

If an encryption key was needed (to decrypt value for sig verify) but not provided a ErrNeedsKey is returned. ErrNotFound is returned if the CID-attribute pair doesn't exist in the database.

The Format fields of `opts` is ignored.

type CborCID

type CborCID []byte

CborCID is a CIDv1 as it is encoded in the DAG-CBOR format.

This is not the same as just the bytes of a CIDv1. See https://ipld.io/specs/codecs/dag-cbor/spec/#links and https://github.com/ipld/cid-cbor

func NewCborCID

func NewCborCID(cid string) (CborCID, error)

NewCborCID takes in a base32 CIDv1 and returns a CborCID, valid for encoding CIDs in DAG-CBOR.

The input CID string is not fully validated and so it is possible for this function to output invalid values.

func (CborCID) MarshalJSON

func (c CborCID) MarshalJSON() (text []byte, err error)

MarshalJSON fulfills the json.Marshaler interface.

It looks like CID(bafy...) which indicates that the value was originally stored in binary rather than a native JSON or string encoding.

func (CborCID) String

func (c CborCID) String() string

String returns the CborCID as a standard base32 CIDv1 string. This fulfills the fmt.Stringer interface, useful for fmt.Print and similar.

type GetAttOpts

type GetAttOpts struct {
	EncKey         []byte
	LeaveEncrypted bool
	Format         string // "cbor", "vc", or "" (cbor)
}

type PostKV

type PostKV struct {
	Key    string `cbor:"key"`
	Value  any    `cbor:"value"`
	Type   string `cbor:"type,omitempty"`
	EncKey []byte `cbor:"encKey,omitempty"` // 32 bytes
}

Attributes for uploading. See https://github.com/starlinglab/authenticated-attributes/blob/main/docs/http.md#post-ccid

Jump to

Keyboard shortcuts

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