Skip to content

Commit

Permalink
Add getSigner as possible entrypoint for public key
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementWalter committed Apr 6, 2023
1 parent f31d7eb commit 149037e
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions scripts/utils/starknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,29 +117,28 @@ async def get_starknet_account(
) -> Account:
address = int(address or ACCOUNT_ADDRESS, 16)
key_pair = KeyPair.from_private_key(int(private_key or PRIVATE_KEY, 16))
try:
call = Call(
to_addr=address,
selector=get_selector_from_name("get_public_key"),
calldata=[],
)
public_key = await GATEWAY_CLIENT.call_contract(call=call, block_hash="pending")
except Exception as err:
if (
json.loads(re.findall("{.*}", err.args[0], re.DOTALL)[0])["code"]
== "StarknetErrorCode.ENTRY_POINT_NOT_FOUND_IN_CONTRACT"
):

public_key = None
for selector in ["get_public_key", "getPublicKey", "getSigner"]:
try:
call = Call(
to_addr=address,
selector=get_selector_from_name("getPublicKey"),
selector=get_selector_from_name(selector),
calldata=[],
)
public_key = await GATEWAY_CLIENT.call_contract(
call=call, block_hash="pending"
)
else:
raise err
if key_pair.public_key != public_key[0]:
public_key = (
await GATEWAY_CLIENT.call_contract(call=call, block_hash="pending")
)[0]
except Exception as err:
if (
json.loads(re.findall("{.*}", err.args[0], re.DOTALL)[0])["code"]
== "StarknetErrorCode.ENTRY_POINT_NOT_FOUND_IN_CONTRACT"
):
continue
else:
raise err

if key_pair.public_key != public_key:
raise ValueError(
f"Public key of account 0x{address:064x} is not consistent with provided private key"
)
Expand Down

0 comments on commit 149037e

Please sign in to comment.