simplehash

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: MIT Imports: 11 Imported by: 5

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 V2HashEvent

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

func V3HashEvent added in v0.0.2

func V3HashEvent(hasher hash.Hash, v3Event V3Event) error

Types

type EventOptionApplier added in v0.0.3

type EventOptionApplier interface {
	ToPublicIdentity()
	SetTimestampCommitted(*timestamppb.Timestamp)
}

type HashOption

type HashOption func(*HashOptions)

func WithAccumulate

func WithAccumulate() 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 Hasher added in v0.0.2

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

func NewHasher added in v0.0.2

func NewHasher() Hasher

func (*Hasher) Reset added in v0.0.2

func (h *Hasher) Reset()

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

func (*Hasher) Sum added in v0.0.2

func (h *Hasher) Sum(b []byte) []byte

type HasherV2

type HasherV2 struct {
	Hasher
}

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. 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) Sum

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

type HasherV3 added in v0.0.2

type HasherV3 struct {
	Hasher
}

func NewHasherV3 added in v0.0.2

func NewHasherV3() HasherV3

func (*HasherV3) HashEvent added in v0.0.2

func (h *HasherV3) 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:

  • WithIDCommitted prefix the data to hash with the bigendian encoding of idtimestamp before hashing.
  • WithPrefix is used to provide domain separation, 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. NOTE: should not be used for valid v3 schema

func (*HasherV3) HashEventFromJSON added in v0.0.3

func (h *HasherV3) HashEventFromJSON(eventJson []byte, opts ...HashOption) error

HashEventFromJson hashes a single event according to the canonical simple hash event format available to api consumers. The source event is in json format.

Options:

  • WithIDCommitted prefix the data to hash with the bigendian encoding of idtimestamp before hashing.
  • WithPrefix is used to provide domain separation, 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. NOTE: should not be used for valid v3 schema

func (*HasherV3) HashEventFromV3 added in v0.0.4

func (h *HasherV3) HashEventFromV3(v3Event V3Event, opts ...HashOption) error

HashEventFromV3 hashes a single event according to the canonical simple hash event format available to api consumers. The source event a pre decoded V3Event type Options: same as HashEventFromJSON

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.

func (*V2Event) SetTimestampCommitted added in v0.0.3

func (e *V2Event) SetTimestampCommitted(timestamp *timestamppb.Timestamp)

SetTimestampCommitted sets the timestamp committed to the given timestamp

func (*V2Event) ToPublicIdentity added in v0.0.3

func (e *V2Event) ToPublicIdentity()

ToPublicIdentity converts the identity of the event into a public identity

type V3Event added in v0.0.2

type V3Event struct {
	Identity           string         `json:"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"`
	TenantIdentity     string         `json:"tenant_identity"`
}

V3Event is a struct that contains ONLY the event fields we want to hash for schema v3

func V3FromEventJSON added in v0.0.2

func V3FromEventJSON(eventJson []byte) (V3Event, error)

V3FromEventJSON unmarshals rest api formated json into the event struct

func V3FromEventResponse added in v0.0.2

func V3FromEventResponse(marshaler *simpleoneof.Marshaler, event *v2assets.EventResponse) (V3Event, error)

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

func (*V3Event) SetTimestampCommitted added in v0.0.3

func (e *V3Event) SetTimestampCommitted(timestamp *timestamppb.Timestamp)

SetTimestampCommitted sets the timestamp committed to the given timestamp

func (*V3Event) ToPublicIdentity added in v0.0.3

func (e *V3Event) ToPublicIdentity()

ToPublicIdentity converts the identity of the event into a public identity

Jump to

Keyboard shortcuts

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