tezosprotocol

package module
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2023 License: MIT Imports: 19 Imported by: 0

README

tezosprotocol

godoc CircleCI codecov

An implementation of the Tezos peer-to-peer communications protocol.

Supports offline fee calculation and the parsing, signing, and encoding of Tezos operations.

Installation

$ go get github.com/anchorageoss/tezosprotocol/v3
import "github.com/anchorageoss/tezosprotocol/v3"

Examples

Operation Parsing

Parsing a Tezos wire-format operation:

signedOperationBytes, _ := hex.DecodeString("e655948a282fcfc31b98abe9b37a82038c4c0e9b8e11f60ea0c7b33e6ecc625f6b0002298c03ed7d454a101eb7022bc95f7e5f41ac78e90901904e00004798d2cc98473d7e250c898885718afd2e4efbcb1a1595ab9730761ed830de0f6c0002298c03ed7d454a101eb7022bc95f7e5f41ac78d0860302c8010080c2d72f0000e7670f32038107a59a2b9cfefae36ea21f5aa63c0065667ade71f0c28dcd8c6f443be8b2ff9ebe9f3d2bd8a95d8a29df74319ef24e46bb8abe3e2553dec2a81353f059093861229869ad3c468ade4d9366be3e1308")
var signedOperation tezosprotocol.SignedOperation
_ = signedOperation.UnmarshalBinary(signedOperationBytes)

fmt.Printf("%v\n", signedOperation)
operationHash, _ := signedOperation.GetHash()
fmt.Println(operationHash)
Operation Signing and Encoding

Creating, signing, and encoding a Tezos wire-format operation:

operation := &tezosprotocol.Operation{
	Branch: tezosprotocol.BranchID("BMTiv62VhjkVXZJL9Cu5s56qTAJxyciQB2fzA9vd2EiVMsaucWB"),
	Contents: []tezosprotocol.OperationContents{
		&tezosprotocol.Revelation{
			Source:       tezosprotocol.ContractID("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"),
			Fee:          big.NewInt(1257),
			Counter:      big.NewInt(1),
			GasLimit:     big.NewInt(10000),
			StorageLimit: big.NewInt(0),
			PublicKey:    tezosprotocol.PublicKey("edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav"),
		},
		&tezosprotocol.Transaction{
			Source:       tezosprotocol.ContractID("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"),
			Fee:          big.NewInt(50000),
			Counter:      big.NewInt(2),
			GasLimit:     big.NewInt(200),
			StorageLimit: big.NewInt(0),
			Amount:       big.NewInt(100000000),
			Destination:  tezosprotocol.ContractID("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN"),
		},
	},
}
privateKey := tezosprotocol.PrivateKey("edskRwAubEVzMEsaPYnTx3DCttC8zYrGjzPMzTfDr7jfDaihYuh95CFrrYj6kyJoqYhycQPXMZHsZR5mPQRtDgjY6KHJxpeKnZ")
signedOperation, _ := tezosprotocol.SignOperation(operation, privateKey)
signedOperationBytes, _ := signedOperation.MarshalBinary()
fmt.Printf("%x\n", signedOperationBytes)

Protocol Upgrades

All backwards-incompatible changes will be handled via standard semantic versioning conventions. Separate tags for the latest stable release for each Tezos protocol will be maintained in parallel.

A separate go module will be published for each Tezos protocol upgrade to support applications migrating between the two.

import (
	babylon "github.com/anchorageoss/tezosprotocol/v3"
	athens "github.com/anchorageoss/tezosprotocol"
)

Documentation

Index

Constants

View Source
const (
	// ContractHashLen is the length in bytes of a serialized contract hash
	ContractHashLen = 20
	// ContractIDLen is the length in bytes of a serialized contract ID
	ContractIDLen = 22
)

Field lengths

