Skip to content

Commit

Permalink
🚀 (signer-utils) [DSDK-556]: Create shared signer utils package (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
aussedatlo authored Oct 24, 2024
2 parents 766e20b + eae6b2e commit da560dc
Show file tree
Hide file tree
Showing 23 changed files with 155 additions and 84 deletions.
1 change: 1 addition & 0 deletions packages/signer/keyring-btc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@ledgerhq/eslint-config-dsdk": "workspace:*",
"@ledgerhq/jest-config-dsdk": "workspace:*",
"@ledgerhq/prettier-config-dsdk": "workspace:*",
"@ledgerhq/signer-utils": "workspace:*",
"@ledgerhq/tsconfig-dsdk": "workspace:*",
"ts-node": "^10.9.2"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import {
GlobalCommandErrorHandler,
InvalidStatusWordError,
} from "@ledgerhq/device-management-kit";

import { DerivationPathUtils } from "@internal/shared/utils/DerivationPathUtils";
import { DerivationPathUtils } from "@ledgerhq/signer-utils";

const STATUS_CODE_LENGTH = 2;

Expand Down

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions packages/signer/keyring-eth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@ledgerhq/eslint-config-dsdk": "workspace:*",
"@ledgerhq/jest-config-dsdk": "workspace:*",
"@ledgerhq/prettier-config-dsdk": "workspace:*",
"@ledgerhq/signer-utils": "workspace:*",
"@ledgerhq/tsconfig-dsdk": "workspace:*",
"@types/semver": "^7.5.8",
"rxjs": "^7.8.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import {
InvalidStatusWordError,
isHexaString,
} from "@ledgerhq/device-management-kit";
import { DerivationPathUtils } from "@ledgerhq/signer-utils";

import {
GetAddressCommandArgs,
GetAddressCommandResponse,
} from "@api/app-binder/GetAddressCommandTypes";
import { DerivationPathUtils } from "@internal/shared/utils/DerivationPathUtils";

const CHAIN_CODE_LENGTH = 32;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import {
GlobalCommandErrorHandler,
InvalidStatusWordError,
} from "@ledgerhq/device-management-kit";
import { DerivationPathUtils } from "@ledgerhq/signer-utils";
import { Maybe } from "purify-ts";

import { type Signature } from "@api/model/Signature";
import { DerivationPathUtils } from "@internal/shared/utils/DerivationPathUtils";

const R_LENGTH = 32;
const S_LENGTH = 32;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {
InvalidStatusWordError,
isSuccessCommandResult,
} from "@ledgerhq/device-management-kit";
import { DerivationPathUtils } from "@ledgerhq/signer-utils";

import { Signature } from "@api/model/Signature";
import {
SignPersonalMessageCommand,
SignPersonalMessageCommandResponse,
} from "@internal/app-binder/command/SignPersonalMessageCommand";
import { DerivationPathUtils } from "@internal/shared/utils/DerivationPathUtils";

import { SendCommandInChunksTask } from "./SendCommandInChunksTask";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {
InvalidStatusWordError,
isSuccessCommandResult,
} from "@ledgerhq/device-management-kit";
import { DerivationPathUtils } from "@ledgerhq/signer-utils";

import { Signature } from "@api/index";
import {
SignTransactionCommand,
SignTransactionCommandResponse,
} from "@internal/app-binder/command/SignTransactionCommand";
import { DerivationPathUtils } from "@internal/shared/utils/DerivationPathUtils";

import { SendCommandInChunksTask } from "./SendCommandInChunksTask";

