Skip to content

Commit

Permalink
feat: move to new std using import map and deno.lock
Browse files Browse the repository at this point in the history
  • Loading branch information
oplik0 committed Dec 26, 2023
1 parent 3690299 commit 39e095f
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 67 deletions.
68 changes: 34 additions & 34 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/deno
{
"name": "Deno",
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick an Debian OS version: bullseye, buster
"args": {
"VARIANT": "bullseye"
}
},
"name": "Deno",
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick an Debian OS version: bullseye, buster
"args": {
"VARIANT": "bullseye"
}
},

// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
// Enables the project as a Deno project
"deno.enable": true,
// Enables Deno linting for the project
"deno.lint": true,
"deno.suggest.imports.hosts": {
"https://deno.land": false
},
"deno.unstable": true,
// Sets Deno as the default formatter for the project
"editor.defaultFormatter": "denoland.vscode-deno"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"denoland.vscode-deno"
]
}
},
"remoteUser": "vscode"
}
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
// Enables the project as a Deno project
"deno.enable": true,
// Enables Deno linting for the project
"deno.lint": true,
"deno.suggest.imports.hosts": {
"https://deno.land": false
},
"deno.unstable": true,
// Sets Deno as the default formatter for the project
"editor.defaultFormatter": "denoland.vscode-deno"
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"denoland.vscode-deno"
]
}
},
"remoteUser": "vscode"
}
2 changes: 1 addition & 1 deletion .releaserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
"@semantic-release/npm",
"@semantic-release/release-notes-generator"
]
}
}
5 changes: 4 additions & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
}
},
"tasks": {
"wasmbuild": "deno run --allow-env --allow-run --allow-read --allow-write --allow-net https://deno.land/x/wasmbuild@0.8.5/main.ts --out ./lib/_wasm --project scrypt-wasm --sync"
"wasmbuild": "deno run --allow-env --allow-run --allow-read --allow-write --allow-net https://deno.land/x/wasmbuild@0.15.4/main.ts --out ./lib/_wasm --project scrypt-wasm --sync"
},
"imports": {
"std/": "https://deno.land/std@0.210.0/"
}
}
51 changes: 51 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 14 additions & 12 deletions dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
"json": {},
"markdown": {},
"toml": {},
"includes": [
"**/*.{ts,tsx,js,jsx,cjs,mjs,json,md,toml,rs}"
],
"excludes": [
"**/node_modules",
"**/*-lock.json",
"**/*.generated.js"
],
"includes": ["**/*.{ts,tsx,js,jsx,cjs,mjs,json,md,toml,rs}"],
"excludes": ["**/node_modules", "**/*-lock.json", "**/*.generated.js"],
"exec": {
"commands": [
{
"command": "rustfmt --edition 2021",
"exts": ["rs"]
}
]
},
"plugins": [
"https://plugins.dprint.dev/typescript-0.69.1.wasm",
"https://plugins.dprint.dev/json-0.15.3.wasm",
"https://plugins.dprint.dev/markdown-0.13.3.wasm",
"https://plugins.dprint.dev/typescript-0.88.7.wasm",
"https://plugins.dprint.dev/json-0.19.1.wasm",
"https://plugins.dprint.dev/markdown-0.16.3.wasm",
"https://plugins.dprint.dev/toml-0.5.4.wasm",
"https://plugins.dprint.dev/rustfmt-0.6.2.json@886c6f3161cf020c2d75160262b0f56d74a521e05cfb91ec4f956650c8ca76ca"
"https://plugins.dprint.dev/exec-0.4.4.json@c207bf9b9a4ee1f0ecb75c594f774924baf62e8e53a2ce9d873816a408cecbf7"
]
}
2 changes: 1 addition & 1 deletion egg.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
"checkTests": false,
"checkInstallation": false,
"check": true
}
}
3 changes: 2 additions & 1 deletion lib/helpers_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from "https://deno.land/std@0.152.0/testing/asserts.ts";
import { assertEquals } from "std/assert/mod.ts";

import { decomposeFormat, ScryptParameters } from "./helpers.ts";

