index.d.ts 2.9 KB

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