Skip to main content

P47hClient

Struct P47hClient 

Source
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

Source

pub fn generate_new() -> Result<P47hClient, JsValue>

Generates a new cryptographic identity using browser’s secure random source

Source

pub fn from_secret(secret_bytes: &[u8]) -> Result<P47hClient, JsValue>

Reconstructs identity from previously exported secret bytes

Source

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 IndexedDB
Source

pub fn from_wrapped_secret( wrapped: &[u8], session_key: &[u8], ) -> Result<P47hClient, JsValue>

Imports identity from encrypted secret

§Arguments
  • wrapped - The encrypted secret from export_wrapped_secret
  • session_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);
Source

pub fn get_did(&self) -> String

Returns the Decentralized Identifier (DID) for this identity

Source

pub fn get_public_key(&self) -> Vec<u8>

Returns the raw public key bytes (for advanced use cases)

Source

pub fn sign_challenge(&self, challenge: &[u8]) -> Vec<u8>

Signs a challenge for authentication with the server

Source

pub fn sign_data(&self, data: &[u8]) -> Vec<u8>

Signs arbitrary data (for advanced use cases)

Source

pub fn evaluate_request( &self, policy_toml: &str, resource: &str, action: &str, ) -> Result<JsValue, JsValue>

Evaluates a policy request locally without server round-trip

Source

pub fn evaluate_batch( &self, policy_toml: &str, requests_json: &str, ) -> Result<JsValue, JsValue>

Batch evaluation of multiple requests (more efficient)

Trait Implementations§

Source§

impl From<P47hClient> for JsValue

Source§

fn from(value: P47hClient) -> Self

Converts to this type from the input type.
Source§

impl FromWasmAbi for P47hClient

Source§

type Abi = WasmPtr<WasmRefCell<P47hClient>>

The Wasm ABI type that this converts from when coming back out from the ABI boundary.
Source§

unsafe fn from_abi(js: Self::Abi) -> Self

Recover a Self from Self::Abi. Read more
Source§

impl IntoWasmAbi for P47hClient

Source§

type Abi = WasmPtr<WasmRefCell<P47hClient>>

The Wasm ABI type that this converts into when crossing the ABI boundary.
Source§

fn into_abi(self) -> Self::Abi

Convert self into Self::Abi so that it can be sent across the wasm ABI boundary.
Source§

impl LongRefFromWasmAbi for P47hClient

Source§

type Abi = WasmPtr<WasmRefCell<P47hClient>>

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRef<P47hClient>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl OptionFromWasmAbi for P47hClient

Source§

fn is_none(abi: &Self::Abi) -> bool

Tests whether the argument is a “none” instance. If so it will be deserialized as None, and otherwise it will be passed to FromWasmAbi.
Source§

impl OptionIntoWasmAbi for P47hClient

Source§

fn none() -> Self::Abi

Returns an ABI instance indicating “none”, which JS will interpret as the None branch of this option. Read more
Source§

impl RefFromWasmAbi for P47hClient

Source§

type Abi = WasmPtr<WasmRefCell<P47hClient>>

The Wasm ABI type references to Self are recovered from.
Source§

type Anchor = RcRef<P47hClient>

The type that holds the reference to 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§

unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor

Recover a Self::Anchor from Self::Abi. Read more
Source§

impl RefMutFromWasmAbi for P47hClient

Source§

type Abi = WasmPtr<WasmRefCell<P47hClient>>

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRefMut<P47hClient>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl TryFromJsValue for P47hClient

Source§

fn try_from_js_value(value: JsValue) -> Result<Self, JsValue>

Performs the conversion.
Source§

fn try_from_js_value_ref(value: &JsValue) -> Option<Self>

Performs the conversion.
Source§

impl VectorFromWasmAbi for P47hClient

Source§

type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi

Source§

unsafe fn vector_from_abi(js: Self::Abi) -> Box<[P47hClient]>

Source§

impl VectorIntoWasmAbi for P47hClient

Source§

impl WasmDescribe for P47hClient

Source§

impl WasmDescribeVector for P47hClient

Source§

impl SupportsConstructor for P47hClient

Source§

impl SupportsInstanceProperty for P47hClient

Source§

impl SupportsStaticProperty for P47hClient

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ReturnWasmAbi for T
where T: IntoWasmAbi,

Source§

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi
Source§

fn return_abi(self) -> <T as ReturnWasmAbi>::Abi

Same as IntoWasmAbi::into_abi, except that it may throw and never return in the case of Err.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,