xchain

package
v0.0.0-...-05508b9 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type XchainCryptoClient

type XchainCryptoClient struct {
	base.CryptoClient
}

func (*XchainCryptoClient) ChangePrivCurveToS256k1

func (xcc *XchainCryptoClient) ChangePrivCurveToS256k1(key *ecdsa.PrivateKey) *ecdsa.PrivateKey

将私钥的曲线转化为secp256k1,并重新计算包含的公钥

func (*XchainCryptoClient) CheckAddressFormat

func (xcc *XchainCryptoClient) CheckAddressFormat(address string) (bool, uint8)

验证钱包地址是否是合法的格式。如果成功,返回true和对应的版本号;如果失败,返回false和默认的版本号0

func (*XchainCryptoClient) ConvertPrvKeyToPubKey

func (xcc *XchainCryptoClient) ConvertPrvKeyToPubKey(privateKey string) (string, error)

将分层确定性私钥转化为公钥

func (*XchainCryptoClient) CreateNewAccountAndSaveSecretKey

func (xcc *XchainCryptoClient) CreateNewAccountAndSaveSecretKey(path string, language int, strength uint8, password string) (*account.ECDSAInfo, error)

创建新的账户,并用支付密码加密私钥后存在本地, 返回的字段:(随机熵(供其他钱包软件推导出私钥)、助记词、私钥的json、公钥的json、钱包地址) as ECDSAAccount,以及可能的错误信息

func (*XchainCryptoClient) CreateNewAccountWithMnemonic

func (xcc *XchainCryptoClient) CreateNewAccountWithMnemonic(language int, strength uint8) (*account.ECDSAAccount, error)

创建含有助记词的新的账户,返回的字段:(助记词、私钥的json、公钥的json、钱包地址) as ECDSAAccount,以及可能的错误信息

func (*XchainCryptoClient) DecryptByAESKey

func (xcc *XchainCryptoClient) DecryptByAESKey(cipherInfo string, cypherKey string) (string, error)

使用AES对称加密算法解密

func (*XchainCryptoClient) DecryptByEcdsaKey

func (xcc *XchainCryptoClient) DecryptByEcdsaKey(privateKey *ecdsa.PrivateKey, cypherText []byte) (msg []byte, err error)

使用椭圆曲线非对称解密

func (*XchainCryptoClient) DecryptByHdKey

func (xcc *XchainCryptoClient) DecryptByHdKey(publicKey, privateAncestorKey, cypherText string) (string, error)

使用子公钥和祖先私钥(可以是推导出该子公钥的任何一级祖先私钥)解密

func (*XchainCryptoClient) DecryptHardenByAESKey

func (xcc *XchainCryptoClient) DecryptHardenByAESKey(cipherInfo string, cypherKey string) (string, error)

使用AES对称加密算法解密,密钥曾经被增强拓展,提升破解难度

func (*XchainCryptoClient) EncryptAccount

func (xcc *XchainCryptoClient) EncryptAccount(info *account.ECDSAAccount, password string) (*account.ECDSAAccountToCloud, error)

使用支付密码加密账户信息并返回加密后的数据(后续用来回传至云端)

func (*XchainCryptoClient) EncryptByAESKey

func (xcc *XchainCryptoClient) EncryptByAESKey(info string, cypherKey string) (string, error)

使用AES对称加密算法加密

func (*XchainCryptoClient) EncryptByEcdsaKey

func (xcc *XchainCryptoClient) EncryptByEcdsaKey(publicKey *ecdsa.PublicKey, msg []byte) (cypherText []byte, err error)

使用椭圆曲线非对称加密

func (*XchainCryptoClient) EncryptByHdKey

func (xcc *XchainCryptoClient) EncryptByHdKey(publicKey, msg string) (string, error)

使用子公钥加密

func (*XchainCryptoClient) EncryptHardenByAESKey

func (xcc *XchainCryptoClient) EncryptHardenByAESKey(info string, cypherKey string) (string, error)

使用AES对称加密算法加密,密钥会被增强拓展,提升破解难度

func (*XchainCryptoClient) ExportNewAccount

func (xcc *XchainCryptoClient) ExportNewAccount(path string) error

