Skip to content

Commit

Permalink
BREAKING: Synchronise package with module-template to fix regression (#…
Browse files Browse the repository at this point in the history
…147)

* Synchronise package with module-template to fix regression

* Use eslint-plugin-import@~2.26.0
  • Loading branch information
Mrtenz authored Jul 14, 2023
1 parent 067224e commit 5bf9fc4
Show file tree
Hide file tree
Showing 20 changed files with 479 additions and 284 deletions.
1 change: 0 additions & 1 deletion .depcheckrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"@metamask/auto-changelog",
"@types/*",
"prettier-plugin-packagejson",
"simple-git-hooks",
"ts-node",
"typedoc"
]
Expand Down
4 changes: 2 additions & 2 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ nodeLinker: node-modules

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs
spec: 'https://raw.githubusercontent.com/LavaMoat/LavaMoat/main/packages/yarn-plugin-allow-scripts/bundles/@yarnpkg/plugin-allow-scripts.js'
spec: "https://raw.githubusercontent.com/LavaMoat/LavaMoat/main/packages/yarn-plugin-allow-scripts/bundles/@yarnpkg/plugin-allow-scripts.js"
- path: .yarn/plugins/@yarnpkg/plugin-constraints.cjs
spec: '@yarnpkg/plugin-constraints'
spec: "@yarnpkg/plugin-constraints"

yarnPath: .yarn/releases/yarn-3.2.3.cjs
5 changes: 5 additions & 0 deletions constraints.pro
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,17 @@ gen_enforced_field(WorkspaceCwd, 'license').

% The type definitions entrypoint the package must be `./dist/types/index.d.ts`.
gen_enforced_field(WorkspaceCwd, 'types', './dist/types/index.d.ts').
gen_enforced_field(WorkspaceCwd, 'exports["."].types', './dist/types/index.d.ts').

% The entrypoint for the package must be `./dist/cjs/index.js`.
gen_enforced_field(WorkspaceCwd, 'main', './dist/cjs/index.js').
gen_enforced_field(WorkspaceCwd, 'exports["."].require', './dist/cjs/index.js').

% The module entrypoint for the package must be `./dist/esm/index.js`.
gen_enforced_field(WorkspaceCwd, 'module', './dist/esm/index.js').
gen_enforced_field(WorkspaceCwd, 'exports["."].import', './dist/esm/index.js').

gen_enforced_field(WorkspaceCwd, 'exports["./package.json"]', './package.json').

% The list of files included in the package must only include files generated
% during the build step.
Expand Down
32 changes: 21 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
},
"license": "MIT",
"author": "kumavis",
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js",
"types": "./dist/types/index.d.ts"
},
"./package.json": "./package.json"
},
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
Expand All @@ -25,7 +33,8 @@
"build:cjs": "swc src --out-dir dist/cjs --config-file .swcrc.build.json --config module.type=commonjs",
"build:clean": "rimraf dist && yarn build",
"build:docs": "typedoc",
"build:esm": "swc src --out-dir dist/esm --config-file .swcrc.build.json --config module.type=es6",
"build:esm": "swc src --out-dir dist/esm --config-file .swcrc.build.json --config module.type=es6 && yarn build:esm:package",
"build:esm:package": "echo >dist/esm/package.json \"{\\\"type\\\":\\\"module\\\"}\"",
"build:source": "yarn build:esm && yarn build:cjs",
"build:types": "tsc --project tsconfig.build.json",
"generate-vectors": "ts-node scripts/generate-vectors.ts > ./test/vectors/derivation.json",
Expand All @@ -52,24 +61,25 @@
"@lavamoat/allow-scripts": "^2.3.1",
"@lavamoat/preinstall-always-fail": "^1.0.0",
"@metamask/auto-changelog": "^3.1.0",
"@metamask/eslint-config": "^11.0.1",
"@metamask/eslint-config-jest": "^11.0.0",
"@metamask/eslint-config-nodejs": "^11.0.1",
"@metamask/eslint-config-typescript": "^11.0.0",
"@metamask/eslint-config": "^12.0.0",
"@metamask/eslint-config-jest": "^12.0.0",
"@metamask/eslint-config-nodejs": "^12.0.0",
"@metamask/eslint-config-typescript": "^12.0.0",
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.66",
"@types/jest": "^28.1.6",
"@types/node": "^16.18.38",
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/parser": "^5.43.0",
"depcheck": "^1.4.3",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.1.5",
"eslint-plugin-jsdoc": "^39.6.2",
"eslint-plugin-node": "^11.1.0",
"eslint": "^8.44.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "~2.26.0",
"eslint-plugin-jest": "^27.2.2",
"eslint-plugin-jsdoc": "^39.9.1",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.1.1",
"jest": "^28.1.3",
"jest-it-up": "^2.0.2",
"prettier": "^2.7.1",
Expand Down
5 changes: 2 additions & 3 deletions scripts/generate-vectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import { bytesToHex } from '@metamask/utils';
// eslint-disable-next-line import/no-nodejs-modules
import { randomInt, randomBytes } from 'crypto';

