Skip to content

Instantly share code, notes, and snippets.

@LifeMoroz
Created August 7, 2023 13:28
Show Gist options
  • Save LifeMoroz/352c87f65273a171248da0bfc0dd4baf to your computer and use it in GitHub Desktop.
Save LifeMoroz/352c87f65273a171248da0bfc0dd4baf to your computer and use it in GitHub Desktop.
Nekoton get pubkey by account
import asyncio
from nekoton import JrpcTransport, Address, PublicKey, Cell
def get_rpc(blockchain) -> JrpcTransport:
rpc = {
1: "https://jrpc.everwallet.net/rpc",
2: "https://jrpc-testnet.venom.foundation/rpc",
}[blockchain]
return JrpcTransport(rpc)
WALLET_V3 = bytes(
[
0x84,
0xDA,
0xFA,
0x44,
0x9F,
0x98,
0xA6,
0x98,
0x77,
0x89,
0xBA,
0x23,
0x23,
0x58,
0x07,
0x2B,
0xC0,
0xF7,
0x6D,
0xC4,
0x52,
0x40,
0x02,
0xA5,
0xD0,
0x91,
0x8B,
0x9A,
0x75,
0xD2,
0xD5,
0x99,
]
)
WALLET_HIGHLOAD = bytes(
[
0x0B,
0x3A,
0x88,
0x7A,
0xEA,
0xCD,
0x2A,
0x7D,
0x40,
0xBB,
0x55,
0x50,
0xBC,
0x92,
0x53,
0x15,
0x6A,
0x02,
0x90,
0x65,
0xAE,
0xFB,
0x6D,
0x6B,
0x58,
0x37,
0x35,
0xD5,
0x8D,
0xA9,
0xD5,
0xBE,
]
)
def is_v3(code_hash):
return code_hash == WALLET_V3
def is_highload(code_hash):
return code_hash == WALLET_HIGHLOAD
async def get_pubkey(rpc: JrpcTransport, addr: str):
addr = Address(addr)
state = await rpc.get_account_state(addr)
code_hash = state.state_init.code_hash
cell = Cell().to_bytes()
if is_v3(code_hash):
return PublicKey.from_bytes(state.state_init.data.to_bytes()[len(cell) + 8 : len(cell) + 8 + 32])
elif is_highload(code_hash):
return PublicKey.from_bytes(state.state_init.data.to_bytes()[len(cell) + 12 : len(cell) + 12 + 32])
else:
return PublicKey.from_bytes(state.state_init.data.to_bytes()[len(cell) : len(cell) + 32])
async def test():
rpc = get_rpc(1) # Everscale
for addr, pub_key in (
(
"0:2da916f0a98b244206236d355e2bff3974d3212472704e8f636b7981c2a4bbda",
"b193327327cb94f8ba1cefad47e23ef59933f63b08dbb96f017e752b3644dc5e",
), # Everwallet
(
"0:ab91c8cec44aa6e3b2c31443202a63241394491f0e41215a30620b57ef28b69b",
"c2838cf1cdd104859ea0fa434e10aa8a592dc04c2cc0c20c2afef21bcd428eb3",
), # Highload
(
"0:8e2586602513e99a55fa2be08561469c7ce51a7d5a25977558e77ef2bc9387b4",
"f1dae34f0bfadc8f9a3d304bb4c50b53ecee10c48098ef23e40d34aa2cd45f35",
), # v3
(
"0:df2808cda59284706e3ba7b10b03d579262a8338423fcaa9ed4addc24bed99e4",
"1c39cada9fc92218cb9789484d59d1d654e74f612a4e6fd8072236689ed546a7",
), # multisig
):
assert (await get_pubkey(rpc, addr)).encode("hex") == pub_key
print("Ok")
if __name__ == "__main__":
asyncio.run(test())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment