@interop/zcap 9.0.3
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.
- package/LICENSE +27 -0
- package/README.md +65 -0
- package/lib/CapabilityDelegation.js +312 -0
- package/lib/CapabilityInvocation.js +343 -0
- package/lib/CapabilityProofPurpose.js +538 -0
- package/lib/constants.js +32 -0
- package/lib/index.js +60 -0
- package/lib/utils.js +674 -0
- package/lib/zcap-types.d.ts +72 -0
- package/package.json +81 -0
- package/types/lib/CapabilityDelegation.d.ts +101 -0
- package/types/lib/CapabilityDelegation.d.ts.map +1 -0
- package/types/lib/CapabilityInvocation.d.ts +100 -0
- package/types/lib/CapabilityInvocation.d.ts.map +1 -0
- package/types/lib/CapabilityProofPurpose.d.ts +126 -0
- package/types/lib/CapabilityProofPurpose.d.ts.map +1 -0
- package/types/lib/constants.d.ts +15 -0
- package/types/lib/constants.d.ts.map +1 -0
- package/types/lib/index.d.ts +50 -0
- package/types/lib/index.d.ts.map +1 -0
- package/types/lib/utils.d.ts +312 -0
- package/types/lib/utils.d.ts.map +1 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2018-2026 Digital Bazaar, Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Hand-authored object shapes for zcaps. These live in a `.d.ts` (rather than
|
|
6
|
+
// as JSDoc `@typedef`s in `utils.js`) because TypeScript's JSDoc parser cannot
|
|
7
|
+
// express a property named `@context` -- the leading `@` is mangled to an
|
|
8
|
+
// empty-string key (`""`). `utils.js` re-exports these via `@typedef
|
|
9
|
+
// {import('./zcap-types.js').X} X` so the public type names are unchanged.
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A root authorization capability (zcap). Root zcaps are unsigned, have no
|
|
13
|
+
* `expires` field and no delegation proof.
|
|
14
|
+
*/
|
|
15
|
+
export interface RootZcap {
|
|
16
|
+
/** The zcap JSON-LD context URL. */
|
|
17
|
+
'@context': string;
|
|
18
|
+
/** Capability ID (`urn:zcap:root:<encodedTarget>`). */
|
|
19
|
+
id: string;
|
|
20
|
+
/** The DID(s) authorized to invoke. */
|
|
21
|
+
controller: string | string[];
|
|
22
|
+
/** Resource URI this capability grants access to (absolute URI). */
|
|
23
|
+
invocationTarget: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** A proof attached to a delegated capability. */
|
|
27
|
+
export interface CapabilityDelegationProof {
|
|
28
|
+
/** The cryptographic suite type (e.g. `'Ed25519Signature2020'`). */
|
|
29
|
+
type: string;
|
|
30
|
+
/** ISO 8601 date-time the proof was created. */
|
|
31
|
+
created: string;
|
|
32
|
+
/** Verification method URI used to sign. */
|
|
33
|
+
verificationMethod: string;
|
|
34
|
+
/** Always `'capabilityDelegation'`. */
|
|
35
|
+
proofPurpose: 'capabilityDelegation';
|
|
36
|
+
/**
|
|
37
|
+
* Ordered capability chain (root > parent). All entries are string IDs
|
|
38
|
+
* except the last delegated zcap, which is embedded as an object.
|
|
39
|
+
*/
|
|
40
|
+
capabilityChain: (string | DelegatedZcap)[];
|
|
41
|
+
/** The encoded proof value. */
|
|
42
|
+
proofValue: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* A delegated authorization capability (zcap). Delegated capabilities narrow
|
|
47
|
+
* a parent capability and must carry exactly one `capabilityDelegation` proof.
|
|
48
|
+
*/
|
|
49
|
+
export interface DelegatedZcap {
|
|
50
|
+
/** JSON-LD context array; first entry MUST be the zcap context URL. */
|
|
51
|
+
'@context': string[];
|
|
52
|
+
/** Capability ID (absolute URI). */
|
|
53
|
+
id: string;
|
|
54
|
+
/** Parent capability ID (absolute URI). */
|
|
55
|
+
parentCapability: string;
|
|
56
|
+
/** The DID(s) authorized to invoke. */
|
|
57
|
+
controller: string | string[];
|
|
58
|
+
/** Resource URI this capability grants access to (absolute URI). */
|
|
59
|
+
invocationTarget: string;
|
|
60
|
+
/**
|
|
61
|
+
* The action(s) the controller may perform; if absent, no actions are
|
|
62
|
+
* allowed (except for the root zcap).
|
|
63
|
+
*/
|
|
64
|
+
allowedAction?: string | string[];
|
|
65
|
+
/** ISO 8601 date-time when this capability expires. */
|
|
66
|
+
expires: string;
|
|
67
|
+
/** The capability delegation proof(s). */
|
|
68
|
+
proof: CapabilityDelegationProof | CapabilityDelegationProof[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** A zcap is either a root or a delegated capability. */
|
|
72
|
+
export type Zcap = RootZcap | DelegatedZcap;
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@interop/zcap",
|
|
3
|
+
"version": "9.0.3",
|
|
4
|
+
"description": "Authorization Capabilities reference implementation.",
|
|
5
|
+
"homepage": "https://github.com/interop-alliance/zcap",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Digital Bazaar, Inc.",
|
|
8
|
+
"email": "support@digitalbazaar.com",
|
|
9
|
+
"url": "https://digitalbazaar.com/"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/interop-alliance/zcap"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/interop-alliance/zcap/issues/"
|
|
17
|
+
},
|
|
18
|
+
"license": "BSD-3-Clause",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./types/lib/index.d.ts",
|
|
23
|
+
"default": "./lib/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"types": "./types/lib/index.d.ts",
|
|
27
|
+
"files": [
|
|
28
|
+
"lib/**/*.js",
|
|
29
|
+
"lib/**/*.d.ts",
|
|
30
|
+
"types/**/*.d.ts",
|
|
31
|
+
"types/**/*.d.ts.map"
|
|
32
|
+
],
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@digitalbazaar/zcap-context": "^2.0.1",
|
|
35
|
+
"@interop/jsonld-signatures": "^11.6.1"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@digitalbazaar/ed25519-signature-2020": "^5.4.0",
|
|
39
|
+
"@digitalcredentials/ed25519-verification-key-2020": "^5.0.0",
|
|
40
|
+
"chai": "^4.3.6",
|
|
41
|
+
"cross-env": "^7.0.3",
|
|
42
|
+
"eslint": "^8.17.0",
|
|
43
|
+
"eslint-config-digitalbazaar": "^5.0.1",
|
|
44
|
+
"eslint-plugin-jsdoc": "^48.2.2",
|
|
45
|
+
"eslint-plugin-unicorn": "^51.0.1",
|
|
46
|
+
"karma": "^6.3.20",
|
|
47
|
+
"karma-chrome-launcher": "^3.1.1",
|
|
48
|
+
"karma-mocha": "^2.0.1",
|
|
49
|
+
"karma-mocha-reporter": "^2.2.5",
|
|
50
|
+
"karma-sourcemap-loader": "^0.4.0",
|
|
51
|
+
"karma-webpack": "^5.0.0",
|
|
52
|
+
"mocha": "^10.0.0",
|
|
53
|
+
"typescript": "^6.0.3",
|
|
54
|
+
"webpack": "^5.73.0"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"test": "npm run test-node",
|
|
58
|
+
"__test-node": "cross-env NODE_ENV=test mocha --delay -t 30000 -A -R ${REPORTER:-spec} tests/test.js",
|
|
59
|
+
"test-node": "cross-env NODE_ENV=test mocha -t 30000 -A -R ${REPORTER:-spec} tests/test.js",
|
|
60
|
+
"test-karma": "cross-env NODE_ENV=test karma start karma.conf.cjs",
|
|
61
|
+
"build:types": "tsc",
|
|
62
|
+
"lint": "eslint ."
|
|
63
|
+
},
|
|
64
|
+
"engines": {
|
|
65
|
+
"node": ">=18"
|
|
66
|
+
},
|
|
67
|
+
"keywords": [
|
|
68
|
+
"Authorization Capability",
|
|
69
|
+
"Authorization Capabilities",
|
|
70
|
+
"JSON",
|
|
71
|
+
"JSON-LD",
|
|
72
|
+
"Linked Data",
|
|
73
|
+
"OCAP",
|
|
74
|
+
"OCAP-LD",
|
|
75
|
+
"Semantic Web",
|
|
76
|
+
"ZCAP",
|
|
77
|
+
"ZCAP-LD",
|
|
78
|
+
"digital signatures",
|
|
79
|
+
"object capabilities"
|
|
80
|
+
]
|
|
81
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('./utils.js').InspectCapabilityChain} InspectCapabilityChain
|
|
3
|
+
* @typedef {import('./utils.js').Zcap} Zcap
|
|
4
|
+
* @typedef {import('./utils.js').DelegatedZcap} DelegatedZcap
|
|
5
|
+
*/
|
|
6
|
+
export class CapabilityDelegation extends CapabilityProofPurpose {
|
|
7
|
+
/**
|
|
8
|
+
* @param {object} options - The options.
|
|
9
|
+
* @param {string|Zcap} [options.parentCapability] - An alternative to
|
|
10
|
+
* passing `capabilityChain` when creating a proof; passing
|
|
11
|
+
* `parentCapability` will enable the capability chain to be auto-computed.
|
|
12
|
+
* Pass a root zcap ID string, or a full root or delegated zcap object.
|
|
13
|
+
* @param {boolean} [options.allowTargetAttenuation=false] - Allow the
|
|
14
|
+
* invocationTarget of a delegation chain to be increasingly restrictive
|
|
15
|
+
* based on a hierarchical RESTful URL structure.
|
|
16
|
+
* @param {string|Date|number} [options.date] - Used during proof
|
|
17
|
+
* verification as the expected date for the creation of the proof
|
|
18
|
+
* (within a maximum timestamp delta) and for checking to see if a
|
|
19
|
+
* capability has expired; if not passed the current date will be used.
|
|
20
|
+
* @param {string|string[]} [options.expectedRootCapability] - The expected
|
|
21
|
+
* root capability for the delegation chain (a single root capability ID
|
|
22
|
+
* string, or an array of acceptable root capability ID strings).
|
|
23
|
+
* @param {object} [options.controller] - The description of the controller,
|
|
24
|
+
* if it is not to be dereferenced via a `documentLoader`.
|
|
25
|
+
* @param {InspectCapabilityChain} [options.inspectCapabilityChain] - An
|
|
26
|
+
* async function that can be used to check for revocations related to any
|
|
27
|
+
* of verified capabilities.
|
|
28
|
+
* @param {number} [options.maxChainLength=10] - The maximum length of the
|
|
29
|
+
* capability delegation chain.
|
|
30
|
+
* @param {number} [options.maxClockSkew=300] - A maximum number of seconds
|
|
31
|
+
* that clocks may be skewed when checking capability expiration date-times
|
|
32
|
+
* against `date`.
|
|
33
|
+
* @param {number} [options.maxDelegationTtl=Infinity] - The maximum
|
|
34
|
+
* milliseconds to live for a delegated zcap as measured by the time
|
|
35
|
+
* difference between `expires` and `created` on the delegation proof.
|
|
36
|
+
* @param {object|object[]} [options.suite] - The jsonld-signature suite(s) to
|
|
37
|
+
* use to verify the capability chain. Required only in verify-proof mode;
|
|
38
|
+
* unused (and omitted) when creating a delegation proof.
|
|
39
|
+
* @param {Zcap} [options._verifiedParentCapability] - Private.
|
|
40
|
+
* @param {Array<string|DelegatedZcap>} [options._capabilityChain] - Private.
|
|
41
|
+
* @param {boolean} [options._skipLocalValidationForTesting] - Private.
|
|
42
|
+
*/
|
|
43
|
+
constructor({ parentCapability, allowTargetAttenuation, controller, date, expectedRootCapability, inspectCapabilityChain, maxChainLength, maxClockSkew, maxDelegationTtl, suite, _verifiedParentCapability, _capabilityChain, _skipLocalValidationForTesting }?: {
|
|
44
|
+
parentCapability?: string | Zcap;
|
|
45
|
+
allowTargetAttenuation?: boolean;
|
|
46
|
+
date?: string | Date | number;
|
|
47
|
+
expectedRootCapability?: string | string[];
|
|
48
|
+
controller?: object;
|
|
49
|
+
inspectCapabilityChain?: InspectCapabilityChain;
|
|
50
|
+
maxChainLength?: number;
|
|
51
|
+
maxClockSkew?: number;
|
|
52
|
+
maxDelegationTtl?: number;
|
|
53
|
+
suite?: object | object[];
|
|
54
|
+
_verifiedParentCapability?: Zcap;
|
|
55
|
+
_capabilityChain?: Array<string | DelegatedZcap>;
|
|
56
|
+
_skipLocalValidationForTesting?: boolean;
|
|
57
|
+
});
|
|
58
|
+
parentCapability: string | import("./zcap-types.js").Zcap;
|
|
59
|
+
_capabilityChain: (string | import("./zcap-types.js").DelegatedZcap)[];
|
|
60
|
+
_skipLocalValidationForTesting: boolean;
|
|
61
|
+
_verifiedParentCapability: import("./zcap-types.js").Zcap;
|
|
62
|
+
update(proof: any, { document }: {
|
|
63
|
+
document: any;
|
|
64
|
+
}): Promise<any>;
|
|
65
|
+
match(proof: any, { document, documentLoader }: {
|
|
66
|
+
document: any;
|
|
67
|
+
documentLoader: any;
|
|
68
|
+
}): Promise<boolean>;
|
|
69
|
+
_getCapabilityDelegationClass(): typeof CapabilityDelegation;
|
|
70
|
+
_getTailCapability({ document, proof }: {
|
|
71
|
+
document: any;
|
|
72
|
+
proof: any;
|
|
73
|
+
}): {
|
|
74
|
+
capability: any;
|
|
75
|
+
};
|
|
76
|
+
_runChecksBeforeChainVerification(): Promise<{
|
|
77
|
+
capabilityChainMeta: {
|
|
78
|
+
verifyResult: {};
|
|
79
|
+
}[];
|
|
80
|
+
}>;
|
|
81
|
+
_runChecksAfterChainVerification({ capabilityChainMeta, dereferencedChain, proof, validateOptions }: {
|
|
82
|
+
capabilityChainMeta: any;
|
|
83
|
+
dereferencedChain: any;
|
|
84
|
+
proof: any;
|
|
85
|
+
validateOptions: any;
|
|
86
|
+
}): Promise<import("@interop/jsonld-signatures").ProofValidateResult>;
|
|
87
|
+
_shortCircuitValidate({ proof, validateOptions }: {
|
|
88
|
+
proof: any;
|
|
89
|
+
validateOptions: any;
|
|
90
|
+
}): Promise<import("@interop/jsonld-signatures").ProofValidateResult>;
|
|
91
|
+
_validateAgainstParent({ proof, verifiedParentCapability, validateOptions }: {
|
|
92
|
+
proof: any;
|
|
93
|
+
verifiedParentCapability: any;
|
|
94
|
+
validateOptions: any;
|
|
95
|
+
}): Promise<import("@interop/jsonld-signatures").ProofValidateResult>;
|
|
96
|
+
}
|
|
97
|
+
export type InspectCapabilityChain = import("./utils.js").InspectCapabilityChain;
|
|
98
|
+
export type Zcap = import("./utils.js").Zcap;
|
|
99
|
+
export type DelegatedZcap = import("./utils.js").DelegatedZcap;
|
|
100
|
+
import { CapabilityProofPurpose } from './CapabilityProofPurpose.js';
|
|
101
|
+
//# sourceMappingURL=CapabilityDelegation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CapabilityDelegation.d.ts","sourceRoot":"","sources":["../../lib/CapabilityDelegation.js"],"names":[],"mappings":"AAMA;;;;GAIG;AAEH;IACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACH,iQAlCG;QAA8B,gBAAgB,GAAtC,MAAM,GAAC,IAAI;QAIO,sBAAsB,GAAxC,OAAO;QAGsB,IAAI,GAAjC,MAAM,GAAC,IAAI,GAAC,MAAM;QAIQ,sBAAsB,GAAhD,MAAM,GAAC,MAAM,EAAE;QAGE,UAAU,GAA3B,MAAM;QAE2B,sBAAsB,GAAvD,sBAAsB;QAGL,cAAc,GAA/B,MAAM;QAEW,YAAY,GAA7B,MAAM;QAGW,gBAAgB,GAAjC,MAAM;QAGoB,KAAK,GAA/B,MAAM,GAAC,MAAM,EAAE;QAGA,yBAAyB,GAAxC,IAAI;QACkC,gBAAgB,GAAtD,KAAK,CAAC,MAAM,GAAC,aAAa,CAAC;QACT,8BAA8B,GAAhD,OAAO;KACjB,EA0EA;IAbG,0DAAwC;IAKtC,uEAAwC;IAGxC,wCAAoE;IAGtE,0DAA0D;IAI9D;;qBAiFC;IAED;;;yBAUC;IAED,6DAEC;IAED;;;;;MAIC;IAED;;;;OAOC;IAED;;;;;0EAsBC;IAED;;;0EAgBC;IAED;;;;0EA8BC;CACF;qCAhTY,OAAO,YAAY,EAAE,sBAAsB;mBAC3C,OAAO,YAAY,EAAE,IAAI;4BACzB,OAAO,YAAY,EAAE,aAAa;uCALV,6BAA6B"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('./utils.js').InspectCapabilityChain} InspectCapabilityChain
|
|
3
|
+
* @typedef {import('./utils.js').DelegatedZcap} DelegatedZcap
|
|
4
|
+
*/
|
|
5
|
+
export class CapabilityInvocation extends CapabilityProofPurpose {
|
|
6
|
+
/**
|
|
7
|
+
* @param {object} options - The options.
|
|
8
|
+
* @param {string|DelegatedZcap} [options.capability] - The capability to
|
|
9
|
+
* add/reference in a created proof. A root zcap MUST be passed as its ID
|
|
10
|
+
* string; a delegated zcap must be passed as the full object.
|
|
11
|
+
* @param {string} [options.capabilityAction] - The capability action that is
|
|
12
|
+
* to be added to a proof.
|
|
13
|
+
* @param {string} [options.invocationTarget] - The invocation target to
|
|
14
|
+
* use; this is required and can be used to attenuate the capability's
|
|
15
|
+
* invocation target if the verifier supports target attenuation.
|
|
16
|
+
* @param {boolean} [options.allowTargetAttenuation=false] - Allow the
|
|
17
|
+
* invocationTarget of a delegation chain to be increasingly restrictive
|
|
18
|
+
* based on a hierarchical RESTful URL structure.
|
|
19
|
+
* @param {object} [options.controller] - The description of the controller,
|
|
20
|
+
* if it is not to be dereferenced via a `documentLoader`.
|
|
21
|
+
* @param {string|Date|number} [options.date] - Used during proof
|
|
22
|
+
* verification as the expected date for the creation of the proof
|
|
23
|
+
* (within a maximum timestamp delta) and for checking to see if a
|
|
24
|
+
* capability has expired; if not passed the current date will be used.
|
|
25
|
+
* @param {string} [options.expectedAction] - The capability action that is
|
|
26
|
+
* expected when validating a proof.
|
|
27
|
+
* @param {string|string[]} [options.expectedRootCapability] - The expected
|
|
28
|
+
* root capability for the delegation chain (a single root capability ID
|
|
29
|
+
* string, or an array of acceptable root capability ID strings).
|
|
30
|
+
* @param {string|string[]} [options.expectedTarget] - The target(s) we
|
|
31
|
+
* expect a capability to apply to (absolute URI, or array of URIs).
|
|
32
|
+
* @param {InspectCapabilityChain} [options.inspectCapabilityChain] - An
|
|
33
|
+
* async function that can be used to check for revocations related to any
|
|
34
|
+
* of verified capabilities.
|
|
35
|
+
* @param {number} [options.maxChainLength=10] - The maximum length of the
|
|
36
|
+
* capability delegation chain.
|
|
37
|
+
* @param {number} [options.maxClockSkew=300] - A maximum number of seconds
|
|
38
|
+
* that clocks may be skewed when checking capability expiration date-times
|
|
39
|
+
* against `date` and when comparing invocation proof creation time against
|
|
40
|
+
* delegation proof creation time.
|
|
41
|
+
* @param {number} [options.maxDelegationTtl=Infinity] - The maximum
|
|
42
|
+
* milliseconds to live for a delegated zcap as measured by the time
|
|
43
|
+
* difference between `expires` and `created` on the delegation proof.
|
|
44
|
+
* @param {number} [options.maxTimestampDelta=Infinity] - A maximum number
|
|
45
|
+
* of seconds that "created" date on the capability invocation proof can
|
|
46
|
+
* deviate from `date`, defaults to `Infinity`.
|
|
47
|
+
* @param {object|object[]} [options.suite] - The jsonld-signature suite(s) to
|
|
48
|
+
* use to verify the capability chain. Required only in verify-proof mode;
|
|
49
|
+
* unused (and omitted) when creating an invocation proof.
|
|
50
|
+
*/
|
|
51
|
+
constructor({ capability, capabilityAction, invocationTarget, allowTargetAttenuation, controller, date, expectedAction, expectedRootCapability, expectedTarget, inspectCapabilityChain, maxChainLength, maxClockSkew, maxDelegationTtl, maxTimestampDelta, suite }?: {
|
|
52
|
+
capability?: string | DelegatedZcap;
|
|
53
|
+
capabilityAction?: string;
|
|
54
|
+
invocationTarget?: string;
|
|
55
|
+
allowTargetAttenuation?: boolean;
|
|
56
|
+
controller?: object;
|
|
57
|
+
date?: string | Date | number;
|
|
58
|
+
expectedAction?: string;
|
|
59
|
+
expectedRootCapability?: string | string[];
|
|
60
|
+
expectedTarget?: string | string[];
|
|
61
|
+
inspectCapabilityChain?: InspectCapabilityChain;
|
|
62
|
+
maxChainLength?: number;
|
|
63
|
+
maxClockSkew?: number;
|
|
64
|
+
maxDelegationTtl?: number;
|
|
65
|
+
maxTimestampDelta?: number;
|
|
66
|
+
suite?: object | object[];
|
|
67
|
+
});
|
|
68
|
+
capability: string | import("./zcap-types.js").DelegatedZcap;
|
|
69
|
+
capabilityAction: string;
|
|
70
|
+
invocationTarget: string;
|
|
71
|
+
expectedTarget: string | string[];
|
|
72
|
+
expectedAction: string;
|
|
73
|
+
update(proof: any): Promise<any>;
|
|
74
|
+
match(proof: any, { document, documentLoader }: {
|
|
75
|
+
document: any;
|
|
76
|
+
documentLoader: any;
|
|
77
|
+
}): Promise<boolean>;
|
|
78
|
+
_getCapabilityDelegationClass(): typeof CapabilityDelegation;
|
|
79
|
+
_getTailCapability({ proof }: {
|
|
80
|
+
proof: any;
|
|
81
|
+
}): {
|
|
82
|
+
capability: any;
|
|
83
|
+
};
|
|
84
|
+
_runChecksBeforeChainVerification({ dereferencedChain, proof }: {
|
|
85
|
+
dereferencedChain: any;
|
|
86
|
+
proof: any;
|
|
87
|
+
}): Promise<{
|
|
88
|
+
capabilityChainMeta: any[];
|
|
89
|
+
}>;
|
|
90
|
+
_runChecksAfterChainVerification({ dereferencedChain, proof, validateOptions }: {
|
|
91
|
+
dereferencedChain: any;
|
|
92
|
+
proof: any;
|
|
93
|
+
validateOptions: any;
|
|
94
|
+
}): Promise<import("@interop/jsonld-signatures").ProofValidateResult>;
|
|
95
|
+
}
|
|
96
|
+
export type InspectCapabilityChain = import("./utils.js").InspectCapabilityChain;
|
|
97
|
+
export type DelegatedZcap = import("./utils.js").DelegatedZcap;
|
|
98
|
+
import { CapabilityProofPurpose } from './CapabilityProofPurpose.js';
|
|
99
|
+
import { CapabilityDelegation } from './CapabilityDelegation.js';
|
|
100
|
+
//# sourceMappingURL=CapabilityInvocation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CapabilityInvocation.d.ts","sourceRoot":"","sources":["../../lib/CapabilityInvocation.js"],"names":[],"mappings":"AAOA;;;GAGG;AAEH;IACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4CG;IACH,qQA3CG;QAAuC,UAAU,GAAzC,MAAM,GAAC,aAAa;QAGH,gBAAgB,GAAjC,MAAM;QAEW,gBAAgB,GAAjC,MAAM;QAGY,sBAAsB,GAAxC,OAAO;QAGU,UAAU,GAA3B,MAAM;QAEuB,IAAI,GAAjC,MAAM,GAAC,IAAI,GAAC,MAAM;QAID,cAAc,GAA/B,MAAM;QAEoB,sBAAsB,GAAhD,MAAM,GAAC,MAAM,EAAE;QAGW,cAAc,GAAxC,MAAM,GAAC,MAAM,EAAE;QAEkB,sBAAsB,GAAvD,sBAAsB;QAGL,cAAc,GAA/B,MAAM;QAEW,YAAY,GAA7B,MAAM;QAIW,gBAAgB,GAAjC,MAAM;QAGW,iBAAiB,GAAlC,MAAM;QAGoB,KAAK,GAA/B,MAAM,GAAC,MAAM,EAAE;KAGzB,EA8FA;IAxBG,6DAA4B;IAC5B,yBAAwC;IACxC,yBAAwC;IAmBxC,kCAAoC;IACpC,uBAAoC;IAIxC,iCAOC;IAED;;;yBA2BC;IAED,6DAEC;IAED;;;;MAEC;IAED;;;;;OA4FC;IAED;;;;0EAgDC;CACF;qCA9UY,OAAO,YAAY,EAAE,sBAAsB;4BAC3C,OAAO,YAAY,EAAE,aAAa;uCAJV,6BAA6B;qCAD/B,2BAA2B"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('./utils.js').InspectCapabilityChain} InspectCapabilityChain
|
|
3
|
+
* @typedef {import('./utils.js').CapabilityMeta} CapabilityMeta
|
|
4
|
+
*/
|
|
5
|
+
export class CapabilityProofPurpose extends jsigs.ControllerProofPurpose {
|
|
6
|
+
/**
|
|
7
|
+
* @param {object} options - The options.
|
|
8
|
+
* @param {boolean} [options.allowTargetAttenuation=false] - Allow the
|
|
9
|
+
* invocationTarget of a delegation chain to be increasingly restrictive
|
|
10
|
+
* based on a hierarchical RESTful URL structure.
|
|
11
|
+
* @param {object} [options.controller] - The description of the controller,
|
|
12
|
+
* if it is not to be dereferenced via a `documentLoader`.
|
|
13
|
+
* @param {string|Date|number} [options.date] - Used during proof
|
|
14
|
+
* verification as the expected date for the creation of the proof
|
|
15
|
+
* (within a maximum timestamp delta) and for checking to see if a
|
|
16
|
+
* capability has expired; if not passed the current date will be used.
|
|
17
|
+
* @param {string|string[]} [options.expectedRootCapability] - The expected
|
|
18
|
+
* root capability for the delegation chain (a single root capability ID
|
|
19
|
+
* string, or an array of acceptable root capability ID strings).
|
|
20
|
+
* @param {InspectCapabilityChain} [options.inspectCapabilityChain] - An
|
|
21
|
+
* async function that can be used to check for revocations related to any
|
|
22
|
+
* of verified capabilities.
|
|
23
|
+
* @param {number} [options.maxChainLength=10] - The maximum length of the
|
|
24
|
+
* capability delegation chain.
|
|
25
|
+
* @param {number} [options.maxClockSkew=300] - A maximum number of seconds
|
|
26
|
+
* that clocks may be skewed checking capability expiration date-times
|
|
27
|
+
* against `date` and when comparing invocation proof creation time against
|
|
28
|
+
* delegation proof creation time.
|
|
29
|
+
* @param {number} [options.maxDelegationTtl=Infinity] - The maximum
|
|
30
|
+
* milliseconds to live for a delegated zcap as measured by the time
|
|
31
|
+
* difference between `expires` and `created` on the delegation proof.
|
|
32
|
+
* @param {number} [options.maxTimestampDelta=Infinity] - A maximum number
|
|
33
|
+
* of seconds that a capability invocation proof (only used by this proof
|
|
34
|
+
* type) "created" date can deviate from `date`, defaults to `Infinity`.
|
|
35
|
+
* @param {object|object[]} [options.suite] - The jsonld-signature suite(s) to
|
|
36
|
+
* use to verify the capability chain. Required only when verifying a proof;
|
|
37
|
+
* unused (and omitted) when creating a delegation proof.
|
|
38
|
+
* @param {string} options.term - The term `capabilityInvocation` or
|
|
39
|
+
* `capabilityDelegation` to look for in an LD proof.
|
|
40
|
+
*/
|
|
41
|
+
constructor({ allowTargetAttenuation, controller, date, expectedRootCapability, inspectCapabilityChain, maxChainLength, maxDelegationTtl, maxTimestampDelta, maxClockSkew, suite, term }?: {
|
|
42
|
+
allowTargetAttenuation?: boolean;
|
|
43
|
+
controller?: object;
|
|
44
|
+
date?: string | Date | number;
|
|
45
|
+
expectedRootCapability?: string | string[];
|
|
46
|
+
inspectCapabilityChain?: InspectCapabilityChain;
|
|
47
|
+
maxChainLength?: number;
|
|
48
|
+
maxClockSkew?: number;
|
|
49
|
+
maxDelegationTtl?: number;
|
|
50
|
+
maxTimestampDelta?: number;
|
|
51
|
+
suite?: object | object[];
|
|
52
|
+
term: string;
|
|
53
|
+
});
|
|
54
|
+
allowTargetAttenuation: boolean;
|
|
55
|
+
expectedRootCapability: string | string[];
|
|
56
|
+
inspectCapabilityChain: Function;
|
|
57
|
+
maxChainLength: number;
|
|
58
|
+
maxClockSkew: number;
|
|
59
|
+
maxDelegationTtl: number;
|
|
60
|
+
suite: any;
|
|
61
|
+
/**
|
|
62
|
+
* Validates a capability proof by verifying its capability delegation chain
|
|
63
|
+
* from the root outward. Overrides
|
|
64
|
+
* {@link jsigs.ControllerProofPurpose#validate} and is structurally
|
|
65
|
+
* compatible with it.
|
|
66
|
+
*
|
|
67
|
+
* @param {object} proof - The proof to validate.
|
|
68
|
+
* @param {object} validateOptions - The validation options (passed through
|
|
69
|
+
* from `jsigs`), including `document` and `documentLoader`.
|
|
70
|
+
*
|
|
71
|
+
* @returns {Promise<import('@interop/jsonld-signatures').
|
|
72
|
+
* ProofValidateResult>} Resolves to `{valid, error?}` (plus an internal
|
|
73
|
+
* `dereferencedChain` on success).
|
|
74
|
+
*/
|
|
75
|
+
validate(proof: object, validateOptions: object): Promise<import("@interop/jsonld-signatures").ProofValidateResult>;
|
|
76
|
+
_dereferenceChain({ document, documentLoader, proof }: {
|
|
77
|
+
document: any;
|
|
78
|
+
documentLoader: any;
|
|
79
|
+
proof: any;
|
|
80
|
+
}): Promise<{
|
|
81
|
+
dereferencedChain: import("./zcap-types.js").Zcap[];
|
|
82
|
+
}>;
|
|
83
|
+
_getCapabilityDelegationClass(): void;
|
|
84
|
+
_getTailCapability(): Promise<void>;
|
|
85
|
+
_runChecksBeforeChainVerification(): Promise<void>;
|
|
86
|
+
_runChecksAfterChainVerification(): Promise<void>;
|
|
87
|
+
_runBaseProofValidation({ proof, validateOptions }: {
|
|
88
|
+
proof: any;
|
|
89
|
+
validateOptions: any;
|
|
90
|
+
}): Promise<jsigs.ProofValidateResult>;
|
|
91
|
+
_shortCircuitValidate(): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Verifies the given dereferenced capability chain. This involves ensuring
|
|
94
|
+
* that the root zcap in the chain is as expected (for the endpoint where an
|
|
95
|
+
* invocation or a simple chain chain is occurring) and that every other zcap
|
|
96
|
+
* in the chain (including any invoked one), has been properly delegated.
|
|
97
|
+
*
|
|
98
|
+
* @param {object} options - The options.
|
|
99
|
+
* @param {Function} options.CapabilityDelegation - The CapabilityDelegation
|
|
100
|
+
* class; this must be passed to avoid circular references in this module.
|
|
101
|
+
* @param {CapabilityMeta[]} options.capabilityChainMeta - The array of
|
|
102
|
+
* results for inspecting the capability chain; if this has a value when
|
|
103
|
+
* passed, then it is presumed to be the verify result for the tail
|
|
104
|
+
* capability and that tail capability will not be verified internally by
|
|
105
|
+
* this function to avoid duplicating work; all verification results
|
|
106
|
+
* (including the tail's -- either computed locally or reused from what
|
|
107
|
+
* was passed) will be added to this array in order from root => tail.
|
|
108
|
+
* @param {Array} options.dereferencedChain - The dereferenced capability
|
|
109
|
+
* chain for `capability`, starting at the root capability and ending at
|
|
110
|
+
* `capability`.
|
|
111
|
+
* @param {Function} options.documentLoader - A configured jsonld
|
|
112
|
+
* documentLoader.
|
|
113
|
+
*
|
|
114
|
+
* @returns {object} An object with `{verified, error}`.
|
|
115
|
+
*/
|
|
116
|
+
_verifyCapabilityChain({ CapabilityDelegation, capabilityChainMeta, dereferencedChain, documentLoader }: {
|
|
117
|
+
CapabilityDelegation: Function;
|
|
118
|
+
capabilityChainMeta: CapabilityMeta[];
|
|
119
|
+
dereferencedChain: any[];
|
|
120
|
+
documentLoader: Function;
|
|
121
|
+
}): object;
|
|
122
|
+
}
|
|
123
|
+
export type InspectCapabilityChain = import("./utils.js").InspectCapabilityChain;
|
|
124
|
+
export type CapabilityMeta = import("./utils.js").CapabilityMeta;
|
|
125
|
+
import jsigs from '@interop/jsonld-signatures';
|
|
126
|
+
//# sourceMappingURL=CapabilityProofPurpose.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CapabilityProofPurpose.d.ts","sourceRoot":"","sources":["../../lib/CapabilityProofPurpose.js"],"names":[],"mappings":"AAUA;;;GAGG;AAEH;IACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,2LAjCG;QAA0B,sBAAsB,GAAxC,OAAO;QAGU,UAAU,GAA3B,MAAM;QAEuB,IAAI,GAAjC,MAAM,GAAC,IAAI,GAAC,MAAM;QAIQ,sBAAsB,GAAhD,MAAM,GAAC,MAAM,EAAE;QAGkB,sBAAsB,GAAvD,sBAAsB;QAGL,cAAc,GAA/B,MAAM;QAEW,YAAY,GAA7B,MAAM;QAIW,gBAAgB,GAAjC,MAAM;QAGW,iBAAiB,GAAlC,MAAM;QAGoB,KAAK,GAA/B,MAAM,GAAC,MAAM,EAAE;QAGC,IAAI,EAApB,MAAM;KAEhB,EAiDA;IARG,gCAAoD;IACpD,0CAAoD;IACpD,iCAAoD;IACpD,uBAAoC;IACpC,qBAAgC;IAChC,yBAAwC;IACxC,WAAkB;IAItB;;;;;;;;;;;;;OAaG;IACH,gBARW,MAAM,mBACN,MAAM,GAGJ,OAAO,CAAC,OAAO,4BAA4B,EACnD,mBAAmB,CAAC,CAmIxB;IAED;;;;;;OA+BC;IAED,sCAEC;IAED,oCAEC;IAGD,mDAA4C;IAG5C,kDAA2C;IAE3C;;;2CAOC;IAGD,uCAAgC;IAEhC;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,yGAjBG;QAA0B,oBAAoB;QAEZ,mBAAmB,EAA7C,cAAc,EAAE;QAOD,iBAAiB;QAGd,cAAc;KAGxC,GAAU,MAAM,CAkNlB;CACF;qCA9gBY,OAAO,YAAY,EAAE,sBAAsB;6BAC3C,OAAO,YAAY,EAAE,cAAc;kBAR9B,4BAA4B"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** @type {object} The zcap JSON-LD context document. */
|
|
2
|
+
export const ZCAP_CONTEXT: object;
|
|
3
|
+
/** @type {string} The zcap JSON-LD context URL (`https://w3id.org/zcap/v1`). */
|
|
4
|
+
export const ZCAP_CONTEXT_URL: string;
|
|
5
|
+
/** @type {string} The base URL for the zcap security vocabulary. */
|
|
6
|
+
export const CAPABILITY_VOCAB_URL: string;
|
|
7
|
+
/** @type {string} URI prefix for root capability IDs (`urn:zcap:root:`). */
|
|
8
|
+
export const ZCAP_ROOT_PREFIX: string;
|
|
9
|
+
/**
|
|
10
|
+
* Default maximum capability delegation chain length (inclusive of the tail).
|
|
11
|
+
*
|
|
12
|
+
* @type {number}
|
|
13
|
+
*/
|
|
14
|
+
export const MAX_CHAIN_LENGTH: number;
|
|
15
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../lib/constants.js"],"names":[],"mappings":"AAYA,wDAAwD;AACxD,2BADW,MAAM,CACmB;AAEpC,gFAAgF;AAChF,+BADW,MAAM,CAC2B;AAE5C,oEAAoE;AACpE,mCADW,MAAM,CACgD;AAEjE,4EAA4E;AAC5E,+BADW,MAAM,CACgC;AAEjD;;;;GAIG;AAGH,+BAJU,MAAM,CAImB"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('./utils.js').RootZcap} RootZcap
|
|
3
|
+
* @typedef {import('./utils.js').DelegatedZcap} DelegatedZcap
|
|
4
|
+
* @typedef {import('./utils.js').Zcap} Zcap
|
|
5
|
+
* @typedef {import('./utils.js').CapabilityDelegationProof} CapabilityDelegationProof
|
|
6
|
+
* @typedef {import('./utils.js').InspectCapabilityChain} InspectCapabilityChain
|
|
7
|
+
* @typedef {import('./utils.js').InspectResult} InspectResult
|
|
8
|
+
* @typedef {import('./utils.js').CapabilityChainDetails} CapabilityChainDetails
|
|
9
|
+
* @typedef {import('./utils.js').CapabilityMeta} CapabilityMeta
|
|
10
|
+
* @typedef {import('./utils.js').VerifyResult} VerifyResult
|
|
11
|
+
* @typedef {import('./utils.js').VerifyProofResult} VerifyProofResult
|
|
12
|
+
* @typedef {import('./utils.js').VerifyProofPurposeResult} VerifyProofPurposeResult
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Wraps an existing document loader so that it also serves the zcap JSON-LD
|
|
16
|
+
* context. The wrapped loader is called for all other URLs.
|
|
17
|
+
*
|
|
18
|
+
* @param {Function} documentLoader - An existing JSON-LD document loader to
|
|
19
|
+
* extend.
|
|
20
|
+
*
|
|
21
|
+
* @returns {Function} A new document loader that handles the zcap context URL
|
|
22
|
+
* and delegates all other URLs to the wrapped loader.
|
|
23
|
+
*/
|
|
24
|
+
export function extendDocumentLoader(documentLoader: Function): Function;
|
|
25
|
+
export { CapabilityInvocation } from "./CapabilityInvocation.js";
|
|
26
|
+
export { CapabilityDelegation } from "./CapabilityDelegation.js";
|
|
27
|
+
export { createRootCapability } from "./utils.js";
|
|
28
|
+
export { constants };
|
|
29
|
+
/**
|
|
30
|
+
* A default JSON-LD document loader that serves only the zcap and
|
|
31
|
+
* jsonld-signatures contexts. Suitable for use when no other contexts are
|
|
32
|
+
* needed. Extend it with {@link extendDocumentLoader} if additional contexts
|
|
33
|
+
* are required.
|
|
34
|
+
*
|
|
35
|
+
* @type {Function}
|
|
36
|
+
*/
|
|
37
|
+
export const documentLoader: Function;
|
|
38
|
+
export type RootZcap = import("./utils.js").RootZcap;
|
|
39
|
+
export type DelegatedZcap = import("./utils.js").DelegatedZcap;
|
|
40
|
+
export type Zcap = import("./utils.js").Zcap;
|
|
41
|
+
export type CapabilityDelegationProof = import("./utils.js").CapabilityDelegationProof;
|
|
42
|
+
export type InspectCapabilityChain = import("./utils.js").InspectCapabilityChain;
|
|
43
|
+
export type InspectResult = import("./utils.js").InspectResult;
|
|
44
|
+
export type CapabilityChainDetails = import("./utils.js").CapabilityChainDetails;
|
|
45
|
+
export type CapabilityMeta = import("./utils.js").CapabilityMeta;
|
|
46
|
+
export type VerifyResult = import("./utils.js").VerifyResult;
|
|
47
|
+
export type VerifyProofResult = import("./utils.js").VerifyProofResult;
|
|
48
|
+
export type VerifyProofPurposeResult = import("./utils.js").VerifyProofPurposeResult;
|
|
49
|
+
import * as constants from './constants.js';
|
|
50
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.js"],"names":[],"mappings":"AAYA;;;;;;;;;;;;GAYG;AAEH;;;;;;;;;GASG;AACH,yEAYC;;;;;AAED;;;;;;;GAOG;AACH,sCAC8B;uBA9CjB,OAAO,YAAY,EAAE,QAAQ;4BAC7B,OAAO,YAAY,EAAE,aAAa;mBAClC,OAAO,YAAY,EAAE,IAAI;wCACzB,OAAO,YAAY,EAAE,yBAAyB;qCAC9C,OAAO,YAAY,EAAE,sBAAsB;4BAC3C,OAAO,YAAY,EAAE,aAAa;qCAClC,OAAO,YAAY,EAAE,sBAAsB;6BAC3C,OAAO,YAAY,EAAE,cAAc;2BACnC,OAAO,YAAY,EAAE,YAAY;gCACjC,OAAO,YAAY,EAAE,iBAAiB;uCACtC,OAAO,YAAY,EAAE,wBAAwB;2BAd/B,gBAAgB"}
|