@veramo/cli 4.3.0 → 4.3.1-next.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/veramo.js +1 -1
- package/build/cli.d.ts +13 -13
- package/build/cli.d.ts.map +1 -1
- package/build/cli.js +19 -23
- package/build/cli.js.map +1 -1
- package/build/config.d.ts +1 -1
- package/build/config.d.ts.map +1 -1
- package/build/config.js +17 -27
- package/build/config.js.map +1 -1
- package/build/credential.js +32 -69
- package/build/credential.js.map +1 -1
- package/build/dev.js +40 -62
- package/build/dev.js.map +1 -1
- package/build/did.js +70 -84
- package/build/did.js.map +1 -1
- package/build/discover.js +9 -20
- package/build/discover.js.map +1 -1
- package/build/execute.js +16 -30
- package/build/execute.js.map +1 -1
- package/build/explore/credentials.d.ts +1 -1
- package/build/explore/credentials.d.ts.map +1 -1
- package/build/explore/credentials.js +19 -37
- package/build/explore/credentials.js.map +1 -1
- package/build/explore/index.js +9 -19
- package/build/explore/index.js.map +1 -1
- package/build/explore/main.d.ts +1 -1
- package/build/explore/main.d.ts.map +1 -1
- package/build/explore/main.js +24 -42
- package/build/explore/main.js.map +1 -1
- package/build/explore/managed-identifiers.d.ts +1 -1
- package/build/explore/managed-identifiers.d.ts.map +1 -1
- package/build/explore/managed-identifiers.js +14 -32
- package/build/explore/managed-identifiers.js.map +1 -1
- package/build/explore/messages.d.ts +1 -1
- package/build/explore/messages.d.ts.map +1 -1
- package/build/explore/messages.js +13 -31
- package/build/explore/messages.js.map +1 -1
- package/build/explore/presentations.d.ts +1 -1
- package/build/explore/presentations.d.ts.map +1 -1
- package/build/explore/presentations.js +19 -37
- package/build/explore/presentations.js.map +1 -1
- package/build/explore/styles.js +1 -4
- package/build/explore/styles.js.map +1 -1
- package/build/explore/utils.js +8 -17
- package/build/explore/utils.js.map +1 -1
- package/build/lib/agentCreator.js +3 -7
- package/build/lib/agentCreator.js.map +1 -1
- package/build/lib/objectCreator.d.ts +1 -1
- package/build/lib/objectCreator.d.ts.map +1 -1
- package/build/lib/objectCreator.js +21 -28
- package/build/lib/objectCreator.js.map +1 -1
- package/build/message.js +8 -19
- package/build/message.js.map +1 -1
- package/build/presentation.js +34 -71
- package/build/presentation.js.map +1 -1
- package/build/sdr.js +50 -68
- package/build/sdr.js.map +1 -1
- package/build/server.js +11 -25
- package/build/server.js.map +1 -1
- package/build/setup.d.ts +0 -1
- package/build/setup.d.ts.map +1 -1
- package/build/setup.js +8 -17
- package/build/setup.js.map +1 -1
- package/build/util.js +17 -32
- package/build/util.js.map +1 -1
- package/build/version.d.ts.map +1 -1
- package/build/version.js +6 -5
- package/build/version.js.map +1 -1
- package/default/default.yml +1 -1
- package/package.json +37 -30
- package/src/cli.ts +15 -14
- package/src/config.ts +5 -4
- package/src/credential.ts +3 -3
- package/src/dev.ts +8 -3
- package/src/did.ts +1 -1
- package/src/discover.ts +1 -1
- package/src/execute.ts +4 -4
- package/src/explore/credentials.ts +3 -3
- package/src/explore/index.ts +4 -3
- package/src/explore/main.ts +6 -6
- package/src/explore/managed-identifiers.ts +3 -3
- package/src/explore/messages.ts +3 -3
- package/src/explore/presentations.ts +3 -3
- package/src/lib/agentCreator.ts +1 -1
- package/src/lib/objectCreator.ts +14 -14
- package/src/message.ts +2 -2
- package/src/presentation.ts +2 -2
- package/src/sdr.ts +3 -3
- package/src/server.ts +3 -3
- package/src/setup.ts +2 -3
- package/src/version.ts +6 -2
package/bin/veramo.js
CHANGED
package/build/cli.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import './did';
|
|
2
|
-
import './credential';
|
|
3
|
-
import './presentation';
|
|
4
|
-
import './explore';
|
|
5
|
-
import './sdr';
|
|
6
|
-
import './message';
|
|
7
|
-
import './discover';
|
|
8
|
-
import './version';
|
|
9
|
-
import './execute';
|
|
10
|
-
import './server';
|
|
11
|
-
import './setup';
|
|
12
|
-
import './config';
|
|
13
|
-
import './dev';
|
|
1
|
+
import './did.js';
|
|
2
|
+
import './credential.js';
|
|
3
|
+
import './presentation.js';
|
|
4
|
+
import './explore/index.js';
|
|
5
|
+
import './sdr.js';
|
|
6
|
+
import './message.js';
|
|
7
|
+
import './discover.js';
|
|
8
|
+
import './version.js';
|
|
9
|
+
import './execute.js';
|
|
10
|
+
import './server.js';
|
|
11
|
+
import './setup.js';
|
|
12
|
+
import './config.js';
|
|
13
|
+
import './dev.js';
|
|
14
14
|
//# sourceMappingURL=cli.d.ts.map
|
package/build/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAMA,OAAO,UAAU,CAAA;AACjB,OAAO,iBAAiB,CAAA;AACxB,OAAO,mBAAmB,CAAA;AAC1B,OAAO,oBAAoB,CAAA;AAC3B,OAAO,UAAU,CAAA;AACjB,OAAO,cAAc,CAAA;AACrB,OAAO,eAAe,CAAA;AACtB,OAAO,cAAc,CAAA;AACrB,OAAO,cAAc,CAAA;AACrB,OAAO,aAAa,CAAA;AACpB,OAAO,YAAY,CAAA;AACnB,OAAO,aAAa,CAAA;AACpB,OAAO,UAAU,CAAA"}
|
package/build/cli.js
CHANGED
|
@@ -1,28 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
require("./server");
|
|
19
|
-
require("./setup");
|
|
20
|
-
require("./config");
|
|
21
|
-
require("./dev");
|
|
1
|
+
import { program } from 'commander';
|
|
2
|
+
import inquirer from 'inquirer';
|
|
3
|
+
import inquirerAutoPrompt from 'inquirer-autocomplete-prompt';
|
|
4
|
+
inquirer.registerPrompt('autocomplete', inquirerAutoPrompt);
|
|
5
|
+
import './did.js';
|
|
6
|
+
import './credential.js';
|
|
7
|
+
import './presentation.js';
|
|
8
|
+
import './explore/index.js';
|
|
9
|
+
import './sdr.js';
|
|
10
|
+
import './message.js';
|
|
11
|
+
import './discover.js';
|
|
12
|
+
import './version.js';
|
|
13
|
+
import './execute.js';
|
|
14
|
+
import './server.js';
|
|
15
|
+
import './setup.js';
|
|
16
|
+
import './config.js';
|
|
17
|
+
import './dev.js';
|
|
22
18
|
if (!process.argv.slice(2).length) {
|
|
23
|
-
|
|
19
|
+
program.outputHelp();
|
|
24
20
|
}
|
|
25
21
|
else {
|
|
26
|
-
|
|
22
|
+
program.parse(process.argv);
|
|
27
23
|
}
|
|
28
24
|
//# sourceMappingURL=cli.js.map
|
package/build/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,QAAQ,MAAM,UAAU,CAAA;AAC/B,OAAO,kBAAkB,MAAM,8BAA8B,CAAA;AAE7D,QAAQ,CAAC,cAAc,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAA;AAE3D,OAAO,UAAU,CAAA;AACjB,OAAO,iBAAiB,CAAA;AACxB,OAAO,mBAAmB,CAAA;AAC1B,OAAO,oBAAoB,CAAA;AAC3B,OAAO,UAAU,CAAA;AACjB,OAAO,cAAc,CAAA;AACrB,OAAO,eAAe,CAAA;AACtB,OAAO,cAAc,CAAA;AACrB,OAAO,cAAc,CAAA;AACrB,OAAO,aAAa,CAAA;AACpB,OAAO,YAAY,CAAA;AACnB,OAAO,aAAa,CAAA;AACpB,OAAO,UAAU,CAAA;AAEjB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE;IACjC,OAAO,CAAC,UAAU,EAAE,CAAA;CACrB;KAAM;IACL,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;CAC5B"}
|
package/build/config.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=config.d.ts.map
|
package/build/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":""}
|
package/build/config.js
CHANGED
|
@@ -1,28 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
require("cross-fetch/polyfill");
|
|
13
|
-
const commander_1 = require("commander");
|
|
14
|
-
const kms_local_1 = require("@veramo/kms-local");
|
|
15
|
-
const setup_1 = require("./setup");
|
|
16
|
-
const fs = require('fs');
|
|
17
|
-
const { dirname } = require('path');
|
|
18
|
-
commander_1.program.option('--config <path>', 'Configuration file', './agent.yml');
|
|
19
|
-
const config = commander_1.program.command('config').description('Agent configuration');
|
|
1
|
+
import { program } from 'commander';
|
|
2
|
+
import { SecretBox } from '@veramo/kms-local';
|
|
3
|
+
import { getAgent } from './setup.js';
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import { dirname } from 'path';
|
|
6
|
+
import * as url from 'url';
|
|
7
|
+
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
|
8
|
+
program.option('--config <path>', 'Configuration file', './agent.yml');
|
|
9
|
+
const config = program.command('config').description('Agent configuration');
|
|
20
10
|
config
|
|
21
11
|
.command('create', { isDefault: true })
|
|
22
12
|
.description('Create default agent config')
|
|
23
13
|
.option('--filename <string>', 'Config file name', './agent.yml')
|
|
24
14
|
.option('--template <string>', 'Use template (default,client)', 'default')
|
|
25
|
-
.action((options) =>
|
|
15
|
+
.action(async (options) => {
|
|
26
16
|
const { filename, template } = options;
|
|
27
17
|
const templateFile = __dirname + '/../default/' + template + '.yml';
|
|
28
18
|
if (!fs.existsSync(templateFile)) {
|
|
@@ -40,16 +30,16 @@ config
|
|
|
40
30
|
else {
|
|
41
31
|
console.log('File already exists: ' + filename);
|
|
42
32
|
}
|
|
43
|
-
})
|
|
33
|
+
});
|
|
44
34
|
config
|
|
45
35
|
.command('create-secret-key')
|
|
46
36
|
.alias('gen-key')
|
|
47
37
|
.alias('key-gen')
|
|
48
38
|
.description('generate secret key')
|
|
49
39
|
.option('-q, --quiet', 'Only print the raw key, no instructions', false)
|
|
50
|
-
.action((options) =>
|
|
40
|
+
.action(async (options) => {
|
|
51
41
|
try {
|
|
52
|
-
const dbEncryptionKey =
|
|
42
|
+
const dbEncryptionKey = await SecretBox.createSecretKey();
|
|
53
43
|
if (options.quiet === true) {
|
|
54
44
|
console.log(dbEncryptionKey);
|
|
55
45
|
}
|
|
@@ -67,15 +57,15 @@ config
|
|
|
67
57
|
catch (e) {
|
|
68
58
|
console.error(e.message);
|
|
69
59
|
}
|
|
70
|
-
})
|
|
60
|
+
});
|
|
71
61
|
config
|
|
72
62
|
.command('check')
|
|
73
63
|
.alias('verify')
|
|
74
64
|
.description('Verify an agent config file syntax')
|
|
75
65
|
.option('-f, --filename <string>', 'Config file name', './agent.yml')
|
|
76
66
|
.option('-m, --method <string>', 'Check that a specific method is exposed by the agent.', 'execute')
|
|
77
|
-
.action((options) =>
|
|
78
|
-
const agent =
|
|
67
|
+
.action(async (options) => {
|
|
68
|
+
const agent = getAgent(options.filename);
|
|
79
69
|
if (!agent) {
|
|
80
70
|
console.error('unknown error while creating the agent from your config. Consider running `veramo config create` to generate a new configuration file, or to manually compare differences.');
|
|
81
71
|
}
|
|
@@ -87,5 +77,5 @@ config
|
|
|
87
77
|
console.log(`Your Veramo configuration seems fine. An agent can be created and the 'agent.${options.method}()' method can be called on it.`);
|
|
88
78
|
}
|
|
89
79
|
}
|
|
90
|
-
})
|
|
80
|
+
});
|
|
91
81
|
//# sourceMappingURL=config.js.map
|
package/build/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAE9B,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAC3B,MAAM,SAAS,GAAG,GAAG,CAAC,aAAa,CAAC,IAAI,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAEnE,OAAO,CAAC,MAAM,CAAC,iBAAiB,EAAE,oBAAoB,EAAE,aAAa,CAAC,CAAA;AAEtE,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAA;AAE3E,MAAM;KACH,OAAO,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;KACtC,WAAW,CAAC,6BAA6B,CAAC;KAC1C,MAAM,CAAC,qBAAqB,EAAE,kBAAkB,EAAE,aAAa,CAAC;KAChE,MAAM,CAAC,qBA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uleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
const setup_1 = require("./setup");
|
|
39
|
-
const commander_1 = require("commander");
|
|
40
|
-
const inquirer_1 = __importDefault(require("inquirer"));
|
|
41
|
-
const qrcode_terminal_1 = __importDefault(require("qrcode-terminal"));
|
|
42
|
-
const fs = __importStar(require("fs"));
|
|
43
|
-
const json5 = __importStar(require("json5"));
|
|
44
|
-
const util_1 = require("./util");
|
|
45
|
-
const fuzzy = require('fuzzy');
|
|
46
|
-
const credential = commander_1.program.command('credential').description('W3C Verifiable Credential');
|
|
1
|
+
import { getAgent } from './setup.js';
|
|
2
|
+
import { program } from 'commander';
|
|
3
|
+
import inquirer from 'inquirer';
|
|
4
|
+
import qrcode from 'qrcode-terminal';
|
|
5
|
+
import * as fs from 'fs';
|
|
6
|
+
import * as json5 from 'json5';
|
|
7
|
+
import { readStdin } from './util.js';
|
|
8
|
+
import fuzzy from 'fuzzy';
|
|
9
|
+
const credential = program.command('credential').description('W3C Verifiable Credential');
|
|
47
10
|
credential
|
|
48
11
|
.command('create', { isDefault: true })
|
|
49
12
|
.description('Create W3C Verifiable Credential')
|
|
50
13
|
.option('-s, --send', 'Send')
|
|
51
14
|
.option('-j, --json', 'Output in JSON')
|
|
52
15
|
.option('-q, --qrcode', 'Show qrcode')
|
|
53
|
-
.action((cmd) =>
|
|
54
|
-
const agent =
|
|
55
|
-
const identifiers =
|
|
56
|
-
const knownDids =
|
|
16
|
+
.action(async (cmd) => {
|
|
17
|
+
const agent = getAgent(program.opts().config);
|
|
18
|
+
const identifiers = await agent.didManagerFind();
|
|
19
|
+
const knownDids = await agent.dataStoreORMGetIdentifiers();
|
|
57
20
|
const subjects = [...knownDids.map((id) => id.did)];
|
|
58
21
|
if (identifiers.length === 0) {
|
|
59
22
|
console.error('No dids');
|
|
60
23
|
process.exit();
|
|
61
24
|
}
|
|
62
|
-
const answers =
|
|
25
|
+
const answers = await inquirer.prompt([
|
|
63
26
|
{
|
|
64
27
|
type: 'list',
|
|
65
28
|
name: 'proofFormat',
|
|
@@ -79,12 +42,12 @@ credential
|
|
|
79
42
|
type: 'autocomplete',
|
|
80
43
|
name: 'sub',
|
|
81
44
|
pageSize: 15,
|
|
82
|
-
source: (answers, input) =>
|
|
45
|
+
source: async (answers, input) => {
|
|
83
46
|
const res = fuzzy
|
|
84
47
|
.filter(input, subjects)
|
|
85
48
|
.map((el) => (typeof el === 'string' ? el : el.original));
|
|
86
49
|
return res;
|
|
87
|
-
}
|
|
50
|
+
},
|
|
88
51
|
message: 'Subject DID',
|
|
89
52
|
},
|
|
90
53
|
{
|
|
@@ -127,7 +90,7 @@ credential
|
|
|
127
90
|
credentialSubject,
|
|
128
91
|
};
|
|
129
92
|
if (answers.addStatus) {
|
|
130
|
-
const statusAnswers =
|
|
93
|
+
const statusAnswers = await inquirer.prompt([
|
|
131
94
|
{
|
|
132
95
|
type: 'input',
|
|
133
96
|
name: 'type',
|
|
@@ -147,7 +110,7 @@ credential
|
|
|
147
110
|
id: statusAnswers.id,
|
|
148
111
|
};
|
|
149
112
|
}
|
|
150
|
-
const verifiableCredential =
|
|
113
|
+
const verifiableCredential = await agent.createVerifiableCredential({
|
|
151
114
|
save: true,
|
|
152
115
|
credential,
|
|
153
116
|
proofFormat: answers.proofFormat,
|
|
@@ -164,7 +127,7 @@ credential
|
|
|
164
127
|
type = 'w3c.vc';
|
|
165
128
|
}
|
|
166
129
|
try {
|
|
167
|
-
const message =
|
|
130
|
+
const message = await agent.sendMessageDIDCommAlpha1({
|
|
168
131
|
save: true,
|
|
169
132
|
data: {
|
|
170
133
|
from: answers.iss,
|
|
@@ -180,7 +143,7 @@ credential
|
|
|
180
143
|
}
|
|
181
144
|
}
|
|
182
145
|
if (cmd.qrcode) {
|
|
183
|
-
|
|
146
|
+
qrcode.generate(verifiableCredential.proof.jwt);
|
|
184
147
|
}
|
|
185
148
|
else {
|
|
186
149
|
if (cmd.json) {
|
|
@@ -190,23 +153,23 @@ credential
|
|
|
190
153
|
console.dir(verifiableCredential, { depth: 10 });
|
|
191
154
|
}
|
|
192
155
|
}
|
|
193
|
-
})
|
|
156
|
+
});
|
|
194
157
|
credential
|
|
195
158
|
.command('verify')
|
|
196
159
|
.description('Verify a W3C Verifiable Credential provided as raw string, file or stdin')
|
|
197
160
|
.option('-f, --filename <string>', 'Optional. Read the credential from a file instead of stdin')
|
|
198
161
|
.option('-r, --raw <string>', 'Optional. Specify the credential as a parameter instead of file or stdin')
|
|
199
|
-
.action((options) =>
|
|
200
|
-
const agent =
|
|
162
|
+
.action(async (options) => {
|
|
163
|
+
const agent = getAgent(program.opts().config);
|
|
201
164
|
let raw = '';
|
|
202
165
|
if (options.raw) {
|
|
203
166
|
raw = options.raw;
|
|
204
167
|
}
|
|
205
168
|
else if (options.filename) {
|
|
206
|
-
raw =
|
|
169
|
+
raw = await fs.promises.readFile(options.filename, 'utf-8');
|
|
207
170
|
}
|
|
208
171
|
else {
|
|
209
|
-
raw =
|
|
172
|
+
raw = await readStdin();
|
|
210
173
|
}
|
|
211
174
|
let credentialAsJSON;
|
|
212
175
|
try {
|
|
@@ -221,7 +184,7 @@ credential
|
|
|
221
184
|
};
|
|
222
185
|
}
|
|
223
186
|
try {
|
|
224
|
-
const result =
|
|
187
|
+
const result = await agent.verifyCredential({ credential: credentialAsJSON });
|
|
225
188
|
if (result.verified === true) {
|
|
226
189
|
console.log('Credential was verified successfully.');
|
|
227
190
|
}
|
|
@@ -232,13 +195,13 @@ credential
|
|
|
232
195
|
catch (e) {
|
|
233
196
|
console.error(e.message);
|
|
234
197
|
}
|
|
235
|
-
})
|
|
198
|
+
});
|
|
236
199
|
credential
|
|
237
200
|
.command('output')
|
|
238
201
|
.description('Print W3C Verifiable Credential to stdout')
|
|
239
|
-
.action((cmd) =>
|
|
240
|
-
const agent =
|
|
241
|
-
const credentials =
|
|
202
|
+
.action(async (cmd) => {
|
|
203
|
+
const agent = getAgent(program.opts().config);
|
|
204
|
+
const credentials = await agent.dataStoreORMGetVerifiableCredentials();
|
|
242
205
|
if (credentials.length > 0) {
|
|
243
206
|
const list = [];
|
|
244
207
|
for (const cred of credentials) {
|
|
@@ -249,7 +212,7 @@ credential
|
|
|
249
212
|
value: cred,
|
|
250
213
|
});
|
|
251
214
|
}
|
|
252
|
-
const answers =
|
|
215
|
+
const answers = await inquirer.prompt([
|
|
253
216
|
{
|
|
254
217
|
type: 'list',
|
|
255
218
|
name: 'credential',
|
|
@@ -262,5 +225,5 @@ credential
|
|
|
262
225
|
else {
|
|
263
226
|
console.log('No credentials found.');
|
|
264
227
|
}
|
|
265
|
-
})
|
|
228
|
+
});
|
|
266
229
|
//# sourceMappingURL=credential.js.map
|
package/build/credential.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credential.js","sourceRoot":"","sources":["../src/credential.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"credential.js","sourceRoot":"","sources":["../src/credential.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,QAAQ,MAAM,UAAU,CAAA;AAC/B,OAAO,MAAM,MAAM,iBAAiB,CAAA;AACpC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAGrC,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,WAAW,CAAC,2BAA2B,CAAC,CAAA;AAEzF,UAAU;KACP,OAAO,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;KACtC,WAAW,CAAC,kCAAkC,CAAC;KAC/C,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC;KAC5B,MAAM,CAAC,YAAY,EAAE,gBAAgB,CAAC;KACtC,MAAM,CAAC,cAAc,EAAE,aAAa,CAAC;KACrC,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IACpB,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,CAAA;IAC7C,MAAM,WAAW,GAAG,MAAM,KAAK,CAAC,cAAc,EAAE,CAAA;IAEhD,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,0BAA0B,EAAE,CAAA;IAC1D,MA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AAA;KAC/C;SAAM;QACL,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAA;KACrC;AACH,CAAC,CAAC,CAAA"}
|
package/build/dev.js
CHANGED
|
@@ -1,44 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
const api_extractor_1 = require("@microsoft/api-extractor");
|
|
36
|
-
const api_extractor_model_1 = require("@microsoft/api-extractor-model");
|
|
37
|
-
const commander_1 = require("commander");
|
|
38
|
-
const fs_1 = require("fs");
|
|
39
|
-
const path_1 = require("path");
|
|
40
|
-
const TJS = __importStar(require("ts-json-schema-generator"));
|
|
41
|
-
const fs = require('fs');
|
|
1
|
+
import { Extractor, ExtractorConfig } from '@microsoft/api-extractor';
|
|
2
|
+
import { ApiModel, } from '@microsoft/api-extractor-model';
|
|
3
|
+
import { program } from 'commander';
|
|
4
|
+
import { writeFileSync } from 'fs';
|
|
5
|
+
import { resolve } from 'path';
|
|
6
|
+
import * as TJS from 'ts-json-schema-generator';
|
|
7
|
+
import module from "module";
|
|
8
|
+
const requireCjs = module.createRequire(import.meta.url);
|
|
42
9
|
const genericTypes = ['boolean', 'string', 'number', 'any', 'Array<string>'];
|
|
43
10
|
function createSchema(generator, symbol) {
|
|
44
11
|
if (genericTypes.includes(symbol)) {
|
|
@@ -85,17 +52,16 @@ function getReference(response) {
|
|
|
85
52
|
return { $ref: '#/components/schemas/' + response };
|
|
86
53
|
}
|
|
87
54
|
}
|
|
88
|
-
const dev =
|
|
55
|
+
const dev = program.command('dev').description('Plugin developer tools');
|
|
89
56
|
dev
|
|
90
57
|
.command('generate-plugin-schema')
|
|
91
58
|
.description('generate plugin schema')
|
|
92
59
|
.option('-c, --extractorConfig <string>', 'API Extractor config file', './api-extractor.json')
|
|
93
60
|
.option('-p, --packageConfig <string>', 'package.json file containing a Veramo plugin interface config', './package.json')
|
|
94
|
-
.action((options) =>
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
const extractorResult = api_extractor_1.Extractor.invoke(extractorConfig, {
|
|
61
|
+
.action(async (options) => {
|
|
62
|
+
const apiExtractorJsonPath = resolve(options.extractorConfig);
|
|
63
|
+
const extractorConfig = ExtractorConfig.loadFileAndPrepare(apiExtractorJsonPath);
|
|
64
|
+
const extractorResult = Extractor.invoke(extractorConfig, {
|
|
99
65
|
localBuild: true,
|
|
100
66
|
showVerboseMessages: true,
|
|
101
67
|
});
|
|
@@ -104,9 +70,9 @@ dev
|
|
|
104
70
|
` and ${extractorResult.warningCount} warnings`);
|
|
105
71
|
process.exitCode = 1;
|
|
106
72
|
}
|
|
107
|
-
const packageConfig =
|
|
73
|
+
const packageConfig = requireCjs(resolve(options.packageConfig));
|
|
108
74
|
const interfaces = {};
|
|
109
|
-
for (const pluginInterfaceName in
|
|
75
|
+
for (const pluginInterfaceName in packageConfig?.veramo?.pluginInterfaces) {
|
|
110
76
|
const entryFile = packageConfig.veramo.pluginInterfaces[pluginInterfaceName];
|
|
111
77
|
const api = {
|
|
112
78
|
components: {
|
|
@@ -115,11 +81,12 @@ dev
|
|
|
115
81
|
},
|
|
116
82
|
};
|
|
117
83
|
const generator = TJS.createGenerator({
|
|
118
|
-
path:
|
|
84
|
+
path: resolve(entryFile),
|
|
119
85
|
encodeRefs: false,
|
|
120
86
|
additionalProperties: true,
|
|
87
|
+
skipTypeCheck: true
|
|
121
88
|
});
|
|
122
|
-
const apiModel = new
|
|
89
|
+
const apiModel = new ApiModel();
|
|
123
90
|
const apiPackage = apiModel.loadPackage(extractorConfig.apiJsonFilePath);
|
|
124
91
|
const entry = apiPackage.entryPoints[0];
|
|
125
92
|
const pluginInterface = entry.findMembersByName(pluginInterfaceName)[0];
|
|
@@ -128,19 +95,30 @@ dev
|
|
|
128
95
|
method.pluginInterfaceName = pluginInterfaceName;
|
|
129
96
|
method.operationId = member.displayName;
|
|
130
97
|
// console.log(member)
|
|
131
|
-
method.parameters =
|
|
98
|
+
method.parameters = member.parameters[0]?.parameterTypeExcerpt?.text;
|
|
132
99
|
method.response = member.returnTypeExcerpt.text
|
|
133
100
|
.replace('Promise<', '')
|
|
134
101
|
.replace('>', '');
|
|
135
102
|
const methodSignature = member;
|
|
136
|
-
method.description =
|
|
103
|
+
method.description = methodSignature.tsdocComment?.summarySection
|
|
104
|
+
?.getChildNodes()[0]
|
|
105
|
+
//@ts-ignore
|
|
106
|
+
?.getChildNodes()[0]?.text;
|
|
137
107
|
method.description = method.description || '';
|
|
138
108
|
if (method.parameters) {
|
|
139
109
|
//@ts-ignore
|
|
140
|
-
api.components.schemas =
|
|
110
|
+
api.components.schemas = {
|
|
111
|
+
//@ts-ignore
|
|
112
|
+
...api.components.schemas,
|
|
113
|
+
...createSchema(generator, method.parameters).components.schemas,
|
|
114
|
+
};
|
|
141
115
|
}
|
|
142
116
|
//@ts-ignore
|
|
143
|
-
api.components.schemas =
|
|
117
|
+
api.components.schemas = {
|
|
118
|
+
//@ts-ignore
|
|
119
|
+
...api.components.schemas,
|
|
120
|
+
...createSchema(generator, method.response).components.schemas,
|
|
121
|
+
};
|
|
144
122
|
//@ts-ignore
|
|
145
123
|
api.components.methods[method.operationId] = {
|
|
146
124
|
description: method.description,
|
|
@@ -150,16 +128,16 @@ dev
|
|
|
150
128
|
}
|
|
151
129
|
interfaces[pluginInterfaceName] = api;
|
|
152
130
|
}
|
|
153
|
-
|
|
154
|
-
})
|
|
131
|
+
writeFileSync(resolve('./src/plugin.schema.json'), JSON.stringify(interfaces, null, 2));
|
|
132
|
+
});
|
|
155
133
|
dev
|
|
156
134
|
.command('extract-api')
|
|
157
135
|
.description('Extract API')
|
|
158
136
|
.option('-c, --extractorConfig <string>', 'API Extractor config file', './api-extractor.json')
|
|
159
|
-
.action((options) =>
|
|
160
|
-
const apiExtractorJsonPath =
|
|
161
|
-
const extractorConfig =
|
|
162
|
-
const extractorResult =
|
|
137
|
+
.action(async (options) => {
|
|
138
|
+
const apiExtractorJsonPath = resolve(options.extractorConfig);
|
|
139
|
+
const extractorConfig = ExtractorConfig.loadFileAndPrepare(apiExtractorJsonPath);
|
|
140
|
+
const extractorResult = Extractor.invoke(extractorConfig, {
|
|
163
141
|
localBuild: true,
|
|
164
142
|
showVerboseMessages: true,
|
|
165
143
|
});
|
|
@@ -168,5 +146,5 @@ dev
|
|
|
168
146
|
` and ${extractorResult.warningCount} warnings`);
|
|
169
147
|
process.exitCode = 1;
|
|
170
148
|
}
|
|
171
|
-
})
|
|
149
|
+
});
|
|
172
150
|
//# sourceMappingURL=dev.js.map
|