-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/endorsement chain #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
manishdex25
wants to merge
4
commits into
beta
Choose a base branch
from
feature/endorsement-chain
base: beta
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fe64c76
feat: add endorsement-chain command for obligation escrow
manishdex25 0e532c0
chore: update dependencies and refactor escrow address handling
manishdex25 59c1668
fix: update verification output for BoE documents
manishdex25 2f3eec1
Merge branch 'beta' of github.com:TrustVC/trustvc-cli into feature/en…
manishdex25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import { info, success } from 'signale'; | ||
| import { fetchEndorsementChain } from '@trustvc/trustvc'; | ||
| import { BaseObligationEscrowCommand } from '../../types'; | ||
| import { | ||
| extractObligationDocumentInfo, | ||
| getSupportedNetwork, | ||
| promptAndReadDocument, | ||
| verifyDocumentSignature, | ||
| } from '../../utils'; | ||
| import { runObligationEscrowCommand } from './shared'; | ||
|
|
||
| export const command = 'endorsement-chain'; | ||
| export const describe = | ||
| 'Fetch BoE obligation endorsement chain (transfers + status events) via network Infura/RPC'; | ||
|
|
||
| /** Read-only — document only; decrypt remarks with credential `id`. */ | ||
| export type ObligationEscrowEndorsementChainCommand = Pick< | ||
| BaseObligationEscrowCommand, | ||
| 'network' | 'obligationRegistryAddress' | 'tokenId' | 'encryptionKey' | ||
| >; | ||
|
|
||
| export const handler = async (): Promise<void> => | ||
| runObligationEscrowCommand(promptForInputs, endorsementChainHandler); | ||
|
|
||
| export const promptForInputs = async (): Promise<ObligationEscrowEndorsementChainCommand> => { | ||
| const document = await promptAndReadDocument(); | ||
| await verifyDocumentSignature(document); | ||
| const { obligationRegistry, tokenId, network, documentId } = | ||
| await extractObligationDocumentInfo(document); | ||
| return { | ||
| network, | ||
| obligationRegistryAddress: obligationRegistry, | ||
| tokenId, | ||
| encryptionKey: documentId, | ||
| }; | ||
| }; | ||
|
|
||
| export const endorsementChainHandler = async (args: ObligationEscrowEndorsementChainCommand) => { | ||
| const { obligationRegistryAddress, tokenId, network, encryptionKey } = args; | ||
| // Always use ChainInfo/Infura-style network RPC — never a wallet provider (MetaMask range caps). | ||
| const provider = getSupportedNetwork(network).provider(); | ||
|
|
||
| info(`Fetching endorsement chain for ${tokenId} on ${obligationRegistryAddress} (${network})…`); | ||
| const chain = await fetchEndorsementChain( | ||
| obligationRegistryAddress, | ||
| tokenId, | ||
| provider as any, | ||
| encryptionKey, | ||
| ); | ||
|
|
||
| success(`Endorsement chain (${chain.length} event${chain.length === 1 ? '' : 's'})`); | ||
| let lastOwner = ''; | ||
| let lastHolder = ''; | ||
| const isZero = (value?: string) => !value || /^0x0{40}$/i.test(value); | ||
| chain.forEach((event, index) => { | ||
| const isShred = | ||
| event.type === 'RETURN_TO_ISSUER_ACCEPTED' || event.type === 'SURRENDER_ACCEPTED'; | ||
| // eBoE shred keeps last owner/holder on the shred row. | ||
| const owner = isZero(event.owner) ? lastOwner : event.owner || lastOwner; | ||
| const holder = isZero(event.holder) ? lastHolder : event.holder || lastHolder; | ||
| if (!isZero(owner)) lastOwner = owner; | ||
| if (!isZero(holder)) lastHolder = holder; | ||
| if (isShred) { | ||
| lastOwner = ''; | ||
| lastHolder = ''; | ||
| } | ||
|
|
||
| const when = event.timestamp ? new Date(event.timestamp).toISOString() : 'unknown-time'; | ||
| info(` ${index + 1}. [${event.type}] block=${event.blockNumber} @ ${when}`); | ||
| info(` Owner: ${owner || '-'}`); | ||
| info(` Holder: ${holder || '-'}`); | ||
| if (isShred && event.terminationReason && event.terminationReason !== 'None') { | ||
| const reasonLabel = | ||
| event.terminationReason === 'ReturnToIssuer' ? 'Return to issuer' : event.terminationReason; | ||
| info(` Reason: ${reasonLabel}`); | ||
| } | ||
| if (event.remark) info(` Remark: ${event.remark}`); | ||
| if (event.transactionHash) info(` Tx: ${event.transactionHash}`); | ||
| }); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
tests/commands/obligation-escrow/endorsement-chain.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import { beforeEach, describe, expect, it, MockedFunction, vi } from 'vitest'; | ||
| import { endorsementChainHandler } from '../../../src/commands/obligation-escrow/endorsement-chain'; | ||
| import { NetworkCmdName } from '../../../src/utils'; | ||
|
|
||
| vi.mock('signale', async (importOriginal) => { | ||
| const originalSignale = await importOriginal<typeof import('signale')>(); | ||
| return { | ||
| ...originalSignale, | ||
| Signale: class MockSignale { | ||
| await = vi.fn(); | ||
| success = vi.fn(); | ||
| error = vi.fn(); | ||
| info = vi.fn(); | ||
| warn = vi.fn(); | ||
| constructor() {} | ||
| }, | ||
| error: vi.fn(), | ||
| info: vi.fn(), | ||
| success: vi.fn(), | ||
| warn: vi.fn(), | ||
| await: vi.fn(), | ||
| default: { | ||
| await: vi.fn(), | ||
| success: vi.fn(), | ||
| error: vi.fn(), | ||
| info: vi.fn(), | ||
| warn: vi.fn(), | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| vi.mock('@trustvc/trustvc', async () => { | ||
| const actual = await vi.importActual<typeof import('@trustvc/trustvc')>('@trustvc/trustvc'); | ||
| return { | ||
| ...actual, | ||
| fetchEndorsementChain: vi.fn().mockResolvedValue([ | ||
| { | ||
| type: 'INITIAL', | ||
| blockNumber: 1, | ||
| timestamp: 1_700_000_000_000, | ||
| owner: '0xOwner', | ||
| holder: '0xHolder', | ||
| remark: 'minted', | ||
| transactionHash: '0xtx1', | ||
| }, | ||
| { | ||
| type: 'RETURN_TO_ISSUER_ACCEPTED', | ||
| blockNumber: 2, | ||
| timestamp: 1_700_000_100_000, | ||
| owner: '0xOwner', | ||
| holder: '0xHolder', | ||
| remark: 'burned', | ||
| transactionHash: '0xtx2', | ||
| terminationReason: 'Discharged', | ||
| }, | ||
| ]), | ||
| }; | ||
| }); | ||
|
|
||
| vi.mock('../../../src/utils', async (importOriginal) => { | ||
| const actual = await importOriginal<typeof import('../../../src/utils')>(); | ||
| return { | ||
| ...actual, | ||
| getSupportedNetwork: vi.fn().mockReturnValue({ | ||
| provider: () => ({ mock: 'infura-provider' }), | ||
| networkId: 11155111, | ||
| }), | ||
| getErrorMessage: (e: unknown) => (e instanceof Error ? e.message : String(e)), | ||
| }; | ||
| }); | ||
|
|
||
| describe('obligation-escrow/endorsement-chain', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('fetches chain via network Infura/RPC using document id as keyId', async () => { | ||
| const trustvc = await import('@trustvc/trustvc'); | ||
| const signale = await import('signale'); | ||
| await endorsementChainHandler({ | ||
| network: NetworkCmdName.Sepolia, | ||
| obligationRegistryAddress: '0xRegistry', | ||
| tokenId: '0x1', | ||
| encryptionKey: 'urn:uuid:test-doc-id', | ||
| }); | ||
|
|
||
| expect(trustvc.fetchEndorsementChain as MockedFunction<any>).toHaveBeenCalledWith( | ||
| '0xRegistry', | ||
| '0x1', | ||
| { mock: 'infura-provider' }, | ||
| 'urn:uuid:test-doc-id', | ||
| ); | ||
|
|
||
| const infoMock = signale.info as MockedFunction<any>; | ||
| const infoMessages = infoMock.mock.calls.map((args) => String(args[0])); | ||
| expect(infoMessages.some((msg) => msg.includes('Owner:') && msg.includes('0xOwner'))).toBe( | ||
| true, | ||
| ); | ||
| expect(infoMessages.some((msg) => msg.includes('Holder:') && msg.includes('0xHolder'))).toBe( | ||
| true, | ||
| ); | ||
| expect(infoMessages.some((msg) => msg.includes('Reason: Discharged'))).toBe(true); | ||
| expect(infoMessages.some((msg) => msg.includes('Remark: burned'))).toBe(true); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Preserve registry output when title escrow resolution fails.
If
getTitleEscrowAddressrejects,Promise.allrejects before the escrow-readcatchruns. The handler then prints no registry-level status, registration, or termination output.src/commands/obligation-escrow/status.ts#L67-L74: resolve the title escrow address separately from the registry reads. Catch resolution and escrow-read failures. Keep escrow output conditional on a resolved address.tests/commands/obligation-escrow/status.test.ts#L105-L134: rejectgetTitleEscrowAddressand assert that registry-level output still prints.📍 Affects 2 files
src/commands/obligation-escrow/status.ts#L67-L74(this comment)tests/commands/obligation-escrow/status.test.ts#L105-L134🤖 Prompt for AI Agents