api

package
Version: v0.9.10 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2021 License: GPL-3.0 Imports: 46 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = fmt.Errorf("artifact is not found")

ErrNotVerified is returned when an artifact is not found on CNLC

View Source
var ErrNotVerified = fmt.Errorf("artifact is not verified")

ErrNotVerified is returned when an artifact is not verified on CNLC

View Source
var WrongPassphraseErr = goErr.New("incorrect notarization password")

Functions

func AppendAttachment added in v0.9.5

func AppendAttachment(attachHash string, key []byte) []byte

func AppendLabel added in v0.9.7

func AppendLabel(label string, key []byte) []byte

func AppendPrefix added in v0.9.0

func AppendPrefix(prefix string, key []byte) []byte

func AppendSignerId added in v0.9.0

func AppendSignerId(signerId string, k []byte) []byte

func GetSignerIDByApiKey added in v0.9.4

func GetSignerIDByApiKey(lcApiKey string) string

func GetUserFromContext added in v0.9.0

func GetUserFromContext(context store.CurrentContext, lcApiKey string, lcLedger string, signingPubKey *ecdsa.PublicKey) (interface{}, error)

GetUserFromContext returns a new the correct user based on the context

func LatestCLIVersion added in v0.6.0

func LatestCLIVersion() (string, string, error)

LatestCLIVersion returns the version string and message of the latest `vcn` CLI release.

func NewLcClient added in v0.9.0

func NewLcClient(lcApiKey, lcLedger, host, port, lcCertPath string, skipTlsVerify, noTls bool, signingPubKey *ecdsa.PublicKey) (*sdk.LcClient, error)

func NewLcClientByContext added in v0.9.1

func NewLcClientByContext(context store.CurrentContext, lcApiKey string, lcLedger string, signingPubKey *ecdsa.PublicKey) (*sdk.LcClient, error)

func TrackPublisher

func TrackPublisher(user *User, event string) (err error)

TrackPublisher is deprecated and will be removed

func TrackSign

func TrackSign(user *User, hash string, filename string, status meta.Status) (err error)

TrackSign is deprecated and will be removed

func TrackVerify

func TrackVerify(user *User, hash string, filename string) (err error)

TrackVerify is deprecated and will be removed

Types

type AlertConfig added in v0.8.0

type AlertConfig struct {
	AlertUUID string   `json:"alertUuid" yaml:"alertUUID"`
	Metadata  Metadata `json:"metadata,omitempty" yaml:"metadata"`
}

AlertConfig represents a platform alert configuration.

type AlertResponse added in v0.8.0

type AlertResponse struct {
	ArtifactHash     string   `json:"artifactHash,omitempty"`
	ArtifactMetaHash string   `json:"artifactMetaHash,omitempty"`
	Email            string   `json:"email,omitempty"`
	Enabled          bool     `json:"enabled"`
	Metadata         Metadata `json:"metadata,omitempty"`
	Name             string   `json:"name"`
	UnAcknowledged   bool     `json:"unAcknowledgedNotification"`
	UUID             string   `json:"uuid,omitempty"`
}

AlertResponse holds alert values returned by the platform.

type Artifact

type Artifact struct {
	Kind        string
	Name        string
	Hash        string
	Size        uint64
	ContentType string
	IncludedIn  []PackageDetails
	Deps        []PackageDetails
	Metadata
}

Artifact represents the set of all relevant information gathered from a digital asset.

func (Artifact) Copy added in v0.5.2

func (a Artifact) Copy() Artifact

Copy returns a deep copy of the artifact.

type ArtifactResponse

