@1auth/crypto 0.0.0-alpha.33 → 0.0.0-alpha.34
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.
- package/index.js +30 -3
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -137,13 +137,18 @@ export const randomId = {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
// *** Digests *** //
|
|
140
|
+
export const createChecksum = (value, { algorithm } = {}) => {
|
|
141
|
+
algorithm ??= options.digestAlgorithm
|
|
142
|
+
return checksum(algorithm).update(value).digest('hex')
|
|
143
|
+
}
|
|
140
144
|
export const createDigest = (value, { algorithm } = {}) => {
|
|
141
145
|
algorithm ??= options.digestAlgorithm
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
return digest
|
|
146
|
+
const checksum = createChecksum(value, { algorithm })
|
|
147
|
+
return `${algorithm}:${checksum}`
|
|
145
148
|
}
|
|
146
149
|
|
|
150
|
+
// TODO evaluate non-iv encryption approach?
|
|
151
|
+
// Use encryption as pepper to allow easier rotation of pepper
|
|
147
152
|
export const createEncryptedDigest = (value, { algorithm } = {}) => {
|
|
148
153
|
const digest = createDigest(value, { algorithm })
|
|
149
154
|
// encrypting using the symetricEncryptionKey instread of
|
|
@@ -162,6 +167,28 @@ export const createEncryptedDigest = (value, { algorithm } = {}) => {
|
|
|
162
167
|
})
|
|
163
168
|
}
|
|
164
169
|
|
|
170
|
+
export const rotateDigestEncryption = (
|
|
171
|
+
encryptedValue,
|
|
172
|
+
encryptionKey,
|
|
173
|
+
newEncryptionKey
|
|
174
|
+
) => {
|
|
175
|
+
const digest = symetricDecrypt(encryptedValue, {
|
|
176
|
+
encryptionKey,
|
|
177
|
+
sub: '',
|
|
178
|
+
encoding: options.symetricEncryptionEncoding
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
return symetricEncrypt(digest, {
|
|
182
|
+
encryptionKey: newEncryptionKey,
|
|
183
|
+
sub: '',
|
|
184
|
+
encoding: options.symetricEncryptionEncoding,
|
|
185
|
+
iv: Buffer.from(
|
|
186
|
+
newEncryptionKey.substring(0, symetricEncryptionEncodingLengths.iv),
|
|
187
|
+
options.symetricEncryptionEncoding
|
|
188
|
+
)
|
|
189
|
+
})
|
|
190
|
+
}
|
|
191
|
+
|
|
165
192
|
// *** Hashing *** //
|
|
166
193
|
const hashOptions = {
|
|
167
194
|
timeCost: 3,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1auth/crypto",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.34",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"url": "https://github.com/willfarrell/1auth/issues"
|
|
45
45
|
},
|
|
46
46
|
"homepage": "https://github.com/willfarrell/1auth",
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "c88105a99efd7f3de80795736d6194e52ef465b4",
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@node-rs/argon2": "1.8.3"
|
|
50
50
|
}
|