@twin.org/identity-cli 0.0.1-next.9 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.js +0 -0
- package/dist/cjs/index.cjs +360 -271
- package/dist/esm/index.mjs +359 -275
- package/dist/locales/en.json +878 -779
- 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 +31 -0
- package/dist/types/commands/verifiableCredentialCreate.d.ts +4 -0
- 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 +3 -0
- package/dist/types/models/identityConnectorTypes.d.ts +13 -0
- package/dist/types/models/identityResolverConnectorTypes.d.ts +13 -0
- package/docs/changelog.md +308 -1
- package/docs/examples.md +14 -12
- package/docs/reference/classes/CLI.md +14 -8
- 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/setupIdentityResolverConnector.md +35 -0
- package/docs/reference/functions/setupVault.md +9 -0
- package/docs/reference/index.md +13 -0
- package/docs/reference/type-aliases/IdentityConnectorTypes.md +5 -0
- package/docs/reference/type-aliases/IdentityResolverConnectorTypes.md +5 -0
- package/docs/reference/variables/IdentityConnectorTypes.md +13 -0
- package/docs/reference/variables/IdentityResolverConnectorTypes.md +13 -0
- package/locales/en.json +39 -27
- package/package.json +21 -21
package/dist/esm/index.mjs
CHANGED
|
@@ -2,18 +2,44 @@ 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, Converter,
|
|
7
|
-
import { IotaIdentityConnector, IotaIdentityUtils } from '@twin.org/identity-connector-iota';
|
|
5
|
+
import { setupWalletConnector, buildCommandFaucet, buildCommandTransfer } from '@twin.org/wallet-cli';
|
|
6
|
+
import { I18n, Is, Converter, Urn, StringHelper, GeneralError, Coerce } from '@twin.org/core';
|
|
8
7
|
import { VaultConnectorFactory, VaultKeyType } from '@twin.org/vault-models';
|
|
9
|
-
import { IotaWalletConnector } from '@twin.org/wallet-connector-iota';
|
|
10
8
|
import { WalletConnectorFactory } from '@twin.org/wallet-models';
|
|
11
9
|
import { Command, Option } from 'commander';
|
|
12
10
|
import { MemoryEntityStorageConnector } from '@twin.org/entity-storage-connector-memory';
|
|
13
11
|
import { EntityStorageConnectorFactory } from '@twin.org/entity-storage-models';
|
|
12
|
+
import { IotaIdentityConnector, IotaIdentityResolverConnector } from '@twin.org/identity-connector-iota';
|
|
14
13
|
import { initSchema, EntityStorageVaultConnector } from '@twin.org/vault-connector-entity-storage';
|
|
15
14
|
import { DocumentHelper } from '@twin.org/identity-models';
|
|
16
|
-
import { DidVerificationMethodType } from '@twin.org/standards-w3c-did';
|
|
15
|
+
import { ProofTypes, DidVerificationMethodType } from '@twin.org/standards-w3c-did';
|
|
16
|
+
import { Jwk } from '@twin.org/web';
|
|
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
|
+
|
|
31
|
+
// Copyright 2024 IOTA Stiftung.
|
|
32
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
33
|
+
/**
|
|
34
|
+
* The identity resolver connector types.
|
|
35
|
+
*/
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
37
|
+
const IdentityResolverConnectorTypes = {
|
|
38
|
+
/**
|
|
39
|
+
* IOTA.
|
|
40
|
+
*/
|
|
41
|
+
Iota: "iota"
|
|
42
|
+
};
|
|
17
43
|
|
|
18
44
|
// Copyright 2024 IOTA Stiftung.
|
|
19
45
|
// SPDX-License-Identifier: Apache-2.0.
|
|
@@ -31,6 +57,48 @@ function setupVault() {
|
|
|
31
57
|
const vaultConnector = new EntityStorageVaultConnector();
|
|
32
58
|
VaultConnectorFactory.register("vault", () => vaultConnector);
|
|
33
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Setup the identity connector for use in the CLI commands.
|
|
62
|
+
* @param options The options for the identity connector.
|
|
63
|
+
* @param options.nodeEndpoint The node endpoint.
|
|
64
|
+
* @param options.network The network.
|
|
65
|
+
* @param options.addressIndex The wallet index.
|
|
66
|
+
* @param options.vaultSeedId The vault seed ID.
|
|
67
|
+
* @param connector The connector to use.
|
|
68
|
+
* @returns The identity connector.
|
|
69
|
+
*/
|
|
70
|
+
function setupIdentityConnector(options, connector) {
|
|
71
|
+
connector ??= IdentityConnectorTypes.Iota;
|
|
72
|
+
return new IotaIdentityConnector({
|
|
73
|
+
config: {
|
|
74
|
+
clientOptions: {
|
|
75
|
+
url: options.nodeEndpoint
|
|
76
|
+
},
|
|
77
|
+
network: options.network ?? "",
|
|
78
|
+
vaultSeedId: options.vaultSeedId,
|
|
79
|
+
walletAddressIndex: options.addressIndex
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Setup the identity resolver connector for use in the CLI commands.
|
|
85
|
+
* @param options The options for the identity connector.
|
|
86
|
+
* @param options.nodeEndpoint The node endpoint.
|
|
87
|
+
* @param options.network The network.
|
|
88
|
+
* @param connector The connector to use.
|
|
89
|
+
* @returns The identity connector.
|
|
90
|
+
*/
|
|
91
|
+
function setupIdentityResolverConnector(options, connector) {
|
|
92
|
+
connector ??= IdentityResolverConnectorTypes.Iota;
|
|
93
|
+
return new IotaIdentityResolverConnector({
|
|
94
|
+
config: {
|
|
95
|
+
clientOptions: {
|
|
96
|
+
url: options.nodeEndpoint
|
|
97
|
+
},
|
|
98
|
+
network: options.network ?? ""
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
34
102
|
|
|
35
103
|
// Copyright 2024 IOTA Stiftung.
|
|
36
104
|
// SPDX-License-Identifier: Apache-2.0.
|
|
@@ -44,7 +112,8 @@ function buildCommandIdentityCreate() {
|
|
|
44
112
|
.name("identity-create")
|
|
45
113
|
.summary(I18n.formatMessage("commands.identity-create.summary"))
|
|
46
114
|
.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"))
|
|
115
|
+
.requiredOption(I18n.formatMessage("commands.identity-create.options.seed.param"), I18n.formatMessage("commands.identity-create.options.seed.description"))
|
|
116
|
+
.option(I18n.formatMessage("commands.identity-create.options.addressIndex.param"), I18n.formatMessage("commands.identity-create.options.addressIndex.description"), "0");
|
|
48
117
|
CLIOptions.output(command, {
|
|
49
118
|
noConsole: true,
|
|
50
119
|
json: true,
|
|
@@ -53,7 +122,11 @@ function buildCommandIdentityCreate() {
|
|
|
53
122
|
mergeEnv: true
|
|
54
123
|
});
|
|
55
124
|
command
|
|
125
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
126
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
127
|
+
.default(IdentityConnectorTypes.Iota))
|
|
56
128
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
129
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
57
130
|
.option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
58
131
|
.action(actionCommandIdentityCreate);
|
|
59
132
|
return command;
|
|
@@ -62,44 +135,38 @@ function buildCommandIdentityCreate() {
|
|
|
62
135
|
* Action the identity create command.
|
|
63
136
|
* @param opts The options for the command.
|
|
64
137
|
* @param opts.seed The private key for the controller.
|
|
138
|
+
* @param opts.connector The connector to perform the operations with.
|
|
65
139
|
* @param opts.node The node URL.
|
|
140
|
+
* @param opts.network The network to use for connector.
|
|
66
141
|
* @param opts.explorer The explorer URL.
|
|
67
142
|
*/
|
|
68
143
|
async function actionCommandIdentityCreate(opts) {
|
|
69
144
|
const seed = CLIParam.hexBase64("seed", opts.seed);
|
|
70
145
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
146
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
147
|
+
? CLIParam.stringValue("network", opts.network)
|
|
148
|
+
: undefined;
|
|
71
149
|
const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
|
|
150
|
+
const addressIndex = CLIParam.integer("addressIndex", opts.addressIndex ?? "0", false, 0);
|
|
72
151
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
152
|
+
if (Is.stringValue(network)) {
|
|
153
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
154
|
+
}
|
|
73
155
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
|
|
156
|
+
CLIDisplay.value(I18n.formatMessage("commands.identity-create.labels.addressIndex"), addressIndex);
|
|
74
157
|
CLIDisplay.break();
|
|
75
158
|
setupVault();
|
|
76
159
|
const vaultSeedId = "local-seed";
|
|
77
160
|
const localIdentity = "local";
|
|
78
161
|
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
79
162
|
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
|
-
});
|
|
163
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
|
|
164
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
165
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, vaultSeedId, network, addressIndex }, opts.connector);
|
|
99
166
|
CLIDisplay.task(I18n.formatMessage("commands.identity-create.progress.creatingIdentity"));
|
|
100
167
|
CLIDisplay.break();
|
|
101
168
|
CLIDisplay.spinnerStart();
|
|
102
|
-
const document = await
|
|
169
|
+
const document = await identityConnector.createDocument(localIdentity);
|
|
103
170
|
CLIDisplay.spinnerStop();
|
|
104
171
|
if (opts.console) {
|
|
105
172
|
CLIDisplay.value(I18n.formatMessage("commands.identity-create.labels.identity"), document.id);
|
|
@@ -111,7 +178,12 @@ async function actionCommandIdentityCreate(opts) {
|
|
|
111
178
|
if (Is.stringValue(opts?.env)) {
|
|
112
179
|
await CLIUtils.writeEnvFile(opts.env, [`DID="${document.id}"`], opts.mergeEnv);
|
|
113
180
|
}
|
|
114
|
-
|
|
181
|
+
if (opts.connector === IdentityConnectorTypes.Iota) {
|
|
182
|
+
const didUrn = Urn.fromValidString(document.id);
|
|
183
|
+
const didParts = didUrn.parts();
|
|
184
|
+
const objectId = didParts[3];
|
|
185
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`);
|
|
186
|
+
}
|
|
115
187
|
CLIDisplay.break();
|
|
116
188
|
CLIDisplay.done();
|
|
117
189
|
}
|
|
@@ -137,8 +209,12 @@ function buildCommandIdentityResolve() {
|
|
|
137
209
|
mergeEnv: false
|
|
138
210
|
});
|
|
139
211
|
command
|
|
212
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
213
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
214
|
+
.default(IdentityConnectorTypes.Iota))
|
|
140
215
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
141
216
|
.option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
217
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
142
218
|
.action(actionCommandIdentityResolve);
|
|
143
219
|
return command;
|
|
144
220
|
}
|
|
@@ -146,39 +222,33 @@ function buildCommandIdentityResolve() {
|
|
|
146
222
|
* Action the identity resolve command.
|
|
147
223
|
* @param opts The options for the command.
|
|
148
224
|
* @param opts.did The identity to resolve.
|
|
225
|
+
* @param opts.connector The connector to perform the operations with.
|
|
149
226
|
* @param opts.node The node URL.
|
|
227
|
+
* @param opts.network The network to use for connector.
|
|
150
228
|
* @param opts.explorer The explorer URL.
|
|
151
229
|
*/
|
|
152
230
|
async function actionCommandIdentityResolve(opts) {
|
|
153
231
|
const did = CLIParam.stringValue("did", opts.did);
|
|
154
232
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
233
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
234
|
+
? CLIParam.stringValue("network", opts.network)
|
|
235
|
+
: undefined;
|
|
155
236
|
const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
|
|
156
237
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.did"), did);
|
|
157
238
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
239
|
+
if (Is.stringValue(network)) {
|
|
240
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
241
|
+
}
|
|
158
242
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
|
|
159
243
|
CLIDisplay.break();
|
|
160
244
|
setupVault();
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
nodes: [nodeEndpoint],
|
|
165
|
-
localPow: true
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
170
|
-
const iotaIdentityConnector = new IotaIdentityConnector({
|
|
171
|
-
config: {
|
|
172
|
-
clientOptions: {
|
|
173
|
-
nodes: [nodeEndpoint],
|
|
174
|
-
localPow: true
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
});
|
|
245
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);
|
|
246
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
247
|
+
const identityResolverConnector = setupIdentityResolverConnector({ nodeEndpoint, network }, opts.connector);
|
|
178
248
|
CLIDisplay.task(I18n.formatMessage("commands.identity-resolve.progress.resolvingIdentity"));
|
|
179
249
|
CLIDisplay.break();
|
|
180
250
|
CLIDisplay.spinnerStart();
|
|
181
|
-
const document = await
|
|
251
|
+
const document = await identityResolverConnector.resolveDocument(did);
|
|
182
252
|
CLIDisplay.spinnerStop();
|
|
183
253
|
if (opts.console) {
|
|
184
254
|
CLIDisplay.section(I18n.formatMessage("commands.identity-resolve.labels.didDocument"));
|
|
@@ -188,7 +258,12 @@ async function actionCommandIdentityResolve(opts) {
|
|
|
188
258
|
if (Is.stringValue(opts?.json)) {
|
|
189
259
|
await CLIUtils.writeJsonFile(opts.json, document, opts.mergeJson);
|
|
190
260
|
}
|
|
191
|
-
|
|
261
|
+
if (opts.connector === IdentityConnectorTypes.Iota) {
|
|
262
|
+
const didUrn = Urn.fromValidString(document.id);
|
|
263
|
+
const didParts = didUrn.parts();
|
|
264
|
+
const objectId = didParts[3];
|
|
265
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`);
|
|
266
|
+
}
|
|
192
267
|
CLIDisplay.break();
|
|
193
268
|
CLIDisplay.done();
|
|
194
269
|
}
|
|
@@ -207,7 +282,7 @@ function buildCommandProofCreate() {
|
|
|
207
282
|
.description(I18n.formatMessage("commands.proof-create.description"))
|
|
208
283
|
.requiredOption(I18n.formatMessage("commands.proof-create.options.id.param"), I18n.formatMessage("commands.proof-create.options.id.description"))
|
|
209
284
|
.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.
|
|
285
|
+
.requiredOption(I18n.formatMessage("commands.proof-create.options.document-filename.param"), I18n.formatMessage("commands.proof-create.options.document-filename.description"));
|
|
211
286
|
CLIOptions.output(command, {
|
|
212
287
|
noConsole: true,
|
|
213
288
|
json: true,
|
|
@@ -216,7 +291,11 @@ function buildCommandProofCreate() {
|
|
|
216
291
|
mergeEnv: true
|
|
217
292
|
});
|
|
218
293
|
command
|
|
294
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
295
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
296
|
+
.default(IdentityConnectorTypes.Iota))
|
|
219
297
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
298
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
220
299
|
.action(actionCommandProofCreate);
|
|
221
300
|
return command;
|
|
222
301
|
}
|
|
@@ -226,53 +305,51 @@ function buildCommandProofCreate() {
|
|
|
226
305
|
* @param opts.id The id of the verification method to use for the credential.
|
|
227
306
|
* @param opts.privateKey The private key for the verification method.
|
|
228
307
|
* @param opts.data The data to create the proof for.
|
|
308
|
+
* @param opts.connector The connector to perform the operations with.
|
|
229
309
|
* @param opts.node The node URL.
|
|
310
|
+
* @param opts.network The network to use for connector.
|
|
230
311
|
*/
|
|
231
312
|
async function actionCommandProofCreate(opts) {
|
|
232
313
|
const id = CLIParam.stringValue("id", opts.id);
|
|
233
314
|
const privateKey = CLIParam.hexBase64("private-key", opts.privateKey);
|
|
234
|
-
const
|
|
315
|
+
const documentFilename = path.resolve(CLIParam.stringValue("document-filename", opts.documentFilename));
|
|
235
316
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
317
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
318
|
+
? CLIParam.stringValue("network", opts.network)
|
|
319
|
+
: undefined;
|
|
236
320
|
CLIDisplay.value(I18n.formatMessage("commands.proof-create.labels.verificationMethodId"), id);
|
|
321
|
+
CLIDisplay.value(I18n.formatMessage("commands.proof-create.labels.documentFilename"), documentFilename);
|
|
237
322
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
323
|
+
if (Is.stringValue(network)) {
|
|
324
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
325
|
+
}
|
|
238
326
|
CLIDisplay.break();
|
|
239
327
|
setupVault();
|
|
240
328
|
const localIdentity = "local";
|
|
329
|
+
const vmParts = DocumentHelper.parseId(id);
|
|
241
330
|
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
|
-
});
|
|
331
|
+
await vaultConnector.addKey(`${localIdentity}/${vmParts.fragment}`, VaultKeyType.Ed25519, privateKey, new Uint8Array());
|
|
332
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);
|
|
333
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
334
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network }, opts.connector);
|
|
260
335
|
CLIDisplay.task(I18n.formatMessage("commands.proof-create.progress.creatingProof"));
|
|
261
336
|
CLIDisplay.break();
|
|
262
337
|
CLIDisplay.spinnerStart();
|
|
263
|
-
const
|
|
264
|
-
|
|
338
|
+
const document = await CLIUtils.readJsonFile(documentFilename);
|
|
339
|
+
if (Is.undefined(document)) {
|
|
340
|
+
throw new GeneralError("commands", "commands.proof-create.documentJsonFileNotFound");
|
|
341
|
+
}
|
|
342
|
+
const proof = await identityConnector.createProof(localIdentity, id, ProofTypes.DataIntegrityProof, document);
|
|
265
343
|
CLIDisplay.spinnerStop();
|
|
266
344
|
if (opts.console) {
|
|
267
|
-
CLIDisplay.
|
|
268
|
-
CLIDisplay.value(I18n.formatMessage("commands.proof-create.labels.value"), proofValue);
|
|
345
|
+
CLIDisplay.json(proof);
|
|
269
346
|
CLIDisplay.break();
|
|
270
347
|
}
|
|
271
348
|
if (Is.stringValue(opts?.json)) {
|
|
272
|
-
await CLIUtils.writeJsonFile(opts.json,
|
|
349
|
+
await CLIUtils.writeJsonFile(opts.json, proof, opts.mergeJson);
|
|
273
350
|
}
|
|
274
351
|
if (Is.stringValue(opts?.env)) {
|
|
275
|
-
await CLIUtils.writeEnvFile(opts.env, [`
|
|
352
|
+
await CLIUtils.writeEnvFile(opts.env, [`DID_PROOF='${JSON.stringify(proof)}'`], opts.mergeEnv);
|
|
276
353
|
}
|
|
277
354
|
CLIDisplay.done();
|
|
278
355
|
}
|
|
@@ -289,10 +366,8 @@ function buildCommandProofVerify() {
|
|
|
289
366
|
.name("proof-verify")
|
|
290
367
|
.summary(I18n.formatMessage("commands.proof-verify.summary"))
|
|
291
368
|
.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"));
|
|
369
|
+
.requiredOption(I18n.formatMessage("commands.proof-verify.options.document-filename.param"), I18n.formatMessage("commands.proof-verify.options.document-filename.description"))
|
|
370
|
+
.requiredOption(I18n.formatMessage("commands.proof-verify.options.proof-filename.param"), I18n.formatMessage("commands.proof-verify.options.proof-filename.description"));
|
|
296
371
|
CLIOptions.output(command, {
|
|
297
372
|
noConsole: true,
|
|
298
373
|
json: true,
|
|
@@ -301,7 +376,11 @@ function buildCommandProofVerify() {
|
|
|
301
376
|
mergeEnv: true
|
|
302
377
|
});
|
|
303
378
|
command
|
|
379
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
380
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
381
|
+
.default(IdentityConnectorTypes.Iota))
|
|
304
382
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
383
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
305
384
|
.action(actionCommandProofVerify);
|
|
306
385
|
return command;
|
|
307
386
|
}
|
|
@@ -309,44 +388,42 @@ function buildCommandProofVerify() {
|
|
|
309
388
|
* Action the proof verify command.
|
|
310
389
|
* @param opts The options for the command.
|
|
311
390
|
* @param opts.id The id of the verification method to use for the credential.
|
|
312
|
-
* @param opts.
|
|
313
|
-
* @param opts.
|
|
314
|
-
* @param opts.
|
|
391
|
+
* @param opts.documentFilename The data to verify the proof for.
|
|
392
|
+
* @param opts.proofFilename The proof value.
|
|
393
|
+
* @param opts.connector The connector to perform the operations with.
|
|
315
394
|
* @param opts.node The node URL.
|
|
395
|
+
* @param opts.network The network to use for connector.
|
|
316
396
|
*/
|
|
317
397
|
async function actionCommandProofVerify(opts) {
|
|
318
|
-
const
|
|
319
|
-
const
|
|
320
|
-
const type = CLIParam.stringValue("type", opts.type);
|
|
321
|
-
const value = CLIParam.hexBase64("value", opts.value);
|
|
398
|
+
const documentFilename = path.resolve(CLIParam.stringValue("document-filename", opts.documentFilename));
|
|
399
|
+
const proofFilename = path.resolve(CLIParam.stringValue("proof-filename", opts.proofFilename));
|
|
322
400
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
401
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
402
|
+
? CLIParam.stringValue("network", opts.network)
|
|
403
|
+
: undefined;
|
|
404
|
+
CLIDisplay.value(I18n.formatMessage("commands.proof-verify.labels.documentFilename"), documentFilename);
|
|
405
|
+
CLIDisplay.value(I18n.formatMessage("commands.proof-verify.labels.proofFilename"), proofFilename);
|
|
326
406
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
407
|
+
if (Is.stringValue(network)) {
|
|
408
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
409
|
+
}
|
|
327
410
|
CLIDisplay.break();
|
|
328
411
|
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
|
-
});
|
|
412
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);
|
|
413
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
414
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network }, opts.connector);
|
|
346
415
|
CLIDisplay.task(I18n.formatMessage("commands.proof-verify.progress.verifyingProof"));
|
|
347
416
|
CLIDisplay.break();
|
|
348
417
|
CLIDisplay.spinnerStart();
|
|
349
|
-
const
|
|
418
|
+
const document = await CLIUtils.readJsonFile(documentFilename);
|
|
419
|
+
if (Is.undefined(document)) {
|
|
420
|
+
throw new GeneralError("commands", "commands.proof-verify.documentJsonFileNotFound");
|
|
421
|
+
}
|
|
422
|
+
const proof = await CLIUtils.readJsonFile(proofFilename);
|
|
423
|
+
if (Is.undefined(proof)) {
|
|
424
|
+
throw new GeneralError("commands", "commands.proof-verify.proofJsonFileNotFound");
|
|
425
|
+
}
|
|
426
|
+
const isVerified = await identityConnector.verifyProof(document, proof);
|
|
350
427
|
CLIDisplay.spinnerStop();
|
|
351
428
|
if (opts.console) {
|
|
352
429
|
CLIDisplay.value(I18n.formatMessage("commands.proof-verify.labels.isVerified"), isVerified);
|
|
@@ -386,7 +463,11 @@ function buildCommandServiceAdd() {
|
|
|
386
463
|
mergeEnv: true
|
|
387
464
|
});
|
|
388
465
|
command
|
|
466
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
467
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
468
|
+
.default(IdentityConnectorTypes.Iota))
|
|
389
469
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
470
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
390
471
|
.option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
391
472
|
.action(actionCommandServiceAdd);
|
|
392
473
|
return command;
|
|
@@ -399,6 +480,7 @@ function buildCommandServiceAdd() {
|
|
|
399
480
|
* @param opts.id The id of the service to add.
|
|
400
481
|
* @param opts.type The type of the service to add.
|
|
401
482
|
* @param opts.endpoint The service endpoint.
|
|
483
|
+
* @param opts.connector The connector to perform the operations with.
|
|
402
484
|
* @param opts.node The node URL.
|
|
403
485
|
* @param opts.explorer The explorer URL.
|
|
404
486
|
*/
|
|
@@ -409,12 +491,18 @@ async function actionCommandServiceAdd(opts) {
|
|
|
409
491
|
const type = CLIParam.stringValue("type", opts.type);
|
|
410
492
|
const endpoint = CLIParam.url("endpoint", opts.endpoint);
|
|
411
493
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
494
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
495
|
+
? CLIParam.stringValue("network", opts.network)
|
|
496
|
+
: undefined;
|
|
412
497
|
const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
|
|
413
498
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.did"), did);
|
|
414
499
|
CLIDisplay.value(I18n.formatMessage("commands.service-add.labels.serviceId"), id);
|
|
415
500
|
CLIDisplay.value(I18n.formatMessage("commands.service-add.labels.serviceType"), type);
|
|
416
501
|
CLIDisplay.value(I18n.formatMessage("commands.service-add.labels.serviceEndpoint"), endpoint);
|
|
417
502
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
503
|
+
if (Is.stringValue(network)) {
|
|
504
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
505
|
+
}
|
|
418
506
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
|
|
419
507
|
CLIDisplay.break();
|
|
420
508
|
setupVault();
|
|
@@ -422,29 +510,13 @@ async function actionCommandServiceAdd(opts) {
|
|
|
422
510
|
const localIdentity = "local";
|
|
423
511
|
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
424
512
|
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
|
-
});
|
|
513
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
|
|
514
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
515
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
|
|
444
516
|
CLIDisplay.task(I18n.formatMessage("commands.service-add.progress.addingService"));
|
|
445
517
|
CLIDisplay.break();
|
|
446
518
|
CLIDisplay.spinnerStart();
|
|
447
|
-
const service = await
|
|
519
|
+
const service = await identityConnector.addService(localIdentity, did, id, type, endpoint);
|
|
448
520
|
CLIDisplay.spinnerStop();
|
|
449
521
|
if (Is.stringValue(opts?.json)) {
|
|
450
522
|
await CLIUtils.writeJsonFile(opts.json, service, opts.mergeJson);
|
|
@@ -456,7 +528,12 @@ async function actionCommandServiceAdd(opts) {
|
|
|
456
528
|
`DID_SERVICE_ENDPOINT="${service.serviceEndpoint}"`
|
|
457
529
|
], opts.mergeEnv);
|
|
458
530
|
}
|
|
459
|
-
|
|
531
|
+
if (opts.connector === IdentityConnectorTypes.Iota) {
|
|
532
|
+
const didUrn = Urn.fromValidString(did);
|
|
533
|
+
const didParts = didUrn.parts();
|
|
534
|
+
const objectId = didParts[3];
|
|
535
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`);
|
|
536
|
+
}
|
|
460
537
|
CLIDisplay.break();
|
|
461
538
|
CLIDisplay.done();
|
|
462
539
|
}
|
|
@@ -483,7 +560,11 @@ function buildCommandServiceRemove() {
|
|
|
483
560
|
mergeEnv: true
|
|
484
561
|
});
|
|
485
562
|
command
|
|
563
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
564
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
565
|
+
.default(IdentityConnectorTypes.Iota))
|
|
486
566
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
567
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
487
568
|
.option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
488
569
|
.action(actionCommandServiceRemove);
|
|
489
570
|
return command;
|
|
@@ -493,16 +574,24 @@ function buildCommandServiceRemove() {
|
|
|
493
574
|
* @param opts The options for the command.
|
|
494
575
|
* @param opts.seed The private key for the controller.
|
|
495
576
|
* @param opts.id The id of the service to remove.
|
|
577
|
+
* @param opts.connector The connector to perform the operations with.
|
|
496
578
|
* @param opts.node The node URL.
|
|
579
|
+
* @param opts.network The network to use for connector.
|
|
497
580
|
* @param opts.explorer The explorer URL.
|
|
498
581
|
*/
|
|
499
582
|
async function actionCommandServiceRemove(opts) {
|
|
500
583
|
const seed = CLIParam.hexBase64("seed", opts.seed);
|
|
501
584
|
const id = CLIParam.stringValue("id", opts.id);
|
|
502
585
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
586
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
587
|
+
? CLIParam.stringValue("network", opts.network)
|
|
588
|
+
: undefined;
|
|
503
589
|
const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
|
|
504
590
|
CLIDisplay.value(I18n.formatMessage("commands.service-remove.labels.serviceId"), id);
|
|
505
591
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
592
|
+
if (Is.stringValue(network)) {
|
|
593
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
594
|
+
}
|
|
506
595
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
|
|
507
596
|
CLIDisplay.break();
|
|
508
597
|
setupVault();
|
|
@@ -510,31 +599,21 @@ async function actionCommandServiceRemove(opts) {
|
|
|
510
599
|
const localIdentity = "local";
|
|
511
600
|
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
512
601
|
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
|
-
});
|
|
602
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
|
|
603
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
604
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
|
|
532
605
|
CLIDisplay.task(I18n.formatMessage("commands.service-remove.progress.removingService"));
|
|
533
606
|
CLIDisplay.break();
|
|
534
607
|
CLIDisplay.spinnerStart();
|
|
535
|
-
await
|
|
608
|
+
await identityConnector.removeService(localIdentity, id);
|
|
536
609
|
CLIDisplay.spinnerStop();
|
|
537
|
-
|
|
610
|
+
const did = DocumentHelper.parseId(id).id;
|
|
611
|
+
if (opts.connector === IdentityConnectorTypes.Iota) {
|
|
612
|
+
const didUrn = Urn.fromValidString(did);
|
|
613
|
+
const didParts = didUrn.parts();
|
|
614
|
+
const objectId = didParts[3];
|
|
615
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`);
|
|
616
|
+
}
|
|
538
617
|
CLIDisplay.break();
|
|
539
618
|
CLIDisplay.done();
|
|
540
619
|
}
|
|
@@ -564,7 +643,11 @@ function buildCommandVerifiableCredentialCreate() {
|
|
|
564
643
|
mergeEnv: true
|
|
565
644
|
});
|
|
566
645
|
command
|
|
646
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
647
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
648
|
+
.default(IdentityConnectorTypes.Iota))
|
|
567
649
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
650
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
568
651
|
.action(actionCommandVerifiableCredentialCreate);
|
|
569
652
|
return command;
|
|
570
653
|
}
|
|
@@ -576,6 +659,7 @@ function buildCommandVerifiableCredentialCreate() {
|
|
|
576
659
|
* @param opts.credentialId The id of the credential.
|
|
577
660
|
* @param opts.subjectJson The JSON data for the subject.
|
|
578
661
|
* @param opts.revocationIndex The revocation index for the credential.
|
|
662
|
+
* @param opts.connector The connector to perform the operations with.
|
|
579
663
|
* @param opts.node The node URL.
|
|
580
664
|
*/
|
|
581
665
|
async function actionCommandVerifiableCredentialCreate(opts) {
|
|
@@ -585,33 +669,26 @@ async function actionCommandVerifiableCredentialCreate(opts) {
|
|
|
585
669
|
const subjectJson = path.resolve(CLIParam.stringValue("subject-json", opts.subjectJson));
|
|
586
670
|
const revocationIndex = Coerce.number(opts.revocationIndex);
|
|
587
671
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
672
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
673
|
+
? CLIParam.stringValue("network", opts.network)
|
|
674
|
+
: undefined;
|
|
588
675
|
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.verificationMethodId"), id);
|
|
589
676
|
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.credentialId"), credentialId);
|
|
590
677
|
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.subjectJson"), subjectJson);
|
|
591
678
|
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.revocationIndex"), revocationIndex);
|
|
592
679
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
680
|
+
if (Is.stringValue(network)) {
|
|
681
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
682
|
+
}
|
|
593
683
|
CLIDisplay.break();
|
|
594
684
|
setupVault();
|
|
595
685
|
const localIdentity = "local";
|
|
686
|
+
const vmParts = DocumentHelper.parseId(id);
|
|
596
687
|
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
597
|
-
await vaultConnector.addKey(`${localIdentity}/${
|
|
598
|
-
const
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
nodes: [nodeEndpoint],
|
|
602
|
-
localPow: true
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
});
|
|
606
|
-
WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
607
|
-
const iotaIdentityConnector = new IotaIdentityConnector({
|
|
608
|
-
config: {
|
|
609
|
-
clientOptions: {
|
|
610
|
-
nodes: [nodeEndpoint],
|
|
611
|
-
localPow: true
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
});
|
|
688
|
+
await vaultConnector.addKey(`${localIdentity}/${vmParts.fragment}`, VaultKeyType.Ed25519, privateKey, new Uint8Array());
|
|
689
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);
|
|
690
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
691
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network }, opts.connector);
|
|
615
692
|
CLIDisplay.task(I18n.formatMessage("commands.verifiable-credential-create.progress.loadingSubjectData"));
|
|
616
693
|
CLIDisplay.break();
|
|
617
694
|
const jsonData = await CLIUtils.readJsonFile(subjectJson);
|
|
@@ -621,7 +698,7 @@ async function actionCommandVerifiableCredentialCreate(opts) {
|
|
|
621
698
|
CLIDisplay.task(I18n.formatMessage("commands.verifiable-credential-create.progress.creatingVerifiableCredential"));
|
|
622
699
|
CLIDisplay.break();
|
|
623
700
|
CLIDisplay.spinnerStart();
|
|
624
|
-
const verifiableCredential = await
|
|
701
|
+
const verifiableCredential = await identityConnector.createVerifiableCredential(localIdentity, id, credentialId, jsonData, revocationIndex);
|
|
625
702
|
CLIDisplay.spinnerStop();
|
|
626
703
|
if (opts.console) {
|
|
627
704
|
CLIDisplay.section(I18n.formatMessage("commands.verifiable-credential-create.labels.verifiableCredential"));
|
|
@@ -654,7 +731,11 @@ function buildCommandVerifiableCredentialRevoke() {
|
|
|
654
731
|
.requiredOption(I18n.formatMessage("commands.verifiable-credential-revoke.options.did.param"), I18n.formatMessage("commands.verifiable-credential-revoke.options.did.description"))
|
|
655
732
|
.requiredOption(I18n.formatMessage("commands.verifiable-credential-revoke.options.revocation-index.param"), I18n.formatMessage("commands.verifiable-credential-revoke.options.revocation-index.description"));
|
|
656
733
|
command
|
|
734
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
735
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
736
|
+
.default(IdentityConnectorTypes.Iota))
|
|
657
737
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
738
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
658
739
|
.action(actionCommandVerifiableCredentialRevoke);
|
|
659
740
|
return command;
|
|
660
741
|
}
|
|
@@ -664,45 +745,37 @@ function buildCommandVerifiableCredentialRevoke() {
|
|
|
664
745
|
* @param opts.seed The seed to generate the private key for the controller.
|
|
665
746
|
* @param opts.did The id of the document to revoke the index.
|
|
666
747
|
* @param opts.revocationIndex The revocation index for the credential.
|
|
748
|
+
* @param opts.connector The connector to perform the operations with.
|
|
667
749
|
* @param opts.node The node URL.
|
|
750
|
+
* @param opts.network The network to use for connector.
|
|
668
751
|
*/
|
|
669
752
|
async function actionCommandVerifiableCredentialRevoke(opts) {
|
|
670
753
|
const seed = CLIParam.hexBase64("seed", opts.seed);
|
|
671
754
|
const did = CLIParam.stringValue("did", opts.did);
|
|
672
755
|
const revocationIndex = CLIParam.integer("revocation-index", opts.revocationIndex);
|
|
673
756
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
757
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
758
|
+
? CLIParam.stringValue("network", opts.network)
|
|
759
|
+
: undefined;
|
|
674
760
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.did"), did);
|
|
675
761
|
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-revoke.labels.revocationIndex"), revocationIndex);
|
|
676
762
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
763
|
+
if (Is.stringValue(network)) {
|
|
764
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
765
|
+
}
|
|
677
766
|
CLIDisplay.break();
|
|
678
767
|
setupVault();
|
|
679
768
|
const vaultSeedId = "local-seed";
|
|
680
769
|
const localIdentity = "local";
|
|
681
770
|
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
682
771
|
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
|
|
683
|
-
const
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
nodes: [nodeEndpoint],
|
|
687
|
-
localPow: true
|
|
688
|
-
},
|
|
689
|
-
vaultSeedId
|
|
690
|
-
}
|
|
691
|
-
});
|
|
692
|
-
WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
693
|
-
const iotaIdentityConnector = new IotaIdentityConnector({
|
|
694
|
-
config: {
|
|
695
|
-
clientOptions: {
|
|
696
|
-
nodes: [nodeEndpoint],
|
|
697
|
-
localPow: true
|
|
698
|
-
},
|
|
699
|
-
vaultSeedId
|
|
700
|
-
}
|
|
701
|
-
});
|
|
772
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
|
|
773
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
774
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
|
|
702
775
|
CLIDisplay.task(I18n.formatMessage("commands.verifiable-credential-revoke.progress.revokingCredential"));
|
|
703
776
|
CLIDisplay.break();
|
|
704
777
|
CLIDisplay.spinnerStart();
|
|
705
|
-
await
|
|
778
|
+
await identityConnector.revokeVerifiableCredentials(localIdentity, did, [revocationIndex]);
|
|
706
779
|
CLIDisplay.spinnerStop();
|
|
707
780
|
CLIDisplay.done();
|
|
708
781
|
}
|
|
@@ -723,7 +796,11 @@ function buildCommandVerifiableCredentialUnrevoke() {
|
|
|
723
796
|
.requiredOption(I18n.formatMessage("commands.verifiable-credential-unrevoke.options.did.param"), I18n.formatMessage("commands.verifiable-credential-unrevoke.options.did.description"))
|
|
724
797
|
.requiredOption(I18n.formatMessage("commands.verifiable-credential-unrevoke.options.revocation-index.param"), I18n.formatMessage("commands.verifiable-credential-unrevoke.options.revocation-index.description"));
|
|
725
798
|
command
|
|
799
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
800
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
801
|
+
.default(IdentityConnectorTypes.Iota))
|
|
726
802
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
803
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
727
804
|
.action(actionCommandVerifiableCredentialUnrevoke);
|
|
728
805
|
return command;
|
|
729
806
|
}
|
|
@@ -733,45 +810,37 @@ function buildCommandVerifiableCredentialUnrevoke() {
|
|
|
733
810
|
* @param opts.seed The seed to generate the private key for the controller.
|
|
734
811
|
* @param opts.did The id of the document to unrevoke the index.
|
|
735
812
|
* @param opts.revocationIndex The revocation index for the credential.
|
|
813
|
+
* @param opts.connector The connector to perform the operations with.
|
|
736
814
|
* @param opts.node The node URL.
|
|
815
|
+
* @param opts.network The network to use for connector.
|
|
737
816
|
*/
|
|
738
817
|
async function actionCommandVerifiableCredentialUnrevoke(opts) {
|
|
739
818
|
const seed = CLIParam.hexBase64("seed", opts.seed);
|
|
740
819
|
const did = CLIParam.stringValue("did", opts.did);
|
|
741
820
|
const revocationIndex = CLIParam.integer("revocation-index", opts.revocationIndex);
|
|
742
821
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
822
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
823
|
+
? CLIParam.stringValue("network", opts.network)
|
|
824
|
+
: undefined;
|
|
743
825
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.did"), did);
|
|
744
826
|
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-unrevoke.labels.revocationIndex"), revocationIndex);
|
|
745
827
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
828
|
+
if (Is.stringValue(network)) {
|
|
829
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
830
|
+
}
|
|
746
831
|
CLIDisplay.break();
|
|
747
832
|
setupVault();
|
|
748
833
|
const vaultSeedId = "local-seed";
|
|
749
834
|
const localIdentity = "local";
|
|
750
835
|
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
751
836
|
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
|
|
752
|
-
const
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
nodes: [nodeEndpoint],
|
|
756
|
-
localPow: true
|
|
757
|
-
},
|
|
758
|
-
vaultSeedId
|
|
759
|
-
}
|
|
760
|
-
});
|
|
761
|
-
WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
762
|
-
const iotaIdentityConnector = new IotaIdentityConnector({
|
|
763
|
-
config: {
|
|
764
|
-
clientOptions: {
|
|
765
|
-
nodes: [nodeEndpoint],
|
|
766
|
-
localPow: true
|
|
767
|
-
},
|
|
768
|
-
vaultSeedId
|
|
769
|
-
}
|
|
770
|
-
});
|
|
837
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
|
|
838
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
839
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
|
|
771
840
|
CLIDisplay.task(I18n.formatMessage("commands.verifiable-credential-unrevoke.progress.unrevokingCredential"));
|
|
772
841
|
CLIDisplay.break();
|
|
773
842
|
CLIDisplay.spinnerStart();
|
|
774
|
-
await
|
|
843
|
+
await identityConnector.unrevokeVerifiableCredentials(localIdentity, did, [revocationIndex]);
|
|
775
844
|
CLIDisplay.spinnerStop();
|
|
776
845
|
CLIDisplay.done();
|
|
777
846
|
}
|
|
@@ -797,7 +866,11 @@ function buildCommandVerifiableCredentialVerify() {
|
|
|
797
866
|
mergeEnv: true
|
|
798
867
|
});
|
|
799
868
|
command
|
|
869
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
870
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
871
|
+
.default(IdentityConnectorTypes.Iota))
|
|
800
872
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
873
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
801
874
|
.action(actionCommandVerifiableCredentialVerify);
|
|
802
875
|
return command;
|
|
803
876
|
}
|
|
@@ -805,36 +878,29 @@ function buildCommandVerifiableCredentialVerify() {
|
|
|
805
878
|
* Action the verifiable credential verify command.
|
|
806
879
|
* @param opts The options for the command.
|
|
807
880
|
* @param opts.jwt The JSON web token for the verifiable credential.
|
|
881
|
+
* @param opts.connector The connector to perform the operations with.
|
|
808
882
|
* @param opts.node The node URL.
|
|
809
883
|
*/
|
|
810
884
|
async function actionCommandVerifiableCredentialVerify(opts) {
|
|
811
885
|
const jwt = CLIParam.stringValue("jwt", opts.jwt);
|
|
812
886
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
887
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
888
|
+
? CLIParam.stringValue("network", opts.network)
|
|
889
|
+
: undefined;
|
|
813
890
|
CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-verify.labels.jwt"), jwt);
|
|
814
891
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
892
|
+
if (Is.stringValue(network)) {
|
|
893
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
894
|
+
}
|
|
815
895
|
CLIDisplay.break();
|
|
816
896
|
setupVault();
|
|
817
|
-
const
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
nodes: [nodeEndpoint],
|
|
821
|
-
localPow: true
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
});
|
|
825
|
-
WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
826
|
-
const iotaIdentityConnector = new IotaIdentityConnector({
|
|
827
|
-
config: {
|
|
828
|
-
clientOptions: {
|
|
829
|
-
nodes: [nodeEndpoint],
|
|
830
|
-
localPow: true
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
});
|
|
897
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);
|
|
898
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
899
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network }, opts.connector);
|
|
834
900
|
CLIDisplay.task(I18n.formatMessage("commands.verifiable-credential-verify.progress.verifyingCredential"));
|
|
835
901
|
CLIDisplay.break();
|
|
836
902
|
CLIDisplay.spinnerStart();
|
|
837
|
-
const verification = await
|
|
903
|
+
const verification = await identityConnector.checkVerifiableCredential(jwt);
|
|
838
904
|
const isVerified = Is.notEmpty(verification.verifiableCredential);
|
|
839
905
|
const isRevoked = verification.revoked;
|
|
840
906
|
CLIDisplay.spinnerStop();
|
|
@@ -881,7 +947,11 @@ function buildCommandVerificationMethodAdd() {
|
|
|
881
947
|
mergeEnv: true
|
|
882
948
|
});
|
|
883
949
|
command
|
|
950
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
951
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
952
|
+
.default(IdentityConnectorTypes.Iota))
|
|
884
953
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
954
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
885
955
|
.option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
886
956
|
.action(actionCommandVerificationMethodAdd);
|
|
887
957
|
return command;
|
|
@@ -893,6 +963,7 @@ function buildCommandVerificationMethodAdd() {
|
|
|
893
963
|
* @param opts.did The identity of the document to add to.
|
|
894
964
|
* @param opts.type The type of the verification method to add.
|
|
895
965
|
* @param opts.id The id of the verification method to add.
|
|
966
|
+
* @param opts.connector The connector to perform the operations with.
|
|
896
967
|
* @param opts.node The node URL.
|
|
897
968
|
* @param opts.explorer The explorer URL.
|
|
898
969
|
*/
|
|
@@ -901,6 +972,9 @@ async function actionCommandVerificationMethodAdd(opts) {
|
|
|
901
972
|
const did = CLIParam.stringValue("did", opts.did);
|
|
902
973
|
const type = CLIParam.stringValue("type", opts.type);
|
|
903
974
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
975
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
976
|
+
? CLIParam.stringValue("network", opts.network)
|
|
977
|
+
: undefined;
|
|
904
978
|
const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
|
|
905
979
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.did"), did);
|
|
906
980
|
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.verificationMethodType"), type);
|
|
@@ -908,6 +982,9 @@ async function actionCommandVerificationMethodAdd(opts) {
|
|
|
908
982
|
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.verificationMethodId"), opts?.id);
|
|
909
983
|
}
|
|
910
984
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
985
|
+
if (Is.stringValue(network)) {
|
|
986
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
987
|
+
}
|
|
911
988
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
|
|
912
989
|
CLIDisplay.break();
|
|
913
990
|
setupVault();
|
|
@@ -915,50 +992,55 @@ async function actionCommandVerificationMethodAdd(opts) {
|
|
|
915
992
|
const localIdentity = "local";
|
|
916
993
|
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
917
994
|
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
|
|
918
|
-
const
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
nodes: [nodeEndpoint],
|
|
922
|
-
localPow: true
|
|
923
|
-
},
|
|
924
|
-
vaultSeedId
|
|
925
|
-
}
|
|
926
|
-
});
|
|
927
|
-
WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
928
|
-
const iotaIdentityConnector = new IotaIdentityConnector({
|
|
929
|
-
config: {
|
|
930
|
-
clientOptions: {
|
|
931
|
-
nodes: [nodeEndpoint],
|
|
932
|
-
localPow: true
|
|
933
|
-
},
|
|
934
|
-
vaultSeedId
|
|
935
|
-
}
|
|
936
|
-
});
|
|
995
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
|
|
996
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
997
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
|
|
937
998
|
CLIDisplay.task(I18n.formatMessage("commands.verification-method-add.progress.addingVerificationMethod"));
|
|
938
999
|
CLIDisplay.break();
|
|
939
1000
|
CLIDisplay.spinnerStart();
|
|
940
|
-
const verificationMethod = await
|
|
1001
|
+
const verificationMethod = await identityConnector.addVerificationMethod(localIdentity, did, type, opts?.id);
|
|
941
1002
|
CLIDisplay.spinnerStop();
|
|
942
|
-
const
|
|
943
|
-
const
|
|
944
|
-
const
|
|
1003
|
+
const keyParts = DocumentHelper.parseId(verificationMethod.id);
|
|
1004
|
+
const keyPair = await vaultConnector.getKey(`${localIdentity}/${keyParts.fragment}`);
|
|
1005
|
+
const privateKeyBase64 = Converter.bytesToBase64Url(keyPair.privateKey);
|
|
1006
|
+
const publicKeyBase64 = Is.uint8Array(keyPair.publicKey)
|
|
1007
|
+
? Converter.bytesToBase64Url(keyPair.publicKey)
|
|
1008
|
+
: "";
|
|
1009
|
+
const privateKeyHex = Converter.bytesToHex(keyPair.privateKey, true);
|
|
1010
|
+
const publicKeyHex = Is.uint8Array(keyPair.publicKey)
|
|
1011
|
+
? Converter.bytesToHex(keyPair.publicKey, true)
|
|
1012
|
+
: "";
|
|
1013
|
+
const jwk = await Jwk.fromEd25519Private(keyPair.privateKey);
|
|
1014
|
+
const kid = await Jwk.generateKid(jwk);
|
|
945
1015
|
if (opts.console) {
|
|
946
1016
|
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.verificationMethodId"), verificationMethod.id);
|
|
947
|
-
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.
|
|
948
|
-
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.
|
|
1017
|
+
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.kid"), kid);
|
|
1018
|
+
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.privateKeyBase64"), privateKeyBase64);
|
|
1019
|
+
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.publicKeyBase64"), publicKeyBase64);
|
|
1020
|
+
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.privateKeyHex"), privateKeyHex);
|
|
1021
|
+
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.publicKeyHex"), publicKeyHex);
|
|
949
1022
|
CLIDisplay.break();
|
|
950
1023
|
}
|
|
951
1024
|
if (Is.stringValue(opts?.json)) {
|
|
952
|
-
await CLIUtils.writeJsonFile(opts.json, {
|
|
1025
|
+
await CLIUtils.writeJsonFile(opts.json, {
|
|
1026
|
+
kid,
|
|
1027
|
+
...jwk
|
|
1028
|
+
}, opts.mergeJson);
|
|
953
1029
|
}
|
|
954
1030
|
if (Is.stringValue(opts?.env)) {
|
|
955
1031
|
await CLIUtils.writeEnvFile(opts.env, [
|
|
956
1032
|
`DID_VERIFICATION_METHOD_ID="${verificationMethod.id}"`,
|
|
957
|
-
`
|
|
958
|
-
`
|
|
1033
|
+
`DID_VERIFICATION_METHOD_KID="${kid}"`,
|
|
1034
|
+
`DID_VERIFICATION_METHOD_PRIVATE_KEY="${privateKeyHex}"`,
|
|
1035
|
+
`DID_VERIFICATION_METHOD_PUBLIC_KEY="${publicKeyHex}"`
|
|
959
1036
|
], opts.mergeEnv);
|
|
960
1037
|
}
|
|
961
|
-
|
|
1038
|
+
if (opts.connector === IdentityConnectorTypes.Iota) {
|
|
1039
|
+
const didUrn = Urn.fromValidString(did);
|
|
1040
|
+
const didParts = didUrn.parts();
|
|
1041
|
+
const objectId = didParts[3];
|
|
1042
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`);
|
|
1043
|
+
}
|
|
962
1044
|
CLIDisplay.break();
|
|
963
1045
|
CLIDisplay.done();
|
|
964
1046
|
}
|
|
@@ -985,7 +1067,11 @@ function buildCommandVerificationMethodRemove() {
|
|
|
985
1067
|
mergeEnv: true
|
|
986
1068
|
});
|
|
987
1069
|
command
|
|
1070
|
+
.addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
|
|
1071
|
+
.choices(Object.values(IdentityConnectorTypes))
|
|
1072
|
+
.default(IdentityConnectorTypes.Iota))
|
|
988
1073
|
.option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
1074
|
+
.option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
|
|
989
1075
|
.option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
990
1076
|
.action(actionCommandVerificationMethodRemove);
|
|
991
1077
|
return command;
|
|
@@ -995,16 +1081,24 @@ function buildCommandVerificationMethodRemove() {
|
|
|
995
1081
|
* @param opts The options for the command.
|
|
996
1082
|
* @param opts.seed The private key for the controller.
|
|
997
1083
|
* @param opts.id The id of the verification method to remove.
|
|
1084
|
+
* @param opts.connector The connector to perform the operations with.
|
|
998
1085
|
* @param opts.node The node URL.
|
|
999
1086
|
* @param opts.explorer The explorer URL.
|
|
1087
|
+
* @param opts.network The network to use for connector.
|
|
1000
1088
|
*/
|
|
1001
1089
|
async function actionCommandVerificationMethodRemove(opts) {
|
|
1002
1090
|
const seed = CLIParam.hexBase64("seed", opts.seed);
|
|
1003
1091
|
const id = CLIParam.stringValue("id", opts.id);
|
|
1004
1092
|
const nodeEndpoint = CLIParam.url("node", opts.node);
|
|
1093
|
+
const network = opts.connector === IdentityConnectorTypes.Iota
|
|
1094
|
+
? CLIParam.stringValue("network", opts.network)
|
|
1095
|
+
: undefined;
|
|
1005
1096
|
const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
|
|
1006
1097
|
CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.verificationMethodId"), id);
|
|
1007
1098
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
1099
|
+
if (Is.stringValue(network)) {
|
|
1100
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
|
|
1101
|
+
}
|
|
1008
1102
|
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
|
|
1009
1103
|
CLIDisplay.break();
|
|
1010
1104
|
setupVault();
|
|
@@ -1012,31 +1106,21 @@ async function actionCommandVerificationMethodRemove(opts) {
|
|
|
1012
1106
|
const localIdentity = "local";
|
|
1013
1107
|
const vaultConnector = VaultConnectorFactory.get("vault");
|
|
1014
1108
|
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
|
|
1015
|
-
const
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
nodes: [nodeEndpoint],
|
|
1019
|
-
localPow: true
|
|
1020
|
-
},
|
|
1021
|
-
vaultSeedId
|
|
1022
|
-
}
|
|
1023
|
-
});
|
|
1024
|
-
WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
1025
|
-
const iotaIdentityConnector = new IotaIdentityConnector({
|
|
1026
|
-
config: {
|
|
1027
|
-
clientOptions: {
|
|
1028
|
-
nodes: [nodeEndpoint],
|
|
1029
|
-
localPow: true
|
|
1030
|
-
},
|
|
1031
|
-
vaultSeedId
|
|
1032
|
-
}
|
|
1033
|
-
});
|
|
1109
|
+
const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
|
|
1110
|
+
WalletConnectorFactory.register("wallet", () => walletConnector);
|
|
1111
|
+
const identityConnector = setupIdentityConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
|
|
1034
1112
|
CLIDisplay.task(I18n.formatMessage("commands.verification-method-remove.progress.removingVerificationMethod"));
|
|
1035
1113
|
CLIDisplay.break();
|
|
1036
1114
|
CLIDisplay.spinnerStart();
|
|
1037
|
-
await
|
|
1115
|
+
await identityConnector.removeVerificationMethod(localIdentity, id);
|
|
1038
1116
|
CLIDisplay.spinnerStop();
|
|
1039
|
-
|
|
1117
|
+
const did = DocumentHelper.parseId(id).id;
|
|
1118
|
+
if (opts.connector === IdentityConnectorTypes.Iota) {
|
|
1119
|
+
const didUrn = Urn.fromValidString(did);
|
|
1120
|
+
const didParts = didUrn.parts();
|
|
1121
|
+
const objectId = didParts[3];
|
|
1122
|
+
CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`);
|
|
1123
|
+
}
|
|
1040
1124
|
CLIDisplay.break();
|
|
1041
1125
|
CLIDisplay.done();
|
|
1042
1126
|
}
|
|
@@ -1059,7 +1143,7 @@ class CLI extends CLIBase {
|
|
|
1059
1143
|
return this.execute({
|
|
1060
1144
|
title: "TWIN Identity",
|
|
1061
1145
|
appName: "twin-identity",
|
|
1062
|
-
version: "0.0.
|
|
1146
|
+
version: "0.0.1", // x-release-please-version
|
|
1063
1147
|
icon: "🌍",
|
|
1064
1148
|
supportsEnvFiles: true,
|
|
1065
1149
|
overrideOutputWidth: options?.overrideOutputWidth
|
|
@@ -1092,4 +1176,4 @@ class CLI extends CLIBase {
|
|
|
1092
1176
|
}
|
|
1093
1177
|
}
|
|
1094
1178
|
|
|
1095
|
-
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 };
|
|
1179
|
+
export { CLI, IdentityConnectorTypes, IdentityResolverConnectorTypes, 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, setupIdentityResolverConnector, setupVault };
|