forked from Bit-Wasp/bitcoin-php
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sign_steps.php
58 lines (47 loc) · 1.69 KB
/
sign_steps.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
require "vendor/autoload.php";
use BitWasp\Bitcoin\Key\PrivateKeyFactory;
use BitWasp\Bitcoin\Script\Interpreter\Number;
use BitWasp\Bitcoin\Script\Opcodes;
use BitWasp\Bitcoin\Script\Path\BranchInterpreter;
use BitWasp\Bitcoin\Script\ScriptFactory;
use BitWasp\Bitcoin\Crypto\Random\Random;
$alice = PrivateKeyFactory::fromInt(1);
$bob = PrivateKeyFactory::fromInt(2);
$random = new Random();
$alicePriv = \BitWasp\Bitcoin\Key\PrivateKeyFactory::create(true);
$alicePub = $alicePriv->getPublicKey();
$bobPriv = \BitWasp\Bitcoin\Key\PrivateKeyFactory::create(true);
$bobPub = $bobPriv->getPublicKey();
$rhash1 = $random->bytes(20);
$rhash2 = $random->bytes(20);
$script = ScriptFactory::sequence([
Opcodes::OP_HASH160, Opcodes::OP_DUP, $rhash1, Opcodes::OP_EQUAL,
Opcodes::OP_IF,
Number::int(6000)->getBuffer(), Opcodes::OP_CHECKSEQUENCEVERIFY,
Opcodes::OP_2DROP, $alicePub->getBuffer(),
Opcodes::OP_ELSE,
$rhash2, Opcodes::OP_EQUAL,
Opcodes::OP_NOTIF,
Number::int(6000)->getBuffer(), Opcodes::OP_CHECKLOCKTIMEVERIFY,
Opcodes::OP_DROP,
Opcodes::OP_ENDIF,
$bobPub->getBuffer(),
Opcodes::OP_ENDIF,
Opcodes::OP_CHECKSIG
]);
echo $script->getHex().PHP_EOL;
$ast = new BranchInterpreter();
$branches = $ast->getScriptBranches($script);
foreach($branches as $branch) {
echo "Branch \n";
var_dump($branch->getPath());
echo "Sign Steps \n\n";
$steps = $branch->getSignSteps();
foreach ($steps as $step) {
echo " * " . $step->makeScript()->getScriptParser()->getHumanReadable() . PHP_EOL;
}
echo "Neutered script \n\n";
echo $branch->getNeuteredScript()->getScriptParser()->getHumanReadable().PHP_EOL;
echo "=======\n";
}