Skip to content

Commit

Permalink
Merge pull request #149 from KeystoneHQ/bump-eth-ur-version
Browse files Browse the repository at this point in the history
Bump eth ur version
  • Loading branch information
LiYanLance authored May 23, 2024
2 parents 7795431 + 6bc2ce6 commit 6d5b26c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
26 changes: 26 additions & 0 deletions packages/ur-registry-eth/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// @ts-nocheck

import { generateAddressFromXpub, findHDPathFromAddress } from "../src/utlis";

describe("utils", () => {

// abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about
// m/44'/60'/0'
const xpub = "xpub6DCoCpSuQZB2jawqnGMEPS63ePKWkwWPH4TU45Q7LPXWuNd8TMtVxRrgjtEshuqpK3mdhaWHPFsBngh5GFZaM6si3yZdUsT8ddYM3PwnATt";
const firstAddress = "0x9858EfFD232B4033E47d90003D41EC34EcaEda94";
const secondAddress = "0x6Fac4D18c912343BF86fa7049364Dd4E424Ab9C0";

describe("generateAddressFromXpub", () => {
it("should derive address from xpub", () => {
expect(generateAddressFromXpub(xpub, "m/0/0")).toBe(firstAddress);
expect(generateAddressFromXpub(xpub, "m/0/1")).toBe(secondAddress);
})
})

describe("findHDPathFromAddress", () => {
it("should find HD path from given address", () => {
expect(findHDPathFromAddress(firstAddress, xpub, 10, "m/44'/60'/0'")).toBe("m/44'/60'/0'/0/0")
expect(findHDPathFromAddress(secondAddress, xpub, 10, "m/44'/60'/0'")).toBe("m/44'/60'/0'/0/1")
})
})
});
4 changes: 2 additions & 2 deletions packages/ur-registry-eth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@keystonehq/bc-ur-registry-eth",
"version": "0.19.1",
"version": "0.20.0",
"description": "bc-ur-registry extension for ETH",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -25,7 +25,7 @@
"author": "soralit <soralitria@gmail.com>",
"license": "ISC",
"dependencies": {
"@ethereumjs/util": "^8.0.0",
"@ethereumjs/util": "^9.0.3",
"@keystonehq/bc-ur-registry": "^0.6.0",
"hdkey": "^2.0.1",
"uuid": "^8.3.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/ur-registry-eth/src/utlis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const generateAddressFromXpub = (xpub: string, derivePath: string) => {
const node = HDKey.fromExtendedKey(xpub);
const publicKey = node.derive(derivePath);
const address =
"0x" + publicToAddress(publicKey.publicKey, true).toString("hex");
"0x" + Buffer.from(publicToAddress(publicKey.publicKey, true)).toString("hex");
return toChecksumAddress(address);
};

Expand Down
18 changes: 16 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6d5b26c

Please sign in to comment.