Skip to content

Commit

Permalink
Add split type to web worker
Browse files Browse the repository at this point in the history
  • Loading branch information
peterlimg committed Sep 29, 2024
1 parent e0a878b commit ad1f574
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions core/zcncrypto/signature_scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions wasmsdk/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand Down
3 changes: 2 additions & 1 deletion wasmsdk/jsbridge/webworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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",
Expand Down
9 changes: 7 additions & 2 deletions wasmsdk/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
4 changes: 3 additions & 1 deletion wasmsdk/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
Expand Down

0 comments on commit ad1f574

Please sign in to comment.