wallet

package
Version: v1.65.3 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2021 License: BSD-3-Clause Imports: 35 Imported by: 0

Documentation

Overview

Package ecdh implements the Diffie-Hellman key exchange using elliptic curves (ECDH). It directly provides ECDH implementations for the NIST curves P224, P256, P384, and Bernstein's Cruve25519.

For generic curves this implementation of ECDH only uses the x-coordinate as the computed secret.

Index

Examples

Constants

View Source
const (

	// PrivacyDBVersion 隐私交易运行过程中,需要使用到钱包数据库存储的数据库版本信息的KEY值
	MixDBVersion = prefix + "DBVersion"
	// Privacy4Addr 存储隐私交易保存账户的隐私公钥对信息的KEY值
	// KEY值格式为  	Privacy4Addr-账号地址
	// VALUE值格式为 types.WalletAccountPrivacy, 存储隐私公钥对
	Mix4Addr = prefix + "Addr"
	//
	MixPrivacyEnable = prefix + "PrivacyEnable"
	//current rescan notes status
	MixRescanStatus = prefix + "RescanStatus"
	MixCommitHash   = prefix + "CommitHash"
	MixNullifier    = prefix + "Nullifier"
)
View Source
const (
	MixSignName = "mixZkSnark"
	MixSignID   = 6
)
View Source
const CECBLOCKSIZE = 32
View Source
const LENNULLKEY = 10

空的公钥字符为“0”,不是空,这里多设置了长度

Variables

This section is empty.

Functions

func New

func New() wcom.WalletBizPolicy

New 创建一盒钱包业务策略

func NewMixTable

func NewMixTable(kvdb db.KV) *table.Table

NewStageTable 新建表

Types

type CurveParams

type CurveParams struct {
	Name    string // the canonical name of the curve
	BitSize int    // the size of the underlying field
}

CurveParams contains the parameters of an elliptic curve.

type KeyExchange

type KeyExchange interface {
	// GenerateKey generates a private/public key pair using entropy from rand.
	// If rand is nil, crypto/rand.Reader will be used.
	GenerateKey(rand io.Reader) (private crypto.PrivateKey, public crypto.PublicKey, err error)

	// Params returns the curve parameters - like the field size.
	Params() CurveParams

	// PublicKey returns the public key corresponding to the given private one.
	PublicKey(private crypto.PrivateKey) (public crypto.PublicKey)

	// Check returns a non-nil error if the peers public key cannot used for the
	// key exchange - for instance the public key isn't a point on the elliptic curve.
	// It's recommended to check peer's public key before computing the secret.
	Check(peersPublic crypto.PublicKey) (err error)

	// ComputeSecret returns the secret value computed from the given private key
	// and the peers public key.
	ComputeSecret(private crypto.PrivateKey, peersPublic crypto.PublicKey) (secret []byte)
}

KeyExchange is the interface defining all functions necessary for ECDH.

func X25519

func X25519() KeyExchange

X25519 creates a new ecdh.KeyExchange with the elliptic curve Curve25519.

Example

An example for the ECDH key-exchange using Curve25519.

c25519 := X25519()

privateAlice, publicAlice, err := c25519.GenerateKey(rand.Reader)
if err != nil {
	fmt.Printf("Failed to generate Alice's private/public key pair: %s\n", err)
}
privateBob, publicBob, err := c25519.GenerateKey(rand.Reader)
if err != nil {
	fmt.Printf("Failed to generate Bob's private/public key pair: %s\n", err)
}

if err := c25519.Check(publicBob); err != nil {
	fmt.Printf("Bob's public key is not on the curve: %s\n", err)
}
secretAlice := c25519.ComputeSecret(privateAlice, publicBob)

if err := c25519.Check(publicAlice); err != nil {
	fmt.Printf("Alice's public key is not on the curve: %s\n", err)
}
secretBob := c25519.ComputeSecret(privateBob, publicAlice)

if !bytes.Equal(secretAlice, secretBob) {
	fmt.Printf("key exchange failed - secret X coordinates not equal\n")
}
Output:

type MixRow

type MixRow struct {
	*mix.WalletDbMixInfo
}

MixRow table meta 结构

func NewMixRow

func NewMixRow() *MixRow

NewStageRow 新建一个meta 结构

func (*MixRow) CreateRow

func (r *MixRow) CreateRow() *table.Row

CreateRow 新建数据行(注意index 数据一定也要保存到数据中,不能就保存heightindex)

func (*MixRow) Get

func (r *MixRow) Get(key string) ([]byte, error)

Get 按照indexName 查询 indexValue

func (*MixRow) SetPayload

func (r *MixRow) SetPayload(data types.Message) error

SetPayload 设置数据

type MixSignPrivateKey

type MixSignPrivateKey struct {
	// contains filtered or unexported fields
}

RingSignPrivateKey 环签名中对于crypto.PrivKey接口实现

func (*MixSignPrivateKey) Bytes

func (privkey *MixSignPrivateKey) Bytes() []byte

Bytes convert key to bytest

func (*MixSignPrivateKey) Equals

func (privkey *MixSignPrivateKey) Equals(other crypto.PrivKey) bool

Equals check key equal

func (*MixSignPrivateKey) PubKey

func (privkey *MixSignPrivateKey) PubKey() crypto.PubKey

PubKey convert to public key

func (*MixSignPrivateKey) Sign

func (privkey *MixSignPrivateKey) Sign(msg []byte) crypto.Signature

Sign signature trasaction

type MixSignPublicKey

type MixSignPublicKey struct {
	// contains filtered or unexported fields
}

RingSignPublicKey 环签名中对于crypto.PubKey接口实现

func (*MixSignPublicKey) Bytes

func (pubkey *MixSignPublicKey) Bytes() []byte

Bytes convert key to bytes

func (*MixSignPublicKey) Equals

func (pubkey *MixSignPublicKey) Equals(other crypto.PubKey) bool

Equals check key is equal

func (*MixSignPublicKey) KeyString

func (pubkey *MixSignPublicKey) KeyString() string

KeyString convert key to string

func (*MixSignPublicKey) VerifyBytes

func (pubkey *MixSignPublicKey) VerifyBytes(msg []byte, sign crypto.Signature) bool

VerifyBytes verify bytes

type MixSignZkSnark

type MixSignZkSnark struct {
}

MixSignZkSnark 对应crypto.Crypto的接口实现

func (*MixSignZkSnark) GenKey

func (r *MixSignZkSnark) GenKey() (crypto.PrivKey, error)

GenKey create privacy key

func (*MixSignZkSnark) PrivKeyFromBytes

func (r *MixSignZkSnark) PrivKeyFromBytes(b []byte) (crypto.PrivKey, error)

PrivKeyFromBytes create private key from bytes

func (*MixSignZkSnark) PubKeyFromBytes

func (r *MixSignZkSnark) PubKeyFromBytes(b []byte) (crypto.PubKey, error)

PubKeyFromBytes create publick key from bytes

func (*MixSignZkSnark) SignatureFromBytes

func (r *MixSignZkSnark) SignatureFromBytes(b []byte) (crypto.Signature, error)

SignatureFromBytes create signature from bytes

func (*MixSignZkSnark) Validate

func (r *MixSignZkSnark) Validate(msg, pub, sig []byte) error

Validate validate msg and signature

type MixSignature

type MixSignature struct {
	// contains filtered or unexported fields
}

MixSignature mix签名中对于crypto.Signature接口实现

func (*MixSignature) Bytes

func (r *MixSignature) Bytes() []byte

Bytes convert to bytest

func (*MixSignature) Equals

func (r *MixSignature) Equals(other crypto.Signature) bool

Equals check equals

func (*MixSignature) IsZero

func (r *MixSignature) IsZero() bool

IsZero check is zero

func (*MixSignature) String

func (r *MixSignature) String() string

String convert to string

Jump to

Keyboard shortcuts

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