Sign Resource

This commit is contained in:
mr
2026-02-09 12:37:03 +01:00
parent b767afb301
commit b9c9b66780
9 changed files with 115 additions and 12 deletions

View File

@@ -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 {