Method Signature
align.blockchain.wallets.decryptWallet(
encrypted: EncryptedWallet,
password: string
): Promise<Wallet>
Parameters
The encrypted wallet data object
The password used for encryption
Returns
Returns the full Wallet object with address, private key, and mnemonic.
Examples
import Align from "@tolbel/align";
import fs from "fs";
const align = new Align({
apiKey: process.env.ALIGN_API_KEY!,
environment: "sandbox",
});
// Load encrypted wallet from storage
const encryptedJson = fs.readFileSync("./wallet.json", "utf8");
const encrypted = JSON.parse(encryptedJson);
// Decrypt the wallet
const wallet = await align.blockchain.wallets.decryptWallet(
encrypted,
process.env.WALLET_PASSWORD!
);
console.log(`Decrypted: ${wallet.address}`);
// Now you can use the wallet normally
const tx = await align.blockchain.wallets.sendNativeToken(
wallet,
recipient,
"0.1",
"polygon"
);
const wallet = await align.blockchain.wallets.decryptWallet(
encrypted,
password
);
console.log("Decrypted:", wallet.address);
Decryption will fail if the wrong password is provided. Handle errors
appropriately.