Skip to content
Merged
3 changes: 1 addition & 2 deletions core/client/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func GetClient() *zcncrypto.Wallet {
// - fee: Preferred value for the transaction fee, just the first value is taken
func InitSDK(walletJSON string,
blockWorker, chainID, signatureScheme string,
nonce int64, isSplitWallet, addWallet bool,
nonce int64, addWallet bool,
options ...int) error {

if addWallet {
Expand Down Expand Up @@ -318,7 +318,6 @@ func InitSDK(walletJSON string,
MinSubmit: minSubmit,
ConfirmationChainLength: confirmationChainLength,
SharderConsensous: sharderConsensous,
IsSplitWallet: isSplitWallet,
})
if err != nil {
return err
Expand Down
4 changes: 1 addition & 3 deletions core/conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ type Config struct {
SharderConsensous int `json:"sharder_consensous"`
ZauthServer string `json:"zauth_server"`
V *viper.Viper `json:"-"`

IsSplitWallet bool `json:"is_split_wallet"`
}

// LoadConfigFile load and parse SDK Config from file
Expand Down Expand Up @@ -178,7 +176,7 @@ func LoadConfig(v Reader) (Config, error) {

cfg.SignatureScheme = v.GetString("signature_scheme")
cfg.ChainID = v.GetString("chain_id")
cfg.ZauthServer = v.GetString("zauth.server")
cfg.ZauthServer = v.GetString("zauth_server")

return cfg, nil
}
Expand Down
8 changes: 4 additions & 4 deletions core/conf/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestLoadConfig(t *testing.T) {
var mockDefaultReader = func() Reader {
reader := &mocks.Reader{}
reader.On("GetString", "block_worker").Return("http://127.0.0.1:9091/dns")
reader.On("GetString", "zauth.server").Return("http://127.0.0.1:8090/")
reader.On("GetString", "zauth_server").Return("http://127.0.0.1:8090/")
reader.On("GetInt", "min_submit").Return(0)
reader.On("GetInt", "min_confirmation").Return(0)
reader.On("GetInt", "max_txn_query").Return(0)
Expand Down Expand Up @@ -42,7 +42,7 @@ func TestLoadConfig(t *testing.T) {

reader := &mocks.Reader{}
reader.On("GetString", "block_worker").Return("")
reader.On("GetString", "zauth.server").Return("")
reader.On("GetString", "zauth_server").Return("")
reader.On("GetInt", "min_submit").Return(0)
reader.On("GetInt", "min_confirmation").Return(0)
reader.On("GetInt", "max_txn_query").Return(0)
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestLoadConfig(t *testing.T) {

reader := &mocks.Reader{}
reader.On("GetString", "block_worker").Return("https://127.0.0.1:9091/dns")
reader.On("GetString", "zauth.server").Return("http://127.0.0.1:8090/")
reader.On("GetString", "zauth_server").Return("http://127.0.0.1:8090/")
reader.On("GetInt", "min_submit").Return(101)
reader.On("GetInt", "min_confirmation").Return(0)
reader.On("GetInt", "max_txn_query").Return(0)
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestLoadConfig(t *testing.T) {

reader := &mocks.Reader{}
reader.On("GetString", "block_worker").Return("https://127.0.0.1:9091/dns")
reader.On("GetString", "zauth.server").Return("http://127.0.0.1:8090/")
reader.On("GetString", "zauth_server").Return("http://127.0.0.1:8090/")
reader.On("GetInt", "min_submit").Return(0)
reader.On("GetInt", "min_confirmation").Return(101)
reader.On("GetInt", "max_txn_query").Return(0)
Expand Down
2 changes: 1 addition & 1 deletion core/zcncrypto/signature_scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type KeyPair struct {
type Wallet struct {
ClientID string `json:"client_id"`
ClientKey string `json:"client_key"`
PeerPublicKey string `json:"peer_public_key"` // Peer public key exists only in split wallet
PeerPublicKey string `json:"peer_public_key"` // Peer public key exists only in split wallet for web only.
Keys []KeyPair `json:"keys"`
Mnemonic string `json:"mnemonics"`
Version string `json:"version"`
Expand Down
3 changes: 2 additions & 1 deletion mobilesdk/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"

"context"

"github.com/0chain/gosdk/core/sys"
"github.com/pkg/errors"

Expand Down Expand Up @@ -128,7 +129,7 @@ func InitStorageSDK(clientJson string, configJson string) (*StorageSDK, error) {
configObj.BlockWorker,
configObj.ChainID,
configObj.SignatureScheme,
0, false, true); err != nil {
0, true); err != nil {
l.Logger.Error(err)
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions wasmsdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ var CreateObjectURL func(buf []byte, mimeType string) string
// - sharderconsensous is the number of sharders to reach consensus
func initSDKs(chainID, blockWorker, signatureScheme string,
minConfirmation, minSubmit, confirmationChainLength int,
zboxHost, zboxAppType string, sharderConsensous int, isSplit bool) error {
zboxHost, zboxAppType string, sharderConsensous int) error {

// Print the parameters beautified
fmt.Printf("{ chainID: %s, blockWorker: %s, signatureScheme: %s, minConfirmation: %d, minSubmit: %d, confirmationChainLength: %d, zboxHost: %s, zboxAppType: %s, sharderConsensous: %d, isSplit: %t }\n", chainID, blockWorker, signatureScheme, minConfirmation, minSubmit, confirmationChainLength, zboxHost, zboxAppType, sharderConsensous, isSplit)
fmt.Printf("{ chainID: %s, blockWorker: %s, signatureScheme: %s, minConfirmation: %d, minSubmit: %d, confirmationChainLength: %d, zboxHost: %s, zboxAppType: %s, sharderConsensous: %d }\n", chainID, blockWorker, signatureScheme, minConfirmation, minSubmit, confirmationChainLength, zboxHost, zboxAppType, sharderConsensous)

zboxApiClient.SetRequest(zboxHost, zboxAppType)

err := client.InitSDK("{}", blockWorker, chainID, signatureScheme, 0, isSplit, false, minConfirmation, minSubmit, confirmationChainLength, sharderConsensous)
err := client.InitSDK("{}", blockWorker, chainID, signatureScheme, 0, false, minConfirmation, minSubmit, confirmationChainLength, sharderConsensous)
if err != nil {
fmt.Println("wasm: InitStorageSDK ", err)
return err
Expand Down
55 changes: 53 additions & 2 deletions zcncore/get_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import (
"encoding/json"
"errors"
"fmt"
"net/url"
"strconv"

"github.com/0chain/gosdk/core/block"
"github.com/0chain/gosdk/core/client"
"github.com/0chain/gosdk/core/sys"
"github.com/0chain/gosdk/core/tokenrate"
"github.com/0chain/gosdk/core/util"
"github.com/0chain/gosdk/core/zcncrypto"
"net/url"
"strconv"
)

type GetClientResponse struct {
Expand Down Expand Up @@ -89,6 +91,55 @@ func SetWalletInfo(jsonWallet, sigScheme string, splitKeyWallet bool) error {
return client.SetSplitKeyWallet(splitKeyWallet)
}

// SetGeneralWalletInfo should be set before any transaction or client specific APIs. Automatically sets KMS mode if specified by wallet structure.
//
// # Inputs(non-KMS)
// - jsonWallet: json format of wallet
// {
// "client_id":"30764bcba73216b67c36b05a17b4dd076bfdc5bb0ed84856f27622188c377269",
// "client_key":"1f495df9605a4479a7dd6e5c7a78caf9f9d54e3a40f62a3dd68ed377115fe614d8acf0c238025f67a85163b9fbf31d10fbbb4a551d1cf00119897edf18b1841c",
// "keys":[
// {"public_key":"1f495df9605a4479a7dd6e5c7a78caf9f9d54e3a40f62a3dd68ed377115fe614d8acf0c238025f67a85163b9fbf31d10fbbb4a551d1cf00119897edf18b1841c","private_key":"41729ed8d82f782646d2d30b9719acfd236842b9b6e47fee12b7bdbd05b35122"}
// ],
// "mnemonics":"glare mistake gun joke bid spare across diagram wrap cube swear cactus cave repeat you brave few best wild lion pitch pole original wasp",
// "version":"1.0",
// "date_created":"1662534022",
// "nonce":0
// }
//
// # Inputs(KMS)
// - jsonWallet: json format of wallet
// {
// "client_id":"30764bcba73216b67c36b05a17b4dd076bfdc5bb0ed84856f27622188c377269",
// "client_key":"1f495df9605a4479a7dd6e5c7a78caf9f9d54e3a40f62a3dd68ed377115fe614d8acf0c238025f67a85163b9fbf31d10fbbb4a551d1cf00119897edf18b1841c",
// "keys":[
// {"public_key":"1f495df9605a4479a7dd6e5c7a78caf9f9d54e3a40f62a3dd68ed377115fe614d8acf0c238025f67a85163b9fbf31d10fbbb4a551d1cf00119897edf18b1841c","private_key":"41729ed8d82f782646d2d30b9719acfd236842b9b6e47fee12b7bdbd05b35122"}
// ],
// "mnemonics":"glare mistake gun joke bid spare across diagram wrap cube swear cactus cave repeat you brave few best wild lion pitch pole original wasp",
// "is_split": true,
// "version":"1.0",
// "date_created":"1662534022",
// "nonce":0,
// }
func SetGeneralWalletInfo(jsonWallet, sigScheme string) error {
wallet := zcncrypto.Wallet{}
err := json.Unmarshal([]byte(jsonWallet), &wallet)
if err != nil {
return errors.New("invalid jsonWallet: " + err.Error())
}

client.SetWallet(wallet)
client.SetSignatureScheme(sigScheme)

return client.SetSplitKeyWallet(wallet.IsSplit)
}

// RegisterZauthServer registers zauth server callbacks for signing operations. Should be used for split key mode.
func RegisterZauthServer(serverAddr string) {
sys.SetAuthorize(ZauthSignTxn(serverAddr))
sys.SetAuthCommon(ZauthAuthCommon(serverAddr))
}

// SetAuthUrl will be called by app to set zauth URL to SDK.
// # Inputs
// - url: the url of zAuth server
Expand Down
Loading