View Source
const (
	// StorageCostPerByte is the amount of mutez burned per byte of storage used.
	// Reference: https://gitlab.com/tezos/tezos/blob/f5c50c8ba1670b7a2ee58bed8a7806f00c43340c/src/proto_alpha/lib_protocol/constants_repr.ml#L126
	StorageCostPerByte = int64(1000)

	// NewAccountStorageLimitBytes is the storage needed to create a new
	// account, either implicit or originated.
	NewAccountStorageLimitBytes = int64(257)

	// NewAccountCreationBurn is the cost in mutez burned from an account that signs
	// an operation creating a new account, either by a transferring to a new implicit address
	// or by originating a KT1 address. The value is equal to ꜩ0.257
	NewAccountCreationBurn = NewAccountStorageLimitBytes * StorageCostPerByte

	// DefaultMinimalFees is a flat fee that represents the cost of broadcasting
	// an operation to the network. This flat fee is added to the variable minimal
	// fees for gas spent and storage used.
	// Reference: https://gitlab.com/tezos/tezos/blob/f5c50c8ba1670b7a2ee58bed8a7806f00c43340c/src/proto_alpha/lib_client/client_proto_args.ml#L251
	DefaultMinimalFees = int64(100)

	// DefaultMinimalMutezPerGasUnit is the default fee rate in mutez that nodes expect
	// per unit gas spent by an operation (and all its contents).
	// Reference: https://gitlab.com/tezos/tezos/blob/f5c50c8ba1670b7a2ee58bed8a7806f00c43340c/src/proto_alpha/lib_client/client_proto_args.ml#L252
	DefaultMinimalNanotezPerGasUnit = int64(100)

	// DefaultMinimalMutezPerByte is the default fee rate in mutez that nodes expect per
	// byte of a serialized, signed operation -- including header and all contents.
	// Reference: https://gitlab.com/tezos/tezos/blob/f5c50c8ba1670b7a2ee58bed8a7806f00c43340c/src/proto_alpha/lib_client/client_proto_args.ml#L253
	DefaultMinimalNanotezPerByte = int64(1000)

	// RevelationGasLimit is the gas consumed by a revelation
	RevelationGasLimit = int64(10000)

	// RevelationStorageLimitBytes is the storage limit required for revelations. Note that
	// it is zero.
	RevelationStorageLimitBytes = int64(0)

	// RevelationStorageBurn is the amount burned by an account as a consequence
	// of signing a revelation. Note that it is zero.
	RevelationStorageBurn = RevelationStorageLimitBytes * StorageCostPerByte

	// MinimumTransactionGasLimit is the gas consumed by a transaction with no parameters
	// that does not result in any Michelson code execution.
	MinimumTransactionGasLimit = int64(10207)

	// DelegationGasLimit is the gas consumed by a delegation
	DelegationGasLimit = int64(10000)

	// DelegationStorageLimitBytes is the storage limit required for delegations. Note that
	// it is zero.
	DelegationStorageLimitBytes = int64(0)

	// DelegationStorageBurn is the amount burned by an account as a consequence
	// of signing a delegation. Note that it is zero.
	DelegationStorageBurn = DelegationStorageLimitBytes * StorageCostPerByte
)

Common values for fees

View Source
const (
	// PubKeyHashLen is the length in bytes of a serialized public key hash
	PubKeyHashLen = 20
	// TaggedPubKeyHashLen is the length in bytes of a serialized, tagged public key hash
	TaggedPubKeyHashLen = PubKeyHashLen + 1
	// PubKeyLenEd25519 is the length in bytes of a serialized Ed25519 public key
	PubKeyLenEd25519 = 32
	// PubKeyLenSecp256k1 is the length in bytes of a serialized Secp256k1 public key
	PubKeyLenSecp256k1 = 33
	// PubKeyLenP256 is the length in bytes of a serialized P256 public key
	PubKeyLenP256 = 33
)

Field lengths

