id

package module
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2020 License: MIT Imports: 9 Imported by: 42

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 added in v0.4.1

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 added in v0.4.1

func NewBlob(blob surge.Marshaler) Blob

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

func (Blob) Hash added in v0.4.1

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 added in v0.4.1

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 added in v0.4.1

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 added in v0.4.1

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 added in v0.3.2

func NewHash(data []byte) Hash

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

func NewMerkleHash added in v0.3.0

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 added in v0.3.1

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 added in v0.3.1

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 added in v0.3.0

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 added in v0.3.0

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 added in v0.3.0

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 added in v0.2.0

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 added in v0.2.0

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 added in v0.2.0

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 added in v0.3.2

type PrivKey ecdsa.PrivateKey

PrivKey is a secp256k1 ECDSA private key.

func NewPrivKey added in v0.3.2

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 added in v0.3.2

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

Marshal into binary.

func (PrivKey) MarshalJSON added in v0.3.4

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 added in v0.4.0

func (privKey PrivKey) PubKey() *PubKey

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

func (PrivKey) Sign added in v0.3.2

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

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

func (PrivKey) Signatory added in v0.3.2

func (privKey PrivKey) Signatory() Signatory

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

func (PrivKey) SizeHint added in v0.3.2

func (privKey PrivKey) SizeHint() int

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

func (*PrivKey) Unmarshal added in v0.3.2

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

Unmarshal from binary.

func (*PrivKey) UnmarshalJSON added in v0.3.4

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 added in v0.4.0

type PubKey ecdsa.PublicKey

PubKey is a secp256k1 ECDSA public key.

func (PubKey) Marshal added in v0.4.0

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

Marshal to binary.

func (PubKey) MarshalJSON added in v0.4.0

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 added in v0.4.0

func (pubKey PubKey) SizeHint() int

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

func (*PubKey) Unmarshal added in v0.4.0

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

Unmarshal from binary.

func (*PubKey) UnmarshalJSON added in v0.4.0

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 added in v0.2.0

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

Marshal into binary.

func (Signatory) MarshalJSON added in v0.2.0

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 added in v0.2.0

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 added in v0.2.0

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

Unmarshal from binary.

func (*Signatory) UnmarshalJSON added in v0.2.0

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 added in v0.2.0

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 added in v0.3.2

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

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

func (Signature) SizeHint added in v0.2.0

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 added in v0.2.0

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