-
Notifications
You must be signed in to change notification settings - Fork 5
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: pjs vault #48
Open
S0c5
wants to merge
36
commits into
main
Choose a base branch
from
feat/pjs-vault
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
feat: pjs vault #48
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
07cf095
feat: Vault exporting signer instead of root account
S0c5 ad5cb5c
feat: Add AccountSigner struct for managing public/private key pairs …
S0c5 60e6635
refactor: Update type definition in account_generation.rs and key_pai…
S0c5 f946cd5
fix: fix type Id for vault os
S0c5 4c590fb
feat: pjs vault
S0c5 dcf11d6
chore: update cargo.toml
S0c5 a771f4b
Merge branch 'main' into feat/libwallet-with-vault-exportin-signer
S0c5 d7264e2
feat(account): Add methods to handle default accounts and update meth…
S0c5 45566f1
merge
S0c5 f86167c
add pjs vault
S0c5 9e205ea
refactor: Refactor code structure and improve async functions in Pjs …
S0c5 273efa0
down grade version
manuelcastrobarinas 6a93643
refactor: Update dependencies and code structure in libwallet and pjs…
S0c5 f749db8
feat(key_pair): add method as_bytes to Signature trait
S0c5 0932335
style: Update key_pair.rs with improved error message for try_into co…
S0c5 8350abe
refactor: Rename variable from `pub_key` to `address` in Pjs impl Acc…
S0c5 00770b4
style: Fix default-features typo in pjs dependency definition in Carg…
S0c5 019ae8e
style: Update default-features value for pjs dependency in Cargo.toml
S0c5 acc0c22
style: Update attribute syntax for conditional wasm_bindgen feature u…
S0c5 a719e4c
feat: Add logging to PjsExtension for debugging purposes
S0c5 2938928
feat: Add logging statement to display data before signing
S0c5 887ca83
feat: Add logging for signature in PjsExtension
S0c5 e5d8409
fix: Fix accessing the correct variable in get! macro to retrieve the…
S0c5 d693e48
feat(libwallet, pjs-rs): Add logging of signatures in the code using …
S0c5 5b91696
style: Improve code readability by refactoring signature extraction l…
S0c5 af56efa
feat: Add logging for final signature in PjsExtension
S0c5 ae8e20e
fix: Add logging for s and b values in PjsExtension
S0c5 d0fd3d1
fix: Update default value for b to 1
S0c5 fb3f59c
fix: Fix parsing issue in PjsExtension impl and add logging informati…
S0c5 6728810
refactor: Remove commented-out code and unnecessary closure in PjsExt…
S0c5 3256b6a
fix: Fix syntax error in from_hex function in PjsExtension
S0c5 a55bc3b
feat: Log message data before signing and after getting the signature
S0c5 85201dd
fix: Use hex::encode instead of custom to_hex implementation in sign …
S0c5 8aaf83b
fix: Update sign method to prepend '0x' to the encoded payload before…
S0c5 2dd7810
fix: Update the type field value to "payload" and remove the prefix "…
S0c5 049b4ef
fix: Update the type field value to "bytes" instead of "payload" in P…
S0c5 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 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
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,87 @@ | ||
extern crate alloc; | ||
use crate::{any::AnySignature, Account, Signer, Vault}; | ||
use alloc::vec::Vec; | ||
use pjs::{Account as PjsAccount, Error, PjsExtension}; | ||
use log; | ||
use hex; | ||
use sp_core::crypto::{AccountId32, Ss58Codec}; | ||
|
||
#[derive(Clone)] | ||
pub struct Pjs { | ||
inner: PjsExtension, | ||
} | ||
|
||
impl Pjs { | ||
pub async fn connect(name: &str) -> Result<Self, Error> { | ||
Ok(Pjs { | ||
inner: PjsExtension::connect(name).await?, | ||
}) | ||
} | ||
|
||
pub async fn list_accounts(&mut self) -> Result<Vec<PjsAccount>, Error> { | ||
self.inner.fetch_accounts().await?; | ||
Ok(self.inner.accounts()) | ||
} | ||
|
||
pub fn select_account(&mut self, idx: u8) { | ||
self.inner.select_account(idx) | ||
} | ||
} | ||
|
||
impl Signer for Pjs { | ||
type Signature = AnySignature; | ||
|
||
async fn sign_msg(&self, msg: impl AsRef<[u8]>) -> Result<Self::Signature, ()> { | ||
log::info!("signing: {}", hex::encode(&msg.as_ref())); | ||
let sig = self.inner.sign(msg.as_ref()).await.map_err(|_| ())?; | ||
log::info!("signature {:?}", hex::encode(&sig)); | ||
Ok(AnySignature::from(sig)) | ||
} | ||
|
||
async fn verify(&self, _: impl AsRef<[u8]>, _: impl AsRef<[u8]>) -> bool { | ||
unimplemented!() | ||
} | ||
} | ||
|
||
impl Account for Pjs { | ||
fn public(&self) -> impl crate::Public { | ||
let mut key = [0u8; 32]; | ||
|
||
let address = self | ||
.inner | ||
.get_selected() | ||
.expect("an account must be defined") | ||
.address(); | ||
|
||
let address = <AccountId32 as Ss58Codec>::from_string(&address) | ||
.expect("it must be a valid ss58 address"); | ||
key.copy_from_slice(address.as_ref()); | ||
key | ||
} | ||
} | ||
|
||
impl core::fmt::Display for Pjs { | ||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { | ||
for byte in self.public().as_ref() { | ||
write!(f, "{:02x}", byte)?; | ||
} | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl Vault for Pjs { | ||
type Id = u8; | ||
type Credentials = (); | ||
type Account = Pjs; | ||
type Error = Error; | ||
|
||
async fn unlock( | ||
&mut self, | ||
account: Self::Id, | ||
_: impl Into<Self::Credentials>, | ||
) -> Result<Self::Account, Self::Error> { | ||
let mut pjs_signer = self.clone(); | ||
pjs_signer.select_account(account); | ||
Ok(pjs_signer) | ||
} | ||
} |
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.
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.
Could we
.connect
on unlock?