Update base2pn.js

Improve encapsulation and error messages.