Skip to content

Commit

Permalink
feat: add whoami to print agent DID (#11)
Browse files Browse the repository at this point in the history
a minimal implementation. The assumption is this command will get more
useful once we have
[w3accounts](https://github.com/web3-storage/specs/blob/main/w3-account.md)

License: MIT
Signed-off-by: Oli Evans <oli@protocol.ai>
  • Loading branch information
olizilla authored Dec 12, 2022
1 parent b6cb1f0 commit e3f2497
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sade from 'sade'
import open from 'open'
import { getPkg, unwarnify } from './lib.js'
import { createSpace, registerSpace, createDelegation, upload, list } from './index.js'
import { createSpace, registerSpace, createDelegation, upload, list, whoami } from './index.js'

unwarnify()

Expand Down Expand Up @@ -31,6 +31,10 @@ cli.command('ls')
.option('--shards', 'Pretty print with shards in output')
.action(list)

cli.command('whoami')
.describe('Print information about the current agent.')
.action(whoami)

cli.command('space')
.describe('Create and mangage w3 spaces')

Expand Down
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,9 @@ export async function createDelegation (audienceDID, opts) {
}
await writer.close()
}

export async function whoami () {
const client = await create()
const who = client.agent()
console.log(who.did())
}
5 changes: 5 additions & 0 deletions test/bin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ test('w3 --version', (t) => {
t.regex(stdout, /w3, \d.\d.\d/)
})

test('w3 whoami', (t) => {
const { stdout } = execaSync('./bin.js', ['whoami'])
t.regex(stdout, /^did:key:/)
})

test('w3 space create', (t) => {
const { stdout } = execaSync('./bin.js', ['space', 'create'])
t.regex(stdout, /^did:key:/)
Expand Down

0 comments on commit e3f2497

Please sign in to comment.