From 6b2e34c973290da221aaabdc2bf4c6654ef9f99c Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Tue, 30 Jan 2024 15:21:04 +0200 Subject: [PATCH] Remove bn.js and resolutions from celo/utils (#105) * Remove bn.js and resolutions. * docs --------- Co-authored-by: Aaron --- .changeset/tall-buckets-sit.md | 19 ++++++++++++ packages/docs/sdk/docs/utils/README.md | 1 - packages/docs/sdk/docs/utils/modules/bn.md | 30 ------------------- .../utils/modules/sign_typed_data_utils.md | 6 ++-- packages/sdk/utils/package.json | 9 ------ packages/sdk/utils/src/bn.ts | 11 ------- .../sdk/utils/src/sign-typed-data-utils.ts | 1 - yarn.lock | 2 -- 8 files changed, 22 insertions(+), 57 deletions(-) create mode 100644 .changeset/tall-buckets-sit.md delete mode 100644 packages/docs/sdk/docs/utils/modules/bn.md delete mode 100644 packages/sdk/utils/src/bn.ts diff --git a/.changeset/tall-buckets-sit.md b/.changeset/tall-buckets-sit.md new file mode 100644 index 000000000..bb661c689 --- /dev/null +++ b/.changeset/tall-buckets-sit.md @@ -0,0 +1,19 @@ +--- +'@celo/utils': major +--- + +Remove export compareBN + +This would have been used to sort BN.js numbers. Generic comparator functions are not really the scope of this library. Removing it allows the bn.js dependency to be removed too. If you were using this function it can be re-implemented as + +```typescript +export function compareBN(a: BN, b: BN) { + if (a.eq(b)) { + return 0 + } else if (a.lt(b)) { + return -1 + } else { + return 1 + } +} +``` diff --git a/packages/docs/sdk/docs/utils/README.md b/packages/docs/sdk/docs/utils/README.md index 1bcc2bb74..3d32832e2 100644 --- a/packages/docs/sdk/docs/utils/README.md +++ b/packages/docs/sdk/docs/utils/README.md @@ -8,7 +8,6 @@ - [address](modules/address.md) - [async](modules/async.md) -- [bn](modules/bn.md) - [celoHistory](modules/celoHistory.md) - [collections](modules/collections.md) - [contacts](modules/contacts.md) diff --git a/packages/docs/sdk/docs/utils/modules/bn.md b/packages/docs/sdk/docs/utils/modules/bn.md deleted file mode 100644 index b5277bbfa..000000000 --- a/packages/docs/sdk/docs/utils/modules/bn.md +++ /dev/null @@ -1,30 +0,0 @@ -[@celo/utils](../README.md) / bn - -# Module: bn - -## Table of contents - -### Functions - -- [compareBN](bn.md#comparebn) - -## Functions - -### compareBN - -▸ **compareBN**(`a`, `b`): ``0`` \| ``1`` \| ``-1`` - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `a` | `BN` | -| `b` | `BN` | - -#### Returns - -``0`` \| ``1`` \| ``-1`` - -#### Defined in - -[packages/sdk/utils/src/bn.ts:3](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/bn.ts#L3) diff --git a/packages/docs/sdk/docs/utils/modules/sign_typed_data_utils.md b/packages/docs/sdk/docs/utils/modules/sign_typed_data_utils.md index 55893c198..355f15173 100644 --- a/packages/docs/sdk/docs/utils/modules/sign_typed_data_utils.md +++ b/packages/docs/sdk/docs/utils/modules/sign_typed_data_utils.md @@ -246,7 +246,7 @@ Constructs the struct encoding of the data as the primary type. #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:249](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L249) +[packages/sdk/utils/src/sign-typed-data-utils.ts:248](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L248) ___ @@ -316,7 +316,7 @@ ___ #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:258](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L258) +[packages/sdk/utils/src/sign-typed-data-utils.ts:257](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L257) ___ @@ -368,4 +368,4 @@ Note that EIP-712 does not specify zero values, and so this is non-standard. #### Defined in -[packages/sdk/utils/src/sign-typed-data-utils.ts:274](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L274) +[packages/sdk/utils/src/sign-typed-data-utils.ts:273](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/sign-typed-data-utils.ts#L273) diff --git a/packages/sdk/utils/package.json b/packages/sdk/utils/package.json index 8c3b98b39..fdf37edf6 100644 --- a/packages/sdk/utils/package.json +++ b/packages/sdk/utils/package.json @@ -24,11 +24,9 @@ "dependencies": { "@celo/base": "^6.0.0", "@ethereumjs/util": "8.0.5", - "@types/bn.js": "^5.1.0", "@types/elliptic": "^6.4.9", "@types/node": "^18.7.16", "bignumber.js": "^9.0.0", - "bn.js": "4.11.9", "elliptic": "^6.5.4", "ethereum-cryptography": "1.2.0", "fp-ts": "2.1.1", @@ -39,12 +37,5 @@ }, "devDependencies": { "@celo/typescript": "0.0.1" - }, - "resolutions": { - "@types/bn.js": "4.11.6", - "bn.js": "4.11.9", - "elliptic/bn.js": "bn.js@4.11.9", - "web3-utils/bn.js": "bn.js@4.11.9", - "@ethereumjs/bn.js": "bn.js@4.11.9" } } diff --git a/packages/sdk/utils/src/bn.ts b/packages/sdk/utils/src/bn.ts deleted file mode 100644 index da5e64790..000000000 --- a/packages/sdk/utils/src/bn.ts +++ /dev/null @@ -1,11 +0,0 @@ -import BN from 'bn.js' - -export function compareBN(a: BN, b: BN) { - if (a.eq(b)) { - return 0 - } else if (a.lt(b)) { - return -1 - } else { - return 1 - } -} diff --git a/packages/sdk/utils/src/sign-typed-data-utils.ts b/packages/sdk/utils/src/sign-typed-data-utils.ts index 00e8b6d84..5ac97de71 100644 --- a/packages/sdk/utils/src/sign-typed-data-utils.ts +++ b/packages/sdk/utils/src/sign-typed-data-utils.ts @@ -199,7 +199,6 @@ export function typeHash(primaryType: string, types: EIP712Types): Buffer { function encodeValue(valueType: string, value: EIP712ObjectValue, types: EIP712Types): Buffer { // Encode the atomic types as their corresponding soldity ABI type. if (EIP712_ATOMIC_TYPES.includes(valueType)) { - // @ts-ignore TypeScript does not believe encodeParameter exists. const hexEncoded = coder.encodeParameter(valueType, normalizeValue(valueType, value)) return Buffer.from(trimLeading0x(hexEncoded), 'hex') } diff --git a/yarn.lock b/yarn.lock index 18d9b5e14..0aad6f0f4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1932,11 +1932,9 @@ __metadata: "@celo/base": "npm:^6.0.0" "@celo/typescript": "npm:0.0.1" "@ethereumjs/util": "npm:8.0.5" - "@types/bn.js": "npm:^5.1.0" "@types/elliptic": "npm:^6.4.9" "@types/node": "npm:^18.7.16" bignumber.js: "npm:^9.0.0" - bn.js: "npm:4.11.9" elliptic: "npm:^6.5.4" ethereum-cryptography: "npm:1.2.0" fp-ts: "npm:2.1.1"