@tideorg/js 0.13.19

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 (234) hide show
  1. package/LICENSE +333 -0
  2. package/README.md +12 -0
  3. package/dist/Clients/ClientBase.d.ts +24 -0
  4. package/dist/Clients/ClientBase.d.ts.map +1 -0
  5. package/dist/Clients/ClientBase.js +160 -0
  6. package/dist/Clients/NetworkClient.d.ts +11 -0
  7. package/dist/Clients/NetworkClient.d.ts.map +1 -0
  8. package/dist/Clients/NetworkClient.js +68 -0
  9. package/dist/Clients/NodeClient.d.ts +34 -0
  10. package/dist/Clients/NodeClient.d.ts.map +1 -0
  11. package/dist/Clients/NodeClient.js +191 -0
  12. package/dist/Clients/VoucherClient.d.ts +8 -0
  13. package/dist/Clients/VoucherClient.d.ts.map +1 -0
  14. package/dist/Clients/VoucherClient.js +36 -0
  15. package/dist/Clients/index.d.ts +5 -0
  16. package/dist/Clients/index.d.ts.map +1 -0
  17. package/dist/Clients/index.js +20 -0
  18. package/dist/Contracts/BaseContract.d.ts +47 -0
  19. package/dist/Contracts/BaseContract.d.ts.map +1 -0
  20. package/dist/Contracts/BaseContract.js +153 -0
  21. package/dist/Contracts/GenericRealmAccessThresholdRoleContract.d.ts +8 -0
  22. package/dist/Contracts/GenericRealmAccessThresholdRoleContract.d.ts.map +1 -0
  23. package/dist/Contracts/GenericRealmAccessThresholdRoleContract.js +21 -0
  24. package/dist/Contracts/GenericResourceAccessThresholdRoleContract.d.ts +8 -0
  25. package/dist/Contracts/GenericResourceAccessThresholdRoleContract.d.ts.map +1 -0
  26. package/dist/Contracts/GenericResourceAccessThresholdRoleContract.js +21 -0
  27. package/dist/Contracts/index.d.ts +4 -0
  28. package/dist/Contracts/index.d.ts.map +1 -0
  29. package/dist/Contracts/index.js +19 -0
  30. package/dist/Cryptide/Components/BaseComponent.d.ts +56 -0
  31. package/dist/Cryptide/Components/BaseComponent.d.ts.map +1 -0
  32. package/dist/Cryptide/Components/BaseComponent.js +176 -0
  33. package/dist/Cryptide/Components/ComponentRegistry.d.ts +18 -0
  34. package/dist/Cryptide/Components/ComponentRegistry.d.ts.map +1 -0
  35. package/dist/Cryptide/Components/ComponentRegistry.js +39 -0
  36. package/dist/Cryptide/Components/Schemes/AES/AESScheme.d.ts +5 -0
  37. package/dist/Cryptide/Components/Schemes/AES/AESScheme.d.ts.map +1 -0
  38. package/dist/Cryptide/Components/Schemes/AES/AESScheme.js +20 -0
  39. package/dist/Cryptide/Components/Schemes/AES/index.d.ts +2 -0
  40. package/dist/Cryptide/Components/Schemes/AES/index.d.ts.map +1 -0
  41. package/dist/Cryptide/Components/Schemes/AES/index.js +17 -0
  42. package/dist/Cryptide/Components/Schemes/BaseScheme.d.ts +7 -0
  43. package/dist/Cryptide/Components/Schemes/BaseScheme.d.ts.map +1 -0
  44. package/dist/Cryptide/Components/Schemes/BaseScheme.js +23 -0
  45. package/dist/Cryptide/Components/Schemes/Ed25519/Ed25519Components.d.ts +52 -0
  46. package/dist/Cryptide/Components/Schemes/Ed25519/Ed25519Components.d.ts.map +1 -0
  47. package/dist/Cryptide/Components/Schemes/Ed25519/Ed25519Components.js +171 -0
  48. package/dist/Cryptide/Components/Schemes/Ed25519/Ed25519Scheme.d.ts +13 -0
  49. package/dist/Cryptide/Components/Schemes/Ed25519/Ed25519Scheme.d.ts.map +1 -0
  50. package/dist/Cryptide/Components/Schemes/Ed25519/Ed25519Scheme.js +71 -0
  51. package/dist/Cryptide/Components/Schemes/Ed25519/index.d.ts +3 -0
  52. package/dist/Cryptide/Components/Schemes/Ed25519/index.d.ts.map +1 -0
  53. package/dist/Cryptide/Components/Schemes/Ed25519/index.js +18 -0
  54. package/dist/Cryptide/Components/Schemes/SchemeRegistry.d.ts +3 -0
  55. package/dist/Cryptide/Components/Schemes/SchemeRegistry.d.ts.map +1 -0
  56. package/dist/Cryptide/Components/Schemes/SchemeRegistry.js +22 -0
  57. package/dist/Cryptide/Components/Schemes/index.d.ts +5 -0
  58. package/dist/Cryptide/Components/Schemes/index.d.ts.map +1 -0
  59. package/dist/Cryptide/Components/Schemes/index.js +20 -0
  60. package/dist/Cryptide/Components/index.d.ts +4 -0
  61. package/dist/Cryptide/Components/index.d.ts.map +1 -0
  62. package/dist/Cryptide/Components/index.js +19 -0
  63. package/dist/Cryptide/Ed25519.d.ts +106 -0
  64. package/dist/Cryptide/Ed25519.d.ts.map +1 -0
  65. package/dist/Cryptide/Ed25519.js +522 -0
  66. package/dist/Cryptide/Encryption/AES.d.ts +6 -0
  67. package/dist/Cryptide/Encryption/AES.d.ts.map +1 -0
  68. package/dist/Cryptide/Encryption/AES.js +76 -0
  69. package/dist/Cryptide/Encryption/DH.d.ts +4 -0
  70. package/dist/Cryptide/Encryption/DH.d.ts.map +1 -0
  71. package/dist/Cryptide/Encryption/DH.js +38 -0
  72. package/dist/Cryptide/Encryption/ElGamal.d.ts +12 -0
  73. package/dist/Cryptide/Encryption/ElGamal.d.ts.map +1 -0
  74. package/dist/Cryptide/Encryption/ElGamal.js +61 -0
  75. package/dist/Cryptide/Encryption/index.d.ts +4 -0
  76. package/dist/Cryptide/Encryption/index.d.ts.map +1 -0
  77. package/dist/Cryptide/Encryption/index.js +19 -0
  78. package/dist/Cryptide/Hashing/H2P.d.ts +6 -0
  79. package/dist/Cryptide/Hashing/H2P.d.ts.map +1 -0
  80. package/dist/Cryptide/Hashing/H2P.js +235 -0
  81. package/dist/Cryptide/Hashing/Hash.d.ts +8 -0
  82. package/dist/Cryptide/Hashing/Hash.d.ts.map +1 -0
  83. package/dist/Cryptide/Hashing/Hash.js +43 -0
  84. package/dist/Cryptide/Hashing/index.d.ts +3 -0
  85. package/dist/Cryptide/Hashing/index.d.ts.map +1 -0
  86. package/dist/Cryptide/Hashing/index.js +18 -0
  87. package/dist/Cryptide/Interpolation.d.ts +20 -0
  88. package/dist/Cryptide/Interpolation.d.ts.map +1 -0
  89. package/dist/Cryptide/Interpolation.js +68 -0
  90. package/dist/Cryptide/Math.d.ts +11 -0
  91. package/dist/Cryptide/Math.d.ts.map +1 -0
  92. package/dist/Cryptide/Math.js +81 -0
  93. package/dist/Cryptide/Serialization.d.ts +66 -0
  94. package/dist/Cryptide/Serialization.d.ts.map +1 -0
  95. package/dist/Cryptide/Serialization.js +517 -0
  96. package/dist/Cryptide/Signing/BlindSig.d.ts +10 -0
  97. package/dist/Cryptide/Signing/BlindSig.d.ts.map +1 -0
  98. package/dist/Cryptide/Signing/BlindSig.js +41 -0
  99. package/dist/Cryptide/Signing/EdDSA.d.ts +14 -0
  100. package/dist/Cryptide/Signing/EdDSA.d.ts.map +1 -0
  101. package/dist/Cryptide/Signing/EdDSA.js +67 -0
  102. package/dist/Cryptide/Signing/TideSignature.d.ts +54 -0
  103. package/dist/Cryptide/Signing/TideSignature.d.ts.map +1 -0
  104. package/dist/Cryptide/Signing/TideSignature.js +110 -0
  105. package/dist/Cryptide/Signing/index.d.ts +4 -0
  106. package/dist/Cryptide/Signing/index.d.ts.map +1 -0
  107. package/dist/Cryptide/Signing/index.js +19 -0
  108. package/dist/Cryptide/TideKey.d.ts +17 -0
  109. package/dist/Cryptide/TideKey.d.ts.map +1 -0
  110. package/dist/Cryptide/TideKey.js +84 -0
  111. package/dist/Cryptide/TideMemoryObjects.d.ts +4 -0
  112. package/dist/Cryptide/TideMemoryObjects.d.ts.map +1 -0
  113. package/dist/Cryptide/TideMemoryObjects.js +32 -0
  114. package/dist/Cryptide/index.d.ts +11 -0
  115. package/dist/Cryptide/index.d.ts.map +1 -0
  116. package/dist/Cryptide/index.js +28 -0
  117. package/dist/Flow/DecryptionFlows/dVVKDecryptionFlow.d.ts +16 -0
  118. package/dist/Flow/DecryptionFlows/dVVKDecryptionFlow.d.ts.map +1 -0
  119. package/dist/Flow/DecryptionFlows/dVVKDecryptionFlow.js +47 -0
  120. package/dist/Flow/DecryptionFlows/index.d.ts +2 -0
  121. package/dist/Flow/DecryptionFlows/index.d.ts.map +1 -0
  122. package/dist/Flow/DecryptionFlows/index.js +17 -0
  123. package/dist/Flow/EncryptionFlows/AuthorizedEncryptionFlow.d.ts +13 -0
  124. package/dist/Flow/EncryptionFlows/AuthorizedEncryptionFlow.d.ts.map +1 -0
  125. package/dist/Flow/EncryptionFlows/AuthorizedEncryptionFlow.js +183 -0
  126. package/dist/Flow/EncryptionFlows/PolicyAuthorizedEncryptionFlow.d.ts +57 -0
  127. package/dist/Flow/EncryptionFlows/PolicyAuthorizedEncryptionFlow.d.ts.map +1 -0
  128. package/dist/Flow/EncryptionFlows/PolicyAuthorizedEncryptionFlow.js +220 -0
  129. package/dist/Flow/EncryptionFlows/index.d.ts +3 -0
  130. package/dist/Flow/EncryptionFlows/index.d.ts.map +1 -0
  131. package/dist/Flow/EncryptionFlows/index.js +18 -0
  132. package/dist/Flow/SigningFlows/AuthorizedSigningFlow.d.ts +12 -0
  133. package/dist/Flow/SigningFlows/AuthorizedSigningFlow.d.ts.map +1 -0
  134. package/dist/Flow/SigningFlows/AuthorizedSigningFlow.js +50 -0
  135. package/dist/Flow/SigningFlows/dTestVVkSigningFlow.d.ts +15 -0
  136. package/dist/Flow/SigningFlows/dTestVVkSigningFlow.d.ts.map +1 -0
  137. package/dist/Flow/SigningFlows/dTestVVkSigningFlow.js +67 -0
  138. package/dist/Flow/SigningFlows/dVVKSigningFlow.d.ts +17 -0
  139. package/dist/Flow/SigningFlows/dVVKSigningFlow.d.ts.map +1 -0
  140. package/dist/Flow/SigningFlows/dVVKSigningFlow.js +61 -0
  141. package/dist/Flow/SigningFlows/dVVKSigningFlow2Step.d.ts +28 -0
  142. package/dist/Flow/SigningFlows/dVVKSigningFlow2Step.d.ts.map +1 -0
  143. package/dist/Flow/SigningFlows/dVVKSigningFlow2Step.js +118 -0
  144. package/dist/Flow/SigningFlows/index.d.ts +5 -0
  145. package/dist/Flow/SigningFlows/index.d.ts.map +1 -0
  146. package/dist/Flow/SigningFlows/index.js +20 -0
  147. package/dist/Flow/VoucherFlows/VoucherFlow.d.ts +16 -0
  148. package/dist/Flow/VoucherFlows/VoucherFlow.d.ts.map +1 -0
  149. package/dist/Flow/VoucherFlows/VoucherFlow.js +34 -0
  150. package/dist/Flow/VoucherFlows/index.d.ts +2 -0
  151. package/dist/Flow/VoucherFlows/index.d.ts.map +1 -0
  152. package/dist/Flow/VoucherFlows/index.js +17 -0
  153. package/dist/Flow/index.d.ts +5 -0
  154. package/dist/Flow/index.d.ts.map +1 -0
  155. package/dist/Flow/index.js +20 -0
  156. package/dist/Math/KeyDecryption.d.ts +3 -0
  157. package/dist/Math/KeyDecryption.d.ts.map +1 -0
  158. package/dist/Math/KeyDecryption.js +24 -0
  159. package/dist/Math/KeySigning.d.ts +4 -0
  160. package/dist/Math/KeySigning.d.ts.map +1 -0
  161. package/dist/Math/KeySigning.js +28 -0
  162. package/dist/Math/index.d.ts +3 -0
  163. package/dist/Math/index.d.ts.map +1 -0
  164. package/dist/Math/index.js +18 -0
  165. package/dist/Models/AuthRequest.d.ts +13 -0
  166. package/dist/Models/AuthRequest.d.ts.map +1 -0
  167. package/dist/Models/AuthRequest.js +46 -0
  168. package/dist/Models/BaseTideRequest.d.ts +55 -0
  169. package/dist/Models/BaseTideRequest.d.ts.map +1 -0
  170. package/dist/Models/BaseTideRequest.js +299 -0
  171. package/dist/Models/CustomTideRequest.d.ts +19 -0
  172. package/dist/Models/CustomTideRequest.d.ts.map +1 -0
  173. package/dist/Models/CustomTideRequest.js +30 -0
  174. package/dist/Models/Datum.d.ts +11 -0
  175. package/dist/Models/Datum.d.ts.map +1 -0
  176. package/dist/Models/Datum.js +33 -0
  177. package/dist/Models/Doken.d.ts +33 -0
  178. package/dist/Models/Doken.d.ts.map +1 -0
  179. package/dist/Models/Doken.js +133 -0
  180. package/dist/Models/EnclaveEntry.d.ts +14 -0
  181. package/dist/Models/EnclaveEntry.d.ts.map +1 -0
  182. package/dist/Models/EnclaveEntry.js +49 -0
  183. package/dist/Models/Infos/KeyInfo.d.ts +24 -0
  184. package/dist/Models/Infos/KeyInfo.d.ts.map +1 -0
  185. package/dist/Models/Infos/KeyInfo.js +51 -0
  186. package/dist/Models/Infos/OrkInfo.d.ts +18 -0
  187. package/dist/Models/Infos/OrkInfo.d.ts.map +1 -0
  188. package/dist/Models/Infos/OrkInfo.js +58 -0
  189. package/dist/Models/Infos/index.d.ts +3 -0
  190. package/dist/Models/Infos/index.d.ts.map +1 -0
  191. package/dist/Models/Infos/index.js +18 -0
  192. package/dist/Models/ModelRegistry.d.ts +29 -0
  193. package/dist/Models/ModelRegistry.d.ts.map +1 -0
  194. package/dist/Models/ModelRegistry.js +321 -0
  195. package/dist/Models/Policy.d.ts +41 -0
  196. package/dist/Models/Policy.d.ts.map +1 -0
  197. package/dist/Models/Policy.js +317 -0
  198. package/dist/Models/PolicyProtectedSerializedField.d.ts +12 -0
  199. package/dist/Models/PolicyProtectedSerializedField.d.ts.map +1 -0
  200. package/dist/Models/PolicyProtectedSerializedField.js +50 -0
  201. package/dist/Models/Responses/Vendor/VoucherResponse.d.ts +12 -0
  202. package/dist/Models/Responses/Vendor/VoucherResponse.d.ts.map +1 -0
  203. package/dist/Models/Responses/Vendor/VoucherResponse.js +39 -0
  204. package/dist/Models/Responses/Vendor/index.d.ts +2 -0
  205. package/dist/Models/Responses/Vendor/index.d.ts.map +1 -0
  206. package/dist/Models/Responses/Vendor/index.js +17 -0
  207. package/dist/Models/Responses/index.d.ts +2 -0
  208. package/dist/Models/Responses/index.d.ts.map +1 -0
  209. package/dist/Models/Responses/index.js +17 -0
  210. package/dist/Models/SerializedField.d.ts +12 -0
  211. package/dist/Models/SerializedField.d.ts.map +1 -0
  212. package/dist/Models/SerializedField.js +50 -0
  213. package/dist/Models/VendorData.d.ts +12 -0
  214. package/dist/Models/VendorData.d.ts.map +1 -0
  215. package/dist/Models/VendorData.js +38 -0
  216. package/dist/Models/VendorSettings.d.ts +9 -0
  217. package/dist/Models/VendorSettings.d.ts.map +1 -0
  218. package/dist/Models/VendorSettings.js +32 -0
  219. package/dist/Models/index.d.ts +13 -0
  220. package/dist/Models/index.d.ts.map +1 -0
  221. package/dist/Models/index.js +30 -0
  222. package/dist/Tools/TideMemory.d.ts +10 -0
  223. package/dist/Tools/TideMemory.d.ts.map +1 -0
  224. package/dist/Tools/TideMemory.js +105 -0
  225. package/dist/Tools/Utils.d.ts +13 -0
  226. package/dist/Tools/Utils.d.ts.map +1 -0
  227. package/dist/Tools/Utils.js +242 -0
  228. package/dist/Tools/index.d.ts +3 -0
  229. package/dist/Tools/index.d.ts.map +1 -0
  230. package/dist/Tools/index.js +18 -0
  231. package/dist/index.d.ts +10 -0
  232. package/dist/index.d.ts.map +1 -0
  233. package/dist/index.js +26 -0
  234. package/package.json +27 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ElGamal.d.ts","sourceRoot":"","sources":["../../../Cryptide/Encryption/ElGamal.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAQnC,MAAM,CAAC,OAAO,OAAO,OAAO;WACX,WAAW,CAAC,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK;WAIpD,cAAc,CAAC,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK;WAOvD,iCAAiC,CAAC,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU;;;;WAW/F,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,UAAU;WAWxD,cAAc,CAAC,YAAY,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,GAAG,UAAU;CAS/E"}
