Skip to content

Commit

Permalink
fix: export social sign-in private key in base58 format instead of hex
Browse files Browse the repository at this point in the history
  • Loading branch information
losman0s authored and chambaz committed Nov 17, 2023
1 parent a0b0903 commit 2d40007
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions apps/marginfi-v2-ui/src/hooks/useWalletContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CHAIN_NAMESPACES, IProvider, ADAPTER_EVENTS, WALLET_ADAPTERS } from "@w
import { Web3AuthNoModal } from "@web3auth/no-modal";
import { OpenloginAdapter } from "@web3auth/openlogin-adapter";
import { SolanaWallet, SolanaPrivateKeyProvider } from "@web3auth/solana-provider";

import base58 from "bs58";
import { Wallet } from "@mrgnlabs/mrgn-common";

// wallet adapter context type to override with web3auth data
Expand Down Expand Up @@ -235,12 +235,14 @@ const WalletProvider = ({ children }: { children: React.ReactNode }) => {
async (provider: IProvider) => {
if (!web3AuthPkCookie.mrgnPrivateKeyRequested) return;

const pk = await provider.request({
const privateKeyHexString = await provider.request({
method: "solanaPrivateKey",
});
}) as string;
const privateKeyBytes = new Uint8Array(privateKeyHexString.match(/.{1,2}/g)!.map((byte) => parseInt(byte, 16)));
const privateKeyBase58 = base58.encode(privateKeyBytes);

setWeb3AuthPkCookie("mrgnPrivateKeyRequested", false);
setWeb3AuthPk(pk as string);
setWeb3AuthPk(privateKeyBase58);
},
[web3AuthPkCookie]
);
Expand Down

0 comments on commit 2d40007

Please sign in to comment.