-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6792 from LedgerHQ/feat/dsdk-276-keyring-eth
Feat/dsdk 276 create keyring-eth module
- Loading branch information
Showing
11 changed files
with
286 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import baseConfig from "../../jest.config"; | ||
|
||
export default { | ||
...baseConfig, | ||
rootDir: __dirname, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"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.10", | ||
"@types/node": "^20.8.10", | ||
"jest": "^29.7.0", | ||
"rimraf": "^4.4.1", | ||
"ts-jest": "^29.1.1", | ||
"ts-node": "^10.7.0", | ||
"typescript": "^5.4.5" | ||
}, | ||
"dependencies": { | ||
"@ledgerhq/context-module": "workspace:^", | ||
"@ledgerhq/hw-app-eth": "workspace:^", | ||
"@ledgerhq/hw-transport": "workspace:^", | ||
"@ledgerhq/types-live": "workspace:^", | ||
"ethers": "^5.7.2" | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
libs/ledgerjs/packages/keyring-eth/src/DefaultKeyringEth.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Transport from "@ledgerhq/hw-transport"; | ||
import { DefaultKeyringEth } from "./DefaultKeyringEth"; | ||
import { Transaction } from "ethers"; | ||
|
||
describe("DefaultEthKeyring", () => { | ||
describe("signTransaction function", () => { | ||
it("Test1", async () => { | ||
const keyring = new DefaultKeyringEth({ | ||
send: jest.fn(), | ||
decorateAppAPIMethods: jest.fn(), | ||
} as unknown as Transport); | ||
|
||
const result = await keyring.signTransaction("", {} as Transaction, {}); | ||
|
||
expect(result).toEqual({}); | ||
}); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
libs/ledgerjs/packages/keyring-eth/src/DefaultKeyringEth.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Transaction } from "ethers"; | ||
import Transport from "@ledgerhq/hw-transport"; | ||
import AppBinding from "@ledgerhq/hw-app-eth"; | ||
import { | ||
EcdsaSignature, | ||
KeyringEth, | ||
GetAddressOptions, | ||
SignMessageOptions, | ||
SignMessagePayload, | ||
SignTransactionOptions, | ||
GetAddressResult, | ||
} from "./KeyringEth"; | ||
|
||
export class DefaultKeyringEth implements KeyringEth { | ||
private _appBinding: AppBinding; | ||
|
||
constructor(transport: Transport) { | ||
this._appBinding = new AppBinding(transport); | ||
} | ||
|
||
public async signTransaction( | ||
_derivationPath: string, | ||
_transaction: Transaction, | ||
_options: SignTransactionOptions, | ||
) { | ||
// TODO: implement | ||
return Promise.resolve({} as EcdsaSignature); | ||
} | ||
|
||
public async signMessage( | ||
_derivationPath: string, | ||
_message: SignMessagePayload, | ||
_options: SignMessageOptions, | ||
): Promise<EcdsaSignature> { | ||
// TODO: implement | ||
return Promise.resolve({} as EcdsaSignature); | ||
} | ||
|
||
public async getAddress( | ||
_derivationPath: string, | ||
_options?: GetAddressOptions, | ||
): Promise<GetAddressResult> { | ||
// TODO: implement | ||
return Promise.resolve({} as GetAddressResult); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export abstract class Keyring { | ||
abstract getAddress(derivationPath: string, options: unknown): Promise<unknown>; | ||
abstract signTransaction( | ||
derivationPath: string, | ||
transaction: unknown, | ||
options: unknown, | ||
): Promise<unknown>; | ||
abstract signMessage( | ||
derivationPath: string, | ||
message: unknown, | ||
options: unknown, | ||
): Promise<unknown>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Transaction } from "ethers"; | ||
import { Keyring } from "./Keyring"; | ||
import { LoaderOptions } from "@ledgerhq/context-module/src/shared/model/LoaderOptions"; | ||
import { EIP712Message } from "@ledgerhq/types-live"; | ||
|
||
export type EcdsaSignature = { r: `0x${string}`; s: `0x${string}`; v: number }; | ||
|
||
export type EIP712Params = { domainSeparator: `0x${string}`; hashStruct: `0x${string}` }; | ||
|
||
export type SignTransactionOptions = LoaderOptions["options"]; | ||
|
||
export type SignMessagePayload = string | EIP712Message | EIP712Params; | ||
|
||
// TODO: reinforce the type of the options | ||
export type SignMessageOptions = { method: "personalSign" | "eip712" | "eip712Hashed" }; | ||
|
||
export type GetAddressResult = { | ||
publicKey: string; | ||
address: `0x${string}`; | ||
}; | ||
|
||
export type GetAddressOptions = { | ||
displayOnDevice?: boolean; | ||
chainId?: string; | ||
}; | ||
|
||
export interface KeyringEth extends Keyring { | ||
getAddress(derivationPath: string, options?: GetAddressOptions): Promise<GetAddressResult>; | ||
|
||
signTransaction( | ||
derivationPath: string, | ||
transaction: Transaction, | ||
options: SignTransactionOptions, | ||
): Promise<EcdsaSignature>; | ||
|
||
signMessage( | ||
derivationPath: string, | ||
message: SignMessagePayload, | ||
options: SignMessageOptions, | ||
): Promise<EcdsaSignature>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./DefaultKeyringEth"; | ||
export * from "./KeyringEth"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "lib" | ||
}, | ||
"include": ["src/**/*"] | ||
} |
Oops, something went wrong.