-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.html
More file actions
79 lines (57 loc) · 2.43 KB
/
test.html
File metadata and controls
79 lines (57 loc) · 2.43 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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>phpcoinCrypto Test</title>
</head>
<body>
<h3>phpcoin-crypto lib test</h3>
<hr/>
<pre style="font-size: 1rem; line-height: 1.5; white-space: pre-line; word-break: break-all">
<script src="dist/phpcoin-crypto.browser.js"></script>
<script>
function write(s) {
console.log(s)
document.write(JSON.stringify(s)+"\n")
}
let account = phpcoinCrypto.generateAccount()
write(account)
let msg = "some message";
let signature = phpcoinCrypto.sign(msg, account.privateKey)
write({signature})
let verified = phpcoinCrypto.verify(msg, signature, account.publicKey)
write({verified})
if(!verified) alert( "Signature verification failed")
let string = "SOME STRING"
let pass = "SOME PASS"
write({string, pass})
let encrypted = phpcoinCrypto.encryptString(string, pass)
write({encrypted})
let decrypted = phpcoinCrypto.decryptString(encrypted, pass)
write({decrypted})
if(decrypted !== string) alert("Decryption failed")
let account2 = phpcoinCrypto.importPrivateKey(account.privateKey)
write({account2})
if(account.address !== account.address) alert("Importing private key failed")
let publicKey = phpcoinCrypto.getPublicKey(account2.privateKey)
write({publicKey})
if(publicKey !== account2.publicKey) alert("Getting public key failed")
let randomString = phpcoinCrypto.generateRandomString(10)
write({randomString})
let input = 'some_input'
let hash = phpcoinCrypto.sha256(input)
write({hash})
if(hash !== '0dc1e7e935329cc6e86c871f63df89fbbfdf0c3d264030e5da42316dcc332427') {
alert("Hashing failed")
}
let deterministicAccount = phpcoinCrypto.generateDeterministicAccount("abc", "123")
write(deterministicAccount)
if(deterministicAccount.address !== 'PccNcR5ftNNGQr6zcq3Eqhnredn7usdn73') {
alert("Deterministic account failed")
}
console.info("All tests passed")
</script>
</pre>
</body>
</html>