### In web
```html
-<script src="https://unpkg.com/nanocurrency-web@1.4.1" type="text/javascript"></script>
+<script src="https://unpkg.com/nanocurrency-web@1.4.2" type="text/javascript"></script>
<script type="text/javascript">
NanocurrencyWeb.wallet.generate(...);
</script>
const nonce = Convert.hex2ab(lib.WordArray.random(this.NONCE_LENGTH).toString())
const encrypted = new Curve25519().box(
- Convert.str2bin(message),
+ Convert.decodeUTF8(message),
nonce,
Convert.hex2ab(convertedPublicKey),
Convert.hex2ab(convertedPrivateKey),
throw new Error('Could not decrypt message')
}
- return Convert.bin2str(decrypted)
+ return Convert.encodeUTF8(decrypted)
}
}
* Convert a byte array to a UTF-8 encoded string
*
* @param {Uint8Array} arr Byte array
- * @return {String} UTF-8 encoded string
+ * @return {string} UTF-8 encoded string
*/
- static bin2str = (arr: Uint8Array) => {
- let i, s = []
- for (i = 0; i < arr.length; i++) {
+ static encodeUTF8 = (arr: Uint8Array): string => {
+ const s = []
+ for (let i = 0; i < arr.length; i++) {
s.push(String.fromCharCode(arr[i]))
}
-
return decodeURIComponent(escape(s.join('')))
}
+ /**
+ * Convert a UTF-8 encoded string to a byte array
+ *
+ * @param {string} str UTF-8 encoded string
+ * @return {Uint8Array} Byte array
+ */
+ static decodeUTF8 = (str: string): Uint8Array => {
+ if (typeof str !== 'string') {
+ throw new TypeError('expected string')
+ }
+ const d = unescape(encodeURIComponent(str))
+ const b = new Uint8Array(d.length)
+ for (let i = 0; i < d.length; i++) {
+ b[i] = d.charCodeAt(i)
+ }
+ return b
+ }
+
/**
* Convert Array of 8 bytes (int64) to hex string
*
{
"name": "nanocurrency-web",
- "version": "1.4.1",
+ "version": "1.4.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
{
"name": "nanocurrency-web",
- "version": "1.4.1",
+ "version": "1.4.2",
"description": "Toolkit for Nano cryptocurrency client side offline integrations",
"author": "Miro Metsänheimo <miro@metsanheimo.fi>",
"license": "MIT",
describe('Box tests', () => {
before(() => {
- this.message = 'The quick brown fox jumps over the lazy dog'
+ this.message = 'The quick brown fox jumps over the lazy dog 🔥'
this.bob = wallet.generate()
this.alice = wallet.generateLegacy()
})