mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
#### PR Dependency Tree * **PR #14243** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Batch management API for coordinated document mutations and change tracking. * New document accessors (IDs, state snapshots, change/delete set queries) and subscriber count. * **Chores** * Upgraded Rust edition across packages to 2024. * Repository-wide formatting, stylistic cleanups and test adjustments. * **Breaking Changes** * Removed the Node native bindings package and its JS/TS declarations and tests (no longer published/available). <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
67 lines
1.5 KiB
Rust
67 lines
1.5 KiB
Rust
use std::convert::TryFrom;
|
|
|
|
use affine_common::hashcash::Stamp;
|
|
use napi::{Env, Result as NapiResult, Task, bindgen_prelude::AsyncTask};
|
|
use napi_derive::napi;
|
|
|
|
pub struct AsyncVerifyChallengeResponse {
|
|
response: String,
|
|
bits: u32,
|
|
resource: String,
|
|
}
|
|
|
|
#[napi]
|
|
impl Task for AsyncVerifyChallengeResponse {
|
|
type Output = bool;
|
|
type JsValue = bool;
|
|
|
|
fn compute(&mut self) -> NapiResult<Self::Output> {
|
|
Ok(if let Ok(stamp) = Stamp::try_from(self.response.as_str()) {
|
|
stamp.check(self.bits, &self.resource)
|
|
} else {
|
|
false
|
|
})
|
|
}
|
|
|
|
fn resolve(&mut self, _: Env, output: bool) -> NapiResult<Self::JsValue> {
|
|
Ok(output)
|
|
}
|
|
}
|
|
|
|
#[napi]
|
|
pub fn verify_challenge_response(
|
|
response: String,
|
|
bits: u32,
|
|
resource: String,
|
|
) -> AsyncTask<AsyncVerifyChallengeResponse> {
|
|
AsyncTask::new(AsyncVerifyChallengeResponse {
|
|
response,
|
|
bits,
|
|
resource,
|
|
})
|
|
}
|
|
|
|
pub struct AsyncMintChallengeResponse {
|
|
bits: Option<u32>,
|
|
resource: String,
|
|
}
|
|
|
|
#[napi]
|
|
impl Task for AsyncMintChallengeResponse {
|
|
type Output = String;
|
|
type JsValue = String;
|
|
|
|
fn compute(&mut self) -> NapiResult<Self::Output> {
|
|
Ok(Stamp::mint(self.resource.clone(), self.bits).format())
|
|
}
|
|
|
|
fn resolve(&mut self, _: Env, output: String) -> NapiResult<Self::JsValue> {
|
|
Ok(output)
|
|
}
|
|
}
|
|
|
|
#[napi]
|
|
pub fn mint_challenge_response(resource: String, bits: Option<u32>) -> AsyncTask<AsyncMintChallengeResponse> {
|
|
AsyncTask::new(AsyncMintChallengeResponse { bits, resource })
|
|
}
|