feat: mint function#78
Conversation
* fix: add w3c credential status check * fix: update test * fix: update enum status codes * fix: remove console
## [1.5.4](v1.5.3...v1.5.4) (2025-06-17) ### Bug Fixes * add w3c credential status check ([#72](#72)) ([0111cb3](0111cb3))
## [1.5.5](v1.5.4...v1.5.5) (2025-06-18) ### Bug Fixes * upgrade package ([#73](#73)) ([3c6c9c7](3c6c9c7))
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe changes introduce new token registry functions for minting, rejecting transfers, and returning tokens, with full support for both ethers.js v5 and v6 and multiple token registry contract versions (V4 and V5). The update modularizes types and utilities, expands the public API, and adds comprehensive test suites using centralized fixtures and mocks. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant App
participant Signer
participant ContractFactory
participant Contract
User->>App: Initiate token operation (e.g., mint, transfer, reject)
App->>Signer: Validate provider and addresses
App->>ContractFactory: Connect to contract (V4 or V5)
App->>Contract: callStatic.<operation> (dry run)
Contract-->>App: Return result or throw error
App->>Contract: Execute <operation> with tx options
Contract-->>App: Return transaction response
App-->>User: Return transaction hash or error
Suggested labels
Suggested reviewers
Poem
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 24
🧹 Nitpick comments (5)
CHANGELOG.md (2)
5-5: Add explicit mention of the newly-addedmintcapability (and PR #78).This PR introduces a user-visible feature – the ability to mint tokens – yet the changelog line still generically states “token registry functions (#74)” from a previous PR.
Updating the bullet makes release notes clearer and prevents overlooking the new Jira ticket TT-781 / PR #78 during future audits.-- token registry functions ([#74](https://github.com/TrustVC/trustvc/issues/74)) ([5690fcd](https://github.com/TrustVC/trustvc/commit/5690fcda798192609b0060fab0a3f3f77dca8012)) +- token registry functions – add **mint / rejectTransfer / returnToken** support + ([#78](https://github.com/TrustVC/trustvc/pull/78)) ([commit-hash-here]) + ([#74](https://github.com/TrustVC/trustvc/issues/74)) ([5690fcd](https://github.com/TrustVC/trustvc/commit/5690fcda798192609b0060fab0a3f3f77dca8012))Please confirm the correct commit hash and wording, or drop in a new “Unreleased” section if this feature will not ship in
1.6.0-alpha.1.
9-9: Grammar tweak: “back-merge” or “back-merged”.The noun/verb agreement flagged by LanguageTool is valid – “back merge” reads awkwardly.
Either treat it as a noun phrase (“Back-merge”) or use the past tense verb (“back-merged”).-- back merge ([#75](https://github.com/TrustVC/trustvc/issues/75)) ... +- back-merge ([#75](https://github.com/TrustVC/trustvc/issues/75)) ...src/__tests__/token-registry-functions/mint.test.ts (1)
141-144: Remove unnecessary mock resetThe mock is being manually reset after the test, but
beforeEachalready callsvi.clearAllMocks()which handles this cleanup.Remove these lines as they are redundant:
- if (isV5TT) { - mockV5TradeTrustTokenContract.callStatic.mint = vi.fn(); - } else { - mockV4TradeTrustTokenContract.callStatic.mint = vi.fn(); - }src/token-registry-functions/returnToken.ts (2)
68-78: Remove redundant await inside Promise.all.Using
awaitinsidePromise.allis redundant and doesn't provide any benefit.[isV4TT, isV5TT] = await Promise.all([ - await isTitleEscrowVersion({ + isTitleEscrowVersion({ titleEscrowAddress, versionInterface: TitleEscrowInterface.V4, provider: signer.provider, }), - await isTitleEscrowVersion({ + isTitleEscrowVersion({ titleEscrowAddress, versionInterface: TitleEscrowInterface.V5, provider: signer.provider, }), ]);
119-130: Update JSDoc to reflect dual version support.The JSDoc comment states "only supported on Token Registry V5" but the implementation supports both V4 and V5 with the
restoreinterface.-* This is only supported on Token Registry V5 contracts with the `restore` functionality. +* This is supported on Token Registry V4/V5 contracts that implement the `restore` interface.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (14)
CHANGELOG.md(1 hunks)src/__tests__/token-registry-functions/fixtures.ts(1 hunks)src/__tests__/token-registry-functions/mint.test.ts(1 hunks)src/__tests__/token-registry-functions/rejectTransfers.test.ts(1 hunks)src/__tests__/token-registry-functions/returnToken.test.ts(1 hunks)src/__tests__/token-registry-functions/transfers.test.ts(2 hunks)src/core/endorsement-chain/useEndorsementChain.ts(1 hunks)src/token-registry-functions/index.ts(1 hunks)src/token-registry-functions/mint.ts(1 hunks)src/token-registry-functions/rejectTransfers.ts(1 hunks)src/token-registry-functions/returnToken.ts(1 hunks)src/token-registry-functions/transfer.ts(8 hunks)src/token-registry-functions/types.ts(1 hunks)src/token-registry-functions/utils.ts(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (6)
src/__tests__/token-registry-functions/rejectTransfers.test.ts (3)
src/token-registry-functions/types.ts (1)
ProviderInfo(79-83)src/__tests__/token-registry-functions/fixtures.ts (4)
providerV5(146-146)providerV6(147-147)PRIVATE_KEY(144-144)mockV5TitleEscrowContract(83-105)src/token-registry-functions/rejectTransfers.ts (3)
rejectTransferHolder(217-217)rejectTransferBeneficiary(217-217)rejectTransferOwners(217-217)
src/token-registry-functions/mint.ts (5)
src/token-registry-functions/types.ts (3)
MintTokenOptions(58-60)MintTokenParams(24-29)TransactionOptions(31-37)src/core/endorsement-chain/useEndorsementChain.ts (1)
checkSupportsInterface(148-164)src/index.ts (2)
v4SupportInterfaceIds(31-31)v5SupportInterfaceIds(35-35)src/core/encrypt.ts (1)
encrypt(17-42)src/token-registry-functions/utils.ts (1)
getTxOptions(44-44)
src/token-registry-functions/rejectTransfers.ts (4)
src/token-registry-functions/types.ts (3)
ContractOptions(39-49)RejectTransferParams(8-10)TransactionOptions(31-37)src/core/endorsement-chain/useEndorsementChain.ts (3)
getTitleEscrowAddress(104-133)isTitleEscrowVersion(179-196)TitleEscrowInterface(17-20)src/core/encrypt.ts (1)
encrypt(17-42)src/token-registry-functions/utils.ts (1)
getTxOptions(44-44)
src/token-registry-functions/types.ts (1)
src/__tests__/token-registry-functions/fixtures.ts (2)
providerV5(146-146)providerV6(147-147)
src/token-registry-functions/returnToken.ts (5)
src/token-registry-functions/types.ts (7)
ContractOptions(39-49)ReturnToIssuerParams(11-13)TransactionOptions(31-37)AcceptReturnedOptions(51-53)RejectReturnedParams(19-22)RejectReturnedOptions(54-56)AcceptReturnedParams(15-18)src/core/endorsement-chain/useEndorsementChain.ts (4)
getTitleEscrowAddress(104-133)isTitleEscrowVersion(179-196)TitleEscrowInterface(17-20)checkSupportsInterface(148-164)src/core/encrypt.ts (1)
encrypt(17-42)src/token-registry-functions/utils.ts (1)
getTxOptions(44-44)src/index.ts (2)
v4SupportInterfaceIds(31-31)v5SupportInterfaceIds(35-35)
src/token-registry-functions/transfer.ts (3)
src/token-registry-functions/types.ts (6)
ContractOptions(39-49)TransferHolderParams(62-65)TransactionOptions(31-37)TransferBeneficiaryParams(66-69)TransferOwnersParams(74-78)NominateParams(70-73)src/token-registry-functions/utils.ts (1)
getTxOptions(44-44)src/index.ts (1)
v4Contracts(34-34)
🪛 LanguageTool
CHANGELOG.md
[grammar] ~9-~9: There seems to be a noun/verb agreement error. Did you mean “merges” or “merged”?
Context: ...012)) ### Miscellaneous Chores - back merge ([#75](https://github.com/TrustVC/trust...
(SINGULAR_NOUN_VERB_AGREEMENT)
[uncategorized] ~90-~90: You might be missing the article “the” here.
Context: ...) (2025-04-22) ### Bug Fixes - update checkDidWebResolve function to use queryDidDocument ([#57]...
(AI_EN_LECTOR_MISSING_DETERMINER_THE)
🪛 Gitleaks (8.26.0)
src/__tests__/token-registry-functions/fixtures.ts
144-144: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
🔇 Additional comments (5)
src/core/endorsement-chain/useEndorsementChain.ts (1)
148-148: LGTM!The export of
checkSupportsInterfaceenables its use in the new token registry functions while maintaining backward compatibility.src/token-registry-functions/index.ts (1)
2-4: Good API consolidation!The new exports follow the existing pattern and provide a clean, centralized entry point for all token registry functions.
src/__tests__/token-registry-functions/transfers.test.ts (1)
1-1: Good test refactoring!Moving mock definitions to a centralized fixtures file improves maintainability and reduces code duplication across test suites.
Also applies to: 4-4, 14-21
src/token-registry-functions/transfer.ts (2)
9-19: LGTM! Clean refactoring to use centralized utilities.The migration to use imported types and the centralized
getTxOptionsutility improves code maintainability and reduces duplication across all transfer functions.Also applies to: 125-125, 248-248, 381-381, 503-503
21-36: Excellent documentation coverage!The JSDoc comments provide comprehensive documentation for all public functions, including parameter descriptions, error conditions, and return values. This greatly improves the developer experience.
Also applies to: 142-159, 267-285, 401-418
| let titleEscrowContract: v5Contracts.TitleEscrow | v4Contracts.TitleEscrow = | ||
| v5Contracts.TitleEscrow__factory.connect(titleEscrowAddress, signer); | ||
|
|
||
| const encryptedRemarks = remarks ? `0x${encrypt(remarks, options.id!)}` : '0x'; |
There was a problem hiding this comment.
Handle optional encryption ID safely.
The code uses non-null assertion (options.id!) on an optional parameter, which could cause runtime errors if id is not provided when remarks is present.
-const encryptedRemarks = remarks ? `0x${encrypt(remarks, options.id!)}` : '0x';
+const encryptedRemarks = remarks && options.id ? `0x${encrypt(remarks, options.id)}` : '0x';Also applies to: 180-180, 274-274
🤖 Prompt for AI Agents
In src/token-registry-functions/returnToken.ts at lines 60, 180, and 274, the
code uses a non-null assertion on options.id when encrypting remarks, which
risks runtime errors if id is undefined. Modify the code to safely check if
options.id exists before calling encrypt; if id is missing when remarks are
present, handle the case gracefully by either skipping encryption or throwing a
clear error. This ensures no unsafe assumptions about options.id and prevents
potential crashes.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 3
♻️ Duplicate comments (2)
src/token-registry-functions/returnToken.ts (2)
180-180: Handle optional encryption ID safely.The code uses non-null assertion (
options.id!) on an optional parameter, which could cause runtime errors ifidis not provided whenremarksis present.- const encryptedRemarks = remarks && isV5TT ? `0x${encrypt(remarks, options.id!)}` : '0x'; + const encryptedRemarks = remarks && isV5TT && options.id ? `0x${encrypt(remarks, options.id)}` : '0x';
274-274: Handle optional encryption ID safely.The code uses non-null assertion (
options.id!) on an optional parameter, which could cause runtime errors ifidis not provided whenremarksis present.- const encryptedRemarks = remarks && isV5TT ? `0x${encrypt(remarks, options.id!)}` : '0x'; + const encryptedRemarks = remarks && isV5TT && options.id ? `0x${encrypt(remarks, options.id)}` : '0x';
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
src/__tests__/token-registry-functions/fixtures.ts(1 hunks)src/__tests__/token-registry-functions/mint.test.ts(1 hunks)src/__tests__/token-registry-functions/rejectTransfers.test.ts(1 hunks)src/__tests__/token-registry-functions/returnToken.test.ts(1 hunks)src/token-registry-functions/mint.ts(1 hunks)src/token-registry-functions/rejectTransfers.ts(1 hunks)src/token-registry-functions/returnToken.ts(1 hunks)src/token-registry-functions/types.ts(1 hunks)src/token-registry-functions/utils.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
- src/tests/token-registry-functions/mint.test.ts
- src/token-registry-functions/mint.ts
- src/tests/token-registry-functions/rejectTransfers.test.ts
- src/token-registry-functions/rejectTransfers.ts
- src/tests/token-registry-functions/fixtures.ts
- src/token-registry-functions/utils.ts
- src/token-registry-functions/types.ts
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/__tests__/token-registry-functions/returnToken.test.ts (3)
src/token-registry-functions/types.ts (1)
ProviderInfo(79-83)src/__tests__/token-registry-functions/fixtures.ts (9)
providerV5(146-146)providerV6(147-147)PRIVATE_KEY(144-144)mockV5TitleEscrowContract(83-105)mockV4TitleEscrowContract(107-123)MOCK_V5_ADDRESS(4-4)MOCK_V4_ADDRESS(5-5)mockV5TradeTrustTokenContract(70-81)mockV4TradeTrustTokenContract(131-142)src/token-registry-functions/returnToken.ts (3)
returnToIssuer(306-306)rejectReturned(306-306)acceptReturned(306-306)
src/token-registry-functions/returnToken.ts (5)
src/token-registry-functions/types.ts (7)
ContractOptions(38-48)ReturnToIssuerParams(10-12)TransactionOptions(30-36)AcceptReturnedOptions(50-52)RejectReturnedParams(18-21)RejectReturnedOptions(53-55)AcceptReturnedParams(14-17)src/core/endorsement-chain/useEndorsementChain.ts (4)
getTitleEscrowAddress(104-133)isTitleEscrowVersion(179-196)TitleEscrowInterface(17-20)checkSupportsInterface(148-164)src/core/encrypt.ts (1)
encrypt(17-42)src/token-registry-functions/utils.ts (1)
getTxOptions(44-44)src/index.ts (2)
v4SupportInterfaceIds(31-31)v5SupportInterfaceIds(35-35)
| mockV4TradeTrustTokenContract.callStatic.burn.mockResolvedValue(true); | ||
| }); | ||
|
|
||
| it('should reject returned token with remarks', async () => { |
There was a problem hiding this comment.
Fix incorrect test description.
The test description says "should reject returned token" but it's testing the acceptReturned function.
- it('should reject returned token with remarks', async () => {
+ it('should accept returned token with remarks', async () => {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| it('should reject returned token with remarks', async () => { | |
| it('should accept returned token with remarks', async () => { |
🤖 Prompt for AI Agents
In src/__tests__/token-registry-functions/returnToken.test.ts at line 353, the
test description incorrectly states "should reject returned token" while the
test actually verifies the acceptReturned function. Update the test description
to accurately reflect that it tests accepting a returned token, for example,
change it to "should accept returned token with remarks."
| ).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should reject returned token without remarks', async () => { |
There was a problem hiding this comment.
Fix incorrect test description.
The test description says "should reject returned token" but it's testing the acceptReturned function.
- it('should reject returned token without remarks', async () => {
+ it('should accept returned token without remarks', async () => {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| it('should reject returned token without remarks', async () => { | |
| it('should accept returned token without remarks', async () => { |
🤖 Prompt for AI Agents
In src/__tests__/token-registry-functions/returnToken.test.ts at line 368, the
test description incorrectly states "should reject returned token" while the
test is actually for the acceptReturned function. Update the test description to
accurately reflect that it is testing the acceptance of a returned token, such
as changing it to "should accept returned token without remarks" or a similar
correct description.
| ); | ||
| } | ||
|
|
||
| if (!titleEscrowAddress) throw new Error('Token registry address is required'); |
There was a problem hiding this comment.
Fix incorrect error message.
The condition checks for titleEscrowAddress but the error message references "Token registry address".
- if (!titleEscrowAddress) throw new Error('Token registry address is required');
+ if (!titleEscrowAddress) throw new Error('Title escrow address is required');📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (!titleEscrowAddress) throw new Error('Token registry address is required'); | |
| if (!titleEscrowAddress) throw new Error('Title escrow address is required'); |
🤖 Prompt for AI Agents
In src/token-registry-functions/returnToken.ts at line 52, the error message
incorrectly states "Token registry address is required" when the condition
checks for titleEscrowAddress. Update the error message to accurately reflect
the missing variable by changing it to "Title escrow address is required".
|
🎉 This PR is included in version 1.6.0-alpha.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary
added token registry Mint function
Issues
Jira Ticket
Summary by CodeRabbit
New Features
Refactor
Tests
Documentation
Chores