aptos-wallet-adapter
aptos-wallet-adapter copied to clipboard
Aptos Connect Signature for Sponsored Transactions is Invalid
Context
Requesting a signature via Aptos Connect sometimes results in an invalid Signature error when trying to sponsor and submit the transaction.
Error from the logs: {"message":"Invalid transaction: Type: Validation Code: INVALID_SIGNATURE","error_code":"vm_error","vm_error_code":1}
This behavior is not deterministic, meaning that sometimes the transaction is executed successfully, sometimes the error above is returned. The error happens using Aptos Connect via Browser, as well as via Telegram Mini App.
Steps to Reproduce
The issue can be reproduced by requesting a signature and sponsor the transaction using the following next client- and server functions:
Client:
const { signTransaction, account } = useWallet();
await executeTransaction(account.address, contractPayload);
async executeTransaction(sender: AccountAddressInput, data: EntryPayload) {
const transactionPayload = {
sender,
data,
withFeePayer: true,
};
const transaction = await aptos.transaction.build.simple(transactionPayload);
const userAuthenticator = await signTransaction(transaction);
const serializedUserAuthenticator = new Serializer();
userAuthenticator.serialize(serializedUserAuthenticator);
const transactionSerializer = new Serializer();
transaction.serialize(transactionSerializer);
return await sponsorTranasction(serializedUserAuthenticator.toUint8Array(), transactionSerializer.toUint8Array());
}
Server:
'use server';
export default async function sponsorTranasction(serializedAuthenticator: Uint8Array, serializedTransaction: Uint8Array) {
const privateKey = new Ed25519PrivateKey(...);
const feePayerAccount = Account.fromPrivateKey({ privateKey });
const userAuthenticator = AccountAuthenticator.deserialize(new Deserializer(serializedAuthenticator));
const transaction = SimpleTransaction.deserialize(new Deserializer(serializedTransaction));
const feePayerAuthenticator = aptos.transaction.signAsFeePayer({
signer: feePayerAccount,
transaction,
});
const committedTransaction = await aptos.transaction.submit.simple({
transaction,
senderAuthenticator: userAuthenticator,
feePayerAuthenticator,
});
await aptos.waitForTransaction({ transactionHash: committedTransaction.hash });
}
Expected Behavior
The message signature is valid and the transaction can be executed by the server after sponsoring the gas fees.
Actual Behavior
Sometimes, the user's signature seems to be invalid. This is an excerpt of the server logs: {"message":"Invalid transaction: Type: Validation Code: INVALID_SIGNATURE","error_code":"vm_error","vm_error_code":1}
Debugging Notes
Unfortunately, this error is not deterministic. At one test, after the INVALID_SIGNATURE error already happened twice, the third execution was successfull.
We have debugged the issue so far and reached to the following log. It occurs with all tested endpoints (official/nodit) and intermittently with the following flow: Sign in with Google -> Sign Transaction.
I suspect smth like that the JWT has expired internally and is not being refreshed.
{ "name": "AptosApiError", "url": "https://api.testnet.aptoslabs.com/v1/transactions", "status": 400, "statusText": "Bad Request", "data": { "message": "Invalid transaction: Type: Validation Code: INVALID_SIGNATURE", "error_code": "vm_error", "vm_error_code": 1 }, "request": { "url": "https://api.testnet.aptoslabs.com/v1", "method": "POST", "originMethod": "submitTransaction", "path": "transactions", "body": {"0":102,"1":20,"2":190,"3":91,"4":221,"5":40,"6":68,"7":234,"8":195,"9":26,"10":133,"11":250,"12":40,"13":215,"14":83,"15":164,"16":37,"17":94,"18":66,"19":10,"20":131,"21":150,"22":82,"23":141,"24":39,"25":177,"26":136,"27":55,"28":235,"29":145,"30":225,"31":197,"32":227,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":2,"41":120,"42":183,"43":120,"44":70,"45":82,"46":178,"47":16,"48":171,"49":59,"50":1,"51":157,"52":189,"53":180,"54":36,"55":178,"56":194,"57":55,"58":132,"59":241,"60":18,"61":25,"62":122,"63":50,"64":55,"65":203,"66":200,"67":14,"68":244,"69":207,"70":143,"71":71,"72":40,"73":6,"74":102,"75":97,"76":117,"77":99,"78":101,"79":116,"80":8,"81":99,"82":108,"83":97,"84":105,"85":109,"86":95,"87":120,"88":112,"89":0,"90":0,"91":64,"92":13,"93":3,"94":0,"95":0,"96":0,"97":0,"98":0,"99":100,"100":0,"101":0,"102":0,"103":0,"104":0,"105":0,"106":0,"107":110,"108":252,"109":145,"110":103,"111":0,"112":0,"113":0,"114":0,"115":2,"116":3,"117":2,"118":3,"119":27,"120":104,"121":116,"122":116,"123":112,"124":115,"125":58,"126":47,"127":47,"128":97,"129":99,"130":99,"131":111,"132":117,"133":110,"134":116,"135":115,"136":46,"137":103,"138":111,"139":111,"140":103,"141":108,"142":101,"143":46,"144":99,"145":111,"146":109,"147":32,"148":19,"149":143,"150":225,"151":125,"152":38,"153":212,"154":79,"155":44,"156":8,"157":84,"158":179,"159":46,"160":0,"161":2,"162":246,"163":41,"164":74,"165":210,"166":235,"167":177,"168":126,"169":34,"170":6,"171":80,"172":132,"173":102,"174":243,"175":12,"176":130,"177":227,"178":134,"179":22,"180":3,"181":0,"182":0,"183":43,"184":23,"185":61,"186":93,"187":228,"188":245,"189":47,"190":68,"191":105,"192":220,"193":181,"194":111,"195":66,"196":235,"197":235,"198":83,"199":147,"200":237,"201":193,"202":112,"203":68,"204":99,"205":71,"206":217,"207":120,"208":119,"209":120,"210":236,"211":204,"212":228,"213":250,"214":162,"215":189,"216":152,"217":201,"218":204,"219":9,"220":240,"221":132,"222":65,"223":65,"224":12,"225":238,"226":27,"227":123,"228":136,"229":48,"230":37,"231":29,"232":238,"233":97,"234":243,"235":141,"236":173,"237":181,"238":210,"239":136,"240":191,"241":113,"242":63,"243":124,"244":203,"245":58,"246":43,"247":37,"248":142,"249":180,"250":106,"251":7,"252":7,"253":65,"254":152,"255":215,"256":133,"257":180,"258":212,"259":152,"260":146,"261":175,"262":83,"263":82,"264":103,"265":68,"266":71,"267":222,"268":230,"269":11,"270":43,"271":158,"272":145,"273":243,"274":158,"275":51,"276":177,"277":249,"278":129,"279":246,"280":131,"281":30,"282":115,"283":224,"284":153,"285":78,"286":90,"287":142,"288":175,"289":242,"290":11,"291":218,"292":255,"293":153,"294":126,"295":225,"296":73,"297":90,"298":2,"299":189,"300":73,"301":232,"302":178,"303":146,"304":229,"305":21,"306":192,"307":71,"308":13,"309":81,"310":27,"311":128,"312":150,"313":152,"314":0,"315":0,"316":0,"317":0,"318":0,"319":0,"320":0,"321":1,"322":0,"323":64,"324":174,"325":220,"326":198,"327":36,"328":90,"329":4,"330":145,"331":223,"332":184,"333":31,"334":45,"335":239,"336":159,"337":63,"338":144,"339":202,"340":181,"341":32,"342":123,"343":63,"344":87,"345":58,"346":93,"347":182,"348":141,"349":126,"350":13,"351":122,"352":124,"353":82,"354":254,"355":71,"356":51,"357":137,"358":240,"359":128,"360":162,"361":17,"362":157,"363":150,"364":18,"365":11,"366":88,"367":82,"368":80,"369":178,"370":152,"371":148,"372":83,"373":244,"374":87,"375":136,"376":164,"377":55,"378":26,"379":93,"380":153,"381":137,"382":145,"383":105,"384":199,"385":218,"386":62,"387":3,"388":76,"389":123,"390":34,"391":97,"392":108,"393":103,"394":34,"395":58,"396":34,"397":82,"398":83,"399":50,"400":53,"401":54,"402":34,"403":44,"404":34,"405":107,"406":105,"407":100,"408":34,"409":58,"410":34,"411":54,"412":51,"413":51,"414":55,"415":98,"416":101,"417":54,"418":51,"419":54,"420":52,"421":102,"422":51,"423":56,"424":50,"425":52,"426":48,"427":48,"428":56,"429":100,"430":48,"431":101,"432":57,"433":48,"434":48,"435":51,"436":102,"437":53,"438":48,"439":98,"440":98,"441":54,"442":98,"443":52,"444":51,"445":100,"446":53,"447":97,"448":57,"449":99,"450":54,"451":34,"452":44,"453":34,"454":116,"455":121,"456":112,"457":34,"458":58,"459":34,"460":74,"461":87,"462":84,"463":34,"464":125,"465":58,"466":24,"467":150,"468":103,"469":0,"470":0,"471":0,"472":0,"473":0,"474":32,"475":177,"476":111,"477":183,"478":150,"479":65,"480":179,"481":252,"482":123,"483":40,"484":88,"485":107,"486":20,"487":186,"488":132,"489":151,"490":97,"491":51,"492":189,"493":113,"494":186,"495":196,"496":90,"497":175,"498":169,"499":143,"500":148,"501":10,"502":71,"503":209,"504":159,"505":128,"506":203,"507":0,"508":64,"509":157,"510":225,"511":212,"512":50,"513":106,"514":33,"515":209,"516":183,"517":236,"518":102,"519":89,"520":158,"521":22,"522":127,"523":214,"524":66,"525":190,"526":253,"527":212,"528":132,"529":215,"530":180,"531":45,"532":166,"533":225,"534":44,"535":238,"536":251,"537":200,"538":146,"539":61,"540":158,"541":227,"542":207,"543":10,"544":123,"545":237,"546":16,"547":48,"548":249,"549":162,"550":185,"551":238,"552":205,"553":82,"554":220,"555":139,"556":44,"557":127,"558":16,"559":254,"560":129,"561":51,"562":244,"563":225,"564":9,"565":31,"566":85,"567":153,"568":235,"569":125,"570":241,"571":153,"572":1,"573":0,"574":0,"575":89,"576":233,"577":152,"578":42,"579":170,"580":81,"581":148,"582":5,"583":142,"584":81,"585":200,"586":190,"587":117,"588":81,"589":158,"590":197,"591":76,"592":81,"593":142,"594":163,"595":101,"596":27,"597":58,"598":74,"599":135,"600":195,"601":155,"602":155,"603":216,"604":139,"605":163,"606":20,"607":0,"608":32,"609":163,"610":215,"611":132,"612":245,"613":9,"614":229,"615":189,"616":209,"617":188,"618":217,"619":214,"620":31,"621":179,"622":224,"623":159,"624":197,"625":192,"626":136,"627":87,"628":143,"629":15,"630":211,"631":41,"632":73,"633":39,"634":147,"635":139,"636":242,"637":173,"638":43,"639":181,"640":28,"641":64,"642":56,"643":110,"644":94,"645":144,"646":184,"647":156,"648":241,"649":29,"650":143,"651":141,"652":84,"653":112,"654":193,"655":173,"656":42,"657":15,"658":211,"659":32,"660":40,"661":37,"662":185,"663":120,"664":225,"665":37,"666":101,"667":55,"668":83,"669":42,"670":160,"671":63,"672":152,"673":26,"674":251,"675":76,"676":227,"677":197,"678":202,"679":165,"680":191,"681":9,"682":236,"683":163,"684":254,"685":197,"686":185,"687":83,"688":64,"689":220,"690":160,"691":118,"692":199,"693":248,"694":77,"695":40,"696":99,"697":131,"698":108,"699":199,"700":25,"701":52,"702":212,"703":45,"704":45,"705":8}, "contentType": "application/x.aptos.signed_transaction+bcs", "overrides": { "HEADERS": {} } } }