aa

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 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-v1relcid

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-v1ccidattr

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-v1i

func SetAttestations

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

Types

type AttEntry

type AttEntry struct {
	Signature struct {
		PubKey []byte  `json:"pubKey"`
		Sig    []byte  `json:"sig"`
		Msg    CborCID `json:"msg"`
	} `json:"signature"`
	Timestamp struct {
		OTS struct {
			Proof    []byte  `json:"proof"`
			Upgraded bool    `json:"upgraded"`
			Msg      CborCID `json:"msg"`
		} `json:"ots"`
	} `json:"timestamp"`
	Attestation struct {
		CID       CborCID   `json:"CID"`
		Value     any       `json:"value"`
		Attribute string    `json:"attribute"`
		Encrypted bool      `json:"encrypted"`
		Timestamp time.Time `json:"timestamp"`
	} `json:"attestation"`
	Version string `json:"version"`
}

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

This may not encode into the same CBOR it was decoded from, but that's okay as that should not be 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 AuthAttrInstance

type AuthAttrInstance struct {
	Url  string
	Jwt  string
	Mock bool // No network requests go through if true
}

func GetAAInstanceFromConfig

func GetAAInstanceFromConfig() *AuthAttrInstance

func (*AuthAttrInstance) AddRelationship

func (a *AuthAttrInstance) 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-v1relcid

func (*AuthAttrInstance) AppendAttestation

func (a *AuthAttrInstance) 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-v1ccidattr

func (*AuthAttrInstance) GetAttestation

func (a *AuthAttrInstance) 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.

func (*AuthAttrInstance) GetAttestationRaw

func (a *AuthAttrInstance) 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 (*AuthAttrInstance) GetAttestations

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

GetAttestations returns all attestations for the provided CID from AA.

func (*AuthAttrInstance) GetCIDs

func (a *AuthAttrInstance) GetCIDs() ([]string, error)

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

func (*AuthAttrInstance) IndexListQuery

func (a *AuthAttrInstance) IndexListQuery(attr string) ([]string, error)

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

func (*AuthAttrInstance) IndexMatchQuery

func (a *AuthAttrInstance) 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-v1i

func (*AuthAttrInstance) SetAttestations

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

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-v1ccid

Jump to

Keyboard shortcuts

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