bbclib

package module
v0.0.0-...-464effc Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

README

bbclib-go

License Build Status Go Report Card Coverage Status Maintainability

This repo is now obsoleted, and move to https://github.com/beyond-blockchain/bbclib-go.git

Golang implementation of bbc1.core.bbclib and bbc1.core.libs modules in https://github.com/beyond-blockchain/bbc1

Features
dependencies

Usage

go get -u github.com/quvox/bbclib-go

Building an external library is also required. When "go get" is done, you will find github.com/quvox/bbclib-go/ directory in ${GOPATH}/src. Then, execute the following commands:

cd ${GOPATH}/src/github.com/quvox/bbclib-go
bash prepare.sh

If you want to use this module in an AWS environment (EC2 or Lambda), do as follows:

cd ${GOPATH}/github.com/quvox/bbclib-go
bash prepare.sh aws

The preparation script (prepare.sh) produces libbbcsig.a, which is a static link library for signing/verifying a transaction. Building libbbcsig.a takes long time, so be patient.

After finishing the compilation, you are ready for "go install".

go install github.com/quvox/bbclib-go

NOTE: example/ directory includes a sample code for this module. There are a document and a preparation script.

Prepare for development (module itself)

For linux/mac

sh prepare.sh

For Amazon Lambda, you need docker and do the following:

sh prepare.sh aws

After finishing prepare.sh script, you will find libbbcsig.a and libbbcsig.h, which are used by keypair.go for signing/verifying.

Documentation

Overview

Package bbclib is a library for defining BBcTransaction. This also provides serializer/deserializer and utilities for BBcTransaction object manipulation.

Serialization and deserialization

A BBcTransaction object contains various object, such as BBcEvent, BBcSignature. In order to store a BBcTransaction object in DB or send it to other host, the object must be serialized. Before serialization, the object is packed, meaning that it is transformed into binary format. Then, the header is prepended to the packed data, resulting in a serialized data. According to the header value, the packed data is compressed, so that you will get a smaller-sized serialized data. Deserialization is the opposite transformation to serialization.

Utility functions

To build a BBcTransaction you need to create (new) objects you want to include. In many cases, it is a kind of common coding manner. The utility functions are helpers to build a BBcTransaction with various objects.

Index

Constants

View Source
const (
	FormatPlain = 0x0000
	FormatZlib  = 0x0010
)

Header values for serialized data

View Source
const (
	KeyTypeNotInitialized = 0
	KeyTypeEcdsaSECP256k1 = 1
	KeyTypeEcdsaP256v1    = 2
)

Supported ECC curve type is SECP256k1 and Prime-256v1.

View Source
const (
	DomainIDLength = 32
)

The length of DomainID must be 256-bit in any domain.

Variables

This section is empty.

Functions

func AddEventAssetBodyObject

func AddEventAssetBodyObject(transaction *BBcTransaction, eventIdx int, assetGroupID, userID *[]byte, body interface{})

AddEventAssetBodyObject sets an object (map[string]interface{}) to a BBcAsset object in a BBcEvent object and then, add it in a BBcTransaction object

func AddEventAssetBodyString

func AddEventAssetBodyString(transaction *BBcTransaction, eventIdx int, assetGroupID, userID *[]byte, body string)

AddEventAssetBodyString sets a string to a BBcAsset object in a BBcEvent object and then, add it in a BBcTransaction object

func AddEventAssetFile

func AddEventAssetFile(transaction *BBcTransaction, eventIdx int, assetGroupID, userID *[]byte, assetFile *[]byte)

AddEventAssetFile sets a file digest to a BBcAsset object in a BBcEvent object and then, add it in a BBcTransaction object

func AddPointerInRelation

func AddPointerInRelation(relation *BBcRelation, refTransaction *BBcTransaction, refAssetID *[]byte)

AddPointerInRelation creates and includes a BBcPointer object in BBcRelation

func AddReference

func AddReference(transaction *BBcTransaction, assetGroupID *[]byte, refTransaction *BBcTransaction, eventIdx int)

AddReference creates and includes a BBcReference object in a BBcTransaction object

func AddRelationAssetBodyObject

func AddRelationAssetBodyObject(transaction *BBcTransaction, relationIdx int, assetGroupID, userID *[]byte, body interface{})

AddRelationAssetBodyObject sets an object (map[string]interface{}) in BBcAsset in BBcRelation, convert the info into msgpack, and add it in a BBcTransaction object

func AddRelationAssetBodyString

