1414 * limitations under the License.
1515 */
1616
17- import { NetworkType } from '../../model/blockchain/NetworkType' ;
1817import { WalletAlgorithm } from '../../model/wallet/WalletAlgorithm' ;
1918import { Convert as convert } from '../format/Convert' ;
2019import { KeyPair } from './KeyPair' ;
@@ -221,16 +220,16 @@ export class Crypto {
221220 * @param {string } msg - A text message
222221 * @param {Uint8Array } iv - An initialization vector
223222 * @param {Uint8Array } salt - A salt
224- * @param {NetworkType } networkType - Catapult network identifier
223+ * @param {SignSchema } signSchema The Sign Schema. (KECCAK(NIS1) / SHA3(Catapult))
225224 * @return {string } - The encoded message
226225 */
227- public static _encode = ( senderPriv , recipientPub , msg , iv , salt , networkType : NetworkType ) => {
226+ public static _encode = ( senderPriv , recipientPub , msg , iv , salt , signSchema : SignSchema ) => {
228227 // Errors
229228 if ( ! senderPriv || ! recipientPub || ! msg || ! iv || ! salt ) { throw new Error ( 'Missing argument !' ) ; }
230229 // Processing
231- const keyPair = KeyPair . createKeyPairFromPrivateKeyString ( senderPriv , networkType ) ;
230+ const keyPair = KeyPair . createKeyPairFromPrivateKeyString ( senderPriv , signSchema ) ;
232231 const pk = convert . hexToUint8 ( recipientPub ) ;
233- const encKey = utility . ua2words ( KeyPair . deriveSharedKey ( keyPair , pk , salt , networkType ) , 32 ) ;
232+ const encKey = utility . ua2words ( KeyPair . deriveSharedKey ( keyPair , pk , salt , signSchema ) , 32 ) ;
234233 const encIv = {
235234 iv : utility . ua2words ( iv , 16 ) ,
236235 } ;
@@ -246,16 +245,16 @@ export class Crypto {
246245 * @param {string } senderPriv - A sender private key
247246 * @param {string } recipientPub - A recipient public key
248247 * @param {string } msg - A text message
249- * @param {NetworkType } networkType - Catapult network identifier
248+ * @param {SignSchema } signSchema The Sign Schema. (KECCAK(NIS1) / SHA3(Catapult))
250249 * @return {string } - The encoded message
251250 */
252- public static encode = ( senderPriv , recipientPub , msg , networkType : NetworkType ) => {
251+ public static encode = ( senderPriv , recipientPub , msg , signSchema : SignSchema ) => {
253252 // Errors
254253 if ( ! senderPriv || ! recipientPub || ! msg ) { throw new Error ( 'Missing argument !' ) ; }
255254 // Processing
256255 const iv = Crypto . randomBytes ( 16 ) ;
257256 const salt = Crypto . randomBytes ( 32 ) ;
258- const encoded = Crypto . _encode ( senderPriv , recipientPub , msg , iv , salt , networkType ) ;
257+ const encoded = Crypto . _encode ( senderPriv , recipientPub , msg , iv , salt , signSchema ) ;
259258 // Result
260259 return encoded ;
261260 }
@@ -266,16 +265,16 @@ export class Crypto {
266265 * @param {string } recipientPrivate - A recipient private key
267266 * @param {string } senderPublic - A sender public key
268267 * @param {Uint8Array } _payload - An encrypted message payload in bytes
269- * @param {NetworkType } networkType - Catapult network identifier
268+ * @param {SignSchema } signSchema The Sign Schema. (KECCAK(NIS1) / SHA3(Catapult))
270269 * @return {string } - The decoded payload as hex
271270 */
272- public static _decode = ( recipientPrivate , senderPublic , payload , iv , salt , networkType : NetworkType ) => {
271+ public static _decode = ( recipientPrivate , senderPublic , payload , iv , salt , signSchema : SignSchema ) => {
273272 // Error
274273 if ( ! recipientPrivate || ! senderPublic || ! payload ) { throw new Error ( 'Missing argument !' ) ; }
275274 // Processing
276- const keyPair = KeyPair . createKeyPairFromPrivateKeyString ( recipientPrivate , networkType ) ;
275+ const keyPair = KeyPair . createKeyPairFromPrivateKeyString ( recipientPrivate , signSchema ) ;
277276 const pk = convert . hexToUint8 ( senderPublic ) ;
278- const encKey = utility . ua2words ( KeyPair . deriveSharedKey ( keyPair , pk , salt , networkType ) , 32 ) ;
277+ const encKey = utility . ua2words ( KeyPair . deriveSharedKey ( keyPair , pk , salt , signSchema ) , 32 ) ;
279278 const encIv = {
280279 iv : utility . ua2words ( iv , 16 ) ,
281280 } ;
@@ -292,19 +291,19 @@ export class Crypto {
292291 *
293292 * @param {string } recipientPrivate - A recipient private key
294293 * @param {string } senderPublic - A sender public key
295- * @param {string } _payload - An encrypted message payload
296- * @param {NetworkType } networkType - Catapult network identifier
294+ * @param {string } payload - An encrypted message payload
295+ * @param {SignSchema } signSchema The Sign Schema. (KECCAK(NIS1) / SHA3(Catapult))
297296 * @return {string } - The decoded payload as hex
298297 */
299- public static decode = ( recipientPrivate , senderPublic , _payload , networkType : NetworkType ) => {
298+ public static decode = ( recipientPrivate , senderPublic , payload , signSchema : SignSchema ) => {
300299 // Error
301- if ( ! recipientPrivate || ! senderPublic || ! _payload ) { throw new Error ( 'Missing argument !' ) ; }
300+ if ( ! recipientPrivate || ! senderPublic || ! payload ) { throw new Error ( 'Missing argument !' ) ; }
302301 // Processing
303- const binPayload = convert . hexToUint8 ( _payload ) ;
304- const payload = new Uint8Array ( binPayload . buffer , 48 ) ;
302+ const binPayload = convert . hexToUint8 ( payload ) ;
303+ const payloadBuffer = new Uint8Array ( binPayload . buffer , 48 ) ;
305304 const salt = new Uint8Array ( binPayload . buffer , 0 , 32 ) ;
306305 const iv = new Uint8Array ( binPayload . buffer , 32 , 16 ) ;
307- const decoded = Crypto . _decode ( recipientPrivate , senderPublic , payload , iv , salt , networkType ) ;
306+ const decoded = Crypto . _decode ( recipientPrivate , senderPublic , payloadBuffer , iv , salt , signSchema ) ;
308307 return decoded ;
309308 }
310309
@@ -318,18 +317,4 @@ export class Crypto {
318317 const crypto = require ( 'crypto' ) ;
319318 return crypto . randomBytes ( length ) ;
320319 }
321-
322- /**
323- * Resolve signature schema from given network type
324- *
325- * @param {NetworkType } networkType - Network type
326- *
327- * @return {SignSchema }
328- */
329- public static resolveNetworkType ( networkType : NetworkType ) : SignSchema {
330- if ( networkType === NetworkType . MAIN_NET || networkType === NetworkType . TEST_NET ) {
331- return SignSchema . KECCAK ;
332- }
333- return SignSchema . SHA3 ;
334- }
335320}
0 commit comments