@quantakrypto/core 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (314) hide show
  1. package/README.md +76 -27
  2. package/dist/cbom-merge.d.ts +9 -0
  3. package/dist/cbom-merge.d.ts.map +1 -0
  4. package/dist/cbom-merge.js +121 -0
  5. package/dist/cbom-merge.js.map +1 -0
  6. package/dist/cbom.d.ts +5 -0
  7. package/dist/cbom.d.ts.map +1 -1
  8. package/dist/cbom.js +132 -37
  9. package/dist/cbom.js.map +1 -1
  10. package/dist/comments.d.ts +6 -26
  11. package/dist/comments.d.ts.map +1 -1
  12. package/dist/comments.js +77 -38
  13. package/dist/comments.js.map +1 -1
  14. package/dist/dependencies.d.ts.map +1 -1
  15. package/dist/dependencies.js +1 -1
  16. package/dist/dependencies.js.map +1 -1
  17. package/dist/detect-utils.d.ts +59 -21
  18. package/dist/detect-utils.d.ts.map +1 -1
  19. package/dist/detect-utils.js +143 -8
  20. package/dist/detect-utils.js.map +1 -1
  21. package/dist/detectors/age.d.ts +16 -0
  22. package/dist/detectors/age.d.ts.map +1 -0
  23. package/dist/detectors/age.js +40 -0
  24. package/dist/detectors/age.js.map +1 -0
  25. package/dist/detectors/ansible.d.ts +13 -0
  26. package/dist/detectors/ansible.d.ts.map +1 -0
  27. package/dist/detectors/ansible.js +108 -0
  28. package/dist/detectors/ansible.js.map +1 -0
  29. package/dist/detectors/bicep.d.ts +20 -0
  30. package/dist/detectors/bicep.d.ts.map +1 -0
  31. package/dist/detectors/bicep.js +74 -0
  32. package/dist/detectors/bicep.js.map +1 -0
  33. package/dist/detectors/c.d.ts +4 -2
  34. package/dist/detectors/c.d.ts.map +1 -1
  35. package/dist/detectors/c.js +222 -4
  36. package/dist/detectors/c.js.map +1 -1
  37. package/dist/detectors/cicd.d.ts +27 -0
  38. package/dist/detectors/cicd.d.ts.map +1 -0
  39. package/dist/detectors/cicd.js +129 -0
  40. package/dist/detectors/cicd.js.map +1 -0
  41. package/dist/detectors/cloud-kms.d.ts +24 -0
  42. package/dist/detectors/cloud-kms.d.ts.map +1 -0
  43. package/dist/detectors/cloud-kms.js +99 -0
  44. package/dist/detectors/cloud-kms.js.map +1 -0
  45. package/dist/detectors/cloudformation.d.ts +38 -0
  46. package/dist/detectors/cloudformation.d.ts.map +1 -0
  47. package/dist/detectors/cloudformation.js +201 -0
  48. package/dist/detectors/cloudformation.js.map +1 -0
  49. package/dist/detectors/codesign.d.ts +50 -0
  50. package/dist/detectors/codesign.d.ts.map +1 -0
  51. package/dist/detectors/codesign.js +143 -0
  52. package/dist/detectors/codesign.js.map +1 -0
  53. package/dist/detectors/csharp.d.ts.map +1 -1
  54. package/dist/detectors/csharp.js +13 -3
  55. package/dist/detectors/csharp.js.map +1 -1
  56. package/dist/detectors/dart.d.ts +35 -0
  57. package/dist/detectors/dart.d.ts.map +1 -0
  58. package/dist/detectors/dart.js +177 -0
  59. package/dist/detectors/dart.js.map +1 -0
  60. package/dist/detectors/database.d.ts +19 -0
  61. package/dist/detectors/database.d.ts.map +1 -0
  62. package/dist/detectors/database.js +97 -0
  63. package/dist/detectors/database.js.map +1 -0
  64. package/dist/detectors/dkim.d.ts +54 -0
  65. package/dist/detectors/dkim.d.ts.map +1 -0
  66. package/dist/detectors/dkim.js +92 -0
  67. package/dist/detectors/dkim.js.map +1 -0
  68. package/dist/detectors/dnssec.d.ts +55 -0
  69. package/dist/detectors/dnssec.d.ts.map +1 -0
  70. package/dist/detectors/dnssec.js +116 -0
  71. package/dist/detectors/dnssec.js.map +1 -0
  72. package/dist/detectors/elixir.d.ts +20 -0
  73. package/dist/detectors/elixir.d.ts.map +1 -0
  74. package/dist/detectors/elixir.js +227 -0
  75. package/dist/detectors/elixir.js.map +1 -0
  76. package/dist/detectors/java.d.ts.map +1 -1
  77. package/dist/detectors/java.js +34 -4
  78. package/dist/detectors/java.js.map +1 -1
  79. package/dist/detectors/jose.d.ts +20 -0
  80. package/dist/detectors/jose.d.ts.map +1 -0
  81. package/dist/detectors/jose.js +72 -0
  82. package/dist/detectors/jose.js.map +1 -0
  83. package/dist/detectors/jwk.d.ts +25 -0
  84. package/dist/detectors/jwk.d.ts.map +1 -0
  85. package/dist/detectors/jwk.js +131 -0
  86. package/dist/detectors/jwk.js.map +1 -0
  87. package/dist/detectors/k8s.d.ts +17 -0
  88. package/dist/detectors/k8s.d.ts.map +1 -0
  89. package/dist/detectors/k8s.js +88 -0
  90. package/dist/detectors/k8s.js.map +1 -0
  91. package/dist/detectors/keystore.d.ts +19 -0
  92. package/dist/detectors/keystore.d.ts.map +1 -0
  93. package/dist/detectors/keystore.js +76 -0
  94. package/dist/detectors/keystore.js.map +1 -0
  95. package/dist/detectors/mesh.d.ts +34 -0
  96. package/dist/detectors/mesh.d.ts.map +1 -0
  97. package/dist/detectors/mesh.js +91 -0
  98. package/dist/detectors/mesh.js.map +1 -0
  99. package/dist/detectors/messaging.d.ts +16 -0
  100. package/dist/detectors/messaging.d.ts.map +1 -0
  101. package/dist/detectors/messaging.js +79 -0
  102. package/dist/detectors/messaging.js.map +1 -0
  103. package/dist/detectors/objc.d.ts +41 -0
  104. package/dist/detectors/objc.d.ts.map +1 -0
  105. package/dist/detectors/objc.js +146 -0
  106. package/dist/detectors/objc.js.map +1 -0
  107. package/dist/detectors/openpgp.d.ts +20 -0
  108. package/dist/detectors/openpgp.d.ts.map +1 -0
  109. package/dist/detectors/openpgp.js +151 -0
  110. package/dist/detectors/openpgp.js.map +1 -0
  111. package/dist/detectors/pem.d.ts.map +1 -1
  112. package/dist/detectors/pem.js +33 -1
  113. package/dist/detectors/pem.js.map +1 -1
  114. package/dist/detectors/php.d.ts +25 -0
  115. package/dist/detectors/php.d.ts.map +1 -0
  116. package/dist/detectors/php.js +171 -0
  117. package/dist/detectors/php.js.map +1 -0
  118. package/dist/detectors/pkcs11.d.ts +17 -0
  119. package/dist/detectors/pkcs11.d.ts.map +1 -0
  120. package/dist/detectors/pkcs11.js +87 -0
  121. package/dist/detectors/pkcs11.js.map +1 -0
  122. package/dist/detectors/proxy.d.ts +52 -0
  123. package/dist/detectors/proxy.d.ts.map +1 -0
  124. package/dist/detectors/proxy.js +157 -0
  125. package/dist/detectors/proxy.js.map +1 -0
  126. package/dist/detectors/pulumi.d.ts +19 -0
  127. package/dist/detectors/pulumi.d.ts.map +1 -0
  128. package/dist/detectors/pulumi.js +80 -0
  129. package/dist/detectors/pulumi.js.map +1 -0
  130. package/dist/detectors/python.d.ts.map +1 -1
  131. package/dist/detectors/python.js +70 -0
  132. package/dist/detectors/python.js.map +1 -1
  133. package/dist/detectors/rust.d.ts.map +1 -1
  134. package/dist/detectors/rust.js +73 -0
  135. package/dist/detectors/rust.js.map +1 -1
  136. package/dist/detectors/secrets.d.ts +24 -0
  137. package/dist/detectors/secrets.d.ts.map +1 -0
  138. package/dist/detectors/secrets.js +63 -0
  139. package/dist/detectors/secrets.js.map +1 -0
  140. package/dist/detectors/solidity.d.ts +50 -0
  141. package/dist/detectors/solidity.d.ts.map +1 -0
  142. package/dist/detectors/solidity.js +108 -0
  143. package/dist/detectors/solidity.js.map +1 -0
  144. package/dist/detectors/source.d.ts.map +1 -1
  145. package/dist/detectors/source.js +243 -53
  146. package/dist/detectors/source.js.map +1 -1
  147. package/dist/detectors/spire.d.ts +49 -0
  148. package/dist/detectors/spire.d.ts.map +1 -0
  149. package/dist/detectors/spire.js +77 -0
  150. package/dist/detectors/spire.js.map +1 -0
  151. package/dist/detectors/ssh-ca.d.ts +72 -0
  152. package/dist/detectors/ssh-ca.d.ts.map +1 -0
  153. package/dist/detectors/ssh-ca.js +119 -0
  154. package/dist/detectors/ssh-ca.js.map +1 -0
  155. package/dist/detectors/stateful-hbs.d.ts.map +1 -1
  156. package/dist/detectors/stateful-hbs.js +9 -6
  157. package/dist/detectors/stateful-hbs.js.map +1 -1
  158. package/dist/detectors/supply-chain.d.ts +17 -0
  159. package/dist/detectors/supply-chain.d.ts.map +1 -0
  160. package/dist/detectors/supply-chain.js +89 -0
  161. package/dist/detectors/supply-chain.js.map +1 -0
  162. package/dist/detectors/swift.d.ts +22 -0
  163. package/dist/detectors/swift.d.ts.map +1 -0
  164. package/dist/detectors/swift.js +120 -0
  165. package/dist/detectors/swift.js.map +1 -0
  166. package/dist/detectors/terraform.d.ts +21 -0
  167. package/dist/detectors/terraform.d.ts.map +1 -0
  168. package/dist/detectors/terraform.js +150 -0
  169. package/dist/detectors/terraform.js.map +1 -0
  170. package/dist/detectors/vault.d.ts +15 -0
  171. package/dist/detectors/vault.d.ts.map +1 -0
  172. package/dist/detectors/vault.js +97 -0
  173. package/dist/detectors/vault.js.map +1 -0
  174. package/dist/detectors/vpn.d.ts +22 -0
  175. package/dist/detectors/vpn.d.ts.map +1 -0
  176. package/dist/detectors/vpn.js +73 -0
  177. package/dist/detectors/vpn.js.map +1 -0
  178. package/dist/detectors/weak-hash.d.ts +71 -0
  179. package/dist/detectors/weak-hash.d.ts.map +1 -0
  180. package/dist/detectors/weak-hash.js +116 -0
  181. package/dist/detectors/weak-hash.js.map +1 -0
  182. package/dist/detectors/webauthn.d.ts +61 -0
  183. package/dist/detectors/webauthn.d.ts.map +1 -0
  184. package/dist/detectors/webauthn.js +109 -0
  185. package/dist/detectors/webauthn.js.map +1 -0
  186. package/dist/detectors/xmldsig.d.ts +23 -0
  187. package/dist/detectors/xmldsig.d.ts.map +1 -0
  188. package/dist/detectors/xmldsig.js +84 -0
  189. package/dist/detectors/xmldsig.js.map +1 -0
  190. package/dist/evidence.d.ts +79 -4
  191. package/dist/evidence.d.ts.map +1 -1
  192. package/dist/evidence.js +76 -0
  193. package/dist/evidence.js.map +1 -1
  194. package/dist/index.d.ts +17 -9
  195. package/dist/index.d.ts.map +1 -1
  196. package/dist/index.js +21 -9
  197. package/dist/index.js.map +1 -1
  198. package/dist/inventory.d.ts +0 -2
  199. package/dist/inventory.d.ts.map +1 -1
  200. package/dist/inventory.js +15 -6
  201. package/dist/inventory.js.map +1 -1
  202. package/dist/policy.d.ts +67 -0
  203. package/dist/policy.d.ts.map +1 -0
  204. package/dist/policy.js +115 -0
  205. package/dist/policy.js.map +1 -0
  206. package/dist/registry.d.ts +9 -4
  207. package/dist/registry.d.ts.map +1 -1
  208. package/dist/registry.js +81 -4
  209. package/dist/registry.js.map +1 -1
  210. package/dist/remediate-pipeline.d.ts +0 -3
  211. package/dist/remediate-pipeline.d.ts.map +1 -1
  212. package/dist/remediate-pipeline.js +23 -2
  213. package/dist/remediate-pipeline.js.map +1 -1
  214. package/dist/remediation.d.ts +10 -0
  215. package/dist/remediation.d.ts.map +1 -1
  216. package/dist/remediation.js +32 -0
  217. package/dist/remediation.js.map +1 -1
  218. package/dist/report.d.ts +9 -0
  219. package/dist/report.d.ts.map +1 -1
  220. package/dist/report.js +38 -1
  221. package/dist/report.js.map +1 -1
  222. package/dist/scan-worker.js +5 -3
  223. package/dist/scan-worker.js.map +1 -1
  224. package/dist/scan.d.ts.map +1 -1
  225. package/dist/scan.js +35 -6
  226. package/dist/scan.js.map +1 -1
  227. package/dist/standards-profiles.d.ts +58 -0
  228. package/dist/standards-profiles.d.ts.map +1 -0
  229. package/dist/standards-profiles.js +100 -0
  230. package/dist/standards-profiles.js.map +1 -0
  231. package/dist/standards.d.ts +96 -0
  232. package/dist/standards.d.ts.map +1 -0
  233. package/dist/standards.js +107 -0
  234. package/dist/standards.js.map +1 -0
  235. package/dist/types.d.ts +6 -5
  236. package/dist/types.d.ts.map +1 -1
  237. package/dist/types.js.map +1 -1
  238. package/dist/version.d.ts +1 -1
  239. package/dist/version.js +1 -1
  240. package/dist/version.js.map +1 -1
  241. package/dist/vex.d.ts +39 -0
  242. package/dist/vex.d.ts.map +1 -0
  243. package/dist/vex.js +87 -0
  244. package/dist/vex.js.map +1 -0
  245. package/dist/walk.d.ts +8 -3
  246. package/dist/walk.d.ts.map +1 -1
  247. package/dist/walk.js +32 -1
  248. package/dist/walk.js.map +1 -1
  249. package/package.json +1 -1
  250. package/src/cbom-merge.ts +146 -0
  251. package/src/cbom.ts +153 -39
  252. package/src/comments.ts +84 -39
  253. package/src/dependencies.ts +2 -1
  254. package/src/detect-utils.ts +146 -12
  255. package/src/detectors/age.ts +60 -0
  256. package/src/detectors/ansible.ts +140 -0
  257. package/src/detectors/bicep.ts +107 -0
  258. package/src/detectors/c.ts +240 -6
  259. package/src/detectors/cicd.ts +171 -0
  260. package/src/detectors/cloud-kms.ts +141 -0
  261. package/src/detectors/cloudformation.ts +250 -0
  262. package/src/detectors/codesign.ts +214 -0
  263. package/src/detectors/csharp.ts +13 -3
  264. package/src/detectors/dart.ts +237 -0
  265. package/src/detectors/database.ts +141 -0
  266. package/src/detectors/dkim.ts +172 -0
  267. package/src/detectors/dnssec.ts +195 -0
  268. package/src/detectors/elixir.ts +268 -0
  269. package/src/detectors/java.ts +39 -4
  270. package/src/detectors/jose.ts +110 -0
  271. package/src/detectors/jwk.ts +170 -0
  272. package/src/detectors/k8s.ts +115 -0
  273. package/src/detectors/keystore.ts +109 -0
  274. package/src/detectors/mesh.ts +130 -0
  275. package/src/detectors/messaging.ts +106 -0
  276. package/src/detectors/objc.ts +209 -0
  277. package/src/detectors/openpgp.ts +194 -0
  278. package/src/detectors/pem.ts +31 -1
  279. package/src/detectors/php.ts +230 -0
  280. package/src/detectors/pkcs11.ts +113 -0
  281. package/src/detectors/proxy.ts +236 -0
  282. package/src/detectors/pulumi.ts +106 -0
  283. package/src/detectors/python.ts +71 -0
  284. package/src/detectors/rust.ts +76 -0
  285. package/src/detectors/secrets.ts +103 -0
  286. package/src/detectors/solidity.ts +176 -0
  287. package/src/detectors/source.ts +283 -73
  288. package/src/detectors/spire.ts +143 -0
  289. package/src/detectors/ssh-ca.ts +215 -0
  290. package/src/detectors/stateful-hbs.ts +9 -6
  291. package/src/detectors/supply-chain.ts +117 -0
  292. package/src/detectors/swift.ts +149 -0
  293. package/src/detectors/terraform.ts +188 -0
  294. package/src/detectors/vault.ts +120 -0
  295. package/src/detectors/vpn.ts +103 -0
  296. package/src/detectors/weak-hash.ts +217 -0
  297. package/src/detectors/webauthn.ts +205 -0
  298. package/src/detectors/xmldsig.ts +115 -0
  299. package/src/evidence.ts +138 -4
  300. package/src/index.ts +50 -12
  301. package/src/inventory.ts +15 -7
  302. package/src/policy.ts +180 -0
  303. package/src/registry.ts +81 -4
  304. package/src/remediate-pipeline.ts +26 -3
  305. package/src/remediation.ts +39 -0
  306. package/src/report.ts +43 -1
  307. package/src/scan-worker.ts +5 -3
  308. package/src/scan.ts +41 -6
  309. package/src/standards-profiles.ts +136 -0
  310. package/src/standards.ts +186 -0
  311. package/src/types.ts +11 -4
  312. package/src/version.ts +1 -1
  313. package/src/vex.ts +122 -0
  314. package/src/walk.ts +33 -2
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Config detector: secrets encrypted at rest with classical asymmetric key
3
+ * wrapping. This is the purest "harvest now, decrypt later" surface — the
4
+ * ciphertext is often committed to a git repository, which means it is already
5
+ * replicated, effectively immortal, and retroactively un-fixable (you can
6
+ * re-encrypt HEAD, not history). Every recipient key here is classical.
7
+ *
8
+ * Covered:
9
+ * - Mozilla SOPS / age recipients: `age1…` bech32 public keys (X25519 key
10
+ * agreement wrapping the data key).
11
+ * - Bitnami Sealed Secrets: `kind: SealedSecret` (controller wraps with RSA-OAEP).
12
+ *
13
+ * Armored PGP blocks (`-----BEGIN PGP MESSAGE-----` and PGP private keys) are owned
14
+ * by the PEM detector (`pem-pgp-message` / `pem-pgp-private-key`), so they are not
15
+ * duplicated here.
16
+ *
17
+ * Symmetric-only schemes (ansible-vault AES, age with a scrypt passphrase) are
18
+ * intentionally NOT flagged: a strong symmetric key is only Grover-weakened, not
19
+ * broken, so it is out of scope for a *classical-asymmetric* readiness signal.
20
+ */
21
+ import type { Detector, Finding, RuleMeta } from "../types.js";
22
+ import {
23
+ DOC_EXTENSIONS,
24
+ eachMatch,
25
+ findingFromRule,
26
+ hasExtension,
27
+ maskCommentLines,
28
+ } from "../detect-utils.js";
29
+ import { CWE_BROKEN_CRYPTO } from "../cwe.js";
30
+
31
+ interface SecretRule {
32
+ re: RegExp;
33
+ meta: RuleMeta;
34
+ }
35
+
36
+ const SECRET_RULES: SecretRule[] = [
37
+ {
38
+ // age/SOPS recipient: `age1` + 58 bech32 chars. Distinctive enough for any file.
39
+ re: /\bage1[0-9a-z]{58}\b/g,
40
+ meta: {
41
+ id: "secrets-age-recipient",
42
+ title: "age / SOPS recipient (X25519)",
43
+ description: "An age (SOPS) recipient public key wraps secrets with classical X25519",
44
+ category: "key-exchange",
45
+ severity: "high",
46
+ confidence: "high",
47
+ algorithm: "X25519",
48
+ hndl: true,
49
+ cwe: CWE_BROKEN_CRYPTO,
50
+ message:
51
+ "Secrets are wrapped to an age/SOPS X25519 recipient (classical key agreement); harvest-now-decrypt-later exposed, and if committed to git the ciphertext is retroactively un-fixable.",
52
+ remediation:
53
+ "Track a post-quantum age recipient / KMS (ML-KEM) and re-encrypt; rotate any secret whose ciphertext has left your control.",
54
+ },
55
+ },
56
+ {
57
+ re: /\bkind:\s*["']?SealedSecret\b/g,
58
+ meta: {
59
+ id: "secrets-sealed-secret",
60
+ title: "Bitnami Sealed Secret (RSA-OAEP)",
61
+ description: "A SealedSecret is wrapped by the controller's classical RSA-OAEP key",
62
+ category: "kem",
63
+ severity: "high",
64
+ confidence: "high",
65
+ algorithm: "RSA",
66
+ hndl: true,
67
+ cwe: CWE_BROKEN_CRYPTO,
68
+ message:
69
+ "A Bitnami SealedSecret is wrapped with the controller's classical RSA-OAEP key; harvest-now-decrypt-later exposed, and typically committed to git.",
70
+ remediation:
71
+ "Plan migration as sealed-secrets adds PQC support; rotate the sealing key and secrets when it does.",
72
+ },
73
+ },
74
+ ];
75
+
76
+ /** Detects secrets encrypted at rest with classical asymmetric key wrapping. */
77
+ export const secretsDetector: Detector = {
78
+ id: "secrets-at-rest",
79
+ description:
80
+ "Secrets wrapped at rest with classical asymmetric crypto (SOPS/age, PGP, Sealed Secrets)",
81
+ scope: "config",
82
+ language: "any",
83
+ rules: SECRET_RULES.map((r) => r.meta),
84
+ // Skip prose/docs: a tutorial showing an example age recipient is not a secret store.
85
+ appliesTo: (f) => !hasExtension(f, DOC_EXTENSIONS),
86
+ detect({ file, content }): Finding[] {
87
+ // Fast reject: none of the distinctive markers present.
88
+ if (!content.includes("age1") && !content.includes("SealedSecret")) {
89
+ return [];
90
+ }
91
+ // A commented `# kind: SealedSecret` / `# age1…` is not an active setting.
92
+ const scan = maskCommentLines(content, ["#"]);
93
+ const findings: Finding[] = [];
94
+ for (const rule of SECRET_RULES) {
95
+ eachMatch(rule.re, scan, (m) => {
96
+ findings.push(
97
+ findingFromRule(rule.meta, { file, content, index: m.index, matchLength: m[0].length }),
98
+ );
99
+ });
100
+ }
101
+ return findings;
102
+ },
103
+ };
@@ -0,0 +1,176 @@
1
+ /**
2
+ * Source detector for classical asymmetric cryptography in smart-contract /
3
+ * blockchain source languages: Solidity (`.sol`), Move (`.move`), and Cairo
4
+ * (`.cairo`). On-chain signature verification is pure classical elliptic-curve
5
+ * cryptography — secp256k1 ECDSA on the EVM, Ed25519 / secp256k1 on Sui & Aptos
6
+ * (Move), and STARK-curve ECDSA on Starknet (Cairo). A cryptographically-relevant
7
+ * quantum computer (CRQC) could forge any of these on-chain authorizations.
8
+ *
9
+ * HNDL: unlike a KEM or key-agreement finding, an on-chain signature check has no
10
+ * confidentiality to harvest — there is nothing to decrypt later — so every rule
11
+ * here is `hndl: false`. The exposure is nonetheless SEVERE: on-chain keys often
12
+ * ARE the custody of the asset (an account's authorization to move funds), so a
13
+ * forged signature is a direct loss, not a downgraded confidentiality guarantee.
14
+ * That is why the findings are `severity: high` despite `hndl: false`.
15
+ *
16
+ * There is no `secp256k1` value in {@link AlgorithmFamily}; secp256k1 usage is
17
+ * mapped to `ECDSA` (the scheme), and the specific curve is named in the message.
18
+ * The STARK-curve check is likewise `ECDSA` (ECDSA over the STARK-friendly curve).
19
+ *
20
+ * Patterns (verified against OpenZeppelin, Solady, Sui/Aptos Move, Starknet docs):
21
+ * - Solidity / EVM (secp256k1 ECDSA → `sol-ecrecover`):
22
+ * `ecrecover(` (the secp256k1 precompile), OpenZeppelin/Solady
23
+ * `ECDSA.recover(` / `ECDSA.tryRecover(`,
24
+ * `SignatureChecker.isValidSignatureNow(`, and imports of the
25
+ * `.../cryptography/ECDSA.sol` / `SignatureChecker.sol` (OZ) or Solady
26
+ * `utils/ECDSA.sol` libraries. Consolidated under one rule; each distinct
27
+ * token/import is its own finding (evidence), but they cannot double-fire on
28
+ * the same span.
29
+ * - Move / Sui & Aptos:
30
+ * `ed25519::signature_verify_strict(` / `ed25519_verify(` → EdDSA
31
+ * (`sol-ed25519`); `ecdsa_k1::secp256k1_verify(` /
32
+ * `ecdsa_k1::secp256k1_ecrecover(` → ECDSA secp256k1
33
+ * (`sol-secp256k1-verify`).
34
+ * - Cairo / Starknet:
35
+ * `check_ecdsa_signature(` (also the `ecdsa::check_ecdsa_signature(`
36
+ * qualified form) → ECDSA over the STARK curve (`cairo-ecdsa`).
37
+ *
38
+ * Comment suppression is done in-detector (Solidity/Move/Cairo all use C-style
39
+ * `//` line comments and `/* … *\/` block comments), so a commented-out
40
+ * verification call cannot fire. Offsets are preserved by the maskers, so finding
41
+ * line/column stay exact.
42
+ */
43
+ import type { Detector, Finding, RuleMeta } from "../types.js";
44
+ import {
45
+ eachMatch,
46
+ findingFromRule,
47
+ hasExtension,
48
+ maskBlockComments,
49
+ maskCommentLines,
50
+ SMART_CONTRACT_EXTENSIONS,
51
+ } from "../detect-utils.js";
52
+ import { CWE_BROKEN_CRYPTO } from "../cwe.js";
53
+
54
+ // Shared remediation: no PQC on-chain signature scheme is standardized on these
55
+ // chains yet, so the actionable step today is to inventory the exposure and track
56
+ // each chain's roadmap for an alternative (quantum-safe) signature scheme.
57
+ const REMEDIATION_ONCHAIN =
58
+ "No PQC on-chain signature scheme is standardized on these chains yet; inventory this on-chain " +
59
+ "signature verification now and track chain roadmaps (e.g. account abstraction enabling " +
60
+ "alternative signature schemes) for a quantum-safe migration path.";
61
+
62
+ // --- Solidity / EVM: secp256k1 ECDSA. ---
63
+ // The secp256k1 recovery precompile. `\b` before `ecrecover` keeps it off the
64
+ // Move `secp256k1_ecrecover` token (preceded by `_`, a word char → no boundary).
65
+ const RE_SOL_ECRECOVER = /\becrecover\s*\(/g;
66
+ // OpenZeppelin / Solady library calls: `ECDSA.recover(` / `ECDSA.tryRecover(`
67
+ // and `SignatureChecker.isValidSignatureNow(`.
68
+ const RE_SOL_ECDSA_LIB =
69
+ /\bECDSA\.(?:recover|tryRecover)\s*\(|\bSignatureChecker\.isValidSignatureNow\s*\(/g;
70
+ // Import of the classical-signature libraries: OZ `.../cryptography/ECDSA.sol` /
71
+ // `.../cryptography/SignatureChecker.sol`, and Solady `.../utils/ECDSA.sol`.
72
+ const RE_SOL_ECDSA_IMPORT = /(?:cryptography|utils)\/(?:ECDSA|SignatureChecker)\.sol\b/g;
73
+
74
+ // --- Move / Sui & Aptos. ---
75
+ // Ed25519 verification: Aptos `ed25519::signature_verify_strict(`, Sui
76
+ // `ed25519::ed25519_verify(` (matched via the bare `ed25519_verify(` token).
77
+ const RE_MOVE_ED25519 = /\bed25519::signature_verify_strict\s*\(|\bed25519_verify\s*\(/g;
78
+ // secp256k1 ECDSA verification / recovery via the Sui `ecdsa_k1` module.
79
+ const RE_MOVE_SECP256K1 = /\becdsa_k1::secp256k1_(?:verify|ecrecover)\s*\(/g;
80
+
81
+ // --- Cairo / Starknet: STARK-curve ECDSA. ---
82
+ // `check_ecdsa_signature(` — also matches the qualified `ecdsa::check_ecdsa_signature(`
83
+ // (the preceding `:` is a non-word char, so the `\b` boundary still holds).
84
+ const RE_CAIRO_ECDSA = /\bcheck_ecdsa_signature\s*\(/g;
85
+
86
+ const RULE_SOL_ECRECOVER: RuleMeta = {
87
+ id: "sol-ecrecover",
88
+ title: "EVM on-chain ECDSA signature verification (secp256k1)",
89
+ description:
90
+ "Solidity ecrecover / OpenZeppelin-Solady ECDSA.recover / SignatureChecker (secp256k1)",
91
+ category: "signature",
92
+ severity: "high",
93
+ confidence: "high",
94
+ algorithm: "ECDSA",
95
+ hndl: false,
96
+ cwe: CWE_BROKEN_CRYPTO,
97
+ message:
98
+ "On-chain ECDSA over secp256k1 (Solidity/EVM: ecrecover, OpenZeppelin/Solady ECDSA / SignatureChecker) is forgeable by a quantum attacker; on-chain keys often ARE asset custody.",
99
+ remediation: REMEDIATION_ONCHAIN,
100
+ };
101
+ const RULE_MOVE_ED25519: RuleMeta = {
102
+ id: "sol-ed25519",
103
+ title: "Move on-chain Ed25519 signature verification",
104
+ description: "Move (Sui/Aptos) ed25519::signature_verify_strict / ed25519_verify",
105
+ category: "signature",
106
+ severity: "high",
107
+ confidence: "high",
108
+ algorithm: "EdDSA",
109
+ hndl: false,
110
+ cwe: CWE_BROKEN_CRYPTO,
111
+ message:
112
+ "On-chain Ed25519 signature verification (Move / Sui / Aptos) is classical and forgeable by a quantum attacker; on-chain keys often ARE asset custody.",
113
+ remediation: REMEDIATION_ONCHAIN,
114
+ };
115
+ const RULE_MOVE_SECP256K1: RuleMeta = {
116
+ id: "sol-secp256k1-verify",
117
+ title: "Move on-chain ECDSA signature verification (secp256k1)",
118
+ description: "Move (Sui) ecdsa_k1::secp256k1_verify / secp256k1_ecrecover",
119
+ category: "signature",
120
+ severity: "high",
121
+ confidence: "high",
122
+ algorithm: "ECDSA",
123
+ hndl: false,
124
+ cwe: CWE_BROKEN_CRYPTO,
125
+ message:
126
+ "On-chain ECDSA over secp256k1 (Move / Sui ecdsa_k1) is forgeable by a quantum attacker; on-chain keys often ARE asset custody.",
127
+ remediation: REMEDIATION_ONCHAIN,
128
+ };
129
+ const RULE_CAIRO_ECDSA: RuleMeta = {
130
+ id: "cairo-ecdsa",
131
+ title: "Cairo/Starknet on-chain ECDSA signature verification (STARK curve)",
132
+ description: "Cairo check_ecdsa_signature (STARK-curve ECDSA)",
133
+ category: "signature",
134
+ severity: "high",
135
+ confidence: "high",
136
+ algorithm: "ECDSA",
137
+ hndl: false,
138
+ cwe: CWE_BROKEN_CRYPTO,
139
+ message:
140
+ "On-chain ECDSA over the STARK curve (Cairo/Starknet check_ecdsa_signature) is forgeable by a quantum attacker; on-chain keys often ARE asset custody.",
141
+ remediation: REMEDIATION_ONCHAIN,
142
+ };
143
+
144
+ /**
145
+ * Detects classical (quantum-vulnerable) on-chain signature verification in
146
+ * smart-contract source: Solidity/EVM secp256k1 ECDSA, Move Ed25519 & secp256k1,
147
+ * and Cairo/Starknet STARK-curve ECDSA.
148
+ */
149
+ export const solidityDetector: Detector = {
150
+ id: "solidity-crypto",
151
+ description:
152
+ "Classical on-chain signature verification in smart-contract source (Solidity, Move, Cairo)",
153
+ scope: "source",
154
+ language: "solidity",
155
+ rules: [RULE_SOL_ECRECOVER, RULE_MOVE_ED25519, RULE_MOVE_SECP256K1, RULE_CAIRO_ECDSA],
156
+ appliesTo: (f) => hasExtension(f, SMART_CONTRACT_EXTENSIONS),
157
+ detect({ file, content }): Finding[] {
158
+ // Mask C-style comments (line `//` + block `/* */`) so commented-out
159
+ // verification calls can't fire; the maskers preserve byte offsets.
160
+ const scan = maskCommentLines(maskBlockComments(content), ["//"]);
161
+ const findings: Finding[] = [];
162
+ const add = (re: RegExp, rule: RuleMeta) =>
163
+ eachMatch(re, scan, (m) =>
164
+ findings.push(
165
+ findingFromRule(rule, { file, content, index: m.index, matchLength: m[0].length }),
166
+ ),
167
+ );
168
+ add(RE_SOL_ECRECOVER, RULE_SOL_ECRECOVER);
169
+ add(RE_SOL_ECDSA_LIB, RULE_SOL_ECRECOVER);
170
+ add(RE_SOL_ECDSA_IMPORT, RULE_SOL_ECRECOVER);
171
+ add(RE_MOVE_ED25519, RULE_MOVE_ED25519);
172
+ add(RE_MOVE_SECP256K1, RULE_MOVE_SECP256K1);
173
+ add(RE_CAIRO_ECDSA, RULE_CAIRO_ECDSA);
174
+ return findings;
175
+ },
176
+ };