Bitpay\SinKey::generate PHP Method

generate() public method

Generates a Service Identification Number (SIN), see: https://en.bitcoin.it/wiki/Identity_protocol_v1
public generate ( ) : SinKey
return SinKey
    public function generate()
    {
        if (is_null($this->publicKey)) {
            throw new \Exception('Public Key has not been set');
        }
        $compressedValue = $this->publicKey;
        if (empty($compressedValue)) {
            throw new \Exception('The Public Key needs to be generated.');
        }
        $step1 = Util::sha256(Util::binConv($compressedValue), true);
        $step2 = Util::ripe160($step1);
        $step3 = sprintf('%s%s%s', self::SIN_VERSION, self::SIN_TYPE, $step2);
        $step4 = Util::twoSha256(Util::binConv($step3), true);
        $step5 = substr(bin2hex($step4), 0, 8);
        $step6 = $step3 . $step5;
        $this->value = Base58::encode($step6);
        return $this;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * @return SinKey
  */
 public function getSin()
 {
     if (empty($this->hex)) {
         $this->generate();
     }
     if (null === $this->sin) {
         $this->sin = new SinKey();
         $this->sin->setPublicKey($this);
         $this->sin->generate();
     }
     return $this->sin;
 }