(feat): add crypto interface for MTPClient in wasm
Some checks failed
CI / rustfmt (push) Successful in 17s
CI / wasm build (push) Successful in 1m18s
CI / clippy (push) Successful in 1m32s
CI / test (push) Successful in 1m53s
CI / example (push) Successful in 1m35s
CI / duplicate code (push) Failing after 31s
CI / web client (push) Failing after 32s
CI / cargo-machete (push) Successful in 1m9s
CI / cargo-deny (push) Failing after 2m31s

(qol): update readme
(fix): small bug in keypair.rs
This commit is contained in:
Alois 2026-06-28 16:04:03 +02:00
commit 6b9bbb6ebf
6 changed files with 144 additions and 29 deletions

View file

@ -52,7 +52,11 @@ const unsubscribe = client.subscribe("SomeType", (message) => {
console.log(message.type, message.data);
});
await client.connectOrRegister();
if (client.credentials?.clientId == null) {
await client.register();
} else {
await client.connect();
}
await client.send("SomeType", { value: "hello" });
const response = await client.request(
@ -93,7 +97,9 @@ const client = await MTPClient.create({
storage,
});
const clientId = await client.connectOrRegister();
const clientId = client.credentials?.clientId == null
? await client.register()
: (await client.connect(), client.credentials.clientId);
```
The storage contract is intentionally small and may be sync or async:
@ -127,7 +133,6 @@ await client.connect();
- `connect()` opens a connection. If credentials include a `clientId` and `hostPublicKey` is available, it uses authenticated login; otherwise it uses unauthenticated connect.
- `register()` performs authenticated registration and persists the assigned client ID when storage is configured.
- `connectOrRegister()` registers when no client ID is present, otherwise performs authenticated login.
- `disconnect()` stops protocol pings and closes the underlying WebTransport session.
For certificate pinning, pass WebTransport certificate hashes: