Issue generating when init SDK, "must load certificates before validating"

We’re encountering a recurring error when initializing the Fireblocks SDK on our client. Our client is based on Next.js, and the initialization code is as follows.

The init function is triggered when the “Init Fireblocks” button is clicked. Upon inspecting the messages within the messagesHandler’s handleOutgoingMessage, the console logs display messages for the get_service_certificates, get_cloud_signer_certificate, and report_event methods. However, the following error appears right after these logs:

Error: B: must load certificates before validating

Your guidance on this issue would be greatly appreciated. Thank you!

const initFireblocks = async () => {
    if (!deviceId) {
      throw Error("deviceId is not set");
    }
    try {
      const secureStorageProvider = new InMemorySecureStorageProvider();

      const messagesHandler: IMessagesHandler = {
        handleOutgoingMessage: async (message: string) => {
          console.log("What Message? :", message);
          if (!deviceId) {
            throw new Error("deviceId is not set");
          }
          return custodyPostAction(
            api/fireblocks/${deviceId},
            message
          );
        }
      };

      const eventsHandler: IEventsHandler = {
        handleEvent: (event: TEvent) => {
          console.log("eventsHandler: ", event);
          if (
            event.type === "key_descriptor_changed" 
            event.type === "key_takeover_changed" 
            event.type === "transaction_signature_changed" ||
            event.type === "join_wallet_descriptor"
          ) {
            console.log("What event?", event);
          }
        }
      };

      const ncwInstance = getFireblocksNCWInstance(deviceId);
      if (ncwInstance) {
        console.log("NCW already exist!");
        setFireblocksNCW(ncwInstance);
      } else {
        setFireblocksNCW(
          await FireblocksNCWFactory({
            env: "sandbox",
            deviceId,
            messagesHandler,
            eventsHandler,
            secureStorageProvider
          })
        );
      }
    } catch (e) {
      console.error(e);
    }
  };

Is there a listener on the backend that can process the invoke response? I do see the invoke arrive and the response being sent but it does not appear to be reaching your frontend.

This error usually happens when there is no communication with the Fireblocks server or the messageHandler is incorrectly defined.

You can see a demo implementation of it here: ncw-web-demo/src/AppStore.ts at 47eaca51e19a7ce6ca894fc0f4c10b48e87b6240 · fireblocks/ncw-web-demo · GitHub

While initializing, I noticed that there are three consecutive communications with Fireblocks.

On the backend, the invokeRpc received responses where the first and second communications returned the public key, and the last communication returned { result: { success: true } }.

This indicates that there doesn’t seem to be an issue with communication or message delivery with Fireblocks. Should something be processed after receiving the final response?

Additionally, as you mentioned, the messagesHandler is the same as the code attached above.

Thank you for your support.

@hayyim0626 , I see that in your message handler, you will call this method in your backend.

custodyPostAction(
            api/fireblocks/${deviceId},
            message
          );

Could you share the code for this method in the backend? Is it invoking the RPC method using NCW signer user and returning the response back to the message handler?

You may refer to this - ncw-backend-demo/src/services/device.service.ts at af5c5e7c8f68bdf755c78e712101a36b9c609dc0 · fireblocks/ncw-backend-demo · GitHub