-
Notifications
You must be signed in to change notification settings - Fork 37
fix: get signing key by pub key user check #1950
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
Open
mjuchli-da
wants to merge
6
commits into
main
Choose a base branch
from
mjuchli/signing-store-sql-tests
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
6 commits
Select commit
Hold shift + click to select a range
4e56fe2
fix: get signing key by pub key user check
mjuchli-da 56102a8
make internal driver auth aware
mjuchli-da 6a52571
revert
mjuchli-da d804e8f
fix tests
mjuchli-da 57d5906
Merge remote-tracking branch 'origin/main' into mjuchli/signing-store…
mjuchli-da 2c142aa
fix
mjuchli-da 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
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,107 @@ | ||
| // Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { describe, expect, test, beforeEach } from 'vitest' | ||
| import { AuthContext } from '@canton-network/core-wallet-auth' | ||
| import { Kysely } from 'kysely' | ||
| import { pino } from 'pino' | ||
| import { migrator } from './migrator.js' | ||
| import { DB } from './schema.js' | ||
| import { connection, StoreSql } from './store-sql.js' | ||
|
|
||
| const userA: AuthContext = { | ||
| userId: 'user-a', | ||
| accessToken: 'token-a', | ||
| } | ||
|
|
||
| const userB: AuthContext = { | ||
| userId: 'user-b', | ||
| accessToken: 'token-b', | ||
| } | ||
|
|
||
| describe('StoreSql auth scoping', () => { | ||
| let db: Kysely<DB> | ||
|
|
||
| beforeEach(async () => { | ||
| db = connection({ connection: { type: 'memory' } }) | ||
| const umzug = migrator(db) | ||
| await umzug.up() | ||
| }) | ||
|
|
||
| test('returns empty for getSigningKeyByPublicKey owned by another user', async () => { | ||
| const storeWithoutAuth = new StoreSql(db, pino({ level: 'silent' })) | ||
| await storeWithoutAuth.setSigningKey(userB.userId, { | ||
| id: 'key-b', | ||
| name: 'key-b', | ||
| publicKey: 'user-b-public-key', | ||
| privateKey: 'private-key-b', | ||
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| }) | ||
|
|
||
| const scopedStore = storeWithoutAuth.withAuthContext(userA) | ||
| const key = | ||
| await scopedStore.getSigningKeyByPublicKey('user-b-public-key') | ||
|
|
||
| expect(key).toBeUndefined() | ||
| }) | ||
|
|
||
| test('scopes getSigningKeyByPublicKey to authContext user', async () => { | ||
| const storeWithoutAuth = new StoreSql(db, pino({ level: 'silent' })) | ||
| await storeWithoutAuth.setSigningKey(userA.userId, { | ||
| id: 'key-a', | ||
| name: 'key-a', | ||
| publicKey: 'shared-public-key', | ||
| privateKey: 'private-key-a', | ||
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| }) | ||
| await storeWithoutAuth.setSigningKey(userB.userId, { | ||
| id: 'key-b', | ||
| name: 'key-b', | ||
| publicKey: 'shared-public-key', | ||
| privateKey: 'private-key-b', | ||
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| }) | ||
|
|
||
| const scopedStore = storeWithoutAuth.withAuthContext(userA) | ||
| const key = | ||
| await scopedStore.getSigningKeyByPublicKey('shared-public-key') | ||
|
|
||
| expect(key?.id).toBe('key-a') | ||
| expect(key?.privateKey).toBe('private-key-a') | ||
| }) | ||
|
|
||
| test('scopes listSigningTransactionsByTxIdsAndPublicKeys to authContext user', async () => { | ||
| const storeWithoutAuth = new StoreSql(db, pino({ level: 'silent' })) | ||
| const now = new Date() | ||
|
|
||
| await storeWithoutAuth.setSigningTransaction(userA.userId, { | ||
| id: 'tx-a', | ||
| hash: 'hash-a', | ||
| publicKey: 'public-key-a', | ||
| status: 'signed', | ||
| createdAt: now, | ||
| updatedAt: now, | ||
| }) | ||
| await storeWithoutAuth.setSigningTransaction(userB.userId, { | ||
| id: 'tx-b', | ||
| hash: 'hash-b', | ||
| publicKey: 'public-key-b', | ||
| status: 'signed', | ||
| createdAt: now, | ||
| updatedAt: now, | ||
| }) | ||
|
|
||
| const scopedStore = storeWithoutAuth.withAuthContext(userA) | ||
| const transactions = | ||
| await scopedStore.listSigningTransactionsByTxIdsAndPublicKeys( | ||
| ['tx-a', 'tx-b'], | ||
| [] | ||
| ) | ||
|
|
||
| expect(transactions).toHaveLength(1) | ||
| expect(transactions[0]?.id).toBe('tx-a') | ||
| }) | ||
| }) |
This file contains hidden or 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 hidden or 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.
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.
userId used to be the email as far as i can see.
please double-check @pawelstepien-da
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.
Yes we definitely used value from email here. In BD signing driver controller the argument was called userId, it was typed as
userId: AuthContext['userId'], but it was actually supposed to be email, so it was quite confusing and is so much clearer now.