Documentation ¶
Overview ¶
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Variables
- func CRandBytes(numBytes int) []byte
- func CRandHex(numDigits int) string
- func CReader() io.Reader
- func CompressPubkey(pubkey *ecdsa.PublicKey) []byte
- func CreateAddress(b common.Address, nonce uint64) common.Address
- func CreateAddress2(b common.Address, salt [32]byte, inithash []byte) common.Address
- func DecompressPubkey(pubkey []byte) (*ecdsa.PublicKey, error)
- func Ecrecover(hash, sig []byte) ([]byte, error)
- func FromECDSA(priv *ecdsa.PrivateKey) []byte
- func FromECDSAPub(pub *ecdsa.PublicKey) []byte
- func GenerateKey() (*ecdsa.PrivateKey, error)
- func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error)
- func Keccak256(data ...[]byte) []byte
- func Keccak256Hash(data ...[]byte) (h common.Hash)
- func Keccak512(data ...[]byte) []byte
- func LoadECDSA(file string) (*ecdsa.PrivateKey, error)
- func MixEntropy(seedBytes []byte)
- func PubkeyToAddress(p ecdsa.PublicKey) common.Address
- func Ripemd160(bytes []byte) []byte
- func S256() elliptic.Curve
- func SaveECDSA(file string, key *ecdsa.PrivateKey) error
- func Sha256(bytes []byte) []byte
- func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error)
- func Sign(hash []byte, prv *ecdsa.PrivateKey) ([]byte, error)
- func ToECDSA(d []byte) (*ecdsa.PrivateKey, error)
- func ToECDSAUnsafe(d []byte) *ecdsa.PrivateKey
- func UnmarshalPubkey(pub []byte) (*ecdsa.PublicKey, error)
- func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool
- func VerifySignature(pubkey, hash, signature []byte) bool
- type CryptoType
- type ISigner
- type KyberEd22519PrivKey
- type PrivateKey
- type PublicKey
- type PublicKeys
- type Signature
- type SignerEd25519
- func (s *SignerEd25519) Address(pubKey PublicKey) common.Address
- func (s *SignerEd25519) AddressFromPubKeyBytes(pubKey []byte) common.Address
- func (s *SignerEd25519) CanRecoverPubFromSig() bool
- func (s *SignerEd25519) Decrypt(p PrivateKey, ct []byte) (m []byte, err error)
- func (s *SignerEd25519) Encrypt(publicKey PublicKey, m []byte) (ct []byte, err error)
- func (s *SignerEd25519) GetCryptoType() CryptoType
- func (s *SignerEd25519) PubKey(privKey PrivateKey) PublicKey
- func (s *SignerEd25519) PublicKeyFromBytes(b []byte) PublicKey
- func (s *SignerEd25519) RandomKeyPair() (publicKey PublicKey, privateKey PrivateKey)
- func (s *SignerEd25519) Sign(privKey PrivateKey, msg []byte) Signature
- func (s *SignerEd25519) Verify(pubKey PublicKey, signature Signature, msg []byte) bool
- type SignerSecp256k1
- func (s *SignerSecp256k1) Address(pubKey PublicKey) common.Address
- func (s *SignerSecp256k1) AddressFromPubKeyBytes(pubKey []byte) common.Address
- func (s *SignerSecp256k1) CanRecoverPubFromSig() bool
- func (s *SignerSecp256k1) DealRecoverID(sig Signature) Signature
- func (s *SignerSecp256k1) Decrypt(p PrivateKey, ct []byte) (m []byte, err error)
- func (s *SignerSecp256k1) Encrypt(p PublicKey, m []byte) (ct []byte, err error)
- func (s *SignerSecp256k1) GetCryptoType() CryptoType
- func (s *SignerSecp256k1) PubKey(privKey PrivateKey) PublicKey
- func (s *SignerSecp256k1) PublicKeyFromBytes(b []byte) PublicKey
- func (s *SignerSecp256k1) RandomKeyPair() (publicKey PublicKey, privateKey PrivateKey)
- func (s *SignerSecp256k1) Sign(privKey PrivateKey, msg []byte) Signature
- func (s *SignerSecp256k1) Verify(pubKey PublicKey, signature Signature, msg []byte) bool
Constants ¶
This section is empty.
Variables ¶
var CryptoNameMap = map[string]CryptoType{ "secp256k1": CryptoTypeSecp256k1, "ed25519": CryptoTypeEd25519, }
Functions ¶
func CompressPubkey ¶
CompressPubkey encodes a public key to the 33-byte compressed format.
func CreateAddress ¶
CreateAddress creates an ethereum address given the bytes and the nonce
func CreateAddress2 ¶
CreateAddress2 creates an ethereum address given the address bytes, initial contract code hash and a salt.
func DecompressPubkey ¶
DecompressPubkey parses a public key in the 33-byte compressed format.
func FromECDSA ¶
func FromECDSA(priv *ecdsa.PrivateKey) []byte
FromECDSA exports a private key into a binary dump.
func FromECDSAPub ¶
func GenerateKey ¶
func GenerateKey() (*ecdsa.PrivateKey, error)
func HexToECDSA ¶
func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error)
HexToECDSA parses a secp256k1 private key.
func Keccak256Hash ¶
Keccak256Hash calculates and returns the Keccak256 hash of the input data, converting it to an internal Hash data structure.
func LoadECDSA ¶
func LoadECDSA(file string) (*ecdsa.PrivateKey, error)
LoadECDSA loads a secp256k1 private key from the given file.
func MixEntropy ¶
func MixEntropy(seedBytes []byte)
Mix additional bytes of randomness, e.g. from hardware, user-input, etc. It is OK to call it multiple times. It does not diminish security.
func SaveECDSA ¶
func SaveECDSA(file string, key *ecdsa.PrivateKey) error
SaveECDSA saves a secp256k1 private key to the given file with restrictive permissions. The key data is saved hex-encoded.
func Sign ¶
func Sign(hash []byte, prv *ecdsa.PrivateKey) ([]byte, error)
Sign calculates an ECDSA signature.
This function is susceptible to chosen plaintext attacks that can leak information about the private key that is used for signing. Callers must be aware that the given hash cannot be chosen by an adversery. Common solution is to hash any input before calculating the signature.
The produced signature is in the [R || S || V] format where V is 0 or 1.
func ToECDSA ¶
func ToECDSA(d []byte) (*ecdsa.PrivateKey, error)
ToECDSA creates a private key with the given D value.
func ToECDSAUnsafe ¶
func ToECDSAUnsafe(d []byte) *ecdsa.PrivateKey
ToECDSAUnsafe blindly converts a binary blob to a private key. It should almost never be used unless you are sure the input is valid and want to avoid hitting errors due to bad origin encoding (0 prefixes cut off).
func UnmarshalPubkey ¶
UnmarshalPubkey converts bytes to a secp256k1 public key.
func ValidateSignatureValues ¶
ValidateSignatureValues verifies whether the signature values are valid with the given chain rules. The v value is assumed to be either 0 or 1.
func VerifySignature ¶
VerifySignature checks that the given public key created signature over hash. The public key should be in compressed (33 bytes) or uncompressed (65 bytes) format. The signature should have the 64 byte [R || S] format.
Types ¶
type CryptoType ¶
type CryptoType int8
const ( CryptoTypeEd25519 CryptoType = iota CryptoTypeSecp256k1 )
func (CryptoType) String ¶
func (c CryptoType) String() string
type ISigner ¶ added in v0.0.2
type ISigner interface { GetCryptoType() CryptoType Sign(privKey PrivateKey, msg []byte) Signature PubKey(privKey PrivateKey) PublicKey Verify(pubKey PublicKey, signature Signature, msg []byte) bool RandomKeyPair() (publicKey PublicKey, privateKey PrivateKey) Address(pubKey PublicKey) common.Address AddressFromPubKeyBytes(pubKey []byte) common.Address Encrypt(publicKey PublicKey, m []byte) (ct []byte, err error) Decrypt(p PrivateKey, ct []byte) (m []byte, err error) PublicKeyFromBytes(b []byte) PublicKey CanRecoverPubFromSig() bool }
var Signer ISigner
set this value when you code run
func NewSigner ¶
func NewSigner(cryptoType CryptoType) ISigner
type KyberEd22519PrivKey ¶
type KyberEd22519PrivKey struct { PrivateKey kyber.Scalar Suit *edwards25519.SuiteEd25519 }
type PrivateKey ¶
type PrivateKey struct { Type CryptoType Bytes []byte }
func PrivateKeyFromBytes ¶
func PrivateKeyFromBytes(typev CryptoType, bytes []byte) PrivateKey
func PrivateKeyFromString ¶
func PrivateKeyFromString(value string) (priv PrivateKey, err error)
func (*PrivateKey) PublicKey ¶
func (p *PrivateKey) PublicKey() *PublicKey
func (*PrivateKey) String ¶
func (k *PrivateKey) String() string
func (*PrivateKey) ToKyberEd25519PrivKey ¶
func (p *PrivateKey) ToKyberEd25519PrivKey() *KyberEd22519PrivKey
type PublicKey ¶
type PublicKey struct { Type CryptoType Bytes []byte }
func PublicKeyFromBytes ¶
func PublicKeyFromBytes(typev CryptoType, bytes []byte) PublicKey
func PublicKeyFromString ¶
type PublicKeys ¶ added in v0.0.2
type PublicKeys []PublicKey
func (PublicKeys) Len ¶ added in v0.0.2
func (h PublicKeys) Len() int
func (PublicKeys) Less ¶ added in v0.0.2
func (h PublicKeys) Less(i, j int) bool
func (PublicKeys) Swap ¶ added in v0.0.2
func (h PublicKeys) Swap(i, j int)
type Signature ¶
type Signature struct { Type CryptoType Bytes []byte }
func SignatureFromBytes ¶
func SignatureFromBytes(typev CryptoType, bytes []byte) Signature
type SignerEd25519 ¶
type SignerEd25519 struct { }
func (*SignerEd25519) Address ¶
func (s *SignerEd25519) Address(pubKey PublicKey) common.Address
Address calculate the address from the pubkey
func (*SignerEd25519) AddressFromPubKeyBytes ¶
func (s *SignerEd25519) AddressFromPubKeyBytes(pubKey []byte) common.Address
func (*SignerEd25519) CanRecoverPubFromSig ¶ added in v0.0.2
func (s *SignerEd25519) CanRecoverPubFromSig() bool
func (*SignerEd25519) Decrypt ¶
func (s *SignerEd25519) Decrypt(p PrivateKey, ct []byte) (m []byte, err error)
func (*SignerEd25519) Encrypt ¶
func (s *SignerEd25519) Encrypt(publicKey PublicKey, m []byte) (ct []byte, err error)
func (*SignerEd25519) GetCryptoType ¶
func (s *SignerEd25519) GetCryptoType() CryptoType
func (*SignerEd25519) PubKey ¶
func (s *SignerEd25519) PubKey(privKey PrivateKey) PublicKey
func (*SignerEd25519) PublicKeyFromBytes ¶ added in v0.0.2
func (s *SignerEd25519) PublicKeyFromBytes(b []byte) PublicKey
func (*SignerEd25519) RandomKeyPair ¶
func (s *SignerEd25519) RandomKeyPair() (publicKey PublicKey, privateKey PrivateKey)
func (*SignerEd25519) Sign ¶
func (s *SignerEd25519) Sign(privKey PrivateKey, msg []byte) Signature
type SignerSecp256k1 ¶
type SignerSecp256k1 struct { }
func (*SignerSecp256k1) Address ¶
func (s *SignerSecp256k1) Address(pubKey PublicKey) common.Address
Address calculate the address from the pubkey
func (*SignerSecp256k1) AddressFromPubKeyBytes ¶
func (s *SignerSecp256k1) AddressFromPubKeyBytes(pubKey []byte) common.Address
func (*SignerSecp256k1) CanRecoverPubFromSig ¶ added in v0.0.2
func (s *SignerSecp256k1) CanRecoverPubFromSig() bool
func (*SignerSecp256k1) DealRecoverID ¶
func (s *SignerSecp256k1) DealRecoverID(sig Signature) Signature
func (*SignerSecp256k1) Decrypt ¶
func (s *SignerSecp256k1) Decrypt(p PrivateKey, ct []byte) (m []byte, err error)
func (*SignerSecp256k1) Encrypt ¶
func (s *SignerSecp256k1) Encrypt(p PublicKey, m []byte) (ct []byte, err error)
func (*SignerSecp256k1) GetCryptoType ¶
func (s *SignerSecp256k1) GetCryptoType() CryptoType
func (*SignerSecp256k1) PubKey ¶
func (s *SignerSecp256k1) PubKey(privKey PrivateKey) PublicKey
func (*SignerSecp256k1) PublicKeyFromBytes ¶ added in v0.0.2
func (s *SignerSecp256k1) PublicKeyFromBytes(b []byte) PublicKey
func (*SignerSecp256k1) RandomKeyPair ¶
func (s *SignerSecp256k1) RandomKeyPair() (publicKey PublicKey, privateKey PrivateKey)
func (*SignerSecp256k1) Sign ¶
func (s *SignerSecp256k1) Sign(privKey PrivateKey, msg []byte) Signature
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve.
|
Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve. |
cloudflare
Package bn256 implements a particular bilinear group at the 128-bit security level.
|
Package bn256 implements a particular bilinear group at the 128-bit security level. |
google
Package bn256 implements a particular bilinear group.
|
Package bn256 implements a particular bilinear group. |
Package secp256k1 wraps the bitcoin secp256k1 C library.
|
Package secp256k1 wraps the bitcoin secp256k1 C library. |