pendra 0.12.0 → 0.12.2
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.d.mts +28 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +51 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -602,6 +602,23 @@ declare class PrivateInferenceEngine {
|
|
|
602
602
|
cachedOrgPublicKeys(): Uint8Array[] | null;
|
|
603
603
|
cachedOrgPublicKey(): Uint8Array | null;
|
|
604
604
|
private tofuIdentity;
|
|
605
|
+
/**
|
|
606
|
+
* Drop the cached key set so the next call re-fetches it.
|
|
607
|
+
*
|
|
608
|
+
* The cache is otherwise held for the whole process lifetime, which is
|
|
609
|
+
* correct while a fleet keeps one key but fatal when it re-keys: a
|
|
610
|
+
* long-running server would go on sealing to a fingerprint no worker holds
|
|
611
|
+
* and fail EVERY request until someone restarted it. The API signals a re-key
|
|
612
|
+
* with `X-Pendra-Error-Code: no_private_inference_worker`, and this is what
|
|
613
|
+
* lets the client recover on its own.
|
|
614
|
+
*
|
|
615
|
+
* Pinned clients are deliberately NOT re-fetched on that signal — a pin is an
|
|
616
|
+
* allowlist, so a fetch could only return fingerprints the pin already
|
|
617
|
+
* rejects. They surface the error instead, which is what pinning means.
|
|
618
|
+
*/
|
|
619
|
+
invalidateOrgKey(): void;
|
|
620
|
+
/** Whether this client seals only to an explicit fingerprint allowlist. */
|
|
621
|
+
get isPinned(): boolean;
|
|
605
622
|
/**
|
|
606
623
|
* Validate the key(s) returned by GET /v1/private-inference/key, apply the pin
|
|
607
624
|
* allowlist (or auto-trust TOFU), cache the accepted public keys, and return
|
|
@@ -682,6 +699,17 @@ declare class Pendra {
|
|
|
682
699
|
response: Response;
|
|
683
700
|
controller: AbortController;
|
|
684
701
|
}>;
|
|
702
|
+
/**
|
|
703
|
+
* Drop the cached encryption keys when the API reports that no worker holds
|
|
704
|
+
* the one this request was sealed to — the signal that the org's fleet has
|
|
705
|
+
* re-keyed. Returns true if the cache was dropped.
|
|
706
|
+
*
|
|
707
|
+
* A PINNED client is left alone on purpose: a pin is an allowlist, so
|
|
708
|
+
* re-fetching could only return fingerprints the pin already rejects and
|
|
709
|
+
* would loop rather than recover. The error surfaces instead, which is
|
|
710
|
+
* exactly what pinning is for.
|
|
711
|
+
*/
|
|
712
|
+
private invalidateKeyCacheIfRekeyed;
|
|
685
713
|
}
|
|
686
714
|
|
|
687
715
|
declare class APIError extends Error {
|
package/dist/index.d.ts
CHANGED
|
@@ -602,6 +602,23 @@ declare class PrivateInferenceEngine {
|
|
|
602
602
|
cachedOrgPublicKeys(): Uint8Array[] | null;
|
|
603
603
|
cachedOrgPublicKey(): Uint8Array | null;
|
|
604
604
|
private tofuIdentity;
|
|
605
|
+
/**
|
|
606
|
+
* Drop the cached key set so the next call re-fetches it.
|
|
607
|
+
*
|
|
608
|
+
* The cache is otherwise held for the whole process lifetime, which is
|
|
609
|
+
* correct while a fleet keeps one key but fatal when it re-keys: a
|
|
610
|
+
* long-running server would go on sealing to a fingerprint no worker holds
|
|
611
|
+
* and fail EVERY request until someone restarted it. The API signals a re-key
|
|
612
|
+
* with `X-Pendra-Error-Code: no_private_inference_worker`, and this is what
|
|
613
|
+
* lets the client recover on its own.
|
|
614
|
+
*
|
|
615
|
+
* Pinned clients are deliberately NOT re-fetched on that signal — a pin is an
|
|
616
|
+
* allowlist, so a fetch could only return fingerprints the pin already
|
|
617
|
+
* rejects. They surface the error instead, which is what pinning means.
|
|
618
|
+
*/
|
|
619
|
+
invalidateOrgKey(): void;
|
|
620
|
+
/** Whether this client seals only to an explicit fingerprint allowlist. */
|
|
621
|
+
get isPinned(): boolean;
|
|
605
622
|
/**
|
|
606
623
|
* Validate the key(s) returned by GET /v1/private-inference/key, apply the pin
|
|
607
624
|
* allowlist (or auto-trust TOFU), cache the accepted public keys, and return
|
|
@@ -682,6 +699,17 @@ declare class Pendra {
|
|
|
682
699
|
response: Response;
|
|
683
700
|
controller: AbortController;
|
|
684
701
|
}>;
|
|
702
|
+
/**
|
|
703
|
+
* Drop the cached encryption keys when the API reports that no worker holds
|
|
704
|
+
* the one this request was sealed to — the signal that the org's fleet has
|
|
705
|
+
* re-keyed. Returns true if the cache was dropped.
|
|
706
|
+
*
|
|
707
|
+
* A PINNED client is left alone on purpose: a pin is an allowlist, so
|
|
708
|
+
* re-fetching could only return fingerprints the pin already rejects and
|
|
709
|
+
* would loop rather than recover. The error surfaces instead, which is
|
|
710
|
+
* exactly what pinning is for.
|
|
711
|
+
*/
|
|
712
|
+
private invalidateKeyCacheIfRekeyed;
|
|
685
713
|
}
|
|
686
714
|
|
|
687
715
|
declare class APIError extends Error {
|
package/dist/index.js
CHANGED
|
@@ -666,6 +666,10 @@ var Rerank = class {
|
|
|
666
666
|
}
|
|
667
667
|
};
|
|
668
668
|
|
|
669
|
+
// src/version.ts
|
|
670
|
+
var VERSION = "0.12.2";
|
|
671
|
+
var USER_AGENT = `pendra-node/${VERSION}`;
|
|
672
|
+
|
|
669
673
|
// src/_hpke.ts
|
|
670
674
|
var import_ed25519 = require("@noble/curves/ed25519.js");
|
|
671
675
|
var import_chacha = require("@noble/ciphers/chacha.js");
|
|
@@ -1059,6 +1063,27 @@ var PrivateInferenceEngine = class {
|
|
|
1059
1063
|
const digest = sha256Hex(new TextEncoder().encode(this.apiKey)).slice(0, 16);
|
|
1060
1064
|
return `${this.baseUrl}|${digest}`;
|
|
1061
1065
|
}
|
|
1066
|
+
/**
|
|
1067
|
+
* Drop the cached key set so the next call re-fetches it.
|
|
1068
|
+
*
|
|
1069
|
+
* The cache is otherwise held for the whole process lifetime, which is
|
|
1070
|
+
* correct while a fleet keeps one key but fatal when it re-keys: a
|
|
1071
|
+
* long-running server would go on sealing to a fingerprint no worker holds
|
|
1072
|
+
* and fail EVERY request until someone restarted it. The API signals a re-key
|
|
1073
|
+
* with `X-Pendra-Error-Code: no_private_inference_worker`, and this is what
|
|
1074
|
+
* lets the client recover on its own.
|
|
1075
|
+
*
|
|
1076
|
+
* Pinned clients are deliberately NOT re-fetched on that signal — a pin is an
|
|
1077
|
+
* allowlist, so a fetch could only return fingerprints the pin already
|
|
1078
|
+
* rejects. They surface the error instead, which is what pinning means.
|
|
1079
|
+
*/
|
|
1080
|
+
invalidateOrgKey() {
|
|
1081
|
+
this.orgPubs = null;
|
|
1082
|
+
}
|
|
1083
|
+
/** Whether this client seals only to an explicit fingerprint allowlist. */
|
|
1084
|
+
get isPinned() {
|
|
1085
|
+
return this.pinnedFingerprints !== null;
|
|
1086
|
+
}
|
|
1062
1087
|
/**
|
|
1063
1088
|
* Validate the key(s) returned by GET /v1/private-inference/key, apply the pin
|
|
1064
1089
|
* allowlist (or auto-trust TOFU), cache the accepted public keys, and return
|
|
@@ -1071,7 +1096,7 @@ var PrivateInferenceEngine = class {
|
|
|
1071
1096
|
if (this.orgPubs !== null) return this.orgPubs;
|
|
1072
1097
|
if (!fetchedKeys || fetchedKeys.length === 0) {
|
|
1073
1098
|
throw new PrivateInferenceError(
|
|
1074
|
-
"No
|
|
1099
|
+
"No encryption key is registered for this organisation. Start a worker and it will be issued one automatically."
|
|
1075
1100
|
);
|
|
1076
1101
|
}
|
|
1077
1102
|
const pubs = [];
|
|
@@ -1097,7 +1122,7 @@ var PrivateInferenceEngine = class {
|
|
|
1097
1122
|
if (accepted.length === 0) {
|
|
1098
1123
|
const pinned = Array.from(this.pinnedFingerprints).sort().join(", ");
|
|
1099
1124
|
throw new PrivateInferenceError(
|
|
1100
|
-
`None of the org's workload key fingerprints (${fps.join(", ")}) match your pinned fingerprint(s) (${pinned}). Refusing to seal (possible man-in-the-middle).
|
|
1125
|
+
`None of the org's workload key fingerprints (${fps.join(", ")}) match your pinned fingerprint(s) (${pinned}). Refusing to seal (possible man-in-the-middle). If your fleet re-keyed \u2014 which happens when every worker goes offline at once \u2014 update the pin to a current fingerprint from the console.`
|
|
1101
1126
|
);
|
|
1102
1127
|
}
|
|
1103
1128
|
} else {
|
|
@@ -1271,7 +1296,7 @@ var Pendra = class {
|
|
|
1271
1296
|
try {
|
|
1272
1297
|
response = await fetch(url, {
|
|
1273
1298
|
method: "GET",
|
|
1274
|
-
headers: { Authorization: `Bearer ${this.apiKey}
|
|
1299
|
+
headers: { Authorization: `Bearer ${this.apiKey}`, "User-Agent": USER_AGENT },
|
|
1275
1300
|
signal: controller.signal
|
|
1276
1301
|
});
|
|
1277
1302
|
} catch (err) {
|
|
@@ -1286,7 +1311,7 @@ var Pendra = class {
|
|
|
1286
1311
|
}
|
|
1287
1312
|
if (response.status === 404) {
|
|
1288
1313
|
throw new PrivateInferenceError(
|
|
1289
|
-
"No
|
|
1314
|
+
"No encryption key is registered for this organisation. Start a worker and it will be issued one automatically."
|
|
1290
1315
|
);
|
|
1291
1316
|
}
|
|
1292
1317
|
if (!response.ok) {
|
|
@@ -1311,6 +1336,7 @@ var Pendra = class {
|
|
|
1311
1336
|
const headers = {
|
|
1312
1337
|
Authorization: `Bearer ${this.apiKey}`,
|
|
1313
1338
|
"Content-Type": "application/json",
|
|
1339
|
+
"User-Agent": USER_AGENT,
|
|
1314
1340
|
...options.headers ?? {}
|
|
1315
1341
|
};
|
|
1316
1342
|
let response;
|
|
@@ -1337,6 +1363,7 @@ var Pendra = class {
|
|
|
1337
1363
|
}
|
|
1338
1364
|
if (!response.ok) {
|
|
1339
1365
|
clearTimeout(timeoutId);
|
|
1366
|
+
this.invalidateKeyCacheIfRekeyed(response);
|
|
1340
1367
|
let message;
|
|
1341
1368
|
try {
|
|
1342
1369
|
const body = await response.json();
|
|
@@ -1350,6 +1377,26 @@ var Pendra = class {
|
|
|
1350
1377
|
}
|
|
1351
1378
|
return { response, controller };
|
|
1352
1379
|
}
|
|
1380
|
+
/**
|
|
1381
|
+
* Drop the cached encryption keys when the API reports that no worker holds
|
|
1382
|
+
* the one this request was sealed to — the signal that the org's fleet has
|
|
1383
|
+
* re-keyed. Returns true if the cache was dropped.
|
|
1384
|
+
*
|
|
1385
|
+
* A PINNED client is left alone on purpose: a pin is an allowlist, so
|
|
1386
|
+
* re-fetching could only return fingerprints the pin already rejects and
|
|
1387
|
+
* would loop rather than recover. The error surfaces instead, which is
|
|
1388
|
+
* exactly what pinning is for.
|
|
1389
|
+
*/
|
|
1390
|
+
invalidateKeyCacheIfRekeyed(response) {
|
|
1391
|
+
const engine = this._piEngine;
|
|
1392
|
+
if (!engine || engine.isPinned) return false;
|
|
1393
|
+
if (response.headers?.get("X-Pendra-Error-Code") !== "no_private_inference_worker") {
|
|
1394
|
+
return false;
|
|
1395
|
+
}
|
|
1396
|
+
engine.invalidateOrgKey();
|
|
1397
|
+
this._piKeyFetch = null;
|
|
1398
|
+
return true;
|
|
1399
|
+
}
|
|
1353
1400
|
};
|
|
1354
1401
|
|
|
1355
1402
|
// src/index.ts
|