iso-ucan 0.0.1 → 0.1.6

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.
@@ -30,12 +30,17 @@ export class Capability<Schema extends StandardSchemaV1, Cmd extends string = st
30
30
  */
31
31
  validate(args: StandardSchemaV1.InferInput<Schema>): Promise<StandardSchemaV1.Result<any>>;
32
32
  /**
33
+ * Invoke this capability
34
+ *
33
35
  * @param {import("./types.js").CapabilityInvokeOptions<Schema>} options
36
+ * @returns {Promise<Invocation>}
34
37
  */
35
38
  invoke(options: import("./types.js").CapabilityInvokeOptions<Schema>): Promise<Invocation>;
36
39
  /**
40
+ * Create a delegation for this capability
37
41
  *
38
42
  * @param {import("./types.js").CapabilityDelegateOptions} options
43
+ * @returns {Promise<Delegation>}
39
44
  */
40
45
  delegate(options: import("./types.js").CapabilityDelegateOptions): Promise<Delegation>;
41
46
  }
@@ -1 +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"}
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;;;;;OAKG;IACH,gBAHW,OAAO,YAAY,EAAE,uBAAuB,CAAC,MAAM,CAAC,GAClD,OAAO,CAAC,UAAU,CAAC,CAoB/B;IAED;;;;;OAKG;IACH,kBAHW,OAAO,YAAY,EAAE,yBAAyB,GAC5C,OAAO,CAAC,UAAU,CAAC,CAI/B;CACF;8BAxE+B,MAAM,SAAzB,gBAAkB,EACR,GAAG,SAAb,MAAQ;YAEX,MAAM;SACN,GAAG;;sCARsB,uBAAuB;2BAH/B,iBAAiB;2BADjB,iBAAiB"}
@@ -51,6 +51,28 @@ export class Delegation {
51
51
  */
52
52
  validate(options: DelegationValidateOptions): Promise<boolean>;
53
53
  toString(): string;
54
+ toJSON(): {
55
+ token: string;
56
+ cid: string;
57
+ envelope: {
58
+ payload: {
59
+ iss: string;
60
+ aud: string;
61
+ sub: string | null;
62
+ cmd: string;
63
+ pol: Policy;
64
+ exp: number | null;
65
+ nbf: number | undefined;
66
+ nonce: string;
67
+ meta: Record<string, unknown> | undefined;
68
+ };
69
+ signature: string;
70
+ alg: import("iso-signatures/types").SignatureType;
71
+ enc: import("./types.js").VarsigEncoding;
72
+ spec: "dlg";
73
+ version: string;
74
+ };
75
+ };
54
76
  }
55
77
  import type { DIDURL } from './types.js';
56
78
  import type { DID } from './types.js';
