1
1
import { Config } from 'sst/node/config'
2
- import { API , error , ok } from '@ucanto/core'
2
+ import { API } from '@ucanto/core'
3
3
import * as Delegation from '@ucanto/core/delegation'
4
4
import { CAR , Legacy , Codec } from '@ucanto/transport'
5
- import { DIDResolutionError , Schema } from '@ucanto/validator'
5
+ import { Schema } from '@ucanto/validator'
6
6
import * as Link from 'multiformats/link'
7
7
import { base64 } from 'multiformats/bases/base64'
8
8
import * as Sentry from '@sentry/serverless'
@@ -11,6 +11,7 @@ import Stripe from 'stripe'
11
11
import { Client as IndexingServiceClient } from '@storacha/indexing-service-client'
12
12
import * as UploadAPI from '@storacha/upload-api'
13
13
import * as UCANCaps from '@storacha/capabilities/ucan'
14
+ import { createDidResolver } from '../did-resolver.js'
14
15
import { composeCarStoresWithOrderedHas , createCarStore } from '../buckets/car-store.js'
15
16
import { createStoreTable } from '../tables/store.js'
16
17
import { createUploadTable } from '../tables/upload.js'
@@ -48,6 +49,7 @@ import { mustGetEnv } from '../../lib/env.js'
48
49
import { createEgressTrafficQueue } from '../../billing/queues/egress-traffic.js'
49
50
import { create as createRoutingService } from '../external-services/router.js'
50
51
import { create as createBlobRetriever } from '../external-services/blob-retriever.js'
52
+ import { PlcClient } from '@storacha/did-plc'
51
53
52
54
Sentry . AWSLambda . init ( {
53
55
environment : process . env . SST_STAGE ,
@@ -119,15 +121,15 @@ export const knownWebDIDs = {
119
121
*/
120
122
export async function ucanInvocationRouter ( request ) {
121
123
try {
122
- // Capture X-Client custom header for analytics
123
- const clientId = Object . entries ( request . headers )
124
+ // Capture X-Client custom header for analytics
125
+ const clientId = Object . entries ( request . headers )
124
126
. find ( ( [ key ] ) => key . toLowerCase ( ) === 'x-client' ) ?. [ 1 ] ?? 'Storacha/?'
125
- console . log ( JSON . stringify ( {
126
- message : 'Client request' ,
127
- clientId,
128
- requestId : request . requestContext ?. requestId || 'unknown' ,
129
- timestamp : new Date ( ) . toISOString ( )
130
- } ) )
127
+ console . log ( JSON . stringify ( {
128
+ message : 'Client request' ,
129
+ clientId,
130
+ requestId : request . requestContext ?. requestId || 'unknown' ,
131
+ timestamp : new Date ( ) . toISOString ( )
132
+ } ) )
131
133
} catch ( error ) {
132
134
console . error ( error )
133
135
}
@@ -309,10 +311,7 @@ export async function ucanInvocationRouter(request) {
309
311
registry : allocationBlobRegistry ,
310
312
blobsStorage,
311
313
blobRetriever,
312
- resolveDIDKey : ( did ) =>
313
- Schema . did ( { method : 'web' } ) . is ( did ) && principalMapping [ did ]
314
- ? ok ( principalMapping [ did ] )
315
- : error ( new DIDResolutionError ( did ) ) ,
314
+ resolveDIDKey : createDidResolver ( principalMapping , new PlcClient ( ) ) ,
316
315
getServiceConnection : ( ) => connection ,
317
316
// TODO: to be deprecated with `store/*` protocol
318
317
storeTable : createStoreTable ( AWS_REGION , storeTableName , {
0 commit comments