Closed araa47 closed 4 years ago
The extension implements the Signer
interface, which looks like this -
export interface Signer {
/**
* @description signs an extrinsic payload from a serialized form
*/
signPayload?: (payload: SignerPayloadJSON) => Promise<SignerResult>;
/**
* @description signs a raw payload, only the bytes data as supplied
*/
signRaw?: (raw: SignerPayloadRaw) => Promise<SignerResult>;
/**
* @description Receives an update for the extrinsic signed by a `signer.sign`
*/
update?: (id: number, status: H256 | ISubmittableResult) => void;
}
The signRaw
is what you are looking for. Passing through (data as hex) { address: string, data: string, type: 'payload' | 'bytes' }
Im able to call the method signRaw
and pass it the payload, however the polkadot extension seems to be stuck after I enter my password. It does not seem to return anything. How can i work on debugging this problem? Ive tried re-installing the extension and setting up a new wallet but ran into the same problem.
Check the logs, ensure you have the correct password, ensure the encoding is correct, example of use in the wild -
Thanks, seems like I'm able to generate a signature without issues now. However I am having troubles verifying this generated signature. It seems to be different from what I generate when I use keyRing. I noticed the length of the signature when converted to Uint8Array was different, so I assumed when using signer.signRaw, I need to add the type info on my own. However this does not seem to solve my issue and I still have problems verifying my signature generated in this method.
// takes an offer and returns a signature
async signOffer(keyRingPair, offer) {
const encodedOffer = offer.toU8a();
const signature = keyRingPair.sign(encodedOffer, { withType: true });
return signature;
}
// takes an offer type
asyn verify(offer, signature, address){
const encoded_offer = offer.toU8a();
const hexsig = signature.toHex();
const isValid = UtilCrypto.signatureVerify(encoded_offer, hexsig, address);
}
async signOffer(injector, offer, address){
// offer is a custom type on my chain
const encodedData = offer.toU8a();
const { signature } = await injector.signer.signRaw({
address: address,
data: stringToHex(encodedData),
type: 'bytes'
});
// convert to u8a array
const encodedSig = parrotSwap.parrot.util.hexToU8a(signature);
// add type information to this signature so length is 65
const encodedSigWithType = u8aConcat(new Uint8Array([0]), encodedSig);
return encodedSigWithType
}
Same as above
Error
Invalid Signature
Yes, it is a straight 64-byte signature.
const encodedSigWithType = u8aConcat(new Uint8Array([0]), encodedSig);
The extension signatures are sr25519 - https://github.com/polkadot-js/common/blob/master/packages/keyring/src/pair/index.ts#L23
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.
Hi, I currently need to sign a message and return this signature back to my UI.
With KeyRings I could initially do
how do i achieve a similar signature using the injected address?
Ive tried
but I get the following error
injector.signer.sign is not a function