Skip to content

upgrade to ucan 0.9 #95

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 17 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from 7 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
8 changes: 4 additions & 4 deletions packages/client/test/client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import fetch from '@web-std/fetch'
test('encode inovocation', async () => {
/** @type {Client.ConnectionView<Service.Service>} */
const connection = Client.connect({
id: w3.principal,
id: w3,
channel: HTTP.open({ url: new URL('about:blank'), fetch }),
encoder: CAR,
decoder: CBOR,
Expand Down Expand Up @@ -62,7 +62,7 @@ test('encode delegated invocation', async () => {

/** @type {Client.ConnectionView<Service.Service>} */
const connection = Client.connect({
id: w3.principal,
id: w3,
channel: HTTP.open({ url: new URL('about:blank'), fetch }),
encoder: CAR,
decoder: CBOR,
Expand Down Expand Up @@ -140,12 +140,12 @@ test('encode delegated invocation', async () => {
const service = Service.create()
/** @type {Client.ConnectionView<Service.Service>} */
const connection = Client.connect({
id: w3.principal,
id: w3,
channel: HTTP.open({
url: new URL('about:blank'),
fetch: async (url, input) => {
const invocations = await CAR.decode(input)
const promises = invocations.map((invocation) => {
const promises = invocations.map(invocation => {
const [capabality] = invocation.capabilities
switch (capabality.can) {
case 'store/add': {
Expand Down
10 changes: 5 additions & 5 deletions packages/client/test/fixtures.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { SigningPrincipal } from '@ucanto/principal'
import * as ed25519 from '@ucanto/principal/ed25519'

/** did:key:z6Mkqa4oY9Z5Pf5tUcjLHLUsDjKwMC95HGXdE1j22jkbhz6r */
export const alice = SigningPrincipal.parse(
export const alice = ed25519.parse(
'MgCZT5vOnYZoVAeyjnzuJIVY9J4LNtJ+f8Js0cTPuKUpFne0BVEDJjEu6quFIU8yp91/TY/+MYK8GvlKoTDnqOCovCVM='
)
/** did:key:z6MkffDZCkCTWreg8868fG1FGFogcJj5X6PY93pPcWDn9bob */
export const bob = SigningPrincipal.parse(
export const bob = ed25519.parse(
'MgCYbj5AJfVvdrjkjNCxB3iAUwx7RQHVQ7H1sKyHy46Iose0BEevXgL1V73PD9snOCIoONgb+yQ9sycYchQC8kygR4qY='
)
/** did:key:z6MktafZTREjJkvV5mfJxcLpNBoVPwDLhTuMg9ng7dY4zMAL */
export const mallory = SigningPrincipal.parse(
export const mallory = ed25519.parse(
'MgCYtH0AvYxiQwBG6+ZXcwlXywq9tI50G2mCAUJbwrrahkO0B0elFYkl3Ulf3Q3A/EvcVY0utb4etiSE8e6pi4H0FEmU='
)

export const service = SigningPrincipal.parse(
export const service = ed25519.parse(
'MgCYKXoHVy7Vk4/QjcEGi+MCqjntUiasxXJ8uJKY0qh11e+0Bs8WsdqGK7xothgrDzzWD0ME7ynPjz2okXDh8537lId8='
)
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"dependencies": {
"@ipld/car": "^4.1.5",
"@ipld/dag-cbor": "^7.0.3",
"@ipld/dag-ucan": "3.0.0-beta",
"@ipld/dag-ucan": "link:/Users/gozala/Projects/js-dag-ucan",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"@ipld/dag-ucan": "link:/Users/gozala/Projects/js-dag-ucan",
"@ipld/dag-ucan": "4.0.0-beta",

"@ucanto/interface": "^1.0.0",
"multiformats": "^9.8.1"
},
Expand Down
13 changes: 6 additions & 7 deletions packages/core/src/delegation.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const isLink =
* @param {API.Proof} proof
* @return {proof is API.Delegation}
*/
export const isDelegation = (proof) => !Link.isLink(proof)
export const isDelegation = proof => !Link.isLink(proof)

/**
* Represents UCAN chain view over the set of DAG UCAN nodes. You can think of
Expand Down Expand Up @@ -73,14 +73,14 @@ export class Delegation {
}

/**
* @type {API.UCAN.Principal}
* @type {API.Principal}
*/
get issuer() {
return this.data.issuer
}

/**
* @type {API.UCAN.Principal}
* @type {API.Principal}
*/
get audience() {
return this.data.audience
Expand Down Expand Up @@ -166,9 +166,8 @@ const decode = ({ bytes }) => {
* not set it defaults to 30 seconds from now. Returns UCAN in primary - IPLD
* representation.
*
* @template {number} A
* @template {API.Capabilities} C
* @param {API.DelegationOptions<C, A>} data
* @param {API.DelegationOptions<C>} data
* @param {API.EncodeOptions} [options]
* @returns {Promise<API.Delegation<C>>}
*/
Expand Down Expand Up @@ -230,7 +229,7 @@ const exportDAG = function* (root, blocks) {
* @param {Iterable<API.Block>} dag
* @returns {API.Delegation<C>}
*/
export const importDAG = (dag) => {
export const importDAG = dag => {
/** @type {Array<[string, API.Block]>} */
let entries = []
for (const block of dag) {
Expand Down Expand Up @@ -262,7 +261,7 @@ export const create = ({ root, blocks }) => new Delegation(root, blocks)
/**
* @param {API.Delegation} delegation
*/
const proofs = (delegation) => {
const proofs = delegation => {
/** @type {API.Proof[]} */
const proofs = []
const { root, blocks } = delegation
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/invocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { delegate } from './delegation.js'
* @param {API.InvocationOptions<Capability>} options
* @return {API.IssuedInvocationView<Capability>}
*/
export const invoke = (options) => new IssuedInvocation(options)
export const invoke = options => new IssuedInvocation(options)

/**
* @template {API.Capability} Capability
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export {
decode as decodeLink,
} from './link.js'
export * as UCAN from '@ipld/dag-ucan'
export * as DID from '@ipld/dag-ucan/did'
10 changes: 5 additions & 5 deletions packages/core/test/fixtures.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { SigningPrincipal } from '@ucanto/principal'
import * as ed25519 from '@ucanto/principal/ed25519'

/** did:key:z6Mkqa4oY9Z5Pf5tUcjLHLUsDjKwMC95HGXdE1j22jkbhz6r */
export const alice = SigningPrincipal.parse(
export const alice = ed25519.parse(
'MgCZT5vOnYZoVAeyjnzuJIVY9J4LNtJ+f8Js0cTPuKUpFne0BVEDJjEu6quFIU8yp91/TY/+MYK8GvlKoTDnqOCovCVM='
)
/** did:key:z6MkffDZCkCTWreg8868fG1FGFogcJj5X6PY93pPcWDn9bob */
export const bob = SigningPrincipal.parse(
export const bob = ed25519.parse(
'MgCYbj5AJfVvdrjkjNCxB3iAUwx7RQHVQ7H1sKyHy46Iose0BEevXgL1V73PD9snOCIoONgb+yQ9sycYchQC8kygR4qY='
)
/** did:key:z6MktafZTREjJkvV5mfJxcLpNBoVPwDLhTuMg9ng7dY4zMAL */
export const mallory = SigningPrincipal.parse(
export const mallory = ed25519.parse(
'MgCYtH0AvYxiQwBG6+ZXcwlXywq9tI50G2mCAUJbwrrahkO0B0elFYkl3Ulf3Q3A/EvcVY0utb4etiSE8e6pi4H0FEmU='
)

export const service = SigningPrincipal.parse(
export const service = ed25519.parse(
'MgCYKXoHVy7Vk4/QjcEGi+MCqjntUiasxXJ8uJKY0qh11e+0Bs8WsdqGK7xothgrDzzWD0ME7ynPjz2okXDh8537lId8='
)
8 changes: 4 additions & 4 deletions packages/core/test/invocation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test('expired invocation', async () => {
const expiration = UCAN.now() - 5
const invocation = invoke({
issuer: alice,
audience: w3.principal,
audience: w3,
capability: {
can: 'store/add',
with: alice.did(),
Expand All @@ -59,7 +59,7 @@ test('invocation with notBefore', async () => {
const notBefore = UCAN.now() + 500
const invocation = invoke({
issuer: alice,
audience: w3.principal,
audience: w3,
capability: {
can: 'store/add',
with: alice.did(),
Expand All @@ -81,7 +81,7 @@ test('invocation with notBefore', async () => {
test('invocation with nonce', async () => {
const invocation = invoke({
issuer: alice,
audience: w3.principal,
audience: w3,
capability: {
can: 'store/add',
with: alice.did(),
Expand All @@ -103,7 +103,7 @@ test('invocation with nonce', async () => {
test('invocation with facts', async () => {
const invocation = invoke({
issuer: alice,
audience: w3.principal,
audience: w3,
capability: {
can: 'store/add',
with: alice.did(),
Expand Down
10 changes: 5 additions & 5 deletions packages/core/test/lib.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ test('create delegation chain', async () => {
})
}

const data = await UCAN.issue({
const ucan = await UCAN.issue({
issuer: mallory,
audience: service,
capabilities: [
Expand All @@ -240,8 +240,8 @@ test('create delegation chain', async () => {
proofs: [delegation.cid],
})

const { cid, bytes } = await UCAN.write(data)
const root = { cid, data, bytes }
const { cid, bytes } = await UCAN.write(ucan)
const root = { cid, data: ucan.model, bytes }

{
const invocation = Delegation.create({
Expand Down Expand Up @@ -346,7 +346,7 @@ test('import delegation', async () => {
})

const replica = Delegation.import(original.export())
assert.deepEqual(original, replica)
assert.deepEqual(replica, original)

assert.equal(replica.issuer.did(), alice.did())
assert.equal(replica.audience.did(), bob.did())
Expand Down Expand Up @@ -404,7 +404,7 @@ test('issue chained delegation', async () => {
return assert.fail('must be a delegation')
}

assert.deepEqual(proof.bytes, delegation.bytes)
assert.deepEqual(delegation.bytes, proof.bytes)

assert.deepEqual([...proof.export()], [proof.root])
assert.deepEqual([...delegation.export()], [proof.root])
Expand Down
2 changes: 1 addition & 1 deletion packages/interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"build": "tsc --build"
},
"dependencies": {
"@ipld/dag-ucan": "3.0.0-beta",
"@ipld/dag-ucan": "link:/Users/gozala/Projects/js-dag-ucan",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"@ipld/dag-ucan": "link:/Users/gozala/Projects/js-dag-ucan",
"@ipld/dag-ucan": "4.0.0-beta",

"multiformats": "^9.8.1"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/interface/src/capability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Result,
Failure,
PrincipalParser,
SigningPrincipal,
Signer,
URI,
Await,
IssuedInvocationView,
Expand Down Expand Up @@ -167,7 +167,7 @@ export type InvokeCapabilityOptions<
C extends {}
> = UCANOptions &
InferCreateOptions<R, C> & {
issuer: SigningPrincipal
issuer: Signer
}

export interface CapabilityParser<M extends Match = Match> extends View<M> {
Expand Down
50 changes: 24 additions & 26 deletions packages/interface/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ import {
Phantom,
Resource,
Signature,
Principal,
Verifier,
Signer,
} from '@ipld/dag-ucan'
import * as UCAN from '@ipld/dag-ucan'
import type {
Principal,
PrincipalParser,
SigningPrincipal,
} from './principal.js'
import {
CanIssue,
InvalidAudience,
Expand All @@ -33,14 +31,13 @@ export type {
MultibaseDecoder,
MultibaseEncoder,
} from 'multiformats/bases/interface'
export * from './principal.js'
export * from './capability.js'
export * from './transport.js'
export type {
Transport,
Principal,
PrincipalParser,
SigningPrincipal,
Verifier,
Signer,
Phantom,
Tuple,
DID,
Expand Down Expand Up @@ -80,11 +77,8 @@ export interface UCANOptions {
proofs?: Proof[]
}

export interface DelegationOptions<
C extends Capabilities,
A extends number = number
> extends UCANOptions {
issuer: SigningPrincipal<A>
export interface DelegationOptions<C extends Capabilities> extends UCANOptions {
issuer: Signer
audience: Principal
capabilities: C
proofs?: Proof[]
Expand All @@ -93,17 +87,17 @@ export interface DelegationOptions<
export interface Delegation<C extends Capabilities = Capabilities> {
readonly root: UCANBlock<C>
/**
* Map of all the IPLD blocks that where included with this delegation DAG.
* Usually this would be blocks corresponding to proofs, however it may
* also contain other blocks e.g. things that `capabilities` or `facts` may
* link.
* It is not guaranteed to include all the blocks of this DAG, as it represents
* a partial DAG of the delegation desired for transporting.
*
* Also note that map may contain blocks that are not part of this
* delegation DAG. That is because `Delegation` is usually constructed as
* view / selection over the CAR which may contain bunch of other blocks.
*/
* Map of all the IPLD blocks that where included with this delegation DAG.
* Usually this would be blocks corresponding to proofs, however it may
* also contain other blocks e.g. things that `capabilities` or `facts` may
* link.
* It is not guaranteed to include all the blocks of this DAG, as it represents
* a partial DAG of the delegation desired for transporting.
*
* Also note that map may contain blocks that are not part of this
* delegation DAG. That is because `Delegation` is usually constructed as
* view / selection over the CAR which may contain bunch of other blocks.
*/
readonly blocks: Map<string, Block>

readonly cid: UCANLink<C>
Expand Down Expand Up @@ -132,13 +126,13 @@ export interface Invocation<C extends Capability = Capability>

export interface InvocationOptions<C extends Capability = Capability>
extends UCANOptions {
issuer: SigningPrincipal
issuer: Signer
capability: C
}

export interface IssuedInvocation<C extends Capability = Capability>
extends DelegationOptions<[C]> {
readonly issuer: SigningPrincipal
readonly issuer: Signer
readonly audience: Principal
readonly capabilities: [C]

Expand Down Expand Up @@ -390,3 +384,7 @@ export interface URI<P extends Protocol = Protocol> extends URL {
export type URIString<P extends URI> = `${URI['protocol']}${string}` & {
protocol?: Protocol
}

Copy link
Collaborator Author

@Gozala Gozala Sep 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export interface Verifier {
   verify(did: UCAN.DID, signature: Signature): Await<boolean>
}

export interface PrincipalParser {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export interface PrincipalParser {
export interface VerifierParser {

parse(did: UCAN.DID): UCAN.Verifier
}
Empty file.
20 changes: 0 additions & 20 deletions packages/interface/src/principal.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/interface/src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
ConnectionView,
Service,
Principal,
SigningPrincipal,
Signer,
Failure,
} from './lib.js'

Expand Down Expand Up @@ -137,7 +137,7 @@ type Store = {
}
declare var store: Store
declare var channel: ConnectionView<{ store: Store }>
declare const alice: SigningPrincipal
declare const alice: Signer
declare const bob: Principal
declare const car: UCAN.Link

Expand Down
Loading