MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / to_account_secure

Function to_account_secure

sdk/python/src/dstack_sdk/ethereum.py:46–66  ·  view source on GitHub ↗

Create an Ethereum account using SHA256 of full key material for security.

(
    get_key_response: GetKeyResponse | GetTlsKeyResponse,
)

Source from the content-addressed store, hash-verified

44
45
46def to_account_secure(
47 get_key_response: GetKeyResponse | GetTlsKeyResponse,
48) -> LocalAccount:
49 """Create an Ethereum account using SHA256 of full key material for security."""
50 if isinstance(get_key_response, GetTlsKeyResponse):
51 warnings.warn(
52 "to_account_secure: Please don't use getTlsKey method to get key, use getKey instead.",
53 DeprecationWarning,
54 stacklevel=2,
55 )
56 try:
57 # Hash the complete key material with SHA256
58 key_bytes = get_key_response.as_uint8array()
59 hashed_key = hashlib.sha256(key_bytes).digest()
60 return Account.from_key(hashed_key) # type: ignore[no-any-return]
61 except Exception as e:
62 raise RuntimeError(
63 "to_account_secure: missing SHA256 support, please upgrade your system"
64 ) from e
65 else: # GetKeyResponse
66 return Account.from_key(get_key_response.decode_key()) # type: ignore[no-any-return]

Callers 4

mainFunction · 0.90

Calls 3

as_uint8arrayMethod · 0.80
digestMethod · 0.45
decode_keyMethod · 0.45

Tested by 4

mainFunction · 0.72