Skip to content

Commit

Permalink
Move VA network RPC variable to config
Browse files Browse the repository at this point in the history
  • Loading branch information
Alladin9393 committed Aug 7, 2022
1 parent 1b478dc commit db00818
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ If you just want to start a single instance of the app and run it directly::
password_providers:
- module: "synapse.handlers.vaccount_auth.VaccountAuthProvider"
config:
NETWORK_PRC_URI: "https://api.velas.com"
REDIS_HOSTNAME: "redis"
REDIS_PASS: "development"
REDIS_REPLICATION_MODE: "master"
Expand Down
8 changes: 6 additions & 2 deletions synapse/handlers/vaccount_auth/auth_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
from hashlib import sha256

from twisted.internet import defer
from solana.rpc.api import Client
from solana.publickey import PublicKey
from nacl.signing import VerifyKey
from nacl.exceptions import BadSignatureError
from redis import Redis

import logging

from synapse.handlers.vaccount_auth.constants import SIGN_TIMESTAMP_TOLERANCE, OPERATIONAL_STATE
from synapse.handlers.vaccount_auth.constants import SIGN_TIMESTAMP_TOLERANCE, OPERATIONAL_STATE, TESTNET_PRC_URI
from synapse.handlers.vaccount_auth.utils import VaccountInfo, get_vaccount_evm_address
from synapse.api.errors import HttpResponseException
from synapse.handlers.vaccount_auth.utils import is_valid_vaccount_address
Expand All @@ -48,6 +49,9 @@ class VaccountAuthProvider:
def __init__(self, config, account_handler: ModuleApi):
self.account_handler = account_handler
self.store: DataStore = account_handler._hs.get_datastore()
self.velas_client = Client(
endpoint=config.get('NETWORK_PRC_URI', TESTNET_PRC_URI),
)
self.redis = Redis(
host=config.get('REDIS_HOSTNAME'),
port=config.get('REDIS_PORT'),
Expand Down Expand Up @@ -215,7 +219,7 @@ async def register_user(self, localpart, displayname):
async def _is_active_vaccount(self, vaccount_address: PublicKey, signer: PublicKey, signer_type: str) -> bool:
"""
"""
vaccount_info = VaccountInfo(vaccount_address)
vaccount_info = VaccountInfo(vaccount_address, self.velas_client)

if vaccount_info.is_ephemeral():
return is_valid_vaccount_address(signer, vaccount_address)
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/vaccount_auth/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

VACCOUNT_PROGRAM_ID = PublicKey("VAcccHVjpknkW5N5R9sfRppQxYJrJYVV7QJGKchkQj5")
VACCOUNT_SEED = b'vaccount'
VELAS_RPC_URI = 'https://api.testnet.velas.com'
TESTNET_PRC_URI = 'https://api.testnet.velas.com'
BASE_OPERATIONAL_LEN = 134

SIGN_TIMESTAMP_TOLERANCE = 120
Expand Down
5 changes: 2 additions & 3 deletions synapse/handlers/vaccount_auth/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
VACCOUNT_PROGRAM_ID,
VACCOUNT_SEED,
VACCOUNT_INFO,
VELAS_RPC_URI,
OPERATIONAL_INFO,
)

Expand Down Expand Up @@ -48,7 +47,7 @@ def is_valid_vaccount_address(genesis_key_seed: PublicKey, vaccount_id: PublicKe
return False


def find_vaccount_address(genesis_key_seed: PublicKey) -> [Tuple[PublicKey, int], None]:
def find_vaccount_address(genesis_key_seed: PublicKey) -> Union[Tuple[PublicKey, int], None]:
"""Find valid `Vaccount` address.
Valid `Vaccount` addresses must fall off the ed25519 curve. This function
Expand Down Expand Up @@ -113,7 +112,7 @@ def get_vaccount_evm_address(vaccount_address: PublicKey) -> str:
class VaccountInfo:
"""Parsed representing Vaccount information"""

def __init__(self, vaccount_pubkey: Union[PublicKey, bytearray, bytes, int, str, List[int]], client=Client(VELAS_RPC_URI)):
def __init__(self, vaccount_pubkey: Union[PublicKey, bytearray, bytes, int, str, List[int]], client: Client):
self.client = client
self.pubkey = vaccount_pubkey if isinstance(vaccount_pubkey, PublicKey) else PublicKey(vaccount_pubkey)
self.version = None
Expand Down

0 comments on commit db00818

Please sign in to comment.