@opentdf/sdk 0.1.0-beta.1701

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 (566) hide show
  1. package/README.md +52 -0
  2. package/dist/cjs/package.json +3 -0
  3. package/dist/cjs/src/access.js +155 -0
  4. package/dist/cjs/src/auth/Eas.js +60 -0
  5. package/dist/cjs/src/auth/auth.js +79 -0
  6. package/dist/cjs/src/auth/oidc-clientcredentials-provider.js +26 -0
  7. package/dist/cjs/src/auth/oidc-externaljwt-provider.js +33 -0
  8. package/dist/cjs/src/auth/oidc-refreshtoken-provider.js +34 -0
  9. package/dist/cjs/src/auth/oidc.js +222 -0
  10. package/dist/cjs/src/auth/providers.js +143 -0
  11. package/dist/cjs/src/encodings/base64.js +154 -0
  12. package/dist/cjs/src/encodings/hex.js +70 -0
  13. package/dist/cjs/src/encodings/index.js +29 -0
  14. package/dist/cjs/src/errors.js +138 -0
  15. package/dist/cjs/src/index.js +344 -0
  16. package/dist/cjs/src/nanotdf/Client.js +296 -0
  17. package/dist/cjs/src/nanotdf/NanoTDF.js +94 -0
  18. package/dist/cjs/src/nanotdf/browser-entry.js +19 -0
  19. package/dist/cjs/src/nanotdf/constants.js +5 -0
  20. package/dist/cjs/src/nanotdf/decrypt.js +17 -0
  21. package/dist/cjs/src/nanotdf/encrypt-dataset.js +38 -0
  22. package/dist/cjs/src/nanotdf/encrypt.js +132 -0
  23. package/dist/cjs/src/nanotdf/enum/CipherEnum.js +13 -0
  24. package/dist/cjs/src/nanotdf/enum/CurveNameEnum.js +15 -0
  25. package/dist/cjs/src/nanotdf/enum/EncodingEnum.js +8 -0
  26. package/dist/cjs/src/nanotdf/enum/PolicyTypeEnum.js +11 -0
  27. package/dist/cjs/src/nanotdf/enum/ProtocolEnum.js +10 -0
  28. package/dist/cjs/src/nanotdf/enum/ResourceLocatorIdentifierEnum.js +11 -0
  29. package/dist/cjs/src/nanotdf/helpers/calculateByCurve.js +29 -0
  30. package/dist/cjs/src/nanotdf/helpers/getHkdfSalt.js +11 -0
  31. package/dist/cjs/src/nanotdf/index.js +25 -0
  32. package/dist/cjs/src/nanotdf/interfaces/PolicyInterface.js +3 -0
  33. package/dist/cjs/src/nanotdf/models/Ciphers.js +61 -0
  34. package/dist/cjs/src/nanotdf/models/DefaultParams.js +27 -0
  35. package/dist/cjs/src/nanotdf/models/EcCurves.js +39 -0
  36. package/dist/cjs/src/nanotdf/models/Header.js +255 -0
  37. package/dist/cjs/src/nanotdf/models/Payload.js +158 -0
  38. package/dist/cjs/src/nanotdf/models/Policy/AbstractPolicy.js +73 -0
  39. package/dist/cjs/src/nanotdf/models/Policy/EmbeddedPolicy.js +82 -0
  40. package/dist/cjs/src/nanotdf/models/Policy/PolicyFactory.js +38 -0
  41. package/dist/cjs/src/nanotdf/models/Policy/RemotePolicy.js +62 -0
  42. package/dist/cjs/src/nanotdf/models/ResourceLocator.js +211 -0
  43. package/dist/cjs/src/nanotdf/models/Signature.js +77 -0
  44. package/dist/cjs/src/nanotdf-crypto/ciphers.js +17 -0
  45. package/dist/cjs/src/nanotdf-crypto/decrypt.js +24 -0
  46. package/dist/cjs/src/nanotdf-crypto/digest.js +7 -0
  47. package/dist/cjs/src/nanotdf-crypto/ecdsaSignature.js +83 -0
  48. package/dist/cjs/src/nanotdf-crypto/encrypt.js +24 -0
  49. package/dist/cjs/src/nanotdf-crypto/enums.js +52 -0
  50. package/dist/cjs/src/nanotdf-crypto/exportCryptoKey.js +20 -0
  51. package/dist/cjs/src/nanotdf-crypto/generateKeyPair.js +13 -0
  52. package/dist/cjs/src/nanotdf-crypto/generateRandomNumber.js +12 -0
  53. package/dist/cjs/src/nanotdf-crypto/importRawKey.js +18 -0
  54. package/dist/cjs/src/nanotdf-crypto/index.js +52 -0
  55. package/dist/cjs/src/nanotdf-crypto/keyAgreement.js +91 -0
  56. package/dist/cjs/src/nanotdf-crypto/pemPublicToCrypto.js +225 -0
  57. package/dist/cjs/src/policy/api.js +58 -0
  58. package/dist/cjs/src/policy/attributes.js +3 -0
  59. package/dist/cjs/src/policy/granter.js +146 -0
  60. package/dist/cjs/src/tdf/AttributeObject.js +15 -0
  61. package/dist/cjs/src/tdf/AttributeObjectJwt.js +3 -0
  62. package/dist/cjs/src/tdf/Crypto.js +47 -0
  63. package/dist/cjs/src/tdf/EntityObject.js +3 -0
  64. package/dist/cjs/src/tdf/NanoTDF/NanoTDF.js +38 -0
  65. package/dist/cjs/src/tdf/Policy.js +50 -0
  66. package/dist/cjs/src/tdf/PolicyObject.js +3 -0
  67. package/dist/cjs/src/tdf/TypedArray.js +3 -0
  68. package/dist/cjs/src/tdf/index.js +35 -0
  69. package/dist/cjs/src/types/index.js +3 -0
  70. package/dist/cjs/src/utils.js +147 -0
  71. package/dist/cjs/src/version.js +12 -0
  72. package/dist/cjs/tdf3/index.js +57 -0
  73. package/dist/cjs/tdf3/src/assertions.js +118 -0
  74. package/dist/cjs/tdf3/src/binary.js +153 -0
  75. package/dist/cjs/tdf3/src/ciphers/aes-gcm-cipher.js +56 -0
  76. package/dist/cjs/tdf3/src/ciphers/algorithms.js +8 -0
  77. package/dist/cjs/tdf3/src/ciphers/index.js +8 -0
  78. package/dist/cjs/tdf3/src/ciphers/symmetric-cipher-base.js +22 -0
  79. package/dist/cjs/tdf3/src/client/DecoratedReadableStream.js +116 -0
  80. package/dist/cjs/tdf3/src/client/builders.js +561 -0
  81. package/dist/cjs/tdf3/src/client/index.js +460 -0
  82. package/dist/cjs/tdf3/src/client/validation.js +63 -0
  83. package/dist/cjs/tdf3/src/crypto/crypto-utils.js +116 -0
  84. package/dist/cjs/tdf3/src/crypto/declarations.js +8 -0
  85. package/dist/cjs/tdf3/src/crypto/index.js +315 -0
  86. package/dist/cjs/tdf3/src/index.js +34 -0
  87. package/dist/cjs/tdf3/src/models/attribute-set.js +122 -0
  88. package/dist/cjs/tdf3/src/models/encryption-information.js +90 -0
  89. package/dist/cjs/tdf3/src/models/index.js +25 -0
  90. package/dist/cjs/tdf3/src/models/key-access.js +103 -0
  91. package/dist/cjs/tdf3/src/models/manifest.js +3 -0
  92. package/dist/cjs/tdf3/src/models/payload.js +3 -0
  93. package/dist/cjs/tdf3/src/models/policy.js +24 -0
  94. package/dist/cjs/tdf3/src/models/upsert-response.js +3 -0
  95. package/dist/cjs/tdf3/src/tdf.js +907 -0
  96. package/dist/cjs/tdf3/src/templates/default.html.js +98 -0
  97. package/dist/cjs/tdf3/src/templates/escaper.js +15 -0
  98. package/dist/cjs/tdf3/src/templates/index.js +12 -0
  99. package/dist/cjs/tdf3/src/utils/buffer-crc32.js +48 -0
  100. package/dist/cjs/tdf3/src/utils/chunkers.js +106 -0
  101. package/dist/cjs/tdf3/src/utils/index.js +296 -0
  102. package/dist/cjs/tdf3/src/utils/keysplit.js +61 -0
  103. package/dist/cjs/tdf3/src/utils/zip-reader.js +253 -0
  104. package/dist/cjs/tdf3/src/utils/zip-writer.js +308 -0
  105. package/dist/cjs/tdf3/src/version.js +6 -0
  106. package/dist/types/src/access.d.ts +47 -0
  107. package/dist/types/src/access.d.ts.map +1 -0
  108. package/dist/types/src/auth/Eas.d.ts +34 -0
  109. package/dist/types/src/auth/Eas.d.ts.map +1 -0
  110. package/dist/types/src/auth/auth.d.ts +86 -0
  111. package/dist/types/src/auth/auth.d.ts.map +1 -0
  112. package/dist/types/src/auth/oidc-clientcredentials-provider.d.ts +9 -0
  113. package/dist/types/src/auth/oidc-clientcredentials-provider.d.ts.map +1 -0
  114. package/dist/types/src/auth/oidc-externaljwt-provider.d.ts +10 -0
  115. package/dist/types/src/auth/oidc-externaljwt-provider.d.ts.map +1 -0
  116. package/dist/types/src/auth/oidc-refreshtoken-provider.d.ts +10 -0
  117. package/dist/types/src/auth/oidc-refreshtoken-provider.d.ts.map +1 -0
  118. package/dist/types/src/auth/oidc.d.ts +104 -0
  119. package/dist/types/src/auth/oidc.d.ts.map +1 -0
  120. package/dist/types/src/auth/providers.d.ts +67 -0
  121. package/dist/types/src/auth/providers.d.ts.map +1 -0
  122. package/dist/types/src/encodings/base64.d.ts +18 -0
  123. package/dist/types/src/encodings/base64.d.ts.map +1 -0
  124. package/dist/types/src/encodings/hex.d.ts +5 -0
  125. package/dist/types/src/encodings/hex.d.ts.map +1 -0
  126. package/dist/types/src/encodings/index.d.ts +3 -0
  127. package/dist/types/src/encodings/index.d.ts.map +1 -0
  128. package/dist/types/src/errors.d.ts +72 -0
  129. package/dist/types/src/errors.d.ts.map +1 -0
  130. package/dist/types/src/index.d.ts +138 -0
  131. package/dist/types/src/index.d.ts.map +1 -0
  132. package/dist/types/src/nanotdf/Client.d.ts +95 -0
  133. package/dist/types/src/nanotdf/Client.d.ts.map +1 -0
  134. package/dist/types/src/nanotdf/NanoTDF.d.ts +25 -0
  135. package/dist/types/src/nanotdf/NanoTDF.d.ts.map +1 -0
  136. package/dist/types/src/nanotdf/browser-entry.d.ts +17 -0
  137. package/dist/types/src/nanotdf/browser-entry.d.ts.map +1 -0
  138. package/dist/types/src/nanotdf/constants.d.ts +2 -0
  139. package/dist/types/src/nanotdf/constants.d.ts.map +1 -0
  140. package/dist/types/src/nanotdf/decrypt.d.ts +9 -0
  141. package/dist/types/src/nanotdf/decrypt.d.ts.map +1 -0
  142. package/dist/types/src/nanotdf/encrypt-dataset.d.ts +12 -0
  143. package/dist/types/src/nanotdf/encrypt-dataset.d.ts.map +1 -0
  144. package/dist/types/src/nanotdf/encrypt.d.ts +14 -0
  145. package/dist/types/src/nanotdf/encrypt.d.ts.map +1 -0
  146. package/dist/types/src/nanotdf/enum/CipherEnum.d.ts +10 -0
  147. package/dist/types/src/nanotdf/enum/CipherEnum.d.ts.map +1 -0
  148. package/dist/types/src/nanotdf/enum/CurveNameEnum.d.ts +12 -0
  149. package/dist/types/src/nanotdf/enum/CurveNameEnum.d.ts.map +1 -0
  150. package/dist/types/src/nanotdf/enum/EncodingEnum.d.ts +5 -0
  151. package/dist/types/src/nanotdf/enum/EncodingEnum.d.ts.map +1 -0
  152. package/dist/types/src/nanotdf/enum/PolicyTypeEnum.d.ts +8 -0
  153. package/dist/types/src/nanotdf/enum/PolicyTypeEnum.d.ts.map +1 -0
  154. package/dist/types/src/nanotdf/enum/ProtocolEnum.d.ts +7 -0
  155. package/dist/types/src/nanotdf/enum/ProtocolEnum.d.ts.map +1 -0
  156. package/dist/types/src/nanotdf/enum/ResourceLocatorIdentifierEnum.d.ts +8 -0
  157. package/dist/types/src/nanotdf/enum/ResourceLocatorIdentifierEnum.d.ts.map +1 -0
  158. package/dist/types/src/nanotdf/helpers/calculateByCurve.d.ts +20 -0
  159. package/dist/types/src/nanotdf/helpers/calculateByCurve.d.ts.map +1 -0
  160. package/dist/types/src/nanotdf/helpers/getHkdfSalt.d.ts +9 -0
  161. package/dist/types/src/nanotdf/helpers/getHkdfSalt.d.ts.map +1 -0
  162. package/dist/types/src/nanotdf/index.d.ts +9 -0
  163. package/dist/types/src/nanotdf/index.d.ts.map +1 -0
  164. package/dist/types/src/nanotdf/interfaces/PolicyInterface.d.ts +17 -0
  165. package/dist/types/src/nanotdf/interfaces/PolicyInterface.d.ts.map +1 -0
  166. package/dist/types/src/nanotdf/models/Ciphers.d.ts +14 -0
  167. package/dist/types/src/nanotdf/models/Ciphers.d.ts.map +1 -0
  168. package/dist/types/src/nanotdf/models/DefaultParams.d.ts +21 -0
  169. package/dist/types/src/nanotdf/models/DefaultParams.d.ts.map +1 -0
  170. package/dist/types/src/nanotdf/models/EcCurves.d.ts +15 -0
  171. package/dist/types/src/nanotdf/models/EcCurves.d.ts.map +1 -0
  172. package/dist/types/src/nanotdf/models/Header.d.ts +73 -0
  173. package/dist/types/src/nanotdf/models/Header.d.ts.map +1 -0
  174. package/dist/types/src/nanotdf/models/Payload.d.ts +47 -0
  175. package/dist/types/src/nanotdf/models/Payload.d.ts.map +1 -0
  176. package/dist/types/src/nanotdf/models/Policy/AbstractPolicy.d.ts +52 -0
  177. package/dist/types/src/nanotdf/models/Policy/AbstractPolicy.d.ts.map +1 -0
  178. package/dist/types/src/nanotdf/models/Policy/EmbeddedPolicy.d.ts +35 -0
  179. package/dist/types/src/nanotdf/models/Policy/EmbeddedPolicy.d.ts.map +1 -0
  180. package/dist/types/src/nanotdf/models/Policy/PolicyFactory.d.ts +11 -0
  181. package/dist/types/src/nanotdf/models/Policy/PolicyFactory.d.ts.map +1 -0
  182. package/dist/types/src/nanotdf/models/Policy/RemotePolicy.d.ts +31 -0
  183. package/dist/types/src/nanotdf/models/Policy/RemotePolicy.d.ts.map +1 -0
  184. package/dist/types/src/nanotdf/models/ResourceLocator.d.ts +65 -0
  185. package/dist/types/src/nanotdf/models/ResourceLocator.d.ts.map +1 -0
  186. package/dist/types/src/nanotdf/models/Signature.d.ts +33 -0
  187. package/dist/types/src/nanotdf/models/Signature.d.ts.map +1 -0
  188. package/dist/types/src/nanotdf-crypto/ciphers.d.ts +8 -0
  189. package/dist/types/src/nanotdf-crypto/ciphers.d.ts.map +1 -0
  190. package/dist/types/src/nanotdf-crypto/decrypt.d.ts +14 -0
  191. package/dist/types/src/nanotdf-crypto/decrypt.d.ts.map +1 -0
  192. package/dist/types/src/nanotdf-crypto/digest.d.ts +3 -0
  193. package/dist/types/src/nanotdf-crypto/digest.d.ts.map +1 -0
  194. package/dist/types/src/nanotdf-crypto/ecdsaSignature.d.ts +35 -0
  195. package/dist/types/src/nanotdf-crypto/ecdsaSignature.d.ts.map +1 -0
  196. package/dist/types/src/nanotdf-crypto/encrypt.d.ts +14 -0
  197. package/dist/types/src/nanotdf-crypto/encrypt.d.ts.map +1 -0
  198. package/dist/types/src/nanotdf-crypto/enums.d.ts +42 -0
  199. package/dist/types/src/nanotdf-crypto/enums.d.ts.map +1 -0
  200. package/dist/types/src/nanotdf-crypto/exportCryptoKey.d.ts +7 -0
  201. package/dist/types/src/nanotdf-crypto/exportCryptoKey.d.ts.map +1 -0
  202. package/dist/types/src/nanotdf-crypto/generateKeyPair.d.ts +10 -0
  203. package/dist/types/src/nanotdf-crypto/generateKeyPair.d.ts.map +1 -0
  204. package/dist/types/src/nanotdf-crypto/generateRandomNumber.d.ts +5 -0
  205. package/dist/types/src/nanotdf-crypto/generateRandomNumber.d.ts.map +1 -0
  206. package/dist/types/src/nanotdf-crypto/importRawKey.d.ts +13 -0
  207. package/dist/types/src/nanotdf-crypto/importRawKey.d.ts.map +1 -0
  208. package/dist/types/src/nanotdf-crypto/index.d.ts +12 -0
  209. package/dist/types/src/nanotdf-crypto/index.d.ts.map +1 -0
  210. package/dist/types/src/nanotdf-crypto/keyAgreement.d.ts +28 -0
  211. package/dist/types/src/nanotdf-crypto/keyAgreement.d.ts.map +1 -0
  212. package/dist/types/src/nanotdf-crypto/pemPublicToCrypto.d.ts +28 -0
  213. package/dist/types/src/nanotdf-crypto/pemPublicToCrypto.d.ts.map +1 -0
  214. package/dist/types/src/policy/api.d.ts +4 -0
  215. package/dist/types/src/policy/api.d.ts.map +1 -0
  216. package/dist/types/src/policy/attributes.d.ts +95 -0
  217. package/dist/types/src/policy/attributes.d.ts.map +1 -0
  218. package/dist/types/src/policy/granter.d.ts +23 -0
  219. package/dist/types/src/policy/granter.d.ts.map +1 -0
  220. package/dist/types/src/tdf/AttributeObject.d.ts +13 -0
  221. package/dist/types/src/tdf/AttributeObject.d.ts.map +1 -0
  222. package/dist/types/src/tdf/AttributeObjectJwt.d.ts +4 -0
  223. package/dist/types/src/tdf/AttributeObjectJwt.d.ts.map +1 -0
  224. package/dist/types/src/tdf/Crypto.d.ts +37 -0
  225. package/dist/types/src/tdf/Crypto.d.ts.map +1 -0
  226. package/dist/types/src/tdf/EntityObject.d.ts +18 -0
  227. package/dist/types/src/tdf/EntityObject.d.ts.map +1 -0
  228. package/dist/types/src/tdf/NanoTDF/NanoTDF.d.ts +99 -0
  229. package/dist/types/src/tdf/NanoTDF/NanoTDF.d.ts.map +1 -0
  230. package/dist/types/src/tdf/Policy.d.ts +28 -0
  231. package/dist/types/src/tdf/Policy.d.ts.map +1 -0
  232. package/dist/types/src/tdf/PolicyObject.d.ts +11 -0
  233. package/dist/types/src/tdf/PolicyObject.d.ts.map +1 -0
  234. package/dist/types/src/tdf/TypedArray.d.ts +3 -0
  235. package/dist/types/src/tdf/TypedArray.d.ts.map +1 -0
  236. package/dist/types/src/tdf/index.d.ts +7 -0
  237. package/dist/types/src/tdf/index.d.ts.map +1 -0
  238. package/dist/types/src/types/index.d.ts +45 -0
  239. package/dist/types/src/types/index.d.ts.map +1 -0
  240. package/dist/types/src/utils.d.ts +45 -0
  241. package/dist/types/src/utils.d.ts.map +1 -0
  242. package/dist/types/src/version.d.ts +9 -0
  243. package/dist/types/src/version.d.ts.map +1 -0
  244. package/dist/types/tdf3/index.d.ts +16 -0
  245. package/dist/types/tdf3/index.d.ts.map +1 -0
  246. package/dist/types/tdf3/src/assertions.d.ts +63 -0
  247. package/dist/types/tdf3/src/assertions.d.ts.map +1 -0
  248. package/dist/types/tdf3/src/binary.d.ts +38 -0
  249. package/dist/types/tdf3/src/binary.d.ts.map +1 -0
  250. package/dist/types/tdf3/src/ciphers/aes-gcm-cipher.d.ts +18 -0
  251. package/dist/types/tdf3/src/ciphers/aes-gcm-cipher.d.ts.map +1 -0
  252. package/dist/types/tdf3/src/ciphers/algorithms.d.ts +4 -0
  253. package/dist/types/tdf3/src/ciphers/algorithms.d.ts.map +1 -0
  254. package/dist/types/tdf3/src/ciphers/index.d.ts +3 -0
  255. package/dist/types/tdf3/src/ciphers/index.d.ts.map +1 -0
  256. package/dist/types/tdf3/src/ciphers/symmetric-cipher-base.d.ts +14 -0
  257. package/dist/types/tdf3/src/ciphers/symmetric-cipher-base.d.ts.map +1 -0
  258. package/dist/types/tdf3/src/client/DecoratedReadableStream.d.ts +53 -0
  259. package/dist/types/tdf3/src/client/DecoratedReadableStream.d.ts.map +1 -0
  260. package/dist/types/tdf3/src/client/builders.d.ts +436 -0
  261. package/dist/types/tdf3/src/client/builders.d.ts.map +1 -0
  262. package/dist/types/tdf3/src/client/index.d.ts +139 -0
  263. package/dist/types/tdf3/src/client/index.d.ts.map +1 -0
  264. package/dist/types/tdf3/src/client/validation.d.ts +8 -0
  265. package/dist/types/tdf3/src/client/validation.d.ts.map +1 -0
  266. package/dist/types/tdf3/src/crypto/crypto-utils.d.ts +34 -0
  267. package/dist/types/tdf3/src/crypto/crypto-utils.d.ts.map +1 -0
  268. package/dist/types/tdf3/src/crypto/declarations.d.ts +60 -0
  269. package/dist/types/tdf3/src/crypto/declarations.d.ts.map +1 -0
  270. package/dist/types/tdf3/src/crypto/index.d.ts +103 -0
  271. package/dist/types/tdf3/src/crypto/index.d.ts.map +1 -0
  272. package/dist/types/tdf3/src/index.d.ts +5 -0
  273. package/dist/types/tdf3/src/index.d.ts.map +1 -0
  274. package/dist/types/tdf3/src/models/attribute-set.d.ts +65 -0
  275. package/dist/types/tdf3/src/models/attribute-set.d.ts.map +1 -0
  276. package/dist/types/tdf3/src/models/encryption-information.d.ts +49 -0
  277. package/dist/types/tdf3/src/models/encryption-information.d.ts.map +1 -0
  278. package/dist/types/tdf3/src/models/index.d.ts +9 -0
  279. package/dist/types/tdf3/src/models/index.d.ts.map +1 -0
  280. package/dist/types/tdf3/src/models/key-access.d.ts +42 -0
  281. package/dist/types/tdf3/src/models/key-access.d.ts.map +1 -0
  282. package/dist/types/tdf3/src/models/manifest.d.ts +9 -0
  283. package/dist/types/tdf3/src/models/manifest.d.ts.map +1 -0
  284. package/dist/types/tdf3/src/models/payload.d.ts +7 -0
  285. package/dist/types/tdf3/src/models/payload.d.ts.map +1 -0
  286. package/dist/types/tdf3/src/models/policy.d.ts +13 -0
  287. package/dist/types/tdf3/src/models/policy.d.ts.map +1 -0
  288. package/dist/types/tdf3/src/models/upsert-response.d.ts +16 -0
  289. package/dist/types/tdf3/src/models/upsert-response.d.ts.map +1 -0
  290. package/dist/types/tdf3/src/tdf.d.ts +152 -0
  291. package/dist/types/tdf3/src/tdf.d.ts.map +1 -0
  292. package/dist/types/tdf3/src/templates/default.html.d.ts +8 -0
  293. package/dist/types/tdf3/src/templates/default.html.d.ts.map +1 -0
  294. package/dist/types/tdf3/src/templates/escaper.d.ts +6 -0
  295. package/dist/types/tdf3/src/templates/escaper.d.ts.map +1 -0
  296. package/dist/types/tdf3/src/templates/index.d.ts +3 -0
  297. package/dist/types/tdf3/src/templates/index.d.ts.map +1 -0
  298. package/dist/types/tdf3/src/utils/buffer-crc32.d.ts +2 -0
  299. package/dist/types/tdf3/src/utils/buffer-crc32.d.ts.map +1 -0
  300. package/dist/types/tdf3/src/utils/chunkers.d.ts +29 -0
  301. package/dist/types/tdf3/src/utils/chunkers.d.ts.map +1 -0
  302. package/dist/types/tdf3/src/utils/index.d.ts +36 -0
  303. package/dist/types/tdf3/src/utils/index.d.ts.map +1 -0
  304. package/dist/types/tdf3/src/utils/keysplit.d.ts +19 -0
  305. package/dist/types/tdf3/src/utils/keysplit.d.ts.map +1 -0
  306. package/dist/types/tdf3/src/utils/zip-reader.d.ts +63 -0
  307. package/dist/types/tdf3/src/utils/zip-reader.d.ts.map +1 -0
  308. package/dist/types/tdf3/src/utils/zip-writer.d.ts +35 -0
  309. package/dist/types/tdf3/src/utils/zip-writer.d.ts.map +1 -0
  310. package/dist/types/tdf3/src/version.d.ts +3 -0
  311. package/dist/types/tdf3/src/version.d.ts.map +1 -0
  312. package/dist/web/package.json +3 -0
  313. package/dist/web/src/access.js +147 -0
  314. package/dist/web/src/auth/Eas.js +55 -0
  315. package/dist/web/src/auth/auth.js +71 -0
  316. package/dist/web/src/auth/oidc-clientcredentials-provider.js +22 -0
  317. package/dist/web/src/auth/oidc-externaljwt-provider.js +29 -0
  318. package/dist/web/src/auth/oidc-refreshtoken-provider.js +30 -0
  319. package/dist/web/src/auth/oidc.js +215 -0
  320. package/dist/web/src/auth/providers.js +119 -0
  321. package/dist/web/src/encodings/base64.js +147 -0
  322. package/dist/web/src/encodings/hex.js +63 -0
  323. package/dist/web/src/encodings/index.js +3 -0
  324. package/dist/web/src/errors.js +123 -0
  325. package/dist/web/src/index.js +313 -0
  326. package/dist/web/src/nanotdf/Client.js +268 -0
  327. package/dist/web/src/nanotdf/NanoTDF.js +89 -0
  328. package/dist/web/src/nanotdf/browser-entry.js +14 -0
  329. package/dist/web/src/nanotdf/constants.js +2 -0
  330. package/dist/web/src/nanotdf/decrypt.js +14 -0
  331. package/dist/web/src/nanotdf/encrypt-dataset.js +32 -0
  332. package/dist/web/src/nanotdf/encrypt.js +126 -0
  333. package/dist/web/src/nanotdf/enum/CipherEnum.js +11 -0
  334. package/dist/web/src/nanotdf/enum/CurveNameEnum.js +13 -0
  335. package/dist/web/src/nanotdf/enum/EncodingEnum.js +6 -0
  336. package/dist/web/src/nanotdf/enum/PolicyTypeEnum.js +9 -0
  337. package/dist/web/src/nanotdf/enum/ProtocolEnum.js +8 -0
  338. package/dist/web/src/nanotdf/enum/ResourceLocatorIdentifierEnum.js +9 -0
  339. package/dist/web/src/nanotdf/helpers/calculateByCurve.js +24 -0
  340. package/dist/web/src/nanotdf/helpers/getHkdfSalt.js +8 -0
  341. package/dist/web/src/nanotdf/index.js +11 -0
  342. package/dist/web/src/nanotdf/interfaces/PolicyInterface.js +2 -0
  343. package/dist/web/src/nanotdf/models/Ciphers.js +54 -0
  344. package/dist/web/src/nanotdf/models/DefaultParams.js +22 -0
  345. package/dist/web/src/nanotdf/models/EcCurves.js +32 -0
  346. package/dist/web/src/nanotdf/models/Header.js +250 -0
  347. package/dist/web/src/nanotdf/models/Payload.js +156 -0
  348. package/dist/web/src/nanotdf/models/Policy/AbstractPolicy.js +71 -0
  349. package/dist/web/src/nanotdf/models/Policy/EmbeddedPolicy.js +77 -0
  350. package/dist/web/src/nanotdf/models/Policy/PolicyFactory.js +33 -0
  351. package/dist/web/src/nanotdf/models/Policy/RemotePolicy.js +57 -0
  352. package/dist/web/src/nanotdf/models/ResourceLocator.js +206 -0
  353. package/dist/web/src/nanotdf/models/Signature.js +74 -0
  354. package/dist/web/src/nanotdf-crypto/ciphers.js +14 -0
  355. package/dist/web/src/nanotdf-crypto/decrypt.js +21 -0
  356. package/dist/web/src/nanotdf-crypto/digest.js +4 -0
  357. package/dist/web/src/nanotdf-crypto/ecdsaSignature.js +77 -0
  358. package/dist/web/src/nanotdf-crypto/encrypt.js +21 -0
  359. package/dist/web/src/nanotdf-crypto/enums.js +49 -0
  360. package/dist/web/src/nanotdf-crypto/exportCryptoKey.js +17 -0
  361. package/dist/web/src/nanotdf-crypto/generateKeyPair.js +10 -0
  362. package/dist/web/src/nanotdf-crypto/generateRandomNumber.js +9 -0
  363. package/dist/web/src/nanotdf-crypto/importRawKey.js +15 -0
  364. package/dist/web/src/nanotdf-crypto/index.js +12 -0
  365. package/dist/web/src/nanotdf-crypto/keyAgreement.js +87 -0
  366. package/dist/web/src/nanotdf-crypto/pemPublicToCrypto.js +197 -0
  367. package/dist/web/src/policy/api.js +54 -0
  368. package/dist/web/src/policy/attributes.js +2 -0
  369. package/dist/web/src/policy/granter.js +141 -0
  370. package/dist/web/src/tdf/AttributeObject.js +11 -0
  371. package/dist/web/src/tdf/AttributeObjectJwt.js +2 -0
  372. package/dist/web/src/tdf/Crypto.js +44 -0
  373. package/dist/web/src/tdf/EntityObject.js +2 -0
  374. package/dist/web/src/tdf/NanoTDF/NanoTDF.js +35 -0
  375. package/dist/web/src/tdf/Policy.js +48 -0
  376. package/dist/web/src/tdf/PolicyObject.js +2 -0
  377. package/dist/web/src/tdf/TypedArray.js +2 -0
  378. package/dist/web/src/tdf/index.js +4 -0
  379. package/dist/web/src/types/index.js +2 -0
  380. package/dist/web/src/utils.js +133 -0
  381. package/dist/web/src/version.js +9 -0
  382. package/dist/web/tdf3/index.js +13 -0
  383. package/dist/web/tdf3/src/assertions.js +111 -0
  384. package/dist/web/tdf3/src/binary.js +149 -0
  385. package/dist/web/tdf3/src/ciphers/aes-gcm-cipher.js +52 -0
  386. package/dist/web/tdf3/src/ciphers/algorithms.js +5 -0
  387. package/dist/web/tdf3/src/ciphers/index.js +3 -0
  388. package/dist/web/tdf3/src/ciphers/symmetric-cipher-base.js +18 -0
  389. package/dist/web/tdf3/src/client/DecoratedReadableStream.js +107 -0
  390. package/dist/web/tdf3/src/client/builders.js +557 -0
  391. package/dist/web/tdf3/src/client/index.js +423 -0
  392. package/dist/web/tdf3/src/client/validation.js +58 -0
  393. package/dist/web/tdf3/src/crypto/crypto-utils.js +107 -0
  394. package/dist/web/tdf3/src/crypto/declarations.js +5 -0
  395. package/dist/web/tdf3/src/crypto/index.js +296 -0
  396. package/dist/web/tdf3/src/index.js +5 -0
  397. package/dist/web/tdf3/src/models/attribute-set.js +118 -0
  398. package/dist/web/tdf3/src/models/encryption-information.js +86 -0
  399. package/dist/web/tdf3/src/models/index.js +9 -0
  400. package/dist/web/tdf3/src/models/key-access.js +74 -0
  401. package/dist/web/tdf3/src/models/manifest.js +2 -0
  402. package/dist/web/tdf3/src/models/payload.js +2 -0
  403. package/dist/web/tdf3/src/models/policy.js +20 -0
  404. package/dist/web/tdf3/src/models/upsert-response.js +2 -0
  405. package/dist/web/tdf3/src/tdf.js +866 -0
  406. package/dist/web/tdf3/src/templates/default.html.js +96 -0
  407. package/dist/web/tdf3/src/templates/escaper.js +10 -0
  408. package/dist/web/tdf3/src/templates/index.js +3 -0
  409. package/dist/web/tdf3/src/utils/buffer-crc32.js +44 -0
  410. package/dist/web/tdf3/src/utils/chunkers.js +96 -0
  411. package/dist/web/tdf3/src/utils/index.js +248 -0
  412. package/dist/web/tdf3/src/utils/keysplit.js +55 -0
  413. package/dist/web/tdf3/src/utils/zip-reader.js +247 -0
  414. package/dist/web/tdf3/src/utils/zip-writer.js +302 -0
  415. package/dist/web/tdf3/src/version.js +3 -0
  416. package/package.json +126 -0
  417. package/src/access.ts +198 -0
  418. package/src/auth/Eas.ts +79 -0
  419. package/src/auth/auth.ts +141 -0
  420. package/src/auth/oidc-clientcredentials-provider.ts +32 -0
  421. package/src/auth/oidc-externaljwt-provider.ts +41 -0
  422. package/src/auth/oidc-refreshtoken-provider.ts +41 -0
  423. package/src/auth/oidc.ts +307 -0
  424. package/src/auth/providers.ts +139 -0
  425. package/src/encodings/base64.ts +160 -0
  426. package/src/encodings/hex.ts +69 -0
  427. package/src/encodings/index.ts +2 -0
  428. package/src/errors.ts +113 -0
  429. package/src/index.ts +441 -0
  430. package/src/nanotdf/Client.ts +349 -0
  431. package/src/nanotdf/NanoTDF.ts +121 -0
  432. package/src/nanotdf/browser-entry.ts +20 -0
  433. package/src/nanotdf/constants.ts +1 -0
  434. package/src/nanotdf/decrypt.ts +19 -0
  435. package/src/nanotdf/encrypt-dataset.ts +52 -0
  436. package/src/nanotdf/encrypt.ts +197 -0
  437. package/src/nanotdf/enum/CipherEnum.ts +10 -0
  438. package/src/nanotdf/enum/CurveNameEnum.ts +12 -0
  439. package/src/nanotdf/enum/EncodingEnum.ts +5 -0
  440. package/src/nanotdf/enum/PolicyTypeEnum.ts +8 -0
  441. package/src/nanotdf/enum/ProtocolEnum.ts +7 -0
  442. package/src/nanotdf/enum/ResourceLocatorIdentifierEnum.ts +8 -0
  443. package/src/nanotdf/helpers/calculateByCurve.ts +26 -0
  444. package/src/nanotdf/helpers/getHkdfSalt.ts +15 -0
  445. package/src/nanotdf/index.ts +10 -0
  446. package/src/nanotdf/interfaces/PolicyInterface.ts +27 -0
  447. package/src/nanotdf/models/Ciphers.ts +67 -0
  448. package/src/nanotdf/models/DefaultParams.ts +24 -0
  449. package/src/nanotdf/models/EcCurves.ts +40 -0
  450. package/src/nanotdf/models/Header.ts +322 -0
  451. package/src/nanotdf/models/Payload.ts +196 -0
  452. package/src/nanotdf/models/Policy/AbstractPolicy.ts +90 -0
  453. package/src/nanotdf/models/Policy/EmbeddedPolicy.ts +101 -0
  454. package/src/nanotdf/models/Policy/PolicyFactory.ts +48 -0
  455. package/src/nanotdf/models/Policy/RemotePolicy.ts +74 -0
  456. package/src/nanotdf/models/ResourceLocator.ts +212 -0
  457. package/src/nanotdf/models/Signature.ts +85 -0
  458. package/src/nanotdf-crypto/ciphers.ts +13 -0
  459. package/src/nanotdf-crypto/decrypt.ts +30 -0
  460. package/src/nanotdf-crypto/digest.ts +8 -0
  461. package/src/nanotdf-crypto/ecdsaSignature.ts +109 -0
  462. package/src/nanotdf-crypto/encrypt.ts +30 -0
  463. package/src/nanotdf-crypto/enums.ts +47 -0
  464. package/src/nanotdf-crypto/exportCryptoKey.ts +17 -0
  465. package/src/nanotdf-crypto/generateKeyPair.ts +19 -0
  466. package/src/nanotdf-crypto/generateRandomNumber.ts +8 -0
  467. package/src/nanotdf-crypto/importRawKey.ts +19 -0
  468. package/src/nanotdf-crypto/index.ts +11 -0
  469. package/src/nanotdf-crypto/keyAgreement.ts +139 -0
  470. package/src/nanotdf-crypto/pemPublicToCrypto.ts +232 -0
  471. package/src/package-lock.json +6 -0
  472. package/src/package.json +3 -0
  473. package/src/platform/authorization/authorization_connect.d.ts +44 -0
  474. package/src/platform/authorization/authorization_connect.js +44 -0
  475. package/src/platform/authorization/authorization_pb.d.ts +707 -0
  476. package/src/platform/authorization/authorization_pb.js +372 -0
  477. package/src/platform/common/common_pb.d.ts +129 -0
  478. package/src/platform/common/common_pb.js +58 -0
  479. package/src/platform/entityresolution/entity_resolution_connect.d.ts +35 -0
  480. package/src/platform/entityresolution/entity_resolution_connect.js +35 -0
  481. package/src/platform/entityresolution/entity_resolution_pb.d.ts +242 -0
  482. package/src/platform/entityresolution/entity_resolution_pb.js +139 -0
  483. package/src/platform/kas/kas_connect.d.ts +59 -0
  484. package/src/platform/kas/kas_connect.js +59 -0
  485. package/src/platform/kas/kas_pb.d.ts +200 -0
  486. package/src/platform/kas/kas_pb.js +84 -0
  487. package/src/platform/policy/attributes/attributes_connect.d.ts +168 -0
  488. package/src/platform/policy/attributes/attributes_connect.js +168 -0
  489. package/src/platform/policy/attributes/attributes_pb.d.ts +929 -0
  490. package/src/platform/policy/attributes/attributes_pb.js +363 -0
  491. package/src/platform/policy/kasregistry/key_access_server_registry_connect.d.ts +62 -0
  492. package/src/platform/policy/kasregistry/key_access_server_registry_connect.js +62 -0
  493. package/src/platform/policy/kasregistry/key_access_server_registry_pb.d.ts +283 -0
  494. package/src/platform/policy/kasregistry/key_access_server_registry_pb.js +113 -0
  495. package/src/platform/policy/namespaces/namespaces_connect.d.ts +62 -0
  496. package/src/platform/policy/namespaces/namespaces_connect.js +62 -0
  497. package/src/platform/policy/namespaces/namespaces_pb.d.ts +270 -0
  498. package/src/platform/policy/namespaces/namespaces_pb.js +110 -0
  499. package/src/platform/policy/objects_pb.d.ts +725 -0
  500. package/src/platform/policy/objects_pb.js +288 -0
  501. package/src/platform/policy/resourcemapping/resource_mapping_connect.d.ts +259 -0
  502. package/src/platform/policy/resourcemapping/resource_mapping_connect.js +259 -0
  503. package/src/platform/policy/resourcemapping/resource_mapping_pb.d.ts +314 -0
  504. package/src/platform/policy/resourcemapping/resource_mapping_pb.js +142 -0
  505. package/src/platform/policy/selectors_pb.d.ts +269 -0
  506. package/src/platform/policy/selectors_pb.js +110 -0
  507. package/src/platform/policy/subjectmapping/subject_mapping_connect.d.ts +118 -0
  508. package/src/platform/policy/subjectmapping/subject_mapping_connect.js +118 -0
  509. package/src/platform/policy/subjectmapping/subject_mapping_pb.d.ts +672 -0
  510. package/src/platform/policy/subjectmapping/subject_mapping_pb.js +260 -0
  511. package/src/platform/wellknownconfiguration/wellknown_configuration_connect.d.ts +26 -0
  512. package/src/platform/wellknownconfiguration/wellknown_configuration_connect.js +26 -0
  513. package/src/platform/wellknownconfiguration/wellknown_configuration_pb.d.ts +75 -0
  514. package/src/platform/wellknownconfiguration/wellknown_configuration_pb.js +35 -0
  515. package/src/policy/api.ts +61 -0
  516. package/src/policy/attributes.ts +117 -0
  517. package/src/policy/granter.ts +181 -0
  518. package/src/tdf/AttributeObject.ts +27 -0
  519. package/src/tdf/AttributeObjectJwt.ts +3 -0
  520. package/src/tdf/Crypto.ts +42 -0
  521. package/src/tdf/EntityObject.ts +18 -0
  522. package/src/tdf/NanoTDF/NanoTDF.ts +120 -0
  523. package/src/tdf/Policy.ts +51 -0
  524. package/src/tdf/PolicyObject.ts +12 -0
  525. package/src/tdf/TypedArray.ts +12 -0
  526. package/src/tdf/index.ts +6 -0
  527. package/src/types/index.ts +55 -0
  528. package/src/utils.ts +149 -0
  529. package/src/version.ts +9 -0
  530. package/tdf3/index.ts +91 -0
  531. package/tdf3/package-lock.json +6 -0
  532. package/tdf3/package.json +3 -0
  533. package/tdf3/src/assertions.ts +191 -0
  534. package/tdf3/src/binary.ts +195 -0
  535. package/tdf3/src/ciphers/aes-gcm-cipher.ts +76 -0
  536. package/tdf3/src/ciphers/algorithms.ts +9 -0
  537. package/tdf3/src/ciphers/index.ts +2 -0
  538. package/tdf3/src/ciphers/symmetric-cipher-base.ts +38 -0
  539. package/tdf3/src/client/DecoratedReadableStream.ts +148 -0
  540. package/tdf3/src/client/builders.ts +701 -0
  541. package/tdf3/src/client/index.ts +637 -0
  542. package/tdf3/src/client/validation.ts +79 -0
  543. package/tdf3/src/crypto/crypto-utils.ts +119 -0
  544. package/tdf3/src/crypto/declarations.ts +89 -0
  545. package/tdf3/src/crypto/index.ts +394 -0
  546. package/tdf3/src/index.ts +4 -0
  547. package/tdf3/src/models/attribute-set.ts +142 -0
  548. package/tdf3/src/models/encryption-information.ts +172 -0
  549. package/tdf3/src/models/index.ts +8 -0
  550. package/tdf3/src/models/key-access.ts +128 -0
  551. package/tdf3/src/models/manifest.ts +9 -0
  552. package/tdf3/src/models/payload.ts +6 -0
  553. package/tdf3/src/models/policy.ts +35 -0
  554. package/tdf3/src/models/upsert-response.ts +17 -0
  555. package/tdf3/src/tdf.ts +1351 -0
  556. package/tdf3/src/templates/default.html.ts +105 -0
  557. package/tdf3/src/templates/escaper.ts +10 -0
  558. package/tdf3/src/templates/index.ts +2 -0
  559. package/tdf3/src/utils/buffer-crc32.ts +46 -0
  560. package/tdf3/src/utils/chunkers.ts +118 -0
  561. package/tdf3/src/utils/index.ts +309 -0
  562. package/tdf3/src/utils/keysplit.ts +63 -0
  563. package/tdf3/src/utils/zip-reader.ts +341 -0
  564. package/tdf3/src/utils/zip-writer.ts +375 -0
  565. package/tdf3/src/version.ts +2 -0
  566. package/tdf3/types.d.ts +14 -0
