Skip to content

Commit

Permalink
Update crypto libraries (bluesky-social#3335)
Browse files Browse the repository at this point in the history
* update crypto libs & use new format option

* reinstall deps

* changeset
  • Loading branch information
dholms authored Jan 7, 2025
1 parent 513b832 commit 1abfd74
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-sloths-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/crypto": patch
---

Update noble crypto libraries
2 changes: 1 addition & 1 deletion packages/aws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@aws-sdk/client-kms": "^3.196.0",
"@aws-sdk/client-s3": "^3.224.0",
"@aws-sdk/lib-storage": "^3.226.0",
"@noble/curves": "^1.1.0",
"@noble/curves": "^1.7.0",
"key-encoder": "^2.0.3",
"multiformats": "^9.9.0",
"uint8arrays": "3.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"build": "tsc --build tsconfig.build.json"
},
"dependencies": {
"@noble/curves": "^1.1.0",
"@noble/hashes": "^1.3.1",
"@noble/curves": "^1.7.0",
"@noble/hashes": "^1.6.1",
"uint8arrays": "3.0.0"
},
"devDependencies": {
Expand Down
6 changes: 1 addition & 5 deletions packages/crypto/src/p256/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ export const verifySig = async (
): Promise<boolean> => {
const allowMalleable = opts?.allowMalleableSig ?? false
const msgHash = await sha256(data)
// parse as compact sig to prevent signature malleability
// library supports sigs in 2 different formats: https://github.com/paulmillr/noble-curves/issues/99
if (!allowMalleable && !isCompactFormat(sig)) {
return false
}
return p256.verify(sig, msgHash, publicKey, {
format: allowMalleable ? undefined : 'compact', // prevent DER-encoded signatures
lowS: !allowMalleable,
})
}
Expand Down
6 changes: 1 addition & 5 deletions packages/crypto/src/secp256k1/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ export const verifySig = async (
): Promise<boolean> => {
const allowMalleable = opts?.allowMalleableSig ?? false
const msgHash = await sha256(data)
// parse as compact sig to prevent signature malleability
// library supports sigs in 2 different formats: https://github.com/paulmillr/noble-curves/issues/99
if (!allowMalleable && !isCompactFormat(sig)) {
return false
}
return k256.verify(sig, msgHash, publicKey, {
format: allowMalleable ? undefined : 'compact', // prevent DER-encoded signatures
lowS: !allowMalleable,
})
}
Expand Down
25 changes: 13 additions & 12 deletions pnpm-lock.yaml

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

0 comments on commit 1abfd74

Please sign in to comment.