Skip to content

Commit

Permalink
feat: @web3-storage/capabilities depends on latest ucanto (#541)
Browse files Browse the repository at this point in the history
Motivation:
* do the upgrade so that we can merge
#539 after (which
requires the upgrade)
  • Loading branch information
gobengo authored Mar 15, 2023
1 parent 91102ff commit f2cfcd2
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 175 deletions.
8 changes: 4 additions & 4 deletions packages/access-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
"license": "(Apache-2.0 OR MIT)",
"dependencies": {
"@ipld/dag-ucan": "^3.2.0",
"@ucanto/core": "^5.1.0",
"@ucanto/interface": "^6.0.0",
"@ucanto/core": "^5.2.0",
"@ucanto/interface": "^6.2.0",
"@ucanto/principal": "^5.1.0",
"@ucanto/server": "^6.0.0",
"@ucanto/server": "^6.1.0",
"@ucanto/transport": "^5.1.0",
"@ucanto/validator": "^6.0.0",
"@ucanto/validator": "^6.1.0",
"@web3-storage/access": "workspace:^",
"@web3-storage/capabilities": "workspace:^",
"@web3-storage/worker-utils": "0.4.3-dev",
Expand Down
8 changes: 5 additions & 3 deletions packages/access-api/src/routes/validate-email.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ async function authorize(req, env) {

if (confirmation.error) {
throw new Error(`unable to validate access session: ${confirmation}`, {
cause: confirmation.error,
cause: confirmation,
})
}

Expand All @@ -168,12 +168,12 @@ async function authorize(req, env) {
}
)
const confirmResult = await confirm(request, {
id: env.signer.verifier,
id: env.signer,
principal: Verifier,
})
if (confirmResult.error) {
throw new Error('error confirming', {
cause: confirmResult.error,
cause: confirmResult,
})
}
const { account, agent } = accessConfirm.parse(request)
Expand All @@ -193,6 +193,8 @@ async function authorize(req, env) {
)
)
} catch (error) {
// eslint-disable-next-line no-console
console.warn('error in validate-email', error)
const err = /** @type {Error} */ (error)
env.log.error(err)
return new HtmlResponse(
Expand Down
3 changes: 1 addition & 2 deletions packages/access-api/src/service/access-authorize.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as Server from '@ucanto/server'
import * as Access from '@web3-storage/capabilities/access'
import * as Mailto from '../utils/did-mailto.js'
import * as DID from '@ipld/dag-ucan/did'
import { delegationToString } from '@web3-storage/access/encoding'

/**
Expand All @@ -25,7 +24,7 @@ export function accessAuthorizeProvider(ctx) {
const confirmation = await Access.confirm
.invoke({
issuer: ctx.signer,
audience: DID.parse(capability.nb.iss),
audience: ctx.signer,
// Because with is set to our DID no other actor will be able to issue
// this delegation without our private key.
with: ctx.signer.did(),
Expand Down
5 changes: 3 additions & 2 deletions packages/access-api/test/access-authorize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('access/authorize', function () {
)
const delegation = stringToDelegation(encoded)
t.deepEqual(delegation.issuer.did(), service.did())
t.deepEqual(delegation.audience.did(), accountDID)
t.deepEqual(delegation.audience.did(), service.did())
t.deepEqual(delegation.capabilities, [
{
with: conn.id.did(),
Expand Down Expand Up @@ -122,8 +122,9 @@ describe('access/authorize', function () {

const url = new URL(email.url)
const rsp = await mf.dispatchFetch(url, { method: 'POST' })
const html = await rsp.text()
assert.deepEqual(rsp.status, 200)

const html = await rsp.text()
assert(html.includes('Email Validated'))
assert(html.includes(toEmail(accountDID)))
assert(html.includes(issuer.did()))
Expand Down
81 changes: 0 additions & 81 deletions packages/access-api/test/store-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,85 +69,4 @@ describe('proxy store/list invocations to upload-api', function () {
assert.ok(!result?.error, 'should not be an error')
})
}

it('errors when a bad delegation is given as proof', async () => {
const mockUpstream = createMockUploadApiServer({
// eslint-disable-next-line unicorn/no-await-expression-member
id: await ed25519.generate(),
})
const mockUpstreamHttp = nodeHttp.createServer(
ucantoServerNodeListener(mockUpstream)
)
await new Promise((resolve, reject) =>
// eslint-disable-next-line unicorn/no-useless-undefined
mockUpstreamHttp.listen(0, () => resolve(undefined))
)
// now mockUpstreamHttp is listening on a port. If something goes wrong, we will close the server to have it stop litening
after(() => {
mockUpstreamHttp.close()
})
const mockUpstreamUrl = serverLocalUrl(mockUpstreamHttp.address())
const [alice, bob, mallory] = await Promise.all(
Array.from({ length: 3 }).map(() => ed25519.Signer.generate())
)
const { service: serviceSigner, conn } = await context({
env: {
UPLOAD_API_URL: mockUpstreamUrl.toString(),
},
})
const service = process.env.DID
? serviceSigner.withDID(ucanto.DID.parse(process.env.DID).did())
: serviceSigner
const spaceCreation = await createSpace(
alice,
service,
conn,
'space-info@dag.house'
)
/**
* @type {Array<{
* invocation: import('@ucanto/interface').IssuedInvocationView
* resultAssertion: (r: import('@ucanto/interface').Result<unknown, { error: true }>) => void
* }>} */
const cases = [
{
invocation: Store.list.invoke({
issuer: mallory,
audience: service,
proofs: [
// this shouldn't work because the audience is bob,
// but its a proof an an invocation issued by mallory
await Store.list.delegate({
issuer: alice,
audience: bob,
with: spaceCreation.space.did(),
}),
],
with: spaceCreation.space.did(),
nb: {},
}),
resultAssertion(result) {
assert.ok(result.error, 'result is an error')
assert.ok('name' in result, 'result has a name')
assert.equal(result.name, 'InvalidAudience')
assert.ok(
'stack' in result && typeof result.stack === 'string',
'result has stack string'
)
},
},
]
for (const { invocation, resultAssertion } of cases) {
const result = await invocation.execute(
/** @type {import('@ucanto/interface').ConnectionView<any>} */ (conn)
)
try {
resultAssertion(result)
} catch (error) {
// eslint-disable-next-line no-console
console.warn('result failed assertion', result)
throw error
}
}
})
})
20 changes: 0 additions & 20 deletions packages/access-api/test/ucan.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,6 @@ describe('ucan', function () {
])
})

