You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(stateless.js): support @solana/web3.js v3 in synchronous PDA derivation (#2395) - #2396
@lightprotocol/stateless.js declares "@solana/web3.js": ">=1.73.5" in peerDependencies. When consumers install @solana/web3.js@3.x (the v3 compatibility bridge), PublicKey no longer exposes PublicKey.findProgramAddressSync or PublicKey.createProgramAddressSync (which were removed in favor of async WebCrypto PDA helpers in @solana/addresses), causing PackedAccounts.addSystemAccounts(), PackedAccounts.addSystemAccountsV2(), defaultStaticAccountsStruct(), and LightSystemProgram.deriveCompressedSolPda() to throw at runtime:
cd ~/projects/light-protocol
@lightprotocol/stateless.js declares "@solana/web3.js": ">=1.73.5" in peerDependencies. When consumers install @solana/web3.js@3.x (the v3 compatibility bridge), PublicKey no longer exposes PublicKey.findProgramAddressSync or PublicKey.createProgramAddressSync (which were removed in favor of async WebCrypto PDA helpers in @solana/addresses), causing PackedAccounts.addSystemAccounts(), PackedAccounts.addSystemAccountsV2(), defaultStaticAccountsStruct(), and LightSystemProgram.deriveCompressedSolPda() to throw at runtime:
TypeError: PublicKey.findProgramAddressSync is not a function
Additionally, PublicKey in @solana/web3.js@3.x exposes .toBytes() rather than .toBuffer(), while PublicKey.isOnCurve() remains synchronous.
Changes
Added js/stateless.js/src/utils/pda.ts with findProgramAddressSync and createProgramAddressSync:
Delegates to PublicKey.findProgramAddressSync when available (@solana/web3.js v1.x).
Falls back to synchronous SHA-256 PDA derivation using @noble/hashes/sha256 (already a direct dependency of @lightprotocol/stateless.js) + PublicKey.isOnCurve() when PublicKey.findProgramAddressSync is absent (@solana/web3.js v3.x).
Safely extracts program ID bytes via programId.toBuffer() or Buffer.from(programId.toBytes()).
Replaced direct PublicKey.findProgramAddressSync calls in:
js/stateless.js/src/constants.ts
js/stateless.js/src/utils/instruction.ts
js/stateless.js/src/programs/system/program.ts
Added unit tests in js/stateless.js/tests/unit/utils/packed-accounts.test.ts verifying identical PDA derivation and PackedAccounts behavior when PublicKey.findProgramAddressSync is unavailable.
Test Plan
pnpm --filter @lightprotocol/stateless.js test:unit:all (126/126 unit tests passing)
js/stateless.js/src/constants.ts is excluded by none and included by none
js/stateless.js/src/programs/system/program.ts is excluded by none and included by none
js/stateless.js/src/utils/instruction.ts is excluded by none and included by none
js/stateless.js/src/utils/pda.ts is excluded by none and included by none
js/stateless.js/tests/unit/utils/packed-accounts.test.ts is excluded by none and included by none
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Tip
🎯 Customize your risk assessments
Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.
✅ Automatic approvals, with your rules
Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2395
@lightprotocol/stateless.jsdeclares"@solana/web3.js": ">=1.73.5"inpeerDependencies. When consumers install@solana/web3.js@3.x(the v3 compatibility bridge),PublicKeyno longer exposesPublicKey.findProgramAddressSyncorPublicKey.createProgramAddressSync(which were removed in favor of async WebCrypto PDA helpers in@solana/addresses), causingPackedAccounts.addSystemAccounts(),PackedAccounts.addSystemAccountsV2(),defaultStaticAccountsStruct(), andLightSystemProgram.deriveCompressedSolPda()to throw at runtime:cd ~/projects/light-protocol
cat << 'EOF' > /tmp/pr_2395_body.md
Summary
Fixes #2395
@lightprotocol/stateless.jsdeclares"@solana/web3.js": ">=1.73.5"inpeerDependencies. When consumers install@solana/web3.js@3.x(the v3 compatibility bridge),PublicKeyno longer exposesPublicKey.findProgramAddressSyncorPublicKey.createProgramAddressSync(which were removed in favor of async WebCrypto PDA helpers in@solana/addresses), causingPackedAccounts.addSystemAccounts(),PackedAccounts.addSystemAccountsV2(),defaultStaticAccountsStruct(), andLightSystemProgram.deriveCompressedSolPda()to throw at runtime:Additionally,
PublicKeyin@solana/web3.js@3.xexposes.toBytes()rather than.toBuffer(), whilePublicKey.isOnCurve()remains synchronous.Changes
js/stateless.js/src/utils/pda.tswithfindProgramAddressSyncandcreateProgramAddressSync:PublicKey.findProgramAddressSyncwhen available (@solana/web3.jsv1.x).@noble/hashes/sha256(already a direct dependency of@lightprotocol/stateless.js) +PublicKey.isOnCurve()whenPublicKey.findProgramAddressSyncis absent (@solana/web3.jsv3.x).programId.toBuffer()orBuffer.from(programId.toBytes()).PublicKey.findProgramAddressSynccalls in:js/stateless.js/src/constants.tsjs/stateless.js/src/utils/instruction.tsjs/stateless.js/src/programs/system/program.tsjs/stateless.js/tests/unit/utils/packed-accounts.test.tsverifying identical PDA derivation andPackedAccountsbehavior whenPublicKey.findProgramAddressSyncis unavailable.Test Plan
pnpm --filter @lightprotocol/stateless.js test:unit:all(126/126 unit tests passing)pnpm --filter @lightprotocol/stateless.js lint&pnpm --filter @lightprotocol/stateless.js build