Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sign update alloc auth ticket #19

Open
wants to merge 12 commits into
base: feat/enterprise-blobber
Choose a base branch
from
8 changes: 8 additions & 0 deletions wasmsdk/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,14 @@ func updateAllocation(allocationID string,
return hash, err
}

func getUpdateAllocTicket(allocationID, userID, operationType string, roundExpiry int64) (string, error) {
sign, err := sdk.GetUpdateAllocTicket(allocationID, userID, operationType, roundExpiry)
if err != nil {
return "", err
}
return sign, err
}

// getAllocationMinLock retrieves the minimum lock value for the allocation creation, as calculated by the network.
// Lock value is the amount of tokens that the client needs to lock in the allocation's write pool
// to be able to pay for the write operations.
Expand Down
29 changes: 21 additions & 8 deletions wasmsdk/auth_txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,29 @@ func registerZauthServer(serverAddr string) {
sys.SetAuthCommon(zcncore.ZauthAuthCommon(serverAddr))
}

// zvaultNewWallet generates new split wallet
func zvaultNewWallet(serverAddr, token string) (string, error) {
return zcncore.CallZvaultNewWalletString(serverAddr, token, "")
func zauthRetrieveKey(clientID, peerPublicKey, serverAddr, token string) (string, error) {
return zcncore.CallZauthRetreiveKey(serverAddr, token, clientID, peerPublicKey)
}

// zvaultNewSplit generates new split wallet from existing clientID
func zvaultNewSplit(clientID, serverAddr, token string) (string, error) {
return zcncore.CallZvaultNewWalletString(serverAddr, token, clientID)
// zvaultNewWallet generates new wallet
func zvaultNewWallet(serverAddr, token string) error {
return zcncore.CallZvaultNewWallet(serverAddr, token)
}

func zvaultStoreKey(serverAddr, token, privateKey string) (string, error) {
// zvaultNewSplit generates new split key for saved wallet
func zvaultNewSplit(clientID, serverAddr, token string) error {
return zcncore.CallZvaultNewSplit(serverAddr, token, clientID)
}

func zvaultRetrieveRestrictions(peerPublicKey, serverAddr, token string) (string, error) {
return zcncore.CallZvaultRetrieveRestrictions(serverAddr, token, peerPublicKey)
}

func zvaultUpdateRestrictions(clientID, peerPublicKey, serverAddr, token string, restrictions []string) error {
return zcncore.CallZvaultUpdateRestrictions(serverAddr, token, clientID, peerPublicKey, restrictions)
}

func zvaultStoreKey(serverAddr, token, privateKey string) error {
return zcncore.CallZvaultStoreKeyString(serverAddr, token, privateKey)
}

Expand Down Expand Up @@ -92,7 +104,8 @@ func registerAuthCommon(this js.Value, args []js.Value) interface{} {
}

// authResponse Publishes the response to the authorization request.
// `response` is the response to the authorization request.
//
// `response` is the response to the authorization request.
func authResponse(response string) {
authResponseC <- response
}
Expand Down
16 changes: 6 additions & 10 deletions wasmsdk/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ func main() {
return "", fmt.Errorf("failed to sign with split key: %v", err)
}

data, err := json.Marshal(struct {
Hash string `json:"hash"`
Signature string `json:"signature"`
ClientID string `json:"client_id"`
}{
data, err := json.Marshal(zcncore.AuthMessage{
Hash: hash,
Signature: sig,
ClientID: client.GetClient().ClientID,
Expand Down Expand Up @@ -271,6 +267,7 @@ func main() {
"getUpdateAllocationMinLock": getUpdateAllocationMinLock,
"getAllocationWith": getAllocationWith,
"createfreeallocation": createfreeallocation,
"getUpdateAllocTicket": getUpdateAllocTicket,

// readpool
"getReadPoolInfo": getReadPoolInfo,
Expand Down Expand Up @@ -328,9 +325,12 @@ func main() {

// zauth
"registerZauthServer": registerZauthServer,
"zauthRetrieveKey": zauthRetrieveKey,
// zvault
"zvaultNewWallet": zvaultNewWallet,
"zvaultNewSplit": zvaultNewSplit,
"zvaultRetrieveRestrictions": zvaultRetrieveRestrictions,
"zvaultUpdateRestrictions": zvaultUpdateRestrictions,
"zvaultStoreKey": zvaultStoreKey,
"zvaultRetrieveKeys": zvaultRetrieveKeys,
"zvaultRevokeKey": zvaultRevokeKey,
Expand Down Expand Up @@ -386,11 +386,7 @@ func main() {
return "", fmt.Errorf("failed to sign with split key: %v", err)
}

data, err := json.Marshal(struct {
Hash string `json:"hash"`
Signature string `json:"signature"`
ClientID string `json:"client_id"`
}{
data, err := json.Marshal(zcncore.AuthMessage{
Hash: hash,
Signature: sig,
ClientID: client.GetClient().ClientID,
Expand Down
2 changes: 1 addition & 1 deletion zboxapi/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (c *Client) createResty(ctx context.Context, csrfToken, userID string, head
h["X-App-Timestamp"] = strconv.FormatInt(time.Now().Unix(), 10)

if _, ok := h["X-App-ID-Token"]; !ok {
h["X-App-ID-Token"] = "*" //ignore firebase token in jwt requests
h["X-App-ID-Token"] = "*"
}

h["X-App-Type"] = c.appType
Expand Down
13 changes: 13 additions & 0 deletions zboxcore/sdk/blobber_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
package sdk

import (
"encoding/hex"
"encoding/json"
"fmt"
"math"
"strings"

Expand Down Expand Up @@ -154,6 +156,17 @@ func UpdateAllocation(
return
}

func GetUpdateAllocTicket(allocationID, userID, operationType string, roundExpiry int64) (string, error) {
payload := fmt.Sprintf("%s:%d:%s:%s", allocationID, roundExpiry, userID, operationType)

signature, err := client.Sign(hex.EncodeToString([]byte(payload)))
if err != nil {
return "", err
}

return signature, nil
}

// StakePoolLock locks tokens in a stake pool.
// This function is the entry point for the staking operation.
// Provided the provider type and provider ID, the value is locked in the stake pool between the SDK client and the provider.
Expand Down
Loading
Loading