View Source
const (
	// PrimK_parameter and the remaining constants are adapted from Adapted from
	// https://gitlab.com/tezos/tezos/blob/master/src%2Fproto_alpha%2Flib_protocol%2Fmichelson_v1_primitives.ml
	// They don't follow go's name conventions in order to preserve easy comparison
	// with the original ocaml code and easy updates to keep up with protocol changes
	// The right order is defined in prim_encoding
	PrimK_parameter byte = iota
	PrimK_storage
	PrimK_code
	PrimD_False
	PrimD_Elt
	PrimD_Left
	PrimD_None
	PrimD_Pair
	PrimD_Right
	PrimD_Some
	PrimD_True
	PrimD_Unit
	PrimI_PACK
	PrimI_UNPACK
	PrimI_BLAKE2B
	PrimI_SHA256
	PrimI_SHA512
	PrimI_ABS
	PrimI_ADD
	PrimI_AMOUNT
	PrimI_AND
	PrimI_BALANCE
	PrimI_CAR
	PrimI_CDR
	PrimI_CHECK_SIGNATURE
	PrimI_COMPARE
	PrimI_CONCAT
	PrimI_CONS
	PrimI_CREATE_ACCOUNT
	PrimI_CREATE_CONTRACT
	PrimI_IMPLICIT_ACCOUNT
	PrimI_DIP
	PrimI_DROP
	PrimI_DUP
	PrimI_EDIV
	PrimI_EMPTY_MAP
	PrimI_EMPTY_SET
	PrimI_EQ
	PrimI_EXEC
	PrimI_FAILWITH
	PrimI_GE
	PrimI_GET
	PrimI_GT
	PrimI_HASH_KEY
	PrimI_IF
	PrimI_IF_CONS
	PrimI_IF_LEFT
	PrimI_IF_NONE
	PrimI_INT
	PrimI_LAMBDA
	PrimI_LE
	PrimI_LEFT
	PrimI_LOOP
	PrimI_LSL
	PrimI_LSR
	PrimI_LT
	PrimI_MAP
	PrimI_MEM
	PrimI_MUL
	PrimI_NEG
	PrimI_NEQ
	PrimI_NIL
	PrimI_NONE
	PrimI_NOT
	PrimI_NOW
	PrimI_OR
	PrimI_PAIR
	PrimI_PUSH
	PrimI_RIGHT
	PrimI_SIZE
	PrimI_SOME
	PrimI_SOURCE
	PrimI_SENDER
	PrimI_SELF
	PrimI_STEPS_TO_QUOTA
	PrimI_SUB
	PrimI_SWAP
	PrimI_TRANSFER_TOKENS
	PrimI_SET_DELEGATE
	PrimI_UNIT
	PrimI_UPDATE
	PrimI_XOR
	PrimI_ITER
	PrimI_LOOP_LEFT
	PrimI_ADDRESS
	PrimI_CONTRACT
	PrimI_ISNAT
	PrimI_CAST
	PrimI_RENAME
	PrimT_bool
	PrimT_contract
	PrimT_int
	PrimT_key
	PrimT_key_hash
	PrimT_lambda
	PrimT_list
	PrimT_map
	PrimT_big_map
	PrimT_nat
	PrimT_option
	PrimT_or
	PrimT_pair
	PrimT_set
	PrimT_signature
	PrimT_string
	PrimT_bytes
	PrimT_mutez
	PrimT_timestamp
	PrimT_unit
	PrimT_operation
	PrimT_address
	PrimI_SLICE
	PrimI_DIG
	PrimI_DUG
	PrimI_EMPTY_BIG_MAP
	PrimI_APPLY
	PrimT_chain_id
	PrimI_CHAIN_ID
)
View Source
const (
	// BlockHashLen is the length in bytes of a serialized block hash
	BlockHashLen = 32
	// OperationHashLen is the length in bytes of a serialized operation hash
	OperationHashLen = 32
	// OperationSignatureLen is the length in bytes of a serialized operation signature
	OperationSignatureLen = 64
)

Field lengths

Variables

