@sphereon/ssi-sdk.w3c-vc-api 0.18.2-next.9 → 0.18.2-unstable.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/VCAPIServer.d.ts +74 -0
- package/dist/VCAPIServer.d.ts.map +1 -0
- package/dist/VCAPIServer.js +333 -0
- package/dist/VCAPIServer.js.map +1 -0
- package/dist/api-functions.d.ts +8 -8
- package/dist/api-functions.js +157 -157
- package/dist/index.d.ts +6 -6
- package/dist/index.js +22 -22
- package/dist/request-agent-router.d.ts +30 -0
- package/dist/request-agent-router.d.ts.map +1 -0
- package/dist/request-agent-router.js +63 -0
- package/dist/request-agent-router.js.map +1 -0
- package/dist/types.d.ts +65 -65
- package/dist/types.js +2 -2
- package/dist/vc-api-server.d.ts +19 -19
- package/dist/vc-api-server.js +64 -64
- package/package.json +12 -12
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { TAgent } from '@veramo/core'
|
|
2
|
+
import { ProofFormat } from '@veramo/core/src/types/ICredentialIssuer'
|
|
3
|
+
import { Express } from 'express'
|
|
4
|
+
import { IRequiredPlugins } from './types'
|
|
5
|
+
export interface IVCAPIOpts {
|
|
6
|
+
issueCredentialOpts?: IIssueOpts
|
|
7
|
+
serverOpts?: IServerOpts
|
|
8
|
+
}
|
|
9
|
+
export interface IServerOpts {
|
|
10
|
+
port?: number
|
|
11
|
+
cookieSigningKey?: string
|
|
12
|
+
hostname?: string
|
|
13
|
+
}
|
|
14
|
+
export interface IIssueOpts {
|
|
15
|
+
issueCredentialPath?: string
|
|
16
|
+
getCredentialsPath?: string
|
|
17
|
+
getCredentialPath?: string
|
|
18
|
+
deleteCredentialPath?: string
|
|
19
|
+
verifyCredentialPath?: string
|
|
20
|
+
verifyPresentationPath?: string
|
|
21
|
+
persistIssuedCredentials?: boolean
|
|
22
|
+
/**
|
|
23
|
+
* The desired format for the VerifiablePresentation to be created.
|
|
24
|
+
*/
|
|
25
|
+
proofFormat: ProofFormat
|
|
26
|
+
/**
|
|
27
|
+
* Remove payload members during JWT-JSON transformation. Defaults to `true`.
|
|
28
|
+
* See https://www.w3.org/TR/vc-data-model/#jwt-encoding
|
|
29
|
+
*/
|
|
30
|
+
removeOriginalFields?: boolean
|
|
31
|
+
/**
|
|
32
|
+
* [Optional] The ID of the key that should sign this credential.
|
|
33
|
+
* If this is not specified, the first matching key will be used.
|
|
34
|
+
*/
|
|
35
|
+
keyRef?: string
|
|
36
|
+
/**
|
|
37
|
+
* When dealing with JSON-LD you also MUST provide the proper contexts.
|
|
38
|
+
* Set this to `true` ONLY if you want the `@context` URLs to be fetched in case they are not preloaded.
|
|
39
|
+
* The context definitions SHOULD rather be provided at startup instead of being fetched.
|
|
40
|
+
*
|
|
41
|
+
* Defaults to `false`
|
|
42
|
+
*/
|
|
43
|
+
fetchRemoteContexts?: boolean
|
|
44
|
+
}
|
|
45
|
+
export interface IIssueOptionsPayload {
|
|
46
|
+
created?: string
|
|
47
|
+
challenge?: string
|
|
48
|
+
domain?: string
|
|
49
|
+
credentialStatus?: {
|
|
50
|
+
type: string
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export interface ChallengeOptsPayload {
|
|
54
|
+
challenge?: string
|
|
55
|
+
domain?: string
|
|
56
|
+
}
|
|
57
|
+
export declare class VCAPIServer {
|
|
58
|
+
private readonly _express
|
|
59
|
+
private readonly _agent
|
|
60
|
+
private readonly _opts?
|
|
61
|
+
constructor(args: { agent: TAgent<IRequiredPlugins>; express?: Express; opts?: IVCAPIOpts })
|
|
62
|
+
get agent(): TAgent<IRequiredPlugins>
|
|
63
|
+
get opts(): IVCAPIOpts | undefined
|
|
64
|
+
get express(): Express
|
|
65
|
+
private setupExpress
|
|
66
|
+
private static sendErrorResponse
|
|
67
|
+
private getCredentialsEndpoint
|
|
68
|
+
private getCredentialEndpoint
|
|
69
|
+
private verifyCredentialEndpoint
|
|
70
|
+
private deleteCredentialEndpoint
|
|
71
|
+
private issueCredentialEndpoint
|
|
72
|
+
private getCredentialByIdOrHash
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=VCAPIServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VCAPIServer.d.ts","sourceRoot":"","sources":["../src/VCAPIServer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqB,MAAM,EAAwB,MAAM,cAAc,CAAA;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAA;AAKtE,OAAgB,EAAE,OAAO,EAAqB,MAAM,SAAS,CAAA;AAE7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE1C,MAAM,WAAW,UAAU;IACzB,mBAAmB,CAAC,EAAE,UAAU,CAAA;IAChC,UAAU,CAAC,EAAE,WAAW,CAAA;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,UAAU;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,sBAAsB,CAAC,EAAE,MAAM,CAAA;IAE/B,wBAAwB,CAAC,EAAE,OAAO,CAAA;IAElC;;OAEG;IACH,WAAW,EAAE,WAAW,CAAA;IAExB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAE9B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf;;;;;;OAMG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAC9B;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,gBAAgB,CAAC,EAAE;QACjB,IAAI,EAAE,MAAM,CAAA;KACb,CAAA;CACF;AAED,MAAM,WAAW,oBAAoB;IACnC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0B;IACjD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAY;gBAEvB,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,UAAU,CAAA;KAAE;IAgB3F,IAAI,KAAK,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAEpC;IAED,IAAI,IAAI,IAAI,UAAU,GAAG,SAAS,CAEjC;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,OAAO,CAAC,YAAY;IA4BpB,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAMhC,OAAO,CAAC,sBAAsB;IAa9B,OAAO,CAAC,qBAAqB;IAoB7B,OAAO,CAAC,wBAAwB;IA0BhC,OAAO,CAAC,wBAAwB;IAwBhC,OAAO,CAAC,uBAAuB;YA2BjB,uBAAuB;CA+BtC"}
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
// noinspection JSUnusedGlobalSymbols
|
|
3
|
+
var __createBinding =
|
|
4
|
+
(this && this.__createBinding) ||
|
|
5
|
+
(Object.create
|
|
6
|
+
? function (o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k)
|
|
9
|
+
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return m[k]
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
Object.defineProperty(o, k2, desc)
|
|
18
|
+
}
|
|
19
|
+
: function (o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k
|
|
21
|
+
o[k2] = m[k]
|
|
22
|
+
})
|
|
23
|
+
var __setModuleDefault =
|
|
24
|
+
(this && this.__setModuleDefault) ||
|
|
25
|
+
(Object.create
|
|
26
|
+
? function (o, v) {
|
|
27
|
+
Object.defineProperty(o, 'default', { enumerable: true, value: v })
|
|
28
|
+
}
|
|
29
|
+
: function (o, v) {
|
|
30
|
+
o['default'] = v
|
|
31
|
+
})
|
|
32
|
+
var __importStar =
|
|
33
|
+
(this && this.__importStar) ||
|
|
34
|
+
function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod
|
|
36
|
+
var result = {}
|
|
37
|
+
if (mod != null) for (var k in mod) if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k)
|
|
38
|
+
__setModuleDefault(result, mod)
|
|
39
|
+
return result
|
|
40
|
+
}
|
|
41
|
+
var __awaiter =
|
|
42
|
+
(this && this.__awaiter) ||
|
|
43
|
+
function (thisArg, _arguments, P, generator) {
|
|
44
|
+
function adopt(value) {
|
|
45
|
+
return value instanceof P
|
|
46
|
+
? value
|
|
47
|
+
: new P(function (resolve) {
|
|
48
|
+
resolve(value)
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
52
|
+
function fulfilled(value) {
|
|
53
|
+
try {
|
|
54
|
+
step(generator.next(value))
|
|
55
|
+
} catch (e) {
|
|
56
|
+
reject(e)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function rejected(value) {
|
|
60
|
+
try {
|
|
61
|
+
step(generator['throw'](value))
|
|
62
|
+
} catch (e) {
|
|
63
|
+
reject(e)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function step(result) {
|
|
67
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected)
|
|
68
|
+
}
|
|
69
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next())
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
var __importDefault =
|
|
73
|
+
(this && this.__importDefault) ||
|
|
74
|
+
function (mod) {
|
|
75
|
+
return mod && mod.__esModule ? mod : { default: mod }
|
|
76
|
+
}
|
|
77
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
78
|
+
exports.VCAPIServer = void 0
|
|
79
|
+
const body_parser_1 = __importDefault(require('body-parser'))
|
|
80
|
+
const cookie_parser_1 = __importDefault(require('cookie-parser'))
|
|
81
|
+
const dotenv = __importStar(require('dotenv-flow'))
|
|
82
|
+
const express_1 = __importDefault(require('express'))
|
|
83
|
+
const uuid_1 = require('uuid')
|
|
84
|
+
class VCAPIServer {
|
|
85
|
+
constructor(args) {
|
|
86
|
+
var _a
|
|
87
|
+
const { agent, opts } = args
|
|
88
|
+
this._agent = agent
|
|
89
|
+
this._opts = opts
|
|
90
|
+
const existingExpress = !!args.express
|
|
91
|
+
this._express = (_a = args.express) !== null && _a !== void 0 ? _a : (0, express_1.default)()
|
|
92
|
+
this.setupExpress(existingExpress)
|
|
93
|
+
// Credential endpoints
|
|
94
|
+
this.issueCredentialEndpoint()
|
|
95
|
+
this.getCredentialEndpoint()
|
|
96
|
+
this.getCredentialsEndpoint()
|
|
97
|
+
this.deleteCredentialEndpoint() // not in spec. TODO: Authz
|
|
98
|
+
this.verifyCredentialEndpoint()
|
|
99
|
+
}
|
|
100
|
+
get agent() {
|
|
101
|
+
return this._agent
|
|
102
|
+
}
|
|
103
|
+
get opts() {
|
|
104
|
+
return this._opts
|
|
105
|
+
}
|
|
106
|
+
get express() {
|
|
107
|
+
return this._express
|
|
108
|
+
}
|
|
109
|
+
setupExpress(existingExpress) {
|
|
110
|
+
var _a, _b, _c, _d, _e, _f
|
|
111
|
+
dotenv.config()
|
|
112
|
+
if (!existingExpress) {
|
|
113
|
+
const port =
|
|
114
|
+
((_b = (_a = this.opts) === null || _a === void 0 ? void 0 : _a.serverOpts) === null || _b === void 0 ? void 0 : _b.port) ||
|
|
115
|
+
process.env.PORT ||
|
|
116
|
+
5000
|
|
117
|
+
const secret =
|
|
118
|
+
((_d = (_c = this.opts) === null || _c === void 0 ? void 0 : _c.serverOpts) === null || _d === void 0 ? void 0 : _d.cookieSigningKey) ||
|
|
119
|
+
process.env.COOKIE_SIGNING_KEY
|
|
120
|
+
const hostname =
|
|
121
|
+
((_f = (_e = this.opts) === null || _e === void 0 ? void 0 : _e.serverOpts) === null || _f === void 0 ? void 0 : _f.hostname) || '0.0.0.0'
|
|
122
|
+
this._express.use((req, res, next) => {
|
|
123
|
+
res.header('Access-Control-Allow-Origin', '*')
|
|
124
|
+
// Request methods you wish to allow
|
|
125
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE')
|
|
126
|
+
// Request headers you wish to allow
|
|
127
|
+
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type')
|
|
128
|
+
// Set to true if you need the website to include cookies in the requests sent
|
|
129
|
+
// to the API (e.g. in case you use sessions)
|
|
130
|
+
res.setHeader('Access-Control-Allow-Credentials', 'true')
|
|
131
|
+
next()
|
|
132
|
+
})
|
|
133
|
+
// this.express.use(cors({ credentials: true }));
|
|
134
|
+
// this.express.use('/proxy', proxy('www.gssoogle.com'));
|
|
135
|
+
this._express.use(body_parser_1.default.urlencoded({ extended: true }))
|
|
136
|
+
this._express.use(body_parser_1.default.json())
|
|
137
|
+
this._express.use((0, cookie_parser_1.default)(secret))
|
|
138
|
+
this._express.listen(port, hostname, () => console.log(`Listening on ${hostname}, port ${port}`))
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
static sendErrorResponse(response, statusCode, message) {
|
|
142
|
+
console.log(message)
|
|
143
|
+
response.statusCode = statusCode
|
|
144
|
+
response.status(statusCode).send(message)
|
|
145
|
+
}
|
|
146
|
+
getCredentialsEndpoint() {
|
|
147
|
+
var _a, _b, _c
|
|
148
|
+
this._express.get(
|
|
149
|
+
(_c =
|
|
150
|
+
(_b = (_a = this.opts) === null || _a === void 0 ? void 0 : _a.issueCredentialOpts) === null || _b === void 0
|
|
151
|
+
? void 0
|
|
152
|
+
: _b.getCredentialsPath) !== null && _c !== void 0
|
|
153
|
+
? _c
|
|
154
|
+
: '/credentials',
|
|
155
|
+
(request, response) =>
|
|
156
|
+
__awaiter(this, void 0, void 0, function* () {
|
|
157
|
+
try {
|
|
158
|
+
const uniqueVCs = yield this.agent.dataStoreORMGetVerifiableCredentials()
|
|
159
|
+
response.statusCode = 202
|
|
160
|
+
return response.send(uniqueVCs.map((uVC) => uVC.verifiableCredential))
|
|
161
|
+
} catch (e) {
|
|
162
|
+
console.log(e)
|
|
163
|
+
return VCAPIServer.sendErrorResponse(response, 500, e.message)
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
)
|
|
167
|
+
}
|
|
168
|
+
getCredentialEndpoint() {
|
|
169
|
+
var _a, _b, _c
|
|
170
|
+
this._express.get(
|
|
171
|
+
(_c =
|
|
172
|
+
(_b = (_a = this.opts) === null || _a === void 0 ? void 0 : _a.issueCredentialOpts) === null || _b === void 0
|
|
173
|
+
? void 0
|
|
174
|
+
: _b.getCredentialPath) !== null && _c !== void 0
|
|
175
|
+
? _c
|
|
176
|
+
: '/credentials/:id',
|
|
177
|
+
(request, response) =>
|
|
178
|
+
__awaiter(this, void 0, void 0, function* () {
|
|
179
|
+
try {
|
|
180
|
+
const id = request.params.id
|
|
181
|
+
if (!id) {
|
|
182
|
+
return VCAPIServer.sendErrorResponse(response, 400, 'no id provided')
|
|
183
|
+
}
|
|
184
|
+
let vcInfo = yield this.getCredentialByIdOrHash(id)
|
|
185
|
+
if (!vcInfo.vc) {
|
|
186
|
+
return VCAPIServer.sendErrorResponse(response, 404, `id ${id} not found`)
|
|
187
|
+
}
|
|
188
|
+
response.statusCode = 200
|
|
189
|
+
return response.send(vcInfo.vc)
|
|
190
|
+
} catch (e) {
|
|
191
|
+
console.log(e)
|
|
192
|
+
return VCAPIServer.sendErrorResponse(response, 500, e.message)
|
|
193
|
+
}
|
|
194
|
+
})
|
|
195
|
+
)
|
|
196
|
+
}
|
|
197
|
+
verifyCredentialEndpoint() {
|
|
198
|
+
var _a, _b, _c
|
|
199
|
+
this._express.post(
|
|
200
|
+
(_c =
|
|
201
|
+
(_b = (_a = this.opts) === null || _a === void 0 ? void 0 : _a.issueCredentialOpts) === null || _b === void 0
|
|
202
|
+
? void 0
|
|
203
|
+
: _b.verifyCredentialPath) !== null && _c !== void 0
|
|
204
|
+
? _c
|
|
205
|
+
: '/credentials/verify',
|
|
206
|
+
(request, response) =>
|
|
207
|
+
__awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
var _d, _e
|
|
209
|
+
try {
|
|
210
|
+
console.log(request.body)
|
|
211
|
+
const credential = request.body.verifiableCredential
|
|
212
|
+
// const options: IIssueOptionsPayload = request.body.options
|
|
213
|
+
if (!credential) {
|
|
214
|
+
return VCAPIServer.sendErrorResponse(response, 400, 'No verifiable credential supplied')
|
|
215
|
+
}
|
|
216
|
+
const verifyResult = yield this.agent.verifyCredential({
|
|
217
|
+
credential,
|
|
218
|
+
fetchRemoteContexts:
|
|
219
|
+
(_e = (_d = this.opts) === null || _d === void 0 ? void 0 : _d.issueCredentialOpts) === null || _e === void 0
|
|
220
|
+
? void 0
|
|
221
|
+
: _e.fetchRemoteContexts,
|
|
222
|
+
})
|
|
223
|
+
response.statusCode = 200
|
|
224
|
+
return response.send(verifyResult)
|
|
225
|
+
} catch (e) {
|
|
226
|
+
console.log(e)
|
|
227
|
+
return VCAPIServer.sendErrorResponse(response, 500, e.message)
|
|
228
|
+
}
|
|
229
|
+
})
|
|
230
|
+
)
|
|
231
|
+
}
|
|
232
|
+
deleteCredentialEndpoint() {
|
|
233
|
+
var _a, _b, _c
|
|
234
|
+
this._express.delete(
|
|
235
|
+
(_c =
|
|
236
|
+
(_b = (_a = this.opts) === null || _a === void 0 ? void 0 : _a.issueCredentialOpts) === null || _b === void 0
|
|
237
|
+
? void 0
|
|
238
|
+
: _b.getCredentialsPath) !== null && _c !== void 0
|
|
239
|
+
? _c
|
|
240
|
+
: '/credentials/:id',
|
|
241
|
+
(request, response) =>
|
|
242
|
+
__awaiter(this, void 0, void 0, function* () {
|
|
243
|
+
try {
|
|
244
|
+
const id = request.params.id
|
|
245
|
+
if (!id) {
|
|
246
|
+
return VCAPIServer.sendErrorResponse(response, 400, 'no id provided')
|
|
247
|
+
}
|
|
248
|
+
let vcInfo = yield this.getCredentialByIdOrHash(id)
|
|
249
|
+
if (!vcInfo.vc || !vcInfo.hash) {
|
|
250
|
+
return VCAPIServer.sendErrorResponse(response, 404, `id ${id} not found`)
|
|
251
|
+
}
|
|
252
|
+
const success = this.agent.dataStoreDeleteVerifiableCredential({ hash: vcInfo.hash })
|
|
253
|
+
if (!success) {
|
|
254
|
+
return VCAPIServer.sendErrorResponse(response, 400, `Could not delete Verifiable Credential with id ${id}`)
|
|
255
|
+
}
|
|
256
|
+
response.statusCode = 200
|
|
257
|
+
return response.send()
|
|
258
|
+
} catch (e) {
|
|
259
|
+
console.log(e)
|
|
260
|
+
return VCAPIServer.sendErrorResponse(response, 500, e.message)
|
|
261
|
+
}
|
|
262
|
+
})
|
|
263
|
+
)
|
|
264
|
+
}
|
|
265
|
+
issueCredentialEndpoint() {
|
|
266
|
+
var _a, _b, _c
|
|
267
|
+
this._express.post(
|
|
268
|
+
(_c =
|
|
269
|
+
(_b = (_a = this.opts) === null || _a === void 0 ? void 0 : _a.issueCredentialOpts) === null || _b === void 0
|
|
270
|
+
? void 0
|
|
271
|
+
: _b.issueCredentialPath) !== null && _c !== void 0
|
|
272
|
+
? _c
|
|
273
|
+
: '/credentials/issue',
|
|
274
|
+
(request, response) =>
|
|
275
|
+
__awaiter(this, void 0, void 0, function* () {
|
|
276
|
+
var _d, _e, _f
|
|
277
|
+
try {
|
|
278
|
+
const credential = request.body.credential
|
|
279
|
+
// const options: IIssueOptionsPayload = request.body.options
|
|
280
|
+
if (!credential) {
|
|
281
|
+
return VCAPIServer.sendErrorResponse(response, 400, 'No credential supplied')
|
|
282
|
+
}
|
|
283
|
+
if (!credential.id) {
|
|
284
|
+
credential.id = `urn:uuid:${(0, uuid_1.v4)()}`
|
|
285
|
+
}
|
|
286
|
+
const issueOpts = (_d = this.opts) === null || _d === void 0 ? void 0 : _d.issueCredentialOpts
|
|
287
|
+
const vc = yield this._agent.createVerifiableCredential({
|
|
288
|
+
credential,
|
|
289
|
+
save:
|
|
290
|
+
(_e = issueOpts === null || issueOpts === void 0 ? void 0 : issueOpts.persistIssuedCredentials) !== null && _e !== void 0 ? _e : true,
|
|
291
|
+
proofFormat: (_f = issueOpts === null || issueOpts === void 0 ? void 0 : issueOpts.proofFormat) !== null && _f !== void 0 ? _f : 'lds',
|
|
292
|
+
fetchRemoteContexts: (issueOpts === null || issueOpts === void 0 ? void 0 : issueOpts.fetchRemoteContexts) || true,
|
|
293
|
+
})
|
|
294
|
+
response.statusCode = 201
|
|
295
|
+
return response.send({ verifiableCredential: vc })
|
|
296
|
+
} catch (e) {
|
|
297
|
+
console.log(e)
|
|
298
|
+
return VCAPIServer.sendErrorResponse(response, 500, e.message)
|
|
299
|
+
}
|
|
300
|
+
})
|
|
301
|
+
)
|
|
302
|
+
}
|
|
303
|
+
getCredentialByIdOrHash(idOrHash) {
|
|
304
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
305
|
+
let vc
|
|
306
|
+
let hash
|
|
307
|
+
const uniqueVCs = yield this.agent.dataStoreORMGetVerifiableCredentials({
|
|
308
|
+
where: [
|
|
309
|
+
{
|
|
310
|
+
column: 'id',
|
|
311
|
+
value: [idOrHash],
|
|
312
|
+
op: 'Equal',
|
|
313
|
+
},
|
|
314
|
+
],
|
|
315
|
+
})
|
|
316
|
+
if (uniqueVCs.length === 0) {
|
|
317
|
+
hash = idOrHash
|
|
318
|
+
vc = yield this.agent.dataStoreGetVerifiableCredential({ hash })
|
|
319
|
+
} else {
|
|
320
|
+
const uniqueVC = uniqueVCs[0]
|
|
321
|
+
hash = uniqueVC.hash
|
|
322
|
+
vc = uniqueVC.verifiableCredential
|
|
323
|
+
}
|
|
324
|
+
return {
|
|
325
|
+
vc,
|
|
326
|
+
id: idOrHash,
|
|
327
|
+
hash,
|
|
328
|
+
}
|
|
329
|
+
})
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
exports.VCAPIServer = VCAPIServer
|
|
333
|
+
//# sourceMappingURL=VCAPIServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VCAPIServer.js","sourceRoot":"","sources":["../src/VCAPIServer.ts"],"names":[],"mappings":";AAAA,qCAAqC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKrC,8DAAoC;AACpC,kEAAwC;AACxC,oDAAqC;AACrC,sDAA6D;AAC7D,+BAAyB;AAiEzB,MAAa,WAAW;IAKtB,YAAY,IAA+E;;QACzF,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,CAAA;QAC5B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACnB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;QACjB,MAAM,eAAe,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAA;QACtC,IAAI,CAAC,QAAQ,GAAG,MAAA,IAAI,CAAC,OAAO,mCAAI,IAAA,iBAAO,GAAE,CAAA;QACzC,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,CAAA;QAElC,uBAAuB;QACvB,IAAI,CAAC,uBAAuB,EAAE,CAAA;QAC9B,IAAI,CAAC,qBAAqB,EAAE,CAAA;QAC5B,IAAI,CAAC,sBAAsB,EAAE,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EAAE;gBAC1B,IAAI,GAAG,QAAQ,CAAA;gBACf,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,gCAAgC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAA;aACjE;iBAAM;gBACL,MAAM,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,CAAA;gBAC7B,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAA;gBACpB,EAAE,GAAG,QAAQ,CAAC,oBAAoB,CAAA;aACnC;YAED,OAAO;gBACL,EAAE;gBACF,EAAE,EAAE,QAAQ;gBACZ,IAAI;aACL,CAAA;QACH,CAAC;KAAA;CACF;AAhND,kCAgNC"}
|
package/dist/api-functions.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ISingleEndpointOpts } from '@sphereon/ssi-express-support';
|
|
2
|
-
import { Router } from 'express';
|
|
3
|
-
import { IIssueCredentialEndpointOpts, IRequiredContext, IVerifyCredentialEndpointOpts } from './types';
|
|
4
|
-
export declare function issueCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IIssueCredentialEndpointOpts): void;
|
|
5
|
-
export declare function getCredentialsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
6
|
-
export declare function getCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
7
|
-
export declare function verifyCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IVerifyCredentialEndpointOpts): void;
|
|
8
|
-
export declare function deleteCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
1
|
+
import { ISingleEndpointOpts } from '@sphereon/ssi-express-support';
|
|
2
|
+
import { Router } from 'express';
|
|
3
|
+
import { IIssueCredentialEndpointOpts, IRequiredContext, IVerifyCredentialEndpointOpts } from './types';
|
|
4
|
+
export declare function issueCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IIssueCredentialEndpointOpts): void;
|
|
5
|
+
export declare function getCredentialsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
6
|
+
export declare function getCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
7
|
+
export declare function verifyCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IVerifyCredentialEndpointOpts): void;
|
|
8
|
+
export declare function deleteCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
|
|
9
9
|
//# sourceMappingURL=api-functions.d.ts.map
|
package/dist/api-functions.js
CHANGED
|
@@ -1,158 +1,158 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.deleteCredentialEndpoint = exports.verifyCredentialEndpoint = exports.getCredentialEndpoint = exports.getCredentialsEndpoint = exports.issueCredentialEndpoint = void 0;
|
|
16
|
-
const ssi_sdk_core_1 = require("@sphereon/ssi-sdk.core");
|
|
17
|
-
const ssi_express_support_1 = require("@sphereon/ssi-express-support");
|
|
18
|
-
const uuid_1 = require("uuid");
|
|
19
|
-
const debug_1 = __importDefault(require("debug"));
|
|
20
|
-
const debug = (0, debug_1.default)('sphereon:ssi-sdk:w3c-vc-api');
|
|
21
|
-
function issueCredentialEndpoint(router, context, opts) {
|
|
22
|
-
var _a;
|
|
23
|
-
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
24
|
-
console.log(`Issue credential endpoint is disabled`);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials/issue';
|
|
28
|
-
router.post(path, (0, ssi_express_support_1.checkAuth)(opts === null || opts === void 0 ? void 0 : opts.endpoint), (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
var _b;
|
|
30
|
-
try {
|
|
31
|
-
const credential = request.body.credential;
|
|
32
|
-
if (!credential) {
|
|
33
|
-
return (0, ssi_express_support_1.sendErrorResponse)(response, 400, 'No credential supplied');
|
|
34
|
-
}
|
|
35
|
-
if (!credential.id) {
|
|
36
|
-
credential.id = `urn:uuid:${(0, uuid_1.v4)()}`;
|
|
37
|
-
}
|
|
38
|
-
const issueOpts = opts === null || opts === void 0 ? void 0 : opts.issueCredentialOpts;
|
|
39
|
-
const vc = yield context.agent.createVerifiableCredential({
|
|
40
|
-
credential,
|
|
41
|
-
save: (opts === null || opts === void 0 ? void 0 : opts.persistIssuedCredentials) !== false,
|
|
42
|
-
proofFormat: (_b = issueOpts === null || issueOpts === void 0 ? void 0 : issueOpts.proofFormat) !== null && _b !== void 0 ? _b : 'lds',
|
|
43
|
-
fetchRemoteContexts: (issueOpts === null || issueOpts === void 0 ? void 0 : issueOpts.fetchRemoteContexts) !== false,
|
|
44
|
-
});
|
|
45
|
-
response.statusCode = 201;
|
|
46
|
-
return response.send({ verifiableCredential: vc });
|
|
47
|
-
}
|
|
48
|
-
catch (e) {
|
|
49
|
-
return (0, ssi_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
50
|
-
}
|
|
51
|
-
}));
|
|
52
|
-
}
|
|
53
|
-
exports.issueCredentialEndpoint = issueCredentialEndpoint;
|
|
54
|
-
function getCredentialsEndpoint(router, context, opts) {
|
|
55
|
-
var _a;
|
|
56
|
-
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
57
|
-
console.log(`Get credentials endpoint is disabled`);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials';
|
|
61
|
-
router.get(path, (0, ssi_express_support_1.checkAuth)(opts === null || opts === void 0 ? void 0 : opts.endpoint), (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
try {
|
|
63
|
-
const uniqueVCs = yield context.agent.dataStoreORMGetVerifiableCredentials();
|
|
64
|
-
response.statusCode = 202;
|
|
65
|
-
return response.send(uniqueVCs.map((uVC) => uVC.verifiableCredential));
|
|
66
|
-
}
|
|
67
|
-
catch (e) {
|
|
68
|
-
return (0, ssi_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
69
|
-
}
|
|
70
|
-
}));
|
|
71
|
-
}
|
|
72
|
-
exports.getCredentialsEndpoint = getCredentialsEndpoint;
|
|
73
|
-
function getCredentialEndpoint(router, context, opts) {
|
|
74
|
-
var _a;
|
|
75
|
-
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
76
|
-
console.log(`Get credential endpoint is disabled`);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials/:id';
|
|
80
|
-
router.get(path, (0, ssi_express_support_1.checkAuth)(opts === null || opts === void 0 ? void 0 : opts.endpoint), (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
try {
|
|
82
|
-
const id = request.params.id;
|
|
83
|
-
if (!id) {
|
|
84
|
-
return (0, ssi_express_support_1.sendErrorResponse)(response, 400, 'no id provided');
|
|
85
|
-
}
|
|
86
|
-
let vcInfo = yield (0, ssi_sdk_core_1.getCredentialByIdOrHash)(context, id);
|
|
87
|
-
if (!vcInfo.vc) {
|
|
88
|
-
return (0, ssi_express_support_1.sendErrorResponse)(response, 404, `id ${id} not found`);
|
|
89
|
-
}
|
|
90
|
-
response.statusCode = 200;
|
|
91
|
-
return response.send(vcInfo.vc);
|
|
92
|
-
}
|
|
93
|
-
catch (e) {
|
|
94
|
-
return (0, ssi_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
95
|
-
}
|
|
96
|
-
}));
|
|
97
|
-
}
|
|
98
|
-
exports.getCredentialEndpoint = getCredentialEndpoint;
|
|
99
|
-
function verifyCredentialEndpoint(router, context, opts) {
|
|
100
|
-
var _a;
|
|
101
|
-
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
102
|
-
console.log(`Verify credential endpoint is disabled`);
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
router.post((_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials/verify', (0, ssi_express_support_1.checkAuth)(opts === null || opts === void 0 ? void 0 : opts.endpoint), (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
try {
|
|
107
|
-
debug(JSON.stringify(request.body, null, 2));
|
|
108
|
-
const credential = request.body.verifiableCredential;
|
|
109
|
-
// const options: IIssueOptionsPayload = request.body.options
|
|
110
|
-
if (!credential) {
|
|
111
|
-
return (0, ssi_express_support_1.sendErrorResponse)(response, 400, 'No verifiable credential supplied');
|
|
112
|
-
}
|
|
113
|
-
const verifyResult = yield context.agent.verifyCredential({
|
|
114
|
-
credential,
|
|
115
|
-
policies: {
|
|
116
|
-
credentialStatus: false, // Do not use built-in. We have our own statusList implementations
|
|
117
|
-
},
|
|
118
|
-
fetchRemoteContexts: (opts === null || opts === void 0 ? void 0 : opts.fetchRemoteContexts) !== false,
|
|
119
|
-
});
|
|
120
|
-
response.statusCode = 200;
|
|
121
|
-
return response.send(verifyResult);
|
|
122
|
-
}
|
|
123
|
-
catch (e) {
|
|
124
|
-
return (0, ssi_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
125
|
-
}
|
|
126
|
-
}));
|
|
127
|
-
}
|
|
128
|
-
exports.verifyCredentialEndpoint = verifyCredentialEndpoint;
|
|
129
|
-
function deleteCredentialEndpoint(router, context, opts) {
|
|
130
|
-
var _a;
|
|
131
|
-
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
132
|
-
console.log(`Delete credential endpoint is disabled`);
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
router.delete((_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials/:id', (0, ssi_express_support_1.checkAuth)(opts === null || opts === void 0 ? void 0 : opts.endpoint), (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
136
|
-
try {
|
|
137
|
-
const id = request.params.id;
|
|
138
|
-
if (!id) {
|
|
139
|
-
return (0, ssi_express_support_1.sendErrorResponse)(response, 400, 'no id provided');
|
|
140
|
-
}
|
|
141
|
-
let vcInfo = yield (0, ssi_sdk_core_1.getCredentialByIdOrHash)(context, id);
|
|
142
|
-
if (!vcInfo.vc || !vcInfo.hash) {
|
|
143
|
-
return (0, ssi_express_support_1.sendErrorResponse)(response, 404, `id ${id} not found`);
|
|
144
|
-
}
|
|
145
|
-
const success = context.agent.dataStoreDeleteVerifiableCredential({ hash: vcInfo.hash });
|
|
146
|
-
if (!success) {
|
|
147
|
-
return (0, ssi_express_support_1.sendErrorResponse)(response, 400, `Could not delete Verifiable Credential with id ${id}`);
|
|
148
|
-
}
|
|
149
|
-
response.statusCode = 200;
|
|
150
|
-
return response.send();
|
|
151
|
-
}
|
|
152
|
-
catch (e) {
|
|
153
|
-
return (0, ssi_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
154
|
-
}
|
|
155
|
-
}));
|
|
156
|
-
}
|
|
157
|
-
exports.deleteCredentialEndpoint = deleteCredentialEndpoint;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.deleteCredentialEndpoint = exports.verifyCredentialEndpoint = exports.getCredentialEndpoint = exports.getCredentialsEndpoint = exports.issueCredentialEndpoint = void 0;
|
|
16
|
+
const ssi_sdk_core_1 = require("@sphereon/ssi-sdk.core");
|
|
17
|
+
const ssi_express_support_1 = require("@sphereon/ssi-express-support");
|
|
18
|
+
const uuid_1 = require("uuid");
|
|
19
|
+
const debug_1 = __importDefault(require("debug"));
|
|
20
|
+
const debug = (0, debug_1.default)('sphereon:ssi-sdk:w3c-vc-api');
|
|
21
|
+
function issueCredentialEndpoint(router, context, opts) {
|
|
22
|
+
var _a;
|
|
23
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
24
|
+
console.log(`Issue credential endpoint is disabled`);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials/issue';
|
|
28
|
+
router.post(path, (0, ssi_express_support_1.checkAuth)(opts === null || opts === void 0 ? void 0 : opts.endpoint), (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
var _b;
|
|
30
|
+
try {
|
|
31
|
+
const credential = request.body.credential;
|
|
32
|
+
if (!credential) {
|
|
33
|
+
return (0, ssi_express_support_1.sendErrorResponse)(response, 400, 'No credential supplied');
|
|
34
|
+
}
|
|
35
|
+
if (!credential.id) {
|
|
36
|
+
credential.id = `urn:uuid:${(0, uuid_1.v4)()}`;
|
|
37
|
+
}
|
|
38
|
+
const issueOpts = opts === null || opts === void 0 ? void 0 : opts.issueCredentialOpts;
|
|
39
|
+
const vc = yield context.agent.createVerifiableCredential({
|
|
40
|
+
credential,
|
|
41
|
+
save: (opts === null || opts === void 0 ? void 0 : opts.persistIssuedCredentials) !== false,
|
|
42
|
+
proofFormat: (_b = issueOpts === null || issueOpts === void 0 ? void 0 : issueOpts.proofFormat) !== null && _b !== void 0 ? _b : 'lds',
|
|
43
|
+
fetchRemoteContexts: (issueOpts === null || issueOpts === void 0 ? void 0 : issueOpts.fetchRemoteContexts) !== false,
|
|
44
|
+
});
|
|
45
|
+
response.statusCode = 201;
|
|
46
|
+
return response.send({ verifiableCredential: vc });
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
return (0, ssi_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
50
|
+
}
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
exports.issueCredentialEndpoint = issueCredentialEndpoint;
|
|
54
|
+
function getCredentialsEndpoint(router, context, opts) {
|
|
55
|
+
var _a;
|
|
56
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
57
|
+
console.log(`Get credentials endpoint is disabled`);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials';
|
|
61
|
+
router.get(path, (0, ssi_express_support_1.checkAuth)(opts === null || opts === void 0 ? void 0 : opts.endpoint), (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
try {
|
|
63
|
+
const uniqueVCs = yield context.agent.dataStoreORMGetVerifiableCredentials();
|
|
64
|
+
response.statusCode = 202;
|
|
65
|
+
return response.send(uniqueVCs.map((uVC) => uVC.verifiableCredential));
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
return (0, ssi_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
69
|
+
}
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
exports.getCredentialsEndpoint = getCredentialsEndpoint;
|
|
73
|
+
function getCredentialEndpoint(router, context, opts) {
|
|
74
|
+
var _a;
|
|
75
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
76
|
+
console.log(`Get credential endpoint is disabled`);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials/:id';
|
|
80
|
+
router.get(path, (0, ssi_express_support_1.checkAuth)(opts === null || opts === void 0 ? void 0 : opts.endpoint), (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
try {
|
|
82
|
+
const id = request.params.id;
|
|
83
|
+
if (!id) {
|
|
84
|
+
return (0, ssi_express_support_1.sendErrorResponse)(response, 400, 'no id provided');
|
|
85
|
+
}
|
|
86
|
+
let vcInfo = yield (0, ssi_sdk_core_1.getCredentialByIdOrHash)(context, id);
|
|
87
|
+
if (!vcInfo.vc) {
|
|
88
|
+
return (0, ssi_express_support_1.sendErrorResponse)(response, 404, `id ${id} not found`);
|
|
89
|
+
}
|
|
90
|
+
response.statusCode = 200;
|
|
91
|
+
return response.send(vcInfo.vc);
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
return (0, ssi_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
95
|
+
}
|
|
96
|
+
}));
|
|
97
|
+
}
|
|
98
|
+
exports.getCredentialEndpoint = getCredentialEndpoint;
|
|
99
|
+
function verifyCredentialEndpoint(router, context, opts) {
|
|
100
|
+
var _a;
|
|
101
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
102
|
+
console.log(`Verify credential endpoint is disabled`);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
router.post((_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials/verify', (0, ssi_express_support_1.checkAuth)(opts === null || opts === void 0 ? void 0 : opts.endpoint), (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
try {
|
|
107
|
+
debug(JSON.stringify(request.body, null, 2));
|
|
108
|
+
const credential = request.body.verifiableCredential;
|
|
109
|
+
// const options: IIssueOptionsPayload = request.body.options
|
|
110
|
+
if (!credential) {
|
|
111
|
+
return (0, ssi_express_support_1.sendErrorResponse)(response, 400, 'No verifiable credential supplied');
|
|
112
|
+
}
|
|
113
|
+
const verifyResult = yield context.agent.verifyCredential({
|
|
114
|
+
credential,
|
|
115
|
+
policies: {
|
|
116
|
+
credentialStatus: false, // Do not use built-in. We have our own statusList implementations
|
|
117
|
+
},
|
|
118
|
+
fetchRemoteContexts: (opts === null || opts === void 0 ? void 0 : opts.fetchRemoteContexts) !== false,
|
|
119
|
+
});
|
|
120
|
+
response.statusCode = 200;
|
|
121
|
+
return response.send(verifyResult);
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
return (0, ssi_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
125
|
+
}
|
|
126
|
+
}));
|
|
127
|
+
}
|
|
128
|
+
exports.verifyCredentialEndpoint = verifyCredentialEndpoint;
|
|
129
|
+
function deleteCredentialEndpoint(router, context, opts) {
|
|
130
|
+
var _a;
|
|
131
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
|
|
132
|
+
console.log(`Delete credential endpoint is disabled`);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
router.delete((_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/credentials/:id', (0, ssi_express_support_1.checkAuth)(opts === null || opts === void 0 ? void 0 : opts.endpoint), (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
try {
|
|
137
|
+
const id = request.params.id;
|
|
138
|
+
if (!id) {
|
|
139
|
+
return (0, ssi_express_support_1.sendErrorResponse)(response, 400, 'no id provided');
|
|
140
|
+
}
|
|
141
|
+
let vcInfo = yield (0, ssi_sdk_core_1.getCredentialByIdOrHash)(context, id);
|
|
142
|
+
if (!vcInfo.vc || !vcInfo.hash) {
|
|
143
|
+
return (0, ssi_express_support_1.sendErrorResponse)(response, 404, `id ${id} not found`);
|
|
144
|
+
}
|
|
145
|
+
const success = context.agent.dataStoreDeleteVerifiableCredential({ hash: vcInfo.hash });
|
|
146
|
+
if (!success) {
|
|
147
|
+
return (0, ssi_express_support_1.sendErrorResponse)(response, 400, `Could not delete Verifiable Credential with id ${id}`);
|
|
148
|
+
}
|
|
149
|
+
response.statusCode = 200;
|
|
150
|
+
return response.send();
|
|
151
|
+
}
|
|
152
|
+
catch (e) {
|
|
153
|
+
return (0, ssi_express_support_1.sendErrorResponse)(response, 500, e.message, e);
|
|
154
|
+
}
|
|
155
|
+
}));
|
|
156
|
+
}
|
|
157
|
+
exports.deleteCredentialEndpoint = deleteCredentialEndpoint;
|
|
158
158
|
//# sourceMappingURL=api-functions.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @public
|
|
3
|
-
*/
|
|
4
|
-
export * from './vc-api-server';
|
|
5
|
-
export * from './types';
|
|
6
|
-
export * from './api-functions';
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
*/
|
|
4
|
+
export * from './vc-api-server';
|
|
5
|
+
export * from './types';
|
|
6
|
+
export * from './api-functions';
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
/**
|
|
18
|
-
* @public
|
|
19
|
-
*/
|
|
20
|
-
__exportStar(require("./vc-api-server"), exports);
|
|
21
|
-
__exportStar(require("./types"), exports);
|
|
22
|
-
__exportStar(require("./api-functions"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
/**
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
__exportStar(require("./vc-api-server"), exports);
|
|
21
|
+
__exportStar(require("./types"), exports);
|
|
22
|
+
__exportStar(require("./api-functions"), exports);
|
|
23
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { IAgent } from '@veramo/core'
|
|
2
|
+
import { Request, Router } from 'express'
|
|
3
|
+
export interface RequestWithAgent extends Request {
|
|
4
|
+
agent?: IAgent
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface RequestWithAgentRouterOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Optional. Pre-configured agent
|
|
12
|
+
*/
|
|
13
|
+
agent?: IAgent
|
|
14
|
+
/**
|
|
15
|
+
* Optional. Function that returns a Promise that resolves to a configured agent for specific request
|
|
16
|
+
*/
|
|
17
|
+
getAgentForRequest?: (req: Request) => Promise<IAgent>
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates an expressjs router that adds a Veramo agent to the request object.
|
|
21
|
+
*
|
|
22
|
+
* This is needed by all other routers provided by this package to be able to perform their functions.
|
|
23
|
+
*
|
|
24
|
+
* @param options - Initialization option
|
|
25
|
+
* @returns Expressjs router
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export declare const RequestWithAgentRouter: (options: RequestWithAgentRouterOptions) => Router
|
|
30
|
+
//# sourceMappingURL=request-agent-router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-agent-router.d.ts","sourceRoot":"","sources":["../src/request-agent-router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAEzC,MAAM,WAAW,gBAAiB,SAAQ,OAAO;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,kBAAkB,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CACvD;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,YAAa,6BAA6B,KAAG,MAc/E,CAAA"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
var __awaiter =
|
|
3
|
+
(this && this.__awaiter) ||
|
|
4
|
+
function (thisArg, _arguments, P, generator) {
|
|
5
|
+
function adopt(value) {
|
|
6
|
+
return value instanceof P
|
|
7
|
+
? value
|
|
8
|
+
: new P(function (resolve) {
|
|
9
|
+
resolve(value)
|
|
10
|
+
})
|
|
11
|
+
}
|
|
12
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
13
|
+
function fulfilled(value) {
|
|
14
|
+
try {
|
|
15
|
+
step(generator.next(value))
|
|
16
|
+
} catch (e) {
|
|
17
|
+
reject(e)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function rejected(value) {
|
|
21
|
+
try {
|
|
22
|
+
step(generator['throw'](value))
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function step(result) {
|
|
28
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected)
|
|
29
|
+
}
|
|
30
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next())
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
34
|
+
exports.RequestWithAgentRouter = void 0
|
|
35
|
+
const express_1 = require('express')
|
|
36
|
+
/**
|
|
37
|
+
* Creates an expressjs router that adds a Veramo agent to the request object.
|
|
38
|
+
*
|
|
39
|
+
* This is needed by all other routers provided by this package to be able to perform their functions.
|
|
40
|
+
*
|
|
41
|
+
* @param options - Initialization option
|
|
42
|
+
* @returns Expressjs router
|
|
43
|
+
*
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
const RequestWithAgentRouter = (options) => {
|
|
47
|
+
const router = (0, express_1.Router)()
|
|
48
|
+
router.use((req, res, next) =>
|
|
49
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
+
if (options.agent) {
|
|
51
|
+
req.agent = options.agent
|
|
52
|
+
} else if (options.getAgentForRequest) {
|
|
53
|
+
req.agent = yield options.getAgentForRequest(req)
|
|
54
|
+
} else {
|
|
55
|
+
throw Error('[RequestWithAgentRouter] agent or getAgentForRequest is required')
|
|
56
|
+
}
|
|
57
|
+
next()
|
|
58
|
+
})
|
|
59
|
+
)
|
|
60
|
+
return router
|
|
61
|
+
}
|
|
62
|
+
exports.RequestWithAgentRouter = RequestWithAgentRouter
|
|
63
|
+
//# sourceMappingURL=request-agent-router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-agent-router.js","sourceRoot":"","sources":["../src/request-agent-router.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qCAAyC;AAqBzC;;;;;;;;;GASG;AACI,MAAM,sBAAsB,GAAG,CAAC,OAAsC,EAAU,EAAE;IACvF,MAAM,MAAM,GAAG,IAAA,gBAAM,GAAE,CAAA;IACvB,MAAM,CAAC,GAAG,CAAC,CAAO,GAAqB,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACpD,IAAI,OAAO,CAAC,KAAK,EAAE;YACjB,GAAG,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;SAC1B;aAAM,IAAI,OAAO,CAAC,kBAAkB,EAAE;YACrC,GAAG,CAAC,KAAK,GAAG,MAAM,OAAO,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAA;SAClD;aAAM;YACL,MAAM,KAAK,CAAC,kEAAkE,CAAC,CAAA;SAChF;QACD,IAAI,EAAE,CAAA;IACR,CAAC,CAAA,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAdY,QAAA,sBAAsB,0BAclC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import { GenericAuthArgs, ISingleEndpointOpts } from '@sphereon/ssi-express-support';
|
|
2
|
-
import { IAgentContext, ICredentialIssuer, ICredentialPlugin, ICredentialVerifier, IDataStore, IDataStoreORM, IDIDManager, IKeyManager, IResolver } from '@veramo/core';
|
|
3
|
-
import { ProofFormat } from '@veramo/core/src/types/ICredentialIssuer';
|
|
4
|
-
export type IRequiredPlugins = IDataStore & IDataStoreORM & IDIDManager & IKeyManager & ICredentialIssuer & ICredentialVerifier & ICredentialPlugin & IResolver;
|
|
5
|
-
export type IRequiredContext = IAgentContext<IRequiredPlugins>;
|
|
6
|
-
export interface IVCAPIOpts {
|
|
7
|
-
endpointOpts?: IVCAPIEndpointOpts;
|
|
8
|
-
issueCredentialOpts?: IVCAPIIssueOpts;
|
|
9
|
-
}
|
|
10
|
-
export interface IVCAPIEndpointOpts {
|
|
11
|
-
basePath?: string;
|
|
12
|
-
globalAuth?: GenericAuthArgs;
|
|
13
|
-
issueCredential?: IIssueCredentialEndpointOpts;
|
|
14
|
-
getCredentials?: ISingleEndpointOpts;
|
|
15
|
-
getCredential?: ISingleEndpointOpts;
|
|
16
|
-
deleteCredential?: ISingleEndpointOpts;
|
|
17
|
-
verifyCredential?: IVerifyCredentialEndpointOpts;
|
|
18
|
-
verifyPresentation?: ISingleEndpointOpts;
|
|
19
|
-
}
|
|
20
|
-
export type vcApiFeatures = 'vc-verify' | 'vc-issue' | 'vc-persist';
|
|
21
|
-
export interface IVCAPIIssueOpts {
|
|
22
|
-
enableFeatures?: vcApiFeatures[];
|
|
23
|
-
persistIssuedCredentials?: boolean;
|
|
24
|
-
/**
|
|
25
|
-
* The desired format for the VerifiablePresentation to be created.
|
|
26
|
-
*/
|
|
27
|
-
proofFormat: ProofFormat;
|
|
28
|
-
/**
|
|
29
|
-
* Remove payload members during JWT-JSON transformation. Defaults to `true`.
|
|
30
|
-
* See https://www.w3.org/TR/vc-data-model/#jwt-encoding
|
|
31
|
-
*/
|
|
32
|
-
removeOriginalFields?: boolean;
|
|
33
|
-
/**
|
|
34
|
-
* [Optional] The ID of the key that should sign this credential.
|
|
35
|
-
* If this is not specified, the first matching key will be used.
|
|
36
|
-
*/
|
|
37
|
-
keyRef?: string;
|
|
38
|
-
/**
|
|
39
|
-
* When dealing with JSON-LD you also MUST provide the proper contexts.
|
|
40
|
-
* Set this to `true` ONLY if you want the `@context` URLs to be fetched in case they are not preloaded.
|
|
41
|
-
* The context definitions SHOULD rather be provided at startup instead of being fetched.
|
|
42
|
-
*
|
|
43
|
-
* Defaults to `false`
|
|
44
|
-
*/
|
|
45
|
-
fetchRemoteContexts?: boolean;
|
|
46
|
-
}
|
|
47
|
-
export interface IIssueCredentialEndpointOpts extends ISingleEndpointOpts {
|
|
48
|
-
issueCredentialOpts?: IVCAPIIssueOpts;
|
|
49
|
-
persistIssuedCredentials?: boolean;
|
|
50
|
-
}
|
|
51
|
-
export interface IVerifyCredentialEndpointOpts extends ISingleEndpointOpts {
|
|
52
|
-
fetchRemoteContexts?: boolean;
|
|
53
|
-
}
|
|
54
|
-
export interface IIssueOptionsPayload {
|
|
55
|
-
created?: string;
|
|
56
|
-
challenge?: string;
|
|
57
|
-
domain?: string;
|
|
58
|
-
credentialStatus?: {
|
|
59
|
-
type: string;
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
export interface ChallengeOptsPayload {
|
|
63
|
-
challenge?: string;
|
|
64
|
-
domain?: string;
|
|
65
|
-
}
|
|
1
|
+
import { GenericAuthArgs, ISingleEndpointOpts } from '@sphereon/ssi-express-support';
|
|
2
|
+
import { IAgentContext, ICredentialIssuer, ICredentialPlugin, ICredentialVerifier, IDataStore, IDataStoreORM, IDIDManager, IKeyManager, IResolver } from '@veramo/core';
|
|
3
|
+
import { ProofFormat } from '@veramo/core/src/types/ICredentialIssuer';
|
|
4
|
+
export type IRequiredPlugins = IDataStore & IDataStoreORM & IDIDManager & IKeyManager & ICredentialIssuer & ICredentialVerifier & ICredentialPlugin & IResolver;
|
|
5
|
+
export type IRequiredContext = IAgentContext<IRequiredPlugins>;
|
|
6
|
+
export interface IVCAPIOpts {
|
|
7
|
+
endpointOpts?: IVCAPIEndpointOpts;
|
|
8
|
+
issueCredentialOpts?: IVCAPIIssueOpts;
|
|
9
|
+
}
|
|
10
|
+
export interface IVCAPIEndpointOpts {
|
|
11
|
+
basePath?: string;
|
|
12
|
+
globalAuth?: GenericAuthArgs;
|
|
13
|
+
issueCredential?: IIssueCredentialEndpointOpts;
|
|
14
|
+
getCredentials?: ISingleEndpointOpts;
|
|
15
|
+
getCredential?: ISingleEndpointOpts;
|
|
16
|
+
deleteCredential?: ISingleEndpointOpts;
|
|
17
|
+
verifyCredential?: IVerifyCredentialEndpointOpts;
|
|
18
|
+
verifyPresentation?: ISingleEndpointOpts;
|
|
19
|
+
}
|
|
20
|
+
export type vcApiFeatures = 'vc-verify' | 'vc-issue' | 'vc-persist';
|
|
21
|
+
export interface IVCAPIIssueOpts {
|
|
22
|
+
enableFeatures?: vcApiFeatures[];
|
|
23
|
+
persistIssuedCredentials?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* The desired format for the VerifiablePresentation to be created.
|
|
26
|
+
*/
|
|
27
|
+
proofFormat: ProofFormat;
|
|
28
|
+
/**
|
|
29
|
+
* Remove payload members during JWT-JSON transformation. Defaults to `true`.
|
|
30
|
+
* See https://www.w3.org/TR/vc-data-model/#jwt-encoding
|
|
31
|
+
*/
|
|
32
|
+
removeOriginalFields?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* [Optional] The ID of the key that should sign this credential.
|
|
35
|
+
* If this is not specified, the first matching key will be used.
|
|
36
|
+
*/
|
|
37
|
+
keyRef?: string;
|
|
38
|
+
/**
|
|
39
|
+
* When dealing with JSON-LD you also MUST provide the proper contexts.
|
|
40
|
+
* Set this to `true` ONLY if you want the `@context` URLs to be fetched in case they are not preloaded.
|
|
41
|
+
* The context definitions SHOULD rather be provided at startup instead of being fetched.
|
|
42
|
+
*
|
|
43
|
+
* Defaults to `false`
|
|
44
|
+
*/
|
|
45
|
+
fetchRemoteContexts?: boolean;
|
|
46
|
+
}
|
|
47
|
+
export interface IIssueCredentialEndpointOpts extends ISingleEndpointOpts {
|
|
48
|
+
issueCredentialOpts?: IVCAPIIssueOpts;
|
|
49
|
+
persistIssuedCredentials?: boolean;
|
|
50
|
+
}
|
|
51
|
+
export interface IVerifyCredentialEndpointOpts extends ISingleEndpointOpts {
|
|
52
|
+
fetchRemoteContexts?: boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface IIssueOptionsPayload {
|
|
55
|
+
created?: string;
|
|
56
|
+
challenge?: string;
|
|
57
|
+
domain?: string;
|
|
58
|
+
credentialStatus?: {
|
|
59
|
+
type: string;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export interface ChallengeOptsPayload {
|
|
63
|
+
challenge?: string;
|
|
64
|
+
domain?: string;
|
|
65
|
+
}
|
|
66
66
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=types.js.map
|
package/dist/vc-api-server.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { ExpressSupport } from '@sphereon/ssi-express-support';
|
|
2
|
-
import { TAgent } from '@veramo/core';
|
|
3
|
-
import express, { Express } from 'express';
|
|
4
|
-
import { IRequiredPlugins, IVCAPIOpts } from './types';
|
|
5
|
-
export declare class VcApiServer {
|
|
6
|
-
get router(): express.Router;
|
|
7
|
-
private readonly _express;
|
|
8
|
-
private readonly _agent;
|
|
9
|
-
private readonly _opts?;
|
|
10
|
-
private readonly _router;
|
|
11
|
-
constructor(args: {
|
|
12
|
-
agent: TAgent<IRequiredPlugins>;
|
|
13
|
-
expressSupport: ExpressSupport;
|
|
14
|
-
opts?: IVCAPIOpts;
|
|
15
|
-
});
|
|
16
|
-
get agent(): TAgent<IRequiredPlugins>;
|
|
17
|
-
get opts(): IVCAPIOpts | undefined;
|
|
18
|
-
get express(): Express;
|
|
19
|
-
}
|
|
1
|
+
import { ExpressSupport } from '@sphereon/ssi-express-support';
|
|
2
|
+
import { TAgent } from '@veramo/core';
|
|
3
|
+
import express, { Express } from 'express';
|
|
4
|
+
import { IRequiredPlugins, IVCAPIOpts } from './types';
|
|
5
|
+
export declare class VcApiServer {
|
|
6
|
+
get router(): express.Router;
|
|
7
|
+
private readonly _express;
|
|
8
|
+
private readonly _agent;
|
|
9
|
+
private readonly _opts?;
|
|
10
|
+
private readonly _router;
|
|
11
|
+
constructor(args: {
|
|
12
|
+
agent: TAgent<IRequiredPlugins>;
|
|
13
|
+
expressSupport: ExpressSupport;
|
|
14
|
+
opts?: IVCAPIOpts;
|
|
15
|
+
});
|
|
16
|
+
get agent(): TAgent<IRequiredPlugins>;
|
|
17
|
+
get opts(): IVCAPIOpts | undefined;
|
|
18
|
+
get express(): Express;
|
|
19
|
+
}
|
|
20
20
|
//# sourceMappingURL=vc-api-server.d.ts.map
|
package/dist/vc-api-server.js
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.VcApiServer = void 0;
|
|
7
|
-
const ssi_sdk_core_1 = require("@sphereon/ssi-sdk.core");
|
|
8
|
-
const express_1 = __importDefault(require("express"));
|
|
9
|
-
const api_functions_1 = require("./api-functions");
|
|
10
|
-
class VcApiServer {
|
|
11
|
-
get router() {
|
|
12
|
-
return this._router;
|
|
13
|
-
}
|
|
14
|
-
constructor(args) {
|
|
15
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
16
|
-
const { agent, opts } = args;
|
|
17
|
-
this._agent = agent;
|
|
18
|
-
if ((_a = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _a === void 0 ? void 0 : _a.globalAuth) {
|
|
19
|
-
copyGlobalAuthToEndpoint(opts, 'issueCredential');
|
|
20
|
-
copyGlobalAuthToEndpoint(opts, 'getCredential');
|
|
21
|
-
copyGlobalAuthToEndpoint(opts, 'getCredentials');
|
|
22
|
-
copyGlobalAuthToEndpoint(opts, 'deleteCredential');
|
|
23
|
-
copyGlobalAuthToEndpoint(opts, 'verifyCredential');
|
|
24
|
-
}
|
|
25
|
-
this._opts = opts;
|
|
26
|
-
this._express = args.expressSupport.express;
|
|
27
|
-
this._router = express_1.default.Router();
|
|
28
|
-
const context = (0, ssi_sdk_core_1.agentContext)(agent);
|
|
29
|
-
const features = (_c = (_b = opts === null || opts === void 0 ? void 0 : opts.issueCredentialOpts) === null || _b === void 0 ? void 0 : _b.enableFeatures) !== null && _c !== void 0 ? _c : ['vc-issue', 'vc-persist', 'vc-verify'];
|
|
30
|
-
console.log(`VC API enabled, with features: ${JSON.stringify(features)}`);
|
|
31
|
-
// Credential endpoints
|
|
32
|
-
if (features.includes('vc-issue')) {
|
|
33
|
-
(0, api_functions_1.issueCredentialEndpoint)(this.router, context, Object.assign(Object.assign({}, (_d = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _d === void 0 ? void 0 : _d.issueCredential), { issueCredentialOpts: opts === null || opts === void 0 ? void 0 : opts.issueCredentialOpts }));
|
|
34
|
-
}
|
|
35
|
-
if (features.includes('vc-persist')) {
|
|
36
|
-
(0, api_functions_1.getCredentialEndpoint)(this.router, context, (_e = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _e === void 0 ? void 0 : _e.getCredential);
|
|
37
|
-
(0, api_functions_1.getCredentialsEndpoint)(this.router, context, (_f = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _f === void 0 ? void 0 : _f.getCredentials);
|
|
38
|
-
(0, api_functions_1.deleteCredentialEndpoint)(this.router, context, (_g = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _g === void 0 ? void 0 : _g.deleteCredential); // not in spec.
|
|
39
|
-
}
|
|
40
|
-
if (features.includes('vc-verify')) {
|
|
41
|
-
(0, api_functions_1.verifyCredentialEndpoint)(this.router, context, Object.assign(Object.assign({}, (_h = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _h === void 0 ? void 0 : _h.verifyCredential), { fetchRemoteContexts: (_j = opts === null || opts === void 0 ? void 0 : opts.issueCredentialOpts) === null || _j === void 0 ? void 0 : _j.fetchRemoteContexts }));
|
|
42
|
-
}
|
|
43
|
-
this._express.use((_l = (_k = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _k === void 0 ? void 0 : _k.basePath) !== null && _l !== void 0 ? _l : '', this.router);
|
|
44
|
-
}
|
|
45
|
-
get agent() {
|
|
46
|
-
return this._agent;
|
|
47
|
-
}
|
|
48
|
-
get opts() {
|
|
49
|
-
return this._opts;
|
|
50
|
-
}
|
|
51
|
-
get express() {
|
|
52
|
-
return this._express;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
exports.VcApiServer = VcApiServer;
|
|
56
|
-
function copyGlobalAuthToEndpoint(opts, key) {
|
|
57
|
-
var _a, _b;
|
|
58
|
-
if ((_a = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _a === void 0 ? void 0 : _a.globalAuth) {
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
opts.endpointOpts[key] = Object.assign(Object.assign({}, opts.endpointOpts[key]), {
|
|
61
|
-
// @ts-ignore
|
|
62
|
-
endpoint: Object.assign(Object.assign({}, opts.endpointOpts.globalAuth), (_b = opts.endpointOpts[key]) === null || _b === void 0 ? void 0 : _b.endpoint) });
|
|
63
|
-
}
|
|
64
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.VcApiServer = void 0;
|
|
7
|
+
const ssi_sdk_core_1 = require("@sphereon/ssi-sdk.core");
|
|
8
|
+
const express_1 = __importDefault(require("express"));
|
|
9
|
+
const api_functions_1 = require("./api-functions");
|
|
10
|
+
class VcApiServer {
|
|
11
|
+
get router() {
|
|
12
|
+
return this._router;
|
|
13
|
+
}
|
|
14
|
+
constructor(args) {
|
|
15
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
16
|
+
const { agent, opts } = args;
|
|
17
|
+
this._agent = agent;
|
|
18
|
+
if ((_a = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _a === void 0 ? void 0 : _a.globalAuth) {
|
|
19
|
+
copyGlobalAuthToEndpoint(opts, 'issueCredential');
|
|
20
|
+
copyGlobalAuthToEndpoint(opts, 'getCredential');
|
|
21
|
+
copyGlobalAuthToEndpoint(opts, 'getCredentials');
|
|
22
|
+
copyGlobalAuthToEndpoint(opts, 'deleteCredential');
|
|
23
|
+
copyGlobalAuthToEndpoint(opts, 'verifyCredential');
|
|
24
|
+
}
|
|
25
|
+
this._opts = opts;
|
|
26
|
+
this._express = args.expressSupport.express;
|
|
27
|
+
this._router = express_1.default.Router();
|
|
28
|
+
const context = (0, ssi_sdk_core_1.agentContext)(agent);
|
|
29
|
+
const features = (_c = (_b = opts === null || opts === void 0 ? void 0 : opts.issueCredentialOpts) === null || _b === void 0 ? void 0 : _b.enableFeatures) !== null && _c !== void 0 ? _c : ['vc-issue', 'vc-persist', 'vc-verify'];
|
|
30
|
+
console.log(`VC API enabled, with features: ${JSON.stringify(features)}`);
|
|
31
|
+
// Credential endpoints
|
|
32
|
+
if (features.includes('vc-issue')) {
|
|
33
|
+
(0, api_functions_1.issueCredentialEndpoint)(this.router, context, Object.assign(Object.assign({}, (_d = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _d === void 0 ? void 0 : _d.issueCredential), { issueCredentialOpts: opts === null || opts === void 0 ? void 0 : opts.issueCredentialOpts }));
|
|
34
|
+
}
|
|
35
|
+
if (features.includes('vc-persist')) {
|
|
36
|
+
(0, api_functions_1.getCredentialEndpoint)(this.router, context, (_e = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _e === void 0 ? void 0 : _e.getCredential);
|
|
37
|
+
(0, api_functions_1.getCredentialsEndpoint)(this.router, context, (_f = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _f === void 0 ? void 0 : _f.getCredentials);
|
|
38
|
+
(0, api_functions_1.deleteCredentialEndpoint)(this.router, context, (_g = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _g === void 0 ? void 0 : _g.deleteCredential); // not in spec.
|
|
39
|
+
}
|
|
40
|
+
if (features.includes('vc-verify')) {
|
|
41
|
+
(0, api_functions_1.verifyCredentialEndpoint)(this.router, context, Object.assign(Object.assign({}, (_h = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _h === void 0 ? void 0 : _h.verifyCredential), { fetchRemoteContexts: (_j = opts === null || opts === void 0 ? void 0 : opts.issueCredentialOpts) === null || _j === void 0 ? void 0 : _j.fetchRemoteContexts }));
|
|
42
|
+
}
|
|
43
|
+
this._express.use((_l = (_k = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _k === void 0 ? void 0 : _k.basePath) !== null && _l !== void 0 ? _l : '', this.router);
|
|
44
|
+
}
|
|
45
|
+
get agent() {
|
|
46
|
+
return this._agent;
|
|
47
|
+
}
|
|
48
|
+
get opts() {
|
|
49
|
+
return this._opts;
|
|
50
|
+
}
|
|
51
|
+
get express() {
|
|
52
|
+
return this._express;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.VcApiServer = VcApiServer;
|
|
56
|
+
function copyGlobalAuthToEndpoint(opts, key) {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
if ((_a = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _a === void 0 ? void 0 : _a.globalAuth) {
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
opts.endpointOpts[key] = Object.assign(Object.assign({}, opts.endpointOpts[key]), {
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
endpoint: Object.assign(Object.assign({}, opts.endpointOpts.globalAuth), (_b = opts.endpointOpts[key]) === null || _b === void 0 ? void 0 : _b.endpoint) });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
65
|
//# sourceMappingURL=vc-api-server.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.w3c-vc-api",
|
|
3
|
-
"version": "0.18.2-
|
|
3
|
+
"version": "0.18.2-unstable.13+4e744e0b",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@sphereon/did-auth-siop": "0.4.2",
|
|
15
|
-
"@sphereon/ssi-express-support": "0.18.2-
|
|
16
|
-
"@sphereon/ssi-sdk.core": "0.18.2-
|
|
17
|
-
"@sphereon/ssi-sdk.kv-store-temp": "0.18.2-
|
|
18
|
-
"@sphereon/ssi-sdk.presentation-exchange": "0.18.2-
|
|
19
|
-
"@sphereon/ssi-types": "0.18.2-
|
|
15
|
+
"@sphereon/ssi-express-support": "0.18.2-unstable.13+4e744e0b",
|
|
16
|
+
"@sphereon/ssi-sdk.core": "0.18.2-unstable.13+4e744e0b",
|
|
17
|
+
"@sphereon/ssi-sdk.kv-store-temp": "0.18.2-unstable.13+4e744e0b",
|
|
18
|
+
"@sphereon/ssi-sdk.presentation-exchange": "0.18.2-unstable.13+4e744e0b",
|
|
19
|
+
"@sphereon/ssi-types": "0.18.2-unstable.13+4e744e0b",
|
|
20
20
|
"@veramo/core": "4.2.0",
|
|
21
21
|
"@veramo/credential-w3c": "4.2.0",
|
|
22
22
|
"body-parser": "^1.19.0",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@sphereon/did-uni-client": "^0.6.0",
|
|
35
|
-
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.
|
|
36
|
-
"@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.
|
|
37
|
-
"@sphereon/ssi-sdk.agent-config": "0.18.2-
|
|
38
|
-
"@sphereon/ssi-sdk.data-store": "0.18.2-
|
|
39
|
-
"@sphereon/ssi-sdk.vc-handler-ld-local": "0.18.2-
|
|
35
|
+
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.14.1-unstable.34+2f414ae",
|
|
36
|
+
"@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.14.1-unstable.34+2f414ae",
|
|
37
|
+
"@sphereon/ssi-sdk.agent-config": "0.18.2-unstable.13+4e744e0b",
|
|
38
|
+
"@sphereon/ssi-sdk.data-store": "0.18.2-unstable.13+4e744e0b",
|
|
39
|
+
"@sphereon/ssi-sdk.vc-handler-ld-local": "0.18.2-unstable.13+4e744e0b",
|
|
40
40
|
"@types/body-parser": "^1.19.2",
|
|
41
41
|
"@types/cookie-parser": "^1.4.3",
|
|
42
42
|
"@types/cors": "^2.8.13",
|
|
@@ -89,5 +89,5 @@
|
|
|
89
89
|
"W3C",
|
|
90
90
|
"VC API"
|
|
91
91
|
],
|
|
92
|
-
"gitHead": "
|
|
92
|
+
"gitHead": "4e744e0bde523847bf8db70438dc8407a602b4ee"
|
|
93
93
|
}
|