common

package
v0.18.2 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package base91 implements base91 encoding, fork from https://github.com/mtraver/base91

Index

Constants

View Source
const (
	SafeChainBitcoin  = bitcoin.ChainBitcoin
	SafeChainLitecoin = bitcoin.ChainLitecoin
	SafeChainEthereum = ethereum.ChainEthereum
	SafeChainPolygon  = ethereum.ChainPolygon

	SafeBitcoinChainId  = "c6d0c728-2624-429b-8e0d-d9d19b6592fa"
	SafeEthereumChainId = "43d61dcd-e413-450d-80b8-101d5e903357"
	SafeLitecoinChainId = "76c802a2-7c88-447f-a93e-c29c9e5dd9c8"
	SafePolygonChainId  = "b7938396-3f94-4e0a-9179-d3440718156f"
)
View Source
const (
	OperationTypeWrapper     = 0
	OperationTypeKeygenInput = 1
	OperationTypeSignInput   = 2

	OperationTypeKeygenOutput = 11
	OperationTypeSignOutput   = 12

	CurveSecp256k1ECDSABitcoin   = 1
	CurveSecp256k1ECDSAEthereum  = 2
	CurveSecp256k1SchnorrBitcoin = 3
	CurveEdwards25519Default     = 4
	CurveEdwards25519Mixin       = 5

	CurveSecp256k1ECDSALitecoin    = 100 + CurveSecp256k1ECDSABitcoin
	CurveSecp256k1ECDSABitcoinCash = 110 + CurveSecp256k1ECDSABitcoin
	CurveSecp256k1ECDSAMVM         = 100 + CurveSecp256k1ECDSAEthereum
	CurveSecp256k1ECDSAPolygon     = 110 + CurveSecp256k1ECDSAEthereum
)
View Source
const (
	RequestRoleHolder   = 1
	RequestRoleSigner   = 2
	RequestRoleObserver = 3

	RequestFlagNone              = 0
	RequestFlagCustomObserverKey = 1

	RequestStateInitial = 1
	RequestStatePending = 2
	RequestStateDone    = 3
	RequestStateFailed  = 4

	ActionMigrateSafeToken = 99

	// Observer can terminate all signer and keeper nodes
	ActionTerminate = 100

	ActionObserverAddKey              = 101
	ActionObserverRequestSignerKeys   = 102
	ActionObserverUpdateNetworkStatus = 103
	ActionObserverHolderDeposit       = 104
	ActionObserverSetOperationParams  = 106

	// For all Bitcoin like chains
	ActionBitcoinSafeProposeAccount     = 110
	ActionBitcoinSafeApproveAccount     = 111
	ActionBitcoinSafeProposeTransaction = 112
	ActionBitcoinSafeApproveTransaction = 113
	ActionBitcoinSafeRevokeTransaction  = 114
	ActionBitcoinSafeCloseAccount       = 115

	// For Mixin Kernel mainnet
	ActionMixinSafeProposeAccount     = 120
	ActionMixinSafeApproveAccount     = 121
	ActionMixinSafeProposeTransaction = 122
	ActionMixinSafeApproveTransaction = 123
	ActionMixinSafeRevokeTransaction  = 124

	// For all Ethereum like chains
	ActionEthereumSafeProposeAccount     = 130
	ActionEthereumSafeApproveAccount     = 131
	ActionEthereumSafeProposeTransaction = 132
	ActionEthereumSafeApproveTransaction = 133
	ActionEthereumSafeRevokeTransaction  = 134
	ActionEthereumSafeCloseAccount       = 135
	ActionEthereumSafeRefundTransaction  = 136

	FlagProposeNormalTransaction   = 0
	FlagProposeRecoveryTransaction = 1
)

Variables

This section is empty.

Functions

func AESDecrypt

func AESDecrypt(secret, b []byte) []byte

func AESEncrypt

func AESEncrypt(secret, b []byte, sid string) []byte

