diff --git a/index.js b/index.js index 6dab1e1..d046274 100644 --- a/index.js +++ b/index.js @@ -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' /** * @@ -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()) diff --git a/package-lock.json b/package-lock.json index 8eb1bd1..81cf3fa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,6 +27,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" }, @@ -5977,6 +5978,11 @@ "queue-microtask": "^1.2.2" } }, + "node_modules/s-ago": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/s-ago/-/s-ago-2.2.0.tgz", + "integrity": "sha512-t6Q/aFCCJSBf5UUkR/WH0mDHX8EGm2IBQ7nQLobVLsdxOlkryYMbOlwu2D4Cf7jPUp0v1LhfPgvIZNoi9k8lUA==" + }, "node_modules/sade": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/sade/-/sade-1.8.1.tgz", diff --git a/package.json b/package.json index e905c08..d61fb7f 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/test/bin.spec.js b/test/bin.spec.js index 6931a42..de6246a 100644 --- a/test/bin.spec.js +++ b/test/bin.spec.js @@ -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/*') }), }