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

[ON-HOLD] feat: initial commit for kadena ledger lib #2458

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

barthuijgen
Copy link
Contributor

@barthuijgen barthuijgen commented Aug 8, 2024

Modify this title

Related Issue/Asana ticket: _

Short description: Add a library called @kadena/ledger that allows integration with the kadena ledger app via browser HID.

Currently ON-HOLD because the kadena app is being re-written.

Test scenarios

  • description of the (manually) executed test scenarios

Reminders (if applicable)

  • I ran pnpm install and pnpm test in the root of the monorepo
    (optionally with --filter=...package... to exclude non-affected
    projects)
  • I ran pnpm changeset in the root of the monorepo
  • Test coverage has not decreased
  • Docs have been updated to reflect changes in PR (don't forget
    docs.kadena.io)

Copy link

vercel bot commented Aug 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
alpha-docs ❌ Failed (Inspect) 💬 Add feedback Oct 3, 2024 11:33am
6 Skipped Deployments
Name Status Preview Comments Updated (UTC)
dev-wallet ⬜️ Skipped (Inspect) Oct 3, 2024 11:33am
explorer ⬜️ Skipped (Inspect) Oct 3, 2024 11:33am
kode-ui ⬜️ Skipped (Inspect) Oct 3, 2024 11:33am
marmalade-marketplace ⬜️ Skipped (Inspect) Oct 3, 2024 11:33am
proof-of-us ⬜️ Skipped (Inspect) Oct 3, 2024 11:33am
tools ⬜️ Skipped (Inspect) Oct 3, 2024 11:33am

Copy link

changeset-bot bot commented Aug 8, 2024

⚠️ No Changeset found

Latest commit: 4915137

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

<div>
<button
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
onClick={() => openApp().then(() => setOpenAppResult('success'))}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

      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={() =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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={() =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can these codes be identified? in some sort of map.

@barthuijgen barthuijgen changed the title feat: initial commit for kadena ledger lib [ON-HOLD] feat: initial commit for kadena ledger lib Sep 4, 2024
@vercel vercel bot temporarily deployed to Preview – dev-wallet October 3, 2024 11:32 Inactive
@vercel vercel bot temporarily deployed to Preview – proof-of-us October 3, 2024 11:32 Inactive
@vercel vercel bot temporarily deployed to Preview – kode-ui October 3, 2024 11:32 Inactive
@vercel vercel bot temporarily deployed to Preview – tools October 3, 2024 11:32 Inactive
@vercel vercel bot temporarily deployed to Preview – marmalade-marketplace October 3, 2024 11:32 Inactive
@vercel vercel bot temporarily deployed to Preview – explorer October 3, 2024 11:32 Inactive
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

Successfully merging this pull request may close these issues.

2 participants