@twin.org/identity-cli 0.0.2-next.9 → 0.0.3-next.1
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/bin/index.js +1 -1
- package/dist/es/cli.js +69 -0
- package/dist/es/cli.js.map +1 -0
- package/dist/es/commands/identityCreate.js +96 -0
- package/dist/es/commands/identityCreate.js.map +1 -0
- package/dist/es/commands/identityResolve.js +87 -0
- package/dist/es/commands/identityResolve.js.map +1 -0
- package/dist/es/commands/proofCreate.js +102 -0
- package/dist/es/commands/proofCreate.js.map +1 -0
- package/dist/es/commands/proofVerify.js +92 -0
- package/dist/es/commands/proofVerify.js.map +1 -0
- package/dist/es/commands/serviceAdd.js +112 -0
- package/dist/es/commands/serviceAdd.js.map +1 -0
- package/dist/es/commands/serviceRemove.js +93 -0
- package/dist/es/commands/serviceRemove.js.map +1 -0
- package/dist/es/commands/setupCommands.js +66 -0
- package/dist/es/commands/setupCommands.js.map +1 -0
- package/dist/es/commands/verifiableCredentialCreate.js +113 -0
- package/dist/es/commands/verifiableCredentialCreate.js.map +1 -0
- package/dist/es/commands/verifiableCredentialRevoke.js +77 -0
- package/dist/es/commands/verifiableCredentialRevoke.js.map +1 -0
- package/dist/es/commands/verifiableCredentialUnrevoke.js +77 -0
- package/dist/es/commands/verifiableCredentialUnrevoke.js.map +1 -0
- package/dist/es/commands/verifiableCredentialVerify.js +83 -0
- package/dist/es/commands/verifiableCredentialVerify.js.map +1 -0
- package/dist/es/commands/verificationMethodAdd.js +140 -0
- package/dist/es/commands/verificationMethodAdd.js.map +1 -0
- package/dist/es/commands/verificationMethodRemove.js +93 -0
- package/dist/es/commands/verificationMethodRemove.js.map +1 -0
- package/dist/es/index.js +19 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/identityConnectorTypes.js +13 -0
- package/dist/es/models/identityConnectorTypes.js.map +1 -0
- package/dist/es/models/identityResolverConnectorTypes.js +13 -0
- package/dist/es/models/identityResolverConnectorTypes.js.map +1 -0
- package/dist/locales/en.json +10 -4
- package/dist/types/commands/identityCreate.d.ts +1 -1
- package/dist/types/commands/identityResolve.d.ts +1 -1
- package/dist/types/commands/proofCreate.d.ts +1 -1
- package/dist/types/commands/proofVerify.d.ts +1 -1
- package/dist/types/commands/serviceAdd.d.ts +1 -1
- package/dist/types/commands/serviceRemove.d.ts +1 -1
- package/dist/types/commands/setupCommands.d.ts +2 -2
- package/dist/types/commands/verifiableCredentialCreate.d.ts +1 -1
- package/dist/types/commands/verifiableCredentialRevoke.d.ts +1 -1
- package/dist/types/commands/verifiableCredentialUnrevoke.d.ts +1 -1
- package/dist/types/commands/verifiableCredentialVerify.d.ts +1 -1
- package/dist/types/commands/verificationMethodAdd.d.ts +1 -1
- package/dist/types/commands/verificationMethodRemove.d.ts +1 -1
- package/dist/types/index.d.ts +16 -16
- package/docs/changelog.md +50 -0
- package/package.json +8 -10
- package/dist/cjs/index.cjs +0 -1248
- package/dist/esm/index.mjs +0 -1216
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { CLIDisplay, CLIParam } from "@twin.org/cli-core";
|
|
4
|
+
import { Converter, I18n, Is } from "@twin.org/core";
|
|
5
|
+
import { VaultConnectorFactory } from "@twin.org/vault-models";
|
|
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 credential unrevoke command for the CLI.
|
|
13
|
+
* @returns The command.
|
|
14
|
+
*/
|
|
15
|
+
export function buildCommandVerifiableCredentialUnrevoke() {
|
|
16
|
+
const command = new Command();
|
|
17
|
+
command
|
|
18
|
+
.name("verifiable-credential-unrevoke")
|
|
19
|
+
.summary(I18n.formatMessage("commands.verifiable-credential-unrevoke.summary"))
|
|
20
|
+
.description(I18n.formatMessage("commands.verifiable-credential-unrevoke.description"))
|
|
21
|
+
.requiredOption(I18n.formatMessage("commands.verifiable-credential-unrevoke.options.seed.param"), I18n.formatMessage("commands.verifiable-credential-unrevoke.options.seed.description"))
|
|
22
|
+
.requiredOption(I18n.formatMessage("commands.verifiable-credential-unrevoke.options.did.param"), I18n.formatMessage("commands.verifiable-credential-unrevoke.options.did.description"))
|
|
23
|
+
.requiredOption(I18n.formatMessage("commands.verifiable-credential-unrevoke.options.revocation-index.param"), I18n.formatMessage("commands.verifiable-credential-unrevoke.options.revocation-index.description"))
|
|
24
|
+
.option(I18n.formatMessage("commands.verifiable-credential-unrevoke.options.addressIndex.param"), I18n.formatMessage("commands.verifiable-credential-unrevoke.options.addressIndex.description"), "0");
|
|
25
|
+
command
|
|
26
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
27
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
28
|
+
.default(IdentityConnectorTypes.Iota))
|
|
29
|
+
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
30
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
31
|
+
.action(actionCommandVerifiableCredentialUnrevoke);
|
|
32
|
+
return command;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Action the verifiable credential unrevoke command.
|
|
36
|
+
* @param opts The options for the command.
|
|
37
|
+
* @param opts.seed The seed to generate the private key for the controller.
|
|
38
|
+
* @param opts.did The id of the document to unrevoke the index.
|
|
39
|
+
* @param opts.revocationIndex The revocation index for the credential.
|
|
40
|
+
* @param opts.connector The connector to perform the operations with.
|
|
41
|
+
* @param opts.node The node URL.
|
|
42
|
+
* @param opts.network The network to use for connector.
|
|
43
|
+
* @param opts.addressIndex The address index to use for key derivation (if applicable).
|
|
44
|
+
*/
|
|
45
|
+
export async function actionCommandVerifiableCredentialUnrevoke(opts) {
|
|
46
|
+
const seed = CLIParam.hexBase64("seed", opts.seed);
|
|
47
|
+
const did = CLIParam.stringValue("did", opts.did);
|
|
48
|
+
const revocationIndex = CLIParam.integer("revocation-index", opts.revocationIndex);
|
|
49
|
+
const addressIndex = CLIParam.integer("addressIndex", opts.addressIndex ?? "0", false, 0);
|
|
50
|
+
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
51
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
52
|
+
? CLIParam.stringValue("network", opts.network)
|
|
53
|
+
: undefined;
|
|
54
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.did"), did);
|
|
55
|
+
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-unrevoke.labels.revocationIndex"), revocationIndex);
|
|
56
|
+
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-unrevoke.labels.addressIndex"), addressIndex);
|
|
57
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
58
|
+
if (Is.stringValue(network)) {
|
|
59
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
60
|
+
}
|
|
61
|
+
CLIDisplay.break();
|
|
62
|
+
setupVault();
|
|
63
|
+
const vaultSeedId = "local-seed";
|
|
64
|
+
const localIdentity = "local";
|
|
65
|
+
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
66
|
+
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
|
|
67
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
|
|
68
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
69
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network, addressIndex, vaultSeedId }, opts.connector);
|
|
70
|
+
CLIDisplay.task(I18n.formatMessage("commands.verifiable-credential-unrevoke.progress.unrevokingCredential"));
|
|
71
|
+
CLIDisplay.break();
|
|
72
|
+
CLIDisplay.spinnerStart();
|
|
73
|
+
await identityConnector.unrevokeVerifiableCredentials(localIdentity, did, [revocationIndex]);
|
|
74
|
+
CLIDisplay.spinnerStop();
|
|
75
|
+
CLIDisplay.done();
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=verifiableCredentialUnrevoke.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verifiableCredentialUnrevoke.js","sourceRoot":"","sources":["../../../src/commands/verifiableCredentialUnrevoke.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,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,cA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,CAAC;IAC1D,MAAM,cAAc,CAAC,SAAS,CAAC,GAAG,aAAa,IAAI,WAAW,EAAE,EAAE,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;IAEjG,MAAM,eAAe,GAAG,oBAAoB,CAC3C,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,EACtC,IAAI,CAAC,SAAS,CACd,CAAC;IACF,sBAAsB,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,CAAC;IAEjE,MAAM,iBAAiB,GAAG,sBAAsB,CAC/C,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,EACpD,IAAI,CAAC,SAAS,CACd,CAAC;IAEF,UAAU,CAAC,IAAI,CACd,IAAI,CAAC,aAAa,CAAC,uEAAuE,CAAC,CAC3F,CAAC;IACF,UAAU,CAAC,KAAK,EAAE,CAAC;IAEnB,UAAU,CAAC,YAAY,EAAE,CAAC;IAE1B,MAAM,iBAAiB,CAAC,6BAA6B,CAAC,aAAa,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;IAE7F,UAAU,CAAC,WAAW,EAAE,CAAC;IAEzB,UAAU,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay, CLIParam } from \"@twin.org/cli-core\";\nimport { Converter, I18n, Is } from \"@twin.org/core\";\nimport { VaultConnectorFactory } from \"@twin.org/vault-models\";\n\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 credential unrevoke command for the CLI.\n * @returns The command.\n */\nexport function buildCommandVerifiableCredentialUnrevoke(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"verifiable-credential-unrevoke\")\n\t\t.summary(I18n.formatMessage(\"commands.verifiable-credential-unrevoke.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.verifiable-credential-unrevoke.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-unrevoke.options.seed.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-unrevoke.options.seed.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-unrevoke.options.did.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-unrevoke.options.did.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-unrevoke.options.revocation-index.param\"),\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"commands.verifiable-credential-unrevoke.options.revocation-index.description\"\n\t\t\t)\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-unrevoke.options.addressIndex.param\"),\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"commands.verifiable-credential-unrevoke.options.addressIndex.description\"\n\t\t\t),\n\t\t\t\"0\"\n\t\t);\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(actionCommandVerifiableCredentialUnrevoke);\n\n\treturn command;\n}\n\n/**\n * Action the verifiable credential unrevoke command.\n * @param opts The options for the command.\n * @param opts.seed The seed to generate the private key for the controller.\n * @param opts.did The id of the document to unrevoke the index.\n * @param opts.revocationIndex The revocation index for the credential.\n * @param opts.connector The connector to perform the operations with.\n * @param opts.node The node 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 actionCommandVerifiableCredentialUnrevoke(opts: {\n\tseed: string;\n\tdid: string;\n\trevocationIndex: string;\n\taddressIndex?: string;\n\tconnector?: IdentityConnectorTypes;\n\tnode: string;\n\tnetwork?: string;\n}): Promise<void> {\n\tconst seed: Uint8Array = CLIParam.hexBase64(\"seed\", opts.seed);\n\tconst did: string = CLIParam.stringValue(\"did\", opts.did);\n\tconst revocationIndex: number = CLIParam.integer(\"revocation-index\", opts.revocationIndex);\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\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.did\"), did);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verifiable-credential-unrevoke.labels.revocationIndex\"),\n\t\trevocationIndex\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verifiable-credential-unrevoke.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.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.verifiable-credential-unrevoke.progress.unrevokingCredential\")\n\t);\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tawait identityConnector.unrevokeVerifiableCredentials(localIdentity, did, [revocationIndex]);\n\n\tCLIDisplay.spinnerStop();\n\n\tCLIDisplay.done();\n}\n"]}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { CLIDisplay, CLIOptions, CLIParam, CLIUtils } from "@twin.org/cli-core";
|
|
4
|
+
import { I18n, Is } from "@twin.org/core";
|
|
5
|
+
import { setupWalletConnector } from "@twin.org/wallet-cli";
|
|
6
|
+
import { WalletConnectorFactory } from "@twin.org/wallet-models";
|
|
7
|
+
import { Command, Option } from "commander";
|
|
8
|
+
import { setupIdentityConnector, setupVault } from "./setupCommands.js";
|
|
9
|
+
import { IdentityConnectorTypes } from "../models/identityConnectorTypes.js";
|
|
10
|
+
/**
|
|
11
|
+
* Build the verifiable credential verify command for the CLI.
|
|
12
|
+
* @returns The command.
|
|
13
|
+
*/
|
|
14
|
+
export function buildCommandVerifiableCredentialVerify() {
|
|
15
|
+
const command = new Command();
|
|
16
|
+
command
|
|
17
|
+
.name("verifiable-credential-verify")
|
|
18
|
+
.summary(I18n.formatMessage("commands.verifiable-credential-verify.summary"))
|
|
19
|
+
.description(I18n.formatMessage("commands.verifiable-credential-verify.description"))
|
|
20
|
+
.requiredOption(I18n.formatMessage("commands.verifiable-credential-verify.options.jwt.param"), I18n.formatMessage("commands.verifiable-credential-verify.options.jwt.description"));
|
|
21
|
+
CLIOptions.output(command, {
|
|
22
|
+
noConsole: true,
|
|
23
|
+
json: true,
|
|
24
|
+
env: true,
|
|
25
|
+
mergeJson: true,
|
|
26
|
+
mergeEnv: true
|
|
27
|
+
});
|
|
28
|
+
command
|
|
29
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
30
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
31
|
+
.default(IdentityConnectorTypes.Iota))
|
|
32
|
+
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
33
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
34
|
+
.action(actionCommandVerifiableCredentialVerify);
|
|
35
|
+
return command;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Action the verifiable credential verify command.
|
|
39
|
+
* @param opts The options for the command.
|
|
40
|
+
* @param opts.jwt The JSON web token for the verifiable credential.
|
|
41
|
+
* @param opts.connector The connector to perform the operations with.
|
|
42
|
+
* @param opts.node The node URL.
|
|
43
|
+
*/
|
|
44
|
+
export async function actionCommandVerifiableCredentialVerify(opts) {
|
|
45
|
+
const jwt = CLIParam.stringValue("jwt", opts.jwt);
|
|
46
|
+
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
47
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
48
|
+
? CLIParam.stringValue("network", opts.network)
|
|
49
|
+
: undefined;
|
|
50
|
+
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-verify.labels.jwt"), jwt);
|
|
51
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
52
|
+
if (Is.stringValue(network)) {
|
|
53
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
54
|
+
}
|
|
55
|
+
CLIDisplay.break();
|
|
56
|
+
setupVault();
|
|
57
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);
|
|
58
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
59
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network }, opts.connector);
|
|
60
|
+
CLIDisplay.task(I18n.formatMessage("commands.verifiable-credential-verify.progress.verifyingCredential"));
|
|
61
|
+
CLIDisplay.break();
|
|
62
|
+
CLIDisplay.spinnerStart();
|
|
63
|
+
const verification = await identityConnector.checkVerifiableCredential(jwt);
|
|
64
|
+
const isVerified = Is.notEmpty(verification.verifiableCredential);
|
|
65
|
+
const isRevoked = verification.revoked;
|
|
66
|
+
CLIDisplay.spinnerStop();
|
|
67
|
+
if (opts.console) {
|
|
68
|
+
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-verify.labels.isVerified"), isVerified);
|
|
69
|
+
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-verify.labels.isRevoked"), isRevoked);
|
|
70
|
+
CLIDisplay.break();
|
|
71
|
+
}
|
|
72
|
+
if (Is.stringValue(opts?.json)) {
|
|
73
|
+
await CLIUtils.writeJsonFile(opts.json, { isVerified, isRevoked }, opts.mergeJson);
|
|
74
|
+
}
|
|
75
|
+
if (Is.stringValue(opts?.env)) {
|
|
76
|
+
await CLIUtils.writeEnvFile(opts.env, [
|
|
77
|
+
`DID_VERIFIABLE_CREDENTIAL_VERIFIED="${isVerified}"`,
|
|
78
|
+
`DID_VERIFIABLE_CREDENTIAL_REVOKED="${isRevoked}"`
|
|
79
|
+
], opts.mergeEnv);
|
|
80
|
+
}
|
|
81
|
+
CLIDisplay.done();
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=verifiableCredentialVerify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verifiableCredentialVerify.js","sourceRoot":"","sources":["../../../src/commands/verifiableCredentialVerify.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,UAAU,EACV,UAAU,EACV,QAAQ,EACR,QAAQ,EAER,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAC1C,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,sCAAsC;IACrD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAC9B,OAAO;SACL,IAAI,CAAC,8BAA8B,CAAC;SACpC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,+CAA+C,CAAC,CAAC;SAC5E,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,mDAAmD,CAAC,CAAC;SACpF,cAAc,CACd,IAAI,CAAC,aAAa,CAAC,yDAAyD,CAAC,EAC7E,IAAI,CAAC,aAAa,CAAC,+DAA+D,CAAC,CACnF,CAAC;IACH,UAAU,CAAC,MAAM,CAAC,OAAO,EAAE;QAC1B,SAAS,EAAE,IAAI;QACf,IAAI,EAAE,IAAI;QACV,GAAG,EAAE,IAAI;QACT,SAAS,EAAE,IAAI;QACf,QAAQ,EAAE,IAAI;KACd,CAAC,CAAC;IAEH,OAAO;SACL,SAAS,CACT,IAAI,MAAM,CACT,IAAI,CAAC,aAAa,CAAC,yCAAyC,CAAC,EAC7D,IAAI,CAAC,aAAa,CAAC,+CAA+C,CAAC,CACnE;SAC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C,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,QAAQ,CAAC,YAAY,CAC1B,IAAI,CAAC,GAAG,EACR;YACC,uCAAuC,UAAU,GAAG;YACpD,sCAAsC,SAAS,GAAG;SAClD,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 {\n\tCLIDisplay,\n\tCLIOptions,\n\tCLIParam,\n\tCLIUtils,\n\ttype CliOutputOptions\n} from \"@twin.org/cli-core\";\nimport { I18n, Is } from \"@twin.org/core\";\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 credential verify command for the CLI.\n * @returns The command.\n */\nexport function buildCommandVerifiableCredentialVerify(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"verifiable-credential-verify\")\n\t\t.summary(I18n.formatMessage(\"commands.verifiable-credential-verify.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.verifiable-credential-verify.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-verify.options.jwt.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-verify.options.jwt.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(actionCommandVerifiableCredentialVerify);\n\n\treturn command;\n}\n\n/**\n * Action the verifiable credential verify command.\n * @param opts The options for the command.\n * @param opts.jwt The JSON web token for the verifiable credential.\n * @param opts.connector The connector to perform the operations with.\n * @param opts.node The node URL.\n */\nexport async function actionCommandVerifiableCredentialVerify(\n\topts: {\n\t\tjwt: string;\n\t\tconnector?: IdentityConnectorTypes;\n\t\tnode: string;\n\t\tnetwork?: string;\n\t} & CliOutputOptions\n): Promise<void> {\n\tconst jwt: string = CLIParam.stringValue(\"jwt\", opts.jwt);\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\tCLIDisplay.value(I18n.formatMessage(\"commands.verifiable-credential-verify.labels.jwt\"), jwt);\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-credential-verify.progress.verifyingCredential\")\n\t);\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tconst verification = await identityConnector.checkVerifiableCredential(jwt);\n\n\tconst isVerified = Is.notEmpty(verification.verifiableCredential);\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-credential-verify.labels.isVerified\"),\n\t\t\tisVerified\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-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(opts.json, { isVerified, isRevoked }, opts.mergeJson);\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_CREDENTIAL_VERIFIED=\"${isVerified}\"`,\n\t\t\t\t`DID_VERIFIABLE_CREDENTIAL_REVOKED=\"${isRevoked}\"`\n\t\t\t],\n\t\t\topts.mergeEnv\n\t\t);\n\t}\n\n\tCLIDisplay.done();\n}\n"]}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { CLIDisplay, CLIOptions, CLIParam, CLIUtils } from "@twin.org/cli-core";
|
|
4
|
+
import { Converter, I18n, Is, StringHelper, Urn } from "@twin.org/core";
|
|
5
|
+
import { DocumentHelper } from "@twin.org/identity-models";
|
|
6
|
+
import { DidVerificationMethodType } from "@twin.org/standards-w3c-did";
|
|
7
|
+
import { VaultConnectorFactory } from "@twin.org/vault-models";
|
|
8
|
+
import { setupWalletConnector } from "@twin.org/wallet-cli";
|
|
9
|
+
import { WalletConnectorFactory } from "@twin.org/wallet-models";
|
|
10
|
+
import { Jwk } from "@twin.org/web";
|
|
11
|
+
import { Command, Option } from "commander";
|
|
12
|
+
import { setupIdentityConnector, setupVault } from "./setupCommands.js";
|
|
13
|
+
import { IdentityConnectorTypes } from "../models/identityConnectorTypes.js";
|
|
14
|
+
/**
|
|
15
|
+
* Build the verification method add command for the CLI.
|
|
16
|
+
* @returns The command.
|
|
17
|
+
*/
|
|
18
|
+
export function buildCommandVerificationMethodAdd() {
|
|
19
|
+
const command = new Command();
|
|
20
|
+
command
|
|
21
|
+
.name("verification-method-add")
|
|
22
|
+
.summary(I18n.formatMessage("commands.verification-method-add.summary"))
|
|
23
|
+
.description(I18n.formatMessage("commands.verification-method-add.description"))
|
|
24
|
+
.requiredOption(I18n.formatMessage("commands.verification-method-add.options.seed.param"), I18n.formatMessage("commands.verification-method-add.options.seed.description"))
|
|
25
|
+
.requiredOption(I18n.formatMessage("commands.verification-method-add.options.did.param"), I18n.formatMessage("commands.verification-method-add.options.did.description"))
|
|
26
|
+
.addOption(new Option(I18n.formatMessage("commands.verification-method-add.options.type.param"), I18n.formatMessage("commands.verification-method-add.options.type.description"))
|
|
27
|
+
.choices(Object.values(DidVerificationMethodType))
|
|
28
|
+
.makeOptionMandatory())
|
|
29
|
+
.option(I18n.formatMessage("commands.verification-method-add.options.id.param"), I18n.formatMessage("commands.verification-method-add.options.id.description"))
|
|
30
|
+
.option(I18n.formatMessage("commands.verification-method-add.options.addressIndex.param"), I18n.formatMessage("commands.verification-method-add.options.addressIndex.description"), "0");
|
|
31
|
+
CLIOptions.output(command, {
|
|
32
|
+
noConsole: true,
|
|
33
|
+
json: true,
|
|
34
|
+
env: true,
|
|
35
|
+
mergeJson: true,
|
|
36
|
+
mergeEnv: true
|
|
37
|
+
});
|
|
38
|
+
command
|
|
39
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
40
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
41
|
+
.default(IdentityConnectorTypes.Iota))
|
|
42
|
+
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
43
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
44
|
+
.option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
45
|
+
.action(actionCommandVerificationMethodAdd);
|
|
46
|
+
return command;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Action the verification method add command.
|
|
50
|
+
* @param opts The options for the command.
|
|
51
|
+
* @param opts.seed The private key for the controller.
|
|
52
|
+
* @param opts.did The identity of the document to add to.
|
|
53
|
+
* @param opts.type The type of the verification method to add.
|
|
54
|
+
* @param opts.id The id of the verification method to add.
|
|
55
|
+
* @param opts.connector The connector to perform the operations with.
|
|
56
|
+
* @param opts.node The node URL.
|
|
57
|
+
* @param opts.explorer The explorer URL.
|
|
58
|
+
* @param opts.network The network to use for connector.
|
|
59
|
+
* @param opts.addressIndex The address index to use for key derivation (if applicable).
|
|
60
|
+
*/
|
|
61
|
+
export async function actionCommandVerificationMethodAdd(opts) {
|
|
62
|
+
const seed = CLIParam.hexBase64("seed", opts.seed);
|
|
63
|
+
const did = CLIParam.stringValue("did", opts.did);
|
|
64
|
+
const type = CLIParam.stringValue("type", opts.type);
|
|
65
|
+
const addressIndex = CLIParam.integer("addressIndex", opts.addressIndex ?? "0", false, 0);
|
|
66
|
+
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
67
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
68
|
+
? CLIParam.stringValue("network", opts.network)
|
|
69
|
+
: undefined;
|
|
70
|
+
const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
|
|
71
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.did"), did);
|
|
72
|
+
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.verificationMethodType"), type);
|
|
73
|
+
if (Is.stringValue(opts.id)) {
|
|
74
|
+
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.verificationMethodId"), opts?.id);
|
|
75
|
+
}
|
|
76
|
+
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.addressIndex"), addressIndex);
|
|
77
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
78
|
+
if (Is.stringValue(network)) {
|
|
79
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
80
|
+
}
|
|
81
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
|
|
82
|
+
CLIDisplay.break();
|
|
83
|
+
setupVault();
|
|
84
|
+
const vaultSeedId = "local-seed";
|
|
85
|
+
const localIdentity = "local";
|
|
86
|
+
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
87
|
+
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
|
|
88
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
|
|
89
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
90
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network, addressIndex, vaultSeedId }, opts.connector);
|
|
91
|
+
CLIDisplay.task(I18n.formatMessage("commands.verification-method-add.progress.addingVerificationMethod"));
|
|
92
|
+
CLIDisplay.break();
|
|
93
|
+
CLIDisplay.spinnerStart();
|
|
94
|
+
const verificationMethod = await identityConnector.addVerificationMethod(localIdentity, did, type, opts?.id);
|
|
95
|
+
CLIDisplay.spinnerStop();
|
|
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)
|
|
100
|
+
? Converter.bytesToBase64Url(keyPair.publicKey)
|
|
101
|
+
: "";
|
|
102
|
+
const privateKeyHex = Converter.bytesToHex(keyPair.privateKey, true);
|
|
103
|
+
const publicKeyHex = Is.uint8Array(keyPair.publicKey)
|
|
104
|
+
? Converter.bytesToHex(keyPair.publicKey, true)
|
|
105
|
+
: "";
|
|
106
|
+
const jwk = await Jwk.fromEd25519Private(keyPair.privateKey);
|
|
107
|
+
const kid = await Jwk.generateKid(jwk);
|
|
108
|
+
if (opts.console) {
|
|
109
|
+
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.verificationMethodId"), verificationMethod.id);
|
|
110
|
+
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.kid"), kid);
|
|
111
|
+
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.privateKeyBase64"), privateKeyBase64);
|
|
112
|
+
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.publicKeyBase64"), publicKeyBase64);
|
|
113
|
+
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.privateKeyHex"), privateKeyHex);
|
|
114
|
+
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.publicKeyHex"), publicKeyHex);
|
|
115
|
+
CLIDisplay.break();
|
|
116
|
+
}
|
|
117
|
+
if (Is.stringValue(opts?.json)) {
|
|
118
|
+
await CLIUtils.writeJsonFile(opts.json, {
|
|
119
|
+
kid,
|
|
120
|
+
...jwk
|
|
121
|
+
}, opts.mergeJson);
|
|
122
|
+
}
|
|
123
|
+
if (Is.stringValue(opts?.env)) {
|
|
124
|
+
await CLIUtils.writeEnvFile(opts.env, [
|
|
125
|
+
`DID_VERIFICATION_METHOD_ID="${verificationMethod.id}"`,
|
|
126
|
+
`DID_VERIFICATION_METHOD_KID="${kid}"`,
|
|
127
|
+
`DID_VERIFICATION_METHOD_PRIVATE_KEY="${privateKeyHex}"`,
|
|
128
|
+
`DID_VERIFICATION_METHOD_PUBLIC_KEY="${publicKeyHex}"`
|
|
129
|
+
], opts.mergeEnv);
|
|
130
|
+
}
|
|
131
|
+
if (opts.connector === IdentityConnectorTypes.Iota) {
|
|
132
|
+
const didUrn = Urn.fromValidString(did);
|
|
133
|
+
const didParts = didUrn.parts();
|
|
134
|
+
const objectId = didParts[didParts.length - 1];
|
|
135
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`);
|
|
136
|
+
}
|
|
137
|
+
CLIDisplay.break();
|
|
138
|
+
CLIDisplay.done();
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=verificationMethodAdd.js.map
|
|
@@ -0,0 +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,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;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I,CAAC,SAAS,CACd,CAAC;IACH,CAAC;IACD,IAAI,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,QAAQ,CAAC,YAAY,CAC1B,IAAI,CAAC,GAAG,EACR;YACC,+BAA+B,kBAAkB,CAAC,EAAE,GAAG;YACvD,gCAAgC,GAAG,GAAG;YACtC,wCAAwC,aAAa,GAAG;YACxD,uCAAuC,YAAY,GAAG;SACtD,EACD,IAAI,CAAC,QAAQ,CACb,CAAC;IACH,CAAC;IAED,IAAI,IAAI,CAAC,SAAS,KAAK,sBAAsB,CAAC,IAAI,EAAE,CAAC;QACpD,MAAM,MAAM,GAAG,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QACxC,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC/C,UAAU,CAAC,KAAK,CACf,IAAI,CAAC,aAAa,CAAC,gCAAgC,CAAC,EACpD,GAAG,YAAY,CAAC,mBAAmB,CAAC,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"]}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { CLIDisplay, CLIOptions, CLIParam } from "@twin.org/cli-core";
|
|
4
|
+
import { Converter, I18n, Is, StringHelper, Urn } from "@twin.org/core";
|
|
5
|
+
import { DocumentHelper } from "@twin.org/identity-models";
|
|
6
|
+
import { VaultConnectorFactory } from "@twin.org/vault-models";
|
|
7
|
+
import { setupWalletConnector } from "@twin.org/wallet-cli";
|
|
8
|
+
import { WalletConnectorFactory } from "@twin.org/wallet-models";
|
|
9
|
+
import { Command, Option } from "commander";
|
|
10
|
+
import { setupIdentityConnector, setupVault } from "./setupCommands.js";
|
|
11
|
+
import { IdentityConnectorTypes } from "../models/identityConnectorTypes.js";
|
|
12
|
+
/**
|
|
13
|
+
* Build the verification method remove command for the CLI.
|
|
14
|
+
* @returns The command.
|
|
15
|
+
*/
|
|
16
|
+
export function buildCommandVerificationMethodRemove() {
|
|
17
|
+
const command = new Command();
|
|
18
|
+
command
|
|
19
|
+
.name("verification-method-remove")
|
|
20
|
+
.summary(I18n.formatMessage("commands.verification-method-remove.summary"))
|
|
21
|
+
.description(I18n.formatMessage("commands.verification-method-remove.description"))
|
|
22
|
+
.requiredOption(I18n.formatMessage("commands.verification-method-remove.options.seed.param"), I18n.formatMessage("commands.verification-method-remove.options.seed.description"))
|
|
23
|
+
.requiredOption(I18n.formatMessage("commands.verification-method-remove.options.id.param"), I18n.formatMessage("commands.verification-method-remove.options.id.description"))
|
|
24
|
+
.option(I18n.formatMessage("commands.verification-method-remove.options.addressIndex.param"), I18n.formatMessage("commands.verification-method-remove.options.addressIndex.description"), "0");
|
|
25
|
+
CLIOptions.output(command, {
|
|
26
|
+
noConsole: true,
|
|
27
|
+
json: true,
|
|
28
|
+
env: true,
|
|
29
|
+
mergeJson: true,
|
|
30
|
+
mergeEnv: true
|
|
31
|
+
});
|
|
32
|
+
command
|
|
33
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
34
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
35
|
+
.default(IdentityConnectorTypes.Iota))
|
|
36
|
+
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
37
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
38
|
+
.option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
39
|
+
.action(actionCommandVerificationMethodRemove);
|
|
40
|
+
return command;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Action the verification method remove command.
|
|
44
|
+
* @param opts The options for the command.
|
|
45
|
+
* @param opts.seed The private key for the controller.
|
|
46
|
+
* @param opts.id The id of the verification method to remove.
|
|
47
|
+
* @param opts.connector The connector to perform the operations with.
|
|
48
|
+
* @param opts.node The node URL.
|
|
49
|
+
* @param opts.explorer The explorer URL.
|
|
50
|
+
* @param opts.network The network to use for connector.
|
|
51
|
+
* @param opts.addressIndex The address index to use for key derivation (if applicable).
|
|
52
|
+
*/
|
|
53
|
+
export async function actionCommandVerificationMethodRemove(opts) {
|
|
54
|
+
const seed = CLIParam.hexBase64("seed", opts.seed);
|
|
55
|
+
const id = CLIParam.stringValue("id", opts.id);
|
|
56
|
+
const addressIndex = CLIParam.integer("addressIndex", opts.addressIndex ?? "0", false, 0);
|
|
57
|
+
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
58
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
59
|
+
? CLIParam.stringValue("network", opts.network)
|
|
60
|
+
: undefined;
|
|
61
|
+
const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
|
|
62
|
+
CLIDisplay.value(I18n.formatMessage("commands.verification-method-remove.labels.verificationMethodId"), id);
|
|
63
|
+
CLIDisplay.value(I18n.formatMessage("commands.verification-method-remove.labels.addressIndex"), addressIndex);
|
|
64
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
65
|
+
if (Is.stringValue(network)) {
|
|
66
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
67
|
+
}
|
|
68
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
|
|
69
|
+
CLIDisplay.break();
|
|
70
|
+
setupVault();
|
|
71
|
+
const vaultSeedId = "local-seed";
|
|
72
|
+
const localIdentity = "local";
|
|
73
|
+
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
74
|
+
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
|
|
75
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
|
|
76
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
77
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network, addressIndex, vaultSeedId }, opts.connector);
|
|
78
|
+
CLIDisplay.task(I18n.formatMessage("commands.verification-method-remove.progress.removingVerificationMethod"));
|
|
79
|
+
CLIDisplay.break();
|
|
80
|
+
CLIDisplay.spinnerStart();
|
|
81
|
+
await identityConnector.removeVerificationMethod(localIdentity, id);
|
|
82
|
+
CLIDisplay.spinnerStop();
|
|
83
|
+
const did = DocumentHelper.parseId(id).id;
|
|
84
|
+
if (opts.connector === IdentityConnectorTypes.Iota) {
|
|
85
|
+
const didUrn = Urn.fromValidString(did);
|
|
86
|
+
const didParts = didUrn.parts();
|
|
87
|
+
const objectId = didParts[didParts.length - 1];
|
|
88
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`);
|
|
89
|
+
}
|
|
90
|
+
CLIDisplay.break();
|
|
91
|
+
CLIDisplay.done();
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=verificationMethodRemove.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verificationMethodRemove.js","sourceRoot":"","sources":["../../../src/commands/verificationMethodRemove.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACtE,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,qBAA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ACd,CAAC;IAEF,UAAU,CAAC,IAAI,CACd,IAAI,CAAC,aAAa,CAAC,yEAAyE,CAAC,CAC7F,CAAC;IACF,UAAU,CAAC,KAAK,EAAE,CAAC;IAEnB,UAAU,CAAC,YAAY,EAAE,CAAC;IAE1B,MAAM,iBAAiB,CAAC,wBAAwB,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;IAEpE,UAAU,CAAC,WAAW,EAAE,CAAC;IAEzB,MAAM,GAAG,GAAG,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IAC1C,IAAI,IAAI,CAAC,SAAS,KAAK,sBAAsB,CAAC,IAAI,EAAE,CAAC;QACpD,MAAM,MAAM,GAAG,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QACxC,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC/C,UAAU,CAAC,KAAK,CACf,IAAI,CAAC,aAAa,CAAC,gCAAgC,CAAC,EACpD,GAAG,YAAY,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,WAAW,QAAQ,YAAY,OAAO,EAAE,CAC7F,CAAC;IACH,CAAC;IACD,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 { CLIDisplay, CLIOptions, CLIParam } from \"@twin.org/cli-core\";\nimport { Converter, I18n, Is, StringHelper, Urn } from \"@twin.org/core\";\nimport { DocumentHelper } from \"@twin.org/identity-models\";\nimport { VaultConnectorFactory } from \"@twin.org/vault-models\";\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 verification method remove command for the CLI.\n * @returns The command.\n */\nexport function buildCommandVerificationMethodRemove(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"verification-method-remove\")\n\t\t.summary(I18n.formatMessage(\"commands.verification-method-remove.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.verification-method-remove.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verification-method-remove.options.seed.param\"),\n\t\t\tI18n.formatMessage(\"commands.verification-method-remove.options.seed.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verification-method-remove.options.id.param\"),\n\t\t\tI18n.formatMessage(\"commands.verification-method-remove.options.id.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verification-method-remove.options.addressIndex.param\"),\n\t\t\tI18n.formatMessage(\"commands.verification-method-remove.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(actionCommandVerificationMethodRemove);\n\n\treturn command;\n}\n\n/**\n * Action the verification method remove command.\n * @param opts The options for the command.\n * @param opts.seed The private key for the controller.\n * @param opts.id The id of the verification method to remove.\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 actionCommandVerificationMethodRemove(opts: {\n\tseed: string;\n\tid: string;\n\taddressIndex?: string;\n\tconnector?: IdentityConnectorTypes;\n\tnode: string;\n\tnetwork?: string;\n\texplorer: string;\n}): Promise<void> {\n\tconst seed: Uint8Array = CLIParam.hexBase64(\"seed\", opts.seed);\n\tconst id: string = CLIParam.stringValue(\"id\", opts.id);\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(\n\t\tI18n.formatMessage(\"commands.verification-method-remove.labels.verificationMethodId\"),\n\t\tid\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verification-method-remove.labels.addressIndex\"),\n\t\taddressIndex\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.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-remove.progress.removingVerificationMethod\")\n\t);\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tawait identityConnector.removeVerificationMethod(localIdentity, id);\n\n\tCLIDisplay.spinnerStop();\n\n\tconst did = DocumentHelper.parseId(id).id;\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\tCLIDisplay.break();\n\n\tCLIDisplay.done();\n}\n"]}
|
package/dist/es/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
export * from "./cli.js";
|
|
4
|
+
export * from "./commands/identityCreate.js";
|
|
5
|
+
export * from "./commands/identityResolve.js";
|
|
6
|
+
export * from "./commands/proofCreate.js";
|
|
7
|
+
export * from "./commands/proofVerify.js";
|
|
8
|
+
export * from "./commands/serviceAdd.js";
|
|
9
|
+
export * from "./commands/serviceRemove.js";
|
|
10
|
+
export * from "./commands/setupCommands.js";
|
|
11
|
+
export * from "./commands/verifiableCredentialCreate.js";
|
|
12
|
+
export * from "./commands/verifiableCredentialRevoke.js";
|
|
13
|
+
export * from "./commands/verifiableCredentialUnrevoke.js";
|
|
14
|
+
export * from "./commands/verifiableCredentialVerify.js";
|
|
15
|
+
export * from "./commands/verificationMethodAdd.js";
|
|
16
|
+
export * from "./commands/verificationMethodRemove.js";
|
|
17
|
+
export * from "./models/identityConnectorTypes.js";
|
|
18
|
+
export * from "./models/identityResolverConnectorTypes.js";
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
/**
|
|
4
|
+
* The identity connector types.
|
|
5
|
+
*/
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7
|
+
export const IdentityConnectorTypes = {
|
|
8
|
+
/**
|
|
9
|
+
* IOTA.
|
|
10
|
+
*/
|
|
11
|
+
Iota: "iota"
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=identityConnectorTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identityConnectorTypes.js","sourceRoot":"","sources":["../../../src/models/identityConnectorTypes.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACrC;;OAEG;IACH,IAAI,EAAE,MAAM;CACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The identity connector types.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const IdentityConnectorTypes = {\n\t/**\n\t * IOTA.\n\t */\n\tIota: \"iota\"\n} as const;\n\n/**\n * The identity connector types.\n */\nexport type IdentityConnectorTypes =\n\t(typeof IdentityConnectorTypes)[keyof typeof IdentityConnectorTypes];\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
/**
|
|
4
|
+
* The identity resolver connector types.
|
|
5
|
+
*/
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7
|
+
export const IdentityResolverConnectorTypes = {
|
|
8
|
+
/**
|
|
9
|
+
* IOTA.
|
|
10
|
+
*/
|
|
11
|
+
Iota: "iota"
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=identityResolverConnectorTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identityResolverConnectorTypes.js","sourceRoot":"","sources":["../../../src/models/identityResolverConnectorTypes.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC7C;;OAEG;IACH,IAAI,EAAE,MAAM;CACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The identity resolver connector types.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const IdentityResolverConnectorTypes = {\n\t/**\n\t * IOTA.\n\t */\n\tIota: \"iota\"\n} as const;\n\n/**\n * The identity resolver connector types.\n */\nexport type IdentityResolverConnectorTypes =\n\t(typeof IdentityResolverConnectorTypes)[keyof typeof IdentityResolverConnectorTypes];\n"]}
|
package/dist/locales/en.json
CHANGED
|
@@ -82,7 +82,9 @@
|
|
|
82
82
|
"url": "Property \"{property}\" must be a Url formatted string, it is \"{value}\"",
|
|
83
83
|
"email": "Property \"{property}\" must be string in e-mail format, it is \"{value}\"",
|
|
84
84
|
"length32Multiple": "Property \"{property}\" should be a multiple of 32, it is {value}",
|
|
85
|
-
"lengthEntropy": "Property \"{property}\" should be a multiple of 4, >=16 and <= 32, it is {value}"
|
|
85
|
+
"lengthEntropy": "Property \"{property}\" should be a multiple of 4, >=16 and <= 32, it is {value}",
|
|
86
|
+
"didPartsTooFew": "The DID \"{value}\" is invalid: expected at least 3 parts but got fewer",
|
|
87
|
+
"didInvalidStart": "The DID \"{value}\" is invalid: expected to start with 'did'"
|
|
86
88
|
},
|
|
87
89
|
"objectHelper": {
|
|
88
90
|
"failedBytesToJSON": "Failed converting bytes to JSON",
|
|
@@ -205,6 +207,13 @@
|
|
|
205
207
|
"createFailed": "Failed to create JWS",
|
|
206
208
|
"verifyFailed": "Failed to verify JWS"
|
|
207
209
|
},
|
|
210
|
+
"contextIdHelper": {
|
|
211
|
+
"contextIdMissing": "The context ID \"{key}\" is missing from the provided context IDs",
|
|
212
|
+
"contextIdSplitMismatch": "The context ID split parts length \"{actual}\" does not match the provided keys length \"{expected}\""
|
|
213
|
+
},
|
|
214
|
+
"contextIdStore": {
|
|
215
|
+
"asyncHooksNotAvailable": "Async Hooks are not available in this environment, please ensure you are running in Node.js"
|
|
216
|
+
},
|
|
208
217
|
"verificationHelper": {
|
|
209
218
|
"jwtDecodeFailed": "Decoding the JWT failed",
|
|
210
219
|
"proofMissingVerificationMethod": "The proof is missing the verification method"
|
|
@@ -213,9 +222,6 @@
|
|
|
213
222
|
"verificationMethodNotFound": "The verification method \"{methodName}\" of type \"{methodType}\" could not be found",
|
|
214
223
|
"verificationMethodJwkNotFound": "The verification method \"{methodName}\" of type \"{methodType}\" is missing the JWK"
|
|
215
224
|
},
|
|
216
|
-
"idHelper": {
|
|
217
|
-
"invalidDocumentId": "The document id \"{id}\" is invalid"
|
|
218
|
-
},
|
|
219
225
|
"proofHelper": {
|
|
220
226
|
"unsupportedProofType": "Proof type \"{proofType}\" not supported."
|
|
221
227
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type CliOutputOptions } from "@twin.org/cli-core";
|
|
2
2
|
import { Command } from "commander";
|
|
3
|
-
import { IdentityConnectorTypes } from "../models/identityConnectorTypes";
|
|
3
|
+
import { IdentityConnectorTypes } from "../models/identityConnectorTypes.js";
|
|
4
4
|
/**
|
|
5
5
|
* Build the identity create command for the CLI.
|
|
6
6
|
* @returns The command.
|