Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
microchipgnu committed May 7, 2024
1 parent cb2e5fe commit 9248d82
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions packages/wallet/src/mintbase-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,39 @@ export const MintbaseWallet: WalletBehaviourFactory<
throw new Error(`The verifyOwner method is not supported by ${metadata.name}`);
};

const signMessage = async (): Promise<void> => {
throw new Error(`The signMessage method is not supported by ${metadata.name}`);
const signMessage = async ({ message, nonce, recipient, callbackUrl }): Promise<void> => {
const { cbUrl } = getCallbackUrl(callbackUrl ?? '');

const newUrl = new URL(`${metadata.walletUrl}/sign-message`);
newUrl.searchParams.set('message', message);
newUrl.searchParams.set('nonce', nonce);
newUrl.searchParams.set('recipient', recipient);
newUrl.searchParams.set('callbackUrl', cbUrl);
window.location.assign(newUrl.toString());
};

const verifyMessage = async ({ accountId, publicKey, signature, message, nonce, recipient, callbackUrl }): Promise<boolean> => {

const newUrl = new URL(`${metadata.walletUrl}/api/verify-message`);
newUrl.searchParams.set('message', message);
newUrl.searchParams.set('accountId', accountId);
newUrl.searchParams.set('publicKey', publicKey);
newUrl.searchParams.set('signature', signature);
newUrl.searchParams.set('nonce', nonce);
newUrl.searchParams.set('recipient', recipient);
newUrl.searchParams.set('callbackUrl', callbackUrl);

try {
const response = await fetch(newUrl.toString())
const data = await response.json();

const { isValid } = data
return isValid
} catch (e) {
return false
}
}

const getAvailableBalance = async (): Promise<void> => {
// const accountId = state.wallet.getAccountId();
// return await getBalance(accountId);
Expand Down Expand Up @@ -307,5 +336,6 @@ export const MintbaseWallet: WalletBehaviourFactory<
getAccounts,
switchAccount,
signAndSendTransactions,
verifyMessage
};
};

0 comments on commit 9248d82

Please sign in to comment.