index.d.ts 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. type Message = string | number[] | ArrayBuffer | Uint8Array;
  2. interface Hasher {
  3. /**
  4. * Update hash
  5. *
  6. * @param message The message you want to hash.
  7. */
  8. update(message: Message): Hasher;
  9. /**
  10. * Return hash in hex string.
  11. */
  12. hex(): string;
  13. /**
  14. * Return hash in hex string.
  15. */
  16. toString(): string;
  17. /**
  18. * Return hash in ArrayBuffer.
  19. */
  20. arrayBuffer(): ArrayBuffer;
  21. /**
  22. * Return hash in integer array.
  23. */
  24. digest(): number[];
  25. /**
  26. * Return hash in integer array.
  27. */
  28. array(): number[];
  29. }
  30. interface Hash {
  31. /**
  32. * Hash and return hex string.
  33. *
  34. * @param message The message you want to hash.
  35. */
  36. (message: Message): string;
  37. /**
  38. * Hash and return hex string.
  39. *
  40. * @param message The message you want to hash.
  41. */
  42. hex(message: Message): string;
  43. /**
  44. * Hash and return ArrayBuffer.
  45. *
  46. * @param message The message you want to hash.
  47. */
  48. arrayBuffer(message: Message): ArrayBuffer;
  49. /**
  50. * Hash and return integer array.
  51. *
  52. * @param message The message you want to hash.
  53. */
  54. digest(message: Message): number[];
  55. /**
  56. * Hash and return integer array.
  57. *
  58. * @param message The message you want to hash.
  59. */
  60. array(message: Message): number[];
  61. /**
  62. * Create a hash object.
  63. */
  64. create(): Hasher;
  65. /**
  66. * Create a hash object and hash message.
  67. *
  68. * @param message The message you want to hash.
  69. */
  70. update(message: Message): Hasher;
  71. }
  72. interface ShakeHash {
  73. /**
  74. * Hash and return hex string.
  75. *
  76. * @param message The message you want to hash.
  77. * @param outputBits The length of output.
  78. */
  79. (message: Message, outputBits: number): string;
  80. /**
  81. * Hash and return hex string.
  82. *
  83. * @param message The message you want to hash.
  84. * @param outputBits The length of output.
  85. */
  86. hex(message: Message, outputBits: number): string;
  87. /**
  88. * Hash and return ArrayBuffer.
  89. *
  90. * @param message The message you want to hash.
  91. * @param outputBits The length of output.
  92. */
  93. arrayBuffer(message: Message, outputBits: number): ArrayBuffer;
  94. /**
  95. * Hash and return integer array.
  96. *
  97. * @param message The message you want to hash.
  98. * @param outputBits The length of output.
  99. */
  100. digest(message: Message, outputBits: number): number[];
  101. /**
  102. * Hash and return integer array.
  103. *
  104. * @param message The message you want to hash.
  105. * @param outputBits The length of output.
  106. */
  107. array(message: Message, outputBits: number): number[];
  108. /**
  109. * Create a hash object.
  110. *
  111. * @param outputBits The length of output.
  112. * @param outputBits The length of output.
  113. */
  114. create(outputBits: number): Hasher;
  115. /**
  116. * Create a hash object and hash message.
  117. *
  118. * @param message The message you want to hash.
  119. * @param outputBits The length of output.
  120. */
  121. update(message: Message, outputBits: number): Hasher;
  122. }
  123. interface CshakeHash {
  124. /**
  125. * Hash and return hex string.
  126. *
  127. * @param message The message you want to hash.
  128. * @param outputBits The length of output.
  129. * @param functionName The function name string.
  130. * @param customization The customization string.
  131. */
  132. (message: Message, outputBits: number, functionName: Message, customization: Message): string;
  133. /**
  134. * Hash and return hex string.
  135. *
  136. * @param message The message you want to hash.
  137. * @param outputBits The length of output.
  138. * @param functionName The function name string.
  139. * @param customization The customization string.
  140. */
  141. hex(message: Message, outputBits: number, functionName: Message, customization: Message): string;
  142. /**
  143. * Hash and return ArrayBuffer.
  144. *
  145. * @param message The message you want to hash.
  146. * @param outputBits The length of output.
  147. * @param functionName The function name string.
  148. * @param customization The customization string.
  149. */
  150. arrayBuffer(message: Message, outputBits: number, functionName: Message, customization: Message): ArrayBuffer;
  151. /**
  152. * Hash and return integer array.
  153. *
  154. * @param message The message you want to hash.
  155. * @param outputBits The length of output.
  156. * @param functionName The function name string.
  157. * @param customization The customization string.
  158. */
  159. digest(message: Message, outputBits: number, functionName: Message, customization: Message): number[];
  160. /**
  161. * Hash and return integer array.
  162. *
  163. * @param message The message you want to hash.
  164. * @param outputBits The length of output.
  165. * @param functionName The function name string.
  166. * @param customization The customization string.
  167. */
  168. array(message: Message, outputBits: number, functionName: Message, customization: Message): number[];
  169. /**
  170. * Create a hash object.
  171. *
  172. * @param outputBits The length of output.
  173. * @param outputBits The length of output.
  174. */
  175. create(outputBits: number): Hasher;
  176. /**
  177. * Create a hash object.
  178. *
  179. * @param outputBits The length of output.
  180. * @param functionName The function name string.
  181. * @param customization The customization string.
  182. */
  183. create(outputBits: number, functionName: Message, customization: Message): Hasher;
  184. /**
  185. * Create a hash object and hash message.
  186. *
  187. * @param message The message you want to hash.
  188. * @param outputBits The length of output.
  189. * @param functionName The function name string.
  190. * @param customization The customization string.
  191. */
  192. update(message: Message, outputBits: number, functionName: Message, customization: Message): Hasher;
  193. }
  194. interface KmacHash {
  195. /**
  196. * Hash and return hex string.
  197. *
  198. * @param key The key string.
  199. * @param message The message you want to hash.
  200. * @param outputBits The length of output.
  201. * @param customization The customization string.
  202. */
  203. (key: Message, message: Message, outputBits: number, customization: Message): string;
  204. /**
  205. * Hash and return hex string.
  206. *
  207. * @param key The key string.
  208. * @param message The message you want to hash.
  209. * @param outputBits The length of output.
  210. * @param customization The customization string.
  211. */
  212. hex(key: Message, message: Message, outputBits: number, customization: Message): string;
  213. /**
  214. * Hash and return ArrayBuffer.
  215. *
  216. * @param key The key string.
  217. * @param message The message you want to hash.
  218. * @param outputBits The length of output.
  219. * @param customization The customization string.
  220. */
  221. arrayBuffer(key: Message, message: Message, outputBits: number, customization: Message): ArrayBuffer;
  222. /**
  223. * Hash and return integer array.
  224. *
  225. * @param key The key string.
  226. * @param message The message you want to hash.
  227. * @param outputBits The length of output.
  228. * @param customization The customization string.
  229. */
  230. digest(key: Message, message: Message, outputBits: number, customization: Message): number[];
  231. /**
  232. * Hash and return integer array.
  233. *
  234. * @param key The key string.
  235. * @param message The message you want to hash.
  236. * @param outputBits The length of output.
  237. * @param customization The customization string.
  238. */
  239. array(key: Message, message: Message, outputBits: number, customization: Message): number[];
  240. /**
  241. * Create a hash object.
  242. *
  243. * @param key The key string.
  244. * @param outputBits The length of output.
  245. * @param customization The customization string.
  246. */
  247. create(key: Message, outputBits: number, customization: Message): Hasher;
  248. /**
  249. * Create a hash object and hash message.
  250. *
  251. * @param key The key string.
  252. * @param message The message you want to hash.
  253. * @param outputBits The length of output.
  254. * @param customization The customization string.
  255. */
  256. update(key: Message, message: Message, outputBits: number, customization: Message): Hasher;
  257. }
  258. export var sha3_512: Hash;
  259. export var sha3_384: Hash;
  260. export var sha3_256: Hash;
  261. export var sha3_224: Hash;
  262. export var keccak_512: Hash;
  263. export var keccak_384: Hash;
  264. export var keccak_256: Hash;
  265. export var keccak_224: Hash;
  266. export var keccak512: Hash;
  267. export var keccak384: Hash;
  268. export var keccak256: Hash;
  269. export var keccak224: Hash;
  270. export var shake_128: ShakeHash;
  271. export var shake_256: ShakeHash;
  272. export var shake128: ShakeHash;
  273. export var shake256: ShakeHash;
  274. export var cshake_128: CshakeHash;
  275. export var cshake_256: CshakeHash;
  276. export var cshake128: CshakeHash;
  277. export var cshake256: CshakeHash;
  278. export var kmac_128: KmacHash;
  279. export var kmac_256: KmacHash;
  280. export var kmac128: KmacHash;
  281. export var kmac256: KmacHash;