-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest.js
43 lines (37 loc) · 1.19 KB
/
test.js
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
var tape = require('tape')
var signatures = require('./')
var toBuffer = require('to-buffer')
var alloc = require('buffer-alloc-unsafe')
tape('sign and verify', function (t) {
var keys = signatures.keyPair()
t.ok(keys.publicKey, 'has public key')
t.ok(keys.secretKey, 'has secret key')
var message = toBuffer('hello')
var sig = signatures.sign(message, keys.secretKey)
t.ok(signatures.verify(message, sig, keys.publicKey), 'message verifies')
t.end()
})
tape('sign and verify with seed', function (t) {
var seed = toBuffer([
123, 321, 123, 321,
123, 321, 123, 321,
123, 321, 123, 321,
123, 321, 123, 321,
123, 321, 123, 321,
123, 321, 123, 321,
123, 321, 123, 321,
123, 321, 123, 321
])
var keys = signatures.keyPair(seed)
t.ok(keys.publicKey, 'has public key')
t.ok(keys.secretKey, 'has secret key')
var message = toBuffer('hello')
var sig = signatures.sign(message, keys.secretKey)
var keys2 = signatures.keyPair(seed)
t.ok(signatures.verify(message, sig, keys2.publicKey), 'message verifies')
t.end()
})
tape('throws on seed not crypto_sign_SEEDBYTES long', function (t) {
t.throws(function () { signatures.keyPair(alloc(31)) })
t.end()
})