@sphereon/ssi-sdk.w3c-vc-api 0.23.5-unstable.88 → 0.24.0
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/package.json +10 -10
- package/src/api-functions.ts +146 -146
- package/dist/VCAPIServer.d.ts +0 -74
- package/dist/VCAPIServer.d.ts.map +0 -1
- package/dist/VCAPIServer.js +0 -333
- package/dist/VCAPIServer.js.map +0 -1
- package/dist/request-agent-router.d.ts +0 -30
- package/dist/request-agent-router.d.ts.map +0 -1
- package/dist/request-agent-router.js +0 -63
- package/dist/request-agent-router.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.w3c-vc-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
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.6.4",
|
|
15
|
-
"@sphereon/ssi-express-support": "0.
|
|
16
|
-
"@sphereon/ssi-sdk.core": "0.
|
|
17
|
-
"@sphereon/ssi-sdk.kv-store-temp": "0.
|
|
18
|
-
"@sphereon/ssi-sdk.presentation-exchange": "0.
|
|
19
|
-
"@sphereon/ssi-types": "0.
|
|
15
|
+
"@sphereon/ssi-express-support": "0.24.0",
|
|
16
|
+
"@sphereon/ssi-sdk.core": "0.24.0",
|
|
17
|
+
"@sphereon/ssi-sdk.kv-store-temp": "0.24.0",
|
|
18
|
+
"@sphereon/ssi-sdk.presentation-exchange": "0.24.0",
|
|
19
|
+
"@sphereon/ssi-types": "0.24.0",
|
|
20
20
|
"@veramo/core": "4.2.0",
|
|
21
21
|
"@veramo/credential-w3c": "4.2.0",
|
|
22
22
|
"body-parser": "^1.19.0",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.19.0",
|
|
37
37
|
"@sphereon/ssi-sdk-ext.key-manager": "0.19.0",
|
|
38
38
|
"@sphereon/ssi-sdk-ext.kms-local": "0.19.0",
|
|
39
|
-
"@sphereon/ssi-sdk.agent-config": "0.
|
|
40
|
-
"@sphereon/ssi-sdk.data-store": "0.
|
|
41
|
-
"@sphereon/ssi-sdk.vc-handler-ld-local": "0.
|
|
39
|
+
"@sphereon/ssi-sdk.agent-config": "0.24.0",
|
|
40
|
+
"@sphereon/ssi-sdk.data-store": "0.24.0",
|
|
41
|
+
"@sphereon/ssi-sdk.vc-handler-ld-local": "0.24.0",
|
|
42
42
|
"@types/body-parser": "^1.19.2",
|
|
43
43
|
"@types/cookie-parser": "^1.4.3",
|
|
44
44
|
"@types/cors": "^2.8.13",
|
|
@@ -91,5 +91,5 @@
|
|
|
91
91
|
"W3C",
|
|
92
92
|
"VC API"
|
|
93
93
|
],
|
|
94
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "fd8e1082588463c2bd5c8d81d711974971812ef7"
|
|
95
95
|
}
|
package/src/api-functions.ts
CHANGED
|
@@ -1,146 +1,146 @@
|
|
|
1
|
-
import { getCredentialByIdOrHash } from '@sphereon/ssi-sdk.core'
|
|
2
|
-
import { checkAuth, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'
|
|
3
|
-
import { CredentialPayload } from '@veramo/core'
|
|
4
|
-
import { ProofFormat } from '@veramo/core/src/types/ICredentialIssuer'
|
|
5
|
-
import { W3CVerifiableCredential } from '@veramo/core/src/types/vc-data-model'
|
|
6
|
-
import { Request, Response, Router } from 'express'
|
|
7
|
-
import { v4 } from 'uuid'
|
|
8
|
-
import { IIssueCredentialEndpointOpts, IRequiredContext, IVCAPIIssueOpts, IVerifyCredentialEndpointOpts } from './types'
|
|
9
|
-
import Debug from 'debug'
|
|
10
|
-
const debug = Debug('sphereon:ssi-sdk:w3c-vc-api')
|
|
11
|
-
export function issueCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IIssueCredentialEndpointOpts) {
|
|
12
|
-
if (opts?.enabled === false) {
|
|
13
|
-
console.log(`Issue credential endpoint is disabled`)
|
|
14
|
-
return
|
|
15
|
-
}
|
|
16
|
-
const path = opts?.path ?? '/credentials/issue'
|
|
17
|
-
|
|
18
|
-
router.post(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
19
|
-
try {
|
|
20
|
-
const credential: CredentialPayload = request.body.credential
|
|
21
|
-
const reqOpts = request.body.options ?? {}
|
|
22
|
-
let reqProofFormat: ProofFormat | undefined
|
|
23
|
-
if (reqOpts.proofFormat) {
|
|
24
|
-
if (reqOpts?.proofFormat?.includes('ld')) {
|
|
25
|
-
reqProofFormat = 'lds'
|
|
26
|
-
} else {
|
|
27
|
-
reqProofFormat = 'jwt'
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (!credential) {
|
|
31
|
-
return sendErrorResponse(response, 400, 'No credential supplied')
|
|
32
|
-
}
|
|
33
|
-
if (!credential.id) {
|
|
34
|
-
credential.id = `urn:uuid:${v4()}`
|
|
35
|
-
}
|
|
36
|
-
const issueOpts: IVCAPIIssueOpts | undefined = opts?.issueCredentialOpts
|
|
37
|
-
const vc = await context.agent.createVerifiableCredential({
|
|
38
|
-
credential,
|
|
39
|
-
save: opts?.persistIssuedCredentials !== false,
|
|
40
|
-
proofFormat: reqProofFormat ?? issueOpts?.proofFormat ?? 'lds',
|
|
41
|
-
fetchRemoteContexts: issueOpts?.fetchRemoteContexts !== false,
|
|
42
|
-
})
|
|
43
|
-
response.statusCode = 201
|
|
44
|
-
return response.send({ verifiableCredential: vc })
|
|
45
|
-
} catch (e) {
|
|
46
|
-
return sendErrorResponse(response, 500, e.message as string, e)
|
|
47
|
-
}
|
|
48
|
-
})
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function getCredentialsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {
|
|
52
|
-
if (opts?.enabled === false) {
|
|
53
|
-
console.log(`Get credentials endpoint is disabled`)
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
const path = opts?.path ?? '/credentials'
|
|
57
|
-
router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
58
|
-
try {
|
|
59
|
-
const uniqueVCs = await context.agent.dataStoreORMGetVerifiableCredentials()
|
|
60
|
-
response.statusCode = 202
|
|
61
|
-
return response.send(uniqueVCs.map((uVC) => uVC.verifiableCredential))
|
|
62
|
-
} catch (e) {
|
|
63
|
-
return sendErrorResponse(response, 500, e.message as string, e)
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function getCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {
|
|
69
|
-
if (opts?.enabled === false) {
|
|
70
|
-
console.log(`Get credential endpoint is disabled`)
|
|
71
|
-
return
|
|
72
|
-
}
|
|
73
|
-
const path = opts?.path ?? '/credentials/:id'
|
|
74
|
-
router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
75
|
-
try {
|
|
76
|
-
const id = request.params.id
|
|
77
|
-
if (!id) {
|
|
78
|
-
return sendErrorResponse(response, 400, 'no id provided')
|
|
79
|
-
}
|
|
80
|
-
let vcInfo = await getCredentialByIdOrHash(context, id)
|
|
81
|
-
if (!vcInfo.vc) {
|
|
82
|
-
return sendErrorResponse(response, 404, `id ${id} not found`)
|
|
83
|
-
}
|
|
84
|
-
response.statusCode = 200
|
|
85
|
-
return response.send(vcInfo.vc)
|
|
86
|
-
} catch (e) {
|
|
87
|
-
return sendErrorResponse(response, 500, e.message as string, e)
|
|
88
|
-
}
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function verifyCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IVerifyCredentialEndpointOpts) {
|
|
93
|
-
if (opts?.enabled === false) {
|
|
94
|
-
console.log(`Verify credential endpoint is disabled`)
|
|
95
|
-
return
|
|
96
|
-
}
|
|
97
|
-
router.post(opts?.path ?? '/credentials/verify', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
98
|
-
try {
|
|
99
|
-
debug(JSON.stringify(request.body, null, 2))
|
|
100
|
-
const credential: W3CVerifiableCredential = request.body.verifiableCredential
|
|
101
|
-
// const options: IIssueOptionsPayload = request.body.options
|
|
102
|
-
if (!credential) {
|
|
103
|
-
return sendErrorResponse(response, 400, 'No verifiable credential supplied')
|
|
104
|
-
}
|
|
105
|
-
const verifyResult = await context.agent.verifyCredential({
|
|
106
|
-
credential,
|
|
107
|
-
policies: {
|
|
108
|
-
credentialStatus: false, // Do not use built-in. We have our own statusList implementations
|
|
109
|
-
},
|
|
110
|
-
fetchRemoteContexts: opts?.fetchRemoteContexts !== false,
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
response.statusCode = 200
|
|
114
|
-
return response.send(verifyResult)
|
|
115
|
-
} catch (e) {
|
|
116
|
-
return sendErrorResponse(response, 500, e.message as string, e)
|
|
117
|
-
}
|
|
118
|
-
})
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export function deleteCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {
|
|
122
|
-
if (opts?.enabled === false) {
|
|
123
|
-
console.log(`Delete credential endpoint is disabled`)
|
|
124
|
-
return
|
|
125
|
-
}
|
|
126
|
-
router.delete(opts?.path ?? '/credentials/:id', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
127
|
-
try {
|
|
128
|
-
const id = request.params.id
|
|
129
|
-
if (!id) {
|
|
130
|
-
return sendErrorResponse(response, 400, 'no id provided')
|
|
131
|
-
}
|
|
132
|
-
let vcInfo = await getCredentialByIdOrHash(context, id)
|
|
133
|
-
if (!vcInfo.vc || !vcInfo.hash) {
|
|
134
|
-
return sendErrorResponse(response, 404, `id ${id} not found`)
|
|
135
|
-
}
|
|
136
|
-
const success = context.agent.dataStoreDeleteVerifiableCredential({ hash: vcInfo.hash })
|
|
137
|
-
if (!success) {
|
|
138
|
-
return sendErrorResponse(response, 400, `Could not delete Verifiable Credential with id ${id}`)
|
|
139
|
-
}
|
|
140
|
-
response.statusCode = 200
|
|
141
|
-
return response.send()
|
|
142
|
-
} catch (e) {
|
|
143
|
-
return sendErrorResponse(response, 500, e.message as string, e)
|
|
144
|
-
}
|
|
145
|
-
})
|
|
146
|
-
}
|
|
1
|
+
import { getCredentialByIdOrHash } from '@sphereon/ssi-sdk.core'
|
|
2
|
+
import { checkAuth, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'
|
|
3
|
+
import { CredentialPayload } from '@veramo/core'
|
|
4
|
+
import { ProofFormat } from '@veramo/core/src/types/ICredentialIssuer'
|
|
5
|
+
import { W3CVerifiableCredential } from '@veramo/core/src/types/vc-data-model'
|
|
6
|
+
import { Request, Response, Router } from 'express'
|
|
7
|
+
import { v4 } from 'uuid'
|
|
8
|
+
import { IIssueCredentialEndpointOpts, IRequiredContext, IVCAPIIssueOpts, IVerifyCredentialEndpointOpts } from './types'
|
|
9
|
+
import Debug from 'debug'
|
|
10
|
+
const debug = Debug('sphereon:ssi-sdk:w3c-vc-api')
|
|
11
|
+
export function issueCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IIssueCredentialEndpointOpts) {
|
|
12
|
+
if (opts?.enabled === false) {
|
|
13
|
+
console.log(`Issue credential endpoint is disabled`)
|
|
14
|
+
return
|
|
15
|
+
}
|
|
16
|
+
const path = opts?.path ?? '/credentials/issue'
|
|
17
|
+
|
|
18
|
+
router.post(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
19
|
+
try {
|
|
20
|
+
const credential: CredentialPayload = request.body.credential
|
|
21
|
+
const reqOpts = request.body.options ?? {}
|
|
22
|
+
let reqProofFormat: ProofFormat | undefined
|
|
23
|
+
if (reqOpts.proofFormat) {
|
|
24
|
+
if (reqOpts?.proofFormat?.includes('ld')) {
|
|
25
|
+
reqProofFormat = 'lds'
|
|
26
|
+
} else {
|
|
27
|
+
reqProofFormat = 'jwt'
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (!credential) {
|
|
31
|
+
return sendErrorResponse(response, 400, 'No credential supplied')
|
|
32
|
+
}
|
|
33
|
+
if (!credential.id) {
|
|
34
|
+
credential.id = `urn:uuid:${v4()}`
|
|
35
|
+
}
|
|
36
|
+
const issueOpts: IVCAPIIssueOpts | undefined = opts?.issueCredentialOpts
|
|
37
|
+
const vc = await context.agent.createVerifiableCredential({
|
|
38
|
+
credential,
|
|
39
|
+
save: opts?.persistIssuedCredentials !== false,
|
|
40
|
+
proofFormat: reqProofFormat ?? issueOpts?.proofFormat ?? 'lds',
|
|
41
|
+
fetchRemoteContexts: issueOpts?.fetchRemoteContexts !== false,
|
|
42
|
+
})
|
|
43
|
+
response.statusCode = 201
|
|
44
|
+
return response.send({ verifiableCredential: vc })
|
|
45
|
+
} catch (e) {
|
|
46
|
+
return sendErrorResponse(response, 500, e.message as string, e)
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function getCredentialsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {
|
|
52
|
+
if (opts?.enabled === false) {
|
|
53
|
+
console.log(`Get credentials endpoint is disabled`)
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
const path = opts?.path ?? '/credentials'
|
|
57
|
+
router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
58
|
+
try {
|
|
59
|
+
const uniqueVCs = await context.agent.dataStoreORMGetVerifiableCredentials()
|
|
60
|
+
response.statusCode = 202
|
|
61
|
+
return response.send(uniqueVCs.map((uVC) => uVC.verifiableCredential))
|
|
62
|
+
} catch (e) {
|
|
63
|
+
return sendErrorResponse(response, 500, e.message as string, e)
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function getCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {
|
|
69
|
+
if (opts?.enabled === false) {
|
|
70
|
+
console.log(`Get credential endpoint is disabled`)
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
const path = opts?.path ?? '/credentials/:id'
|
|
74
|
+
router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
75
|
+
try {
|
|
76
|
+
const id = request.params.id
|
|
77
|
+
if (!id) {
|
|
78
|
+
return sendErrorResponse(response, 400, 'no id provided')
|
|
79
|
+
}
|
|
80
|
+
let vcInfo = await getCredentialByIdOrHash(context, id)
|
|
81
|
+
if (!vcInfo.vc) {
|
|
82
|
+
return sendErrorResponse(response, 404, `id ${id} not found`)
|
|
83
|
+
}
|
|
84
|
+
response.statusCode = 200
|
|
85
|
+
return response.send(vcInfo.vc)
|
|
86
|
+
} catch (e) {
|
|
87
|
+
return sendErrorResponse(response, 500, e.message as string, e)
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function verifyCredentialEndpoint(router: Router, context: IRequiredContext, opts?: IVerifyCredentialEndpointOpts) {
|
|
93
|
+
if (opts?.enabled === false) {
|
|
94
|
+
console.log(`Verify credential endpoint is disabled`)
|
|
95
|
+
return
|
|
96
|
+
}
|
|
97
|
+
router.post(opts?.path ?? '/credentials/verify', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
98
|
+
try {
|
|
99
|
+
debug(JSON.stringify(request.body, null, 2))
|
|
100
|
+
const credential: W3CVerifiableCredential = request.body.verifiableCredential
|
|
101
|
+
// const options: IIssueOptionsPayload = request.body.options
|
|
102
|
+
if (!credential) {
|
|
103
|
+
return sendErrorResponse(response, 400, 'No verifiable credential supplied')
|
|
104
|
+
}
|
|
105
|
+
const verifyResult = await context.agent.verifyCredential({
|
|
106
|
+
credential,
|
|
107
|
+
policies: {
|
|
108
|
+
credentialStatus: false, // Do not use built-in. We have our own statusList implementations
|
|
109
|
+
},
|
|
110
|
+
fetchRemoteContexts: opts?.fetchRemoteContexts !== false,
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
response.statusCode = 200
|
|
114
|
+
return response.send(verifyResult)
|
|
115
|
+
} catch (e) {
|
|
116
|
+
return sendErrorResponse(response, 500, e.message as string, e)
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function deleteCredentialEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts) {
|
|
122
|
+
if (opts?.enabled === false) {
|
|
123
|
+
console.log(`Delete credential endpoint is disabled`)
|
|
124
|
+
return
|
|
125
|
+
}
|
|
126
|
+
router.delete(opts?.path ?? '/credentials/:id', checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
127
|
+
try {
|
|
128
|
+
const id = request.params.id
|
|
129
|
+
if (!id) {
|
|
130
|
+
return sendErrorResponse(response, 400, 'no id provided')
|
|
131
|
+
}
|
|
132
|
+
let vcInfo = await getCredentialByIdOrHash(context, id)
|
|
133
|
+
if (!vcInfo.vc || !vcInfo.hash) {
|
|
134
|
+
return sendErrorResponse(response, 404, `id ${id} not found`)
|
|
135
|
+
}
|
|
136
|
+
const success = context.agent.dataStoreDeleteVerifiableCredential({ hash: vcInfo.hash })
|
|
137
|
+
if (!success) {
|
|
138
|
+
return sendErrorResponse(response, 400, `Could not delete Verifiable Credential with id ${id}`)
|
|
139
|
+
}
|
|
140
|
+
response.statusCode = 200
|
|
141
|
+
return response.send()
|
|
142
|
+
} catch (e) {
|
|
143
|
+
return sendErrorResponse(response, 500, e.message as string, e)
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
}
|
package/dist/VCAPIServer.d.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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;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C;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"}
|
package/dist/VCAPIServer.js
DELETED
|
@@ -1,333 +0,0 @@
|
|
|
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
|
package/dist/VCAPIServer.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"VCAPIServer.js","sourceRoot":"","sources":["../src/VCAPIServer.ts"],"names":[],"mappings":";AAAA,qCAAqC;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OAAO,QAAQ,CAAC,IAAI,CAAC,EAAE,oBAAoB,EAAE,EAAE,EAAE,CAAC,CAAA;aACnD;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;gBACd,OAAO,WAAW,CAAC,iBAAiB,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC,OAAiB,CAAC,CAAA;aACzE;QACH,CAAC,CAAA,CAAC,CAAA;IACJ,CAAC;IAEa,uBAAuB,CAAC,QAAgB;;YAKpD,IAAI,EAAwB,CAAA;YAC5B,IAAI,IAAY,CAAA;YAChB,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,oCAAoC,CAAC;gBACtE,KAAK,EAAE;oBACL;wBACE,MAAM,EAAE,IAAI;wBACZ,KAAK,EAAE,CAAC,QAAQ,CAAC;wBACjB,EAAE,EAAE,OAAO;qBACZ;iBACF;aACF,CAAC,CAAA;YACF,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,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"}
|
|
@@ -1,30 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,63 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|