ts-mls 1.0.2

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 (583) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +196 -0
  3. package/dist/src/IncomingMessageAction.d.ts +10 -0
  4. package/dist/src/IncomingMessageAction.js +2 -0
  5. package/dist/src/IncomingMessageAction.js.map +1 -0
  6. package/dist/src/authenticatedContent.d.ts +32 -0
  7. package/dist/src/authenticatedContent.js +26 -0
  8. package/dist/src/authenticatedContent.js.map +1 -0
  9. package/dist/src/authenticationService.d.ts +7 -0
  10. package/dist/src/authenticationService.js +6 -0
  11. package/dist/src/authenticationService.js.map +1 -0
  12. package/dist/src/capabilities.d.ts +14 -0
  13. package/dist/src/capabilities.js +28 -0
  14. package/dist/src/capabilities.js.map +1 -0
  15. package/dist/src/clientConfig.d.ts +21 -0
  16. package/dist/src/clientConfig.js +13 -0
  17. package/dist/src/clientConfig.js.map +1 -0
  18. package/dist/src/clientState.d.ts +122 -0
  19. package/dist/src/clientState.js +547 -0
  20. package/dist/src/clientState.js.map +1 -0
  21. package/dist/src/codec/number.d.ts +10 -0
  22. package/dist/src/codec/number.js +56 -0
  23. package/dist/src/codec/number.js.map +1 -0
  24. package/dist/src/codec/optional.d.ts +4 -0
  25. package/dist/src/codec/optional.js +20 -0
  26. package/dist/src/codec/optional.js.map +1 -0
  27. package/dist/src/codec/tlsDecoder.d.ts +14 -0
  28. package/dist/src/codec/tlsDecoder.js +78 -0
  29. package/dist/src/codec/tlsDecoder.js.map +1 -0
  30. package/dist/src/codec/tlsEncoder.d.ts +9 -0
  31. package/dist/src/codec/tlsEncoder.js +23 -0
  32. package/dist/src/codec/tlsEncoder.js.map +1 -0
  33. package/dist/src/codec/variableLength.d.ts +11 -0
  34. package/dist/src/codec/variableLength.js +95 -0
  35. package/dist/src/codec/variableLength.js.map +1 -0
  36. package/dist/src/commit.d.ts +10 -0
  37. package/dist/src/commit.js +9 -0
  38. package/dist/src/commit.js.map +1 -0
  39. package/dist/src/contentType.d.ts +12 -0
  40. package/dist/src/contentType.js +12 -0
  41. package/dist/src/contentType.js.map +1 -0
  42. package/dist/src/createCommit.d.ts +32 -0
  43. package/dist/src/createCommit.js +250 -0
  44. package/dist/src/createCommit.js.map +1 -0
  45. package/dist/src/createMessage.d.ts +24 -0
  46. package/dist/src/createMessage.js +32 -0
  47. package/dist/src/createMessage.js.map +1 -0
  48. package/dist/src/credential.d.ts +21 -0
  49. package/dist/src/credential.js +31 -0
  50. package/dist/src/credential.js.map +1 -0
  51. package/dist/src/credentialType.d.ts +11 -0
  52. package/dist/src/credentialType.js +11 -0
  53. package/dist/src/credentialType.js.map +1 -0
  54. package/dist/src/crypto/aead.d.ts +8 -0
  55. package/dist/src/crypto/aead.js +69 -0
  56. package/dist/src/crypto/aead.js.map +1 -0
  57. package/dist/src/crypto/ciphersuite.d.ts +51 -0
  58. package/dist/src/crypto/ciphersuite.js +245 -0
  59. package/dist/src/crypto/ciphersuite.js.map +1 -0
  60. package/dist/src/crypto/hash.d.ts +8 -0
  61. package/dist/src/crypto/hash.js +32 -0
  62. package/dist/src/crypto/hash.js.map +1 -0
  63. package/dist/src/crypto/hpke.d.ts +51 -0
  64. package/dist/src/crypto/hpke.js +109 -0
  65. package/dist/src/crypto/hpke.js.map +1 -0
  66. package/dist/src/crypto/kdf.d.ts +12 -0
  67. package/dist/src/crypto/kdf.js +42 -0
  68. package/dist/src/crypto/kdf.js.map +1 -0
  69. package/dist/src/crypto/kem.d.ts +3 -0
  70. package/dist/src/crypto/kem.js +49 -0
  71. package/dist/src/crypto/kem.js.map +1 -0
  72. package/dist/src/crypto/rng.d.ts +4 -0
  73. package/dist/src/crypto/rng.js +6 -0
  74. package/dist/src/crypto/rng.js.map +1 -0
  75. package/dist/src/crypto/signature.d.ts +12 -0
  76. package/dist/src/crypto/signature.js +127 -0
  77. package/dist/src/crypto/signature.js.map +1 -0
  78. package/dist/src/customCredential.d.ts +2 -0
  79. package/dist/src/customCredential.js +11 -0
  80. package/dist/src/customCredential.js.map +1 -0
  81. package/dist/src/defaultCapabilities.d.ts +2 -0
  82. package/dist/src/defaultCapabilities.js +12 -0
  83. package/dist/src/defaultCapabilities.js.map +1 -0
  84. package/dist/src/defaultExtensionType.d.ts +13 -0
  85. package/dist/src/defaultExtensionType.js +14 -0
  86. package/dist/src/defaultExtensionType.js.map +1 -0
  87. package/dist/src/defaultProposalType.d.ts +15 -0
  88. package/dist/src/defaultProposalType.js +16 -0
  89. package/dist/src/defaultProposalType.js.map +1 -0
  90. package/dist/src/extension.d.ts +18 -0
  91. package/dist/src/extension.js +30 -0
  92. package/dist/src/extension.js.map +1 -0
  93. package/dist/src/externalProposal.d.ts +7 -0
  94. package/dist/src/externalProposal.js +40 -0
  95. package/dist/src/externalProposal.js.map +1 -0
  96. package/dist/src/externalSender.d.ts +9 -0
  97. package/dist/src/externalSender.js +7 -0
  98. package/dist/src/externalSender.js.map +1 -0
  99. package/dist/src/framedContent.d.ts +113 -0
  100. package/dist/src/framedContent.js +131 -0
  101. package/dist/src/framedContent.js.map +1 -0
  102. package/dist/src/grease.d.ts +16 -0
  103. package/dist/src/grease.js +29 -0
  104. package/dist/src/grease.js.map +1 -0
  105. package/dist/src/groupContext.d.ts +19 -0
  106. package/dist/src/groupContext.js +44 -0
  107. package/dist/src/groupContext.js.map +1 -0
  108. package/dist/src/groupInfo.d.ts +26 -0
  109. package/dist/src/groupInfo.js +47 -0
  110. package/dist/src/groupInfo.js.map +1 -0
  111. package/dist/src/groupSecrets.d.ts +10 -0
  112. package/dist/src/groupSecrets.js +8 -0
  113. package/dist/src/groupSecrets.js.map +1 -0
  114. package/dist/src/hpkeCiphertext.d.ts +8 -0
  115. package/dist/src/hpkeCiphertext.js +6 -0
  116. package/dist/src/hpkeCiphertext.js.map +1 -0
  117. package/dist/src/index.d.ts +32 -0
  118. package/dist/src/index.js +24 -0
  119. package/dist/src/index.js.map +1 -0
  120. package/dist/src/keyPackage.d.ts +38 -0
  121. package/dist/src/keyPackage.js +72 -0
  122. package/dist/src/keyPackage.js.map +1 -0
  123. package/dist/src/keyPackageEqualityConfig.d.ts +7 -0
  124. package/dist/src/keyPackageEqualityConfig.js +10 -0
  125. package/dist/src/keyPackageEqualityConfig.js.map +1 -0
  126. package/dist/src/keyRetentionConfig.d.ts +6 -0
  127. package/dist/src/keyRetentionConfig.js +6 -0
  128. package/dist/src/keyRetentionConfig.js.map +1 -0
  129. package/dist/src/keySchedule.d.ts +24 -0
  130. package/dist/src/keySchedule.js +43 -0
  131. package/dist/src/keySchedule.js.map +1 -0
  132. package/dist/src/leafNode.d.ts +78 -0
  133. package/dist/src/leafNode.js +87 -0
  134. package/dist/src/leafNode.js.map +1 -0
  135. package/dist/src/leafNodeSource.d.ts +12 -0
  136. package/dist/src/leafNodeSource.js +12 -0
  137. package/dist/src/leafNodeSource.js.map +1 -0
  138. package/dist/src/lifetime.d.ts +9 -0
  139. package/dist/src/lifetime.js +13 -0
  140. package/dist/src/lifetime.js.map +1 -0
  141. package/dist/src/lifetimeConfig.d.ts +5 -0
  142. package/dist/src/lifetimeConfig.js +5 -0
  143. package/dist/src/lifetimeConfig.js.map +1 -0
  144. package/dist/src/message.d.ts +42 -0
  145. package/dist/src/message.js +45 -0
  146. package/dist/src/message.js.map +1 -0
  147. package/dist/src/messageProtection.d.ts +36 -0
  148. package/dist/src/messageProtection.js +128 -0
  149. package/dist/src/messageProtection.js.map +1 -0
  150. package/dist/src/messageProtectionPublic.d.ts +17 -0
  151. package/dist/src/messageProtectionPublic.js +99 -0
  152. package/dist/src/messageProtectionPublic.js.map +1 -0
  153. package/dist/src/mlsError.d.ts +24 -0
  154. package/dist/src/mlsError.js +49 -0
  155. package/dist/src/mlsError.js.map +1 -0
  156. package/dist/src/nodeType.d.ts +11 -0
  157. package/dist/src/nodeType.js +11 -0
  158. package/dist/src/nodeType.js.map +1 -0
  159. package/dist/src/paddingConfig.d.ts +9 -0
  160. package/dist/src/paddingConfig.js +8 -0
  161. package/dist/src/paddingConfig.js.map +1 -0
  162. package/dist/src/parentHash.d.ts +16 -0
  163. package/dist/src/parentHash.js +103 -0
  164. package/dist/src/parentHash.js.map +1 -0
  165. package/dist/src/parentNode.d.ts +9 -0
  166. package/dist/src/parentNode.js +11 -0
  167. package/dist/src/parentNode.js.map +1 -0
  168. package/dist/src/pathSecrets.d.ts +10 -0
  169. package/dist/src/pathSecrets.js +31 -0
  170. package/dist/src/pathSecrets.js.map +1 -0
  171. package/dist/src/presharedkey.d.ts +51 -0
  172. package/dist/src/presharedkey.js +59 -0
  173. package/dist/src/presharedkey.js.map +1 -0
  174. package/dist/src/privateKeyPath.d.ts +12 -0
  175. package/dist/src/privateKeyPath.js +21 -0
  176. package/dist/src/privateKeyPath.js.map +1 -0
  177. package/dist/src/privateMessage.d.ts +41 -0
  178. package/dist/src/privateMessage.js +114 -0
  179. package/dist/src/privateMessage.js.map +1 -0
  180. package/dist/src/processMessages.d.ts +26 -0
  181. package/dist/src/processMessages.js +196 -0
  182. package/dist/src/processMessages.js.map +1 -0
  183. package/dist/src/proposal.d.ts +97 -0
  184. package/dist/src/proposal.js +91 -0
  185. package/dist/src/proposal.js.map +1 -0
  186. package/dist/src/proposalOrRefType.d.ts +25 -0
  187. package/dist/src/proposalOrRefType.js +31 -0
  188. package/dist/src/proposalOrRefType.js.map +1 -0
  189. package/dist/src/protocolVersion.d.ts +9 -0
  190. package/dist/src/protocolVersion.js +10 -0
  191. package/dist/src/protocolVersion.js.map +1 -0
  192. package/dist/src/pskIndex.d.ts +7 -0
  193. package/dist/src/pskIndex.js +18 -0
  194. package/dist/src/pskIndex.js.map +1 -0
  195. package/dist/src/publicMessage.d.ts +29 -0
  196. package/dist/src/publicMessage.js +71 -0
  197. package/dist/src/publicMessage.js.map +1 -0
  198. package/dist/src/ratchetTree.d.ts +46 -0
  199. package/dist/src/ratchetTree.js +254 -0
  200. package/dist/src/ratchetTree.js.map +1 -0
  201. package/dist/src/requiredCapabilities.d.ts +10 -0
  202. package/dist/src/requiredCapabilities.js +8 -0
  203. package/dist/src/requiredCapabilities.js.map +1 -0
  204. package/dist/src/resumption.d.ts +18 -0
  205. package/dist/src/resumption.js +74 -0
  206. package/dist/src/resumption.js.map +1 -0
  207. package/dist/src/secretTree.d.ts +29 -0
  208. package/dist/src/secretTree.js +137 -0
  209. package/dist/src/secretTree.js.map +1 -0
  210. package/dist/src/sender.d.ts +56 -0
  211. package/dist/src/sender.js +81 -0
  212. package/dist/src/sender.js.map +1 -0
  213. package/dist/src/transcriptHash.d.ts +14 -0
  214. package/dist/src/transcriptHash.js +23 -0
  215. package/dist/src/transcriptHash.js.map +1 -0
  216. package/dist/src/treeHash.d.ts +27 -0
  217. package/dist/src/treeHash.js +70 -0
  218. package/dist/src/treeHash.js.map +1 -0
  219. package/dist/src/treemath.d.ts +14 -0
  220. package/dist/src/treemath.js +87 -0
  221. package/dist/src/treemath.js.map +1 -0
  222. package/dist/src/unappliedProposals.d.ts +7 -0
  223. package/dist/src/unappliedProposals.js +9 -0
  224. package/dist/src/unappliedProposals.js.map +1 -0
  225. package/dist/src/updatePath.d.ts +34 -0
  226. package/dist/src/updatePath.js +163 -0
  227. package/dist/src/updatePath.js.map +1 -0
  228. package/dist/src/util/addToMap.d.ts +1 -0
  229. package/dist/src/util/addToMap.js +6 -0
  230. package/dist/src/util/addToMap.js.map +1 -0
  231. package/dist/src/util/array.d.ts +2 -0
  232. package/dist/src/util/array.js +9 -0
  233. package/dist/src/util/array.js.map +1 -0
  234. package/dist/src/util/byteArray.d.ts +3 -0
  235. package/dist/src/util/byteArray.js +27 -0
  236. package/dist/src/util/byteArray.js.map +1 -0
  237. package/dist/src/util/constantTimeCompare.d.ts +1 -0
  238. package/dist/src/util/constantTimeCompare.js +10 -0
  239. package/dist/src/util/constantTimeCompare.js.map +1 -0
  240. package/dist/src/util/enumHelpers.d.ts +4 -0
  241. package/dist/src/util/enumHelpers.js +28 -0
  242. package/dist/src/util/enumHelpers.js.map +1 -0
  243. package/dist/src/util/repeat.d.ts +1 -0
  244. package/dist/src/util/repeat.js +8 -0
  245. package/dist/src/util/repeat.js.map +1 -0
  246. package/dist/src/welcome.d.ts +29 -0
  247. package/dist/src/welcome.js +46 -0
  248. package/dist/src/welcome.js.map +1 -0
  249. package/dist/src/wireformat.d.ts +13 -0
  250. package/dist/src/wireformat.js +14 -0
  251. package/dist/src/wireformat.js.map +1 -0
  252. package/dist/test/base64.test.d.ts +1 -0
  253. package/dist/test/base64.test.js +87 -0
  254. package/dist/test/base64.test.js.map +1 -0
  255. package/dist/test/codec/authenticatedContent.test.d.ts +1 -0
  256. package/dist/test/codec/authenticatedContent.test.js +38 -0
  257. package/dist/test/codec/authenticatedContent.test.js.map +1 -0
  258. package/dist/test/codec/capabilities.test.d.ts +1 -0
  259. package/dist/test/codec/capabilities.test.js +26 -0
  260. package/dist/test/codec/capabilities.test.js.map +1 -0
  261. package/dist/test/codec/commit.test.d.ts +1 -0
  262. package/dist/test/codec/commit.test.js +15 -0
  263. package/dist/test/codec/commit.test.js.map +1 -0
  264. package/dist/test/codec/composite.test.d.ts +1 -0
  265. package/dist/test/codec/composite.test.js +61 -0
  266. package/dist/test/codec/composite.test.js.map +1 -0
  267. package/dist/test/codec/contentType.test.d.ts +1 -0
  268. package/dist/test/codec/contentType.test.js +12 -0
  269. package/dist/test/codec/contentType.test.js.map +1 -0
  270. package/dist/test/codec/credential.test.d.ts +1 -0
  271. package/dist/test/codec/credential.test.js +17 -0
  272. package/dist/test/codec/credential.test.js.map +1 -0
  273. package/dist/test/codec/credentialType.test.d.ts +1 -0
  274. package/dist/test/codec/credentialType.test.js +12 -0
  275. package/dist/test/codec/credentialType.test.js.map +1 -0
  276. package/dist/test/codec/encryptedGroupSecrets.test.d.ts +1 -0
  277. package/dist/test/codec/encryptedGroupSecrets.test.js +18 -0
  278. package/dist/test/codec/encryptedGroupSecrets.test.js.map +1 -0
  279. package/dist/test/codec/extension.test.d.ts +1 -0
  280. package/dist/test/codec/extension.test.js +20 -0
  281. package/dist/test/codec/extension.test.js.map +1 -0
  282. package/dist/test/codec/extensionType.test.d.ts +1 -0
  283. package/dist/test/codec/extensionType.test.js +12 -0
  284. package/dist/test/codec/extensionType.test.js.map +1 -0
  285. package/dist/test/codec/externalSender.test.d.ts +1 -0
  286. package/dist/test/codec/externalSender.test.js +20 -0
  287. package/dist/test/codec/externalSender.test.js.map +1 -0
  288. package/dist/test/codec/framedContent.test.d.ts +1 -0
  289. package/dist/test/codec/framedContent.test.js +26 -0
  290. package/dist/test/codec/framedContent.test.js.map +1 -0
  291. package/dist/test/codec/groupContext.test.d.ts +1 -0
  292. package/dist/test/codec/groupContext.test.js +30 -0
  293. package/dist/test/codec/groupContext.test.js.map +1 -0
  294. package/dist/test/codec/groupInfo.test.d.ts +1 -0
  295. package/dist/test/codec/groupInfo.test.js +45 -0
  296. package/dist/test/codec/groupInfo.test.js.map +1 -0
  297. package/dist/test/codec/groupSecrets.test.d.ts +1 -0
  298. package/dist/test/codec/groupSecrets.test.js +16 -0
  299. package/dist/test/codec/groupSecrets.test.js.map +1 -0
  300. package/dist/test/codec/hpkeCiphertext.test.d.ts +1 -0
  301. package/dist/test/codec/hpkeCiphertext.test.js +13 -0
  302. package/dist/test/codec/hpkeCiphertext.test.js.map +1 -0
  303. package/dist/test/codec/keyPackage.test.d.ts +1 -0
  304. package/dist/test/codec/keyPackage.test.js +58 -0
  305. package/dist/test/codec/keyPackage.test.js.map +1 -0
  306. package/dist/test/codec/keyPackageTBS.test.d.ts +1 -0
  307. package/dist/test/codec/keyPackageTBS.test.js +59 -0
  308. package/dist/test/codec/keyPackageTBS.test.js.map +1 -0
  309. package/dist/test/codec/leafNode.test.d.ts +1 -0
  310. package/dist/test/codec/leafNode.test.js +43 -0
  311. package/dist/test/codec/leafNode.test.js.map +1 -0
  312. package/dist/test/codec/leafNodeData.test.d.ts +1 -0
  313. package/dist/test/codec/leafNodeData.test.js +36 -0
  314. package/dist/test/codec/leafNodeData.test.js.map +1 -0
  315. package/dist/test/codec/leafNodeSource.test.d.ts +1 -0
  316. package/dist/test/codec/leafNodeSource.test.js +15 -0
  317. package/dist/test/codec/leafNodeSource.test.js.map +1 -0
  318. package/dist/test/codec/lifetime.test.d.ts +1 -0
  319. package/dist/test/codec/lifetime.test.js +12 -0
  320. package/dist/test/codec/lifetime.test.js.map +1 -0
  321. package/dist/test/codec/message.test.d.ts +1 -0
  322. package/dist/test/codec/message.test.js +100 -0
  323. package/dist/test/codec/message.test.js.map +1 -0
  324. package/dist/test/codec/nodeType.test.d.ts +1 -0
  325. package/dist/test/codec/nodeType.test.js +12 -0
  326. package/dist/test/codec/nodeType.test.js.map +1 -0
  327. package/dist/test/codec/number.test.d.ts +1 -0
  328. package/dist/test/codec/number.test.js +74 -0
  329. package/dist/test/codec/number.test.js.map +1 -0
  330. package/dist/test/codec/optional.test.d.ts +1 -0
  331. package/dist/test/codec/optional.test.js +42 -0
  332. package/dist/test/codec/optional.test.js.map +1 -0
  333. package/dist/test/codec/padding.test.d.ts +1 -0
  334. package/dist/test/codec/padding.test.js +40 -0
  335. package/dist/test/codec/padding.test.js.map +1 -0
  336. package/dist/test/codec/parentHash.test.d.ts +1 -0
  337. package/dist/test/codec/parentHash.test.js +13 -0
  338. package/dist/test/codec/parentHash.test.js.map +1 -0
  339. package/dist/test/codec/parentNode.test.d.ts +1 -0
  340. package/dist/test/codec/parentNode.test.js +22 -0
  341. package/dist/test/codec/parentNode.test.js.map +1 -0
  342. package/dist/test/codec/presharedkey.test.d.ts +1 -0
  343. package/dist/test/codec/presharedkey.test.js +35 -0
  344. package/dist/test/codec/presharedkey.test.js.map +1 -0
  345. package/dist/test/codec/privateContentAAD.test.d.ts +1 -0
  346. package/dist/test/codec/privateContentAAD.test.js +30 -0
  347. package/dist/test/codec/privateContentAAD.test.js.map +1 -0
  348. package/dist/test/codec/privateMessage.test.d.ts +1 -0
  349. package/dist/test/codec/privateMessage.test.js +36 -0
  350. package/dist/test/codec/privateMessage.test.js.map +1 -0
  351. package/dist/test/codec/proposal.test.d.ts +1 -0
  352. package/dist/test/codec/proposal.test.js +44 -0
  353. package/dist/test/codec/proposal.test.js.map +1 -0
  354. package/dist/test/codec/proposalOrRef.test.d.ts +1 -0
  355. package/dist/test/codec/proposalOrRef.test.js +12 -0
  356. package/dist/test/codec/proposalOrRef.test.js.map +1 -0
  357. package/dist/test/codec/proposalOrRefType.test.d.ts +1 -0
  358. package/dist/test/codec/proposalOrRefType.test.js +12 -0
  359. package/dist/test/codec/proposalOrRefType.test.js.map +1 -0
  360. package/dist/test/codec/proposalType.test.d.ts +1 -0
  361. package/dist/test/codec/proposalType.test.js +12 -0
  362. package/dist/test/codec/proposalType.test.js.map +1 -0
  363. package/dist/test/codec/protocolVersion.test.d.ts +1 -0
  364. package/dist/test/codec/protocolVersion.test.js +9 -0
  365. package/dist/test/codec/protocolVersion.test.js.map +1 -0
  366. package/dist/test/codec/pskId.test.d.ts +1 -0
  367. package/dist/test/codec/pskId.test.js +18 -0
  368. package/dist/test/codec/pskId.test.js.map +1 -0
  369. package/dist/test/codec/pskInfo.test.d.ts +1 -0
  370. package/dist/test/codec/pskInfo.test.js +12 -0
  371. package/dist/test/codec/pskInfo.test.js.map +1 -0
  372. package/dist/test/codec/pskLabel.test.d.ts +1 -0
  373. package/dist/test/codec/pskLabel.test.js +26 -0
  374. package/dist/test/codec/pskLabel.test.js.map +1 -0
  375. package/dist/test/codec/pskType.test.d.ts +1 -0
  376. package/dist/test/codec/pskType.test.js +12 -0
  377. package/dist/test/codec/pskType.test.js.map +1 -0
  378. package/dist/test/codec/publicMessage.test.d.ts +1 -0
  379. package/dist/test/codec/publicMessage.test.js +39 -0
  380. package/dist/test/codec/publicMessage.test.js.map +1 -0
  381. package/dist/test/codec/ratchetTree.test.d.ts +1 -0
  382. package/dist/test/codec/ratchetTree.test.js +83 -0
  383. package/dist/test/codec/ratchetTree.test.js.map +1 -0
  384. package/dist/test/codec/requiredCapabilities.test.d.ts +1 -0
  385. package/dist/test/codec/requiredCapabilities.test.js +30 -0
  386. package/dist/test/codec/requiredCapabilities.test.js.map +1 -0
  387. package/dist/test/codec/resumptionPSKUsage.test.d.ts +1 -0
  388. package/dist/test/codec/resumptionPSKUsage.test.js +15 -0
  389. package/dist/test/codec/resumptionPSKUsage.test.js.map +1 -0
  390. package/dist/test/codec/reuseGuard.test.d.ts +1 -0
  391. package/dist/test/codec/reuseGuard.test.js +9 -0
  392. package/dist/test/codec/reuseGuard.test.js.map +1 -0
  393. package/dist/test/codec/roundtrip.d.ts +3 -0
  394. package/dist/test/codec/roundtrip.js +8 -0
  395. package/dist/test/codec/roundtrip.js.map +1 -0
  396. package/dist/test/codec/sender.test.d.ts +1 -0
  397. package/dist/test/codec/sender.test.js +18 -0
  398. package/dist/test/codec/sender.test.js.map +1 -0
  399. package/dist/test/codec/senderData.test.d.ts +1 -0
  400. package/dist/test/codec/senderData.test.js +12 -0
  401. package/dist/test/codec/senderData.test.js.map +1 -0
  402. package/dist/test/codec/senderDataAAD.test.d.ts +1 -0
  403. package/dist/test/codec/senderDataAAD.test.js +12 -0
  404. package/dist/test/codec/senderDataAAD.test.js.map +1 -0
  405. package/dist/test/codec/senderType.test.d.ts +1 -0
  406. package/dist/test/codec/senderType.test.js +18 -0
  407. package/dist/test/codec/senderType.test.js.map +1 -0
  408. package/dist/test/codec/transcriptHash.test.d.ts +1 -0
  409. package/dist/test/codec/transcriptHash.test.js +38 -0
  410. package/dist/test/codec/transcriptHash.test.js.map +1 -0
  411. package/dist/test/codec/treeHash.test.d.ts +1 -0
  412. package/dist/test/codec/treeHash.test.js +17 -0
  413. package/dist/test/codec/treeHash.test.js.map +1 -0
  414. package/dist/test/codec/updatePath.test.d.ts +1 -0
  415. package/dist/test/codec/updatePath.test.js +81 -0
  416. package/dist/test/codec/updatePath.test.js.map +1 -0
  417. package/dist/test/codec/updatePathNode.test.d.ts +1 -0
  418. package/dist/test/codec/updatePathNode.test.js +23 -0
  419. package/dist/test/codec/updatePathNode.test.js.map +1 -0
  420. package/dist/test/codec/varLengthEncoding.test.d.ts +1 -0
  421. package/dist/test/codec/varLengthEncoding.test.js +90 -0
  422. package/dist/test/codec/varLengthEncoding.test.js.map +1 -0
  423. package/dist/test/codec/welcome.test.d.ts +1 -0
  424. package/dist/test/codec/welcome.test.js +25 -0
  425. package/dist/test/codec/welcome.test.js.map +1 -0
  426. package/dist/test/codec/wireformat.test.d.ts +1 -0
  427. package/dist/test/codec/wireformat.test.js +21 -0
  428. package/dist/test/codec/wireformat.test.js.map +1 -0
  429. package/dist/test/crypto/aead.test.d.ts +1 -0
  430. package/dist/test/crypto/aead.test.js +44 -0
  431. package/dist/test/crypto/aead.test.js.map +1 -0
  432. package/dist/test/crypto/hpke.test.d.ts +1 -0
  433. package/dist/test/crypto/hpke.test.js +58 -0
  434. package/dist/test/crypto/hpke.test.js.map +1 -0
  435. package/dist/test/crypto/keyMatch.d.ts +7 -0
  436. package/dist/test/crypto/keyMatch.js +22 -0
  437. package/dist/test/crypto/keyMatch.js.map +1 -0
  438. package/dist/test/extensionsEqual.test.d.ts +1 -0
  439. package/dist/test/extensionsEqual.test.js +51 -0
  440. package/dist/test/extensionsEqual.test.js.map +1 -0
  441. package/dist/test/groupinfo.test.d.ts +1 -0
  442. package/dist/test/groupinfo.test.js +40 -0
  443. package/dist/test/groupinfo.test.js.map +1 -0
  444. package/dist/test/scenario/common.d.ts +8 -0
  445. package/dist/test/scenario/common.js +41 -0
  446. package/dist/test/scenario/common.js.map +1 -0
  447. package/dist/test/scenario/customExtensions.test.d.ts +1 -0
  448. package/dist/test/scenario/customExtensions.test.js +56 -0
  449. package/dist/test/scenario/customExtensions.test.js.map +1 -0
  450. package/dist/test/scenario/customProposal.test.d.ts +1 -0
  451. package/dist/test/scenario/customProposal.test.js +71 -0
  452. package/dist/test/scenario/customProposal.test.js.map +1 -0
  453. package/dist/test/scenario/epochOutOfOrder.test.d.ts +1 -0
  454. package/dist/test/scenario/epochOutOfOrder.test.js +162 -0
  455. package/dist/test/scenario/epochOutOfOrder.test.js.map +1 -0
  456. package/dist/test/scenario/externalAddProposal.test.d.ts +1 -0
  457. package/dist/test/scenario/externalAddProposal.test.js +69 -0
  458. package/dist/test/scenario/externalAddProposal.test.js.map +1 -0
  459. package/dist/test/scenario/externalJoin.test.d.ts +1 -0
  460. package/dist/test/scenario/externalJoin.test.js +51 -0
  461. package/dist/test/scenario/externalJoin.test.js.map +1 -0
  462. package/dist/test/scenario/externalJoinResync.test.d.ts +1 -0
  463. package/dist/test/scenario/externalJoinResync.test.js +59 -0
  464. package/dist/test/scenario/externalJoinResync.test.js.map +1 -0
  465. package/dist/test/scenario/externalProposal.test.d.ts +1 -0
  466. package/dist/test/scenario/externalProposal.test.js +69 -0
  467. package/dist/test/scenario/externalProposal.test.js.map +1 -0
  468. package/dist/test/scenario/externalPsk.test.d.ts +1 -0
  469. package/dist/test/scenario/externalPsk.test.js +73 -0
  470. package/dist/test/scenario/externalPsk.test.js.map +1 -0
  471. package/dist/test/scenario/externalPskJoin.test.d.ts +1 -0
  472. package/dist/test/scenario/externalPskJoin.test.js +51 -0
  473. package/dist/test/scenario/externalPskJoin.test.js.map +1 -0
  474. package/dist/test/scenario/generationOutOfOrder.test.d.ts +1 -0
  475. package/dist/test/scenario/generationOutOfOrder.test.js +111 -0
  476. package/dist/test/scenario/generationOutOfOrder.test.js.map +1 -0
  477. package/dist/test/scenario/grease.test.d.ts +1 -0
  478. package/dist/test/scenario/grease.test.js +44 -0
  479. package/dist/test/scenario/grease.test.js.map +1 -0
  480. package/dist/test/scenario/largeGroupFullLifecycle.test.d.ts +1 -0
  481. package/dist/test/scenario/largeGroupFullLifecycle.test.js +127 -0
  482. package/dist/test/scenario/largeGroupFullLifecycle.test.js.map +1 -0
  483. package/dist/test/scenario/leaveProposal.test.d.ts +1 -0
  484. package/dist/test/scenario/leaveProposal.test.js +77 -0
  485. package/dist/test/scenario/leaveProposal.test.js.map +1 -0
  486. package/dist/test/scenario/multipleJoinsAtOnce.test.d.ts +1 -0
  487. package/dist/test/scenario/multipleJoinsAtOnce.test.js +48 -0
  488. package/dist/test/scenario/multipleJoinsAtOnce.test.js.map +1 -0
  489. package/dist/test/scenario/oneToOneJoin.test.d.ts +1 -0
  490. package/dist/test/scenario/oneToOneJoin.test.js +98 -0
  491. package/dist/test/scenario/oneToOneJoin.test.js.map +1 -0
  492. package/dist/test/scenario/ratchetTreeExtension.test.d.ts +1 -0
  493. package/dist/test/scenario/ratchetTreeExtension.test.js +48 -0
  494. package/dist/test/scenario/ratchetTreeExtension.test.js.map +1 -0
  495. package/dist/test/scenario/reinit.test.d.ts +1 -0
  496. package/dist/test/scenario/reinit.test.js +57 -0
  497. package/dist/test/scenario/reinit.test.js.map +1 -0
  498. package/dist/test/scenario/rejectIncomingMessage.test.d.ts +1 -0
  499. package/dist/test/scenario/rejectIncomingMessage.test.js +67 -0
  500. package/dist/test/scenario/rejectIncomingMessage.test.js.map +1 -0
  501. package/dist/test/scenario/remove.test.d.ts +1 -0
  502. package/dist/test/scenario/remove.test.js +68 -0
  503. package/dist/test/scenario/remove.test.js.map +1 -0
  504. package/dist/test/scenario/requiredCapabilites.test.d.ts +1 -0
  505. package/dist/test/scenario/requiredCapabilites.test.js +65 -0
  506. package/dist/test/scenario/requiredCapabilites.test.js.map +1 -0
  507. package/dist/test/scenario/resumption.test.d.ts +1 -0
  508. package/dist/test/scenario/resumption.test.js +43 -0
  509. package/dist/test/scenario/resumption.test.js.map +1 -0
  510. package/dist/test/scenario/threePartyJoin.test.d.ts +1 -0
  511. package/dist/test/scenario/threePartyJoin.test.js +56 -0
  512. package/dist/test/scenario/threePartyJoin.test.js.map +1 -0
  513. package/dist/test/scenario/update.test.d.ts +1 -0
  514. package/dist/test/scenario/update.test.js +50 -0
  515. package/dist/test/scenario/update.test.js.map +1 -0
  516. package/dist/test/test-vectors/cryptoBasics.test.d.ts +1 -0
  517. package/dist/test/test-vectors/cryptoBasics.test.js +60 -0
  518. package/dist/test/test-vectors/cryptoBasics.test.js.map +1 -0
  519. package/dist/test/test-vectors/deserialization.test.d.ts +1 -0
  520. package/dist/test/test-vectors/deserialization.test.js +13 -0
  521. package/dist/test/test-vectors/deserialization.test.js.map +1 -0
  522. package/dist/test/test-vectors/keySchedule.test.d.ts +1 -0
  523. package/dist/test/test-vectors/keySchedule.test.js +48 -0
  524. package/dist/test/test-vectors/keySchedule.test.js.map +1 -0
  525. package/dist/test/test-vectors/messageProtection.test.d.ts +1 -0
  526. package/dist/test/test-vectors/messageProtection.test.js +215 -0
  527. package/dist/test/test-vectors/messageProtection.test.js.map +1 -0
  528. package/dist/test/test-vectors/messages.test.d.ts +1 -0
  529. package/dist/test/test-vectors/messages.test.js +136 -0
  530. package/dist/test/test-vectors/messages.test.js.map +1 -0
  531. package/dist/test/test-vectors/passiveClientScenarios.test.d.ts +1 -0
  532. package/dist/test/test-vectors/passiveClientScenarios.test.js +86 -0
  533. package/dist/test/test-vectors/passiveClientScenarios.test.js.map +1 -0
  534. package/dist/test/test-vectors/pskSecret.test.d.ts +1 -0
  535. package/dist/test/test-vectors/pskSecret.test.js +18 -0
  536. package/dist/test/test-vectors/pskSecret.test.js.map +1 -0
  537. package/dist/test/test-vectors/secretTree.test.d.ts +1 -0
  538. package/dist/test/test-vectors/secretTree.test.js +48 -0
  539. package/dist/test/test-vectors/secretTree.test.js.map +1 -0
  540. package/dist/test/test-vectors/transcriptHashes.test.d.ts +1 -0
  541. package/dist/test/test-vectors/transcriptHashes.test.js +26 -0
  542. package/dist/test/test-vectors/transcriptHashes.test.js.map +1 -0
  543. package/dist/test/test-vectors/treeOperations.test.d.ts +1 -0
  544. package/dist/test/test-vectors/treeOperations.test.js +45 -0
  545. package/dist/test/test-vectors/treeOperations.test.js.map +1 -0
  546. package/dist/test/test-vectors/treeValidation.test.d.ts +1 -0
  547. package/dist/test/test-vectors/treeValidation.test.js +36 -0
  548. package/dist/test/test-vectors/treeValidation.test.js.map +1 -0
  549. package/dist/test/test-vectors/treekem.test.d.ts +1 -0
  550. package/dist/test/test-vectors/treekem.test.js +100 -0
  551. package/dist/test/test-vectors/treekem.test.js.map +1 -0
  552. package/dist/test/test-vectors/treemath.test.d.ts +1 -0
  553. package/dist/test/test-vectors/treemath.test.js +55 -0
  554. package/dist/test/test-vectors/treemath.test.js.map +1 -0
  555. package/dist/test/test-vectors/welcome.test.d.ts +1 -0
  556. package/dist/test/test-vectors/welcome.test.js +40 -0
  557. package/dist/test/test-vectors/welcome.test.js.map +1 -0
  558. package/dist/test/validation/proposalValidation.test.d.ts +1 -0
  559. package/dist/test/validation/proposalValidation.test.js +231 -0
  560. package/dist/test/validation/proposalValidation.test.js.map +1 -0
  561. package/dist/test/validation/ratchetTreeValidation.test.d.ts +1 -0
  562. package/dist/test/validation/ratchetTreeValidation.test.js +51 -0
  563. package/dist/test/validation/ratchetTreeValidation.test.js.map +1 -0
  564. package/dist/test/validation/resumptionValidation.test.d.ts +1 -0
  565. package/dist/test/validation/resumptionValidation.test.js +79 -0
  566. package/dist/test/validation/resumptionValidation.test.js.map +1 -0
  567. package/dist/test_vectors/crypto-basics.json +303 -0
  568. package/dist/test_vectors/deserialization.json +58 -0
  569. package/dist/test_vectors/key-schedule.json +926 -0
  570. package/dist/test_vectors/message-protection.json +142 -0
  571. package/dist/test_vectors/messages.json +5702 -0
  572. package/dist/test_vectors/passive-client-handling-commit.json +2683 -0
  573. package/dist/test_vectors/passive-client-random.json +2657 -0
  574. package/dist/test_vectors/passive-client-welcome.json +814 -0
  575. package/dist/test_vectors/psk_secret.json +2382 -0
  576. package/dist/test_vectors/secret-tree.json +4846 -0
  577. package/dist/test_vectors/transcript-hashes.json +58 -0
  578. package/dist/test_vectors/tree-math.json +8156 -0
  579. package/dist/test_vectors/tree-operations.json +47 -0
  580. package/dist/test_vectors/tree-validation.json +6204 -0
  581. package/dist/test_vectors/treekem.json +14859 -0
  582. package/dist/test_vectors/welcome.json +51 -0
  583. package/package.json +108 -0
