Ejemplo n.º 1
0
def test_vector79000():
    nyzo_string = NyzoStringPrivateSeed.from_hex(
        "d60987f22773e4c7-7efb079e9900554e-b6efb568de81ec74-f7396efab7f5605d")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "key_8dp9y_8Et~j7wMJ7EGB0mkYUZZmFVF7JuftXsMHV.n1upfKfwunh"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
Ejemplo n.º 2
0
def test_vector25000():
    nyzo_string = NyzoStringPrivateSeed.from_hex(
        "2882cc9feb9e0861-ccb999c8400cf515-49b73fab4cc6c7a8-0cffef201fc2e777")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "key_82z2R9_IExyyRbDqQ40c.hm9KR~Ijcs7H0R_ZQ0wNLuV9ieWk_p4"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
Ejemplo n.º 3
0
def test_vector0():
    nyzo_string = NyzoStringPrivateSeed.from_hex(
        "74d84ed425f51e6f-aa9bae140e952601-29d16a73241231dc-6962619b5fbc6e27")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "key_87jpjKgC.hXMHGLL50Ym9x4GSnGR918PV6CzpqKwM6WEgqRzfABZ"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
Ejemplo n.º 4
0
def test_vector19000():
    nyzo_string = NyzoStringPrivateSeed.from_hex(
        "c253802154f4aa04-906275b8f922ed86-81cf11d2cac11a92-8dcdf3bee1c5af32")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "key_8c9jx25k.aF4B69TLfBzZpr1RP7iQJ4rBFVd-ZZyPr-QQWm3Ivcv"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
def test_vector0():
    nyzo_string = NyzoStringPublicIdentifier.from_hex(
        "848db2de31cbe4c4-28dbb9e6bdda3aba-98581356ab0e6e02-37b37fd370ac3c7b")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "id__88idJKWPQ~j4adLXXIVreIHpn1dnHNXL0AvRw.dNI3PZXtxdHx7u"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
Ejemplo n.º 6
0
def test_vector8000():
    nyzo_string = NyzoStringPrivateSeed.from_hex(
        "83a2c34eef86da60-e0d26b82a305367b-cf4ed6893ed5d807-0f2fae99a97d77bd")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "key_88ezNSZMyKGxWd9IxHc5dEMfjKr9fKop1N-MIGDGwov.tBBqPRDY"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
Ejemplo n.º 7
0
def test_vector13000():
    nyzo_string = NyzoStringPrivateSeed.from_hex(
        "e58d51a913e209db-8645d6d78f061309-d2af2ef1ed651788-4ea8d4bc4f678401")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "key_8endkrBjWxEsyBonTW-64NEiIQZPZnkoz4YFTbPfqWg1jt28sUiM"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
def test_vector13000():
    nyzo_string = NyzoStringPublicIdentifier.from_hex(
        "39558c7380ba4817-1a748b48fac7bed0-b2d5cbff5d38bf45-8b1f41aacef67881")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "id__83CmA7e0LBxo6EibifI7MK2QTtM_ojz_hpJwgrIe.Ez1H8dsIm5."
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
def test_vector25000():
    nyzo_string = NyzoStringPublicIdentifier.from_hex(
        "701a37089b596a18-b719922a543fff1b-54879e7ca1d4fd5c-64eabd2c85d55231")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "id__870rdNzsnnFpKPDiaCg__PKkyXX-Fuj.o6jHMiQ5Tm8PkBAY.aa9"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
def test_vector19000():
    nyzo_string = NyzoStringPublicIdentifier.from_hex(
        "4c66c2c9ef2f6d7a-ec0057d224dcf8eb-f21ce9f1f938fd7c-b3ab6c77ffd805cc")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "id__84PDNJEMbUTYZ01oSzjt~eMQ7eEP~jA.wbeIs7w_U0ocYX2G.tGZ"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
