-
Notifications
You must be signed in to change notification settings - Fork 22
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
feat: access-api uses DID env variable when building its ucanto server id #275
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6504306
access-api uses DID env variable when building its ucanto server sign…
gobengo a4785dd
access-api add test ensuring error when non-did config.DID provided t…
gobengo 91edd06
access-api update isDID type guard to use @ucanto/validator instead o…
gobengo 795582a
pnpm-lock
gobengo b9533c9
access-api configureSigner happens inside loadConfig and sets config.…
gobengo d204331
remove unnecessary PRIVATE_KEY environment var from access-api/test/u…
gobengo 5184a55
access-api/src/config remove isDID function
gobengo a629263
improve configureSigner test
gobengo 852951f
config loadConfig no longer has DID or PRIVATE_KEY on it
gobengo 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
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,50 @@ | ||
import assert from 'assert' | ||
import * as configModule from '../src/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', | ||
}, | ||
} | ||
|
||
describe('@web3-storage/access-api/src/config configureSigner', () => { | ||
it('creates a signer using config.{DID,PRIVATE_KEY}', async () => { | ||
const config = { | ||
PRIVATE_KEY: testKeypair.private.multiformats, | ||
DID: 'did:web:exampe.com', | ||
} | ||
const signer = configModule.configureSigner(config) | ||
assert.ok(signer) | ||
assert.equal(signer.did().toString(), config.DID) | ||
const { keys } = signer.toArchive() | ||
const didKeys = Object.keys(keys) | ||
assert.deepEqual(didKeys, [testKeypair.public.did]) | ||
}) | ||
it('errors if config.DID is provided but not a did', () => { | ||
assert.throws(() => { | ||
configModule.configureSigner({ | ||
DID: 'not a did', | ||
PRIVATE_KEY: testKeypair.private.multiformats, | ||
}) | ||
}, 'Invalid DID') | ||
}) | ||
it('infers did from config.PRIVATE_KEY when config.DID is omitted', async () => { | ||
const config = { | ||
PRIVATE_KEY: testKeypair.private.multiformats, | ||
} | ||
const signer = configModule.configureSigner(config) | ||
assert.ok(signer) | ||
assert.equal(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
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 |
---|---|---|
|
@@ -144,6 +144,29 @@ describe('ucan', function () { | |
t.deepEqual(rsp, ['test pass']) | ||
}) | ||
|
||
test('should support ucan invoking to a did:web aud', async function () { | ||
const serviceDidWeb = 'did:web:example.com' | ||
const { mf, issuer, service } = await context({ | ||
environment: { | ||
...process.env, | ||
DID: serviceDidWeb, | ||
}, | ||
}) | ||
const ucan = await UCAN.issue({ | ||
issuer, | ||
audience: service.withDID(serviceDidWeb), | ||
capabilities: [{ can: 'testing/pass', with: 'mailto:[email protected]' }], | ||
}) | ||
const res = await mf.dispatchFetch('http://localhost:8787/raw', { | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Bearer ${UCAN.format(ucan)}`, | ||
}, | ||
}) | ||
const rsp = await res.json() | ||
t.deepEqual(rsp, ['test pass']) | ||
}) | ||
|
||
test('should handle exception in route handler', async function () { | ||
const { mf, service, issuer } = ctx | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we get the did:key and did:web from the signer instance ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.