@polkadot/types-codec 16.1.2 → 16.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/abstract/Base.js +14 -14
- package/abstract/Int.js +8 -8
- package/base/Compact.js +20 -20
- package/base/DoNotConstruct.js +15 -15
- package/base/Enum.js +39 -39
- package/base/Option.js +17 -17
- package/base/Tuple.js +6 -6
- package/base/Vec.js +8 -8
- package/base/VecFixed.js +5 -5
- package/cjs/abstract/Base.js +14 -14
- package/cjs/abstract/Int.js +8 -8
- package/cjs/base/Compact.js +20 -20
- package/cjs/base/DoNotConstruct.js +15 -15
- package/cjs/base/Enum.js +39 -39
- package/cjs/base/Option.js +17 -17
- package/cjs/base/Tuple.js +6 -6
- package/cjs/base/Vec.js +8 -8
- package/cjs/base/VecFixed.js +5 -5
- package/cjs/extended/BTreeSet.js +3 -3
- package/cjs/extended/BitVec.js +9 -9
- package/cjs/extended/Map.js +7 -7
- package/cjs/extended/Range.js +3 -3
- package/cjs/extended/WrapperKeepOpaque.js +19 -19
- package/cjs/native/Float.js +4 -4
- package/cjs/native/Set.js +9 -9
- package/cjs/native/Struct.js +8 -8
- package/cjs/native/Text.js +3 -3
- package/cjs/packageInfo.js +1 -1
- package/cjs/utils/decodeU8a.js +12 -0
- package/extended/BTreeSet.js +3 -3
- package/extended/BitVec.js +9 -9
- package/extended/Map.js +7 -7
- package/extended/Range.js +3 -3
- package/extended/WrapperKeepOpaque.js +19 -19
- package/native/Float.js +4 -4
- package/native/Set.js +9 -9
- package/native/Struct.js +8 -8
- package/native/Text.js +3 -3
- package/package.json +3 -3
- package/packageInfo.js +1 -1
- package/utils/decodeU8a.js +12 -0
package/native/Struct.js
CHANGED
|
@@ -78,8 +78,8 @@ export class Struct extends Map {
|
|
|
78
78
|
createdAtHash;
|
|
79
79
|
initialU8aLength;
|
|
80
80
|
isStorageFallback;
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
#jsonMap;
|
|
82
|
+
#Types;
|
|
83
83
|
constructor(registry, Types, value, jsonMap = new Map(), { definition, setDefinition = noopSetDefinition } = {}) {
|
|
84
84
|
const typeMap = definition || setDefinition(mapToTypeMap(registry, Types));
|
|
85
85
|
const [decoded, decodedLength] = isU8a(value) || isHex(value)
|
|
@@ -90,8 +90,8 @@ export class Struct extends Map {
|
|
|
90
90
|
super(decoded);
|
|
91
91
|
this.initialU8aLength = decodedLength;
|
|
92
92
|
this.registry = registry;
|
|
93
|
-
this
|
|
94
|
-
this
|
|
93
|
+
this.#jsonMap = jsonMap;
|
|
94
|
+
this.#Types = typeMap;
|
|
95
95
|
}
|
|
96
96
|
static with(Types, jsonMap) {
|
|
97
97
|
let definition;
|
|
@@ -111,7 +111,7 @@ export class Struct extends Map {
|
|
|
111
111
|
* @description The available keys for this struct
|
|
112
112
|
*/
|
|
113
113
|
get defKeys() {
|
|
114
|
-
return this
|
|
114
|
+
return this.#Types[1];
|
|
115
115
|
}
|
|
116
116
|
/**
|
|
117
117
|
* @description Checks if the value is an empty value '{}'
|
|
@@ -140,7 +140,7 @@ export class Struct extends Map {
|
|
|
140
140
|
*/
|
|
141
141
|
get Type() {
|
|
142
142
|
const result = {};
|
|
143
|
-
const [Types, keys] = this
|
|
143
|
+
const [Types, keys] = this.#Types;
|
|
144
144
|
for (let i = 0, count = keys.length; i < count; i++) {
|
|
145
145
|
result[keys[i]] = new Types[i](this.registry).toRawType();
|
|
146
146
|
}
|
|
@@ -218,7 +218,7 @@ export class Struct extends Map {
|
|
|
218
218
|
for (const [k, v] of this.entries()) {
|
|
219
219
|
// Here we pull out the entry against the JSON mapping (if supplied)
|
|
220
220
|
// since this representation goes over RPC and needs to be correct
|
|
221
|
-
json[(this.
|
|
221
|
+
json[(this.#jsonMap.get(k) || k)] = v.toJSON();
|
|
222
222
|
}
|
|
223
223
|
return json;
|
|
224
224
|
}
|
|
@@ -236,7 +236,7 @@ export class Struct extends Map {
|
|
|
236
236
|
* @description Returns the base runtime type name for this instance
|
|
237
237
|
*/
|
|
238
238
|
toRawType() {
|
|
239
|
-
return stringify(typesToMap(this.registry, this
|
|
239
|
+
return stringify(typesToMap(this.registry, this.#Types));
|
|
240
240
|
}
|
|
241
241
|
/**
|
|
242
242
|
* @description Returns the string representation of the value
|
package/native/Text.js
CHANGED
|
@@ -40,7 +40,7 @@ export class Text extends String {
|
|
|
40
40
|
createdAtHash;
|
|
41
41
|
initialU8aLength;
|
|
42
42
|
isStorageFallback;
|
|
43
|
-
|
|
43
|
+
#override = null;
|
|
44
44
|
constructor(registry, value) {
|
|
45
45
|
const [str, decodedLength] = decodeText(value);
|
|
46
46
|
super(str);
|
|
@@ -95,7 +95,7 @@ export class Text extends String {
|
|
|
95
95
|
* @description Set an override value for this
|
|
96
96
|
*/
|
|
97
97
|
setOverride(override) {
|
|
98
|
-
this
|
|
98
|
+
this.#override = override;
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
101
101
|
* @description Returns a hex string representation of the value
|
|
@@ -133,7 +133,7 @@ export class Text extends String {
|
|
|
133
133
|
* @description Returns the string representation of the value
|
|
134
134
|
*/
|
|
135
135
|
toString() {
|
|
136
|
-
return this
|
|
136
|
+
return this.#override || super.toString();
|
|
137
137
|
}
|
|
138
138
|
/**
|
|
139
139
|
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"./cjs/packageDetect.js"
|
|
19
19
|
],
|
|
20
20
|
"type": "module",
|
|
21
|
-
"version": "16.
|
|
21
|
+
"version": "16.2.2",
|
|
22
22
|
"main": "./cjs/index.js",
|
|
23
23
|
"module": "./index.js",
|
|
24
24
|
"types": "./index.d.ts",
|
|
@@ -1142,8 +1142,8 @@
|
|
|
1142
1142
|
}
|
|
1143
1143
|
},
|
|
1144
1144
|
"dependencies": {
|
|
1145
|
-
"@polkadot/util": "^13.5.
|
|
1146
|
-
"@polkadot/x-bigint": "^13.5.
|
|
1145
|
+
"@polkadot/util": "^13.5.2",
|
|
1146
|
+
"@polkadot/x-bigint": "^13.5.2",
|
|
1147
1147
|
"tslib": "^2.8.1"
|
|
1148
1148
|
}
|
|
1149
1149
|
}
|
package/packageInfo.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const packageInfo = { name: '@polkadot/types-codec', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '16.
|
|
1
|
+
export const packageInfo = { name: '@polkadot/types-codec', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '16.2.2' };
|
package/utils/decodeU8a.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { u8aToHex } from '@polkadot/util';
|
|
2
|
+
const MAX_DEPTH = 1024;
|
|
3
|
+
/** @internal */
|
|
4
|
+
function isComplexType(Type) {
|
|
5
|
+
const typeName = Type.name?.toLowerCase() || '';
|
|
6
|
+
return ['enum', 'hashmap', 'linkage', 'null', 'option', 'range', 'rangeinclusive', 'result', 'struct', 'tuple', 'vec', 'vecfixed'].includes(typeName);
|
|
7
|
+
}
|
|
2
8
|
/** @internal */
|
|
3
9
|
function formatFailure(registry, fn, _result, { message }, u8a, i, count, Type, key) {
|
|
4
10
|
let type = '';
|
|
@@ -50,6 +56,9 @@ export function decodeU8aStruct(registry, result, u8a, [Types, keys]) {
|
|
|
50
56
|
const count = result.length;
|
|
51
57
|
let offset = 0;
|
|
52
58
|
let i = 0;
|
|
59
|
+
if (count > MAX_DEPTH && isComplexType(Types[i])) {
|
|
60
|
+
throw new Error(`decodeU8aStruct: Maximum depth exceeded, received ${count} elements, limit ${MAX_DEPTH}`);
|
|
61
|
+
}
|
|
53
62
|
try {
|
|
54
63
|
while (i < count) {
|
|
55
64
|
const value = new Types[i](registry, u8a.subarray(offset));
|
|
@@ -71,6 +80,9 @@ export function decodeU8aStruct(registry, result, u8a, [Types, keys]) {
|
|
|
71
80
|
*/
|
|
72
81
|
export function decodeU8aVec(registry, result, u8a, startAt, Type) {
|
|
73
82
|
const count = result.length;
|
|
83
|
+
if (count > MAX_DEPTH && isComplexType(Type)) {
|
|
84
|
+
throw new Error(`decodeU8aVec: Maximum depth exceeded, received ${count} elements, limit ${MAX_DEPTH}`);
|
|
85
|
+
}
|
|
74
86
|
let offset = startAt;
|
|
75
87
|
let i = 0;
|
|
76
88
|
try {
|