@sphereon/ssi-sdk.siopv2-oid4vp-op-auth 0.32.1-next.54 → 0.33.1-feature.vcdm2.4
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/agent/DidAuthSiopOpAuthenticator.d.ts +6 -1
- package/dist/agent/DidAuthSiopOpAuthenticator.d.ts.map +1 -1
- package/dist/agent/DidAuthSiopOpAuthenticator.js +325 -277
- package/dist/agent/DidAuthSiopOpAuthenticator.js.map +1 -1
- package/dist/index.js +7 -27
- package/dist/index.js.map +1 -1
- package/dist/link-handler/index.js +35 -47
- package/dist/link-handler/index.js.map +1 -1
- package/dist/localization/Localization.js +38 -43
- package/dist/localization/Localization.js.map +1 -1
- package/dist/machine/CallbackStateListener.js +9 -22
- package/dist/machine/CallbackStateListener.js.map +1 -1
- package/dist/machine/Siopv2Machine.js +129 -131
- package/dist/machine/Siopv2Machine.js.map +1 -1
- package/dist/services/IdentifierService.js +11 -24
- package/dist/services/IdentifierService.js.map +1 -1
- package/dist/services/Siopv2MachineService.d.ts +4 -2
- package/dist/services/Siopv2MachineService.d.ts.map +1 -1
- package/dist/services/Siopv2MachineService.js +193 -98
- package/dist/services/Siopv2MachineService.js.map +1 -1
- package/dist/session/OID4VP.d.ts +4 -4
- package/dist/session/OID4VP.d.ts.map +1 -1
- package/dist/session/OID4VP.js +184 -194
- package/dist/session/OID4VP.js.map +1 -1
- package/dist/session/OpSession.d.ts.map +1 -1
- package/dist/session/OpSession.js +252 -288
- package/dist/session/OpSession.js.map +1 -1
- package/dist/session/functions.js +95 -111
- package/dist/session/functions.js.map +1 -1
- package/dist/session/index.js +3 -19
- package/dist/session/index.js.map +1 -1
- package/dist/types/IDidAuthSiopOpAuthenticator.d.ts +11 -7
- package/dist/types/IDidAuthSiopOpAuthenticator.d.ts.map +1 -1
- package/dist/types/IDidAuthSiopOpAuthenticator.js +4 -7
- package/dist/types/IDidAuthSiopOpAuthenticator.js.map +1 -1
- package/dist/types/error/index.js +1 -2
- package/dist/types/identifier/index.js +1 -4
- package/dist/types/identifier/index.js.map +1 -1
- package/dist/types/index.js +5 -21
- package/dist/types/index.js.map +1 -1
- package/dist/types/machine/index.js +10 -13
- package/dist/types/machine/index.js.map +1 -1
- package/dist/types/siop-service/index.d.ts +4 -2
- package/dist/types/siop-service/index.d.ts.map +1 -1
- package/dist/types/siop-service/index.js +4 -7
- package/dist/types/siop-service/index.js.map +1 -1
- package/dist/utils/CredentialUtils.d.ts +23 -0
- package/dist/utils/CredentialUtils.d.ts.map +1 -0
- package/dist/utils/CredentialUtils.js +55 -0
- package/dist/utils/CredentialUtils.js.map +1 -0
- package/dist/utils/dcql.d.ts +5 -0
- package/dist/utils/dcql.d.ts.map +1 -0
- package/dist/utils/dcql.js +34 -0
- package/dist/utils/dcql.js.map +1 -0
- package/package.json +26 -23
- package/src/agent/DidAuthSiopOpAuthenticator.ts +122 -42
- package/src/services/Siopv2MachineService.ts +130 -20
- package/src/session/OID4VP.ts +8 -8
- package/src/session/OpSession.ts +5 -4
- package/src/types/IDidAuthSiopOpAuthenticator.ts +20 -7
- package/src/types/siop-service/index.ts +9 -6
- package/src/utils/CredentialUtils.ts +71 -0
- package/src/utils/dcql.ts +36 -0
|
@@ -7,13 +7,14 @@ import { IIssuanceBranding } from '@sphereon/ssi-sdk.issuance-branding';
|
|
|
7
7
|
import { IAgentContext, IDIDManager, IIdentifier, IResolver } from '@veramo/core';
|
|
8
8
|
import { IDidAuthSiopOpAuthenticator } from '../IDidAuthSiopOpAuthenticator';
|
|
9
9
|
import { Siopv2MachineContext, Siopv2MachineInterpreter, Siopv2MachineState } from '../machine';
|
|
10
|
-
import {
|
|
10
|
+
import { DcqlQuery } from 'dcql';
|
|
11
|
+
import { HasherSync } from '@sphereon/ssi-types';
|
|
11
12
|
export type DidAuthSiopOpAuthenticatorOptions = {
|
|
12
13
|
presentationSignCallback?: PresentationSignCallback;
|
|
13
14
|
customApprovals?: Record<string, (verifiedAuthorizationRequest: VerifiedAuthorizationRequest, sessionId: string) => Promise<void>>;
|
|
14
15
|
onContactIdentityCreated?: (args: OnContactIdentityCreatedArgs) => Promise<void>;
|
|
15
16
|
onIdentifierCreated?: (args: OnIdentifierCreatedArgs) => Promise<void>;
|
|
16
|
-
hasher?:
|
|
17
|
+
hasher?: HasherSync;
|
|
17
18
|
};
|
|
18
19
|
export type GetMachineArgs = {
|
|
19
20
|
url: string | URL;
|
|
@@ -59,6 +60,7 @@ export type Siopv2AuthorizationRequestData = {
|
|
|
59
60
|
uri?: URL;
|
|
60
61
|
clientId?: string;
|
|
61
62
|
presentationDefinitions?: PresentationDefinitionWithLocation[];
|
|
63
|
+
dcqlQuery?: DcqlQuery;
|
|
62
64
|
};
|
|
63
65
|
export type SelectableCredentialsMap = Map<string, Array<SelectableCredential>>;
|
|
64
66
|
export type SelectableCredential = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/siop-service/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kCAAkC,EAClC,wBAAwB,EACxB,6BAA6B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/siop-service/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kCAAkC,EAClC,wBAAwB,EACxB,6BAA6B,EAC7B,4BAA4B,EAC7B,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,qBAAqB,EAAE,6BAA6B,EAAE,MAAM,6CAA6C,CAAA;AAClH,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAA;AAC9F,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAA;AACxG,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAA;AACvE,OAAO,EAAE,aAAa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uBAAuB,CAAC,EAAE,kCAAkC,EAAE,CAAA;IAC9D,SAAS,CAAC,EAAE,SAAS,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,oBAAoB,CAAC,CAAC,CAAA;AAE/E,MAAM,MAAM,oBAAoB,GAAG;IACjC,UAAU,EAAE,uBAAuB,CAAA;IACnC,kBAAkB,EAAE,KAAK,CAAC,yBAAyB,CAAC,CAAA;IACpD,WAAW,CAAC,EAAE,KAAK,CAAA;IACnB,YAAY,CAAC,EAAE,KAAK,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,4BAA4B,GAAG;IACzC,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,QAAQ,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC,UAAU,EAAE,WAAW,CAAA;CACxB,CAAA;AAED,MAAM,MAAM,eAAe,GAAG,aAAa,CACzC,eAAe,GAAG,2BAA2B,GAAG,WAAW,GAAG,SAAS,GAAG,qBAAqB,GAAG,gBAAgB,GAAG,iBAAiB,CACvI,CAAA"}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SupportedLanguage = exports.Siopv2HolderEvent = void 0;
|
|
4
|
-
var Siopv2HolderEvent;
|
|
1
|
+
export var Siopv2HolderEvent;
|
|
5
2
|
(function (Siopv2HolderEvent) {
|
|
6
3
|
Siopv2HolderEvent["CONTACT_IDENTITY_CREATED"] = "contact_identity_created";
|
|
7
4
|
Siopv2HolderEvent["IDENTIFIER_CREATED"] = "identifier_created";
|
|
8
|
-
})(Siopv2HolderEvent || (
|
|
9
|
-
var SupportedLanguage;
|
|
5
|
+
})(Siopv2HolderEvent || (Siopv2HolderEvent = {}));
|
|
6
|
+
export var SupportedLanguage;
|
|
10
7
|
(function (SupportedLanguage) {
|
|
11
8
|
SupportedLanguage["ENGLISH"] = "en";
|
|
12
9
|
SupportedLanguage["DUTCH"] = "nl";
|
|
13
|
-
})(SupportedLanguage || (
|
|
10
|
+
})(SupportedLanguage || (SupportedLanguage = {}));
|
|
14
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/siop-service/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/siop-service/index.ts"],"names":[],"mappings":"AAgDA,MAAM,CAAN,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC3B,0EAAqD,CAAA;IACrD,8DAAyC,CAAA;AAC3C,CAAC,EAHW,iBAAiB,KAAjB,iBAAiB,QAG5B;AAED,MAAM,CAAN,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC3B,mCAAc,CAAA;IACd,iCAAY,CAAA;AACd,CAAC,EAHW,iBAAiB,KAAjB,iBAAiB,QAG5B"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ICredential, OriginalVerifiableCredential } from '@sphereon/ssi-types';
|
|
2
|
+
import { VerifiableCredential } from '@veramo/core';
|
|
3
|
+
import { UniqueDigitalCredential } from '@sphereon/ssi-sdk.credential-store';
|
|
4
|
+
/**
|
|
5
|
+
* Return the type(s) of a VC minus the VerifiableCredential type which should always be present
|
|
6
|
+
* @param credential The input credential
|
|
7
|
+
*/
|
|
8
|
+
export declare const getCredentialTypeAsString: (credential: ICredential | VerifiableCredential) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Returns a Unique Verifiable Credential (with hash) as stored in Veramo, based upon matching the id of the input VC or the proof value of the input VC
|
|
11
|
+
* @param uniqueVCs The Unique VCs to search in
|
|
12
|
+
* @param searchVC The VC to search for in the unique VCs array
|
|
13
|
+
*/
|
|
14
|
+
export declare const getMatchingUniqueDigitalCredential: (uniqueVCs: UniqueDigitalCredential[], searchVC: OriginalVerifiableCredential) => UniqueDigitalCredential | undefined;
|
|
15
|
+
type InputCredential = UniqueDigitalCredential | VerifiableCredential | ICredential | OriginalVerifiableCredential;
|
|
16
|
+
/**
|
|
17
|
+
* Get an original verifiable credential. Maps to wrapped Verifiable Credential first, to get an original JWT as Veramo stores these with a special proof value
|
|
18
|
+
* @param credential The input VC
|
|
19
|
+
*/
|
|
20
|
+
export declare const getOriginalVerifiableCredential: (credential: InputCredential) => OriginalVerifiableCredential;
|
|
21
|
+
export declare const isUniqueDigitalCredential: (credential: InputCredential) => credential is UniqueDigitalCredential;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=CredentialUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CredentialUtils.d.ts","sourceRoot":"","sources":["../../src/utils/CredentialUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,WAAW,EAAyB,4BAA4B,EAAE,MAAM,qBAAqB,CAAA;AACpI,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAA;AAE5E;;;GAGG;AACH,eAAO,MAAM,yBAAyB,eAAgB,WAAW,GAAG,oBAAoB,KAAG,MAO1F,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,kCAAkC,cAClC,uBAAuB,EAAE,YAC1B,4BAA4B,KACrC,uBAAuB,GAAG,SAe5B,CAAA;AAED,KAAK,eAAe,GAAG,uBAAuB,GAAG,oBAAoB,GAAG,WAAW,GAAG,4BAA4B,CAAA;AAElH;;;GAGG;AAEH,eAAO,MAAM,+BAA+B,eAAgB,eAAe,KAAG,4BAS7E,CAAA;AAUD,eAAO,MAAM,yBAAyB,eAAgB,eAAe,KAAG,UAAU,IAAI,uBAErF,CAAA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { CredentialMapper } from '@sphereon/ssi-types';
|
|
2
|
+
/**
|
|
3
|
+
* Return the type(s) of a VC minus the VerifiableCredential type which should always be present
|
|
4
|
+
* @param credential The input credential
|
|
5
|
+
*/
|
|
6
|
+
export const getCredentialTypeAsString = (credential) => {
|
|
7
|
+
if (!credential.type) {
|
|
8
|
+
return 'Verifiable Credential';
|
|
9
|
+
}
|
|
10
|
+
else if (typeof credential.type === 'string') {
|
|
11
|
+
return credential.type;
|
|
12
|
+
}
|
|
13
|
+
return credential.type.filter((type) => type !== 'VerifiableCredential').join(', ');
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Returns a Unique Verifiable Credential (with hash) as stored in Veramo, based upon matching the id of the input VC or the proof value of the input VC
|
|
17
|
+
* @param uniqueVCs The Unique VCs to search in
|
|
18
|
+
* @param searchVC The VC to search for in the unique VCs array
|
|
19
|
+
*/
|
|
20
|
+
export const getMatchingUniqueDigitalCredential = (uniqueVCs, searchVC) => {
|
|
21
|
+
// Since an ID is optional in a VC according to VCDM, and we really need the matches, we have a fallback match on something which is guaranteed to be unique for any VC (the proof(s))
|
|
22
|
+
return uniqueVCs.find((uniqueVC) => (typeof searchVC !== 'string' &&
|
|
23
|
+
(uniqueVC.id === searchVC.id ||
|
|
24
|
+
uniqueVC.originalVerifiableCredential.proof === searchVC.proof)) ||
|
|
25
|
+
(typeof searchVC === 'string' && uniqueVC.uniformVerifiableCredential?.proof?.jwt === searchVC) ||
|
|
26
|
+
// We are ignoring the signature of the sd-jwt as PEX signs the vc again and it will not match anymore with the jwt in the proof of the stored jsonld vc
|
|
27
|
+
(typeof searchVC === 'string' &&
|
|
28
|
+
CredentialMapper.isSdJwtEncoded(searchVC) &&
|
|
29
|
+
uniqueVC.uniformVerifiableCredential?.proof &&
|
|
30
|
+
'jwt' in uniqueVC.uniformVerifiableCredential.proof &&
|
|
31
|
+
uniqueVC.uniformVerifiableCredential.proof.jwt?.split('.')?.slice(0, 2)?.join('.') === searchVC.split('.')?.slice(0, 2)?.join('.')));
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Get an original verifiable credential. Maps to wrapped Verifiable Credential first, to get an original JWT as Veramo stores these with a special proof value
|
|
35
|
+
* @param credential The input VC
|
|
36
|
+
*/
|
|
37
|
+
export const getOriginalVerifiableCredential = (credential) => {
|
|
38
|
+
if (isUniqueDigitalCredential(credential)) {
|
|
39
|
+
if (!credential.originalVerifiableCredential) {
|
|
40
|
+
throw new Error('originalVerifiableCredential is not defined in UniqueDigitalCredential');
|
|
41
|
+
}
|
|
42
|
+
return getCredentialFromProofOrWrapped(credential.originalVerifiableCredential);
|
|
43
|
+
}
|
|
44
|
+
return getCredentialFromProofOrWrapped(credential);
|
|
45
|
+
};
|
|
46
|
+
const getCredentialFromProofOrWrapped = (cred, hasher) => {
|
|
47
|
+
if (typeof cred === 'object' && 'proof' in cred && 'jwt' in cred.proof && CredentialMapper.isSdJwtEncoded(cred.proof.jwt)) {
|
|
48
|
+
return cred.proof.jwt;
|
|
49
|
+
}
|
|
50
|
+
return CredentialMapper.toWrappedVerifiableCredential(cred, { hasher }).original;
|
|
51
|
+
};
|
|
52
|
+
export const isUniqueDigitalCredential = (credential) => {
|
|
53
|
+
return credential.digitalCredential !== undefined;
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=CredentialUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CredentialUtils.js","sourceRoot":"","sources":["../../src/utils/CredentialUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAgF,MAAM,qBAAqB,CAAA;AAIpI;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,UAA8C,EAAU,EAAE;IAClG,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QACrB,OAAO,uBAAuB,CAAA;IAChC,CAAC;SAAM,IAAI,OAAO,UAAU,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC/C,OAAO,UAAU,CAAC,IAAI,CAAA;IACxB,CAAC;IACD,OAAO,UAAU,CAAC,IAAI,CAAC,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BAA4B,EAAE,CAAC;YAC7C,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAA;QAC3F,CAAC;QACD,OAAO,+BAA+B,CAAC,UAAU,CAAC,4BAA4B,CAAC,CAAA;IACjF,CAAC;IAED,OAAO,+BAA+B,CAAC,UAAU,CAAC,CAAA;AACpD,CAAC,CAAA;AAED,MAAM,+BAA+B,GAAG,CAAC,IAAS,EAAE,MAAmB,EAAgC,EAAE;IACvG,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,IAAI,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI,gBAAgB,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1H,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAA;IACvB,CAAC;IAED,OAAO,gBAAgB,CAAC,6BAA6B,CAAC,IAAoC,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAA;AAClH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,UAA2B,EAAyC,EAAE;IAC9G,OAAQ,UAAsC,CAAC,iBAAiB,KAAK,SAAS,CAAA;AAChF,CAAC,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { UniqueDigitalCredential } from '@sphereon/ssi-sdk.credential-store';
|
|
2
|
+
import { DcqlCredential } from 'dcql';
|
|
3
|
+
import { HasherSync, OriginalVerifiableCredential } from '@sphereon/ssi-types';
|
|
4
|
+
export declare function convertToDcqlCredentials(credential: UniqueDigitalCredential | OriginalVerifiableCredential, hasher?: HasherSync): DcqlCredential;
|
|
5
|
+
//# sourceMappingURL=dcql.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dcql.d.ts","sourceRoot":"","sources":["../../src/utils/dcql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAA;AAC5E,OAAO,EAAE,cAAc,EAA8C,MAAM,MAAM,CAAA;AACjF,OAAO,EAAoB,UAAU,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAA;AAGhG,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,uBAAuB,GAAG,4BAA4B,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,cAAc,CA8BhJ"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CredentialMapper } from '@sphereon/ssi-types';
|
|
2
|
+
import { isUniqueDigitalCredential } from './CredentialUtils';
|
|
3
|
+
export function convertToDcqlCredentials(credential, hasher) {
|
|
4
|
+
let payload;
|
|
5
|
+
if (isUniqueDigitalCredential(credential)) {
|
|
6
|
+
if (!credential.originalVerifiableCredential) {
|
|
7
|
+
throw new Error('originalVerifiableCredential is not defined in UniqueDigitalCredential');
|
|
8
|
+
}
|
|
9
|
+
payload = CredentialMapper.decodeVerifiableCredential(credential.originalVerifiableCredential, hasher);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
payload = CredentialMapper.decodeVerifiableCredential(credential, hasher);
|
|
13
|
+
}
|
|
14
|
+
if (!payload) {
|
|
15
|
+
throw new Error('No payload found');
|
|
16
|
+
}
|
|
17
|
+
if ('decodedPayload' in payload && payload.decodedPayload) {
|
|
18
|
+
payload = payload.decodedPayload;
|
|
19
|
+
}
|
|
20
|
+
if ('vct' in payload) {
|
|
21
|
+
return { vct: payload.vct, claims: payload, credential_format: 'vc+sd-jwt' }; // TODO dc+sd-jwt support?
|
|
22
|
+
}
|
|
23
|
+
else if ('docType' in payload && 'namespaces' in payload) {
|
|
24
|
+
// mdoc
|
|
25
|
+
return { docType: payload.docType, namespaces: payload.namespaces, claims: payload };
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return {
|
|
29
|
+
claims: payload,
|
|
30
|
+
credential_format: 'jwt_vc_json', // TODO jwt_vc_json-ld support
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}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U,EAAE,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,CAAA;IACtF,CAAC;SAAM,CAAC;QACN,OAAO;YACL,MAAM,EAAE,OAAO;YACf,iBAAiB,EAAE,aAAa,EAAE,8BAA8B;SAC1C,CAAA;IAC1B,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.siopv2-oid4vp-op-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.1-feature.vcdm2.4+9f634bdb",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,30 +14,31 @@
|
|
|
14
14
|
"build:clean": "tsc --build --clean && tsc --build"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@sphereon/did-auth-siop": "0.
|
|
18
|
-
"@sphereon/did-auth-siop-adapter": "0.
|
|
19
|
-
"@sphereon/oid4vc-common": "0.
|
|
17
|
+
"@sphereon/did-auth-siop": "0.17.0",
|
|
18
|
+
"@sphereon/did-auth-siop-adapter": "0.17.0",
|
|
19
|
+
"@sphereon/oid4vc-common": "0.17.0",
|
|
20
20
|
"@sphereon/pex": "5.0.0-unstable.28",
|
|
21
21
|
"@sphereon/pex-models": "^2.3.2",
|
|
22
|
-
"@sphereon/ssi-sdk-ext.did-utils": "0.
|
|
23
|
-
"@sphereon/ssi-sdk-ext.identifier-resolution": "0.
|
|
24
|
-
"@sphereon/ssi-sdk-ext.jwt-service": "0.
|
|
25
|
-
"@sphereon/ssi-sdk.contact-manager": "0.
|
|
26
|
-
"@sphereon/ssi-sdk.core": "0.
|
|
27
|
-
"@sphereon/ssi-sdk.credential-store": "0.
|
|
28
|
-
"@sphereon/ssi-sdk.credential-validation": "0.
|
|
29
|
-
"@sphereon/ssi-sdk.data-store": "0.
|
|
30
|
-
"@sphereon/ssi-sdk.issuance-branding": "0.
|
|
31
|
-
"@sphereon/ssi-sdk.pd-manager": "0.
|
|
32
|
-
"@sphereon/ssi-sdk.presentation-exchange": "0.
|
|
33
|
-
"@sphereon/ssi-sdk.sd-jwt": "0.
|
|
34
|
-
"@sphereon/ssi-sdk.siopv2-oid4vp-common": "0.
|
|
35
|
-
"@sphereon/ssi-sdk.xstate-machine-persistence": "0.
|
|
36
|
-
"@sphereon/ssi-types": "0.
|
|
22
|
+
"@sphereon/ssi-sdk-ext.did-utils": "0.28.0",
|
|
23
|
+
"@sphereon/ssi-sdk-ext.identifier-resolution": "0.28.0",
|
|
24
|
+
"@sphereon/ssi-sdk-ext.jwt-service": "0.28.0",
|
|
25
|
+
"@sphereon/ssi-sdk.contact-manager": "0.33.1-feature.vcdm2.4+9f634bdb",
|
|
26
|
+
"@sphereon/ssi-sdk.core": "0.33.1-feature.vcdm2.4+9f634bdb",
|
|
27
|
+
"@sphereon/ssi-sdk.credential-store": "0.33.1-feature.vcdm2.4+9f634bdb",
|
|
28
|
+
"@sphereon/ssi-sdk.credential-validation": "0.33.1-feature.vcdm2.4+9f634bdb",
|
|
29
|
+
"@sphereon/ssi-sdk.data-store": "0.33.1-feature.vcdm2.4+9f634bdb",
|
|
30
|
+
"@sphereon/ssi-sdk.issuance-branding": "0.33.1-feature.vcdm2.4+9f634bdb",
|
|
31
|
+
"@sphereon/ssi-sdk.pd-manager": "0.33.1-feature.vcdm2.4+9f634bdb",
|
|
32
|
+
"@sphereon/ssi-sdk.presentation-exchange": "0.33.1-feature.vcdm2.4+9f634bdb",
|
|
33
|
+
"@sphereon/ssi-sdk.sd-jwt": "0.33.1-feature.vcdm2.4+9f634bdb",
|
|
34
|
+
"@sphereon/ssi-sdk.siopv2-oid4vp-common": "0.33.1-feature.vcdm2.4+9f634bdb",
|
|
35
|
+
"@sphereon/ssi-sdk.xstate-machine-persistence": "0.33.1-feature.vcdm2.4+9f634bdb",
|
|
36
|
+
"@sphereon/ssi-types": "0.33.1-feature.vcdm2.4+9f634bdb",
|
|
37
37
|
"@sphereon/wellknown-dids-client": "^0.1.3",
|
|
38
38
|
"@veramo/core": "4.2.0",
|
|
39
39
|
"@veramo/credential-w3c": "4.2.0",
|
|
40
40
|
"cross-fetch": "^3.1.8",
|
|
41
|
+
"dcql": "0.2.19",
|
|
41
42
|
"did-jwt-vc": "3.1.3",
|
|
42
43
|
"i18n-js": "^3.9.2",
|
|
43
44
|
"lodash.memoize": "^4.1.2",
|
|
@@ -46,19 +47,21 @@
|
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
49
|
"@sphereon/did-uni-client": "^0.6.3",
|
|
49
|
-
"@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.
|
|
50
|
-
"@sphereon/ssi-sdk.agent-config": "0.
|
|
50
|
+
"@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.28.0",
|
|
51
|
+
"@sphereon/ssi-sdk.agent-config": "0.33.1-feature.vcdm2.4+9f634bdb",
|
|
51
52
|
"@types/i18n-js": "^3.8.9",
|
|
52
53
|
"@types/lodash.memoize": "^4.1.9",
|
|
53
54
|
"@types/sha.js": "^2.4.4",
|
|
54
55
|
"@types/uuid": "^9.0.8",
|
|
56
|
+
"@veramo/data-store": "4.2.0",
|
|
55
57
|
"@veramo/did-provider-key": "4.2.0",
|
|
56
58
|
"@veramo/did-resolver": "4.2.0",
|
|
57
59
|
"@veramo/remote-client": "4.2.0",
|
|
58
60
|
"@veramo/remote-server": "4.2.0",
|
|
59
61
|
"@veramo/utils": "4.2.0",
|
|
60
62
|
"did-resolver": "^4.1.0",
|
|
61
|
-
"nock": "^13.5.4"
|
|
63
|
+
"nock": "^13.5.4",
|
|
64
|
+
"typeorm": "^0.3.21"
|
|
62
65
|
},
|
|
63
66
|
"files": [
|
|
64
67
|
"dist/**/*",
|
|
@@ -88,5 +91,5 @@
|
|
|
88
91
|
"Authenticator"
|
|
89
92
|
],
|
|
90
93
|
"nx": {},
|
|
91
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "9f634bdb714061141e277508c124b08d626f6036"
|
|
92
95
|
}
|
|
@@ -2,19 +2,22 @@ import { decodeUriAsJson, PresentationSignCallback, SupportedVersion, VerifiedAu
|
|
|
2
2
|
import {
|
|
3
3
|
ConnectionType,
|
|
4
4
|
CorrelationIdentifierType,
|
|
5
|
+
CredentialDocumentFormat,
|
|
5
6
|
CredentialRole,
|
|
7
|
+
DocumentType,
|
|
6
8
|
Identity,
|
|
7
9
|
IdentityOrigin,
|
|
8
10
|
NonPersistedIdentity,
|
|
9
11
|
Party,
|
|
10
12
|
} from '@sphereon/ssi-sdk.data-store'
|
|
11
|
-
import {
|
|
13
|
+
import { HasherSync, Loggers, SdJwtDecodedVerifiableCredential } from '@sphereon/ssi-types'
|
|
12
14
|
import { IAgentPlugin } from '@veramo/core'
|
|
13
15
|
import { v4 as uuidv4 } from 'uuid'
|
|
14
16
|
import {
|
|
15
17
|
DidAuthSiopOpAuthenticatorOptions,
|
|
16
18
|
GetSelectableCredentialsArgs,
|
|
17
19
|
IOpSessionArgs,
|
|
20
|
+
Json,
|
|
18
21
|
LOGGER_NAMESPACE,
|
|
19
22
|
RequiredContext,
|
|
20
23
|
schema,
|
|
@@ -30,16 +33,19 @@ import { computeEntryHash } from '@veramo/utils'
|
|
|
30
33
|
import { UniqueDigitalCredential } from '@sphereon/ssi-sdk.credential-store'
|
|
31
34
|
import { EventEmitter } from 'events'
|
|
32
35
|
import {
|
|
33
|
-
AddIdentityArgs,
|
|
34
|
-
CreateConfigArgs,
|
|
35
|
-
CreateConfigResult,
|
|
36
|
-
GetSiopRequestArgs,
|
|
37
36
|
IDidAuthSiopOpAuthenticator,
|
|
38
37
|
IGetSiopSessionArgs,
|
|
39
38
|
IRegisterCustomApprovalForSiopArgs,
|
|
40
39
|
IRemoveCustomApprovalForSiopArgs,
|
|
41
40
|
IRemoveSiopSessionArgs,
|
|
42
41
|
IRequiredContext,
|
|
42
|
+
} from '../types'
|
|
43
|
+
|
|
44
|
+
import {
|
|
45
|
+
AddIdentityArgs,
|
|
46
|
+
CreateConfigArgs,
|
|
47
|
+
CreateConfigResult,
|
|
48
|
+
GetSiopRequestArgs,
|
|
43
49
|
OnContactIdentityCreatedArgs,
|
|
44
50
|
OnIdentifierCreatedArgs,
|
|
45
51
|
RetrieveContactArgs,
|
|
@@ -47,8 +53,9 @@ import {
|
|
|
47
53
|
Siopv2AuthorizationRequestData,
|
|
48
54
|
Siopv2HolderEvent,
|
|
49
55
|
Siopv2Machine as Siopv2MachineId,
|
|
50
|
-
Siopv2MachineInstanceOpts
|
|
56
|
+
Siopv2MachineInstanceOpts,
|
|
51
57
|
} from '../types'
|
|
58
|
+
import { DcqlCredential, DcqlPresentation, DcqlQuery, DcqlSdJwtVcCredential } from 'dcql'
|
|
52
59
|
|
|
53
60
|
const logger = Loggers.DEFAULT.options(LOGGER_NAMESPACE, {}).get(LOGGER_NAMESPACE)
|
|
54
61
|
|
|
@@ -84,22 +91,16 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
|
|
|
84
91
|
siopGetSelectableCredentials: this.siopGetSelectableCredentials.bind(this),
|
|
85
92
|
}
|
|
86
93
|
|
|
87
|
-
private readonly hasher?: Hasher
|
|
88
94
|
private readonly sessions: Map<string, OpSession>
|
|
89
95
|
private readonly customApprovals: Record<string, (verifiedAuthorizationRequest: VerifiedAuthorizationRequest, sessionId: string) => Promise<void>>
|
|
90
96
|
private readonly presentationSignCallback?: PresentationSignCallback
|
|
91
97
|
private readonly onContactIdentityCreated?: (args: OnContactIdentityCreatedArgs) => Promise<void>
|
|
92
98
|
private readonly onIdentifierCreated?: (args: OnIdentifierCreatedArgs) => Promise<void>
|
|
93
99
|
private readonly eventEmitter?: EventEmitter
|
|
100
|
+
private readonly hasher?: HasherSync
|
|
94
101
|
|
|
95
102
|
constructor(options?: DidAuthSiopOpAuthenticatorOptions) {
|
|
96
|
-
const {
|
|
97
|
-
onContactIdentityCreated,
|
|
98
|
-
onIdentifierCreated,
|
|
99
|
-
hasher,
|
|
100
|
-
customApprovals = {},
|
|
101
|
-
presentationSignCallback
|
|
102
|
-
} = { ...options }
|
|
103
|
+
const { onContactIdentityCreated, onIdentifierCreated, hasher, customApprovals = {}, presentationSignCallback } = { ...options }
|
|
103
104
|
|
|
104
105
|
this.hasher = hasher
|
|
105
106
|
this.onContactIdentityCreated = onContactIdentityCreated
|
|
@@ -214,9 +215,14 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
|
|
|
214
215
|
}
|
|
215
216
|
const { sessionId, redirectUrl } = didAuthConfig
|
|
216
217
|
|
|
217
|
-
const session: OpSession = await agent
|
|
218
|
-
|
|
219
|
-
|
|
218
|
+
const session: OpSession = await agent.siopGetOPSession({ sessionId }).catch(
|
|
219
|
+
async () =>
|
|
220
|
+
await agent.siopRegisterOPSession({
|
|
221
|
+
requestJwtOrUri: redirectUrl,
|
|
222
|
+
sessionId,
|
|
223
|
+
op: { eventEmitter: this.eventEmitter, hasher: this.hasher },
|
|
224
|
+
}),
|
|
225
|
+
)
|
|
220
226
|
|
|
221
227
|
logger.debug(`session: ${JSON.stringify(session.id, null, 2)}`)
|
|
222
228
|
const verifiedAuthorizationRequest = await session.getAuthorizationRequest()
|
|
@@ -245,6 +251,7 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
|
|
|
245
251
|
verifiedAuthorizationRequest.presentationDefinitions.length > 0)
|
|
246
252
|
? verifiedAuthorizationRequest.presentationDefinitions
|
|
247
253
|
: undefined,
|
|
254
|
+
dcqlQuery: verifiedAuthorizationRequest.dcqlQuery,
|
|
248
255
|
}
|
|
249
256
|
}
|
|
250
257
|
|
|
@@ -345,32 +352,75 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
|
|
|
345
352
|
|
|
346
353
|
const pex = new PEX({ hasher: this.hasher })
|
|
347
354
|
const verifiableCredentialsWithDefinition: Array<VerifiableCredentialsWithDefinition> = []
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
355
|
+
const dcqlCredentialsWithCredentials: Map<DcqlCredential, UniqueDigitalCredential> = new Map()
|
|
356
|
+
|
|
357
|
+
if (Array.isArray(authorizationRequestData.presentationDefinitions) && authorizationRequestData?.presentationDefinitions.length > 0) {
|
|
358
|
+
try {
|
|
359
|
+
authorizationRequestData.presentationDefinitions?.forEach((presentationDefinition) => {
|
|
360
|
+
const { areRequiredCredentialsPresent, verifiableCredential: verifiableCredentials } = pex.selectFrom(
|
|
361
|
+
presentationDefinition.definition,
|
|
362
|
+
selectedCredentials.map((udc) => udc.originalVerifiableCredential!),
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
if (areRequiredCredentialsPresent !== Status.ERROR && verifiableCredentials) {
|
|
366
|
+
let uniqueDigitalCredentials: UniqueDigitalCredential[] = []
|
|
367
|
+
uniqueDigitalCredentials = verifiableCredentials.map((vc) => {
|
|
368
|
+
// @ts-ignore FIXME Funke
|
|
369
|
+
const hash = typeof vc === 'string' ? computeEntryHash(vc.split('~'[0])) : computeEntryHash(vc)
|
|
370
|
+
const udc = selectedCredentials.find((udc) => udc.hash == hash || udc.originalVerifiableCredential == vc)
|
|
371
|
+
|
|
372
|
+
if (!udc) {
|
|
373
|
+
throw Error(
|
|
374
|
+
`UniqueDigitalCredential could not be found in store. Either the credential is not present in the store or the hash is not correct.`,
|
|
375
|
+
)
|
|
376
|
+
}
|
|
377
|
+
return udc
|
|
378
|
+
})
|
|
379
|
+
verifiableCredentialsWithDefinition.push({
|
|
380
|
+
definition: presentationDefinition,
|
|
381
|
+
credentials: uniqueDigitalCredentials,
|
|
382
|
+
})
|
|
362
383
|
}
|
|
363
|
-
return udc
|
|
364
|
-
})
|
|
365
|
-
verifiableCredentialsWithDefinition.push({
|
|
366
|
-
definition: presentationDefinition,
|
|
367
|
-
credentials: uniqueDigitalCredentials,
|
|
368
384
|
})
|
|
385
|
+
} catch (e) {
|
|
386
|
+
return Promise.reject(e)
|
|
369
387
|
}
|
|
370
|
-
})
|
|
371
388
|
|
|
372
|
-
|
|
373
|
-
|
|
389
|
+
if (verifiableCredentialsWithDefinition.length === 0) {
|
|
390
|
+
return Promise.reject(Error('None of the selected credentials match any of the presentation definitions.'))
|
|
391
|
+
}
|
|
392
|
+
} else if (authorizationRequestData.dcqlQuery) {
|
|
393
|
+
//TODO Only SD-JWT and MSO MDOC are supported at the moment
|
|
394
|
+
if (this.hasMDocCredentials(selectedCredentials) || this.hasSdJwtCredentials(selectedCredentials)) {
|
|
395
|
+
try {
|
|
396
|
+
selectedCredentials.forEach((vc) => {
|
|
397
|
+
if (this.isSdJwtCredential(vc)) {
|
|
398
|
+
const payload = (vc.originalVerifiableCredential as SdJwtDecodedVerifiableCredential).decodedPayload
|
|
399
|
+
const result: DcqlSdJwtVcCredential = {
|
|
400
|
+
claims: payload as { [x: string]: Json },
|
|
401
|
+
vct: payload.vct,
|
|
402
|
+
credential_format: 'vc+sd-jwt',
|
|
403
|
+
}
|
|
404
|
+
dcqlCredentialsWithCredentials.set(result, vc)
|
|
405
|
+
//FIXME MDoc namespaces are incompatible: array of strings vs complex object - https://sphereon.atlassian.net/browse/SPRIND-143
|
|
406
|
+
} else {
|
|
407
|
+
throw Error(`Invalid credential format: ${vc.digitalCredential.documentFormat}`)
|
|
408
|
+
}
|
|
409
|
+
})
|
|
410
|
+
} catch (e) {
|
|
411
|
+
return Promise.reject(e)
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const dcqlPresentationRecord: DcqlPresentation.Output = {}
|
|
415
|
+
const queryResult = DcqlQuery.query(authorizationRequestData.dcqlQuery, Array.from(dcqlCredentialsWithCredentials.keys()))
|
|
416
|
+
for (const [key, value] of Object.entries(queryResult.credential_matches)) {
|
|
417
|
+
if (value.success) {
|
|
418
|
+
dcqlPresentationRecord[key] = this.retrieveEncodedCredential(dcqlCredentialsWithCredentials.get(value.output)!) as
|
|
419
|
+
| string
|
|
420
|
+
| { [x: string]: Json }
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
374
424
|
}
|
|
375
425
|
|
|
376
426
|
const response = await siopSendAuthorizationResponse(
|
|
@@ -380,7 +430,7 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
|
|
|
380
430
|
...(args.idOpts && { idOpts: args.idOpts }),
|
|
381
431
|
...(authorizationRequestData.presentationDefinitions !== undefined && { verifiableCredentialsWithDefinition }),
|
|
382
432
|
isFirstParty,
|
|
383
|
-
hasher: this.hasher
|
|
433
|
+
hasher: this.hasher,
|
|
384
434
|
},
|
|
385
435
|
context,
|
|
386
436
|
)
|
|
@@ -395,11 +445,41 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
|
|
|
395
445
|
|
|
396
446
|
return {
|
|
397
447
|
body: responseBody,
|
|
398
|
-
url: response
|
|
399
|
-
queryParams: decodeUriAsJson(response
|
|
448
|
+
url: response?.url,
|
|
449
|
+
queryParams: decodeUriAsJson(response?.url),
|
|
400
450
|
}
|
|
401
451
|
}
|
|
402
452
|
|
|
453
|
+
private hasMDocCredentials = (credentials: UniqueDigitalCredential[]): boolean => {
|
|
454
|
+
return credentials.some(this.isMDocCredential)
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
private isMDocCredential = (credential: UniqueDigitalCredential) => {
|
|
458
|
+
return (
|
|
459
|
+
credential.digitalCredential.documentFormat === CredentialDocumentFormat.MSO_MDOC &&
|
|
460
|
+
credential.digitalCredential.documentType === DocumentType.VC
|
|
461
|
+
)
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
private hasSdJwtCredentials = (credentials: UniqueDigitalCredential[]): boolean => {
|
|
465
|
+
return credentials.some(this.isSdJwtCredential)
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
private isSdJwtCredential = (credential: UniqueDigitalCredential) => {
|
|
469
|
+
return (
|
|
470
|
+
credential.digitalCredential.documentFormat === CredentialDocumentFormat.SD_JWT && credential.digitalCredential.documentType === DocumentType.VC
|
|
471
|
+
)
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
private retrieveEncodedCredential = (credential: UniqueDigitalCredential) => {
|
|
475
|
+
return credential.originalVerifiableCredential !== undefined &&
|
|
476
|
+
credential.originalVerifiableCredential !== null &&
|
|
477
|
+
(credential?.originalVerifiableCredential as SdJwtDecodedVerifiableCredential)?.compactSdJwtVc !== undefined &&
|
|
478
|
+
(credential?.originalVerifiableCredential as SdJwtDecodedVerifiableCredential)?.compactSdJwtVc !== null
|
|
479
|
+
? (credential.originalVerifiableCredential as SdJwtDecodedVerifiableCredential).compactSdJwtVc
|
|
480
|
+
: credential.originalVerifiableCredential
|
|
481
|
+
}
|
|
482
|
+
|
|
403
483
|
private async siopGetSelectableCredentials(args: GetSelectableCredentialsArgs, context: RequiredContext): Promise<SelectableCredentialsMap> {
|
|
404
484
|
const { authorizationRequestData } = args
|
|
405
485
|
|