Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

remove buffer-dep, replace with bufferFrom #445

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion integration/file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe(`File API integration tests for portal '${portal}'`, () => {
});

it("getEntryData should return null for non-existent File API entry data", async () => {
const { publicKey: userID } = genKeyPairAndSeed();
const { publicKey: userID } = await genKeyPairAndSeed();
const { data: received } = await client.file.getEntryData(userID, path);
expect(received).toBeNull();
});
Expand Down
10 changes: 5 additions & 5 deletions integration/registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe(`Registry end to end integration tests for portal '${portal}'`, () => {
const data = stringToUint8ArrayUtf8(skylink);

it("Should return null for an inexistent entry", async () => {
const { publicKey } = genKeyPairAndSeed();
const { publicKey } = await genKeyPairAndSeed();

// Try getting an inexistent entry.
const { entry, signature } = await client.registry.getEntry(publicKey, "foo");
Expand All @@ -16,7 +16,7 @@ describe(`Registry end to end integration tests for portal '${portal}'`, () => {
});

it("Should set and get string entries correctly", async () => {
const { publicKey, privateKey } = genKeyPairAndSeed();
const { publicKey, privateKey } = await genKeyPairAndSeed();

const entry = {
dataKey,
Expand All @@ -33,7 +33,7 @@ describe(`Registry end to end integration tests for portal '${portal}'`, () => {
});

it("Should set and get unicode entries correctly", async () => {
const { publicKey, privateKey } = genKeyPairAndSeed();
const { publicKey, privateKey } = await genKeyPairAndSeed();

const entry = {
dataKey,
Expand All @@ -50,7 +50,7 @@ describe(`Registry end to end integration tests for portal '${portal}'`, () => {
});

it("Should set and get an entry with empty data correctly", async () => {
const { publicKey, privateKey } = genKeyPairAndSeed();
const { publicKey, privateKey } = await genKeyPairAndSeed();

const entry = {
dataKey,
Expand All @@ -67,7 +67,7 @@ describe(`Registry end to end integration tests for portal '${portal}'`, () => {
});

it("Should fail to set an entry with a revision number that's too low", async () => {
const { privateKey } = genKeyPairAndSeed();
const { privateKey } = await genKeyPairAndSeed();

const entry = {
dataKey,
Expand Down
20 changes: 10 additions & 10 deletions integration/skydb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe(`SkyDB end to end integration tests for portal '${portal}'`, () => {
});

it("Should return null for an inexistent entry", async () => {
const { publicKey } = genKeyPairAndSeed();
const { publicKey } = await genKeyPairAndSeed();

// Try getting an inexistent entry.
const { data, dataLink } = await client.db.getJSON(publicKey, "foo");
Expand All @@ -69,7 +69,7 @@ describe(`SkyDB end to end integration tests for portal '${portal}'`, () => {
});

it("Should set and get new entries", async () => {
const { publicKey, privateKey } = genKeyPairAndSeed();
const { publicKey, privateKey } = await genKeyPairAndSeed();
const json = { data: "thisistext" };
const json2 = { data: "foo2" };

Expand All @@ -94,7 +94,7 @@ describe(`SkyDB end to end integration tests for portal '${portal}'`, () => {
const dataKeys = [".", "..", "http://localhost:8000/", ""];

it.each(dataKeys)("Should set and get new entry with dataKey '%s'", async (dataKey) => {
const { publicKey, privateKey } = genKeyPairAndSeed();
const { publicKey, privateKey } = await genKeyPairAndSeed();
const json = { data: "thisistext" };

await client.db.setJSON(privateKey, dataKey, json);
Expand All @@ -106,7 +106,7 @@ describe(`SkyDB end to end integration tests for portal '${portal}'`, () => {
});

it("Should be able to delete an existing entry", async () => {
const { publicKey, privateKey } = genKeyPairAndSeed();
const { publicKey, privateKey } = await genKeyPairAndSeed();
const json = { data: "thisistext" };

await client.db.setJSON(privateKey, dataKey, json);
Expand All @@ -125,7 +125,7 @@ describe(`SkyDB end to end integration tests for portal '${portal}'`, () => {
});

it("Should be able to set a new entry as deleted and then write over it", async () => {
const { publicKey, privateKey } = genKeyPairAndSeed();
const { publicKey, privateKey } = await genKeyPairAndSeed();

await client.db.deleteJSON(privateKey, dataKey);

Expand Down Expand Up @@ -162,7 +162,7 @@ describe(`SkyDB end to end integration tests for portal '${portal}'`, () => {
});

it("Should correctly set a data link", async () => {
const { publicKey, privateKey } = genKeyPairAndSeed();
const { publicKey, privateKey } = await genKeyPairAndSeed();
const dataLink = "AAAVyJktMuK-7WRCNUvYcYq7izvhCbgDLXlT4YgechblJw";
const dataLinkBytes = decodeSkylinkBase64(dataLink);

Expand All @@ -177,7 +177,7 @@ describe(`SkyDB end to end integration tests for portal '${portal}'`, () => {
});

it("should set and get entry data", async () => {
const { publicKey, privateKey } = genKeyPairAndSeed();
const { publicKey, privateKey } = await genKeyPairAndSeed();
const data = new Uint8Array([1, 2, 3]);

// Set the entry data.
Expand All @@ -191,7 +191,7 @@ describe(`SkyDB end to end integration tests for portal '${portal}'`, () => {
});

it("should set and delete entry data", async () => {
const { publicKey, privateKey } = genKeyPairAndSeed();
const { publicKey, privateKey } = await genKeyPairAndSeed();
const data = new Uint8Array([1, 2, 3]);

// Set the entry data.
Expand All @@ -208,7 +208,7 @@ describe(`SkyDB end to end integration tests for portal '${portal}'`, () => {
it("should be able to delete a new entry and then write over it", async () => {
const data = new Uint8Array([1, 2, 3]);

const { publicKey, privateKey } = genKeyPairAndSeed();
const { publicKey, privateKey } = await genKeyPairAndSeed();

// Delete the entry data.
await client.db.deleteEntryData(privateKey, dataKey);
Expand All @@ -228,7 +228,7 @@ describe(`SkyDB end to end integration tests for portal '${portal}'`, () => {
});

it("Should correctly handle the hashedDataKeyHex option", async () => {
const { publicKey, privateKey } = genKeyPairAndSeed();
const { publicKey, privateKey } = await genKeyPairAndSeed();
const dataKey = "test";
const hashedDataKeyHex = toHexString(hashDataKey(dataKey));
const json = { message: "foo" };
Expand Down
22 changes: 11 additions & 11 deletions integration/skydb_v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe(`SkyDBV2 end to end integration tests for portal '${portal}'`, () => {
});

it("Should return null for an inexistent entry", async () => {
const { publicKey } = genKeyPairAndSeed();
const { publicKey } = await genKeyPairAndSeed();

// Try getting an inexistent entry.
const { data, dataLink } = await client.dbV2.getJSON(publicKey, "foo");
Expand All @@ -69,7 +69,7 @@ describe(`SkyDBV2 end to end integration tests for portal '${portal}'`, () => {
});

it("Should set and get new entries", async () => {
const { publicKey, privateKey } = genKeyPairAndSeed();
const { publicKey, privateKey } = await genKeyPairAndSeed();
const json = { data: "thisistext" };
const json2 = { data: "foo2" };

Expand All @@ -94,7 +94,7 @@ describe(`SkyDBV2 end to end integration tests for portal '${portal}'`, () => {
const dataKeys = [".", "..", "http://localhost:8000/", ""];

it.each(dataKeys)("Should set and get new entry with dataKey '%s'", async (dataKey) => {
const { publicKey, privateKey } = genKeyPairAndSeed();
const { publicKey, privateKey } = await genKeyPairAndSeed();
const json = { data: "thisistext" };

await client.dbV2.setJSON(privateKey, dataKey, json);
Expand All @@ -106,7 +106,7 @@ describe(`SkyDBV2 end to end integration tests for portal '${portal}'`, () => {
});

it("Should be able to delete an existing entry", async () => {
const { publicKey, privateKey } = genKeyPairAndSeed();
const { publicKey, privateKey } = await genKeyPairAndSeed();
const json = { data: "thisistext" };

await client.dbV2.setJSON(privateKey, dataKey, json);
Expand All @@ -125,7 +125,7 @@ describe(`SkyDBV2 end to end integration tests for portal '${portal}'`, () => {
});

it("Should be able to set a new entry as deleted and then write over it", async () => {
const { publicKey, privateKey } = genKeyPairAndSeed();
const { publicKey, privateKey } = await genKeyPairAndSeed();

await client.dbV2.deleteJSON(privateKey, dataKey);

Expand Down Expand Up @@ -162,7 +162,7 @@ describe(`SkyDBV2 end to end integration tests for portal '${portal}'`, () => {
});

it("Should correctly set a data link", async () => {
const { publicKey, privateKey } = genKeyPairAndSeed();
const { publicKey, privateKey } = await genKeyPairAndSeed();
const dataLink = "AAAVyJktMuK-7WRCNUvYcYq7izvhCbgDLXlT4YgechblJw";
const dataLinkBytes = decodeSkylinkBase64(dataLink);

Expand All @@ -177,7 +177,7 @@ describe(`SkyDBV2 end to end integration tests for portal '${portal}'`, () => {
});

it("should set and get entry data", async () => {
const { publicKey, privateKey } = genKeyPairAndSeed();
const { publicKey, privateKey } = await genKeyPairAndSeed();
const data = new Uint8Array([1, 2, 3]);

// Set the entry data.
Expand All @@ -191,7 +191,7 @@ describe(`SkyDBV2 end to end integration tests for portal '${portal}'`, () => {
});

it("should set and delete entry data", async () => {
const { publicKey, privateKey } = genKeyPairAndSeed();
const { publicKey, privateKey } = await genKeyPairAndSeed();
const data = new Uint8Array([1, 2, 3]);

// Set the entry data.
Expand All @@ -208,7 +208,7 @@ describe(`SkyDBV2 end to end integration tests for portal '${portal}'`, () => {
it("should be able to delete a new entry and then write over it", async () => {
const data = new Uint8Array([1, 2, 3]);

const { publicKey, privateKey } = genKeyPairAndSeed();
const { publicKey, privateKey } = await genKeyPairAndSeed();

// Delete the entry data.
await client.dbV2.deleteEntryData(privateKey, dataKey);
Expand All @@ -228,7 +228,7 @@ describe(`SkyDBV2 end to end integration tests for portal '${portal}'`, () => {
});

it("Should correctly handle the hashedDataKeyHex option", async () => {
const { publicKey, privateKey } = genKeyPairAndSeed();
const { publicKey, privateKey } = await genKeyPairAndSeed();
const dataKey = "test";
const hashedDataKeyHex = toHexString(hashDataKey(dataKey));
const json = { message: "foo" };
Expand All @@ -243,7 +243,7 @@ describe(`SkyDBV2 end to end integration tests for portal '${portal}'`, () => {
});

it("Should update the revision number cache", async () => {
const { publicKey, privateKey } = genKeyPairAndSeed();
const { publicKey, privateKey } = await genKeyPairAndSeed();
const json = { message: 1 };

await client.dbV2.setJSON(privateKey, dataKey, json);
Expand Down
2 changes: 1 addition & 1 deletion integration/upload_download.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ describe(`Upload and download end-to-end tests for portal '${portal}'`, () => {
});

it("Should update an etag for a resolver skylink after changing its data", async () => {
const { publicKey, privateKey } = genKeyPairAndSeed();
const { publicKey, privateKey } = await genKeyPairAndSeed();

// Generate random file data.
const [data1, data2] = [randomUnicodeString(4096), randomUnicodeString(4096)];
Expand Down
16 changes: 16 additions & 0 deletions jest-environment-jsdom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable */

const { TestEnvironment } = require("jest-environment-jsdom");

module.exports = class CustomTestEnvironment extends TestEnvironment {
async setup() {
await super.setup();

// https://github.com/jsdom/jsdom/issues/2524
if (typeof this.global.TextEncoder === "undefined") {
const { TextEncoder, TextDecoder } = require("util");
this.global.TextEncoder = TextEncoder;
this.global.TextDecoder = TextDecoder;
}
}
};
30 changes: 30 additions & 0 deletions jest-resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// Jest 27 to 28 migration issue: https://jestjs.io/docs/upgrading-to-jest28#packagejson-exports
// Workaround discussion: https://github.com/microsoft/accessibility-insights-web/pull/5421#issuecomment-1109168149
// Workaround copied from: https://github.com/microsoft/accessibility-insights-web/pull/5421/commits/9ad4e618019298d82732d49d00aafb846fb6bac7

// eslint-disable-next-line no-undef
module.exports = (path, options) => {
// Call the defaultResolver, so we leverage its cache, error handling, etc.
return options.defaultResolver(path, {
...options,
// Use packageFilter to process parsed `package.json` before the resolution (see https://www.npmjs.com/package/resolve#resolveid-opts-cb)
packageFilter: (pkg) => {
// jest-environment-jsdom 28+ tries to use browser exports instead of default exports,
// but some modules only offer an ESM browser export and not a CommonJS one. Jest does not yet
// support ESM modules natively, so this causes a Jest error related to trying to parse
// "export" syntax.
//
// Once we're able to migrate our Jest config to ESM and a browser crypto
// implementation is available for the browser+ESM version of uuid to use (eg, via
// https://github.com/jsdom/jsdom/pull/3352 or a similar polyfill), this can go away.
if (pkg.name === "pbkdf2-hmac") {
delete pkg["exports"];
delete pkg["module"];
}
return pkg;
},
});
};
4 changes: 2 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const config: Config.InitialOptions = {
// resetModules: false,

// A path to a custom resolver
// resolver: undefined,
resolver: `${__dirname}/jest-resolver.js`,

// Automatically restore mock state between every test
// restoreMocks: false,
Expand All @@ -149,7 +149,7 @@ const config: Config.InitialOptions = {
// snapshotSerializers: [],

// The test environment that will be used for testing
testEnvironment: "jsdom",
testEnvironment: "./jest-environment-jsdom.js",

// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,11 @@
"base32-encode": "^1.1.1",
"base64-js": "^1.3.1",
"blakejs": "^1.1.0",
"buffer": "^6.0.1",
"buffer-from": "^1.1.2",
"mime": "^3.0.0",
"path-browserify": "^1.0.1",
"pbkdf2-hmac": "^1.0.4",
"post-me": "^0.4.5",
"randombytes": "^2.1.0",
"sjcl": "^1.0.8",
"skynet-mysky-utils": "^0.3.0",
"tweetnacl": "^1.0.3",
"url-join": "^4.0.1",
Expand All @@ -75,12 +74,12 @@
"devDependencies": {
"@skynetlabs/skynet-nodejs": "^2.8.0",
"@types/base64-js": "^1.3.0",
"@types/buffer-from": "^1.1.0",
"@types/jest": "^29.1.1",
"@types/mime": "^3.0.1",
"@types/minimist": "^1.2.2",
"@types/node": "^18.0.0",
"@types/randombytes": "^2.0.0",
"@types/sjcl": "^1.0.29",
"@types/pbkdf2": "^3.1.0",
"@types/url-join": "^4.0.0",
"@types/url-parse": "^1.4.3",
"@typescript-eslint/eslint-plugin": "^5.27.1",
Expand Down
8 changes: 4 additions & 4 deletions src/crypto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ describe("deriveChildSeed", () => {
});

describe("genKeyPairAndSeed", () => {
it("should create a seed of the given length, hex-encoded", () => {
it("should create a seed of the given length, hex-encoded", async () => {
const length = 8;
const { seed } = genKeyPairAndSeed(length);
const { seed } = await genKeyPairAndSeed(length);
// The length is specified in bytes and seed.length gives us the length of
// the string representation of the seed bytes, which is hex encoded.
expect(seed.length).toEqual(length * 2);
});
});

describe("genKeyPairFromSeed", () => {
it("should create an expected keypair from a given seed", () => {
it("should create an expected keypair from a given seed", async () => {
// Hard-code expected values to catch any breaking changes.
const seed = "c1197e1275fbf570d21dde01a00af83ed4a743d1884e4a09cebce0dd21ae254c";
const expectedPublicKey = "f8a7da8324fabb9d57bb32c59c48d4ba304d08ee5f1297a46836cf841da71c80";
const expectedPrivateKey =
"c404ff07fba961000dfb25ece7477f45b109b50a5169a45f3fb239343002c1cff8a7da8324fabb9d57bb32c59c48d4ba304d08ee5f1297a46836cf841da71c80";

const { publicKey, privateKey } = genKeyPairFromSeed(seed);
const { publicKey, privateKey } = await genKeyPairFromSeed(seed);
expect(publicKey).toEqual(expectedPublicKey);
expect(privateKey).toEqual(expectedPrivateKey);
});
Expand Down
Loading