Skip to content

Commit

Permalink
Add proper attribution for @noble/hashes (#1171)
Browse files Browse the repository at this point in the history
  • Loading branch information
pilcrowonpaper authored Sep 28, 2023
1 parent 7543f92 commit bb857c2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
6 changes: 6 additions & 0 deletions .auri/$87kr76r2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
package: "lucia" # package name
type: "patch" # "major", "minor", "patch"
---

Add proper attributes for `@noble/hashes`
21 changes: 21 additions & 0 deletions packages/lucia/src/scrypt/MODULE_LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2022 Paul Miller (https://paulmillr.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
6 changes: 3 additions & 3 deletions packages/lucia/src/scrypt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const XorAndSalsa = (
ii: number,
out: Uint32Array,
oi: number
) => {
): void => {
const y00 = prev[pi++] ^ input[ii++],
y01 = prev[pi++] ^ input[ii++];
const y02 = prev[pi++] ^ input[ii++],
Expand Down Expand Up @@ -101,7 +101,7 @@ const BlockMix = (
out: Uint32Array,
oi: number,
r: number
) => {
): void => {
let head = oi + 0;
let tail = oi + 16 * r;
for (let i = 0; i < 16; i++) out[tail + i] = input[ii + (2 * r - 1) * 16 + i];
Expand Down Expand Up @@ -194,7 +194,7 @@ export default async (
password: Uint8Array,
salt: Uint8Array,
opts: ScryptOpts
) => {
): Promise<Uint8Array> => {
const { N, r, p, dkLen, blockSize32, V, B32, B, tmp, blockMixCb, asyncTick } =
await scryptInit(password, salt, opts);
for (let pi = 0; pi < p; pi++) {
Expand Down
3 changes: 1 addition & 2 deletions packages/lucia/src/scrypt/pbkdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const pbkdf2 = async (
c: number;
dkLen: number;
}
) => {
): Promise<Uint8Array> => {
const pwKey = await crypto.subtle.importKey(
"raw",
password,
Expand All @@ -23,6 +23,5 @@ export const pbkdf2 = async (
pwKey,
options.dkLen * 8
);

return new Uint8Array(keyBuffer);
};
17 changes: 11 additions & 6 deletions packages/lucia/src/scrypt/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
export const u32 = (arr: Uint8Array) =>
new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
export const u32 = (arr: Uint8Array): Uint32Array => {
return new Uint32Array(
arr.buffer,
arr.byteOffset,
Math.floor(arr.byteLength / 4)
);
};

export const nextTick = async () => {};
export const nextTick = async (): Promise<void> => {};

export function checkOpts<T1 extends {}, T2 extends {}>(
defaults: T1,
Expand All @@ -14,11 +19,11 @@ export function checkOpts<T1 extends {}, T2 extends {}>(
export const asyncLoop = async (
iters: number,
tick: number,
cb: (i: number) => void
) => {
callback: (i: number) => void
): Promise<void> => {
let ts = Date.now();
for (let i = 0; i < iters; i++) {
cb(i);
callback(i);
const diff = Date.now() - ts;
if (diff >= 0 && diff < tick) continue;
await nextTick();
Expand Down

0 comments on commit bb857c2

Please sign in to comment.