Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
contract_backend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
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
Odysseus
contract_backend
Commits
b818ad31
Commit
b818ad31
authored
Nov 01, 2024
by
贾浩@五瓣科技
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix private key
parent
82e68f7e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
9 deletions
+13
-9
contract.go
dao/contract.go
+4
-2
user.go
server/user.go
+5
-4
hdkey.go
util/hdkey.go
+4
-3
No files found.
dao/contract.go
View file @
b818ad31
...
@@ -13,12 +13,13 @@ import (
...
@@ -13,12 +13,13 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
)
)
func
(
d
*
Dao
)
Login
(
privateKey
*
ecdsa
.
PrivateKey
,
userId
string
,
inviter
string
)
(
txHash
common
.
Hash
,
err
error
)
{
func
(
d
*
Dao
)
Login
(
byteKey
[]
byte
,
userId
string
,
inviter
string
)
(
txHash
common
.
Hash
,
err
error
)
{
instance
,
err
:=
aon_user
.
NewAonUser
(
common
.
HexToAddress
(
d
.
c
.
Chain
.
UserContract
),
d
.
ethClient
)
instance
,
err
:=
aon_user
.
NewAonUser
(
common
.
HexToAddress
(
d
.
c
.
Chain
.
UserContract
),
d
.
ethClient
)
if
err
!=
nil
{
if
err
!=
nil
{
return
common
.
Hash
{},
err
return
common
.
Hash
{},
err
}
}
privateKey
:=
crypto
.
ToECDSAUnsafe
(
byteKey
)
auth
,
err
:=
bind
.
NewKeyedTransactorWithChainID
(
privateKey
,
d
.
chainId
)
auth
,
err
:=
bind
.
NewKeyedTransactorWithChainID
(
privateKey
,
d
.
chainId
)
if
err
!=
nil
{
if
err
!=
nil
{
return
common
.
Hash
{},
err
return
common
.
Hash
{},
err
...
@@ -32,11 +33,12 @@ func (d *Dao) Login(privateKey *ecdsa.PrivateKey, userId string, inviter string)
...
@@ -32,11 +33,12 @@ func (d *Dao) Login(privateKey *ecdsa.PrivateKey, userId string, inviter string)
return
tx
.
Hash
(),
nil
return
tx
.
Hash
(),
nil
}
}
func
(
d
*
Dao
)
CheckApprove
(
privateKey
*
ecdsa
.
PrivateKey
)
(
txHash
common
.
Hash
,
err
error
)
{
func
(
d
*
Dao
)
CheckApprove
(
byteKey
[]
byte
)
(
txHash
common
.
Hash
,
err
error
)
{
instance
,
err
:=
erc20
.
NewErc20
(
common
.
HexToAddress
(
d
.
c
.
Chain
.
AppPointContract
),
d
.
ethClient
)
instance
,
err
:=
erc20
.
NewErc20
(
common
.
HexToAddress
(
d
.
c
.
Chain
.
AppPointContract
),
d
.
ethClient
)
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
privateKey
:=
crypto
.
ToECDSAUnsafe
(
byteKey
)
user
:=
crypto
.
PubkeyToAddress
(
privateKey
.
PublicKey
)
user
:=
crypto
.
PubkeyToAddress
(
privateKey
.
PublicKey
)
allowance
,
err
:=
instance
.
Allowance
(
&
bind
.
CallOpts
{},
user
,
common
.
HexToAddress
(
d
.
c
.
Chain
.
ExecutorContract
))
allowance
,
err
:=
instance
.
Allowance
(
&
bind
.
CallOpts
{},
user
,
common
.
HexToAddress
(
d
.
c
.
Chain
.
ExecutorContract
))
if
err
!=
nil
{
if
err
!=
nil
{
...
...
server/user.go
View file @
b818ad31
...
@@ -3,11 +3,11 @@ package server
...
@@ -3,11 +3,11 @@ package server
import
(
import
(
.
"contract_backend/constant"
.
"contract_backend/constant"
"contract_backend/util"
"contract_backend/util"
"crypto/ecdsa"
"fmt"
"fmt"
"io"
"io"
"time"
"time"
"github.com/btcsuite/btcd/btcec"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
...
@@ -33,7 +33,7 @@ func userChange(c *gin.Context) {
...
@@ -33,7 +33,7 @@ func userChange(c *gin.Context) {
}
}
var
userId
string
var
userId
string
var
key
*
ecdsa
.
PrivateKey
var
key
*
btcec
.
PrivateKey
operation
:=
gjson
.
Get
(
string
(
rawJson
),
"operation"
)
.
String
()
operation
:=
gjson
.
Get
(
string
(
rawJson
),
"operation"
)
.
String
()
switch
operation
{
switch
operation
{
...
@@ -120,7 +120,8 @@ func userChange(c *gin.Context) {
...
@@ -120,7 +120,8 @@ func userChange(c *gin.Context) {
time
.
Sleep
(
time
.
Second
)
time
.
Sleep
(
time
.
Second
)
}
}
txHash
,
err
:=
d
.
Login
(
key
,
userId
,
""
)
// 在alpine nocgo上使用ecdsa.PrivateKey会报错 msg="call ca login error" error="private key curve is not secp256k1"
txHash
,
err
:=
d
.
Login
(
key
.
Serialize
(),
userId
,
""
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"call ca login error"
)
log
.
WithError
(
err
)
.
Error
(
"call ca login error"
)
c
.
JSON
(
200
,
withError
(
InternalError
))
c
.
JSON
(
200
,
withError
(
InternalError
))
...
@@ -133,7 +134,7 @@ func userChange(c *gin.Context) {
...
@@ -133,7 +134,7 @@ func userChange(c *gin.Context) {
})
.
Info
(
"user login"
)
})
.
Info
(
"user login"
)
go
func
()
{
go
func
()
{
txHash
,
err
=
d
.
CheckApprove
(
key
)
txHash
,
err
=
d
.
CheckApprove
(
key
.
Serialize
()
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"call ca check approve error"
)
log
.
WithError
(
err
)
.
Error
(
"call ca check approve error"
)
return
return
...
...
util/hdkey.go
View file @
b818ad31
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
"strconv"
"strconv"
"strings"
"strings"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcutil/hdkeychain"
"github.com/btcsuite/btcutil/hdkeychain"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
...
@@ -34,7 +35,7 @@ func GetAddressByUserId(xpub, userId string) (output common.Address, err error)
...
@@ -34,7 +35,7 @@ func GetAddressByUserId(xpub, userId string) (output common.Address, err error)
return
crypto
.
PubkeyToAddress
(
*
pubkey
),
nil
return
crypto
.
PubkeyToAddress
(
*
pubkey
),
nil
}
}
func
GetPrivateKeyByUserId
(
xpriv
,
userId
string
)
(
key
*
ecdsa
.
PrivateKey
,
err
error
)
{
func
GetPrivateKeyByUserId
(
xpriv
,
userId
string
)
(
key
*
btcec
.
PrivateKey
,
err
error
)
{
uid
,
err
:=
uuid
.
Parse
(
userId
)
uid
,
err
:=
uuid
.
Parse
(
userId
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -87,7 +88,7 @@ func GetDepositAddress(input common.Address, xpub string) (output common.Address
...
@@ -87,7 +88,7 @@ func GetDepositAddress(input common.Address, xpub string) (output common.Address
// }
// }
// return pk.ToECDSA(), nil
// return pk.ToECDSA(), nil
func
GetPrivKeyByPriv
(
xpriv
string
,
path
string
)
(
privkey
*
ecdsa
.
PrivateKey
,
err
error
)
{
func
GetPrivKeyByPriv
(
xpriv
string
,
path
string
)
(
privkey
*
btcec
.
PrivateKey
,
err
error
)
{
pathList
:=
parsePath
(
path
)
pathList
:=
parsePath
(
path
)
var
next
*
hdkeychain
.
ExtendedKey
var
next
*
hdkeychain
.
ExtendedKey
for
_
,
floor
:=
range
pathList
{
for
_
,
floor
:=
range
pathList
{
...
@@ -103,7 +104,7 @@ func GetPrivKeyByPriv(xpriv string, path string) (privkey *ecdsa.PrivateKey, err
...
@@ -103,7 +104,7 @@ func GetPrivKeyByPriv(xpriv string, path string) (privkey *ecdsa.PrivateKey, err
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
return
pk
.
ToECDSA
()
,
nil
return
pk
,
nil
}
}
func
GetPubKeyByPub
(
xpub
string
,
path
string
)
(
pubkey
*
ecdsa
.
PublicKey
,
err
error
)
{
func
GetPubKeyByPub
(
xpub
string
,
path
string
)
(
pubkey
*
ecdsa
.
PublicKey
,
err
error
)
{
...
...
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