Categorygithub.com/stratumn/go-chainscript
modulepackage
1.0.2
Repository: https://github.com/stratumn/go-chainscript.git
Documentation: pkg.go.dev

# README

Go ChainScript

GoDoc build status codecov Go Report Card

Official Go implementation of ChainScript. This is the recommended way to use ChainScript in your Go projects.

However, it is opinionated and tries to keep the application data as abstract as possible. Some applications will have different requirements and might want to optimize for specific use-cases. If you are in that case, don't hesitate to implement your own ChainScript library. If you do so, don't forget to set the client_id field to make it easy for others to deserialize and validate your data.

Updating ChainScript

The ChainScript definitions are imported as a git subtree. Changes to the protobuf files should be done in the ChainScript repository.

To get the latest ChainScript definitions in this project, run:

make update_chainscript

Note that when you update the git subtree, you must not squash your commits when merging to the master branch, otherwise the subtree update will fail because it will be unable to find the previous subtree commit.

Compile the new protobuf definitions:

make protobuf

Fixing JSON struct tags

If the protobuf compiler added json tags (json:"map_id") to your structs, you might need to manually fix them if you want to be fully compatible with other languages.

Those tags create an issue for fields that contain an underscore in the proto definitions. For such fields you'll need to manually update the generated go file until the protobuf compiler provides configuration options to generate json tags properly.

Protobuf uses snake_case for field definitions (in your .proto files) but follows the JSON recommendation to use camelCase when serializing those fields to JSON. However the protobuf compiler also adds struct tags to tell the JSON serializer to use snake_case for fields that contain an underscore. As long as you use protobuf's JSON serializer you're fine because it will accept both snake_case and camelCase, but if you need to use another serializer at some point (in our case canonical-json for signatures v1.0.0) your JSON representation will use snake_case. Javascript correctly uses camelCase so your Javascript code will not be able to validate signatures generated by Go code (and the other way around as well).

The fix is simple: track all your snake_case fields and update the json:"snake_field" struct tag to json:"snakeField".

Updating dependencies

When updating dependencies (go-crypto, canonical-json, etc) we must stay backwards-compatible. That means that each dependency update should thoroughly check whether it introduces breaking changes in the serialized data. If it does, the version of some fields (link, signature) needs to be updated accordingly.

# Packages

No description provided by the author
Package main defines the end-to-end compatibility tests.

# Functions

MarshalEvidence marshals using protobuf.
MarshalLink marshals using protobuf.
MarshalSegment marshals using protobuf.
NewEvidence creates a new evidence that can be added to a segment.
NewLinkBuilder creates a new link builder.
NewLinkHashFromString decodes a string and returns a link hash.
UnmarshalEvidence unmarshals protobuf bytes.
UnmarshalLink unmarshals protobuf bytes.
UnmarshalSegment unmarshals protobuf bytes.

# Constants

ClientID allows segment receivers to figure out how the segment was encoded and can be decoded.
LinkVersion is the version used for new links.
LinkVersion1_0_0 is the first version of the link encoding.
SignatureVersion is the version used for new signatures.
SignatureVersion1_0_0 is the first version of the link signature.

# Variables

Segment errors.
Link errors.
Signature errors.
Segment errors.
Segment errors.
Link errors.
Link errors.
Link errors.
Link errors.
Segment errors.
Segment errors.
Link errors.
Link errors.
Link errors.
Link errors.
Signature errors.

# Structs

Evidences can be used to externally verify a link's existence at a given moment in time.
A link is the immutable part of a segment.
LinkBuilder makes it easy to create links that adhere to the ChainScript spec.
Metadata associated to a process' step.
A reference to a link that can be in another process.
A process represents a real-world process that is shared between multiple independent actors.
A segment describes an atomic step in your process.
Segment metadata.
A signature of configurable parts of a link.

# Interfaces

Proof is the generic interface an evidence's proof should implement.

# Type aliases

LinkHash is a byte array for which we provide utility methods.