@twin.org/identity-cli 0.0.1-next.10
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/LICENSE +201 -0
- package/README.md +21 -0
- package/bin/index.js +10 -0
- package/dist/cjs/index.cjs +1122 -0
- package/dist/esm/index.mjs +1095 -0
- package/dist/locales/en.json +780 -0
- package/dist/types/cli.d.ts +17 -0
- package/dist/types/commands/identityCreate.d.ts +19 -0
- package/dist/types/commands/identityResolve.d.ts +19 -0
- package/dist/types/commands/proofCreate.d.ts +21 -0
- package/dist/types/commands/proofVerify.d.ts +23 -0
- package/dist/types/commands/serviceAdd.d.ts +27 -0
- package/dist/types/commands/serviceRemove.d.ts +20 -0
- package/dist/types/commands/setupCommands.d.ts +4 -0
- package/dist/types/commands/verifiableCredentialCreate.d.ts +25 -0
- package/dist/types/commands/verifiableCredentialRevoke.d.ts +20 -0
- package/dist/types/commands/verifiableCredentialUnrevoke.d.ts +20 -0
- package/dist/types/commands/verifiableCredentialVerify.d.ts +17 -0
- package/dist/types/commands/verificationMethodAdd.d.ts +26 -0
- package/dist/types/commands/verificationMethodRemove.d.ts +20 -0
- package/dist/types/index.d.ts +13 -0
- package/docs/changelog.md +5 -0
- package/docs/examples.md +211 -0
- package/docs/reference/classes/CLI.md +53 -0
- package/docs/reference/functions/actionCommandIdentityCreate.md +15 -0
- package/docs/reference/functions/actionCommandIdentityResolve.md +15 -0
- package/docs/reference/functions/actionCommandProofCreate.md +15 -0
- package/docs/reference/functions/actionCommandProofVerify.md +15 -0
- package/docs/reference/functions/actionCommandServiceAdd.md +15 -0
- package/docs/reference/functions/actionCommandServiceRemove.md +31 -0
- package/docs/reference/functions/actionCommandVerifiableCredentialCreate.md +15 -0
- package/docs/reference/functions/actionCommandVerifiableCredentialRevoke.md +31 -0
- package/docs/reference/functions/actionCommandVerifiableCredentialUnrevoke.md +31 -0
- package/docs/reference/functions/actionCommandVerifiableCredentialVerify.md +15 -0
- package/docs/reference/functions/actionCommandVerificationMethodAdd.md +15 -0
- package/docs/reference/functions/actionCommandVerificationMethodRemove.md +31 -0
- package/docs/reference/functions/buildCommandIdentityCreate.md +11 -0
- package/docs/reference/functions/buildCommandIdentityResolve.md +11 -0
- package/docs/reference/functions/buildCommandProofCreate.md +11 -0
- package/docs/reference/functions/buildCommandProofVerify.md +11 -0
- package/docs/reference/functions/buildCommandServiceAdd.md +11 -0
- package/docs/reference/functions/buildCommandServiceRemove.md +11 -0
- package/docs/reference/functions/buildCommandVerifiableCredentialCreate.md +11 -0
- package/docs/reference/functions/buildCommandVerifiableCredentialRevoke.md +11 -0
- package/docs/reference/functions/buildCommandVerifiableCredentialUnrevoke.md +11 -0
- package/docs/reference/functions/buildCommandVerifiableCredentialVerify.md +11 -0
- package/docs/reference/functions/buildCommandVerificationMethodAdd.md +11 -0
- package/docs/reference/functions/buildCommandVerificationMethodRemove.md +11 -0
- package/docs/reference/index.md +32 -0
- package/locales/en.json +326 -0
- package/package.json +58 -0
|
@@ -0,0 +1,1122 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('node:path');
|
|
4
|
+
var node_url = require('node:url');
|
|
5
|
+
var cliCore = require('@twin.org/cli-core');
|
|
6
|
+
var cryptoCli = require('@twin.org/crypto-cli');
|
|
7
|
+
var walletCli = require('@twin.org/wallet-cli');
|
|
8
|
+
var core = require('@twin.org/core');
|
|
9
|
+
var identityConnectorIota = require('@twin.org/identity-connector-iota');
|
|
10
|
+
var vaultModels = require('@twin.org/vault-models');
|
|
11
|
+
var walletConnectorIota = require('@twin.org/wallet-connector-iota');
|
|
12
|
+
var walletModels = require('@twin.org/wallet-models');
|
|
13
|
+
var commander = require('commander');
|
|
14
|
+
var entityStorageConnectorMemory = require('@twin.org/entity-storage-connector-memory');
|
|
15
|
+
var entityStorageModels = require('@twin.org/entity-storage-models');
|
|
16
|
+
var vaultConnectorEntityStorage = require('@twin.org/vault-connector-entity-storage');
|
|
17
|
+
var identityModels = require('@twin.org/identity-models');
|
|
18
|
+
var standardsW3cDid = require('@twin.org/standards-w3c-did');
|
|
19
|
+
|
|
20
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
21
|
+
// Copyright 2024 IOTA Stiftung.
|
|
22
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
23
|
+
/**
|
|
24
|
+
* Setup the vault for use in the CLI commands.
|
|
25
|
+
*/
|
|
26
|
+
function setupVault() {
|
|
27
|
+
vaultConnectorEntityStorage.initSchema();
|
|
28
|
+
entityStorageModels.EntityStorageConnectorFactory.register("vault-key", () => new entityStorageConnectorMemory.MemoryEntityStorageConnector({
|
|
29
|
+
entitySchema: "VaultKey"
|
|
30
|
+
}));
|
|
31
|
+
entityStorageModels.EntityStorageConnectorFactory.register("vault-secret", () => new entityStorageConnectorMemory.MemoryEntityStorageConnector({
|
|
32
|
+
entitySchema: "VaultSecret"
|
|
33
|
+
}));
|
|
34
|
+
const vaultConnector = new vaultConnectorEntityStorage.EntityStorageVaultConnector();
|
|
35
|
+
vaultModels.VaultConnectorFactory.register("vault", () => vaultConnector);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Copyright 2024 IOTA Stiftung.
|
|
39
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
40
|
+
/**
|
|
41
|
+
* Build the identity create command for the CLI.
|
|
42
|
+
* @returns The command.
|
|
43
|
+
*/
|
|
44
|
+
function buildCommandIdentityCreate() {
|
|
45
|
+
const command = new commander.Command();
|
|
46
|
+
command
|
|
47
|
+
.name("identity-create")
|
|
48
|
+
.summary(core.I18n.formatMessage("commands.identity-create.summary"))
|
|
49
|
+
.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"));
|
|
51
|
+
cliCore.CLIOptions.output(command, {
|
|
52
|
+
noConsole: true,
|
|
53
|
+
json: true,
|
|
54
|
+
env: true,
|
|
55
|
+
mergeJson: true,
|
|
56
|
+
mergeEnv: true
|
|
57
|
+
});
|
|
58
|
+
command
|
|
59
|
+
.option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
60
|
+
.option(core.I18n.formatMessage("commands.common.options.explorer.param"), core.I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
61
|
+
.action(actionCommandIdentityCreate);
|
|
62
|
+
return command;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Action the identity create command.
|
|
66
|
+
* @param opts The options for the command.
|
|
67
|
+
* @param opts.seed The private key for the controller.
|
|
68
|
+
* @param opts.node The node URL.
|
|
69
|
+
* @param opts.explorer The explorer URL.
|
|
70
|
+
*/
|
|
71
|
+
async function actionCommandIdentityCreate(opts) {
|
|
72
|
+
const seed = cliCore.CLIParam.hexBase64("seed", opts.seed);
|
|
73
|
+
const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
|
|
74
|
+
const explorerEndpoint = cliCore.CLIParam.url("explorer", opts.explorer);
|
|
75
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
76
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
|
|
77
|
+
cliCore.CLIDisplay.break();
|
|
78
|
+
setupVault();
|
|
79
|
+
const vaultSeedId = "local-seed";
|
|
80
|
+
const localIdentity = "local";
|
|
81
|
+
const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
|
|
82
|
+
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, core.Converter.bytesToBase64(seed));
|
|
83
|
+
const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
|
|
84
|
+
config: {
|
|
85
|
+
clientOptions: {
|
|
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
|
+
});
|
|
102
|
+
cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.identity-create.progress.creatingIdentity"));
|
|
103
|
+
cliCore.CLIDisplay.break();
|
|
104
|
+
cliCore.CLIDisplay.spinnerStart();
|
|
105
|
+
const document = await iotaIdentityConnector.createDocument(localIdentity);
|
|
106
|
+
cliCore.CLIDisplay.spinnerStop();
|
|
107
|
+
if (opts.console) {
|
|
108
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.identity-create.labels.identity"), document.id);
|
|
109
|
+
cliCore.CLIDisplay.break();
|
|
110
|
+
}
|
|
111
|
+
if (core.Is.stringValue(opts?.json)) {
|
|
112
|
+
await cliCore.CLIUtils.writeJsonFile(opts.json, { did: document.id }, opts.mergeJson);
|
|
113
|
+
}
|
|
114
|
+
if (core.Is.stringValue(opts?.env)) {
|
|
115
|
+
await cliCore.CLIUtils.writeEnvFile(opts.env, [`DID="${document.id}"`], opts.mergeEnv);
|
|
116
|
+
}
|
|
117
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explore"), `${core.StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${identityConnectorIota.IotaIdentityUtils.didToAddress(document.id)}?tab=DID`);
|
|
118
|
+
cliCore.CLIDisplay.break();
|
|
119
|
+
cliCore.CLIDisplay.done();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Copyright 2024 IOTA Stiftung.
|
|
123
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
124
|
+
/**
|
|
125
|
+
* Build the identity resolve command for the CLI.
|
|
126
|
+
* @returns The command.
|
|
127
|
+
*/
|
|
128
|
+
function buildCommandIdentityResolve() {
|
|
129
|
+
const command = new commander.Command();
|
|
130
|
+
command
|
|
131
|
+
.name("identity-resolve")
|
|
132
|
+
.summary(core.I18n.formatMessage("commands.identity-resolve.summary"))
|
|
133
|
+
.description(core.I18n.formatMessage("commands.identity-resolve.description"))
|
|
134
|
+
.requiredOption(core.I18n.formatMessage("commands.identity-resolve.options.did.param"), core.I18n.formatMessage("commands.identity-resolve.options.did.description"));
|
|
135
|
+
cliCore.CLIOptions.output(command, {
|
|
136
|
+
noConsole: true,
|
|
137
|
+
json: true,
|
|
138
|
+
env: false,
|
|
139
|
+
mergeJson: true,
|
|
140
|
+
mergeEnv: false
|
|
141
|
+
});
|
|
142
|
+
command
|
|
143
|
+
.option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
144
|
+
.option(core.I18n.formatMessage("commands.common.options.explorer.param"), core.I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
145
|
+
.action(actionCommandIdentityResolve);
|
|
146
|
+
return command;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Action the identity resolve command.
|
|
150
|
+
* @param opts The options for the command.
|
|
151
|
+
* @param opts.did The identity to resolve.
|
|
152
|
+
* @param opts.node The node URL.
|
|
153
|
+
* @param opts.explorer The explorer URL.
|
|
154
|
+
*/
|
|
155
|
+
async function actionCommandIdentityResolve(opts) {
|
|
156
|
+
const did = cliCore.CLIParam.stringValue("did", opts.did);
|
|
157
|
+
const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
|
|
158
|
+
const explorerEndpoint = cliCore.CLIParam.url("explorer", opts.explorer);
|
|
159
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.did"), did);
|
|
160
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
161
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
|
|
162
|
+
cliCore.CLIDisplay.break();
|
|
163
|
+
setupVault();
|
|
164
|
+
const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
|
|
165
|
+
config: {
|
|
166
|
+
clientOptions: {
|
|
167
|
+
nodes: [nodeEndpoint],
|
|
168
|
+
localPow: true
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
walletModels.WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
173
|
+
const iotaIdentityConnector = new identityConnectorIota.IotaIdentityConnector({
|
|
174
|
+
config: {
|
|
175
|
+
clientOptions: {
|
|
176
|
+
nodes: [nodeEndpoint],
|
|
177
|
+
localPow: true
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.identity-resolve.progress.resolvingIdentity"));
|
|
182
|
+
cliCore.CLIDisplay.break();
|
|
183
|
+
cliCore.CLIDisplay.spinnerStart();
|
|
184
|
+
const document = await iotaIdentityConnector.resolveDocument(did);
|
|
185
|
+
cliCore.CLIDisplay.spinnerStop();
|
|
186
|
+
if (opts.console) {
|
|
187
|
+
cliCore.CLIDisplay.section(core.I18n.formatMessage("commands.identity-resolve.labels.didDocument"));
|
|
188
|
+
cliCore.CLIDisplay.json(document);
|
|
189
|
+
cliCore.CLIDisplay.break();
|
|
190
|
+
}
|
|
191
|
+
if (core.Is.stringValue(opts?.json)) {
|
|
192
|
+
await cliCore.CLIUtils.writeJsonFile(opts.json, document, opts.mergeJson);
|
|
193
|
+
}
|
|
194
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explore"), `${core.StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${identityConnectorIota.IotaIdentityUtils.didToAddress(document.id)}?tab=DID`);
|
|
195
|
+
cliCore.CLIDisplay.break();
|
|
196
|
+
cliCore.CLIDisplay.done();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Copyright 2024 IOTA Stiftung.
|
|
200
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
201
|
+
/**
|
|
202
|
+
* Build the proof create command for the CLI.
|
|
203
|
+
* @returns The command.
|
|
204
|
+
*/
|
|
205
|
+
function buildCommandProofCreate() {
|
|
206
|
+
const command = new commander.Command();
|
|
207
|
+
command
|
|
208
|
+
.name("proof-create")
|
|
209
|
+
.summary(core.I18n.formatMessage("commands.proof-create.summary"))
|
|
210
|
+
.description(core.I18n.formatMessage("commands.proof-create.description"))
|
|
211
|
+
.requiredOption(core.I18n.formatMessage("commands.proof-create.options.id.param"), core.I18n.formatMessage("commands.proof-create.options.id.description"))
|
|
212
|
+
.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.data.param"), core.I18n.formatMessage("commands.proof-create.options.data.description"));
|
|
214
|
+
cliCore.CLIOptions.output(command, {
|
|
215
|
+
noConsole: true,
|
|
216
|
+
json: true,
|
|
217
|
+
env: true,
|
|
218
|
+
mergeJson: true,
|
|
219
|
+
mergeEnv: true
|
|
220
|
+
});
|
|
221
|
+
command
|
|
222
|
+
.option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
223
|
+
.action(actionCommandProofCreate);
|
|
224
|
+
return command;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Action the proof create command.
|
|
228
|
+
* @param opts The options for the command.
|
|
229
|
+
* @param opts.id The id of the verification method to use for the credential.
|
|
230
|
+
* @param opts.privateKey The private key for the verification method.
|
|
231
|
+
* @param opts.data The data to create the proof for.
|
|
232
|
+
* @param opts.node The node URL.
|
|
233
|
+
*/
|
|
234
|
+
async function actionCommandProofCreate(opts) {
|
|
235
|
+
const id = cliCore.CLIParam.stringValue("id", opts.id);
|
|
236
|
+
const privateKey = cliCore.CLIParam.hexBase64("private-key", opts.privateKey);
|
|
237
|
+
const data = cliCore.CLIParam.hexBase64("data", opts.data);
|
|
238
|
+
const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
|
|
239
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.proof-create.labels.verificationMethodId"), id);
|
|
240
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
241
|
+
cliCore.CLIDisplay.break();
|
|
242
|
+
setupVault();
|
|
243
|
+
const localIdentity = "local";
|
|
244
|
+
const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
|
|
245
|
+
await vaultConnector.addKey(`${localIdentity}/${id}`, vaultModels.VaultKeyType.Ed25519, privateKey, new Uint8Array());
|
|
246
|
+
const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
|
|
247
|
+
config: {
|
|
248
|
+
clientOptions: {
|
|
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
|
+
});
|
|
263
|
+
cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.proof-create.progress.creatingProof"));
|
|
264
|
+
cliCore.CLIDisplay.break();
|
|
265
|
+
cliCore.CLIDisplay.spinnerStart();
|
|
266
|
+
const proof = await iotaIdentityConnector.createProof(localIdentity, id, data);
|
|
267
|
+
const proofValue = core.Converter.bytesToBase64(proof.value);
|
|
268
|
+
cliCore.CLIDisplay.spinnerStop();
|
|
269
|
+
if (opts.console) {
|
|
270
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.proof-create.labels.type"), proof.type);
|
|
271
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.proof-create.labels.value"), proofValue);
|
|
272
|
+
cliCore.CLIDisplay.break();
|
|
273
|
+
}
|
|
274
|
+
if (core.Is.stringValue(opts?.json)) {
|
|
275
|
+
await cliCore.CLIUtils.writeJsonFile(opts.json, { type: proof.type, value: proofValue }, opts.mergeJson);
|
|
276
|
+
}
|
|
277
|
+
if (core.Is.stringValue(opts?.env)) {
|
|
278
|
+
await cliCore.CLIUtils.writeEnvFile(opts.env, [`DID_PROOF_TYPE="${proof.type}"`, `DID_PROOF_VALUE="${proofValue}"`], opts.mergeEnv);
|
|
279
|
+
}
|
|
280
|
+
cliCore.CLIDisplay.done();
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Copyright 2024 IOTA Stiftung.
|
|
284
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
285
|
+
/**
|
|
286
|
+
* Build the proof verify command for the CLI.
|
|
287
|
+
* @returns The command.
|
|
288
|
+
*/
|
|
289
|
+
function buildCommandProofVerify() {
|
|
290
|
+
const command = new commander.Command();
|
|
291
|
+
command
|
|
292
|
+
.name("proof-verify")
|
|
293
|
+
.summary(core.I18n.formatMessage("commands.proof-verify.summary"))
|
|
294
|
+
.description(core.I18n.formatMessage("commands.proof-verify.description"))
|
|
295
|
+
.requiredOption(core.I18n.formatMessage("commands.proof-verify.options.id.param"), core.I18n.formatMessage("commands.proof-verify.options.id.description"))
|
|
296
|
+
.requiredOption(core.I18n.formatMessage("commands.proof-verify.options.data.param"), core.I18n.formatMessage("commands.proof-verify.options.data.description"))
|
|
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"));
|
|
299
|
+
cliCore.CLIOptions.output(command, {
|
|
300
|
+
noConsole: true,
|
|
301
|
+
json: true,
|
|
302
|
+
env: true,
|
|
303
|
+
mergeJson: true,
|
|
304
|
+
mergeEnv: true
|
|
305
|
+
});
|
|
306
|
+
command
|
|
307
|
+
.option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
308
|
+
.action(actionCommandProofVerify);
|
|
309
|
+
return command;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Action the proof verify command.
|
|
313
|
+
* @param opts The options for the command.
|
|
314
|
+
* @param opts.id The id of the verification method to use for the credential.
|
|
315
|
+
* @param opts.data The data to verify the proof for.
|
|
316
|
+
* @param opts.type The type of the proof.
|
|
317
|
+
* @param opts.value The proof value.
|
|
318
|
+
* @param opts.node The node URL.
|
|
319
|
+
*/
|
|
320
|
+
async function actionCommandProofVerify(opts) {
|
|
321
|
+
const id = cliCore.CLIParam.stringValue("id", opts.id);
|
|
322
|
+
const data = cliCore.CLIParam.hexBase64("data", opts.data);
|
|
323
|
+
const type = cliCore.CLIParam.stringValue("type", opts.type);
|
|
324
|
+
const value = cliCore.CLIParam.hexBase64("value", opts.value);
|
|
325
|
+
const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
|
|
326
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.proof-verify.labels.verificationMethodId"), id);
|
|
327
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.proof-verify.labels.type"), type);
|
|
328
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.proof-verify.labels.value"), core.Converter.bytesToBase64(value));
|
|
329
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
330
|
+
cliCore.CLIDisplay.break();
|
|
331
|
+
setupVault();
|
|
332
|
+
const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
|
|
333
|
+
config: {
|
|
334
|
+
clientOptions: {
|
|
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
|
+
});
|
|
349
|
+
cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.proof-verify.progress.verifyingProof"));
|
|
350
|
+
cliCore.CLIDisplay.break();
|
|
351
|
+
cliCore.CLIDisplay.spinnerStart();
|
|
352
|
+
const isVerified = await iotaIdentityConnector.verifyProof(id, data, type, value);
|
|
353
|
+
cliCore.CLIDisplay.spinnerStop();
|
|
354
|
+
if (opts.console) {
|
|
355
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.proof-verify.labels.isVerified"), isVerified);
|
|
356
|
+
cliCore.CLIDisplay.break();
|
|
357
|
+
}
|
|
358
|
+
if (core.Is.stringValue(opts?.json)) {
|
|
359
|
+
await cliCore.CLIUtils.writeJsonFile(opts.json, { isVerified }, opts.mergeJson);
|
|
360
|
+
}
|
|
361
|
+
if (core.Is.stringValue(opts?.env)) {
|
|
362
|
+
await cliCore.CLIUtils.writeEnvFile(opts.env, [`DID_PROOF_VERIFIED="${isVerified}"`], opts.mergeEnv);
|
|
363
|
+
}
|
|
364
|
+
cliCore.CLIDisplay.done();
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// Copyright 2024 IOTA Stiftung.
|
|
368
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
369
|
+
/**
|
|
370
|
+
* Build the service add command for the CLI.
|
|
371
|
+
* @returns The command.
|
|
372
|
+
*/
|
|
373
|
+
function buildCommandServiceAdd() {
|
|
374
|
+
const command = new commander.Command();
|
|
375
|
+
command
|
|
376
|
+
.name("service-add")
|
|
377
|
+
.summary(core.I18n.formatMessage("commands.service-add.summary"))
|
|
378
|
+
.description(core.I18n.formatMessage("commands.service-add.description"))
|
|
379
|
+
.requiredOption(core.I18n.formatMessage("commands.service-add.options.seed.param"), core.I18n.formatMessage("commands.service-add.options.seed.description"))
|
|
380
|
+
.requiredOption(core.I18n.formatMessage("commands.service-add.options.did.param"), core.I18n.formatMessage("commands.service-add.options.did.description"))
|
|
381
|
+
.requiredOption(core.I18n.formatMessage("commands.service-add.options.id.param"), core.I18n.formatMessage("commands.service-add.options.id.description"))
|
|
382
|
+
.requiredOption(core.I18n.formatMessage("commands.service-add.options.type.param"), core.I18n.formatMessage("commands.service-add.options.type.description"))
|
|
383
|
+
.requiredOption(core.I18n.formatMessage("commands.service-add.options.endpoint.param"), core.I18n.formatMessage("commands.service-add.options.endpoint.description"));
|
|
384
|
+
cliCore.CLIOptions.output(command, {
|
|
385
|
+
noConsole: true,
|
|
386
|
+
json: true,
|
|
387
|
+
env: true,
|
|
388
|
+
mergeJson: true,
|
|
389
|
+
mergeEnv: true
|
|
390
|
+
});
|
|
391
|
+
command
|
|
392
|
+
.option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
393
|
+
.option(core.I18n.formatMessage("commands.common.options.explorer.param"), core.I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
394
|
+
.action(actionCommandServiceAdd);
|
|
395
|
+
return command;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Action the service add command.
|
|
399
|
+
* @param opts The options for the command.
|
|
400
|
+
* @param opts.seed The private key for the controller.
|
|
401
|
+
* @param opts.did The identity of the document to add to.
|
|
402
|
+
* @param opts.id The id of the service to add.
|
|
403
|
+
* @param opts.type The type of the service to add.
|
|
404
|
+
* @param opts.endpoint The service endpoint.
|
|
405
|
+
* @param opts.node The node URL.
|
|
406
|
+
* @param opts.explorer The explorer URL.
|
|
407
|
+
*/
|
|
408
|
+
async function actionCommandServiceAdd(opts) {
|
|
409
|
+
const seed = cliCore.CLIParam.hexBase64("seed", opts.seed);
|
|
410
|
+
const did = cliCore.CLIParam.stringValue("did", opts.did);
|
|
411
|
+
const id = cliCore.CLIParam.stringValue("id", opts.id);
|
|
412
|
+
const type = cliCore.CLIParam.stringValue("type", opts.type);
|
|
413
|
+
const endpoint = cliCore.CLIParam.url("endpoint", opts.endpoint);
|
|
414
|
+
const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
|
|
415
|
+
const explorerEndpoint = cliCore.CLIParam.url("explorer", opts.explorer);
|
|
416
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.did"), did);
|
|
417
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.service-add.labels.serviceId"), id);
|
|
418
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.service-add.labels.serviceType"), type);
|
|
419
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.service-add.labels.serviceEndpoint"), endpoint);
|
|
420
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
421
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
|
|
422
|
+
cliCore.CLIDisplay.break();
|
|
423
|
+
setupVault();
|
|
424
|
+
const vaultSeedId = "local-seed";
|
|
425
|
+
const localIdentity = "local";
|
|
426
|
+
const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
|
|
427
|
+
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, core.Converter.bytesToBase64(seed));
|
|
428
|
+
const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
|
|
429
|
+
config: {
|
|
430
|
+
clientOptions: {
|
|
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
|
+
});
|
|
447
|
+
cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.service-add.progress.addingService"));
|
|
448
|
+
cliCore.CLIDisplay.break();
|
|
449
|
+
cliCore.CLIDisplay.spinnerStart();
|
|
450
|
+
const service = await iotaIdentityConnector.addService(localIdentity, did, id, type, endpoint);
|
|
451
|
+
cliCore.CLIDisplay.spinnerStop();
|
|
452
|
+
if (core.Is.stringValue(opts?.json)) {
|
|
453
|
+
await cliCore.CLIUtils.writeJsonFile(opts.json, service, opts.mergeJson);
|
|
454
|
+
}
|
|
455
|
+
if (core.Is.stringValue(opts?.env)) {
|
|
456
|
+
await cliCore.CLIUtils.writeEnvFile(opts.env, [
|
|
457
|
+
`DID_SERVICE_ID="${service.id}"`,
|
|
458
|
+
`DID_SERVICE_TYPE="${service.type}"`,
|
|
459
|
+
`DID_SERVICE_ENDPOINT="${service.serviceEndpoint}"`
|
|
460
|
+
], opts.mergeEnv);
|
|
461
|
+
}
|
|
462
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explore"), `${core.StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${identityConnectorIota.IotaIdentityUtils.didToAddress(did)}?tab=DID`);
|
|
463
|
+
cliCore.CLIDisplay.break();
|
|
464
|
+
cliCore.CLIDisplay.done();
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// Copyright 2024 IOTA Stiftung.
|
|
468
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
469
|
+
/**
|
|
470
|
+
* Build the service remove command for the CLI.
|
|
471
|
+
* @returns The command.
|
|
472
|
+
*/
|
|
473
|
+
function buildCommandServiceRemove() {
|
|
474
|
+
const command = new commander.Command();
|
|
475
|
+
command
|
|
476
|
+
.name("service-remove")
|
|
477
|
+
.summary(core.I18n.formatMessage("commands.service-remove.summary"))
|
|
478
|
+
.description(core.I18n.formatMessage("commands.service-remove.description"))
|
|
479
|
+
.requiredOption(core.I18n.formatMessage("commands.service-remove.options.seed.param"), core.I18n.formatMessage("commands.service-remove.options.seed.description"))
|
|
480
|
+
.requiredOption(core.I18n.formatMessage("commands.service-remove.options.id.param"), core.I18n.formatMessage("commands.service-remove.options.id.description"));
|
|
481
|
+
cliCore.CLIOptions.output(command, {
|
|
482
|
+
noConsole: true,
|
|
483
|
+
json: true,
|
|
484
|
+
env: true,
|
|
485
|
+
mergeJson: true,
|
|
486
|
+
mergeEnv: true
|
|
487
|
+
});
|
|
488
|
+
command
|
|
489
|
+
.option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
490
|
+
.option(core.I18n.formatMessage("commands.common.options.explorer.param"), core.I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
491
|
+
.action(actionCommandServiceRemove);
|
|
492
|
+
return command;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Action the service remove command.
|
|
496
|
+
* @param opts The options for the command.
|
|
497
|
+
* @param opts.seed The private key for the controller.
|
|
498
|
+
* @param opts.id The id of the service to remove.
|
|
499
|
+
* @param opts.node The node URL.
|
|
500
|
+
* @param opts.explorer The explorer URL.
|
|
501
|
+
*/
|
|
502
|
+
async function actionCommandServiceRemove(opts) {
|
|
503
|
+
const seed = cliCore.CLIParam.hexBase64("seed", opts.seed);
|
|
504
|
+
const id = cliCore.CLIParam.stringValue("id", opts.id);
|
|
505
|
+
const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
|
|
506
|
+
const explorerEndpoint = cliCore.CLIParam.url("explorer", opts.explorer);
|
|
507
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.service-remove.labels.serviceId"), id);
|
|
508
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
509
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
|
|
510
|
+
cliCore.CLIDisplay.break();
|
|
511
|
+
setupVault();
|
|
512
|
+
const vaultSeedId = "local-seed";
|
|
513
|
+
const localIdentity = "local";
|
|
514
|
+
const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
|
|
515
|
+
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, core.Converter.bytesToBase64(seed));
|
|
516
|
+
const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
|
|
517
|
+
config: {
|
|
518
|
+
clientOptions: {
|
|
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
|
+
});
|
|
535
|
+
cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.service-remove.progress.removingService"));
|
|
536
|
+
cliCore.CLIDisplay.break();
|
|
537
|
+
cliCore.CLIDisplay.spinnerStart();
|
|
538
|
+
await iotaIdentityConnector.removeService(localIdentity, id);
|
|
539
|
+
cliCore.CLIDisplay.spinnerStop();
|
|
540
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explore"), `${core.StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${identityConnectorIota.IotaIdentityUtils.didToAddress(identityModels.DocumentHelper.parse(id).id)}?tab=DID`);
|
|
541
|
+
cliCore.CLIDisplay.break();
|
|
542
|
+
cliCore.CLIDisplay.done();
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// Copyright 2024 IOTA Stiftung.
|
|
546
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
547
|
+
/**
|
|
548
|
+
* Build the verifiable credential create command for the CLI.
|
|
549
|
+
* @returns The command.
|
|
550
|
+
*/
|
|
551
|
+
function buildCommandVerifiableCredentialCreate() {
|
|
552
|
+
const command = new commander.Command();
|
|
553
|
+
command
|
|
554
|
+
.name("verifiable-credential-create")
|
|
555
|
+
.summary(core.I18n.formatMessage("commands.verifiable-credential-create.summary"))
|
|
556
|
+
.description(core.I18n.formatMessage("commands.verifiable-credential-create.description"))
|
|
557
|
+
.requiredOption(core.I18n.formatMessage("commands.verifiable-credential-create.options.id.param"), core.I18n.formatMessage("commands.verifiable-credential-create.options.id.description"))
|
|
558
|
+
.requiredOption(core.I18n.formatMessage("commands.verifiable-credential-create.options.private-key.param"), core.I18n.formatMessage("commands.verifiable-credential-create.options.private-key.description"))
|
|
559
|
+
.option(core.I18n.formatMessage("commands.verifiable-credential-create.options.credential-id.param"), core.I18n.formatMessage("commands.verifiable-credential-create.options.credential-id.description"))
|
|
560
|
+
.requiredOption(core.I18n.formatMessage("commands.verifiable-credential-create.options.subject-json.param"), core.I18n.formatMessage("commands.verifiable-credential-create.options.subject-json.description"))
|
|
561
|
+
.option(core.I18n.formatMessage("commands.verifiable-credential-create.options.revocation-index.param"), core.I18n.formatMessage("commands.verifiable-credential-create.options.revocation-index.description"));
|
|
562
|
+
cliCore.CLIOptions.output(command, {
|
|
563
|
+
noConsole: true,
|
|
564
|
+
json: true,
|
|
565
|
+
env: true,
|
|
566
|
+
mergeJson: true,
|
|
567
|
+
mergeEnv: true
|
|
568
|
+
});
|
|
569
|
+
command
|
|
570
|
+
.option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
571
|
+
.action(actionCommandVerifiableCredentialCreate);
|
|
572
|
+
return command;
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Action the verifiable credential create command.
|
|
576
|
+
* @param opts The options for the command.
|
|
577
|
+
* @param opts.id The id of the verification method to use for the credential.
|
|
578
|
+
* @param opts.privateKey The private key for the verification method.
|
|
579
|
+
* @param opts.credentialId The id of the credential.
|
|
580
|
+
* @param opts.subjectJson The JSON data for the subject.
|
|
581
|
+
* @param opts.revocationIndex The revocation index for the credential.
|
|
582
|
+
* @param opts.node The node URL.
|
|
583
|
+
*/
|
|
584
|
+
async function actionCommandVerifiableCredentialCreate(opts) {
|
|
585
|
+
const id = cliCore.CLIParam.stringValue("id", opts.id);
|
|
586
|
+
const privateKey = cliCore.CLIParam.hexBase64("private-key", opts.privateKey);
|
|
587
|
+
const credentialId = cliCore.CLIParam.stringValue("credential-id", opts.credentialId);
|
|
588
|
+
const subjectJson = path.resolve(cliCore.CLIParam.stringValue("subject-json", opts.subjectJson));
|
|
589
|
+
const revocationIndex = core.Coerce.number(opts.revocationIndex);
|
|
590
|
+
const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
|
|
591
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verifiable-credential-create.labels.verificationMethodId"), id);
|
|
592
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verifiable-credential-create.labels.credentialId"), credentialId);
|
|
593
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verifiable-credential-create.labels.subjectJson"), subjectJson);
|
|
594
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verifiable-credential-create.labels.revocationIndex"), revocationIndex);
|
|
595
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
596
|
+
cliCore.CLIDisplay.break();
|
|
597
|
+
setupVault();
|
|
598
|
+
const localIdentity = "local";
|
|
599
|
+
const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
|
|
600
|
+
await vaultConnector.addKey(`${localIdentity}/${id}`, vaultModels.VaultKeyType.Ed25519, privateKey, new Uint8Array());
|
|
601
|
+
const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
|
|
602
|
+
config: {
|
|
603
|
+
clientOptions: {
|
|
604
|
+
nodes: [nodeEndpoint],
|
|
605
|
+
localPow: true
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
walletModels.WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
610
|
+
const iotaIdentityConnector = new identityConnectorIota.IotaIdentityConnector({
|
|
611
|
+
config: {
|
|
612
|
+
clientOptions: {
|
|
613
|
+
nodes: [nodeEndpoint],
|
|
614
|
+
localPow: true
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.verifiable-credential-create.progress.loadingSubjectData"));
|
|
619
|
+
cliCore.CLIDisplay.break();
|
|
620
|
+
const jsonData = await cliCore.CLIUtils.readJsonFile(subjectJson);
|
|
621
|
+
if (core.Is.undefined(jsonData)) {
|
|
622
|
+
throw new core.GeneralError("commands", "commands.verifiable-credential-create.subjectJsonFileNotFound");
|
|
623
|
+
}
|
|
624
|
+
cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.verifiable-credential-create.progress.creatingVerifiableCredential"));
|
|
625
|
+
cliCore.CLIDisplay.break();
|
|
626
|
+
cliCore.CLIDisplay.spinnerStart();
|
|
627
|
+
const verifiableCredential = await iotaIdentityConnector.createVerifiableCredential(localIdentity, id, credentialId, jsonData, revocationIndex);
|
|
628
|
+
cliCore.CLIDisplay.spinnerStop();
|
|
629
|
+
if (opts.console) {
|
|
630
|
+
cliCore.CLIDisplay.section(core.I18n.formatMessage("commands.verifiable-credential-create.labels.verifiableCredential"));
|
|
631
|
+
cliCore.CLIDisplay.write(verifiableCredential.jwt);
|
|
632
|
+
cliCore.CLIDisplay.break();
|
|
633
|
+
cliCore.CLIDisplay.break();
|
|
634
|
+
}
|
|
635
|
+
if (core.Is.stringValue(opts?.json)) {
|
|
636
|
+
await cliCore.CLIUtils.writeJsonFile(opts.json, { verifiableCredentialJwt: verifiableCredential.jwt }, opts.mergeJson);
|
|
637
|
+
}
|
|
638
|
+
if (core.Is.stringValue(opts?.env)) {
|
|
639
|
+
await cliCore.CLIUtils.writeEnvFile(opts.env, [`DID_VERIFIABLE_CREDENTIAL_JWT="${verifiableCredential.jwt}"`], opts.mergeEnv);
|
|
640
|
+
}
|
|
641
|
+
cliCore.CLIDisplay.done();
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// Copyright 2024 IOTA Stiftung.
|
|
645
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
646
|
+
/**
|
|
647
|
+
* Build the verifiable credential revoke command for the CLI.
|
|
648
|
+
* @returns The command.
|
|
649
|
+
*/
|
|
650
|
+
function buildCommandVerifiableCredentialRevoke() {
|
|
651
|
+
const command = new commander.Command();
|
|
652
|
+
command
|
|
653
|
+
.name("verifiable-credential-revoke")
|
|
654
|
+
.summary(core.I18n.formatMessage("commands.verifiable-credential-revoke.summary"))
|
|
655
|
+
.description(core.I18n.formatMessage("commands.verifiable-credential-revoke.description"))
|
|
656
|
+
.requiredOption(core.I18n.formatMessage("commands.verifiable-credential-revoke.options.seed.param"), core.I18n.formatMessage("commands.verifiable-credential-revoke.options.seed.description"))
|
|
657
|
+
.requiredOption(core.I18n.formatMessage("commands.verifiable-credential-revoke.options.did.param"), core.I18n.formatMessage("commands.verifiable-credential-revoke.options.did.description"))
|
|
658
|
+
.requiredOption(core.I18n.formatMessage("commands.verifiable-credential-revoke.options.revocation-index.param"), core.I18n.formatMessage("commands.verifiable-credential-revoke.options.revocation-index.description"));
|
|
659
|
+
command
|
|
660
|
+
.option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
661
|
+
.action(actionCommandVerifiableCredentialRevoke);
|
|
662
|
+
return command;
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Action the verifiable credential revoke command.
|
|
666
|
+
* @param opts The options for the command.
|
|
667
|
+
* @param opts.seed The seed to generate the private key for the controller.
|
|
668
|
+
* @param opts.did The id of the document to revoke the index.
|
|
669
|
+
* @param opts.revocationIndex The revocation index for the credential.
|
|
670
|
+
* @param opts.node The node URL.
|
|
671
|
+
*/
|
|
672
|
+
async function actionCommandVerifiableCredentialRevoke(opts) {
|
|
673
|
+
const seed = cliCore.CLIParam.hexBase64("seed", opts.seed);
|
|
674
|
+
const did = cliCore.CLIParam.stringValue("did", opts.did);
|
|
675
|
+
const revocationIndex = cliCore.CLIParam.integer("revocation-index", opts.revocationIndex);
|
|
676
|
+
const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
|
|
677
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.did"), did);
|
|
678
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verifiable-credential-revoke.labels.revocationIndex"), revocationIndex);
|
|
679
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
680
|
+
cliCore.CLIDisplay.break();
|
|
681
|
+
setupVault();
|
|
682
|
+
const vaultSeedId = "local-seed";
|
|
683
|
+
const localIdentity = "local";
|
|
684
|
+
const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
|
|
685
|
+
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, core.Converter.bytesToBase64(seed));
|
|
686
|
+
const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
|
|
687
|
+
config: {
|
|
688
|
+
clientOptions: {
|
|
689
|
+
nodes: [nodeEndpoint],
|
|
690
|
+
localPow: true
|
|
691
|
+
},
|
|
692
|
+
vaultSeedId
|
|
693
|
+
}
|
|
694
|
+
});
|
|
695
|
+
walletModels.WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
696
|
+
const iotaIdentityConnector = new identityConnectorIota.IotaIdentityConnector({
|
|
697
|
+
config: {
|
|
698
|
+
clientOptions: {
|
|
699
|
+
nodes: [nodeEndpoint],
|
|
700
|
+
localPow: true
|
|
701
|
+
},
|
|
702
|
+
vaultSeedId
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.verifiable-credential-revoke.progress.revokingCredential"));
|
|
706
|
+
cliCore.CLIDisplay.break();
|
|
707
|
+
cliCore.CLIDisplay.spinnerStart();
|
|
708
|
+
await iotaIdentityConnector.revokeVerifiableCredentials(localIdentity, did, [revocationIndex]);
|
|
709
|
+
cliCore.CLIDisplay.spinnerStop();
|
|
710
|
+
cliCore.CLIDisplay.done();
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
// Copyright 2024 IOTA Stiftung.
|
|
714
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
715
|
+
/**
|
|
716
|
+
* Build the verifiable credential unrevoke command for the CLI.
|
|
717
|
+
* @returns The command.
|
|
718
|
+
*/
|
|
719
|
+
function buildCommandVerifiableCredentialUnrevoke() {
|
|
720
|
+
const command = new commander.Command();
|
|
721
|
+
command
|
|
722
|
+
.name("verifiable-credential-unrevoke")
|
|
723
|
+
.summary(core.I18n.formatMessage("commands.verifiable-credential-unrevoke.summary"))
|
|
724
|
+
.description(core.I18n.formatMessage("commands.verifiable-credential-unrevoke.description"))
|
|
725
|
+
.requiredOption(core.I18n.formatMessage("commands.verifiable-credential-unrevoke.options.seed.param"), core.I18n.formatMessage("commands.verifiable-credential-unrevoke.options.seed.description"))
|
|
726
|
+
.requiredOption(core.I18n.formatMessage("commands.verifiable-credential-unrevoke.options.did.param"), core.I18n.formatMessage("commands.verifiable-credential-unrevoke.options.did.description"))
|
|
727
|
+
.requiredOption(core.I18n.formatMessage("commands.verifiable-credential-unrevoke.options.revocation-index.param"), core.I18n.formatMessage("commands.verifiable-credential-unrevoke.options.revocation-index.description"));
|
|
728
|
+
command
|
|
729
|
+
.option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
730
|
+
.action(actionCommandVerifiableCredentialUnrevoke);
|
|
731
|
+
return command;
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Action the verifiable credential unrevoke command.
|
|
735
|
+
* @param opts The options for the command.
|
|
736
|
+
* @param opts.seed The seed to generate the private key for the controller.
|
|
737
|
+
* @param opts.did The id of the document to unrevoke the index.
|
|
738
|
+
* @param opts.revocationIndex The revocation index for the credential.
|
|
739
|
+
* @param opts.node The node URL.
|
|
740
|
+
*/
|
|
741
|
+
async function actionCommandVerifiableCredentialUnrevoke(opts) {
|
|
742
|
+
const seed = cliCore.CLIParam.hexBase64("seed", opts.seed);
|
|
743
|
+
const did = cliCore.CLIParam.stringValue("did", opts.did);
|
|
744
|
+
const revocationIndex = cliCore.CLIParam.integer("revocation-index", opts.revocationIndex);
|
|
745
|
+
const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
|
|
746
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.did"), did);
|
|
747
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verifiable-credential-unrevoke.labels.revocationIndex"), revocationIndex);
|
|
748
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
749
|
+
cliCore.CLIDisplay.break();
|
|
750
|
+
setupVault();
|
|
751
|
+
const vaultSeedId = "local-seed";
|
|
752
|
+
const localIdentity = "local";
|
|
753
|
+
const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
|
|
754
|
+
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, core.Converter.bytesToBase64(seed));
|
|
755
|
+
const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
|
|
756
|
+
config: {
|
|
757
|
+
clientOptions: {
|
|
758
|
+
nodes: [nodeEndpoint],
|
|
759
|
+
localPow: true
|
|
760
|
+
},
|
|
761
|
+
vaultSeedId
|
|
762
|
+
}
|
|
763
|
+
});
|
|
764
|
+
walletModels.WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
765
|
+
const iotaIdentityConnector = new identityConnectorIota.IotaIdentityConnector({
|
|
766
|
+
config: {
|
|
767
|
+
clientOptions: {
|
|
768
|
+
nodes: [nodeEndpoint],
|
|
769
|
+
localPow: true
|
|
770
|
+
},
|
|
771
|
+
vaultSeedId
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.verifiable-credential-unrevoke.progress.unrevokingCredential"));
|
|
775
|
+
cliCore.CLIDisplay.break();
|
|
776
|
+
cliCore.CLIDisplay.spinnerStart();
|
|
777
|
+
await iotaIdentityConnector.unrevokeVerifiableCredentials(localIdentity, did, [revocationIndex]);
|
|
778
|
+
cliCore.CLIDisplay.spinnerStop();
|
|
779
|
+
cliCore.CLIDisplay.done();
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// Copyright 2024 IOTA Stiftung.
|
|
783
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
784
|
+
/**
|
|
785
|
+
* Build the verifiable credential verify command for the CLI.
|
|
786
|
+
* @returns The command.
|
|
787
|
+
*/
|
|
788
|
+
function buildCommandVerifiableCredentialVerify() {
|
|
789
|
+
const command = new commander.Command();
|
|
790
|
+
command
|
|
791
|
+
.name("verifiable-credential-verify")
|
|
792
|
+
.summary(core.I18n.formatMessage("commands.verifiable-credential-verify.summary"))
|
|
793
|
+
.description(core.I18n.formatMessage("commands.verifiable-credential-verify.description"))
|
|
794
|
+
.requiredOption(core.I18n.formatMessage("commands.verifiable-credential-verify.options.jwt.param"), core.I18n.formatMessage("commands.verifiable-credential-verify.options.jwt.description"));
|
|
795
|
+
cliCore.CLIOptions.output(command, {
|
|
796
|
+
noConsole: true,
|
|
797
|
+
json: true,
|
|
798
|
+
env: true,
|
|
799
|
+
mergeJson: true,
|
|
800
|
+
mergeEnv: true
|
|
801
|
+
});
|
|
802
|
+
command
|
|
803
|
+
.option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
804
|
+
.action(actionCommandVerifiableCredentialVerify);
|
|
805
|
+
return command;
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* Action the verifiable credential verify command.
|
|
809
|
+
* @param opts The options for the command.
|
|
810
|
+
* @param opts.jwt The JSON web token for the verifiable credential.
|
|
811
|
+
* @param opts.node The node URL.
|
|
812
|
+
*/
|
|
813
|
+
async function actionCommandVerifiableCredentialVerify(opts) {
|
|
814
|
+
const jwt = cliCore.CLIParam.stringValue("jwt", opts.jwt);
|
|
815
|
+
const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
|
|
816
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verifiable-credential-verify.labels.jwt"), jwt);
|
|
817
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
818
|
+
cliCore.CLIDisplay.break();
|
|
819
|
+
setupVault();
|
|
820
|
+
const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
|
|
821
|
+
config: {
|
|
822
|
+
clientOptions: {
|
|
823
|
+
nodes: [nodeEndpoint],
|
|
824
|
+
localPow: true
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
walletModels.WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
829
|
+
const iotaIdentityConnector = new identityConnectorIota.IotaIdentityConnector({
|
|
830
|
+
config: {
|
|
831
|
+
clientOptions: {
|
|
832
|
+
nodes: [nodeEndpoint],
|
|
833
|
+
localPow: true
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
});
|
|
837
|
+
cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.verifiable-credential-verify.progress.verifyingCredential"));
|
|
838
|
+
cliCore.CLIDisplay.break();
|
|
839
|
+
cliCore.CLIDisplay.spinnerStart();
|
|
840
|
+
const verification = await iotaIdentityConnector.checkVerifiableCredential(jwt);
|
|
841
|
+
const isVerified = core.Is.notEmpty(verification.verifiableCredential);
|
|
842
|
+
const isRevoked = verification.revoked;
|
|
843
|
+
cliCore.CLIDisplay.spinnerStop();
|
|
844
|
+
if (opts.console) {
|
|
845
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verifiable-credential-verify.labels.isVerified"), isVerified);
|
|
846
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verifiable-credential-verify.labels.isRevoked"), isRevoked);
|
|
847
|
+
cliCore.CLIDisplay.break();
|
|
848
|
+
}
|
|
849
|
+
if (core.Is.stringValue(opts?.json)) {
|
|
850
|
+
await cliCore.CLIUtils.writeJsonFile(opts.json, { isVerified, isRevoked }, opts.mergeJson);
|
|
851
|
+
}
|
|
852
|
+
if (core.Is.stringValue(opts?.env)) {
|
|
853
|
+
await cliCore.CLIUtils.writeEnvFile(opts.env, [
|
|
854
|
+
`DID_VERIFIABLE_CREDENTIAL_VERIFIED="${isVerified}"`,
|
|
855
|
+
`DID_VERIFIABLE_CREDENTIAL_REVOKED="${isRevoked}"`
|
|
856
|
+
], opts.mergeEnv);
|
|
857
|
+
}
|
|
858
|
+
cliCore.CLIDisplay.done();
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
// Copyright 2024 IOTA Stiftung.
|
|
862
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
863
|
+
/**
|
|
864
|
+
* Build the verification method add command for the CLI.
|
|
865
|
+
* @returns The command.
|
|
866
|
+
*/
|
|
867
|
+
function buildCommandVerificationMethodAdd() {
|
|
868
|
+
const command = new commander.Command();
|
|
869
|
+
command
|
|
870
|
+
.name("verification-method-add")
|
|
871
|
+
.summary(core.I18n.formatMessage("commands.verification-method-add.summary"))
|
|
872
|
+
.description(core.I18n.formatMessage("commands.verification-method-add.description"))
|
|
873
|
+
.requiredOption(core.I18n.formatMessage("commands.verification-method-add.options.seed.param"), core.I18n.formatMessage("commands.verification-method-add.options.seed.description"))
|
|
874
|
+
.requiredOption(core.I18n.formatMessage("commands.verification-method-add.options.did.param"), core.I18n.formatMessage("commands.verification-method-add.options.did.description"))
|
|
875
|
+
.addOption(new commander.Option(core.I18n.formatMessage("commands.verification-method-add.options.type.param"), core.I18n.formatMessage("commands.verification-method-add.options.type.description"))
|
|
876
|
+
.choices(Object.values(standardsW3cDid.DidVerificationMethodType))
|
|
877
|
+
.makeOptionMandatory())
|
|
878
|
+
.option(core.I18n.formatMessage("commands.verification-method-add.options.id.param"), core.I18n.formatMessage("commands.verification-method-add.options.id.description"));
|
|
879
|
+
cliCore.CLIOptions.output(command, {
|
|
880
|
+
noConsole: true,
|
|
881
|
+
json: true,
|
|
882
|
+
env: true,
|
|
883
|
+
mergeJson: true,
|
|
884
|
+
mergeEnv: true
|
|
885
|
+
});
|
|
886
|
+
command
|
|
887
|
+
.option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
888
|
+
.option(core.I18n.formatMessage("commands.common.options.explorer.param"), core.I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
889
|
+
.action(actionCommandVerificationMethodAdd);
|
|
890
|
+
return command;
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* Action the verification method add command.
|
|
894
|
+
* @param opts The options for the command.
|
|
895
|
+
* @param opts.seed The private key for the controller.
|
|
896
|
+
* @param opts.did The identity of the document to add to.
|
|
897
|
+
* @param opts.type The type of the verification method to add.
|
|
898
|
+
* @param opts.id The id of the verification method to add.
|
|
899
|
+
* @param opts.node The node URL.
|
|
900
|
+
* @param opts.explorer The explorer URL.
|
|
901
|
+
*/
|
|
902
|
+
async function actionCommandVerificationMethodAdd(opts) {
|
|
903
|
+
const seed = cliCore.CLIParam.hexBase64("seed", opts.seed);
|
|
904
|
+
const did = cliCore.CLIParam.stringValue("did", opts.did);
|
|
905
|
+
const type = cliCore.CLIParam.stringValue("type", opts.type);
|
|
906
|
+
const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
|
|
907
|
+
const explorerEndpoint = cliCore.CLIParam.url("explorer", opts.explorer);
|
|
908
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.did"), did);
|
|
909
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verification-method-add.labels.verificationMethodType"), type);
|
|
910
|
+
if (core.Is.stringValue(opts.id)) {
|
|
911
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verification-method-add.labels.verificationMethodId"), opts?.id);
|
|
912
|
+
}
|
|
913
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
914
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
|
|
915
|
+
cliCore.CLIDisplay.break();
|
|
916
|
+
setupVault();
|
|
917
|
+
const vaultSeedId = "local-seed";
|
|
918
|
+
const localIdentity = "local";
|
|
919
|
+
const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
|
|
920
|
+
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, core.Converter.bytesToBase64(seed));
|
|
921
|
+
const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
|
|
922
|
+
config: {
|
|
923
|
+
clientOptions: {
|
|
924
|
+
nodes: [nodeEndpoint],
|
|
925
|
+
localPow: true
|
|
926
|
+
},
|
|
927
|
+
vaultSeedId
|
|
928
|
+
}
|
|
929
|
+
});
|
|
930
|
+
walletModels.WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
931
|
+
const iotaIdentityConnector = new identityConnectorIota.IotaIdentityConnector({
|
|
932
|
+
config: {
|
|
933
|
+
clientOptions: {
|
|
934
|
+
nodes: [nodeEndpoint],
|
|
935
|
+
localPow: true
|
|
936
|
+
},
|
|
937
|
+
vaultSeedId
|
|
938
|
+
}
|
|
939
|
+
});
|
|
940
|
+
cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.verification-method-add.progress.addingVerificationMethod"));
|
|
941
|
+
cliCore.CLIDisplay.break();
|
|
942
|
+
cliCore.CLIDisplay.spinnerStart();
|
|
943
|
+
const verificationMethod = await iotaIdentityConnector.addVerificationMethod(localIdentity, did, type, opts?.id);
|
|
944
|
+
cliCore.CLIDisplay.spinnerStop();
|
|
945
|
+
const keyPair = await vaultConnector.getKey(`${localIdentity}/${verificationMethod.id}`);
|
|
946
|
+
const privateKey = core.Converter.bytesToBase64(keyPair.privateKey);
|
|
947
|
+
const publicKey = core.Converter.bytesToBase64(keyPair.publicKey);
|
|
948
|
+
if (opts.console) {
|
|
949
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verification-method-add.labels.verificationMethodId"), verificationMethod.id);
|
|
950
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verification-method-add.labels.privateKey"), privateKey);
|
|
951
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verification-method-add.labels.publicKey"), publicKey);
|
|
952
|
+
cliCore.CLIDisplay.break();
|
|
953
|
+
}
|
|
954
|
+
if (core.Is.stringValue(opts?.json)) {
|
|
955
|
+
await cliCore.CLIUtils.writeJsonFile(opts.json, { verificationMethodId: verificationMethod.id, privateKey, publicKey }, opts.mergeJson);
|
|
956
|
+
}
|
|
957
|
+
if (core.Is.stringValue(opts?.env)) {
|
|
958
|
+
await cliCore.CLIUtils.writeEnvFile(opts.env, [
|
|
959
|
+
`DID_VERIFICATION_METHOD_ID="${verificationMethod.id}"`,
|
|
960
|
+
`DID_VERIFICATION_METHOD_PRIVATE_KEY="${privateKey}"`,
|
|
961
|
+
`DID_VERIFICATION_METHOD_PUBLIC_KEY="${publicKey}"`
|
|
962
|
+
], opts.mergeEnv);
|
|
963
|
+
}
|
|
964
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explore"), `${core.StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${identityConnectorIota.IotaIdentityUtils.didToAddress(did)}?tab=DID`);
|
|
965
|
+
cliCore.CLIDisplay.break();
|
|
966
|
+
cliCore.CLIDisplay.done();
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
// Copyright 2024 IOTA Stiftung.
|
|
970
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
971
|
+
/**
|
|
972
|
+
* Build the verification method remove command for the CLI.
|
|
973
|
+
* @returns The command.
|
|
974
|
+
*/
|
|
975
|
+
function buildCommandVerificationMethodRemove() {
|
|
976
|
+
const command = new commander.Command();
|
|
977
|
+
command
|
|
978
|
+
.name("verification-method-remove")
|
|
979
|
+
.summary(core.I18n.formatMessage("commands.verification-method-remove.summary"))
|
|
980
|
+
.description(core.I18n.formatMessage("commands.verification-method-remove.description"))
|
|
981
|
+
.requiredOption(core.I18n.formatMessage("commands.verification-method-remove.options.seed.param"), core.I18n.formatMessage("commands.verification-method-remove.options.seed.description"))
|
|
982
|
+
.requiredOption(core.I18n.formatMessage("commands.verification-method-remove.options.id.param"), core.I18n.formatMessage("commands.verification-method-remove.options.id.description"));
|
|
983
|
+
cliCore.CLIOptions.output(command, {
|
|
984
|
+
noConsole: true,
|
|
985
|
+
json: true,
|
|
986
|
+
env: true,
|
|
987
|
+
mergeJson: true,
|
|
988
|
+
mergeEnv: true
|
|
989
|
+
});
|
|
990
|
+
command
|
|
991
|
+
.option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
|
|
992
|
+
.option(core.I18n.formatMessage("commands.common.options.explorer.param"), core.I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
|
|
993
|
+
.action(actionCommandVerificationMethodRemove);
|
|
994
|
+
return command;
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* Action the verification method remove command.
|
|
998
|
+
* @param opts The options for the command.
|
|
999
|
+
* @param opts.seed The private key for the controller.
|
|
1000
|
+
* @param opts.id The id of the verification method to remove.
|
|
1001
|
+
* @param opts.node The node URL.
|
|
1002
|
+
* @param opts.explorer The explorer URL.
|
|
1003
|
+
*/
|
|
1004
|
+
async function actionCommandVerificationMethodRemove(opts) {
|
|
1005
|
+
const seed = cliCore.CLIParam.hexBase64("seed", opts.seed);
|
|
1006
|
+
const id = cliCore.CLIParam.stringValue("id", opts.id);
|
|
1007
|
+
const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
|
|
1008
|
+
const explorerEndpoint = cliCore.CLIParam.url("explorer", opts.explorer);
|
|
1009
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verification-method-add.labels.verificationMethodId"), id);
|
|
1010
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
|
|
1011
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
|
|
1012
|
+
cliCore.CLIDisplay.break();
|
|
1013
|
+
setupVault();
|
|
1014
|
+
const vaultSeedId = "local-seed";
|
|
1015
|
+
const localIdentity = "local";
|
|
1016
|
+
const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
|
|
1017
|
+
await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, core.Converter.bytesToBase64(seed));
|
|
1018
|
+
const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
|
|
1019
|
+
config: {
|
|
1020
|
+
clientOptions: {
|
|
1021
|
+
nodes: [nodeEndpoint],
|
|
1022
|
+
localPow: true
|
|
1023
|
+
},
|
|
1024
|
+
vaultSeedId
|
|
1025
|
+
}
|
|
1026
|
+
});
|
|
1027
|
+
walletModels.WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
|
|
1028
|
+
const iotaIdentityConnector = new identityConnectorIota.IotaIdentityConnector({
|
|
1029
|
+
config: {
|
|
1030
|
+
clientOptions: {
|
|
1031
|
+
nodes: [nodeEndpoint],
|
|
1032
|
+
localPow: true
|
|
1033
|
+
},
|
|
1034
|
+
vaultSeedId
|
|
1035
|
+
}
|
|
1036
|
+
});
|
|
1037
|
+
cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.verification-method-remove.progress.removingVerificationMethod"));
|
|
1038
|
+
cliCore.CLIDisplay.break();
|
|
1039
|
+
cliCore.CLIDisplay.spinnerStart();
|
|
1040
|
+
await iotaIdentityConnector.removeVerificationMethod(localIdentity, id);
|
|
1041
|
+
cliCore.CLIDisplay.spinnerStop();
|
|
1042
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explore"), `${core.StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${identityConnectorIota.IotaIdentityUtils.didToAddress(identityModels.DocumentHelper.parse(id).id)}?tab=DID`);
|
|
1043
|
+
cliCore.CLIDisplay.break();
|
|
1044
|
+
cliCore.CLIDisplay.done();
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
// Copyright 2024 IOTA Stiftung.
|
|
1048
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
1049
|
+
/**
|
|
1050
|
+
* The main entry point for the CLI.
|
|
1051
|
+
*/
|
|
1052
|
+
class CLI extends cliCore.CLIBase {
|
|
1053
|
+
/**
|
|
1054
|
+
* Run the app.
|
|
1055
|
+
* @param argv The process arguments.
|
|
1056
|
+
* @param localesDirectory The directory for the locales, default to relative to the script.
|
|
1057
|
+
* @param options Additional options for the CLI.
|
|
1058
|
+
* @param options.overrideOutputWidth The override output width.
|
|
1059
|
+
* @returns The exit code.
|
|
1060
|
+
*/
|
|
1061
|
+
async run(argv, localesDirectory, options) {
|
|
1062
|
+
return this.execute({
|
|
1063
|
+
title: "TWIN Identity",
|
|
1064
|
+
appName: "twin-identity",
|
|
1065
|
+
version: "0.0.3-next.18",
|
|
1066
|
+
icon: "🌍",
|
|
1067
|
+
supportsEnvFiles: true,
|
|
1068
|
+
overrideOutputWidth: options?.overrideOutputWidth
|
|
1069
|
+
}, 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);
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* Get the commands for the CLI.
|
|
1073
|
+
* @param program The main program to add the commands to.
|
|
1074
|
+
* @internal
|
|
1075
|
+
*/
|
|
1076
|
+
getCommands(program) {
|
|
1077
|
+
return [
|
|
1078
|
+
cryptoCli.buildCommandMnemonic(),
|
|
1079
|
+
cryptoCli.buildCommandAddress(),
|
|
1080
|
+
walletCli.buildCommandFaucet(),
|
|
1081
|
+
walletCli.buildCommandTransfer(),
|
|
1082
|
+
buildCommandIdentityCreate(),
|
|
1083
|
+
buildCommandIdentityResolve(),
|
|
1084
|
+
buildCommandVerificationMethodAdd(),
|
|
1085
|
+
buildCommandVerificationMethodRemove(),
|
|
1086
|
+
buildCommandServiceAdd(),
|
|
1087
|
+
buildCommandServiceRemove(),
|
|
1088
|
+
buildCommandVerifiableCredentialCreate(),
|
|
1089
|
+
buildCommandVerifiableCredentialVerify(),
|
|
1090
|
+
buildCommandVerifiableCredentialRevoke(),
|
|
1091
|
+
buildCommandVerifiableCredentialUnrevoke(),
|
|
1092
|
+
buildCommandProofCreate(),
|
|
1093
|
+
buildCommandProofVerify()
|
|
1094
|
+
];
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
exports.CLI = CLI;
|
|
1099
|
+
exports.actionCommandIdentityCreate = actionCommandIdentityCreate;
|
|
1100
|
+
exports.actionCommandIdentityResolve = actionCommandIdentityResolve;
|
|
1101
|
+
exports.actionCommandProofCreate = actionCommandProofCreate;
|
|
1102
|
+
exports.actionCommandProofVerify = actionCommandProofVerify;
|
|
1103
|
+
exports.actionCommandServiceAdd = actionCommandServiceAdd;
|
|
1104
|
+
exports.actionCommandServiceRemove = actionCommandServiceRemove;
|
|
1105
|
+
exports.actionCommandVerifiableCredentialCreate = actionCommandVerifiableCredentialCreate;
|
|
1106
|
+
exports.actionCommandVerifiableCredentialRevoke = actionCommandVerifiableCredentialRevoke;
|
|
1107
|
+
exports.actionCommandVerifiableCredentialUnrevoke = actionCommandVerifiableCredentialUnrevoke;
|
|
1108
|
+
exports.actionCommandVerifiableCredentialVerify = actionCommandVerifiableCredentialVerify;
|
|
1109
|
+
exports.actionCommandVerificationMethodAdd = actionCommandVerificationMethodAdd;
|
|
1110
|
+
exports.actionCommandVerificationMethodRemove = actionCommandVerificationMethodRemove;
|
|
1111
|
+
exports.buildCommandIdentityCreate = buildCommandIdentityCreate;
|
|
1112
|
+
exports.buildCommandIdentityResolve = buildCommandIdentityResolve;
|
|
1113
|
+
exports.buildCommandProofCreate = buildCommandProofCreate;
|
|
1114
|
+
exports.buildCommandProofVerify = buildCommandProofVerify;
|
|
1115
|
+
exports.buildCommandServiceAdd = buildCommandServiceAdd;
|
|
1116
|
+
exports.buildCommandServiceRemove = buildCommandServiceRemove;
|
|
1117
|
+
exports.buildCommandVerifiableCredentialCreate = buildCommandVerifiableCredentialCreate;
|
|
1118
|
+
exports.buildCommandVerifiableCredentialRevoke = buildCommandVerifiableCredentialRevoke;
|
|
1119
|
+
exports.buildCommandVerifiableCredentialUnrevoke = buildCommandVerifiableCredentialUnrevoke;
|
|
1120
|
+
exports.buildCommandVerifiableCredentialVerify = buildCommandVerifiableCredentialVerify;
|
|
1121
|
+
exports.buildCommandVerificationMethodAdd = buildCommandVerificationMethodAdd;
|
|
1122
|
+
exports.buildCommandVerificationMethodRemove = buildCommandVerificationMethodRemove;
|