Documentation
¶
Overview ¶
Package apikey manages 0xkey API keys for organizations
Index ¶
- Constants
- func DecodeZeroXKeyPublicECDSAKey(encodedPublicKey string, scheme signatureScheme) (*ecdsa.PublicKey, error)
- func EncodePrivateECDSAKey(privateKey *ecdsa.PrivateKey) string
- func EncodePublicECDSAKey(publicKey *ecdsa.PublicKey) string
- func ExtractSignatureSchemeFromSuffixedPrivateKey(data string) (string, signatureScheme, error)
- func Stamp(message []byte, apiKey *Key) (string, error)
- func WithScheme(scheme signatureScheme) optionFunc
- type APIStamp
- type Curve
- type Key
- func FromECDSAPrivateKey(privateKey *ecdsa.PrivateKey, scheme signatureScheme) (*Key, error)
- func FromED25519PrivateKey(privateKey ed25519.PrivateKey) (*Key, error)
- func FromZeroXKeyPrivateKey(encodedPrivateKey string, scheme signatureScheme) (*Key, error)
- func New(organizationID string, opts ...optionFunc) (*Key, error)
- type Metadata
Constants ¶
const ( // CurveP256 is the wrapped form of the shorthand for the p256 curve. CurveP256 = Curve("p256") // CurveSecp256k1 is the wrapped form of the shorthand for the secp256k1 curve. CurveSecp256k1 = Curve("secp256k1") // CurveEd25519 is the wrapped form of the shorthand for the ed25519 curve. CurveEd25519 = Curve("ed25519") // SchemeUnsupported is a placeholder for scheme not supported by the API, returned // if invalid Curve value is supplied to CurveToScheme. SchemeUnsupported = signatureScheme("") // SchemeP256 is the API enum value for p256 curve. SchemeP256 = signatureScheme("SIGNATURE_SCHEME_TK_API_P256") // SchemeSECP256K1 is the API enum value for secp256k1 curve. SchemeSECP256K1 = signatureScheme("SIGNATURE_SCHEME_TK_API_SECP256K1") // SchemeED25519 is the API enum value for ed25519 curve. SchemeED25519 = signatureScheme("SIGNATURE_SCHEME_TK_API_ED25519") )
const ZeroXKeyECDSAPublicKeyBytes = credential.ECDSAPublicKeyBytes
ZeroXKeyECDSAPublicKeyBytes is the expected number of bytes for a public ECDSA key.
Variables ¶
This section is empty.
Functions ¶
func DecodeZeroXKeyPublicECDSAKey ¶
func DecodeZeroXKeyPublicECDSAKey(encodedPublicKey string, scheme signatureScheme) (*ecdsa.PublicKey, error)
DecodeZeroXKeyPublicECDSAKey takes a 0xkey-encoded public key and creates an ECDSA public key.
func EncodePrivateECDSAKey ¶
func EncodePrivateECDSAKey(privateKey *ecdsa.PrivateKey) string
EncodePrivateECDSAKey encodes an ECDSA private key into the 0xkey format.
func EncodePublicECDSAKey ¶
EncodePublicECDSAKey encodes an ECDSA public key into the 0xkey format.
func ExtractSignatureSchemeFromSuffixedPrivateKey ¶
ExtractSignatureSchemeFromSuffixedPrivateKey infers the signature type from a suffix appended to the end of the private key data (e.g. "deadbeef0123:secp256k1").
func Stamp ¶
Stamp generates a signing stamp for the given message with the given API key. The resulting stamp should be added as the "X-Stamp" header of an API request.
func WithScheme ¶
func WithScheme(scheme signatureScheme) optionFunc
Types ¶
type APIStamp ¶
type APIStamp struct {
// API public key, hex-encoded
PublicKey string `json:"publicKey"`
// Signature is the P-256 signature bytes, hex-encoded
Signature string `json:"signature"`
// Signature scheme. Can be set to "SIGNATURE_SCHEME_TK_API_P256", "SIGNATURE_SCHEME_TK_API_SECP256K1",
// or "SIGNATURE_SCHEME_TK_API_ED25519"
Scheme signatureScheme `json:"scheme"`
}
APIStamp defines the stamp format used to authenticate payloads to the API.
type Curve ¶
type Curve string
Curve is a wrapped abbreviated version of curve; use with CurveToScheme to produce signatureScheme, which is non-exported to limit options.
type Key ¶
type Key struct {
Metadata
EncodedPrivateKey string `json:"-"` // do not store the private key in the metadata file
EncodedPublicKey string `json:"public_key"`
// contains filtered or unexported fields
}
Key defines a structure in which to hold both serialized and ecdsa-lib-friendly versions of a 0xkey API keypair.
func FromECDSAPrivateKey ¶
func FromECDSAPrivateKey(privateKey *ecdsa.PrivateKey, scheme signatureScheme) (*Key, error)
FromECDSAPrivateKey takes an ECDSA keypair and forms a 0xkey API key from it.
func FromED25519PrivateKey ¶
func FromED25519PrivateKey(privateKey ed25519.PrivateKey) (*Key, error)
FromED25519PrivateKey takes an ED25519 keypair and forms a 0xkey API key from it.
func FromZeroXKeyPrivateKey ¶
FromZeroXKeyPrivateKey takes a 0xkey-encoded private key, derives a public key from it, and then returns the corresponding 0xkey API key.
func (Key) GetCurve ¶
GetCurve returns the curve used; defaults to p256 for backwards compatibility with keys created before there were multiple supported types.
func (Key) GetPrivateKey ¶
GetPrivateKey gets the key's private key.
func (Key) GetPublicKey ¶
GetPublicKey gets the key's public key.
func (Key) LoadMetadata ¶
LoadMetadata loads a JSON metadata file.
func (*Key) MergeMetadata ¶
MergeMetadata merges the given metadata with the api key.