You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
3.3 KiB

5 months ago
  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. * Return hash in base64 string.
  31. */
  32. base64(): string;
  33. }
  34. interface Hmac {
  35. /**
  36. * Computes a Hash-based message authentication code (HMAC) using a secret key
  37. *
  38. * @param secretKey The Secret Key
  39. * @param message The message you want to hash.
  40. */
  41. (secretKey: Message, message: Message): string;
  42. /**
  43. * Create a hash object using a secret key.
  44. *
  45. * @param secretKey The Secret Key
  46. */
  47. create(secretKey: Message): Hasher;
  48. /**
  49. * Create a hash object and hash message using a secret key
  50. *
  51. * @param secretKey The Secret Key
  52. * @param message The message you want to hash.
  53. */
  54. update(secretKey: Message, message: Message): Hasher;
  55. /**
  56. * Return hash in hex string.
  57. *
  58. * @param secretKey The Secret Key
  59. * @param message The message you want to hash.
  60. */
  61. hex(secretKey: Message, message: Message): string;
  62. /**
  63. * Return hash in ArrayBuffer.
  64. *
  65. * @param secretKey The Secret Key
  66. * @param message The message you want to hash.
  67. */
  68. arrayBuffer(secretKey: Message, message: Message): ArrayBuffer;
  69. /**
  70. * Return hash in integer array.
  71. *
  72. * @param secretKey The Secret Key
  73. * @param message The message you want to hash.
  74. */
  75. digest(secretKey: Message, message: Message): number[];
  76. /**
  77. * Return hash in integer array.
  78. *
  79. * @param secretKey The Secret Key
  80. * @param message The message you want to hash.
  81. */
  82. array(secretKey: Message, message: Message): number[];
  83. /**
  84. * Return hash in base64 string.
  85. *
  86. * @param secretKey The Secret Key
  87. * @param message The message you want to hash.
  88. */
  89. base64(secretKey: Message, message: Message): string;
  90. }
  91. interface Hash {
  92. /**
  93. * Hash and return hex string.
  94. *
  95. * @param message The message you want to hash.
  96. */
  97. (message: Message): string;
  98. /**
  99. * Create a hash object.
  100. */
  101. create(): Hasher;
  102. /**
  103. * Create a hash object and hash message.
  104. *
  105. * @param message The message you want to hash.
  106. */
  107. update(message: Message): Hasher;
  108. /**
  109. * Return hash in hex string.
  110. *
  111. * @param message The message you want to hash.
  112. */
  113. hex(message: Message): string;
  114. /**
  115. * Return hash in ArrayBuffer.
  116. *
  117. * @param message The message you want to hash.
  118. */
  119. arrayBuffer(message: Message): ArrayBuffer;
  120. /**
  121. * Return hash in integer array.
  122. *
  123. * @param message The message you want to hash.
  124. */
  125. digest(message: Message): number[];
  126. /**
  127. * Return hash in integer array.
  128. *
  129. * @param message The message you want to hash.
  130. */
  131. array(message: Message): number[];
  132. /**
  133. * Return hash in base64 string.
  134. *
  135. * @param message The message you want to hash.
  136. */
  137. base64(message: Message): string;
  138. /**
  139. * HMAC interface
  140. */
  141. hmac: Hmac;
  142. }
  143. export var md5: Hash;