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
e4481593
Commit
e4481593
authored
Nov 20, 2018
by
sanghg
Committed by
vipwzw
Nov 21, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复隐私合约中golint的警告
修改crypto、executor中的golint警告
parent
f08844a1
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
214 additions
and
155 deletions
+214
-155
onetimeed25519.go
plugin/dapp/privacy/crypto/onetimeed25519.go
+11
-11
privacy.go
plugin/dapp/privacy/crypto/privacy.go
+40
-32
privacy_test.go
plugin/dapp/privacy/crypto/privacy_test.go
+2
-2
privatekey.go
plugin/dapp/privacy/crypto/privatekey.go
+13
-9
publickey.go
plugin/dapp/privacy/crypto/publickey.go
+12
-7
ring_signature.go
plugin/dapp/privacy/crypto/ring_signature.go
+14
-12
ring_signature_crypto.go
plugin/dapp/privacy/crypto/ring_signature_crypto.go
+23
-6
ring_signature_test.go
plugin/dapp/privacy/crypto/ring_signature_test.go
+29
-29
signature.go
plugin/dapp/privacy/crypto/signature.go
+10
-6
exec.go
plugin/dapp/privacy/executor/exec.go
+5
-2
exec_del_local.go
plugin/dapp/privacy/executor/exec_del_local.go
+3
-0
exec_local.go
plugin/dapp/privacy/executor/exec_local.go
+9
-6
kv.go
plugin/dapp/privacy/executor/kv.go
+18
-16
privacy.go
plugin/dapp/privacy/executor/privacy.go
+12
-8
query.go
plugin/dapp/privacy/executor/query.go
+13
-9
No files found.
plugin/dapp/privacy/crypto/onetimeed25519.go
View file @
e4481593
...
...
@@ -13,19 +13,19 @@ import (
privacytypes
"github.com/33cn/plugin/plugin/dapp/privacy/types"
)
type
O
neTimeEd25519
struct
{}
type
o
neTimeEd25519
struct
{}
func
init
()
{
crypto
.
Register
(
privacytypes
.
SignNameOnetimeED25519
,
&
O
neTimeEd25519
{})
crypto
.
Register
(
privacytypes
.
SignNameOnetimeED25519
,
&
o
neTimeEd25519
{})
}
func
(
onetime
*
O
neTimeEd25519
)
GenKey
()
(
crypto
.
PrivKey
,
error
)
{
func
(
onetime
*
o
neTimeEd25519
)
GenKey
()
(
crypto
.
PrivKey
,
error
)
{
privKeyPrivacyPtr
:=
&
PrivKeyPrivacy
{}
pubKeyPrivacyPtr
:=
&
PubKeyPrivacy
{}
copy
(
privKeyPrivacyPtr
[
:
PrivateKeyLen
],
crypto
.
CRandBytes
(
P
rivateKeyLen
))
copy
(
privKeyPrivacyPtr
[
:
privateKeyLen
],
crypto
.
CRandBytes
(
p
rivateKeyLen
))
addr32
:=
(
*
[
KeyLen32
]
byte
)(
unsafe
.
Pointer
(
privKeyPrivacyPtr
))
addr64
:=
(
*
[
P
rivateKeyLen
]
byte
)(
unsafe
.
Pointer
(
privKeyPrivacyPtr
))
addr64
:=
(
*
[
p
rivateKeyLen
]
byte
)(
unsafe
.
Pointer
(
privKeyPrivacyPtr
))
edwards25519
.
ScReduce
(
addr32
,
addr64
)
//to generate the publickey
...
...
@@ -38,16 +38,16 @@ func (onetime *OneTimeEd25519) GenKey() (crypto.PrivKey, error) {
return
*
privKeyPrivacyPtr
,
nil
}
func
(
onetime
*
O
neTimeEd25519
)
PrivKeyFromBytes
(
b
[]
byte
)
(
privKey
crypto
.
PrivKey
,
err
error
)
{
func
(
onetime
*
o
neTimeEd25519
)
PrivKeyFromBytes
(
b
[]
byte
)
(
privKey
crypto
.
PrivKey
,
err
error
)
{
if
len
(
b
)
!=
64
{
return
nil
,
errors
.
New
(
"invalid priv key byte"
)
}
privKeyBytes
:=
new
([
P
rivateKeyLen
]
byte
)
pubKeyBytes
:=
new
([
P
ublicKeyLen
]
byte
)
privKeyBytes
:=
new
([
p
rivateKeyLen
]
byte
)
pubKeyBytes
:=
new
([
p
ublicKeyLen
]
byte
)
copy
(
privKeyBytes
[
:
KeyLen32
],
b
[
:
KeyLen32
])
addr32
:=
(
*
[
KeyLen32
]
byte
)(
unsafe
.
Pointer
(
privKeyBytes
))
addr64
:=
(
*
[
P
rivateKeyLen
]
byte
)(
unsafe
.
Pointer
(
privKeyBytes
))
addr64
:=
(
*
[
p
rivateKeyLen
]
byte
)(
unsafe
.
Pointer
(
privKeyBytes
))
//to generate the publickey
var
A
edwards25519
.
ExtendedGroupElement
...
...
@@ -59,7 +59,7 @@ func (onetime *OneTimeEd25519) PrivKeyFromBytes(b []byte) (privKey crypto.PrivKe
return
PrivKeyPrivacy
(
*
privKeyBytes
),
nil
}
func
(
onetime
*
O
neTimeEd25519
)
PubKeyFromBytes
(
b
[]
byte
)
(
pubKey
crypto
.
PubKey
,
err
error
)
{
func
(
onetime
*
o
neTimeEd25519
)
PubKeyFromBytes
(
b
[]
byte
)
(
pubKey
crypto
.
PubKey
,
err
error
)
{
if
len
(
b
)
!=
32
{
return
nil
,
errors
.
New
(
"invalid pub key byte"
)
}
...
...
@@ -68,7 +68,7 @@ func (onetime *OneTimeEd25519) PubKeyFromBytes(b []byte) (pubKey crypto.PubKey,
return
PubKeyPrivacy
(
*
pubKeyBytes
),
nil
}
func
(
onetime
*
O
neTimeEd25519
)
SignatureFromBytes
(
b
[]
byte
)
(
sig
crypto
.
Signature
,
err
error
)
{
func
(
onetime
*
o
neTimeEd25519
)
SignatureFromBytes
(
b
[]
byte
)
(
sig
crypto
.
Signature
,
err
error
)
{
sigBytes
:=
new
([
64
]
byte
)
copy
(
sigBytes
[
:
],
b
[
:
])
return
SignatureOnetime
(
*
sigBytes
),
nil
...
...
plugin/dapp/privacy/crypto/privacy.go
View file @
e4481593
...
...
@@ -11,7 +11,7 @@ import (
"unsafe"
"github.com/33cn/chain33/common"
.
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/crypto/sha3"
"github.com/33cn/chain33/common/ed25519/edwards25519"
log
"github.com/33cn/chain33/common/log/log15"
...
...
@@ -22,11 +22,13 @@ import (
)
const
(
PublicKeyLen
=
32
PrivateKeyLen
=
64
KeyLen32
=
32
publicKeyLen
=
32
privateKeyLen
=
64
// KeyLen32 key Length
KeyLen32
=
32
)
// Privacy privacy struct type
type
Privacy
struct
{
ViewPubkey
PubKeyPrivacy
ViewPrivKey
PrivKeyPrivacy
...
...
@@ -34,28 +36,32 @@ type Privacy struct {
SpendPrivKey
PrivKeyPrivacy
}
type
E
llipticCurvePoint
[
32
]
byte
type
e
llipticCurvePoint
[
32
]
byte
type
sigcomm
struct
{
hash
[
32
]
byte
pubkey
E
llipticCurvePoint
comm
E
llipticCurvePoint
pubkey
e
llipticCurvePoint
comm
e
llipticCurvePoint
}
//
type
sigcommArray
[
32
*
3
]
byte
// KeyImage key image type
type
KeyImage
[
32
]
byte
var
(
E
rrViewPub
=
errors
.
New
(
"ErrViewPub"
)
E
rrSpendPub
=
errors
.
New
(
"ErrSpendPub"
)
E
rrViewSecret
=
errors
.
New
(
"ErrViewSecret"
)
E
rrSpendSecret
=
errors
.
New
(
"ErrSpendSecret"
)
E
rrNullRandInput
=
errors
.
New
(
"ErrNullRandInput"
)
e
rrViewPub
=
errors
.
New
(
"ErrViewPub"
)
e
rrSpendPub
=
errors
.
New
(
"ErrSpendPub"
)
e
rrViewSecret
=
errors
.
New
(
"ErrViewSecret"
)
e
rrSpendSecret
=
errors
.
New
(
"ErrSpendSecret"
)
e
rrNullRandInput
=
errors
.
New
(
"ErrNullRandInput"
)
)
var
privacylog
=
log
.
New
(
"module"
,
"crypto.privacy"
)
//////////////
// NewPrivacy create privacy object
func
NewPrivacy
()
*
Privacy
{
privacy
:=
&
Privacy
{}
GenerateKeyPair
(
&
privacy
.
SpendPrivKey
,
&
privacy
.
SpendPubkey
)
...
...
@@ -64,6 +70,7 @@ func NewPrivacy() *Privacy {
return
privacy
}
// NewPrivacyWithPrivKey create privacy from private key
func
NewPrivacyWithPrivKey
(
privKey
*
[
KeyLen32
]
byte
)
(
privacy
*
Privacy
,
err
error
)
{
privacylog
.
Info
(
"NewPrivacyWithPrivKey"
,
"input prikey"
,
common
.
Bytes2Hex
(
privKey
[
:
]))
hash
:=
sccrypto
.
HashAll
(
*
privKey
)
...
...
@@ -83,19 +90,19 @@ func NewPrivacyWithPrivKey(privKey *[KeyLen32]byte) (privacy *Privacy, err error
return
privacy
,
nil
}
//(A, B) => Hs(rA)G + B, rG=>R
//
GenerateOneTimeAddr
(A, B) => Hs(rA)G + B, rG=>R
//func GenerateOneTimeAddr(viewPub, spendPub, skAddr32 *[32]byte, outputIndex int64) (pubkeyOnetime, RtxPublicKey *[32]byte, errInfo error) {
func
GenerateOneTimeAddr
(
viewPub
,
spendPub
,
skAddr32
*
[
32
]
byte
,
outputIndex
int64
)
(
pubkeyOnetime
*
[
32
]
byte
,
errInfo
error
)
{
//to calculate rA
var
point
edwards25519
.
ExtendedGroupElement
if
res
:=
point
.
FromBytes
(
viewPub
);
!
res
{
return
nil
,
E
rrViewPub
return
nil
,
e
rrViewPub
}
//skAddr32 := (*[KeyLen32]byte)(unsafe.Pointer(sk))
if
!
edwards25519
.
ScCheck
(
skAddr32
)
{
privacylog
.
Error
(
"xxx GenerateOneTimeAddr Fail to do edwards25519.ScCheck with sk
\n
"
)
return
nil
,
E
rrViewSecret
return
nil
,
e
rrViewSecret
}
var
point2
edwards25519
.
ProjectiveGroupElement
zeroValue
:=
&
[
32
]
byte
{}
...
...
@@ -110,13 +117,13 @@ func GenerateOneTimeAddr(viewPub, spendPub, skAddr32 *[32]byte, outputIndex int6
//to calculate Hs(rA)G + B
var
B
edwards25519
.
ExtendedGroupElement
//A
if
res
:=
B
.
FromBytes
(
spendPub
);
!
res
{
return
nil
,
E
rrSpendPub
return
nil
,
e
rrSpendPub
}
//Hs(rA)
Hs
_r
A
:=
derivation2scalar
(
rA
,
outputIndex
)
Hs
R
A
:=
derivation2scalar
(
rA
,
outputIndex
)
var
A
edwards25519
.
ExtendedGroupElement
edwards25519
.
GeScalarMultBase
(
&
A
,
Hs
_r
A
)
edwards25519
.
GeScalarMultBase
(
&
A
,
Hs
R
A
)
//A.ToBytes(publicKey)
var
cachedA
edwards25519
.
CachedGroupElement
//Hs(rA)G
...
...
@@ -133,8 +140,8 @@ func GenerateOneTimeAddr(viewPub, spendPub, skAddr32 *[32]byte, outputIndex int6
return
}
//calculate Hs(aR) + b
func
RecoverOnetimePriKey
(
R
[]
byte
,
viewSecretKey
,
spendSecretKey
PrivKey
,
outputIndex
int64
)
(
PrivKey
,
error
)
{
//
RecoverOnetimePriKey
calculate Hs(aR) + b
func
RecoverOnetimePriKey
(
R
[]
byte
,
viewSecretKey
,
spendSecretKey
crypto
.
PrivKey
,
outputIndex
int64
)
(
crypto
.
PrivKey
,
error
)
{
var
viewSecAddr
,
spendSecAddr
,
RtxPubAddr
*
[
32
]
byte
viewSecAddr
=
(
*
[
32
]
byte
)(
unsafe
.
Pointer
(
&
viewSecretKey
.
Bytes
()[
0
]))
spendSecAddr
=
(
*
[
32
]
byte
)(
unsafe
.
Pointer
(
&
spendSecretKey
.
Bytes
()[
0
]))
...
...
@@ -143,12 +150,12 @@ func RecoverOnetimePriKey(R []byte, viewSecretKey, spendSecretKey PrivKey, outpu
var
point
edwards25519
.
ExtendedGroupElement
if
res
:=
point
.
FromBytes
(
RtxPubAddr
);
!
res
{
privacylog
.
Error
(
"RecoverOnetimePriKey Fail to do get point.FromBytes with viewSecAddr
\n
"
)
return
nil
,
E
rrViewSecret
return
nil
,
e
rrViewSecret
}
if
!
edwards25519
.
ScCheck
(
viewSecAddr
)
{
privacylog
.
Error
(
"xxx RecoverOnetimePriKey Fail to do edwards25519.ScCheck with viewSecAddr
\n
"
)
return
nil
,
E
rrViewSecret
return
nil
,
e
rrViewSecret
}
var
point2
edwards25519
.
ProjectiveGroupElement
...
...
@@ -163,21 +170,21 @@ func RecoverOnetimePriKey(R []byte, viewSecretKey, spendSecretKey PrivKey, outpu
if
!
edwards25519
.
ScCheck
(
spendSecAddr
)
{
privacylog
.
Error
(
"xxx RecoverOnetimePriKey Fail to do edwards25519.ScCheck with spendSecAddr
\n
"
)
return
nil
,
E
rrViewSecret
return
nil
,
e
rrViewSecret
}
//2rd to calculate Hs(aR) + b
//Hs(aR)
Hs
_a
R
:=
derivation2scalar
(
aR
,
outputIndex
)
Hs
A
R
:=
derivation2scalar
(
aR
,
outputIndex
)
//TODO:代码疑问
//var onetimePriKey PrivKeyEd25519
//onetimePriKeyAddr := (*[32]byte)(unsafe.Pointer(&onetimePriKey.Bytes()[0]))
//edwards25519.ScAdd(onetimePriKeyAddr, Hs
_a
R, spendSecAddr)
//edwards25519.ScAdd(onetimePriKeyAddr, Hs
A
R, spendSecAddr)
onetimePriKeydata
:=
new
([
64
]
byte
)
onetimePriKeyAddr
:=
(
*
[
32
]
byte
)(
unsafe
.
Pointer
(
onetimePriKeydata
))
edwards25519
.
ScAdd
(
onetimePriKeyAddr
,
Hs
_a
R
,
spendSecAddr
)
edwards25519
.
ScAdd
(
onetimePriKeyAddr
,
Hs
A
R
,
spendSecAddr
)
prikey
:=
PrivKeyPrivacy
(
*
onetimePriKeydata
)
prikey
.
PubKey
()
...
...
@@ -202,11 +209,12 @@ func RecoverOnetimePriKey(R []byte, viewSecretKey, spendSecretKey PrivKey, outpu
// return checkRes
//}
// GenerateKeyPair create key pair
func
GenerateKeyPair
(
privKeyPrivacyPtr
*
PrivKeyPrivacy
,
pubKeyPrivacyPtr
*
PubKeyPrivacy
)
{
copy
(
privKeyPrivacyPtr
[
:
PrivateKeyLen
],
CRandBytes
(
P
rivateKeyLen
))
copy
(
privKeyPrivacyPtr
[
:
privateKeyLen
],
crypto
.
CRandBytes
(
p
rivateKeyLen
))
addr32
:=
(
*
[
KeyLen32
]
byte
)(
unsafe
.
Pointer
(
privKeyPrivacyPtr
))
addr64
:=
(
*
[
P
rivateKeyLen
]
byte
)(
unsafe
.
Pointer
(
privKeyPrivacyPtr
))
addr64
:=
(
*
[
p
rivateKeyLen
]
byte
)(
unsafe
.
Pointer
(
privKeyPrivacyPtr
))
edwards25519
.
ScReduce
(
addr32
,
addr64
)
//to generate the publickey
...
...
@@ -219,7 +227,7 @@ func GenerateKeyPair(privKeyPrivacyPtr *PrivKeyPrivacy, pubKeyPrivacyPtr *PubKey
func
generateKeyPairWithPrivKey
(
privByte
*
[
KeyLen32
]
byte
,
privKeyPrivacyPtr
*
PrivKeyPrivacy
,
pubKeyPrivacyPtr
*
PubKeyPrivacy
)
error
{
if
nil
==
privByte
{
return
E
rrNullRandInput
return
e
rrNullRandInput
}
_
,
err
:=
io
.
ReadFull
(
bytes
.
NewReader
(
privByte
[
:
]),
privKeyPrivacyPtr
[
:
32
])
...
...
@@ -228,7 +236,7 @@ func generateKeyPairWithPrivKey(privByte *[KeyLen32]byte, privKeyPrivacyPtr *Pri
}
addr32
:=
(
*
[
KeyLen32
]
byte
)(
unsafe
.
Pointer
(
privKeyPrivacyPtr
))
addr64
:=
(
*
[
P
rivateKeyLen
]
byte
)(
unsafe
.
Pointer
(
privKeyPrivacyPtr
))
addr64
:=
(
*
[
p
rivateKeyLen
]
byte
)(
unsafe
.
Pointer
(
privKeyPrivacyPtr
))
edwards25519
.
ScReduce
(
addr32
,
addr64
)
//to generate the publickey
...
...
@@ -250,11 +258,11 @@ func mul8(r *edwards25519.CompletedGroupElement, t *edwards25519.ProjectiveGroup
u
.
Double
(
r
)
}
func
derivation2scalar
(
derivation
_r
A
*
[
32
]
byte
,
outputIndex
int64
)
(
ellipticCurveScalar
*
[
32
]
byte
)
{
func
derivation2scalar
(
derivation
R
A
*
[
32
]
byte
,
outputIndex
int64
)
(
ellipticCurveScalar
*
[
32
]
byte
)
{
len
:=
32
+
(
unsafe
.
Sizeof
(
outputIndex
)
*
8
+
6
)
/
7
//buf := new([len]byte)
buf
:=
make
([]
byte
,
len
)
copy
(
buf
[
:
32
],
derivation
_r
A
[
:
])
copy
(
buf
[
:
32
],
derivation
R
A
[
:
])
index
:=
32
for
outputIndex
>=
0x80
{
buf
[
index
]
=
byte
((
outputIndex
&
0x7f
)
|
0x80
)
...
...
plugin/dapp/privacy/crypto/privacy_test.go
View file @
e4481593
...
...
@@ -73,7 +73,7 @@ func TestPrivacySignWithFixInput(t *testing.T) {
Signature: sig.Bytes(),
}
c := &
O
neTimeEd25519{}
c := &
o
neTimeEd25519{}
pub, err := c.PubKeyFromBytes(sign.Pubkey)
if err != nil {
...
...
@@ -156,7 +156,7 @@ func TestPrivacySignWithFixInput(t *testing.T) {
// Signature:sig.Bytes(),
// }
//
// c := &
O
neTimeEd25519{}
// c := &
o
neTimeEd25519{}
//
// pub, err := c.PubKeyFromBytes(sign.Pubkey)
// if err != nil {
...
...
plugin/dapp/privacy/crypto/privatekey.go
View file @
e4481593
...
...
@@ -8,22 +8,25 @@ import (
"bytes"
"unsafe"
.
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/crypto/sha3"
"github.com/33cn/chain33/common/ed25519/edwards25519"
)
type
PrivKeyPrivacy
[
PrivateKeyLen
]
byte
// PrivKeyPrivacy struct data type
type
PrivKeyPrivacy
[
privateKeyLen
]
byte
// Bytes convert to bytes
func
(
privKey
PrivKeyPrivacy
)
Bytes
()
[]
byte
{
return
privKey
[
:
]
}
func
(
privKey
PrivKeyPrivacy
)
Sign
(
msg
[]
byte
)
Signature
{
// Sign signature trasaction
func
(
privKey
PrivKeyPrivacy
)
Sign
(
msg
[]
byte
)
crypto
.
Signature
{
temp
:=
new
([
64
]
byte
)
randomScalar
:=
new
([
32
]
byte
)
copy
(
temp
[
:
],
CRandBytes
(
64
))
copy
(
temp
[
:
],
crypto
.
CRandBytes
(
64
))
edwards25519
.
ScReduce
(
randomScalar
,
temp
)
var
sigcommdata
sigcommArray
...
...
@@ -47,12 +50,13 @@ func (privKey PrivKeyPrivacy) Sign(msg []byte) Signature {
return
sigOnetime
}
func
(
privKey
PrivKeyPrivacy
)
PubKey
()
PubKey
{
// PubKey get public key
func
(
privKey
PrivKeyPrivacy
)
PubKey
()
crypto
.
PubKey
{
var
pubKeyPrivacy
PubKeyPrivacy
addr32
:=
(
*
[
KeyLen32
]
byte
)(
unsafe
.
Pointer
(
&
privKey
.
Bytes
()[
0
]))
addr64
:=
(
*
[
P
rivateKeyLen
]
byte
)(
unsafe
.
Pointer
(
&
privKey
.
Bytes
()[
0
]))
addr64
:=
(
*
[
p
rivateKeyLen
]
byte
)(
unsafe
.
Pointer
(
&
privKey
.
Bytes
()[
0
]))
var
A
edwards25519
.
ExtendedGroupElement
pubKeyAddr32
:=
(
*
[
KeyLen32
]
byte
)(
unsafe
.
Pointer
(
&
pubKeyPrivacy
))
...
...
@@ -63,10 +67,10 @@ func (privKey PrivKeyPrivacy) PubKey() PubKey {
return
pubKeyPrivacy
}
func
(
privKey
PrivKeyPrivacy
)
Equals
(
other
PrivKey
)
bool
{
// Equals check equals
func
(
privKey
PrivKeyPrivacy
)
Equals
(
other
crypto
.
PrivKey
)
bool
{
if
otherEd
,
ok
:=
other
.
(
PrivKeyPrivacy
);
ok
{
return
bytes
.
Equal
(
privKey
[
:
],
otherEd
[
:
])
}
else
{
return
false
}
return
false
}
plugin/dapp/privacy/crypto/publickey.go
View file @
e4481593
...
...
@@ -9,24 +9,28 @@ import (
"fmt"
"github.com/33cn/chain33/common"
.
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/types"
privacytypes
"github.com/33cn/plugin/plugin/dapp/privacy/types"
)
type
PubKeyPrivacy
[
PublicKeyLen
]
byte
// PubKeyPrivacy key struct types
type
PubKeyPrivacy
[
publicKeyLen
]
byte
// Bytes convert to bytes
func
(
pubKey
PubKeyPrivacy
)
Bytes
()
[]
byte
{
return
pubKey
[
:
]
}
// Bytes2PubKeyPrivacy convert bytes to PubKeyPrivacy
func
Bytes2PubKeyPrivacy
(
in
[]
byte
)
PubKeyPrivacy
{
var
temp
PubKeyPrivacy
copy
(
temp
[
:
],
in
)
return
temp
}
func
(
pubKey
PubKeyPrivacy
)
VerifyBytes
(
msg
[]
byte
,
sig_
Signature
)
bool
{
// VerifyBytes verify bytes
func
(
pubKey
PubKeyPrivacy
)
VerifyBytes
(
msg
[]
byte
,
sig
crypto
.
Signature
)
bool
{
var
tx
types
.
Transaction
if
err
:=
types
.
Decode
(
msg
,
&
tx
);
err
!=
nil
{
return
false
...
...
@@ -47,7 +51,7 @@ func (pubKey PubKeyPrivacy) VerifyBytes(msg []byte, sig_ Signature) bool {
return
false
}
var
ringSign
types
.
RingSignature
if
err
:=
types
.
Decode
(
sig
_
.
Bytes
(),
&
ringSign
);
err
!=
nil
{
if
err
:=
types
.
Decode
(
sig
.
Bytes
(),
&
ringSign
);
err
!=
nil
{
return
false
}
...
...
@@ -99,14 +103,15 @@ func (pubKey PubKeyPrivacy) VerifyBytes(msg []byte, sig_ Signature) bool {
// return subtle.ConstantTimeCompare(sigAddr32a[:], out32[:]) == 1
//}
// KeyString convert to string
func
(
pubKey
PubKeyPrivacy
)
KeyString
()
string
{
return
fmt
.
Sprintf
(
"%X"
,
pubKey
[
:
])
}
func
(
pubKey
PubKeyPrivacy
)
Equals
(
other
PubKey
)
bool
{
// Equals check equals
func
(
pubKey
PubKeyPrivacy
)
Equals
(
other
crypto
.
PubKey
)
bool
{
if
otherEd
,
ok
:=
other
.
(
PubKeyPrivacy
);
ok
{
return
bytes
.
Equal
(
pubKey
[
:
],
otherEd
[
:
])
}
else
{
return
false
}
return
false
}
plugin/dapp/privacy/crypto/ring_signature.go
View file @
e4481593
...
...
@@ -13,6 +13,7 @@ import (
privacytypes
"github.com/33cn/plugin/plugin/dapp/privacy/types"
)
// Sign signature data struct type
type
Sign
[
64
]
byte
func
randomScalar
(
res
*
[
32
]
byte
)
{
...
...
@@ -38,16 +39,16 @@ func generateKeyImage(pub *PubKeyPrivacy, sec *PrivKeyPrivacy, image *KeyImage)
func
generateRingSignature
(
data
[]
byte
,
image
*
KeyImage
,
pubs
[]
*
PubKeyPrivacy
,
sec
*
PrivKeyPrivacy
,
signs
[]
*
Sign
,
index
int
)
error
{
var
sum
,
k
,
h
,
tmp
[
32
]
byte
var
image
_p
re
edwards25519
.
DsmPreCompGroupElement
var
image
_u
np
edwards25519
.
ExtendedGroupElement
var
image
P
re
edwards25519
.
DsmPreCompGroupElement
var
image
U
np
edwards25519
.
ExtendedGroupElement
var
buf
[]
byte
buf
=
append
(
buf
,
data
...
)
if
!
edwards25519
.
GeFromBytesVartime
(
&
image
_u
np
,
(
*
[
32
]
byte
)(
unsafe
.
Pointer
(
image
)))
{
if
!
edwards25519
.
GeFromBytesVartime
(
&
image
U
np
,
(
*
[
32
]
byte
)(
unsafe
.
Pointer
(
image
)))
{
privacylog
.
Error
(
"generateRingSignature"
,
"from image failed."
)
return
privacytypes
.
ErrGeFromBytesVartime
}
edwards25519
.
GeDsmPrecomp
(
&
image
_pre
,
&
image_u
np
)
edwards25519
.
GeDsmPrecomp
(
&
image
Pre
,
&
imageU
np
)
for
i
:=
0
;
i
<
len
(
pubs
);
i
++
{
var
tmp2
edwards25519
.
ProjectiveGroupElement
var
tmp3
edwards25519
.
ExtendedGroupElement
...
...
@@ -93,7 +94,7 @@ func generateRingSignature(data []byte, image *KeyImage, pubs []*PubKeyPrivacy,
// r = a * A + b * B
// Wi * Hp(Pi) + q_i * I
// (r, Wi, Hp(Pi), q_i, I)
edwards25519
.
GeDoubleScalarmultPrecompVartime
(
&
tmp2
,
pb
,
&
tmp3
,
pa
,
&
image
_p
re
)
edwards25519
.
GeDoubleScalarmultPrecompVartime
(
&
tmp2
,
pb
,
&
tmp3
,
pa
,
&
image
P
re
)
// save q_i*Hp(Pi) + Wi*I
tmp2
.
ToBytes
(
&
tmp
)
buf
=
append
(
buf
,
tmp
[
:
]
...
)
...
...
@@ -115,17 +116,17 @@ func generateRingSignature(data []byte, image *KeyImage, pubs []*PubKeyPrivacy,
return
nil
}
func
checkRingSignature
(
prefix
_h
ash
[]
byte
,
image
*
KeyImage
,
pubs
[]
*
PubKeyPrivacy
,
signs
[]
*
Sign
)
bool
{
func
checkRingSignature
(
prefix
H
ash
[]
byte
,
image
*
KeyImage
,
pubs
[]
*
PubKeyPrivacy
,
signs
[]
*
Sign
)
bool
{
var
sum
,
h
,
tmp
[
32
]
byte
var
image
_u
np
edwards25519
.
ExtendedGroupElement
var
image
_p
re
edwards25519
.
DsmPreCompGroupElement
var
image
U
np
edwards25519
.
ExtendedGroupElement
var
image
P
re
edwards25519
.
DsmPreCompGroupElement
var
buf
[]
byte
buf
=
append
(
buf
,
prefix
_h
ash
...
)
buf
=
append
(
buf
,
prefix
H
ash
...
)
if
!
edwards25519
.
GeFromBytesVartime
(
&
image
_u
np
,
(
*
[
32
]
byte
)(
unsafe
.
Pointer
(
image
)))
{
if
!
edwards25519
.
GeFromBytesVartime
(
&
image
U
np
,
(
*
[
32
]
byte
)(
unsafe
.
Pointer
(
image
)))
{
return
false
}
edwards25519
.
GeDsmPrecomp
(
&
image
_pre
,
&
image_u
np
)
edwards25519
.
GeDsmPrecomp
(
&
image
Pre
,
&
imageU
np
)
for
i
:=
0
;
i
<
len
(
pubs
);
i
++
{
var
tmp2
edwards25519
.
ProjectiveGroupElement
var
tmp3
edwards25519
.
ExtendedGroupElement
...
...
@@ -147,7 +148,7 @@ func checkRingSignature(prefix_hash []byte, image *KeyImage, pubs []*PubKeyPriva
//Hp(Pi)
edwards25519
.
HashToEc
(
pub
[
:
],
&
tmp3
)
//R'_i = r_i * Hp(Pi) + c_i * I
edwards25519
.
GeDoubleScalarmultPrecompVartime
(
&
tmp2
,
pb
,
&
tmp3
,
pa
,
&
image
_p
re
)
edwards25519
.
GeDoubleScalarmultPrecompVartime
(
&
tmp2
,
pb
,
&
tmp3
,
pa
,
&
image
P
re
)
//save: R'_i = r_i * Hp(Pi) + c_i * I
tmp2
.
ToBytes
(
&
tmp
)
buf
=
append
(
buf
,
tmp
[
:
]
...
)
...
...
@@ -161,6 +162,7 @@ func checkRingSignature(prefix_hash []byte, image *KeyImage, pubs []*PubKeyPriva
return
edwards25519
.
ScIsNonZero
(
&
h
)
==
0
}
// GenerateRingSignature create ring signature object
func
GenerateRingSignature
(
datahash
[]
byte
,
utxos
[]
*
privacytypes
.
UTXOBasic
,
privKey
[]
byte
,
realUtxoIndex
int
,
keyImage
[]
byte
)
(
*
types
.
RingSignatureItem
,
error
)
{
count
:=
len
(
utxos
)
signs
:=
make
([]
*
Sign
,
count
)
...
...
plugin/dapp/privacy/crypto/ring_signature_crypto.go
View file @
e4481593
...
...
@@ -5,6 +5,7 @@
/*
基于框架中Crypto接口,实现签名、验证的处理
*/
package
privacy
import
(
...
...
@@ -28,18 +29,22 @@ type RingSignature struct {
sign
types
.
RingSignature
}
// Bytes convert to bytest
func
(
r
*
RingSignature
)
Bytes
()
[]
byte
{
return
types
.
Encode
(
&
r
.
sign
)
}
// IsZero check is zero
func
(
r
*
RingSignature
)
IsZero
()
bool
{
return
len
(
r
.
sign
.
GetItems
())
==
0
}
// String convert to string
func
(
r
*
RingSignature
)
String
()
string
{
return
r
.
sign
.
String
()
}
// Equals check equals
func
(
r
*
RingSignature
)
Equals
(
other
crypto
.
Signature
)
bool
{
if
_
,
ok
:=
other
.
(
*
RingSignature
);
ok
{
this
:=
types
.
Encode
(
&
r
.
sign
)
...
...
@@ -50,13 +55,15 @@ func (r *RingSignature) Equals(other crypto.Signature) bool {
// RingSignPrivateKey 环签名中对于crypto.PrivKey接口实现
type
RingSignPrivateKey
struct
{
key
[
P
rivateKeyLen
]
byte
key
[
p
rivateKeyLen
]
byte
}
// Bytes convert key to bytest
func
(
privkey
*
RingSignPrivateKey
)
Bytes
()
[]
byte
{
return
privkey
.
key
[
:
]
}
// Sign signature trasaction
func
(
privkey
*
RingSignPrivateKey
)
Sign
(
msg
[]
byte
)
crypto
.
Signature
{
emptySign
:=
&
RingSignature
{}
if
len
(
msg
)
<=
0
{
...
...
@@ -107,10 +114,11 @@ func (privkey *RingSignPrivateKey) Sign(msg []byte) crypto.Signature {
return
emptySign
}
// PubKey convert to public key
func
(
privkey
*
RingSignPrivateKey
)
PubKey
()
crypto
.
PubKey
{
publicKey
:=
new
(
RingSignPublicKey
)
addr32
:=
(
*
[
KeyLen32
]
byte
)(
unsafe
.
Pointer
(
&
privkey
.
key
))
addr64
:=
(
*
[
P
rivateKeyLen
]
byte
)(
unsafe
.
Pointer
(
&
privkey
.
key
))
addr64
:=
(
*
[
p
rivateKeyLen
]
byte
)(
unsafe
.
Pointer
(
&
privkey
.
key
))
A
:=
new
(
edwards25519
.
ExtendedGroupElement
)
edwards25519
.
GeScalarMultBase
(
A
,
addr32
)
...
...
@@ -120,6 +128,7 @@ func (privkey *RingSignPrivateKey) PubKey() crypto.PubKey {
return
publicKey
}
// Equals check key equal
func
(
privkey
*
RingSignPrivateKey
)
Equals
(
other
crypto
.
PrivKey
)
bool
{
if
otherPrivKey
,
ok
:=
other
.
(
*
RingSignPrivateKey
);
ok
{
return
bytes
.
Equal
(
privkey
.
key
[
:
],
otherPrivKey
.
key
[
:
])
...
...
@@ -129,13 +138,15 @@ func (privkey *RingSignPrivateKey) Equals(other crypto.PrivKey) bool {
// RingSignPublicKey 环签名中对于crypto.PubKey接口实现
type
RingSignPublicKey
struct
{
key
[
P
ublicKeyLen
]
byte
key
[
p
ublicKeyLen
]
byte
}
// Bytes convert key to bytes
func
(
pubkey
*
RingSignPublicKey
)
Bytes
()
[]
byte
{
return
pubkey
.
key
[
:
]
}
// VerifyBytes verify bytes
func
(
pubkey
*
RingSignPublicKey
)
VerifyBytes
(
msg
[]
byte
,
sign
crypto
.
Signature
)
bool
{
if
len
(
msg
)
<=
0
{
return
false
...
...
@@ -170,10 +181,12 @@ func (pubkey *RingSignPublicKey) VerifyBytes(msg []byte, sign crypto.Signature)
return
true
}
// KeyString convert key to string
func
(
pubkey
*
RingSignPublicKey
)
KeyString
()
string
{
return
fmt
.
Sprintf
(
"%X"
,
pubkey
.
key
[
:
])
}
// Equals check key is equal
func
(
pubkey
*
RingSignPublicKey
)
Equals
(
other
crypto
.
PubKey
)
bool
{
if
otherPubKey
,
ok
:=
other
.
(
*
RingSignPublicKey
);
ok
{
return
bytes
.
Equal
(
pubkey
.
key
[
:
],
otherPubKey
.
key
[
:
])
...
...
@@ -185,13 +198,14 @@ func (pubkey *RingSignPublicKey) Equals(other crypto.PubKey) bool {
type
RingSignED25519
struct
{
}
// GenKey create privacy key
func
(
r
*
RingSignED25519
)
GenKey
()
(
crypto
.
PrivKey
,
error
)
{
privKeyPrivacyPtr
:=
&
PrivKeyPrivacy
{}
pubKeyPrivacyPtr
:=
&
PubKeyPrivacy
{}
copy
(
privKeyPrivacyPtr
[
:
PrivateKeyLen
],
crypto
.
CRandBytes
(
P
rivateKeyLen
))
copy
(
privKeyPrivacyPtr
[
:
privateKeyLen
],
crypto
.
CRandBytes
(
p
rivateKeyLen
))
addr32
:=
(
*
[
KeyLen32
]
byte
)(
unsafe
.
Pointer
(
privKeyPrivacyPtr
))
addr64
:=
(
*
[
P
rivateKeyLen
]
byte
)(
unsafe
.
Pointer
(
privKeyPrivacyPtr
))
addr64
:=
(
*
[
p
rivateKeyLen
]
byte
)(
unsafe
.
Pointer
(
privKeyPrivacyPtr
))
edwards25519
.
ScReduce
(
addr32
,
addr64
)
//to generate the publickey
...
...
@@ -204,6 +218,7 @@ func (r *RingSignED25519) GenKey() (crypto.PrivKey, error) {
return
*
privKeyPrivacyPtr
,
nil
}
// PrivKeyFromBytes create private key from bytes
func
(
r
*
RingSignED25519
)
PrivKeyFromBytes
(
b
[]
byte
)
(
crypto
.
PrivKey
,
error
)
{
if
len
(
b
)
<=
0
{
return
nil
,
types
.
ErrInvalidParam
...
...
@@ -216,11 +231,12 @@ func (r *RingSignED25519) PrivKeyFromBytes(b []byte) (crypto.PrivKey, error) {
return
privateKey
,
nil
}
// PubKeyFromBytes create publick key from bytes
func
(
r
*
RingSignED25519
)
PubKeyFromBytes
(
b
[]
byte
)
(
crypto
.
PubKey
,
error
)
{
if
len
(
b
)
<=
0
{
return
nil
,
types
.
ErrInvalidParam
}
if
len
(
b
)
!=
P
ublicKeyLen
{
if
len
(
b
)
!=
p
ublicKeyLen
{
return
nil
,
types
.
ErrPubKeyLen
}
publicKey
:=
new
(
RingSignPublicKey
)
...
...
@@ -228,6 +244,7 @@ func (r *RingSignED25519) PubKeyFromBytes(b []byte) (crypto.PubKey, error) {
return
publicKey
,
nil
}
// SignatureFromBytes create signature from bytes
func
(
r
*
RingSignED25519
)
SignatureFromBytes
(
b
[]
byte
)
(
crypto
.
Signature
,
error
)
{
if
len
(
b
)
<=
0
{
return
nil
,
types
.
ErrInvalidParam
...
...
plugin/dapp/privacy/crypto/ring_signature_test.go
View file @
e4481593
...
...
@@ -18,8 +18,8 @@ import (
)
var
(
pubs
_b
yte
[
10
][]
byte
secs
_b
yte
[
10
][]
byte
pubs
B
yte
[
10
][]
byte
secs
B
yte
[
10
][]
byte
)
func
init
()
{
...
...
@@ -48,8 +48,8 @@ func init() {
}
for
i
:=
0
;
i
<
10
;
i
++
{
pubs
_b
yte
[
i
],
_
=
common
.
FromHex
(
pubstrs
[
i
])
secs
_b
yte
[
i
],
_
=
common
.
FromHex
(
secstrs
[
i
])
pubs
B
yte
[
i
],
_
=
common
.
FromHex
(
pubstrs
[
i
])
secs
B
yte
[
i
],
_
=
common
.
FromHex
(
secstrs
[
i
])
}
}
...
...
@@ -104,7 +104,7 @@ func TestGenerateRingSignature1(t *testing.T) {
var
sec
PrivKeyPrivacy
var
signs
[
maxCount
]
*
Sign
index
:=
0
prefix
_h
ash
,
err
:=
common
.
FromHex
(
"fd1f64844a7d6a9f74fc2141bceba9d9d69b1fd6104f93bfa42a6d708a6ab22c"
)
prefix
H
ash
,
err
:=
common
.
FromHex
(
"fd1f64844a7d6a9f74fc2141bceba9d9d69b1fd6104f93bfa42a6d708a6ab22c"
)
tmp
,
err
:=
common
.
FromHex
(
"e7d85d6e81512c5650adce0499d6c17a83e2e29a05c1166cd2171b6b9288b3c4"
)
copy
(
image
[
:
],
tmp
)
tmp
,
err
=
common
.
FromHex
(
"15e3cc7cdb904d62f7c20d7fa51923fa2839f9e0a92ff0eddf8c12bd09089c15"
)
...
...
@@ -119,7 +119,7 @@ func TestGenerateRingSignature1(t *testing.T) {
for
i
:=
0
;
i
<
maxCount
;
i
++
{
signs
[
i
]
=
&
Sign
{}
}
err
=
generateRingSignature
(
prefix
_h
ash
,
&
image
,
pubs
[
:
],
&
sec
,
signs
[
:
],
index
)
err
=
generateRingSignature
(
prefix
H
ash
,
&
image
,
pubs
[
:
],
&
sec
,
signs
[
:
],
index
)
if
err
!=
nil
{
t
.
Error
(
"generateRingSignature() cause error "
,
err
)
}
...
...
@@ -131,7 +131,7 @@ func TestCheckRingSignature1(t *testing.T) {
var
pubs
[
maxCount
]
*
PubKeyPrivacy
var
signs
[
maxCount
]
*
Sign
prefix
_h
ash
,
err
:=
common
.
FromHex
(
"fd1f64844a7d6a9f74fc2141bceba9d9d69b1fd6104f93bfa42a6d708a6ab22c"
)
prefix
H
ash
,
err
:=
common
.
FromHex
(
"fd1f64844a7d6a9f74fc2141bceba9d9d69b1fd6104f93bfa42a6d708a6ab22c"
)
if
err
!=
nil
{
t
.
Error
(
"initialize public key from hex failed."
)
}
...
...
@@ -150,7 +150,7 @@ func TestCheckRingSignature1(t *testing.T) {
signs
[
i
]
=
&
sign
}
if
!
checkRingSignature
(
prefix
_h
ash
,
&
image
,
pubs
[
:
],
signs
[
:
])
{
if
!
checkRingSignature
(
prefix
H
ash
,
&
image
,
pubs
[
:
],
signs
[
:
])
{
t
.
Fatal
(
"checkRingSignature() failed."
)
}
}
...
...
@@ -159,7 +159,7 @@ func TestCheckRingSignatureAPI1(t *testing.T) {
const
maxCount
=
1
var
signatures
types
.
RingSignatureItem
publickeys
:=
make
([][]
byte
,
maxCount
)
prefix
_h
ash
,
err
:=
common
.
FromHex
(
"fd1f64844a7d6a9f74fc2141bceba9d9d69b1fd6104f93bfa42a6d708a6ab22c"
)
prefix
H
ash
,
err
:=
common
.
FromHex
(
"fd1f64844a7d6a9f74fc2141bceba9d9d69b1fd6104f93bfa42a6d708a6ab22c"
)
if
err
!=
nil
{
t
.
Errorf
(
"common.FromHex."
,
err
)
}
...
...
@@ -181,7 +181,7 @@ func TestCheckRingSignatureAPI1(t *testing.T) {
}
signatures
.
Signature
=
data
if
!
CheckRingSignature
(
prefix
_h
ash
,
&
signatures
,
publickeys
,
keyimage
)
{
if
!
CheckRingSignature
(
prefix
H
ash
,
&
signatures
,
publickeys
,
keyimage
)
{
t
.
Fatal
(
"checkRingSignature() failed."
)
}
}
...
...
@@ -192,7 +192,7 @@ func TestCheckRingSignature3(t *testing.T) {
var
pubs
[
maxCount
]
*
PubKeyPrivacy
var
signs
[
maxCount
]
*
Sign
prefix
_h
ash
,
err
:=
common
.
FromHex
(
"9e7ff8bde0e318543dcedbe34c51c6b25a850578adae2e7930bbda5224c77ef5"
)
prefix
H
ash
,
err
:=
common
.
FromHex
(
"9e7ff8bde0e318543dcedbe34c51c6b25a850578adae2e7930bbda5224c77ef5"
)
if
err
!=
nil
{
t
.
Error
(
"initialize public key from hex failed."
)
}
...
...
@@ -211,7 +211,7 @@ func TestCheckRingSignature3(t *testing.T) {
signs
[
i
]
=
&
sign
}
if
!
checkRingSignature
(
prefix
_h
ash
,
&
image
,
pubs
[
:
],
signs
[
:
])
{
if
!
checkRingSignature
(
prefix
H
ash
,
&
image
,
pubs
[
:
],
signs
[
:
])
{
t
.
Fatal
(
"checkRingSignature() failed."
)
}
}
...
...
@@ -242,7 +242,7 @@ func TestCheckRingSignature17(t *testing.T) {
"c618c6b0e328886be15e2c92052dcf74cf4745a4e5e53f6d2417a9c9d139c167"
,
}
prefix
_h
ash
,
err
:=
common
.
FromHex
(
"1c909782c70567e9968ded1c05a4226a3e04a07ae9db48e0153a56b2a4684779"
)
prefix
H
ash
,
err
:=
common
.
FromHex
(
"1c909782c70567e9968ded1c05a4226a3e04a07ae9db48e0153a56b2a4684779"
)
if
err
!=
nil
{
t
.
Error
(
"initialize public key from hex failed."
)
}
...
...
@@ -262,7 +262,7 @@ func TestCheckRingSignature17(t *testing.T) {
signs
[
i
]
=
&
sign
}
if
!
checkRingSignature
(
prefix
_h
ash
,
&
image
,
pubs
[
:
],
signs
[
:
])
{
if
!
checkRingSignature
(
prefix
H
ash
,
&
image
,
pubs
[
:
],
signs
[
:
])
{
t
.
Fatal
(
"checkRingSignature() failed."
)
}
}
...
...
@@ -276,27 +276,27 @@ func TestRingSignatere1(t *testing.T) {
index
:=
0
// 初始化测试数据
prefix
_h
ash
,
_
:=
common
.
FromHex
(
"fd1f64844a7d6a9f74fc2141bceba9d9d69b1fd6104f93bfa42a6d708a6ab22c"
)
prefix
H
ash
,
_
:=
common
.
FromHex
(
"fd1f64844a7d6a9f74fc2141bceba9d9d69b1fd6104f93bfa42a6d708a6ab22c"
)
for
i
:=
0
;
i
<
maxCount
;
i
++
{
pub
:=
PubKeyPrivacy
{}
sign
:=
Sign
{}
pubs
[
i
]
=
&
pub
signs
[
i
]
=
&
sign
copy
(
pub
[
:
],
pubs
_b
yte
[
i
])
copy
(
pub
[
:
],
pubs
B
yte
[
i
])
if
i
==
index
{
// 创建 KeyImage
copy
(
sec
[
:
],
secs
_b
yte
[
i
])
copy
(
sec
[
:
],
secs
B
yte
[
i
])
generateKeyImage
(
&
pub
,
&
sec
,
&
image
)
}
}
// 创建环签名
err
:=
generateRingSignature
(
prefix
_h
ash
,
&
image
,
pubs
[
:
],
&
sec
,
signs
[
:
],
index
)
err
:=
generateRingSignature
(
prefix
H
ash
,
&
image
,
pubs
[
:
],
&
sec
,
signs
[
:
],
index
)
if
err
!=
nil
{
t
.
Fatal
(
"generateRingSignature() failed. error "
,
err
)
}
// 消炎环签名
if
!
checkRingSignature
(
prefix
_h
ash
,
&
image
,
pubs
[
:
],
signs
[
:
])
{
if
!
checkRingSignature
(
prefix
H
ash
,
&
image
,
pubs
[
:
],
signs
[
:
])
{
t
.
Fatal
(
"checkRingSignature() failed."
)
}
}
...
...
@@ -309,7 +309,7 @@ func testRingSignatureOncetime(maxCount int, t *testing.T) {
signs
:=
make
([]
*
Sign
,
maxCount
)
// 初始化测试数据
prefix
_h
ash
,
_
:=
common
.
FromHex
(
"fd1f64844a7d6a9f74fc2141bceba9d9d69b1fd6104f93bfa42a6d708a6ab22c"
)
prefix
H
ash
,
_
:=
common
.
FromHex
(
"fd1f64844a7d6a9f74fc2141bceba9d9d69b1fd6104f93bfa42a6d708a6ab22c"
)
c
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
"privacy"
,
privacytypes
.
OnetimeED25519
))
if
err
!=
nil
{
...
...
@@ -339,12 +339,12 @@ func testRingSignatureOncetime(maxCount int, t *testing.T) {
}
}
// 创建环签名
err
=
generateRingSignature
(
prefix
_h
ash
,
&
image
,
pubs
[
:
],
&
sec
,
signs
[
:
],
index
)
err
=
generateRingSignature
(
prefix
H
ash
,
&
image
,
pubs
[
:
],
&
sec
,
signs
[
:
],
index
)
if
err
!=
nil
{
t
.
Fatal
(
"generateRingSignature() failed. error "
,
err
)
}
// 消炎环签名
if
!
checkRingSignature
(
prefix
_h
ash
,
&
image
,
pubs
[
:
],
signs
[
:
])
{
if
!
checkRingSignature
(
prefix
H
ash
,
&
image
,
pubs
[
:
],
signs
[
:
])
{
t
.
Fatal
(
"checkRingSignature() failed."
)
}
}
...
...
@@ -371,12 +371,12 @@ func TestGenerateRingSignatureAPI(t *testing.T) {
}
realUtxoIndex
:=
rand
.
Int
()
%
maxCount
prefix
_h
ash
,
_
:=
common
.
FromHex
(
"fd1f64844a7d6a9f74fc2141bceba9d9d69b1fd6104f93bfa42a6d708a6ab22c"
)
prefix
H
ash
,
_
:=
common
.
FromHex
(
"fd1f64844a7d6a9f74fc2141bceba9d9d69b1fd6104f93bfa42a6d708a6ab22c"
)
utxos
=
make
([]
*
privacytypes
.
UTXOBasic
,
maxCount
)
for
i
:=
0
;
i
<
maxCount
;
i
++
{
utxo
:=
privacytypes
.
UTXOBasic
{}
utxos
[
i
]
=
&
utxo
utxo
.
OnetimePubkey
=
append
(
utxo
.
OnetimePubkey
[
:
],
pubs
_b
yte
[
i
]
...
)
utxo
.
OnetimePubkey
=
append
(
utxo
.
OnetimePubkey
[
:
],
pubs
B
yte
[
i
]
...
)
if
i
==
realUtxoIndex
{
pubKey
:=
privkey
.
PubKey
()
.
Bytes
()
// 增加指定的密钥对
...
...
@@ -394,7 +394,7 @@ func TestGenerateRingSignatureAPI(t *testing.T) {
var
signaturedata
*
types
.
RingSignatureItem
// step2. generate ring signature
if
signaturedata
,
err
=
GenerateRingSignature
(
prefix
_h
ash
,
utxos
,
sec
[
:
],
realUtxoIndex
,
keyImage
);
err
!=
nil
{
if
signaturedata
,
err
=
GenerateRingSignature
(
prefix
H
ash
,
utxos
,
sec
[
:
],
realUtxoIndex
,
keyImage
);
err
!=
nil
{
t
.
Errorf
(
"GenerateRingSignature() failed. "
,
err
)
}
...
...
@@ -403,7 +403,7 @@ func TestGenerateRingSignatureAPI(t *testing.T) {
publickeys
[
i
]
=
append
(
publickeys
[
i
],
utxos
[
i
]
.
OnetimePubkey
...
)
}
// step3. checksignature
if
!
CheckRingSignature
(
prefix
_h
ash
,
signaturedata
,
publickeys
,
keyImage
)
{
if
!
CheckRingSignature
(
prefix
H
ash
,
signaturedata
,
publickeys
,
keyImage
)
{
t
.
Error
(
"CheckRingSignature() failed."
)
}
}
...
...
@@ -416,7 +416,7 @@ func benchRingSignatureOncetime(maxCount int) {
signs
:=
make
([]
*
Sign
,
maxCount
)
// 初始化测试数据
prefix
_h
ash
,
_
:=
common
.
FromHex
(
"fd1f64844a7d6a9f74fc2141bceba9d9d69b1fd6104f93bfa42a6d708a6ab22c"
)
prefix
H
ash
,
_
:=
common
.
FromHex
(
"fd1f64844a7d6a9f74fc2141bceba9d9d69b1fd6104f93bfa42a6d708a6ab22c"
)
c
,
_
:=
crypto
.
New
(
types
.
GetSignName
(
"privacy"
,
privacytypes
.
OnetimeED25519
))
for
i
:=
0
;
i
<
maxCount
;
i
++
{
...
...
@@ -437,9 +437,9 @@ func benchRingSignatureOncetime(maxCount int) {
}
}
// 创建环签名
generateRingSignature
(
prefix
_h
ash
,
&
image
,
pubs
[
:
],
&
sec
,
signs
[
:
],
index
)
generateRingSignature
(
prefix
H
ash
,
&
image
,
pubs
[
:
],
&
sec
,
signs
[
:
],
index
)
// 效验环签名
checkRingSignature
(
prefix
_h
ash
,
&
image
,
pubs
[
:
],
signs
[
:
])
checkRingSignature
(
prefix
H
ash
,
&
image
,
pubs
[
:
],
signs
[
:
])
}
func
Benchmark_RingSignature
(
b
*
testing
.
B
)
{
...
...
plugin/dapp/privacy/crypto/signature.go
View file @
e4481593
...
...
@@ -8,34 +8,38 @@ import (
"bytes"
"fmt"
.
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/crypto"
)
// Signature
// Signature
Onetime sinature data type
type
SignatureOnetime
[
64
]
byte
// SignatureS signature data
type
SignatureS
struct
{
Signature
crypto
.
Signature
}
// Bytes get bytes
func
(
sig
SignatureOnetime
)
Bytes
()
[]
byte
{
s
:=
make
([]
byte
,
64
)
copy
(
s
,
sig
[
:
])
return
s
}
// IsZero check is zero
func
(
sig
SignatureOnetime
)
IsZero
()
bool
{
return
len
(
sig
)
==
0
}
// String format to string
func
(
sig
SignatureOnetime
)
String
()
string
{
fingerprint
:=
make
([]
byte
,
len
(
sig
[
:
]))
copy
(
fingerprint
,
sig
[
:
])
return
fmt
.
Sprintf
(
"/%X.../"
,
fingerprint
)
}
func
(
sig
SignatureOnetime
)
Equals
(
other
Signature
)
bool
{
// Equals check signature equal
func
(
sig
SignatureOnetime
)
Equals
(
other
crypto
.
Signature
)
bool
{
if
otherEd
,
ok
:=
other
.
(
SignatureOnetime
);
ok
{
return
bytes
.
Equal
(
sig
[
:
],
otherEd
[
:
])
}
else
{
return
false
}
return
false
}
plugin/dapp/privacy/executor/exec.go
View file @
e4481593
...
...
@@ -11,6 +11,7 @@ import (
ty
"github.com/33cn/plugin/plugin/dapp/privacy/types"
)
// Exec_Public2Privacy execute public to privacy
func
(
p
*
privacy
)
Exec_Public2Privacy
(
payload
*
ty
.
Public2Privacy
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
if
payload
.
Tokenname
!=
types
.
BTY
{
return
nil
,
types
.
ErrNotSupport
...
...
@@ -50,6 +51,7 @@ func (p *privacy) Exec_Public2Privacy(payload *ty.Public2Privacy, tx *types.Tran
return
receipt
,
nil
}
// Exec_Privacy2Privacy execute privacy to privacy transaction
func
(
p
*
privacy
)
Exec_Privacy2Privacy
(
payload
*
ty
.
Privacy2Privacy
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
if
payload
.
Tokenname
!=
types
.
BTY
{
return
nil
,
types
.
ErrNotSupport
...
...
@@ -58,7 +60,7 @@ func (p *privacy) Exec_Privacy2Privacy(payload *ty.Privacy2Privacy, tx *types.Tr
receipt
:=
&
types
.
Receipt
{
KV
:
make
([]
*
types
.
KeyValue
,
0
)}
privacyInput
:=
payload
.
Input
for
_
,
keyInput
:=
range
privacyInput
.
Keyinput
{
value
:=
[]
byte
{
K
eyImageSpentAlready
}
value
:=
[]
byte
{
k
eyImageSpentAlready
}
key
:=
calcPrivacyKeyImageKey
(
payload
.
Tokenname
,
keyInput
.
KeyImage
)
stateDB
:=
p
.
GetStateDB
()
stateDB
.
Set
(
key
,
value
)
...
...
@@ -91,6 +93,7 @@ func (p *privacy) Exec_Privacy2Privacy(payload *ty.Privacy2Privacy, tx *types.Tr
return
receipt
,
nil
}
// Exec_Privacy2Public execute privacy to public transaction
func
(
p
*
privacy
)
Exec_Privacy2Public
(
payload
*
ty
.
Privacy2Public
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
if
payload
.
Tokenname
!=
types
.
BTY
{
return
nil
,
types
.
ErrNotSupport
...
...
@@ -104,7 +107,7 @@ func (p *privacy) Exec_Privacy2Public(payload *ty.Privacy2Public, tx *types.Tran
}
privacyInput
:=
payload
.
Input
for
_
,
keyInput
:=
range
privacyInput
.
Keyinput
{
value
:=
[]
byte
{
K
eyImageSpentAlready
}
value
:=
[]
byte
{
k
eyImageSpentAlready
}
key
:=
calcPrivacyKeyImageKey
(
payload
.
Tokenname
,
keyInput
.
KeyImage
)
stateDB
:=
p
.
GetStateDB
()
stateDB
.
Set
(
key
,
value
)
...
...
plugin/dapp/privacy/executor/exec_del_local.go
View file @
e4481593
...
...
@@ -87,14 +87,17 @@ func (p *privacy) execDelLocal(tx *types.Transaction, receiptData *types.Receipt
return
dbSet
,
nil
}
// ExecDelLocal_Public2Privacy local delete execute public to privacy transaction
func
(
p
*
privacy
)
ExecDelLocal_Public2Privacy
(
payload
*
ty
.
Public2Privacy
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
p
.
execDelLocal
(
tx
,
receiptData
,
index
)
}
// ExecDelLocal_Privacy2Privacy local delete execute privacy to privacy transaction
func
(
p
*
privacy
)
ExecDelLocal_Privacy2Privacy
(
payload
*
ty
.
Privacy2Privacy
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
p
.
execDelLocal
(
tx
,
receiptData
,
index
)
}
// ExecDelLocal_Privacy2Public local delete execute public to public transaction
func
(
p
*
privacy
)
ExecDelLocal_Privacy2Public
(
payload
*
ty
.
Privacy2Public
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
p
.
execDelLocal
(
tx
,
receiptData
,
index
)
}
plugin/dapp/privacy/executor/exec_local.go
View file @
e4481593
...
...
@@ -101,14 +101,17 @@ func (p *privacy) execLocal(receiptData *types.ReceiptData, tx *types.Transactio
return
dbSet
,
nil
}
func
(
g
*
privacy
)
ExecLocal_Public2Privacy
(
payload
*
ty
.
Public2Privacy
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
g
.
execLocal
(
receiptData
,
tx
,
index
)
// ExecLocal_Public2Privacy local execute public to privacy transaction
func
(
p
*
privacy
)
ExecLocal_Public2Privacy
(
payload
*
ty
.
Public2Privacy
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
p
.
execLocal
(
receiptData
,
tx
,
index
)
}
func
(
g
*
privacy
)
ExecLocal_Privacy2Privacy
(
payload
*
ty
.
Privacy2Privacy
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
g
.
execLocal
(
receiptData
,
tx
,
index
)
// ExecLocal_Privacy2Privacy local execute privacy to privacy transaction
func
(
p
*
privacy
)
ExecLocal_Privacy2Privacy
(
payload
*
ty
.
Privacy2Privacy
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
p
.
execLocal
(
receiptData
,
tx
,
index
)
}
func
(
g
*
privacy
)
ExecLocal_Privacy2Public
(
payload
*
ty
.
Privacy2Public
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
g
.
execLocal
(
receiptData
,
tx
,
index
)
// ExecLocal_Privacy2Public local execute privacy to public trasaction
func
(
p
*
privacy
)
ExecLocal_Privacy2Public
(
payload
*
ty
.
Privacy2Public
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
p
.
execLocal
(
receiptData
,
tx
,
index
)
}
plugin/dapp/privacy/executor/kv.go
View file @
e4481593
...
...
@@ -11,39 +11,41 @@ import (
)
const
(
P
rivacyOutputKeyPrefix
=
"mavl-privacy-UTXO-tahi"
P
rivacyKeyImagePrefix
=
"mavl-privacy-UTXO-keyimage"
P
rivacyUTXOKEYPrefix
=
"LODB-privacy-UTXO-tahhi"
P
rivacyAmountTypePrefix
=
"LODB-privacy-UTXO-atype"
P
rivacyTokenTypesPrefix
=
"LODB-privacy-UTXO-token"
K
eyImageSpentAlready
=
0x01
Invalid_index
=
-
1
p
rivacyOutputKeyPrefix
=
"mavl-privacy-UTXO-tahi"
p
rivacyKeyImagePrefix
=
"mavl-privacy-UTXO-keyimage"
p
rivacyUTXOKEYPrefix
=
"LODB-privacy-UTXO-tahhi"
p
rivacyAmountTypePrefix
=
"LODB-privacy-UTXO-atype"
p
rivacyTokenTypesPrefix
=
"LODB-privacy-UTXO-token"
k
eyImageSpentAlready
=
0x01
invalidIndex
=
-
1
)
//该key对应的是types.KeyOutput
//
CalcPrivacyOutputKey
该key对应的是types.KeyOutput
//该kv会在store中设置
func
CalcPrivacyOutputKey
(
token
string
,
amount
int64
,
txhash
string
,
outindex
int
)
(
key
[]
byte
)
{
return
[]
byte
(
fmt
.
Sprintf
(
P
rivacyOutputKeyPrefix
+
"-%s-%d-%s-%d"
,
token
,
amount
,
txhash
,
outindex
))
return
[]
byte
(
fmt
.
Sprintf
(
p
rivacyOutputKeyPrefix
+
"-%s-%d-%s-%d"
,
token
,
amount
,
txhash
,
outindex
))
}
func
calcPrivacyKeyImageKey
(
token
string
,
keyimage
[]
byte
)
[]
byte
{
return
[]
byte
(
fmt
.
Sprintf
(
P
rivacyKeyImagePrefix
+
"-%s-%s"
,
token
,
common
.
ToHex
(
keyimage
)))
return
[]
byte
(
fmt
.
Sprintf
(
p
rivacyKeyImagePrefix
+
"-%s-%s"
,
token
,
common
.
ToHex
(
keyimage
)))
}
//在本地数据库中设置一条可以找到对应amount的对应的utxo的global index
//
CalcPrivacyUTXOkeyHeight
在本地数据库中设置一条可以找到对应amount的对应的utxo的global index
func
CalcPrivacyUTXOkeyHeight
(
token
string
,
amount
,
height
int64
,
txhash
string
,
txindex
,
outindex
int
)
(
key
[]
byte
)
{
return
[]
byte
(
fmt
.
Sprintf
(
P
rivacyUTXOKEYPrefix
+
"-%s-%d-%d-%s-%d-%d"
,
token
,
amount
,
height
,
txhash
,
txindex
,
outindex
))
return
[]
byte
(
fmt
.
Sprintf
(
p
rivacyUTXOKEYPrefix
+
"-%s-%d-%d-%s-%d-%d"
,
token
,
amount
,
height
,
txhash
,
txindex
,
outindex
))
}
// CalcPrivacyUTXOkeyHeightPrefix get privacy utxo key by height and prefix
func
CalcPrivacyUTXOkeyHeightPrefix
(
token
string
,
amount
int64
)
(
key
[]
byte
)
{
return
[]
byte
(
fmt
.
Sprintf
(
P
rivacyUTXOKEYPrefix
+
"-%s-%d-"
,
token
,
amount
))
return
[]
byte
(
fmt
.
Sprintf
(
p
rivacyUTXOKEYPrefix
+
"-%s-%d-"
,
token
,
amount
))
}
//设置当前系统存在的token的amount的类型,如存在1,3,5,100...等等的类型,
//
CalcprivacyKeyTokenAmountType
设置当前系统存在的token的amount的类型,如存在1,3,5,100...等等的类型,
func
CalcprivacyKeyTokenAmountType
(
token
string
)
(
key
[]
byte
)
{
return
[]
byte
(
fmt
.
Sprintf
(
P
rivacyAmountTypePrefix
+
"-%s-"
,
token
))
return
[]
byte
(
fmt
.
Sprintf
(
p
rivacyAmountTypePrefix
+
"-%s-"
,
token
))
}
// CalcprivacyKeyTokenTypes get privacy token types key
func
CalcprivacyKeyTokenTypes
()
(
key
[]
byte
)
{
return
[]
byte
(
P
rivacyTokenTypesPrefix
)
return
[]
byte
(
p
rivacyTokenTypesPrefix
)
}
plugin/dapp/privacy/executor/privacy.go
View file @
e4481593
...
...
@@ -41,12 +41,14 @@ func init() {
ety
.
InitFuncList
(
types
.
ListMethod
(
&
privacy
{}))
}
// Init initialize executor driver
func
Init
(
name
string
,
sub
[]
byte
)
{
drivers
.
Register
(
GetName
(),
newPrivacy
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
// 如果需要在开发环境下使用隐私交易,则需要使用下面这行代码,否则用上面的代码
//drivers.Register(newPrivacy().GetName(), newPrivacy, 0)
}
// GetName get privacy name
func
GetName
()
string
{
return
newPrivacy
()
.
GetName
()
}
...
...
@@ -62,6 +64,7 @@ func newPrivacy() drivers.Driver {
return
t
}
// GetDriverName get driver name
func
(
p
*
privacy
)
GetDriverName
()
string
{
return
driverName
}
...
...
@@ -142,7 +145,7 @@ func (p *privacy) getGlobalUtxoIndex(getUtxoIndexReq *pty.ReqUTXOGlobalIndex) (t
return
utxoGlobalIndexResp
,
nil
}
//获取指定amount下的所有utxo,这样就可以查询当前系统不同amout下存在的UTXO,可以帮助查询用于混淆用的资源
//
ShowAmountsOfUTXO
获取指定amount下的所有utxo,这样就可以查询当前系统不同amout下存在的UTXO,可以帮助查询用于混淆用的资源
//也可以确认币种的碎片化问题
//显示存在的各种不同的额度的UTXO,如1,3,5,10,20,30,100...
func
(
p
*
privacy
)
ShowAmountsOfUTXO
(
reqtoken
*
pty
.
ReqPrivacyToken
)
(
types
.
Message
,
error
)
{
...
...
@@ -171,7 +174,7 @@ func (p *privacy) ShowAmountsOfUTXO(reqtoken *pty.ReqPrivacyToken) (types.Messag
return
replyAmounts
,
nil
}
//显示在指定额度下的UTXO的具体信息,如区块高度,交易hash,输出索引等具体信息
//
ShowUTXOs4SpecifiedAmount
显示在指定额度下的UTXO的具体信息,如区块高度,交易hash,输出索引等具体信息
func
(
p
*
privacy
)
ShowUTXOs4SpecifiedAmount
(
reqtoken
*
pty
.
ReqPrivacyToken
)
(
types
.
Message
,
error
)
{
querydb
:=
p
.
GetLocalDB
()
...
...
@@ -193,6 +196,7 @@ func (p *privacy) ShowUTXOs4SpecifiedAmount(reqtoken *pty.ReqPrivacyToken) (type
return
&
replyUTXOsOfAmount
,
nil
}
// CheckTx check transaction
func
(
p
*
privacy
)
CheckTx
(
tx
*
types
.
Transaction
,
index
int
)
error
{
txhashstr
:=
common
.
Bytes2Hex
(
tx
.
Hash
())
var
action
pty
.
PrivacyAction
...
...
@@ -288,11 +292,11 @@ func (p *privacy) checkUTXOValid(keyImages [][]byte) (bool, int32) {
values
,
err
:=
stateDB
.
BatchGet
(
keyImages
)
if
err
!=
nil
{
privacylog
.
Error
(
"exec module"
,
"checkUTXOValid failed to get value from statDB"
)
return
false
,
Invalid_i
ndex
return
false
,
invalidI
ndex
}
if
len
(
values
)
!=
len
(
keyImages
)
{
privacylog
.
Error
(
"exec module"
,
"checkUTXOValid return different count value with keys"
)
return
false
,
Invalid_i
ndex
return
false
,
invalidI
ndex
}
for
i
,
value
:=
range
values
{
if
value
!=
nil
{
...
...
@@ -301,19 +305,19 @@ func (p *privacy) checkUTXOValid(keyImages [][]byte) (bool, int32) {
}
}
return
true
,
Invalid_i
ndex
return
true
,
invalidI
ndex
}
func
(
p
*
privacy
)
checkPubKeyValid
(
keys
[][]
byte
,
pubkeys
[][]
byte
)
(
bool
,
int32
)
{
values
,
err
:=
p
.
GetStateDB
()
.
BatchGet
(
keys
)
if
err
!=
nil
{
privacylog
.
Error
(
"exec module"
,
"checkPubKeyValid failed to get value from statDB with err"
,
err
)
return
false
,
Invalid_i
ndex
return
false
,
invalidI
ndex
}
if
len
(
values
)
!=
len
(
pubkeys
)
{
privacylog
.
Error
(
"exec module"
,
"checkPubKeyValid return different count value with keys"
)
return
false
,
Invalid_i
ndex
return
false
,
invalidI
ndex
}
for
i
,
value
:=
range
values
{
...
...
@@ -325,5 +329,5 @@ func (p *privacy) checkPubKeyValid(keys [][]byte, pubkeys [][]byte) (bool, int32
}
}
return
true
,
Invalid_i
ndex
return
true
,
invalidI
ndex
}
plugin/dapp/privacy/executor/query.go
View file @
e4481593
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of
this
source code is governed by a BSD-style
// Use of
p
source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
executor
...
...
@@ -9,18 +9,22 @@ import (
pty
"github.com/33cn/plugin/plugin/dapp/privacy/types"
)
func
(
this
*
privacy
)
Query_ShowAmountsOfUTXO
(
param
*
pty
.
ReqPrivacyToken
)
(
types
.
Message
,
error
)
{
return
this
.
ShowAmountsOfUTXO
(
param
)
// Query_ShowAmountsOfUTXO show amount of utxo
func
(
p
*
privacy
)
Query_ShowAmountsOfUTXO
(
param
*
pty
.
ReqPrivacyToken
)
(
types
.
Message
,
error
)
{
return
p
.
ShowAmountsOfUTXO
(
param
)
}
func
(
this
*
privacy
)
Query_ShowUTXOs4SpecifiedAmount
(
param
*
pty
.
ReqPrivacyToken
)
(
types
.
Message
,
error
)
{
return
this
.
ShowUTXOs4SpecifiedAmount
(
param
)
// Query_ShowUTXOs4SpecifiedAmount shwo utxos for specified amount
func
(
p
*
privacy
)
Query_ShowUTXOs4SpecifiedAmount
(
param
*
pty
.
ReqPrivacyToken
)
(
types
.
Message
,
error
)
{
return
p
.
ShowUTXOs4SpecifiedAmount
(
param
)
}
func
(
this
*
privacy
)
Query_GetUTXOGlobalIndex
(
param
*
pty
.
ReqUTXOGlobalIndex
)
(
types
.
Message
,
error
)
{
return
this
.
getGlobalUtxoIndex
(
param
)
// Query_GetUTXOGlobalIndex get utxo global index
func
(
p
*
privacy
)
Query_GetUTXOGlobalIndex
(
param
*
pty
.
ReqUTXOGlobalIndex
)
(
types
.
Message
,
error
)
{
return
p
.
getGlobalUtxoIndex
(
param
)
}
func
(
this
*
privacy
)
Query_GetTxsByAddr
(
param
*
types
.
ReqAddr
)
(
types
.
Message
,
error
)
{
return
this
.
GetTxsByAddr
(
param
)
// Query_GetTxsByAddr get transactions by address
func
(
p
*
privacy
)
Query_GetTxsByAddr
(
param
*
types
.
ReqAddr
)
(
types
.
Message
,
error
)
{
return
p
.
GetTxsByAddr
(
param
)
}
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