-
Notifications
You must be signed in to change notification settings - Fork 89
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
feat(backend): unique keys per wallet address #2863
Open
sabineschaller
wants to merge
24
commits into
main
Choose a base branch
from
s2-unique-key-upload
base: main
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
24 commits
Select commit
Hold shift + click to select a range
c0e4574
feat(backend): make keys unique
sabineschaller 8378b0b
fix: only make keys unique per wallet address
sabineschaller 705bf44
fix(frontend): It is ambiguous on what scale is the withdrawal and de…
Emanuel-Palestino ba203bc
chore: sync docs and readmes (#2830)
JoblersTune a5f953a
chore(deps): update dependency @apollo/client to ^3.11.2 (#2822)
renovate[bot] 612f671
feat(frontend): ux improvements to liquidity dialog component (#2839)
Emanuel-Palestino 7ef4d44
feat(docker): switch to alpine3.19 (#2842)
golobitch 60a9148
fix(auth): interact redirect (#2832)
sabineschaller c3671dd
feat(interaction): return grantId (#2843)
golobitch d2ef6b8
feat(outgoing-payment): add grantId to admin api (#2841)
golobitch 8f3c147
feat(auth): soft delete access tokens and grant accesses (#2837)
njlie 3dbd870
feat(auth): set session expiry based on interaction expiry env (#2851)
njlie aea3361
feat(localenv): span metrics generation (#2849)
BlairCurrey ef8f2da
chore(deps): update dependency @types/node to ^20.14.15 (#2838)
renovate[bot] 2bf62f3
chore(deps): update dependency @apollo/client to ^3.11.4 (#2845)
renovate[bot] af91a0d
feat(2737): add fees as metric for outgoing payment. (#2831)
koekiebox 31bf57c
refactor(dependencies): axios to 1.7.4 (#2861)
golobitch f01fd23
chore: add tests and better error handling
sabineschaller 6b43cef
chore: formatting
sabineschaller fdaf29b
Merge branch 'main' into s2-unique-key-upload
sabineschaller 5e81569
fix: build
sabineschaller 0653ff9
fix: add camelcase quotes and make `up` async
sabineschaller 56aba1e
chore: keep latest version of key
sabineschaller 83664de
fix: formatting
sabineschaller 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
31 changes: 31 additions & 0 deletions
31
packages/backend/migrations/20240731084359_add_unique_constraint_to_kid.js
This file contains 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,31 @@ | ||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.up = async function (knex) { | ||
// delete any existing duplicates per wallet address, keep latest version | ||
await knex.raw(` | ||
DELETE FROM "walletAddressKeys" | ||
WHERE ctid NOT IN ( | ||
SELECT ctid FROM ( | ||
SELECT "walletAddressId", kid, x, MAX("createdAt") AS latest_added, MAX(ctid) AS ctid | ||
FROM "walletAddressKeys" | ||
GROUP BY "walletAddressId", kid, x | ||
) subquery | ||
); | ||
`) | ||
|
||
return knex.schema.alterTable('walletAddressKeys', (table) => { | ||
table.unique(['walletAddressId', 'kid', 'x']) | ||
}) | ||
} | ||
|
||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.down = function (knex) { | ||
return knex.schema.alterTable('walletAddressKeys', (table) => { | ||
table.dropUnique(['walletAddressId', 'kid', 'x']) | ||
}) | ||
} |
This file contains 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 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
21 changes: 21 additions & 0 deletions
21
packages/backend/src/open_payments/wallet_address/key/errors.ts
This file contains 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,21 @@ | ||
import { GraphQLErrorCode } from '../../../graphql/errors' | ||
|
||
export enum WalletAddressKeyError { | ||
DuplicateKey = 'DuplicateKey' | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types | ||
export const isWalletAddressKeyError = (o: any): o is WalletAddressKeyError => | ||
Object.values(WalletAddressKeyError).includes(o) | ||
|
||
export const errorToCode: { | ||
[key in WalletAddressKeyError]: GraphQLErrorCode | ||
} = { | ||
[WalletAddressKeyError.DuplicateKey]: GraphQLErrorCode.Duplicate | ||
} | ||
|
||
export const errorToMessage: { | ||
[key in WalletAddressKeyError]: string | ||
} = { | ||
[WalletAddressKeyError.DuplicateKey]: 'Key already exists' | ||
} |
This file contains 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 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 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 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
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.
played around with it and it seems to be working. Had to lookup ctid but I guess it probably makes for an easier query than using the uuid.
What's the user experience going to be for the people using the keys being deleted here? I recall the discussion and read the issue but I guess I'm still not quite connecting the dots. For example, is some normal user going to see
invalid signature
or similar from the grant request process and have no idea they need to upload some new key? I guess probably not because they should still have a key right (just not duplicates of it)? I suppose maybe it just fixes the bug in that issue and otherwise people wont be impacted from these duplicates being deleted.I see the error for duplicate writes in gql - that makes sense.
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 users should not have any issues since they still have another copy of the key. But this makes me think I need to check what happens when a user re-adds a key that they have previously revoked. That should be un-revoked and not throw the duplicate error. And I'll also double check that we actually delete the older versions of the key in the migration and keep the most recent.
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.
yeah thats a good point... since we're not deleting these and instead setting
revoked
to true I imagine re-adding the previously revoked key will trigger the unique constraint error. I dont think we can just add therevoked
to the unique constraint because you couldnt revoke it twice.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.
Not tested, but I think a partial index like this would work:
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.
do we really want to unrevoke the key? if we do this, we lose the information that sometime in the past, this key was revoked. I think that we need to have new entry in the database if revoked key was again added
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.
Agreed with @golobitch re: unrevoking (we should just create a new row instead) & @BlairCurrey's partial index suggestion