@sphereon/oid4vci-client 0.10.3 → 0.10.4-next.119
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/README.md +24 -5
- package/dist/AccessTokenClient.d.ts +5 -5
- package/dist/AccessTokenClient.d.ts.map +1 -1
- package/dist/AccessTokenClient.js +51 -37
- package/dist/AccessTokenClient.js.map +1 -1
- package/dist/AccessTokenClientV1_0_11.d.ts +29 -0
- package/dist/AccessTokenClientV1_0_11.d.ts.map +1 -0
- package/dist/AccessTokenClientV1_0_11.js +209 -0
- package/dist/AccessTokenClientV1_0_11.js.map +1 -0
- package/dist/AuthorizationCodeClient.d.ts +9 -4
- package/dist/AuthorizationCodeClient.d.ts.map +1 -1
- package/dist/AuthorizationCodeClient.js +102 -18
- package/dist/AuthorizationCodeClient.js.map +1 -1
- package/dist/AuthorizationCodeClientV1_0_11.d.ts +9 -0
- package/dist/AuthorizationCodeClientV1_0_11.d.ts.map +1 -0
- package/dist/AuthorizationCodeClientV1_0_11.js +134 -0
- package/dist/AuthorizationCodeClientV1_0_11.js.map +1 -0
- package/dist/CredentialOfferClient.d.ts.map +1 -1
- package/dist/CredentialOfferClient.js +18 -13
- package/dist/CredentialOfferClient.js.map +1 -1
- package/dist/CredentialOfferClientV1_0_11.d.ts +10 -0
- package/dist/CredentialOfferClientV1_0_11.d.ts.map +1 -0
- package/dist/CredentialOfferClientV1_0_11.js +101 -0
- package/dist/CredentialOfferClientV1_0_11.js.map +1 -0
- package/dist/CredentialOfferClientV1_0_13.d.ts +10 -0
- package/dist/CredentialOfferClientV1_0_13.d.ts.map +1 -0
- package/dist/CredentialOfferClientV1_0_13.js +94 -0
- package/dist/CredentialOfferClientV1_0_13.js.map +1 -0
- package/dist/CredentialRequestClient.d.ts +20 -7
- package/dist/CredentialRequestClient.d.ts.map +1 -1
- package/dist/CredentialRequestClient.js +46 -30
- package/dist/CredentialRequestClient.js.map +1 -1
- package/dist/CredentialRequestClientBuilder.d.ts +11 -6
- package/dist/CredentialRequestClientBuilder.d.ts.map +1 -1
- package/dist/CredentialRequestClientBuilder.js +22 -9
- package/dist/CredentialRequestClientBuilder.js.map +1 -1
- package/dist/CredentialRequestClientBuilderV1_0_11.d.ts +48 -0
- package/dist/CredentialRequestClientBuilderV1_0_11.d.ts.map +1 -0
- package/dist/CredentialRequestClientBuilderV1_0_11.js +121 -0
- package/dist/CredentialRequestClientBuilderV1_0_11.js.map +1 -0
- package/dist/CredentialRequestClientV1_0_11.d.ts +50 -0
- package/dist/CredentialRequestClientV1_0_11.d.ts.map +1 -0
- package/dist/CredentialRequestClientV1_0_11.js +151 -0
- package/dist/CredentialRequestClientV1_0_11.js.map +1 -0
- package/dist/MetadataClient.d.ts +5 -15
- package/dist/MetadataClient.d.ts.map +1 -1
- package/dist/MetadataClient.js +41 -44
- package/dist/MetadataClient.js.map +1 -1
- package/dist/MetadataClientV1_0_11.d.ts +31 -0
- package/dist/MetadataClientV1_0_11.d.ts.map +1 -0
- package/dist/MetadataClientV1_0_11.js +182 -0
- package/dist/MetadataClientV1_0_11.js.map +1 -0
- package/dist/MetadataClientV1_0_13.d.ts +31 -0
- package/dist/MetadataClientV1_0_13.d.ts.map +1 -0
- package/dist/MetadataClientV1_0_13.js +181 -0
- package/dist/MetadataClientV1_0_13.js.map +1 -0
- package/dist/OpenID4VCIClient.d.ts +14 -19
- package/dist/OpenID4VCIClient.d.ts.map +1 -1
- package/dist/OpenID4VCIClient.js +111 -61
- package/dist/OpenID4VCIClient.js.map +1 -1
- package/dist/OpenID4VCIClientV1_0_11.d.ts +108 -0
- package/dist/OpenID4VCIClientV1_0_11.d.ts.map +1 -0
- package/dist/OpenID4VCIClientV1_0_11.js +449 -0
- package/dist/OpenID4VCIClientV1_0_11.js.map +1 -0
- package/dist/OpenID4VCIClientV1_0_13.d.ts +112 -0
- package/dist/OpenID4VCIClientV1_0_13.d.ts.map +1 -0
- package/dist/OpenID4VCIClientV1_0_13.js +478 -0
- package/dist/OpenID4VCIClientV1_0_13.js.map +1 -0
- package/dist/ProofOfPossessionBuilder.d.ts +14 -3
- package/dist/ProofOfPossessionBuilder.d.ts.map +1 -1
- package/dist/ProofOfPossessionBuilder.js +20 -21
- package/dist/ProofOfPossessionBuilder.js.map +1 -1
- package/dist/functions/OpenIDUtils.d.ts +12 -0
- package/dist/functions/OpenIDUtils.d.ts.map +1 -0
- package/dist/functions/OpenIDUtils.js +37 -0
- package/dist/functions/OpenIDUtils.js.map +1 -0
- package/dist/functions/index.d.ts +2 -3
- package/dist/functions/index.d.ts.map +1 -1
- package/dist/functions/index.js +2 -3
- package/dist/functions/index.js.map +1 -1
- package/dist/functions/notifications.d.ts +4 -0
- package/dist/functions/notifications.d.ts.map +1 -0
- package/dist/functions/notifications.js +39 -0
- package/dist/functions/notifications.js.map +1 -0
- package/dist/index.d.ts +13 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -1
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -1
- package/lib/AccessTokenClient.ts +59 -34
- package/lib/AccessTokenClientV1_0_11.ts +250 -0
- package/lib/AuthorizationCodeClient.ts +131 -28
- package/lib/AuthorizationCodeClientV1_0_11.ts +170 -0
- package/lib/CredentialOfferClient.ts +21 -8
- package/lib/CredentialOfferClientV1_0_11.ts +112 -0
- package/lib/CredentialOfferClientV1_0_13.ts +103 -0
- package/lib/CredentialRequestClient.ts +65 -26
- package/lib/CredentialRequestClientBuilder.ts +34 -16
- package/lib/CredentialRequestClientBuilderV1_0_11.ts +163 -0
- package/lib/CredentialRequestClientV1_0_11.ts +197 -0
- package/lib/MetadataClient.ts +64 -49
- package/lib/MetadataClientV1_0_11.ts +189 -0
- package/lib/MetadataClientV1_0_13.ts +188 -0
- package/lib/OpenID4VCIClient.ts +132 -68
- package/lib/OpenID4VCIClientV1_0_11.ts +635 -0
- package/lib/OpenID4VCIClientV1_0_13.ts +677 -0
- package/lib/ProofOfPossessionBuilder.ts +41 -11
- package/lib/__tests__/AccessTokenClient.spec.ts +40 -12
- package/lib/__tests__/AuthorizationDetailsBuilder.spec.ts +0 -12
- package/lib/__tests__/CredentialRequestClient.spec.ts +87 -50
- package/lib/__tests__/CredentialRequestClientBuilder.spec.ts +18 -12
- package/lib/__tests__/CredentialRequestClientV1_0_11.spec.ts +317 -0
- package/lib/__tests__/EBSIE2E.spec.test.ts +2 -2
- package/lib/__tests__/HttpUtils.spec.ts +1 -1
- package/lib/__tests__/IT.spec.ts +264 -14
- package/lib/__tests__/IssuanceInitiation.spec.ts +59 -4
- package/lib/__tests__/IssuanceInitiationV1_0_11.spec.ts +62 -0
- package/lib/__tests__/MattrE2E.spec.test.ts +2 -2
- package/lib/__tests__/MetadataClient.spec.ts +53 -3
- package/lib/__tests__/MetadataMocks.ts +42 -2
- package/lib/__tests__/OpenID4VCIClient.spec.ts +58 -2
- package/lib/__tests__/{OpenID4VCIClientPAR.spec.ts → OpenID4VCIClientPARV1_0_11.spec.ts} +5 -5
- package/lib/__tests__/OpenID4VCIClientV1_0_11.spec.ts +226 -0
- package/lib/__tests__/OpenID4VCIClientV1_0_13.spec.ts +204 -0
- package/lib/__tests__/ProofOfPossessionBuilder.spec.ts +1 -1
- package/lib/__tests__/SdJwt.spec.ts +36 -30
- package/lib/__tests__/SphereonE2E.spec.test.ts +10 -7
- package/lib/__tests__/data/VciDataFixtures.ts +712 -27
- package/lib/functions/OpenIDUtils.ts +25 -0
- package/lib/functions/index.ts +2 -3
- package/lib/functions/notifications.ts +32 -0
- package/lib/index.ts +16 -1
- package/lib/types/index.ts +6 -0
- package/package.json +4 -4
- package/dist/functions/ProofUtil.d.ts +0 -30
- package/dist/functions/ProofUtil.d.ts.map +0 -1
- package/dist/functions/ProofUtil.js +0 -106
- package/dist/functions/ProofUtil.js.map +0 -1
- package/lib/functions/ProofUtil.ts +0 -128
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { KeyObject } from 'crypto';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
Alg,
|
|
5
|
+
EndpointMetadata,
|
|
6
|
+
getCredentialRequestForVersion,
|
|
7
|
+
getIssuerFromCredentialOfferPayload,
|
|
8
|
+
Jwt,
|
|
9
|
+
OpenId4VCIVersion,
|
|
10
|
+
ProofOfPossession,
|
|
11
|
+
URL_NOT_VALID,
|
|
12
|
+
WellKnownEndpoints,
|
|
13
|
+
} from '@sphereon/oid4vci-common';
|
|
14
|
+
import * as jose from 'jose';
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
import nock from 'nock';
|
|
18
|
+
|
|
19
|
+
import { CredentialOfferClientV1_0_11, CredentialRequestClientBuilderV1_0_11, MetadataClientV1_0_13, ProofOfPossessionBuilder } from '..';
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
IDENTIPROOF_ISSUER_URL,
|
|
23
|
+
IDENTIPROOF_OID4VCI_METADATA,
|
|
24
|
+
INITIATION_TEST,
|
|
25
|
+
INITIATION_TEST_V1_0_08,
|
|
26
|
+
WALT_OID4VCI_METADATA,
|
|
27
|
+
} from './MetadataMocks';
|
|
28
|
+
import { getMockData } from './data/VciDataFixtures';
|
|
29
|
+
|
|
30
|
+
const partialJWT = 'eyJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmN';
|
|
31
|
+
|
|
32
|
+
const jwt: Jwt = {
|
|
33
|
+
header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1', typ: 'jwt' },
|
|
34
|
+
payload: { iss: 'sphereon:wallet', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: IDENTIPROOF_ISSUER_URL },
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const kid = 'did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1';
|
|
38
|
+
|
|
39
|
+
let keypair: KeyPair;
|
|
40
|
+
|
|
41
|
+
async function proofOfPossessionCallbackFunction(args: Jwt, kid?: string): Promise<string> {
|
|
42
|
+
if (!args.payload.aud) {
|
|
43
|
+
throw Error('aud required');
|
|
44
|
+
} else if (!kid) {
|
|
45
|
+
throw Error('kid required');
|
|
46
|
+
}
|
|
47
|
+
return await new jose.SignJWT({ ...args.payload })
|
|
48
|
+
.setProtectedHeader({ alg: 'ES256' })
|
|
49
|
+
.setIssuedAt()
|
|
50
|
+
.setIssuer(kid)
|
|
51
|
+
.setAudience(args.payload.aud)
|
|
52
|
+
.setExpirationTime('2h')
|
|
53
|
+
.sign(keypair.privateKey);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface KeyPair {
|
|
57
|
+
publicKey: KeyObject;
|
|
58
|
+
privateKey: KeyObject;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
beforeAll(async () => {
|
|
62
|
+
const { privateKey, publicKey } = await jose.generateKeyPair('ES256');
|
|
63
|
+
keypair = { publicKey: publicKey as KeyObject, privateKey: privateKey as KeyObject };
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
beforeEach(async () => {
|
|
67
|
+
nock.cleanAll();
|
|
68
|
+
nock(IDENTIPROOF_ISSUER_URL).get(WellKnownEndpoints.OPENID4VCI_ISSUER).reply(200, JSON.stringify(IDENTIPROOF_OID4VCI_METADATA));
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
afterEach(async () => {
|
|
72
|
+
nock.cleanAll();
|
|
73
|
+
});
|
|
74
|
+
describe('Credential Request Client ', () => {
|
|
75
|
+
it('should get a failed credential response with an unsupported format', async function () {
|
|
76
|
+
const basePath = 'https://sphereonjunit2022101301.com/';
|
|
77
|
+
nock(basePath).post(/.*/).reply(500, {
|
|
78
|
+
error: 'unsupported_format',
|
|
79
|
+
error_description: 'This is a mock error message',
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const credReqClient = CredentialRequestClientBuilderV1_0_11.fromCredentialOffer({ credentialOffer: INITIATION_TEST_V1_0_08 })
|
|
83
|
+
.withCredentialEndpoint(basePath + '/credential')
|
|
84
|
+
.withFormat('ldp_vc')
|
|
85
|
+
.withCredentialType('https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential')
|
|
86
|
+
.build();
|
|
87
|
+
const proof: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({
|
|
88
|
+
jwt,
|
|
89
|
+
callbacks: {
|
|
90
|
+
signCallback: proofOfPossessionCallbackFunction,
|
|
91
|
+
},
|
|
92
|
+
version: OpenId4VCIVersion.VER_1_0_08,
|
|
93
|
+
})
|
|
94
|
+
// .withEndpointMetadata(metadata)
|
|
95
|
+
.withClientId('sphereon:wallet')
|
|
96
|
+
.withKid(kid)
|
|
97
|
+
.build();
|
|
98
|
+
expect(credReqClient.getCredentialEndpoint()).toEqual(basePath + '/credential');
|
|
99
|
+
const credentialRequest = await credReqClient.createCredentialRequest({ proofInput: proof, version: OpenId4VCIVersion.VER_1_0_08 });
|
|
100
|
+
expect(credentialRequest.proof?.jwt?.includes(partialJWT)).toBeTruthy();
|
|
101
|
+
const result = await credReqClient.acquireCredentialsUsingRequest(credentialRequest);
|
|
102
|
+
expect(result?.errorBody?.error).toBe('unsupported_format');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('should get success credential response', async function () {
|
|
106
|
+
const mockedVC =
|
|
107
|
+
'eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA';
|
|
108
|
+
nock('https://oidc4vci.demo.spruceid.com')
|
|
109
|
+
.post(/credential/)
|
|
110
|
+
.reply(200, {
|
|
111
|
+
format: 'jwt-vc',
|
|
112
|
+
credential: mockedVC,
|
|
113
|
+
});
|
|
114
|
+
const credReqClient = CredentialRequestClientBuilderV1_0_11.fromCredentialOfferRequest({ request: INITIATION_TEST })
|
|
115
|
+
.withCredentialEndpoint('https://oidc4vci.demo.spruceid.com/credential')
|
|
116
|
+
.withFormat('jwt_vc')
|
|
117
|
+
.withCredentialType('https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential')
|
|
118
|
+
.build();
|
|
119
|
+
const proof: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({
|
|
120
|
+
jwt,
|
|
121
|
+
callbacks: {
|
|
122
|
+
signCallback: proofOfPossessionCallbackFunction,
|
|
123
|
+
},
|
|
124
|
+
version: OpenId4VCIVersion.VER_1_0_08,
|
|
125
|
+
})
|
|
126
|
+
// .withEndpointMetadata(metadata)
|
|
127
|
+
.withKid(kid)
|
|
128
|
+
.withClientId('sphereon:wallet')
|
|
129
|
+
.build();
|
|
130
|
+
const credentialRequest = await credReqClient.createCredentialRequest({
|
|
131
|
+
proofInput: proof,
|
|
132
|
+
format: 'jwt',
|
|
133
|
+
version: OpenId4VCIVersion.VER_1_0_08,
|
|
134
|
+
});
|
|
135
|
+
expect(credentialRequest.proof?.jwt?.includes(partialJWT)).toBeTruthy();
|
|
136
|
+
expect(credentialRequest.format).toEqual('jwt_vc');
|
|
137
|
+
const result = await credReqClient.acquireCredentialsUsingRequest(credentialRequest);
|
|
138
|
+
expect(result?.successBody?.credential).toEqual(mockedVC);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('should fail with invalid url', async () => {
|
|
142
|
+
const credReqClient = CredentialRequestClientBuilderV1_0_11.fromCredentialOfferRequest({ request: INITIATION_TEST })
|
|
143
|
+
.withCredentialEndpoint('httpsf://oidc4vci.demo.spruceid.com/credential')
|
|
144
|
+
.withFormat('jwt_vc')
|
|
145
|
+
.withCredentialType('https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential')
|
|
146
|
+
.build();
|
|
147
|
+
const proof: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({
|
|
148
|
+
jwt,
|
|
149
|
+
callbacks: {
|
|
150
|
+
signCallback: proofOfPossessionCallbackFunction,
|
|
151
|
+
},
|
|
152
|
+
version: OpenId4VCIVersion.VER_1_0_08,
|
|
153
|
+
})
|
|
154
|
+
// .withEndpointMetadata(metadata)
|
|
155
|
+
.withKid(kid)
|
|
156
|
+
.withClientId('sphereon:wallet')
|
|
157
|
+
.build();
|
|
158
|
+
await expect(credReqClient.acquireCredentialsUsingRequest({ format: 'jwt_vc_json', types: ['random'], proof })).rejects.toThrow(
|
|
159
|
+
Error(URL_NOT_VALID),
|
|
160
|
+
);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
describe('Credential Request Client with Walt.id ', () => {
|
|
165
|
+
beforeEach(() => {
|
|
166
|
+
nock.cleanAll();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
afterEach(() => {
|
|
170
|
+
nock.cleanAll();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it.skip('should have correct metadata endpoints', async function () {
|
|
174
|
+
nock.cleanAll();
|
|
175
|
+
const WALT_IRR_URI =
|
|
176
|
+
'openid-initiate-issuance://?issuer=https%3A%2F%2Fjff.walt.id%2Fissuer-api%2Foidc%2F&credential_type=OpenBadgeCredential&pre-authorized_code=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhOTUyZjUxNi1jYWVmLTQ4YjMtODIxYy00OTRkYzgyNjljZjAiLCJwcmUtYXV0aG9yaXplZCI6dHJ1ZX0.YE5DlalcLC2ChGEg47CQDaN1gTxbaQqSclIVqsSAUHE&user_pin_required=false';
|
|
177
|
+
const credentialOffer = await CredentialOfferClientV1_0_11.fromURI(WALT_IRR_URI);
|
|
178
|
+
|
|
179
|
+
const request = credentialOffer.credential_offer;
|
|
180
|
+
const metadata = await MetadataClientV1_0_13.retrieveAllMetadata(getIssuerFromCredentialOfferPayload(request) as string);
|
|
181
|
+
expect(metadata.credential_endpoint).toEqual(WALT_OID4VCI_METADATA.credential_endpoint);
|
|
182
|
+
expect(metadata.token_endpoint).toEqual(WALT_OID4VCI_METADATA.token_endpoint);
|
|
183
|
+
|
|
184
|
+
const credReqClient = CredentialRequestClientBuilderV1_0_11.fromCredentialOffer({
|
|
185
|
+
credentialOffer,
|
|
186
|
+
metadata,
|
|
187
|
+
}).build();
|
|
188
|
+
expect(credReqClient.credentialRequestOpts.credentialEndpoint).toBe(WALT_OID4VCI_METADATA.credential_endpoint);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
describe('Credential Request Client with different issuers ', () => {
|
|
193
|
+
beforeEach(() => {
|
|
194
|
+
nock.cleanAll();
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
afterEach(() => {
|
|
198
|
+
nock.cleanAll();
|
|
199
|
+
});
|
|
200
|
+
it('should create correct CredentialRequest for Spruce', async () => {
|
|
201
|
+
const IRR_URI =
|
|
202
|
+
'openid-initiate-issuance://?issuer=https%3A%2F%2Fngi%2Doidc4vci%2Dtest%2Espruceid%2Exyz&credential_type=OpenBadgeCredential&pre-authorized_code=eyJhbGciOiJFUzI1NiJ9.eyJjcmVkZW50aWFsX3R5cGUiOlsiT3BlbkJhZGdlQ3JlZGVudGlhbCJdLCJleHAiOiIyMDIzLTA0LTIwVDA5OjA0OjM2WiIsIm5vbmNlIjoibWFibmVpT0VSZVB3V3BuRFFweEt3UnRsVVRFRlhGUEwifQ.qOZRPN8sTv_knhp7WaWte2-aDULaPZX--2i9unF6QDQNUllqDhvxgIHMDCYHCV8O2_Gj-T2x1J84fDMajE3asg&user_pin_required=false';
|
|
203
|
+
const credentialRequest = await (
|
|
204
|
+
await CredentialRequestClientBuilderV1_0_11.fromURI({
|
|
205
|
+
uri: IRR_URI,
|
|
206
|
+
metadata: getMockData('spruce')?.metadata as unknown as EndpointMetadata,
|
|
207
|
+
})
|
|
208
|
+
)
|
|
209
|
+
.build()
|
|
210
|
+
.createCredentialRequest({
|
|
211
|
+
proofInput: {
|
|
212
|
+
proof_type: 'jwt',
|
|
213
|
+
jwt: getMockData('spruce')?.credential.request.proof.jwt as string,
|
|
214
|
+
},
|
|
215
|
+
credentialTypes: ['OpenBadgeCredential'],
|
|
216
|
+
format: 'jwt_vc',
|
|
217
|
+
version: OpenId4VCIVersion.VER_1_0_08,
|
|
218
|
+
});
|
|
219
|
+
const draft8CredentialRequest = getCredentialRequestForVersion(credentialRequest, OpenId4VCIVersion.VER_1_0_08);
|
|
220
|
+
expect(draft8CredentialRequest).toEqual(getMockData('spruce')?.credential.request);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('should create correct CredentialRequest for Walt', async () => {
|
|
224
|
+
nock.cleanAll();
|
|
225
|
+
const IRR_URI =
|
|
226
|
+
'openid-initiate-issuance://?issuer=https%3A%2F%2Fjff.walt.id%2Fissuer-api%2Fdefault%2Foidc%2F&credential_type=OpenBadgeCredential&pre-authorized_code=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIwMTc4OTNjYy04ZTY3LTQxNzItYWZlOS1lODcyYmYxNDBlNWMiLCJwcmUtYXV0aG9yaXplZCI6dHJ1ZX0.ODfq2AIhOcB61dAb3zMrXBJjPJaf53zkeHh_AssYyYA&user_pin_required=false';
|
|
227
|
+
const credentialOffer = await (
|
|
228
|
+
await CredentialRequestClientBuilderV1_0_11.fromURI({
|
|
229
|
+
uri: IRR_URI,
|
|
230
|
+
metadata: getMockData('walt')?.metadata as unknown as EndpointMetadata,
|
|
231
|
+
})
|
|
232
|
+
)
|
|
233
|
+
.build()
|
|
234
|
+
.createCredentialRequest({
|
|
235
|
+
proofInput: {
|
|
236
|
+
proof_type: 'jwt',
|
|
237
|
+
jwt: getMockData('walt')?.credential.request.proof.jwt as string,
|
|
238
|
+
},
|
|
239
|
+
credentialTypes: ['OpenBadgeCredential'],
|
|
240
|
+
format: 'jwt_vc',
|
|
241
|
+
version: OpenId4VCIVersion.VER_1_0_08,
|
|
242
|
+
});
|
|
243
|
+
expect(credentialOffer).toEqual(getMockData('walt')?.credential.request);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
// Missing the issuer required property
|
|
247
|
+
xit('should create correct CredentialRequest for uniissuer', async () => {
|
|
248
|
+
const IRR_URI =
|
|
249
|
+
'https://oidc4vc.uniissuer.io/?credential_type=OpenBadgeCredential&pre-authorized_code=0ApoI8rxVmdQ44RIpuDbFIURIIkOhyek&user_pin_required=false';
|
|
250
|
+
const credentialOffer = await (
|
|
251
|
+
await CredentialRequestClientBuilderV1_0_11.fromURI({
|
|
252
|
+
uri: IRR_URI,
|
|
253
|
+
metadata: getMockData('uniissuer')?.metadata as unknown as EndpointMetadata,
|
|
254
|
+
})
|
|
255
|
+
)
|
|
256
|
+
.build()
|
|
257
|
+
.createCredentialRequest({
|
|
258
|
+
proofInput: {
|
|
259
|
+
proof_type: 'jwt',
|
|
260
|
+
jwt: getMockData('uniissuer')?.credential.request.proof.jwt as string,
|
|
261
|
+
},
|
|
262
|
+
credentialTypes: ['OpenBadgeCredential'],
|
|
263
|
+
format: 'jwt_vc',
|
|
264
|
+
version: OpenId4VCIVersion.VER_1_0_08,
|
|
265
|
+
});
|
|
266
|
+
expect(credentialOffer).toEqual(getMockData('uniissuer')?.credential.request);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it('should create correct CredentialRequest for mattr', async () => {
|
|
270
|
+
const IRR_URI =
|
|
271
|
+
'openid-initiate-issuance://?issuer=https://launchpad.mattrlabs.com&credential_type=OpenBadgeCredential&pre-authorized_code=g0UCOj6RAN5AwHU6gczm_GzB4_lH6GW39Z0Dl2DOOiO';
|
|
272
|
+
const credentialOffer = await (
|
|
273
|
+
await CredentialRequestClientBuilderV1_0_11.fromURI({
|
|
274
|
+
uri: IRR_URI,
|
|
275
|
+
metadata: getMockData('mattr')?.metadata as unknown as EndpointMetadata,
|
|
276
|
+
})
|
|
277
|
+
)
|
|
278
|
+
.build()
|
|
279
|
+
.createCredentialRequest({
|
|
280
|
+
proofInput: {
|
|
281
|
+
proof_type: 'jwt',
|
|
282
|
+
jwt: getMockData('mattr')?.credential.request.proof.jwt as string,
|
|
283
|
+
},
|
|
284
|
+
credentialTypes: ['OpenBadgeCredential'],
|
|
285
|
+
format: 'ldp_vc',
|
|
286
|
+
version: OpenId4VCIVersion.VER_1_0_08,
|
|
287
|
+
});
|
|
288
|
+
const credentialRequest = getCredentialRequestForVersion(credentialOffer, OpenId4VCIVersion.VER_1_0_08);
|
|
289
|
+
expect(credentialRequest).toEqual(getMockData('mattr')?.credential.request);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it('should create correct CredentialRequest for diwala', async () => {
|
|
293
|
+
const IRR_URI =
|
|
294
|
+
'openid-initiate-issuance://?issuer=https://oidc4vc.diwala.io&credential_type=OpenBadgeCredential&pre-authorized_code=eyJhbGciOiJIUzI1NiJ9.eyJjcmVkZW50aWFsX3R5cGUiOiJPcGVuQmFkZ2VDcmVkZW50aWFsIiwiZXhwIjoxNjgxOTg0NDY3fQ.fEAHKz2nuWfiYHw406iNxr-81pWkNkbi31bWsYSf6Ng';
|
|
295
|
+
const credentialOffer = await (
|
|
296
|
+
await CredentialRequestClientBuilderV1_0_11.fromURI({
|
|
297
|
+
uri: IRR_URI,
|
|
298
|
+
metadata: getMockData('diwala')?.metadata as unknown as EndpointMetadata,
|
|
299
|
+
})
|
|
300
|
+
)
|
|
301
|
+
.build()
|
|
302
|
+
.createCredentialRequest({
|
|
303
|
+
proofInput: {
|
|
304
|
+
proof_type: 'jwt',
|
|
305
|
+
jwt: getMockData('diwala')?.credential.request.proof.jwt as string,
|
|
306
|
+
},
|
|
307
|
+
credentialTypes: ['OpenBadgeCredential'],
|
|
308
|
+
format: 'ldp_vc',
|
|
309
|
+
version: OpenId4VCIVersion.VER_1_0_08,
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
// createCredentialRequest returns uniform format in draft 11
|
|
313
|
+
const credentialRequest = getCredentialRequestForVersion(credentialOffer, OpenId4VCIVersion.VER_1_0_08);
|
|
314
|
+
|
|
315
|
+
expect(credentialRequest).toEqual(getMockData('diwala')?.credential.request);
|
|
316
|
+
});
|
|
317
|
+
});
|
|
@@ -9,7 +9,7 @@ import debug from 'debug';
|
|
|
9
9
|
import { base64url, importJWK, JWK, SignJWT } from 'jose';
|
|
10
10
|
import * as u8a from 'uint8arrays';
|
|
11
11
|
|
|
12
|
-
import {
|
|
12
|
+
import { OpenID4VCIClientV1_0_11 } from '..';
|
|
13
13
|
|
|
14
14
|
export const UNIT_TEST_TIMEOUT = 30000;
|
|
15
15
|
|
|
@@ -58,7 +58,7 @@ describe.skip('OID4VCI-Client using Sphereon issuer should', () => {
|
|
|
58
58
|
async function test(credentialType: 'CTWalletCrossPreAuthorisedInTime' | 'CTWalletCrossPreAuthorisedDeferred' | 'CTWalletCrossAuthorisedInTime') {
|
|
59
59
|
debug.enable('*');
|
|
60
60
|
const offer = await getCredentialOffer(credentialType);
|
|
61
|
-
const client = await
|
|
61
|
+
const client = await OpenID4VCIClientV1_0_11.fromURI({
|
|
62
62
|
uri: offer,
|
|
63
63
|
kid,
|
|
64
64
|
alg: Alg.ES256,
|