ephemeral

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2023 License: BSD-2-Clause Imports: 10 Imported by: 35

Documentation

Index

Constants

View Source
const (
	// IdLen is the length of an ephemeral [Id].
	IdLen = 8

	Period            = int64(time.Hour * 24)
	NumOffsets  int64 = 1 << 16
	NsPerOffset       = Period / NumOffsets
)

Variables

View Source
var ReservedIDs = []Id{
	{0, 0, 0, 0, 0, 0, 0, 0},
	{1, 1, 1, 1, 1, 1, 1, 1},
}

ReservedIDs are ephemeral IDs reserved for specific actions:

  • All zeros denote a dummy ID
  • All ones denote a payment

Functions

func GetIntermediaryId

func GetIntermediaryId(id *id.ID) ([]byte, error)

GetIntermediaryId returns an intermediary ID for the ephemeral ID creation (ID hash).

func GetOffset

func GetOffset(intermediaryId []byte) int64

func GetOffsetBounds

func GetOffsetBounds(offset, timestamp int64) (time.Time, time.Time, uint64)

func GetOffsetNum

func GetOffsetNum(offset int64) int64

func HandleQuantization

func HandleQuantization(start time.Time) (int64, int32)

func IsReserved

func IsReserved(eid Id) bool

IsReserved checks if the Id is among the reserved global reserved ID list. Returns true if reserved, false if non-reserved.

Types

type Id

type Id [IdLen]byte

Id is the ephemeral ID type.

func GetId

func GetId(id *id.ID, size uint, timestamp int64) (Id, time.Time, time.Time, error)

GetId returns ephemeral ID based on the passed in ID. Accepts an ID, ID size in bits, and timestamp in nanoseconds. Returns an ephemeral ID and the start and end timestamps for the salt window.

func GetIdFromIntermediary

func GetIdFromIntermediary(iid []byte, size uint, timestamp int64) (
	Id, time.Time, time.Time, error)

GetIdFromIntermediary returns the ephemeral ID from intermediary (ID hash). Accepts an intermediary ephemeral ID, ID size in bits, and timestamp in nanoseconds. Returns an ephemeral ID and the start and end timestamps for salt window.

func Marshal

func Marshal(data []byte) (Id, error)

Marshal loads an ephemeral ID from raw bytes.

func (Id) Clear

func (eid Id) Clear(size uint) Id

Clear clears all the bits in the ID outside of the given size.

func (Id) Fill

func (eid Id) Fill(size uint, rng io.Reader) (Id, error)

Fill sets the bits of an ID with random data from passed in rng. The size of the ID is in bits.

func (*Id) Int64

func (eid *Id) Int64() int64

Int64 returns the ephemeral ID as an int64.

func (Id) MarshalJSON

func (eid Id) MarshalJSON() ([]byte, error)

MarshalJSON marshals the ephemeral Id into valid JSON. This function adheres to the json.Marshaler interface.

func (*Id) UInt64

func (eid *Id) UInt64() uint64

UInt64 returns the ephemeral ID as a uint64.

func (*Id) UnmarshalJSON

func (eid *Id) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshalls the JSON into the ephemeral Id. This function adheres to the json.Unmarshaler interface.

type ProtoIdentity

type ProtoIdentity struct {
	Id    Id
	Start time.Time
	End   time.Time
}

ProtoIdentity contains the ID and the start and end time for the salt window.

func GetIdsByRange

func GetIdsByRange(id *id.ID, size uint, timestamp time.Time,
	timeRange time.Duration) ([]ProtoIdentity, error)

GetIdsByRange returns ephemeral IDs based on passed in ID and a time range. Accepts an ID, ID size in bits, timestamp, and a time range. Returns a list of ephemeral IDs.

Jump to

Keyboard shortcuts

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