Skip to main content

AdmissionClaim

Struct AdmissionClaim 

Source
pub struct AdmissionClaim { /* private fields */ }
Expand description

The body of a redemption request, together with its exact JSON bytes.

The JSON shape is an object with exactly these members: purpose (always ADMISSION_CLAIM_PURPOSE), node, subject, invitation and notice_sha256. Unknown, duplicate and missing members are rejected, and so is any other purpose.

Unlike the bootstrap ClaimBody, an admission claim carries no nonce and no expiry. The signed request that carries it is already fresh (±60 s), single use (its event ID is stored) and bound to the node’s canonical URL, and the invitation is consumed when it is accepted. The client writes the body itself; there is no server-issued copy to compare against.

Equality compares the fields and the bytes. The type has no serde implementations on purpose: send the bytes from as_bytes and parse them with parse.

§Accepting a claim

AdmissionClaim::check is one step and proves nothing on its own. To accept a redemption the server must, committing nothing unless every step succeeds:

  1. Verify the signed request with verify_request, passing the received body as ExpectedRequest::body and the canonical URL.
  2. Parse the same bytes with AdmissionClaim::parse.
  3. Call check with its own node DID, the signer from VerifiedRequest::signer and the digest of the notice it serves.
  4. Look up invitation and require it to be issued, unexpired and bound to subject.
  5. In one transaction, consume the invitation, record the request’s event ID for replay protection and create the membership.

§Examples

use stratum_node_core::{
    admission_notice_v1_sha256, AdmissionClaim, AdmissionFields, CheckAdmissionError,
    InvitationId, NostrSecretKey,
};

let node = NostrSecretKey::from_hex(&"06".repeat(32))?.public();
let tenant = NostrSecretKey::from_hex(&"07".repeat(32))?.public();

// Client side: build the body and sign a request over its bytes.
let claim = AdmissionClaim::new(AdmissionFields {
    node,
    subject: tenant,
    invitation: InvitationId::from_bytes([1; 16]),
    notice_sha256: admission_notice_v1_sha256(),
});

// Server side, after verifying the signed request over these bytes:
let received = AdmissionClaim::parse(claim.as_bytes())?;
received.check(&node, &tenant, &admission_notice_v1_sha256())?;

// A request signed by anyone else fails.
let other = NostrSecretKey::from_hex(&"08".repeat(32))?.public();
assert_eq!(
    received.check(&node, &other, &admission_notice_v1_sha256()),
    Err(CheckAdmissionError::SubjectMismatch),
);

Implementations§

Source§

impl AdmissionClaim

Source

pub fn new(fields: AdmissionFields) -> Self

Serialises fields once, with purpose set to ADMISSION_CLAIM_PURPOSE, and keeps the bytes.

The members are written in the order purpose, node, subject, invitation, notice_sha256, as compact JSON.

§Panics

Does not panic: serde_json has no failure path for this struct of strings.

Source

pub fn parse(bytes: &[u8]) -> Result<Self, ParseAdmissionError>

Parses admission-claim bytes strictly and keeps them exactly as given.

§Errors

Returns ParseAdmissionError::WrongPurpose when the body is an object whose purpose is a string other than ADMISSION_CLAIM_PURPOSE, and ParseAdmissionError::Malformed for any other deviation: not a single JSON object, a missing, unknown or duplicate member, or an invalid member value.

Source

pub fn check( &self, expected_node: &DidNostr, signer: &DidNostr, expected_notice: &Sha256Digest, ) -> Result<(), CheckAdmissionError>

Checks the claim against the node’s own DID, the verified signer of the request that carried it and the digest of the notice the node serves.

This is a partial check; see Accepting a claim for the full procedure.

§Errors

Returns CheckAdmissionError::NodeMismatch when the claim names another node, CheckAdmissionError::SubjectMismatch when its subject is not signer, and CheckAdmissionError::NoticeMismatch when its notice digest is not expected_notice, checked in that order.

Source

pub fn as_bytes(&self) -> &[u8] ⓘ

Returns the exact bytes this claim was built or parsed from.

Source

pub fn into_bytes(self) -> Vec<u8> ⓘ

Consumes the claim and returns its exact bytes.

Source

pub fn fields(&self) -> &AdmissionFields

Returns all fields.

Source

pub fn node(&self) -> DidNostr

Returns the node being joined.

Source

pub fn subject(&self) -> DidNostr

Returns the invited identity.

Source

pub fn invitation(&self) -> InvitationId

Returns the invitation being redeemed.

Source

pub fn notice_sha256(&self) -> Sha256Digest

Returns the notice digest the subject signed.

Trait Implementations§

Source§

impl Clone for AdmissionClaim

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AdmissionClaim

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for AdmissionClaim

Source§

impl Hash for AdmissionClaim

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for AdmissionClaim

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for AdmissionClaim

Auto Trait Implementations§

§

impl Forget for AdmissionClaim

§

impl Freeze for AdmissionClaim
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl Move for AdmissionClaim

§

impl RefUnwindSafe for AdmissionClaim

§

impl Send for AdmissionClaim
where RawVecInner: Send,

§

impl Sync for AdmissionClaim
where RawVecInner: Sync,

§

impl Unpin for AdmissionClaim
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for AdmissionClaim

§

impl UnwindSafe for AdmissionClaim
where RawVecInner: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.