@sphereon/ssi-sdk.presentation-exchange 0.26.0 → 0.26.1-next.108
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/functions.d.ts +1 -0
- package/dist/functions.d.ts.map +1 -1
- package/dist/functions.js +29 -14
- package/dist/functions.js.map +1 -1
- package/package.json +6 -6
- package/src/functions.ts +33 -13
package/dist/functions.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { Format } from '@sphereon/pex-models';
|
|
|
5
5
|
export declare function createPEXPresentationSignCallback(args: {
|
|
6
6
|
idOpts: IIdentifierOpts;
|
|
7
7
|
fetchRemoteContexts?: boolean;
|
|
8
|
+
skipDidResolution?: boolean;
|
|
8
9
|
format?: Format | ProofFormat;
|
|
9
10
|
domain?: string;
|
|
10
11
|
challenge?: string;
|
package/dist/functions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6E,eAAe,EAAE,MAAM,iCAAiC,CAAA;
|
|
1
|
+
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6E,eAAe,EAAE,MAAM,iCAAiC,CAAA;AAE5I,OAAO,EAAE,4BAA4B,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAE9F,OAAO,EAA6B,WAAW,EAAE,MAAM,cAAc,CAAA;AAErE,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAE7C,wBAAsB,iCAAiC,CACrD,IAAI,EAAE;IACJ,MAAM,EAAE,eAAe,CAAA;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,MAAM,CAAC,EAAE,MAAM,GAAG,WAAW,CAAA;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,EACD,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,4BAA4B,CAAC,CA4IvC"}
|
package/dist/functions.js
CHANGED
|
@@ -32,7 +32,7 @@ function createPEXPresentationSignCallback(args, context) {
|
|
|
32
32
|
return proofFormat;
|
|
33
33
|
}
|
|
34
34
|
return (_a) => __awaiter(this, [_a], void 0, function* ({ presentation, domain, presentationDefinition, format, challenge, }) {
|
|
35
|
-
var _b, _c, _d;
|
|
35
|
+
var _b, _c, _d, _e, _f, _g;
|
|
36
36
|
const idOpts = args.idOpts;
|
|
37
37
|
const id = yield (0, ssi_sdk_ext_did_utils_1.getIdentifier)(idOpts, context);
|
|
38
38
|
if (typeof idOpts.identifier === 'string') {
|
|
@@ -41,24 +41,42 @@ function createPEXPresentationSignCallback(args, context) {
|
|
|
41
41
|
if (!presentation.holder) {
|
|
42
42
|
presentation.holder = id.did;
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
let key;
|
|
45
|
+
if (args.skipDidResolution) {
|
|
46
|
+
if (!idOpts.kid) {
|
|
47
|
+
key = id.keys.find((key) => { var _a, _b, _c; return ((_b = (_a = key.meta) === null || _a === void 0 ? void 0 : _a.purpose) === null || _b === void 0 ? void 0 : _b.includes((_c = idOpts.verificationMethodSection) !== null && _c !== void 0 ? _c : 'authentication')) === true; });
|
|
48
|
+
}
|
|
49
|
+
if (!key) {
|
|
50
|
+
key = id.keys.find((key) => { var _a; return !idOpts.kid || key.kid === idOpts.kid || ((_a = key.meta) === null || _a === void 0 ? void 0 : _a.jwkThumbprint) === idOpts.kid || `${id.did}#${key.kid}` === idOpts.kid; });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
key = yield (0, ssi_sdk_ext_did_utils_1.getKey)(id, 'authentication', context, idOpts.kid);
|
|
55
|
+
}
|
|
56
|
+
if (!key) {
|
|
57
|
+
throw Error(`Could not determine key to use ${JSON.stringify(idOpts)}`);
|
|
58
|
+
}
|
|
59
|
+
let vm = undefined;
|
|
60
|
+
if (args.skipDidResolution !== true) {
|
|
61
|
+
const didResolution = yield (0, ssi_sdk_ext_did_utils_1.getAgentResolver)(context).resolve(idOpts.identifier.did);
|
|
62
|
+
const vms = yield (0, ssi_sdk_ext_did_utils_1.dereferenceDidKeysWithJwkSupport)(didResolution.didDocument, (_b = idOpts.verificationMethodSection) !== null && _b !== void 0 ? _b : 'authentication', context);
|
|
63
|
+
vm = vms.find((vm) => vm.publicKeyHex === key.publicKeyHex);
|
|
64
|
+
if (!vm) {
|
|
65
|
+
throw Error(`Could not resolve DID document or match signing key to did ${idOpts.identifier.did}`);
|
|
66
|
+
}
|
|
50
67
|
}
|
|
51
68
|
const proofFormat = determineProofFormat({ format, presentationDefinition });
|
|
52
69
|
let header;
|
|
53
70
|
if (!presentation.holder) {
|
|
54
71
|
presentation.holder = id.did;
|
|
55
72
|
}
|
|
73
|
+
const kid = (_e = (_c = vm === null || vm === void 0 ? void 0 : vm.id) !== null && _c !== void 0 ? _c : (_d = key.meta) === null || _d === void 0 ? void 0 : _d.jwkThumbprint) !== null && _e !== void 0 ? _e : key.kid;
|
|
56
74
|
if (proofFormat === 'jwt') {
|
|
57
75
|
header = {
|
|
58
|
-
kid:
|
|
76
|
+
kid: kid.includes('#') ? kid : `${id.did}#${kid}`,
|
|
59
77
|
};
|
|
60
78
|
if (presentation.verifier || !presentation.aud) {
|
|
61
|
-
presentation.aud = Array.isArray(presentation.verifier) ? presentation.verifier : (
|
|
79
|
+
presentation.aud = Array.isArray(presentation.verifier) ? presentation.verifier : (_g = (_f = presentation.verifier) !== null && _f !== void 0 ? _f : domain) !== null && _g !== void 0 ? _g : args.domain;
|
|
62
80
|
delete presentation.verifier;
|
|
63
81
|
}
|
|
64
82
|
if (!presentation.nbf) {
|
|
@@ -69,7 +87,7 @@ function createPEXPresentationSignCallback(args, context) {
|
|
|
69
87
|
}
|
|
70
88
|
}
|
|
71
89
|
else {
|
|
72
|
-
presentation.nbf = Math.floor(Date.now() / 1000);
|
|
90
|
+
presentation.nbf = Math.floor(Date.now() / 1000 - 120);
|
|
73
91
|
}
|
|
74
92
|
}
|
|
75
93
|
if (!presentation.iat) {
|
|
@@ -83,7 +101,7 @@ function createPEXPresentationSignCallback(args, context) {
|
|
|
83
101
|
}
|
|
84
102
|
}
|
|
85
103
|
else {
|
|
86
|
-
presentation.exp = presentation.nbf + 600;
|
|
104
|
+
presentation.exp = presentation.nbf + 600 + 120;
|
|
87
105
|
}
|
|
88
106
|
}
|
|
89
107
|
if (!presentation.vp) {
|
|
@@ -98,7 +116,6 @@ function createPEXPresentationSignCallback(args, context) {
|
|
|
98
116
|
}
|
|
99
117
|
// we ignore the alg / proof_format for now, as we already have the kid anyway at this point
|
|
100
118
|
// todo: look for jwt_vc_json and remove types and @context
|
|
101
|
-
console.log(`PRE CREATE VP AGENT ${new Date().toString()}`);
|
|
102
119
|
const vp = yield context.agent.createVerifiablePresentation({
|
|
103
120
|
presentation: presentation,
|
|
104
121
|
removeOriginalFields: false,
|
|
@@ -109,8 +126,6 @@ function createPEXPresentationSignCallback(args, context) {
|
|
|
109
126
|
proofFormat,
|
|
110
127
|
header,
|
|
111
128
|
});
|
|
112
|
-
console.log(`POST CREATE VP AGENT ${new Date().toString()}`);
|
|
113
|
-
console.log(`PRE MAPPER AGENT ${new Date().toString()}`);
|
|
114
129
|
// makes sure we extract an actual JWT from the internal representation in case it is a JWT
|
|
115
130
|
return ssi_types_1.CredentialMapper.storedPresentationToOriginalFormat(vp);
|
|
116
131
|
});
|
package/dist/functions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2EAA4I;
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../src/functions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AAY,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;oBACjD,CAAC;gBACH,CAAC;gBAED,IAAI,CAAC,YAAY,CAAC,EAAE,EAAE,CAAC;oBACrB,YAAY,CAAC,EAAE,GAAG,EAAE,CAAA;gBACtB,CAAC;gBACD,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC;oBACtB,YAAY,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,CAAA;gBAC3B,CAAC;gBACD,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC;oBAC5B,YAAY,CAAC,EAAE,CAAC,MAAM,GAAG,EAAE,CAAC,GAAG,CAAA;gBACjC,CAAC;YACH,CAAC;YAED,4FAA4F;YAE5F,2DAA2D;YAE3D,MAAM,EAAE,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,4BAA4B,CAAC;gBAC1D,YAAY,EAAE,YAAmC;gBACjD,oBAAoB,EAAE,KAAK;gBAC3B,MAAM,EAAE,GAAG,CAAC,GAAG;gBACf,oGAAoG;gBACpG,SAAS,EAAE,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,IAAI,CAAC,SAAS;gBACtC,mBAAmB,EAAE,IAAI,CAAC,mBAAmB,KAAK,KAAK;gBACvD,WAAW;gBACX,MAAM;aACP,CAAC,CAAA;YACF,2FAA2F;YAC3F,OAAO,4BAAgB,CAAC,kCAAkC,CAAC,EAAoC,CAAC,CAAA;QAClG,CAAC,CAAA,CAAA;IACH,CAAC;CAAA;AAtJD,8EAsJC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.presentation-exchange",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.1-next.108+3d45251f",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@sphereon/pex": "^3.3.3",
|
|
18
18
|
"@sphereon/pex-models": "^2.2.4",
|
|
19
|
-
"@sphereon/ssi-sdk-ext.did-utils": "0.
|
|
20
|
-
"@sphereon/ssi-sdk.data-store": "0.26.
|
|
21
|
-
"@sphereon/ssi-types": "0.26.
|
|
19
|
+
"@sphereon/ssi-sdk-ext.did-utils": "0.22.0",
|
|
20
|
+
"@sphereon/ssi-sdk.data-store": "0.26.1-next.108+3d45251f",
|
|
21
|
+
"@sphereon/ssi-types": "0.26.1-next.108+3d45251f",
|
|
22
22
|
"@veramo/core": "4.2.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@sphereon/did-uni-client": "^0.6.3",
|
|
26
|
-
"@sphereon/ssi-sdk.agent-config": "0.26.
|
|
26
|
+
"@sphereon/ssi-sdk.agent-config": "0.26.1-next.108+3d45251f",
|
|
27
27
|
"@types/json-buffer": "^3.0.0",
|
|
28
28
|
"@veramo/did-provider-key": "4.2.0",
|
|
29
29
|
"@veramo/did-resolver": "4.2.0",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"OpenID Connect",
|
|
61
61
|
"Authenticator"
|
|
62
62
|
],
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "3d45251fa6e91fc3aaa3b684211124a6c79999c9"
|
|
64
64
|
}
|
package/src/functions.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { dereferenceDidKeysWithJwkSupport, getAgentResolver, getIdentifier, getKey, IIdentifierOpts } from '@sphereon/ssi-sdk-ext.did-utils'
|
|
2
|
+
import { _NormalizedVerificationMethod } from '@veramo/utils'
|
|
2
3
|
import { IPEXPresentationSignCallback, IRequiredContext } from './types/IPresentationExchange'
|
|
3
4
|
import { IPresentationDefinition } from '@sphereon/pex'
|
|
4
|
-
import { PresentationPayload, ProofFormat } from '@veramo/core'
|
|
5
|
+
import { IKey, PresentationPayload, ProofFormat } from '@veramo/core'
|
|
5
6
|
import { CredentialMapper, Optional, OriginalVerifiablePresentation, W3CVerifiablePresentation } from '@sphereon/ssi-types'
|
|
6
7
|
import { Format } from '@sphereon/pex-models'
|
|
7
8
|
|
|
@@ -9,6 +10,7 @@ export async function createPEXPresentationSignCallback(
|
|
|
9
10
|
args: {
|
|
10
11
|
idOpts: IIdentifierOpts
|
|
11
12
|
fetchRemoteContexts?: boolean
|
|
13
|
+
skipDidResolution?: boolean
|
|
12
14
|
format?: Format | ProofFormat
|
|
13
15
|
domain?: string
|
|
14
16
|
challenge?: string
|
|
@@ -58,12 +60,32 @@ export async function createPEXPresentationSignCallback(
|
|
|
58
60
|
if (!presentation.holder) {
|
|
59
61
|
presentation.holder = id.did
|
|
60
62
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
let key: IKey | undefined
|
|
64
|
+
|
|
65
|
+
if (args.skipDidResolution) {
|
|
66
|
+
if (!idOpts.kid) {
|
|
67
|
+
key = id.keys.find((key) => key.meta?.purpose?.includes(idOpts.verificationMethodSection ?? 'authentication') === true)
|
|
68
|
+
}
|
|
69
|
+
if (!key) {
|
|
70
|
+
key = id.keys.find(
|
|
71
|
+
(key) => !idOpts.kid || key.kid === idOpts.kid || key.meta?.jwkThumbprint === idOpts.kid || `${id.did}#${key.kid}` === idOpts.kid,
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
key = await getKey(id, 'authentication', context, idOpts.kid)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!key) {
|
|
79
|
+
throw Error(`Could not determine key to use ${JSON.stringify(idOpts)}`)
|
|
80
|
+
}
|
|
81
|
+
let vm: _NormalizedVerificationMethod | undefined = undefined
|
|
82
|
+
if (args.skipDidResolution !== true) {
|
|
83
|
+
const didResolution = await getAgentResolver(context).resolve(idOpts.identifier.did)
|
|
84
|
+
const vms = await dereferenceDidKeysWithJwkSupport(didResolution.didDocument!, idOpts.verificationMethodSection ?? 'authentication', context)
|
|
85
|
+
vm = vms.find((vm) => vm.publicKeyHex === key.publicKeyHex)
|
|
86
|
+
if (!vm) {
|
|
87
|
+
throw Error(`Could not resolve DID document or match signing key to did ${idOpts.identifier.did}`)
|
|
88
|
+
}
|
|
67
89
|
}
|
|
68
90
|
|
|
69
91
|
const proofFormat = determineProofFormat({ format, presentationDefinition })
|
|
@@ -71,9 +93,10 @@ export async function createPEXPresentationSignCallback(
|
|
|
71
93
|
if (!presentation.holder) {
|
|
72
94
|
presentation.holder = id.did
|
|
73
95
|
}
|
|
96
|
+
const kid = vm?.id ?? key.meta?.jwkThumbprint ?? key.kid
|
|
74
97
|
if (proofFormat === 'jwt') {
|
|
75
98
|
header = {
|
|
76
|
-
kid:
|
|
99
|
+
kid: kid.includes('#') ? kid : `${id.did}#${kid}`,
|
|
77
100
|
}
|
|
78
101
|
if (presentation.verifier || !presentation.aud) {
|
|
79
102
|
presentation.aud = Array.isArray(presentation.verifier) ? presentation.verifier : presentation.verifier ?? domain ?? args.domain
|
|
@@ -86,7 +109,7 @@ export async function createPEXPresentationSignCallback(
|
|
|
86
109
|
presentation.nbf = Math.floor(converted / 1000)
|
|
87
110
|
}
|
|
88
111
|
} else {
|
|
89
|
-
presentation.nbf = Math.floor(Date.now() / 1000)
|
|
112
|
+
presentation.nbf = Math.floor(Date.now() / 1000 - 120)
|
|
90
113
|
}
|
|
91
114
|
}
|
|
92
115
|
|
|
@@ -101,7 +124,7 @@ export async function createPEXPresentationSignCallback(
|
|
|
101
124
|
presentation.exp = Math.floor(converted / 1000)
|
|
102
125
|
}
|
|
103
126
|
} else {
|
|
104
|
-
presentation.exp = presentation.nbf + 600
|
|
127
|
+
presentation.exp = presentation.nbf + 600 + 120
|
|
105
128
|
}
|
|
106
129
|
}
|
|
107
130
|
|
|
@@ -120,7 +143,6 @@ export async function createPEXPresentationSignCallback(
|
|
|
120
143
|
|
|
121
144
|
// todo: look for jwt_vc_json and remove types and @context
|
|
122
145
|
|
|
123
|
-
console.log(`PRE CREATE VP AGENT ${new Date().toString()}`)
|
|
124
146
|
const vp = await context.agent.createVerifiablePresentation({
|
|
125
147
|
presentation: presentation as PresentationPayload,
|
|
126
148
|
removeOriginalFields: false,
|
|
@@ -131,8 +153,6 @@ export async function createPEXPresentationSignCallback(
|
|
|
131
153
|
proofFormat,
|
|
132
154
|
header,
|
|
133
155
|
})
|
|
134
|
-
console.log(`POST CREATE VP AGENT ${new Date().toString()}`)
|
|
135
|
-
console.log(`PRE MAPPER AGENT ${new Date().toString()}`)
|
|
136
156
|
// makes sure we extract an actual JWT from the internal representation in case it is a JWT
|
|
137
157
|
return CredentialMapper.storedPresentationToOriginalFormat(vp as OriginalVerifiablePresentation)
|
|
138
158
|
}
|