至信SDK
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.6 KiB

package zxsdk
import (
"git.yuanzoo.cn/zhangzhengqiang/popi-zxl/third_party/official/gosdk_demo/zxsdk/constant"
"git.yuanzoo.cn/zhangzhengqiang/popi-zxl/third_party/official/gosdk_demo/zxsdk/tools"
"git.yuanzoo.cn/zhangzhengqiang/popi-zxl/third_party/official/gosdk_demo/zxsdk/wallet_sdk"
"github.com/google/uuid"
"net/http"
"strconv"
)
type ZxChainClient struct {
secretId string
secretKey string
privateKey string
publicKey string
addr string
httpClient *http.Client
}
func NewZxChainClient(secretId, secretKey, privateKey string) (*ZxChainClient, error) {
if secretId == "" {
return nil, constant.SECRET_ID_EMPTY_ERROR
}
if secretKey == "" {
return nil, constant.SECRET_KEY_EMPTY_ERROR
}
if privateKey == "" {
return nil, constant.PRIVATE_KEY_FORMAT_ERROR
}
publicKey, err := wallet_sdk.PriKey2PubKey(privateKey)
if err != nil {
return nil, constant.PRIVATE_KEY_FORMAT_ERROR
}
addr, _ := wallet_sdk.PubKey2Address(publicKey)
return &ZxChainClient{
secretId: secretId,
secretKey: secretKey,
publicKey: publicKey,
privateKey: privateKey,
addr: addr,
httpClient: tools.DefaultHttpClient,
}, nil
}
func (zx ZxChainClient) makeHeader() map[string]string {
apiSignData, _ := wallet_sdk.GenerateApiSign(zx.secretId, zx.secretKey)
header := map[string]string{
"Secret-Id": zx.secretId,
"Signature": apiSignData.Signature,
"Signature-Time": apiSignData.SignatureTime,
"Nonce": strconv.Itoa(apiSignData.Nonce),
constant.TraceKey: uuid.New().String(),
}
return header
}
func (zx ZxChainClient) SetHttpClient(client *http.Client) {
zx.httpClient = client
}