gm

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: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GmCryptoClient

type GmCryptoClient struct {
	base.CryptoClient
}

func (*GmCryptoClient) ChangePrivCurveToS256k1

func (gcc *GmCryptoClient) ChangePrivCurveToS256k1(key *ecdsa.PrivateKey) *ecdsa.PrivateKey

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

func (*GmCryptoClient) CheckAddressFormat

func (gcc *GmCryptoClient) CheckAddressFormat(address string) (bool, uint8)

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

func (*GmCryptoClient) ConvertPrvKeyToPubKey

func (gcc *GmCryptoClient) ConvertPrvKeyToPubKey(privateKey string) (string, error)

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

func (*GmCryptoClient) CreateNewAccountAndSaveSecretKey

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

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

func (*GmCryptoClient) CreateNewAccountWithMnemonic

func (gcc *GmCryptoClient) CreateNewAccountWithMnemonic(language int, strength uint8) (*account.ECDSAAccount, error)

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

func (*GmCryptoClient) DecryptByAESKey

func (gcc *GmCryptoClient) DecryptByAESKey(cipherInfo string, cypherKey string) (string, error)

使用AES对称加密算法解密

func (*GmCryptoClient) DecryptByEcdsaKey

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

使用椭圆曲线非对称解密

func (*GmCryptoClient) DecryptByHdKey

func (gcc *GmCryptoClient) DecryptByHdKey(publicKey, privateAncestorKey, cypherText string) (string, error)

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

func (*GmCryptoClient) DecryptHardenByAESKey

func (gcc *GmCryptoClient) DecryptHardenByAESKey(cipherInfo string, cypherKey string) (string, error)

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

func (*GmCryptoClient) EncryptAccount

func (gcc *GmCryptoClient) EncryptAccount(info *account.ECDSAAccount, password string) (*account.ECDSAAccountToCloud, error)

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

func (*GmCryptoClient) EncryptByAESKey

func (gcc *GmCryptoClient) EncryptByAESKey(info string, cypherKey string) (string, error)

使用AES对称加密算法加密

func (*GmCryptoClient) EncryptByEcdsaKey

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

使用椭圆曲线非对称加密

func (*GmCryptoClient) EncryptByHdKey

func (gcc *GmCryptoClient) EncryptByHdKey(publicKey, msg string) (string, error)

使用子公钥加密

func (*GmCryptoClient) EncryptHardenByAESKey

func (gcc *GmCryptoClient) EncryptHardenByAESKey(info string, cypherKey string) (string, error)

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

func (*GmCryptoClient) ExportNewAccount

func (gcc *GmCryptoClient) ExportNewAccount(path string) error

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

func (*GmCryptoClient) ExportNewAccountWithMnemonic

func (gcc *GmCryptoClient) ExportNewAccountWithMnemonic(path string, language int, strength uint8) error

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

func (*GmCryptoClient) GenerateChildKey

func (gcc *GmCryptoClient) GenerateChildKey(parentKey string, index uint32) (string, error)

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

func (*GmCryptoClient) GenerateEntropy

func (gcc *GmCryptoClient) GenerateEntropy(bitSize int) ([]byte, error)

产生随机熵

func (*GmCryptoClient) GenerateKeyBySeed

func (gcc *GmCryptoClient) GenerateKeyBySeed(seed []byte) (*ecdsa.PrivateKey, error)

func (*GmCryptoClient) GenerateMasterKeyByMnemonic

func (gcc *GmCryptoClient) GenerateMasterKeyByMnemonic(mnemonic string, language int) (string, error)

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

func (*GmCryptoClient) GenerateMnemonic

func (gcc *GmCryptoClient) GenerateMnemonic(entropy []byte, language int) (string, error)

将随机熵转为助记词

func (*GmCryptoClient) GenerateMultiSignSignature

func (gcc *GmCryptoClient) GenerateMultiSignSignature(s []byte, r []byte) ([]byte, error)

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

func (*GmCryptoClient) GenerateSeedWithErrorChecking

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

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

func (*GmCryptoClient) GetAddressFromPublicKey

func (gcc *GmCryptoClient) GetAddressFromPublicKey(key *ecdsa.PublicKey) (string, error)

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

func (*GmCryptoClient) GetAddressFromPublicKeys

func (gcc *GmCryptoClient) GetAddressFromPublicKeys(keys []*ecdsa.PublicKey) (string, error)

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

func (*GmCryptoClient) GetBinaryEcdsaPrivateKeyFromFile

func (gcc *GmCryptoClient) GetBinaryEcdsaPrivateKeyFromFile(path string, password string) ([]byte, error)

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

func (*GmCryptoClient) GetEcdsaPrivateKeyBytesFromEncryptedStringByPassword

func (gcc *GmCryptoClient) GetEcdsaPrivateKeyBytesFromEncryptedStringByPassword(encryptedPrivateKey string, password string) ([]byte, error)

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

func (*GmCryptoClient) GetEcdsaPrivateKeyFromEncryptedStringByPassword

func (gcc *GmCryptoClient) GetEcdsaPrivateKeyFromEncryptedStringByPassword(encryptedPrivateKey string, password string) (*ecdsa.PrivateKey, error)

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

func (*GmCryptoClient) GetEcdsaPrivateKeyFromFile

func (gcc *GmCryptoClient) GetEcdsaPrivateKeyFromFile(filename string) (*ecdsa.PrivateKey, error)

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

func (*GmCryptoClient) GetEcdsaPrivateKeyFromFileByPassword

func (gcc *GmCryptoClient) GetEcdsaPrivateKeyFromFileByPassword(path string, password string) (*ecdsa.PrivateKey, error)

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

func (*GmCryptoClient) GetEcdsaPrivateKeyFromJsonStr

