@sphereon/ssi-sdk.siopv2-oid4vp-rp-rest-client 0.34.1-feature.SSISDK.57.uni.client.205 → 0.34.1-feature.SSISDK.58.host.nonce.endpoint.145
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/index.cjs +26 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -6
- package/dist/index.d.ts +12 -6
- package/dist/index.js +26 -11
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/agent/SIOPv2OID4VPRPRestClient.ts +28 -17
- package/src/types/ISIOPv2OID4VPRPRestClient.ts +9 -4
package/dist/index.cjs
CHANGED
|
@@ -26,9 +26,8 @@ __export(index_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(index_exports);
|
|
27
27
|
|
|
28
28
|
// src/agent/SIOPv2OID4VPRPRestClient.ts
|
|
29
|
-
var import_ssi_sdk = require("@sphereon/ssi-sdk.siopv2-oid4vp-common");
|
|
30
|
-
var import_ssi_types = require("@sphereon/ssi-types");
|
|
31
29
|
var import_cross_fetch = require("cross-fetch");
|
|
30
|
+
var import_ssi_types = require("@sphereon/ssi-types");
|
|
32
31
|
var logger = import_ssi_types.Loggers.DEFAULT.get("sphereon:ssi-sdk-siopv2-oid4vp-rp-rest-client");
|
|
33
32
|
var SIOPv2OID4VPRPRestClient = class {
|
|
34
33
|
static {
|
|
@@ -40,9 +39,11 @@ var SIOPv2OID4VPRPRestClient = class {
|
|
|
40
39
|
siopClientGetAuthStatus: this.siopClientGetAuthStatus.bind(this)
|
|
41
40
|
};
|
|
42
41
|
baseUrl;
|
|
42
|
+
definitionId;
|
|
43
43
|
authOpts;
|
|
44
44
|
constructor(args) {
|
|
45
45
|
this.baseUrl = args?.baseUrl;
|
|
46
|
+
this.definitionId = args?.definitionId;
|
|
46
47
|
this.authOpts = args?.authentication;
|
|
47
48
|
}
|
|
48
49
|
async createHeaders(existing) {
|
|
@@ -60,7 +61,8 @@ var SIOPv2OID4VPRPRestClient = class {
|
|
|
60
61
|
}
|
|
61
62
|
async siopClientRemoveAuthRequestState(args) {
|
|
62
63
|
const baseUrl = this.checkBaseUrlParameter(args.baseUrl);
|
|
63
|
-
|
|
64
|
+
const definitionId = this.checkDefinitionIdParameter(args.definitionId);
|
|
65
|
+
await (0, import_cross_fetch.fetch)(this.uriWithBase(`/webapp/definitions/${definitionId}/auth-requests/${args.correlationId}`, baseUrl), {
|
|
64
66
|
headers: await this.createHeaders(),
|
|
65
67
|
method: "DELETE"
|
|
66
68
|
});
|
|
@@ -68,11 +70,16 @@ var SIOPv2OID4VPRPRestClient = class {
|
|
|
68
70
|
}
|
|
69
71
|
async siopClientGetAuthStatus(args) {
|
|
70
72
|
const baseUrl = this.checkBaseUrlParameter(args.baseUrl);
|
|
71
|
-
const url = this.uriWithBase(
|
|
73
|
+
const url = this.uriWithBase("/webapp/auth-status", baseUrl);
|
|
74
|
+
const definitionId = this.checkDefinitionIdParameter(args.definitionId);
|
|
72
75
|
const statusResponse = await (0, import_cross_fetch.fetch)(url, {
|
|
73
|
-
method: "
|
|
76
|
+
method: "POST",
|
|
74
77
|
headers: await this.createHeaders({
|
|
75
78
|
"Content-Type": "application/json"
|
|
79
|
+
}),
|
|
80
|
+
body: JSON.stringify({
|
|
81
|
+
correlationId: args.correlationId,
|
|
82
|
+
definitionId
|
|
76
83
|
})
|
|
77
84
|
});
|
|
78
85
|
logger.debug(`auth status response: ${statusResponse}`);
|
|
@@ -84,18 +91,20 @@ var SIOPv2OID4VPRPRestClient = class {
|
|
|
84
91
|
}
|
|
85
92
|
async siopClientCreateAuthRequest(args) {
|
|
86
93
|
const baseUrl = this.checkBaseUrlParameter(args.baseUrl);
|
|
87
|
-
const
|
|
94
|
+
const definitionId = this.checkDefinitionIdParameter(args.definitionId);
|
|
95
|
+
const url = this.uriWithBase(`/webapp/definitions/${definitionId}/auth-requests`, baseUrl);
|
|
88
96
|
const origResponse = await (0, import_cross_fetch.fetch)(url, {
|
|
89
97
|
method: "POST",
|
|
90
98
|
headers: await this.createHeaders({
|
|
91
99
|
"Content-Type": "application/json"
|
|
92
100
|
}),
|
|
93
|
-
body: JSON.stringify(
|
|
94
|
-
...args
|
|
95
|
-
|
|
96
|
-
|
|
101
|
+
body: JSON.stringify({
|
|
102
|
+
...args.responseRedirectURI && {
|
|
103
|
+
response_redirect_uri: args.responseRedirectURI
|
|
104
|
+
}
|
|
105
|
+
})
|
|
97
106
|
});
|
|
98
|
-
return
|
|
107
|
+
return await origResponse.json();
|
|
99
108
|
}
|
|
100
109
|
uriWithBase(path, baseUrl) {
|
|
101
110
|
if (!this.baseUrl && !baseUrl) {
|
|
@@ -109,5 +118,11 @@ var SIOPv2OID4VPRPRestClient = class {
|
|
|
109
118
|
}
|
|
110
119
|
return baseUrl ? baseUrl : this.baseUrl;
|
|
111
120
|
}
|
|
121
|
+
checkDefinitionIdParameter(definitionId) {
|
|
122
|
+
if (!definitionId && !this.definitionId) {
|
|
123
|
+
throw new Error("No definition id has been provided");
|
|
124
|
+
}
|
|
125
|
+
return definitionId ? definitionId : this.definitionId;
|
|
126
|
+
}
|
|
112
127
|
};
|
|
113
128
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/agent/SIOPv2OID4VPRPRestClient.ts"],"sourcesContent":["export { SIOPv2OID4VPRPRestClient } from './agent/SIOPv2OID4VPRPRestClient'\nexport * from './types/ISIOPv2OID4VPRPRestClient'\n","import {\n
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/agent/SIOPv2OID4VPRPRestClient.ts"],"sourcesContent":["export { SIOPv2OID4VPRPRestClient } from './agent/SIOPv2OID4VPRPRestClient'\nexport * from './types/ISIOPv2OID4VPRPRestClient'\n","import { fetch } from 'cross-fetch'\nimport {\n ISiopClientGenerateAuthRequestArgs,\n ISiopClientGetAuthStatusArgs,\n ISiopClientRemoveAuthRequestSessionArgs,\n ISIOPv2OID4VPRPRestClient,\n Siopv2RestClientAuthenticationOpts,\n Siopv2RestClientOpts,\n} from '../types/ISIOPv2OID4VPRPRestClient'\nimport { IAgentPlugin } from '@veramo/core'\nimport { AuthStatusResponse, GenerateAuthRequestURIResponse } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'\nimport { Loggers } from '@sphereon/ssi-types'\n\nconst logger = Loggers.DEFAULT.get('sphereon:ssi-sdk-siopv2-oid4vp-rp-rest-client')\n\n/**\n * @beta\n */\nexport class SIOPv2OID4VPRPRestClient implements IAgentPlugin {\n readonly methods: ISIOPv2OID4VPRPRestClient = {\n siopClientRemoveAuthRequestState: this.siopClientRemoveAuthRequestState.bind(this),\n siopClientCreateAuthRequest: this.siopClientCreateAuthRequest.bind(this),\n siopClientGetAuthStatus: this.siopClientGetAuthStatus.bind(this),\n }\n\n private readonly baseUrl?: string\n private readonly definitionId?: string\n private readonly authOpts?: Siopv2RestClientAuthenticationOpts\n\n constructor(args?: Siopv2RestClientOpts) {\n this.baseUrl = args?.baseUrl\n this.definitionId = args?.definitionId\n this.authOpts = args?.authentication\n }\n\n private async createHeaders(existing?: Record<string, any>): Promise<HeadersInit> {\n const headers: HeadersInit = {\n ...existing,\n Accept: 'application/json',\n }\n if (this.authOpts?.enabled === true) {\n if (!this.authOpts.bearerToken) {\n throw Error(`Cannot have authentication enabled, whilst not enabling static bearer tokens at this point`)\n }\n headers.Authorization = `Bearer ${\n typeof this.authOpts.bearerToken === 'string' ? this.authOpts.bearerToken : await this.authOpts.bearerToken()\n }`\n }\n return headers\n }\n\n private async siopClientRemoveAuthRequestState(args: ISiopClientRemoveAuthRequestSessionArgs): Promise<boolean> {\n const baseUrl = this.checkBaseUrlParameter(args.baseUrl)\n const definitionId = this.checkDefinitionIdParameter(args.definitionId)\n await fetch(this.uriWithBase(`/webapp/definitions/${definitionId}/auth-requests/${args.correlationId}`, baseUrl), {\n headers: await this.createHeaders(),\n method: 'DELETE',\n })\n return true\n }\n\n private async siopClientGetAuthStatus(args: ISiopClientGetAuthStatusArgs): Promise<AuthStatusResponse> {\n const baseUrl = this.checkBaseUrlParameter(args.baseUrl)\n const url = this.uriWithBase('/webapp/auth-status', baseUrl)\n const definitionId = this.checkDefinitionIdParameter(args.definitionId)\n const statusResponse = await fetch(url, {\n method: 'POST',\n headers: await this.createHeaders({ 'Content-Type': 'application/json' }),\n body: JSON.stringify({\n correlationId: args.correlationId,\n definitionId,\n }),\n })\n logger.debug(`auth status response: ${statusResponse}`)\n try {\n return await statusResponse.json()\n } catch (err) {\n throw Error(`Status has returned ${statusResponse.status}`)\n }\n }\n\n private async siopClientCreateAuthRequest(args: ISiopClientGenerateAuthRequestArgs): Promise<GenerateAuthRequestURIResponse> {\n const baseUrl = this.checkBaseUrlParameter(args.baseUrl)\n const definitionId = this.checkDefinitionIdParameter(args.definitionId)\n const url = this.uriWithBase(`/webapp/definitions/${definitionId}/auth-requests`, baseUrl)\n const origResponse = await fetch(url, {\n method: 'POST',\n headers: await this.createHeaders({ 'Content-Type': 'application/json' }),\n body: JSON.stringify({\n ...(args.responseRedirectURI && { response_redirect_uri: args.responseRedirectURI }),\n }),\n })\n return await origResponse.json()\n }\n\n private uriWithBase(path: string, baseUrl?: string): string {\n if (!this.baseUrl && !baseUrl) {\n throw new Error('You have to provide baseUrl')\n }\n return baseUrl ? `${baseUrl}${path.startsWith('/') ? path : '/' + path}` : `${this.baseUrl}${path.startsWith('/') ? path : '/' + path}`\n }\n\n private checkBaseUrlParameter(baseUrl?: string): string {\n if (!baseUrl && !this.baseUrl) {\n throw new Error('No base url has been provided')\n }\n return baseUrl ? baseUrl : (this.baseUrl as string)\n }\n\n private checkDefinitionIdParameter(definitionId?: string): string {\n if (!definitionId && !this.definitionId) {\n throw new Error('No definition id has been provided')\n }\n return definitionId ? definitionId : (this.definitionId as string)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,yBAAsB;AAWtB,u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EACnC;EAEQc,2BAA2Bb,cAA+B;AAChE,QAAI,CAACA,gBAAgB,CAAC,KAAKA,cAAc;AACvC,YAAM,IAAIU,MAAM,oCAAA;IAClB;AACA,WAAOV,eAAeA,eAAgB,KAAKA;EAC7C;AACF;","names":["logger","Loggers","DEFAULT","get","SIOPv2OID4VPRPRestClient","methods","siopClientRemoveAuthRequestState","bind","siopClientCreateAuthRequest","siopClientGetAuthStatus","baseUrl","definitionId","authOpts","args","authentication","createHeaders","existing","headers","Accept","enabled","bearerToken","Error","Authorization","checkBaseUrlParameter","checkDefinitionIdParameter","fetch","uriWithBase","correlationId","method","url","statusResponse","body","JSON","stringify","debug","json","err","status","origResponse","responseRedirectURI","response_redirect_uri","path","startsWith"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
import { IPluginMethodMap, IAgentContext, IAgentPlugin } from '@veramo/core';
|
|
2
|
-
import { CreateAuthorizationRequest, CreateAuthorizationResponse, AuthStatusResponse } from '@sphereon/ssi-sdk.siopv2-oid4vp-common';
|
|
3
1
|
import { BearerTokenArg } from '@sphereon/ssi-types';
|
|
2
|
+
import { IPluginMethodMap, IAgentContext, IAgentPlugin } from '@veramo/core';
|
|
3
|
+
import { GenerateAuthRequestURIResponse, AuthStatusResponse } from '@sphereon/ssi-sdk.siopv2-oid4vp-common';
|
|
4
4
|
|
|
5
5
|
interface ISIOPv2OID4VPRPRestClient extends IPluginMethodMap {
|
|
6
6
|
siopClientRemoveAuthRequestState(args: ISiopClientRemoveAuthRequestSessionArgs, context: IRequiredContext): Promise<boolean>;
|
|
7
|
-
siopClientCreateAuthRequest(args: ISiopClientGenerateAuthRequestArgs, context: IRequiredContext): Promise<
|
|
7
|
+
siopClientCreateAuthRequest(args: ISiopClientGenerateAuthRequestArgs, context: IRequiredContext): Promise<GenerateAuthRequestURIResponse>;
|
|
8
8
|
siopClientGetAuthStatus(args: ISiopClientGetAuthStatusArgs, context: IRequiredContext): Promise<AuthStatusResponse>;
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
interface ISiopClientGenerateAuthRequestArgs {
|
|
11
|
+
definitionId?: string;
|
|
11
12
|
baseUrl?: string;
|
|
12
|
-
|
|
13
|
+
responseRedirectURI?: string;
|
|
14
|
+
}
|
|
13
15
|
interface ISiopClientRemoveAuthRequestSessionArgs {
|
|
14
16
|
correlationId: string;
|
|
15
17
|
baseUrl?: string;
|
|
16
|
-
|
|
18
|
+
definitionId?: string;
|
|
17
19
|
}
|
|
18
20
|
interface ISiopClientGetAuthStatusArgs {
|
|
19
21
|
correlationId: string;
|
|
20
22
|
baseUrl?: string;
|
|
23
|
+
definitionId?: string;
|
|
21
24
|
}
|
|
22
25
|
interface Siopv2RestClientAuthenticationOpts {
|
|
23
26
|
enabled?: boolean;
|
|
@@ -25,6 +28,7 @@ interface Siopv2RestClientAuthenticationOpts {
|
|
|
25
28
|
}
|
|
26
29
|
interface Siopv2RestClientOpts {
|
|
27
30
|
baseUrl?: string;
|
|
31
|
+
definitionId?: string;
|
|
28
32
|
authentication?: Siopv2RestClientAuthenticationOpts;
|
|
29
33
|
}
|
|
30
34
|
type IRequiredContext = IAgentContext<any>;
|
|
@@ -35,6 +39,7 @@ type IRequiredContext = IAgentContext<any>;
|
|
|
35
39
|
declare class SIOPv2OID4VPRPRestClient implements IAgentPlugin {
|
|
36
40
|
readonly methods: ISIOPv2OID4VPRPRestClient;
|
|
37
41
|
private readonly baseUrl?;
|
|
42
|
+
private readonly definitionId?;
|
|
38
43
|
private readonly authOpts?;
|
|
39
44
|
constructor(args?: Siopv2RestClientOpts);
|
|
40
45
|
private createHeaders;
|
|
@@ -43,6 +48,7 @@ declare class SIOPv2OID4VPRPRestClient implements IAgentPlugin {
|
|
|
43
48
|
private siopClientCreateAuthRequest;
|
|
44
49
|
private uriWithBase;
|
|
45
50
|
private checkBaseUrlParameter;
|
|
51
|
+
private checkDefinitionIdParameter;
|
|
46
52
|
}
|
|
47
53
|
|
|
48
54
|
export { type IRequiredContext, type ISIOPv2OID4VPRPRestClient, type ISiopClientGenerateAuthRequestArgs, type ISiopClientGetAuthStatusArgs, type ISiopClientRemoveAuthRequestSessionArgs, SIOPv2OID4VPRPRestClient, type Siopv2RestClientAuthenticationOpts, type Siopv2RestClientOpts };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
import { IPluginMethodMap, IAgentContext, IAgentPlugin } from '@veramo/core';
|
|
2
|
-
import { CreateAuthorizationRequest, CreateAuthorizationResponse, AuthStatusResponse } from '@sphereon/ssi-sdk.siopv2-oid4vp-common';
|
|
3
1
|
import { BearerTokenArg } from '@sphereon/ssi-types';
|
|
2
|
+
import { IPluginMethodMap, IAgentContext, IAgentPlugin } from '@veramo/core';
|
|
3
|
+
import { GenerateAuthRequestURIResponse, AuthStatusResponse } from '@sphereon/ssi-sdk.siopv2-oid4vp-common';
|
|
4
4
|
|
|
5
5
|
interface ISIOPv2OID4VPRPRestClient extends IPluginMethodMap {
|
|
6
6
|
siopClientRemoveAuthRequestState(args: ISiopClientRemoveAuthRequestSessionArgs, context: IRequiredContext): Promise<boolean>;
|
|
7
|
-
siopClientCreateAuthRequest(args: ISiopClientGenerateAuthRequestArgs, context: IRequiredContext): Promise<
|
|
7
|
+
siopClientCreateAuthRequest(args: ISiopClientGenerateAuthRequestArgs, context: IRequiredContext): Promise<GenerateAuthRequestURIResponse>;
|
|
8
8
|
siopClientGetAuthStatus(args: ISiopClientGetAuthStatusArgs, context: IRequiredContext): Promise<AuthStatusResponse>;
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
interface ISiopClientGenerateAuthRequestArgs {
|
|
11
|
+
definitionId?: string;
|
|
11
12
|
baseUrl?: string;
|
|
12
|
-
|
|
13
|
+
responseRedirectURI?: string;
|
|
14
|
+
}
|
|
13
15
|
interface ISiopClientRemoveAuthRequestSessionArgs {
|
|
14
16
|
correlationId: string;
|
|
15
17
|
baseUrl?: string;
|
|
16
|
-
|
|
18
|
+
definitionId?: string;
|
|
17
19
|
}
|
|
18
20
|
interface ISiopClientGetAuthStatusArgs {
|
|
19
21
|
correlationId: string;
|
|
20
22
|
baseUrl?: string;
|
|
23
|
+
definitionId?: string;
|
|
21
24
|
}
|
|
22
25
|
interface Siopv2RestClientAuthenticationOpts {
|
|
23
26
|
enabled?: boolean;
|
|
@@ -25,6 +28,7 @@ interface Siopv2RestClientAuthenticationOpts {
|
|
|
25
28
|
}
|
|
26
29
|
interface Siopv2RestClientOpts {
|
|
27
30
|
baseUrl?: string;
|
|
31
|
+
definitionId?: string;
|
|
28
32
|
authentication?: Siopv2RestClientAuthenticationOpts;
|
|
29
33
|
}
|
|
30
34
|
type IRequiredContext = IAgentContext<any>;
|
|
@@ -35,6 +39,7 @@ type IRequiredContext = IAgentContext<any>;
|
|
|
35
39
|
declare class SIOPv2OID4VPRPRestClient implements IAgentPlugin {
|
|
36
40
|
readonly methods: ISIOPv2OID4VPRPRestClient;
|
|
37
41
|
private readonly baseUrl?;
|
|
42
|
+
private readonly definitionId?;
|
|
38
43
|
private readonly authOpts?;
|
|
39
44
|
constructor(args?: Siopv2RestClientOpts);
|
|
40
45
|
private createHeaders;
|
|
@@ -43,6 +48,7 @@ declare class SIOPv2OID4VPRPRestClient implements IAgentPlugin {
|
|
|
43
48
|
private siopClientCreateAuthRequest;
|
|
44
49
|
private uriWithBase;
|
|
45
50
|
private checkBaseUrlParameter;
|
|
51
|
+
private checkDefinitionIdParameter;
|
|
46
52
|
}
|
|
47
53
|
|
|
48
54
|
export { type IRequiredContext, type ISIOPv2OID4VPRPRestClient, type ISiopClientGenerateAuthRequestArgs, type ISiopClientGetAuthStatusArgs, type ISiopClientRemoveAuthRequestSessionArgs, SIOPv2OID4VPRPRestClient, type Siopv2RestClientAuthenticationOpts, type Siopv2RestClientOpts };
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,8 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/agent/SIOPv2OID4VPRPRestClient.ts
|
|
5
|
-
import { createAuthorizationRequestToPayload, createAuthorizationResponseFromPayload } from "@sphereon/ssi-sdk.siopv2-oid4vp-common";
|
|
6
|
-
import { Loggers } from "@sphereon/ssi-types";
|
|
7
5
|
import { fetch } from "cross-fetch";
|
|
6
|
+
import { Loggers } from "@sphereon/ssi-types";
|
|
8
7
|
var logger = Loggers.DEFAULT.get("sphereon:ssi-sdk-siopv2-oid4vp-rp-rest-client");
|
|
9
8
|
var SIOPv2OID4VPRPRestClient = class {
|
|
10
9
|
static {
|
|
@@ -16,9 +15,11 @@ var SIOPv2OID4VPRPRestClient = class {
|
|
|
16
15
|
siopClientGetAuthStatus: this.siopClientGetAuthStatus.bind(this)
|
|
17
16
|
};
|
|
18
17
|
baseUrl;
|
|
18
|
+
definitionId;
|
|
19
19
|
authOpts;
|
|
20
20
|
constructor(args) {
|
|
21
21
|
this.baseUrl = args?.baseUrl;
|
|
22
|
+
this.definitionId = args?.definitionId;
|
|
22
23
|
this.authOpts = args?.authentication;
|
|
23
24
|
}
|
|
24
25
|
async createHeaders(existing) {
|
|
@@ -36,7 +37,8 @@ var SIOPv2OID4VPRPRestClient = class {
|
|
|
36
37
|
}
|
|
37
38
|
async siopClientRemoveAuthRequestState(args) {
|
|
38
39
|
const baseUrl = this.checkBaseUrlParameter(args.baseUrl);
|
|
39
|
-
|
|
40
|
+
const definitionId = this.checkDefinitionIdParameter(args.definitionId);
|
|
41
|
+
await fetch(this.uriWithBase(`/webapp/definitions/${definitionId}/auth-requests/${args.correlationId}`, baseUrl), {
|
|
40
42
|
headers: await this.createHeaders(),
|
|
41
43
|
method: "DELETE"
|
|
42
44
|
});
|
|
@@ -44,11 +46,16 @@ var SIOPv2OID4VPRPRestClient = class {
|
|
|
44
46
|
}
|
|
45
47
|
async siopClientGetAuthStatus(args) {
|
|
46
48
|
const baseUrl = this.checkBaseUrlParameter(args.baseUrl);
|
|
47
|
-
const url = this.uriWithBase(
|
|
49
|
+
const url = this.uriWithBase("/webapp/auth-status", baseUrl);
|
|
50
|
+
const definitionId = this.checkDefinitionIdParameter(args.definitionId);
|
|
48
51
|
const statusResponse = await fetch(url, {
|
|
49
|
-
method: "
|
|
52
|
+
method: "POST",
|
|
50
53
|
headers: await this.createHeaders({
|
|
51
54
|
"Content-Type": "application/json"
|
|
55
|
+
}),
|
|
56
|
+
body: JSON.stringify({
|
|
57
|
+
correlationId: args.correlationId,
|
|
58
|
+
definitionId
|
|
52
59
|
})
|
|
53
60
|
});
|
|
54
61
|
logger.debug(`auth status response: ${statusResponse}`);
|
|
@@ -60,18 +67,20 @@ var SIOPv2OID4VPRPRestClient = class {
|
|
|
60
67
|
}
|
|
61
68
|
async siopClientCreateAuthRequest(args) {
|
|
62
69
|
const baseUrl = this.checkBaseUrlParameter(args.baseUrl);
|
|
63
|
-
const
|
|
70
|
+
const definitionId = this.checkDefinitionIdParameter(args.definitionId);
|
|
71
|
+
const url = this.uriWithBase(`/webapp/definitions/${definitionId}/auth-requests`, baseUrl);
|
|
64
72
|
const origResponse = await fetch(url, {
|
|
65
73
|
method: "POST",
|
|
66
74
|
headers: await this.createHeaders({
|
|
67
75
|
"Content-Type": "application/json"
|
|
68
76
|
}),
|
|
69
|
-
body: JSON.stringify(
|
|
70
|
-
...args
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
body: JSON.stringify({
|
|
78
|
+
...args.responseRedirectURI && {
|
|
79
|
+
response_redirect_uri: args.responseRedirectURI
|
|
80
|
+
}
|
|
81
|
+
})
|
|
73
82
|
});
|
|
74
|
-
return
|
|
83
|
+
return await origResponse.json();
|
|
75
84
|
}
|
|
76
85
|
uriWithBase(path, baseUrl) {
|
|
77
86
|
if (!this.baseUrl && !baseUrl) {
|
|
@@ -85,6 +94,12 @@ var SIOPv2OID4VPRPRestClient = class {
|
|
|
85
94
|
}
|
|
86
95
|
return baseUrl ? baseUrl : this.baseUrl;
|
|
87
96
|
}
|
|
97
|
+
checkDefinitionIdParameter(definitionId) {
|
|
98
|
+
if (!definitionId && !this.definitionId) {
|
|
99
|
+
throw new Error("No definition id has been provided");
|
|
100
|
+
}
|
|
101
|
+
return definitionId ? definitionId : this.definitionId;
|
|
102
|
+
}
|
|
88
103
|
};
|
|
89
104
|
export {
|
|
90
105
|
SIOPv2OID4VPRPRestClient
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/agent/SIOPv2OID4VPRPRestClient.ts"],"sourcesContent":["import {\n
|
|
1
|
+
{"version":3,"sources":["../src/agent/SIOPv2OID4VPRPRestClient.ts"],"sourcesContent":["import { fetch } from 'cross-fetch'\nimport {\n ISiopClientGenerateAuthRequestArgs,\n ISiopClientGetAuthStatusArgs,\n ISiopClientRemoveAuthRequestSessionArgs,\n ISIOPv2OID4VPRPRestClient,\n Siopv2RestClientAuthenticationOpts,\n Siopv2RestClientOpts,\n} from '../types/ISIOPv2OID4VPRPRestClient'\nimport { IAgentPlugin } from '@veramo/core'\nimport { AuthStatusResponse, GenerateAuthRequestURIResponse } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'\nimport { Loggers } from '@sphereon/ssi-types'\n\nconst logger = Loggers.DEFAULT.get('sphereon:ssi-sdk-siopv2-oid4vp-rp-rest-client')\n\n/**\n * @beta\n */\nexport class SIOPv2OID4VPRPRestClient implements IAgentPlugin {\n readonly methods: ISIOPv2OID4VPRPRestClient = {\n siopClientRemoveAuthRequestState: this.siopClientRemoveAuthRequestState.bind(this),\n siopClientCreateAuthRequest: this.siopClientCreateAuthRequest.bind(this),\n siopClientGetAuthStatus: this.siopClientGetAuthStatus.bind(this),\n }\n\n private readonly baseUrl?: string\n private readonly definitionId?: string\n private readonly authOpts?: Siopv2RestClientAuthenticationOpts\n\n constructor(args?: Siopv2RestClientOpts) {\n this.baseUrl = args?.baseUrl\n this.definitionId = args?.definitionId\n this.authOpts = args?.authentication\n }\n\n private async createHeaders(existing?: Record<string, any>): Promise<HeadersInit> {\n const headers: HeadersInit = {\n ...existing,\n Accept: 'application/json',\n }\n if (this.authOpts?.enabled === true) {\n if (!this.authOpts.bearerToken) {\n throw Error(`Cannot have authentication enabled, whilst not enabling static bearer tokens at this point`)\n }\n headers.Authorization = `Bearer ${\n typeof this.authOpts.bearerToken === 'string' ? this.authOpts.bearerToken : await this.authOpts.bearerToken()\n }`\n }\n return headers\n }\n\n private async siopClientRemoveAuthRequestState(args: ISiopClientRemoveAuthRequestSessionArgs): Promise<boolean> {\n const baseUrl = this.checkBaseUrlParameter(args.baseUrl)\n const definitionId = this.checkDefinitionIdParameter(args.definitionId)\n await fetch(this.uriWithBase(`/webapp/definitions/${definitionId}/auth-requests/${args.correlationId}`, baseUrl), {\n headers: await this.createHeaders(),\n method: 'DELETE',\n })\n return true\n }\n\n private async siopClientGetAuthStatus(args: ISiopClientGetAuthStatusArgs): Promise<AuthStatusResponse> {\n const baseUrl = this.checkBaseUrlParameter(args.baseUrl)\n const url = this.uriWithBase('/webapp/auth-status', baseUrl)\n const definitionId = this.checkDefinitionIdParameter(args.definitionId)\n const statusResponse = await fetch(url, {\n method: 'POST',\n headers: await this.createHeaders({ 'Content-Type': 'application/json' }),\n body: JSON.stringify({\n correlationId: args.correlationId,\n definitionId,\n }),\n })\n logger.debug(`auth status response: ${statusResponse}`)\n try {\n return await statusResponse.json()\n } catch (err) {\n throw Error(`Status has returned ${statusResponse.status}`)\n }\n }\n\n private async siopClientCreateAuthRequest(args: ISiopClientGenerateAuthRequestArgs): Promise<GenerateAuthRequestURIResponse> {\n const baseUrl = this.checkBaseUrlParameter(args.baseUrl)\n const definitionId = this.checkDefinitionIdParameter(args.definitionId)\n const url = this.uriWithBase(`/webapp/definitions/${definitionId}/auth-requests`, baseUrl)\n const origResponse = await fetch(url, {\n method: 'POST',\n headers: await this.createHeaders({ 'Content-Type': 'application/json' }),\n body: JSON.stringify({\n ...(args.responseRedirectURI && { response_redirect_uri: args.responseRedirectURI }),\n }),\n })\n return await origResponse.json()\n }\n\n private uriWithBase(path: string, baseUrl?: string): string {\n if (!this.baseUrl && !baseUrl) {\n throw new Error('You have to provide baseUrl')\n }\n return baseUrl ? `${baseUrl}${path.startsWith('/') ? path : '/' + path}` : `${this.baseUrl}${path.startsWith('/') ? path : '/' + path}`\n }\n\n private checkBaseUrlParameter(baseUrl?: string): string {\n if (!baseUrl && !this.baseUrl) {\n throw new Error('No base url has been provided')\n }\n return baseUrl ? baseUrl : (this.baseUrl as string)\n }\n\n private checkDefinitionIdParameter(definitionId?: string): string {\n if (!definitionId && !this.definitionId) {\n throw new Error('No definition id has been provided')\n }\n return definitionId ? definitionId : (this.definitionId as string)\n }\n}\n"],"mappings":";;;;AAAA,SAASA,aAAa;AAWtB,SAASC,eAAe;AAExB,IAAMC,SAASC,QAAQC,QAAQC,IAAI,+CAAA;AAK5B,IAAMC,2BAAN,MAAMA;EAlBb,OAkBaA;;;EACFC,UAAqC;IAC5CC,kCAAkC,KAAKA,iCAAiCC,KAAK,IAAI;IACjFC,6BAA6B,KAAKA,4BAA4BD,KAAK,IAAI;IACvEE,yBAAyB,KAAKA,wBAAwBF,KAAK,IAAI;EACjE;EAEiBG;EACAC;EACAC;EAEjB,YAAYC,MAA6B;AACvC,SAAKH,UAAUG,MAAMH;AACrB,SAAKC,eAAeE,MAAMF;AAC1B,SAAKC,WAAWC,MAAMC;EACxB;EAEA,MAAcC,cAAcC,UAAsD;AAChF,UAAMC,UAAuB;MAC3B,GAAGD;MACHE,QAAQ;IACV;AACA,QAAI,KAAKN,UAAUO,YAAY,MAAM;AACnC,UAAI,CAAC,KAAKP,SAASQ,aAAa;AAC9B,cAAMC,MAAM,4FAA4F;MAC1G;AACAJ,cAAQK,gBAAgB,UACtB,OAAO,KAAKV,SAASQ,gBAAgB,WAAW,KAAKR,SAASQ,cAAc,MAAM,KAAKR,SAASQ,YAAW,CAAA;IAE/G;AACA,WAAOH;EACT;EAEA,MAAcX,iCAAiCO,M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AA;IACF,CAAA;AACA,WAAO,MAAMD,aAAaH,KAAI;EAChC;EAEQT,YAAYe,MAAc/B,SAA0B;AAC1D,QAAI,CAAC,KAAKA,WAAW,CAACA,SAAS;AAC7B,YAAM,IAAIW,MAAM,6BAAA;IAClB;AACA,WAAOX,UAAU,GAAGA,OAAAA,GAAU+B,KAAKC,WAAW,GAAA,IAAOD,OAAO,MAAMA,IAAAA,KAAS,GAAG,KAAK/B,OAAO,GAAG+B,KAAKC,WAAW,GAAA,IAAOD,OAAO,MAAMA,IAAAA;EACnI;EAEQlB,sBAAsBb,SAA0B;AACtD,QAAI,CAACA,WAAW,CAAC,KAAKA,SAAS;AAC7B,YAAM,IAAIW,MAAM,+BAAA;IAClB;AACA,WAAOX,UAAUA,UAAW,KAAKA;EACnC;EAEQc,2BAA2Bb,cAA+B;AAChE,QAAI,CAACA,gBAAgB,CAAC,KAAKA,cAAc;AACvC,YAAM,IAAIU,MAAM,oCAAA;IAClB;AACA,WAAOV,eAAeA,eAAgB,KAAKA;EAC7C;AACF;","names":["fetch","Loggers","logger","Loggers","DEFAULT","get","SIOPv2OID4VPRPRestClient","methods","siopClientRemoveAuthRequestState","bind","siopClientCreateAuthRequest","siopClientGetAuthStatus","baseUrl","definitionId","authOpts","args","authentication","createHeaders","existing","headers","Accept","enabled","bearerToken","Error","Authorization","checkBaseUrlParameter","checkDefinitionIdParameter","fetch","uriWithBase","correlationId","method","url","statusResponse","body","JSON","stringify","debug","json","err","status","origResponse","responseRedirectURI","response_redirect_uri","path","startsWith"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.siopv2-oid4vp-rp-rest-client",
|
|
3
3
|
"description": "contains the client side to call REST endpoints of relying party",
|
|
4
|
-
"version": "0.34.1-feature.SSISDK.
|
|
4
|
+
"version": "0.34.1-feature.SSISDK.58.host.nonce.endpoint.145+5bfc0b12",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.cjs",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"build": "tsup --config ../../tsup.config.ts --tsconfig ../../tsconfig.tsup.json"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@sphereon/ssi-sdk.siopv2-oid4vp-common": "0.34.1-feature.SSISDK.
|
|
31
|
-
"@sphereon/ssi-types": "0.34.1-feature.SSISDK.
|
|
30
|
+
"@sphereon/ssi-sdk.siopv2-oid4vp-common": "0.34.1-feature.SSISDK.58.host.nonce.endpoint.145+5bfc0b12",
|
|
31
|
+
"@sphereon/ssi-types": "0.34.1-feature.SSISDK.58.host.nonce.endpoint.145+5bfc0b12",
|
|
32
32
|
"@veramo/core": "4.2.0",
|
|
33
33
|
"cross-fetch": "^4.1.0"
|
|
34
34
|
},
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"author": "Sphereon <dev@sphereon.com>",
|
|
54
54
|
"license": "Apache-2.0",
|
|
55
55
|
"keywords": [],
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "5bfc0b1229134b5d80279a3baf1fc64c9c6e755e"
|
|
57
57
|
}
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type AuthStatusResponse,
|
|
3
|
-
type CreateAuthorizationRequest,
|
|
4
|
-
createAuthorizationRequestToPayload,
|
|
5
|
-
type CreateAuthorizationResponse,
|
|
6
|
-
createAuthorizationResponseFromPayload,
|
|
7
|
-
} from '@sphereon/ssi-sdk.siopv2-oid4vp-common'
|
|
8
|
-
import { Loggers } from '@sphereon/ssi-types'
|
|
9
|
-
import { IAgentPlugin } from '@veramo/core'
|
|
10
1
|
import { fetch } from 'cross-fetch'
|
|
11
2
|
import {
|
|
12
3
|
ISiopClientGenerateAuthRequestArgs,
|
|
@@ -16,6 +7,9 @@ import {
|
|
|
16
7
|
Siopv2RestClientAuthenticationOpts,
|
|
17
8
|
Siopv2RestClientOpts,
|
|
18
9
|
} from '../types/ISIOPv2OID4VPRPRestClient'
|
|
10
|
+
import { IAgentPlugin } from '@veramo/core'
|
|
11
|
+
import { AuthStatusResponse, GenerateAuthRequestURIResponse } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'
|
|
12
|
+
import { Loggers } from '@sphereon/ssi-types'
|
|
19
13
|
|
|
20
14
|
const logger = Loggers.DEFAULT.get('sphereon:ssi-sdk-siopv2-oid4vp-rp-rest-client')
|
|
21
15
|
|
|
@@ -30,10 +24,12 @@ export class SIOPv2OID4VPRPRestClient implements IAgentPlugin {
|
|
|
30
24
|
}
|
|
31
25
|
|
|
32
26
|
private readonly baseUrl?: string
|
|
27
|
+
private readonly definitionId?: string
|
|
33
28
|
private readonly authOpts?: Siopv2RestClientAuthenticationOpts
|
|
34
29
|
|
|
35
30
|
constructor(args?: Siopv2RestClientOpts) {
|
|
36
31
|
this.baseUrl = args?.baseUrl
|
|
32
|
+
this.definitionId = args?.definitionId
|
|
37
33
|
this.authOpts = args?.authentication
|
|
38
34
|
}
|
|
39
35
|
|
|
@@ -55,7 +51,8 @@ export class SIOPv2OID4VPRPRestClient implements IAgentPlugin {
|
|
|
55
51
|
|
|
56
52
|
private async siopClientRemoveAuthRequestState(args: ISiopClientRemoveAuthRequestSessionArgs): Promise<boolean> {
|
|
57
53
|
const baseUrl = this.checkBaseUrlParameter(args.baseUrl)
|
|
58
|
-
|
|
54
|
+
const definitionId = this.checkDefinitionIdParameter(args.definitionId)
|
|
55
|
+
await fetch(this.uriWithBase(`/webapp/definitions/${definitionId}/auth-requests/${args.correlationId}`, baseUrl), {
|
|
59
56
|
headers: await this.createHeaders(),
|
|
60
57
|
method: 'DELETE',
|
|
61
58
|
})
|
|
@@ -64,10 +61,15 @@ export class SIOPv2OID4VPRPRestClient implements IAgentPlugin {
|
|
|
64
61
|
|
|
65
62
|
private async siopClientGetAuthStatus(args: ISiopClientGetAuthStatusArgs): Promise<AuthStatusResponse> {
|
|
66
63
|
const baseUrl = this.checkBaseUrlParameter(args.baseUrl)
|
|
67
|
-
const url = this.uriWithBase(
|
|
64
|
+
const url = this.uriWithBase('/webapp/auth-status', baseUrl)
|
|
65
|
+
const definitionId = this.checkDefinitionIdParameter(args.definitionId)
|
|
68
66
|
const statusResponse = await fetch(url, {
|
|
69
|
-
method: '
|
|
67
|
+
method: 'POST',
|
|
70
68
|
headers: await this.createHeaders({ 'Content-Type': 'application/json' }),
|
|
69
|
+
body: JSON.stringify({
|
|
70
|
+
correlationId: args.correlationId,
|
|
71
|
+
definitionId,
|
|
72
|
+
}),
|
|
71
73
|
})
|
|
72
74
|
logger.debug(`auth status response: ${statusResponse}`)
|
|
73
75
|
try {
|
|
@@ -77,16 +79,18 @@ export class SIOPv2OID4VPRPRestClient implements IAgentPlugin {
|
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
81
|
|
|
80
|
-
private async siopClientCreateAuthRequest(args: ISiopClientGenerateAuthRequestArgs): Promise<
|
|
82
|
+
private async siopClientCreateAuthRequest(args: ISiopClientGenerateAuthRequestArgs): Promise<GenerateAuthRequestURIResponse> {
|
|
81
83
|
const baseUrl = this.checkBaseUrlParameter(args.baseUrl)
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
+
const definitionId = this.checkDefinitionIdParameter(args.definitionId)
|
|
85
|
+
const url = this.uriWithBase(`/webapp/definitions/${definitionId}/auth-requests`, baseUrl)
|
|
84
86
|
const origResponse = await fetch(url, {
|
|
85
87
|
method: 'POST',
|
|
86
88
|
headers: await this.createHeaders({ 'Content-Type': 'application/json' }),
|
|
87
|
-
body: JSON.stringify(
|
|
89
|
+
body: JSON.stringify({
|
|
90
|
+
...(args.responseRedirectURI && { response_redirect_uri: args.responseRedirectURI }),
|
|
91
|
+
}),
|
|
88
92
|
})
|
|
89
|
-
return
|
|
93
|
+
return await origResponse.json()
|
|
90
94
|
}
|
|
91
95
|
|
|
92
96
|
private uriWithBase(path: string, baseUrl?: string): string {
|
|
@@ -102,4 +106,11 @@ export class SIOPv2OID4VPRPRestClient implements IAgentPlugin {
|
|
|
102
106
|
}
|
|
103
107
|
return baseUrl ? baseUrl : (this.baseUrl as string)
|
|
104
108
|
}
|
|
109
|
+
|
|
110
|
+
private checkDefinitionIdParameter(definitionId?: string): string {
|
|
111
|
+
if (!definitionId && !this.definitionId) {
|
|
112
|
+
throw new Error('No definition id has been provided')
|
|
113
|
+
}
|
|
114
|
+
return definitionId ? definitionId : (this.definitionId as string)
|
|
115
|
+
}
|
|
105
116
|
}
|
|
@@ -1,28 +1,32 @@
|
|
|
1
|
-
import { AuthStatusResponse, type CreateAuthorizationRequest, type CreateAuthorizationResponse } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'
|
|
2
1
|
import { BearerTokenArg } from '@sphereon/ssi-types'
|
|
3
2
|
import { IAgentContext, IPluginMethodMap } from '@veramo/core'
|
|
4
3
|
|
|
4
|
+
import { AuthStatusResponse, GenerateAuthRequestURIResponse } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'
|
|
5
|
+
|
|
5
6
|
export interface ISIOPv2OID4VPRPRestClient extends IPluginMethodMap {
|
|
6
7
|
siopClientRemoveAuthRequestState(args: ISiopClientRemoveAuthRequestSessionArgs, context: IRequiredContext): Promise<boolean>
|
|
7
8
|
|
|
8
|
-
siopClientCreateAuthRequest(args: ISiopClientGenerateAuthRequestArgs, context: IRequiredContext): Promise<
|
|
9
|
+
siopClientCreateAuthRequest(args: ISiopClientGenerateAuthRequestArgs, context: IRequiredContext): Promise<GenerateAuthRequestURIResponse>
|
|
9
10
|
|
|
10
11
|
siopClientGetAuthStatus(args: ISiopClientGetAuthStatusArgs, context: IRequiredContext): Promise<AuthStatusResponse>
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
export
|
|
14
|
+
export interface ISiopClientGenerateAuthRequestArgs {
|
|
15
|
+
definitionId?: string
|
|
14
16
|
baseUrl?: string
|
|
17
|
+
responseRedirectURI?: string
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
export interface ISiopClientRemoveAuthRequestSessionArgs {
|
|
18
21
|
correlationId: string
|
|
19
22
|
baseUrl?: string
|
|
20
|
-
|
|
23
|
+
definitionId?: string
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
export interface ISiopClientGetAuthStatusArgs {
|
|
24
27
|
correlationId: string
|
|
25
28
|
baseUrl?: string
|
|
29
|
+
definitionId?: string
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
export interface Siopv2RestClientAuthenticationOpts {
|
|
@@ -32,6 +36,7 @@ export interface Siopv2RestClientAuthenticationOpts {
|
|
|
32
36
|
|
|
33
37
|
export interface Siopv2RestClientOpts {
|
|
34
38
|
baseUrl?: string
|
|
39
|
+
definitionId?: string
|
|
35
40
|
authentication?: Siopv2RestClientAuthenticationOpts
|
|
36
41
|
}
|
|
37
42
|
|