2

I'm trying to generate a typed signature for an array in JavaScript based on EIP-712 and using eth-sig-util.

My problem is that I need to sign an array. It says in the specification to use Type[] or Type[n] for arrays.

Definition: The reference types are arrays and structs. Arrays are either fixed size or dynamic and denoted by Type[n] or Type[] respectively. Structs are references to other structs by their name. The standard supports recursive struct types.

But when I do that, I get the error:

Error: Arrays currently unimplemented in encodeData

Here is how my property and data look:

const signStable = ({ data, prvtKey, properties }) => {
  const trimmedPrivateKey = prvtKey.replace('0x', '');
  const prvtKeyBuffer = Buffer.from(trimmedPrivateKey, 'hex');
  const payload = createPayload({ message: data, properties });
  return ethSigUtils.signTypedData(prvtKeyBuffer, { data: payload });
};

const createPayload = ({
  message,
  properties,
  primaryType = 'RequestParams'
}) => ({
  types: {
    EIP712Domain: [
      { name: 'name', type: 'string' },
      { name: 'version', type: 'string' },
      { name: 'verifyingContract', type: 'address' }
    ],
    ...properties
  },
  primaryType,
  domain: {
    name: 'Fortmatic',
    version: '1',
    verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC'
  },
  message
});

const prvtKey = 'abc...';
const foo = 'foo';
const bar = 'bar';
const id = 'ck35k2yol000bn4op6u0vbteq';
const num = 42;
const arr = [num];
const MyObj = [{ name: 'arr', type: 'number[]' }];
const RequestParams = [
  { name: 'foo', type: 'string' },
  { name: 'bar', type: 'string' },
  { name: id, type: 'MyObj' }
];
const obj = { [id]: { arr }, bar, foo };
const properties = { MyObj, RequestParams };

signStable({ data: obj, properties, prvtKey });

Is there any way to do a typed signature for arrays?

Edit: Based on the comments :)

The line triggering the error is

return ethSigUtils.signTypedData(prvtKeyBuffer, { data: payload });

in my code. And within eth-sig-util its in line 108.

4
  • It says in the specification - please provide link (or by the least indicate which function this statement refers to). – goodvibration Dec 11 '19 at 18:56
  • Error: Arrays currently unimplemented in encodeData - please indicate exactly which line in your code triggers this error. – goodvibration Dec 11 '19 at 18:57
  • @goodvibration Thank you for you help :) I added the lines and the specification quote. – J. Hesters Dec 11 '19 at 19:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.