[ON-HOLD] feat: initial commit for kadena ledger lib - #2458
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
6 Skipped Deployments
|
|
| <div> | ||
| <button | ||
| className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" | ||
| onClick={() => openApp().then(() => setOpenAppResult('success'))} |
There was a problem hiding this comment.
onClick={async () => {
await openApp();
setOpenAppResult('success');
}}
| <div> | ||
| <button | ||
| className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" | ||
| onClick={() => |
There was a problem hiding this comment.
onClick={async () => {
const result = await getPublicKey(0);
setGetPublicKeyResult(result);
}}
| <div> | ||
| <button | ||
| className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" | ||
| onClick={() => getVersion().then((x) => setGetVersionResult(x))} |
There was a problem hiding this comment.
onClick={async () => {
const result = await getVersion();
setGetVersionResult(result);
}}
| <div> | ||
| <button | ||
| className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" | ||
| onClick={() => |
There was a problem hiding this comment.
onClick={async () => {
const result = await signTransaction(0, 'transfer', {
recipient: '2017fee3fb15cfe840e5ed34bf101cc7d5579ffdd20dea09e32fd77c1757f946',
recipientChainId: '0',
networkId: 'testnet04',
amount: 0.1,
namespace_: '',
module_: '',
gasPrice: '1.0e-6',
gasLimit: '2300',
creationTime: '1723017869',
chainId: '0',
nonce: '',
ttl: '600',
type: 'transfer',
});
setSignTransactionResult(result);
}}
| 0x00, | ||
| Buffer.from('Kadena', 'ascii'), | ||
| ); | ||
| await new Promise((resolve) => setTimeout(resolve, 1000)); |
There was a problem hiding this comment.
I still don't know why this is here and it probably should not bere here, since is does not make sense.
| @@ -0,0 +1,9 @@ | |||
| import { StrictMode } from 'react'; | |||
There was a problem hiding this comment.
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import App from './app.tsx';
const root = createRoot(document.getElementById('root')!);
root.render(
<StrictMode>
<App />
</StrictMode>,
);
| @@ -0,0 +1,33 @@ | |||
| import { KadenaLedger } from './ledger'; | |||
There was a problem hiding this comment.
add return types:
import { KadenaLedger } from './ledger';
import { TransactionParams } from './transaction';
let ledger: KadenaLedger | null = null;
async function getLedger(): Promise<KadenaLedger> {
if (!ledger) ledger = await KadenaLedger.findDevice();
return ledger;
}
export async function openApp(): Promise<void> {
const ledger = await getLedger();
return await ledger.openApp();
}
export async function getPublicKey(index: number): Promise<string> {
const ledger = await getLedger();
return await ledger.getPublicKey(index);
}
export async function signTransaction(
index: number,
type: 'transfer' | 'cross-chain-transfer',
params: TransactionParams,
): Promise<string> {
const ledger = await getLedger();
return await ledger.signTransaction(index, type, params);
}
export async function getVersion(): Promise<string> {
const ledger = await getLedger();
return await ledger.getVersion();
}
| [StatusCodes.OK, 0x6e01], // 0x6e01 = already open | ||
| ); | ||
| // Opening the app makes the device reconnect, wait a moment for this | ||
| await new Promise((resolve) => setTimeout(resolve, 500)); |
There was a problem hiding this comment.
that's should be done more smarter, the reconnecting' isn't. there a event available we can listen to, this doesn't seem very error prone
| appName: string; | ||
| }> { | ||
| const response = await this.transport.send( | ||
| 0x00, |
There was a problem hiding this comment.
can these codes be identified? in some sort of map.
e48c9d3 to
4915137
Compare
|
This PR is stale because it is open for 60 days with no activity |
Modify this title
Related Issue/Asana ticket: _
Short description: Add a library called
@kadena/ledgerthat allows integration with the kadena ledger app via browser HID.Currently ON-HOLD because the kadena app is being re-written.
Test scenarios
Reminders (if applicable)
pnpm installandpnpm testin the root of the monorepo(optionally with
--filter=...package...to exclude non-affectedprojects)
pnpm changesetin the root of the monorepodocs.kadena.io)