@twin.org/identity-cli 0.0.3-next.2 → 0.0.3-next.20

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 (49) hide show
  1. package/README.md +5 -5
  2. package/dist/es/cli.js +9 -1
  3. package/dist/es/cli.js.map +1 -1
  4. package/dist/es/commands/alsoKnownAsAdd.js +108 -0
  5. package/dist/es/commands/alsoKnownAsAdd.js.map +1 -0
  6. package/dist/es/commands/alsoKnownAsRemove.js +106 -0
  7. package/dist/es/commands/alsoKnownAsRemove.js.map +1 -0
  8. package/dist/es/commands/identityCreate.js +2 -1
  9. package/dist/es/commands/identityCreate.js.map +1 -1
  10. package/dist/es/commands/proofCreate.js +4 -9
  11. package/dist/es/commands/proofCreate.js.map +1 -1
  12. package/dist/es/commands/serviceAdd.js +4 -3
  13. package/dist/es/commands/serviceAdd.js.map +1 -1
  14. package/dist/es/commands/serviceRemove.js +3 -3
  15. package/dist/es/commands/serviceRemove.js.map +1 -1
  16. package/dist/es/commands/verifiableCredentialCreate.js +18 -16
  17. package/dist/es/commands/verifiableCredentialCreate.js.map +1 -1
  18. package/dist/es/commands/verifiableCredentialVerify.js +24 -5
  19. package/dist/es/commands/verifiableCredentialVerify.js.map +1 -1
  20. package/dist/es/commands/verifiablePresentationCreate.js +137 -0
  21. package/dist/es/commands/verifiablePresentationCreate.js.map +1 -0
  22. package/dist/es/commands/verifiablePresentationVerify.js +107 -0
  23. package/dist/es/commands/verifiablePresentationVerify.js.map +1 -0
  24. package/dist/es/commands/verificationMethodAdd.js +31 -10
  25. package/dist/es/commands/verificationMethodAdd.js.map +1 -1
  26. package/dist/es/index.js +2 -0
  27. package/dist/es/index.js.map +1 -1
  28. package/dist/locales/en.json +196 -38
  29. package/dist/types/commands/alsoKnownAsAdd.d.ts +30 -0
  30. package/dist/types/commands/alsoKnownAsRemove.d.ts +30 -0
  31. package/dist/types/commands/identityCreate.d.ts +1 -0
  32. package/dist/types/commands/proofCreate.d.ts +0 -2
  33. package/dist/types/commands/verifiableCredentialCreate.d.ts +4 -4
  34. package/dist/types/commands/verifiableCredentialVerify.d.ts +3 -1
  35. package/dist/types/commands/verifiablePresentationCreate.d.ts +32 -0
  36. package/dist/types/commands/verifiablePresentationVerify.d.ts +24 -0
  37. package/dist/types/index.d.ts +2 -0
  38. package/docs/changelog.md +404 -90
  39. package/docs/reference/classes/CLI.md +1 -1
  40. package/docs/reference/functions/actionCommandVerifiablePresentationCreate.md +17 -0
  41. package/docs/reference/functions/actionCommandVerifiablePresentationVerify.md +17 -0
  42. package/docs/reference/functions/buildCommandVerifiablePresentationCreate.md +11 -0
  43. package/docs/reference/functions/buildCommandVerifiablePresentationVerify.md +11 -0
  44. package/docs/reference/index.md +4 -0
  45. package/docs/reference/variables/IdentityConnectorTypes.md +1 -1
  46. package/docs/reference/variables/IdentityResolverConnectorTypes.md +1 -1
  47. package/docs/{examples.md → usage.md} +23 -27
  48. package/locales/en.json +153 -12
  49. package/package.json +5 -5