@@ -0,0 +1,61 @@
1
+ //
2
+ // Tide Protocol - Infrastructure for a TRUE Zero-Trust paradigm
3
+ // Copyright (C) 2022 Tide Foundation Ltd
4
+ //
5
+ // This program is free software and is subject to the terms of
6
+ // the Tide Community Open Code License as published by the
7
+ // Tide Foundation Limited. You may modify it and redistribute
8
+ // it in accordance with and subject to the terms of that License.
9
+ // This program is distributed WITHOUT WARRANTY of any kind,
10
+ // including without any implied warranty of MERCHANTABILITY or
11
+ // FITNESS FOR A PARTICULAR PURPOSE.
12
+ // See the Tide Community Open Code License for more details.
13
+ // You should have received a copy of the Tide Community Open
14
+ // Code License along with this program.
15
+ // If not, see https://tide.org/licenses_tcoc2-0-0-en
16
+ //
17
+ import { Point } from "../Ed25519";
18
+ import { RandomBigInt } from "../Math";
19
+ import { encryptDataRawOutput, decryptDataRawOutput } from "./AES";
20
+ import { SHA256_Digest } from "../Hashing/Hash";
21
+ import { BigIntFromByteArray, ConcatUint8Arrays, base64ToBytes, bytesToBase64 } from "../Serialization";
22
+ import TideKey from "../TideKey";
23
+ import { Ed25519PrivateComponent } from "../Components/Schemes/Ed25519";
24
+ export default class ElGamal {
25
+ static async encryptData(secretData, publicKey) {
26
+ return bytesToBase64(await this.encryptDataRaw(secretData, publicKey));
27
+ }
28
+ static async encryptDataRaw(secretData, publicKey) {
29
+ const r = RandomBigInt();
30
+ const c1 = Point.BASE.mul(r).toRawBytes();
31
+ const c2 = await encryptDataRawOutput(secretData, await SHA256_Digest(publicKey.mul(r).toRawBytes()));
32
+ return ConcatUint8Arrays([c1, c2]);
33
+ }
34
+ static async encryptDataRaw_withAuthentication(secretData, publicKey, authMsg) {
35
+ const r = RandomBigInt();
36
+ const c1 = Point.BASE.mul(r).toRawBytes();
37
+ const c2 = await encryptDataRawOutput(secretData, await SHA256_Digest(publicKey.mul(r).toRawBytes()));
38
+ const authSig = await (new TideKey(new Ed25519PrivateComponent(r)).sign(authMsg));
39
+ return {
40
+ cipher: ConcatUint8Arrays([c1, c2]),
41
+ auth: authSig
42
+ };
43
+ }
44
+ static async decryptData(base64_c1_c2, k) {
45
+ const priv = typeof (k) == 'bigint' ? k : BigIntFromByteArray(k);
46
+ const b = base64ToBytes(base64_c1_c2);
47
+ const c1 = b.slice(0, 32);
48
+ const c2 = b.slice(32);
49
+ const c1Point = Point.fromBytes(c1);
50
+ const decrypted = await decryptDataRawOutput(c2, await SHA256_Digest(c1Point.mul(priv).toRawBytes()));
51
+ return decrypted;
52
+ }
53
+ static async decryptDataRaw(base64_c1_c2, k) {
54
+ const priv = typeof (k) == 'bigint' ? k : BigIntFromByteArray(k);
55
+ const c1 = base64_c1_c2.slice(0, 32);
56
+ const c2 = base64_c1_c2.slice(32);
57
+ const c1Point = Point.fromBytes(c1);
58
+ const decrypted = await decryptDataRawOutput(c2, await SHA256_Digest(c1Point.mul(priv).toRawBytes()));
59
+ return decrypted;
60
+ }
61
+ }
@@ -0,0 +1,4 @@
1
+ export { default as ElGamal } from './ElGamal';
2
+ export * as AES from './AES';
3
+ export * as DH from './DH';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../Cryptide/Encryption/index.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,MAAM,CAAC"}
@@ -0,0 +1,19 @@
1
+ //
2
+ // Tide Protocol - Infrastructure for a TRUE Zero-Trust paradigm
3
+ // Copyright (C) 2022 Tide Foundation Ltd
4
+ //
5
+ // This program is free software and is subject to the terms of
6
+ // the Tide Community Open Code License as published by the
7
+ // Tide Foundation Limited. You may modify it and redistribute
8
+ // it in accordance with and subject to the terms of that License.
9
+ // This program is distributed WITHOUT WARRANTY of any kind,
10
+ // including without any implied warranty of MERCHANTABILITY or
11
+ // FITNESS FOR A PARTICULAR PURPOSE.
12
+ // See the Tide Community Open Code License for more details.
13
+ // You should have received a copy of the Tide Community Open
14
+ // Code License along with this program.
15
+ // If not, see https://tide.org/licenses_tcoc2-0-0-en
16
+ //
17
+ export { default as ElGamal } from './ElGamal';
18
+ export * as AES from './AES';
19
+ export * as DH from './DH';
@@ -0,0 +1,6 @@
1
+ import { Point } from "../Ed25519";
2
+ /**
3
+ * Hashes a msg to a point on the ed25519 curve.
4
+ */
5
+ export default function HashToPoint(msg: string | Uint8Array): Promise<Point>;
6
+ //# sourceMappingURL=H2P.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"H2P.d.ts","sourceRoot":"","sources":["../../../Cryptide/Hashing/H2P.ts"],"names":[],"mappings":"AAyCA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAmLnC;;GAEG;AACH,wBAA8B,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,CASlF"}
@@ -0,0 +1,235 @@
1
+ //
2
+ // Tide Protocol - Infrastructure for a TRUE Zero-Trust paradigm
3
+ // Copyright (C) 2022 Tide Foundation Ltd
4
+ //
5
+ // This program is free software and is subject to the terms of
6
+ // the Tide Community Open Code License as published by the
7
+ // Tide Foundation Limited. You may modify it and redistribute
8
+ // it in accordance with and subject to the terms of that License.
9
+ // This program is distributed WITHOUT WARRANTY of any kind,
10
+ // including without any implied warranty of MERCHANTABILITY or
11
+ // FITNESS FOR A PARTICULAR PURPOSE.
12
+ // See the Tide Community Open Code License for more details.
13
+ // You should have received a copy of the Tide Community Open
14
+ // Code License along with this program.
15
+ // If not, see https://tide.org/licenses_tcoc2-0-0-en
16
+ //
17
+ // Some parts of the code were taken from @noble/curves project and are protected under the following license:
18
+ //
19
+ // The MIT License (MIT)
20
+ //
21
+ // Copyright (c) 2022 Paul Miller (https://paulmillr.com)
22
+ //
23
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
24
+ // of this software and associated documentation files (the "Software"), to deal
25
+ // in the Software without restriction, including without limitation the rights
26
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27
+ // copies of the Software, and to permit persons to whom the Software is
28
+ // furnished to do so, subject to the following conditions:
29
+ //
30
+ // The above copyright notice and this permission notice shall be included in
31
+ // all copies or substantial portions of the Software.
32
+ //
33
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
39
+ // THE SOFTWARE.
40
+ //
41
+ import { Point } from "../Ed25519";
42
+ import { ConcatUint8Arrays, BigIntFromByteArray } from "../Serialization";
43
+ import { mod, mod_inv } from "../Math";
44
+ import { SHA512_Digest } from "./Hash";
45
+ const curveP = BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949");
46
+ const _0n = BigInt(0), _1n = BigInt(1), _2n = BigInt(2);
47
+ function Fp_FpInvertBatch(nums) {
48
+ const tmp = new Array(nums.length);
49
+ // Walk from first to last, multiply them by each other MOD p
50
+ const lastMultiplied = nums.reduce((acc, num, i) => {
51
+ if (num === _0n)
52
+ return acc;
53
+ tmp[i] = acc;
54
+ return multiply_nums(acc, num);
55
+ }, _1n);
56
+ // Invert last element
57
+ const inverted = mod_inv(lastMultiplied, curveP);
58
+ // Walk from last to first, multiply them by inverted each other MOD p
59
+ nums.reduceRight((acc, num, i) => {
60
+ if (num === _0n)
61
+ return acc;
62
+ tmp[i] = multiply_nums(acc, tmp[i]);
63
+ return multiply_nums(acc, num);
64
+ }, inverted);
65
+ return tmp;
66
+ }
67
+ ;
68
+ //functions from field
69
+ function cmov(a, b, c) { return (c ? b : a); }
70
+ ; //returns b if c is true and returns a if c is false
71
+ function add_nums(num1, num2, modulus = curveP) { return mod(num1 + num2, modulus); }
72
+ ; //adds 2 numbers together then uses mod to ensure that they are not greater than the curveP value
73
+ function multiply_nums(num1, num2, modulus = curveP) { return mod(BigInt(num1 * num2), modulus); }
74
+ ; //multiplies numbers then reduces them below curveP
75
+ function to_the_power_of(number, power, modulus = curveP) {
76
+ if (power < _0n)
77
+ throw new Error('Expected power > 0');
78
+ if (power === _0n)
79
+ return _1n;
80
+ if (power === _1n)
81
+ return number;
82
+ let p = _1n;
83
+ let d = number;
84
+ while (power > _0n) {
85
+ if (power & _1n)
86
+ p = multiply_nums(p, d, modulus);
87
+ d = multiply_nums(d, d, modulus);
88
+ power >>= _1n;
89
+ }
90
+ ;
91
+ return p;
92
+ }
93
+ ; // raises a number to a certain power while keeping values below curveP
94
+ //constants used in the map_to_curve functions
95
+ const ELL2_C1_EDWARDS = BigInt('6853475219497561581579357271197624642482790079785650197046958215289687604742'); //hard coded as the field only has one value in this case Fp = Field(ED25519_P, undefined, true); ELL2_C1_EDWARDS = FpSqrtEven(Fp, Fp.neg(BigInt(486664))); // sgn0(c1) MUST equal 0
96
+ const ELL2_C1 = (curveP + BigInt(3)) / BigInt(8); // 1. c1 = (q + 3) / 8 # Integer arithmetic
97
+ const ELL2_C2 = to_the_power_of(_2n, ELL2_C1); // 2. c2 = 2^c1
98
+ const ELL2_C3 = BigInt('38214883241950591754978413199355411911188925816896391856984770930832735035197'); //hard coded sqrt value of ELL2_C3 = Fp.sqrt(Fp.neg(Fp.ONE)); // 3. c3 = sqrt(-1)
99
+ const ELL2_C4 = (curveP - BigInt(5)) / BigInt(8); // 4. c4 = (q - 5) / 8 # Integer arithmetic
100
+ const ELL2_J = BigInt(486662);
101
+ function map_to_curve_elligator2_curve25519_(u) {
102
+ let tv1 = multiply_nums(u, u); // 1. tv1 = u^2
103
+ tv1 = multiply_nums(tv1, _2n); // 2. tv1 = 2 * tv1
104
+ let xd = add_nums(tv1, _1n); // 3. xd = tv1 + 1 # Nonzero: -1 is square (mod p), tv1 is not
105
+ let x1n = -ELL2_J; // 4. x1n = -J # x1 = x1n / xd = -J / (1 + 2 * u^2)
106
+ let tv2 = multiply_nums(xd, xd); // 5. tv2 = xd^2
107
+ let gxd = multiply_nums(tv2, xd); // 6. gxd = tv2 * xd # gxd = xd^3
108
+ let gx1 = multiply_nums(tv1, ELL2_J); // 7. gx1 = J * tv1 # x1n + J * xd
109
+ gx1 = multiply_nums(gx1, x1n); // 8. gx1 = gx1 * x1n # x1n^2 + J * x1n * xd
110
+ gx1 = add_nums(gx1, tv2); // 9. gx1 = gx1 + tv2 # x1n^2 + J * x1n * xd + xd^2
111
+ gx1 = multiply_nums(gx1, x1n); // 10. gx1 = gx1 * x1n # x1n^3 + J * x1n^2 * xd + x1n * xd^2
112
+ let tv3 = multiply_nums(gxd, gxd); // 11. tv3 = gxd^2
113
+ tv2 = multiply_nums(tv3, tv3); // 12. tv2 = tv3^2 # gxd^4
114
+ tv3 = multiply_nums(tv3, gxd); // 13. tv3 = tv3 * gxd # gxd^3
115
+ tv3 = multiply_nums(tv3, gx1); // 14. tv3 = tv3 * gx1 # gx1 * gxd^3
116
+ tv2 = multiply_nums(tv2, tv3); // 15. tv2 = tv2 * tv3 # gx1 * gxd^7
117
+ let y11 = to_the_power_of(tv2, ELL2_C4); // 16. y11 = tv2^c4 # (gx1 * gxd^7)^((p - 5) / 8)
118
+ y11 = multiply_nums(y11, tv3); // 17. y11 = y11 * tv3 # gx1*gxd^3*(gx1*gxd^7)^((p-5)/8)
119
+ let y12 = multiply_nums(y11, ELL2_C3); // 18. y12 = y11 * c3
120
+ tv2 = multiply_nums(y11, y11); // 19. tv2 = y11^2
121
+ tv2 = multiply_nums(tv2, gxd); // 20. tv2 = tv2 * gxd
122
+ let e1 = (tv2 === gx1); // 21. e1 = tv2 == gx1
123
+ let y1 = cmov(y12, y11, e1); // 22. y1 = CMOV(y12, y11, e1) # If g(x1) is square, this is its sqrt
124
+ let x2n = multiply_nums(x1n, tv1); // 23. x2n = x1n * tv1 # x2 = x2n / xd = 2 * u^2 * x1n / xd
125
+ let y21 = multiply_nums(y11, u); // 24. y21 = y11 * u
126
+ y21 = multiply_nums(y21, ELL2_C2); // 25. y21 = y21 * c2
127
+ let y22 = multiply_nums(y21, ELL2_C3); // 26. y22 = y21 * c3
128
+ let gx2 = multiply_nums(gx1, tv1); // 27. gx2 = gx1 * tv1 # g(x2) = gx2 / gxd = 2 * u^2 * g(x1)
129
+ tv2 = multiply_nums(y21, y21); // 28. tv2 = y21^2
130
+ tv2 = multiply_nums(tv2, gxd); // 29. tv2 = tv2 * gxd
131
+ let e2 = (tv2 === gx2); // 30. e2 = tv2 == gx2
132
+ let y2 = cmov(y22, y21, e2); // 31. y2 = CMOV(y22, y21, e2) # If g(x2) is square, this is its sqrt
133
+ tv2 = multiply_nums(y1, y1); // 32. tv2 = y1^2
134
+ tv2 = multiply_nums(tv2, gxd); // 33. tv2 = tv2 * gxd
135
+ let e3 = (tv2 === gx1); // 34. e3 = tv2 == gx1
136
+ let xn = cmov(x2n, x1n, e3); // 35. xn = CMOV(x2n, x1n, e3) # If e3, x = x1, else x = x2
137
+ let y = cmov(y2, y1, e3); // 36. y = CMOV(y2, y1, e3) # If e3, y = y1, else y = y2
138
+ let e4 = ((y & _1n) === _1n); // 37. e4 = sgn0(y) == 1 # Fix sign of y
139
+ y = cmov(y, -y, e3 !== e4); // 38. y = CMOV(y, -y, e3 XOR e4)
140
+ return { xMn: xn, xMd: xd, yMn: y, yMd: _1n }; // 39. return (xn, xd, y, 1)
141
+ }
142
+ function map_to_curve_elligator2_edwards25519_(u) {
143
+ const { xMn, xMd, yMn, yMd } = map_to_curve_elligator2_curve25519_(u); // 1. (xMn, xMd, yMn, yMd) =
144
+ // map_to_curve_elligator2_curve25519(u)
145
+ let xn = multiply_nums(xMn, yMd); // 2. xn = xMn * yMd
146
+ xn = multiply_nums(xn, ELL2_C1_EDWARDS); // 3. xn = xn * c1
147
+ let xd = multiply_nums(xMd, yMn); // 4. xd = xMd * yMn # xn / xd = c1 * xM / yM
148
+ let yn = mod(xMn - xMd, curveP); // 5. yn = xMn - xMd
149
+ let yd = add_nums(xMn, xMd); // 6. yd = xMn + xMd # (n / d - 1) / (n / d + 1) = (n - d) / (n + d)
150
+ let tv1 = multiply_nums(xd, yd); // 7. tv1 = xd * yd
151
+ let e = (tv1 === _0n); // 8. e = tv1 == 0
152
+ xn = cmov(xn, _0n, e); // 9. xn = CMOV(xn, 0, e)
153
+ xd = cmov(xd, _1n, e); // 10. xd = CMOV(xd, 1, e)
154
+ yn = cmov(yn, _1n, e); // 11. yn = CMOV(yn, 1, e)
155
+ yd = cmov(yd, _1n, e); // 12. yd = CMOV(yd, 1, e)
156
+ const inv = Fp_FpInvertBatch([xd, yd]); // batch division
157
+ return { x: multiply_nums(xn, inv[0]), y: multiply_nums(yn, inv[1]) }; // 13. return (xn, xd, yn, yd)
158
+ }
159
+ function i2osp(value, length) {
160
+ if (value < 0 || value >= 1 << (8 * length)) {
161
+ throw new Error(`bad I2OSP call: value=${value} length=${length}`);
162
+ }
163
+ const res = Array.from({ length }).fill(0);
164
+ for (let i = length - 1; i >= 0; i--) {
165
+ res[i] = value & 0xff;
166
+ value >>>= 8;
167
+ }
168
+ return new Uint8Array(res);
169
+ } //takes a value and a length, an array is created with that length. Then takes the smallest 8 bits from the value and places it at the end of the array.
170
+ //Repeats this with the next 8 bits and places them in the next last value in the array for the rest of the value
171
+ function strxor(a, b) {
172
+ const arr = new Uint8Array(a.length);
173
+ for (let i = 0; i < a.length; i++) {
174
+ arr[i] = a[i] ^ b[i];
175
+ }
176
+ return arr;
177
+ }
178
+ ; //does bitwise xor on all values in 2 arrays and returns a new array with the results
179
+ async function expand_message_xmd(msg, DST, len_in_bytes) {
180
+ const b_in_bytes = 64;
181
+ const r_in_bytes = 128;
182
+ const ell = Math.ceil(len_in_bytes / b_in_bytes);
183
+ if (ell > 255)
184
+ throw new Error('Invalid xmd length');
185
+ const DST_prime = ConcatUint8Arrays([DST, i2osp(DST.length, 1)]);
186
+ const Z_pad = i2osp(0, r_in_bytes);
187
+ const len_in_bytes_str = i2osp(len_in_bytes, 2);
188
+ const b = new Array(ell);
189
+ const arr = ConcatUint8Arrays([Z_pad, msg, len_in_bytes_str, i2osp(0, 1), DST_prime]);
190
+ const b_0 = await SHA512_Digest(arr);
191
+ const promise_b = SHA512_Digest((ConcatUint8Arrays([b_0, i2osp(1, 1), DST_prime])));
192
+ b[0] = await promise_b;
193
+ for (let i = 1; i <= ell; i++) {
194
+ const args = [strxor(b_0, b[i - 1]), i2osp(i + 1, 1), DST_prime];
195
+ b[i] = await SHA512_Digest(ConcatUint8Arrays(args));
196
+ }
197
+ const pseudo_random_bytes = ConcatUint8Arrays(b);
198
+ return pseudo_random_bytes.slice(0, len_in_bytes);
199
+ }
200
+ ; //a message and a DST that are encoded into Uint8arrays are hashed into a certain number of values according to len_in_bytes
201
+ async function hashtofield(msg) {
202
+ const _DST = 'QUUX-V01-CS02-with-edwards25519_XMD:SHA-512_ELL2_RO_', m = 1, count = 2, k = 128, p = BigInt('57896044618658097711785492504343953926634992332820282019728792003956564819949');
203
+ const DST = new TextEncoder().encode(_DST);
204
+ const log2p = p.toString(2).length;
205
+ const L = Math.ceil((log2p + k) / 8);
206
+ const len_in_bytes = count * m * L;
207
+ let prb = await expand_message_xmd(msg, DST, len_in_bytes);
208
+ const u = new Array(count);
209
+ for (let i = 0; i < count; i++) {
210
+ const e = new Array(m);
211
+ for (let j = 0; j < m; j++) {
212
+ const elm_offset = L * (j + i * m);
213
+ const tv = prb.subarray(elm_offset, elm_offset + L);
214
+ e[j] = mod(BigIntFromByteArray(tv.reverse()), p);
215
+ }
216
+ u[i] = e;
217
+ }
218
+ return u;
219
+ }
220
+ ; //takes in a message hashes it with expand_message_xmd and splits the resulting value into 2 parts
221
+ /**
222
+ * Hashes a msg to a point on the ed25519 curve.
223
+ */
224
+ export default async function HashToPoint(msg) {
225
+ const arr = typeof (msg) === 'string' ? new TextEncoder().encode(msg) : msg;
226
+ const u = await hashtofield(arr);
227
+ const x0y0 = map_to_curve_elligator2_edwards25519_(u[0][0]);
228
+ const x1y1 = map_to_curve_elligator2_edwards25519_(u[1][0]);
229
+ const p0 = Point.fromAffine(x0y0);
230
+ const p1 = Point.fromAffine(x1y1);
231
+ const P = p0.add(p1).clearCofactor();
232
+ return P;
233
+ }
234
+ ; //hashtofield takes an Uint8array encoded message and gives back 2 values. the map_to_curve function then uses those values to generate 2 x and y values
235
+ // 2 Points are created using the x and y values. The points are added to each other and then are muliplied by 8 to give the final point.
@@ -0,0 +1,8 @@
1
+ import { Point } from "../Ed25519";
2
+ export declare function SHA256_Digest(message: string | Uint8Array): Promise<Uint8Array<ArrayBuffer>>;
3
+ export declare function SHA512_Digest(message: string | Uint8Array): Promise<Uint8Array<ArrayBuffer>>;
4
+ /**
5
+ * DO NOT USE THIS TO SIGN. THE KEY IS THE HASH OF THE FIRST MESSAGE PASSED. THIS FUNCTION IS FOR HASHING MULTIPLE MESSAGES.
6
+ */
7
+ export declare function HMAC_forHashing(message: string, pub: Point): Promise<Uint8Array<ArrayBuffer>>;
8
+ //# sourceMappingURL=Hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Hash.d.ts","sourceRoot":"","sources":["../../../Cryptide/Hashing/Hash.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,oCAK/D;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,oCAK/D;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,oCAehE"}
@@ -0,0 +1,43 @@
1
+ //
2
+ // Tide Protocol - Infrastructure for a TRUE Zero-Trust paradigm
3
+ // Copyright (C) 2022 Tide Foundation Ltd
4
+ //
5
+ // This program is free software and is subject to the terms of
6
+ // the Tide Community Open Code License as published by the
7
+ // Tide Foundation Limited. You may modify it and redistribute
8
+ // it in accordance with and subject to the terms of that License.
9
+ // This program is distributed WITHOUT WARRANTY of any kind,
10
+ // including without any implied warranty of MERCHANTABILITY or
11
+ // FITNESS FOR A PARTICULAR PURPOSE.
12
+ // See the Tide Community Open Code License for more details.
13
+ // You should have received a copy of the Tide Community Open
14
+ // Code License along with this program.
15
+ // If not, see https://tide.org/licenses_tcoc2-0-0-en
16
+ //
17
+ export async function SHA256_Digest(message) {
18
+ const data = typeof (message) === 'string' ? new TextEncoder().encode(message) : message;
19
+ const hash = await crypto.subtle.digest('SHA-256', data);
20
+ return new Uint8Array(hash);
21
+ }
22
+ export async function SHA512_Digest(message) {
23
+ const data = typeof (message) === 'string' ? new TextEncoder().encode(message) : message;
24
+ const hash = await crypto.subtle.digest('SHA-512', data);
25
+ return new Uint8Array(hash);
26
+ }
27
+ /**
28
+ * DO NOT USE THIS TO SIGN. THE KEY IS THE HASH OF THE FIRST MESSAGE PASSED. THIS FUNCTION IS FOR HASHING MULTIPLE MESSAGES.
29
+ */
30
+ export async function HMAC_forHashing(message, pub) {
31
+ const tx = new TextEncoder();
32
+ const key = await SHA256_Digest(tx.encode(message));
33
+ const cryptoKey = await crypto.subtle.importKey('raw', // raw format for Uint8Array input
34
+ key, // the Uint8Array key data
35
+ {
36
+ name: 'HMAC',
37
+ hash: { name: 'SHA-256' }, // specifying the hash algorithm to use with HMAC
38
+ }, false, // whether the key is extractable
39
+ ['sign'] // allowed key usages
40
+ );
41
+ const hash = await window.crypto.subtle.sign("HMAC", cryptoKey, pub.toRawBytes());
42
+ return new Uint8Array(hash);
43
+ }
@@ -0,0 +1,3 @@
1
+ export * as Hash from './Hash';
2
+ export { default as HashToPoint } from './H2P';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../Cryptide/Hashing/index.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,OAAO,CAAC"}
@@ -0,0 +1,18 @@
1
+ //
2
+ // Tide Protocol - Infrastructure for a TRUE Zero-Trust paradigm
3
+ // Copyright (C) 2022 Tide Foundation Ltd
4
+ //
5
+ // This program is free software and is subject to the terms of
6
+ // the Tide Community Open Code License as published by the
7
+ // Tide Foundation Limited. You may modify it and redistribute
8
+ // it in accordance with and subject to the terms of that License.
9
+ // This program is distributed WITHOUT WARRANTY of any kind,
10
+ // including without any implied warranty of MERCHANTABILITY or
11
+ // FITNESS FOR A PARTICULAR PURPOSE.
12
+ // See the Tide Community Open Code License for more details.
13
+ // You should have received a copy of the Tide Community Open
14
+ // Code License along with this program.
15
+ // If not, see https://tide.org/licenses_tcoc2-0-0-en
16
+ //
17
+ export * as Hash from './Hash';
18
+ export { default as HashToPoint } from './H2P';
@@ -0,0 +1,20 @@
1
+ import { Point } from "./Ed25519";
2
+ import { Ed25519PublicComponent } from "./Components/Schemes/Ed25519/Ed25519Components";
3
+ export declare function GetLi(xi: bigint, xs: bigint[], m?: bigint): bigint;
4
+ export declare function GetLis(ids: bigint[]): bigint[];
5
+ export declare function AggregatePoints(points: Point[]): Point;
6
+ export declare function AggregatePublicComponents(points: Ed25519PublicComponent[]): Ed25519PublicComponent;
7
+ export declare function AggregatePublicComponentArrays(pointArrays: Ed25519PublicComponent[][]): Ed25519PublicComponent[];
8
+ /**
9
+ * Will aggregate all points at corresponding indexes. E.g. all points from each array at index 0 will be summed.
10
+ */
11
+ export declare function AggregatePointArrays(pointArrays: Point[][]): Point[];
12
+ /**
13
+ * Will aggregate all points and multiply by corresponding li of id.
14
+ */
15
+ export declare function AggregatePointsWithIds(points: Point[], ids: bigint[]): Point;
16
+ /**
17
+ * Will aggregate all points and multiply by corresponding li.
18
+ */
19
+ export declare function AggregatePointsWithLis(points: Point[], lis: bigint[]): Point;
20
+ //# sourceMappingURL=Interpolation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Interpolation.d.ts","sourceRoot":"","sources":["../../Cryptide/Interpolation.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,KAAK,EAAS,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,gDAAgD,CAAC;AAExF,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,GAAE,MAAgB,GAAG,MAAM,CAK3E;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,YAEnC;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,SAG9C;AACD,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,sBAAsB,EAAE,0BAGzE;AAED,wBAAgB,8BAA8B,CAAC,WAAW,EAAE,sBAAsB,EAAE,EAAE,4BAIrF;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,KAAK,EAAE,EAAE,WAI1D;AACD;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,KAAK,CAG5E;AACD;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,KAAK,CAE5E"}
@@ -0,0 +1,68 @@
1
+ //
2
+ // Tide Protocol - Infrastructure for a TRUE Zero-Trust paradigm
3
+ // Copyright (C) 2022 Tide Foundation Ltd
4
+ //
5
+ // This program is free software and is subject to the terms of
6
+ // the Tide Community Open Code License as published by the
7
+ // Tide Foundation Limited. You may modify it and redistribute
8
+ // it in accordance with and subject to the terms of that License.
9
+ // This program is distributed WITHOUT WARRANTY of any kind,
10
+ // including without any implied warranty of MERCHANTABILITY or
11
+ // FITNESS FOR A PARTICULAR PURPOSE.
12
+ // See the Tide Community Open Code License for more details.
13
+ // You should have received a copy of the Tide Community Open
14
+ // Code License along with this program.
15
+ // If not, see https://tide.org/licenses_tcoc2-0-0-en
16
+ //
17
+ import { mod, mod_inv } from "./Math";
18
+ import { Point, CURVE } from "./Ed25519";
19
+ import { Ed25519PublicComponent } from "./Components/Schemes/Ed25519/Ed25519Components";
20
+ export function GetLi(xi, xs, m = CURVE.n) {
21
+ var li = xs.filter(xj => xj != xi)
22
+ .map(xj => mod(mod_inv(xj - xi, m) * xj), m)
23
+ .reduce((li, num) => mod(li * num, m));
24
+ return li;
25
+ }
26
+ export function GetLis(ids) {
27
+ return ids.map(id => GetLi(id, ids, CURVE.n));
28
+ }
29
+ export function AggregatePoints(points) {
30
+ if (points.every(p => p == null))
31
+ return null;
32
+ else
33
+ return points.reduce((sum, next) => next == null ? sum : sum.add(next), Point.ZERO);
34
+ }
35
+ export function AggregatePublicComponents(points) {
36
+ if (points.every(p => p == null))
37
+ return null;
38
+ else
39
+ return points.reduce((sum, next) => next == null ? sum : sum.AddComponent(next), new Ed25519PublicComponent(Point.ZERO));
40
+ }
41
+ export function AggregatePublicComponentArrays(pointArrays) {
42
+ const arrayDepth = pointArrays[0].length;
43
+ if (!pointArrays.every(array => array.length == arrayDepth))
44
+ throw Error("Inconsistent amount of array depths");
45
+ return pointArrays[0].map((_, i) => AggregatePublicComponents(pointArrays.map(array => array[i])));
46
+ }
47
+ /**
48
+ * Will aggregate all points at corresponding indexes. E.g. all points from each array at index 0 will be summed.
49
+ */
50
+ export function AggregatePointArrays(pointArrays) {
51
+ const arrayDepth = pointArrays[0].length;
52
+ if (!pointArrays.every(array => array.length == arrayDepth))
53
+ throw Error("Inconsistent amount of array depths");
54
+ return pointArrays[0].map((_, i) => AggregatePoints(pointArrays.map(array => array[i])));
55
+ }
56
+ /**
57
+ * Will aggregate all points and multiply by corresponding li of id.
58
+ */
59
+ export function AggregatePointsWithIds(points, ids) {
60
+ const lis = GetLis(ids);
61
+ return AggregatePoints(points.map((p, i) => p.mul(lis[i])));
62
+ }
63
+ /**
64
+ * Will aggregate all points and multiply by corresponding li.
65
+ */
66
+ export function AggregatePointsWithLis(points, lis) {
67
+ return AggregatePoints(points.map((p, i) => p.mul(lis[i])));
68
+ }
@@ -0,0 +1,11 @@
1
+ import { Point } from "./Ed25519";
2
+ export declare function mod(a: bigint, b?: bigint): bigint;
3
+ export declare function median(numbers: bigint[]): any;
4
+ export declare function RandomBigInt(): bigint;
5
+ export declare function GenSessKey(): Uint8Array<ArrayBufferLike>;
6
+ export declare function CreateGPrismAuth(gPassPRISM: Point): Promise<Point>;
7
+ export declare function GetPublic(a: bigint | Uint8Array): Point;
8
+ export declare function Min(arr: number[]): number;
9
+ export declare function mod_inv(number: bigint, modulo?: bigint): bigint;
10
+ export declare function SumPoints(points: Point[]): Point;
11
+ //# sourceMappingURL=Math.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Math.d.ts","sourceRoot":"","sources":["../../Cryptide/Math.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAS,KAAK,EAAE,MAAM,WAAW,CAAC;AAUzC,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAE,MAAgB,GAAG,MAAM,CAG1D;AAED,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,OASvC;AAED,wBAAgB,YAAY,IAAI,MAAM,CAIrC;AAED,wBAAgB,UAAU,gCAEzB;AACD,wBAAsB,gBAAgB,CAAC,UAAU,EAAE,KAAK,kBAEvD;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,UAAU,SAG/C;AAED,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,UAShC;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,MAAgB,GAAG,MAAM,CAmBxE;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,SAExC"}
@@ -0,0 +1,81 @@
1
+ //
2
+ // Tide Protocol - Infrastructure for a TRUE Zero-Trust paradigm
3
+ // Copyright (C) 2022 Tide Foundation Ltd
4
+ //
5
+ // This program is free software and is subject to the terms of
6
+ // the Tide Community Open Code License as published by the
7
+ // Tide Foundation Limited. You may modify it and redistribute
8
+ // it in accordance with and subject to the terms of that License.
9
+ // This program is distributed WITHOUT WARRANTY of any kind,
10
+ // including without any implied warranty of MERCHANTABILITY or
11
+ // FITNESS FOR A PARTICULAR PURPOSE.
12
+ // See the Tide Community Open Code License for more details.
13
+ // You should have received a copy of the Tide Community Open
14
+ // Code License along with this program.
15
+ // If not, see https://tide.org/licenses_tcoc2-0-0-en
16
+ //
17
+ import { CURVE, Point } from "./Ed25519";
18
+ import { BigIntFromByteArray, BigIntToByteArray } from "../Cryptide/Serialization";
19
+ const _0n = BigInt(0);
20
+ const _1n = BigInt(1);
21
+ const _2n = BigInt(2);
22
+ export function mod(a, b = CURVE.n) {
23
+ var res = a % b;
24
+ return res >= BigInt(0) ? res : b + res;
25
+ }
26
+ export function median(numbers) {
27
+ const sorted = Array.from(numbers).sort();
28
+ const middle = Math.floor(sorted.length / 2);
29
+ if (sorted.length % 2 === 0) {
30
+ return ((sorted[middle - 1] + (sorted[middle])) / _2n);
31
+ }
32
+ return sorted[middle];
33
+ }
34
+ export function RandomBigInt() {
35
+ const buf = new Uint8Array(32);
36
+ window.crypto.getRandomValues(buf);
37
+ return mod(BigIntFromByteArray(buf), CURVE.n);
38
+ }
39
+ export function GenSessKey() {
40
+ return BigIntToByteArray(RandomBigInt());
41
+ }
42
+ export async function CreateGPrismAuth(gPassPRISM) {
43
+ return Point.BASE.mul(await gPassPRISM.hash());
44
+ }
45
+ export function GetPublic(a) {
46
+ let num = typeof (a) == 'bigint' ? a : BigIntFromByteArray(a);
47
+ return Point.BASE.mul(num);
48
+ }
49
+ export function Min(arr) {
50
+ let minValue = arr[0]; // Initialize with the first element
51
+ for (let i = 1; i < arr.length; i++) {
52
+ if (arr[i] < minValue) {
53
+ minValue = arr[i];
54
+ }
55
+ }
56
+ return minValue;
57
+ }
58
+ export function mod_inv(number, modulo = CURVE.n) {
59
+ if (number === _0n || modulo <= _0n) {
60
+ throw new Error(`invert: expected positive integers, got n=${number} mod=${modulo}`);
61
+ }
62
+ let a = mod(number, modulo);
63
+ let b = modulo;
64
+ // prettier-ignore
65
+ let x = _0n, y = _1n, u = _1n, v = _0n;
66
+ while (a !== _0n) {
67
+ const q = b / a;
68
+ const r = b % a;
69
+ const m = x - u * q;
70
+ const n = y - v * q;
71
+ // prettier-ignore
72
+ b = a, a = r, x = u, y = v, u = m, v = n;
73
+ }
74
+ const gcd = b;
75
+ if (gcd !== _1n)
76
+ throw new Error('invert: does not exist');
77
+ return mod(x, modulo);
78
+ }
79
+ export function SumPoints(points) {
80
+ return points.reduce((sum, next) => sum.add(next));
81
+ }