2

From the wiki (https://wiki.polkadot.network/docs/build-transaction-construction),

import { createSignedTx } from "@substrate/txwrapper-polkadot";

// Example code, replace `signWithAlice` with actual remote signer.
// An example is given here:
// https://github.com/paritytech/txwrapper-core/blob/b213cabf50f18f0fe710817072a81596e1a53cae/packages/txwrapper-core/src/test-helpers/signWithAlice.ts
const signature = await signWithAlice(signingPayload);
console.log(signature);

const signedTx = createSignedTx(unsigned, signature, { metadataRpc, registry });

The printed signature is simply a hash string like "0x01b0e5778f36fd4c5adea875a5cd88b0da246154798fec28c5d1b4b2446d7b2028c46a423bd9706d26525706386d2dc34062bf83086db5178334d9da5016f2e684"

Question 1: I would like to know whether we could decrypt this hash string to see what informations consist of this signature. i.e whether Polkadot.js APIs supports this decryption.

From the test code (https://github.com/polkadot-js/api/blob/074e790bfc1326cda331b795b3a1e8e480493246/packages/types/src/extrinsic/v4/Extrinsic.spec.ts#L71), we can partly guess some of informations included in signature.

Question 2: From this test code, I would like to know what each data represents as you see below and where we could find how such hash strings are derived depending on the chosen cryptogrphy (ECDSA, Sr25519, or Ed25519). Particularly I look for source code for ECDSA signature.

'0x' + 
'00' + // ?
'd172a74cda4c865912c32ba0a80a57ae69abae410e5ccb59dee84e2f4432db4f' + // ?
'00' + // ed25519 (00) ; sr25519 (01) ; ECDSA (02) 
'eb58b10100923b73df92010db6f9363300ea3947d4c7c92ce669da93931853e8' + // ?  
'a2f21c8a7c73035b3ddd8cdd47ef5db3092aad09d15e6f5ed9d32d7864821409' + // ? 
'00040800' + // era 
'0600' + // nonce 
'00' + // tip 
'd7568e5f0a7eda67a82691ff379ac4bba4f9c9b859fe779b5d46363b61ad2db9' + // ?
'e56c' // ?

I would be very grateful if anyone could advise me. Thanks

1 Answer 1

1

For the second question I suggest you check the code of library @polkadot/util-crypto, the library that PolkadotJS uses to sign/verify. Follow the signatureVerify, where it checks what kind of signature is to know how to verify it.

In your case ECDSA, the code source code to verify the signature is here secp256k1Verify and to sign secp256k1Sign where you can see how the couple (𝑟,𝑠) of the ECDSA signature are concatenated.

Is a code in Rust but it can also be useful for you to check this old answer on StackExchange: Recover ECDSA pub key from signature.

1
  • Thank you for several nice links. I look for the next function which generates a signature (consisting of all informations in Question 2 above) with the value (concatenating r and s values) returned from secp256k1Sign function. Thanks Apr 18 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.