wallet

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PREFIX_MAINNET = "ckb"
	PREFIX_TESTNET = "ckt"
)

Variables

This section is empty.

Functions

func GetLockScriptArgsFromShortAddress

func GetLockScriptArgsFromShortAddress(address string) (string, error)

func GetShortAddressFromLockScriptArgs

func GetShortAddressFromLockScriptArgs(args string, isTestNet bool) (string, error)

payload = type(01) | code hash index(00) | pubkey Blake160 docs: https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md

Types

type CkbWalletObj

type CkbWalletObj struct {
	SystemScripts *utils.SystemScripts
	Secp256k1Key  *secp256k1.Secp256k1Key
	LockScript    *types.Script
}

func InitCkbWallet

func InitCkbWallet(privateKeyHex string, systemScript *utils.SystemScripts) (*CkbWalletObj, error)

type EllipticCurve

type EllipticCurve struct {
	A *big.Int
	B *big.Int
	P *big.Int
	G Point
	N *big.Int
	H *big.Int
}
y**2 = x**3 + a*x + b  % p

EllipticCurve represents the parameters of a short Weierstrass equation elliptic curve.

func (*EllipticCurve) Add

func (ec *EllipticCurve) Add(P, Q Point) (R Point)

Add computes R = P + Q on EllipticCurve ec.

func (*EllipticCurve) Decompress

func (ec *EllipticCurve) Decompress(x *big.Int, ylsb uint) (P Point, err error)

Decompress decompresses coordinate x and ylsb (y's least significant bit) into a Point P on EllipticCurve ec.

func (*EllipticCurve) IsInfinity

func (ec *EllipticCurve) IsInfinity(P Point) bool

IsInfinity checks if point P is infinity on EllipticCurve ec.

func (*EllipticCurve) IsOnCurve

func (ec *EllipticCurve) IsOnCurve(P Point) bool

IsOnCurve checks if point P is on EllipticCurve ec.

func (*EllipticCurve) ScalarBaseMult

func (ec *EllipticCurve) ScalarBaseMult(k *big.Int) (Q Point)

ScalarBaseMult computes Q = k * G on EllipticCurve ec.

func (*EllipticCurve) ScalarMult

func (ec *EllipticCurve) ScalarMult(k *big.Int, P Point) (Q Point)

ScalarMult computes Q = k * P on EllipticCurve ec.

type HexStrObj

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

func (*HexStrObj) Bytes

func (hs *HexStrObj) Bytes() []byte

type NewWalletObj

type NewWalletObj struct {
	PriKeyHex  string
	PubKeyHex  string
	AddressHex string
}

func CreateCKBWallet

func CreateCKBWallet(isTestNet bool) (*NewWalletObj, error)

func (*NewWalletObj) Json

func (n *NewWalletObj) Json() string

type Point

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

Point represents a point on an EllipticCurve.

type PrivateKey

type PrivateKey struct {
	PublicKey
	D *big.Int
}

PrivateKey represents a Bitcoin private key.

func GenerateKey

func GenerateKey(rand io.Reader) (priv PrivateKey, err error)

GenerateKey generates a public and private key pair using random source rand.

func NewPrivateKey

func NewPrivateKey(d *big.Int) *PrivateKey

func (*PrivateKey) ToBytes

func (priv *PrivateKey) ToBytes() (b []byte)

ToBytes converts a Bitcoin private key to a 32-byte byte slice.

type PublicKey

type PublicKey struct {
	Point
}

PublicKey represents a Bitcoin public key.

func (*PublicKey) ToBytes

func (pub *PublicKey) ToBytes() (b []byte)

ToBytes converts a Bitcoin public key to a 33-byte byte slice with point compression.

func (*PublicKey) ToBytesUncompressed

func (pub *PublicKey) ToBytesUncompressed() (b []byte)

ToBytesUncompressed converts a Bitcoin public key to a 65-byte byte slice without point compression.

Jump to

Keyboard shortcuts

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