Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sign and Verify Messages #509

Merged
merged 1 commit into from
May 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
SurgeCode marked this conversation as resolved.
Show resolved Hide resolved
}
}

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
};
};