Hey all,
I am currently having an issue with signing a serialized message used for a sponsored txn.
I have followed the necessary steps to serialize a message but it won’t sign it. If there were errors in my steps that should hinder the serialization process.
The given message does not have correct format.
at sb.signMessage
if (serializedMessage !== '') {
console.log(serializedMessage, 'serializedMessage');
const promise = ccProvider.signMessage(caccount, {
type: 'BinaryMessage',
value: serializedMessage,
schema: typeSchemaFromBase64(SERIALIZATION_HELPER_SCHEMA),
});
promise
.then(async (permitSignature: any) => {
console.log(permitSignature);
await submitMintOperation({
backend: VERIFIER_URL,
nonce: 0,
signature: permitSignature[0][0],
expiryTimeSignature,
to: account,
signer: TXN_SIGNER,
token_id,
});
})
.catch((err: Error) => {
console.log(err, 'err here');
});
}
What could be the possible reason for this?
Doris
February 25, 2024, 12:55pm
2
Your above code does not show how you get to the value serializedMessage
which makes it difficult to help. If you used our sponsored transaction example, then comparing your code with the example dapp code, you might miss the Buffer
part.
import { Buffer } from 'buffer/';
...
const permitSignature = await connection.signMessage(account, {
type: 'BinaryMessage',
value: Buffer.from(serializedMessage.buffer),
schema: typeSchemaFromBase64(SERIALIZATION_HELPER_SCHEMA_PERMIT_MESSAGE),
});
Thank you @Doris , here is my code from the generateMintMessage
function and I still get same error.
const mintData = {
owner: {
Account: [account],
},
metadata_url: {
url: 'https://gateway.pinata.cloud/ipfs/QmZ3939dLLFzvYZjFnkdqACe2n9TQA8Rx4efbjaYTXteeu',
hash: {
Some: [
'f982b4603b9c116598d381d1aee90a7b5332377b209b6bbd8d7a4dfab18f2a80',
],
},
},
token_id,
amount: '1',
};
const payload = serializeTypeValue(
mintData,
toBuffer(MINT_PARAMETER_SCHEMA, 'base64'),
);
const message = {
contract_address: {
index: SPONSORED_TX_CONTRACT_INDEX,
subindex: 0,
},
nonce,
timestamp: expiryTimeSignature,
entry_point: 'mint',
payload: Array.from(payload),
};
const serializedMessage = serializeTypeValue(
message,
toBuffer(SERIALIZATION_HELPER_SCHEMA, 'base64'),
);
return serializedMessage;
Doris
February 29, 2024, 1:02pm
4
We have two sponsored transaction examples that showcase how you can construct the serializedMessage and provide it to the wallet connected via the walletConnect
library (GitHub - Concordium/concordium-dapp-libraries: A coherent set of building blocks for making it as easy as possible for developers to build web-based dApps. ). Does it help to follow along the code example?
try {
const serializedMessage = await generateTransferMessage(
setTokenID,
expiryTimeSignature,
account,
data.nonce,
data.tokenAmount,
data.itemIndex,
);
const permitSignature = await connection.signMessage(account, {
type: 'BinaryMessage',
value: Buffer.from(serializedMessage.buffer),
schema: typeSchemaFromBase64(SERIALIZATION_HELPER_SCHEMA_PERMIT_MESSAGE),
});
setSignature(permitSignature[0][0]);
} catch (err) {
setSigningError((err as Error).message);
}
}
// RFC 3339 format (e.g. 2030-08-08T05:15:00Z)
const expiryTimeSignature = date.toISOString();
setExpiryTime(expiryTimeSignature);
const serializedMessage = isUpdateOperatorTab
? await generateUpdateOperatorMessage(expiryTimeSignature, nonce, operator, addOperator)
: await generateTransferMessage(expiryTimeSignature, nonce, tokenID, from, to);
if (serializedMessage !== '') {
const promise = connection.signMessage(account, {
type: 'BinaryMessage',
value: serializedMessage,
schema: typeSchemaFromBase64(SERIALIZATION_HELPER_SCHEMA),
});
promise
.then((permitSignature) => {
setSignature(permitSignature[0][0]);
})
.catch((err: Error) => setSigningError((err as Error).message));