@orangecheck/me-client 0.62.0 → 0.64.0
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/CHANGELOG.md +84 -0
- package/README.md +2 -1
- package/dist/button-auto.js +65 -15
- package/dist/button-auto.js.map +1 -1
- package/dist/button-auto.mjs +65 -15
- package/dist/button-auto.mjs.map +1 -1
- package/dist/button.css +4 -4
- package/dist/button.js +65 -15
- package/dist/button.js.map +1 -1
- package/dist/button.mjs +65 -15
- package/dist/button.mjs.map +1 -1
- package/dist/index.d.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +65 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -10
- package/dist/index.mjs.map +1 -1
- package/dist/{integrator-BiJgTlse.d.mts → integrator-DDLwyj8-.d.mts} +4 -0
- package/dist/{integrator-BiJgTlse.d.ts → integrator-DDLwyj8-.d.ts} +4 -0
- package/dist/integrator.d.mts +1 -1
- package/dist/integrator.d.ts +1 -1
- package/dist/integrator.js.map +1 -1
- package/dist/integrator.mjs.map +1 -1
- package/dist/react.js +71 -20
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +71 -20
- package/dist/react.mjs.map +1 -1
- package/dist/server.d.mts +4 -3
- package/dist/server.d.ts +4 -3
- package/dist/server.js +25 -27
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +25 -27
- package/dist/server.mjs.map +1 -1
- package/package.json +3 -3
package/dist/server.mjs
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { verifyOcToken as verifyOcToken$1, checkOcToken as checkOcToken$1, readOcSessionToken, SAFE_METHODS, readBondNeed, familyRevocationCheck, integratorRevocationCheck, bondMeets, readBondClaim } from '@orangecheck/auth-core';
|
|
2
2
|
export { bondMeets, readBondClaim, readBondNeed } from '@orangecheck/auth-core';
|
|
3
|
+
import { parseIssuerOrigin, ISSUER_ORIGIN_RULE } from '@orangecheck/auth-core/issuer-origin';
|
|
3
4
|
import { isDidOc } from '@orangecheck/auth-core/identifiers';
|
|
4
5
|
|
|
5
6
|
var __defProp = Object.defineProperty;
|
|
6
7
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
8
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
9
|
+
function issuerOrigin(value, what) {
|
|
10
|
+
const origin = parseIssuerOrigin(value);
|
|
11
|
+
if (origin === null) {
|
|
12
|
+
throw new TypeError(`@orangecheck/me-client: ${what} must be ${ISSUER_ORIGIN_RULE}; got ${JSON.stringify(value)}`);
|
|
13
|
+
}
|
|
14
|
+
return origin;
|
|
15
|
+
}
|
|
8
16
|
|
|
9
17
|
// src/own-options.ts
|
|
10
18
|
function inheritedKeys(opts, known) {
|
|
@@ -305,8 +313,6 @@ async function importJWK(jwk, alg, options) {
|
|
|
305
313
|
throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
|
|
306
314
|
}
|
|
307
315
|
}
|
|
308
|
-
|
|
309
|
-
// src/identity.ts
|
|
310
316
|
var DEFAULT_ISSUER = "https://me.ochk.io";
|
|
311
317
|
var DEFAULT_TTL_MS = 60 * 60 * 1e3;
|
|
312
318
|
var DEFAULT_MAX_STALE_MS = 6 * 60 * 60 * 1e3;
|
|
@@ -506,7 +512,12 @@ async function verifyActivityAttestation(bundle, options = {}) {
|
|
|
506
512
|
return { ok: false, reason: "provided jwk failed import", checks };
|
|
507
513
|
}
|
|
508
514
|
} else {
|
|
509
|
-
const issuer = options.issuer ?? DEFAULT_ISSUER;
|
|
515
|
+
const issuer = parseIssuerOrigin(options.issuer ?? DEFAULT_ISSUER);
|
|
516
|
+
if (issuer === null) {
|
|
517
|
+
const reason = `issuer must be ${ISSUER_ORIGIN_RULE}`;
|
|
518
|
+
checks.push({ ok: false, label: "JWK with matching kid present", detail: reason });
|
|
519
|
+
return { ok: false, reason, checks };
|
|
520
|
+
}
|
|
510
521
|
const ttl = options.jwksCacheTtlMs ?? DEFAULT_TTL_MS;
|
|
511
522
|
const maxStale = options.jwksMaxStaleMs ?? DEFAULT_MAX_STALE_MS;
|
|
512
523
|
try {
|
|
@@ -566,8 +577,9 @@ async function verifyActivityAttestation(bundle, options = {}) {
|
|
|
566
577
|
return { ok: true, attestation: signed, checks };
|
|
567
578
|
}
|
|
568
579
|
async function refreshEnvelopeJwks(issuer = DEFAULT_ISSUER) {
|
|
569
|
-
|
|
570
|
-
|
|
580
|
+
const origin = issuerOrigin(issuer, "refreshEnvelopeJwks: issuer");
|
|
581
|
+
jwksCache.delete(origin);
|
|
582
|
+
await fetchEnvelopeJwks(origin, DEFAULT_TTL_MS);
|
|
571
583
|
}
|
|
572
584
|
var identity = {
|
|
573
585
|
verifyActivityAttestation,
|
|
@@ -774,23 +786,6 @@ function spendOnce(jti, exp, store) {
|
|
|
774
786
|
});
|
|
775
787
|
}
|
|
776
788
|
var REVOKE_OPTIONS = /* @__PURE__ */ new Set(["issuer", "timeoutMs"]);
|
|
777
|
-
function issuerOrigin(issuer, where = "revokeToken") {
|
|
778
|
-
if (typeof issuer !== "string") fail2(`${where}: issuer must be a URL`);
|
|
779
|
-
const refuse = () => fail2(`${where}: issuer must be one https origin (http only on this machine), such as https://ochk.io, got ${issuer}`);
|
|
780
|
-
if (/[?#@\\]/.test(issuer)) refuse();
|
|
781
|
-
let url;
|
|
782
|
-
try {
|
|
783
|
-
url = new URL(issuer);
|
|
784
|
-
} catch {
|
|
785
|
-
return refuse();
|
|
786
|
-
}
|
|
787
|
-
const local = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
|
|
788
|
-
if (url.protocol !== "https:" && !(url.protocol === "http:" && local)) refuse();
|
|
789
|
-
if (url.pathname !== "/" || url.search !== "" || url.hash !== "" || url.username !== "" || url.password !== "") {
|
|
790
|
-
refuse();
|
|
791
|
-
}
|
|
792
|
-
return url.origin;
|
|
793
|
-
}
|
|
794
789
|
function revokeToken(token, options = {}) {
|
|
795
790
|
if (options === null || typeof options !== "object") fail2("revokeToken: options must be an object");
|
|
796
791
|
const unknown = Object.keys(options).filter((k) => !REVOKE_OPTIONS.has(k));
|
|
@@ -803,7 +798,7 @@ function revokeToken(token, options = {}) {
|
|
|
803
798
|
if (!tokens || tokens.length < 1 || tokens.length > MAX_TOKENS || !tokens.every((t) => typeof t === "string" && t.length > 0 && t.length <= MAX_TOKEN_LENGTH)) {
|
|
804
799
|
fail2(`revokeToken: pass one token, or 1 to ${MAX_TOKENS}, each a non-empty string of at most ${MAX_TOKEN_LENGTH} characters`);
|
|
805
800
|
}
|
|
806
|
-
const origin = issuerOrigin(options.issuer ?? DEFAULT_ISSUER2);
|
|
801
|
+
const origin = issuerOrigin(options.issuer ?? DEFAULT_ISSUER2, "revokeToken: issuer");
|
|
807
802
|
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS2;
|
|
808
803
|
if (typeof timeoutMs !== "number" || !(timeoutMs > 0 && timeoutMs <= MAX_TIMEOUT_MS2)) {
|
|
809
804
|
fail2(`revokeToken: timeoutMs must be above 0 and at most ${MAX_TIMEOUT_MS2}`);
|
|
@@ -885,7 +880,8 @@ async function exchangeNativeCode(input, options = {}) {
|
|
|
885
880
|
if (typeof projectKey !== "string" || projectKey.length === 0 || projectKey.length > MAX_FIELD_LENGTH) {
|
|
886
881
|
fail3("needs your project key: options.projectKey, or OC_PROJECT_KEY");
|
|
887
882
|
}
|
|
888
|
-
const issuer = issuerOrigin(options.issuer ?? DEFAULT_ISSUER3, "exchangeNativeCode");
|
|
883
|
+
const issuer = issuerOrigin(options.issuer ?? DEFAULT_ISSUER3, "exchangeNativeCode: issuer");
|
|
884
|
+
const meOrigin = options.meOrigin === void 0 ? void 0 : issuerOrigin(options.meOrigin, "exchangeNativeCode: meOrigin");
|
|
889
885
|
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS3;
|
|
890
886
|
if (typeof timeoutMs !== "number" || !(timeoutMs > 0 && timeoutMs <= MAX_TIMEOUT_MS3)) {
|
|
891
887
|
fail3(`timeoutMs must be above 0 and at most ${MAX_TIMEOUT_MS3}`);
|
|
@@ -896,7 +892,7 @@ async function exchangeNativeCode(input, options = {}) {
|
|
|
896
892
|
const verified = await checkOcToken(token, { audience: input.audience, issuer });
|
|
897
893
|
if (verified.status === "unavailable") return { status: "unavailable", reason: "key_set_unavailable" };
|
|
898
894
|
if (verified.status === "invalid") return { status: "invalid", reason: verified.reason ?? "invalid_token" };
|
|
899
|
-
const where =
|
|
895
|
+
const where = meOrigin ? { meOrigin } : {};
|
|
900
896
|
const checked = await checkOcSession(
|
|
901
897
|
{ authorization: `Bearer ${token}` },
|
|
902
898
|
{
|
|
@@ -1041,7 +1037,7 @@ async function checkOcToken(token, options = {}) {
|
|
|
1041
1037
|
checkRequireHandle(requireHandle);
|
|
1042
1038
|
const checked = await checkOcToken$1(token, core);
|
|
1043
1039
|
if (checked.status === "unavailable") return { status: "unavailable", reason: "key_set_unavailable" };
|
|
1044
|
-
if (checked.status === "invalid") return { status: "invalid" };
|
|
1040
|
+
if (checked.status === "invalid") return checked.reason ? { status: "invalid", reason: checked.reason } : { status: "invalid" };
|
|
1045
1041
|
if (lacksHandle(checked.session, requireHandle)) {
|
|
1046
1042
|
warnNoHandle(checked.session);
|
|
1047
1043
|
return { status: "invalid", reason: "no_session_handle" };
|
|
@@ -1186,6 +1182,8 @@ function checkOptions(options) {
|
|
|
1186
1182
|
);
|
|
1187
1183
|
}
|
|
1188
1184
|
refuseInherited("", options, KNOWN_OPTIONS);
|
|
1185
|
+
if (options.issuer !== void 0) issuerOrigin(options.issuer, "issuer");
|
|
1186
|
+
if (options.meOrigin !== void 0) issuerOrigin(options.meOrigin, "meOrigin");
|
|
1189
1187
|
checkRequireHandle(options.requireHandle);
|
|
1190
1188
|
const bond = options.requireBond;
|
|
1191
1189
|
if (bond === void 0) return;
|
|
@@ -1229,7 +1227,7 @@ function standing(slot) {
|
|
|
1229
1227
|
return hit?.at && since(hit.at) < POLICY_MAX_STALE_MS ? hit.need : void 0;
|
|
1230
1228
|
}
|
|
1231
1229
|
async function projectRequirement(options) {
|
|
1232
|
-
const base = (options.meOrigin ?? "https://me.ochk.io"
|
|
1230
|
+
const base = issuerOrigin(options.meOrigin ?? "https://me.ochk.io", "meOrigin");
|
|
1233
1231
|
const key = options.projectKey;
|
|
1234
1232
|
const slot = `${base} ${key}`;
|
|
1235
1233
|
const unknownAt = unknownKeys.get(slot);
|