apikey

package
v0.0.0-...-5ebfb53 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package apikey manages Turnkey API keys for organizations

Index

Constants

View Source
const TurnkeyAPISignatureScheme = "SIGNATURE_SCHEME_TK_API_P256"

TurnkeyAPISignatureScheme is the signature scheme to use for the API request signature.

Variables

This section is empty.

Functions

func DecodeTurnkeyPublicKey

func DecodeTurnkeyPublicKey(encodedPublicKey string) (*ecdsa.PublicKey, error)

DecodeTurnkeyPublicKey takes a Turnkey-encoded public key and creates an ECDSA public key.

func EncodePrivateKey

func EncodePrivateKey(privateKey *ecdsa.PrivateKey) string

EncodePrivateKey encodes an ECDSA private key into the Turnkey format. For now, "Turnkey format" = raw DER form.

func EncodePublicKey

func EncodePublicKey(publicKey *ecdsa.PublicKey) string

EncodePublicKey encodes an ECDSA public key into the Turnkey format. For now, "Turnkey format" = standard compressed form for ECDSA keys.

func Stamp

func Stamp(message []byte, apiKey *Key) (out string, err error)

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.

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. Must be set to "SIGNATURE_SCHEME_TK_API_P256"
	Scheme string `json:"scheme"`
}

APIStamp defines the stamp format used to authenticate payloads to the API.

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) (*Key, error)

FromECDSAPrivateKey takes an ECDSA keypair and forms a Turnkey API key from it. Assumes that privateKey.PublicKey has already been derived.

func FromTurnkeyPrivateKey

func FromTurnkeyPrivateKey(encodedPrivateKey string) (*Key, error)

FromTurnkeyPrivateKey takes a Turnkey-encoded private key, derives a public key from it, and then returns the corresponding Turnkey API key.

func New

func New(organizationID string) (*Key, error)

New generates a new Turnkey API key.

func (Key) GetMetadata

func (k Key) GetMetadata() Metadata

GetMetadata gets the key's metadata.

func (Key) GetPrivateKey

func (k Key) GetPrivateKey() string

GetPrivateKey gets the key's private key.

func (Key) GetPublicKey

func (k Key) GetPublicKey() string

GetPublicKey gets the key's public key.

func (Key) LoadMetadata

func (k Key) LoadMetadata(fn string) (*Metadata, error)

LoadMetadata loads a JSON metadata file.

func (Key) MergeMetadata

func (k Key) MergeMetadata(md Metadata) error

MergeMetadata merges the given metadata with the api key.

type Metadata

type Metadata struct {
	Name          string   `json:"name"`
	Organizations []string `json:"organizations"`
	PublicKey     string   `json:"public_key"`
}

Metadata stores non-secret metadata about the API key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL