```js Mutation: { createHaloAccount(_, args, c...
# orm-help
h
Copy code
js
Mutation: {
    createHaloAccount(_, args, ctx, info) {
      // Check signature is valid for the halo address with ecRecover before assigning a deposit address
      let isValid = isValidSignature(args.authPayload.message, args.authPayload.signature, args.authPayload.haloAddress);
      if (isValid) {
        let { address, privateKey } = web3.eth.accounts.create(web3.utils.randomHex(32));
        let encryptedPrivateKey = encrypt(privateKey, MAINTESTER_PRIVATEKEY);

        // Create a haloAccount if it doesn't already exist for the provided halo address
        // Or update the provided account with the eth address
        return ctx.prisma.mutation.createHaloAccount({
          data: {
            haloAddress: args.authPayload.haloAddress,
            ethAccount: {
              create: {
                address: address,
                encryptedPrivateKey: encryptedPrivateKey
              }
            }
          },
        },
          info,
        );
      } else {
        return console.error("Invalid authPayload provided for the account requested.")
      }
    }
}