github.com/storacha/go-ucanto@v0.7.2/core/invocation/invocation.go (about)

     1  package invocation
     2  
     3  import (
     4  	"github.com/storacha/go-ucanto/core/dag/blockstore"
     5  	"github.com/storacha/go-ucanto/core/delegation"
     6  	"github.com/storacha/go-ucanto/core/ipld"
     7  	"github.com/storacha/go-ucanto/ucan"
     8  )
     9  
    10  // Invocation represents a UCAN that can be presented to a service provider to
    11  // invoke or "exercise" a Capability. You can think of invocations as a
    12  // serialized function call, where the ability or `can` portion of the
    13  // Capability acts as the function name, and the resource (`with`) and caveats
    14  // (`nb`) of the capability act as function arguments.
    15  //
    16  // Most invocations will require valid proofs, which consist of a chain of
    17  // Delegations. The service provider will inspect the proofs to verify that the
    18  // invocation has sufficient privileges to execute.
    19  type Invocation interface {
    20  	delegation.Delegation
    21  }
    22  
    23  func NewInvocation(root ipld.Block, bs blockstore.BlockReader) (Invocation, error) {
    24  	return delegation.NewDelegation(root, bs)
    25  }
    26  
    27  func NewInvocationView(root ipld.Link, bs blockstore.BlockReader) (Invocation, error) {
    28  	return delegation.NewDelegationView(root, bs)
    29  }
    30  
    31  type IssuedInvocation interface {
    32  	Invocation
    33  }
    34  
    35  func Invoke[C ucan.CaveatBuilder](issuer ucan.Signer, audience ucan.Principal, capability ucan.Capability[C], options ...delegation.Option) (IssuedInvocation, error) {
    36  	return delegation.Delegate(issuer, audience, []ucan.Capability[C]{capability}, options...)
    37  }