Skip to content

Commit 6bf9f78

Browse files
committed
refactor: read web dids from env
1 parent fa17c18 commit 6bf9f78

File tree

6 files changed

+30
-12
lines changed

6 files changed

+30
-12
lines changed

src/middleware/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,4 @@ export { withAuthorizedSpace } from './withAuthorizedSpace.js'
77
export { withLocator } from './withLocator.js'
88
export { withEgressTracker } from './withEgressTracker.js'
99
export { withEgressClient } from './withEgressClient.js'
10-
export { withDelegationStubs } from './withDelegationStubs.js'
11-
12-
export const GATEWAY_DID = 'did:web:staging.w3s.link'
13-
export const UPLOAD_DID = 'did:web:staging.web3.storage'
10+
export { withDelegationStubs } from './withDelegationStubs.js'

src/middleware/withEgressClient.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ async function connect(serverUrl, principal) {
7676
* @returns {Promise<void>}
7777
*/
7878
async function record(space, resource, bytes, servedAt, env, ctx) {
79-
const uploadServicePrincipal = DID.parse('did:web:staging.web3.storage') // TODO move to env var
79+
const uploadServicePrincipal = DID.parse(env.UPLOAD_SERVICE_DID)
8080
const connection = await connect(env.UPLOAD_API_URL, uploadServicePrincipal)
8181

8282
const invocation = Space.egressRecord.invoke({

src/middleware/withEgressClient.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { DelegationsStorageContext } from './withAuthorizedSpace.types.js'
66
export interface Environment extends MiddlewareEnvironment {
77
GATEWAY_PRINCIPAL_KEY: string
88
UPLOAD_API_URL: string
9+
UPLOAD_SERVICE_DID: string
910
}
1011

1112
export interface EgressClientContext

src/middleware/withGatewayIdentity.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Signer } from '@ucanto/principal/ed25519'
2-
import { GATEWAY_DID } from './index.js'
31
import { ed25519 } from '@ucanto/principal'
42

53
/**
@@ -17,6 +15,10 @@ export function withGatewayIdentity(handler) {
1715
const gatewaySigner = env.GATEWAY_PRINCIPAL_KEY
1816
? ed25519.Signer.parse(env.GATEWAY_PRINCIPAL_KEY)
1917
: await ed25519.Signer.generate()
20-
return handler(req, env, { ...ctx, gatewaySigner, gatewayIdentity: gatewaySigner.withDID(GATEWAY_DID) })
18+
19+
const gatewayIdentity = gatewaySigner.withDID(
20+
/** @type {`did:${string}:${string}`} */ (env.GATEWAY_SERVICE_DID)
21+
)
22+
return handler(req, env, { ...ctx, gatewaySigner, gatewayIdentity })
2123
}
2224
}

src/middleware/withGatewayIdentity.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { EdSigner } from '@ucanto/principal/ed25519'
44

55
export interface Environment extends MiddlewareEnvironment {
66
GATEWAY_PRINCIPAL_KEY: string
7+
GATEWAY_SERVICE_DID: string
78
}
89

