| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace BitWasp\Bitcoin\Key\Deterministic\Slip132; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use BitWasp\Bitcoin\Bitcoin; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use BitWasp\Bitcoin\Key\Deterministic\HdPrefix\ScriptPrefix; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use BitWasp\Bitcoin\Key\KeyToScript\ScriptDataFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use BitWasp\Bitcoin\Key\KeyToScript\KeyToScriptHelper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | class Slip132 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |      * @var KeyToScriptHelper | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     private $helper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * Slip132PrefixRegistry constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * @param KeyToScriptHelper $helper | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 | 23 |  |     public function __construct(KeyToScriptHelper $helper = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 | 23 |  |         $this->helper = $helper ?: new KeyToScriptHelper(Bitcoin::getEcAdapter()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 | 23 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @param PrefixRegistry $registry | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @param ScriptDataFactory $factory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * @return ScriptPrefix | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 32 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 33 | 23 |  |     private function loadPrefix(PrefixRegistry $registry, ScriptDataFactory $factory) | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 35 | 23 |  |         list ($private, $public) = $registry->getPrefixes($factory->getScriptType()); | 
            
                                                                        
                            
            
                                    
            
            
                | 36 | 23 |  |         return new ScriptPrefix($factory, $private, $public); | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * xpub on bitcoin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @param PrefixRegistry $registry | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * @return ScriptPrefix | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 6 |  |     public function p2pkh(PrefixRegistry $registry) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 6 |  |         return $this->loadPrefix($registry, $this->helper->getP2pkhFactory()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * xpub on bitcoin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * @param PrefixRegistry $registry | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * @return ScriptPrefix | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @throws \BitWasp\Bitcoin\Exceptions\DisallowedScriptDataFactoryException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 2 |  |     public function p2shP2pkh(PrefixRegistry $registry) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 2 |  |         return $this->loadPrefix($registry, $this->helper->getP2shFactory($this->helper->getP2pkhFactory())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * ypub on bitcoin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @param PrefixRegistry $registry | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * @return ScriptPrefix | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * @throws \BitWasp\Bitcoin\Exceptions\DisallowedScriptDataFactoryException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 5 |  |     public function p2shP2wpkh(PrefixRegistry $registry) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 5 |  |         return $this->loadPrefix($registry, $this->helper->getP2shFactory($this->helper->getP2wpkhFactory())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * Ypub on bitcoin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * @param PrefixRegistry $registry | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * @return ScriptPrefix | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * @throws \BitWasp\Bitcoin\Exceptions\DisallowedScriptDataFactoryException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 2 |  |     public function p2shP2wshP2pkh(PrefixRegistry $registry) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 2 |  |         return $this->loadPrefix($registry, $this->helper->getP2shP2wshFactory($this->helper->getP2pkhFactory())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * zpub on bitcoin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * @param PrefixRegistry $registry | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * @return ScriptPrefix | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 | 6 |  |     public function p2wpkh(PrefixRegistry $registry) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 6 |  |         return $this->loadPrefix($registry, $this->helper->getP2wpkhFactory()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * Zpub on bitcoin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * @param PrefixRegistry $registry | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      * @return ScriptPrefix | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      * @throws \BitWasp\Bitcoin\Exceptions\DisallowedScriptDataFactoryException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 | 2 |  |     public function p2wshP2pkh(PrefixRegistry $registry) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 | 2 |  |         return $this->loadPrefix($registry, $this->helper->getP2wshFactory($this->helper->getP2pkhFactory())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 108 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 109 |  |  |  |