id

package module
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2021 License: MIT Imports: 9 Imported by: 14

README

🔒 id

GitHub Coverage Report

Documentation

ECDSA identification for content and content authorship. Supports:

  • hashing,
  • merkle trees,
  • signing, and
  • verification.

Contributors

Built with ❤ by Ren.

Documentation

Index

Constants

View Source
const (
	// SizeHintPubKey is the number of bytes required to represent a secp256k1
	// ECDSA public key in binary.
	SizeHintPubKey = 33
	// SizeHintPrivKey is the number of bytes required to represent a secp256k1
	// ECDSA private key in binary.
	SizeHintPrivKey = 32
)
View Source
const (
	SizeHintSignature = 65
	SizeHintSignatory = 32
)

Constants represent the length of the variables.

View Source
const SizeHintHash = 32

SizeHintHash is the number of bytes required to represent a Hash in binary.

Variables

This section is empty.

Functions

This section is empty.

Types

type Blob

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

A Blob is a helper type for hash-addressable content where the hash is known to be the SHA2 256-bit hash of the binary representation of the content.

func NewBlob

func NewBlob(blob surge.Marshaler) Blob

NewBlob returns a wrapper around a type that knows how to represent itself in binary.

func (Blob) Hash

func (blob Blob) Hash() (Hash, error)

Hash returns the SHA2 256-bit hash of the inner content used to create the blob.

func (Blob) Marshal

func (blob Blob) Marshal(buf []byte, rem int) ([]byte, int, error)

Marshal to binary. This is the same as marshaling the inner content used to create the blob.

func (Blob) SizeHint

func (blob Blob) SizeHint() int

SizeHint returns the number of bytes required to represent the blob in binary. This returns the same number as the inner content used to create the blob.

type Content

type Content interface {
	surge.Marshaler

	// Hash of the Content. It must be unique with respect to the content, but
	// it does not necessarily have to be a hash of the content.
	Hash() (Hash, error)
}

Content defines an interface for hash-addressable data. Content must be able to represent itself in binary, and must expose a way to acquire a unique hash to itself. Typically, the hash will be the SHA2 256-bit hash of the binary representation of the content. However, this is not strictly required, and should not be assumed.

type Hash

type Hash [SizeHintHash]byte

Hash defines the output of the 256-bit SHA2 hashing function.

func NewHash

func NewHash(data []byte) Hash

NewHash consumes a slice of bytes and hashes it using the 256-bit SHA2 hashing function.

func NewMerkleHash

func NewMerkleHash(hashes []Hash) Hash

NewMerkleHash returns the root hash of the merkle tree that uses the hashes as leaves. The hashes are recursively hashed in pairs from left-to-right, with odd hashes trailing at the front. This function does not allow the caller to specify an arbitrary binary tree; it will always pack the hashes pairwise left-to-right. The input slice is unmodified.

Two hashes:

/\

Three hashes:

 /\
/ /\

Four hashes:

 /\
/\/\

Five hashes:

  /\
 / /\
/ /\/\

Six hashes:

  /\
 / /\
/\/\/\

Seven hashes:

   /\
  /  \
 /\  /\
/ /\/\/\

func NewMerkleHashFromSignatories

func NewMerkleHashFromSignatories(signatories []Signatory) Hash

NewMerkleHashFromSignatories is the same as NewMerkleHash but it accepts a slice of Signatories instead of a slice of Hashes.

func NewMerkleHashFromSignatoriesInPlace

func NewMerkleHashFromSignatoriesInPlace(signatories []Signatory) Hash

NewMerkleHashFromSignatoriesInPlace is the same as NewMerkleHashInPlace but it accepts a slice of Signatories instead of a slice of Hashes.

func NewMerkleHashInPlace

func NewMerkleHashInPlace(hashes []Hash) Hash

NewMerkleHashInPlace returns the root hash of the merkle tree that uses the hashes as leaves. It is the same as NewMerkleHash but it overrides values in the input slice for efficiency. Only use this function if you do not need the input slices.

func NewMerkleHashInPlaceSafe

func NewMerkleHashInPlaceSafe(hashes []Hash) Hash

NewMerkleHashInPlaceSafe is the same as NewMerkleHashInPlace, but it does not use any unsafe Go internally. This function is ~5% slower than its unsafe counter-part, and is primarily used to test the correctness/performance of the unsafe implementation.

func NewMerkleHashSafe

func NewMerkleHashSafe(hashes []Hash) Hash

NewMerkleHashSafe is the same as NewMerkleHash, but it does not use any unsafe Go internally. This function is ~5% slower than its unsafe counter-part, and is primarily used to test the correctness/performance of the unsafe implementation.

func (Hash) Equal

func (hash Hash) Equal(other *Hash) bool

Equal compares one Hash with another. If they are equal, then it returns true, otherwise it returns false.

func (Hash) Marshal

func (hash Hash) Marshal(buf []byte, rem int) ([]byte, int, error)

Marshal into binary.

func (Hash) MarshalJSON

func (hash Hash) MarshalJSON() ([]byte, error)

MarshalJSON implements the JSON marshaler interface for the Hash type. It is represented as an unpadded base64 string.

func (Hash) SizeHint

func (Hash) SizeHint() int

SizeHint returns the number of bytes required to represent a Hash in binary.

func (Hash) String

func (hash Hash) String() string

String returns the unpadded base64 URL string representation of the Hash.

func (*Hash) Unmarshal

func (hash *Hash) Unmarshal(buf []byte, rem int) ([]byte, int, error)

Unmarshal from binary.

