Skip to content

Commit

Permalink
feat!: upgrade proof ls (#136)
Browse files Browse the repository at this point in the history
<img width="680" alt="Screenshot 2023-11-25 at 22 09 32"
src="https://github.com/web3-storage/w3cli/assets/58871/133cab28-f994-4391-8ad9-8bb44f54bd57">

- `w3 proof ls` now shows lots more info with ucan flavour properties so
it matches what you'd see in the spec or at https://ucan.xyz/validator/
  - and with a relative date help for `exp` e.g `# expires in one year`.
- and in valid yaml you can pate into a dingus (tho... what isn't valid
yaml).
  - and in colour! (optional)
- `--no-color` works automagically with chalk, so no additional plumbing
is needed to disable it
- audience is removed as it is always the did of the current agent, so
is redundent.
- `w3 proof ls --json` now returns **all** the info about the proofs. I
need this for debugging, and it's neat to be able to dig into them with
`jq`
- this is a breaking change as it changes the json output format to use
the default ucan/ipld flavour property names rather than custom ones.
- e.g. `att` instead of `capabilities`. `/` for the root cid, rather
than `cid`


**w3 proof ls --json**
```shell
# all issuers
$  w3 proof ls --json | jq '.iss'
"did:mailto:protocol.ai:oli"
"did:web:web3.storage"
"did:key:z6MknD58DihJ7j3XdPZLuJPVPt8LC8BtdTULatbWmoqr8Awp"
"did:key:z6MkhfzTwZJ28aRobCp76uXRqzsjH6GNu18WFwMumkAF5ojW"
"did:key:z6Mku56ywWspVnzkcVQbeSkw6egVRSNKVSYgS38HhKcUJRiN"
"did:key:z6Mktg5HxV1fifagzK8tnXXgCDsw1o4ekQHQpp9DKbLkh9hU"
"did:web:web3.storage"

# all space names
$ ❯ w3 proof ls --json | jq '.fct[].space.name | select(.)'
"clean"
"toots"
"fruits"
"veg"

# all ucan cids
$ w3 proof ls --json | jq '.["/"]'
"bafyreiaxpxm7oqdesq3nbjzcku3qqsb5onx25ab2tp23fl3edmjwllemgm"
"bafyreifwqxlcwwwb4xll3deyq6zlvui26k5bq2oq4rcaam4pmg5rfmtqnu"
"bafyreid2kvymk6nearlhg262zigjxitcl77ncsavcin2twdmhqmrlhxwui"
"bafyreibpxq7zqbmphfprnn7qotfaowryr63nh5sg6kk75zmm3hsx6vhdfy"
"bafyreietbar6chzhwp6bbxor6qydxkyhela7xpo2zmdmjbycoabgzxuexi"
"bafyreigu6g2psglmekpfo73zapgebs5sbydcctibgq6obwilbvepap3l3a"
"bafyreifwqxlcwwwb4xll3deyq6zlvui26k5bq2oq4rcaam4pmg5rfmtqnu"
```


**w3 proof ls**
```yaml
# bafyreiaxpxm7oqdesq3nbjzcku3qqsb5onx25ab2tp23fl3edmjwllemgm
iss: did:mailto:protocol.ai:oli
att:
  - can: *
    with: ucan:*
fct:
  - {"access/confirm":{"/":"bafyreidaljxvbccdts7dwoogds57a37y5fxy4b6wiq5h7oaz5npihtsgcq"},"access/request":{"/":"bafyreiabnffvury7onrouhhbsj6pi3de7oejxazkuoxbrjkl4vxuvdxjmm"}}

# bafyreifwqxlcwwwb4xll3deyq6zlvui26k5bq2oq4rcaam4pmg5rfmtqnu
iss: did:web:web3.storage
att:
  - can: ucan/attest
    with: did:web:web3.storage
    nb: {"proof":{"/":"bafyreiaxpxm7oqdesq3nbjzcku3qqsb5onx25ab2tp23fl3edmjwllemgm"}}
fct:
  - {"access/confirm":{"/":"bafyreidaljxvbccdts7dwoogds57a37y5fxy4b6wiq5h7oaz5npihtsgcq"},"access/request":{"/":"bafyreiabnffvury7onrouhhbsj6pi3de7oejxazkuoxbrjkl4vxuvdxjmm"}}

# bafyreid2kvymk6nearlhg262zigjxitcl77ncsavcin2twdmhqmrlhxwui
iss: did:key:z6MknD58DihJ7j3XdPZLuJPVPt8LC8BtdTULatbWmoqr8Awp
exp: 1731519367  # expires in a year
att:
  - can: space/*
    with: did:key:z6MknD58DihJ7j3XdPZLuJPVPt8LC8BtdTULatbWmoqr8Awp
  - can: store/*
    with: did:key:z6MknD58DihJ7j3XdPZLuJPVPt8LC8BtdTULatbWmoqr8Awp
  - can: upload/*
    with: did:key:z6MknD58DihJ7j3XdPZLuJPVPt8LC8BtdTULatbWmoqr8Awp
  - can: access/*
    with: did:key:z6MknD58DihJ7j3XdPZLuJPVPt8LC8BtdTULatbWmoqr8Awp
  - can: filecoin/*
    with: did:key:z6MknD58DihJ7j3XdPZLuJPVPt8LC8BtdTULatbWmoqr8Awp
  - can: usage/*
    with: did:key:z6MknD58DihJ7j3XdPZLuJPVPt8LC8BtdTULatbWmoqr8Awp
fct:
  - {"space":{"name":"clean"}}
```
License: MIT

---------

Signed-off-by: Oli Evans <[email protected]>
  • Loading branch information
olizilla authored Nov 27, 2023
1 parent 125f929 commit d95d1a4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
39 changes: 21 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as ucanto from '@ucanto/core'
import chalk from 'chalk'
export * as Coupon from './coupon.js'
export { Account, Space }
import ago from 's-ago'

/**
*
Expand Down Expand Up @@ -474,33 +475,35 @@ export async function listProofs(opts) {
const proofs = client.proofs()
if (opts.json) {
for (const proof of proofs) {
console.log(
JSON.stringify({
cid: proof.cid.toString(),
issuer: proof.issuer.did(),
capabilities: proof.capabilities.map((c) => ({
with: c.with,
can: c.can,
})),
})
)
console.log(JSON.stringify(proof))
}
} else {
for (const proof of proofs) {
console.log(proof.cid.toString())
console.log(` issuer: ${proof.issuer.did()}`)
console.log(` audience: ${proof.audience.did()}`)
console.log(chalk.dim(`# ${proof.cid.toString()}`))
console.log(`iss: ${chalk.cyanBright(proof.issuer.did())}`)
if (proof.expiration !== Infinity) {
console.log(`exp: ${chalk.yellow(proof.expiration)} ${chalk.dim(` # expires ${ago(new Date(proof.expiration * 1000))}`)}`)
}
console.log('att:')
for (const capability of proof.capabilities) {
console.log(` with: ${capability.with}`)
console.log(` can: ${capability.can}`)
console.log(` - can: ${chalk.magentaBright(capability.can)}`)
console.log(` with: ${chalk.green(capability.with)}`)
if (capability.nb) {
console.log(` nb: ${JSON.stringify(capability.nb)}`)
}
}
if (proof.facts.length > 0) {
console.log('fct:')
}
for (const fact of proof.facts) {
console.log(` - ${JSON.stringify(fact)}`)
}
console.log('')
}
console.log(chalk.dim(`# ${proofs.length} proof${proofs.length === 1 ? '' : 's'} for ${client.agent.did()}`))
}
}

/**
*
*/
export async function whoami() {
const client = await getClient()
console.log(client.did())
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"open": "^9.1.0",
"ora": "^7.0.1",
"pretty-tree": "^1.0.0",
"s-ago": "^2.2.0",
"sade": "^1.8.1",
"update-notifier": "^6.0.2"
},
Expand Down
8 changes: 4 additions & 4 deletions test/bin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -967,10 +967,10 @@ export const testProof = {
.env(env.bob)
.join()
const proofData = JSON.parse(proofList.output)
assert.equal(proofData.issuer, aliceDID)
assert.equal(proofData.capabilities.length, 1)
assert.equal(proofData.capabilities[0].with, spaceDID)
assert.equal(proofData.capabilities[0].can, 'store/*')
assert.equal(proofData.iss, aliceDID)
assert.equal(proofData.att.length, 1)
assert.equal(proofData.att[0].with, spaceDID)
assert.equal(proofData.att[0].can, 'store/*')
}),
}

Expand Down

0 comments on commit d95d1a4

Please sign in to comment.