@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
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { i8, i8 as I8 } from './I8';
|
|
2
|
+
export { i16, i16 as I16 } from './I16';
|
|
3
|
+
export { i32, i32 as I32 } from './I32';
|
|
4
|
+
export { i64, i64 as I64 } from './I64';
|
|
5
|
+
export { i128, i128 as I128 } from './I128';
|
|
6
|
+
export { i256, i256 as I256 } from './I256';
|
|
7
|
+
export { u8, u8 as U8 } from './U8';
|
|
8
|
+
export { u16, u16 as U16 } from './U16';
|
|
9
|
+
export { u32, u32 as U32 } from './U32';
|
|
10
|
+
export { u64, u64 as U64 } from './U64';
|
|
11
|
+
export { u128, u128 as U128 } from './U128';
|
|
12
|
+
export { u256, u256 as U256 } from './U256';
|
|
13
|
+
export { usize, usize as USize } from './USize';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
export { i8, i8 as I8 } from "./I8.js";
|
|
4
|
+
export { i16, i16 as I16 } from "./I16.js";
|
|
5
|
+
export { i32, i32 as I32 } from "./I32.js";
|
|
6
|
+
export { i64, i64 as I64 } from "./I64.js";
|
|
7
|
+
export { i128, i128 as I128 } from "./I128.js";
|
|
8
|
+
export { i256, i256 as I256 } from "./I256.js";
|
|
9
|
+
export { u8, u8 as U8 } from "./U8.js";
|
|
10
|
+
export { u16, u16 as U16 } from "./U16.js";
|
|
11
|
+
export { u32, u32 as U32 } from "./U32.js";
|
|
12
|
+
export { u64, u64 as U64 } from "./U64.js";
|
|
13
|
+
export { u128, u128 as U128 } from "./U128.js";
|
|
14
|
+
export { u256, u256 as U256 } from "./U256.js";
|
|
15
|
+
export { usize, usize as USize } from "./USize.js";
|
package/types/codec.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/types/codec.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { HexString } from '@polkadot/util/types';
|
|
2
|
+
import type { AnyJson } from './helpers';
|
|
3
|
+
import type { IU8a } from './interfaces';
|
|
4
|
+
import type { CodecRegistry } from './registry';
|
|
5
|
+
export declare type BareOpts = boolean | Record<string, boolean>;
|
|
6
|
+
/**
|
|
7
|
+
* @name Codec
|
|
8
|
+
* @description
|
|
9
|
+
* The base Codec interface. All types implement the interface provided here. Additionally
|
|
10
|
+
* implementors can add their own specific interfaces and helpers with getters and functions.
|
|
11
|
+
* The Codec Base is however required for operating as an encoding/decoding layer
|
|
12
|
+
*/
|
|
13
|
+
export interface Codec {
|
|
14
|
+
/**
|
|
15
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
16
|
+
*/
|
|
17
|
+
readonly encodedLength: number;
|
|
18
|
+
/**
|
|
19
|
+
* @description Returns a hash of the value
|
|
20
|
+
*/
|
|
21
|
+
readonly hash: IU8a;
|
|
22
|
+
/**
|
|
23
|
+
* @description The length of the initial encoded value (Only available when constructed from a Uint8Array)
|
|
24
|
+
*/
|
|
25
|
+
readonly initialU8aLength?: number;
|
|
26
|
+
/**
|
|
27
|
+
* @description Checks if the value is an empty value
|
|
28
|
+
*/
|
|
29
|
+
readonly isEmpty: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* @description The registry associated with this object
|
|
32
|
+
*/
|
|
33
|
+
readonly registry: CodecRegistry;
|
|
34
|
+
/**
|
|
35
|
+
* @description The block at which this value was retrieved/created (set to non-empty when retrieved from storage)
|
|
36
|
+
*/
|
|
37
|
+
createdAtHash?: IU8a;
|
|
38
|
+
/**
|
|
39
|
+
* @description Compares the value of the input to see if there is a match
|
|
40
|
+
*/
|
|
41
|
+
eq(other?: unknown): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
44
|
+
*/
|
|
45
|
+
toHex(isLe?: boolean): HexString;
|
|
46
|
+
/**
|
|
47
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
48
|
+
*/
|
|
49
|
+
toHuman(isExtended?: boolean): AnyJson;
|
|
50
|
+
/**
|
|
51
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
52
|
+
*/
|
|
53
|
+
toJSON(): AnyJson;
|
|
54
|
+
/**
|
|
55
|
+
* @description Returns the base runtime type name for this instance
|
|
56
|
+
*/
|
|
57
|
+
toRawType(): string;
|
|
58
|
+
/**
|
|
59
|
+
* @description Returns the string representation of the value
|
|
60
|
+
*/
|
|
61
|
+
toString(): string;
|
|
62
|
+
/**
|
|
63
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
64
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
65
|
+
*/
|
|
66
|
+
toU8a(isBare?: BareOpts): Uint8Array;
|
|
67
|
+
}
|
|
68
|
+
export interface CodecClass<T = Codec> {
|
|
69
|
+
/**
|
|
70
|
+
* @description An internal fallback type (previous generation) if encoding fails
|
|
71
|
+
*/
|
|
72
|
+
readonly __fallbackType?: string;
|
|
73
|
+
new (registry: CodecRegistry, ...args: any[]): T;
|
|
74
|
+
}
|
|
75
|
+
export declare type CodecClassDef<T = Codec> = Record<string, CodecClass<T>>;
|
|
76
|
+
export declare type CodecTo = 'toHex' | 'toJSON' | 'toString' | 'toU8a';
|
|
77
|
+
export declare type ArgsDef = Record<string, CodecClass | string>;
|
package/types/codec.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
2
|
+
import type { BN } from '@polkadot/util';
|
|
3
|
+
import type { Codec } from './codec';
|
|
4
|
+
export declare type AnyJson = string | number | boolean | null | undefined | AnyJson[] | {
|
|
5
|
+
[index: string]: AnyJson;
|
|
6
|
+
};
|
|
7
|
+
export declare type AnyFunction = (...args: any[]) => any;
|
|
8
|
+
export declare type AnyNumber = BN | bigint | Uint8Array | number | string;
|
|
9
|
+
export declare type AnyString = string | string;
|
|
10
|
+
export declare type AnyTuple = Codec[];
|
|
11
|
+
export declare type AnyU8a = Uint8Array | number[] | string;
|
|
12
|
+
export declare type UIntBitLength = 8 | 16 | 32 | 64 | 128 | 256;
|
|
13
|
+
export declare type U8aBitLength = 8 | 16 | 32 | 64 | 128 | 160 | 256 | 264 | 512 | 520 | 1024 | 2048;
|
|
14
|
+
export declare type AnyTupleValue = AnyU8a | (Codec | AnyU8a | AnyNumber | AnyString | undefined | null)[];
|
package/types/helpers.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/types/index.cjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _codec = require("./codec.cjs");
|
|
8
|
+
|
|
9
|
+
Object.keys(_codec).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _codec[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _codec[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
var _helpers = require("./helpers.cjs");
|
|
21
|
+
|
|
22
|
+
Object.keys(_helpers).forEach(function (key) {
|
|
23
|
+
if (key === "default" || key === "__esModule") return;
|
|
24
|
+
if (key in exports && exports[key] === _helpers[key]) return;
|
|
25
|
+
Object.defineProperty(exports, key, {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _helpers[key];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
var _interfaces = require("./interfaces.cjs");
|
|
34
|
+
|
|
35
|
+
Object.keys(_interfaces).forEach(function (key) {
|
|
36
|
+
if (key === "default" || key === "__esModule") return;
|
|
37
|
+
if (key in exports && exports[key] === _interfaces[key]) return;
|
|
38
|
+
Object.defineProperty(exports, key, {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function () {
|
|
41
|
+
return _interfaces[key];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
var _registry = require("./registry.cjs");
|
|
47
|
+
|
|
48
|
+
Object.keys(_registry).forEach(function (key) {
|
|
49
|
+
if (key === "default" || key === "__esModule") return;
|
|
50
|
+
if (key in exports && exports[key] === _registry[key]) return;
|
|
51
|
+
Object.defineProperty(exports, key, {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function () {
|
|
54
|
+
return _registry[key];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
package/types/index.d.ts
ADDED
package/types/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
2
|
+
import type { BN } from '@polkadot/util';
|
|
3
|
+
import type { ArgsDef, Codec } from './codec';
|
|
4
|
+
import type { AnyTuple } from './helpers';
|
|
5
|
+
export interface ICompact<T extends INumber = INumber> extends Codec {
|
|
6
|
+
toBigInt(): bigint;
|
|
7
|
+
toBn(): BN;
|
|
8
|
+
toNumber(): number;
|
|
9
|
+
unwrap(): T;
|
|
10
|
+
}
|
|
11
|
+
export interface IEnum extends Codec {
|
|
12
|
+
readonly defIndexes: number[];
|
|
13
|
+
readonly defKeys: string[];
|
|
14
|
+
readonly index: number;
|
|
15
|
+
readonly isBasic: boolean;
|
|
16
|
+
readonly type: string;
|
|
17
|
+
readonly value: Codec;
|
|
18
|
+
toNumber(): number;
|
|
19
|
+
}
|
|
20
|
+
export interface IMap<K extends Codec = Codec, V extends Codec = Codec> extends Map<K, V>, Codec {
|
|
21
|
+
}
|
|
22
|
+
export interface INumber extends Codec {
|
|
23
|
+
bitLength(): number;
|
|
24
|
+
toBigInt(): bigint;
|
|
25
|
+
toBn(): BN;
|
|
26
|
+
toNumber(): number;
|
|
27
|
+
}
|
|
28
|
+
export interface IOption<T extends Codec = Codec> extends Codec {
|
|
29
|
+
readonly isNone: boolean;
|
|
30
|
+
readonly isSome: boolean;
|
|
31
|
+
readonly value: Codec;
|
|
32
|
+
unwrap(): T;
|
|
33
|
+
unwrapOr<O>(other: O): T | O;
|
|
34
|
+
unwrapOrDefault(): T;
|
|
35
|
+
}
|
|
36
|
+
export interface IResult<O extends Codec = Codec, E extends Codec = Codec> extends IEnum {
|
|
37
|
+
readonly asErr: E;
|
|
38
|
+
readonly asOk: O;
|
|
39
|
+
readonly isErr: boolean;
|
|
40
|
+
readonly isOk: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface ISet<K = string> extends Set<K>, Codec {
|
|
43
|
+
readonly strings: string[];
|
|
44
|
+
}
|
|
45
|
+
export interface IStruct<K = string, V extends Codec = Codec> extends Map<K, V>, Codec {
|
|
46
|
+
readonly defKeys: string[];
|
|
47
|
+
getAtIndex(index: number): Codec;
|
|
48
|
+
toArray(): Codec[];
|
|
49
|
+
}
|
|
50
|
+
export declare type ITuple<T extends AnyTuple = Codec[]> = T & Codec;
|
|
51
|
+
export interface IU8a extends Uint8Array, Codec {
|
|
52
|
+
readonly isAscii: boolean;
|
|
53
|
+
readonly isUtf8: boolean;
|
|
54
|
+
bitLength(): number;
|
|
55
|
+
toHuman(isExtended?: boolean): any;
|
|
56
|
+
toJSON(): any;
|
|
57
|
+
toUtf8(): string;
|
|
58
|
+
}
|
|
59
|
+
export interface IVec<T extends Codec = Codec> extends Array<T>, Codec {
|
|
60
|
+
toArray(): T[];
|
|
61
|
+
}
|
|
62
|
+
export interface IMethod<A extends AnyTuple = AnyTuple> extends Codec {
|
|
63
|
+
readonly args: A;
|
|
64
|
+
readonly argsDef: ArgsDef;
|
|
65
|
+
readonly callIndex: Uint8Array;
|
|
66
|
+
readonly data: Uint8Array;
|
|
67
|
+
is: (tx: IMethod<AnyTuple>) => tx is IMethod<A>;
|
|
68
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
2
|
+
import type { BN } from '@polkadot/util';
|
|
3
|
+
import type { Codec, CodecClass } from './codec';
|
|
4
|
+
import type { ICompact, IEnum, IMap, IMethod, INumber, IOption, IResult, ISet, IStruct, ITuple, IU8a, IVec } from './interfaces';
|
|
5
|
+
export declare type OnlyCodec<K, T, Types> = K extends keyof Types ? Types[K] : T extends ICompact | IEnum | IMap | IMethod | INumber | IOption | IResult | ISet | IStruct | ITuple | IU8a | IVec ? T : T extends Codec ? T : never;
|
|
6
|
+
export declare type RegistryTypes = Record<string, CodecClass | string | Record<string, string> | {
|
|
7
|
+
_enum: string[] | Record<string, number> | Record<string, string | null>;
|
|
8
|
+
} | {
|
|
9
|
+
_set: Record<string, number>;
|
|
10
|
+
}>;
|
|
11
|
+
export interface CodecCreateOptions {
|
|
12
|
+
blockHash?: Uint8Array | string | null;
|
|
13
|
+
isOptional?: boolean;
|
|
14
|
+
isPedantic?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface CodecRegistry {
|
|
17
|
+
readonly chainDecimals: number[];
|
|
18
|
+
readonly chainSS58: number | undefined;
|
|
19
|
+
readonly chainTokens: string[];
|
|
20
|
+
createdAtHash?: IU8a;
|
|
21
|
+
findMetaCall(callIndex: Uint8Array): unknown;
|
|
22
|
+
findMetaError(errorIndex: Uint8Array | {
|
|
23
|
+
error: BN;
|
|
24
|
+
index: BN;
|
|
25
|
+
}): unknown;
|
|
26
|
+
findMetaEvent(eventIndex: Uint8Array): CodecClass<any>;
|
|
27
|
+
isLookupType(value: string): boolean;
|
|
28
|
+
createLookupType(lookupId: ICompact<INumber> | number): string;
|
|
29
|
+
createClassUnsafe<T extends Codec = Codec, K extends string = string>(type: K): CodecClass<T>;
|
|
30
|
+
createTypeUnsafe<T extends Codec = Codec, K extends string = string>(type: K, params: unknown[], options?: CodecCreateOptions): T;
|
|
31
|
+
getClassName(clazz: CodecClass): string | undefined;
|
|
32
|
+
getOrThrow<T extends Codec = Codec, K extends string = string>(name: K, msg?: string): CodecClass<T>;
|
|
33
|
+
getOrUnknown<T extends Codec = Codec, K extends string = string>(name: K): CodecClass<T>;
|
|
34
|
+
getSignedExtensionExtra(): Record<string, string>;
|
|
35
|
+
getSignedExtensionTypes(): Record<string, string>;
|
|
36
|
+
hasClass(name: string): boolean;
|
|
37
|
+
hasDef(name: string): boolean;
|
|
38
|
+
hasType(name: string): boolean;
|
|
39
|
+
hash(data: Uint8Array): IU8a;
|
|
40
|
+
register(type: CodecClass | RegistryTypes): void;
|
|
41
|
+
register(name: string, type: CodecClass): void;
|
|
42
|
+
register(arg1: string | CodecClass | RegistryTypes, arg2?: CodecClass): void;
|
|
43
|
+
setMetadata(metadata: unknown, signedExtensions?: string[], userExtensions?: unknown): void;
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.compareArray = compareArray;
|
|
7
|
+
|
|
8
|
+
var _util = require("@polkadot/util");
|
|
9
|
+
|
|
10
|
+
var _util2 = require("./util.cjs");
|
|
11
|
+
|
|
12
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
13
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
14
|
+
// NOTE These are used internally and when comparing objects, expects that
|
|
15
|
+
// when the second is an Codec[] that the first has to be as well
|
|
16
|
+
function compareArray(a, b) {
|
|
17
|
+
if (Array.isArray(b)) {
|
|
18
|
+
return a.length === b.length && (0, _util.isUndefined)(a.find((v, index) => (0, _util2.hasEq)(v) ? !v.eq(b[index]) : v !== b[index]));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function compareArray(a: unknown[], b?: unknown): boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { isUndefined } from '@polkadot/util';
|
|
4
|
+
import { hasEq } from "./util.js"; // NOTE These are used internally and when comparing objects, expects that
|
|
5
|
+
// when the second is an Codec[] that the first has to be as well
|
|
6
|
+
|
|
7
|
+
export function compareArray(a, b) {
|
|
8
|
+
if (Array.isArray(b)) {
|
|
9
|
+
return a.length === b.length && isUndefined(a.find((v, index) => hasEq(v) ? !v.eq(b[index]) : v !== b[index]));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.compareMap = compareMap;
|
|
7
|
+
|
|
8
|
+
var _util = require("@polkadot/util");
|
|
9
|
+
|
|
10
|
+
var _util2 = require("./util.cjs");
|
|
11
|
+
|
|
12
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
13
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
14
|
+
function hasMismatch(a, b) {
|
|
15
|
+
return (0, _util.isUndefined)(a) || ((0, _util2.hasEq)(a) ? !a.eq(b) : a !== b);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function notEntry(value) {
|
|
19
|
+
return !Array.isArray(value) || value.length !== 2;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function compareMapArray(a, b) {
|
|
23
|
+
// equal number of entries and each entry in the array should match
|
|
24
|
+
return a.size === b.length && !b.some(e => notEntry(e) || hasMismatch(a.get(e[0]), e[1]));
|
|
25
|
+
} // NOTE These are used internally and when comparing objects, expects that
|
|
26
|
+
// when the second is an Map<string, Codec> that the first has to be as well
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
function compareMap(a, b) {
|
|
30
|
+
if (Array.isArray(b)) {
|
|
31
|
+
return compareMapArray(a, b);
|
|
32
|
+
} else if (b instanceof Map) {
|
|
33
|
+
return compareMapArray(a, [...b.entries()]);
|
|
34
|
+
} else if ((0, _util.isObject)(b)) {
|
|
35
|
+
return compareMapArray(a, Object.entries(b));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function compareMap(a: Map<unknown, unknown>, b?: unknown): boolean;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { isObject, isUndefined } from '@polkadot/util';
|
|
4
|
+
import { hasEq } from "./util.js";
|
|
5
|
+
|
|
6
|
+
function hasMismatch(a, b) {
|
|
7
|
+
return isUndefined(a) || (hasEq(a) ? !a.eq(b) : a !== b);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function notEntry(value) {
|
|
11
|
+
return !Array.isArray(value) || value.length !== 2;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function compareMapArray(a, b) {
|
|
15
|
+
// equal number of entries and each entry in the array should match
|
|
16
|
+
return a.size === b.length && !b.some(e => notEntry(e) || hasMismatch(a.get(e[0]), e[1]));
|
|
17
|
+
} // NOTE These are used internally and when comparing objects, expects that
|
|
18
|
+
// when the second is an Map<string, Codec> that the first has to be as well
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export function compareMap(a, b) {
|
|
22
|
+
if (Array.isArray(b)) {
|
|
23
|
+
return compareMapArray(a, b);
|
|
24
|
+
} else if (b instanceof Map) {
|
|
25
|
+
return compareMapArray(a, [...b.entries()]);
|
|
26
|
+
} else if (isObject(b)) {
|
|
27
|
+
return compareMapArray(a, Object.entries(b));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.compareSet = compareSet;
|
|
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
|
+
function compareSetArray(a, b) {
|
|
13
|
+
// equal number of entries and each entry in the array should match
|
|
14
|
+
return a.size === b.length && !b.some(e => !a.has(e));
|
|
15
|
+
} // NOTE These are used internally and when comparing objects, expects that
|
|
16
|
+
// when the second is an Set<string, Codec> that the first has to be as well
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
function compareSet(a, b) {
|
|
20
|
+
if (Array.isArray(b)) {
|
|
21
|
+
return compareSetArray(a, b);
|
|
22
|
+
} else if (b instanceof Set) {
|
|
23
|
+
return compareSetArray(a, [...b.values()]);
|
|
24
|
+
} else if ((0, _util.isObject)(b)) {
|
|
25
|
+
return compareSetArray(a, Object.values(b));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function compareSet(a: Set<unknown>, b?: unknown): boolean;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { isObject } from '@polkadot/util';
|
|
4
|
+
|
|
5
|
+
function compareSetArray(a, b) {
|
|
6
|
+
// equal number of entries and each entry in the array should match
|
|
7
|
+
return a.size === b.length && !b.some(e => !a.has(e));
|
|
8
|
+
} // NOTE These are used internally and when comparing objects, expects that
|
|
9
|
+
// when the second is an Set<string, Codec> that the first has to be as well
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export function compareSet(a, b) {
|
|
13
|
+
if (Array.isArray(b)) {
|
|
14
|
+
return compareSetArray(a, b);
|
|
15
|
+
} else if (b instanceof Set) {
|
|
16
|
+
return compareSetArray(a, [...b.values()]);
|
|
17
|
+
} else if (isObject(b)) {
|
|
18
|
+
return compareSetArray(a, Object.values(b));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.decodeU8a = decodeU8a;
|
|
7
|
+
exports.decodeU8aVec = decodeU8aVec;
|
|
8
|
+
|
|
9
|
+
var _util = require("@polkadot/util");
|
|
10
|
+
|
|
11
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
12
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
13
|
+
function formatFailure(error, type, u8a, key) {
|
|
14
|
+
return `decodeU8a: failed at ${(0, _util.u8aToHex)(u8a)}…${key ? ` on ${key}` : ''}${type ? `: ${type}` : ''}:: ${error.message}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getRawType(registry, Type) {
|
|
18
|
+
try {
|
|
19
|
+
return new Type(registry).toRawType();
|
|
20
|
+
} catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Given an u8a, and an array of Type constructors, decode the u8a against the
|
|
26
|
+
* types, and return an array of decoded values.
|
|
27
|
+
*
|
|
28
|
+
* @param u8a - The u8a to decode.
|
|
29
|
+
* @param result - The result array (will be returned with values pushed)
|
|
30
|
+
* @param types - The array of CodecClass to decode the U8a against.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
function decodeU8a(registry, u8a, types, withZip) {
|
|
35
|
+
const [Types, keys] = Array.isArray(types) ? [types, []] : [Object.values(types), Object.keys(types)];
|
|
36
|
+
const result = new Array(Types.length);
|
|
37
|
+
let offset = 0;
|
|
38
|
+
|
|
39
|
+
for (let i = 0; i < Types.length; i++) {
|
|
40
|
+
try {
|
|
41
|
+
const value = new Types[i](registry, u8a.subarray(offset));
|
|
42
|
+
offset += value.initialU8aLength || value.encodedLength;
|
|
43
|
+
result[i] = withZip ? [keys[i], value] : value;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
throw new Error(formatFailure(error, getRawType(registry, Types[i]), u8a.subarray(offset, offset + 16), keys[i]));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return [result, offset];
|
|
50
|
+
} // Split from decodeU8a since this is specialized to 1 instance ... yes duplication, but
|
|
51
|
+
// since we have to do less checks (and these are intensive anyway), much faster
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
function decodeU8aVec(registry, u8a, start, Type, count) {
|
|
55
|
+
const result = new Array(count);
|
|
56
|
+
let offset = start;
|
|
57
|
+
|
|
58
|
+
for (let i = 0; i < count; i++) {
|
|
59
|
+
try {
|
|
60
|
+
const value = new Type(registry, u8a.subarray(offset));
|
|
61
|
+
offset += value.initialU8aLength || value.encodedLength;
|
|
62
|
+
result[i] = value;
|
|
63
|
+
} catch (error) {
|
|
64
|
+
throw new Error(formatFailure(error, getRawType(registry, Type), u8a.subarray(offset, offset + 16)));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return [result, offset, offset - start];
|
|
69
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Codec, CodecClass, CodecRegistry } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Given an u8a, and an array of Type constructors, decode the u8a against the
|
|
4
|
+
* types, and return an array of decoded values.
|
|
5
|
+
*
|
|
6
|
+
* @param u8a - The u8a to decode.
|
|
7
|
+
* @param result - The result array (will be returned with values pushed)
|
|
8
|
+
* @param types - The array of CodecClass to decode the U8a against.
|
|
9
|
+
*/
|
|
10
|
+
export declare function decodeU8a<T extends Codec = Codec, E = T>(registry: CodecRegistry, u8a: Uint8Array, types: CodecClass[] | {
|
|
11
|
+
[index: string]: CodecClass;
|
|
12
|
+
}, withZip?: boolean): [E[], number];
|
|
13
|
+
export declare function decodeU8aVec<T extends Codec = Codec>(registry: CodecRegistry, u8a: Uint8Array, start: number, Type: CodecClass<T>, count: number): [T[], number, number];
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { u8aToHex } from '@polkadot/util';
|
|
4
|
+
|
|
5
|
+
function formatFailure(error, type, u8a, key) {
|
|
6
|
+
return `decodeU8a: failed at ${u8aToHex(u8a)}…${key ? ` on ${key}` : ''}${type ? `: ${type}` : ''}:: ${error.message}`;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function getRawType(registry, Type) {
|
|
10
|
+
try {
|
|
11
|
+
return new Type(registry).toRawType();
|
|
12
|
+
} catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Given an u8a, and an array of Type constructors, decode the u8a against the
|
|
18
|
+
* types, and return an array of decoded values.
|
|
19
|
+
*
|
|
20
|
+
* @param u8a - The u8a to decode.
|
|
21
|
+
* @param result - The result array (will be returned with values pushed)
|
|
22
|
+
* @param types - The array of CodecClass to decode the U8a against.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
export function decodeU8a(registry, u8a, types, withZip) {
|
|
27
|
+
const [Types, keys] = Array.isArray(types) ? [types, []] : [Object.values(types), Object.keys(types)];
|
|
28
|
+
const result = new Array(Types.length);
|
|
29
|
+
let offset = 0;
|
|
30
|
+
|
|
31
|
+
for (let i = 0; i < Types.length; i++) {
|
|
32
|
+
try {
|
|
33
|
+
const value = new Types[i](registry, u8a.subarray(offset));
|
|
34
|
+
offset += value.initialU8aLength || value.encodedLength;
|
|
35
|
+
result[i] = withZip ? [keys[i], value] : value;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
throw new Error(formatFailure(error, getRawType(registry, Types[i]), u8a.subarray(offset, offset + 16), keys[i]));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return [result, offset];
|
|
42
|
+
} // Split from decodeU8a since this is specialized to 1 instance ... yes duplication, but
|
|
43
|
+
// since we have to do less checks (and these are intensive anyway), much faster
|
|
44
|
+
|
|
45
|
+
export function decodeU8aVec(registry, u8a, start, Type, count) {
|
|
46
|
+
const result = new Array(count);
|
|
47
|
+
let offset = start;
|
|
48
|
+
|
|
49
|
+
for (let i = 0; i < count; i++) {
|
|
50
|
+
try {
|
|
51
|
+
const value = new Type(registry, u8a.subarray(offset));
|
|
52
|
+
offset += value.initialU8aLength || value.encodedLength;
|
|
53
|
+
result[i] = value;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
throw new Error(formatFailure(error, getRawType(registry, Type), u8a.subarray(offset, offset + 16)));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return [result, offset, offset - start];
|
|
60
|
+
}
|