simplehash

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 10 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidOption = errors.New("option not supported by this method")
)

Functions

func EventSimpleHashV2

func EventSimpleHashV2(hasher hash.Hash, marshaler *simpleoneof.Marshaler, event *v2assets.EventResponse) error

EventSimpleHashV2 hashes a single event according to the canonical simple hash event format available to api consumers.

  • If the event is the permissioned (owner) counter part of a public attestation, you must call PublicFromPermissionedEvent first.
  • No special treatment is given to confirmation status (PENDING vs CONFIRMED). Because the rules for forestrie and PENDING events are *NOT THE SAME* as those for proof_mechanism simplehash.

func NewEventMarshaler

func NewEventMarshaler() *simpleoneof.Marshaler

NewEventMarshaler creates a flat marshaler to transform events to api format.

otherwise attributes look like this: {"foo":{"str_val": "bar"}} instead of {"foo": "bar"} this mimics the public list events api response, so minimises changes to the public api response, to reproduce the anchor

func PublicFromPermissionedEvent

func PublicFromPermissionedEvent(event *v2assets.EventResponse)

PublicFromPermissionedEvent translates the permissioned event and asset identities to their public counter parts.

func V2HashEvent

func V2HashEvent(hasher hash.Hash, v2Event V2Event) error

Types

type HashOption

type HashOption func(*HashOptions)

func WithAccumulate

func WithAccumulate() HashOption

func WithAsConfirmed

func WithAsConfirmed() HashOption

func WithIDCommitted

func WithIDCommitted(idcommitted uint64) HashOption

WithIDCommitted includes the snowflakeid unique commitment timestamp in the hash idcommitted is never (legitimately) zero

func WithPrefix

func WithPrefix(b []byte) HashOption

WithPrefix pre-pends the provided bytes to the hash. This option can be used multiple times and the successive bytes are appended to the prefix. This is typically used to provide hash domain seperation where second pre-image collisions are a concerne.

func WithPublicFromPermissioned

func WithPublicFromPermissioned() HashOption

func WithTimestampCommitted

func WithTimestampCommitted(committed *timestamppb.Timestamp) HashOption

type HashOptions

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

type HasherV2

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

func NewHasherV2

func NewHasherV2() HasherV2

func (*HasherV2) HashEvent

func (h *HasherV2) HashEvent(event *v2assets.EventResponse, opts ...HashOption) error

HashEvent hashes a single event according to the canonical simple hash event format available to api consumers. The source event is in the grpc proto buf format. GRPC endpoints are not presently exposed by the platform.

Options:

  • WithTimestampCommitted set the timestamp_commited before hashing
  • WithPrefix is used to provide domain seperation, the provided bytes are pre-pended to the data to be hashed. Eg H(prefix || data) This option can be used multiple times, the prefix bytes are appended to any previously supplied.
  • WithAccumulate callers wishing to implement batched hashing of multiple events in series should set this. They should call Reset() at their batch boundaries.
  • WithPublicFromPermissioned should be set if the event is the permissioned (owner) counter part of a public attestation.
  • WithAsConfirmed should be set if the caller is implementing CONFIRMATION as part of an evidence subsystem implementation. The expectation is that the caller has a PENDING record to hand, and is in the process of creating the CONFIRMED record. It is the CONFIRMED record that needs to be publicly verifiable.

func (*HasherV2) HashEventJSON

func (h *HasherV2) HashEventJSON(event []byte, opts ...HashOption) error

HashEventJSON hashes a single event according to the canonical simple hash event format available to api consumers. The source event data is in the form returned by our apis

Options:

  • WithAccumulate callers wishing to implement batched hashing of multiple events in series should set this. They should call Reset() at their batch boundaries.
  • WithAsConfirmed should be set if the caller wishes to anticipate the hash of a confirmed event based on a pending response

func (*HasherV2) Reset

func (h *HasherV2) Reset()

Reset resets the hasher state This is only useful in combination with WithAccumulate

func (*HasherV2) Sum

func (h *HasherV2) Sum() []byte

type V2Event

type V2Event struct {
	Identity           string         `json:"identity"`
	AssetIdentity      string         `json:"asset_identity"`
	EventAttributes    map[string]any `json:"event_attributes"`
	AssetAttributes    map[string]any `json:"asset_attributes"`
	Operation          string         `json:"operation"`
	Behaviour          string         `json:"behaviour"`
	TimestampDeclared  string         `json:"timestamp_declared"`
	TimestampAccepted  string         `json:"timestamp_accepted"`
	TimestampCommitted string         `json:"timestamp_committed"`
	PrincipalAccepted  map[string]any `json:"principal_accepted"`
	PrincipalDeclared  map[string]any `json:"principal_declared"`
	ConfirmationStatus string         `json:"confirmation_status"`
	From               string         `json:"from"`
	TenantIdentity     string         `json:"tenant_identity"`
}

V2Event is a struct that contains ONLY the event fields we want to hash for schema v2

func V2FromEventJSON

func V2FromEventJSON(eventJson []byte) (V2Event, error)

V2FromEventJSON unmarshals rest api formated json into the event struct

func V2FromEventResponse

func V2FromEventResponse(marshaler *simpleoneof.Marshaler, event *v2assets.EventResponse) (V2Event, error)

V2FromEventResponse transforms a single event in grpc proto format (message bus compatible) to the canonical, publicly verifiable, api format.

Jump to

Keyboard shortcuts

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