Skip to content

Use web api crypto instead of node:crypto for targeting evaluation #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Aug 26, 2024
Merged
Prev Previous commit
Next Next commit
add error message
  • Loading branch information
zhiyuanliang-ms committed Aug 20, 2024
commit ec8905c74b0a87e164c5a8960997c9c9544b98df
9 changes: 7 additions & 2 deletions src/filter/TargetingFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@
}
// Fallback to native Node.js crypto module
else {
crypto = require("crypto"); // maybe wrap with try-catch in case of uncovered runtimes... or you maybe want to fail the program because there's no way to calc hash then
try {
crypto = require('crypto');

Check failure on line 146 in src/filter/TargetingFilter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Strings must use doublequote

Check failure on line 146 in src/filter/TargetingFilter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Strings must use doublequote
} catch (error) {
console.error('Failed to load the crypto module:', error.message);

Check failure on line 148 in src/filter/TargetingFilter.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Strings must use doublequote

Check failure on line 148 in src/filter/TargetingFilter.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Strings must use doublequote
throw error;
}
}

// In the browser, use crypto.subtle.digest
Expand All @@ -159,4 +164,4 @@
const uint32 = hash.readUInt32LE(0);
return uint32;
}
}
}
Loading