polkadot-js/wasm

View on GitHub

Showing 37 of 37 total issues

Similar blocks of code found in 9 locations. Consider refactoring.
Open

export const keccak256 = /*#__PURE__*/ withWasm((wasm, data: Uint8Array): Uint8Array => {
  wasm.ext_keccak256(8, ...bridge.allocU8a(data));

  return bridge.resultU8a();
});
Severity: Major
Found in packages/wasm-crypto/src/bundle.ts and 8 other locations - About 1 hr to fix
packages/wasm-crypto/src/bundle.ts on lines 73..77
packages/wasm-crypto/src/bundle.ts on lines 91..95
packages/wasm-crypto/src/bundle.ts on lines 97..101
packages/wasm-crypto/src/bundle.ts on lines 103..107
packages/wasm-crypto/src/bundle.ts on lines 139..143
packages/wasm-crypto/src/bundle.ts on lines 199..203
packages/wasm-crypto/src/bundle.ts on lines 217..221
packages/wasm-crypto/src/bundle.ts on lines 223..227

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 67.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 9 locations. Consider refactoring.
Open

export const keccak512 = /*#__PURE__*/ withWasm((wasm, data: Uint8Array): Uint8Array => {
  wasm.ext_keccak512(8, ...bridge.allocU8a(data));

  return bridge.resultU8a();
});
Severity: Major
Found in packages/wasm-crypto/src/bundle.ts and 8 other locations - About 1 hr to fix
packages/wasm-crypto/src/bundle.ts on lines 73..77
packages/wasm-crypto/src/bundle.ts on lines 91..95
packages/wasm-crypto/src/bundle.ts on lines 97..101
packages/wasm-crypto/src/bundle.ts on lines 103..107
packages/wasm-crypto/src/bundle.ts on lines 139..143
packages/wasm-crypto/src/bundle.ts on lines 193..197
packages/wasm-crypto/src/bundle.ts on lines 217..221
packages/wasm-crypto/src/bundle.ts on lines 223..227

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 67.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 9 locations. Consider refactoring.
Open

export const sha256 = /*#__PURE__*/ withWasm((wasm, data: Uint8Array): Uint8Array => {
  wasm.ext_sha256(8, ...bridge.allocU8a(data));

  return bridge.resultU8a();
});
Severity: Major
Found in packages/wasm-crypto/src/bundle.ts and 8 other locations - About 1 hr to fix
packages/wasm-crypto/src/bundle.ts on lines 73..77
packages/wasm-crypto/src/bundle.ts on lines 91..95
packages/wasm-crypto/src/bundle.ts on lines 97..101
packages/wasm-crypto/src/bundle.ts on lines 103..107
packages/wasm-crypto/src/bundle.ts on lines 139..143
packages/wasm-crypto/src/bundle.ts on lines 193..197
packages/wasm-crypto/src/bundle.ts on lines 199..203
packages/wasm-crypto/src/bundle.ts on lines 223..227

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 67.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 9 locations. Consider refactoring.
Open

export const secp256k1Compress = /*#__PURE__*/ withWasm((wasm, pubkey: Uint8Array): Uint8Array => {
  wasm.ext_secp_pub_compress(8, ...bridge.allocU8a(pubkey));

  return bridge.resultU8a();
});
Severity: Major
Found in packages/wasm-crypto/src/bundle.ts and 8 other locations - About 1 hr to fix
packages/wasm-crypto/src/bundle.ts on lines 73..77
packages/wasm-crypto/src/bundle.ts on lines 91..95
packages/wasm-crypto/src/bundle.ts on lines 103..107
packages/wasm-crypto/src/bundle.ts on lines 139..143
packages/wasm-crypto/src/bundle.ts on lines 193..197
packages/wasm-crypto/src/bundle.ts on lines 199..203
packages/wasm-crypto/src/bundle.ts on lines 217..221
packages/wasm-crypto/src/bundle.ts on lines 223..227

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 67.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 9 locations. Consider refactoring.
Open

export const sr25519KeypairFromSeed = /*#__PURE__*/ withWasm((wasm, seed: Uint8Array): Uint8Array => {
  wasm.ext_sr_from_seed(8, ...bridge.allocU8a(seed));

  return bridge.resultU8a();
});
Severity: Major
Found in packages/wasm-crypto/src/bundle.ts and 8 other locations - About 1 hr to fix
packages/wasm-crypto/src/bundle.ts on lines 73..77
packages/wasm-crypto/src/bundle.ts on lines 91..95
packages/wasm-crypto/src/bundle.ts on lines 97..101
packages/wasm-crypto/src/bundle.ts on lines 103..107
packages/wasm-crypto/src/bundle.ts on lines 193..197
packages/wasm-crypto/src/bundle.ts on lines 199..203
packages/wasm-crypto/src/bundle.ts on lines 217..221
packages/wasm-crypto/src/bundle.ts on lines 223..227

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 67.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 9 locations. Consider refactoring.
Open