type ArtifactResponse struct {
	// root fields
	Kind        string `json:"kind" yaml:"kind" vcn:"Kind"`
	Name        string `json:"name" yaml:"name" vcn:"Name"`
	Hash        string `json:"hash" yaml:"hash" vcn:"Hash"`
	Size        uint64 `json:"size" yaml:"size" vcn:"Size"`
	ContentType string `json:"contentType" yaml:"contentType" vcn:"ContentType"`
	URL         string `json:"url" yaml:"url" vcn:"URL"`

	// custom metadata
	Metadata Metadata `json:"metadata" yaml:"metadata" vcn:"Metadata"`

	// ArtifactResponse specific
	Level             int64  `json:"level,omitempty" yaml:"level,omitempty"`
	Status            string `json:"status,omitempty" yaml:"status,omitempty"`
	Visibility        string `json:"visibility" yaml:"visibility" vcn:"Visibility"`
	CreatedAt         string `json:"createdAt" yaml:"createdAt"`
	VerificationCount uint64 `json:"verificationCount" yaml:"verificationCount"`
	SignerCount       uint64 `json:"signerCount" yaml:"signerCount"`
	Signer            string `json:"signer" yaml:"signer" vcn:"Signer"`
	Company           string `json:"company" yaml:"company" vcn:"Company"`
	Website           string `json:"website" yaml:"website" vcn:"Website"`
}

ArtifactResponse holds artifact values returned by the platform.

func LoadArtifact added in v0.6.0

func LoadArtifact(user *User, hash string, metahash string) (*ArtifactResponse, error)

LoadArtifact fetches and returns an artifact matching the given hash and optionally a given metahash. Returned values depends on user permissions on the artifact, if user is nil then only publicly disclosable values are returned.

func (ArtifactResponse) Artifact

func (a ArtifactResponse) Artifact() *Artifact

Artifact returns an new *Artifact from a

func (ArtifactResponse) String

func (a ArtifactResponse) String() string

type Attachment added in v0.9.5

type Attachment struct {
	Filename string `json:"filename" yaml:"filename" vcn:"filename"`
	Hash     string `json:"hash" yaml:"hash" vcn:"hash"`
	Mime     string `json:"mime" yaml:"mime" vcn:"mime"`
	Label    string `json:"label" yaml:"label" vcn:"label"`
}

Attachment holds Attachment attributes

type BlockchainOrganisation

type BlockchainOrganisation struct {
	Owner     common.Address   `json:"owner"`
	Members   []common.Address `json:"members"`
	Hash      string           `json:"hash"`
	Timestamp time.Time        `json:"timestamp"`
}

BlockchainOrganisation represents the organization data stored onto the blockchain.

func GetBlockChainOrganisation added in v0.6.0

func GetBlockChainOrganisation(name string) (*BlockchainOrganisation, error)

GetBlockChainOrganisation returns a BlockchainOrganisation for the organization name, if any. It returns a nil value and an error if the organization is not found.

func (*BlockchainOrganisation) MembersIDs added in v0.6.0

func (o *BlockchainOrganisation) MembersIDs() []string

MembersIDs returns org members' IDs (SignerIDs) as slice of strings for o, if any, otherwise a zero-len slice

func (*BlockchainOrganisation) OwnerID added in v0.6.0

func (o *BlockchainOrganisation) OwnerID() string

OwnerID returns org owner's public address as string for o, if any, otherwise an empty string

type BlockchainVerification

type BlockchainVerification struct {
	Owner     common.Address `json:"owner" yaml:"owner"`
	Level     meta.Level     `json:"level" yaml:"level"`
	Status    meta.Status    `json:"status" yaml:"status"`
	Timestamp time.Time      `json:"timestamp" yaml:"timestamp"`
}

BlockchainVerification represents the notarized data onto the blockchain.

func BlockChainInspect added in v0.5.1

func BlockChainInspect(hash string) ([]BlockchainVerification, error)

BlockChainInspect returns an array of BlockchainVerification containing all verifications found for the given hash

func Verify added in v0.6.0

func Verify(hash string) (*BlockchainVerification, error)

Verify returns the most recent *BlockchainVerification with highest level available for the given hash.

func VerifyMatchingSignerID added in v0.6.0

func VerifyMatchingSignerID(hash string, signerID string) (*BlockchainVerification, error)

VerifyMatchingSignerID returns *BlockchainVerification for hash matching a given SignerID.

func VerifyMatchingSignerIDWithFallback added in v0.6.2

func VerifyMatchingSignerIDWithFallback(hash string, signerID string) (*BlockchainVerification, error)

VerifyMatchingSignerIDWithFallback returns *BlockchainVerification for the hash matching a given SignerID, if any, otherwise it returns the same result of Verify().

func VerifyMatchingSignerIDs added in v0.6.0

func VerifyMatchingSignerIDs(hash string, signerIDs []string) (*BlockchainVerification, error)

VerifyMatchingSignerIDs returns *BlockchainVerification for hash matching at least one of signerIDs.

func (*BlockchainVerification) Date

func (v *BlockchainVerification) Date() string

Date returns a RFC3339 formatted string of verification time (v.Timestamp), if any, otherwise an empty string.

func (*BlockchainVerification) MarshalJSON

func (v *BlockchainVerification) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*BlockchainVerification) MarshalYAML

func (v *BlockchainVerification) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface.

func (*BlockchainVerification) MetaHash

func (v *BlockchainVerification) MetaHash() string

MetaHash returns the SHA256 digest of BlockchainVerification's data. The returned value uniquely identify a single notarization.

func (*BlockchainVerification) SignerID added in v0.6.0

func (v *BlockchainVerification) SignerID() string

SignerID returns the public address derived from owner's public key (v.Owner), if any, otherwise an empty string.

func (*BlockchainVerification) Trusted

func (v *BlockchainVerification) Trusted() bool

Trusted returns true if v.Status is meta.StatusTrusted

func (*BlockchainVerification) Unknown

func (v *BlockchainVerification) Unknown() bool

Unknown returns true if v is nil or v.Status is meta.StatusUnknown

func (*BlockchainVerification) UnmarshalJSON added in v0.5.1

func (v *BlockchainVerification) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*BlockchainVerification) UnmarshalYAML added in v0.7.0

func (v *BlockchainVerification) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type Error

type Error struct {
	Description string   `json:"description"`
	Status      int      `json:"status"`
	Message     string   `json:"message"`
	Path        string   `json:"path"`
	Timestamp   string   `json:"timestamp"`
	Error       string   `json:"error"`
	FieldErrors []string `json:"fieldErrors"`
}

Error represents a CodeNotary platform's API returned error.

type LcArtifact added in v0.9.0

type LcArtifact struct {
	// root fields
	Uid         string    `json:"uid" yaml:"uid" vcn:"UID"`
	Kind        string    `json:"kind" yaml:"kind" vcn:"Kind"`
	Name        string    `json:"name" yaml:"name" vcn:"Name"`
	Hash        string    `json:"hash" yaml:"hash" vcn:"Hash"`
	Size        uint64    `json:"size" yaml:"size" vcn:"Size"`
	Timestamp   time.Time `json:"timestamp,omitempty" yaml:"timestamp" vcn:"Timestamp"`
	ContentType string    `json:"contentType" yaml:"contentType" vcn:"ContentType"`

	// custom metadata
	Metadata    Metadata     `json:"metadata" yaml:"metadata" vcn:"Metadata"`
	Attachments []Attachment `json:"attachments" yaml:"attachments" vcn:"Attachments"`

	Signer  string      `json:"signer" yaml:"signer" vcn:"SignerID"`
	Revoked *time.Time  `json:"revoked,omitempty" yaml:"revoked" vcn:"Apikey revoked"`
	Status  meta.Status `json:"status" yaml:"status" vcn:"Status"`
	Ledger  string      `json:"ledger,omitempty" yaml:"ledger"`

	IncludedIn []PackageDetails `json:"included_in,omitempty" yaml:"included_in,omitempty" vcn:"Included in"`
	Deps       []PackageDetails `json:"bom,omitempty" yaml:"bom,omitempty" vcn:"Dependencies"`
}

func ItemToLcArtifact added in v0.9.0

func ItemToLcArtifact(item *schema.ItemExt) (*LcArtifact, error)

func LcVerifyEnv added in v0.9.5

func LcVerifyEnv(hash, lcLedger, signerID string) (a *LcArtifact, err error)

PublicCNLCVerify allow connection and verification on CNLC ledger with a single call using environment variables. LcLedger parameter is used when a cross-ledger key is provided in order to specify the ledger on which future operations will be directed. Empty string is accepted. signerID parameter is used to filter result on a specific signer ID. If empty value is provided is used the current logged signerID value.

func PublicCNLCVerify added in v0.9.5

func PublicCNLCVerify(hash, lcLedger, signerID, lcHost, lcPort, lcCert string, lcSkipTlsVerify, lcNoTls bool) (a *LcArtifact, err error)

PublicCNLCVerify allow connection and verification on CNLC ledger with a single call. LcLedger parameter is used when a cross-ledger key is provided in order to specify the ledger on which future operations will be directed. Empty string is accepted signerID parameter is used to filter result on a specific signer ID. If empty value is provided is used the current logged signerID value.

func VerifiableItemExtToLcArtifact added in v0.9.1

func VerifiableItemExtToLcArtifact(item *schema.VerifiableItemExt) (*LcArtifact, error)

func ZItemToLcArtifact added in v0.9.0

func ZItemToLcArtifact(ie *schema.ZItemExt) (*LcArtifact, error)

func (*LcArtifact) Date added in v0.9.5

func (lca *LcArtifact) Date() string

Date returns a RFC3339 formatted string of verification time (v.Timestamp), if any, otherwise an empty string.

type LcSignOption added in v0.9.0

type LcSignOption func(*lcSignOpts) error

SignOption is a functional option for signing operations

func LcSignWithAttachments added in v0.9.5

func LcSignWithAttachments(attach []string) LcSignOption

LcSignWithAttachments returns the functional option for the given status.

func LcSignWithBom added in v0.9.8

func LcSignWithBom(bom string) LcSignOption

func LcSignWithStatus added in v0.9.0

func LcSignWithStatus(status meta.Status) LcSignOption

SignWithStatus returns the functional option for the given status.

func LcSignWithVisibility added in v0.9.0

func LcSignWithVisibility(visibility meta.Visibility) LcSignOption

SignWithVisibility returns the functional option for the given visibility.

type LcUser added in v0.9.0

type LcUser struct {
	Client *sdk.LcClient
}

User represent a CodeNotary platform user.

func NewLcUser added in v0.9.0

func NewLcUser(lcApiKey, lcLedger, host, port, lcCert string, skipTlsVerify bool, noTls bool, signingPubKey *ecdsa.PublicKey) (*LcUser, error)

NewLcUser returns a new User instance configured with provided parameters. LcLedger parameter is used when a cross-ledger key is provided in order to specify the ledger on which future operations will be directed. Empty string is accepted

func NewLcUserVolatile added in v0.9.0

func NewLcUserVolatile(lcApiKey, lcLedger string, host string, port string) *LcUser

NewLcUserVolatile returns a new User instance without a backing cfg file.

func (*LcUser) CheckConnectionPublicKey added in v0.9.10

func (u *LcUser) CheckConnectionPublicKey(enforceSignatureVerify bool) error

CheckConnectionPublicKey the aim of this method is to guarantee that the connection between vcn and a CNC server are verified by the first login auto trusted signature. This method fetches an immudb state, checks if the public key provided to the immudb client match server signature and saves locally such key. In addition it checks if a previously trusted (local) key is the same to the current one used by client. This guarantee that the connection is established on a previously trusted server. If enforceSignatureVerify is TRUE it requires an explicit fingerprint confirmation. NOTE: if VCN_SIGNING_PUB_KEY_FILE or VCN_SIGNING_PUB_KEY environment flag or arguments are provided this method is not called.