func (gcc *GmCryptoClient) GetEcdsaPrivateKeyFromJsonStr(keyStr string) (*ecdsa.PrivateKey, error)

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

func (*GmCryptoClient) GetEcdsaPrivateKeyJsonFormatStr

func (gcc *GmCryptoClient) GetEcdsaPrivateKeyJsonFormatStr(k *ecdsa.PrivateKey) (string, error)

获取ECC私钥的json格式的表达

func (*GmCryptoClient) GetEcdsaPublicKeyFromFile

func (gcc *GmCryptoClient) GetEcdsaPublicKeyFromFile(filename string) (*ecdsa.PublicKey, error)

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

func (*GmCryptoClient) GetEcdsaPublicKeyFromJsonStr

func (gcc *GmCryptoClient) GetEcdsaPublicKeyFromJsonStr(keyStr string) (*ecdsa.PublicKey, error)

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

func (*GmCryptoClient) GetEcdsaPublicKeyJsonFormatStr

func (gcc *GmCryptoClient) GetEcdsaPublicKeyJsonFormatStr(k *ecdsa.PrivateKey) (string, error)

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

func (*GmCryptoClient) GetEcdsaPublicKeyJsonFormatStrFromPublicKey

func (gcc *GmCryptoClient) GetEcdsaPublicKeyJsonFormatStrFromPublicKey(k *ecdsa.PublicKey) (string, error)

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

func (*GmCryptoClient) GetRUsingAllRi

func (gcc *GmCryptoClient) GetRUsingAllRi(key *ecdsa.PublicKey, arrayOfRi [][]byte) []byte

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

func (*GmCryptoClient) GetRandom32Bytes

func (gcc *GmCryptoClient) GetRandom32Bytes() ([]byte, error)

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

func (*GmCryptoClient) GetRiUsingRandomBytes

func (gcc *GmCryptoClient) GetRiUsingRandomBytes(key *ecdsa.PublicKey, k []byte) []byte

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

func (*GmCryptoClient) GetSUsingAllSi

func (gcc *GmCryptoClient) GetSUsingAllSi(arrayOfSi [][]byte) []byte

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

func (*GmCryptoClient) GetSharedPublicKeyForPublicKeys

func (gcc *GmCryptoClient) GetSharedPublicKeyForPublicKeys(keys []*ecdsa.PublicKey) ([]byte, error)

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

func (*GmCryptoClient) GetSiUsingKCRM

func (gcc *GmCryptoClient) 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 (*GmCryptoClient) HashUsingHmac512

func (gcc *GmCryptoClient) HashUsingHmac512(data, key []byte) []byte

使用Hmac512做哈希运算

func (*GmCryptoClient) HashUsingRipemd160

func (gcc *GmCryptoClient) HashUsingRipemd160(data []byte) []byte

使用Ripemd160做哈希运算

func (*GmCryptoClient) HashUsingSM3

func (gcc *GmCryptoClient) HashUsingSM3(data []byte) []byte

使用SHA256做单次哈希运算

func (*GmCryptoClient) MultiSign

func (gcc *GmCryptoClient) MultiSign(keys []*ecdsa.PrivateKey, message []byte) ([]byte, error)

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

func (*GmCryptoClient) RetrieveAccountByMnemonic

func (gcc *GmCryptoClient) RetrieveAccountByMnemonic(mnemonic string, language int) (*account.ECDSAAccount, error)

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

func (*GmCryptoClient) RetrieveAccountByMnemonicAndSavePrivKey

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

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

func (*GmCryptoClient) RetrievePrivateKeyByShares

func (gcc *GmCryptoClient) RetrievePrivateKeyByShares(jsonPrivateKeyShares []string) (string, error)

通过私钥片段恢复私钥

func (*GmCryptoClient) SaveEncryptedAccountToFile

func (gcc *GmCryptoClient) SaveEncryptedAccountToFile(account *account.ECDSAAccountToCloud, path string) error

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

func (*GmCryptoClient) SecretRetrieve

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

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

func (*GmCryptoClient) SecretSplit

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

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

func (*GmCryptoClient) SignECDSA

func (gcc *GmCryptoClient) SignECDSA(k *ecdsa.PrivateKey, msg []byte) ([]byte, error)

使用ECC私钥来签名

func (*GmCryptoClient) SignSchnorr

func (gcc *GmCryptoClient) SignSchnorr(privateKey *ecdsa.PrivateKey, message []byte) ([]byte, error)

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

func (*GmCryptoClient) SignSchnorrRing

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

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

func (*GmCryptoClient) SignV2ECDSA

func (gcc *GmCryptoClient) SignV2ECDSA(k *ecdsa.PrivateKey, msg []byte) ([]byte, error)

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

func (*GmCryptoClient) SplitPrivateKey

func (gcc *GmCryptoClient) SplitPrivateKey(jsonPrivateKey string, totalShareNumber, minimumShareNumber int) ([]string, error)

切分账户私钥

func (*GmCryptoClient) VerifyAddressUsingPublicKey

func (gcc *GmCryptoClient) VerifyAddressUsingPublicKey(address string, pub *ecdsa.PublicKey) (bool, uint8)

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

func (*GmCryptoClient) VerifyAddressUsingPublicKeys

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

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

func (*GmCryptoClient) VerifyECDSA

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

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

func (*GmCryptoClient) VerifyMultiSig

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

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

func (*GmCryptoClient) VerifySchnorr

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

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

func (*GmCryptoClient) VerifySchnorrRing

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

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

func (*GmCryptoClient) VerifyV2ECDSA

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

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

func (*GmCryptoClient) VerifyXuperSignature

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

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

Jump to

Keyboard shortcuts

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