mirror of
https://github.com/onsonr/sonr.git
synced 2025-03-10 13:07:09 +00:00
refactor: use RawPublicKey instead of PublicKey in macaroon issuer
This commit is contained in:
parent
6da6f2b97b
commit
a0a5f0c7e0
@ -5,7 +5,6 @@ import (
|
|||||||
|
|
||||||
"github.com/onsonr/crypto/mpc"
|
"github.com/onsonr/crypto/mpc"
|
||||||
|
|
||||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
didv1 "github.com/onsonr/sonr/api/did/v1"
|
didv1 "github.com/onsonr/sonr/api/did/v1"
|
||||||
)
|
)
|
||||||
@ -16,8 +15,8 @@ type ControllerI interface {
|
|||||||
SonrAddress() string
|
SonrAddress() string
|
||||||
EthAddress() string
|
EthAddress() string
|
||||||
BtcAddress() string
|
BtcAddress() string
|
||||||
// RawPublicKey() []byte
|
RawPublicKey() []byte
|
||||||
StdPublicKey() cryptotypes.PubKey
|
// StdPublicKey() cryptotypes.PubKey
|
||||||
GetTableEntry() (*didv1.Controller, error)
|
GetTableEntry() (*didv1.Controller, error)
|
||||||
ExportUserKs() (string, error)
|
ExportUserKs() (string, error)
|
||||||
}
|
}
|
||||||
@ -123,7 +122,6 @@ func (c *controller) RawPublicKey() []byte {
|
|||||||
return c.publicKey
|
return c.publicKey
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// func (c *controller) StdPublicKey() cryptotypes.PubKey {
|
// func (c *controller) StdPublicKey() cryptotypes.PubKey {
|
||||||
// return c.stdPubKey
|
// return c.stdPubKey
|
||||||
// }
|
// }
|
||||||
|
@ -15,7 +15,7 @@ var fourYears = time.Hour * 24 * 365 * 4
|
|||||||
// IssueAdminMacaroon creates a macaroon with the specified parameters.
|
// IssueAdminMacaroon creates a macaroon with the specified parameters.
|
||||||
func (k Keeper) IssueAdminMacaroon(sdkctx sdk.Context, controller didtypes.ControllerI) (*macaroon.Macaroon, error) {
|
func (k Keeper) IssueAdminMacaroon(sdkctx sdk.Context, controller didtypes.ControllerI) (*macaroon.Macaroon, error) {
|
||||||
// Derive the root key by hashing the shared MPC public key
|
// Derive the root key by hashing the shared MPC public key
|
||||||
rootKey := sha256.Sum256([]byte(controller.PublicKey()))
|
rootKey := sha256.Sum256([]byte(controller.RawPublicKey()))
|
||||||
// Create the macaroon
|
// Create the macaroon
|
||||||
m, err := macaroon.New(rootKey[:], []byte(controller.SonrAddress()), controller.ChainID(), macaroon.LatestVersion)
|
m, err := macaroon.New(rootKey[:], []byte(controller.SonrAddress()), controller.ChainID(), macaroon.LatestVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// assembleVault assembles the initial vault
|
// assembleVault assembles the initial vault
|
||||||
func (k Keeper) assembleVault(cotx sdk.Context) (string, int64, error) {
|
func (k Keeper) assembleVault(cotx sdk.Context, schema *dwngen.Schema) (string, int64, error) {
|
||||||
_, con, err := k.DIDKeeper.NewController(cotx)
|
_, con, err := k.DIDKeeper.NewController(cotx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, err
|
return "", 0, err
|
||||||
@ -19,11 +19,7 @@ func (k Keeper) assembleVault(cotx sdk.Context) (string, int64, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, err
|
return "", 0, err
|
||||||
}
|
}
|
||||||
sch, err := k.currentSchema(cotx)
|
v, err := types.NewVault(usrKs, con.SonrAddress(), con.ChainID(), schema)
|
||||||
if err != nil {
|
|
||||||
return "", 0, err
|
|
||||||
}
|
|
||||||
v, err := types.NewVault(usrKs, con.SonrAddress(), con.ChainID(), sch)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, err
|
return "", 0, err
|
||||||
}
|
}
|
||||||
|
@ -53,10 +53,16 @@ func (k Querier) Schema(goCtx context.Context, req *types.QuerySchemaRequest) (*
|
|||||||
func (k Querier) Allocate(goCtx context.Context, req *types.AllocateRequest) (*types.AllocateResponse, error) {
|
func (k Querier) Allocate(goCtx context.Context, req *types.AllocateRequest) (*types.AllocateResponse, error) {
|
||||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||||
|
|
||||||
// 2.Allocate the vault msg.GetSubject(), msg.GetOrigin()
|
// 1. Get current schema
|
||||||
cid, expiryBlock, err := k.assembleVault(ctx)
|
sch, err := k.currentSchema(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, types.ErrInvalidSchema.Wrap(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2.Allocate the vault msg.GetSubject(), msg.GetOrigin()
|
||||||
|
cid, expiryBlock, err := k.assembleVault(ctx, sch)
|
||||||
|
if err != nil {
|
||||||
|
return nil, types.ErrVaultAssembly.Wrap(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
return &types.AllocateResponse{
|
return &types.AllocateResponse{
|
||||||
|
@ -4,7 +4,9 @@ import sdkerrors "cosmossdk.io/errors"
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
ErrInvalidGenesisState = sdkerrors.Register(ModuleName, 100, "invalid genesis state")
|
ErrInvalidGenesisState = sdkerrors.Register(ModuleName, 100, "invalid genesis state")
|
||||||
ErrUnsupportedKeyEncoding = sdkerrors.Register(ModuleName, 200, "unsupported key encoding")
|
ErrInvalidSchema = sdkerrors.Register(ModuleName, 200, "invalid schema")
|
||||||
ErrUnsopportedChainCode = sdkerrors.Register(ModuleName, 201, "unsupported chain code")
|
ErrVaultAssembly = sdkerrors.Register(ModuleName, 201, "vault assembly")
|
||||||
ErrUnsupportedKeyCurve = sdkerrors.Register(ModuleName, 202, "unsupported key curve")
|
ErrUnsupportedKeyEncoding = sdkerrors.Register(ModuleName, 300, "unsupported key encoding")
|
||||||
|
ErrUnsopportedChainCode = sdkerrors.Register(ModuleName, 301, "unsupported chain code")
|
||||||
|
ErrUnsupportedKeyCurve = sdkerrors.Register(ModuleName, 302, "unsupported key curve")
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user