Skip to content

Conversation

sujalsalekar
Copy link

@sujalsalekar sujalsalekar commented May 11, 2025

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

}

throw new Error(`Unsupported beacon type: ${chainInfo.schemeID}`);
} catch (error) {
Copy link
Contributor

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) {
Copy link
Contributor

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) {
Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 accepted too

Copy link
Contributor

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)) {
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants