PowFinder implements proof-of-work algorithm (also known as Hashcash). Proof-of-work is used in Dscuss to protect against Sybil attack.
type PowFinder struct {
// contains filtered or unexported fields
}
func NewPowFinder(data []byte) *PowFinder
func (pf *PowFinder) Find() ProofOfWork
func (pf *PowFinder) Validate(nonce ProofOfWork) bool
type PrivateKey ecdsa.PrivateKey
func NewPrivateKey() (*PrivateKey, error)
NewPrivateKey generates a random P-224 ECDSA private key.
func ParsePrivateKeyFromDER(der []byte) (*PrivateKey, error)
ParsePrivateKeyFromDER decodes a PEM-encoded ECDSA private key.
func ParsePrivateKeyFromPEM(encodedKey []byte) (*PrivateKey, error)
ParsePrivateKeyFromPEM decodes a PEM-encoded ECDSA private key.
func (key *PrivateKey) EncodeToDER() []byte
EncodeToDER encodes an ECDSA private key to DER format.
func (key *PrivateKey) EncodeToPEM() []byte
EncodeToPEM encodes an ECDSA private key to PEM format.
func (key *PrivateKey) Public() *PublicKey
public returns the public key corresponding to the private key.
type ProofOfWork uint64
type PublicKey ecdsa.PublicKey
func ParsePublicKeyFromDER(encodedKey []byte) (*PublicKey, error)
ParsePublicKeyFromDER decodes a DER-encoded ECDSA public key.
func ParsePublicKeyFromPEM(encodedKey []byte) (*PublicKey, error)
ParsePublicKeyFromPEM decodes a PEM-encoded ECDSA public key.
func (key *PublicKey) EncodeToDER() []byte
EncodeToDER encodes an ECDSA public key to DER format.
func (key *PublicKey) EncodeToPEM() []byte
EncodeToPEM encodes an ECDSA public key to PEM format.
func (key *PublicKey) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoded key.
func (key *PublicKey) UnmarshalJSON(b []byte) error
UnmarshalJSON decodes b and sets result to *key.
func (key *PublicKey) Verify(data []byte, sig Signature) bool
Verify checks whether the sig of the data corresponds the public key.
type Signature []byte
func ParseSignature(b64sig []byte) (Signature, error)
ParseSignature decodes an ECDSA signature according to https://tools.ietf.org/html/rfc7515#appendix-A.3.1
func (sig Signature) Encode() string
Encode encodes an ECDSA signature according to https://tools.ietf.org/html/rfc7515#appendix-A.3.1
func (sig Signature) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON-encoded key.
func (sig *Signature) UnmarshalJSON(b []byte) error
UnmarshalJSON decodes b and sets result to *sig.
Signer hides private key from caller and offers simple interface for signing data.
type Signer struct {
// contains filtered or unexported fields
}
func NewSigner(privkey *PrivateKey) *Signer
func (s *Signer) Public() *PublicKey
func (s *Signer) Sign(data []byte) (Signature, error)
Sign creates a signature for the data using the Signer's private key.