pub struct AuthPayload {
pub signed_message: SignedMessage,
pub nonce: [u8; 32],
pub message: String,
pub recipient: String,
pub callback_url: Option<String>,
}Expand description
HTTP request payload for NEP-413 authentication.
This is the typical JSON structure sent from a frontend to a backend for authentication. Use this to deserialize the HTTP request body.
§Example
use near_kit::nep413::{AuthPayload, verify_signature, DEFAULT_MAX_AGE};
// Parse JSON from HTTP request body (in a real app, from req.body)
fn handle_login(body: &str) -> bool {
let payload: AuthPayload = serde_json::from_str(body).unwrap();
let params = payload.to_params();
verify_signature(&payload.signed_message, ¶ms, DEFAULT_MAX_AGE)
}Fields§
§signed_message: SignedMessageThe signed message from the client.
nonce: [u8; 32]The nonce as a hex-encoded string (64 characters for 32 bytes).
message: StringThe message that was signed (must match what the client signed).
recipient: StringThe recipient identifier (must match what the client signed).
callback_url: Option<String>Optional callback URL (must match what the client signed, if any).
Implementations§
Source§impl AuthPayload
impl AuthPayload
Sourcepub fn to_params(&self) -> SignMessageParams
pub fn to_params(&self) -> SignMessageParams
Convert to SignMessageParams for verification.
Sourcepub fn from_signed(
signed_message: SignedMessage,
params: &SignMessageParams,
) -> Self
pub fn from_signed( signed_message: SignedMessage, params: &SignMessageParams, ) -> Self
Create an AuthPayload from a signed message and the original parameters.
This is useful when you want to generate the same JSON format that a TypeScript client would produce, for example when testing or when a Rust client needs to authenticate to a service.
§Example
use near_kit::{Near, nep413};
let near = Near::testnet()
.credentials("ed25519:...", "alice.testnet")?
.build();
let params = nep413::SignMessageParams {
message: "Sign in to My App".to_string(),
recipient: "myapp.com".to_string(),
nonce: nep413::generate_nonce(),
callback_url: None,
state: None,
};
let signed = near.sign_message(params.clone()).await?;
let payload = nep413::AuthPayload::from_signed(signed, ¶ms);
// Serialize to JSON for HTTP request
let json = serde_json::to_string(&payload)?;
println!("POST body: {}", json);Trait Implementations§
Source§impl Clone for AuthPayload
impl Clone for AuthPayload
Source§fn clone(&self) -> AuthPayload
fn clone(&self) -> AuthPayload
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more