@interop/did-cli 0.13.0 → 0.15.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 +166 -6
- package/README.md +172 -26
- package/dist/commands/did/create.d.ts +22 -0
- package/dist/commands/did/create.d.ts.map +1 -1
- package/dist/commands/did/create.js +6 -27
- package/dist/commands/did/create.js.map +1 -1
- package/dist/commands/did/service.d.ts +19 -4
- package/dist/commands/did/service.d.ts.map +1 -1
- package/dist/commands/did/service.js +46 -45
- package/dist/commands/did/service.js.map +1 -1
- package/dist/commands/did/webvh-update.d.ts +72 -9
- package/dist/commands/did/webvh-update.d.ts.map +1 -1
- package/dist/commands/did/webvh-update.js +177 -61
- package/dist/commands/did/webvh-update.js.map +1 -1
- package/dist/commands/did.d.ts.map +1 -1
- package/dist/commands/did.js +10 -1
- package/dist/commands/did.js.map +1 -1
- package/dist/commands/key.d.ts.map +1 -1
- package/dist/commands/key.js +5 -8
- package/dist/commands/key.js.map +1 -1
- package/dist/commands/was/request-grant.d.ts +39 -0
- package/dist/commands/was/request-grant.d.ts.map +1 -0
- package/dist/commands/was/request-grant.js +250 -0
- package/dist/commands/was/request-grant.js.map +1 -0
- package/dist/commands/was/resource.d.ts +21 -7
- package/dist/commands/was/resource.d.ts.map +1 -1
- package/dist/commands/was/resource.js +40 -15
- package/dist/commands/was/resource.js.map +1 -1
- package/dist/commands/was/shared.d.ts +43 -3
- package/dist/commands/was/shared.d.ts.map +1 -1
- package/dist/commands/was/shared.js +82 -4
- package/dist/commands/was/shared.js.map +1 -1
- package/dist/commands/was/shell/completer.d.ts +24 -0
- package/dist/commands/was/shell/completer.d.ts.map +1 -0
- package/dist/commands/was/shell/completer.js +99 -0
- package/dist/commands/was/shell/completer.js.map +1 -0
- package/dist/commands/was/shell/dispatcher.d.ts +27 -0
- package/dist/commands/was/shell/dispatcher.d.ts.map +1 -0
- package/dist/commands/was/shell/dispatcher.js +227 -0
- package/dist/commands/was/shell/dispatcher.js.map +1 -0
- package/dist/commands/was/shell/session.d.ts +37 -0
- package/dist/commands/was/shell/session.d.ts.map +1 -0
- package/dist/commands/was/shell/session.js +67 -0
- package/dist/commands/was/shell/session.js.map +1 -0
- package/dist/commands/was/shell/tokenize.d.ts +19 -0
- package/dist/commands/was/shell/tokenize.d.ts.map +1 -0
- package/dist/commands/was/shell/tokenize.js +77 -0
- package/dist/commands/was/shell/tokenize.js.map +1 -0
- package/dist/commands/was/shell.d.ts +30 -0
- package/dist/commands/was/shell.d.ts.map +1 -0
- package/dist/commands/was/shell.js +170 -0
- package/dist/commands/was/shell.js.map +1 -0
- package/dist/commands/was/tree.d.ts +6 -1
- package/dist/commands/was/tree.d.ts.map +1 -1
- package/dist/commands/was/tree.js +12 -5
- package/dist/commands/was/tree.js.map +1 -1
- package/dist/commands/was.d.ts.map +1 -1
- package/dist/commands/was.js +34 -1
- package/dist/commands/was.js.map +1 -1
- package/dist/commands/zcap.d.ts +22 -2
- package/dist/commands/zcap.d.ts.map +1 -1
- package/dist/commands/zcap.js +75 -4
- package/dist/commands/zcap.js.map +1 -1
- package/dist/keys/seed.d.ts +21 -0
- package/dist/keys/seed.d.ts.map +1 -0
- package/dist/keys/seed.js +41 -0
- package/dist/keys/seed.js.map +1 -0
- package/dist/keys/webvh-signer.d.ts +18 -13
- package/dist/keys/webvh-signer.d.ts.map +1 -1
- package/dist/keys/webvh-signer.js +5 -20
- package/dist/keys/webvh-signer.js.map +1 -1
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +57 -10
- package/dist/storage.js.map +1 -1
- package/dist/was/address.d.ts +24 -0
- package/dist/was/address.d.ts.map +1 -1
- package/dist/was/address.js +49 -3
- package/dist/was/address.js.map +1 -1
- package/dist/was/capability.d.ts.map +1 -1
- package/dist/was/capability.js +4 -1
- package/dist/was/capability.js.map +1 -1
- package/dist/was/client.d.ts +10 -3
- package/dist/was/client.d.ts.map +1 -1
- package/dist/was/client.js +27 -6
- package/dist/was/client.js.map +1 -1
- package/dist/was/request-grant.d.ts +147 -0
- package/dist/was/request-grant.d.ts.map +1 -0
- package/dist/was/request-grant.js +256 -0
- package/dist/was/request-grant.js.map +1 -0
- package/dist/zcap/create.d.ts +1 -1
- package/dist/zcap/create.js +1 -1
- package/dist/zcap/delegate.d.ts +1 -1
- package/dist/zcap/delegate.js +1 -1
- package/dist/zcap/encoding.d.ts +17 -5
- package/dist/zcap/encoding.d.ts.map +1 -1
- package/dist/zcap/encoding.js +31 -17
- package/dist/zcap/encoding.js.map +1 -1
- package/dist/zcap/resolve.d.ts +17 -4
- package/dist/zcap/resolve.d.ts.map +1 -1
- package/dist/zcap/resolve.js +25 -8
- package/dist/zcap/resolve.js.map +1 -1
- package/package.json +22 -20
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The requesting half of capability delegation (`was request-grant`), the
|
|
3
|
+
* inverse of `was grant`. Instead of signing a capability for someone else,
|
|
4
|
+
* this asks a user's wallet to sign one for us: it builds a zcap-only
|
|
5
|
+
* Verifiable Presentation Request (VPR), opens an ephemeral exchange on the
|
|
6
|
+
* WAS server to carry it, and waits for the wallet to post back a response
|
|
7
|
+
* presentation holding the delegated capabilities.
|
|
8
|
+
*
|
|
9
|
+
* Nothing here is signed. The exchange routes are unauthenticated by design --
|
|
10
|
+
* the exchange URL is itself the secret, and it travels point-to-point to the
|
|
11
|
+
* user (today as a printed interaction URL). Both the exchange transport and
|
|
12
|
+
* the zcap-only VPR composition come from `@interop/wallet-request`; what
|
|
13
|
+
* is owned here is the CLI's own request shape (the public-collection
|
|
14
|
+
* descriptor and the action normalization) and the response parsing.
|
|
15
|
+
*/
|
|
16
|
+
import { composeCapabilityRequest, createEphemeralExchange, pollEphemeralExchange, EPHEMERAL_EXCHANGE_TTL_MS } from '@interop/wallet-request';
|
|
17
|
+
/**
|
|
18
|
+
* The wallet-defined descriptor for a world-readable collection under the
|
|
19
|
+
* user's own Space. Naming a descriptor rather than a URL is what lets the
|
|
20
|
+
* request be written before the Space exists: the wallet resolves it to one of
|
|
21
|
+
* its own collections at consent time.
|
|
22
|
+
*/
|
|
23
|
+
export const PUBLIC_COLLECTION_TYPE = 'https://w3id.org/byoe#public-collection';
|
|
24
|
+
/** The collection the request names when `--collection` is not given. */
|
|
25
|
+
export const DEFAULT_COLLECTION = 'web';
|
|
26
|
+
/** The actions the request asks for when `--action` is not given. */
|
|
27
|
+
export const DEFAULT_ACTIONS = ['GET', 'HEAD', 'PUT', 'POST'];
|
|
28
|
+
/**
|
|
29
|
+
* The actions a capability request may name. A superset of the verbs
|
|
30
|
+
* `was grant` signs (it adds `HEAD`), because the wallet -- not this CLI -- is
|
|
31
|
+
* the authority on what it is willing to delegate.
|
|
32
|
+
*/
|
|
33
|
+
const REQUESTABLE_ACTIONS = ['GET', 'HEAD', 'PUT', 'POST', 'DELETE'];
|
|
34
|
+
/**
|
|
35
|
+
* How long to wait for the user to approve before giving up: the server's
|
|
36
|
+
* exchange TTL, since past it the exchange is gone and no approval can arrive.
|
|
37
|
+
*/
|
|
38
|
+
export const DEFAULT_TIMEOUT_MS = EPHEMERAL_EXCHANGE_TTL_MS;
|
|
39
|
+
/**
|
|
40
|
+
* The largest wait the poll's deadline accepts (a `setTimeout` delay, which is
|
|
41
|
+
* truncated to a signed 32-bit value and would otherwise fire at once).
|
|
42
|
+
* Anything past this is rejected as bad input rather than left to fail deep
|
|
43
|
+
* inside the poll.
|
|
44
|
+
*/
|
|
45
|
+
export const MAX_TIMEOUT_MS = 2_147_483_647;
|
|
46
|
+
/**
|
|
47
|
+
* Raised when the exchange itself ran but produced no grant: the user declined,
|
|
48
|
+
* let it expire, or approved a request the wallet could not satisfy. These are
|
|
49
|
+
* operation failures rather than bad input, and the command reports them as
|
|
50
|
+
* such. Internal to this package; nothing dispatches on the name across a
|
|
51
|
+
* package boundary.
|
|
52
|
+
*/
|
|
53
|
+
export class GrantRequestError extends Error {
|
|
54
|
+
}
|
|
55
|
+
let exchangeFetch;
|
|
56
|
+
/**
|
|
57
|
+
* Replaces the `fetch` the exchange helpers transport over (a test-only seam,
|
|
58
|
+
* mirroring `setWasClientFactory`). Call with no argument to restore the
|
|
59
|
+
* global `fetch`.
|
|
60
|
+
*
|
|
61
|
+
* @param [fetchImpl] {FetchLike}
|
|
62
|
+
* @returns {void}
|
|
63
|
+
*/
|
|
64
|
+
export function setExchangeFetch(fetchImpl) {
|
|
65
|
+
exchangeFetch = fetchImpl;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Normalizes requested action verbs to their canonical uppercase form,
|
|
69
|
+
* rejecting anything that is not an HTTP verb a WAS server matches against.
|
|
70
|
+
*
|
|
71
|
+
* @param actions {string[]}
|
|
72
|
+
* @returns {string[]}
|
|
73
|
+
*/
|
|
74
|
+
function normalizeRequestedActions(actions) {
|
|
75
|
+
return actions.map(action => {
|
|
76
|
+
const verb = action.toUpperCase();
|
|
77
|
+
if (!REQUESTABLE_ACTIONS.includes(verb)) {
|
|
78
|
+
throw new Error(`Unknown action "${action}" (supported: ` +
|
|
79
|
+
`${REQUESTABLE_ACTIONS.join(', ')}).`);
|
|
80
|
+
}
|
|
81
|
+
return verb;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Builds the zcap-only VPR this command sends: one capability query naming the
|
|
86
|
+
* agent as the capability `controller` and a public-collection descriptor as
|
|
87
|
+
* the target, plus an optional root `agent` member naming what the agent
|
|
88
|
+
* calls itself, composed by wallet-core. There is deliberately no
|
|
89
|
+
* `DIDAuthentication` query and no `domain` -- the agent is asking for
|
|
90
|
+
* authority, not proving who it is to a verifier, and a CLI has no attested
|
|
91
|
+
* origin for a wallet to check a domain against (one sent anyway is enforced,
|
|
92
|
+
* and fails).
|
|
93
|
+
*
|
|
94
|
+
* @param options {object}
|
|
95
|
+
* @param options.controller {string} The agent's did:key (the grantee).
|
|
96
|
+
* @param [options.collection] {string} The collection name to request.
|
|
97
|
+
* @param [options.actions] {string[]} The actions to request.
|
|
98
|
+
* @param [options.reason] {string} Human-readable text shown at consent.
|
|
99
|
+
* @param [options.name] {string} The agent's self-declared display name,
|
|
100
|
+
* shown at consent as what it calls itself.
|
|
101
|
+
* @returns {IVPRDetails}
|
|
102
|
+
*/
|
|
103
|
+
export function buildCapabilityRequest({ controller, collection = DEFAULT_COLLECTION, actions = DEFAULT_ACTIONS, reason, name }) {
|
|
104
|
+
const capabilityQuery = {
|
|
105
|
+
...(reason !== undefined && { reason }),
|
|
106
|
+
allowedAction: normalizeRequestedActions(actions),
|
|
107
|
+
controller,
|
|
108
|
+
invocationTarget: {
|
|
109
|
+
type: PUBLIC_COLLECTION_TYPE,
|
|
110
|
+
name: collection
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
return composeCapabilityRequest({
|
|
114
|
+
capabilityQueries: [capabilityQuery],
|
|
115
|
+
...(name !== undefined && { agent: { name } })
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The wallet route an outside request is handed to. Requests arriving from
|
|
120
|
+
* outside the app land under `/external/`; `/wallet/*` stays CHAPI-handler
|
|
121
|
+
* only. The wallet routes on the URL fragment, so the route (and the query it
|
|
122
|
+
* carries) lives after `#`.
|
|
123
|
+
*/
|
|
124
|
+
const WALLET_REQUEST_ROUTE = '/external/request';
|
|
125
|
+
/**
|
|
126
|
+
* Resolves a wallet base URL to its external-request route, rejecting anything
|
|
127
|
+
* that is not an absolute http(s) URL. Kept separate from the link itself so a
|
|
128
|
+
* bad `--wallet` is caught before an exchange is opened for it.
|
|
129
|
+
*
|
|
130
|
+
* @param options {object}
|
|
131
|
+
* @param options.wallet {string} The wallet's base URL.
|
|
132
|
+
* @returns {URL} The base URL with the route as its fragment.
|
|
133
|
+
*/
|
|
134
|
+
export function walletRequestRoute({ wallet }) {
|
|
135
|
+
let base;
|
|
136
|
+
try {
|
|
137
|
+
base = new URL(wallet);
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
throw new Error(`Invalid wallet URL "${wallet}": expected an absolute http(s) URL.`, { cause: err });
|
|
141
|
+
}
|
|
142
|
+
if (base.protocol !== 'https:' && base.protocol !== 'http:') {
|
|
143
|
+
throw new Error(`Invalid wallet URL "${wallet}": expected an http(s) URL, got ` +
|
|
144
|
+
`"${base.protocol}".`);
|
|
145
|
+
}
|
|
146
|
+
// Keep the base path (a wallet deployed under a sub-path keeps its prefix)
|
|
147
|
+
// and hang the route off it as the fragment.
|
|
148
|
+
const path = base.pathname.endsWith('/') ? base.pathname : `${base.pathname}/`;
|
|
149
|
+
const route = new URL(path, base);
|
|
150
|
+
route.hash = WALLET_REQUEST_ROUTE;
|
|
151
|
+
return route;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Builds the link that opens a wallet straight onto the approval page for an
|
|
155
|
+
* exchange, for the case where the user is already at a browser: the wallet's
|
|
156
|
+
* external-request route carrying the interaction URL as a percent-encoded
|
|
157
|
+
* `url` parameter. The parameter goes inside the fragment, after the route,
|
|
158
|
+
* because that is the only part of the URL a fragment-routed wallet reads.
|
|
159
|
+
* The interaction URL alone stays the fallback, since it is what a wallet on
|
|
160
|
+
* another device can be pointed at.
|
|
161
|
+
*
|
|
162
|
+
* @param options {object}
|
|
163
|
+
* @param options.route {URL} The wallet's external-request route.
|
|
164
|
+
* @param options.interactionUrl {string} The exchange's interaction URL.
|
|
165
|
+
* @returns {string}
|
|
166
|
+
*/
|
|
167
|
+
export function buildWalletDeepLink({ route, interactionUrl }) {
|
|
168
|
+
const link = new URL(route);
|
|
169
|
+
const params = new URLSearchParams({ url: interactionUrl });
|
|
170
|
+
link.hash = `${route.hash.slice(1)}?${params.toString()}`;
|
|
171
|
+
return link.toString();
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Opens an ephemeral exchange on the WAS server carrying the request, and
|
|
175
|
+
* returns both the URL to poll and the interaction URL to hand the user.
|
|
176
|
+
*
|
|
177
|
+
* @param options {object}
|
|
178
|
+
* @param options.exchange {string} Base URL of the WAS server hosting the
|
|
179
|
+
* exchange.
|
|
180
|
+
* @param options.request {IVPRDetails} The VPR to store on the exchange.
|
|
181
|
+
* @returns {Promise<{exchangeUrl: string, interactionUrl: string}>}
|
|
182
|
+
*/
|
|
183
|
+
export async function openGrantExchange({ exchange, request }) {
|
|
184
|
+
return createEphemeralExchange({
|
|
185
|
+
serverUrl: exchange,
|
|
186
|
+
request,
|
|
187
|
+
...(exchangeFetch && { fetch: exchangeFetch })
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Pulls the delegated capabilities out of a completed exchange response. The
|
|
192
|
+
* wallet posts `{ verifiablePresentation }`, and the zcaps ride inside that
|
|
193
|
+
* presentation as its `zcap` member.
|
|
194
|
+
*
|
|
195
|
+
* @param response {unknown} The exchange's `response` member.
|
|
196
|
+
* @returns {IZcap[]}
|
|
197
|
+
*/
|
|
198
|
+
export function extractCapabilities(response) {
|
|
199
|
+
const presentation = response?.verifiablePresentation;
|
|
200
|
+
if (!presentation) {
|
|
201
|
+
throw new GrantRequestError('The wallet response contained no verifiablePresentation.');
|
|
202
|
+
}
|
|
203
|
+
const { zcap } = presentation;
|
|
204
|
+
const zcaps = zcap === undefined ? [] : Array.isArray(zcap) ? zcap : [zcap];
|
|
205
|
+
for (const capability of zcaps) {
|
|
206
|
+
if (typeof capability.id !== 'string' || capability.id === '') {
|
|
207
|
+
throw new GrantRequestError('The wallet returned a capability with no id, which cannot be filed ' +
|
|
208
|
+
'in the zcap store or named by a later --capability.');
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (zcaps.length === 0) {
|
|
212
|
+
throw new GrantRequestError('The wallet returned a presentation with no capabilities: the request ' +
|
|
213
|
+
'was declined, or the collection could not be granted (a public ' +
|
|
214
|
+
'collection is only ever created public, never converted from an ' +
|
|
215
|
+
'existing private one).');
|
|
216
|
+
}
|
|
217
|
+
return zcaps;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Waits for the user's wallet to complete the exchange, and returns the
|
|
221
|
+
* capabilities it delegated. Gives up at `timeoutMs`, and distinguishes an
|
|
222
|
+
* exchange the server has already dropped from one still waiting on the user.
|
|
223
|
+
*
|
|
224
|
+
* @param options {object}
|
|
225
|
+
* @param options.exchangeUrl {string}
|
|
226
|
+
* @param [options.timeoutMs] {number}
|
|
227
|
+
* @param [options.intervalMs] {number} How often to poll.
|
|
228
|
+
* @returns {Promise<IZcap[]>}
|
|
229
|
+
*/
|
|
230
|
+
export async function awaitGrantedCapabilities({ exchangeUrl, timeoutMs = DEFAULT_TIMEOUT_MS, intervalMs }) {
|
|
231
|
+
let response;
|
|
232
|
+
try {
|
|
233
|
+
response = await pollEphemeralExchange({
|
|
234
|
+
exchangeUrl,
|
|
235
|
+
timeoutMs,
|
|
236
|
+
...(intervalMs !== undefined && { intervalMs }),
|
|
237
|
+
...(exchangeFetch && { fetch: exchangeFetch })
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
catch (err) {
|
|
241
|
+
// The transport is injected and may resolve to a different copy of
|
|
242
|
+
// wallet-core, so the error name is the stable contract here.
|
|
243
|
+
if (err.name === 'EphemeralExchangeGoneError') {
|
|
244
|
+
throw new GrantRequestError('The request expired before it was approved (the server keeps an ' +
|
|
245
|
+
'exchange for ten minutes). Run the command again for a fresh link.', { cause: err });
|
|
246
|
+
}
|
|
247
|
+
if (err.name === 'EphemeralExchangeTimeoutError') {
|
|
248
|
+
throw new GrantRequestError(`Gave up waiting for approval after ${Math.round(timeoutMs / 1000)}s. ` +
|
|
249
|
+
'The request may still be approvable; raise --timeout, or run the ' +
|
|
250
|
+
'command again for a fresh link.', { cause: err });
|
|
251
|
+
}
|
|
252
|
+
throw err;
|
|
253
|
+
}
|
|
254
|
+
return extractCapabilities(response);
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=request-grant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-grant.js","source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AA;QACH,CAAC;QACD,IAAK,GAAa,CAAC,IAAI,KAAK,+BAA+B,EAAE,CAAC;YAC5D,MAAM,IAAI,iBAAiB,CACzB,sCAAsC,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK;gBACrE,mEAAmE;gBACnE,iCAAiC,EACnC,EAAE,KAAK,EAAE,GAAG,EAAE,CACf,CAAA;QACH,CAAC;QACD,MAAM,GAAG,CAAA;IACX,CAAC;IACD,OAAO,mBAAmB,CAAC,QAAQ,CAAC,CAAA;AACtC,CAAC"}
|
package/dist/zcap/create.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { IRootZcap } from '@interop/data-integrity-core/zcap';
|
|
|
8
8
|
* @param options.url {string} The resource URI the capability targets (the
|
|
9
9
|
* `invocationTarget`).
|
|
10
10
|
* @returns {{rootCapability: IRootZcap, encoded: string}} The root capability
|
|
11
|
-
* and its multibase (
|
|
11
|
+
* and its multibase (base64url) encoding.
|
|
12
12
|
*/
|
|
13
13
|
export declare function createCapability({ controller, url }: {
|
|
14
14
|
controller: string;
|
package/dist/zcap/create.js
CHANGED
|
@@ -17,7 +17,7 @@ import { encodeCapability } from './encoding.js';
|
|
|
17
17
|
* @param options.url {string} The resource URI the capability targets (the
|
|
18
18
|
* `invocationTarget`).
|
|
19
19
|
* @returns {{rootCapability: IRootZcap, encoded: string}} The root capability
|
|
20
|
-
* and its multibase (
|
|
20
|
+
* and its multibase (base64url) encoding.
|
|
21
21
|
*/
|
|
22
22
|
export function createCapability({ controller, url }) {
|
|
23
23
|
const rootCapability = createRootCapability({
|
package/dist/zcap/delegate.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ import type { IDelegatedZcap, IZcap } from '@interop/data-integrity-core/zcap';
|
|
|
25
25
|
* @param [options.expires] {string} Explicit ISO 8601 expiration (overrides
|
|
26
26
|
* `ttl`).
|
|
27
27
|
* @returns {Promise<{delegatedCapability: IDelegatedZcap, encoded: string}>}
|
|
28
|
-
* The signed delegated capability and its multibase (
|
|
28
|
+
* The signed delegated capability and its multibase (base64url) encoding.
|
|
29
29
|
*/
|
|
30
30
|
export declare function delegateCapability({ did, controller, delegatee, url, capability, invocationTarget, allow, ttl, expires }: {
|
|
31
31
|
did?: string;
|
package/dist/zcap/delegate.js
CHANGED
|
@@ -46,7 +46,7 @@ import { loadDelegationSigner } from './signer.js';
|
|
|
46
46
|
* @param [options.expires] {string} Explicit ISO 8601 expiration (overrides
|
|
47
47
|
* `ttl`).
|
|
48
48
|
* @returns {Promise<{delegatedCapability: IDelegatedZcap, encoded: string}>}
|
|
49
|
-
* The signed delegated capability and its multibase (
|
|
49
|
+
* The signed delegated capability and its multibase (base64url) encoding.
|
|
50
50
|
*/
|
|
51
51
|
export async function delegateCapability({ did, controller, delegatee, url, capability, invocationTarget, allow, ttl = '1y', expires }) {
|
|
52
52
|
const delegationSigner = await loadDelegationSigner({ did, controller });
|
package/dist/zcap/encoding.d.ts
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
import type { IZcap } from '@interop/data-integrity-core/zcap';
|
|
2
2
|
/**
|
|
3
|
-
* Encodes a capability as a multibase (
|
|
3
|
+
* Encodes a capability as a multibase (base64url, no padding) string.
|
|
4
4
|
*
|
|
5
5
|
* @param capability {IZcap} The root or delegated capability to encode.
|
|
6
|
-
* @returns {string} The capability JSON,
|
|
6
|
+
* @returns {string} The capability JSON, base64url-encoded with a leading
|
|
7
|
+
* `u`.
|
|
7
8
|
*/
|
|
8
9
|
export declare function encodeCapability(capability: IZcap): string;
|
|
9
10
|
/**
|
|
10
|
-
*
|
|
11
|
+
* Tells whether a `--capability` value is an encoded capability rather than a
|
|
12
|
+
* file path or a stored id/handle. The `u` form is base64url of JSON that
|
|
13
|
+
* always opens with `{"`, so it always begins `ueyJ`; checking that prefix is
|
|
14
|
+
* what keeps a `urn:` capability id (which also begins with `u`) out of the
|
|
15
|
+
* decoder.
|
|
11
16
|
*
|
|
12
|
-
* @param
|
|
13
|
-
*
|
|
17
|
+
* @param value {string}
|
|
18
|
+
* @returns {boolean}
|
|
19
|
+
*/
|
|
20
|
+
export declare function isEncodedCapability(value: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Decodes a multibase (base64url, `u` prefix) capability string back into a
|
|
23
|
+
* capability.
|
|
24
|
+
*
|
|
25
|
+
* @param encoded {string} A `u`-prefixed multibase string.
|
|
14
26
|
* @returns {IZcap} The decoded root or delegated capability.
|
|
15
27
|
*/
|
|
16
28
|
export declare function decodeCapability(encoded: string): IZcap;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../../src/zcap/encoding.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAA;AAE9D
|
|
1
|
+
{"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../../src/zcap/encoding.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAA;AAE9D;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,KAAK,GAAG,MAAM,CAG1D;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAQvD"}
|
package/dist/zcap/encoding.js
CHANGED
|
@@ -1,37 +1,51 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Multibase
|
|
2
|
+
* Multibase encoding for Authorization Capabilities (zcaps).
|
|
3
3
|
*
|
|
4
4
|
* The CLI prints an `encoded` form alongside each capability: the capability's
|
|
5
|
-
* JSON serialized to UTF-8 bytes,
|
|
6
|
-
* multibase prefix
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
5
|
+
* JSON serialized to UTF-8 bytes, base64url-encoded without padding, with a
|
|
6
|
+
* leading `u` multibase prefix. `decodeCapability` reverses this so a
|
|
7
|
+
* delegated capability can be passed back in via `--capability`. base64url
|
|
8
|
+
* rather than base58btc because a delegated capability embeds its whole
|
|
9
|
+
* chain, and base58 is quadratic in the input size, so `@scure/base` refuses
|
|
10
|
+
* it past 2048 bytes -- smaller than a two-hop chain a wallet delegates.
|
|
11
11
|
*/
|
|
12
|
-
import {
|
|
12
|
+
import { base64urlnopad } from '@scure/base';
|
|
13
13
|
/**
|
|
14
|
-
* Encodes a capability as a multibase (
|
|
14
|
+
* Encodes a capability as a multibase (base64url, no padding) string.
|
|
15
15
|
*
|
|
16
16
|
* @param capability {IZcap} The root or delegated capability to encode.
|
|
17
|
-
* @returns {string} The capability JSON,
|
|
17
|
+
* @returns {string} The capability JSON, base64url-encoded with a leading
|
|
18
|
+
* `u`.
|
|
18
19
|
*/
|
|
19
20
|
export function encodeCapability(capability) {
|
|
20
21
|
const bytes = new TextEncoder().encode(JSON.stringify(capability));
|
|
21
|
-
return `
|
|
22
|
+
return `u${base64urlnopad.encode(bytes)}`;
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
|
-
*
|
|
25
|
+
* Tells whether a `--capability` value is an encoded capability rather than a
|
|
26
|
+
* file path or a stored id/handle. The `u` form is base64url of JSON that
|
|
27
|
+
* always opens with `{"`, so it always begins `ueyJ`; checking that prefix is
|
|
28
|
+
* what keeps a `urn:` capability id (which also begins with `u`) out of the
|
|
29
|
+
* decoder.
|
|
25
30
|
*
|
|
26
|
-
* @param
|
|
27
|
-
*
|
|
31
|
+
* @param value {string}
|
|
32
|
+
* @returns {boolean}
|
|
33
|
+
*/
|
|
34
|
+
export function isEncodedCapability(value) {
|
|
35
|
+
return /^ueyJ[A-Za-z0-9_-]*$/.test(value);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Decodes a multibase (base64url, `u` prefix) capability string back into a
|
|
39
|
+
* capability.
|
|
40
|
+
*
|
|
41
|
+
* @param encoded {string} A `u`-prefixed multibase string.
|
|
28
42
|
* @returns {IZcap} The decoded root or delegated capability.
|
|
29
43
|
*/
|
|
30
44
|
export function decodeCapability(encoded) {
|
|
31
|
-
if (!encoded.startsWith('
|
|
32
|
-
throw new Error('Encoded capability must be a multibase
|
|
45
|
+
if (!encoded.startsWith('u')) {
|
|
46
|
+
throw new Error('Encoded capability must be a multibase base64url string (leading "u").');
|
|
33
47
|
}
|
|
34
|
-
const bytes =
|
|
48
|
+
const bytes = base64urlnopad.decode(encoded.slice(1));
|
|
35
49
|
return JSON.parse(new TextDecoder().decode(bytes));
|
|
36
50
|
}
|
|
37
51
|
//# sourceMappingURL=encoding.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encoding.js","sourceRoot":"","sources":["../../src/zcap/encoding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"encoding.js","sourceRoot":"","sources":["../../src/zcap/encoding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAG5C;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,UAAiB;IAChD,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAA;IAClE,OAAO,IAAI,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAA;AAC3C,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC/C,OAAO,sBAAsB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAC3C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC9C,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CACb,wEAAwE,CACzE,CAAA;IACH,CAAC;IACD,MAAM,KAAK,GAAG,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IACrD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAU,CAAA;AAC7D,CAAC"}
|
package/dist/zcap/resolve.d.ts
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
import type { IZcap } from '@interop/data-integrity-core/zcap';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* an existing file is parsed as capability JSON
|
|
6
|
-
*
|
|
3
|
+
* Reads a capability given directly rather than by stored reference: a value
|
|
4
|
+
* that `isEncodedCapability` recognizes is decoded as a multibase capability
|
|
5
|
+
* string, and a path to an existing file is parsed as capability JSON. Returns
|
|
6
|
+
* undefined when the value is neither.
|
|
7
|
+
*
|
|
8
|
+
* @param options {object}
|
|
9
|
+
* @param options.ref {string}
|
|
10
|
+
* @returns {Promise<IZcap | undefined>}
|
|
11
|
+
*/
|
|
12
|
+
export declare function readCapabilityInput({ ref }: {
|
|
13
|
+
ref: string;
|
|
14
|
+
}): Promise<IZcap | undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* Resolves a `--capability` reference to a capability object. An encoded
|
|
17
|
+
* capability string or a capability JSON file is read by
|
|
18
|
+
* `readCapabilityInput`; anything else is looked up in the local zcap store by
|
|
19
|
+
* capability id or metadata handle.
|
|
7
20
|
*
|
|
8
21
|
* @param options {object}
|
|
9
22
|
* @param options.ref {string}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/zcap/resolve.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAA;AAmB9D;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAAC,EAC3C,GAAG,EACJ,EAAE;IACD,GAAG,EAAE,MAAM,CAAA;CACZ,GAAG,OAAO,CAAC,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/zcap/resolve.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAA;AAmB9D;;;;;;;;;GASG;AACH,wBAAsB,mBAAmB,CAAC,EACxC,GAAG,EACJ,EAAE;IACD,GAAG,EAAE,MAAM,CAAA;CACZ,GAAG,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC,CAgB7B;AAED;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAAC,EAC3C,GAAG,EACJ,EAAE;IACD,GAAG,EAAE,MAAM,CAAA;CACZ,GAAG,OAAO,CAAC,KAAK,CAAC,CAajB"}
|
package/dist/zcap/resolve.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { access, readFile } from 'node:fs/promises';
|
|
8
8
|
import { resolveZcapRef } from '../meta.js';
|
|
9
|
-
import { decodeCapability } from './encoding.js';
|
|
9
|
+
import { decodeCapability, isEncodedCapability } from './encoding.js';
|
|
10
10
|
/**
|
|
11
11
|
* Returns true when the path exists on disk.
|
|
12
12
|
*
|
|
@@ -23,17 +23,17 @@ async function fileExists(filePath) {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* an existing file is parsed as capability JSON
|
|
29
|
-
*
|
|
26
|
+
* Reads a capability given directly rather than by stored reference: a value
|
|
27
|
+
* that `isEncodedCapability` recognizes is decoded as a multibase capability
|
|
28
|
+
* string, and a path to an existing file is parsed as capability JSON. Returns
|
|
29
|
+
* undefined when the value is neither.
|
|
30
30
|
*
|
|
31
31
|
* @param options {object}
|
|
32
32
|
* @param options.ref {string}
|
|
33
|
-
* @returns {Promise<IZcap>}
|
|
33
|
+
* @returns {Promise<IZcap | undefined>}
|
|
34
34
|
*/
|
|
35
|
-
export async function
|
|
36
|
-
if (ref
|
|
35
|
+
export async function readCapabilityInput({ ref }) {
|
|
36
|
+
if (isEncodedCapability(ref)) {
|
|
37
37
|
return decodeCapability(ref);
|
|
38
38
|
}
|
|
39
39
|
if (await fileExists(ref)) {
|
|
@@ -45,6 +45,23 @@ export async function resolveCapabilityInput({ ref }) {
|
|
|
45
45
|
`${err instanceof Error ? err.message : String(err)}`, { cause: err });
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Resolves a `--capability` reference to a capability object. An encoded
|
|
52
|
+
* capability string or a capability JSON file is read by
|
|
53
|
+
* `readCapabilityInput`; anything else is looked up in the local zcap store by
|
|
54
|
+
* capability id or metadata handle.
|
|
55
|
+
*
|
|
56
|
+
* @param options {object}
|
|
57
|
+
* @param options.ref {string}
|
|
58
|
+
* @returns {Promise<IZcap>}
|
|
59
|
+
*/
|
|
60
|
+
export async function resolveCapabilityInput({ ref }) {
|
|
61
|
+
const direct = await readCapabilityInput({ ref });
|
|
62
|
+
if (direct) {
|
|
63
|
+
return direct;
|
|
64
|
+
}
|
|
48
65
|
const stored = await resolveZcapRef({ ref });
|
|
49
66
|
if (!stored) {
|
|
50
67
|
throw new Error(`No capability found for "${ref}" (not an encoded string, a file, ` +
|
package/dist/zcap/resolve.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/zcap/resolve.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAEnD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/zcap/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E,CAAC,CAAA;IACjD,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,MAAM,CAAA;IACf,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,EAAE,GAAG,EAAE,CAAC,CAAA;IAC5C,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,4BAA4B,GAAG,oCAAoC;YACjE,8BAA8B,CACjC,CAAA;IACH,CAAC;IACD,OAAO,MAAM,CAAC,IAAa,CAAA;AAC7B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interop/did-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "DID CLI tool for DIDs, Verifiable Credentials, key pairs, and zcaps",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -26,25 +26,27 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@digitalcredentials/bnid": "^5.0.0",
|
|
28
28
|
"@digitalcredentials/issuer-registry-client": "^4.0.0",
|
|
29
|
-
"@interop/data-integrity-core": "^8.
|
|
30
|
-
"@interop/data-integrity-proof": "^3.4.
|
|
31
|
-
"@interop/did-io": "^4.
|
|
32
|
-
"@interop/did-method-key": "^7.
|
|
33
|
-
"@interop/did-method-webvh": "^
|
|
34
|
-
"@interop/did-web-resolver": "^6.
|
|
35
|
-
"@interop/ecdsa-multikey": "^2.
|
|
36
|
-
"@interop/ecdsa-signature": "2.0.
|
|
37
|
-
"@interop/ed25519-signature": "^7.
|
|
38
|
-
"@interop/ed25519-verification-key": "^8.0
|
|
39
|
-
"@interop/edv-client": "^17.
|
|
40
|
-
"@interop/ezcap": "^7.
|
|
41
|
-
"@interop/minimal-cipher": "^7.
|
|
42
|
-
"@interop/security-document-loader": "^
|
|
43
|
-
"@interop/vc": "^11.0.
|
|
44
|
-
"@interop/verifier-core": "^3.
|
|
45
|
-
"@interop/
|
|
46
|
-
"@interop/
|
|
47
|
-
"@interop/
|
|
29
|
+
"@interop/data-integrity-core": "^8.7.1",
|
|
30
|
+
"@interop/data-integrity-proof": "^3.4.5",
|
|
31
|
+
"@interop/did-io": "^4.1.1",
|
|
32
|
+
"@interop/did-method-key": "^7.4.2",
|
|
33
|
+
"@interop/did-method-webvh": "^5.9.0",
|
|
34
|
+
"@interop/did-web-resolver": "^6.3.3",
|
|
35
|
+
"@interop/ecdsa-multikey": "^2.4.0",
|
|
36
|
+
"@interop/ecdsa-signature": "2.0.7",
|
|
37
|
+
"@interop/ed25519-signature": "^7.2.2",
|
|
38
|
+
"@interop/ed25519-verification-key": "^8.2.0",
|
|
39
|
+
"@interop/edv-client": "^17.8.4",
|
|
40
|
+
"@interop/ezcap": "^7.4.8",
|
|
41
|
+
"@interop/minimal-cipher": "^7.10.2",
|
|
42
|
+
"@interop/security-document-loader": "^10.1.2",
|
|
43
|
+
"@interop/vc": "^11.0.9",
|
|
44
|
+
"@interop/verifier-core": "^3.5.8",
|
|
45
|
+
"@interop/wallet-core": "^0.78.0",
|
|
46
|
+
"@interop/wallet-request": "^0.3.1",
|
|
47
|
+
"@interop/was-client": "^0.64.0",
|
|
48
|
+
"@interop/x25519-key-agreement-key": "^5.4.0",
|
|
49
|
+
"@interop/zcap": "^11.3.0",
|
|
48
50
|
"@scure/base": "^2.2.0",
|
|
49
51
|
"commander": "^15.0.0"
|
|
50
52
|
},
|