keys

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	R = 8
	P = 8
	N = 16384
)
View Source
var KeyCases = []Ktype{
	{
		Address:    "AJntkozhVgbc6irY9hRFtNUvuPZS4YcUyD",
		PrivateKey: "831cb932167332a768f1c898d2cf4586a14aa606b7f078eba028c849c306cce6",
		PublicKey:  "03b7a7f933199f28cc1c48d22a21c78ac3992cf7fceb038a9c670fe55444426619",
		Wif:        "L1caMUAsHr2dKwhqbMpYRcCzmzvZTfYZSCBefgARhz9iimAFRn1z",
		Passphrase: "neo-gogogo",
		Nep2key:    "6PYRGTFTzMq5BTcZphryV8KEtyhGJCK7fRZr6etdAKrb2gowRvSjsSA5XZ",
		ScriptHash: "62d6035f671f46b1ab5715eef3a903910bb81921",
	},
	{
		Address:    "AHbwJGdhUy3d1BwhXQKc1VrNojjBTX6g87",
		PrivateKey: "82a4ff38f5de304c2fae62d1a736c343816412f7e4fe3badaf5e1e940c8f07c3",
		PublicKey:  "027d73c8b02e446340caceee7a517cddff72440e60c28cbb84884f307760ecad5b",
		Wif:        "L1bfdDaFQErh7gGMz32zgBXZCN65AKeexKzxeEvS7d4Cq6zf2Rpf",
		Passphrase: "",
		Nep2key:    "6PYP4RrgZTU8zcb5RN2xzeV2ufddJRe2DKom3kW8AhxuLCtFYKAt3dGZ4G",
		ScriptHash: "80176d20bd72e6f8b16332fdfa75bd63cd230f14",
	},
	{
		Address:    "AKeMGQcrN4Su5mEK7T1NgCCyBtY16vD16Y",
		PrivateKey: "31ab808b68c25377b2068500e264f164d1d75eda748a8e0a98db4c74db181b66",
		PublicKey:  "038a2151948a908cdf2d680eead6512217769e34b9db196574572cb98e273516a1",
		Wif:        "KxtGC6QHFKSiHVLY1ANkwS78ebfhworv6LnkJH2MUxE8AbbgAHVW",
		Passphrase: "密码@👍",
		Nep2key:    "6PYUKxjoTp8CmbR4ZDLLdugviWzf7QuxikGir7mudeAcSo9dviT6x6MtPB",
		ScriptHash: "6ea9062064e43b49df964d13da0a413c113b742a",
	},
	{
		Address:    "AQzRMe3zyGS8W177xLJfewRRQZY2kddMun",
		PrivateKey: "b503c7727756aaed15e2cfc1d571e00109c92b075d080038d208f8b9cab917af",
		PublicKey:  "03d08d6f766b54e35745bc99d643c939ec6f3d37004f2a59006be0e53610f0be25",
		Wif:        "L3Hab7wL43SbWLnkfnVCp6dT99xzfB4qLZxeR9dFgcWWPirwKyXp",
		Passphrase: "1",
		Nep2key:    "6PYLjXkQzADs7r36XQjByJXoggm3beRh6UzxuN59NZiBxFBnm1HPvv3ytM",
		ScriptHash: "d2601d3651a41a7faf6e02a280ab26d9dc971865",
	},
}

Arr contains a set of known keys in Ktype format.

Functions

func CreateMultiSigRedeemScript

func CreateMultiSigRedeemScript(m int, ps ...*PublicKey) ([]byte, error)

create multi-signature check script

func CreateSignatureRedeemScript

func CreateSignatureRedeemScript(p *PublicKey) []byte

create signature check script

func NEP2Encrypt

func NEP2Encrypt(keyPair *KeyPair, passphrase string) (s string, err error)

NEP2Encrypt encrypts a the PrivateKey using a given passphrase under the NEP-2 standard.

func ToEcdsa

func ToEcdsa(key []byte) *ecdsa.PrivateKey

ecdsa converts the private key byte[] to a usable ecdsa.PrivateKey for signing data.