@@ -1 +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"}
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;IACD;;;;;;;;;;;;;;;;;;;;;MAuBC;CACF;4BAxKsG,YAAY;yBAAZ,YAAY;4BAAZ,YAAY;yBAC7F,cAAc;+CADmE,YAAY;uCAAZ,YAAY"}
@@ -1,5 +1,42 @@
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>;
1
+ /**
2
+ * @import { RouteOutput, StandardSchemaV1, RouteOptions, RouteHandlerOptions} from './types'
3
+ * @import {Capability} from './capability'
4
+ */
5
+ /**
6
+ * Workaround to make imports types work
7
+ * @template {Capability<StandardSchemaV1, string>} T
8
+ * @template Output
9
+ * @typedef {Object} DELETE_ME
10
+ * @prop {string} url
11
+ * @prop {Capability<StandardSchemaV1, string>[]} capabilities
12
+ * @prop {RouteOutput<T, Output>} router
13
+ * @prop {RouteOptions<T, Output>} options
14
+ * @prop {RouteHandlerOptions} routerClient
15
+ */
16
+ /**
17
+ * @template Output
18
+ * @template {Capability<StandardSchemaV1>} Cap
19
+ * @param {RouteOptions<Cap, Output>} options
20
+ * @returns {RouteOutput<Cap, Output>}
21
+ */
22
+ export function route<Output, Cap extends Capability<StandardSchemaV1>>(options: RouteOptions<Cap, Output>): RouteOutput<Cap, Output>;
23
+ /**
24
+ * Workaround to make imports types work
25
+ */
26
+ export type DELETE_ME<T extends Capability<StandardSchemaV1, string>, Output> = {
27
+ url: string;
28
+ capabilities: Capability<StandardSchemaV1, string>[];
29
+ router: RouteOutput<T, Output>;
30
+ options: RouteOptions<T, Output>;
31
+ routerClient: RouteHandlerOptions;
32
+ };
33
+ import type { StandardSchemaV1 } from './types';
34
+ import type { Capability } from './capability';
35
+ import type { RouteOptions } from './types';
36
+ import type { RouteOutput } from './types';
37
+ import type { StandardSchemaV1 as StandardSchemaV1_1 } from './types';
38
+ import type { Capability as Capability_1 } from './capability';
39
+ import type { RouteOutput as RouteOutput_1 } from './types';
40
+ import type { RouteOptions as RouteOptions_1 } from './types';
41
+ import type { RouteHandlerOptions } from './types';
5
42
  //# sourceMappingURL=server.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.js"],"names":[],"mappings":"AAIA;;;GAGG;AAEH;;;;;;;;;;GAUG;AAEH;;;;;GAKG;AACH,sBALa,MAAM,EACyB,GAAG,SAAlC,WAAY,gBAAgB,CAAE,WAChC,aAAa,GAAG,EAAE,MAAM,CAAC,GACvB,YAAY,GAAG,EAAE,MAAM,CAAC,CAqBpC;;;;sBAnCmD,CAAC,SAAxC,WAAY,gBAAgB,EAAE,MAAM,CAAE,EACtC,MAAM;SAET,MAAM;kBACN,WAAW,gBAAgB,EAAE,MAAM,CAAC,EAAE;YACtC,YAAY,CAAC,EAAE,MAAM,CAAC;aACtB,aAAa,CAAC,EAAE,MAAM,CAAC;kBACvB,mBAAmB;;sCAbuD,SAAS;gCAChE,cAAc;kCADyC,SAAS;iCAAT,SAAS;4DAAT,SAAS;gDAChE,cAAc;kDADyC,SAAS;oDAAT,SAAS;yCAAT,SAAS"}
