Skip to content

Commit

Permalink
Merge pull request #46 from eric0x01/update_dependency
Browse files Browse the repository at this point in the history
update dependencies, remove useless code
  • Loading branch information
charles2023wood authored Mar 13, 2024
2 parents 469151d + ca79754 commit bbc82de
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 68 deletions.
44 changes: 37 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@
"description": "",
"main": "index.js",
"scripts": {
"testrpc": "ganache-cli --mnemonic 'clock radar mass judge dismiss just intact mind resemble fringe diary casino' --gasLimit 13000000 -e 100000",
"test:ci": "scripts/run-test.sh",
"generate-test": "node generate-system.js --mock true && node generate-validatorset.js --mock true && node generate-btclightclient.js --mock true && node generate-candidatehub.js --mock true && node generate-pledgeagent.js --mock true && node generate-slash.js --mock true",
"generate-mainnet": "node generate-genesis.js --chainid 1116 --initValidatorSetBytes f90285ea944121f067b0f5135d77c29b2b329e8cb1bd96c96094f8b18cecc98d976ad253d38e4100a73d4e154726ea947f461f8a1c35edecd6816e76eb2e84eb661751ee94f8b18cecc98d976ad253d38e4100a73d4e154726ea94fd806ab93db5742944b7b50ce759e5eee5f6fe5094f8b18cecc98d976ad253d38e4100a73d4e154726ea947ef3a94ad1c443481fb3d86829355ca90477f8b594f8b18cecc98d976ad253d38e4100a73d4e154726ea9467d1ad48f91e131413bd0b04e823f3ae4f81e85394f8b18cecc98d976ad253d38e4100a73d4e154726ea943fb42cab4416024dc1b4c9e21b9acd0dfcef35f694f8b18cecc98d976ad253d38e4100a73d4e154726ea943511e3b8ac7336b99517d324145e9b5bb33e08a494f8b18cecc98d976ad253d38e4100a73d4e154726ea94729f39a54304fcc6ec279684c71491a385d7b9ae94f8b18cecc98d976ad253d38e4100a73d4e154726ea94f44a785fd9f23f0abd443541386e71356ce619dc94f8b18cecc98d976ad253d38e4100a73d4e154726ea942efd3cf0733421aec3e4202480d0a90bd157514994f8b18cecc98d976ad253d38e4100a73d4e154726ea94613b0f519ada008cb99b6130e89122ba416bf15994f8b18cecc98d976ad253d38e4100a73d4e154726ea94c0925eeb800ff6ba4695ded61562a10102152b5f94f8b18cecc98d976ad253d38e4100a73d4e154726ea9419e3c7d7e69f273f3f91c060bb438a007f6fc33c94f8b18cecc98d976ad253d38e4100a73d4e154726ea94e127f110d172a0c4c6209fe045dd71781e8fe9d494f8b18cecc98d976ad253d38e4100a73d4e154726ea94f778dc4a199a440dbe9f16d1e13e185bb179b3b794f8b18cecc98d976ad253d38e4100a73d4e154726 --initMembersBytes f86994548e6acce441866674e04ab84587af2d394034c094bb06d463bc143eecc4a0cfa35e0346d5690fa9f694e2fe60f349c6e1a85caad1d22200c289da40dc1294b198db68258f06e79d415a0998be7f9b38ea722694dd173b85f306128f1b10d7d7219059c28c6d6c09",
"generate-testnet": "node generate-genesis.js --chainid 1115 --initValidatorSetBytes f8d7ea9401bca3615d24d3c638836691517b2b9b49b054b1943ae030dc3717c66f63d6e8f1d1508a5c941ff46dea94a458499604a85e90225a14946f36368ae24df16d94de442f5ba55687a24f04419424e0dc2593cc9f4cea945e00c0d5c4c10d4c805aba878d51129a89d513e094cb089be171e256acdaac1ebbeb32ffba0dd438eeea941cd652bc64af3f09b490daae27f46e53726ce230940a53b7e0ffd97357e444b85f4d683c1d8e22879aea94da37ccecbb2d7c83ae27ee2bebfe8ebce162c60094d82c24274ebbfe438788d684dc6034c3c67664a4 --initMembersBytes f83f9491fb7d8a73d2752830ea189737ea0e007f999b949448bfbc530e7c54c332b0fae07312fba7078b878994de60b7d0e6b758ca5dd8c61d377a2c5f1af51ec1",
"generate-testnet2": "node generate-genesis.js --chainid 1114 --initValidatorSetBytes f8d7ea9401bca3615d24d3c638836691517b2b9b49b054b19401bca3615d24d3c638836691517b2b9b49b054b1ea94a458499604a85e90225a14946f36368ae24df16d94a458499604a85e90225a14946f36368ae24df16dea945e00c0d5c4c10d4c805aba878d51129a89d513e0945e00c0d5c4c10d4c805aba878d51129a89d513e0ea941cd652bc64af3f09b490daae27f46e53726ce230941cd652bc64af3f09b490daae27f46e53726ce230ea94da37ccecbb2d7c83ae27ee2bebfe8ebce162c60094da37ccecbb2d7c83ae27ee2bebfe8ebce162c600 --initMembersBytes f83f9491fb7d8a73d2752830ea189737ea0e007f999b949448bfbc530e7c54c332b0fae07312fba7078b878994de60b7d0e6b758ca5dd8c61d377a2c5f1af51ec1"
"generate-testnet": "node generate-genesis.js --chainid 1115 --initValidatorSetBytes f8d7ea9401bca3615d24d3c638836691517b2b9b49b054b1943ae030dc3717c66f63d6e8f1d1508a5c941ff46dea94a458499604a85e90225a14946f36368ae24df16d94de442f5ba55687a24f04419424e0dc2593cc9f4cea945e00c0d5c4c10d4c805aba878d51129a89d513e094cb089be171e256acdaac1ebbeb32ffba0dd438eeea941cd652bc64af3f09b490daae27f46e53726ce230940a53b7e0ffd97357e444b85f4d683c1d8e22879aea94da37ccecbb2d7c83ae27ee2bebfe8ebce162c60094d82c24274ebbfe438788d684dc6034c3c67664a4 --initMembersBytes f83f9491fb7d8a73d2752830ea189737ea0e007f999b949448bfbc530e7c54c332b0fae07312fba7078b878994de60b7d0e6b758ca5dd8c61d377a2c5f1af51ec1"
},
"author": "",
"license": "MIT",
"dependencies": {
"commander": "^3.0.1",
"nunjucks": "^3.2.3",
"es5-ext": "^0.10.64",
"nunjucks": "^3.2.4",
"rlp": "^2.2.7",
"web3": "^1.9.0"
}
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
eth-brownie==1.19.4
PyYAML==5.4.1
ecdsa==0.17.0
55 changes: 1 addition & 54 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import random
import pathlib
import codecs
import hashlib
import ecdsa
import yaml

