This repository has been archived by the owner on Jun 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (46 loc) · 1.56 KB
/
index.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
44
45
46
47
48
49
50
51
52
53
54
var test = require('tape')
var memdb = require('memdb')
var resetTokens = require('../index')
var publicKey = `-----BEGIN PUBLIC KEY-----
MIGbMBAGByqGSM49AgEGBSuBBAAjA4GGAAQAvmJlA/DZl3SVKNl0OcyVbsMTOmTM
qU0Avhmcl6r8qxkBgjwArIxQr7G7v8m0LOeFIklnmF3sYAwA+8llHGFReV8ASW4w
5AUC8ngZThaH9xk6DQscaMmoEFPN5thWpNcwMgUFYovBtPLwtAZjYr9Se+UT/5k4
VltW7ko6SHbCfMgUUbU=
-----END PUBLIC KEY-----`
var privateKey = `-----BEGIN EC PRIVATE KEY-----
MIHbAgEBBEFmz7VMXRtCPTlBETqMMx/mokyA3xPXra2SkcA7Xh0N6sgne1rgSZNU
ngT6TR3XLfBOt5+p5GRW6p1FVtn+vtPyRKAHBgUrgQQAI6GBiQOBhgAEAL5iZQPw
2Zd0lSjZdDnMlW7DEzpkzKlNAL4ZnJeq/KsZAYI8AKyMUK+xu7/JtCznhSJJZ5hd
7GAMAPvJZRxhUXlfAEluMOQFAvJ4GU4Wh/cZOg0LHGjJqBBTzebYVqTXMDIFBWKL
wbTy8LQGY2K/UnvlE/+ZOFZbVu5KOkh2wnzIFFG1
-----END EC PRIVATE KEY-----`
test('using a secret', function (t) {
var db = memdb()
var reset = resetTokens(db, {
secret: 'choose a better secret'
})
reset.create({ accountKey: 'key for an account' }, function (err, token) {
t.ifErr(err)
t.equal(typeof token, 'string')
reset.confirm({ accountKey: 'key for an account', token: token }, function (err) {
t.ifErr(err)
t.end()
})
})
})
test('using a keypair', function (t) {
var db = memdb()
var reset = resetTokens(db, {
publicKey: publicKey,
privateKey: privateKey,
algorithm: 'ES512'
})
reset.create({ accountKey: 'key for an account' }, function (err, token) {
t.ifErr(err)
t.equal(typeof token, 'string')
reset.confirm({ accountKey: 'key for an account', token: token }, function (err) {
t.ifErr(err)
t.end()
})
})
})