Version 1.4.2
* Fix encrypting and decrypting emojis
This commit is contained in:
parent
252125d0f2
commit
8b531fa570
6 changed files with 28 additions and 11 deletions
|
|
@ -33,7 +33,7 @@ npm install nanocurrency-web
|
||||||
### In web
|
### In web
|
||||||
|
|
||||||
```html
|
```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">
|
<script type="text/javascript">
|
||||||
NanocurrencyWeb.wallet.generate(...);
|
NanocurrencyWeb.wallet.generate(...);
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ export default class Box {
|
||||||
|
|
||||||
const nonce = Convert.hex2ab(lib.WordArray.random(this.NONCE_LENGTH).toString())
|
const nonce = Convert.hex2ab(lib.WordArray.random(this.NONCE_LENGTH).toString())
|
||||||
const encrypted = new Curve25519().box(
|
const encrypted = new Curve25519().box(
|
||||||
Convert.str2bin(message),
|
Convert.decodeUTF8(message),
|
||||||
nonce,
|
nonce,
|
||||||
Convert.hex2ab(convertedPublicKey),
|
Convert.hex2ab(convertedPublicKey),
|
||||||
Convert.hex2ab(convertedPrivateKey),
|
Convert.hex2ab(convertedPrivateKey),
|
||||||
|
|
@ -63,7 +63,7 @@ export default class Box {
|
||||||
throw new Error('Could not decrypt message')
|
throw new Error('Could not decrypt message')
|
||||||
}
|
}
|
||||||
|
|
||||||
return Convert.bin2str(decrypted)
|
return Convert.encodeUTF8(decrypted)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,17 +30,34 @@ export default class Convert {
|
||||||
* Convert a byte array to a UTF-8 encoded string
|
* Convert a byte array to a UTF-8 encoded string
|
||||||
*
|
*
|
||||||
* @param {Uint8Array} arr Byte array
|
* @param {Uint8Array} arr Byte array
|
||||||
* @return {String} UTF-8 encoded string
|
* @return {string} UTF-8 encoded string
|
||||||
*/
|
*/
|
||||||
static bin2str = (arr: Uint8Array) => {
|
static encodeUTF8 = (arr: Uint8Array): string => {
|
||||||
let i, s = []
|
const s = []
|
||||||
for (i = 0; i < arr.length; i++) {
|
for (let i = 0; i < arr.length; i++) {
|
||||||
s.push(String.fromCharCode(arr[i]))
|
s.push(String.fromCharCode(arr[i]))
|
||||||
}
|
}
|
||||||
|
|
||||||
return decodeURIComponent(escape(s.join('')))
|
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
|
* Convert Array of 8 bytes (int64) to hex string
|
||||||
*
|
*
|
||||||
|
|
|
||||||
2
package-lock.json
generated
2
package-lock.json
generated
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "nanocurrency-web",
|
"name": "nanocurrency-web",
|
||||||
"version": "1.4.1",
|
"version": "1.4.2",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "nanocurrency-web",
|
"name": "nanocurrency-web",
|
||||||
"version": "1.4.1",
|
"version": "1.4.2",
|
||||||
"description": "Toolkit for Nano cryptocurrency client side offline integrations",
|
"description": "Toolkit for Nano cryptocurrency client side offline integrations",
|
||||||
"author": "Miro Metsänheimo <miro@metsanheimo.fi>",
|
"author": "Miro Metsänheimo <miro@metsanheimo.fi>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
|
||||||
|
|
@ -332,7 +332,7 @@ describe('Signer tests', () => {
|
||||||
describe('Box tests', () => {
|
describe('Box tests', () => {
|
||||||
|
|
||||||
before(() => {
|
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.bob = wallet.generate()
|
||||||
this.alice = wallet.generateLegacy()
|
this.alice = wallet.generateLegacy()
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue