Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined: secp256k1.RecoverPubkey #103

Open
yangyile1990 opened this issue Sep 9, 2023 · 6 comments · May be fixed by #135
Open

undefined: secp256k1.RecoverPubkey #103

yangyile1990 opened this issue Sep 9, 2023 · 6 comments · May be fixed by #135

Comments

@yangyile1990
Copy link

/go/pkg/mod/github.com/fbsobreira/[email protected]/pkg/keystore/recover.go:17:33: undefined: secp256k1.RecoverPubkey

FROM golang:alpine as builder
#FROM golang:1.20 AS builder

#由于是使用了私有的gitlab的代码包,因此在编译时需要用到 git 命令拉代码
RUN apk update && apk add --no-cache git
#RUN apt-get update && apt-get install -y git

WORKDIR /work

ADD . /work

#由于 go module 中使用了私有gitlab的代码包,因此需要拉代码,需要密码
RUN cp ./config/.netrc ~/.netrc && chmod 0600 ~/.netrc

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main cmd/main.go

FROM amd64/alpine:latest
#FROM debian:stable-slim

WORKDIR /work

COPY --from=builder /work/main /work

CMD ["./main", "-path=./config"]

@yangyile1990
Copy link
Author

I knew it. because the:

//go:build !gofuzz && cgo
// +build !gofuzz,cgo

while I close the cgo:

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main cmd/main.go

@yangyile1990
Copy link
Author

yangyile1990 commented Sep 9, 2023

but I cannot open the cgo.

unrecognized command-line option '-m64'

because:

在 Alpine Linux 上,GCC 不支持 -m64 选项。

I think you should do some change. to make sure "even user not open cgo, can also use the sdk".
thank you.

@yangyile1990
Copy link
Author

yangyile1990 commented Sep 9, 2023

I can build with this dockerfile config.

#FROM golang:alpine as builder
#FROM golang:1.20 AS builder
FROM --platform=linux/amd64 golang:1.20-alpine AS builder

# 由于是使用了私有的gitlab的代码包,因此在编译时需要用到 git 命令拉代码
# 更新包并安装 Git
RUN apk update && apk add --no-cache git
#RUN apt-get update && apt-get install -y git

RUN apk add --no-cache gcc
RUN apk add --no-cache build-base

WORKDIR /work

ADD . /work

#由于 go module 中使用了私有gitlab的代码包,因此需要拉代码,需要密码
# 复制 .netrc 文件并设置权限
RUN cp ./config/.netrc ~/.netrc && chmod 0600 ~/.netrc

RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o main cmd/main.go

FROM amd64/alpine:latest
#FROM debian:stable-slim

WORKDIR /work

COPY --from=builder /work/main /work

CMD ["./main", "-path=./config"]

But it takes me about 288.4 seconds.

[+] Building 288.4s (17/17) FINISHED 

So, could you please make some change. to make sure, even not open cgo. can build success.

@kslamph
Copy link

kslamph commented Oct 3, 2023

#107
this is a fallback implementation of secp256k1.RecoverPubkey without cgo

@yangyile1990
Copy link
Author

#107 this is a fallback implementation of secp256k1.RecoverPubkey without cgo

waiting for your good news.

@pengbotter
Copy link

Use the btcec library to replace it

import (
btcecdsa "github.com/btcsuite/btcd/btcec/v2/ecdsa"
"github.com/fbsobreira/gotron-sdk/pkg/address"
"crypto/ecdsa"
)

func Recover(signature, data []byte) (*ecdsa.PublicKey, error) {
if len(signature) != 65 {
return nil, errors.New("invalid signature length")
}
// Convert to btcec input format with 'recovery id' v at the beginning.
btcsig := make([]byte, 65)
btcsig[0] = signature[64]
copy(btcsig[1:], signature)

//hash, err := hashWithEthereumPrefix(data)
//if err != nil {
//	return nil, err
//}

pbk, _, err := btcecdsa.RecoverCompact(btcsig, data)
if err != nil {
	return nil, err
}
return pbk.ToECDSA(), err

}

// RecoverPubkey To secp256k1.RecoverPubkey
func RecoverPubkey(hash []byte, signature []byte) (address.Address, error) {
pubKey1, err := Recover(signature, hash)
if err != nil {
return nil, err
}

addr := address.PubkeyToAddress(*pubKey1)
return addr, nil

}

@subnix subnix linked a pull request May 30, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants