@polkadot/types-codec 8.8.3-2 → 8.8.3-5

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.
Files changed (69) hide show
  1. package/abstract/{AbstractArray.d.ts → Array.d.ts} +0 -0
  2. package/abstract/{AbstractArray.js → Array.js} +0 -0
  3. package/{base → abstract}/Base.d.ts +2 -2
  4. package/{base → abstract}/Base.js +2 -7
  5. package/abstract/{AbstractInt.d.ts → Int.d.ts} +1 -4
  6. package/abstract/{AbstractInt.js → Int.js} +7 -14
  7. package/abstract/index.d.ts +3 -2
  8. package/abstract/index.js +3 -2
  9. package/base/Compact.d.ts +0 -2
  10. package/base/Compact.js +15 -16
  11. package/base/Enum.js +6 -6
  12. package/base/Int.d.ts +1 -1
  13. package/base/Int.js +1 -1
  14. package/base/Null.d.ts +2 -8
  15. package/base/Null.js +2 -16
  16. package/base/Option.d.ts +1 -4
  17. package/base/Option.js +1 -10
  18. package/base/Tuple.d.ts +1 -1
  19. package/base/Tuple.js +3 -4
  20. package/base/UInt.d.ts +1 -1
  21. package/base/UInt.js +1 -1
  22. package/base/Vec.d.ts +1 -1
  23. package/base/Vec.js +2 -3
  24. package/base/VecAny.d.ts +1 -1
  25. package/base/VecAny.js +1 -1
  26. package/base/VecFixed.d.ts +1 -1
  27. package/base/VecFixed.js +2 -3
  28. package/base/index.d.ts +0 -1
  29. package/base/index.js +0 -1
  30. package/cjs/abstract/{AbstractArray.js → Array.js} +0 -0
  31. package/cjs/{base → abstract}/Base.js +4 -9
  32. package/cjs/abstract/{AbstractInt.js → Int.js} +6 -13
  33. package/cjs/abstract/index.js +12 -4
  34. package/cjs/base/Compact.js +15 -16
  35. package/cjs/base/Enum.js +5 -5
  36. package/cjs/base/Int.js +2 -2
  37. package/cjs/base/Null.js +2 -16
  38. package/cjs/base/Option.js +1 -10
  39. package/cjs/base/Tuple.js +4 -5
  40. package/cjs/base/UInt.js +2 -2
  41. package/cjs/base/Vec.js +3 -4
  42. package/cjs/base/VecAny.js +2 -2
  43. package/cjs/base/VecFixed.js +3 -4
  44. package/cjs/base/index.js +0 -8
  45. package/cjs/extended/Bytes.js +1 -1
  46. package/cjs/extended/Map.js +2 -2
  47. package/cjs/extended/OptionBool.js +1 -8
  48. package/cjs/native/Struct.js +2 -7
  49. package/cjs/native/Text.js +1 -10
  50. package/cjs/packageInfo.js +1 -1
  51. package/cjs/utils/decodeU8a.js +63 -20
  52. package/cjs/utils/index.js +6 -0
  53. package/cjs/utils/mapToTypeMap.js +1 -1
  54. package/extended/Bytes.js +2 -2
  55. package/extended/Map.js +1 -1
  56. package/extended/OptionBool.d.ts +0 -4
  57. package/extended/OptionBool.js +1 -8
  58. package/native/Raw.d.ts +1 -1
  59. package/native/Struct.d.ts +1 -1
  60. package/native/Struct.js +3 -8
  61. package/native/Text.d.ts +2 -5
  62. package/native/Text.js +1 -10
  63. package/package.json +15 -15
  64. package/packageInfo.js +1 -1
  65. package/utils/decodeU8a.d.ts +16 -1
  66. package/utils/decodeU8a.js +57 -19
  67. package/utils/index.d.ts +1 -1
  68. package/utils/index.js +1 -1
  69. package/utils/mapToTypeMap.js +1 -1
File without changes
File without changes
@@ -4,10 +4,11 @@ import type { AnyJson, BareOpts, Codec, Inspect, IU8a, Registry } from '../types
4
4
  * @name Base