test('should fail with bad service audience', async function () {
const { mf, issuer } = ctx

const audience = await Signer.generate()
const ucan = await UCAN.issue({
issuer,
audience,
// @ts-ignore
capabilities: [],
})
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[0].name, 'InvalidAudience')
})

test('should fail with with more than 1 cap', async function () {
const { mf, service, issuer } = ctx

Expand Down
2 changes: 1 addition & 1 deletion packages/access-api/test/validate-email.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('validate-email', () => {
const extraBytes = getRandomValues(new Uint8Array(10 * 1024))
const ucan = await Delegation.delegate({
issuer: service,
audience: agent,
audience: service,
capabilities: [
Access.confirm.create({
with: service.did(),
Expand Down
8 changes: 4 additions & 4 deletions packages/access-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@
"@ipld/dag-cbor": "^9.0.0",
"@ipld/dag-ucan": "^3.2.0",
"@ucanto/client": "^5.1.0",
"@ucanto/core": "^5.1.0",
"@ucanto/interface": "^6.0.0",
"@ucanto/core": "^5.2.0",
"@ucanto/interface": "^6.2.0",
"@ucanto/principal": "^5.1.0",
"@ucanto/transport": "^5.1.0",
"@ucanto/validator": "^6.0.0",
"@ucanto/validator": "^6.1.0",
"@web3-storage/capabilities": "workspace:^",
"bigint-mod-arith": "^3.1.2",
"conf": "10.2.0",
Expand All @@ -91,7 +91,7 @@
"@types/node": "^18.11.18",
"@types/varint": "^6.0.1",
"@types/ws": "^8.5.4",
"@ucanto/server": "^6.0.0",
"@ucanto/server": "^6.1.0",
"assert": "^2.0.0",
"delay": "^5.0.0",
"hd-scripts": "^4.0.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/capabilities/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@
"dist/src/**/*.d.ts.map"
],
"dependencies": {
"@ucanto/core": "^5.1.0",
"@ucanto/interface": "^6.0.0",
"@ucanto/core": "^5.2.0",
"@ucanto/interface": "^6.2.0",
"@ucanto/principal": "^5.1.0",
"@ucanto/transport": "^5.1.0",
"@ucanto/validator": "^6.0.0"
"@ucanto/validator": "^6.1.0"
},
"devDependencies": {
"@types/assert": "^1.5.6",
Expand Down
12 changes: 6 additions & 6 deletions packages/upload-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@
},
"dependencies": {
"@ucanto/client": "^5.1.0",
"@ucanto/interface": "^6.0.0",
"@ucanto/interface": "^6.2.0",
"@ucanto/principal": "^5.1.0",
"@ucanto/server": "^6.0.0",
"@ucanto/server": "^6.1.0",
"@ucanto/transport": "^5.1.0",
"@web3-storage/capabilities": "^3.0.0",
"@web3-storage/capabilities": "workspace:^",
"multiformats": "^11.0.1",
"p-retry": "^5.1.2"
},
"devDependencies": {
"@ipld/car": "^5.0.1",
"@types/mocha": "^10.0.1",
"@ucanto/core": "^5.1.0",
"@web3-storage/sigv4": "^1.0.2",
"@web-std/blob": "^3.0.4",
"mocha": "^10.2.0",
"hd-scripts": "^4.1.0"
"@web3-storage/sigv4": "^1.0.2",
"hd-scripts": "^4.1.0",
"mocha": "^10.2.0"
},
"eslintConfig": {
"extends": [
Expand Down
4 changes: 2 additions & 2 deletions packages/upload-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"@ipld/dag-ucan": "^3.2.0",
"@ipld/unixfs": "^2.0.1",
"@ucanto/client": "^5.1.0",
"@ucanto/interface": "^6.0.0",
"@ucanto/interface": "^6.2.0",
"@ucanto/transport": "^5.1.0",
"@web3-storage/capabilities": "workspace:^",
"multiformats": "^11.0.1",
Expand All @@ -78,7 +78,7 @@
"@types/assert": "^1.5.6",
"@types/mocha": "^10.0.1",
"@ucanto/principal": "^5.1.0",
"@ucanto/server": "^6.0.0",
"@ucanto/server": "^6.1.0",
"assert": "^2.0.0",
"blockstore-core": "^3.0.0",
"c8": "^7.12.0",
Expand Down
Loading

0 comments on commit f2cfcd2

Please sign in to comment.