-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_keys.php
38 lines (36 loc) · 980 Bytes
/
convert_keys.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
<?php
require_once 'vendor/autoload.php';
use swentel\nostr\Key\Key;
$postdata = file_get_contents("php://input");
$req = json_decode($postdata);
// BECH32 TO HEX
if ($req->msg == 'convert_to_hex') {
$key = new Key();
$okey = $req->keyx;
$tohex = $key->convertToHex($okey);
$message = [
'status' => 1,
'hex_key' => $tohex
];
exit(json_encode($message));
}
// HEX TO BECH32
else if ($req->msg == 'convert_to_bech32') {
$key = new Key();
$public_key = $req->pubkey;
$private_key = $req->privkey;
$bech32_public = $key->convertPublicKeyToBech32($public_key);
$bech32_private = $key->convertPrivateKeyToBech32($private_key);
$message = [
'status' => 1,
'public_key' => $bech32_public,
'private_key' => $bech32_private
];
exit(json_encode($message));
} else {
$message = [
'status' => 0,
'message' => 'Key Conversion failed!'
];
exit(json_encode($message));
}