-
Notifications
You must be signed in to change notification settings - Fork 22
improve error handling, buffer operations, and TypeScript configurat… #103
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
base: master
Are you sure you want to change the base?
Conversation
} | ||
|
||
throw new Error(`Unsupported beacon type: ${chainInfo.schemeID}`); | ||
} catch (error) { |
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.
catching locally thrown errors feels like a bit of a code smell. Also this could be a breaking change for users expecting certain cryptographic errors to throw exceptions
const buffer = Buffer.alloc(8) | ||
buffer.writeBigUInt64BE(BigInt(round)) | ||
return buffer | ||
if (!Number.isInteger(round) || round < 0) { |
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.
the check here makes sense, though I dunno the rationale behind replacing writeBigUint64BE
if (!!this.options.chainVerificationParams && !isValidInfo(chainInfo, this.options.chainVerificationParams)) { | ||
throw Error(`The chain info retrieved from ${this.baseUrl} did not match the verification params!`) | ||
async get(roundNumber: number): Promise<RandomnessBeacon> { | ||
if (!Number.isInteger(roundNumber) || roundNumber < 1) { |
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.
we actually accept 0
too though it returns latest
roundNumber = roundAt(Date.now(), info); | ||
} | ||
|
||
if (roundNumber < 1) { |
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.
0 accepted too
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.
hmm although the old code didn't accept it 🤔
@@ -6,64 +6,107 @@ import {LIB_VERSION} from './version' | |||
|
|||
export function sleep(timeMs: number): Promise<void> { | |||
return new Promise(resolve => { | |||
if (!Number.isFinite(timeMs)) { |
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.
bit of a random change - this is only used a few places in the lib itself, none of which take Infinity
afaik
fix: Improve SDK stability with enhanced error handling, BigInt buffer fixes, and TypeScript updates
improved error handling for more robust runtime behavior.
Fixed buffer operations involving BigInt to ensure accurate processing.
Updated TypeScript configuration to strengthen type safety and developer experience.
Enhanced beacon verification logic for better reliability and correctne