question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't interop with subkey

See original GitHub issue

Guys, I’m driving myself crazy and I hope you can help me out.

If I sign a message with @polkadot, I can’t then verify it with subkey, how does that work?

// Output:
//
// pub: 6a7636545fecfa16f2e37679ea8547685cc2149807f94a4ada6ec0a264ead14d
// secret: a8e59c0eaa54b586bafabe3e4c5597d6b96677c61105e60b0f690327f8d4db4fc7f7331ec0a5bd07390edee454c6e60508af900be8b8682da35b94420992f460
// sig: ead0899d04969bea6857a95a2404babf77844d852431383d7adfabbceebe066b87d3888af454ecf1775dd84e7dbfe12266f15d1346c5d8778bad2cdcf2744683

const { sr25519PairFromSeed, sr25519Sign, cryptoWaitReady } = require('@polkadot/util-crypto')

cryptoWaitReady().then(() => {
    const pair = sr25519PairFromSeed(Buffer.from("42f2524bd7800cc244deb8ce5b4c24cb262c1ba317b86880d7ff33f1e93c6348", 'hex'))

    console.log(Buffer.from(pair.publicKey).toString('hex'))
    console.log(Buffer.from(pair.secretKey).toString('hex'))

    console.log(Buffer.from(sr25519Sign("test message", pair)).toString('hex'))
})

From subkey:

$ subkey inspect "time treat merit corn crystal fiscal banner zoo jacket pulse frog long"
Secret phrase:       time treat merit corn crystal fiscal banner zoo jacket pulse frog long

  Network ID:        substrate
  Secret seed:       0x42f2524bd7800cc244deb8ce5b4c24cb262c1ba317b86880d7ff33f1e93c6348
  Public key (hex):  0x6a7636545fecfa16f2e37679ea8547685cc2149807f94a4ada6ec0a264ead14d
  Account ID:        0x6a7636545fecfa16f2e37679ea8547685cc2149807f94a4ada6ec0a264ead14d
  Public key (SS58): 5EUJ3p7ds1436scqdA2n6ph9xVs6chshRP1ADjgK1Qj3Hqs2
  SS58 Address:      5EUJ3p7ds1436scqdA2n6ph9xVs6chshRP1ADjgK1Qj3Hqs2
  
$ echo "test message" | subkey verify ead0899d04969bea6857a95a2404babf77844d852431383d7adfabbceebe066b87d3888af454ecf1775dd84e7dbfe12266f15d1346c5d8778bad2cdcf2744683 5EUJ3p7ds1436scqdA2n6ph9xVs6chshRP1ADjgK1Qj3Hqs2
Error: SignatureInvalid

For context

I got here because I am getting an error 1010 when submitting a balance transfer to Westend. I then found these two but I didn’t manage to get anywhere either. This code still fails:

const CTX : &'static [u8] = b"substrate";
let sec = SecretKey::generate();
let pub_bytes = sec.to_public().to_bytes();

let message = b"<Bytes>message to sign</Bytes>";

let sig = match (SecretKey::from_ed25519_bytes(&sec.to_bytes()), PublicKey::from_bytes(&pub_bytes)) {
(Ok(s), Ok(k)) => s
	.sign_simple(CTX, message, &k)
	.to_bytes()
	.to_vec(),
_ => panic!("Invalid secret or pubkey provided.")
};


// ext_sr_verify function
let res =   match (Signature::from_bytes(&sig), PublicKey::from_bytes(&pub_bytes)) {
(Ok(s), Ok(k)) => k
	.verify_simple(CTX, message, &s)
	.is_ok(),
_ => false
};

assert!(res)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
georgiosdcommented, May 20, 2022

@jacogr, if you’re ever in Greece, I’m buying you a beer! My email is my github username @ gmail 😃

0reactions
polkadot-js-botcommented, May 27, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.

Read more comments on GitHub >

github_iconTop Results From Across the Web

I can't access certain subkeys in an entry in the registry
I'm trying to get to HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\GameUX\, but the only subkey being returned in C# is MachineSettings - even though there ...
Read more >
Can't open existing SubKey without any Exception in HKLM
Hi,. I've found a very strange situation when reading a key in Registry (found for multiple keys in different pathes).
Read more >
More Information on 'Library not registered ... - IBM
End user is experiencing errors when using Excel-related functionality with Controller. All the errors mention 'Library not registered .
Read more >
Cannot create a stable subkey under a volatile parent key.
I'm getting this exception when launching SQL Server Management Studio (SQL Server 2005 Developer Edition). I installed SQL Server 2005 after Visual
Read more >
[Solved] Windows Registry Create Subkey - CodeProject
CreateRegistrySubKey ("MyNew Application") I can't seem to get this to work correctly. It doesn't create the new subkey in the registry.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found