commercio

package module
v0.0.0-...-e98582d Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2020 License: MIT Imports: 37 Imported by: 0

README

commercio-sdk.go

Commercio.network SDK written in Go.

Warning!

This software is work-in-progress, no guarantees on interface stability and feature completeness.

Install

go get github.com/commercionetwork/commercio-sdk.go

Example

package main

import (
	"fmt"
	"log"

	"github.com/commercionetwork/commercio-sdk.go"
)

func mightFatal(err error) {
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	m := "cover safe brass same salad raccoon expect rigid service brush ski amateur sample emerge actress oblige camp business three awkward absent peasant kitchen pool"

	c := commercio.DefaultConfig

	// only used for demonstration purposes
	c.Mode = commercio.TxModeBlock

	s, err := commercio.NewSDK(m, commercio.DefaultConfig)
	mightFatal(err)

	jack, err := commercio.Address("did:com:1l9rr5ck7ed30ny3ex4uj75ezrt03gfp96z7nen")
	mightFatal(err)

	janet, err := commercio.Address("did:com:1zla8arsc5rju9wekz00yz54zguj20a96jn9cy6")
	mightFatal(err)

	send := commercio.MsgSend{
		FromAddress: jack,
		ToAddress:   janet,
		Amount:      commercio.Amount(1000),
	}

	hash, err := s.SendTransaction(send)
	mightFatal(err)

	fmt.Println("transaction hash:", hash)
}

Documentation

Index

Constants

View Source
const (
	// TxModeSync represents the `sync` transaction mode.
	TxModeSync = "sync"

	// TxModeAsync represents the `async` transaction mode.
	TxModeAsync = "async"

	// TxModeBlock represents the `block` transaction mode.
	TxModeBlock = "block"
)

Variables

View Source
var (
	// ErrNewSDK represents some kind of error that happened during the initialization phase of the SDK.
	ErrNewSDK = errors.New("could not initialize SDK")

	// ErrInvalidMessage represents some kind of error that happened during the adaptation of messages to the
	// format used for broadcasting.
	ErrInvalidMessage = errors.New("invalid transaction")

	// ErrInvalidPublicKey is used when a Bech32-encoded public key is invalid or malformed.
	ErrInvalidPublicKey = errors.New("invalid public key")

	// ErrInvalidAddress is used when a Bech32-encoded address is invalid or malformed.
	ErrInvalidAddress = errors.New("invalid address key")

	// ErrInvalidSignatureKey represents an error returned when the RSA signature key is invalid.
	ErrInvalidSignatureKey = errors.New("invalid signature key")

	// ErrInvalidTumblerKey represents an error returned when the RSA tumbler key is invalid.
	ErrInvalidTumblerKey = errors.New("invalid signature key")

	// ErrInvalidVerificationKey represents an error returned when the RSA verification key is invalid.
	ErrInvalidVerificationKey = errors.New("invalid verification key")

	// ErrProofCreation represents an error returned when the DidDocument proof creation fails.
	ErrProofCreation = errors.New("cannot create proof")

	// ErrInvalidAmount represents an error returned when the provided uint64 amount is invalid.
	ErrInvalidAmount = errors.New("invalid coin amount")

	// ErrInvalidPowerupParams represents an error returned when the provided power up params are invalid.
	ErrInvalidPowerupParams = errors.New("invalid powerup params")

	// ErrNotEnoughEntropy represents an error returned when there's not enough entropy to generate random data.
	ErrNotEnoughEntropy = errors.New("not enough entropy")

	// ErrEncryptionFailure represents an error returned when some error happens during the encryption process.
	ErrEncryptionFailure = errors.New("encryption failure")
)
View Source
var (
	MembershipTypeBronze = "bronze"
	MembershipTypeSilver = "silver"
	MembershipTypeGold   = "gold"
	MembershipTypeBlack  = "black"
)

Membership types definition

View Source
var (
	// DefaultSDKConfig represents the default configuration for a commercio.network SDK instance.
	DefaultSDKConfig = SDKConfig{
		DerivationPath: derivationPath,

		LCDEndpoint: "http://localhost:1317",
		Mode:        TxModeSync,
		// contains filtered or unexported fields
	}
)

Functions

func Address

func Address(str string) (types.AccAddress, error)

Address returns str as a Cosmos-compatible address, given str as a bech32-encoded string.

func Amount

func Amount(amount uint64) (types.Coins, error)

Amount returns a Cosmos-compatible Commercio.network amount, expressed in ucommercio.

func NewMnemonic

func NewMnemonic() (string, error)

NewMnemonic return a cryptographically-secure wallet mnemonic.

func NewRSAKeypair

func NewRSAKeypair() (string, string, error)

NewRSAKeypair returns a new PEM-encoded RSA 2048-bit keypair.

Types

type DidDocument

