Skip to content
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
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 Apr 24, 2024
ad5cb5c
feat: Add AccountSigner struct for managing public/private key pairs …
S0c5 Apr 24, 2024
60e6635
refactor: Update type definition in account_generation.rs and key_pai…
S0c5 Apr 25, 2024
f946cd5
fix: fix type Id for vault os
S0c5 Apr 25, 2024
4c590fb
feat: pjs vault
S0c5 Apr 26, 2024
dcf11d6
chore: update cargo.toml
S0c5 Apr 26, 2024
a771f4b
Merge branch 'main' into feat/libwallet-with-vault-exportin-signer
S0c5 Apr 26, 2024
d7264e2
feat(account): Add methods to handle default accounts and update meth…
S0c5 Apr 26, 2024
45566f1
merge
S0c5 Apr 26, 2024
f86167c
add pjs vault
S0c5 Apr 26, 2024
9e205ea
refactor: Refactor code structure and improve async functions in Pjs …
S0c5 Apr 28, 2024
273efa0
down grade version
manuelcastrobarinas Apr 28, 2024
6a93643
refactor: Update dependencies and code structure in libwallet and pjs…
S0c5 Apr 30, 2024
f749db8
feat(key_pair): add method as_bytes to Signature trait
S0c5 Apr 30, 2024
0932335
style: Update key_pair.rs with improved error message for try_into co…
S0c5 Apr 30, 2024
8350abe
refactor: Rename variable from `pub_key` to `address` in Pjs impl Acc…
S0c5 Apr 30, 2024
00770b4
style: Fix default-features typo in pjs dependency definition in Carg…
S0c5 Apr 30, 2024
019ae8e
style: Update default-features value for pjs dependency in Cargo.toml
S0c5 Apr 30, 2024
acc0c22
style: Update attribute syntax for conditional wasm_bindgen feature u…
S0c5 Apr 30, 2024
a719e4c
feat: Add logging to PjsExtension for debugging purposes
S0c5 Apr 30, 2024
2938928
feat: Add logging statement to display data before signing
S0c5 Apr 30, 2024
887ca83
feat: Add logging for signature in PjsExtension
S0c5 Apr 30, 2024
e5d8409
fix: Fix accessing the correct variable in get! macro to retrieve the…
S0c5 Apr 30, 2024
d693e48
feat(libwallet, pjs-rs): Add logging of signatures in the code using …
S0c5 Apr 30, 2024
5b91696
style: Improve code readability by refactoring signature extraction l…
S0c5 Apr 30, 2024
af56efa
feat: Add logging for final signature in PjsExtension
S0c5 Apr 30, 2024
ae8e20e
fix: Add logging for s and b values in PjsExtension
S0c5 Apr 30, 2024
d0fd3d1
fix: Update default value for b to 1
S0c5 Apr 30, 2024
fb3f59c
fix: Fix parsing issue in PjsExtension impl and add logging informati…
S0c5 Apr 30, 2024
6728810
refactor: Remove commented-out code and unnecessary closure in PjsExt…
S0c5 Apr 30, 2024
3256b6a
fix: Fix syntax error in from_hex function in PjsExtension
S0c5 Apr 30, 2024
a55bc3b
feat: Log message data before signing and after getting the signature
S0c5 May 1, 2024
85201dd
fix: Use hex::encode instead of custom to_hex implementation in sign …
S0c5 May 1, 2024
8aaf83b
fix: Update sign method to prepend '0x' to the encoded payload before…
S0c5 May 1, 2024
2dd7810
fix: Update the type field value to "payload" and remove the prefix "…
S0c5 May 1, 2024
049b4ef
fix: Update the type field value to "bytes" instead of "payload" in P…
S0c5 May 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions libwallet/src/vault/pjs.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@

use pjs::{Error, PjsExtension, Account as PjsAccount};
use crate::{any::AnySignature, Account, Signature, Signer, Vault};
use core::{fmt::Display, marker::PhantomData};

extern crate alloc;
use crate::{any::AnySignature, Account, Signer, Vault};
use pjs::{Account as PjsAccount, Error, PjsExtension};
use alloc::vec::Vec;
#[derive(Clone)]
struct Pjs {
pub struct Pjs {
inner: PjsExtension,
}

impl Pjs {
pub async fn connect(name: &str) -> Result<Self, Error> {
Pjs {
Ok(Pjs {
inner: PjsExtension::connect(name).await?,
}
})
}

pub async fn list_accounts(&mut self) -> Result<Vec<PjsAccount>, Error> {
self.inner.fetch_accounts().await?;
self.inner.accounts()
Ok(self.inner.accounts())
}

pub fn select_account(&mut self, idx: u8) {
Expand All @@ -29,7 +28,8 @@ impl Signer for Pjs {
type Signature = AnySignature;

async fn sign_msg(&self, msg: impl AsRef<[u8]>) -> Result<Self::Signature, ()> {
self.inner.sign(msg).await.map_err(|_| Err(()))
let sig = self.inner.sign(msg.as_ref()).await.map_err(|_| ())?;
Ok(AnySignature::from(sig))
}

async fn verify(&self, _: impl AsRef<[u8]>, _: impl AsRef<[u8]>) -> bool {
Expand All @@ -39,10 +39,15 @@ impl Signer for Pjs {

impl Account for Pjs {
fn public(&self) -> impl crate::Public {
self.inner
let mut key = [0u8; 32];

let pub_key = self.inner
.get_selected()
.expect("an account must be defined")
.address()
.address();

key.copy_from_slice(pub_key.as_bytes());
key
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The returned hex string should be decoded, otherwise I don't think you are getting the desired data.

}
}

Expand All @@ -57,14 +62,14 @@ impl core::fmt::Display for Pjs {

impl Vault for Pjs {
type Id = u8;
type Credentials = String;
type Credentials = ();
type Account = Pjs;
type Error = Error;

async fn unlock(
&mut self,
Copy link
Member

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?

account: Self::Id,
cred: impl Into<Self::Credentials>,
_: impl Into<Self::Credentials>,
) -> Result<Self::Account, Self::Error> {
let mut pjs_signer = self.clone();
pjs_signer.select_account(account);
Expand Down
2 changes: 1 addition & 1 deletion pjs-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ features = [
]

[lib]
crate-type = ["cdylib"]
crate-type = ["cdylib", "lib"]
3 changes: 3 additions & 0 deletions pjs-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ macro_rules! get {
const NULL: JsValue = JsValue::null();

#[wasm_bindgen]
#[derive(Clone)]
pub struct PjsExtension {
pjs: JsValue,
accounts: Vec<Account>,
Expand Down Expand Up @@ -183,10 +184,12 @@ impl Account {
pub fn name(&self) -> String {
self.name.clone()
}

#[wasm_bindgen(getter)]
pub fn address(&self) -> String {
self.address.clone()
}

#[wasm_bindgen(getter)]
pub fn network(&self) -> Network {
self.net
Expand Down
Loading