Place the cornstarch in a pan and gradually whisk in the cold milk, making sure that there are no lumps. Whisk in the cocoa powder, sugar and vanilla.
Place the pan over a low heat and stir constantly until it comes up to the boil and thickens. Once it starts to thicken, whisk it vigorously for about a minute, making sure that you get right into the edges of the pan. When you stop for a few seconds, a few big bubbles should rise to the surface and pop.
Remove from the heat, add the butter and chocolate and whisk until melted and smooth.
Use a spatula or the back of a spoon to scrape the pastry cream through a fine mesh sieve into a bowl.
Cover the pastry cream with clingfilm directly on the surface, this will prevent a skin from forming. Refrigerate until cold, giving it a vigorous stir every now and again as it cools. It will take 3-4 hours to cool completely and I like to give it a stir every 45 minutes, this helps to prevent it from forming lumps and setting too firm.
When you are ready to use the pastry cream, give it a good whisk with a balloon whisk, electric mixer or stand mixer fitted with a paddle attachment until it is smooth and creamy. It is now ready to use.