@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
|
@@ -14,8 +14,23 @@
|
|
|
14
14
|
* 2. Node — backed by the built-in `node:crypto` module (`webcrypto`, else
|
|
15
15
|
* `randomFillSync`). This is what a Node runtime WITHOUT a global WebCrypto
|
|
16
16
|
* (Node 18 script entrypoints, some embedded hosts) falls back to.
|
|
17
|
-
* 3. React Native — `expo-crypto.getRandomBytes
|
|
18
|
-
*
|
|
17
|
+
* 3. React Native — `expo-crypto.getRandomBytes`, through the dependency-free
|
|
18
|
+
* `@oxy.so/protocol/random` entry.
|
|
19
|
+
*
|
|
20
|
+
* # Evaluation order — this module must import NOTHING that can capture the global
|
|
21
|
+
*
|
|
22
|
+
* `@noble/hashes` 1.x reads `globalThis.crypto` exactly once, when its
|
|
23
|
+
* `crypto.js` is evaluated, and `randomBytes` uses that captured binding for
|
|
24
|
+
* the lifetime of the app. ES imports are evaluated before the importing
|
|
25
|
+
* module's body, so every module this file imports runs BEFORE the shim below
|
|
26
|
+
* is installed. This file used to import `@oxy.so/protocol`'s root entry,
|
|
27
|
+
* which reaches `@noble/curves` → `@noble/hashes` through the envelope signer:
|
|
28
|
+
* on Hermes (no `globalThis.crypto` at startup) noble captured `undefined`
|
|
29
|
+
* before the shim existed, and every identity creation on Android failed with
|
|
30
|
+
* `crypto.getRandomValues must be defined`. Its imports are therefore limited
|
|
31
|
+
* to `buffer` and `@oxy.so/protocol/random`, both free of crypto libraries,
|
|
32
|
+
* and `index.ts` imports this file first. `__tests__/polyfillOrder.test.ts`
|
|
33
|
+
* guards both halves.
|
|
19
34
|
*
|
|
20
35
|
* Historically step (2) delegated to `@oxy.so/protocol`'s RN-only
|
|
21
36
|
* `getRandomBytesRN`, which THROWS on Node — so any Node host lacking a global
|
|
@@ -26,7 +41,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
41
|
exports.Buffer = void 0;
|
|
27
42
|
const buffer_1 = require("buffer");
|
|
28
43
|
Object.defineProperty(exports, "Buffer", { enumerable: true, get: function () { return buffer_1.Buffer; } });
|
|
29
|
-
const
|
|
44
|
+
const random_1 = require("@oxy.so/protocol/random");
|
|
30
45
|
const getGlobalObject = () => {
|
|
31
46
|
if (typeof globalThis !== 'undefined')
|
|
32
47
|
return globalThis;
|
|
@@ -111,12 +126,12 @@ const cryptoPolyfill = {
|
|
|
111
126
|
// Node: back the CSPRNG with `node:crypto`. This is the path that matters on
|
|
112
127
|
// Node runtimes shipping WITHOUT a global WebCrypto — where delegating to
|
|
113
128
|
// the RN-only expo-crypto stub would throw.
|
|
114
|
-
if ((0,
|
|
129
|
+
if ((0, random_1.isNodeJS)() && fillFromNodeCrypto(array)) {
|
|
115
130
|
return array;
|
|
116
131
|
}
|
|
117
132
|
// React Native (and any non-Node host without WebCrypto): synchronous
|
|
118
|
-
// expo-crypto via @oxy.so/protocol's RN `platform/
|
|
119
|
-
const bytes = (0,
|
|
133
|
+
// expo-crypto via @oxy.so/protocol's RN `platform/random` variant.
|
|
134
|
+
const bytes = (0, random_1.getRandomBytesRN)(array.byteLength);
|
|
120
135
|
const uint8View = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
|
|
121
136
|
uint8View.set(bytes);
|
|
122
137
|
return array;
|
package/dist/cjs/index.js
CHANGED
|
@@ -24,7 +24,10 @@ exports.buildPaginationParams = exports.buildUrl = exports.buildSearchParams = e
|
|
|
24
24
|
exports.registrableApex = exports.getAccountColor = exports.formatPublicKeyHandle = exports.getAccountFallbackHandle = exports.getAccountDisplayName = exports.createQuickAccount = exports.buildAccountsArray = exports.updateAvatarVisibility = exports.isDev = exports.consoleSink = exports.resetLoggerConfig = exports.getLoggerConfig = exports.configureLogger = exports.createLogger = exports.logger = exports.normalizeMultilineText = exports.normalizeInlineText = exports.validateAndSanitizeUserInput = exports.isValidObjectId = exports.sanitizeHTML = exports.sanitizeString = exports.isValidFileType = exports.isValidFileSize = exports.isValidDate = exports.isValidURL = exports.isValidUUID = exports.isValidObject = exports.isValidArray = exports.isRequiredBoolean = exports.isRequiredNumber = exports.isRequiredString = exports.DISPLAY_NAME_UNFLANKED_SEPARATOR_SOURCE = exports.DISPLAY_NAME_ORPHANED_MARK_SOURCE = exports.DISPLAY_NAME_DISALLOWED_SOURCE = exports.DISPLAY_NAME_ALLOWED_SCRIPTS = exports.isValidDisplayName = exports.isValidPassword = exports.isValidEmail = exports.DISPLAY_NAME_INVALID_MESSAGE = exports.MAX_DISPLAY_NAME_LENGTH = exports.PASSWORD_REGEX = exports.EMAIL_REGEX = exports.retryAsync = exports.validateRequiredFields = exports.parseHttpErrorBody = exports.isHttpRequestError = exports.handleHttpError = exports.createApiError = exports.ErrorCodes = exports.safeJsonParse = void 0;
|
|
25
25
|
exports.decideSharedDeviceJoin = exports.createSharedMirroringAuthStateStore = exports.AUTH_STATE_STORAGE_KEY = exports.createMemoryAuthStateStore = exports.createNativeAuthStateStore = exports.createWebAuthStateStore = exports.createAccountDialogController = exports.AccountDialogController = exports.resolveAccountDelegationAccess = exports.canSwitchIntoAccount = exports.isSwitchTargetAccount = exports.showsPrincipalHeaders = exports.buildSwitcherRows = exports.resolveDeviceContext = exports.resolveActiveContext = exports.projectDevicePrincipals = exports.directoryHandle = exports.directoryDisplayName = exports.canActivateContext = exports.accountIdsOf = exports.activeUserOf = exports.activeSessionIdOf = exports.deviceStateToClientSessions = exports.createSessionClient = exports.createSessionClientHost = exports.SessionClient = exports.isAllowedDeviceJoinOrigin = exports.isOfficialWebOrigin = exports.isLoopbackOrigin = exports.consumeOAuthReturnPath = exports.persistOAuthReturnPath = exports.clearOAuthHandshake = exports.readOAuthHandshake = exports.persistOAuthHandshake = exports.canonicalizeOAuthRedirectUri = exports.normalizeOAuthRedirectUri = exports.OXY_OAUTH_RETURN_PATH_STORAGE_KEY = exports.OXY_OAUTH_REDIRECT_URI_STORAGE_KEY = exports.OXY_OAUTH_CODE_VERIFIER_STORAGE_KEY = exports.OXY_OAUTH_STATE_STORAGE_KEY = exports.OXY_AUTHORIZE_URL = exports.DEFAULT_OAUTH_SCOPE = exports.generatePkcePair = exports.generateOAuthState = exports.computeCodeChallenge = exports.buildOAuthAuthorizeUrl = exports.runColdBoot = exports.isOxyRpOrigin = exports.IDENTITY_WEB_ORIGIN = exports.CENTRAL_IDP_APEX = void 0;
|
|
26
26
|
exports.packageInfo = exports.runSessionColdBoot = exports.OXY_INFERENCE_BASE_URL = exports.OxyInferenceProtocolError = exports.OxyInferenceError = exports.OxyInferenceClient = exports.TOKEN_REFRESH_LEAD_MS = exports.startTokenRefreshScheduler = exports.installAuthRefreshHandler = exports.createAuthRefreshHandler = exports.refreshDeviceSecretArm = exports.refreshPersistedSession = exports.AccountNotOnDeviceError = exports.establishIdentitySession = exports.resolveIdentityPin = exports.IDENTITY_PIN_STORAGE_KEY = exports.identityPinMatches = exports.createMemoryIdentityPinStore = exports.createNativeIdentityPinStore = exports.createWebIdentityPinStore = exports.readLocalDeviceCredential = exports.publishProvenDeviceCredential = exports.normalizeSharedDeviceSessionRead = exports.decideSharedDevicePublish = void 0;
|
|
27
|
-
// Ensure crypto polyfills are loaded before anything else
|
|
27
|
+
// Ensure crypto polyfills are loaded before anything else. This MUST stay the
|
|
28
|
+
// first import: `@noble/hashes` captures `globalThis.crypto` when it is
|
|
29
|
+
// evaluated, so the shim has to exist before any module below reaches it (see
|
|
30
|
+
// the evaluation-order note in `./crypto/polyfill`).
|
|
28
31
|
require("./crypto/polyfill");
|
|
29
32
|
// ---------------------------------------------------------------------------
|
|
30
33
|
// API client
|
|
@@ -145,9 +145,14 @@ class OxyInferenceClient {
|
|
|
145
145
|
* both see the PUBLIC catalogue; only an internal/system application's
|
|
146
146
|
* service token sees internal-only routes.
|
|
147
147
|
*
|
|
148
|
-
* **`[]` is a normal answer
|
|
149
|
-
*
|
|
150
|
-
*
|
|
148
|
+
* **`[]` is a normal answer**: a route is not publicly exposed until
|
|
149
|
+
* somebody has reviewed the right to resell it. An official application's
|
|
150
|
+
* credential also sees the internal catalogue Oxy keeps in step with
|
|
151
|
+
* Kaana automatically.
|
|
152
|
+
*
|
|
153
|
+
* Each entry's `capabilities.reasoningEfforts` lists the efforts a request
|
|
154
|
+
* may name in `reasoning.effort` (empty: none), and `releasedAt`, when
|
|
155
|
+
* present, is the date the upstream provider published the model.
|
|
151
156
|
*/
|
|
152
157
|
async listModels(options = {}) {
|
|
153
158
|
const body = await __classPrivateFieldGet(this, _OxyInferenceClient_instances, "m", _OxyInferenceClient_request).call(this, 'GET', '/v1/models', { ...(options.signal === undefined ? {} : { signal: options.signal }) });
|
|
@@ -496,6 +496,7 @@ function OxyServicesUtilityMixin(Base) {
|
|
|
496
496
|
return onError(error);
|
|
497
497
|
return res.status(401).json(error);
|
|
498
498
|
}
|
|
499
|
+
const tier = decoded.tier === 'internal' ? 'internal' : 'external';
|
|
499
500
|
// Read delegated user ID from header
|
|
500
501
|
const oxyUserIdRaw = req.headers['x-oxy-user-id'];
|
|
501
502
|
const oxyUserId = isExactNonEmptyServiceClaim(oxyUserIdRaw) ? oxyUserIdRaw : null;
|
|
@@ -516,12 +517,21 @@ function OxyServicesUtilityMixin(Base) {
|
|
|
516
517
|
return onError(error);
|
|
517
518
|
return res.status(401).json(error);
|
|
518
519
|
}
|
|
519
|
-
//
|
|
520
|
-
//
|
|
521
|
-
//
|
|
522
|
-
//
|
|
523
|
-
|
|
524
|
-
|
|
520
|
+
// One of Oxy's own applications acts for a user without a grant:
|
|
521
|
+
// inside the ecosystem that is trust, not consent. It still acts
|
|
522
|
+
// with the USER's authority only — what that user may do is for the
|
|
523
|
+
// receiving service to check.
|
|
524
|
+
if (oxyUserId && tier === 'internal') {
|
|
525
|
+
req.userId = oxyUserId;
|
|
526
|
+
req.user = { id: oxyUserId };
|
|
527
|
+
req.serviceActingAs = { userId: oxyUserId, scopes: [] };
|
|
528
|
+
}
|
|
529
|
+
else if (oxyUserId) {
|
|
530
|
+
// C3: an EXTERNAL service may only act as a user when an explicit
|
|
531
|
+
// ServiceActingAs grant exists for that (appId, userId) pair.
|
|
532
|
+
// Without the grant we MUST refuse — silently attaching
|
|
533
|
+
// `req.userId = oxyUserId` would let any service impersonate
|
|
534
|
+
// any user simply by setting the header.
|
|
525
535
|
const grant = await oxyInstance.verifyServiceActingAs(appId, oxyUserId);
|
|
526
536
|
if (!grant || !grant.authorized) {
|
|
527
537
|
logger_1.logger.warn('[oxy.auth] Service token rejected — no delegation grant', {
|
|
@@ -572,6 +582,7 @@ function OxyServicesUtilityMixin(Base) {
|
|
|
572
582
|
ownerAccountId,
|
|
573
583
|
scopes: Array.isArray(decoded.scopes) ? decoded.scopes : [],
|
|
574
584
|
environment,
|
|
585
|
+
tier,
|
|
575
586
|
};
|
|
576
587
|
if (debug) {
|
|
577
588
|
logger_1.logger.debug(`[oxy.auth] Service token OK app=${decoded.appName} delegateUser=${oxyUserId || '(none)'}`, {
|
|
@@ -1004,6 +1015,12 @@ function OxyServicesUtilityMixin(Base) {
|
|
|
1004
1015
|
});
|
|
1005
1016
|
return;
|
|
1006
1017
|
}
|
|
1018
|
+
// Oxy's own applications are trusted app to app; scopes are the
|
|
1019
|
+
// external lane.
|
|
1020
|
+
if (req.serviceApp.tier === 'internal') {
|
|
1021
|
+
next();
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
1007
1024
|
const appHasScope = appScopes.includes(scope);
|
|
1008
1025
|
const delegationHasScope = delegatedScopes.includes(scope);
|
|
1009
1026
|
const hasRequiredScope = req.serviceActingAs
|