1
1
const { expect } = require ( "chai" ) ;
2
- const encryptIM = require ( "./../dapps/utils/encryp-im/encrypt-im.js" ) ;
3
- const decryptIM = require ( "./../dapps/utils/decrypt-im/decrypt-im.js" ) ;
2
+ const { ethers } = require ( "hardhat" ) ;
3
+ const { utils } = require ( "ethers" ) ;
4
+ const encryptIM = require ( "./../dapps/utils/encrypt-im.js" ) ;
5
+ const decryptIM = require ( "./../dapps/utils/decrypt-im.js" ) ;
4
6
5
7
const accounts = {
6
8
Owner : {
@@ -33,4 +35,37 @@ describe("Encryption and Decryption", function () {
33
35
// Check if the decrypted message matches the original message
34
36
expect ( decryptedMessage ) . to . equal ( message ) ;
35
37
} ) ;
38
+
39
+ it ( "should encrypt the message, send it to Oracle, Oracle should decrypt it" , async function ( ) {
40
+ const message = "Hello, world!" ;
41
+
42
+ // Encrypting a message from Owner to Heir
43
+ const encryptedMessage = await encryptIM ( message , accounts . Owner . privateKey , accounts . Heir . publicKey ) ;
44
+
45
+ // Owner encrypting message for Oracle and send it
46
+ const encryptedMessageForOracle = await encryptIM ( encryptedMessage , accounts . Owner . privateKey , accounts . Oracle . publicKey ) ;
47
+
48
+ // Oracle gets encrypted message from Owner and decrypted it
49
+ const decryptedMessageFromOwnerToOracle = await decryptIM ( encryptedMessageForOracle , accounts . Oracle . privateKey , accounts . Owner . publicKey )
50
+
51
+ expect ( decryptedMessageFromOwnerToOracle ) . to . equal ( encryptedMessage )
52
+ } )
53
+
54
+ it ( "create new account using ether.js and private key" , async function ( ) {
55
+ const message = "Hello, world!" ;
56
+
57
+ // Encrypting a message from Owner to Heir
58
+ const encryptedMessage = await encryptIM ( message , accounts . Owner . privateKey , accounts . Heir . publicKey ) ;
59
+
60
+ // Owner encrypting message for Oracle and send it
61
+ const encryptedMessageForOracle = await encryptIM ( encryptedMessage , accounts . Owner . privateKey , accounts . Oracle . publicKey ) ;
62
+
63
+ // Oracle gets encrypted message from Owner and decrypted it
64
+ const decryptedMessageFromOwnerToOracle = await decryptIM ( encryptedMessageForOracle , accounts . Oracle . privateKey , accounts . Owner . publicKey )
65
+
66
+ // Heir gets encrypt message from Oracle
67
+ const decryptedMessageFromOwnetToHeir = await decryptIM ( decryptedMessageFromOwnerToOracle , accounts . Heir . privateKey , accounts . Owner . publicKey )
68
+
69
+ expect ( decryptedMessageFromOwnetToHeir ) . to . equal ( message )
70
+ } )
36
71
} ) ;
0 commit comments