def test_vector8000():
    nyzo_string = NyzoStringPublicIdentifier.from_hex(
        "1a7d496278a9ffc7-febfed9f3e8d83ab-eb4a227d020fbbaa-ab1544f0cef8f53f")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "id__81G.in9WHw_7_I_KERYdxYMIiz9.0x~ZHHJmhf3e~fk_3tn4IuEs"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
Ejemplo n.º 12
0
 async def deposit(self, ctx, block_id: int = -1):
     """Used to deposit Nyzo on you account"""
     if block_id != -1:
         count = 0
         successed = 0
         result = await async_get("{}/block/{}".format(
             CONFIG["api_url"], block_id),
                                  is_json=True)
         for block in result:
             for transaction in block["value"]["transactions"]:
                 if transaction["value"]["receiver_identifier"] == MAIN_ADDRESS and \
                         transaction["value"]["sender_data"]:
                     count += 1
                     if self.deposit_transaction(
                             transaction["value"]["amount"] -
                             ceil(transaction["value"]["amount"] * 0.0025),
                             bytes.fromhex(transaction["value"]
                                           ["sender_data"]).decode("utf-8"),
                             transaction["value"]["signature"],
                             transaction["value"]["sender_identifier"]):
                         successed += 1
         await ctx.send(
             "{} deposit transactions found in block {}\nSuccessfuly processed {}"
             .format(count, block_id, successed))
     else:
         nyzostring = NyzoStringEncoder.encode(
             NyzoStringPrefilledData.from_hex(
                 MAIN_ADDRESS,
                 str(ctx.author.id).encode().hex()))
         await ctx.send(
             "To deposit nyzo on your account, send a transaction to `{}` with `{}` in the data field\n"
             "Or use this nyzostring: `{}`\nYou will get a message once the deposit is validated."
             .format(MAIN_ID, ctx.author.id, nyzostring))
Ejemplo n.º 13
0
def token_ownership(ctx, token_name: str, recipient: str, key_: str = ""):
    # ./Nyzocli.py --verbose token ownership TEST3 3f19e603b9577b6f91d4c84531e1e94e946aa172063ea3a88efb26e3fe75bb84
    if key_ == "":
        seed = config.PRIVATE_KEY.to_bytes()
        key_ = NyzoStringEncoder.encode(
            NyzoStringPrivateSeed.from_hex(seed.hex()))
    else:
        seed = NyzoStringEncoder.decode(key_).get_bytes()
    key, pub = KeyUtil.get_from_private_seed(seed.hex())
    address = pub.to_ascii(encoding="hex").decode('utf-8')
    id__recipient, recipient = normalize_address(recipient, asHex=True)
    print(f"token ownership transfer {token_name} to {recipient}")
    data = f"TO:{token_name}"
    fees = 0.000001
    # Test via API
    url = f"{ctx.obj['token']}/check_tx/{address}/{recipient}/{fees:0.6f}/{data}"
    if VERBOSE:
        print(url)
    res = get(url).text
    if VERBOSE:
        print(res)
    if "Error:" in res:
        print("E", res)
    else:
        # Assemble, sign and forward if ok
        client = NyzoClient(ctx.obj['client'])
        res = client.send(recipient, fees, data, key_)
        print(res)
