Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add web5 CLI for DID creation #63

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [Prerequisites](#prerequisites)
- [`hermit`](#hermit)
- [Helpful Commands](#helpful-commands)
- [`web5` CLI](#web5-cli)
- [Contributing](#contributing)


Expand Down Expand Up @@ -63,6 +64,13 @@ This repo uses [`just`](https://github.com/casey/just) as a command runner. Belo
| `just test` | runs all tests |
| `just lint` | runs linter |

### `web5` CLI

```shell
web5 -h
```

See [cmd/web5/README.md](cmd/web5/README.md) for more information.

### Contributing
Each package's README contains in-depth information about the package's structure and suggestions on how add features specific to that package
3 changes: 3 additions & 0 deletions bin/hermit.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
env = {
"PATH": "${HERMIT_ENV}/scripts:${PATH}",
}
23 changes: 23 additions & 0 deletions cmd/web5/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# web5

## Usage

```shell
➜ web5 -h
Usage: web5 <command>

Web5 - A decentralized web platform that puts you in
control of your data and identity.

Flags:
-h, --help Show context-sensitive help.

Commands:
did:jwk create
Create a did:jwk.

did:web create <domain>
Create a did:web.

Run "web5 <command> --help" for more information on a command.
```
36 changes: 36 additions & 0 deletions cmd/web5/cmd_didjwk.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"context"
"encoding/json"
"fmt"

"github.com/tbd54566975/web5-go/dids/didjwk"
)

type didJWKCreate struct{}

func (c *didJWKCreate) Run(_ context.Context) error {
did, err := didjwk.Create()
if err != nil {
return err
}

portableDID, err := did.ToPortableDID()
if err != nil {
return err
}

jsonDID, err := json.MarshalIndent(portableDID, "", " ")
if err != nil {
return err
}

fmt.Println(string(jsonDID))

return nil
}

type didJWKCmd struct {
Create didJWKCreate `cmd:"" help:"Create a did:jwk."`
}
38 changes: 38 additions & 0 deletions cmd/web5/cmd_didweb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"context"
"encoding/json"
"fmt"

"github.com/tbd54566975/web5-go/dids/didweb"
)

type didWebCreate struct {
Domain string `arg:"" help:"The domain name for the DID." required:""`
}

func (c *didWebCreate) Run(_ context.Context) error {
did, err := didweb.Create(c.Domain)
if err != nil {
return err
}

portableDID, err := did.ToPortableDID()
if err != nil {
return err
}

jsonDID, err := json.MarshalIndent(portableDID, "", " ")
if err != nil {
return err
}

fmt.Println(string(jsonDID))

return nil
}

type didWebCmd struct {
Create didWebCreate `cmd:"" help:"Create a did:web."`
}
25 changes: 25 additions & 0 deletions cmd/web5/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"context"

"github.com/alecthomas/kong"
)

type CLI struct {
DIDJWK didJWKCmd `cmd:"" name:"did:jwk" help:"Manage did:jwk's."`
DIDWeb didWebCmd `cmd:"" name:"did:web" help:"Manage did:web's."`
}

var cli CLI

func main() {
kctx := kong.Parse(&cli,
kong.Description("Web5 - A decentralized web platform that puts you in control of your data and identity."),
)

ctx := context.Background()
kctx.BindTo(ctx, (*context.Context)(nil))
err := kctx.Run(ctx)
kctx.FatalIfErrorf(err)
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.22.0

require (
github.com/alecthomas/assert/v2 v2.5.0
github.com/alecthomas/kong v0.8.1
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0
github.com/tv42/zbase32 v0.0.0-20220222190657-f76a9fc892fa
golang.org/x/net v0.20.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/alecthomas/assert/v2 v2.5.0 h1:OJKYg53BQx06/bMRBSPDCO49CbCDNiUQXwdoNrt6x5w=
github.com/alecthomas/assert/v2 v2.5.0/go.mod h1:fw5suVxB+wfYJ3291t0hRTqtGzFYdSwstnRQdaQx2DM=
github.com/alecthomas/kong v0.8.1 h1:acZdn3m4lLRobeh3Zi2S2EpnXTd1mOL6U7xVml+vfkY=
github.com/alecthomas/kong v0.8.1/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U=
github.com/alecthomas/repr v0.3.0 h1:NeYzUPfjjlqHY4KtzgKJiWd6sVq2eNUPTi34PiFGjY8=
github.com/alecthomas/repr v0.3.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
Expand Down
7 changes: 7 additions & 0 deletions scripts/web5
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -euo pipefail
basedir="$(dirname "$0")/.."
name="$(basename "$0")"
dest="${basedir}/build/devel"
mkdir -p "$dest"
(cd "${basedir}" && ./bin/go build -ldflags="-s -w -buildid=" -o "$dest/${name}" "./cmd/${name}") && exec "$dest/${name}" "$@"
Loading