-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: upload-api doesn't use a did:web as the serviceSigner in accessC…
…lient (#100) Motivation: * @alanshaw informed me via slack that upload-api signs invocations sent to access-api. These signatures wouldn't be verifiable if their signer did was a non-key-did. What * This PR makes it so the service signer for most of upload-api knows nothing about `env.UPLOAD_API_DID`. * `env.UPLOAD_API_DID` only is used for the Principal passed to the ucanto server id (to verify incoming invocations 'aud') * similar to this I did for w3protocol storacha/w3up#303 * /version api response object has new property `aud`, which is the expected `aud` value of any UCAN invocations sent to the ucanto server (when env.UPLOAD_API_DID is set, it'll be that did) Signed-off-by: Oli Evans <oli@protocol.ai>
- Loading branch information
Showing
7 changed files
with
65 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,25 +1,26 @@ | ||
/** | ||
* This file uses SSTs magic Config handler. | ||
* If you depend on it in a test then you need to use the `sst bind` CLI to setup the config object. | ||
* | ||
* see: https://docs.sst.dev/config | ||
* see: https://docs.sst.dev/advanced/testing#how-sst-bind-works | ||
*/ | ||
import * as ed25519 from '@ucanto/principal/ed25519' | ||
import { DID } from '@ucanto/validator' | ||
import * as DID from '@ipld/dag-ucan/did' | ||
|
||
/** | ||
* Given a config, return a ucanto Signer object representing the service | ||
* | ||
* @param {object} config | ||
* @param {string} [config.UPLOAD_API_DID] - public identifier of the running service. e.g. a did:key or a did:web | ||
* @param {string} config.PRIVATE_KEY - multiformats private key of primary signing key | ||
*/ | ||
export function getServiceSigner(config) { | ||
const signer = ed25519.parse(config.PRIVATE_KEY) | ||
const did = config.UPLOAD_API_DID | ||
if (!did) { | ||
return signer | ||
return signer | ||
} | ||
|
||
/** | ||
* Given a config, return a ucanto principal | ||
* | ||
* @param {{ UPLOAD_API_DID: string } | { PRIVATE_KEY: string }} config | ||
* @returns {import('@ucanto/interface').Principal} | ||
*/ | ||
export function getServicePrincipal(config) { | ||
if ('UPLOAD_API_DID' in config) { | ||
return DID.parse(config.UPLOAD_API_DID) | ||
} | ||
return signer.withDID(DID.match({}).from(did)) | ||
return getServiceSigner(config) | ||
} |
This file contains 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 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 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 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 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 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