Position a rack in the center of your oven and preheat the oven to 350.F. Butter or coat an 8-inch square baking pan with nonstick spray. Line the pan with a strip of parchment paper that hangs over two of the edges.
MAKE THE CAKE: In a large bowl, whisk the sugar and eggs until pale and foamy, about 1 minute. Add the buttermilk, oil, butter, vanilla, and salt. Whisk until smooth and emulsified. Add the cocoa powder and whisk until smooth
Add the flour, baking powder, and baking soda and whisk until well-combined and smooth. Gently stir in the coffee, then fold in the chocolate (if using).
Pour the batter into the prepared pan, tap the pan gently on the counter to release any air bubbles, and smooth the top of the batter with an offset spatula
Bake the cake until puffed and a tester inserted into the center comes out clean, 35 to 45 minutes. Set the pan on a rack to cool for about 15 minutes. Then use the parchment paper to lift the cake out of the pan and set it on the rack to cool completely.
MAKE THE FROSTING: Add the butter to a large bowl and mix with an electric mixer on medium-high until smooth and creamy. Turn the mixer to low, add the cocoa powder, and mix until smooth, scraping the bottom and sides of the bowl as necessary, then slowly add the confectioners’ sugar. Mix until the sugar is moistened, then add the vanilla, a pinch of salt, and 2 tablespoons milk. Turn the mixer to medium high and whip until light and fluffy, adding more milk as necessary to make a smooth and fluffy frosting.
Top the cooled cake with swoops of frosting and scatter the shaved chocolate or sprinkles over the top. (Store the cake, covered, at room temperature or in the fridge for up to three days.)