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