@@ -0,0 +1,74 @@
1
+ import { makePskIndex, createGroup, joinGroup } from "./clientState";
2
+ import { createCommit } from "./createCommit";
3
+ import { getCiphersuiteImpl, getCiphersuiteFromName } from "./crypto/ciphersuite";
4
+ import { UsageError } from "./mlsError";
5
+ export async function reinitGroup(state, groupId, version, cipherSuite, extensions, cs) {
6
+ const reinitProposal = {
7
+ proposalType: "reinit",
8
+ reinit: {
9
+ groupId,
10
+ version,
11
+ cipherSuite,
12
+ extensions,
13
+ },
14
+ };
15
+ return createCommit(state, makePskIndex(state, {}), false, [reinitProposal], cs);
16
+ }
17
+ export async function reinitCreateNewGroup(state, keyPackage, privateKeyPackage, memberKeyPackages, groupId, cipherSuite, extensions) {
18
+ const cs = await getCiphersuiteImpl(getCiphersuiteFromName(cipherSuite));
19
+ const newGroup = await createGroup(groupId, keyPackage, privateKeyPackage, extensions, cs);
20
+ const addProposals = memberKeyPackages.map((kp) => ({
21
+ proposalType: "add",
22
+ add: { keyPackage: kp },
23
+ }));
24
+ const psk = makeResumptionPsk(state, "reinit", cs);
25
+ const resumptionPsk = {
26
+ proposalType: "psk",
27
+ psk: {
28
+ preSharedKeyId: psk.id,
29
+ },
30
+ };
31
+ return createCommit(newGroup, makePskIndex(state, {}), false, [...addProposals, resumptionPsk], cs);
32
+ }
33
+ export function makeResumptionPsk(state, usage, cs) {
34
+ const secret = state.keySchedule.resumptionPsk;
35
+ const pskNonce = cs.rng.randomBytes(cs.kdf.size);
36
+ const psk = {
37
+ pskEpoch: state.groupContext.epoch,
38
+ pskGroupId: state.groupContext.groupId,
39
+ psktype: "resumption",
40
+ pskNonce,
41
+ usage,
42
+ };
43
+ return { id: psk, secret };
44
+ }
45
+ export async function branchGroup(state, keyPackage, privateKeyPackage, memberKeyPackages, newGroupId, cs) {
46
+ const resumptionPsk = makeResumptionPsk(state, "branch", cs);
47
+ const pskSearch = makePskIndex(state, {});
48
+ const newGroup = await createGroup(newGroupId, keyPackage, privateKeyPackage, state.groupContext.extensions, cs);
49
+ const addMemberProposals = memberKeyPackages.map((kp) => ({
50
+ proposalType: "add",
51
+ add: {
52
+ keyPackage: kp,
53
+ },
54
+ }));
55
+ const branchPskProposal = {
56
+ proposalType: "psk",
57
+ psk: {
58
+ preSharedKeyId: resumptionPsk.id,
59
+ },
60
+ };
61
+ return createCommit(newGroup, pskSearch, false, [...addMemberProposals, branchPskProposal], cs);
62
+ }
63
+ export async function joinGroupFromBranch(oldState, welcome, keyPackage, privateKeyPackage, ratchetTree, cs) {
64
+ const pskSearch = makePskIndex(oldState, {});
65
+ return await joinGroup(welcome, keyPackage, privateKeyPackage, pskSearch, cs, ratchetTree, oldState);
66
+ }
67
+ export async function joinGroupFromReinit(suspendedState, welcome, keyPackage, privateKeyPackage, ratchetTree) {
68
+ const pskSearch = makePskIndex(suspendedState, {});
69
+ if (suspendedState.groupActiveState.kind !== "suspendedPendingReinit")
70
+ throw new UsageError("Cannot reinit because no init proposal found in last commit");
71
+ const cs = await getCiphersuiteImpl(getCiphersuiteFromName(suspendedState.groupActiveState.reinit.cipherSuite));
72
+ return await joinGroup(welcome, keyPackage, privateKeyPackage, pskSearch, cs, ratchetTree, suspendedState);
73
+ }
74
+ //# sourceMappingURL=resumption.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resumption.js","sourceRoot":"","sources":["../../src/resumption.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACjF,OAAO,EAAsB,YAAY,EAAE,MAAM,gBAAgB,CAAA;AACjE,OAAO,EAAoC,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAGnH,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAOvC,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,KAAkB,EAClB,OAAmB,EACnB,OAA4B,EAC5B,WAA4B,EAC5B,UAAuB,EACvB,EAAmB;IAEnB,MAAM,cAAc,GAAa;QAC/B,YAAY,EAAE,QAAQ;Q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mBAAmB,CACvC,QAAqB,EACrB,OAAgB,EAChB,UAAsB,EACtB,iBAAoC,EACpC,WAAoC,EACpC,EAAmB;IAEnB,MAAM,SAAS,GAAG,YAAY,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IAE5C,OAAO,MAAM,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,SAAS,EAAE,EAAE,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAA;AACtG,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,cAA2B,EAC3B,OAAgB,EAChB,UAAsB,EACtB,iBAAoC,EACpC,WAAoC;IAEpC,MAAM,SAAS,GAAG,YAAY,CAAC,cAAc,EAAE,EAAE,CAAC,CAAA;IAClD,IAAI,cAAc,CAAC,gBAAgB,CAAC,IAAI,KAAK,wBAAwB;QACnE,MAAM,IAAI,UAAU,CAAC,6DAA6D,CAAC,CAAA;IAErF,MAAM,EAAE,GAAG,MAAM,kBAAkB,CAAC,sBAAsB,CAAC,cAAc,CAAC,gBAAgB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAA;IAE/G,OAAO,MAAM,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,SAAS,EAAE,EAAE,EAAE,WAAW,EAAE,cAAc,CAAC,CAAA;AAC5G,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { ContentTypeName } from "./contentType";
2
+ import { CiphersuiteImpl } from "./crypto/ciphersuite";
3
+ import { Kdf } from "./crypto/kdf";
4
+ import { KeyRetentionConfig } from "./keyRetentionConfig";
5
+ import { ReuseGuard, SenderData } from "./sender";
6
+ export type GenerationSecret = {
7
+ secret: Uint8Array;
8
+ generation: number;
9
+ unusedGenerations: Record<number, Uint8Array>;
10
+ };
11
+ export type SecretTreeNode = {
12
+ handshake: GenerationSecret;
13
+ application: GenerationSecret;
14
+ };
15
+ export type SecretTree = SecretTreeNode[];
16
+ export type ConsumeRatchetResult = {
17
+ nonce: Uint8Array;
18
+ reuseGuard: ReuseGuard;
19
+ key: Uint8Array;
20
+ generation: number;
21
+ newTree: SecretTree;
22
+ };
23
+ export declare function createSecretTree(leafWidth: number, encryptionSecret: Uint8Array, kdf: Kdf): Promise<SecretTree>;
24
+ export declare function deriveNonce(secret: Uint8Array, generation: number, cs: CiphersuiteImpl): Promise<Uint8Array>;
25
+ export declare function deriveKey(secret: Uint8Array, generation: number, cs: CiphersuiteImpl): Promise<Uint8Array>;
26
+ export declare function ratchetUntil(current: GenerationSecret, desiredGen: number, config: KeyRetentionConfig, kdf: Kdf): Promise<GenerationSecret>;
27
+ export declare function derivePrivateMessageNonce(secret: Uint8Array, generation: number, reuseGuard: Uint8Array, cs: CiphersuiteImpl): Promise<Uint8Array>;
28
+ export declare function ratchetToGeneration(tree: SecretTree, senderData: SenderData, contentType: ContentTypeName, config: KeyRetentionConfig, cs: CiphersuiteImpl): Promise<ConsumeRatchetResult>;
29
+ export declare function consumeRatchet(tree: SecretTree, index: number, contentType: ContentTypeName, cs: CiphersuiteImpl): Promise<ConsumeRatchetResult>;
@@ -0,0 +1,137 @@
1
+ import { expandWithLabel, deriveTreeSecret } from "./crypto/kdf";
2
+ import { InternalError, ValidationError } from "./mlsError";
3
+ import { nodeWidth, root, right, isLeaf, left, leafToNodeIndex } from "./treemath";
4
+ import { updateArray } from "./util/array";
5
+ import { repeatAsync } from "./util/repeat";
6
+ function scaffoldSecretTree(leafWidth, encryptionSecret, kdf) {
7
+ const tree = new Array(nodeWidth(leafWidth));
8
+ const rootIndex = root(leafWidth);
9
+ const parentInhabited = updateArray(tree, rootIndex, encryptionSecret);
10
+ return deriveChildren(parentInhabited, rootIndex, kdf);
11
+ }
12
+ export async function createSecretTree(leafWidth, encryptionSecret, kdf) {
13
+ const tree = await scaffoldSecretTree(leafWidth, encryptionSecret, kdf);
14
+ return await Promise.all(tree.map(async (secret) => {
15
+ const application = await createRatchetRoot(secret, "application", kdf);
16
+ const handshake = await createRatchetRoot(secret, "handshake", kdf);
17
+ return { handshake, application };
18
+ }));
19
+ }
20
+ async function deriveChildren(tree, nodeIndex, kdf) {
21
+ if (isLeaf(nodeIndex))
22
+ return tree;
23
+ const l = left(nodeIndex);
24
+ const r = right(nodeIndex);
25
+ const parentSecret = tree[nodeIndex];
26
+ if (parentSecret === undefined)
27
+ throw new InternalError("Bad node index for secret tree");
28
+ const leftSecret = await expandWithLabel(parentSecret, "tree", new TextEncoder().encode("left"), kdf.size, kdf);
29
+ const rightSecret = await expandWithLabel(parentSecret, "tree", new TextEncoder().encode("right"), kdf.size, kdf);
30
+ const currentTree = updateArray(updateArray(tree, l, leftSecret), r, rightSecret);
31
+ return deriveChildren(await deriveChildren(currentTree, l, kdf), r, kdf);
32
+ }
33
+ export async function deriveNonce(secret, generation, cs) {
34
+ return await deriveTreeSecret(secret, "nonce", generation, cs.hpke.nonceLength, cs.kdf);
35
+ }
36
+ export async function deriveKey(secret, generation, cs) {
37
+ return await deriveTreeSecret(secret, "key", generation, cs.hpke.keyLength, cs.kdf);
38
+ }
39
+ export async function ratchetUntil(current, desiredGen, config, kdf) {
40
+ const generationDifference = desiredGen - current.generation;
41
+ if (generationDifference > config.maximumForwardRatchetSteps)
42
+ throw new ValidationError("Desired generation too far in the future");
43
+ return await repeatAsync(async (s) => {
44
+ const nextSecret = await deriveTreeSecret(s.secret, "secret", s.generation, kdf.size, kdf);
45
+ return {
46
+ secret: nextSecret,
47
+ generation: s.generation + 1,
48
+ unusedGenerations: newFunction(s, config.retainKeysForGenerations),
49
+ };
50
+ }, current, generationDifference);
51
+ }
52
+ function newFunction(s, retainGenerationsMax) {
53
+ const withNew = { ...s.unusedGenerations, [s.generation]: s.secret };
54
+ const generations = Object.keys(withNew);
55
+ const result = generations.length >= retainGenerationsMax ? removeOldGenerations(withNew, retainGenerationsMax) : withNew;
56
+ return result;
57
+ }
58
+ function removeOldGenerations(historicalReceiverData, max) {
59
+ const sortedGenerations = Object.keys(historicalReceiverData)
60
+ .map(Number)
61
+ .sort((a, b) => (a < b ? -1 : 1));
62
+ return Object.fromEntries(sortedGenerations.slice(-max).map((generation) => [generation, historicalReceiverData[generation]]));
63
+ }
64
+ export async function derivePrivateMessageNonce(secret, generation, reuseGuard, cs) {
65
+ const nonce = await deriveNonce(secret, generation, cs);
66
+ if (nonce.length >= 4 && reuseGuard.length >= 4) {
67
+ for (let i = 0; i < 4; i++) {
68
+ nonce[i] ^= reuseGuard[i];
69
+ }
70
+ }
71
+ else
72
+ throw new ValidationError("Reuse guard or nonce incorrect length");
73
+ return nonce;
74
+ }
75
+ export async function ratchetToGeneration(tree, senderData, contentType, config, cs) {
76
+ const index = leafToNodeIndex(senderData.leafIndex);
77
+ const node = tree[index];
78
+ if (node === undefined)
79
+ throw new InternalError("Bad node index for secret tree");
80
+ const ratchet = ratchetForContentType(node, contentType);
81
+ if (ratchet.generation > senderData.generation) {
82
+ const desired = ratchet.unusedGenerations[senderData.generation];
83
+ if (desired !== undefined) {
84
+ const { [senderData.generation]: _, ...removedDesiredGen } = ratchet.unusedGenerations;
85
+ const ratchetState = { ...ratchet, unusedGenerations: removedDesiredGen };
86
+ return await createRatchetResultWithSecret(node, index, desired, senderData.generation, senderData.reuseGuard, tree, contentType, cs, ratchetState);
87
+ }
88
+ throw new ValidationError("Desired gen in the past");
89
+ }
90
+ const currentSecret = await ratchetUntil(ratchetForContentType(node, contentType), senderData.generation, config, cs.kdf);
91
+ return createRatchetResult(node, index, currentSecret, senderData.reuseGuard, tree, contentType, cs);
92
+ }
93
+ export async function consumeRatchet(tree, index, contentType, cs) {
94
+ const node = tree[index];
95
+ if (node === undefined)
96
+ throw new InternalError("Bad node index for secret tree");
97
+ const currentSecret = ratchetForContentType(node, contentType);
98
+ const reuseGuard = cs.rng.randomBytes(4);
99
+ return createRatchetResult(node, index, currentSecret, reuseGuard, tree, contentType, cs);
100
+ }
101
+ async function createRatchetResult(node, index, currentSecret, reuseGuard, tree, contentType, cs) {
102
+ const nextSecret = await deriveTreeSecret(currentSecret.secret, "secret", currentSecret.generation, cs.kdf.size, cs.kdf);
103
+ const ratchetState = { ...currentSecret, secret: nextSecret, generation: currentSecret.generation + 1 };
104
+ return await createRatchetResultWithSecret(node, index, currentSecret.secret, currentSecret.generation, reuseGuard, tree, contentType, cs, ratchetState);
105
+ }
106
+ async function createRatchetResultWithSecret(node, index, secret, generation, reuseGuard, tree, contentType, cs, ratchetState) {
107
+ const { nonce, key } = await createKeyAndNonce(secret, generation, reuseGuard, cs);
108
+ const newNode = contentType === "application" ? { ...node, application: ratchetState } : { ...node, handshake: ratchetState };
109
+ const newTree = updateArray(tree, index, newNode);
110
+ return {
111
+ generation: generation,
112
+ reuseGuard,
113
+ nonce,
114
+ key,
115
+ newTree,
116
+ };
117
+ }
118
+ async function createKeyAndNonce(secret, generation, reuseGuard, cs) {
119
+ const key = await deriveKey(secret, generation, cs);
120
+ const nonce = await derivePrivateMessageNonce(secret, generation, reuseGuard, cs);
121
+ return { nonce, key };
122
+ }
123
+ function ratchetForContentType(node, contentType) {
124
+ switch (contentType) {
125
+ case "application":
126
+ return node.application;
127
+ case "proposal":
128
+ return node.handshake;
129
+ case "commit":
130
+ return node.handshake;
131
+ }
132
+ }
133
+ async function createRatchetRoot(node, label, kdf) {
134
+ const secret = await expandWithLabel(node, label, new Uint8Array(), kdf.size, kdf);
135
+ return { secret: secret, generation: 0, unusedGenerations: {} };
136
+ }
137
+ //# sourceMappingURL=secretTree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secretTree.js","sourceRoot":"","sources":["../../src/secretTree.ts"],"names":[],"mappings":"AAEA,OAAO,EAAO,eAAe,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAErE,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE3D,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAClF,OAAO,EAAE,WA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KAAK,EAAE,OAAO,CAAC,CAAA;IAEjD,OAAO;QACL,UAAU,EAAE,UAAU;QACtB,UAAU;QACV,KAAK;QACL,GAAG;QACH,OAAO;KACR,CAAA;AACH,CAAC;AAED,KAAK,UAAU,iBAAiB,CAAC,MAAkB,EAAE,UAAkB,EAAE,UAAsB,EAAE,EAAmB;IAClH,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,CAAC,CAAA;IACnD,MAAM,KAAK,GAAG,MAAM,yBAAyB,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,CAAC,CAAA;IACjF,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAA;AACvB,CAAC;AAED,SAAS,qBAAqB,CAAC,IAAoB,EAAE,WAA4B;IAC/E,QAAQ,WAAW,EAAE,CAAC;QACpB,KAAK,aAAa;YAChB,OAAO,IAAI,CAAC,WAAW,CAAA;QACzB,KAAK,UAAU;YACb,OAAO,IAAI,CAAC,SAAS,CAAA;QACvB,KAAK,QAAQ;YACX,OAAO,IAAI,CAAC,SAAS,CAAA;IACzB,CAAC;AACH,CAAC;AAED,KAAK,UAAU,iBAAiB,CAAC,IAAgB,EAAE,KAAa,EAAE,GAAQ;IACxE,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,UAAU,EAAE,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;IAClF,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,EAAE,iBAAiB,EAAE,EAAE,EAAE,CAAA;AACjE,CAAC"}
@@ -0,0 +1,56 @@
1
+ import { Decoder } from "./codec/tlsDecoder";
2
+ import { Encoder } from "./codec/tlsEncoder";
3
+ import { ContentTypeName } from "./contentType";
4
+ import { CiphersuiteImpl } from "./crypto/ciphersuite";
5
+ declare const senderTypes: {
6
+ readonly member: 1;
7
+ readonly external: 2;
8
+ readonly new_member_proposal: 3;
9
+ readonly new_member_commit: 4;
10
+ };
11
+ export type SenderTypeName = keyof typeof senderTypes;
12
+ export type SenderTypeValue = (typeof senderTypes)[SenderTypeName];
13
+ export declare const encodeSenderType: Encoder<SenderTypeName>;
14
+ export declare const decodeSenderType: Decoder<SenderTypeName>;
15
+ export type Sender = SenderMember | SenderNonMember;
16
+ export type SenderMember = {
17
+ senderType: "member";
18
+ leafIndex: number;
19
+ };
20
+ export type SenderNonMember = SenderExternal | SenderNewMemberProposal | SenderNewMemberCommit;
21
+ export type SenderExternal = {
22
+ senderType: "external";
23
+ senderIndex: number;
24
+ };
25
+ export type SenderNewMemberProposal = {
26
+ senderType: "new_member_proposal";
27
+ };
28
+ export type SenderNewMemberCommit = {
29
+ senderType: "new_member_commit";
30
+ };
31
+ export declare const encodeSender: Encoder<Sender>;
32
+ export declare const decodeSender: Decoder<Sender>;
33
+ export declare function getSenderLeafNodeIndex(sender: Sender): number | undefined;
34
+ export type SenderData = {
35
+ leafIndex: number;
36
+ generation: number;
37
+ reuseGuard: ReuseGuard;
38
+ };
39
+ export type ReuseGuard = Uint8Array & {
40
+ length: 4;
41
+ };
42
+ export declare const encodeReuseGuard: Encoder<ReuseGuard>;
43
+ export declare const decodeReuseGuard: Decoder<ReuseGuard>;
44
+ export declare const encodeSenderData: Encoder<SenderData>;
45
+ export declare const decodeSenderData: Decoder<SenderData>;
46
+ export type SenderDataAAD = {
47
+ groupId: Uint8Array;
48
+ epoch: bigint;
49
+ contentType: ContentTypeName;
50
+ };
51
+ export declare const encodeSenderDataAAD: Encoder<SenderDataAAD>;
52
+ export declare const decodeSenderDataAAD: Decoder<SenderDataAAD>;
53
+ export declare function sampleCiphertext(cs: CiphersuiteImpl, ciphertext: Uint8Array): Uint8Array;
54
+ export declare function expandSenderDataKey(cs: CiphersuiteImpl, senderDataSecret: Uint8Array, ciphertext: Uint8Array): Promise<Uint8Array>;
55
+ export declare function expandSenderDataNonce(cs: CiphersuiteImpl, senderDataSecret: Uint8Array, ciphertext: Uint8Array): Promise<Uint8Array>;
56
+ export {};
@@ -0,0 +1,81 @@
1
+ import { decodeUint32, decodeUint64, decodeUint8, encodeUint32, encodeUint64, encodeUint8 } from "./codec/number";
2
+ import { flatMapDecoder, mapDecoder, mapDecoderOption, mapDecoders } from "./codec/tlsDecoder";
3
+ import { contramapEncoder, contramapEncoders } from "./codec/tlsEncoder";
4
+ import { decodeVarLenData, encodeVarLenData } from "./codec/variableLength";
5
+ import { decodeContentType, encodeContentType } from "./contentType";
6
+ import { expandWithLabel } from "./crypto/kdf";
7
+ import { enumNumberToKey } from "./util/enumHelpers";
8
+ const senderTypes = {
9
+ member: 1,
10
+ external: 2,
11
+ new_member_proposal: 3,
12
+ new_member_commit: 4,
13
+ };
14
+ export const encodeSenderType = contramapEncoder(encodeUint8, (t) => senderTypes[t]);
15
+ export const decodeSenderType = mapDecoderOption(decodeUint8, enumNumberToKey(senderTypes));
16
+ export const encodeSender = (s) => {
17
+ switch (s.senderType) {
18
+ case "member":
19
+ return contramapEncoders([encodeSenderType, encodeUint32], (s) => [s.senderType, s.leafIndex])(s);
20
+ case "external":
21
+ return contramapEncoders([encodeSenderType, encodeUint32], (s) => [s.senderType, s.senderIndex])(s);
22
+ case "new_member_proposal":
23
+ case "new_member_commit":
24
+ return encodeSenderType(s.senderType);
25
+ }
26
+ };
27
+ export const decodeSender = flatMapDecoder(decodeSenderType, (senderType) => {
28
+ switch (senderType) {
29
+ case "member":
30
+ return mapDecoder(decodeUint32, (leafIndex) => ({
31
+ senderType,
32
+ leafIndex,
33
+ }));
34
+ case "external":
35
+ return mapDecoder(decodeUint32, (senderIndex) => ({
36
+ senderType,
37
+ senderIndex,
38
+ }));
39
+ case "new_member_proposal":
40
+ return mapDecoder(() => [undefined, 0], () => ({
41
+ senderType,
42
+ }));
43
+ case "new_member_commit":
44
+ return mapDecoder(() => [undefined, 0], () => ({
45
+ senderType,
46
+ }));
47
+ }
48
+ });
49
+ export function getSenderLeafNodeIndex(sender) {
50
+ return sender.senderType === "member" ? sender.leafIndex : undefined;
51
+ }
52
+ export const encodeReuseGuard = (g) => g;
53
+ export const decodeReuseGuard = (b, offset) => {
54
+ return [b.subarray(offset, offset + 4), 4];
55
+ };
56
+ export const encodeSenderData = contramapEncoders([encodeUint32, encodeUint32, encodeReuseGuard], (s) => [s.leafIndex, s.generation, s.reuseGuard]);
57
+ export const decodeSenderData = mapDecoders([decodeUint32, decodeUint32, decodeReuseGuard], (leafIndex, generation, reuseGuard) => ({
58
+ leafIndex,
59
+ generation,
60
+ reuseGuard,
61
+ }));
62
+ export const encodeSenderDataAAD = contramapEncoders([encodeVarLenData, encodeUint64, encodeContentType], (aad) => [aad.groupId, aad.epoch, aad.contentType]);
63
+ export const decodeSenderDataAAD = mapDecoders([decodeVarLenData, decodeUint64, decodeContentType], (groupId, epoch, contentType) => ({
64
+ groupId,
65
+ epoch,
66
+ contentType,
67
+ }));
68
+ export function sampleCiphertext(cs, ciphertext) {
69
+ return ciphertext.length < cs.kdf.size ? ciphertext : ciphertext.slice(0, cs.kdf.size);
70
+ }
71
+ export async function expandSenderDataKey(cs, senderDataSecret, ciphertext) {
72
+ const ciphertextSample = sampleCiphertext(cs, ciphertext);
73
+ const keyLength = cs.hpke.keyLength;
74
+ return await expandWithLabel(senderDataSecret, "key", ciphertextSample, keyLength, cs.kdf);
75
+ }
76
+ export async function expandSenderDataNonce(cs, senderDataSecret, ciphertext) {
77
+ const ciphertextSample = sampleCiphertext(cs, ciphertext);
78
+ const keyLength = cs.hpke.nonceLength;
79
+ return await expandWithLabel(senderDataSecret, "nonce", ciphertextSample, keyLength, cs.kdf);
80
+ }
81
+ //# sourceMappingURL=sender.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sender.js","sourceRoot":"","sources":["../../src/sender.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAg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,CAAC,IAAI,CAAC,CAAA;AACxF,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,EAAmB,EACnB,gBAA4B,EAC5B,UAAsB;IAEtB,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,EAAE,EAAE,UAAU,CAAC,CAAA;IACzD,MAAM,SAAS,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAA;IAEnC,OAAO,MAAM,eAAe,CAAC,gBAAgB,EAAE,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,EAAE,CAAC,GAAG,CAAC,CAAA;AAC5F,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,EAAmB,EACnB,gBAA4B,EAC5B,UAAsB;IAEtB,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,EAAE,EAAE,UAAU,CAAC,CAAA;IACzD,MAAM,SAAS,GAAG,EAAE,CAAC,IAAI,CAAC,WAAW,CAAA;IAErC,OAAO,MAAM,eAAe,CAAC,gBAAgB,EAAE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,EAAE,CAAC,GAAG,CAAC,CAAA;AAC9F,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { Decoder } from "./codec/tlsDecoder";
2
+ import { Encoder } from "./codec/tlsEncoder";
3
+ import { Hash } from "./crypto/hash";
4
+ import { FramedContentCommit } from "./framedContent";
5
+ import { WireformatName } from "./wireformat";
6
+ export type ConfirmedTranscriptHashInput = {
7
+ wireformat: WireformatName;
8
+ content: FramedContentCommit;
9
+ signature: Uint8Array;
10
+ };
11
+ export declare const encodeConfirmedTranscriptHashInput: Encoder<ConfirmedTranscriptHashInput>;
12
+ export declare const decodeConfirmedTranscriptHashInput: Decoder<ConfirmedTranscriptHashInput>;
13
+ export declare function createConfirmedHash(interimTranscriptHash: Uint8Array, input: ConfirmedTranscriptHashInput, hash: Hash): Promise<Uint8Array>;
14
+ export declare function createInterimHash(confirmedHash: Uint8Array, confirmationTag: Uint8Array, hash: Hash): Promise<Uint8Array>;
@@ -0,0 +1,23 @@
1
+ import { mapDecodersOption } from "./codec/tlsDecoder";
2
+ import { contramapEncoders } from "./codec/tlsEncoder";
3
+ import { decodeVarLenData, encodeVarLenData } from "./codec/variableLength";
4
+ import { decodeFramedContent, encodeFramedContent } from "./framedContent";
5
+ import { decodeWireformat, encodeWireformat } from "./wireformat";
6
+ export const encodeConfirmedTranscriptHashInput = contramapEncoders([encodeWireformat, encodeFramedContent, encodeVarLenData], (input) => [input.wireformat, input.content, input.signature]);
7
+ export const decodeConfirmedTranscriptHashInput = mapDecodersOption([decodeWireformat, decodeFramedContent, decodeVarLenData], (wireformat, content, signature) => {
8
+ if (content.contentType === "commit")
9
+ return {
10
+ wireformat,
11
+ content,
12
+ signature,
13
+ };
14
+ else
15
+ return undefined;
16
+ });
17
+ export function createConfirmedHash(interimTranscriptHash, input, hash) {
18
+ return hash.digest(new Uint8Array([...interimTranscriptHash, ...encodeConfirmedTranscriptHashInput(input)]));
19
+ }
20
+ export function createInterimHash(confirmedHash, confirmationTag, hash) {
21
+ return hash.digest(new Uint8Array([...confirmedHash, ...encodeVarLenData(confirmationTag)]));
22
+ }
23
+ //# sourceMappingURL=transcriptHash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcriptHash.js","sourceRoot":"","sources":["../../src/transcriptHash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,iBAAiB,EAAW,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAE3E,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAuB,MAAM,iBAAiB,CAAA;AAC/F,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAkB,MAAM,cAAc,CAAA;AAQjF,MAAM,CAAC,MAAM,kCAAkC,GAA0C,iBAAiB,CACxG,CAAC,gBAAgB,EAAE,mBAAmB,EAAE,gBAAgB,CAAC,EACzD,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAU,CACvE,CAAA;AAED,MAAM,CAAC,MAAM,kCAAkC,GAA0C,iBAAiB,CACxG,CAAC,gBAAgB,EAAE,mBAAmB,EAAE,gBAAgB,CAAC,EACzD,CAAC,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE;IACjC,IAAI,OAAO,CAAC,WAAW,KAAK,QAAQ;QAClC,OAAO;YACL,UAAU;YACV,OAAO;YACP,SAAS;SACV,CAAA;;QACE,OAAO,SAAS,CAAA;AACvB,CAAC,CACF,CAAA;AAED,MAAM,UAAU,mBAAmB,CACjC,qBAAiC,EACjC,KAAmC,EACnC,IAAU;IAEV,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,CAAC,GAAG,qBAAqB,EAAE,GAAG,kCAAkC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AAC9G,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,aAAyB,EACzB,eAA2B,EAC3B,IAAU;IAEV,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,CAAC,GAAG,aAAa,EAAE,GAAG,gBAAgB,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAA;AAC9F,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { Decoder } from "./codec/tlsDecoder";
2
+ import { Encoder } from "./codec/tlsEncoder";
3
+ import { Hash } from "./crypto/hash";
4
+ import { LeafNode } from "./leafNode";
5
+ import { ParentNode } from "./parentNode";
6
+ import { RatchetTree } from "./ratchetTree";
7
+ export type TreeHashInput = LeafNodeHashInput | ParentNodeHashInput;
8
+ type LeafNodeHashInput = {
9
+ nodeType: "leaf";
10
+ leafIndex: number;
11
+ leafNode: LeafNode | undefined;
12
+ };
13
+ type ParentNodeHashInput = {
14
+ nodeType: "parent";
15
+ parentNode: ParentNode | undefined;
16
+ leftHash: Uint8Array;
17
+ rightHash: Uint8Array;
18
+ };
19
+ export declare const encodeLeafNodeHashInput: Encoder<LeafNodeHashInput>;
20
+ export declare const decodeLeafNodeHashInput: Decoder<LeafNodeHashInput>;
21
+ export declare const encodeParentNodeHashInput: Encoder<ParentNodeHashInput>;
22
+ export declare const decodeParentNodeHashInput: Decoder<ParentNodeHashInput>;
23
+ export declare const encodeTreeHashInput: Encoder<TreeHashInput>;
24
+ export declare const decodeTreeHashInput: Decoder<TreeHashInput>;
25
+ export declare function treeHashRoot(tree: RatchetTree, h: Hash): Promise<Uint8Array>;
26
+ export declare function treeHash(tree: RatchetTree, subtreeIndex: number, h: Hash): Promise<Uint8Array>;
27
+ export {};
@@ -0,0 +1,70 @@
1
+ import { encodeUint32, decodeUint32 } from "./codec/number";
2
+ import { encodeOptional, decodeOptional } from "./codec/optional";
3
+ import { mapDecoders, flatMapDecoder } from "./codec/tlsDecoder";
4
+ import { contramapEncoders } from "./codec/tlsEncoder";
5
+ import { encodeVarLenData, decodeVarLenData } from "./codec/variableLength";
6
+ import { encodeLeafNode, decodeLeafNode } from "./leafNode";
7
+ import { InternalError } from "./mlsError";
8
+ import { encodeNodeType, decodeNodeType } from "./nodeType";
9
+ import { encodeParentNode, decodeParentNode } from "./parentNode";
10
+ import { rootFromNodeWidth, isLeaf, nodeToLeafIndex, left, right } from "./treemath";
11
+ export const encodeLeafNodeHashInput = contramapEncoders([encodeNodeType, encodeUint32, encodeOptional(encodeLeafNode)], (input) => [input.nodeType, input.leafIndex, input.leafNode]);
12
+ export const decodeLeafNodeHashInput = mapDecoders([decodeUint32, decodeOptional(decodeLeafNode)], (leafIndex, leafNode) => ({
13
+ nodeType: "leaf",
14
+ leafIndex,
15
+ leafNode,
16
+ }));
17
+ export const encodeParentNodeHashInput = contramapEncoders([encodeNodeType, encodeOptional(encodeParentNode), encodeVarLenData, encodeVarLenData], (input) => [input.nodeType, input.parentNode, input.leftHash, input.rightHash]);
18
+ export const decodeParentNodeHashInput = mapDecoders([decodeOptional(decodeParentNode), decodeVarLenData, decodeVarLenData], (parentNode, leftHash, rightHash) => ({
19
+ nodeType: "parent",
20
+ parentNode,
21
+ leftHash,
22
+ rightHash,
23
+ }));
24
+ export const encodeTreeHashInput = (input) => {
25
+ switch (input.nodeType) {
26
+ case "leaf":
27
+ return encodeLeafNodeHashInput(input);
28
+ case "parent":
29
+ return encodeParentNodeHashInput(input);
30
+ }
31
+ };
32
+ export const decodeTreeHashInput = flatMapDecoder(decodeNodeType, (nodeType) => {
33
+ switch (nodeType) {
34
+ case "leaf":
35
+ return decodeLeafNodeHashInput;
36
+ case "parent":
37
+ return decodeParentNodeHashInput;
38
+ }
39
+ });
40
+ export async function treeHashRoot(tree, h) {
41
+ return treeHash(tree, rootFromNodeWidth(tree.length), h);
42
+ }
43
+ export async function treeHash(tree, subtreeIndex, h) {
44
+ if (isLeaf(subtreeIndex)) {
45
+ const leafNode = tree[subtreeIndex];
46
+ if (leafNode?.nodeType === "parent")
47
+ throw new InternalError("Somehow found parent node in leaf position");
48
+ const input = encodeLeafNodeHashInput({
49
+ nodeType: "leaf",
50
+ leafIndex: nodeToLeafIndex(subtreeIndex),
51
+ leafNode: leafNode?.leaf,
52
+ });
53
+ return await h.digest(input);
54
+ }
55
+ else {
56
+ const parentNode = tree[subtreeIndex];
57
+ if (parentNode?.nodeType === "leaf")
58
+ throw new InternalError("Somehow found leaf node in parent position");
59
+ const leftHash = await treeHash(tree, left(subtreeIndex), h);
60
+ const rightHash = await treeHash(tree, right(subtreeIndex), h);
61
+ const input = {
62
+ nodeType: "parent",
63
+ parentNode: parentNode?.parent,
64
+ leftHash: leftHash,
65
+ rightHash: rightHash,
66
+ };
67
+ return await h.digest(encodeParentNodeHashInput(input));
68
+ }
69
+ }
70
+ //# sourceMappingURL=treeHash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"treeHash.js","sourceRoot":"","sources":["../../src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AAM,CAAC,YAAY,CAAC,EAAE,CAAC;QACzB,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,CAAA;QACnC,IAAI,QAAQ,EAAE,QAAQ,KAAK,QAAQ;YAAE,MAAM,IAAI,aAAa,CAAC,4CAA4C,CAAC,CAAA;QAC1G,MAAM,KAAK,GAAG,uBAAuB,CAAC;YACpC,QAAQ,EAAE,MAAM;YAChB,SAAS,EAAE,eAAe,CAAC,YAAY,CAAC;YACxC,QAAQ,EAAE,QAAQ,EAAE,IAAI;SACzB,CAAC,CAAA;QACF,OAAO,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAC9B,CAAC;SAAM,CAAC;QACN,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,CAAA;QACrC,IAAI,UAAU,EAAE,QAAQ,KAAK,MAAM;YAAE,MAAM,IAAI,aAAa,CAAC,4CAA4C,CAAC,CAAA;QAC1G,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAA;QAC5D,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAA;QAC9D,MAAM,KAAK,GAAG;YACZ,QAAQ,EAAE,QAAQ;YAClB,UAAU,EAAE,UAAU,EAAE,MAAM;YAC9B,QAAQ,EAAE,QAAQ;YAClB,SAAS,EAAE,SAAS;SACZ,CAAA;QAEV,OAAO,MAAM,CAAC,CAAC,MAAM,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAA;IACzD,CAAC;AACH,CAAC"}
@@ -0,0 +1,14 @@
1
+ export declare function isLeaf(nodeIndex: number): boolean;
2
+ export declare function leafToNodeIndex(leafIndex: number): number;
3
+ export declare function nodeToLeafIndex(nodeIndex: number): number;
4
+ export declare function leafWidth(nodeWidth: number): number;
5
+ export declare function nodeWidth(leafWidth: number): number;
6
+ export declare function rootFromNodeWidth(nodeWidth: number): number;
7
+ export declare function root(leafWidth: number): number;
8
+ export declare function left(nodeIndex: number): number;
9
+ export declare function right(nodeIndex: number): number;
10
+ export declare function parent(nodeIndex: number, leafWidth: number): number;
11
+ export declare function sibling(x: number, n: number): number;
12
+ export declare function directPath(nodeIndex: number, leafWidth: number): number[];
13
+ export declare function copath(nodeIndex: number, leafWidth: number): number[];
14
+ export declare function isAncestor(childNodeIndex: number, ancestor: number, nodeWidth: number): boolean;