# Nom - Name Registry DNA Zome Calls
###### tags: `Technical Specification`
**Pluggable Zomes**
1. `create_unique_name` [/]
2. `check_expiration` []
**Namespace**
1. `create_namespace` [/]
2. `update_namespace` [/]
3. `renew_namespace` [/]
4. `get_all_namespaces` [/]
5. `get_nametypes(input: namespace)` [/]
**NameType**
1. `add_nametype` [/]
2. `update_nametype` [/]
**NameRegistration**
1. `register_name` [/]
2. `renew_name` [/]
3. `get_name_registration(input: {unique_name: string, namespace: string, nametype: Vec<u8>})` [/]
4. `register_global_name` [/]
5. `renew_global_name(??)` [/]
##### Create Namespace
```rust=
#[hdk_entry]
struct Namespace {
origin_dna: HoloHash<Dna>,
global_name_reg_opt_in: bool,
}
#[hdk_entry]
struct NamespaceProperties {
name: string,
dna_versions: Vec<HoloHash<Dna>>, // index 0 is the initial DNA hash
creator: AgentPubKey,
// list of agents that can create NameType entries within
// this namespace and modify this property entry
maintainers: Vec<AgentPubKey>,
org_detail: Organization,
// index 0 of top level key is the path_component_name
// second level is <key: version, value: NameType EntryHash>
// The new NameType entry is the prev_action so
// we can get it in validation to see if it exist
name_types: HashMap<Vec<u8>, BTreeMap<u16, EntryHash>>,
namespace_coupons: BtreeMap<u8, NamespaceCouponData>
}
struct NamespaceCouponData {
serial_number: Vec<u8>, // must be unique
origin_dna: HoloHash<Dna>,
global_name_reg_opt_in: bool,
payment_proof_sig: Signature, // The public key (ed25519) should be in the property of the DNA
max_free_names: u32, // The price of the namespace differs based on the number of max names provided
ttl: u8 // time to live. expressed in years
}
create_namespace(input: NamespaceInput) -> ExternResult<NamespaceOutput> {}
struct NamespaceInput {
name: String,
initial_dna: HoloHash<Dna>,
coupon: NamespaceCouponData,
maintainers: Vec<AgentPubKey>
}
struct NamespaceOutput {
id: HoloHash<Entry>,
name: String
}
```
```mermaid
sequenceDiagram
participant Client as Client_HApp
participant Portal as Registration_Portal
participant Reg as Registry_DNA
Portal-->>Client: display namespace registration page
Client-->>Portal: enter namespace registration details
Portal-->>Reg: call `create_namespace(input)`
Reg-->>Reg: create_entry Namespace
Reg-->>Reg: create_entry NamespaceProperties
Reg-->>Reg: create_link from Namespace to NamespaceProperties
Reg-->>Portal: return NamespaceOutput
Portal-->>Client: return Namespace Hash
```
##### Update Namespace
```rust=
update_namespace(input: NamespaceInput) -> ExternResult<NamespaceOutput> {}
struct NamespaceInput {}
struct NamespaceOutput {}
```
```mermaid
sequenceDiagram
participant Client as Client_HApp
participant Portal as Registration_Portal
participant Reg as Registry_DNA
Portal-->>Client: display Namespace update page
Client-->>Portal: enter Namespace hash to update and update details
Portal-->>Reg: call `update_namespace(input)`
Reg-->>reg: get_links() on Namespace hash
Reg-->>Reg: construct NamespaceProperties struct with updated details
Reg-->>Reg: update_entry() NamespaceProperties Entry
Reg-->>Portal: return NamespaceOutput
Portal-->>Client: return Namespace Hash
```
##### Renew Namespace
```rust=
create_namespace(input: NamespaceInput) -> ExternResult<NamespaceOutput> {}
struct NamespaceInput {}
struct NamespaceOutput {}
```
```mermaid
sequenceDiagram
participant Client as Client_HApp
participant Portal as Registration_Portal
participant Reg as Registry_DNA
Portal-->>Client: display Namespace renewal page
Client-->>Portal: enter Namespace hash to renew and new coupon
Portal-->>Reg: call `renew_namespace(input)`
Reg-->>Reg: get_links() on Namespace hash using tag "metadata"
Reg-->>Reg: get() on links[0].target
Reg-->>Reg: construct NamespaceProperties struct with updated coupon BTreeMap
Reg-->>Reg: update_entry() NamespaceProperties Entry
Reg-->>Portal: return NamespaceOutput
Portal-->>Client: return Namespace Hash
```
##### Add NameType
```rust=
add_nametype(input: NameTypeInput) -> <> {}
NameTypeInput {}
NameTypeOutput {}
```
```mermaid
sequenceDiagram
participant Client as Client_HApp
participant Portal as Registration_Portal
participant Reg as Registry_DNA
Portal-->>Client: display nametype registration page
Client-->>Portal: enter namespace hash to add NameType to
Portal-->>Reg: call `add_nametype(input)`
Reg-->>Reg: create_entry NameType
Reg-->>Reg: get_links() on Namespace hash using tag "metadata" to get the NamespaceProperties %% do we get the latest here?
Reg-->>Reg: create new BTreeMap adding new NameType as version 1 to previous entries
Reg-->>Reg: add <Nametype.component, BTreeMap> to HashMap in NamespaceProperties.name_types
Reg-->>Reg: update_entry NamespaceProperties with the changes
Reg-->>Portal: return NameTypeOutput
Portal-->>Client: return Namespace Hash
```
##### Update NameType
```rust=
update_nametype(input: NameTypeInput) -> <> {}
NameTypeInput {}
NameTypeOutput {}
```
```mermaid
sequenceDiagram
participant Client as Client_HApp
participant Portal as Registration_Portal
participant Reg as Registry_DNA
Portal-->>Client: display NameType registration page
Client-->>Portal: enter Namespace hash
Portal-->>Client: display list of NameTypes
Client-->>Portal: select NameType to update
Portal-->>Client: display NameType update page
Client-->>Portal: enter NameType update details
Portal-->>Reg: call `update_nametype(input)`
Reg-->>Reg: get() NameType Entry
Reg-->>Reg: construct NameType struct using input
Reg-->>Reg: udpate_entry() NameType Entry
Reg-->>Reg: get_links() on NameType.namespace using tag "metadata" to get the NamespaceProperties %% do we get the latest here?
Reg-->>Reg: create new BTreeMap adding the updated NameType as version max+1 to previous entries
Reg-->>Reg: add <Nametype.component, BTreeMap> to HashMap in NamespaceProperties.name_types
Reg-->>Reg: update_entry NamespaceProperties with the changes
Reg-->>Portal: return NameTypeOutput
Portal-->>Client: return Namespace Hash
```
##### Register Name (on Rival)
```rust=
register_name(input: NameInput{}) -> ExternResult<NameOutput> {}
struct NameInput {}
struct NameOutput {}
```
```mermaid
sequenceDiagram
participant User as User
participant Portal as Registration_Portal
participant Reg as Registry_DNA
Portal-->>User: display Name Registration page
User-->>Portal: supply details
Portal-->>Reg: call `register_name(input)`
Reg-->>Reg: create NameRegistration struct (including CouponData)
Reg-->>Reg: initiate countersigning session of NameRegistration
alt majority signatures reached
Reg-->>Reg: create_entry() NameRegistration
Reg-->>Reg: ensure NamePath to create_entry()
Reg-->>Reg: link NameRegistration to NamePath
Reg-->>Portal: return NameOutput
else majority signatures not reached
Reg-->>Portal: return error: countersigning error
Portal-->>User: return error: name registration failed
end
```
##### Register Name (on client hApp)
```rust=
register_name(input: NameInput{}) -> ExternResult<NameOutput> {}
struct NameInput {}
struct NameOutput {}
```
```mermaid
sequenceDiagram
participant Portal as
participant User as Client_HApp
participant Plug as Pluggable_Zome
Portal-->>User: display NameRegistrationOutput after a successful Rival Registration
User-->>Plug: call `create_unique_name()`
Plug-->>Plug: create_entry() NameRegistrationReceipt
Plug-->>Plug: ensure NamePath to create_entry()
Plug-->>Plug: link NameRegistrationReceipt to NamePath
Plug-->>User: return NameOutput
```
##### Register Global Name (on Rival)
```rust=
register_global_name(input: NameInput{}) -> ExternResult<NameOutput> {}
struct NameInput {}
struct NameOutput {}
```
```mermaid
sequenceDiagram
participant User as User
participant Portal as Portal
participant Reg as Registry_DNA
Portal-->>User: display Name Registration page
User-->>Portal: select global option and supply details <br> (namespace and nametype should be grayed out)
Portal-->>Reg: call `register_name(input)`
Reg-->>Reg: create GlobalNameRegistration struct (including CouponData)
Reg-->>Reg: initiate countersigning session of GlobalNameRegistration
alt majority signatures reached
Reg-->>Reg: create_entry() GlobalNameRegistration
Reg-->>Reg: ensure NamePath to create_entry() %% Rival.<Handle_Component>.Name
Reg-->>Reg: link GlobalNameRegistration to NamePath
Reg-->>Portal: return NameOutput
else majority signatures not reached
Reg-->>Portal: return error: countersigning error
Portal-->>User: return name registration error
end
```
##### Register Global Name (on Client hApp)
```rust=
register_global_name(input: NameInput{}) -> ExternResult<NameOutput> {}
struct NameInput {}
struct NameOutput {}
```
```mermaid
sequenceDiagram
participant Portal as Registration_Portal
participant User as Client_HApp
participant Plug as Pluggable_Zome
Portal-->>User: display Name RegistrationOutput <br> after a successful Rival registration
User-->>Plug: call `create_unique_name()`
Plug-->>Plug: create_entry() GlobalNameRegistrationReceipt
Plug-->>Plug: ensure NamePath to create_entry()
Plug-->>Plug: link GlobalNameRegistrationReceipt to NamePath
Plug-->>User: return NameOutput
```
##### Renew Name (on Rival)
```rust=
renew_name(input: CouponInput) -> ExternResult<NameOutput> {}
struct CouponInput {}
struct NameOutput {}
```
```mermaid
sequenceDiagram
participant User as User
participant Portal as Registration_Portal
participant Reg as Registry_DNA
Portal-->>User: display Name Renewal page
User-->>Portal: supply new coupon details
Portal-->>Reg: call `renew_name(input)`
Reg-->>Reg: create NameRegistration struct (with new CouponData) and new `created` field
Reg-->>Reg: initiate countersigning session of NameRegistration
alt majority signatures reached
Reg-->>Reg: update_entry() NameRegistration
Reg-->>Portal: return NameOutput
else majority signatures not reached
Reg-->>Reg: return error: countersigning error
Reg-->>Portal: return name renewal error
end
```
##### Renew Name (on Client hApp)
```rust=
renew_name(input: CouponInput) -> ExternResult<NameOutput> {}
struct CouponInput {}
struct NameOutput {}
```
```mermaid
sequenceDiagram
participant Portal as Registration_Portal
participant User as Client_HApp
participant Plug as Pluggable_Zome
Portal-->>User: display NameRegistrationOutput <br> after a successful Rival name renewal
User-->>Plug: call `renew_unique_name(input)`
Plug-->>Plug: get_links() on NamePath
Plug-->>Plug: construct updated NameRegistrationReceipt
Plug-->>Plug: update_entry() NameRegistrationReceipt
Plug-->>User: return NameOutput
```
##### Renew Global Name (on Rival)
```rust=
renew_name(input: CouponInput) -> ExternResult<NameOutput> {}
struct CouponInput {}
struct NameOutput {}
```
```mermaid
sequenceDiagram
participant User as Client_HApp
participant Portal as Portal
participant Reg as Registry_DNA
Portal-->>User: display Name Renewal page
User-->>Portal: supply new coupon details
Portal-->>Reg: call `renew_name(input)`
Reg-->>Reg: create GlobalNameRegistration struct (including CouponData) with updated `created` field
Reg-->>Reg: add new coupon to new GlobalNameRegistration's Coupon BTreeMap
Reg-->>Reg: initiate countersigning session of GlobalNameRegistration
alt majority signatures reached
Reg-->>Reg: update_entry() GlobalNameRegistration
Reg-->>Portal: return NameOutput
else majority signatures not reached
Reg-->>Portal: return error: countersigning error
Portal-->>User: return name renewal error
end
```
##### Renew Global Name (on Client hApp)
```rust=
renew_name(input: CouponInput) -> ExternResult<NameOutput> {}
struct CouponInput {}
struct NameOutput {}
```
```mermaid
sequenceDiagram
participant User as User
participant Portal as Portal
participant Plug as Pluggable_Zome
Portal-->>User: display NameRegistrationOutput <br> after a successful Rival name renewal
User-->>Plug: call `renew_unique_name`
Plug-->>Plug: get_links() on NamePath
Plug-->>Plug: construct updated GlobalNameRegistrationReceipt
Plug-->>Plug: update_entry() GlobalNameRegistrationReceipt
Plug-->>User: return NameOutput
```
##### Get Namespaces and Nametypes (Pluggable Zome)
```rust=
get_namespaces_and_nametypes() -> ExternResult<> {}
struct NamespacesOutput<
HashMap<EntryHash, NamespaceProperties>, // NamespaceEntryHash -> Namespace
HashMap<EntryHash, Vec<EntryHash>>, // NamespaceEntryHash -> Vec<NametypeEntryHash>
HashMap<EntryHash, NameType> // NametypeEntryHash -> NameType
>
```
```mermaid
sequenceDiagram
participant UI as Reusable_UI_Components
participant Node as Read_Only_API_Node
participant Reg as Registry_DNA
UI-->>Node: call `get_namespaces_and_nametypes()`
Node-->>Node: initialize empty NamespacesOutput HashMap
Node-->>Reg: get_links on path hash_entry("all_namespaces")
Reg-->>Node: return links
loop for every link in links
Node-->>Reg: call get() on link
Reg-->>Node: return NamespaceEntry
Node-->>Reg: call get_links() on NamespaceEntry <br> with tag "metadata"
Reg-->>Node: return NamespacePropertiesEntry
Node-->>Node: add (hash(NamespacePropertiesEntry), NamespaceProperties) to HashMap
loop for every component on NamespacePropertiesEntry.Nametypes
Node-->>Reg: call get() on NamespacesPropertiesEntry.Nametypes[component][latest_version]
Reg-->>Node: return NameTypeEntry
Node-->>Node: add hash(NameTypeEntry) to the vector value <br> in NamespaceOutput[NamespaceEntryHash]
Node-->>Node: add (hash(NameTypeEntry), NameType) to NamespacesOutput
end
end
Node-->>UI: return NamespacesOutput
```
##### Get Namespaces
```rust=
get_namespaces() -> ExternResult<> {}
struct NamespacesOutput<
HashMap<EntryHash, NamespaceProperties> // NamespaceEntryHash -> Namespace
>
```
```mermaid
sequenceDiagram
participant UI as Reusable_UI_Components
participant Node as Read_Only_API_Node
participant Reg as Registry_DNA
UI-->>Node: call `get_namespaces()`
Node-->>Node: initialize empty NamespacesOutput HashMap
Node-->>Reg: get_links() on path hash_entry("all_namespaces")
Reg-->>Node: return links
loop for every link in links
Node-->>Reg: call get() on link
Reg-->>Node: return NamespaceEntry
Node-->>Reg: call get_links() on NamespaceEntry <br> with tag "metadata"
Reg-->>Node: return NamespacePropertiesEntry
Node-->>Node: add (hash(NamespacePropertiesEntry), NamespaceProperties) to HashMap
end
Node-->>UI: return NamespacesOutput
```
##### Get NameTypes
```rust=
get_nametypes() -> ExternResult<> {}
struct NameTypesOutput<
HashMap<EntryHash, Vec<EntryHash>>, // NamespaceEntryHash -> Vec<NametypeEntryHash>
HashMap<EntryHash, NameType> // NametypeEntryHash -> NameType
>
```
```mermaid
sequenceDiagram
participant UI as Reusable_UI_Components
participant Node as Read_Only_API_Node
participant Reg as Registry_DNA
UI-->>Node: call `get_nametypes()`
Node-->>Reg: call `get_nametypes()`
Reg-->>Reg: get_links() on namespace hash using tag "metadata"
Reg-->>Reg: get() on link[0].target to get NamespaceProperties
loop for every component on NamespacePropertiesEntry.Nametypes
Node-->>Reg: call get() on NamespacesPropertiesEntry.Nametypes[component][latest_version]
Reg-->>Node: return NameTypeEntry
Node-->>Node: add hash(NameTypeEntry) to the vector value <br> in NamespaceOutput[NamespaceEntryHash]
Node-->>Node: add (hash(NameTypeEntry), NameType) to NamespacesOutput
end
Node-->>UI: return NameTypesOutput
```
##### Get NameRegistration
```rust=
get_name_registration() -> ExternResult<> {}
NameOutput {}
```
```mermaid
sequenceDiagram
participant Client as Client_HApp
participant Plug as Pluggable_Zome
participant Reg as Registry_DNA
Client-->>Plug: call `get_name_registration()`
Plug-->>Plug: construct NamePath
Plug-->>Reg: call `get_name_registration()`
Reg-->>Reg: get_links() on input.path
Reg-->>Reg: get() links[0].target
Reg-->>Plug: return NameRegistration
Plug-->>Client: return NameRegistration
```
##### Verify Coupon
```rust
verify_coupon(coupon_data) -> ExternResult<bool> {}
```
```mermaid
sequenceDiagram
participant User as User
participant Reg as Registry_DNA
User-->>Reg: perform a transaction requiring a coupon
Reg-->>Reg: get pubkey from DNA properties
Reg-->>Reg: call verify_signature() where key=public key from props
alt verify_signature returns true
Reg-->>Reg: proceed with transaction
Reg-->>User: return result of transaction
else verify_signature returns false
Reg-->>User: return error ask for a different coupon
end
```