Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"producerInfo" must be a non-empty Uint8Array, yet methods calling deriveKey are passing buffers #79

Open
cykoder opened this issue Mar 26, 2021 · 0 comments

Comments

@cykoder
Copy link

cykoder commented Mar 26, 2021

This error for producer/consumer info is rather annoying, I don't think my implementation is wrong, and if I comment out these lines manually everything works as expected. I can see why there may be a need for a type check here:
https://github.com/transmute-industries/did-key.js/blame/c1bef568ad9afd703ba9ac3d42b919ccfdf10aee/packages/did-key-cipher/src/Cipher/algorithms/ecdhkdf.ts#L50

But, in this method (and other methods that call derivekey): https://github.com/transmute-industries/did-key.js/blob/master/packages/x25519/src/X25519KeyPair.ts#L137 its passing buffers for producer/consumer info variables. As seen here: https://github.com/transmute-industries/did-key.js/blob/master/packages/x25519/src/X25519KeyPair.ts#L158

Here's what producerInfo/consumerInfo look like when passed to derivedKey, it looks correct - just should be in a different format.

  console.log node_modules/@transmute/did-key-cipher/dist/did-key-cipher.cjs.development.js:54
    producerInfo <Buffer ee 7d a9 e2 96 dc 7b 46 54 e4 03 04 84 7e 6b a8 8b 5f d6 1a f6 cd 5f cd af 14 21 64 70 ab ca 57>

  console.log node_modules/@transmute/did-key-cipher/dist/did-key-cipher.cjs.development.js:55
    consumerInfo <Buffer 64 69 64 3a 6b 65 79 3a 7a 36 4c 53 68 39 51 5a 37 58 76 6b 73 52 37 64 76 35 50 6e 68 36 73 46 75 69 54 63 71 31 46 32 58 6d 58 53 35 42 73 62 31 36 ... 55 more bytes>

This of course causes it to fail for me. Am I doing something wrong, or is this a bug? I am using node 14, I have tried with 13 and same issue. Usage is like:

const kp = await X25519KeyPair.generate({
  secureRandom: () => derivedKey, // derivedKey is a uint8array
});
  const keyResolver = ({ id }) => {
    if (kp.id === id) {
      return kp.toJsonWebKeyPair(false);
    }
    throw new Error(`Key ${id} not found`);
  };

  const cipher = new Cipher(X25519KeyPair);
  return await Promise.all(
    contents.map((content) => cipher.encryptObject({
      obj: { ...content },
      recipients: [...recipients],
      keyResolver,
    })),
  );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant