Skip to main content

Method Signature

align.blockchain.wallets.createFromEncrypted(
  encrypted: string,
  password: string
): Promise<Wallet>

Parameters

encrypted
string
required
The encrypted wallet JSON string (keystore format)
password
string
required
The password used to encrypt the wallet

Returns

address
string
The wallet’s public address
privateKey
string
The decrypted private key

Examples

import Align from "@tolbel/align";

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

// Encrypted keystore JSON (typically stored in a file or database)
const encryptedJson = `{
  "address": "742d35cc6634c0532925a3b844bc9e7595f0ab42",
  "crypto": {
    "cipher": "aes-128-ctr",
    "ciphertext": "...",
    "kdf": "scrypt",
    ...
  }
}`;

const wallet = await align.blockchain.wallets.createFromEncrypted(
  encryptedJson,
  "mySecurePassword123"
);

console.log(`Decrypted wallet: ${wallet.address}`);

Load from File

import fs from "fs";

// Read keystore file
const keystorePath = "./keystore/wallet.json";
const encryptedJson = fs.readFileSync(keystorePath, "utf8");

// Decrypt with password
const wallet = await align.blockchain.wallets.createFromEncrypted(
  encryptedJson,
  process.env.WALLET_PASSWORD!
);

Encryption/Decryption Flow

Decryption can take several seconds as it’s intentionally slow (using scrypt) to prevent brute-force attacks.