> ## Documentation Index
> Fetch the complete documentation index at: https://docs.notareum.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Registry

# Rust: Registry

`RegistryClient` wraps the `NotaRegistry` contract and is accessible as the `registry` field on the `Notareum` factory: `ntm.registry`. It registers resources, resolves aliases, revokes records, and computes resource IDs locally. All on-chain methods are `async`; write methods require the client to be configured with a signer.

## Write methods

### `register_resource`

Registers a new resource on-chain and returns the transaction hash as a `String`:

```rust theme={"system"}
pub async fn register_resource(
    &self,
    resource_type: u8,
    chain_id: u64,
    identifier: &str,
    proof_hash: &str,
    alias: Option<&str>,
) -> Result<String, SdkError>
```

`proof_hash` is the `keccak256` of the canonical `.nota` serialization as a `0x`-prefixed hex string. Pass `None` for `alias` to skip alias assignment.

### `revoke_resource`

Only the current owner may revoke. Revocation flips the `is_revoked` flag but preserves the record for auditability:

```rust theme={"system"}
pub async fn revoke_resource(
    &self,
    resource_id: &str,
) -> Result<String, SdkError>
```

### `add_resource_type` / `remove_resource_type`

Governance-only. Extend or shrink the governance-managed resource type registry:

```rust theme={"system"}
pub async fn add_resource_type(
    &self,
    type_id: u8,
    name: &str,
) -> Result<String, SdkError>

pub async fn remove_resource_type(
    &self,
    type_id: u8,
) -> Result<String, SdkError>
```

## Read methods

### `get_resource`

Fetches the full resource record:

```rust theme={"system"}
pub async fn get_resource(
    &self,
    resource_id: &str,
) -> Result<ResourceInfo, SdkError>
```

`ResourceInfo` includes `owner`, `resource_type`, `chain_id`, `proof_hash`, `alias`, `verification_level`, `registered_at`, `last_updated_at`, and `is_revoked`.

### `resolve_alias`

Resolves a human-readable alias to the `0x`-prefixed bytes32 resource ID:

```rust theme={"system"}
pub async fn resolve_alias(
    &self,
    alias: &str,
) -> Result<String, SdkError>
```

### `is_valid_resource_type` / `get_resource_type_name`

Introspect the governance-managed resource type registry:

```rust theme={"system"}
pub async fn is_valid_resource_type(&self, type_id: u8) -> Result<bool, SdkError>
pub async fn get_resource_type_name(&self, type_id: u8) -> Result<String, SdkError>
```

## Utility: `compute_resource_id`

Derives the resource ID locally, without an RPC call:

```rust theme={"system"}
pub fn compute_resource_id(
    &self,
    resource_type: u8,
    chain_id: u64,
    identifier: &str,
) -> Result<String, SdkError>
```

The output matches the on-chain derivation exactly, so you can predict the ID before paying gas to register it.

## Full example

```rust theme={"system"}
use notareum::CreateNotaOptions;
use tiny_keccak::{Hasher, Keccak};

// 1. Create and sign a .nota file
let signed = ntm.nota
    .create(CreateNotaOptions {
        type_: "address".into(),
        chain_name: "ethereum".into(),
        chain_id: 1,
        identifier: "0xabc...".into(),
        alias: Some("alice.eth".into()),
        ..CreateNotaOptions::new("address", "ethereum", 1, "0xabc...")
    })?
    .validate()?
    .sign(&private_key_hex)?;

let wire = signed.serialize()?;

// 2. Compute proof hash (keccak256 of canonical bytes)
let mut hasher = Keccak::v256();
let mut out = [0u8; 32];
hasher.update(wire.as_bytes());
hasher.finalize(&mut out);
let proof_hash = format!("0x{}", hex::encode(out));

// 3. Register
let tx_hash = ntm.registry
    .register_resource(0u8, 1u64, "0xabc...", &proof_hash, Some("alice.eth"))
    .await?;
println!("Registered: {tx_hash}");

// 4. Later, anyone resolves it
let resource_id = ntm.registry.resolve_alias("alice.eth").await?;
let info = ntm.registry.get_resource(&resource_id).await?;
println!("{} level={}", info.owner, info.verification_level);
```

> `tiny_keccak` and `hex` are already transitive dependencies of the SDK; you can also reach into `notareum::core::crypto` for a thin keccak helper instead of pulling them in directly.

## See also

* [Resource Registry protocol page](../../protocol/resource-registry.md)
* [Registering a Resource guide](../../guides/registering-a-resource.md)
* [Rust API Reference](api-reference.md)
