Skip to content

Commit

Permalink
Merge pull request #1755 from 0chain/fix/ownerSigingPublicKey
Browse files Browse the repository at this point in the history
Fix create allocation for owner to get ownerSigningPublicKey
  • Loading branch information
dabasov authored Feb 24, 2025
2 parents 671e93e + f8bd4ea commit 555ea31
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
4 changes: 4 additions & 0 deletions wasmsdk/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,3 +545,7 @@ func repairSize(allocationID, remotePath string) (sdk.RepairSize, error) {
}
return alloc.RepairSize(remotePath)
}

func generateOwnerSigningKey(ownerPublicKey, ownerID string) (string, error) {
return sdk.GenerateOwnerSigningPublicKey()
}
4 changes: 3 additions & 1 deletion wasmsdk/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func main() {
"terminateWorkers": terminateWorkers,
"createWorkers": createWorkers,
"getFileMetaByName": getFileMetaByName,
"getFileMetaByAuthTicket": getFileMetaByAuthTicket,
"getFileMetaByAuthTicket": getFileMetaByAuthTicket,
"downloadDirectory": downloadDirectory,
"cancelDownloadDirectory": cancelDownloadDirectory,
"cancelDownloadBlocks": cancelDownloadBlocks,
Expand Down Expand Up @@ -290,6 +290,8 @@ func main() {
"allocationRepair": allocationRepair,
"repairSize": repairSize,

"generateOwnerSigningKey": generateOwnerSigningKey,

// bridge
"initBridge": initBridge,
"burnZCN": burnZCN,
Expand Down
6 changes: 3 additions & 3 deletions zboxcore/sdk/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func (a *Allocation) generateAndSetOwnerSigningPublicKey() {
if a.OwnerPublicKey != client.PublicKey() {
return
}
privateSigningKey, err := generateOwnerSigningKey(a.OwnerPublicKey, a.Owner)
privateSigningKey, err := GenerateOwnerSigningKey(a.OwnerPublicKey, a.Owner)
if err != nil {
l.Logger.Error("Failed to generate owner signing key", zap.Error(err))
return
Expand Down Expand Up @@ -1385,7 +1385,7 @@ func (a *Allocation) generateDownloadRequest(
downloadReq.allocOwnerPubKey = a.OwnerPublicKey
downloadReq.allocOwnerSigningPubKey = a.OwnerSigningPublicKey
if len(a.privateSigningKey) == 0 {
sk, err := generateOwnerSigningKey(client.PublicKey(), client.Id())
sk, err := GenerateOwnerSigningKey(client.PublicKey(), client.Id())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -2829,7 +2829,7 @@ func (a *Allocation) downloadFromAuthTicket(fileHandler sys.File, authTicket str
downloadReq.allocOwnerPubKey = a.OwnerPublicKey
downloadReq.allocOwnerSigningPubKey = a.OwnerSigningPublicKey
//for auth ticket set your own signing key
sk, err := generateOwnerSigningKey(client.PublicKey(), client.Id())
sk, err := GenerateOwnerSigningKey(client.PublicKey(), client.Id())
if err != nil {
return err
}
Expand Down
28 changes: 20 additions & 8 deletions zboxcore/sdk/blobber_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
//
// returns the hash of the transaction, the nonce of the transaction, the transaction object and an error if any.
func CreateAllocationForOwner(
owner, ownerpublickey string,
datashards, parityshards int, size int64,
owner, ownerPublicKey, ownerSigningPublicKey string,
dataShards, parityShards int, size int64,
readPrice, writePrice PriceRange,
lock uint64, preferredBlobberIds, blobberAuthTickets []string, thirdPartyExtendable, IsEnterprise, force bool, fileOptionsParams *FileOptionsParameters, authRoundExpiry int64,
) (hash string, nonce int64, txn *transaction.Transaction, err error) {
Expand All @@ -41,12 +41,12 @@ func CreateAllocationForOwner(
return "", 0, nil, errors.New("invalid_lock", "int64 overflow on lock value")
}

if datashards < 1 || parityshards < 1 {
if dataShards < 1 || parityShards < 1 {
return "", 0, nil, errors.New("allocation_validation_failed", "atleast 1 data and 1 parity shards are required")
}

allocationRequest, err := getNewAllocationBlobbers(
StorageV2, datashards, parityshards, size, readPrice, writePrice, preferredBlobberIds, blobberAuthTickets, force)
StorageV2, dataShards, parityShards, size, readPrice, writePrice, preferredBlobberIds, blobberAuthTickets, force)
if err != nil {
return "", 0, nil, errors.New("failed_get_allocation_blobbers", "failed to get blobbers for allocation: "+err.Error())
}
Expand All @@ -55,18 +55,20 @@ func CreateAllocationForOwner(
return "", 0, nil, sdkNotInitialized
}

if client.PublicKey() == ownerpublickey {
privateSigningKey, err := generateOwnerSigningKey(ownerpublickey, owner)
if client.PublicKey() == ownerPublicKey {
privateSigningKey, err := GenerateOwnerSigningKey(ownerPublicKey, owner)
if err != nil {
return "", 0, nil, errors.New("failed_generate_owner_signing_key", "failed to generate owner signing key: "+err.Error())
}
pub := privateSigningKey.Public().(ed25519.PublicKey)
pk := hex.EncodeToString(pub)
allocationRequest["owner_signing_public_key"] = pk
} else {
allocationRequest["owner_signing_public_key"] = ownerSigningPublicKey
}

allocationRequest["owner_id"] = owner
allocationRequest["owner_public_key"] = ownerpublickey
allocationRequest["owner_public_key"] = ownerPublicKey
allocationRequest["third_party_extendable"] = thirdPartyExtendable
allocationRequest["file_options_changed"], allocationRequest["file_options"] = calculateAllocationFileOptions(63 /*0011 1111*/, fileOptionsParams)
allocationRequest["is_enterprise"] = IsEnterprise
Expand Down Expand Up @@ -359,7 +361,7 @@ func WritePoolUnlock(allocID string, fee uint64) (hash string, nonce int64, err
return
}

func generateOwnerSigningKey(ownerPublicKey, ownerID string) (ed25519.PrivateKey, error) {
func GenerateOwnerSigningKey(ownerPublicKey, ownerID string) (ed25519.PrivateKey, error) {
if ownerPublicKey == "" {
return nil, errors.New("owner_public_key_required", "owner public key is required")
}
Expand All @@ -374,3 +376,13 @@ func generateOwnerSigningKey(ownerPublicKey, ownerID string) (ed25519.PrivateKey
privateSigningKey := ed25519.NewKeyFromSeed(decodedSig[:32])
return privateSigningKey, nil
}

func GenerateOwnerSigningPublicKey() (string, error) {
privateSigningKey, err := GenerateOwnerSigningKey(client.PublicKey(), client.Id())
if err != nil {
return "", err
}

pubKey := privateSigningKey.Public().(ed25519.PublicKey)
return hex.EncodeToString(pubKey), nil
}
2 changes: 1 addition & 1 deletion zboxcore/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ func CreateAllocationWith(options CreateAllocationOptions) (
string, int64, *transaction.Transaction, error) {

return CreateAllocationForOwner(client.Id(),
client.PublicKey(), options.DataShards, options.ParityShards,
client.PublicKey(), "", options.DataShards, options.ParityShards,
options.Size, options.ReadPrice, options.WritePrice, options.Lock,
options.BlobberIds, options.BlobberAuthTickets, options.ThirdPartyExtendable, options.IsEnterprise, options.Force, options.FileOptionsParams, options.AuthRoundExpiry)
}
Expand Down

0 comments on commit 555ea31

Please sign in to comment.