diff --git a/packages/access-api/src/service/upload-api-proxy.js b/packages/access-api/src/service/upload-api-proxy.js index d23939587..606645bab 100644 --- a/packages/access-api/src/service/upload-api-proxy.js +++ b/packages/access-api/src/service/upload-api-proxy.js @@ -16,7 +16,6 @@ import { createProxyHandler } from '../ucanto/proxy.js' * @template {string|number|symbol} M * @template {Ucanto.ConnectionView} [Connection=Ucanto.ConnectionView] * @param {object} options - * @param {Ucanto.Signer} options.signer * @param {Array} options.methods * @param {{ default: Connection } & Record} options.connections */ @@ -97,7 +96,6 @@ function getDefaultConnections(options) { /** * @template {Ucanto.ConnectionView} [Connection=Ucanto.ConnectionView] * @param {object} options - * @param {Ucanto.Signer} options.signer * @param {typeof globalThis.fetch} [options.fetch] * @param {{ default: Connection, [K: Ucanto.UCAN.DID]: Connection }} [options.connections] * @param {Record} [options.audienceToUrl] @@ -116,7 +114,6 @@ export function createUploadProxy(options) { /** * @template {Ucanto.ConnectionView} [Connection=Ucanto.ConnectionView] * @param {object} options - * @param {Ucanto.Signer} options.signer * @param {typeof globalThis.fetch} [options.fetch] * @param {{ default: Connection, [K: Ucanto.UCAN.DID]: Connection }} [options.connections] * @param {Record} [options.audienceToUrl] diff --git a/packages/access-api/src/ucanto/client-codec.js b/packages/access-api/src/ucanto/client-codec.js index c16070494..fcd80c5bb 100644 --- a/packages/access-api/src/ucanto/client-codec.js +++ b/packages/access-api/src/ucanto/client-codec.js @@ -1,4 +1,3 @@ -import { Delegation } from '@ucanto/core' import * as UCAN from '@ipld/dag-ucan' import { UTF8 } from '@ucanto/transport' @@ -6,7 +5,7 @@ import { UTF8 } from '@ucanto/transport' export const clientCodec = { async encode(invocations, options) { const headers = new Headers() - const chain = await Delegation.delegate(invocations[0]) + const chain = await invocations[0].delegate() // TODO iterate over proofs and send them too // for (const ucan of chain.iterate()) { diff --git a/packages/access-api/src/ucanto/proxy.js b/packages/access-api/src/ucanto/proxy.js index 543ffe0e7..0f9909621 100644 --- a/packages/access-api/src/ucanto/proxy.js +++ b/packages/access-api/src/ucanto/proxy.js @@ -47,35 +47,23 @@ function defaultCatchInvocationError(error) { * @param {object} options * @param {(error: unknown) => Promise} [options.catchInvocationError] - catches any error that comes from invoking the proxy invocation on the connection. If it returns a value, that value will be the proxied invocation result. * @param {{ default: Connection, [K: Ucanto.UCAN.DID]: Connection }} options.connections - * @param {Ucanto.Signer} options.signer */ export function createProxyHandler(options) { /** * @template {import('@ucanto/interface').Capability} Capability - * @param {Ucanto.Invocation} invocationIn + * @param {Ucanto.Invocation} invocation * @param {Ucanto.InvocationContext} context * @returns {Promise>} */ - return async function handleInvocation(invocationIn, context) { - const { - connections, - signer, - catchInvocationError = defaultCatchInvocationError, - } = options - const { audience, capabilities, expiration, notBefore } = invocationIn - const connection = connections[audience.did()] ?? connections.default - const proxyInvocation = Client.invoke({ - issuer: signer, - capability: capabilities[0], - audience, - proofs: [invocationIn], - expiration, - notBefore, - }) + return async function handleInvocation(invocation, context) { + const { connections, catchInvocationError = defaultCatchInvocationError } = + options + const connection = + connections[invocation.audience.did()] ?? connections.default try { const [result] = await Client.execute( - [proxyInvocation], - /** @type {Client.ConnectionView} */ (connection) + [await invocation.delegate()], + connection ) return result } catch (error) { diff --git a/packages/access-api/test/ucanto-proxy.test.js b/packages/access-api/test/ucanto-proxy.test.js index fb7ef3f6b..e6f873564 100644 --- a/packages/access-api/test/ucanto-proxy.test.js +++ b/packages/access-api/test/ucanto-proxy.test.js @@ -45,7 +45,6 @@ describe('ucanto-proxy', () => { service: { test: { succeed: createProxyHandler({ - signer: proxyPrincipal, connections: { default: Client.connect({ id: upstreamPrincipal, @@ -117,7 +116,6 @@ describe('ucanto-proxy', () => { service: { test: { succeed: createProxyHandler({ - signer: upstreamPrincipal, connections: { default: Client.connect({ id: upstreamPrincipal,