Sign Resource
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package resources
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"slices"
|
||||
@@ -27,7 +28,21 @@ type AbstractResource struct {
|
||||
Owners []utils.Owner `json:"owners,omitempty" bson:"owners,omitempty"` // Owners is the list of owners of the resource
|
||||
UsageRestrictions string `bson:"usage_restrictions,omitempty" json:"usage_restrictions,omitempty"`
|
||||
AllowedBookingModes map[booking.BookingMode]*pricing.PricingVariation `bson:"allowed_booking_modes" json:"allowed_booking_modes"`
|
||||
Signature []byte `bson:"signature" json:"signature"`
|
||||
Signature []byte `bson:"signature,omitempty" json:"signature,omitempty"`
|
||||
}
|
||||
|
||||
func (r *AbstractResource) Unsign() {
|
||||
r.Signature = nil
|
||||
}
|
||||
|
||||
func (r *AbstractResource) Sign() {
|
||||
priv, err := tools.LoadKeyFromFilePrivate() // your node private key
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
b, _ := json.Marshal(r)
|
||||
hash := sha256.Sum256(b)
|
||||
r.Signature, err = priv.Sign(hash[:])
|
||||
}
|
||||
|
||||
func (abs *AbstractResource) GetSignature() []byte {
|
||||
|
||||
Reference in New Issue
Block a user