To connect and use MSafe wallet, you will need to first initialize an MSafeWallet object.
const msafe = await MSafeWallet.new();
You may also pass in a list of URLs as the allowed origins of the parent frame. For example, if you only want to connect to MSafe production (https://app.m-safe.io), the msafe instance can be initialized with:
MSafe enforces an origin check to ensure that any transaction requests initiated by dApp is passed on to a pre-defined allowed origin URL. The origin check is to prevent the potential phishing attacks launched from any unauthorized third-party.
MSafe will maintain a default list of allowed endpoints deployed by MSafe in MSafe-wallet repository. If no additional arguments is provided, the default list will be used. The current default allowlist is:
The default allowlist shall meet most requirements for MSafe integration in production and development.
Example:
Initialization
import { MSafeWallet } from"msafe-wallet";// check if the dapp is running in msafeif(!MSafeWallet.inMSafeWallet()){ // get dapp url for msafeconsturl=MSafeWallet.getAppUrl('Mainnet'); // redirect to msafe dappwindow.location.href.replace(url); }constmsafe=awaitMSafeWallet.new();