@premai/api-sdk 1.0.42 → 1.0.43
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 +19 -0
- package/dist/bare.cjs +25981 -0
- package/dist/bare.d.ts +31 -0
- package/dist/bare.mjs +25938 -0
- package/dist/cli-claude.mjs +67 -67
- package/dist/cli.mjs +72 -72
- package/dist/index.cjs +3 -3
- package/dist/index.mjs +3 -3
- package/package.json +14 -9
- package/dist/bare-global.d.ts +0 -4
- package/dist/bare-global.mjs +0 -30
package/dist/cli-claude.mjs
CHANGED
|
@@ -236,7 +236,7 @@ function interactivePickModel(models) {
|
|
|
236
236
|
import express from "express";
|
|
237
237
|
|
|
238
238
|
// src/anthropic/http.ts
|
|
239
|
-
import { randomBytes as randomBytes3 } from "
|
|
239
|
+
import { bytesToHex as bytesToHex3, randomBytes as randomBytes3 } from "@noble/ciphers/utils.js";
|
|
240
240
|
var ANTHROPIC_VERSION_DEFAULT = "2023-06-01";
|
|
241
241
|
var ANTHROPIC_VERSION_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
242
242
|
function isAnthropicApiVersionSupported(version) {
|
|
@@ -246,10 +246,10 @@ function isAnthropicApiVersionSupported(version) {
|
|
|
246
246
|
return ANTHROPIC_VERSION_DATE.test(version);
|
|
247
247
|
}
|
|
248
248
|
function newAnthropicRequestId() {
|
|
249
|
-
return `req_${randomBytes3(12)
|
|
249
|
+
return `req_${bytesToHex3(randomBytes3(12))}`;
|
|
250
250
|
}
|
|
251
251
|
function newAnthropicMessageId() {
|
|
252
|
-
return `msg_${randomBytes3(12)
|
|
252
|
+
return `msg_${bytesToHex3(randomBytes3(12))}`;
|
|
253
253
|
}
|
|
254
254
|
function extractAnthropicApiKey(req) {
|
|
255
255
|
const raw = req.headers["x-api-key"];
|
|
@@ -1136,7 +1136,7 @@ function registerAnthropicModelsRoute(router, deps) {
|
|
|
1136
1136
|
import multer from "multer";
|
|
1137
1137
|
|
|
1138
1138
|
// src/audio/index.ts
|
|
1139
|
-
import { bytesToHex as
|
|
1139
|
+
import { bytesToHex as bytesToHex4, hexToBytes as hexToBytes3 } from "@noble/ciphers/utils.js";
|
|
1140
1140
|
|
|
1141
1141
|
// src/utils/attestation.ts
|
|
1142
1142
|
var cachedPrem;
|
|
@@ -1378,13 +1378,13 @@ async function preprocessAudioRequest(body, encryptionKeys) {
|
|
|
1378
1378
|
const { encrypted: encryptedFileName, nonce: fileNameNonce } = encryptPayload(sharedSecret, fileName);
|
|
1379
1379
|
return {
|
|
1380
1380
|
body: {
|
|
1381
|
-
cipherText:
|
|
1382
|
-
encryptedInference:
|
|
1383
|
-
nonce:
|
|
1384
|
-
fileNameNonce:
|
|
1385
|
-
encryptedFileName:
|
|
1386
|
-
fileNonce:
|
|
1387
|
-
encryptedFile:
|
|
1381
|
+
cipherText: bytesToHex4(cipherText),
|
|
1382
|
+
encryptedInference: bytesToHex4(encrypted),
|
|
1383
|
+
nonce: bytesToHex4(nonce),
|
|
1384
|
+
fileNameNonce: bytesToHex4(fileNameNonce),
|
|
1385
|
+
encryptedFileName: bytesToHex4(encryptedFileName),
|
|
1386
|
+
fileNonce: bytesToHex4(fileNonce),
|
|
1387
|
+
encryptedFile: bytesToHex4(encryptedFile),
|
|
1388
1388
|
model: body.model
|
|
1389
1389
|
},
|
|
1390
1390
|
sharedSecret
|
|
@@ -1424,13 +1424,13 @@ async function preprocessAudioTranslationRequest(body, encryptionKeys) {
|
|
|
1424
1424
|
const { encrypted: encryptedFileName, nonce: fileNameNonce } = encryptPayload(sharedSecret, fileName);
|
|
1425
1425
|
return {
|
|
1426
1426
|
body: {
|
|
1427
|
-
cipherText:
|
|
1428
|
-
encryptedInference:
|
|
1429
|
-
nonce:
|
|
1430
|
-
fileNameNonce:
|
|
1431
|
-
encryptedFileName:
|
|
1432
|
-
fileNonce:
|
|
1433
|
-
encryptedFile:
|
|
1427
|
+
cipherText: bytesToHex4(cipherText),
|
|
1428
|
+
encryptedInference: bytesToHex4(encrypted),
|
|
1429
|
+
nonce: bytesToHex4(nonce),
|
|
1430
|
+
fileNameNonce: bytesToHex4(fileNameNonce),
|
|
1431
|
+
encryptedFileName: bytesToHex4(encryptedFileName),
|
|
1432
|
+
fileNonce: bytesToHex4(fileNonce),
|
|
1433
|
+
encryptedFile: bytesToHex4(encryptedFile),
|
|
1434
1434
|
model: body.model
|
|
1435
1435
|
},
|
|
1436
1436
|
sharedSecret
|
|
@@ -1508,7 +1508,7 @@ function createAudioClient(apiKey, encryptionKeys, requestTimeoutMs = DEFAULT_RE
|
|
|
1508
1508
|
}
|
|
1509
1509
|
|
|
1510
1510
|
// src/files/index.ts
|
|
1511
|
-
import { bytesToHex as
|
|
1511
|
+
import { bytesToHex as bytesToHex5, hexToBytes as hexToBytes4, randomBytes as randomBytes4 } from "@noble/ciphers/utils.js";
|
|
1512
1512
|
import { sha256 as sha2562 } from "@noble/hashes/sha2.js";
|
|
1513
1513
|
import { isValid, parseISO } from "date-fns";
|
|
1514
1514
|
import { z } from "zod";
|
|
@@ -1678,13 +1678,13 @@ async function prepareEncryptedPayload(dekStore, options, apiKey, clientKEK, tim
|
|
|
1678
1678
|
const wrappedDEK = wrapDEK(_clientKEK, dek);
|
|
1679
1679
|
const clientKID = clientKEK ? getClientKID(clientKEK) : getClientKID();
|
|
1680
1680
|
const filePayload = {
|
|
1681
|
-
client_hash:
|
|
1682
|
-
encrypted_content:
|
|
1681
|
+
client_hash: bytesToHex5(sha2562(fileBytes)),
|
|
1682
|
+
encrypted_content: bytesToHex5(encryptedFile),
|
|
1683
1683
|
encrypted_name: encryptedName,
|
|
1684
1684
|
kid: clientKID,
|
|
1685
1685
|
mime_type: encryptedMimeType,
|
|
1686
1686
|
version: "2",
|
|
1687
|
-
wrapped_dek:
|
|
1687
|
+
wrapped_dek: bytesToHex5(wrappedDEK)
|
|
1688
1688
|
};
|
|
1689
1689
|
if (options.ragIndex) {
|
|
1690
1690
|
await addRagIndexToPayload(dekStore, dek, filePayload, apiKey, clientKEK, timeoutMs);
|
|
@@ -1699,7 +1699,7 @@ async function addRagIndexToPayload(dekStore, dek, filePayload, apiKey, clientKE
|
|
|
1699
1699
|
const wrappedRagDEK = wrapDEK(_clientKEK, ragDEK);
|
|
1700
1700
|
dekStore.ragDEK = wrappedRagDEK;
|
|
1701
1701
|
try {
|
|
1702
|
-
await saveRagDEKToBackend(apiKey,
|
|
1702
|
+
await saveRagDEKToBackend(apiKey, bytesToHex5(wrappedRagDEK), timeoutMs);
|
|
1703
1703
|
} catch (error) {
|
|
1704
1704
|
console.error("Warning: Failed to save RAG DEK to backend:", error);
|
|
1705
1705
|
}
|
|
@@ -1710,11 +1710,11 @@ async function addRagIndexToPayload(dekStore, dek, filePayload, apiKey, clientKE
|
|
|
1710
1710
|
const { cipherText, sharedSecret } = createMLKEMEncapsulation(enclavePublicKey);
|
|
1711
1711
|
const { encrypted: encryptedFileDEK, nonce: fileNonce } = encryptPayload(sharedSecret, dek);
|
|
1712
1712
|
const { encrypted: encryptedRagDEK, nonce: ragDEKNonce } = encryptPayload(sharedSecret, ragDEK);
|
|
1713
|
-
filePayload.encrypted_file_dek =
|
|
1714
|
-
filePayload.encrypted_rag_dek =
|
|
1715
|
-
filePayload.file_nonce =
|
|
1716
|
-
filePayload.rag_dek_nonce =
|
|
1717
|
-
filePayload.cipher_text =
|
|
1713
|
+
filePayload.encrypted_file_dek = bytesToHex5(encryptedFileDEK);
|
|
1714
|
+
filePayload.encrypted_rag_dek = bytesToHex5(encryptedRagDEK);
|
|
1715
|
+
filePayload.file_nonce = bytesToHex5(fileNonce);
|
|
1716
|
+
filePayload.rag_dek_nonce = bytesToHex5(ragDEKNonce);
|
|
1717
|
+
filePayload.cipher_text = bytesToHex5(cipherText);
|
|
1718
1718
|
}
|
|
1719
1719
|
async function performUpload(apiKey, filePayload, controller) {
|
|
1720
1720
|
const uploadResponse = await fetch(`${endpoints.proxy}/files/encrypted/upload`, {
|
|
@@ -1925,12 +1925,12 @@ async function indexFiles(apiKey, dekStore, options, clientKEK, timeoutMs = DEFA
|
|
|
1925
1925
|
const { encrypted: encryptedRagDEK, nonce: ragDEKNonce } = encryptPayload(sharedSecret, ragDEK);
|
|
1926
1926
|
return {
|
|
1927
1927
|
file_id: file.fileId,
|
|
1928
|
-
encrypted_file_dek:
|
|
1929
|
-
encrypted_rag_dek:
|
|
1930
|
-
file_nonce:
|
|
1931
|
-
rag_dek_nonce:
|
|
1928
|
+
encrypted_file_dek: bytesToHex5(encryptedFileDEK),
|
|
1929
|
+
encrypted_rag_dek: bytesToHex5(encryptedRagDEK),
|
|
1930
|
+
file_nonce: bytesToHex5(fileNonce),
|
|
1931
|
+
rag_dek_nonce: bytesToHex5(ragDEKNonce),
|
|
1932
1932
|
s3_r2_path: file.filePath,
|
|
1933
|
-
cipher_text:
|
|
1933
|
+
cipher_text: bytesToHex5(cipherText)
|
|
1934
1934
|
};
|
|
1935
1935
|
});
|
|
1936
1936
|
const controller = new AbortController;
|
|
@@ -1983,9 +1983,9 @@ async function deleteIndex(apiKey, dekStore, options, clientKEK, timeoutMs = DEF
|
|
|
1983
1983
|
"Content-Type": "application/json"
|
|
1984
1984
|
},
|
|
1985
1985
|
body: JSON.stringify({
|
|
1986
|
-
cipher_text:
|
|
1987
|
-
encrypted_rag_dek:
|
|
1988
|
-
rag_dek_nonce:
|
|
1986
|
+
cipher_text: bytesToHex5(cipherText),
|
|
1987
|
+
encrypted_rag_dek: bytesToHex5(encryptedRagDEK),
|
|
1988
|
+
rag_dek_nonce: bytesToHex5(ragDEKNonce),
|
|
1989
1989
|
fileIds: options.fileIds
|
|
1990
1990
|
}),
|
|
1991
1991
|
signal: controller.signal
|
|
@@ -2061,16 +2061,16 @@ function createModelsClient(apiKey, timeoutMs = DEFAULT_REQUEST_TIMEOUT_MS) {
|
|
|
2061
2061
|
}
|
|
2062
2062
|
|
|
2063
2063
|
// src/rvenc/index.ts
|
|
2064
|
-
import { bytesToHex as
|
|
2064
|
+
import { bytesToHex as bytesToHex6, hexToBytes as hexToBytes5 } from "@noble/ciphers/utils.js";
|
|
2065
2065
|
import OpenAI from "openai";
|
|
2066
2066
|
function preprocessRequest(body, encryptionKeys) {
|
|
2067
2067
|
const { cipherText, sharedSecret } = encryptionKeys;
|
|
2068
2068
|
const { encrypted, nonce } = encryptPayload(sharedSecret, body);
|
|
2069
2069
|
return {
|
|
2070
2070
|
body: {
|
|
2071
|
-
cipherText:
|
|
2072
|
-
encryptedInference:
|
|
2073
|
-
nonce:
|
|
2071
|
+
cipherText: bytesToHex6(cipherText),
|
|
2072
|
+
encryptedInference: bytesToHex6(encrypted),
|
|
2073
|
+
nonce: bytesToHex6(nonce),
|
|
2074
2074
|
model: body.model,
|
|
2075
2075
|
stream: body.stream === true
|
|
2076
2076
|
},
|
|
@@ -2227,7 +2227,7 @@ async function* createDecryptedStreamGenerator(reader, sharedSecret, nonce, maxB
|
|
|
2227
2227
|
}
|
|
2228
2228
|
|
|
2229
2229
|
// src/tools/index.ts
|
|
2230
|
-
import { bytesToHex as
|
|
2230
|
+
import { bytesToHex as bytesToHex7, hexToBytes as hexToBytes6, randomBytes as randomBytes5 } from "@noble/ciphers/utils.js";
|
|
2231
2231
|
var FILE_OUTPUT_TOOLS = ["generateImage", "audioGenerateFromText", "createFileForUser"];
|
|
2232
2232
|
var FILE_INPUT_TOOLS = [
|
|
2233
2233
|
"imageDescribeAndCaption",
|
|
@@ -2328,9 +2328,9 @@ async function callSimpleTool(toolName, params, apiKey, timeoutMs, attest2) {
|
|
|
2328
2328
|
const { cipherText, sharedSecret } = createMLKEMEncapsulation(enclavePublicKey);
|
|
2329
2329
|
const { encrypted, nonce } = encryptPayload(sharedSecret, params);
|
|
2330
2330
|
const body = {
|
|
2331
|
-
cipherText:
|
|
2332
|
-
encryptedParams:
|
|
2333
|
-
nonce:
|
|
2331
|
+
cipherText: bytesToHex7(cipherText),
|
|
2332
|
+
encryptedParams: bytesToHex7(encrypted),
|
|
2333
|
+
nonce: bytesToHex7(nonce)
|
|
2334
2334
|
};
|
|
2335
2335
|
const response = await callToolRequest(toolName, body, apiKey, timeoutMs, attest2);
|
|
2336
2336
|
return decryptPayload(response.encryptedResponse, sharedSecret, hexToBytes6(response.nonce));
|
|
@@ -2345,13 +2345,13 @@ async function callFileOutputTool(toolName, params, apiKey, dekStore, clientKEK,
|
|
|
2345
2345
|
const wrappedDEK = wrapDEK(_clientKEK, dek);
|
|
2346
2346
|
const clientKID = clientKEK ? getClientKID(clientKEK) : getClientKID();
|
|
2347
2347
|
const body = {
|
|
2348
|
-
cipherText:
|
|
2349
|
-
encryptedParams:
|
|
2350
|
-
nonce:
|
|
2351
|
-
encryptedDEK:
|
|
2352
|
-
dekNonce:
|
|
2348
|
+
cipherText: bytesToHex7(cipherText),
|
|
2349
|
+
encryptedParams: bytesToHex7(encrypted),
|
|
2350
|
+
nonce: bytesToHex7(nonce),
|
|
2351
|
+
encryptedDEK: bytesToHex7(encryptedDEK),
|
|
2352
|
+
dekNonce: bytesToHex7(dekNonce),
|
|
2353
2353
|
kid: clientKID,
|
|
2354
|
-
wrappedDEK:
|
|
2354
|
+
wrappedDEK: bytesToHex7(wrappedDEK)
|
|
2355
2355
|
};
|
|
2356
2356
|
const response = await callToolRequest(toolName, body, apiKey, timeoutMs, attest2);
|
|
2357
2357
|
const result = await downloadAndDecryptFile(response, dek, apiKey, timeoutMs);
|
|
@@ -2386,13 +2386,13 @@ async function callFileInputTool(toolName, params, apiKey, dekStore, clientKEK,
|
|
|
2386
2386
|
}
|
|
2387
2387
|
const { encrypted: encryptedFileDEK, nonce: fileDEKNonce } = encryptPayload(sharedSecret, fileDEK);
|
|
2388
2388
|
const body = {
|
|
2389
|
-
cipherText:
|
|
2390
|
-
nonce:
|
|
2389
|
+
cipherText: bytesToHex7(cipherText),
|
|
2390
|
+
nonce: bytesToHex7(nonce),
|
|
2391
2391
|
fileId: params.fileId,
|
|
2392
|
-
encryptedDEK:
|
|
2393
|
-
dekNonce:
|
|
2394
|
-
encryptedFileDEK:
|
|
2395
|
-
fileDEKNonce:
|
|
2392
|
+
encryptedDEK: bytesToHex7(encryptedDEK),
|
|
2393
|
+
dekNonce: bytesToHex7(dekNonce),
|
|
2394
|
+
encryptedFileDEK: bytesToHex7(encryptedFileDEK),
|
|
2395
|
+
fileDEKNonce: bytesToHex7(fileDEKNonce)
|
|
2396
2396
|
};
|
|
2397
2397
|
const response = await callToolRequest(toolName, body, apiKey, timeoutMs, attest2);
|
|
2398
2398
|
return decryptPayload(response.encryptedResponse, sharedSecret, hexToBytes6(response.nonce));
|
|
@@ -2420,8 +2420,8 @@ async function callRagTool(toolName, params, apiKey, dekStore, clientKEK, timeou
|
|
|
2420
2420
|
const { encrypted: encryptedFileDEK, nonce: fileDEKNonce } = encryptPayload(sharedSecret, unwrappedFileDEK);
|
|
2421
2421
|
acc.push({
|
|
2422
2422
|
fileId,
|
|
2423
|
-
encryptedDEK:
|
|
2424
|
-
nonce:
|
|
2423
|
+
encryptedDEK: bytesToHex7(encryptedFileDEK),
|
|
2424
|
+
nonce: bytesToHex7(fileDEKNonce)
|
|
2425
2425
|
});
|
|
2426
2426
|
return acc;
|
|
2427
2427
|
}, []);
|
|
@@ -2435,16 +2435,16 @@ async function callRagTool(toolName, params, apiKey, dekStore, clientKEK, timeou
|
|
|
2435
2435
|
const { encrypted: encryptedRagDEK, nonce: ragDEKNonce } = encryptPayload(sharedSecret, ragDEK);
|
|
2436
2436
|
const { encrypted: encryptedRagVersion, nonce: ragVersionNonce } = encryptPayload(sharedSecret, dekStore.ragVersion);
|
|
2437
2437
|
const body = {
|
|
2438
|
-
cipherText:
|
|
2439
|
-
encryptedParams:
|
|
2440
|
-
nonce:
|
|
2441
|
-
encryptedDEK:
|
|
2442
|
-
dekNonce:
|
|
2438
|
+
cipherText: bytesToHex7(cipherText),
|
|
2439
|
+
encryptedParams: bytesToHex7(encrypted),
|
|
2440
|
+
nonce: bytesToHex7(nonce),
|
|
2441
|
+
encryptedDEK: bytesToHex7(encryptedDEK),
|
|
2442
|
+
dekNonce: bytesToHex7(dekNonce),
|
|
2443
2443
|
encryptedFileDEKs,
|
|
2444
|
-
encryptedRagDEK:
|
|
2445
|
-
ragDEKNonce:
|
|
2446
|
-
encryptedRagVersion:
|
|
2447
|
-
ragVersionNonce:
|
|
2444
|
+
encryptedRagDEK: bytesToHex7(encryptedRagDEK),
|
|
2445
|
+
ragDEKNonce: bytesToHex7(ragDEKNonce),
|
|
2446
|
+
encryptedRagVersion: bytesToHex7(encryptedRagVersion),
|
|
2447
|
+
ragVersionNonce: bytesToHex7(ragVersionNonce)
|
|
2448
2448
|
};
|
|
2449
2449
|
const response = await callToolRequest(toolName, body, apiKey, timeoutMs, attest2);
|
|
2450
2450
|
return decryptPayload(response.encryptedResponse, sharedSecret, hexToBytes6(response.nonce));
|
package/dist/cli.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { parseArgs } from "node:util";
|
|
|
9
9
|
import express from "express";
|
|
10
10
|
|
|
11
11
|
// src/anthropic/http.ts
|
|
12
|
-
import { randomBytes } from "
|
|
12
|
+
import { bytesToHex, randomBytes } from "@noble/ciphers/utils.js";
|
|
13
13
|
var ANTHROPIC_VERSION_DEFAULT = "2023-06-01";
|
|
14
14
|
var ANTHROPIC_VERSION_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
15
15
|
function isAnthropicApiVersionSupported(version) {
|
|
@@ -19,10 +19,10 @@ function isAnthropicApiVersionSupported(version) {
|
|
|
19
19
|
return ANTHROPIC_VERSION_DATE.test(version);
|
|
20
20
|
}
|
|
21
21
|
function newAnthropicRequestId() {
|
|
22
|
-
return `req_${randomBytes(12)
|
|
22
|
+
return `req_${bytesToHex(randomBytes(12))}`;
|
|
23
23
|
}
|
|
24
24
|
function newAnthropicMessageId() {
|
|
25
|
-
return `msg_${randomBytes(12)
|
|
25
|
+
return `msg_${bytesToHex(randomBytes(12))}`;
|
|
26
26
|
}
|
|
27
27
|
function extractAnthropicApiKey(req) {
|
|
28
28
|
const raw = req.headers["x-api-key"];
|
|
@@ -909,7 +909,7 @@ function registerAnthropicModelsRoute(router, deps) {
|
|
|
909
909
|
import multer from "multer";
|
|
910
910
|
|
|
911
911
|
// src/audio/index.ts
|
|
912
|
-
import { bytesToHex as
|
|
912
|
+
import { bytesToHex as bytesToHex3, hexToBytes as hexToBytes2 } from "@noble/ciphers/utils.js";
|
|
913
913
|
|
|
914
914
|
// src/config.ts
|
|
915
915
|
var endpoints = {
|
|
@@ -1061,7 +1061,7 @@ async function attest(apiKey, options = { enabled: true }) {
|
|
|
1061
1061
|
// src/utils/crypto.ts
|
|
1062
1062
|
import { aeskwp } from "@noble/ciphers/aes.js";
|
|
1063
1063
|
import { xchacha20poly1305 } from "@noble/ciphers/chacha.js";
|
|
1064
|
-
import { bytesToHex, hexToBytes, managedNonce, randomBytes as randomBytes2 } from "@noble/ciphers/utils.js";
|
|
1064
|
+
import { bytesToHex as bytesToHex2, hexToBytes, managedNonce, randomBytes as randomBytes2 } from "@noble/ciphers/utils.js";
|
|
1065
1065
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
1066
1066
|
import { sha3_256 } from "@noble/hashes/sha3.js";
|
|
1067
1067
|
import { XWing } from "@noble/post-quantum/hybrid.js";
|
|
@@ -1136,7 +1136,7 @@ function encryptWithDEK(dek, plaintext) {
|
|
|
1136
1136
|
function encryptMetadataWithDEK(dek, metadata) {
|
|
1137
1137
|
const encoded = new TextEncoder().encode(metadata);
|
|
1138
1138
|
const encrypted = encryptWithDEK(dek, encoded);
|
|
1139
|
-
return
|
|
1139
|
+
return bytesToHex2(encrypted);
|
|
1140
1140
|
}
|
|
1141
1141
|
function wrapDEK(kek, dek) {
|
|
1142
1142
|
const kw = aeskwp(kek);
|
|
@@ -1252,13 +1252,13 @@ async function preprocessAudioRequest(body, encryptionKeys) {
|
|
|
1252
1252
|
const { encrypted: encryptedFileName, nonce: fileNameNonce } = encryptPayload(sharedSecret, fileName);
|
|
1253
1253
|
return {
|
|
1254
1254
|
body: {
|
|
1255
|
-
cipherText:
|
|
1256
|
-
encryptedInference:
|
|
1257
|
-
nonce:
|
|
1258
|
-
fileNameNonce:
|
|
1259
|
-
encryptedFileName:
|
|
1260
|
-
fileNonce:
|
|
1261
|
-
encryptedFile:
|
|
1255
|
+
cipherText: bytesToHex3(cipherText),
|
|
1256
|
+
encryptedInference: bytesToHex3(encrypted),
|
|
1257
|
+
nonce: bytesToHex3(nonce),
|
|
1258
|
+
fileNameNonce: bytesToHex3(fileNameNonce),
|
|
1259
|
+
encryptedFileName: bytesToHex3(encryptedFileName),
|
|
1260
|
+
fileNonce: bytesToHex3(fileNonce),
|
|
1261
|
+
encryptedFile: bytesToHex3(encryptedFile),
|
|
1262
1262
|
model: body.model
|
|
1263
1263
|
},
|
|
1264
1264
|
sharedSecret
|
|
@@ -1298,13 +1298,13 @@ async function preprocessAudioTranslationRequest(body, encryptionKeys) {
|
|
|
1298
1298
|
const { encrypted: encryptedFileName, nonce: fileNameNonce } = encryptPayload(sharedSecret, fileName);
|
|
1299
1299
|
return {
|
|
1300
1300
|
body: {
|
|
1301
|
-
cipherText:
|
|
1302
|
-
encryptedInference:
|
|
1303
|
-
nonce:
|
|
1304
|
-
fileNameNonce:
|
|
1305
|
-
encryptedFileName:
|
|
1306
|
-
fileNonce:
|
|
1307
|
-
encryptedFile:
|
|
1301
|
+
cipherText: bytesToHex3(cipherText),
|
|
1302
|
+
encryptedInference: bytesToHex3(encrypted),
|
|
1303
|
+
nonce: bytesToHex3(nonce),
|
|
1304
|
+
fileNameNonce: bytesToHex3(fileNameNonce),
|
|
1305
|
+
encryptedFileName: bytesToHex3(encryptedFileName),
|
|
1306
|
+
fileNonce: bytesToHex3(fileNonce),
|
|
1307
|
+
encryptedFile: bytesToHex3(encryptedFile),
|
|
1308
1308
|
model: body.model
|
|
1309
1309
|
},
|
|
1310
1310
|
sharedSecret
|
|
@@ -1382,13 +1382,13 @@ function createAudioClient(apiKey, encryptionKeys, requestTimeoutMs = DEFAULT_RE
|
|
|
1382
1382
|
}
|
|
1383
1383
|
|
|
1384
1384
|
// src/files/index.ts
|
|
1385
|
-
import { bytesToHex as
|
|
1385
|
+
import { bytesToHex as bytesToHex5, hexToBytes as hexToBytes4, randomBytes as randomBytes4 } from "@noble/ciphers/utils.js";
|
|
1386
1386
|
import { sha256 as sha2562 } from "@noble/hashes/sha2.js";
|
|
1387
1387
|
import { isValid, parseISO } from "date-fns";
|
|
1388
1388
|
import { z } from "zod";
|
|
1389
1389
|
|
|
1390
1390
|
// src/utils/dek-store.ts
|
|
1391
|
-
import { bytesToHex as
|
|
1391
|
+
import { bytesToHex as bytesToHex4, hexToBytes as hexToBytes3, randomBytes as randomBytes3 } from "@noble/ciphers/utils.js";
|
|
1392
1392
|
function initializeDEKStore(clientKEK) {
|
|
1393
1393
|
const ragDEK = randomBytes3(32);
|
|
1394
1394
|
const _clientKEK = clientKEK ? hexToBytes3(clientKEK) : getClientKEK();
|
|
@@ -1407,10 +1407,10 @@ function getClientKEK() {
|
|
|
1407
1407
|
}
|
|
1408
1408
|
function getClientKID(clientKEK) {
|
|
1409
1409
|
if (clientKEK) {
|
|
1410
|
-
return
|
|
1410
|
+
return bytesToHex4(keyIdFromKEK(hexToBytes3(clientKEK)));
|
|
1411
1411
|
}
|
|
1412
1412
|
const _clientKEK = getClientKEK();
|
|
1413
|
-
return
|
|
1413
|
+
return bytesToHex4(keyIdFromKEK(_clientKEK));
|
|
1414
1414
|
}
|
|
1415
1415
|
|
|
1416
1416
|
// src/files/index.ts
|
|
@@ -1580,13 +1580,13 @@ async function prepareEncryptedPayload(dekStore, options, apiKey, clientKEK, tim
|
|
|
1580
1580
|
const wrappedDEK = wrapDEK(_clientKEK, dek);
|
|
1581
1581
|
const clientKID = clientKEK ? getClientKID(clientKEK) : getClientKID();
|
|
1582
1582
|
const filePayload = {
|
|
1583
|
-
client_hash:
|
|
1584
|
-
encrypted_content:
|
|
1583
|
+
client_hash: bytesToHex5(sha2562(fileBytes)),
|
|
1584
|
+
encrypted_content: bytesToHex5(encryptedFile),
|
|
1585
1585
|
encrypted_name: encryptedName,
|
|
1586
1586
|
kid: clientKID,
|
|
1587
1587
|
mime_type: encryptedMimeType,
|
|
1588
1588
|
version: "2",
|
|
1589
|
-
wrapped_dek:
|
|
1589
|
+
wrapped_dek: bytesToHex5(wrappedDEK)
|
|
1590
1590
|
};
|
|
1591
1591
|
if (options.ragIndex) {
|
|
1592
1592
|
await addRagIndexToPayload(dekStore, dek, filePayload, apiKey, clientKEK, timeoutMs);
|
|
@@ -1601,7 +1601,7 @@ async function addRagIndexToPayload(dekStore, dek, filePayload, apiKey, clientKE
|
|
|
1601
1601
|
const wrappedRagDEK = wrapDEK(_clientKEK, ragDEK);
|
|
1602
1602
|
dekStore.ragDEK = wrappedRagDEK;
|
|
1603
1603
|
try {
|
|
1604
|
-
await saveRagDEKToBackend(apiKey,
|
|
1604
|
+
await saveRagDEKToBackend(apiKey, bytesToHex5(wrappedRagDEK), timeoutMs);
|
|
1605
1605
|
} catch (error) {
|
|
1606
1606
|
console.error("Warning: Failed to save RAG DEK to backend:", error);
|
|
1607
1607
|
}
|
|
@@ -1612,11 +1612,11 @@ async function addRagIndexToPayload(dekStore, dek, filePayload, apiKey, clientKE
|
|
|
1612
1612
|
const { cipherText, sharedSecret } = createMLKEMEncapsulation(enclavePublicKey);
|
|
1613
1613
|
const { encrypted: encryptedFileDEK, nonce: fileNonce } = encryptPayload(sharedSecret, dek);
|
|
1614
1614
|
const { encrypted: encryptedRagDEK, nonce: ragDEKNonce } = encryptPayload(sharedSecret, ragDEK);
|
|
1615
|
-
filePayload.encrypted_file_dek =
|
|
1616
|
-
filePayload.encrypted_rag_dek =
|
|
1617
|
-
filePayload.file_nonce =
|
|
1618
|
-
filePayload.rag_dek_nonce =
|
|
1619
|
-
filePayload.cipher_text =
|
|
1615
|
+
filePayload.encrypted_file_dek = bytesToHex5(encryptedFileDEK);
|
|
1616
|
+
filePayload.encrypted_rag_dek = bytesToHex5(encryptedRagDEK);
|
|
1617
|
+
filePayload.file_nonce = bytesToHex5(fileNonce);
|
|
1618
|
+
filePayload.rag_dek_nonce = bytesToHex5(ragDEKNonce);
|
|
1619
|
+
filePayload.cipher_text = bytesToHex5(cipherText);
|
|
1620
1620
|
}
|
|
1621
1621
|
async function performUpload(apiKey, filePayload, controller) {
|
|
1622
1622
|
const uploadResponse = await fetch(`${endpoints.proxy}/files/encrypted/upload`, {
|
|
@@ -1827,12 +1827,12 @@ async function indexFiles(apiKey, dekStore, options, clientKEK, timeoutMs = DEFA
|
|
|
1827
1827
|
const { encrypted: encryptedRagDEK, nonce: ragDEKNonce } = encryptPayload(sharedSecret, ragDEK);
|
|
1828
1828
|
return {
|
|
1829
1829
|
file_id: file.fileId,
|
|
1830
|
-
encrypted_file_dek:
|
|
1831
|
-
encrypted_rag_dek:
|
|
1832
|
-
file_nonce:
|
|
1833
|
-
rag_dek_nonce:
|
|
1830
|
+
encrypted_file_dek: bytesToHex5(encryptedFileDEK),
|
|
1831
|
+
encrypted_rag_dek: bytesToHex5(encryptedRagDEK),
|
|
1832
|
+
file_nonce: bytesToHex5(fileNonce),
|
|
1833
|
+
rag_dek_nonce: bytesToHex5(ragDEKNonce),
|
|
1834
1834
|
s3_r2_path: file.filePath,
|
|
1835
|
-
cipher_text:
|
|
1835
|
+
cipher_text: bytesToHex5(cipherText)
|
|
1836
1836
|
};
|
|
1837
1837
|
});
|
|
1838
1838
|
const controller = new AbortController;
|
|
@@ -1885,9 +1885,9 @@ async function deleteIndex(apiKey, dekStore, options, clientKEK, timeoutMs = DEF
|
|
|
1885
1885
|
"Content-Type": "application/json"
|
|
1886
1886
|
},
|
|
1887
1887
|
body: JSON.stringify({
|
|
1888
|
-
cipher_text:
|
|
1889
|
-
encrypted_rag_dek:
|
|
1890
|
-
rag_dek_nonce:
|
|
1888
|
+
cipher_text: bytesToHex5(cipherText),
|
|
1889
|
+
encrypted_rag_dek: bytesToHex5(encryptedRagDEK),
|
|
1890
|
+
rag_dek_nonce: bytesToHex5(ragDEKNonce),
|
|
1891
1891
|
fileIds: options.fileIds
|
|
1892
1892
|
}),
|
|
1893
1893
|
signal: controller.signal
|
|
@@ -1963,16 +1963,16 @@ function createModelsClient(apiKey, timeoutMs = DEFAULT_REQUEST_TIMEOUT_MS) {
|
|
|
1963
1963
|
}
|
|
1964
1964
|
|
|
1965
1965
|
// src/rvenc/index.ts
|
|
1966
|
-
import { bytesToHex as
|
|
1966
|
+
import { bytesToHex as bytesToHex6, hexToBytes as hexToBytes5 } from "@noble/ciphers/utils.js";
|
|
1967
1967
|
import OpenAI from "openai";
|
|
1968
1968
|
function preprocessRequest(body, encryptionKeys) {
|
|
1969
1969
|
const { cipherText, sharedSecret } = encryptionKeys;
|
|
1970
1970
|
const { encrypted, nonce } = encryptPayload(sharedSecret, body);
|
|
1971
1971
|
return {
|
|
1972
1972
|
body: {
|
|
1973
|
-
cipherText:
|
|
1974
|
-
encryptedInference:
|
|
1975
|
-
nonce:
|
|
1973
|
+
cipherText: bytesToHex6(cipherText),
|
|
1974
|
+
encryptedInference: bytesToHex6(encrypted),
|
|
1975
|
+
nonce: bytesToHex6(nonce),
|
|
1976
1976
|
model: body.model,
|
|
1977
1977
|
stream: body.stream === true
|
|
1978
1978
|
},
|
|
@@ -2129,7 +2129,7 @@ async function* createDecryptedStreamGenerator(reader, sharedSecret, nonce, maxB
|
|
|
2129
2129
|
}
|
|
2130
2130
|
|
|
2131
2131
|
// src/tools/index.ts
|
|
2132
|
-
import { bytesToHex as
|
|
2132
|
+
import { bytesToHex as bytesToHex7, hexToBytes as hexToBytes6, randomBytes as randomBytes5 } from "@noble/ciphers/utils.js";
|
|
2133
2133
|
var FILE_OUTPUT_TOOLS = ["generateImage", "audioGenerateFromText", "createFileForUser"];
|
|
2134
2134
|
var FILE_INPUT_TOOLS = [
|
|
2135
2135
|
"imageDescribeAndCaption",
|
|
@@ -2230,9 +2230,9 @@ async function callSimpleTool(toolName, params, apiKey, timeoutMs, attest2) {
|
|
|
2230
2230
|
const { cipherText, sharedSecret } = createMLKEMEncapsulation(enclavePublicKey);
|
|
2231
2231
|
const { encrypted, nonce } = encryptPayload(sharedSecret, params);
|
|
2232
2232
|
const body = {
|
|
2233
|
-
cipherText:
|
|
2234
|
-
encryptedParams:
|
|
2235
|
-
nonce:
|
|
2233
|
+
cipherText: bytesToHex7(cipherText),
|
|
2234
|
+
encryptedParams: bytesToHex7(encrypted),
|
|
2235
|
+
nonce: bytesToHex7(nonce)
|
|
2236
2236
|
};
|
|
2237
2237
|
const response = await callToolRequest(toolName, body, apiKey, timeoutMs, attest2);
|
|
2238
2238
|
return decryptPayload(response.encryptedResponse, sharedSecret, hexToBytes6(response.nonce));
|
|
@@ -2247,13 +2247,13 @@ async function callFileOutputTool(toolName, params, apiKey, dekStore, clientKEK,
|
|
|
2247
2247
|
const wrappedDEK = wrapDEK(_clientKEK, dek);
|
|
2248
2248
|
const clientKID = clientKEK ? getClientKID(clientKEK) : getClientKID();
|
|
2249
2249
|
const body = {
|
|
2250
|
-
cipherText:
|
|
2251
|
-
encryptedParams:
|
|
2252
|
-
nonce:
|
|
2253
|
-
encryptedDEK:
|
|
2254
|
-
dekNonce:
|
|
2250
|
+
cipherText: bytesToHex7(cipherText),
|
|
2251
|
+
encryptedParams: bytesToHex7(encrypted),
|
|
2252
|
+
nonce: bytesToHex7(nonce),
|
|
2253
|
+
encryptedDEK: bytesToHex7(encryptedDEK),
|
|
2254
|
+
dekNonce: bytesToHex7(dekNonce),
|
|
2255
2255
|
kid: clientKID,
|
|
2256
|
-
wrappedDEK:
|
|
2256
|
+
wrappedDEK: bytesToHex7(wrappedDEK)
|
|
2257
2257
|
};
|
|
2258
2258
|
const response = await callToolRequest(toolName, body, apiKey, timeoutMs, attest2);
|
|
2259
2259
|
const result = await downloadAndDecryptFile(response, dek, apiKey, timeoutMs);
|
|
@@ -2288,13 +2288,13 @@ async function callFileInputTool(toolName, params, apiKey, dekStore, clientKEK,
|
|
|
2288
2288
|
}
|
|
2289
2289
|
const { encrypted: encryptedFileDEK, nonce: fileDEKNonce } = encryptPayload(sharedSecret, fileDEK);
|
|
2290
2290
|
const body = {
|
|
2291
|
-
cipherText:
|
|
2292
|
-
nonce:
|
|
2291
|
+
cipherText: bytesToHex7(cipherText),
|
|
2292
|
+
nonce: bytesToHex7(nonce),
|
|
2293
2293
|
fileId: params.fileId,
|
|
2294
|
-
encryptedDEK:
|
|
2295
|
-
dekNonce:
|
|
2296
|
-
encryptedFileDEK:
|
|
2297
|
-
fileDEKNonce:
|
|
2294
|
+
encryptedDEK: bytesToHex7(encryptedDEK),
|
|
2295
|
+
dekNonce: bytesToHex7(dekNonce),
|
|
2296
|
+
encryptedFileDEK: bytesToHex7(encryptedFileDEK),
|
|
2297
|
+
fileDEKNonce: bytesToHex7(fileDEKNonce)
|
|
2298
2298
|
};
|
|
2299
2299
|
const response = await callToolRequest(toolName, body, apiKey, timeoutMs, attest2);
|
|
2300
2300
|
return decryptPayload(response.encryptedResponse, sharedSecret, hexToBytes6(response.nonce));
|
|
@@ -2322,8 +2322,8 @@ async function callRagTool(toolName, params, apiKey, dekStore, clientKEK, timeou
|
|
|
2322
2322
|
const { encrypted: encryptedFileDEK, nonce: fileDEKNonce } = encryptPayload(sharedSecret, unwrappedFileDEK);
|
|
2323
2323
|
acc.push({
|
|
2324
2324
|
fileId,
|
|
2325
|
-
encryptedDEK:
|
|
2326
|
-
nonce:
|
|
2325
|
+
encryptedDEK: bytesToHex7(encryptedFileDEK),
|
|
2326
|
+
nonce: bytesToHex7(fileDEKNonce)
|
|
2327
2327
|
});
|
|
2328
2328
|
return acc;
|
|
2329
2329
|
}, []);
|
|
@@ -2337,16 +2337,16 @@ async function callRagTool(toolName, params, apiKey, dekStore, clientKEK, timeou
|
|
|
2337
2337
|
const { encrypted: encryptedRagDEK, nonce: ragDEKNonce } = encryptPayload(sharedSecret, ragDEK);
|
|
2338
2338
|
const { encrypted: encryptedRagVersion, nonce: ragVersionNonce } = encryptPayload(sharedSecret, dekStore.ragVersion);
|
|
2339
2339
|
const body = {
|
|
2340
|
-
cipherText:
|
|
2341
|
-
encryptedParams:
|
|
2342
|
-
nonce:
|
|
2343
|
-
encryptedDEK:
|
|
2344
|
-
dekNonce:
|
|
2340
|
+
cipherText: bytesToHex7(cipherText),
|
|
2341
|
+
encryptedParams: bytesToHex7(encrypted),
|
|
2342
|
+
nonce: bytesToHex7(nonce),
|
|
2343
|
+
encryptedDEK: bytesToHex7(encryptedDEK),
|
|
2344
|
+
dekNonce: bytesToHex7(dekNonce),
|
|
2345
2345
|
encryptedFileDEKs,
|
|
2346
|
-
encryptedRagDEK:
|
|
2347
|
-
ragDEKNonce:
|
|
2348
|
-
encryptedRagVersion:
|
|
2349
|
-
ragVersionNonce:
|
|
2346
|
+
encryptedRagDEK: bytesToHex7(encryptedRagDEK),
|
|
2347
|
+
ragDEKNonce: bytesToHex7(ragDEKNonce),
|
|
2348
|
+
encryptedRagVersion: bytesToHex7(encryptedRagVersion),
|
|
2349
|
+
ragVersionNonce: bytesToHex7(ragVersionNonce)
|
|
2350
2350
|
};
|
|
2351
2351
|
const response = await callToolRequest(toolName, body, apiKey, timeoutMs, attest2);
|
|
2352
2352
|
return decryptPayload(response.encryptedResponse, sharedSecret, hexToBytes6(response.nonce));
|
package/dist/index.cjs
CHANGED
|
@@ -1638,7 +1638,7 @@ var core_default = createRvencClient;
|
|
|
1638
1638
|
var import_express = __toESM(require("express"));
|
|
1639
1639
|
|
|
1640
1640
|
// src/anthropic/http.ts
|
|
1641
|
-
var
|
|
1641
|
+
var import_utils7 = require("@noble/ciphers/utils.js");
|
|
1642
1642
|
var ANTHROPIC_VERSION_DEFAULT = "2023-06-01";
|
|
1643
1643
|
var ANTHROPIC_VERSION_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
1644
1644
|
function isAnthropicApiVersionSupported(version) {
|
|
@@ -1648,10 +1648,10 @@ function isAnthropicApiVersionSupported(version) {
|
|
|
1648
1648
|
return ANTHROPIC_VERSION_DATE.test(version);
|
|
1649
1649
|
}
|
|
1650
1650
|
function newAnthropicRequestId() {
|
|
1651
|
-
return `req_${
|
|
1651
|
+
return `req_${import_utils7.bytesToHex(import_utils7.randomBytes(12))}`;
|
|
1652
1652
|
}
|
|
1653
1653
|
function newAnthropicMessageId() {
|
|
1654
|
-
return `msg_${
|
|
1654
|
+
return `msg_${import_utils7.bytesToHex(import_utils7.randomBytes(12))}`;
|
|
1655
1655
|
}
|
|
1656
1656
|
function extractAnthropicApiKey(req) {
|
|
1657
1657
|
const raw = req.headers["x-api-key"];
|
package/dist/index.mjs
CHANGED
|
@@ -1553,7 +1553,7 @@ var core_default = createRvencClient;
|
|
|
1553
1553
|
import express from "express";
|
|
1554
1554
|
|
|
1555
1555
|
// src/anthropic/http.ts
|
|
1556
|
-
import { randomBytes as randomBytes5 } from "
|
|
1556
|
+
import { bytesToHex as bytesToHex7, randomBytes as randomBytes5 } from "@noble/ciphers/utils.js";
|
|
1557
1557
|
var ANTHROPIC_VERSION_DEFAULT = "2023-06-01";
|
|
1558
1558
|
var ANTHROPIC_VERSION_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
1559
1559
|
function isAnthropicApiVersionSupported(version) {
|
|
@@ -1563,10 +1563,10 @@ function isAnthropicApiVersionSupported(version) {
|
|
|
1563
1563
|
return ANTHROPIC_VERSION_DATE.test(version);
|
|
1564
1564
|
}
|
|
1565
1565
|
function newAnthropicRequestId() {
|
|
1566
|
-
return `req_${randomBytes5(12)
|
|
1566
|
+
return `req_${bytesToHex7(randomBytes5(12))}`;
|
|
1567
1567
|
}
|
|
1568
1568
|
function newAnthropicMessageId() {
|
|
1569
|
-
return `msg_${randomBytes5(12)
|
|
1569
|
+
return `msg_${bytesToHex7(randomBytes5(12))}`;
|
|
1570
1570
|
}
|
|
1571
1571
|
function extractAnthropicApiKey(req) {
|
|
1572
1572
|
const raw = req.headers["x-api-key"];
|