go-substrate-rpc-client
go-substrate-rpc-client copied to clipboard
use ecdsa signature and submit extrinsic.but got 'Transaction has a bad signature'
Due to the problem of public key derivation, I considered using ecdsa to generate an account. But after ecdsa signs, there will be signature errors. Where should I go to troubleshoot and solve this problem?
in the westend network,i use code like that:
scheme := ecdsa.Scheme{}
pari, err := scheme.FromSeed(secert)
if err != nil {
return nil, nil, err
}
sig, err := signECDSA(data, hex.EncodeToString(signer.Seed()))
if err != nil {
return e, err
}
multiSig := types.MultiSignature{IsEcdsa: true, AsEcdsa: types.NewBytes(sig)}
func signECDSA(data []byte, privateKeyURI string) ([]byte, error) {
// if data is longer than 256 bytes, hash it first
if len(data) > 256 {
h := blake2b.Sum256(data)
data = h[:]
}
scheme := ecdsa.Scheme{}
kyr, err := subkey.DeriveKeyPair(scheme, privateKeyURI)
if err != nil {
return nil, err
}
signature, err := kyr.Sign(data)
if err != nil {
return nil, err
}
return signature, nil
}
And in the ecdsa,the public key is 33 byte, but 'MultiAddress'
type MultiAddress struct {
AccountId AccountID
Index UCompact
Raw Bytes
Address32 H256
Address20 H160
types int
}
accountid is 32 byte. I think it was caused by an error in the public key transmission,but i can`t fix this by change MultiAddress.
code : sign_ecdsa.go
plz help
@litterGuy have you tried the RawBytes?
@litterGuy have you tried the RawBytes?
Also tried. Set RawBytes as public key ( 33 byte ), and result the error is
{"Code":1011,"Message":"Unknown Transaction Validity","Data":"CannotLookup"}
@litterGuy i just looked at the substrate code. looks like you have to do a blake2b hash of compressed 33 byte pub key to get 32 byte key which will be the public key - sp_io::hashing::blake2_256(&who.as_ref()[..]).into()
https://github.com/paritytech/substrate/blob/master/primitives/runtime/src/lib.rs#L292.
You can give it a shot if you want
Thanks for the help, i will try later
accountId:= blake2b.Sum256(kr.Public())
and set accountId(32 byte) to raw, also get the same error is :
{"Code":1011,"Message":"Unknown Transaction Validity","Data":"CannotLookup"}
when set "AsID" = accountId , the error is 'Transaction has a bad signature'.
are there any other suggestions?
This issue seems stale, closing it for now. Please let us know if you still need help.