-
Notifications
You must be signed in to change notification settings - Fork 3
/
ecp-mpkgen.php
44 lines (40 loc) · 2.12 KB
/
ecp-mpkgen.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
defined( 'ABSPATH' ) or die( 'Bitcoin is for all!' );
// https://github.com/bkkcoins/misc
//
// Example using GenAddress as a cmd line utility
//
// requires phpecc library
// easy way is: git clone git://github.com/mdanter/phpecc.git
// in the directory where this code lives
// and then this loader below will take care of it.
// bcmath module in php seems to be very slow
// apparently the gmp module is much faster
// base2dec needs to be written for gmp as phpecc is missing it
// ===========================================================================
function ECP__MATH_generate_bitcoin_address_from_mpk_v1( $master_public_key, $key_index ) {
return ElectrumHelper::mpk_to_bc_address( $master_public_key, $key_index, ElectrumHelper::V1 );
}
// ===========================================================================
// ===========================================================================
function ECP__MATH_generate_bitcoin_address_from_mpk_v2( $master_public_key, $key_index, $is_for_change = false ) {
return ElectrumHelper::mpk_to_bc_address( $master_public_key, $key_index, ElectrumHelper::V2, $is_for_change );
}
// ===========================================================================
// ===========================================================================
function ECP__MATH_generate_bitcoin_address_from_mpk( $master_public_key, $key_index, $is_for_change = false ) {
if ( USE_EXT != 'GMP' && USE_EXT != 'BCMATH' ) {
ECP__log_event( __FILE__, __LINE__, 'Neither GMP nor BCMATH PHP math libraries are present. Aborting.' );
return false;
}
if ( preg_match( '/^[a-f0-9]{128}$/', $master_public_key ) ) {
// return ECP__MATH_generate_bitcoin_address_from_mpk_v1($master_public_key, $key_index);
return false;// TODO remove mpkv1
}
if ( preg_match( '/^xpub[a-zA-Z0-9]{107}$/', $master_public_key ) ) {
return ECP__MATH_generate_bitcoin_address_from_mpk_v2( $master_public_key, $key_index, $is_for_change );
}
ECP__log_event( __FILE__, __LINE__, "Invalid MPK passed: '$master_public_key'. Aborting." );
return false;
}
// ===========================================================================