github.com/0chain/gosdk@v1.17.11/zboxcore/marker/authticket.go (about)

     1  package marker
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/0chain/gosdk/core/encryption"
     7  	"github.com/0chain/gosdk/zboxcore/client"
     8  )
     9  
    10  // AuthTicket authentication ticket for file sharing.
    11  // AuthTicket is used to provide access to a file or directory by non-owner clients.
    12  // It's generated by the owner client and signed with their wallet's private key.
    13  // Then shared with the non-owner client to be able to access the shared file or directory.
    14  type AuthTicket struct {
    15  	ClientID        string `json:"client_id"`
    16  	OwnerID         string `json:"owner_id"`
    17  	AllocationID    string `json:"allocation_id"`
    18  	FilePathHash    string `json:"file_path_hash"`
    19  	ActualFileHash  string `json:"actual_file_hash"`
    20  	FileName        string `json:"file_name"`
    21  	RefType         string `json:"reference_type"`
    22  	Expiration      int64  `json:"expiration"`
    23  	Timestamp       int64  `json:"timestamp"`
    24  	ReEncryptionKey string `json:"re_encryption_key,omitempty"`
    25  	Encrypted       bool   `json:"encrypted"`
    26  	Signature       string `json:"signature"`
    27  }
    28  
    29  // NewAuthTicket returns the MPT hash of the AuthTicket
    30  func (at *AuthTicket) GetHashData() string {
    31  	hashData := fmt.Sprintf("%v:%v:%v:%v:%v:%v:%v:%v:%v:%v:%v",
    32  		at.AllocationID,
    33  		at.ClientID,
    34  		at.OwnerID,
    35  		at.FilePathHash,
    36  		at.FileName,
    37  		at.RefType,
    38  		at.ReEncryptionKey,
    39  		at.Expiration,
    40  		at.Timestamp,
    41  		at.ActualFileHash,
    42  		at.Encrypted,
    43  	)
    44  	return hashData
    45  }
    46  
    47  // Sign signs the AuthTicket
    48  func (at *AuthTicket) Sign() error {
    49  	var err error
    50  	hash := encryption.Hash(at.GetHashData())
    51  	at.Signature, err = client.Sign(hash)
    52  	return err
    53  }