func AddRelationAssetBodyString(transaction *BBcTransaction, relationIdx int, assetGroupID, userID *[]byte, body string)

AddRelationAssetBodyString sets a string in BBcAsset in BBcRelation and add it to a BBcTransaction object

func AddRelationAssetFile

func AddRelationAssetFile(transaction *BBcTransaction, relationIdx int, assetGroupID, userID, assetFile *[]byte)

AddRelationAssetFile sets a file digest to BBcAsset in BBcRelation and add it to a BBcTransaction object

func AddRelationPointer

func AddRelationPointer(transaction *BBcTransaction, relationIdx int, refTransactionID, refAssetID *[]byte)

AddRelationPointer creates and includes a BBcPointer object in BBcRelation and then, add it in a BBcTransaction object

func Get2byte

func Get2byte(buf *bytes.Buffer) (uint16, error)

Get2byte returns a uint16 value from the buffer

func Get4byte

func Get4byte(buf *bytes.Buffer) (uint32, error)

Get4byte returns a uint32 value from the buffer

func Get8byte

func Get8byte(buf *bytes.Buffer) (int64, error)

Get8byte returns a int64 value from the buffer

func GetBigInt

func GetBigInt(buf *bytes.Buffer) ([]byte, error)

GetBigInt returns a ID data from the buffer

func GetBytes

func GetBytes(buf *bytes.Buffer, length int) ([]byte, error)

GetBytes returns binary data with specified length from the buffer

func GetIdentifier

func GetIdentifier(seed string, length int) []byte

GetIdentifier returns a random byte data with specified length (seed string ais used)

func GetIdentifierWithTimestamp

func GetIdentifierWithTimestamp(seed string, length int) []byte

GetIdentifierWithTimestamp returns a random byte data with specified length (seed string and timestamp are used)

func GetRandomValue

func GetRandomValue(length int) []byte

GetRandomValue returns a random byte data with specified length

func Put2byte

func Put2byte(buf *bytes.Buffer, val uint16)

Put2byte sets uint16 in the buffer for packing

func Put4byte

func Put4byte(buf *bytes.Buffer, val uint32)

Put4byte sets a uint32 in the buffer for packing

func Put8byte

func Put8byte(buf *bytes.Buffer, val int64)

Put8byte sets a int64 in the buffer for packing

func PutBigInt

func PutBigInt(buf *bytes.Buffer, val *[]byte, length int)

PutBigInt sets a ID data in the buffer for packing

func Serialize

func Serialize(transaction *BBcTransaction, formatType uint16) ([]byte, error)

Serialize BBcTransaction object into packed data

formatType = 0x0000: Packed data is simply used for serialized data.

formatType = 0x0010: Packed data is compressed using zlib, and the compressed data is used for serialized data.

func SignToTransaction

func SignToTransaction(transaction *BBcTransaction, userID *[]byte, keypair *KeyPair)

SignToTransaction signs the transaction and append the BBcSignature object to it

func VerifyBBcSignature

func VerifyBBcSignature(digest []byte, sig *BBcSignature) bool

VerifyBBcSignature verifies a given digest with BBcSignature object

func ZlibCompress

func ZlibCompress(dat *[]byte) []byte

ZlibCompress compresses the given data using zlib

func ZlibDecompress

func ZlibDecompress(dat []byte) ([]byte, error)

ZlibDecompress decompresses the given data using zlib

Types

type BBcAsset

type BBcAsset struct {
	IDLength int

	AssetID         []byte
	UserID          []byte
	Nonce           []byte
	AssetFileSize   uint32
	AssetFileDigest []byte
	AssetBodyType   uint16
	AssetBodySize   uint16
	AssetBody       []byte
	// contains filtered or unexported fields
}

BBcAsset definition

"IDLength" and "digestCalculating" are not included in a packed data. They are for internal use only.

"AssetID" is the SHA256 digest of packed BBcAsset data, which contains from "UserID" to "AssetBody". The length of "AssetID" and "UserID" is defined by "IDLength". "Nonce" is automatically determined with random value. BBcAsset can contain a digest of a file, string, map[string]interface{} object as asset.

func (*BBcAsset) Add

func (p *BBcAsset) Add(userID *[]byte)

Add sets userID in the BBcAsset object

func (*BBcAsset) AddBodyObject

func (p *BBcAsset) AddBodyObject(bodyContent interface{}) error

AddBodyObject sets an object data in the BBcAsset object and convert it in MessagePack format

func (*BBcAsset) AddBodyString

func (p *BBcAsset) AddBodyString(bodyContent string)

AddBodyString sets a string data in the BBcAsset object

func (*BBcAsset) AddFile

func (p *BBcAsset) AddFile(fileContent *[]byte)

AddFile add the digest of file in the BBcAsset object Note that this method adds the SHA256 digest of the file content (not file binary itself)

func (*BBcAsset) Digest

func (p *BBcAsset) Digest() []byte

Digest calculates the SHA256 digest of the AssetID value of the BBcAsset object

func (*BBcAsset) GetBodyObject

func (p *BBcAsset) GetBodyObject() (interface{}, error)

GetBodyObject returns the object which is in MessagePack format

func (*BBcAsset) Pack

func (p *BBcAsset) Pack() ([]byte, error)

Pack returns the binary data of the BBcAsset object

func (*BBcAsset) Stringer

func (p *BBcAsset) Stringer() string

Stringer outputs the content of the object

func (*BBcAsset) Unpack

func (p *BBcAsset) Unpack(dat *[]byte) error

Unpack the BBcAsset object to the binary data

type BBcCrossRef

type BBcCrossRef struct {
	IDLength      int
	DomainID      []byte
	TransactionID []byte
}

BBcCrossRef definition

CrossRef stands for CrossReference, which holds information in other domain for inter-domain collaboration of transaction authenticity.

"IDLength" is not included in a packed data. It is for internal use only.

"DomainID" is the identifier of a domain and the length of the ID must be 256 bits (=32 bytes). "TransactionID" is that of transaction object in other domain (specified by the DomainID).

func (*BBcCrossRef) Add

func (p *BBcCrossRef) Add(domainID *[]byte, txid *[]byte)

Add sets essential information to the BBcCrossRef object

func (*BBcCrossRef) Pack

func (p *BBcCrossRef) Pack() ([]byte, error)

Pack returns binary data from the BBcCrossRef object

func (*BBcCrossRef) Stringer

func (p *BBcCrossRef) Stringer() string

Stringer outputs the content of the object

func (*BBcCrossRef) Unpack

func (p *BBcCrossRef) Unpack(dat *[]byte) error

Unpack the binary data to the BBcCrossRef object

type BBcEvent

type BBcEvent struct {
	IDLength                     int
	AssetGroupID                 []byte
	ReferenceIndices             []int
	MandatoryApprovers           [][]byte
	OptionApproverNumNumerator   uint16
	OptionApproverNumDenominator uint16
	OptionApprovers              [][]byte
	Asset                        *BBcAsset
}

BBcEvent definition

BBcEvent expresses an output of UTXO (Unspent Transaction Output) structure.

"AssetGroupID" distinguishes a type of asset, e.g., token-X, token-Y, Movie content, etc..

"ReferenceIndices" has the index numbers in BBcReference object list in the transaction object. It expresses that this BBcEvent object has a certain relationship with the BBcReference objects specified by ReferenceIndices. This would be used in the case that the transaction object has multiple BBcReference objects.

BBcEvent designates Mandatory/Option Approvers to be signers to a BBcTransaction in the future, which use the asset in the BBcEvent. As for "OptionApprovers", it is enough that some of them give sign to the BBcTransaction. The number of signers to be included is "OptionApproverNumNumerator".

Asset is the most important part of the BBcTransaction. The BBcAsset object includes the digital asset to be protected by BBc-1.

"IDLength" is not included in a packed data. It is for internal use only.

func (*BBcEvent) Add

func (p *BBcEvent) Add(assetGroupID *[]byte, asset *BBcAsset)

Add sets essential information to the BBcEvent object

func (*BBcEvent) AddMandatoryApprover

func (p *BBcEvent) AddMandatoryApprover(userID *[]byte)

AddMandatoryApprover sets userID in MandatoryApprover list of the BBcEvent object

func (*BBcEvent) AddOptionApprover

func (p *BBcEvent) AddOptionApprover(userID *[]byte)

AddOptionApprover sets userID in OptionApprover list of the BBcEvent object

func (*BBcEvent) AddOptionParams

func (p *BBcEvent) AddOptionParams(numerator int, denominator int)

AddOptionParams sets values to OptionApproverNumNumerator and OptionApproverNumDenominator in the BBcEvent object

func (*BBcEvent) AddReferenceIndex

func (p *BBcEvent) AddReferenceIndex(relIndex int)

AddReferenceIndex sets an index to ReferenceIndices of the BBcEvent object

func (*BBcEvent) Pack

func (p *BBcEvent) Pack() ([]byte, error)

