go-dag-jose

module
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2021 License: MIT

README

dagjose-go

An implementation of the dag-jose multiformat for Go.

Example usage

To read a JWS from IPFS:

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

jose, err := dagjose.LoadJOSE(
    jwsLnk,
    context.Background(),
    ipld.LinkContext{},
    <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())
}

To write a JWS to IPFS

dagJws, err := dagjose.ParseJWS("<the general JSON serialization of a JWS>")
if err != nil {
    panic(err)
}
link, err := dagjose.BuildJOSELink(
    context.Background(),
    ipld.LinkContext{},
    dagJws,
    <an implementation of `ipld.Storer` which knows how to store the raw block data>
)
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.

Directories

Path Synopsis
Package dagjose is an implementation of the IPLD codec.
Package dagjose is an implementation of the IPLD codec.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL