@twin.org/identity-cli 0.0.3-next.14 → 0.0.3-next.16
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/dist/es/cli.js +1 -1
- package/dist/es/cli.js.map +1 -1
- 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/verificationMethodAdd.js +4 -4
- package/dist/es/commands/verificationMethodAdd.js.map +1 -1
- package/docs/changelog.md +30 -0
- package/package.json +3 -3
package/dist/es/cli.js
CHANGED
|
@@ -33,7 +33,7 @@ export class CLI extends CLIBase {
|
|
|
33
33
|
return this.execute({
|
|
34
34
|
title: "TWIN Identity",
|
|
35
35
|
appName: "twin-identity",
|
|
36
|
-
version: "0.0.3-next.
|
|
36
|
+
version: "0.0.3-next.16", // x-release-please-version
|
|
37
37
|
icon: "🌍",
|
|
38
38
|
supportsEnvFiles: true,
|
|
39
39
|
overrideOutputWidth: options?.overrideOutputWidth,
|
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,E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B,EAAE;YAC7B,iCAAiC,EAAE;YACnC,oCAAoC,EAAE;YACtC,sBAAsB,EAAE;YACxB,yBAAyB,EAAE;YAC3B,sCAAsC,EAAE;YACxC,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 { 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 { 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.0.3-next.
|
|
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,4CAA4C,CAAC;AACtG,OAAO,EAAE,sCAAsC,EAAE,MAAM,0CAA0C,CAAC;AAClG,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AACxF,OAAO,EAAE,oCAAoC,EAAE,MAAM,wCAAwC,CAAC;AAE9F;;GAEG;AACH,MAAM,OAAO,GAAI,SAAQ,OAAO;IAC/B;;;;;;;OAOG;IACI,KAAK,CAAC,GAAG,CACf,IAAc,EACd,gBAAyB,EACzB,OAA0C;QAE1C,OAAO,IAAI,CAAC,OAAO,CAClB;YACC,KAAK,EAAE,eAAe;YACtB,OAAO,EAAE,eAAe;YACxB,OAAO,EAAE,eAAe,EAAE,2BAA2B;YACrD,IAAI,EAAE,IAAI;YACV,gBAAgB,EAAE,IAAI;YACtB,mBAAmB,EAAE,OAAO,EAAE,mBAAmB;YACjD,kBAAkB,EAAE,IAAI;SACxB,EACD,gBAAgB,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,CAAC,EACzF,IAAI,CACJ,CAAC;IACH,CAAC;IAED;;;;OAIG;IACO,WAAW,CAAC,OAAgB;QACrC,OAAO;YACN,oBAAoB,EAAE;YACtB,mBAAmB,EAAE;YACrB,kBAAkB,EAAE;YACpB,oBAAoB,EAAE;YACtB,0BAA0B,EAAE;YAC5B,2BAA2B,EAAE;YAC7B,iCAAiC,EAAE;YACnC,oCAAoC,EAAE;YACtC,sBAAsB,EAAE;YACxB,yBAAyB,EAAE;YAC3B,sCAAsC,EAAE;YACxC,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 { 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 { 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.0.3-next.16\", // 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 * @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\tbuildCommandVerifiableCredentialCreate(),\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"]}
|
|
@@ -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,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,I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C,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,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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,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 { 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,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,CAAC,gBA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AG,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;IACxC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAC9B,OAAO;SACL,IAAI,CAAC,gBAAgB,CAAC;SACtB,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,iCAAiC,CAAC,CAAC;SAC9D,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,qCAAqC,CAA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M,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"]}
|
|
@@ -82,19 +82,19 @@ export async function actionCommandVerificationMethodAdd(opts) {
|
|
|
82
82
|
CLIDisplay.break();
|
|
83
83
|
setupVault();
|
|
84
84
|
const vaultSeedId = "local-seed";
|
|
85
|
-
const
|
|
85
|
+
const vmParts = DocumentHelper.parseId(did);
|
|
86
86
|
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
87
|
-
await vaultConnector.setSecret(`${
|
|
87
|
+
await vaultConnector.setSecret(`${vmParts.id}/${vaultSeedId}`, Converter.bytesToBase64(seed));
|
|
88
88
|
const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
|
|
89
89
|
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
90
90
|
const identityConnector = setupIdentityConnector({ nodeEndpoint, network, addressIndex, vaultSeedId }, opts.connector);
|
|
91
91
|
CLIDisplay.task(I18n.formatMessage("commands.verification-method-add.progress.addingVerificationMethod"));
|
|
92
92
|
CLIDisplay.break();
|
|
93
93
|
CLIDisplay.spinnerStart();
|
|
94
|
-
const verificationMethod = await identityConnector.addVerificationMethod(
|
|
94
|
+
const verificationMethod = await identityConnector.addVerificationMethod(vmParts.id, did, type, opts?.id);
|
|
95
95
|
CLIDisplay.spinnerStop();
|
|
96
96
|
const keyParts = DocumentHelper.parseId(verificationMethod.id);
|
|
97
|
-
const keyPair = await vaultConnector.getKey(`${
|
|
97
|
+
const keyPair = await vaultConnector.getKey(`${vmParts.id}/${keyParts.fragment}`);
|
|
98
98
|
const privateKeyBase64Url = Converter.bytesToBase64Url(keyPair.privateKey);
|
|
99
99
|
const publicKeyBase64Url = Is.uint8Array(keyPair.publicKey)
|
|
100
100
|
? Converter.bytesToBase64Url(keyPair.publicKey)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verificationMethodAdd.js","sourceRoot":"","sources":["../../../src/commands/verificationMethodAdd.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,UAAU,EACV,UAAU,EACV,QAAQ,EACR,QAAQ,EAER,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAE7E;;;GAGG;AACH,MAAM,UAAU,iCAAiC;IAChD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAC9B,OAAO;SACL,IAAI,CAAC,yBAAyB,CAAC;SAC/B,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,0CAA0C,CAAC,CAAC;SACvE,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,8CAA8C,CAAC,CAAC;SAC/E,cAAc,CACd,IAAI,CAAC,aAAa,CAAC,qDAAqD,CAAC,EACzE,IAAI,CAAC,aAAa,CAA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IACH,CAAC;IAED,UAAU,CAAC,KAAK,EAAE,CAAC;IAEnB,UAAU,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tCLIDisplay,\n\tCLIOptions,\n\tCLIParam,\n\tCLIUtils,\n\ttype CliOutputOptions\n} from \"@twin.org/cli-core\";\nimport { Converter, I18n, Is, StringHelper, Urn } from \"@twin.org/core\";\nimport { DocumentHelper } from \"@twin.org/identity-models\";\nimport { DidVerificationMethodType } from \"@twin.org/standards-w3c-did\";\nimport { VaultConnectorFactory } from \"@twin.org/vault-models\";\nimport { setupWalletConnector } from \"@twin.org/wallet-cli\";\nimport { WalletConnectorFactory } from \"@twin.org/wallet-models\";\nimport { Jwk } from \"@twin.org/web\";\nimport { Command, Option } from \"commander\";\nimport { setupIdentityConnector, setupVault } from \"./setupCommands.js\";\nimport { IdentityConnectorTypes } from \"../models/identityConnectorTypes.js\";\n\n/**\n * Build the verification method add command for the CLI.\n * @returns The command.\n */\nexport function buildCommandVerificationMethodAdd(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"verification-method-add\")\n\t\t.summary(I18n.formatMessage(\"commands.verification-method-add.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.verification-method-add.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.seed.param\"),\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.seed.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.did.param\"),\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.did.description\")\n\t\t)\n\t\t.addOption(\n\t\t\tnew Option(\n\t\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.type.param\"),\n\t\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.type.description\")\n\t\t\t)\n\t\t\t\t.choices(Object.values(DidVerificationMethodType))\n\t\t\t\t.makeOptionMandatory()\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.id.param\"),\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.id.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.addressIndex.param\"),\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.addressIndex.description\"),\n\t\t\t\"0\"\n\t\t);\n\tCLIOptions.output(command, {\n\t\tnoConsole: true,\n\t\tjson: true,\n\t\tenv: true,\n\t\tmergeJson: true,\n\t\tmergeEnv: true\n\t});\n\n\tcommand\n\t\t.addOption(\n\t\t\tnew Option(\n\t\t\t\tI18n.formatMessage(\"commands.common.options.connector.param\"),\n\t\t\t\tI18n.formatMessage(\"commands.common.options.connector.description\")\n\t\t\t)\n\t\t\t\t.choices(Object.values(IdentityConnectorTypes))\n\t\t\t\t.default(IdentityConnectorTypes.Iota)\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.node.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.node.description\"),\n\t\t\t\"!NODE_URL\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.network.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.network.description\"),\n\t\t\t\"!NETWORK\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.explorer.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.explorer.description\"),\n\t\t\t\"!EXPLORER_URL\"\n\t\t)\n\t\t.action(actionCommandVerificationMethodAdd);\n\n\treturn command;\n}\n\n/**\n * Action the verification method add command.\n * @param opts The options for the command.\n * @param opts.seed The private key for the controller.\n * @param opts.did The identity of the document to add to.\n * @param opts.type The type of the verification method to add.\n * @param opts.id The id of the verification method to add.\n * @param opts.connector The connector to perform the operations with.\n * @param opts.node The node URL.\n * @param opts.explorer The explorer URL.\n * @param opts.network The network to use for connector.\n * @param opts.addressIndex The address index to use for key derivation (if applicable).\n */\nexport async function actionCommandVerificationMethodAdd(\n\topts: {\n\t\tseed: string;\n\t\tdid: string;\n\t\ttype: DidVerificationMethodType;\n\t\tid?: string;\n\t\taddressIndex?: string;\n\t\tconnector?: IdentityConnectorTypes;\n\t\tnode: string;\n\t\tnetwork?: string;\n\t\texplorer: string;\n\t} & CliOutputOptions\n): Promise<void> {\n\tconst seed: Uint8Array = CLIParam.hexBase64(\"seed\", opts.seed);\n\tconst did: string = CLIParam.stringValue(\"did\", opts.did);\n\tconst type: DidVerificationMethodType = CLIParam.stringValue(\n\t\t\"type\",\n\t\topts.type\n\t) as DidVerificationMethodType;\n\tconst addressIndex: number = CLIParam.integer(\"addressIndex\", opts.addressIndex ?? \"0\", false, 0);\n\tconst nodeEndpoint: string = CLIParam.url(\"node\", opts.node);\n\tconst network: string | undefined =\n\t\topts.connector === IdentityConnectorTypes.Iota\n\t\t\t? CLIParam.stringValue(\"network\", opts.network)\n\t\t\t: undefined;\n\tconst explorerEndpoint: string = CLIParam.url(\"explorer\", opts.explorer);\n\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.did\"), did);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verification-method-add.labels.verificationMethodType\"),\n\t\ttype\n\t);\n\tif (Is.stringValue(opts.id)) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.verificationMethodId\"),\n\t\t\topts?.id\n\t\t);\n\t}\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verification-method-add.labels.addressIndex\"),\n\t\taddressIndex\n\t);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.node\"), nodeEndpoint);\n\tif (Is.stringValue(network)) {\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.network\"), network);\n\t}\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.explorer\"), explorerEndpoint);\n\tCLIDisplay.break();\n\n\tsetupVault();\n\n\tconst vaultSeedId = \"local-seed\";\n\tconst localIdentity = \"local\";\n\n\tconst vaultConnector = VaultConnectorFactory.get(\"vault\");\n\tawait vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));\n\n\tconst walletConnector = setupWalletConnector(\n\t\t{ nodeEndpoint, vaultSeedId, network },\n\t\topts.connector\n\t);\n\tWalletConnectorFactory.register(\"wallet\", () => walletConnector);\n\n\tconst identityConnector = setupIdentityConnector(\n\t\t{ nodeEndpoint, network, addressIndex, vaultSeedId },\n\t\topts.connector\n\t);\n\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\"commands.verification-method-add.progress.addingVerificationMethod\")\n\t);\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tconst verificationMethod = await identityConnector.addVerificationMethod(\n\t\tlocalIdentity,\n\t\tdid,\n\t\ttype,\n\t\topts?.id\n\t);\n\n\tCLIDisplay.spinnerStop();\n\n\tconst keyParts = DocumentHelper.parseId(verificationMethod.id);\n\n\tconst keyPair = await vaultConnector.getKey(`${localIdentity}/${keyParts.fragment}`);\n\tconst privateKeyBase64Url = Converter.bytesToBase64Url(keyPair.privateKey);\n\tconst publicKeyBase64Url = Is.uint8Array(keyPair.publicKey)\n\t\t? Converter.bytesToBase64Url(keyPair.publicKey)\n\t\t: \"\";\n\n\tconst privateKeyBase64 = Converter.bytesToBase64(keyPair.privateKey);\n\tconst publicKeyBase64 = Is.uint8Array(keyPair.publicKey)\n\t\t? Converter.bytesToBase64(keyPair.publicKey)\n\t\t: \"\";\n\n\tconst privateKeyHex = Converter.bytesToHex(keyPair.privateKey, true);\n\tconst publicKeyHex = Is.uint8Array(keyPair.publicKey)\n\t\t? Converter.bytesToHex(keyPair.publicKey, true)\n\t\t: \"\";\n\n\tconst jwk = await Jwk.fromEd25519Private(keyPair.privateKey);\n\tconst kid = await Jwk.generateKid(jwk);\n\n\tif (opts.console) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.verificationMethodId\"),\n\t\t\tverificationMethod.id\n\t\t);\n\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.verification-method-add.labels.kid\"), kid);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.privateKeyBase64Url\"),\n\t\t\tprivateKeyBase64Url\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.publicKeyBase64Url\"),\n\t\t\tpublicKeyBase64Url\n\t\t);\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.privateKeyBase64\"),\n\t\t\tprivateKeyBase64\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.publicKeyBase64\"),\n\t\t\tpublicKeyBase64\n\t\t);\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.privateKeyHex\"),\n\t\t\tprivateKeyHex\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.publicKeyHex\"),\n\t\t\tpublicKeyHex\n\t\t);\n\n\t\tCLIDisplay.break();\n\t}\n\n\tif (Is.stringValue(opts?.json)) {\n\t\tawait CLIUtils.writeJsonFile(\n\t\t\topts.json,\n\t\t\t{\n\t\t\t\tverificationMethodId: verificationMethod.id,\n\t\t\t\tprivateKeyJwk: {\n\t\t\t\t\tkid,\n\t\t\t\t\t...jwk\n\t\t\t\t},\n\t\t\t\tprivateKeyHex,\n\t\t\t\tpublicKeyHex,\n\t\t\t\tprivateKeyBase64,\n\t\t\t\tpublicKeyBase64\n\t\t\t},\n\t\t\topts.mergeJson\n\t\t);\n\t}\n\tif (Is.stringValue(opts?.env)) {\n\t\tawait CLIUtils.writeEnvFile(\n\t\t\topts.env,\n\t\t\t[\n\t\t\t\t`DID_VERIFICATION_METHOD_ID=\"${verificationMethod.id}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_KID=\"${kid}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_JWK_KTY=\"${jwk.kty}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_JWK_USE=\"${jwk.use}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_JWK_ALG=\"${jwk.alg}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_JWK_CRV=\"${jwk.crv}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_JWK_X=\"${jwk.x}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_JWK_D=\"${jwk.d}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_PRIVATE_KEY_HEX=\"${privateKeyHex}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_PUBLIC_KEY_HEX=\"${publicKeyHex}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_PRIVATE_KEY_BASE64=\"${privateKeyBase64}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_PUBLIC_KEY_BASE64=\"${publicKeyBase64}\"`\n\t\t\t],\n\t\t\topts.mergeEnv\n\t\t);\n\t}\n\n\tif (opts.connector === IdentityConnectorTypes.Iota) {\n\t\tconst didUrn = Urn.fromValidString(did);\n\t\tconst didParts = didUrn.parts();\n\t\tconst objectId = didParts[didParts.length - 1];\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.common.labels.explore\"),\n\t\t\t`${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`\n\t\t);\n\t}\n\n\tCLIDisplay.break();\n\n\tCLIDisplay.done();\n}\n"]}
|
|
1
|
+
{"version":3,"file":"verificationMethodAdd.js","sourceRoot":"","sources":["../../../src/commands/verificationMethodAdd.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,UAAU,EACV,UAAU,EACV,QAAQ,EACR,QAAQ,EAER,MAAM,oBAAoB,CAAC;AAC5B,OA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"@twin.org/cli-core\";\nimport { Converter, I18n, Is, StringHelper, Urn } from \"@twin.org/core\";\nimport { DocumentHelper } from \"@twin.org/identity-models\";\nimport { DidVerificationMethodType } from \"@twin.org/standards-w3c-did\";\nimport { VaultConnectorFactory } from \"@twin.org/vault-models\";\nimport { setupWalletConnector } from \"@twin.org/wallet-cli\";\nimport { WalletConnectorFactory } from \"@twin.org/wallet-models\";\nimport { Jwk } from \"@twin.org/web\";\nimport { Command, Option } from \"commander\";\nimport { setupIdentityConnector, setupVault } from \"./setupCommands.js\";\nimport { IdentityConnectorTypes } from \"../models/identityConnectorTypes.js\";\n\n/**\n * Build the verification method add command for the CLI.\n * @returns The command.\n */\nexport function buildCommandVerificationMethodAdd(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"verification-method-add\")\n\t\t.summary(I18n.formatMessage(\"commands.verification-method-add.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.verification-method-add.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.seed.param\"),\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.seed.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.did.param\"),\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.did.description\")\n\t\t)\n\t\t.addOption(\n\t\t\tnew Option(\n\t\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.type.param\"),\n\t\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.type.description\")\n\t\t\t)\n\t\t\t\t.choices(Object.values(DidVerificationMethodType))\n\t\t\t\t.makeOptionMandatory()\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.id.param\"),\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.id.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.addressIndex.param\"),\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.options.addressIndex.description\"),\n\t\t\t\"0\"\n\t\t);\n\tCLIOptions.output(command, {\n\t\tnoConsole: true,\n\t\tjson: true,\n\t\tenv: true,\n\t\tmergeJson: true,\n\t\tmergeEnv: true\n\t});\n\n\tcommand\n\t\t.addOption(\n\t\t\tnew Option(\n\t\t\t\tI18n.formatMessage(\"commands.common.options.connector.param\"),\n\t\t\t\tI18n.formatMessage(\"commands.common.options.connector.description\")\n\t\t\t)\n\t\t\t\t.choices(Object.values(IdentityConnectorTypes))\n\t\t\t\t.default(IdentityConnectorTypes.Iota)\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.node.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.node.description\"),\n\t\t\t\"!NODE_URL\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.network.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.network.description\"),\n\t\t\t\"!NETWORK\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.explorer.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.explorer.description\"),\n\t\t\t\"!EXPLORER_URL\"\n\t\t)\n\t\t.action(actionCommandVerificationMethodAdd);\n\n\treturn command;\n}\n\n/**\n * Action the verification method add command.\n * @param opts The options for the command.\n * @param opts.seed The private key for the controller.\n * @param opts.did The identity of the document to add to.\n * @param opts.type The type of the verification method to add.\n * @param opts.id The id of the verification method to add.\n * @param opts.connector The connector to perform the operations with.\n * @param opts.node The node URL.\n * @param opts.explorer The explorer URL.\n * @param opts.network The network to use for connector.\n * @param opts.addressIndex The address index to use for key derivation (if applicable).\n */\nexport async function actionCommandVerificationMethodAdd(\n\topts: {\n\t\tseed: string;\n\t\tdid: string;\n\t\ttype: DidVerificationMethodType;\n\t\tid?: string;\n\t\taddressIndex?: string;\n\t\tconnector?: IdentityConnectorTypes;\n\t\tnode: string;\n\t\tnetwork?: string;\n\t\texplorer: string;\n\t} & CliOutputOptions\n): Promise<void> {\n\tconst seed: Uint8Array = CLIParam.hexBase64(\"seed\", opts.seed);\n\tconst did: string = CLIParam.stringValue(\"did\", opts.did);\n\tconst type: DidVerificationMethodType = CLIParam.stringValue(\n\t\t\"type\",\n\t\topts.type\n\t) as DidVerificationMethodType;\n\tconst addressIndex: number = CLIParam.integer(\"addressIndex\", opts.addressIndex ?? \"0\", false, 0);\n\tconst nodeEndpoint: string = CLIParam.url(\"node\", opts.node);\n\tconst network: string | undefined =\n\t\topts.connector === IdentityConnectorTypes.Iota\n\t\t\t? CLIParam.stringValue(\"network\", opts.network)\n\t\t\t: undefined;\n\tconst explorerEndpoint: string = CLIParam.url(\"explorer\", opts.explorer);\n\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.did\"), did);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verification-method-add.labels.verificationMethodType\"),\n\t\ttype\n\t);\n\tif (Is.stringValue(opts.id)) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.verificationMethodId\"),\n\t\t\topts?.id\n\t\t);\n\t}\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verification-method-add.labels.addressIndex\"),\n\t\taddressIndex\n\t);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.node\"), nodeEndpoint);\n\tif (Is.stringValue(network)) {\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.network\"), network);\n\t}\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.explorer\"), explorerEndpoint);\n\tCLIDisplay.break();\n\n\tsetupVault();\n\n\tconst vaultSeedId = \"local-seed\";\n\n\tconst vmParts = DocumentHelper.parseId(did);\n\n\tconst vaultConnector = VaultConnectorFactory.get(\"vault\");\n\tawait vaultConnector.setSecret(`${vmParts.id}/${vaultSeedId}`, Converter.bytesToBase64(seed));\n\n\tconst walletConnector = setupWalletConnector(\n\t\t{ nodeEndpoint, vaultSeedId, network },\n\t\topts.connector\n\t);\n\tWalletConnectorFactory.register(\"wallet\", () => walletConnector);\n\n\tconst identityConnector = setupIdentityConnector(\n\t\t{ nodeEndpoint, network, addressIndex, vaultSeedId },\n\t\topts.connector\n\t);\n\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\"commands.verification-method-add.progress.addingVerificationMethod\")\n\t);\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tconst verificationMethod = await identityConnector.addVerificationMethod(\n\t\tvmParts.id,\n\t\tdid,\n\t\ttype,\n\t\topts?.id\n\t);\n\n\tCLIDisplay.spinnerStop();\n\n\tconst keyParts = DocumentHelper.parseId(verificationMethod.id);\n\n\tconst keyPair = await vaultConnector.getKey(`${vmParts.id}/${keyParts.fragment}`);\n\tconst privateKeyBase64Url = Converter.bytesToBase64Url(keyPair.privateKey);\n\tconst publicKeyBase64Url = Is.uint8Array(keyPair.publicKey)\n\t\t? Converter.bytesToBase64Url(keyPair.publicKey)\n\t\t: \"\";\n\n\tconst privateKeyBase64 = Converter.bytesToBase64(keyPair.privateKey);\n\tconst publicKeyBase64 = Is.uint8Array(keyPair.publicKey)\n\t\t? Converter.bytesToBase64(keyPair.publicKey)\n\t\t: \"\";\n\n\tconst privateKeyHex = Converter.bytesToHex(keyPair.privateKey, true);\n\tconst publicKeyHex = Is.uint8Array(keyPair.publicKey)\n\t\t? Converter.bytesToHex(keyPair.publicKey, true)\n\t\t: \"\";\n\n\tconst jwk = await Jwk.fromEd25519Private(keyPair.privateKey);\n\tconst kid = await Jwk.generateKid(jwk);\n\n\tif (opts.console) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.verificationMethodId\"),\n\t\t\tverificationMethod.id\n\t\t);\n\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.verification-method-add.labels.kid\"), kid);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.privateKeyBase64Url\"),\n\t\t\tprivateKeyBase64Url\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.publicKeyBase64Url\"),\n\t\t\tpublicKeyBase64Url\n\t\t);\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.privateKeyBase64\"),\n\t\t\tprivateKeyBase64\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.publicKeyBase64\"),\n\t\t\tpublicKeyBase64\n\t\t);\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.privateKeyHex\"),\n\t\t\tprivateKeyHex\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verification-method-add.labels.publicKeyHex\"),\n\t\t\tpublicKeyHex\n\t\t);\n\n\t\tCLIDisplay.break();\n\t}\n\n\tif (Is.stringValue(opts?.json)) {\n\t\tawait CLIUtils.writeJsonFile(\n\t\t\topts.json,\n\t\t\t{\n\t\t\t\tverificationMethodId: verificationMethod.id,\n\t\t\t\tprivateKeyJwk: {\n\t\t\t\t\tkid,\n\t\t\t\t\t...jwk\n\t\t\t\t},\n\t\t\t\tprivateKeyHex,\n\t\t\t\tpublicKeyHex,\n\t\t\t\tprivateKeyBase64,\n\t\t\t\tpublicKeyBase64\n\t\t\t},\n\t\t\topts.mergeJson\n\t\t);\n\t}\n\tif (Is.stringValue(opts?.env)) {\n\t\tawait CLIUtils.writeEnvFile(\n\t\t\topts.env,\n\t\t\t[\n\t\t\t\t`DID_VERIFICATION_METHOD_ID=\"${verificationMethod.id}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_KID=\"${kid}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_JWK_KTY=\"${jwk.kty}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_JWK_USE=\"${jwk.use}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_JWK_ALG=\"${jwk.alg}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_JWK_CRV=\"${jwk.crv}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_JWK_X=\"${jwk.x}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_JWK_D=\"${jwk.d}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_PRIVATE_KEY_HEX=\"${privateKeyHex}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_PUBLIC_KEY_HEX=\"${publicKeyHex}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_PRIVATE_KEY_BASE64=\"${privateKeyBase64}\"`,\n\t\t\t\t`DID_VERIFICATION_METHOD_PUBLIC_KEY_BASE64=\"${publicKeyBase64}\"`\n\t\t\t],\n\t\t\topts.mergeEnv\n\t\t);\n\t}\n\n\tif (opts.connector === IdentityConnectorTypes.Iota) {\n\t\tconst didUrn = Urn.fromValidString(did);\n\t\tconst didParts = didUrn.parts();\n\t\tconst objectId = didParts[didParts.length - 1];\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.common.labels.explore\"),\n\t\t\t`${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`\n\t\t);\n\t}\n\n\tCLIDisplay.break();\n\n\tCLIDisplay.done();\n}\n"]}
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @twin.org/identity-cli - Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.16](https://github.com/twinfoundation/identity/compare/identity-cli-v0.0.3-next.15...identity-cli-v0.0.3-next.16) (2026-02-13)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Miscellaneous Chores
|
|
7
|
+
|
|
8
|
+
* **identity-cli:** Synchronize repo versions
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/identity-models bumped from 0.0.3-next.15 to 0.0.3-next.16
|
|
16
|
+
* @twin.org/identity-connector-iota bumped from 0.0.3-next.15 to 0.0.3-next.16
|
|
17
|
+
|
|
18
|
+
## [0.0.3-next.15](https://github.com/twinfoundation/identity/compare/identity-cli-v0.0.3-next.14...identity-cli-v0.0.3-next.15) (2026-02-12)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
* correct vault usage in cli commands ([#106](https://github.com/twinfoundation/identity/issues/106)) ([d81671d](https://github.com/twinfoundation/identity/commit/d81671d994390c9db7ded82e5f42b4bc521603fc))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Dependencies
|
|
27
|
+
|
|
28
|
+
* The following workspace dependencies were updated
|
|
29
|
+
* dependencies
|
|
30
|
+
* @twin.org/identity-models bumped from 0.0.3-next.14 to 0.0.3-next.15
|
|
31
|
+
* @twin.org/identity-connector-iota bumped from 0.0.3-next.14 to 0.0.3-next.15
|
|
32
|
+
|
|
3
33
|
## [0.0.3-next.14](https://github.com/twinfoundation/identity/compare/identity-cli-v0.0.3-next.13...identity-cli-v0.0.3-next.14) (2026-02-10)
|
|
4
34
|
|
|
5
35
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/identity-cli",
|
|
3
|
-
"version": "0.0.3-next.
|
|
3
|
+
"version": "0.0.3-next.16",
|
|
4
4
|
"description": "A command line interface for interacting with the identity connectors",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"@twin.org/data-json-ld": "next",
|
|
22
22
|
"@twin.org/entity": "next",
|
|
23
23
|
"@twin.org/entity-storage-connector-memory": "next",
|
|
24
|
-
"@twin.org/identity-connector-iota": "0.0.3-next.
|
|
25
|
-
"@twin.org/identity-models": "0.0.3-next.
|
|
24
|
+
"@twin.org/identity-connector-iota": "0.0.3-next.16",
|
|
25
|
+
"@twin.org/identity-models": "0.0.3-next.16",
|
|
26
26
|
"@twin.org/nameof": "next",
|
|
27
27
|
"@twin.org/standards-w3c-did": "next",
|
|
28
28
|
"@twin.org/vault-connector-entity-storage": "next",
|