Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Groups are not supported error when creating a new node deterministically #1946

Closed
rmisio opened this issue Mar 18, 2019 · 8 comments
Closed

Comments

@rmisio
Copy link

rmisio commented Mar 18, 2019

Version: 0.34.4
Platform: OSX
Browse: Chrome

When I try to create a new IPFS node with a specific peerId, I get a "Groups not supported" error.

image

Here's how I'm creating the node:

new IPFS({
  "EXPERIMENTAL": {
    "pubsub": true,
    "ipnsPubsub": true
  },
  "relay": {
    "enabled": true
  },
  "repo": "./ipfs/QmUgy68cwca6FwXJf9LnoXzyM64LwsomfWDVLQTHXRbXgw",
  "init": {
    "privateKey": "Yx/lrMILAKM2bLsS8FnfOJSYkaiBUNF3OCLuHCGCoXveyXd6x2fG393UN+YITA7YgeshWTcLHMnpUMJME4gtqw=="
  }
});

The ready handler never fires and the error comes through via the error handler.

@rmisio
Copy link
Author

rmisio commented Mar 18, 2019

If I remove the EXPERIMENTAL and relay keys, then I get a different error:

image

{
  "repo": "ipfs/QmWTnbv52ipaJgdjj7QiP46TJoLHpz9EChf47doYFAX9bj",
  "init": {
    "privateKey": "mLVMlgsvjFd7Q7xOA2/m9HC+aNSFkFRUVLsPY8F4sboF5Y5Tj6xQ+8G1HnfxAaf+1+p6GxCu359GIFI0oMCilg=="
  }
}

@rmisio
Copy link
Author

rmisio commented Mar 18, 2019

Is the schema of the options I'm providing not correct?

@alanshaw
Copy link
Member

@jacobheun @vasco-santos @vmx do you have any bandwidth to look into this issue? It looks like a libp2p issue here but a ipld issue here: https://discuss.ipfs.io/t/using-jsipfs-pin-add/5044

@alanshaw
Copy link
Member

Not sure if this is relevant mafintosh/protocol-buffers#38

@vmx
Copy link
Member

vmx commented Mar 20, 2019

@jacobheun @vasco-santos It would be cool if you could have a look and ping me when it comes to IPLD? If you don't have the time, let me know an I'll try to see what I can do.

@jacobheun
Copy link
Contributor

The issue is that the privateKey is not supported/correct. @rmisio how did you generate the private key you're using?

This is likely due to libp2p/js-peer-id#82.

There's some discussion at libp2p/js-libp2p#229 (comment) around how to create and print out a workaround if you need to reuse your own private key

@rmisio
Copy link
Author

rmisio commented Mar 20, 2019

@jacobheun hmm... it's the same code I'm using from a project I worked on two month back. Then it worked without issue. Has something changed regarding the private key format?

Anyhow, this is how I'm generating the key:

export function identityKeyFromSeed(mnemonic, bits = 4096) {
  return new Promise((resolve, reject) => {
    const bip39seed = bip39.mnemonicToSeed(mnemonic, 'Secret Passphrase');
    const hmac = sha256.hmac.create('OpenBazaar seed');
    hmac.update(bip39seed);
    const seed = new Uint8Array(hmac.array());

    keys.generateKeyPairFromSeed('ed25519', seed, bits, (err, keypair) => {
      if (!err) {
        PeerId.createFromPubKey(keys.marshalPublicKey(keypair.public),
          (err, peerId) => {
            if (err) {
              reject(err);
              return;
            }

            // todo: strip the 'Key' suffix from pub and priv
            resolve({
              peerId: peerId.toBytes(),
              publicKey: keypair.public.bytes,
              privateKey: keypair._key,
            });
          });
      } else {
        reject(err);
      }
    });
  });
}
  // need base58 peerId, base64 privateKey
  getIpfsNodeInitOpts(peerId, privateKey) {
    if (typeof peerId !== 'string') {
      throw new Error('Please provide a peerId as a string.');
    }

    if (typeof privateKey !== 'string') {
      throw new Error('Please provide a privateKey as a string.');
    }    

    return {
      EXPERIMENTAL: {
        pubsub: true,
        dht: true,
      },
      relay: {
        "enabled": true,
      },
      repo: `./ipfs/${peerId}`,
      init: { privateKey },
    }
  }
    identityKeyFromSeed(seed)
      .then(identity => {
        const peerId = createFromBytes(identity.peerId).toB58String();
        const privateKey = fromByteArray(identity.privateKey);
        const ipfsInitOpts = this.getIpfsNodeInitOpts(peerId, privateKey)
        const node = new IPFS(ipfsInitOpts);
      });

@rmisio
Copy link
Author

rmisio commented Mar 20, 2019

ok, interesting, if I change the private key in the identityKeyFromSeed method to privateKey: keypair.bytes, it seems to work.

I think I switched to privateKey: keypair._key because that worked for some other context whereas privateKey: keypair.bytes did not, but I really don't 100% remember why I made the switch.

Anyhow, looks like it's working for now and not using the "private" property seems safer. I'll re-comment if I discover any issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants