Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ucanto/interface

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ucanto/interface - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

2

package.json
{
"name": "@ucanto/interface",
"description": "interface definitions for ucanto",
"version": "0.4.0",
"version": "0.5.0",
"types": "./dist/src/lib.d.ts",

@@ -6,0 +6,0 @@ "main": "./src/lib.js",

@@ -1,3 +0,3 @@

import * as UCAN from "@ipld/dag-ucan"
import type { DID, Identity, Signer, Verifier, Signature } from "@ipld/dag-ucan"
import * as UCAN from '@ipld/dag-ucan'
import type { DID, Identity, Signer, Verifier, Signature } from '@ipld/dag-ucan'

@@ -4,0 +4,0 @@ export type { DID, Identity, Signer, Verifier, Signature }

@@ -9,2 +9,3 @@ import {

Ability,
URI,
Capability,

@@ -14,4 +15,8 @@ DID,

Await,
API,
} from "./lib.js"
Proof,
SigningAuthority,
IssuedInvocationView,
Fact,
UCANOptions,
} from './lib.js'

@@ -59,8 +64,2 @@ export interface Source {

export type Parser<
I extends unknown,
O extends unknown,
X extends { error: true } = Failure
> = (input: I) => Result<O, X>
export interface Decoder<

@@ -71,3 +70,3 @@ I extends unknown,

> {
decode: Parser<I, O, X> //(input: I): Result<O, X>
decode: (input: I) => Result<O, X>
}

@@ -90,6 +89,6 @@

to: TheCapabilityParser<DirectMatch<T>>
derives: Derives<T, M["value"]>
derives: Derives<T, M['value']>
}
export interface Derives<T, U> {
export interface Derives<T, U = T> {
(self: T, from: U): Result<true, Failure>

@@ -136,7 +135,48 @@ }

export type InferCaveatParams<T> = keyof T extends never
? never | undefined
: {
[K in keyof T]: T[K] extends { toJSON(): infer U } ? U : T[K]
}
export interface TheCapabilityParser<M extends Match<ParsedCapability>>
extends CapabilityParser<M> {
readonly can: M["value"]["can"]
readonly can: M['value']['can']
create(
input: InferCreateOptions<M['value']['with'], M['value']['caveats']>
): Capability<M['value']['can'], M['value']['uri']['href']> &
M['value']['caveats']
invoke(
options: InvokeCapabilityOptions<M['value']['with'], M['value']['caveats']>
): IssuedInvocationView<
Capability<M['value']['can'], M['value']['uri']['href']> &
M['value']['caveats']
>
}
export type InferCreateOptions<R extends Resource, C extends {}> = {
with: Resource
caveats?: {}
} & Optionalize<{
with: R
caveats: InferCaveatParams<C>
}>
type Optionalize<T> = InferRequried<T> & InferOptional<T>
type InferOptional<T> = {
[K in keyof T as T[K] | undefined extends T[K] ? K : never]?: T[K]
}
type InferRequried<T> = {
[K in keyof T as T[K] | undefined extends T[K] ? never : K]: T[K]
}
export type InvokeCapabilityOptions<R extends Resource, C> = UCANOptions &
InferCreateOptions<R, C> & {
issuer: SigningAuthority
}
export interface CapabilityParser<M extends Match = Match> extends View<M> {

@@ -234,39 +274,35 @@ /**

Can extends Ability = Ability,
Resource extends URI = URI,
C extends object = {}
> {
can: Can
with: Resource
uri: URL
with: Resource['href']
uri: Resource
caveats: C
}
export type InferCaveats<C> = InferRequiredCaveats<C> & InferOptionalCaveats<C>
export type InferCaveats<C> = Optionalize<{
[K in keyof C]: C[K] extends Decoder<unknown, infer T, infer _> ? T : never
}>
export type InferOptionalCaveats<C> = {
[Key in keyof C as C[Key] extends Decoder<any, infer _ | undefined, any>
? Key
: never]?: C[Key] extends Decoder<unknown, infer T | undefined, infer _>
? T
: never
}
export type InferRequiredCaveats<C> = {
[Key in keyof C as C[Key] extends Decoder<any, infer _ | undefined, any>
? never
: Key]: C[Key] extends Decoder<unknown, infer T, infer _> ? T : never
}
export interface Descriptor<A extends Ability, C extends Caveats> {
export interface Descriptor<
A extends Ability,
R extends URI,
C extends Caveats
> {
can: A
with: Decoder<Resource, URL, Failure>
with: Decoder<Resource, R, Failure>
caveats?: C
derives: Derives<
ParsedCapability<A, InferCaveats<C>>,
ParsedCapability<A, InferCaveats<C>>
derives?: Derives<
ParsedCapability<A, R, InferCaveats<C>>,
ParsedCapability<A, R, InferCaveats<C>>
>
}
export interface CapabilityMatch<A extends Ability, C extends Caveats>
extends DirectMatch<ParsedCapability<A, InferCaveats<C>>> {}
export interface CapabilityMatch<
A extends Ability,
R extends URI,
C extends Caveats
> extends DirectMatch<ParsedCapability<A, R, InferCaveats<C>>> {}

@@ -281,5 +317,7 @@ export interface CanIssue {

export interface ValidationOptions<
C extends ParsedCapability = ParsedCapability
> extends CanIssue {
export interface AuthorityOptions {
authority: AuthorityParser
}
export interface IssuingOptions {
/**

@@ -292,3 +330,5 @@ * You can provide default set of capabilities per did, which is used to

my?: (issuer: DID) => Capability[]
}
export interface ProofResolver extends AuthorityOptions, IssuingOptions {
/**

@@ -300,9 +340,14 @@ * You can provide a proof resolver that validator will call when UCAN

resolve?: (proof: LinkedProof) => Await<Result<Delegation, UnavailableProof>>
}
authority: AuthorityParser
capability: CapabilityParser<Match<C>>
export interface ValidationOptions<C extends ParsedCapability>
extends CanIssue,
IssuingOptions,
AuthorityOptions,
ProofResolver {
capability: CapabilityParser<Match<C, any>>
}
export interface DelegationError extends Failure {
name: "InvalidClaim"
name: 'InvalidClaim'
causes: (InvalidCapability | EscalatedDelegation | DelegationError)[]

@@ -314,3 +359,3 @@

export interface EscalatedDelegation extends Failure {
name: "EscalatedCapability"
name: 'EscalatedCapability'
claimed: ParsedCapability

@@ -322,3 +367,3 @@ delegated: object

export interface UnknownCapability extends Failure {
name: "UnknownCapability"
name: 'UnknownCapability'
capability: Capability

@@ -328,3 +373,3 @@ }

export interface MalformedCapability extends Failure {
name: "MalformedCapability"
name: 'MalformedCapability'
capability: Capability

@@ -334,3 +379,3 @@ }

export interface InvalidAudience extends Failure {
readonly name: "InvalidAudience"
readonly name: 'InvalidAudience'
readonly audience: Identity

@@ -341,3 +386,3 @@ readonly delegation: Delegation

export interface UnavailableProof extends Failure {
readonly name: "UnavailableProof"
readonly name: 'UnavailableProof'
readonly link: LinkedProof

@@ -347,3 +392,3 @@ }

export interface Expired extends Failure {
readonly name: "Expired"
readonly name: 'Expired'
readonly delegation: Delegation

@@ -354,3 +399,3 @@ readonly expiredAt: number

export interface NotValidBefore extends Failure {
readonly name: "NotValidBefore"
readonly name: 'NotValidBefore'
readonly delegation: Delegation

@@ -361,3 +406,3 @@ readonly validAt: number

export interface InvalidSignature extends Failure {
readonly name: "InvalidSignature"
readonly name: 'InvalidSignature'
readonly issuer: Identity

@@ -378,3 +423,3 @@ readonly audience: Identity

export interface Unauthorized extends Failure {
name: "Unauthorized"
name: 'Unauthorized'
cause: InvalidCapability | InvalidProof | InvalidClaim

@@ -385,3 +430,3 @@ }

issuer: Identity
name: "InvalidClaim"
name: 'InvalidClaim'
capability: ParsedCapability

@@ -388,0 +433,0 @@ delegation: Delegation

@@ -1,4 +0,4 @@

import type * as Transport from "./transport.js"
import type { Tuple } from "./transport.js"
export * as UCAN from "@ipld/dag-ucan"
import type * as Transport from './transport.js'
import type { Tuple } from './transport.js'
export * as UCAN from '@ipld/dag-ucan'
import type {

@@ -8,3 +8,3 @@ Authority,

AuthorityParser,
} from "./authority.js"
} from './authority.js'
import type {

@@ -28,3 +28,3 @@ Phantom,

Capability,
} from "@ipld/dag-ucan"
} from '@ipld/dag-ucan'

@@ -34,3 +34,3 @@ export type {

MultibaseDecoder,
} from "multiformats/bases/interface"
} from 'multiformats/bases/interface'

@@ -66,7 +66,7 @@ export type {

UnavailableProof,
} from "./capability.js"
} from './capability.js'
export * from "./transport.js"
export * from "./authority.js"
export * from "./capability.js"
export * from './transport.js'
export * from './authority.js'
export * from './capability.js'

@@ -89,9 +89,4 @@ /**

export interface DelegationOptions<
C extends [Capability, ...Capability[]],
A extends number = number
> {
issuer: SigningAuthority<A>
export interface UCANOptions {
audience: Identity
capabilities: C
lifetimeInSeconds?: number

@@ -107,2 +102,11 @@ expiration?: number

export interface DelegationOptions<
C extends [Capability, ...Capability[]],
A extends number = number
> extends UCANOptions {
issuer: SigningAuthority<A>
audience: Identity
capabilities: C
}
export interface Delegation<

@@ -137,7 +141,6 @@ C extends [Capability, ...Capability[]] = [Capability, ...Capability[]]

export interface InvocationOptions<C extends Capability = Capability> {
export interface InvocationOptions<C extends Capability = Capability>
extends UCANOptions {
issuer: SigningAuthority
audience: Audience
capability: C
proofs?: Proof[]
}

@@ -206,3 +209,3 @@

C extends Capability
> = ResolveServiceMethod<S, C["can"]> extends ServiceMethod<
> = ResolveServiceMethod<S, C['can']> extends ServiceMethod<
infer C,

@@ -218,3 +221,3 @@ infer _T,

S
> = ResolveServiceMethod<S, C["can"]> extends ServiceMethod<
> = ResolveServiceMethod<S, C['can']> extends ServiceMethod<
infer _,

@@ -242,4 +245,5 @@ infer T,

extends IssuedInvocation<C> {
delegate(): Promise<Delegation<[C]>>
execute<T extends InvocationService<C>>(
service: Connection<T>
service: ConnectionView<T>
): Await<InferServiceInvocationReturn<C, T>>

@@ -261,3 +265,3 @@ }

C extends Capability,
A extends string = C["can"]
A extends string = C['can']
> = A extends `${infer Base}/${infer Path}`

@@ -272,3 +276,3 @@ ? { [Key in Base]: InvocationService<C, Path> }

T extends Record<string, any>,
Ability extends string = C["can"]
Ability extends string = C['can']
> = Ability extends `${infer Base}/${infer Path}`

@@ -292,3 +296,3 @@ ? ExecuteInvocation<C, T[Base], Path>

capability: Capability
name: "HandlerNotFound"
name: 'HandlerNotFound'
}

@@ -299,3 +303,3 @@

cause: Error
name: "HandlerExecutionError"
name: 'HandlerExecutionError'
}

@@ -349,5 +353,5 @@

readonly canIssue?: CanIssue["canIssue"]
readonly my?: InvocationContext["my"]
readonly resolve?: InvocationContext["resolve"]
readonly canIssue?: CanIssue['canIssue']
readonly my?: InvocationContext['my']
readonly resolve?: InvocationContext['resolve']
}

@@ -380,1 +384,11 @@

export type Await<T> = T | PromiseLike<T> | Promise<T>
export type Protocol<Scheme extends string = string> = `${Scheme}:`
export interface URI<P extends Protocol = Protocol> extends URL {
protocol: P
href: `${P}${string}`
}
export type URIString<P extends URI> = `${URI['protocol']}${string}` & {
protocol?: Protocol
}

@@ -10,2 +10,3 @@ import type {

Connection,
ConnectionView,
Service,

@@ -15,3 +16,3 @@ Authority,

Failure,
} from "./lib.js"
} from './lib.js'

@@ -122,6 +123,6 @@ export type QueryInput = {

type StoreAdd = (
input: Invocation<{ can: "store/add"; with: UCAN.DID; link: UCAN.Link }>
input: Invocation<{ can: 'store/add'; with: UCAN.DID; link: UCAN.Link }>
) => Result<
| { status: "done"; with: UCAN.DID; link: UCAN.Link }
| { status: "pending"; with: UCAN.DID; link: UCAN.Link; url: string },
| { status: 'done'; with: UCAN.DID; link: UCAN.Link }
| { status: 'pending'; with: UCAN.DID; link: UCAN.Link; url: string },
Failure

@@ -131,3 +132,3 @@ >

type StoreRemove = (
input: Invocation<{ can: "store/remove"; with: UCAN.DID; link: UCAN.Link }>
input: Invocation<{ can: 'store/remove'; with: UCAN.DID; link: UCAN.Link }>
) => Result<boolean, Failure>

@@ -140,3 +141,3 @@

declare var store: Store
declare var channel: Connection<{ store: Store }>
declare var channel: ConnectionView<{ store: Store }>
declare const alice: SigningAuthority

@@ -150,5 +151,5 @@ declare const bob: Authority

type A = ToPath<"">
type B = ToPath<"foo">
type C = ToPath<"foo/bar">
type A = ToPath<''>
type B = ToPath<'foo'>
type C = ToPath<'foo/bar'>

@@ -171,3 +172,3 @@ type Unpack<T> = T extends infer A & infer B ? [A, B] : []

declare var host: Connection<{ store: Store }>
declare var host: ConnectionView<{ store: Store }>

@@ -179,3 +180,3 @@ const demo = async () => {

capability: {
can: "store/add",
can: 'store/add',
with: alice.did(),

@@ -190,3 +191,3 @@ link: car,

capability: {
can: "store/remove",
can: 'store/remove',
with: alice.did(),

@@ -193,0 +194,0 @@ link: car,

@@ -1,3 +0,3 @@

import type { Phantom, Await } from "@ipld/dag-ucan"
import * as UCAN from "@ipld/dag-ucan"
import type { Phantom, Await } from '@ipld/dag-ucan'
import * as UCAN from '@ipld/dag-ucan'
import type {

@@ -8,3 +8,3 @@ ServiceInvocation,

Capability,
} from "./lib.js"
} from './lib.js'

@@ -11,0 +11,0 @@ /**

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc