@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.
Files changed (116) hide show
  1. package/CHANGELOG.md +341 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +1307 -0
  4. package/dist/commands/did.d.ts +3 -0
  5. package/dist/commands/did.d.ts.map +1 -0
  6. package/dist/commands/did.js +605 -0
  7. package/dist/commands/did.js.map +1 -0
  8. package/dist/commands/key.d.ts +3 -0
  9. package/dist/commands/key.d.ts.map +1 -0
  10. package/dist/commands/key.js +430 -0
  11. package/dist/commands/key.js.map +1 -0
  12. package/dist/commands/vc.d.ts +79 -0
  13. package/dist/commands/vc.d.ts.map +1 -0
  14. package/dist/commands/vc.js +528 -0
  15. package/dist/commands/vc.js.map +1 -0
  16. package/dist/commands/wallet.d.ts +14 -0
  17. package/dist/commands/wallet.d.ts.map +1 -0
  18. package/dist/commands/wallet.js +48 -0
  19. package/dist/commands/wallet.js.map +1 -0
  20. package/dist/commands/was.d.ts +500 -0
  21. package/dist/commands/was.d.ts.map +1 -0
  22. package/dist/commands/was.js +1833 -0
  23. package/dist/commands/was.js.map +1 -0
  24. package/dist/commands/zcap.d.ts +85 -0
  25. package/dist/commands/zcap.d.ts.map +1 -0
  26. package/dist/commands/zcap.js +447 -0
  27. package/dist/commands/zcap.js.map +1 -0
  28. package/dist/index.d.ts +3 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +20 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/keys/ecdsa.d.ts +40 -0
  33. package/dist/keys/ecdsa.d.ts.map +1 -0
  34. package/dist/keys/ecdsa.js +73 -0
  35. package/dist/keys/ecdsa.js.map +1 -0
  36. package/dist/meta.d.ts +164 -0
  37. package/dist/meta.d.ts.map +1 -0
  38. package/dist/meta.js +286 -0
  39. package/dist/meta.js.map +1 -0
  40. package/dist/storage.d.ts +191 -0
  41. package/dist/storage.d.ts.map +1 -0
  42. package/dist/storage.js +307 -0
  43. package/dist/storage.js.map +1 -0
  44. package/dist/table.d.ts +43 -0
  45. package/dist/table.d.ts.map +1 -0
  46. package/dist/table.js +61 -0
  47. package/dist/table.js.map +1 -0
  48. package/dist/vc/fixtures/welcomeCredential.d.ts +22 -0
  49. package/dist/vc/fixtures/welcomeCredential.d.ts.map +1 -0
  50. package/dist/vc/fixtures/welcomeCredential.js +25 -0
  51. package/dist/vc/fixtures/welcomeCredential.js.map +1 -0
  52. package/dist/vc/issue.d.ts +24 -0
  53. package/dist/vc/issue.d.ts.map +1 -0
  54. package/dist/vc/issue.js +211 -0
  55. package/dist/vc/issue.js.map +1 -0
  56. package/dist/vc/registries.d.ts +30 -0
  57. package/dist/vc/registries.d.ts.map +1 -0
  58. package/dist/vc/registries.js +53 -0
  59. package/dist/vc/registries.js.map +1 -0
  60. package/dist/vc/registryManager.d.ts +25 -0
  61. package/dist/vc/registryManager.d.ts.map +1 -0
  62. package/dist/vc/registryManager.js +29 -0
  63. package/dist/vc/registryManager.js.map +1 -0
  64. package/dist/vc/suites/expirationSuite.d.ts +23 -0
  65. package/dist/vc/suites/expirationSuite.d.ts.map +1 -0
  66. package/dist/vc/suites/expirationSuite.js +84 -0
  67. package/dist/vc/suites/expirationSuite.js.map +1 -0
  68. package/dist/vc/suites/issuerDetailsSuite.d.ts +22 -0
  69. package/dist/vc/suites/issuerDetailsSuite.d.ts.map +1 -0
  70. package/dist/vc/suites/issuerDetailsSuite.js +69 -0
  71. package/dist/vc/suites/issuerDetailsSuite.js.map +1 -0
  72. package/dist/vc/verify.d.ts +46 -0
  73. package/dist/vc/verify.d.ts.map +1 -0
  74. package/dist/vc/verify.js +147 -0
  75. package/dist/vc/verify.js.map +1 -0
  76. package/dist/was/address.d.ts +44 -0
  77. package/dist/was/address.d.ts.map +1 -0
  78. package/dist/was/address.js +98 -0
  79. package/dist/was/address.js.map +1 -0
  80. package/dist/was/capability.d.ts +65 -0
  81. package/dist/was/capability.d.ts.map +1 -0
  82. package/dist/was/capability.js +108 -0
  83. package/dist/was/capability.js.map +1 -0
  84. package/dist/was/client.d.ts +108 -0
  85. package/dist/was/client.d.ts.map +1 -0
  86. package/dist/was/client.js +142 -0
  87. package/dist/was/client.js.map +1 -0
  88. package/dist/was/io.d.ts +71 -0
  89. package/dist/was/io.d.ts.map +1 -0
  90. package/dist/was/io.js +146 -0
  91. package/dist/was/io.js.map +1 -0
  92. package/dist/was/registry.d.ts +79 -0
  93. package/dist/was/registry.d.ts.map +1 -0
  94. package/dist/was/registry.js +99 -0
  95. package/dist/was/registry.js.map +1 -0
  96. package/dist/zcap/create.d.ts +20 -0
  97. package/dist/zcap/create.d.ts.map +1 -0
  98. package/dist/zcap/create.js +29 -0
  99. package/dist/zcap/create.js.map +1 -0
  100. package/dist/zcap/delegate.d.ts +44 -0
  101. package/dist/zcap/delegate.d.ts.map +1 -0
  102. package/dist/zcap/delegate.js +77 -0
  103. package/dist/zcap/delegate.js.map +1 -0
  104. package/dist/zcap/encoding.d.ts +17 -0
  105. package/dist/zcap/encoding.d.ts.map +1 -0
  106. package/dist/zcap/encoding.js +37 -0
  107. package/dist/zcap/encoding.js.map +1 -0
  108. package/dist/zcap/signer.d.ts +20 -0
  109. package/dist/zcap/signer.d.ts.map +1 -0
  110. package/dist/zcap/signer.js +62 -0
  111. package/dist/zcap/signer.js.map +1 -0
  112. package/dist/zcap/ttl.d.ts +19 -0
  113. package/dist/zcap/ttl.d.ts.map +1 -0
  114. package/dist/zcap/ttl.js +40 -0
  115. package/dist/zcap/ttl.js.map +1 -0
  116. package/package.json +64 -0
@@ -0,0 +1,44 @@
1
+ import type { IDelegatedZcap, IZcap } from '@interop/data-integrity-core/zcap';
2
+ /**
3
+ * Signs a delegated capability.
4
+ *
5
+ * Exactly one of `url` (first-level delegation from the root capability for that
6
+ * target) or `capability` (further delegation of an existing capability) drives
7
+ * the parent; `invocationTarget` narrows the target when delegating an existing
8
+ * capability. Expiration is `expires` (an ISO 8601 date) when given, otherwise
9
+ * derived from `ttl`.
10
+ *
11
+ * @param options {object}
12
+ * @param [options.did] {string} The id of a stored DID to sign with.
13
+ * @param [options.controller] {string} The expected controller DID, when
14
+ * signing via `ZCAP_CONTROLLER_KEY_SEED`.
15
+ * @param options.delegatee {string} The DID to delegate to (the new
16
+ * capability's controller).
17
+ * @param [options.url] {string} The invocation target for a first-level
18
+ * delegation from the root capability.
19
+ * @param [options.capability] {IZcap} A parent capability to delegate (already
20
+ * decoded from its multibase string or a JSON file).
21
+ * @param [options.invocationTarget] {string} An attenuated invocation target.
22
+ * @param [options.allow] {string[]} Allowed actions; omitted inherits the
23
+ * parent's actions.
24
+ * @param [options.ttl] {string} Time-to-live for expiration (default `1y`).
25
+ * @param [options.expires] {string} Explicit ISO 8601 expiration (overrides
26
+ * `ttl`).
27
+ * @returns {Promise<{delegatedCapability: IDelegatedZcap, encoded: string}>}
28
+ * The signed delegated capability and its multibase (base58btc) encoding.
29
+ */
30
+ export declare function delegateCapability({ did, controller, delegatee, url, capability, invocationTarget, allow, ttl, expires }: {
31
+ did?: string;
32
+ controller?: string;
33
+ delegatee: string;
34
+ url?: string;
35
+ capability?: IZcap;
36
+ invocationTarget?: string;
37
+ allow?: string[];
38
+ ttl?: string;
39
+ expires?: string;
40
+ }): Promise<{
41
+ delegatedCapability: IDelegatedZcap;
42
+ encoded: string;
43
+ }>;
44
+ //# sourceMappingURL=delegate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delegate.d.ts","sourceRoot":"","sources":["../../src/zcap/delegate.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAA;AAW9E;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,kBAAkB,CAAC,EACvC,GAAG,EACH,UAAU,EACV,SAAS,EACT,GAAG,EACH,UAAU,EACV,gBAAgB,EAChB,KAAK,EACL,GAAU,EACV,OAAO,EACR,EAAE;IACD,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,UAAU,CAAC,EAAE,KAAK,CAAA;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,GAAG,OAAO,CAAC;IAAE,mBAAmB,EAAE,cAAc,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAuBpE"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Delegated Authorization Capability (zcap) signing.
3
+ *
4
+ * `delegateCapability` signs a delegated capability using @interop/ezcap's
5
+ * `ZcapClient.delegate`, which builds the delegated zcap (id, controller,
6
+ * parent, invocation target, expiration, allowed actions), auto-computes the
7
+ * capability chain, and signs it with the delegator's `capabilityDelegation`
8
+ * key. For a first-level delegation the parent is the root capability generated
9
+ * from the invocation target; for further (attenuated) delegation a decoded
10
+ * parent capability is passed instead. The signing key is resolved from a stored
11
+ * DID or `ZCAP_CONTROLLER_KEY_SEED` (see `loadDelegationSigner`).
12
+ *
13
+ * The document loader is `@interop/security-document-loader`'s loader, which
14
+ * already bundles the zcap JSON-LD context (and the ed25519-2020 suite context),
15
+ * so it can be passed to `ZcapClient` as-is.
16
+ */
17
+ import { Ed25519Signature2020 } from '@interop/ed25519-signature';
18
+ import { ZcapClient } from '@interop/ezcap';
19
+ import { securityLoader } from '@interop/security-document-loader';
20
+ import { encodeCapability } from './encoding.js';
21
+ import { expiresFromTtl } from './ttl.js';
22
+ import { loadDelegationSigner } from './signer.js';
23
+ /**
24
+ * Offline document loader for signing: bundles the zcap, VC, Data Integrity, and
25
+ * suite contexts plus a did:key resolver. Built once and reused across calls.
26
+ */
27
+ const documentLoader = securityLoader().build();
28
+ /**
29
+ * Signs a delegated capability.
30
+ *
31
+ * Exactly one of `url` (first-level delegation from the root capability for that
32
+ * target) or `capability` (further delegation of an existing capability) drives
33
+ * the parent; `invocationTarget` narrows the target when delegating an existing
34
+ * capability. Expiration is `expires` (an ISO 8601 date) when given, otherwise
35
+ * derived from `ttl`.
36
+ *
37
+ * @param options {object}
38
+ * @param [options.did] {string} The id of a stored DID to sign with.
39
+ * @param [options.controller] {string} The expected controller DID, when
40
+ * signing via `ZCAP_CONTROLLER_KEY_SEED`.
41
+ * @param options.delegatee {string} The DID to delegate to (the new
42
+ * capability's controller).
43
+ * @param [options.url] {string} The invocation target for a first-level
44
+ * delegation from the root capability.
45
+ * @param [options.capability] {IZcap} A parent capability to delegate (already
46
+ * decoded from its multibase string or a JSON file).
47
+ * @param [options.invocationTarget] {string} An attenuated invocation target.
48
+ * @param [options.allow] {string[]} Allowed actions; omitted inherits the
49
+ * parent's actions.
50
+ * @param [options.ttl] {string} Time-to-live for expiration (default `1y`).
51
+ * @param [options.expires] {string} Explicit ISO 8601 expiration (overrides
52
+ * `ttl`).
53
+ * @returns {Promise<{delegatedCapability: IDelegatedZcap, encoded: string}>}
54
+ * The signed delegated capability and its multibase (base58btc) encoding.
55
+ */
56
+ export async function delegateCapability({ did, controller, delegatee, url, capability, invocationTarget, allow, ttl = '1y', expires }) {
57
+ const delegationSigner = await loadDelegationSigner({ did, controller });
58
+ const client = new ZcapClient({
59
+ SuiteClass: Ed25519Signature2020,
60
+ delegationSigner,
61
+ documentLoader
62
+ });
63
+ const expiresValue = expires ?? expiresFromTtl(ttl);
64
+ const target = invocationTarget ?? url;
65
+ const delegatedCapability = await client.delegate({
66
+ capability,
67
+ controller: delegatee,
68
+ invocationTarget: target,
69
+ expires: expiresValue,
70
+ allowedActions: allow
71
+ });
72
+ return {
73
+ delegatedCapability,
74
+ encoded: encodeCapability(delegatedCapability)
75
+ };
76
+ }
77
+ //# sourceMappingURL=delegate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delegate.js","sourceRoot":"","sources":["../../src/zcap/delegate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AAElE,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAElD;;;GAGG;AACH,MAAM,cAAc,GAAG,cAAc,EAAE,CAAC,KAAK,EAAE,CAAA;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,EACvC,GAAG,EACH,UAAU,EACV,SAAS,EACT,GAAG,EACH,UAAU,EACV,gBAAgB,EAChB,KAAK,EACL,GAAG,GAAG,IAAI,EACV,OAAO,EAWR;IACC,MAAM,gBAAgB,GAAG,MAAM,oBAAoB,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,CAAA;IACxE,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC;QAC5B,UAAU,EAAE,oBAAoB;QAChC,gBAAgB;QAChB,cAAc;KACf,CAAC,CAAA;IAEF,MAAM,YAAY,GAAG,OAAO,IAAI,cAAc,CAAC,GAAG,CAAC,CAAA;IACnD,MAAM,MAAM,GAAG,gBAAgB,IAAI,GAAG,CAAA;IAEtC,MAAM,mBAAmB,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC;QAChD,UAAU;QACV,UAAU,EAAE,SAAS;QACrB,gBAAgB,EAAE,MAAM;QACxB,OAAO,EAAE,YAAY;QACrB,cAAc,EAAE,KAAK;KACtB,CAAC,CAAA;IAEF,OAAO;QACL,mBAAmB;QACnB,OAAO,EAAE,gBAAgB,CAAC,mBAAmB,CAAC;KAC/C,CAAA;AACH,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { IZcap } from '@interop/data-integrity-core/zcap';
2
+ /**
3
+ * Encodes a capability as a multibase (base58btc) string.
4
+ *
5
+ * @param capability {IZcap} The root or delegated capability to encode.
6
+ * @returns {string} The capability JSON, base58btc-encoded with a leading `z`.
7
+ */
8
+ export declare function encodeCapability(capability: IZcap): string;
9
+ /**
10
+ * Decodes a multibase (base58btc) capability string back into a capability.
11
+ *
12
+ * @param encoded {string} A `z`-prefixed base58btc string from
13
+ * `encodeCapability`.
14
+ * @returns {IZcap} The decoded root or delegated capability.
15
+ */
16
+ export declare function decodeCapability(encoded: string): IZcap;
17
+ //# sourceMappingURL=encoding.d.ts.map
@@ -0,0 +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;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,KAAK,GAAG,MAAM,CAG1D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAQvD"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Multibase (base58btc) encoding for Authorization Capabilities (zcaps).
3
+ *
4
+ * The CLI prints an `encoded` form alongside each capability: the capability's
5
+ * JSON serialized to UTF-8 bytes, base58btc-encoded, with a leading `z`
6
+ * multibase prefix (matching the legacy did-cli output). `decodeCapability`
7
+ * reverses this so a delegated capability can be passed back in via
8
+ * `zcap delegate --capability`. Uses `@scure/base`'s `base58` (the same base58
9
+ * implementation used by `@interop/ed25519-verification-key`), which operates on
10
+ * raw base58 without a multibase prefix, so the `z` is added/stripped here.
11
+ */
12
+ import { base58 } from '@scure/base';
13
+ /**
14
+ * Encodes a capability as a multibase (base58btc) string.
15
+ *
16
+ * @param capability {IZcap} The root or delegated capability to encode.
17
+ * @returns {string} The capability JSON, base58btc-encoded with a leading `z`.
18
+ */
19
+ export function encodeCapability(capability) {
20
+ const bytes = new TextEncoder().encode(JSON.stringify(capability));
21
+ return `z${base58.encode(bytes)}`;
22
+ }
23
+ /**
24
+ * Decodes a multibase (base58btc) capability string back into a capability.
25
+ *
26
+ * @param encoded {string} A `z`-prefixed base58btc string from
27
+ * `encodeCapability`.
28
+ * @returns {IZcap} The decoded root or delegated capability.
29
+ */
30
+ export function decodeCapability(encoded) {
31
+ if (!encoded.startsWith('z')) {
32
+ throw new Error('Encoded capability must be a multibase base58btc string (leading "z").');
33
+ }
34
+ const bytes = base58.decode(encoded.slice(1));
35
+ return JSON.parse(new TextDecoder().decode(bytes));
36
+ }
37
+ //# sourceMappingURL=encoding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encoding.js","sourceRoot":"","sources":["../../src/zcap/encoding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAGpC;;;;;GAKG;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,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAA;AACnC,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,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IAC7C,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAU,CAAA;AAC7D,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { ISigner } from '@interop/data-integrity-core';
2
+ /**
3
+ * Loads the delegation signer for `zcap delegate`.
4
+ *
5
+ * When `did` is given, the signer is loaded from the locally-stored DID and its
6
+ * secret key file. Otherwise the `ZCAP_CONTROLLER_KEY_SEED` environment variable
7
+ * is required and the `did:key` is regenerated from it, with `controller` used
8
+ * to verify the regenerated DID matches the caller's expectation.
9
+ *
10
+ * @param options {object}
11
+ * @param [options.did] {string} The id of a locally-stored DID to sign with.
12
+ * @param [options.controller] {string} The expected controller DID, required
13
+ * (and verified) when signing via `ZCAP_CONTROLLER_KEY_SEED`.
14
+ * @returns {Promise<ISigner>} The `capabilityDelegation` signer.
15
+ */
16
+ export declare function loadDelegationSigner({ did, controller }: {
17
+ did?: string;
18
+ controller?: string;
19
+ }): Promise<ISigner>;
20
+ //# sourceMappingURL=signer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/zcap/signer.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAqB3D;;;;;;;;;;;;;GAaG;AACH,wBAAsB,oBAAoB,CAAC,EACzC,GAAG,EACH,UAAU,EACX,EAAE;IACD,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,GAAG,OAAO,CAAC,OAAO,CAAC,CAoCnB"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Loads the `capabilityDelegation` signer used to sign delegated capabilities.
3
+ *
4
+ * Two key-sourcing modes are supported, mirroring the rest of the CLI and the
5
+ * legacy did-cli respectively:
6
+ *
7
+ * - Stored DID (`--did`): the DID document and its secret key are read from
8
+ * local storage (`~/.config/did-cli-wallet/dids/`, the store written by `id create --save`),
9
+ * exactly as `vc issue` loads its signing key. For `did:key` the single key
10
+ * serves the `capabilityDelegation` relationship.
11
+ * - Env seed (`ZCAP_CONTROLLER_KEY_SEED` + `--controller`): the `did:key` is
12
+ * regenerated from the seed, its id is checked against `--controller`, and the
13
+ * `capabilityDelegation` key is used to sign.
14
+ */
15
+ import { decodeSecretKeySeed } from '@digitalcredentials/bnid';
16
+ import { driver } from '@interop/did-method-key';
17
+ import { Ed25519VerificationKey } from '@interop/ed25519-verification-key';
18
+ import { createSigner } from '@interop/ed25519-signature';
19
+ import { loadDidDocument, loadDidKeys } from '../storage.js';
20
+ /**
21
+ * Loads the delegation signer for `zcap delegate`.
22
+ *
23
+ * When `did` is given, the signer is loaded from the locally-stored DID and its
24
+ * secret key file. Otherwise the `ZCAP_CONTROLLER_KEY_SEED` environment variable
25
+ * is required and the `did:key` is regenerated from it, with `controller` used
26
+ * to verify the regenerated DID matches the caller's expectation.
27
+ *
28
+ * @param options {object}
29
+ * @param [options.did] {string} The id of a locally-stored DID to sign with.
30
+ * @param [options.controller] {string} The expected controller DID, required
31
+ * (and verified) when signing via `ZCAP_CONTROLLER_KEY_SEED`.
32
+ * @returns {Promise<ISigner>} The `capabilityDelegation` signer.
33
+ */
34
+ export async function loadDelegationSigner({ did, controller }) {
35
+ if (did) {
36
+ await loadDidDocument(did);
37
+ const keysData = await loadDidKeys(did);
38
+ const keyPair = await Ed25519VerificationKey.from(keysData);
39
+ return createSigner(keyPair);
40
+ }
41
+ const secretKeySeed = process.env.ZCAP_CONTROLLER_KEY_SEED;
42
+ if (!secretKeySeed) {
43
+ throw new Error('Provide --did (a stored DID) or set ZCAP_CONTROLLER_KEY_SEED with ' +
44
+ '--controller to sign the delegation.');
45
+ }
46
+ if (!controller) {
47
+ throw new Error('--controller is required when signing via ZCAP_CONTROLLER_KEY_SEED.');
48
+ }
49
+ const seedBytes = decodeSecretKeySeed({ secretKeySeed });
50
+ const didDriver = driver();
51
+ didDriver.use({ keyPairClass: Ed25519VerificationKey });
52
+ const { didDocument, methodFor } = await didDriver.generate({
53
+ seed: seedBytes
54
+ });
55
+ if (didDocument.id !== controller) {
56
+ throw new Error(`The DID generated from ZCAP_CONTROLLER_KEY_SEED (${didDocument.id}) ` +
57
+ `does not match --controller (${controller}).`);
58
+ }
59
+ const delegationKey = methodFor({ purpose: 'capabilityDelegation' });
60
+ return createSigner(delegationKey);
61
+ }
62
+ //# sourceMappingURL=signer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signer.js","sourceRoot":"","sources":["../../src/zcap/signer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAChD,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAA;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAEzD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAoB5D;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,EACzC,GAAG,EACH,UAAU,EAIX;IACC,IAAI,GAAG,EAAE,CAAC;QACR,MAAM,eAAe,CAAC,GAAG,CAAC,CAAA;QAC1B,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAgB,GAAG,CAAC,CAAA;QACtD,MAAM,OAAO,GAAG,MAAM,sBAAsB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC3D,OAAO,YAAY,CAAC,OAAO,CAAC,CAAA;IAC9B,CAAC;IAED,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAA;IAC1D,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CACb,oEAAoE;YAClE,sCAAsC,CACzC,CAAA;IACH,CAAC;IACD,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CACb,qEAAqE,CACtE,CAAA;IACH,CAAC;IACD,MAAM,SAAS,GAAG,mBAAmB,CAAC,EAAE,aAAa,EAAE,CAAC,CAAA;IACxD,MAAM,SAAS,GAAG,MAAM,EAAE,CAAA;IAC1B,SAAS,CAAC,GAAG,CAAC,EAAE,YAAY,EAAE,sBAAsB,EAAE,CAAC,CAAA;IACvD,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC;QAC1D,IAAI,EAAE,SAAS;KAChB,CAAC,CAAA;IACF,IAAI,WAAW,CAAC,EAAE,KAAK,UAAU,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CACb,oDAAoD,WAAW,CAAC,EAAE,IAAI;YACpE,gCAAgC,UAAU,IAAI,CACjD,CAAA;IACH,CAAC;IACD,MAAM,aAAa,GACjB,SACD,CAAC,EAAE,OAAO,EAAE,sBAAsB,EAAE,CAAC,CAAA;IACtC,OAAO,YAAY,CAAC,aAAa,CAAC,CAAA;AACpC,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Time-to-live parsing for delegated capability expiration.
3
+ *
4
+ * `expiresFromTtl` turns a short duration string (e.g. `1y`, `30d`, `24h`) into
5
+ * an absolute expiration `Date` relative to now, used as the default `expires`
6
+ * for `zcap delegate` when an explicit `--expires` ISO date is not given.
7
+ */
8
+ /**
9
+ * Parses a time-to-live duration string into an absolute expiration date.
10
+ *
11
+ * The format is an integer followed by a unit: `s` (seconds), `m` (minutes),
12
+ * `h` (hours), `d` (days), `w` (weeks), or `y` (365 days), e.g. `1y`, `30d`,
13
+ * `24h`, `15m`.
14
+ *
15
+ * @param ttl {string} The duration string.
16
+ * @returns {Date} `now + ttl`.
17
+ */
18
+ export declare function expiresFromTtl(ttl: string): Date;
19
+ //# sourceMappingURL=ttl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ttl.d.ts","sourceRoot":"","sources":["../../src/zcap/ttl.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAeH;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAWhD"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Time-to-live parsing for delegated capability expiration.
3
+ *
4
+ * `expiresFromTtl` turns a short duration string (e.g. `1y`, `30d`, `24h`) into
5
+ * an absolute expiration `Date` relative to now, used as the default `expires`
6
+ * for `zcap delegate` when an explicit `--expires` ISO date is not given.
7
+ */
8
+ /**
9
+ * Supported duration units and their length in milliseconds. Note `m` is
10
+ * minutes (not months) and `y` is treated as 365 days.
11
+ */
12
+ const UNIT_MS = {
13
+ s: 1000,
14
+ m: 60 * 1000,
15
+ h: 60 * 60 * 1000,
16
+ d: 24 * 60 * 60 * 1000,
17
+ w: 7 * 24 * 60 * 60 * 1000,
18
+ y: 365 * 24 * 60 * 60 * 1000
19
+ };
20
+ /**
21
+ * Parses a time-to-live duration string into an absolute expiration date.
22
+ *
23
+ * The format is an integer followed by a unit: `s` (seconds), `m` (minutes),
24
+ * `h` (hours), `d` (days), `w` (weeks), or `y` (365 days), e.g. `1y`, `30d`,
25
+ * `24h`, `15m`.
26
+ *
27
+ * @param ttl {string} The duration string.
28
+ * @returns {Date} `now + ttl`.
29
+ */
30
+ export function expiresFromTtl(ttl) {
31
+ const match = /^(\d+)([smhdwy])$/.exec(ttl.trim());
32
+ if (!match) {
33
+ throw new Error(`Invalid --ttl value "${ttl}". Expected a number followed by a unit ` +
34
+ '(s, m, h, d, w, or y), e.g. 1y, 30d, 24h.');
35
+ }
36
+ const amount = Number(match[1]);
37
+ const unitMs = UNIT_MS[match[2]];
38
+ return new Date(Date.now() + amount * unitMs);
39
+ }
40
+ //# sourceMappingURL=ttl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ttl.js","sourceRoot":"","sources":["../../src/zcap/ttl.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;GAGG;AACH,MAAM,OAAO,GAA2B;IACtC,CAAC,EAAE,IAAI;IACP,CAAC,EAAE,EAAE,GAAG,IAAI;IACZ,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;IACjB,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IACtB,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAC1B,CAAC,EAAE,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;CAC7B,CAAA;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,MAAM,KAAK,GAAG,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;IAClD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CACb,wBAAwB,GAAG,0CAA0C;YACnE,2CAA2C,CAC9C,CAAA;IACH,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IAC/B,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IAChC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,GAAG,MAAM,CAAC,CAAA;AAC/C,CAAC"}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@interop/did-cli",
3
+ "version": "0.6.0",
4
+ "description": "DID CLI tool for DIDs, Verifiable Credentials, key pairs, and zcaps",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "bin": {
8
+ "di": "dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "CHANGELOG.md"
13
+ ],
14
+ "scripts": {
15
+ "build": "npm run clean && tsc",
16
+ "build:watch": "tsc --watch",
17
+ "clean": "rm -rf dist",
18
+ "fix": "eslint --fix src && npm run format",
19
+ "format": "prettier --write src",
20
+ "lint": "eslint src",
21
+ "prepublishOnly": "npm run build",
22
+ "start": "node --enable-source-maps dist/index.js",
23
+ "test": "npm run lint && npm run format && npm run test:node",
24
+ "test:node": "node --test --import tsx --enable-source-maps 'src/**/*.test.ts'"
25
+ },
26
+ "dependencies": {
27
+ "@digitalcredentials/bnid": "^5.0.0",
28
+ "@digitalcredentials/issuer-registry-client": "^4.0.0",
29
+ "@interop/data-integrity-core": "^7.0.0",
30
+ "@interop/data-integrity-proof": "^3.3.1",
31
+ "@interop/did-method-key": "^7.3.1",
32
+ "@interop/did-web-resolver": "^6.2.1",
33
+ "@interop/ecdsa-multikey": "^2.3.0",
34
+ "@interop/ecdsa-signature": "2.0.2",
35
+ "@interop/ed25519-signature": "^7.1.1",
36
+ "@interop/ed25519-verification-key": "^8.0.0",
37
+ "@interop/ezcap": "^7.2.0",
38
+ "@interop/security-document-loader": "^9.3.0",
39
+ "@interop/vc": "^11.0.3",
40
+ "@interop/verifier-core": "^3.2.0",
41
+ "@interop/was-client": "^0.3.0",
42
+ "@interop/zcap": "^11.0.2",
43
+ "@scure/base": "^2.2.0",
44
+ "commander": "^15.0.0"
45
+ },
46
+ "packageManager": "pnpm@11.5.0",
47
+ "engines": {
48
+ "node": ">=22"
49
+ },
50
+ "devDependencies": {
51
+ "@eslint/js": "^10.0.1",
52
+ "@types/node": "^25.6.0",
53
+ "eslint": "^10.2.0",
54
+ "eslint-config-prettier": "^10.1.8",
55
+ "globals": "^17.5.0",
56
+ "prettier": "^3.8.2",
57
+ "tsx": "^4.21.0",
58
+ "typescript": "^5.0.0",
59
+ "typescript-eslint": "^8.58.2"
60
+ },
61
+ "publishConfig": {
62
+ "access": "public"
63
+ }
64
+ }