View Source
var (
	// AllBase58CheckPrefixes is the list of all defined base58check prefixes
	AllBase58CheckPrefixes = []Base58CheckPrefix{}

	PrefixBlockHash = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 32,
		prefixBytes:   []byte{1, 52},
	})
	PrefixOperationHash = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 32,
		prefixBytes:   []byte{5, 116},
	})
	PrefixOperationListHash = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 32,
		prefixBytes:   []byte{133, 233},
	})
	PrefixOperationListListHash = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 32,
		prefixBytes:   []byte{29, 159, 109},
	})
	PrefixProtocolHash = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 32,
		prefixBytes:   []byte{2, 170},
	})
	PrefixContextHash = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 32,
		prefixBytes:   []byte{79, 199},
	})
	PrefixEd25519PublicKeyHash = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 20,
		prefixBytes:   []byte{6, 161, 159},
	})
	PrefixSecp256k1PublicKeyHash = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 20,
		prefixBytes:   []byte{6, 161, 161},
	})
	PrefixP256PublicKeyHash = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 20,
		prefixBytes:   []byte{6, 161, 164},
	})
	PrefixCryptoboxPublicKeyHash = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 16,
		prefixBytes:   []byte{153, 103},
	})
	PrefixEd25519Seed = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 32,
		prefixBytes:   []byte{13, 15, 58, 7},
	})
	PrefixEd25519PublicKey = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 32,
		prefixBytes:   []byte{13, 15, 37, 217},
	})
	PrefixSecp256k1SecretKey = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 32,
		prefixBytes:   []byte{17, 162, 224, 201},
	})
	PrefixP256SecretKey = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 32,
		prefixBytes:   []byte{16, 81, 238, 189},
	})
	PrefixEd25519EncryptedSeed = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 56,
		prefixBytes:   []byte{7, 90, 60, 179, 41},
	})
	PrefixSecp256k1EncryptedSecretKey = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 56,
		prefixBytes:   []byte{9, 237, 241, 174, 150},
	})
	PrefixP256EncryptedSecretKey = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 56,
		prefixBytes:   []byte{9, 48, 57, 115, 171},
	})
	PrefixSecp256k1PublicKey = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 33,
		prefixBytes:   []byte{3, 254, 226, 86},
	})
	PrefixP256PublicKey = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 33,
		prefixBytes:   []byte{3, 178, 139, 127},
	})
	PrefixSecp256k1Scalar = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 33,
		prefixBytes:   []byte{38, 248, 136},
	})
	PrefixSecp256k1Element = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 33,
		prefixBytes:   []byte{5, 92, 0},
	})
	PrefixEd25519SecretKey = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 64,
		prefixBytes:   []byte{43, 246, 78, 7},
	})
	PrefixEd25519Signature = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 64,
		prefixBytes:   []byte{9, 245, 205, 134, 18},
	})
	PrefixSecp256k1Signature = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 64,
		prefixBytes:   []byte{13, 115, 101, 19, 63},
	})
	PrefixP256Signature = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 64,
		prefixBytes:   []byte{54, 240, 44, 52},
	})
	PrefixGenericSignature = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 64,
		prefixBytes:   []byte{4, 130, 43},
	})
	PrefixChainID = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 4,
		prefixBytes:   []byte{87, 82, 0},
	})
	// PrefixContractHash is referenced from https://gitlab.com/tezos/tezos/blob/master/src/proto_alpha/lib_protocol/contract_hash.ml#L26
	PrefixContractHash = registerBase58CheckPrefix(base58CheckPrefixInfo{
		payloadLength: 20,
		prefixBytes:   []byte{2, 90, 121},
	})
)

Base58Check prefixes

View Source
var (
	EntrypointDefault        = Entrypoint{/* contains filtered or unexported fields */}
	EntrypointRoot           = Entrypoint{/* contains filtered or unexported fields */}
	EntrypointDo             = Entrypoint{/* contains filtered or unexported fields */}
	EntrypointSetDelegate    = Entrypoint{/* contains filtered or unexported fields */}
	EntrypointRemoveDelegate = Entrypoint{/* contains filtered or unexported fields */}
)

Preset entrypoints (those with an implicit name)

Functions

func Base58CheckEncode

func Base58CheckEncode(b58Prefix Base58CheckPrefix, input []byte) (string, error)

Base58CheckEncode encodes the given binary payload to base58check. Prefix must be a valid tezos base58check prefix.

func ComputeMinimumFee

func ComputeMinimumFee(gasLimit, operationSizeBytes *big.Int) *big.Int

ComputeMinimumFee returns the minimum fee required according to the constraint:

fees >= (minimal_fees + minimal_nanotez_per_byte * size + minimal_nanotez_per_gas_unit * gas)

Amount returned is in units of mutez. Reference: http://tezos.gitlab.io/mainnet/protocols/003_PsddFKi3.html#baker

func VerifyMessage

func VerifyMessage(message string, signature Signature, publicKey crypto.PublicKey) error

VerifyMessage verifies the signature on a human readable message

Types

type AccountType

type AccountType string

AccountType is either an implicit account or an originated account

const (
	// AccountTypeImplicit indicates an implicit account
	AccountTypeImplicit AccountType = "implicit"
	// AccountTypeOriginated indicates an originated account
	AccountTypeOriginated AccountType = "originated"
)

type Base58CheckPrefix

type Base58CheckPrefix int

Base58CheckPrefix in an enum that models a base58check prefix used specifically by tezos

func Base58CheckDecode

func Base58CheckDecode(input string) (Base58CheckPrefix, []byte, error)

Base58CheckDecode decodes the given base58check string and returns the payload and prefix. Errors if the given string does not include a tezos prefix, or if the checksum does not match.

func (Base58CheckPrefix) PayloadLength

func (b Base58CheckPrefix) PayloadLength() int

PayloadLength is the number of bytes expected to be in the base58 encoded payload

func (Base58CheckPrefix) PrefixBytes

