Skip to content

Commit 7787bd5

Browse files
committed
feat(project): add admin account validation
1 parent 9c23f02 commit 7787bd5

5 files changed

Lines changed: 502 additions & 255 deletions

File tree

libsimba/simba.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# THE SOFTWARE.
2020
import asyncio
2121
import base64
22+
import json
2223
import logging
2324

2425
from typing import Any, AsyncGenerator, List, Optional, Tuple, Union
@@ -1489,3 +1490,83 @@ async def admin_create_account(
14891490
endpoint=Path.ADMIN_ACCOUNTS,
14901491
login=login,
14911492
).send(config=config, json_payload=payload, headers=headers or {})
1493+
1494+
async def admin_account_sign(
1495+
self,
1496+
network: str,
1497+
alias: str,
1498+
owner_identifier: str,
1499+
owner_type: str,
1500+
input_pairs: List[Tuple[str, Any]],
1501+
hash_message: Optional[bool] = False,
1502+
user_identifier: Optional[str] = None,
1503+
user_type: Optional[str] = None,
1504+
headers: Optional[dict] = None,
1505+
login: Login = None,
1506+
config: ConnectionConfig = None,
1507+
) -> dict:
1508+
if owner_type == "Organisation" and (not user_identifier or not user_type):
1509+
raise ValueError("Owner is an org but user or user type is not given.")
1510+
payload = {
1511+
"account": {
1512+
"identifier": {
1513+
"type": "Alias",
1514+
"value": alias
1515+
},
1516+
"owner": {
1517+
"type": owner_type,
1518+
"identifier": owner_identifier
1519+
}
1520+
},
1521+
"data": {
1522+
"input_pairs": [list(t) for t in input_pairs],
1523+
"hash_message": hash_message,
1524+
}
1525+
}
1526+
if owner_type == "Organisation":
1527+
payload["account"]["user"] = {
1528+
"type": user_type,
1529+
"identifier": user_identifier
1530+
}
1531+
return await SimbaRequest(
1532+
method="POST",
1533+
endpoint=Path.ADMIN_BLOCKCHAIN_SIGN.create(network),
1534+
login=login,
1535+
).send(config=config, json_payload=payload, headers=headers or {})
1536+
1537+
async def admin_account_validate(
1538+
self,
1539+
network: str,
1540+
alias: str,
1541+
owner_identifier: str,
1542+
owner_type: str,
1543+
user_identifier: Optional[str] = None,
1544+
user_type: Optional[str] = None,
1545+
headers: Optional[dict] = None,
1546+
login: Login = None,
1547+
config: ConnectionConfig = None,
1548+
) -> dict:
1549+
if owner_type == "Organisation" and (not user_identifier or not user_type):
1550+
raise ValueError("Owner is an org but user or user type is not given.")
1551+
payload = {
1552+
"account": {
1553+
"identifier": {
1554+
"type": "Alias",
1555+
"value": alias
1556+
},
1557+
"owner": {
1558+
"type": owner_type,
1559+
"identifier": owner_identifier
1560+
}
1561+
}
1562+
}
1563+
if owner_type == "Organisation":
1564+
payload["account"]["user"] = {
1565+
"type": user_type,
1566+
"identifier": user_identifier
1567+
}
1568+
return await SimbaRequest(
1569+
method="POST",
1570+
endpoint=Path.ADMIN_BLOCKCHAIN_VALIDATE.create(network),
1571+
login=login,
1572+
).send(config=config, json_payload=payload, headers=headers or {})

libsimba/simba_sync.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2811,3 +2811,139 @@ def admin_create_account(
28112811
endpoint=Path.ADMIN_ACCOUNTS,
28122812
login=login,
28132813
).send_sync(config=config, json_payload=payload, headers=headers or {})
2814+
2815+
def admin_account_sign(
2816+
self,
2817+
network: str,
2818+
alias: str,
2819+
owner_identifier: str,
2820+
owner_type: str,
2821+
input_pairs: List[Tuple[str, Any]],
2822+
hash_message: Optional[bool] = False,
2823+
user_identifier: Optional[str] = None,
2824+
user_type: Optional[str] = None,
2825+
headers: Optional[dict] = None,
2826+
login: Login = None,
2827+
config: ConnectionConfig = None,
2828+
) -> dict:
2829+
"""
2830+
POST ``/admin/blockchain/{name}/sign/``
2831+
2832+
Sign on behalf of a user.
2833+
2834+
:param network: The blockchain name.
2835+
:type network: str
2836+
:param alias: The account alias.
2837+
:type alias: str
2838+
:param owner_identifier: The account owner.
2839+
:type owner_identifier: str
2840+
:param owner_type: The account owner type. One of User or Organisation.
2841+
:type owner_type: str
2842+
:param user_identifier: The requesting user.
2843+
:type user_identifier: str
2844+
:param user_type: The requesting user type. One of User or SimbaIdentity. Required if owner is an organisation.
2845+
:type user_type: Optional[str]
2846+
:param input_pairs: A list of tuples defining the data type and data to sign.
2847+
:type input_pairs: List[Tuple(str, Any)]
2848+
:param hash_message: Whether to hash the message before signing or not
2849+
:type hash_message: Optional[bool]. Default False
2850+
2851+
:Keyword Arguments:
2852+
* **headers** (`Optional[dict]`) - additional http headers
2853+
* **login** (`Optional[Login]`)
2854+
* **config** (`Optional[ConnectionConfig]`)
2855+
:return: a signed data structure.
2856+
:rtype: dict
2857+
"""
2858+
if owner_type == "Organisation" and (not user_identifier or not user_type):
2859+
raise ValueError("Owner is an org but user or user type is not given.")
2860+
payload = {
2861+
"account": {
2862+
"identifier": {
2863+
"type": "Alias",
2864+
"value": alias
2865+
},
2866+
"owner": {
2867+
"type": owner_type,
2868+
"identifier": owner_identifier
2869+
}
2870+
},
2871+
"data": {
2872+
"input_pairs": [list(t) for t in input_pairs],
2873+
"hash_message": hash_message,
2874+
}
2875+
}
2876+
if owner_type == "Organisation":
2877+
payload["account"]["user"] = {
2878+
"type": user_type,
2879+
"identifier": user_identifier
2880+
}
2881+
return SimbaRequest(
2882+
method="POST",
2883+
endpoint=Path.ADMIN_BLOCKCHAIN_SIGN.create(network),
2884+
login=login,
2885+
).send_sync(config=config, json_payload=payload, headers=headers or {})
2886+
2887+
def admin_account_validate(
2888+
self,
2889+
network: str,
2890+
alias: str,
2891+
owner_identifier: str,
2892+
owner_type: str,
2893+
user_identifier: Optional[str] = None,
2894+
user_type: Optional[str] = None,
2895+
headers: Optional[dict] = None,
2896+
login: Login = None,
2897+
config: ConnectionConfig = None,
2898+
) -> dict:
2899+
"""
2900+
POST ``/admin/blockchain/{name}/validate/``
2901+
2902+
Validate the user has access to the given wallet.
2903+
2904+
:param network: The blockchain name.
2905+
:type network: str
2906+
:param alias: The account alias.
2907+
:type alias: str
2908+
:param owner_identifier: The account owner.
2909+
:type owner_identifier: str
2910+
:param owner_type: The account owner type. One of User or Organisation.
2911+
:type owner_type: str
2912+
:param user_identifier: The requesting user.
2913+
:type user_identifier: str
2914+
:param user_type: The requesting user type. One of User or SimbaIdentity. Required if owner is an organisation.
2915+
:type user_type: Optional[str]
2916+
2917+
:Keyword Arguments:
2918+
* **headers** (`Optional[dict]`) - additional http headers
2919+
* **login** (`Optional[Login]`)
2920+
* **config** (`Optional[ConnectionConfig]`)
2921+
:return: a signed data structure.
2922+
:rtype: dict
2923+
"""
2924+
if owner_type == "Organisation" and (not user_identifier or not user_type):
2925+
raise ValueError("Owner is an org but user or user type is not given.")
2926+
payload = {
2927+
"account": {
2928+
"identifier": {
2929+
"type": "Alias",
2930+
"value": alias
2931+
},
2932+
"owner": {
2933+
"type": owner_type,
2934+
"identifier": owner_identifier
2935+
}
2936+
}
2937+
}
2938+
if owner_type == "Organisation":
2939+
payload["account"]["user"] = {
2940+
"type": user_type,
2941+
"identifier": user_identifier
2942+
}
2943+
return SimbaRequest(
2944+
method="POST",
2945+
endpoint=Path.ADMIN_BLOCKCHAIN_VALIDATE.create(network),
2946+
login=login,
2947+
).send_sync(config=config, json_payload=payload, headers=headers or {})
2948+
2949+

libsimba/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class Path(str, Enum):
5959
USER_FUND_ADDRESS = "/user/account/{}/fund/"
6060
USER_ADDRESS_BALANCE = "/user/account/{}/balance/{}/"
6161
ADMIN_WALLET_SET = "/admin/users/{}/wallet/set/"
62+
ADMIN_BLOCKCHAIN_SIGN = "/admin/blockchain/{}/sign/"
63+
ADMIN_BLOCKCHAIN_VALIDATE = "/admin/blockchain/{}/validate/"
6264
USER_WALLET_SET = "/user/wallet/set/"
6365
USER_WALLET = "/user/wallet/"
6466
USER_ACCOUNTS = "/user/accounts/"

0 commit comments

Comments
 (0)