Skip to content

Commit

Permalink
refactor: repo URL and IPLD Builder interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw committed Sep 18, 2024
1 parent 9408c1a commit eb31dd1
Show file tree
Hide file tree
Showing 78 changed files with 500 additions and 354 deletions.
53 changes: 31 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Ucanto UCAN RPC in Golang.
## Install

```console
go get github.com/storacha-network/go-ucanto
go get github.com/storacha/go-ucanto
```

## Usage
Expand Down Expand Up @@ -35,18 +35,27 @@ audience := servicePrincipal

type StoreAddCaveats struct {
Link ipld.Link
Size uint64
Size int
}

func (c *StoreAddCaveats) Build() (datamodel.Node, error) {
n := bindnode.Wrap(c, typ)
return n.Representation(), nil
func (c StoreAddCaveats) ToIPLD() (datamodel.Node, error) {
return ipld.WrapWithRecovery(&c, StoreAddType())
}

func StoreAddType() ipldschema.Type {
ts, _ := ipldprime.LoadSchemaBytes([]byte(`
type StoreAdd struct {
link Link
size Int
}
`))
return ts.TypeByName("StoreAdd")
}

capability := ucan.NewCapability(
"store/add",
did.Parse("did:key:z6MkwDuRThQcyWjqNsK54yKAmzfsiH6BTkASyiucThMtHt1T").String(),
&StoreAddCaveats{
StoreAddCaveats{
// TODO
},
)
Expand Down Expand Up @@ -104,14 +113,8 @@ type TestEcho struct {
Echo string
}

func (c *TestEcho) Build() (ipld.Node, error) {
np := basicnode.Prototype.Any
nb := np.NewBuilder()
ma, _ := nb.BeginMap(1)
ma.AssembleKey().AssignString("echo")
ma.AssembleValue().AssignString(c.Echo)
ma.Finish()
return nb.Build(), nil
func (c TestEcho) ToIPLD() (ipld.Node, error) {
return ipld.WrapWithRecovery(&c, EchoType())
}

func EchoType() ipldschema.Type {
Expand All @@ -128,16 +131,22 @@ func createServer(signer principal.Signer) (server.ServerView, error) {
testecho := validator.NewCapability(
"test/echo",
schema.DIDString(),
schema.Struct[*TestEcho](EchoType()),
schema.Struct[TestEcho](EchoType(), nil),
validator.DefaultDerives,
)

return server.NewServer(
signer,
// Handler definitions
server.WithServiceMethod(testecho.Can(), server.Provide(testecho, func(cap ucan.Capability[*TestEcho], inv invocation.Invocation, ctx server.InvocationContext) (transaction.Transaction[*TestEcho, ipld.Builder], error) {
r := result.Ok[*TestEcho, ipld.Builder](&TestEcho{Echo: cap.Nb().Echo})
return transaction.NewTransaction(r), nil
})),
server.WithServiceMethod(
testecho.Can(),
server.Provide(
testecho,
func(cap ucan.Capability[TestEcho], inv invocation.Invocation, ctx server.InvocationContext) (TestEcho, receipt.Effects, error) {
return TestEcho{Echo: cap.Nb().Echo}, nil, nil
},
),
),
)
}

Expand Down Expand Up @@ -172,15 +181,15 @@ func main() {

## API

[pkg.go.dev Reference](https://pkg.go.dev/github.com/storacha-network/go-ucanto)
[pkg.go.dev Reference](https://pkg.go.dev/github.com/storacha/go-ucanto)

## Related

* [Ucanto in Javascript](https://github.com/storacha-network/ucanto)
* [Ucanto in Javascript](https://github.com/storacha/ucanto)

## Contributing

Feel free to join in. All welcome. Please [open an issue](https://github.com/storacha-network/go-ucanto/issues)!
Feel free to join in. All welcome. Please [open an issue](https://github.com/storacha/go-ucanto/issues)!

## License

Expand Down
12 changes: 6 additions & 6 deletions client/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"hash"
"iter"

"github.com/storacha-network/go-ucanto/core/invocation"
"github.com/storacha-network/go-ucanto/core/ipld/block"
"github.com/storacha-network/go-ucanto/core/message"
"github.com/storacha-network/go-ucanto/transport"
"github.com/storacha-network/go-ucanto/transport/car"
"github.com/storacha-network/go-ucanto/ucan"
"github.com/storacha/go-ucanto/core/invocation"
"github.com/storacha/go-ucanto/core/ipld/block"
"github.com/storacha/go-ucanto/core/message"
"github.com/storacha/go-ucanto/transport"
"github.com/storacha/go-ucanto/transport/car"
"github.com/storacha/go-ucanto/ucan"
)

type Connection interface {
Expand Down
4 changes: 2 additions & 2 deletions core/car/car.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/ipld/go-car/util"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"github.com/multiformats/go-varint"
"github.com/storacha-network/go-ucanto/core/ipld"
"github.com/storacha-network/go-ucanto/core/ipld/block"
"github.com/storacha/go-ucanto/core/ipld"
"github.com/storacha/go-ucanto/core/ipld/block"
)

// ContentType is the value the HTTP Content-Type header should have for CARs.
Expand Down
2 changes: 1 addition & 1 deletion core/car/car_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/ipfs/go-cid"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"github.com/storacha-network/go-ucanto/core/ipld"
"github.com/storacha/go-ucanto/core/ipld"
)

type fixture struct {
Expand Down
2 changes: 1 addition & 1 deletion core/dag/blockstore/blockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"iter"
"sync"

"github.com/storacha-network/go-ucanto/core/ipld"
"github.com/storacha/go-ucanto/core/ipld"
)

type BlockReader interface {
Expand Down
8 changes: 4 additions & 4 deletions core/delegation/datamodel/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (

"github.com/ipfs/go-cid"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
adm "github.com/storacha-network/go-ucanto/core/delegation/datamodel"
"github.com/storacha-network/go-ucanto/core/ipld/block"
"github.com/storacha-network/go-ucanto/core/ipld/codec/cbor"
"github.com/storacha-network/go-ucanto/core/ipld/hash/sha256"
adm "github.com/storacha/go-ucanto/core/delegation/datamodel"
"github.com/storacha/go-ucanto/core/ipld/block"
"github.com/storacha/go-ucanto/core/ipld/codec/cbor"
"github.com/storacha/go-ucanto/core/ipld/hash/sha256"
)

func TestEncodeDecode(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions core/delegation/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package delegation
import (
"fmt"

"github.com/storacha-network/go-ucanto/core/dag/blockstore"
"github.com/storacha-network/go-ucanto/core/ipld/block"
"github.com/storacha-network/go-ucanto/core/ipld/codec/cbor"
"github.com/storacha-network/go-ucanto/core/ipld/hash/sha256"
"github.com/storacha-network/go-ucanto/ucan"
udm "github.com/storacha-network/go-ucanto/ucan/datamodel/ucan"
"github.com/storacha/go-ucanto/core/dag/blockstore"
"github.com/storacha/go-ucanto/core/ipld/block"
"github.com/storacha/go-ucanto/core/ipld/codec/cbor"
"github.com/storacha/go-ucanto/core/ipld/hash/sha256"
"github.com/storacha/go-ucanto/ucan"
udm "github.com/storacha/go-ucanto/ucan/datamodel/ucan"
)

// Option is an option configuring a UCAN delegation.
Expand Down
20 changes: 10 additions & 10 deletions core/delegation/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import (
"iter"
"sync"

"github.com/storacha-network/go-ucanto/core/car"
"github.com/storacha-network/go-ucanto/core/dag/blockstore"
adm "github.com/storacha-network/go-ucanto/core/delegation/datamodel"
"github.com/storacha-network/go-ucanto/core/ipld"
"github.com/storacha-network/go-ucanto/core/ipld/block"
"github.com/storacha-network/go-ucanto/core/ipld/codec/cbor"
"github.com/storacha-network/go-ucanto/core/ipld/hash/sha256"
"github.com/storacha-network/go-ucanto/ucan"
"github.com/storacha-network/go-ucanto/ucan/crypto/signature"
udm "github.com/storacha-network/go-ucanto/ucan/datamodel/ucan"
"github.com/storacha/go-ucanto/core/car"
"github.com/storacha/go-ucanto/core/dag/blockstore"
adm "github.com/storacha/go-ucanto/core/delegation/datamodel"
"github.com/storacha/go-ucanto/core/ipld"
"github.com/storacha/go-ucanto/core/ipld/block"
"github.com/storacha/go-ucanto/core/ipld/codec/cbor"
"github.com/storacha/go-ucanto/core/ipld/hash/sha256"
"github.com/storacha/go-ucanto/ucan"
"github.com/storacha/go-ucanto/ucan/crypto/signature"
udm "github.com/storacha/go-ucanto/ucan/datamodel/ucan"
)

// Delagation is a materialized view of a UCAN delegation, which can be encoded
Expand Down
6 changes: 3 additions & 3 deletions core/delegation/proofs.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package delegation

import (
"github.com/storacha-network/go-ucanto/core/dag/blockstore"
"github.com/storacha-network/go-ucanto/core/ipld"
"github.com/storacha-network/go-ucanto/ucan"
"github.com/storacha/go-ucanto/core/dag/blockstore"
"github.com/storacha/go-ucanto/core/ipld"
"github.com/storacha/go-ucanto/ucan"
)

type Proof struct {
Expand Down
8 changes: 4 additions & 4 deletions core/invocation/invocation.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package invocation

import (
"github.com/storacha-network/go-ucanto/core/dag/blockstore"
"github.com/storacha-network/go-ucanto/core/delegation"
"github.com/storacha-network/go-ucanto/core/ipld"
"github.com/storacha-network/go-ucanto/ucan"
"github.com/storacha/go-ucanto/core/dag/blockstore"
"github.com/storacha/go-ucanto/core/delegation"
"github.com/storacha/go-ucanto/core/ipld"
"github.com/storacha/go-ucanto/ucan"
)

// Invocation represents a UCAN that can be presented to a service provider to
Expand Down
8 changes: 4 additions & 4 deletions core/invocation/ran/ran.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package ran

import (
"github.com/storacha-network/go-ucanto/core/dag/blockstore"
"github.com/storacha-network/go-ucanto/core/invocation"
"github.com/storacha-network/go-ucanto/core/ipld"
"github.com/storacha-network/go-ucanto/ucan"
"github.com/storacha/go-ucanto/core/dag/blockstore"
"github.com/storacha/go-ucanto/core/invocation"
"github.com/storacha/go-ucanto/core/ipld"
"github.com/storacha/go-ucanto/ucan"
)

type Ran struct {
Expand Down
4 changes: 2 additions & 2 deletions core/ipld/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/ipld/go-ipld-prime"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"github.com/ipld/go-ipld-prime/schema"
"github.com/storacha-network/go-ucanto/core/ipld/codec"
"github.com/storacha-network/go-ucanto/core/ipld/hash"
"github.com/storacha/go-ucanto/core/ipld/codec"
"github.com/storacha/go-ucanto/core/ipld/hash"
)

type Block interface {
Expand Down
2 changes: 1 addition & 1 deletion core/ipld/hash/sha256/sha256.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"crypto/sha256"

"github.com/multiformats/go-multihash"
"github.com/storacha-network/go-ucanto/core/ipld/hash"
"github.com/storacha/go-ucanto/core/ipld/hash"
)

// sha2-256
Expand Down
6 changes: 3 additions & 3 deletions core/ipld/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import (
"github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/node/bindnode"
"github.com/ipld/go-ipld-prime/schema"
"github.com/storacha-network/go-ucanto/core/ipld/block"
"github.com/storacha/go-ucanto/core/ipld/block"
)

type Link = ipld.Link
type Block = block.Block
type Node = ipld.Node

// Builder can be modeled as an IPLD data and provides a `Build` method to
// Builder can be modeled as an IPLD data and provides a `ToIPLD` method to
// build itself into a `datamodel.Node`.
type Builder interface {
Build() (Node, error)
ToIPLD() (Node, error)
}

// WrapWithRecovery behaves like bindnode.Wrap but converts panics into errors
Expand Down
2 changes: 1 addition & 1 deletion core/ipld/rebind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/datamodel"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"github.com/storacha-network/go-ucanto/core/ipld/codec/cbor"
"github.com/storacha/go-ucanto/core/ipld/codec/cbor"
)

func TestRebind(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions core/message/datamodel/agentmessage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"github.com/ipfs/go-cid"
"github.com/ipld/go-ipld-prime"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"github.com/storacha-network/go-ucanto/core/ipld/block"
"github.com/storacha-network/go-ucanto/core/ipld/codec/cbor"
"github.com/storacha-network/go-ucanto/core/ipld/hash/sha256"
mdm "github.com/storacha-network/go-ucanto/core/message/datamodel"
"github.com/storacha/go-ucanto/core/ipld/block"
"github.com/storacha/go-ucanto/core/ipld/codec/cbor"
"github.com/storacha/go-ucanto/core/ipld/hash/sha256"
mdm "github.com/storacha/go-ucanto/core/message/datamodel"
)

func TestEncodeDecode(t *testing.T) {
Expand Down
16 changes: 8 additions & 8 deletions core/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"fmt"
"iter"

"github.com/storacha-network/go-ucanto/core/dag/blockstore"
"github.com/storacha-network/go-ucanto/core/invocation"
"github.com/storacha-network/go-ucanto/core/ipld"
"github.com/storacha-network/go-ucanto/core/ipld/block"
"github.com/storacha-network/go-ucanto/core/ipld/codec/cbor"
"github.com/storacha-network/go-ucanto/core/ipld/hash/sha256"
mdm "github.com/storacha-network/go-ucanto/core/message/datamodel"
"github.com/storacha-network/go-ucanto/core/receipt"
"github.com/storacha/go-ucanto/core/dag/blockstore"
"github.com/storacha/go-ucanto/core/invocation"
"github.com/storacha/go-ucanto/core/ipld"
"github.com/storacha/go-ucanto/core/ipld/block"
"github.com/storacha/go-ucanto/core/ipld/codec/cbor"
"github.com/storacha/go-ucanto/core/ipld/hash/sha256"
mdm "github.com/storacha/go-ucanto/core/message/datamodel"
"github.com/storacha/go-ucanto/core/receipt"
)

type AgentMessage interface {
Expand Down
8 changes: 4 additions & 4 deletions core/receipt/datamodel/receipt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (

"github.com/ipfs/go-cid"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"github.com/storacha-network/go-ucanto/core/ipld/block"
"github.com/storacha-network/go-ucanto/core/ipld/codec/cbor"
"github.com/storacha-network/go-ucanto/core/ipld/hash/sha256"
rdm "github.com/storacha-network/go-ucanto/core/receipt/datamodel"
"github.com/storacha/go-ucanto/core/ipld/block"
"github.com/storacha/go-ucanto/core/ipld/codec/cbor"
"github.com/storacha/go-ucanto/core/ipld/hash/sha256"
rdm "github.com/storacha/go-ucanto/core/receipt/datamodel"
)

type resultOk struct {
Expand Down
Loading

0 comments on commit eb31dd1

Please sign in to comment.