func (b Base58CheckPrefix) PrefixBytes() []byte

PrefixBytes are the bytes to append as a prefix before base58 encoding

func (Base58CheckPrefix) String

func (b Base58CheckPrefix) String() string

String prints a human regodnizable string representation of this prefix

type BranchID

type BranchID string

BranchID encodes a tezos branch ID in base58check encoding

func (BranchID) MarshalBinary

func (b BranchID) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*BranchID) UnmarshalBinary

func (b *BranchID) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler

type ContentsTag

type ContentsTag byte

ContentsTag captures the possible tag values for operation contents

const (
	// ContentsTagRevelation is the tag for revelations
	ContentsTagRevelation ContentsTag = 107
	// ContentsTagTransaction is the tag for transactions
	ContentsTagTransaction ContentsTag = 108
	// ContentsTagOrigination is the tag for originations
	ContentsTagOrigination ContentsTag = 109
	// ContentsTagDelegation is the tag for delegations
	ContentsTagDelegation ContentsTag = 110
	// ContentsTagEndorsement is the tag for endorsements
	ContentsTagEndorsement ContentsTag = 0
)

type ContractID

type ContractID string

ContractID encodes a tezos contract ID (either implicit or originated) in base58check encoding.

func NewContractIDFromOrigination

func NewContractIDFromOrigination(operationHash OperationHash, nonce uint32) (ContractID, error)

NewContractIDFromOrigination returns the address (contract ID) of an account that would be originated by this operation. Nonce disambiguates which account in the case that multiple accounts would be originated by this same operation. Nonce starts at 0 for the first account. AccountType is "originated."

func NewContractIDFromPublicKey

func NewContractIDFromPublicKey(pubKey PublicKey) (ContractID, error)

NewContractIDFromPublicKey creates a new contract ID from a public key. AccountType is "implicit."

func (ContractID) AccountType

func (c ContractID) AccountType() (AccountType, error)

AccountType returns the account type represented by this contract ID

func (ContractID) EncodePubKeyHash

func (c ContractID) EncodePubKeyHash() ([]byte, error)

EncodePubKeyHash returns the public key hash corresponding to this contract ID. This is only possible for implicit addresses, which are themselves just a base58check encoding of a public key hash. Method returns an error for originated addresses, whose public key hashes are not inferrable from their contract ID.

func (ContractID) MarshalBinary

func (c ContractID) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler. Reference: http://tezos.gitlab.io/mainnet/api/p2p.html#contract-id-22-bytes-8-bit-tag

func (*ContractID) UnmarshalBinary

func (c *ContractID) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler. It accepts a 22 byte $contract_id or a 21 byte $public_key_hash

type ContractIDTag

type ContractIDTag byte

ContractIDTag captures the possible tag values for $contract_id

const (
	// ContractIDTagImplicit is the tag for implicit accounts
	ContractIDTagImplicit ContractIDTag = 0
	// ContractIDTagOriginated is the tag for originated accounts
	ContractIDTagOriginated ContractIDTag = 1
)

type ContractScript

type ContractScript struct {
	Code    []byte
	Storage []byte
}

ContractScript models $scripted.contracts

func (ContractScript) MarshalBinary

func (c ContractScript) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler. Reference: http://tezos.gitlab.io/mainnet/api/p2p.html#contract-id-22-bytes-8-bit-tag

func (*ContractScript) UnmarshalBinary

func (c *ContractScript) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

type Delegation

type Delegation struct {
	Source       ContractID
	Fee          *big.Int
	Counter      *big.Int
	GasLimit     *big.Int
	StorageLimit *big.Int
	Delegate     *ContractID
}

Delegation models the tezos delegation operation type

func (*Delegation) GetSource

func (d *Delegation) GetSource() ContractID

GetSource returns the operation's source

func (*Delegation) GetTag

func (d *Delegation) GetTag() ContentsTag

GetTag implements OperationContents

func (*Delegation) MarshalBinary

func (d *Delegation) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler

func (*Delegation) String

func (d *Delegation) String() string

func (*Delegation) UnmarshalBinary

func (d *Delegation) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler

type Endorsement

type Endorsement struct {
	Level int32
}

Endorsement models the tezos endorsement operation type

func (*Endorsement) GetTag

func (e *Endorsement) GetTag() ContentsTag

GetTag implements OperationContents

func (*Endorsement) MarshalBinary

func (e *Endorsement) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler

func (*Endorsement) String

