From db966b1a9156af56c7ae7337bae044285df89d4c Mon Sep 17 00:00:00 2001 From: Thomas Kerin Date: Thu, 11 Oct 2018 13:12:11 +0200 Subject: [PATCH] CreateWallet: allow disabling wallet until it's confirmed by another endpoint --- src/BlocktrailSDK.php | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/BlocktrailSDK.php b/src/BlocktrailSDK.php index 9bef815..09cdd56 100644 --- a/src/BlocktrailSDK.php +++ b/src/BlocktrailSDK.php @@ -737,7 +737,8 @@ protected function createNewWalletV1($options) { $primaryMnemonic, $checksum, $options['key_index'], - array_key_exists('segwit', $options) ? $options['segwit'] : false + array_key_exists('segwit', $options) ? $options['segwit'] : false, + array_key_exists('require_activation', $options) ? $options['require_activation'] : false ); // received the blocktrail public keys @@ -859,7 +860,8 @@ protected function createNewWalletV2($options) { $storeDataOnServer ? $recoverySecret : false, $checksum, $options['key_index'], - array_key_exists('segwit', $options) ? $options['segwit'] : false + array_key_exists('segwit', $options) ? $options['segwit'] : false, + array_key_exists('require_activation', $options) ? $options['require_activation'] : false ); // received the blocktrail public keys @@ -1004,7 +1006,8 @@ protected function createNewWalletV3($options) { $storeDataOnServer ? $recoverySecret->getHex() : false, $checksum, $options['key_index'], - array_key_exists('segwit', $options) ? $options['segwit'] : false + array_key_exists('segwit', $options) ? $options['segwit'] : false, + array_key_exists('require_activation', $options) ? $options['require_activation'] : false ); // received the blocktrail public keys @@ -1084,9 +1087,12 @@ private function verifyPublicOnly(array $walletData) { * @param string $checksum checksum to store * @param int $keyIndex account that we expect to use * @param bool $segwit opt in to segwit + * @param bool $requireActivation require wallet to be activated by another endpoint * @return mixed + * @throws BlocktrailSDKException + * @throws \Exception */ - public function storeNewWalletV1($identifier, $primaryPublicKey, $backupPublicKey, $primaryMnemonic, $checksum, $keyIndex, $segwit = false) { + public function storeNewWalletV1($identifier, $primaryPublicKey, $backupPublicKey, $primaryMnemonic, $checksum, $keyIndex, $segwit = false, $requireActivation = false) { $data = [ 'identifier' => $identifier, 'primary_public_key' => $primaryPublicKey, @@ -1096,6 +1102,9 @@ public function storeNewWalletV1($identifier, $primaryPublicKey, $backupPublicKe 'key_index' => $keyIndex, 'segwit' => $segwit, ]; + if ($requireActivation) { + $data['require_activation'] = true; + } $this->verifyPublicOnly($data); $response = $this->blocktrailClient->post("wallet", null, $data, RestClient::AUTH_HTTP_SIG); return self::jsonDecode($response->body(), true); @@ -1113,10 +1122,12 @@ public function storeNewWalletV1($identifier, $primaryPublicKey, $backupPublicKe * @param string $checksum checksum to store * @param int $keyIndex account that we expect to use * @param bool $segwit opt in to segwit + * @param bool $requireActivation require wallet to be activated by another endpoint * @return mixed + * @throws BlocktrailSDKException * @throws \Exception */ - public function storeNewWalletV2($identifier, $primaryPublicKey, $backupPublicKey, $encryptedPrimarySeed, $encryptedSecret, $recoverySecret, $checksum, $keyIndex, $segwit = false) { + public function storeNewWalletV2($identifier, $primaryPublicKey, $backupPublicKey, $encryptedPrimarySeed, $encryptedSecret, $recoverySecret, $checksum, $keyIndex, $segwit = false, $requireActivation = false) { $data = [ 'identifier' => $identifier, 'wallet_version' => Wallet::WALLET_VERSION_V2, @@ -1129,6 +1140,9 @@ public function storeNewWalletV2($identifier, $primaryPublicKey, $backupPublicKe 'key_index' => $keyIndex, 'segwit' => $segwit, ]; + if ($requireActivation) { + $data['require_activation'] = true; + } $this->verifyPublicOnly($data); $response = $this->blocktrailClient->post("wallet", null, $data, RestClient::AUTH_HTTP_SIG); return self::jsonDecode($response->body(), true); @@ -1146,11 +1160,12 @@ public function storeNewWalletV2($identifier, $primaryPublicKey, $backupPublicKe * @param string $checksum checksum to store * @param int $keyIndex account that we expect to use * @param bool $segwit opt in to segwit + * @param bool $requireActivation require wallet to be activated by another endpoint * @return mixed + * @throws BlocktrailSDKException * @throws \Exception */ - public function storeNewWalletV3($identifier, $primaryPublicKey, $backupPublicKey, $encryptedPrimarySeed, $encryptedSecret, $recoverySecret, $checksum, $keyIndex, $segwit = false) { - + public function storeNewWalletV3($identifier, $primaryPublicKey, $backupPublicKey, $encryptedPrimarySeed, $encryptedSecret, $recoverySecret, $checksum, $keyIndex, $segwit = false, $requireActivation = false) { $data = [ 'identifier' => $identifier, 'wallet_version' => Wallet::WALLET_VERSION_V3, @@ -1163,7 +1178,9 @@ public function storeNewWalletV3($identifier, $primaryPublicKey, $backupPublicKe 'key_index' => $keyIndex, 'segwit' => $segwit, ]; - + if ($requireActivation) { + $data['require_activation'] = true; + } $this->verifyPublicOnly($data); $response = $this->blocktrailClient->post("wallet", null, $data, RestClient::AUTH_HTTP_SIG); return self::jsonDecode($response->body(), true);