1- // import { RP, CreateJwtCallback, VerifyJwtCallback, ResponseType, ResponseMode, Scope, PassBy, SupportedVersion, SubjectType } from '@sphereon/did-auth-siop';
21import { agent } from './veramo' ;
32import { getUniResolver } from '@sphereon/did-uni-client' ;
43import { Resolvable , Resolver , ResolverRegistry } from 'did-resolver' ;
54import { createJWT , decodeJWT , verifyJWT } from 'did-jwt' ;
65import { JWTHeader } from 'did-jwt/lib/JWT' ;
7- // import { VerifyCallback } from '@sphereon/wellknown-dids-client';
8- // import { parseJWT, SigningAlgo } from '@sphereon/oid4vc-common';
9- // import { VerifiedJWT } from '@sphereon/did-auth-siop';
106import { bytesToBase64 , createJWK } from '@veramo/utils' ;
11- // import objectPath from 'object-path';
127import moment from 'moment' ;
138
149const domain : string = process . env . DOMAIN !== undefined ? process . env . DOMAIN : '' ;
1510const url = new URL ( domain ) ;
1611const url_res = url . protocol + "//" + url . hostname + "/api/vp/response" ;
17- // const url_auth = url.protocol + "//" + url.hostname + "/api/vp/authorize";
1812
1913const createAuthRequest = async ( nonce :string , state :string , type :string , pd_id :string ) => {
2014 const identifier = await agent . didManagerGetOrCreate ( { alias : 'default' } ) ;
@@ -159,18 +153,6 @@ const verifyAuthResponse = async(jwt:string) => {
159153 }
160154}
161155
162- // const getAudience = (jwt: string) => {
163- // const { payload } = parseJWT(jwt)
164- // if (!payload) {
165- // throw new Error('No audience found in JWT payload or not configured')
166- // } else if (!payload.aud) {
167- // return undefined
168- // } else if (Array.isArray(payload.aud)) {
169- // throw new Error('Audience is invalid. Should be a string value.')
170- // }
171- // return payload.aud
172- // }
173-
174156const getResolver = ( methods : string | string [ ] ) : Resolvable => {
175157 const getMethodFromDid = ( did : string ) : string => {
176158 if ( ! did ) {
@@ -193,148 +175,4 @@ const getResolver = (methods: string | string[]): Resolvable => {
193175 return new Resolver ( ...uniResolvers ) ;
194176}
195177
196- // const verifyJwtCallback = (
197- // // resolver?: Resolvable,
198- // verifyOpts?: JWTVerifyOptions & {
199- // checkLinkedDomain: 'never' | 'if_present' | 'always'
200- // wellknownDIDVerifyCallback?: VerifyCallback
201- // },
202- // ): VerifyJwtCallback => {
203- // return async (jwtVerifier, jwt) => {
204- // const resolver = getResolver(objectPath.get(jwtVerifier, 'didUrl'))
205- // console.log(resolver)
206- // console.log(jwtVerifier)
207- // const audience =
208- // jwtVerifier.type === 'request-object'
209- // ? (verifyOpts?.audience ?? getAudience(jwt.raw))
210- // : jwtVerifier.type === 'id-token'
211- // ? (verifyOpts?.audience ?? getAudience(jwt.raw))
212- // : undefined
213- // await verifyDidJWT(jwt.raw, resolver, { audience, ...verifyOpts })
214- // return true
215- // }
216- // }
217-
218- // const createJwtCallback = (): CreateJwtCallback => {
219- // return async (jwtIssuer, jwt) => {
220- // if (jwtIssuer.method === 'did') {
221- // const jwk = createJWK("Ed25519", identifier.keys[0].publicKeyHex);
222- // jwt.header = {alg: 'EdDSA', typ: 'JWT', jwk: jwk };
223- // const signer = (data: string | Uint8Array ) => {
224- // let dataString, encoding: 'base64' | undefined
225- // if (typeof data === 'string') {
226- // dataString = data
227- // encoding = undefined
228- // } else {
229- // ;(dataString = bytesToBase64(data)), (encoding = 'base64')
230- // }
231- // return agent.keyManagerSign({ keyRef: identifier.keys[0].kid, data: dataString, alg: jwt.header.alg })
232- // }
233- // const jwt_created = await createJWT(
234- // jwt.payload,
235- // { issuer: identifier.did, signer, alg: jwt.header.alg },
236- // jwt.header as Partial<JWTHeader>
237- // );
238- // return jwt_created;
239- // }
240- // throw new Error('Not implemented yet')
241- // }
242- // }
243-
244- // const verifyDidJWT = async(jwt: string, resolver: Resolvable, options: JWTVerifyOptions): Promise<VerifiedJWT> => {
245- // try {
246- // return await verifyJWT(jwt, { ...options, resolver })
247- // } catch (e: any) {
248- // return Promise.reject(e)
249- // }
250- // }
251-
252- // const rp = (type:string, id:string) => {
253- // let constraints = {};
254- // if (type === 'NPI') {
255- // constraints = {
256- // "fields": [
257- // {
258- // "path": [
259- // "$.vc.credentialSubject.npi",
260- // "$.vc.credentialSubject.name",
261- // "$.vc.credentialSubject.description",
262- // "$.vc.credentialSubject.gender",
263- // "$.vc.credentialSubject.city",
264- // "$.vc.credentialSubject.state",
265- // "$.vc.credentialSubject.zip",
266- // "$.vc.credentialSubject.credentials",
267- // "$.vc.credentialSubject.specialty",
268- // "$.vc.credentialSubject.medicalSchools",
269- // "$.vc.credentialSubject.residencies",
270- // "$.vc.credentialSubject.profilePhoto",
271- // ]
272- // }
273- // ]
274- // }
275- // } else {
276- // constraints = {
277- // "fields": [
278- // {
279- // "path": [
280- // "$.vc.credentialSubject.name",
281- // "$.vc.credentialSubject.email",
282- // "$.vc.credentialSubject.dob"
283- // ]
284- // }
285- // ]
286- // }
287- // }
288- // return RP.builder()
289- // // return RP.builder({ requestVersion: SupportedVersion.SIOPv2_ID1 })
290- // .withClientId(identifier.did)
291- // .withScope('openid')
292- // .withResponseType('vp_token id_token')
293- // .withResponseMode(ResponseMode.POST)
294- // .withAuthorizationEndpoint(url_auth)
295- // .withRedirectUri(url_res)
296- // .withVerifyJwtCallback(verifyJwtCallback())
297- // .withRequestBy(PassBy.VALUE)
298- // .withCreateJwtCallback(createJwtCallback())
299- // // .withAudience(aud)
300- // // .withSupportedVersions(SupportedVersion.SIOPv2_ID1)
301- // .withSupportedVersions(SupportedVersion.SIOPv2_D12_OID4VP_D20)
302- // .withPresentationDefinition({
303- // definition: {
304- // id: id,
305- // input_descriptors: [
306- // {
307- // "id": "1",
308- // "name": type + " Verifiable Credential",
309- // "purpose": "We want a VC of this type to proof provider claim",
310- // "constraints": constraints,
311- // "schema": [
312- // {
313- // "uri": "https://www.w3.org/2018/credentials/v1"
314- // }
315- // ]
316- // }
317- // ]
318- // }
319- // })
320- // .withClientMetadata({
321- // client_id: identifier.did,
322- // idTokenSigningAlgValuesSupported: [SigningAlgo.EDDSA, SigningAlgo.ES256],
323- // requestObjectSigningAlgValuesSupported: [SigningAlgo.EDDSA, SigningAlgo.ES256],
324- // responseTypesSupported: [ResponseType.ID_TOKEN, ResponseType.VP_TOKEN],
325- // vpFormatsSupported: {
326- // jwt_vc: { alg: [SigningAlgo.EDDSA, SigningAlgo.RS256, SigningAlgo.ES256] },
327- // jwt_vp: { alg: [SigningAlgo.EDDSA, SigningAlgo.RS256, SigningAlgo.ES256] }
328- // },
329- // scopesSupported: [Scope.OPENID_DIDAUTHN, Scope.OPENID],
330- // subjectTypesSupported: [SubjectType.PAIRWISE],
331- // subject_syntax_types_supported: ['did', 'did:ethr', 'did:key', 'did:jwk', 'did:web', 'did:ion'],
332- // passBy: PassBy.VALUE,
333- // // logo_uri: VERIFIER_LOGO_FOR_CLIENT,
334- // clientName: 'Trustee',
335- // clientPurpose: "Grant Negotiation and Authorization Protocol (GNAP) Server"
336- // })
337- // .build();
338- // }
339-
340178export { createAuthRequest , verifyAuthResponse }
0 commit comments