func (e *Endorsement) String() string

func (*Endorsement) UnmarshalBinary

func (e *Endorsement) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler

type Entrypoint

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

Entrypoint models $entrypoint

func NewNamedEntrypoint

func NewNamedEntrypoint(name string) (Entrypoint, error)

NewNamedEntrypoint creates a named entrypoint. This should be used when attempting to invoke a custom entrypoint that is not one of the reserved ones (%default, %root, %do, etcetera...).

func (Entrypoint) MarshalBinary

func (e Entrypoint) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (Entrypoint) Name

func (e Entrypoint) Name() (string, error)

Name returns the entrypoint name

func (Entrypoint) String

func (e Entrypoint) String() string

String implements fmt.Stringer

func (Entrypoint) Tag

func (e Entrypoint) Tag() EntrypointTag

Tag returns the entrypoint tag

func (*Entrypoint) UnmarshalBinary

func (e *Entrypoint) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

type EntrypointTag

type EntrypointTag byte

EntrypointTag captures the possible tag values for $entrypoint.Tag

const (
	EntrypointTagDefault        EntrypointTag = 0
	EntrypointTagRoot           EntrypointTag = 1
	EntrypointTagDo             EntrypointTag = 2
	EntrypointTagSetDelegate    EntrypointTag = 3
	EntrypointTagRemoveDelegate EntrypointTag = 4
	EntrypointTagNamed          EntrypointTag = 255
)

EntrypointTag values

type MichelineBytes

type MichelineBytes []byte

MichelineBytes represents a byte array in a Micheline expression

func (MichelineBytes) MarshalBinary

func (m MichelineBytes) MarshalBinary() ([]byte, error)

MarshalBinary implements the MichelineNode interface

func (*MichelineBytes) UnmarshalBinary

func (m *MichelineBytes) UnmarshalBinary([]byte) error

UnmarshalBinary implements the MichelineNode interface

type MichelineInt

type MichelineInt big.Int

MichelineInt represents an integer in a Micheline expression

func (MichelineInt) MarshalBinary

func (m MichelineInt) MarshalBinary() ([]byte, error)

MarshalBinary implements the MichelineNode interface

func (*MichelineInt) UnmarshalBinary

func (m *MichelineInt) UnmarshalBinary([]byte) error

UnmarshalBinary implements the MichelineNode interface

type MichelineNode

type MichelineNode interface {
	MarshalBinary() ([]byte, error)
	UnmarshalBinary([]byte) error
	// contains filtered or unexported methods
}

MichelineNode represents one node in the tree of Micheline expressions

type MichelinePrim

type MichelinePrim struct {
	Prim   byte
	Args   []MichelineNode
	Annots []string
}

MichelinePrim likely represents a Michelson primitive in a Micheline expression

func (MichelinePrim) MarshalBinary

func (m MichelinePrim) MarshalBinary() ([]byte, error)

MarshalBinary implements the MichelineNode interface

func (*MichelinePrim) UnmarshalBinary

func (m *MichelinePrim) UnmarshalBinary([]byte) error

UnmarshalBinary implements the MichelineNode interface

type MichelineSeq

type MichelineSeq []MichelineNode

MichelineSeq represents a sequence of nodes in a Micheline expression

func (MichelineSeq) MarshalBinary

func (m MichelineSeq) MarshalBinary() ([]byte, error)

MarshalBinary implements the MichelineNode interface

func (*MichelineSeq) UnmarshalBinary

func (m *MichelineSeq) UnmarshalBinary([]byte) error

UnmarshalBinary implements the MichelineNode interface

type MichelineString

type MichelineString string

MichelineString represents a string in a Micheline expression

func (MichelineString) MarshalBinary

func (m MichelineString) MarshalBinary() ([]byte, error)

MarshalBinary implements the MichelineNode interface

func (*MichelineString) UnmarshalBinary

func (m *MichelineString) UnmarshalBinary([]byte) error

UnmarshalBinary implements the MichelineNode interface

type Operation

type Operation struct {
	Branch   BranchID
	Contents []OperationContents
}

Operation models a tezos operation with variable length contents.

func (*Operation) MarshalBinary

func (o *Operation) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler. It encodes the operation unsigned, in the format suitable for signing and transmission.

func (*Operation) SignatureHash

func (o *Operation) SignatureHash() ([]byte, error)

SignatureHash returns the hash of the operation to be signed, including watermark

func (*Operation) String

func (o *Operation) String() string

