-
Notifications
You must be signed in to change notification settings - Fork 1
feat: mdoc cert pull #11
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
Changes from 1 commit
3bf1486
0ba0662
36568a8
d1eefc7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,6 +21,7 @@ import { | |||||||
| ProofsModule, | ||||||||
| V2CredentialProtocol, | ||||||||
| V2ProofProtocol, | ||||||||
| X509Module, | ||||||||
| } from '@credo-ts/core' | ||||||||
| import { IndyVdrAnonCredsRegistry, IndyVdrModule, IndyVdrPoolConfig } from '@credo-ts/indy-vdr' | ||||||||
| import { OpenId4VcHolderModule } from '@credo-ts/openid4vc' | ||||||||
|
|
@@ -34,18 +35,46 @@ interface GetAgentModulesOptions { | |||||||
| indyNetworks: IndyVdrPoolConfig[] | ||||||||
| mediatorInvitationUrl?: string | ||||||||
| txnCache?: { capacity: number; expiryOffsetMs: number; path?: string } | ||||||||
| trustedCertificates?: string[] | ||||||||
| } | ||||||||
|
|
||||||||
| export type BifoldAgent = Agent<ReturnType<typeof getAgentModules>> | ||||||||
|
|
||||||||
| /** | ||||||||
| * Fetches trusted certificates from a remote API | ||||||||
| * @param url The API endpoint URL | ||||||||
| * @returns Array of certificate strings | ||||||||
| */ | ||||||||
| async function fetchTrustedCertificates(url: string): Promise<string[]> { | ||||||||
| try { | ||||||||
| const response = await fetch(url) | ||||||||
|
||||||||
| if (!response.ok) { | ||||||||
| return [] | ||||||||
| } | ||||||||
| const certificates = await response.json() | ||||||||
| if (!Array.isArray(certificates)) { | ||||||||
| return [] | ||||||||
| } | ||||||||
| return certificates.filter((cert) => typeof cert === 'string' && cert.trim().length > 0) | ||||||||
|
Comment on lines
+60
to
+64
|
||||||||
| } catch (error) { | ||||||||
SpencerMckayQ marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| } catch (error) { | |
| } catch (error) { | |
| console.error(`Failed to fetch trusted certificates from "${url}". Returning empty list.`, error) |
Copilot
AI
Feb 20, 2026
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.
The function fetchTrustedCertificates returns an empty array on failure (lines 58, 62, 66). However, there's no way for the caller to distinguish between "no certificates available" and "fetch failed". This could lead to silent failures where an agent is initialized without certificates when they should be available. Consider returning a result object with success status or throwing an error that can be caught and logged at a higher level.
SpencerMckayQ marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Feb 20, 2026
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.
The type assertion 'trustedCertificates as [string, ...string[]]' could be unsafe if the array is empty. Although the condition checks 'trustedCertificates.length > 0', TypeScript doesn't narrow the type based on the length check. Consider using a type guard function or explicitly checking if the array has at least one element before the type assertion to make the code more type-safe.
| trustedCertificates: trustedCertificates as [string, ...string[]], | |
| trustedCertificates: [trustedCertificates[0], ...trustedCertificates.slice(1)], |
Copilot
AI
Feb 20, 2026
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.
The X509Module is conditionally added only when trustedCertificates.length is greater than 0. However, other parts of the codebase (e.g., resolverProof.tsx) use agent.x509 directly, which could cause runtime errors if the module is not registered. The removed code in offerResolve.tsx also accessed agent.x509 directly. Consider either always registering the X509Module with an empty array or ensuring all usages check for the module's existence first.
Copilot
AI
Feb 20, 2026
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.
The new functions fetchTrustedCertificates and getAgentModulesWithCertificates lack test coverage. Given that the repository has comprehensive tests for utility functions (as seen in tests/utils/), these new functions should have tests covering success cases, failure cases (network errors, malformed responses), and edge cases (empty arrays, invalid certificate formats).
Uh oh!
There was an error while loading. Please reload this page.