@@ -0,0 +1,107 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import path from "node:path";
4
+ import { CLIDisplay, CLIOptions, CLIParam, CLIUtils } from "@twin.org/cli-core";
5
+ import { GeneralError, I18n, Is } from "@twin.org/core";
6
+ import { setupWalletConnector } from "@twin.org/wallet-cli";
7
+ import { WalletConnectorFactory } from "@twin.org/wallet-models";
8
+ import { Command, Option } from "commander";
9
+ import { setupIdentityConnector, setupVault } from "./setupCommands.js";
10
+ import { IdentityConnectorTypes } from "../models/identityConnectorTypes.js";
11
+ /**
12
+ * Build the verifiable presentation verify command for the CLI.
13
+ * @returns The command.
14
+ */
15
+ export function buildCommandVerifiablePresentationVerify() {
16
+ const command = new Command();
17
+ command
18
+ .name("verifiable-presentation-verify")
19
+ .summary(I18n.formatMessage("commands.verifiable-presentation-verify.summary"))
20
+ .description(I18n.formatMessage("commands.verifiable-presentation-verify.description"))
21
+ .option(I18n.formatMessage("commands.verifiable-presentation-verify.options.jwt.param"), I18n.formatMessage("commands.verifiable-presentation-verify.options.jwt.description"))
22
+ .option(I18n.formatMessage("commands.verifiable-presentation-verify.options.json-ld.param"), I18n.formatMessage("commands.verifiable-presentation-verify.options.json-ld.description"));
23
+ CLIOptions.output(command, {
24
+ noConsole: true,
25
+ json: true,
26
+ env: true,
27
+ mergeJson: true,
28
+ mergeEnv: true
29
+ });
30
+ command
31
+ .addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
32
+ .choices(Object.values(IdentityConnectorTypes))
33
+ .default(IdentityConnectorTypes.Iota))
34
+ .option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
35
+ .option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
36
+ .action(actionCommandVerifiablePresentationVerify);
37
+ return command;
38
+ }
39
+ /**
40
+ * Action the verifiable presentation verify command.
41
+ * @param opts The options for the command.
42
+ * @param opts.jwt The JSON web token for the verifiable presentation.
43
+ * @param opts.jsonLd The filename of a JSON-LD verifiable presentation to verify.
44
+ * @param opts.connector The connector to perform the operations with.
45
+ * @param opts.node The node URL.
46
+ * @param opts.network The network name.
47
+ */
48
+ export async function actionCommandVerifiablePresentationVerify(opts) {
49
+ const nodeEndpoint = CLIParam.url("node", opts.node);
50
+ const network = opts.connector === IdentityConnectorTypes.Iota
51
+ ? CLIParam.stringValue("network", opts.network)
52
+ : undefined;
53
+ let presentation;
54
+ if (Is.stringValue(opts.jwt)) {
55
+ const jwt = CLIParam.stringValue("jwt", opts.jwt);
56
+ CLIDisplay.value(I18n.formatMessage("commands.verifiable-presentation-verify.labels.jwt"), jwt);
57
+ presentation = jwt;
58
+ }
59
+ else if (Is.stringValue(opts.jsonLd)) {
60
+ const jsonLdPath = path.resolve(CLIParam.stringValue("json-ld", opts.jsonLd));
61
+ CLIDisplay.value(I18n.formatMessage("commands.verifiable-presentation-verify.labels.jsonLd"), jsonLdPath);
62
+ const jsonData = await CLIUtils.readJsonFile(jsonLdPath);
63
+ if (Is.undefined(jsonData)) {
64
+ throw new GeneralError("commands", "commands.verifiable-presentation-verify.jsonLdFileNotFound");
65
+ }
66
+ presentation = jsonData;
67
+ }
68
+ else {
69
+ throw new GeneralError("commands", "commands.verifiable-presentation-verify.noPresentationProvided");
70
+ }
71
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
72
+ if (Is.stringValue(network)) {
73
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
74
+ }
75
+ CLIDisplay.break();
76
+ setupVault();
77
+ const walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);
78
+ WalletConnectorFactory.register("wallet", () => walletConnector);
79
+ const identityConnector = setupIdentityConnector({ nodeEndpoint, network }, opts.connector);
80
+ CLIDisplay.task(I18n.formatMessage("commands.verifiable-presentation-verify.progress.verifyingPresentation"));
81
+ CLIDisplay.break();
82
+ CLIDisplay.spinnerStart();
83
+ const verification = await identityConnector.checkVerifiablePresentation(presentation);
84
+ const isVerified = Is.notEmpty(verification.verifiablePresentation);
85
+ const isRevoked = verification.revoked;
86
+ CLIDisplay.spinnerStop();
87
+ if (opts.console) {
88
+ CLIDisplay.value(I18n.formatMessage("commands.verifiable-presentation-verify.labels.isVerified"), isVerified);
89
+ CLIDisplay.value(I18n.formatMessage("commands.verifiable-presentation-verify.labels.isRevoked"), isRevoked);
90
+ CLIDisplay.break();
91
+ }
92
+ if (Is.stringValue(opts?.json)) {
93
+ await CLIUtils.writeJsonFile(opts.json, {
94
+ isVerified,
95
+ isRevoked,
96
+ verifiablePresentation: verification.verifiablePresentation
97
+ }, opts.mergeJson);
98
+ }
99
+ if (Is.stringValue(opts?.env)) {
100
+ await CLIUtils.writeEnvFile(opts.env, [
101
+ `DID_VERIFIABLE_PRESENTATION_VERIFIED="${isVerified}"`,
102
+ `DID_VERIFIABLE_PRESENTATION_REVOKED="${isRevoked}"`
103
+ ], opts.mergeEnv);
104
+ }
105
+ CLIDisplay.done();
106
+ }
107
+ //# sourceMappingURL=verifiablePresentationVerify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verifiablePresentationVerify.js","sourceRoot":"","sources":["../../../src/commands/verifiablePresentationVerify.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACN,UAAU,EACV,UAAU,EACV,QAAQ,EACR,QAAQ,EAER,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAE7E;;;GAGG;AACH,MAAM,UAAU,wCAAwC;IACvD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAC9B,OAAO;SACL,IAAI,CAAC,gCAAgC,CAAC;SACtC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,iDAAiD,CAAC,CAAC;SAC9E,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,qDAAqD,CAAC,CAAC;SACtF,MAAM,CACN,IAAI,CAAC,aAAa,CAAC,2DAA2D,CAAC,EAC/E,IAAI,CAAC,aAAa,CAAC,iEAAiE,CAAC,CACrF;SACA,MAAM,CACN,IAAI,CAAC,aAAa,CAAC,+DAA+D,CAAC,EACnF,IAAI,CAAC,aAAa,CAAC,qEAAqE,CAAC,CACzF,CAAC;IACH,UAAU,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U,GAAG;YACtD,wCAAwC,SAAS,GAAG;SACpD,EACD,IAAI,CAAC,QAAQ,CACb,CAAC;IACH,CAAC;IAED,UAAU,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport path from \"node:path\";\nimport {\n\tCLIDisplay,\n\tCLIOptions,\n\tCLIParam,\n\tCLIUtils,\n\ttype CliOutputOptions\n} from \"@twin.org/cli-core\";\nimport { GeneralError, I18n, Is } from \"@twin.org/core\";\nimport type { IDidVerifiablePresentation } from \"@twin.org/standards-w3c-did\";\nimport { setupWalletConnector } from \"@twin.org/wallet-cli\";\nimport { WalletConnectorFactory } from \"@twin.org/wallet-models\";\nimport { Command, Option } from \"commander\";\nimport { setupIdentityConnector, setupVault } from \"./setupCommands.js\";\nimport { IdentityConnectorTypes } from \"../models/identityConnectorTypes.js\";\n\n/**\n * Build the verifiable presentation verify command for the CLI.\n * @returns The command.\n */\nexport function buildCommandVerifiablePresentationVerify(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"verifiable-presentation-verify\")\n\t\t.summary(I18n.formatMessage(\"commands.verifiable-presentation-verify.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.verifiable-presentation-verify.description\"))\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verifiable-presentation-verify.options.jwt.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-presentation-verify.options.jwt.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verifiable-presentation-verify.options.json-ld.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-presentation-verify.options.json-ld.description\")\n\t\t);\n\tCLIOptions.output(command, {\n\t\tnoConsole: true,\n\t\tjson: true,\n\t\tenv: true,\n\t\tmergeJson: true,\n\t\tmergeEnv: true\n\t});\n\n\tcommand\n\t\t.addOption(\n\t\t\tnew Option(\n\t\t\t\tI18n.formatMessage(\"commands.common.options.connector.param\"),\n\t\t\t\tI18n.formatMessage(\"commands.common.options.connector.description\")\n\t\t\t)\n\t\t\t\t.choices(Object.values(IdentityConnectorTypes))\n\t\t\t\t.default(IdentityConnectorTypes.Iota)\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.node.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.node.description\"),\n\t\t\t\"!NODE_URL\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.network.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.network.description\"),\n\t\t\t\"!NETWORK\"\n\t\t)\n\t\t.action(actionCommandVerifiablePresentationVerify);\n\n\treturn command;\n}\n\n/**\n * Action the verifiable presentation verify command.\n * @param opts The options for the command.\n * @param opts.jwt The JSON web token for the verifiable presentation.\n * @param opts.jsonLd The filename of a JSON-LD verifiable presentation to verify.\n * @param opts.connector The connector to perform the operations with.\n * @param opts.node The node URL.\n * @param opts.network The network name.\n */\nexport async function actionCommandVerifiablePresentationVerify(\n\topts: {\n\t\tjwt?: string;\n\t\tjsonLd?: string;\n\t\tconnector?: IdentityConnectorTypes;\n\t\tnode: string;\n\t\tnetwork?: string;\n\t} & CliOutputOptions\n): Promise<void> {\n\tconst nodeEndpoint: string = CLIParam.url(\"node\", opts.node);\n\tconst network: string | undefined =\n\t\topts.connector === IdentityConnectorTypes.Iota\n\t\t\t? CLIParam.stringValue(\"network\", opts.network)\n\t\t\t: undefined;\n\n\tlet presentation: string | IDidVerifiablePresentation;\n\n\tif (Is.stringValue(opts.jwt)) {\n\t\tconst jwt = CLIParam.stringValue(\"jwt\", opts.jwt);\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.verifiable-presentation-verify.labels.jwt\"), jwt);\n\t\tpresentation = jwt;\n\t} else if (Is.stringValue(opts.jsonLd)) {\n\t\tconst jsonLdPath = path.resolve(CLIParam.stringValue(\"json-ld\", opts.jsonLd));\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verifiable-presentation-verify.labels.jsonLd\"),\n\t\t\tjsonLdPath\n\t\t);\n\t\tconst jsonData = await CLIUtils.readJsonFile<IDidVerifiablePresentation>(jsonLdPath);\n\t\tif (Is.undefined(jsonData)) {\n\t\t\tthrow new GeneralError(\n\t\t\t\t\"commands\",\n\t\t\t\t\"commands.verifiable-presentation-verify.jsonLdFileNotFound\"\n\t\t\t);\n\t\t}\n\t\tpresentation = jsonData;\n\t} else {\n\t\tthrow new GeneralError(\n\t\t\t\"commands\",\n\t\t\t\"commands.verifiable-presentation-verify.noPresentationProvided\"\n\t\t);\n\t}\n\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.node\"), nodeEndpoint);\n\tif (Is.stringValue(network)) {\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.network\"), network);\n\t}\n\tCLIDisplay.break();\n\n\tsetupVault();\n\n\tconst walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);\n\tWalletConnectorFactory.register(\"wallet\", () => walletConnector);\n\n\tconst identityConnector = setupIdentityConnector({ nodeEndpoint, network }, opts.connector);\n\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\"commands.verifiable-presentation-verify.progress.verifyingPresentation\")\n\t);\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tconst verification = await identityConnector.checkVerifiablePresentation(presentation);\n\n\tconst isVerified = Is.notEmpty(verification.verifiablePresentation);\n\tconst isRevoked = verification.revoked;\n\n\tCLIDisplay.spinnerStop();\n\n\tif (opts.console) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verifiable-presentation-verify.labels.isVerified\"),\n\t\t\tisVerified\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verifiable-presentation-verify.labels.isRevoked\"),\n\t\t\tisRevoked\n\t\t);\n\t\tCLIDisplay.break();\n\t}\n\n\tif (Is.stringValue(opts?.json)) {\n\t\tawait CLIUtils.writeJsonFile(\n\t\t\topts.json,\n\t\t\t{\n\t\t\t\tisVerified,\n\t\t\t\tisRevoked,\n\t\t\t\tverifiablePresentation: verification.verifiablePresentation\n\t\t\t},\n\t\t\topts.mergeJson\n\t\t);\n\t}\n\tif (Is.stringValue(opts?.env)) {\n\t\tawait CLIUtils.writeEnvFile(\n\t\t\topts.env,\n\t\t\t[\n\t\t\t\t`DID_VERIFIABLE_PRESENTATION_VERIFIED=\"${isVerified}\"`,\n\t\t\t\t`DID_VERIFIABLE_PRESENTATION_REVOKED=\"${isRevoked}\"`\n\t\t\t],\n\t\t\topts.mergeEnv\n\t\t);\n\t}\n\n\tCLIDisplay.done();\n}\n"]}
@@ -82,23 +82,27 @@ export async function actionCommandVerificationMethodAdd(opts) {
82
82
  CLIDisplay.break();
83
83
  setupVault();
84
84
  const vaultSeedId = "local-seed";
85
- const localIdentity = "local";
85
+ const vmParts = DocumentHelper.parseId(did);
86
86
  const vaultConnector = VaultConnectorFactory.get("vault");
87
- await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
87
+ await vaultConnector.setSecret(`${vmParts.id}/${vaultSeedId}`, Converter.bytesToBase64(seed));
88
88
  const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
89
89
  WalletConnectorFactory.register("wallet", () => walletConnector);
90
90
  const identityConnector = setupIdentityConnector({ nodeEndpoint, network, addressIndex, vaultSeedId }, opts.connector);
91
91
  CLIDisplay.task(I18n.formatMessage("commands.verification-method-add.progress.addingVerificationMethod"));
92
92
  CLIDisplay.break();
93
93
  CLIDisplay.spinnerStart();
94
- const verificationMethod = await identityConnector.addVerificationMethod(localIdentity, did, type, opts?.id);
94
+ const verificationMethod = await identityConnector.addVerificationMethod(vmParts.id, did, type, opts?.id);
95
95
  CLIDisplay.spinnerStop();
96
96
  const keyParts = DocumentHelper.parseId(verificationMethod.id);
97
- const keyPair = await vaultConnector.getKey(`${localIdentity}/${keyParts.fragment}`);
98
- const privateKeyBase64 = Converter.bytesToBase64Url(keyPair.privateKey);
99
- const publicKeyBase64 = Is.uint8Array(keyPair.publicKey)
97
+ const keyPair = await vaultConnector.getKey(`${vmParts.id}/${keyParts.fragment}`);
98
+ const privateKeyBase64Url = Converter.bytesToBase64Url(keyPair.privateKey);
99
+ const publicKeyBase64Url = Is.uint8Array(keyPair.publicKey)
100
100
  ? Converter.bytesToBase64Url(keyPair.publicKey)
101
101
  : "";
102
+ const privateKeyBase64 = Converter.bytesToBase64(keyPair.privateKey);
103
+ const publicKeyBase64 = Is.uint8Array(keyPair.publicKey)
104
+ ? Converter.bytesToBase64(keyPair.publicKey)
105
+ : "";
102
106
  const privateKeyHex = Converter.bytesToHex(keyPair.privateKey, true);
103
107
  const publicKeyHex = Is.uint8Array(keyPair.publicKey)
104
108
  ? Converter.bytesToHex(keyPair.publicKey, true)
@@ -108,6 +112,8 @@ export async function actionCommandVerificationMethodAdd(opts) {
108
112
  if (opts.console) {
109
113
  CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.verificationMethodId"), verificationMethod.id);
110
114
  CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.kid"), kid);
115
+ CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.privateKeyBase64Url"), privateKeyBase64Url);
116
+ CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.publicKeyBase64Url"), publicKeyBase64Url);
111
117
  CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.privateKeyBase64"), privateKeyBase64);
112
118
  CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.publicKeyBase64"), publicKeyBase64);
113
119
  CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.privateKeyHex"), privateKeyHex);
@@ -116,16 +122,31 @@ export async function actionCommandVerificationMethodAdd(opts) {
116
122
  }
117
123
  if (Is.stringValue(opts?.json)) {
118
124
  await CLIUtils.writeJsonFile(opts.json, {
119
- kid,
120
- ...jwk
125
+ verificationMethodId: verificationMethod.id,
126
+ privateKeyJwk: {
127
+ kid,
128
+ ...jwk
129
+ },
130
+ privateKeyHex,
131
+ publicKeyHex,
132
+ privateKeyBase64,
133
+ publicKeyBase64
121
134
  }, opts.mergeJson);
122
135
  }
123
136
  if (Is.stringValue(opts?.env)) {
124
137
  await CLIUtils.writeEnvFile(opts.env, [
125
138
  `DID_VERIFICATION_METHOD_ID="${verificationMethod.id}"`,
126
139
  `DID_VERIFICATION_METHOD_KID="${kid}"`,
127
- `DID_VERIFICATION_METHOD_PRIVATE_KEY="${privateKeyHex}"`,
128
- `DID_VERIFICATION_METHOD_PUBLIC_KEY="${publicKeyHex}"`
140
+ `DID_VERIFICATION_METHOD_JWK_KTY="${jwk.kty}"`,
141
+ `DID_VERIFICATION_METHOD_JWK_USE="${jwk.use}"`,
142
+ `DID_VERIFICATION_METHOD_JWK_ALG="${jwk.alg}"`,
143
+ `DID_VERIFICATION_METHOD_JWK_CRV="${jwk.crv}"`,
144
+ `DID_VERIFICATION_METHOD_JWK_X="${jwk.x}"`,
145
+ `DID_VERIFICATION_METHOD_JWK_D="${jwk.d}"`,
146
+ `DID_VERIFICATION_METHOD_PRIVATE_KEY_HEX="${privateKeyHex}"`,
147
+ `DID_VERIFICATION_METHOD_PUBLIC_KEY_HEX="${publicKeyHex}"`,
148
+ `DID_VERIFICATION_METHOD_PRIVATE_KEY_BASE64="${privateKeyBase64}"`,
149
+ `DID_VERIFICATION_METHOD_PUBLIC_KEY_BASE64="${publicKeyBase64}"`
129
150
  ], opts.mergeEnv);
130
151
  }
131
152
  if (opts.connector === IdentityConnectorTypes.Iota) {
@@ -1 +1 @@
1
- {"version":3,"file":"verificationMethodAdd.js","sourceRoot":"","sources":["../../../src/commands/verificationMethodAdd.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,UAAU,EACV,UAAU,EACV,QAAQ,EACR,QAAQ,EAER,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SA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AAC,gBAAgB,CAAC,WAAW,QAAQ,YAAY,OAAO,EAAE,CAC7F,CAAC;IACH,CAAC;IAED,UAAU,CAAC,KAAK,EAAE,CAAC;IAEnB,UAAU,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tCLIDisplay,\n\tCLIOptions,\n\tCLIParam,\n\tCLIUtils,\n\ttype CliOutputOptions\n} from \"@twin.org/cli-core\";\nimport { Converter, I18n, Is, StringHelper, Urn } from \"@twin.org/core\";\nimport { DocumentHelper } from \"@twin.org/identity-models\";\nimport { DidVerificationMethodType } from \"@twin.org/standards-w3c-did\";\nimport { VaultConnectorFactory } from \"@twin.org/vault-models\";\nimport { setupWalletConnector } from \"@twin.org/wallet-cli\";\nimport { WalletConnectorFactory } from \"@twin.org/wallet-models\";\nimport { Jwk } from \"@twin.org/web\";\nimport { Command, Option } from \"commander\";\nimport { setupIdentityConnector, setupVault } from \"./setupCommands.js\";\nimport { IdentityConnectorTypes } from \"../models/identityConnectorTypes.js\";\n\n/**\n * Build the verification method add command for the CLI.\n * @returns The command.\n */\nexport function buildCommandVerificationMethodAdd(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"verification-method-add\")\n\t\t.summary(I18n.formatMessage(\"commands.verification-method-add.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.verification-method-add.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.seed.param\"),\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.seed.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.did.param\"),\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.did.description\")\n\t\t)\n\t\t.addOption(\n\t\t\tnew Option(\n\t\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.type.param\"),\n\t\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.type.description\")\n\t\t\t)\n\t\t\t\t.choices(Object.values(DidVerificationMethodType))\n\t\t\t\t.makeOptionMandatory()\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.id.param\"),\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.id.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.addressIndex.param\"),\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.addressIndex.description\"),\n\t\t\t\"0\"\n\t\t);\n\tCLIOptions.output(command, {\n\t\tnoConsole: true,\n\t\tjson: true,\n\t\tenv: true,\n\t\tmergeJson: true,\n\t\tmergeEnv: true\n\t});\n\n\tcommand\n\t\t.addOption(\n\t\t\tnew Option(\n\t\t\t\tI18n.formatMessage(\"commands.common.options.connector.param\"),\n\t\t\t\tI18n.formatMessage(\"commands.common.options.connector.description\")\n\t\t\t)\n\t\t\t\t.choices(Object.values(IdentityConnectorTypes))\n\t\t\t\t.default(IdentityConnectorTypes.Iota)\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.node.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.node.description\"),\n\t\t\t\"!NODE_URL\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.network.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.network.description\"),\n\t\t\t\"!NETWORK\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.explorer.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.explorer.description\"),\n\t\t\t\"!EXPLORER_URL\"\n\t\t)\n\t\t.action(actionCommandVerificationMethodAdd);\n\n\treturn command;\n}\n\n/**\n * Action the verification method add command.\n * @param opts The options for the command.\n * @param opts.seed The private key for the controller.\n * @param opts.did The identity of the document to add to.\n * @param opts.type The type of the verification method to add.\n * @param opts.id The id of the verification method to add.\n * @param opts.connector The connector to perform the operations with.\n * @param opts.node The node URL.\n * @param opts.explorer The explorer URL.\n * @param opts.network The network to use for connector.\n * @param opts.addressIndex The address index to use for key derivation (if applicable).\n */\nexport async function actionCommandVerificationMethodAdd(\n\topts: {\n\t\tseed: string;\n\t\tdid: string;\n\t\ttype: DidVerificationMethodType;\n\t\tid?: string;\n\t\taddressIndex?: string;\n\t\tconnector?: IdentityConnectorTypes;\n\t\tnode: string;\n\t\tnetwork?: string;\n\t\texplorer: string;\n\t} & CliOutputOptions\n): Promise<void> {\n\tconst seed: Uint8Array = CLIParam.hexBase64(\"seed\", opts.seed);\n\tconst did: string = CLIParam.stringValue(\"did\", opts.did);\n\tconst type: DidVerificationMethodType = CLIParam.stringValue(\n\t\t\"type\",\n\t\topts.type\n\t) as DidVerificationMethodType;\n\tconst addressIndex: number = CLIParam.integer(\"addressIndex\", opts.addressIndex ?? \"0\", false, 0);\n\tconst nodeEndpoint: string = CLIParam.url(\"node\", opts.node);\n\tconst network: string | undefined =\n\t\topts.connector === IdentityConnectorTypes.Iota\n\t\t\t? CLIParam.stringValue(\"network\", opts.network)\n\t\t\t: undefined;\n\tconst explorerEndpoint: string = CLIParam.url(\"explorer\", opts.explorer);\n\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.did\"), did);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verification-method-add.labels.verificationMethodType\"),\n\t\ttype\n\t);\n\tif (Is.stringValue(opts.id)) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.verificationMethodId\"),\n\t\t\topts?.id\n\t\t);\n\t}\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verification-method-add.labels.addressIndex\"),\n\t\taddressIndex\n\t);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.node\"), nodeEndpoint);\n\tif (Is.stringValue(network)) {\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.network\"), network);\n\t}\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.explorer\"), explorerEndpoint);\n\tCLIDisplay.break();\n\n\tsetupVault();\n\n\tconst vaultSeedId = \"local-seed\";\n\tconst localIdentity = \"local\";\n\n\tconst vaultConnector = VaultConnectorFactory.get(\"vault\");\n\tawait vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));\n\n\tconst walletConnector = setupWalletConnector(\n\t\t{ nodeEndpoint, vaultSeedId, network },\n\t\topts.connector\n\t);\n\tWalletConnectorFactory.register(\"wallet\", () => walletConnector);\n\n\tconst identityConnector = setupIdentityConnector(\n\t\t{ nodeEndpoint, network, addressIndex, vaultSeedId },\n\t\topts.connector\n\t);\n\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\"commands.verification-method-add.progress.addingVerificationMethod\")\n\t);\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tconst verificationMethod = await identityConnector.addVerificationMethod(\n\t\tlocalIdentity,\n\t\tdid,\n\t\ttype,\n\t\topts?.id\n\t);\n\n\tCLIDisplay.spinnerStop();\n\n\tconst keyParts = DocumentHelper.parseId(verificationMethod.id);\n\n\tconst keyPair = await vaultConnector.getKey(`${localIdentity}/${keyParts.fragment}`);\n\tconst privateKeyBase64 = Converter.bytesToBase64Url(keyPair.privateKey);\n\tconst publicKeyBase64 = Is.uint8Array(keyPair.publicKey)\n\t\t? Converter.bytesToBase64Url(keyPair.publicKey)\n\t\t: \"\";\n\n\tconst privateKeyHex = Converter.bytesToHex(keyPair.privateKey, true);\n\tconst publicKeyHex = Is.uint8Array(keyPair.publicKey)\n\t\t? Converter.bytesToHex(keyPair.publicKey, true)\n\t\t: \"\";\n\n\tconst jwk = await Jwk.fromEd25519Private(keyPair.privateKey);\n\tconst kid = await Jwk.generateKid(jwk);\n\n\tif (opts.console) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.verificationMethodId\"),\n\t\t\tverificationMethod.id\n\t\t);\n\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.verification-method-add.labels.kid\"), kid);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.privateKeyBase64\"),\n\t\t\tprivateKeyBase64\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.publicKeyBase64\"),\n\t\t\tpublicKeyBase64\n\t\t);\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.privateKeyHex\"),\n\t\t\tprivateKeyHex\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.publicKeyHex\"),\n\t\t\tpublicKeyHex\n\t\t);\n\n\t\tCLIDisplay.break();\n\t}\n\n\tif (Is.stringValue(opts?.json)) {\n\t\tawait CLIUtils.writeJsonFile(\n\t\t\topts.json,\n\t\t\t{\n\t\t\t\tkid,\n\t\t\t\t...jwk\n\t\t\t},\n\t\t\topts.mergeJson\n\t\t);\n\t}\n\tif (Is.stringValue(opts?.env)) {\n\t\tawait CLIUtils.writeEnvFile(\n\t\t\topts.env,\n\t\t\t[\n\t\t\t\t`DID_VERIFICATION_METHOD_ID=\"${verificationMethod.id}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_KID=\"${kid}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_PRIVATE_KEY=\"${privateKeyHex}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_PUBLIC_KEY=\"${publicKeyHex}\"`\n\t\t\t],\n\t\t\topts.mergeEnv\n\t\t);\n\t}\n\n\tif (opts.connector === IdentityConnectorTypes.Iota) {\n\t\tconst didUrn = Urn.fromValidString(did);\n\t\tconst didParts = didUrn.parts();\n\t\tconst objectId = didParts[didParts.length - 1];\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.common.labels.explore\"),\n\t\t\t`${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`\n\t\t);\n\t}\n\n\tCLIDisplay.break();\n\n\tCLIDisplay.done();\n}\n"]}
1
+ {"version":3,"file":"verificationMethodAdd.js","sourceRoot":"","sources":["../../../src/commands/verificationMethodAdd.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,UAAU,EACV,UAAU,EACV,QAAQ,EACR,QAAQ,EAER,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAE7E;;;GAGG;AACH,MAAM,UAAU,iCAAiC;IAChD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAC9B,OAAO;SACL,IAAI,CAAC,yBAAyB,CAAC;SAC/B,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,0CAA0C,CAAC,CAAC;SACvE,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,8CAA8C,CAAC,CAAC;SAC/E,cAAc,CACd,IAAI,CAAC,aAAa,CAAC,qDAAqD,CAAC,EACzE,IAAI,CAAC,aAAa,CAAC,2DAA2D,CAAC,CAC/E;SACA,cAAc,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,YAAY,OAAO,EAAE,CAC7F,CAAC;IACH,CAAC;IAED,UAAU,CAAC,KAAK,EAAE,CAAC;IAEnB,UAAU,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tCLIDisplay,\n\tCLIOptions,\n\tCLIParam,\n\tCLIUtils,\n\ttype CliOutputOptions\n} from \"@twin.org/cli-core\";\nimport { Converter, I18n, Is, StringHelper, Urn } from \"@twin.org/core\";\nimport { DocumentHelper } from \"@twin.org/identity-models\";\nimport { DidVerificationMethodType } from \"@twin.org/standards-w3c-did\";\nimport { VaultConnectorFactory } from \"@twin.org/vault-models\";\nimport { setupWalletConnector } from \"@twin.org/wallet-cli\";\nimport { WalletConnectorFactory } from \"@twin.org/wallet-models\";\nimport { Jwk } from \"@twin.org/web\";\nimport { Command, Option } from \"commander\";\nimport { setupIdentityConnector, setupVault } from \"./setupCommands.js\";\nimport { IdentityConnectorTypes } from \"../models/identityConnectorTypes.js\";\n\n/**\n * Build the verification method add command for the CLI.\n * @returns The command.\n */\nexport function buildCommandVerificationMethodAdd(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"verification-method-add\")\n\t\t.summary(I18n.formatMessage(\"commands.verification-method-add.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.verification-method-add.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.seed.param\"),\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.seed.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.did.param\"),\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.did.description\")\n\t\t)\n\t\t.addOption(\n\t\t\tnew Option(\n\t\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.type.param\"),\n\t\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.type.description\")\n\t\t\t)\n\t\t\t\t.choices(Object.values(DidVerificationMethodType))\n\t\t\t\t.makeOptionMandatory()\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.id.param\"),\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.id.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.addressIndex.param\"),\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.addressIndex.description\"),\n\t\t\t\"0\"\n\t\t);\n\tCLIOptions.output(command, {\n\t\tnoConsole: true,\n\t\tjson: true,\n\t\tenv: true,\n\t\tmergeJson: true,\n\t\tmergeEnv: true\n\t});\n\n\tcommand\n\t\t.addOption(\n\t\t\tnew Option(\n\t\t\t\tI18n.formatMessage(\"commands.common.options.connector.param\"),\n\t\t\t\tI18n.formatMessage(\"commands.common.options.connector.description\")\n\t\t\t)\n\t\t\t\t.choices(Object.values(IdentityConnectorTypes))\n\t\t\t\t.default(IdentityConnectorTypes.Iota)\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.node.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.node.description\"),\n\t\t\t\"!NODE_URL\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.network.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.network.description\"),\n\t\t\t\"!NETWORK\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.explorer.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.explorer.description\"),\n\t\t\t\"!EXPLORER_URL\"\n\t\t)\n\t\t.action(actionCommandVerificationMethodAdd);\n\n\treturn command;\n}\n\n/**\n * Action the verification method add command.\n * @param opts The options for the command.\n * @param opts.seed The private key for the controller.\n * @param opts.did The identity of the document to add to.\n * @param opts.type The type of the verification method to add.\n * @param opts.id The id of the verification method to add.\n * @param opts.connector The connector to perform the operations with.\n * @param opts.node The node URL.\n * @param opts.explorer The explorer URL.\n * @param opts.network The network to use for connector.\n * @param opts.addressIndex The address index to use for key derivation (if applicable).\n */\nexport async function actionCommandVerificationMethodAdd(\n\topts: {\n\t\tseed: string;\n\t\tdid: string;\n\t\ttype: DidVerificationMethodType;\n\t\tid?: string;\n\t\taddressIndex?: string;\n\t\tconnector?: IdentityConnectorTypes;\n\t\tnode: string;\n\t\tnetwork?: string;\n\t\texplorer: string;\n\t} & CliOutputOptions\n): Promise<void> {\n\tconst seed: Uint8Array = CLIParam.hexBase64(\"seed\", opts.seed);\n\tconst did: string = CLIParam.stringValue(\"did\", opts.did);\n\tconst type: DidVerificationMethodType = CLIParam.stringValue(\n\t\t\"type\",\n\t\topts.type\n\t) as DidVerificationMethodType;\n\tconst addressIndex: number = CLIParam.integer(\"addressIndex\", opts.addressIndex ?? \"0\", false, 0);\n\tconst nodeEndpoint: string = CLIParam.url(\"node\", opts.node);\n\tconst network: string | undefined =\n\t\topts.connector === IdentityConnectorTypes.Iota\n\t\t\t? CLIParam.stringValue(\"network\", opts.network)\n\t\t\t: undefined;\n\tconst explorerEndpoint: string = CLIParam.url(\"explorer\", opts.explorer);\n\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.did\"), did);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verification-method-add.labels.verificationMethodType\"),\n\t\ttype\n\t);\n\tif (Is.stringValue(opts.id)) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.verificationMethodId\"),\n\t\t\topts?.id\n\t\t);\n\t}\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verification-method-add.labels.addressIndex\"),\n\t\taddressIndex\n\t);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.node\"), nodeEndpoint);\n\tif (Is.stringValue(network)) {\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.network\"), network);\n\t}\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.explorer\"), explorerEndpoint);\n\tCLIDisplay.break();\n\n\tsetupVault();\n\n\tconst vaultSeedId = \"local-seed\";\n\n\tconst vmParts = DocumentHelper.parseId(did);\n\n\tconst vaultConnector = VaultConnectorFactory.get(\"vault\");\n\tawait vaultConnector.setSecret(`${vmParts.id}/${vaultSeedId}`, Converter.bytesToBase64(seed));\n\n\tconst walletConnector = setupWalletConnector(\n\t\t{ nodeEndpoint, vaultSeedId, network },\n\t\topts.connector\n\t);\n\tWalletConnectorFactory.register(\"wallet\", () => walletConnector);\n\n\tconst identityConnector = setupIdentityConnector(\n\t\t{ nodeEndpoint, network, addressIndex, vaultSeedId },\n\t\topts.connector\n\t);\n\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\"commands.verification-method-add.progress.addingVerificationMethod\")\n\t);\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tconst verificationMethod = await identityConnector.addVerificationMethod(\n\t\tvmParts.id,\n\t\tdid,\n\t\ttype,\n\t\topts?.id\n\t);\n\n\tCLIDisplay.spinnerStop();\n\n\tconst keyParts = DocumentHelper.parseId(verificationMethod.id);\n\n\tconst keyPair = await vaultConnector.getKey(`${vmParts.id}/${keyParts.fragment}`);\n\tconst privateKeyBase64Url = Converter.bytesToBase64Url(keyPair.privateKey);\n\tconst publicKeyBase64Url = Is.uint8Array(keyPair.publicKey)\n\t\t? Converter.bytesToBase64Url(keyPair.publicKey)\n\t\t: \"\";\n\n\tconst privateKeyBase64 = Converter.bytesToBase64(keyPair.privateKey);\n\tconst publicKeyBase64 = Is.uint8Array(keyPair.publicKey)\n\t\t? Converter.bytesToBase64(keyPair.publicKey)\n\t\t: \"\";\n\n\tconst privateKeyHex = Converter.bytesToHex(keyPair.privateKey, true);\n\tconst publicKeyHex = Is.uint8Array(keyPair.publicKey)\n\t\t? Converter.bytesToHex(keyPair.publicKey, true)\n\t\t: \"\";\n\n\tconst jwk = await Jwk.fromEd25519Private(keyPair.privateKey);\n\tconst kid = await Jwk.generateKid(jwk);\n\n\tif (opts.console) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.verificationMethodId\"),\n\t\t\tverificationMethod.id\n\t\t);\n\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.verification-method-add.labels.kid\"), kid);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.privateKeyBase64Url\"),\n\t\t\tprivateKeyBase64Url\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.publicKeyBase64Url\"),\n\t\t\tpublicKeyBase64Url\n\t\t);\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.privateKeyBase64\"),\n\t\t\tprivateKeyBase64\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.publicKeyBase64\"),\n\t\t\tpublicKeyBase64\n\t\t);\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.privateKeyHex\"),\n\t\t\tprivateKeyHex\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.publicKeyHex\"),\n\t\t\tpublicKeyHex\n\t\t);\n\n\t\tCLIDisplay.break();\n\t}\n\n\tif (Is.stringValue(opts?.json)) {\n\t\tawait CLIUtils.writeJsonFile(\n\t\t\topts.json,\n\t\t\t{\n\t\t\t\tverificationMethodId: verificationMethod.id,\n\t\t\t\tprivateKeyJwk: {\n\t\t\t\t\tkid,\n\t\t\t\t\t...jwk\n\t\t\t\t},\n\t\t\t\tprivateKeyHex,\n\t\t\t\tpublicKeyHex,\n\t\t\t\tprivateKeyBase64,\n\t\t\t\tpublicKeyBase64\n\t\t\t},\n\t\t\topts.mergeJson\n\t\t);\n\t}\n\tif (Is.stringValue(opts?.env)) {\n\t\tawait CLIUtils.writeEnvFile(\n\t\t\topts.env,\n\t\t\t[\n\t\t\t\t`DID_VERIFICATION_METHOD_ID=\"${verificationMethod.id}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_KID=\"${kid}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_JWK_KTY=\"${jwk.kty}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_JWK_USE=\"${jwk.use}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_JWK_ALG=\"${jwk.alg}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_JWK_CRV=\"${jwk.crv}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_JWK_X=\"${jwk.x}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_JWK_D=\"${jwk.d}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_PRIVATE_KEY_HEX=\"${privateKeyHex}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_PUBLIC_KEY_HEX=\"${publicKeyHex}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_PRIVATE_KEY_BASE64=\"${privateKeyBase64}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_PUBLIC_KEY_BASE64=\"${publicKeyBase64}\"`\n\t\t\t],\n\t\t\topts.mergeEnv\n\t\t);\n\t}\n\n\tif (opts.connector === IdentityConnectorTypes.Iota) {\n\t\tconst didUrn = Urn.fromValidString(did);\n\t\tconst didParts = didUrn.parts();\n\t\tconst objectId = didParts[didParts.length - 1];\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.common.labels.explore\"),\n\t\t\t`${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`\n\t\t);\n\t}\n\n\tCLIDisplay.break();\n\n\tCLIDisplay.done();\n}\n"]}
package/dist/es/index.js CHANGED
@@ -9,6 +9,8 @@ export * from "./commands/serviceAdd.js";
9
9
  export * from "./commands/serviceRemove.js";
10
10
  export * from "./commands/setupCommands.js";
11
11
  export * from "./commands/verifiableCredentialCreate.js";
12
+ export * from "./commands/verifiablePresentationCreate.js";
13
+ export * from "./commands/verifiablePresentationVerify.js";
12
14
  export * from "./commands/verifiableCredentialRevoke.js";
13
15
  export * from "./commands/verifiableCredentialUnrevoke.js";
14
16
  export * from "./commands/verifiableCredentialVerify.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,UAAU,CAAC;AACzB,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0CAA0C,CAAC;AACzD,cAAc,0CAA0C,CAAC;AACzD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,0CAA0C,CAAC;AACzD,cAAc,qCAAqC,CAAC;AACpD,cAAc,wCAAwC,CAAC;AACvD,cAAc,oCAAoC,CAAC;AACnD,cAAc,4CAA4C,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./cli.js\";\nexport * from \"./commands/identityCreate.js\";\nexport * from \"./commands/identityResolve.js\";\nexport * from \"./commands/proofCreate.js\";\nexport * from \"./commands/proofVerify.js\";\nexport * from \"./commands/serviceAdd.js\";\nexport * from \"./commands/serviceRemove.js\";\nexport * from \"./commands/setupCommands.js\";\nexport * from \"./commands/verifiableCredentialCreate.js\";\nexport * from \"./commands/verifiableCredentialRevoke.js\";\nexport * from \"./commands/verifiableCredentialUnrevoke.js\";\nexport * from \"./commands/verifiableCredentialVerify.js\";\nexport * from \"./commands/verificationMethodAdd.js\";\nexport * from \"./commands/verificationMethodRemove.js\";\nexport * from \"./models/identityConnectorTypes.js\";\nexport * from \"./models/identityResolverConnectorTypes.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,UAAU,CAAC;AACzB,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0CAA0C,CAAC;AACzD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,4CAA4C,CAAC;AAC3D,cAAc,0CAA0C,CAAC;AACzD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,0CAA0C,CAAC;AACzD,cAAc,qCAAqC,CAAC;AACpD,cAAc,wCAAwC,CAAC;AACvD,cAAc,oCAAoC,CAAC;AACnD,cAAc,4CAA4C,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./cli.js\";\nexport * from \"./commands/identityCreate.js\";\nexport * from \"./commands/identityResolve.js\";\nexport * from \"./commands/proofCreate.js\";\nexport * from \"./commands/proofVerify.js\";\nexport * from \"./commands/serviceAdd.js\";\nexport * from \"./commands/serviceRemove.js\";\nexport * from \"./commands/setupCommands.js\";\nexport * from \"./commands/verifiableCredentialCreate.js\";\nexport * from \"./commands/verifiablePresentationCreate.js\";\nexport * from \"./commands/verifiablePresentationVerify.js\";\nexport * from \"./commands/verifiableCredentialRevoke.js\";\nexport * from \"./commands/verifiableCredentialUnrevoke.js\";\nexport * from \"./commands/verifiableCredentialVerify.js\";\nexport * from \"./commands/verificationMethodAdd.js\";\nexport * from \"./commands/verificationMethodRemove.js\";\nexport * from \"./models/identityConnectorTypes.js\";\nexport * from \"./models/identityResolverConnectorTypes.js\";\n"]}