I tried to sign custom calls to my canisters with ledger-icp and got this error
Error: A ledger error happened during signature:
Code: 27012
Message: "Data is invalid : Unexpected data type"
As far as I understand, it only works with predefined transactions hardcoded inside the ledger app. This means trying to sign your own requests will result in error and IC developers can’t use it at all for their own canisters.
I actually faced the same issue 27012 while rewriting the ledger for nns-dapp in svelte yesterday.
My colleague @lmuntaner ultimately found out that the function that was transforming the request was not yet moved to my rewrite.
Everything is now solved and my understanding of the issue is that the request has to be formatted differently if it uses the standard identity or the ledger identity - i.e. when it goes through the ledger
I re-implemented this week in Svelte the nns-dapp feature for the accounts (“attach new hardware wallet”, “transfer icp from a hardware wallet” and “display principal on hardware wallet”). That’s why I faced above error.
In nns-dapp we use a custom implementation of the ledger identity. It’s on my low-prio todo to clear why and if we stick to it. Anyway it might also explains why it did not work out with your sample repo and on the contrary it worked out for me this week. Spontaneous guessing though.
This error comes from the device.
First repo error:
ledger.js:68 Uncaught (in promise) Error: A ledger error happened during signature:
Code: 27012
Message: "Data is invalid : Unexpected data type"
at LedgerIdentity.sign (ledger.js:68:1)
at async LedgerIdentity.transformRequest (ledger.js:79:1)
at async HttpAgent.call (index.js:172:1)
at async caller (actor.js:174:43)
at async HTMLFormElement.<anonymous> (index.js:17:1)
Second repo error
nns_identity.ts:168 Uncaught (in promise) Error: A ledger error happened during signature:
Code: 27012
Message: "Data is invalid : Unexpected data type"
at nns_identity.ts:168:1
at async LedgerIdentity._executeWithApp (nns_identity.ts:205:1)
at async LedgerIdentity.sign (nns_identity.ts:162:1)
at async LedgerIdentity.transformRequest (nns_identity.ts:186:1)
at async HttpAgent.call (index.js:172:1)
at async caller (actor.js:174:43)
at async HTMLFormElement.<anonymous> (index.js:17:1)
(anonymous) @ nns_identity.ts:168
Having a look at the sample repo you shared in your issue on zondax ledger-icp. If I get it right you get the error when you do query the actor const count = await signtest.add(3); right?
If so I think we have the same limitation - i.e. when we do query with the ledger identity we have to go through queries that use protobuf at the moment (also still on my todo list). For example, in nns-js, when we query the list of neurons through the dedicated function, we follow different path if identiy or ledger identity.
I know it does not solve your question directly but I guess it helps a bit.
That confirms that the hardware Ledger app only works with protobuf functions, which can only be exposed by canisters in Rust, but not Motoko. I wonder if Zondax team are aware that they need to add Candid support?
sorry for the late response, we (zondax) are relatively new in this forum.
Do you still encounter this issue? There was a recent upgrade of the ICP ledger app that includes support for several candid functions.
If you (anyone on the icp community) encounter any issue in the future with the Ledger app please feel free to create a ticket in our repository GitHub - Zondax/ledger-icp
I’d like to use the opportunity to communicate that in the next week another upgrade of the ICP ledger app will be available, and this will support even more candid functions.
I wonder if Ledger → Metamask Snap → Custom canisters will get it done
or the new standards https://github.com/dfinity/wg-identity-authentication
instead of Metamask Snap will allow us to ‘convert’ arbitrary calls to something well-defined Ledger hardware can understand.