iso-ucan 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @import {StandardSchemaV1} from '@standard-schema/spec'
3
+ */
4
+ /**
5
+ * @template {StandardSchemaV1} Schema
6
+ * @template {string} [Cmd=string]
7
+ * @typedef {Object} CapabilityOptions
8
+ * @prop {Schema} schema
9
+ * @prop {Cmd} cmd
10
+ */
11
+ /**
12
+ * @template {StandardSchemaV1} Schema
13
+ * @template {string} [Cmd=string]
14
+ */
15
+ export class Capability<Schema extends StandardSchemaV1, Cmd extends string = string> {
16
+ /**
17
+ * @template {StandardSchemaV1} Schema
18
+ * @template {string} [Cmd=string]
19
+ * @param {CapabilityOptions<Schema, Cmd>} options
20
+ */
21
+ static from<Schema_1 extends StandardSchemaV1, Cmd_1 extends string = string>(options: CapabilityOptions<Schema_1, Cmd_1>): Capability<Schema_1, Cmd_1>;
22
+ /**
23
+ * @param {CapabilityOptions<Schema, Cmd>} options
24
+ */
25
+ constructor(options: CapabilityOptions<Schema, Cmd>);
26
+ schema: Schema;
27
+ cmd: Cmd;
28
+ /**
29
+ * @param {StandardSchemaV1.InferInput<Schema>} args
30
+ */
31
+ validate(args: StandardSchemaV1.InferInput<Schema>): Promise<StandardSchemaV1.Result<any>>;
32
+ /**
33
+ * @param {import("./types.js").CapabilityInvokeOptions<Schema>} options
34
+ */
35
+ invoke(options: import("./types.js").CapabilityInvokeOptions<Schema>): Promise<Invocation>;
36
+ /**
37
+ *
38
+ * @param {import("./types.js").CapabilityDelegateOptions} options
39
+ */
40
+ delegate(options: import("./types.js").CapabilityDelegateOptions): Promise<Delegation>;
41
+ }
42
+ export type CapabilityOptions<Schema extends StandardSchemaV1, Cmd extends string = string> = {
43
+ schema: Schema;
44
+ cmd: Cmd;
45
+ };
46
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
47
+ import { Invocation } from './invocation.js';
48
+ import { Delegation } from './delegation.js';
49
+ //# sourceMappingURL=capability.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../../src/capability.js"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;;;;;GAMG;AAEH;;;GAGG;AACH,wBAHgC,MAAM,SAAzB,gBAAkB,EACR,GAAG,SAAb,MAAQ;IAWnB;;;;OAIG;IACH,6BAJa,gBAAkB,gBAClB,MAAQ,oBACV,iBAAiB,CAAC,QAAM,EAAE,KAAG,CAAC,+BAIxC;IAfD;;OAEG;IACH,qBAFW,iBAAiB,CAAC,MAAM,EAAE,GAAG,CAAC,EAKxC;IAFC,eAA4B;IAC5B,SAAsB;IAYxB;;OAEG;IACH,eAFW,4BAA4B,MAAM,CAAC,yCAK7C;IAED;;OAEG;IACH,gBAFW,OAAO,YAAY,EAAE,uBAAuB,CAAC,MAAM,CAAC,uBAoB9D;IAED;;;OAGG;IACH,kBAFW,OAAO,YAAY,EAAE,yBAAyB,uBAIxD;CACF;8BAnE+B,MAAM,SAAzB,gBAAkB,EACR,GAAG,SAAb,MAAQ;YAEX,MAAM;SACN,GAAG;;sCARsB,uBAAuB;2BAH/B,iBAAiB;2BADjB,iBAAiB"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @import {InferProtocol, RouteOutput, StandardSchemaV1, ClientOptions, RouterClient} from './types'
3
+ * @import {Capability} from './capability'
4
+ */
5
+ /**
6
+ * Workaround to make imports types work
7
+ * @template {{ cmd: string; in: unknown; out: unknown; }} T
8
+ * @typedef {Object} DELETE_ME
9
+ * @prop {string} url
10
+ * @prop {Capability<StandardSchemaV1, string>[]} capabilities
11
+ * @prop {InferProtocol<Record<string, RouteOutput<Capability<StandardSchemaV1>, unknown>>>} router
12
+ * @prop {ClientOptions} options
13
+ * @prop {RouterClient<T>} routerClient
14
+ */
15
+ /**
16
+ * @template {InferProtocol<Record<string, RouteOutput<Capability<StandardSchemaV1>, unknown>>>} T
17
+ * @param {ClientOptions} options
18
+ * @returns {RouterClient<T>}
19
+ */
20
+ export function createClient<T extends InferProtocol<Record<string, RouteOutput<Capability<StandardSchemaV1>, unknown>>>>(options: ClientOptions): RouterClient<T>;
21
+ /**
22
+ * Workaround to make imports types work
23
+ */
24
+ export type DELETE_ME<T extends {
25
+ cmd: string;
26
+ in: unknown;
27
+ out: unknown;
28
+ }> = {
29
+ url: string;
30
+ capabilities: Capability<StandardSchemaV1, string>[];
31
+ router: InferProtocol<Record<string, RouteOutput<Capability<StandardSchemaV1>, unknown>>>;
32
+ options: ClientOptions;
33
+ routerClient: RouterClient<T>;
34
+ };
35
+ import type { StandardSchemaV1 } from './types';
36
+ import type { Capability } from './capability';
37
+ import type { RouteOutput } from './types';
38
+ import type { InferProtocol } from './types';
39
+ import type { ClientOptions } from './types';
40
+ import type { RouterClient } from './types';
41
+ import type { StandardSchemaV1 as StandardSchemaV1_1 } from './types';
42
+ import type { Capability as Capability_1 } from './capability';
43
+ import type { RouteOutput as RouteOutput_1 } from './types';
44
+ import type { InferProtocol as InferProtocol_1 } from './types';
45
+ import type { ClientOptions as ClientOptions_1 } from './types';
46
+ import type { RouterClient as RouterClient_1 } from './types';
47
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.js"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AAEH;;;;GAIG;AACH,6BAJiG,CAAC,SAArF,cAAe,MAAM,CAAC,MAAM,EAAE,YAAY,WAAW,gBAAgB,CAAC,EAAE,OAAO,CAAC,CAAC,CAAE,WACrF,aAAa,GACX,aAAa,CAAC,CAAC,CAgC3B;;;;sBA5C0D,CAAC,SAA/C;IAAG,GAAG,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,OAAO,CAAC;IAAC,GAAG,EAAE,OAAO,CAAC;CAAG;SAEhD,MAAM;kBACN,WAAW,gBAAgB,EAAE,MAAM,CAAC,EAAE;YACtC,cAAc,MAAM,CAAC,MAAM,EAAE,YAAY,WAAW,gBAAgB,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;aACjF,aAAa;kBACb,aAAa,CAAC,CAAC;;sCAZmE,SAAS;gCACxE,cAAc;iCADiD,SAAS;mCAAT,SAAS;mCAAT,SAAS;kCAAT,SAAS;4DAAT,SAAS;gDACxE,cAAc;kDADiD,SAAS;sDAAT,SAAS;sDAAT,SAAS;oDAAT,SAAS"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @import {DelegationValidateOptions, Policy, DelegationOptions, DelegationPayload, DID, DIDURL} from './types.js'
3
+ * @import {CID} from 'multiformats'
4
+ */
5
+ /**
6
+ * UCAN Delegation
7
+ */
8
+ export class Delegation {
9
+ /**
10
+ *
11
+ * @param {import("./types.js").DelegationFromOptions} options
12
+ */
13
+ static from(options: import("./types.js").DelegationFromOptions): Promise<Delegation>;
14
+ /**
15
+ *
16
+ * @param {DelegationOptions & { cmd: string }} options
17
+ */
18
+ static create(options: DelegationOptions & {
19
+ cmd: string;
20
+ }): Promise<Delegation>;
21
+ /**
22
+ *
23
+ * @param {import("./types.js").DecodedEnvelope<'dlg'>} envelope
24
+ * @param {Uint8Array} bytes
25
+ * @param {CID} cid
26
+ */
27
+ constructor(envelope: import("./types.js").DecodedEnvelope<"dlg">, bytes: Uint8Array, cid: CID);
28
+ /** @type {DIDURL} */
29
+ iss: DIDURL;
30
+ /** @type {DID} */
31
+ aud: DID;
32
+ /** @type {DID | null} */
33
+ sub: DID | null;
34
+ /** @type {string} */
35
+ cmd: string;
36
+ /** @type {Policy} */
37
+ pol: Policy;
38
+ /** @type {number | undefined} */
39
+ nbf: number | undefined;
40
+ /** @type {Uint8Array} */
41
+ nonce: Uint8Array;
42
+ /** @type {Record<string, unknown> | undefined} */
43
+ meta: Record<string, unknown> | undefined;
44
+ /** @type {number | null} */
45
+ exp: number | null;
46
+ envelope: import("./types.js").DecodedEnvelope<"dlg">;
47
+ bytes: Uint8Array<ArrayBufferLike>;
48
+ cid: CID<any, number, number, import("multiformats").Version>;
49
+ /**
50
+ * @param {DelegationValidateOptions} options
51
+ */
52
+ validate(options: DelegationValidateOptions): Promise<boolean>;
53
+ toString(): string;
54
+ }
55
+ import type { DIDURL } from './types.js';
56
+ import type { DID } from './types.js';
57
+ import type { Policy } from './types.js';
58
+ import type { CID } from 'multiformats';
59
+ import type { DelegationValidateOptions } from './types.js';
60
+ import type { DelegationOptions } from './types.js';
61
+ //# sourceMappingURL=delegation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delegation.d.ts","sourceRoot":"","sources":["../../src/delegation.js"],"names":[],"mappings":"AAgBA;;;GAGG;AAEH;;GAEG;AACH;IA0CE;;;OAGG;IACH,qBAFW,OAAO,YAAY,EAAE,qBAAqB,uBAuBpD;IAED;;;OAGG;IACH,uBAFW,iBAAiB,GAAG;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,uBA6C7C;IAhGD;;;;;OAKG;IACH,sBAJW,OAAO,YAAY,EAAE,eAAe,CAAC,KAAK,CAAC,SAC3C,UAAU,OACV,GAAG,EAgBb;IAvCD,qBAAqB;IACrB,KADW,MAAM,CACd;IACH,kBAAkB;IAClB,KADW,GAAG,CACX;IACH,yBAAyB;IACzB,KADW,GAAG,GAAG,IAAI,CAClB;IACH,qBAAqB;IACrB,KADW,MAAM,CACd;IACH,qBAAqB;IACrB,KADW,MAAM,CACd;IACH,iCAAiC;IACjC,KADW,MAAM,GAAG,SAAS,CAC1B;IACH,yBAAyB;IACzB,OADW,UAAU,CAChB;IACL,kDAAkD;IAClD,MADW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAC1C;IACJ,4BAA4B;IAC5B,KADW,MAAM,GAAG,IAAI,CACrB;IASD,sDAAwB;IACxB,mCAAkB;IAClB,8DAAc;IAyFhB;;OAEG;IACH,kBAFW,yBAAyB,oBAanC;IAED,mBAEC;CACF;4BAhJsG,YAAY;yBAAZ,YAAY;4BAAZ,YAAY;yBAC7F,cAAc;+CADmE,YAAY;uCAAZ,YAAY"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ *
3
+ * @param {EnvelopeSignOptions} options
4
+ */
5
+ export function sign(options: EnvelopeSignOptions): Promise<{
6
+ signature: Uint8Array<ArrayBufferLike>;
7
+ signaturePayload: SignaturePayload;
8
+ }>;
9
+ /**
10
+ * Encode a UCAN envelope
11
+ *
12
+ * @see https://github.com/ucan-wg/spec#envelope
13
+ * @param {EnvelopeEncodeOptions} options
14
+ *
15
+ */
16
+ export function encode(options: EnvelopeEncodeOptions): ByteView<(Uint8Array<ArrayBufferLike> | SignaturePayload<unknown>)[]>;
17
+ /**
18
+ * Decode a UCAN envelope
19
+ *
20
+ * @template {PayloadSpec} Spec
21
+ * @see https://github.com/ucan-wg/spec#envelope
22
+ * @param {EnvelopeDecodeOptions} options
23
+ * @returns {DecodedEnvelope<Spec>}
24
+ */
25
+ export function decode<Spec extends PayloadSpec>(options: EnvelopeDecodeOptions): DecodedEnvelope<Spec>;
26
+ /**
27
+ * @import { Envelope, PayloadTag, EnvelopeDecodeOptions, EnvelopeEncodeOptions, EnvelopeSignOptions, SignaturePayload, PayloadSpec, DecodedEnvelope, DelegationPayload, InvocationPayload} from './types.js'
28
+ * @import { ByteView } from 'multiformats'
29
+ */
30
+ /** Version */
31
+ export const VERSION: "1.0.0-rc.1";
32
+ import type { EnvelopeSignOptions } from './types.js';
33
+ import type { SignaturePayload } from './types.js';
34
+ import type { EnvelopeEncodeOptions } from './types.js';
35
+ import type { ByteView } from 'multiformats';
36
+ import type { PayloadSpec } from './types.js';
37
+ import type { EnvelopeDecodeOptions } from './types.js';
38
+ import type { DecodedEnvelope } from './types.js';
39
+ //# sourceMappingURL=envelope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../src/envelope.js"],"names":[],"mappings":"AAWA;;;GAGG;AACH,8BAFW,mBAAmB;;;GAmB7B;AAED;;;;;;GAMG;AACH,gCAHW,qBAAqB,yEAS/B;AAED;;;;;;;GAOG;AACH,uBAL2B,IAAI,SAAlB,WAAa,WAEf,qBAAqB,GACnB,gBAAgB,IAAI,CAAC,CAgCjC;AApFD;;;GAGG;AAEH,cAAc;AACd,sBAAuB,YAAY,CAAA;yCAL8J,YAAY;sCAAZ,YAAY;2CAAZ,YAAY;8BAChL,cAAc;iCADsJ,YAAY;2CAAZ,YAAY;qCAAZ,YAAY"}
@@ -0,0 +1,2 @@
1
+ export * as Varsig from "./varsig.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":""}
@@ -0,0 +1,46 @@
1
+ /**
2
+ *
3
+ * @param {import("./types.js").InvocationPayload} payload
4
+ * @param {Delegation[]} proofs
5
+ */
6
+ export function assertProofs(payload: import("./types.js").InvocationPayload, proofs: Delegation[]): boolean;
7
+ /**
8
+ * @import {Delegation} from './delegation.js'
9
+ * @import {CID} from 'multiformats'
10
+ */
11
+ /**
12
+ * UCAN Invocation
13
+ */
14
+ export class Invocation {
15
+ /**
16
+ *
17
+ * @param {import("./types.js").InvocationFromOptions} options
18
+ */
19
+ static from(options: import("./types.js").InvocationFromOptions): Promise<Invocation>;
20
+ /**
21
+ * @param {import("./types.js").InvocationOptions} options
22
+ */
23
+ static create(options: import("./types.js").InvocationOptions): Promise<Invocation>;
24
+ /**
25
+ *
26
+ * @param {import("./types.js").DecodedEnvelope<'inv'>} envelope
27
+ * @param {Uint8Array} bytes
28
+ * @param {CID} cid
29
+ * @param {Delegation[]} delegations
30
+ */
31
+ constructor(envelope: import("./types.js").DecodedEnvelope<"inv">, bytes: Uint8Array, cid: CID, delegations: Delegation[]);
32
+ /**
33
+ * @type {Delegation[]}
34
+ */
35
+ delegations: Delegation[];
36
+ /**
37
+ * @type {CID}
38
+ */
39
+ cid: CID;
40
+ envelope: import("./types.js").DecodedEnvelope<"inv">;
41
+ payload: import("./types.js").InvocationPayload;
42
+ bytes: Uint8Array<ArrayBufferLike>;
43
+ }
44
+ import type { Delegation } from './delegation.js';
45
+ import type { CID } from 'multiformats';
46
+ //# sourceMappingURL=invocation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invocation.d.ts","sourceRoot":"","sources":["../../src/invocation.js"],"names":[],"mappings":"AA0KA;;;;GAIG;AACH,sCAHW,OAAO,YAAY,EAAE,iBAAiB,UACtC,UAAU,EAAE,WAqDtB;AApND;;;GAGG;AAEH;;GAEG;AACH;IA0BE;;;OAGG;IACH,qBAFW,OAAO,YAAY,EAAE,qBAAqB,uBA6CpD;IAED;;OAEG;IACH,uBAFW,OAAO,YAAY,EAAE,iBAAiB,uBAmDhD;IApHD;;;;;;OAMG;IACH,sBALW,OAAO,YAAY,EAAE,eAAe,CAAC,KAAK,CAAC,SAC3C,UAAU,OACV,GAAG,eACH,UAAU,EAAE,EAQtB;IAvBD;;OAEG;IACH,aAFU,UAAU,EAAE,CAEX;IAEX;;OAEG;IACH,KAFU,GAAG,CAEV;IAUD,sDAAwB;IACxB,gDAA+B;IAC/B,mCAAkB;CA2GrB;gCAvI4B,iBAAiB;yBACxB,cAAc"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Validates invocation arguments against a UCAN policy.
3
+ *
4
+ * @template {Record<string, unknown>} Args
5
+ * @param {Args} args The arguments of the eventual invocation.
6
+ * @param {import("./types.js").Policy<Args>} policy An array of policy statements.
7
+ * @returns {boolean} True if the args are valid according to the policy, false otherwise.
8
+ */
9
+ export function validate<Args extends Record<string, unknown>>(args: Args, policy: import("./types.js").Policy<Args>): boolean;
10
+ //# sourceMappingURL=policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../src/policy.js"],"names":[],"mappings":"AAoQA;;;;;;;GAOG;AACH,yBALuC,IAAI,SAA7B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAE,QAC3B,IAAI,UACJ,OAAO,YAAY,EAAE,MAAM,CAAC,IAAI,CAAC,GAC/B,OAAO,CAKnB"}
@@ -0,0 +1,5 @@
1
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
2
+ import type { Capability } from './capability.js';
3
+ import type { RouteOptions, RouteOutput } from './types.js';
4
+ export declare function route<Cap extends Capability<StandardSchemaV1>, Output>(options: RouteOptions<Cap, Output>): RouteOutput<Cap, Output>;
5
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EAAuB,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAEhF,wBAAgB,KAAK,CAAC,GAAG,SAAS,UAAU,CAAC,gBAAgB,CAAC,EAAE,MAAM,EACpE,OAAO,EAAE,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,GACjC,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,CAiB1B"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Store
3
+ */
4
+ export class Store {
5
+ /**
6
+ * @param {Driver} driver
7
+ */
8
+ constructor(driver: Driver);
9
+ /** @type {Driver} */
10
+ driver: Driver;
11
+ /** @type {KV} */
12
+ kv: KV;
13
+ /**
14
+ * @param {Delegation[]} delegations
15
+ */
16
+ add(delegations: Delegation[]): Promise<void>;
17
+ /**
18
+ * Get a delegation by cid
19
+ *
20
+ * @param {string} cid
21
+ */
22
+ get(cid: string): Promise<Delegation | undefined>;
23
+ /**
24
+ * Resolve a proof by CID
25
+ *
26
+ * @param {CID} cid
27
+ */
28
+ resolveProof(cid: CID): Promise<Delegation>;
29
+ /**
30
+ * List proofs by sub and aud
31
+ *
32
+ * @param {import('./types.js').StoreProofsOptions} options
33
+ */
34
+ proofs(options: import("./types.js").StoreProofsOptions): AsyncGenerator<Delegation, void, unknown>;
35
+ /**
36
+ * Resolve a single chain of proofs ending with a root (subject === issuer).
37
+ * Returns the first such chain found (depth-first).
38
+ *
39
+ * @param {import('./types.js').StoreProofsOptions} options
40
+ * @returns {Promise<Delegation[]>}
41
+ */
42
+ chain({ aud, sub, cmd }: import("./types.js").StoreProofsOptions): Promise<Delegation[]>;
43
+ #private;
44
+ }
45
+ import type { Driver } from 'iso-kv';
46
+ import { KV } from 'iso-kv';
47
+ import type { Delegation } from './delegation.js';
48
+ import type { CID } from 'multiformats';
49
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/store.js"],"names":[],"mappings":"AAYA;;GAEG;AACH;IAOE;;OAEG;IACH,oBAFW,MAAM,EAQhB;IAfD,qBAAqB;IACrB,QADW,MAAM,CACX;IAEN,iBAAiB;IACjB,IADW,EAAE,CACX;IAoCF;;OAEG;IACH,iBAFW,UAAU,EAAE,iBAMtB;IAED;;;;OAIG;IACH,SAFW,MAAM,mCAIhB;IAED;;;;OAIG;IACH,kBAFW,GAAG,uBAQb;IAED;;;;OAIG;IACH,gBAFW,OAAO,YAAY,EAAE,kBAAkB,6CA8BjD;IAED;;;;;;OAMG;IACH,yBAHW,OAAO,YAAY,EAAE,kBAAkB,GACrC,OAAO,CAAC,UAAU,EAAE,CAAC,CAmCjC;;CACF;4BA7JwB,QAAQ;mBALd,QAAQ;gCAIE,iBAAiB;yBAExB,cAAc"}
@@ -0,0 +1,187 @@
1
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
2
+ import type { Resolver as _DidResolver } from 'iso-did';
3
+ import type { DID, DIDURLObject, VerifiableDID } from 'iso-did/types';
4
+ import type { ISigner } from 'iso-signatures/types';
5
+ import type { Resolver } from 'iso-signatures/verifiers/resolver.js';
6
+ import type { CID } from 'multiformats';
7
+ import type { Capability } from './capability';
8
+ import type { Delegation } from './delegation';
9
+ import type { Invocation } from './invocation';
10
+ import type { Store } from './store';
11
+ import type { Policy } from './types/policy';
12
+ export type { StandardSchemaV1 } from '@standard-schema/spec';
13
+ export type { DID, DIDURL, DIDURLObject } from 'iso-did/types';
14
+ export * from './types/envelope';
15
+ export * from './types/policy';
16
+ export * from './types/varsig';
17
+ export type ResolveProof = (proof: CID) => Promise<Delegation>;
18
+ export type IsRevoked = (cid: CID) => Promise<boolean>;
19
+ export type VerifierResolver = Resolver;
20
+ export type DidResolver = _DidResolver;
21
+ export type CborPrimitive = string | number | boolean | null | bigint | Uint8Array | ArrayBuffer;
22
+ export type CborArray = CborValue[] | readonly CborValue[];
23
+ export type CborObject = {
24
+ [Key in string]: CborValue;
25
+ } | {
26
+ [Key in string]?: CborValue | undefined;
27
+ };
28
+ export type CborValue = CborPrimitive | CborArray | CborObject;
29
+ /**
30
+ * Delegation
31
+ */
32
+ export interface DelegationOptions<Args = unknown> {
33
+ iss: ISigner;
34
+ aud: DID;
35
+ sub: DID | null;
36
+ pol: Policy<Args>;
37
+ /**
38
+ * Expiration time in seconds or null for no expiration
39
+ */
40
+ exp?: number | null;
41
+ /**
42
+ * Time to live in seconds, expiration thats precedence over ttl
43
+ * @default 300
44
+ */
45
+ ttl?: number;
46
+ /**
47
+ * Not before time in seconds
48
+ * Delegation is not valid before this time
49
+ */
50
+ nbf?: number;
51
+ nonce?: Uint8Array;
52
+ cmd: string;
53
+ meta?: CborObject;
54
+ }
55
+ export interface DelegationFromOptions {
56
+ bytes: Uint8Array;
57
+ isRevoked?: IsRevoked;
58
+ didResolver?: DidResolver;
59
+ verifierResolver: VerifierResolver;
60
+ }
61
+ export interface DelegationValidateOptions {
62
+ isRevoked?: IsRevoked;
63
+ didResolver?: DidResolver;
64
+ verifierResolver: VerifierResolver;
65
+ }
66
+ export type CapabilityDelegateOptions<Args = unknown> = Omit<DelegationOptions<Args>, 'cmd'>;
67
+ /**
68
+ * Invocation
69
+ */
70
+ /**
71
+ * Invocation options
72
+ */
73
+ export interface InvocationOptions {
74
+ iss: ISigner;
75
+ aud?: DID;
76
+ sub: DID;
77
+ cmd: string;
78
+ args: CborObject;
79
+ /**
80
+ * Proofs of the chain of authority
81
+ */
82
+ prf: Delegation[];
83
+ /**
84
+ * Expiration time in seconds or null for no expiration
85
+ */
86
+ exp?: number | null;
87
+ /**
88
+ * Time to live in seconds, expiration thats precedence over ttl
89
+ * @default 300
90
+ */
91
+ ttl?: number;
92
+ /**
93
+ * Issued at time in seconds
94
+ */
95
+ iat?: number;
96
+ nbf?: number;
97
+ nonce?: Uint8Array;
98
+ cause?: CID;
99
+ meta?: CborObject;
100
+ }
101
+ export interface InvocationFromOptions {
102
+ bytes: Uint8Array;
103
+ audience: VerifiableDID;
104
+ didResolver?: DidResolver;
105
+ verifierResolver: VerifierResolver;
106
+ isRevoked?: IsRevoked;
107
+ resolveProof: ResolveProof;
108
+ }
109
+ export interface CapabilityInvokeOptions<Schema extends StandardSchemaV1> extends Omit<InvocationOptions, 'cmd' | 'args' | 'prf'> {
110
+ args: StandardSchemaV1.InferOutput<Schema>;
111
+ store: Store;
112
+ }
113
+ /**
114
+ * Store types
115
+ */
116
+ /**
117
+ * Resolve proofs options
118
+ */
119
+ export interface StoreProofsOptions {
120
+ aud?: DID;
121
+ sub: DID | null;
122
+ cmd: string;
123
+ }
124
+ /**
125
+ * Server types
126
+ */
127
+ export type Promisable<T> = T | PromiseLike<T>;
128
+ export interface HandlerOptions<Schema extends StandardSchemaV1> {
129
+ args: StandardSchemaV1.InferOutput<Schema>;
130
+ store: Store;
131
+ }
132
+ export type Handler<Schema extends StandardSchemaV1, Output> = (options: HandlerOptions<Schema>) => Promisable<Output>;
133
+ export interface RouteOptions<Cap extends Capability<StandardSchemaV1>, Output> {
134
+ capability: Cap;
135
+ handler: Handler<Cap['schema'], Output>;
136
+ }
137
+ export type RouteOutput<Cap extends Capability<StandardSchemaV1>, Output> = {
138
+ cap: Cap;
139
+ fn: (options: RouteHandlerOptions) => Promisable<Output>;
140
+ };
141
+ /**
142
+ * Infer the protocol from a router
143
+ */
144
+ export type InferProtocol<Routes extends Record<string, RouteOutput<Capability<StandardSchemaV1>, unknown>>> = {
145
+ [K in keyof Routes]: Routes[K] extends RouteOutput<infer Cap, infer Output> ? {
146
+ cmd: Cap['cmd'] extends K ? Cap['cmd'] : never;
147
+ in: StandardSchemaV1.InferOutput<Cap['schema']>;
148
+ out: Output;
149
+ } : never;
150
+ }[keyof Routes];
151
+ export type Protocol<Cap extends Capability<StandardSchemaV1> = Capability<StandardSchemaV1>> = {
152
+ cmd: Cap['cmd'];
153
+ in: StandardSchemaV1.InferOutput<Cap['schema']>;
154
+ out: unknown;
155
+ }[];
156
+ /**
157
+ * Creates a router type that validates:
158
+ * 1. Router keys match capability commands
159
+ * 2. Router values are RouteOutput types that match the capability
160
+ */
161
+ export type Router<Caps extends readonly Capability<StandardSchemaV1>[]> = {
162
+ [K in Caps[number]['cmd']]: Caps extends readonly (infer Cap)[] ? Cap extends Capability<StandardSchemaV1> ? Cap['cmd'] extends K ? RouteOutput<Cap, unknown> : never : never : never;
163
+ };
164
+ export interface RouteHandlerOptions {
165
+ request: Request;
166
+ issuer: ISigner;
167
+ invocation: Invocation;
168
+ store: Store;
169
+ }
170
+ /**
171
+ * Client type that provides type-safe request methods based on router inference
172
+ */
173
+ export type RouterClient<Router extends InferProtocol<Record<string, RouteOutput<Capability<StandardSchemaV1>, unknown>>>> = {
174
+ request<Cmd extends Router['cmd']>(cmd: Cmd, args: Extract<Router, {
175
+ cmd: Cmd;
176
+ }>['in']): Promise<Extract<Router, {
177
+ cmd: Cmd;
178
+ }>['out']>;
179
+ };
180
+ export type ClientOptions = {
181
+ url: string;
182
+ issuer: ISigner;
183
+ audience: DIDURLObject;
184
+ store: Store;
185
+ capabilities: Capability<StandardSchemaV1, string>[];
186
+ };
187
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.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