19 lines
1.9 KiB
JavaScript
19 lines
1.9 KiB
JavaScript
const fs=require('node:fs'),path=require('node:path'),assert=require('node:assert/strict'),vm=require('node:vm'),crypto=require('node:crypto');
|
|
const ts=require('../node_modules/typescript');
|
|
const ROOT=path.resolve(__dirname,'..'),DIR=path.join(ROOT,'storage/app/private/investmoz-v2/portal-audit');
|
|
const plan=JSON.parse(fs.readFileSync(path.join(DIR,'portal-stability-latest.json')));
|
|
const file=path.join(plan.source,'resources/js/lib/operation-key.ts'),text=fs.readFileSync(file,'utf8');
|
|
const script=ts.transpileModule(text,{compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2022},reportDiagnostics:true});
|
|
assert(!(script.diagnostics??[]).some(d=>d.category===ts.DiagnosticCategory.Error));
|
|
function load(c){const exports={};const context=vm.createContext({exports,crypto:c,Uint8Array,Error,Array});new vm.Script(script.outputText).runInContext(context);return exports.createOperationKey;}
|
|
const pattern=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
const native=load(crypto.webcrypto);assert.match(native(),pattern);
|
|
const compatible=load({getRandomValues:crypto.webcrypto.getRandomValues.bind(crypto.webcrypto)}),keys=new Set();
|
|
for(let i=0;i<2000;i++){const key=compatible();assert.match(key,pattern);assert(!keys.has(key));keys.add(key);}
|
|
assert.throws(()=>load({})(),/geração criptográfica segura/);assert.throws(()=>load(undefined)(),/geração criptográfica segura/);
|
|
assert(!/Math\.random|Date\.now|new Date/.test(text));
|
|
const proof={result:'passed',native_UUID:true,getRandomValues_only_UUID_v4:true,controlled_failure_without_secure_generator:true,
|
|
weak_random_or_timestamp:false,retry_scope:'UUID retained by each caller; separate browser criteria verify actual retry/receipt behavior',
|
|
input_sha256:crypto.createHash('sha256').update(text).digest('hex'),active_writes:0};
|
|
fs.writeFileSync(path.join(DIR,'portal-stability-operation-key-test.json'),JSON.stringify(proof,null,2));console.log(JSON.stringify(proof));
|