|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Blocktrail\SDK; |
|
4
|
|
|
|
|
5
|
|
|
use BitWasp\Bitcoin\Mnemonic\MnemonicFactory; |
|
6
|
|
|
use BitWasp\Buffertools\BufferInterface; |
|
7
|
|
|
use Blocktrail\SDK\Exceptions\BlocktrailSDKException; |
|
8
|
|
|
use Btccom\JustEncrypt\Encryption; |
|
9
|
|
|
use Btccom\JustEncrypt\EncryptionMnemonic; |
|
10
|
|
|
|
|
11
|
|
|
class WalletV3Sweeper extends WalletSweeper |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @param string $encryptedPrimaryMnemonic |
|
15
|
|
|
* @param string $encryptedSecretMnemonic |
|
16
|
|
|
* @param string $backupMnemonic |
|
17
|
|
|
* @param BufferInterface $passphrase |
|
18
|
|
|
* @param array $blocktrailPublicKeys |
|
19
|
|
|
* @param UnspentOutputFinder $utxoFinder |
|
20
|
|
|
* @param string $network |
|
21
|
|
|
* @param bool $testnet |
|
22
|
|
|
* @throws BlocktrailSDKException |
|
23
|
|
|
*/ |
|
24
|
1 |
|
public function __construct($encryptedPrimaryMnemonic, $encryptedSecretMnemonic, $backupMnemonic, BufferInterface $passphrase, array $blocktrailPublicKeys, UnspentOutputFinder $utxoFinder, $network = 'btc', $testnet = false) { |
|
25
|
|
|
// cleanup copy paste errors from mnemonics |
|
26
|
1 |
|
$encryptedPrimaryMnemonic = str_replace(" ", " ", str_replace("\r\n", " ", str_replace("\n", " ", trim($encryptedPrimaryMnemonic)))); |
|
27
|
1 |
|
$encryptedSecretMnemonic = str_replace(" ", " ", str_replace("\r\n", " ", str_replace("\n", " ", trim($encryptedSecretMnemonic)))); |
|
28
|
1 |
|
$backupMnemonic = str_replace(" ", " ", str_replace("\r\n", " ", str_replace("\n", " ", trim($backupMnemonic)))); |
|
29
|
|
|
|
|
30
|
1 |
|
if (!($secret = Encryption::decrypt(EncryptionMnemonic::decode($encryptedSecretMnemonic), $passphrase))) { |
|
31
|
|
|
throw new BlocktrailSDKException("Failed to decret password encrypted secret"); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
1 |
|
if (!($primarySeed = Encryption::decrypt(EncryptionMnemonic::decode($encryptedPrimaryMnemonic), $secret))) { |
|
35
|
|
|
throw new BlocktrailSDKException("failed to decrypt encrypted primary seed! (weird!)"); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
1 |
|
$backupMnemonic = MnemonicFactory::bip39()->mnemonicToEntropy($backupMnemonic); |
|
39
|
1 |
|
parent::__construct($primarySeed, $backupMnemonic, $blocktrailPublicKeys, $utxoFinder, $network, $testnet); |
|
40
|
1 |
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|