crypto

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2021 License: LGPL-3.0 Imports: 14 Imported by: 10

Documentation

Index

Constants

View Source
const ExitPrefix = "Exit request:"
View Source
const Myst uint64 = 1000_000_000_000_000_000

Myst represents a single myst ERC 777 token.

Variables

This section is empty.

Functions

func BigMystToFloat added in v0.2.0

func BigMystToFloat(input *big.Int) float64

BigMystToFloat takes in a big int and returns a float64 representation of the myst.

func FloatToBigMyst added in v0.2.0

func FloatToBigMyst(input float64) *big.Int

FloatToBigMyst takes in a float converts it to a big int representation. For example, 1.5 becomes 1500_000_000_000_000_000.

func GenerateChannelAddress

func GenerateChannelAddress(identity, hermes, registry, channelImplementation string) (address string, err error)

GenerateChannelAddress generate channel address from given identity hash

func GenerateHermesAddress added in v0.2.0

func GenerateHermesAddress(operator string, registry string, hermesImplementation string) (address string, err error)

GenerateHermesAddress generate hermes address from given hermes operator address

func GenerateProviderChannelID

func GenerateProviderChannelID(providerIdentity, hermesAddress string) (string, error)

GenerateProviderChannelID generated channelID for provider channels from given identity hash

func GenerateProviderChannelIDForPayAndSettle added in v0.2.0

func GenerateProviderChannelIDForPayAndSettle(providerIdentity, hermesAddress string) (string, error)

GenerateProviderChannelIDForPayAndSettle generated channelID for provider channels from given identity hash

func GetProxyCode

func GetProxyCode(destinationAddress string) ([]byte, error)

GetProxyCode generates bytecode of minimal proxy contract (EIP 1167)

func HexToBytes added in v0.2.0

func HexToBytes(str string) []byte

func Pad

func Pad(b []byte, size int) []byte

Pad pads the given byte array to given size by prefixing with zeros

func RecoverAddress

func RecoverAddress(message []byte, signature []byte) (common.Address, error)

RecoverAddress recovers the address from message and signature

func ReformatSignatureVForBC

func ReformatSignatureVForBC(signature []byte) error

ReformatSignatureVForBC takes in the signature and modifies its last byte to correspond to the format required for SC

func ReformatSignatureVForRecovery

func ReformatSignatureVForRecovery(signature []byte) error

ReformatSignatureVForRecovery takes in the signature and modifies its last byte to normalize V to either 0 or 1

Types

type DecreaseProviderStakeRequest added in v0.2.0

type DecreaseProviderStakeRequest struct {
	ChannelID     [32]byte
	HermesID      common.Address
	Amount        *big.Int
	TransactorFee *big.Int
	Nonce         *big.Int
	ChainID       int64
	Signature     []byte
}

DecreaseProviderStakeRequest represents all the parameters required for decreasing provider stake.

func (DecreaseProviderStakeRequest) CreateSignature added in v0.2.0

func (dpsr DecreaseProviderStakeRequest) CreateSignature(ks hashSigner, signer common.Address) ([]byte, error)

CreateSignature signs promise using keystore

func (DecreaseProviderStakeRequest) GetMessage added in v0.2.0

func (dpsr DecreaseProviderStakeRequest) GetMessage() []byte

GetMessage gets a message representation of the DecreaseProviderStakeRequest.

func (DecreaseProviderStakeRequest) IsValid added in v0.2.0

func (dpsr DecreaseProviderStakeRequest) IsValid(expectedSigner common.Address) bool

IsValid checks if the current stake decrease request is valid or not.

func (DecreaseProviderStakeRequest) RecoverSigner added in v0.2.0

func (dpsr DecreaseProviderStakeRequest) RecoverSigner() (common.Address, error)

RecoverSigner recovers signer address out of request signature.

func (*DecreaseProviderStakeRequest) Sign added in v0.2.0

Sign signs the DecreaseProviderStakeRequest.

type ExchangeMessage

type ExchangeMessage struct {
	Promise        Promise
	AgreementID    *big.Int
	AgreementTotal *big.Int
	Provider       string
	Signature      string
	HermesID       string
	ChainID        int64
}

ExchangeMessage represent a promise exchange message

func CreateExchangeMessage

func CreateExchangeMessage(chainID int64, invoice Invoice, promiseAmount *big.Int, channelID, hermesID string, ks hashSigner, signer common.Address) (*ExchangeMessage, error)

CreateExchangeMessage creates new exchange message with it's promise

