|
| 1 | +/* |
| 2 | + * Copyright 2019 NEM |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import {expect} from 'chai'; |
| 18 | +import {Account} from '../../../src/model/account/Account'; |
| 19 | + |
| 20 | +import {PublicAccount} from '../../../src/model/account/PublicAccount'; |
| 21 | +import {NetworkType} from '../../../src/model/blockchain/NetworkType'; |
| 22 | +import {EncryptedMessage} from '../../../src/model/transaction/EncryptedMessage'; |
| 23 | + |
| 24 | + |
| 25 | +describe('EncryptedMessage', () => { |
| 26 | + |
| 27 | + const accountInformation = { |
| 28 | + address: 'SCTVW23D2MN5VE4AQ4TZIDZENGNOZXPRPRLIKCF2', |
| 29 | + privateKey: '26b64cb10f005e5988a36744ca19e20d835ccc7c105aaa5f3b212da593180930'.toUpperCase(), |
| 30 | + publicKey: 'c2f93346e27ce6ad1a9f8f5e3066f8326593a406bdf357acb041e2f9ab402efe'.toUpperCase(), |
| 31 | + }; |
| 32 | + let recipientPublicAccount:PublicAccount; |
| 33 | + |
| 34 | + before(() => { |
| 35 | + recipientPublicAccount = PublicAccount.createFromPublicKey(accountInformation.publicKey,NetworkType.MIJIN_TEST); |
| 36 | + }); |
| 37 | + |
| 38 | + it("should create a encrypted message from a DTO", () => { |
| 39 | + const encryptedMessage = EncryptedMessage.createFromDTO("test transaction"); |
| 40 | + expect(encryptedMessage.payload).to.be.equal("test transaction"); |
| 41 | + }); |
| 42 | + |
| 43 | + it("should return encrypted message dto", () => { |
| 44 | + const account = Account.createFromPrivateKey(accountInformation.privateKey,NetworkType.MIJIN_TEST); |
| 45 | + const publicAccount = PublicAccount.createFromPublicKey(account.publicKey,NetworkType.MIJIN_TEST); |
| 46 | + const encryptedMessage = account.encryptMessage("test transaction", publicAccount); |
| 47 | + const plainMessage = account.decryptMessage(encryptedMessage, publicAccount); |
| 48 | + expect(plainMessage.payload).to.be.equal("test transaction"); |
| 49 | + }); |
| 50 | + |
| 51 | + it("should create an encrypted message from a DTO and decrypt it", () => { |
| 52 | + const account = Account.createFromPrivateKey(accountInformation.privateKey,NetworkType.MIJIN_TEST); |
| 53 | + const publicAccount = PublicAccount.createFromPublicKey("0414fe7647ec008e533aac98a4bf1c5fbf1d236c75b81fdadf1f5d1042fdd2ff",NetworkType.MIJIN_TEST); |
| 54 | + const encryptMessage = EncryptedMessage.createFromDTO("02bb332c0fdd445455117882b2bec5e49f5713860d6b34650d0f769159d021a27518ea03539af8913231b9f80f600daae9291bb100a6d32e36b52a6c457fea287ca9942a32368618fe1fd0c185dbf834"); |
| 55 | + const plainMessage = account.decryptMessage(encryptMessage, publicAccount); |
| 56 | + expect(plainMessage.payload).to.be.equal("test transaction"); |
| 57 | + }); |
| 58 | +}); |
0 commit comments