Skip to content

Commit

Permalink
rm cacaoDomain
Browse files Browse the repository at this point in the history
  • Loading branch information
stbrody committed Jun 3, 2024
1 parent c8292b8 commit 87aef31
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 19 deletions.
19 changes: 1 addition & 18 deletions src/ancillary/anchor-request-params-parser.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import type { Request as ExpReq } from 'express'
import { CID as CIDObj } from 'multiformats/cid'
import { CARFactory, type CAR } from 'cartonne'
import { CARFactory } from 'cartonne'
import { ServiceMetrics as Metrics } from '@ceramicnetwork/observability'
import { base64urlToJSON } from '@ceramicnetwork/common'
import { METRIC_NAMES } from '../settings.js'
import * as DAG_JOSE from 'dag-jose'
import { logger } from '../logger/index.js'
import {
uint8array,
cid,
Expand Down Expand Up @@ -55,7 +52,6 @@ export const RequestAnchorParamsV2 = sparse({
streamId: streamIdAsString,
timestamp: date,
cid: cidAsString,
cacaoDomain: optional(string)
})

export type RequestAnchorParamsV2 = TypeOf<typeof RequestAnchorParamsV2>
Expand All @@ -80,31 +76,18 @@ export class AnchorRequestCarFileDecoder implements Decoder<Uint8Array, RequestA
const rootE = RequestAnchorParamsV2Root.decode(rootRecord, context)
if (isLeft(rootE)) return context.failures(rootE.left)
const root = rootE.right
const cacaoDomain = this.extractCacaoDomain(rootRecord, carFile)

return context.success({
streamId: root.streamId,
timestamp: root.timestamp,
cid: root.tip,
cacaoDomain: cacaoDomain,
})
} catch (e: any) {
const message = e.message || String(e)
return context.failure(`Can not decode CAR file: ${message}`)
}
}

private extractCacaoDomain(rootRecord: any, carFile: CAR): string {
try {
const tipProtectedHeader = base64urlToJSON(carFile.get(rootRecord.tip).signatures[0].protected)
return carFile.get(CIDObj.parse(tipProtectedHeader['cap'].replace('ipfs://', ''))).p.domain
} catch (e: any) {
const message = e.message || String(e)
logger.warn(`Error extracting cacao: ${message}`)
return ''
}
}

}

export class AnchorRequestParamsParser {
Expand Down
1 change: 0 additions & 1 deletion src/services/request-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ export class RequestService {
cid: request.cid,
stream: request.streamId,
origin: request.origin,
cacao: 'cacaoDomain' in params ? params.cacaoDomain : '',
}

// DO NOT REMOVE - this logging is used by business metrics
Expand Down

0 comments on commit 87aef31

Please sign in to comment.