mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-05-25 16:26:44 +00:00

* added upper and lower case TA resolution testing * added more detailed error reporting to the ValidateSignature method. * extended test cases to test and verify these errs and their differences * fixed CID attestation issue. CIDs are send in web compatible encoding that is not hex encoded and can be utilized without any further decoding on the server side. * added checks and error handling for the Ta store object storage/loading Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package keeper
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"errors"
|
|
"planetmint-go/x/machine/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/store/prefix"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
)
|
|
|
|
func (k Keeper) StoreTrustAnchor(ctx sdk.Context, ta types.TrustAnchor, activated bool) error {
|
|
store := prefix.NewStore(ctx.KVStore(k.taStoreKey), types.KeyPrefix(types.TrustAnchorKey))
|
|
// if activated is set to true then store 1 else 0
|
|
var appendValue []byte
|
|
if activated {
|
|
appendValue = []byte{1}
|
|
} else {
|
|
appendValue = []byte{0}
|
|
}
|
|
pubKey_bytes, err := getTrustAnchorBytes(ta.Pubkey)
|
|
if err != nil {
|
|
return errors.New("the given public key could not be decoded (malformed string)")
|
|
}
|
|
store.Set(pubKey_bytes, appendValue)
|
|
return nil
|
|
}
|
|
|
|
func (k Keeper) GetTrustAnchor(ctx sdk.Context, pubKey string) (val types.TrustAnchor, activated bool, found bool) {
|
|
store := prefix.NewStore(ctx.KVStore(k.taStoreKey), types.KeyPrefix(types.TrustAnchorKey))
|
|
pubKey_bytes, err := getTrustAnchorBytes(pubKey)
|
|
if err != nil {
|
|
return val, false, false
|
|
}
|
|
trustAnchorActivated := store.Get(pubKey_bytes)
|
|
|
|
if trustAnchorActivated == nil {
|
|
return val, false, false
|
|
}
|
|
|
|
// if stored byte is 1 then return activated equals true
|
|
val.Pubkey = pubKey
|
|
if trustAnchorActivated[0] == 1 {
|
|
return val, true, true
|
|
} else {
|
|
return val, false, true
|
|
}
|
|
}
|
|
|
|
func getTrustAnchorBytes(pubKey string) ([]byte, error) {
|
|
return hex.DecodeString(pubKey)
|
|
}
|