Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use proper ESM #109

Merged
merged 7 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const fs = require('node:fs')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't use import here? is that a workspace limitation?

Copy link
Contributor Author

@sparten11740 sparten11740 Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have to make the entire workspace a module in that case or change the extension of the file to .mjs. But I am not sure if eslint 8 supports esm configs (eslint 9 does)


const shared = {
'import/no-cycle': ['error', { ignoreExternal: true }],
'unicorn/no-array-callback-reference': 'off',
Expand All @@ -14,7 +16,13 @@ const shared = {
],
}

const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'))
const isModule = pkg.type === 'module'

const sourceExts = ['js', 'json', 'ts', 'tsx', 'android.js', 'ios.js']
const esmConfigs = isModule
? ['plugin:@exodus/require-extensions/recommended', 'plugin:@exodus/hydra/esm']
: []

module.exports = {
extends: [
Expand All @@ -23,7 +31,8 @@ module.exports = {
'plugin:@exodus/basic-utils/recommended',
'plugin:@exodus/restricted-imports/recommended',
'plugin:@exodus/hydra/recommended',
'plugin:@exodus/eslint-plugin-package/recommended',
'plugin:@exodus/package/recommended',
...esmConfigs,
],
rules: shared,
globals: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
parserOptions: {
tsconfigRootDir: '../../',
babelOptions: {
configFile: path.join(path.dirname(__filename), 'babel.config.js'),
configFile: path.join(path.dirname(__filename), 'babel.config.cjs'),
},
},
overrides: [
Expand Down
2 changes: 1 addition & 1 deletion features/keychain/__tests__/index.integration-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import createIOC from '@exodus/argo'
import keychain from '../index'
import keychain from '../index.js'

// 2. Create ioc container
describe('keychain feature', () => {
Expand Down
6 changes: 3 additions & 3 deletions features/keychain/api/__tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import KeyIdentifier from '@exodus/key-identifier'
import { mnemonicToSeed } from 'bip39'
import apiDefinition from '..'
import moduleDefinition from '../../module'
import { getSeedId } from '../../module/crypto/seed-id'
import apiDefinition from '../index.js'
import moduleDefinition from '../../module/index.js'
import { getSeedId } from '../../module/crypto/seed-id.js'

const mnemonic = 'cousin access oak tragic entire dynamic marine expand govern enjoy honey tissue'
const otherMnemonic =
Expand Down
2 changes: 1 addition & 1 deletion features/keychain/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import keychainApiDefinition from './api'
import keychainApiDefinition from './api/index.js'

declare const keychain: () => {
id: 'keychain'
Expand Down
4 changes: 2 additions & 2 deletions features/keychain/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import moduleDefinition from './module/keychain'
import apiDefinition from './api'
import moduleDefinition from './module/keychain.js'
import apiDefinition from './api/index.js'

const keychain = ({ cachePublicKeys }) => {
// TODO: support caching
Expand Down
8 changes: 6 additions & 2 deletions features/keychain/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import baseConfig from '../../jest.config.js'

/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
...require('../../jest.config'),
const config = {
...baseConfig,
testMatch: ['**/__tests__/**.test.js'],
}

export default config
4 changes: 2 additions & 2 deletions features/keychain/module/__tests__/binauth.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { mnemonicToSeed } from 'bip39'

import { EXODUS_KEY_IDS } from '@exodus/key-ids'
import createKeychain from './create-keychain'
import { getSeedId } from '../crypto/seed-id'
import createKeychain from './create-keychain.js'
import { getSeedId } from '../crypto/seed-id.js'

const seed = mnemonicToSeed(
'menu memory fury language physical wonder dog valid smart edge decrease worth'
Expand Down
4 changes: 2 additions & 2 deletions features/keychain/module/__tests__/compatibility.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { mnemonicToSeed } from 'bip39'
import { createKeyIdentifierForExodus } from '@exodus/key-ids'
import KeyIdentifier from '@exodus/key-identifier'
import createKeychain from './create-keychain'
import { getSeedId } from '../crypto/seed-id'
import createKeychain from './create-keychain.js'
import { getSeedId } from '../crypto/seed-id.js'

const seed = mnemonicToSeed(
'menu memory fury language physical wonder dog valid smart edge decrease worth'
Expand Down
2 changes: 1 addition & 1 deletion features/keychain/module/__tests__/create-keychain.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import keychainDefinition from '..'
import keychainDefinition from '../index.js'

const createKeychain = ({ seed, ...rest }) => {
const instance = keychainDefinition.factory(rest)
Expand Down
4 changes: 2 additions & 2 deletions features/keychain/module/__tests__/ecdsa.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { mnemonicToSeed } from 'bip39'

import createKeychain from './create-keychain'
import { getSeedId } from '../crypto/seed-id'
import createKeychain from './create-keychain.js'
import { getSeedId } from '../crypto/seed-id.js'
import KeyIdentifier from '@exodus/key-identifier'

const seed = mnemonicToSeed(
Expand Down
4 changes: 2 additions & 2 deletions features/keychain/module/__tests__/eddsa.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { mnemonicToSeed } from 'bip39'
import { createKeyIdentifierForExodus } from '@exodus/key-ids'
import KeyIdentifier from '@exodus/key-identifier'
import createKeychain from './create-keychain'
import { getSeedId } from '../crypto/seed-id'
import createKeychain from './create-keychain.js'
import { getSeedId } from '../crypto/seed-id.js'

const seed = mnemonicToSeed(
'menu memory fury language physical wonder dog valid smart edge decrease worth'
Expand Down
2 changes: 1 addition & 1 deletion features/keychain/module/__tests__/ethsign.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { create } from '../crypto/secp256k1'
import { create } from '../crypto/secp256k1.js'
import KeyIdentifier from '@exodus/key-identifier'

const fixtures = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { connectAssetsList } from '@exodus/assets'
import solanaAssets from '@exodus/solana-meta'
import { mnemonicToSeed } from 'bip39'
import assert from 'minimalistic-assert'
import keychainDefinition, { KeyIdentifier } from '..'
import { getSeedId } from '../crypto/seed-id'
import keychainDefinition, { KeyIdentifier } from '../index.js'
import { getSeedId } from '../crypto/seed-id.js'

const seed = mnemonicToSeed(
'menu memory fury language physical wonder dog valid smart edge decrease worth'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { EXODUS_KEY_IDS } from '@exodus/key-ids'
import { createUnsignedTx } from '@exodus/solana-lib'
import { mnemonicToSeed } from 'bip39'

import { assets } from './fixtures/assets'
import simpleTx from './fixtures/simple-tx'
import { assets } from './fixtures/assets.js'
import simpleTx from './fixtures/simple-tx.js'

import KeyIdentifier from '@exodus/key-identifier'
import keychainDefinition, { Keychain } from '../keychain'
import { getSeedId } from '../crypto/seed-id'
import keychainDefinition, { Keychain } from '../keychain.js'
import { getSeedId } from '../crypto/seed-id.js'

const { factory: createMultiSeedKeychain } = keychainDefinition

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { mnemonicToSeed } from 'bip39'
import { createKeyIdentifierForExodus } from '@exodus/key-ids'
import createKeychain from './create-keychain'
import { getSeedId } from '../crypto/seed-id'
import createKeychain from './create-keychain.js'
import { getSeedId } from '../crypto/seed-id.js'
import KeyIdentifier from '@exodus/key-identifier'

const seed = mnemonicToSeed(
Expand Down
2 changes: 1 addition & 1 deletion features/keychain/module/__tests__/schnorr.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { utils } from '@noble/secp256k1'
import ecc from '@exodus/bitcoinerlab-secp256k1'

import { create } from '../crypto/secp256k1'
import { create } from '../crypto/secp256k1.js'
import KeyIdentifier from '@exodus/key-identifier'

const fixtures = [
Expand Down
4 changes: 2 additions & 2 deletions features/keychain/module/__tests__/sodium.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { mnemonicToSeed } from 'bip39'

import KeyIdentifier from '@exodus/key-identifier'
import createKeychain from './create-keychain'
import { getSeedId } from '../crypto/seed-id'
import createKeychain from './create-keychain.js'
import { getSeedId } from '../crypto/seed-id.js'

const seed = mnemonicToSeed(
'menu memory fury language physical wonder dog valid smart edge decrease worth'
Expand Down
2 changes: 1 addition & 1 deletion features/keychain/module/crypto/secp256k1.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import elliptic from '@exodus/elliptic'
import { mapValues, pick } from '@exodus/basic-utils'
import ecc from '@exodus/bitcoinerlab-secp256k1'

import { tweakPrivateKey } from './tweak'
import { tweakPrivateKey } from './tweak.js'

const isValidEcOptions = (ecOptions) =>
!ecOptions || Object.keys(ecOptions).every((key) => ['canonical'].includes(key))
Expand Down
4 changes: 2 additions & 2 deletions features/keychain/module/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { createKeyIdentifierForExodus, EXODUS_KEY_IDS, KeyIdentifier } from './key-identifier'
export { default, Keychain } from './keychain'
export { createKeyIdentifierForExodus, EXODUS_KEY_IDS, KeyIdentifier } from './key-identifier.js'
export { default, Keychain } from './keychain.js'
2 changes: 1 addition & 1 deletion features/keychain/module/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default as KeyIdentifier } from '@exodus/key-identifier'
export { default, Keychain } from './keychain'
export { default, Keychain } from './keychain.js'
10 changes: 5 additions & 5 deletions features/keychain/module/keychain.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import SLIP10 from '@exodus/slip10'
import { mapValues } from '@exodus/basic-utils'
import assert from 'minimalistic-assert'

import * as ed25519 from './crypto/ed25519'
import * as secp256k1 from './crypto/secp256k1'
import * as sodium from './crypto/sodium'
import * as ed25519 from './crypto/ed25519.js'
import * as secp256k1 from './crypto/secp256k1.js'
import * as sodium from './crypto/sodium.js'
import {
throwIfInvalidKeyIdentifier,
throwIfInvalidMasters,
throwIfInvalidLegacyPrivToPub,
} from './validate'
import { getSeedId } from './crypto/seed-id'
} from './validate.js'
import { getSeedId } from './crypto/seed-id.js'

const MAP_KDF = Object.freeze({
BIP32: bip32FromMasterSeed,
Expand Down
3 changes: 2 additions & 1 deletion features/keychain/module/memoized-keychain.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BJSON from 'buffer-json'
import stableStringify from 'json-stable-stringify'

import { Keychain } from './keychain'
import { Keychain } from './keychain.js'

const keyIdToCacheKey = stableStringify

Expand Down Expand Up @@ -63,4 +63,5 @@ const memoizedKeychainDefinition = {
dependencies: ['storage', 'legacyPrivToPub'],
}

// eslint-disable-next-line @exodus/hydra/no-unused-ioc-nodes
export default memoizedKeychainDefinition
2 changes: 1 addition & 1 deletion features/keychain/module/validate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from 'minimalistic-assert'
import KeyIdentifier from '@exodus/key-identifier'

import { ExpectedKeyIdentifier, NotInitializedError } from './errors'
import { ExpectedKeyIdentifier, NotInitializedError } from './errors.js'

export const throwIfInvalidKeyIdentifier = (potentialKeyIdentifier) => {
if (!KeyIdentifier.validate(potentialKeyIdentifier) || !Object.isFrozen(potentialKeyIdentifier)) {
Expand Down
5 changes: 3 additions & 2 deletions features/keychain/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@exodus/keychain",
"version": "6.5.0",
"type": "module",
"description": "A module designed to work more securely with private key material",
"author": "Exodus Movement, Inc.",
"homepage": "https://github.com/ExodusMovement/exodus-oss/tree/master/features/keychain",
Expand All @@ -9,8 +10,8 @@
"lib": "src",
"test": "__tests__"
},
"main": "index.js",
"files": [
"index.js",
"index.d.ts",
"module",
"api",
Expand All @@ -34,7 +35,7 @@
"@exodus/bitcoinerlab-secp256k1": "^1.0.5-exodus.1",
"@exodus/elliptic": "^6.5.4-precomputed",
"@exodus/key-identifier": "^1.0.1",
"@exodus/key-utils": "^3.0.0",
"@exodus/key-utils": "^3.5.1",
"@exodus/slip10": "^1.0.0",
"@exodus/sodium-crypto": "^3.1.0",
"buffer-json": "^2.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assets } from '../../../features/keychain/module/__tests__/fixtures/assets'
import { assets } from '../../../features/keychain/module/__tests__/fixtures/assets.js'
import { createKeyIdentifierForExodus } from '@exodus/key-ids'
import KeyIdentifier from '../src/key-identifier'
import KeyIdentifier from '../src/key-identifier.js'

describe('KeyIdentifier', () => {
it('should fail on incorrect construction', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createKeyIdentifierForExodus } from '@exodus/key-ids'
import KeyIdentifier from '../src/key-identifier'
import KeyIdentifier from '../src/key-identifier.js'

describe('KeyIdentifier', () => {
it('should fail on incorrect construction', () => {
Expand Down
8 changes: 6 additions & 2 deletions libraries/key-identifier/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import baseConfig from '../../jest.config.js'

/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
...require('../../jest.config.js'),
const config = {
...baseConfig,
testMatch: ['**/__tests__/**.test.js'],
}

export default config
5 changes: 3 additions & 2 deletions libraries/key-identifier/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@exodus/key-identifier",
"version": "1.1.1",
"type": "module",
"description": "Provides a KeyIdentifier class that helps to define how a key is derived",
"author": "Exodus Movement, Inc.",
"repository": {
Expand All @@ -25,11 +26,11 @@
"todo:reenable:test:integration": "jest --testMatch='**/*.integration-test.js'"
},
"dependencies": {
"@exodus/key-utils": "^3.3.0",
"@exodus/key-utils": "^3.5.1",
"minimalistic-assert": "^1.0.1"
},
"devDependencies": {
"@exodus/key-ids": "^1.2.0",
"@exodus/key-ids": "^1.2.2",
"@exodus/keychain": "workspace:^"
}
}
2 changes: 1 addition & 1 deletion libraries/key-identifier/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from './key-identifier'
export { default } from './key-identifier.js'
2 changes: 1 addition & 1 deletion libraries/key-identifier/src/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from './key-identifier'
export { default } from './key-identifier.js'
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@
"@exodus/eslint-config": "^5.22.0",
"@exodus/eslint-plugin-ban-flow": "latest",
"@exodus/eslint-plugin-basic-utils": "latest",
"@exodus/eslint-plugin-hydra": "^1.0.0",
"@exodus/eslint-plugin-hydra": "^1.16.0",
"@exodus/eslint-plugin-package": "^1.10.1",
"@exodus/eslint-plugin-require-extensions": "^0.1.3-exodus.2",
"@exodus/eslint-plugin-restricted-imports": "^1.1.1",
"@exodus/prettier": "^1.0.0",
"@nrwl/devkit": "^15.8.5",
Expand Down
Loading
Loading