json-keystore.d.ts 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * The JSON Wallet formats allow a simple way to store the private
  3. * keys needed in Ethereum along with related information and allows
  4. * for extensible forms of encryption.
  5. *
  6. * These utilities facilitate decrypting and encrypting the most common
  7. * JSON Wallet formats.
  8. *
  9. * @_subsection: api/wallet:JSON Wallets [json-wallets]
  10. */
  11. import type { ProgressCallback } from "../crypto/index.js";
  12. import type { BytesLike } from "../utils/index.js";
  13. /**
  14. * The contents of a JSON Keystore Wallet.
  15. */
  16. export type KeystoreAccount = {
  17. address: string;
  18. privateKey: string;
  19. mnemonic?: {
  20. path?: string;
  21. locale?: string;
  22. entropy: string;
  23. };
  24. };
  25. /**
  26. * The parameters to use when encrypting a JSON Keystore Wallet.
  27. */
  28. export type EncryptOptions = {
  29. progressCallback?: ProgressCallback;
  30. iv?: BytesLike;
  31. entropy?: BytesLike;
  32. client?: string;
  33. salt?: BytesLike;
  34. uuid?: string;
  35. scrypt?: {
  36. N?: number;
  37. r?: number;
  38. p?: number;
  39. };
  40. };
  41. /**
  42. * Returns true if %%json%% is a valid JSON Keystore Wallet.
  43. */
  44. export declare function isKeystoreJson(json: string): boolean;
  45. /**
  46. * Returns the account details for the JSON Keystore Wallet %%json%%
  47. * using %%password%%.
  48. *
  49. * It is preferred to use the [async version](decryptKeystoreJson)
  50. * instead, which allows a [[ProgressCallback]] to keep the user informed
  51. * as to the decryption status.
  52. *
  53. * This method will block the event loop (freezing all UI) until decryption
  54. * is complete, which can take quite some time, depending on the wallet
  55. * paramters and platform.
  56. */
  57. export declare function decryptKeystoreJsonSync(json: string, _password: string | Uint8Array): KeystoreAccount;
  58. /**
  59. * Resolves to the decrypted JSON Keystore Wallet %%json%% using the
  60. * %%password%%.
  61. *
  62. * If provided, %%progress%% will be called periodically during the
  63. * decrpytion to provide feedback, and if the function returns
  64. * ``false`` will halt decryption.
  65. *
  66. * The %%progressCallback%% will **always** receive ``0`` before
  67. * decryption begins and ``1`` when complete.
  68. */
  69. export declare function decryptKeystoreJson(json: string, _password: string | Uint8Array, progress?: ProgressCallback): Promise<KeystoreAccount>;
  70. /**
  71. * Return the JSON Keystore Wallet for %%account%% encrypted with
  72. * %%password%%.
  73. *
  74. * The %%options%% can be used to tune the password-based key
  75. * derivation function parameters, explicitly set the random values
  76. * used. Any provided [[ProgressCallback]] is ignord.
  77. */
  78. export declare function encryptKeystoreJsonSync(account: KeystoreAccount, password: string | Uint8Array, options?: EncryptOptions): string;
  79. /**
  80. * Resolved to the JSON Keystore Wallet for %%account%% encrypted
  81. * with %%password%%.
  82. *
  83. * The %%options%% can be used to tune the password-based key
  84. * derivation function parameters, explicitly set the random values
  85. * used and provide a [[ProgressCallback]] to receive periodic updates
  86. * on the completion status..
  87. */
  88. export declare function encryptKeystoreJson(account: KeystoreAccount, password: string | Uint8Array, options?: EncryptOptions): Promise<string>;
  89. //# sourceMappingURL=json-keystore.d.ts.map