@interop/did-cli 0.6.0
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/CHANGELOG.md +341 -0
- package/LICENSE.md +21 -0
- package/README.md +1307 -0
- package/dist/commands/did.d.ts +3 -0
- package/dist/commands/did.d.ts.map +1 -0
- package/dist/commands/did.js +605 -0
- package/dist/commands/did.js.map +1 -0
- package/dist/commands/key.d.ts +3 -0
- package/dist/commands/key.d.ts.map +1 -0
- package/dist/commands/key.js +430 -0
- package/dist/commands/key.js.map +1 -0
- package/dist/commands/vc.d.ts +79 -0
- package/dist/commands/vc.d.ts.map +1 -0
- package/dist/commands/vc.js +528 -0
- package/dist/commands/vc.js.map +1 -0
- package/dist/commands/wallet.d.ts +14 -0
- package/dist/commands/wallet.d.ts.map +1 -0
- package/dist/commands/wallet.js +48 -0
- package/dist/commands/wallet.js.map +1 -0
- package/dist/commands/was.d.ts +500 -0
- package/dist/commands/was.d.ts.map +1 -0
- package/dist/commands/was.js +1833 -0
- package/dist/commands/was.js.map +1 -0
- package/dist/commands/zcap.d.ts +85 -0
- package/dist/commands/zcap.d.ts.map +1 -0
- package/dist/commands/zcap.js +447 -0
- package/dist/commands/zcap.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/keys/ecdsa.d.ts +40 -0
- package/dist/keys/ecdsa.d.ts.map +1 -0
- package/dist/keys/ecdsa.js +73 -0
- package/dist/keys/ecdsa.js.map +1 -0
- package/dist/meta.d.ts +164 -0
- package/dist/meta.d.ts.map +1 -0
- package/dist/meta.js +286 -0
- package/dist/meta.js.map +1 -0
- package/dist/storage.d.ts +191 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +307 -0
- package/dist/storage.js.map +1 -0
- package/dist/table.d.ts +43 -0
- package/dist/table.d.ts.map +1 -0
- package/dist/table.js +61 -0
- package/dist/table.js.map +1 -0
- package/dist/vc/fixtures/welcomeCredential.d.ts +22 -0
- package/dist/vc/fixtures/welcomeCredential.d.ts.map +1 -0
- package/dist/vc/fixtures/welcomeCredential.js +25 -0
- package/dist/vc/fixtures/welcomeCredential.js.map +1 -0
- package/dist/vc/issue.d.ts +24 -0
- package/dist/vc/issue.d.ts.map +1 -0
- package/dist/vc/issue.js +211 -0
- package/dist/vc/issue.js.map +1 -0
- package/dist/vc/registries.d.ts +30 -0
- package/dist/vc/registries.d.ts.map +1 -0
- package/dist/vc/registries.js +53 -0
- package/dist/vc/registries.js.map +1 -0
- package/dist/vc/registryManager.d.ts +25 -0
- package/dist/vc/registryManager.d.ts.map +1 -0
- package/dist/vc/registryManager.js +29 -0
- package/dist/vc/registryManager.js.map +1 -0
- package/dist/vc/suites/expirationSuite.d.ts +23 -0
- package/dist/vc/suites/expirationSuite.d.ts.map +1 -0
- package/dist/vc/suites/expirationSuite.js +84 -0
- package/dist/vc/suites/expirationSuite.js.map +1 -0
- package/dist/vc/suites/issuerDetailsSuite.d.ts +22 -0
- package/dist/vc/suites/issuerDetailsSuite.d.ts.map +1 -0
- package/dist/vc/suites/issuerDetailsSuite.js +69 -0
- package/dist/vc/suites/issuerDetailsSuite.js.map +1 -0
- package/dist/vc/verify.d.ts +46 -0
- package/dist/vc/verify.d.ts.map +1 -0
- package/dist/vc/verify.js +147 -0
- package/dist/vc/verify.js.map +1 -0
- package/dist/was/address.d.ts +44 -0
- package/dist/was/address.d.ts.map +1 -0
- package/dist/was/address.js +98 -0
- package/dist/was/address.js.map +1 -0
- package/dist/was/capability.d.ts +65 -0
- package/dist/was/capability.d.ts.map +1 -0
- package/dist/was/capability.js +108 -0
- package/dist/was/capability.js.map +1 -0
- package/dist/was/client.d.ts +108 -0
- package/dist/was/client.d.ts.map +1 -0
- package/dist/was/client.js +142 -0
- package/dist/was/client.js.map +1 -0
- package/dist/was/io.d.ts +71 -0
- package/dist/was/io.d.ts.map +1 -0
- package/dist/was/io.js +146 -0
- package/dist/was/io.js.map +1 -0
- package/dist/was/registry.d.ts +79 -0
- package/dist/was/registry.d.ts.map +1 -0
- package/dist/was/registry.js +99 -0
- package/dist/was/registry.js.map +1 -0
- package/dist/zcap/create.d.ts +20 -0
- package/dist/zcap/create.d.ts.map +1 -0
- package/dist/zcap/create.js +29 -0
- package/dist/zcap/create.js.map +1 -0
- package/dist/zcap/delegate.d.ts +44 -0
- package/dist/zcap/delegate.d.ts.map +1 -0
- package/dist/zcap/delegate.js +77 -0
- package/dist/zcap/delegate.js.map +1 -0
- package/dist/zcap/encoding.d.ts +17 -0
- package/dist/zcap/encoding.d.ts.map +1 -0
- package/dist/zcap/encoding.js +37 -0
- package/dist/zcap/encoding.js.map +1 -0
- package/dist/zcap/signer.d.ts +20 -0
- package/dist/zcap/signer.d.ts.map +1 -0
- package/dist/zcap/signer.js +62 -0
- package/dist/zcap/signer.js.map +1 -0
- package/dist/zcap/ttl.d.ts +19 -0
- package/dist/zcap/ttl.d.ts.map +1 -0
- package/dist/zcap/ttl.js +40 -0
- package/dist/zcap/ttl.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"issuerDetailsSuite.js","sourceRoot":"","sources":["../../../src/vc/suites/issuerDetailsSuite.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AAE/D;;;;;;GAMG;AACH,SAAS,YAAY,CAAC,UAAmC;IACvD,MAAM,MAAM,GAAG,UAAU,CAAC,MAA8C,CAAA;IACxE,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,MAAM,CAAA;IACf,CAAC;IACD,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,MAAM,CAAC,EAAE,KAAK,QAAQ,EAAE,CAAC;QAC1E,OAAO,MAAM,CAAC,EAAE,CAAA;IAClB,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CA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Ae,EAAE;SAC7B,CAAA;IACH,CAAC;CACF,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAsB;IACnD,EAAE,EAAE,OAAO;IACX,IAAI,EAAE,cAAc;IACpB,WAAW,EAAE,yCAAyC;IACtD,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,CAAC,kBAAkB,CAAC;CAC7B,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { CredentialVerificationResult, CheckResult, EntityIdentityRegistry } from '@interop/verifier-core';
|
|
2
|
+
/**
|
|
3
|
+
* Compact, human-friendly verification summary produced for the `--summary`
|
|
4
|
+
* flag. `undefined` check values mean the check was skipped (not applicable).
|
|
5
|
+
*/
|
|
6
|
+
export interface VerificationSummary {
|
|
7
|
+
verified: boolean;
|
|
8
|
+
checks: {
|
|
9
|
+
signature?: boolean;
|
|
10
|
+
expired?: boolean;
|
|
11
|
+
revoked?: boolean;
|
|
12
|
+
issuerRecognized?: boolean;
|
|
13
|
+
};
|
|
14
|
+
matchingIssuers: unknown[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Runs full verification on a credential: the default verifier-core pipeline
|
|
18
|
+
* plus the expiration and issuer-details custom suites.
|
|
19
|
+
*
|
|
20
|
+
* @param options {object}
|
|
21
|
+
* @param options.credential {object} The parsed Verifiable Credential.
|
|
22
|
+
* @param options.registries {EntityIdentityRegistry[]} Trusted registries
|
|
23
|
+
* for the issuer DID lookup.
|
|
24
|
+
* @returns {Promise<CredentialVerificationResult>}
|
|
25
|
+
*/
|
|
26
|
+
export declare function verifyCredentialFully({ credential, registries }: {
|
|
27
|
+
credential: object;
|
|
28
|
+
registries: EntityIdentityRegistry[];
|
|
29
|
+
}): Promise<CredentialVerificationResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Returns the result of a structural parse failure check, if the credential
|
|
32
|
+
* was malformed. Callers treat this as a fatal (exit code 2) condition.
|
|
33
|
+
*
|
|
34
|
+
* @param result {CredentialVerificationResult}
|
|
35
|
+
* @returns {CheckResult | undefined}
|
|
36
|
+
*/
|
|
37
|
+
export declare function findParseFailure(result: CredentialVerificationResult): CheckResult | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Translates a verifier-core result into a compact summary object for the
|
|
40
|
+
* `--summary` flag.
|
|
41
|
+
*
|
|
42
|
+
* @param result {CredentialVerificationResult}
|
|
43
|
+
* @returns {VerificationSummary}
|
|
44
|
+
*/
|
|
45
|
+
export declare function toSummary(result: CredentialVerificationResult): VerificationSummary;
|
|
46
|
+
//# sourceMappingURL=verify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../src/vc/verify.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACV,4BAA4B,EAC5B,WAAW,EACX,sBAAsB,EACvB,MAAM,wBAAwB,CAAA;AAgB/B;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,OAAO,CAAA;IACjB,MAAM,EAAE;QACN,SAAS,CAAC,EAAE,OAAO,CAAA;QACnB,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,gBAAgB,CAAC,EAAE,OAAO,CAAA;KAC3B,CAAA;IACD,eAAe,EAAE,OAAO,EAAE,CAAA;CAC3B;AAED;;;;;;;;;GASG;AACH,wBAAsB,qBAAqB,CAAC,EAC1C,UAAU,EACV,UAAU,EACX,EAAE;IACD,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,sBAAsB,EAAE,CAAA;CACrC,GAAG,OAAO,CAAC,4BAA4B,CAAC,CASxC;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,4BAA4B,GACnC,WAAW,GAAG,SAAS,CAKzB;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,4BAA4B,GACnC,mBAAmB,CAcrB"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential verification adapter over @interop/verifier-core.
|
|
3
|
+
*
|
|
4
|
+
* A single `verifyCredentialFully` call runs the fork's default suite pipeline
|
|
5
|
+
* (structure, cryptographic signature, revocation/status, issuer registry
|
|
6
|
+
* lookup) plus two custom suites (`expirationSuite`, `issuerDetailsSuite`),
|
|
7
|
+
* returning the unified `CredentialVerificationResult` directly -- it is
|
|
8
|
+
* already dev-friendly (top-level `verified`, per-suite `summary[]`, flat
|
|
9
|
+
* `results[]`). `toSummary` derives a compact flattened object for the CLI's
|
|
10
|
+
* `--summary` flag. All knowledge of the verifier-core contract is isolated to
|
|
11
|
+
* this file.
|
|
12
|
+
*/
|
|
13
|
+
import { verifyCredential, ProblemTypes } from '@interop/verifier-core';
|
|
14
|
+
import { expirationSuite } from './suites/expirationSuite.js';
|
|
15
|
+
import { issuerDetailsSuite } from './suites/issuerDetailsSuite.js';
|
|
16
|
+
/**
|
|
17
|
+
* Dot-separated check ids emitted by the verifier-core pipeline (and the two
|
|
18
|
+
* custom suites) that the summary reads.
|
|
19
|
+
*/
|
|
20
|
+
const CHECK_ID = {
|
|
21
|
+
signature: 'proof.signature',
|
|
22
|
+
status: 'status.bitstring',
|
|
23
|
+
expiration: 'validity.expiration',
|
|
24
|
+
issuerDetails: 'trust.issuer-details',
|
|
25
|
+
parsing: 'parsing.envelope'
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Runs full verification on a credential: the default verifier-core pipeline
|
|
29
|
+
* plus the expiration and issuer-details custom suites.
|
|
30
|
+
*
|
|
31
|
+
* @param options {object}
|
|
32
|
+
* @param options.credential {object} The parsed Verifiable Credential.
|
|
33
|
+
* @param options.registries {EntityIdentityRegistry[]} Trusted registries
|
|
34
|
+
* for the issuer DID lookup.
|
|
35
|
+
* @returns {Promise<CredentialVerificationResult>}
|
|
36
|
+
*/
|
|
37
|
+
export async function verifyCredentialFully({ credential, registries }) {
|
|
38
|
+
return verifyCredential({
|
|
39
|
+
credential: credential,
|
|
40
|
+
registries,
|
|
41
|
+
additionalSuites: [expirationSuite, issuerDetailsSuite],
|
|
42
|
+
// verbose so results[] carries EVERY check (incl. successes and the
|
|
43
|
+
// issuer-details payload), not just failures folded into summary[].
|
|
44
|
+
verbose: true
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Returns the result of a structural parse failure check, if the credential
|
|
49
|
+
* was malformed. Callers treat this as a fatal (exit code 2) condition.
|
|
50
|
+
*
|
|
51
|
+
* @param result {CredentialVerificationResult}
|
|
52
|
+
* @returns {CheckResult | undefined}
|
|
53
|
+
*/
|
|
54
|
+
export function findParseFailure(result) {
|
|
55
|
+
return result.results.find(check => check.check === CHECK_ID.parsing && check.outcome.status === 'failure');
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Translates a verifier-core result into a compact summary object for the
|
|
59
|
+
* `--summary` flag.
|
|
60
|
+
*
|
|
61
|
+
* @param result {CredentialVerificationResult}
|
|
62
|
+
* @returns {VerificationSummary}
|
|
63
|
+
*/
|
|
64
|
+
export function toSummary(result) {
|
|
65
|
+
const byCheck = (checkId) => result.results.find(check => check.check === checkId);
|
|
66
|
+
return {
|
|
67
|
+
verified: result.verified,
|
|
68
|
+
checks: {
|
|
69
|
+
signature: passed(byCheck(CHECK_ID.signature)),
|
|
70
|
+
expired: failed(byCheck(CHECK_ID.expiration)),
|
|
71
|
+
revoked: revoked(byCheck(CHECK_ID.status)),
|
|
72
|
+
issuerRecognized: issuerRecognized(byCheck(CHECK_ID.issuerDetails))
|
|
73
|
+
},
|
|
74
|
+
matchingIssuers: matchingIssuersFrom(byCheck(CHECK_ID.issuerDetails))
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Maps a check to `true` on success, `false` on failure, `undefined` when the
|
|
79
|
+
* check was skipped or absent.
|
|
80
|
+
*
|
|
81
|
+
* @param check {CheckResult | undefined}
|
|
82
|
+
* @returns {boolean | undefined}
|
|
83
|
+
*/
|
|
84
|
+
function passed(check) {
|
|
85
|
+
if (!check || check.outcome.status === 'skipped') {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
return check.outcome.status === 'success';
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Maps a check to `true` when it failed (e.g. the expiration check), `false`
|
|
92
|
+
* on success, `undefined` when skipped or absent.
|
|
93
|
+
*
|
|
94
|
+
* @param check {CheckResult | undefined}
|
|
95
|
+
* @returns {boolean | undefined}
|
|
96
|
+
*/
|
|
97
|
+
function failed(check) {
|
|
98
|
+
const result = passed(check);
|
|
99
|
+
return result === undefined ? undefined : !result;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Maps the status (revocation) check to a `revoked` boolean. A failure whose
|
|
103
|
+
* first problem is STATUS_LIST_NOT_FOUND is treated as "not revoked" -- the
|
|
104
|
+
* status list simply is not published, so the credential is unchecked rather
|
|
105
|
+
* than revoked.
|
|
106
|
+
*
|
|
107
|
+
* @param check {CheckResult | undefined}
|
|
108
|
+
* @returns {boolean | undefined}
|
|
109
|
+
*/
|
|
110
|
+
function revoked(check) {
|
|
111
|
+
if (!check || check.outcome.status === 'skipped') {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
if (check.outcome.status === 'success') {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
if (check.outcome.problems[0]?.type === ProblemTypes.STATUS_LIST_NOT_FOUND) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Maps the issuer-details check to whether the issuer was found in a registry.
|
|
124
|
+
*
|
|
125
|
+
* @param check {CheckResult | undefined}
|
|
126
|
+
* @returns {boolean | undefined}
|
|
127
|
+
*/
|
|
128
|
+
function issuerRecognized(check) {
|
|
129
|
+
if (!check || check.outcome.status !== 'success') {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
return matchingIssuersFrom(check).length > 0;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Pulls the rich `matchingIssuers` array off the issuer-details check payload.
|
|
136
|
+
*
|
|
137
|
+
* @param check {CheckResult | undefined}
|
|
138
|
+
* @returns {unknown[]}
|
|
139
|
+
*/
|
|
140
|
+
function matchingIssuersFrom(check) {
|
|
141
|
+
if (!check || check.outcome.status !== 'success') {
|
|
142
|
+
return [];
|
|
143
|
+
}
|
|
144
|
+
const payload = check.outcome.payload;
|
|
145
|
+
return payload?.matchingIssuers ?? [];
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=verify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.js","sourceRoot":"","sources":["../../src/vc/verify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAMvE,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAEnE;;;GAGG;AACH,MAAM,QAAQ,GAAG;IACf,SAAS,EAAE,iBAAiB;IAC5B,MAAM,EAAE,kBAAkB;IAC1B,UAAU,EAAE,qBAAqB;IACjC,aAAa,EAAE,sBAAsB;IACrC,OAAO,EAAE,kBAAkB;CACnB,CAAA;AAiBV;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,EAC1C,UAAU,EACV,UAAU,EAIX;IACC,OAAO,gBAAgB,CAAC;QACtB,UAAU,EAAE,UAAmB;QAC/B,UAAU;QACV,gBAAgB,EAAE,CAAC,eAAe,EAAE,kBAAkB,CAAC;QACvD,oEAAoE;QACpE,oEAAoE;QACpE,OAAO,EAAE,IAAI;KACd,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM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URCE]]` -- into its components.
|
|
4
|
+
*
|
|
5
|
+
* The `SPACE` part takes one of three forms:
|
|
6
|
+
*
|
|
7
|
+
* - a local registry handle (e.g. `home`), resolved later against the local
|
|
8
|
+
* space registry;
|
|
9
|
+
* - a bare space id (e.g. a server-generated uuid or urn), which needs the
|
|
10
|
+
* server URL supplied separately;
|
|
11
|
+
* - a full space https URL (e.g. `https://was.example/space/<id>`), which is
|
|
12
|
+
* self-contained: the server URL is the URL's origin and the space id is
|
|
13
|
+
* the segment after `/space/`. Collection/resource segments may appear
|
|
14
|
+
* inside the URL itself or be appended with the same `/<coll>/<res>`
|
|
15
|
+
* syntax as the other forms.
|
|
16
|
+
*
|
|
17
|
+
* Handles and bare space ids are not distinguished here -- both land in
|
|
18
|
+
* `spaceRef` and are resolved against the registry by the caller. Resource
|
|
19
|
+
* ids containing `/` are not supported by this syntax.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* The normalized form of a WAS address: the server URL when the address was
|
|
23
|
+
* given as a full space URL, the space reference (handle or space id) as
|
|
24
|
+
* written, and the optional collection/resource ids.
|
|
25
|
+
*/
|
|
26
|
+
export interface WasAddress {
|
|
27
|
+
/** Server base URL (origin), present only for the full-URL form. */
|
|
28
|
+
server?: string;
|
|
29
|
+
/** The space handle or space id, exactly as the user wrote it. */
|
|
30
|
+
spaceRef: string;
|
|
31
|
+
collectionId?: string;
|
|
32
|
+
resourceId?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Parses a WAS address -- `SPACE[/COLLECTION[/RESOURCE]]`, where `SPACE` is a
|
|
36
|
+
* registry handle, a bare space id, or a full space https URL -- into its
|
|
37
|
+
* normalized components. Throws on malformed addresses (empty segments,
|
|
38
|
+
* paths deeper than collection/resource, URLs without a `/space/<id>` path).
|
|
39
|
+
*
|
|
40
|
+
* @param address {string}
|
|
41
|
+
* @returns {WasAddress}
|
|
42
|
+
*/
|
|
43
|
+
export declare function parseWasAddress(address: string): WasAddress;
|
|
44
|
+
//# sourceMappingURL=address.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/was/address.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,kEAAkE;IAClE,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAuDD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CA2B3D"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WAS path parsing: normalizes the single positional address accepted by the
|
|
3
|
+
* `was` commands -- `SPACE[/COLLECTION[/RESOURCE]]` -- into its components.
|
|
4
|
+
*
|
|
5
|
+
* The `SPACE` part takes one of three forms:
|
|
6
|
+
*
|
|
7
|
+
* - a local registry handle (e.g. `home`), resolved later against the local
|
|
8
|
+
* space registry;
|
|
9
|
+
* - a bare space id (e.g. a server-generated uuid or urn), which needs the
|
|
10
|
+
* server URL supplied separately;
|
|
11
|
+
* - a full space https URL (e.g. `https://was.example/space/<id>`), which is
|
|
12
|
+
* self-contained: the server URL is the URL's origin and the space id is
|
|
13
|
+
* the segment after `/space/`. Collection/resource segments may appear
|
|
14
|
+
* inside the URL itself or be appended with the same `/<coll>/<res>`
|
|
15
|
+
* syntax as the other forms.
|
|
16
|
+
*
|
|
17
|
+
* Handles and bare space ids are not distinguished here -- both land in
|
|
18
|
+
* `spaceRef` and are resolved against the registry by the caller. Resource
|
|
19
|
+
* ids containing `/` are not supported by this syntax.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Returns the parsed URL when the value is an http(s) URL, undefined
|
|
23
|
+
* otherwise.
|
|
24
|
+
*
|
|
25
|
+
* @param value {string}
|
|
26
|
+
* @returns {URL | undefined}
|
|
27
|
+
*/
|
|
28
|
+
function tryParseHttpUrl(value) {
|
|
29
|
+
let url;
|
|
30
|
+
try {
|
|
31
|
+
url = new URL(value);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
return url;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Splits the trailing path segments of a WAS address into collection and
|
|
43
|
+
* resource ids, rejecting empty segments and paths deeper than
|
|
44
|
+
* collection/resource.
|
|
45
|
+
*
|
|
46
|
+
* @param options {object}
|
|
47
|
+
* @param options.segments {string[]}
|
|
48
|
+
* @param options.address {string} The original address, for error messages.
|
|
49
|
+
* @returns {{collectionId?: string, resourceId?: string}}
|
|
50
|
+
*/
|
|
51
|
+
function parseTailSegments({ segments, address }) {
|
|
52
|
+
if (segments.length > 2) {
|
|
53
|
+
throw new Error(`Invalid WAS address "${address}": expected at most ` +
|
|
54
|
+
'SPACE/COLLECTION/RESOURCE.');
|
|
55
|
+
}
|
|
56
|
+
if (segments.some(segment => segment === '')) {
|
|
57
|
+
throw new Error(`Invalid WAS address "${address}": empty path segment.`);
|
|
58
|
+
}
|
|
59
|
+
const [collectionId, resourceId] = segments;
|
|
60
|
+
return {
|
|
61
|
+
...(collectionId !== undefined && { collectionId }),
|
|
62
|
+
...(resourceId !== undefined && { resourceId })
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Parses a WAS address -- `SPACE[/COLLECTION[/RESOURCE]]`, where `SPACE` is a
|
|
67
|
+
* registry handle, a bare space id, or a full space https URL -- into its
|
|
68
|
+
* normalized components. Throws on malformed addresses (empty segments,
|
|
69
|
+
* paths deeper than collection/resource, URLs without a `/space/<id>` path).
|
|
70
|
+
*
|
|
71
|
+
* @param address {string}
|
|
72
|
+
* @returns {WasAddress}
|
|
73
|
+
*/
|
|
74
|
+
export function parseWasAddress(address) {
|
|
75
|
+
if (address === '') {
|
|
76
|
+
throw new Error('Invalid WAS address: empty string.');
|
|
77
|
+
}
|
|
78
|
+
const url = tryParseHttpUrl(address);
|
|
79
|
+
if (url) {
|
|
80
|
+
const segments = url.pathname.split('/').filter(Boolean);
|
|
81
|
+
if (segments[0] !== 'space' || !segments[1]) {
|
|
82
|
+
throw new Error(`Invalid WAS space URL "${address}": expected a path of the form ` +
|
|
83
|
+
'/space/<space-id>[/<collection>[/<resource>]].');
|
|
84
|
+
}
|
|
85
|
+
const [, spaceRef, ...tail] = segments;
|
|
86
|
+
return {
|
|
87
|
+
server: url.origin,
|
|
88
|
+
spaceRef,
|
|
89
|
+
...parseTailSegments({ segments: tail, address })
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const [spaceRef, ...tail] = address.split('/');
|
|
93
|
+
if (spaceRef === '') {
|
|
94
|
+
throw new Error(`Invalid WAS address "${address}": empty space segment.`);
|
|
95
|
+
}
|
|
96
|
+
return { spaceRef, ...parseTailSegments({ segments: tail, address }) };
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../src/was/address.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAgBH;;;;;;GAMG;AACH,SAAS,eAAe,CAAC,KAAa;IACpC,IAAI,GAAQ,CAAA;IACZ,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAA;IACtB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC1D,OA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MAAM,CAAC,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,GAAG,QAAQ,CAAA;QACtC,OAAO;YACL,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,QAAQ;YACR,GAAG,iBAAiB,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;SAClD,CAAA;IACH,CAAC;IAED,MAAM,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC9C,IAAI,QAAQ,KAAK,EAAE,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,wBAAwB,OAAO,yBAAyB,CAAC,CAAA;IAC3E,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,GAAG,iBAAiB,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,CAAA;AACxE,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { Collection, Resource, Space, IZcap, WasClient } from '@interop/was-client';
|
|
2
|
+
/**
|
|
3
|
+
* The depth a capability handle operates at, implied by the path of its
|
|
4
|
+
* `invocationTarget`.
|
|
5
|
+
*/
|
|
6
|
+
export type CapabilityDepth = 'space' | 'collection' | 'resource';
|
|
7
|
+
/**
|
|
8
|
+
* The depth-independent fields of a resolved capability target.
|
|
9
|
+
*/
|
|
10
|
+
interface ResolvedCapabilityBase {
|
|
11
|
+
client: WasClient;
|
|
12
|
+
zcap: IZcap;
|
|
13
|
+
/** The server base URL (the invocation target's origin). */
|
|
14
|
+
server: string;
|
|
15
|
+
/** The resolved signing DID. */
|
|
16
|
+
did: string;
|
|
17
|
+
/** The capability's invocation target URL, for messages and output. */
|
|
18
|
+
url: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A ready-to-use command target rebuilt from a received capability. A
|
|
22
|
+
* discriminated union keyed by `depth`, so checking the depth narrows the
|
|
23
|
+
* `handle` to the matching access-handle type.
|
|
24
|
+
*/
|
|
25
|
+
export type ResolvedCapabilityTarget = (ResolvedCapabilityBase & {
|
|
26
|
+
depth: 'space';
|
|
27
|
+
handle: Space;
|
|
28
|
+
}) | (ResolvedCapabilityBase & {
|
|
29
|
+
depth: 'collection';
|
|
30
|
+
handle: Collection;
|
|
31
|
+
}) | (ResolvedCapabilityBase & {
|
|
32
|
+
depth: 'resource';
|
|
33
|
+
handle: Resource;
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* Resolves a `--capability` reference to a capability object. A value
|
|
37
|
+
* beginning with `z` is decoded as a multibase capability string; a path to
|
|
38
|
+
* an existing file is parsed as capability JSON; anything else is looked up
|
|
39
|
+
* in the local zcap store by capability id or metadata handle.
|
|
40
|
+
*
|
|
41
|
+
* @param options {object}
|
|
42
|
+
* @param options.ref {string}
|
|
43
|
+
* @returns {Promise<IZcap>}
|
|
44
|
+
*/
|
|
45
|
+
export declare function resolveCapabilityInput({ ref }: {
|
|
46
|
+
ref: string;
|
|
47
|
+
}): Promise<IZcap>;
|
|
48
|
+
/**
|
|
49
|
+
* Resolves a `--capability` reference into a ready-to-use command target:
|
|
50
|
+
* the capability itself, a signed client for the invocation target's
|
|
51
|
+
* server, and the access handle rebuilt at the depth the capability
|
|
52
|
+
* implies.
|
|
53
|
+
*
|
|
54
|
+
* @param options {object}
|
|
55
|
+
* @param options.ref {string} The `--capability` value.
|
|
56
|
+
* @param [options.did] {string} The `--did` flag value (DID or handle);
|
|
57
|
+
* falls back to `WAS_DID`, then the capability's `controller`.
|
|
58
|
+
* @returns {Promise<ResolvedCapabilityTarget>}
|
|
59
|
+
*/
|
|
60
|
+
export declare function resolveCapabilityTarget({ ref, did }: {
|
|
61
|
+
ref: string;
|
|
62
|
+
did?: string;
|
|
63
|
+
}): Promise<ResolvedCapabilityTarget>;
|
|
64
|
+
export {};
|
|
65
|
+
//# sourceMappingURL=capability.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../../src/was/capability.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,UAAU,EACV,QAAQ,EACR,KAAK,EACL,KAAK,EACL,SAAS,EACV,MAAM,qBAAqB,CAAA;AAK5B;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,YAAY,GAAG,UAAU,CAAA;AAEjE;;GAEG;AACH,UAAU,sBAAsB;IAC9B,MAAM,EAAE,SAAS,CAAA;IACjB,IAAI,EAAE,KAAK,CAAA;IACX,4DAA4D;IAC5D,MAAM,EAAE,MAAM,CAAA;IACd,gCAAgC;IAChC,GAAG,EAAE,MAAM,CAAA;IACX,uEAAuE;IACvE,GAAG,EAAE,MAAM,CAAA;CACZ;AAED;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,GAChC,CAAC,sBAAsB,GAAG;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,KAAK,CAAA;CAAE,CAAC,GAC5D,CAAC,sBAAsB,GAAG;IAAE,KAAK,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAE,CAAC,GACtE,CAAC,sBAAsB,GAAG;IAAE,KAAK,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,QAAQ,CAAA;CAAE,CAAC,CAAA;AAiBtE;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAAC,EAC3C,GAAG,EACJ,EAAE;IACD,GAAG,EAAE,MAAM,CAAA;CACZ,GAAG,OAAO,CAAC,KAAK,CAAC,CAuBjB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,uBAAuB,CAAC,EAC5C,GAAG,EACH,GAAG,EACJ,EAAE;IACD,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAuCpC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capability-based addressing for the `was` commands (the receiving side of
|
|
3
|
+
* delegation): resolves a `--capability` reference -- a multibase-encoded
|
|
4
|
+
* capability string, a JSON file path, or the id/handle of a zcap stored in
|
|
5
|
+
* `~/.config/did-cli-wallet/zcaps/` -- and rebuilds a signed access handle from it with
|
|
6
|
+
* `was.fromCapability()`. The capability's `invocationTarget` determines
|
|
7
|
+
* both the server URL (its origin) and the handle depth (space, collection,
|
|
8
|
+
* or resource), so no path argument is needed. The signing DID falls back
|
|
9
|
+
* from `--did` / `WAS_DID` to the capability's `controller` (the delegatee,
|
|
10
|
+
* who is the one invoking it).
|
|
11
|
+
*/
|
|
12
|
+
import { access, readFile } from 'node:fs/promises';
|
|
13
|
+
import { decodeCapability } from '../zcap/encoding.js';
|
|
14
|
+
import { resolveZcapRef } from '../meta.js';
|
|
15
|
+
import { buildWasClient } from './client.js';
|
|
16
|
+
/**
|
|
17
|
+
* Returns true when the path exists on disk.
|
|
18
|
+
*
|
|
19
|
+
* @param filePath {string}
|
|
20
|
+
* @returns {Promise<boolean>}
|
|
21
|
+
*/
|
|
22
|
+
async function fileExists(filePath) {
|
|
23
|
+
try {
|
|
24
|
+
await access(filePath);
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Resolves a `--capability` reference to a capability object. A value
|
|
33
|
+
* beginning with `z` is decoded as a multibase capability string; a path to
|
|
34
|
+
* an existing file is parsed as capability JSON; anything else is looked up
|
|
35
|
+
* in the local zcap store by capability id or metadata handle.
|
|
36
|
+
*
|
|
37
|
+
* @param options {object}
|
|
38
|
+
* @param options.ref {string}
|
|
39
|
+
* @returns {Promise<IZcap>}
|
|
40
|
+
*/
|
|
41
|
+
export async function resolveCapabilityInput({ ref }) {
|
|
42
|
+
if (ref.startsWith('z')) {
|
|
43
|
+
return decodeCapability(ref);
|
|
44
|
+
}
|
|
45
|
+
if (await fileExists(ref)) {
|
|
46
|
+
try {
|
|
47
|
+
return JSON.parse(await readFile(ref, 'utf8'));
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
throw new Error(`${ref} does not contain capability JSON: ` +
|
|
51
|
+
`${err instanceof Error ? err.message : String(err)}`, { cause: err });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const stored = await resolveZcapRef({ ref });
|
|
55
|
+
if (!stored) {
|
|
56
|
+
throw new Error(`No capability found for "${ref}" (not an encoded string, a file, ` +
|
|
57
|
+
'or a stored zcap id/handle).');
|
|
58
|
+
}
|
|
59
|
+
return stored.zcap;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Resolves a `--capability` reference into a ready-to-use command target:
|
|
63
|
+
* the capability itself, a signed client for the invocation target's
|
|
64
|
+
* server, and the access handle rebuilt at the depth the capability
|
|
65
|
+
* implies.
|
|
66
|
+
*
|
|
67
|
+
* @param options {object}
|
|
68
|
+
* @param options.ref {string} The `--capability` value.
|
|
69
|
+
* @param [options.did] {string} The `--did` flag value (DID or handle);
|
|
70
|
+
* falls back to `WAS_DID`, then the capability's `controller`.
|
|
71
|
+
* @returns {Promise<ResolvedCapabilityTarget>}
|
|
72
|
+
*/
|
|
73
|
+
export async function resolveCapabilityTarget({ ref, did }) {
|
|
74
|
+
const zcap = await resolveCapabilityInput({ ref });
|
|
75
|
+
if (!zcap.invocationTarget) {
|
|
76
|
+
throw new Error(`The capability "${ref}" has no invocationTarget.`);
|
|
77
|
+
}
|
|
78
|
+
const url = zcap.invocationTarget;
|
|
79
|
+
let server;
|
|
80
|
+
try {
|
|
81
|
+
server = new URL(url).origin;
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
throw new Error(`The capability's invocationTarget is not a valid URL: ${url}`, { cause: err });
|
|
85
|
+
}
|
|
86
|
+
const didRef = did ??
|
|
87
|
+
process.env.WAS_DID ??
|
|
88
|
+
(typeof zcap.controller === 'string' ? zcap.controller : undefined);
|
|
89
|
+
if (!didRef) {
|
|
90
|
+
throw new Error('No signing DID for the capability: provide --did or WAS_DID.');
|
|
91
|
+
}
|
|
92
|
+
const { client, did: resolvedDid } = await buildWasClient({
|
|
93
|
+
server,
|
|
94
|
+
did: didRef
|
|
95
|
+
});
|
|
96
|
+
const handle = client.fromCapability(zcap);
|
|
97
|
+
const base = { client, zcap, server, did: resolvedDid, url };
|
|
98
|
+
// The handle's own shape implies the depth: a Resource carries
|
|
99
|
+
// `collectionId`, a Collection carries `spaceId`, a Space carries neither.
|
|
100
|
+
if ('collectionId' in handle) {
|
|
101
|
+
return { ...base, depth: 'resource', handle };
|
|
102
|
+
}
|
|
103
|
+
if ('spaceId' in handle) {
|
|
104
|
+
return { ...base, depth: 'collection', handle };
|
|
105
|
+
}
|
|
106
|
+
return { ...base, depth: 'space', handle };
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=capability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capability.js","sourceRoot":"","sources":["../../src/was/capability.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAQnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAgC5C;;;;;GAKG;AACH,KAAK,UAAU,UAAU,CAAC,QAAgB;IACxC,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAA;QACtB,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,EAC3C,GAAG,EAGJ;IACC,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,C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OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,yDAAyD,GAAG,EAAE,EAC9D,EAAE,KAAK,EAAE,GAAG,EAAE,CACf,CAAA;IACH,CAAC;IACD,MAAM,MAAM,GACV,GAAG;QACH,OAAO,CAAC,GAAG,CAAC,OAAO;QACnB,CAAC,OAAO,IAAI,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IACrE,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,8DAA8D,CAC/D,CAAA;IACH,CAAC;IACD,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,MAAM,cAAc,CAAC;QACxD,MAAM;QACN,GAAG,EAAE,MAAM;KACZ,CAAC,CAAA;IACF,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAA;IAC1C,MAAM,IAAI,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,CAAA;IAC5D,+DAA+D;IAC/D,2EAA2E;IAC3E,IAAI,cAAc,IAAI,MAAM,EAAE,CAAC;QAC7B,OAAO,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,CAAA;IAC/C,CAAC;IACD,IAAI,SAAS,IAAI,MAAM,EAAE,CAAC;QACxB,OAAO,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,CAAA;IACjD,CAAC;IACD,OAAO,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,CAAA;AAC5C,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds a `WasClient` from a DID stored in the local wallet plus a server
|
|
3
|
+
* URL, resolving both from flags, environment variables, and the local space
|
|
4
|
+
* registry. The signing DID resolution order is the `--did` flag (a DID or a
|
|
5
|
+
* metadata handle), then the `WAS_DID` environment variable, then the
|
|
6
|
+
* `controller` recorded in the registry entry for the addressed space. The
|
|
7
|
+
* server URL resolution order is the origin of a full space URL address,
|
|
8
|
+
* then the `--server` flag, then `WAS_SERVER_URL`, then the `server`
|
|
9
|
+
* recorded in the registry entry.
|
|
10
|
+
*
|
|
11
|
+
* Only locally stored `did:key` DIDs with Ed25519 keys are supported for
|
|
12
|
+
* signing (the constraint of the `Ed25519Signature2020` zcap suite used by
|
|
13
|
+
* `@interop/was-client`).
|
|
14
|
+
*/
|
|
15
|
+
import { WasClient } from '@interop/was-client';
|
|
16
|
+
import type { ISigner } from '@interop/data-integrity-core';
|
|
17
|
+
import { type ItemMetadata } from '../storage.js';
|
|
18
|
+
import { type SpaceRecord } from './registry.js';
|
|
19
|
+
/**
|
|
20
|
+
* Constructs the `WasClient` for a resolved server URL and signer. Kept as a
|
|
21
|
+
* replaceable factory so command tests can substitute a stubbed client (no
|
|
22
|
+
* network) while exercising the full resolution path.
|
|
23
|
+
*/
|
|
24
|
+
type WasClientFactory = (options: {
|
|
25
|
+
serverUrl: string;
|
|
26
|
+
signer: ISigner;
|
|
27
|
+
}) => WasClient;
|
|
28
|
+
/**
|
|
29
|
+
* Replaces the `WasClient` construction step (a test-only seam). Call with
|
|
30
|
+
* no argument to restore the default factory.
|
|
31
|
+
*
|
|
32
|
+
* @param [factory] {WasClientFactory}
|
|
33
|
+
* @returns {void}
|
|
34
|
+
*/
|
|
35
|
+
export declare function setWasClientFactory(factory?: WasClientFactory): void;
|
|
36
|
+
/**
|
|
37
|
+
* A fully resolved WAS command target: the client to talk to the server
|
|
38
|
+
* with, the resolved server URL and signing DID, the addressed space /
|
|
39
|
+
* collection / resource ids, and the local registry entry for the space
|
|
40
|
+
* (when one exists).
|
|
41
|
+
*/
|
|
42
|
+
export interface ResolvedWasTarget {
|
|
43
|
+
client: WasClient;
|
|
44
|
+
server: string;
|
|
45
|
+
did: string;
|
|
46
|
+
spaceId: string;
|
|
47
|
+
collectionId?: string;
|
|
48
|
+
resourceId?: string;
|
|
49
|
+
entry?: {
|
|
50
|
+
storageId: string;
|
|
51
|
+
record: SpaceRecord;
|
|
52
|
+
meta?: ItemMetadata;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Loads the WAS invocation signer from a locally stored DID. Only `did:key`
|
|
57
|
+
* DIDs with Ed25519 keys are supported; anything else is rejected with a
|
|
58
|
+
* clear error.
|
|
59
|
+
*
|
|
60
|
+
* @param options {object}
|
|
61
|
+
* @param options.did {string} A DID or the metadata handle of a stored DID.
|
|
62
|
+
* @returns {Promise<{did: string, signer: ISigner}>}
|
|
63
|
+
*/
|
|
64
|
+
export declare function loadWasSigner({ did }: {
|
|
65
|
+
did: string;
|
|
66
|
+
}): Promise<{
|
|
67
|
+
did: string;
|
|
68
|
+
signer: ISigner;
|
|
69
|
+
}>;
|
|
70
|
+
/**
|
|
71
|
+
* Builds a `WasClient` from an explicit server URL and signing DID,
|
|
72
|
+
* falling back to the `WAS_SERVER_URL` and `WAS_DID` environment variables.
|
|
73
|
+
* Used by commands that do not address an existing space (e.g.
|
|
74
|
+
* `was space create`).
|
|
75
|
+
*
|
|
76
|
+
* @param options {object}
|
|
77
|
+
* @param [options.server] {string} The server base URL.
|
|
78
|
+
* @param [options.did] {string} A DID or stored-DID metadata handle.
|
|
79
|
+
* @returns {Promise<{client: WasClient, server: string, did: string}>}
|
|
80
|
+
*/
|
|
81
|
+
export declare function buildWasClient({ server, did }?: {
|
|
82
|
+
server?: string;
|
|
83
|
+
did?: string;
|
|
84
|
+
}): Promise<{
|
|
85
|
+
client: WasClient;
|
|
86
|
+
server: string;
|
|
87
|
+
did: string;
|
|
88
|
+
}>;
|
|
89
|
+
/**
|
|
90
|
+
* Resolves a WAS address into a ready-to-use command target: parses the
|
|
91
|
+
* `SPACE[/COLLECTION[/RESOURCE]]` path, consults the local space registry
|
|
92
|
+
* for the space reference (handle or id), resolves the server URL and
|
|
93
|
+
* signing DID from the flags / environment / registry entry, and builds the
|
|
94
|
+
* signed `WasClient`.
|
|
95
|
+
*
|
|
96
|
+
* @param options {object}
|
|
97
|
+
* @param options.address {string} The positional WAS path.
|
|
98
|
+
* @param [options.server] {string} The `--server` flag value.
|
|
99
|
+
* @param [options.did] {string} The `--did` flag value (DID or handle).
|
|
100
|
+
* @returns {Promise<ResolvedWasTarget>}
|
|
101
|
+
*/
|
|
102
|
+
export declare function resolveWasTarget({ address, server, did }: {
|
|
103
|
+
address: string;
|
|
104
|
+
server?: string;
|
|
105
|
+
did?: string;
|
|
106
|
+
}): Promise<ResolvedWasTarget>;
|
|
107
|
+
export {};
|
|
108
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/was/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAG/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAC3D,OAAO,EAAgC,KAAK,YAAY,EAAE,MAAM,eAAe,CAAA;AAG/E,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,eAAe,CAAA;AAEjE;;;;GAIG;AACH,KAAK,gBAAgB,GAAG,CAAC,OAAO,EAAE;IAChC,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,OAAO,CAAA;CAChB,KAAK,SAAS,CAAA;AAcf;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAEpE;AAaD;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,SAAS,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,EAA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