coreapi

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrAccountIDInvalid is a sentinel error for invalid account IDs.
	ErrAccountIDInvalid = errors.Error("account ID is invalid")

	// ErrAccountNotFound is a sentinel error for when account is missing.
	ErrAccountNotFound = errors.Error("account not found")
)
View Source
const (
	// DocumentIDParam for document_id in api path.
	DocumentIDParam = "document_id"

	// VersionIDParam for version_id in api path.
	VersionIDParam = "version_id"
)
View Source
const (
	// ErrInvalidDocumentID is a sentinel error for invalid document identifiers.
	ErrInvalidDocumentID = errors.Error("invalid document identifier")

	// ErrDocumentNotFound is a sentinel error for missing documents.
	ErrDocumentNotFound = errors.Error("document not found")
)
View Source
const (
	// ErrInvalidJobID is the sentinel error when the job_id passed is invalid.
	ErrInvalidJobID = errors.Error("Invalid Job ID")

	// ErrJobNotFound is a sentinel error when job associated with job_id is not found.
	ErrJobNotFound = errors.Error("Job not found")
)
View Source
const (
	// ErrInvalidTokenID is a sentinel error when token ID is invalid
	ErrInvalidTokenID = errors.Error("Invalid Token ID")

	// ErrInvalidRegistryAddress is a sentinel error when registry address is invalid
	ErrInvalidRegistryAddress = errors.Error("Invalid registry address")
)
View Source
const BootstrappedCoreAPIService = "CoreAPI Service"

BootstrappedCoreAPIService key maps to the Service implementation in Bootstrap context.

Variables

This section is empty.

Functions

func Register

func Register(ctx map[string]interface{}, r chi.Router)

Register registers the core apis to the router.

func ToDocumentsCreatePayload

func ToDocumentsCreatePayload(request CreateDocumentRequest) (documents.CreatePayload, error)

ToDocumentsCreatePayload converts CoreAPI create payload to documents payload.

Types

type Account

type Account struct {
	EthereumAccount                  EthAccount              `json:"eth_account"`
	EthereumDefaultAccountName       string                  `json:"eth_default_account_name"`
	ReceiveEventNotificationEndpoint string                  `json:"receive_event_notification_endpoint"`
	IdentityID                       byteutils.HexBytes      `json:"identity_id" swaggertype:"primitive,string"`
	SigningKeyPair                   KeyPair                 `json:"signing_key_pair"`
	P2PKeyPair                       KeyPair                 `json:"p2p_key_pair"`
	CentChainAccount                 config.CentChainAccount `json:"centrifuge_chain_account"`
}

Account holds the single account details.

type Accounts

type Accounts struct {
	Data []Account `json:"data"`
}

Accounts holds a list of accounts

type AttributeMapRequest

type AttributeMapRequest map[string]AttributeRequest

AttributeMapRequest defines a map of attributes with attribute key as key

type AttributeMapResponse

type AttributeMapResponse map[string]AttributeResponse

AttributeMapResponse maps attribute label to AttributeResponse

type AttributeRequest

type AttributeRequest struct {
	Type          string         `json:"type" enums:"integer,decimal,string,bytes,timestamp,monetary"`
	Value         string         `json:"value"`
	MonetaryValue *MonetaryValue `json:"monetary_value,omitempty"`
}

AttributeRequest defines a single attribute. Type type of the attribute Value simple value of the attribute MonetaryValue value for only monetary attribute

type AttributeResponse

type AttributeResponse struct {
	AttributeRequest
	Key         byteutils.HexBytes `json:"key" swaggertype:"primitive,string"`
	SignedValue SignedValue        `json:"signed_value"`
}

AttributeResponse adds key to the attribute.

type Bootstrapper

type Bootstrapper struct{}

Bootstrapper implements bootstrap.Bootstrapper.

func (Bootstrapper) Bootstrap

func (b Bootstrapper) Bootstrap(ctx map[string]interface{}) error

Bootstrap adds transaction.Repository into context.

type CreateDocumentRequest

type CreateDocumentRequest struct {
	Scheme      string              `json:"scheme" enums:"generic,entity"`
	ReadAccess  []identity.DID      `json:"read_access" swaggertype:"array,string"`
	WriteAccess []identity.DID      `json:"write_access" swaggertype:"array,string"`
	Data        interface{}         `json:"data"`
	Attributes  AttributeMapRequest `json:"attributes"`
}

CreateDocumentRequest defines the payload for creating documents.

type DocumentResponse

type DocumentResponse struct {
	Header     ResponseHeader       `json:"header"`
	Scheme     string               `json:"scheme" enums:"generic,entity"`
	Data       interface{}          `json:"data"`
	Attributes AttributeMapResponse `json:"attributes"`
}

DocumentResponse is the common response for Document APIs.

