@polkadot/types-codec 6.12.2-10

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 (214) hide show
  1. package/abstract/AbstractArray.cjs +208 -0
  2. package/abstract/AbstractArray.d.ts +84 -0
  3. package/abstract/AbstractArray.js +197 -0
  4. package/abstract/AbstractInt.cjs +254 -0
  5. package/abstract/AbstractInt.d.ts +75 -0
  6. package/abstract/AbstractInt.js +231 -0
  7. package/abstract/index.cjs +21 -0
  8. package/abstract/index.d.ts +2 -0
  9. package/abstract/index.js +4 -0
  10. package/base/Base.cjs +137 -0
  11. package/base/Base.d.ts +56 -0
  12. package/base/Base.js +125 -0
  13. package/base/Compact.cjs +201 -0
  14. package/base/Compact.d.ts +83 -0
  15. package/base/Compact.js +186 -0
  16. package/base/DoNotConstruct.cjs +101 -0
  17. package/base/DoNotConstruct.d.ts +33 -0
  18. package/base/DoNotConstruct.js +88 -0
  19. package/base/Enum.cjs +445 -0
  20. package/base/Enum.d.ts +105 -0
  21. package/base/Enum.js +421 -0
  22. package/base/Int.cjs +45 -0
  23. package/base/Int.d.ts +16 -0
  24. package/base/Int.js +33 -0
  25. package/base/Null.cjs +111 -0
  26. package/base/Null.d.ts +54 -0
  27. package/base/Null.js +101 -0
  28. package/base/Option.cjs +256 -0
  29. package/base/Option.d.ts +88 -0
  30. package/base/Option.js +240 -0
  31. package/base/Result.cjs +109 -0
  32. package/base/Result.d.ts +46 -0
  33. package/base/Result.js +98 -0
  34. package/base/Tuple.cjs +132 -0
  35. package/base/Tuple.d.ts +39 -0
  36. package/base/Tuple.js +116 -0
  37. package/base/UInt.cjs +39 -0
  38. package/base/UInt.d.ts +15 -0
  39. package/base/UInt.js +29 -0
  40. package/base/Vec.cjs +126 -0
  41. package/base/Vec.d.ts +28 -0
  42. package/base/Vec.js +104 -0
  43. package/base/VecAny.cjs +31 -0
  44. package/base/VecAny.d.ts +15 -0
  45. package/base/VecAny.js +21 -0
  46. package/base/VecFixed.cjs +111 -0
  47. package/base/VecFixed.d.ts +26 -0
  48. package/base/VecFixed.js +93 -0
  49. package/base/index.cjs +109 -0
  50. package/base/index.d.ts +13 -0
  51. package/base/index.js +15 -0
  52. package/bundle.cjs +100 -0
  53. package/bundle.d.ts +7 -0
  54. package/bundle.js +9 -0
  55. package/detectPackage.cjs +9 -0
  56. package/detectPackage.d.ts +1 -0
  57. package/detectPackage.js +5 -0
  58. package/extended/BTreeMap.cjs +24 -0
  59. package/extended/BTreeMap.d.ts +5 -0
  60. package/extended/BTreeMap.js +14 -0
  61. package/extended/BTreeSet.cjs +227 -0
  62. package/extended/BTreeSet.d.ts +55 -0
  63. package/extended/BTreeSet.js +212 -0
  64. package/extended/BitVec.cjs +97 -0
  65. package/extended/BitVec.d.ts +26 -0
  66. package/extended/BitVec.js +82 -0
  67. package/extended/Bytes.cjs +86 -0
  68. package/extended/Bytes.d.ts +25 -0
  69. package/extended/Bytes.js +75 -0
  70. package/extended/HashMap.cjs +24 -0
  71. package/extended/HashMap.d.ts +5 -0
  72. package/extended/HashMap.js +14 -0
  73. package/extended/Linkage.cjs +89 -0
  74. package/extended/Linkage.d.ts +31 -0
  75. package/extended/Linkage.js +71 -0
  76. package/extended/Map.cjs +244 -0
  77. package/extended/Map.d.ts +50 -0
  78. package/extended/Map.js +225 -0
  79. package/extended/Range.cjs +92 -0
  80. package/extended/Range.d.ts +30 -0
  81. package/extended/Range.js +75 -0
  82. package/extended/Type.cjs +39 -0
  83. package/extended/Type.d.ts +16 -0
  84. package/extended/Type.js +27 -0
  85. package/extended/U8aFixed.cjs +66 -0
  86. package/extended/U8aFixed.d.ts +16 -0
  87. package/extended/U8aFixed.js +53 -0
  88. package/extended/WrapperOpaque.cjs +60 -0
  89. package/extended/WrapperOpaque.d.ts +14 -0
  90. package/extended/WrapperOpaque.js +49 -0
  91. package/extended/index.cjs +105 -0
  92. package/extended/index.d.ts +11 -0
  93. package/extended/index.js +13 -0
  94. package/index.cjs +20 -0
  95. package/index.d.ts +2 -0
  96. package/index.js +4 -0
  97. package/native/Bool.cjs +141 -0
  98. package/native/Bool.d.ts +62 -0
  99. package/native/Bool.js +130 -0
  100. package/native/Date.cjs +170 -0
  101. package/native/Date.d.ts +76 -0
  102. package/native/Date.js +158 -0
  103. package/native/Json.cjs +137 -0
  104. package/native/Json.d.ts +56 -0
  105. package/native/Json.js +121 -0
  106. package/native/Raw.cjs +192 -0
  107. package/native/Raw.d.ts +90 -0
  108. package/native/Raw.js +182 -0
  109. package/native/Set.cjs +268 -0
  110. package/native/Set.d.ts +76 -0
  111. package/native/Set.js +251 -0
  112. package/native/Struct.cjs +302 -0
  113. package/native/Struct.d.ts +93 -0
  114. package/native/Struct.js +286 -0
  115. package/native/Text.cjs +193 -0
  116. package/native/Text.d.ts +71 -0
  117. package/native/Text.js +178 -0
  118. package/native/index.cjs +79 -0
  119. package/native/index.d.ts +7 -0
  120. package/native/index.js +9 -0
  121. package/package.json +387 -0
  122. package/packageInfo.cjs +14 -0
  123. package/packageInfo.d.ts +4 -0
  124. package/packageInfo.js +7 -0
  125. package/primitive/I128.cjs +26 -0
  126. package/primitive/I128.d.ts +11 -0
  127. package/primitive/I128.js +16 -0
  128. package/primitive/I16.cjs +26 -0
  129. package/primitive/I16.d.ts +11 -0
  130. package/primitive/I16.js +16 -0
  131. package/primitive/I256.cjs +26 -0
  132. package/primitive/I256.d.ts +11 -0
  133. package/primitive/I256.js +16 -0
  134. package/primitive/I32.cjs +26 -0
  135. package/primitive/I32.d.ts +11 -0
  136. package/primitive/I32.js +16 -0
  137. package/primitive/I64.cjs +26 -0
  138. package/primitive/I64.d.ts +11 -0
  139. package/primitive/I64.js +16 -0
  140. package/primitive/I8.cjs +26 -0
  141. package/primitive/I8.d.ts +11 -0
  142. package/primitive/I8.js +16 -0
  143. package/primitive/U128.cjs +26 -0
  144. package/primitive/U128.d.ts +11 -0
  145. package/primitive/U128.js +16 -0
  146. package/primitive/U16.cjs +26 -0
  147. package/primitive/U16.d.ts +11 -0
  148. package/primitive/U16.js +16 -0
  149. package/primitive/U256.cjs +26 -0
  150. package/primitive/U256.d.ts +11 -0
  151. package/primitive/U256.js +16 -0
  152. package/primitive/U32.cjs +26 -0
  153. package/primitive/U32.d.ts +11 -0
  154. package/primitive/U32.js +16 -0
  155. package/primitive/U64.cjs +26 -0
  156. package/primitive/U64.d.ts +11 -0
  157. package/primitive/U64.js +16 -0
  158. package/primitive/U8.cjs +26 -0
  159. package/primitive/U8.d.ts +11 -0
  160. package/primitive/U8.js +16 -0
  161. package/primitive/USize.cjs +28 -0
  162. package/primitive/USize.d.ts +12 -0
  163. package/primitive/USize.js +18 -0
  164. package/primitive/index.cjs +187 -0
  165. package/primitive/index.d.ts +13 -0
  166. package/primitive/index.js +15 -0
  167. package/types/codec.cjs +1 -0
  168. package/types/codec.d.ts +77 -0
  169. package/types/codec.js +1 -0
  170. package/types/helpers.cjs +1 -0
  171. package/types/helpers.d.ts +14 -0
  172. package/types/helpers.js +1 -0
  173. package/types/index.cjs +57 -0
  174. package/types/index.d.ts +4 -0
  175. package/types/index.js +6 -0
  176. package/types/interfaces.cjs +1 -0
  177. package/types/interfaces.d.ts +69 -0
  178. package/types/interfaces.js +1 -0
  179. package/types/registry.cjs +1 -0
  180. package/types/registry.d.ts +61 -0
  181. package/types/registry.js +1 -0
  182. package/utils/compareArray.cjs +22 -0
  183. package/utils/compareArray.d.ts +1 -0
  184. package/utils/compareArray.js +13 -0
  185. package/utils/compareMap.cjs +39 -0
  186. package/utils/compareMap.d.ts +1 -0
  187. package/utils/compareMap.js +31 -0
  188. package/utils/compareSet.cjs +29 -0
  189. package/utils/compareSet.d.ts +1 -0
  190. package/utils/compareSet.js +22 -0
  191. package/utils/decodeU8a.cjs +69 -0
  192. package/utils/decodeU8a.d.ts +13 -0
  193. package/utils/decodeU8a.js +60 -0
  194. package/utils/index.cjs +95 -0
  195. package/utils/index.d.ts +9 -0
  196. package/utils/index.js +11 -0
  197. package/utils/mapToTypeMap.cjs +25 -0
  198. package/utils/mapToTypeMap.d.ts +5 -0
  199. package/utils/mapToTypeMap.js +17 -0
  200. package/utils/sanitize.cjs +242 -0
  201. package/utils/sanitize.d.ts +16 -0
  202. package/utils/sanitize.js +215 -0
  203. package/utils/sortValues.cjs +89 -0
  204. package/utils/sortValues.d.ts +13 -0
  205. package/utils/sortValues.js +73 -0
  206. package/utils/typeToConstructor.cjs +14 -0
  207. package/utils/typeToConstructor.d.ts +2 -0
  208. package/utils/typeToConstructor.js +6 -0
  209. package/utils/typesToMap.cjs +20 -0
  210. package/utils/typesToMap.d.ts +2 -0
  211. package/utils/typesToMap.js +13 -0
  212. package/utils/util.cjs +15 -0
  213. package/utils/util.d.ts +3 -0
  214. package/utils/util.js +7 -0
@@ -0,0 +1,90 @@
1
+ import type { HexString } from '@polkadot/util/types';
2
+ import type { AnyJson, AnyU8a, CodecRegistry, IU8a } from '../types';
3
+ /**
4
+ * @name Raw
5
+ * @description
6
+ * A basic wrapper around Uint8Array, with no frills and no fuss. It does differ
7
+ * from other implementations where it will consume the full Uint8Array as passed to it.
8
+ * As such it is meant to be subclassed where the wrapper takes care of the
9
+ * actual lengths instead of used directly.
10
+ * @noInheritDoc
11
+ */
12
+ export declare class Raw extends Uint8Array implements IU8a {
13
+ readonly registry: CodecRegistry;
14
+ createdAtHash?: IU8a;
15
+ readonly initialU8aLength?: number;
16
+ constructor(registry: CodecRegistry, value?: AnyU8a, initialU8aLength?: number);
17
+ /**
18
+ * @description The length of the value when encoded as a Uint8Array
19
+ */
20
+ get encodedLength(): number;
21
+ /**
22
+ * @description returns a hash of the contents
23
+ */
24
+ get hash(): IU8a;
25
+ /**
26
+ * @description Returns true if the wrapped value contains only ASCII printable characters
27
+ */
28
+ get isAscii(): boolean;
29
+ /**
30
+ * @description Returns true if the type wraps an empty/default all-0 value
31
+ */
32
+ get isEmpty(): boolean;
33
+ /**
34
+ * @description Returns true if the wrapped value contains only utf8 characters
35
+ */
36
+ get isUtf8(): boolean;
37
+ /**
38
+ * @description The length of the value
39
+ */
40
+ get length(): number;
41
+ /**
42
+ * @description Returns the number of bits in the value
43
+ */
44
+ bitLength(): number;
45
+ /**
46
+ * @description Compares the value of the input to see if there is a match
47
+ */
48
+ eq(other?: unknown): boolean;
49
+ /**
50
+ * @description Create a new slice from the actual buffer. (compat)
51
+ * @param start The position to start at
52
+ * @param end The position to end at
53
+ */
54
+ slice(start?: number, end?: number): Uint8Array;
55
+ /**
56
+ * @description Create a new subarray from the actual buffer. (compat)
57
+ * @param begin The position to start at
58
+ * @param end The position to end at
59
+ */
60
+ subarray(begin?: number, end?: number): Uint8Array;
61
+ /**
62
+ * @description Returns a hex string representation of the value
63
+ */
64
+ toHex(): HexString;
65
+ /**
66
+ * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
67
+ */
68
+ toHuman(): AnyJson;
69
+ /**
70
+ * @description Converts the Object to JSON, typically used for RPC transfers
71
+ */
72
+ toJSON(): string;
73
+ /**
74
+ * @description Returns the base runtime type name for this instance
75
+ */
76
+ toRawType(): string;
77
+ /**
78
+ * @description Returns the string representation of the value
79
+ */
80
+ toString(): string;
81
+ /**
82
+ * @description Encodes the value as a Uint8Array as per the SCALE specifications
83
+ * @param isBare true when the value has none of the type-specific prefixes (internal)
84
+ */
85
+ toU8a(isBare?: boolean): Uint8Array;
86
+ /**
87
+ * @description Returns the wrapped data as a UTF-8 string
88
+ */
89
+ toUtf8(): string;
90
+ }
package/native/Raw.js ADDED
@@ -0,0 +1,182 @@
1
+ // Copyright 2017-2021 @polkadot/types-codec authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { assert, isAscii, isUndefined, isUtf8, u8aToHex, u8aToString, u8aToU8a } from '@polkadot/util';
4
+ /**
5
+ * @name Raw
6
+ * @description
7
+ * A basic wrapper around Uint8Array, with no frills and no fuss. It does differ
8
+ * from other implementations where it will consume the full Uint8Array as passed to it.
9
+ * As such it is meant to be subclassed where the wrapper takes care of the
10
+ * actual lengths instead of used directly.
11
+ * @noInheritDoc
12
+ */
13
+
14
+ export class Raw extends Uint8Array {
15
+ constructor(registry, value, initialU8aLength) {
16
+ super(u8aToU8a(value));
17
+ this.registry = void 0;
18
+ this.createdAtHash = void 0;
19
+ this.initialU8aLength = void 0;
20
+ this.registry = registry;
21
+ this.initialU8aLength = initialU8aLength;
22
+ }
23
+ /**
24
+ * @description The length of the value when encoded as a Uint8Array
25
+ */
26
+
27
+
28
+ get encodedLength() {
29
+ return this.length;
30
+ }
31
+ /**
32
+ * @description returns a hash of the contents
33
+ */
34
+
35
+
36
+ get hash() {
37
+ return this.registry.hash(this.toU8a());
38
+ }
39
+ /**
40
+ * @description Returns true if the wrapped value contains only ASCII printable characters
41
+ */
42
+
43
+
44
+ get isAscii() {
45
+ return isAscii(this);
46
+ }
47
+ /**
48
+ * @description Returns true if the type wraps an empty/default all-0 value
49
+ */
50
+
51
+
52
+ get isEmpty() {
53
+ return !this.length || isUndefined(this.find(b => !!b));
54
+ }
55
+ /**
56
+ * @description Returns true if the wrapped value contains only utf8 characters
57
+ */
58
+
59
+
60
+ get isUtf8() {
61
+ return isUtf8(this);
62
+ }
63
+ /**
64
+ * @description The length of the value
65
+ */
66
+
67
+
68
+ get length() {
69
+ // only included here since we ignore inherited docs
70
+ return super.length;
71
+ }
72
+ /**
73
+ * @description Returns the number of bits in the value
74
+ */
75
+
76
+
77
+ bitLength() {
78
+ return this.length * 8;
79
+ }
80
+ /**
81
+ * @description Compares the value of the input to see if there is a match
82
+ */
83
+
84
+
85
+ eq(other) {
86
+ if (other instanceof Uint8Array) {
87
+ return this.length === other.length && !this.some((b, index) => b !== other[index]);
88
+ }
89
+
90
+ return this.eq(u8aToU8a(other));
91
+ }
92
+ /**
93
+ * @description Create a new slice from the actual buffer. (compat)
94
+ * @param start The position to start at
95
+ * @param end The position to end at
96
+ */
97
+
98
+
99
+ slice(start, end) {
100
+ // Like subarray below, we have to follow this approach since we are extending the TypeArray.
101
+ // This happens especially when it comes to further extensions, the length may be an override
102
+ return Uint8Array.from(this).slice(start, end);
103
+ }
104
+ /**
105
+ * @description Create a new subarray from the actual buffer. (compat)
106
+ * @param begin The position to start at
107
+ * @param end The position to end at
108
+ */
109
+
110
+
111
+ subarray(begin, end) {
112
+ return Uint8Array.from(this).subarray(begin, end);
113
+ }
114
+ /**
115
+ * @description Returns a hex string representation of the value
116
+ */
117
+
118
+
119
+ toHex() {
120
+ return u8aToHex(this);
121
+ }
122
+ /**
123
+ * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
124
+ */
125
+
126
+
127
+ toHuman() {
128
+ if (this.isAscii) {
129
+ const text = this.toUtf8(); // ensure we didn't end up with multibyte codepoints
130
+
131
+ if (isAscii(text)) {
132
+ return text;
133
+ }
134
+ }
135
+
136
+ return this.toJSON();
137
+ }
138
+ /**
139
+ * @description Converts the Object to JSON, typically used for RPC transfers
140
+ */
141
+
142
+
143
+ toJSON() {
144
+ return this.toHex();
145
+ }
146
+ /**
147
+ * @description Returns the base runtime type name for this instance
148
+ */
149
+
150
+
151
+ toRawType() {
152
+ return 'Raw';
153
+ }
154
+ /**
155
+ * @description Returns the string representation of the value
156
+ */
157
+
158
+
159
+ toString() {
160
+ return this.toHex();
161
+ }
162
+ /**
163
+ * @description Encodes the value as a Uint8Array as per the SCALE specifications
164
+ * @param isBare true when the value has none of the type-specific prefixes (internal)
165
+ */
166
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
167
+
168
+
169
+ toU8a(isBare) {
170
+ return Uint8Array.from(this);
171
+ }
172
+ /**
173
+ * @description Returns the wrapped data as a UTF-8 string
174
+ */
175
+
176
+
177
+ toUtf8() {
178
+ assert(this.isUtf8, 'The character sequence is not a valid Utf8 string');
179
+ return u8aToString(this);
180
+ }
181
+
182
+ }
package/native/Set.cjs ADDED
@@ -0,0 +1,268 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.CodecSet = void 0;
9
+
10
+ var _classPrivateFieldLooseBase2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldLooseBase"));
11
+
12
+ var _classPrivateFieldLooseKey2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldLooseKey"));
13
+
14
+ var _util = require("@polkadot/util");
15
+
16
+ var _index = require("../utils/index.cjs");
17
+
18
+ // Copyright 2017-2021 @polkadot/types-codec authors & contributors
19
+ // SPDX-License-Identifier: Apache-2.0
20
+ function encodeSet(setValues, values) {
21
+ const encoded = new _util.BN(0);
22
+
23
+ for (let i = 0; i < values.length; i++) {
24
+ encoded.ior((0, _util.bnToBn)(setValues[values[i]] || 0));
25
+ }
26
+
27
+ return encoded;
28
+ }
29
+ /** @internal */
30
+
31
+
32
+ function decodeSetArray(setValues, values) {
33
+ const result = new Array(values.length);
34
+
35
+ for (let i = 0; i < values.length; i++) {
36
+ const key = values[i];
37
+ (0, _util.assert)(!(0, _util.isUndefined)(setValues[key]), () => `Set: Invalid key '${key}' passed to Set, allowed ${Object.keys(setValues).join(', ')}`);
38
+ result[i] = key;
39
+ }
40
+
41
+ return result;
42
+ }
43
+ /** @internal */
44
+
45
+
46
+ function decodeSetNumber(setValues, _value) {
47
+ const bn = (0, _util.bnToBn)(_value);
48
+ const keys = Object.keys(setValues);
49
+ const result = [];
50
+
51
+ for (let i = 0; i < keys.length; i++) {
52
+ const key = keys[i];
53
+
54
+ if (bn.and((0, _util.bnToBn)(setValues[key])).eq((0, _util.bnToBn)(setValues[key]))) {
55
+ result.push(key);
56
+ }
57
+ }
58
+
59
+ const computed = encodeSet(setValues, result);
60
+ (0, _util.assert)(bn.eq(computed), () => `Set: Mismatch decoding '${bn.toString()}', computed as '${computed.toString()}' with ${result.join(', ')}`);
61
+ return result;
62
+ }
63
+ /** @internal */
64
+
65
+
66
+ function decodeSet(setValues) {
67
+ let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
68
+ let bitLength = arguments.length > 2 ? arguments[2] : undefined;
69
+ (0, _util.assert)(bitLength % 8 === 0, () => `Expected valid bitLength, power of 8, found ${bitLength}`);
70
+ const byteLength = bitLength / 8;
71
+
72
+ if ((0, _util.isU8a)(value)) {
73
+ return value.length === 0 ? [] : decodeSetNumber(setValues, (0, _util.u8aToBn)(value.subarray(0, byteLength), {
74
+ isLe: true
75
+ }));
76
+ } else if ((0, _util.isString)(value)) {
77
+ return decodeSet(setValues, (0, _util.u8aToU8a)(value), byteLength);
78
+ } else if (value instanceof Set || Array.isArray(value)) {
79
+ const input = Array.isArray(value) ? value : [...value.values()];
80
+ return decodeSetArray(setValues, input);
81
+ }
82
+
83
+ return decodeSetNumber(setValues, value);
84
+ }
85
+ /**
86
+ * @name Set
87
+ * @description
88
+ * An Set is an array of string values, represented an an encoded type by
89
+ * a bitwise representation of the values.
90
+ */
91
+
92
+
93
+ var _allowed = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("allowed");
94
+
95
+ var _byteLength = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("byteLength");
96
+
97
+ class CodecSet extends Set {
98
+ constructor(registry, setValues, value) {
99
+ let bitLength = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 8;
100
+ super(decodeSet(setValues, value, bitLength));
101
+ this.registry = void 0;
102
+ this.createdAtHash = void 0;
103
+ Object.defineProperty(this, _allowed, {
104
+ writable: true,
105
+ value: void 0
106
+ });
107
+ Object.defineProperty(this, _byteLength, {
108
+ writable: true,
109
+ value: void 0
110
+ });
111
+
112
+ this.add = key => {
113
+ // ^^^ add = () property done to assign this instance's this, otherwise Set.add creates "some" chaos
114
+ // we have the isUndefined(this._setValues) in here as well, add is used internally
115
+ // in the Set constructor (so it is undefined at this point, and should allow)
116
+ (0, _util.assert)((0, _util.isUndefined)((0, _classPrivateFieldLooseBase2.default)(this, _allowed)[_allowed]) || !(0, _util.isUndefined)((0, _classPrivateFieldLooseBase2.default)(this, _allowed)[_allowed][key]), () => `Set: Invalid key '${key}' on add`);
117
+ super.add(key);
118
+ return this;
119
+ };
120
+
121
+ this.registry = registry;
122
+ (0, _classPrivateFieldLooseBase2.default)(this, _allowed)[_allowed] = setValues;
123
+ (0, _classPrivateFieldLooseBase2.default)(this, _byteLength)[_byteLength] = bitLength / 8;
124
+ }
125
+
126
+ static with(values, bitLength) {
127
+ const keys = Object.keys(values);
128
+ const isKeys = new Array(keys.length);
129
+
130
+ for (let i = 0; i < keys.length; i++) {
131
+ isKeys[i] = `is${(0, _util.stringPascalCase)(keys[i])}`;
132
+ }
133
+
134
+ return class extends CodecSet {
135
+ constructor(registry, value) {
136
+ super(registry, values, value, bitLength);
137
+ (0, _util.objectProperties)(this, isKeys, (_, i) => this.strings.includes(keys[i]));
138
+ }
139
+
140
+ };
141
+ }
142
+ /**
143
+ * @description The length of the value when encoded as a Uint8Array
144
+ */
145
+
146
+
147
+ get encodedLength() {
148
+ return (0, _classPrivateFieldLooseBase2.default)(this, _byteLength)[_byteLength];
149
+ }
150
+ /**
151
+ * @description returns a hash of the contents
152
+ */
153
+
154
+
155
+ get hash() {
156
+ return this.registry.hash(this.toU8a());
157
+ }
158
+ /**
159
+ * @description true is the Set contains no values
160
+ */
161
+
162
+
163
+ get isEmpty() {
164
+ return this.size === 0;
165
+ }
166
+ /**
167
+ * @description The actual set values as a string[]
168
+ */
169
+
170
+
171
+ get strings() {
172
+ return [...super.values()];
173
+ }
174
+ /**
175
+ * @description The encoded value for the set members
176
+ */
177
+
178
+
179
+ get valueEncoded() {
180
+ return encodeSet((0, _classPrivateFieldLooseBase2.default)(this, _allowed)[_allowed], this.strings);
181
+ }
182
+ /**
183
+ * @description adds a value to the Set (extended to allow for validity checking)
184
+ */
185
+
186
+
187
+ /**
188
+ * @description Compares the value of the input to see if there is a match
189
+ */
190
+ eq(other) {
191
+ if (Array.isArray(other)) {
192
+ // we don't actually care about the order, sort the values
193
+ return (0, _index.compareArray)(this.strings.sort(), other.sort());
194
+ } else if (other instanceof Set) {
195
+ return this.eq([...other.values()]);
196
+ } else if ((0, _util.isNumber)(other) || (0, _util.isBn)(other)) {
197
+ return this.valueEncoded.eq((0, _util.bnToBn)(other));
198
+ }
199
+
200
+ return false;
201
+ }
202
+ /**
203
+ * @description Returns a hex string representation of the value
204
+ */
205
+
206
+
207
+ toHex() {
208
+ return (0, _util.u8aToHex)(this.toU8a());
209
+ }
210
+ /**
211
+ * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
212
+ */
213
+
214
+
215
+ toHuman() {
216
+ return this.toJSON();
217
+ }
218
+ /**
219
+ * @description Converts the Object to JSON, typically used for RPC transfers
220
+ */
221
+
222
+
223
+ toJSON() {
224
+ return this.strings;
225
+ }
226
+ /**
227
+ * @description The encoded value for the set members
228
+ */
229
+
230
+
231
+ toNumber() {
232
+ return this.valueEncoded.toNumber();
233
+ }
234
+ /**
235
+ * @description Returns the base runtime type name for this instance
236
+ */
237
+
238
+
239
+ toRawType() {
240
+ return (0, _util.stringify)({
241
+ _set: (0, _classPrivateFieldLooseBase2.default)(this, _allowed)[_allowed]
242
+ });
243
+ }
244
+ /**
245
+ * @description Returns the string representation of the value
246
+ */
247
+
248
+
249
+ toString() {
250
+ return `[${this.strings.join(', ')}]`;
251
+ }
252
+ /**
253
+ * @description Encodes the value as a Uint8Array as per the SCALE specifications
254
+ * @param isBare true when the value has none of the type-specific prefixes (internal)
255
+ */
256
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
257
+
258
+
259
+ toU8a(isBare) {
260
+ return (0, _util.bnToU8a)(this.valueEncoded, {
261
+ bitLength: (0, _classPrivateFieldLooseBase2.default)(this, _byteLength)[_byteLength] * 8,
262
+ isLe: true
263
+ });
264
+ }
265
+
266
+ }
267
+
268
+ exports.CodecSet = CodecSet;
@@ -0,0 +1,76 @@
1
+ /// <reference types="bn.js" />
2
+ import type { HexString } from '@polkadot/util/types';
3
+ import type { CodecClass, CodecRegistry, ISet, IU8a } from '../types';
4
+ import { BN } from '@polkadot/util';
5
+ declare type SetValues = Record<string, number | BN>;
6
+ /**
7
+ * @name Set
8
+ * @description
9
+ * An Set is an array of string values, represented an an encoded type by
10
+ * a bitwise representation of the values.
11
+ */
12
+ export declare class CodecSet extends Set<string> implements ISet<string> {
13
+ #private;
14
+ readonly registry: CodecRegistry;
15
+ createdAtHash?: IU8a;
16
+ constructor(registry: CodecRegistry, setValues: SetValues, value?: string[] | Set<string> | Uint8Array | BN | number | string, bitLength?: number);
17
+ static with(values: SetValues, bitLength?: number): CodecClass<CodecSet>;
18
+ /**
19
+ * @description The length of the value when encoded as a Uint8Array
20
+ */
21
+ get encodedLength(): number;
22
+ /**
23
+ * @description returns a hash of the contents
24
+ */
25
+ get hash(): IU8a;
26
+ /**
27
+ * @description true is the Set contains no values
28
+ */
29
+ get isEmpty(): boolean;
30
+ /**
31
+ * @description The actual set values as a string[]
32
+ */
33
+ get strings(): string[];
34
+ /**
35
+ * @description The encoded value for the set members
36
+ */
37
+ get valueEncoded(): BN;
38
+ /**
39
+ * @description adds a value to the Set (extended to allow for validity checking)
40
+ */
41
+ add: (key: string) => this;
42
+ /**
43
+ * @description Compares the value of the input to see if there is a match
44
+ */
45
+ eq(other?: unknown): boolean;
46
+ /**
47
+ * @description Returns a hex string representation of the value
48
+ */
49
+ toHex(): HexString;
50
+ /**
51
+ * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
52
+ */
53
+ toHuman(): string[];
54
+ /**
55
+ * @description Converts the Object to JSON, typically used for RPC transfers
56
+ */
57
+ toJSON(): string[];
58
+ /**
59
+ * @description The encoded value for the set members
60
+ */
61
+ toNumber(): number;
62
+ /**
63
+ * @description Returns the base runtime type name for this instance
64
+ */
65
+ toRawType(): string;
66
+ /**
67
+ * @description Returns the string representation of the value
68
+ */
69
+ toString(): string;
70
+ /**
71
+ * @description Encodes the value as a Uint8Array as per the SCALE specifications
72
+ * @param isBare true when the value has none of the type-specific prefixes (internal)
73
+ */
74
+ toU8a(isBare?: boolean): Uint8Array;
75
+ }
76
+ export {};