from web3 import Web3
from brownie.network.transaction import TransactionReceipt
from brownie.network.account import LocalAccount
from brownie import accounts, chain, web3, history
from brownie import chain, web3, history
from eth_account import Account
from eth_abi import encode
from hashlib import sha256
Expand Down Expand Up @@ -44,56 +41,6 @@ def expect_event_not_emitted(tx_receipt: TransactionReceipt, event_name):
assert event_name not in tx_receipt.events


def get_mnemonic() -> str:
current_path = pathlib.Path(__file__)
config_file_path = current_path.parent.parent / "brownie-config.yaml"
with open(config_file_path, "r") as f:
data = yaml.load(f.read(), Loader=yaml.CLoader)
return data['networks']['development']['cmd_settings']['mnemonic']


def get_private_key_by_idx(idx):
account = accounts.from_mnemonic(get_mnemonic(), offset=idx)
return account.private_key


def pk2public_key(pk, compressed=False):
if pk.startswith('0x'):
private_key_bytes = Web3.toBytes(hexstr=pk)
else:
private_key_bytes = codecs.decode(pk, 'hex')

# Generating a public key in bytes using SECP256k1 & ecdsa library
public_key_raw = ecdsa.SigningKey.from_string(private_key_bytes, curve=ecdsa.SECP256k1).verifying_key
public_key_bytes = public_key_raw.to_string()

# Hex encoding the public key from bytes
public_key_hex = codecs.encode(public_key_bytes, 'hex')

# Bitcoin uncompressed public key begins with bytes 0x04 so we have to add the bytes at the start
public_key = (b'04' + public_key_hex).decode('utf-8')
if not compressed:
return '0x' + public_key

# Checking if the last byte is odd or even
if ord(bytearray.fromhex(public_key[-2:])) % 2 == 0:
public_key_compressed = '02'
else:
public_key_compressed = '03'
# Add bytes 0x02 to the X of the key if even or 0x03 if odd
public_key_compressed += public_key[2:66]
return '0x' + public_key_compressed


def get_public_key_by_idx(idx: int, compressed=False):
return pk2public_key(get_private_key_by_idx(idx), compressed)


def get_public_key_by_address(address, compressed=False):
idx = [account.address for account in accounts].index(address)
return get_public_key_by_idx(idx, compressed)


def public_key2PKHash(public_key):
if public_key.startswith('0x'):
public_key_bytes = Web3.toBytes(hexstr=public_key)
Expand Down

0 comments on commit bbc82de

Please sign in to comment.