-
Notifications
You must be signed in to change notification settings - Fork 0
/
brfc.php
82 lines (67 loc) · 1.33 KB
/
brfc.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
# BRFC ID generator in PHP language.
# Based on: https://github.com/moneybutton/brfc
declare(strict_types=1);
function brfcID(string $title,string $author,string $version):string {
$brfcID = array(
$title,
$author,
$version
);
$brfcID = array_map(
'trim',
$brfcID
);
$brfcID = implode(
'',
$brfcID
);
$brfcID = hash(
'sha256',
$brfcID,
true
);
$brfcID = hash(
'sha256',
$brfcID,
true
);
$brfcID = strrev($brfcID);
$brfcID = bin2hex($brfcID);
return substr(
$brfcID,
0,
12
);
}
header('Content-Type: text/plain');
const TESTS = array(
'57dd1f54fc67'=>array(
'title'=>'BRFC Specifications',
'author'=>'andy (nChain)',
'version'=>'1',
),
'74524c4d6274'=>array(
'title'=>'bsvalias Payment Addressing (PayTo Protocol Prefix)',
'author'=>'andy (nChain)',
'version'=>'1',
),
'0036f9b8860f'=>array(
'title'=>'bsvalias Integration with Simplified Payment Protocol',
'author'=>'andy (nChain)',
'version'=>'1',
),
);
foreach (TESTS as $expectedResult=>$ids) {
$testResult = brfcID(
$ids['title'],
$ids['author'],
$ids['version']
);
echo "Result:\t\t\t",$testResult;
echo PHP_EOL;
echo "Should be:\t\t",$expectedResult;
echo PHP_EOL;
echo str_repeat('-',55);
echo PHP_EOL;
}