'Nami wallet and CIP-0008: signData got changed?
I have a web application which is using window.cardano.nami injection since months. Following CIP-0008, I'm trying to abstract all the source code to support ccvault and other Cardano wallets; everything works fine, but it seems the signData method has been changed.
I was using window.cardano.signData and the result was a plaintext signature like this: window.cardano.signData signature
const signedData = await window.cardano.signData(usedAddresses, hexMessage);
I switched to api.signData (where api is the new endpoint returned by window.cardano.nami.enable() and now the signature is an object like this: api.signData signature
const signedData = await wallet.signData(usedAddresses, hexMessage);
So, the type is different, but that's not enough: the signature itself (if I compare the first signature with the .signature attribute of the second signature object) is different!
Even more weird: ccvault works like a charm!
What am I missing?
Solution 1:[1]
The problem is there is a legacy version of nami and a new one, best is to check for both and return the correct one. Then just keep using it like normal.
let connectNami = async () => {
// @ts-ignore
if (typeof window.cardano.nami !== "undefined") {
// @ts-ignore
return await window.cardano.nami.enable();
} else {
console.debug(`Using legacy nami wallet integration`);
// @ts-ignore
await window.cardano.enable();
// @ts-ignore
return window.cardano;
}
};
const cardano= await connectNami();
const token = await cardano.signData(address, messageToSign);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sandro Schaier |
