Files
ucan/token/invocation/schema.go

86 lines
1.8 KiB
Go
Raw Permalink Normal View History

2024-10-02 10:53:30 +02:00
package invocation
import (
_ "embed"
"fmt"
"sync"
"github.com/ipfs/go-cid"
2024-10-02 10:53:30 +02:00
"github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/node/bindnode"
"github.com/ipld/go-ipld-prime/schema"
"code.sonr.org/go/ucan/pkg/args"
"code.sonr.org/go/ucan/pkg/meta"
"code.sonr.org/go/ucan/token/internal/envelope"
2024-10-02 10:53:30 +02:00
)
// [Tag] is the string used as a key within the SigPayload that identifies
// that the TokenPayload is an invocation.
//
// [Tag]: https://github.com/ucan-wg/invocation#type-tag
const Tag = "ucan/inv@1.0.0-rc.1"
//go:embed invocation.ipldsch
var schemaBytes []byte
var (
once sync.Once
ts *schema.TypeSystem
errSchema error
2024-10-02 10:53:30 +02:00
)
func mustLoadSchema() *schema.TypeSystem {
once.Do(func() {
ts, errSchema = ipld.LoadSchemaBytes(schemaBytes)
2024-10-02 10:53:30 +02:00
})
if errSchema != nil {
panic(fmt.Errorf("failed to load IPLD schema: %s", errSchema))
2024-10-02 10:53:30 +02:00
}
return ts
}
func payloadType() schema.Type {
return mustLoadSchema().TypeByName("Payload")
}
var _ envelope.Tokener = (*tokenPayloadModel)(nil)
type tokenPayloadModel struct {
// The DID of the Invoker
2024-10-02 10:53:30 +02:00
Iss string
// The DID of Subject being invoked
Sub string
// The DID of the intended Executor if different from the Subject
Aud *string
2024-10-02 10:53:30 +02:00
// The Command
2024-10-02 10:53:30 +02:00
Cmd string
// The Command's Arguments
Args *args.Args
// Delegations that prove the chain of authority
Prf []cid.Cid
2024-10-02 10:53:30 +02:00
// Arbitrary Metadata
Meta *meta.Meta
2024-10-02 10:53:30 +02:00
// A unique, random nonce
Nonce []byte
2024-10-02 10:53:30 +02:00
// The timestamp at which the Invocation becomes invalid
// optional: can be nil
Exp *int64
// The timestamp at which the Invocation was created
Iat *int64
// An optional CID of the Receipt that enqueued the Task
Cause *cid.Cid
2024-10-02 10:53:30 +02:00
}
func (e *tokenPayloadModel) Prototype() schema.TypedPrototype {
return bindnode.Prototype((*tokenPayloadModel)(nil), payloadType())
}
func (*tokenPayloadModel) Tag() string {
return Tag
}