-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start access/delegate invocation handler in access-api (and access-cl…
…ient types)
- Loading branch information
Showing
6 changed files
with
106 additions
and
1 deletion.
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,11 @@ | ||
import * as Server from '@ucanto/server' | ||
import { delegate } from '@web3-storage/capabilities/access' | ||
|
||
/** | ||
* @param {import('../bindings').RouteContext} ctx | ||
*/ | ||
export function accessDelegateProvider(ctx) { | ||
return Server.provide(delegate, async ({ capability, invocation }) => { | ||
return {} | ||
}) | ||
} |
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,79 @@ | ||
import { context } from './helpers/context.js' | ||
import * as Access from '@web3-storage/capabilities/access' | ||
import * as assert from 'node:assert' | ||
// eslint-disable-next-line no-unused-vars | ||
import * as Ucanto from '@ucanto/interface' | ||
import { delegate } from '@ucanto/core' | ||
|
||
describe('access/delegate', function () { | ||
for (const [variantName, createInvocation] of Object.entries( | ||
namedDelegateVariants() | ||
)) { | ||
it(`handles invocation variant ${variantName}`, async () => { | ||
const { service, conn, issuer } = await context() | ||
const invocation = await createInvocation({ issuer, audience: service }) | ||
const [result] = await conn.execute(invocation) | ||
assert.notDeepEqual( | ||
result.error, | ||
true, | ||
'invocation result is not an error' | ||
) | ||
}) | ||
} | ||
}) | ||
|
||
/** | ||
* @typedef {(options: { issuer: Ucanto.Signer<Ucanto.DID<'key'>>, audience: Ucanto.Principal }) => Promise<Ucanto.Delegation<[Ucanto.InferInvokedCapability<typeof Access.delegate>]>>} AccessDelegateInvocationFactory | ||
*/ | ||
|
||
/** | ||
* create valid delegate invocation with an empty delegation set | ||
* | ||
* @type {AccessDelegateInvocationFactory} | ||
*/ | ||
function withEmptyDelegationSet({ issuer, audience }) { | ||
return Access.delegate | ||
.invoke({ | ||
issuer, | ||
audience, | ||
with: issuer.did(), | ||
nb: { | ||
delegations: {}, | ||
}, | ||
}) | ||
.delegate() | ||
} | ||
|
||
/** | ||
* create a valid delegate invocation with a single delegation in nb.delegations set | ||
* | ||
* @type {AccessDelegateInvocationFactory} | ||
*/ | ||
async function withSingleDelegation({ issuer, audience }) { | ||
return Access.delegate | ||
.invoke({ | ||
issuer, | ||
audience, | ||
with: issuer.did(), | ||
nb: { | ||
delegations: { | ||
notACid: await delegate({ | ||
issuer, | ||
audience, | ||
capabilities: [{ can: '*', with: 'urn:foo' }], | ||
}).then(({ cid }) => cid), | ||
}, | ||
}, | ||
}) | ||
.delegate() | ||
} | ||
|
||
/** | ||
* @returns {Record<string, AccessDelegateInvocationFactory>} | ||
*/ | ||
function namedDelegateVariants() { | ||
return { | ||
withEmptyDelegationSet, | ||
withSingleDelegation, | ||
} | ||
} |
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