@twin.org/identity-cli 0.0.1-next.4 → 0.0.1-next.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.js +0 -0
- package/dist/cjs/index.cjs +292 -277
- package/dist/esm/index.mjs +292 -280
- package/dist/locales/en.json +904 -789
- package/dist/types/commands/identityCreate.d.ts +6 -0
- package/dist/types/commands/identityResolve.d.ts +5 -0
- package/dist/types/commands/proofCreate.d.ts +6 -1
- package/dist/types/commands/proofVerify.d.ts +9 -7
- package/dist/types/commands/serviceAdd.d.ts +4 -0
- package/dist/types/commands/serviceRemove.d.ts +5 -0
- package/dist/types/commands/setupCommands.d.ts +18 -0
- package/dist/types/commands/verifiableCredentialCreate.d.ts +4 -4
- package/dist/types/commands/verifiableCredentialRevoke.d.ts +5 -0
- package/dist/types/commands/verifiableCredentialUnrevoke.d.ts +5 -0
- package/dist/types/commands/verifiableCredentialVerify.d.ts +4 -0
- package/dist/types/commands/verificationMethodAdd.d.ts +4 -0
- package/dist/types/commands/verificationMethodRemove.d.ts +5 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/models/identityConnectorTypes.d.ts +17 -0
- package/docs/changelog.md +34 -1
- package/docs/examples.md +9 -9
- package/docs/reference/classes/CLI.md +10 -4
- package/docs/reference/functions/actionCommandIdentityCreate.md +3 -1
- package/docs/reference/functions/actionCommandIdentityResolve.md +3 -1
- package/docs/reference/functions/actionCommandProofCreate.md +3 -1
- package/docs/reference/functions/actionCommandProofVerify.md +3 -1
- package/docs/reference/functions/actionCommandServiceAdd.md +3 -1
- package/docs/reference/functions/actionCommandServiceRemove.md +25 -5
- package/docs/reference/functions/actionCommandVerifiableCredentialCreate.md +3 -1
- package/docs/reference/functions/actionCommandVerifiableCredentialRevoke.md +25 -5
- package/docs/reference/functions/actionCommandVerifiableCredentialUnrevoke.md +25 -5
- package/docs/reference/functions/actionCommandVerifiableCredentialVerify.md +3 -1
- package/docs/reference/functions/actionCommandVerificationMethodAdd.md +3 -1
- package/docs/reference/functions/actionCommandVerificationMethodRemove.md +25 -5
- package/docs/reference/functions/setupIdentityConnector.md +47 -0
- package/docs/reference/functions/setupVault.md +9 -0
- package/docs/reference/index.md +10 -0
- package/docs/reference/type-aliases/IdentityConnectorTypes.md +5 -0
- package/docs/reference/variables/IdentityConnectorTypes.md +19 -0
- package/locales/en.json +35 -36
- package/package.json +9 -6
package/dist/esm/index.mjs
CHANGED
|
@@ -2,18 +2,35 @@ import path from 'node:path';
|
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
|
3
3
|
import { CLIOptions, CLIParam, CLIDisplay, CLIUtils, CLIBase } from '@twin.org/cli-core';
|
|
4
4
|
import { buildCommandMnemonic, buildCommandAddress } from '@twin.org/crypto-cli';
|
|
5
|
-
import { buildCommandFaucet, buildCommandTransfer } from '@twin.org/wallet-cli';
|
|
6
|
-
import { I18n,
|
|
7
|
-
import {
|
|
5
|
+
import { setupWalletConnector, buildCommandFaucet, buildCommandTransfer } from '@twin.org/wallet-cli';
|
|
6
|
+
import { I18n, Is, Converter, StringHelper, GeneralError, Coerce } from '@twin.org/core';
|
|
7
|
+
import { IotaStardustIdentityConnector, IotaStardustIdentityUtils, IotaStardustIdentityResolverConnector } from '@twin.org/identity-connector-iota-stardust';
|
|
8
8
|
import { VaultConnectorFactory, VaultKeyType } from '@twin.org/vault-models';
|
|
9
|
-
import { IotaWalletConnector } from '@twin.org/wallet-connector-iota';
|
|
10
9
|
import { WalletConnectorFactory } from '@twin.org/wallet-models';
|
|
11
10
|
import { Command, Option } from 'commander';
|
|
12
11
|
import { MemoryEntityStorageConnector } from '@twin.org/entity-storage-connector-memory';
|
|
13
12
|
import { EntityStorageConnectorFactory } from '@twin.org/entity-storage-models';
|
|
13
|
+
import { IotaIdentityConnector } from '@twin.org/identity-connector-iota';
|
|
14
14
|
import { initSchema, EntityStorageVaultConnector } from '@twin.org/vault-connector-entity-storage';
|
|
15
15
|
import { DocumentHelper } from '@twin.org/identity-models';
|
|
16
|
-
import { DidVerificationMethodType } from '@twin.org/standards-w3c-did';
|
|
16
|
+
import { ProofTypes, DidVerificationMethodType } from '@twin.org/standards-w3c-did';
|
|
17
|
+
|
|
18
|
+
// Copyright 2024 IOTA Stiftung.
|
|
19
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
20
|
+
/**
|
|
21
|
+
* The identity connector types.
|
|
22
|
+
*/
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
24
|
+
const IdentityConnectorTypes = {
|
|
25
|
+
/**
|
|
26
|
+
* IOTA.
|
|
27
|
+
*/
|
|
28
|
+
Iota: "iota",
|
|
29
|
+
/**
|
|
30
|
+
* IOTA Stardust.
|
|
31
|
+
*/
|
|
32
|
+
IotaStardust: "iota-stardust"
|
|
33
|
+
};
|
|
17
34
|
|
|
18
35
|
// Copyright 2024 IOTA Stiftung.
|
|
19
36
|
// SPDX-License-Identifier: Apache-2.0.
|
|
@@ -31,6 +48,41 @@ function setupVault() {
|
|
|
31
48
|
const vaultConnector = new EntityStorageVaultConnector();
|
|
32
49
|
VaultConnectorFactory.register("vault", () => vaultConnector);
|
|
33
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Setup the identity connector for use in the CLI commands.
|
|
53
|
+
* @param options The options for the identity connector.
|
|
54
|
+
* @param options.nodeEndpoint The node endpoint.
|
|
55
|
+
* @param options.network The network.
|
|
56
|
+
* @param options.addressIndex The wallet index.
|
|
57
|
+
* @param options.vaultSeedId The vault seed ID.
|
|
58
|
+
* @param connector The connector to use.
|
|
59
|
+
* @returns The identity connector.
|
|
60
|
+
*/
|
|
61
|
+
function setupIdentityConnector(options, connector) {
|
|
62
|
+
connector ??= IdentityConnectorTypes.Iota;
|
|
63
|
+
if (connector === IdentityConnectorTypes.Iota) {
|
|
64
|
+
return new IotaIdentityConnector({
|
|
65
|
+
config: {
|
|
66
|
+
clientOptions: {
|
|
67
|
+
url: options.nodeEndpoint
|
|
68
|
+
},
|
|
69
|
+
network: options.network ?? "",
|
|
70
|
+
vaultSeedId: options.vaultSeedId,
|
|
71
|
+
walletAddressIndex: options.addressIndex
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return new IotaStardustIdentityConnector({
|
|
76
|
+
config: {
|
|
77
|
+
clientOptions: {
|
|
78
|
+
nodes: [options.nodeEndpoint],
|
|
79
|
+
localPow: true
|
|
80
|
+
},
|
|
81
|
+
vaultSeedId: options.vaultSeedId,
|
|
82
|
+
walletAddressIndex: options.addressIndex
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
34
86
|
|
|
35
87
|
// Copyright 2024 IOTA Stiftung.
|
|
36
88
|
// SPDX-License-Identifier: Apache-2.0.
|
|
@@ -44,7 +96,8 @@ function buildCommandIdentityCreate() {
|
|
|
44
96
|
.name("identity-create")
|
|
45
97
|
.summary(I18n.formatMessage("commands.identity-create.summary"))
|
|
46
98
|
.description(I18n.formatMessage("commands.identity-create.description"))
|
|
47
|
-
.requiredOption(I18n.formatMessage("commands.identity-create.options.seed.param"), I18n.formatMessage("commands.identity-create.options.seed.description"))
|
|
99
|
+
.requiredOption(I18n.formatMessage("commands.identity-create.options.seed.param"), I18n.formatMessage("commands.identity-create.options.seed.description"))
|
|
100
|
+
.option(I18n.formatMessage("commands.identity-create.options.addressIndex.param"), I18n.formatMessage("commands.identity-create.options.addressIndex.description"), "0");
|
|
48
101
|
CLIOptions.output(command, {
|
|
49
102
|
noConsole: true,
|
|
50
103
|
json: true,
|
|
@@ -53,7 +106,11 @@ function buildCommandIdentityCreate() {
|
|
|
53
106
|
mergeEnv: true
|
|
54
107
|
});
|
|
55
108
|
command
|
|
109
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
110
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
111
|
+
.default(IdentityConnectorTypes.Iota))
|
|
56
112
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
113
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
57
114
|
.option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
58
115
|
.action(actionCommandIdentityCreate);
|
|
59
116
|
return command;
|
|
@@ -62,44 +119,38 @@ function buildCommandIdentityCreate() {
|
|
|
62
119
|
* Action the identity create command.
|
|
63
120
|
* @param opts The options for the command.
|
|
64
121
|
* @param opts.seed The private key for the controller.
|
|
122
|
+
* @param opts.connector The connector to perform the operations with.
|
|
65
123
|
* @param opts.node The node URL.
|
|
124
|
+
* @param opts.network The network to use for connector.
|
|
66
125
|
* @param opts.explorer The explorer URL.
|
|
67
126
|
*/
|
|
68
127
|
async function actionCommandIdentityCreate(opts) {
|
|
69
128
|
const seed = CLIParam.hexBase64("seed", opts.seed);
|
|
70
129
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
130
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
131
|
+
? CLIParam.stringValue("network", opts.network)
|
|
132
|
+
: undefined;
|
|
71
133
|
const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
|
|
134
|
+
const addressIndex = CLIParam.integer("addressIndex", opts.addressIndex ?? "0", false, 0);
|
|
72
135
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
136
|
+
if (Is.stringValue(network)) {
|
|
137
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
138
|
+
}
|
|
73
139
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
|
|
140
|
+
CLIDisplay.value(I18n.formatMessage("commands.identity-create.labels.addressIndex"), addressIndex);
|
|
74
141
|
CLIDisplay.break();
|
|
75
142
|
setupVault();
|
|
76
143
|
const vaultSeedId = "local-seed";
|
|
77
144
|
const localIdentity = "local";
|
|
78
145
|
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
79
146
|
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
nodes: [nodeEndpoint],
|
|
84
|
-
localPow: true
|
|
85
|
-
},
|
|
86
|
-
vaultSeedId
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
90
|
-
const iotaIdentityConnector = new IotaIdentityConnector({
|
|
91
|
-
config: {
|
|
92
|
-
clientOptions: {
|
|
93
|
-
nodes: [nodeEndpoint],
|
|
94
|
-
localPow: true
|
|
95
|
-
},
|
|
96
|
-
vaultSeedId
|
|
97
|
-
}
|
|
98
|
-
});
|
|
147
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
|
|
148
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
149
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, vaultSeedId, network, addressIndex }, opts.connector);
|
|
99
150
|
CLIDisplay.task(I18n.formatMessage("commands.identity-create.progress.creatingIdentity"));
|
|
100
151
|
CLIDisplay.break();
|
|
101
152
|
CLIDisplay.spinnerStart();
|
|
102
|
-
const document = await
|
|
153
|
+
const document = await identityConnector.createDocument(localIdentity);
|
|
103
154
|
CLIDisplay.spinnerStop();
|
|
104
155
|
if (opts.console) {
|
|
105
156
|
CLIDisplay.value(I18n.formatMessage("commands.identity-create.labels.identity"), document.id);
|
|
@@ -111,7 +162,7 @@ async function actionCommandIdentityCreate(opts) {
|
|
|
111
162
|
if (Is.stringValue(opts?.env)) {
|
|
112
163
|
await CLIUtils.writeEnvFile(opts.env, [`DID="${document.id}"`], opts.mergeEnv);
|
|
113
164
|
}
|
|
114
|
-
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${
|
|
165
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${IotaStardustIdentityUtils.didToAddress(document.id)}?tab=DID`);
|
|
115
166
|
CLIDisplay.break();
|
|
116
167
|
CLIDisplay.done();
|
|
117
168
|
}
|
|
@@ -137,8 +188,12 @@ function buildCommandIdentityResolve() {
|
|
|
137
188
|
mergeEnv: false
|
|
138
189
|
});
|
|
139
190
|
command
|
|
191
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
192
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
193
|
+
.default(IdentityConnectorTypes.Iota))
|
|
140
194
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
141
195
|
.option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
196
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
142
197
|
.action(actionCommandIdentityResolve);
|
|
143
198
|
return command;
|
|
144
199
|
}
|
|
@@ -146,28 +201,29 @@ function buildCommandIdentityResolve() {
|
|
|
146
201
|
* Action the identity resolve command.
|
|
147
202
|
* @param opts The options for the command.
|
|
148
203
|
* @param opts.did The identity to resolve.
|
|
204
|
+
* @param opts.connector The connector to perform the operations with.
|
|
149
205
|
* @param opts.node The node URL.
|
|
206
|
+
* @param opts.network The network to use for connector.
|
|
150
207
|
* @param opts.explorer The explorer URL.
|
|
151
208
|
*/
|
|
152
209
|
async function actionCommandIdentityResolve(opts) {
|
|
153
210
|
const did = CLIParam.stringValue("did", opts.did);
|
|
154
211
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
212
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
213
|
+
? CLIParam.stringValue("network", opts.network)
|
|
214
|
+
: undefined;
|
|
155
215
|
const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
|
|
156
216
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.did"), did);
|
|
157
217
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
218
|
+
if (Is.stringValue(network)) {
|
|
219
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
220
|
+
}
|
|
158
221
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
|
|
159
222
|
CLIDisplay.break();
|
|
160
223
|
setupVault();
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
nodes: [nodeEndpoint],
|
|
165
|
-
localPow: true
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
170
|
-
const iotaIdentityConnector = new IotaIdentityConnector({
|
|
224
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);
|
|
225
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
226
|
+
const iotaIdentityResolverConnector = new IotaStardustIdentityResolverConnector({
|
|
171
227
|
config: {
|
|
172
228
|
clientOptions: {
|
|
173
229
|
nodes: [nodeEndpoint],
|
|
@@ -178,7 +234,7 @@ async function actionCommandIdentityResolve(opts) {
|
|
|
178
234
|
CLIDisplay.task(I18n.formatMessage("commands.identity-resolve.progress.resolvingIdentity"));
|
|
179
235
|
CLIDisplay.break();
|
|
180
236
|
CLIDisplay.spinnerStart();
|
|
181
|
-
const document = await
|
|
237
|
+
const document = await iotaIdentityResolverConnector.resolveDocument(did);
|
|
182
238
|
CLIDisplay.spinnerStop();
|
|
183
239
|
if (opts.console) {
|
|
184
240
|
CLIDisplay.section(I18n.formatMessage("commands.identity-resolve.labels.didDocument"));
|
|
@@ -188,7 +244,7 @@ async function actionCommandIdentityResolve(opts) {
|
|
|
188
244
|
if (Is.stringValue(opts?.json)) {
|
|
189
245
|
await CLIUtils.writeJsonFile(opts.json, document, opts.mergeJson);
|
|
190
246
|
}
|
|
191
|
-
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${
|
|
247
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${IotaStardustIdentityUtils.didToAddress(document.id)}?tab=DID`);
|
|
192
248
|
CLIDisplay.break();
|
|
193
249
|
CLIDisplay.done();
|
|
194
250
|
}
|
|
@@ -207,7 +263,7 @@ function buildCommandProofCreate() {
|
|
|
207
263
|
.description(I18n.formatMessage("commands.proof-create.description"))
|
|
208
264
|
.requiredOption(I18n.formatMessage("commands.proof-create.options.id.param"), I18n.formatMessage("commands.proof-create.options.id.description"))
|
|
209
265
|
.requiredOption(I18n.formatMessage("commands.proof-create.options.private-key.param"), I18n.formatMessage("commands.proof-create.options.private-key.description"))
|
|
210
|
-
.requiredOption(I18n.formatMessage("commands.proof-create.options.
|
|
266
|
+
.requiredOption(I18n.formatMessage("commands.proof-create.options.document-filename.param"), I18n.formatMessage("commands.proof-create.options.document-filename.description"));
|
|
211
267
|
CLIOptions.output(command, {
|
|
212
268
|
noConsole: true,
|
|
213
269
|
json: true,
|
|
@@ -216,7 +272,11 @@ function buildCommandProofCreate() {
|
|
|
216
272
|
mergeEnv: true
|
|
217
273
|
});
|
|
218
274
|
command
|
|
275
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
276
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
277
|
+
.default(IdentityConnectorTypes.Iota))
|
|
219
278
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
279
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
220
280
|
.action(actionCommandProofCreate);
|
|
221
281
|
return command;
|
|
222
282
|
}
|
|
@@ -226,53 +286,51 @@ function buildCommandProofCreate() {
|
|
|
226
286
|
* @param opts.id The id of the verification method to use for the credential.
|
|
227
287
|
* @param opts.privateKey The private key for the verification method.
|
|
228
288
|
* @param opts.data The data to create the proof for.
|
|
289
|
+
* @param opts.connector The connector to perform the operations with.
|
|
229
290
|
* @param opts.node The node URL.
|
|
291
|
+
* @param opts.network The network to use for connector.
|
|
230
292
|
*/
|
|
231
293
|
async function actionCommandProofCreate(opts) {
|
|
232
294
|
const id = CLIParam.stringValue("id", opts.id);
|
|
233
295
|
const privateKey = CLIParam.hexBase64("private-key", opts.privateKey);
|
|
234
|
-
const
|
|
296
|
+
const documentFilename = path.resolve(CLIParam.stringValue("document-filename", opts.documentFilename));
|
|
235
297
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
298
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
299
|
+
? CLIParam.stringValue("network", opts.network)
|
|
300
|
+
: undefined;
|
|
236
301
|
CLIDisplay.value(I18n.formatMessage("commands.proof-create.labels.verificationMethodId"), id);
|
|
302
|
+
CLIDisplay.value(I18n.formatMessage("commands.proof-create.labels.documentFilename"), documentFilename);
|
|
237
303
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
304
|
+
if (Is.stringValue(network)) {
|
|
305
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
306
|
+
}
|
|
238
307
|
CLIDisplay.break();
|
|
239
308
|
setupVault();
|
|
240
309
|
const localIdentity = "local";
|
|
310
|
+
const vmParts = DocumentHelper.parseId(id);
|
|
241
311
|
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
242
|
-
await vaultConnector.addKey(`${localIdentity}/${
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
nodes: [nodeEndpoint],
|
|
247
|
-
localPow: true
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
252
|
-
const iotaIdentityConnector = new IotaIdentityConnector({
|
|
253
|
-
config: {
|
|
254
|
-
clientOptions: {
|
|
255
|
-
nodes: [nodeEndpoint],
|
|
256
|
-
localPow: true
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
});
|
|
312
|
+
await vaultConnector.addKey(`${localIdentity}/${vmParts.fragment}`, VaultKeyType.Ed25519, privateKey, new Uint8Array());
|
|
313
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);
|
|
314
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
315
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network }, opts.connector);
|
|
260
316
|
CLIDisplay.task(I18n.formatMessage("commands.proof-create.progress.creatingProof"));
|
|
261
317
|
CLIDisplay.break();
|
|
262
318
|
CLIDisplay.spinnerStart();
|
|
263
|
-
const
|
|
264
|
-
|
|
319
|
+
const document = await CLIUtils.readJsonFile(documentFilename);
|
|
320
|
+
if (Is.undefined(document)) {
|
|
321
|
+
throw new GeneralError("commands", "commands.proof-create.documentJsonFileNotFound");
|
|
322
|
+
}
|
|
323
|
+
const proof = await identityConnector.createProof(localIdentity, id, ProofTypes.DataIntegrityProof, document);
|
|
265
324
|
CLIDisplay.spinnerStop();
|
|
266
325
|
if (opts.console) {
|
|
267
|
-
CLIDisplay.
|
|
268
|
-
CLIDisplay.value(I18n.formatMessage("commands.proof-create.labels.value"), proofValue);
|
|
326
|
+
CLIDisplay.json(proof);
|
|
269
327
|
CLIDisplay.break();
|
|
270
328
|
}
|
|
271
329
|
if (Is.stringValue(opts?.json)) {
|
|
272
|
-
await CLIUtils.writeJsonFile(opts.json,
|
|
330
|
+
await CLIUtils.writeJsonFile(opts.json, proof, opts.mergeJson);
|
|
273
331
|
}
|
|
274
332
|
if (Is.stringValue(opts?.env)) {
|
|
275
|
-
await CLIUtils.writeEnvFile(opts.env, [`
|
|
333
|
+
await CLIUtils.writeEnvFile(opts.env, [`DID_PROOF='${JSON.stringify(proof)}'`], opts.mergeEnv);
|
|
276
334
|
}
|
|
277
335
|
CLIDisplay.done();
|
|
278
336
|
}
|
|
@@ -289,10 +347,8 @@ function buildCommandProofVerify() {
|
|
|
289
347
|
.name("proof-verify")
|
|
290
348
|
.summary(I18n.formatMessage("commands.proof-verify.summary"))
|
|
291
349
|
.description(I18n.formatMessage("commands.proof-verify.description"))
|
|
292
|
-
.requiredOption(I18n.formatMessage("commands.proof-verify.options.
|
|
293
|
-
.requiredOption(I18n.formatMessage("commands.proof-verify.options.
|
|
294
|
-
.requiredOption(I18n.formatMessage("commands.proof-verify.options.type.param"), I18n.formatMessage("commands.proof-verify.options.type.description"))
|
|
295
|
-
.requiredOption(I18n.formatMessage("commands.proof-verify.options.value.param"), I18n.formatMessage("commands.proof-verify.options.value.description"));
|
|
350
|
+
.requiredOption(I18n.formatMessage("commands.proof-verify.options.document-filename.param"), I18n.formatMessage("commands.proof-verify.options.document-filename.description"))
|
|
351
|
+
.requiredOption(I18n.formatMessage("commands.proof-verify.options.proof-filename.param"), I18n.formatMessage("commands.proof-verify.options.proof-filename.description"));
|
|
296
352
|
CLIOptions.output(command, {
|
|
297
353
|
noConsole: true,
|
|
298
354
|
json: true,
|
|
@@ -301,7 +357,11 @@ function buildCommandProofVerify() {
|
|
|
301
357
|
mergeEnv: true
|
|
302
358
|
});
|
|
303
359
|
command
|
|
360
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
361
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
362
|
+
.default(IdentityConnectorTypes.Iota))
|
|
304
363
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
364
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
305
365
|
.action(actionCommandProofVerify);
|
|
306
366
|
return command;
|
|
307
367
|
}
|
|
@@ -309,44 +369,42 @@ function buildCommandProofVerify() {
|
|
|
309
369
|
* Action the proof verify command.
|
|
310
370
|
* @param opts The options for the command.
|
|
311
371
|
* @param opts.id The id of the verification method to use for the credential.
|
|
312
|
-
* @param opts.
|
|
313
|
-
* @param opts.
|
|
314
|
-
* @param opts.
|
|
372
|
+
* @param opts.documentFilename The data to verify the proof for.
|
|
373
|
+
* @param opts.proofFilename The proof value.
|
|
374
|
+
* @param opts.connector The connector to perform the operations with.
|
|
315
375
|
* @param opts.node The node URL.
|
|
376
|
+
* @param opts.network The network to use for connector.
|
|
316
377
|
*/
|
|
317
378
|
async function actionCommandProofVerify(opts) {
|
|
318
|
-
const
|
|
319
|
-
const
|
|
320
|
-
const type = CLIParam.stringValue("type", opts.type);
|
|
321
|
-
const value = CLIParam.hexBase64("value", opts.value);
|
|
379
|
+
const documentFilename = path.resolve(CLIParam.stringValue("document-filename", opts.documentFilename));
|
|
380
|
+
const proofFilename = path.resolve(CLIParam.stringValue("proof-filename", opts.proofFilename));
|
|
322
381
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
382
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
383
|
+
? CLIParam.stringValue("network", opts.network)
|
|
384
|
+
: undefined;
|
|
385
|
+
CLIDisplay.value(I18n.formatMessage("commands.proof-verify.labels.documentFilename"), documentFilename);
|
|
386
|
+
CLIDisplay.value(I18n.formatMessage("commands.proof-verify.labels.proofFilename"), proofFilename);
|
|
326
387
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
388
|
+
if (Is.stringValue(network)) {
|
|
389
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
390
|
+
}
|
|
327
391
|
CLIDisplay.break();
|
|
328
392
|
setupVault();
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
nodes: [nodeEndpoint],
|
|
333
|
-
localPow: true
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
});
|
|
337
|
-
WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
338
|
-
const iotaIdentityConnector = new IotaIdentityConnector({
|
|
339
|
-
config: {
|
|
340
|
-
clientOptions: {
|
|
341
|
-
nodes: [nodeEndpoint],
|
|
342
|
-
localPow: true
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
});
|
|
393
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);
|
|
394
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
395
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network }, opts.connector);
|
|
346
396
|
CLIDisplay.task(I18n.formatMessage("commands.proof-verify.progress.verifyingProof"));
|
|
347
397
|
CLIDisplay.break();
|
|
348
398
|
CLIDisplay.spinnerStart();
|
|
349
|
-
const
|
|
399
|
+
const document = await CLIUtils.readJsonFile(documentFilename);
|
|
400
|
+
if (Is.undefined(document)) {
|
|
401
|
+
throw new GeneralError("commands", "commands.proof-verify.documentJsonFileNotFound");
|
|
402
|
+
}
|
|
403
|
+
const proof = await CLIUtils.readJsonFile(proofFilename);
|
|
404
|
+
if (Is.undefined(proof)) {
|
|
405
|
+
throw new GeneralError("commands", "commands.proof-verify.proofJsonFileNotFound");
|
|
406
|
+
}
|
|
407
|
+
const isVerified = await identityConnector.verifyProof(document, proof);
|
|
350
408
|
CLIDisplay.spinnerStop();
|
|
351
409
|
if (opts.console) {
|
|
352
410
|
CLIDisplay.value(I18n.formatMessage("commands.proof-verify.labels.isVerified"), isVerified);
|
|
@@ -386,7 +444,11 @@ function buildCommandServiceAdd() {
|
|
|
386
444
|
mergeEnv: true
|
|
387
445
|
});
|
|
388
446
|
command
|
|
447
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
448
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
449
|
+
.default(IdentityConnectorTypes.Iota))
|
|
389
450
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
451
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
390
452
|
.option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
391
453
|
.action(actionCommandServiceAdd);
|
|
392
454
|
return command;
|
|
@@ -399,6 +461,7 @@ function buildCommandServiceAdd() {
|
|
|
399
461
|
* @param opts.id The id of the service to add.
|
|
400
462
|
* @param opts.type The type of the service to add.
|
|
401
463
|
* @param opts.endpoint The service endpoint.
|
|
464
|
+
* @param opts.connector The connector to perform the operations with.
|
|
402
465
|
* @param opts.node The node URL.
|
|
403
466
|
* @param opts.explorer The explorer URL.
|
|
404
467
|
*/
|
|
@@ -409,12 +472,18 @@ async function actionCommandServiceAdd(opts) {
|
|
|
409
472
|
const type = CLIParam.stringValue("type", opts.type);
|
|
410
473
|
const endpoint = CLIParam.url("endpoint", opts.endpoint);
|
|
411
474
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
475
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
476
|
+
? CLIParam.stringValue("network", opts.network)
|
|
477
|
+
: undefined;
|
|
412
478
|
const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
|
|
413
479
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.did"), did);
|
|
414
480
|
CLIDisplay.value(I18n.formatMessage("commands.service-add.labels.serviceId"), id);
|
|
415
481
|
CLIDisplay.value(I18n.formatMessage("commands.service-add.labels.serviceType"), type);
|
|
416
482
|
CLIDisplay.value(I18n.formatMessage("commands.service-add.labels.serviceEndpoint"), endpoint);
|
|
417
483
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
484
|
+
if (Is.stringValue(network)) {
|
|
485
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
486
|
+
}
|
|
418
487
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
|
|
419
488
|
CLIDisplay.break();
|
|
420
489
|
setupVault();
|
|
@@ -422,29 +491,13 @@ async function actionCommandServiceAdd(opts) {
|
|
|
422
491
|
const localIdentity = "local";
|
|
423
492
|
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
424
493
|
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
|
|
425
|
-
const
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
nodes: [nodeEndpoint],
|
|
429
|
-
localPow: true
|
|
430
|
-
},
|
|
431
|
-
vaultSeedId
|
|
432
|
-
}
|
|
433
|
-
});
|
|
434
|
-
WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
435
|
-
const iotaIdentityConnector = new IotaIdentityConnector({
|
|
436
|
-
config: {
|
|
437
|
-
clientOptions: {
|
|
438
|
-
nodes: [nodeEndpoint],
|
|
439
|
-
localPow: true
|
|
440
|
-
},
|
|
441
|
-
vaultSeedId
|
|
442
|
-
}
|
|
443
|
-
});
|
|
494
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
|
|
495
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
496
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
|
|
444
497
|
CLIDisplay.task(I18n.formatMessage("commands.service-add.progress.addingService"));
|
|
445
498
|
CLIDisplay.break();
|
|
446
499
|
CLIDisplay.spinnerStart();
|
|
447
|
-
const service = await
|
|
500
|
+
const service = await identityConnector.addService(localIdentity, did, id, type, endpoint);
|
|
448
501
|
CLIDisplay.spinnerStop();
|
|
449
502
|
if (Is.stringValue(opts?.json)) {
|
|
450
503
|
await CLIUtils.writeJsonFile(opts.json, service, opts.mergeJson);
|
|
@@ -456,7 +509,7 @@ async function actionCommandServiceAdd(opts) {
|
|
|
456
509
|
`DID_SERVICE_ENDPOINT="${service.serviceEndpoint}"`
|
|
457
510
|
], opts.mergeEnv);
|
|
458
511
|
}
|
|
459
|
-
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${
|
|
512
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${IotaStardustIdentityUtils.didToAddress(did)}?tab=DID`);
|
|
460
513
|
CLIDisplay.break();
|
|
461
514
|
CLIDisplay.done();
|
|
462
515
|
}
|
|
@@ -483,7 +536,11 @@ function buildCommandServiceRemove() {
|
|
|
483
536
|
mergeEnv: true
|
|
484
537
|
});
|
|
485
538
|
command
|
|
539
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
540
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
541
|
+
.default(IdentityConnectorTypes.Iota))
|
|
486
542
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
543
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
487
544
|
.option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
488
545
|
.action(actionCommandServiceRemove);
|
|
489
546
|
return command;
|
|
@@ -493,16 +550,24 @@ function buildCommandServiceRemove() {
|
|
|
493
550
|
* @param opts The options for the command.
|
|
494
551
|
* @param opts.seed The private key for the controller.
|
|
495
552
|
* @param opts.id The id of the service to remove.
|
|
553
|
+
* @param opts.connector The connector to perform the operations with.
|
|
496
554
|
* @param opts.node The node URL.
|
|
555
|
+
* @param opts.network The network to use for connector.
|
|
497
556
|
* @param opts.explorer The explorer URL.
|
|
498
557
|
*/
|
|
499
558
|
async function actionCommandServiceRemove(opts) {
|
|
500
559
|
const seed = CLIParam.hexBase64("seed", opts.seed);
|
|
501
560
|
const id = CLIParam.stringValue("id", opts.id);
|
|
502
561
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
562
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
563
|
+
? CLIParam.stringValue("network", opts.network)
|
|
564
|
+
: undefined;
|
|
503
565
|
const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
|
|
504
566
|
CLIDisplay.value(I18n.formatMessage("commands.service-remove.labels.serviceId"), id);
|
|
505
567
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
568
|
+
if (Is.stringValue(network)) {
|
|
569
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
570
|
+
}
|
|
506
571
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
|
|
507
572
|
CLIDisplay.break();
|
|
508
573
|
setupVault();
|
|
@@ -510,31 +575,15 @@ async function actionCommandServiceRemove(opts) {
|
|
|
510
575
|
const localIdentity = "local";
|
|
511
576
|
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
512
577
|
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
|
|
513
|
-
const
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
nodes: [nodeEndpoint],
|
|
517
|
-
localPow: true
|
|
518
|
-
},
|
|
519
|
-
vaultSeedId
|
|
520
|
-
}
|
|
521
|
-
});
|
|
522
|
-
WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
523
|
-
const iotaIdentityConnector = new IotaIdentityConnector({
|
|
524
|
-
config: {
|
|
525
|
-
clientOptions: {
|
|
526
|
-
nodes: [nodeEndpoint],
|
|
527
|
-
localPow: true
|
|
528
|
-
},
|
|
529
|
-
vaultSeedId
|
|
530
|
-
}
|
|
531
|
-
});
|
|
578
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
|
|
579
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
580
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
|
|
532
581
|
CLIDisplay.task(I18n.formatMessage("commands.service-remove.progress.removingService"));
|
|
533
582
|
CLIDisplay.break();
|
|
534
583
|
CLIDisplay.spinnerStart();
|
|
535
|
-
await
|
|
584
|
+
await identityConnector.removeService(localIdentity, id);
|
|
536
585
|
CLIDisplay.spinnerStop();
|
|
537
|
-
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${
|
|
586
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${IotaStardustIdentityUtils.didToAddress(DocumentHelper.parseId(id).id)}?tab=DID`);
|
|
538
587
|
CLIDisplay.break();
|
|
539
588
|
CLIDisplay.done();
|
|
540
589
|
}
|
|
@@ -554,8 +603,6 @@ function buildCommandVerifiableCredentialCreate() {
|
|
|
554
603
|
.requiredOption(I18n.formatMessage("commands.verifiable-credential-create.options.id.param"), I18n.formatMessage("commands.verifiable-credential-create.options.id.description"))
|
|
555
604
|
.requiredOption(I18n.formatMessage("commands.verifiable-credential-create.options.private-key.param"), I18n.formatMessage("commands.verifiable-credential-create.options.private-key.description"))
|
|
556
605
|
.option(I18n.formatMessage("commands.verifiable-credential-create.options.credential-id.param"), I18n.formatMessage("commands.verifiable-credential-create.options.credential-id.description"))
|
|
557
|
-
.option(I18n.formatMessage("commands.verifiable-credential-create.options.types.param"), I18n.formatMessage("commands.verifiable-credential-create.options.types.description"))
|
|
558
|
-
.option(I18n.formatMessage("commands.verifiable-credential-create.options.contexts.param"), I18n.formatMessage("commands.verifiable-credential-create.options.contexts.description"))
|
|
559
606
|
.requiredOption(I18n.formatMessage("commands.verifiable-credential-create.options.subject-json.param"), I18n.formatMessage("commands.verifiable-credential-create.options.subject-json.description"))
|
|
560
607
|
.option(I18n.formatMessage("commands.verifiable-credential-create.options.revocation-index.param"), I18n.formatMessage("commands.verifiable-credential-create.options.revocation-index.description"));
|
|
561
608
|
CLIOptions.output(command, {
|
|
@@ -566,7 +613,11 @@ function buildCommandVerifiableCredentialCreate() {
|
|
|
566
613
|
mergeEnv: true
|
|
567
614
|
});
|
|
568
615
|
command
|
|
616
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
617
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
618
|
+
.default(IdentityConnectorTypes.Iota))
|
|
569
619
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
620
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
570
621
|
.action(actionCommandVerifiableCredentialCreate);
|
|
571
622
|
return command;
|
|
572
623
|
}
|
|
@@ -576,60 +627,38 @@ function buildCommandVerifiableCredentialCreate() {
|
|
|
576
627
|
* @param opts.id The id of the verification method to use for the credential.
|
|
577
628
|
* @param opts.privateKey The private key for the verification method.
|
|
578
629
|
* @param opts.credentialId The id of the credential.
|
|
579
|
-
* @param opts.types The types for the credential.
|
|
580
630
|
* @param opts.subjectJson The JSON data for the subject.
|
|
581
|
-
* @param opts.contexts The contexts for the credential.
|
|
582
631
|
* @param opts.revocationIndex The revocation index for the credential.
|
|
632
|
+
* @param opts.connector The connector to perform the operations with.
|
|
583
633
|
* @param opts.node The node URL.
|
|
584
634
|
*/
|
|
585
635
|
async function actionCommandVerifiableCredentialCreate(opts) {
|
|
586
|
-
if (!Is.undefined(opts.types)) {
|
|
587
|
-
Guards.arrayValue("commands", "types", opts.types);
|
|
588
|
-
}
|
|
589
|
-
if (!Is.undefined(opts.contexts)) {
|
|
590
|
-
Guards.arrayValue("commands", "contexts", opts.contexts);
|
|
591
|
-
}
|
|
592
636
|
const id = CLIParam.stringValue("id", opts.id);
|
|
593
637
|
const privateKey = CLIParam.hexBase64("private-key", opts.privateKey);
|
|
594
638
|
const credentialId = CLIParam.stringValue("credential-id", opts.credentialId);
|
|
595
|
-
const types = opts.types;
|
|
596
|
-
const contexts = opts.contexts;
|
|
597
639
|
const subjectJson = path.resolve(CLIParam.stringValue("subject-json", opts.subjectJson));
|
|
598
640
|
const revocationIndex = Coerce.number(opts.revocationIndex);
|
|
599
641
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
642
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
643
|
+
? CLIParam.stringValue("network", opts.network)
|
|
644
|
+
: undefined;
|
|
600
645
|
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.verificationMethodId"), id);
|
|
601
646
|
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.credentialId"), credentialId);
|
|
602
|
-
if (Is.arrayValue(types)) {
|
|
603
|
-
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.types"), types.join(","));
|
|
604
|
-
}
|
|
605
|
-
if (Is.arrayValue(contexts)) {
|
|
606
|
-
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.contexts"), contexts.join(","));
|
|
607
|
-
}
|
|
608
647
|
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.subjectJson"), subjectJson);
|
|
609
648
|
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.revocationIndex"), revocationIndex);
|
|
610
649
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
650
|
+
if (Is.stringValue(network)) {
|
|
651
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
652
|
+
}
|
|
611
653
|
CLIDisplay.break();
|
|
612
654
|
setupVault();
|
|
613
655
|
const localIdentity = "local";
|
|
656
|
+
const vmParts = DocumentHelper.parseId(id);
|
|
614
657
|
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
615
|
-
await vaultConnector.addKey(`${localIdentity}/${
|
|
616
|
-
const
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
nodes: [nodeEndpoint],
|
|
620
|
-
localPow: true
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
});
|
|
624
|
-
WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
625
|
-
const iotaIdentityConnector = new IotaIdentityConnector({
|
|
626
|
-
config: {
|
|
627
|
-
clientOptions: {
|
|
628
|
-
nodes: [nodeEndpoint],
|
|
629
|
-
localPow: true
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
});
|
|
658
|
+
await vaultConnector.addKey(`${localIdentity}/${vmParts.fragment}`, VaultKeyType.Ed25519, privateKey, new Uint8Array());
|
|
659
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);
|
|
660
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
661
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network }, opts.connector);
|
|
633
662
|
CLIDisplay.task(I18n.formatMessage("commands.verifiable-credential-create.progress.loadingSubjectData"));
|
|
634
663
|
CLIDisplay.break();
|
|
635
664
|
const jsonData = await CLIUtils.readJsonFile(subjectJson);
|
|
@@ -639,7 +668,7 @@ async function actionCommandVerifiableCredentialCreate(opts) {
|
|
|
639
668
|
CLIDisplay.task(I18n.formatMessage("commands.verifiable-credential-create.progress.creatingVerifiableCredential"));
|
|
640
669
|
CLIDisplay.break();
|
|
641
670
|
CLIDisplay.spinnerStart();
|
|
642
|
-
const verifiableCredential = await
|
|
671
|
+
const verifiableCredential = await identityConnector.createVerifiableCredential(localIdentity, id, credentialId, jsonData, revocationIndex);
|
|
643
672
|
CLIDisplay.spinnerStop();
|
|
644
673
|
if (opts.console) {
|
|
645
674
|
CLIDisplay.section(I18n.formatMessage("commands.verifiable-credential-create.labels.verifiableCredential"));
|
|
@@ -672,7 +701,11 @@ function buildCommandVerifiableCredentialRevoke() {
|
|
|
672
701
|
.requiredOption(I18n.formatMessage("commands.verifiable-credential-revoke.options.did.param"), I18n.formatMessage("commands.verifiable-credential-revoke.options.did.description"))
|
|
673
702
|
.requiredOption(I18n.formatMessage("commands.verifiable-credential-revoke.options.revocation-index.param"), I18n.formatMessage("commands.verifiable-credential-revoke.options.revocation-index.description"));
|
|
674
703
|
command
|
|
704
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
705
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
706
|
+
.default(IdentityConnectorTypes.Iota))
|
|
675
707
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
708
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
676
709
|
.action(actionCommandVerifiableCredentialRevoke);
|
|
677
710
|
return command;
|
|
678
711
|
}
|
|
@@ -682,45 +715,37 @@ function buildCommandVerifiableCredentialRevoke() {
|
|
|
682
715
|
* @param opts.seed The seed to generate the private key for the controller.
|
|
683
716
|
* @param opts.did The id of the document to revoke the index.
|
|
684
717
|
* @param opts.revocationIndex The revocation index for the credential.
|
|
718
|
+
* @param opts.connector The connector to perform the operations with.
|
|
685
719
|
* @param opts.node The node URL.
|
|
720
|
+
* @param opts.network The network to use for connector.
|
|
686
721
|
*/
|
|
687
722
|
async function actionCommandVerifiableCredentialRevoke(opts) {
|
|
688
723
|
const seed = CLIParam.hexBase64("seed", opts.seed);
|
|
689
724
|
const did = CLIParam.stringValue("did", opts.did);
|
|
690
725
|
const revocationIndex = CLIParam.integer("revocation-index", opts.revocationIndex);
|
|
691
726
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
727
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
728
|
+
? CLIParam.stringValue("network", opts.network)
|
|
729
|
+
: undefined;
|
|
692
730
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.did"), did);
|
|
693
731
|
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-revoke.labels.revocationIndex"), revocationIndex);
|
|
694
732
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
733
|
+
if (Is.stringValue(network)) {
|
|
734
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
735
|
+
}
|
|
695
736
|
CLIDisplay.break();
|
|
696
737
|
setupVault();
|
|
697
738
|
const vaultSeedId = "local-seed";
|
|
698
739
|
const localIdentity = "local";
|
|
699
740
|
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
700
741
|
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
|
|
701
|
-
const
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
nodes: [nodeEndpoint],
|
|
705
|
-
localPow: true
|
|
706
|
-
},
|
|
707
|
-
vaultSeedId
|
|
708
|
-
}
|
|
709
|
-
});
|
|
710
|
-
WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
711
|
-
const iotaIdentityConnector = new IotaIdentityConnector({
|
|
712
|
-
config: {
|
|
713
|
-
clientOptions: {
|
|
714
|
-
nodes: [nodeEndpoint],
|
|
715
|
-
localPow: true
|
|
716
|
-
},
|
|
717
|
-
vaultSeedId
|
|
718
|
-
}
|
|
719
|
-
});
|
|
742
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
|
|
743
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
744
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
|
|
720
745
|
CLIDisplay.task(I18n.formatMessage("commands.verifiable-credential-revoke.progress.revokingCredential"));
|
|
721
746
|
CLIDisplay.break();
|
|
722
747
|
CLIDisplay.spinnerStart();
|
|
723
|
-
await
|
|
748
|
+
await identityConnector.revokeVerifiableCredentials(localIdentity, did, [revocationIndex]);
|
|
724
749
|
CLIDisplay.spinnerStop();
|
|
725
750
|
CLIDisplay.done();
|
|
726
751
|
}
|
|
@@ -741,7 +766,11 @@ function buildCommandVerifiableCredentialUnrevoke() {
|
|
|
741
766
|
.requiredOption(I18n.formatMessage("commands.verifiable-credential-unrevoke.options.did.param"), I18n.formatMessage("commands.verifiable-credential-unrevoke.options.did.description"))
|
|
742
767
|
.requiredOption(I18n.formatMessage("commands.verifiable-credential-unrevoke.options.revocation-index.param"), I18n.formatMessage("commands.verifiable-credential-unrevoke.options.revocation-index.description"));
|
|
743
768
|
command
|
|
769
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
770
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
771
|
+
.default(IdentityConnectorTypes.Iota))
|
|
744
772
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
773
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
745
774
|
.action(actionCommandVerifiableCredentialUnrevoke);
|
|
746
775
|
return command;
|
|
747
776
|
}
|
|
@@ -751,45 +780,37 @@ function buildCommandVerifiableCredentialUnrevoke() {
|
|
|
751
780
|
* @param opts.seed The seed to generate the private key for the controller.
|
|
752
781
|
* @param opts.did The id of the document to unrevoke the index.
|
|
753
782
|
* @param opts.revocationIndex The revocation index for the credential.
|
|
783
|
+
* @param opts.connector The connector to perform the operations with.
|
|
754
784
|
* @param opts.node The node URL.
|
|
785
|
+
* @param opts.network The network to use for connector.
|
|
755
786
|
*/
|
|
756
787
|
async function actionCommandVerifiableCredentialUnrevoke(opts) {
|
|
757
788
|
const seed = CLIParam.hexBase64("seed", opts.seed);
|
|
758
789
|
const did = CLIParam.stringValue("did", opts.did);
|
|
759
790
|
const revocationIndex = CLIParam.integer("revocation-index", opts.revocationIndex);
|
|
760
791
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
792
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
793
|
+
? CLIParam.stringValue("network", opts.network)
|
|
794
|
+
: undefined;
|
|
761
795
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.did"), did);
|
|
762
796
|
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-unrevoke.labels.revocationIndex"), revocationIndex);
|
|
763
797
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
798
|
+
if (Is.stringValue(network)) {
|
|
799
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
800
|
+
}
|
|
764
801
|
CLIDisplay.break();
|
|
765
802
|
setupVault();
|
|
766
803
|
const vaultSeedId = "local-seed";
|
|
767
804
|
const localIdentity = "local";
|
|
768
805
|
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
769
806
|
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
|
|
770
|
-
const
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
nodes: [nodeEndpoint],
|
|
774
|
-
localPow: true
|
|
775
|
-
},
|
|
776
|
-
vaultSeedId
|
|
777
|
-
}
|
|
778
|
-
});
|
|
779
|
-
WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
780
|
-
const iotaIdentityConnector = new IotaIdentityConnector({
|
|
781
|
-
config: {
|
|
782
|
-
clientOptions: {
|
|
783
|
-
nodes: [nodeEndpoint],
|
|
784
|
-
localPow: true
|
|
785
|
-
},
|
|
786
|
-
vaultSeedId
|
|
787
|
-
}
|
|
788
|
-
});
|
|
807
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
|
|
808
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
809
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
|
|
789
810
|
CLIDisplay.task(I18n.formatMessage("commands.verifiable-credential-unrevoke.progress.unrevokingCredential"));
|
|
790
811
|
CLIDisplay.break();
|
|
791
812
|
CLIDisplay.spinnerStart();
|
|
792
|
-
await
|
|
813
|
+
await identityConnector.unrevokeVerifiableCredentials(localIdentity, did, [revocationIndex]);
|
|
793
814
|
CLIDisplay.spinnerStop();
|
|
794
815
|
CLIDisplay.done();
|
|
795
816
|
}
|
|
@@ -815,7 +836,11 @@ function buildCommandVerifiableCredentialVerify() {
|
|
|
815
836
|
mergeEnv: true
|
|
816
837
|
});
|
|
817
838
|
command
|
|
839
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
840
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
841
|
+
.default(IdentityConnectorTypes.Iota))
|
|
818
842
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
843
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
819
844
|
.action(actionCommandVerifiableCredentialVerify);
|
|
820
845
|
return command;
|
|
821
846
|
}
|
|
@@ -823,36 +848,29 @@ function buildCommandVerifiableCredentialVerify() {
|
|
|
823
848
|
* Action the verifiable credential verify command.
|
|
824
849
|
* @param opts The options for the command.
|
|
825
850
|
* @param opts.jwt The JSON web token for the verifiable credential.
|
|
851
|
+
* @param opts.connector The connector to perform the operations with.
|
|
826
852
|
* @param opts.node The node URL.
|
|
827
853
|
*/
|
|
828
854
|
async function actionCommandVerifiableCredentialVerify(opts) {
|
|
829
855
|
const jwt = CLIParam.stringValue("jwt", opts.jwt);
|
|
830
856
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
857
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
858
|
+
? CLIParam.stringValue("network", opts.network)
|
|
859
|
+
: undefined;
|
|
831
860
|
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-verify.labels.jwt"), jwt);
|
|
832
861
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
862
|
+
if (Is.stringValue(network)) {
|
|
863
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
864
|
+
}
|
|
833
865
|
CLIDisplay.break();
|
|
834
866
|
setupVault();
|
|
835
|
-
const
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
nodes: [nodeEndpoint],
|
|
839
|
-
localPow: true
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
});
|
|
843
|
-
WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
844
|
-
const iotaIdentityConnector = new IotaIdentityConnector({
|
|
845
|
-
config: {
|
|
846
|
-
clientOptions: {
|
|
847
|
-
nodes: [nodeEndpoint],
|
|
848
|
-
localPow: true
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
});
|
|
867
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);
|
|
868
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
869
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network }, opts.connector);
|
|
852
870
|
CLIDisplay.task(I18n.formatMessage("commands.verifiable-credential-verify.progress.verifyingCredential"));
|
|
853
871
|
CLIDisplay.break();
|
|
854
872
|
CLIDisplay.spinnerStart();
|
|
855
|
-
const verification = await
|
|
873
|
+
const verification = await identityConnector.checkVerifiableCredential(jwt);
|
|
856
874
|
const isVerified = Is.notEmpty(verification.verifiableCredential);
|
|
857
875
|
const isRevoked = verification.revoked;
|
|
858
876
|
CLIDisplay.spinnerStop();
|
|
@@ -899,7 +917,11 @@ function buildCommandVerificationMethodAdd() {
|
|
|
899
917
|
mergeEnv: true
|
|
900
918
|
});
|
|
901
919
|
command
|
|
920
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
921
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
922
|
+
.default(IdentityConnectorTypes.Iota))
|
|
902
923
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
924
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
903
925
|
.option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
904
926
|
.action(actionCommandVerificationMethodAdd);
|
|
905
927
|
return command;
|
|
@@ -911,6 +933,7 @@ function buildCommandVerificationMethodAdd() {
|
|
|
911
933
|
* @param opts.did The identity of the document to add to.
|
|
912
934
|
* @param opts.type The type of the verification method to add.
|
|
913
935
|
* @param opts.id The id of the verification method to add.
|
|
936
|
+
* @param opts.connector The connector to perform the operations with.
|
|
914
937
|
* @param opts.node The node URL.
|
|
915
938
|
* @param opts.explorer The explorer URL.
|
|
916
939
|
*/
|
|
@@ -919,6 +942,9 @@ async function actionCommandVerificationMethodAdd(opts) {
|
|
|
919
942
|
const did = CLIParam.stringValue("did", opts.did);
|
|
920
943
|
const type = CLIParam.stringValue("type", opts.type);
|
|
921
944
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
945
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
946
|
+
? CLIParam.stringValue("network", opts.network)
|
|
947
|
+
: undefined;
|
|
922
948
|
const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
|
|
923
949
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.did"), did);
|
|
924
950
|
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.verificationMethodType"), type);
|
|
@@ -926,6 +952,9 @@ async function actionCommandVerificationMethodAdd(opts) {
|
|
|
926
952
|
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.verificationMethodId"), opts?.id);
|
|
927
953
|
}
|
|
928
954
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
955
|
+
if (Is.stringValue(network)) {
|
|
956
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
957
|
+
}
|
|
929
958
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
|
|
930
959
|
CLIDisplay.break();
|
|
931
960
|
setupVault();
|
|
@@ -933,33 +962,20 @@ async function actionCommandVerificationMethodAdd(opts) {
|
|
|
933
962
|
const localIdentity = "local";
|
|
934
963
|
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
935
964
|
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
|
|
936
|
-
const
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
nodes: [nodeEndpoint],
|
|
940
|
-
localPow: true
|
|
941
|
-
},
|
|
942
|
-
vaultSeedId
|
|
943
|
-
}
|
|
944
|
-
});
|
|
945
|
-
WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
946
|
-
const iotaIdentityConnector = new IotaIdentityConnector({
|
|
947
|
-
config: {
|
|
948
|
-
clientOptions: {
|
|
949
|
-
nodes: [nodeEndpoint],
|
|
950
|
-
localPow: true
|
|
951
|
-
},
|
|
952
|
-
vaultSeedId
|
|
953
|
-
}
|
|
954
|
-
});
|
|
965
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
|
|
966
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
967
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
|
|
955
968
|
CLIDisplay.task(I18n.formatMessage("commands.verification-method-add.progress.addingVerificationMethod"));
|
|
956
969
|
CLIDisplay.break();
|
|
957
970
|
CLIDisplay.spinnerStart();
|
|
958
|
-
const verificationMethod = await
|
|
971
|
+
const verificationMethod = await identityConnector.addVerificationMethod(localIdentity, did, type, opts?.id);
|
|
959
972
|
CLIDisplay.spinnerStop();
|
|
960
|
-
const
|
|
973
|
+
const keyParts = DocumentHelper.parseId(verificationMethod.id);
|
|
974
|
+
const keyPair = await vaultConnector.getKey(`${localIdentity}/${keyParts.fragment}`);
|
|
961
975
|
const privateKey = Converter.bytesToBase64(keyPair.privateKey);
|
|
962
|
-
const publicKey =
|
|
976
|
+
const publicKey = Is.uint8Array(keyPair.publicKey)
|
|
977
|
+
? Converter.bytesToBase64(keyPair.publicKey)
|
|
978
|
+
: "";
|
|
963
979
|
if (opts.console) {
|
|
964
980
|
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.verificationMethodId"), verificationMethod.id);
|
|
965
981
|
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.privateKey"), privateKey);
|
|
@@ -976,7 +992,7 @@ async function actionCommandVerificationMethodAdd(opts) {
|
|
|
976
992
|
`DID_VERIFICATION_METHOD_PUBLIC_KEY="${publicKey}"`
|
|
977
993
|
], opts.mergeEnv);
|
|
978
994
|
}
|
|
979
|
-
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${
|
|
995
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${IotaStardustIdentityUtils.didToAddress(did)}?tab=DID`);
|
|
980
996
|
CLIDisplay.break();
|
|
981
997
|
CLIDisplay.done();
|
|
982
998
|
}
|
|
@@ -1003,7 +1019,11 @@ function buildCommandVerificationMethodRemove() {
|
|
|
1003
1019
|
mergeEnv: true
|
|
1004
1020
|
});
|
|
1005
1021
|
command
|
|
1022
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
1023
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
1024
|
+
.default(IdentityConnectorTypes.Iota))
|
|
1006
1025
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
1026
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
1007
1027
|
.option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
1008
1028
|
.action(actionCommandVerificationMethodRemove);
|
|
1009
1029
|
return command;
|
|
@@ -1013,16 +1033,24 @@ function buildCommandVerificationMethodRemove() {
|
|
|
1013
1033
|
* @param opts The options for the command.
|
|
1014
1034
|
* @param opts.seed The private key for the controller.
|
|
1015
1035
|
* @param opts.id The id of the verification method to remove.
|
|
1036
|
+
* @param opts.connector The connector to perform the operations with.
|
|
1016
1037
|
* @param opts.node The node URL.
|
|
1017
1038
|
* @param opts.explorer The explorer URL.
|
|
1039
|
+
* @param opts.network The network to use for connector.
|
|
1018
1040
|
*/
|
|
1019
1041
|
async function actionCommandVerificationMethodRemove(opts) {
|
|
1020
1042
|
const seed = CLIParam.hexBase64("seed", opts.seed);
|
|
1021
1043
|
const id = CLIParam.stringValue("id", opts.id);
|
|
1022
1044
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
1045
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
1046
|
+
? CLIParam.stringValue("network", opts.network)
|
|
1047
|
+
: undefined;
|
|
1023
1048
|
const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
|
|
1024
1049
|
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.verificationMethodId"), id);
|
|
1025
1050
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
1051
|
+
if (Is.stringValue(network)) {
|
|
1052
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
1053
|
+
}
|
|
1026
1054
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
|
|
1027
1055
|
CLIDisplay.break();
|
|
1028
1056
|
setupVault();
|
|
@@ -1030,31 +1058,15 @@ async function actionCommandVerificationMethodRemove(opts) {
|
|
|
1030
1058
|
const localIdentity = "local";
|
|
1031
1059
|
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
1032
1060
|
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
|
|
1033
|
-
const
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
nodes: [nodeEndpoint],
|
|
1037
|
-
localPow: true
|
|
1038
|
-
},
|
|
1039
|
-
vaultSeedId
|
|
1040
|
-
}
|
|
1041
|
-
});
|
|
1042
|
-
WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
1043
|
-
const iotaIdentityConnector = new IotaIdentityConnector({
|
|
1044
|
-
config: {
|
|
1045
|
-
clientOptions: {
|
|
1046
|
-
nodes: [nodeEndpoint],
|
|
1047
|
-
localPow: true
|
|
1048
|
-
},
|
|
1049
|
-
vaultSeedId
|
|
1050
|
-
}
|
|
1051
|
-
});
|
|
1061
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
|
|
1062
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
1063
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
|
|
1052
1064
|
CLIDisplay.task(I18n.formatMessage("commands.verification-method-remove.progress.removingVerificationMethod"));
|
|
1053
1065
|
CLIDisplay.break();
|
|
1054
1066
|
CLIDisplay.spinnerStart();
|
|
1055
|
-
await
|
|
1067
|
+
await identityConnector.removeVerificationMethod(localIdentity, id);
|
|
1056
1068
|
CLIDisplay.spinnerStop();
|
|
1057
|
-
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${
|
|
1069
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${IotaStardustIdentityUtils.didToAddress(DocumentHelper.parseId(id).id)}?tab=DID`);
|
|
1058
1070
|
CLIDisplay.break();
|
|
1059
1071
|
CLIDisplay.done();
|
|
1060
1072
|
}
|
|
@@ -1077,7 +1089,7 @@ class CLI extends CLIBase {
|
|
|
1077
1089
|
return this.execute({
|
|
1078
1090
|
title: "TWIN Identity",
|
|
1079
1091
|
appName: "twin-identity",
|
|
1080
|
-
version: "0.0.
|
|
1092
|
+
version: "0.0.1-next.41", // x-release-please-version
|
|
1081
1093
|
icon: "🌍",
|
|
1082
1094
|
supportsEnvFiles: true,
|
|
1083
1095
|
overrideOutputWidth: options?.overrideOutputWidth
|
|
@@ -1110,4 +1122,4 @@ class CLI extends CLIBase {
|
|
|
1110
1122
|
}
|
|
1111
1123
|
}
|
|
1112
1124
|
|
|
1113
|
-
export { CLI, actionCommandIdentityCreate, actionCommandIdentityResolve, actionCommandProofCreate, actionCommandProofVerify, actionCommandServiceAdd, actionCommandServiceRemove, actionCommandVerifiableCredentialCreate, actionCommandVerifiableCredentialRevoke, actionCommandVerifiableCredentialUnrevoke, actionCommandVerifiableCredentialVerify, actionCommandVerificationMethodAdd, actionCommandVerificationMethodRemove, buildCommandIdentityCreate, buildCommandIdentityResolve, buildCommandProofCreate, buildCommandProofVerify, buildCommandServiceAdd, buildCommandServiceRemove, buildCommandVerifiableCredentialCreate, buildCommandVerifiableCredentialRevoke, buildCommandVerifiableCredentialUnrevoke, buildCommandVerifiableCredentialVerify, buildCommandVerificationMethodAdd, buildCommandVerificationMethodRemove };
|
|
1125
|
+
export { CLI, IdentityConnectorTypes, actionCommandIdentityCreate, actionCommandIdentityResolve, actionCommandProofCreate, actionCommandProofVerify, actionCommandServiceAdd, actionCommandServiceRemove, actionCommandVerifiableCredentialCreate, actionCommandVerifiableCredentialRevoke, actionCommandVerifiableCredentialUnrevoke, actionCommandVerifiableCredentialVerify, actionCommandVerificationMethodAdd, actionCommandVerificationMethodRemove, buildCommandIdentityCreate, buildCommandIdentityResolve, buildCommandProofCreate, buildCommandProofVerify, buildCommandServiceAdd, buildCommandServiceRemove, buildCommandVerifiableCredentialCreate, buildCommandVerifiableCredentialRevoke, buildCommandVerifiableCredentialUnrevoke, buildCommandVerifiableCredentialVerify, buildCommandVerificationMethodAdd, buildCommandVerificationMethodRemove, setupIdentityConnector, setupVault };
|