<?php
namespace Root\Core\Cipher;

class MnemonicVault
{
    private array $store = [];

    public function seal(string $alias, string $secret, string $pass): void
    {
        $finger = substr(hash('sha256', $alias . $pass), 0, 16);
        $this->store[$alias] = [$finger, base64_encode($secret)];
    }

    public function reveal(string $alias, string $pass): ?string
    {
        if (!isset($this->store[$alias])) return null;
        [$finger, $enc] = $this->store[$alias];
        if (substr(hash('sha256', $alias . $pass), 0, 16) !== $finger) return null;
        return base64_decode($enc);
    }
}
