From 945784105d54f2b7d051f58dfead48b18a861999 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 13 Dec 2022 07:18:46 +0000 Subject: [PATCH] fix: add expiration parameter (#21) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If you don't set this the UCANs expire immediately 🙈. --- bin.js | 1 + index.js | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bin.js b/bin.js index 92eb1fd..486b0da 100755 --- a/bin.js +++ b/bin.js @@ -63,6 +63,7 @@ cli.command('delegation create ') .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) diff --git a/index.js b/index.js index a0f2942..a5b814c 100644 --- a/index.js +++ b/index.js @@ -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) { @@ -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()