nChain has this in our SDK

, This is one of the many patents I have been filing.