Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjg committed May 23, 2021
1 parent be12f9c commit a1c22ba
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,48 @@ An implementation of the [`dag-jose`](https://github.com/ipld/specs/pull/269) mu

To read a JWS from IPFS:

```go import ( "github.com/alexjg/dagjose" cidlink "github.com/ipld/go-ipld-prime/linking/cid"
```go
import (
"github.com/alexjg/dagjose" cidlink "github.com/ipld/go-ipld-prime/linking/cid"
)
// Here we're creating a `CID` which points to a JWS
jwsCid, err := cid.Decode(
"bagcqcerafzecmo67npzj56gfyukh3tbwxywgfsmxirr4oq57s6sddou4p5dq"
)
jwsCid, err := cid.Decode("some cid")
if err != nil {
panic(err)
}
// cidlink.Link is an implementation of `ipld.Link` backed by a CID
jwsLnk := cidlink.Link{Cid: jwsCid}

ls := cidlink.DefaultLinkSystem()

jose, err := dagjose.LoadJOSE(
jwsLnk,
context.Background(),
ipld.LinkContext{},
<an implementation of ipld.Loader, which knows how to get the block data from IPFS>,
ls, //<an implementation of ipld.Loader, which knows how to get the block data from IPFS>,
)
if err != nil {
panic(err)
}
if jose.AsJWS() != nil {
// We have a JWS object, print the general serialization of it
print(jose.AsJWS().GeneralJSONSerialization())
} else {
print("This is not a JWS")
}
```

To write a JWS to IPFS

```go
dagJws, err := dagjose.ParseJWS("<the general JSON serialization of a JWS>")
dagJws, err := dagjose.ParseJWS([]byte("<the general JSON serialization of a JWS>"))
if err != nil {
panic(err)
}
link, err := dagjose.BuildJOSELink(
context.Background(),
ls := cidlink.DefaultLinkSystem()
link, err := dagjose.StoreJOSE(
ipld.LinkContext{},
dagJws,
<an implementation of `ipld.Storer` which knows how to store the raw block data>
dagJws.AsJOSE(),
ls,
)
if err != nil {
panic(err)
Expand Down

0 comments on commit a1c22ba

Please sign in to comment.