@sphereon/ssi-sdk.presentation-exchange 0.18.2-unstable.32 → 0.18.2-unstable.34
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.map +1 -1
- package/dist/functions.js +66 -17
- package/dist/functions.js.map +1 -1
- package/package.json +6 -6
- package/src/functions.ts +65 -15
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;AAC5I,OAAO,EAAE,WAAW,EAAE,4BAA4B,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAC3G,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AACvD,OAAO,EAAuB,WAAW,EAAE,MAAM,cAAc,CAAA;AAE/D,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAE7C,wBAAsB,yBAAyB,CAAC,UAAU,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,uBAAuB,GAAG,SAAS,CAAC,CAItH;AAED,wBAAsB,iCAAiC,CACrD,IAAI,EAAE;IACJ,MAAM,EAAE,eAAe,CAAA;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,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,
|
|
1
|
+
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6E,eAAe,EAAE,MAAM,iCAAiC,CAAA;AAC5I,OAAO,EAAE,WAAW,EAAE,4BAA4B,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAC3G,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AACvD,OAAO,EAAuB,WAAW,EAAE,MAAM,cAAc,CAAA;AAE/D,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAE7C,wBAAsB,yBAAyB,CAAC,UAAU,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,uBAAuB,GAAG,SAAS,CAAC,CAItH;AAED,wBAAsB,iCAAiC,CACrD,IAAI,EAAE;IACJ,MAAM,EAAE,eAAe,CAAA;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,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,CAiHvC"}
|
package/dist/functions.js
CHANGED
|
@@ -22,13 +22,33 @@ function getPresentationDefinition(pexOptions) {
|
|
|
22
22
|
exports.getPresentationDefinition = getPresentationDefinition;
|
|
23
23
|
function createPEXPresentationSignCallback(args, context) {
|
|
24
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
function determineProofFormat(format, presentationDefinition) {
|
|
26
|
+
var _a;
|
|
27
|
+
let proofFormat = 'jwt';
|
|
28
|
+
const formatOptions = (_a = format !== null && format !== void 0 ? format : args.format) !== null && _a !== void 0 ? _a : presentationDefinition.format;
|
|
29
|
+
if (formatOptions) {
|
|
30
|
+
if (typeof formatOptions === 'object') {
|
|
31
|
+
const formats = Object.keys(formatOptions).map((form) => (form.includes('ldp') ? 'lds' : 'jwt'));
|
|
32
|
+
if (!formats.includes('jwt')) {
|
|
33
|
+
proofFormat = 'lds';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
proofFormat = formatOptions;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return proofFormat;
|
|
41
|
+
}
|
|
25
42
|
return ({ presentation, domain, presentationDefinition, format, challenge, }) => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
var _a, _b;
|
|
43
|
+
var _a, _b, _c;
|
|
27
44
|
const idOpts = args.idOpts;
|
|
28
45
|
const id = yield (0, ssi_sdk_ext_did_utils_1.getIdentifier)(idOpts, context);
|
|
29
46
|
if (typeof idOpts.identifier === 'string') {
|
|
30
47
|
idOpts.identifier = id;
|
|
31
48
|
}
|
|
49
|
+
if (!presentation.holder) {
|
|
50
|
+
presentation.holder = id.did;
|
|
51
|
+
}
|
|
32
52
|
const key = yield (0, ssi_sdk_ext_did_utils_1.getKey)(id, 'authentication', context, idOpts.kid);
|
|
33
53
|
const didResolution = yield (0, ssi_sdk_ext_did_utils_1.getAgentResolver)(context).resolve(idOpts.identifier.did);
|
|
34
54
|
const vms = yield (0, ssi_sdk_ext_did_utils_1.dereferenceDidKeysWithJwkSupport)(didResolution.didDocument, (_a = idOpts.verificationMethodSection) !== null && _a !== void 0 ? _a : 'authentication', context);
|
|
@@ -36,32 +56,61 @@ function createPEXPresentationSignCallback(args, context) {
|
|
|
36
56
|
if (!vm) {
|
|
37
57
|
throw Error(`Could not resolve DID document or match signing key to did ${idOpts.identifier.did}`);
|
|
38
58
|
}
|
|
39
|
-
|
|
40
|
-
const formatOptions = (_b = format !== null && format !== void 0 ? format : args.format) !== null && _b !== void 0 ? _b : presentationDefinition.format;
|
|
41
|
-
if (formatOptions) {
|
|
42
|
-
if (typeof formatOptions === 'object') {
|
|
43
|
-
const formats = Object.keys(formatOptions).map((form) => (form.includes('ldp') ? 'lds' : 'jwt'));
|
|
44
|
-
if (!formats.includes('jwt')) {
|
|
45
|
-
proofFormat = 'lds';
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
proofFormat = formatOptions;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
59
|
+
const proofFormat = determineProofFormat(format !== null && format !== void 0 ? format : 'jwt', presentationDefinition);
|
|
52
60
|
let header;
|
|
53
|
-
if (
|
|
61
|
+
if (!presentation.holder) {
|
|
62
|
+
presentation.holder = id.did;
|
|
63
|
+
}
|
|
64
|
+
if (proofFormat === 'jwt') {
|
|
54
65
|
header = {
|
|
55
66
|
kid: vm.id,
|
|
56
67
|
};
|
|
68
|
+
if (presentation.verifier || !presentation.aud) {
|
|
69
|
+
presentation.aud = Array.isArray(presentation.verifier) ? presentation.verifier : (_c = (_b = presentation.verifier) !== null && _b !== void 0 ? _b : domain) !== null && _c !== void 0 ? _c : args.domain;
|
|
70
|
+
delete presentation.verifier;
|
|
71
|
+
}
|
|
72
|
+
if (!presentation.nbf) {
|
|
73
|
+
if (presentation.issuanceDate) {
|
|
74
|
+
const converted = Date.parse(presentation.issuanceDate);
|
|
75
|
+
if (!isNaN(converted)) {
|
|
76
|
+
presentation.nbf = Math.floor(converted / 1000);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
presentation.nbf = Math.floor(Date.now() / 1000);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (!presentation.iat) {
|
|
84
|
+
presentation.iat = presentation.nbf;
|
|
85
|
+
}
|
|
86
|
+
if (!presentation.exp) {
|
|
87
|
+
if (presentation.expirationDate) {
|
|
88
|
+
const converted = Date.parse(presentation.expirationDate);
|
|
89
|
+
if (!isNaN(converted)) {
|
|
90
|
+
presentation.exp = Math.floor(converted / 1000);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
presentation.exp = presentation.nbf + 600;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (!presentation.vp) {
|
|
98
|
+
presentation.vp = {};
|
|
99
|
+
}
|
|
100
|
+
if (!presentation.sub) {
|
|
101
|
+
presentation.sub = id.did;
|
|
102
|
+
}
|
|
103
|
+
if (!presentation.vp.holder) {
|
|
104
|
+
presentation.vp.holder = id.did;
|
|
105
|
+
}
|
|
57
106
|
}
|
|
58
107
|
// we ignore the alg / proof_format for now, as we already have the kid anyway at this point
|
|
59
108
|
// todo: look for jwt_vc_json and remove types and @context
|
|
60
109
|
const vp = yield context.agent.createVerifiablePresentation({
|
|
61
110
|
presentation: presentation,
|
|
62
|
-
removeOriginalFields:
|
|
111
|
+
removeOriginalFields: false,
|
|
63
112
|
keyRef: key.kid,
|
|
64
|
-
domain: domain
|
|
113
|
+
// domain: domain ?? args.domain, // handled above, and did-jwt-vc creates an array even for 1 entry
|
|
65
114
|
challenge: challenge !== null && challenge !== void 0 ? challenge : args.challenge,
|
|
66
115
|
fetchRemoteContexts: args.fetchRemoteContexts !== false,
|
|
67
116
|
proofFormat,
|
package/dist/functions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2EAA4I;AAI5I,mDAA2H;AAG3H,SAAsB,yBAAyB,CAAC,UAAwB;;QACtE,OAAO,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,UAAU,CAAA;QAC7B;sGAC8F;IAChG,CAAC;CAAA;AAJD,8DAIC;AAED,SAAsB,iCAAiC,CACrD,IAMC,EACD,OAAyB;;QAEzB,OAAO,CAAO,EACZ,YAAY,EACZ,MAAM,EACN,sBAAsB,EACtB,MAAM,EACN,SAAS,GAOV,EAAsC,EAAE;;YACvC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;YAC1B,MAAM,EAAE,GAAG,MAAM,IAAA,qCAAa,EAAC,MAAM,EAAE,OAAO,CAAC,CAAA;YAC/C,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,QAAQ,EAAE;gBACzC,MAAM,CAAC,UAAU,GAAG,EAAE,CAAA;aACvB;YACD,MAAM,GAAG,GAAG,MAAM,IAAA,8BAAM,EAAC,EAAE,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,CAAA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CAAkC,CAAC,EAAoC,CAAC,CAAA;QAClG,CAAC,CAAA,CAAA;IACH,CAAC;CAAA;AA1HD,8EA0HC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.presentation-exchange",
|
|
3
|
-
"version": "0.18.2-unstable.
|
|
3
|
+
"version": "0.18.2-unstable.34+59efb484",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,16 +14,16 @@
|
|
|
14
14
|
"build:clean": "tsc --build --clean && tsc --build"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@sphereon/pex": "3.
|
|
17
|
+
"@sphereon/pex": "^3.2.0",
|
|
18
18
|
"@sphereon/pex-models": "^2.2.0",
|
|
19
19
|
"@sphereon/ssi-sdk-ext.did-utils": "0.15.0",
|
|
20
|
-
"@sphereon/ssi-sdk.kv-store-temp": "0.18.2-unstable.
|
|
21
|
-
"@sphereon/ssi-types": "0.18.2-unstable.
|
|
20
|
+
"@sphereon/ssi-sdk.kv-store-temp": "0.18.2-unstable.34+59efb484",
|
|
21
|
+
"@sphereon/ssi-types": "0.18.2-unstable.34+59efb484",
|
|
22
22
|
"@veramo/core": "4.2.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@sphereon/did-uni-client": "^0.6.0",
|
|
26
|
-
"@sphereon/ssi-sdk.agent-config": "0.18.2-unstable.
|
|
26
|
+
"@sphereon/ssi-sdk.agent-config": "0.18.2-unstable.34+59efb484",
|
|
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",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"OpenID Connect",
|
|
64
64
|
"Authenticator"
|
|
65
65
|
],
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "59efb484dc96358221c0cc6aab4bbb2ea033d6b7"
|
|
67
67
|
}
|
package/src/functions.ts
CHANGED
|
@@ -21,6 +21,22 @@ export async function createPEXPresentationSignCallback(
|
|
|
21
21
|
},
|
|
22
22
|
context: IRequiredContext
|
|
23
23
|
): Promise<IPEXPresentationSignCallback> {
|
|
24
|
+
function determineProofFormat(format: Format | 'jwt' | 'lds' | 'EthereumEip712Signature2021', presentationDefinition: IPresentationDefinition) {
|
|
25
|
+
let proofFormat: ProofFormat = 'jwt'
|
|
26
|
+
const formatOptions = format ?? args.format ?? presentationDefinition.format
|
|
27
|
+
if (formatOptions) {
|
|
28
|
+
if (typeof formatOptions === 'object') {
|
|
29
|
+
const formats = Object.keys(formatOptions).map((form) => (form.includes('ldp') ? 'lds' : 'jwt'))
|
|
30
|
+
if (!formats.includes('jwt')) {
|
|
31
|
+
proofFormat = 'lds'
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
proofFormat = formatOptions
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return proofFormat
|
|
38
|
+
}
|
|
39
|
+
|
|
24
40
|
return async ({
|
|
25
41
|
presentation,
|
|
26
42
|
domain,
|
|
@@ -39,6 +55,9 @@ export async function createPEXPresentationSignCallback(
|
|
|
39
55
|
if (typeof idOpts.identifier === 'string') {
|
|
40
56
|
idOpts.identifier = id
|
|
41
57
|
}
|
|
58
|
+
if (!presentation.holder) {
|
|
59
|
+
presentation.holder = id.did
|
|
60
|
+
}
|
|
42
61
|
const key = await getKey(id, 'authentication', context, idOpts.kid)
|
|
43
62
|
const didResolution = await getAgentResolver(context).resolve(idOpts.identifier.did)
|
|
44
63
|
const vms = await dereferenceDidKeysWithJwkSupport(didResolution.didDocument!, idOpts.verificationMethodSection ?? 'authentication', context)
|
|
@@ -47,23 +66,54 @@ export async function createPEXPresentationSignCallback(
|
|
|
47
66
|
throw Error(`Could not resolve DID document or match signing key to did ${idOpts.identifier.did}`)
|
|
48
67
|
}
|
|
49
68
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
const formats = Object.keys(formatOptions).map((form) => (form.includes('ldp') ? 'lds' : 'jwt'))
|
|
55
|
-
if (!formats.includes('jwt')) {
|
|
56
|
-
proofFormat = 'lds'
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
proofFormat = formatOptions
|
|
60
|
-
}
|
|
69
|
+
const proofFormat = determineProofFormat(format ?? 'jwt', presentationDefinition)
|
|
70
|
+
let header
|
|
71
|
+
if (!presentation.holder) {
|
|
72
|
+
presentation.holder = id.did
|
|
61
73
|
}
|
|
62
|
-
|
|
63
|
-
if (format === 'jwt') {
|
|
74
|
+
if (proofFormat === 'jwt') {
|
|
64
75
|
header = {
|
|
65
76
|
kid: vm.id,
|
|
66
77
|
}
|
|
78
|
+
if (presentation.verifier || !presentation.aud) {
|
|
79
|
+
presentation.aud = Array.isArray(presentation.verifier) ? presentation.verifier : presentation.verifier ?? domain ?? args.domain
|
|
80
|
+
delete presentation.verifier
|
|
81
|
+
}
|
|
82
|
+
if (!presentation.nbf) {
|
|
83
|
+
if (presentation.issuanceDate) {
|
|
84
|
+
const converted = Date.parse(presentation.issuanceDate)
|
|
85
|
+
if (!isNaN(converted)) {
|
|
86
|
+
presentation.nbf = Math.floor(converted / 1000)
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
presentation.nbf = Math.floor(Date.now() / 1000)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!presentation.iat) {
|
|
94
|
+
presentation.iat = presentation.nbf
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (!presentation.exp) {
|
|
98
|
+
if (presentation.expirationDate) {
|
|
99
|
+
const converted = Date.parse(presentation.expirationDate)
|
|
100
|
+
if (!isNaN(converted)) {
|
|
101
|
+
presentation.exp = Math.floor(converted / 1000)
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
presentation.exp = presentation.nbf + 600
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (!presentation.vp) {
|
|
109
|
+
presentation.vp = {}
|
|
110
|
+
}
|
|
111
|
+
if (!presentation.sub) {
|
|
112
|
+
presentation.sub = id.did
|
|
113
|
+
}
|
|
114
|
+
if (!presentation.vp.holder) {
|
|
115
|
+
presentation.vp.holder = id.did
|
|
116
|
+
}
|
|
67
117
|
}
|
|
68
118
|
|
|
69
119
|
// we ignore the alg / proof_format for now, as we already have the kid anyway at this point
|
|
@@ -72,9 +122,9 @@ export async function createPEXPresentationSignCallback(
|
|
|
72
122
|
|
|
73
123
|
const vp = await context.agent.createVerifiablePresentation({
|
|
74
124
|
presentation: presentation as PresentationPayload,
|
|
75
|
-
removeOriginalFields:
|
|
125
|
+
removeOriginalFields: false,
|
|
76
126
|
keyRef: key.kid,
|
|
77
|
-
domain: domain ?? args.domain,
|
|
127
|
+
// domain: domain ?? args.domain, // handled above, and did-jwt-vc creates an array even for 1 entry
|
|
78
128
|
challenge: challenge ?? args.challenge,
|
|
79
129
|
fetchRemoteContexts: args.fetchRemoteContexts !== false,
|
|
80
130
|
proofFormat,
|