diff --git a/.changeset/green-tips-accept.md b/.changeset/green-tips-accept.md new file mode 100644 index 000000000..b512e1aeb --- /dev/null +++ b/.changeset/green-tips-accept.md @@ -0,0 +1,5 @@ +--- +"@ckb-lumos/toolkit": patch +--- + +remove peer dependencies in toolkit diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index 5953ccc82..f831283e1 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -26,16 +26,14 @@ }, "author": "Xuejie Xiao", "license": "MIT", - "peerDependencies": { - "cross-fetch": "^3.1.4", - "jsbi": "^4.1.0" - }, "publishConfig": { "access": "public" }, + "dependencies": { + "@ckb-lumos/bi": "0.21.0-next.0" + }, "devDependencies": { "@babel/plugin-proposal-export-namespace-from": "^7.18.9", - "@babel/plugin-transform-modules-commonjs": "^7.21.5", - "jsbi": "^4.1.0" + "@babel/plugin-transform-modules-commonjs": "^7.21.5" } } diff --git a/packages/toolkit/src/normalizers.js b/packages/toolkit/src/normalizers.js index baf6ffeca..a26923f3d 100644 --- a/packages/toolkit/src/normalizers.js +++ b/packages/toolkit/src/normalizers.js @@ -10,7 +10,7 @@ // Note this is only used when you need to deal with CKB structures in molecule // format. If you are using RPCs or GraphQL to interact with CKB, chances are you // will not need this package. -import JSBI from "jsbi"; +import { BI } from "@ckb-lumos/bi"; import { Reader } from "./reader"; /** * @deprecated please follow the {@link https://lumos-website.vercel.app/migrations/migrate-to-v0.19 migration-guide} @@ -18,7 +18,7 @@ import { Reader } from "./reader"; function normalizeHexNumber(length) { return function (debugPath, value) { if (!(value instanceof ArrayBuffer)) { - let intValue = JSBI.BigInt(value).toString(16); + let intValue = BI.from(value).toString(16); if (intValue.length % 2 !== 0) { intValue = "0" + intValue; } diff --git a/packages/toolkit/tests/normailizers.js b/packages/toolkit/tests/normailizers.js new file mode 100644 index 000000000..7ff3475dd --- /dev/null +++ b/packages/toolkit/tests/normailizers.js @@ -0,0 +1,32 @@ +const test = require("ava"); +const { normalizers } = require("../lib"); + +test("correct outPoint should pass validation", (t) => { + const normalizedOutpoint = normalizers.NormalizeOutPoint({ + txHash: `0x${"00".repeat(32)}`, + index: "0x1", + }); + const expectedNormalizedIndex = new ArrayBuffer(4); + const view = new Int32Array(expectedNormalizedIndex); + view[0] = 1; + + t.deepEqual(normalizedOutpoint, { + index: expectedNormalizedIndex, + txHash: new ArrayBuffer(32), + }); +}); + +test("error outPoint should not pass validation", (t) => { + t.throws(() => { + normalizers.NormalizeOutPoint({ + txHash: `0x${"00".repeat(32)}`, + index: "0x", + }); + }); + t.throws(() => { + normalizers.NormalizeOutPoint({ + txHash: `0x${"00".repeat(32)}`, + index: "not a number", + }); + }); +}); diff --git a/packages/toolkit/types/index.d.ts b/packages/toolkit/types/index.d.ts index fbafb8bef..a359b56f5 100644 --- a/packages/toolkit/types/index.d.ts +++ b/packages/toolkit/types/index.d.ts @@ -1,5 +1,3 @@ -import JSBI from "jsbi"; - export * as validators from "./validators"; /** @@ -17,15 +15,6 @@ export class Reader { serializeJson(): string; } -/** - * @deprecated please follow the {@link https://lumos-website.vercel.app/migrations/migrate-to-v0.19 migration-guide} - */ -export function HexStringToBigInt(hexString: string): JSBI; -/** - * @deprecated please follow the {@link https://lumos-website.vercel.app/migrations/migrate-to-v0.19 migration-guide} - */ -export function BigIntToHexString(i: JSBI): string; - /** * @deprecated please follow the {@link https://lumos-website.vercel.app/migrations/migrate-to-v0.19 migration-guide} */ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fac299978..803812822 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -717,9 +717,9 @@ importers: packages/toolkit: dependencies: - cross-fetch: - specifier: ^3.1.4 - version: 3.1.5 + '@ckb-lumos/bi': + specifier: 0.21.0-next.0 + version: link:../bi devDependencies: '@babel/plugin-proposal-export-namespace-from': specifier: ^7.18.9 @@ -727,9 +727,6 @@ importers: '@babel/plugin-transform-modules-commonjs': specifier: ^7.21.5 version: 7.21.5(@babel/core@7.21.8) - jsbi: - specifier: ^4.1.0 - version: 4.1.0 packages/transaction-manager: dependencies: