crypto

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PUSH1 = 0x51

	// encoded public key length 0x21 || encoded public key (33 bytes) || OP_CHECKSIG(0xac)
	PublicKeyScriptLength = 35

	// signature length(0x40) || 64 bytes signature
	SignatureScriptLength = 65

	// 1byte m || 3 encoded public keys with leading 0x40 (34 bytes * 3) ||
	// 1byte n + 1byte OP_CHECKMULTISIG
	MinMultiSignCodeLength = 71
)
View Source
const (
	SignerLength      = 32
	SignatureLength   = 64
	NegativeBigLength = 33
)
View Source
const (
	INFINITYLEN      = 1
	FLAGLEN          = 1
	XORYVALUELEN     = 32
	COMPRESSEDLEN    = 33
	NOCOMPRESSEDLEN  = 65
	COMPEVENFLAG     = 0x02
	COMPODDFLAG      = 0x03
	NOCOMPRESSEDFLAG = 0x04
	P256PARAMA       = -3
)

Variables

View Source
var (
	DefaultCurve  = elliptic.P256()
	DefaultParams = DefaultCurve.Params()
)

Functions

func AesDecrypt added in v0.2.2

func AesDecrypt(cipherText []byte, key []byte, iv []byte) ([]byte, error)

func AesEncrypt added in v0.2.2

func AesEncrypt(plaintext []byte, key []byte, iv []byte) ([]byte, error)

func AppendSignature added in v0.2.2

func AppendSignature(signerIndex int, signature, data, code, param []byte) ([]byte, error)

func ComputeParent added in v0.2.2

func ComputeParent(left common.Uint256, right common.Uint256) common.Uint256

func ComputeRoot

func ComputeRoot(hashes []common.Uint256) (common.Uint256, error)

input a []uint256, create a MerkleTree & calc the root hash

func Decrypt added in v0.3.2

func Decrypt(privateKey, cipher []byte) (m []byte, err error)

Decrypt decrypts an ECIES ciphertext.

func Encrypt added in v0.3.2

func Encrypt(publicKey *PublicKey, message []byte) (ct []byte, err error)

Encrypt encrypts a message using ECIES as specified in SEC 1, 5.1.

func Equal added in v0.2.2

func Equal(e1 *PublicKey, e2 *PublicKey) bool

func GetM added in v0.2.2

func GetM(code []byte) (uint, error)

func GetScriptType added in v0.2.2

func GetScriptType(script []byte) (byte, error)

func GetSignStatus added in v0.2.2

func GetSignStatus(code, param []byte) (haveSign, needSign int, err error)

func ParseCrossChainScript added in v0.2.2

func ParseCrossChainScript(code []byte) ([][]byte, error)

func ParseMultisigScript added in v0.2.2

func ParseMultisigScript(code []byte) ([][]byte, error)

func Sign added in v0.2.2

func Sign(priKey []byte, data []byte) ([]byte, error)

func SortPublicKeys added in v0.2.2

func SortPublicKeys(publicKeys []*PublicKey)

func ToAesKey added in v0.2.2

func ToAesKey(pwd []byte) []byte

func Verify

func Verify(publicKey PublicKey, data []byte, signature []byte) error

Types

type MerkleTree

type MerkleTree struct {
	Depth uint
	Root  *MerkleTreeNode
}

func NewMerkleTree

func NewMerkleTree(hashes []common.Uint256) (*MerkleTree, error)

use []Uint256 to create a new MerkleTree

type MerkleTreeNode

type MerkleTreeNode struct {
	Hash  common.Uint256
	Left  *MerkleTreeNode
	Right *MerkleTreeNode
}

func (*MerkleTreeNode) IsLeaf

func (t *MerkleTreeNode) IsLeaf() bool

type PublicKey added in v0.2.2

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

func DecodePoint

func DecodePoint(encodeData []byte) (*PublicKey, error)

func GenerateKeyPair added in v0.2.2

func GenerateKeyPair() ([]byte, *PublicKey, error)

func GenerateSubKeyPair added in v0.2.2

func GenerateSubKeyPair(index int, chainCode, parentPrivateKey []byte) ([]byte, *PublicKey, error)

func NewPubKey added in v0.2.2

func NewPubKey(priKey []byte) *PublicKey

func (*PublicKey) Deserialize added in v0.2.2

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

func (*PublicKey) EncodePoint added in v0.2.2

func (e *PublicKey) EncodePoint(isCompressed bool) ([]byte, error)

func (*PublicKey) Serialize added in v0.2.2

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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