Skip to content

Tm/upgrade-ledger-2fa #976

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

Merged
merged 2 commits into from
Sep 25, 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
26 changes: 16 additions & 10 deletions docs/sdk-and-tools/sdk-dapp/internal-processes/guardians.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,22 @@ All signing providers (except Ledger) take care internally of formatting the tra
After formatting the transaction and applying the signature provided by the Ledger device, the transaction must be signed by the Guardian. This is done by sending the transaction (or transactions array) to the web wallet 2FA hook. The web wallet will then prompt the user to sign the transaction with the Guardian account, and respond with the signed transaction.

```js
import { WalletProvider } from '@multiversx/sdk-web-wallet-provider';
import { CrossWindowProvider } from "@multiversx/sdk-web-wallet-cross-window-provider";

const walletProvider = new WalletProvider('https://wallet.multiversx.com/dapp/init');
walletProvider.guardTransactions(transactions, {
callbackUrl: encodeURIComponent('https://my-dapp.com'),
});
```
Once transactions are back from the web wallet, they can be retrieved as follows:
// instantiate wallet cross-window provider
await CrossWindowProvider.getInstance().init();
const crossWindowProvider = CrossWindowProvider.getInstance();
crossWindowProvider.setWalletUrl(WALLET_PROVIDER_URL);

```js
const signedTransactions = new WalletProvider('https://wallet.multiversx.com/dapp/init').getTransactionsFromWalletUrl();
```
// set sender
const ledgerSenderBech32 = await this.hwProvider.getAddress();
const sender = Address.newFromBech32(ledgerSenderBech32); // or "erd1...abc" witohut awaiting `getAddress()`
crossWindowProvider.setAddress(sender);

// To complete the transaction, the user will sign using their Ledger device. This requires an additional step: a confirmation popup will appear, prompting the user to approve the action, after which a new tab will open in the browser.
crossWindowProvider.setShouldShowConsentPopup(true);

const guardedTransactions = await crossWindowProvider.guardTransactions(
signedTransactions
);
```
Loading