Conversation
Signed-off-by: Krishna Waske <krishna.waske@ayanworks.com>
Signed-off-by: Krishna Waske <krishna.waske@ayanworks.com>
|
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 ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis PR enables Polygon DID support in the agent by updating the polygon module dependency constraint from exact to flexible versioning, adding Polygon registrars and resolvers to the DID configuration, instantiating and configuring the PolygonModule with contract addresses and RPC settings, and introducing new API routes and OpenAPI documentation for Polygon operations including key creation, schema management, transaction estimation, and schema retrieval. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
1 similar comment
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 7
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/cliAgent.ts (1)
174-186:⚠️ Potential issue | 🟡 MinorAdd trailing commas to satisfy formatter checks.
Line 178 and Line 185 are missing trailing commas and currently fail Prettier.
Suggested fix
registrars: [ new IndyVdrIndyDidRegistrar(), new KeyDidRegistrar(), new JwkDidRegistrar(), - new PolygonDidRegistrar() + new PolygonDidRegistrar(), ], resolvers: [ new IndyVdrIndyDidResolver(), new KeyDidResolver(), new WebDidResolver(), new JwkDidResolver(), - new PolygonDidResolver() + new PolygonDidResolver(), ],🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/cliAgent.ts` around lines 174 - 186, Add trailing commas to the arrays in the registrars and resolvers object so Prettier passes; specifically, update the registrars array (after PolygonDidRegistrar()) and the resolvers array (after PolygonDidResolver()) in src/cliAgent.ts to include a trailing comma each, ensuring the entries for new PolygonDidRegistrar() and new PolygonDidResolver() end with commas.
🧹 Nitpick comments (1)
src/routes/swagger.json (1)
3807-3812: Polygon 200 responses use empty schemas (schema: {}), which weakens API contract documentation and client type generation.The three endpoints
/polygon/create-schema(POST),/polygon/estimate-transaction(POST), and/polygon/{did}/{schemaId}(GET) all return untyped responses. TheRecord_string.unknown_schema exists in components and can be referenced to provide proper typing.🔧 Suggested schema contract improvement
"/polygon/create-schema": { "post": { "responses": { "200": { "description": "Schema JSON", "content": { "application/json": { - "schema": {} + "schema": { + "$ref": "#/components/schemas/Record_string.unknown_" + } } } } } } }, "/polygon/estimate-transaction": { "post": { "responses": { "200": { "description": "Transaction Object", "content": { "application/json": { - "schema": {} + "schema": { + "$ref": "#/components/schemas/Record_string.unknown_" + } } } } } } }, "/polygon/{did}/{schemaId}": { "get": { "responses": { "200": { "description": "Schema Object", "content": { "application/json": { - "schema": {} + "schema": { + "$ref": "#/components/schemas/Record_string.unknown_" + } } } } } } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/routes/swagger.json` around lines 3807 - 3812, The 200 responses for the Polygon endpoints are using empty schemas (schema: {}); update the OpenAPI response objects for the three paths "/polygon/create-schema" (POST), "/polygon/estimate-transaction" (POST), and "/polygon/{did}/{schemaId}" (GET) to reference the existing components schema "Record_string.unknown_" instead of an empty object so clients and generated types get proper typing; locate the response objects in swagger.json for those paths and replace the empty "schema": {} entries under "content": {"application/json"} with a $ref to "#/components/schemas/Record_string.unknown_".
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@package.json`:
- Line 42: The dependency entry for "@ayanworks/credo-polygon-w3c-module" is
pinned to ^2.0.0 which doesn't exist; update that dependency value in
package.json to a published version (e.g., "^1.0.0" or "1.0.0") so npm install
can succeed, then regenerate lockfile by running npm install (or yarn install)
to update package-lock.json/yarn.lock accordingly.
In `@src/cliAgent.ts`:
- Line 68: The import statement for PolygonDidRegistrar, PolygonDidResolver,
PolygonModule from '@ayanworks/credo-polygon-w3c-module' is in the wrong import
group; move that line into the external (third-party) imports block so it obeys
the import/order rule. Locate the import of "PolygonDidRegistrar,
PolygonDidResolver, PolygonModule" in src/cliAgent.ts and place it with other
external package imports (not with local/internal or parent imports) ensuring
any alphabetization/grouping used by the file's existing import ordering is
preserved.
- Around line 240-249: The PolygonModule is being passed values that use `as
string` fallbacks which can hide missing envs; update the initialization where
`polygon: new PolygonModule({ ... })` is constructed to call the codebase's
requireEnv helper for required settings (e.g. DID_CONTRACT_ADDRESS,
SCHEMA_MANAGER_CONTRACT_ADDRESS, FILE_SERVER_TOKEN, RPC_URL, SERVER_URL) when
the corresponding CLI variables (didRegistryContractAddress,
schemaManagerContractAddress, fileServerToken, rpcUrl, fileServerUrl) are not
provided, so that requireEnv(...) throws immediately on missing configuration
instead of passing undefined strings into PolygonModule.
In `@src/routes/routes.ts`:
- Around line 9-10: The routes import and DI resolution reference the Polygon
controller symbol (import { Polygon } and container.get<Polygon>(Polygon)) but
the PolygonController implementation/export is commented out, causing
build/runtime failures; restore or re-export the Polygon controller class with
its routed methods (ensure class name matches Polygon or update the import),
then re-run tsoa to regenerate routes so the auto-generated routes.ts and
container resolution align (verify PolygonController exports the expected
methods used by routes and that the symbol name matches the import/container.get
usage).
In `@src/routes/swagger.json`:
- Around line 485-488: The swagger schema for the "resource" property currently
disallows any properties (it declares "type": "object" with
"additionalProperties": false), which blocks real addResource payloads; update
the "resource" schema used by the addResource operation to either (a) remove
"additionalProperties": false so arbitrary resource fields are allowed, (b) set
"additionalProperties": true to permit dynamic properties, or (c) explicitly
declare the expected properties and their types under "resource" so valid
payloads can pass validation; adjust the "required" list accordingly if needed.
In `@src/utils/agent.ts`:
- Line 33: The import for PolygonModule ("import { PolygonModule } from
'@ayanworks/credo-polygon-w3c-module'") is out of order and triggers the
import/order ESLint rule; move that line into the correct import group with
other third-party/externals (keeping it with other node_modules imports), ensure
it follows the project's import grouping and ordering style, and then run ESLint
or use the project's import sorter to reformat imports so the import/order rule
passes.
- Around line 130-136: The PolygonModule is being instantiated with empty
strings; replace those hardcoded empty values by reading the corresponding
environment variables (e.g., process.env.DID_CONTRACT_ADDRESS,
process.env.SCHEMA_MANAGER_CONTRACT_ADDRESS, process.env.FILE_SERVER_TOKEN,
process.env.POLYGON_RPC_URL or similar RPC env var, and
process.env.POLYGON_SERVER_URL) when constructing PolygonModule in the
PolygonModule(...) call, and perform a fail-fast check (throw an error or exit)
if any required env var is missing so the app fails at startup rather than
causing runtime failures.
---
Outside diff comments:
In `@src/cliAgent.ts`:
- Around line 174-186: Add trailing commas to the arrays in the registrars and
resolvers object so Prettier passes; specifically, update the registrars array
(after PolygonDidRegistrar()) and the resolvers array (after
PolygonDidResolver()) in src/cliAgent.ts to include a trailing comma each,
ensuring the entries for new PolygonDidRegistrar() and new PolygonDidResolver()
end with commas.
---
Nitpick comments:
In `@src/routes/swagger.json`:
- Around line 3807-3812: The 200 responses for the Polygon endpoints are using
empty schemas (schema: {}); update the OpenAPI response objects for the three
paths "/polygon/create-schema" (POST), "/polygon/estimate-transaction" (POST),
and "/polygon/{did}/{schemaId}" (GET) to reference the existing components
schema "Record_string.unknown_" instead of an empty object so clients and
generated types get proper typing; locate the response objects in swagger.json
for those paths and replace the empty "schema": {} entries under "content":
{"application/json"} with a $ref to
"#/components/schemas/Record_string.unknown_".
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e5c246a7-5258-4039-b633-eddeaab6f211
⛔ Files ignored due to path filters (1)
yarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (5)
package.jsonsrc/cliAgent.tssrc/routes/routes.tssrc/routes/swagger.jsonsrc/utils/agent.ts
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (7)
src/utils/agent.ts (2)
33-33:⚠️ Potential issue | 🟡 MinorFix external import grouping for
PolygonModule.Line 33 is still below a local import and continues to violate
import/order.Suggested fix
import type { InitConfig } from '@credo-ts/core' +import { PolygonModule } from '@ayanworks/credo-polygon-w3c-module' @@ import { TsLogger } from './logger' -import { PolygonModule } from '@ayanworks/credo-polygon-w3c-module'🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/utils/agent.ts` at line 33, The import for PolygonModule is placed after a local import and violates import/order; move the line importing PolygonModule from '@ayanworks/credo-polygon-w3c-module' into the external (third-party) imports block so it appears with other external dependencies (above any local/project-relative imports), then re-run the linter/formatter to ensure import/order is satisfied; reference the PolygonModule import statement to locate and relocate it.
130-136:⚠️ Potential issue | 🟠 MajorAvoid booting PolygonModule with empty required config.
Lines 130-135 pass hardcoded empty strings, which will defer failure to runtime. Load required env values and fail fast during startup.
Suggested fix
+const requireEnv = (name: string): string => { + const value = process.env[name] + if (!value) throw new Error(`Missing environment variable: ${name}`) + return value +} + @@ polygon: new PolygonModule({ - didContractAddress: '', - schemaManagerContractAddress: '', - fileServerToken: '', - rpcUrl: '', - serverUrl: '', + didContractAddress: requireEnv('DID_CONTRACT_ADDRESS'), + schemaManagerContractAddress: requireEnv('SCHEMA_MANAGER_CONTRACT_ADDRESS'), + fileServerToken: requireEnv('FILE_SERVER_TOKEN'), + rpcUrl: requireEnv('RPC_URL'), + serverUrl: requireEnv('SERVER_URL'), }),🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/utils/agent.ts` around lines 130 - 136, PolygonModule is being instantiated with empty strings for required config, which defers errors to runtime; update the initialization to read the required environment/config values (didContractAddress, schemaManagerContractAddress, fileServerToken, rpcUrl, serverUrl) and validate them before constructing PolygonModule (e.g., throw or log fatal and exit if any are missing/invalid) so startup fails fast; locate the PolygonModule instantiation and replace the hardcoded empty values with the validated config variables (and add a short helper or inline checks to surface a clear error if any required value is absent).src/cliAgent.ts (2)
68-68:⚠️ Potential issue | 🟡 MinorReorder
Polygonimport to satisfyimport/order.Line 68 is still out of the external import grouping and will keep lint failing.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/cliAgent.ts` at line 68, The import for PolygonDidRegistrar, PolygonDidResolver, PolygonModule is currently misplaced and violating import/order; move the line "import { PolygonDidRegistrar, PolygonDidResolver, PolygonModule } from '@ayanworks/credo-polygon-w3c-module'" into the external-imports group with the other third-party imports (keeping a single blank line between external and internal imports) so the external grouping order is preserved and the linter passes.
240-249:⚠️ Potential issue | 🟠 MajorFail fast for required Polygon config instead of using
as stringfallbacks.These assertions can hide missing env vars and pass invalid runtime config into module initialization.
Suggested fix
polygon: new PolygonModule({ - didContractAddress: didRegistryContractAddress - ? didRegistryContractAddress - : (process.env.DID_CONTRACT_ADDRESS as string), - schemaManagerContractAddress: - schemaManagerContractAddress || (process.env.SCHEMA_MANAGER_CONTRACT_ADDRESS as string), - fileServerToken: fileServerToken ? fileServerToken : (process.env.FILE_SERVER_TOKEN as string), - rpcUrl: rpcUrl ? rpcUrl : (process.env.RPC_URL as string), - serverUrl: fileServerUrl ? fileServerUrl : (process.env.SERVER_URL as string), + didContractAddress: didRegistryContractAddress || requireEnv('DID_CONTRACT_ADDRESS'), + schemaManagerContractAddress: + schemaManagerContractAddress || requireEnv('SCHEMA_MANAGER_CONTRACT_ADDRESS'), + fileServerToken: fileServerToken || requireEnv('FILE_SERVER_TOKEN'), + rpcUrl: rpcUrl || requireEnv('RPC_URL'), + serverUrl: fileServerUrl || requireEnv('SERVER_URL'), }),#!/bin/bash # Verify no unsafe `as string` env fallbacks remain for PolygonModule config rg -n "polygon: new PolygonModule|didContractAddress:|schemaManagerContractAddress:|fileServerToken:|rpcUrl:|serverUrl:" src/cliAgent.ts -C2 rg -n "process\.env\.(DID_CONTRACT_ADDRESS|SCHEMA_MANAGER_CONTRACT_ADDRESS|FILE_SERVER_TOKEN|RPC_URL|SERVER_URL)\s+as string" src/cliAgent.ts🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/cliAgent.ts` around lines 240 - 249, The PolygonModule initialization currently uses unsafe "as string" fallbacks which can hide missing env vars; update the code that constructs new PolygonModule so each field (didContractAddress, schemaManagerContractAddress, fileServerToken, rpcUrl, serverUrl) first prefers the explicit parameter (e.g., didRegistryContractAddress, schemaManagerContractAddress, fileServerToken, rpcUrl, fileServerUrl) and if absent reads process.env, and if the resulting value is undefined or empty throw a clear Error (fail fast) instead of casting with "as string"; remove all "as string" assertions and ensure the constructor receives validated non-empty strings.package.json (1)
42-42:⚠️ Potential issue | 🟠 MajorVerify
@ayanworks/credo-polygon-w3c-module@^2.0.0is actually published.If
2.xis unavailable, dependency install will fail; pin to a published version and regenerate lockfile.#!/bin/bash # Verify published versions and compatibility metadata from npm npm view `@ayanworks/credo-polygon-w3c-module` versions --json npm view `@ayanworks/credo-polygon-w3c-module`@2.0.0 version npm view `@ayanworks/credo-polygon-w3c-module`@1.0.0 peerDependencies --json🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@package.json` at line 42, The dependency entry "@ayanworks/credo-polygon-w3c-module": "^2.0.0" may point to an unpublished 2.x release; verify publication with npm view for versions and the specific 2.0.0 tag, and if 2.0.0 is not published change the package.json dependency to a published version (e.g., pin to the latest 1.x release) replacing the "^2.0.0" string, then regenerate the lockfile (npm install or npm ci) and commit the updated package.json and lockfile; reference the package name "@ayanworks/credo-polygon-w3c-module" and the version token "^2.0.0" when making the change.src/routes/routes.ts (1)
9-10:⚠️ Potential issue | 🔴 CriticalEnsure
Polygoncontroller symbol and routed methods exist and are active.These route bindings depend on
PolygonpluscreateKeyPair/createSchema/estimateTransaction/getSchemaById. If those are missing/commented insrc/controllers/polygon/PolygonController.ts, route resolution breaks.#!/bin/bash # Verify Polygon controller export and required methods sed -n '1,260p' src/controllers/polygon/PolygonController.ts rg -n "export class Polygon|class Polygon" src/controllers/polygon/PolygonController.ts -C2 rg -nP "^\s*(public\s+)?(async\s+)?(createKeyPair|createSchema|estimateTransaction|getSchemaById)\s*\(" src/controllers/polygon/PolygonController.ts -C2 rg -n "Polygon\.prototype\.(createKeyPair|createSchema|estimateTransaction|getSchemaById)" src/routes/routes.tsAlso applies to: 1775-1920
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/routes/routes.ts` around lines 9 - 10, The routes file imports Polygon and expects the controller class and methods createKeyPair, createSchema, estimateTransaction, and getSchemaById to be present and exported; inspect src/controllers/polygon/PolygonController.ts and ensure it exports "class Polygon" (or an exported const/class named Polygon) and that the four methods are implemented as public (not commented out) with matching names/signatures; if missing, re-add or uncomment these methods or export the Polygon symbol (or adjust the routes to the actual exported name) so that references like Polygon.prototype.createKeyPair in routes.ts resolve correctly.src/routes/swagger.json (1)
485-488:⚠️ Potential issue | 🟠 Major
resourcestill only accepts{}inAddResourceDidOperationOptions.At Line 486,
additionalProperties: falseis set with no declaredproperties, so the requiredresourcefield (Line 498) cannot carry real payload content.🔧 Proposed fix
"AddResourceDidOperationOptions": { "properties": { "did": { "type": "string" }, "resource": { - "additionalProperties": false, - "type": "object" + "$ref": "#/components/schemas/Record_string.unknown_" }, "resourceId": { "type": "string" },#!/bin/bash jq '.components.schemas.AddResourceDidOperationOptions.properties.resource' src/routes/swagger.json🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/routes/swagger.json` around lines 485 - 488, The AddResourceDidOperationOptions schema's "resource" field is currently defined as an object with "additionalProperties": false and no declared properties, which effectively disallows any payload; update the AddResourceDidOperationOptions -> properties -> resource schema (the "resource" entry) to allow arbitrary object content by either removing "additionalProperties": false or setting "additionalProperties": true (or explicitly declaring the expected properties for resource), so the "resource" field can carry real payloads.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/cliAgent.ts`:
- Around line 178-185: The array literals constructing the registrars and
resolvers (specifically the entries using PolygonDidRegistrar,
IndyVdrIndyDidResolver, KeyDidResolver, WebDidResolver, JwkDidResolver, and
PolygonDidResolver) are missing trailing commas which breaks the formatter;
update both arrays so each item line ends with a trailing comma (e.g., after new
PolygonDidRegistrar() and new PolygonDidResolver()) to satisfy Prettier rules
and ensure the file formats cleanly.
---
Duplicate comments:
In `@package.json`:
- Line 42: The dependency entry "@ayanworks/credo-polygon-w3c-module": "^2.0.0"
may point to an unpublished 2.x release; verify publication with npm view for
versions and the specific 2.0.0 tag, and if 2.0.0 is not published change the
package.json dependency to a published version (e.g., pin to the latest 1.x
release) replacing the "^2.0.0" string, then regenerate the lockfile (npm
install or npm ci) and commit the updated package.json and lockfile; reference
the package name "@ayanworks/credo-polygon-w3c-module" and the version token
"^2.0.0" when making the change.
In `@src/cliAgent.ts`:
- Line 68: The import for PolygonDidRegistrar, PolygonDidResolver, PolygonModule
is currently misplaced and violating import/order; move the line "import {
PolygonDidRegistrar, PolygonDidResolver, PolygonModule } from
'@ayanworks/credo-polygon-w3c-module'" into the external-imports group with the
other third-party imports (keeping a single blank line between external and
internal imports) so the external grouping order is preserved and the linter
passes.
- Around line 240-249: The PolygonModule initialization currently uses unsafe
"as string" fallbacks which can hide missing env vars; update the code that
constructs new PolygonModule so each field (didContractAddress,
schemaManagerContractAddress, fileServerToken, rpcUrl, serverUrl) first prefers
the explicit parameter (e.g., didRegistryContractAddress,
schemaManagerContractAddress, fileServerToken, rpcUrl, fileServerUrl) and if
absent reads process.env, and if the resulting value is undefined or empty throw
a clear Error (fail fast) instead of casting with "as string"; remove all "as
string" assertions and ensure the constructor receives validated non-empty
strings.
In `@src/routes/routes.ts`:
- Around line 9-10: The routes file imports Polygon and expects the controller
class and methods createKeyPair, createSchema, estimateTransaction, and
getSchemaById to be present and exported; inspect
src/controllers/polygon/PolygonController.ts and ensure it exports "class
Polygon" (or an exported const/class named Polygon) and that the four methods
are implemented as public (not commented out) with matching names/signatures; if
missing, re-add or uncomment these methods or export the Polygon symbol (or
adjust the routes to the actual exported name) so that references like
Polygon.prototype.createKeyPair in routes.ts resolve correctly.
In `@src/routes/swagger.json`:
- Around line 485-488: The AddResourceDidOperationOptions schema's "resource"
field is currently defined as an object with "additionalProperties": false and
no declared properties, which effectively disallows any payload; update the
AddResourceDidOperationOptions -> properties -> resource schema (the "resource"
entry) to allow arbitrary object content by either removing
"additionalProperties": false or setting "additionalProperties": true (or
explicitly declaring the expected properties for resource), so the "resource"
field can carry real payloads.
In `@src/utils/agent.ts`:
- Line 33: The import for PolygonModule is placed after a local import and
violates import/order; move the line importing PolygonModule from
'@ayanworks/credo-polygon-w3c-module' into the external (third-party) imports
block so it appears with other external dependencies (above any
local/project-relative imports), then re-run the linter/formatter to ensure
import/order is satisfied; reference the PolygonModule import statement to
locate and relocate it.
- Around line 130-136: PolygonModule is being instantiated with empty strings
for required config, which defers errors to runtime; update the initialization
to read the required environment/config values (didContractAddress,
schemaManagerContractAddress, fileServerToken, rpcUrl, serverUrl) and validate
them before constructing PolygonModule (e.g., throw or log fatal and exit if any
are missing/invalid) so startup fails fast; locate the PolygonModule
instantiation and replace the hardcoded empty values with the validated config
variables (and add a short helper or inline checks to surface a clear error if
any required value is absent).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9472e6c3-53ee-4113-be99-2d1b78e43b60
⛔ Files ignored due to path filters (1)
yarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (5)
package.jsonsrc/cliAgent.tssrc/routes/routes.tssrc/routes/swagger.jsonsrc/utils/agent.ts
Signed-off-by: Krishna Waske <krishna.waske@ayanworks.com>
Signed-off-by: Krishna Waske <krishna.waske@ayanworks.com>
Signed-off-by: Krishna Waske <krishna.waske@ayanworks.com>
|
Let’s update the README to include the prerequisite instructions for these env variables. |
Signed-off-by: Krishna Waske <krishna.waske@ayanworks.com>
|
Actually we haven't added any new variables. They were just missing from a place, where they were expected. |


What:
Summary by CodeRabbit
New Features
Chores