-
Notifications
You must be signed in to change notification settings - Fork 9
feat: implement set_client_data() [WPB-10919] #757
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0695105
chore: add consumer_data table to SQLite schema
SimonThormeyer c0331d1
chore: add consumer_data indexedDB store
SimonThormeyer 23fafcc
chore: implement count() and find_one() in unique entity
SimonThormeyer 7a00966
chore: add consumer data struct to keystore
SimonThormeyer 7747ff0
feat: implement set_data() and get_data() on context [WPB-10919]
SimonThormeyer bdd00c7
chore: expose set_data() and get_data() in wasm bindings
SimonThormeyer e56c0c0
chore: expose set_data() and get_data() in uniffi bindings
SimonThormeyer 8ac1aff
chore: add test for set_data()
SimonThormeyer 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /// Consumers of this library can use this to specify data to be persisted at the end of | ||
| /// a transaction. | ||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| #[cfg_attr( | ||
| any(target_family = "wasm", feature = "serde"), | ||
| derive(serde::Serialize, serde::Deserialize) | ||
| )] | ||
| pub struct ConsumerData { | ||
| pub content: Vec<u8>, | ||
| } | ||
|
|
||
| impl From<Vec<u8>> for ConsumerData { | ||
| fn from(content: Vec<u8>) -> Self { | ||
| Self { content } | ||
| } | ||
| } | ||
|
|
||
| impl From<ConsumerData> for Vec<u8> { | ||
| fn from(consumer_data: ConsumerData) -> Self { | ||
| consumer_data.content | ||
| } | ||
| } |
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,49 @@ | ||
| use crate::{ | ||
| connection::KeystoreDatabaseConnection, | ||
| entities::{ConsumerData, Entity, EntityBase, EntityFindParams, StringEntityId, UniqueEntity}, | ||
| CryptoKeystoreResult, MissingKeyErrorKind, | ||
| }; | ||
|
|
||
| impl Entity for ConsumerData { | ||
| fn id_raw(&self) -> &[u8] { | ||
| &[Self::ID as u8] | ||
| } | ||
| } | ||
|
|
||
| #[async_trait::async_trait] | ||
| impl UniqueEntity for ConsumerData { | ||
| fn new(content: Vec<u8>) -> Self { | ||
| Self { content } | ||
| } | ||
|
|
||
| fn content(&self) -> &[u8] { | ||
| &self.content | ||
| } | ||
| } | ||
|
|
||
| #[async_trait::async_trait] | ||
| impl EntityBase for ConsumerData { | ||
| type ConnectionType = KeystoreDatabaseConnection; | ||
| type AutoGeneratedFields = (); | ||
| const COLLECTION_NAME: &'static str = "consumer_data"; | ||
|
|
||
| fn to_missing_key_err_kind() -> MissingKeyErrorKind { | ||
| MissingKeyErrorKind::ConsumerData | ||
| } | ||
|
|
||
| fn to_transaction_entity(self) -> crate::transaction::dynamic_dispatch::Entity { | ||
| crate::transaction::dynamic_dispatch::Entity::ConsumerData(self) | ||
| } | ||
|
|
||
| async fn find_all(conn: &mut Self::ConnectionType, params: EntityFindParams) -> CryptoKeystoreResult<Vec<Self>> { | ||
| <Self as UniqueEntity>::find_all(conn, params).await | ||
| } | ||
|
|
||
| async fn find_one(conn: &mut Self::ConnectionType, _id: &StringEntityId) -> CryptoKeystoreResult<Option<Self>> { | ||
| <Self as UniqueEntity>::find_one(conn).await | ||
| } | ||
|
|
||
| async fn count(conn: &mut Self::ConnectionType) -> CryptoKeystoreResult<usize> { | ||
| <Self as UniqueEntity>::count(conn).await | ||
| } | ||
| } |
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,56 @@ | ||
| use crate::connection::DatabaseConnection; | ||
| use crate::entities::Entity; | ||
| use crate::{ | ||
| connection::KeystoreDatabaseConnection, | ||
| entities::{ConsumerData, EntityBase, EntityFindParams, StringEntityId, UniqueEntity}, | ||
| CryptoKeystoreResult, MissingKeyErrorKind, | ||
| }; | ||
|
|
||
| #[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))] | ||
| #[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)] | ||
| impl EntityBase for ConsumerData { | ||
| type ConnectionType = KeystoreDatabaseConnection; | ||
| type AutoGeneratedFields = (); | ||
| const COLLECTION_NAME: &'static str = "consumer_data"; | ||
|
|
||
| fn to_missing_key_err_kind() -> MissingKeyErrorKind { | ||
| MissingKeyErrorKind::ConsumerData | ||
| } | ||
|
|
||
| fn to_transaction_entity(self) -> crate::transaction::dynamic_dispatch::Entity { | ||
| crate::transaction::dynamic_dispatch::Entity::ConsumerData(self) | ||
| } | ||
|
|
||
| async fn find_all(conn: &mut Self::ConnectionType, params: EntityFindParams) -> CryptoKeystoreResult<Vec<Self>> { | ||
| <Self as UniqueEntity>::find_all(conn, params).await | ||
| } | ||
|
|
||
| async fn find_one(conn: &mut Self::ConnectionType, _id: &StringEntityId) -> CryptoKeystoreResult<Option<Self>> { | ||
| <Self as UniqueEntity>::find_one(conn).await | ||
| } | ||
|
|
||
| async fn count(conn: &mut Self::ConnectionType) -> CryptoKeystoreResult<usize> { | ||
| <Self as UniqueEntity>::count(conn).await | ||
| } | ||
| } | ||
|
|
||
| impl Entity for ConsumerData { | ||
| fn id_raw(&self) -> &[u8] { | ||
| &Self::ID | ||
| } | ||
|
|
||
| fn encrypt(&mut self, cipher: &aes_gcm::Aes256Gcm) -> CryptoKeystoreResult<()> { | ||
| self.content = self.encrypt_data(cipher, self.content.as_slice())?; | ||
| Self::ConnectionType::check_buffer_size(self.content.len())?; | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn decrypt(&mut self, cipher: &aes_gcm::Aes256Gcm) -> CryptoKeystoreResult<()> { | ||
| self.content = self.decrypt_data(cipher, self.content.as_slice())?; | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| #[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))] | ||
| #[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)] | ||
| impl UniqueEntity for ConsumerData {} |
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
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.
I don't know how these identifiers are used. Are these identifiers persisted at all? Can anything go wrong by moving
identifier_16fromProteusPrekeytoConsumerData?Uh oh!
There was an error while loading. Please reload this page.
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.
These identifiers are merely used to hold the data from the in-memory cache before it is committed. So it doesn't matter what their name is/was at all.
If we can create them internally in the macro instead of passing them in, I would like doing so!
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.
Creating idents like this within a macro is tricky but not impossible.
In the future, it will be easier: combine the
${index()}metafunction with thepaste!macro and we should be able to generate all these idents automatically.For now,
${index()}is still not stable, so you have to use recursive macro tricks to build up a unary number for each index and then count how many symbols appear in that number. This approach is complicated and opaque enough I'd recommend not reworking the existing macro until${index()}stabilizes.