-
Notifications
You must be signed in to change notification settings - Fork 13
fix: handling content-serve delegations #189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ac2f45c
wip
fforbeck 7067221
fix(service): properly handle attested delegations (#190)
hannahhoward 57ea330
fix(wip): content retrieval
fforbeck 6c2858f
wip
fforbeck 5201d92
fix config
fforbeck 97236b4
fix config
fforbeck c28d53b
lint fix
fforbeck 5b5a046
lint fix
fforbeck 7d2d8c6
minor fix
fforbeck cead209
clean up comments
fforbeck 2af6f0b
cleanup
fforbeck 8601eb8
added missing GATEWAY_VALIDATOR_PROOF for staging and prod
fforbeck 6dc6687
update blob-fetcher lib
fforbeck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| /** | ||
| * Create a "ucan/attest" delegation allowing the gateway to validate | ||
| * attestations issued by the upload-service. | ||
| * | ||
| * This generates the GATEWAY_VALIDATOR_PROOF environment variable value. | ||
| * | ||
| * Usage: node scripts/mk-validator-proof.js <upload-service-did-web> <upload-service-private-key> <gateway-did-web> | ||
| * | ||
| * Example (staging): | ||
| * node scripts/mk-validator-proof.js \ | ||
| * did:web:staging.up.storacha.network \ | ||
| * MgCZT5J+...your-key-here... \ | ||
| * did:web:staging.w3s.link | ||
| * | ||
| * Example (production): | ||
| * node scripts/mk-validator-proof.js \ | ||
| * did:web:up.storacha.network \ | ||
| * MgCZT5J+...your-key-here... \ | ||
| * did:web:w3s.link | ||
| */ | ||
| import * as DID from '@ipld/dag-ucan/did' | ||
| import { CAR, delegate } from '@ucanto/core' | ||
| import * as ed25519 from '@ucanto/principal/ed25519' | ||
| import { base64 } from 'multiformats/bases/base64' | ||
| import { identity } from 'multiformats/hashes/identity' | ||
| import * as Link from 'multiformats/link' | ||
|
|
||
| // CORRECT DIRECTION (staging): | ||
| // - issuer should be did:web:staging.up.storacha.network (upload-service) | ||
| // - audience should be did:web:staging.w3s.link (gateway) | ||
| // - can should be 'ucan/attest' | ||
| // - with should be issuer.did() (i.e. did:web:staging.up.storacha.network) | ||
| // The private key must be the upload-service private key. This makes the | ||
| // gateway trust attestations issued by the upload-service. | ||
|
|
||
| const uploadServiceDIDWeb = process.argv[2] | ||
| const uploadServicePrivateKey = process.argv[3] | ||
| const gatewayDIDWeb = process.argv[4] | ||
|
|
||
| if (!uploadServiceDIDWeb || !uploadServicePrivateKey || !gatewayDIDWeb) { | ||
| console.error('Error: Missing required arguments') | ||
| console.error('Usage: node scripts/mk-validator-proof.js <upload-service-did-web> <upload-service-private-key> <gateway-did-web>') | ||
| console.error('') | ||
| console.error('Example (staging):') | ||
| console.error(' node scripts/mk-validator-proof.js \\') | ||
| console.error(' did:web:staging.up.storacha.network \\') | ||
| console.error(' MgCZT5J+...your-key-here... \\') | ||
| console.error(' did:web:staging.w3s.link') | ||
| process.exit(1) | ||
| } | ||
|
|
||
| console.log(`Upload Service DID: ${uploadServiceDIDWeb}`) | ||
| console.log(`Upload Service Private Key: ${uploadServicePrivateKey.slice(0, 7)}...${uploadServicePrivateKey.slice(-7)}`) | ||
| console.log(`Gateway DID: ${gatewayDIDWeb}`) | ||
| console.log('') | ||
|
|
||
| const issuer = ed25519 | ||
| .parse(uploadServicePrivateKey) | ||
| .withDID(DID.parse(uploadServiceDIDWeb).did()) | ||
| const audience = DID.parse(gatewayDIDWeb) | ||
|
|
||
| // Note: variable names are confusing - "uploadService" is actually the issuer (gateway in our case) | ||
| // and "gateway" is actually the audience (upload service in our case) | ||
| // The 'with' should be the issuer's DID per colleague's instructions | ||
| const delegation = await delegate({ | ||
| issuer, | ||
| audience, | ||
| capabilities: [{ can: 'ucan/attest', with: issuer.did() }], | ||
| expiration: Infinity | ||
| }) | ||
|
|
||
| console.log('✅ Delegation created:') | ||
| console.log(` Issuer: ${issuer.did()}`) | ||
| console.log(` Audience: ${audience.did()}`) | ||
| console.log(` Capability: ucan/attest with ${issuer.did()}`) | ||
| console.log('') | ||
|
|
||
| const res = await delegation.archive() | ||
| if (res.error) { | ||
| console.error('❌ Error archiving delegation:', res.error) | ||
| throw res.error | ||
| } | ||
|
|
||
| const proof = Link.create(CAR.code, identity.digest(res.ok)).toString(base64) | ||
|
|
||
| console.log('✅ Validator proof generated successfully!') | ||
| console.log('') | ||
| console.log('Add this to your environment variables:') | ||
| console.log('') | ||
| console.log('GATEWAY_VALIDATOR_PROOF=' + proof) | ||
| console.log('') | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.