Skip to content
This repository has been archived by the owner on Jun 27, 2022. It is now read-only.

Is ledgerjs hardcoded to support only Polkadot, but not other testnets like Westend? #586

Open
will-yjn opened this issue Mar 31, 2021 · 3 comments

Comments

@will-yjn
Copy link

I use the @ledgerhq/hw-app-polkadot library to sign payloads for transactions. Code below works on Polkadot:

  const { block } = await api.rpc.chain.getBlock();
  const blockNumber = block.header.number.unwrap().toNumber();
  const blockHash = (await api.rpc.chain.getBlockHash()).toHex();
  const genesisHash = (await api.rpc.chain.getBlockHash(0)).toHex();
  const metadataRpc = (await api.rpc.state.getMetadata()).toHex();
  const runtimeVersion = await api.rpc.state.getRuntimeVersion();
  const specVersion = runtimeVersion.specVersion.toNumber();
  const transactionVersion = runtimeVersion.transactionVersion.toNumber();
  const specName = runtimeVersion.specName.toString();
  const ledgerAddress = (await getLedgerAddress(ledgerInstance)).address;
  const { nonce, } = await api.query.system.account(ledgerAddress);
  const chainName = (await api.rpc.system.chain()).toString();

  log.cyan(`You are connected to chain: ${chainName}`);
  log.cyan(transactionVersion);
  log.cyan(specName);

  const registry = getRegistry({
    chainName,
    specName: specName as specNameType,
    specVersion,
    metadataRpc,
  });
  
  const unsigned = methods.balances.transfer(
    {
      value: totalAmount,
      dest,
    },
    {
      address,
      blockHash,
      blockNumber,
      eraPeriod: 64,
      genesisHash,
      metadataRpc,
      nonce: nonce.toNumber(),
      specVersion,
      tip: 0,
      transactionVersion,
    },
    {
      metadataRpc,
      registry,
    }
  );

  // https://github.com/LedgerHQ/ledger-live-common/blob/master/src/families/polkadot/js-signOperation.js#L177
  const extrinsicPayload = registry.createType(
    "ExtrinsicPayload",
    unsigned,
    {
      version: unsigned.version,
    }
  );
  const extrinsicPayloadU8a = extrinsicPayload.toU8a({ method: true });
  const signingPayloadU8a = extrinsicPayloadU8a.length > 256
		? registry.hash(extrinsicPayloadU8a)
		: extrinsicPayloadU8a;

  // code below throws error on testnet Westend
  const {signature} = await ledgerSign(ledgerInstance, signingPayloadU8a);

  const signedTx = construct.signedTx(unsigned, signature, { metadataRpc, registry });
  return signedTx;

However it doesn't work on the testnet Westend. The same code throws error "Txn version is not supported". If I hardcode the transactionVersion variable to be 6 which is the number on Polkadot, it throws Unexpected buffer end.

Is ledger-polkadot hardcoded to support only Polkadot but not testnet like Westend?

@ghost
Copy link

ghost commented Apr 2, 2021

Hi @will-yijinin, what Nano app are you using for this scenario? To my knowledge there is currently no Ledger Nano app for Westend, as indeed the Polkadot Nano app is compatible only with Polkadot.

Similarly there is a Kusama app, but I'm not sure @ledgerhq/hw-app-polkadot would support it out of the box, some adaptation could be required.

@will-yjn
Copy link
Author

will-yjn commented Apr 3, 2021

Hi @haammar-ledger I am using Ledger Polkadot app. Do I have to re-write the ledger polkadot app and install it on ledger to make it compatible with Westend?

@ghost
Copy link

ghost commented Apr 6, 2021

Yes indeed, you would first need to adapt the Polkadot Nano app to create a Westend app, then also adapt the @ledgerhq/hw-app-polkadot library to support Westend.

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

1 participant