bbclib

package module
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2019 License: Apache-2.0 Imports: 18 Imported by: 3

README

bbclib-go

License Build Status Go Report Card Coverage Status Maintainability

Golang implementation of bbc1.core.bbclib and bbc1.core.libs modules in https://github.com/beyond-blockchain/bbc1. This reposigory is originally from https://github.com/quvox/bbclib-go

Features

Usage

import "github.com/beyond-blockchain/bbclib-go"

An example source code is in example/.

Install (step by step)

go get -u github.com/beyond-blockchain/bbclib-go

NOTE: example/ directory includes a sample code for this module.

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.

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  // unsported
	KeyTypeEcdsaP256v1 = 2

	DefaultCompressionMode = 4
)

Supported ECC curve type is Prime-256v1 only

View Source
const (
	DomainIDLength = 32
)

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

Variables

View Source
var IdLengthConfig = BBcIdConfig{
	TransactionIdLength: defaultIDLength,
	UserIdLength:        defaultIDLength,
	AssetGroupIdLength:  defaultIDLength,
	AssetIdLength:       defaultIDLength,
	NonceLength:         defaultIDLength,
}

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 (old style, only for backward compatibility)

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 (old style, only for backward compatibility)

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 (old style, only for backward compatibility)

func AddPointerInRelation

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

AddPointerInRelation creates and includes a BBcPointer object in BBcRelation (old style, only for backward compatibility)

func AddReference

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

AddReference creates and includes a BBcReference object in a BBcTransaction object (old style, only for backward compatibility)

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 (old style, only for backward compatibility)

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 (old style, only for backward compatibility)

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 (old style, only for backward compatibility)

func AddRelationAssetHash added in v1.5.0

func AddRelationAssetHash(transaction *BBcTransaction, relationIdx int, assetGroupId, assetIds *[]byte)

AddRelationAssetHash sets assetIDs in BBcAssetHash in BBcRelation and add it to a BBcTransaction object (old style, only for backward compatibility)

func AddRelationAssetRaw added in v1.5.0

func AddRelationAssetRaw(transaction *BBcTransaction, relationIdx int, assetGroupId, assetId *[]byte, assetBody interface{})

AddRelationAssetRawBody sets a data in BBcAssetRaw in BBcRelation and add it to a BBcTransaction object (old style, only for backward compatibility)

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 (old style, only for backward compatibility)

func ConfigureIdLength

func ConfigureIdLength(conf *BBcIdConfig)

Configure various ID length

func ConfigureIdLengthAll

func ConfigureIdLengthAll(length int)

Configure all kind of ID length with the same value

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, int, error)

GetBigInt returns a ID data from the buffer

func GetBytes

func GetBytes(buf *bytes.Buffer, length int) ([]byte, int, 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 (old style, only for backward compatibility)

func UpdateIdLengthConfig added in v1.5.0

func UpdateIdLengthConfig(main, refer *BBcIdConfig)

Copy new config in refer to main

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 {
	IdLengthConf *BBcIdConfig
	Version      uint32

	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) AddBody added in v1.6.0

func (p *BBcAsset) AddBody(bodyContent interface{})

AddBody sets data 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) SetIdLengthConf

func (p *BBcAsset) SetIdLengthConf(conf *BBcIdConfig)

Set ID length configuration

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 BBcAssetHash added in v1.5.0

type BBcAssetHash struct {
	IdLengthConf *BBcIdConfig
	Version      uint32
	AssetIdNum   uint16
	AssetIDs     [][]byte
}

BBcAssetHash definition

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

Multiple AssetIDs can be cotained in the list. The length of "AssetID" is defined by "IDLength".

func (*BBcAssetHash) AddAssetId added in v1.5.0

func (p *BBcAssetHash) AddAssetId(assetId *[]byte)

AddAssetId sets a string data in the BBcAsset object

func (*BBcAssetHash) Pack added in v1.5.0

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

Pack returns the binary data of the BBcAsset object

func (*BBcAssetHash) SetIdLengthConf added in v1.5.0

func (p *BBcAssetHash) SetIdLengthConf(conf *BBcIdConfig)

Set ID length configuration

func (*BBcAssetHash) Stringer added in v1.5.0

func (p *BBcAssetHash) Stringer() string

Stringer outputs the content of the object

func (*BBcAssetHash) Unpack added in v1.5.0

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

Unpack the BBcAsset object to the binary data

type BBcAssetRaw added in v1.5.0

type BBcAssetRaw struct {
	IdLengthConf  *BBcIdConfig
	Version       uint32
	AssetID       []byte
	AssetBodySize uint16
	AssetBody     []byte
}

BBcAssetRaw definition

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

"AssetID" is externally calculated digest value. The length of "AssetID" is defined by "IDLength".

func (*BBcAssetRaw) AddBody added in v1.5.0

func (p *BBcAssetRaw) AddBody(assetID *[]byte, assetBody interface{})

AddBody sets a string data in the BBcAsset object

func (*BBcAssetRaw) Pack added in v1.5.0

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

Pack returns the binary data of the BBcAsset object

func (*BBcAssetRaw) SetIdLengthConf added in v1.5.0

func (p *BBcAssetRaw) SetIdLengthConf(conf *BBcIdConfig)

Set ID length configuration

func (*BBcAssetRaw) Stringer added in v1.5.0

func (p *BBcAssetRaw) Stringer() string

Stringer outputs the content of the object

func (*BBcAssetRaw) Unpack added in v1.5.0

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

Unpack the BBcAsset object to the binary data

type BBcCrossRef

type BBcCrossRef struct {
	IdLengthConf  *BBcIdConfig
	Version       uint32
	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) SetIdLengthConf

func (p *BBcCrossRef) SetIdLengthConf(conf *BBcIdConfig)

Set ID length configuration

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 {
	IdLengthConf                 *BBcIdConfig
	Version                      uint32
	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) *BBcEvent

AddMandatoryApprover sets userID in MandatoryApprover list of the BBcEvent object

func (*BBcEvent) AddOptionApprover

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

AddOptionApprover sets userID in OptionApprover list of the BBcEvent object

func (*BBcEvent) AddReferenceIndex

func (p *BBcEvent) AddReferenceIndex(relIndex int) *BBcEvent

AddReferenceIndex sets an index to ReferenceIndices of the BBcEvent object

func (*BBcEvent) CreateAsset added in v1.6.0

func (p *BBcEvent) CreateAsset(userId *[]byte, fileContent *[]byte, bodyContent interface{}) *BBcEvent

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

func (*BBcEvent) Pack

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

Pack returns the binary data of the BBcEvent object

func (*BBcEvent) SetAssetGroup added in v1.6.0

func (p *BBcEvent) SetAssetGroup(assetGroupId *[]byte) *BBcEvent

SetAssetGroup sets asset_group_id in the BBcEvent object

func (*BBcEvent) SetIdLengthConf

func (p *BBcEvent) SetIdLengthConf(conf *BBcIdConfig)

Set ID length configuration

func (*BBcEvent) SetOptionParams added in v1.6.0

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

AddOptionParams sets values to OptionApproverNumNumerator and OptionApproverNumDenominator in 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 BBcIdConfig

type BBcIdConfig struct {
	TransactionIdLength int
	UserIdLength        int
	AssetGroupIdLength  int
	AssetIdLength       int
	NonceLength         int
}

type BBcPointer

type BBcPointer struct {
	IdLengthConf  *BBcIdConfig
	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) SetIdLengthConf

func (p *BBcPointer) SetIdLengthConf(conf *BBcIdConfig)

Set ID length configuration

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 {
	IdLengthConf    *BBcIdConfig
	Version         uint32
	AssetGroupID    []byte
	TransactionID   []byte
	EventIndexInRef uint16
	SigIndices      []int

	Transaction    *BBcTransaction
	RefTransaction *BBcTransaction
	RefEvent       BBcEvent
	// contains filtered or unexported fields
}

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) 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) SetIdLengthConf

func (p *BBcReference) SetIdLengthConf(conf *BBcIdConfig)

Set ID length configuration

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 {
	IdLengthConf *BBcIdConfig
	Version      uint32
	AssetGroupID []byte
	Pointers     []*BBcPointer
	Asset        *BBcAsset
	AssetRaw     *BBcAssetRaw
	AssetHash    *BBcAssetHash
}

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) *BBcRelation

MakeRelationWithAsset is a utility for making simple BBcTransaction object with BBcRelation with BBcAsset (old style, only for backward compatibility)

func (*BBcRelation) CreateAsset added in v1.6.0

func (p *BBcRelation) CreateAsset(userId *[]byte, fileContent *[]byte, bodyContent interface{}) *BBcRelation

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

func (*BBcRelation) CreateAssetHash added in v1.6.0

func (p *BBcRelation) CreateAssetHash(assetId *[]byte) *BBcRelation

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

func (*BBcRelation) CreateAssetRaw added in v1.6.0

func (p *BBcRelation) CreateAssetRaw(assetID *[]byte, bodyContent interface{}) *BBcRelation

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

func (*BBcRelation) CreatePointer added in v1.6.0

func (p *BBcRelation) CreatePointer(transactionId, assetId *[]byte) *BBcRelation

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) SetAssetGroup added in v1.6.0

func (p *BBcRelation) SetAssetGroup(assetGroupId *[]byte) *BBcRelation

SetAssetGroup sets asset_group_id in the BBcRelation object

func (*BBcRelation) SetIdLengthConf

func (p *BBcRelation) SetIdLengthConf(conf *BBcIdConfig)

Set ID length configuration

func (*BBcRelation) SetVersion added in v1.5.0

func (p *BBcRelation) SetVersion(version uint32)

Set version of the transaction format

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 {
	Version      uint32
	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) SetPublicKeyInfo

func (p *BBcSignature) SetPublicKeyInfo(keyType uint32)

SetPublicKeyInfo sets the keyType only (public key will be given when verification)

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

func (*BBcSignature) VerifyWithPublicKey

func (p *BBcSignature) VerifyWithPublicKey(digest []byte, publicKey []byte) bool

Verify the TransactionID with the given public key

type BBcTransaction

type BBcTransaction struct {
	IdLengthConf          BBcIdConfig
	TransactionID         []byte
	TransactionBaseDigest []byte
	TransactionData       []byte
	SigIndexedUsers       [][]byte
	Version               uint32
	Timestamp             int64
	TransactionIdLength   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 "SigIndexedUsers" 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) *BBcTransaction

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

func (*BBcTransaction) AddEvent

func (p *BBcTransaction) AddEvent(assetGroupId *[]byte, referenceIndices *[]int) *BBcTransaction

AddEvent adds the BBcEvent object in the transaction object

func (*BBcTransaction) AddRelation

func (p *BBcTransaction) AddRelation(assetGroupId *[]byte) *BBcTransaction

AddRelation adds the BBcRelation object in the transaction object

func (*BBcTransaction) AddSignatureObj added in v1.6.0

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

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

func (*BBcTransaction) AddWitness

func (p *BBcTransaction) AddWitness(userId *[]byte) *BBcTransaction

AddWitness sets the BBcWitness object in the transaction object

func (*BBcTransaction) CreateCrossRef added in v1.6.0

func (p *BBcTransaction) CreateCrossRef(domainId, transactionId *[]byte) *BBcTransaction

AddCrossRef sets the BBcCrossRef object in the transaction object

func (*BBcTransaction) CreateReference added in v1.6.0

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

AddReference adds the BBcReference 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) SetIdLengthConf

func (p *BBcTransaction) SetIdLengthConf(conf *BBcIdConfig)

Set ID length configuration

func (*BBcTransaction) SetSigIndex

func (p *BBcTransaction) SetSigIndex(userID []byte, idx int)

SetSigIndex simply sets the index of signature list for the specified userID

func (*BBcTransaction) Sign

func (p *BBcTransaction) Sign(userId *[]byte, keyPair *KeyPair, noPubkey bool) *BBcTransaction

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

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 {
	IdLengthConf *BBcIdConfig
	Version      uint32
	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) SetIdLengthConf

func (p *BBcWitness) SetIdLengthConf(conf *BBcIdConfig)

Set ID length configuration

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
	CompressionType     int
	Pubkey              []byte
	Privkey             []byte
	PublicKeyStructure  *ecdsa.PublicKey
	PrivateKeyStructure *ecdsa.PrivateKey
}

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, error)

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

func (*KeyPair) CheckX509 added in v1.4.2

func (k *KeyPair) CheckX509(certstr string, privkey string) bool

VerifyX509 verifies the public key's legitimacy

func (*KeyPair) ConvertFromDer added in v1.4.2

func (k *KeyPair) ConvertFromDer(der []byte, compressionMode int) error

ConvertFromPem imports DER formatted private key

func (*KeyPair) ConvertFromPem

func (k *KeyPair) ConvertFromPem(pemstr string, compressionMode int) error

ConvertFromPem imports PEM formatted private key

func (*KeyPair) GetKeyId added in v1.6.0

func (k *KeyPair) GetKeyId() ([]byte, error)

GetKeyId returns Key ID of the public key

func (*KeyPair) GetPublicKeyCompressed added in v1.4.2

func (k *KeyPair) GetPublicKeyCompressed() *[]byte

GetPublicKeyCompressed gets a public key (compressed) from private key

func (*KeyPair) GetPublicKeyUncompressed added in v1.4.2

func (k *KeyPair) GetPublicKeyUncompressed() *[]byte

GetPublicKeyUncompressed gets a public key (uncompressed) from private key

func (*KeyPair) OutputDer added in v1.4.2

func (k *KeyPair) OutputDer() []byte

OutputDer outputs DER formatted private key

func (*KeyPair) OutputPem added in v1.4.2

func (k *KeyPair) OutputPem() (string, error)

OutputDer outputs PEM formatted private key

func (*KeyPair) OutputPublicKeyDer added in v1.4.2

func (k *KeyPair) OutputPublicKeyDer() []byte

OutputDer outputs DER formatted private key

func (*KeyPair) OutputPublicKeyPem added in v1.4.2

func (k *KeyPair) OutputPublicKeyPem() (string, error)

OutputDer outputs PEM formatted private key

func (*KeyPair) ReadX509 added in v1.4.2

func (k *KeyPair) ReadX509(certstr string, compressionMode int) (*x509.Certificate, error)

ReadX509 imports X.509 public key certificate

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

Jump to

Keyboard shortcuts

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