Ejemplo n.º 14
0
def token_burn(ctx, token_name: str, amount: str, key_: str = ""):
    # ./Nyzocli.py --verbose token burn TEST3 1.12345
    if key_ == "":
        seed = config.PRIVATE_KEY.to_bytes()
        key_ = NyzoStringEncoder.encode(
            NyzoStringPrivateSeed.from_hex(seed.hex()))
    else:
        seed = NyzoStringEncoder.decode(key_).get_bytes()
    key, pub = KeyUtil.get_from_private_seed(seed.hex())
    address = pub.to_ascii(encoding="hex").decode('utf-8')
    if float(amount) <= 0:
        raise ValueError("Amount has to be > 0")
    if not re.match(r"[0-9A-Z_]{3,32}", token_name):
        raise ValueError(f"Token name '{token_name}' does not follow rules")
    if VERBOSE:
        print(f"token burn {token_name} amount {amount}")
    data = f"TB:{token_name}:{amount}"
    fees = 0.000001
    # Test via API
    recipient = CYCLE_ADDRESS_HEX
    url = f"{ctx.obj['token']}/check_tx/{address}/{recipient}/{fees:0.6f}/{data}"
    if VERBOSE:
        print(url)
    res = get(url).text
    if VERBOSE:
        print(res)
    if "Error:" in res:
        print(res)
    else:
        # Assemble, sign and forward if ok
        client = NyzoClient(ctx.obj['client'])
        res = client.send(recipient, fees, data, key_)
        print(res)
def test_vector79000():
    nyzo_string = NyzoStringPublicIdentifier.from_hex(
        "af4fdb9a637d7e83-a0b9d222e3cd1326-8c07c20ad66cf08e-b506f79d2865e2ad")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "id__8a.fUXGAwoY3FbEi8Lfd4Qrc1-8aTDRNAIk6.XSFqvaKuiPwfgjC"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
Ejemplo n.º 16
0
def normalize_address(
        address: str,
        asHex: bool = False) -> Union[Tuple[str, str], Tuple[str, bytes]]:
    """Takes an address as raw byte or id__ and provides both formats back"""
    try:
        # convert recipient to raw if provided as id__
        if address.startswith("id__"):
            address_raw = NyzoStringEncoder.decode(address).get_bytes().hex()
            if VERBOSE:
                print(f"Raw address is {address_raw}")
        else:
            raise RuntimeWarning("Not an id__")
    except:
        if VERBOSE:
            print(f"address was not a proper id_ nyzostring")
        address_raw = re.sub(r"[^0-9a-f]", "", address.lower())
        # print(address_raw)
        if len(address_raw) != 64:
            raise ValueError(
                "Wrong address format. 64 bytes as hex or id_ nyzostring required"
            )
        if VERBOSE:
            print(f"Trying with {address_raw}")
        address = NyzoStringEncoder.encode(
            NyzoStringPublicIdentifier.from_hex(address_raw))
    # Here we should have both recipient and recipient_raw in all cases.
    if asHex:
        return address, address_raw
    else:
        return address, bytes.fromhex(address_raw)
Ejemplo n.º 17
0
def test_vector0():
    nyzo_string = NyzoStringSignature.from_hex(
        "2529c59201fc91f34fcd4329563997fa89ebe16b15751ab6b93a09988c6d637b9a28d2a77fa02a319466fad2f5cc2b6a03c3c06794c64eb19b243423832cfe01"
    )
    encoded = NyzoStringEncoder.encode(nyzo_string)
    # oops10
    assert encoded == "sig_g2kGPq81_97Rj-T3ampXC_H9Y~5I5okrKIBY2qzcsndZDzAiGV~xaA6kqMIi.tNIrxf3N6vkPBYPDQgS8WcJ_x6Ya_pG"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
Ejemplo n.º 18
0
def test_vector1():
    nyzo_string = NyzoStringSignature.from_hex(
        "1da1460c6b796f7e44734fd2a7b01c63846e42df4ba422a717c1e1389b5a0e539f2337c41345d86b12a9b48728eb72483f85a2d8fde0b612bdcd85453b05b702"
    )
    encoded = NyzoStringEncoder.encode(nyzo_string)
    # lucyLuky17
    assert encoded == "sig_g1UyhxPIvn.~h7dfSHvN76e4sBbwiYgzGPw1WjzsnxXjEQcVP1d5U6JiHsi7aeKQi3~5FKA.WbpiMtU5hjJ5KN8xEaQt"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
