Compare commits

..

1 Commits

Author SHA1 Message Date
yuroitaki
616ec1394a Add gitignore 2025-07-29 10:48:25 +08:00
9 changed files with 293 additions and 519 deletions

View File

@@ -1,10 +0,0 @@
[target.wasm32-unknown-unknown]
rustflags = [
"-C",
"target-feature=+atomics,+bulk-memory,+mutable-globals",
"-A",
"unused_qualifications"
]
[unstable]
build-std = ["panic_abort", "std"]

718
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1 +1,4 @@
wasm/
**/wasm
**/dist
**/node_modules
**/Cargo.lock

View File

@@ -1,11 +1,10 @@
import * as main from "./main";
import { PluginOutput, PluginVerifierConfig, VerifierOutput } from "./pdk";
import { PluginVerifierConfig, VerifierOutput } from "./pdk";
export function config(): number {
const output = main.configImpl();
console.log(`configImpl untyped output: ${JSON.stringify(output)}`);
const untypedOutput = PluginVerifierConfig.toJson(output);
Host.outputString(JSON.stringify(untypedOutput));
@@ -14,11 +13,9 @@ export function config(): number {
export function verify(): number {
const untypedInput = JSON.parse(Host.inputString());
const input = VerifierOutput.fromJson(untypedInput);
const input = VerifierOutput.fromJson(untypedInput);
const output = main.verifyImpl(input);
console.log(`verifyImpl untyped output: ${JSON.stringify(output)}`);
Host.outputString(JSON.stringify(output));
main.verifyImpl(input);
return 0;
}

View File

@@ -1,6 +1,6 @@
import { PluginOutput, PluginVerifierConfig, VerifierOutput } from "./pdk";
import { PluginVerifierConfig, VerifierOutput } from "./pdk";
const SERVER_DOMAIN = "api.x.com";
const SERVER_DOMAIN = "raw.githubusercontent.com";
/**
* Returns the verifier configuration.
@@ -19,9 +19,8 @@ export function configImpl(): PluginVerifierConfig {
* and allows the plugin to perform custom verification logic.
*
* @param {VerifierOutput} input -
* @returns {PluginOutput}
*/
export function verifyImpl(input: VerifierOutput): PluginOutput {
export function verifyImpl(input: VerifierOutput) {
console.log("Starting verification...");
const { serverName, transcript, transcriptCommitments } = input;
@@ -52,7 +51,7 @@ export function verifyImpl(input: VerifierOutput): PluginOutput {
const received = new Uint8Array(transcript.received);
const response = new TextDecoder().decode(received);
if (!response.includes("screen_name")) {
if (!response.includes("123 Elm Street")) {
throw new Error("Verification failed: missing data in received data");
}
@@ -61,18 +60,12 @@ export function verifyImpl(input: VerifierOutput): PluginOutput {
throw new Error("Verification failed: server name mismatches");
}
const match = response.match(/"screen_name":"([^"]+)"/);
const screenName = match ? match[1] : "";
const sentString = bytesToRedactedString(sent);
const receivedString = bytesToRedactedString(received);
console.log(`Successfully verified ${SERVER_DOMAIN}`);
console.log(`Verified sent data:\n${sentString}`);
console.log(`Verified received data:\n${receivedString}`);
console.log(`Verified screen name: ${screenName}`);
return PluginOutput.fromJson({ screenName: screenName });
}
/**

View File

@@ -83,24 +83,6 @@ export class EncoderSecret {
}
}
export class PluginOutput {
// @ts-expect-error TS2564
screenName: string;
static fromJson(obj: any): PluginOutput {
console.log(`PluginOutput fromJson: ${JSON.stringify(obj)}`);
return {
...obj,
};
}
static toJson(obj: PluginOutput): any {
return {
...obj,
};
}
}
/**
* Commitment to the encoding of the transcript data
*/

View File

@@ -4,7 +4,7 @@ use anyhow::anyhow;
use extism_pdk::*;
use pdk::*;
const SERVER_DOMAIN: &str = "api.x.com";
const SERVER_DOMAIN: &str = "raw.githubusercontent.com";
// Returns the verifier configuration.
// The configuration is used to initialize the verifier in the host.

View File

@@ -29,7 +29,6 @@ futures-util = { workspace = true }
glob = { version = "0.3.2" }
http = { workspace = true }
http-body-util = { workspace = true }
reqwest = "0.12"
hyper = { workspace = true, features = ["client", "http1", "server"] }
hyper-util = { workspace = true, features = ["full"] }
jsonwebtoken = { version = "9.3.1", features = ["use_pem"] }

View File

@@ -23,9 +23,6 @@ use tokio_util::compat::TokioAsyncReadCompatExt;
use tracing::debug;
use crate::{types::NotaryGlobals, NotaryServerError};
use reqwest;
use serde_json::json;
use std::env;
#[derive(Deserialize, FromBytes, Serialize, ToBytes, Debug)]
#[encoding(Json)]
@@ -41,13 +38,6 @@ struct PluginVerifierConfig {
max_recv_records_online: Option<usize>,
}
#[derive(Deserialize, FromBytes, Serialize, ToBytes, Debug)]
#[encoding(Json)]
#[serde(rename_all = "camelCase")]
struct PluginOutput {
screen_name: String,
}
#[derive(Deserialize, FromBytes, Serialize, ToBytes)]
#[encoding(Json)]
#[serde(rename_all = "camelCase")]
@@ -197,33 +187,13 @@ pub async fn verifier_service<T: AsyncWrite + AsyncRead + Send + Unpin + 'static
.await
.map_err(|_| eyre!("Timeout reached before verification completes"))??;
let result = plugin
.call::<VerifierOutput, PluginOutput>("verify", output.into())
plugin
.call::<VerifierOutput, ()>("verify", output.into())
.map_err(|e| eyre!("Failed to verify on plugin: {}", e))?;
debug!("Plugin verification result: {:?}", result);
plugin
.reset()
.map_err(|e| eyre!("Failed to reset plugin memory: {}", e))?;
let client = reqwest::Client::new();
let url = "http://localhost:3030/update-session";
let body = json!({"screen_name": result.screen_name, "session_id": session_id});
let response = client.post(url)
.header("Content-Type", "application/json")
.header("X-VERIFIER-SECRET-KEY", env::var("VERIFIER_SECRET_KEY").unwrap())
.body(body.to_string())
.send()
.await
.map_err(|e| eyre!("Failed to send request: {}", e))?;
let status = response.status();
let body_text = response.text().await.map_err(|e| eyre!("Failed to get response body: {}", e))?;
println!("Status: {}", status);
println!("Response body: {}", body_text);
Ok(())
}