Esempio n. 1
0
async def _require_confirm_payload(ctx, payload: bytearray, encrypt=False):
    payload = bytes(payload).decode()

    if len(payload) > 48:
        payload = payload[:48] + ".."
    if encrypt:
        text = Text("Confirm payload", ui.ICON_SEND, icon_color=ui.GREEN)
        text.bold("Encrypted:")
        text.normal(*split_words(payload, 22))
    else:
        text = Text("Confirm payload", ui.ICON_SEND, icon_color=ui.RED)
        text.bold("Unencrypted:")
        text.normal(*split_words(payload, 22))
    await require_confirm(ctx, text, ButtonRequestType.ConfirmOutput)
Esempio n. 2
0
async def _require_confirm_payload(ctx, payload: bytes, encrypt=False):
    payload = str(payload, 'utf-8')

    if len(payload) > 48:
        payload = payload[:48] + '..'
    if encrypt:
        text = Text('Confirm payload', ui.ICON_SEND, icon_color=ui.GREEN)
        text.bold('Encrypted:')
        text.normal(*split_words(payload, 22))
    else:
        text = Text('Confirm payload', ui.ICON_SEND, icon_color=ui.RED)
        text.bold('Unencrypted:')
        text.normal(*split_words(payload, 22))
    await require_confirm(ctx, text, ButtonRequestType.ConfirmOutput)
Esempio n. 3
0
def split_message(message):
    def measure(s):
        return ui.display.text_width(s, ui.NORMAL)

    try:
        m = bytes(message).decode()
        lines = split_words(m, ui.WIDTH - 2 * TEXT_MARGIN_LEFT, metric=measure)
    except UnicodeError:
        m = hexlify(message)
        lines = chunks(m, 16)
    return lines
Esempio n. 4
0
async def _require_confirm_payload(ctx, payload: bytes, encrypt=False):
    payload = str(payload, 'utf-8')

    if len(payload) > 48:
        payload = payload[:48] + '..'
    if encrypt:
        content = Text('Confirm payload',
                       ui.ICON_SEND,
                       ui.BOLD,
                       'Encrypted:',
                       ui.NORMAL,
                       *split_words(payload, 22),
                       icon_color=ui.GREEN)
    else:
        content = Text('Confirm payload',
                       ui.ICON_SEND,
                       ui.BOLD,
                       'Unencrypted:',
                       ui.NORMAL,
                       *split_words(payload, 22),
                       icon_color=ui.RED)
    await require_confirm(ctx, content, ButtonRequestType.ConfirmOutput)
Esempio n. 5
0
def _get_mosaic_properties(definition: NEMMosaicDefinition):
    properties = []
    if definition.description:
        t = Text('Confirm properties', ui.ICON_SEND, ui.BOLD, 'Description:',
                 ui.NORMAL, *split_words(trim(definition.description, 70), 22))
        properties.append(t)
    if definition.transferable:
        transferable = 'Yes'
    else:
        transferable = 'No'
    t = Text('Confirm properties', ui.ICON_SEND, ui.BOLD, 'Transferable?',
             ui.NORMAL, transferable)
    properties.append(t)
    if definition.mutable_supply:
        imm = 'mutable'
    else:
        imm = 'immutable'
    if definition.supply:
        t = Text('Confirm properties',
                 ui.ICON_SEND, ui.BOLD, 'Initial supply:', ui.NORMAL,
                 str(definition.supply), ui.NORMAL, imm)
    else:
        t = Text('Confirm properties', ui.ICON_SEND, ui.BOLD,
                 'Initial supply:', ui.NORMAL, imm)
    properties.append(t)
    if definition.levy:
        t = Text('Confirm properties', ui.ICON_SEND, ui.BOLD,
                 'Levy recipient:', ui.MONO,
                 *split_address(definition.levy_address))
        properties.append(t)
        t = Text('Confirm properties',
                 ui.ICON_SEND, ui.BOLD, 'Levy fee:', ui.NORMAL,
                 str(definition.fee), ui.BOLD, 'Levy divisibility:', ui.NORMAL,
                 str(definition.divisibility))
        properties.append(t)
        t = Text('Confirm properties', ui.ICON_SEND, ui.BOLD,
                 'Levy namespace:', ui.NORMAL, definition.levy_namespace,
                 ui.BOLD, 'Levy mosaic:', ui.NORMAL, definition.levy_mosaic)
        properties.append(t)
        if definition.levy == NEMMosaicLevy.MosaicLevy_Absolute:
            levy_type = 'absolute'
        else:
            levy_type = 'percentile'
        t = Text('Confirm properties', ui.ICON_SEND, ui.BOLD, 'Levy type:',
                 ui.NORMAL, levy_type)
        properties.append(t)

    return properties
