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:
- Verify the signed request with
verify_request, passing the received body asExpectedRequest::bodyand the canonical URL. - Parse the same bytes with
AdmissionClaim::parse. - Call
checkwith its own node DID, the signer fromVerifiedRequest::signerand the digest of the notice it serves. - Look up
invitationand require it to be issued, unexpired and bound tosubject. - 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
impl AdmissionClaim
Sourcepub fn new(fields: AdmissionFields) -> Self
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.
Sourcepub fn parse(bytes: &[u8]) -> Result<Self, ParseAdmissionError>
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.
Sourcepub fn check(
&self,
expected_node: &DidNostr,
signer: &DidNostr,
expected_notice: &Sha256Digest,
) -> Result<(), CheckAdmissionError>
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.
Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Consumes the claim and returns its exact bytes.
Sourcepub fn fields(&self) -> &AdmissionFields
pub fn fields(&self) -> &AdmissionFields
Returns all fields.
Sourcepub fn invitation(&self) -> InvitationId
pub fn invitation(&self) -> InvitationId
Returns the invitation being redeemed.
Sourcepub fn notice_sha256(&self) -> Sha256Digest
pub fn notice_sha256(&self) -> Sha256Digest
Returns the notice digest the subject signed.