@@ -0,0 +1,119 @@
1
+ import type { DID, DIDURL } from 'iso-did/types';
2
+ import type { ISigner } from 'iso-signatures/types';
3
+ import type { CID } from 'multiformats';
4
+ import type { Policy } from './policy';
5
+ import type { VarsigAlgorithm, VarsigEncoding } from './varsig';
6
+ /**
7
+ * Envelope types
8
+ */
9
+ export type PayloadSpec = 'dlg' | 'inv';
10
+ export type PayloadTag = `ucan/${PayloadSpec}@${string}`;
11
+ export interface PayloadBase {
12
+ /**
13
+ * Issuer DID (sender)
14
+ */
15
+ iss: DIDURL;
16
+ /**
17
+ * Audience DID (receiver)
18
+ */
19
+ aud?: DID;
20
+ /**
21
+ * Principal that the chain is about (the [Subject])
22
+ */
23
+ sub?: DID | null;
24
+ /**
25
+ * The Command to eventually invoke
26
+ * @see https://github.com/ucan-wg/spec#command
27
+ */
28
+ cmd: string;
29
+ /**
30
+ * The nonce of the UCAN
31
+ * @see https://github.com/ucan-wg/spec#nonce
32
+ */
33
+ nonce: Uint8Array;
34
+ /**
35
+ * Meta (asserted, signed data) — is not delegated authority
36
+ */
37
+ meta?: Record<string, unknown>;
38
+ /**
39
+ * Expiration UTC Unix Timestamp in seconds (valid until)
40
+ */
41
+ exp: number | null;
42
+ /**
43
+ * "Not before" UTC Unix Timestamp in seconds (valid from)
44
+ */
45
+ nbf?: number;
46
+ }
47
+ /**
48
+ * @see https://github.com/ucan-wg/invocation#invocation-payload
49
+ */
50
+ export interface InvocationPayload extends PayloadBase {
51
+ sub: DID;
52
+ /**
53
+ * Optional if equal to subject
54
+ */
55
+ aud?: DID;
56
+ /**
57
+ * Any [Arguments] that MUST be present in the Invocation
58
+ */
59
+ args: Record<string, unknown>;
60
+ /**
61
+ * Delegations that prove the chain of authority
62
+ */
63
+ prf: CID[];
64
+ /**
65
+ * Issued at time
66
+ */
67
+ iat?: number;
68
+ /**
69
+ * An OPTIONAL CID of the Receipt that enqueued the Task
70
+ */
71
+ cause?: CID;
72
+ }
73
+ export interface DelegationPayload<Args = unknown> extends PayloadBase {
74
+ aud: DID;
75
+ /**
76
+ * Subject can be null here for Powerline
77
+ * @see https://github.com/ucan-wg/delegation/#powerline
78
+ */
79
+ sub: DID | null;
80
+ pol: Policy<Args>;
81
+ }
82
+ export type Payload<Args = unknown> = InvocationPayload | DelegationPayload<Args>;
83
+ export type SignaturePayload<Args = unknown> = {
84
+ h: Uint8Array;
85
+ [payloadTag: PayloadTag]: Payload<Args>;
86
+ };
87
+ export type Envelope<Args = unknown> = [Uint8Array, SignaturePayload<Args>];
88
+ /**
89
+ * @see https://github.com/ucan-wg/spec#envelope
90
+ */
91
+ export type EnvelopeEncodeOptions = {
92
+ signature: Uint8Array;
93
+ signaturePayload: SignaturePayload;
94
+ };
95
+ export interface EnvelopeSignOptions {
96
+ /**
97
+ * @default '1.0.0'
98
+ */
99
+ version?: string;
100
+ /**
101
+ * @default 'DAG-CBOR'
102
+ */
103
+ enc?: VarsigEncoding;
104
+ spec: PayloadSpec;
105
+ payload: Payload;
106
+ signer: ISigner;
107
+ }
108
+ export interface EnvelopeDecodeOptions {
109
+ envelope: Uint8Array;
110
+ }
111
+ export type DecodedEnvelope<Spec extends PayloadSpec> = {
112
+ alg: VarsigAlgorithm;
113
+ enc: VarsigEncoding;
114
+ signature: Uint8Array;
115
+ payload: Spec extends 'dlg' ? DelegationPayload : InvocationPayload;
116
+ spec: Spec;
117
+ version: string;
118
+ };
119
+ //# sourceMappingURL=envelope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../../src/types/envelope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAE/D;;GAEG;AAEH,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,KAAK,CAAA;AACvC,MAAM,MAAM,UAAU,GAAG,QAAQ,WAAW,IAAI,MAAM,EAAE,CAAA;AACxD,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;OAEG;IACH,GAAG,CAAC,EAAE,GAAG,CAAA;IACT;;OAEG;IACH,GAAG,CAAC,EAAE,GAAG,GAAG,IAAI,CAAA;IAChB;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;;OAGG;IACH,KAAK,EAAE,UAAU,CAAA;IACjB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B;;OAEG;IACH,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;IAClB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED;;GAEG;AACH,MAAM,WAA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O,CAAA;CAChB;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,UAAU,CAAA;CACrB;AAED,MAAM,MAAM,eAAe,CAAC,IAAI,SAAS,WAAW,IAAI;IACtD,GAAG,EAAE,eAAe,CAAA;IACpB,GAAG,EAAE,cAAc,CAAA;IACnB,SAAS,EAAE,UAAU,CAAA;IACrB,OAAO,EAAE,IAAI,SAAS,KAAK,GAAG,iBAAiB,GAAG,iBAAiB,CAAA;IACnE,IAAI,EAAE,IAAI,CAAA;IACV,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Policy types
3
+ * @see https://github.com/ucan-wg/delegation/#policy
4
+ */
5
+ /**
6
+ * Type-safe selector utilities
7
+ */
8
+ /**
9
+ * Extracts all possible paths from a data structure as string literals
10
+ */
11
+ type PathsToStringProps<T> = T extends string | number | boolean | null | undefined ? never : T extends Array<infer U> ? `[]` | `[${number}]` | `[${number}:${number}]` | `[${number}:]` | `[:${number}]` | `[:]` | PathsToStringProps<U> : T extends object ? {
12
+ [K in keyof T & (string | number)]: K extends string ? `.${K}` | `.${K}?` | `.${K}${PathsToStringProps<T[K]>}` : `[${K}]` | `[${K}]?` | `[${K}]${PathsToStringProps<T[K]>}`;
13
+ }[keyof T & (string | number)] : never;
14
+ /**
15
+ * Flattens nested path strings into a union of all possible selectors
16
+ */
17
+ type FlattenPaths<T> = T extends string ? T : T extends object ? {
18
+ [K in keyof T]: T[K] extends string ? T[K] : T[K] extends object ? FlattenPaths<T[K]> : never;
19
+ }[keyof T] : never;
20
+ /**
21
+ * Type-safe selector that only allows valid paths for the given data structure
22
+ */
23
+ export type Selector<Args = unknown> = Args extends unknown ? FlattenPaths<PathsToStringProps<Args>> | '.' : string;
24
+ /**
25
+ * Extracts the type of the value at a given selector path (minimal version)
26
+ */
27
+ type SelectorValue<T, S extends string> = S extends `.${infer K}` ? K extends keyof T ? T[K] : never : S extends `[${infer I}]` ? T extends Array<infer U> ? U : never : never;
28
+ /** Connectives */
29
+ export type EqualityOp = '==' | '!=';
30
+ export type Equality<Args = unknown> = [EqualityOp, Selector<Args>, unknown];
31
+ export type InequalityOp = '<' | '<=' | '>' | '>=';
32
+ export type Inequality<Args = unknown> = [InequalityOp, Selector<Args>, number];
33
+ export type NegateOp = 'not';
34
+ export type Negate<Args = unknown> = [NegateOp, Statement<Args>];
35
+ export type ConnectiveOp = 'and' | 'or';
36
+ export type Connective<Args = unknown> = [ConnectiveOp, Statement<Args>[]];
37
+ export type QuantifierOp = 'all' | 'any';
38
+ export type Quantifier<Args = unknown, Sel extends Selector<Args> = Selector<Args>> = [QuantifierOp, Sel, Statement<SelectorValue<Args, Sel>>];
39
+ export type LikeOp = 'like';
40
+ export type Like<Args = unknown> = [LikeOp, Selector<Args>, string];
41
+ export type Statement<Args = unknown> = Equality<Args> | Inequality<Args> | Negate<Args> | Connective<Args> | Quantifier<Args> | Like<Args>;
42
+ export type Policy<Args = unknown> = Statement<Args>[];
43
+ export {};
44
+ //# sourceMappingURL=policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../../src/types/policy.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AAEH;;GAEG;AACH,KAAK,kBAAkB,CAAC,CAAC,IAAI,CAAC,SAC1B,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,GACT,KAAK,GACL,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GAElB,IAAI,GACJ,IAAI,MAAM,GAAG,GACb,IAAI,MAAM,IAAI,MAAM,GAAG,GACvB,IAAI,MAAM,IAAI,GACd,KAAK,MAAM,GAAG,GACd,KAAK,GACL,kBAAkB,CAAC,CAAC,CAAC,GACzB,CAAC,SAAS,MAAM,GACd;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,MAAM,GACh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GACZ,UAAU,CAAC,IAAI,CAAC,GAChB,UAAU,CAAC,IAAI,CAAC,GAChB,IAAI,CAAC,IAAI,CAAC,CAAA;AAEd,MAAM,MAAM,MAAM,CAAC,IAAI,GAAG,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE,CAAA"}
@@ -0,0 +1,18 @@
1
+ import type { SignatureType } from 'iso-signatures/types';
2
+ /**
3
+ * Varsig types
4
+ */
5
+ /**
6
+ * Supported encoding types for data to be signed or verified
7
+ */
8
+ export type VarsigEncoding = 'RAW' | 'DAG-CBOR';
9
+ /**
10
+ * Supported signature types
11
+ */
12
+ export type VarsigAlgorithm = SignatureType;
13
+ export interface VarsigOptions {
14
+ enc: VarsigEncoding;
15
+ alg: VarsigAlgorithm;
16
+ }
17
+ export type DecodeOutput = VarsigOptions;
18
+ //# sourceMappingURL=varsig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"varsig.d.ts","sourceRoot":"","sources":["../../../src/types/varsig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEzD;;GAEG;AAEH;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,UAAU,CAAA;AAE/C;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,aAAa,CAAA;AAE3C,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,cAAc,CAAA;IACnB,GAAG,EAAE,eAAe,CAAA;CACrB;AAED,MAAM,MAAM,YAAY,GAAG,aAAa,CAAA"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "iso-ucan",
3
3
  "type": "module",
