Skip to content

Commit

Permalink
feat!: use new account model (#53)
Browse files Browse the repository at this point in the history
1) add a new `authorize` command that invokes the new `access/authorize`
capability
2) add a new `can access claim` command that invokes the new
`access/claim` capability
3) update `space register` to use the new space registration flow (which invokes `provider/add` and `access/delegate`)

---------

Co-authored-by: Irakli Gozalishvili <contact@gozala.io>
  • Loading branch information
travis and Gozala authored Mar 22, 2023
1 parent 1b69cbb commit 7f63286
Show file tree
Hide file tree
Showing 5 changed files with 735 additions and 153 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ w3 up recipies.txt
## Commands

* Basics
* [`w3 authorize`](#w3-authorize-email)
* [`w3 up`](#w3-up-path-path)
* [`w3 ls`](#w3-ls)
* [`w3 rm`](#w3-rm-root-cid) <sup>coming soon!</sup>
Expand Down Expand Up @@ -67,6 +68,10 @@ w3 up recipies.txt

---

### `w3 authorize <email>`

Authorize this agent to interact with the w3up service with any capabilities granted to the given email.

### `w3 up <path> [path...]`

Upload file(s) to web3.storage. The IPFS Content ID (CID) for your files is calculated on your machine, and sent up along with your files. web3.storage makes your content available on the IPFS network
Expand Down
12 changes: 12 additions & 0 deletions bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import sade from 'sade'
import open from 'open'
import { getPkg } from './lib.js'
import {
accessClaim,
authorize,
createSpace,
registerSpace,
addSpace,
Expand Down Expand Up @@ -58,6 +60,12 @@ cli.command('rm <root-cid>')
.option('--shards', 'Remove all shards referenced by the upload from the store. Use with caution and ensure other uploads do not reference the same shards.')
.action(remove)

cli.command('authorize <email>')
.alias('auth')
.example('authorize user@example.com')
.describe('Authorize this agent to interact with the w3up service with any capabilities granted to the given email.')
.action(authorize)

cli.command('whoami')
.describe('Print information about the current agent.')
.action(whoami)
Expand Down Expand Up @@ -107,6 +115,10 @@ cli.command('proof ls')
.option('--json', 'Format as newline delimited JSON')
.action(listProofs)

cli.command('can access claim')
.describe('Claim delegated capabilities for the authorized account.')
.action(accessClaim)

cli.command('can store add <car-path>')
.describe('Store a CAR file with the service.')
.action(storeAdd)
Expand Down
33 changes: 29 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,32 @@ import { CarWriter } from '@ipld/car'
import { filesFromPaths } from 'files-from-path'
import { getClient, checkPathsExist, filesize, readProof, uploadListResponseToString } from './lib.js'

export async function accessClaim () {
const client = await getClient()
await client.capability.access.claim()
}

/**
* @param {string} email
*/
export async function authorize (email) {
const client = await getClient()
/** @type {import('ora').Ora|undefined} */
let spinner
setTimeout(() => {
spinner = ora(`🔗 please click the link we sent to ${email} to authorize this agent`).start()
}, 1000)
try {
await client.capability.access.authorize(email)
} catch (err) {
if (spinner) spinner.stop()
console.error(err)
process.exit(1)
}
if (spinner) spinner.stop()
console.log(`⁂ agent authorized to use capabilities delegated to ${email}`)
}

/**
* @param {string} firstPath
* @param {object} opts
Expand Down Expand Up @@ -143,10 +169,8 @@ export async function registerSpace (email) {
await client.setCurrentSpace(space.did())
}
/** @type {import('ora').Ora|undefined} */
let spinner
setTimeout(() => {
spinner = ora(`🔗 please click the link we sent to ${email} to register your space`).start()
}, 1000)
const spinner = ora('registering your space').start()

try {
await client.registerSpace(email)
} catch (err) {
Expand Down Expand Up @@ -311,6 +335,7 @@ export async function listProofs (opts) {
for (const proof of proofs) {
console.log(proof.cid.toString())
console.log(` issuer: ${proof.issuer.did()}`)
console.log(` audience: ${proof.audience.did()}`)
for (const capability of proof.capabilities) {
console.log(` with: ${capability.with}`)
console.log(` can: ${capability.can}`)
Expand Down
Loading

0 comments on commit 7f63286

Please sign in to comment.