-
Notifications
You must be signed in to change notification settings - Fork 0
/
HomomorphicTransaction_test.js
162 lines (155 loc) · 3 KB
/
HomomorphicTransaction_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
const addr = "0xe8e7c10967dbe7f3fbfe381db73dd16af9e5e33c";
const Web3 = require('web3');
const elliptic = require('elliptic');
const ec = elliptic.ec("secp256k1");
const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545/'))
const BN = require("bn.js");
const SHA3 = require('sha3');
function calculate_addr(key) {
const d = new SHA3.SHA3Hash(256)
d.update(Buffer.from(key.pub.x.toString('hex') + key.pub.y.toString('hex'), 'hex'))
return '0x' + d.digest('hex').slice(24)
}
const k1 = ec.keyFromPrivate("test sono itchi dayo")
k1.getPublic();
const k1addr = calculate_addr(k1); // 0xd4be9d252318628613b786c893560152c711763d
const k2 = ec.keyFromPrivate("test sono ni dayo wowowow")
k2.getPublic();
const k2addr = calculate_addr(k2); // 0xbde7a982a5da1d64dabb867db6d015384e67bda6
const hom = new web3.eth.Contract([
{
"constant": true,
"inputs": [
{
"name": "",
"type": "uint256"
},
{
"name": "",
"type": "uint256"
},
{
"name": "",
"type": "uint256"
}
],
"name": "txouts",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "uint256"
}
],
"name": "isSpent",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_outputs",
"type": "uint256[3][]"
}
],
"name": "mint",
"outputs": [],
"payable": true,
"stateMutability": "payable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "numTxs",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_inputs",
"type": "uint256[5][]"
},
{
"name": "_outputs",
"type": "uint256[3][]"
}
],
"name": "createTransaction",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "uint256"
},
{
"name": "",
"type": "uint256"
},
{
"name": "",
"type": "uint256"
}
],
"name": "txins",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "index",
"type": "uint256"
}
],
"name": "NewTransaction",
"type": "event"
}
], addr);
one_ether = "1000000000000000000";
one_ether_encrypted = ec.g.mul(new bn(one_ether));
// [["0x29f1348bd6c634cc19c31aec3bb052a3bef0f603c73997fb0f841c12d236d372", "0xee4f8cbcd1b522c4949168ca9f9731f261de719dbf8aaab488b8801c8dd3b2a7", "0xd4be9d252318628613b786c893560152c711763d"]]
mint([[one_ether_encrypted.x.toString(), one_ether_encrypted.y.toString(), k1addr]], {value: one_ether});