eip4361

package module
v0.0.0-...-ba8adbf Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: Unlicense Imports: 15 Imported by: 0

README

eip4361

this is an implementation of eip4361 (sign in with ethereum)

it is a fork of github.com/spruceid/siwe-go and therefore uses a very similar test suite and api

installation

go get gfx.cafe/open/eip4361

differences

so in the original package, the message is created through making a slice of and then joining them all.

this package instead uses a precompiled template, see tmpl.go, the template is much easier to read but thats just to me

it also adds apis for encoding and decoding from both json and gob.

this allows the api keys to be stored in either json or byte based key-value store, and be accessed in a distributed manner.

otherwise the package is largely unchanged

Documentation

Overview

Package eip4361

package for encoding, decoding, and verifying eip4361 messages

Index

Constants

View Source
const (
	// StdLen is a standard length of uniuri string to achieve ~95 bits of entropy.
	StdLen = 16
	// UUIDLen is a length of uniuri string to achieve ~119 bits of entropy, closest
	// to what can be losslessly converted to UUIDv4 (122 bits).
	UUIDLen = 20
)
View Source
const ISO8601 = "2006-01-02T15:04:05.000Z" // time.RFC3339

ISO8601 time formatting that js uses

View Source
const MessageTemplateString = `` /* 545-byte string literal not displayed */

MessageTemplateString is the template string used to compile eip4361 messages

Variables

View Source
var MessageTemplate = template.Must(template.New("EIP4361Message").Parse(MessageTemplateString))

MessageTemplate is the template used to compile eip4361 message

View Source
var StdChars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")

StdChars is a set of standard characters allowed in uniuri string.

Functions

func GenerateNonce

func GenerateNonce() string

func New

func New() string

New returns a new random string of the standard length, consisting of standard characters.

func NewLen

func NewLen(length int) string

NewLen returns a new random string of the provided length, consisting of standard characters.

func NewLenChars

func NewLenChars(length int, chars []byte) string

NewLenChars returns a new random string of the provided length, consisting of the provided byte slice of allowed characters (maximum 256).

Types

type ExpiredMessage

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

ExpiredMessage is return when msg is expired

func (*ExpiredMessage) Error

func (m *ExpiredMessage) Error() string

Error implements error.Error

type InvalidMessage

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

InvalidMessage is return when msg is invalid

func (*InvalidMessage) Error

func (m *InvalidMessage) Error() string

Error implements error.Error

type InvalidSignature

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

InvalidSignature is return when sig is invalid

func (*InvalidSignature) Error

func (m *InvalidSignature) Error() string

Error implements error.Error

type Message

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

Message a message that represents eip4361 message

func InitMessage

func InitMessage(domain, address, uri, nonce string, options map[string]interface{}) (*Message, error)

InitMessage creates a Message object with the provided parameters

func ParseMessage

func ParseMessage(message string) (*Message, error)

ParseMessage returns a Message object by parsing an EIP-4361 formatted string

func (*Message) GetAddress

func (m *Message) GetAddress() common.Address

GetAddress gets address

func (*Message) GetChainID

func (m *Message) GetChainID() int

GetChainID gets chain id

func (*Message) GetDomain

func (m *Message) GetDomain() string

GetDomain gets domain

func (*Message) GetExpirationTime

func (m *Message) GetExpirationTime() *string

GetExpirationTime gets expiration time

func (*Message) GetIssuedAt

func (m *Message) GetIssuedAt() string

GetIssuedAt gets issuedat

func (*Message) GetNonce

func (m *Message) GetNonce() string

GetNonce gets nonce

func (*Message) GetNotBefore

func (m *Message) GetNotBefore() *string

GetNotBefore gets not before

func (*Message) GetRequestID

func (m *Message) GetRequestID() *string

GetRequestID gets request id

func (*Message) GetResources

func (m *Message) GetResources() []url.URL

GetResources gets resources

func (*Message) GetStatement

func (m *Message) GetStatement() *string

GetStatement gets statement

func (*Message) GetStatementString

func (m *Message) GetStatementString() string

GetStatementString gets statement string

func (*Message) GetURI

func (m *Message) GetURI() url.URL

GetURI gets uri

func (*Message) GetURIString

func (m *Message) GetURIString() string

GetURIString gets uri string

func (*Message) GetVersion

func (m *Message) GetVersion() string

GetVersion gets version

func (*Message) GobDecode

func (m *Message) GobDecode(b []byte) error

GobDecode implements GobDecoder

func (*Message) GobEncode

func (m *Message) GobEncode() ([]byte, error)

GobEncode implements GobEncoder

func (*Message) MarshalJSON

func (m *Message) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*Message) String

func (m *Message) String() string

String implements fmt.Stringer

func (*Message) UnmarshalJSON

func (m *Message) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler

func (*Message) ValidAt

func (m *Message) ValidAt(when time.Time) (bool, error)

ValidAt validates the time constraints of the message at a specific point in time.

func (*Message) ValidNow

func (m *Message) ValidNow() (bool, error)

ValidNow validates the time constraints of the message at current time.

func (*Message) Verify

func (m *Message) Verify(signature string, domain *string, nonce *string, timestamp *time.Time) (*ecdsa.PublicKey, error)

Verify validates time constraints and integrity of the object by matching it's signature.

func (*Message) VerifyEIP191

func (m *Message) VerifyEIP191(signature string) (*ecdsa.PublicKey, error)

VerifyEIP191 validates the integrity of the object by matching it's signature.

Jump to

Keyboard shortcuts

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