@verii/server-mockvendor 1.0.0-pre.1752076816
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/.localdev.env +15 -0
- package/.standalone.env +5 -0
- package/LICENSE +201 -0
- package/docker/compose.yml +25 -0
- package/jest.config.js +20 -0
- package/multilingual-string.schema.json +40 -0
- package/package.json +70 -0
- package/src/config/config.js +55 -0
- package/src/controllers/api/accepted-offers/controller.js +9 -0
- package/src/controllers/api/accepted-offers/repo.js +25 -0
- package/src/controllers/api/applicants/controller.js +9 -0
- package/src/controllers/api/applicants/repo.js +30 -0
- package/src/controllers/api/create_did_key/controller.js +29 -0
- package/src/controllers/api/create_did_key/schemas/index.js +4 -0
- package/src/controllers/api/create_did_key/schemas/jwk-did-request.schema.js +20 -0
- package/src/controllers/api/create_did_key/schemas/jwk-did-response.schema.js +41 -0
- package/src/controllers/api/create_jwk/controller.js +35 -0
- package/src/controllers/api/create_jwk/schemas/index.js +3 -0
- package/src/controllers/api/create_jwk/schemas/jwk-response.schema.js +33 -0
- package/src/controllers/api/credential-submissions/controller.js +59 -0
- package/src/controllers/api/credential-submissions/repo.js +16 -0
- package/src/controllers/api/identifications/controller.js +67 -0
- package/src/controllers/api/identifications/repo.js +22 -0
- package/src/controllers/api/issuing-exchanges/controller.js +218 -0
- package/src/controllers/api/issuing-exchanges/fetchers.js +45 -0
- package/src/controllers/api/issuing-exchanges/repo.js +27 -0
- package/src/controllers/api/jwt/controller.js +69 -0
- package/src/controllers/api/jwt/schemas/index.js +6 -0
- package/src/controllers/api/jwt/schemas/jwt-request.schema.js +40 -0
- package/src/controllers/api/jwt/schemas/jwt-response.schema.js +14 -0
- package/src/controllers/api/jwt/schemas/jwt-verify-request.schema.js +17 -0
- package/src/controllers/api/jwt/schemas/jwt-verify-response.schema.js +17 -0
- package/src/controllers/api/offers/autohooks.js +5 -0
- package/src/controllers/api/offers/controller.js +87 -0
- package/src/controllers/api/offers/new-mockvendor-offer.schema.js +22 -0
- package/src/controllers/api/offers/repo.js +33 -0
- package/src/controllers/api/users/controller.js +20 -0
- package/src/controllers/api/users/repo.js +29 -0
- package/src/controllers/autohooks.js +22 -0
- package/src/controllers/inspection/controller.js +39 -0
- package/src/controllers/issuing/controller.js +158 -0
- package/src/controllers/registrar/controller.js +67 -0
- package/src/controllers/registrar/repo.js +24 -0
- package/src/controllers/root/controller.js +15 -0
- package/src/controllers/schemas/index.js +21 -0
- package/src/controllers/schemas/issuer-data.schema.json +26 -0
- package/src/entities/index.js +4 -0
- package/src/entities/key-pairs/index.js +3 -0
- package/src/entities/key-pairs/key-pairs.js +73 -0
- package/src/entities/offers/index.js +3 -0
- package/src/entities/offers/schemas/generate-offers.schema.js +30 -0
- package/src/entities/offers/schemas/index.js +3 -0
- package/src/index.js +19 -0
- package/src/init-server.js +34 -0
- package/src/main.js +18 -0
- package/src/standalone.js +8 -0
- package/src/start-app-server.js +32 -0
- package/test/accepted-offers.test.js +47 -0
- package/test/api-users.test.js +170 -0
- package/test/create_did_key-controller.test.js +94 -0
- package/test/create_jwk-controller.test.js +86 -0
- package/test/credential-submissions.test.js +331 -0
- package/test/factories/accepted-offers.factory.js +16 -0
- package/test/factories/delayed-offer.factory.js +17 -0
- package/test/factories/identifications.factory.js +33 -0
- package/test/factories/offers.factory.js +64 -0
- package/test/factories/users.factory.js +24 -0
- package/test/helpers/PastEmploymentPosition-2007-2009-Junior-Project-Manager.json +26 -0
- package/test/helpers/PastEmploymentPosition-2009-2015-Project-Manager.json +26 -0
- package/test/helpers/helpers/PastEmploymentPosition-2009-2015-Project-Manager.json +26 -0
- package/test/helpers/latest-Adam-Smith.json +49 -0
- package/test/helpers/legacy-Adam-Smith.json +33 -0
- package/test/helpers/mockvendor-build-fastify.js +16 -0
- package/test/helpers/tools/verifgen/templates/PastEmploymentPosition-2009-2015-Project-Manager.json +26 -0
- package/test/identifications.test.js +56 -0
- package/test/issuing-exchanges.test.js +335 -0
- package/test/issuing-identify.test.js +137 -0
- package/test/jwt-controller.test.js +320 -0
- package/test/offers.test.js +682 -0
- package/test/registrar.test.js +276 -0
- package/test/root.test.js +25 -0
- package/test/swagger.test.js +21 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const jwkResponse = {
|
|
2
|
+
title: 'jwk-response',
|
|
3
|
+
$id: 'https://velocitycareerlabs.io/jwk-response.schema.json',
|
|
4
|
+
description: 'jwk response schema',
|
|
5
|
+
type: 'object',
|
|
6
|
+
properties: {
|
|
7
|
+
jwk: {
|
|
8
|
+
type: 'object',
|
|
9
|
+
required: ['kty'],
|
|
10
|
+
properties: {
|
|
11
|
+
kty: { type: 'string' },
|
|
12
|
+
use: { type: 'string' },
|
|
13
|
+
key_ops: { type: 'string' },
|
|
14
|
+
x5u: { type: 'string' },
|
|
15
|
+
x5c: { type: 'string' },
|
|
16
|
+
x5t: { type: 'string' },
|
|
17
|
+
'x5t#S256': { type: 'string' },
|
|
18
|
+
alg: { type: 'string' },
|
|
19
|
+
kid: { type: 'string' },
|
|
20
|
+
exp: { type: 'string' },
|
|
21
|
+
crv: { type: 'string' },
|
|
22
|
+
y: { type: 'string' },
|
|
23
|
+
x: { type: 'string' },
|
|
24
|
+
n: { type: 'string' },
|
|
25
|
+
e: { type: 'string' },
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
keyId: { type: 'string' },
|
|
29
|
+
},
|
|
30
|
+
required: ['jwk', 'keyId'],
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
module.exports = { jwkResponse };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const { isEmpty, set } = require('lodash/fp');
|
|
2
|
+
const { endOfDay, startOfDay } = require('date-fns/fp');
|
|
3
|
+
|
|
4
|
+
module.exports = async (fastify) => {
|
|
5
|
+
fastify.get(
|
|
6
|
+
'/',
|
|
7
|
+
{
|
|
8
|
+
onRequest: fastify.verifyAdmin,
|
|
9
|
+
schema: {
|
|
10
|
+
query: {
|
|
11
|
+
type: 'object',
|
|
12
|
+
properties: {
|
|
13
|
+
vendorDisclosureId: {
|
|
14
|
+
type: 'string',
|
|
15
|
+
description:
|
|
16
|
+
'(optional) the vendor disclosure id to get submissions for',
|
|
17
|
+
},
|
|
18
|
+
dateFrom: {
|
|
19
|
+
type: 'string',
|
|
20
|
+
format: 'date',
|
|
21
|
+
description:
|
|
22
|
+
'(optional) only get submissions for dates on or after this date',
|
|
23
|
+
},
|
|
24
|
+
dateUntil: {
|
|
25
|
+
type: 'string',
|
|
26
|
+
format: 'date',
|
|
27
|
+
description:
|
|
28
|
+
'(optional) only get submissions for dates on or before this date',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
async ({ repos, query }) => {
|
|
35
|
+
let filter = {};
|
|
36
|
+
if (!isEmpty(query.vendorDisclosureId)) {
|
|
37
|
+
filter = set('vendorDisclosureId', query.vendorDisclosureId, filter);
|
|
38
|
+
}
|
|
39
|
+
if (!isEmpty(query.dateFrom)) {
|
|
40
|
+
filter = set(
|
|
41
|
+
'createdAt.$gte',
|
|
42
|
+
startOfDay(new Date(query.dateFrom)),
|
|
43
|
+
filter
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
if (!isEmpty(query.dateUntil)) {
|
|
47
|
+
filter = set(
|
|
48
|
+
'createdAt.$lte',
|
|
49
|
+
endOfDay(new Date(query.dateFrom)),
|
|
50
|
+
filter
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
return repos.credentialSubmissions.find({
|
|
54
|
+
filter,
|
|
55
|
+
sort: { createdAt: -1 },
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const {
|
|
2
|
+
autoboxIdsExtension,
|
|
3
|
+
repoFactory,
|
|
4
|
+
} = require('@spencejs/spence-mongo-repos');
|
|
5
|
+
|
|
6
|
+
module.exports = (app, opts, next = () => {}) => {
|
|
7
|
+
next();
|
|
8
|
+
return repoFactory(
|
|
9
|
+
{
|
|
10
|
+
name: 'credentialSubmissions',
|
|
11
|
+
entityName: 'credentialSubmission',
|
|
12
|
+
extensions: [autoboxIdsExtension],
|
|
13
|
+
},
|
|
14
|
+
app
|
|
15
|
+
);
|
|
16
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const { isEmpty, set } = require('lodash/fp');
|
|
2
|
+
const { endOfDay, startOfDay } = require('date-fns/fp');
|
|
3
|
+
|
|
4
|
+
module.exports = async (fastify) => {
|
|
5
|
+
fastify.get(
|
|
6
|
+
'/',
|
|
7
|
+
{
|
|
8
|
+
onRequest: fastify.verifyAdmin,
|
|
9
|
+
schema: {
|
|
10
|
+
query: {
|
|
11
|
+
type: 'object',
|
|
12
|
+
properties: {
|
|
13
|
+
dateFrom: {
|
|
14
|
+
type: 'string',
|
|
15
|
+
format: 'date',
|
|
16
|
+
description:
|
|
17
|
+
'(optional) only get submissions for dates on or after this date',
|
|
18
|
+
},
|
|
19
|
+
dateUntil: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
format: 'date',
|
|
22
|
+
description:
|
|
23
|
+
'(optional) only get submissions for dates on or before this date',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
response: {
|
|
28
|
+
200: {
|
|
29
|
+
type: 'object',
|
|
30
|
+
properties: {
|
|
31
|
+
identifications: {
|
|
32
|
+
type: 'array',
|
|
33
|
+
items: {
|
|
34
|
+
type: 'object',
|
|
35
|
+
additionalProperties: true,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
async ({ repos, query }) => {
|
|
44
|
+
let filter = {};
|
|
45
|
+
if (!isEmpty(query.dateFrom)) {
|
|
46
|
+
filter = set(
|
|
47
|
+
'createdAt.$gte',
|
|
48
|
+
startOfDay(new Date(query.dateFrom)),
|
|
49
|
+
filter
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
if (!isEmpty(query.dateUntil)) {
|
|
53
|
+
filter = set(
|
|
54
|
+
'createdAt.$lte',
|
|
55
|
+
endOfDay(new Date(query.dateFrom)),
|
|
56
|
+
filter
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
const identifications = await repos.identifications.find({
|
|
60
|
+
filter,
|
|
61
|
+
sort: { createdAt: -1 },
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return { identifications };
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const {
|
|
2
|
+
autoboxIdsExtension,
|
|
3
|
+
repoFactory,
|
|
4
|
+
} = require('@spencejs/spence-mongo-repos');
|
|
5
|
+
|
|
6
|
+
module.exports = (app, opts, next = () => {}) => {
|
|
7
|
+
next();
|
|
8
|
+
return repoFactory(
|
|
9
|
+
{
|
|
10
|
+
name: 'identifications',
|
|
11
|
+
entityName: 'identification',
|
|
12
|
+
extensions: [autoboxIdsExtension],
|
|
13
|
+
mutable: false,
|
|
14
|
+
defaultProjection: {
|
|
15
|
+
_id: 1,
|
|
16
|
+
identification: 1,
|
|
17
|
+
createdAt: 1,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
app
|
|
21
|
+
);
|
|
22
|
+
};
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
const { map, omit, castArray, isNil, omitBy } = require('lodash/fp');
|
|
2
|
+
const { nanoid } = require('nanoid');
|
|
3
|
+
const {
|
|
4
|
+
submitCreateExchange,
|
|
5
|
+
submitOffer,
|
|
6
|
+
completeSubmitOffer,
|
|
7
|
+
getExchangeQrCode,
|
|
8
|
+
} = require('./fetchers');
|
|
9
|
+
|
|
10
|
+
const createExchange = async (tenantDID, context) => {
|
|
11
|
+
const exchange = await submitCreateExchange(tenantDID, 'ISSUING', context);
|
|
12
|
+
|
|
13
|
+
await context.repos.issuingExchanges.insert({
|
|
14
|
+
exchangeId: exchange.id,
|
|
15
|
+
tenantDID,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return exchange.id;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const prepOffer = (exchangeId, tenantDID) => (offer) => ({
|
|
22
|
+
offerId: nanoid(),
|
|
23
|
+
exchangeId,
|
|
24
|
+
issuer: { id: tenantDID },
|
|
25
|
+
...offer,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const createCredentialAgentOffers = async (
|
|
29
|
+
offers,
|
|
30
|
+
tenantDID,
|
|
31
|
+
exchangeId,
|
|
32
|
+
context
|
|
33
|
+
) => {
|
|
34
|
+
const { repos } = context;
|
|
35
|
+
|
|
36
|
+
const insertedOffers = await repos.offers.insertMany(
|
|
37
|
+
map(prepOffer(exchangeId, tenantDID), offers)
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
await Promise.all(
|
|
41
|
+
map(
|
|
42
|
+
(offer) =>
|
|
43
|
+
submitOffer(
|
|
44
|
+
{
|
|
45
|
+
offer: omit(['id', 'exchangeId'], offer),
|
|
46
|
+
exchangeId,
|
|
47
|
+
tenantDID,
|
|
48
|
+
},
|
|
49
|
+
context
|
|
50
|
+
),
|
|
51
|
+
insertedOffers
|
|
52
|
+
)
|
|
53
|
+
);
|
|
54
|
+
await completeSubmitOffer({ exchangeId, tenantDID }, context);
|
|
55
|
+
return { exchangeId, tenantDID, offers: insertedOffers };
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const controller = async (fastify) => {
|
|
59
|
+
fastify.get(
|
|
60
|
+
'/:tenantDID',
|
|
61
|
+
{
|
|
62
|
+
onRequest: fastify.verifyAdmin,
|
|
63
|
+
schema: {
|
|
64
|
+
params: {
|
|
65
|
+
type: 'object',
|
|
66
|
+
properties: {
|
|
67
|
+
tenantDID: { type: 'string' },
|
|
68
|
+
},
|
|
69
|
+
required: ['tenantDID'],
|
|
70
|
+
},
|
|
71
|
+
query: {
|
|
72
|
+
type: 'object',
|
|
73
|
+
properties: {
|
|
74
|
+
exchangeId: { type: 'string' },
|
|
75
|
+
issuer: { type: 'string' },
|
|
76
|
+
vendorUserId: { type: 'string' },
|
|
77
|
+
date: { type: 'string', format: 'date-time' },
|
|
78
|
+
credentialTypes: {
|
|
79
|
+
oneOf: [
|
|
80
|
+
{ type: 'string' },
|
|
81
|
+
{ type: 'array', items: { type: 'string' } },
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
async (req) => {
|
|
89
|
+
const {
|
|
90
|
+
query: { credentialTypes, exchangeId, vendorUserId, date },
|
|
91
|
+
params: { tenantDID },
|
|
92
|
+
repos,
|
|
93
|
+
} = req;
|
|
94
|
+
return repos.issuingExchanges.find({
|
|
95
|
+
filter: omitBy(isNil, {
|
|
96
|
+
exchangeId,
|
|
97
|
+
issuer: { id: tenantDID },
|
|
98
|
+
vendorUserId,
|
|
99
|
+
createdAt: date ? { $gte: new Date(date) } : undefined,
|
|
100
|
+
type: {
|
|
101
|
+
$in: castArray(credentialTypes),
|
|
102
|
+
},
|
|
103
|
+
}),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
fastify.post(
|
|
108
|
+
'/:tenantDID/:exchangeId/push-offers',
|
|
109
|
+
{
|
|
110
|
+
onRequest: fastify.verifyAdmin,
|
|
111
|
+
schema: {
|
|
112
|
+
params: {
|
|
113
|
+
type: 'object',
|
|
114
|
+
properties: {
|
|
115
|
+
exchangeId: { type: 'string' },
|
|
116
|
+
tenantDID: { type: 'string' },
|
|
117
|
+
},
|
|
118
|
+
required: ['tenantDID', 'exchangeId'],
|
|
119
|
+
},
|
|
120
|
+
body: {
|
|
121
|
+
type: 'object',
|
|
122
|
+
required: ['offer'],
|
|
123
|
+
properties: {
|
|
124
|
+
offer: {
|
|
125
|
+
oneOf: [
|
|
126
|
+
{
|
|
127
|
+
$ref: 'https://velocitycareerlabs.io/new-vendor-offer.schema.json#',
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
type: 'array',
|
|
131
|
+
items: {
|
|
132
|
+
$ref: 'https://velocitycareerlabs.io/new-vendor-offer.schema.json#',
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
async (req) => {
|
|
142
|
+
const {
|
|
143
|
+
body: { offer },
|
|
144
|
+
params: { exchangeId, tenantDID },
|
|
145
|
+
} = req;
|
|
146
|
+
const { offers } = await createCredentialAgentOffers(
|
|
147
|
+
castArray(offer),
|
|
148
|
+
tenantDID,
|
|
149
|
+
exchangeId,
|
|
150
|
+
req
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
return offers;
|
|
154
|
+
}
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
fastify.post(
|
|
158
|
+
'/:tenantDID/create-qrcode',
|
|
159
|
+
{
|
|
160
|
+
onRequest: fastify.verifyAdmin,
|
|
161
|
+
schema: {
|
|
162
|
+
params: {
|
|
163
|
+
type: 'object',
|
|
164
|
+
properties: {
|
|
165
|
+
tenantDID: { type: 'string' },
|
|
166
|
+
},
|
|
167
|
+
required: ['tenantDID'],
|
|
168
|
+
},
|
|
169
|
+
body: {
|
|
170
|
+
type: 'object',
|
|
171
|
+
required: ['offer'],
|
|
172
|
+
properties: {
|
|
173
|
+
vendorOriginContext: {
|
|
174
|
+
type: 'string',
|
|
175
|
+
},
|
|
176
|
+
offer: {
|
|
177
|
+
oneOf: [
|
|
178
|
+
{
|
|
179
|
+
$ref: 'https://velocitycareerlabs.io/new-vendor-offer.schema.json#',
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
type: 'array',
|
|
183
|
+
items: {
|
|
184
|
+
$ref: 'https://velocitycareerlabs.io/new-vendor-offer.schema.json#',
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
async (req, reply) => {
|
|
194
|
+
const {
|
|
195
|
+
body: { offer, vendorOriginContext },
|
|
196
|
+
params: { tenantDID },
|
|
197
|
+
} = req;
|
|
198
|
+
const exchangeId = await createExchange(tenantDID, req);
|
|
199
|
+
await createCredentialAgentOffers(
|
|
200
|
+
castArray(offer),
|
|
201
|
+
tenantDID,
|
|
202
|
+
exchangeId,
|
|
203
|
+
req
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
const response = await getExchangeQrCode(
|
|
207
|
+
tenantDID,
|
|
208
|
+
exchangeId,
|
|
209
|
+
vendorOriginContext,
|
|
210
|
+
req
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
return reply.type('image/png').send(response.rawBody);
|
|
214
|
+
}
|
|
215
|
+
);
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
module.exports = controller;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const submitCreateExchange = (tenantDID, type, { agentFetch }) =>
|
|
2
|
+
agentFetch
|
|
3
|
+
.post(`operator-api/v0.8/tenants/${tenantDID}/exchanges`, {
|
|
4
|
+
json: { type },
|
|
5
|
+
})
|
|
6
|
+
.json();
|
|
7
|
+
|
|
8
|
+
const getExchangeQrCode = (
|
|
9
|
+
tenantDID,
|
|
10
|
+
exchangeId,
|
|
11
|
+
vendorOriginContext,
|
|
12
|
+
{ agentFetch }
|
|
13
|
+
) => {
|
|
14
|
+
const urlSearchParams = new URLSearchParams();
|
|
15
|
+
if (vendorOriginContext != null) {
|
|
16
|
+
urlSearchParams.set('vendorOriginContext', vendorOriginContext);
|
|
17
|
+
}
|
|
18
|
+
return agentFetch.get(
|
|
19
|
+
`operator-api/v0.8/tenants/${tenantDID}/exchanges/${exchangeId}/qrcode.png?${urlSearchParams.toString()}`
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const submitOffer = ({ offer, tenantDID, exchangeId }, { agentFetch }) =>
|
|
24
|
+
agentFetch
|
|
25
|
+
.post(
|
|
26
|
+
`operator-api/v0.8/tenants/${tenantDID}/exchanges/${exchangeId}/offers`,
|
|
27
|
+
{
|
|
28
|
+
json: offer,
|
|
29
|
+
}
|
|
30
|
+
)
|
|
31
|
+
.json();
|
|
32
|
+
|
|
33
|
+
const completeSubmitOffer = ({ exchangeId, tenantDID }, { agentFetch }) =>
|
|
34
|
+
agentFetch
|
|
35
|
+
.post(
|
|
36
|
+
`operator-api/v0.8/tenants/${tenantDID}/exchanges/${exchangeId}/offers/complete`
|
|
37
|
+
)
|
|
38
|
+
.json();
|
|
39
|
+
|
|
40
|
+
module.exports = {
|
|
41
|
+
submitOffer,
|
|
42
|
+
completeSubmitOffer,
|
|
43
|
+
submitCreateExchange,
|
|
44
|
+
getExchangeQrCode,
|
|
45
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const {
|
|
2
|
+
autoboxIdsExtension,
|
|
3
|
+
repoFactory,
|
|
4
|
+
} = require('@spencejs/spence-mongo-repos');
|
|
5
|
+
|
|
6
|
+
const repo = (app, opts, next = () => {}) => {
|
|
7
|
+
next();
|
|
8
|
+
return repoFactory(
|
|
9
|
+
{
|
|
10
|
+
name: 'issuingExchanges',
|
|
11
|
+
entityName: 'issuingExchange',
|
|
12
|
+
defaultProjection: {
|
|
13
|
+
_id: 1,
|
|
14
|
+
type: 1,
|
|
15
|
+
issuer: 1,
|
|
16
|
+
exchangeId: 1,
|
|
17
|
+
vendorUserId: 1,
|
|
18
|
+
createdAt: 1,
|
|
19
|
+
updatedAt: 1,
|
|
20
|
+
},
|
|
21
|
+
extensions: [autoboxIdsExtension],
|
|
22
|
+
},
|
|
23
|
+
app
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
module.exports = repo;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const { jwtSign, jwtVerify, deriveJwk } = require('@verii/jwt');
|
|
2
|
+
const {
|
|
3
|
+
jwtRequest,
|
|
4
|
+
jwtResponse,
|
|
5
|
+
jwtVerifyRequest,
|
|
6
|
+
jwtVerifyResponse,
|
|
7
|
+
} = require('./schemas');
|
|
8
|
+
const { getKeyPair } = require('../../../entities');
|
|
9
|
+
|
|
10
|
+
const controller = async (fastify) => {
|
|
11
|
+
fastify.post(
|
|
12
|
+
'/sign',
|
|
13
|
+
{
|
|
14
|
+
schema: {
|
|
15
|
+
tags: ['jose'],
|
|
16
|
+
body: jwtRequest,
|
|
17
|
+
response: {
|
|
18
|
+
200: jwtResponse,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
async (req) => {
|
|
23
|
+
const { body } = req;
|
|
24
|
+
const { header, payload, options } = body;
|
|
25
|
+
|
|
26
|
+
const keyPair = getKeyPair(options);
|
|
27
|
+
|
|
28
|
+
const compactJwt = await jwtSign(payload, keyPair.privateKey, {
|
|
29
|
+
...header,
|
|
30
|
+
alg: keyPair.alg,
|
|
31
|
+
jwk: keyPair.publicKey,
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
compactJwt,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
fastify.post(
|
|
40
|
+
'/verify',
|
|
41
|
+
{
|
|
42
|
+
schema: {
|
|
43
|
+
tags: ['jose'],
|
|
44
|
+
body: jwtVerifyRequest,
|
|
45
|
+
response: {
|
|
46
|
+
200: jwtVerifyResponse,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
async (req) => {
|
|
51
|
+
const { body } = req;
|
|
52
|
+
const { jwt, publicKey } = body;
|
|
53
|
+
try {
|
|
54
|
+
const jwk = deriveJwk(jwt, publicKey);
|
|
55
|
+
await jwtVerify(jwt, jwk);
|
|
56
|
+
return {
|
|
57
|
+
verified: true,
|
|
58
|
+
};
|
|
59
|
+
} catch (e) {
|
|
60
|
+
return {
|
|
61
|
+
verified: false,
|
|
62
|
+
error: e,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
module.exports = controller;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const jwtRequest = {
|
|
2
|
+
title: 'jwt-request',
|
|
3
|
+
$id: 'https://velocitycareerlabs.io/jwt-request.schema.json',
|
|
4
|
+
description: 'jwt request schema',
|
|
5
|
+
type: 'object',
|
|
6
|
+
properties: {
|
|
7
|
+
header: {
|
|
8
|
+
type: 'object',
|
|
9
|
+
},
|
|
10
|
+
payload: {
|
|
11
|
+
type: 'object',
|
|
12
|
+
},
|
|
13
|
+
options: {
|
|
14
|
+
type: 'object',
|
|
15
|
+
oneOf: [
|
|
16
|
+
{
|
|
17
|
+
required: ['kid'],
|
|
18
|
+
properties: {
|
|
19
|
+
kid: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
minLength: 1,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
required: ['keyId'],
|
|
27
|
+
properties: {
|
|
28
|
+
keyId: {
|
|
29
|
+
type: 'string',
|
|
30
|
+
minLength: 1,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
required: ['payload', 'options'],
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
module.exports = { jwtRequest };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const jwtResponse = {
|
|
2
|
+
title: 'jwt-response',
|
|
3
|
+
$id: 'https://velocitycareerlabs.io/jwt-response.schema.json',
|
|
4
|
+
description: 'jwt response schema',
|
|
5
|
+
type: 'object',
|
|
6
|
+
properties: {
|
|
7
|
+
compactJwt: {
|
|
8
|
+
type: 'string',
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
required: ['compactJwt'],
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
module.exports = { jwtResponse };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const jwtVerifyRequest = {
|
|
2
|
+
title: 'jwt-verify-request',
|
|
3
|
+
$id: 'https://velocitycareerlabs.io/jwt-verify-request.schema.json',
|
|
4
|
+
description: 'jwt verify request schema',
|
|
5
|
+
type: 'object',
|
|
6
|
+
properties: {
|
|
7
|
+
jwt: {
|
|
8
|
+
type: 'string',
|
|
9
|
+
},
|
|
10
|
+
publicKey: {
|
|
11
|
+
type: 'object',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
required: ['jwt'],
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
module.exports = { jwtVerifyRequest };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const jwtVerifyResponse = {
|
|
2
|
+
title: 'jwt-verify-response',
|
|
3
|
+
$id: 'https://velocitycareerlabs.io/jwt-verify-response.schema.json',
|
|
4
|
+
description: 'jwt verify response schema',
|
|
5
|
+
type: 'object',
|
|
6
|
+
properties: {
|
|
7
|
+
verified: {
|
|
8
|
+
type: 'boolean',
|
|
9
|
+
},
|
|
10
|
+
error: {
|
|
11
|
+
type: 'string',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
required: ['verified'],
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
module.exports = { jwtVerifyResponse };
|