nacl.d.ts 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Type definitions for TweetNaCl.js
  2. export as namespace nacl;
  3. declare var nacl: nacl;
  4. export = nacl;
  5. declare namespace nacl {
  6. export interface BoxKeyPair {
  7. publicKey: Uint8Array;
  8. secretKey: Uint8Array;
  9. }
  10. export interface SignKeyPair {
  11. publicKey: Uint8Array;
  12. secretKey: Uint8Array;
  13. }
  14. export interface secretbox {
  15. (msg: Uint8Array, nonce: Uint8Array, key: Uint8Array): Uint8Array;
  16. open(box: Uint8Array, nonce: Uint8Array, key: Uint8Array): Uint8Array | false;
  17. readonly keyLength: number;
  18. readonly nonceLength: number;
  19. readonly overheadLength: number;
  20. }
  21. export interface scalarMult {
  22. (n: Uint8Array, p: Uint8Array): Uint8Array;
  23. base(n: Uint8Array): Uint8Array;
  24. readonly scalarLength: number;
  25. readonly groupElementLength: number;
  26. }
  27. namespace box {
  28. export interface open {
  29. (msg: Uint8Array, nonce: Uint8Array, publicKey: Uint8Array, secretKey: Uint8Array): Uint8Array | false;
  30. after(box: Uint8Array, nonce: Uint8Array, key: Uint8Array): Uint8Array | false;
  31. }
  32. export interface keyPair {
  33. (): BoxKeyPair;
  34. fromSecretKey(secretKey: Uint8Array): BoxKeyPair;
  35. }
  36. }
  37. export interface box {
  38. (msg: Uint8Array, nonce: Uint8Array, publicKey: Uint8Array, secretKey: Uint8Array): Uint8Array;
  39. before(publicKey: Uint8Array, secretKey: Uint8Array): Uint8Array;
  40. after(msg: Uint8Array, nonce: Uint8Array, key: Uint8Array): Uint8Array;
  41. open: box.open;
  42. keyPair: box.keyPair;
  43. readonly publicKeyLength: number;
  44. readonly secretKeyLength: number;
  45. readonly sharedKeyLength: number;
  46. readonly nonceLength: number;
  47. readonly overheadLength: number;
  48. }
  49. namespace sign {
  50. export interface detached {
  51. (msg: Uint8Array, secretKey: Uint8Array): Uint8Array;
  52. verify(msg: Uint8Array, sig: Uint8Array, publicKey: Uint8Array): boolean;
  53. }
  54. export interface keyPair {
  55. (): SignKeyPair;
  56. fromSecretKey(secretKey: Uint8Array): SignKeyPair;
  57. fromSeed(secretKey: Uint8Array): SignKeyPair;
  58. }
  59. }
  60. export interface sign {
  61. (msg: Uint8Array, secretKey: Uint8Array): Uint8Array;
  62. open(signedMsg: Uint8Array, publicKey: Uint8Array): Uint8Array | null;
  63. detached: sign.detached;
  64. keyPair: sign.keyPair;
  65. readonly publicKeyLength: number;
  66. readonly secretKeyLength: number;
  67. readonly seedLength: number;
  68. readonly signatureLength: number;
  69. }
  70. export interface hash {
  71. (msg: Uint8Array): Uint8Array;
  72. readonly hashLength: number;
  73. }
  74. }
  75. declare interface nacl {
  76. randomBytes(n: number): Uint8Array;
  77. secretbox: nacl.secretbox;
  78. scalarMult: nacl.scalarMult;
  79. box: nacl.box;
  80. sign: nacl.sign;
  81. hash: nacl.hash;
  82. verify(x: Uint8Array, y: Uint8Array): boolean;
  83. setPRNG(fn: (x: Uint8Array, n: number) => void): void;
  84. }