@@ -16,10 +16,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
1616 const multiformats_1 = require ( "@chelonia/multiformats" ) ;
1717 const scrypt_async_1 = __importDefault ( require ( "scrypt-async" ) ) ;
1818 const tweetnacl_1 = __importDefault ( require ( "tweetnacl" ) ) ;
19- const strToBuf = ( str ) => {
19+ const bufToStr = ( ( ) => {
20+ const textDecoder = new TextDecoder ( ) ;
21+ return ( buf ) => {
22+ return textDecoder . decode ( buf ) ;
23+ } ;
24+ } ) ( ) ;
25+ const strToBuf = ( ( ) => {
2026 const textEncoder = new TextEncoder ( ) ;
21- return textEncoder . encode ( str ) ;
22- } ;
27+ return ( str ) => {
28+ return textEncoder . encode ( str ) ;
29+ } ;
30+ } ) ( ) ;
2331 const blake32Hash = ( data ) => {
2432 const uint8array = typeof data === 'string' ? strToBuf ( data ) : data ;
2533 const digest = multiformats_1 . blake2b256 . digest ( uint8array ) ;
@@ -418,7 +426,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
418426 if ( ! decrypted ) {
419427 throw new Error ( 'Could not decrypt message' ) ;
420428 }
421- return Buffer . from ( decrypted ) . toString ( 'utf-8' ) ;
429+ return bufToStr ( decrypted ) ;
422430 }
423431 else if ( key . type === exports . CURVE25519XSALSA20POLY1305 ) {
424432 if ( ! key . secretKey ) {
@@ -439,7 +447,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
439447 if ( ! decrypted ) {
440448 throw new Error ( 'Could not decrypt message' ) ;
441449 }
442- return Buffer . from ( decrypted ) . toString ( 'utf-8' ) ;
450+ return bufToStr ( decrypted ) ;
443451 }
444452 throw new Error ( 'Unsupported algorithm' ) ;
445453 } ;
0 commit comments