Skip to content

fix: exponential scan #329

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 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/validator/src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,16 @@ const verifySession = async (delegation, proofs, config) => {

return await claim(
attestation,
// We omit the delegation otherwise we may end up in an infinite loop
proofs.filter(proof => proof != delegation),
// We only consider attestations otherwise we will end up doing an
// exponential scan if there are other proofs that require attestations.
proofs.filter(isAttestation),
config
)
}

/**
* Checks if the delegation is an attestation.
*
* @param {API.Delegation} proof
*/
const isAttestation = proof => proof.capabilities[0]?.can === 'ucan/attest'
60 changes: 60 additions & 0 deletions packages/validator/test/session.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,63 @@ test('service can not delegate account resource', async () => {

assert.equal(!result.ok, true)
})

test('redundant proofs have no impact', async () => {
const account = Absentee.from({ id: 'did:mailto:web.mail:alice' })
const pairs = 6
const logins = await Promise.all(
Array(pairs)
.fill(0)
.map((_, n) =>
Delegation.delegate({
issuer: account,
audience: alice,
capabilities: [
{
can: '*',
with: 'ucan:*',
},
],
expiration: Infinity,
nonce: `${n}`,
})
)
)

const expiration = Core.UCAN.now() + 60 * 60 * 24 * 365 // 1 year
const attestations = await Promise.all(
logins.map(login =>
Delegation.delegate({
issuer: w3,
audience: alice,
capabilities: [
{
with: w3.did(),
can: 'ucan/attest',
nb: { proof: login.cid },
},
],
expiration,
})
)
)

const proofs = [...logins, ...attestations]

const request = await echo.invoke({
issuer: alice,
audience: w3,
with: account.did(),
nb: { message: 'hello world' },
proofs,
})

const result = await access(await request.delegate(), {
authority: w3,
capability: echo,
principal: Verifier,
validateAuthorization: () => ({ ok: {} }),
})

assert.ok(result.ok)
})