Skip to content

Commit

Permalink
Replace micro-aes-gcm with @noble/ciphers
Browse files Browse the repository at this point in the history
  • Loading branch information
steida committed Aug 18, 2023
1 parent 597abce commit 5f9f10b
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 135 deletions.
5 changes: 5 additions & 0 deletions .changeset/pink-masks-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"evolu": patch
---

Replace micro-aes-gcm with @noble/ciphers
2 changes: 1 addition & 1 deletion apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"devDependencies": {
"@evolu/tsconfig": "workspace:*",
"@types/node": "^20.5.0",
"@types/node": "^20.5.1",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
},
Expand Down
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"devDependencies": {
"@evolu/tsconfig": "workspace:*",
"@types/node": "^20.5.0",
"@types/node": "^20.5.1",
"@types/react": "^18.2.20",
"@types/react-dom": "^18.2.7",
"autoprefixer": "^10.4.15",
Expand Down
2 changes: 1 addition & 1 deletion packages/evolu-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@types/body-parser": "^1.19.2",
"@types/cors": "^2.8.13",
"@types/express": "^4.17.17",
"@types/node": "^20.5.0",
"@types/node": "^20.5.1",
"eslint": "^8.47.0",
"eslint-config-evolu": "workspace:*",
"typescript": "^5.1.6",
Expand Down
4 changes: 2 additions & 2 deletions packages/evolu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@
"proto": "pnpm protoc --ts_out ./src --proto_path protobuf protobuf/Protobuf.proto --ts_opt eslint_disable && pnpm format"
},
"dependencies": {
"@noble/ciphers": "^0.2.0",
"@noble/hashes": "^1.3.1",
"@protobuf-ts/runtime": "^2.9.1",
"@scure/bip39": "^1.2.1",
"@sqlite.org/sqlite-wasm": "3.42.0-build7",
"expo-sqlite": "^11.3.2",
"kysely": "~0.26.1",
"micro-aes-gcm": "~0.4.0",
"nanoid": "^4.0.2"
},
"devDependencies": {
Expand All @@ -84,7 +84,7 @@
"react-dom": "^18.2.0",
"react-native": "^0.72.4",
"react-native-get-random-values": "^1.9.0",
"tslib": "^2.6.1",
"tslib": "^2.6.2",
"typescript": "^5.1.6",
"user-agent-data-types": "^0.3.1",
"vitest": "^0.34.2"
Expand Down
24 changes: 12 additions & 12 deletions packages/evolu/src/CryptoLive.web.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { aes_decrypt, aes_encrypt } from "@noble/ciphers/simple";
import { hmac } from "@noble/hashes/hmac";
import { sha512 } from "@noble/hashes/sha512";
import { Effect, Layer } from "effect";
import * as aesGcm from "micro-aes-gcm";
import { customAlphabet, nanoid } from "nanoid";
import {
AesGcm,
Expand All @@ -20,7 +20,7 @@ const importBip39WithEnglish = Effect.all(
Effect.promise(() => import("@scure/bip39")),
Effect.promise(() => import("@scure/bip39/wordlists/english")),
],
{ concurrency: "unbounded" },
{ concurrency: "unbounded" }
);

export const Bip39Live = Layer.succeed(
Expand All @@ -29,13 +29,13 @@ export const Bip39Live = Layer.succeed(
make: importBip39WithEnglish.pipe(
Effect.map(
([{ generateMnemonic }, { wordlist }]) =>
generateMnemonic(wordlist, 128) as Mnemonic,
),
generateMnemonic(wordlist, 128) as Mnemonic
)
),

toSeed: (mnemonic) =>
Effect.promise(() => import("@scure/bip39")).pipe(
Effect.flatMap((a) => Effect.promise(() => a.mnemonicToSeed(mnemonic))),
Effect.flatMap((a) => Effect.promise(() => a.mnemonicToSeed(mnemonic)))
),

parse: (mnemonic) =>
Expand All @@ -45,10 +45,10 @@ export const Bip39Live = Layer.succeed(
? Effect.succeed(mnemonic as Mnemonic)
: Effect.fail<InvalidMnemonicError>({
_tag: "InvalidMnemonicError",
}),
),
})
)
),
}),
})
);

export const HmacLive = Layer.succeed(Hmac, hmac);
Expand All @@ -62,15 +62,15 @@ export const NanoIdLive = Layer.succeed(
NanoId.of({
nanoid: Effect.sync(() => nanoid()),
nanoidAsNodeId: Effect.sync(() => nanoidForNodeId() as NodeId),
}),
})
);

export const AesGcmLive = Layer.succeed(
AesGcm,
AesGcm.of({
encrypt: (sharedKey, plaintext) =>
Effect.promise(() => aesGcm.encrypt(sharedKey, plaintext)),
Effect.promise(() => aes_encrypt(sharedKey, plaintext)),
decrypt: (sharedKey, ciphertext) =>
Effect.promise(() => aesGcm.decrypt(sharedKey, ciphertext)),
}),
Effect.promise(() => aes_decrypt(sharedKey, ciphertext)),
})
);
Loading

1 comment on commit 5f9f10b

@vercel
Copy link

@vercel vercel bot commented on 5f9f10b Aug 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

evolu – ./

evolu.dev
evolu-evolu.vercel.app
www.evolu.dev
evolu.vercel.app
evolu-git-main-evolu.vercel.app

Please sign in to comment.