Signature error when update request to motoko takes a long time

Server returned an error:
I am seeing this error when calling to my motoko backend canister

Code: 400 (Bad Request)
  Body: Invalid signature: Invalid basic signature: Ed25519 signature could not be verified: public key e9de264ff18e7faaf551b7bbbab85affed592b82643796abef20f1ff6b5ac9a3, signature 8f92f2f70c22e4bb422c16e8d46c6297391ad8698f6342ae5c8546f0b48c807dd88fdc34da291494f4e5fd03f30fbdaea750784c44fb5a6d7e6152015cc82903, error: A signature was invalid


Error: AgentHTTPResponseError [AgentError]: Server returned an error:
  Code: 400 (Bad Request)
  Body: Invalid signature: Invalid basic signature: Ed25519 signature could not be verified: public key e9de264ff18e7faaf551b7bbbab85affed592b82643796abef20f1ff6b5ac9a3, signature ce98d87b2399ba4be6eab414e2f8c0efc9b477a349c8a9679e1afe03da2561d5814b15aed1bc6381d38dc07d2eb0cca17823c3a843a01bee96e6e0cae9e09507, error: A signature was invalid

    at HttpAgent._HttpAgent_requestAndRetry (/Users/jakebeard/Documents/GitHub/vault-labs-exchange/node_modules/@dfinity/agent/lib/cjs/agent/http/index.js:854:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async HttpAgent._HttpAgent_requestAndRetry (/Users/jakebeard/Documents/GitHub/vault-labs-exchange/node_modules/@dfinity/agent/lib/cjs/agent/http/index.js:852:16)
    at async HttpAgent._HttpAgent_requestAndRetry (/Users/jakebeard/Documents/GitHub/vault-labs-exchange/node_modules/@dfinity/agent/lib/cjs/agent/http/index.js:852:16)
    at async HttpAgent._HttpAgent_requestAndRetry (/Users/jakebeard/Documents/GitHub/vault-labs-exchange/node_modules/@dfinity/agent/lib/cjs/agent/http/index.js:852:16)
    at async HttpAgent.readState (/Users/jakebeard/Documents/GitHub/vault-labs-exchange/node_modules/@dfinity/agent/lib/cjs/agent/http/index.js:595:30)
    at async pollForResponse (/Users/jakebeard/Documents/GitHub/vault-labs-exchange/node_modules/@dfinity/agent/lib/cjs/polling/index.js:53:19)
    at async caller (/Users/jakebeard/Documents/GitHub/vault-labs-exchange/node_modules/@dfinity/agent/lib/cjs/actor.js:290:34)
    at async Object.panicEvent (file:///Users/jakebeard/Documents/GitHub/vault-labs-exchange/node_modules/@infu/icblast/esm/index.js:1:4524)
    at async main (/Users/jakebeard/Documents/GitHub/vault-labs-exchange/test.js:306:26) {
  response: {
    ok: false,
    status: 400,
    statusText: 'Bad Request',
    headers: [
      [Array], [Array],
      [Array], [Array],
      [Array], [Array],
      [Array], [Array],
      [Array]
    ]
  }
}

Here is my test function that is failing

async function main() {
  try {
    const icblastModule = await import('@infu/icblast');
    const { default: icblast, hashIdentity } = icblastModule;

    const canisterID = 'j5kl4-5yaaa-aaaag-ak5fa-cai';

    const hash = 'blah-blah-blah';
    const identity = hashIdentity(hash);

    const principal = identity.getPrincipal().toString();

    const ic = icblast({ identity: identity });

    let actor = await ic(canisterID, idlFactory);
    const admins = await actor.getAdmins();
    console.log(admins);

    const res = await actor.updateOrderBookState(1, { Finishing: null });
    console.log(res);

    const endEventData = await actor.panicEvent();
    console.log(endEventData);
  } catch (error) {
    console.error('Error:', error);
  }
}

main();

These first two calls are quite fast and respond successfully

however the following call takes a bit longer and fails (panicEvent)

    const admins = await actor.getAdmins();
    console.log(admins);

    const res = await actor.updateOrderBookState(1, { Finishing: null });
    console.log(res);

I see this kind of errors when identity session expires. You need to re-authenticate.
I think icblast has misplaced the props. They should be here
image
and not inside auth.client.login

I think this might be related to browser errors. I am doing this in a backend server

This code produces the same error response

async function main() {
  try {
    const icblastModule = await import('@infu/icblast');
    const { HttpAgent } = await import('@dfinity/agent');
    const { Actor } = await import('@dfinity/agent');
    const { Ed25519KeyIdentity } = await import('@dfinity/identity');
    const { sha256 } = await import("js-sha256");


    // Doesn't work in Electron
    // export const file = async (path) =>
    //   Array.from(new Uint8Array(await (await blobFrom(path)).arrayBuffer()));

    const hashIdentity = (pass) => {
      const hash = sha256.create();
      hash.update(pass);
      let entropy = new Uint8Array(hash.digest());
      let identity = Ed25519KeyIdentity.generate(entropy);
      return identity;
    };

    const canisterID = 'j5kl4-5yaaa-aaaag-ak5fa-cai';
    const hash = 'game-controller-development';
    const identity = hashIdentity(hash);
    console.log('Public Key:', identity.getPublicKey().toDer());
    console.log('Principal:', identity.getPrincipal().toString());
    const IC_HOST = 'https://icp0.io';

    // Create agent properly with async initialization
    const agent = await HttpAgent.create({
      host: IC_HOST,
      identity,
      shouldFetchRootKey: true,
      // Add retry configuration
      retryTimes: 3,
      verifyQuerySignatures: false,
      backoffStrategy: () => {
        let attempts = 0;
        return {
          next: () => {
            attempts++;
            return attempts <= 3 ? 1000 * attempts : null;
          },
        };
      },
      // Add fetch options with longer timeout
      fetchOptions: {
        timeout: 300000, // 5 minutes
      },
      // Add call options with longer timeout
      callOptions: {
        deadline: BigInt(Date.now() + 300_000), // 5 minutes from now
      },
    });

    // Sync time with the network
    await agent.syncTime();

    const actor = Actor.createActor(idlFactory, {
      agent,
      canisterId: canisterID,
    });

    const admins = await actor.getAdmins();
    console.log(admins);

    const res = await actor.updateOrderBookState(1, { Finishing: null });
    console.log(res);

    const endEventData = await actor.panicEvent();
    console.log(endEventData);
    // const res2 = await actor.panicMarket(1);
    // console.log('Panic Market Result:', res2);
  } catch (error) {
    console.error('Error:', error);
  }
}
main();

If I change the backend to execute quicker i no longer receive this error. But this is not a solution to my problem

Ooo thanks - this may be a reproduction of an intermittent bug I’ve been interested in hunting down

Let me know if theres anyway i can help my discord is BustyBeardo

bustybeardo

Whoops - caught covid right after replying