Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
1578dafa
Commit
1578dafa
authored
Oct 26, 2020
by
pengjun
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'paillier'
parents
ea08eae7
4b93825f
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
217 additions
and
4 deletions
+217
-4
paillier.go
plugin/crypto/paillier/paillier.go
+88
-0
paillier_test.go
plugin/crypto/paillier/paillier_test.go
+18
-0
exec.go
plugin/dapp/storage/executor/exec.go
+6
-0
exec_local.go
plugin/dapp/storage/executor/exec_local.go
+21
-0
storage_test.go
plugin/dapp/storage/executor/storage_test.go
+22
-0
storagedb.go
plugin/dapp/storage/executor/storagedb.go
+44
-0
storage.proto
plugin/dapp/storage/proto/storage.proto
+12
-2
types.go
plugin/dapp/storage/rpc/types.go
+1
-2
storage.go
plugin/dapp/storage/types/storage.go
+5
-0
storage.pb.go
plugin/dapp/storage/types/storage.pb.go
+0
-0
No files found.
plugin/crypto/paillier/paillier.go
0 → 100644
View file @
1578dafa
package
paillier
import
(
"bytes"
"encoding/binary"
"encoding/hex"
"fmt"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/types"
"math/big"
)
func
CiphertextAdd
(
ciphertext1
,
ciphertext2
string
)
(
string
,
error
)
{
cipherbytes1
,
err
:=
common
.
FromHex
(
ciphertext1
)
if
err
!=
nil
{
fmt
.
Errorf
(
"CiphertextAdd.FromHex. ciphertext1:%s, error:%v"
,
ciphertext1
,
err
)
return
""
,
err
}
cipherbytes2
,
err
:=
common
.
FromHex
(
ciphertext2
)
if
err
!=
nil
{
fmt
.
Errorf
(
"CiphertextAdd.FromHex. ciphertext2:%s, error:%v"
,
ciphertext2
,
err
)
return
""
,
err
}
res
,
err
:=
CiphertextAddBytes
(
cipherbytes1
,
cipherbytes2
)
if
err
!=
nil
{
fmt
.
Errorf
(
"CiphertextAdd.CiphertextAddBytes. error:%v"
,
err
)
return
""
,
nil
}
return
hex
.
EncodeToString
(
res
),
nil
}
func
CiphertextAddBytes
(
cipherbytes1
,
cipherbytes2
[]
byte
)
([]
byte
,
error
)
{
nlen1
:=
bytesToInt
(
cipherbytes1
[
0
:
2
])
if
nlen1
>=
len
(
cipherbytes1
)
-
2
{
fmt
.
Errorf
(
"CiphertextAddBytes. error param length"
)
return
nil
,
types
.
ErrInvalidParam
}
nBytes1
:=
make
([]
byte
,
nlen1
)
copy
(
nBytes1
,
cipherbytes1
[
2
:
2
+
nlen1
])
nlen2
:=
bytesToInt
(
cipherbytes2
[
0
:
2
])
if
nlen2
>=
len
(
cipherbytes2
)
-
2
{
fmt
.
Errorf
(
"CiphertextAddBytes. error param length"
)
return
nil
,
types
.
ErrInvalidParam
}
nBytes2
:=
make
([]
byte
,
nlen2
)
copy
(
nBytes2
,
cipherbytes2
[
2
:
2
+
nlen2
])
if
!
bytes
.
Equal
(
nBytes1
,
nBytes2
)
{
fmt
.
Errorf
(
"CiphertextAddBytes. error: param error n1!=n2"
)
return
nil
,
types
.
ErrInvalidParam
}
data1
:=
make
([]
byte
,
len
(
cipherbytes1
)
-
nlen1
-
2
)
copy
(
data1
,
cipherbytes1
[
2
+
nlen1
:
])
data2
:=
make
([]
byte
,
len
(
cipherbytes2
)
-
nlen2
-
2
)
copy
(
data2
,
cipherbytes2
[
2
+
nlen2
:
])
cipher1
:=
new
(
big
.
Int
)
.
SetBytes
(
data1
)
cipher2
:=
new
(
big
.
Int
)
.
SetBytes
(
data2
)
n1
:=
new
(
big
.
Int
)
.
SetBytes
(
nBytes1
)
nsquare
:=
new
(
big
.
Int
)
.
Mul
(
n1
,
n1
)
res
:=
big
.
NewInt
(
0
)
res
.
Mul
(
cipher1
,
cipher2
)
.
Mod
(
res
,
nsquare
)
data
:=
make
([]
byte
,
nlen1
+
2
+
len
(
res
.
Bytes
()))
copy
(
data
[
:
nlen1
+
2
],
cipherbytes1
[
:
nlen1
+
2
])
copy
(
data
[
nlen1
+
2
:
],
res
.
Bytes
())
return
data
,
nil
}
func
bytesToInt
(
cipherbytes
[]
byte
)
int
{
bytebuff
:=
bytes
.
NewBuffer
(
cipherbytes
)
var
data
int16
binary
.
Read
(
bytebuff
,
binary
.
BigEndian
,
&
data
)
return
int
(
data
)
}
\ No newline at end of file
plugin/crypto/paillier/paillier_test.go
0 → 100644
View file @
1578dafa
package
paillier
import
(
"github.com/stretchr/testify/assert"
"testing"
)
func
TestCiphertextAdd
(
t
*
testing
.
T
)
{
c1
:=
"010070061bde0fc57d38e0ce9c82c088f793a93a20f830ed94a5f7e01f5af0decccf0ee7f70a711dc78b69b40f7e411f7f6ff34a5de4ad32fa5dc9d09b09dbbcf8e49bb1c9be19b215577167458b969bb40634f71dba00bdfdd12f1c878effd9e08475b8301a214bc7dfc95c2f341aa8fbd985a5da05af046336c23cf356570772530017c9a8bb96140977698d50c3258e8d31c040bb887c56d3d6e583db7a4ff2ea28aa93885312dfa50bf86a15618288b2c2701e6d75743fec9f3ca35b7e20ad902ad6985fe0b3c389b9582b3c62d9bea90230d1512a07c66a5404bf804693b6bb677a4ff038ae4a762f89f6a877d7621f7461431a7d4cadaf1687057ca4a9d1570e4ceeab32c86856d89731d50edf6f0886ccf348cc4565227f1df6b813569c49b3170e9efd722e4f4e957add9a115a2122a9f5c00780a1b8020d44b8b865d16113eadcfd15d1b755aed7c983b3d4b9390eda68d22d165a32d4055eee95adee79d7d28d2ee6d593d4eff217cd3e3d70bb9c32a6608af78afb7d5cb7ee0422500273b934209b950cd07842ab7e10c0dfc790d212c9085058d39c667b7dfff0963478118451ec64af30aff518384cc47758b2aa4331c8b5f36d6d1b9c3a6ee7ba77d28ea6ca844960e24ab6384e36127745f1285f3b71cea6c5c6a41c51ca7edbfae07766a3fb7bd9ef6b8f999460741a5b44eeb0b98937b57f4582294e18fd70d402dee2e557fa7df5cfb13240458f77b62a32169940ab5a1fce95b52583ecb13e21c22749f7620caaa6fd998e4f9bd0e617c925b83bed5ed2215ec8a404357a782b70d2c6ece6fa7a4fb30d18a01b81b2f3a8e38cc12f32becfdf195e02879b710f2feda5b0c2e86ba6df2a0fa25c60cef58224ee466787034cc5d0872a28cf8d6bad106125660b0b4bfe86eacb829dbb073420ff3af3ac76e5718c199fcf53258397a9e4fed0d98f360d16248693aced1ecbc5ca5211f48df011d14d372ee07f9b7c24bc219f3cdc403ebeb5b452643ddd1f4276779fab76a19c8b195a1213a235f7facf67a26b8a7804cb326f58200d756d62d40edb650498c198a524c091f0"
c2
:=
"010070061bde0fc57d38e0ce9c82c088f793a93a20f830ed94a5f7e01f5af0decccf0ee7f70a711dc78b69b40f7e411f7f6ff34a5de4ad32fa5dc9d09b09dbbcf8e49bb1c9be19b215577167458b969bb40634f71dba00bdfdd12f1c878effd9e08475b8301a214bc7dfc95c2f341aa8fbd985a5da05af046336c23cf356570772530017c9a8bb96140977698d50c3258e8d31c040bb887c56d3d6e583db7a4ff2ea28aa93885312dfa50bf86a15618288b2c2701e6d75743fec9f3ca35b7e20ad902ad6985fe0b3c389b9582b3c62d9bea90230d1512a07c66a5404bf804693b6bb677a4ff038ae4a762f89f6a877d7621f7461431a7d4cadaf1687057ca4a9d157195acafe73f5eed77b314dd640999ee20de461600ce3d3620cef84abc256774a514db5b65721cd93d1601e0fa8f53630dbe8567493018588e9619783e1526eb9bc56cc7b37c99025a9bdc10465bfb01605232292e50ac3b56b2ffefe48f0615651649d1db4ebff57d955e434f0c564b2a6842d3af04be1bfc5e968abe390f15bc89b9a4ed7a00b82beea07cf8e03c82bdd6a40b6c6334e51a432024caf9247db25058eb0cbce567ed49c56730058480e5854f3888e988053c403045239098ba6977aa0adb7f6dec785d31bacee8276a87d7a8f2114bb6662a117e3e37846c5b713e599801fbae5185cf21360760721376efe0736b7f4fa049d0c9f3086324be3a0f44d6cae5450d87d79a7bcaa0a2aa259b738ed85a59fead48d985597f6d77022ecdf37685df4182267d4fbdb24747f208a9e1b3126251b320066d8499ab5298395dab0340a78325b39d383d34a31a27f223114a9774498a314e3ba3cf4b87150e1f959f29556e67ae136a6290922e8cd3890c3b93bb68f38990ac3a4700cbe075795f7603755a28f3226e31c29a2eab2bff2423dc6177a6d8eaa950fbe2320b9bee89b8bbc3149b7ee177224e59726f28bcb796ccb09ac6b3feb3256ca033eb177aeea997be798f0e1b63b284dc8361ff870de717263cb86838a0c6cd5a82e12d162bd04f9c85267d4abd3a6828639fd0584a023388cc220d404d4646d0318"
c3
:=
"010070061bde0fc57d38e0ce9c82c088f793a93a20f830ed94a5f7e01f5af0decccf0ee7f70a711dc78b69b40f7e411f7f6ff34a5de4ad32fa5dc9d09b09dbbcf8e49bb1c9be19b215577167458b969bb40634f71dba00bdfdd12f1c878effd9e08475b8301a214bc7dfc95c2f341aa8fbd985a5da05af046336c23cf356570772530017c9a8bb96140977698d50c3258e8d31c040bb887c56d3d6e583db7a4ff2ea28aa93885312dfa50bf86a15618288b2c2701e6d75743fec9f3ca35b7e20ad902ad6985fe0b3c389b9582b3c62d9bea90230d1512a07c66a5404bf804693b6bb677a4ff038ae4a762f89f6a877d7621f7461431a7d4cadaf1687057ca4a9d1571d74c0a358b73242b65cf84139071503ffa45c824d84cb0336510de9a1ad1a7c56142efa23f8b69b4094c940adb42df385fc11bf2704a2608b1a65c5d17f2a051114832ab141290c16201b59eae28639ece329eb5b8003b4f1025e57066115d7d378581268359e0ca94117451ca3aa6b0d597cf8f621b66bf20fc488b18848aa47e31d5939d59b8058def7df416f6734b3821bacd1fc8f4f1d422fc2c17c9bd903e80fabea7eb0f6237f771d0be65941cfca8ed6ec0e412bc940fc09cb0033abe4e668fee7f07a9cba77da04815747271eb32a5a9278ca0f57d7e05cffa6bdb5902984586259fab80be0460e9af3391f2a3212a1e4f350e060f988781e6ab2254e76c972e5611151fa501607d1d342667253d21e9ca113f2b87d823a55e70d4f5899e0ba8121477dded3d3b858438c4d0486a0c9846eb05b737a734ba37cdfdaaca8a4a38f2bd1c1ed0b4583b96c2fd2d1675991b4a151470811b4f4bfbad46ddbaa0e1fa28a81a3801e8c211137db822fb5a07344dc719b13e50562bd1e3a391a7747709db2445543f7412fd9c3011141d9ad4f05182593e6e75033764395fa8be80039cb47ed5d750f62836312e7b23152f69a65e41a9782d841b3c48719403e98bd8e72c824083275a29a53d681dc25b7df6c60cb0c4c74feab1d7b1edc76c09a1fe4da1acf9979d3c200233b082f66710725867ef6418e866cd93d26c7fd"
data
,
err
:=
CiphertextAdd
(
c1
,
c2
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
c3
,
data
)
}
plugin/dapp/storage/executor/exec.go
View file @
1578dafa
...
...
@@ -35,3 +35,8 @@ func (s *storage) Exec_EncryptShareStorage(payload *storagetypes.EncryptShareNot
action
:=
newStorageAction
(
s
,
tx
,
index
)
return
action
.
EncryptShareStorage
(
payload
)
}
func
(
s
*
storage
)
Exec_EncryptAdd
(
payload
*
storagetypes
.
EncryptNotaryAdd
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
newStorageAction
(
s
,
tx
,
index
)
return
action
.
EncryptAdd
(
payload
)
}
\ No newline at end of file
plugin/dapp/storage/executor/exec_local.go
View file @
1578dafa
...
...
@@ -115,6 +115,27 @@ func (s *storage) ExecLocal_EncryptShareStorage(payload *ety.EncryptShareNotaryS
return
s
.
addAutoRollBack
(
tx
,
dbSet
.
KV
),
nil
}
func
(
s
*
storage
)
ExecLocal_EncryptAdd
(
payload
*
ety
.
EncryptNotaryAdd
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
dbSet
:=
&
types
.
LocalDBSet
{}
cfg
:=
s
.
GetAPI
()
.
GetConfig
()
if
cfg
.
IsDappFork
(
s
.
GetHeight
(),
ety
.
StorageX
,
ety
.
ForkStorageLocalDB
)
{
if
receiptData
.
Ty
==
types
.
ExecOk
{
for
_
,
log
:=
range
receiptData
.
Logs
{
switch
log
.
Ty
{
case
ety
.
TyEncryptAddLog
:
storage
:=
&
ety
.
Storage
{}
if
err
:=
types
.
Decode
(
log
.
Log
,
storage
);
err
!=
nil
{
return
nil
,
err
}
kv
:=
&
types
.
KeyValue
{
Key
:
getLocalDBKey
(
storage
.
GetEncryptStorage
()
.
Key
),
Value
:
types
.
Encode
(
storage
)}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kv
)
}
}
}
}
return
s
.
addAutoRollBack
(
tx
,
dbSet
.
KV
),
nil
}
//设置自动回滚
func
(
s
*
storage
)
addAutoRollBack
(
tx
*
types
.
Transaction
,
kv
[]
*
types
.
KeyValue
)
*
types
.
LocalDBSet
{
...
...
plugin/dapp/storage/executor/storage_test.go
View file @
1578dafa
...
...
@@ -165,6 +165,28 @@ func TestStorage(t *testing.T) {
assert
.
Equal
(
t
,
common
.
Sha256
(
contents
[
0
]),
reply
.
GetEncryptStorage
()
.
ContentHash
)
assert
.
Equal
(
t
,
crypted
,
reply
.
GetEncryptStorage
()
.
EncryptContent
)
assert
.
Equal
(
t
,
ivs
[
0
],
reply
.
GetEncryptStorage
()
.
Nonce
)
// 同态加密
c1
,
_
:=
common
.
FromHex
(
"010076833cbc35c9b7a87eda9aab7aafec45bd7eb8c0e9306141e7d1e84ecd87a5cb9f80343551bd9b0d04669fd74d020fca8837d9b3b471e3e13c125a06663d820cabb36c243747a11ea2601a9cb32e61c697dcdc846c492d954fa8c3ca2be662e8c0142138b647ce5d9e7c4c4d2ace8ba3c5699fbec98beef24e3c740967ec0b72b1626ecd4a7ce54960ae9bc1e2ea5594b05778f4f772aa213a06421744ed8dd775fb8f212bcc7e0da5fe4949051e6aa09d47db7e8d5028ecc41cea2aed4e23aefd80714519662fae980e3a6ca3defc0dd5596cb7e90da29e1bdd84db82603aed78fb8f98687898cd675da74452052ff1761446bf2ee922fc8c56b7e1beb2d4b91042742837052b340e4afce1836badf4a56ef775bb6a94fd91686a44122543fdab3ee90488160068769fbce2e74ffd5e052bb4c651969c4755f6eb5d7ea0cee3e7fa58f4b38b1722535909bd0f325a0b8d0797c15300ab06095b305f46497bbd75c3682d379387f55f638cd10639db1f050090bfd5d291718cee9fc6894d04ba6ef0acb477184512984f435b13e9bffe630bbc8ceade6d269487bf219e25b3beecc46afb98fb8e1fec1a9ad0af0a16e70611f9a4337af05a2ff82d7c9dcebeea9d8e2070413e49e29ff564e6dcee5696e39dc590ff8f8f553834c66c5ae730d05441e3fcc59de0d6efb12fd8852e19f2e309e4ac4cbf0634655fcaab5a70b4eab49829190ea2862c2568e8b69ff0324055f92275de05f2de1d6a8a78333370da754708f7a827f5e9bbe2e58d58294cafef37898a5a5a4866678b6e07941a3bfcb3c3f2d150f830a12d8e0dd20d756099be48f10d51521b3ba0c49f2ab139724ae3962999d75b88bf572fbfd86b6eef3bad5a446b97949d95f9e742500f8609ecfe189d2b4d5a47ea997164f48b3872ec525f16ec23fa5700d10d3385019edfabfec780f15b639f6863332c69fe6b17895620821fe6aaf94caab29c0fec19ff1bebc59f5ed8f973a3b720257cce803541406ae8e75163cf0049f8fbf14d239e86089cdefba8bcbb03db284283a1ff572320aeb7d4a139d4429e00c8bb196539d7"
)
c2
,
_
:=
common
.
FromHex
(
"010076833cbc35c9b7a87eda9aab7aafec45bd7eb8c0e9306141e7d1e84ecd87a5cb9f80343551bd9b0d04669fd74d020fca8837d9b3b471e3e13c125a06663d820cabb36c243747a11ea2601a9cb32e61c697dcdc846c492d954fa8c3ca2be662e8c0142138b647ce5d9e7c4c4d2ace8ba3c5699fbec98beef24e3c740967ec0b72b1626ecd4a7ce54960ae9bc1e2ea5594b05778f4f772aa213a06421744ed8dd775fb8f212bcc7e0da5fe4949051e6aa09d47db7e8d5028ecc41cea2aed4e23aefd80714519662fae980e3a6ca3defc0dd5596cb7e90da29e1bdd84db82603aed78fb8f98687898cd675da74452052ff1761446bf2ee922fc8c56b7e1beb2d4b9338ddba1f37e26ef7e0b9cb3bec18dc4b450d91a1a0901a3aca75000b58dd639635dce66553945a698b186c89443361ab4c1d3525de6bace217cd27fce0c8f6efc9e7c95269139487b5772182d8276ed6edfe0560537d18330aae4191af1dfae0a430b2021401bc17a111730f7114f514b7b84cb09bf717c67bb25c21a31b3a062f32dceb99103cdd622242148ec1799d04f4f3f4fc5af9e18cfaf356388b1413cc95b6f5bc0c293acf09ad0513e15d2ea525f120930e6072e0cf750e4e03bbf65b278ad92476f5e507bb51f01c3d2797931794cad156b5980fb5ec51fc82e99fde99e81dd85e9dba1d549aa8768c609e46171750b7bc636b709e47c92b076f1b7f71bff1fd690f8bfcdbf48559f777017b9ad300cbb3a1089f3eb6fed5632be9edecc33be09da7d43275640a097114f8f9e529289cce15d7b4ba613feda9e4d818743bf2741c5cd2aaaec7cc96ed835ee909ea0e9675f57bad4ad01688cc2a77e6181a0bca9a46d0ca160a1d94771e24db357e861e1f029104782445413c6d4861404df9ec3140b895083ebbb8a92bbc7decc8990353e9347a7933f85ef94ed325a331b3e6e6c752086adc7926abac3dfd8c8f3d7add64c80f327c1c4d74fde7a6c8981f79ede165f0584e5d6317d7272d9836098cd8ef82fbe85770962b709dfe1f2ae3454ac471e6ea24c6545f332a3eb4eecbc09e2276748d484a5216361"
)
c3
,
_
:=
common
.
FromHex
(
"010076833cbc35c9b7a87eda9aab7aafec45bd7eb8c0e9306141e7d1e84ecd87a5cb9f80343551bd9b0d04669fd74d020fca8837d9b3b471e3e13c125a06663d820cabb36c243747a11ea2601a9cb32e61c697dcdc846c492d954fa8c3ca2be662e8c0142138b647ce5d9e7c4c4d2ace8ba3c5699fbec98beef24e3c740967ec0b72b1626ecd4a7ce54960ae9bc1e2ea5594b05778f4f772aa213a06421744ed8dd775fb8f212bcc7e0da5fe4949051e6aa09d47db7e8d5028ecc41cea2aed4e23aefd80714519662fae980e3a6ca3defc0dd5596cb7e90da29e1bdd84db82603aed78fb8f98687898cd675da74452052ff1761446bf2ee922fc8c56b7e1beb2d4b90a734625f41c1709ad56e8a801346d70f190e7080c805de1e380198a4ebaf86ca6e5b9dbdc6eacad7c545f78c718a6e0262bc61d68244f99255d0fc8126cfbc0449e935bf5ee81af5e600f7d5b23b4b2d1f48482e037642690035f0289d4d3c72662d63e958edf8d566c765bcbc44cedc618b31db5eebdc6fd5848d53161e3e01c6c73010c32391db709a71cedb4c45fb71ec85de48ace0cba009ef2c0a88386e62b9607faf36c9b219508281267c0df2a182a88ad8fd146101564f5a14c7fd5ed2d4ae547c8741a31c560501230edd5417c622a7aba8d7efb08c08d5b7c45508c766353f2d43bd092834461f0673196abc8ef56b9fd54bdf82c2a392ff8dedcef3d90d3e47370d31083c2d19cefe2ce83936fd881f4a38ef3e5aaf3b0d48842ded5e6a16fc2fb7b5379406c2889e1d9de1fe611645310ba5b5048e817f44c451b5ec557c0e3b8e64049a437b82f901866ba4c1994d3c3caf02f81582f7409d10480df2c353eb63db4ec57671b2ac6c28fce842c605bae902ac5bb649f08199307458b542849d663809c9980a7c939b4f1f6d2eddf3dfe02f70ee4cf8956bf7a6a29a307939cd17eebdbcc80fb830bd545351a12c275375feaf3f690c52cc76dc7521ce87f621163b551a70e06d5bd3274bdc144f61f4ff8f1cdb2fcf97c67df1935057fdadaa23bf675892b4db841a63d49cd788c34498c70fb4ea787f3f8c1"
)
tx
,
err
=
CreateTx
(
"EncryptStorage"
,
&
oty
.
EncryptNotaryStorage
{
ContentHash
:
common
.
Sha256
(
c1
),
EncryptContent
:
c1
,
Nonce
:
ivs
[
0
]},
PrivKeyA
,
cfg
)
assert
.
Nil
(
t
,
err
)
Exec_Block
(
t
,
stateDB
,
kvdb
,
env
,
tx
)
txhash
=
common
.
ToHex
(
tx
.
Hash
())
reply
,
err
=
QueryStorageByKey
(
stateDB
,
kvdb
,
txhash
,
cfg
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
common
.
Sha256
(
c1
),
reply
.
GetEncryptStorage
()
.
ContentHash
)
assert
.
Equal
(
t
,
c1
,
reply
.
GetEncryptStorage
()
.
EncryptContent
)
tx
,
err
=
CreateTx
(
"EncryptAdd"
,
&
oty
.
EncryptNotaryAdd
{
Key
:
txhash
,
EncryptAdd
:
c2
},
PrivKeyA
,
cfg
)
assert
.
Nil
(
t
,
err
)
Exec_Block
(
t
,
stateDB
,
kvdb
,
env
,
tx
)
reply
,
err
=
QueryStorageByKey
(
stateDB
,
kvdb
,
txhash
,
cfg
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
c3
,
reply
.
GetEncryptStorage
()
.
EncryptContent
)
}
func
signTx
(
tx
*
types
.
Transaction
,
hexPrivKey
string
)
(
*
types
.
Transaction
,
error
)
{
...
...
plugin/dapp/storage/executor/storagedb.go
View file @
1578dafa
...
...
@@ -2,6 +2,7 @@ package executor
import
(
"fmt"
"github.com/33cn/plugin/plugin/crypto/paillier"
"github.com/33cn/chain33/client"
"github.com/33cn/chain33/common"
...
...
@@ -190,6 +191,49 @@ func (s *StorageAction) EncryptShareStorage(payload *ety.EncryptShareNotaryStora
return
receipt
,
nil
}
//EncryptAdd ...
func
(
s
*
StorageAction
)
EncryptAdd
(
payload
*
ety
.
EncryptNotaryAdd
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
kvs
[]
*
types
.
KeyValue
cfg
:=
s
.
api
.
GetConfig
()
store
,
err
:=
QueryStorage
(
s
.
db
,
s
.
localdb
,
payload
.
Key
)
if
err
!=
nil
{
fmt
.
Errorf
(
"EncryptAdd.QueryStorage. err:%v"
,
err
)
return
nil
,
err
}
cipherText
:=
store
.
GetEncryptStorage
()
.
EncryptContent
res
,
err
:=
paillier
.
CiphertextAddBytes
(
cipherText
,
payload
.
EncryptAdd
)
if
err
!=
nil
{
fmt
.
Errorf
(
"EncryptAdd.CiphertextAddBytes. err:%v"
,
err
)
return
nil
,
err
}
store
.
GetEncryptStorage
()
.
EncryptContent
=
res
newStore
:=
&
ety
.
EncryptNotaryStorage
{
ContentHash
:
store
.
GetEncryptStorage
()
.
ContentHash
,
EncryptContent
:
res
,
Nonce
:
store
.
GetEncryptStorage
()
.
Nonce
,
Key
:
store
.
GetEncryptStorage
()
.
Key
,
Value
:
store
.
GetEncryptStorage
()
.
Value
,
}
if
cfg
.
IsDappFork
(
s
.
height
,
ety
.
StorageX
,
ety
.
ForkStorageLocalDB
)
{
stg
:=
&
ety
.
Storage
{
Value
:
&
ety
.
Storage_EncryptStorage
{
EncryptStorage
:
newStore
},
Ty
:
ety
.
TyEncryptStorageAction
}
log
:=
&
types
.
ReceiptLog
{
Ty
:
ety
.
TyEncryptAddLog
,
Log
:
types
.
Encode
(
stg
)}
logs
=
append
(
logs
,
log
)
}
else
{
log
:=
&
types
.
ReceiptLog
{
Ty
:
ety
.
TyEncryptAddLog
}
logs
=
append
(
logs
,
log
)
kvs
=
append
(
kvs
,
&
types
.
KeyValue
{
Key
:
Key
(
payload
.
Key
),
Value
:
types
.
Encode
(
newStore
)})
}
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kvs
,
Logs
:
logs
}
return
receipt
,
nil
}
//QueryStorageByTxHash ...
func
QueryStorageByTxHash
(
db
dbm
.
KV
,
txhash
string
)
(
*
ety
.
Storage
,
error
)
{
data
,
err
:=
db
.
Get
(
Key
(
txhash
))
...
...
plugin/dapp/storage/proto/storage.proto
View file @
1578dafa
...
...
@@ -8,8 +8,9 @@ message Storage {
LinkNotaryStorage
linkStorage
=
3
;
EncryptNotaryStorage
encryptStorage
=
4
;
EncryptShareNotaryStorage
encryptShareStorage
=
5
;
EncryptNotaryAdd
encryptAdd
=
6
;
}
int32
ty
=
6
;
int32
ty
=
7
;
}
message
StorageAction
{
...
...
@@ -19,8 +20,9 @@ message StorageAction {
LinkNotaryStorage
linkStorage
=
3
;
EncryptNotaryStorage
encryptStorage
=
4
;
EncryptShareNotaryStorage
encryptShareStorage
=
5
;
EncryptNotaryAdd
encryptAdd
=
6
;
}
int32
ty
=
6
;
int32
ty
=
7
;
}
// 内容存证模型
message
ContentOnlyNotaryStorage
{
...
...
@@ -85,6 +87,14 @@ message EncryptShareNotaryStorage {
string
value
=
5
;
}
// 加密存证数据运算
message
EncryptNotaryAdd
{
//源操作数存证索引
string
key
=
1
;
//待操作数据
bytes
encryptAdd
=
2
;
}
service
storage
{}
//根据txhash去状态数据库中查询存储内容
message
QueryStorage
{
...
...
plugin/dapp/storage/rpc/types.go
View file @
1578dafa
...
...
@@ -2,7 +2,6 @@ package rpc
import
(
rpctypes
"github.com/33cn/chain33/rpc/types"
storagetypes
"github.com/33cn/plugin/plugin/dapp/storage/types"
)
/*
...
...
@@ -30,5 +29,5 @@ func Init(name string, s rpctypes.RPCServer) {
grpc
:=
&
Grpc
{
channelClient
:
cli
}
cli
.
Init
(
name
,
s
,
&
Jrpc
{
cli
:
cli
},
grpc
)
//存在grpc service时注册grpc server,需要生成对应的pb.go文件
storagetypes
.
RegisterStorageServer
(
s
.
GRPC
(),
grpc
)
//
storagetypes.RegisterStorageServer(s.GRPC(), grpc)
}
plugin/dapp/storage/types/storage.go
View file @
1578dafa
...
...
@@ -20,12 +20,14 @@ const (
TyLinkStorageAction
TyEncryptStorageAction
TyEncryptShareStorageAction
TyEncryptAddAction
NameContentStorageAction
=
"ContentStorage"
NameHashStorageAction
=
"HashStorage"
NameLinkStorageAction
=
"LinkStorage"
NameEncryptStorageAction
=
"EncryptStorage"
NameEncryptShareStorageAction
=
"EncryptShareStorage"
NameEncryptAddAction
=
"EncryptAdd"
FuncNameQueryStorage
=
"QueryStorage"
FuncNameBatchQueryStorage
=
"BatchQueryStorage"
...
...
@@ -39,6 +41,7 @@ const (
TyLinkStorageLog
TyEncryptStorageLog
TyEncryptShareStorageLog
TyEncryptAddLog
)
//storage op
...
...
@@ -61,6 +64,7 @@ var (
NameLinkStorageAction
:
TyLinkStorageAction
,
NameEncryptStorageAction
:
TyEncryptStorageAction
,
NameEncryptShareStorageAction
:
TyEncryptShareStorageAction
,
NameEncryptAddAction
:
TyEncryptAddAction
,
}
//定义log的id和具体log类型及名称,填入具体自定义log类型
logMap
=
map
[
int64
]
*
types
.
LogInfo
{
...
...
@@ -69,6 +73,7 @@ var (
TyLinkStorageLog
:
{
Ty
:
reflect
.
TypeOf
(
Storage
{}),
Name
:
"LogLinkStorage"
},
TyEncryptStorageLog
:
{
Ty
:
reflect
.
TypeOf
(
Storage
{}),
Name
:
"LogEncryptStorage"
},
TyEncryptShareStorageLog
:
{
Ty
:
reflect
.
TypeOf
(
Storage
{}),
Name
:
"LogEncryptShareStorage"
},
TyEncryptAddLog
:
{
Ty
:
reflect
.
TypeOf
(
Storage
{}),
Name
:
"LogEncryptAdd"
},
}
)
...
...
plugin/dapp/storage/types/storage.pb.go
View file @
1578dafa
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment