How to transform a legacy widget into a block

In case anyone is interested, I’m answering my question:

The blocks parameter in the transform code should be [ 'core/legacy-widget' ] instead of [ 'my/custom-block' ]. For a from transform it indicates the block(s) you want to transform from, which in this case is a legacy widget.