Skip to content

Commit 555ea31

Browse files
authored
Merge pull request #1755 from 0chain/fix/ownerSigingPublicKey
Fix create allocation for owner to get ownerSigningPublicKey
2 parents 671e93e + f8bd4ea commit 555ea31

File tree

5 files changed

+31
-13
lines changed

5 files changed

+31
-13
lines changed

wasmsdk/allocation.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,3 +545,7 @@ func repairSize(allocationID, remotePath string) (sdk.RepairSize, error) {
545545
}
546546
return alloc.RepairSize(remotePath)
547547
}
548+
549+
func generateOwnerSigningKey(ownerPublicKey, ownerID string) (string, error) {
550+
return sdk.GenerateOwnerSigningPublicKey()
551+
}

wasmsdk/proxy.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func main() {
247247
"terminateWorkers": terminateWorkers,
248248
"createWorkers": createWorkers,
249249
"getFileMetaByName": getFileMetaByName,
250-
"getFileMetaByAuthTicket": getFileMetaByAuthTicket,
250+
"getFileMetaByAuthTicket": getFileMetaByAuthTicket,
251251
"downloadDirectory": downloadDirectory,
252252
"cancelDownloadDirectory": cancelDownloadDirectory,
253253
"cancelDownloadBlocks": cancelDownloadBlocks,
@@ -290,6 +290,8 @@ func main() {
290290
"allocationRepair": allocationRepair,
291291
"repairSize": repairSize,
292292

293+
"generateOwnerSigningKey": generateOwnerSigningKey,
294+
293295
// bridge
294296
"initBridge": initBridge,
295297
"burnZCN": burnZCN,

zboxcore/sdk/allocation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ func (a *Allocation) generateAndSetOwnerSigningPublicKey() {
457457
if a.OwnerPublicKey != client.PublicKey() {
458458
return
459459
}
460-
privateSigningKey, err := generateOwnerSigningKey(a.OwnerPublicKey, a.Owner)
460+
privateSigningKey, err := GenerateOwnerSigningKey(a.OwnerPublicKey, a.Owner)
461461
if err != nil {
462462
l.Logger.Error("Failed to generate owner signing key", zap.Error(err))
463463
return
@@ -1385,7 +1385,7 @@ func (a *Allocation) generateDownloadRequest(
13851385
downloadReq.allocOwnerPubKey = a.OwnerPublicKey
13861386
downloadReq.allocOwnerSigningPubKey = a.OwnerSigningPublicKey
13871387
if len(a.privateSigningKey) == 0 {
1388-
sk, err := generateOwnerSigningKey(client.PublicKey(), client.Id())
1388+
sk, err := GenerateOwnerSigningKey(client.PublicKey(), client.Id())
13891389
if err != nil {
13901390
return nil, err
13911391
}
@@ -2829,7 +2829,7 @@ func (a *Allocation) downloadFromAuthTicket(fileHandler sys.File, authTicket str
28292829
downloadReq.allocOwnerPubKey = a.OwnerPublicKey
28302830
downloadReq.allocOwnerSigningPubKey = a.OwnerSigningPublicKey
28312831
//for auth ticket set your own signing key
2832-
sk, err := generateOwnerSigningKey(client.PublicKey(), client.Id())
2832+
sk, err := GenerateOwnerSigningKey(client.PublicKey(), client.Id())
28332833
if err != nil {
28342834
return err
28352835
}

zboxcore/sdk/blobber_operations.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import (
3131
//
3232
// returns the hash of the transaction, the nonce of the transaction, the transaction object and an error if any.
3333
func CreateAllocationForOwner(
34-
owner, ownerpublickey string,
35-
datashards, parityshards int, size int64,
34+
owner, ownerPublicKey, ownerSigningPublicKey string,
35+
dataShards, parityShards int, size int64,
3636
readPrice, writePrice PriceRange,
3737
lock uint64, preferredBlobberIds, blobberAuthTickets []string, thirdPartyExtendable, IsEnterprise, force bool, fileOptionsParams *FileOptionsParameters, authRoundExpiry int64,
3838
) (hash string, nonce int64, txn *transaction.Transaction, err error) {
@@ -41,12 +41,12 @@ func CreateAllocationForOwner(
4141
return "", 0, nil, errors.New("invalid_lock", "int64 overflow on lock value")
4242
}
4343

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

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

58-
if client.PublicKey() == ownerpublickey {
59-
privateSigningKey, err := generateOwnerSigningKey(ownerpublickey, owner)
58+
if client.PublicKey() == ownerPublicKey {
59+
privateSigningKey, err := GenerateOwnerSigningKey(ownerPublicKey, owner)
6060
if err != nil {
6161
return "", 0, nil, errors.New("failed_generate_owner_signing_key", "failed to generate owner signing key: "+err.Error())
6262
}
6363
pub := privateSigningKey.Public().(ed25519.PublicKey)
6464
pk := hex.EncodeToString(pub)
6565
allocationRequest["owner_signing_public_key"] = pk
66+
} else {
67+
allocationRequest["owner_signing_public_key"] = ownerSigningPublicKey
6668
}
6769

6870
allocationRequest["owner_id"] = owner
69-
allocationRequest["owner_public_key"] = ownerpublickey
71+
allocationRequest["owner_public_key"] = ownerPublicKey
7072
allocationRequest["third_party_extendable"] = thirdPartyExtendable
7173
allocationRequest["file_options_changed"], allocationRequest["file_options"] = calculateAllocationFileOptions(63 /*0011 1111*/, fileOptionsParams)
7274
allocationRequest["is_enterprise"] = IsEnterprise
@@ -359,7 +361,7 @@ func WritePoolUnlock(allocID string, fee uint64) (hash string, nonce int64, err
359361
return
360362
}
361363

362-
func generateOwnerSigningKey(ownerPublicKey, ownerID string) (ed25519.PrivateKey, error) {
364+
func GenerateOwnerSigningKey(ownerPublicKey, ownerID string) (ed25519.PrivateKey, error) {
363365
if ownerPublicKey == "" {
364366
return nil, errors.New("owner_public_key_required", "owner public key is required")
365367
}
@@ -374,3 +376,13 @@ func generateOwnerSigningKey(ownerPublicKey, ownerID string) (ed25519.PrivateKey
374376
privateSigningKey := ed25519.NewKeyFromSeed(decodedSig[:32])
375377
return privateSigningKey, nil
376378
}
379+
380+
func GenerateOwnerSigningPublicKey() (string, error) {
381+
privateSigningKey, err := GenerateOwnerSigningKey(client.PublicKey(), client.Id())
382+
if err != nil {
383+
return "", err
384+
}
385+
386+
pubKey := privateSigningKey.Public().(ed25519.PublicKey)
387+
return hex.EncodeToString(pubKey), nil
388+
}

zboxcore/sdk/sdk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ func CreateAllocationWith(options CreateAllocationOptions) (
810810
string, int64, *transaction.Transaction, error) {
811811

812812
return CreateAllocationForOwner(client.Id(),
813-
client.PublicKey(), options.DataShards, options.ParityShards,
813+
client.PublicKey(), "", options.DataShards, options.ParityShards,
814814
options.Size, options.ReadPrice, options.WritePrice, options.Lock,
815815
options.BlobberIds, options.BlobberAuthTickets, options.ThirdPartyExtendable, options.IsEnterprise, options.Force, options.FileOptionsParams, options.AuthRoundExpiry)
816816
}

0 commit comments

Comments
 (0)