@@ -228,20 +228,19 @@ export class Crypto {
228228 recipientPub : string ,
229229 msg : string ,
230230 iv : Uint8Array ,
231- salt : Uint8Array ,
232231 signSchema : SignSchema ) : string => {
233232 // Errors
234- if ( ! senderPriv || ! recipientPub || ! msg || ! iv || ! salt ) { throw new Error ( 'Missing argument !' ) ; }
233+ if ( ! senderPriv || ! recipientPub || ! msg || ! iv ) { throw new Error ( 'Missing argument !' ) ; }
235234 // Processing
236235 const keyPair = KeyPair . createKeyPairFromPrivateKeyString ( senderPriv , signSchema ) ;
237236 const pk = convert . hexToUint8 ( recipientPub ) ;
238- const encKey = utility . ua2words ( KeyPair . deriveSharedKey ( keyPair , pk , salt , signSchema ) , 32 ) ;
237+ const encKey = utility . ua2words ( KeyPair . deriveSharedKey ( keyPair , pk , signSchema ) , 32 ) ;
239238 const encIv = {
240239 iv : utility . ua2words ( iv , 16 ) ,
241240 } ;
242241 const encrypted = CryptoJS . AES . encrypt ( CryptoJS . enc . Hex . parse ( msg ) , encKey , encIv ) ;
243242 // Result
244- const result = convert . uint8ToHex ( salt ) + convert . uint8ToHex ( iv ) + CryptoJS . enc . Hex . stringify ( encrypted . ciphertext ) ;
243+ const result = convert . uint8ToHex ( iv ) + CryptoJS . enc . Hex . stringify ( encrypted . ciphertext ) ;
245244 return result ;
246245 }
247246
@@ -264,8 +263,7 @@ export class Crypto {
264263 if ( ! senderPriv || ! recipientPub || ! msg ) { throw new Error ( 'Missing argument !' ) ; }
265264 // Processing
266265 const iv = Crypto . randomBytes ( 16 ) ;
267- const salt = Crypto . randomBytes ( 32 ) ;
268- const encoded = Crypto . _encode ( senderPriv , recipientPub , isHexString ? msg : convert . utf8ToHex ( msg ) , iv , salt , signSchema ) ;
266+ const encoded = Crypto . _encode ( senderPriv , recipientPub , isHexString ? msg : convert . utf8ToHex ( msg ) , iv , signSchema ) ;
269267 // Result
270268 return encoded ;
271269 }
@@ -277,22 +275,20 @@ export class Crypto {
277275 * @param {string } senderPublic - A sender public key
278276 * @param {Uint8Array } payload - An encrypted message payload in bytes
279277 * @param {Uint8Array } iv - 16-byte AES initialization vector
280- * @param {Uint8Array } salt - 32-byte salt
281278 * @param {SignSchema } signSchema The Sign Schema. (KECCAK(NIS1) / SHA3(Catapult))
282279 * @return {string } - The decoded payload as hex
283280 */
284281 public static _decode = ( recipientPrivate : string ,
285282 senderPublic : string ,
286283 payload : Uint8Array ,
287284 iv : Uint8Array ,
288- salt : Uint8Array ,
289285 signSchema : SignSchema ) : string => {
290286 // Error
291287 if ( ! recipientPrivate || ! senderPublic || ! payload ) { throw new Error ( 'Missing argument !' ) ; }
292288 // Processing
293289 const keyPair = KeyPair . createKeyPairFromPrivateKeyString ( recipientPrivate , signSchema ) ;
294290 const pk = convert . hexToUint8 ( senderPublic ) ;
295- const encKey = utility . ua2words ( KeyPair . deriveSharedKey ( keyPair , pk , salt , signSchema ) , 32 ) ;
291+ const encKey = utility . ua2words ( KeyPair . deriveSharedKey ( keyPair , pk , signSchema ) , 32 ) ;
296292 const encIv = {
297293 iv : utility . ua2words ( iv , 16 ) ,
298294 } ;
@@ -321,10 +317,9 @@ export class Crypto {
321317 if ( ! recipientPrivate || ! senderPublic || ! payload ) { throw new Error ( 'Missing argument !' ) ; }
322318 // Processing
323319 const binPayload = convert . hexToUint8 ( payload ) ;
324- const payloadBuffer = new Uint8Array ( binPayload . buffer , 48 ) ;
325- const salt = new Uint8Array ( binPayload . buffer , 0 , 32 ) ;
326- const iv = new Uint8Array ( binPayload . buffer , 32 , 16 ) ;
327- const decoded = Crypto . _decode ( recipientPrivate , senderPublic , payloadBuffer , iv , salt , signSchema ) ;
320+ const payloadBuffer = new Uint8Array ( binPayload . buffer , 16 ) ;
321+ const iv = new Uint8Array ( binPayload . buffer , 0 , 16 ) ;
322+ const decoded = Crypto . _decode ( recipientPrivate , senderPublic , payloadBuffer , iv , signSchema ) ;
328323 return decoded . toUpperCase ( ) ;
329324 }
330325
0 commit comments