ec

package
v0.0.0-...-25c81e3 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2018 License: ISC Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	N1      = 16384
	N2      = 1024
	R1      = 8
	R2      = 1
	P1      = 8
	P2      = 1
	KeyLen1 = 32
	KeyLen2 = 64
)

Parameters configuration for SCRYPT

View Source
const (
	// Compressed denotes the public key is in compressed form
	Compressed = 0x20
	// Uncompressed denotes the public key is in uncompressed form
	Uncompressed = 0x00
	// NoLotSequence is employed when no lot number or sequence number is included
	NoLotSequence = 0x00
	// WithLotSequence is the opposite to NoLotSequence
	WithLotSequence = 0x04
)

flag bits

View Source
const ConfirmationMagicLen = 5

ConfirmationMagicLen is the length of magic bytes to encode the confirmation code returning to owner from the generator

View Source
const MagicLen = 8

MagicLen is the length of magic bytes to encode the intermediate passphrase string

View Source
const RawConfirmationCodeLen = 1 + 4 + 8 + 33

RawConfirmationCodeLen is the length of confirmation code without encoding and the magic prefix

View Source
const RawEncryptedKeyLen = 1 + 4 + 8 + 8 + 16

RawEncryptedKeyLen is the length of encrypted private key without base58 encoding and trimming out the version prefix

View Source
const VersionLen = 2

VersionLen is length of version prefix for encrypting private key according to EC-Multiply mode

Variables

View Source
var ConfirmationMagicCode = []byte{0x64, 0x3B, 0xF6, 0xA8, 0x9A}

ConfirmationMagicCode prepend to the raw confirmation code to make up the "cfrm38" prefix in the final base58-encoding string

View Source
var Version = []byte{0x01, 0x43}

Version is the object identifier prefix for EC-Multiply encryption mode

Functions

func DecodeLotSequence

func DecodeLotSequence(lotSequence []byte) (uint32, uint32)

DecodeLotSequence decodes the lot and sequence numbers out of the given byte sequence. The first 4 bytes of lotSequence would be employed for decoding.

func Decrypt

func Decrypt(encrypted string, passphrase string) ([]byte, error)

Decrypt decrypts the derived private key out of the base58-encoded encrypted string based on the owner's passphrase. And if applicable, the corresponding lot and sequence number can be recovered using the LotSequenceFromEncryptedKey function.

func EncodeLotSequence

func EncodeLotSequence(lotSequence []byte, lot, sequence uint32)

EncodeLotSequence encodes the lot and sequence numbers into the given lotSequence buffer. And the first 32 bits consist of the least significant 20 bits of lot following by the 12 bits of sequence.

func Encrypt

func Encrypt(rand io.Reader, passphraseEx string,
	compressed bool) (string, string, error)

Encrypt derives an encrypted private key from the given passphrase code and return the resultant encrypted private key and confirmation code

func EncryptPassphrase

func EncryptPassphrase(rand io.Reader, passphrase string) (
	string, error)

EncryptPassphrase generates a intermediate passphrase code from the given one provided by owner.

func EncryptPassphraseX

func EncryptPassphraseX(rand io.Reader, passphrase string,
	lot, sequence uint32) (string, error)

EncryptPassphraseX works similarly to EncryptPassphrase, except that the ownerEntropy consists of 4 byte owner salt and 4 byte buffer encoded from the lot number and the sequence number.

func GenerateConfirmationCode

func GenerateConfirmationCode(flag byte, addrHash, ownerEntropy, b,
	derivedHalf1, derivedHalf2 []byte) string

GenerateConfirmationCode derives the corresponding confirmation code based on the intermediate information during private key encryption. Especially, both derivedHalf1 and derivedHalf2 should be of exact length as 32 bytes. Otherwise, the program would behave unexpectedly.

func LotSequenceFromConfirmationCode

func LotSequenceFromConfirmationCode(code string) (uint32, uint32, error)

LotSequenceFromConfirmationCode decodes the lot number and sequence number out of the given passphrase code.

func LotSequenceFromEncryptedKey

func LotSequenceFromEncryptedKey(encrypted string) (uint32, uint32, error)

LotSequenceFromEncryptedKey decodes the lot number and sequence number out of the given encrypted private key.

func RecoverAddress

func RecoverAddress(passphrase, code string) (string, error)

RecoverAddress recovers the generated address out of the given confirmation code based on the given passphrase. If applicable, the corresponding lot and sequence number can be recovered from this passphrase code using LotSequenceFromConfirmationCode function.

Types

This section is empty.

Jump to

Keyboard shortcuts

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