Documentation
¶
Index ¶
- Constants
- Variables
- func Base64Decode(s string) ([]byte, error)
- func Base64Encode(b []byte) string
- func Base64URLDecode(s string) ([]byte, error)
- func Base64URLEncode(b []byte) string
- func BitcoinSign(msg []byte, key *ecdsa.PrivateKey) (string, error)
- func BitcoinVerify(msg []byte, sig string, key *ecdsa.PublicKey) (bool, error)
- func CheckWIF(wif string) (valid bool, err error)
- func DecodeSignature(encodedSig string) ([]byte, error)
- func EncodeMessage(payload []byte) []byte
- func EncodeMessageHash(payload []byte) []byte
- func EncodeSignature(sig []byte, compressed bool) string
- func ExtractUint16(size uint16) []byte
- func ExtractUint32(size uint32) []byte
- func ExtractUint64(size uint64) []byte
- func ExtractUint8(size uint) []byte
- func FromECDSA(seckey *ecdsa.PrivateKey) []byte
- func FromECDSAPub(pubkey *ecdsa.PublicKey) []byte
- func GenerateKey() (*ecdsa.PrivateKey, error)
- func HexToECDSA(hexstring string) (*ecdsa.PrivateKey, error)
- func ParseMessage(s string) interface{}
- func Serialize(header *Header, claims *ClaimSet, message string) ([]byte, error)
- func Sha256RipeMD160(b []byte) []byte
- func ShaSha256(b []byte) []byte
- func ToAddress(pub *ecdsa.PublicKey) (address string)
- func ToAddressUncompressed(pub *ecdsa.PublicKey) (address string)
- func ToBytes(pub *ecdsa.PublicKey) (b []byte)
- func ToBytesUncompressed(pub *ecdsa.PublicKey) (b []byte)
- func ToECDSA(b []byte) *ecdsa.PrivateKey
- func ToECDSAPub(b []byte) *ecdsa.PublicKey
- func VarInt(size uint) []byte
- type ClaimSet
- type Header
- type JWSMultiMessage
- type JWSSignature
- type SignedMessage
Constants ¶
const (
NETWORK_NAME = "bitcoin"
)
Variables ¶
var ( ErrRecovery = errors.New("Supplied public key is not equal to the key recovered from the signature.") ErrKidAbsent = errors.New("No Kid was supplied in the header.") ErrKidNoMatch = errors.New("Kid does not match recovered address.") ErrMultiHeadersLength = errors.New("The amount of keys is not equal to the amount of JWS headers.") )
Functions ¶
func Base64Decode ¶
func Base64Encode ¶
func Base64URLDecode ¶
func Base64URLEncode ¶
func BitcoinSign ¶
func BitcoinSign(msg []byte, key *ecdsa.PrivateKey) (string, error)
Sign libsecp256k1
func BitcoinVerify ¶
Verify libsecp256k1
func CheckWIF ¶
CheckWIF checks that string wif is a valid Wallet Import Format or Wallet Import Format Compressed string. If it is not, err is populated with the reason.
func DecodeSignature ¶
Decodes a base64 encoded Bitcoin signature as bytes
func EncodeMessage ¶
Encodes a message according to the Bitcoin protocol
func EncodeMessageHash ¶
Encodes the message and returns the message digest
func EncodeSignature ¶
Encodes a series of bytes representing as a Bitcoin compliant signature
func ExtractUint16 ¶
Extract the first two bytes from a uint as a bytestring
func ExtractUint32 ¶
Extract the first four bytes from a uint as a bytetring
func ExtractUint64 ¶
Extract the first eight bytes from a uint
func ExtractUint8 ¶
Extract the first byte from a uint as a bytestring
func FromECDSA ¶
func FromECDSA(seckey *ecdsa.PrivateKey) []byte
Convert an ecdsa.PrivateKey to a bytestring
func FromECDSAPub ¶
Convert an ecdsa.PublicKey to a bytestring
func GenerateKey ¶
func GenerateKey() (*ecdsa.PrivateKey, error)
Generate a keypair and encode as base64
func HexToECDSA ¶
func HexToECDSA(hexstring string) (*ecdsa.PrivateKey, error)
Convert hex to an ecdsa.PrivateKey
func ParseMessage ¶
func ParseMessage(s string) interface{}
Try to parse a message, signed or multi or return nil
func ToAddressUncompressed ¶
ToAddressUncompressed converts a Bitcoin public key to an uncompressed Bitcoin address string.
func ToBytes ¶
ToBytes converts a Bitcoin public key to a 33-byte byte slice with point compression.
func ToBytesUncompressed ¶
ToBytesUncompressed converts a Bitcoin public key to a 65-byte byte slice without point compression.
func ToECDSA ¶
func ToECDSA(b []byte) *ecdsa.PrivateKey
Convert a set of bytes to an ecdsa.PrivateKey
func ToECDSAPub ¶
Convert a set of bytes to an ecdsa.PublicKey
Types ¶
type ClaimSet ¶
type ClaimSet struct {
Iss string `json:"iss"` // email address of the client_id of the application making the access token request
Scope string `json:"scope,omitempty"` // space-delimited list of the permissions the application requests
Aud string `json:"aud,omitempty"` // descriptor of the intended target of the assertion (Optional).
Exp int64 `json:"exp"` // the expiration time of the assertion (seconds since Unix epoch)
Iat int64 `json:"iat"` // the time the assertion was issued (seconds since Unix epoch)
Typ string `json:"typ,omitempty"` // token type (Optional).
// Email for which the application is requesting delegated access (Optional).
Sub string `json:"sub,omitempty"`
// The old name of Sub. Client keeps setting Prn to be
// complaint with legacy OAuth 2.0 providers. (Optional)
Prn string `json:"prn,omitempty"`
// The public key corresponding to the private key used in signing
PubKey string `json:"pubkey,omitempty"`
// The public keys corresponding to the private keys used to sign
PubKeys []string `json:"pubkeys,omitempty"`
// A generic message expected to be JSON encodable
Msg interface{} `json:"msg,omitempty"`
}
func CreateDefaultClaims ¶
type Header ¶
type Header struct {
// The algorithm used for signing the payload
Algorithm string `json:"alg"`
// The type of token
Typ string `json:"typ,omitempty"`
// The key id of protected header fields
Kid string `json:"kid,omitempty"`
}
Header represents the header for the signed JWS payload
func CreateDefaultHeader ¶
type JWSMultiMessage ¶
type JWSMultiMessage struct {
Payload string `json:"payload"`
Signatures []*JWSSignature `json:"signatures"`
}
Signed MultiSig JWS JSON structure
func ParseMultiSignedMessage ¶
func ParseMultiSignedMessage(jwsString string) *JWSMultiMessage
Try to parse a JWS message or return nil
func SignMulti ¶
func SignMulti(seckeys []*ecdsa.PrivateKey, hdrs []*Header, clm *ClaimSet, message string) (*JWSMultiMessage, error)
Sign an unsigned multi-signature request with the provided body
func SimpleSignMulti ¶
func SimpleSignMulti(seckeys []*ecdsa.PrivateKey, hdrs []*Header, clm *ClaimSet) (*JWSMultiMessage, error)
Sign an unsigned multi-signature request without a body
func (*JWSMultiMessage) EncodeJWS ¶
func (snm *JWSMultiMessage) EncodeJWS() (string, error)
Encode a signed multi signature message to JWS JSON format
func (*JWSMultiMessage) SimpleVerify ¶
func (jm *JWSMultiMessage) SimpleVerify(pubkeys []*ecdsa.PublicKey) (bool, error)
Simple multi signature verification
type JWSSignature ¶
type JWSSignature struct {
Protected string `json:"protected"`
Signature string `json:"signature"` // Base64 URL encoded
}
A JWS JSON Signature structure
type SignedMessage ¶
Signed JWS compact message structure
func ParseSignedMessage ¶
func ParseSignedMessage(compact string) *SignedMessage
Try to parse a signed message or return nil
func Sign ¶
func Sign(key *ecdsa.PrivateKey, hdr *Header, clm *ClaimSet, message string) (*SignedMessage, error)
Sign an unsigned single signature claimset with a message
func SimpleSign ¶
func SimpleSign(key *ecdsa.PrivateKey, hdr *Header, clm *ClaimSet) (*SignedMessage, error)
Sign an unsigned single signature claimset without message
func (*SignedMessage) EncodeCompactJWS ¶
func (sns *SignedMessage) EncodeCompactJWS() (string, error)
Encode a signed message to <header>.<payload>.<signature> compact serialization
func (*SignedMessage) SimpleVerify ¶
func (sm *SignedMessage) SimpleVerify(pubkey *ecdsa.PublicKey) (bool, error)
Simple single signature verification