Ejemplo n.º 19
0
def test_vector44000():
    nyzo_string = NyzoStringPrefilledData.from_hex(
        "b0c5aef7f03d6c95-e6643f98e12196cb-41fff5e71d4903f4-55419cf80e28781e",
        "")
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert encoded == "pre_8s35IMwNfnQmXDg_De4yCJK1__oE7kB3.5m1Efxea7xv0c64GT24"
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.receiver_identifier == nyzo_string.receiver_identifier
    assert decoded.sender_data == nyzo_string.sender_data
    assert decoded.get_bytes() == nyzo_string.get_bytes()
Ejemplo n.º 20
0
def safe_send(ctx,
              recipient,
              amount: float = 0,
              data: str = "",
              key_: str = ""):
    """
    Send Nyzo to a RECIPIENT then makes sure it is embedded in the planned block.
    If no seed is given, use the wallet one.
    - ex: python3 Nyzocli.py safe_send abd7fede35a84b10-8a36e6dc361d9b32-ca84d149f6eb85b4-a4e63015278d4c9f 10
    - ex: python3 Nyzocli.py safe_send abd7fede35a84b10-8a36e6dc361d9b32-ca84d149f6eb85b4-a4e63015278d4c9f 10 key_...
    """
    if key_ == "":
        seed = config.PRIVATE_KEY.to_bytes()
        key_ = NyzoStringEncoder.encode(
            NyzoStringPrivateSeed.from_hex(seed.hex()))
    else:
        seed = NyzoStringEncoder.decode(key_).get_bytes()
    # convert key to address
    address = KeyUtil.private_to_public(seed.hex())

    my_balance = ctx.invoke(balance, address=address)
    if amount == -1:
        if my_balance is None:
            my_balance = ctx.invoke(balance, address=address)
            print(my_balance)
            # my_balance = balance(ctx, address)
        amount = float(my_balance)
        if amount <= 0:
            if VERBOSE:
                app_log.warning(
                    "Balance too low or unknown {}, dropping.".format(
                        my_balance))
            print(
                json.dumps({
                    "result": "Error",
                    "reason": "Balance too low, {}".format(my_balance)
                }))
            return
        else:
            if VERBOSE:
                app_log.warning("Sending full balance {}.".format(my_balance))

    recipient, recipient_raw = normalize_address(recipient, asHex=True)

    client = NyzoClient(ctx.obj['client'])
    res = client.safe_send(recipient,
                           amount,
                           data,
                           key_,
                           max_tries=5,
                           verbose=True)
    print(res)
    return
Ejemplo n.º 21
0
def test_vector0():
    nyzo_string = NyzoStringPrefilledData.from_hex(
        "1a74dff9c1bb47f7-01eabcfd217f2d6e-ab58a6889efaa44b-5bbe06d396596560",
        "82fb2a31c2fdedd9",
    )
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert (
        encoded ==
        "pre_ahGSV_E1LSwV0vH-_i5_bnYInar8EMHBiTL~1Kennnmx28bZaA72_vVqroRgFqRe")
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.receiver_identifier == nyzo_string.receiver_identifier
    assert decoded.sender_data == nyzo_string.sender_data
    assert decoded.get_bytes() == nyzo_string.get_bytes()
Ejemplo n.º 22
0
def test_vector17000():
    nyzo_string = NyzoStringPrefilledData.from_hex(
        "53daaf0f7243222a-89324a82a2f2da6d-e9a3c025c3156b9d-fbd1bdab6af1409c",
        "536142cd5127b085fd48d3512cc3300abdd7bbca774d691e76437f7db0",
    )
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert (
        encoded ==
        "pre_fCfrIN.QgQ8Hzj9axHbQUDVGF-0CNPmIEwMhMrKH-k2t7mdygJTh9Z25_kAjkiR3c0H.TZMauSTG7Eq3wVUNIh0cVwG-"
    )
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.receiver_identifier == nyzo_string.receiver_identifier
    assert decoded.sender_data == nyzo_string.sender_data
    assert decoded.get_bytes() == nyzo_string.get_bytes()
