示例#1
0
def register_interchain_auth_v1(
        chain_registration_body: Dict[str, str]) -> None:
    dcid = chain_registration_body["dcid"]
    key = chain_registration_body["key"]
    signature = chain_registration_body["signature"]

    # Initialize keys with chain id as public key (dont need to pull from matchmaking)
    requester_keys = keys.DCKeys(pull_keys=False).initialize(
        public_key_string=dcid, hash_type="sha256")

    if not requester_keys.check_signature(
            f"{keys.get_public_id()}_{key}".encode("utf-8"), signature):
        _log.info(
            f"invalid signature for interchain key registration from {dcid}")
        raise exceptions.UnauthorizedException(
            "Invalid signature authorization")

    # Authorization successful, now register actual key
    auth_key = api_key_model.new_from_scratch(interchain_dcid=dcid)
    auth_key.key = key
    try:
        api_key_dao.save_api_key(auth_key)
    except Exception:
        _log.exception("Error saving interchain auth key")
        raise RuntimeError("Authorization registration failure")

    _log.info(f"successfully registered interchain auth key with {dcid}")
示例#2
0
 def sign_transaction(self, raw_transaction: Dict[str, Any]) -> str:
     """Sign a transaction for this network
     Args:
         amount (int): amount of token in transaction
         to_address (str): hex of the address to send to
         symbol (str, optional): the exchange symbol for the token (defaults to 'BNB')
         memo (str, optional): string of data to publish in the transaction (defaults to '')
     Returns:
         String of the signed transaction as base64
     """
     built_transaction = self._build_transaction_msg(raw_transaction)
     try:
         if self.testnet:
             tx = TestBnbTransaction.from_obj(built_transaction)
         else:  # mainnet
             tx = BnbTransaction.from_obj(built_transaction)
         _log.info(
             f"[BINANCE] Signing raw transaction: {tx.signing_json()}")
         mykeys = keys.DCKeys(pull_keys=False)
         mykeys.initialize(private_key_string=self.b64_private_key)
         signature = base64.b64decode(
             mykeys.make_binance_signature(content=tx.signing_json()))
         tx.apply_sig(signature, self.pub.serialize(compressed=True))
         signed_transaction_bytes = tx.encode()
         # signed_transaction expected to be base64, not hex:
         return base64.b64encode(signed_transaction_bytes).decode("ascii")
     except Exception as e:
         raise exceptions.BadRequest(
             f"[BINANCE] Error signing transaction: {e}")
示例#3
0
def get_verifying_keys(chain_id: str) -> keys.DCKeys:
    _log.info("[L2] Getting L1's verifying keys")
    return keys.DCKeys(chain_id)
def get_verifying_keys(chain_id: str) -> keys.DCKeys:
    return keys.DCKeys(chain_id)