diff --git a/.yarn/cache/@types-pbkdf2-npm-3.1.0-9fa74ff7fb-d15024b195.zip b/.yarn/cache/@types-pbkdf2-npm-3.1.0-9fa74ff7fb-d15024b195.zip new file mode 100644 index 00000000..7afb6d83 Binary files /dev/null and b/.yarn/cache/@types-pbkdf2-npm-3.1.0-9fa74ff7fb-d15024b195.zip differ diff --git a/packages/status-communities/package.json b/packages/status-communities/package.json index 3f7d396b..eec56752 100644 --- a/packages/status-communities/package.json +++ b/packages/status-communities/package.json @@ -25,6 +25,7 @@ "devDependencies": { "@types/chai": "^4.2.22", "@types/mocha": "^9.0.0", + "@types/pbkdf2": "^3.1.0", "@types/secp256k1": "^4.0.3", "@typescript-eslint/eslint-plugin": "^4.31.1", "@typescript-eslint/parser": "^4.31.1", @@ -47,6 +48,7 @@ "ecies-geth": "^1.5.3", "js-sha3": "^0.8.0", "js-waku": "^0.13.1", + "pbkdf2": "^3.1.2", "protobufjs": "^6.11.2", "secp256k1": "^4.0.2" } diff --git a/packages/status-communities/src/encryption.spec.ts b/packages/status-communities/src/encryption.spec.ts new file mode 100644 index 00000000..2c16ed94 --- /dev/null +++ b/packages/status-communities/src/encryption.spec.ts @@ -0,0 +1,14 @@ +import { expect } from "chai"; + +import { createSymKeyFromPassword } from "./encryption"; + +describe("Encryption", () => { + it("Generate symmetric key from password", async function () { + const str = "arbitrary data here"; + const symKey = await createSymKeyFromPassword(str); + + expect(Buffer.from(symKey).toString("hex")).to.eq( + "c49ad65ebf2a7b7253bf400e3d27719362a91b2c9b9f54d50a69117021666c33" + ); + }); +}); diff --git a/packages/status-communities/src/encryption.ts b/packages/status-communities/src/encryption.ts index 4aa297b2..e27d06af 100644 --- a/packages/status-communities/src/encryption.ts +++ b/packages/status-communities/src/encryption.ts @@ -1,9 +1,15 @@ -import { kdf } from "ecies-geth"; +import pbkdf2 from "pbkdf2"; const AESKeyLength = 32; // bytes export async function createSymKeyFromPassword( password: string ): Promise { - return kdf(Buffer.from(password, "utf-8"), AESKeyLength); + return pbkdf2.pbkdf2Sync( + Buffer.from(password, "utf-8"), + "", + 65356, + AESKeyLength, + "sha256" + ); } diff --git a/yarn.lock b/yarn.lock index 9e2ff6ec..dc797f0c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -938,6 +938,15 @@ __metadata: languageName: node linkType: hard +"@types/pbkdf2@npm:^3.1.0": + version: 3.1.0 + resolution: "@types/pbkdf2@npm:3.1.0" + dependencies: + "@types/node": "*" + checksum: d15024b1957c21cf3b8887329d9bd8dfde754cf13a09d76ae25f1391cfc62bb8b8d7b760773c5dbaa748172fba8b3e0c3dbe962af6ccbd69b76df12a48dfba40 + languageName: node + linkType: hard + "@types/prettier@npm:^1.19.0": version: 1.19.1 resolution: "@types/prettier@npm:1.19.1" @@ -8755,7 +8764,7 @@ fsevents@~2.3.2: languageName: node linkType: hard -"pbkdf2@npm:^3.0.3": +"pbkdf2@npm:^3.0.3, pbkdf2@npm:^3.1.2": version: 3.1.2 resolution: "pbkdf2@npm:3.1.2" dependencies: @@ -10487,6 +10496,7 @@ resolve@^2.0.0-next.3: dependencies: "@types/chai": ^4.2.22 "@types/mocha": ^9.0.0 + "@types/pbkdf2": ^3.1.0 "@types/secp256k1": ^4.0.3 "@typescript-eslint/eslint-plugin": ^4.31.1 "@typescript-eslint/parser": ^4.31.1 @@ -10503,6 +10513,7 @@ resolve@^2.0.0-next.3: js-waku: ^0.13.1 mocha: ^9.1.1 npm-run-all: ^4.1.5 + pbkdf2: ^3.1.2 prettier: ^2.4.0 protobufjs: ^6.11.2 secp256k1: ^4.0.2