fix(api): replace crypto-js with Web Crypto API#1
Open
ohld wants to merge 1 commit intoRSquad:masterfrom
Open
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
@ton-pay/apibreaks Next.js builds with hundreds of "Module not found" errors (cipher-core,aes,blowfish). The package bundles all 37 crypto-js sub-modules (228KB) vianoExternal: ['crypto-js']in tsup — but only usesHmacSHA256for webhook signature verification.Hit this while building a TMA with TON payments on Next.js. Had to drop
@ton-pay/apientirely and use rawtonConnectUI.sendTransaction()as a workaround.Fix
Replaced
crypto-jswith the Web Crypto API (crypto.subtle.importKey+crypto.subtle.sign). This is:The tradeoff:
verifySignatureis now async (returnsPromise<boolean>). Since it's a server-side webhook verification function, this should be fine — webhook handlers are already async.Changes
packages/api/src/utils/verify-signature.ts— replaced crypto-js import with Web Crypto APIpackages/api/package.json— removedcrypto-jsand@types/crypto-jsdependenciespackages/api/tsup.config.ts— removednoExternal: ['crypto-js']Repro (before this fix)
npx create-next-app@latest myapp --typescript --appnpm install @ton-pay/apicreateTonPayTransferin any filenpm run build→ hundreds of "Module not found: Can't resolve './cipher-core'" errors