func GetDocumentResponse

func GetDocumentResponse(model documents.Model, tokenRegistry documents.TokenRegistry, jobID jobs.JobID) (resp DocumentResponse, err error)

GetDocumentResponse converts model to a client api format.

type EthAccount

type EthAccount struct {
	Address  string `json:"address"`
	Key      string `json:"key,omitempty"`
	Password string `json:"password,omitempty"`
}

EthAccount holds address of the account.

type GenerateAccountPayload

type GenerateAccountPayload struct {
	CentChainAccount config.CentChainAccount `json:"centrifuge_chain_account"`
}

GenerateAccountPayload holds required fields to generate account with defaults.

type KeyPair

type KeyPair struct {
	Pub string `json:"pub"`
	Pvt string `json:"pvt"`
}

KeyPair represents the public and private key.

type MintNFTRequest

type MintNFTRequest struct {
	DocumentID          byteutils.HexBytes    `json:"document_id" swaggertype:"primitive,string"`
	DepositAddress      common.Address        `json:"deposit_address" swaggertype:"primitive,string"`
	AssetManagerAddress byteutils.OptionalHex `json:"asset_manager_address" swaggertype:"primitive,string"`
	ProofFields         []string              `json:"proof_fields"`
}

MintNFTRequest holds required fields for minting NFT

type MintNFTResponse

type MintNFTResponse struct {
	Header          NFTResponseHeader  `json:"header"`
	DocumentID      byteutils.HexBytes `json:"document_id" swaggertype:"primitive,string"`
	TokenID         string             `json:"token_id"`
	RegistryAddress common.Address     `json:"registry_address" swaggertype:"primitive,string"`
	DepositAddress  common.Address     `json:"deposit_address" swaggertype:"primitive,string"`
}

MintNFTResponse holds the details of the minted NFT.

type MonetaryValue

type MonetaryValue struct {
	Value   *documents.Decimal `json:"value" swaggertype:"primitive,string"`
	ChainID byteutils.HexBytes `json:"chain_id" swaggertype:"primitive,string"`
	ID      string             `json:"id"`
}

MonetaryValue defines user format to represent currency type Value string representation of decimal number ChainID hex bytes representing the chain where the currency is relevant ID string representing the Currency (USD|ETH|0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2(DAI)...)

type NFT

type NFT struct {
	Registry   string `json:"registry"`
	Owner      string `json:"owner"`
	TokenID    string `json:"token_id"`
	TokenIndex string `json:"token_index"`
}

NFT defines a single NFT.

type NFTOwnerResponse

type NFTOwnerResponse struct {
	TokenID         string         `json:"token_id"`
	RegistryAddress common.Address `json:"registry_address" swaggertype:"primitive,string"`
	Owner           common.Address `json:"owner" swaggertype:"primitive,string"`
}

NFTOwnerResponse is the response for NFT owner request.

type NFTResponseHeader

type NFTResponseHeader struct {
	JobID string `json:"job_id"`
}

NFTResponseHeader holds the NFT mint job ID.

type ProofResponseHeader

type ProofResponseHeader struct {
	DocumentID byteutils.HexBytes `json:"document_id" swaggertype:"primitive,string"`
	VersionID  byteutils.HexBytes `json:"version_id" swaggertype:"primitive,string"`
	State      string             `json:"state"`
}

ProofResponseHeader holds the document details.

type ProofsRequest

type ProofsRequest struct {
	Fields []string `json:"fields"`
}

ProofsRequest holds the fields for which proofs are generated.

type ProofsResponse

type ProofsResponse struct {
	Header      ProofResponseHeader `json:"header"`
	FieldProofs []documents.Proof   `json:"field_proofs"`
}

ProofsResponse holds the proofs for the fields given for a document.

type ResponseHeader

type ResponseHeader struct {
	DocumentID  string             `json:"document_id"`
	VersionID   string             `json:"version_id"`
	Author      string             `json:"author"`
	CreatedAt   string             `json:"created_at"`
	ReadAccess  []identity.DID     `json:"read_access" swaggertype:"array,string"`
	WriteAccess []identity.DID     `json:"write_access" swaggertype:"array,string"`
	JobID       string             `json:"job_id,omitempty"`
	NFTs        []NFT              `json:"nfts"`
	Status      string             `json:"status,omitempty"`
	Fingerprint byteutils.HexBytes `json:"fingerprint,omitempty" swaggertype:"primitive,string"`
}

ResponseHeader holds the common response header fields

func DeriveResponseHeader

func DeriveResponseHeader(tokenRegistry documents.TokenRegistry, model documents.Model, id jobs.JobID) (response ResponseHeader, err error)

DeriveResponseHeader derives an appropriate response header

type Service

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

Service defines the functionality for the CoreAPI service.