@@ -0,0 +1,142 @@
1
+ import { decodeJwt } from 'jose';
2
+
3
+ export type AttributeObject = {
4
+ attribute: string;
5
+ kasUrl?: string;
6
+ kid?: string;
7
+ pubKey?: string;
8
+ displayName?: string;
9
+ isDefault?: boolean;
10
+ jwt?: string;
11
+ };
12
+
13
+ export class AttributeSet {
14
+ attributes: AttributeObject[];
15
+
16
+ verbose: boolean = false;
17
+
18
+ defaultAttribute?: AttributeObject;
19
+
20
+ constructor() {
21
+ this.attributes = [];
22
+ }
23
+
24
+ /**
25
+ * Check if attribute is in the list
26
+ * @param attribute URL of the attribute
27
+ * @return if attribute is in the set
28
+ */
29
+ has(attribute = ''): boolean {
30
+ // This could be much more elegant with something other than an
31
+ // array as the data structure. This is OK-ish only because the
32
+ // expected size of the data structure is small
33
+ // console.log(">>> ----- Has Attribute" + attribute);
34
+ return !!this.attributes.find((attrObj) => attrObj.attribute === attribute);
35
+ }
36
+
37
+ /**
38
+ * Get an attribute by URL
39
+ * @param attribute URL of the attribute
40
+ * @return attribute in object form, if found
41
+ */
42
+ get(attribute = ''): AttributeObject | null {
43
+ // This could be much more elegant with something other than an
44
+ // array as the data structure. This is OK-ish only because the
45
+ // expected size of the data structure is small
46
+ // console.log(">>> ----- Get Attribute" + attribute);
47
+ const result = this.attributes.filter((attrObj) => attrObj.attribute == attribute);
48
+ return result.length > 0 ? result[0] : null;
49
+ }
50
+
51
+ /**
52
+ * Get all the attributes.
53
+ * @return default attribute in object form or null
54
+ */
55
+ getDefault(): AttributeObject | null {
56
+ return this.defaultAttribute || null;
57
+ }
58
+
59
+ /**
60
+ * Get the default attribute, if it exists.
61
+ * @return return all the attribute urls
62
+ */
63
+ getUrls(): string[] {
64
+ return this.attributes.map((attr) => attr.attribute);
65
+ }
66
+
67
+ /**
68
+ * Add an attribute to the set. Should be idempotent.
69
+ * @param attrObj AttributeObject to add, in non-JWT form
70
+ * @return the attribute object if successful, or null
71
+ */
72
+ addAttribute(attrObj: AttributeObject): AttributeObject | null {
73
+ // Check for duplicate entries to assure idempotency.
74
+ if (this.has(attrObj.attribute)) {
75
+ // This may be a common occurance, so only un-comment this log message
76
+ // if you want verbose mode.
77
+ // console.log(`Attribute ${attrObj.attribute} is already loaded.`);
78
+ return null; // reject silently
79
+ }
80
+
81
+ if (attrObj.isDefault === true) {
82
+ if (this.defaultAttribute && this.defaultAttribute.attribute !== attrObj.attribute) {
83
+ // Remove the existing default attribute to make room for the new one
84
+ this.deleteAttribute(this.defaultAttribute.attribute);
85
+ }
86
+ this.defaultAttribute = attrObj;
87
+ }
88
+ this.attributes.push(attrObj);
89
+ return attrObj;
90
+ }
91
+
92
+ /**
93
+ * Delete an attribute from the set. Should be idempotent.
94
+ * @param attrUrl - URL of Attribute object to delete.
95
+ * @return The attribute object if successful or null if not
96
+ */
97
+ deleteAttribute(attrUrl = ''): AttributeObject | null {
98
+ const deleted = this.get(attrUrl);
99
+ if (deleted) {
100
+ this.attributes = this.attributes.filter((attrObj) => attrObj.attribute != attrUrl);
101
+ }
102
+ return deleted;
103
+ }
104
+
105
+ /**
106
+ * Add a list of attributes in object form
107
+ * @param attributes List of attribute objects as provided in an EntityObject
108
+ * @param easPublicKey EAS public key for decrypting the JWTs
109
+ * @return list of attribute objects
110
+ */
111
+ addAttributes(attributes: AttributeObject[] = []): (AttributeObject | null)[] {
112
+ return attributes
113
+ .map((attrObj) => {
114
+ return this.addAttribute(attrObj); // Returns promise
115
+ })
116
+ .filter((x) => x);
117
+ }
118
+
119
+ /**
120
+ * Add an attribute in JWT form = { jwt: <string jwt> }
121
+ * @param {Object} jwtAttribute - Attribute object in JWT form.
122
+ * @return {Object} - Decrypted and added attribute object
123
+ */
124
+ addJwtAttribute(jwtAttribute: { jwt: string }) {
125
+ const attrJwt = jwtAttribute?.jwt;
126
+ // Can't verify the JWT because the client does not have the easPublicKey,
127
+ // but the contents of the JWT can be decoded.
128
+ const attrObjPayload = attrJwt && decodeJwt(attrJwt);
129
+ if (!attrObjPayload) {
130
+ return null;
131
+ }
132
+ // JWT payloads contain many things, incluing .iat and .exp. This
133
+ // extraneous material should be stripped away before adding the
134
+ // attribute to the attributeSet.
135
+ const { attribute, displayName, pubKey, kasUrl } = attrObjPayload as AttributeObject;
136
+ const attrObj: AttributeObject = { attribute, displayName, pubKey, kasUrl, jwt: attrJwt };
137
+ if (attrObjPayload.isDefault) {
138
+ attrObj.isDefault = !!attrObjPayload.isDefault;
139
+ }
140
+ return this.addAttribute(attrObj);
141
+ }
142
+ }
@@ -0,0 +1,172 @@
1
+ import { keySplit } from '../utils/index.js';
2
+ import { base64, hex } from '../../../src/encodings/index.js';
3
+ import { Binary } from '../binary.js';
4
+ import { type SymmetricCipher } from '../ciphers/symmetric-cipher-base.js';
5
+ import { type KeyAccess, type KeyAccessObject } from './key-access.js';
6
+ import { type Policy } from './policy.js';
7
+ import {
8
+ type CryptoService,
9
+ type DecryptResult,
10
+ type EncryptResult,
11
+ } from '../crypto/declarations.js';
12
+ import { IntegrityAlgorithm } from '../tdf.js';
13
+ import { ConfigurationError } from '../../../src/errors.js';
14
+
15
+ export type KeyInfo = {
16
+ readonly unwrappedKeyBinary: Binary;
17
+ readonly unwrappedKeyIvBinary: Binary;
18
+ };
19
+
20
+ export type Segment = {
21
+ readonly hash: string;
22
+ // If not present, segmentSizeDefault must be defined and used.
23
+ readonly segmentSize?: number;
24
+ // If not present, encryptedSegmentSizeDefault must be defined and used.??
25
+ readonly encryptedSegmentSize?: number;
26
+ };
27
+
28
+ export type SplitType = 'split';
29
+
30
+ export type EncryptionInformation = {
31
+ readonly type: SplitType;
32
+ readonly keyAccess: KeyAccessObject[];
33
+ readonly integrityInformation: {
34
+ readonly rootSignature: {
35
+ alg: IntegrityAlgorithm;
36
+ sig: string;
37
+ };
38
+ segmentHashAlg?: IntegrityAlgorithm;
39
+ segments: Segment[];
40
+ segmentSizeDefault?: number;
41
+ encryptedSegmentSizeDefault?: number;
42
+ };
43
+ readonly method: {
44
+ readonly algorithm: string;
45
+ isStreamable: boolean;
46
+ readonly iv: string;
47
+ };
48
+ policy: string;
49
+ };
50
+
51
+ export class SplitKey {
52
+ readonly cryptoService: CryptoService;
53
+ keyAccess: KeyAccess[];
54
+
55
+ constructor(public readonly cipher: SymmetricCipher) {
56
+ this.cryptoService = cipher.cryptoService;
57
+ this.keyAccess = [];
58
+ }
59
+
60
+ async generateKey(): Promise<KeyInfo> {
61
+ const unwrappedKey = await this.cipher.generateKey();
62
+ const unwrappedKeyBinary = Binary.fromString(hex.decode(unwrappedKey));
63
+ const unwrappedKeyIvBinary = await this.generateIvBinary();
64
+ return { unwrappedKeyBinary, unwrappedKeyIvBinary };
65
+ }
66
+
67
+ async encrypt(
68
+ contentBinary: Binary,
69
+ keyBinary: Binary,
70
+ ivBinaryOptional?: Binary
71
+ ): Promise<EncryptResult> {
72
+ const ivBinary = ivBinaryOptional || (await this.generateIvBinary());
73
+ return this.cipher.encrypt(contentBinary, keyBinary, ivBinary);
74
+ }
75
+
76
+ async decrypt(content: Uint8Array, keyBinary: Binary): Promise<DecryptResult> {
77
+ return this.cipher.decrypt(content, keyBinary);
78
+ }
79
+
80
+ async getKeyAccessObjects(policy: Policy, keyInfo: KeyInfo): Promise<KeyAccessObject[]> {
81
+ const splitIds = [...new Set(this.keyAccess.map(({ sid }) => sid))].sort((a, b) =>
82
+ a.localeCompare(b)
83
+ );
84
+ const unwrappedKeySplitBuffers = await keySplit(
85
+ new Uint8Array(keyInfo.unwrappedKeyBinary.asByteArray()),
86
+ splitIds.length,
87
+ this.cryptoService
88
+ );
89
+ const splitsByName = Object.fromEntries(
90
+ splitIds.map((sid, index) => [sid, unwrappedKeySplitBuffers[index]])
91
+ );
92
+
93
+ const keyAccessObjects = [];
94
+ for (const item of this.keyAccess) {
95
+ // use the key split to encrypt metadata for each key access object
96
+ const unwrappedKeySplitBuffer = splitsByName[item.sid];
97
+ const unwrappedKeySplitBinary = Binary.fromArrayBuffer(unwrappedKeySplitBuffer.buffer);
98
+
99
+ const metadata = item.metadata || '';
100
+ const metadataStr = (
101
+ typeof metadata === 'object'
102
+ ? JSON.stringify(metadata)
103
+ : typeof metadata === 'string'
104
+ ? metadata
105
+ : () => {
106
+ throw new ConfigurationError(
107
+ "KAO generation failure: metadata isn't a string or object"
108
+ );
109
+ }
110
+ ) as string;
111
+
112
+ const metadataBinary = Binary.fromArrayBuffer(new TextEncoder().encode(metadataStr));
113
+
114
+ const encryptedMetadataResult = await this.encrypt(
115
+ metadataBinary,
116
+ unwrappedKeySplitBinary,
117
+ keyInfo.unwrappedKeyIvBinary
118
+ );
119
+
120
+ const encryptedMetadataOb = {
121
+ ciphertext: base64.encode(encryptedMetadataResult.payload.asString()),
122
+ iv: base64.encode(keyInfo.unwrappedKeyIvBinary.asString()),
123
+ };
124
+
125
+ const encryptedMetadataStr = JSON.stringify(encryptedMetadataOb);
126
+ const keyAccessObject = await item.write(
127
+ policy,
128
+ unwrappedKeySplitBuffer,
129
+ encryptedMetadataStr
130
+ );
131
+ keyAccessObjects.push(keyAccessObject);
132
+ }
133
+
134
+ return keyAccessObjects;
135
+ }
136
+
137
+ async generateIvBinary(): Promise<Binary> {
138
+ const iv = await this.cipher.generateInitializationVector();
139
+ return Binary.fromString(hex.decode(iv));
140
+ }
141
+
142
+ async write(policy: Policy, keyInfo: KeyInfo): Promise<EncryptionInformation> {
143
+ const algorithm = this.cipher?.name;
144
+ if (!algorithm) {
145
+ // Hard coded as part of the cipher object. This should not be reachable.
146
+ throw new ConfigurationError('uninitialized cipher type');
147
+ }
148
+ const keyAccessObjects = await this.getKeyAccessObjects(policy, keyInfo);
149
+
150
+ // For now we're only concerned with a single (first) key access object
151
+ const policyForManifest = base64.encode(JSON.stringify(policy));
152
+
153
+ return {
154
+ type: 'split',
155
+ keyAccess: keyAccessObjects,
156
+ method: {
157
+ algorithm,
158
+ isStreamable: false,
159
+ iv: base64.encode(keyInfo.unwrappedKeyIvBinary.asString()),
160
+ },
161
+ integrityInformation: {
162
+ rootSignature: {
163
+ alg: 'HS256',
164
+ sig: '',
165
+ },
166
+ segmentHashAlg: 'GMAC',
167
+ segments: [],
168
+ },
169
+ policy: policyForManifest,
170
+ };
171
+ }
172
+ }
@@ -0,0 +1,8 @@
1
+ export * from './attribute-set.js';
2
+ export * from './encryption-information.js';
3
+ export * from './key-access.js';
4
+ export * from './manifest.js';
5
+ export * from './payload.js';
6
+ export * from './policy.js';
7
+ export * from './upsert-response.js';
8
+ export * from '../assertions.js';
@@ -0,0 +1,128 @@
1
+ import { Binary } from '../binary.js';
2
+ import { base64, hex } from '../../../src/encodings/index.js';
3
+ import * as cryptoService from '../crypto/index.js';
4
+ import { Policy } from './policy.js';
5
+
6
+ export type KeyAccessType = 'remote' | 'wrapped';
7
+
8
+ export function isRemote(keyAccessJSON: KeyAccess | KeyAccessObject): boolean {
9
+ return keyAccessJSON.type === 'remote';
10
+ }
11
+
12
+ export class Wrapped {
13
+ readonly type = 'wrapped';
14
+ keyAccessObject?: KeyAccessObject;
15
+
16
+ constructor(
17
+ public readonly url: string,
18
+ public readonly kid: string | undefined,
19
+ public readonly publicKey: string,
20
+ public readonly metadata: unknown,
21
+ public readonly sid: string
22
+ ) {}
23
+
24
+ async write(
25
+ policy: Policy,
26
+ keyBuffer: Uint8Array,
27
+ encryptedMetadataStr: string
28
+ ): Promise<KeyAccessObject> {
29
+ const policyStr = JSON.stringify(policy);
30
+ const unwrappedKeyBinary = Binary.fromArrayBuffer(keyBuffer.buffer);
31
+ const wrappedKeyBinary = await cryptoService.encryptWithPublicKey(
32
+ unwrappedKeyBinary,
33
+ this.publicKey
34
+ );
35
+
36
+ const policyBinding = await cryptoService.hmac(
37
+ hex.encodeArrayBuffer(keyBuffer),
38
+ base64.encode(policyStr)
39
+ );
40
+
41
+ this.keyAccessObject = {
42
+ type: 'wrapped',
43
+ url: this.url,
44
+ protocol: 'kas',
45
+ wrappedKey: base64.encode(wrappedKeyBinary.asString()),
46
+ encryptedMetadata: base64.encode(encryptedMetadataStr),
47
+ policyBinding: {
48
+ alg: 'HS256',
49
+ hash: base64.encode(policyBinding),
50
+ },
51
+ };
52
+ if (this.kid) {
53
+ this.keyAccessObject.kid = this.kid;
54
+ }
55
+ if (this.sid?.length) {
56
+ this.keyAccessObject.sid = this.sid;
57
+ }
58
+
59
+ return this.keyAccessObject;
60
+ }
61
+ }
62
+
63
+ export class Remote {
64
+ readonly type = 'remote';
65
+ keyAccessObject?: KeyAccessObject;
66
+ wrappedKey?: string;
67
+ policyBinding?: string;
68
+
69
+ constructor(
70
+ public readonly url: string,
71
+ public readonly kid: string | undefined,
72
+ public readonly publicKey: string,
73
+ public readonly metadata: unknown,
74
+ public readonly sid: string
75
+ ) {}
76
+
77
+ async write(
78
+ policy: Policy,
79
+ keyBuffer: Uint8Array,
80
+ encryptedMetadataStr: string
81
+ ): Promise<KeyAccessObject> {
82
+ const policyStr = JSON.stringify(policy);
83
+ const policyBinding = await cryptoService.hmac(
84
+ hex.encodeArrayBuffer(keyBuffer),
85
+ base64.encode(policyStr)
86
+ );
87
+ const unwrappedKeyBinary = Binary.fromArrayBuffer(keyBuffer.buffer);
88
+ const wrappedKeyBinary = await cryptoService.encryptWithPublicKey(
89
+ unwrappedKeyBinary,
90
+ this.publicKey
91
+ );
92
+
93
+ // this.wrappedKey = wrappedKeyBinary.asBuffer().toString('hex');
94
+ this.wrappedKey = base64.encode(wrappedKeyBinary.asString());
95
+
96
+ this.keyAccessObject = {
97
+ type: 'remote',
98
+ url: this.url,
99
+ protocol: 'kas',
100
+ wrappedKey: this.wrappedKey,
101
+ encryptedMetadata: base64.encode(encryptedMetadataStr),
102
+ policyBinding: {
103
+ alg: 'HS256',
104
+ hash: base64.encode(policyBinding),
105
+ },
106
+ };
107
+ if (this.kid) {
108
+ this.keyAccessObject.kid = this.kid;
109
+ }
110
+ return this.keyAccessObject;
111
+ }
112
+ }
113
+
114
+ export type KeyAccess = Remote | Wrapped;
115
+
116
+ export type KeyAccessObject = {
117
+ sid?: string;
118
+ type: KeyAccessType;
119
+ url: string;
120
+ kid?: string;
121
+ protocol: 'kas';
122
+ wrappedKey?: string;
123
+ policyBinding?: {
124
+ alg: string;
125
+ hash: string;
126
+ };
127
+ encryptedMetadata?: string;
128
+ };
@@ -0,0 +1,9 @@
1
+ import { type Assertion } from '../assertions.js';
2
+ import { type Payload } from './payload.js';
3
+ import { type EncryptionInformation } from './encryption-information.js';
4
+
5
+ export type Manifest = {
6
+ payload: Payload;
7
+ encryptionInformation: EncryptionInformation;
8
+ assertions: Assertion[];
9
+ };
@@ -0,0 +1,6 @@
1
+ export type Payload = {
2
+ type: string; // "reference";
3
+ url: string; // "0.payload"
4
+ protocol: string; // "zip"
5
+ isEncrypted: boolean; // true
6
+ };
@@ -0,0 +1,35 @@
1
+ import { ConfigurationError } from '../../../src/errors.js';
2
+ import { AttributeObject } from './attribute-set.js';
3
+
4
+ export const CURRENT_VERSION = '1.1.0';
5
+
6
+ export type PolicyBody = {
7
+ dataAttributes: AttributeObject[];
8
+ dissem: string[];
9
+ };
10
+
11
+ export type Policy = {
12
+ tdf_spec_version?: string;
13
+ uuid?: string;
14
+ body?: PolicyBody;
15
+ };
16
+
17
+ export function validatePolicyObject(policyMaybe: unknown): policyMaybe is Policy {
18
+ if (typeof policyMaybe !== 'object') {
19
+ throw new ConfigurationError(
20
+ `The given policy reference must be an object, not: ${policyMaybe}`
21
+ );
22
+ }
23
+ const policy = policyMaybe as Policy;
24
+ const missingFields = [];
25
+ if (!policy.uuid) missingFields.push('uuid');
26
+ if (!policy.body) missingFields.push('body', 'body.dissem');
27
+ if (policy.body && !policy.body.dissem) missingFields.push('body.dissem');
28
+
29
+ if (missingFields.length) {
30
+ throw new ConfigurationError(
31
+ `The given policy object requires the following properties: ${missingFields}`
32
+ );
33
+ }
34
+ return true;
35
+ }
@@ -0,0 +1,17 @@
1
+ export type ArtifactFinder = {
2
+ upload?: string;
3
+ // Download URL for the payload. This can be a direct link to the file (S3), or a proxy URL.
4
+ download: string;
5
+ key?: string;
6
+ bucket?: string;
7
+ };
8
+
9
+ export type UpsertResponse = {
10
+ uuid: string;
11
+ storageLinks: {
12
+ payload: ArtifactFinder & {
13
+ proxy?: boolean | string;
14
+ };
15
+ metadata?: ArtifactFinder;
16
+ };
17
+ }[][];