func (*Operation) UnmarshalBinary

func (o *Operation) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler

type OperationContents

type OperationContents interface {
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler
	fmt.Stringer
	GetTag() ContentsTag
}

OperationContents models one of multiple contents of a tezos operation. Reference: http://tezos.gitlab.io/mainnet/api/p2p.html#operation-alpha-contents-determined-from-data-8-bit-tag

type OperationHash

type OperationHash string

OperationHash encodes an operation hash in base58check encoding

func (OperationHash) MarshalBinary

func (o OperationHash) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*OperationHash) UnmarshalBinary

func (o *OperationHash) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

type Origination

type Origination struct {
	Source       ContractID
	Fee          *big.Int
	Counter      *big.Int
	GasLimit     *big.Int
	StorageLimit *big.Int
	Balance      *big.Int
	Delegate     *ContractID
	Script       ContractScript
}

Origination models the tezos origination operation type.

func (*Origination) GetSource

func (o *Origination) GetSource() ContractID

GetSource returns the operation's source

func (*Origination) GetTag

func (o *Origination) GetTag() ContentsTag

GetTag implements OperationContents

func (*Origination) MarshalBinary

func (o *Origination) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler

func (*Origination) String

func (o *Origination) String() string

func (*Origination) UnmarshalBinary

func (o *Origination) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler

type PrivateKey

type PrivateKey string

PrivateKey encodes a tezos private key in base58check encoding

func NewPrivateKeyFromCryptoPrivateKey

func NewPrivateKeyFromCryptoPrivateKey(cryptoPrivateKey crypto.PrivateKey) (PrivateKey, error)

NewPrivateKeyFromCryptoPrivateKey creates a new PrivateKey from a crypto.PrivateKey

func (PrivateKey) CryptoPrivateKey

func (p PrivateKey) CryptoPrivateKey() (crypto.PrivateKey, error)

CryptoPrivateKey returns a crypto.PrivateKey

func (PrivateKey) MarshalBinary

func (p PrivateKey) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

type PrivateKeySeed

type PrivateKeySeed string

PrivateKeySeed encodes a tezos private key seed in base58check encoding.

func (PrivateKeySeed) PrivateKey

func (p PrivateKeySeed) PrivateKey() (PrivateKey, error)

PrivateKey returns the private key derived from this private key seed.

type PubKeyHashTag

type PubKeyHashTag byte

PubKeyHashTag captures the possible tag values for $public_key_hash

const (
	// PubKeyHashTagEd25519 is the tag for Ed25519 pubkey hashes
	PubKeyHashTagEd25519 PubKeyHashTag = 0
	// PubKeyHashTagSecp256k1 is the tag for Secp256k1 pubkey hashes
	PubKeyHashTagSecp256k1 PubKeyHashTag = 1
	// PubKeyHashTagP256 is the tag for P256 pubkey hashes
	PubKeyHashTagP256 PubKeyHashTag = 2
)

type PubKeyTag

type PubKeyTag byte

PubKeyTag captures the possible tag values for $public_key

const (
	// PubKeyTagEd25519 is the tag for Ed25519 pubkeys
	PubKeyTagEd25519 PubKeyTag = 0
	// PubKeyTagSecp256k1 is the tag for Secp256k1 pubkeys
	PubKeyTagSecp256k1 PubKeyTag = 1
	// PubKeyTagP256 is the tag for P256 pubkeys
	PubKeyTagP256 PubKeyTag = 2
)

type PublicKey

type PublicKey string

PublicKey encodes a tezos public key in base58check encoding

func NewPublicKeyFromCryptoPublicKey

func NewPublicKeyFromCryptoPublicKey(cryptoPubKey crypto.PublicKey) (PublicKey, error)

NewPublicKeyFromCryptoPublicKey creates a new PublicKey from a crypto.PublicKey

func (PublicKey) CryptoPublicKey

func (p PublicKey) CryptoPublicKey() (crypto.PublicKey, error)

CryptoPublicKey returns a crypto.PublicKey

func (PublicKey) MarshalBinary

func (p PublicKey) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler. Reference: http://tezos.gitlab.io/mainnet/api/p2p.html#public-key-determined-from-data-8-bit-tag

func (*PublicKey) UnmarshalBinary

func (p *PublicKey) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler

type Revelation

type Revelation struct {
	Source       ContractID
	Fee          *big.Int
	Counter      *big.Int
	GasLimit     *big.Int
	StorageLimit *big.Int
	PublicKey    PublicKey
}

