-
Notifications
You must be signed in to change notification settings - Fork 12
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
fix(eth signer): use a unique anchor in ans-104 headers #311
Conversation
this will produce non-deterministic IDs for all signer types that dont provide salt PE-7158
src/common/contracts/ao-process.ts
Outdated
65 + Math.floor(Math.random() * 26), | ||
); | ||
// anchor is a random string produce non-deterministic messages IDs | ||
const anchor = Date.now().toString().padEnd(32, randomLetter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would only let users send basic messages up to 26 times, right? Maybe just use fully random bytes or some combination of the current timestamp plus random bytes. Here's a way to produce random characters:
function getRandomText(length = 32) {
const array = new Uint8Array(length);
crypto.getRandomValues(array);
return Array.from(array, byte => byte.toString(16).padStart(2, '0')).join('').slice(0, length);
}
crypto.getRandomValues generates cryptographically secure random values.
Array.from with .toString(16): Converts each byte to a hexadecimal string (base 16).
.padStart(2, '0'): Ensures each byte is represented as two characters (e.g., 0a instead of a).
.slice(0, length): Ensures the resulting string is exactly the specified length.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was trying to avoid putting crypto
import here as we don't access it much in the SDK. maybe something like this?
export function randomString(length: number): string {
const chars =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
for (let i = 0; i < length; i++) {
result += chars.charAt(Math.floor(Math.random() * chars.length));
}
return result;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That won't perform as well, I believe, and is less likely to distribute randomness uniformly. If we're already relying on crypto elsewhere and if it won't create additional integration stresses for SDK clients, I recommend we use it.
🎉 This PR is included in version 3.0.1-alpha.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
this will produce non-deterministic IDs for all signer types that dont provide salt
PE-7158