@pezkuwi/util 14.0.10 → 14.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/array/chunk.d.ts +15 -0
- package/array/chunk.js +27 -0
- package/array/filter.d.ts +16 -0
- package/array/filter.js +19 -0
- package/array/flatten.d.ts +15 -0
- package/array/flatten.js +39 -0
- package/array/index.d.ts +10 -0
- package/array/index.js +10 -0
- package/array/range.d.ts +16 -0
- package/array/range.js +25 -0
- package/array/shuffle.d.ts +5 -0
- package/array/shuffle.js +19 -0
- package/array/unzip.d.ts +5 -0
- package/array/unzip.js +13 -0
- package/array/zip.d.ts +5 -0
- package/array/zip.js +12 -0
- package/assert.d.ts +29 -0
- package/assert.js +39 -0
- package/bi/consts.d.ts +90 -0
- package/bi/consts.js +91 -0
- package/bi/helpers.d.ts +2 -0
- package/bi/helpers.js +16 -0
- package/bi/index.d.ts +9 -0
- package/bi/index.js +9 -0
- package/bi/min.d.ts +10 -0
- package/bi/min.js +11 -0
- package/bi/sqrt.d.ts +7 -0
- package/bi/sqrt.js +29 -0
- package/bi/toBigInt.d.ts +7 -0
- package/bi/toBigInt.js +25 -0
- package/bi/toHex.d.ts +7 -0
- package/bi/toHex.js +9 -0
- package/bi/toU8a.d.ts +7 -0
- package/bi/toU8a.js +49 -0
- package/bn/bn.d.ts +2 -0
- package/bn/bn.js +2 -0
- package/bn/consts.d.ts +91 -0
- package/bn/consts.js +91 -0
- package/bn/fromHex.d.ts +1 -0
- package/bn/fromHex.js +1 -0
- package/bn/index.d.ts +11 -0
- package/bn/index.js +11 -0
- package/bn/min.d.ts +29 -0
- package/bn/min.js +29 -0
- package/bn/sqrt.d.ts +16 -0
- package/bn/sqrt.js +38 -0
- package/bn/toBn.d.ts +19 -0
- package/bn/toBn.js +37 -0
- package/bn/toHex.d.ts +18 -0
- package/bn/toHex.js +20 -0
- package/bn/toU8a.d.ts +17 -0
- package/bn/toU8a.js +33 -0
- package/buffer/index.d.ts +4 -0
- package/buffer/index.js +4 -0
- package/buffer/toU8a.d.ts +15 -0
- package/buffer/toU8a.js +17 -0
- package/bundle-pezkuwi-util.js +4830 -0
- package/bundle.d.ts +28 -0
- package/bundle.js +28 -0
- package/cjs/array/chunk.d.ts +15 -0
- package/cjs/array/chunk.js +30 -0
- package/cjs/array/filter.d.ts +16 -0
- package/cjs/array/filter.js +22 -0
- package/cjs/array/flatten.d.ts +15 -0
- package/cjs/array/flatten.js +42 -0
- package/cjs/array/index.d.ts +10 -0
- package/cjs/array/index.js +20 -0
- package/cjs/array/range.d.ts +16 -0
- package/cjs/array/range.js +28 -0
- package/cjs/array/shuffle.d.ts +5 -0
- package/cjs/array/shuffle.js +22 -0
- package/cjs/array/unzip.d.ts +5 -0
- package/cjs/array/unzip.js +16 -0
- package/cjs/array/zip.d.ts +5 -0
- package/cjs/array/zip.js +15 -0
- package/cjs/assert.d.ts +29 -0
- package/cjs/assert.js +44 -0
- package/cjs/bi/consts.d.ts +90 -0
- package/cjs/bi/consts.js +94 -0
- package/cjs/bi/helpers.d.ts +2 -0
- package/cjs/bi/helpers.js +19 -0
- package/cjs/bi/index.d.ts +9 -0
- package/cjs/bi/index.js +19 -0
- package/cjs/bi/min.d.ts +10 -0
- package/cjs/bi/min.js +14 -0
- package/cjs/bi/sqrt.d.ts +7 -0
- package/cjs/bi/sqrt.js +32 -0
- package/cjs/bi/toBigInt.d.ts +7 -0
- package/cjs/bi/toBigInt.js +28 -0
- package/cjs/bi/toHex.d.ts +7 -0
- package/cjs/bi/toHex.js +12 -0
- package/cjs/bi/toU8a.d.ts +7 -0
- package/cjs/bi/toU8a.js +52 -0
- package/cjs/bn/bn.d.ts +2 -0
- package/cjs/bn/bn.js +6 -0
- package/cjs/bn/consts.d.ts +91 -0
- package/cjs/bn/consts.js +94 -0
- package/cjs/bn/fromHex.d.ts +1 -0
- package/cjs/bn/fromHex.js +5 -0
- package/cjs/bn/index.d.ts +11 -0
- package/cjs/bn/index.js +23 -0
- package/cjs/bn/min.d.ts +29 -0
- package/cjs/bn/min.js +32 -0
- package/cjs/bn/sqrt.d.ts +16 -0
- package/cjs/bn/sqrt.js +41 -0
- package/cjs/bn/toBn.d.ts +19 -0
- package/cjs/bn/toBn.js +40 -0
- package/cjs/bn/toHex.d.ts +18 -0
- package/cjs/bn/toHex.js +23 -0
- package/cjs/bn/toU8a.d.ts +17 -0
- package/cjs/bn/toU8a.js +36 -0
- package/cjs/buffer/index.d.ts +4 -0
- package/cjs/buffer/index.js +8 -0
- package/cjs/buffer/toU8a.d.ts +15 -0
- package/cjs/buffer/toU8a.js +20 -0
- package/cjs/bundle.d.ts +28 -0
- package/cjs/bundle.js +33 -0
- package/cjs/compact/addLength.d.ts +13 -0
- package/cjs/compact/addLength.js +23 -0
- package/cjs/compact/defaults.d.ts +3 -0
- package/cjs/compact/defaults.js +5 -0
- package/cjs/compact/fromU8a.d.ts +22 -0
- package/cjs/compact/fromU8a.js +92 -0
- package/cjs/compact/index.d.ts +24 -0
- package/cjs/compact/index.js +32 -0
- package/cjs/compact/stripLength.d.ts +13 -0
- package/cjs/compact/stripLength.js +24 -0
- package/cjs/compact/toU8a.d.ts +14 -0
- package/cjs/compact/toU8a.js +48 -0
- package/cjs/compact/types.d.ts +1 -0
- package/cjs/compact/types.js +2 -0
- package/cjs/detectPackage.d.ts +17 -0
- package/cjs/detectPackage.js +100 -0
- package/cjs/extractTime.d.ts +14 -0
- package/cjs/extractTime.js +56 -0
- package/cjs/float/index.d.ts +1 -0
- package/cjs/float/index.js +5 -0
- package/cjs/float/toU8a.d.ts +11 -0
- package/cjs/float/toU8a.js +22 -0
- package/cjs/format/formatBalance.d.ts +54 -0
- package/cjs/format/formatBalance.js +88 -0
- package/cjs/format/formatDate.d.ts +5 -0
- package/cjs/format/formatDate.js +20 -0
- package/cjs/format/formatDecimal.d.ts +5 -0
- package/cjs/format/formatDecimal.js +19 -0
- package/cjs/format/formatElapsed.d.ts +7 -0
- package/cjs/format/formatElapsed.js +30 -0
- package/cjs/format/formatNumber.d.ts +14 -0
- package/cjs/format/formatNumber.js +14 -0
- package/cjs/format/getSeparator.d.ts +9 -0
- package/cjs/format/getSeparator.js +14 -0
- package/cjs/format/index.d.ts +6 -0
- package/cjs/format/index.js +16 -0
- package/cjs/format/si.d.ts +9 -0
- package/cjs/format/si.js +45 -0
- package/cjs/has.d.ts +14 -0
- package/cjs/has.js +19 -0
- package/cjs/hex/addPrefix.d.ts +16 -0
- package/cjs/hex/addPrefix.js +23 -0
- package/cjs/hex/fixLength.d.ts +18 -0
- package/cjs/hex/fixLength.js +30 -0
- package/cjs/hex/hasPrefix.d.ts +16 -0
- package/cjs/hex/hasPrefix.js +21 -0
- package/cjs/hex/index.d.ts +12 -0
- package/cjs/hex/index.js +24 -0
- package/cjs/hex/stripPrefix.d.ts +15 -0
- package/cjs/hex/stripPrefix.js +30 -0
- package/cjs/hex/toBigInt.d.ts +6 -0
- package/cjs/hex/toBigInt.js +15 -0
- package/cjs/hex/toBn.d.ts +21 -0
- package/cjs/hex/toBn.js +35 -0
- package/cjs/hex/toNumber.d.ts +15 -0
- package/cjs/hex/toNumber.js +23 -0
- package/cjs/hex/toString.d.ts +15 -0
- package/cjs/hex/toString.js +22 -0
- package/cjs/hex/toU8a.d.ts +16 -0
- package/cjs/hex/toU8a.js +57 -0
- package/cjs/hex/toU8aBuffer.d.ts +16 -0
- package/cjs/hex/toU8aBuffer.js +43 -0
- package/cjs/index.d.ts +2 -0
- package/cjs/index.js +5 -0
- package/cjs/is/array.d.ts +5 -0
- package/cjs/is/array.js +10 -0
- package/cjs/is/ascii.d.ts +8 -0
- package/cjs/is/ascii.js +43 -0
- package/cjs/is/bigInt.d.ts +15 -0
- package/cjs/is/bigInt.js +20 -0
- package/cjs/is/bn.d.ts +17 -0
- package/cjs/is/bn.js +22 -0
- package/cjs/is/boolean.d.ts +15 -0
- package/cjs/is/boolean.js +20 -0
- package/cjs/is/buffer.d.ts +16 -0
- package/cjs/is/buffer.js +24 -0
- package/cjs/is/childClass.d.ts +17 -0
- package/cjs/is/childClass.js +26 -0
- package/cjs/is/class.d.ts +6 -0
- package/cjs/is/class.js +9 -0
- package/cjs/is/codec.d.ts +12 -0
- package/cjs/is/codec.js +9 -0
- package/cjs/is/compact.d.ts +13 -0
- package/cjs/is/compact.js +9 -0
- package/cjs/is/error.d.ts +15 -0
- package/cjs/is/error.js +21 -0
- package/cjs/is/function.d.ts +17 -0
- package/cjs/is/function.js +20 -0
- package/cjs/is/helpers.d.ts +3 -0
- package/cjs/is/helpers.js +19 -0
- package/cjs/is/hex.d.ts +19 -0
- package/cjs/is/hex.js +27 -0
- package/cjs/is/index.d.ts +33 -0
- package/cjs/is/index.js +66 -0
- package/cjs/is/instanceOf.d.ts +15 -0
- package/cjs/is/instanceOf.js +21 -0
- package/cjs/is/ip.d.ts +18 -0
- package/cjs/is/ip.js +44 -0
- package/cjs/is/jsonObject.d.ts +27 -0
- package/cjs/is/jsonObject.js +40 -0
- package/cjs/is/null.d.ts +15 -0
- package/cjs/is/null.js +20 -0
- package/cjs/is/number.d.ts +15 -0
- package/cjs/is/number.js +20 -0
- package/cjs/is/object.d.ts +18 -0
- package/cjs/is/object.js +21 -0
- package/cjs/is/observable.d.ts +16 -0
- package/cjs/is/observable.js +19 -0
- package/cjs/is/promise.d.ts +1 -0
- package/cjs/is/promise.js +5 -0
- package/cjs/is/riscv.d.ts +7 -0
- package/cjs/is/riscv.js +20 -0
- package/cjs/is/string.d.ts +16 -0
- package/cjs/is/string.js +20 -0
- package/cjs/is/testChain.d.ts +1 -0
- package/cjs/is/testChain.js +10 -0
- package/cjs/is/toBigInt.d.ts +2 -0
- package/cjs/is/toBigInt.js +5 -0
- package/cjs/is/toBn.d.ts +2 -0
- package/cjs/is/toBn.js +5 -0
- package/cjs/is/u8a.d.ts +15 -0
- package/cjs/is/u8a.js +23 -0
- package/cjs/is/undefined.d.ts +15 -0
- package/cjs/is/undefined.js +20 -0
- package/cjs/is/utf8.d.ts +7 -0
- package/cjs/is/utf8.js +200 -0
- package/cjs/is/wasm.d.ts +7 -0
- package/cjs/is/wasm.js +15 -0
- package/cjs/lazy.d.ts +14 -0
- package/cjs/lazy.js +55 -0
- package/cjs/logger.d.ts +17 -0
- package/cjs/logger.js +122 -0
- package/cjs/memoize.d.ts +10 -0
- package/cjs/memoize.js +33 -0
- package/cjs/nextTick.d.ts +5 -0
- package/cjs/nextTick.js +27 -0
- package/cjs/noop.d.ts +8 -0
- package/cjs/noop.js +16 -0
- package/cjs/number/index.d.ts +5 -0
- package/cjs/number/index.js +10 -0
- package/cjs/number/toHex.d.ts +17 -0
- package/cjs/number/toHex.js +23 -0
- package/cjs/number/toU8a.d.ts +15 -0
- package/cjs/number/toU8a.js +22 -0
- package/cjs/object/clear.d.ts +5 -0
- package/cjs/object/clear.js +14 -0
- package/cjs/object/copy.d.ts +5 -0
- package/cjs/object/copy.js +11 -0
- package/cjs/object/entries.d.ts +9 -0
- package/cjs/object/entries.js +10 -0
- package/cjs/object/index.d.ts +7 -0
- package/cjs/object/index.js +18 -0
- package/cjs/object/keys.d.ts +5 -0
- package/cjs/object/keys.js +10 -0
- package/cjs/object/property.d.ts +10 -0
- package/cjs/object/property.js +38 -0
- package/cjs/object/spread.d.ts +6 -0
- package/cjs/object/spread.js +34 -0
- package/cjs/object/values.d.ts +5 -0
- package/cjs/object/values.js +10 -0
- package/cjs/package.json +3 -0
- package/cjs/packageDetect.d.ts +1 -0
- package/cjs/packageDetect.js +7 -0
- package/cjs/packageInfo.d.ts +6 -0
- package/cjs/packageInfo.js +4 -0
- package/cjs/promisify.d.ts +16 -0
- package/cjs/promisify.js +30 -0
- package/cjs/string/camelCase.d.ts +13 -0
- package/cjs/string/camelCase.js +62 -0
- package/cjs/string/index.d.ts +8 -0
- package/cjs/string/index.js +18 -0
- package/cjs/string/lowerFirst.d.ts +31 -0
- package/cjs/string/lowerFirst.js +40 -0
- package/cjs/string/shorten.d.ts +16 -0
- package/cjs/string/shorten.js +22 -0
- package/cjs/string/toHex.d.ts +16 -0
- package/cjs/string/toHex.js +22 -0
- package/cjs/string/toU8a.d.ts +16 -0
- package/cjs/string/toU8a.js +24 -0
- package/cjs/stringify.d.ts +6 -0
- package/cjs/stringify.js +18 -0
- package/cjs/types.d.ts +62 -0
- package/cjs/types.js +2 -0
- package/cjs/u8a/cmp.d.ts +17 -0
- package/cjs/u8a/cmp.js +49 -0
- package/cjs/u8a/concat.d.ts +24 -0
- package/cjs/u8a/concat.js +51 -0
- package/cjs/u8a/concatBuffer.d.ts +19 -0
- package/cjs/u8a/concatBuffer.js +29 -0
- package/cjs/u8a/empty.d.ts +7 -0
- package/cjs/u8a/empty.js +20 -0
- package/cjs/u8a/eq.d.ts +15 -0
- package/cjs/u8a/eq.js +40 -0
- package/cjs/u8a/fixLength.d.ts +17 -0
- package/cjs/u8a/fixLength.js +31 -0
- package/cjs/u8a/index.d.ts +18 -0
- package/cjs/u8a/index.js +42 -0
- package/cjs/u8a/sorted.d.ts +15 -0
- package/cjs/u8a/sorted.js +21 -0
- package/cjs/u8a/toBigInt.d.ts +6 -0
- package/cjs/u8a/toBigInt.js +73 -0
- package/cjs/u8a/toBn.d.ts +21 -0
- package/cjs/u8a/toBn.js +81 -0
- package/cjs/u8a/toBuffer.d.ts +16 -0
- package/cjs/u8a/toBuffer.js +24 -0
- package/cjs/u8a/toFloat.d.ts +11 -0
- package/cjs/u8a/toFloat.js +20 -0
- package/cjs/u8a/toHex.d.ts +16 -0
- package/cjs/u8a/toHex.js +56 -0
- package/cjs/u8a/toHexBuffer.d.ts +16 -0
- package/cjs/u8a/toHexBuffer.js +25 -0
- package/cjs/u8a/toNumber.d.ts +6 -0
- package/cjs/u8a/toNumber.js +61 -0
- package/cjs/u8a/toString.d.ts +15 -0
- package/cjs/u8a/toString.js +24 -0
- package/cjs/u8a/toU8a.d.ts +19 -0
- package/cjs/u8a/toU8a.js +42 -0
- package/cjs/u8a/wrap.d.ts +22 -0
- package/cjs/u8a/wrap.js +49 -0
- package/compact/addLength.d.ts +13 -0
- package/compact/addLength.js +20 -0
- package/compact/defaults.d.ts +3 -0
- package/compact/defaults.js +2 -0
- package/compact/fromU8a.d.ts +22 -0
- package/compact/fromU8a.js +88 -0
- package/compact/index.d.ts +24 -0
- package/compact/index.js +24 -0
- package/compact/stripLength.d.ts +13 -0
- package/compact/stripLength.js +21 -0
- package/compact/toU8a.d.ts +14 -0
- package/compact/toU8a.js +45 -0
- package/compact/types.d.ts +1 -0
- package/compact/types.js +1 -0
- package/detectPackage.d.ts +17 -0
- package/detectPackage.js +96 -0
- package/extractTime.d.ts +14 -0
- package/extractTime.js +53 -0
- package/float/index.d.ts +1 -0
- package/float/index.js +1 -0
- package/float/toU8a.d.ts +11 -0
- package/float/toU8a.js +19 -0
- package/format/formatBalance.d.ts +54 -0
- package/format/formatBalance.js +85 -0
- package/format/formatDate.d.ts +5 -0
- package/format/formatDate.js +17 -0
- package/format/formatDecimal.d.ts +5 -0
- package/format/formatDecimal.js +16 -0
- package/format/formatElapsed.d.ts +7 -0
- package/format/formatElapsed.js +27 -0
- package/format/formatNumber.d.ts +14 -0
- package/format/formatNumber.js +11 -0
- package/format/getSeparator.d.ts +9 -0
- package/format/getSeparator.js +11 -0
- package/format/index.d.ts +6 -0
- package/format/index.js +6 -0
- package/format/si.d.ts +9 -0
- package/format/si.js +40 -0
- package/has.d.ts +14 -0
- package/has.js +16 -0
- package/hex/addPrefix.d.ts +16 -0
- package/hex/addPrefix.js +20 -0
- package/hex/fixLength.d.ts +18 -0
- package/hex/fixLength.js +27 -0
- package/hex/hasPrefix.d.ts +16 -0
- package/hex/hasPrefix.js +18 -0
- package/hex/index.d.ts +12 -0
- package/hex/index.js +12 -0
- package/hex/stripPrefix.d.ts +15 -0
- package/hex/stripPrefix.js +27 -0
- package/hex/toBigInt.d.ts +6 -0
- package/hex/toBigInt.js +12 -0
- package/hex/toBn.d.ts +21 -0
- package/hex/toBn.js +32 -0
- package/hex/toNumber.d.ts +15 -0
- package/hex/toNumber.js +20 -0
- package/hex/toString.d.ts +15 -0
- package/hex/toString.js +19 -0
- package/hex/toU8a.d.ts +16 -0
- package/hex/toU8a.js +54 -0
- package/hex/toU8aBuffer.d.ts +16 -0
- package/hex/toU8aBuffer.js +40 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/is/array.d.ts +5 -0
- package/is/array.js +7 -0
- package/is/ascii.d.ts +8 -0
- package/is/ascii.js +40 -0
- package/is/bigInt.d.ts +15 -0
- package/is/bigInt.js +17 -0
- package/is/bn.d.ts +17 -0
- package/is/bn.js +19 -0
- package/is/boolean.d.ts +15 -0
- package/is/boolean.js +17 -0
- package/is/buffer.d.ts +16 -0
- package/is/buffer.js +21 -0
- package/is/childClass.d.ts +17 -0
- package/is/childClass.js +23 -0
- package/is/class.d.ts +6 -0
- package/is/class.js +6 -0
- package/is/codec.d.ts +12 -0
- package/is/codec.js +6 -0
- package/is/compact.d.ts +13 -0
- package/is/compact.js +6 -0
- package/is/error.d.ts +15 -0
- package/is/error.js +18 -0
- package/is/function.d.ts +17 -0
- package/is/function.js +17 -0
- package/is/helpers.d.ts +3 -0
- package/is/helpers.js +14 -0
- package/is/hex.d.ts +19 -0
- package/is/hex.js +23 -0
- package/is/index.d.ts +33 -0
- package/is/index.js +33 -0
- package/is/instanceOf.d.ts +15 -0
- package/is/instanceOf.js +18 -0
- package/is/ip.d.ts +18 -0
- package/is/ip.js +41 -0
- package/is/jsonObject.d.ts +27 -0
- package/is/jsonObject.js +37 -0
- package/is/null.d.ts +15 -0
- package/is/null.js +17 -0
- package/is/number.d.ts +15 -0
- package/is/number.js +17 -0
- package/is/object.d.ts +18 -0
- package/is/object.js +18 -0
- package/is/observable.d.ts +16 -0
- package/is/observable.js +16 -0
- package/is/promise.d.ts +1 -0
- package/is/promise.js +2 -0
- package/is/riscv.d.ts +7 -0
- package/is/riscv.js +17 -0
- package/is/string.d.ts +16 -0
- package/is/string.js +17 -0
- package/is/testChain.d.ts +1 -0
- package/is/testChain.js +7 -0
- package/is/toBigInt.d.ts +2 -0
- package/is/toBigInt.js +2 -0
- package/is/toBn.d.ts +2 -0
- package/is/toBn.js +2 -0
- package/is/u8a.d.ts +15 -0
- package/is/u8a.js +20 -0
- package/is/undefined.d.ts +15 -0
- package/is/undefined.js +17 -0
- package/is/utf8.d.ts +7 -0
- package/is/utf8.js +197 -0
- package/is/wasm.d.ts +7 -0
- package/is/wasm.js +12 -0
- package/lazy.d.ts +14 -0
- package/lazy.js +51 -0
- package/logger.d.ts +17 -0
- package/logger.js +118 -0
- package/memoize.d.ts +10 -0
- package/memoize.js +30 -0
- package/nextTick.d.ts +5 -0
- package/nextTick.js +24 -0
- package/noop.d.ts +8 -0
- package/noop.js +12 -0
- package/number/index.d.ts +5 -0
- package/number/index.js +5 -0
- package/number/toHex.d.ts +17 -0
- package/number/toHex.js +20 -0
- package/number/toU8a.d.ts +15 -0
- package/number/toU8a.js +19 -0
- package/object/clear.d.ts +5 -0
- package/object/clear.js +11 -0
- package/object/copy.d.ts +5 -0
- package/object/copy.js +8 -0
- package/object/entries.d.ts +9 -0
- package/object/entries.js +7 -0
- package/object/index.d.ts +7 -0
- package/object/index.js +7 -0
- package/object/keys.d.ts +5 -0
- package/object/keys.js +7 -0
- package/object/property.d.ts +10 -0
- package/object/property.js +34 -0
- package/object/spread.d.ts +6 -0
- package/object/spread.js +31 -0
- package/object/values.d.ts +5 -0
- package/object/values.js +7 -0
- package/package.json +1956 -12
- package/packageDetect.d.ts +1 -0
- package/packageDetect.js +5 -0
- package/packageInfo.d.ts +6 -0
- package/packageInfo.js +1 -0
- package/promisify.d.ts +16 -0
- package/promisify.js +27 -0
- package/string/camelCase.d.ts +13 -0
- package/string/camelCase.js +59 -0
- package/string/index.d.ts +8 -0
- package/string/index.js +8 -0
- package/string/lowerFirst.d.ts +31 -0
- package/string/lowerFirst.js +37 -0
- package/string/shorten.d.ts +16 -0
- package/string/shorten.js +19 -0
- package/string/toHex.d.ts +16 -0
- package/string/toHex.js +19 -0
- package/string/toU8a.d.ts +16 -0
- package/string/toU8a.js +21 -0
- package/stringify.d.ts +6 -0
- package/stringify.js +15 -0
- package/types.d.ts +62 -0
- package/types.js +1 -0
- package/u8a/cmp.d.ts +17 -0
- package/u8a/cmp.js +46 -0
- package/u8a/concat.d.ts +24 -0
- package/u8a/concat.js +47 -0
- package/u8a/concatBuffer.d.ts +19 -0
- package/u8a/concatBuffer.js +26 -0
- package/u8a/empty.d.ts +7 -0
- package/u8a/empty.js +17 -0
- package/u8a/eq.d.ts +15 -0
- package/u8a/eq.js +37 -0
- package/u8a/fixLength.d.ts +17 -0
- package/u8a/fixLength.js +28 -0
- package/u8a/index.d.ts +18 -0
- package/u8a/index.js +18 -0
- package/u8a/sorted.d.ts +15 -0
- package/u8a/sorted.js +18 -0
- package/u8a/toBigInt.d.ts +6 -0
- package/u8a/toBigInt.js +70 -0
- package/u8a/toBn.d.ts +21 -0
- package/u8a/toBn.js +78 -0
- package/u8a/toBuffer.d.ts +16 -0
- package/u8a/toBuffer.js +21 -0
- package/u8a/toFloat.d.ts +11 -0
- package/u8a/toFloat.js +17 -0
- package/u8a/toHex.d.ts +16 -0
- package/u8a/toHex.js +53 -0
- package/u8a/toHexBuffer.d.ts +16 -0
- package/u8a/toHexBuffer.js +22 -0
- package/u8a/toNumber.d.ts +6 -0
- package/u8a/toNumber.js +58 -0
- package/u8a/toString.d.ts +15 -0
- package/u8a/toString.js +21 -0
- package/u8a/toU8a.d.ts +19 -0
- package/u8a/toU8a.js +39 -0
- package/u8a/wrap.d.ts +22 -0
- package/u8a/wrap.js +43 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { U8aLike } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* @name u8aToU8a
|
|
4
|
+
* @summary Creates a Uint8Array value from a Uint8Array, Buffer, string or hex input.
|
|
5
|
+
* @description
|
|
6
|
+
* `null` or `undefined` inputs returns a `[]` result, Uint8Array values returns the value, hex strings returns a Uint8Array representation.
|
|
7
|
+
* If `strict` is true, `null` or `undefined` will throw an error instead of returning an empty array.
|
|
8
|
+
* Supports input types: Uint8Array, Buffer, hex string, string, or number array.
|
|
9
|
+
* @example
|
|
10
|
+
* <BR>
|
|
11
|
+
*
|
|
12
|
+
* ```javascript
|
|
13
|
+
* import { u8aToU8a } from '@pezkuwi/util';
|
|
14
|
+
*
|
|
15
|
+
* u8aToU8a(new Uint8Array([0x12, 0x34]); // => Uint8Array([0x12, 0x34])
|
|
16
|
+
* u8aToU8a(0x1234); // => Uint8Array([0x12, 0x34])
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function u8aToU8a(value?: U8aLike | null, strict?: boolean): Uint8Array;
|
package/cjs/u8a/toU8a.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.u8aToU8a = u8aToU8a;
|
|
4
|
+
const toU8a_js_1 = require("../hex/toU8a.js");
|
|
5
|
+
const buffer_js_1 = require("../is/buffer.js");
|
|
6
|
+
const hex_js_1 = require("../is/hex.js");
|
|
7
|
+
const u8a_js_1 = require("../is/u8a.js");
|
|
8
|
+
const toU8a_js_2 = require("../string/toU8a.js");
|
|
9
|
+
/**
|
|
10
|
+
* @name u8aToU8a
|
|
11
|
+
* @summary Creates a Uint8Array value from a Uint8Array, Buffer, string or hex input.
|
|
12
|
+
* @description
|
|
13
|
+
* `null` or `undefined` inputs returns a `[]` result, Uint8Array values returns the value, hex strings returns a Uint8Array representation.
|
|
14
|
+
* If `strict` is true, `null` or `undefined` will throw an error instead of returning an empty array.
|
|
15
|
+
* Supports input types: Uint8Array, Buffer, hex string, string, or number array.
|
|
16
|
+
* @example
|
|
17
|
+
* <BR>
|
|
18
|
+
*
|
|
19
|
+
* ```javascript
|
|
20
|
+
* import { u8aToU8a } from '@pezkuwi/util';
|
|
21
|
+
*
|
|
22
|
+
* u8aToU8a(new Uint8Array([0x12, 0x34]); // => Uint8Array([0x12, 0x34])
|
|
23
|
+
* u8aToU8a(0x1234); // => Uint8Array([0x12, 0x34])
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
function u8aToU8a(value, strict = false) {
|
|
27
|
+
if (strict && (value === null || value === undefined)) {
|
|
28
|
+
throw new Error('u8aToU8a: Expected non-null, non-undefined value');
|
|
29
|
+
}
|
|
30
|
+
return (0, u8a_js_1.isU8a)(value)
|
|
31
|
+
// NOTE isBuffer needs to go here since it actually extends
|
|
32
|
+
// Uint8Array on Node.js environments, so all Buffer are Uint8Array,
|
|
33
|
+
// but Uint8Array is not Buffer
|
|
34
|
+
? (0, buffer_js_1.isBuffer)(value)
|
|
35
|
+
? new Uint8Array(value)
|
|
36
|
+
: value
|
|
37
|
+
: (0, hex_js_1.isHex)(value)
|
|
38
|
+
? (0, toU8a_js_1.hexToU8a)(value)
|
|
39
|
+
: Array.isArray(value)
|
|
40
|
+
? new Uint8Array(value)
|
|
41
|
+
: (0, toU8a_js_2.stringToU8a)(value);
|
|
42
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { U8aLike } from '../types.js';
|
|
2
|
+
/** @internal */
|
|
3
|
+
export declare const U8A_WRAP_ETHEREUM: Uint8Array;
|
|
4
|
+
/** @internal */
|
|
5
|
+
export declare const U8A_WRAP_PREFIX: Uint8Array;
|
|
6
|
+
/** @internal */
|
|
7
|
+
export declare const U8A_WRAP_POSTFIX: Uint8Array;
|
|
8
|
+
/** @internal */
|
|
9
|
+
export declare function u8aIsWrapped(u8a: Uint8Array, withEthereum: boolean): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* @name u8aUnwrapBytes
|
|
12
|
+
* @description Removes all <Bytes>...</Bytes> wrappers from the supplied value
|
|
13
|
+
*/
|
|
14
|
+
export declare function u8aUnwrapBytes(bytes: U8aLike): Uint8Array;
|
|
15
|
+
/**
|
|
16
|
+
* @name u8aWrapBytes
|
|
17
|
+
* @description
|
|
18
|
+
* Adds a <Bytes>...</Bytes> wrapper to the supplied value, if
|
|
19
|
+
* - We don't already have a Bytes wrapper
|
|
20
|
+
* - The message is not an Ethereum-style message
|
|
21
|
+
*/
|
|
22
|
+
export declare function u8aWrapBytes(bytes: U8aLike): Uint8Array;
|
package/cjs/u8a/wrap.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.U8A_WRAP_POSTFIX = exports.U8A_WRAP_PREFIX = exports.U8A_WRAP_ETHEREUM = void 0;
|
|
4
|
+
exports.u8aIsWrapped = u8aIsWrapped;
|
|
5
|
+
exports.u8aUnwrapBytes = u8aUnwrapBytes;
|
|
6
|
+
exports.u8aWrapBytes = u8aWrapBytes;
|
|
7
|
+
const concat_js_1 = require("./concat.js");
|
|
8
|
+
const eq_js_1 = require("./eq.js");
|
|
9
|
+
const toU8a_js_1 = require("./toU8a.js");
|
|
10
|
+
/** @internal */
|
|
11
|
+
exports.U8A_WRAP_ETHEREUM = (0, toU8a_js_1.u8aToU8a)('\x19Ethereum Signed Message:\n');
|
|
12
|
+
/** @internal */
|
|
13
|
+
exports.U8A_WRAP_PREFIX = (0, toU8a_js_1.u8aToU8a)('<Bytes>');
|
|
14
|
+
/** @internal */
|
|
15
|
+
exports.U8A_WRAP_POSTFIX = (0, toU8a_js_1.u8aToU8a)('</Bytes>');
|
|
16
|
+
const WRAP_LEN = exports.U8A_WRAP_PREFIX.length + exports.U8A_WRAP_POSTFIX.length;
|
|
17
|
+
/** @internal */
|
|
18
|
+
function u8aIsWrapped(u8a, withEthereum) {
|
|
19
|
+
return ((u8a.length >= WRAP_LEN &&
|
|
20
|
+
(0, eq_js_1.u8aEq)(u8a.subarray(0, exports.U8A_WRAP_PREFIX.length), exports.U8A_WRAP_PREFIX) &&
|
|
21
|
+
(0, eq_js_1.u8aEq)(u8a.slice(-exports.U8A_WRAP_POSTFIX.length), exports.U8A_WRAP_POSTFIX)) ||
|
|
22
|
+
(withEthereum &&
|
|
23
|
+
u8a.length >= exports.U8A_WRAP_ETHEREUM.length &&
|
|
24
|
+
(0, eq_js_1.u8aEq)(u8a.subarray(0, exports.U8A_WRAP_ETHEREUM.length), exports.U8A_WRAP_ETHEREUM)));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @name u8aUnwrapBytes
|
|
28
|
+
* @description Removes all <Bytes>...</Bytes> wrappers from the supplied value
|
|
29
|
+
*/
|
|
30
|
+
function u8aUnwrapBytes(bytes) {
|
|
31
|
+
const u8a = (0, toU8a_js_1.u8aToU8a)(bytes);
|
|
32
|
+
// we don't want to unwrap Ethereum-style wraps
|
|
33
|
+
return u8aIsWrapped(u8a, false)
|
|
34
|
+
? u8a.subarray(exports.U8A_WRAP_PREFIX.length, u8a.length - exports.U8A_WRAP_POSTFIX.length)
|
|
35
|
+
: u8a;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @name u8aWrapBytes
|
|
39
|
+
* @description
|
|
40
|
+
* Adds a <Bytes>...</Bytes> wrapper to the supplied value, if
|
|
41
|
+
* - We don't already have a Bytes wrapper
|
|
42
|
+
* - The message is not an Ethereum-style message
|
|
43
|
+
*/
|
|
44
|
+
function u8aWrapBytes(bytes) {
|
|
45
|
+
const u8a = (0, toU8a_js_1.u8aToU8a)(bytes);
|
|
46
|
+
return u8aIsWrapped(u8a, true)
|
|
47
|
+
? u8a
|
|
48
|
+
: (0, concat_js_1.u8aConcatStrict)([exports.U8A_WRAP_PREFIX, u8a, exports.U8A_WRAP_POSTFIX]);
|
|
49
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @name compactAddLength
|
|
3
|
+
* @description Adds a length prefix to the input value
|
|
4
|
+
* @example
|
|
5
|
+
* <BR>
|
|
6
|
+
*
|
|
7
|
+
* ```javascript
|
|
8
|
+
* import { compactAddLength } from '@pezkuwi/util';
|
|
9
|
+
*
|
|
10
|
+
* console.log(compactAddLength(new Uint8Array([0xde, 0xad, 0xbe, 0xef]))); // Uint8Array([4 << 2, 0xde, 0xad, 0xbe, 0xef])
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare function compactAddLength(input: Uint8Array): Uint8Array;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { u8aConcatStrict } from '../u8a/index.js';
|
|
2
|
+
import { compactToU8a } from './toU8a.js';
|
|
3
|
+
/**
|
|
4
|
+
* @name compactAddLength
|
|
5
|
+
* @description Adds a length prefix to the input value
|
|
6
|
+
* @example
|
|
7
|
+
* <BR>
|
|
8
|
+
*
|
|
9
|
+
* ```javascript
|
|
10
|
+
* import { compactAddLength } from '@pezkuwi/util';
|
|
11
|
+
*
|
|
12
|
+
* console.log(compactAddLength(new Uint8Array([0xde, 0xad, 0xbe, 0xef]))); // Uint8Array([4 << 2, 0xde, 0xad, 0xbe, 0xef])
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export function compactAddLength(input) {
|
|
16
|
+
return u8aConcatStrict([
|
|
17
|
+
compactToU8a(input.length),
|
|
18
|
+
input
|
|
19
|
+
]);
|
|
20
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { U8aLike } from '../types.js';
|
|
2
|
+
import { BN } from '../bn/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* @name compactFromU8a
|
|
5
|
+
* @description Retrives the offset and encoded length from a compact-prefixed value
|
|
6
|
+
* @example
|
|
7
|
+
* <BR>
|
|
8
|
+
*
|
|
9
|
+
* ```javascript
|
|
10
|
+
* import { compactFromU8a } from '@pezkuwi/util';
|
|
11
|
+
*
|
|
12
|
+
* const [offset, length] = compactFromU8a(new Uint8Array([254, 255, 3, 0]));
|
|
13
|
+
*
|
|
14
|
+
* console.log('value offset=', offset, 'length=', length); // 4, 0xffff
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function compactFromU8a(input: U8aLike): [number, BN];
|
|
18
|
+
/**
|
|
19
|
+
* @name compactFromU8aLim
|
|
20
|
+
* @description A limited version of [[compactFromU8a]], accepting only Uint8Array inputs for values <= 48 bits
|
|
21
|
+
*/
|
|
22
|
+
export declare function compactFromU8aLim(u8a: Uint8Array): [number, number];
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { BN } from '../bn/index.js';
|
|
2
|
+
import { u8aToBn, u8aToU8a } from '../u8a/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* @name compactFromU8a
|
|
5
|
+
* @description Retrives the offset and encoded length from a compact-prefixed value
|
|
6
|
+
* @example
|
|
7
|
+
* <BR>
|
|
8
|
+
*
|
|
9
|
+
* ```javascript
|
|
10
|
+
* import { compactFromU8a } from '@pezkuwi/util';
|
|
11
|
+
*
|
|
12
|
+
* const [offset, length] = compactFromU8a(new Uint8Array([254, 255, 3, 0]));
|
|
13
|
+
*
|
|
14
|
+
* console.log('value offset=', offset, 'length=', length); // 4, 0xffff
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export function compactFromU8a(input) {
|
|
18
|
+
const u8a = u8aToU8a(input);
|
|
19
|
+
// The u8a is manually converted here for 1, 2 & 4 lengths, it is 2x faster
|
|
20
|
+
// than doing an additional call to u8aToBn (as with variable length)
|
|
21
|
+
switch (u8a[0] & 0b11) {
|
|
22
|
+
case 0b00:
|
|
23
|
+
return [1, new BN(u8a[0] >>> 2)];
|
|
24
|
+
case 0b01:
|
|
25
|
+
return [2, new BN((u8a[0] + (u8a[1] << 8)) >>> 2)];
|
|
26
|
+
case 0b10:
|
|
27
|
+
// for the 3rd byte, we don't << 24 - since JS converts all bitwise operators to
|
|
28
|
+
// 32-bit, in the case where the top-most bit is set this yields a negative value
|
|
29
|
+
return [4, new BN((u8a[0] + (u8a[1] << 8) + (u8a[2] << 16) + (u8a[3] * 0x1_00_00_00)) >>> 2)];
|
|
30
|
+
// 0b11
|
|
31
|
+
default: {
|
|
32
|
+
// add 5 to shifted (4 for base length, 1 for this byte)
|
|
33
|
+
const offset = (u8a[0] >>> 2) + 5;
|
|
34
|
+
// we unroll the loop
|
|
35
|
+
switch (offset) {
|
|
36
|
+
// there still could be 4 bytes data, similar to 0b10 above (with offsets)
|
|
37
|
+
case 5:
|
|
38
|
+
// for the 3rd byte, we don't << 24 - since JS converts all bitwise operators to
|
|
39
|
+
// 32-bit, in the case where the top-most bit is set this yields a negative value
|
|
40
|
+
return [5, new BN(u8a[1] + (u8a[2] << 8) + (u8a[3] << 16) + (u8a[4] * 0x1_00_00_00))];
|
|
41
|
+
case 6:
|
|
42
|
+
return [6, new BN(u8a[1] + (u8a[2] << 8) + (u8a[3] << 16) + ((u8a[4] + (u8a[5] << 8)) * 0x1_00_00_00))];
|
|
43
|
+
// 6 bytes data is the maximum, 48 bits (56 would overflow)
|
|
44
|
+
case 7:
|
|
45
|
+
return [7, new BN(u8a[1] + (u8a[2] << 8) + (u8a[3] << 16) + ((u8a[4] + (u8a[5] << 8) + (u8a[6] << 16)) * 0x1_00_00_00))];
|
|
46
|
+
// for anything else, use the non-unrolled version
|
|
47
|
+
default:
|
|
48
|
+
return [offset, u8aToBn(u8a.subarray(1, offset))];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @name compactFromU8aLim
|
|
55
|
+
* @description A limited version of [[compactFromU8a]], accepting only Uint8Array inputs for values <= 48 bits
|
|
56
|
+
*/
|
|
57
|
+
export function compactFromU8aLim(u8a) {
|
|
58
|
+
// The u8a is manually converted here for 1, 2 & 4 lengths, it is 2x faster
|
|
59
|
+
// than doing an additional call to u8aToBn (as with variable length)
|
|
60
|
+
switch (u8a[0] & 0b11) {
|
|
61
|
+
case 0b00:
|
|
62
|
+
return [1, u8a[0] >>> 2];
|
|
63
|
+
case 0b01:
|
|
64
|
+
return [2, (u8a[0] + (u8a[1] << 8)) >>> 2];
|
|
65
|
+
case 0b10:
|
|
66
|
+
// for the 3rd byte, we don't << 24 - since JS converts all bitwise operators to
|
|
67
|
+
// 32-bit, in the case where the top-most bit is set this yields a negative value
|
|
68
|
+
return [4, (u8a[0] + (u8a[1] << 8) + (u8a[2] << 16) + (u8a[3] * 0x1_00_00_00)) >>> 2];
|
|
69
|
+
// 0b11
|
|
70
|
+
default: {
|
|
71
|
+
// add 5 to shifted (4 for base length, 1 for this byte)
|
|
72
|
+
// we unroll the loop
|
|
73
|
+
switch ((u8a[0] >>> 2) + 5) {
|
|
74
|
+
// there still could be 4 bytes data, similar to 0b10 above (with offsets)
|
|
75
|
+
case 5:
|
|
76
|
+
return [5, u8a[1] + (u8a[2] << 8) + (u8a[3] << 16) + (u8a[4] * 0x1_00_00_00)];
|
|
77
|
+
case 6:
|
|
78
|
+
return [6, u8a[1] + (u8a[2] << 8) + (u8a[3] << 16) + ((u8a[4] + (u8a[5] << 8)) * 0x1_00_00_00)];
|
|
79
|
+
// 6 bytes data is the maximum, 48 bits (56 would overflow)
|
|
80
|
+
case 7:
|
|
81
|
+
return [7, u8a[1] + (u8a[2] << 8) + (u8a[3] << 16) + ((u8a[4] + (u8a[5] << 8) + (u8a[6] << 16)) * 0x1_00_00_00)];
|
|
82
|
+
// for anything else, we are above the actual MAX_SAFE_INTEGER - bail out
|
|
83
|
+
default:
|
|
84
|
+
throw new Error('Compact input is > Number.MAX_SAFE_INTEGER');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* Encoding and decoding of parity-codec compact numbers. The codec is created
|
|
4
|
+
* to take up the least amount of space for a specific number. It performs the
|
|
5
|
+
* same function as Length, however differs in that it uses a variable number of
|
|
6
|
+
* bytes to do the actual encoding. From the Rust implementation for compact
|
|
7
|
+
* encoding:
|
|
8
|
+
*
|
|
9
|
+
* 0b00 00 00 00 / 00 00 00 00 / 00 00 00 00 / 00 00 00 00
|
|
10
|
+
* (0 ... 2**6 - 1) (u8)
|
|
11
|
+
* xx xx xx 00
|
|
12
|
+
* (2**6 ... 2**14 - 1) (u8, u16) low LH high
|
|
13
|
+
* yL yL yL 01 / yH yH yH yL
|
|
14
|
+
* (2**14 ... 2**30 - 1) (u16, u32) low LMMH high
|
|
15
|
+
* zL zL zL 10 / zM zM zM zL / zM zM zM zM / zH zH zH zM
|
|
16
|
+
* (2**30 ... 2**536 - 1) (u32, u64, u128, U256, U512, U520) straight LE-encoded
|
|
17
|
+
* nn nn nn 11 [ / zz zz zz zz ]{4 + n}
|
|
18
|
+
*
|
|
19
|
+
* Note: we use *LOW BITS* of the LSB in LE encoding to encode the 2 bit key.
|
|
20
|
+
*/
|
|
21
|
+
export { compactAddLength } from './addLength.js';
|
|
22
|
+
export { compactFromU8a, compactFromU8aLim } from './fromU8a.js';
|
|
23
|
+
export { compactStripLength } from './stripLength.js';
|
|
24
|
+
export { compactToU8a } from './toU8a.js';
|
package/compact/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* Encoding and decoding of parity-codec compact numbers. The codec is created
|
|
4
|
+
* to take up the least amount of space for a specific number. It performs the
|
|
5
|
+
* same function as Length, however differs in that it uses a variable number of
|
|
6
|
+
* bytes to do the actual encoding. From the Rust implementation for compact
|
|
7
|
+
* encoding:
|
|
8
|
+
*
|
|
9
|
+
* 0b00 00 00 00 / 00 00 00 00 / 00 00 00 00 / 00 00 00 00
|
|
10
|
+
* (0 ... 2**6 - 1) (u8)
|
|
11
|
+
* xx xx xx 00
|
|
12
|
+
* (2**6 ... 2**14 - 1) (u8, u16) low LH high
|
|
13
|
+
* yL yL yL 01 / yH yH yH yL
|
|
14
|
+
* (2**14 ... 2**30 - 1) (u16, u32) low LMMH high
|
|
15
|
+
* zL zL zL 10 / zM zM zM zL / zM zM zM zM / zH zH zH zM
|
|
16
|
+
* (2**30 ... 2**536 - 1) (u32, u64, u128, U256, U512, U520) straight LE-encoded
|
|
17
|
+
* nn nn nn 11 [ / zz zz zz zz ]{4 + n}
|
|
18
|
+
*
|
|
19
|
+
* Note: we use *LOW BITS* of the LSB in LE encoding to encode the 2 bit key.
|
|
20
|
+
*/
|
|
21
|
+
export { compactAddLength } from './addLength.js';
|
|
22
|
+
export { compactFromU8a, compactFromU8aLim } from './fromU8a.js';
|
|
23
|
+
export { compactStripLength } from './stripLength.js';
|
|
24
|
+
export { compactToU8a } from './toU8a.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @name compactStripLength
|
|
3
|
+
* @description Removes the length prefix, returning both the total length (including the value + compact encoding) and the decoded value with the correct length
|
|
4
|
+
* @example
|
|
5
|
+
* <BR>
|
|
6
|
+
*
|
|
7
|
+
* ```javascript
|
|
8
|
+
* import { compactStripLength } from '@pezkuwi/util';
|
|
9
|
+
*
|
|
10
|
+
* console.log(compactStripLength(new Uint8Array([2 << 2, 0xde, 0xad]))); // [2, Uint8Array[0xde, 0xad]]
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare function compactStripLength(input: Uint8Array): [number, Uint8Array];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { compactFromU8a } from './fromU8a.js';
|
|
2
|
+
/**
|
|
3
|
+
* @name compactStripLength
|
|
4
|
+
* @description Removes the length prefix, returning both the total length (including the value + compact encoding) and the decoded value with the correct length
|
|
5
|
+
* @example
|
|
6
|
+
* <BR>
|
|
7
|
+
*
|
|
8
|
+
* ```javascript
|
|
9
|
+
* import { compactStripLength } from '@pezkuwi/util';
|
|
10
|
+
*
|
|
11
|
+
* console.log(compactStripLength(new Uint8Array([2 << 2, 0xde, 0xad]))); // [2, Uint8Array[0xde, 0xad]]
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export function compactStripLength(input) {
|
|
15
|
+
const [offset, length] = compactFromU8a(input);
|
|
16
|
+
const total = offset + length.toNumber();
|
|
17
|
+
return [
|
|
18
|
+
total,
|
|
19
|
+
input.subarray(offset, total)
|
|
20
|
+
];
|
|
21
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BN } from '../bn/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* @name compactToU8a
|
|
4
|
+
* @description Encodes a number into a compact representation
|
|
5
|
+
* @example
|
|
6
|
+
* <BR>
|
|
7
|
+
*
|
|
8
|
+
* ```javascript
|
|
9
|
+
* import { compactToU8a } from '@pezkuwi/util';
|
|
10
|
+
*
|
|
11
|
+
* console.log(compactToU8a(511, 32)); // Uint8Array([0b11111101, 0b00000111])
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function compactToU8a(value: BN | bigint | number): Uint8Array;
|
package/compact/toU8a.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { BN, BN_ONE, BN_TWO, bnToBn, bnToU8a } from '../bn/index.js';
|
|
2
|
+
import { u8aConcatStrict } from '../u8a/index.js';
|
|
3
|
+
const MAX_U8 = BN_TWO.pow(new BN(8 - 2)).isub(BN_ONE);
|
|
4
|
+
const MAX_U16 = BN_TWO.pow(new BN(16 - 2)).isub(BN_ONE);
|
|
5
|
+
const MAX_U32 = BN_TWO.pow(new BN(32 - 2)).isub(BN_ONE);
|
|
6
|
+
const BL_16 = { bitLength: 16 };
|
|
7
|
+
const BL_32 = { bitLength: 32 };
|
|
8
|
+
/**
|
|
9
|
+
* @name compactToU8a
|
|
10
|
+
* @description Encodes a number into a compact representation
|
|
11
|
+
* @example
|
|
12
|
+
* <BR>
|
|
13
|
+
*
|
|
14
|
+
* ```javascript
|
|
15
|
+
* import { compactToU8a } from '@pezkuwi/util';
|
|
16
|
+
*
|
|
17
|
+
* console.log(compactToU8a(511, 32)); // Uint8Array([0b11111101, 0b00000111])
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function compactToU8a(value) {
|
|
21
|
+
const bn = bnToBn(value);
|
|
22
|
+
if (bn.lte(MAX_U8)) {
|
|
23
|
+
return new Uint8Array([bn.toNumber() << 2]);
|
|
24
|
+
}
|
|
25
|
+
else if (bn.lte(MAX_U16)) {
|
|
26
|
+
return bnToU8a(bn.shln(2).iadd(BN_ONE), BL_16);
|
|
27
|
+
}
|
|
28
|
+
else if (bn.lte(MAX_U32)) {
|
|
29
|
+
return bnToU8a(bn.shln(2).iadd(BN_TWO), BL_32);
|
|
30
|
+
}
|
|
31
|
+
const u8a = bnToU8a(bn);
|
|
32
|
+
let length = u8a.length;
|
|
33
|
+
// adjust to the minimum number of bytes
|
|
34
|
+
while (u8a[length - 1] === 0) {
|
|
35
|
+
length--;
|
|
36
|
+
}
|
|
37
|
+
if (length < 4) {
|
|
38
|
+
throw new Error('Invalid length, previous checks match anything less than 2^30');
|
|
39
|
+
}
|
|
40
|
+
return u8aConcatStrict([
|
|
41
|
+
// subtract 4 as minimum (also catered for in decoding)
|
|
42
|
+
new Uint8Array([((length - 4) << 2) + 0b11]),
|
|
43
|
+
u8a.subarray(0, length)
|
|
44
|
+
]);
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type BitLength = 8 | 16 | 32 | 64 | 128 | 256;
|
package/compact/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface VersionPath {
|
|
2
|
+
path: string;
|
|
3
|
+
type: string;
|
|
4
|
+
version: string;
|
|
5
|
+
}
|
|
6
|
+
interface PackageInfo extends VersionPath {
|
|
7
|
+
name: string;
|
|
8
|
+
}
|
|
9
|
+
type FnString = () => string | undefined;
|
|
10
|
+
export declare const POLKADOTJS_DISABLE_ESM_CJS_WARNING_FLAG = "POLKADOTJS_DISABLE_ESM_CJS_WARNING";
|
|
11
|
+
/**
|
|
12
|
+
* @name detectPackage
|
|
13
|
+
* @summary Checks that a specific package is only imported once
|
|
14
|
+
* @description A `@pezkuwi/*` version detection utility, checking for one occurrence of a package in addition to checking for dependency versions.
|
|
15
|
+
*/
|
|
16
|
+
export declare function detectPackage({ name, path, type, version }: PackageInfo, pathOrFn?: FnString | string | false | null, deps?: PackageInfo[]): void;
|
|
17
|
+
export {};
|
package/detectPackage.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { xglobal } from '@pezkuwi/x-global';
|
|
2
|
+
import { isFunction } from './is/function.js';
|
|
3
|
+
const DEDUPE = 'Either remove and explicitly install matching versions or dedupe using your package manager.\nThe following conflicting packages were found:';
|
|
4
|
+
export const POLKADOTJS_DISABLE_ESM_CJS_WARNING_FLAG = 'POLKADOTJS_DISABLE_ESM_CJS_WARNING';
|
|
5
|
+
/** @internal */
|
|
6
|
+
function getEntry(name) {
|
|
7
|
+
const _global = xglobal;
|
|
8
|
+
if (!_global.__polkadotjs) {
|
|
9
|
+
_global.__polkadotjs = {};
|
|
10
|
+
}
|
|
11
|
+
if (!_global.__polkadotjs[name]) {
|
|
12
|
+
_global.__polkadotjs[name] = [];
|
|
13
|
+
}
|
|
14
|
+
return _global.__polkadotjs[name];
|
|
15
|
+
}
|
|
16
|
+
/** @internal */
|
|
17
|
+
function formatDisplay(all, fmt) {
|
|
18
|
+
let max = 0;
|
|
19
|
+
for (let i = 0, count = all.length; i < count; i++) {
|
|
20
|
+
max = Math.max(max, all[i].version.length);
|
|
21
|
+
}
|
|
22
|
+
return all
|
|
23
|
+
.map((d) => `\t${fmt(d.version.padEnd(max), d).join('\t')}`)
|
|
24
|
+
.join('\n');
|
|
25
|
+
}
|
|
26
|
+
/** @internal */
|
|
27
|
+
function formatInfo(version, { name }) {
|
|
28
|
+
return [
|
|
29
|
+
version,
|
|
30
|
+
name
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
/** @internal */
|
|
34
|
+
function formatVersion(version, { path, type }) {
|
|
35
|
+
let extracted;
|
|
36
|
+
if (path && path.length >= 5) {
|
|
37
|
+
const nmIndex = path.indexOf('node_modules');
|
|
38
|
+
extracted = nmIndex === -1
|
|
39
|
+
? path
|
|
40
|
+
: path.substring(nmIndex);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
extracted = '<unknown>';
|
|
44
|
+
}
|
|
45
|
+
return [
|
|
46
|
+
`${`${type || ''}`.padStart(3)} ${version}`,
|
|
47
|
+
extracted
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
/** @internal */
|
|
51
|
+
function getPath(infoPath, pathOrFn) {
|
|
52
|
+
if (infoPath) {
|
|
53
|
+
return infoPath;
|
|
54
|
+
}
|
|
55
|
+
else if (isFunction(pathOrFn)) {
|
|
56
|
+
try {
|
|
57
|
+
return pathOrFn() || '';
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return '';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return pathOrFn || '';
|
|
64
|
+
}
|
|
65
|
+
/** @internal */
|
|
66
|
+
function warn(pre, all, fmt) {
|
|
67
|
+
console.warn(`${pre}\n${DEDUPE}\n${formatDisplay(all, fmt)}`);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @name detectPackage
|
|
71
|
+
* @summary Checks that a specific package is only imported once
|
|
72
|
+
* @description A `@pezkuwi/*` version detection utility, checking for one occurrence of a package in addition to checking for dependency versions.
|
|
73
|
+
*/
|
|
74
|
+
export function detectPackage({ name, path, type, version }, pathOrFn, deps = []) {
|
|
75
|
+
if (!name.startsWith('@pezkuwi')) {
|
|
76
|
+
throw new Error(`Invalid package descriptor ${name}`);
|
|
77
|
+
}
|
|
78
|
+
const entry = getEntry(name);
|
|
79
|
+
entry.push({ path: getPath(path, pathOrFn), type, version });
|
|
80
|
+
// if we have more than one entry at DIFFERENT version types then warn. If there is
|
|
81
|
+
// more than one entry at the same version and ESM/CJS dual warnings are disabled,
|
|
82
|
+
// then do not display warnings
|
|
83
|
+
const entriesSameVersion = entry.every((e) => e.version === version);
|
|
84
|
+
const esmCjsWarningDisabled = xglobal.process?.env?.[POLKADOTJS_DISABLE_ESM_CJS_WARNING_FLAG] === '1';
|
|
85
|
+
const multipleEntries = entry.length !== 1;
|
|
86
|
+
const disableWarnings = esmCjsWarningDisabled && entriesSameVersion;
|
|
87
|
+
if (multipleEntries && !disableWarnings) {
|
|
88
|
+
warn(`${name} has multiple versions, ensure that there is only one installed.`, entry, formatVersion);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
const mismatches = deps.filter((d) => d && d.version !== version);
|
|
92
|
+
if (mismatches.length) {
|
|
93
|
+
warn(`${name} requires direct dependencies exactly matching version ${version}.`, mismatches, formatInfo);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
package/extractTime.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Time } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* @name extractTime
|
|
4
|
+
* @summary Convert a quantity of seconds to Time array representing accumulated {days, minutes, hours, seconds, milliseconds}
|
|
5
|
+
* @example
|
|
6
|
+
* <BR>
|
|
7
|
+
*
|
|
8
|
+
* ```javascript
|
|
9
|
+
* import { extractTime } from '@pezkuwi/util';
|
|
10
|
+
*
|
|
11
|
+
* const { days, minutes, hours, seconds, milliseconds } = extractTime(6000); // 0, 0, 10, 0, 0
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function extractTime(milliseconds?: number): Time;
|
package/extractTime.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const MIN_MS = 60 * 1000;
|
|
2
|
+
const HR_MS = MIN_MS * 60;
|
|
3
|
+
const DAY_MS = HR_MS * 24;
|
|
4
|
+
const ZERO = { days: 0, hours: 0, milliseconds: 0, minutes: 0, seconds: 0 };
|
|
5
|
+
/** @internal */
|
|
6
|
+
function add(a, b) {
|
|
7
|
+
return {
|
|
8
|
+
days: (a.days || 0) + b.days,
|
|
9
|
+
hours: (a.hours || 0) + b.hours,
|
|
10
|
+
milliseconds: (a.milliseconds || 0) + b.milliseconds,
|
|
11
|
+
minutes: (a.minutes || 0) + b.minutes,
|
|
12
|
+
seconds: (a.seconds || 0) + b.seconds
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/** @internal */
|
|
16
|
+
function extractSecs(ms) {
|
|
17
|
+
const s = ms / 1000;
|
|
18
|
+
if (s < 60) {
|
|
19
|
+
const seconds = ~~s;
|
|
20
|
+
return add({ seconds }, extractTime(ms - (seconds * 1000)));
|
|
21
|
+
}
|
|
22
|
+
const m = s / 60;
|
|
23
|
+
if (m < 60) {
|
|
24
|
+
const minutes = ~~m;
|
|
25
|
+
return add({ minutes }, extractTime(ms - (minutes * MIN_MS)));
|
|
26
|
+
}
|
|
27
|
+
const h = m / 60;
|
|
28
|
+
if (h < 24) {
|
|
29
|
+
const hours = ~~h;
|
|
30
|
+
return add({ hours }, extractTime(ms - (hours * HR_MS)));
|
|
31
|
+
}
|
|
32
|
+
const days = ~~(h / 24);
|
|
33
|
+
return add({ days }, extractTime(ms - (days * DAY_MS)));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @name extractTime
|
|
37
|
+
* @summary Convert a quantity of seconds to Time array representing accumulated {days, minutes, hours, seconds, milliseconds}
|
|
38
|
+
* @example
|
|
39
|
+
* <BR>
|
|
40
|
+
*
|
|
41
|
+
* ```javascript
|
|
42
|
+
* import { extractTime } from '@pezkuwi/util';
|
|
43
|
+
*
|
|
44
|
+
* const { days, minutes, hours, seconds, milliseconds } = extractTime(6000); // 0, 0, 10, 0, 0
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export function extractTime(milliseconds) {
|
|
48
|
+
return !milliseconds
|
|
49
|
+
? ZERO
|
|
50
|
+
: milliseconds < 1000
|
|
51
|
+
? add({ milliseconds }, ZERO)
|
|
52
|
+
: extractSecs(milliseconds);
|
|
53
|
+
}
|
package/float/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { floatToU8a } from './toU8a.js';
|
package/float/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { floatToU8a } from './toU8a.js';
|
package/float/toU8a.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface Options {
|
|
2
|
+
bitLength?: 32 | 64;
|
|
3
|
+
isLe?: boolean;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* @name floatToU8a
|
|
7
|
+
* @description Converts a float into a U8a representation (While we don't use BE in SCALE
|
|
8
|
+
* we still allow for either representation, although, as elsewhere, isLe is default)
|
|
9
|
+
*/
|
|
10
|
+
export declare function floatToU8a(value?: String | string | number | Number, { bitLength, isLe }?: Options): Uint8Array;
|
|
11
|
+
export {};
|