@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,112 @@
|
|
|
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 { 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 service add command for the CLI.
|
|
13
|
+
* @returns The command.
|
|
14
|
+
*/
|
|
15
|
+
export function buildCommandServiceAdd() {
|
|
16
|
+
const command = new Command();
|
|
17
|
+
command
|
|
18
|
+
.name("service-add")
|
|
19
|
+
.summary(I18n.formatMessage("commands.service-add.summary"))
|
|
20
|
+
.description(I18n.formatMessage("commands.service-add.description"))
|
|
21
|
+
.requiredOption(I18n.formatMessage("commands.service-add.options.seed.param"), I18n.formatMessage("commands.service-add.options.seed.description"))
|
|
22
|
+
.requiredOption(I18n.formatMessage("commands.service-add.options.did.param"), I18n.formatMessage("commands.service-add.options.did.description"))
|
|
23
|
+
.requiredOption(I18n.formatMessage("commands.service-add.options.id.param"), I18n.formatMessage("commands.service-add.options.id.description"))
|
|
24
|
+
.requiredOption(I18n.formatMessage("commands.service-add.options.type.param"), I18n.formatMessage("commands.service-add.options.type.description"))
|
|
25
|
+
.requiredOption(I18n.formatMessage("commands.service-add.options.endpoint.param"), I18n.formatMessage("commands.service-add.options.endpoint.description"))
|
|
26
|
+
.option(I18n.formatMessage("commands.service-add.options.addressIndex.param"), I18n.formatMessage("commands.service-add.options.addressIndex.description"), "0");
|
|
27
|
+
CLIOptions.output(command, {
|
|
28
|
+
noConsole: true,
|
|
29
|
+
json: true,
|
|
30
|
+
env: true,
|
|
31
|
+
mergeJson: true,
|
|
32
|
+
mergeEnv: true
|
|
33
|
+
});
|
|
34
|
+
command
|
|
35
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
36
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
37
|
+
.default(IdentityConnectorTypes.Iota))
|
|
38
|
+
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
39
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
40
|
+
.option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
41
|
+
.action(actionCommandServiceAdd);
|
|
42
|
+
return command;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Action the service add command.
|
|
46
|
+
* @param opts The options for the command.
|
|
47
|
+
* @param opts.seed The private key for the controller.
|
|
48
|
+
* @param opts.did The identity of the document to add to.
|
|
49
|
+
* @param opts.id The id of the service to add.
|
|
50
|
+
* @param opts.type The type of the service to add.
|
|
51
|
+
* @param opts.endpoint The service endpoint.
|
|
52
|
+
* @param opts.addressIndex The address index to use for key derivation (if applicable).
|
|
53
|
+
* @param opts.connector The connector to perform the operations with.
|
|
54
|
+
* @param opts.node The node URL.
|
|
55
|
+
* @param opts.explorer The explorer URL.
|
|
56
|
+
*/
|
|
57
|
+
export async function actionCommandServiceAdd(opts) {
|
|
58
|
+
const seed = CLIParam.hexBase64("seed", opts.seed);
|
|
59
|
+
const did = CLIParam.stringValue("did", opts.did);
|
|
60
|
+
const id = CLIParam.stringValue("id", opts.id);
|
|
61
|
+
const type = CLIParam.stringValue("type", opts.type);
|
|
62
|
+
const endpoint = CLIParam.url("endpoint", opts.endpoint);
|
|
63
|
+
const addressIndex = CLIParam.integer("addressIndex", opts.addressIndex ?? "0", false, 0);
|
|
64
|
+
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
65
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
66
|
+
? CLIParam.stringValue("network", opts.network)
|
|
67
|
+
: undefined;
|
|
68
|
+
const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
|
|
69
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.did"), did);
|
|
70
|
+
CLIDisplay.value(I18n.formatMessage("commands.service-add.labels.serviceId"), id);
|
|
71
|
+
CLIDisplay.value(I18n.formatMessage("commands.service-add.labels.serviceType"), type);
|
|
72
|
+
CLIDisplay.value(I18n.formatMessage("commands.service-add.labels.serviceEndpoint"), endpoint);
|
|
73
|
+
CLIDisplay.value(I18n.formatMessage("commands.service-add.labels.addressIndex"), addressIndex);
|
|
74
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
75
|
+
if (Is.stringValue(network)) {
|
|
76
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
77
|
+
}
|
|
78
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
|
|
79
|
+
CLIDisplay.break();
|
|
80
|
+
setupVault();
|
|
81
|
+
const vaultSeedId = "local-seed";
|
|
82
|
+
const localIdentity = "local";
|
|
83
|
+
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
84
|
+
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
|
|
85
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
|
|
86
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
87
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network, addressIndex, vaultSeedId }, opts.connector);
|
|
88
|
+
CLIDisplay.task(I18n.formatMessage("commands.service-add.progress.addingService"));
|
|
89
|
+
CLIDisplay.break();
|
|
90
|
+
CLIDisplay.spinnerStart();
|
|
91
|
+
const service = await identityConnector.addService(localIdentity, did, id, type, endpoint);
|
|
92
|
+
CLIDisplay.spinnerStop();
|
|
93
|
+
if (Is.stringValue(opts?.json)) {
|
|
94
|
+
await CLIUtils.writeJsonFile(opts.json, service, opts.mergeJson);
|
|
95
|
+
}
|
|
96
|
+
if (Is.stringValue(opts?.env)) {
|
|
97
|
+
await CLIUtils.writeEnvFile(opts.env, [
|
|
98
|
+
`DID_SERVICE_ID="${service.id}"`,
|
|
99
|
+
`DID_SERVICE_TYPE="${Is.string(service.type) ? service.type : service.type.join(",")}"`,
|
|
100
|
+
`DID_SERVICE_ENDPOINT="${Is.string(service.serviceEndpoint) ? service.serviceEndpoint : service.serviceEndpoint.join(",")}"`
|
|
101
|
+
], opts.mergeEnv);
|
|
102
|
+
}
|
|
103
|
+
if (opts.connector === IdentityConnectorTypes.Iota) {
|
|
104
|
+
const didUrn = Urn.fromValidString(did);
|
|
105
|
+
const didParts = didUrn.parts();
|
|
106
|
+
const objectId = didParts[didParts.length - 1];
|
|
107
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`);
|
|
108
|
+
}
|
|
109
|
+
CLIDisplay.break();
|
|
110
|
+
CLIDisplay.done();
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=serviceAdd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serviceAdd.js","sourceRoot":"","sources":["../../../src/commands/serviceAdd.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,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,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,sBAAsB;IACrC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAC9B,OAAO;SACL,IAAI,CAAC,aAAa,CAAC;SACnB,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,8BAA8B,CAAC,CAAC;SAC3D,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,kCAAkC,CAAC,CAAC;SAC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AC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG;SAC5H,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 { 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 service add command for the CLI.\n * @returns The command.\n */\nexport function buildCommandServiceAdd(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"service-add\")\n\t\t.summary(I18n.formatMessage(\"commands.service-add.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.service-add.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.service-add.options.seed.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-add.options.seed.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.service-add.options.did.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-add.options.did.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.service-add.options.id.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-add.options.id.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.service-add.options.type.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-add.options.type.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.service-add.options.endpoint.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-add.options.endpoint.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.service-add.options.addressIndex.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-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(actionCommandServiceAdd);\n\n\treturn command;\n}\n\n/**\n * Action the service 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.id The id of the service to add.\n * @param opts.type The type of the service to add.\n * @param opts.endpoint The service endpoint.\n * @param opts.addressIndex The address index to use for key derivation (if applicable).\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 */\nexport async function actionCommandServiceAdd(\n\topts: {\n\t\tseed: string;\n\t\tdid: string;\n\t\tid: string;\n\t\ttype: string;\n\t\tendpoint: 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 id: string = CLIParam.stringValue(\"id\", opts.id);\n\tconst type: string = CLIParam.stringValue(\"type\", opts.type);\n\tconst endpoint: string = CLIParam.url(\"endpoint\", opts.endpoint);\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(I18n.formatMessage(\"commands.service-add.labels.serviceId\"), id);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.service-add.labels.serviceType\"), type);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.service-add.labels.serviceEndpoint\"), endpoint);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.service-add.labels.addressIndex\"), addressIndex);\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(I18n.formatMessage(\"commands.service-add.progress.addingService\"));\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tconst service = await identityConnector.addService(localIdentity, did, id, type, endpoint);\n\n\tCLIDisplay.spinnerStop();\n\n\tif (Is.stringValue(opts?.json)) {\n\t\tawait CLIUtils.writeJsonFile(opts.json, service, 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_SERVICE_ID=\"${service.id}\"`,\n\t\t\t\t`DID_SERVICE_TYPE=\"${Is.string(service.type) ? service.type : service.type.join(\",\")}\"`,\n\t\t\t\t`DID_SERVICE_ENDPOINT=\"${Is.string(service.serviceEndpoint) ? service.serviceEndpoint : service.serviceEndpoint.join(\",\")}\"`\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 service remove command for the CLI.
|
|
14
|
+
* @returns The command.
|
|
15
|
+
*/
|
|
16
|
+
export function buildCommandServiceRemove() {
|
|
17
|
+
const command = new Command();
|
|
18
|
+
command
|
|
19
|
+
.name("service-remove")
|
|
20
|
+
.summary(I18n.formatMessage("commands.service-remove.summary"))
|
|
21
|
+
.description(I18n.formatMessage("commands.service-remove.description"))
|
|
22
|
+
.requiredOption(I18n.formatMessage("commands.service-remove.options.seed.param"), I18n.formatMessage("commands.service-remove.options.seed.description"))
|
|
23
|
+
.requiredOption(I18n.formatMessage("commands.service-remove.options.id.param"), I18n.formatMessage("commands.service-remove.options.id.description"))
|
|
24
|
+
.option(I18n.formatMessage("commands.service-remove.options.addressIndex.param"), I18n.formatMessage("commands.service-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(actionCommandServiceRemove);
|
|
40
|
+
return command;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Action the service 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 service to remove.
|
|
47
|
+
* @param opts.connector The connector to perform the operations with.
|
|
48
|
+
* @param opts.node The node URL.
|
|
49
|
+
* @param opts.network The network to use for connector.
|
|
50
|
+
* @param opts.explorer The explorer URL.
|
|
51
|
+
* @param opts.addressIndex The address index to use for key derivation (if applicable).
|
|
52
|
+
*/
|
|
53
|
+
export async function actionCommandServiceRemove(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.service-remove.labels.serviceId"), id);
|
|
63
|
+
CLIDisplay.value(I18n.formatMessage("commands.service-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.service-remove.progress.removingService"));
|
|
79
|
+
CLIDisplay.break();
|
|
80
|
+
CLIDisplay.spinnerStart();
|
|
81
|
+
await identityConnector.removeService(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=serviceRemove.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serviceRemove.js","sourceRoot":"","sources":["../../../src/commands/serviceRemove.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,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,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,yBAAyB;IACxC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAC9B,OAAO;SACL,IAAI,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,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 { 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 service remove command for the CLI.\n * @returns The command.\n */\nexport function buildCommandServiceRemove(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"service-remove\")\n\t\t.summary(I18n.formatMessage(\"commands.service-remove.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.service-remove.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.service-remove.options.seed.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-remove.options.seed.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.service-remove.options.id.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-remove.options.id.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.service-remove.options.addressIndex.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-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(actionCommandServiceRemove);\n\n\treturn command;\n}\n\n/**\n * Action the service 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 service to remove.\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.explorer The explorer URL.\n * @param opts.addressIndex The address index to use for key derivation (if applicable).\n */\nexport async function actionCommandServiceRemove(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(I18n.formatMessage(\"commands.service-remove.labels.serviceId\"), id);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.service-remove.labels.addressIndex\"), addressIndex);\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(I18n.formatMessage(\"commands.service-remove.progress.removingService\"));\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tawait identityConnector.removeService(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\n\tCLIDisplay.break();\n\n\tCLIDisplay.done();\n}\n"]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { MemoryEntityStorageConnector } from "@twin.org/entity-storage-connector-memory";
|
|
4
|
+
import { EntityStorageConnectorFactory } from "@twin.org/entity-storage-models";
|
|
5
|
+
import { IotaIdentityConnector, IotaIdentityResolverConnector } from "@twin.org/identity-connector-iota";
|
|
6
|
+
import { EntityStorageVaultConnector, initSchema } from "@twin.org/vault-connector-entity-storage";
|
|
7
|
+
import { VaultConnectorFactory } from "@twin.org/vault-models";
|
|
8
|
+
import { IdentityConnectorTypes } from "../models/identityConnectorTypes.js";
|
|
9
|
+
import { IdentityResolverConnectorTypes } from "../models/identityResolverConnectorTypes.js";
|
|
10
|
+
/**
|
|
11
|
+
* Setup the vault for use in the CLI commands.
|
|
12
|
+
*/
|
|
13
|
+
export function setupVault() {
|
|
14
|
+
initSchema();
|
|
15
|
+
EntityStorageConnectorFactory.register("vault-key", () => new MemoryEntityStorageConnector({
|
|
16
|
+
entitySchema: "VaultKey"
|
|
17
|
+
}));
|
|
18
|
+
EntityStorageConnectorFactory.register("vault-secret", () => new MemoryEntityStorageConnector({
|
|
19
|
+
entitySchema: "VaultSecret"
|
|
20
|
+
}));
|
|
21
|
+
const vaultConnector = new EntityStorageVaultConnector();
|
|
22
|
+
VaultConnectorFactory.register("vault", () => vaultConnector);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Setup the identity connector for use in the CLI commands.
|
|
26
|
+
* @param options The options for the identity connector.
|
|
27
|
+
* @param options.nodeEndpoint The node endpoint.
|
|
28
|
+
* @param options.network The network.
|
|
29
|
+
* @param options.addressIndex The wallet index.
|
|
30
|
+
* @param options.vaultSeedId The vault seed ID.
|
|
31
|
+
* @param connector The connector to use.
|
|
32
|
+
* @returns The identity connector.
|
|
33
|
+
*/
|
|
34
|
+
export function setupIdentityConnector(options, connector) {
|
|
35
|
+
connector ??= IdentityConnectorTypes.Iota;
|
|
36
|
+
return new IotaIdentityConnector({
|
|
37
|
+
config: {
|
|
38
|
+
clientOptions: {
|
|
39
|
+
url: options.nodeEndpoint
|
|
40
|
+
},
|
|
41
|
+
network: options.network ?? "",
|
|
42
|
+
vaultSeedId: options.vaultSeedId,
|
|
43
|
+
walletAddressIndex: options.addressIndex
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Setup the identity resolver connector for use in the CLI commands.
|
|
49
|
+
* @param options The options for the identity connector.
|
|
50
|
+
* @param options.nodeEndpoint The node endpoint.
|
|
51
|
+
* @param options.network The network.
|
|
52
|
+
* @param connector The connector to use.
|
|
53
|
+
* @returns The identity connector.
|
|
54
|
+
*/
|
|
55
|
+
export function setupIdentityResolverConnector(options, connector) {
|
|
56
|
+
connector ??= IdentityResolverConnectorTypes.Iota;
|
|
57
|
+
return new IotaIdentityResolverConnector({
|
|
58
|
+
config: {
|
|
59
|
+
clientOptions: {
|
|
60
|
+
url: options.nodeEndpoint
|
|
61
|
+
},
|
|
62
|
+
network: options.network ?? ""
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=setupCommands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setupCommands.js","sourceRoot":"","sources":["../../../src/commands/setupCommands.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC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AAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,8BAA8B,CAC7C,OAAmD,EACnD,SAA0C;IAE1C,SAAS,KAAK,8BAA8B,CAAC,IAAI,CAAC;IAElD,OAAO,IAAI,6BAA6B,CAAC;QACxC,MAAM,EAAE;YACP,aAAa,EAAE;gBACd,GAAG,EAAE,OAAO,CAAC,YAAY;aACzB;YACD,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE;SAC9B;KACD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { MemoryEntityStorageConnector } from \"@twin.org/entity-storage-connector-memory\";\nimport { EntityStorageConnectorFactory } from \"@twin.org/entity-storage-models\";\nimport {\n\tIotaIdentityConnector,\n\tIotaIdentityResolverConnector\n} from \"@twin.org/identity-connector-iota\";\nimport type { IIdentityConnector, IIdentityResolverConnector } from \"@twin.org/identity-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tEntityStorageVaultConnector,\n\ttype VaultKey,\n\ttype VaultSecret,\n\tinitSchema\n} from \"@twin.org/vault-connector-entity-storage\";\nimport { VaultConnectorFactory } from \"@twin.org/vault-models\";\nimport { IdentityConnectorTypes } from \"../models/identityConnectorTypes.js\";\nimport { IdentityResolverConnectorTypes } from \"../models/identityResolverConnectorTypes.js\";\n\n/**\n * Setup the vault for use in the CLI commands.\n */\nexport function setupVault(): void {\n\tinitSchema();\n\n\tEntityStorageConnectorFactory.register(\n\t\t\"vault-key\",\n\t\t() =>\n\t\t\tnew MemoryEntityStorageConnector<VaultKey>({\n\t\t\t\tentitySchema: nameof<VaultKey>()\n\t\t\t})\n\t);\n\tEntityStorageConnectorFactory.register(\n\t\t\"vault-secret\",\n\t\t() =>\n\t\t\tnew MemoryEntityStorageConnector<VaultSecret>({\n\t\t\t\tentitySchema: nameof<VaultSecret>()\n\t\t\t})\n\t);\n\n\tconst vaultConnector = new EntityStorageVaultConnector();\n\tVaultConnectorFactory.register(\"vault\", () => vaultConnector);\n}\n\n/**\n * Setup the identity connector for use in the CLI commands.\n * @param options The options for the identity connector.\n * @param options.nodeEndpoint The node endpoint.\n * @param options.network The network.\n * @param options.addressIndex The wallet index.\n * @param options.vaultSeedId The vault seed ID.\n * @param connector The connector to use.\n * @returns The identity connector.\n */\nexport function setupIdentityConnector(\n\toptions: { nodeEndpoint: string; network?: string; addressIndex?: number; vaultSeedId?: string },\n\tconnector?: IdentityConnectorTypes\n): IIdentityConnector {\n\tconnector ??= IdentityConnectorTypes.Iota;\n\n\treturn new IotaIdentityConnector({\n\t\tconfig: {\n\t\t\tclientOptions: {\n\t\t\t\turl: options.nodeEndpoint\n\t\t\t},\n\t\t\tnetwork: options.network ?? \"\",\n\t\t\tvaultSeedId: options.vaultSeedId,\n\t\t\twalletAddressIndex: options.addressIndex\n\t\t}\n\t});\n}\n\n/**\n * Setup the identity resolver connector for use in the CLI commands.\n * @param options The options for the identity connector.\n * @param options.nodeEndpoint The node endpoint.\n * @param options.network The network.\n * @param connector The connector to use.\n * @returns The identity connector.\n */\nexport function setupIdentityResolverConnector(\n\toptions: { nodeEndpoint: string; network?: string },\n\tconnector?: IdentityResolverConnectorTypes\n): IIdentityResolverConnector {\n\tconnector ??= IdentityResolverConnectorTypes.Iota;\n\n\treturn new IotaIdentityResolverConnector({\n\t\tconfig: {\n\t\t\tclientOptions: {\n\t\t\t\turl: options.nodeEndpoint\n\t\t\t},\n\t\t\tnetwork: options.network ?? \"\"\n\t\t}\n\t});\n}\n"]}
|
|
@@ -0,0 +1,113 @@
|
|
|
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 { Coerce, GeneralError, I18n, Is } from "@twin.org/core";
|
|
6
|
+
import { DocumentHelper } from "@twin.org/identity-models";
|
|
7
|
+
import { VaultConnectorFactory, VaultKeyType } from "@twin.org/vault-models";
|
|
8
|
+
import { setupWalletConnector } from "@twin.org/wallet-cli";
|
|
9
|
+
import { WalletConnectorFactory } from "@twin.org/wallet-models";
|
|
10
|
+
import { Command, Option } from "commander";
|
|
11
|
+
import { setupIdentityConnector, setupVault } from "./setupCommands.js";
|
|
12
|
+
import { IdentityConnectorTypes } from "../models/identityConnectorTypes.js";
|
|
13
|
+
/**
|
|
14
|
+
* Build the verifiable credential create command for the CLI.
|
|
15
|
+
* @returns The command.
|
|
16
|
+
*/
|
|
17
|
+
export function buildCommandVerifiableCredentialCreate() {
|
|
18
|
+
const command = new Command();
|
|
19
|
+
command
|
|
20
|
+
.name("verifiable-credential-create")
|
|
21
|
+
.summary(I18n.formatMessage("commands.verifiable-credential-create.summary"))
|
|
22
|
+
.description(I18n.formatMessage("commands.verifiable-credential-create.description"))
|
|
23
|
+
.requiredOption(I18n.formatMessage("commands.verifiable-credential-create.options.id.param"), I18n.formatMessage("commands.verifiable-credential-create.options.id.description"))
|
|
24
|
+
.requiredOption(I18n.formatMessage("commands.verifiable-credential-create.options.private-key.param"), I18n.formatMessage("commands.verifiable-credential-create.options.private-key.description"))
|
|
25
|
+
.option(I18n.formatMessage("commands.verifiable-credential-create.options.credential-id.param"), I18n.formatMessage("commands.verifiable-credential-create.options.credential-id.description"))
|
|
26
|
+
.requiredOption(I18n.formatMessage("commands.verifiable-credential-create.options.subject-json.param"), I18n.formatMessage("commands.verifiable-credential-create.options.subject-json.description"))
|
|
27
|
+
.option(I18n.formatMessage("commands.verifiable-credential-create.options.revocation-index.param"), I18n.formatMessage("commands.verifiable-credential-create.options.revocation-index.description"))
|
|
28
|
+
.option(I18n.formatMessage("commands.verifiable-credential-create.options.addressIndex.param"), I18n.formatMessage("commands.verifiable-credential-create.options.addressIndex.description"), "0");
|
|
29
|
+
CLIOptions.output(command, {
|
|
30
|
+
noConsole: true,
|
|
31
|
+
json: true,
|
|
32
|
+
env: true,
|
|
33
|
+
mergeJson: true,
|
|
34
|
+
mergeEnv: true
|
|
35
|
+
});
|
|
36
|
+
command
|
|
37
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
38
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
39
|
+
.default(IdentityConnectorTypes.Iota))
|
|
40
|
+
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
41
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
42
|
+
.action(actionCommandVerifiableCredentialCreate);
|
|
43
|
+
return command;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Action the verifiable credential create command.
|
|
47
|
+
* @param opts The options for the command.
|
|
48
|
+
* @param opts.id The id of the verification method to use for the credential.
|
|
49
|
+
* @param opts.privateKey The private key for the verification method.
|
|
50
|
+
* @param opts.credentialId The id of the credential.
|
|
51
|
+
* @param opts.subjectJson The JSON data for the subject.
|
|
52
|
+
* @param opts.revocationIndex The revocation index for the credential.
|
|
53
|
+
* @param opts.addressIndex The address index to use for key derivation (if applicable).
|
|
54
|
+
* @param opts.connector The connector to perform the operations with.
|
|
55
|
+
* @param opts.node The node URL.
|
|
56
|
+
*/
|
|
57
|
+
export async function actionCommandVerifiableCredentialCreate(opts) {
|
|
58
|
+
const id = CLIParam.stringValue("id", opts.id);
|
|
59
|
+
const privateKey = CLIParam.hexBase64("private-key", opts.privateKey);
|
|
60
|
+
const credentialId = CLIParam.stringValue("credential-id", opts.credentialId);
|
|
61
|
+
const subjectJson = path.resolve(CLIParam.stringValue("subject-json", opts.subjectJson));
|
|
62
|
+
const revocationIndex = Coerce.number(opts.revocationIndex);
|
|
63
|
+
const addressIndex = CLIParam.integer("addressIndex", opts.addressIndex ?? "0", false, 0);
|
|
64
|
+
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
65
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
66
|
+
? CLIParam.stringValue("network", opts.network)
|
|
67
|
+
: undefined;
|
|
68
|
+
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.verificationMethodId"), id);
|
|
69
|
+
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.credentialId"), credentialId);
|
|
70
|
+
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.subjectJson"), subjectJson);
|
|
71
|
+
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.revocationIndex"), revocationIndex);
|
|
72
|
+
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.addressIndex"), addressIndex);
|
|
73
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
74
|
+
if (Is.stringValue(network)) {
|
|
75
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
76
|
+
}
|
|
77
|
+
CLIDisplay.break();
|
|
78
|
+
setupVault();
|
|
79
|
+
const localIdentity = "local";
|
|
80
|
+
const vmParts = DocumentHelper.parseId(id);
|
|
81
|
+
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
82
|
+
await vaultConnector.addKey(`${localIdentity}/${vmParts.fragment}`, VaultKeyType.Ed25519, privateKey, new Uint8Array());
|
|
83
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);
|
|
84
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
85
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network, addressIndex }, opts.connector);
|
|
86
|
+
CLIDisplay.task(I18n.formatMessage("commands.verifiable-credential-create.progress.loadingSubjectData"));
|
|
87
|
+
CLIDisplay.break();
|
|
88
|
+
const jsonData = await CLIUtils.readJsonFile(subjectJson);
|
|
89
|
+
if (Is.undefined(jsonData)) {
|
|
90
|
+
throw new GeneralError("commands", "commands.verifiable-credential-create.subjectJsonFileNotFound");
|
|
91
|
+
}
|
|
92
|
+
CLIDisplay.task(I18n.formatMessage("commands.verifiable-credential-create.progress.creatingVerifiableCredential"));
|
|
93
|
+
CLIDisplay.break();
|
|
94
|
+
CLIDisplay.spinnerStart();
|
|
95
|
+
const verifiableCredential = await identityConnector.createVerifiableCredential(localIdentity, id, credentialId, jsonData, {
|
|
96
|
+
revocationIndex
|
|
97
|
+
});
|
|
98
|
+
CLIDisplay.spinnerStop();
|
|
99
|
+
if (opts.console) {
|
|
100
|
+
CLIDisplay.section(I18n.formatMessage("commands.verifiable-credential-create.labels.verifiableCredential"));
|
|
101
|
+
CLIDisplay.write(verifiableCredential.jwt);
|
|
102
|
+
CLIDisplay.break();
|
|
103
|
+
CLIDisplay.break();
|
|
104
|
+
}
|
|
105
|
+
if (Is.stringValue(opts?.json)) {
|
|
106
|
+
await CLIUtils.writeJsonFile(opts.json, { verifiableCredentialJwt: verifiableCredential.jwt }, opts.mergeJson);
|
|
107
|
+
}
|
|
108
|
+
if (Is.stringValue(opts?.env)) {
|
|
109
|
+
await CLIUtils.writeEnvFile(opts.env, [`DID_VERIFIABLE_CREDENTIAL_JWT="${verifiableCredential.jwt}"`], opts.mergeEnv);
|
|
110
|
+
}
|
|
111
|
+
CLIDisplay.done();
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=verifiableCredentialCreate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verifiableCredentialCreate.js","sourceRoot":"","sources":["../../../src/commands/verifiableCredentialCreate.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,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAEhE,OAAO,EAAE,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aAAa,EACb,EAAE,EACF,YAAY,EACZ,QAAQ,EACR;QACC,eAAe;KACf,CACD,CAAC;IAEF,UAAU,CAAC,WAAW,EAAE,CAAC;IAEzB,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QAClB,UAAU,CAAC,OAAO,CACjB,IAAI,CAAC,aAAa,CAAC,mEAAmE,CAAC,CACvF,CAAC;QAEF,UAAU,CAAC,KAAK,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC;QAC3C,UAAU,CAAC,KAAK,EAAE,CAAC;QACnB,UAAU,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;IAED,IAAI,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;QAChC,MAAM,QAAQ,CAAC,aAAa,CAC3B,IAAI,CAAC,IAAI,EACT,EAAE,uBAAuB,EAAE,oBAAoB,CAAC,GAAG,EAAE,EACrD,IAAI,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,CAAC,kCAAkC,oBAAoB,CAAC,GAAG,GAAG,CAAC,EAC/D,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 { Coerce, GeneralError, I18n, Is } from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport { DocumentHelper } from \"@twin.org/identity-models\";\nimport { VaultConnectorFactory, VaultKeyType } 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 verifiable credential create command for the CLI.\n * @returns The command.\n */\nexport function buildCommandVerifiableCredentialCreate(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"verifiable-credential-create\")\n\t\t.summary(I18n.formatMessage(\"commands.verifiable-credential-create.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.verifiable-credential-create.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.id.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.id.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.private-key.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.private-key.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.credential-id.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.credential-id.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.subject-json.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.subject-json.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.revocation-index.param\"),\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"commands.verifiable-credential-create.options.revocation-index.description\"\n\t\t\t)\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.addressIndex.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.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.action(actionCommandVerifiableCredentialCreate);\n\n\treturn command;\n}\n\n/**\n * Action the verifiable credential create command.\n * @param opts The options for the command.\n * @param opts.id The id of the verification method to use for the credential.\n * @param opts.privateKey The private key for the verification method.\n * @param opts.credentialId The id of the credential.\n * @param opts.subjectJson The JSON data for the subject.\n * @param opts.revocationIndex The revocation index for the credential.\n * @param opts.addressIndex The address index to use for key derivation (if applicable).\n * @param opts.connector The connector to perform the operations with.\n * @param opts.node The node URL.\n */\nexport async function actionCommandVerifiableCredentialCreate(\n\topts: {\n\t\tid: string;\n\t\tprivateKey: string;\n\t\tcredentialId?: string;\n\t\tsubjectJson: string;\n\t\trevocationIndex?: string;\n\t\taddressIndex?: string;\n\t\tconnector?: IdentityConnectorTypes;\n\t\tnode: string;\n\t\tnetwork?: string;\n\t} & CliOutputOptions\n): Promise<void> {\n\tconst id: string = CLIParam.stringValue(\"id\", opts.id);\n\tconst privateKey: Uint8Array = CLIParam.hexBase64(\"private-key\", opts.privateKey);\n\tconst credentialId: string = CLIParam.stringValue(\"credential-id\", opts.credentialId);\n\tconst subjectJson: string = path.resolve(CLIParam.stringValue(\"subject-json\", opts.subjectJson));\n\tconst revocationIndex: number | undefined = Coerce.number(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(\n\t\tI18n.formatMessage(\"commands.verifiable-credential-create.labels.verificationMethodId\"),\n\t\tid\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verifiable-credential-create.labels.credentialId\"),\n\t\tcredentialId\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verifiable-credential-create.labels.subjectJson\"),\n\t\tsubjectJson\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verifiable-credential-create.labels.revocationIndex\"),\n\t\trevocationIndex\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verifiable-credential-create.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 localIdentity = \"local\";\n\n\tconst vmParts = DocumentHelper.parseId(id);\n\n\tconst vaultConnector = VaultConnectorFactory.get(\"vault\");\n\tawait vaultConnector.addKey(\n\t\t`${localIdentity}/${vmParts.fragment}`,\n\t\tVaultKeyType.Ed25519,\n\t\tprivateKey,\n\t\tnew Uint8Array()\n\t);\n\n\tconst walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);\n\tWalletConnectorFactory.register(\"wallet\", () => walletConnector);\n\n\tconst identityConnector = setupIdentityConnector(\n\t\t{ nodeEndpoint, network, addressIndex },\n\t\topts.connector\n\t);\n\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\"commands.verifiable-credential-create.progress.loadingSubjectData\")\n\t);\n\tCLIDisplay.break();\n\n\tconst jsonData = await CLIUtils.readJsonFile<IJsonLdNodeObject>(subjectJson);\n\tif (Is.undefined(jsonData)) {\n\t\tthrow new GeneralError(\n\t\t\t\"commands\",\n\t\t\t\"commands.verifiable-credential-create.subjectJsonFileNotFound\"\n\t\t);\n\t}\n\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\n\t\t\t\"commands.verifiable-credential-create.progress.creatingVerifiableCredential\"\n\t\t)\n\t);\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tconst verifiableCredential = await identityConnector.createVerifiableCredential(\n\t\tlocalIdentity,\n\t\tid,\n\t\tcredentialId,\n\t\tjsonData,\n\t\t{\n\t\t\trevocationIndex\n\t\t}\n\t);\n\n\tCLIDisplay.spinnerStop();\n\n\tif (opts.console) {\n\t\tCLIDisplay.section(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.labels.verifiableCredential\")\n\t\t);\n\n\t\tCLIDisplay.write(verifiableCredential.jwt);\n\t\tCLIDisplay.break();\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{ verifiableCredentialJwt: verifiableCredential.jwt },\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[`DID_VERIFIABLE_CREDENTIAL_JWT=\"${verifiableCredential.jwt}\"`],\n\t\t\topts.mergeEnv\n\t\t);\n\t}\n\n\tCLIDisplay.done();\n}\n"]}
|
|
@@ -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 revoke command for the CLI.
|
|
13
|
+
* @returns The command.
|
|
14
|
+
*/
|
|
15
|
+
export function buildCommandVerifiableCredentialRevoke() {
|
|
16
|
+
const command = new Command();
|
|
17
|
+
command
|
|
18
|
+
.name("verifiable-credential-revoke")
|
|
19
|
+
.summary(I18n.formatMessage("commands.verifiable-credential-revoke.summary"))
|
|
20
|
+
.description(I18n.formatMessage("commands.verifiable-credential-revoke.description"))
|
|
21
|
+
.requiredOption(I18n.formatMessage("commands.verifiable-credential-revoke.options.seed.param"), I18n.formatMessage("commands.verifiable-credential-revoke.options.seed.description"))
|
|
22
|
+
.requiredOption(I18n.formatMessage("commands.verifiable-credential-revoke.options.did.param"), I18n.formatMessage("commands.verifiable-credential-revoke.options.did.description"))
|
|
23
|
+
.requiredOption(I18n.formatMessage("commands.verifiable-credential-revoke.options.revocation-index.param"), I18n.formatMessage("commands.verifiable-credential-revoke.options.revocation-index.description"))
|
|
24
|
+
.option(I18n.formatMessage("commands.verifiable-credential-revoke.options.addressIndex.param"), I18n.formatMessage("commands.verifiable-credential-revoke.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(actionCommandVerifiableCredentialRevoke);
|
|
32
|
+
return command;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Action the verifiable credential revoke 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 revoke 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 actionCommandVerifiableCredentialRevoke(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-revoke.labels.revocationIndex"), revocationIndex);
|
|
56
|
+
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-revoke.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-revoke.progress.revokingCredential"));
|
|
71
|
+
CLIDisplay.break();
|
|
72
|
+
CLIDisplay.spinnerStart();
|
|
73
|
+
await identityConnector.revokeVerifiableCredentials(localIdentity, did, [revocationIndex]);
|
|
74
|
+
CLIDisplay.spinnerStop();
|
|
75
|
+
CLIDisplay.done();
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=verifiableCredentialRevoke.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verifiableCredentialRevoke.js","sourceRoot":"","sources":["../../../src/commands/verifiableCredentialRevoke.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;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,OAAO,EAA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right 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\";\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 revoke command for the CLI.\n * @returns The command.\n */\nexport function buildCommandVerifiableCredentialRevoke(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"verifiable-credential-revoke\")\n\t\t.summary(I18n.formatMessage(\"commands.verifiable-credential-revoke.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.verifiable-credential-revoke.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-revoke.options.seed.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-revoke.options.seed.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-revoke.options.did.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-revoke.options.did.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-revoke.options.revocation-index.param\"),\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"commands.verifiable-credential-revoke.options.revocation-index.description\"\n\t\t\t)\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-revoke.options.addressIndex.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-revoke.options.addressIndex.description\"),\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(actionCommandVerifiableCredentialRevoke);\n\n\treturn command;\n}\n\n/**\n * Action the verifiable credential revoke 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 revoke 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 actionCommandVerifiableCredentialRevoke(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-revoke.labels.revocationIndex\"),\n\t\trevocationIndex\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verifiable-credential-revoke.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-revoke.progress.revokingCredential\")\n\t);\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tawait identityConnector.revokeVerifiableCredentials(localIdentity, did, [revocationIndex]);\n\n\tCLIDisplay.spinnerStop();\n\n\tCLIDisplay.done();\n}\n"]}
|