@sphereon/ssi-sdk.oidf-client 0.30.2-feature.SPRIND.92.153 → 0.30.2-fix.198
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/OIDFClient.d.ts +2 -3
- package/dist/agent/OIDFClient.d.ts.map +1 -1
- package/dist/agent/OIDFClient.js +39 -7
- package/dist/agent/OIDFClient.js.map +1 -1
- package/dist/ssi-sdk.oidf-client.d.ts +5 -6
- package/dist/types/IOIDFClient.d.ts +1 -1
- package/dist/types/IOIDFClient.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/agent/OIDFClient.ts +44 -12
- package/src/types/IOIDFClient.ts +1 -1
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { IAgentPlugin } from "@veramo/core";
|
|
2
2
|
import { IOIDFClient, OIDFClientArgs } from '../types/IOIDFClient';
|
|
3
|
-
import { com } from '@sphereon/openid-federation-client';
|
|
4
|
-
import FederationClient = com.sphereon.oid.fed.client.FederationClient;
|
|
5
3
|
export declare const oidfClientMethods: Array<string>;
|
|
6
4
|
export declare class OIDFClient implements IAgentPlugin {
|
|
7
|
-
|
|
5
|
+
private oidfClient?;
|
|
8
6
|
readonly schema: any;
|
|
9
7
|
constructor(args?: OIDFClientArgs);
|
|
10
8
|
readonly methods: IOIDFClient;
|
|
11
9
|
private resolveTrustChain;
|
|
10
|
+
private checkAndSetDefaultCryptoService;
|
|
12
11
|
private signJwt;
|
|
13
12
|
private verifyJwt;
|
|
14
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OIDFClient.d.ts","sourceRoot":"","sources":["../../src/agent/OIDFClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,cAAc,CAAC;AAO1C,OAAO,EACH,WAAW,EACX,cAAc,EAIjB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"OIDFClient.d.ts","sourceRoot":"","sources":["../../src/agent/OIDFClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,cAAc,CAAC;AAO1C,OAAO,EACH,WAAW,EACX,cAAc,EAIjB,MAAM,sBAAsB,CAAC;AAS9B,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,MAAM,CAI3C,CAAA;AAED,qBAAa,UAAW,YAAW,YAAY;IAC3C,OAAO,CAAC,UAAU,CAAC,CAAkB;IACrC,QAAQ,CAAC,MAAM,MAAqB;gBAExB,IAAI,CAAC,EAAE,cAAc;IAYjC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAI5B;YAEa,iBAAiB;IAM/B,OAAO,CAAC,+BAA+B;YA6BzB,OAAO;YAIP,SAAS;CAG1B"}
|
package/dist/agent/OIDFClient.js
CHANGED
|
@@ -30,20 +30,52 @@ class OIDFClient {
|
|
|
30
30
|
verifyJwt: this.verifyJwt.bind(this)
|
|
31
31
|
};
|
|
32
32
|
const { cryptoServiceCallback } = Object.assign({}, args);
|
|
33
|
-
|
|
34
|
-
DefaultCallbacks.setTrustChainServiceDefault(new DefaultTrustChainJSImpl());
|
|
35
|
-
if (cryptoServiceCallback) {
|
|
33
|
+
if (cryptoServiceCallback !== undefined && cryptoServiceCallback !== null) {
|
|
36
34
|
DefaultCallbacks.setCryptoServiceDefault(cryptoServiceCallback);
|
|
35
|
+
DefaultCallbacks.setFetchServiceDefault(new DefaultFetchJSImpl());
|
|
36
|
+
// Depends on the crypto and fetch services, thus it must be the last one to be set
|
|
37
|
+
DefaultCallbacks.setTrustChainServiceDefault(new DefaultTrustChainJSImpl());
|
|
38
|
+
this.oidfClient = new FederationClient();
|
|
37
39
|
}
|
|
38
|
-
//FIXME set default Federation client crypto callback
|
|
39
|
-
this.oidfClient = new FederationClient();
|
|
40
40
|
}
|
|
41
|
-
resolveTrustChain(args) {
|
|
41
|
+
resolveTrustChain(args, context) {
|
|
42
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
var _a;
|
|
43
44
|
const { entityIdentifier, trustAnchors } = args;
|
|
44
|
-
|
|
45
|
+
this.checkAndSetDefaultCryptoService(context);
|
|
46
|
+
return yield ((_a = this.oidfClient) === null || _a === void 0 ? void 0 : _a.resolveTrustChain(entityIdentifier, trustAnchors));
|
|
45
47
|
});
|
|
46
48
|
}
|
|
49
|
+
checkAndSetDefaultCryptoService(context) {
|
|
50
|
+
if ((context.agent.jwtVerifyJwsSignature !== undefined &&
|
|
51
|
+
context.agent.jwtVerifyJwsSignature !== null) &&
|
|
52
|
+
(this.oidfClient === undefined || this.oidfClient === null)) {
|
|
53
|
+
try {
|
|
54
|
+
DefaultCallbacks.setCryptoServiceDefault({
|
|
55
|
+
verify: (jwt, key) => __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const jwk = Object.assign({}, key);
|
|
57
|
+
try {
|
|
58
|
+
console.error(`JWT: ${jwt}\nJWK: ${JSON.stringify(jwk)}`);
|
|
59
|
+
return !(yield context.agent.jwtVerifyJwsSignature({
|
|
60
|
+
jws: jwt,
|
|
61
|
+
jwk
|
|
62
|
+
})).error;
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
console.error(`Error verifying the JWT: ${e.message}`);
|
|
66
|
+
return Promise.reject(e);
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
});
|
|
70
|
+
DefaultCallbacks.setFetchServiceDefault(new DefaultFetchJSImpl());
|
|
71
|
+
DefaultCallbacks.setTrustChainServiceDefault(new DefaultTrustChainJSImpl());
|
|
72
|
+
this.oidfClient = new FederationClient();
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
throw Error(`Could not initialize the federation client: ${error.message}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
47
79
|
signJwt(args, context) {
|
|
48
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
81
|
return yield context.agent.jwtCreateJwsCompactSignature(args);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OIDFClient.js","sourceRoot":"","sources":["../../src/agent/OIDFClient.ts"],"names":[],"mappings":";;;;;;;;;;;;AAcA,
|
|
1
|
+
{"version":3,"file":"OIDFClient.js","sourceRoot":"","sources":["../../src/agent/OIDFClient.ts"],"names":[],"mappings":"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"}
|
|
@@ -11,23 +11,22 @@ import { VerifyJwsArgs } from '@sphereon/ssi-sdk-ext.jwt-service';
|
|
|
11
11
|
export declare type CryptoServiceCallbackArgs = ICryptoCallbackServiceJS;
|
|
12
12
|
|
|
13
13
|
export declare interface IOIDFClient extends IPluginMethodMap {
|
|
14
|
-
resolveTrustChain(args: ResolveTrustChainArgs): Promise<ResolveTrustChainCallbackResult>;
|
|
14
|
+
resolveTrustChain(args: ResolveTrustChainArgs, context: RequiredContext): Promise<ResolveTrustChainCallbackResult>;
|
|
15
15
|
signJwt(args: CreateJwsCompactArgs, context: RequiredContext): Promise<JwtCompactResult>;
|
|
16
16
|
verifyJwt(args: VerifyJwsArgs, context: RequiredContext): Promise<IJwsValidationResult>;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export declare const logger: ISimpleLogger<unknown>;
|
|
20
20
|
|
|
21
|
-
declare type Nullable<T> = T | null | undefined
|
|
22
|
-
|
|
23
|
-
declare type Nullable_2<T> = T | null | undefined;
|
|
21
|
+
declare type Nullable<T> = T | null | undefined;
|
|
24
22
|
|
|
25
23
|
export declare class OIDFClient implements IAgentPlugin {
|
|
26
|
-
|
|
24
|
+
private oidfClient?;
|
|
27
25
|
readonly schema: any;
|
|
28
26
|
constructor(args?: OIDFClientArgs);
|
|
29
27
|
readonly methods: IOIDFClient;
|
|
30
28
|
private resolveTrustChain;
|
|
29
|
+
private checkAndSetDefaultCryptoService;
|
|
31
30
|
private signJwt;
|
|
32
31
|
private verifyJwt;
|
|
33
32
|
}
|
|
@@ -45,7 +44,7 @@ export declare type ResolveTrustChainArgs = {
|
|
|
45
44
|
trustAnchors: Array<string>;
|
|
46
45
|
};
|
|
47
46
|
|
|
48
|
-
export declare type ResolveTrustChainCallbackResult =
|
|
47
|
+
export declare type ResolveTrustChainCallbackResult = Nullable<Array<string>>;
|
|
49
48
|
|
|
50
49
|
/**
|
|
51
50
|
* @public
|
|
@@ -3,7 +3,7 @@ import { com } from '@sphereon/openid-federation-client';
|
|
|
3
3
|
import ICryptoCallbackServiceJS = com.sphereon.oid.fed.client.crypto.ICryptoCallbackServiceJS;
|
|
4
4
|
import { CreateJwsCompactArgs, IJwsValidationResult, IJwtService, JwtCompactResult, VerifyJwsArgs } from '@sphereon/ssi-sdk-ext.jwt-service';
|
|
5
5
|
export interface IOIDFClient extends IPluginMethodMap {
|
|
6
|
-
resolveTrustChain(args: ResolveTrustChainArgs): Promise<ResolveTrustChainCallbackResult>;
|
|
6
|
+
resolveTrustChain(args: ResolveTrustChainArgs, context: RequiredContext): Promise<ResolveTrustChainCallbackResult>;
|
|
7
7
|
signJwt(args: CreateJwsCompactArgs, context: RequiredContext): Promise<JwtCompactResult>;
|
|
8
8
|
verifyJwt(args: VerifyJwsArgs, context: RequiredContext): Promise<IJwsValidationResult>;
|
|
9
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IOIDFClient.d.ts","sourceRoot":"","sources":["../../src/types/IOIDFClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,GAAG,EAAE,MAAM,oCAAoC,CAAC;AACzD,OAAO,wBAAwB,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,wBAAwB,CAAC;AAC9F,OAAO,EACH,oBAAoB,EACpB,oBAAoB,EACpB,WAAW,EACX,gBAAgB,EAChB,aAAa,EAChB,MAAM,mCAAmC,CAAC;AAE3C,MAAM,WAAW,WAAY,SAAQ,gBAAgB;IACjD,iBAAiB,CAAC,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC,+BAA+B,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"IOIDFClient.d.ts","sourceRoot":"","sources":["../../src/types/IOIDFClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,GAAG,EAAE,MAAM,oCAAoC,CAAC;AACzD,OAAO,wBAAwB,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,wBAAwB,CAAC;AAC9F,OAAO,EACH,oBAAoB,EACpB,oBAAoB,EACpB,WAAW,EACX,gBAAgB,EAChB,aAAa,EAChB,MAAM,mCAAmC,CAAC;AAE3C,MAAM,WAAW,WAAY,SAAQ,gBAAgB;IACjD,iBAAiB,CAAC,IAAI,EAAE,qBAAqB,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,+BAA+B,CAAC,CAAA;IAClH,OAAO,CAAC,IAAI,EAAE,oBAAoB,EAAE,OAAO,EAAE,eAAe,GAAI,OAAO,CAAC,gBAAgB,CAAC,CAAA;IACzF,SAAS,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAA;CAC1F;AAED,MAAM,MAAM,qBAAqB,GAAG;IAChC,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CAC9B,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IACzB,qBAAqB,CAAC,EAAE,yBAAyB,CAAA;CACpD,CAAA;AAED,MAAM,MAAM,yBAAyB,GAAG,wBAAwB,CAAA;AAEhE,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAA;AAEvC,MAAM,MAAM,+BAA+B,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;AAErE,MAAM,MAAM,eAAe,GAAG,aAAa,CAAC,WAAW,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.oidf-client",
|
|
3
|
-
"version": "0.30.2-
|
|
3
|
+
"version": "0.30.2-fix.198+53185bd6",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
"generate-plugin-schema": "ts-node ../../packages/dev/bin/sphereon.js dev generate-plugin-schema"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@sphereon/openid-federation-client": "0.1.0-unstable.
|
|
19
|
-
"@sphereon/openid-federation-common": "0.1.0-unstable.
|
|
20
|
-
"@sphereon/openid-federation-open-api": "0.1.0-unstable.
|
|
21
|
-
"@sphereon/ssi-sdk-ext.jwt-service": "
|
|
22
|
-
"@sphereon/ssi-types": "0.30.2-
|
|
18
|
+
"@sphereon/openid-federation-client": "0.1.0-unstable.d8421f6",
|
|
19
|
+
"@sphereon/openid-federation-common": "0.1.0-unstable.d8421f6",
|
|
20
|
+
"@sphereon/openid-federation-open-api": "0.1.0-unstable.d8421f6",
|
|
21
|
+
"@sphereon/ssi-sdk-ext.jwt-service": "0.25.0",
|
|
22
|
+
"@sphereon/ssi-types": "0.30.2-fix.198+53185bd6"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@sphereon/ssi-sdk.agent-config": "0.30.2-
|
|
25
|
+
"@sphereon/ssi-sdk.agent-config": "0.30.2-fix.198+53185bd6",
|
|
26
26
|
"@veramo/remote-client": "4.2.0",
|
|
27
27
|
"@veramo/remote-server": "4.2.0",
|
|
28
28
|
"cross-fetch": "^3.1.8",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"Veramo",
|
|
50
50
|
"OpenID Federation"
|
|
51
51
|
],
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "53185bd6a982dba2e45fc591048ca0a3bf38612e"
|
|
53
53
|
}
|
package/src/agent/OIDFClient.ts
CHANGED
|
@@ -12,12 +12,13 @@ import {
|
|
|
12
12
|
ResolveTrustChainArgs,
|
|
13
13
|
ResolveTrustChainCallbackResult
|
|
14
14
|
} from '../types/IOIDFClient';
|
|
15
|
-
import {
|
|
15
|
+
import {com} from '@sphereon/openid-federation-client';
|
|
16
16
|
import {schema} from '../index';
|
|
17
17
|
import FederationClient = com.sphereon.oid.fed.client.FederationClient;
|
|
18
|
-
import DefaultFetchJSImpl = com.sphereon.oid.fed.client.fetch.DefaultFetchJSImpl
|
|
19
|
-
import DefaultTrustChainJSImpl = com.sphereon.oid.fed.client.trustchain.DefaultTrustChainJSImpl
|
|
20
|
-
import DefaultCallbacks = com.sphereon.oid.fed.client.service.DefaultCallbacks
|
|
18
|
+
import DefaultFetchJSImpl = com.sphereon.oid.fed.client.fetch.DefaultFetchJSImpl;
|
|
19
|
+
import DefaultTrustChainJSImpl = com.sphereon.oid.fed.client.trustchain.DefaultTrustChainJSImpl;
|
|
20
|
+
import DefaultCallbacks = com.sphereon.oid.fed.client.service.DefaultCallbacks;
|
|
21
|
+
import {JWK} from "@sphereon/ssi-types";
|
|
21
22
|
|
|
22
23
|
export const oidfClientMethods: Array<string> = [
|
|
23
24
|
'resolveTrustChain',
|
|
@@ -26,18 +27,19 @@ export const oidfClientMethods: Array<string> = [
|
|
|
26
27
|
]
|
|
27
28
|
|
|
28
29
|
export class OIDFClient implements IAgentPlugin {
|
|
29
|
-
|
|
30
|
+
private oidfClient?: FederationClient
|
|
30
31
|
readonly schema = schema.IOIDFClient
|
|
31
32
|
|
|
32
33
|
constructor(args?: OIDFClientArgs) {
|
|
33
34
|
const { cryptoServiceCallback } = { ...args }
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (cryptoServiceCallback) {
|
|
35
|
+
|
|
36
|
+
if (cryptoServiceCallback !== undefined && cryptoServiceCallback !== null) {
|
|
37
37
|
DefaultCallbacks.setCryptoServiceDefault(cryptoServiceCallback)
|
|
38
|
+
DefaultCallbacks.setFetchServiceDefault(new DefaultFetchJSImpl())
|
|
39
|
+
// Depends on the crypto and fetch services, thus it must be the last one to be set
|
|
40
|
+
DefaultCallbacks.setTrustChainServiceDefault(new DefaultTrustChainJSImpl())
|
|
41
|
+
this.oidfClient = new FederationClient()
|
|
38
42
|
}
|
|
39
|
-
//FIXME set default Federation client crypto callback
|
|
40
|
-
this.oidfClient = new FederationClient()
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
readonly methods: IOIDFClient = {
|
|
@@ -46,9 +48,39 @@ export class OIDFClient implements IAgentPlugin {
|
|
|
46
48
|
verifyJwt: this.verifyJwt.bind(this)
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
private async resolveTrustChain(args: ResolveTrustChainArgs): Promise<ResolveTrustChainCallbackResult> {
|
|
51
|
+
private async resolveTrustChain(args: ResolveTrustChainArgs, context: RequiredContext): Promise<ResolveTrustChainCallbackResult> {
|
|
50
52
|
const { entityIdentifier, trustAnchors } = args
|
|
51
|
-
|
|
53
|
+
this.checkAndSetDefaultCryptoService(context);
|
|
54
|
+
return await this.oidfClient?.resolveTrustChain(entityIdentifier, trustAnchors)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private checkAndSetDefaultCryptoService(context: RequiredContext) {
|
|
58
|
+
if ((context.agent.jwtVerifyJwsSignature !== undefined &&
|
|
59
|
+
context.agent.jwtVerifyJwsSignature !== null) &&
|
|
60
|
+
(this.oidfClient === undefined || this.oidfClient === null)) {
|
|
61
|
+
try {
|
|
62
|
+
DefaultCallbacks.setCryptoServiceDefault({
|
|
63
|
+
verify: async (jwt: string, key: any): Promise<boolean> => {
|
|
64
|
+
const jwk: JWK = { ...key }
|
|
65
|
+
try {
|
|
66
|
+
console.error(`JWT: ${jwt}\nJWK: ${JSON.stringify(jwk)}`)
|
|
67
|
+
return !(await context.agent.jwtVerifyJwsSignature({
|
|
68
|
+
jws: jwt,
|
|
69
|
+
jwk
|
|
70
|
+
})).error
|
|
71
|
+
} catch(e) {
|
|
72
|
+
console.error(`Error verifying the JWT: ${e.message}`)
|
|
73
|
+
return Promise.reject(e)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
DefaultCallbacks.setFetchServiceDefault(new DefaultFetchJSImpl())
|
|
78
|
+
DefaultCallbacks.setTrustChainServiceDefault(new DefaultTrustChainJSImpl())
|
|
79
|
+
this.oidfClient = new FederationClient()
|
|
80
|
+
} catch (error) {
|
|
81
|
+
throw Error(`Could not initialize the federation client: ${error.message}`)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
52
84
|
}
|
|
53
85
|
|
|
54
86
|
private async signJwt(args: CreateJwsCompactArgs, context: RequiredContext): Promise<JwtCompactResult> {
|
package/src/types/IOIDFClient.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from '@sphereon/ssi-sdk-ext.jwt-service';
|
|
11
11
|
|
|
12
12
|
export interface IOIDFClient extends IPluginMethodMap {
|
|
13
|
-
resolveTrustChain(args: ResolveTrustChainArgs): Promise<ResolveTrustChainCallbackResult>
|
|
13
|
+
resolveTrustChain(args: ResolveTrustChainArgs, context: RequiredContext): Promise<ResolveTrustChainCallbackResult>
|
|
14
14
|
signJwt(args: CreateJwsCompactArgs, context: RequiredContext ): Promise<JwtCompactResult>
|
|
15
15
|
verifyJwt(args: VerifyJwsArgs, context: RequiredContext): Promise<IJwsValidationResult>
|
|
16
16
|
}
|