@simplewebauthn/server 7.4.0 → 8.0.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 (343) hide show
  1. package/LICENSE.md +11 -14
  2. package/README.md +20 -7
  3. package/{dist → esm}/authentication/generateAuthenticationOptions.d.ts +2 -2
  4. package/esm/authentication/generateAuthenticationOptions.js +36 -0
  5. package/{dist → esm}/authentication/verifyAuthenticationResponse.d.ts +2 -2
  6. package/esm/authentication/verifyAuthenticationResponse.js +164 -0
  7. package/esm/deps.d.ts +11 -0
  8. package/esm/deps.js +14 -0
  9. package/esm/helpers/convertAAGUIDToString.js +17 -0
  10. package/esm/helpers/convertCOSEtoPKCS.js +21 -0
  11. package/{dist → esm}/helpers/convertCertBufferToPEM.d.ts +1 -1
  12. package/esm/helpers/convertCertBufferToPEM.js +31 -0
  13. package/esm/helpers/convertPEMToBytes.js +11 -0
  14. package/{dist → esm}/helpers/convertX509PublicKeyToCOSE.d.ts +1 -1
  15. package/esm/helpers/convertX509PublicKeyToCOSE.js +70 -0
  16. package/{dist → esm}/helpers/cose.d.ts +2 -1
  17. package/esm/helpers/cose.js +81 -0
  18. package/{dist → esm}/helpers/decodeAttestationObject.d.ts +3 -0
  19. package/esm/helpers/decodeAttestationObject.js +13 -0
  20. package/esm/helpers/decodeAuthenticatorExtensions.js +34 -0
  21. package/{dist → esm}/helpers/decodeClientDataJSON.d.ts +3 -0
  22. package/esm/helpers/decodeClientDataJSON.js +13 -0
  23. package/esm/helpers/decodeCredentialPublicKey.d.ts +5 -0
  24. package/esm/helpers/decodeCredentialPublicKey.js +8 -0
  25. package/esm/helpers/fetch.d.ts +8 -0
  26. package/esm/helpers/fetch.js +12 -0
  27. package/esm/helpers/generateChallenge.d.ts +7 -0
  28. package/esm/helpers/generateChallenge.js +21 -0
  29. package/{dist → esm}/helpers/getCertificateInfo.d.ts +1 -1
  30. package/esm/helpers/getCertificateInfo.js +76 -0
  31. package/esm/helpers/index.d.ts +22 -0
  32. package/esm/helpers/index.js +16 -0
  33. package/{dist → esm}/helpers/isCertRevoked.d.ts +1 -1
  34. package/esm/helpers/isCertRevoked.js +98 -0
  35. package/{dist → esm}/helpers/iso/index.d.ts +4 -4
  36. package/esm/helpers/iso/index.js +11 -0
  37. package/esm/helpers/iso/isoBase64URL.js +57 -0
  38. package/{dist → esm}/helpers/iso/isoCBOR.d.ts +1 -1
  39. package/esm/helpers/iso/isoCBOR.js +44 -0
  40. package/{dist → esm}/helpers/iso/isoCrypto/digest.d.ts +1 -1
  41. package/esm/helpers/iso/isoCrypto/digest.js +14 -0
  42. package/{dist → esm}/helpers/iso/isoCrypto/getRandomValues.d.ts +1 -1
  43. package/esm/helpers/iso/isoCrypto/getRandomValues.js +11 -0
  44. package/esm/helpers/iso/isoCrypto/getWebCrypto.d.ts +6 -0
  45. package/esm/helpers/iso/isoCrypto/getWebCrypto.js +40 -0
  46. package/esm/helpers/iso/isoCrypto/importKey.js +8 -0
  47. package/esm/helpers/iso/isoCrypto/index.d.ts +3 -0
  48. package/esm/helpers/iso/isoCrypto/index.js +3 -0
  49. package/{dist → esm}/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoAlg.d.ts +2 -2
  50. package/esm/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoAlg.js +20 -0
  51. package/{dist → esm}/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoKeyAlgName.d.ts +2 -2
  52. package/esm/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoKeyAlgName.js +19 -0
  53. package/esm/helpers/iso/isoCrypto/structs.js +1 -0
  54. package/esm/helpers/iso/isoCrypto/unwrapEC2Signature.js +30 -0
  55. package/{dist → esm}/helpers/iso/isoCrypto/verify.d.ts +1 -1
  56. package/esm/helpers/iso/isoCrypto/verify.js +28 -0
  57. package/{dist → esm}/helpers/iso/isoCrypto/verifyEC2.d.ts +1 -1
  58. package/esm/helpers/iso/isoCrypto/verifyEC2.js +73 -0
  59. package/{dist → esm}/helpers/iso/isoCrypto/verifyOKP.d.ts +1 -1
  60. package/esm/helpers/iso/isoCrypto/verifyOKP.js +51 -0
  61. package/{dist → esm}/helpers/iso/isoCrypto/verifyRSA.d.ts +1 -1
  62. package/esm/helpers/iso/isoCrypto/verifyRSA.js +91 -0
  63. package/esm/helpers/iso/isoUint8Array.js +75 -0
  64. package/{dist → esm}/helpers/logging.d.ts +1 -1
  65. package/esm/helpers/logging.js +19 -0
  66. package/{dist → esm}/helpers/mapX509SignatureAlgToCOSEAlg.d.ts +1 -1
  67. package/esm/helpers/mapX509SignatureAlgToCOSEAlg.js +35 -0
  68. package/esm/helpers/matchExpectedRPID.js +41 -0
  69. package/{dist → esm}/helpers/parseAuthenticatorData.d.ts +4 -1
  70. package/esm/helpers/parseAuthenticatorData.js +71 -0
  71. package/{dist → esm}/helpers/parseBackupFlags.d.ts +4 -1
  72. package/esm/helpers/parseBackupFlags.js +25 -0
  73. package/{dist → esm}/helpers/toHash.d.ts +1 -1
  74. package/esm/helpers/toHash.js +12 -0
  75. package/esm/helpers/validateCertificatePath.js +122 -0
  76. package/{dist → esm}/helpers/verifySignature.d.ts +4 -1
  77. package/esm/helpers/verifySignature.js +32 -0
  78. package/esm/index.d.ts +17 -0
  79. package/esm/index.js +11 -0
  80. package/{dist → esm}/metadata/mdsTypes.d.ts +1 -1
  81. package/esm/metadata/mdsTypes.js +17 -0
  82. package/esm/metadata/parseJWT.js +12 -0
  83. package/{dist → esm}/metadata/verifyAttestationWithMetadata.d.ts +3 -3
  84. package/esm/metadata/verifyAttestationWithMetadata.js +159 -0
  85. package/esm/metadata/verifyJWT.js +37 -0
  86. package/esm/package.json +3 -0
  87. package/{dist → esm}/registration/generateRegistrationOptions.d.ts +2 -2
  88. package/esm/registration/generateRegistrationOptions.js +142 -0
  89. package/esm/registration/verifications/tpm/constants.js +182 -0
  90. package/esm/registration/verifications/tpm/parseCertInfo.js +58 -0
  91. package/esm/registration/verifications/tpm/parsePubArea.js +94 -0
  92. package/{dist → esm}/registration/verifications/tpm/verifyAttestationTPM.d.ts +1 -1
  93. package/esm/registration/verifications/tpm/verifyAttestationTPM.js +323 -0
  94. package/{dist → esm}/registration/verifications/verifyAttestationAndroidKey.d.ts +1 -1
  95. package/esm/registration/verifications/verifyAttestationAndroidKey.js +90 -0
  96. package/{dist → esm}/registration/verifications/verifyAttestationAndroidSafetyNet.d.ts +1 -1
  97. package/esm/registration/verifications/verifyAttestationAndroidSafetyNet.js +112 -0
  98. package/{dist → esm}/registration/verifications/verifyAttestationApple.d.ts +1 -1
  99. package/esm/registration/verifications/verifyAttestationApple.js +57 -0
  100. package/{dist → esm}/registration/verifications/verifyAttestationFIDOU2F.d.ts +1 -1
  101. package/esm/registration/verifications/verifyAttestationFIDOU2F.js +48 -0
  102. package/{dist → esm}/registration/verifications/verifyAttestationPacked.d.ts +1 -1
  103. package/esm/registration/verifications/verifyAttestationPacked.js +105 -0
  104. package/{dist → esm}/registration/verifyRegistrationResponse.d.ts +3 -3
  105. package/esm/registration/verifyRegistrationResponse.js +198 -0
  106. package/esm/services/defaultRootCerts/android-key.js +85 -0
  107. package/esm/services/defaultRootCerts/android-safetynet.js +32 -0
  108. package/esm/services/defaultRootCerts/apple.js +25 -0
  109. package/esm/services/defaultRootCerts/mds.js +32 -0
  110. package/{dist → esm}/services/metadataService.d.ts +1 -1
  111. package/{dist → esm}/services/metadataService.js +52 -36
  112. package/{dist → esm}/services/settingsService.d.ts +1 -1
  113. package/esm/services/settingsService.js +65 -0
  114. package/package.json +40 -42
  115. package/script/authentication/generateAuthenticationOptions.d.ts +23 -0
  116. package/{dist → script}/authentication/generateAuthenticationOptions.js +8 -9
  117. package/script/authentication/verifyAuthenticationResponse.d.ts +66 -0
  118. package/{dist → script}/authentication/verifyAuthenticationResponse.js +25 -23
  119. package/script/deps.d.ts +11 -0
  120. package/script/deps.js +71 -0
  121. package/script/helpers/convertAAGUIDToString.d.ts +4 -0
  122. package/{dist → script}/helpers/convertAAGUIDToString.js +2 -3
  123. package/script/helpers/convertCOSEtoPKCS.d.ts +4 -0
  124. package/{dist → script}/helpers/convertCOSEtoPKCS.js +7 -8
  125. package/script/helpers/convertCertBufferToPEM.d.ts +5 -0
  126. package/{dist → script}/helpers/convertCertBufferToPEM.js +5 -6
  127. package/script/helpers/convertPEMToBytes.d.ts +4 -0
  128. package/{dist → script}/helpers/convertPEMToBytes.js +2 -3
  129. package/script/helpers/convertX509PublicKeyToCOSE.d.ts +2 -0
  130. package/{dist → script}/helpers/convertX509PublicKeyToCOSE.js +21 -25
  131. package/script/helpers/cose.d.ts +98 -0
  132. package/{dist → script}/helpers/cose.js +1 -1
  133. package/script/helpers/decodeAttestationObject.d.ts +29 -0
  134. package/script/helpers/decodeAttestationObject.js +17 -0
  135. package/script/helpers/decodeAuthenticatorExtensions.d.ts +20 -0
  136. package/{dist → script}/helpers/decodeAuthenticatorExtensions.js +2 -3
  137. package/script/helpers/decodeClientDataJSON.d.ts +17 -0
  138. package/script/helpers/decodeClientDataJSON.js +17 -0
  139. package/script/helpers/decodeCredentialPublicKey.d.ts +5 -0
  140. package/script/helpers/decodeCredentialPublicKey.js +12 -0
  141. package/script/helpers/fetch.d.ts +8 -0
  142. package/script/helpers/fetch.js +16 -0
  143. package/script/helpers/generateChallenge.d.ts +7 -0
  144. package/{dist → script}/helpers/generateChallenge.js +9 -6
  145. package/script/helpers/getCertificateInfo.d.ts +31 -0
  146. package/{dist → script}/helpers/getCertificateInfo.js +4 -6
  147. package/script/helpers/index.d.ts +22 -0
  148. package/script/helpers/index.js +59 -0
  149. package/script/helpers/isCertRevoked.d.ts +8 -0
  150. package/{dist → script}/helpers/isCertRevoked.js +20 -25
  151. package/script/helpers/iso/index.d.ts +11 -0
  152. package/{dist → script}/helpers/iso/index.js +4 -5
  153. package/script/helpers/iso/isoBase64URL.d.ts +37 -0
  154. package/{dist → script}/helpers/iso/isoBase64URL.js +9 -13
  155. package/script/helpers/iso/isoCBOR.d.ts +12 -0
  156. package/{dist → script}/helpers/iso/isoCBOR.js +8 -28
  157. package/script/helpers/iso/isoCrypto/digest.d.ts +8 -0
  158. package/script/helpers/iso/isoCrypto/digest.js +18 -0
  159. package/script/helpers/iso/isoCrypto/getRandomValues.d.ts +6 -0
  160. package/script/helpers/iso/isoCrypto/getRandomValues.js +15 -0
  161. package/script/helpers/iso/isoCrypto/getWebCrypto.d.ts +6 -0
  162. package/script/helpers/iso/isoCrypto/getWebCrypto.js +44 -0
  163. package/script/helpers/iso/isoCrypto/importKey.d.ts +4 -0
  164. package/script/helpers/iso/isoCrypto/importKey.js +12 -0
  165. package/script/helpers/iso/isoCrypto/index.d.ts +3 -0
  166. package/{dist → script}/helpers/iso/isoCrypto/index.js +6 -7
  167. package/script/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoAlg.d.ts +6 -0
  168. package/{dist → script}/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoAlg.js +6 -6
  169. package/script/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoKeyAlgName.d.ts +6 -0
  170. package/{dist → script}/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoKeyAlgName.js +5 -6
  171. package/script/helpers/iso/isoCrypto/structs.d.ts +3 -0
  172. package/{dist → script}/helpers/iso/isoCrypto/structs.js +0 -1
  173. package/script/helpers/iso/isoCrypto/unwrapEC2Signature.d.ts +6 -0
  174. package/{dist → script}/helpers/iso/isoCrypto/unwrapEC2Signature.js +4 -6
  175. package/script/helpers/iso/isoCrypto/verify.d.ts +10 -0
  176. package/script/helpers/iso/isoCrypto/verify.js +32 -0
  177. package/script/helpers/iso/isoCrypto/verifyEC2.d.ts +10 -0
  178. package/{dist → script}/helpers/iso/isoCrypto/verifyEC2.js +19 -22
  179. package/script/helpers/iso/isoCrypto/verifyOKP.d.ts +6 -0
  180. package/{dist → script}/helpers/iso/isoCrypto/verifyOKP.js +13 -16
  181. package/script/helpers/iso/isoCrypto/verifyRSA.d.ts +10 -0
  182. package/{dist → script}/helpers/iso/isoCrypto/verifyRSA.js +19 -22
  183. package/script/helpers/iso/isoUint8Array.d.ts +36 -0
  184. package/{dist → script}/helpers/iso/isoUint8Array.js +7 -8
  185. package/script/helpers/logging.d.ts +17 -0
  186. package/{dist → script}/helpers/logging.js +2 -6
  187. package/script/helpers/mapX509SignatureAlgToCOSEAlg.d.ts +8 -0
  188. package/{dist → script}/helpers/mapX509SignatureAlgToCOSEAlg.js +8 -9
  189. package/script/helpers/matchExpectedRPID.d.ts +7 -0
  190. package/{dist → script}/helpers/matchExpectedRPID.js +5 -6
  191. package/script/helpers/parseAuthenticatorData.d.ts +28 -0
  192. package/{dist → script}/helpers/parseAuthenticatorData.js +19 -16
  193. package/script/helpers/parseBackupFlags.d.ts +19 -0
  194. package/{dist → script}/helpers/parseBackupFlags.js +2 -2
  195. package/script/helpers/toHash.d.ts +6 -0
  196. package/{dist → script}/helpers/toHash.js +4 -5
  197. package/script/helpers/validateCertificatePath.d.ts +6 -0
  198. package/{dist → script}/helpers/validateCertificatePath.js +13 -15
  199. package/script/helpers/verifySignature.d.ts +14 -0
  200. package/script/helpers/verifySignature.js +36 -0
  201. package/script/index.d.ts +17 -0
  202. package/script/index.js +19 -0
  203. package/script/metadata/mdsTypes.d.ts +216 -0
  204. package/{dist → script}/metadata/mdsTypes.js +0 -1
  205. package/script/metadata/parseJWT.d.ts +4 -0
  206. package/{dist → script}/metadata/parseJWT.js +3 -4
  207. package/script/metadata/verifyAttestationWithMetadata.d.ts +29 -0
  208. package/{dist → script}/metadata/verifyAttestationWithMetadata.js +24 -22
  209. package/script/metadata/verifyJWT.d.ts +10 -0
  210. package/script/metadata/verifyJWT.js +41 -0
  211. package/script/package.json +3 -0
  212. package/script/registration/generateRegistrationOptions.d.ts +43 -0
  213. package/{dist → script}/registration/generateRegistrationOptions.js +9 -10
  214. package/script/registration/verifications/tpm/constants.d.ts +47 -0
  215. package/{dist → script}/registration/verifications/tpm/constants.js +1 -2
  216. package/script/registration/verifications/tpm/parseCertInfo.d.ts +24 -0
  217. package/{dist → script}/registration/verifications/tpm/parseCertInfo.js +13 -14
  218. package/script/registration/verifications/tpm/parsePubArea.d.ts +43 -0
  219. package/{dist → script}/registration/verifications/tpm/parsePubArea.js +16 -17
  220. package/script/registration/verifications/tpm/verifyAttestationTPM.d.ts +2 -0
  221. package/{dist → script}/registration/verifications/tpm/verifyAttestationTPM.js +58 -58
  222. package/script/registration/verifications/verifyAttestationAndroidKey.d.ts +5 -0
  223. package/{dist → script}/registration/verifications/verifyAttestationAndroidKey.js +22 -26
  224. package/script/registration/verifications/verifyAttestationAndroidSafetyNet.d.ts +5 -0
  225. package/{dist → script}/registration/verifications/verifyAttestationAndroidSafetyNet.js +22 -23
  226. package/script/registration/verifications/verifyAttestationApple.d.ts +2 -0
  227. package/{dist → script}/registration/verifications/verifyAttestationApple.js +15 -17
  228. package/script/registration/verifications/verifyAttestationFIDOU2F.d.ts +5 -0
  229. package/{dist → script}/registration/verifications/verifyAttestationFIDOU2F.js +12 -13
  230. package/script/registration/verifications/verifyAttestationPacked.d.ts +5 -0
  231. package/{dist → script}/registration/verifications/verifyAttestationPacked.js +17 -18
  232. package/script/registration/verifyRegistrationResponse.d.ts +85 -0
  233. package/{dist → script}/registration/verifyRegistrationResponse.js +39 -38
  234. package/script/services/defaultRootCerts/android-key.d.ts +24 -0
  235. package/{dist → script}/services/defaultRootCerts/android-key.js +0 -1
  236. package/script/services/defaultRootCerts/android-safetynet.d.ts +11 -0
  237. package/{dist → script}/services/defaultRootCerts/android-safetynet.js +0 -1
  238. package/script/services/defaultRootCerts/apple.d.ts +11 -0
  239. package/{dist → script}/services/defaultRootCerts/apple.js +0 -1
  240. package/script/services/defaultRootCerts/mds.d.ts +11 -0
  241. package/{dist → script}/services/defaultRootCerts/mds.js +0 -1
  242. package/script/services/metadataService.d.ts +53 -0
  243. package/script/services/metadataService.js +277 -0
  244. package/script/services/settingsService.d.ts +25 -0
  245. package/{dist → script}/services/settingsService.js +21 -13
  246. package/dist/authentication/generateAuthenticationOptions.js.map +0 -1
  247. package/dist/authentication/verifyAuthenticationResponse.js.map +0 -1
  248. package/dist/helpers/convertAAGUIDToString.js.map +0 -1
  249. package/dist/helpers/convertCOSEtoPKCS.js.map +0 -1
  250. package/dist/helpers/convertCertBufferToPEM.js.map +0 -1
  251. package/dist/helpers/convertPEMToBytes.js.map +0 -1
  252. package/dist/helpers/convertX509PublicKeyToCOSE.js.map +0 -1
  253. package/dist/helpers/cose.js.map +0 -1
  254. package/dist/helpers/decodeAttestationObject.js +0 -14
  255. package/dist/helpers/decodeAttestationObject.js.map +0 -1
  256. package/dist/helpers/decodeAuthenticatorExtensions.js.map +0 -1
  257. package/dist/helpers/decodeClientDataJSON.js +0 -14
  258. package/dist/helpers/decodeClientDataJSON.js.map +0 -1
  259. package/dist/helpers/decodeCredentialPublicKey.d.ts +0 -2
  260. package/dist/helpers/decodeCredentialPublicKey.js +0 -9
  261. package/dist/helpers/decodeCredentialPublicKey.js.map +0 -1
  262. package/dist/helpers/generateChallenge.d.ts +0 -4
  263. package/dist/helpers/generateChallenge.js.map +0 -1
  264. package/dist/helpers/getCertificateInfo.js.map +0 -1
  265. package/dist/helpers/index.d.ts +0 -22
  266. package/dist/helpers/index.js +0 -60
  267. package/dist/helpers/index.js.map +0 -1
  268. package/dist/helpers/isCertRevoked.js.map +0 -1
  269. package/dist/helpers/iso/index.js.map +0 -1
  270. package/dist/helpers/iso/isoBase64URL.js.map +0 -1
  271. package/dist/helpers/iso/isoCBOR.js.map +0 -1
  272. package/dist/helpers/iso/isoCrypto/digest.js +0 -21
  273. package/dist/helpers/iso/isoCrypto/digest.js.map +0 -1
  274. package/dist/helpers/iso/isoCrypto/getRandomValues.js +0 -18
  275. package/dist/helpers/iso/isoCrypto/getRandomValues.js.map +0 -1
  276. package/dist/helpers/iso/isoCrypto/importKey.js +0 -13
  277. package/dist/helpers/iso/isoCrypto/importKey.js.map +0 -1
  278. package/dist/helpers/iso/isoCrypto/index.d.ts +0 -3
  279. package/dist/helpers/iso/isoCrypto/index.js.map +0 -1
  280. package/dist/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoAlg.js.map +0 -1
  281. package/dist/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoKeyAlgName.js.map +0 -1
  282. package/dist/helpers/iso/isoCrypto/structs.js.map +0 -1
  283. package/dist/helpers/iso/isoCrypto/unwrapEC2Signature.js.map +0 -1
  284. package/dist/helpers/iso/isoCrypto/verify.js +0 -28
  285. package/dist/helpers/iso/isoCrypto/verify.js.map +0 -1
  286. package/dist/helpers/iso/isoCrypto/verifyEC2.js.map +0 -1
  287. package/dist/helpers/iso/isoCrypto/verifyOKP.js.map +0 -1
  288. package/dist/helpers/iso/isoCrypto/verifyRSA.js.map +0 -1
  289. package/dist/helpers/iso/isoUint8Array.js.map +0 -1
  290. package/dist/helpers/logging.js.map +0 -1
  291. package/dist/helpers/mapX509SignatureAlgToCOSEAlg.js.map +0 -1
  292. package/dist/helpers/matchExpectedRPID.js.map +0 -1
  293. package/dist/helpers/parseAuthenticatorData.js.map +0 -1
  294. package/dist/helpers/parseBackupFlags.js.map +0 -1
  295. package/dist/helpers/toHash.js.map +0 -1
  296. package/dist/helpers/validateCertificatePath.js.map +0 -1
  297. package/dist/helpers/verifySignature.js +0 -33
  298. package/dist/helpers/verifySignature.js.map +0 -1
  299. package/dist/index.d.ts +0 -17
  300. package/dist/index.js +0 -20
  301. package/dist/index.js.map +0 -1
  302. package/dist/metadata/mdsTypes.js.map +0 -1
  303. package/dist/metadata/parseJWT.js.map +0 -1
  304. package/dist/metadata/verifyAttestationWithMetadata.js.map +0 -1
  305. package/dist/metadata/verifyJWT.js +0 -42
  306. package/dist/metadata/verifyJWT.js.map +0 -1
  307. package/dist/registration/generateRegistrationOptions.js.map +0 -1
  308. package/dist/registration/verifications/tpm/constants.js.map +0 -1
  309. package/dist/registration/verifications/tpm/parseCertInfo.js.map +0 -1
  310. package/dist/registration/verifications/tpm/parsePubArea.js.map +0 -1
  311. package/dist/registration/verifications/tpm/verifyAttestationTPM.js.map +0 -1
  312. package/dist/registration/verifications/verifyAttestationAndroidKey.js.map +0 -1
  313. package/dist/registration/verifications/verifyAttestationAndroidSafetyNet.js.map +0 -1
  314. package/dist/registration/verifications/verifyAttestationApple.js.map +0 -1
  315. package/dist/registration/verifications/verifyAttestationFIDOU2F.js.map +0 -1
  316. package/dist/registration/verifications/verifyAttestationPacked.js.map +0 -1
  317. package/dist/registration/verifyRegistrationResponse.js.map +0 -1
  318. package/dist/services/defaultRootCerts/android-key.js.map +0 -1
  319. package/dist/services/defaultRootCerts/android-safetynet.js.map +0 -1
  320. package/dist/services/defaultRootCerts/apple.js.map +0 -1
  321. package/dist/services/defaultRootCerts/mds.js.map +0 -1
  322. package/dist/services/metadataService.js.map +0 -1
  323. package/dist/services/settingsService.js.map +0 -1
  324. /package/{dist → esm}/helpers/convertAAGUIDToString.d.ts +0 -0
  325. /package/{dist → esm}/helpers/convertCOSEtoPKCS.d.ts +0 -0
  326. /package/{dist → esm}/helpers/convertPEMToBytes.d.ts +0 -0
  327. /package/{dist → esm}/helpers/decodeAuthenticatorExtensions.d.ts +0 -0
  328. /package/{dist → esm}/helpers/iso/isoBase64URL.d.ts +0 -0
  329. /package/{dist → esm}/helpers/iso/isoCrypto/importKey.d.ts +0 -0
  330. /package/{dist → esm}/helpers/iso/isoCrypto/structs.d.ts +0 -0
  331. /package/{dist → esm}/helpers/iso/isoCrypto/unwrapEC2Signature.d.ts +0 -0
  332. /package/{dist → esm}/helpers/iso/isoUint8Array.d.ts +0 -0
  333. /package/{dist → esm}/helpers/matchExpectedRPID.d.ts +0 -0
  334. /package/{dist → esm}/helpers/validateCertificatePath.d.ts +0 -0
  335. /package/{dist → esm}/metadata/parseJWT.d.ts +0 -0
  336. /package/{dist → esm}/metadata/verifyJWT.d.ts +0 -0
  337. /package/{dist → esm}/registration/verifications/tpm/constants.d.ts +0 -0
  338. /package/{dist → esm}/registration/verifications/tpm/parseCertInfo.d.ts +0 -0
  339. /package/{dist → esm}/registration/verifications/tpm/parsePubArea.d.ts +0 -0
  340. /package/{dist → esm}/services/defaultRootCerts/android-key.d.ts +0 -0
  341. /package/{dist → esm}/services/defaultRootCerts/android-safetynet.d.ts +0 -0
  342. /package/{dist → esm}/services/defaultRootCerts/apple.d.ts +0 -0
  343. /package/{dist → esm}/services/defaultRootCerts/mds.d.ts +0 -0
