-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path09-trust-code-verification.php
More file actions
107 lines (82 loc) · 2.47 KB
/
Copy path09-trust-code-verification.php
File metadata and controls
107 lines (82 loc) · 2.47 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/**
* PPS-PHP Example 09: Trust Code Verification
*
* Demonstrates Trust Code generation and verification:
* 1. Generate Trust Code from signature
* 2. Verify Trust Code matches
* 3. AmountMark embedding
*
* Usage:
* php examples/09-trust-code-verification.php
*/
declare(strict_types=1);
require_once __DIR__ . '/../vendor/autoload.php';
use Pps\Crypto\Base64Url;
use Pps\Crypto\Ed25519;
use Pps\Key\KeyManager;
use Pps\Trust\AmountMark;
use Pps\Trust\TrustCodeGenerator;
use Pps\Trust\TrustPhraseGenerator;
echo "=== PPS-PHP Example 09: Trust Code Verification ===\n\n";
$rpId = 'example.com';
$nonce = random_bytes(16);
$epoch = intdiv(time(), 30);
// Generate a test signature
$key = KeyManager::generateKeyPair();
$message = 'test-message';
$signature = Ed25519::sign($message, $key->secretKey);
// ---------------------------------------------------------------
// Step 1: Generate Trust Code
// ---------------------------------------------------------------
echo "Step 1: Generate Trust Code\n";
$trustCode = TrustCodeGenerator::generate(
$signature,
$rpId,
$nonce,
$epoch,
8
);
echo " Trust Code: $trustCode\n";
// ---------------------------------------------------------------
// Step 2: Verify Trust Code
// ---------------------------------------------------------------
echo "\nStep 2: Verify Trust Code\n";
$valid = TrustCodeGenerator::verify(
$trustCode,
$signature,
$rpId,
$nonce,
$epoch
);
echo " Valid: " . ($valid ? 'YES' : 'NO') . "\n";
// ---------------------------------------------------------------
// Step 3: AmountMark embedding
// ---------------------------------------------------------------
echo "\nStep 3: AmountMark embedding\n";
$amountMinor = 2500067;
$amountMark = AmountMark::generate($amountMinor);
$trustCodeWithAmount = TrustCodeGenerator::generate(
$signature,
$rpId,
$nonce,
$epoch,
8,
$amountMinor
);
echo " Amount: " . number_format($amountMinor) . "\n";
echo " AmountMark: $amountMark\n";
echo " Trust Code: $trustCodeWithAmount\n";
echo " Last 2 digits: " . substr($trustCodeWithAmount, -2) . "\n";
// ---------------------------------------------------------------
// Step 4: Trust Phrase
// ---------------------------------------------------------------
echo "\nStep 4: Trust Phrase\n";
$trustPhrase = TrustPhraseGenerator::generate(
$signature,
$rpId,
$nonce,
$epoch
);
echo " Trust Phrase: $trustPhrase\n";
echo "\n=== Example 09 Complete ===\n";