Change Wallet PIN
How to change a wallet's PIN encryption key. Requires the current PIN.
Overview
Changing a wallet's PIN re-encrypts the private key with a new PIN. The old PIN stops working immediately.
Requirements:
- - User must know their current PIN
- - Wallet must be PIN-encrypted (not passkey)
Implementation
There is no pre-built component for PIN change yet. Here's how to build it:
typescriptimport { useUpdateWalletEncryption } from "@chipi-stack/chipi-react";
function ChangePinForm({ wallet }) {
const { updateWalletEncryption, isLoading } = useUpdateWalletEncryption();
const handleChange = async (oldPin: string, newPin: string) => {
// 1. Decrypt with old PIN
const decrypted = decryptPrivateKey(wallet.encryptedPrivateKey, oldPin);
// 2. Re-encrypt with new PIN
const newEncrypted = encryptPrivateKey(decrypted, newPin);
// 3. Update on backend
await updateWalletEncryption({
params: {
externalUserId: wallet.externalUserId,
newEncryptedPrivateKey: newEncrypted,
},
bearerToken: await getToken(),
});
};
// Render form with old PIN input, new PIN input, confirm new PIN
}Security Notes
- - No recovery: If the user forgets both old and new PIN, the wallet is locked.
- - Validate new PIN: Require minimum 4 digits. Reject sequential (1234) and repeated (1111) patterns.
- - Don't log PINs: Never persist or transmit PINs.
- - Consider passkey: After changing PIN, recommend migrating to passkey for better security.