@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,142 @@
|
|
|
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 { Ed25519VerificationKey } from '@interop/ed25519-verification-key';
|
|
17
|
+
import { createSigner } from '@interop/ed25519-signature';
|
|
18
|
+
import { loadDidDocument, loadDidKeys } from '../storage.js';
|
|
19
|
+
import { resolveDidRef } from '../meta.js';
|
|
20
|
+
import { parseWasAddress } from './address.js';
|
|
21
|
+
import { resolveSpaceRef } from './registry.js';
|
|
22
|
+
function defaultWasClientFactory({ serverUrl, signer }) {
|
|
23
|
+
return WasClient.fromSigner({ serverUrl, signer });
|
|
24
|
+
}
|
|
25
|
+
let wasClientFactory = defaultWasClientFactory;
|
|
26
|
+
/**
|
|
27
|
+
* Replaces the `WasClient` construction step (a test-only seam). Call with
|
|
28
|
+
* no argument to restore the default factory.
|
|
29
|
+
*
|
|
30
|
+
* @param [factory] {WasClientFactory}
|
|
31
|
+
* @returns {void}
|
|
32
|
+
*/
|
|
33
|
+
export function setWasClientFactory(factory) {
|
|
34
|
+
wasClientFactory = factory ?? defaultWasClientFactory;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Loads the WAS invocation signer from a locally stored DID. Only `did:key`
|
|
38
|
+
* DIDs with Ed25519 keys are supported; anything else is rejected with a
|
|
39
|
+
* clear error.
|
|
40
|
+
*
|
|
41
|
+
* @param options {object}
|
|
42
|
+
* @param options.did {string} A DID or the metadata handle of a stored DID.
|
|
43
|
+
* @returns {Promise<{did: string, signer: ISigner}>}
|
|
44
|
+
*/
|
|
45
|
+
export async function loadWasSigner({ did }) {
|
|
46
|
+
const resolved = await resolveDidRef({ ref: did });
|
|
47
|
+
if (!resolved) {
|
|
48
|
+
throw new Error(`No locally stored DID found for "${did}".`);
|
|
49
|
+
}
|
|
50
|
+
if (!resolved.startsWith('did:key:')) {
|
|
51
|
+
throw new Error(`WAS signing currently supports only did:key DIDs (got ${resolved}).`);
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
await loadDidDocument(resolved);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
if (err.code === 'ENOENT') {
|
|
58
|
+
throw new Error(`DID ${resolved} is not in local storage; save it first with ` +
|
|
59
|
+
'"di did create --save".', { cause: err });
|
|
60
|
+
}
|
|
61
|
+
throw err;
|
|
62
|
+
}
|
|
63
|
+
const keysData = await loadDidKeys(resolved);
|
|
64
|
+
// Both Ed25519 and ECDSA keys export as `type: 'Multikey'`; the curve is
|
|
65
|
+
// identified by the multicodec prefix of the public key (`z6Mk` = Ed25519).
|
|
66
|
+
if (!keysData.publicKeyMultibase?.startsWith('z6Mk')) {
|
|
67
|
+
throw new Error('WAS signing currently supports only Ed25519 keys ' +
|
|
68
|
+
`(DID ${resolved} has a different key type).`);
|
|
69
|
+
}
|
|
70
|
+
const keyPair = await Ed25519VerificationKey.from(keysData);
|
|
71
|
+
return { did: resolved, signer: createSigner(keyPair) };
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Builds a `WasClient` from an explicit server URL and signing DID,
|
|
75
|
+
* falling back to the `WAS_SERVER_URL` and `WAS_DID` environment variables.
|
|
76
|
+
* Used by commands that do not address an existing space (e.g.
|
|
77
|
+
* `was space create`).
|
|
78
|
+
*
|
|
79
|
+
* @param options {object}
|
|
80
|
+
* @param [options.server] {string} The server base URL.
|
|
81
|
+
* @param [options.did] {string} A DID or stored-DID metadata handle.
|
|
82
|
+
* @returns {Promise<{client: WasClient, server: string, did: string}>}
|
|
83
|
+
*/
|
|
84
|
+
export async function buildWasClient({ server, did } = {}) {
|
|
85
|
+
const serverUrl = server ?? process.env.WAS_SERVER_URL;
|
|
86
|
+
if (!serverUrl) {
|
|
87
|
+
throw new Error('No WAS server URL: provide --server or set WAS_SERVER_URL.');
|
|
88
|
+
}
|
|
89
|
+
const didRef = did ?? process.env.WAS_DID;
|
|
90
|
+
if (!didRef) {
|
|
91
|
+
throw new Error('No signing DID: provide --did or set WAS_DID.');
|
|
92
|
+
}
|
|
93
|
+
const { did: resolvedDid, signer } = await loadWasSigner({ did: didRef });
|
|
94
|
+
const client = wasClientFactory({ serverUrl, signer });
|
|
95
|
+
return { client, server: serverUrl, did: resolvedDid };
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Resolves a WAS address into a ready-to-use command target: parses the
|
|
99
|
+
* `SPACE[/COLLECTION[/RESOURCE]]` path, consults the local space registry
|
|
100
|
+
* for the space reference (handle or id), resolves the server URL and
|
|
101
|
+
* signing DID from the flags / environment / registry entry, and builds the
|
|
102
|
+
* signed `WasClient`.
|
|
103
|
+
*
|
|
104
|
+
* @param options {object}
|
|
105
|
+
* @param options.address {string} The positional WAS path.
|
|
106
|
+
* @param [options.server] {string} The `--server` flag value.
|
|
107
|
+
* @param [options.did] {string} The `--did` flag value (DID or handle).
|
|
108
|
+
* @returns {Promise<ResolvedWasTarget>}
|
|
109
|
+
*/
|
|
110
|
+
export async function resolveWasTarget({ address, server, did }) {
|
|
111
|
+
const parsed = parseWasAddress(address);
|
|
112
|
+
const entry = await resolveSpaceRef({ ref: parsed.spaceRef });
|
|
113
|
+
const spaceId = entry?.record.id ?? parsed.spaceRef;
|
|
114
|
+
const serverUrl = parsed.server ??
|
|
115
|
+
server ??
|
|
116
|
+
process.env.WAS_SERVER_URL ??
|
|
117
|
+
entry?.record.server;
|
|
118
|
+
if (!serverUrl) {
|
|
119
|
+
throw new Error(`No WAS server URL for space "${parsed.spaceRef}": use a full space ` +
|
|
120
|
+
'URL, provide --server or WAS_SERVER_URL, or register the space ' +
|
|
121
|
+
'with "di was space add".');
|
|
122
|
+
}
|
|
123
|
+
const didRef = did ?? process.env.WAS_DID ?? entry?.record.controller;
|
|
124
|
+
if (!didRef) {
|
|
125
|
+
throw new Error(`No signing DID for space "${parsed.spaceRef}": provide --did or ` +
|
|
126
|
+
'WAS_DID, or register the space with its controller DID.');
|
|
127
|
+
}
|
|
128
|
+
const { did: resolvedDid, signer } = await loadWasSigner({ did: didRef });
|
|
129
|
+
const client = wasClientFactory({ serverUrl, signer });
|
|
130
|
+
return {
|
|
131
|
+
client,
|
|
132
|
+
server: serverUrl,
|
|
133
|
+
did: resolvedDid,
|
|
134
|
+
spaceId,
|
|
135
|
+
...(parsed.collectionId !== undefined && {
|
|
136
|
+
collectionId: parsed.collectionId
|
|
137
|
+
}),
|
|
138
|
+
...(parsed.resourceId !== undefined && { resourceId: parsed.resourceId }),
|
|
139
|
+
...(entry && { entry })
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/was/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAA;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAEzD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAqB,MAAM,eAAe,CAAA;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAoB,MAAM,eAAe,CAAA;AAYjE,SAAS,uBAAuB,CAAC,EAC/B,SAAS,EACT,MAAM,EAIP;IACC,OAAO,SAAS,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAA;AACpD,CAAC;AAED,IAAI,gBAAgB,GAAqB,uBAAuB,CAAA;AAEhE;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAA0B;IAC5D,gBAAgB,GAAG,OAAO,IAAI,uBAAuB,CAAA;AACvD,CAAC;AA6BD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,EAClC,GAAG,EAGJ;IACC,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC,EAAE,GAAG,E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,IAAI,KAAK,EAAE,MAAM,CAAC,UAAU,CAAA;IACrE,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,6BAA6B,MAAM,CAAC,QAAQ,sBAAsB;YAChE,yDAAyD,CAC5D,CAAA;IACH,CAAC;IACD,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,MAAM,aAAa,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAA;IACzE,MAAM,MAAM,GAAG,gBAAgB,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAA;IAEtD,OAAO;QACL,MAAM;QACN,MAAM,EAAE,SAAS;QACjB,GAAG,EAAE,WAAW;QAChB,OAAO;QACP,GAAG,CAAC,MAAM,CAAC,YAAY,KAAK,SAAS,IAAI;YACvC,YAAY,EAAE,MAAM,CAAC,YAAY;SAClC,CAAC;QACF,GAAG,CAAC,MAAM,CAAC,UAAU,KAAK,SAAS,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC;QACzE,GAAG,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,CAAC;KACxB,CAAA;AACH,CAAC"}
|
package/dist/was/io.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Readable } from 'node:stream';
|
|
2
|
+
import type { Json } from '@interop/was-client';
|
|
3
|
+
/**
|
|
4
|
+
* A resource write payload, resolved to either parsed JSON data or raw
|
|
5
|
+
* binary bytes plus the content type to send them with.
|
|
6
|
+
*/
|
|
7
|
+
export interface ResourcePayload {
|
|
8
|
+
data: Json | Uint8Array;
|
|
9
|
+
/** The content type of a binary payload (JSON payloads carry none). */
|
|
10
|
+
contentType?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Reads a resource write payload from a file or stdin and resolves it to
|
|
14
|
+
* JSON or binary form (see the module header for the detection rules).
|
|
15
|
+
*
|
|
16
|
+
* @param options {object}
|
|
17
|
+
* @param [options.file] {string} The input file path; stdin when omitted.
|
|
18
|
+
* @param [options.contentType] {string} Explicit content type: the bytes
|
|
19
|
+
* are sent as-is with this type, skipping JSON detection.
|
|
20
|
+
* @param [options.stdin] {Readable} The stdin stream (a test seam).
|
|
21
|
+
* @returns {Promise<ResourcePayload>}
|
|
22
|
+
*/
|
|
23
|
+
export declare function readPayload({ file, contentType, stdin }?: {
|
|
24
|
+
file?: string;
|
|
25
|
+
contentType?: string;
|
|
26
|
+
stdin?: Readable;
|
|
27
|
+
}): Promise<ResourcePayload>;
|
|
28
|
+
/**
|
|
29
|
+
* Reads raw bytes from a file or stdin, without any payload detection.
|
|
30
|
+
* Used for opaque pass-through content such as space export/import tars.
|
|
31
|
+
*
|
|
32
|
+
* @param options {object}
|
|
33
|
+
* @param [options.file] {string} The input file path; stdin when omitted.
|
|
34
|
+
* @param [options.stdin] {Readable} The stdin stream (a test seam).
|
|
35
|
+
* @returns {Promise<Uint8Array>}
|
|
36
|
+
*/
|
|
37
|
+
export declare function readInputBytes({ file, stdin }?: {
|
|
38
|
+
file?: string;
|
|
39
|
+
stdin?: Readable;
|
|
40
|
+
}): Promise<Uint8Array>;
|
|
41
|
+
/**
|
|
42
|
+
* Writes raw bytes to an output file (with a byte-count note on stderr) or
|
|
43
|
+
* raw to stdout when no file is given. Used for opaque pass-through
|
|
44
|
+
* content such as space export tars.
|
|
45
|
+
*
|
|
46
|
+
* @param options {object}
|
|
47
|
+
* @param options.bytes {Uint8Array}
|
|
48
|
+
* @param [options.output] {string} The output file path; stdout when
|
|
49
|
+
* omitted.
|
|
50
|
+
* @returns {Promise<void>}
|
|
51
|
+
*/
|
|
52
|
+
export declare function writeBytesOutput({ bytes, output }: {
|
|
53
|
+
bytes: Uint8Array;
|
|
54
|
+
output?: string;
|
|
55
|
+
}): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Writes a resource read result: JSON is pretty-printed to stdout (or
|
|
58
|
+
* written to the `--output` file); binary content is written raw to the
|
|
59
|
+
* `--output` file, or to stdout when none is given.
|
|
60
|
+
*
|
|
61
|
+
* @param options {object}
|
|
62
|
+
* @param options.data {Json | Blob} The value returned by `resource.get()`.
|
|
63
|
+
* @param [options.output] {string} The output file path; stdout when
|
|
64
|
+
* omitted.
|
|
65
|
+
* @returns {Promise<void>}
|
|
66
|
+
*/
|
|
67
|
+
export declare function writeResourceOutput({ data, output }: {
|
|
68
|
+
data: Json | Blob;
|
|
69
|
+
output?: string;
|
|
70
|
+
}): Promise<void>;
|
|
71
|
+
//# sourceMappingURL=io.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../../src/was/io.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAI/C;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,IAAI,GAAG,UAAU,CAAA;IACvB,uEAAuE;IACvE,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AA2CD;;;;;;;;;;GAUG;AACH,wBAAsB,WAAW,CAAC,EAChC,IAAI,EACJ,WAAW,EACX,KAAqB,EACtB,GAAE;IACD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,KAAK,CAAC,EAAE,QAAQ,CAAA;CACZ,GAAG,OAAO,CAAC,eAAe,CAAC,CAkBhC;AAED;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAAC,EACnC,IAAI,EACJ,KAAqB,EACtB,GAAE;IACD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,QAAQ,CAAA;CACZ,GAAG,OAAO,CAAC,UAAU,CAAC,CAG3B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,KAAK,EACL,MAAM,EACP,EAAE;IACD,KAAK,EAAE,UAAU,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,GAAG,OAAO,CAAC,IAAI,CAAC,CAOhB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,mBAAmB,CAAC,EACxC,IAAI,EACJ,MAAM,EACP,EAAE;IACD,IAAI,EAAE,IAAI,GAAG,IAAI,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBhB"}
|
package/dist/was/io.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payload and output helpers for the `was resource` commands: reading write
|
|
3
|
+
* payloads from a file or stdin with JSON-vs-binary detection, and writing
|
|
4
|
+
* read results to stdout or an `--output` file.
|
|
5
|
+
*
|
|
6
|
+
* Detection rules: an explicit `--content-type` always wins and sends the
|
|
7
|
+
* raw bytes with that type (so e.g. `application/ld+json` is preserved
|
|
8
|
+
* exactly). Without it, a `*.json` file must parse as JSON and is sent as a
|
|
9
|
+
* JSON payload; any other input is sniffed -- content that parses to a JSON
|
|
10
|
+
* object or array is sent as JSON, everything else is sent as binary
|
|
11
|
+
* `application/octet-stream`.
|
|
12
|
+
*/
|
|
13
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
14
|
+
const OCTET_STREAM = 'application/octet-stream';
|
|
15
|
+
/**
|
|
16
|
+
* Reads a whole stream (stdin) into a single byte buffer.
|
|
17
|
+
*
|
|
18
|
+
* @param stream {Readable}
|
|
19
|
+
* @returns {Promise<Buffer>}
|
|
20
|
+
*/
|
|
21
|
+
async function readStream(stream) {
|
|
22
|
+
const chunks = [];
|
|
23
|
+
for await (const chunk of stream) {
|
|
24
|
+
chunks.push(chunk);
|
|
25
|
+
}
|
|
26
|
+
return Buffer.concat(chunks);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Parses bytes as a JSON object or array. Returns undefined when the bytes
|
|
30
|
+
* are not valid UTF-8 JSON or parse to a primitive (which WAS resources do
|
|
31
|
+
* not accept as JSON payloads).
|
|
32
|
+
*
|
|
33
|
+
* @param bytes {Buffer}
|
|
34
|
+
* @returns {Json | undefined}
|
|
35
|
+
*/
|
|
36
|
+
function parseJsonPayload(bytes) {
|
|
37
|
+
let text;
|
|
38
|
+
try {
|
|
39
|
+
text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
let parsed;
|
|
45
|
+
try {
|
|
46
|
+
parsed = JSON.parse(text);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
if (parsed === null || typeof parsed !== 'object') {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
return parsed;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Reads a resource write payload from a file or stdin and resolves it to
|
|
58
|
+
* JSON or binary form (see the module header for the detection rules).
|
|
59
|
+
*
|
|
60
|
+
* @param options {object}
|
|
61
|
+
* @param [options.file] {string} The input file path; stdin when omitted.
|
|
62
|
+
* @param [options.contentType] {string} Explicit content type: the bytes
|
|
63
|
+
* are sent as-is with this type, skipping JSON detection.
|
|
64
|
+
* @param [options.stdin] {Readable} The stdin stream (a test seam).
|
|
65
|
+
* @returns {Promise<ResourcePayload>}
|
|
66
|
+
*/
|
|
67
|
+
export async function readPayload({ file, contentType, stdin = process.stdin } = {}) {
|
|
68
|
+
const bytes = file ? await readFile(file) : await readStream(stdin);
|
|
69
|
+
if (contentType) {
|
|
70
|
+
return { data: new Uint8Array(bytes), contentType };
|
|
71
|
+
}
|
|
72
|
+
const parsed = parseJsonPayload(bytes);
|
|
73
|
+
if (file?.endsWith('.json')) {
|
|
74
|
+
if (parsed === undefined) {
|
|
75
|
+
throw new Error(`${file} does not contain a JSON object or array.`);
|
|
76
|
+
}
|
|
77
|
+
return { data: parsed };
|
|
78
|
+
}
|
|
79
|
+
if (parsed !== undefined) {
|
|
80
|
+
return { data: parsed };
|
|
81
|
+
}
|
|
82
|
+
return { data: new Uint8Array(bytes), contentType: OCTET_STREAM };
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Reads raw bytes from a file or stdin, without any payload detection.
|
|
86
|
+
* Used for opaque pass-through content such as space export/import tars.
|
|
87
|
+
*
|
|
88
|
+
* @param options {object}
|
|
89
|
+
* @param [options.file] {string} The input file path; stdin when omitted.
|
|
90
|
+
* @param [options.stdin] {Readable} The stdin stream (a test seam).
|
|
91
|
+
* @returns {Promise<Uint8Array>}
|
|
92
|
+
*/
|
|
93
|
+
export async function readInputBytes({ file, stdin = process.stdin } = {}) {
|
|
94
|
+
const bytes = file ? await readFile(file) : await readStream(stdin);
|
|
95
|
+
return new Uint8Array(bytes);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Writes raw bytes to an output file (with a byte-count note on stderr) or
|
|
99
|
+
* raw to stdout when no file is given. Used for opaque pass-through
|
|
100
|
+
* content such as space export tars.
|
|
101
|
+
*
|
|
102
|
+
* @param options {object}
|
|
103
|
+
* @param options.bytes {Uint8Array}
|
|
104
|
+
* @param [options.output] {string} The output file path; stdout when
|
|
105
|
+
* omitted.
|
|
106
|
+
* @returns {Promise<void>}
|
|
107
|
+
*/
|
|
108
|
+
export async function writeBytesOutput({ bytes, output }) {
|
|
109
|
+
if (output) {
|
|
110
|
+
await writeFile(output, bytes);
|
|
111
|
+
console.error(`Wrote ${bytes.length} bytes to ${output}`);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
process.stdout.write(bytes);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Writes a resource read result: JSON is pretty-printed to stdout (or
|
|
118
|
+
* written to the `--output` file); binary content is written raw to the
|
|
119
|
+
* `--output` file, or to stdout when none is given.
|
|
120
|
+
*
|
|
121
|
+
* @param options {object}
|
|
122
|
+
* @param options.data {Json | Blob} The value returned by `resource.get()`.
|
|
123
|
+
* @param [options.output] {string} The output file path; stdout when
|
|
124
|
+
* omitted.
|
|
125
|
+
* @returns {Promise<void>}
|
|
126
|
+
*/
|
|
127
|
+
export async function writeResourceOutput({ data, output }) {
|
|
128
|
+
if (data instanceof Blob) {
|
|
129
|
+
const bytes = new Uint8Array(await data.arrayBuffer());
|
|
130
|
+
if (output) {
|
|
131
|
+
await writeFile(output, bytes);
|
|
132
|
+
console.error(`Wrote ${bytes.length} bytes to ${output}`);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
process.stdout.write(bytes);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const text = JSON.stringify(data, null, 2);
|
|
139
|
+
if (output) {
|
|
140
|
+
await writeFile(output, `${text}\n`, 'utf8');
|
|
141
|
+
console.error(`Wrote ${output}`);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
console.log(text);
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=io.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"io.js","sourceRoot":"","sources":["../../src/was/io.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAItD,MAAM,YAAY,GAAG,0BAA0B,CAAA;AAY/C;;;;;GAKG;AACH,KAAK,UAAU,UAAU,CAAC,MAAgB;IACxC,MAAM,MAAM,GAAa,EAAE,CAAA;IAC3B,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QACjC,MAAM,CAAC,IAAI,CAAC,KAAe,CAAC,CAAA;IAC9B,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;AAC9B,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,gBAAgB,CAAC,KAAa;IACrC,IAAI,IAAY,CAAA;IAChB,IAAI,CAA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ACR,CAAC;QACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAC3B,OAAM;IACR,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IAC1C,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,SAAS,CAAC,MAAM,EAAE,GAAG,IAAI,IAAI,EAAE,MAAM,CAAC,CAAA;QAC5C,OAAO,CAAC,KAAK,CAAC,SAAS,MAAM,EAAE,CAAC,CAAA;QAChC,OAAM;IACR,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;AACnB,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local space registry: records of WAS spaces the user works with, stored in
|
|
3
|
+
* the `was-spaces` wallet collection (`~/.config/did-cli-wallet/was-spaces/`). Each entry
|
|
4
|
+
* carries the space id, its display name, the server base URL, and the
|
|
5
|
+
* controller DID, with the usual `.meta.json` sidecar (created / handle /
|
|
6
|
+
* description). The registry is what lets `was space list` work without the
|
|
7
|
+
* (unimplemented) server-side List Spaces operation, and what supplies
|
|
8
|
+
* server URL and signing DID defaults so commands can be as short as
|
|
9
|
+
* `di was get home/credentials/vc-1`.
|
|
10
|
+
*/
|
|
11
|
+
import { type ItemMetadata } from '../storage.js';
|
|
12
|
+
/**
|
|
13
|
+
* A registered space, as stored in a `was-spaces` item file.
|
|
14
|
+
*/
|
|
15
|
+
export interface SpaceRecord {
|
|
16
|
+
/** The space id (server-generated uuid or urn). */
|
|
17
|
+
id: string;
|
|
18
|
+
/** The space's display name. */
|
|
19
|
+
name?: string;
|
|
20
|
+
/** The server base URL (origin). */
|
|
21
|
+
server: string;
|
|
22
|
+
/** The controller DID, used as the default signing DID. */
|
|
23
|
+
controller?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Saves (or overwrites) a space registry entry and its metadata sidecar.
|
|
27
|
+
* The `created` timestamp of an existing sidecar is preserved; `handle` and
|
|
28
|
+
* `description` overwrite only when given.
|
|
29
|
+
*
|
|
30
|
+
* @param options {object}
|
|
31
|
+
* @param options.record {SpaceRecord}
|
|
32
|
+
* @param [options.handle] {string}
|
|
33
|
+
* @param [options.description] {string}
|
|
34
|
+
* @returns {Promise<string>} The saved item file path.
|
|
35
|
+
*/
|
|
36
|
+
export declare function saveSpaceRecord({ record, handle, description }: {
|
|
37
|
+
record: SpaceRecord;
|
|
38
|
+
handle?: string;
|
|
39
|
+
description?: string;
|
|
40
|
+
}): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Lists all registered spaces with their metadata sidecars.
|
|
43
|
+
*
|
|
44
|
+
* @returns {Promise<{storageId: string, record: SpaceRecord, meta?: ItemMetadata}[]>}
|
|
45
|
+
*/
|
|
46
|
+
export declare function listSpaceRecords(): Promise<{
|
|
47
|
+
storageId: string;
|
|
48
|
+
record: SpaceRecord;
|
|
49
|
+
meta?: ItemMetadata;
|
|
50
|
+
}[]>;
|
|
51
|
+
/**
|
|
52
|
+
* Resolve a user-supplied space reference -- a space id or a metadata handle
|
|
53
|
+
* -- to a registered space. Space id matches take precedence; otherwise the
|
|
54
|
+
* metadata sidecars are searched for a matching handle. Throws when a handle
|
|
55
|
+
* matches more than one space (handles are not unique). Returns undefined
|
|
56
|
+
* when nothing matches.
|
|
57
|
+
*
|
|
58
|
+
* @param options {object}
|
|
59
|
+
* @param options.ref {string}
|
|
60
|
+
* @returns {Promise<{storageId: string, record: SpaceRecord, meta?: ItemMetadata} | undefined>}
|
|
61
|
+
*/
|
|
62
|
+
export declare function resolveSpaceRef({ ref }: {
|
|
63
|
+
ref: string;
|
|
64
|
+
}): Promise<{
|
|
65
|
+
storageId: string;
|
|
66
|
+
record: SpaceRecord;
|
|
67
|
+
meta?: ItemMetadata;
|
|
68
|
+
} | undefined>;
|
|
69
|
+
/**
|
|
70
|
+
* Removes a space registry entry (the item file plus its metadata sidecar).
|
|
71
|
+
*
|
|
72
|
+
* @param options {object}
|
|
73
|
+
* @param options.storageId {string}
|
|
74
|
+
* @returns {Promise<string[]>} The file paths that were deleted.
|
|
75
|
+
*/
|
|
76
|
+
export declare function removeSpaceRecord({ storageId }: {
|
|
77
|
+
storageId: string;
|
|
78
|
+
}): Promise<string[]>;
|
|
79
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/was/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAQL,KAAK,YAAY,EAClB,MAAM,eAAe,CAAA;AAItB;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,mDAAmD;IACnD,EAAE,EAAE,MAAM,CAAA;IACV,gCAAgC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAA;IACd,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CAAC,EACpC,MAAM,EACN,MAAM,EACN,WAAW,EACZ,EAAE;IACD,MAAM,EAAE,WAAW,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,GAAG,OAAO,CAAC,MAAM,CAAC,CAmBlB;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAC/C;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,WAAW,CAAC;IAAC,IAAI,CAAC,EAAE,YAAY,CAAA;CAAE,EAAE,CAClE,CAgBA;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CAAC,EAAE,GAAG,EAAE,EAAE;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CACpE;IACE,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,WAAW,CAAA;IACnB,IAAI,CAAC,EAAE,YAAY,CAAA;CACpB,GACD,SAAS,CACZ,CAiBA;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CAAC,EACtC,SAAS,EACV,EAAE;IACD,SAAS,EAAE,MAAM,CAAA;CAClB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAEpB"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local space registry: records of WAS spaces the user works with, stored in
|
|
3
|
+
* the `was-spaces` wallet collection (`~/.config/did-cli-wallet/was-spaces/`). Each entry
|
|
4
|
+
* carries the space id, its display name, the server base URL, and the
|
|
5
|
+
* controller DID, with the usual `.meta.json` sidecar (created / handle /
|
|
6
|
+
* description). The registry is what lets `was space list` work without the
|
|
7
|
+
* (unimplemented) server-side List Spaces operation, and what supplies
|
|
8
|
+
* server URL and signing DID defaults so commands can be as short as
|
|
9
|
+
* `di was get home/credentials/vc-1`.
|
|
10
|
+
*/
|
|
11
|
+
import { listCollection, loadFromCollection, loadMetaFromCollection, removeFromCollection, saveMetaToCollection, saveToCollection, sanitizeStorageId } from '../storage.js';
|
|
12
|
+
const COLLECTION = 'was-spaces';
|
|
13
|
+
/**
|
|
14
|
+
* Saves (or overwrites) a space registry entry and its metadata sidecar.
|
|
15
|
+
* The `created` timestamp of an existing sidecar is preserved; `handle` and
|
|
16
|
+
* `description` overwrite only when given.
|
|
17
|
+
*
|
|
18
|
+
* @param options {object}
|
|
19
|
+
* @param options.record {SpaceRecord}
|
|
20
|
+
* @param [options.handle] {string}
|
|
21
|
+
* @param [options.description] {string}
|
|
22
|
+
* @returns {Promise<string>} The saved item file path.
|
|
23
|
+
*/
|
|
24
|
+
export async function saveSpaceRecord({ record, handle, description }) {
|
|
25
|
+
const storageId = sanitizeStorageId(record.id);
|
|
26
|
+
const filePath = await saveToCollection(COLLECTION, storageId, record);
|
|
27
|
+
const existing = await loadMetaFromCollection({
|
|
28
|
+
collection: COLLECTION,
|
|
29
|
+
storageId
|
|
30
|
+
});
|
|
31
|
+
const meta = {
|
|
32
|
+
...existing,
|
|
33
|
+
created: existing?.created ?? new Date().toISOString()
|
|
34
|
+
};
|
|
35
|
+
if (handle) {
|
|
36
|
+
meta.handle = handle;
|
|
37
|
+
}
|
|
38
|
+
if (description) {
|
|
39
|
+
meta.description = description;
|
|
40
|
+
}
|
|
41
|
+
await saveMetaToCollection({ collection: COLLECTION, storageId, meta });
|
|
42
|
+
return filePath;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Lists all registered spaces with their metadata sidecars.
|
|
46
|
+
*
|
|
47
|
+
* @returns {Promise<{storageId: string, record: SpaceRecord, meta?: ItemMetadata}[]>}
|
|
48
|
+
*/
|
|
49
|
+
export async function listSpaceRecords() {
|
|
50
|
+
const storageIds = await listCollection(COLLECTION);
|
|
51
|
+
const entries = [];
|
|
52
|
+
for (const storageId of storageIds) {
|
|
53
|
+
const record = await loadFromCollection(COLLECTION, storageId);
|
|
54
|
+
const meta = await loadMetaFromCollection({
|
|
55
|
+
collection: COLLECTION,
|
|
56
|
+
storageId
|
|
57
|
+
});
|
|
58
|
+
entries.push({ storageId, record, meta });
|
|
59
|
+
}
|
|
60
|
+
return entries;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Resolve a user-supplied space reference -- a space id or a metadata handle
|
|
64
|
+
* -- to a registered space. Space id matches take precedence; otherwise the
|
|
65
|
+
* metadata sidecars are searched for a matching handle. Throws when a handle
|
|
66
|
+
* matches more than one space (handles are not unique). Returns undefined
|
|
67
|
+
* when nothing matches.
|
|
68
|
+
*
|
|
69
|
+
* @param options {object}
|
|
70
|
+
* @param options.ref {string}
|
|
71
|
+
* @returns {Promise<{storageId: string, record: SpaceRecord, meta?: ItemMetadata} | undefined>}
|
|
72
|
+
*/
|
|
73
|
+
export async function resolveSpaceRef({ ref }) {
|
|
74
|
+
const entries = await listSpaceRecords();
|
|
75
|
+
const byId = entries.find(entry => entry.record.id === ref);
|
|
76
|
+
if (byId) {
|
|
77
|
+
return byId;
|
|
78
|
+
}
|
|
79
|
+
const matches = entries.filter(entry => entry.meta?.handle === ref);
|
|
80
|
+
if (matches.length === 0) {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
if (matches.length > 1) {
|
|
84
|
+
throw new Error(`Handle "${ref}" matches ${matches.length} spaces; ` +
|
|
85
|
+
'use the space id instead.');
|
|
86
|
+
}
|
|
87
|
+
return matches[0];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Removes a space registry entry (the item file plus its metadata sidecar).
|
|
91
|
+
*
|
|
92
|
+
* @param options {object}
|
|
93
|
+
* @param options.storageId {string}
|
|
94
|
+
* @returns {Promise<string[]>} The file paths that were deleted.
|
|
95
|
+
*/
|
|
96
|
+
export async function removeSpaceRecord({ storageId }) {
|
|
97
|
+
return removeFromCollection({ collection: COLLECTION, storageId });
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/was/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,EAElB,MAAM,eAAe,CAAA;AAEtB,MAAM,UAAU,GAAG,YAAY,CAAA;AAgB/B;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,EACpC,MAAM,EACN,MAAM,EACN,WAAW,EAKZ;IACC,MAAM,SAAS,GAAG,iBAAiB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IAC9C,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,CAAA;IACtE,MAAM,QAAQ,GAAG,MAAM,sBAAsB,CAA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,CAAC,CAAA;IAC3D,IAAI,IAAI,EAAE,CAAC;QACT,OAAO,IAAI,CAAA;IACb,CAAC;IACD,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,KAAK,GAAG,CAAC,CAAA;IACnE,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CACb,WAAW,GAAG,aAAa,OAAO,CAAC,MAAM,WAAW;YAClD,2BAA2B,CAC9B,CAAA;IACH,CAAC;IACD,OAAO,OAAO,CAAC,CAAC,CAAC,CAAA;AACnB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,EACtC,SAAS,EAGV;IACC,OAAO,oBAAoB,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC,CAAA;AACpE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { IRootZcap } from '@interop/data-integrity-core/zcap';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a root capability for an invocation target.
|
|
4
|
+
*
|
|
5
|
+
* @param options {object}
|
|
6
|
+
* @param options.controller {string} The DID authorized to invoke (the root
|
|
7
|
+
* controller).
|
|
8
|
+
* @param options.url {string} The resource URI the capability targets (the
|
|
9
|
+
* `invocationTarget`).
|
|
10
|
+
* @returns {{rootCapability: IRootZcap, encoded: string}} The root capability
|
|
11
|
+
* and its multibase (base58btc) encoding.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createCapability({ controller, url }: {
|
|
14
|
+
controller: string;
|
|
15
|
+
url: string;
|
|
16
|
+
}): {
|
|
17
|
+
rootCapability: IRootZcap;
|
|
18
|
+
encoded: string;
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=create.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/zcap/create.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAA;AAGlE;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,UAAU,EACV,GAAG,EACJ,EAAE;IACD,UAAU,EAAE,MAAM,CAAA;IAClB,GAAG,EAAE,MAAM,CAAA;CACZ,GAAG;IAAE,cAAc,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAMjD"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Root Authorization Capability (zcap) creation.
|
|
3
|
+
*
|
|
4
|
+
* `createCapability` builds an unsigned root capability via @interop/zcap's
|
|
5
|
+
* `createRootCapability` (which sets `@context`, the `urn:zcap:root:<target>`
|
|
6
|
+
* id, the controller, and the invocation target) and returns it alongside its
|
|
7
|
+
* multibase-encoded form. Root capabilities are unsigned, so no key is needed.
|
|
8
|
+
*/
|
|
9
|
+
import { createRootCapability } from '@interop/zcap';
|
|
10
|
+
import { encodeCapability } from './encoding.js';
|
|
11
|
+
/**
|
|
12
|
+
* Creates a root capability for an invocation target.
|
|
13
|
+
*
|
|
14
|
+
* @param options {object}
|
|
15
|
+
* @param options.controller {string} The DID authorized to invoke (the root
|
|
16
|
+
* controller).
|
|
17
|
+
* @param options.url {string} The resource URI the capability targets (the
|
|
18
|
+
* `invocationTarget`).
|
|
19
|
+
* @returns {{rootCapability: IRootZcap, encoded: string}} The root capability
|
|
20
|
+
* and its multibase (base58btc) encoding.
|
|
21
|
+
*/
|
|
22
|
+
export function createCapability({ controller, url }) {
|
|
23
|
+
const rootCapability = createRootCapability({
|
|
24
|
+
controller,
|
|
25
|
+
invocationTarget: url
|
|
26
|
+
});
|
|
27
|
+
return { rootCapability, encoded: encodeCapability(rootCapability) };
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/zcap/create.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAEhD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAC/B,UAAU,EACV,GAAG,EAIJ;IACC,MAAM,cAAc,GAAG,oBAAoB,CAAC;QAC1C,UAAU;QACV,gBAAgB,EAAE,GAAG;KACtB,CAAC,CAAA;IACF,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,gBAAgB,CAAC,cAAc,CAAC,EAAE,CAAA;AACtE,CAAC"}
|