@1auth/authn-recovery-codes 0.0.0-alpha.60 → 0.0.0-alpha.63

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +4 -4
  2. package/index.js +0 -117
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1auth/authn-recovery-codes",
3
- "version": "0.0.0-alpha.60",
3
+ "version": "0.0.0-alpha.63",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "engines": {
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "repository": {
43
43
  "type": "git",
44
- "url": "github:willfarrell/1auth",
44
+ "url": "git+https://github.com/willfarrell/1auth.git",
45
45
  "directory": "packages/authn-recovery-codes"
46
46
  },
47
47
  "bugs": {
@@ -50,7 +50,7 @@
50
50
  "homepage": "https://github.com/willfarrell/1auth",
51
51
  "gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431",
52
52
  "dependencies": {
53
- "@1auth/authn": "0.0.0-alpha.60",
54
- "@1auth/crypto": "0.0.0-alpha.60"
53
+ "@1auth/authn": "0.0.0-alpha.63",
54
+ "@1auth/crypto": "0.0.0-alpha.63"
55
55
  }
56
56
  }
package/index.js DELETED
@@ -1,117 +0,0 @@
1
- import {
2
- charactersAlphaNumeric,
3
- entropyToCharacterLength,
4
- randomAlphaNumeric,
5
- createSecretHash,
6
- verifySecretHash
7
- } from '@1auth/crypto'
8
- import {
9
- getOptions as authnGetOptions,
10
- count as authnCount,
11
- list as authnList,
12
- // create as authnCreate,
13
- createList as authnCreateList,
14
- authenticate as authnAuthenticate,
15
- remove as authnRemove
16
- } from '@1auth/authn'
17
-
18
- // aka lookup secret
19
- const id = 'recoveryCodes'
20
-
21
- const secret = {
22
- id,
23
- type: 'secret',
24
- minLength: entropyToCharacterLength(112, charactersAlphaNumeric.length),
25
- otp: true,
26
- create: async () => randomAlphaNumeric(secret.minLength),
27
- encode: async (value) => createSecretHash(value),
28
- decode: async (value) => value,
29
- verify: async (value, hash) => verifySecretHash(hash, value)
30
- }
31
-
32
- const defaults = {
33
- id,
34
- secret,
35
- count: 5
36
- }
37
- const options = {}
38
- export default (opt = {}) => {
39
- Object.assign(options, authnGetOptions(), defaults, opt)
40
- }
41
-
42
- export const count = async (sub) => {
43
- if (options.log) {
44
- options.log('@1auth/authn-recovery-codes count(', sub, ')')
45
- }
46
- return await authnCount(options.secret, sub)
47
- }
48
-
49
- export const list = async (sub) => {
50
- if (options.log) {
51
- options.log('@1auth/authn-recovery-codes list(', sub, ')')
52
- }
53
- return await authnList(options.secret, sub)
54
- }
55
-
56
- export const authenticate = async (username, secret) => {
57
- return await authnAuthenticate(options.secret, username, secret)
58
- }
59
-
60
- export const create = async (sub) => {
61
- if (options.log) {
62
- options.log('@1auth/authn-recovery-codes create(', sub, ')')
63
- }
64
- const secrets = await createSecrets(sub, options.count)
65
- await options.notify.trigger('authn-recovery-codes-create', sub)
66
- return secrets
67
- }
68
-
69
- export const update = async (sub) => {
70
- if (options.log) {
71
- options.log('@1auth/authn-recovery-codes update(', sub, ')')
72
- }
73
- const existingSecrets = await options.store.selectList(options.table, {
74
- sub,
75
- type: options.secret.id + '-' + options.secret.type
76
- })
77
- const secrets = await createSecrets(sub, options.count)
78
-
79
- const id = existingSecrets.map((item) => item.id)
80
- await authnRemove(options.secret, sub, id)
81
-
82
- await options.notify.trigger('authn-recovery-codes-update', sub)
83
- return secrets
84
- }
85
-
86
- export const remove = async (sub, id) => {
87
- if (options.log) {
88
- options.log('@1auth/authn-recovery-codes remove(', sub, id, ')')
89
- }
90
-
91
- id ??= await options.store
92
- .selectList(options.table, {
93
- sub,
94
- type: options.id + '-' + options.secret.type
95
- })
96
- .then((res) => res.map((item) => item.id))
97
-
98
- await authnRemove(options.secret, sub, id)
99
-
100
- await options.notify.trigger('authn-recovery-codes-remove', sub)
101
- }
102
-
103
- const createSecrets = async (sub, count = options.count) => {
104
- const secrets = []
105
- const now = nowInSeconds()
106
- for (let i = count; i--;) {
107
- const secret = await options.secret.create()
108
- secrets.push({
109
- value: secret,
110
- verify: now
111
- })
112
- }
113
- await authnCreateList(options.secret, sub, secrets)
114
- return secrets
115
- }
116
-
117
- const nowInSeconds = () => Math.floor(Date.now() / 1000)