-
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
32
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.
+209
−11
Open
Changes from all commits
Commits
Show all changes
32 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 7aa3c12
Updated branch
oana-lolea 6a75ee9
Added unrevoke wallet address key query resolver
oana-lolea 78be128
Updated migration and removed unrevoked resolver
oana-lolea d166800
Checkstyle fix
oana-lolea 2b2b34e
Updated walletAddressKey deletion migration, removed unnecessary test…
oana-lolea dd6353c
Use ctid instead of createdAt to determine which rows are deleted
oana-lolea 6161e06
Fixed typo
oana-lolea 4d4d980
Delete the least recent rows that have the same kid and are unrevoked
oana-lolea 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
36 changes: 36 additions & 0 deletions
36
packages/backend/migrations/20241119125038_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,36 @@ | ||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.up = async function (knex) { | ||
return knex | ||
.raw( | ||
// Keep only one active walletAddressKey (the most recent row) | ||
`DELETE FROM "walletAddressKeys" w | ||
WHERE revoked = false | ||
AND ctid NOT IN ( | ||
SELECT MAX(ctid) | ||
FROM "walletAddressKeys" | ||
WHERE revoked = false | ||
AND kid = w.kid | ||
GROUP BY kid, "walletAddressId" | ||
)` | ||
) | ||
.then(() => { | ||
return knex.raw(` | ||
CREATE UNIQUE INDEX "wallet_address_keys_revoked_false_idx" | ||
ON "walletAddressKeys" ("walletAddressId", kid) | ||
WHERE revoked = false; | ||
`) | ||
}) | ||
} | ||
|
||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.down = function (knex) { | ||
return knex.raw( | ||
`DROP INDEX IF EXISTS "wallet_address_keys_revoked_false_idx"` | ||
) | ||
} |
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.
can you double check if this suggestion has the same behaviour? I think it should. Otherwise, looks good 👍