public function handle_mpk_request($bip32_array) { $this->CI->load->model('bip32_model'); if (!isset($bip32_array['auth_id'])) { // Need this in order to delete it later, as the action is a write action. return 'Unable to proceed, no auth ID'; } $check_key_valid = \BitWasp\BitcoinLib\BIP32::import($bip32_array['key']) !== FALSE; $insert = array('user_id' => $bip32_array['user_id'], 'key' => $bip32_array['key'], 'provider' => 'Onchain'); return $check_key_valid ? ($this->CI->bip32_model->add($insert) == TRUE and $this->CI->onchain_model->clear_auth($bip32_array['auth_id'] == TRUE)) ? 'Key set up successfully!' : 'Error setting key' : 'Invalid BIP32 key'; }
public function testBIP32() { $masterkey = "tpubD9q6vq9zdP3gbhpjs7n2TRvT7h4PeBhxg1Kv9jEc1XAss7429VenxvQTsJaZhzTk54gnsHRpgeeNMbm1QTag4Wf1QpQ3gy221GDuUCxgfeZ"; $import = BIP32::import($masterkey); $this->assertEquals("022f6b9339309e89efb41ecabae60e1d40b7809596c68c03b05deb5a694e33cd26", $import['key']); $this->assertEquals("tpubDAtJthHcm9MJwmHp4r2UwSTmiDYZWHbQUMqySJ1koGxQpRNSaJdyL2Ab8wwtMm5DsMMk3v68299LQE6KhT8XPQWzxPLK5TbTHKtnrmjV8Gg", BIP32::build_key($masterkey, "0")[0]); $this->assertEquals("tpubDDfqpEKGqEVa5FbdLtwezc6Xgn81teTFFVA69ZfJBHp4UYmUmhqVZMmqXeJBDahvySZrPjpwMy4gKfNfrxuFHmzo1r6srB4MrsDKWbwEw3d", BIP32::build_key($masterkey, "0/0")[0]); $this->assertEquals("tpubDHNy3kAG39ThyiwwsgoKY4iRenXDRtce8qdCFJZXPMCJg5dsCUHayp84raLTpvyiNA9sXPob5rgqkKvkN8S7MMyXbnEhGJMW64Cf4vFAoaF", BIP32::build_key(BIP32::master_key("000102030405060708090a0b0c0d0e0f", "bitcoin", true), "M/0'/1/2'/2/1000000000")[0]); }
public function validate_depth_bip32($str) { $decode = \BitWasp\BitcoinLib\BIP32::import($str); return $decode['depth'] == '1'; }
/** * create checksum to verify ownership of the master primary key * * @return string[] [address, signature] */ protected function createChecksumVerificationSignature() { $import = BIP32::import($this->primaryPrivateKey->key()); $public = $this->primaryPrivateKey->publicKey(); $address = BitcoinLib::public_key_to_address($public, $import['version']); return [$address, BitcoinLib::signMessage($address, $import)]; }
/** * BIP32 Private Keys To Wallet * * This function accepts $wallet - a reference to an array containing * wallet info, indexed by hash160 of expected address. * It will attempt to add each key to this wallet, as well as all the * details that could be needed later on: public key, uncompressed key, * address, an indicator for address compression. Type is always set * to pubkeyhash for private key entries in the wallet. * * @param $wallet * @param array $keys * @param null $magic_byte */ public static function bip32_keys_to_wallet(&$wallet, array $keys, $magic_byte = null) { $magic_byte = BitcoinLib::magicByte($magic_byte); RawTransaction::private_keys_to_wallet($wallet, array_map(function ($key) { return BIP32::import($key[0]); }, $keys), $magic_byte); }