Skip to content

Add warnings for MPTokenMetadata - XLS-89d#3041

Merged
Patel-Raj11 merged 16 commits intomainfrom
mpt-metadata-warning
Jul 24, 2025
Merged

Add warnings for MPTokenMetadata - XLS-89d#3041
Patel-Raj11 merged 16 commits intomainfrom
mpt-metadata-warning

Conversation

@Patel-Raj11
Copy link
Collaborator

High Level Overview of Change

This PR adds console warnings to MPTokenIssuanceCreate transaction if the MPTokenMetadata does not follow XLS-89d standard.

Context of Change

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (non-breaking change that only restructures code)
  • Tests (You added tests for code that already exists, or your new feature included in this PR)
  • Documentation Updates
  • Release

Did you update HISTORY.md?

  • Yes
  • No, this change does not impact library users

Test Plan

Added unit tests.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 11, 2025

"""

Walkthrough

This update adds detailed validation logic and runtime warnings for the MPTokenMetadata field in MPTokenIssuanceCreate and VaultCreate transactions, introduces new TypeScript interfaces for metadata structure, exports the metadata validation function, updates changelog, and expands test coverage with fixtures and warning verification.

Changes

Files/Paths Change Summary
packages/xrpl/HISTORY.md Added changelog entry documenting MPTokenIssuanceCreate warning messages and XLS-89d standard reference.
packages/xrpl/src/models/common/index.ts Added new interfaces MPTokenMetadata and MPTokenMetadataUrl defining metadata structure.
packages/xrpl/src/models/transactions/common.ts Added constants and validateMPTokenMetadata function for comprehensive metadata validation per XLS-89d.
packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts Enhanced metadata validation logic; added warnings for invalid metadata without blocking validation.
packages/xrpl/src/models/transactions/vaultCreate.ts Replaced hardcoded max length with constant; added metadata validation warnings.
packages/xrpl/src/models/transactions/index.ts Exported validateMPTokenMetadata from common module.
packages/xrpl/test/fixtures/transactions/mptokenMetadata.json Added JSON fixture with multiple MPTokenMetadata validation test cases and expected messages.
packages/xrpl/test/models/MPTokenIssuanceCreate.test.ts Updated metadata test data; added tests verifying warnings on invalid metadata via console.warn spy.
packages/xrpl/test/models/vaultCreate.test.ts Added tests to verify warnings are logged for invalid MPTokenMetadata in VaultCreate transactions.
packages/xrpl/test/models/utils.test.ts Added tests iterating over fixture cases to validate MPTokenMetadata and assert expected validation messages.
packages/xrpl/src/models/methods/subscribe.ts Added optional network_id property to LedgerStream, LedgerStreamResponse, and ValidationStream interfaces.
packages/xrpl/test/integration/requests/subscribe.test.ts Updated test to expect network_id field in ledger subscription stream response.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • achowdhry-ripple
  • ckeshava
  • khancode

Poem

🐇
A token’s tale in metadata grows,
With warnings now where caution shows.
New tests abound, their fixtures bright,
Ensuring fields are typed just right.
So hop along this code review,
For standards shine in what we do!
🌱✨
"""

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm warn EBADENGINE Unsupported engine {
npm warn EBADENGINE package: '@es-joy/jsdoccomment@0.36.1',
npm warn EBADENGINE required: { node: '^14 || ^16 || ^17 || ^18 || ^19' },
npm warn EBADENGINE current: { node: 'v24.3.0', npm: '11.4.2' }
npm warn EBADENGINE }
npm warn EBADENGINE Unsupported engine {
npm warn EBADENGINE package: 'eslint-plugin-jsdoc@39.9.1',
npm warn EBADENGINE required: { node: '^14 || ^16 || ^17 || ^18 || ^19' },
npm warn EBADENGINE current: { node: 'v24.3.0', npm: '11.4.2' }
npm warn EBADENGINE }
npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-07-24T16_58_10_473Z-debug-0.log

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d385b31 and 30dd907.

📒 Files selected for processing (2)
  • packages/xrpl/src/models/methods/subscribe.ts (3 hunks)
  • packages/xrpl/test/integration/requests/subscribe.test.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/xrpl/src/models/methods/subscribe.ts
  • packages/xrpl/test/integration/requests/subscribe.test.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: integration (22.x)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: browser (22.x)
  • GitHub Check: unit (20.x)
  • GitHub Check: build-and-lint (22.x)
  • GitHub Check: integration (20.x)
  • GitHub Check: unit (22.x)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch mpt-metadata-warning

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Patel-Raj11 Patel-Raj11 changed the title Mpt metadata warning Add warnings for MPTokenMetadata - XLS-89d Jul 11, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🔭 Outside diff range comments (1)
packages/xrpl/test/fixtures/transactions/mptokenMetadata.json (1)

217-218: Invalid JSON – stray line breaks the fixture

The solitary 218 after the closing bracket makes the file unparsable JSON.
Any consumer doing JSON.parse (the test runner, tools, IDEs) will throw.

  }
-]
-218
+]
🧹 Nitpick comments (2)
packages/xrpl/HISTORY.md (1)

13-13: Minor wording nit

Consider “Add warning messages for MPTokenIssuanceCreate …” – the preposition “for” reads better than “to” in this context.

-* Add warning messages to `MPTokenIssuanceCreate` transaction as per ...
+* Add warning messages for `MPTokenIssuanceCreate` transaction as per ...
packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts (1)

241-377: Consider refactoring for better maintainability.

The validation function is quite long (137 lines). Consider breaking it into smaller, focused functions for better readability and maintainability.

Example structure:

  • parseMetadata(input: string): unknown - Handle JSON parsing
  • validateMetadataStructure(obj: Record<string, unknown>): boolean - Validate object structure
  • validateMetadataContent(metadata: MPTokenMetadata): void - Validate content rules

This would make the code more modular and easier to test individually.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bc7fc4b and a859eac.

