feat(statics): add runtime validation for AMS token metadata (CGD-748)#8925
Draft
bitgo-ai-agent-dev[bot] wants to merge 1 commit into
Draft
feat(statics): add runtime validation for AMS token metadata (CGD-748)#8925bitgo-ai-agent-dev[bot] wants to merge 1 commit into
bitgo-ai-agent-dev[bot] wants to merge 1 commit into
Conversation
Add validateAmsTokenConfig and validateTrimmedAmsTokenConfig functions that verify required fields, decimalPlaces (finite non-negative integer), and feature arrays (only known CoinFeature values) before AMS token metadata is used to construct coin objects. - decimalPlaces: guards against NaN, Infinity, negatives, non-integers that would corrupt Math.pow(10, decimalPlaces) in getBaseFactor() - features / additionalFeatures / excludedFeatures: guards against unknown string values that could bypass contract address checks - Required string fields: guards against missing or empty values Validation is called in createToken(), createTokenUsingTrimmedConfigDetails(), and createTokenMapUsingTrimmedConfigDetails() (where invalid tokens are skipped with a console.warn rather than throwing). 21 new unit tests cover valid configs, each invalid case, and the integration with createToken / createTokenMapUsingTrimmedConfigDetails. Ticket: CGD-748 Session-Id: 8c327ce7-3f5a-40aa-9516-1aa73939d1e1 Task-Id: 5aa45fd0-f207-4868-8327-1d13d7a1e234
b85745b to
f98d813
Compare
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.
Summary
validateAmsTokenConfigandvalidateTrimmedAmsTokenConfigfunctions to@bitgo/staticsthat validate AMS token metadata at the boundary before it reaches coin factory constructorsdecimalPlacesagainst NaN, Infinity, negative values, and non-integers that would corruptMath.pow(10, decimalPlaces)ingetBaseFactor()implementationsfeatures/additionalFeatures/excludedFeaturesarrays against unknown string values that bypass contract address format checksid,name,fullName,family,asset) against missing or empty valuesChanges
modules/statics/src/coins.ts: Two new exported validation functions;validateAmsTokenConfigcalled at the top ofcreateToken();validateTrimmedAmsTokenConfigcalled increateTokenMapUsingTrimmedConfigDetails()(skip-and-warn on invalid) andcreateTokenUsingTrimmedConfigDetails()(throws on invalid)modules/statics/test/unit/coins.ts: 21 new unit tests covering valid configs, each invalid field case, and integration with createToken / createTokenMapUsingTrimmedConfigDetailsTest plan
yarn unit-test --scope @bitgo/staticspasses (29,120 tests including 21 new)yarn unit-test --scope @bitgo/statics -- --grep validateAmsTokenConfig— 14 passingyarn unit-test --scope @bitgo/statics -- --grep validateTrimmedAmsTokenConfig— 7 passingFixes: CGD-748 / IS-783
🤖 Generated with Ralph