-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: upload-api ucanto server id uses did from env.DID (#91)
Motivation: * #90 What * w3infra upload-api will use env.UPLOAD_API_DID for its ucanto server id * UPLOAD_API_DID gets set to did:web:{customDomain} on new sst stack creation, where customDomain comes from seed.run env.HOSTED_ZONE Questions: * I think I did the `Config.Parameter` right using sst for the upload-api `UPLOAD_API_DID` parameter? but not sure since other configs just use environment variables without explicitly using `Config.Parameter`. How do we decide when to use `Config.Parameter` and when not to?
- Loading branch information
Showing
7 changed files
with
144 additions
and
8 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { test } from './helpers/context.js' | ||
import * as configModule from '../config.js' | ||
|
||
/** keypair that can be used for testing */ | ||
const testKeypair = { | ||
private: { | ||
/** | ||
* Private key encoded as multiformats | ||
*/ | ||
multiformats: | ||
'MgCYWjE6vp0cn3amPan2xPO+f6EZ3I+KwuN1w2vx57vpJ9O0Bn4ci4jn8itwc121ujm7lDHkCW24LuKfZwIdmsifVysY=', | ||
}, | ||
public: { | ||
/** | ||
* Public key encoded as a did:key | ||
*/ | ||
did: 'did:key:z6MkqBzPG7oNu7At8fktasQuS7QR7Tj7CujaijPMAgzdmAxD', | ||
}, | ||
} | ||
|
||
test('upload-api/config getServiceSigner creates a signer using config.{UPLOAD_API_KEY,PRIVATE_KEY}', async (t) => { | ||
const config = { | ||
PRIVATE_KEY: testKeypair.private.multiformats, | ||
UPLOAD_API_DID: 'did:web:exampe.com', | ||
} | ||
const signer = configModule.getServiceSigner(config) | ||
t.assert(signer) | ||
t.is(signer.did().toString(), config.UPLOAD_API_DID) | ||
const { keys } = signer.toArchive() | ||
const didKeys = Object.keys(keys) | ||
t.deepEqual(didKeys, [testKeypair.public.did]) | ||
}) | ||
test('upload-api/config getServiceSigner errors if config.DID is provided but not a did', (t) => { | ||
t.throws(() => { | ||
configModule.getServiceSigner({ | ||
UPLOAD_API_DID: 'not a did', | ||
PRIVATE_KEY: testKeypair.private.multiformats, | ||
}) | ||
}, { message: /^Expected a did: but got ".+" instead$/ }) | ||
}) | ||
test('upload-api/config getServiceSigner infers did from config.PRIVATE_KEY when config.DID is omitted', async (t) => { | ||
const config = { | ||
PRIVATE_KEY: testKeypair.private.multiformats, | ||
} | ||
const signer = configModule.getServiceSigner(config) | ||
t.assert(signer) | ||
t.is(signer.did().toString(), testKeypair.public.did) | ||
}) |
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