Skip to content

Commit

Permalink
Merge pull request #22 from aviarytech/cli
Browse files Browse the repository at this point in the history
Updates to the CLI
  • Loading branch information
brianorwhatever authored Nov 14, 2024
2 parents 43f84ec + 8b8f764 commit baf3aa7
Show file tree
Hide file tree
Showing 14 changed files with 789 additions and 246 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ test/logs
node_modules
bun.lockb
claude_chats
*.jsonl
*.jsonl
did.json
147 changes: 63 additions & 84 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ The following commands are defined in the `package.json` file:
```
This command runs: `bun test`

4. `test:watch`: Run tests in watch mode, focusing on witness tests.
4. `test:watch`: Run tests in watch mode.
```bash
bun run test:watch
```
This command runs: `bun test --watch witness`
This command runs: `bun test --watch`

5. `test:bail`: Run tests in watch mode, stopping on the first failure with verbose output.
```bash
Expand All @@ -78,102 +78,81 @@ The following commands are defined in the `package.json` file:
```
This command runs: `bun run src/cli.ts --`

## CLI Documentation
## CLI Usage Guide

```
The CLI is Experimental, buggy and beta software -- use at your own risk!
```

The trustdidweb-ts package provides a Command Line Interface (CLI) for managing Decentralized Identifiers (DIDs) using the `did:tdw` method.


### Usage

The general syntax for using the CLI is:
> ⚠️ **Warning**: The CLI is experimental beta software - use at your own risk!
### Basic Syntax
```bash
bun run cli [command] [options]
```

To output the help using the CLI:
### Available Commands

#### 1. Create a DID
Create a new DID with various configuration options:

```bash
bun run cli help
bun run cli create \
--domain example.com \
--output ./did.jsonl \
--portable \
--witness did:tdw:witness1:example.com \
--witness-threshold 1
```

### Commands

1. **Create a DID**

```bash
bun run cli create [options]
```

Options:
- `--domain [domain]`: (Required) Domain for the DID
- `--output [file]`: (Optional) Path to save the DID log
- `--portable`: (Optional) Make the DID portable
- `--prerotation`: (Optional) Enable pre-rotation
- `--witness [witness]`: (Optional) Add a witness (can be used multiple times)
- `--witness-threshold [n]`: (Optional) Set witness threshold

Example:
```bash
bun run cli create --domain example.com --portable --witness did:tdw:QmWitness1:example.com --witness did:tdw:QmWitness2...:example.com
```

2. **Resolve a DID**

```bash
bun run cli resolve --did [did]
```

Example:
```bash
bun run cli resolve --did did:tdw:Qm...:example.com
```

3. **Update a DID**

```bash
bun run cli update [options]
```
**Key Options:**
- `--domain`: (Required) Host domain for the DID
- `--output`: Save location for DID log
- `--portable`: Enable domain portability
- `--prerotation`: Enable key pre-rotation security
- `--witness`: Add witness DIDs (repeatable)
- `--witness-threshold`: Set minimum witness count
- `--next-key-hash`: Add pre-rotation key hashes (required with --prerotation)

Options:
- `--log [file]`: (Required) Path to the DID log file
- `--output [file]`: (Optional) Path to save the updated DID log
- `--prerotation`: (Optional) Enable pre-rotation
- `--witness [witness]`: (Optional) Add a witness (can be used multiple times)
- `--witness-threshold [n]`: (Optional) Set witness threshold
- `--service [service]`: (Optional) Add a service (format: type,endpoint)
- `--add-vm [type]`: (Optional) Add a verification method
- `--also-known-as [alias]`: (Optional) Add an alsoKnownAs alias

Example:
```bash
bun run cli update --log ./did.jsonl --output ./updated-did.jsonl --add-vm keyAgreement --service LinkedDomains,https://example.com
```
#### 2. Resolve a DID
View the current state of a DID:

4. **Deactivate a DID**
```bash
# From DID identifier
bun run cli resolve --did did:tdw:123456:example.com

```bash
bun run cli deactivate [options]
```
# From local log file
bun run cli resolve --log ./did.jsonl
```

Options:
- `--log [file]`: (Required) Path to the DID log file
- `--output [file]`: (Optional) Path to save the deactivated DID log
#### 3. Update a DID
Modify an existing DID's properties:

Example:
```bash
bun run cli deactivate --log ./did.jsonl --output ./deactivated-did.jsonl
```
```bash
bun run cli update \
--log ./did.jsonl \
--output ./updated.jsonl \
--add-vm keyAgreement \
--service LinkedDomains,https://example.com \
--also-known-as did:web:example.com
```

### Additional Notes
**Update Options:**
- `--log`: (Required) Current DID log path
- `--output`: Updated log save location
- `--add-vm`: Add verification methods:
- authentication
- assertionMethod
- keyAgreement
- capabilityInvocation
- capabilityDelegation
- `--service`: Add services (format: type,endpoint)
- `--also-known-as`: Add alternative identifiers
- `--prerotation`: Enable/update key pre-rotation
- `--witness`: Update witness list
- `--witness-threshold`: Update witness requirements

#### 4. Deactivate a DID
Permanently deactivate a DID:

- The CLI automatically generates new authentication keys when creating or updating a DID.
- The `--portable` option in the create command allows the DID to be moved to a different domain later.
- The `--prerotation` option enables key pre-rotation, which helps prevent loss of control if an active private key is compromised.
- Witness functionality allows for third-party attestation of DID operations.
- The CLI saves the DID log to a file when the `--output` option is provided.
- For the update and deactivate commands, the existing DID log must be provided using the `--log` option.
```bash
bun run cli deactivate \
--log ./did.jsonl \
--output ./deactivated.jsonl
```
8 changes: 8 additions & 0 deletions bin/tdw
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bun
import { main } from "../src/cli.ts";

// Execute the main CLI function
main().catch(error => {
console.error('Fatal error:', error);
process.exit(1);
});
16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,33 @@
"name": "trustdidweb-ts",
"module": "src/index.ts",
"type": "module",
"version": "0.0.4",
"scripts": {
"dev": "bun --watch --inspect-wait ./src/resolver.ts",
"server": "bun --watch ./src/resolver.ts",
"test": "bun test",
"test:watch": "bun test --watch witness",
"test:watch": "bun test --watch",
"test:bail": "bun test --watch --bail --verbose",
"test:log": "mkdir -p ./test/logs && LOG_RESOLVES=true bun test &> ./test/logs/test-run.txt",
"cli": "bun run src/cli.ts"
"cli": "bun src/cli.ts"
},
"devDependencies": {
"bun-bagel": "^1.1.0",
"bun-types": "latest"
},
"peerDependencies": {
"typescript": "^5.0.0"
"typescript": "^5.4.5"
},
"dependencies": {
"@interop/base58-universal": "^1.0.0",
"@noble/curves": "^1.4.2",
"@noble/curves": "^1.6.0",
"@noble/ed25519": "^2.1.0",
"elysia": "^0.8.17",
"json-canonicalize": "^1.0.6",
"multiformats": "^13.1.0",
"nanoid": "^5.0.6"
"multiformats": "^13.3.1",
"nanoid": "^5.0.8"
},
"bin": {
"tdw": "./bin/tdw"
}
}
Loading

0 comments on commit baf3aa7

Please sign in to comment.