From bd3f51844c798c5673ee076fb96eef0315184094 Mon Sep 17 00:00:00 2001 From: Jaco Date: Sat, 4 Dec 2021 08:11:16 +0100 Subject: [PATCH] Add BigInt shim (#1280) --- packages/util-crypto/src/cryptoInit.ts | 2 ++ packages/x-bigint/package.json | 5 ++++- packages/x-bigint/src/index.ts | 2 +- packages/x-bigint/src/shim.ts | 10 ++++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 packages/x-bigint/src/shim.ts diff --git a/packages/util-crypto/src/cryptoInit.ts b/packages/util-crypto/src/cryptoInit.ts index f8fb514ba..8e44189eb 100644 --- a/packages/util-crypto/src/cryptoInit.ts +++ b/packages/util-crypto/src/cryptoInit.ts @@ -1,6 +1,8 @@ // Copyright 2017-2021 @polkadot/util-crypto authors & contributors // SPDX-License-Identifier: Apache-2.0 +import '@polkadot/x-bigint/shim'; + import { u8aConcat } from '@polkadot/util'; import { utils as utilsNobleSecp256k1 } from '@polkadot/x-noble-secp256k1'; diff --git a/packages/x-bigint/package.json b/packages/x-bigint/package.json index 7744f0f4c..e38fde5cc 100644 --- a/packages/x-bigint/package.json +++ b/packages/x-bigint/package.json @@ -15,7 +15,10 @@ "type": "git", "url": "https://github.com/polkadot-js/common.git" }, - "sideEffects": false, + "sideEffects": [ + "./shim.js", + "./shim.cjs" + ], "type": "module", "version": "8.0.6-15", "dependencies": { diff --git a/packages/x-bigint/src/index.ts b/packages/x-bigint/src/index.ts index 01531b06b..77ec1999c 100644 --- a/packages/x-bigint/src/index.ts +++ b/packages/x-bigint/src/index.ts @@ -1,4 +1,4 @@ -// Copyright 2017-2021 @polkadot/x-ws authors & contributors +// Copyright 2017-2021 @polkadot/x-bigint authors & contributors // SPDX-License-Identifier: Apache-2.0 import { xglobal } from '@polkadot/x-global'; diff --git a/packages/x-bigint/src/shim.ts b/packages/x-bigint/src/shim.ts new file mode 100644 index 000000000..883179935 --- /dev/null +++ b/packages/x-bigint/src/shim.ts @@ -0,0 +1,10 @@ +// Copyright 2017-2021 @polkadot/x-bigint authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import { xglobal } from '@polkadot/x-global'; + +import { BigInt } from '.'; + +if (typeof xglobal.BigInt !== 'function') { + (xglobal as Record).BigInt = BigInt; +}