func CreateExchangeMessageWithPromise added in v0.2.0

func CreateExchangeMessageWithPromise(chainID int64, invoice Invoice, promise *Promise, hermesID string, ks hashSigner, signer common.Address) (*ExchangeMessage, error)

func (ExchangeMessage) CreateSignature

func (m ExchangeMessage) CreateSignature(ks hashSigner, signer common.Address) ([]byte, error)

CreateSignature signs promise using keystore

func (ExchangeMessage) GetAgreementTotal

func (m ExchangeMessage) GetAgreementTotal() *big.Int

GetAgreementTotal returns a big int representation for the agreement total amount

func (ExchangeMessage) GetFee

func (m ExchangeMessage) GetFee() *big.Int

GetFee returns the big int representation for the promise settling transaction fee

func (ExchangeMessage) GetMessage

func (m ExchangeMessage) GetMessage() []byte

GetMessage forms the message of promise exchange request

func (ExchangeMessage) GetMessageHash

func (m ExchangeMessage) GetMessageHash() []byte

GetMessageHash returns a keccak of exchange message params

func (ExchangeMessage) GetSignatureBytesRaw

func (m ExchangeMessage) GetSignatureBytesRaw() []byte

GetSignatureBytesRaw returns the unadulterated bytes of the signature

func (ExchangeMessage) IsMessageValid

func (m ExchangeMessage) IsMessageValid(expectedSigner common.Address) bool

IsMessageValid validates if given exchange message was signed by expected identity

func (ExchangeMessage) RecoverConsumerIdentity

func (m ExchangeMessage) RecoverConsumerIdentity() (common.Address, error)

RecoverConsumerIdentity recovers the identity from the given request

type ExitRequest added in v0.2.0

type ExitRequest struct {
	ChannelID   common.Address
	Beneficiary common.Address
	ValidUntil  *big.Int
	Signature   []byte
}

func NewExitRequest added in v0.2.0

func NewExitRequest(channelID, beneficiary common.Address, validUntil *big.Int) *ExitRequest

func (ExitRequest) CreateSignature added in v0.2.0

func (er ExitRequest) CreateSignature(ks hashSigner, signer common.Address) ([]byte, error)

func (ExitRequest) GetMessage added in v0.2.0

func (er ExitRequest) GetMessage() []byte

func (ExitRequest) RecoverSigner added in v0.2.0

func (er ExitRequest) RecoverSigner() (common.Address, error)

func (ExitRequest) Sign added in v0.2.0

func (er ExitRequest) Sign(ks *keystore.KeyStore, signer common.Address) error

type Invoice

type Invoice struct {
	AgreementID    *big.Int
	AgreementTotal *big.Int
	TransactorFee  *big.Int
	Hashlock       string
	Provider       string
	ChainID        int64
}

Invoice represent a payment request

func CreateInvoice

func CreateInvoice(agreementID, agreementTotal, transactorFee *big.Int, r []byte, chainID int64) Invoice

CreateInvoice creates new invoice

type PayAndSettleBeneficiaryPayload added in v0.2.0

type PayAndSettleBeneficiaryPayload struct {
	Beneficiary                    common.Address
	Signature                      []byte
	ChainID                        int64
	ProviderChannelIDForWithdrawal string
	Amount                         *big.Int
	R                              [32]byte
}

func NewPayAndSettleBeneficiaryPayload added in v0.2.0

func NewPayAndSettleBeneficiaryPayload(beneficiary common.Address, chainID int64, providerChannelIDForWithdrawal string, amount *big.Int, r [32]byte) *PayAndSettleBeneficiaryPayload

func (*PayAndSettleBeneficiaryPayload) RecoverSigner added in v0.2.0

func (pasp *PayAndSettleBeneficiaryPayload) RecoverSigner() (common.Address, error)

RecoverSigner recovers signer address out of promise signature

func (*PayAndSettleBeneficiaryPayload) Sign added in v0.2.0

func (pasp *PayAndSettleBeneficiaryPayload) Sign(ks hashSigner, signer common.Address) error

type Promise

type Promise struct {
	ChannelID []byte
	ChainID   int64
	Amount    *big.Int
	Fee       *big.Int
	Hashlock  []byte
	R         []byte
	Signature []byte
}

Promise is payment promise object

func CreatePromise

func CreatePromise(channelID string, chainID int64, amount *big.Int, fee *big.Int, hashlock string, ks hashSigner, signer common.Address) (*Promise, error)

CreatePromise creates and signs new payment promise

func NewPromise