4
- "version": "0.0.1",
4
+ "version": "0.1.6",
5
5
  "description": "Isomorphic UCAN",
6
6
  "author": "Hugo Dias <hugomrdias@gmail.com> (hugodias.me)",
7
7
  "license": "MIT",
@@ -98,8 +98,8 @@
98
98
  },
99
99
  "files": [
100
100
  "src",
101
- "dist/src/*.d.ts",
102
- "dist/src/*.d.ts.map"
101
+ "dist/src/**/*.d.ts",
102
+ "dist/src/**/*.d.ts.map"
103
103
  ],
104
104
  "dependencies": {
105
105
  "@ipld/dag-cbor": "^9.2.4",
@@ -110,9 +110,9 @@
110
110
  "iso-web": "^1.1.1",
111
111
  "it-merge": "^3.0.12",
112
112
  "multiformats": "^13.3.7",
113
- "iso-base": "^4.0.2",
114
- "iso-did": "^1.8.0",
115
- "iso-signatures": "^0.3.2"
113
+ "iso-did": "^2.0.0",
114
+ "iso-signatures": "^0.4.0",
115
+ "iso-base": "^4.1.0"
116
116
  },
117
117
  "devDependencies": {
118
118
  "@types/node": "^24.1.0",
package/src/capability.js CHANGED
@@ -45,7 +45,10 @@ export class Capability {
45
45
  }
46
46
 
47
47
  /**
48
+ * Invoke this capability
49
+ *
48
50
  * @param {import("./types.js").CapabilityInvokeOptions<Schema>} options
51
+ * @returns {Promise<Invocation>}
49
52
  */
50
53
  async invoke(options) {
51
54
  const result = await this.schema['~standard'].validate(options.args)
@@ -68,8 +71,10 @@ export class Capability {
68
71
  }
69
72
 
70
73
  /**
74
+ * Create a delegation for this capability
71
75
  *
72
76
  * @param {import("./types.js").CapabilityDelegateOptions} options
77
+ * @returns {Promise<Delegation>}
73
78
  */
74
79
  delegate(options) {
75
80
  return Delegation.create({ ...options, cmd: this.cmd })
package/src/delegation.js CHANGED
@@ -159,6 +159,30 @@ export class Delegation {
159
159
  toString() {
160
160
  return base64pad.encode(this.bytes)
161
161
  }
162
+ toJSON() {
163
+ return {
164
+ token: this.toString(),
165
+ cid: this.cid.toString(),
166
+ envelope: {
167
+ payload: {
168
+ iss: this.iss.toString(),
169
+ aud: this.aud.toString(),
170
+ sub: this.sub ? this.sub.toString() : null,
171
+ cmd: this.cmd,
172
+ pol: this.pol,
173
+ exp: this.exp,
174
+ nbf: this.nbf,
175
+ nonce: base64pad.encode(this.nonce),
176
+ meta: this.meta,
177
+ },
178
+ signature: base64pad.encode(this.envelope.signature),
179
+ alg: this.envelope.alg,
180
+ enc: this.envelope.enc,
181
+ spec: this.envelope.spec,
182
+ version: this.envelope.version,
183
+ },
184
+ }
185
+ }
162
186
  }
163
187
 
164
188
  /**
package/src/server.js ADDED
@@ -0,0 +1,47 @@
1
+ // import type { StandardSchemaV1 } from '@standard-schema/spec'
2
+ // import type { Capability } from './capability.js'
3
+ // import type { RouteHandlerOptions, RouteOptions, RouteOutput } from './types.js'
4
+
5
+ /**
6
+ * @import { RouteOutput, StandardSchemaV1, RouteOptions, RouteHandlerOptions} from './types'
7
+ * @import {Capability} from './capability'
8
+ */
9
+
10
+ /**
11
+ * Workaround to make imports types work
12
+ * @template {Capability<StandardSchemaV1, string>} T
13
+ * @template Output
14
+ * @typedef {Object} DELETE_ME
15
+ * @prop {string} url
16
+ * @prop {Capability<StandardSchemaV1, string>[]} capabilities
17
+ * @prop {RouteOutput<T, Output>} router
18
+ * @prop {RouteOptions<T, Output>} options
19
+ * @prop {RouteHandlerOptions} routerClient
20
+ */
21
+
22
+ /**
23
+ * @template Output
24
+ * @template {Capability<StandardSchemaV1>} Cap
25
+ * @param {RouteOptions<Cap, Output>} options
26
+ * @returns {RouteOutput<Cap, Output>}
27
+ */
28
+ export function route(options) {
29
+ return {
30
+ cap: options.capability,
31
+ fn: async (
32
+ /** @type {RouteHandlerOptions} */ { request, issuer, invocation, store }
33
+ ) => {
34
+ const { capability, handler } = options
35
+
36
+ const args = await capability.validate(invocation.payload.args)
37
+ if (args.issues) {
38
+ throw new Error(args.issues.map((issue) => issue.message).join(', '))
39
+ }
40
+
41
+ // TODO: handle failure
42
+ const result = await handler({ args: args.value, store })
43
+
44
+ return result
45
+ },
46
+ }
47
+ }
package/src/server.ts DELETED
@@ -1,24 +0,0 @@
1
- import type { StandardSchemaV1 } from '@standard-schema/spec'
2
- import type { Capability } from './capability.js'
3
- import type { RouteHandlerOptions, RouteOptions, RouteOutput } from './types.js'
4
-
5
- export function route<Cap extends Capability<StandardSchemaV1>, Output>(
6
- options: RouteOptions<Cap, Output>
7
- ): RouteOutput<Cap, Output> {
8
- return {
9
- cap: options.capability,
10
- fn: async ({ request, issuer, invocation, store }: RouteHandlerOptions) => {
11
- const { capability, handler } = options
12
-
13
- const args = await capability.validate(invocation.payload.args)
14
- if (args.issues) {
15
- throw new Error(args.issues.map((issue) => issue.message).join(', '))
16
- }
17
-
18
- // TODO: handle failure
19
- const result = await handler({ args: args.value, store })
20
-
21
- return result
22
- },
23
- }
24
- }