Skip to main content

Module sui::nitro_attestation

use std::ascii;
use std::bcs;
use std::option;
use std::string;
use std::vector;
use sui::address;
use sui::clock;
use sui::hex;
use sui::object;
use sui::transfer;
use sui::tx_context;

Struct PCREntry

Represents a PCR entry with an index and value.

public struct PCREntry has drop
Click to open
Fields
index: u8
value: vector<u8>

Struct NitroAttestationDocument

Nitro Attestation Document defined for AWS.

public struct NitroAttestationDocument has drop
Click to open
Fields
version: u8
Version
module_id: vector<u8>
Issuing Nitro hypervisor module ID.
timestamp: u64
UTC time when document was created, in milliseconds since UNIX epoch.
digest: vector<u8>
The digest function used for calculating the register values.
pcrs: vector<vector<u8>>
The map of all locked PCRs at the moment the attestation document was generated. The array contains PCR0, PCR1, PCR2, PCR3, PCR4, PCR8. See more .
public_key: std::option::Option<vector<u8>>
An optional DER-encoded key the attestation, consumer can use to encrypt data with.
user_data: std::option::Option<vector<u8>>
Additional signed user data, defined by protocol.
nonce: std::option::Option<vector<u8>>
An optional cryptographic nonce provided by the attestation consumer as a proof of authenticity.

Constants

Error that the pcrs length is invalid.

const EInvalidPcrLength: u64 = 3;

Error that the feature is not available on this network.

const ENotSupportedError: u64 = 0;

Error that the attestation input failed to be parsed.

const EParseError: u64 = 1;

Error that the attestation failed to be verified.

const EVerifyError: u64 = 2;

Function verify_nitro_attestation_internal

Internal native function

fun verify_nitro_attestation_internal(attestation: &vector<u8>, current_timestamp: u64): sui::nitro_attestation::NitroAttestationDocument
Click to open
Implementation
native fun verify_nitro_attestation_internal(
    attestation: &vector<u8>,
    current_timestamp: u64
): NitroAttestationDocument;

Function verify_nitro_attestation

@param attestation: attesttaion documents bytes data. @param clock: the clock object.

Returns parsed NitroAttestationDocument after verifying the attestation.

public fun verify_nitro_attestation(attestation: &vector<u8>, clock: &sui::clock::Clock): sui::nitro_attestation::NitroAttestationDocument
Click to open
Implementation
public fun verify_nitro_attestation(
    attestation: &vector<u8>,
    clock: &Clock
): NitroAttestationDocument {
    verify_nitro_attestation_internal(attestation, clock::timestamp_ms(clock))
}

Function module_id

public fun module_id(attestation: &sui::nitro_attestation::NitroAttestationDocument): vector<u8>
Click to open
Implementation
public fun module_id(attestation: &NitroAttestationDocument): vector<u8> {
    attestation.module_id
}

Function timestamp

public fun timestamp(attestation: &sui::nitro_attestation::NitroAttestationDocument): &u64
Click to open
Implementation
public fun timestamp(attestation: &NitroAttestationDocument): &u64 {
    &attestation.timestamp
}

Function digest

public fun digest(attestation: &sui::nitro_attestation::NitroAttestationDocument): &vector<u8>
Click to open
Implementation
public fun digest(attestation: &NitroAttestationDocument): &vector<u8> {
    &attestation.digest
}

Function pcrs

Returns a list of mapping from index to the pcr itself. Currently AWS supports PCR0, PCR1, PCR2, PCR3, PCR4, PCR8.

public fun pcrs(attestation: &sui::nitro_attestation::NitroAttestationDocument): vector<sui::nitro_attestation::PCREntry>
Click to open
Implementation
public fun pcrs(attestation: &NitroAttestationDocument): vector<PCREntry> {
    assert!(attestation.pcrs.length() == 6, EInvalidPcrLength);
    let mut result: vector<PCREntry> = vector::empty();
    let indices = vector[0, 1, 2, 3, 4, 8];
    let mut i = 0;
    while (i < attestation.pcrs.length()) {
        result.push_back(PCREntry {
            index: indices[i],
            value: attestation.pcrs[i]
        });
        i = i + 1;
    };
    result
}

Function public_key

public fun public_key(attestation: &sui::nitro_attestation::NitroAttestationDocument): &std::option::Option<vector<u8>>
Click to open
Implementation
public fun public_key(attestation: &NitroAttestationDocument): &Option<vector<u8>> {
    &attestation.public_key
}

Function user_data

public fun user_data(attestation: &sui::nitro_attestation::NitroAttestationDocument): &std::option::Option<vector<u8>>
Click to open
Implementation
public fun user_data(attestation: &NitroAttestationDocument): &Option<vector<u8>> {
    &attestation.user_data
}

Function nonce

public fun nonce(attestation: &sui::nitro_attestation::NitroAttestationDocument): &std::option::Option<vector<u8>>
Click to open
Implementation
public fun nonce(attestation: &NitroAttestationDocument): &Option<vector<u8>> {
    &attestation.nonce
}

Function version

public fun version(attestation: &sui::nitro_attestation::NitroAttestationDocument): &u8
Click to open
Implementation
public fun version(attestation: &NitroAttestationDocument): &u8 {
    &attestation.version
}

Function index

public fun index(entry: &sui::nitro_attestation::PCREntry): u8
Click to open
Implementation
public fun index(entry: &PCREntry): u8 {
    entry.index
}

Function value

public fun value(entry: &sui::nitro_attestation::PCREntry): &vector<u8>
Click to open
Implementation
public fun value(entry: &PCREntry): &vector<u8> {
    &entry.value
}