func (*LcUser) DownloadAttachment added in v0.9.5

func (u *LcUser) DownloadAttachment(attach *Attachment, ar *LcArtifact, tx uint64, lcAttachForce bool) (err error)

DownloadAttachment download locally all the attachments linked to the assets

func (*LcUser) GetArtifactAttachmentListByLabel added in v0.9.7

func (u *LcUser) GetArtifactAttachmentListByLabel(hash string, signerID, label string) ([]Attachment, string, error)

GetArtifactAttachmentListByLabel returns the attachment list of an artifact and the most recent uid by a provided label and signerID When there are multiple attachments with same file name it adds an enumerator postfix.

func (*LcUser) LoadArtifact added in v0.9.0

func (u *LcUser) LoadArtifact(
	hash, signerID string,
	uid string,
	tx uint64,
	gRPCMetadata map[string][]string,
) (lc *LcArtifact, verified bool, err error)

LoadArtifact fetches and returns an *lcArtifact for the given hash and current u, if any.

func (*LcUser) LoadArtifacts added in v0.9.10

func (u *LcUser) LoadArtifacts(
	signerID string,
	hashes []string,
	gRPCMetadata map[string][]string,
) (artifacts []*LcArtifact, verified []bool, errs []error, err error)

LoadArtifacts fetches and returns multiple *lcArtifact for the given hashes and current u, if any.

func (LcUser) RequireFeatOrErr added in v0.9.8

func (u LcUser) RequireFeatOrErr(feat string) error

func (LcUser) Sign added in v0.9.0

func (u LcUser) Sign(artifact Artifact, options ...LcSignOption) (bool, uint64, error)

Sign is invoked by the User to notarize an artifact using the given functional options, By default, the artifact is notarized using status = meta.StatusTrusted, visibility meta.VisibilityPrivate.

func (LcUser) SignMulti added in v0.9.10

func (u LcUser) SignMulti(artifacts []*Artifact, options [][]LcSignOption) ([]bool, []uint64, []error, error)

SignMulti ...

type Metadata

type Metadata map[string]interface{}

Metadata holds custom artifact attributes

func (Metadata) Get

func (m Metadata) Get(key string, defaultValue interface{}) interface{}

Get returns the value for the given key, if any, otherwise returns defaultValue

func (*Metadata) Set

func (m *Metadata) Set(key string, value interface{})

Set sets the value for given key

func (*Metadata) SetValues

func (m *Metadata) SetValues(values map[string]interface{})

SetValues sets given values into this Metadata instance

type PackageDetails added in v0.9.9

type PackageDetails struct {
	Name    string      `json:"name" yaml:"name" vcn:"name"`
	Version string      `json:"version,omitempty" yaml:"version,omitempty" vcn:"version"`
	Hash    string      `json:"hash" yaml:"hash" vcn:"hash"`
	Status  meta.Status `json:"status" yaml:"status" vcn:"status"`
	License string      `json:"license,omitempty" yaml:"license"`
}

type PagedArtifactResponse

type PagedArtifactResponse struct {
	Content       []ArtifactResponse `json:"content"`
	TotalElements uint64             `json:"totalElements"`
	Pageable      struct {
		PageSize   uint64 `json:"pageSize"`
		PageNumber uint64 `json:"pageNumber"`
	} `json:"pageable"`
}

PagedArtifactResponse holds a page of ArtifactResponse(s) returned by the platform.

type SignOption added in v0.7.0

type SignOption func(*signOpts) error

SignOption is a functional option for signing operations

func SignWithKey added in v0.7.0

func SignWithKey(keyin, passphrase string) SignOption

SignWithKey returns the functional option for the given keyin and passphrase.

func SignWithStatus added in v0.7.0

func SignWithStatus(status meta.Status) SignOption