func Base91Decode

func Base91Decode(src string) ([]byte, error)

func Base91Encode

func Base91Encode(src []byte) string

func CheckTestEnvironment

func CheckTestEnvironment(ctx context.Context) bool

func CheckUnique

func CheckUnique(args ...any) bool

func CreateTransactionRequestUntilSufficient added in v0.13.0

func CreateTransactionRequestUntilSufficient(ctx context.Context, client *mixin.Client, id, raw string) (*mixin.SafeTransactionRequest, error)

func DecodeHexOrPanic

func DecodeHexOrPanic(s string) []byte

func ECDHEd25519

func ECDHEd25519(priv, pub string) [32]byte

func EnableTestEnvironment

func EnableTestEnvironment(ctx context.Context) context.Context

func ExpandTilde added in v0.9.6

func ExpandTilde(path string) string

func ExtraLimit added in v0.13.0

func ExtraLimit(tx mixinnet.Transaction) int

func Fingerprint added in v0.3.0

func Fingerprint(public string) []byte

func HandleCORS added in v0.9.3

func HandleCORS(handler http.Handler) http.Handler

TODO may consider a whitelist in the case of Ethereum scams

func HandleNotFound added in v0.9.3

func HandleNotFound(w http.ResponseWriter, r *http.Request)

func HandlePanic added in v0.9.3

func HandlePanic(w http.ResponseWriter, r *http.Request, rcv any)

func MarshalJSONOrPanic added in v0.9.3

func MarshalJSONOrPanic(v any) []byte

func MarshalPanic

func MarshalPanic(m encoding.BinaryMarshaler) []byte

func NormalizeCurve added in v0.2.0

func NormalizeCurve(crv uint8) uint8

func OpenSQLite3ReadOnlyStore

func OpenSQLite3ReadOnlyStore(path string) (*sql.DB, error)

func OpenSQLite3Store

func OpenSQLite3Store(path, schema string) (*sql.DB, error)

func ReadUsers added in v0.13.0

func ReadUsers(ctx context.Context, client *mixin.Client, ids []string) ([]*mixin.User, error)

func RenderError added in v0.9.3

func RenderError(w http.ResponseWriter, r *http.Request, err error)

func RenderJSON added in v0.9.3

func RenderJSON(w http.ResponseWriter, r *http.Request, status int, data any)

func SafeAssetBalance added in v0.13.0

func SafeAssetBalance(ctx context.Context, client *mixin.Client, members []string, threshold int, assetId string) (*common.Integer, error)

func SafeAssetIdChain added in v0.13.0

func SafeAssetIdChain(chainId string) byte

func SafeAssetIdChainNoPanic added in v0.13.0

func SafeAssetIdChainNoPanic(chainId string) byte

func SafeChainAssetId added in v0.13.0

func SafeChainAssetId(chain byte) string

func SafeChainCurve added in v0.13.0

func SafeChainCurve(chain byte) byte

func SafeCurveChain added in v0.13.0

func SafeCurveChain(crv byte) byte

func SafeReadMultisigRequestUntilSufficient added in v0.13.0

func SafeReadMultisigRequestUntilSufficient(ctx context.Context, client *mixin.Client, id string) (*mixin.SafeMultisigRequest, error)

func SafeReadTransactionRequestUntilSufficient added in v0.13.0

func SafeReadTransactionRequestUntilSufficient(ctx context.Context, client *mixin.Client, id string) (*mixin.SafeTransactionRequest, error)

func SendTransactionUntilSufficient

func SendTransactionUntilSufficient(ctx context.Context, client *mixin.Client, members []string, threshold int, receivers []string, receiversThreshold int, amount decimal.Decimal, traceId, assetId, memo, spendPrivateKey string) (*mixin.SafeTransactionRequest, error)

func SignMultisigUntilSufficient added in v0.13.0

