// In Blocklet Server, getWalletDid(user) extracts wallet DID from user.connectedAccounts.
// In CF Workers, the user's DID from DID Connect IS the wallet DID (wallet signed directly).
export function getWalletDid(user?: any) {
  if (user) {
    // If user has connectedAccounts (from enriched getUser), use it
    if (user.connectedAccounts) {
      const walletAccount = user.connectedAccounts.find((a: any) => a.provider === 'wallet');
      if (walletAccount) return walletAccount.did;
    }
    // In CF Workers, user.did IS the wallet DID (signed via DID Connect)
    if (user.did) return user.did;
  }
  return (globalThis as any).__CF_ENV__?.WALLET_DID || '';
}