Esempio n. 6
0
async def cipher_key_value(ctx, msg):
    if len(msg.value) % 16 > 0:
        raise wire.DataError('Value length must be a multiple of 16')

    encrypt = msg.encrypt
    decrypt = not msg.encrypt
    if (encrypt and msg.ask_on_encrypt) or (decrypt and msg.ask_on_decrypt):
        if encrypt:
            title = 'Encrypt value'
        else:
            title = 'Decrypt value'
        lines = split_words(msg.key, ui.WIDTH - 2 * TEXT_MARGIN_LEFT, metric=lambda x: ui.display.text_width(x, ui.NORMAL))
        await require_confirm(ctx, Text(title, ui.ICON_DEFAULT, max_lines=5, *lines))

    node = await seed.derive_node(ctx, msg.address_n)
    value = compute_cipher_key_value(msg, node.private_key())
    return CipheredKeyValue(value=value)
Esempio n. 7
0
async def ask_transfer_mosaic(ctx, common: NEMTransactionCommon,
                              transfer: NEMTransfer, mosaic: NEMMosaic):
    if is_nem_xem_mosaic(mosaic.namespace, mosaic.mosaic):
        return

    definition = get_mosaic_definition(mosaic.namespace, mosaic.mosaic,
                                       common.network)
    mosaic_quantity = mosaic.quantity * transfer.amount / NEM_MOSAIC_AMOUNT_DIVISOR

    if definition:
        msg = Text('Confirm mosaic', ui.ICON_SEND, icon_color=ui.GREEN)
        msg.normal('Confirm transfer of')
        msg.bold(
            format_amount(mosaic_quantity, definition['divisibility']) +
            definition['ticker'])
        msg.normal('of')
        msg.bold(definition['name'])
        await require_confirm(ctx, msg, ButtonRequestType.ConfirmOutput)

        if 'levy' in definition and 'fee' in definition:
            levy_msg = _get_levy_msg(definition, mosaic_quantity,
                                     common.network)
            msg = Text('Confirm mosaic', ui.ICON_SEND, icon_color=ui.GREEN)
            msg.normal('Confirm mosaic', 'levy fee of')
            msg.bold(levy_msg)
            await require_confirm(ctx, msg, ButtonRequestType.ConfirmOutput)

    else:
        msg = Text('Confirm mosaic', ui.ICON_SEND, icon_color=ui.RED)
        msg.bold('Unknown mosaic!')
        msg.normal(*split_words(
            'Divisibility and levy cannot be shown for unknown mosaics', 22))
        await require_confirm(ctx, msg, ButtonRequestType.ConfirmOutput)

        msg = Text('Confirm mosaic', ui.ICON_SEND, icon_color=ui.GREEN)
        msg.normal('Confirm transfer of')
        msg.bold('%s raw units' % mosaic_quantity)
        msg.normal('of')
        msg.bold('%s.%s' % (mosaic.namespace, mosaic.mosaic))
        await require_confirm(ctx, msg, ButtonRequestType.ConfirmOutput)
Esempio n. 8
0
async def ask_transfer_mosaic(ctx, common: NEMTransactionCommon,
                              transfer: NEMTransfer, mosaic: NEMMosaic):
    if is_nem_xem_mosaic(mosaic.namespace, mosaic.mosaic):
        return

    definition = get_mosaic_definition(mosaic.namespace, mosaic.mosaic,
                                       common.network)
    mosaic_quantity = mosaic.quantity * transfer.amount / NEM_MOSAIC_AMOUNT_DIVISOR

    if definition:
        msg = Text("Confirm mosaic", ui.ICON_SEND, icon_color=ui.GREEN)
        msg.normal("Confirm transfer of")
        msg.bold(
            format_amount(mosaic_quantity, definition["divisibility"]) +
            definition["ticker"])
        msg.normal("of")
        msg.bold(definition["name"])
        await require_confirm(ctx, msg, ButtonRequestType.ConfirmOutput)

        if "levy" in definition and "fee" in definition:
            levy_msg = _get_levy_msg(definition, mosaic_quantity,
                                     common.network)
            msg = Text("Confirm mosaic", ui.ICON_SEND, icon_color=ui.GREEN)
            msg.normal("Confirm mosaic", "levy fee of")
            msg.bold(levy_msg)
            await require_confirm(ctx, msg, ButtonRequestType.ConfirmOutput)

    else:
        msg = Text("Confirm mosaic", ui.ICON_SEND, icon_color=ui.RED)
        msg.bold("Unknown mosaic!")
        msg.normal(*split_words(
            "Divisibility and levy cannot be shown for unknown mosaics", 22))
        await require_confirm(ctx, msg, ButtonRequestType.ConfirmOutput)

        msg = Text("Confirm mosaic", ui.ICON_SEND, icon_color=ui.GREEN)
        msg.normal("Confirm transfer of")
        msg.bold("%s raw units" % mosaic_quantity)
        msg.normal("of")
        msg.bold("%s.%s" % (mosaic.namespace, mosaic.mosaic))
        await require_confirm(ctx, msg, ButtonRequestType.ConfirmOutput)