ExportNewAccount 创建新账户(不使用助记词,不推荐使用)

func (*XchainCryptoClient) ExportNewAccountWithMnemonic

func (xcc *XchainCryptoClient) ExportNewAccountWithMnemonic(path string, language int, strength uint8) error

创建新的账户,并导出相关文件(含助记词)到本地。生成如下几个文件:1.助记词,2.私钥,3.公钥,4.钱包地址

func (*XchainCryptoClient) GenerateBlsKeyPair

func (xcc *XchainCryptoClient) GenerateBlsKeyPair() (*bls_sign.PrivateKey, *bls_sign.PublicKey, error)

BLS签名算法 生成公钥和私钥对

func (*XchainCryptoClient) GenerateChildKey

func (xcc *XchainCryptoClient) GenerateChildKey(parentKey string, index uint32) (string, error)

通过分层确定性私钥/公钥(如根私钥)推导出子私钥/公钥

func (*XchainCryptoClient) GenerateEntropy

func (xcc *XchainCryptoClient) GenerateEntropy(bitSize int) ([]byte, error)

产生随机熵

func (*XchainCryptoClient) GenerateKeyBySeed

func (xcc *XchainCryptoClient) GenerateKeyBySeed(seed []byte) (*ecdsa.PrivateKey, error)

通过随机数种子来生成椭圆曲线加密所需要的公钥和私钥

func (*XchainCryptoClient) GenerateMasterKeyByMnemonic

func (xcc *XchainCryptoClient) GenerateMasterKeyByMnemonic(mnemonic string, language int) (string, error)

通过助记词恢复出分层确定性根密钥

func (*XchainCryptoClient) GenerateMnemonic

func (xcc *XchainCryptoClient) GenerateMnemonic(entropy []byte, language int) (string, error)

将随机熵转为助记词

func (*XchainCryptoClient) GenerateMultiSignSignature

func (xcc *XchainCryptoClient) GenerateMultiSignSignature(s []byte, r []byte) ([]byte, error)

负责计算多重签名的节点,最终生成多重签名的统一签名格式XuperSignature

func (*XchainCryptoClient) GenerateSeedWithErrorChecking

func (xcc *XchainCryptoClient) GenerateSeedWithErrorChecking(mnemonic string, password string, keyLen int, language int) ([]byte, error)

将助记词转为指定长度的随机数种子,在此过程中,校验助记词是否合法

func (*XchainCryptoClient) GenerateTssSignSignature

func (xcc *XchainCryptoClient) GenerateTssSignSignature(s []byte, r []byte) ([]byte, error)

负责计算门限签名的节点,最终生成门限签名的统一签名格式XuperSignature

func (*XchainCryptoClient) GetAddressFromPublicKey

func (xcc *XchainCryptoClient) GetAddressFromPublicKey(key *ecdsa.PublicKey) (string, error)

使用单个公钥来生成钱包地址

func (*XchainCryptoClient) GetAddressFromPublicKeys

func (xcc *XchainCryptoClient) GetAddressFromPublicKeys(keys []*ecdsa.PublicKey) (string, error)

使用多个公钥来生成钱包地址(环签名,多重签名地址)

func (*XchainCryptoClient) GetBinaryEcdsaPrivateKeyFromFile

func (xcc *XchainCryptoClient) GetBinaryEcdsaPrivateKeyFromFile(path string, password string) ([]byte, error)

从导出的私钥文件读取私钥的byte格式

func (*XchainCryptoClient) GetEcdsaPrivateKeyBytesFromEncryptedStringByPassword

func (xcc *XchainCryptoClient) GetEcdsaPrivateKeyBytesFromEncryptedStringByPassword(encryptedPrivateKey string, password string) ([]byte, error)

使用支付密码从二进制加密字符串获取真实私钥的字节数组

func (*XchainCryptoClient) GetEcdsaPrivateKeyFromEncryptedStringByPassword

func (xcc *XchainCryptoClient) GetEcdsaPrivateKeyFromEncryptedStringByPassword(encryptedPrivateKey string, password string) (*ecdsa.PrivateKey, error)

