async def test_get_base_url_and_compliance_key(client: AsyncClient): faucet = Faucet(client) parent_vasp, child_vasp = await faucet.gen_vasp(base_url="http://hello.com") base_url, key = await client.get_base_url_and_compliance_key(child_vasp.account_address) assert base_url == "http://hello.com" assert utils.public_key_bytes(key) == parent_vasp.compliance_public_key_bytes base_url, key = await client.get_base_url_and_compliance_key(parent_vasp.account_address) assert base_url == "http://hello.com" assert utils.public_key_bytes(key) == parent_vasp.compliance_public_key_bytes
def test_get_base_url_and_compliance_key(): client = testnet.create_client() parent_vasp = testnet.gen_account(client, base_url="http://hello.com") child_vasp = testnet.gen_child_vasp(client, parent_vasp) base_url, key = client.get_base_url_and_compliance_key( child_vasp.account_address) assert base_url == "http://hello.com" assert utils.public_key_bytes( key) == parent_vasp.compliance_public_key_bytes base_url, key = client.get_base_url_and_compliance_key( parent_vasp.account_address) assert base_url == "http://hello.com" assert utils.public_key_bytes( key) == parent_vasp.compliance_public_key_bytes
def init_compliance_keys(self) -> jsonrpc.Transaction: self.compliance_key = Ed25519PrivateKey.generate() txn = self.create_transaction( self._parent_vasp, stdlib.encode_rotate_dual_attestation_info_script( new_url=b"http://helloworld.org", new_key=utils.public_key_bytes(self.compliance_key.public_key()) ), testnet.TEST_CURRENCY_CODE, ) return self.submit_and_wait(self._parent_vasp.sign(txn))
def main(): print("#1 connect to testnet") client = testnet.create_client() print("#2 Generate Keys") # generate private key for sender account sender_private_key = Ed25519PrivateKey.generate() # generate auth key for sender account sender_auth_key = AuthKey.from_public_key(sender_private_key.public_key()) print( f"Generated sender address: {utils.account_address_hex(sender_auth_key.account_address())}" ) print("#3 Create account") faucet = testnet.Faucet(client) testnet.Faucet.mint(faucet, sender_auth_key.hex(), 100000000, CURRENCY) print("#4 Get account information") sender_account = client.get_account(sender_auth_key.account_address()) events_key = sender_account.received_events_key print("#5 Start event listener") get_events_example.subscribe(client, events_key) print("#6 Add money to account") faucet = testnet.Faucet(client) testnet.Faucet.mint(faucet, sender_auth_key.hex(), 10000000, CURRENCY) print("#7 Generate Keys") # generate private key for receiver account receiver_private_key = Ed25519PrivateKey.generate() # generate auth key for receiver account receiver_auth_key = AuthKey.from_public_key( receiver_private_key.public_key()) print( f"Generated receiver address: {utils.account_address_hex(receiver_auth_key.account_address())}" ) print("#8 Create second account") faucet = testnet.Faucet(client) testnet.Faucet.mint(faucet, receiver_auth_key.hex(), 1000000, CURRENCY) print("#9 Generate IntentIdentifier") account_identifier = identifier.encode_account( utils.account_address_hex(receiver_auth_key.account_address()), None, identifier.TDM) encoded_intent_identifier = identifier.encode_intent( account_identifier, CURRENCY, 10000000) print(f"Encoded IntentIdentifier: {encoded_intent_identifier}") print("#10 Deserialize IntentIdentifier") intent_identifier = identifier.decode_intent(encoded_intent_identifier, identifier.TDM) print( f"Account (HEX) from intent: {utils.account_address_hex(intent_identifier.account_address)}" ) print(f"Amount from intent: {intent_identifier.amount}") print(f"Currency from intent: {intent_identifier.currency_code}") print("#11 Peer 2 peer transaction") # create script script = stdlib.encode_peer_to_peer_with_metadata_script( currency=utils.currency_code(intent_identifier.currency_code), payee=intent_identifier.account_address, amount=intent_identifier.amount, metadata=b'', # no requirement for metadata and metadata signature metadata_signature=b'', ) # create transaction raw_transaction = diem_types.RawTransaction( sender=sender_auth_key.account_address(), sequence_number=sender_account.sequence_number, payload=diem_types.TransactionPayload__Script(script), max_gas_amount=1_000_000, gas_unit_price=0, gas_currency_code=CURRENCY, expiration_timestamp_secs=int(time.time()) + 30, chain_id=testnet.CHAIN_ID, ) # sign transaction signature = sender_private_key.sign( utils.raw_transaction_signing_msg(raw_transaction)) public_key_bytes = utils.public_key_bytes(sender_private_key.public_key()) signed_txn = utils.create_signed_transaction(raw_transaction, public_key_bytes, signature) # submit transaction client.submit(signed_txn) # wait for transaction client.wait_for_transaction(signed_txn)
def compliance_public_key_bytes(self) -> bytes: pub = self.offchain_compliance_key().get_public() return utils.public_key_bytes(pub)
def compliance_public_key_bytes(self) -> bytes: return utils.public_key_bytes( self.compliance_private_key().public_key())
exit() compliance_private_key = Ed25519PrivateKey.generate() GW_PORT = os.getenv("GW_PORT", 8080) ENV_FILE_NAME = os.getenv("ENV_FILE_NAME", ".env") LIQUIDITY_SERVICE_HOST = os.getenv("LIQUIDITY_SERVICE_HOST", "liquidity") LIQUIDITY_SERVICE_PORT = os.getenv("LIQUIDITY_SERVICE_PORT", 5000) JSON_RPC_URL = os.getenv("JSON_RPC_URL", "https://testnet.diem.com/v1") FAUCET_URL = os.getenv("FAUCET_URL", "https://testnet.diem.com/mint") CHAIN_ID = int(os.getenv("CHAIN_ID", testnet.CHAIN_ID.value)) OFFCHAIN_SERVICE_PORT: int = int(os.getenv("OFFCHAIN_SERVICE_PORT", 8091)) VASP_BASE_URL = os.getenv("VASP_BASE_URL", "http://0.0.0.0:8091") VASP_COMPLIANCE_KEY = utils.private_key_bytes(compliance_private_key).hex() VASP_PUBLIC_KEY_BYTES = utils.public_key_bytes(compliance_private_key.public_key()) wallet_account = LocalAccount.generate() execution_dir_path = os.getcwd() wallet_env_file_path = os.path.join(execution_dir_path, "vasp/backend", ENV_FILE_NAME) print(f"Creating {wallet_env_file_path}") # setup merchant wallet with open(wallet_env_file_path, "w") as dotenv: private_keys = {f"{wallet_account_name}": get_private_key_hex(wallet_account.private_key)} wallet_custody_private_keys = json.dumps(private_keys, separators=(',', ':')) dotenv.write(f"GW_PORT={GW_PORT}\n") dotenv.write(f"WALLET_CUSTODY_ACCOUNT_NAME={wallet_account_name}\n") dotenv.write(f"CUSTODY_PRIVATE_KEYS={wallet_custody_private_keys}\n")
def main(): # connect to testnet client = testnet.create_client() # generate private key for sender account sender_private_key = Ed25519PrivateKey.generate() # generate auth key for sender account sender_auth_key = AuthKey.from_public_key(sender_private_key.public_key()) print( f"Generated sender address: {utils.account_address_hex(sender_auth_key.account_address())}" ) # create sender account faucet = testnet.Faucet(client) testnet.Faucet.mint(faucet, sender_auth_key.hex(), 100000000, "XUS") # get sender account sender_account = client.get_account(sender_auth_key.account_address()) # generate private key for receiver account receiver_private_key = Ed25519PrivateKey.generate() # generate auth key for receiver account receiver_auth_key = AuthKey.from_public_key( receiver_private_key.public_key()) print( f"Generated receiver address: {utils.account_address_hex(receiver_auth_key.account_address())}" ) # create receiver account faucet = testnet.Faucet(client) testnet.Faucet.mint(faucet, receiver_auth_key.hex(), 10000000, CURRENCY) # create script script = stdlib.encode_peer_to_peer_with_metadata_script( currency=utils.currency_code(CURRENCY), payee=receiver_auth_key.account_address(), amount=10000000, metadata=b'', # no requirement for metadata and metadata signature metadata_signature=b'', ) # create transaction raw_transaction = diem_types.RawTransaction( sender=sender_auth_key.account_address(), sequence_number=sender_account.sequence_number, payload=diem_types.TransactionPayload__Script(script), max_gas_amount=1_000_000, gas_unit_price=0, gas_currency_code=CURRENCY, expiration_timestamp_secs=int(time.time()) + 30, chain_id=testnet.CHAIN_ID, ) # sign transaction signature = sender_private_key.sign( utils.raw_transaction_signing_msg(raw_transaction)) public_key_bytes = utils.public_key_bytes(sender_private_key.public_key()) signed_txn = utils.create_signed_transaction(raw_transaction, public_key_bytes, signature) # submit transaction client.submit(signed_txn) # wait for transaction client.wait_for_transaction(signed_txn)