Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add use cases package #1506

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/use-cases/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Use Cases

This package is a "cookbook" of different uses for `@web3-storage/w3up-client`.
1 change: 1 addition & 0 deletions packages/use-cases/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("this is the use-cases module of w3up - it is not currently intended to be used as a module")
19 changes: 19 additions & 0 deletions packages/use-cases/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@web3-storage/use-cases",
"description": "Use cases for w3up-client",
"version": "0.0.1",
"type": "module",
"main": "./main.js",
"homepage": "https://web3.storage",
"repository": {
"type": "git",
"url": "https://github.com/w3s-project/w3up.git",
"directory": "packages/upload-api"
},
"dependencies": {
"@ucanto/core": "^10.0.1",
"@ucanto/principal": "^9.0.1",
"@web3-storage/did-mailto": "workspace:^",
"@web3-storage/w3up-client": "workspace:^"
}
}
34 changes: 34 additions & 0 deletions packages/use-cases/transfer-control-of-space.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env node

import { create } from '@web3-storage/w3up-client'
import { delegate } from '@ucanto/core'
import { Absentee } from '@ucanto/principal'
import * as DidMailto from '@web3-storage/did-mailto'

const CURRENT_EMAIL = '[email protected]'
const NEW_EMAIL = '[email protected]'
const SPACE_DID_TO_DELEGATE = 'did:key:asdf'

const newAccountDID = DidMailto.fromEmail(NEW_EMAIL)

const client = await create()
await client.login(CURRENT_EMAIL)


// Register a delegation with the service that grants all capabilities on
// the given space to NEW_EMAIL.
//
// The resulting delegation will delegate from CURRENT_EMAIL to the local agent
// and then to NEW_EMAIL which is a little ugly.
await client.capability.access.delegate({
space: SPACE_DID_TO_DELEGATE,
delegations:
[await delegate({
issuer: client.agent.issuer,
audience: Absentee.from({ id: newAccountDID }),
capabilities: [{
with: SPACE_DID_TO_DELEGATE,
can: '*'
}]
})]
})
Loading
Loading