export const sha512 = /*#__PURE__*/ withWasm((wasm, data: Uint8Array): Uint8Array => {
  wasm.ext_sha512(8, ...bridge.allocU8a(data));

  return bridge.resultU8a();
});
Severity: Major
Found in packages/wasm-crypto/src/bundle.ts and 8 other locations - About 1 hr to fix
packages/wasm-crypto/src/bundle.ts on lines 73..77
packages/wasm-crypto/src/bundle.ts on lines 91..95
packages/wasm-crypto/src/bundle.ts on lines 97..101
packages/wasm-crypto/src/bundle.ts on lines 103..107
packages/wasm-crypto/src/bundle.ts on lines 139..143
packages/wasm-crypto/src/bundle.ts on lines 193..197
packages/wasm-crypto/src/bundle.ts on lines 199..203
packages/wasm-crypto/src/bundle.ts on lines 217..221

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 67.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 9 locations. Consider refactoring.
Open

export const ed25519KeypairFromSeed = /*#__PURE__*/ withWasm((wasm, seed: Uint8Array): Uint8Array => {
  wasm.ext_ed_from_seed(8, ...bridge.allocU8a(seed));

  return bridge.resultU8a();
});
Severity: Major
Found in packages/wasm-crypto/src/bundle.ts and 8 other locations - About 1 hr to fix
packages/wasm-crypto/src/bundle.ts on lines 91..95
packages/wasm-crypto/src/bundle.ts on lines 97..101
packages/wasm-crypto/src/bundle.ts on lines 103..107
packages/wasm-crypto/src/bundle.ts on lines 139..143
packages/wasm-crypto/src/bundle.ts on lines 193..197
packages/wasm-crypto/src/bundle.ts on lines 199..203
packages/wasm-crypto/src/bundle.ts on lines 217..221
packages/wasm-crypto/src/bundle.ts on lines 223..227

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 67.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 9 locations. Consider refactoring.
Open

export const secp256k1Expand = /*#__PURE__*/ withWasm((wasm, pubkey: Uint8Array): Uint8Array => {
  wasm.ext_secp_pub_expand(8, ...bridge.allocU8a(pubkey));

  return bridge.resultU8a();
});
Severity: Major
Found in packages/wasm-crypto/src/bundle.ts and 8 other locations - About 1 hr to fix
packages/wasm-crypto/src/bundle.ts on lines 73..77
packages/wasm-crypto/src/bundle.ts on lines 91..95
packages/wasm-crypto/src/bundle.ts on lines 97..101
packages/wasm-crypto/src/bundle.ts on lines 139..143
packages/wasm-crypto/src/bundle.ts on lines 193..197
packages/wasm-crypto/src/bundle.ts on lines 199..203
packages/wasm-crypto/src/bundle.ts on lines 217..221
packages/wasm-crypto/src/bundle.ts on lines 223..227

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 67.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function hMap has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const hMap = ((cd: Uint8Array, mb: number, r: 0 | 1) => {
  const s = cd.length;
  // index
  let i = 0;
  // u16 "map": index -> # of codes with bit length = index
Severity: Minor
Found in packages/wasm-util/src/fflate.ts - About 1 hr to fix

    Function createWasmFn has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function createWasmFn <C extends WasmBaseInstance> (root: 'crypto', wasmBytes: null | Uint8Array, asmFn: null | ((wbg: WasmImports) => C)): InitFn<C> {
      return async (wbg: WasmImports): InitPromise<C> => {
        const result: InitResult<C> = {
          error: null,
          type: 'none',
    Severity: Minor
    Found in packages/wasm-bridge/src/init.ts - About 1 hr to fix

      Avoid deeply nested control flow statements.
      Open

              for (let i = 0; i < hcLen; ++i) {
                // use index map to get real code
                clt[clim[i]] = bits(dat, pos + i * 3, 7);
              }
      Severity: Major
      Found in packages/wasm-util/src/fflate.ts - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                for (let i = 0; i < tl;) {
                  const r = clm[bits(dat, pos, clbmsk)];
                  // bits read
                  pos += r & 15;
                  // symbol
        Severity: Major
        Found in packages/wasm-util/src/fflate.ts - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                  if (!noSt && pos + tl * (clb + 7) > tbts) break;
          Severity: Major
          Found in packages/wasm-util/src/fflate.ts - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                      if (noSt) throw 'unexpected EOF';
            Severity: Major
            Found in packages/wasm-util/src/fflate.ts - About 45 mins to fix

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                ext_ed_sign(resLen: 8, ptrPub: number, lenPub: number, ptrSec: number, lenSec: number, ptrMsg: number, lenMsg: number): void;
              Severity: Minor
              Found in packages/wasm-crypto-init/src/types.ts and 1 other location - About 30 mins to fix
              packages/wasm-crypto-init/src/types.ts on lines 66..66

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 45.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                ext_sr_sign(resLen: 8, ptrPub: number, lenPub: number, ptrSec: number, lenSec: number, ptrMsg: number, lenMsg: number): void;
              Severity: Minor
              Found in packages/wasm-crypto-init/src/types.ts and 1 other location - About 30 mins to fix
              packages/wasm-crypto-init/src/types.ts on lines 24..24

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 45.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Function slc has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              const slc = <T extends Uint8Array | Uint16Array | Uint32Array>(v: T, s: number, e?: number): T => {
                if (s == null || s < 0) s = 0;
                if (e == null || e > v.length) e = v.length;
                // can't use .constructor in case user-supplied
                const n = new (v instanceof u16 ? u16 : v instanceof u32 ? u32 : u8)(e - s) as T;
              Severity: Minor
              Found in packages/wasm-util/src/fflate.ts - About 25 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Severity
              Category
              Status
              Source
              Language