extargs: make the hash more convenient to use by directly returning the invocation.Option
This commit is contained in:
committed by
Michael Muré
parent
cc661f3936
commit
41d679dfab
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/ucan-wg/go-ucan/pkg/args"
|
||||
"github.com/ucan-wg/go-ucan/pkg/policy"
|
||||
"github.com/ucan-wg/go-ucan/pkg/policy/literal"
|
||||
"github.com/ucan-wg/go-ucan/token/invocation"
|
||||
)
|
||||
|
||||
// JsonRpcArgsKey is the key in the args, used for:
|
||||
@@ -112,7 +113,9 @@ func (jrea *JsonRpcExtArgs) verifyHash() error {
|
||||
// If that hash is inserted at the JsonRpcArgsKey key in the invocation arguments,
|
||||
// this increases the security as the UCAN token cannot be used with a different
|
||||
// JsonRPC request.
|
||||
func MakeJsonRpcHash(req *jsonrpc.Request) ([]byte, error) {
|
||||
// For convenience, the hash is returned as a read to use invocation argument.
|
||||
func MakeJsonRpcHash(req *jsonrpc.Request) (invocation.Option, error) {
|
||||
// Note: the hash is computed on the full IPLD args, including JsonRpcArgsKey
|
||||
computedArgs, err := makeJsonRpcArgs(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -133,7 +136,7 @@ func MakeJsonRpcHash(req *jsonrpc.Request) ([]byte, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return sum, nil
|
||||
return invocation.WithArgument(JsonRpcArgsKey, []byte(sum)), nil
|
||||
}
|
||||
|
||||
func makeJsonRpcArgs(req *jsonrpc.Request) (*args.Args, error) {
|
||||
|
||||
Reference in New Issue
Block a user