Esempio n. 9
0
async def require_confirm_text(ctx, action: str):
    words = split_words(action, 18)
    await require_confirm_content(ctx, 'Confirm action', words)
Esempio n. 10
0
def _get_mosaic_properties(definition: NEMMosaicDefinition):
    properties = []

    # description
    if definition.description:
        t = Text("Confirm properties", ui.ICON_SEND)
        t.bold("Description:")
        t.normal(*split_words(trim(definition.description, 70), 22))
        properties.append(t)

    # transferable
    if definition.transferable:
        transferable = "Yes"
    else:
        transferable = "No"
    t = Text("Confirm properties", ui.ICON_SEND)
    t.bold("Transferable?")
    t.normal(transferable)
    properties.append(t)

    # mutable_supply
    if definition.mutable_supply:
        imm = "mutable"
    else:
        imm = "immutable"
    if definition.supply:
        t = Text("Confirm properties", ui.ICON_SEND)
        t.bold("Initial supply:")
        t.normal(str(definition.supply), imm)
    else:
        t = Text("Confirm properties", ui.ICON_SEND)
        t.bold("Initial supply:")
        t.normal(imm)
    properties.append(t)

    # levy
    if definition.levy:

        t = Text("Confirm properties", ui.ICON_SEND)
        t.bold("Levy recipient:")
        t.mono(*split_address(definition.levy_address))
        properties.append(t)

        t = Text("Confirm properties", ui.ICON_SEND)
        t.bold("Levy fee:")
        t.normal(str(definition.fee))
        t.bold("Levy divisibility:")
        t.normal(str(definition.divisibility))
        properties.append(t)

        t = Text("Confirm properties", ui.ICON_SEND)
        t.bold("Levy namespace:")
        t.normal(definition.levy_namespace)
        t.bold("Levy mosaic:")
        t.normal(definition.levy_mosaic)
        properties.append(t)

        if definition.levy == NEMMosaicLevy.MosaicLevy_Absolute:
            levy_type = "absolute"
        else:
            levy_type = "percentile"
        t = Text("Confirm properties", ui.ICON_SEND)
        t.bold("Levy type:")
        t.normal(levy_type)
        properties.append(t)

    return properties
Esempio n. 11
0
def _get_mosaic_properties(definition: NEMMosaicDefinition):
    properties = []

    # description
    if definition.description:
        t = Text('Confirm properties', ui.ICON_SEND)
        t.bold('Description:')
        t.normal(*split_words(trim(definition.description, 70), 22))
        properties.append(t)

    # transferable
    if definition.transferable:
        transferable = 'Yes'
    else:
        transferable = 'No'
    t = Text('Confirm properties', ui.ICON_SEND)
    t.bold('Transferable?')
    t.normal(transferable)
    properties.append(t)

    # mutable_supply
    if definition.mutable_supply:
        imm = 'mutable'
    else:
        imm = 'immutable'
    if definition.supply:
        t = Text('Confirm properties', ui.ICON_SEND)
        t.bold('Initial supply:')
        t.normal(str(definition.supply), imm)
    else:
        t = Text('Confirm properties', ui.ICON_SEND)
        t.bold('Initial supply:')
        t.normal(imm)
    properties.append(t)

    # levy
    if definition.levy:

        t = Text('Confirm properties', ui.ICON_SEND)
        t.bold('Levy recipient:')
        t.mono(*split_address(definition.levy_address))
        properties.append(t)

        t = Text('Confirm properties', ui.ICON_SEND)
        t.bold('Levy fee:')
        t.normal(str(definition.fee))
        t.bold('Levy divisibility:')
        t.normal(str(definition.divisibility))
        properties.append(t)

        t = Text('Confirm properties', ui.ICON_SEND)
        t.bold('Levy namespace:')
        t.normal(definition.levy_namespace)
        t.bold('Levy mosaic:')
        t.normal(definition.levy_mosaic)
        properties.append(t)

        if definition.levy == NEMMosaicLevy.MosaicLevy_Absolute:
            levy_type = 'absolute'
        else:
            levy_type = 'percentile'
        t = Text('Confirm properties', ui.ICON_SEND)
        t.bold('Levy type:')
        t.normal(levy_type)
        properties.append(t)

    return properties