crypto

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2020 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SEED_TEST_STRING ...
	SEED_TEST_STRING = "e5dcc2bdf7310ea3abc82a3580621bd0a487c181113d889d0775d3f8eba21e84"

	// IDKEY_TEST_STRING ...
	IDKEY_TEST_STRING = "68403eeafc1431eb85aabd250480752b3950f50463023a42f4d4d3b301544451"

	// PATH_1_STRING ...
	PATH_1_STRING = "m/0'/0/0"

	// PUBLIC_DECOMPRESSED_KEY_1_STRING ...
	PUBLIC_DECOMPRESSED_KEY_1_STRING = "" /* 130-byte string literal not displayed */

	// PUBLIC_COMPRESSED_KEY_1_STRING ...
	PUBLIC_COMPRESSED_KEY_1_STRING = "03e315a987bd79b9f49d3a1c8bd1ef5a401a242820d52a3f22505da81dfcd992cc"

	// SECRET_KEY_1_STRING ...
	SECRET_KEY_1_STRING = "b9fc3b425d6c1745b9c963c97e6e1d4c1db7a093a36e0cf7c0bf85dc1130b8a0"
)

Variables

This section is empty.

Functions

func CheckSig

func CheckSig(signature []byte, msg []byte, decompressedPublicKey []byte) bool

CheckSig is the function that verifies the validity of the signature of a given content with a public key.

It takes the signature, the content that was signed and the decompressed public key to use as arguments and returns true if it checks out. It's the verifying counterpart of the Sig() function. Therefore, as of the latest version, it takes an ECDSA signature in 64-byte [R||S] format and its associated decompressed public key in byte array and hashes the content message with the system's Hash() function before using it.

func Decrypt

func Decrypt(ciphered, privateKey, decompressedPublicKey []byte) ([]byte, error)

Decrypt ...

func ECDSAPrivateKeyFrom

func ECDSAPrivateKeyFrom(privateKeyBytes, publicKeyBytes []byte) (sk ecdsa.PrivateKey, err error)

ECDSAPrivateKeyFrom ...

func ECDSAPublicKeyFrom

func ECDSAPublicKeyFrom(publicKeyBytes []byte) (pk ecdsa.PublicKey, err error)

ECDSAPublicKeyFrom ...

func ECIESKeyPairFrom

func ECIESKeyPairFrom(ecdsaPublicKBytes, ecdsaPrivateKBytes []byte) (pubkey ecies.PublicKey, privkey ecies.PrivateKey, err error)

ECIESKeyPairFrom transforms an ECDSA keypair in byte array to its ECIES counterparts.

It takes a keypair in byte array and returns the ECIES PublicKey and PrivateKey objects, and an error if something went wrong. Keys generated through the GenerateKeyPair() function should be compatible.

func Encrypt

func Encrypt(msg, decompressedPublicKey []byte) ([]byte, error)

Encrypt ...

func GenerateKeyPair

func GenerateKeyPair(seed []byte, path Path) (pubkey, privkey []byte, err error)

GenerateKeyPair is the function that should be used whenever a keypair is needed in the rooot™ project.

It takes a seed and a BIP32 path, and returns a keypair in byte array, decompressed public and private, and an error if any. As of the latest version in the system, this keypair operates on Bitcoin's secp256k1 elliptic curve. It shall be used for either signing with ECDSA or encrypting/decrypting with ECIES. One should use the utils.ToHex() utility method to save any of these byte arrays as their hexadecimal string representation if needed.

func GenerateRandomKeyPair

func GenerateRandomKeyPair() (pubkey, privkey []byte, err error)

GenerateRandomKeyPair generates a random keypair

func Hash

func Hash(input []byte) ([]byte, error)

Hash is the hashing function that should be used whenever hashing in the rooot™ project.

It takes a byte array as argument and returns a byte array and an error if any. As of the latest version of the system, it double-hashes any input string with the SHA256 standard algorithm. One should use the utils.ToHex() utility method to save the byte array as its hexadecimal string representation.

func IsCompatibleKeyPair

func IsCompatibleKeyPair(pk, sk []byte) bool

IsCompatibleKeyPair tests whether a decompressed public key and a private key form an actual valid keypair.

func IsHashedValue

func IsHashedValue(str string) bool

IsHashedValue ...

func ParsePrivateKey

func ParsePrivateKey(base58PrivateKey string) (pubkey []byte, err error)

ParsePrivateKey ...

func ParsePublicKey

func ParsePublicKey(base58PublicKey string) (pubkey []byte, err error)

ParsePublicKey ...

func ParsePublicKeyFromCompressed

func ParsePublicKeyFromCompressed(str string) (pubkey []byte, err error)

ParsePublicKeyFromCompressed ...

func Sig

func Sig(msg []byte, secretKey []byte) ([]byte, error)

Sig is the signature function that should be used whenever signing in the rooot™ project.

It takes the content to sign and the secret key to use as arguments and returns the signature and an error if any. As of the latest version of the system, it first hashes the content message with the system's Hash() function, then signs it using Bitcoin's secp256k1 elliptic curve that returns a recoverable ECDSA signature in 65-byte [R||S||V] format, and finally gets rid of the recovery 65th byte (the V).

func SignatureImport

func SignatureImport(input []byte) (signature []byte, err error)

SignatureImport parses a DER ECDSA signature as in `ecies-geth` JavaScript module to produce the appropriate 64-byte [R||S] signature @see https://github.com/cryptocoinjs/secp256k1-node/blob/90a04a2e1127f4c1bfd7015aa5a7b22d08edb811/lib/elliptic.js

Types

type Account

type Account struct {
	Number   uint32
	Hardened bool
}

Account ...

type Indices

type Indices struct {
	Account  Account
	Scope    uint32
	KeyIndex uint32
}

Indices ...

type Path

type Path string

Path is the string representation of a BIP32 path, eg. "m/0'/0/0"

func (Path) Parse

func (p Path) Parse() (i Indices, err error)

Parse ...

type PublicKey

type PublicKey struct {
	Path  string `json:"path"`
	Value string `json:"value"`
}

PublicKey is the decompressed BIP-32 public key used for encrypting and/or signing transactions in rooot™

func CompressedToPublicKey

func CompressedToPublicKey(path string, compressed string) (pk *PublicKey, err error)

CompressedToPublicKey ...

func ToPublicKey

func ToPublicKey(path string, decompressed string) *PublicKey

ToPublicKey ...

func (PublicKey) Compressed

func (pk PublicKey) Compressed() (comp []byte, err error)

Compressed ...

func (PublicKey) Decompressed

func (pk PublicKey) Decompressed() (dec []byte, err error)

Decompressed ...

Jump to

Keyboard shortcuts

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