Skip to main content

credential_keylet

Function credential_keylet 

Source
pub fn credential_keylet(
    subject: &AccountID,
    issuer: &AccountID,
    credential_type: &[u8],
) -> Result<KeyletBytes>
Expand description

Generates a credential keylet for a given subject, issuer, and credential type.

A credential keylet is used to reference credential entries in the XRP Ledger.

§Arguments

  • subject - The AccountID of the subject for whom the credential is issued
  • issuer - The AccountID of the entity issuing the credential
  • credential_type - A byte slice representing the type of credential

§Returns

  • Result<KeyletBytes> - On success, returns a 32-byte credential keylet. On failure, returns an Error with the corresponding error code.

§Safety

This function makes unsafe FFI calls to the host environment through the host::credential_keylet function.

§Example

use xrpl_wasm_stdlib::core::types::account_id::AccountID;
use xrpl_wasm_stdlib::core::keylets::credential_keylet;
use xrpl_wasm_stdlib::host::trace::{DataRepr, trace_data, trace_num};
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let subject: AccountID =
        AccountID::from(*b"\xd5\xb9\x84VP\x9f \xb5'\x9d\x1eJ.\xe8\xb2\xaa\x82\xaec\xe3");
    let issuer: AccountID =
        AccountID::from(*b"\xd5\xb9\x84VP\x9f \xb5'\x9d\x1eJ.\xe8\xb2\xaa\x82\xaec\xe3");
    let cred_type: &[u8] = b"termsandconditions";
    match credential_keylet(&subject, &issuer, cred_type) {
      xrpl_wasm_stdlib::host::Result::Ok(keylet) => {
        let _ = trace_data("Generated keylet", &keylet, DataRepr::AsHex);
      }
      xrpl_wasm_stdlib::host::Result::Err(e) => {
        let _ = trace_num("Error assembling keylet", e.code() as i64);
      }
    }
    Ok(())
}