sunrise

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDecode            = errors.New("sunrise: could not decode token")
	ErrSize              = errors.New("sunrise: invalid size for token")
	ErrInvalidSunriseID  = errors.New("invalid sunrise token: no sunrise id")
	ErrInvalidExpiration = errors.New("invalid sunrise token: no expiration timestamp")
	ErrInvalidNonce      = errors.New("invalid sunrise token: incorrect nonce")
	ErrInvalidSignature  = errors.New("invalid sunrise token: incorrect hmac signature")
	ErrUnexpectedType    = errors.New("sunrise: could not scan non-bytes type")
)

Functions

This section is empty.

Types

type SignedToken

type SignedToken struct {
	Token
	// contains filtered or unexported fields
}

A signed token contains a signature that can be stored in the local database in order to verify an incoming verification token from a client.

func (*SignedToken) Equal

func (t *SignedToken) Equal(o *SignedToken) bool

func (*SignedToken) MarshalBinary

func (t *SignedToken) MarshalBinary() (out []byte, err error)

func (*SignedToken) Scan

func (t *SignedToken) Scan(value interface{}) error

Scan the signed token from a database query.

func (*SignedToken) Signature

func (t *SignedToken) Signature() []byte

Retrieve the signature from the signed token.

func (*SignedToken) UnmarshalBinary

func (t *SignedToken) UnmarshalBinary(data []byte) (err error)

func (*SignedToken) Validate

func (t *SignedToken) Validate() (err error)

func (*SignedToken) Value

func (t *SignedToken) Value() (_ driver.Value, err error)

Produce a database value from the signed token for inserts/updates to database.

func (*SignedToken) Verify

func (t *SignedToken) Verify(token VerificationToken) (secure bool, err error)

Verify that a signed token belongs with the associated verification token.

type Token

type Token struct {
	SunriseID  ulid.ULID // ID of the sunrise record in the database
	Expiration time.Time // Expiration date of the token (not after)
	// contains filtered or unexported fields
}

A Token is a data representation of the information needed to create a secure sunrise verification token to send to the compliance officer of the counterparty. Tokens can be used to generate SignedTokens and SignedTokens can be used to send a secure verification token and to verify that tokens belong to the specified user.

func NewToken

func NewToken(sunriseID ulid.ULID, expiration time.Time) *Token

Create a new token with the specified ID and expiration timestamp. If the timestamp is zero valued, then a timestamp in the future will be generated with the default expiration deadline.

func (*Token) Equal

func (t *Token) Equal(o *Token) bool

func (*Token) IsExpired

func (t *Token) IsExpired() bool

func (*Token) MarshalBinary

func (t *Token) MarshalBinary() ([]byte, error)

func (*Token) Sign

func (t *Token) Sign() (token VerificationToken, signature *SignedToken, err error)

Sign a token creating a verification token that should be sent as a string to the counterparty and a signed token that should be stored in the database.

func (*Token) UnmarshalBinary

func (t *Token) UnmarshalBinary(data []byte) error

func (*Token) Validate

func (t *Token) Validate() (err error)

type VerificationToken

type VerificationToken []byte

A verification token is sent to the client and contains the information needed to lookup a signed token in the database and to verify that the message is authentic.

func ParseVerification

func ParseVerification(tks string) (_ VerificationToken, err error)

func (VerificationToken) Secret

func (v VerificationToken) Secret() []byte

func (VerificationToken) String

func (v VerificationToken) String() string

func (VerificationToken) SunriseID

func (v VerificationToken) SunriseID() ulid.ULID

Jump to

Keyboard shortcuts

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