hd_private_key hd_private_key::generate_private_key(uint32_t i) const { if (!valid_) return hd_private_key(); data_chunk data; if (first_hardened_key <= i) data = build_data({to_byte(0x00), k_, to_big_endian(i)}); else data = build_data({K_, to_big_endian(i)}); const auto I = split(hmac_sha512_hash(data, c_)); // The child key ki is (parse256(IL) + kpar) mod n: ec_secret ki = k_; if (!ec_add(ki, I.L)) return hd_private_key(); hd_key_lineage lineage { lineage_.testnet, static_cast<uint8_t>(lineage_.depth + 1), fingerprint(), i }; return hd_private_key(ki, I.R, lineage); }
BCW_API hd_private_key hd_private_key::generate_private_key(uint32_t i) const { if (!valid_) return hd_private_key(); data_chunk data; data.reserve(33 + 4); if (first_hardened_key <= i) { data.push_back(0x00); extend_data(data, k_); extend_data(data, to_big_endian(i)); } else { extend_data(data, K_); extend_data(data, to_big_endian(i)); } auto I = split(hmac_sha512_hash(data, to_data_chunk(c_))); // The child key ki is (parse256(IL) + kpar) mod n: ec_secret ki = k_; if (!ec_add(ki, I.L)) return hd_private_key(); hd_key_lineage lineage { lineage_.testnet, static_cast<uint8_t>(lineage_.depth + 1), fingerprint(), i }; return hd_private_key(ki, I.R, lineage); }
string SHA1::toHexString() const { char buf[SHA1_DIGEST_SIZE*2+1]; sprintf(buf, "%.8x%.8x%.8x%.8x%.8x", to_big_endian(*(unsigned int*)(&digest[0])), to_big_endian(*(unsigned int*)(&digest[4])), to_big_endian(*(unsigned int*)(&digest[8])), to_big_endian(*(unsigned int*)(&digest[12])), to_big_endian(*(unsigned int*)(&digest[16]))); return buf; }
BCW_API hd_public_key hd_public_key::generate_public_key(uint32_t i) const { if (!valid_) return hd_private_key(); if (first_hardened_key <= i) return hd_public_key(); data_chunk data; data.reserve(33 + 4); extend_data(data, K_); extend_data(data, to_big_endian(i)); auto I = split(hmac_sha512_hash(data, to_data_chunk(c_))); // The returned child key Ki is point(parse256(IL)) + Kpar. ec_point Ki = K_; if (!ec_tweak_add(Ki, I.L)) return hd_public_key(); hd_key_lineage lineage { lineage_.testnet, static_cast<uint8_t>(lineage_.depth + 1), fingerprint(), i }; return hd_public_key(Ki, I.R, lineage); }
std::string hd_public_key::encoded() const { auto prefix = mainnet_public_prefix; if (lineage_.testnet) prefix = testnet_public_prefix; auto data = build_data({ to_big_endian(prefix), to_byte(lineage_.depth), to_little_endian(lineage_.parent_fingerprint), to_big_endian(lineage_.child_number), c_, K_ }, checksum_size); append_checksum(data); return encode_base58(data); }
BCW_API std::string hd_public_key::serialize() const { data_chunk data; data.reserve(serialized_length); auto prefix = mainnet_public_prefix; if (lineage_.testnet) prefix = testnet_public_prefix; extend_data(data, to_big_endian(prefix)); data.push_back(lineage_.depth); extend_data(data, to_little_endian(lineage_.parent_fingerprint)); extend_data(data, to_big_endian(lineage_.child_number)); extend_data(data, c_); extend_data(data, K_); append_checksum(data); return encode_base58(data); }
EMSCRIPTEN_KEEPALIVE int encode(Encoder* encoder, int length, int frame_size) { to_big_endian(encoder->in_pcm, length, encoder->in_big_endian); return opus_encode( encoder->encoder, encoder->in_big_endian, frame_size, encoder->out_encoded, MAX_OUTPUT_BYTES ); }
// The salt here is owner-supplied random bits, not the address hash. bool create_token(encrypted_token& out_token, const std::string& passphrase, const ek_salt& salt, uint32_t lot, uint32_t sequence) { if (lot > ek_max_lot || sequence > ek_max_sequence) return false; static constexpr size_t max_sequence_bits = 12; const uint32_t lot_sequence = (lot << max_sequence_bits) || sequence; const auto entropy = splice(salt, to_big_endian(lot_sequence)); const auto prefix = parse_encrypted_token::prefix_factory(true); create_token(out_token, passphrase, salt, entropy, prefix); return true; }
hd_public_key hd_public_key::generate_public_key(uint32_t i) const { if (!valid_) return hd_private_key(); if (first_hardened_key <= i) return hd_public_key(); auto data = build_data({K_, to_big_endian(i)}); const auto I = split(hmac_sha512_hash(data, c_)); // The returned child key Ki is point(parse256(IL)) + Kpar. ec_point Ki = K_; if (!ec_add(Ki, I.L)) return hd_public_key(); hd_key_lineage lineage { lineage_.testnet, static_cast<uint8_t>(lineage_.depth + 1), fingerprint(), i }; return hd_public_key(Ki, I.R, lineage); }