Skip to content

Conversation

@bitbeckers
Copy link
Collaborator

  • Safe signature support for User entities
  • File upload endpoint
  • Test suites
  • Attestation fetching and resolver updates

pheuberger and others added 30 commits December 4, 2024 14:42
The user controller had a lot of repetetive code. This patch dry's this
code up quite a bit and makes the high-level intent more apparent.
Without this patch the user controller only allows updating the user
data directly via EOA. Calling it with a multisig like the Safe would
fail as the smart wallet isn't able to create a signature.

In this instance the API needs to track signature requests, so that the
user data can be written once the signature threshold is met.

The need to track these signature requests arises from the fact that you
cannot delete signatures from the Safe once they were "used". They will
stick around forever and it is up to us to track which signature
corresponds to which change, if it is discarded or implemented, etc.

The patch introduces a new folder: src/lib/users. The reason is that the
project is currently structured by implementation details, so I wanted
to keep the user controller in with the rest of the controllers but have
a place to store this business logic.
Without this patch we can only write signature requests, but not fetch
them.

This patch implements the required resolvers and also exposes any
signature requests that are registered for a particular user.
Without this patch the user has no way of canceling signature requests.

This patch introduces a status field. It has 3 possible values: PENDING,
CANCELED and EXECUTED.
The controller allows canceling the signature request only when it's in
status PENDING and the caller authenticates as one of the owners of the
Safe.
Without this patch we're missing a way for the API to execute the
signature requests and commit the data to record if the signature
threshold is met.

This patch adds the request POST /signature-requests/process which reads
all **pending** signature requests from the data DB, checks if the
confirmations meet the signature threshold and if so writes the attached
username and avatar changes to the users table.

To stay within the rate limit of 5 requests per second required by the
Safe API I implemented a rate limited queue and worker that process them
concurrently.

The request doesn't require authentication, so it could be invoked by a
CRON job, as well as the user when they log in or specifically request
an update.
This directive didn't have any effect.
In case somebody is wondering why we have duplicate type definitions in
our code base.
Without this patch adding a new signature request to the database
doesn't invalidate the cache right away. This needs to be triggered
manually.
As the class is the only export in that module, it's better to have it
as a default export.
The file wasn't prettier formatted yet and making a change to it would
result in a huge diff with 99% styling changes.
Without this patch we rely on users making a POST request to
/v1/signature-requests/process to kick off signature request processing.

Since it's not going to be high load, we want to have a regular cron job
that relieves users of that duty and will run signature request
validations on autopilot.

This way users just have to wait a bit to find their signature requests
validated once the Safe message has reached the required threshold.

Also made a small change to the log statement in the processor to make
it more clear that it's running signature requests, now that a console
log will show up every 30 seconds.
Run cron job to start Safe signature requests queue processing
Fixes the test file and controller to have passing tests and better
error handling for the metadata upload functionality of the
MetadataController
Restores the metadata validation endpoint testing. Additionally the full
metadata controller is using try catches and we updated the response
types. The response types have been made more simple and flexible, for
one to support the cases of validation where the processing can be
successful but the data is invalid. Lastly, responses where data is set
as null were cleaned so simply not return data.
Update all controllers to use the updated types structure. Rebuild the
updated API routes and Swagger.
Fixes the allowlist upload unit test flows. The current test suite was
breaking on missing imports and the tested flow and types were updated
to the latest implementation
wraps business logic in try-catches and updates response types where
needed
Adds vitest coverage reporting and CI action
Fixes the test file and controller to have passing tests and better
error handling for the metadata upload functionality of the
MetadataController
Restores the metadata validation endpoint testing. Additionally the full
metadata controller is using try catches and we updated the response
types. The response types have been made more simple and flexible, for
one to support the cases of validation where the processing can be
successful but the data is invalid. Lastly, responses where data is set
as null were cleaned so simply not return data.
Update all controllers to use the updated types structure. Rebuild the
updated API routes and Swagger.
Adds vitest coverage reporting and CI action
updates gha test script to use env var
Adds an upload endpoint to our API. This has been implemented using
multer as a middleware for file validations and restrictions on file
size. Basic happy/unhappy flow tests pass.
Increases coverage threshold based on updated test suite
Updates the types used in lib/users to match updated API types
Generated updated Swagger
Add validations on file type and size
bitbeckers and others added 19 commits January 3, 2025 03:44
To gradually clean up the repo, we agreed on restructuring helpers from
utils to more cleanly scoped libs. Additionally, added some tests
- Introduced a new script for batch minting blueprints from a CSV file
- Added a new CSV file to define example blueprint data.
- Updated `package.json` to include new dependencies: `@inquirer/prompts` and `csv-parse`.
- Modified `BlueprintController` to make the `cardImage` field optional in validation.
…-script

