feature/1110 abstract connected wallet operations (#1166)

- **refactor: refactor DID module types and move to controller package**
- **refactor: move controller creation and resolution logic to keeper**
- **refactor: update imports to reflect controller package move**
- **refactor: update protobuf definitions for DID module**
- **docs: update proto README to reflect changes**
- **refactor: move hway to gateway, update node modules, and refactor
pkl generation**
- **build: update pkl-gen task to use new pkl file paths**
- **refactor: refactor DWN WASM build and deployment process**
- **refactor: refactor DID controller implementation to use
account-based storage**
- **refactor: move DID controller interface to base file and update
implementation**
- **chore: migrate to google protobuf**
- **feat: Add v0.52.0 Interfaces for Acc Abstraction**
- **refactor: replace public_key with public_key_hex in Assertion
message**
- **refactor: remove unused PubKey, JSONWebKey, and RawKey message types
and related code**
This commit is contained in:
Prad Nukala
2024-11-18 19:04:10 -05:00
committed by GitHub
parent 01cb37e82e
commit bf94277b0f
190 changed files with 9345 additions and 14038 deletions
+179 -358
View File
@@ -323,6 +323,173 @@ func NewAuthenticationTable(db ormtable.Schema) (AuthenticationTable, error) {
return authenticationTable{table}, nil
}
type BiscuitTable interface {
Insert(ctx context.Context, biscuit *Biscuit) error
InsertReturningId(ctx context.Context, biscuit *Biscuit) (uint64, error)
LastInsertedSequence(ctx context.Context) (uint64, error)
Update(ctx context.Context, biscuit *Biscuit) error
Save(ctx context.Context, biscuit *Biscuit) error
Delete(ctx context.Context, biscuit *Biscuit) error
Has(ctx context.Context, id uint64) (found bool, err error)
// Get returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found.
Get(ctx context.Context, id uint64) (*Biscuit, error)
HasBySubjectOrigin(ctx context.Context, subject string, origin string) (found bool, err error)
// GetBySubjectOrigin returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found.
GetBySubjectOrigin(ctx context.Context, subject string, origin string) (*Biscuit, error)
List(ctx context.Context, prefixKey BiscuitIndexKey, opts ...ormlist.Option) (BiscuitIterator, error)
ListRange(ctx context.Context, from, to BiscuitIndexKey, opts ...ormlist.Option) (BiscuitIterator, error)
DeleteBy(ctx context.Context, prefixKey BiscuitIndexKey) error
DeleteRange(ctx context.Context, from, to BiscuitIndexKey) error
doNotImplement()
}
type BiscuitIterator struct {
ormtable.Iterator
}
func (i BiscuitIterator) Value() (*Biscuit, error) {
var biscuit Biscuit
err := i.UnmarshalMessage(&biscuit)
return &biscuit, err
}
type BiscuitIndexKey interface {
id() uint32
values() []interface{}
biscuitIndexKey()
}
// primary key starting index..
type BiscuitPrimaryKey = BiscuitIdIndexKey
type BiscuitIdIndexKey struct {
vs []interface{}
}
func (x BiscuitIdIndexKey) id() uint32 { return 0 }
func (x BiscuitIdIndexKey) values() []interface{} { return x.vs }
func (x BiscuitIdIndexKey) biscuitIndexKey() {}
func (this BiscuitIdIndexKey) WithId(id uint64) BiscuitIdIndexKey {
this.vs = []interface{}{id}
return this
}
type BiscuitSubjectOriginIndexKey struct {
vs []interface{}
}
func (x BiscuitSubjectOriginIndexKey) id() uint32 { return 1 }
func (x BiscuitSubjectOriginIndexKey) values() []interface{} { return x.vs }
func (x BiscuitSubjectOriginIndexKey) biscuitIndexKey() {}
func (this BiscuitSubjectOriginIndexKey) WithSubject(subject string) BiscuitSubjectOriginIndexKey {
this.vs = []interface{}{subject}
return this
}
func (this BiscuitSubjectOriginIndexKey) WithSubjectOrigin(subject string, origin string) BiscuitSubjectOriginIndexKey {
this.vs = []interface{}{subject, origin}
return this
}
type biscuitTable struct {
table ormtable.AutoIncrementTable
}
func (this biscuitTable) Insert(ctx context.Context, biscuit *Biscuit) error {
return this.table.Insert(ctx, biscuit)
}
func (this biscuitTable) Update(ctx context.Context, biscuit *Biscuit) error {
return this.table.Update(ctx, biscuit)
}
func (this biscuitTable) Save(ctx context.Context, biscuit *Biscuit) error {
return this.table.Save(ctx, biscuit)
}
func (this biscuitTable) Delete(ctx context.Context, biscuit *Biscuit) error {
return this.table.Delete(ctx, biscuit)
}
func (this biscuitTable) InsertReturningId(ctx context.Context, biscuit *Biscuit) (uint64, error) {
return this.table.InsertReturningPKey(ctx, biscuit)
}
func (this biscuitTable) LastInsertedSequence(ctx context.Context) (uint64, error) {
return this.table.LastInsertedSequence(ctx)
}
func (this biscuitTable) Has(ctx context.Context, id uint64) (found bool, err error) {
return this.table.PrimaryKey().Has(ctx, id)
}
func (this biscuitTable) Get(ctx context.Context, id uint64) (*Biscuit, error) {
var biscuit Biscuit
found, err := this.table.PrimaryKey().Get(ctx, &biscuit, id)
if err != nil {
return nil, err
}
if !found {
return nil, ormerrors.NotFound
}
return &biscuit, nil
}
func (this biscuitTable) HasBySubjectOrigin(ctx context.Context, subject string, origin string) (found bool, err error) {
return this.table.GetIndexByID(1).(ormtable.UniqueIndex).Has(ctx,
subject,
origin,
)
}
func (this biscuitTable) GetBySubjectOrigin(ctx context.Context, subject string, origin string) (*Biscuit, error) {
var biscuit Biscuit
found, err := this.table.GetIndexByID(1).(ormtable.UniqueIndex).Get(ctx, &biscuit,
subject,
origin,
)
if err != nil {
return nil, err
}
if !found {
return nil, ormerrors.NotFound
}
return &biscuit, nil
}
func (this biscuitTable) List(ctx context.Context, prefixKey BiscuitIndexKey, opts ...ormlist.Option) (BiscuitIterator, error) {
it, err := this.table.GetIndexByID(prefixKey.id()).List(ctx, prefixKey.values(), opts...)
return BiscuitIterator{it}, err
}
func (this biscuitTable) ListRange(ctx context.Context, from, to BiscuitIndexKey, opts ...ormlist.Option) (BiscuitIterator, error) {
it, err := this.table.GetIndexByID(from.id()).ListRange(ctx, from.values(), to.values(), opts...)
return BiscuitIterator{it}, err
}
func (this biscuitTable) DeleteBy(ctx context.Context, prefixKey BiscuitIndexKey) error {
return this.table.GetIndexByID(prefixKey.id()).DeleteBy(ctx, prefixKey.values()...)
}
func (this biscuitTable) DeleteRange(ctx context.Context, from, to BiscuitIndexKey) error {
return this.table.GetIndexByID(from.id()).DeleteRange(ctx, from.values(), to.values())
}
func (this biscuitTable) doNotImplement() {}
var _ BiscuitTable = biscuitTable{}
func NewBiscuitTable(db ormtable.Schema) (BiscuitTable, error) {
table := db.GetTable(&Biscuit{})
if table == nil {
return nil, ormerrors.TableNotFound.Wrap(string((&Biscuit{}).ProtoReflect().Descriptor().FullName()))
}
return biscuitTable{table.(ormtable.AutoIncrementTable)}, nil
}
type ControllerTable interface {
Insert(ctx context.Context, controller *Controller) error
InsertReturningNumber(ctx context.Context, controller *Controller) (uint64, error)
@@ -591,340 +758,6 @@ func NewControllerTable(db ormtable.Schema) (ControllerTable, error) {
return controllerTable{table.(ormtable.AutoIncrementTable)}, nil
}
type GrantTable interface {
Insert(ctx context.Context, grant *Grant) error
InsertReturningId(ctx context.Context, grant *Grant) (uint64, error)
LastInsertedSequence(ctx context.Context) (uint64, error)
Update(ctx context.Context, grant *Grant) error
Save(ctx context.Context, grant *Grant) error
Delete(ctx context.Context, grant *Grant) error
Has(ctx context.Context, id uint64) (found bool, err error)
// Get returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found.
Get(ctx context.Context, id uint64) (*Grant, error)
HasBySubjectOrigin(ctx context.Context, subject string, origin string) (found bool, err error)
// GetBySubjectOrigin returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found.
GetBySubjectOrigin(ctx context.Context, subject string, origin string) (*Grant, error)
List(ctx context.Context, prefixKey GrantIndexKey, opts ...ormlist.Option) (GrantIterator, error)
ListRange(ctx context.Context, from, to GrantIndexKey, opts ...ormlist.Option) (GrantIterator, error)
DeleteBy(ctx context.Context, prefixKey GrantIndexKey) error
DeleteRange(ctx context.Context, from, to GrantIndexKey) error
doNotImplement()
}
type GrantIterator struct {
ormtable.Iterator
}
func (i GrantIterator) Value() (*Grant, error) {
var grant Grant
err := i.UnmarshalMessage(&grant)
return &grant, err
}
type GrantIndexKey interface {
id() uint32
values() []interface{}
grantIndexKey()
}
// primary key starting index..
type GrantPrimaryKey = GrantIdIndexKey
type GrantIdIndexKey struct {
vs []interface{}
}
func (x GrantIdIndexKey) id() uint32 { return 0 }
func (x GrantIdIndexKey) values() []interface{} { return x.vs }
func (x GrantIdIndexKey) grantIndexKey() {}
func (this GrantIdIndexKey) WithId(id uint64) GrantIdIndexKey {
this.vs = []interface{}{id}
return this
}
type GrantSubjectOriginIndexKey struct {
vs []interface{}
}
func (x GrantSubjectOriginIndexKey) id() uint32 { return 1 }
func (x GrantSubjectOriginIndexKey) values() []interface{} { return x.vs }
func (x GrantSubjectOriginIndexKey) grantIndexKey() {}
func (this GrantSubjectOriginIndexKey) WithSubject(subject string) GrantSubjectOriginIndexKey {
this.vs = []interface{}{subject}
return this
}
func (this GrantSubjectOriginIndexKey) WithSubjectOrigin(subject string, origin string) GrantSubjectOriginIndexKey {
this.vs = []interface{}{subject, origin}
return this
}
type grantTable struct {
table ormtable.AutoIncrementTable
}
func (this grantTable) Insert(ctx context.Context, grant *Grant) error {
return this.table.Insert(ctx, grant)
}
func (this grantTable) Update(ctx context.Context, grant *Grant) error {
return this.table.Update(ctx, grant)
}
func (this grantTable) Save(ctx context.Context, grant *Grant) error {
return this.table.Save(ctx, grant)
}
func (this grantTable) Delete(ctx context.Context, grant *Grant) error {
return this.table.Delete(ctx, grant)
}
func (this grantTable) InsertReturningId(ctx context.Context, grant *Grant) (uint64, error) {
return this.table.InsertReturningPKey(ctx, grant)
}
func (this grantTable) LastInsertedSequence(ctx context.Context) (uint64, error) {
return this.table.LastInsertedSequence(ctx)
}
func (this grantTable) Has(ctx context.Context, id uint64) (found bool, err error) {
return this.table.PrimaryKey().Has(ctx, id)
}
func (this grantTable) Get(ctx context.Context, id uint64) (*Grant, error) {
var grant Grant
found, err := this.table.PrimaryKey().Get(ctx, &grant, id)
if err != nil {
return nil, err
}
if !found {
return nil, ormerrors.NotFound
}
return &grant, nil
}
func (this grantTable) HasBySubjectOrigin(ctx context.Context, subject string, origin string) (found bool, err error) {
return this.table.GetIndexByID(1).(ormtable.UniqueIndex).Has(ctx,
subject,
origin,
)
}
func (this grantTable) GetBySubjectOrigin(ctx context.Context, subject string, origin string) (*Grant, error) {
var grant Grant
found, err := this.table.GetIndexByID(1).(ormtable.UniqueIndex).Get(ctx, &grant,
subject,
origin,
)
if err != nil {
return nil, err
}
if !found {
return nil, ormerrors.NotFound
}
return &grant, nil
}
func (this grantTable) List(ctx context.Context, prefixKey GrantIndexKey, opts ...ormlist.Option) (GrantIterator, error) {
it, err := this.table.GetIndexByID(prefixKey.id()).List(ctx, prefixKey.values(), opts...)
return GrantIterator{it}, err
}
func (this grantTable) ListRange(ctx context.Context, from, to GrantIndexKey, opts ...ormlist.Option) (GrantIterator, error) {
it, err := this.table.GetIndexByID(from.id()).ListRange(ctx, from.values(), to.values(), opts...)
return GrantIterator{it}, err
}
func (this grantTable) DeleteBy(ctx context.Context, prefixKey GrantIndexKey) error {
return this.table.GetIndexByID(prefixKey.id()).DeleteBy(ctx, prefixKey.values()...)
}
func (this grantTable) DeleteRange(ctx context.Context, from, to GrantIndexKey) error {
return this.table.GetIndexByID(from.id()).DeleteRange(ctx, from.values(), to.values())
}
func (this grantTable) doNotImplement() {}
var _ GrantTable = grantTable{}
func NewGrantTable(db ormtable.Schema) (GrantTable, error) {
table := db.GetTable(&Grant{})
if table == nil {
return nil, ormerrors.TableNotFound.Wrap(string((&Grant{}).ProtoReflect().Descriptor().FullName()))
}
return grantTable{table.(ormtable.AutoIncrementTable)}, nil
}
type MacaroonTable interface {
Insert(ctx context.Context, macaroon *Macaroon) error
InsertReturningId(ctx context.Context, macaroon *Macaroon) (uint64, error)
LastInsertedSequence(ctx context.Context) (uint64, error)
Update(ctx context.Context, macaroon *Macaroon) error
Save(ctx context.Context, macaroon *Macaroon) error
Delete(ctx context.Context, macaroon *Macaroon) error
Has(ctx context.Context, id uint64) (found bool, err error)
// Get returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found.
Get(ctx context.Context, id uint64) (*Macaroon, error)
HasBySubjectOrigin(ctx context.Context, subject string, origin string) (found bool, err error)
// GetBySubjectOrigin returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found.
GetBySubjectOrigin(ctx context.Context, subject string, origin string) (*Macaroon, error)
List(ctx context.Context, prefixKey MacaroonIndexKey, opts ...ormlist.Option) (MacaroonIterator, error)
ListRange(ctx context.Context, from, to MacaroonIndexKey, opts ...ormlist.Option) (MacaroonIterator, error)
DeleteBy(ctx context.Context, prefixKey MacaroonIndexKey) error
DeleteRange(ctx context.Context, from, to MacaroonIndexKey) error
doNotImplement()
}
type MacaroonIterator struct {
ormtable.Iterator
}
func (i MacaroonIterator) Value() (*Macaroon, error) {
var macaroon Macaroon
err := i.UnmarshalMessage(&macaroon)
return &macaroon, err
}
type MacaroonIndexKey interface {
id() uint32
values() []interface{}
macaroonIndexKey()
}
// primary key starting index..
type MacaroonPrimaryKey = MacaroonIdIndexKey
type MacaroonIdIndexKey struct {
vs []interface{}
}
func (x MacaroonIdIndexKey) id() uint32 { return 0 }
func (x MacaroonIdIndexKey) values() []interface{} { return x.vs }
func (x MacaroonIdIndexKey) macaroonIndexKey() {}
func (this MacaroonIdIndexKey) WithId(id uint64) MacaroonIdIndexKey {
this.vs = []interface{}{id}
return this
}
type MacaroonSubjectOriginIndexKey struct {
vs []interface{}
}
func (x MacaroonSubjectOriginIndexKey) id() uint32 { return 1 }
func (x MacaroonSubjectOriginIndexKey) values() []interface{} { return x.vs }
func (x MacaroonSubjectOriginIndexKey) macaroonIndexKey() {}
func (this MacaroonSubjectOriginIndexKey) WithSubject(subject string) MacaroonSubjectOriginIndexKey {
this.vs = []interface{}{subject}
return this
}
func (this MacaroonSubjectOriginIndexKey) WithSubjectOrigin(subject string, origin string) MacaroonSubjectOriginIndexKey {
this.vs = []interface{}{subject, origin}
return this
}
type macaroonTable struct {
table ormtable.AutoIncrementTable
}
func (this macaroonTable) Insert(ctx context.Context, macaroon *Macaroon) error {
return this.table.Insert(ctx, macaroon)
}
func (this macaroonTable) Update(ctx context.Context, macaroon *Macaroon) error {
return this.table.Update(ctx, macaroon)
}
func (this macaroonTable) Save(ctx context.Context, macaroon *Macaroon) error {
return this.table.Save(ctx, macaroon)
}
func (this macaroonTable) Delete(ctx context.Context, macaroon *Macaroon) error {
return this.table.Delete(ctx, macaroon)
}
func (this macaroonTable) InsertReturningId(ctx context.Context, macaroon *Macaroon) (uint64, error) {
return this.table.InsertReturningPKey(ctx, macaroon)
}
func (this macaroonTable) LastInsertedSequence(ctx context.Context) (uint64, error) {
return this.table.LastInsertedSequence(ctx)
}
func (this macaroonTable) Has(ctx context.Context, id uint64) (found bool, err error) {
return this.table.PrimaryKey().Has(ctx, id)
}
func (this macaroonTable) Get(ctx context.Context, id uint64) (*Macaroon, error) {
var macaroon Macaroon
found, err := this.table.PrimaryKey().Get(ctx, &macaroon, id)
if err != nil {
return nil, err
}
if !found {
return nil, ormerrors.NotFound
}
return &macaroon, nil
}
func (this macaroonTable) HasBySubjectOrigin(ctx context.Context, subject string, origin string) (found bool, err error) {
return this.table.GetIndexByID(1).(ormtable.UniqueIndex).Has(ctx,
subject,
origin,
)
}
func (this macaroonTable) GetBySubjectOrigin(ctx context.Context, subject string, origin string) (*Macaroon, error) {
var macaroon Macaroon
found, err := this.table.GetIndexByID(1).(ormtable.UniqueIndex).Get(ctx, &macaroon,
subject,
origin,
)
if err != nil {
return nil, err
}
if !found {
return nil, ormerrors.NotFound
}
return &macaroon, nil
}
func (this macaroonTable) List(ctx context.Context, prefixKey MacaroonIndexKey, opts ...ormlist.Option) (MacaroonIterator, error) {
it, err := this.table.GetIndexByID(prefixKey.id()).List(ctx, prefixKey.values(), opts...)
return MacaroonIterator{it}, err
}
func (this macaroonTable) ListRange(ctx context.Context, from, to MacaroonIndexKey, opts ...ormlist.Option) (MacaroonIterator, error) {
it, err := this.table.GetIndexByID(from.id()).ListRange(ctx, from.values(), to.values(), opts...)
return MacaroonIterator{it}, err
}
func (this macaroonTable) DeleteBy(ctx context.Context, prefixKey MacaroonIndexKey) error {
return this.table.GetIndexByID(prefixKey.id()).DeleteBy(ctx, prefixKey.values()...)
}
func (this macaroonTable) DeleteRange(ctx context.Context, from, to MacaroonIndexKey) error {
return this.table.GetIndexByID(from.id()).DeleteRange(ctx, from.values(), to.values())
}
func (this macaroonTable) doNotImplement() {}
var _ MacaroonTable = macaroonTable{}
func NewMacaroonTable(db ormtable.Schema) (MacaroonTable, error) {
table := db.GetTable(&Macaroon{})
if table == nil {
return nil, ormerrors.TableNotFound.Wrap(string((&Macaroon{}).ProtoReflect().Descriptor().FullName()))
}
return macaroonTable{table.(ormtable.AutoIncrementTable)}, nil
}
type VerificationTable interface {
Insert(ctx context.Context, verification *Verification) error
Update(ctx context.Context, verification *Verification) error
@@ -1185,9 +1018,8 @@ func NewVerificationTable(db ormtable.Schema) (VerificationTable, error) {
type StateStore interface {
AssertionTable() AssertionTable
AuthenticationTable() AuthenticationTable
BiscuitTable() BiscuitTable
ControllerTable() ControllerTable
GrantTable() GrantTable
MacaroonTable() MacaroonTable
VerificationTable() VerificationTable
doNotImplement()
@@ -1196,9 +1028,8 @@ type StateStore interface {
type stateStore struct {
assertion AssertionTable
authentication AuthenticationTable
biscuit BiscuitTable
controller ControllerTable
grant GrantTable
macaroon MacaroonTable
verification VerificationTable
}
@@ -1210,18 +1041,14 @@ func (x stateStore) AuthenticationTable() AuthenticationTable {
return x.authentication
}
func (x stateStore) BiscuitTable() BiscuitTable {
return x.biscuit
}
func (x stateStore) ControllerTable() ControllerTable {
return x.controller
}
func (x stateStore) GrantTable() GrantTable {
return x.grant
}
func (x stateStore) MacaroonTable() MacaroonTable {
return x.macaroon
}
func (x stateStore) VerificationTable() VerificationTable {
return x.verification
}
@@ -1241,21 +1068,16 @@ func NewStateStore(db ormtable.Schema) (StateStore, error) {
return nil, err
}
biscuitTable, err := NewBiscuitTable(db)
if err != nil {
return nil, err
}
controllerTable, err := NewControllerTable(db)
if err != nil {
return nil, err
}
grantTable, err := NewGrantTable(db)
if err != nil {
return nil, err
}
macaroonTable, err := NewMacaroonTable(db)
if err != nil {
return nil, err
}
verificationTable, err := NewVerificationTable(db)
if err != nil {
return nil, err
@@ -1264,9 +1086,8 @@ func NewStateStore(db ormtable.Schema) (StateStore, error) {
return stateStore{
assertionTable,
authenticationTable,
biscuitTable,
controllerTable,
grantTable,
macaroonTable,
verificationTable,
}, nil
}