Skip to main content

Method Signature

align.blockchain.wallets.encryptWallet(
  wallet: Wallet,
  password: string
): Promise<EncryptedWallet>

Parameters

wallet
Wallet
required
The wallet object to encrypt
password
string
required
Password for encryption (use a strong password!)

Returns

encryptedData
string
The encrypted wallet data
address
string
The wallet’s public address (unencrypted)

Examples

import Align from "@tolbel/align";
import fs from "fs";

const align = new Align({
  apiKey: process.env.ALIGN_API_KEY!,
  environment: "sandbox",
});

// Create a wallet
const wallet = await align.blockchain.wallets.create();
console.log(`Created: ${wallet.address}`);

// Encrypt for secure storage
const encrypted = await align.blockchain.wallets.encryptWallet(
  wallet,
  "mySecurePassword123!"
);

// Save encrypted wallet
fs.writeFileSync(
  `./wallets/${encrypted.address}.json`,
  JSON.stringify(encrypted)
);

console.log("Wallet encrypted and saved!");
The public address is NOT encrypted - only the private key and mnemonic are protected.