Skip to content

Commit

Permalink
public key test
Browse files Browse the repository at this point in the history
  • Loading branch information
exploreriii committed Dec 15, 2024
1 parent 59f6f15 commit 9128a56
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
from src.account.account_id import AccountId
from src.account.account_create_transaction import AccountCreateTransaction
from src.crypto.private_key import PrivateKey
from src.crypto.public_key import PublicKey
from src.tokens.token_create_transaction import TokenCreateTransaction
from src.tokens.token_associate_transaction import TokenAssociateTransaction
from src.transaction.transfer_transaction import TransferTransaction
from src.response_code import ResponseCode
from src.tokens.token_delete_transaction import TokenDeleteTransaction
from cryptography.hazmat.primitives import serialization

def load_operator_credentials():
"""Load operator credentials from environment variables."""
Expand Down Expand Up @@ -52,7 +54,7 @@ def create_new_account(client, initial_balance=100000000):

return new_account_id, new_account_private_key

def create_token(client, operator_id, admin_key):
def create_token(client, operator_id, admin_public_key_bytes):
"""Create a new token and return its TokenId instance."""
transaction = (
TokenCreateTransaction()
Expand All @@ -61,10 +63,10 @@ def create_token(client, operator_id, admin_key):
.set_decimals(2)
.set_initial_supply(1000)
.set_treasury_account_id(operator_id)
.set_admin_key(admin_key)
.set_admin_key(admin_public_key_bytes)
.freeze_with(client)
)
transaction.sign(admin_key)
# transaction.sign(admin_key)
transaction.sign(client.operator_private_key)


Expand Down Expand Up @@ -149,13 +151,18 @@ def main():
operator_id, operator_key = load_operator_credentials()
# admin_key = PrivateKey.from_string(os.getenv('ADMIN_KEY'))
admin_key = PrivateKey.generate()
admin_public_key = admin_key.public_key
admin_public_key_bytes = admin_public_key.public_bytes(
encoding=serialization.Encoding.Raw,
format=serialization.PublicFormat.Raw
)

network = Network(node_address='localhost:50211', node_account_id=AccountId(0, 0, 3))
client = Client(network)
client.set_operator(operator_id, operator_key)

recipient_id, recipient_private_key = create_new_account(client)
token_id = create_token(client, operator_id, admin_key)
token_id = create_token(client, operator_id, admin_public_key_bytes)
associate_token(client, recipient_id, recipient_private_key, token_id)
transfer_token(client, recipient_id, token_id)
delete_token(client, token_id, admin_key)
Expand Down

0 comments on commit 9128a56

Please sign in to comment.