Documentation
¶
Overview ¶
Package apikey manages Turnkey API keys for organizations
Index ¶
- Constants
- func DecodeTurnkeyPublicECDSAKey(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) (out string, err 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 FromTurnkeyPrivateKey(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 TurnkeyECDSAPublicKeyBytes = 33
TurnkeyECDSAPublicKeyBytes is the expected number of bytes for a public ECDSA key.
Variables ¶
This section is empty.
Functions ¶
func DecodeTurnkeyPublicECDSAKey ¶
func DecodeTurnkeyPublicECDSAKey(encodedPublicKey string, scheme signatureScheme) (*ecdsa.PublicKey, error)
DecodeTurnkeyPublicECDSAKey takes a Turnkey-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 Turnkey format. For now, "Turnkey format" = raw DER form.
func EncodePublicECDSAKey ¶
EncodePublicECDSAKey encodes an ECDSA public key into the Turnkey format. For now, "Turnkey format" = standard compressed form for ECDSA keys.
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 TkPrivateKey string `json:"-"` // do not store the private key in the metadata file TkPublicKey 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 Turnkey API keypair.
func FromECDSAPrivateKey ¶
func FromECDSAPrivateKey(privateKey *ecdsa.PrivateKey, scheme signatureScheme) (*Key, error)
FromECDSAPrivateKey takes an ECDSA keypair and forms a Turnkey API key from it. Assumes that privateKey.PublicKey has already been derived.
func FromED25519PrivateKey ¶
func FromED25519PrivateKey(privateKey ed25519.PrivateKey) (*Key, error)
FromED25519PrivateKey takes an ED25519 keypair and forms a Turnkey API key from it.
func FromTurnkeyPrivateKey ¶
FromTurnkeyPrivateKey takes a Turnkey-encoded private key, derives a public key from it, and then returns the corresponding Turnkey 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.