import type { BIP32Node, SLIP10Node } from '../src';
import {
BIP32Node,
BIP_32_HARDENED_OFFSET,
ed25519,
MAX_BIP_32_INDEX,
secp256k1,
SLIP10Node,
} from '../src';
import { Curve } from '../src/curves';
import type { Curve } from '../src/curves';
import { createBip39KeyFromSeed } from '../src/derivers/bip39';

/**
Expand Down
11 changes: 6 additions & 5 deletions src/BIP44CoinTypeNode.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { assert } from '@metamask/utils';

import { BIP44Node, BIP44NodeInterface, JsonBIP44Node } from './BIP44Node';
import {
import type { BIP44NodeInterface, JsonBIP44Node } from './BIP44Node';
import { BIP44Node } from './BIP44Node';
import type {
BIP39Node,
BIP44Depth,
BIP44PurposeNodeToken,
BIP_32_HARDENED_OFFSET,
CoinTypeHDPathString,
HardenedBIP32Node,
} from './constants';
import { SupportedCurve } from './curves';
import { BIP_32_HARDENED_OFFSET } from './constants';
import type { SupportedCurve } from './curves';
import { deriveChildNode } from './SLIP10Node';
import type { CoinTypeToAddressIndices } from './utils';
import {
CoinTypeToAddressIndices,
getBIP32NodeToken,
getBIP44ChangePathString,
getBIP44CoinTypePathString,
Expand Down
12 changes: 7 additions & 5 deletions src/BIP44Node.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { assert } from '@metamask/utils';

import {
import type {
BIP44Depth,
PartialHDPathTuple,
RootedSLIP10PathTuple,
SLIP10Path,
} from './constants';
import {
BIP44PurposeNodeToken,
BIP_32_PATH_REGEX,
BIP_39_PATH_REGEX,
MAX_BIP_44_DEPTH,
MIN_BIP_44_DEPTH,
PartialHDPathTuple,
RootedSLIP10PathTuple,
SLIP10Path,
} from './constants';
import { SupportedCurve } from './curves';
import type { SupportedCurve } from './curves';
import {
decodeExtendedKey,
encodeExtendedKey,
Expand Down
14 changes: 6 additions & 8 deletions src/SLIP10Node.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { assert, bytesToHex } from '@metamask/utils';

import { BIP44CoinTypeNode } from './BIP44CoinTypeNode';
import { BIP44Node } from './BIP44Node';
import {
BYTES_KEY_LENGTH,
RootedSLIP10PathTuple,
SLIP10PathTuple,
} from './constants';
import { getCurveByName, SupportedCurve } from './curves';
import type { BIP44CoinTypeNode } from './BIP44CoinTypeNode';
import type { BIP44Node } from './BIP44Node';
import type { RootedSLIP10PathTuple, SLIP10PathTuple } from './constants';
import { BYTES_KEY_LENGTH } from './constants';
import type { SupportedCurve } from './curves';
import { getCurveByName } from './curves';
import { deriveKeyFromPath } from './derivation';
import { publicKeyToEthAddress } from './derivers/bip32';
import {
Expand Down
4 changes: 2 additions & 2 deletions src/derivation.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { bytesToHex } from '@metamask/utils';

import fixtures from '../test/fixtures';
import { HDPathTuple } from './constants';
import type { HDPathTuple } from './constants';
import { secp256k1 } from './curves';
import { deriveKeyFromPath, validatePathSegment } from './derivation';
import { derivers } from './derivers';
import { privateKeyToEthAddress } from './derivers/bip32';
import { SLIP10Node } from './SLIP10Node';
import type { SLIP10Node } from './SLIP10Node';
import { getUnhardenedBIP32NodeToken, mnemonicPhraseToBytes } from './utils';

const {
Expand Down
8 changes: 5 additions & 3 deletions src/derivation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import { assert } from '@metamask/utils';

import { BIP44CoinTypeNode } from './BIP44CoinTypeNode';
import { BIP44Node } from './BIP44Node';
import type { SLIP10Path } from './constants';
import {
BIP_32_PATH_REGEX,
BIP_39_PATH_REGEX,
MIN_BIP_44_DEPTH,
SLIP10Path,
SLIP_10_PATH_REGEX,
} from './constants';
import { getCurveByName, SupportedCurve } from './curves';
import { Deriver, derivers } from './derivers';
import type { SupportedCurve } from './curves';
import { getCurveByName } from './curves';
import type { Deriver } from './derivers';
import { derivers } from './derivers';
import { SLIP10Node } from './SLIP10Node';

/**
Expand Down
6 changes: 3 additions & 3 deletions src/derivers/bip32.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { assert } from '@metamask/utils';
import { keccak_256 as keccak256 } from '@noble/hashes/sha3';

import { DeriveChildKeyArgs } from '.';
import type { DeriveChildKeyArgs } from '.';
import { BYTES_KEY_LENGTH } from '../constants';
import { secp256k1 } from '../curves';
import { SLIP10Node } from '../SLIP10Node';
import type { SLIP10Node } from '../SLIP10Node';
import { isValidBytesKey, validateBIP32Index } from '../utils';
import type { DeriveNodeArgs } from './shared';
import {
DeriveNodeArgs,
deriveChildKey as sharedDeriveChildKey,
deriveSecretExtension,
generateEntropy,
Expand Down
7 changes: 4 additions & 3 deletions src/derivers/bip39.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { assert } from '@metamask/utils';
import { hmac } from '@noble/hashes/hmac';
import { sha512 } from '@noble/hashes/sha512';

import { DeriveChildKeyArgs } from '.';
import { BIP39StringNode, BYTES_KEY_LENGTH } from '../constants';
import { Curve } from '../curves';
import type { DeriveChildKeyArgs } from '.';
import type { BIP39StringNode } from '../constants';
import { BYTES_KEY_LENGTH } from '../constants';
import type { Curve } from '../curves';
import { SLIP10Node } from '../SLIP10Node';
import { getFingerprint } from '../utils';

Expand Down
4 changes: 2 additions & 2 deletions src/derivers/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Curve } from '../curves';
import { SLIP10Node } from '../SLIP10Node';
import type { Curve } from '../curves';
import type { SLIP10Node } from '../SLIP10Node';
import * as bip32 from './bip32';
import * as bip39 from './bip39';
import * as slip10 from './slip10';
Expand Down
5 changes: 3 additions & 2 deletions src/derivers/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {
import { hmac } from '@noble/hashes/hmac';
import { sha512 } from '@noble/hashes/sha512';

import { DeriveChildKeyArgs, DerivedKeys } from '.';
import type { DeriveChildKeyArgs, DerivedKeys } from '.';
import { BIP_32_HARDENED_OFFSET, UNPREFIXED_PATH_REGEX } from '../constants';
import { Curve, mod } from '../curves';
import type { Curve } from '../curves';
import { mod } from '../curves';
import { SLIP10Node } from '../SLIP10Node';
import { isValidBytesKey, numberToUint32 } from '../utils';

Expand Down
6 changes: 3 additions & 3 deletions src/derivers/slip10.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { concatBytes } from '@metamask/utils';

import { DeriveChildKeyArgs } from '.';
import type { DeriveChildKeyArgs } from '.';
import { BIP_32_HARDENED_OFFSET } from '../constants';
import { SLIP10Node } from '../SLIP10Node';
import type { SLIP10Node } from '../SLIP10Node';
import { numberToUint32 } from '../utils';
import {
DeriveNodeArgs,
generateEntropy,
deriveChildKey as sharedDeriveChildKey,
} from './shared';
import type { DeriveNodeArgs } from './shared';

/**
* Derive a SLIP-10 child key with a given path from a parent key.
Expand Down
2 changes: 1 addition & 1 deletion src/extended-keys.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { hexToBytes } from '@metamask/utils';

import type { ExtendedKey } from './extended-keys';
import {
decodeExtendedKey,
encodeExtendedKey,
ExtendedKey,
PRIVATE_KEY_VERSION,
PUBLIC_KEY_VERSION,
} from './extended-keys';
Expand Down
13 changes: 8 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@ import { ripemd160 } from '@noble/hashes/ripemd160';
import { sha256 } from '@noble/hashes/sha256';
import { base58check as scureBase58check } from '@scure/base';

import {
import type {
BIP32Node,
BIP44PurposeNodeToken,
ChangeHDPathString,
CoinTypeHDPathString,
CoinTypeToAddressTuple,
HardenedBIP32Node,
UnhardenedBIP32Node,
UnprefixedNode,
} from './constants';
import {
BIP44PurposeNodeToken,
MAX_BIP_32_INDEX,
MAX_UNHARDENED_BIP_32_INDEX,
UnhardenedBIP32Node,
UNPREFIXED_BIP_32_PATH_REGEX,
UnprefixedNode,
} from './constants';
import { curves, SupportedCurve } from './curves';
import type { SupportedCurve } from './curves';
import { curves } from './curves';

/**
* Gets a string representation of a BIP-44 path of depth 2, i.e.:
Expand Down
8 changes: 2 additions & 6 deletions test/reference-implementations.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
BIP44Node,
SLIP10Node,
BIP44PurposeNodeToken,
HDPathTuple,
} from '../src';
import type { SLIP10Node, HDPathTuple } from '../src';
import { BIP44Node, BIP44PurposeNodeToken } from '../src';
import { ed25519, secp256k1 } from '../src/curves';
import { deriveKeyFromPath } from '../src/derivation';
import { createBip39KeyFromSeed } from '../src/derivers/bip39';
Expand Down
6 changes: 4 additions & 2 deletions test/vectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import { hexToBytes } from '@metamask/utils';

import { secp256k1, SLIP10PathTuple } from '../src';
import { Curve, ed25519 } from '../src/curves';
import type { SLIP10PathTuple } from '../src';
import { secp256k1 } from '../src';
import type { Curve } from '../src/curves';
import { ed25519 } from '../src/curves';
import { createBip39KeyFromSeed } from '../src/derivers/bip39';
import derivationVectors from './vectors/derivation.json';

Expand Down
Loading

0 comments on commit 5bf9fc4

Please sign in to comment.