Skip to content

Commit

Permalink
fix: enable storefront signer to be different from main service signer (
Browse files Browse the repository at this point in the history
storacha#1072)

Per storacha/w3filecoin-infra#52 make
storefront now same signer as aggregator to enable receipt chain
  • Loading branch information
vasco-santos authored Nov 4, 2023
1 parent 45bf06a commit 21ded3c
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 58 deletions.
4 changes: 2 additions & 2 deletions packages/filecoin-api/src/storefront/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface ServiceContext {
/**
* Service signer
*/
id: Signer
storefrontSigner: Signer
/**
* Principal for aggregator service
*/
Expand Down Expand Up @@ -86,7 +86,7 @@ export interface StorefrontClientContext {
export interface CronContext
extends Pick<
ServiceContext,
'id' | 'pieceStore' | 'receiptStore' | 'taskStore' | 'aggregatorId'
'storefrontSigner' | 'pieceStore' | 'receiptStore' | 'taskStore' | 'aggregatorId'
> {}

export interface PieceRecord {
Expand Down
2 changes: 1 addition & 1 deletion packages/filecoin-api/src/storefront/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export const handleCronTick = async (context) => {
const updatedResponses = await Promise.all(
submittedPieces.ok.map((pieceRecord) =>
updatePiecesWithDeal({
id: context.id,
id: context.storefrontSigner,
aggregatorId: context.aggregatorId,
pieceRecord,
pieceStore: context.pieceStore,
Expand Down
26 changes: 13 additions & 13 deletions packages/filecoin-api/src/storefront/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const filecoinOffer = async ({ capability }, context) => {
return { error: new StoreOperationFailed(hasRes.error.message) }
}

const group = context.id.did()
const group = context.storefrontSigner.did()
if (!hasRes.ok) {
// Queue the piece for validation etc.
const queueRes = await context.filecoinSubmitQueue.add({
Expand All @@ -46,9 +46,9 @@ export const filecoinOffer = async ({ capability }, context) => {
const [submitfx, acceptfx] = await Promise.all([
StorefrontCaps.filecoinSubmit
.invoke({
issuer: context.id,
audience: context.id,
with: context.id.did(),
issuer: context.storefrontSigner,
audience: context.storefrontSigner,
with: context.storefrontSigner.did(),
nb: {
piece,
content,
Expand All @@ -58,9 +58,9 @@ export const filecoinOffer = async ({ capability }, context) => {
.delegate(),
StorefrontCaps.filecoinAccept
.invoke({
issuer: context.id,
audience: context.id,
with: context.id.did(),
issuer: context.storefrontSigner,
audience: context.storefrontSigner,
with: context.storefrontSigner.did(),
nb: {
piece,
content,
Expand All @@ -83,7 +83,7 @@ export const filecoinOffer = async ({ capability }, context) => {
*/
export const filecoinSubmit = async ({ capability }, context) => {
const { piece, content } = capability.nb
const group = context.id.did()
const group = context.storefrontSigner.did()

// Queue `piece/offer` invocation
const res = await context.pieceOfferQueue.add({
Expand All @@ -100,9 +100,9 @@ export const filecoinSubmit = async ({ capability }, context) => {
// Create effect for receipt
const fx = await AggregatorCaps.pieceOffer
.invoke({
issuer: context.id,
issuer: context.storefrontSigner,
audience: context.aggregatorId,
with: context.id.did(),
with: context.storefrontSigner.did(),
nb: {
piece,
group,
Expand Down Expand Up @@ -132,9 +132,9 @@ export const filecoinAccept = async ({ capability }, context) => {
const { group } = getPieceRes.ok
const fx = await AggregatorCaps.pieceOffer
.invoke({
issuer: context.id,
issuer: context.storefrontSigner,
audience: context.aggregatorId,
with: context.id.did(),
with: context.storefrontSigner.did(),
nb: {
piece,
group,
Expand Down Expand Up @@ -267,7 +267,7 @@ export function createService(context) {
*/
export const createServer = (context) =>
Server.create({
id: context.id,
id: context.storefrontSigner,
codec: context.codec || CAR.inbound,
service: createService(context),
catch: (error) => context.errorReporter.catch(error),
Expand Down
26 changes: 13 additions & 13 deletions packages/filecoin-api/test/events/storefront.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const test = {
const message = {
piece: cargo.link.link(),
content: cargo.content.link(),
group: context.id.did(),
group: context.storefrontSigner.did(),
}

// Handle message
Expand All @@ -60,7 +60,7 @@ export const test = {
const message = {
piece: cargo.link.link(),
content: cargo.content.link(),
group: context.id.did(),
group: context.storefrontSigner.did(),
}
/** @type {PieceRecord} */
const pieceRecord = {
Expand Down Expand Up @@ -95,7 +95,7 @@ export const test = {
const message = {
piece: cargo.link.link(),
content: cargo.content.link(),
group: context.id.did(),
group: context.storefrontSigner.did(),
}

// Handle message
Expand All @@ -117,7 +117,7 @@ export const test = {
const message = {
piece: cargo.link.link(),
content: cargo.content.link(),
group: context.id.did(),
group: context.storefrontSigner.did(),
}

// Handle message
Expand Down Expand Up @@ -150,7 +150,7 @@ export const test = {
const message = {
piece: cargo.link.link(),
content: cargo.content.link(),
group: context.id.did(),
group: context.storefrontSigner.did(),
}

// Handle message
Expand Down Expand Up @@ -185,8 +185,8 @@ export const test = {
aggregatorService: {
connection: aggregatorConnection,
invocationConfig: {
issuer: context.id,
with: context.id.did(),
issuer: context.storefrontSigner,
with: context.storefrontSigner.did(),
audience: aggregatorSigner,
},
},
Expand All @@ -201,7 +201,7 @@ export const test = {
const message = {
piece: cargo.link.link(),
content: cargo.content.link(),
group: context.id.did(),
group: context.storefrontSigner.did(),
}
/** @type {PieceRecord} */
const pieceRecord = {
Expand Down Expand Up @@ -242,7 +242,7 @@ export const test = {
const message = {
piece: cargo.link.link(),
content: cargo.content.link(),
group: context.id.did(),
group: context.storefrontSigner.did(),
}
/** @type {PieceRecord} */
const pieceRecord = {
Expand Down Expand Up @@ -286,7 +286,7 @@ export const test = {
const message = {
piece: cargo.link.link(),
content: cargo.content.link(),
group: context.id.did(),
group: context.storefrontSigner.did(),
}
/** @type {PieceRecord} */
const pieceRecord = {
Expand All @@ -309,7 +309,7 @@ export const test = {
context
) => {
const { dealer } = await getServiceContext()
const group = context.id.did()
const group = context.storefrontSigner.did()

// Create piece and aggregate for test
const { aggregate, pieces } = await randomAggregate(10, 128)
Expand All @@ -323,7 +323,7 @@ export const test = {
const putRes = await context.pieceStore.put({
piece: p.link,
content: p.content,
group: context.id.did(),
group: context.storefrontSigner.did(),
status: 'submitted',
insertedAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
Expand Down Expand Up @@ -359,7 +359,7 @@ export const test = {
// Create invocation and receipts chain until deal
const { invocations, receipts } =
await createInvocationsAndReceiptsForDealDataProofChain({
storefront: context.id,
storefront: context.storefrontSigner,
aggregator: context.aggregatorId,
dealer,
aggregate: aggregate.link,
Expand Down
54 changes: 27 additions & 27 deletions packages/filecoin-api/test/services/storefront.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const test = {
async (assert, context) => {
const { agent } = await getServiceContext()
const connection = connect({
id: context.id,
id: context.storefrontSigner,
channel: createServer(context),
})

Expand Down Expand Up @@ -58,9 +58,9 @@ export const test = {
// Validate effects in receipt
const fxFork = await Filecoin.submit
.invoke({
issuer: context.id,
audience: context.id,
with: context.id.did(),
issuer: context.storefrontSigner,
audience: context.storefrontSigner,
with: context.storefrontSigner.did(),
nb: {
piece: cargo.link.link(),
content: cargo.content.link(),
Expand All @@ -70,9 +70,9 @@ export const test = {
.delegate()
const fxJoin = await Filecoin.accept
.invoke({
issuer: context.id,
audience: context.id,
with: context.id.did(),
issuer: context.storefrontSigner,
audience: context.storefrontSigner,
with: context.storefrontSigner.did(),
nb: {
piece: cargo.link.link(),
content: cargo.content.link(),
Expand Down Expand Up @@ -101,7 +101,7 @@ export const test = {
async (assert, context) => {
const { agent } = await getServiceContext()
const connection = connect({
id: context.id,
id: context.storefrontSigner,
channel: createServer(context),
})

Expand All @@ -112,7 +112,7 @@ export const test = {
const putRes = await context.pieceStore.put({
piece: cargo.link.link(),
content: cargo.content.link(),
group: context.id.did(),
group: context.storefrontSigner.did(),
status: 'submitted',
insertedAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
Expand Down Expand Up @@ -140,9 +140,9 @@ export const test = {
// Validate effects in receipt
const fxFork = await Filecoin.submit
.invoke({
issuer: context.id,
audience: context.id,
with: context.id.did(),
issuer: context.storefrontSigner,
audience: context.storefrontSigner,
with: context.storefrontSigner.did(),
nb: {
piece: cargo.link.link(),
content: cargo.content.link(),
Expand All @@ -152,9 +152,9 @@ export const test = {
.delegate()
const fxJoin = await Filecoin.accept
.invoke({
issuer: context.id,
audience: context.id,
with: context.id.did(),
issuer: context.storefrontSigner,
audience: context.storefrontSigner,
with: context.storefrontSigner.did(),
nb: {
piece: cargo.link.link(),
content: cargo.content.link(),
Expand All @@ -178,7 +178,7 @@ export const test = {
async (assert, context) => {
const { agent } = await getServiceContext()
const connection = connect({
id: context.id,
id: context.storefrontSigner,
channel: createServer(context),
})

Expand Down Expand Up @@ -210,7 +210,7 @@ export const test = {
async (assert, context) => {
const { agent } = await getServiceContext()
const connection = connect({
id: context.id,
id: context.storefrontSigner,
channel: createServer(context),
})

Expand Down Expand Up @@ -241,7 +241,7 @@ export const test = {
async (assert, context) => {
const { agent } = await getServiceContext()
const connection = connect({
id: context.id,
id: context.storefrontSigner,
channel: createServer(context),
})

Expand All @@ -267,12 +267,12 @@ export const test = {
// Validate effects in receipt
const fxJoin = await Aggregator.pieceOffer
.invoke({
issuer: context.id,
issuer: context.storefrontSigner,
audience: context.aggregatorId,
with: context.id.did(),
with: context.storefrontSigner.did(),
nb: {
piece: cargo.link.link(),
group: context.id.did(),
group: context.storefrontSigner.did(),
},
expiration: Infinity,
})
Expand All @@ -286,7 +286,7 @@ export const test = {
async (assert, context) => {
const { agent } = await getServiceContext()
const connection = connect({
id: context.id,
id: context.storefrontSigner,
channel: createServer(context),
})

Expand Down Expand Up @@ -316,9 +316,9 @@ export const test = {
context
) => {
const { agent, aggregator, dealer } = await getServiceContext()
const group = context.id.did()
const group = context.storefrontSigner.did()
const connection = connect({
id: context.id,
id: context.storefrontSigner,
channel: createServer({
...context,
aggregatorId: aggregator,
Expand All @@ -335,7 +335,7 @@ export const test = {
const putRes = await context.pieceStore.put({
piece: piece.link,
content: piece.content,
group: context.id.did(),
group: context.storefrontSigner.did(),
status: 'submitted',
insertedAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
Expand All @@ -357,7 +357,7 @@ export const test = {
}
const { invocations, receipts } =
await createInvocationsAndReceiptsForDealDataProofChain({
storefront: context.id,
storefront: context.storefrontSigner,
aggregator,
dealer,
aggregate: aggregate.link,
Expand Down Expand Up @@ -427,7 +427,7 @@ export const test = {
async (assert, context) => {
const { agent } = await getServiceContext()
const connection = connect({
id: context.id,
id: context.storefrontSigner,
channel: createServer(context),
})

Expand Down
2 changes: 2 additions & 0 deletions packages/filecoin-api/test/storefront.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('storefront', () => {
},
{
id: storefrontSigner,
storefrontSigner,
aggregatorId: aggregatorSigner,
errorReporter: {
catch(error) {
Expand Down Expand Up @@ -92,6 +93,7 @@ describe('storefront', () => {
},
{
id: storefrontSigner,
storefrontSigner,
aggregatorId: aggregatorSigner,
pieceStore,
receiptStore,
Expand Down
Loading

0 comments on commit 21ded3c

Please sign in to comment.