Ejemplo n.º 23
0
def test_vector75000():
    nyzo_string = NyzoStringPrefilledData.from_hex(
        "7182d875367fbb32-eef8831d47079a78-fd5daf7aabaa145e-1bdb4914676ae579",
        "8044e813bd9acf83149a31d819e22c820edc76f3cd00cd87e67958495e562cd3",
    )
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert (
        encoded ==
        "pre_go62U7kUwZJQZMz37kt7DEA.or.YHYFkoyMsihhErLmX8814Y1e.DJ~359FPU1Ezb88eV7sRRg3dy~qXn4CvmzRjFuo.qVfn"
    )
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.receiver_identifier == nyzo_string.receiver_identifier
    assert decoded.sender_data == nyzo_string.sender_data
    assert decoded.get_bytes() == nyzo_string.get_bytes()
Ejemplo n.º 24
0
def test_vector0new():
    nyzo_string = NyzoStringPrefilledData.from_hex(
        "848db2de31cbe4c4-28dbb9e6bdda3aba-98581356ab0e6e02-37b37fd370ac3c7b",
        # id__88idJKWPQ~j4adLXXIVreIHpn1dnHNXL0AvRw.dNI3PZXtxdHx7u
        "",
    )
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert (
        encoded == "pre_8pidJKWPQ~j4adLXXIVreIHpn1dnHNXL0AvRw.dNI3PZ0fp93qvz")
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.receiver_identifier == nyzo_string.receiver_identifier
    assert decoded.sender_data == nyzo_string.sender_data
    assert decoded.amount == nyzo_string.amount
    assert decoded.get_bytes() == nyzo_string.get_bytes()
