@oxy.so/core 1.7.4 → 1.8.1
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/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/crypto/polyfill.js +21 -6
- package/dist/cjs/index.js +4 -1
- package/dist/cjs/inference/OxyInferenceClient.js +8 -3
- package/dist/cjs/mixins/OxyServices.utility.js +23 -6
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/crypto/polyfill.js +19 -4
- package/dist/esm/index.js +4 -1
- package/dist/esm/inference/OxyInferenceClient.js +8 -3
- package/dist/esm/mixins/OxyServices.utility.js +23 -6
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/crypto/polyfill.d.ts +17 -2
- package/dist/types/inference/OxyInferenceClient.d.ts +15 -4
- package/dist/types/mixins/OxyServices.utility.d.ts +8 -0
- package/dist/types/server/auth.d.ts +2 -0
- package/package.json +3 -3
- package/src/crypto/__tests__/polyfill.test.ts +1 -1
- package/src/crypto/__tests__/polyfillOrder.test.ts +114 -0
- package/src/crypto/polyfill.ts +19 -4
- package/src/index.ts +4 -1
- package/src/inference/OxyInferenceClient.ts +15 -3
- package/src/inference/__tests__/OxyInferenceClient.test.ts +17 -0
- package/src/mixins/OxyServices.utility.ts +33 -6
- package/src/mixins/__tests__/serviceAuth.test.ts +57 -0
- package/src/server/auth.ts +2 -0
|
@@ -13,8 +13,23 @@
|
|
|
13
13
|
* 2. Node — backed by the built-in `node:crypto` module (`webcrypto`, else
|
|
14
14
|
* `randomFillSync`). This is what a Node runtime WITHOUT a global WebCrypto
|
|
15
15
|
* (Node 18 script entrypoints, some embedded hosts) falls back to.
|
|
16
|
-
* 3. React Native — `expo-crypto.getRandomBytes
|
|
17
|
-
*
|
|
16
|
+
* 3. React Native — `expo-crypto.getRandomBytes`, through the dependency-free
|
|
17
|
+
* `@oxy.so/protocol/random` entry.
|
|
18
|
+
*
|
|
19
|
+
* # Evaluation order — this module must import NOTHING that can capture the global
|
|
20
|
+
*
|
|
21
|
+
* `@noble/hashes` 1.x reads `globalThis.crypto` exactly once, when its
|
|
22
|
+
* `crypto.js` is evaluated, and `randomBytes` uses that captured binding for
|
|
23
|
+
* the lifetime of the app. ES imports are evaluated before the importing
|
|
24
|
+
* module's body, so every module this file imports runs BEFORE the shim below
|
|
25
|
+
* is installed. This file used to import `@oxy.so/protocol`'s root entry,
|
|
26
|
+
* which reaches `@noble/curves` → `@noble/hashes` through the envelope signer:
|
|
27
|
+
* on Hermes (no `globalThis.crypto` at startup) noble captured `undefined`
|
|
28
|
+
* before the shim existed, and every identity creation on Android failed with
|
|
29
|
+
* `crypto.getRandomValues must be defined`. Its imports are therefore limited
|
|
30
|
+
* to `buffer` and `@oxy.so/protocol/random`, both free of crypto libraries,
|
|
31
|
+
* and `index.ts` imports this file first. `__tests__/polyfillOrder.test.ts`
|
|
32
|
+
* guards both halves.
|
|
18
33
|
*
|
|
19
34
|
* Historically step (2) delegated to `@oxy.so/protocol`'s RN-only
|
|
20
35
|
* `getRandomBytesRN`, which THROWS on Node — so any Node host lacking a global
|
|
@@ -23,7 +38,7 @@
|
|
|
23
38
|
*/
|
|
24
39
|
import _cjs_buffer from 'buffer';
|
|
25
40
|
const { Buffer } = _cjs_buffer;
|
|
26
|
-
import { getRandomBytesRN, isNodeJS } from '@oxy.so/protocol';
|
|
41
|
+
import { getRandomBytesRN, isNodeJS } from '@oxy.so/protocol/random';
|
|
27
42
|
const getGlobalObject = () => {
|
|
28
43
|
if (typeof globalThis !== 'undefined')
|
|
29
44
|
return globalThis;
|
|
@@ -112,7 +127,7 @@ const cryptoPolyfill = {
|
|
|
112
127
|
return array;
|
|
113
128
|
}
|
|
114
129
|
// React Native (and any non-Node host without WebCrypto): synchronous
|
|
115
|
-
// expo-crypto via @oxy.so/protocol's RN `platform/
|
|
130
|
+
// expo-crypto via @oxy.so/protocol's RN `platform/random` variant.
|
|
116
131
|
const bytes = getRandomBytesRN(array.byteLength);
|
|
117
132
|
const uint8View = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
|
|
118
133
|
uint8View.set(bytes);
|
package/dist/esm/index.js
CHANGED
|
@@ -16,7 +16,10 @@
|
|
|
16
16
|
* Every export below is NOMINAL — no `export *`, no barrels, no compat shims.
|
|
17
17
|
* If a symbol does not appear here, it is NOT part of the public API.
|
|
18
18
|
*/
|
|
19
|
-
// Ensure crypto polyfills are loaded before anything else
|
|
19
|
+
// Ensure crypto polyfills are loaded before anything else. This MUST stay the
|
|
20
|
+
// first import: `@noble/hashes` captures `globalThis.crypto` when it is
|
|
21
|
+
// evaluated, so the shim has to exist before any module below reaches it (see
|
|
22
|
+
// the evaluation-order note in `./crypto/polyfill`).
|
|
20
23
|
import './crypto/polyfill.js';
|
|
21
24
|
// ---------------------------------------------------------------------------
|
|
22
25
|
// API client
|
|
@@ -140,9 +140,14 @@ export class OxyInferenceClient {
|
|
|
140
140
|
* both see the PUBLIC catalogue; only an internal/system application's
|
|
141
141
|
* service token sees internal-only routes.
|
|
142
142
|
*
|
|
143
|
-
* **`[]` is a normal answer
|
|
144
|
-
*
|
|
145
|
-
*
|
|
143
|
+
* **`[]` is a normal answer**: a route is not publicly exposed until
|
|
144
|
+
* somebody has reviewed the right to resell it. An official application's
|
|
145
|
+
* credential also sees the internal catalogue Oxy keeps in step with
|
|
146
|
+
* Kaana automatically.
|
|
147
|
+
*
|
|
148
|
+
* Each entry's `capabilities.reasoningEfforts` lists the efforts a request
|
|
149
|
+
* may name in `reasoning.effort` (empty: none), and `releasedAt`, when
|
|
150
|
+
* present, is the date the upstream provider published the model.
|
|
146
151
|
*/
|
|
147
152
|
async listModels(options = {}) {
|
|
148
153
|
const body = await __classPrivateFieldGet(this, _OxyInferenceClient_instances, "m", _OxyInferenceClient_request).call(this, 'GET', '/v1/models', { ...(options.signal === undefined ? {} : { signal: options.signal }) });
|
|
@@ -493,6 +493,7 @@ export function OxyServicesUtilityMixin(Base) {
|
|
|
493
493
|
return onError(error);
|
|
494
494
|
return res.status(401).json(error);
|
|
495
495
|
}
|
|
496
|
+
const tier = decoded.tier === 'internal' ? 'internal' : 'external';
|
|
496
497
|
// Read delegated user ID from header
|
|
497
498
|
const oxyUserIdRaw = req.headers['x-oxy-user-id'];
|
|
498
499
|
const oxyUserId = isExactNonEmptyServiceClaim(oxyUserIdRaw) ? oxyUserIdRaw : null;
|
|
@@ -513,12 +514,21 @@ export function OxyServicesUtilityMixin(Base) {
|
|
|
513
514
|
return onError(error);
|
|
514
515
|
return res.status(401).json(error);
|
|
515
516
|
}
|
|
516
|
-
//
|
|
517
|
-
//
|
|
518
|
-
//
|
|
519
|
-
//
|
|
520
|
-
|
|
521
|
-
|
|
517
|
+
// One of Oxy's own applications acts for a user without a grant:
|
|
518
|
+
// inside the ecosystem that is trust, not consent. It still acts
|
|
519
|
+
// with the USER's authority only — what that user may do is for the
|
|
520
|
+
// receiving service to check.
|
|
521
|
+
if (oxyUserId && tier === 'internal') {
|
|
522
|
+
req.userId = oxyUserId;
|
|
523
|
+
req.user = { id: oxyUserId };
|
|
524
|
+
req.serviceActingAs = { userId: oxyUserId, scopes: [] };
|
|
525
|
+
}
|
|
526
|
+
else if (oxyUserId) {
|
|
527
|
+
// C3: an EXTERNAL service may only act as a user when an explicit
|
|
528
|
+
// ServiceActingAs grant exists for that (appId, userId) pair.
|
|
529
|
+
// Without the grant we MUST refuse — silently attaching
|
|
530
|
+
// `req.userId = oxyUserId` would let any service impersonate
|
|
531
|
+
// any user simply by setting the header.
|
|
522
532
|
const grant = await oxyInstance.verifyServiceActingAs(appId, oxyUserId);
|
|
523
533
|
if (!grant || !grant.authorized) {
|
|
524
534
|
logger.warn('[oxy.auth] Service token rejected — no delegation grant', {
|
|
@@ -569,6 +579,7 @@ export function OxyServicesUtilityMixin(Base) {
|
|
|
569
579
|
ownerAccountId,
|
|
570
580
|
scopes: Array.isArray(decoded.scopes) ? decoded.scopes : [],
|
|
571
581
|
environment,
|
|
582
|
+
tier,
|
|
572
583
|
};
|
|
573
584
|
if (debug) {
|
|
574
585
|
logger.debug(`[oxy.auth] Service token OK app=${decoded.appName} delegateUser=${oxyUserId || '(none)'}`, {
|
|
@@ -1001,6 +1012,12 @@ export function OxyServicesUtilityMixin(Base) {
|
|
|
1001
1012
|
});
|
|
1002
1013
|
return;
|
|
1003
1014
|
}
|
|
1015
|
+
// Oxy's own applications are trusted app to app; scopes are the
|
|
1016
|
+
// external lane.
|
|
1017
|
+
if (req.serviceApp.tier === 'internal') {
|
|
1018
|
+
next();
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1004
1021
|
const appHasScope = appScopes.includes(scope);
|
|
1005
1022
|
const delegationHasScope = delegatedScopes.includes(scope);
|
|
1006
1023
|
const hasRequiredScope = req.serviceActingAs
|