@mattrglobal/verifier-sdk-web 2.3.1-unstable.3 → 2.3.1-unstable.32
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/README.md +1 -1
- package/dist/lib/verifier-js-no-deps.cjs.js +77 -10
- package/dist/lib/verifier-js-no-deps.cjs.js.map +1 -1
- package/dist/lib/verifier-js.cjs.js +77 -10
- package/dist/lib/verifier-js.cjs.js.map +1 -1
- package/dist/typings/verifier/requestCredentialsDigitalCredentialsApi.d.ts +12 -1
- package/dist/typings/verifier/types/credential-presentation.d.ts +20 -0
- package/dist/typings/verifier/utils.d.ts +10 -2
- package/dist/verifier-js.development.js +73 -10
- package/dist/verifier-js.development.js.map +1 -1
- package/dist/verifier-js.production.esm.js +2 -2
- package/dist/verifier-js.production.esm.js.map +1 -1
- package/dist/verifier-js.production.js +2 -2
- package/dist/verifier-js.production.js.map +1 -1
- package/package.json +3 -3
|
@@ -14,6 +14,17 @@ export declare const requestCredentialsWithDigitalCredentialsApi: (options: Requ
|
|
|
14
14
|
*
|
|
15
15
|
* Checks if Digital Credentials API feature is supported for the current browser.
|
|
16
16
|
*
|
|
17
|
-
* @returns boolean
|
|
17
|
+
* @returns boolean
|
|
18
18
|
*/
|
|
19
19
|
export declare const isDigitalCredentialsApiSupported: () => boolean;
|
|
20
|
+
export type DigitalCredentialsApiSupport = {
|
|
21
|
+
supported: boolean;
|
|
22
|
+
/** MATTR VII & browser supported protocols */
|
|
23
|
+
protocols?: string[];
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Determines DC-API support for the current browser, narrowed to the protocols it accepts.
|
|
27
|
+
*
|
|
28
|
+
* @ignore - Internal method
|
|
29
|
+
*/
|
|
30
|
+
export declare const getDigitalCredentialsApiSupport: (apiBaseUrl: string) => Promise<DigitalCredentialsApiSupport>;
|
|
@@ -329,6 +329,18 @@ export type RequestCredentialsWithDcApiOptions = {
|
|
|
329
329
|
challenge: string;
|
|
330
330
|
request: Record<string, unknown>;
|
|
331
331
|
};
|
|
332
|
+
export type VerifierConfiguration = v.InferOutput<typeof VerifierConfigurationValidator>;
|
|
333
|
+
export declare const VerifierConfigurationValidator: v.ObjectSchema<{
|
|
334
|
+
readonly dcApi: v.ObjectSchema<{
|
|
335
|
+
/**
|
|
336
|
+
* DC-API protocols that MATTR VII supports.
|
|
337
|
+
*
|
|
338
|
+
* Typed as plain strings rather than a known strict set, since the list is fetched from MATTR VII
|
|
339
|
+
* at runtime and a fixed set here could introduce version mismatches between an SDK release
|
|
340
|
+
*/
|
|
341
|
+
readonly protocols: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
342
|
+
}, undefined>;
|
|
343
|
+
}, undefined>;
|
|
332
344
|
export type CreateSessionRequest = v.InferOutput<typeof CreateSessionRequestValidator>;
|
|
333
345
|
export declare const CreateSessionRequestValidator: v.ObjectSchema<{
|
|
334
346
|
readonly credentialQuery: v.ArraySchema<v.ObjectSchema<{
|
|
@@ -341,7 +353,15 @@ export declare const CreateSessionRequestValidator: v.ObjectSchema<{
|
|
|
341
353
|
readonly challenge: v.StringSchema<undefined>;
|
|
342
354
|
readonly redirectUri: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
343
355
|
readonly walletProviderId: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
356
|
+
/** Indicates if DC-API is supported in the browser */
|
|
344
357
|
readonly dcApiSupported: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
358
|
+
/**
|
|
359
|
+
* DC-API request protocols that MATTR VII supports & the browser accepts.
|
|
360
|
+
*
|
|
361
|
+
* Typed as plain strings rather than a known strict set, since the list is fetched from MATTR VII
|
|
362
|
+
* at runtime and a fixed set here could introduce version mismatches between an SDK release
|
|
363
|
+
*/
|
|
364
|
+
readonly dcApiProtocols: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
|
|
345
365
|
readonly state: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
346
366
|
}, undefined>;
|
|
347
367
|
export type CreateSessionResponse = v.InferOutput<typeof CreateSessionResponseValidator>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Result } from "neverthrow";
|
|
2
2
|
import { SafeFetchValidateResponseError } from "../common/safeFetch";
|
|
3
|
-
import { CreateSessionRequest, ExchangeSessionResultResponse, GetSessionStatusRequest, GetSessionStatusResponse, AbortSessionRequest, InitializeOptions, CreateSessionResponse } from "./types";
|
|
3
|
+
import { CreateSessionRequest, ExchangeSessionResultResponse, GetSessionStatusRequest, GetSessionStatusResponse, AbortSessionRequest, InitializeOptions, CreateSessionResponse, VerifierConfiguration } from "./types";
|
|
4
4
|
/**
|
|
5
5
|
* Generates a challenge string using the window.crypto API.
|
|
6
6
|
*
|
|
@@ -15,6 +15,14 @@ export declare const generateChallenge: () => string;
|
|
|
15
15
|
* @returns The value of the specified parameter, or null if the parameter is not found.
|
|
16
16
|
*/
|
|
17
17
|
export declare const getHashParamValue: (hash: string, param: string) => string | null;
|
|
18
|
+
/**
|
|
19
|
+
* Fetches the verifier configuration MATTR VII advertises, including the DC-API protocols it
|
|
20
|
+
* can serve.
|
|
21
|
+
*
|
|
22
|
+
* @param uri - The base URL of the API.
|
|
23
|
+
* @returns A promise that resolves to a result containing either the verifier configuration or an error.
|
|
24
|
+
*/
|
|
25
|
+
export declare const getVerifierConfiguration: (uri: string) => Promise<Result<VerifierConfiguration, SafeFetchValidateResponseError>>;
|
|
18
26
|
/**
|
|
19
27
|
* Creates a new session with the provided parameters.
|
|
20
28
|
*
|
|
@@ -26,7 +34,7 @@ export declare const getHashParamValue: (hash: string, param: string) => string
|
|
|
26
34
|
* @param walletProviderId - optional, The ID of the wallet provider, if not provided the default wallet provider will be used.
|
|
27
35
|
* @returns A promise that resolves to a result containing either the created session response or an error.
|
|
28
36
|
*/
|
|
29
|
-
export declare const createSession: ({ credentialQuery, challenge, redirectUri, apiBaseUrl, walletProviderId, dcApiSupported, applicationId, state, }: CreateSessionRequest & InitializeOptions) => Promise<Result<CreateSessionResponse, SafeFetchValidateResponseError>>;
|
|
37
|
+
export declare const createSession: ({ credentialQuery, challenge, redirectUri, apiBaseUrl, walletProviderId, dcApiSupported, dcApiProtocols, applicationId, state, }: CreateSessionRequest & InitializeOptions) => Promise<Result<CreateSessionResponse, SafeFetchValidateResponseError>>;
|
|
30
38
|
/**
|
|
31
39
|
* Abort a session with the provided parameters.
|
|
32
40
|
*
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Do Not Translate or Localize
|
|
8
8
|
*
|
|
9
9
|
* Bundle of @mattrglobal/verifier-sdk-web
|
|
10
|
-
* Generated: 2026-
|
|
10
|
+
* Generated: 2026-10-12
|
|
11
11
|
* Version: 2.3.0
|
|
12
12
|
* Dependencies:
|
|
13
13
|
*
|
|
@@ -1350,12 +1350,18 @@
|
|
|
1350
1350
|
SessionType["DigitalCredentialsApi"] = "digital-credentials-api";
|
|
1351
1351
|
SessionType["Openid4vp"] = "openid4vp";
|
|
1352
1352
|
})(SessionType || (SessionType = {}));
|
|
1353
|
+
const VerifierConfigurationValidator = object({
|
|
1354
|
+
dcApi: object({
|
|
1355
|
+
protocols: array(string())
|
|
1356
|
+
})
|
|
1357
|
+
});
|
|
1353
1358
|
object({
|
|
1354
1359
|
credentialQuery: array(CredentialQueryValidator),
|
|
1355
1360
|
challenge: string(),
|
|
1356
1361
|
redirectUri: optional(string()),
|
|
1357
1362
|
walletProviderId: optional(string()),
|
|
1358
1363
|
dcApiSupported: optional(_boolean()),
|
|
1364
|
+
dcApiProtocols: optional(array(string())),
|
|
1359
1365
|
state: optional(pipe(string(), minLength(1)))
|
|
1360
1366
|
});
|
|
1361
1367
|
const CreateSessionDigitalCredentialsValidator = object({
|
|
@@ -1617,18 +1623,40 @@
|
|
|
1617
1623
|
const urlParams = new URLSearchParams(hash.split("#")[1]);
|
|
1618
1624
|
return urlParams.get(param);
|
|
1619
1625
|
};
|
|
1620
|
-
const
|
|
1626
|
+
const getVerifierConfiguration = async uri => {
|
|
1627
|
+
const responseResult = await safeFetch(`${uri}/v2/presentations/web/configuration`, {
|
|
1628
|
+
method: "GET",
|
|
1629
|
+
headers: {
|
|
1630
|
+
"Content-Type": "application/json"
|
|
1631
|
+
}
|
|
1632
|
+
});
|
|
1633
|
+
if (responseResult.isErr()) {
|
|
1634
|
+
return err(responseResult.error);
|
|
1635
|
+
}
|
|
1636
|
+
const body = await responseResult.value.json().catch((() => undefined));
|
|
1637
|
+
if (!isType(VerifierConfigurationValidator)(body)) {
|
|
1638
|
+
return err({
|
|
1639
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
1640
|
+
message: "Verifier configuration returned unsupported response"
|
|
1641
|
+
});
|
|
1642
|
+
}
|
|
1643
|
+
return ok(body);
|
|
1644
|
+
};
|
|
1645
|
+
const createSession = async ({credentialQuery: credentialQuery, challenge: challenge, redirectUri: redirectUri, apiBaseUrl: apiBaseUrl, walletProviderId: walletProviderId, dcApiSupported: dcApiSupported, dcApiProtocols: dcApiProtocols, applicationId: applicationId, state: state}) => {
|
|
1621
1646
|
const openid4vpConfiguration = !!walletProviderId || !!redirectUri ? {
|
|
1622
1647
|
redirectUri: redirectUri,
|
|
1623
1648
|
walletProviderId: walletProviderId
|
|
1624
1649
|
} : undefined;
|
|
1625
|
-
const postData = Object.assign({
|
|
1650
|
+
const postData = Object.assign(Object.assign(Object.assign({
|
|
1626
1651
|
credentialQuery: credentialQuery,
|
|
1627
1652
|
challenge: challenge,
|
|
1628
1653
|
applicationId: applicationId,
|
|
1629
|
-
dcApiSupported: dcApiSupported
|
|
1654
|
+
dcApiSupported: dcApiSupported
|
|
1655
|
+
}, dcApiProtocols !== undefined ? {
|
|
1656
|
+
dcApiProtocols: dcApiProtocols
|
|
1657
|
+
} : {}), {
|
|
1630
1658
|
openid4vpConfiguration: openid4vpConfiguration
|
|
1631
|
-
}, state !== undefined ? {
|
|
1659
|
+
}), state !== undefined ? {
|
|
1632
1660
|
state: state
|
|
1633
1661
|
} : {});
|
|
1634
1662
|
const responseResult = await safeFetch(`${apiBaseUrl}/v2/presentations/web/sessions`, {
|
|
@@ -2054,9 +2082,43 @@
|
|
|
2054
2082
|
}
|
|
2055
2083
|
return ok(credentialVerificationResponse);
|
|
2056
2084
|
};
|
|
2057
|
-
const
|
|
2058
|
-
var _a;
|
|
2059
|
-
return "DigitalCredential" in
|
|
2085
|
+
const digitalCredentialsApiSupported = target => {
|
|
2086
|
+
var _a, _b;
|
|
2087
|
+
return "DigitalCredential" in target && typeof ((_b = (_a = target.navigator) === null || _a === void 0 ? void 0 : _a.credentials) === null || _b === void 0 ? void 0 : _b.get) === "function" && typeof target.DigitalCredential === "function" && (!("userAgentAllowsProtocol" in target.DigitalCredential) || typeof target.DigitalCredential.userAgentAllowsProtocol === "function");
|
|
2088
|
+
};
|
|
2089
|
+
const isDigitalCredentialsApiSupported = () => digitalCredentialsApiSupported(window);
|
|
2090
|
+
const getDigitalCredentialsApiSupport = async apiBaseUrl => {
|
|
2091
|
+
if (!digitalCredentialsApiSupported(window)) {
|
|
2092
|
+
return {
|
|
2093
|
+
supported: false
|
|
2094
|
+
};
|
|
2095
|
+
}
|
|
2096
|
+
const {DigitalCredential: digitalCredential} = window;
|
|
2097
|
+
if (!digitalCredential.userAgentAllowsProtocol) {
|
|
2098
|
+
return {
|
|
2099
|
+
supported: true
|
|
2100
|
+
};
|
|
2101
|
+
}
|
|
2102
|
+
const configurationResult = await getVerifierConfiguration(apiBaseUrl);
|
|
2103
|
+
if (configurationResult.isErr()) {
|
|
2104
|
+
return {
|
|
2105
|
+
supported: true
|
|
2106
|
+
};
|
|
2107
|
+
}
|
|
2108
|
+
const protocols = configurationResult.value.dcApi.protocols.filter((protocol => {
|
|
2109
|
+
var _a;
|
|
2110
|
+
try {
|
|
2111
|
+
return ((_a = digitalCredential.userAgentAllowsProtocol) === null || _a === void 0 ? void 0 : _a.call(digitalCredential, protocol)) === true;
|
|
2112
|
+
} catch (_b) {
|
|
2113
|
+
return false;
|
|
2114
|
+
}
|
|
2115
|
+
}));
|
|
2116
|
+
return protocols.length > 0 ? {
|
|
2117
|
+
supported: true,
|
|
2118
|
+
protocols: protocols
|
|
2119
|
+
} : {
|
|
2120
|
+
supported: false
|
|
2121
|
+
};
|
|
2060
2122
|
};
|
|
2061
2123
|
const sleep = ms => new Promise((resolve => setTimeout(resolve, ms)));
|
|
2062
2124
|
const SESSION_STATUS_POLLING_MAX_RETRY = 1e3;
|
|
@@ -2130,7 +2192,7 @@
|
|
|
2130
2192
|
assertType(RequestCredentialsOptionsValidator, "Invalid request credential options")(options);
|
|
2131
2193
|
const {apiBaseUrl: apiBaseUrl, applicationId: applicationId} = initializeOptions;
|
|
2132
2194
|
const {challenge: challenge = generateChallenge(), credentialQuery: credentialQuery, openid4vpConfiguration: openid4vpConfiguration, state: state, onPresentationRequest: onPresentationRequest} = options;
|
|
2133
|
-
const
|
|
2195
|
+
const dcApiSupport = await getDigitalCredentialsApiSupport(apiBaseUrl);
|
|
2134
2196
|
const openId4VpRedirectUri = deriveOpenId4vpRedirectUri(openid4vpConfiguration);
|
|
2135
2197
|
const createSessionResult = await createSession({
|
|
2136
2198
|
credentialQuery: credentialQuery,
|
|
@@ -2139,7 +2201,8 @@
|
|
|
2139
2201
|
walletProviderId: (_a = openid4vpConfiguration === null || openid4vpConfiguration === void 0 ? void 0 : openid4vpConfiguration.walletProviderId) !== null && _a !== void 0 ? _a : undefined,
|
|
2140
2202
|
apiBaseUrl: apiBaseUrl,
|
|
2141
2203
|
applicationId: applicationId,
|
|
2142
|
-
dcApiSupported:
|
|
2204
|
+
dcApiSupported: dcApiSupport.supported,
|
|
2205
|
+
dcApiProtocols: dcApiSupport.protocols,
|
|
2143
2206
|
state: state
|
|
2144
2207
|
});
|
|
2145
2208
|
if (createSessionResult.isErr()) {
|