address.js 808 B

12345678910111213141516171819202122232425
  1. import { getAddress } from "../address/index.js";
  2. import { keccak256, SigningKey } from "../crypto/index.js";
  3. /**
  4. * Returns the address for the %%key%%.
  5. *
  6. * The key may be any standard form of public key or a private key.
  7. */
  8. export function computeAddress(key) {
  9. let pubkey;
  10. if (typeof (key) === "string") {
  11. pubkey = SigningKey.computePublicKey(key, false);
  12. }
  13. else {
  14. pubkey = key.publicKey;
  15. }
  16. return getAddress(keccak256("0x" + pubkey.substring(4)).substring(26));
  17. }
  18. /**
  19. * Returns the recovered address for the private key that was
  20. * used to sign %%digest%% that resulted in %%signature%%.
  21. */
  22. export function recoverAddress(digest, signature) {
  23. return computeAddress(SigningKey.recoverPublicKey(digest, signature));
  24. }
  25. //# sourceMappingURL=address.js.map