Beispiel #1
0
	def __struct__(self):
		enc = Encoding()
		_s = {
			'UniqueTx' : {
				'txID' : enc.Encode(self.txID),
				'state' : self.TxState
			}
		}
		return _s
Beispiel #2
0
    def __struct__(self):
        enc = Encoding()
        vid = self.vtxID

        if isinstance(vid, bytes):
            vid = enc.Encode(vid)

        state = self.v
        if state:
            state = state.__struct__()

        return {
            'UniqueVertex': {
                "vertex_id": vid,
                "state": state,
                "txs": self.Txs()
            }
        }
Beispiel #3
0
class Msg:
    def __init__(self, op, fields, data_bytes):
        self.op = op
        self.fields = fields
        self.bytes = data_bytes
        self.encoder = Encoding()

    def __repr__(self) -> str:

        field_desc = {}
        for f in self.fields:
            k = "{}({})".format(Field.String(f), f)
            if f == 6 or f == 9:
                field_desc[k] = self.encoder.Encode(self.fields[f])
            elif f == 10 or f == 13:
                field_desc[k] = "[BINARY] {} Bytes".format(len(self.fields[f]))
            elif f == 5 or f == 15:
                field_desc[k] = "{} IPs".format(len(self.fields[f]))
            else:
                field_desc[k] = self.fields[f]

        dct = {
            'op': self.op,
            'op_name': Op.String(self.op),
            'fields': field_desc,
            'msg_size': len(self.bytes),
            # uncomment this to show raw bytes in printout
            # might clutter the screen
            # 'bytes': self.bytes.hex()
        }

        return "network.Msg " + str(dct)

    # Field returns the value of the specified field in this message
    def Op(self):
        return self.op

    # Field returns the value of the specified field in this message
    def Get(self, field):
        return self.fields[field]

    # Bytes returns this message in bytes
    def Bytes(self):
        return self.bytes
Beispiel #4
0
#
# Find tutorials and use cases at https://crypto.bi
"""

Copyright (C) 2021 - crypto.bi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

---

Help support this Open Source project!
Donations address: X-avax1qr6yzjykcjmeflztsgv6y88dl0xnlel3chs3r4
Thank you!

"""

# --#--#--

from avaxpython.utils.formatting.encoding import Encoding

my_bytes = bytearray.fromhex(
    "a8d7f87f1c8a5583c1ca92b20b8ace3330ba0d9ddaa7f4bfa6435f75459f7394")
enc = Encoding()
he = enc.HashEncode(my_bytes)

print(he)
Beispiel #5
0
"""

# --#--#--

import json
from avaxpython.types import *
from avaxpython.snow.engine.avalanche.vertex.stateless_vertex import innerStatelessVertex
from avaxpython.codec.reflectcodec.type_codec import genericCodec
from avaxpython.utils.wrappers.Packer import Packer
from avaxpython.vms.avm.tx import Tx
from avaxpython.vms.avm.types import registered_types
from avaxpython.utils.formatting.encoding import Encoding

txbytes = bytearray.fromhex(
    "00000000000300000001ed5f38341e436e5d46e2bb00b45d62ae97d1b050c64bc634ae10626739e35c4b0000000121e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff00000007000000520ef23eef00000000000000000000000100000001107bb6b9ae55ce54d6e83602b55699ebea87e0150000000000000000000000000000000000000000000000000000000000000000000000000000000000000001a8d7f87f1c8a5583c1ca92b20b8ace3330ba0d9ddaa7f4bfa6435f75459f73940000000021e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff00000005000000520f01812f0000000100000000000000010000000900000001cf929996c66224fb7f3dafc3916ee0b1c64070ff472f325a3e976db8a346d6fa20ae77ca53ddf5d36a5bf629d3359ad79cfed1217cfe33710663be738f5d785300"
)

enc = Encoding()
txID = enc.HashEncode(txbytes)
print(f"TX ID {txID}")

p = Packer(txbytes)
b = p.UnpackShort()
print(f"Codec Version: {b}")
tx = Tx()
dest = genericCodec._unmarshal(p, tx, type_ids=registered_types)

print("\n\n\n")
print(dest)
print("\n\n\n")
    print("Invalid phrase length provided. Got {} expected {}.".format(len(sys.argv)-1, word_length))
    exit(1)

seed = Mnemonic("english").to_seed(" ".join(sys.argv[1:]), passphrase="")

masterHdKey = Bip32.FromSeed(seed)
accountHdKey = Bip32.FromSeedAndPath(seed, WalletConfig.AVA_ACCOUNT_PATH)

# the first private key generated by an HD wallet seeded from this mnemonic phrase
firstHDKey = BIP32.derive_master_key(accountHdKey, '0/0')

masterKey = masterHdKey.PrivateKey().Raw().ToBytes()
accountKey = accountHdKey.PrivateKey().Raw().ToBytes()
firstKey = firstHDKey.PrivateKey().Raw().ToBytes()

enc = Encoding()
pkey_prefix = "PrivateKey-{}"

masterKeyEncoded = pkey_prefix.format(enc.Encode(masterKey))
accountKeyEncoded = pkey_prefix.format(enc.Encode(accountKey))
firstKeyEncoded = pkey_prefix.format(enc.Encode(firstKey))

output = {
    'masterHdKeyEncoded' : masterKeyEncoded,
    'accountHdKeyEncoded' : accountKeyEncoded,
    'masterHdKey' : masterKey.hex(),
    'accountHdKey' : accountKey.hex(),
    'firstHdKey' : firstKey.hex(),
    'firstHdKeyEncoded' : firstKeyEncoded,
    'seed': seed.hex()
}
Beispiel #7
0
#
# Find tutorials and use cases at https://crypto.bi
"""

Copyright (C) 2021 - crypto.bi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

---

Help support this Open Source project!
Donations address: X-avax1qr6yzjykcjmeflztsgv6y88dl0xnlel3chs3r4
Thank you!

"""

# --#--#--

from avaxpython.utils.formatting.encoding import Encoding

my_bytes = bytearray.fromhex(
    "a8d7f87f1c8a5583c1ca92b20b8ace3330ba0d9ddaa7f4bfa6435f75459f7394")
enc = Encoding()
he = enc.Encode(my_bytes)

print(he)
Beispiel #8
0
 def __str__(self):
     global defaultEncoding
     enc = Encoding(defaultEncoding)
     encoded = enc.Encode(self.bytes)
     return encoded
Beispiel #9
0
 def __init__(self, op, fields, data_bytes):
     self.op = op
     self.fields = fields
     self.bytes = data_bytes
     self.encoder = Encoding()