func NewService

func NewService(docSrv documents.Service, jobsSrv jobs.Manager, nftSrv nft.Service, accountsSrv config.Service) Service

NewService returns the new CoreAPI Service.

func (Service) CreateAccount

func (s Service) CreateAccount(acc config.Account) (config.Account, error)

CreateAccount creates a new account from the data provided.

func (Service) CreateDocument

func (s Service) CreateDocument(ctx context.Context, payload documents.CreatePayload) (documents.Model, jobs.JobID, error)

CreateDocument creates the document from the payload and anchors it.

func (Service) GenerateAccount

func (s Service) GenerateAccount(payload GenerateAccountPayload) (config.Account, error)

GenerateAccount generates an account with defaults.

func (Service) GenerateProofs

func (s Service) GenerateProofs(ctx context.Context, docID []byte, fields []string) (*documents.DocumentProof, error)

GenerateProofs returns the proofs for the latest version of the document.

func (Service) GenerateProofsForVersion

func (s Service) GenerateProofsForVersion(ctx context.Context, docID, versionID []byte, fields []string) (*documents.DocumentProof, error)

GenerateProofsForVersion returns the proofs for the specific version of the document.

func (Service) GetAccount

func (s Service) GetAccount(accountID []byte) (config.Account, error)

GetAccount returns the Account associated with accountID

func (Service) GetAccounts

func (s Service) GetAccounts() ([]config.Account, error)

GetAccounts returns all the accounts.

func (Service) GetDocument

func (s Service) GetDocument(ctx context.Context, docID []byte) (documents.Model, error)

GetDocument returns the latest version of the document.

func (Service) GetDocumentVersion

func (s Service) GetDocumentVersion(ctx context.Context, docID, versionID []byte) (documents.Model, error)

GetDocumentVersion returns the specific version of the document

func (Service) GetJobStatus

func (s Service) GetJobStatus(account identity.DID, id jobs.JobID) (jobs.StatusResponse, error)

GetJobStatus returns the job status.

func (Service) MintNFT

func (s Service) MintNFT(ctx context.Context, request nft.MintNFTRequest) (*nft.TokenResponse, error)

MintNFT mints an NFT.

func (Service) OwnerOfNFT

func (s Service) OwnerOfNFT(registry common.Address, tokenID nft.TokenID) (common.Address, error)

OwnerOfNFT returns the owner of the NFT.

func (Service) SignPayload

func (s Service) SignPayload(accountID, payload []byte) (*coredocumentpb.Signature, error)

SignPayload uses the accountID's secret key to sign the payload and returns the signature

func (Service) TransferNFT

func (s Service) TransferNFT(ctx context.Context, to, registry common.Address, tokenID nft.TokenID) (*nft.TokenResponse, error)

TransferNFT transfers NFT with tokenID in a given registry to `to` address.

func (Service) UpdateAccount

func (s Service) UpdateAccount(acc config.Account) (config.Account, error)

UpdateAccount updates the existing account with the data provided.

func (Service) UpdateDocument

func (s Service) UpdateDocument(ctx context.Context, payload documents.UpdatePayload) (documents.Model, jobs.JobID, error)

UpdateDocument updates the document from the payload and anchors the next version.

type SignRequest

type SignRequest struct {
	Payload byteutils.HexBytes `json:"payload" swaggertype:"primitive,string"`
}

SignRequest holds the payload to be signed.

type SignResponse

type SignResponse struct {
	Payload   byteutils.HexBytes `json:"payload" swaggertype:"primitive,string"`
	Signature byteutils.HexBytes `json:"signature" swaggertype:"primitive,string"`
	PublicKey byteutils.HexBytes `json:"public_key" swaggertype:"primitive,string"`
	SignerID  byteutils.HexBytes `json:"signer_id" swaggertype:"primitive,string"`
}

SignResponse holds the signature, pk and Payload for the Sign request.

type SignedValue

type SignedValue struct {
	Identity identity.DID       `json:"identity" swaggertype:"primitive,string"`
	Value    byteutils.HexBytes `json:"value" swaggertype:"primitive,string"`
}

SignedValue contains the Identity of who signed the attribute and value which was signed

type TransferNFTRequest

type TransferNFTRequest struct {
	To common.Address `json:"to" swaggertype:"primitive,string"`
}

TransferNFTRequest holds Registry Address and To address for NFT transfer

type TransferNFTResponse

type TransferNFTResponse struct {
	Header          NFTResponseHeader `json:"header"`
	TokenID         string            `json:"token_id"`
	RegistryAddress common.Address    `json:"registry_address" swaggertype:"primitive,string"`
	To              common.Address    `json:"to" swaggertype:"primitive,string"`
}

TransferNFTResponse is the response for NFT transfer.

Jump to

Keyboard shortcuts

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