Documentation ¶
Index ¶
- Constants
- type Blob
- type Content
- type Hash
- func NewHash(data []byte) Hash
- func NewMerkleHash(hashes []Hash) Hash
- func NewMerkleHashFromSignatories(signatories []Signatory) Hash
- func NewMerkleHashFromSignatoriesInPlace(signatories []Signatory) Hash
- func NewMerkleHashInPlace(hashes []Hash) Hash
- func NewMerkleHashInPlaceSafe(hashes []Hash) Hash
- func NewMerkleHashSafe(hashes []Hash) Hash
- func (hash Hash) Equal(other *Hash) bool
- func (hash Hash) Marshal(buf []byte, rem int) ([]byte, int, error)
- func (hash Hash) MarshalJSON() ([]byte, error)
- func (Hash) SizeHint() int
- func (hash Hash) String() string
- func (hash *Hash) Unmarshal(buf []byte, rem int) ([]byte, int, error)
- func (hash *Hash) UnmarshalJSON(data []byte) error
- type PrivKey
- func (privKey PrivKey) Marshal(buf []byte, rem int) ([]byte, int, error)
- func (privKey PrivKey) MarshalJSON() ([]byte, error)
- func (privKey PrivKey) PubKey() *PubKey
- func (privKey PrivKey) Sign(hash *Hash) (Signature, error)
- func (privKey PrivKey) Signatory() Signatory
- func (privKey PrivKey) SizeHint() int
- func (privKey *PrivKey) Unmarshal(buf []byte, rem int) ([]byte, int, error)
- func (privKey *PrivKey) UnmarshalJSON(data []byte) error
- type PubKey
- type Signatory
- func (signatory Signatory) Equal(other *Signatory) bool
- func (signatory Signatory) Marshal(buf []byte, rem int) ([]byte, int, error)
- func (signatory Signatory) MarshalJSON() ([]byte, error)
- func (Signatory) SizeHint() int
- func (signatory Signatory) String() string
- func (signatory *Signatory) Unmarshal(buf []byte, rem int) ([]byte, int, error)
- func (signatory *Signatory) UnmarshalJSON(data []byte) error
- type Signature
- func (signature Signature) Equal(other *Signature) bool
- func (signature Signature) Marshal(buf []byte, rem int) ([]byte, int, error)
- func (signature Signature) MarshalJSON() ([]byte, error)
- func (signature Signature) Signatory(hash *Hash) (Signatory, error)
- func (Signature) SizeHint() int
- func (signature Signature) String() string
- func (signature *Signature) Unmarshal(buf []byte, rem int) ([]byte, int, error)
- func (signature *Signature) UnmarshalJSON(data []byte) error
Constants ¶
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 )
const ( SizeHintSignature = 65 SizeHintSignatory = 32 )
Constants represent the length of the variables.
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 ¶
NewBlob returns a wrapper around a type that knows how to represent itself in binary.
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 ¶
NewHash consumes a slice of bytes and hashes it using the 256-bit SHA2 hashing function.
func NewMerkleHash ¶
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 ¶
NewMerkleHashFromSignatories is the same as NewMerkleHash but it accepts a slice of Signatories instead of a slice of Hashes.
func NewMerkleHashFromSignatoriesInPlace ¶
NewMerkleHashFromSignatoriesInPlace is the same as NewMerkleHashInPlace but it accepts a slice of Signatories instead of a slice of Hashes.
func NewMerkleHashInPlace ¶
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 ¶
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 ¶
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 ¶
Equal compares one Hash with another. If they are equal, then it returns true, otherwise it returns false.
func (Hash) MarshalJSON ¶
MarshalJSON implements the JSON marshaler interface for the Hash type. It is represented as an unpadded base64 string.
func (*Hash) UnmarshalJSON ¶
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) MarshalJSON ¶
MarshalJSON implements the JSON marshaler interface by representing this private key as an unpadded base64 string.
func (PrivKey) Signatory ¶
Signatory returns the public identity generated from the public key associated with this PrivKey.
func (PrivKey) SizeHint ¶
SizeHint returns the numbers of bytes required to represent this PrivKey in binary.
func (*PrivKey) UnmarshalJSON ¶
UnmarshalJSON implements the JSON unmarshaler interface by representing this private key as an unpadded base64 string.
type PubKey ¶
PubKey is a secp256k1 ECDSA public key.
func (PubKey) MarshalJSON ¶
MarshalJSON implements the JSON marshaler interface by representing this private key as an unpadded base64 string.
func (PubKey) SizeHint ¶
SizeHint returns the number of bytes required to represent the PubKey in binary.
func (*PubKey) UnmarshalJSON ¶
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 ¶
NewSignatory returns the the Signatory of the given ECSDA.PublicKey
func (Signatory) Equal ¶
Equal compares one Signatory with another. If they are equal, then it returns true, otherwise it returns false.
func (Signatory) MarshalJSON ¶
MarshalJSON implements the JSON marshaler interface for the Signatory type. It is represented as an unpadded base64 string.
func (Signatory) SizeHint ¶
SizeHint returns the number of bytes required to represent a Signatory in binary.
func (Signatory) String ¶
String returns the unpadded base64 URL string representation of the Signatory.
func (*Signatory) UnmarshalJSON ¶
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 ¶
Equal compares one Signature with another. If they are equal, then it returns true, otherwise it returns false.
func (Signature) MarshalJSON ¶
MarshalJSON implements the JSON marshaler interface for the Signature type. It is represented as an unpadded base64 string.
func (Signature) SizeHint ¶
SizeHint returns the number of bytes required to represent a Signature in binary.
func (Signature) String ¶
String returns the unpadded base64 URL string representation of the Signature.
func (*Signature) UnmarshalJSON ¶
UnmarshalJSON implements the JSON unmarshaler interface for the Signature type. It assumes that it has been represented as an unpadded base64 string.