mars-v2-frontend/utils/address.ts
Gustavo Mauricio 28c53b1e59
Wallets integration (#3)
* keplr/metamask integration initial commit

* chains settings and type definitions. notifications prototype

* fix: dom nested buttons

* address copied toast

* react-toastify colors

* wallet store and initial queries setup. zustand and react query dependencies added

* _app code cleanup

* remove obsolete WalletContext

* unused import

* walletStore initial commit

* leftover component reference removed

* fix: react hydration mismatch wallet component

* metamask conditional click handler

* connect modal minor tweaks and wallet installation urls added
2022-09-14 12:28:18 +01:00

19 lines
525 B
TypeScript

import { bech32 } from "bech32";
import { Address } from "ethereumjs-util";
export const getInjectiveAddress = (address: string): string => {
const addressBuffer = Address.fromString(address.toString()).toBuffer();
return bech32.encode("inj", bech32.toWords(addressBuffer));
};
export const getAddressFromInjectiveAddress = (address: string): string => {
if (address.startsWith("0x")) {
return address;
}
return `0x${Buffer.from(
bech32.fromWords(bech32.decode(address).words)
).toString("hex")}`;
};