Example #1
0
ptree prop_list(const tx_output_type& tx_output)
{
    ptree tree;
    const auto address = payment_address::extract(tx_output.script);
    if (address)
        tree.put("address", address);

    tree.put("script", script(tx_output.script).to_string());

    // TODO: this will eventually change due to privacy problems, see:
    // lists.dyne.org/lurker/message/20140812.214120.317490ae.en.html

    if (!address)
    {
        uint32_t stealth_prefix;
        ec_compressed ephemeral_key;
        if (to_stealth_prefix(stealth_prefix, tx_output.script) &&
            extract_ephemeral_key(ephemeral_key, tx_output.script))
        {
            tree.put("stealth.prefix", stealth_prefix);
            tree.put("stealth.ephemeral_public_key", ec_public(ephemeral_key));
        }
    }

    tree.put("value", tx_output.value);
    return tree;
}
Example #2
0
int ec_generate(struct ec_key *key, int bits, progfn_t pfn,
                void *pfnparam)
{
    struct ec_point *publicKey;

    if (bits == 256) {
        key->publicKey.curve = ec_p256();
    } else if (bits == 384) {
        key->publicKey.curve = ec_p384();
    } else if (bits == 521) {
        key->publicKey.curve = ec_p521();
    } else {
        return 0;
    }

    key->privateKey = bignum_random_in_range(One, key->publicKey.curve->w.n);
    if (!key->privateKey) return 0;

    publicKey = ec_public(key->privateKey, key->publicKey.curve);
    if (!publicKey) {
        freebn(key->privateKey);
        key->privateKey = NULL;
        return 0;
    }

    key->publicKey.x = publicKey->x;
    key->publicKey.y = publicKey->y;
    key->publicKey.z = NULL;
    sfree(publicKey);

    return 1;
}
Example #3
0
int ec_generate(struct ec_key *key, int bits, progfn_t pfn, void *pfnparam)
{
  struct ec_point *publicKey;

  if (!ec_nist_alg_and_curve_by_bits(
          bits, &key->publicKey.curve, &key->signalg))
    return 0;

  key->privateKey = bignum_random_in_range(One, key->publicKey.curve->w.n);
  if (!key->privateKey)
    return 0;

  publicKey = ec_public(key->privateKey, key->publicKey.curve);
  if (!publicKey) {
    freebn(key->privateKey);
    key->privateKey = NULL;
    return 0;
  }

  key->publicKey.x = publicKey->x;
  key->publicKey.y = publicKey->y;
  key->publicKey.z = NULL;
  sfree(publicKey);

  return 1;
}
Example #4
0
int ec_edgenerate(struct ec_key *key, int bits, progfn_t pfn, void *pfnparam)
{
  struct ec_point *publicKey;

  if (!ec_ed_alg_and_curve_by_bits(bits, &key->publicKey.curve, &key->signalg))
    return 0;

  {
    /* EdDSA secret keys are just 32 bytes of hash preimage; the
     * 64-byte SHA-512 hash of that key will be used when signing,
     * but the form of the key stored on disk is the preimage
     * only. */
    Bignum privMax = bn_power_2(bits);
    if (!privMax)
      return 0;
    key->privateKey = bignum_random_in_range(Zero, privMax);
    freebn(privMax);
    if (!key->privateKey)
      return 0;
  }

  publicKey = ec_public(key->privateKey, key->publicKey.curve);
  if (!publicKey) {
    freebn(key->privateKey);
    key->privateKey = NULL;
    return 0;
  }

  key->publicKey.x = publicKey->x;
  key->publicKey.y = publicKey->y;
  key->publicKey.z = NULL;
  sfree(publicKey);

  return 1;
}
ptree prop_list(const chain::stealth& row)
{
    ptree tree;
    tree.put("ephemeral_public_key", ec_public(row.ephemeral_public_key));
    tree.put("public_key_hash", btc160(row.public_key_hash));
    tree.put("transaction_hash", btc256(row.transaction_hash));
    return tree;
}
Example #6
0
ptree prop_list(const stealth_address& stealth)
{
    // We don't serialize a "reuse key" value as this is strictly an
    // optimization for the purpose of serialization and otherwise complicates
    // understanding of what is actually otherwise very simple behavior.
    // So instead we emit the reused key as one of the spend keys.
    // This means that it is typical to see the same key in scan and spend.

    auto spend_keys = cast<ec_compressed, ec_public>(stealth.spend_keys());
    auto spend_keys_prop_values = prop_value_list("public_key", spend_keys);

    ptree tree;
    tree.put("encoded", stealth);
    tree.put("filter", stealth.filter());
    tree.put("scan_public_key", ec_public(stealth.scan_key()));
    tree.put("signatures", stealth.signatures());
    tree.add_child("spend", spend_keys_prop_values);
    tree.put("version", stealth.version());
    return tree;
}