Ejemplo n.º 25
0
def cmd_balance():
    no_help()
    address = input("wallet ID or prefix: ").strip()
    address = normalize_id(address)
    print("wallet ID or prefix after normalization: {}".format(address))
    nyzo_string = NyzoStringPublicIdentifier.from_hex(address)
    id_ = NyzoStringEncoder.encode(nyzo_string)
    if address == "":
        print("please provide a wallet ID or prefix")
        return
    if address == 'ff':
        print(
            """╔═════════╦═════════════════════════════════════════════════════════════════════╦══════════════════════════════════════════════════════════╦═════════════════╗
║ block   ║                                                                     ║                                                          ║                 ║
║ height  ║ wallet ID                                                           ║ ID string                                                ║ balance         ║
╠═════════╬═════════════════════════════════════════════════════════════════════╬══════════════════════════════════════════════════════════╬═════════════════╣
║ 5399202 ║ ff0e597aa28012f4-cfba7ef9f1c25bf6-4ebd9bc209dfaff8-b60110f1854aa540 ║ id__8f-enoHzx1bSRZG~~w72n_qeMqM22u~M~bp14f65iHm03viaTvr5 ║ ∩1356604.936151 ║
║ 5399202 ║ ff188d0027165772-3fd521e65983f4fb-140840e6a720450e-f35494e81f80a1b1 ║ id__8f-pAg0E5CuQf.kyXCD3.fJk243DGQ153MdkCexwxa6PWCbQDtgJ ║ ∩84.885685      ║
║ 5399202 ║ ff1b27802b6cce82-436133b101a97fe3-ef3839b36c06099b-abc3f106e104d3b3 ║ id__8f-s9W0IscY2gU4RJg6Gw~fMe3DRs0p9DYM3-gsy1deRQhS9JCzp ║ ∩75.840805      ║
║ 5399202 ║ ff3d6af8305cf2f8-8dafbb56512bc4a5-52729f38f1be83ec-96b54241e00d8929 ║ id__8f-.rMxNofbWAr~ZmC4IPamitG-W-sY3Z9rTgB7x3pBGa974CD4E ║ ∩10.972408      ║
║ 5399202 ║ ff4343e18a1e0c31-db8e48484d788a91-933d824ac03d36da-81af418df9cf2af8 ║ id__8f.3g~6a7xNPUWX8i4TWzG6jfp9aN3SUUF6MgpVXRQIWmuGBhEqb ║ ∩180.734644     ║
║ 5399202 ║ ff4dfe7e7b99e3f1-45024726dc37bcc8-210266968763f34e-0c4bc57ec85e4cc8 ║ id__8f.d_EXZDvfPhg979KNVMcxy0DrnyUfRjxPbPoZ8oBR8jxGJTGwp ║ ∩37.600176      ║
║ 5399202 ║ ff538fa326122ee6-7d2c1622ea2a701b-9e1dd8fcf26e2b71-8b88b68b22afc735 ║ id__8f.jAYcD4zZDwiNn8LFHt1Lv7uA--DWItpL8KFJzI-tT4NAP1Lu. ║ ∩111.229775     ║
║ 5399202 ║ ff614fbcd5aaf1b6-e2a4aec20fc0f244-fd47d5ef1fff45e3-32b3a9461b6d041e ║ id__8f.yjZRmHM6UWHiLNx_0-Bj.h.oM7_.5WRaRHkpssggvf5pBgKN7 ║ ∩206.594460     ║
║ 5399202 ║ ff698862706afa10-88731b8a23c37605-cdf26f2f1a17a8ab-ee7ea519d78e8112 ║ id__8f.Gz69NrMFgz7cszzf3uxod-D-M6yvFH~X~GhEoAF4i0tpBIYx6 ║ ∩97.706838      ║
║ 5399202 ║ ff7f024298d5b2ed-6799302c31e97102-9829c8ec048531af-94dbc4cf739ad52e ║ id__8f._0BapTsbKqXBNb37GtgapatAJ18kPIXjsPc.RDKkL7nAyerzL ║ ∩416.309419     ║
║ 5399202 ║ ff82ccaad7b6ad58-5eb0d8707c878ff3-e94f8ab91013f153-c6f5de295e1fd8d3 ║ id__8f~2RaIoKHTpoI3pt7Q7A_fGjWHX41fPk-sTVzCv7.AjiQL2Ecwf ║ ∩56.073429      ║
║ 5399202 ║ ff8a6f99d1e8b3ef-40a899970cec1ff2-5924f6c6b147243c-471be6fc25770398 ║ id__8f~asXEhYbfMgazqCNRJ7_9q9fs6JktBf4tsXMNCuNep2HNoSVB- ║ ∩10.174500      ║
║ 5399202 ║ ffb5a85fcc138983-d463d5b2c4a949ed-8d06dc7a04cefb81-03eadc0bf4213605 ║ id__8f~TH5_c4WD3T6fmJJiGivUd1KPY1cZZxgfHV0MS8jp5_Y6rkcI7 ║ ∩1354.290441    ║
║ 5399202 ║ ffb7706cc9cf2f0f-abe77438d2370c57-044aea0c5cd56035-1039a7e2c3a9190b ║ id__8f~Vt6R9RQ-fH~uSed8V35t4iLFcodmxdh0XG~b3HhBbPkhjsqZK ║ ∩484.809293     ║
║ 5399202 ║ ffbb94829f67e861-e7ba24decfb45f49-5507d686d08fff84-1bfa5b8893fb52df ║ id__8f~ZC8awq~yyXZFBVJ~SoSCm1.r6S8__y1MYnWzj~TbwSUjI0_ox ║ ∩40.364892      ║
║ 5399202 ║ ffbefdf86aac750f-62964e0f080f9f44-33874a0f726c34ff-bec4f522439cce01 ║ id__8f~~_wyHI7kfpGqe3NxfESgRySFftDNS_ZZ4.i93EcW153QA7-Mx ║ ∩137.430708     ║
║ 5399202 ║ ffd476bde89b47cc-7406f60dc250e828-dff6152c2f9fb002-8414436e45f7c6ab ║ id__8f_kuIVFDSwcu0sU3t9gY2Aw.ykJbX~N0FgkgUX5.-rI.Q8FqVNH ║ ∩6432.872405    ║
║ 5399202 ║ fffabcff6162fbbf-a122e001b95630be-30624f75a708d5e3-228d64e0df27c799 ║ id__8f_YMf.ypML_Fibx0sCncbWNpB.TGNAmWQadqe3w9-vq~9M.X9ah ║ ∩449.074037     ║
╚═════════╩═════════════════════════════════════════════════════════════════════╩══════════════════════════════════════════════════════════╩═════════════════╝
""")
        return

    # TODO: here, address should be re-converted with dashes to fit the real client display
    print(
        """╔═════════╦═════════════════════════════════════════════════════════════════════╦══════════════════════════════════════════════════════════╦═══════════════╗
║ block   ║                                                                     ║                                                          ║               ║
║ height  ║ wallet ID                                                           ║ ID string                                                ║ balance       ║
╠═════════╬═════════════════════════════════════════════════════════════════════╬══════════════════════════════════════════════════════════╬═══════════════╣
║ {frozen} ║ {address} ║ {id_} ║ ∩1234.{rand:0000} ║
╚═════════╩═════════════════════════════════════════════════════════════════════╩══════════════════════════════════════════════════════════╩═══════════════╝
""".format(frozen=FROZEN,
           address=address,
           id_=id_,
           rand=random.randint(1, 1000)))
