Skip to content

Commit

Permalink
fix: add expiration parameter (#21)
Browse files Browse the repository at this point in the history
If you don't set this the UCANs expire immediately 🙈.
  • Loading branch information
Alan Shaw authored Dec 13, 2022
1 parent e25b809 commit 9457841
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ cli.command('delegation create <audience-did>')
.option('-c, --can', 'One or more abilities to delegate.', '*')
.option('-n, --name', 'Human readable name for the audience receiving the delegation.')
.option('-t, --type', 'Type of the audience receiving the delegation, one of: device, app, service.')
.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(createDelegation)

Expand Down
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export async function useSpace (did) {
* @param {string[]|string} opts.can
* @param {string} [opts.name]
* @param {string} [opts.type]
* @param {number} [opts.expiration]
* @param {string} [opts.output]
*/
export async function createDelegation (audienceDID, opts) {
Expand All @@ -198,9 +199,13 @@ export async function createDelegation (audienceDID, opts) {
const audienceMeta = {}
if (opts.name) audienceMeta.name = opts.name
if (opts.type) audienceMeta.type = opts.type
const expiration = opts.expiration || Infinity

// @ts-expect-error createDelegation should validate abilities
const delegation = await client.createDelegation(audience, abilities, { audienceMeta })
const delegation = await client.createDelegation(audience, abilities, {
expiration,
audienceMeta
})
delegation.export()

const { writer, out } = CarWriter.create()
Expand Down

0 comments on commit 9457841

Please sign in to comment.