diff --git a/context.go b/context.go index 3d263de..e48e6d2 100644 --- a/context.go +++ b/context.go @@ -1240,6 +1240,11 @@ func NewContext(db * badger.DB, log Logger) (*Context, error) { return nil, err } + err = ctx.RegisterNodeType(BaseNodeType, []ExtType{}) + if err != nil { + return nil, err + } + err = ctx.RegisterNodeType(GQLNodeType, []ExtType{GroupExtType, GQLExtType}) if err != nil { return nil, err diff --git a/gql.go b/gql.go index 1b12b18..4c064a1 100644 --- a/gql.go +++ b/gql.go @@ -31,6 +31,25 @@ import ( "github.com/google/uuid" ) +func AuthorizationHeader(node *Node) (string, error) { + key_ser, err := x509.MarshalPKCS8PrivateKey(node.Key) + if err != nil { + return "", err + } + + id_bytes, err := node.ID.MarshalBinary() + if err != nil { + return "", err + } + id_str := base64.StdEncoding.EncodeToString(id_bytes) + key_str := base64.StdEncoding.EncodeToString(key_ser) + + bytes := append([]byte(id_str), ':') + bytes = append(bytes, []byte(key_str)...) + + return base64.StdEncoding.EncodeToString(bytes), nil +} + func NodeInterfaceDefaultIsType(required_extensions []ExtType) func(graphql.IsTypeOfParams) bool { return func(p graphql.IsTypeOfParams) bool { ctx, ok := p.Context.Value("resolve").(*ResolveContext) diff --git a/serialize.go b/serialize.go index 94338d8..4112469 100644 --- a/serialize.go +++ b/serialize.go @@ -85,6 +85,7 @@ var ( GroupExtType = NewExtType("GROUP") GQLNodeType = NewNodeType("GQL") + BaseNodeType = NewNodeType("BASE") StopSignalType = NewSignalType("STOP") CreateSignalType = NewSignalType("CREATE")