@@ -42,6 +42,7 @@ def cat_id_for_role(self, role_id: RoleID) -> (str, str):
4242 role_id ,
4343 role_0_pk ,
4444 role_data ["rotation" ],
45+ True ,
4546 ),
4647 role_data ["sk" ],
4748 )
@@ -63,18 +64,22 @@ def __rbac_chain_factory(role_id: RoleID) -> RBACChain:
6364
6465
6566def generate_cat_id (
66- network : str , subnet : str , role_id : RoleID , pk_hex : str , rotation : int
67+ network : str , subnet : str , role_id : RoleID , pk_hex : str , rotation : int , is_uri : bool
6768):
6869 pk = bytes .fromhex (pk_hex )[:32 ]
69- prefix = "catid.:"
7070 nonce = int (datetime .now (timezone .utc ).timestamp ())
7171 subnet = f"{ subnet } ." if subnet else ""
7272 role0_pk_b64 = base64_url (pk )
7373
7474 if role_id == RoleID .ROLE_0 and rotation == 0 :
75- return f"{ prefix } { nonce } @{ subnet } { network } /{ role0_pk_b64 } "
75+ res = f"{ nonce } @{ subnet } { network } /{ role0_pk_b64 } "
76+ else :
77+ res = f"{ nonce } @{ subnet } { network } /{ role0_pk_b64 } /{ role_id } /{ rotation } "
7678
77- return f"{ prefix } { nonce } @{ subnet } { network } /{ role0_pk_b64 } /{ role_id } /{ rotation } "
79+ if is_uri :
80+ res = f"id.catalyst://{ res } "
81+
82+ return res
7883
7984
8085def generate_rbac_auth_token (
@@ -90,13 +95,14 @@ def generate_rbac_auth_token(
9095 bip32_ed25519_sk = BIP32ED25519PrivateKey (sk , chain_code )
9196 bip32_ed25519_pk = BIP32ED25519PublicKey (pk , chain_code )
9297
93- cat_id = generate_cat_id (network , subnet , RoleID .ROLE_0 , pk_hex , 0 )
98+ token_prefix = "catid.:"
99+ cat_id = generate_cat_id (network , subnet , RoleID .ROLE_0 , pk_hex , 0 , False )
94100
95101 signature = bip32_ed25519_sk .sign (cat_id .encode ())
96102 bip32_ed25519_pk .verify (signature , cat_id .encode ())
97103 signature_b64 = base64_url (signature )
98104
99- return f"{ cat_id } .{ signature_b64 } "
105+ return f"{ token_prefix } { cat_id } .{ signature_b64 } "
100106
101107
102108def base64_url (data : bytes ) -> str :
0 commit comments