SignWithStatus returns the functional option for the given status.

func SignWithVisibility added in v0.7.0

func SignWithVisibility(visibility meta.Visibility) SignOption

SignWithVisibility returns the functional option for the given visibility.

type User

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

User represent a CodeNotary platform user.

func NewUser

func NewUser(email string) *User

NewUser returns a new User instance for the given email.

func (*User) Authenticate

func (u *User) Authenticate(password string, otp string) (err error)

Authenticate the User against the CodeNotary platform. If successful the auth token in stored within the User's config and used for subsequent API call.

func (*User) ClearAuth

func (u *User) ClearAuth()

ClearAuth deletes the stored authentication token.

func (User) Config added in v0.6.0

func (u User) Config() *store.User

Config returns the User configuration object (see store.User), if any. It returns nil if the User is not properly initialized.

func (*User) CreateAlert added in v0.8.0

func (u *User) CreateAlert(name string, email string, a Artifact, v BlockchainVerification, m Metadata) (alertConfig *AlertConfig, err error)

CreateAlert creates a platform alert and returns its UUID.

func (User) Email

func (u User) Email() string

Email returns the User's email, if any, otherwise an empty string.

func (*User) GetAlert added in v0.8.0

func (u *User) GetAlert(uuid string) (*AlertResponse, error)

GetAlert returns an AlertResponse for a given alert uuid.

func (User) IsAuthenticated

func (u User) IsAuthenticated() (bool, error)

IsAuthenticated returns true if the stored auth token is still valid.

func (User) IsExist

func (u User) IsExist() (bool, error)

IsExist returns true if the User's was registered on the CodeNotary platform.

func (User) ListArtifacts added in v0.5.2

func (u User) ListArtifacts(page uint) (*PagedArtifactResponse, error)

ListArtifacts fetches and returns a paged list of user's artifacts.

func (*User) LoadArtifact

func (u *User) LoadArtifact(hash string) (*ArtifactResponse, error)

LoadArtifact fetches and returns an *ArtifactResponse for the given hash and current u, if any.

func (*User) PingAlert added in v0.8.0

func (u *User) PingAlert(config AlertConfig) error

PingAlert sends a ping for the given alert _config_. Once the first ping goes through, the platform starts a server-side watcher and will trigger a notification after some amount of time if no further pings for the alert are received.

func (User) RemainingSignOps

func (u User) RemainingSignOps() (uint64, error)

RemainingSignOps returns the number of remaining notarizations in the User's account subscription.

func (User) Secret added in v0.7.0

func (u User) Secret() (reader, id string, offline bool, err error)

Secret fetches the User's secret and returns an io.Reader for reading it.

func (User) Sign

func (u User) Sign(artifact Artifact, options ...SignOption) (*BlockchainVerification, error)

Sign is invoked by the User to notarize an artifact using the given functional options, if successful a BlockchainVerification is returned. By default, the artifact is notarized using status = meta.StatusTrusted, visibility meta.VisibilityPrivate. At least the key (secret) must be provided using SignWithKey().

func (User) SignerID added in v0.7.0

func (u User) SignerID() (id string, err error)

SignerID retrives the User's SignerID (the public address derived from the secret) from the platform.

func (*User) TriggerAlert added in v0.8.0

func (u *User) TriggerAlert(config AlertConfig) error

TriggerAlert triggers a notification immediately for the given alert _config_.

func (User) UploadSecret added in v0.7.0

func (u User) UploadSecret(secret io.Reader, passphrase string) (err error)

UploadSecret uploads the User's secret to the platform.

func (User) User added in v0.9.0

func (u User) User() *store.User

Config returns the User configuration object (see store.User), if any. It returns nil if the User is not properly initialized.

func (*User) UserByCfg added in v0.9.0

func (u *User) UserByCfg(cfg *store.User)

UserByCfg configures current user with a custom values

Jump to

Keyboard shortcuts

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