pub struct P47hClient { /* private fields */ }Expand description
WASM-compatible client managing Identity lifecycle and local policy evaluation.
Handles key generation, secure wrapped export (ChaCha20Poly1305), and signing operations. Private keys remain within WASM linear memory unless explicitly exported.
Implementations§
Source§impl P47hClient
impl P47hClient
Sourcepub fn generate_new() -> Result<P47hClient, JsValue>
pub fn generate_new() -> Result<P47hClient, JsValue>
Generates a new cryptographic identity using browser’s secure random source
Sourcepub fn from_secret(secret_bytes: &[u8]) -> Result<P47hClient, JsValue>
pub fn from_secret(secret_bytes: &[u8]) -> Result<P47hClient, JsValue>
Reconstructs identity from previously exported secret bytes
Sourcepub fn export_wrapped_secret(
&self,
session_key: &[u8],
) -> Result<Vec<u8>, JsValue>
pub fn export_wrapped_secret( &self, session_key: &[u8], ) -> Result<Vec<u8>, JsValue>
Exports the private key encrypted with ChaCha20Poly1305
§Security
This method encrypts the private key using ChaCha20Poly1305 AEAD cipher before exporting it. The caller must provide a 32-byte session key.
§Arguments
session_key- A 32-byte key derived from user password or other secure source
§Returns
Returns a byte array containing: [nonce(12 bytes) || ciphertext || tag(16 bytes)]
§Example
// Derive session key from password using PBKDF2 or similar
const sessionKey = await deriveKey(password);
const wrapped = client.export_wrapped_secret(sessionKey);
// Store wrapped securely in IndexedDBSourcepub fn from_wrapped_secret(
wrapped: &[u8],
session_key: &[u8],
) -> Result<P47hClient, JsValue>
pub fn from_wrapped_secret( wrapped: &[u8], session_key: &[u8], ) -> Result<P47hClient, JsValue>
Imports identity from encrypted secret
§Arguments
wrapped- The encrypted secret fromexport_wrapped_secretsession_key- The same 32-byte key used for encryption
§Returns
Returns a new P47hClient instance with the decrypted identity
§Example
const sessionKey = await deriveKey(password);
const client = P47hClient.from_wrapped_secret(wrapped, sessionKey);Sourcepub fn get_public_key(&self) -> Vec<u8> ⓘ
pub fn get_public_key(&self) -> Vec<u8> ⓘ
Returns the raw public key bytes (for advanced use cases)
Sourcepub fn sign_challenge(&self, challenge: &[u8]) -> Vec<u8> ⓘ
pub fn sign_challenge(&self, challenge: &[u8]) -> Vec<u8> ⓘ
Signs a challenge for authentication with the server
Sourcepub fn sign_data(&self, data: &[u8]) -> Vec<u8> ⓘ
pub fn sign_data(&self, data: &[u8]) -> Vec<u8> ⓘ
Signs arbitrary data (for advanced use cases)
Trait Implementations§
Source§impl From<P47hClient> for JsValue
impl From<P47hClient> for JsValue
Source§fn from(value: P47hClient) -> Self
fn from(value: P47hClient) -> Self
Source§impl FromWasmAbi for P47hClient
impl FromWasmAbi for P47hClient
Source§impl IntoWasmAbi for P47hClient
impl IntoWasmAbi for P47hClient
Source§impl LongRefFromWasmAbi for P47hClient
impl LongRefFromWasmAbi for P47hClient
Source§type Abi = WasmPtr<WasmRefCell<P47hClient>>
type Abi = WasmPtr<WasmRefCell<P47hClient>>
RefFromWasmAbi::AbiSource§type Anchor = RcRef<P47hClient>
type Anchor = RcRef<P47hClient>
RefFromWasmAbi::AnchorSource§unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor
unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor
RefFromWasmAbi::ref_from_abiSource§impl OptionFromWasmAbi for P47hClient
impl OptionFromWasmAbi for P47hClient
Source§impl OptionIntoWasmAbi for P47hClient
impl OptionIntoWasmAbi for P47hClient
Source§impl RefFromWasmAbi for P47hClient
impl RefFromWasmAbi for P47hClient
Source§type Abi = WasmPtr<WasmRefCell<P47hClient>>
type Abi = WasmPtr<WasmRefCell<P47hClient>>
Self are recovered from.Source§type Anchor = RcRef<P47hClient>
type Anchor = RcRef<P47hClient>
Self for the duration of the
invocation of the function that has an &Self parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous.Source§impl RefMutFromWasmAbi for P47hClient
impl RefMutFromWasmAbi for P47hClient
Source§type Abi = WasmPtr<WasmRefCell<P47hClient>>
type Abi = WasmPtr<WasmRefCell<P47hClient>>
RefFromWasmAbi::AbiSource§type Anchor = RcRefMut<P47hClient>
type Anchor = RcRefMut<P47hClient>
RefFromWasmAbi::AnchorSource§unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor
unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor
RefFromWasmAbi::ref_from_abiSource§impl TryFromJsValue for P47hClient
impl TryFromJsValue for P47hClient
Source§impl VectorFromWasmAbi for P47hClient
impl VectorFromWasmAbi for P47hClient
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi(js: Self::Abi) -> Box<[P47hClient]>
Source§impl VectorIntoWasmAbi for P47hClient
impl VectorIntoWasmAbi for P47hClient
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi(vector: Box<[P47hClient]>) -> Self::Abi
Source§impl WasmDescribeVector for P47hClient
impl WasmDescribeVector for P47hClient
impl SupportsConstructor for P47hClient
impl SupportsInstanceProperty for P47hClient
impl SupportsStaticProperty for P47hClient
Auto Trait Implementations§
impl Freeze for P47hClient
impl RefUnwindSafe for P47hClient
impl Send for P47hClient
impl Sync for P47hClient
impl Unpin for P47hClient
impl UnsafeUnpin for P47hClient
impl UnwindSafe for P47hClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.