# third party
from sqlalchemy.orm import Session

# syft absolute
from syft.core.node.common.node_service.node_setup.node_setup_messages import (
    CreateInitialSetUpMessage,
)

# grid absolute
from grid.core.config import settings
from grid.core.node import node
from grid.db import base  # noqa: F401


def init_db(db: Session) -> None:

    # Build Syft Message
    msg = CreateInitialSetUpMessage(
        address=node.address,
        name="Jane Doe",
        email=settings.FIRST_SUPERUSER,
        password=settings.FIRST_SUPERUSER_PASSWORD,
        domain_name=settings.DOMAIN_NAME,
        budget=55.55,
        reply_to=node.address,
    ).sign(signing_key=node.signing_key)

    # Process syft message
    _ = node.recv_immediate_msg_with_reply(msg=msg).message

@@ -7,16 +7,89 @@
 d party%0A
+from nacl.encoding import HexEncoder%0Afrom nacl.signing import SigningKey%0A
 from sql
@@ -407,17 +407,89 @@
 %3E None:%0A
-%0A
+    if not len(node.setup):  # Check if setup was defined previously%0A    
     # Bu
@@ -501,24 +501,28 @@
 yft Message%0A
+    
     msg = Cr
@@ -554,16 +554,20 @@
         
+   
+ 
 address=
@@ -588,16 +588,20 @@
         
+    
 name=%22Ja
@@ -617,16 +617,20 @@
         
+  
+  
 email=se
@@ -653,16 +653,20 @@
 ERUSER,%0A
+    
         
@@ -717,16 +717,20 @@
         
+ 
+   
 domain_n
@@ -755,16 +755,20 @@
 N_NAME,%0A
+    
         
@@ -789,16 +789,20 @@
         
+    
 reply_to
@@ -820,16 +820,20 @@
 ss,%0A    
+   
+ 
 ).sign(s
@@ -862,16 +862,20 @@
 g_key)%0A%0A
+    
     # Pr
@@ -897,16 +897,20 @@
 age%0A    
+  
+  
 _ = node
@@ -949,16 +949,356 @@
 sg=msg).message%0A
+%0A    else:  # Uses the Owner root key to update node keys%0A        owner = node.users.first(role=node.roles.owner_role.id)%0A        root_key = SigningKey(owner.private_key.encode(%22utf-8%22), encoder=HexEncoder)%0A        node.signing_key = root_key%0A        node.verify_key = root_key.verify_key%0A        node.root_verify_key = root_key.verify_key%0A

Fix init_db to sync the node/owner keys