new script API

fixes https://github.com/bitpay/bitcore/issues/602
it should throw an Error if `num` is invalid