Expand Down
2 changes: 2 additions & 0 deletions packages/signer/signer-utils/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib/*
coverage/*
3 changes: 3 additions & 0 deletions packages/signer/signer-utils/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require("@ledgerhq/prettier-config-dsdk"),
};
1 change: 1 addition & 0 deletions packages/signer/signer-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @ledgerhq/signer-utils
1 change: 1 addition & 0 deletions packages/signer/signer-utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Ledger Signer Utils Package
13 changes: 13 additions & 0 deletions packages/signer/signer-utils/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import config from "@ledgerhq/eslint-config-dsdk";

export default [
...config,
{
ignores: ["eslint.config.mjs"],
languageOptions: {
parserOptions: {
project: "./tsconfig.json",
},
},
},
];
26 changes: 26 additions & 0 deletions packages/signer/signer-utils/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint no-restricted-syntax: 0 */
import { JestConfigWithTsJest, pathsToModuleNameMapper } from "ts-jest";

import { compilerOptions } from "./tsconfig.json";

const paths = pathsToModuleNameMapper(compilerOptions.paths, {
prefix: "<rootDir>/",
});

const config: JestConfigWithTsJest = {
preset: "@ledgerhq/jest-config-dsdk",
setupFiles: ["<rootDir>/jest.setup.ts"],
testPathIgnorePatterns: ["<rootDir>/lib/esm", "<rootDir>/lib/cjs"],
collectCoverageFrom: [
"src/**/*.ts",
"!src/**/*.stub.ts",
"!src/index.ts",
"!src/api/index.ts",
"!src/**/__test-utils__/*",
],
moduleNameMapper: {
...paths,
},
};

export default config;
Empty file.
49 changes: 49 additions & 0 deletions packages/signer/signer-utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "@ledgerhq/signer-utils",
"version": "1.0.0",
"license": "Apache-2.0",
"private": true,
"exports": {
".": {
"types": "./lib/types/index.d.ts",
"import": "./lib/esm/index.js",
"require": "./lib/cjs/index.js"
},
"./*": {
"types": "./lib/types/*",
"import": "./lib/esm/*",
"require": "./lib/cjs/*"
}
},
"files": [
"./lib"
],
"scripts": {
"prebuild": "rimraf lib",
"build": "pnpm lmdk-build --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
"dev": "concurrently \"pnpm watch:builds\" \"pnpm watch:types\"",
"watch:builds": "pnpm lmdk-watch --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\"",
"lint": "eslint",
"lint:fix": "pnpm lint --fix",
"postpack": "find . -name '*.tgz' -exec cp {} ../../../dist/ \\; ",
"prettier": "prettier . --check",
"prettier:fix": "prettier . --write",
"typecheck": "tsc --noEmit",
"test": "jest",
"test:watch": "pnpm test -- --watch",
"test:coverage": "pnpm test -- --coverage"
},
"devDependencies": {
"@ledgerhq/device-management-kit": "workspace:*",
"@ledgerhq/esbuild-tools": "workspace:*",
"@ledgerhq/eslint-config-dsdk": "workspace:*",
"@ledgerhq/jest-config-dsdk": "workspace:*",
"@ledgerhq/prettier-config-dsdk": "workspace:*",
"@ledgerhq/tsconfig-dsdk": "workspace:*",
"ts-node": "^10.9.2"
},
"peerDependencies": {
"@ledgerhq/device-management-kit": "workspace:*"
}
}
1 change: 1 addition & 0 deletions packages/signer/signer-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./utils/DerivationPathUtils";
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// TODO: Move to shared package and use in both keyring-btc and keyring-eth

export class DerivationPathUtils {
static PADDING = 0x80000000;

Expand Down
18 changes: 18 additions & 0 deletions packages/signer/signer-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "@ledgerhq/tsconfig-dsdk/tsconfig.sdk",
"compilerOptions": {
"baseUrl": ".",
"outDir": "./lib/types",
"module": "esnext",
"target": "esnext",
"moduleResolution": "bundler",
"emitDeclarationOnly": true,
"paths": {
"@api/*": ["./src/api/*"],
"@internal/*": ["./src/internal/*"],
"@root/*": ["./*"]
},
"resolveJsonModule": true
},
"include": ["src", "jest.*.ts"]
}
4 changes: 4 additions & 0 deletions packages/signer/signer-utils/tsconfig.prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"include": ["src"]
}
30 changes: 30 additions & 0 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 da560dc

Please sign in to comment.