@tideorg/js 0.0.1

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 +59 -0
  103. package/dist/Cryptide/Signing/TideSignature.d.ts.map +1 -0
  104. package/dist/Cryptide/Signing/TideSignature.js +118 -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 +14 -0
  166. package/dist/Models/AuthRequest.d.ts.map +1 -0
  167. package/dist/Models/AuthRequest.js +48 -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 +244 -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,66 @@
1
+ import { Point } from "./Ed25519";
2
+ export declare function writeInt64LittleEndian(value: bigint): Uint8Array<ArrayBuffer>;
3
+ export declare function readInt64LittleEndian(bytes: Uint8Array): bigint;
4
+ export declare class AuthorizerPack {
5
+ AuthFlow: any;
6
+ Authorizer: any;
7
+ SignModels: any[];
8
+ constructor(data: Uint8Array);
9
+ }
10
+ export declare class GVRK_Pack {
11
+ GVRK: any;
12
+ Expiry: any;
13
+ constructor(data: Uint8Array);
14
+ encode(): Uint8Array<ArrayBuffer>;
15
+ }
16
+ export declare function CreateTideMemory(initialValue: Uint8Array, totalLength: number, version?: number): Uint8Array<ArrayBuffer>;
17
+ export declare function CreateTideMemoryFromArray(datas: Uint8Array[]): Uint8Array<ArrayBuffer>;
18
+ export declare function WriteValue(memory: Uint8Array, index: number, value: Uint8Array): void;
19
+ export declare function GetValue(a: Uint8Array, index: number): Uint8Array<ArrayBufferLike>;
20
+ export declare function TryGetValue(a: Uint8Array, index: number, returnObj: any): boolean;
21
+ export declare function DeserializeNetworkKey(data: string): Point;
22
+ export declare function EdPointToJWK(p: Point): Promise<string>;
23
+ export declare function DeserializeTIDE_KEY(key: string, prefix: string): bigint;
24
+ export declare function GetUID(str: string): Promise<string>;
25
+ export declare function BigIntToByteArray(num: bigint): Uint8Array;
26
+ export declare function BigIntFromByteArray(bytes: Uint8Array): bigint;
27
+ export declare function ConcatUint8Arrays(arrays: Uint8Array[]): Uint8Array<ArrayBuffer>;
28
+ export declare function XOR(array1: Uint8Array, array2: Uint8Array): Uint8Array<ArrayBuffer>;
29
+ export declare function PadRight(array: any[], length: number, padding?: any): any[];
30
+ export declare function StringToUint8Array(string: string): Uint8Array<ArrayBuffer>;
31
+ export declare function StringFromUint8Array(bytes: Uint8Array): string;
32
+ export declare class Byte {
33
+ bits: number[];
34
+ constructor();
35
+ /**
36
+ * Sets a bit at the start of the array (index 0)
37
+ */
38
+ setFirstBit(bit: number): void;
39
+ toUint8Array(): Uint8Array;
40
+ static fromUint8Array(uint8Array: Uint8Array): Byte;
41
+ /**
42
+ * Maximum number of 255
43
+ */
44
+ static fromNumber(number: number): Byte;
45
+ }
46
+ export declare function getBytesFromInt16(schemeInt: number): Uint8Array<ArrayBuffer>;
47
+ export declare function numberToUint8Array(num: number, len?: number): Uint8Array<ArrayBuffer>;
48
+ export declare function Uint8ArrayToNumber(byteArray: Uint8Array): number;
49
+ export declare function base64ToBase64Url(base64: string): string;
50
+ export declare function base64UrlToBase64(base64Url: string): string;
51
+ export declare function bitArrayToUint8Array(array: number[]): Uint8Array<ArrayBuffer>;
52
+ /**
53
+ * Works for .NET functions.
54
+ */
55
+ export declare function serializeBitArray(bitArray_p: number[]): Uint8Array<ArrayBuffer>;
56
+ export declare function bitArrayAND(bitarray1: (0 | 1)[], bitarray2: (0 | 1)[]): (0 | 1)[];
57
+ /**
58
+ * Works for .NET functions.
59
+ */
60
+ export declare function deserializeBitArray(byteArray: Uint8Array): any[];
61
+ export declare function uint8ArrayToBitArray(byteArray: Uint8Array): any[];
62
+ export declare function Hex2Bytes(string: string): Uint8Array;
63
+ export declare function Bytes2Hex(byteArray: Uint8Array): string;
64
+ export declare function bytesToBase64(bytes: Uint8Array): string;
65
+ export declare function base64ToBytes(str: string): Uint8Array;
66
+ //# sourceMappingURL=Serialization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Serialization.d.ts","sourceRoot":"","sources":["../../Cryptide/Serialization.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAO,KAAK,EAAE,MAAM,WAAW,CAAC;AAKvC,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,2BAcnD;AACD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,UAAU,UActD;AACD,qBAAa,cAAc;IAC1B,QAAQ,EAAE,GAAG,CAAC;IACd,UAAU,EAAE,GAAG,CAAC;IAChB,UAAU,EAAE,GAAG,EAAE,CAAC;gBACN,IAAI,EAAE,UAAU;CAkB5B;AACD,qBAAa,SAAS;IACrB,IAAI,EAAE,GAAG,CAAC;IACV,MAAM,EAAE,GAAG,CAAC;gBACA,IAAI,EAAE,UAAU;IAIzB,MAAM;CAGT;AACD,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,MAAU,2BAuBlG;AACD,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,UAAU,EAAE,2BAQ5D;AACD,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,QAsC9E;AACD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,+BA2CpD;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,WASvE;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,SAEjD;AAED,wBAAsB,YAAY,CAAC,CAAC,EAAE,KAAK,mBAQ1C;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAM9D;AAED,wBAAsB,MAAM,CAAC,GAAG,EAAE,MAAM,mBAEvC;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAEzD;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAE7D;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,EAAE,2BASrD;AAED,wBAAgB,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,2BASzD;AACD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,GAAO,SAKtE;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,2BAGhD;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,UAGrD;AAED,qBAAa,IAAI;IAChB,IAAI,EAAE,MAAM,EAAE,CAAM;;IAOpB;;OAEG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM;IAIpB,YAAY,IAAI,UAAU;IAY1B,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAOtD;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;CAWvC;AACD,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,2BAQlD;AACD,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,GAAE,MAAW,2BAoB/D;AACD,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,UAAU,UAUvD;AACD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,UAE/C;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,UAMlD;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,2BAanD;AACD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,2BAoBrD;AACD,wBAAgB,WAAW,CAAC,SAAS,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,aAErE;AACD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,UAAU,SAexD;AACD,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,UAAU,SAczD;AACD,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAiBpD;AAED,wBAAgB,SAAS,CAAC,SAAS,EAAE,UAAU,GAAG,MAAM,CAavD;AAoCD,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAoBvD;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAyBrD"}
@@ -0,0 +1,517 @@
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 { Ed25519PublicComponent } from "./Components/Schemes/Ed25519/Ed25519Components";
18
+ import { etc, Point } from "./Ed25519";
19
+ import { SHA256_Digest } from "./Hashing/Hash";
20
+ import { CreateVRKPackage } from "./TideMemoryObjects";
21
+ export function writeInt64LittleEndian(value) {
22
+ const INT64_MIN = -9223372036854775808n; // -2^63
23
+ const INT64_MAX = 9223372036854775807n; // 2^63 - 1
24
+ if (value < INT64_MIN || value > INT64_MAX) {
25
+ throw new RangeError("Value is out of range for a 64-bit signed integer.");
26
+ }
27
+ const bytes = new Uint8Array(8);
28
+ for (let i = 0; i < 8; i++) {
29
+ bytes[i] = Number((value >> BigInt(8 * i)) & 0xffn);
30
+ }
31
+ return bytes;
32
+ }
33
+ export function readInt64LittleEndian(bytes) {
34
+ if (bytes.length !== 8) {
35
+ throw new Error("Invalid byte array length. Expected 8 bytes.");
36
+ }
37
+ let value = 0n;
38
+ for (let i = 0; i < 8; i++) {
39
+ value |= BigInt(bytes[i]) << BigInt(8 * i);
40
+ }
41
+ // Interpret the value as a signed 64-bit integer
42
+ value = BigInt.asIntN(64, value);
43
+ return value;
44
+ }
45
+ export class AuthorizerPack {
46
+ constructor(data) {
47
+ // Cross-realm safe check
48
+ const d = data;
49
+ const isUint8Like = d && (d instanceof Uint8Array ||
50
+ (ArrayBuffer.isView(d) && d.constructor?.name === 'Uint8Array') ||
51
+ (typeof d === 'object' && typeof d.length === 'number' && d.buffer instanceof ArrayBuffer));
52
+ if (!isUint8Like)
53
+ throw Error("Data must be byte array");
54
+ this.AuthFlow = StringFromUint8Array(GetValue(data, 0));
55
+ this.Authorizer = new GVRK_Pack(GetValue(data, 1));
56
+ var c = true;
57
+ var i = 2;
58
+ this.SignModels = [];
59
+ while (c) {
60
+ try {
61
+ this.SignModels.push(StringFromUint8Array(GetValue(data, i)));
62
+ i++;
63
+ }
64
+ catch {
65
+ c = false;
66
+ }
67
+ }
68
+ }
69
+ }
70
+ export class GVRK_Pack {
71
+ constructor(data) {
72
+ this.GVRK = Ed25519PublicComponent.DeserializeComponent(GetValue(data, 0));
73
+ this.Expiry = readInt64LittleEndian(GetValue(data, 1)); // we do not allow vrks without expiry on enclave for now
74
+ }
75
+ encode() {
76
+ return CreateVRKPackage(this.GVRK, this.Expiry);
77
+ }
78
+ }
79
+ export function CreateTideMemory(initialValue, totalLength, version = 1) {
80
+ if (totalLength < initialValue.length + 4) {
81
+ throw new Error("Not enough space to allocate requested data. Make sure to request more space in totalLength than length of InitialValue plus 4 bytes for length.");
82
+ }
83
+ // Total buffer length is 4 (version) + totalLength
84
+ const bufferLength = 4 + totalLength;
85
+ const buffer = new Uint8Array(bufferLength);
86
+ const dataView = new DataView(buffer.buffer);
87
+ // Write version at position 0 (4 bytes)
88
+ dataView.setInt32(0, version, true); // true for little-endian
89
+ let dataLocationIndex = 4;
90
+ // Write data length of initialValue at position 4 (4 bytes)
91
+ dataView.setInt32(dataLocationIndex, initialValue.length, true);
92
+ dataLocationIndex += 4;
93
+ // Write initialValue starting from position 8
94
+ buffer.set(initialValue, dataLocationIndex);
95
+ return buffer;
96
+ }
97
+ export function CreateTideMemoryFromArray(datas) {
98
+ if (datas.length == 0)
99
+ return new Uint8Array();
100
+ const length = datas.reduce((sum, next) => sum + 4 + next.length, 0);
101
+ const mem = CreateTideMemory(datas[0], length);
102
+ for (let i = 1; i < datas.length; i++) {
103
+ WriteValue(mem, i, datas[i]);
104
+ }
105
+ return mem;
106
+ }
107
+ export function WriteValue(memory, index, value) {
108
+ if (index < 0)
109
+ throw new Error("Index cannot be less than 0");
110
+ if (index === 0)
111
+ throw new Error("Use CreateTideMemory to set value at index 0");
112
+ if (memory.length < 4 + value.length)
113
+ throw new Error("Could not write to memory. Memory too small for this value");
114
+ const dataView = new DataView(memory.buffer);
115
+ let dataLocationIndex = 4; // Start after the version number
116
+ // Navigate through existing data segments
117
+ for (let i = 0; i < index; i++) {
118
+ if (dataLocationIndex + 4 > memory.length) {
119
+ throw new RangeError("Index out of range.");
120
+ }
121
+ // Read data length at current position
122
+ const nextDataLength = dataView.getInt32(dataLocationIndex, true);
123
+ dataLocationIndex += 4;
124
+ dataLocationIndex += nextDataLength;
125
+ }
126
+ // Check if there's enough space to write the value
127
+ if (dataLocationIndex + 4 + value.length > memory.length) {
128
+ throw new RangeError("Not enough space to write value");
129
+ }
130
+ // Check if data has already been written to this index
131
+ const existingLength = dataView.getInt32(dataLocationIndex, true);
132
+ if (existingLength !== 0) {
133
+ throw new Error("Data has already been written to this index");
134
+ }
135
+ // Write data length of value at current position
136
+ dataView.setInt32(dataLocationIndex, value.length, true);
137
+ dataLocationIndex += 4;
138
+ // Write value starting from current position
139
+ memory.set(value, dataLocationIndex);
140
+ }
141
+ export function GetValue(a, index) {
142
+ if (!(a instanceof Uint8Array)) {
143
+ console.error('[GetValue] Invalid input type:', typeof a, 'value:', a);
144
+ throw new TypeError("Input must be a Uint8Array.");
145
+ }
146
+ const buffer = a;
147
+ if (buffer.length < 4) {
148
+ throw new Error("Insufficient data to read.");
149
+ }
150
+ // Create a DataView for reading integers in little-endian format
151
+ const dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
152
+ // Optional: Read the version if needed
153
+ // const version = dataView.getInt32(0, true);
154
+ let dataLocationIndex = 4;
155
+ for (let i = 0; i < index; i++) {
156
+ // Check if there's enough data to read the length of the next segment
157
+ if (dataLocationIndex + 4 > buffer.length) {
158
+ throw new RangeError("Index out of range.");
159
+ }
160
+ const nextDataLength = dataView.getInt32(dataLocationIndex, true);
161
+ dataLocationIndex += 4 + nextDataLength;
162
+ }
163
+ // Check if there's enough data to read the length of the final segment
164
+ if (dataLocationIndex + 4 > buffer.length) {
165
+ throw new RangeError("Index out of range.");
166
+ }
167
+ const finalDataLength = dataView.getInt32(dataLocationIndex, true);
168
+ dataLocationIndex += 4;
169
+ // Check if the final data segment is within bounds
170
+ if (dataLocationIndex + finalDataLength > buffer.length) {
171
+ throw new RangeError("Index out of range.");
172
+ }
173
+ return buffer.subarray(dataLocationIndex, dataLocationIndex + finalDataLength);
174
+ }
175
+ export function TryGetValue(a, index, returnObj) {
176
+ try {
177
+ returnObj["result"] = GetValue(a, index);
178
+ return true;
179
+ }
180
+ catch {
181
+ returnObj["result"] = null;
182
+ return false;
183
+ }
184
+ }
185
+ export function DeserializeNetworkKey(data) {
186
+ return Point.fromBytes(Hex2Bytes(data.toLowerCase()));
187
+ }
188
+ export async function EdPointToJWK(p) {
189
+ return JSON.stringify({
190
+ "kty": "OKP",
191
+ "kid": Bytes2Hex(await SHA256_Digest(p.toRawBytes())),
192
+ "alg": "EdDSA",
193
+ "crv": "Ed25519",
194
+ "x": base64ToBase64Url(p.toBase64())
195
+ });
196
+ }
197
+ export function DeserializeTIDE_KEY(key, prefix) {
198
+ const header = key.substring(0, 8);
199
+ const data = base64ToBytes(key.substring(8, key.length));
200
+ if (header != "tide" + prefix + "key")
201
+ throw Error("Unexpected header in deserialization");
202
+ if (data.length != 32)
203
+ throw Error("Unexpected key length in deserialization");
204
+ return BigIntFromByteArray(data);
205
+ }
206
+ export async function GetUID(str) {
207
+ return Bytes2Hex(await SHA256_Digest(str.toLowerCase()));
208
+ }
209
+ export function BigIntToByteArray(num) {
210
+ return etc.bigIntToBytes(num);
211
+ }
212
+ export function BigIntFromByteArray(bytes) {
213
+ return etc.bytesToBigInt(bytes);
214
+ }
215
+ export function ConcatUint8Arrays(arrays) {
216
+ const totalLength = arrays.reduce((sum, next) => next.length + sum, 0);
217
+ var newArray = new Uint8Array(totalLength);
218
+ var offset = 0;
219
+ arrays.forEach(item => {
220
+ newArray.set(item, offset);
221
+ offset += item.length;
222
+ });
223
+ return newArray;
224
+ }
225
+ export function XOR(array1, array2) {
226
+ if (array1.length !== array2.length) {
227
+ throw new Error('Arrays have different lengths, cannot XOR them.');
228
+ }
229
+ let result = new Uint8Array(array1.length);
230
+ for (let i = 0; i < array1.length; i++) {
231
+ result[i] = array1[i] ^ array2[i];
232
+ }
233
+ return result;
234
+ }
235
+ export function PadRight(array, length, padding = 0) {
236
+ while (array.length < length) {
237
+ array.push(padding);
238
+ }
239
+ return array;
240
+ }
241
+ export function StringToUint8Array(string) {
242
+ const enc = new TextEncoder();
243
+ return enc.encode(string);
244
+ }
245
+ export function StringFromUint8Array(bytes) {
246
+ const decoder = new TextDecoder('utf-8');
247
+ return decoder.decode(bytes);
248
+ }
249
+ export class Byte {
250
+ constructor() {
251
+ this.bits = [];
252
+ /**
253
+ * @type {number[]}
254
+ */
255
+ this.bits = []; // bits.length should never exceed 8 - hence a byte
256
+ }
257
+ /**
258
+ * Sets a bit at the start of the array (index 0)
259
+ */
260
+ setFirstBit(bit) {
261
+ const b = bit === 0 ? 0 : 1;
262
+ this.bits[0] = b;
263
+ }
264
+ toUint8Array() {
265
+ let number = 0;
266
+ for (let i = 0; i < 8; i++) {
267
+ number += this.bits[i] * Math.pow(2, 7 - i);
268
+ }
269
+ const byteArray = new Uint8Array(1); // only 1 byte needed
270
+ byteArray[0] = number & 255;
271
+ return byteArray;
272
+ }
273
+ static fromUint8Array(uint8Array) {
274
+ let bitArray = new Byte();
275
+ for (let i = 7; i >= 0; i--) {
276
+ bitArray.bits.push((uint8Array[0] >> i) & 1); // only get first byte of byte array
277
+ }
278
+ return bitArray;
279
+ }
280
+ /**
281
+ * Maximum number of 255
282
+ */
283
+ static fromNumber(number) {
284
+ if (number < 0 || number > 255) {
285
+ throw Error("Number must be between 0 and 255"); // Adjusted the range check
286
+ }
287
+ let byte = new Byte();
288
+ let binaryString = number.toString(2).padStart(8, '0'); // Pad the string to ensure 8 bits
289
+ for (let i = 0; i < 8; i++) {
290
+ byte.bits.push(binaryString[i] === '1' ? 1 : 0); // Corrected the condition
291
+ }
292
+ return byte;
293
+ }
294
+ }
295
+ export function getBytesFromInt16(schemeInt) {
296
+ // Create an ArrayBuffer with 2 bytes (16 bits)
297
+ const buffer = new ArrayBuffer(2);
298
+ const view = new DataView(buffer);
299
+ // Write the 16-bit integer to the buffer, little-endian
300
+ view.setInt16(0, schemeInt, true); // 'true' for little-endian, 'false' for big-endian
301
+ // Return the bytes as a Uint8Array
302
+ return new Uint8Array(buffer);
303
+ }
304
+ export function numberToUint8Array(num, len = -1) {
305
+ if (num < 0 || !Number.isInteger(num)) {
306
+ throw new Error('Number must be a non-negative integer.');
307
+ }
308
+ if (num === 0)
309
+ return new Uint8Array([0]);
310
+ let numberOfBytes = Math.ceil(Math.log2(num + 1) / 8);
311
+ let byteArray = new Uint8Array(numberOfBytes);
312
+ for (let i = 0; i < numberOfBytes; i++) {
313
+ byteArray[i] = (num >> (8 * i)) & 0xFF;
314
+ }
315
+ if (len == -1)
316
+ return byteArray;
317
+ else {
318
+ const offset = len - byteArray.length;
319
+ if (offset == 0)
320
+ return byteArray;
321
+ const padding = new Uint8Array(offset).fill(0);
322
+ return ConcatUint8Arrays([byteArray, padding]);
323
+ }
324
+ }
325
+ export function Uint8ArrayToNumber(byteArray) {
326
+ if (!(byteArray instanceof Uint8Array)) {
327
+ throw new Error('Input must be a Uint8Array.');
328
+ }
329
+ let num = 0;
330
+ for (let i = byteArray.length - 1; i >= 0; i--) {
331
+ num = (num << 8) | byteArray[i];
332
+ }
333
+ return num;
334
+ }
335
+ export function base64ToBase64Url(base64) {
336
+ return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
337
+ }
338
+ export function base64UrlToBase64(base64Url) {
339
+ let base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
340
+ while (base64.length % 4) {
341
+ base64 += '=';
342
+ }
343
+ return base64;
344
+ }
345
+ export function bitArrayToUint8Array(array) {
346
+ // Made without ChatGPT (but had some help)
347
+ const byteArray = new Uint8Array(Math.ceil(array.length / 8));
348
+ let bitCount = 0;
349
+ for (let i = 0; i < byteArray.length; i++) {
350
+ const currentByteLength = array.length - bitCount >= 8 ? 8 : array.length - bitCount;
351
+ for (let j = 0; j < currentByteLength; j++) {
352
+ byteArray[i] |= array[bitCount] << (currentByteLength - 1 - j);
353
+ bitCount++;
354
+ }
355
+ }
356
+ return byteArray;
357
+ }
358
+ /**
359
+ * Works for .NET functions.
360
+ */
361
+ export function serializeBitArray(bitArray_p) {
362
+ // If anyone does a deep dive into this function and notices the bits are reversed, blame .NET's BitArray class.
363
+ let bitArray = bitArray_p.slice();
364
+ // Ensure the bit array length is a multiple of 8 by padding if necessary
365
+ while (bitArray.length % 8 !== 0) {
366
+ bitArray.push(0);
367
+ }
368
+ const byteArray = new Uint8Array(bitArray.length / 8);
369
+ for (let byteIndex = 0; byteIndex < byteArray.length; byteIndex++) {
370
+ // For each byte, calculate its value from 8 bits, reversing the bit order
371
+ let byteValue = 0;
372
+ for (let bitPosition = 0; bitPosition < 8; bitPosition++) {
373
+ byteValue |= (bitArray[byteIndex * 8 + bitPosition] << bitPosition);
374
+ }
375
+ byteArray[byteIndex] = byteValue;
376
+ }
377
+ return byteArray;
378
+ }
379
+ export function bitArrayAND(bitarray1, bitarray2) {
380
+ return bitarray1.map((b, i) => b == 1 && bitarray2[i] == 1 ? 1 : 0);
381
+ }
382
+ /**
383
+ * Works for .NET functions.
384
+ */
385
+ export function deserializeBitArray(byteArray) {
386
+ const bitArray = [];
387
+ byteArray.forEach(byte => {
388
+ for (let bitPosition = 0; bitPosition < 8; bitPosition++) {
389
+ bitArray.push((byte >> bitPosition) & 1);
390
+ }
391
+ });
392
+ // Remove padding
393
+ while (bitArray.length > 0 && bitArray[bitArray.length - 1] === 0) {
394
+ bitArray.pop();
395
+ }
396
+ return bitArray;
397
+ }
398
+ export function uint8ArrayToBitArray(byteArray) {
399
+ // always produces a bitArray of length 20
400
+ const bitArray = [];
401
+ let count = 0;
402
+ for (let i = 0; i < byteArray.length; i++) {
403
+ for (let j = 7; j >= 0; j--) {
404
+ // Extract the j-th bit of the i-th byte.
405
+ const bit = (byteArray[i] >> j) & 1;
406
+ if (count < 16 || count > 19)
407
+ bitArray.push(bit); // exclude intermediate bits, always l=20!
408
+ count++;
409
+ }
410
+ }
411
+ return bitArray;
412
+ }
413
+ export function Hex2Bytes(string) {
414
+ const hexRegex = /^0x[0-9A-Fa-f]+$|^[0-9A-Fa-f]+$/;
415
+ if (!hexRegex.test(string))
416
+ throw Error("Invalid Hex");
417
+ const normal = string.length % 2 ? "0" + string : string; // Make even length
418
+ const bytes = new Uint8Array(normal.length / 2);
419
+ for (let index = 0; index < bytes.length; ++index) {
420
+ const c1 = normal.charCodeAt(index * 2);
421
+ const c2 = normal.charCodeAt(index * 2 + 1);
422
+ const n1 = c1 - (c1 < 58 ? 48 : (c1 < 97 ? 55 : 87));
423
+ const n2 = c2 - (c2 < 58 ? 48 : (c2 < 97 ? 55 : 87));
424
+ bytes[index] = n1 * 16 + n2;
425
+ }
426
+ return bytes;
427
+ }
428
+ export function Bytes2Hex(byteArray) {
429
+ const chars = new Uint8Array(byteArray.length * 2);
430
+ const alpha = 'a'.charCodeAt(0) - 10;
431
+ const digit = '0'.charCodeAt(0);
432
+ let p = 0;
433
+ for (let i = 0; i < byteArray.length; i++) {
434
+ let nibble = byteArray[i] >>> 4;
435
+ chars[p++] = nibble > 9 ? nibble + alpha : nibble + digit;
436
+ nibble = byteArray[i] & 0xF;
437
+ chars[p++] = nibble > 9 ? nibble + alpha : nibble + digit;
438
+ }
439
+ return String.fromCharCode.apply(null, Array.from(chars));
440
+ }
441
+ /**
442
+ * Credits to Egor Nepomnyaschih for the below code
443
+ * Link: https://gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727
444
+ */
445
+ const base64abc = [
446
+ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
447
+ "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
448
+ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
449
+ "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
450
+ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/"
451
+ ];
452
+ const base64codes = [
453
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
454
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
455
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63,
456
+ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, 255, 0, 255, 255,
457
+ 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
458
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 255, 255, 255, 255, 255,
459
+ 255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
460
+ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
461
+ ];
462
+ function getBase64Code(charCode) {
463
+ if (charCode >= base64codes.length) {
464
+ throw new Error("Unable to parse base64 string.");
465
+ }
466
+ const code = base64codes[charCode];
467
+ if (code === 255) {
468
+ throw new Error("Unable to parse base64 string.");
469
+ }
470
+ return code;
471
+ }
472
+ export function bytesToBase64(bytes) {
473
+ let result = '', i, l = bytes.length;
474
+ for (i = 2; i < l; i += 3) {
475
+ result += base64abc[bytes[i - 2] >> 2];
476
+ result += base64abc[((bytes[i - 2] & 0x03) << 4) | (bytes[i - 1] >> 4)];
477
+ result += base64abc[((bytes[i - 1] & 0x0F) << 2) | (bytes[i] >> 6)];
478
+ result += base64abc[bytes[i] & 0x3F];
479
+ }
480
+ if (i === l + 1) { // 1 octet yet to write
481
+ result += base64abc[bytes[i - 2] >> 2];
482
+ result += base64abc[(bytes[i - 2] & 0x03) << 4];
483
+ result += "==";
484
+ }
485
+ if (i === l) { // 2 octets yet to write
486
+ result += base64abc[bytes[i - 2] >> 2];
487
+ result += base64abc[((bytes[i - 2] & 0x03) << 4) | (bytes[i - 1] >> 4)];
488
+ result += base64abc[(bytes[i - 1] & 0x0F) << 2];
489
+ result += "=";
490
+ }
491
+ return result;
492
+ }
493
+ export function base64ToBytes(str) {
494
+ const base64Regex = /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/;
495
+ if (!base64Regex.test(str))
496
+ throw Error("Not valid base64");
497
+ if (str.length % 4 !== 0) {
498
+ throw new Error("Unable to parse base64 string.");
499
+ }
500
+ const index = str.indexOf("=");
501
+ if (index !== -1 && index < str.length - 2) {
502
+ throw new Error("Unable to parse base64 string.");
503
+ }
504
+ let missingOctets = str.endsWith("==") ? 2 : str.endsWith("=") ? 1 : 0, n = str.length, result = new Uint8Array(3 * (n / 4)), buffer;
505
+ for (let i = 0, j = 0; i < n; i += 4, j += 3) {
506
+ buffer =
507
+ getBase64Code(str.charCodeAt(i)) << 18 |
508
+ getBase64Code(str.charCodeAt(i + 1)) << 12 |
509
+ getBase64Code(str.charCodeAt(i + 2)) << 6 |
510
+ getBase64Code(str.charCodeAt(i + 3));
511
+ result[j] = buffer >> 16;
512
+ result[j + 1] = (buffer >> 8) & 0xFF;
513
+ result[j + 2] = buffer & 0xFF;
514
+ }
515
+ return result.subarray(0, result.length - missingOctets);
516
+ }
517
+ // Custom extensions
@@ -0,0 +1,10 @@
1
+ import { Point } from "../Ed25519";
2
+ export declare function genBlindMessage(gR: Point, pub: Point, message: Uint8Array, multiplier: bigint): Promise<{
3
+ blurHCMKMul: bigint;
4
+ blur: bigint;
5
+ gRMul: Point;
6
+ }>;
7
+ export declare function unblindSignature(blindS: bigint, blur: bigint): Promise<bigint>;
8
+ export declare function verifyBlindSignature(S: bigint, noncePublic: Point, pub: Point, message: Uint8Array): Promise<boolean>;
9
+ export declare function serializeBlindSig(S: bigint, noncePublic: Point): Uint8Array<ArrayBuffer>;
10
+ //# sourceMappingURL=BlindSig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BlindSig.d.ts","sourceRoot":"","sources":["../../../Cryptide/Signing/BlindSig.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAInC,wBAAsB,eAAe,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM;;;;GAOnG;AACD,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,mBAGlE;AAED,wBAAsB,oBAAoB,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,oBAOxG;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,2BAE9D"}
@@ -0,0 +1,41 @@
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 { RandomBigInt, mod, mod_inv } from "../Math";
18
+ import { SHA512_Digest } from "../Hashing/Hash";
19
+ import { BigIntFromByteArray, BigIntToByteArray, ConcatUint8Arrays, bytesToBase64 } from "../Serialization";
20
+ import * as EdDSA from "./EdDSA";
21
+ export async function genBlindMessage(gR, pub, message, multiplier) {
22
+ const blur = RandomBigInt();
23
+ const gRMul = gR.mul(mod_inv(blur));
24
+ const eddsaH = mod(BigIntFromByteArray(await SHA512_Digest(ConcatUint8Arrays([gRMul.toRawBytes(), pub.toRawBytes(), message]))));
25
+ const blurHCMKMul = mod(eddsaH * multiplier * blur);
26
+ return { blurHCMKMul, blur, gRMul };
27
+ }
28
+ export async function unblindSignature(blindS, blur) {
29
+ const s = mod(blindS * mod_inv(blur));
30
+ return s;
31
+ }
32
+ export async function verifyBlindSignature(S, noncePublic, pub, message) {
33
+ const valid = await EdDSA.verifyRaw(S, noncePublic, pub, message);
34
+ if (!valid) {
35
+ console.error(`Signature failed. \nM: ${bytesToBase64(message)}\nS: ${S.toString()}\nNoncePublic: ${noncePublic.toBase64()}\nPublic: ${pub.toBase64()}`);
36
+ }
37
+ return valid;
38
+ }
39
+ export function serializeBlindSig(S, noncePublic) {
40
+ return ConcatUint8Arrays([BigIntToByteArray(S), noncePublic.toRawBytes()]);
41
+ }
@@ -0,0 +1,14 @@
1
+ import { Point } from "../Ed25519";
2
+ /**
3
+ * Sign the msg with a private key in non-standard way as it uses a random number generator. Non-deterministic.
4
+ */
5
+ export declare function sign(msg: string | Uint8Array, priv: bigint): Promise<string>;
6
+ /**
7
+ * Verify a EdDSA signature, given a signature, public key and message.
8
+ */
9
+ export declare function verify(sig: string, pub: string | Point, msg: string | Uint8Array): Promise<boolean>;
10
+ /**
11
+ * Verify a message with raw S and R
12
+ */
13
+ export declare function verifyRaw(S: bigint, R: Point, A: Point, M: Uint8Array): Promise<boolean>;
14
+ //# sourceMappingURL=EdDSA.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EdDSA.d.ts","sourceRoot":"","sources":["../../../Cryptide/Signing/EdDSA.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,KAAK,EAAS,MAAM,YAAY,CAAC;AAM1C;;GAEG;AACH,wBAAsB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,EAAE,IAAI,EAAE,MAAM,mBAehE;AAED;;GAEG;AACH,wBAAsB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,KAAK,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU,oBAiBtF;AAED;;GAEG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,UAAU,oBAQ3E"}