func (*Hash) UnmarshalJSON

func (hash *Hash) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the JSON unmarshaler interface for the Hash type. It assumes that it has been represented as an unpadded base64 string.

type PrivKey

type PrivKey ecdsa.PrivateKey

PrivKey is a secp256k1 ECDSA private key.

func NewPrivKey

func NewPrivKey() *PrivKey

NewPrivKey generates a random PrivKey and returns it. This function will panic if there is an error generating the PrivKey.

func (PrivKey) Marshal

func (privKey PrivKey) Marshal(buf []byte, rem int) ([]byte, int, error)

Marshal into binary.

func (PrivKey) MarshalJSON

func (privKey PrivKey) MarshalJSON() ([]byte, error)

MarshalJSON implements the JSON marshaler interface by representing this private key as an unpadded base64 string.

func (PrivKey) PubKey

func (privKey PrivKey) PubKey() *PubKey

PubKey returns the ECDSA public key associated with this privey key.

func (PrivKey) Sign

func (privKey PrivKey) Sign(hash *Hash) (Signature, error)

Sign a Hash and return the resulting Signature, or error.

func (PrivKey) Signatory

func (privKey PrivKey) Signatory() Signatory

Signatory returns the public identity generated from the public key associated with this PrivKey.

func (PrivKey) SizeHint

func (privKey PrivKey) SizeHint() int

SizeHint returns the numbers of bytes required to represent this PrivKey in binary.

func (*PrivKey) Unmarshal

func (privKey *PrivKey) Unmarshal(buf []byte, rem int) ([]byte, int, error)

Unmarshal from binary.

func (*PrivKey) UnmarshalJSON

func (privKey *PrivKey) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the JSON unmarshaler interface by representing this private key as an unpadded base64 string.

type PubKey

type PubKey ecdsa.PublicKey

PubKey is a secp256k1 ECDSA public key.

func (PubKey) Marshal

func (pubKey PubKey) Marshal(buf []byte, rem int) ([]byte, int, error)

Marshal to binary.

func (PubKey) MarshalJSON

func (pubKey PubKey) MarshalJSON() ([]byte, error)

MarshalJSON implements the JSON marshaler interface by representing this private key as an unpadded base64 string.

func (PubKey) SizeHint

func (pubKey PubKey) SizeHint() int

SizeHint returns the number of bytes required to represent the PubKey in binary.

func (*PubKey) Unmarshal

func (pubKey *PubKey) Unmarshal(buf []byte, rem int) ([]byte, int, error)

Unmarshal from binary.

func (*PubKey) UnmarshalJSON

func (pubKey *PubKey) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the JSON unmarshaler interface by representing this private key as an unpadded base64 string.

type Signatory

type Signatory [SizeHintSignatory]byte

Signatory defines the Hash of the ECDSA public key that is recovered from a Signature.

func NewSignatory

func NewSignatory(pubKey *PubKey) Signatory

NewSignatory returns the the Signatory of the given ECSDA.PublicKey

func (Signatory) Equal

func (signatory Signatory) Equal(other *Signatory) bool

Equal compares one Signatory with another. If they are equal, then it returns true, otherwise it returns false.

func (Signatory) Marshal

func (signatory Signatory) Marshal(buf []byte, rem int) ([]byte, int, error)

Marshal into binary.

func (Signatory) MarshalJSON

func (signatory Signatory) MarshalJSON() ([]byte, error)

MarshalJSON implements the JSON marshaler interface for the Signatory type. It is represented as an unpadded base64 string.

func (Signatory) SizeHint

func (Signatory) SizeHint() int

SizeHint returns the number of bytes required to represent a Signatory in binary.

func (Signatory) String

func (signatory Signatory) String() string

String returns the unpadded base64 URL string representation of the Signatory.

func (*Signatory) Unmarshal

func (signatory *Signatory) Unmarshal(buf []byte, rem int) ([]byte, int, error)

Unmarshal from binary.

func (*Signatory) UnmarshalJSON

func (signatory *Signatory) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the JSON unmarshaler interface for the Signatory type. It assumes that it has been represented as an unpadded base64 string.

type Signature

type Signature [SizeHintSignature]byte

Signature defines an ECDSA signature of a Hash, encoded as [R || S || V] where V is either 0 or 1.

func (Signature) Equal

func (signature Signature) Equal(other *Signature) bool

Equal compares one Signature with another. If they are equal, then it returns true, otherwise it returns false.

func (Signature) Marshal

func (signature Signature) Marshal(buf []byte, rem int) ([]byte, int, error)

Marshal into binary.

func (Signature) MarshalJSON

func (signature Signature) MarshalJSON() ([]byte, error)

MarshalJSON implements the JSON marshaler interface for the Signature type. It is represented as an unpadded base64 string.

func (Signature) Signatory

func (signature Signature) Signatory(hash *Hash) (Signatory, error)

Signatory returns the that signed the Hash to produce this Signature.

func (Signature) SizeHint

func (Signature) SizeHint() int

SizeHint returns the number of bytes required to represent a Signature in binary.

func (Signature) String

func (signature Signature) String() string

String returns the unpadded base64 URL string representation of the Signature.

func (*Signature) Unmarshal

func (signature *Signature) Unmarshal(buf []byte, rem int) ([]byte, int, error)

Unmarshal from binary.

func (*Signature) UnmarshalJSON

func (signature *Signature) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the JSON unmarshaler interface for the Signature type. It assumes that it has been represented as an unpadded base64 string.

Jump to

Keyboard shortcuts

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