-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: provision using a proof (#123)
Adds a couple of more commands `w3 coupon create did:...` - That can be used to create delegation and pack it as a redeemable coupon. `w3 space provision --coupon https://gozala.io/coupon` - That can be used to provision space with pre-arranged coupon `w3 plan get` - Prints current plan info All the above are in support of the workshop and specifically so we could create short lived coupon for workshop participants that would allow them to provision spaces without signing up as customer.
- Loading branch information
Showing
10 changed files
with
514 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import { getPkg } from './lib.js' | |
import { | ||
Account, | ||
Space, | ||
Coupon, | ||
accessClaim, | ||
addSpace, | ||
listSpaces, | ||
|
@@ -21,7 +22,8 @@ import { | |
remove, | ||
list, | ||
whoami, | ||
usageReport | ||
usageReport, | ||
getPlan, | ||
} from './index.js' | ||
import { | ||
storeAdd, | ||
|
@@ -30,7 +32,7 @@ import { | |
uploadAdd, | ||
uploadList, | ||
uploadRemove, | ||
filecoinInfo | ||
filecoinInfo, | ||
} from './can.js' | ||
|
||
const pkg = getPkg() | ||
|
@@ -52,6 +54,12 @@ cli | |
) | ||
.action(Account.login) | ||
|
||
cli | ||
.command('plan get [email]') | ||
.example('plan get [email protected]') | ||
.describe('Displays plan given account is on') | ||
.action(getPlan) | ||
|
||
cli | ||
.command('account ls') | ||
.alias('account list') | ||
|
@@ -122,6 +130,8 @@ cli | |
.command('space provision [name]') | ||
.describe('Associating space with a billing account') | ||
.option('-c, --customer', 'The email address of the billing account') | ||
.option('--coupon', 'Coupon URL to provision space with') | ||
.option('-p, -password', 'Coupon password') | ||
.option( | ||
'-p, --provider', | ||
'The storage provider to associate with this space.' | ||
|
@@ -152,6 +162,21 @@ cli | |
.describe('Set the current space in use by the agent') | ||
.action(useSpace) | ||
|
||
cli | ||
.command('coupon create <did>') | ||
.option('--password', 'Password for created coupon.') | ||
.option('-c, --can', 'One or more abilities to delegate.') | ||
.option( | ||
'-e, --expiration', | ||
'Unix timestamp when the delegation is no longer valid. Zero indicates no expiration.', | ||
0 | ||
) | ||
.option( | ||
'-o, --output', | ||
'Path of file to write the exported delegation data to.' | ||
) | ||
.action(Coupon.issue) | ||
|
||
cli | ||
.command('delegation create <audience-did>') | ||
.describe( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import fs from 'node:fs/promises' | ||
import * as DID from '@ipld/dag-ucan/did' | ||
import * as Account from './account.js' | ||
import * as Space from './space.js' | ||
import { getClient } from './lib.js' | ||
import * as ucanto from '@ucanto/core' | ||
|
||
export { Account, Space } | ||
|
||
/** | ||
* @typedef {object} CouponIssueOptions | ||
* @property {string} customer | ||
* @property {string[]|string} [can] | ||
* @property {string} [password] | ||
* @property {number} [expiration] | ||
* @property {string} [output] | ||
* | ||
* @param {string} customer | ||
* @param {CouponIssueOptions} options | ||
*/ | ||
export const issue = async ( | ||
customer, | ||
{ can = 'provider/add', expiration, password, output } | ||
) => { | ||
const client = await getClient() | ||
|
||
const audience = DID.parse(customer) | ||
const abilities = can ? [can].flat() : [] | ||
if (!abilities.length) { | ||
console.error('Error: missing capabilities for delegation') | ||
process.exit(1) | ||
} | ||
|
||
const capabilities = /** @type {ucanto.API.Capabilities} */ ( | ||
abilities.map((can) => ({ can, with: audience.did() })) | ||
) | ||
|
||
const coupon = await client.coupon.issue({ | ||
capabilities, | ||
expiration: expiration === 0 ? Infinity : expiration, | ||
password, | ||
}) | ||
|
||
const { ok: bytes, error } = await coupon.archive() | ||
if (!bytes) { | ||
console.error(error) | ||
return process.exit(1) | ||
} | ||
|
||
if (output) { | ||
await fs.writeFile(output, bytes) | ||
} else { | ||
process.stdout.write(bytes) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.