Ejemplo n.º 26
0
def token_issue(ctx,
                token_name: str,
                decimals: int,
                supply: str,
                key_: str = ""):
    # ./Nyzocli.py --verbose token issue -- TEST3 3 -1
    if key_ == "":
        seed = config.PRIVATE_KEY.to_bytes()
        key_ = NyzoStringEncoder.encode(
            NyzoStringPrivateSeed.from_hex(seed.hex()))
    else:
        seed = NyzoStringEncoder.decode(key_).get_bytes()
    key, pub = KeyUtil.get_from_private_seed(seed.hex())
    address = pub.to_ascii(encoding="hex").decode('utf-8')
    if decimals < 0:
        raise ValueError("Decimals have to be >= 0")
    if decimals > 18:
        raise ValueError("Decimals have to be <= 18")
    dec = str(decimals)
    while len(dec) < 2:
        dec = "0" + dec
    if not re.match(r"[0-9A-Z_]{3,32}", token_name):
        raise ValueError(f"Token name '{token_name}' does not follow rules")
    if VERBOSE:
        print(f"token issue {token_name} decimals {dec} supply {supply}")
    data = f"TI:{token_name}:d{dec}:{supply}"
    # get fees
    url = f"{ctx.obj['token']}/fees"
    res = get(url)
    fees = res.json()
    issue_fees = fees[-1]["issue_fees"]  # micro_nyzos
    amount = issue_fees / 1000000
    if VERBOSE:
        print(f"Issue fees are {issue_fees} micro nyzos.")
    # Test via API
    recipient = CYCLE_ADDRESS_HEX
    url = f"{ctx.obj['token']}/check_tx/{address}/{recipient}/{amount:0.6f}/{data}"
    if VERBOSE:
        print(url)
    res = get(url).text
    if VERBOSE:
        print(res)
    if "Error:" in res:
        print(res)
    else:
        # Assemble, sign and forward if ok
        client = NyzoClient(ctx.obj['client'])
        res = client.send(recipient, amount, data, key_)
        print(res)