使用支付密码从二进制加密字符串获取真实ECC私钥

func (*XchainCryptoClient) GetEcdsaPrivateKeyFromFile

func (xcc *XchainCryptoClient) GetEcdsaPrivateKeyFromFile(filename string) (*ecdsa.PrivateKey, error)

从导出的私钥文件读取私钥

func (*XchainCryptoClient) GetEcdsaPrivateKeyFromFileByPassword

func (xcc *XchainCryptoClient) GetEcdsaPrivateKeyFromFileByPassword(path string, password string) (*ecdsa.PrivateKey, error)

使用支付密码从导出的私钥文件读取私钥

func (*XchainCryptoClient) GetEcdsaPrivateKeyFromJsonStr

func (xcc *XchainCryptoClient) GetEcdsaPrivateKeyFromJsonStr(keyStr string) (*ecdsa.PrivateKey, error)

从json格式私钥内容字符串产生ECC私钥

func (*XchainCryptoClient) GetEcdsaPrivateKeyJsonFormatStr

func (xcc *XchainCryptoClient) GetEcdsaPrivateKeyJsonFormatStr(k *ecdsa.PrivateKey) (string, error)

获取ECC私钥的json格式的表达的字符串

func (*XchainCryptoClient) GetEcdsaPublicKeyFromFile

func (xcc *XchainCryptoClient) GetEcdsaPublicKeyFromFile(filename string) (*ecdsa.PublicKey, error)

从导出的公钥文件读取公钥

func (*XchainCryptoClient) GetEcdsaPublicKeyFromJsonStr

func (xcc *XchainCryptoClient) GetEcdsaPublicKeyFromJsonStr(keyStr string) (*ecdsa.PublicKey, error)

从json格式公钥内容字符串产生ECC公钥

func (*XchainCryptoClient) GetEcdsaPublicKeyJsonFormatStr

func (xcc *XchainCryptoClient) GetEcdsaPublicKeyJsonFormatStr(k *ecdsa.PrivateKey) (string, error)

通过私钥获取ECC公钥的json格式的表达的字符串

func (*XchainCryptoClient) GetEcdsaPublicKeyJsonFormatStrFromPublicKey

func (xcc *XchainCryptoClient) GetEcdsaPublicKeyJsonFormatStrFromPublicKey(k *ecdsa.PublicKey) (string, error)

通过公钥获取ECC公钥的json格式的表达的字符串

func (*XchainCryptoClient) GetLocalPrivateKeyByShares

func (xcc *XchainCryptoClient) GetLocalPrivateKeyByShares(shares []*big.Int) *ecdsa.PrivateKey

每个潜在参与节点根据所收集的所有的与自己相关的碎片(自己的Index是X值,收集所有该X值对应的Y值), 来计算出自己的本地私钥X(i)(该X值对应的Y值之和),这是一个关键秘密信息

func (*XchainCryptoClient) GetLocalShares

func (xcc *XchainCryptoClient) GetLocalShares(totalShareNumber, minimumShareNumber int) (shares map[int]*big.Int, points []*ecc.Point, err error)

- method 1 start - 一个步骤整体 所有潜在参与节点根据门限目标生成产生本地秘密和验证点的私钥碎片 minimumShareNumber可以理解为threshold,至少需要minimumShareNumber个潜在参与节点进行实际参与才能完成门限签名

func (*XchainCryptoClient) GetPolynomialForSecretShareGenerate

func (xcc *XchainCryptoClient) GetPolynomialForSecretShareGenerate(totalShareNumber, minimumShareNumber int) ([]*big.Int, error)

- method 2 start - 分步骤 为产生本地秘密的私钥碎片做准备,预先生成好一个目标多项式 minimumShareNumber可以理解为threshold,至少需要minimumShareNumber个潜在参与节点进行实际参与才能完成门限签名

func (*XchainCryptoClient) GetRUsingAllRi

func (xcc *XchainCryptoClient) GetRUsingAllRi(key *ecdsa.PublicKey, arrayOfRi [][]byte) []byte

负责计算多重签名的节点来收集所有节点的Ri,并计算R = k1*G + k2*G + ... + kn*G