Pack returns the binary data of the BBcEvent object

func (*BBcEvent) Stringer

func (p *BBcEvent) Stringer() string

Stringer outputs the content of the object

func (*BBcEvent) Unpack

func (p *BBcEvent) Unpack(dat *[]byte) error

Unpack the binary data to the BBcEvent object

type BBcPointer

type BBcPointer struct {
	IDLength      int
	TransactionID []byte
	AssetID       []byte
}

BBcPointer definition

BBcPointer(s) are included in BBcRelation object. A BBcPointer object includes "TransactionID" and "AssetID" and declares that the transaction has a certain relationship with the BBcTransaction and BBcAsset object specified by those IDs.

IDLength is not included in a packed data. It is for internal use only.

func (*BBcPointer) Add

func (p *BBcPointer) Add(txid *[]byte, asid *[]byte)

Add sets essential information to the BBcPointer object

func (*BBcPointer) Pack

func (p *BBcPointer) Pack() ([]byte, error)

Pack returns the binary data of the BBcPointer object

func (*BBcPointer) Stringer

func (p *BBcPointer) Stringer() string

Stringer outputs the content of the object

func (*BBcPointer) Unpack

func (p *BBcPointer) Unpack(dat *[]byte) error

Unpack the BBcPointer object to the binary data

type BBcReference

type BBcReference struct {
	IDLength        int
	AssetGroupID    []byte
	TransactionID   []byte
	EventIndexInRef uint16
	SigIndices      []int
	Transaction     *BBcTransaction
	RefTransaction  *BBcTransaction
	RefEvent        BBcEvent
}

BBcReference definition

The BBcReference is an input of UTXO (Unspent Transaction Output) structure and this object must accompanied by a BBcEvent object because it is an output of UTXO.

"AssetGroupID" distinguishes a type of asset, e.g., token-X, token-Y, Movie content, etc.. "TransactionID" is that of a certain transaction in the past. "EventIndexInRef" points to the BBcEvent object in the past BBcTransaction. "SigIndices" is a mapping info between userID and the position (index) of the signature list in the BBcTransaction object.

"Transaction" is the pointer to the parent BBcTransaction object, and "RefTransaction" is the pointer to the past BBcTransaction object.

"IDLength", "Transaction", "RefTransaction" and "RefEvent" are not included in a packed data. They are for internal use only.

func (*BBcReference) Add

func (p *BBcReference) Add(assetGroupID *[]byte, refTransaction *BBcTransaction, eventIdx int)

Add sets essential information to the BBcReference object

func (*BBcReference) AddApprover

func (p *BBcReference) AddApprover(userID *[]byte) error

AddApprover makes a memo for managing approvers who sign this BBcTransaction object

func (*BBcReference) AddSignature

func (p *BBcReference) AddSignature(userID *[]byte, sig *BBcSignature) error

AddSignature sets the BBcSignature object in the object

func (*BBcReference) Pack

func (p *BBcReference) Pack() ([]byte, error)

Pack returns the binary data of the BBcReference object

func (*BBcReference) SetTransaction

func (p *BBcReference) SetTransaction(txobj *BBcTransaction)

SetTransaction links the BBcReference object to the parent transaction object

func (*BBcReference) Stringer

func (p *BBcReference) Stringer() string

Stringer outputs the content of the object

func (*BBcReference) Unpack

func (p *BBcReference) Unpack(dat *[]byte) error

Unpack the BBcReference object to the binary data

type BBcRelation

type BBcRelation struct {
	IDLength     int
	AssetGroupID []byte
	Pointers     []*BBcPointer
	Asset        *BBcAsset
}

BBcRelation definition

The BBcRelation holds the asset (by BBcAsset) and the relationship with the other transaction/asset (by BBcPointer). Different from UTXO, state information or account-type information can be expressed by using this object. If you want to include signature(s) according to the contents of BBcRelation object, BBcWitness should be included in the transaction object.

"AssetGroupID" distinguishes a type of asset, e.g., token-X, token-Y, Movie content, etc.. "Pointers" is a list of BBcPointers object. "Asset" is a BBcAsset object.

"IDLength" is not included in a packed data. It is for internal use only.

func MakeRelationWithAsset

func MakeRelationWithAsset(assetGroupID, userID *[]byte, assetBodyString string, assetBodyObject interface{}, assetFile *[]byte, idLength int) *BBcRelation

MakeRelationWithAsset is a utility for making simple BBcTransaction object with BBcRelation with BBcAsset

func (*BBcRelation) Add

func (p *BBcRelation) Add(assetGroupID *[]byte, asset *BBcAsset)

Add sets essential information (assetGroupID and BBcAsset object) to the BBcRelation object

func (*BBcRelation) AddPointer

func (p *BBcRelation) AddPointer(pointer *BBcPointer)

AddPointer sets the BBcPointer object in the object

func (*BBcRelation) Pack

func (p *BBcRelation) Pack() ([]byte, error)

Pack returns the binary data of the BBcRelation object

func (*BBcRelation) Stringer

func (p *BBcRelation) Stringer() string

Stringer outputs the content of the object

func (*BBcRelation) Unpack

func (p *BBcRelation) Unpack(dat *[]byte) error

Unpack the BBcRelation object to the binary data

type BBcSignature

type BBcSignature struct {
	KeyType      uint32
	Pubkey       []byte
	PubkeyLen    uint32
	Signature    []byte
	SignatureLen uint32
}

BBcSignature definition

The BBcSignature holds public key and signature. The signature is for the TransactionID of the transaction object.

func RecoverSignatureObject

func RecoverSignatureObject(dat *[]byte) *BBcSignature

RecoverSignatureObject is a utility for recovering signature data into BBcSignature object

func (*BBcSignature) Pack

func (p *BBcSignature) Pack() ([]byte, error)

Pack returns the binary data of the BBcSignature object

func (*BBcSignature) SetPublicKey

func (p *BBcSignature) SetPublicKey(keyType uint32, pubkey *[]byte)

SetPublicKey sets signature binary in the object

func (*BBcSignature) SetPublicKeyByKeypair

func (p *BBcSignature) SetPublicKeyByKeypair(keypair *KeyPair)

SetPublicKeyByKeypair sets public key (in keypair object) in the object

func (*BBcSignature) SetSignature

func (p *BBcSignature) SetSignature(sig *[]byte)

SetSignature sets signature binary in the object

func (*BBcSignature) Stringer

func (p *BBcSignature) Stringer() string

Stringer outputs the content of the object

func (*BBcSignature) Unpack

func (p *BBcSignature) Unpack(dat *[]byte) error

Unpack the BBcSignature object to the binary data

func (*BBcSignature) Verify

func (p *BBcSignature) Verify(digest []byte) bool

Verify the TransactionID of the parent BBcTransaction object with the signature in the object

type BBcTransaction

type BBcTransaction struct {
	TransactionID         []byte
	TransactionBaseDigest []byte
	TransactionData       []byte
	SigIndices            [][]byte
	Version               uint32
	Timestamp             int64
	IDLength              int
	Events                []*BBcEvent
	References            []*BBcReference
	Relations             []*BBcRelation
	Witness               *BBcWitness
	Crossref              *BBcCrossRef
	Signatures            []*BBcSignature
	// contains filtered or unexported fields
}

BBcTransaction definition

BBcTransaction is just a container of various objects.

Events, References, Relations and Signatures are list of BBcEvent, BBcReference, BBcRelation and BBcSignature objects, respectively. "digestCalculating", "TransactionBaseDigest", "TransactionData" and "SigIndices" are not included in the packed data. They are internal use only.

Calculating TransactionID

How to calculate the TransactionID of the transaction is a little bit complicated, meaning that 2-step manner. This is because inter-domain transaction authenticity (i.e., CrossReference) can be conducted in secure manner. By presenting TransactionBaseDigest (see below) to an outer-domain, the domain user can confirm the existence of the transaction in the past. (no need to present whole transaction data including the asset information).

1st step:

  • Pack info (from version to Witness) by packBase()
  • Calculate SHA256 digest of the packed info. This value is TransactionBaseDigest.

2nd step:

  • Pack BBcCrossRef object to get packed data by packCrossRef()
  • Concatenate TransactionBaseDigest and the packed BBcCrossRef
  • Calculate SHA256 digest of the concatenated data. This value is TransactionID

func Deserialize

func Deserialize(dat []byte) (*BBcTransaction, error)

Deserialize BBcTransaction data with header

func MakeTransaction

func MakeTransaction(eventNum, relationNum int, witness bool, idLength int) *BBcTransaction

MakeTransaction is a utility for making simple BBcTransaction object with BBcEvent, BBcRelation or/and BBcWitness

func (*BBcTransaction) AddCrossRef

func (p *BBcTransaction) AddCrossRef(obj *BBcCrossRef)

AddCrossRef sets the BBcCrossRef object in the transaction object

func (*BBcTransaction) AddEvent