Ejemplo n.º 27
0
def test_vector_vote():
    nyzo_string = NyzoStringTransaction.from_hex_vote(
        "9bdecd1085b8f5e1",
        "3ce4eaf311934276-673752ccb5cf4cac-61eed231d8fcb649-6310887ecf99f6e5",
        "6a675732bd20a2c203a925fc62f1d5249b98c128b555472c980f84d9d37fb3452c7211ea448eeed51b7af17785490593a429e97a4f373788a1a768e40d64657c",
        1,
        "1da1460c6b796f7e44734fd2a7b01c63846e42df4ba422a717c1e1389b5a0e539f2337c41345d86b12a9b48728eb72483f85a2d8fde0b612bdcd85453b05b702"  # fake sig
    )
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert (
        encoded ==
        "tx__HxisVJSgysATWjRBYMchBS9UqRuiRbofjaPyZK8PUfQUincgz7ZfDwsC0hUyhxPIvn.~h7dfSHvN76e4sBbwiYgzGPw1WjzsnxXjEQcVP1d5U6JiHsi7aeKQi3~5FKA.WbpiMtU5hjJ5KN9HqTtQMi2zNxeG9wPz-ukBDXA1abmmhQQp3WjqSV~RhiPQ4vG4ALZm6VIPuWm91qeBavCYjRtVza6Eregdq6m-hccQ7-vf"
    )
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.get_bytes() == nyzo_string.get_bytes()
Ejemplo n.º 28
0
def find_it(string: str, ctx):
    found = 0
    while True:
        # pk = urandom(32).hex()
        pk = token_hex(
            32)  # +50% time, but supposed to be cryptographically secure
        nyzo_string = NyzoStringPublicIdentifier.from_hex(pk)
        address = NyzoStringEncoder.encode(nyzo_string)
        if not ctx.obj['case']:
            address = address.lower()
        if string in address:
            print(address, bytes_as_string_with_dashes(pk))
            found += 1
            if found > ctx.obj['max']:
                return
Ejemplo n.º 29
0
def test_vector0new2():
    nyzo_string = NyzoStringPrefilledData.from_hex(
        "848db2de31cbe4c4-28dbb9e6bdda3aba-98581356ab0e6e02-37b37fd370ac3c7b",
        # id__88idJKWPQ~j4adLXXIVreIHpn1dnHNXL0AvRw.dNI3PZXtxdHx7u
        "",
        10 *
        1000000  # Amount to be provided as int, micronyzos. no amount = 0.
    )
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert (
        encoded ==
        "pre_apidJKWPQ~j4adLXXIVreIHpn1dnHNXL0AvRw.dNI3PZx0000000D9r0fJmDjEFZ")
    decoded = NyzoStringEncoder.decode(encoded)
    assert decoded.receiver_identifier == nyzo_string.receiver_identifier
    assert decoded.sender_data == nyzo_string.sender_data
    assert decoded.amount == nyzo_string.amount
    assert decoded.get_bytes() == nyzo_string.get_bytes()
Ejemplo n.º 30
0
def test_vector0():
    nyzo_string = NyzoStringMicropay.from_hex(
        "f786ad285a251faa-6b59b353b83b0cc7-5a5a9e53a99d148c-a7f1439909da15a6",
        "1e0621f818c44de5700ccb243fb9e8d0a65acdc70943",
        "fbe53e25acb1caf0",
        "d8e13cd700325825",
        "6da37b293519ca78",
        "a045e3c666ffec05-e7e392c0c09c8a99-3a883c8f2a40f915-a9e50659e0e16f08",
    )
    encoded = NyzoStringEncoder.encode(nyzo_string)
    assert (
        encoded ==
        "pay_s_v6Iiyr9h~HrTDRkZxZ3curnGXjHqSkAawPgXB9UynD5yW68wxpP4VCt0Rb93~XYd2DnJV72kfZXjWCIb7a-dAyfdt0cCxCsrdZajkqQEzxhvf6qM_J1vwABJ30E8HqeFx-AQG0~hnGXgqqWe5M2avMAHTp"
    )
    decoded = NyzoStringEncoder.decode(encoded)
    # todo: More detailed tests (but comparing core bytes storage should be enough)
    assert decoded.get_bytes() == nyzo_string.get_bytes()