Skip to content

Commit

Permalink
feat(keyring-eth): new module
Browse files Browse the repository at this point in the history
  • Loading branch information
aussedatlo committed May 3, 2024
1 parent c23a6a8 commit e78a60f
Show file tree
Hide file tree
Showing 6 changed files with 338 additions and 225 deletions.
6 changes: 6 additions & 0 deletions libs/ledgerjs/packages/keyring-eth/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import baseConfig from "../../jest.config";

export default {
...baseConfig,
rootDir: __dirname,
};
30 changes: 30 additions & 0 deletions libs/ledgerjs/packages/keyring-eth/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@ledgerhq/keyring-eth",
"version": "0.0.1",
"description": "Ledger keyring eth module",
"files": [
"./lib"
],
"scripts": {
"build": "rimraf lib && tsc",
"test": "jest"
},
"keywords": [],
"license": "Apache-2.0",
"devDependencies": {
"@tsconfig/recommended": "^1.0.6",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.7",
"jest": "^29.7.0",
"rimraf": "^5.0.5",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
},
"dependencies": {
"@ledgerhq/context-module": "workspace:^",
"@ledgerhq/hw-app-eth": "workspace:^",
"@ledgerhq/hw-transport": "workspace:^",
"ethers": "^5.7.2"
}
}
61 changes: 61 additions & 0 deletions libs/ledgerjs/packages/keyring-eth/src/EthKeyring.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Transaction } from "ethers";
import Transport from "@ledgerhq/hw-transport";
import AppBinding from "@ledgerhq/hw-app-eth";
import { ForwardDomainOptions } from "@ledgerhq/context-module/lib/models/LoaderOptions";
import { EIP712Message } from "../../types-live/lib";

type SignTransactionArgs = {
derivationPath: string;
transaction: Transaction;
options?: { forwardDomainOptions?: ForwardDomainOptions }; // TODO: TBD
};

type SignMessageArgs = {
derivationPath: string;
message: string | EIP712Message; // EIP-712/EIP-191
options: {
type: "EIP-191" | "EIP-712";
context: any; // TODO: TBD
};
};

type GetAddressArgs = {
derivationPath: string;
options: object; //TBD needVerify
};

export interface EthKeyring {
signTransaction(args: SignTransactionArgs): Promise<EcdsaSignature>;
signMessage(args: SignMessageArgs): Promise<EcdsaSignature>;
getAddress(args: GetAddressArgs): Promise<{ address: string; options: string }>;
}

export type EcdsaSignature = { r: `0x${string}`; s: `0x${string}`; v: number };

export class DefaultEthKeyring implements EthKeyring {
private _appBinding: AppBinding;

constructor(transport: Transport) {
this._appBinding = new AppBinding(transport);
}

public async signTransaction({
derivationPath: _derivationPath,
transaction: _transaction,
options: _options,
}: SignTransactionArgs) {
return Promise.resolve({ r: "0x", s: "0x", v: 0 } as EcdsaSignature);
}

public async signMessage({
derivationPath: _derivationPath,
message: _message,
options: _options,
}: SignMessageArgs) {
return Promise.resolve({ r: "0x", s: "0x", v: 0 } as EcdsaSignature);
}

public async getAddress({ derivationPath: _derivationPath, options: _options }: GetAddressArgs) {
return Promise.resolve({ address: "", options: "" });
}
}
Empty file.
7 changes: 7 additions & 0 deletions libs/ledgerjs/packages/keyring-eth/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "lib"
},
"include": ["src/**/*"]
}

0 comments on commit e78a60f

Please sign in to comment.