func (p *BBcTransaction) AddEvent(obj *BBcEvent)

AddEvent adds the BBcEvent object in the transaction object

func (*BBcTransaction) AddReference

func (p *BBcTransaction) AddReference(obj *BBcReference)

AddReference adds the BBcReference object in the transaction object

func (*BBcTransaction) AddRelation

func (p *BBcTransaction) AddRelation(obj *BBcRelation)

AddRelation adds the BBcRelation object in the transaction object

func (*BBcTransaction) AddSignature

func (p *BBcTransaction) AddSignature(userID *[]byte, sig *BBcSignature)

AddSignature adds the BBcSignature object for the specified userID in the transaction object

func (*BBcTransaction) AddWitness

func (p *BBcTransaction) AddWitness(obj *BBcWitness)

AddWitness sets the BBcWitness object in the transaction object

func (*BBcTransaction) Digest

func (p *BBcTransaction) Digest() []byte

Digest calculates TransactionID of the BBcTransaction object

func (*BBcTransaction) GetSigIndex

func (p *BBcTransaction) GetSigIndex(userID []byte) int

GetSigIndex reserves and returns the position (index) of the corespondent userID in the signature list

func (*BBcTransaction) Pack

func (p *BBcTransaction) Pack() ([]byte, error)

Pack BBcTransaction object in binary data

func (*BBcTransaction) Sign

func (p *BBcTransaction) Sign(keypair *KeyPair) ([]byte, error)

Sign TransactionID using private key in the given keypair

func (*BBcTransaction) Stringer

func (p *BBcTransaction) Stringer() string

Stringer outputs the content of the object

func (*BBcTransaction) Unpack

func (p *BBcTransaction) Unpack(dat *[]byte) error

Unpack binary data to BBcTransaction object

func (*BBcTransaction) VerifyAll

func (p *BBcTransaction) VerifyAll() (bool, int)

VerifyAll verifies TransactionID with all BBcSignature objects in the transaction

type BBcWitness

type BBcWitness struct {
	IDLength    int
	UserIDs     [][]byte
	SigIndices  []int
	Transaction *BBcTransaction
}

BBcWitness definition

The BBcWitness has the mapping info between the userIDs and BBcSignature objects. This object should be used if BBcRelation is used or a certain user wants to sign to the transaction in some reason.

"UserIDs" is the list of userID, and "SigIndices" is a mapping info between userID and the position (index) of the signature list in the BBcTransaction object.

"Transaction" is the pointer to the parent BBcTransaction object.

"IDLength" and "Transaction" are not included in a packed data. They are for internal use only.

func (*BBcWitness) AddSignature

func (p *BBcWitness) AddSignature(userID *[]byte, sig *BBcSignature) error

AddSignature sets the BBcSignature to the parent BBcTransaction and the position in the Signatures list in BBcTransaction is based on the UserID

func (*BBcWitness) AddWitness

func (p *BBcWitness) AddWitness(userID *[]byte) error

AddWitness makes a memo for managing signer who sign this BBcTransaction object This must be done before AddSignature.

func (*BBcWitness) Pack

func (p *BBcWitness) Pack() ([]byte, error)

Pack returns the binary data of the BBcWitness object

func (*BBcWitness) SetTransaction

func (p *BBcWitness) SetTransaction(txobj *BBcTransaction)

SetTransaction links the BBcWitness object to the parent transaction object

func (*BBcWitness) Stringer

func (p *BBcWitness) Stringer() string

Stringer outputs the content of the object

func (*BBcWitness) Unpack

func (p *BBcWitness) Unpack(dat *[]byte) error

Unpack the BBcWitness object to the binary data

type KeyPair

type KeyPair struct {
	CurveType int
	Pubkey    []byte
	Privkey   []byte
}

KeyPair definition

A KeyPair object hold a pair of private key and public key. This object includes functions for sign and verify a signature. The sign/verify functions is realized by "libbbcsig".

func GenerateKeypair

func GenerateKeypair(curveType int, compressionMode int) KeyPair

GenerateKeypair generates a new Key pair object with new private key and public key

func (*KeyPair) ConvertFromPem

func (k *KeyPair) ConvertFromPem(pem string, compressionMode int)

ConvertFromPem outputs PEM formatted public key

func (*KeyPair) Sign

func (k *KeyPair) Sign(digest []byte) []byte

Sign to a given digest

func (*KeyPair) Verify

func (k *KeyPair) Verify(digest []byte, sig []byte) bool

Verify a given digest with signature

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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