5
5
  * @description A type extends the Base class, when it holds a value
6
6
  */
7
- export declare abstract class Base<T extends Codec> implements Codec {
7
+ export declare abstract class AbstractBase<T extends Codec> implements Codec {
8
8
  #private;
9
9
  createdAtHash?: IU8a;
10
10
  readonly initialU8aLength?: number;
11
+ readonly registry: Registry;
11
12
  protected constructor(registry: Registry, value: T, initialU8aLength?: number);
12
13
  /**
13
14
  * @description The length of the value when encoded as a Uint8Array
@@ -22,7 +23,6 @@ export declare abstract class Base<T extends Codec> implements Codec {
22
23
  * @description Checks if the value is an empty value
23
24
  */
24
25
  get isEmpty(): boolean;
25
- get registry(): Registry;
26
26
  /**
27
27
  * @description Compares the value of the input to see if there is a match
28
28
  */
@@ -5,14 +5,13 @@
5
5
  * @name Base
6
6
  * @description A type extends the Base class, when it holds a value
7
7
  */
8
- export class Base {
9
- #registry;
8
+ export class AbstractBase {
10
9
  #raw;
11
10
 
12
11
  constructor(registry, value, initialU8aLength) {
13
- this.#registry = registry;
14
12
  this.#raw = value;
15
13
  this.initialU8aLength = initialU8aLength;
14
+ this.registry = registry;
16
15
  }
17
16
  /**
18
17
  * @description The length of the value when encoded as a Uint8Array
@@ -42,10 +41,6 @@ export class Base {
42
41
  get isEmpty() {
43
42
  return this.#raw.isEmpty;
44
43
  }
45
-
46
- get registry() {
47
- return this.#registry;
48
- }
49
44
  /**
50
45
  * @description Compares the value of the input to see if there is a match
51
46
  */
@@ -13,6 +13,7 @@ export declare abstract class AbstractInt extends BN implements INumber {
13
13
  readonly registry: Registry;
14
14
  createdAtHash?: IU8a;
15
15
  readonly encodedLength: number;
16
+ readonly isUnsigned: boolean;
16
17
  constructor(registry: Registry, value?: AnyNumber, bitLength?: UIntBitLength, isSigned?: boolean);
17
18
  /**
18
19
  * @description returns a hash of the contents
@@ -22,10 +23,6 @@ export declare abstract class AbstractInt extends BN implements INumber {
22
23
  * @description Checks if the value is a zero value (align elsewhere)
23
24
  */
24
25
  get isEmpty(): boolean;
25
- /**
26
- * @description Checks if the value is an unsigned type
27
- */
28
- get isUnsigned(): boolean;
29
26
  /**
30
27
  * @description Returns the number of bits in the value
31
28
  */
@@ -1,6 +1,6 @@
1
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { assert, BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_QUINTILL, BN_ZERO, bnToBn, bnToHex, bnToU8a, formatBalance, formatNumber, hexToBn, isBn, isHex, isNumber, isString, isU8a, u8aToBn } from '@polkadot/util';
3
+ import { assert, BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_QUINTILL, BN_ZERO, bnToBn, bnToHex, bnToU8a, formatBalance, formatNumber, hexToBn, isBn, isHex, isNumber, isString, isU8a, u8aToBn, u8aToNumber } from '@polkadot/util';
4
4
  export const DEFAULT_UINT_BITS = 64; // Maximum allowed integer for JS is 2^53 - 1, set limit at 52
5
5
  // In this case however, we always print any >32 as hex
6
6
 
@@ -43,21 +43,22 @@ function decodeAbstractInt(value, isNegative) {
43
43
 
44
44
  export class AbstractInt extends BN {
45
45
  #bitLength;
46
- #isSigned;
47
46
 
48
47
  constructor(registry, value = 0, bitLength = DEFAULT_UINT_BITS, isSigned = false) {
49
- // Construct via a string, which will be passed in the BN constructor.
48
+ // Construct via a string/number, which will be passed in the BN constructor.
50
49
  // It would be ideal to actually return a BN, but there is an issue:
51
50
  // https://github.com/indutny/bn.js/issues/206
52
51
  super( // shortcut isU8a as used in SCALE decoding
53
- isU8a(value) ? u8aToBn(value.subarray(0, bitLength / 8), {
52
+ isU8a(value) ? bitLength <= 48 ? u8aToNumber(value.subarray(0, bitLength / 8), {
53
+ isNegative: isSigned
54
+ }) : u8aToBn(value.subarray(0, bitLength / 8), {
54
55
  isLe: true,
55
56
  isNegative: isSigned
56
57
  }).toString() : decodeAbstractInt(value, isSigned));
57
58
  this.registry = registry;
58
59
  this.#bitLength = bitLength;
59
60
  this.encodedLength = this.#bitLength / 8;
60
- this.#isSigned = isSigned;
61
+ this.isUnsigned = !isSigned;
61
62
  const isPositive = this.gte(BN_ZERO);
62
63
  const maxBits = bitLength - (isSigned && isPositive ? 1 : 0);
63
64
  assert(isSigned || isPositive, () => `${this.toRawType()}: Negative number passed to unsigned type`);
@@ -79,14 +80,6 @@ export class AbstractInt extends BN {
79
80
  get isEmpty() {
80
81
  return this.isZero();
81
82
  }
82
- /**
83
- * @description Checks if the value is an unsigned type
84
- */
85
-
86
-
87
- get isUnsigned() {
88
- return !this.#isSigned;
89
- }
90
83
  /**
91
84
  * @description Returns the number of bits in the value
92
85
  */
@@ -106,7 +99,7 @@ export class AbstractInt extends BN {
106
99
  // number and BN inputs (no `.eqn` needed) - numbers will be converted
107
100
  return super.eq(isHex(other) ? hexToBn(other.toString(), {
108
101
  isLe: false,
109
- isNegative: this.#isSigned
102
+ isNegative: !this.isUnsigned
110
103
  }) : bnToBn(other));
111
104
  }
112
105
  /**
@@ -1,2 +1,3 @@
1
- export { AbstractArray } from './AbstractArray';
2
- export { AbstractInt } from './AbstractInt';
1
+ export { AbstractArray } from './Array';
2
+ export { AbstractBase } from './Base';
3
+ export { AbstractInt } from './Int';
package/abstract/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- export { AbstractArray } from "./AbstractArray.js";
4
- export { AbstractInt } from "./AbstractInt.js";
3
+ export { AbstractArray } from "./Array.js";
4
+ export { AbstractBase } from "./Base.js";
5
+ export { AbstractInt } from "./Int.js";
package/base/Compact.d.ts CHANGED
@@ -21,8 +21,6 @@ export declare class Compact<T extends INumber> implements ICompact<T> {
21
21
  readonly initialU8aLength?: number;
22
22
  constructor(registry: Registry, Type: CodecClass<T> | string, value?: Compact<T> | AnyNumber, { definition, setDefinition }?: Options<T>);
23
23
  static with<O extends INumber>(Type: CodecClass<O> | string): CodecClass<Compact<O>>;
24
- /** @internal */
25
- static decodeCompact<T extends INumber>(registry: Registry, Type: CodecClass<T>, value: Compact<T> | AnyNumber): [T, number];
26
24
  /**
27
25
  * @description The length of the value when encoded as a Uint8Array
28
26
  */
package/base/Compact.js CHANGED
@@ -6,6 +6,20 @@ import { typeToConstructor } from "../utils/index.js";
6
6
  function noopSetDefinition(d) {
7
7
  return d;
8
8
  }
9
+
10
+ function decodeCompact(registry, Type, value) {
11
+ if (isU8a(value)) {
12
+ const [decodedLength, bn] = (value[0] & 0b11) < 0b11 ? compactFromU8aLim(value) : compactFromU8a(value);
13
+ return [new Type(registry, bn), decodedLength];
14
+ } else if (value instanceof Compact) {
15
+ const raw = value.unwrap();
16
+ return raw instanceof Type ? [raw, 0] : [new Type(registry, raw), 0];
17
+ } else if (value instanceof Type) {
18
+ return [value, 0];
19
+ }
20
+
21
+ return [new Type(registry, value), 0];
22
+ }
9
23
  /**
10
24
  * @name Compact
11
25
  * @description
@@ -26,7 +40,7 @@ export class Compact {
26
40
  } = {}) {
27
41
  this.registry = registry;
28
42
  this.#Type = definition || setDefinition(typeToConstructor(registry, Type));
29
- const [raw, decodedLength] = Compact.decodeCompact(registry, this.#Type, value);
43
+ const [raw, decodedLength] = decodeCompact(registry, this.#Type, value);
30
44
  this.initialU8aLength = decodedLength;
31
45
  this.#raw = raw;
32
46
  }
@@ -46,21 +60,6 @@ export class Compact {
46
60
 
47
61
  };
48
62
  }
49
- /** @internal */
50
-
51
-
52
- static decodeCompact(registry, Type, value) {
53
- if (isU8a(value)) {
54
- const [decodedLength, bn] = (value[0] & 0b11) < 0b11 ? compactFromU8aLim(value) : compactFromU8a(value);
55
- return [new Type(registry, bn), decodedLength];
56
- } else if (value instanceof Compact) {
57
- return value.#raw instanceof Type ? [value.#raw, 0] : [new Type(registry, value.#raw), 0];
58
- } else if (value instanceof Type) {
59
- return [value, 0];
60
- }
61
-
62
- return [new Type(registry, value), 0];
63
- }
64
63
  /**
65
64
  * @description The length of the value when encoded as a Uint8Array
66
65
  */
package/base/Enum.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { assert, isCodec, isHex, isNumber, isObject, isString, isU8a, isUndefined, objectProperties, stringCamelCase, stringify, stringPascalCase, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
3
+ import { assert, isHex, isNumber, isObject, isString, isU8a, isUndefined, objectProperties, stringCamelCase, stringify, stringPascalCase, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
4
4
  import { mapToTypeMap, typesToMap } from "../utils/index.js";
5
5
  import { Null } from "./Null.js"; // export interface, this is used in Enum.with, so required as public by TS
6
6
 
@@ -75,7 +75,7 @@ function createFromValue(registry, def, index = 0, value) {
75
75
  assert(!isUndefined(entry), () => `Unable to create Enum via index ${index}, in ${Object.keys(def).join(', ')}`);
76
76
  return {
77
77
  index,
78
- value: isCodec(value) && value instanceof entry.Type ? value : new entry.Type(registry, value)
78
+ value: value instanceof entry.Type ? value : new entry.Type(registry, value)
79
79
  };
80
80
  }
81
81
 
@@ -153,7 +153,7 @@ export class Enum {
153
153
  this.#indexes = Object.values(def).map(({
154
154
  index
155
155
  }) => index);
156
- this.#entryIndex = this.#indexes.indexOf(decoded.index) || 0;
156
+ this.#entryIndex = this.#indexes.indexOf(decoded.index);
157
157
  this.#raw = decoded.value;
158
158
 
159
159
  if (this.#raw.initialU8aLength) {
@@ -167,7 +167,7 @@ export class Enum {
167
167
  const isKeys = new Array(keys.length);
168
168
 
169
169
  for (let i = 0; i < keys.length; i++) {
170
- const name = stringPascalCase(keys[i].replace(' ', '_'));
170
+ const name = stringPascalCase(keys[i]);
171
171
  asKeys[i] = `as${name}`;
172
172
  isKeys[i] = `is${name}`;
173
173
  }
@@ -303,7 +303,7 @@ export class Enum {
303
303
  return this.type === other;
304
304
  } else if (isHex(other)) {
305
305
  return this.toHex() === other;
306
- } else if (isCodec(other) && other instanceof Enum) {
306
+ } else if (other instanceof Enum) {
307
307
  return this.index === other.index && this.value.eq(other.value);
308
308
  } else if (isObject(other)) {
309
309
  return this.value.eq(other[this.type]);
@@ -318,7 +318,7 @@ export class Enum {
318
318
 
319
319
 
320
320
  inspect() {
321
- if (this.isBasic) {
321
+ if (this.#isBasic) {
322
322
  return {
323
323
  outer: [new Uint8Array([this.index])]
324
324
  };
package/base/Int.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { AnyNumber, CodecClass, Registry, UIntBitLength } from '../types';
2
- import { AbstractInt } from '../abstract/AbstractInt';
2
+ import { AbstractInt } from '../abstract/Int';
3
3
  /**
4
4
  * @name Int
5
5
  * @description
package/base/Int.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { AbstractInt } from "../abstract/AbstractInt.js";
3
+ import { AbstractInt } from "../abstract/Int.js";
4
4
  /**
5
5
  * @name Int
6
6
  * @description
package/base/Null.d.ts CHANGED
@@ -6,22 +6,16 @@ import type { Codec, Inspect, IU8a, Registry } from '../types';
6
6
  * Implements a type that does not contain anything (apart from `null`)
7
7
  */
8
8
  export declare class Null implements Codec {
9
+ readonly encodedLength = 0;
10
+ readonly isEmpty = true;
9
11
  readonly registry: Registry;
10
12
  createdAtHash?: IU8a;
11
13
  readonly initialU8aLength = 0;
12
14
  constructor(registry: Registry);
13
- /**
14
- * @description The length of the value when encoded as a Uint8Array
15
- */
16
- get encodedLength(): number;
17
15
  /**
18
16
  * @description returns a hash of the contents
19
17
  */
20
18
  get hash(): IU8a;
21
- /**
22
- * @description Checks if the value is an empty value (always true)
23
- */
24
- get isEmpty(): boolean;
25
19
  /**
26
20
  * @description Compares the value of the input to see if there is a match
27
21
  */
package/base/Null.js CHANGED
@@ -8,20 +8,14 @@ import { isNull } from '@polkadot/util';
8
8
  */
9
9
 
10
10
  export class Null {
11
+ encodedLength = 0;
12
+ isEmpty = true;
11
13
  // Added for compatibility reasons, e.g. see Option
12
14
  initialU8aLength = 0;
13
15
 
14
16
  constructor(registry) {
15
17
  this.registry = registry;
16
18
  }
17
- /**
18
- * @description The length of the value when encoded as a Uint8Array
19
- */
20
-
21
-
22
- get encodedLength() {
23
- return 0;
24
- }
25
19
  /**
26
20
  * @description returns a hash of the contents
27
21
  */
@@ -30,14 +24,6 @@ export class Null {
30
24
  get hash() {
31
25
  throw new Error('.hash is not implemented on Null');
32
26
  }
33
- /**
34
- * @description Checks if the value is an empty value (always true)
35
- */
36
-
37
-
38
- get isEmpty() {
39
- return true;
40
- }
41
27
  /**
42
28
  * @description Compares the value of the input to see if there is a match
43
29
  */
package/base/Option.d.ts CHANGED
@@ -16,16 +16,13 @@ export declare class Option<T extends Codec> implements IOption<T> {
16
16
  #private;
17
17
  readonly registry: Registry;
18
18
  createdAtHash?: IU8a;
19
+ initialU8aLength?: number;
19
20
  constructor(registry: Registry, typeName: CodecClass<T> | string, value?: unknown, { definition, setDefinition }?: Options<T>);
20
21
  static with<O extends Codec>(Type: CodecClass<O> | string): CodecClass<Option<O>>;
21
22
  /**
22
23
  * @description The length of the value when encoded as a Uint8Array
23
24
  */
24
25
  get encodedLength(): number;
25
- /**
26
- * @description The length of the initial encoded value (Only available when constructed from a Uint8Array)
27
- */
28
- get initialU8aLength(): number | undefined;
29
26
  /**
30
27
  * @description returns a hash of the contents
31
28
  */
package/base/Option.js CHANGED
@@ -58,7 +58,6 @@ function decodeOption(registry, Type, value) {
58
58
 
59
59
  export class Option {
60
60
  #Type;
61
- #initialU8aLength;
62
61
  #raw;
63
62
 
64
63
  constructor(registry, typeName, value, {
@@ -72,7 +71,7 @@ export class Option {
72
71
  this.#raw = decoded;
73
72
 
74
73
  if (decoded && decoded.initialU8aLength) {
75
- this.#initialU8aLength = 1 + decoded.initialU8aLength;
74
+ this.initialU8aLength = 1 + decoded.initialU8aLength;
76
75
  }
77
76
  }
78
77
 
@@ -103,14 +102,6 @@ export class Option {
103
102
  // boolean byte (has value, doesn't have) along with wrapped length
104
103
  return 1 + this.#raw.encodedLength;
105
104
  }
106
- /**
107
- * @description The length of the initial encoded value (Only available when constructed from a Uint8Array)
108
- */
109
-
110
-
111
- get initialU8aLength() {
112
- return this.#initialU8aLength;
113
- }
114
105
  /**
115
106
  * @description returns a hash of the contents
116
107
  */
package/base/Tuple.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { AnyTupleValue, Codec, CodecClass, Inspect, ITuple, Registry } from '../types';
2
- import { AbstractArray } from '../abstract/AbstractArray';
2
+ import { AbstractArray } from '../abstract/Array';
3
3
  declare type TupleType = (CodecClass | string);
4
4
  declare type TupleTypes = TupleType[] | {
5
5
  [index: string]: CodecClass | string;
package/base/Tuple.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { isFunction, isHex, isString, isU8a, stringify, u8aConcatStrict, u8aToU8a } from '@polkadot/util';
4
- import { AbstractArray } from "../abstract/AbstractArray.js";
4
+ import { AbstractArray } from "../abstract/Array.js";
5
5
  import { decodeU8a, mapToTypeMap, typeToConstructor } from "../utils/index.js";
6
6
 
7
7
  function noopSetDefinition(d) {
@@ -10,7 +10,7 @@ function noopSetDefinition(d) {
10
10
  /** @internal */
11
11
 
12
12
 
13
- function decodeTuple(registry, result, Classes, value) {
13
+ function decodeTuple(registry, result, value, Classes) {
14
14
  if (isU8a(value) || isHex(value)) {
15
15
  return decodeU8a(registry, result, u8aToU8a(value), Classes);
16
16
  }
@@ -45,8 +45,7 @@ export class Tuple extends AbstractArray {
45
45
  } = {}) {
46
46
  const Classes = definition || setDefinition(Array.isArray(Types) ? [Types.map(t => typeToConstructor(registry, t)), []] : isFunction(Types) || isString(Types) ? [[typeToConstructor(registry, Types)], []] : mapToTypeMap(registry, Types));
47
47
  super(registry, Classes[0].length);
48
- const [, decodedLength] = isU8a(value) ? decodeU8a(registry, this, value, Classes, false) : decodeTuple(registry, this, Classes, value);
49
- this.initialU8aLength = decodedLength;
48
+ this.initialU8aLength = (isU8a(value) ? decodeU8a(registry, this, value, Classes) : decodeTuple(registry, this, value, Classes))[1];
50
49
  this.#Types = Classes;
51
50
  }
52
51
 
package/base/UInt.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { CodecClass, UIntBitLength } from '../types';
2
- import { AbstractInt } from '../abstract/AbstractInt';
2
+ import { AbstractInt } from '../abstract/Int';
3
3
  /**
4
4
  * @name UInt
5
5
  * @description
package/base/UInt.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { AbstractInt } from "../abstract/AbstractInt.js";
3
+ import { AbstractInt } from "../abstract/Int.js";
4
4
  /**
5
5
  * @name UInt
6
6
  * @description
package/base/Vec.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { HexString } from '@polkadot/util/types';
2
2
  import type { Codec, CodecClass, Registry } from '../types';
3
- import { AbstractArray } from '../abstract/AbstractArray';
3
+ import { AbstractArray } from '../abstract/Array';
4
4
  interface Options<T> {
5
5
  definition?: CodecClass<T>;
6
6
  setDefinition?: (d: CodecClass<T>) => CodecClass<T>;
package/base/Vec.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { assert, compactFromU8aLim, isU8a, logger, u8aToU8a } from '@polkadot/util';
4
- import { AbstractArray } from "../abstract/AbstractArray.js";
4
+ import { AbstractArray } from "../abstract/Array.js";
5
5
  import { decodeU8aVec, typeToConstructor } from "../utils/index.js";
6
6
  const MAX_LENGTH = 64 * 1024;
7
7
  const l = logger('Vec');
@@ -59,8 +59,7 @@ export class Vec extends AbstractArray {
59
59
  const [decodeFrom, length, startAt] = decodeVecLength(value);
60
60
  super(registry, length);
61
61
  this.#Type = definition || setDefinition(typeToConstructor(registry, Type));
62
- const [decodedLength] = isU8a(decodeFrom) ? decodeU8aVec(registry, this, decodeFrom, startAt, this.#Type) : decodeVec(registry, this, decodeFrom, startAt, this.#Type);
63
- this.initialU8aLength = decodedLength;
62
+ this.initialU8aLength = (isU8a(decodeFrom) ? decodeU8aVec(registry, this, decodeFrom, startAt, this.#Type) : decodeVec(registry, this, decodeFrom, startAt, this.#Type))[0];
64
63
  }
65
64
 
66
65
  static with(Type) {
package/base/VecAny.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Codec } from '../types';
2
- import { AbstractArray } from '../abstract/AbstractArray';
2
+ import { AbstractArray } from '../abstract/Array';
3
3
  /**
4
4
  * @name VecAny
5
5
  * @description
package/base/VecAny.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { AbstractArray } from "../abstract/AbstractArray.js";
3
+ import { AbstractArray } from "../abstract/Array.js";
4
4
  /**
5
5
  * @name VecAny
6
6
  * @description
@@ -1,6 +1,6 @@
1
1
  import type { HexString } from '@polkadot/util/types';
2
2
  import type { Codec, CodecClass, Inspect, Registry } from '../types';
3
- import { AbstractArray } from '../abstract/AbstractArray';
3
+ import { AbstractArray } from '../abstract/Array';
4
4
  interface Options<T> {
5
5
  definition?: CodecClass<T>;
6
6
  setDefinition?: (d: CodecClass<T>) => CodecClass<T>;
package/base/VecFixed.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { isU8a, u8aConcatStrict } from '@polkadot/util';
4
- import { AbstractArray } from "../abstract/AbstractArray.js";
4
+ import { AbstractArray } from "../abstract/Array.js";
5
5
  import { decodeU8aVec, typeToConstructor } from "../utils/index.js";
6
6
  import { decodeVec } from "./Vec.js";
7
7
 
@@ -24,8 +24,7 @@ export class VecFixed extends AbstractArray {
24
24
  } = {}) {
25
25
  super(registry, length);
26
26
  this.#Type = definition || setDefinition(typeToConstructor(registry, Type));
27
- const [, decodedLengthNoOffset] = isU8a(value) ? decodeU8aVec(registry, this, value, 0, this.#Type) : decodeVec(registry, this, value, 0, this.#Type);
28
- this.initialU8aLength = decodedLengthNoOffset;
27
+ this.initialU8aLength = (isU8a(value) ? decodeU8aVec(registry, this, value, 0, this.#Type) : decodeVec(registry, this, value, 0, this.#Type))[1];
29
28
  }
30
29
 
31
30
  static with(Type, length) {
package/base/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export { Base } from './Base';
2
1
  export { Compact } from './Compact';
3
2
  export { DoNotConstruct } from './DoNotConstruct';
4
3
  export { Enum } from './Enum';
package/base/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- export { Base } from "./Base.js";
4
3
  export { Compact } from "./Compact.js";
5
4
  export { DoNotConstruct } from "./DoNotConstruct.js";
6
5
  export { Enum } from "./Enum.js";
File without changes
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.Base = void 0;
6
+ exports.AbstractBase = void 0;
7
7
 
8
8
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
9
9
  // SPDX-License-Identifier: Apache-2.0
@@ -12,14 +12,13 @@ exports.Base = void 0;
12
12
  * @name Base
13
13
  * @description A type extends the Base class, when it holds a value
14
14
  */
15
- class Base {
16
- #registry;
15
+ class AbstractBase {
17
16
  #raw;
18
17
 
19
18
  constructor(registry, value, initialU8aLength) {
20
- this.#registry = registry;
21
19
  this.#raw = value;
22
20
  this.initialU8aLength = initialU8aLength;
21
+ this.registry = registry;
23
22
  }
24
23
  /**
25
24
  * @description The length of the value when encoded as a Uint8Array
@@ -49,10 +48,6 @@ class Base {
49
48
  get isEmpty() {
50
49
  return this.#raw.isEmpty;
51
50
  }
52
-
53
- get registry() {
54
- return this.#registry;
55
- }
56
51
  /**
57
52
  * @description Compares the value of the input to see if there is a match
58
53
  */
@@ -125,4 +120,4 @@ class Base {
125
120
 
126
121
  }
127
122
 
128
- exports.Base = Base;
123
+ exports.AbstractBase = AbstractBase;
@@ -52,24 +52,25 @@ function decodeAbstractInt(value, isNegative) {
52
52
 
53
53
  class AbstractInt extends _util.BN {
54
54
  #bitLength;
55
- #isSigned;
56
55
 
57
56
  constructor(registry) {
58
57
  let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
59
58
  let bitLength = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_UINT_BITS;
60
59
  let isSigned = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
61
- // Construct via a string, which will be passed in the BN constructor.
60
+ // Construct via a string/number, which will be passed in the BN constructor.
62
61
  // It would be ideal to actually return a BN, but there is an issue:
63
62
  // https://github.com/indutny/bn.js/issues/206
64
63
  super( // shortcut isU8a as used in SCALE decoding
65
- (0, _util.isU8a)(value) ? (0, _util.u8aToBn)(value.subarray(0, bitLength / 8), {
64
+ (0, _util.isU8a)(value) ? bitLength <= 48 ? (0, _util.u8aToNumber)(value.subarray(0, bitLength / 8), {
65
+ isNegative: isSigned
66
+ }) : (0, _util.u8aToBn)(value.subarray(0, bitLength / 8), {
66
67
  isLe: true,
67
68
  isNegative: isSigned
68
69
  }).toString() : decodeAbstractInt(value, isSigned));
69
70
  this.registry = registry;
70
71
  this.#bitLength = bitLength;
71
72
  this.encodedLength = this.#bitLength / 8;
72
- this.#isSigned = isSigned;
73
+ this.isUnsigned = !isSigned;
73
74
  const isPositive = this.gte(_util.BN_ZERO);
74
75
  const maxBits = bitLength - (isSigned && isPositive ? 1 : 0);
75
76
  (0, _util.assert)(isSigned || isPositive, () => `${this.toRawType()}: Negative number passed to unsigned type`);
@@ -91,14 +92,6 @@ class AbstractInt extends _util.BN {
91
92
  get isEmpty() {
92
93
  return this.isZero();
93
94
  }
94
- /**
95
- * @description Checks if the value is an unsigned type
96
- */
97
-
98
-
99
- get isUnsigned() {
100
- return !this.#isSigned;
101
- }
102
95
  /**
103
96
  * @description Returns the number of bits in the value
104
97
  */
@@ -118,7 +111,7 @@ class AbstractInt extends _util.BN {
118
111
  // number and BN inputs (no `.eqn` needed) - numbers will be converted
119
112
  return super.eq((0, _util.isHex)(other) ? (0, _util.hexToBn)(other.toString(), {
120
113
  isLe: false,
121
- isNegative: this.#isSigned
114
+ isNegative: !this.isUnsigned
122
115
  }) : (0, _util.bnToBn)(other));
123
116
  }
124
117
  /**