forked from Bit-Wasp/bitcoin-php
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaddresstypes.script.php
41 lines (30 loc) · 1.35 KB
/
addresstypes.script.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
<?php
use BitWasp\Bitcoin\Address\AddressCreator;
use BitWasp\Bitcoin\Key\Factory\PrivateKeyFactory;
use BitWasp\Bitcoin\Key\KeyToScript\Factory\P2pkhScriptDataFactory;
use BitWasp\Bitcoin\Script\P2shScript;
use BitWasp\Bitcoin\Script\WitnessScript;
require __DIR__ . "/../vendor/autoload.php";
$addrReader = new AddressCreator();
$privFactory = new PrivateKeyFactory();
$priv = $privFactory->fromWif('L1U6RC3rXfsoAx3dxsU1UcBaBSRrLWjEwUGbZPxWX9dBukN345R1');
$publicKey = $priv->getPublicKey();
$helper = new P2pkhScriptDataFactory();
$scriptData = $helper->convertKey($publicKey);
$script = $scriptData->getScriptPubKey();
### Key hash types
echo "key hash types\n";
$p2pkh = $scriptData->getAddress($addrReader);
echo " * p2pkh address: {$p2pkh->getAddress()}\n";
#### Script hash types
echo "\nscript hash types:\n";
// taking an available script to be another addresses redeem script..
$redeemScript = new P2shScript($p2pkh->getScriptPubKey());
$p2shAddr = $redeemScript->getAddress();
echo " * p2sh: {$p2shAddr->getAddress()}\n";
$p2wshScript = new WitnessScript($p2pkh->getScriptPubKey());
$p2wshAddr = $p2wshScript->getAddress();
echo " * p2wsh: {$p2wshAddr->getAddress()}\n";
$p2shP2wshScript = new P2shScript(new WitnessScript($p2pkh->getScriptPubKey()));
$p2shP2wshAddr = $p2shP2wshScript->getAddress();
echo " * p2sh|p2wsh: {$p2shP2wshAddr->getAddress()}\n";