func (*XchainCryptoClient) GetRandom32Bytes

func (xcc *XchainCryptoClient) GetRandom32Bytes() ([]byte, error)

每个多重签名算法流程的参与节点生成32位长度的随机byte,返回值可以认为是k

func (*XchainCryptoClient) GetRiUsingRandomBytes

func (xcc *XchainCryptoClient) GetRiUsingRandomBytes(key *ecdsa.PublicKey, k []byte) []byte

每个多重签名算法流程的参与节点生成Ri = Ki*G

func (*XchainCryptoClient) GetSUsingAllSi

func (xcc *XchainCryptoClient) GetSUsingAllSi(arrayOfSi [][]byte) []byte

负责计算多重签名的节点来收集所有节点的Si,并计算出S = sum(si)

func (*XchainCryptoClient) GetSharedPublicKey

func (xcc *XchainCryptoClient) GetSharedPublicKey(verifyPoints []*ecc.Point) (*ecdsa.PublicKey, error)

每个潜在参与节点来收集所有节点的秘密验证点,并计算公共公钥:C = VP(1) + VP(2) + ... + VP(i)

func (*XchainCryptoClient) GetSharedPublicKeyForPublicKeys

func (xcc *XchainCryptoClient) GetSharedPublicKeyForPublicKeys(keys []*ecdsa.PublicKey) ([]byte, error)

负责计算多重签名的节点来收集所有节点的公钥Pi,并计算公共公钥:C = P1 + P2 + ... + Pn

func (*XchainCryptoClient) GetSiUsingKCRM

func (xcc *XchainCryptoClient) GetSiUsingKCRM(key *ecdsa.PrivateKey, k []byte, c []byte, r []byte, message []byte) []byte

负责计算多重签名的节点将计算出的R和C分别传递给各个参与节点后,由各个参与节点再次计算自己的Si 计算 Si = Ki + HASH(C,R,m) * Xi X代表大数D,也就是私钥的关键参数

func (*XchainCryptoClient) GetSiUsingKCRMWithCoef

func (xcc *XchainCryptoClient) GetSiUsingKCRMWithCoef(k []byte, c []byte, r []byte, message []byte, coef *big.Int) []byte

每个实际参与节点再次计算自己的S(i) S(i) = K(i) + HASH(C,R,m) * X(i) * Coef(i) X代表大数D,也就是私钥的关键参数

func (*XchainCryptoClient) GetSiUsingKCRMWithCoefNoKi

func (xcc *XchainCryptoClient) GetSiUsingKCRMWithCoefNoKi(c []byte, r []byte, message []byte, coef *big.Int) []byte

注意:专用于多层门限算法,每个实际参与节点再次计算自己的S(i) 版本2 S(i) = HASH(C,R,m) * X(i) * Coef(i) X代表大数D,也就是私钥的关键参数

func (*XchainCryptoClient) GetSpecifiedSecretShareByPolynomial

func (xcc *XchainCryptoClient) GetSpecifiedSecretShareByPolynomial(poly []*big.Int, index *big.Int) *big.Int

为产生本地秘密的私钥碎片做准备,通过目标多项式和节点index生成对应的碎片

func (*XchainCryptoClient) GetVerifyPointByPolynomial

func (xcc *XchainCryptoClient) GetVerifyPointByPolynomial(poly []*big.Int) (*ecc.Point, error)

为产生本地秘密的私钥碎片做准备,通过目标多项式生成验证点

func (*XchainCryptoClient) GetXiWithcoef

func (xcc *XchainCryptoClient) GetXiWithcoef(indexSet []*big.Int, localIndexPos int, key *ecdsa.PrivateKey) *big.Int

每个实际参与节点再次计算自己的独有系数与自己私钥秘密的乘积,也就是X(i) * Coef(i),为下一步的S(i)计算做准备 indexSet是指所有实际参与节点的index所组成的集合 localIndexPos是本节点在indexSet中的位置 key是在DKG过程中,自己计算出的私钥

func (*XchainCryptoClient) HashUsingDefaultMiMC

func (xcc *XchainCryptoClient) HashUsingDefaultMiMC(data []byte) []byte

使用MiMC做哈希运算