type DidDocument id.DidDocument

x/id messages

type Document

type Document docs.Document

x/docs messages

type DocumentChecksum

type DocumentChecksum docs.DocumentChecksum

type DocumentMetadata

type DocumentMetadata docs.DocumentMetadata

type DocumentMetadataSchema

type DocumentMetadataSchema docs.DocumentMetadataSchema

type DocumentReceipt

type DocumentReceipt docs.DocumentReceipt

type MetadataSchema

type MetadataSchema docs.MetadataSchema

type MsgAddSupportedMetadataSchema

type MsgAddSupportedMetadataSchema docs.MsgAddSupportedMetadataSchema

type MsgAddTrustedMetadataSchemaProposer

type MsgAddTrustedMetadataSchemaProposer docs.MsgAddTrustedMetadataSchemaProposer

type MsgBuyMembership

type MsgBuyMembership memberships.MsgBuyMembership

type MsgCloseCdp

type MsgCloseCdp = commerciomint.MsgCloseCdp

type MsgIncrementsBlockRewardsPool

type MsgIncrementsBlockRewardsPool vbr.MsgIncrementsBlockRewardsPool

x/vbr messages

type MsgInviteUser

type MsgInviteUser memberships.MsgInviteUser

x/memberships messages

type MsgOpenCdp

type MsgOpenCdp = commerciomint.MsgOpenCdp

x/commerciomint messages

type MsgRequestDidPowerUp

type MsgRequestDidPowerUp id.MsgRequestDidPowerUp

type MsgSend

type MsgSend bank.MsgSend

Standard Cosmos-sdk messages

type MsgSendDocumentReceipt

type MsgSendDocumentReceipt docs.MsgSendDocumentReceipt

type MsgSetIdentity

type MsgSetIdentity id.MsgSetIdentity

type MsgShareDocument

type MsgShareDocument docs.MsgShareDocument

type PowerUpParams

type PowerUpParams struct {
	// PubKey is the bech32-encoded public key of the account which sends the Power-up request.
	PubKey string

	// TumblerKey is the tumbler RSA PKIX public key.
	TumblerKey io.Reader

	// SignatureKey is the user RSA PKCS8 private key, used to build the message proof.
	//
	// It must be the private part of the keypair created and associated with the account which sends
	// the transaction.
	SignatureKey io.Reader

	// Amount represents the amount the user signing the transaction wants to send to its Pairwise address.
	Amount uint64

	// PairwiseAddress is the address to which the user signing the transaction wants to send Amount tokens.
	PairwiseAddress types.AccAddress
}

PowerUpParams are parameters used by BuildPowerupRequests during its lifecycle.

type Proof

type Proof id.Proof

type PubKey

type PubKey id.PubKey

type PubKeys

type PubKeys id.PubKeys

type SDK

type SDK struct {
	Address   string
	PublicKey string
	// contains filtered or unexported fields
}

SDK represents the entrypoint for the commercio.network SDK.

func NewSDK

func NewSDK(mnemonic string, config SDKConfig) (*SDK, error)

NewSDK returns a new instance of SDK initialized by given mnemonic and config.

func (*SDK) BuildDidDocument

func (sdk *SDK) BuildDidDocument(pubKeyString string, signatureKey, verificationKey io.Reader) (DidDocument, error)

BuildDidDocument creates a DidDocument for the account associated to sdk, given its publick key, signature and verification RSA public keys.

func (*SDK) BuildPowerupRequest

func (sdk *SDK) BuildPowerupRequest(params PowerUpParams) (MsgRequestDidPowerUp, error)

BuildPowerupRequest creates a MsgRequestDidPowerUp based on params.

func (*SDK) SendTransaction

func (sdk *SDK) SendTransaction(rawMsgs ...interface{}) (string, error)

SendTransaction sends all the messages contained in rawMsgs through the pre-defined LCD, then returns the transaction hash.

type SDKConfig

type SDKConfig struct {
	// DerivationPath represents the derivation path used while performing crypto-related operations.
	DerivationPath string

	// LCDEndpoint is the commercio.network REST LCD server endpoint, where transaction will be broadcasted.
	LCDEndpoint string

	// Mode is the TxMode to be used while performing transaction-related operations.
	Mode TxMode
	// contains filtered or unexported fields
}

SDKConfig allows callers to customize default behaviors the commercio.network SDK assumes.

type Services

type Services id.Services

type TxMode

type TxMode string

TxMode represents the mode used by the SDK to broadcast the transaction. TxMode can be either:

  • `sync`: the LCD will do basic validity checks on the messages, will not wait for the message to be included in a block; it'll always return no error.
  • `async`: like `sync`, but no checks are performed.
  • `block`: like `sync`, but it will wait for the message to be included in a block; it could return error.

Jump to

Keyboard shortcuts

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