-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: unifiy principals & signers Co-authored-by: Hugo Dias <[email protected]> * fix: tests on core * fix: transport package * chore: update client to 0.9 * feat(validator): update to ucan 0.9 * feat(server): upgrade to 0.9 * fix(principal): invalid test * chore: update dag-ucan dep * feat: rename caveats to nb * fix(server): type checks * fix(validator): increase coverage * fix(docs): rename caveats to nb * feat: improve decoders * fix: types * fix: types for .create / .invoke of capability * fix: nb inference 98 * feat: implement InferInvokedCapability type * fix: remove conflicting type Co-authored-by: Hugo Dias <[email protected]>
- Loading branch information
1 parent
b752b39
commit fc5a2ac
Showing
6 changed files
with
149 additions
and
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import * as Voucher from './voucher.js' | ||
import { test, assert } from './test.js' | ||
import { alice, bob, mallory, service as w3 } from './fixtures.js' | ||
import { capability, URI, Link } from '../src/lib.js' | ||
import * as API from './types.js' | ||
|
||
test('execute capabilty', () => | ||
/** | ||
* @param {API.ConnectionView<API.Service>} connection | ||
*/ | ||
async connection => { | ||
const claim = Voucher.Claim.invoke({ | ||
issuer: alice, | ||
audience: w3, | ||
with: alice.did(), | ||
nb: { | ||
identity: URI.from(`mailto:${alice.did}@web.mail`), | ||
product: Link.parse('bafkqaaa'), | ||
service: w3.did(), | ||
}, | ||
}) | ||
|
||
const proof = Voucher.Redeem.invoke({ | ||
issuer: alice, | ||
audience: w3, | ||
with: alice.did(), | ||
nb: { | ||
product: 'test', | ||
identity: 'whatever', | ||
account: alice.did(), | ||
}, | ||
}) | ||
|
||
const redeem = Voucher.Redeem.invoke({ | ||
issuer: alice, | ||
audience: w3, | ||
with: alice.did(), | ||
nb: { | ||
product: 'test', | ||
identity: proof.capabilities[0].nb.identity, | ||
account: alice.did(), | ||
}, | ||
}) | ||
|
||
const r1 = await redeem.execute(connection) | ||
if (!r1.error) { | ||
r1.product.toLowerCase() | ||
} | ||
|
||
const r2 = await claim.execute(connection) | ||
if (!r2.error) { | ||
r2.service.toUpperCase() | ||
} | ||
}) | ||
|
||
test('can access fields on the proof', () => | ||
/** | ||
* @param {API.Delegation<[API.VoucherRedeem]>} proof | ||
*/ | ||
proof => { | ||
const redeem = Voucher.Redeem.invoke({ | ||
issuer: alice, | ||
audience: w3, | ||
with: alice.did(), | ||
nb: { | ||
product: proof.capabilities[0].nb.product, | ||
identity: proof.capabilities[0].nb.identity, | ||
account: proof.capabilities[0].nb.account, | ||
}, | ||
proofs: [proof], | ||
}) | ||
}) | ||
|
||
test('use InferInvokedCapability', () => | ||
/** | ||
* @param {API.ConnectionView<API.Service>} connection | ||
* @param {API.InferInvokedCapability<typeof Voucher.Redeem>} capability | ||
*/ | ||
async (connection, capability) => { | ||
const redeem = Voucher.Redeem.invoke({ | ||
issuer: alice, | ||
audience: w3, | ||
with: capability.with, | ||
nb: { | ||
product: capability.nb.product, | ||
identity: capability.nb.identity, | ||
account: capability.nb.account, | ||
}, | ||
}) | ||
|
||
const result = await redeem.execute(connection) | ||
if (!result.error) { | ||
result.product.toLocaleLowerCase() | ||
} | ||
}) |
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,44 @@ | ||
import { equalWith, canDelegateURI, fail } from './util.js' | ||
import { capability, URI, Text, Link, DID } from '../src/lib.js' | ||
|
||
export const Voucher = capability({ | ||
can: 'voucher/*', | ||
with: DID.match({ method: 'key' }), | ||
}) | ||
|
||
export const Claim = Voucher.derive({ | ||
to: capability({ | ||
can: 'voucher/claim', | ||
with: DID.match({ method: 'key' }), | ||
nb: { | ||
product: Link, | ||
identity: URI.match({ protocol: 'mailto:' }), | ||
service: DID, | ||
}, | ||
derives: (child, parent) => { | ||
return ( | ||
fail(equalWith(child, parent)) || | ||
fail(canDelegateURI(child.nb.identity, parent.nb.identity)) || | ||
fail( | ||
canDelegateURI( | ||
child.nb.product.toString(), | ||
parent.nb.product.toString() | ||
) | ||
) || | ||
fail(canDelegateURI(child.nb.service, parent.nb.service)) || | ||
true | ||
) | ||
}, | ||
}), | ||
derives: equalWith, | ||
}) | ||
|
||
export const Redeem = capability({ | ||
can: 'voucher/redeem', | ||
with: URI.match({ protocol: 'did:' }), | ||
nb: { | ||
product: Text, | ||
identity: Text, | ||
account: URI.match({ protocol: 'did:' }), | ||
}, | ||
}) |