Revelation models the revelation operation type

func (*Revelation) GetSource

func (r *Revelation) GetSource() ContractID

GetSource returns the operation's source

func (*Revelation) GetTag

func (r *Revelation) GetTag() ContentsTag

GetTag implements OperationContents

func (*Revelation) MarshalBinary

func (r *Revelation) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler

func (*Revelation) String

func (r *Revelation) String() string

func (*Revelation) UnmarshalBinary

func (r *Revelation) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler

type Signature

type Signature string

Signature is a tezos base58check encoded signature. It may be in either the generic or non-generic format.

func SignMessage

func SignMessage(message string, privateKey PrivateKey) (Signature, error)

SignMessage signs the given text based message using the provided signing key. It returns the base58check-encoded signature which does not include the message. It uses the 0x04 non-standard watermark.

func (Signature) MarshalBinary

func (s Signature) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler

type SignedOperation

type SignedOperation struct {
	Operation *Operation
	Signature Signature
}

SignedOperation represents a signed operation

func SignOperation

func SignOperation(operation *Operation, privateKey PrivateKey) (SignedOperation, error)

SignOperation signs the given tezos operation using the provided signing key. The returned bytes are the signed operation, encoded as (operation bytes || signature bytes).

func (SignedOperation) GetHash

func (s SignedOperation) GetHash() (OperationHash, error)

GetHash returns the hash of a signed operation.

func (SignedOperation) MarshalBinary

func (s SignedOperation) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler

func (*SignedOperation) UnmarshalBinary

func (s *SignedOperation) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler. In cases where the signature type cannot be inferred, PrefixGenericSignature is used instead.

type Transaction

type Transaction struct {
	Source       ContractID
	Fee          *big.Int
	Counter      *big.Int
	GasLimit     *big.Int
	StorageLimit *big.Int
	Amount       *big.Int
	Destination  ContractID
	Parameters   *TransactionParameters
}

Transaction models the tezos transaction type

func (*Transaction) GetSource

func (t *Transaction) GetSource() ContractID

GetSource returns the operation's source

func (*Transaction) GetTag

func (t *Transaction) GetTag() ContentsTag

GetTag implements OperationContents

func (*Transaction) MarshalBinary

func (t *Transaction) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler

func (*Transaction) String

func (t *Transaction) String() string

func (*Transaction) UnmarshalBinary

func (t *Transaction) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler

type TransactionParameters

type TransactionParameters struct {
	Entrypoint Entrypoint
	Value      TransactionParametersValue
}

TransactionParameters models $X_o. Reference: http://tezos.gitlab.io/babylonnet/api/p2p.html#x-0

func (TransactionParameters) MarshalBinary

func (t TransactionParameters) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*TransactionParameters) UnmarshalBinary

func (t *TransactionParameters) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler.

type TransactionParametersValue

type TransactionParametersValue interface {
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler
}

TransactionParametersValue models $X_o.value

type TransactionParametersValueRawBytes

type TransactionParametersValueRawBytes []byte

TransactionParametersValueRawBytes is an interim way to provide the value for transaction parameters, until support for Michelson is added.

func (*TransactionParametersValueRawBytes) MarshalBinary

func (t *TransactionParametersValueRawBytes) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*TransactionParametersValueRawBytes) UnmarshalBinary

func (t *TransactionParametersValueRawBytes) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

type Watermark

type Watermark byte

Watermark is the first byte of a signable payload that indicates the type of data represented.

const (
	// BlockHeaderWatermark is the special byte prepended to serialized block headers before signing
	BlockHeaderWatermark Watermark = 1
	// EndorsementWatermark is the special byte prepended to serialized endorsements before signing
	EndorsementWatermark Watermark = 2
	// OperationWatermark is the special byte prepended to serialized operations before signing
	OperationWatermark Watermark = 3
	// CustomWatermark is for custom purposes
	CustomWatermark Watermark = 4
	// TextWatermark is the special byte prepended to plaintext messages before signing. It is not
	// yet part of the standard but has some precedent here:
	// https://tezos.stackexchange.com/questions/1177/whats-the-easiest-way-for-an-account-holder-to-verify-sign-that-they-are-the-ri/1178#1178
	TextWatermark Watermark = 5
)

References: https://gitlab.com/tezos/tezos/blob/master/src/lib_crypto/signature.ml#L43

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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