secp256k1

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2023 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Overview

Copyright 2023 The Go SSI Framework Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2023 The Go SSI Framework Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2023 The Go SSI Framework Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2023 The Go SSI Framework Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Index

Constants

View Source
const Secp256k1 jwa.EllipticCurveAlgorithm = "secp256k1"

Variables

This section is empty.

Functions

func GeneratePrivateKeyAsJwk

func GeneratePrivateKeyAsJwk(didController string) (jwk.Key, error)

GeneratePrivateKeyAsJwk generates secp256k1 key pair and returns private key as json web key

Types

type EciesEncrypted

type EciesEncrypted struct {
	Iv             []byte // 16 bits
	EphemPublicKey []byte // 33 bits
	Mac            []byte // 32 bits
	Ciphertext     []byte // variable bits
}

type PrivateKey

type PrivateKey struct {
	*ecdsa.PrivateKey
	// Needed to include because information is lost when transforming between jwk and ecdsa
	JwkKey jwk.Key
}

PrivateKey is an instance of secp256k1 private key with nested public key

func GeneratePrivateKey

func GeneratePrivateKey() (*PrivateKey, error)

GenerateKey generates secp256k1 key pair

func NewPrivateKeyFromBytes

func NewPrivateKeyFromBytes(privBytes []byte) (*PrivateKey, error)

NewPrivateKeyFromBytes decodes private key raw bytes, computes public key and returns PrivateKey instance

func NewPrivateKeyFromHex

func NewPrivateKeyFromHex(privHex string) (*PrivateKey, error)

NewPrivateKeyFromHex decodes hex form of private key raw bytes, computes public key and returns PrivateKey instance

func NewPrivateKeyFromJwk

func NewPrivateKeyFromJwk(privJwk jwk.Key) (*PrivateKey, error)

func NewPrivateKeyFromMap

func NewPrivateKeyFromMap(privMap map[string]interface{}) (*PrivateKey, error)

NewPrivateKeyFromMap decodes private key from a map, map must be a valid json web key

func SetPrivateKey

func SetPrivateKey(priv *ecdsa.PrivateKey) *PrivateKey

func (*PrivateKey) Bytes

func (k *PrivateKey) Bytes() []byte

Bytes returns private key raw bytes

func (*PrivateKey) Decrypt

func (k *PrivateKey) Decrypt(msg []byte) ([]byte, error)

Decrypt decrypts a passed message with a receiver private key, returns plaintext or decryption error

func (*PrivateKey) ECDH

func (k *PrivateKey) ECDH(pub *ecdsa.PublicKey) ([]byte, error)

ECDH encapsulates key by using Key Encapsulation Mechanism and returns symmetric key; can be safely used as encryption key

func (*PrivateKey) Encrypt

func (k *PrivateKey) Encrypt(pubKey *ecdsa.PublicKey, plaintext []byte) ([]byte, error)

Encrypt encrypts a passed message with a sender private key and receivers public key, returns ecies structure or encryption error

func (*PrivateKey) Equals

func (k *PrivateKey) Equals(priv *ecdsa.PrivateKey) bool

Equals compares two private keys with constant time (to resist timing attacks)

func (*PrivateKey) Hex

func (k *PrivateKey) Hex() string

Hex returns private key bytes in hex form

func (*PrivateKey) Jwk

func (k *PrivateKey) Jwk(didController string) (jwk.Key, error)

Jwk returns private key as json web key

func (*PrivateKey) MarshalJSON

func (k *PrivateKey) MarshalJSON() ([]byte, error)

func (*PrivateKey) Sign

func (k *PrivateKey) Sign(payload interface{}) (interface{}, error)

Sign signs the payload, jwt (payload is jwt.Token) and linked data proof are supported (payload is map[string]interface)

func (*PrivateKey) UnmarshalJSON

func (k *PrivateKey) UnmarshalJSON(data []byte) error

type PublicKey

type PublicKey struct {
	*ecdsa.PublicKey
	// Needed to include because information is lost when transforming between jwk and ecdsa
	JwkKey jwk.Key
}

PublicKey instance with nested elliptic.Curve interface (secp256k1 instance in our case)

func NewPublicKeyFromBytes

func NewPublicKeyFromBytes(pubBytes []byte) (*PublicKey, error)

NewPublicKeyFromBytes decodes public key raw bytes and returns PublicKey instance; Supports both compressed and uncompressed public keys

func NewPublicKeyFromHex

func NewPublicKeyFromHex(pubHex string) (*PublicKey, error)

NewPublicKeyFromHex decodes hex form of public key raw bytes and returns PublicKey instance

func NewPublicKeyFromJwk

func NewPublicKeyFromJwk(pubJwk jwk.Key) (*PublicKey, error)

func NewPublicKeyFromMap

func NewPublicKeyFromMap(pubMap map[string]interface{}) (*PublicKey, error)

NewPublicKeyFromMap decodes public key from a map, map must be a valid json web key

func SetPublicKey

func SetPublicKey(pub *ecdsa.PublicKey) *PublicKey

func (*PublicKey) Bytes

func (k *PublicKey) Bytes(compressed bool) []byte

Bytes returns public key raw bytes; Could be optionally compressed by dropping Y part

func (*PublicKey) ECDH

func (k *PublicKey) ECDH(priv *ecdsa.PrivateKey) ([]byte, error)

Decapsulate decapsulates key by using Key Encapsulation Mechanism and returns symmetric key; can be safely used as encryption key

func (*PublicKey) Equals

func (k *PublicKey) Equals(pub *ecdsa.PublicKey) bool

Equals compares two public keys with constant time (to resist timing attacks)

func (*PublicKey) GetAdress

func (k *PublicKey) GetAdress() (string, error)

GetAdress gets the ethereum address of the public key

func (*PublicKey) Hex

func (k *PublicKey) Hex(compressed bool) string

Hex returns public key bytes in hex form

func (*PublicKey) Jwk

func (k *PublicKey) Jwk() (jwk.Key, error)

Jwk returns public key as json web key

func (*PublicKey) MarshalJSON

func (k *PublicKey) MarshalJSON() ([]byte, error)

func (*PublicKey) UnmarshalJSON

func (k *PublicKey) UnmarshalJSON(data []byte) error

func (*PublicKey) Verify

func (k *PublicKey) Verify(signed interface{}, options ...jwt.ParseOption) error

Verify will verify a signed token with the public key.

Jump to

Keyboard shortcuts

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