feat: blueprint batch minting form
- Added `hypercerts` field to the Blueprint type in the GraphQL schema.
- Updated BlueprintResolver to include a new FieldResolver for fetching hypercerts based on `hypercert_ids`.
- Modified the Blueprint type definition to include the new `hypercerts` field
- Modified the blueprints type definition to include internal `hypercert_ids` field for data handling.
Updates the UploadController to use custom errors. The custom errors are
defined in a uploads lib directory and handles all cases found in the
controller.
Updates the UploadController typedoc example to document different
upload tools and the expected responses
Adds typeguards and updates the parsing of failed and successful file
uploads for readability
Updates the test cases to test on the expanded upload result types.
Additionally typedoc documentation was updated to document the error and
the controller more accurately.
At 10 osme files around 9.7 failed. This is the ducttape solution until
we've resolved the issues
…percerts-relation

Feat/expose blueprints hypercerts relation
Updates Attestation resolver, input and args to support fetching
attestations based on schema data. This enables queries based on schema
uids
updates generated graphql schema
Updates the where clause and field name to use eas_schema which is more
intuitive
…_with_schemas

Attestation resolver with schemas
Updates test suite to work with file limits. Update testing to cover
more edges cases. Testfiles were renamed to match the file they were
testing
- Introduced separate arrays for testnet and production chains for better organization, and because .testnet property is not always defined in viem.
- Updated chain selection logic to determine if the selected chain is a testnet based on the new structure.
@bitbeckers bitbeckers added the enhancement New feature or request label Jan 24, 2025
@bitbeckers bitbeckers self-assigned this Jan 24, 2025
@github-actions
Copy link

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 20.13% (🎯 20%) 1044 / 5185
🟢 Statements 20.13% (🎯 20%) 1044 / 5185
🟢 Functions 60.43% (🎯 60%) 55 / 91
🟢 Branches 64.85% (🎯 64%) 179 / 276
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/index.ts 0% 0% 0% 0% 1-61
src/client/supabase.ts 0% 0% 0% 0% 1-429
src/commands/CommandFactory.ts 0% 0% 0% 0% 1-30
src/commands/SafeApiCommand.ts 0% 0% 0% 0% 1-26
src/commands/UserUpsertCommand.ts 0% 0% 0% 0% 1-77
src/controllers/AllowListController.ts 90% 90% 100% 90% 107-114
src/controllers/BlueprintController.ts 0% 0% 0% 0% 1-394
src/controllers/HyperboardController.ts 0% 0% 0% 0% 1-966
src/controllers/MarketplaceController.ts 0% 0% 0% 0% 1-492
src/controllers/MetadataController.ts 41.37% 72.72% 50% 41.37% 61-73, 116-180, 214-228, 237-244, 261-308
src/controllers/SignatureRequestController.ts 0% 0% 0% 0% 1-130
src/controllers/UploadController.ts 98.5% 93.1% 100% 98.5% 239, 243
src/controllers/UserController.ts 0% 0% 0% 0% 1-102
src/cron/SignatureRequestProcessing.ts 0% 0% 0% 0% 1-31
src/lib/allowlists/isParsableToMerkleTree.ts 100% 100% 100% 100%
src/lib/allowlists/parseMerkleTree.ts 100% 100% 100% 100%
src/lib/safe-signature-verification/SafeSignatureVerifier.ts 74.28% 80% 75% 74.28% 15-16, 39-46
src/lib/safe-signature-verification/UserUpsertSignatureVerifier.ts 100% 100% 100% 100%
src/lib/uploads/errors.ts 100% 100% 100% 100%
src/lib/users/EOAUpsertStrategy.ts 0% 0% 0% 0% 1-74
src/lib/users/MultisigUpsertStrategy.ts 0% 0% 0% 0% 1-81
src/lib/users/UserUpsertStrategy.ts 0% 0% 0% 0% 1-23
src/lib/users/errors.ts 0% 100% 100% 0% 3-11
src/lib/users/schemas.ts 0% 0% 0% 0% 1-41
src/middleware/upload.ts 85.1% 100% 50% 85.1% 60-66
src/services/SafeApiQueue.ts 78.37% 86.36% 90.9% 78.37% 21-28, 52, 87-93
src/services/SignatureRequestProcessor.ts 0% 0% 0% 0% 1-55
src/services/SupabaseCachingService.ts 0% 0% 0% 0% 1-252
src/services/SupabaseDataService.ts 0% 0% 0% 0% 1-766
src/utils/getRpcUrl.ts 76.63% 43.18% 100% 76.63% 18, 20, 22, 24, 26, 30, 39, 41, 43, 45, 47, 60, 62, 64, 66, 68, 72, 81, 83, 85, 87, 89, 93, 109, 112
src/utils/signatures.ts 0% 100% 100% 0% 3-5
src/utils/validateRemoteAllowList.ts 5.4% 100% 0% 5.4% 6-43
src/utils/verifyAuthSignedData.ts 100% 100% 100% 100%
Generated in workflow #29 for commit 8241c33 by the Vitest Coverage Report Action

@bitbeckers bitbeckers merged commit 8e0988f into main Jan 24, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Development

Successfully merging this pull request may close these issues.

5 participants