mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
accounts, rpc: more nocgo alternatives
This commit is contained in:
parent
7f00452de9
commit
4cd0cc5a00
2 changed files with 56 additions and 9 deletions
|
|
@ -37,7 +37,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/crypto/secp256k1"
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
pcsc "github.com/gballet/go-libpcsclite"
|
pcsc "github.com/gballet/go-libpcsclite"
|
||||||
"github.com/status-im/keycard-go/derivationpath"
|
"github.com/status-im/keycard-go/derivationpath"
|
||||||
|
|
@ -1052,13 +1051,10 @@ func (s *Session) sign(path accounts.DerivationPath, hash []byte) ([]byte, error
|
||||||
func determinePublicKey(sig, pubkeyX []byte) ([]byte, error) {
|
func determinePublicKey(sig, pubkeyX []byte) ([]byte, error) {
|
||||||
for v := 0; v < 2; v++ {
|
for v := 0; v < 2; v++ {
|
||||||
sig[64] = byte(v)
|
sig[64] = byte(v)
|
||||||
pubkey, err := crypto.Ecrecover(DerivationSignatureHash[:], sig)
|
if pubkey, err := crypto.Ecrecover(DerivationSignatureHash[:], sig); err == nil {
|
||||||
if err == nil {
|
|
||||||
if bytes.Equal(pubkey, pubkeyX) {
|
if bytes.Equal(pubkey, pubkeyX) {
|
||||||
return pubkey, nil
|
return pubkey, nil
|
||||||
}
|
}
|
||||||
} else if v == 1 || err != secp256k1.ErrRecoverFailed {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, ErrPubkeyMismatch
|
return nil, ErrPubkeyMismatch
|
||||||
|
|
@ -1069,13 +1065,10 @@ func determinePublicKey(sig, pubkeyX []byte) ([]byte, error) {
|
||||||
func makeRecoverableSignature(hash, sig, expectedPubkey []byte) ([]byte, error) {
|
func makeRecoverableSignature(hash, sig, expectedPubkey []byte) ([]byte, error) {
|
||||||
for v := 0; v < 2; v++ {
|
for v := 0; v < 2; v++ {
|
||||||
sig[64] = byte(v)
|
sig[64] = byte(v)
|
||||||
pubkey, err := crypto.Ecrecover(hash, sig)
|
if pubkey, err := crypto.Ecrecover(hash, sig); err == nil {
|
||||||
if err == nil {
|
|
||||||
if bytes.Equal(pubkey, expectedPubkey) {
|
if bytes.Equal(pubkey, expectedPubkey) {
|
||||||
return sig, nil
|
return sig, nil
|
||||||
}
|
}
|
||||||
} else if v == 1 || err != secp256k1.ErrRecoverFailed {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, ErrPubkeyMismatch
|
return nil, ErrPubkeyMismatch
|
||||||
|
|
|
||||||
54
rpc/ipc_unix_nocgo.go
Normal file
54
rpc/ipc_unix_nocgo.go
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
// Copyright 2015 The go-ethereum Authors
|
||||||
|
// This file is part of the go-ethereum library.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
|
||||||
|
|
||||||
|
package rpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ipcListen will create a Unix socket on the given endpoint.
|
||||||
|
func ipcListen(endpoint string) (net.Listener, error) {
|
||||||
|
if len(endpoint) > 255 {
|
||||||
|
log.Warn(fmt.Sprintf("The ipc endpoint is longer than %d characters. ", 255),
|
||||||
|
"endpoint", endpoint)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure the IPC path exists and remove any previous leftover
|
||||||
|
if err := os.MkdirAll(filepath.Dir(endpoint), 0751); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
os.Remove(endpoint)
|
||||||
|
l, err := net.Listen("unix", endpoint)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
os.Chmod(endpoint, 0600)
|
||||||
|
return l, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// newIPCConnection will connect to a Unix socket on the given endpoint.
|
||||||
|
func newIPCConnection(ctx context.Context, endpoint string) (net.Conn, error) {
|
||||||
|
return dialContext(ctx, "unix", endpoint)
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue