Beispiel #1
0
<?php

require 'vendor/autoload.php';
use TheFox\Pow\Hashcash;
// Example 1: simple mint (real world example)
$hashcash = new Hashcash();
$hashcash->setBits(20);
$hashcash->setResource('*****@*****.**');
try {
    print "stamp1: '" . $hashcash->mint() . "'\n";
} catch (Exception $e) {
    print 'ERROR 1: ' . $e->getMessage() . "\n";
}
// Example 2a: simple mint, another way (real world example)
$hashcash = new Hashcash(20, '*****@*****.**');
$stamp = '';
try {
    $stamp = $hashcash->mint();
    print "stamp2: '" . $stamp . "'\n";
} catch (Exception $e) {
    print 'ERROR 2: ' . $e->getMessage() . "\n";
}
// Example 2b: verify a stamp (real world example)
$hashcash = new Hashcash();
try {
    print "stamp2 verify: '" . ($hashcash->verify($stamp) ? 'Ok' : 'failed') . "'\n";
} catch (Exception $e) {
    print 'ERROR 3: ' . $e->getMessage() . "\n";
}
// Example 3a: use a certain date
$hashcash = new Hashcash(20, '*****@*****.**');
Beispiel #2
0
 public function testDoublespend2()
 {
     #fwrite(STDOUT, __METHOD__."\n");
     $db = new HashcashDb();
     $hashcash = new Hashcash();
     $hashcash->setVersion(1);
     $hashcash->setBits(5);
     $hashcash->setResource('thefox');
     $hashcash->setSuffix(1);
     $this->assertTrue($db->addHashcash($hashcash));
     $hashcash = new Hashcash();
     $hashcash->setVersion(1);
     $hashcash->setBits(5);
     $hashcash->setResource('thefox');
     $hashcash->setSuffix(1);
     $this->assertFalse($db->addHashcash($hashcash));
     $this->assertEquals(1, count($db->getHashcashs()));
 }
Beispiel #3
0
 public function testVerify()
 {
     #$this->markTestIncomplete('This test has not been implemented yet.');
     #$this->assertTrue(true); return;
     $hashcash = new Hashcash();
     $hashcash->setExpiration(0);
     $this->assertTrue($hashcash->verify('1:20:140422:mint2::ArrRIabEj3nZrOcM:0000000000007u1E'));
     $this->assertTrue($hashcash->verify('1:24:140422:mint2:ext1:Nde2ffWsRoe3DXVQ:00000001M+iu'));
     $this->assertTrue($hashcash->verify('1:20:140422:mint2:ext2:salt2:256507'));
     $this->assertTrue($hashcash->verify('1:28:140422:::s15xXleWocBKSA95Zw4e1Q==:245861178'));
     $this->assertTrue($hashcash->verify('1:21:870221:thefox::2B6kv/rFiCdJRzqhH7P2eA==:995214'));
     $this->assertFalse($hashcash->verify('1:20:140422:mint3::ArrRIabEj3nZrOcM:0000000000007u1E'));
     $hashcash->setExpiration(3600 * 24 * 365);
     $this->assertFalse($hashcash->verify('1:21:870221:thefox::2B6kv/rFiCdJRzqhH7P2eA==:995214'));
     $hashcash1 = new Hashcash();
     $hashcash1->setBits(10);
     $hashcash2 = new Hashcash();
     $this->assertTrue($hashcash2->verify($hashcash1->mint()));
 }