pub struct SignedEnvelope {
pub pubkey: ByteBufB64,
pub signature: ByteBufB64,
pub digest: Option<ByteBufB64>,
pub delegation: Option<Vec<SignedDelegationCompact>>,
}Expand description
The authentication envelope for Internet Computer authentication.
This structure encapsulates all the necessary components for authenticating a request to an Internet Computer service. It includes the public key of the sender, the signature, the content digest, and an optional delegation chain.
The envelope can be serialized to and from various formats, including bytes, base64 strings, and HTTP headers, making it versatile for different transport mechanisms.
Fields§
§pubkey: ByteBufB64The public key of the self-authenticating principal this request is from. This is the head of the delegation chain (if any) and is used to derive the principal ID of the sender.
signature: ByteBufB64A cryptographic signature authorizing the request.
When delegations are involved, this is the signature from the tail of the
delegation chain, not necessarily made by the owner of pubkey.
digest: Option<ByteBufB64>The request content’s hash digest that was signed by the sender. This is typically a SHA-256 or SHA3-256 hash of the request content.
delegation: Option<Vec<SignedDelegationCompact>>The chain of delegations connecting pubkey to signature, in order.
Each delegation authorizes the next entity in the chain to sign on behalf
of the previous entity, forming a chain of trust from the original identity
to the actual signer.
Implementations§
Source§impl SignedEnvelope
impl SignedEnvelope
Sourcepub fn sender(&self) -> Principal
pub fn sender(&self) -> Principal
Returns the sender’s principal ID derived from the public key.
This computes a self-authenticating principal ID based on the public key in the envelope, which uniquely identifies the sender.
§Returns
Principal- The principal ID of the sender
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Encodes the SignedEnvelope into a binary representation.
§Returns
Vec<u8>- The CBOR-encoded binary representation of the envelope
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<SignedEnvelope, String>
pub fn from_bytes(bytes: &[u8]) -> Result<SignedEnvelope, String>
Sourcepub fn to_base64(&self) -> String
pub fn to_base64(&self) -> String
Encodes the SignedEnvelope into a base64url string.
§Returns
String- The base64url-encoded representation of the envelope
Sourcepub fn from_base64(s: &str) -> Result<SignedEnvelope, String>
pub fn from_base64(s: &str) -> Result<SignedEnvelope, String>
Sourcepub fn verify(
&self,
now_ms: u64,
expect_target: Option<Principal>,
expect_digest: Option<&[u8]>,
) -> Result<(), String>
pub fn verify( &self, now_ms: u64, expect_target: Option<Principal>, expect_digest: Option<&[u8]>, ) -> Result<(), String>
Verifies the SignedEnvelope according to the Internet Computer authentication rules.
Verification rules:
- Delegation chain length must not exceed 5
- Delegations must not be expired (considering the permitted time drift)
- Each signature in the chain must verify against the corresponding public key
- If delegation targets are specified, the expected target must be included
- The content digest must match the expected digest (if provided)
§Arguments
now_ms- The current time in milliseconds since the Unix epochexpect_target- Optional canister ID that should be in the delegation targetsexpect_digest- Optional expected content digest to verify against
§Returns
Ok(())if verification succeedsErr(String)with a detailed error message if verification fails
Extracts a SignedEnvelope from the Authorization header.
This looks for an “ICP” authentication scheme in the Authorization header and decodes the associated token as a SignedEnvelope.
§Arguments
headers- The HTTP headers to extract from
§Returns
Option<Self>- The extracted envelope, or None if not found or invalid
Adds the SignedEnvelope to the Authorization header.
This encodes the envelope as a base64url string and adds it to the Authorization header with the “ICP” authentication scheme.
§Arguments
headers- The HTTP headers to add to
§Returns
Result<(), String>- Success or an error message if adding fails
Sourcepub fn from_headers(headers: &HeaderMap) -> Option<SignedEnvelope>
pub fn from_headers(headers: &HeaderMap) -> Option<SignedEnvelope>
Extracts a SignedEnvelope from the IC-Auth-* HTTP headers.
This looks for the individual components of the envelope in separate headers and reconstructs the envelope from them.
§Arguments
headers- The HTTP headers to extract from
§Returns
Option<Self>- The extracted envelope, or None if not found or invalid
Trait Implementations§
Source§impl CandidType for SignedEnvelope
impl CandidType for SignedEnvelope
Source§impl Clone for SignedEnvelope
impl Clone for SignedEnvelope
Source§fn clone(&self) -> SignedEnvelope
fn clone(&self) -> SignedEnvelope
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more