Skip to content

Commit 93627f4

Browse files
thymikeeclaude
andcommitted
fix(revyl): derive the runtime owner with scrypt and key fixture overrides by Map
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 1f830c7 commit 93627f4

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

‎packages/provider-revyl/src/revyl-backend.fixtures.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export async function startRevylFixtureBackend(
6767
let healthPolls = 0;
6868
const screen = options.screen ?? DEFAULT_IOS_SCREEN;
6969

70+
const overrides = new Map(Object.entries(options.respond ?? {}));
7071
const server = http.createServer((request, response) => {
7172
const chunks: Buffer[] = [];
7273
request.on('data', (chunk: Buffer) => chunks.push(chunk));
@@ -83,7 +84,7 @@ export async function startRevylFixtureBackend(
8384
clientHeader: header(request, 'x-revyl-client'),
8485
agentHeader: header(request, 'x-revyl-agent'),
8586
});
86-
const override = options.respond?.[`${method} ${url}`];
87+
const override = overrides.get(`${method} ${url}`);
8788
if (typeof override === 'function') {
8889
const value = override();
8990
respondWith(response, { body: value });

‎packages/provider-revyl/src/runtime-instance.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
import { createHash } from 'node:crypto';
1+
import { scryptSync } from 'node:crypto';
22
import { REVYL_DEFAULT_BACKEND_URL } from './revyl-client.ts';
33

4+
const RUNTIME_INSTANCE_KEY_LENGTH = 16;
5+
const RUNTIME_INSTANCE_SCRYPT_COST = 16_384;
6+
const RUNTIME_INSTANCE_SCRYPT_MAX_MEMORY = 64 * 1024 * 1024;
7+
const RUNTIME_INSTANCE_SALT = 'agent-device:revyl-runtime-owner:v1';
8+
49
/**
510
* The stable identity of one Revyl runtime, and so of one owner. Two runtimes that rent devices for
611
* the same account against the same origin share it; two accounts never do. The key is hashed rather
@@ -17,5 +22,11 @@ export function resolveRevylRuntimeInstance(
1722
backendUrl: options.backendUrl ?? REVYL_DEFAULT_BACKEND_URL,
1823
apiKey: options.apiKey,
1924
});
20-
return `principal-${createHash('sha256').update(principal).digest('hex').slice(0, 32)}`;
25+
const fingerprint = scryptSync(principal, RUNTIME_INSTANCE_SALT, RUNTIME_INSTANCE_KEY_LENGTH, {
26+
N: RUNTIME_INSTANCE_SCRYPT_COST,
27+
r: 8,
28+
p: 1,
29+
maxmem: RUNTIME_INSTANCE_SCRYPT_MAX_MEMORY,
30+
});
31+
return `principal-${fingerprint.toString('hex')}`;
2132
}

0 commit comments

Comments
 (0)