Skip to content

Commit

Permalink
chore: replace decentraland-crypto-middleware with platform-crypto-mi…
Browse files Browse the repository at this point in the history
…ddleware (#168)
  • Loading branch information
hugoArregui authored Jul 26, 2023
1 parent 937fd79 commit badbee0
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 2,377 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules/
coverage
contents
.env
yarn-error.log
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@dcl/catalyst-storage": "^3.0.1",
"@dcl/crypto": "^3.4.3",
"@dcl/hashing": "^3.0.1",
"@dcl/platform-crypto-middleware": "^1.0.1",
"@dcl/protocol": "^1.0.0-5623934099.commit-07e0626",
"@dcl/schemas": "^8.2.2",
"@types/busboy": "^1.5.0",
Expand All @@ -26,7 +27,6 @@
"@well-known-components/metrics": "^2.0.1",
"@well-known-components/thegraph-component": "^1.6.0",
"busboy": "^1.6.0",
"decentraland-crypto-middleware": "^1.1.0",
"eth-connect": "^6.2.0",
"livekit-server-sdk": "^1.2.5",
"lru-cache": "^7.18.3",
Expand Down
11 changes: 6 additions & 5 deletions src/controllers/handlers/cast-adapter-handler.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { HandlerContextWithPath, InvalidRequestError, NotFoundError } from '../../types'
import { IHttpServerComponent } from '@well-known-components/interfaces'
import { DecentralandSignatureContext } from 'decentraland-crypto-middleware/lib/types'
import verify from 'decentraland-crypto-middleware/lib/verify'
import { DecentralandSignatureContext, verify } from '@dcl/platform-crypto-middleware'
import { allowedByAcl } from '../../logic/acl'
import { AccessToken } from 'livekit-server-sdk'

export async function castAdapterHandler(
context: HandlerContextWithPath<
'config' | 'storage' | 'namePermissionChecker' | 'worldsManager',
'config' | 'storage' | 'namePermissionChecker' | 'worldsManager' | 'fetch',
'/meet-adapter/:roomId'
> &
DecentralandSignatureContext<any>
): Promise<IHttpServerComponent.IResponse> {
const {
components: { config, storage }
components: { config, storage, fetch }
} = context

const apiKey = await config.requireString('LIVEKIT_API_KEY')
Expand All @@ -25,7 +24,9 @@ export async function castAdapterHandler(
const path = new URL(baseUrl + context.url.pathname)

try {
context.verification = await verify(context.request.method, path.pathname, context.request.headers.raw(), {})
context.verification = await verify(context.request.method, path.pathname, context.request.headers.raw(), {
fetcher: fetch
})
} catch (e) {
return {
status: 401,
Expand Down
11 changes: 6 additions & 5 deletions src/controllers/handlers/comms-adapter-handler.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { HandlerContextWithPath, InvalidRequestError, NotFoundError } from '../../types'
import { IHttpServerComponent } from '@well-known-components/interfaces'
import { DecentralandSignatureContext } from 'decentraland-crypto-middleware/lib/types'
import verify from 'decentraland-crypto-middleware/lib/verify'
import { verify, DecentralandSignatureContext } from '@dcl/platform-crypto-middleware'

export async function commsAdapterHandler(
context: HandlerContextWithPath<'commsAdapter' | 'config' | 'storage', '/get-comms-adapter/:roomId'> &
context: HandlerContextWithPath<'commsAdapter' | 'config' | 'storage' | 'fetch', '/get-comms-adapter/:roomId'> &
DecentralandSignatureContext<any>
): Promise<IHttpServerComponent.IResponse> {
const {
components: { commsAdapter, config, storage }
components: { commsAdapter, config, storage, fetch }
} = context

const baseUrl = (await config.getString('HTTP_BASE_URL')) || `${context.url.protocol}//${context.url.host}`

const path = new URL(baseUrl + context.url.pathname)

try {
context.verification = await verify(context.request.method, path.pathname, context.request.headers.raw(), {})
context.verification = await verify(context.request.method, path.pathname, context.request.headers.raw(), {
fetcher: fetch
})
} catch (e) {
return {
status: 401,
Expand Down
11 changes: 6 additions & 5 deletions src/controllers/handlers/meet-adapter-handler.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { HandlerContextWithPath, InvalidRequestError, NotFoundError } from '../../types'
import { IHttpServerComponent } from '@well-known-components/interfaces'
import { DecentralandSignatureContext } from 'decentraland-crypto-middleware/lib/types'
import verify from 'decentraland-crypto-middleware/lib/verify'
import { allowedByAcl } from '../../logic/acl'
import { verify, DecentralandSignatureContext } from '@dcl/platform-crypto-middleware'

export async function meetAdapterHandler(
context: HandlerContextWithPath<
'commsAdapter' | 'config' | 'storage' | 'namePermissionChecker' | 'worldsManager',
'commsAdapter' | 'config' | 'storage' | 'namePermissionChecker' | 'worldsManager' | 'fetch',
'/meet-adapter/:roomId'
> &
DecentralandSignatureContext<any>
): Promise<IHttpServerComponent.IResponse> {
const {
components: { commsAdapter, config, storage }
components: { commsAdapter, config, storage, fetch }
} = context

const baseUrl = (
Expand All @@ -21,7 +20,9 @@ export async function meetAdapterHandler(
const path = new URL(baseUrl + context.url.pathname)

try {
context.verification = await verify(context.request.method, path.pathname, context.request.headers.raw(), {})
context.verification = await verify(context.request.method, path.pathname, context.request.headers.raw(), {
fetcher: fetch
})
} catch (e) {
return {
status: 401,
Expand Down
6 changes: 1 addition & 5 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import { Readable } from 'stream'
import { IContentStorageComponent } from '@dcl/catalyst-storage'
import { stringToUtf8Bytes } from 'eth-connect'
import { AuthChain } from '@dcl/schemas'
import {
AUTH_CHAIN_HEADER_PREFIX,
AUTH_METADATA_HEADER,
AUTH_TIMESTAMP_HEADER
} from 'decentraland-crypto-middleware/lib/types'
import { AUTH_CHAIN_HEADER_PREFIX, AUTH_METADATA_HEADER, AUTH_TIMESTAMP_HEADER } from '@dcl/platform-crypto-middleware'

export async function storeJson(storage: IContentStorageComponent, fileId: string, data: any) {
const buffer = stringToUtf8Bytes(JSON.stringify(data))
Expand Down
Loading

0 comments on commit badbee0

Please sign in to comment.