@polkadot/types-codec 6.12.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/AbstractArray.cjs +208 -0
- package/abstract/AbstractArray.d.ts +84 -0
- package/abstract/AbstractArray.js +197 -0
- package/abstract/AbstractInt.cjs +254 -0
- package/abstract/AbstractInt.d.ts +75 -0
- package/abstract/AbstractInt.js +231 -0
- package/abstract/index.cjs +21 -0
- package/abstract/index.d.ts +2 -0
- package/abstract/index.js +4 -0
- package/base/Base.cjs +109 -0
- package/base/Base.d.ts +54 -0
- package/base/Base.js +100 -0
- package/base/Compact.cjs +201 -0
- package/base/Compact.d.ts +83 -0
- package/base/Compact.js +186 -0
- package/base/DoNotConstruct.cjs +101 -0
- package/base/DoNotConstruct.d.ts +33 -0
- package/base/DoNotConstruct.js +88 -0
- package/base/Enum.cjs +437 -0
- package/base/Enum.d.ts +101 -0
- package/base/Enum.js +413 -0
- package/base/Int.cjs +45 -0
- package/base/Int.d.ts +16 -0
- package/base/Int.js +33 -0
- package/base/Null.cjs +111 -0
- package/base/Null.d.ts +54 -0
- package/base/Null.js +101 -0
- package/base/Option.cjs +256 -0
- package/base/Option.d.ts +88 -0
- package/base/Option.js +240 -0
- package/base/Result.cjs +109 -0
- package/base/Result.d.ts +46 -0
- package/base/Result.js +98 -0
- package/base/Tuple.cjs +132 -0
- package/base/Tuple.d.ts +39 -0
- package/base/Tuple.js +116 -0
- package/base/UInt.cjs +39 -0
- package/base/UInt.d.ts +15 -0
- package/base/UInt.js +29 -0
- package/base/Vec.cjs +126 -0
- package/base/Vec.d.ts +28 -0
- package/base/Vec.js +104 -0
- package/base/VecAny.cjs +31 -0
- package/base/VecAny.d.ts +15 -0
- package/base/VecAny.js +21 -0
- package/base/VecFixed.cjs +111 -0
- package/base/VecFixed.d.ts +26 -0
- package/base/VecFixed.js +93 -0
- package/base/index.cjs +109 -0
- package/base/index.d.ts +13 -0
- package/base/index.js +15 -0
- package/bundle.cjs +100 -0
- package/bundle.d.ts +7 -0
- package/bundle.js +9 -0
- package/detectPackage.cjs +9 -0
- package/detectPackage.d.ts +1 -0
- package/detectPackage.js +5 -0
- package/extended/BTreeMap.cjs +24 -0
- package/extended/BTreeMap.d.ts +5 -0
- package/extended/BTreeMap.js +14 -0
- package/extended/BTreeSet.cjs +227 -0
- package/extended/BTreeSet.d.ts +55 -0
- package/extended/BTreeSet.js +212 -0
- package/extended/BitVec.cjs +97 -0
- package/extended/BitVec.d.ts +26 -0
- package/extended/BitVec.js +82 -0
- package/extended/Bytes.cjs +86 -0
- package/extended/Bytes.d.ts +25 -0
- package/extended/Bytes.js +75 -0
- package/extended/HashMap.cjs +24 -0
- package/extended/HashMap.d.ts +5 -0
- package/extended/HashMap.js +14 -0
- package/extended/Linkage.cjs +89 -0
- package/extended/Linkage.d.ts +31 -0
- package/extended/Linkage.js +71 -0
- package/extended/Map.cjs +244 -0
- package/extended/Map.d.ts +50 -0
- package/extended/Map.js +225 -0
- package/extended/Range.cjs +92 -0
- package/extended/Range.d.ts +30 -0
- package/extended/Range.js +75 -0
- package/extended/Type.cjs +39 -0
- package/extended/Type.d.ts +16 -0
- package/extended/Type.js +27 -0
- package/extended/U8aFixed.cjs +66 -0
- package/extended/U8aFixed.d.ts +16 -0
- package/extended/U8aFixed.js +53 -0
- package/extended/WrapperOpaque.cjs +68 -0
- package/extended/WrapperOpaque.d.ts +18 -0
- package/extended/WrapperOpaque.js +57 -0
- package/extended/index.cjs +105 -0
- package/extended/index.d.ts +11 -0
- package/extended/index.js +13 -0
- package/index.cjs +20 -0
- package/index.d.ts +2 -0
- package/index.js +4 -0
- package/native/Bool.cjs +141 -0
- package/native/Bool.d.ts +62 -0
- package/native/Bool.js +130 -0
- package/native/Date.cjs +170 -0
- package/native/Date.d.ts +76 -0
- package/native/Date.js +158 -0
- package/native/Json.cjs +133 -0
- package/native/Json.d.ts +55 -0
- package/native/Json.js +117 -0
- package/native/Raw.cjs +192 -0
- package/native/Raw.d.ts +90 -0
- package/native/Raw.js +182 -0
- package/native/Set.cjs +268 -0
- package/native/Set.d.ts +76 -0
- package/native/Set.js +251 -0
- package/native/Struct.cjs +289 -0
- package/native/Struct.d.ts +92 -0
- package/native/Struct.js +273 -0
- package/native/Text.cjs +193 -0
- package/native/Text.d.ts +71 -0
- package/native/Text.js +178 -0
- package/native/index.cjs +79 -0
- package/native/index.d.ts +7 -0
- package/native/index.js +9 -0
- package/package.json +387 -0
- package/packageInfo.cjs +14 -0
- package/packageInfo.d.ts +4 -0
- package/packageInfo.js +7 -0
- package/primitive/I128.cjs +26 -0
- package/primitive/I128.d.ts +11 -0
- package/primitive/I128.js +16 -0
- package/primitive/I16.cjs +26 -0
- package/primitive/I16.d.ts +11 -0
- package/primitive/I16.js +16 -0
- package/primitive/I256.cjs +26 -0
- package/primitive/I256.d.ts +11 -0
- package/primitive/I256.js +16 -0
- package/primitive/I32.cjs +26 -0
- package/primitive/I32.d.ts +11 -0
- package/primitive/I32.js +16 -0
- package/primitive/I64.cjs +26 -0
- package/primitive/I64.d.ts +11 -0
- package/primitive/I64.js +16 -0
- package/primitive/I8.cjs +26 -0
- package/primitive/I8.d.ts +11 -0
- package/primitive/I8.js +16 -0
- package/primitive/U128.cjs +26 -0
- package/primitive/U128.d.ts +11 -0
- package/primitive/U128.js +16 -0
- package/primitive/U16.cjs +26 -0
- package/primitive/U16.d.ts +11 -0
- package/primitive/U16.js +16 -0
- package/primitive/U256.cjs +26 -0
- package/primitive/U256.d.ts +11 -0
- package/primitive/U256.js +16 -0
- package/primitive/U32.cjs +26 -0
- package/primitive/U32.d.ts +11 -0
- package/primitive/U32.js +16 -0
- package/primitive/U64.cjs +26 -0
- package/primitive/U64.d.ts +11 -0
- package/primitive/U64.js +16 -0
- package/primitive/U8.cjs +26 -0
- package/primitive/U8.d.ts +11 -0
- package/primitive/U8.js +16 -0
- package/primitive/USize.cjs +28 -0
- package/primitive/USize.d.ts +12 -0
- package/primitive/USize.js +18 -0
- package/primitive/index.cjs +187 -0
- package/primitive/index.d.ts +13 -0
- package/primitive/index.js +15 -0
- package/types/codec.cjs +1 -0
- package/types/codec.d.ts +77 -0
- package/types/codec.js +1 -0
- package/types/helpers.cjs +1 -0
- package/types/helpers.d.ts +14 -0
- package/types/helpers.js +1 -0
- package/types/index.cjs +57 -0
- package/types/index.d.ts +4 -0
- package/types/index.js +6 -0
- package/types/interfaces.cjs +1 -0
- package/types/interfaces.d.ts +68 -0
- package/types/interfaces.js +1 -0
- package/types/registry.cjs +1 -0
- package/types/registry.d.ts +44 -0
- package/types/registry.js +1 -0
- package/utils/compareArray.cjs +22 -0
- package/utils/compareArray.d.ts +1 -0
- package/utils/compareArray.js +13 -0
- package/utils/compareMap.cjs +39 -0
- package/utils/compareMap.d.ts +1 -0
- package/utils/compareMap.js +31 -0
- package/utils/compareSet.cjs +29 -0
- package/utils/compareSet.d.ts +1 -0
- package/utils/compareSet.js +22 -0
- package/utils/decodeU8a.cjs +69 -0
- package/utils/decodeU8a.d.ts +13 -0
- package/utils/decodeU8a.js +60 -0
- package/utils/index.cjs +95 -0
- package/utils/index.d.ts +9 -0
- package/utils/index.js +11 -0
- package/utils/mapToTypeMap.cjs +25 -0
- package/utils/mapToTypeMap.d.ts +5 -0
- package/utils/mapToTypeMap.js +17 -0
- package/utils/sanitize.cjs +242 -0
- package/utils/sanitize.d.ts +16 -0
- package/utils/sanitize.js +215 -0
- package/utils/sortValues.cjs +89 -0
- package/utils/sortValues.d.ts +13 -0
- package/utils/sortValues.js +73 -0
- package/utils/typeToConstructor.cjs +14 -0
- package/utils/typeToConstructor.d.ts +2 -0
- package/utils/typeToConstructor.js +6 -0
- package/utils/typesToMap.cjs +20 -0
- package/utils/typesToMap.d.ts +2 -0
- package/utils/typesToMap.js +13 -0
- package/utils/util.cjs +15 -0
- package/utils/util.d.ts +3 -0
- package/utils/util.js +7 -0
package/native/Raw.cjs
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Raw = void 0;
|
|
7
|
+
|
|
8
|
+
var _util = require("@polkadot/util");
|
|
9
|
+
|
|
10
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
11
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @name Raw
|
|
15
|
+
* @description
|
|
16
|
+
* A basic wrapper around Uint8Array, with no frills and no fuss. It does differ
|
|
17
|
+
* from other implementations where it will consume the full Uint8Array as passed to it.
|
|
18
|
+
* As such it is meant to be subclassed where the wrapper takes care of the
|
|
19
|
+
* actual lengths instead of used directly.
|
|
20
|
+
* @noInheritDoc
|
|
21
|
+
*/
|
|
22
|
+
class Raw extends Uint8Array {
|
|
23
|
+
constructor(registry, value, initialU8aLength) {
|
|
24
|
+
super((0, _util.u8aToU8a)(value));
|
|
25
|
+
this.registry = void 0;
|
|
26
|
+
this.createdAtHash = void 0;
|
|
27
|
+
this.initialU8aLength = void 0;
|
|
28
|
+
this.registry = registry;
|
|
29
|
+
this.initialU8aLength = initialU8aLength;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
get encodedLength() {
|
|
37
|
+
return this.length;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @description returns a hash of the contents
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
get hash() {
|
|
45
|
+
return this.registry.hash(this.toU8a());
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @description Returns true if the wrapped value contains only ASCII printable characters
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
get isAscii() {
|
|
53
|
+
return (0, _util.isAscii)(this);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* @description Returns true if the type wraps an empty/default all-0 value
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
get isEmpty() {
|
|
61
|
+
return !this.length || (0, _util.isUndefined)(this.find(b => !!b));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* @description Returns true if the wrapped value contains only utf8 characters
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
get isUtf8() {
|
|
69
|
+
return (0, _util.isUtf8)(this);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* @description The length of the value
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
get length() {
|
|
77
|
+
// only included here since we ignore inherited docs
|
|
78
|
+
return super.length;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* @description Returns the number of bits in the value
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
bitLength() {
|
|
86
|
+
return this.length * 8;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* @description Compares the value of the input to see if there is a match
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
eq(other) {
|
|
94
|
+
if (other instanceof Uint8Array) {
|
|
95
|
+
return this.length === other.length && !this.some((b, index) => b !== other[index]);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return this.eq((0, _util.u8aToU8a)(other));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* @description Create a new slice from the actual buffer. (compat)
|
|
102
|
+
* @param start The position to start at
|
|
103
|
+
* @param end The position to end at
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
slice(start, end) {
|
|
108
|
+
// Like subarray below, we have to follow this approach since we are extending the TypeArray.
|
|
109
|
+
// This happens especially when it comes to further extensions, the length may be an override
|
|
110
|
+
return Uint8Array.from(this).slice(start, end);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* @description Create a new subarray from the actual buffer. (compat)
|
|
114
|
+
* @param begin The position to start at
|
|
115
|
+
* @param end The position to end at
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
subarray(begin, end) {
|
|
120
|
+
return Uint8Array.from(this).subarray(begin, end);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @description Returns a hex string representation of the value
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
toHex() {
|
|
128
|
+
return (0, _util.u8aToHex)(this);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
toHuman() {
|
|
136
|
+
if (this.isAscii) {
|
|
137
|
+
const text = this.toUtf8(); // ensure we didn't end up with multibyte codepoints
|
|
138
|
+
|
|
139
|
+
if ((0, _util.isAscii)(text)) {
|
|
140
|
+
return text;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return this.toJSON();
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
148
|
+
*/
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
toJSON() {
|
|
152
|
+
return this.toHex();
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* @description Returns the base runtime type name for this instance
|
|
156
|
+
*/
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
toRawType() {
|
|
160
|
+
return 'Raw';
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* @description Returns the string representation of the value
|
|
164
|
+
*/
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
toString() {
|
|
168
|
+
return this.toHex();
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
172
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
173
|
+
*/
|
|
174
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
toU8a(isBare) {
|
|
178
|
+
return Uint8Array.from(this);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* @description Returns the wrapped data as a UTF-8 string
|
|
182
|
+
*/
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
toUtf8() {
|
|
186
|
+
(0, _util.assert)(this.isUtf8, 'The character sequence is not a valid Utf8 string');
|
|
187
|
+
return (0, _util.u8aToString)(this);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
exports.Raw = Raw;
|
package/native/Raw.d.ts
ADDED
|
@@ -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
|
+
}
|