-
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
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.