📒 Files selected for processing (5)
  • packages/xrpl/HISTORY.md (1 hunks)
  • packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts (4 hunks)
  • packages/xrpl/src/models/transactions/index.ts (1 hunks)
  • packages/xrpl/test/fixtures/transactions/mptokenMetadata.json (1 hunks)
  • packages/xrpl/test/models/MPTokenIssuanceCreate.test.ts (3 hunks)
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/test/integration/transactions/permissionedDomain.test.ts:25-80
Timestamp: 2025-01-08T02:12:28.489Z
Learning: The rippled C++ implementation (PR #5161) includes comprehensive test coverage for PermissionedDomain (XLS-80d) error cases. The JS SDK tests focus on the happy path since the error cases are already validated at the rippled level, following the principle of not duplicating complex validation testing across SDK implementations.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2895
File: packages/xrpl/test/models/DIDDelete.test.ts:28-31
Timestamp: 2025-02-12T23:30:40.622Z
Learning: In JavaScript/TypeScript transaction validation tests, object key validation can be performed using:
1. Object.keys() comparison with expected set
2. TypeScript interfaces with strict object literal checks
3. Object sanitization by filtering to allowed keys only
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2829
File: packages/xrpl/src/models/ledger/Credential.ts:36-36
Timestamp: 2024-12-09T07:06:47.258Z
Learning: In TypeScript interfaces, ensure that fields documented as optional are marked with the `?` operator to denote optionality.
packages/xrpl/HISTORY.md (5)
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#3027
File: packages/xrpl/src/models/ledger/MPTokenIssuance.ts:13-16
Timestamp: 2025-06-26T17:25:36.429Z
Learning: In the XRPL ecosystem, type choices for amount fields (like `number` vs `string`) in ledger objects such as `LockedAmount` vs `OutstandingAmount` in `MPTokenIssuance` are deliberate design decisions made across multiple products and cannot be changed unilaterally by individual contributors.
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2812
File: packages/xrpl/test/integration/transactions/payment.test.ts:41-43
Timestamp: 2024-10-30T01:05:33.583Z
Learning: In tests involving fee calculations for XRPL, avoid using default fee amounts. If unable to retrieve fee values from the latest validated ledger, throw an error instead of defaulting to a specific amount.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
packages/xrpl/src/models/transactions/index.ts (5)
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-08T16:29:11.194Z
Learning: In `generateModels.js`, the regex used to match `SubmittableTransaction` in `transaction.ts` is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-02T15:47:02.491Z
Learning: In `generateModels.js`, the regex used to match `SubmittableTransaction` in `transaction.ts` is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
packages/xrpl/test/models/MPTokenIssuanceCreate.test.ts (13)
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/test/integration/transactions/permissionedDomain.test.ts:25-80
Timestamp: 2025-01-08T02:12:28.489Z
Learning: The rippled C++ implementation (PR #5161) includes comprehensive test coverage for PermissionedDomain (XLS-80d) error cases. The JS SDK tests focus on the happy path since the error cases are already validated at the rippled level, following the principle of not duplicating complex validation testing across SDK implementations.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2873
File: packages/xrpl/test/integration/transactions/trustSet.test.ts:0-0
Timestamp: 2025-01-31T17:46:25.375Z
Learning: For the XRPL implementation, extensive test cases for deep freeze behavior (high/low side interactions, clearing flags, etc.) are maintained in the C++ implementation and don't need to be duplicated in the JavaScript implementation.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-02T15:47:02.491Z
Learning: In `generateModels.js`, the regex used to match `SubmittableTransaction` in `transaction.ts` is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-08T16:29:11.194Z
Learning: In `generateModels.js`, the regex used to match `SubmittableTransaction` in `transaction.ts` is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2801
File: packages/xrpl/test/models/Batch.test.ts:0-0
Timestamp: 2025-04-16T15:22:45.633Z
Learning: Using `as any` type assertions is acceptable in test files for the XRPL.js project, as strict typing is not required for test code.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2895
File: packages/xrpl/test/models/clawback.test.ts:0-0
Timestamp: 2025-02-12T23:28:55.377Z
Learning: The `validate` function in xrpl.js is synchronous and should be tested using `assert.doesNotThrow` rather than async assertions.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#3032
File: packages/xrpl/src/models/transactions/common.ts:689-698
Timestamp: 2025-07-10T22:04:59.970Z
Learning: In the XRPL.js library, the validateDomainID function in `packages/xrpl/src/models/transactions/common.ts` should only validate the length (64 characters) of domain IDs, not hex encoding. The rippled C++ implementation does not enforce any regex check on domain ID values, so additional hex validation is not required in the JS implementation.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2895
File: packages/xrpl/test/models/DIDDelete.test.ts:28-31
Timestamp: 2025-02-12T23:30:40.622Z
Learning: In JavaScript/TypeScript transaction validation tests, object key validation can be performed using:
1. Object.keys() comparison with expected set
2. TypeScript interfaces with strict object literal checks
3. Object sanitization by filtering to allowed keys only
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/src/models/transactions/common.ts:0-0
Timestamp: 2025-01-16T04:26:36.757Z
Learning: Test libraries like chai should not be used in source code. Use existing validation functions where available, or implement custom validation using ValidationError for runtime checks.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/src/models/transactions/common.ts:18-18
Timestamp: 2025-01-16T04:11:37.316Z
Learning: Test libraries like chai should not be used in source code. For runtime checks in browser-compatible code, use vanilla JS error throwing instead of assertion libraries.
packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts (17)
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2873
File: packages/xrpl/src/models/transactions/trustSet.ts:33-36
Timestamp: 2025-01-08T13:08:52.688Z
Learning: For trust-set transactions in XRPL, validation rules for flags should be implemented comprehensively rather than cherry-picking specific rules, as there are many interdependent validation rules associated with these flags.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#3032
File: packages/xrpl/src/models/transactions/common.ts:689-698
Timestamp: 2025-07-10T22:04:59.970Z
Learning: In the XRPL.js library, the validateDomainID function in `packages/xrpl/src/models/transactions/common.ts` should only validate the length (64 characters) of domain IDs, not hex encoding. The rippled C++ implementation does not enforce any regex check on domain ID values, so additional hex validation is not required in the JS implementation.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-02T15:47:02.491Z
Learning: In `generateModels.js`, the regex used to match `SubmittableTransaction` in `transaction.ts` is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-08T16:29:11.194Z
Learning: In `generateModels.js`, the regex used to match `SubmittableTransaction` in `transaction.ts` is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#3027
File: packages/xrpl/src/models/ledger/MPTokenIssuance.ts:13-16
Timestamp: 2025-06-26T17:25:36.429Z
Learning: In the XRPL ecosystem, type choices for amount fields (like `number` vs `string`) in ledger objects such as `LockedAmount` vs `OutstandingAmount` in `MPTokenIssuance` are deliberate design decisions made across multiple products and cannot be changed unilaterally by individual contributors.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/test/integration/transactions/permissionedDomain.test.ts:25-80
Timestamp: 2025-01-08T02:12:28.489Z
Learning: The rippled C++ implementation (PR #5161) includes comprehensive test coverage for PermissionedDomain (XLS-80d) error cases. The JS SDK tests focus on the happy path since the error cases are already validated at the rippled level, following the principle of not duplicating complex validation testing across SDK implementations.
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2829
File: packages/xrpl/src/models/transactions/CredentialAccept.ts:36-44
Timestamp: 2024-12-18T20:54:40.935Z
Learning: The validateCredentialType function already checks that CredentialType is a properly hex-encoded string within the allowed length.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/src/models/transactions/common.ts:0-0
Timestamp: 2025-01-16T04:26:36.757Z
Learning: Test libraries like chai should not be used in source code. Use existing validation functions where available, or implement custom validation using ValidationError for runtime checks.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2801
File: packages/xrpl/src/Wallet/batchSigner.ts:0-0
Timestamp: 2025-04-16T15:55:50.121Z
Learning: When using `encodeForSigningBatch` for Batch transactions in the XRPL.js library, the field names should use camelCase (`flags`, `txIDs`) even though the transaction object properties themselves use PascalCase (`Flags`, `TxIDs`).
Learnt from: mvadari
PR: XRPLF/xrpl.js#2895
File: packages/xrpl/test/models/clawback.test.ts:0-0
Timestamp: 2025-02-12T23:28:55.377Z
Learning: The `validate` function in xrpl.js is synchronous and should be tested using `assert.doesNotThrow` rather than async assertions.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2801
File: packages/xrpl/test/models/Batch.test.ts:0-0
Timestamp: 2025-04-16T15:22:45.633Z
Learning: Using `as any` type assertions is acceptable in test files for the XRPL.js project, as strict typing is not required for test code.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2829
File: packages/xrpl/src/models/methods/ledgerEntry.ts:74-85
Timestamp: 2024-12-12T01:12:01.868Z
Learning: In the XRPL.js library, request parameters use camelCase (e.g., `credentialType`), while transaction model fields follow the XRP Ledger protocol's PascalCase convention (e.g., `CredentialType`).
Learnt from: mvadari
PR: XRPLF/xrpl.js#2895
File: packages/xrpl/test/models/DIDDelete.test.ts:28-31
Timestamp: 2025-02-12T23:30:40.622Z
Learning: In JavaScript/TypeScript transaction validation tests, object key validation can be performed using:
1. Object.keys() comparison with expected set
2. TypeScript interfaces with strict object literal checks
3. Object sanitization by filtering to allowed keys only
packages/xrpl/test/fixtures/transactions/mptokenMetadata.json (4)
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2873
File: packages/xrpl/test/integration/transactions/trustSet.test.ts:0-0
Timestamp: 2025-01-31T17:46:25.375Z
Learning: For the XRPL implementation, extensive test cases for deep freeze behavior (high/low side interactions, clearing flags, etc.) are maintained in the C++ implementation and don't need to be duplicated in the JavaScript implementation.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/test/models/permissionedDomainDelete.test.ts:15-20
Timestamp: 2025-01-08T02:11:21.997Z
Learning: In validation test cases for XRPL transactions, using generic JSON input (e.g., `as any`) is preferred over strict typing as it better represents real-world scenarios where the `validate` method needs to handle arbitrary JSON/map/dictionary input from users.
🧬 Code Graph Analysis (1)
packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts (1)
packages/xrpl/src/models/transactions/common.ts (1)
  • isString (100-102)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: browser (22.x)
🔇 Additional comments (9)
packages/xrpl/test/fixtures/transactions/mptokenMetadata.json (1)

63-66: Key name typo: warningsMessages

Across all cases the property is spelled warningsMessages.
If the validation harness expects warningMessages (singular + plural) or a different key, every test will falsely fail. Double-check the expected schema.

No code change suggested here—verify the contract first.

Also applies to: 77-80, 91-94, 105-108, 119-122, 132-135, 153-156, 170-173, 199-205

packages/xrpl/src/models/transactions/index.ts (1)

58-63: LGTM – new exports correctly wired

MPTokenMetadata and MPTokenMetadataUrl are now available to callers; location and style match existing export patterns.

packages/xrpl/test/models/MPTokenIssuanceCreate.test.ts (3)

5-5: ****


28-35: Good alignment with XLS-89d standard.

The updated MPTokenMetadata structure properly demonstrates the expected format with all required fields.


143-174: Well-structured test suite for metadata warnings.

The test implementation correctly uses Jest spying to verify console warnings are emitted for various metadata compliance scenarios. The dynamic test generation from fixture data is a good practice for comprehensive coverage.

packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts (4)

1-2: ****


20-47: Constants correctly implement XLS-89d validation rules.

The validation constants properly define the required fields, asset classifications, and ticker format according to the standard.


237-237: Appropriate placement of warning logic.

The metadata warning function is correctly called after all validation checks.


382-396: Clean helper function implementation.

The URL structure validation helper is well-implemented with proper null checks and type validation.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts (2)

304-314: Improve validation strictness for additional_info object type.

The current validation for additional_info allows any object type, which may be too permissive. Consider checking for plain objects only to avoid unexpected behavior with Date, RegExp, or other object types.

  if (
    obj.additional_info != null &&
    !(
      isString(obj.additional_info) ||
-     (typeof obj.additional_info === 'object' &&
-       !Array.isArray(obj.additional_info))
+     (typeof obj.additional_info === 'object' &&
+       !Array.isArray(obj.additional_info) &&
+       obj.additional_info.constructor === Object)
    )
  ) {

250-377: Consider refactoring to improve maintainability.

The logWarningsForMPTMetadata function is quite long and complex. Consider extracting validation logic into smaller, focused functions to improve readability and maintainability.

For example, you could extract field validation:

function validateRequiredFields(obj: Record<string, unknown>): string[] {
  return MPT_META_REQUIRED_FIELDS.filter(field => !isString(obj[field]))
}

function validateOptionalFields(obj: Record<string, unknown>): string[] {
  const warnings: string[] = []
  if (obj.desc != null && !isString(obj.desc)) {
    warnings.push('desc must be a string.')
  }
  // ... other optional field validations
  return warnings
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a859eac and d2af89e.

📒 Files selected for processing (1)
  • packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts (4 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/test/integration/transactions/permissionedDomain.test.ts:25-80
Timestamp: 2025-01-08T02:12:28.489Z
Learning: The rippled C++ implementation (PR #5161) includes comprehensive test coverage for PermissionedDomain (XLS-80d) error cases. The JS SDK tests focus on the happy path since the error cases are already validated at the rippled level, following the principle of not duplicating complex validation testing across SDK implementations.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/test/integration/transactions/permissionedDomain.test.ts:25-80
Timestamp: 2025-01-08T02:12:28.489Z
Learning: For PermissionedDomain feature (XLS-80d), complex error cases like invalid credential format, duplicate credentials, and non-existent DomainID are tested in the rippled C++ implementation rather than being duplicated across SDK implementations like xrpl.js.
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#3032
File: packages/xrpl/src/models/transactions/common.ts:689-698
Timestamp: 2025-07-10T22:04:59.970Z
Learning: In the XRPL.js library, the validateDomainID function in `packages/xrpl/src/models/transactions/common.ts` should only validate the length (64 characters) of domain IDs, not hex encoding. The rippled C++ implementation does not enforce any regex check on domain ID values, so additional hex validation is not required in the JS implementation.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2873
File: packages/xrpl/test/integration/transactions/trustSet.test.ts:0-0
Timestamp: 2025-01-31T17:46:25.375Z
Learning: For the XRPL implementation, extensive test cases for deep freeze behavior (high/low side interactions, clearing flags, etc.) are maintained in the C++ implementation and don't need to be duplicated in the JavaScript implementation.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2895
File: packages/xrpl/test/models/clawback.test.ts:0-0
Timestamp: 2025-02-12T23:28:55.377Z
Learning: The `validate` function in xrpl.js is synchronous and should be tested using `assert.doesNotThrow` rather than async assertions.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2895
File: packages/xrpl/test/models/DIDDelete.test.ts:28-31
Timestamp: 2025-02-12T23:30:40.622Z
Learning: In JavaScript/TypeScript transaction validation tests, object key validation can be performed using:
1. Object.keys() comparison with expected set
2. TypeScript interfaces with strict object literal checks
3. Object sanitization by filtering to allowed keys only
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2829
File: packages/xrpl/src/models/ledger/Credential.ts:36-36
Timestamp: 2024-12-09T07:06:47.258Z
Learning: In TypeScript interfaces, ensure that fields documented as optional are marked with the `?` operator to denote optionality.
packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts (21)
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-02T15:47:02.491Z
Learning: In `generateModels.js`, the regex used to match `SubmittableTransaction` in `transaction.ts` is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-08T16:29:11.194Z
Learning: In `generateModels.js`, the regex used to match `SubmittableTransaction` in `transaction.ts` is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#3032
File: packages/xrpl/src/models/transactions/common.ts:689-698
Timestamp: 2025-07-10T22:04:59.970Z
Learning: In the XRPL.js library, the validateDomainID function in `packages/xrpl/src/models/transactions/common.ts` should only validate the length (64 characters) of domain IDs, not hex encoding. The rippled C++ implementation does not enforce any regex check on domain ID values, so additional hex validation is not required in the JS implementation.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#3027
File: packages/xrpl/src/models/ledger/MPTokenIssuance.ts:13-16
Timestamp: 2025-06-26T17:25:36.429Z
Learning: In the XRPL ecosystem, type choices for amount fields (like `number` vs `string`) in ledger objects such as `LockedAmount` vs `OutstandingAmount` in `MPTokenIssuance` are deliberate design decisions made across multiple products and cannot be changed unilaterally by individual contributors.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2873
File: packages/xrpl/src/models/transactions/trustSet.ts:33-36
Timestamp: 2025-01-08T13:08:52.688Z
Learning: For trust-set transactions in XRPL, validation rules for flags should be implemented comprehensively rather than cherry-picking specific rules, as there are many interdependent validation rules associated with these flags.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2829
File: packages/xrpl/src/models/ledger/Credential.ts:36-36
Timestamp: 2024-12-09T07:06:47.258Z
Learning: In TypeScript interfaces, ensure that fields documented as optional are marked with the `?` operator to denote optionality.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/src/models/ledger/PermissionedDomain.ts:3-8
Timestamp: 2025-01-08T02:08:00.476Z
Learning: In xrpl.js, the Credential interface must maintain a nested structure with a `Credential` property containing `Issuer` and `CredentialType` fields to mirror the structure defined in the rippled codebase.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2829
File: packages/xrpl/src/models/methods/ledgerEntry.ts:74-85
Timestamp: 2024-12-12T01:12:01.868Z
Learning: In the XRPL.js library, request parameters use camelCase (e.g., `credentialType`), while transaction model fields follow the XRP Ledger protocol's PascalCase convention (e.g., `CredentialType`).
Learnt from: mvadari
PR: XRPLF/xrpl.js#2801
File: packages/xrpl/src/Wallet/batchSigner.ts:0-0
Timestamp: 2025-04-16T15:55:50.121Z
Learning: When using `encodeForSigningBatch` for Batch transactions in the XRPL.js library, the field names should use camelCase (`flags`, `txIDs`) even though the transaction object properties themselves use PascalCase (`Flags`, `TxIDs`).
Learnt from: mvadari
PR: XRPLF/xrpl.js#2801
File: packages/xrpl/test/models/Batch.test.ts:0-0
Timestamp: 2025-04-16T15:22:45.633Z
Learning: Using `as any` type assertions is acceptable in test files for the XRPL.js project, as strict typing is not required for test code.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2873
File: packages/xrpl/test/integration/transactions/trustSet.test.ts:0-0
Timestamp: 2025-01-31T17:46:25.375Z
Learning: For the XRPL implementation, extensive test cases for deep freeze behavior (high/low side interactions, clearing flags, etc.) are maintained in the C++ implementation and don't need to be duplicated in the JavaScript implementation.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/test/integration/transactions/permissionedDomain.test.ts:25-80
Timestamp: 2025-01-08T02:12:28.489Z
Learning: The rippled C++ implementation (PR #5161) includes comprehensive test coverage for PermissionedDomain (XLS-80d) error cases. The JS SDK tests focus on the happy path since the error cases are already validated at the rippled level, following the principle of not duplicating complex validation testing across SDK implementations.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/test/models/permissionedDomainDelete.test.ts:15-20
Timestamp: 2025-01-08T02:11:21.997Z
Learning: In validation test cases for XRPL transactions, using generic JSON input (e.g., `as any`) is preferred over strict typing as it better represents real-world scenarios where the `validate` method needs to handle arbitrary JSON/map/dictionary input from users.
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2829
File: packages/xrpl/src/models/transactions/CredentialAccept.ts:36-44
Timestamp: 2024-12-18T20:54:40.935Z
Learning: The validateCredentialType function already checks that CredentialType is a properly hex-encoded string within the allowed length.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/src/models/transactions/common.ts:0-0
Timestamp: 2025-01-16T04:26:36.757Z
Learning: Test libraries like chai should not be used in source code. Use existing validation functions where available, or implement custom validation using ValidationError for runtime checks.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2895
File: packages/xrpl/test/models/clawback.test.ts:0-0
Timestamp: 2025-02-12T23:28:55.377Z
Learning: The `validate` function in xrpl.js is synchronous and should be tested using `assert.doesNotThrow` rather than async assertions.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2895
File: packages/xrpl/test/models/DIDDelete.test.ts:28-31
Timestamp: 2025-02-12T23:30:40.622Z
Learning: In JavaScript/TypeScript transaction validation tests, object key validation can be performed using:
1. Object.keys() comparison with expected set
2. TypeScript interfaces with strict object literal checks
3. Object sanitization by filtering to allowed keys only
🧬 Code Graph Analysis (1)
packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts (1)
packages/xrpl/src/models/transactions/common.ts (1)
  • isString (100-102)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: integration (20.x)
  • GitHub Check: browser (22.x)
  • GitHub Check: integration (22.x)
  • GitHub Check: unit (20.x)
  • GitHub Check: build-and-lint (22.x)
  • GitHub Check: unit (22.x)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (5)
packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts (5)

1-2: Import statement and ESLint directive look good.

The hexToString import is properly utilized for decoding hex-encoded metadata, and the max-lines disable is justified given the extensive validation logic.


20-47: Constants are well-defined and align with XLS-89d standard.

The TICKER_REGEX, required fields, and asset class constants provide clear validation boundaries. The regex pattern correctly enforces uppercase alphanumeric characters with a 6-character limit.


102-124: Interface definitions are comprehensive and correctly structured.

Both MPTokenMetadata and MPTokenMetadataUrl interfaces properly define the expected structure. The optional fields are correctly marked with ? operator.


237-237: Integration of metadata validation is properly placed.

The call to logWarningsForMPTMetadata is correctly positioned after all other validation checks, ensuring warnings are only logged for otherwise valid transactions.


382-396: Helper function is well-implemented.

The isValidMPTokenMetadataUrlStructure function correctly validates the required structure for URL objects with proper type checking.

@khancode khancode requested review from ckeshava and khancode July 14, 2025 16:31
Copy link
Collaborator

@ckeshava ckeshava left a comment

Choose a reason for hiding this comment

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

Hello Raj, this is good work.

  1. What is the decision on the MPTIssuanceCreate transactions whose meta-data exceed the expected size i.e. 1024 bytes? In this version of the PR, rippled will reject them with an appropriate error-code. Is that the expected behavior?

Here is a verbatim snippet from the final design choices for the XLS-89 spec:

If the metadata is too large, developers will receive a pre-submission warning before anything is sent to rippled

  1. This solution is repetitive. You need to implement this solution in all the client libraries. Despite all this effort, if a user submits a transaction directly to a rippled node, they are not supplied with any warnings at all. If companies/organizations use non-SDK pipelines, they will not be notified of the XLS-89d structure. Do you have any thoughts on this issue?

For reference, here is the associated validation in rippled.

  1. Users can set the MPTokenMetadata in the VaultCreate transaction (Single-Asset-Vault amendment) too. Are you planning to add this validation into that transaction too?

  2. I'm concerned about the number of console warnings that will be printed due to this PR -- Can a user choose to opt out of adhering to the XLS-89D standard? This comment from @sappenin is helpful in detecting if users are trying to adhere to XLS-89.

  3. Can you include all of this validation inside an exportable method? A method with the one-of-the-below signature is helpful.

Otherwise, this logic will need to be repeated across explorer and indexers in the XRPL ecosystem. If users can import this method, that will be very helpful.

validateMPTokenMetadata(metadata: unknown): metadata is MPTokenMetadata { ... }
isMetadata_XLS_89_compatible(metadata: unknown): boolean { ... }
isMPTMetadataDiscoverable(metadata: unknown): boolean { ... }

@Patel-Raj11
Copy link
Collaborator Author

@ckeshava Thanks for the detailed feedback:

What is the decision on the MPTIssuanceCreate transactions whose meta-data exceed the expected size i.e. 1024 bytes? In this version of the PR, rippled will reject them with an appropriate error-code. Is that the expected behavior?

Yes, it's expected behaviour for rippled to reject it. Client library will just warn the user.

This solution is repetitive. You need to implement this solution in all the client libraries. Despite all this effort, if a user submits a transaction directly to a rippled node, they are not supplied with any warnings at all. If companies/organizations use non-SDK pipelines, they will not be notified of the XLS-89d structure. Do you have any thoughts on this issue?

I brought this same point to Julian and it was concluded that if the project/company is really serious about their project, they will take the warnings seriously if they are using our SDKs. If they are directly submitting the transactions to rippled, then we can't do much and I don't have any other solution in mind but to have rippled enforce such metadata structure and error out if the transaction does not adhere to it. Since MPTokensV1 is out for voting, I think we can have another amendment to enforce such metadata structure.

Users can set the MPTokenMetadata in the VaultCreate transaction (Single-Asset-Vault amendment) too. Are you planning to add this validation into that transaction too?

Thanks for highlighting this. I overlooked it. To me it makes sense to give warning messages here as well.

I'm concerned about the number of console warnings that will be printed due to this PR -- Can a user choose to opt out of adhering to the XLS-89D standard? XRPLF/XRPL-Standards#293 (comment) from @sappenin is helpful in detecting if users are trying to adhere to XLS-89.

Yes, there would be many warnings for VaultCreate and MPTokenIssuanceCreate transactions. But those are for good. We can combine those into one single warning message. Do you have any better suggestion other than having rippled enforce at their end? Yes, user can opt out, they are just warnings and not hard failures.

Can you include all of this validation inside an exportable method? A method with the one-of-the-below signature is helpful.

I will move these validations to a common place now since VaultCreate needs to be validated as well. However, since we want to export this, we need to have an extra parameter for whether to log warnings or not. Something like this:
validateMPTokenMetadata(metadata: unknown, logWarnings: boolean): metadata is MPTokenMetadata { ... }

@ckeshava
Copy link
Collaborator

@ckeshava Thanks for the detailed feedback:

What is the decision on the MPTIssuanceCreate transactions whose meta-data exceed the expected size i.e. 1024 bytes? In this version of the PR, rippled will reject them with an appropriate error-code. Is that the expected behavior?

Yes, it's expected behaviour for rippled to reject it. Client library will just warn the user.

Where have you included the warning in the xrpl-py client library, appropos the size of the meta-data field?

Users can set the MPTokenMetadata in the VaultCreate transaction (Single-Asset-Vault amendment) too. Are you planning to add this validation into that transaction too?

Thanks for highlighting this. I overlooked it. To me it makes sense to give warning messages here as well.

Okay, let me know once the VaultCreate transaction has been updated with the warning message.

I'm concerned about the number of console warnings that will be printed due to this PR -- Can a user choose to opt out of adhering to the XLS-89D standard? XRPLF/XRPL-Standards#293 (comment) from @sappenin is helpful in detecting if users are trying to adhere to XLS-89.

Yes, there would be many warnings for VaultCreate and MPTokenIssuanceCreate transactions. But those are for good. We can combine those into one single warning message. Do you have any better suggestion other than having rippled enforce at their end? Yes, user can opt out, they are just warnings and not hard failures.

Hmm apart from implementing this inside rippled and David Fuelling's suggestion, I don't have any other ideas.

Can you include all of this validation inside an exportable method? A method with the one-of-the-below signature is helpful.

I will move these validations to a common place now since VaultCreate needs to be validated as well. However, since we want to export this, we need to have an extra parameter for whether to log warnings or not. Something like this: validateMPTokenMetadata(metadata: unknown, logWarnings: boolean): metadata is MPTokenMetadata { ... }

Are console warnings the best way to inform the user? If the xrpl package is used inside a browser (or) node, these console-warnings will be printed in the "developer-console". However, will developers read all the logs of their application? I'm trying to think of a better alternative to inform the user.

@Patel-Raj11
Copy link
Collaborator Author

Where have you included the warning in the xrpl-py client library, appropos the size of the meta-data field?

This will be implemented once, xrpl.js review progresses beyond the fact of deciding whether console warnings are the right thing to do, in the interest of development effort.

Hmm apart from implementing this inside rippled and David Fuelling's suggestion, I don't have any other ideas.

David Fuelling's suggestion is marked as resolved and is up for future versions of the meta data spec. This PR pertains to XLS-89d. We can revisit this implementation once the spec is updated with that suggestion in future. Let me know if you think otherwise.

Are console warnings the best way to inform the user? If the xrpl package is used inside a browser (or) node, these console-warnings will be printed in the "developer-console". However, will developers read all the logs of their application? I'm trying to think of a better alternative to inform the user.

For now, to me it seems console warnings is the best way forward. xrpl.org should be updated for even better communication. Developer might or might not view the console warnings. Let me know once you have a better suggestion for this, I'll resume implementation after that, in the interest of development effort.

@ckeshava
Copy link
Collaborator

Where have you included the warning in the xrpl-py client library, appropos the size of the meta-data field?

This will be implemented once, xrpl.js review progresses beyond the fact of deciding whether console warnings are the right thing to do, in the interest of development effort.

My bad, I am referring to metada-sized based warnings in this PR? Where are such validations?

Hmm apart from implementing this inside rippled and David Fuelling's suggestion, I don't have any other ideas.

David Fuelling's suggestion is marked as resolved and is up for future versions of the meta data spec. This PR pertains to XLS-89d. We can revisit this implementation once the spec is updated with that suggestion in future. Let me know if you think otherwise.

Yes, I understand; I'm only pointing out that his suggestion -- adding a spec_version field will make it easier for SDK to detect if a user wants to adhere to XLS-89d. The absence of such a field could have been used to silence these console-warnings.

Are console warnings the best way to inform the user? If the xrpl package is used inside a browser (or) node, these console-warnings will be printed in the "developer-console". However, will developers read all the logs of their application? I'm trying to think of a better alternative to inform the user.

For now, to me it seems console warnings is the best way forward. xrpl.org should be updated for even better communication. Developer might or might not view the console warnings. Let me know once you have a better suggestion for this, I'll resume implementation after that, in the interest of development effort.

I agree that xrpl.org should be updated with the XLS-89d standard. Additionally, I recommend using the Typedoc/JSDoc-strings in the VaultCreate, MPTokenIssuanceCreate transactions to document the existence of a new metadata standard.

I don't have any other objections pertaining to this implementation approach. Please proceed.

@Patel-Raj11 Patel-Raj11 requested a review from ckeshava July 17, 2025 14:01
Comment on lines +226 to +234
ticker: string
name: string
desc?: string
icon: string
asset_class: string
asset_subclass?: string
issuer_name: string
urls?: MPTokenMetadataUrl[]
additional_info?: string
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move optional fields after required ones?

* While adherence to the XLS-89d format is not mandatory, non-compliant metadata
* may not be discoverable by ecosystem tools such as explorers and indexers.
*/
MPTokenMetadata?: string | null
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
MPTokenMetadata?: string | null
MPTokenMetadata?: string

I know you didn't make this change but there shouldn't be | null since it's an optional field.

Comment on lines +752 to +757
if (!isHex(input) || input.length / 2 > MAX_MPT_META_BYTE_LENGTH) {
validationMessages.push(
`MPTokenMetadata must be in hex format and max ${MAX_MPT_META_BYTE_LENGTH} bytes.`,
)
return { validationMessages, isValid: false }
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I would separate these error messages so it's cleaner.

Comment on lines +747 to +748
isValid: boolean
validationMessages: string[]
Copy link
Contributor

@khancode khancode Jul 23, 2025

Choose a reason for hiding this comment

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

Suggested change
isValid: boolean
validationMessages: string[]
validationMessages?: string[]

We can infer validity by checking if validationMessages is returned.

Comment on lines +771 to +775
!(
jsonMetaData != null &&
typeof jsonMetaData === 'object' &&
!Array.isArray(jsonMetaData)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
!(
jsonMetaData != null &&
typeof jsonMetaData === 'object' &&
!Array.isArray(jsonMetaData)
)
jsonMetaData == null ||
typeof jsonMetaData !== 'object' ||
Array.isArray(jsonMetaData)

Simplified and easy to read.

Comment on lines +809 to +814
obj.additional_info != null &&
!(
isString(obj.additional_info) ||
(typeof obj.additional_info === 'object' &&
!Array.isArray(obj.additional_info))
)
Copy link
Contributor

@khancode khancode Jul 23, 2025

Choose a reason for hiding this comment

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

Suggested change
obj.additional_info != null &&
!(
isString(obj.additional_info) ||
(typeof obj.additional_info === 'object' &&
!Array.isArray(obj.additional_info))
)
obj.additional_info != null &&
!isString(obj.additional_info) &&
(
typeof obj.additional_info !== 'object' ||
Array.isArray(obj.additional_info)
)

Nested negation is difficult to read.

Comment on lines +820 to +829
if (
obj.urls != null &&
(!Array.isArray(obj.urls) ||
!obj.urls.every(isValidMPTokenMetadataUrlStructure))
) {
validationMessages.push(
`urls field is not properly structured as per the XLS-89d standard.`,
)
return { validationMessages, isValid: false }
}
Copy link
Contributor

@khancode khancode Jul 23, 2025

Choose a reason for hiding this comment

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

Suggested change
if (
obj.urls != null &&
(!Array.isArray(obj.urls) ||
!obj.urls.every(isValidMPTokenMetadataUrlStructure))
) {
validationMessages.push(
`urls field is not properly structured as per the XLS-89d standard.`,
)
return { validationMessages, isValid: false }
}
if (obj.urls != null) {
if (!Array.isArray(obj.urls)) {
validationMessages.push('urls must be an array as per XLS-89d.');
return { validationMessages, isValid: false };
}
if (!obj.urls.every(isValidMPTokenMetadataUrlStructure)) {
validationMessages.push('One or more urls are not structured per XLS-89d.');
return { validationMessages, isValid: false };
}
}

Separate error messages here too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@khancode Added your suggestions in 756a81a.
Also, updated the validation function to check for field count as well, so that users are warned if they add other fields that are not mentioned in the spec. It's not an issue to have such fields present since tools can ignore them, but good to have warnings.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/xrpl/test/fixtures/transactions/mptokenMetadata.json (1)

229-229: Consider making the JSON error test more robust

The error message includes the JavaScript engine's specific error text which might vary across different environments.

Consider using a regex or partial string match in the test to make it more robust across different JavaScript engines, or just check that the message starts with "MPTokenMetadata is not properly formatted as JSON".

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2269745 and ffa204d.

📒 Files selected for processing (6)
  • packages/xrpl/src/models/common/index.ts (1 hunks)
  • packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts (4 hunks)
  • packages/xrpl/src/models/transactions/common.ts (4 hunks)
  • packages/xrpl/src/models/transactions/vaultCreate.ts (5 hunks)
  • packages/xrpl/test/fixtures/transactions/mptokenMetadata.json (1 hunks)
  • packages/xrpl/test/models/utils.test.ts (4 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/xrpl/test/models/utils.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/xrpl/src/models/common/index.ts
  • packages/xrpl/src/models/transactions/vaultCreate.ts
  • packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/test/integration/transactions/permissionedDomain.test.ts:25-80
Timestamp: 2025-01-08T02:12:28.489Z
Learning: The rippled C++ implementation (PR #5161) includes comprehensive test coverage for PermissionedDomain (XLS-80d) error cases. The JS SDK tests focus on the happy path since the error cases are already validated at the rippled level, following the principle of not duplicating complex validation testing across SDK implementations.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2873
File: packages/xrpl/src/models/transactions/trustSet.ts:33-36
Timestamp: 2025-01-08T13:08:52.688Z
Learning: For trust-set transactions in XRPL, validation rules for flags should be implemented comprehensively rather than cherry-picking specific rules, as there are many interdependent validation rules associated with these flags.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#3032
File: packages/xrpl/src/models/transactions/common.ts:689-698
Timestamp: 2025-07-10T22:04:59.994Z
Learning: In the XRPL.js library, the validateDomainID function in `packages/xrpl/src/models/transactions/common.ts` should only validate the length (64 characters) of domain IDs, not hex encoding. The rippled C++ implementation does not enforce any regex check on domain ID values, so additional hex validation is not required in the JS implementation.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2895
File: packages/xrpl/test/models/DIDDelete.test.ts:28-31
Timestamp: 2025-02-12T23:30:40.622Z
Learning: In JavaScript/TypeScript transaction validation tests, object key validation can be performed using:
1. Object.keys() comparison with expected set
2. TypeScript interfaces with strict object literal checks
3. Object sanitization by filtering to allowed keys only
packages/xrpl/test/fixtures/transactions/mptokenMetadata.json (6)

Learnt from: shawnxie999
PR: #2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file packages/xrpl/test/models/MPTokenAuthorize.test.ts, negative test cases for invalid Account address format, invalid Holder address format, invalid MPTokenIssuanceID format, and invalid flag combinations are not necessary.

Learnt from: ckeshava
PR: #2874
File: packages/xrpl/test/models/permissionedDomainDelete.test.ts:15-20
Timestamp: 2025-01-08T02:11:21.997Z
Learning: In validation test cases for XRPL transactions, using generic JSON input (e.g., as any) is preferred over strict typing as it better represents real-world scenarios where the validate method needs to handle arbitrary JSON/map/dictionary input from users.

Learnt from: shawnxie999
PR: #2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in packages/xrpl/test/integration/transactions/), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.

Learnt from: ckeshava
PR: #2873
File: packages/xrpl/test/integration/transactions/trustSet.test.ts:0-0
Timestamp: 2025-01-31T17:46:25.375Z
Learning: For the XRPL implementation, extensive test cases for deep freeze behavior (high/low side interactions, clearing flags, etc.) are maintained in the C++ implementation and don't need to be duplicated in the JavaScript implementation.

Learnt from: ckeshava
PR: #2874
File: packages/xrpl/test/integration/transactions/permissionedDomain.test.ts:25-80
Timestamp: 2025-01-08T02:12:28.489Z
Learning: The rippled C++ implementation (PR #5161) includes comprehensive test coverage for PermissionedDomain (XLS-80d) error cases. The JS SDK tests focus on the happy path since the error cases are already validated at the rippled level, following the principle of not duplicating complex validation testing across SDK implementations.

Learnt from: achowdhry-ripple
PR: #2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in validate* functions in packages/xrpl/src/models/transactions/, utilize existing helper functions (e.g., validateOptionalField, validateType, isNumber, isInteger) for type checking and validation where appropriate.

packages/xrpl/src/models/transactions/common.ts (22)

Learnt from: shawnxie999
PR: #2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file packages/xrpl/test/models/MPTokenAuthorize.test.ts, negative test cases for invalid Account address format, invalid Holder address format, invalid MPTokenIssuanceID format, and invalid flag combinations are not necessary.

Learnt from: achowdhry-ripple
PR: #2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in validate* functions in packages/xrpl/src/models/transactions/, utilize existing helper functions (e.g., validateOptionalField, validateType, isNumber, isInteger) for type checking and validation where appropriate.

Learnt from: ckeshava
PR: #3032
File: packages/xrpl/src/models/transactions/common.ts:689-698
Timestamp: 2025-07-10T22:04:59.994Z
Learning: In the XRPL.js library, the validateDomainID function in packages/xrpl/src/models/transactions/common.ts should only validate the length (64 characters) of domain IDs, not hex encoding. The rippled C++ implementation does not enforce any regex check on domain ID values, so additional hex validation is not required in the JS implementation.

Learnt from: ckeshava
PR: #3032
File: packages/xrpl/src/models/transactions/common.ts:689-698
Timestamp: 2025-07-11T21:22:07.809Z
Learning: Domain ID validation in XRPL.js is handled at the serialization/deserialization layer through Hash types in the ripple-binary-codec package, not at the transaction validation layer. The validateDomainID function only needs to validate length (64 characters) as hex validation occurs when Hash types are constructed during serialization.

Learnt from: ckeshava
PR: #2873
File: packages/xrpl/src/models/transactions/trustSet.ts:33-36
Timestamp: 2025-01-08T13:08:52.688Z
Learning: For trust-set transactions in XRPL, validation rules for flags should be implemented comprehensively rather than cherry-picking specific rules, as there are many interdependent validation rules associated with these flags.

Learnt from: ckeshava
PR: #3027
File: packages/xrpl/src/models/ledger/MPTokenIssuance.ts:13-16
Timestamp: 2025-06-26T17:25:36.429Z
Learning: In the XRPL ecosystem, type choices for amount fields (like number vs string) in ledger objects such as LockedAmount vs OutstandingAmount in MPTokenIssuance are deliberate design decisions made across multiple products and cannot be changed unilaterally by individual contributors.

Learnt from: shawnxie999
PR: #2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in packages/xrpl/test/integration/transactions/), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.

Learnt from: mvadari
PR: #2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-02T15:47:02.491Z
Learning: In generateModels.js, the regex used to match SubmittableTransaction in transaction.ts is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.

Learnt from: mvadari
PR: #2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-08T16:29:11.194Z
Learning: In generateModels.js, the regex used to match SubmittableTransaction in transaction.ts is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.

Learnt from: ckeshava
PR: #2874
File: packages/xrpl/test/integration/transactions/permissionedDomain.test.ts:25-80
Timestamp: 2025-01-08T02:12:28.489Z
Learning: The rippled C++ implementation (PR #5161) includes comprehensive test coverage for PermissionedDomain (XLS-80d) error cases. The JS SDK tests focus on the happy path since the error cases are already validated at the rippled level, following the principle of not duplicating complex validation testing across SDK implementations.

Learnt from: ckeshava
PR: #2873
File: packages/xrpl/test/integration/transactions/trustSet.test.ts:0-0
Timestamp: 2025-01-31T17:46:25.375Z
Learning: For the XRPL implementation, extensive test cases for deep freeze behavior (high/low side interactions, clearing flags, etc.) are maintained in the C++ implementation and don't need to be duplicated in the JavaScript implementation.

Learnt from: mvadari
PR: #2801
File: packages/xrpl/test/wallet/batchSigner.test.ts:0-0
Timestamp: 2025-04-16T15:28:21.204Z
Learning: In the XRPL.js library, hardcoded seeds in test files are acceptable as they don't represent protected data or real funds - they're only used for consistent test behavior.

Learnt from: ckeshava
PR: #2874
File: packages/xrpl/src/models/transactions/permissionedDomainSet.ts:32-33
Timestamp: 2025-01-17T09:27:33.335Z
Learning: Use Array.isArray() instead of instanceof Array for reliable array type checking in JavaScript, as instanceof Array fails for cross-realm arrays (e.g., from iframes) and arrays from different JavaScript contexts.

Learnt from: mvadari
PR: #2801
File: packages/xrpl/test/models/Batch.test.ts:0-0
Timestamp: 2025-04-16T15:22:45.633Z
Learning: Using as any type assertions is acceptable in test files for the XRPL.js project, as strict typing is not required for test code.

Learnt from: mvadari
PR: #2801
File: packages/xrpl/src/Wallet/batchSigner.ts:0-0
Timestamp: 2025-04-16T15:55:50.121Z
Learning: When using encodeForSigningBatch for Batch transactions in the XRPL.js library, the field names should use camelCase (flags, txIDs) even though the transaction object properties themselves use PascalCase (Flags, TxIDs).

Learnt from: ckeshava
PR: #2826
File: packages/xrpl/tools/generateModels.js:25-25
Timestamp: 2025-01-13T22:38:40.085Z
Learning: When parsing rippled source files (e.g., macro files, cpp files) in tools/scripts, extensive error handling for regex matches is not needed as any malformed content would be caught by rippled's C++ compiler and unit tests during the build process.

Learnt from: mvadari
PR: #2829
File: packages/xrpl/src/models/methods/ledgerEntry.ts:74-85
Timestamp: 2024-12-12T01:12:01.868Z
Learning: In the XRPL.js library, request parameters use camelCase (e.g., credentialType), while transaction model fields follow the XRP Ledger protocol's PascalCase convention (e.g., CredentialType).

Learnt from: mvadari
PR: #2826
File: packages/xrpl/tools/generateModels.js:36-36
Timestamp: 2024-11-18T23:29:19.882Z
Learning: In the file packages/xrpl/tools/generateModels.js, it's acceptable for the script to crash when the regex doesn't match as expected.

Learnt from: ckeshava
PR: #2874
File: packages/xrpl/src/models/ledger/PermissionedDomain.ts:3-8
Timestamp: 2025-01-08T02:08:00.476Z
Learning: In xrpl.js, the Credential interface must maintain a nested structure with a Credential property containing Issuer and CredentialType fields to mirror the structure defined in the rippled codebase.

Learnt from: ckeshava
PR: #2874
File: packages/xrpl/test/integration/transactions/permissionedDomain.test.ts:25-80
Timestamp: 2025-01-08T02:12:28.489Z
Learning: For PermissionedDomain feature (XLS-80d), complex error cases like invalid credential format, duplicate credentials, and non-existent DomainID are tested in the rippled C++ implementation rather than being duplicated across SDK implementations like xrpl.js.

Learnt from: mvadari
PR: #2895
File: packages/xrpl/test/models/DIDDelete.test.ts:28-31
Timestamp: 2025-02-12T23:30:40.622Z
Learning: In JavaScript/TypeScript transaction validation tests, object key validation can be performed using:

  1. Object.keys() comparison with expected set
  2. TypeScript interfaces with strict object literal checks
  3. Object sanitization by filtering to allowed keys only

Learnt from: achowdhry-ripple
PR: #2829
File: packages/xrpl/src/models/transactions/CredentialAccept.ts:36-44
Timestamp: 2024-12-18T20:54:40.935Z
Learning: The validateCredentialType function already checks that CredentialType is a properly hex-encoded string within the allowed length.

🧬 Code Graph Analysis (1)
packages/xrpl/src/models/transactions/common.ts (3)
packages/xrpl/src/models/transactions/index.ts (1)
  • validateMPTokenMetadata (1-1)
packages/xrpl/src/models/utils/index.ts (1)
  • isHex (60-62)
packages/xrpl/src/models/common/index.ts (1)
  • MPTokenMetadata (225-235)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: integration (22.x)
  • GitHub Check: unit (22.x)
  • GitHub Check: integration (20.x)
  • GitHub Check: browser (22.x)
  • GitHub Check: unit (20.x)
  • GitHub Check: build-and-lint (22.x)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (5)
packages/xrpl/src/models/transactions/common.ts (4)

2-2: LGTM!

The imports and constant are correctly added to support MPTokenMetadata validation.

Also applies to: 15-15, 26-26


31-68: Well-structured constants for XLS-89d validation!

The constants properly define the validation rules according to the XLS-89d standard. The warning header message is clear and informative.


849-896: Comprehensive content validation!

The content validation properly enforces all XLS-89d requirements including ticker format, HTTPS URLs, asset classifications, and conditional subclass requirements.


903-917: Clean URL structure validation!

The helper function correctly validates the URL object structure according to XLS-89d requirements.

packages/xrpl/test/fixtures/transactions/mptokenMetadata.json (1)

1-426: Excellent test coverage!

The test fixture comprehensively covers all validation scenarios including:

  • Valid and invalid metadata structures
  • All required and optional fields
  • Format constraints (ticker, URLs, asset classifications)
  • Size and field count limits
  • Edge cases and error conditions
  • Multiple simultaneous validation errors

This provides thorough test coverage for the XLS-89d validation implementation.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/xrpl/src/models/transactions/common.ts (1)

744-898: Consider refactoring for improved maintainability.

The validation function is comprehensive and functionally correct, but its length (150+ lines) makes it challenging to maintain. Consider extracting validation logic into smaller, focused helper functions:

  1. validateMPTokenMetadataStructure(obj) - for structural validation (lines 792-842)
  2. validateMPTokenMetadataContent(metadata) - for content validation (lines 847-896)
  3. validateMPTokenMetadataBasics(input) - for hex/size validation (lines 753-763)

This would improve readability, testability, and maintainability while preserving the current functionality.

Example refactor structure:

export function validateMPTokenMetadata(input: string): string[] {
  const validationMessages: string[] = []
  
  // Basic validation
  const basicErrors = validateMPTokenMetadataBasics(input)
  if (basicErrors.length > 0) {
    return basicErrors
  }
  
  // JSON parsing and object validation
  let jsonMetaData: unknown
  try {
    jsonMetaData = JSON.parse(hexToString(input))
  } catch (err) {
    return [`MPTokenMetadata is not properly formatted as JSON - ${String(err)}`]
  }
  
  if (!isValidJSONObject(jsonMetaData)) {
    return ['MPTokenMetadata is not properly formatted as per XLS-89d.']
  }
  
  const obj = jsonMetaData as Record<string, unknown>
  
  // Structural validation
  validationMessages.push(...validateMPTokenMetadataStructure(obj))
  if (validationMessages.length > 0) {
    return validationMessages
  }
  
  // Content validation
  validationMessages.push(...validateMPTokenMetadataContent(obj as MPTokenMetadata))
  
  return validationMessages
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ffa204d and 36ed797.

📒 Files selected for processing (2)
  • packages/xrpl/src/models/transactions/common.ts (4 hunks)
  • packages/xrpl/test/fixtures/transactions/mptokenMetadata.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/xrpl/test/fixtures/transactions/mptokenMetadata.json
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/test/integration/transactions/permissionedDomain.test.ts:25-80
Timestamp: 2025-01-08T02:12:28.489Z
Learning: The rippled C++ implementation (PR #5161) includes comprehensive test coverage for PermissionedDomain (XLS-80d) error cases. The JS SDK tests focus on the happy path since the error cases are already validated at the rippled level, following the principle of not duplicating complex validation testing across SDK implementations.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2873
File: packages/xrpl/src/models/transactions/trustSet.ts:33-36
Timestamp: 2025-01-08T13:08:52.688Z
Learning: For trust-set transactions in XRPL, validation rules for flags should be implemented comprehensively rather than cherry-picking specific rules, as there are many interdependent validation rules associated with these flags.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#3032
File: packages/xrpl/src/models/transactions/common.ts:689-698
Timestamp: 2025-07-10T22:04:59.994Z
Learning: In the XRPL.js library, the validateDomainID function in `packages/xrpl/src/models/transactions/common.ts` should only validate the length (64 characters) of domain IDs, not hex encoding. The rippled C++ implementation does not enforce any regex check on domain ID values, so additional hex validation is not required in the JS implementation.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in `validate*` functions in `packages/xrpl/src/models/transactions/`, utilize existing helper functions (e.g., `validateOptionalField`, `validateType`, `isNumber`, `isInteger`) for type checking and validation where appropriate.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2895
File: packages/xrpl/test/models/DIDDelete.test.ts:28-31
Timestamp: 2025-02-12T23:30:40.622Z
Learning: In JavaScript/TypeScript transaction validation tests, object key validation can be performed using:
1. Object.keys() comparison with expected set
2. TypeScript interfaces with strict object literal checks
3. Object sanitization by filtering to allowed keys only
packages/xrpl/src/models/transactions/common.ts (26)

Learnt from: shawnxie999
PR: #2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file packages/xrpl/test/models/MPTokenAuthorize.test.ts, negative test cases for invalid Account address format, invalid Holder address format, invalid MPTokenIssuanceID format, and invalid flag combinations are not necessary.

Learnt from: achowdhry-ripple
PR: #2661
File: packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts:69-102
Timestamp: 2024-12-05T16:48:12.951Z
Learning: When adding validation in validate* functions in packages/xrpl/src/models/transactions/, utilize existing helper functions (e.g., validateOptionalField, validateType, isNumber, isInteger) for type checking and validation where appropriate.

Learnt from: ckeshava
PR: #3032
File: packages/xrpl/src/models/transactions/common.ts:689-698
Timestamp: 2025-07-10T22:04:59.994Z
Learning: In the XRPL.js library, the validateDomainID function in packages/xrpl/src/models/transactions/common.ts should only validate the length (64 characters) of domain IDs, not hex encoding. The rippled C++ implementation does not enforce any regex check on domain ID values, so additional hex validation is not required in the JS implementation.

Learnt from: ckeshava
PR: #3032
File: packages/xrpl/src/models/transactions/common.ts:689-698
Timestamp: 2025-07-11T21:22:07.809Z
Learning: Domain ID validation in XRPL.js is handled at the serialization/deserialization layer through Hash types in the ripple-binary-codec package, not at the transaction validation layer. The validateDomainID function only needs to validate length (64 characters) as hex validation occurs when Hash types are constructed during serialization.

Learnt from: ckeshava
PR: #2873
File: packages/xrpl/src/models/transactions/trustSet.ts:33-36
Timestamp: 2025-01-08T13:08:52.688Z
Learning: For trust-set transactions in XRPL, validation rules for flags should be implemented comprehensively rather than cherry-picking specific rules, as there are many interdependent validation rules associated with these flags.

Learnt from: ckeshava
PR: #3027
File: packages/xrpl/src/models/ledger/MPTokenIssuance.ts:13-16
Timestamp: 2025-06-26T17:25:36.429Z
Learning: In the XRPL ecosystem, type choices for amount fields (like number vs string) in ledger objects such as LockedAmount vs OutstandingAmount in MPTokenIssuance are deliberate design decisions made across multiple products and cannot be changed unilaterally by individual contributors.

Learnt from: shawnxie999
PR: #2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in packages/xrpl/test/integration/transactions/), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.

Learnt from: ckeshava
PR: #2874
File: packages/xrpl/test/integration/transactions/permissionedDomain.test.ts:25-80
Timestamp: 2025-01-08T02:12:28.489Z
Learning: The rippled C++ implementation (PR #5161) includes comprehensive test coverage for PermissionedDomain (XLS-80d) error cases. The JS SDK tests focus on the happy path since the error cases are already validated at the rippled level, following the principle of not duplicating complex validation testing across SDK implementations.

Learnt from: mvadari
PR: #2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-02T15:47:02.491Z
Learning: In generateModels.js, the regex used to match SubmittableTransaction in transaction.ts is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.

Learnt from: mvadari
PR: #2690
File: packages/xrpl/tools/generateModels.js:52-52
Timestamp: 2024-10-08T16:29:11.194Z
Learning: In generateModels.js, the regex used to match SubmittableTransaction in transaction.ts is expected to always succeed because the pattern is present in the source code. If it fails, the code needs to be updated.

Learnt from: ckeshava
PR: #2873
File: packages/xrpl/test/integration/transactions/trustSet.test.ts:0-0
Timestamp: 2025-01-31T17:46:25.375Z
Learning: For the XRPL implementation, extensive test cases for deep freeze behavior (high/low side interactions, clearing flags, etc.) are maintained in the C++ implementation and don't need to be duplicated in the JavaScript implementation.

Learnt from: mvadari
PR: #2801
File: packages/xrpl/test/wallet/batchSigner.test.ts:0-0
Timestamp: 2025-04-16T15:28:21.204Z
Learning: In the XRPL.js library, hardcoded seeds in test files are acceptable as they don't represent protected data or real funds - they're only used for consistent test behavior.

Learnt from: ckeshava
PR: #2874
File: packages/xrpl/src/models/transactions/permissionedDomainSet.ts:32-33
Timestamp: 2025-01-17T09:27:33.335Z
Learning: Use Array.isArray() instead of instanceof Array for reliable array type checking in JavaScript, as instanceof Array fails for cross-realm arrays (e.g., from iframes) and arrays from different JavaScript contexts.

Learnt from: mvadari
PR: #2895
File: packages/xrpl/test/models/clawback.test.ts:0-0
Timestamp: 2025-02-12T23:28:55.377Z
Learning: The validate function in xrpl.js is synchronous and should be tested using assert.doesNotThrow rather than async assertions.

Learnt from: ckeshava
PR: #2874
File: packages/xrpl/test/models/permissionedDomainDelete.test.ts:15-20
Timestamp: 2025-01-08T02:11:21.997Z
Learning: In validation test cases for XRPL transactions, using generic JSON input (e.g., as any) is preferred over strict typing as it better represents real-world scenarios where the validate method needs to handle arbitrary JSON/map/dictionary input from users.

Learnt from: mvadari
PR: #2829
File: packages/xrpl/src/models/methods/ledgerEntry.ts:74-85
Timestamp: 2024-12-12T01:12:01.868Z
Learning: In the XRPL.js library, request parameters use camelCase (e.g., credentialType), while transaction model fields follow the XRP Ledger protocol's PascalCase convention (e.g., CredentialType).

Learnt from: mvadari
PR: #2801
File: packages/xrpl/src/Wallet/batchSigner.ts:0-0
Timestamp: 2025-04-16T15:55:50.121Z
Learning: When using encodeForSigningBatch for Batch transactions in the XRPL.js library, the field names should use camelCase (flags, txIDs) even though the transaction object properties themselves use PascalCase (Flags, TxIDs).

Learnt from: mvadari
PR: #2895
File: packages/xrpl/test/models/DIDDelete.test.ts:28-31
Timestamp: 2025-02-12T23:30:40.622Z
Learning: In JavaScript/TypeScript transaction validation tests, object key validation can be performed using:

  1. Object.keys() comparison with expected set
  2. TypeScript interfaces with strict object literal checks
  3. Object sanitization by filtering to allowed keys only

Learnt from: shawnxie999
PR: #2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for clawback.test.ts, it's acceptable to use @ts-expect-error to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.

Learnt from: mvadari
PR: #2801
File: packages/xrpl/src/sugar/autofill.ts:374-408
Timestamp: 2025-04-16T15:55:59.970Z
Learning: Code that is moved without substantial changes in a PR should not be the target of refactoring suggestions as it would be out of scope for the PR's primary purpose.

Learnt from: mvadari
PR: #2801
File: packages/xrpl/test/models/Batch.test.ts:0-0
Timestamp: 2025-04-16T15:22:45.633Z
Learning: Using as any type assertions is acceptable in test files for the XRPL.js project, as strict typing is not required for test code.

Learnt from: ckeshava
PR: #2826
File: packages/xrpl/tools/generateModels.js:25-25
Timestamp: 2025-01-13T22:38:40.085Z
Learning: When parsing rippled source files (e.g., macro files, cpp files) in tools/scripts, extensive error handling for regex matches is not needed as any malformed content would be caught by rippled's C++ compiler and unit tests during the build process.

Learnt from: mvadari
PR: #2826
File: packages/xrpl/tools/generateModels.js:36-36
Timestamp: 2024-11-18T23:29:19.882Z
Learning: In the file packages/xrpl/tools/generateModels.js, it's acceptable for the script to crash when the regex doesn't match as expected.

Learnt from: ckeshava
PR: #2874
File: packages/xrpl/src/models/ledger/PermissionedDomain.ts:3-8
Timestamp: 2025-01-08T02:08:00.476Z
Learning: In xrpl.js, the Credential interface must maintain a nested structure with a Credential property containing Issuer and CredentialType fields to mirror the structure defined in the rippled codebase.

Learnt from: ckeshava
PR: #2874
File: packages/xrpl/test/integration/transactions/permissionedDomain.test.ts:25-80
Timestamp: 2025-01-08T02:12:28.489Z
Learning: For PermissionedDomain feature (XLS-80d), complex error cases like invalid credential format, duplicate credentials, and non-existent DomainID are tested in the rippled C++ implementation rather than being duplicated across SDK implementations like xrpl.js.

Learnt from: achowdhry-ripple
PR: #2829
File: packages/xrpl/src/models/transactions/CredentialAccept.ts:36-44
Timestamp: 2024-12-18T20:54:40.935Z
Learning: The validateCredentialType function already checks that CredentialType is a properly hex-encoded string within the allowed length.

🧬 Code Graph Analysis (1)
packages/xrpl/src/models/transactions/common.ts (3)
packages/xrpl/src/models/transactions/index.ts (1)
  • validateMPTokenMetadata (1-1)
packages/xrpl/src/models/utils/index.ts (1)
  • isHex (60-62)
packages/xrpl/src/models/common/index.ts (1)
  • MPTokenMetadata (225-235)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Analyze (javascript)
  • GitHub Check: browser (22.x)
  • GitHub Check: integration (22.x)
  • GitHub Check: integration (20.x)
  • GitHub Check: unit (20.x)
  • GitHub Check: unit (22.x)
  • GitHub Check: build-and-lint (22.x)
🔇 Additional comments (4)
packages/xrpl/src/models/transactions/common.ts (4)

2-2: LGTM! Import addition is correct.

The hexToString import is necessary for the new metadata validation functionality.


15-15: LGTM! Constants are well-defined and follow XLS-89d specification.

The constants are properly organized, follow consistent naming conventions, and provide clear validation rules. The warning header effectively communicates the purpose and impact of non-compliance.

Also applies to: 26-26, 31-69


902-916: LGTM! Helper function is well-implemented.

The isValidMPTokenMetadataUrlStructure function properly validates the URL object structure, including type checking and field count validation. The implementation follows established patterns in the codebase.


854-856: URL validation approach is appropriate for this context.

The validation checks for HTTPS prefix rather than full URL validity, which is the right approach here since:

  1. It avoids network calls during validation
  2. It provides immediate feedback on protocol requirements
  3. Full URL validation would be expensive and potentially unreliable

This maintains performance while ensuring compliance with the security requirement of HTTPS URLs.

Also applies to: 892-895

@Patel-Raj11 Patel-Raj11 requested a review from khancode July 23, 2025 19:38
Copy link
Contributor

@khancode khancode left a comment

Choose a reason for hiding this comment

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

Left a comment but LGTM.

validationMessages.push(`url should be a valid https url.`)
}

return validationMessages
Copy link
Contributor

@khancode khancode Jul 24, 2025

Choose a reason for hiding this comment

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

Suggested change
return validationMessages
return validationMessages.length > 0 ? validationMessages : null

When there are no errors, I prefer returning null rather than returning an empty array to signal no errors. Then the calling function would only have to do a truthy check if (validationMessages) rather than if (validationMessages.length > 0).

Copy link
Contributor

Choose a reason for hiding this comment

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

I would also rename it to warningMessages so it's more explicit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think in general an empty list is better design than a function returning an optional list. The consumers of the functions are guaranteed to get a list as opposed to null or a list. This avoids mistakes at consumer end of iterating, accessing elements of a list that is not even present. In xrpl4j, this convention is followed for simplicity. (i.e. Empty array/list is as good as no array/list).

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fair, LGTM 👍

* Validates if MPTokenMetadata adheres to XLS-89d standard.
*
* @param input - Hex encoded MPTokenMetadata.
* @returns Validation error messages if MPTokenMetadata does not adheres to XLS-89d standard.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @returns Validation error messages if MPTokenMetadata does not adheres to XLS-89d standard.
* @returns Validation warning messages if MPTokenMetadata does not adheres to XLS-89d standard.

These are warning messages rather than errors right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This function just returns validation messages. Consumers decide whether to throw error or warnings. Updated to depict this.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/xrpl/src/models/transactions/common.ts (1)

858-860: Consider more robust URL validation.

The current validation only checks if URLs start with "https://". Consider using a more comprehensive URL validation to ensure the URLs are properly formatted.

-  if (!mptMPTokenMetadata.icon.startsWith('https://')) {
-    validationMessages.push(`icon should be a valid https url.`)
+  try {
+    const iconUrl = new URL(mptMPTokenMetadata.icon)
+    if (iconUrl.protocol !== 'https:') {
+      validationMessages.push(`icon should be a valid https url.`)
+    }
+  } catch {
+    validationMessages.push(`icon should be a valid https url.`)
   }

Similarly for the urls array validation:

-    !mptMPTokenMetadata.urls.every((ele) => ele.url.startsWith('https://'))
+    !mptMPTokenMetadata.urls.every((ele) => {
+      try {
+        const url = new URL(ele.url)
+        return url.protocol === 'https:'
+      } catch {
+        return false
+      }
+    })

Also applies to: 895-899

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8ad355b and d385b31.

📒 Files selected for processing (1)
  • packages/xrpl/src/models/transactions/common.ts (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Analyze (javascript)
  • GitHub Check: integration (22.x)
  • GitHub Check: build-and-lint (22.x)
  • GitHub Check: browser (22.x)
  • GitHub Check: integration (20.x)
  • GitHub Check: unit (20.x)
  • GitHub Check: unit (22.x)
🔇 Additional comments (5)
packages/xrpl/src/models/transactions/common.ts (5)

2-2: LGTM!

The new imports are appropriate for the MPTokenMetadata validation functionality.

Also applies to: 15-15


26-69: Well-structured constants for XLS-89d validation.

The constants are properly organized and follow the specification requirements. The warning header message clearly explains the purpose and implications of non-compliance.


755-779: Robust validation implementation with proper error handling.

The validation logic is well-structured with clear separation between format, structure, and content validation. The error handling for JSON parsing includes the error details which is helpful for debugging.


906-920: Clean helper function for URL structure validation.

The function properly validates the URL object structure with appropriate null checks and field count validation.


797-803: Good field count validation for strict compliance.

The field count check ensures metadata adheres to the expected structure and provides helpful feedback about the actual vs expected count.

@Patel-Raj11 Patel-Raj11 merged commit 7799528 into main Jul 24, 2025
13 checks passed
@Patel-Raj11 Patel-Raj11 deleted the mpt-metadata-warning branch July 24, 2025 17:16
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.

3 participants