func NewPromise(chainID int64, channelID string, amount, fee *big.Int, preimage string, signature string) (*Promise, error)

NewPromise will create new promise, signature can be empty and be created later using `Sign()` method.

func NewRawPromise added in v0.2.0

func NewRawPromise(chainID int64, channelID string, amount, fee *big.Int, hashlock string, signature string) (*Promise, error)

NewRawPromise creates a promise from given params. The promise has no R.

func (Promise) CreateSignature

func (p Promise) CreateSignature(ks hashSigner, signer common.Address) ([]byte, error)

CreateSignature signs promise using keystore

func (Promise) GetHash

func (p Promise) GetHash() []byte

GetHash returns a keccak of payment promise message

func (Promise) GetMessage

func (p Promise) GetMessage() []byte

GetMessage forms the message of payment promise

func (Promise) GetSignatureHexString

func (p Promise) GetSignatureHexString() string

GetSignatureHexString returns signature in hex sting format

func (Promise) IsPromiseValid

func (p Promise) IsPromiseValid(expectedSigner common.Address) bool

IsPromiseValid validates if given promise params are properly signed

func (Promise) RecoverSigner

func (p Promise) RecoverSigner() (common.Address, error)

RecoverSigner recovers signer address out of promise signature

func (*Promise) Sign

func (p *Promise) Sign(ks *keystore.KeyStore, signer common.Address) error

Sign signs promise with given keystore and signer

type ProviderChannelType added in v0.2.0

type ProviderChannelType string
const (
	ProviderChannelTypeDefault      ProviderChannelType = ""
	ProviderChannelTypePayAndSettle ProviderChannelType = "withdrawal"
)

type ReferralTokenRequest added in v0.2.0

type ReferralTokenRequest struct {
	Identity  common.Address
	Signature string
}

func CreateReferralTokenRequest added in v0.2.0

func CreateReferralTokenRequest(ks hashSigner, signer common.Address) (ReferralTokenRequest, error)

CreateSignature signs promise using keystore

func (ReferralTokenRequest) IsValid added in v0.2.0

func (rtr ReferralTokenRequest) IsValid() error

type SetBeneficiaryRequest added in v0.0.13

type SetBeneficiaryRequest struct {
	ChainID     int64    `json:"chainID"`
	Registry    string   `json:"registry"`
	Identity    string   `json:"channelID"`
	Beneficiary string   `json:"beneficiary"`
	Nonce       *big.Int `json:"nonce"`
	Signature   string   `json:"signature"`
}

SetBeneficiaryRequest represents a request for setting new beneficiary.

func CreateBeneficiaryRequest added in v0.0.13

func CreateBeneficiaryRequest(chainID int64, identity, registry, beneficiary string, nonce *big.Int, ks hashSigner, signer common.Address) (*SetBeneficiaryRequest, error)

func NewBeneficiaryRequest added in v0.0.13

func NewBeneficiaryRequest(chainID int64, identity, registry, beneficiary string, nonce *big.Int, signature string) (*SetBeneficiaryRequest, error)

func (SetBeneficiaryRequest) CreateSignature added in v0.0.13

func (r SetBeneficiaryRequest) CreateSignature(ks hashSigner, signer common.Address) ([]byte, error)

CreateSignature signs set beneficiary request using keystore

func (SetBeneficiaryRequest) GetMessage added in v0.0.13

func (r SetBeneficiaryRequest) GetMessage() []byte

GetMessage forms the message payload given the set beneficiary request.

func (SetBeneficiaryRequest) GetSignatureBytesRaw added in v0.0.13

func (r SetBeneficiaryRequest) GetSignatureBytesRaw() []byte

GetSignatureBytesRaw returns the unadulterated bytes of the signature.

func (SetBeneficiaryRequest) RecoverSigner added in v0.0.13

func (r SetBeneficiaryRequest) RecoverSigner() (common.Address, error)

RecoverSigner recovers the signer identity from the given request.

type SignedIdentityRequest added in v1.0.0

type SignedIdentityRequest struct {
	Identity  common.Address `json:"identity,omitempty"`
	Signature string         `json:"signature,omitempty"`
}

func CreateSignedIdentityRequest added in v1.0.0

func CreateSignedIdentityRequest(ks hashSigner, identityToSign, signer common.Address) (SignedIdentityRequest, error)

func (SignedIdentityRequest) RecoverSigner added in v1.0.0

func (sir SignedIdentityRequest) RecoverSigner() (common.Address, error)

Jump to

Keyboard shortcuts

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