910
export interface GatewayIdentityContext extends MiddlewareContext {

wrangler.toml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ r2_buckets = [
88

99
[vars]
1010
CONTENT_CLAIMS_SERVICE_URL = "https://dev.claims.web3.storage"
11+
GATEWAY_SERVICE_DID = "did:web:staging.w3s.link"
12+
UPLOAD_SERVICE_DID = "did:web:staging.web3.storage"
13+
UPLOAD_API_URL = "https://staging.up.web3.storage"
1114

1215
[build]
1316
command = "npm run build:debug"
@@ -46,8 +49,11 @@ MAX_SHARDS = "825"
4649
FF_RATE_LIMITER_ENABLED = "false"
4750
FF_EGRESS_TRACKER_ENABLED = "false"
4851
FF_TELEMETRY_ENABLED = "true"
52+
GATEWAY_SERVICE_DID = "did:web:w3s.link"
53+
UPLOAD_SERVICE_DID = "did:web:web3.storage"
4954
CONTENT_CLAIMS_SERVICE_URL = "https://claims.web3.storage"
5055
CARPARK_PUBLIC_BUCKET_URL = "https://carpark-prod-0.r2.w3s.link"
56+
UPLOAD_API_URL = "https://up.web3.storage"
5157

5258
# Staging!
5359
[env.staging]
@@ -65,7 +71,10 @@ MAX_SHARDS = "825"
6571
FF_RATE_LIMITER_ENABLED = "false"
6672
FF_EGRESS_TRACKER_ENABLED = "false"
6773
FF_TELEMETRY_ENABLED = "false"
74+
GATEWAY_SERVICE_DID = "did:web:staging.w3s.link"
75+
UPLOAD_SERVICE_DID = "did:web:staging.web3.storage"
6876
CONTENT_CLAIMS_SERVICE_URL = "https://staging.claims.web3.storage"
77+
UPLOAD_API_URL = "https://staging.up.web3.storage"
6978
CARPARK_PUBLIC_BUCKET_URL = "https://carpark-staging-0.r2.w3s.link"
7079

7180
# Test!
@@ -81,7 +90,10 @@ FF_RATE_LIMITER_ENABLED = "false"
8190
FF_EGRESS_TRACKER_ENABLED = "false"
8291
FF_TELEMETRY_ENABLED = "true"
8392
MAX_SHARDS = "120"
93+
GATEWAY_SERVICE_DID = "did:web:staging.w3s.link"
94+
UPLOAD_SERVICE_DID = "did:web:staging.web3.storage"
8495
CONTENT_CLAIMS_SERVICE_URL = "https://test.claims.web3.storage"
96+
UPLOAD_API_URL = "https://staging.up.web3.storage"
8597

8698
[env.alanshaw]
8799
workers_dev = true
@@ -95,7 +107,10 @@ DEBUG = "true"
95107
FF_RATE_LIMITER_ENABLED = "false"
96108
FF_EGRESS_TRACKER_ENABLED = "false"
97109
FF_TELEMETRY_ENABLED = "true"
110+
GATEWAY_SERVICE_DID = "did:web:staging.w3s.link"
111+
UPLOAD_SERVICE_DID = "did:web:staging.web3.storage"
98112
CONTENT_CLAIMS_SERVICE_URL = "https://dev.claims.web3.storage"
113+
UPLOAD_API_URL = "https://staging.up.web3.storage"
99114

100115
[env.fforbeck]
101116
name = "freeway-fforbeck"
@@ -114,17 +129,13 @@ r2_buckets = [
114129

115130
[env.fforbeck.vars]
116131
DEBUG = "true"
117-
# Feature Flags
118132
FF_RATE_LIMITER_ENABLED = "false"
119133
FF_EGRESS_TRACKER_ENABLED = "true"
120134
FF_TELEMETRY_ENABLED = "false"
121-
# DIDs
122135
GATEWAY_SERVICE_DID = "did:web:staging.w3s.link"
123136
UPLOAD_SERVICE_DID = "did:web:staging.web3.storage"
124-
# SERVICE URLs
125137
CONTENT_CLAIMS_SERVICE_URL = "https://staging.claims.web3.storage"
126138
UPLOAD_API_URL = "https://staging.up.web3.storage"
127-
#UPLOAD_API_URL = "https://pr435.up.storacha.network"
128139

129140
[[env.fforbeck.unsafe.bindings]]
130141
name = "RATE_LIMITER"
@@ -150,8 +161,11 @@ DEBUG = "true"
150161
FF_RATE_LIMITER_ENABLED = "false"
151162
FF_EGRESS_TRACKER_ENABLED = "false"
152163
FF_TELEMETRY_ENABLED = "true"
164+
GATEWAY_SERVICE_DID = "did:web:staging.w3s.link"
165+
UPLOAD_SERVICE_DID = "did:web:staging.web3.storage"
153166
CONTENT_CLAIMS_SERVICE_URL = "https://claims.web3.storage"
154167
CARPARK_PUBLIC_BUCKET_URL = "https://carpark-prod-0.r2.w3s.link"
168+
UPLOAD_API_URL = "https://staging.up.web3.storage"
155169

156170
### Integration Tests Configuration
157171
[env.integration]
@@ -167,7 +181,10 @@ DEBUG = "true"
167181
FF_RATE_LIMITER_ENABLED = "true"
168182
FF_EGRESS_TRACKER_ENABLED = "true"
169183
FF_TELEMETRY_ENABLED = "true"
184+
GATEWAY_SERVICE_DID = "did:web:staging.w3s.link"
185+
UPLOAD_SERVICE_DID = "did:web:staging.web3.storage"
170186
CONTENT_CLAIMS_SERVICE_URL = "https://staging.claims.web3.storage"
187+
UPLOAD_API_URL = "https://staging.up.web3.storage"
171188

172189
[[env.integration.unsafe.bindings]]
173190
name = "RATE_LIMITER"

0 commit comments

Comments
 (0)