Expand All @@ -12,6 +12,7 @@ Deno.test("decompose scrypt with format detection", (): void => {
r: 8,
p: 1,
// dprint-ignore-next-line
// deno-fmt-ignore
salt: new Uint8Array([196, 52, 207, 10, 123, 64, 210, 228, 151, 16, 167, 215, 139, 193, 239, 144, 24, 88, 50, 43, 173, 63, 72, 255, 177, 125, 250, 85, 70, 5, 242, 141]),
} as ScryptParameters;
assertEquals(params, expectedParams);
Expand Down
8 changes: 4 additions & 4 deletions lib/scrypt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { encode as base64encode } from "https://deno.land/std@0.152.0/encoding/base64.ts";
import { encode as hexencode } from "https://deno.land/std@0.152.0/encoding/hex.ts";
import { encodeBase64 } from "std/encoding/base64.ts";
import { encodeHex } from "std/encoding/hex.ts";
import { instantiate, scrypt_hash } from "./_wasm/scrypt_wasm.generated.js";
const encoder: TextEncoder = new TextEncoder();
const decoder: TextDecoder = new TextDecoder("utf-8");
Expand Down Expand Up @@ -31,9 +31,9 @@ export function scrypt(
const result: Uint8Array = scrypt_hash(password, salt, N, r, p, dklen);
switch (outputEncoding) {
case "base64":
return base64encode(result);
return encodeBase64(result);
case "hex":
return hexencode(result);
return encodeHex(result);
case "utf-8":
return decoder.decode(result);
default:
Expand Down
51 changes: 39 additions & 12 deletions lib/scrypt_bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ Deno.bench("small scrypt", { group: "small scrypt", baseline: true }, () => {
Deno.bench("small scrypt - last version (longer password and salt)", {
group: "small scrypt (longer password and salt)",
}, () => {
scryptOld("long password to test that", "long salt to test that", 1024, 8, 1, 64);
scryptOld(
"long password to test that",
"long salt to test that",
1024,
8,
1,
64,
);
});
Deno.bench("small scrypt (longer password and salt)", {
group: "small scrypt (longer password and salt)",
Expand All @@ -42,6 +49,7 @@ Deno.bench("small scrypt - last version (extremely long password and salt)", {
});
Deno.bench("small scrypt (extremely long password and salt)", {
group: "small scrypt (extremely long password and salt)",
baseline: true,
}, () => {
scrypt(extremePassword, extremeSalt, 1024, 8, 1, 64);
});
Expand Down Expand Up @@ -82,35 +90,54 @@ Deno.bench(
},
);

Deno.bench("standard scrypt - last version (extremely long password and salt)", {
group: "scrypt (extremely long password and salt)",
}, () => {
scryptOld(extremePassword, extremeSalt, 16384, 8, 1, 64);
});
Deno.bench(
"standard scrypt - last version (extremely long password and salt)",
{
group: "scrypt (extremely long password and salt)",
},
() => {
scryptOld(extremePassword, extremeSalt, 16384, 8, 1, 64);
},
);
Deno.bench("standard scrypt (extremely long password and salt)", {
group: "scrypt (extremely long password and salt)",
baseline: true,
}, () => {
scrypt(extremePassword, extremeSalt, 16384, 8, 1, 64);
});

Deno.bench("large n scrypt - last version (4x standard)", { group: "large n scrypt" }, () => {
Deno.bench("large n scrypt - last version (4x standard)", {
group: "large n scrypt",
}, () => {
scryptOld("password", "salt", 65536, 8, 1, 64);
});
Deno.bench("large n scrypt (4x standard)", { group: "large n scrypt", baseline: true }, () => {
Deno.bench("large n scrypt (4x standard)", {
group: "large n scrypt",
baseline: true,
}, () => {
scrypt("password", "salt", 65536, 8, 1, 64);
});

Deno.bench("large r scrypt - last version (4x standard)", { group: "large r scrypt" }, () => {
Deno.bench("large r scrypt - last version (4x standard)", {
group: "large r scrypt",
}, () => {
scryptOld("password", "salt", 16384, 32, 1, 64);
});
Deno.bench("large r scrypt (4x standard)", { group: "large r scrypt", baseline: true }, () => {
Deno.bench("large r scrypt (4x standard)", {
group: "large r scrypt",
baseline: true,
}, () => {
scrypt("password", "salt", 16384, 32, 1, 64);
});

Deno.bench("large p scrypt - last version (4x standard)", { group: "large p scrypt" }, () => {
Deno.bench("large p scrypt - last version (4x standard)", {
group: "large p scrypt",
}, () => {
scryptOld("password", "salt", 16384, 8, 4, 64);
});
Deno.bench("large p scrypt (4x standard)", { group: "large p scrypt", baseline: true }, () => {
Deno.bench("large p scrypt (4x standard)", {
group: "large p scrypt",
baseline: true,
}, () => {
scrypt("password", "salt", 16384, 8, 4, 64);
});
5 changes: 4 additions & 1 deletion lib/scrypt_test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { assertEquals } from "https://deno.land/std@0.152.0/testing/asserts.ts";
import { assertEquals } from "std/assert/mod.ts";
import { scrypt } from "./scrypt.ts";

Deno.test("scrypt #1", (): void => {
// dprint-ignore-next-line
// deno-fmt-ignore
const expectedOutput: Uint8Array = new Uint8Array([0x77, 0xd6, 0x57, 0x62, 0x38, 0x65, 0x7b, 0x20, 0x3b, 0x19, 0xca, 0x42, 0xc1, 0x8a, 0x04, 0x97, 0xf1, 0x6b, 0x48, 0x44, 0xe3, 0x07, 0x4a, 0xe8, 0xdf, 0xdf, 0xfa, 0x3f, 0xed, 0xe2, 0x14, 0x42, 0xfc, 0xd0, 0x06, 0x9d, 0xed, 0x09, 0x48, 0xf8, 0x32, 0x6a, 0x75, 0x3a, 0x0f, 0xc8, 0x1f, 0x17, 0xe8, 0xd3, 0xe0, 0xfb, 0x2e, 0x0d, 0x36, 0x28, 0xcf, 0x35, 0xe2, 0x0c, 0x38, 0xd1, 0x89, 0x06]);
assertEquals(
(scrypt("", "", 16, 1, 1, 64)) as Uint8Array,
Expand All @@ -12,6 +13,7 @@ Deno.test("scrypt #1", (): void => {

Deno.test("scrypt #2", (): void => {
// dprint-ignore-next-line
// deno-fmt-ignore
const expectedOutput: Uint8Array = new Uint8Array([0xfd, 0xba, 0xbe, 0x1c, 0x9d, 0x34, 0x72, 0x00, 0x78, 0x56, 0xe7, 0x19, 0x0d, 0x01, 0xe9, 0xfe, 0x7c, 0x6a, 0xd7, 0xcb, 0xc8, 0x23, 0x78, 0x30, 0xe7, 0x73, 0x76, 0x63, 0x4b, 0x37, 0x31, 0x62, 0x2e, 0xaf, 0x30, 0xd9, 0x2e, 0x22, 0xa3, 0x88, 0x6f, 0xf1, 0x09, 0x27, 0x9d, 0x98, 0x30, 0xda, 0xc7, 0x27, 0xaf, 0xb9, 0x4a, 0x83, 0xee, 0x6d, 0x83, 0x60, 0xcb, 0xdf, 0xa2, 0xcc, 0x06, 0x40]);
assertEquals(
(scrypt("password", "NaCl", 1024, 8, 16, 64)) as Uint8Array,
Expand All @@ -21,6 +23,7 @@ Deno.test("scrypt #2", (): void => {

Deno.test("scrypt #3", (): void => {
// dprint-ignore-next-line
// deno-fmt-ignore
const expectedOutput: Uint8Array = new Uint8Array([0x70, 0x23, 0xbd, 0xcb, 0x3a, 0xfd, 0x73, 0x48, 0x46, 0x1c, 0x06, 0xcd, 0x81, 0xfd, 0x38, 0xeb, 0xfd, 0xa8, 0xfb, 0xba, 0x90, 0x4f, 0x8e, 0x3e, 0xa9, 0xb5, 0x43, 0xf6, 0x54, 0x5d, 0xa1, 0xf2, 0xd5, 0x43, 0x29, 0x55, 0x61, 0x3f, 0x0f, 0xcf, 0x62, 0xd4, 0x97, 0x05, 0x24, 0x2a, 0x9a, 0xf9, 0xe6, 0x1e, 0x85, 0xdc, 0x0d, 0x65, 0x1e, 0x40, 0xdf, 0xcf, 0x01, 0x7b, 0x45, 0x57, 0x58, 0x87]);
assertEquals(
(scrypt(
Expand Down

0 comments on commit 39e095f

Please sign in to comment.