mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
feature/1111 sync chain dwn endpoint (#1143)
- **feat(did): add assertion type to DID spec** - **refactor: update build process to include assets generation** - **refactor: update import paths for to** - **feat: introduce new authentication state management** - **feat: add current account route** - **feat: implement global toasts with custom HTML** - **refactor: remove unused session code** - **feat: add config.json to embedded assets** - **refactor: remove unused dependency on gorilla/sessions** - **refactor: simplify session management and remove unnecessary fields** - **fix: remove unnecessary import for unused protobuf types** - **feat: introduce separate HTTP contexts for Highway and DWN** - **fix(keeper): Handle missing controller during initial sync** - **refactor: extract DWN configuration from DWNContext** - **feat: add view route** - **fix: update configuration file name in embed.go** - **feat: improve vaultindex page loading experience** - **feat(hway): add highway context to echo context** - **chore(deps): bump onsonr/crypto from 1.32.0 to 1.33.0** - **refactor: rename DWNSessionMiddleware to WebNodeSessionMiddleware** - **feat: rename client API to web node API** - **refactor: separate API and view routes** - **refactor: remove unused build targets in Makefile** - **feat: add Devbox integration to container** - **feat: add wasm support for dwn** - **refactor: update module proto import** - **feat: add default first and third party caveats** - **feat: Add target vault allocation mechanism** - **refactor: introduce standardized session cookie handling** - **fix: update service worker installation and ready states** - **feat: add worker handlers** - **feat: Enable SSH access to devcontainer** - **refactor: rename HighwayContext to HwayContext** - **feat: add block expiration calculation to sonr context** - **feat: remove config from cookie and header** - **feat(gen): Remove generated code for IPFS, Motr and Sonr** - **refactor: remove unused createMotrConfig function** - **feat: add project analytics with Repobeats** - **docs: Remove component details from README** - **refactor: rename SetConfig to injectConfig**
This commit is contained in:
@@ -3,13 +3,39 @@ package keeper
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/onsonr/sonr/internal/ctx"
|
||||
didtypes "github.com/onsonr/sonr/x/did/types"
|
||||
"gopkg.in/macaroon.v2"
|
||||
)
|
||||
|
||||
// IssueMacaroon creates a macaroon with the specified parameters.
|
||||
func (k Keeper) IssueMacaroon(ctx sdk.Context, sharedMPCPubKey, location, id string, blockExpiry uint64) (*macaroon.Macaroon, error) {
|
||||
var fourYears = time.Hour * 24 * 365 * 4
|
||||
|
||||
// IssueAdminMacaroon creates a macaroon with the specified parameters.
|
||||
func (k Keeper) IssueAdminMacaroon(sdkctx sdk.Context, controller didtypes.ControllerI) (*macaroon.Macaroon, error) {
|
||||
sctx := ctx.GetSonrCTX(sdkctx)
|
||||
// Derive the root key by hashing the shared MPC public key
|
||||
rootKey := sha256.Sum256([]byte(controller.PublicKey()))
|
||||
// Create the macaroon
|
||||
m, err := macaroon.New(rootKey[:], []byte(controller.SonrAddress()), controller.ChainID(), macaroon.LatestVersion)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Add the block expiry caveat
|
||||
caveat := fmt.Sprintf("block-expiry=%d", sctx.GetBlockExpiration(fourYears))
|
||||
err = m.AddFirstPartyCaveat([]byte(caveat))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// IssueServiceMacaroon creates a macaroon with the specified parameters.
|
||||
func (k Keeper) IssueServiceMacaroon(sdkctx sdk.Context, sharedMPCPubKey, location, id string, blockExpiry uint64) (*macaroon.Macaroon, error) {
|
||||
// Derive the root key by hashing the shared MPC public key
|
||||
rootKey := sha256.Sum256([]byte(sharedMPCPubKey))
|
||||
// Create the macaroon
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
OriginMacroonCaveat MacroonCaveat = "origin"
|
||||
ScopesMacroonCaveat MacroonCaveat = "scopes"
|
||||
SubjectMacroonCaveat MacroonCaveat = "subject"
|
||||
ExpMacroonCaveat MacroonCaveat = "exp"
|
||||
TokenMacroonCaveat MacroonCaveat = "token"
|
||||
)
|
||||
|
||||
var MacroonCaveats = []MacroonCaveat{OriginMacroonCaveat, ScopesMacroonCaveat, SubjectMacroonCaveat, ExpMacroonCaveat, TokenMacroonCaveat}
|
||||
|
||||
type MacroonCaveat string
|
||||
|
||||
func (c MacroonCaveat) Equal(other string) bool {
|
||||
return string(c) == other
|
||||
}
|
||||
|
||||
func (c MacroonCaveat) String() string {
|
||||
return string(c)
|
||||
}
|
||||
|
||||
func (c MacroonCaveat) Verify(value string) error {
|
||||
switch c {
|
||||
case OriginMacroonCaveat:
|
||||
return nil
|
||||
case ScopesMacroonCaveat:
|
||||
return nil
|
||||
case SubjectMacroonCaveat:
|
||||
return nil
|
||||
case ExpMacroonCaveat:
|
||||
// Check if the expiration time is still valid
|
||||
exp, err := time.Parse(time.RFC3339, value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if time.Now().After(exp) {
|
||||
return fmt.Errorf("expired")
|
||||
}
|
||||
return nil
|
||||
case TokenMacroonCaveat:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("unknown caveat: %s", c)
|
||||
}
|
||||
}
|
||||
+352
-59
@@ -242,8 +242,8 @@ func (m *Scopes) GetSupported() []string {
|
||||
|
||||
// Caveats defines the available caveats
|
||||
type Caveats struct {
|
||||
SupportedFirstParty []string `protobuf:"bytes,1,rep,name=supported_first_party,json=supportedFirstParty,proto3" json:"supported_first_party,omitempty"`
|
||||
SupportedThirdParty []string `protobuf:"bytes,2,rep,name=supported_third_party,json=supportedThirdParty,proto3" json:"supported_third_party,omitempty"`
|
||||
SupportedFirstParty []*Caveat `protobuf:"bytes,1,rep,name=supported_first_party,json=supportedFirstParty,proto3" json:"supported_first_party,omitempty"`
|
||||
SupportedThirdParty []*Caveat `protobuf:"bytes,2,rep,name=supported_third_party,json=supportedThirdParty,proto3" json:"supported_third_party,omitempty"`
|
||||
}
|
||||
|
||||
func (m *Caveats) Reset() { *m = Caveats{} }
|
||||
@@ -279,14 +279,14 @@ func (m *Caveats) XXX_DiscardUnknown() {
|
||||
|
||||
var xxx_messageInfo_Caveats proto.InternalMessageInfo
|
||||
|
||||
func (m *Caveats) GetSupportedFirstParty() []string {
|
||||
func (m *Caveats) GetSupportedFirstParty() []*Caveat {
|
||||
if m != nil {
|
||||
return m.SupportedFirstParty
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Caveats) GetSupportedThirdParty() []string {
|
||||
func (m *Caveats) GetSupportedThirdParty() []*Caveat {
|
||||
if m != nil {
|
||||
return m.SupportedThirdParty
|
||||
}
|
||||
@@ -347,6 +347,66 @@ func (m *Transactions) GetDenylist() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
type Caveat struct {
|
||||
Scopes []string `protobuf:"bytes,1,rep,name=scopes,proto3" json:"scopes,omitempty"`
|
||||
Caveat string `protobuf:"bytes,2,opt,name=caveat,proto3" json:"caveat,omitempty"`
|
||||
Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"`
|
||||
}
|
||||
|
||||
func (m *Caveat) Reset() { *m = Caveat{} }
|
||||
func (m *Caveat) String() string { return proto.CompactTextString(m) }
|
||||
func (*Caveat) ProtoMessage() {}
|
||||
func (*Caveat) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_06e0b5dfdf5e52ba, []int{6}
|
||||
}
|
||||
func (m *Caveat) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *Caveat) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_Caveat.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *Caveat) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Caveat.Merge(m, src)
|
||||
}
|
||||
func (m *Caveat) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *Caveat) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Caveat.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_Caveat proto.InternalMessageInfo
|
||||
|
||||
func (m *Caveat) GetScopes() []string {
|
||||
if m != nil {
|
||||
return m.Scopes
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Caveat) GetCaveat() string {
|
||||
if m != nil {
|
||||
return m.Caveat
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *Caveat) GetDescription() string {
|
||||
if m != nil {
|
||||
return m.Description
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*GenesisState)(nil), "macaroon.v1.GenesisState")
|
||||
proto.RegisterType((*Params)(nil), "macaroon.v1.Params")
|
||||
@@ -354,42 +414,46 @@ func init() {
|
||||
proto.RegisterType((*Scopes)(nil), "macaroon.v1.Scopes")
|
||||
proto.RegisterType((*Caveats)(nil), "macaroon.v1.Caveats")
|
||||
proto.RegisterType((*Transactions)(nil), "macaroon.v1.Transactions")
|
||||
proto.RegisterType((*Caveat)(nil), "macaroon.v1.Caveat")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("macaroon/v1/genesis.proto", fileDescriptor_06e0b5dfdf5e52ba) }
|
||||
|
||||
var fileDescriptor_06e0b5dfdf5e52ba = []byte{
|
||||
// 470 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xc1, 0x6a, 0xdb, 0x30,
|
||||
0x18, 0xc7, 0xad, 0xb4, 0x38, 0x8b, 0x5a, 0xe8, 0xa6, 0xb6, 0xe0, 0x86, 0xe2, 0x14, 0x5f, 0x56,
|
||||
0x36, 0xb0, 0x49, 0x77, 0xcb, 0xad, 0x1d, 0x6c, 0xa7, 0x41, 0x71, 0x73, 0x1a, 0x83, 0xa2, 0xd8,
|
||||
0xaa, 0x2d, 0xb0, 0x25, 0x23, 0x29, 0x59, 0xf3, 0x0a, 0x63, 0x87, 0x1d, 0x77, 0xec, 0x23, 0x0c,
|
||||
0xf6, 0x12, 0x3d, 0xf6, 0xb8, 0xd3, 0x18, 0xc9, 0x61, 0x7b, 0x8c, 0x61, 0x49, 0x76, 0xda, 0x2d,
|
||||
0xd0, 0x8b, 0x91, 0xbe, 0xdf, 0xf7, 0xff, 0x7f, 0xff, 0x4f, 0x18, 0x1e, 0x94, 0x38, 0xc1, 0x82,
|
||||
0x73, 0x16, 0xcd, 0x86, 0x51, 0x46, 0x18, 0x91, 0x54, 0x86, 0x95, 0xe0, 0x8a, 0xa3, 0xad, 0x06,
|
||||
0x85, 0xb3, 0x61, 0xff, 0x19, 0x2e, 0x29, 0xe3, 0x91, 0xfe, 0x1a, 0xde, 0xdf, 0xcb, 0x78, 0xc6,
|
||||
0xf5, 0x31, 0xaa, 0x4f, 0xb6, 0xba, 0x93, 0xd2, 0xb4, 0xf6, 0x52, 0xd7, 0xa6, 0x10, 0x9c, 0xc2,
|
||||
0xed, 0xb7, 0xc6, 0xf7, 0x42, 0x61, 0x45, 0xd0, 0x10, 0xba, 0x15, 0x16, 0xb8, 0x94, 0x1e, 0x38,
|
||||
0x02, 0xc7, 0x5b, 0x27, 0xbb, 0xe1, 0xbd, 0x39, 0xe1, 0xb9, 0x46, 0x67, 0x9b, 0xb7, 0x3f, 0x07,
|
||||
0x4e, 0x6c, 0x1b, 0x83, 0xef, 0x00, 0xba, 0x06, 0xa0, 0x10, 0x76, 0x4b, 0xa2, 0x72, 0x9e, 0x36,
|
||||
0xf2, 0xbd, 0x07, 0xf2, 0x77, 0x86, 0xc5, 0x4d, 0x13, 0x7a, 0x09, 0x5d, 0x99, 0xf0, 0x8a, 0x48,
|
||||
0xaf, 0xb3, 0x66, 0xda, 0x85, 0x46, 0xb1, 0x6d, 0xa9, 0xcd, 0x13, 0x3c, 0x23, 0x58, 0x49, 0x6f,
|
||||
0x63, 0x8d, 0xf9, 0x6b, 0xc3, 0xe2, 0xa6, 0x69, 0x74, 0xf8, 0xf5, 0x66, 0xe0, 0xfc, 0xb9, 0x19,
|
||||
0x80, 0x4f, 0xbf, 0xbf, 0xbd, 0xd8, 0x69, 0x5f, 0xd2, 0xa6, 0xfe, 0x00, 0xbb, 0x36, 0x0e, 0xf2,
|
||||
0x60, 0x37, 0x25, 0x57, 0x78, 0x5a, 0x28, 0x9d, 0xba, 0x17, 0x37, 0x57, 0x74, 0x08, 0x7b, 0x72,
|
||||
0x5a, 0x55, 0x5c, 0x28, 0x92, 0x7a, 0x9d, 0xa3, 0x8d, 0xe3, 0x5e, 0xbc, 0x2a, 0x8c, 0x0e, 0x1a,
|
||||
0xf3, 0xa7, 0xad, 0xb9, 0x5d, 0x2c, 0x18, 0x43, 0xd7, 0xa4, 0x47, 0x08, 0x6e, 0x4e, 0xb0, 0x24,
|
||||
0xd6, 0x59, 0x9f, 0x1f, 0xb1, 0xf5, 0xfe, 0xcf, 0x6c, 0x5e, 0x20, 0xf8, 0x0c, 0x60, 0xd7, 0xae,
|
||||
0x89, 0x4e, 0xe0, 0x7e, 0x2b, 0xb9, 0xbc, 0xa2, 0x42, 0xaa, 0xcb, 0x0a, 0x0b, 0x35, 0xf7, 0x80,
|
||||
0xf6, 0xdb, 0x6d, 0xe1, 0x9b, 0x9a, 0x9d, 0xd7, 0xe8, 0xa1, 0x46, 0xe5, 0x54, 0xa4, 0x56, 0xd3,
|
||||
0xf9, 0x47, 0x33, 0xae, 0x99, 0xd6, 0xac, 0x5b, 0xd2, 0x3e, 0x70, 0x90, 0xc3, 0xed, 0xb1, 0xc0,
|
||||
0x4c, 0xe2, 0x44, 0x51, 0xce, 0x64, 0xbd, 0x16, 0x2e, 0x0a, 0xfe, 0xb1, 0xa0, 0x52, 0xd9, 0x18,
|
||||
0xab, 0x02, 0xea, 0xc3, 0x27, 0x29, 0x61, 0x73, 0x0d, 0xcd, 0xbc, 0xf6, 0x3e, 0xf2, 0x9b, 0x21,
|
||||
0xfb, 0xed, 0x10, 0x75, 0xcf, 0xf9, 0xec, 0xf4, 0x76, 0xe1, 0x83, 0xbb, 0x85, 0x0f, 0x7e, 0x2d,
|
||||
0x7c, 0xf0, 0x65, 0xe9, 0x3b, 0x77, 0x4b, 0xdf, 0xf9, 0xb1, 0xf4, 0x9d, 0xf7, 0xcf, 0x33, 0xaa,
|
||||
0xf2, 0xe9, 0x24, 0x4c, 0x78, 0x19, 0x71, 0x26, 0x39, 0x13, 0x91, 0xfe, 0x5c, 0x47, 0x2b, 0xa7,
|
||||
0x79, 0x45, 0xe4, 0xc4, 0xd5, 0xff, 0xfb, 0xab, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x19, 0xb5,
|
||||
0x2c, 0xe7, 0x53, 0x03, 0x00, 0x00,
|
||||
// 517 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0xcd, 0x6a, 0xdb, 0x40,
|
||||
0x10, 0xb6, 0xec, 0x20, 0x57, 0xe3, 0x40, 0xda, 0xcd, 0x0f, 0x8a, 0x09, 0xb2, 0xd1, 0xa5, 0xa1,
|
||||
0x05, 0x09, 0xb7, 0x37, 0xdf, 0x92, 0x42, 0x73, 0x2a, 0x84, 0x8d, 0x4f, 0xa1, 0x10, 0xd6, 0xd2,
|
||||
0xc6, 0x16, 0x58, 0x5a, 0xb1, 0xbb, 0x76, 0xe3, 0x57, 0xe8, 0xa9, 0xc7, 0x1e, 0xf3, 0x08, 0x85,
|
||||
0x42, 0x9f, 0x21, 0xc7, 0x1c, 0x7b, 0x2a, 0xc5, 0x3e, 0xb4, 0x8f, 0x51, 0xb4, 0xbb, 0x92, 0x1d,
|
||||
0x62, 0x68, 0x2e, 0xcb, 0xce, 0x7c, 0xf3, 0x7d, 0xf3, 0xed, 0x68, 0x04, 0x87, 0x29, 0x89, 0x08,
|
||||
0x67, 0x2c, 0x0b, 0x67, 0xbd, 0x70, 0x44, 0x33, 0x2a, 0x12, 0x11, 0xe4, 0x9c, 0x49, 0x86, 0x5a,
|
||||
0x25, 0x14, 0xcc, 0x7a, 0xed, 0x17, 0x24, 0x4d, 0x32, 0x16, 0xaa, 0x53, 0xe3, 0xed, 0x9d, 0x38,
|
||||
0x89, 0x0b, 0x96, 0xbc, 0x31, 0x89, 0xbd, 0x11, 0x1b, 0x31, 0x75, 0x0d, 0x8b, 0x9b, 0xce, 0xfa,
|
||||
0x27, 0xb0, 0x7d, 0xa6, 0x75, 0x2f, 0x24, 0x91, 0x14, 0xf5, 0xc0, 0xce, 0x09, 0x27, 0xa9, 0x70,
|
||||
0xad, 0xae, 0x75, 0xdc, 0x7a, 0xb3, 0x1b, 0xac, 0xf5, 0x09, 0xce, 0x15, 0x74, 0xba, 0x75, 0xf7,
|
||||
0xab, 0x53, 0xc3, 0xa6, 0xd0, 0xff, 0x6e, 0x81, 0xad, 0x01, 0x14, 0x40, 0x33, 0xa5, 0x72, 0xcc,
|
||||
0xe2, 0x92, 0xbe, 0xf7, 0x80, 0xfe, 0x41, 0x63, 0xb8, 0x2c, 0x42, 0xaf, 0xc1, 0x16, 0x11, 0xcb,
|
||||
0xa9, 0x70, 0xeb, 0x1b, 0xba, 0x5d, 0x28, 0x08, 0x9b, 0x92, 0x42, 0x3c, 0x22, 0x33, 0x4a, 0xa4,
|
||||
0x70, 0x1b, 0x1b, 0xc4, 0xdf, 0x69, 0x0c, 0x97, 0x45, 0xfd, 0xa3, 0xaf, 0xb7, 0x9d, 0xda, 0xdf,
|
||||
0xdb, 0x8e, 0xf5, 0xf9, 0xcf, 0xb7, 0x57, 0x3b, 0xd5, 0x24, 0x8d, 0xeb, 0x8f, 0xd0, 0x34, 0x76,
|
||||
0x90, 0x0b, 0xcd, 0x98, 0x5e, 0x93, 0xe9, 0x44, 0x2a, 0xd7, 0x0e, 0x2e, 0x43, 0x74, 0x04, 0x8e,
|
||||
0x98, 0xe6, 0x39, 0xe3, 0x92, 0xc6, 0x6e, 0xbd, 0xdb, 0x38, 0x76, 0xf0, 0x2a, 0xd1, 0x3f, 0x2c,
|
||||
0xc5, 0x9f, 0x57, 0xe2, 0xe6, 0x61, 0xfe, 0x00, 0x6c, 0xed, 0x1e, 0x21, 0xd8, 0x1a, 0x12, 0x41,
|
||||
0x8d, 0xb2, 0xba, 0xff, 0x47, 0xd6, 0x7d, 0xec, 0x59, 0x4f, 0xc0, 0xff, 0x61, 0x41, 0xd3, 0x3c,
|
||||
0x13, 0x9d, 0xc1, 0x7e, 0x45, 0xb9, 0xba, 0x4e, 0xb8, 0x90, 0x57, 0x39, 0xe1, 0x72, 0xee, 0x5a,
|
||||
0xdd, 0xc6, 0xa3, 0x49, 0x6a, 0x12, 0xde, 0xad, 0x18, 0xef, 0x0b, 0xc2, 0x79, 0x51, 0xff, 0x50,
|
||||
0x48, 0x8e, 0x13, 0x1e, 0x1b, 0xa1, 0xfa, 0x53, 0x84, 0x06, 0x05, 0x41, 0x09, 0x6d, 0x1a, 0x87,
|
||||
0xf9, 0x14, 0xfe, 0x18, 0xb6, 0x07, 0x9c, 0x64, 0x82, 0x44, 0x32, 0x61, 0x99, 0x28, 0x06, 0x40,
|
||||
0x26, 0x13, 0xf6, 0x69, 0x92, 0x08, 0xa9, 0x0c, 0x3b, 0x78, 0x95, 0x40, 0x6d, 0x78, 0x16, 0xd3,
|
||||
0x6c, 0xae, 0x40, 0x3d, 0x9d, 0x2a, 0xee, 0x7b, 0x65, 0x93, 0xfd, 0xaa, 0x89, 0x5c, 0x53, 0xf6,
|
||||
0x2f, 0xc1, 0xd6, 0x1e, 0xd1, 0x41, 0xb5, 0x5b, 0xba, 0x41, 0xb9, 0x46, 0x07, 0x60, 0x6b, 0x5b,
|
||||
0x6a, 0xe7, 0x1c, 0x6c, 0x22, 0xd4, 0x85, 0x56, 0x4c, 0x45, 0xc4, 0x93, 0xbc, 0x50, 0x52, 0x2b,
|
||||
0xe6, 0xe0, 0xf5, 0xd4, 0xe9, 0xc9, 0xdd, 0xc2, 0xb3, 0xee, 0x17, 0x9e, 0xf5, 0x7b, 0xe1, 0x59,
|
||||
0x5f, 0x96, 0x5e, 0xed, 0x7e, 0xe9, 0xd5, 0x7e, 0x2e, 0xbd, 0xda, 0xe5, 0xcb, 0x51, 0x22, 0xc7,
|
||||
0xd3, 0x61, 0x10, 0xb1, 0x34, 0x64, 0x99, 0x60, 0x19, 0x0f, 0xd5, 0x71, 0x13, 0xae, 0x5c, 0xce,
|
||||
0x73, 0x2a, 0x86, 0xb6, 0xfa, 0xeb, 0xde, 0xfe, 0x0b, 0x00, 0x00, 0xff, 0xff, 0x50, 0xa1, 0x26,
|
||||
0x49, 0xd9, 0x03, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (this *Params) Equal(that interface{}) bool {
|
||||
@@ -509,7 +573,7 @@ func (this *Caveats) Equal(that interface{}) bool {
|
||||
return false
|
||||
}
|
||||
for i := range this.SupportedFirstParty {
|
||||
if this.SupportedFirstParty[i] != that1.SupportedFirstParty[i] {
|
||||
if !this.SupportedFirstParty[i].Equal(that1.SupportedFirstParty[i]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -517,7 +581,7 @@ func (this *Caveats) Equal(that interface{}) bool {
|
||||
return false
|
||||
}
|
||||
for i := range this.SupportedThirdParty {
|
||||
if this.SupportedThirdParty[i] != that1.SupportedThirdParty[i] {
|
||||
if !this.SupportedThirdParty[i].Equal(that1.SupportedThirdParty[i]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -752,18 +816,28 @@ func (m *Caveats) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
_ = l
|
||||
if len(m.SupportedThirdParty) > 0 {
|
||||
for iNdEx := len(m.SupportedThirdParty) - 1; iNdEx >= 0; iNdEx-- {
|
||||
i -= len(m.SupportedThirdParty[iNdEx])
|
||||
copy(dAtA[i:], m.SupportedThirdParty[iNdEx])
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(len(m.SupportedThirdParty[iNdEx])))
|
||||
{
|
||||
size, err := m.SupportedThirdParty[iNdEx].MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
}
|
||||
}
|
||||
if len(m.SupportedFirstParty) > 0 {
|
||||
for iNdEx := len(m.SupportedFirstParty) - 1; iNdEx >= 0; iNdEx-- {
|
||||
i -= len(m.SupportedFirstParty[iNdEx])
|
||||
copy(dAtA[i:], m.SupportedFirstParty[iNdEx])
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(len(m.SupportedFirstParty[iNdEx])))
|
||||
{
|
||||
size, err := m.SupportedFirstParty[iNdEx].MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
@@ -812,6 +886,52 @@ func (m *Transactions) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func (m *Caveat) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *Caveat) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *Caveat) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.Description) > 0 {
|
||||
i -= len(m.Description)
|
||||
copy(dAtA[i:], m.Description)
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(len(m.Description)))
|
||||
i--
|
||||
dAtA[i] = 0x1a
|
||||
}
|
||||
if len(m.Caveat) > 0 {
|
||||
i -= len(m.Caveat)
|
||||
copy(dAtA[i:], m.Caveat)
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(len(m.Caveat)))
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
}
|
||||
if len(m.Scopes) > 0 {
|
||||
for iNdEx := len(m.Scopes) - 1; iNdEx >= 0; iNdEx-- {
|
||||
i -= len(m.Scopes[iNdEx])
|
||||
copy(dAtA[i:], m.Scopes[iNdEx])
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(len(m.Scopes[iNdEx])))
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int {
|
||||
offset -= sovGenesis(v)
|
||||
base := offset
|
||||
@@ -900,14 +1020,14 @@ func (m *Caveats) Size() (n int) {
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.SupportedFirstParty) > 0 {
|
||||
for _, s := range m.SupportedFirstParty {
|
||||
l = len(s)
|
||||
for _, e := range m.SupportedFirstParty {
|
||||
l = e.Size()
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
}
|
||||
}
|
||||
if len(m.SupportedThirdParty) > 0 {
|
||||
for _, s := range m.SupportedThirdParty {
|
||||
l = len(s)
|
||||
for _, e := range m.SupportedThirdParty {
|
||||
l = e.Size()
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
}
|
||||
}
|
||||
@@ -935,6 +1055,29 @@ func (m *Transactions) Size() (n int) {
|
||||
return n
|
||||
}
|
||||
|
||||
func (m *Caveat) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.Scopes) > 0 {
|
||||
for _, s := range m.Scopes {
|
||||
l = len(s)
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
}
|
||||
}
|
||||
l = len(m.Caveat)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
}
|
||||
l = len(m.Description)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func sovGenesis(x uint64) (n int) {
|
||||
return (math_bits.Len64(x|1) + 6) / 7
|
||||
}
|
||||
@@ -1443,7 +1586,7 @@ func (m *Caveats) Unmarshal(dAtA []byte) error {
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field SupportedFirstParty", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
var msglen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
@@ -1453,29 +1596,31 @@ func (m *Caveats) Unmarshal(dAtA []byte) error {
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
msglen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
if msglen < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
postIndex := iNdEx + msglen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.SupportedFirstParty = append(m.SupportedFirstParty, string(dAtA[iNdEx:postIndex]))
|
||||
m.SupportedFirstParty = append(m.SupportedFirstParty, &Caveat{})
|
||||
if err := m.SupportedFirstParty[len(m.SupportedFirstParty)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
case 2:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field SupportedThirdParty", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
var msglen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
@@ -1485,23 +1630,25 @@ func (m *Caveats) Unmarshal(dAtA []byte) error {
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
msglen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
if msglen < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
postIndex := iNdEx + msglen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.SupportedThirdParty = append(m.SupportedThirdParty, string(dAtA[iNdEx:postIndex]))
|
||||
m.SupportedThirdParty = append(m.SupportedThirdParty, &Caveat{})
|
||||
if err := m.SupportedThirdParty[len(m.SupportedThirdParty)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
@@ -1638,6 +1785,152 @@ func (m *Transactions) Unmarshal(dAtA []byte) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *Caveat) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: Caveat: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: Caveat: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Scopes", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Scopes = append(m.Scopes, string(dAtA[iNdEx:postIndex]))
|
||||
iNdEx = postIndex
|
||||
case 2:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Caveat", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Caveat = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
case 3:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Description = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipGenesis(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (skippy < 0) || (iNdEx+skippy) < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func skipGenesis(dAtA []byte) (n int, err error) {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
|
||||
@@ -45,8 +45,67 @@ func DefaultScopes() *Scopes {
|
||||
func DefaultCaveats() *Caveats {
|
||||
return &Caveats{
|
||||
// First party - JWT Format
|
||||
SupportedFirstParty: []string{"aud", "exp", "iat", "iss", "nbf", "nonce", "sub"},
|
||||
SupportedFirstParty: DefaultFirstPartyCaveats(),
|
||||
// Third party - UCAN Format
|
||||
SupportedThirdParty: []string{"cap", "nbf", "exp", "att", "prf", "rmt", "sig", "ucv"},
|
||||
SupportedThirdParty: DefaultThirdPartyCaveats(),
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultFirstPartyCaveats() []*Caveat {
|
||||
return []*Caveat{
|
||||
{
|
||||
Scopes: []string{"openid", "profile", "sonr.address"},
|
||||
Caveat: "aud",
|
||||
Description: "Audience must be a valid DID",
|
||||
},
|
||||
{
|
||||
Scopes: []string{"openid", "profile", "sonr.address"},
|
||||
Caveat: "exp",
|
||||
Description: "Expiration time must be a valid timestamp",
|
||||
},
|
||||
{
|
||||
Scopes: []string{"openid", "profile", "sonr.address"},
|
||||
Caveat: "iat",
|
||||
Description: "Issued at time must be a valid timestamp",
|
||||
},
|
||||
{
|
||||
Scopes: []string{"openid", "profile", "sonr.address"},
|
||||
Caveat: "iss",
|
||||
Description: "Issuer must be a valid DID",
|
||||
},
|
||||
{
|
||||
Scopes: []string{"openid", "profile", "sonr.address"},
|
||||
Caveat: "nbf",
|
||||
Description: "Not before time must be a valid timestamp",
|
||||
},
|
||||
{
|
||||
Scopes: []string{"openid", "profile", "sonr.address"},
|
||||
Caveat: "nonce",
|
||||
Description: "Nonce must be a valid string",
|
||||
},
|
||||
{
|
||||
Scopes: []string{"openid", "profile", "sonr.address"},
|
||||
Caveat: "sub",
|
||||
Description: "Subject must be a valid DID",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultThirdPartyCaveats() []*Caveat {
|
||||
return []*Caveat{
|
||||
{
|
||||
Scopes: []string{"create", "read", "update", "delete", "sign", "verify", "simulate", "execute", "broadcast", "admin"},
|
||||
Caveat: "cap",
|
||||
Description: "Capability must be a valid capability",
|
||||
},
|
||||
{
|
||||
Scopes: []string{"create", "read", "update", "delete", "sign", "verify", "simulate", "execute", "broadcast", "admin"},
|
||||
Caveat: "exp",
|
||||
Description: "Expiration time must be a valid timestamp",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Caveat) Equal(other *Caveat) bool {
|
||||
return c.Caveat == other.Caveat
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user