token: ditch the generic bundle in favor of specialized struct
It's kust cleaner that way, the generic has no upside.
This commit is contained in:
@@ -217,7 +217,6 @@ func (g *generator) writeGoFile() error {
|
||||
Println("import (")
|
||||
Println("\t\"github.com/ipfs/go-cid\"")
|
||||
Println()
|
||||
Println("\t\"github.com/ucan-wg/go-ucan/token\"")
|
||||
Println("\t\"github.com/ucan-wg/go-ucan/token/delegation\"")
|
||||
Println(")")
|
||||
|
||||
@@ -243,7 +242,7 @@ func (g *generator) writeGoFile() error {
|
||||
Println("}")
|
||||
|
||||
Println()
|
||||
Println("var AllBundles = []token.Bundle[*delegation.Token]{")
|
||||
Println("var AllBundles = []delegation.Bundle{")
|
||||
for _, d := range g.dlgs {
|
||||
Printf("\t%sBundle,\n", d.name)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/ipfs/go-cid"
|
||||
|
||||
"github.com/ucan-wg/go-ucan/pkg/command"
|
||||
"github.com/ucan-wg/go-ucan/token"
|
||||
"github.com/ucan-wg/go-ucan/token/delegation"
|
||||
)
|
||||
|
||||
@@ -39,7 +38,7 @@ var fs embed.FS
|
||||
var _ delegation.Loader = (*DelegationLoader)(nil)
|
||||
|
||||
type DelegationLoader struct {
|
||||
bundles map[cid.Cid]token.Bundle[*delegation.Token]
|
||||
bundles map[cid.Cid]delegation.Bundle
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -76,7 +75,7 @@ func loadDelegations() (*DelegationLoader, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bundles := make(map[cid.Cid]token.Bundle[*delegation.Token], len(dirEntries))
|
||||
bundles := make(map[cid.Cid]delegation.Bundle, len(dirEntries))
|
||||
|
||||
for _, dirEntry := range dirEntries {
|
||||
data, err := fs.ReadFile(filepath.Join(TokenDir, dirEntry.Name()))
|
||||
@@ -89,7 +88,7 @@ func loadDelegations() (*DelegationLoader, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bundles[id] = token.Bundle[*delegation.Token]{Cid: id, Decoded: tkn, Sealed: data}
|
||||
bundles[id] = delegation.Bundle{Cid: id, Decoded: tkn, Sealed: data}
|
||||
}
|
||||
|
||||
return &DelegationLoader{
|
||||
@@ -107,7 +106,7 @@ func CidToName(id cid.Cid) string {
|
||||
return cidToName[id]
|
||||
}
|
||||
|
||||
func mustGetBundle(id cid.Cid) token.Bundle[*delegation.Token] {
|
||||
func mustGetBundle(id cid.Cid) delegation.Bundle {
|
||||
bundle, ok := GetDelegationLoader().bundles[id]
|
||||
if !ok {
|
||||
panic(delegation.ErrDelegationNotFound)
|
||||
|
||||
@@ -5,7 +5,6 @@ package delegationtest
|
||||
import (
|
||||
"github.com/ipfs/go-cid"
|
||||
|
||||
"github.com/ucan-wg/go-ucan/token"
|
||||
"github.com/ucan-wg/go-ucan/token/delegation"
|
||||
)
|
||||
|
||||
@@ -196,7 +195,7 @@ var AllTokens = []*delegation.Token{
|
||||
TokenErinFrank_ValidExamplePolicy,
|
||||
}
|
||||
|
||||
var AllBundles = []token.Bundle[*delegation.Token]{
|
||||
var AllBundles = []delegation.Bundle{
|
||||
TokenAliceBobBundle,
|
||||
TokenBobCarolBundle,
|
||||
TokenCarolDanBundle,
|
||||
|
||||
@@ -15,3 +15,10 @@ type Loader interface {
|
||||
// If not found, ErrDelegationNotFound is returned.
|
||||
GetDelegation(cid cid.Cid) (*Token, error)
|
||||
}
|
||||
|
||||
// Bundle carries together a decoded token with its Cid and raw signed data.
|
||||
type Bundle struct {
|
||||
Cid cid.Cid
|
||||
Decoded *Token
|
||||
Sealed []byte
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ type Marshaller interface {
|
||||
}
|
||||
|
||||
// Bundle carries together a decoded token with its Cid and raw signed data.
|
||||
type Bundle[T Token] struct {
|
||||
type Bundle struct {
|
||||
Cid cid.Cid
|
||||
Decoded T
|
||||
Decoded Token
|
||||
Sealed []byte
|
||||
}
|
||||
|
||||
10
token/invocation/utilities.go
Normal file
10
token/invocation/utilities.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package invocation
|
||||
|
||||
import "github.com/ipfs/go-cid"
|
||||
|
||||
// Bundle carries together a decoded token with its Cid and raw signed data.
|
||||
type Bundle struct {
|
||||
Cid cid.Cid
|
||||
Decoded *Token
|
||||
Sealed []byte
|
||||
}
|
||||
Reference in New Issue
Block a user