From ad1f57483e733512463892cf5181b6b43cbe6859 Mon Sep 17 00:00:00 2001 From: peterlimg Date: Sun, 29 Sep 2024 15:40:18 +0800 Subject: [PATCH] Add split type to web worker --- core/zcncrypto/signature_scheme.go | 1 + wasmsdk/cache.go | 1 + wasmsdk/jsbridge/webworker.go | 3 ++- wasmsdk/proxy.go | 9 +++++++-- wasmsdk/wallet.go | 4 +++- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/core/zcncrypto/signature_scheme.go b/core/zcncrypto/signature_scheme.go index 6a192ac26..d8c154857 100644 --- a/core/zcncrypto/signature_scheme.go +++ b/core/zcncrypto/signature_scheme.go @@ -31,6 +31,7 @@ type Wallet struct { DateCreated string `json:"date_created"` Nonce int64 `json:"nonce"` IsSplit bool `json:"is_split"` + SplitType string `json:"split_type"` } // SignatureScheme - an encryption scheme for signing and verifying messages diff --git a/wasmsdk/cache.go b/wasmsdk/cache.go index 2e8d914e5..9a29a3165 100644 --- a/wasmsdk/cache.go +++ b/wasmsdk/cache.go @@ -92,6 +92,7 @@ func addWebWorkers(alloc *sdk.Allocation) (err error) { c.Keys[0].PublicKey, c.Keys[0].PrivateKey, c.Mnemonic, + c.SplitType, c.IsSplit) //nolint:errcheck if workerCreated { respRequired++ diff --git a/wasmsdk/jsbridge/webworker.go b/wasmsdk/jsbridge/webworker.go index 63034b008..2666f6353 100644 --- a/wasmsdk/jsbridge/webworker.go +++ b/wasmsdk/jsbridge/webworker.go @@ -64,7 +64,7 @@ var ( gZauthServer string ) -func NewWasmWebWorker(blobberID, blobberURL, clientID, clientKey, peerPublicKey, publicKey, privateKey, mnemonic string, isSplit bool) (*WasmWebWorker, bool, error) { +func NewWasmWebWorker(blobberID, blobberURL, clientID, clientKey, peerPublicKey, publicKey, privateKey, mnemonic, splitType string, isSplit bool) (*WasmWebWorker, bool, error) { created := false _, ok := workers[blobberID] if ok { @@ -82,6 +82,7 @@ func NewWasmWebWorker(blobberID, blobberURL, clientID, clientKey, peerPublicKey, "MODE=worker", "PUBLIC_KEY=" + publicKey, "IS_SPLIT=" + strconv.FormatBool(isSplit), + "SPLIT_TYPE=" + splitType, "MNEMONIC=" + mnemonic, "ZAUTH_SERVER=" + gZauthServer}, Path: "zcn.wasm", diff --git a/wasmsdk/proxy.go b/wasmsdk/proxy.go index 92419364b..05663ebbf 100644 --- a/wasmsdk/proxy.go +++ b/wasmsdk/proxy.go @@ -480,7 +480,7 @@ func main() { } } - setWallet(clientID, clientKey, peerPublicKey, publicKey, privateKey, mnemonic, isSplit) + setWallet(clientID, clientKey, peerPublicKey, publicKey, privateKey, mnemonic, splitType, isSplit) hideLogs() debug.SetGCPercent(75) debug.SetMemoryLimit(1 * 1024 * 1024 * 1024) //1GB @@ -543,7 +543,12 @@ func UpdateWalletWithEventData(data *safejs.Value) error { isSplit = false } + splitType, err := jsbridge.ParseEventDataField(data, "split_type") + if err != nil { + splitType = "" + } + fmt.Println("update wallet with event data") - setWallet(clientID, clientKey, peerPublicKey, publicKey, privateKey, mnemonic, isSplit) + setWallet(clientID, clientKey, peerPublicKey, publicKey, privateKey, mnemonic, splitType, isSplit) return nil } diff --git a/wasmsdk/wallet.go b/wasmsdk/wallet.go index c806a074a..d67fbb1bc 100644 --- a/wasmsdk/wallet.go +++ b/wasmsdk/wallet.go @@ -15,7 +15,7 @@ import ( "github.com/0chain/gosdk/zcncore" ) -func setWallet(clientID, clientKey, peerPublicKey, publicKey, privateKey, mnemonic string, isSplit bool) error { +func setWallet(clientID, clientKey, peerPublicKey, publicKey, privateKey, mnemonic, splitType string, isSplit bool) error { if mnemonic == "" && !isSplit { return errors.New("mnemonic is required") } @@ -49,6 +49,7 @@ func setWallet(clientID, clientKey, peerPublicKey, publicKey, privateKey, mnemon Mnemonic: mnemonic, Keys: keys, IsSplit: isSplit, + SplitType: splitType, } fmt.Println("set Wallet, is split:", isSplit) err := zcncore.SetWallet(*w, isSplit) @@ -67,6 +68,7 @@ func setWallet(clientID, clientKey, peerPublicKey, publicKey, privateKey, mnemon "private_key": privateKey, "mnemonic": mnemonic, "is_split": strconv.FormatBool(isSplit), + "split_type": splitType, }); err != nil { return err }