From 80cdde0f5b610cf6328dc17cb505759eddda821a Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Sun, 5 Nov 2023 15:15:55 +0100 Subject: [PATCH] fix: revert enable storefront signer to be different from main service signer (#1075) This reverts commit 21ded3c171ca66480e4f74329943527dcc2bac3e **(#1072)** --- packages/filecoin-api/src/storefront/api.ts | 4 +- .../filecoin-api/src/storefront/events.js | 2 +- .../filecoin-api/src/storefront/service.js | 26 ++++----- .../filecoin-api/test/events/storefront.js | 26 ++++----- .../filecoin-api/test/services/storefront.js | 54 +++++++++---------- packages/filecoin-api/test/storefront.spec.js | 2 - packages/filecoin-api/test/types.ts | 2 +- packages/upload-api/src/lib.js | 1 + packages/upload-api/test/helpers/context.js | 1 - 9 files changed, 58 insertions(+), 60 deletions(-) diff --git a/packages/filecoin-api/src/storefront/api.ts b/packages/filecoin-api/src/storefront/api.ts index 26053dd0a..4a06ed0de 100644 --- a/packages/filecoin-api/src/storefront/api.ts +++ b/packages/filecoin-api/src/storefront/api.ts @@ -35,7 +35,7 @@ export interface ServiceContext { /** * Service signer */ - storefrontSigner: Signer + id: Signer /** * Principal for aggregator service */ @@ -86,7 +86,7 @@ export interface StorefrontClientContext { export interface CronContext extends Pick< ServiceContext, - 'storefrontSigner' | 'pieceStore' | 'receiptStore' | 'taskStore' | 'aggregatorId' + 'id' | 'pieceStore' | 'receiptStore' | 'taskStore' | 'aggregatorId' > {} export interface PieceRecord { diff --git a/packages/filecoin-api/src/storefront/events.js b/packages/filecoin-api/src/storefront/events.js index 5eff60b4e..8b2981bbd 100644 --- a/packages/filecoin-api/src/storefront/events.js +++ b/packages/filecoin-api/src/storefront/events.js @@ -140,7 +140,7 @@ export const handleCronTick = async (context) => { const updatedResponses = await Promise.all( submittedPieces.ok.map((pieceRecord) => updatePiecesWithDeal({ - id: context.storefrontSigner, + id: context.id, aggregatorId: context.aggregatorId, pieceRecord, pieceStore: context.pieceStore, diff --git a/packages/filecoin-api/src/storefront/service.js b/packages/filecoin-api/src/storefront/service.js index 84c5b8c7b..42c25c1cd 100644 --- a/packages/filecoin-api/src/storefront/service.js +++ b/packages/filecoin-api/src/storefront/service.js @@ -26,7 +26,7 @@ export const filecoinOffer = async ({ capability }, context) => { return { error: new StoreOperationFailed(hasRes.error.message) } } - const group = context.storefrontSigner.did() + const group = context.id.did() if (!hasRes.ok) { // Queue the piece for validation etc. const queueRes = await context.filecoinSubmitQueue.add({ @@ -46,9 +46,9 @@ export const filecoinOffer = async ({ capability }, context) => { const [submitfx, acceptfx] = await Promise.all([ StorefrontCaps.filecoinSubmit .invoke({ - issuer: context.storefrontSigner, - audience: context.storefrontSigner, - with: context.storefrontSigner.did(), + issuer: context.id, + audience: context.id, + with: context.id.did(), nb: { piece, content, @@ -58,9 +58,9 @@ export const filecoinOffer = async ({ capability }, context) => { .delegate(), StorefrontCaps.filecoinAccept .invoke({ - issuer: context.storefrontSigner, - audience: context.storefrontSigner, - with: context.storefrontSigner.did(), + issuer: context.id, + audience: context.id, + with: context.id.did(), nb: { piece, content, @@ -83,7 +83,7 @@ export const filecoinOffer = async ({ capability }, context) => { */ export const filecoinSubmit = async ({ capability }, context) => { const { piece, content } = capability.nb - const group = context.storefrontSigner.did() + const group = context.id.did() // Queue `piece/offer` invocation const res = await context.pieceOfferQueue.add({ @@ -100,9 +100,9 @@ export const filecoinSubmit = async ({ capability }, context) => { // Create effect for receipt const fx = await AggregatorCaps.pieceOffer .invoke({ - issuer: context.storefrontSigner, + issuer: context.id, audience: context.aggregatorId, - with: context.storefrontSigner.did(), + with: context.id.did(), nb: { piece, group, @@ -132,9 +132,9 @@ export const filecoinAccept = async ({ capability }, context) => { const { group } = getPieceRes.ok const fx = await AggregatorCaps.pieceOffer .invoke({ - issuer: context.storefrontSigner, + issuer: context.id, audience: context.aggregatorId, - with: context.storefrontSigner.did(), + with: context.id.did(), nb: { piece, group, @@ -267,7 +267,7 @@ export function createService(context) { */ export const createServer = (context) => Server.create({ - id: context.storefrontSigner, + id: context.id, codec: context.codec || CAR.inbound, service: createService(context), catch: (error) => context.errorReporter.catch(error), diff --git a/packages/filecoin-api/test/events/storefront.js b/packages/filecoin-api/test/events/storefront.js index 3ee2dcd86..9de711d01 100644 --- a/packages/filecoin-api/test/events/storefront.js +++ b/packages/filecoin-api/test/events/storefront.js @@ -34,7 +34,7 @@ export const test = { const message = { piece: cargo.link.link(), content: cargo.content.link(), - group: context.storefrontSigner.did(), + group: context.id.did(), } // Handle message @@ -60,7 +60,7 @@ export const test = { const message = { piece: cargo.link.link(), content: cargo.content.link(), - group: context.storefrontSigner.did(), + group: context.id.did(), } /** @type {PieceRecord} */ const pieceRecord = { @@ -95,7 +95,7 @@ export const test = { const message = { piece: cargo.link.link(), content: cargo.content.link(), - group: context.storefrontSigner.did(), + group: context.id.did(), } // Handle message @@ -117,7 +117,7 @@ export const test = { const message = { piece: cargo.link.link(), content: cargo.content.link(), - group: context.storefrontSigner.did(), + group: context.id.did(), } // Handle message @@ -150,7 +150,7 @@ export const test = { const message = { piece: cargo.link.link(), content: cargo.content.link(), - group: context.storefrontSigner.did(), + group: context.id.did(), } // Handle message @@ -185,8 +185,8 @@ export const test = { aggregatorService: { connection: aggregatorConnection, invocationConfig: { - issuer: context.storefrontSigner, - with: context.storefrontSigner.did(), + issuer: context.id, + with: context.id.did(), audience: aggregatorSigner, }, }, @@ -201,7 +201,7 @@ export const test = { const message = { piece: cargo.link.link(), content: cargo.content.link(), - group: context.storefrontSigner.did(), + group: context.id.did(), } /** @type {PieceRecord} */ const pieceRecord = { @@ -242,7 +242,7 @@ export const test = { const message = { piece: cargo.link.link(), content: cargo.content.link(), - group: context.storefrontSigner.did(), + group: context.id.did(), } /** @type {PieceRecord} */ const pieceRecord = { @@ -286,7 +286,7 @@ export const test = { const message = { piece: cargo.link.link(), content: cargo.content.link(), - group: context.storefrontSigner.did(), + group: context.id.did(), } /** @type {PieceRecord} */ const pieceRecord = { @@ -309,7 +309,7 @@ export const test = { context ) => { const { dealer } = await getServiceContext() - const group = context.storefrontSigner.did() + const group = context.id.did() // Create piece and aggregate for test const { aggregate, pieces } = await randomAggregate(10, 128) @@ -323,7 +323,7 @@ export const test = { const putRes = await context.pieceStore.put({ piece: p.link, content: p.content, - group: context.storefrontSigner.did(), + group: context.id.did(), status: 'submitted', insertedAt: new Date().toISOString(), updatedAt: new Date().toISOString(), @@ -359,7 +359,7 @@ export const test = { // Create invocation and receipts chain until deal const { invocations, receipts } = await createInvocationsAndReceiptsForDealDataProofChain({ - storefront: context.storefrontSigner, + storefront: context.id, aggregator: context.aggregatorId, dealer, aggregate: aggregate.link, diff --git a/packages/filecoin-api/test/services/storefront.js b/packages/filecoin-api/test/services/storefront.js index 4bc100b40..928deac62 100644 --- a/packages/filecoin-api/test/services/storefront.js +++ b/packages/filecoin-api/test/services/storefront.js @@ -30,7 +30,7 @@ export const test = { async (assert, context) => { const { agent } = await getServiceContext() const connection = connect({ - id: context.storefrontSigner, + id: context.id, channel: createServer(context), }) @@ -58,9 +58,9 @@ export const test = { // Validate effects in receipt const fxFork = await Filecoin.submit .invoke({ - issuer: context.storefrontSigner, - audience: context.storefrontSigner, - with: context.storefrontSigner.did(), + issuer: context.id, + audience: context.id, + with: context.id.did(), nb: { piece: cargo.link.link(), content: cargo.content.link(), @@ -70,9 +70,9 @@ export const test = { .delegate() const fxJoin = await Filecoin.accept .invoke({ - issuer: context.storefrontSigner, - audience: context.storefrontSigner, - with: context.storefrontSigner.did(), + issuer: context.id, + audience: context.id, + with: context.id.did(), nb: { piece: cargo.link.link(), content: cargo.content.link(), @@ -101,7 +101,7 @@ export const test = { async (assert, context) => { const { agent } = await getServiceContext() const connection = connect({ - id: context.storefrontSigner, + id: context.id, channel: createServer(context), }) @@ -112,7 +112,7 @@ export const test = { const putRes = await context.pieceStore.put({ piece: cargo.link.link(), content: cargo.content.link(), - group: context.storefrontSigner.did(), + group: context.id.did(), status: 'submitted', insertedAt: new Date().toISOString(), updatedAt: new Date().toISOString(), @@ -140,9 +140,9 @@ export const test = { // Validate effects in receipt const fxFork = await Filecoin.submit .invoke({ - issuer: context.storefrontSigner, - audience: context.storefrontSigner, - with: context.storefrontSigner.did(), + issuer: context.id, + audience: context.id, + with: context.id.did(), nb: { piece: cargo.link.link(), content: cargo.content.link(), @@ -152,9 +152,9 @@ export const test = { .delegate() const fxJoin = await Filecoin.accept .invoke({ - issuer: context.storefrontSigner, - audience: context.storefrontSigner, - with: context.storefrontSigner.did(), + issuer: context.id, + audience: context.id, + with: context.id.did(), nb: { piece: cargo.link.link(), content: cargo.content.link(), @@ -178,7 +178,7 @@ export const test = { async (assert, context) => { const { agent } = await getServiceContext() const connection = connect({ - id: context.storefrontSigner, + id: context.id, channel: createServer(context), }) @@ -210,7 +210,7 @@ export const test = { async (assert, context) => { const { agent } = await getServiceContext() const connection = connect({ - id: context.storefrontSigner, + id: context.id, channel: createServer(context), }) @@ -241,7 +241,7 @@ export const test = { async (assert, context) => { const { agent } = await getServiceContext() const connection = connect({ - id: context.storefrontSigner, + id: context.id, channel: createServer(context), }) @@ -267,12 +267,12 @@ export const test = { // Validate effects in receipt const fxJoin = await Aggregator.pieceOffer .invoke({ - issuer: context.storefrontSigner, + issuer: context.id, audience: context.aggregatorId, - with: context.storefrontSigner.did(), + with: context.id.did(), nb: { piece: cargo.link.link(), - group: context.storefrontSigner.did(), + group: context.id.did(), }, expiration: Infinity, }) @@ -286,7 +286,7 @@ export const test = { async (assert, context) => { const { agent } = await getServiceContext() const connection = connect({ - id: context.storefrontSigner, + id: context.id, channel: createServer(context), }) @@ -316,9 +316,9 @@ export const test = { context ) => { const { agent, aggregator, dealer } = await getServiceContext() - const group = context.storefrontSigner.did() + const group = context.id.did() const connection = connect({ - id: context.storefrontSigner, + id: context.id, channel: createServer({ ...context, aggregatorId: aggregator, @@ -335,7 +335,7 @@ export const test = { const putRes = await context.pieceStore.put({ piece: piece.link, content: piece.content, - group: context.storefrontSigner.did(), + group: context.id.did(), status: 'submitted', insertedAt: new Date().toISOString(), updatedAt: new Date().toISOString(), @@ -357,7 +357,7 @@ export const test = { } const { invocations, receipts } = await createInvocationsAndReceiptsForDealDataProofChain({ - storefront: context.storefrontSigner, + storefront: context.id, aggregator, dealer, aggregate: aggregate.link, @@ -427,7 +427,7 @@ export const test = { async (assert, context) => { const { agent } = await getServiceContext() const connection = connect({ - id: context.storefrontSigner, + id: context.id, channel: createServer(context), }) diff --git a/packages/filecoin-api/test/storefront.spec.js b/packages/filecoin-api/test/storefront.spec.js index 2ee54f3b1..e5e76084d 100644 --- a/packages/filecoin-api/test/storefront.spec.js +++ b/packages/filecoin-api/test/storefront.spec.js @@ -38,7 +38,6 @@ describe('storefront', () => { }, { id: storefrontSigner, - storefrontSigner, aggregatorId: aggregatorSigner, errorReporter: { catch(error) { @@ -93,7 +92,6 @@ describe('storefront', () => { }, { id: storefrontSigner, - storefrontSigner, aggregatorId: aggregatorSigner, pieceStore, receiptStore, diff --git a/packages/filecoin-api/test/types.ts b/packages/filecoin-api/test/types.ts index 0ed68c377..d17cda9b6 100644 --- a/packages/filecoin-api/test/types.ts +++ b/packages/filecoin-api/test/types.ts @@ -40,7 +40,7 @@ export interface StorefrontTestEventsContext StorefrontInterface.PieceOfferMessageContext, StorefrontInterface.StorefrontClientContext, StorefrontInterface.CronContext { - storefrontSigner: Signer + id: Signer aggregatorId: Signer service: Partial<{ filecoin: Partial diff --git a/packages/upload-api/src/lib.js b/packages/upload-api/src/lib.js index f86087ec0..38a22e6b6 100644 --- a/packages/upload-api/src/lib.js +++ b/packages/upload-api/src/lib.js @@ -31,6 +31,7 @@ export const createServer = ({ id, codec = Legacy.inbound, ...context }) => codec, service: createService({ ...context, + id }), catch: (error) => context.errorReporter.catch(error), }) diff --git a/packages/upload-api/test/helpers/context.js b/packages/upload-api/test/helpers/context.js index 609d45ca7..ec93f5cd2 100644 --- a/packages/upload-api/test/helpers/context.js +++ b/packages/upload-api/test/helpers/context.js @@ -44,7 +44,6 @@ export const createContext = async (options = {}) => { /** @type { import('../../src/types.js').UcantoServerContext } */ const serviceContext = { id, - storefrontSigner: id, aggregatorId: aggregatorSigner, signer: id, email: Email.debug(),