func VerifyMultiSig

func VerifyMultiSig(message []byte, signatures [][]byte, pubKeys []*PublicKey) bool

todo UT

func VerifySignature

func VerifySignature(message []byte, signature []byte, p *PublicKey) bool

Verify returns true if the signature is valid and corresponds to the hash and public key

Types

type KeyPair

type KeyPair struct {
	PrivateKey []byte
	PublicKey  *PublicKey
}

func GenerateKeyPair

func GenerateKeyPair() (key *KeyPair, err error)

func NEP2Decrypt

func NEP2Decrypt(key, passphrase string) (s *KeyPair, err error)

NEP2Decrypt decrypts an encrypted key using a given passphrase under the NEP-2 standard.

func NewKeyPair

func NewKeyPair(privateKey []byte) (key *KeyPair, err error)

func NewKeyPairFromNEP2

func NewKeyPairFromNEP2(nep2 string, password string) (key *KeyPair, err error)

func NewKeyPairFromWIF

func NewKeyPairFromWIF(wif string) (key *KeyPair, err error)

func (*KeyPair) ExportNep2

func (p *KeyPair) ExportNep2(password string) (string, error)

export nep2 key string

func (*KeyPair) ExportWIF

func (p *KeyPair) ExportWIF() string

export wif string

func (*KeyPair) Sign

func (p *KeyPair) Sign(message []byte) ([]byte, error)

sign message with KeyPair

func (*KeyPair) String

func (p *KeyPair) String() string

String implements the Stringer interface.

func (*KeyPair) ToEcdsa

func (p *KeyPair) ToEcdsa() *ecdsa.PrivateKey

ecdsa converts the key to a usable ecdsa.PrivateKey for signing data.

type KeyPairSlice

type KeyPairSlice []*KeyPair

func (KeyPairSlice) Len

func (kps KeyPairSlice) Len() int

func (KeyPairSlice) Less

func (kps KeyPairSlice) Less(i, j int) bool

func (KeyPairSlice) Swap

func (kps KeyPairSlice) Swap(i, j int)

type Ktype

type Ktype struct {
	Address,
	PrivateKey,
	PublicKey,
	Wif,
	Passphrase,
	Nep2key,
	ScriptHash string
}

Ktype represents key test case values (different encodings of the key).

type PublicKey

type PublicKey struct {
	X *big.Int
	Y *big.Int
}

PublicKey represents a public key and provides a high level API around the X/Y point.

func NewPublicKey

func NewPublicKey(data []byte) (*PublicKey, error)

NewPublicKey return a public key created from the given []byte.

func NewPublicKeyFromString

func NewPublicKeyFromString(s string) (*PublicKey, error)

NewPublicKeyFromString return a public key created from the given hex string.

func (*PublicKey) Address

func (p *PublicKey) Address() string

Address returns a base58-encoded NEO-specific address based on the key hash.

func (*PublicKey) Compare

func (p *PublicKey) Compare(q *PublicKey) int

Compare q to q

func (*PublicKey) Deserialize

func (p *PublicKey) Deserialize(r io.Reader) error

Deserialize a PublicKey from the given io.Reader.

func (*PublicKey) EncodeCompression

func (p *PublicKey) EncodeCompression() []byte

Bytes returns the byte array representation of the public key.

func (*PublicKey) ScriptHash

func (p *PublicKey) ScriptHash() helper.UInt160

Signature returns a NEO-specific hash of the key.

func (*PublicKey) Serialize

func (p *PublicKey) Serialize(w io.Writer) error

Serialize encodes a PublicKey to the given io.Writer.

func (*PublicKey) String

func (p *PublicKey) String() string

String implements the Stringer interface.

type PublicKeySlice

type PublicKeySlice []*PublicKey

PublicKeys is a list of public keys.

func (PublicKeySlice) Len

func (keys PublicKeySlice) Len() int

func (PublicKeySlice) Less

func (keys PublicKeySlice) Less(i, j int) bool

func (PublicKeySlice) Swap

func (keys PublicKeySlice) Swap(i, j int)

Jump to

Keyboard shortcuts

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