@polkadot/types-codec 8.8.3-1 → 8.8.3-12

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 (84) 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} +23 -20
  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 +23 -10
  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 +6 -12
  18. package/base/Result.js +8 -3
  19. package/base/Tuple.d.ts +1 -1
  20. package/base/Tuple.js +3 -4
  21. package/base/UInt.d.ts +1 -1
  22. package/base/UInt.js +1 -1
  23. package/base/Vec.d.ts +1 -1
  24. package/base/Vec.js +8 -5
  25. package/base/VecAny.d.ts +1 -1
  26. package/base/VecAny.js +1 -1
  27. package/base/VecFixed.d.ts +1 -1
  28. package/base/VecFixed.js +2 -3
  29. package/base/index.d.ts +0 -1
  30. package/base/index.js +0 -1
  31. package/cjs/abstract/{AbstractArray.js → Array.js} +0 -0
  32. package/cjs/{base → abstract}/Base.js +4 -9
  33. package/cjs/abstract/{AbstractInt.js → Int.js} +22 -19
  34. package/cjs/abstract/index.js +12 -4
  35. package/cjs/base/Compact.js +15 -16
  36. package/cjs/base/Enum.js +22 -9
  37. package/cjs/base/Int.js +2 -2
  38. package/cjs/base/Null.js +2 -16
  39. package/cjs/base/Option.js +5 -11
  40. package/cjs/base/Result.js +8 -4
  41. package/cjs/base/Tuple.js +4 -5
  42. package/cjs/base/UInt.js +2 -2
  43. package/cjs/base/Vec.js +8 -5
  44. package/cjs/base/VecAny.js +2 -2
  45. package/cjs/base/VecFixed.js +3 -4
  46. package/cjs/base/index.js +0 -8
  47. package/cjs/extended/BitVec.js +5 -1
  48. package/cjs/extended/Bytes.js +8 -3
  49. package/cjs/extended/Map.js +2 -2
  50. package/cjs/extended/OptionBool.js +1 -8
  51. package/cjs/extended/U8aFixed.js +4 -1
  52. package/cjs/extended/WrapperKeepOpaque.js +5 -1
  53. package/cjs/native/Raw.js +4 -1
  54. package/cjs/native/Set.js +19 -4
  55. package/cjs/native/Struct.js +9 -9
  56. package/cjs/native/Text.js +8 -12
  57. package/cjs/packageInfo.js +1 -1
  58. package/cjs/utils/decodeU8a.js +63 -20
  59. package/cjs/utils/index.js +6 -0
  60. package/cjs/utils/mapToTypeMap.js +1 -1
  61. package/cjs/utils/sanitize.js +17 -37
  62. package/extended/BitVec.js +6 -2
  63. package/extended/Bytes.js +9 -4
  64. package/extended/Map.js +1 -1
  65. package/extended/OptionBool.d.ts +0 -4
  66. package/extended/OptionBool.js +1 -8
  67. package/extended/U8aFixed.js +5 -2
  68. package/extended/WrapperKeepOpaque.js +6 -2
  69. package/native/Raw.d.ts +1 -1
  70. package/native/Raw.js +5 -2
  71. package/native/Set.js +19 -5
  72. package/native/Struct.d.ts +1 -1
  73. package/native/Struct.js +11 -11
  74. package/native/Text.d.ts +2 -5
  75. package/native/Text.js +9 -13
  76. package/package.json +15 -15
  77. package/packageInfo.js +1 -1
  78. package/utils/decodeU8a.d.ts +16 -1
  79. package/utils/decodeU8a.js +57 -19
  80. package/utils/index.d.ts +1 -1
  81. package/utils/index.js +1 -1
  82. package/utils/mapToTypeMap.js +1 -1
  83. package/utils/sanitize.d.ts +3 -5
  84. package/utils/sanitize.js +17 -37
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;
@@ -25,7 +25,10 @@ function toPercentage(value, divisor) {
25
25
 
26
26
  function decodeAbstractInt(value, isNegative) {
27
27
  if ((0, _util.isNumber)(value)) {
28
- (0, _util.assert)(value <= Number.MAX_SAFE_INTEGER && value >= Number.MIN_SAFE_INTEGER && Number.isInteger(value), 'Number needs to be an integer <= Number.MAX_SAFE_INTEGER, i.e. 2 ^ 53 - 1');
28
+ if (!Number.isInteger(value) || value > Number.MAX_SAFE_INTEGER || value < Number.MIN_SAFE_INTEGER) {
29
+ throw new Error('Number needs to be an integer <= Number.MAX_SAFE_INTEGER, i.e. 2 ^ 53 - 1');
30
+ }
31
+
29
32
  return value;
30
33
  } else if ((0, _util.isString)(value)) {
31
34
  if ((0, _util.isHex)(value, -1, true)) {
@@ -35,7 +38,10 @@ function decodeAbstractInt(value, isNegative) {
35
38
  }).toString();
36
39
  }
37
40
 
38
- (0, _util.assert)(!(value.includes('.') || value.includes(',') || value.includes('e')), 'String should not contain decimal points or scientific notation');
41
+ if (value.includes('.') || value.includes(',') || value.includes('e')) {
42
+ throw new Error('String should not contain decimal points or scientific notation');
43
+ }
44
+
39
45
  return value;
40
46
  } else if ((0, _util.isBn)(value)) {
41
47
  return value.toString();
@@ -52,28 +58,33 @@ function decodeAbstractInt(value, isNegative) {
52
58
 
53
59
  class AbstractInt extends _util.BN {
54
60
  #bitLength;
55
- #isSigned;
56
61
 
57
62
  constructor(registry) {
58
63
  let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
59
64
  let bitLength = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_UINT_BITS;
60
65
  let isSigned = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
61
- // Construct via a string, which will be passed in the BN constructor.
66
+ // Construct via a string/number, which will be passed in the BN constructor.
62
67
  // It would be ideal to actually return a BN, but there is an issue:
63
68
  // https://github.com/indutny/bn.js/issues/206
64
69
  super( // shortcut isU8a as used in SCALE decoding
65
- (0, _util.isU8a)(value) ? (0, _util.u8aToBn)(value.subarray(0, bitLength / 8), {
70
+ (0, _util.isU8a)(value) ? bitLength <= 48 ? (0, _util.u8aToNumber)(value.subarray(0, bitLength / 8), {
71
+ isNegative: isSigned
72
+ }) : (0, _util.u8aToBn)(value.subarray(0, bitLength / 8), {
66
73
  isLe: true,
67
74
  isNegative: isSigned
68
75
  }).toString() : decodeAbstractInt(value, isSigned));
69
76
  this.registry = registry;
70
77
  this.#bitLength = bitLength;
71
78
  this.encodedLength = this.#bitLength / 8;
72
- this.#isSigned = isSigned;
73
- const isPositive = this.gte(_util.BN_ZERO);
74
- const maxBits = bitLength - (isSigned && isPositive ? 1 : 0);
75
- (0, _util.assert)(isSigned || isPositive, () => `${this.toRawType()}: Negative number passed to unsigned type`);
76
- (0, _util.assert)(super.bitLength() <= maxBits, () => `${this.toRawType()}: Input too large. Found input with ${super.bitLength()} bits, expected ${maxBits}`);
79
+ this.isUnsigned = !isSigned;
80
+ const isNegative = this.isNeg();
81
+ const maxBits = bitLength - (isSigned && !isNegative ? 1 : 0);
82
+
83
+ if (isNegative && !isSigned) {
84
+ throw new Error(`${this.toRawType()}: Negative number passed to unsigned type`);
85
+ } else if (super.bitLength() > maxBits) {
86
+ throw new Error(`${this.toRawType()}: Input too large. Found input with ${super.bitLength()} bits, expected ${maxBits}`);
87
+ }
77
88
  }
78
89
  /**
79
90
  * @description returns a hash of the contents
@@ -91,14 +102,6 @@ class AbstractInt extends _util.BN {
91
102
  get isEmpty() {
92
103
  return this.isZero();
93
104
  }
94
- /**
95
- * @description Checks if the value is an unsigned type
96
- */
97
-
98
-
99
- get isUnsigned() {
100
- return !this.#isSigned;
101
- }
102
105
  /**
103
106
  * @description Returns the number of bits in the value
104
107
  */
@@ -118,7 +121,7 @@ class AbstractInt extends _util.BN {
118
121
  // number and BN inputs (no `.eqn` needed) - numbers will be converted
119
122
  return super.eq((0, _util.isHex)(other) ? (0, _util.hexToBn)(other.toString(), {
120
123
  isLe: false,
121
- isNegative: this.#isSigned
124
+ isNegative: !this.isUnsigned
122
125
  }) : (0, _util.bnToBn)(other));
123
126
  }
124
127
  /**
@@ -6,16 +6,24 @@ Object.defineProperty(exports, "__esModule", {
6
6
  Object.defineProperty(exports, "AbstractArray", {
7
7
  enumerable: true,
8
8
  get: function () {
9
- return _AbstractArray.AbstractArray;
9
+ return _Array.AbstractArray;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "AbstractBase", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _Base.AbstractBase;
10
16
  }
11
17
  });
12
18
  Object.defineProperty(exports, "AbstractInt", {
13
19
  enumerable: true,
14
20
  get: function () {
15
- return _AbstractInt.AbstractInt;
21
+ return _Int.AbstractInt;
16
22
  }
17
23
  });
18
24
 
19
- var _AbstractArray = require("./AbstractArray");
25
+ var _Array = require("./Array");
26
+
27
+ var _Base = require("./Base");
20
28
 
21
- var _AbstractInt = require("./AbstractInt");
29
+ var _Int = require("./Int");
@@ -14,6 +14,20 @@ var _utils = require("../utils");
14
14
  function noopSetDefinition(d) {
15
15
  return d;
16
16
  }
17
+
18
+ function decodeCompact(registry, Type, value) {
19
+ if ((0, _util.isU8a)(value)) {
20
+ const [decodedLength, bn] = (value[0] & 0b11) < 0b11 ? (0, _util.compactFromU8aLim)(value) : (0, _util.compactFromU8a)(value);
21
+ return [new Type(registry, bn), decodedLength];
22
+ } else if (value instanceof Compact) {
23
+ const raw = value.unwrap();
24
+ return raw instanceof Type ? [raw, 0] : [new Type(registry, raw), 0];
25
+ } else if (value instanceof Type) {
26
+ return [value, 0];
27
+ }
28
+
29
+ return [new Type(registry, value), 0];
30
+ }
17
31
  /**
18
32
  * @name Compact
19
33
  * @description
@@ -36,7 +50,7 @@ class Compact {
36
50
  } = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
37
51
  this.registry = registry;
38
52
  this.#Type = definition || setDefinition((0, _utils.typeToConstructor)(registry, Type));
39
- const [raw, decodedLength] = Compact.decodeCompact(registry, this.#Type, value);
53
+ const [raw, decodedLength] = decodeCompact(registry, this.#Type, value);
40
54
  this.initialU8aLength = decodedLength;
41
55
  this.#raw = raw;
42
56
  }
@@ -56,21 +70,6 @@ class Compact {
56
70
 
57
71
  };
58
72
  }
59
- /** @internal */
60
-
61
-
62
- static decodeCompact(registry, Type, value) {
63
- if ((0, _util.isU8a)(value)) {
64
- const [decodedLength, bn] = (value[0] & 0b11) < 0b11 ? (0, _util.compactFromU8aLim)(value) : (0, _util.compactFromU8a)(value);
65
- return [new Type(registry, bn), decodedLength];
66
- } else if (value instanceof Compact) {
67
- return value.#raw instanceof Type ? [value.#raw, 0] : [new Type(registry, value.#raw), 0];
68
- } else if (value instanceof Type) {
69
- return [value, 0];
70
- }
71
-
72
- return [new Type(registry, value), 0];
73
- }
74
73
  /**
75
74
  * @description The length of the value when encoded as a Uint8Array
76
75
  */
package/cjs/base/Enum.js CHANGED
@@ -21,7 +21,10 @@ function isRustEnum(def) {
21
21
  const defValues = Object.values(def);
22
22
 
23
23
  if (defValues.some(v => (0, _util.isNumber)(v))) {
24
- (0, _util.assert)(defValues.every(v => (0, _util.isNumber)(v) && v >= 0 && v <= 255), 'Invalid number-indexed enum definition');
24
+ if (!defValues.every(v => (0, _util.isNumber)(v) && v >= 0 && v <= 255)) {
25
+ throw new Error('Invalid number-indexed enum definition');
26
+ }
27
+
25
28
  return false;
26
29
  }
27
30
 
@@ -86,10 +89,14 @@ function createFromValue(registry, def) {
86
89
  let index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
87
90
  let value = arguments.length > 3 ? arguments[3] : undefined;
88
91
  const entry = Object.values(def).find(e => e.index === index);
89
- (0, _util.assert)(!(0, _util.isUndefined)(entry), () => `Unable to create Enum via index ${index}, in ${Object.keys(def).join(', ')}`);
92
+
93
+ if ((0, _util.isUndefined)(entry)) {
94
+ throw new Error(`Unable to create Enum via index ${index}, in ${Object.keys(def).join(', ')}`);
95
+ }
96
+
90
97
  return {
91
98
  index,
92
- value: (0, _util.isCodec)(value) && value instanceof entry.Type ? value : new entry.Type(registry, value)
99
+ value: value instanceof entry.Type ? value : new entry.Type(registry, value)
93
100
  };
94
101
  }
95
102
 
@@ -99,7 +106,10 @@ function decodeFromJSON(registry, def, key, value) {
99
106
  const keys = Object.keys(def).map(k => k.toLowerCase());
100
107
  const keyLower = key.toLowerCase();
101
108
  const index = keys.indexOf(keyLower);
102
- (0, _util.assert)(index !== -1, () => `Cannot map Enum JSON, unable to find '${key}' in ${keys.join(', ')}`);
109
+
110
+ if (index === -1) {
111
+ throw new Error(`Cannot map Enum JSON, unable to find '${key}' in ${keys.join(', ')}`);
112
+ }
103
113
 
104
114
  try {
105
115
  return createFromValue(registry, def, Object.values(def)[index].index, value);
@@ -171,7 +181,7 @@ class Enum {
171
181
  } = _ref2;
172
182
  return index;
173
183
  });
174
- this.#entryIndex = this.#indexes.indexOf(decoded.index) || 0;
184
+ this.#entryIndex = this.#indexes.indexOf(decoded.index);
175
185
  this.#raw = decoded.value;
176
186
 
177
187
  if (this.#raw.initialU8aLength) {
@@ -185,7 +195,7 @@ class Enum {
185
195
  const isKeys = new Array(keys.length);
186
196
 
187
197
  for (let i = 0; i < keys.length; i++) {
188
- const name = (0, _util.stringPascalCase)(keys[i].replace(' ', '_'));
198
+ const name = (0, _util.stringPascalCase)(keys[i]);
189
199
  asKeys[i] = `as${name}`;
190
200
  isKeys[i] = `is${name}`;
191
201
  }
@@ -202,7 +212,10 @@ class Enum {
202
212
  });
203
213
  (0, _util.objectProperties)(this, isKeys, (_, i) => this.type === keys[i]);
204
214
  (0, _util.objectProperties)(this, asKeys, (k, i) => {
205
- (0, _util.assert)(this[isKeys[i]], () => `Cannot convert '${this.type}' via ${k}`);
215
+ if (!this[isKeys[i]]) {
216
+ throw new Error(`Cannot convert '${this.type}' via ${k}`);
217
+ }
218
+
206
219
  return this.value;
207
220
  });
208
221
  }
@@ -321,7 +334,7 @@ class Enum {
321
334
  return this.type === other;
322
335
  } else if ((0, _util.isHex)(other)) {
323
336
  return this.toHex() === other;
324
- } else if ((0, _util.isCodec)(other) && other instanceof Enum) {
337
+ } else if (other instanceof Enum) {
325
338
  return this.index === other.index && this.value.eq(other.value);
326
339
  } else if ((0, _util.isObject)(other)) {
327
340
  return this.value.eq(other[this.type]);
@@ -336,7 +349,7 @@ class Enum {
336
349
 
337
350
 
338
351
  inspect() {
339
- if (this.isBasic) {
352
+ if (this.#isBasic) {
340
353
  return {
341
354
  outer: [new Uint8Array([this.index])]
342
355
  };
package/cjs/base/Int.js CHANGED
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.Int = void 0;
7
7
 
8
- var _AbstractInt = require("../abstract/AbstractInt");
8
+ var _Int = require("../abstract/Int");
9
9
 
10
10
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
11
11
  // SPDX-License-Identifier: Apache-2.0
@@ -20,7 +20,7 @@ var _AbstractInt = require("../abstract/AbstractInt");
20
20
  * is available here.
21
21
  * @noInheritDoc
22
22
  */
23
- class Int extends _AbstractInt.AbstractInt {
23
+ class Int extends _Int.AbstractInt {
24
24
  constructor(registry) {
25
25
  let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
26
26
  let bitLength = arguments.length > 2 ? arguments[2] : undefined;
package/cjs/base/Null.js CHANGED
@@ -16,20 +16,14 @@ var _util = require("@polkadot/util");
16
16
  * Implements a type that does not contain anything (apart from `null`)
17
17
  */
18
18
  class Null {
19
+ encodedLength = 0;
20
+ isEmpty = true;
19
21
  // Added for compatibility reasons, e.g. see Option
20
22
  initialU8aLength = 0;
21
23
 
22
24
  constructor(registry) {
23
25
  this.registry = registry;
24
26
  }
25
- /**
26
- * @description The length of the value when encoded as a Uint8Array
27
- */
28
-
29
-
30
- get encodedLength() {
31
- return 0;
32
- }
33
27
  /**
34
28
  * @description returns a hash of the contents
35
29
  */
@@ -38,14 +32,6 @@ class Null {
38
32
  get hash() {
39
33
  throw new Error('.hash is not implemented on Null');
40
34
  }
41
- /**
42
- * @description Checks if the value is an empty value (always true)
43
- */
44
-
45
-
46
- get isEmpty() {
47
- return true;
48
- }
49
35
  /**
50
36
  * @description Compares the value of the input to see if there is a match
51
37
  */
@@ -67,7 +67,6 @@ function decodeOption(registry, Type, value) {
67
67
 
68
68
  class Option {
69
69
  #Type;
70
- #initialU8aLength;
71
70
  #raw;
72
71
 
73
72
  constructor(registry, typeName, value) {
@@ -82,7 +81,7 @@ class Option {
82
81
  this.#raw = decoded;
83
82
 
84
83
  if (decoded && decoded.initialU8aLength) {
85
- this.#initialU8aLength = 1 + decoded.initialU8aLength;
84
+ this.initialU8aLength = 1 + decoded.initialU8aLength;
86
85
  }
87
86
  }
88
87
 
@@ -113,14 +112,6 @@ class Option {
113
112
  // boolean byte (has value, doesn't have) along with wrapped length
114
113
  return 1 + this.#raw.encodedLength;
115
114
  }
116
- /**
117
- * @description The length of the initial encoded value (Only available when constructed from a Uint8Array)
118
- */
119
-
120
-
121
- get initialU8aLength() {
122
- return this.#initialU8aLength;
123
- }
124
115
  /**
125
116
  * @description returns a hash of the contents
126
117
  */
@@ -263,7 +254,10 @@ class Option {
263
254
 
264
255
 
265
256
  unwrap() {
266
- (0, _util.assert)(this.isSome, 'Option: unwrapping a None value');
257
+ if (this.isNone) {
258
+ throw new Error('Option: unwrapping a None value');
259
+ }
260
+
267
261
  return this.#raw;
268
262
  }
269
263
  /**
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.Result = void 0;
7
7
 
8
- var _util = require("@polkadot/util");
9
-
10
8
  var _Enum = require("./Enum");
11
9
 
12
10
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
@@ -41,7 +39,10 @@ class Result extends _Enum.Enum {
41
39
 
42
40
 
43
41
  get asErr() {
44
- (0, _util.assert)(this.isErr, 'Cannot extract Err value from Ok result, check isErr first');
42
+ if (!this.isErr) {
43
+ throw new Error('Cannot extract Err value from Ok result, check isErr first');
44
+ }
45
+
45
46
  return this.value;
46
47
  }
47
48
  /**
@@ -58,7 +59,10 @@ class Result extends _Enum.Enum {
58
59
 
59
60
 
60
61
  get asOk() {
61
- (0, _util.assert)(this.isOk, 'Cannot extract Ok value from Err result, check isOk first');
62
+ if (!this.isOk) {
63
+ throw new Error('Cannot extract Ok value from Err result, check isOk first');
64
+ }
65
+
62
66
  return this.value;
63
67
  }
64
68
  /**
package/cjs/base/Tuple.js CHANGED
@@ -7,7 +7,7 @@ exports.Tuple = void 0;
7
7
 
8
8
  var _util = require("@polkadot/util");
9
9
 
10
- var _AbstractArray = require("../abstract/AbstractArray");
10
+ var _Array = require("../abstract/Array");
11
11
 
12
12
  var _utils = require("../utils");
13
13
 
@@ -19,7 +19,7 @@ function noopSetDefinition(d) {
19
19
  /** @internal */
20
20
 
21
21
 
22
- function decodeTuple(registry, result, Classes, value) {
22
+ function decodeTuple(registry, result, value, Classes) {
23
23
  if ((0, _util.isU8a)(value) || (0, _util.isHex)(value)) {
24
24
  return (0, _utils.decodeU8a)(registry, result, (0, _util.u8aToU8a)(value), Classes);
25
25
  }
@@ -45,7 +45,7 @@ function decodeTuple(registry, result, Classes, value) {
45
45
  */
46
46
 
47
47
 
48
- class Tuple extends _AbstractArray.AbstractArray {
48
+ class Tuple extends _Array.AbstractArray {
49
49
  #Types;
50
50
 
51
51
  constructor(registry, Types, value) {
@@ -55,8 +55,7 @@ class Tuple extends _AbstractArray.AbstractArray {
55
55
  } = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
56
56
  const Classes = definition || setDefinition(Array.isArray(Types) ? [Types.map(t => (0, _utils.typeToConstructor)(registry, t)), []] : (0, _util.isFunction)(Types) || (0, _util.isString)(Types) ? [[(0, _utils.typeToConstructor)(registry, Types)], []] : (0, _utils.mapToTypeMap)(registry, Types));
57
57
  super(registry, Classes[0].length);
58
- const [, decodedLength] = (0, _util.isU8a)(value) ? (0, _utils.decodeU8a)(registry, this, value, Classes, false) : decodeTuple(registry, this, Classes, value);
59
- this.initialU8aLength = decodedLength;
58
+ this.initialU8aLength = ((0, _util.isU8a)(value) ? (0, _utils.decodeU8a)(registry, this, value, Classes) : decodeTuple(registry, this, value, Classes))[1];
60
59
  this.#Types = Classes;
61
60
  }
62
61
 
package/cjs/base/UInt.js CHANGED
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.UInt = void 0;
7
7
 
8
- var _AbstractInt = require("../abstract/AbstractInt");
8
+ var _Int = require("../abstract/Int");
9
9
 
10
10
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
11
11
  // SPDX-License-Identifier: Apache-2.0
@@ -20,7 +20,7 @@ var _AbstractInt = require("../abstract/AbstractInt");
20
20
  * is available here.
21
21
  * @noInheritDoc
22
22
  */
23
- class UInt extends _AbstractInt.AbstractInt {
23
+ class UInt extends _Int.AbstractInt {
24
24
  static with(bitLength, typeName) {
25
25
  return class extends UInt {
26
26
  constructor(registry, value) {
package/cjs/base/Vec.js CHANGED
@@ -8,7 +8,7 @@ exports.decodeVec = decodeVec;
8
8
 
9
9
  var _util = require("@polkadot/util");
10
10
 
11
- var _AbstractArray = require("../abstract/AbstractArray");
11
+ var _Array = require("../abstract/Array");
12
12
 
13
13
  var _utils = require("../utils");
14
14
 
@@ -28,7 +28,11 @@ function decodeVecLength(value) {
28
28
 
29
29
  const u8a = (0, _util.u8aToU8a)(value);
30
30
  const [startAt, length] = (0, _util.compactFromU8aLim)(u8a);
31
- (0, _util.assert)(length <= MAX_LENGTH, () => `Vec length ${length.toString()} exceeds ${MAX_LENGTH}`);
31
+
32
+ if (length > MAX_LENGTH) {
33
+ throw new Error(`Vec length ${length.toString()} exceeds ${MAX_LENGTH}`);
34
+ }
35
+
32
36
  return [u8a, length, startAt];
33
37
  }
34
38
 
@@ -61,7 +65,7 @@ function decodeVec(registry, result, value, startAt, Type) {
61
65
  */
62
66
 
63
67
 
64
- class Vec extends _AbstractArray.AbstractArray {
68
+ class Vec extends _Array.AbstractArray {
65
69
  #Type;
66
70
 
67
71
  constructor(registry, Type) {
@@ -73,8 +77,7 @@ class Vec extends _AbstractArray.AbstractArray {
73
77
  const [decodeFrom, length, startAt] = decodeVecLength(value);
74
78
  super(registry, length);
75
79
  this.#Type = definition || setDefinition((0, _utils.typeToConstructor)(registry, Type));
76
- const [decodedLength] = (0, _util.isU8a)(decodeFrom) ? (0, _utils.decodeU8aVec)(registry, this, decodeFrom, startAt, this.#Type) : decodeVec(registry, this, decodeFrom, startAt, this.#Type);
77
- this.initialU8aLength = decodedLength;
80
+ this.initialU8aLength = ((0, _util.isU8a)(decodeFrom) ? (0, _utils.decodeU8aVec)(registry, this, decodeFrom, startAt, this.#Type) : decodeVec(registry, this, decodeFrom, startAt, this.#Type))[0];
78
81
  }
79
82
 
80
83
  static with(Type) {
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.VecAny = void 0;
7
7
 
8
- var _AbstractArray = require("../abstract/AbstractArray");
8
+ var _Array = require("../abstract/Array");
9
9
 
10
10
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
11
11
  // SPDX-License-Identifier: Apache-2.0
@@ -17,7 +17,7 @@ var _AbstractArray = require("../abstract/AbstractArray");
17
17
  * a vector, this can be used to manage array-like structures with variable arguments of
18
18
  * any types
19
19
  */
20
- class VecAny extends _AbstractArray.AbstractArray {
20
+ class VecAny extends _Array.AbstractArray {
21
21
  /**
22
22
  * @description Returns the base runtime type name for this instance
23
23
  */
@@ -7,7 +7,7 @@ exports.VecFixed = void 0;
7
7
 
8
8
  var _util = require("@polkadot/util");
9
9
 
10
- var _AbstractArray = require("../abstract/AbstractArray");
10
+ var _Array = require("../abstract/Array");
11
11
 
12
12
  var _utils = require("../utils");
13
13
 
@@ -25,7 +25,7 @@ function noopSetDefinition(d) {
25
25
  */
26
26
 
27
27
 
28
- class VecFixed extends _AbstractArray.AbstractArray {
28
+ class VecFixed extends _Array.AbstractArray {
29
29
  #Type;
30
30
 
31
31
  constructor(registry, Type, length) {
@@ -36,8 +36,7 @@ class VecFixed extends _AbstractArray.AbstractArray {
36
36
  } = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
37
37
  super(registry, length);
38
38
  this.#Type = definition || setDefinition((0, _utils.typeToConstructor)(registry, Type));
39
- const [, decodedLengthNoOffset] = (0, _util.isU8a)(value) ? (0, _utils.decodeU8aVec)(registry, this, value, 0, this.#Type) : (0, _Vec.decodeVec)(registry, this, value, 0, this.#Type);
40
- this.initialU8aLength = decodedLengthNoOffset;
39
+ this.initialU8aLength = ((0, _util.isU8a)(value) ? (0, _utils.decodeU8aVec)(registry, this, value, 0, this.#Type) : (0, _Vec.decodeVec)(registry, this, value, 0, this.#Type))[1];
41
40
  }
42
41
 
43
42
  static with(Type, length) {
package/cjs/base/index.js CHANGED
@@ -3,12 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "Base", {
7
- enumerable: true,
8
- get: function () {
9
- return _Base.Base;
10
- }
11
- });
12
6
  Object.defineProperty(exports, "Compact", {
13
7
  enumerable: true,
14
8
  get: function () {
@@ -82,8 +76,6 @@ Object.defineProperty(exports, "VecFixed", {
82
76
  }
83
77
  });
84
78
 
85
- var _Base = require("./Base");
86
-
87
79
  var _Compact = require("./Compact");
88
80
 
89
81
  var _DoNotConstruct = require("./DoNotConstruct");
@@ -21,7 +21,11 @@ function decodeBitVecU8a(value) {
21
21
 
22
22
  const [offset, length] = (0, _util.compactFromU8aLim)(value);
23
23
  const total = offset + Math.ceil(length / 8);
24
- (0, _util.assert)(total <= value.length, () => `BitVec: required length less than remainder, expected at least ${total}, found ${value.length}`);
24
+
25
+ if (total > value.length) {
26
+ throw new Error(`BitVec: required length less than remainder, expected at least ${total}, found ${value.length}`);
27
+ }
28
+
25
29
  return [length, value.subarray(offset, total)];
26
30
  }
27
31
  /** @internal */