Example #1
0
def create_nonce(idx):
    if idx != get_master_nonce_idx():
        old_nonce = config.get(beam_app_id(), idx)
        new_nonce = bytearray(32)
        if old_nonce:
                new_nonce = bytearray(old_nonce)
        master_nonce = config.get(beam_app_id(), get_master_nonce_idx())
        beam.create_derived_nonce(master_nonce, idx, new_nonce)
        config.set(beam_app_id(), idx, new_nonce)
        return old_nonce, new_nonce
Example #2
0
async def get_nonce_public(ctx, msg):
    idx = msg.slot
    if idx == get_master_nonce_idx() or idx > 255:
        return Failure(message='Incorrect slot provided')

    if not is_master_nonce_created():
        return Failure(message='Nonce Generator is not initialized')

    pubkey_x, pubkey_y = get_nonce_pub(msg.slot)
    return BeamECCPoint(x=pubkey_x, y=int(pubkey_y[0]))
Example #3
0
async def generate_nonce(ctx, msg):
    gc.collect()

    idx = msg.slot
    if idx == get_master_nonce_idx() or idx > 255:
        return Failure(message="Incorrect slot provided")

    if not is_master_nonce_created():
        return Failure(message="Nonce Generator is not initialized")

    _, new_nonce = create_nonce(idx)
    pubkey_x, pubkey_y = calc_nonce_pub(new_nonce)
    return BeamECCPoint(x=pubkey_x, y=int(pubkey_y[0]))
Example #4
0
def create_master_nonce(seed):
    master_nonce = bytearray(32)
    beam.create_master_nonce(master_nonce, seed)
    config.set(beam_app_id(), get_master_nonce_idx(), master_nonce)
    for idx in range(1, 255):
        consume_nonce(idx)
Example #5
0
def get_nonce_pub(idx):
    if idx != get_master_nonce_idx():
        nonce = config.get(beam_app_id(), idx)
        return calc_nonce_pub(nonce)
Example #6
0
def is_master_nonce_created():
    master_nonce = config.get(beam_app_id(), get_master_nonce_idx())
    return master_nonce is not None