func SignMultisigUntilSufficient(ctx context.Context, client *mixin.Client, requestId, raw string, views []mixinnet.Key, members []string, spendPrivateKey string) (*mixin.SafeMultisigRequest, error)

func SignTransactionUntilSufficient added in v0.13.0

func SignTransactionUntilSufficient(ctx context.Context, client *mixin.Client, requestId, raw string, views []mixinnet.Key, spendPrivateKey string) (*mixin.SafeTransactionRequest, error)

func StateName added in v0.3.0

func StateName(state int) string

func UniqueId added in v0.11.0

func UniqueId(a, b string) string

func VerifyKernelTransaction

func VerifyKernelTransaction(ctx context.Context, reader KernelTransactionReader, out *mtg.Action, timeout time.Duration) (*common.VersionedTransaction, error)

TODO the output should include the snapshot signature, then it can just be verified against the active kernel nodes public key

func WriteStorageUntilSufficient added in v0.13.0

func WriteStorageUntilSufficient(ctx context.Context, client *mixin.Client, extra []byte, sTraceId string, su bot.SafeUser) (crypto.Hash, error)

Types

type AccountProposal added in v0.8.0

type AccountProposal struct {
	Receivers []string
	Threshold byte
	Timelock  time.Duration
	Observer  string
}

type Encoding

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

An Encoding is a base 91 encoding/decoding scheme defined by a 91-character alphabet.

func (*Encoding) Decode

func (enc *Encoding) Decode(dst, src []byte) (int, error)

Decode decodes src using the encoding enc. It writes at most DecodedLen(len(src)) bytes to dst and returns the number of bytes written. If src contains invalid base91 data, it will return the number of bytes successfully written and CorruptInputError.

func (*Encoding) DecodedLen

func (enc *Encoding) DecodedLen(n int) int

DecodedLen returns the maximum length in bytes of the decoded data corresponding to n bytes of base91-encoded data.

func (*Encoding) Encode

func (enc *Encoding) Encode(dst, src []byte) int

Encode encodes src using the encoding enc, writing bytes to dst. It returns the number of bytes written, because the exact output size cannot be known before encoding takes place. EncodedLen(len(src)) may be used to determine an upper bound on the output size when allocating a dst slice.

func (*Encoding) EncodedLen

func (enc *Encoding) EncodedLen(n int) int

EncodedLen returns an upper bound on the length in bytes of the base91 encoding of an input buffer of length n. The true encoded length may be shorter.

type KernelTransactionReader added in v0.16.0

type KernelTransactionReader interface {
	ReadKernelTransactionUntilSufficient(ctx context.Context, txHash string) (*common.VersionedTransaction, error)
}

type Operation

type Operation struct {
	Id     string
	Type   uint8
	Curve  uint8
	Public string
	Extra  []byte
}

func DecodeOperation

func DecodeOperation(b []byte) (*Operation, error)

func (*Operation) Encode

func (o *Operation) Encode() []byte

TODO compact format for different type

func (*Operation) IdBytes

func (o *Operation) IdBytes() []byte

type Request

type Request struct {
	Id         string
	MixinHash  crypto.Hash
	MixinIndex int
	AssetId    string
	Amount     decimal.Decimal
	Role       uint8
	Action     uint8
	Curve      uint8
	Holder     string
	ExtraHEX   string
	State      uint8
	CreatedAt  time.Time
	Sequence   uint64

	Output *mtg.Action
}

func DecodeRequest

func DecodeRequest(out *mtg.Action, b []byte, role uint8) (*Request, error)

func (*Request) ExtraBytes added in v0.13.0

func (req *Request) ExtraBytes() []byte

func (*Request) Operation

func (req *Request) Operation() *Operation

func (*Request) ParseMixinRecipient

func (req *Request) ParseMixinRecipient(ctx context.Context, client *mixin.Client, extra []byte) (*AccountProposal, error)

func (*Request) VerifyFormat

func (r *Request) VerifyFormat() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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