Skip to content

Commit

Permalink
feat: dag-jose implementation using IPLD schema/code generation (#23)
Browse files Browse the repository at this point in the history
* feat: `dag-jose` implementation using IPLD schema/code generation

* cleanup

* support for "flattened" JOSE objects

* updates from review

* comments and renaming

* validate (then ignore) `link` when encoding

* updates and test fixes

* first pass of unit tests

* update dependencies

* test fixes

* Introduce tests using fixtures from the ipld/ipld repo. (#24)

* Introduce tests using fixtures from the ipld/ipld repo.

* tweak some fixture hunk names.

See commit message in the linked commit in the ipld/ipld submodule.

(Calling both the dagjose and the dagjson hunks "data", as it was
previously, suggested incorrect things: they are not that similar.
The dagjson is the datamodel view, and that is *not* the same thing
as a transliteration of the tokens that you'd get if you parsed the
dag-jose as dag-cbor.)

* test fixes

* test fixes

* test fixes

* test fixes

* cleanup docs

* remove `link` from encoded JWS

* fix up tests

* minor updates and add TODOs

* add CID matching to spec tests

* remove travis.yml file and add TODOs to README.md

* Update spec_test.go

Remove redundant code

* updates from review

* update to latest ipld repo

* use newest go-ipld-prime

* check err from traversal

Co-authored-by: Eric Myhre <hash@exultant.us>
  • Loading branch information
smrz2001 and warpfork authored Nov 26, 2021
1 parent 7a5074f commit 0029d76
Show file tree
Hide file tree
Showing 31 changed files with 16,897 additions and 2,707 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule ".ipld"]
path = .ipld
url = https://github.com/ipld/ipld/
1 change: 1 addition & 0 deletions .ipld
Submodule .ipld added at 3ac8e8
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

64 changes: 8 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,14 @@
# go-dag-jose

An implementation of the [`dag-jose`](https://github.com/ipld/specs/pull/269) multiformat for Go.
This is an implementation of the IPLD [dag-jose codec](https://ipld.io/specs/codecs/dag-jose/spec/).

## Example usage
Data that is encoded using the `dag-jose` codec is guaranteed to be a CBOR encoding of the general serialization of
either a JWE or a JWS.

To read a JWS from IPFS:
Module initialization registers the `dagjose.Encode` and `dagjose.Decode` with `go-ipld-prime`.

```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("some cid")
if err != nil {
panic(err)
}
// cidlink.Link is an implementation of `ipld.Link` backed by a CID
jwsLnk := cidlink.Link{Cid: jwsCid}
## TODOs

ls := cidlink.DefaultLinkSystem()

jose, err := dagjose.LoadJOSE(
jwsLnk,
ipld.LinkContext{},
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([]byte("<the general JSON serialization of a JWS>"))
if err != nil {
panic(err)
}
ls := cidlink.DefaultLinkSystem()
link, err := dagjose.StoreJOSE(
ipld.LinkContext{},
dagJws.AsJOSE(),
ls,
)
if err != nil {
panic(err)
}
fmt.Printf("Link is: %v", link)
```

## Changelog

This project attempts to stay up to date with changes in `go-ipld-prime`, this
means somewhat frequent API breakage as `go-ipld-prime` is not yet stable.
See [the changelog](./CHANGELOG.md).
- [ ] Add support for "compact" JWE/JWS serialization
- [ ] Add CI pipeline
- [ ] Add support for comparing recursive types in unit tests
109 changes: 0 additions & 109 deletions dagjose/dagjose.go

This file was deleted.

Loading

0 comments on commit 0029d76

Please sign in to comment.