func (*XchainCryptoClient) HashUsingDoubleSha256

func (xcc *XchainCryptoClient) HashUsingDoubleSha256(data []byte) []byte

使用SHA256做双次哈希运算,担心SHA256存在后门时可以这么做

func (*XchainCryptoClient) HashUsingHmac512

func (xcc *XchainCryptoClient) HashUsingHmac512(data, key []byte) []byte

使用Hmac512做哈希运算

func (*XchainCryptoClient) HashUsingRipemd160

func (xcc *XchainCryptoClient) HashUsingRipemd160(data []byte) []byte

使用Ripemd160做哈希运算

func (*XchainCryptoClient) HashUsingSha256

func (xcc *XchainCryptoClient) HashUsingSha256(data []byte) []byte

使用SHA256做单次哈希运算

func (*XchainCryptoClient) MultiSign

func (xcc *XchainCryptoClient) MultiSign(keys []*ecdsa.PrivateKey, message []byte) ([]byte, error)

-- 多重签名的另一种用法,适用于完全中心化的流程 使用ECC私钥数组来进行多重签名,生成统一签名格式XuperSignature

func (*XchainCryptoClient) RetrieveAccountByMnemonic

func (xcc *XchainCryptoClient) RetrieveAccountByMnemonic(mnemonic string, language int) (*account.ECDSAAccount, error)

从助记词恢复钱包账户 TODO: 后续可以从助记词中识别出语言类型

func (*XchainCryptoClient) RetrieveAccountByMnemonicAndSavePrivKey

func (xcc *XchainCryptoClient) RetrieveAccountByMnemonicAndSavePrivKey(path string, language int, mnemonic string, password string) (*account.ECDSAInfo, error)

从助记词恢复钱包账户,并用支付密码加密私钥后存在本地, 返回的字段:(随机熵(供其他钱包软件推导出私钥)、助记词、私钥的json、公钥的json、钱包地址) as ECDSAAccount,以及可能的错误信息

func (*XchainCryptoClient) RetrievePrivateKeyByShares

func (xcc *XchainCryptoClient) RetrievePrivateKeyByShares(jsonPrivateKeyShares []string) (string, error)

通过私钥片段恢复私钥

func (*XchainCryptoClient) SaveEncryptedAccountToFile

func (xcc *XchainCryptoClient) SaveEncryptedAccountToFile(account *account.ECDSAAccountToCloud, path string) error

将经过支付密码加密的账户保存到文件中

func (*XchainCryptoClient) SecretRetrieve

func (xcc *XchainCryptoClient) SecretRetrieve(shares map[int]*big.Int) ([]byte, error)

通过收集到的碎片来还原出秘密

func (*XchainCryptoClient) SecretSplit

func (xcc *XchainCryptoClient) SecretSplit(totalShareNumber, minimumShareNumber int, secret []byte) (shares map[int]*big.Int, err error)

将秘密分割为碎片,totalShareNumber为碎片数量,minimumShareNumber为需要至少多少碎片才能还原出信息

func (*XchainCryptoClient) SignBls

func (xcc *XchainCryptoClient) SignBls(privateKey *bls_sign.PrivateKey, message []byte) (blsSignature []byte, err error)

BLS签名算法 生成统一签名XuperSignature

func (*XchainCryptoClient) SignECDSA

func (xcc *XchainCryptoClient) SignECDSA(k *ecdsa.PrivateKey, msg []byte) ([]byte, error)

使用ECC私钥来签名

func (*XchainCryptoClient) SignSchnorr

func (xcc *XchainCryptoClient) SignSchnorr(privateKey *ecdsa.PrivateKey, message []byte) ([]byte, error)

schnorr签名算法 生成统一签名XuperSignature

func (*XchainCryptoClient) SignSchnorrRing

func (xcc *XchainCryptoClient) SignSchnorrRing(keys []*ecdsa.PublicKey, privateKey *ecdsa.PrivateKey, message []byte) (ringSignature []byte, err error)

schnorr环签名算法 生成统一签名XuperSignature

func (*XchainCryptoClient) SignV2ECDSA

func (xcc *XchainCryptoClient) SignV2ECDSA(k *ecdsa.PrivateKey, msg []byte) ([]byte, error)

使用ECC私钥来签名,生成统一签名的新签名函数

func (*XchainCryptoClient) SplitPrivateKey

func (xcc *XchainCryptoClient) SplitPrivateKey(jsonPrivateKey string, totalShareNumber, minimumShareNumber int) ([]string, error)

切分账户私钥

func (*XchainCryptoClient) VerifyAddressUsingPublicKey

func (xcc *XchainCryptoClient) VerifyAddressUsingPublicKey(address string, pub *ecdsa.PublicKey) (bool, uint8)

验证钱包地址是否和指定的公钥match。如果成功,返回true和对应的版本号;如果失败,返回false和默认的版本号0

func (*XchainCryptoClient) VerifyAddressUsingPublicKeys

func (xcc *XchainCryptoClient) VerifyAddressUsingPublicKeys(address string, pub []*ecdsa.PublicKey) (bool, uint8)

验证钱包地址(环签名,多重签名地址)是否和指定的公钥数组match。如果成功,返回true和对应的版本号;如果失败,返回false和默认的版本号0

func (*XchainCryptoClient) VerifyBlsSig

func (xcc *XchainCryptoClient) VerifyBlsSig(key *bls_sign.PublicKey, signature, message []byte) (bool, error)

使用BLS公钥来进行门限签名的验证 -- 外部函数,因为椭圆曲线的原因,暂时无法成为内部函数,供统一验签函数调用

func (*XchainCryptoClient) VerifyECDSA

func (xcc *XchainCryptoClient) VerifyECDSA(k *ecdsa.PublicKey, signature, msg []byte) (bool, error)

使用ECC公钥来验证签名 -- 对应SignECDSA

func (*XchainCryptoClient) VerifyMultiSig

func (xcc *XchainCryptoClient) VerifyMultiSig(keys []*ecdsa.PublicKey, signature, message []byte) (bool, error)

使用ECC公钥数组来进行多重签名的验证 -- 内部函数,供统一验签函数调用

func (*XchainCryptoClient) VerifySchnorr

func (xcc *XchainCryptoClient) VerifySchnorr(publicKey *ecdsa.PublicKey, sig, message []byte) (bool, error)

schnorr签名算法 验证签名 -- 内部函数,供统一验签函数调用

func (*XchainCryptoClient) VerifySchnorrRing

func (xcc *XchainCryptoClient) VerifySchnorrRing(keys []*ecdsa.PublicKey, sig, message []byte) (bool, error)

schnorr环签名算法 验证签名 -- 内部函数,供统一验签函数调用

func (*XchainCryptoClient) VerifyTssSig

func (xcc *XchainCryptoClient) VerifyTssSig(key *ecdsa.PublicKey, signature, message []byte) (bool, error)

使用ECC公钥来进行门限签名的验证 -- 内部函数,供统一验签函数调用

func (*XchainCryptoClient) VerifyV2ECDSA

func (xcc *XchainCryptoClient) VerifyV2ECDSA(k *ecdsa.PublicKey, signature, msg []byte) (bool, error)

使用ECC公钥来验证签名,验证统一签名的新签名函数 -- 内部函数,供统一验签函数调用

func (*XchainCryptoClient) VerifyXuperSignature

func (xcc *XchainCryptoClient) VerifyXuperSignature(publicKeys []*ecdsa.PublicKey, sig []byte, message []byte) (valid bool, err error)

--- 统一验签算法,可以对用各种签名算法生成的统一签名格式XuperSignature进行验证

func (*XchainCryptoClient) ZkpProveMiMC

func (*XchainCryptoClient) ZkpSetupMiMC

func (xcc *XchainCryptoClient) ZkpSetupMiMC() (*zkp.ZkpInfo, error)

初始化哈希算法MiMC的参数

func (*XchainCryptoClient) ZkpVerifyMiMC

func (xcc *XchainCryptoClient) ZkpVerifyMiMC(proof bls12_381_groth16.Proof, vk bls12_381_groth16.VerifyingKey, hashResult []byte) (bool, error)

Jump to

Keyboard shortcuts

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