Add full Chain 138 integration: 8 steps, chain spec, app-ethereum config, docs
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
30
step-02-device-app-lib/hw-app-eth-usage.ts
Normal file
30
step-02-device-app-lib/hw-app-eth-usage.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Step 2 — Device app lib (JS bindings)
|
||||
* For EVM/Chain 138 we use existing @ledgerhq/hw-app-eth. No new package needed.
|
||||
* Ensure chainId 138 is passed when building/signing transactions.
|
||||
*
|
||||
* Example usage in coin-module or live-common (signer/bridge):
|
||||
*/
|
||||
|
||||
import Eth from "@ledgerhq/hw-app-eth";
|
||||
|
||||
const CHAIN_ID_138 = 138;
|
||||
|
||||
// When getting address (path is BIP44 EVM: 44'/60'/0'/0/0)
|
||||
async function getAddress(
|
||||
transport: { send: (cla: number, ins: number, p1: number, p2: number, data?: Buffer) => Promise<Buffer> },
|
||||
path: string,
|
||||
display?: boolean
|
||||
) {
|
||||
const eth = new Eth(transport);
|
||||
const result = await eth.getAddress(path, display ?? false);
|
||||
return { address: result.address, publicKey: result.publicKey, path };
|
||||
}
|
||||
|
||||
// When signing a transaction, the serialized tx must include chainId 138 (EIP-155)
|
||||
// so the device shows "Defi Oracle Meta" and signs correctly.
|
||||
function buildTxWithChainId(tx: { chainId?: number; [k: string]: unknown }) {
|
||||
return { ...tx, chainId: tx.chainId ?? CHAIN_ID_138 };
|
||||
}
|
||||
|
||||
export { getAddress, buildTxWithChainId, CHAIN_ID_138 };
|
||||
Reference in New Issue
Block a user