diff --git a/core/client/set.go b/core/client/set.go index 0ad28f865..3eb4d486e 100644 --- a/core/client/set.go +++ b/core/client/set.go @@ -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 { @@ -318,7 +318,6 @@ func InitSDK(walletJSON string, MinSubmit: minSubmit, ConfirmationChainLength: confirmationChainLength, SharderConsensous: sharderConsensous, - IsSplitWallet: isSplitWallet, }) if err != nil { return err diff --git a/core/conf/config.go b/core/conf/config.go index 4444892e3..d68b510f0 100644 --- a/core/conf/config.go +++ b/core/conf/config.go @@ -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 @@ -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 } diff --git a/core/conf/config_test.go b/core/conf/config_test.go index 77f8c51b1..356cf9cc2 100644 --- a/core/conf/config_test.go +++ b/core/conf/config_test.go @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/core/zcncrypto/signature_scheme.go b/core/zcncrypto/signature_scheme.go index 6a192ac26..c81bbe4d7 100644 --- a/core/zcncrypto/signature_scheme.go +++ b/core/zcncrypto/signature_scheme.go @@ -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"` diff --git a/mobilesdk/sdk/sdk.go b/mobilesdk/sdk/sdk.go index 3fab257b4..467ab0b49 100644 --- a/mobilesdk/sdk/sdk.go +++ b/mobilesdk/sdk/sdk.go @@ -12,6 +12,7 @@ import ( "strings" "context" + "github.com/0chain/gosdk/core/sys" "github.com/pkg/errors" @@ -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 } diff --git a/wasmsdk/sdk.go b/wasmsdk/sdk.go index 974958d62..c0b78a2b6 100644 --- a/wasmsdk/sdk.go +++ b/wasmsdk/sdk.go @@ -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 diff --git a/zcncore/get_data.go b/zcncore/get_data.go index d408ef916..6a17f7aff 100644 --- a/zcncore/get_data.go +++ b/zcncore/get_data.go @@ -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 { @@ -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