@twin.org/identity-cli 0.0.3-next.9 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/es/cli.js +10 -1
- package/dist/es/cli.js.map +1 -1
- package/dist/es/commands/alsoKnownAsAdd.js +108 -0
- package/dist/es/commands/alsoKnownAsAdd.js.map +1 -0
- package/dist/es/commands/alsoKnownAsRemove.js +106 -0
- package/dist/es/commands/alsoKnownAsRemove.js.map +1 -0
- package/dist/es/commands/serviceAdd.js +4 -3
- package/dist/es/commands/serviceAdd.js.map +1 -1
- package/dist/es/commands/serviceRemove.js +3 -3
- package/dist/es/commands/serviceRemove.js.map +1 -1
- package/dist/es/commands/setupCommands.js +4 -6
- package/dist/es/commands/setupCommands.js.map +1 -1
- package/dist/es/commands/verifiableCredentialCreate.js +11 -8
- package/dist/es/commands/verifiableCredentialCreate.js.map +1 -1
- package/dist/es/commands/verifiableCredentialVerify.js +24 -5
- package/dist/es/commands/verifiableCredentialVerify.js.map +1 -1
- package/dist/es/commands/verifiablePresentationCreate.js +137 -0
- package/dist/es/commands/verifiablePresentationCreate.js.map +1 -0
- package/dist/es/commands/verifiablePresentationVerify.js +107 -0
- package/dist/es/commands/verifiablePresentationVerify.js.map +1 -0
- package/dist/es/commands/verificationMethodAdd.js +8 -8
- package/dist/es/commands/verificationMethodAdd.js.map +1 -1
- package/dist/es/index.js +2 -0
- package/dist/es/index.js.map +1 -1
- package/dist/locales/en.json +251 -39
- package/dist/types/commands/alsoKnownAsAdd.d.ts +30 -0
- package/dist/types/commands/alsoKnownAsRemove.d.ts +30 -0
- package/dist/types/commands/setupCommands.d.ts +2 -2
- package/dist/types/commands/verifiableCredentialCreate.d.ts +2 -2
- package/dist/types/commands/verifiableCredentialVerify.d.ts +3 -1
- package/dist/types/commands/verifiablePresentationCreate.d.ts +32 -0
- package/dist/types/commands/verifiablePresentationVerify.d.ts +24 -0
- package/dist/types/index.d.ts +2 -0
- package/docs/changelog.md +669 -117
- package/docs/reference/classes/CLI.md +1 -1
- package/docs/reference/functions/actionCommandVerifiablePresentationCreate.md +17 -0
- package/docs/reference/functions/actionCommandVerifiablePresentationVerify.md +17 -0
- package/docs/reference/functions/buildCommandVerifiablePresentationCreate.md +11 -0
- package/docs/reference/functions/buildCommandVerifiablePresentationVerify.md +11 -0
- package/docs/reference/index.md +4 -0
- package/docs/reference/variables/IdentityConnectorTypes.md +1 -1
- package/docs/reference/variables/IdentityResolverConnectorTypes.md +1 -1
- package/docs/{examples.md → usage.md} +23 -27
- package/locales/en.json +142 -2
- package/package.json +22 -22
package/README.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
# TWIN Identity
|
|
1
|
+
# TWIN Identity
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The identity-cli package provides a command line interface for running identity operations from local development shells and automation pipelines. It helps teams execute common workflows quickly while staying aligned with the same contracts and connectors used in service and integration code.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```shell
|
|
8
|
-
npm install @twin.org/identity-cli
|
|
8
|
+
npm install -D @twin.org/identity-cli
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Usage
|
|
12
12
|
|
|
13
|
-
Usage of the tool is shown in the examples [docs/
|
|
13
|
+
Usage of the tool is shown in the examples [docs/usage.md](docs/usage.md)
|
|
14
14
|
|
|
15
15
|
## Reference
|
|
16
16
|
|
package/dist/es/cli.js
CHANGED
|
@@ -5,6 +5,8 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
import { CLIBase } from "@twin.org/cli-core";
|
|
6
6
|
import { buildCommandAddress, buildCommandMnemonic } from "@twin.org/crypto-cli";
|
|
7
7
|
import { buildCommandFaucet, buildCommandTransfer } from "@twin.org/wallet-cli";
|
|
8
|
+
import { buildCommandAlsoKnownAsAdd } from "./commands/alsoKnownAsAdd.js";
|
|
9
|
+
import { buildCommandAlsoKnownAsRemove } from "./commands/alsoKnownAsRemove.js";
|
|
8
10
|
import { buildCommandIdentityCreate } from "./commands/identityCreate.js";
|
|
9
11
|
import { buildCommandIdentityResolve } from "./commands/identityResolve.js";
|
|
10
12
|
import { buildCommandProofCreate } from "./commands/proofCreate.js";
|
|
@@ -15,6 +17,8 @@ import { buildCommandVerifiableCredentialCreate } from "./commands/verifiableCre
|
|
|
15
17
|
import { buildCommandVerifiableCredentialRevoke } from "./commands/verifiableCredentialRevoke.js";
|
|
16
18
|
import { buildCommandVerifiableCredentialUnrevoke } from "./commands/verifiableCredentialUnrevoke.js";
|
|
17
19
|
import { buildCommandVerifiableCredentialVerify } from "./commands/verifiableCredentialVerify.js";
|
|
20
|
+
import { buildCommandVerifiablePresentationCreate } from "./commands/verifiablePresentationCreate.js";
|
|
21
|
+
import { buildCommandVerifiablePresentationVerify } from "./commands/verifiablePresentationVerify.js";
|
|
18
22
|
import { buildCommandVerificationMethodAdd } from "./commands/verificationMethodAdd.js";
|
|
19
23
|
import { buildCommandVerificationMethodRemove } from "./commands/verificationMethodRemove.js";
|
|
20
24
|
/**
|
|
@@ -33,7 +37,7 @@ export class CLI extends CLIBase {
|
|
|
33
37
|
return this.execute({
|
|
34
38
|
title: "TWIN Identity",
|
|
35
39
|
appName: "twin-identity",
|
|
36
|
-
version: "0.0
|
|
40
|
+
version: "0.9.0", // x-release-please-version
|
|
37
41
|
icon: "🌍",
|
|
38
42
|
supportsEnvFiles: true,
|
|
39
43
|
overrideOutputWidth: options?.overrideOutputWidth,
|
|
@@ -43,6 +47,7 @@ export class CLI extends CLIBase {
|
|
|
43
47
|
/**
|
|
44
48
|
* Get the commands for the CLI.
|
|
45
49
|
* @param program The main program to add the commands to.
|
|
50
|
+
* @returns The list of commands.
|
|
46
51
|
* @internal
|
|
47
52
|
*/
|
|
48
53
|
getCommands(program) {
|
|
@@ -57,7 +62,11 @@ export class CLI extends CLIBase {
|
|
|
57
62
|
buildCommandVerificationMethodRemove(),
|
|
58
63
|
buildCommandServiceAdd(),
|
|
59
64
|
buildCommandServiceRemove(),
|
|
65
|
+
buildCommandAlsoKnownAsAdd(),
|
|
66
|
+
buildCommandAlsoKnownAsRemove(),
|
|
60
67
|
buildCommandVerifiableCredentialCreate(),
|
|
68
|
+
buildCommandVerifiablePresentationCreate(),
|
|
69
|
+
buildCommandVerifiablePresentationVerify(),
|
|
61
70
|
buildCommandVerifiableCredentialVerify(),
|
|
62
71
|
buildCommandVerifiableCredentialRevoke(),
|
|
63
72
|
buildCommandVerifiableCredentialUnrevoke(),
|
package/dist/es/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEhF,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,sCAAsC,EAAE,MAAM,0CAA0C,CAAC;AAClG,OAAO,EAAE,sCAAsC,EAAE,MAAM,0CAA0C,CAAC;AAClG,OAAO,EAAE,wCAAwC,EAAE,MAAM,4C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C5B,6BAA6B,EAAE;YAC/B,sCAAsC,EAAE;YACxC,wCAAwC,EAAE;YAC1C,wCAAwC,EAAE;YAC1C,sCAAsC,EAAE;YACxC,sCAAsC,EAAE;YACxC,wCAAwC,EAAE;YAC1C,uBAAuB,EAAE;YACzB,uBAAuB,EAAE;SACzB,CAAC;IACH,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { CLIBase } from \"@twin.org/cli-core\";\nimport { buildCommandAddress, buildCommandMnemonic } from \"@twin.org/crypto-cli\";\nimport { buildCommandFaucet, buildCommandTransfer } from \"@twin.org/wallet-cli\";\nimport type { Command } from \"commander\";\nimport { buildCommandAlsoKnownAsAdd } from \"./commands/alsoKnownAsAdd.js\";\nimport { buildCommandAlsoKnownAsRemove } from \"./commands/alsoKnownAsRemove.js\";\nimport { buildCommandIdentityCreate } from \"./commands/identityCreate.js\";\nimport { buildCommandIdentityResolve } from \"./commands/identityResolve.js\";\nimport { buildCommandProofCreate } from \"./commands/proofCreate.js\";\nimport { buildCommandProofVerify } from \"./commands/proofVerify.js\";\nimport { buildCommandServiceAdd } from \"./commands/serviceAdd.js\";\nimport { buildCommandServiceRemove } from \"./commands/serviceRemove.js\";\nimport { buildCommandVerifiableCredentialCreate } from \"./commands/verifiableCredentialCreate.js\";\nimport { buildCommandVerifiableCredentialRevoke } from \"./commands/verifiableCredentialRevoke.js\";\nimport { buildCommandVerifiableCredentialUnrevoke } from \"./commands/verifiableCredentialUnrevoke.js\";\nimport { buildCommandVerifiableCredentialVerify } from \"./commands/verifiableCredentialVerify.js\";\nimport { buildCommandVerifiablePresentationCreate } from \"./commands/verifiablePresentationCreate.js\";\nimport { buildCommandVerifiablePresentationVerify } from \"./commands/verifiablePresentationVerify.js\";\nimport { buildCommandVerificationMethodAdd } from \"./commands/verificationMethodAdd.js\";\nimport { buildCommandVerificationMethodRemove } from \"./commands/verificationMethodRemove.js\";\n\n/**\n * The main entry point for the CLI.\n */\nexport class CLI extends CLIBase {\n\t/**\n\t * Run the app.\n\t * @param argv The process arguments.\n\t * @param localesDirectory The directory for the locales, default to relative to the script.\n\t * @param options Additional options for the CLI.\n\t * @param options.overrideOutputWidth The override output width.\n\t * @returns The exit code.\n\t */\n\tpublic async run(\n\t\targv: string[],\n\t\tlocalesDirectory?: string,\n\t\toptions?: { overrideOutputWidth?: number }\n\t): Promise<number> {\n\t\treturn this.execute(\n\t\t\t{\n\t\t\t\ttitle: \"TWIN Identity\",\n\t\t\t\tappName: \"twin-identity\",\n\t\t\t\tversion: \"0.9.0\", // x-release-please-version\n\t\t\t\ticon: \"🌍\",\n\t\t\t\tsupportsEnvFiles: true,\n\t\t\t\toverrideOutputWidth: options?.overrideOutputWidth,\n\t\t\t\tshowDevToolWarning: true\n\t\t\t},\n\t\t\tlocalesDirectory ?? path.join(path.dirname(fileURLToPath(import.meta.url)), \"../locales\"),\n\t\t\targv\n\t\t);\n\t}\n\n\t/**\n\t * Get the commands for the CLI.\n\t * @param program The main program to add the commands to.\n\t * @returns The list of commands.\n\t * @internal\n\t */\n\tprotected getCommands(program: Command): Command[] {\n\t\treturn [\n\t\t\tbuildCommandMnemonic(),\n\t\t\tbuildCommandAddress(),\n\t\t\tbuildCommandFaucet(),\n\t\t\tbuildCommandTransfer(),\n\t\t\tbuildCommandIdentityCreate(),\n\t\t\tbuildCommandIdentityResolve(),\n\t\t\tbuildCommandVerificationMethodAdd(),\n\t\t\tbuildCommandVerificationMethodRemove(),\n\t\t\tbuildCommandServiceAdd(),\n\t\t\tbuildCommandServiceRemove(),\n\t\t\tbuildCommandAlsoKnownAsAdd(),\n\t\t\tbuildCommandAlsoKnownAsRemove(),\n\t\t\tbuildCommandVerifiableCredentialCreate(),\n\t\t\tbuildCommandVerifiablePresentationCreate(),\n\t\t\tbuildCommandVerifiablePresentationVerify(),\n\t\t\tbuildCommandVerifiableCredentialVerify(),\n\t\t\tbuildCommandVerifiableCredentialRevoke(),\n\t\t\tbuildCommandVerifiableCredentialUnrevoke(),\n\t\t\tbuildCommandProofCreate(),\n\t\t\tbuildCommandProofVerify()\n\t\t];\n\t}\n}\n"]}
|
|
@@ -0,0 +1,108 @@
|
|
|
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 { ArrayHelper, 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, setupIdentityResolverConnector, setupVault } from "./setupCommands.js";
|
|
11
|
+
import { IdentityConnectorTypes } from "../models/identityConnectorTypes.js";
|
|
12
|
+
/**
|
|
13
|
+
* Build the alsoKnownAs add command for the CLI.
|
|
14
|
+
* @returns The command.
|
|
15
|
+
*/
|
|
16
|
+
export function buildCommandAlsoKnownAsAdd() {
|
|
17
|
+
const command = new Command();
|
|
18
|
+
command
|
|
19
|
+
.name("also-known-as-add")
|
|
20
|
+
.summary(I18n.formatMessage("commands.also-known-as-add.summary"))
|
|
21
|
+
.description(I18n.formatMessage("commands.also-known-as-add.description"))
|
|
22
|
+
.requiredOption(I18n.formatMessage("commands.also-known-as-add.options.seed.param"), I18n.formatMessage("commands.also-known-as-add.options.seed.description"))
|
|
23
|
+
.requiredOption(I18n.formatMessage("commands.also-known-as-add.options.did.param"), I18n.formatMessage("commands.also-known-as-add.options.did.description"))
|
|
24
|
+
.requiredOption(I18n.formatMessage("commands.also-known-as-add.options.alias.param"), I18n.formatMessage("commands.also-known-as-add.options.alias.description"))
|
|
25
|
+
.option(I18n.formatMessage("commands.also-known-as-add.options.addressIndex.param"), I18n.formatMessage("commands.also-known-as-add.options.addressIndex.description"), "0");
|
|
26
|
+
CLIOptions.output(command, {
|
|
27
|
+
noConsole: true,
|
|
28
|
+
json: true,
|
|
29
|
+
env: true,
|
|
30
|
+
mergeJson: true,
|
|
31
|
+
mergeEnv: true
|
|
32
|
+
});
|
|
33
|
+
command
|
|
34
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
35
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
36
|
+
.default(IdentityConnectorTypes.Iota))
|
|
37
|
+
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
38
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
39
|
+
.option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
40
|
+
.action(actionCommandAlsoKnownAsAdd);
|
|
41
|
+
return command;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Action the alsoKnownAs add command.
|
|
45
|
+
* @param opts The options for the command.
|
|
46
|
+
* @param opts.seed The private key for the controller.
|
|
47
|
+
* @param opts.did The identity of the document to add to.
|
|
48
|
+
* @param opts.alias The alsoKnownAs value to add.
|
|
49
|
+
* @param opts.addressIndex The address index to use for key derivation (if applicable).
|
|
50
|
+
* @param opts.connector The connector to perform the operations with.
|
|
51
|
+
* @param opts.node The node URL.
|
|
52
|
+
* @param opts.network The network to use for connector.
|
|
53
|
+
* @param opts.explorer The explorer URL.
|
|
54
|
+
*/
|
|
55
|
+
export async function actionCommandAlsoKnownAsAdd(opts) {
|
|
56
|
+
const seed = CLIParam.hexBase64("seed", opts.seed);
|
|
57
|
+
const did = CLIParam.stringValue("did", opts.did);
|
|
58
|
+
const alias = CLIParam.stringValue("alias", opts.alias);
|
|
59
|
+
const addressIndex = CLIParam.integer("addressIndex", opts.addressIndex ?? "0", false, 0);
|
|
60
|
+
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
61
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
62
|
+
? CLIParam.stringValue("network", opts.network)
|
|
63
|
+
: undefined;
|
|
64
|
+
const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
|
|
65
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.did"), did);
|
|
66
|
+
CLIDisplay.value(I18n.formatMessage("commands.also-known-as-add.labels.alias"), alias);
|
|
67
|
+
CLIDisplay.value(I18n.formatMessage("commands.also-known-as-add.labels.addressIndex"), addressIndex);
|
|
68
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
69
|
+
if (Is.stringValue(network)) {
|
|
70
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
71
|
+
}
|
|
72
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
|
|
73
|
+
CLIDisplay.break();
|
|
74
|
+
setupVault();
|
|
75
|
+
const vaultSeedId = "local-seed";
|
|
76
|
+
const vmParts = DocumentHelper.parseId(did);
|
|
77
|
+
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
78
|
+
await vaultConnector.setSecret(`${vmParts.id}/${vaultSeedId}`, Converter.bytesToBase64(seed));
|
|
79
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
|
|
80
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
81
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network, addressIndex, vaultSeedId }, opts.connector);
|
|
82
|
+
CLIDisplay.task(I18n.formatMessage("commands.also-known-as-add.progress.addingAlsoKnownAs"));
|
|
83
|
+
CLIDisplay.break();
|
|
84
|
+
CLIDisplay.spinnerStart();
|
|
85
|
+
await identityConnector.addAlsoKnownAs(vmParts.id, did, alias);
|
|
86
|
+
const identityResolverConnector = setupIdentityResolverConnector({ nodeEndpoint, network }, opts.connector);
|
|
87
|
+
// Retrieve the updated DID document to get the full alsoKnownAs array
|
|
88
|
+
const didDocument = await identityResolverConnector.resolveDocument(did);
|
|
89
|
+
const alsoKnownAs = ArrayHelper.fromObjectOrArray(didDocument.alsoKnownAs) ?? [];
|
|
90
|
+
CLIDisplay.spinnerStop();
|
|
91
|
+
if (Is.stringValue(opts?.json)) {
|
|
92
|
+
await CLIUtils.writeJsonFile(opts.json, {
|
|
93
|
+
alsoKnownAs
|
|
94
|
+
}, opts.mergeJson);
|
|
95
|
+
}
|
|
96
|
+
if (Is.stringValue(opts?.env)) {
|
|
97
|
+
await CLIUtils.writeEnvFile(opts.env, [`DID_ALSO_KNOWN_AS="${alsoKnownAs.join(",")}"`], opts.mergeEnv);
|
|
98
|
+
}
|
|
99
|
+
if (opts.connector === IdentityConnectorTypes.Iota) {
|
|
100
|
+
const didUrn = Urn.fromValidString(did);
|
|
101
|
+
const didParts = didUrn.parts();
|
|
102
|
+
const objectId = didParts[didParts.length - 1];
|
|
103
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`);
|
|
104
|
+
}
|
|
105
|
+
CLIDisplay.break();
|
|
106
|
+
CLIDisplay.done();
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=alsoKnownAsAdd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alsoKnownAsAdd.js","sourceRoot":"","sources":["../../../src/commands/alsoKnownAsAdd.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,UAAU,EACV,UAAU,EACV,QAAQ,EACR,QAAQ,EAER,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,SAAS,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EACD,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,sBAAsB,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAChD,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 { ArrayHelper, 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 {\n\tsetupIdentityConnector,\n\tsetupIdentityResolverConnector,\n\tsetupVault\n} from \"./setupCommands.js\";\nimport { IdentityConnectorTypes } from \"../models/identityConnectorTypes.js\";\n\n/**\n * Build the alsoKnownAs add command for the CLI.\n * @returns The command.\n */\nexport function buildCommandAlsoKnownAsAdd(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"also-known-as-add\")\n\t\t.summary(I18n.formatMessage(\"commands.also-known-as-add.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.also-known-as-add.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.also-known-as-add.options.seed.param\"),\n\t\t\tI18n.formatMessage(\"commands.also-known-as-add.options.seed.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.also-known-as-add.options.did.param\"),\n\t\t\tI18n.formatMessage(\"commands.also-known-as-add.options.did.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.also-known-as-add.options.alias.param\"),\n\t\t\tI18n.formatMessage(\"commands.also-known-as-add.options.alias.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.also-known-as-add.options.addressIndex.param\"),\n\t\t\tI18n.formatMessage(\"commands.also-known-as-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(actionCommandAlsoKnownAsAdd);\n\n\treturn command;\n}\n\n/**\n * Action the alsoKnownAs 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.alias The alsoKnownAs value to add.\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.network The network to use for connector.\n * @param opts.explorer The explorer URL.\n */\nexport async function actionCommandAlsoKnownAsAdd(\n\topts: {\n\t\tseed: string;\n\t\tdid: string;\n\t\talias: 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 alias: string = CLIParam.stringValue(\"alias\", opts.alias);\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.also-known-as-add.labels.alias\"), alias);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.also-known-as-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 vmParts = DocumentHelper.parseId(did);\n\n\tconst vaultConnector = VaultConnectorFactory.get(\"vault\");\n\tawait vaultConnector.setSecret(`${vmParts.id}/${vaultSeedId}`, Converter.bytesToBase64(seed));\n\n\tconst walletConnector = setupWalletConnector(\n\t\t{ nodeEndpoint, vaultSeedId, network },\n\t\topts.connector\n\t);\n\tWalletConnectorFactory.register(\"wallet\", () => walletConnector);\n\n\tconst identityConnector = setupIdentityConnector(\n\t\t{ nodeEndpoint, network, addressIndex, vaultSeedId },\n\t\topts.connector\n\t);\n\n\tCLIDisplay.task(I18n.formatMessage(\"commands.also-known-as-add.progress.addingAlsoKnownAs\"));\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tawait identityConnector.addAlsoKnownAs(vmParts.id, did, alias);\n\n\tconst identityResolverConnector = setupIdentityResolverConnector(\n\t\t{ nodeEndpoint, network },\n\t\topts.connector\n\t);\n\n\t// Retrieve the updated DID document to get the full alsoKnownAs array\n\tconst didDocument = await identityResolverConnector.resolveDocument(did);\n\tconst alsoKnownAs = ArrayHelper.fromObjectOrArray(didDocument.alsoKnownAs) ?? [];\n\n\tCLIDisplay.spinnerStop();\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\talsoKnownAs\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[`DID_ALSO_KNOWN_AS=\"${alsoKnownAs.join(\",\")}\"`],\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,106 @@
|
|
|
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 { ArrayHelper, 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, setupIdentityResolverConnector, setupVault } from "./setupCommands.js";
|
|
11
|
+
import { IdentityConnectorTypes } from "../models/identityConnectorTypes.js";
|
|
12
|
+
/**
|
|
13
|
+
* Build the alsoKnownAs remove command for the CLI.
|
|
14
|
+
* @returns The command.
|
|
15
|
+
*/
|
|
16
|
+
export function buildCommandAlsoKnownAsRemove() {
|
|
17
|
+
const command = new Command();
|
|
18
|
+
command
|
|
19
|
+
.name("also-known-as-remove")
|
|
20
|
+
.summary(I18n.formatMessage("commands.also-known-as-remove.summary"))
|
|
21
|
+
.description(I18n.formatMessage("commands.also-known-as-remove.description"))
|
|
22
|
+
.requiredOption(I18n.formatMessage("commands.also-known-as-remove.options.seed.param"), I18n.formatMessage("commands.also-known-as-remove.options.seed.description"))
|
|
23
|
+
.requiredOption(I18n.formatMessage("commands.also-known-as-remove.options.did.param"), I18n.formatMessage("commands.also-known-as-remove.options.did.description"))
|
|
24
|
+
.requiredOption(I18n.formatMessage("commands.also-known-as-remove.options.alias.param"), I18n.formatMessage("commands.also-known-as-remove.options.alias.description"))
|
|
25
|
+
.option(I18n.formatMessage("commands.also-known-as-remove.options.addressIndex.param"), I18n.formatMessage("commands.also-known-as-remove.options.addressIndex.description"), "0");
|
|
26
|
+
CLIOptions.output(command, {
|
|
27
|
+
noConsole: true,
|
|
28
|
+
json: true,
|
|
29
|
+
env: true,
|
|
30
|
+
mergeJson: true,
|
|
31
|
+
mergeEnv: true
|
|
32
|
+
});
|
|
33
|
+
command
|
|
34
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
35
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
36
|
+
.default(IdentityConnectorTypes.Iota))
|
|
37
|
+
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
38
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
39
|
+
.option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
40
|
+
.action(actionCommandAlsoKnownAsRemove);
|
|
41
|
+
return command;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Action the alsoKnownAs remove command.
|
|
45
|
+
* @param opts The options for the command.
|
|
46
|
+
* @param opts.seed The private key for the controller.
|
|
47
|
+
* @param opts.did The identity of the document to remove from.
|
|
48
|
+
* @param opts.alias The alsoKnownAs value to remove.
|
|
49
|
+
* @param opts.addressIndex The address index to use for key derivation (if applicable).
|
|
50
|
+
* @param opts.connector The connector to perform the operations with.
|
|
51
|
+
* @param opts.node The node URL.
|
|
52
|
+
* @param opts.network The network to use for connector.
|
|
53
|
+
* @param opts.explorer The explorer URL.
|
|
54
|
+
*/
|
|
55
|
+
export async function actionCommandAlsoKnownAsRemove(opts) {
|
|
56
|
+
const seed = CLIParam.hexBase64("seed", opts.seed);
|
|
57
|
+
const did = CLIParam.stringValue("did", opts.did);
|
|
58
|
+
const alias = CLIParam.stringValue("alias", opts.alias);
|
|
59
|
+
const addressIndex = CLIParam.integer("addressIndex", opts.addressIndex ?? "0", false, 0);
|
|
60
|
+
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
61
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
62
|
+
? CLIParam.stringValue("network", opts.network)
|
|
63
|
+
: undefined;
|
|
64
|
+
const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
|
|
65
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.did"), did);
|
|
66
|
+
CLIDisplay.value(I18n.formatMessage("commands.also-known-as-remove.labels.alias"), alias);
|
|
67
|
+
CLIDisplay.value(I18n.formatMessage("commands.also-known-as-remove.labels.addressIndex"), addressIndex);
|
|
68
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
69
|
+
if (Is.stringValue(network)) {
|
|
70
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
71
|
+
}
|
|
72
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
|
|
73
|
+
CLIDisplay.break();
|
|
74
|
+
setupVault();
|
|
75
|
+
const vaultSeedId = "local-seed";
|
|
76
|
+
const vmParts = DocumentHelper.parseId(did);
|
|
77
|
+
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
78
|
+
await vaultConnector.setSecret(`${vmParts.id}/${vaultSeedId}`, Converter.bytesToBase64(seed));
|
|
79
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
|
|
80
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
81
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network, addressIndex, vaultSeedId }, opts.connector);
|
|
82
|
+
CLIDisplay.task(I18n.formatMessage("commands.also-known-as-remove.progress.removingAlsoKnownAs"));
|
|
83
|
+
CLIDisplay.break();
|
|
84
|
+
CLIDisplay.spinnerStart();
|
|
85
|
+
await identityConnector.removeAlsoKnownAs(vmParts.id, did, alias);
|
|
86
|
+
const identityResolverConnector = setupIdentityResolverConnector({ nodeEndpoint, network }, opts.connector);
|
|
87
|
+
// Retrieve the updated DID document to get the full alsoKnownAs array
|
|
88
|
+
const didDocument = await identityResolverConnector.resolveDocument(did);
|
|
89
|
+
const alsoKnownAs = ArrayHelper.fromObjectOrArray(didDocument.alsoKnownAs) ?? [];
|
|
90
|
+
CLIDisplay.spinnerStop();
|
|
91
|
+
if (Is.stringValue(opts?.json)) {
|
|
92
|
+
await CLIUtils.writeJsonFile(opts.json, { alsoKnownAs }, opts.mergeJson);
|
|
93
|
+
}
|
|
94
|
+
if (Is.stringValue(opts?.env)) {
|
|
95
|
+
await CLIUtils.writeEnvFile(opts.env, [`DID_ALSO_KNOWN_AS="${alsoKnownAs.join(",")}"`], opts.mergeEnv);
|
|
96
|
+
}
|
|
97
|
+
if (opts.connector === IdentityConnectorTypes.Iota) {
|
|
98
|
+
const didUrn = Urn.fromValidString(did);
|
|
99
|
+
const didParts = didUrn.parts();
|
|
100
|
+
const objectId = didParts[didParts.length - 1];
|
|
101
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`);
|
|
102
|
+
}
|
|
103
|
+
CLIDisplay.break();
|
|
104
|
+
CLIDisplay.done();
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=alsoKnownAsRemove.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alsoKnownAsRemove.js","sourceRoot":"","sources":["../../../src/commands/alsoKnownAsRemove.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,UAAU,EACV,UAAU,EACV,QAAQ,EACR,QAAQ,EAER,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrF,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,EACN,sBAAsB,EACtB,8BAA8B,EAC9B,UAAU,EACV,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAE7E;;;GAGG;AACH,MAAM,UAAU,6BAA6B;IAC5C,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAC9B,OAAO;SACL,IAAI,CAAC,sBAAsB,CAAC;SAC5B,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,uCAAuC,CAAC,CAAC;SACpE,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,2CAA2C,CAAC,CAAC;SAC5E,cAAc,CACd,IAAI,CAAC,aAAa,CAAC,kDAAkD,CAAC,EACtE,IAAI,CAAC,aAAa,CAAC,wDAAwD,CAAC,CAC5E;SACA,cAAc,CACd,IAAI,CAAC,aAAa,CAAC,iDAAiD,CAAC,EACrE,IAAI,CAAC,aAAa,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n\tCLIParam,\n\tCLIUtils,\n\ttype CliOutputOptions\n} from \"@twin.org/cli-core\";\nimport { ArrayHelper, 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 {\n\tsetupIdentityConnector,\n\tsetupIdentityResolverConnector,\n\tsetupVault\n} from \"./setupCommands.js\";\nimport { IdentityConnectorTypes } from \"../models/identityConnectorTypes.js\";\n\n/**\n * Build the alsoKnownAs remove command for the CLI.\n * @returns The command.\n */\nexport function buildCommandAlsoKnownAsRemove(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"also-known-as-remove\")\n\t\t.summary(I18n.formatMessage(\"commands.also-known-as-remove.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.also-known-as-remove.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.also-known-as-remove.options.seed.param\"),\n\t\t\tI18n.formatMessage(\"commands.also-known-as-remove.options.seed.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.also-known-as-remove.options.did.param\"),\n\t\t\tI18n.formatMessage(\"commands.also-known-as-remove.options.did.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.also-known-as-remove.options.alias.param\"),\n\t\t\tI18n.formatMessage(\"commands.also-known-as-remove.options.alias.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.also-known-as-remove.options.addressIndex.param\"),\n\t\t\tI18n.formatMessage(\"commands.also-known-as-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(actionCommandAlsoKnownAsRemove);\n\n\treturn command;\n}\n\n/**\n * Action the alsoKnownAs remove 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 remove from.\n * @param opts.alias The alsoKnownAs value to remove.\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.network The network to use for connector.\n * @param opts.explorer The explorer URL.\n */\nexport async function actionCommandAlsoKnownAsRemove(\n\topts: {\n\t\tseed: string;\n\t\tdid: string;\n\t\talias: 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 alias: string = CLIParam.stringValue(\"alias\", opts.alias);\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.also-known-as-remove.labels.alias\"), alias);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.also-known-as-remove.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 vmParts = DocumentHelper.parseId(did);\n\n\tconst vaultConnector = VaultConnectorFactory.get(\"vault\");\n\tawait vaultConnector.setSecret(`${vmParts.id}/${vaultSeedId}`, Converter.bytesToBase64(seed));\n\n\tconst walletConnector = setupWalletConnector(\n\t\t{ nodeEndpoint, vaultSeedId, network },\n\t\topts.connector\n\t);\n\tWalletConnectorFactory.register(\"wallet\", () => walletConnector);\n\n\tconst identityConnector = setupIdentityConnector(\n\t\t{ nodeEndpoint, network, addressIndex, vaultSeedId },\n\t\topts.connector\n\t);\n\n\tCLIDisplay.task(I18n.formatMessage(\"commands.also-known-as-remove.progress.removingAlsoKnownAs\"));\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tawait identityConnector.removeAlsoKnownAs(vmParts.id, did, alias);\n\n\tconst identityResolverConnector = setupIdentityResolverConnector(\n\t\t{ nodeEndpoint, network },\n\t\topts.connector\n\t);\n\n\t// Retrieve the updated DID document to get the full alsoKnownAs array\n\tconst didDocument = await identityResolverConnector.resolveDocument(did);\n\tconst alsoKnownAs = ArrayHelper.fromObjectOrArray(didDocument.alsoKnownAs) ?? [];\n\n\tCLIDisplay.spinnerStop();\n\n\tif (Is.stringValue(opts?.json)) {\n\t\tawait CLIUtils.writeJsonFile(opts.json, { alsoKnownAs }, opts.mergeJson);\n\t}\n\tif (Is.stringValue(opts?.env)) {\n\t\tawait CLIUtils.writeEnvFile(\n\t\t\topts.env,\n\t\t\t[`DID_ALSO_KNOWN_AS=\"${alsoKnownAs.join(\",\")}\"`],\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"]}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
3
|
import { CLIDisplay, CLIOptions, CLIParam, CLIUtils } from "@twin.org/cli-core";
|
|
4
4
|
import { Converter, I18n, Is, StringHelper, Urn } from "@twin.org/core";
|
|
5
|
+
import { DocumentHelper } from "@twin.org/identity-models";
|
|
5
6
|
import { VaultConnectorFactory } from "@twin.org/vault-models";
|
|
6
7
|
import { setupWalletConnector } from "@twin.org/wallet-cli";
|
|
7
8
|
import { WalletConnectorFactory } from "@twin.org/wallet-models";
|
|
@@ -79,16 +80,16 @@ export async function actionCommandServiceAdd(opts) {
|
|
|
79
80
|
CLIDisplay.break();
|
|
80
81
|
setupVault();
|
|
81
82
|
const vaultSeedId = "local-seed";
|
|
82
|
-
const
|
|
83
|
+
const vmParts = DocumentHelper.parseId(did);
|
|
83
84
|
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
84
|
-
await vaultConnector.setSecret(`${
|
|
85
|
+
await vaultConnector.setSecret(`${vmParts.id}/${vaultSeedId}`, Converter.bytesToBase64(seed));
|
|
85
86
|
const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
|
|
86
87
|
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
87
88
|
const identityConnector = setupIdentityConnector({ nodeEndpoint, network, addressIndex, vaultSeedId }, opts.connector);
|
|
88
89
|
CLIDisplay.task(I18n.formatMessage("commands.service-add.progress.addingService"));
|
|
89
90
|
CLIDisplay.break();
|
|
90
91
|
CLIDisplay.spinnerStart();
|
|
91
|
-
const service = await identityConnector.addService(
|
|
92
|
+
const service = await identityConnector.addService(vmParts.id, did, id, type, endpoint);
|
|
92
93
|
CLIDisplay.spinnerStop();
|
|
93
94
|
if (Is.stringValue(opts?.json)) {
|
|
94
95
|
await CLIUtils.writeJsonFile(opts.json, service, opts.mergeJson);
|
|
@@ -1 +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,EAA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G,CAAC,EAAE,CAAC;QAC/B,MAAM,QAAQ,CAAC,YAAY,CAC1B,IAAI,CAAC,GAAG,EACR;YACC,mBAAmB,OAAO,CAAC,EAAE,GAAG;YAChC,qBAAqB,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG;YACvF,yBAAyB,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,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"]}
|
|
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,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,oBAAoB,E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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 { 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 vmParts = DocumentHelper.parseId(did);\n\n\tconst vaultConnector = VaultConnectorFactory.get(\"vault\");\n\tawait vaultConnector.setSecret(`${vmParts.id}/${vaultSeedId}`, Converter.bytesToBase64(seed));\n\n\tconst walletConnector = setupWalletConnector(\n\t\t{ nodeEndpoint, vaultSeedId, network },\n\t\topts.connector\n\t);\n\tWalletConnectorFactory.register(\"wallet\", () => walletConnector);\n\n\tconst identityConnector = setupIdentityConnector(\n\t\t{ nodeEndpoint, network, addressIndex, vaultSeedId },\n\t\topts.connector\n\t);\n\n\tCLIDisplay.task(I18n.formatMessage(\"commands.service-add.progress.addingService\"));\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tconst service = await identityConnector.addService(vmParts.id, 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"]}
|
|
@@ -69,16 +69,16 @@ export async function actionCommandServiceRemove(opts) {
|
|
|
69
69
|
CLIDisplay.break();
|
|
70
70
|
setupVault();
|
|
71
71
|
const vaultSeedId = "local-seed";
|
|
72
|
-
const
|
|
72
|
+
const vmParts = DocumentHelper.parseId(id);
|
|
73
73
|
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
74
|
-
await vaultConnector.setSecret(`${
|
|
74
|
+
await vaultConnector.setSecret(`${vmParts.id}/${vaultSeedId}`, Converter.bytesToBase64(seed));
|
|
75
75
|
const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
|
|
76
76
|
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
77
77
|
const identityConnector = setupIdentityConnector({ nodeEndpoint, network, addressIndex, vaultSeedId }, opts.connector);
|
|
78
78
|
CLIDisplay.task(I18n.formatMessage("commands.service-remove.progress.removingService"));
|
|
79
79
|
CLIDisplay.break();
|
|
80
80
|
CLIDisplay.spinnerStart();
|
|
81
|
-
await identityConnector.removeService(
|
|
81
|
+
await identityConnector.removeService(vmParts.id, id);
|
|
82
82
|
CLIDisplay.spinnerStop();
|
|
83
83
|
const did = DocumentHelper.parseId(id).id;
|
|
84
84
|
if (opts.connector === IdentityConnectorTypes.Iota) {
|
|
@@ -1 +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,EAA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AC;IAEzD,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;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"]}
|
|
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;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AC,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;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 vmParts = DocumentHelper.parseId(id);\n\n\tconst vaultConnector = VaultConnectorFactory.get(\"vault\");\n\tawait vaultConnector.setSecret(`${vmParts.id}/${vaultSeedId}`, Converter.bytesToBase64(seed));\n\n\tconst walletConnector = setupWalletConnector(\n\t\t{ nodeEndpoint, vaultSeedId, network },\n\t\topts.connector\n\t);\n\tWalletConnectorFactory.register(\"wallet\", () => walletConnector);\n\n\tconst identityConnector = setupIdentityConnector(\n\t\t{ nodeEndpoint, network, addressIndex, vaultSeedId },\n\t\topts.connector\n\t);\n\n\tCLIDisplay.task(I18n.formatMessage(\"commands.service-remove.progress.removingService\"));\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tawait identityConnector.removeService(vmParts.id, 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"]}
|
|
@@ -5,18 +5,18 @@ import { EntityStorageConnectorFactory } from "@twin.org/entity-storage-models";
|
|
|
5
5
|
import { IotaIdentityConnector, IotaIdentityResolverConnector } from "@twin.org/identity-connector-iota";
|
|
6
6
|
import { EntityStorageVaultConnector, initSchema } from "@twin.org/vault-connector-entity-storage";
|
|
7
7
|
import { VaultConnectorFactory } from "@twin.org/vault-models";
|
|
8
|
-
import { IdentityConnectorTypes } from "../models/identityConnectorTypes.js";
|
|
9
|
-
import { IdentityResolverConnectorTypes } from "../models/identityResolverConnectorTypes.js";
|
|
10
8
|
/**
|
|
11
9
|
* Setup the vault for use in the CLI commands.
|
|
12
10
|
*/
|
|
13
11
|
export function setupVault() {
|
|
14
12
|
initSchema();
|
|
15
13
|
EntityStorageConnectorFactory.register("vault-key", () => new MemoryEntityStorageConnector({
|
|
16
|
-
entitySchema: "VaultKey"
|
|
14
|
+
entitySchema: "VaultKey",
|
|
15
|
+
config: { storageKey: "vault-key" }
|
|
17
16
|
}));
|
|
18
17
|
EntityStorageConnectorFactory.register("vault-secret", () => new MemoryEntityStorageConnector({
|
|
19
|
-
entitySchema: "VaultSecret"
|
|
18
|
+
entitySchema: "VaultSecret",
|
|
19
|
+
config: { storageKey: "vault-secret" }
|
|
20
20
|
}));
|
|
21
21
|
const vaultConnector = new EntityStorageVaultConnector();
|
|
22
22
|
VaultConnectorFactory.register("vault", () => vaultConnector);
|
|
@@ -32,7 +32,6 @@ export function setupVault() {
|
|
|
32
32
|
* @returns The identity connector.
|
|
33
33
|
*/
|
|
34
34
|
export function setupIdentityConnector(options, connector) {
|
|
35
|
-
connector ??= IdentityConnectorTypes.Iota;
|
|
36
35
|
return new IotaIdentityConnector({
|
|
37
36
|
config: {
|
|
38
37
|
clientOptions: {
|
|
@@ -53,7 +52,6 @@ export function setupIdentityConnector(options, connector) {
|
|
|
53
52
|
* @returns The identity connector.
|
|
54
53
|
*/
|
|
55
54
|
export function setupIdentityResolverConnector(options, connector) {
|
|
56
|
-
connector ??= IdentityResolverConnectorTypes.Iota;
|
|
57
55
|
return new IotaIdentityResolverConnector({
|
|
58
56
|
config: {
|
|
59
57
|
clientOptions: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupCommands.js","sourceRoot":"","sources":["../../../src/commands/setupCommands.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,4BAA4B,EAAE,MAAM,2CAA2C,CAAC;AACzF,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EACN,qBAAqB,EACrB,6BAA6B,EAC7B,MAAM,mCAAmC,CAAC;AAG3C,OAAO,EACN,2BAA2B,EAG3B,UAAU,EACV,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"setupCommands.js","sourceRoot":"","sources":["../../../src/commands/setupCommands.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,4BAA4B,EAAE,MAAM,2CAA2C,CAAC;AACzF,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EACN,qBAAqB,EACrB,6BAA6B,EA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E,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 type { IdentityConnectorTypes } from \"../models/identityConnectorTypes.js\";\nimport type { 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\tconfig: { storageKey: \"vault-key\" }\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\tconfig: { storageKey: \"vault-secret\" }\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\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\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"]}
|