@@ -12,3 +12,6 @@ export type ClientDataJSON = {
12
12
  status: 'present' | 'supported' | 'not-supported';
13
13
  };
14
14
  };
15
+ export declare const _decodeClientDataJSONInternals: {
16
+ stubThis: (value: ClientDataJSON) => ClientDataJSON;
17
+ };
@@ -0,0 +1,13 @@
1
+ import { isoBase64URL } from './iso/index.js';
2
+ /**
3
+ * Decode an authenticator's base64url-encoded clientDataJSON to JSON
4
+ */
5
+ export function decodeClientDataJSON(data) {
6
+ const toString = isoBase64URL.toString(data);
7
+ const clientData = JSON.parse(toString);
8
+ return _decodeClientDataJSONInternals.stubThis(clientData);
9
+ }
10
+ // Make it possible to stub the return value during testing
11
+ export const _decodeClientDataJSONInternals = {
12
+ stubThis: (value) => value,
13
+ };
@@ -0,0 +1,5 @@
1
+ import { COSEPublicKey } from './cose.js';
2
+ export declare function decodeCredentialPublicKey(publicKey: Uint8Array): COSEPublicKey;
3
+ export declare const _decodeCredentialPublicKeyInternals: {
4
+ stubThis: (value: COSEPublicKey) => COSEPublicKey;
5
+ };
@@ -0,0 +1,8 @@
1
+ import { isoCBOR } from './iso/index.js';
2
+ export function decodeCredentialPublicKey(publicKey) {
3
+ return _decodeCredentialPublicKeyInternals.stubThis(isoCBOR.decodeFirst(publicKey));
4
+ }
5
+ // Make it possible to stub the return value during testing
6
+ export const _decodeCredentialPublicKeyInternals = {
7
+ stubThis: (value) => value,
8
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * A simple method for requesting data via standard `fetch`. Should work
3
+ * across multiple runtimes.
4
+ */
5
+ export declare function fetch(url: string): Promise<Response>;
6
+ export declare const _fetchInternals: {
7
+ stubThis: (url: string) => Promise<Response>;
8
+ };
@@ -0,0 +1,12 @@
1
+ import { crossFetch } from '../deps.js';
2
+ /**
3
+ * A simple method for requesting data via standard `fetch`. Should work
4
+ * across multiple runtimes.
5
+ */
6
+ export function fetch(url) {
7
+ return _fetchInternals.stubThis(url);
8
+ }
9
+ // Make it possible to stub the return value during testing
10
+ export const _fetchInternals = {
11
+ stubThis: (url) => crossFetch(url),
12
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Generate a suitably random value to be used as an attestation or assertion challenge
3
+ */
4
+ export declare function generateChallenge(): Promise<Uint8Array>;
5
+ export declare const _generateChallengeInternals: {
6
+ stubThis: (value: Uint8Array) => Uint8Array;
7
+ };
@@ -0,0 +1,21 @@
1
+ import { isoCrypto } from './iso/index.js';
2
+ /**
3
+ * Generate a suitably random value to be used as an attestation or assertion challenge
4
+ */
5
+ export async function generateChallenge() {
6
+ /**
7
+ * WebAuthn spec says that 16 bytes is a good minimum:
8
+ *
9
+ * "In order to prevent replay attacks, the challenges MUST contain enough entropy to make
10
+ * guessing them infeasible. Challenges SHOULD therefore be at least 16 bytes long."
11
+ *
12
+ * Just in case, let's double it
13
+ */
14
+ const challenge = new Uint8Array(32);
15
+ await isoCrypto.getRandomValues(challenge);
16
+ return _generateChallengeInternals.stubThis(challenge);
17
+ }
18
+ // Make it possible to stub the return value during testing
19
+ export const _generateChallengeInternals = {
20
+ stubThis: (value) => value,
21
+ };
@@ -1,4 +1,4 @@
1
- import { Certificate } from '@peculiar/asn1-x509';
1
+ import { Certificate } from '../deps.js';
2
2
  export type CertificateInfo = {
3
3
  issuer: Issuer;
4
4
  subject: Subject;
@@ -0,0 +1,76 @@
1
+ import { AsnParser, BasicConstraints, Certificate, id_ce_basicConstraints } from '../deps.js';
2
+ const issuerSubjectIDKey = {
3
+ '2.5.4.6': 'C',
4
+ '2.5.4.10': 'O',
5
+ '2.5.4.11': 'OU',
6
+ '2.5.4.3': 'CN',
7
+ };
8
+ /**
9
+ * Extract PEM certificate info
10
+ *
11
+ * @param pemCertificate Result from call to `convertASN1toPEM(x5c[0])`
12
+ */
13
+ export function getCertificateInfo(leafCertBuffer) {
14
+ const x509 = AsnParser.parse(leafCertBuffer, Certificate);
15
+ const parsedCert = x509.tbsCertificate;
16
+ // Issuer
17
+ const issuer = { combined: '' };
18
+ parsedCert.issuer.forEach(([iss]) => {
19
+ const key = issuerSubjectIDKey[iss.type];
20
+ if (key) {
21
+ issuer[key] = iss.value.toString();
22
+ }
23
+ });
24
+ issuer.combined = issuerSubjectToString(issuer);
25
+ // Subject
26
+ const subject = { combined: '' };
27
+ parsedCert.subject.forEach(([iss]) => {
28
+ const key = issuerSubjectIDKey[iss.type];
29
+ if (key) {
30
+ subject[key] = iss.value.toString();
31
+ }
32
+ });
33
+ subject.combined = issuerSubjectToString(subject);
34
+ let basicConstraintsCA = false;
35
+ if (parsedCert.extensions) {
36
+ // console.log(parsedCert.extensions);
37
+ for (const ext of parsedCert.extensions) {
38
+ if (ext.extnID === id_ce_basicConstraints) {
39
+ const basicConstraints = AsnParser.parse(ext.extnValue, BasicConstraints);
40
+ basicConstraintsCA = basicConstraints.cA;
41
+ }
42
+ }
43
+ }
44
+ return {
45
+ issuer,
46
+ subject,
47
+ version: parsedCert.version,
48
+ basicConstraintsCA,
49
+ notBefore: parsedCert.validity.notBefore.getTime(),
50
+ notAfter: parsedCert.validity.notAfter.getTime(),
51
+ parsedCertificate: x509,
52
+ };
53
+ }
54
+ /**
55
+ * Stringify the parts of Issuer or Subject info for easier comparison of subject issuers with
56
+ * issuer subjects.
57
+ *
58
+ * The order might seem arbitrary, because it is. It should be enough that the two are stringified
59
+ * in the same order.
60
+ */
61
+ function issuerSubjectToString(input) {
62
+ const parts = [];
63
+ if (input.C) {
64
+ parts.push(input.C);
65
+ }
66
+ if (input.O) {
67
+ parts.push(input.O);
68
+ }
69
+ if (input.OU) {
70
+ parts.push(input.OU);
71
+ }
72
+ if (input.CN) {
73
+ parts.push(input.CN);
74
+ }
75
+ return parts.join(' : ');
76
+ }
@@ -0,0 +1,22 @@
1
+ import { convertAAGUIDToString } from './convertAAGUIDToString.js';
2
+ import { convertCertBufferToPEM } from './convertCertBufferToPEM.js';
3
+ import { convertCOSEtoPKCS } from './convertCOSEtoPKCS.js';
4
+ import { decodeAttestationObject } from './decodeAttestationObject.js';
5
+ import { decodeClientDataJSON } from './decodeClientDataJSON.js';
6
+ import { decodeCredentialPublicKey } from './decodeCredentialPublicKey.js';
7
+ import { generateChallenge } from './generateChallenge.js';
8
+ import { getCertificateInfo } from './getCertificateInfo.js';
9
+ import { isCertRevoked } from './isCertRevoked.js';
10
+ import { parseAuthenticatorData } from './parseAuthenticatorData.js';
11
+ import { toHash } from './toHash.js';
12
+ import { validateCertificatePath } from './validateCertificatePath.js';
13
+ import { verifySignature } from './verifySignature.js';
14
+ import { isoBase64URL, isoCBOR, isoCrypto, isoUint8Array } from './iso/index.js';
15
+ import * as cose from './cose.js';
16
+ export { convertAAGUIDToString, convertCertBufferToPEM, convertCOSEtoPKCS, cose, decodeAttestationObject, decodeClientDataJSON, decodeCredentialPublicKey, generateChallenge, getCertificateInfo, isCertRevoked, isoBase64URL, isoCBOR, isoCrypto, isoUint8Array, parseAuthenticatorData, toHash, validateCertificatePath, verifySignature, };
17
+ import type { AttestationFormat, AttestationObject, AttestationStatement } from './decodeAttestationObject.js';
18
+ import type { CertificateInfo } from './getCertificateInfo.js';
19
+ import type { ClientDataJSON } from './decodeClientDataJSON.js';
20
+ import type { COSEPublicKey } from './cose.js';
21
+ import type { ParsedAuthenticatorData } from './parseAuthenticatorData.js';
22
+ export type { AttestationFormat, AttestationObject, AttestationStatement, CertificateInfo, ClientDataJSON, COSEPublicKey, ParsedAuthenticatorData, };
@@ -0,0 +1,16 @@
1
+ import { convertAAGUIDToString } from './convertAAGUIDToString.js';
2
+ import { convertCertBufferToPEM } from './convertCertBufferToPEM.js';
3
+ import { convertCOSEtoPKCS } from './convertCOSEtoPKCS.js';
4
+ import { decodeAttestationObject } from './decodeAttestationObject.js';
5
+ import { decodeClientDataJSON } from './decodeClientDataJSON.js';
6
+ import { decodeCredentialPublicKey } from './decodeCredentialPublicKey.js';
7
+ import { generateChallenge } from './generateChallenge.js';
8
+ import { getCertificateInfo } from './getCertificateInfo.js';
9
+ import { isCertRevoked } from './isCertRevoked.js';
10
+ import { parseAuthenticatorData } from './parseAuthenticatorData.js';
11
+ import { toHash } from './toHash.js';
12
+ import { validateCertificatePath } from './validateCertificatePath.js';
13
+ import { verifySignature } from './verifySignature.js';
14
+ import { isoBase64URL, isoCBOR, isoCrypto, isoUint8Array } from './iso/index.js';
15
+ import * as cose from './cose.js';
16
+ export { convertAAGUIDToString, convertCertBufferToPEM, convertCOSEtoPKCS, cose, decodeAttestationObject, decodeClientDataJSON, decodeCredentialPublicKey, generateChallenge, getCertificateInfo, isCertRevoked, isoBase64URL, isoCBOR, isoCrypto, isoUint8Array, parseAuthenticatorData, toHash, validateCertificatePath, verifySignature, };
@@ -1,4 +1,4 @@
1
- import { Certificate } from '@peculiar/asn1-x509';
1
+ import { Certificate } from '../deps.js';
2
2
  /**
3
3
  * A method to pull a CRL from a certificate and compare its serial number to the list of revoked
4
4
  * certificate serial numbers within the CRL.
@@ -0,0 +1,98 @@
1
+ import { AsnParser, AuthorityKeyIdentifier, CertificateList, CRLDistributionPoints, id_ce_authorityKeyIdentifier, id_ce_cRLDistributionPoints, id_ce_subjectKeyIdentifier, SubjectKeyIdentifier, } from '../deps.js';
2
+ import { isoUint8Array } from './iso/index.js';
3
+ import { fetch } from './fetch.js';
4
+ const cacheRevokedCerts = {};
5
+ /**
6
+ * A method to pull a CRL from a certificate and compare its serial number to the list of revoked
7
+ * certificate serial numbers within the CRL.
8
+ *
9
+ * CRL certificate structure referenced from https://tools.ietf.org/html/rfc5280#page-117
10
+ */
11
+ export async function isCertRevoked(cert) {
12
+ const { extensions } = cert.tbsCertificate;
13
+ if (!extensions) {
14
+ return false;
15
+ }
16
+ let extAuthorityKeyID;
17
+ let extSubjectKeyID;
18
+ let extCRLDistributionPoints;
19
+ extensions.forEach((ext) => {
20
+ if (ext.extnID === id_ce_authorityKeyIdentifier) {
21
+ extAuthorityKeyID = AsnParser.parse(ext.extnValue, AuthorityKeyIdentifier);
22
+ }
23
+ else if (ext.extnID === id_ce_subjectKeyIdentifier) {
24
+ extSubjectKeyID = AsnParser.parse(ext.extnValue, SubjectKeyIdentifier);
25
+ }
26
+ else if (ext.extnID === id_ce_cRLDistributionPoints) {
27
+ extCRLDistributionPoints = AsnParser.parse(ext.extnValue, CRLDistributionPoints);
28
+ }
29
+ });
30
+ // Check to see if we've got cached info for the cert's CA
31
+ let keyIdentifier = undefined;
32
+ if (extAuthorityKeyID && extAuthorityKeyID.keyIdentifier) {
33
+ keyIdentifier = isoUint8Array.toHex(new Uint8Array(extAuthorityKeyID.keyIdentifier.buffer));
34
+ }
35
+ else if (extSubjectKeyID) {
36
+ /**
37
+ * We might be dealing with a self-signed root certificate. Check the
38
+ * Subject key Identifier extension next.
39
+ */
40
+ keyIdentifier = isoUint8Array.toHex(new Uint8Array(extSubjectKeyID.buffer));
41
+ }
42
+ const certSerialHex = isoUint8Array.toHex(new Uint8Array(cert.tbsCertificate.serialNumber));
43
+ if (keyIdentifier) {
44
+ const cached = cacheRevokedCerts[keyIdentifier];
45
+ if (cached) {
46
+ const now = new Date();
47
+ // If there's a nextUpdate then make sure we're before it
48
+ if (!cached.nextUpdate || cached.nextUpdate > now) {
49
+ return cached.revokedCerts.indexOf(certSerialHex) >= 0;
50
+ }
51
+ }
52
+ }
53
+ const crlURL = extCRLDistributionPoints?.[0].distributionPoint?.fullName?.[0]
54
+ .uniformResourceIdentifier;
55
+ // If no URL is provided then we have nothing to check
56
+ if (!crlURL) {
57
+ return false;
58
+ }
59
+ // Download and read the CRL
60
+ let certListBytes;
61
+ try {
62
+ const respCRL = await fetch(crlURL);
63
+ certListBytes = await respCRL.arrayBuffer();
64
+ }
65
+ catch (_err) {
66
+ return false;
67
+ }
68
+ let data;
69
+ try {
70
+ data = AsnParser.parse(certListBytes, CertificateList);
71
+ }
72
+ catch (_err) {
73
+ // Something was malformed with the CRL, so pass
74
+ return false;
75
+ }
76
+ const newCached = {
77
+ revokedCerts: [],
78
+ nextUpdate: undefined,
79
+ };
80
+ // nextUpdate
81
+ if (data.tbsCertList.nextUpdate) {
82
+ newCached.nextUpdate = data.tbsCertList.nextUpdate.getTime();
83
+ }
84
+ // revokedCertificates
85
+ const revokedCerts = data.tbsCertList.revokedCertificates;
86
+ if (revokedCerts) {
87
+ for (const cert of revokedCerts) {
88
+ const revokedHex = isoUint8Array.toHex(new Uint8Array(cert.userCertificate));
89
+ newCached.revokedCerts.push(revokedHex);
90
+ }
91
+ // Cache the results
92
+ if (keyIdentifier) {
93
+ cacheRevokedCerts[keyIdentifier] = newCached;
94
+ }
95
+ return newCached.revokedCerts.indexOf(certSerialHex) >= 0;
96
+ }
97
+ return false;
98
+ }
@@ -5,7 +5,7 @@
5
5
  * with specific server-like runtimes that expose global Web APIs (CloudFlare Workers, Deno, Bun,
6
6
  * etc...), while also supporting execution in Node.
7
7
  */
8
- export * as isoBase64URL from './isoBase64URL';
9
- export * as isoCBOR from './isoCBOR';
10
- export * as isoCrypto from './isoCrypto';
11
- export * as isoUint8Array from './isoUint8Array';
8
+ export * as isoBase64URL from './isoBase64URL.js';
9
+ export * as isoCBOR from './isoCBOR.js';
10
+ export * as isoCrypto from './isoCrypto/index.js';
11
+ export * as isoUint8Array from './isoUint8Array.js';
@@ -0,0 +1,11 @@
1
+ /**
2
+ * A collection of methods for isomorphic manipulation of trickier data types
3
+ *
4
+ * The goal with these is to make it easier to replace dependencies later that might not play well
5
+ * with specific server-like runtimes that expose global Web APIs (CloudFlare Workers, Deno, Bun,
6
+ * etc...), while also supporting execution in Node.
7
+ */
8
+ export * as isoBase64URL from './isoBase64URL.js';
9
+ export * as isoCBOR from './isoCBOR.js';
10
+ export * as isoCrypto from './isoCrypto/index.js';
11
+ export * as isoUint8Array from './isoUint8Array.js';
@@ -0,0 +1,57 @@
1
+ import { base64 } from '../../deps.js';
2
+ /**
3
+ * Decode from a Base64URL-encoded string to an ArrayBuffer. Best used when converting a
4
+ * credential ID from a JSON string to an ArrayBuffer, like in allowCredentials or
5
+ * excludeCredentials.
6
+ *
7
+ * @param buffer Value to decode from base64
8
+ * @param to (optional) The decoding to use, in case it's desirable to decode from base64 instead
9
+ */
10
+ export function toBuffer(base64urlString, from = 'base64url') {
11
+ const _buffer = base64.toArrayBuffer(base64urlString, from === 'base64url');
12
+ return new Uint8Array(_buffer);
13
+ }
14
+ /**
15
+ * Encode the given array buffer into a Base64URL-encoded string. Ideal for converting various
16
+ * credential response ArrayBuffers to string for sending back to the server as JSON.
17
+ *
18
+ * @param buffer Value to encode to base64
19
+ * @param to (optional) The encoding to use, in case it's desirable to encode to base64 instead
20
+ */
21
+ export function fromBuffer(buffer, to = 'base64url') {
22
+ return base64.fromArrayBuffer(buffer, to === 'base64url');
23
+ }
24
+ /**
25
+ * Convert a base64url string into base64
26
+ */
27
+ export function toBase64(base64urlString) {
28
+ const fromBase64Url = base64.toArrayBuffer(base64urlString, true);
29
+ const toBase64 = base64.fromArrayBuffer(fromBase64Url);
30
+ return toBase64;
31
+ }
32
+ /**
33
+ * Encode a string to base64url
34
+ */
35
+ export function fromString(ascii) {
36
+ return base64.fromString(ascii, true);
37
+ }
38
+ /**
39
+ * Decode a base64url string into its original string
40
+ */
41
+ export function toString(base64urlString) {
42
+ return base64.toString(base64urlString, true);
43
+ }
44
+ /**
45
+ * Confirm that the string is encoded into base64
46
+ */
47
+ export function isBase64(input) {
48
+ return base64.validate(input, false);
49
+ }
50
+ /**
51
+ * Confirm that the string is encoded into base64url, with support for optional padding
52
+ */
53
+ export function isBase64url(input) {
54
+ // Trim padding characters from the string if present
55
+ input = input.replace(/=/g, '');
56
+ return base64.validate(input, true);
57
+ }
@@ -9,4 +9,4 @@ export declare function decodeFirst<Type>(input: Uint8Array): Type;
9
9
  /**
10
10
  * Encode data to CBOR
11
11
  */
12
- export declare function encode(input: any): Uint8Array;
12
+ export declare function encode(input: unknown): Uint8Array;
@@ -0,0 +1,44 @@
1
+ import { cborx } from '../../deps.js';
2
+ /**
3
+ * This encoder should keep CBOR data the same length when data is re-encoded
4
+ *
5
+ * MOST CRITICALLY, this means the following needs to be true of whatever CBOR library we use:
6
+ * - CBOR Map type values MUST decode to JavaScript Maps
7
+ * - CBOR tag 64 (uint8 Typed Array) MUST NOT be used when encoding Uint8Arrays back to CBOR
8
+ *
9
+ * So long as these requirements are maintained, then CBOR sequences can be encoded and decoded
10
+ * freely while maintaining their lengths for the most accurate pointer movement across them.
11
+ */
12
+ const encoder = new cborx.Encoder({
13
+ mapsAsObjects: false,
14
+ tagUint8Array: false,
15
+ });
16
+ /**
17
+ * Decode and return the first item in a sequence of CBOR-encoded values
18
+ *
19
+ * @param input The CBOR data to decode
20
+ * @param asObject (optional) Whether to convert any CBOR Maps into JavaScript Objects. Defaults to
21
+ * `false`
22
+ */
23
+ export function decodeFirst(input) {
24
+ // Make a copy so we don't mutate the original
25
+ const _input = new Uint8Array(input);
26
+ const decoded = encoder.decodeMultiple(_input);
27
+ if (decoded === undefined) {
28
+ throw new Error('CBOR input data was empty');
29
+ }
30
+ /**
31
+ * Typing on `decoded` is `void | []` which causes TypeScript to think that it's an empty array,
32
+ * and thus you can't destructure it. I'm ignoring that because the code works fine in JS, and
33
+ * so this should be a valid operation.
34
+ */
35
+ // @ts-ignore 2493
36
+ const [first] = decoded;
37
+ return first;
38
+ }
39
+ /**
40
+ * Encode data to CBOR
41
+ */
42
+ export function encode(input) {
43
+ return encoder.encode(input);
44
+ }
@@ -1,4 +1,4 @@
1
- import { COSEALG } from '../../cose';
1
+ import { COSEALG } from '../../cose.js';
2
2
  /**
3
3
  * Generate a digest of the provided data.
4
4
  *
@@ -0,0 +1,14 @@
1
+ import { mapCoseAlgToWebCryptoAlg } from './mapCoseAlgToWebCryptoAlg.js';
2
+ import { getWebCrypto } from './getWebCrypto.js';
3
+ /**
4
+ * Generate a digest of the provided data.
5
+ *
6
+ * @param data The data to generate a digest of
7
+ * @param algorithm A COSE algorithm ID that maps to a desired SHA algorithm
8
+ */
9
+ export async function digest(data, algorithm) {
10
+ const WebCrypto = await getWebCrypto();
11
+ const subtleAlgorithm = mapCoseAlgToWebCryptoAlg(algorithm);
12
+ const hashed = await WebCrypto.subtle.digest(subtleAlgorithm, data);
13
+ return new Uint8Array(hashed);
14
+ }
@@ -3,4 +3,4 @@
3
3
  *
4
4
  * @returns the same bytes array passed into the method
5
5
  */
6
- export declare function getRandomValues(array: Uint8Array): Uint8Array;
6
+ export declare function getRandomValues(array: Uint8Array): Promise<Uint8Array>;
@@ -0,0 +1,11 @@
1
+ import { getWebCrypto } from './getWebCrypto.js';
2
+ /**
3
+ * Fill up the provided bytes array with random bytes equal to its length.
4
+ *
5
+ * @returns the same bytes array passed into the method
6
+ */
7
+ export async function getRandomValues(array) {
8
+ const WebCrypto = await getWebCrypto();
9
+ WebCrypto.getRandomValues(array);
10
+ return array;
11
+ }
@@ -0,0 +1,6 @@
1
+ import type { Crypto } from '../../../deps.js';
2
+ /**
3
+ * Try to get an instance of the Crypto API from the current runtime. Should support Node,
4
+ * as well as others, like Deno, that implement Web APIs.
5
+ */
6
+ export declare function getWebCrypto(): Promise<Crypto>;
@@ -0,0 +1,40 @@
1
+ let webCrypto = undefined;
2
+ /**
3
+ * Try to get an instance of the Crypto API from the current runtime. Should support Node,
4
+ * as well as others, like Deno, that implement Web APIs.
5
+ */
6
+ export async function getWebCrypto() {
7
+ if (webCrypto) {
8
+ return webCrypto;
9
+ }
10
+ try {
11
+ /**
12
+ * Naively attempt a Node import...
13
+ */
14
+ // @ts-ignore: We'll handle any errors...
15
+ // dnt-shim-ignore
16
+ const _crypto = await require('node:crypto');
17
+ webCrypto = _crypto.webcrypto;
18
+ }
19
+ catch (_err) {
20
+ /**
21
+ * Naively attempt to access Crypto as a global object, which popular alternative run-times
22
+ * support.
23
+ */
24
+ // @ts-ignore: ...right here.
25
+ const _crypto = globalThis.crypto;
26
+ if (!_crypto) {
27
+ // We tried to access it both in Node and globally, so bail out
28
+ throw new MissingWebCrypto();
29
+ }
30
+ webCrypto = _crypto;
31
+ }
32
+ return webCrypto;
33
+ }
34
+ class MissingWebCrypto extends Error {
35
+ constructor() {
36
+ const message = 'An instance of the Crypto API could not be located';
37
+ super(message);
38
+ this.name = 'MissingWebCrypto';
39
+ }
40
+ }
@@ -0,0 +1,8 @@
1
+ import { getWebCrypto } from './getWebCrypto.js';
2
+ export async function importKey(opts) {
3
+ const WebCrypto = await getWebCrypto();
4
+ const { keyData, algorithm } = opts;
5
+ return WebCrypto.subtle.importKey('jwk', keyData, algorithm, false, [
6
+ 'verify',
7
+ ]);
8
+ }
@@ -0,0 +1,3 @@
1
+ export { digest } from './digest.js';
2
+ export { getRandomValues } from './getRandomValues.js';
3
+ export { verify } from './verify.js';
@@ -0,0 +1,3 @@
1
+ export { digest } from './digest.js';
2
+ export { getRandomValues } from './getRandomValues.js';
3
+ export { verify } from './verify.js';
@@ -1,5 +1,5 @@
1
- import { SubtleCryptoAlg } from './structs';
2
- import { COSEALG } from '../../cose';
1
+ import { SubtleCryptoAlg } from './structs.js';
2
+ import { COSEALG } from '../../cose.js';
3
3
  /**
4
4
  * Convert a COSE alg ID into a corresponding string value that WebCrypto APIs expect
5
5
  */
@@ -0,0 +1,20 @@
1
+ import { COSEALG } from '../../cose.js';
2
+ /**
3
+ * Convert a COSE alg ID into a corresponding string value that WebCrypto APIs expect
4
+ */
5
+ export function mapCoseAlgToWebCryptoAlg(alg) {
6
+ if ([COSEALG.RS1].indexOf(alg) >= 0) {
7
+ return 'SHA-1';
8
+ }
9
+ else if ([COSEALG.ES256, COSEALG.PS256, COSEALG.RS256].indexOf(alg) >= 0) {
10
+ return 'SHA-256';
11
+ }
12
+ else if ([COSEALG.ES384, COSEALG.PS384, COSEALG.RS384].indexOf(alg) >= 0) {
13
+ return 'SHA-384';
14
+ }
15
+ else if ([COSEALG.ES512, COSEALG.PS512, COSEALG.RS512, COSEALG.EdDSA].indexOf(alg) >=
16
+ 0) {
17
+ return 'SHA-512';
18
+ }
19
+ throw new Error(`Could not map COSE alg value of ${alg} to a WebCrypto alg`);
20
+ }
@@ -1,5 +1,5 @@
1
- import { COSEALG } from '../../cose';
2
- import { SubtleCryptoKeyAlgName } from './structs';
1
+ import { COSEALG } from '../../cose.js';
2
+ import { SubtleCryptoKeyAlgName } from './structs.js';
3
3
  /**
4
4
  * Convert a COSE alg ID into a corresponding key algorithm string value that WebCrypto APIs expect
5
5
  */
@@ -0,0 +1,19 @@
1
+ import { COSEALG } from '../../cose.js';
2
+ /**
3
+ * Convert a COSE alg ID into a corresponding key algorithm string value that WebCrypto APIs expect
4
+ */
5
+ export function mapCoseAlgToWebCryptoKeyAlgName(alg) {
6
+ if ([COSEALG.EdDSA].indexOf(alg) >= 0) {
7
+ return 'Ed25519';
8
+ }
9
+ else if ([COSEALG.ES256, COSEALG.ES384, COSEALG.ES512, COSEALG.ES256K].indexOf(alg) >= 0) {
10
+ return 'ECDSA';
11
+ }
12
+ else if ([COSEALG.RS256, COSEALG.RS384, COSEALG.RS512, COSEALG.RS1].indexOf(alg) >= 0) {
13
+ return 'RSASSA-PKCS1-v1_5';
14
+ }
15
+ else if ([COSEALG.PS256, COSEALG.PS384, COSEALG.PS512].indexOf(alg) >= 0) {
16
+ return 'RSA-PSS';
17
+ }
18
+ throw new Error(`Could not map COSE alg value of ${alg} to a WebCrypto key alg name`);
19
+ }
@@ -0,0 +1 @@
1
+ export {};