@polkadot-api/substrate-bindings 0.5.0 → 0.6.1
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/dist/esm/codecs/blockHeader.mjs +42 -0
- package/dist/esm/codecs/blockHeader.mjs.map +1 -0
- package/dist/esm/codecs/metadata/docs.mjs +6 -0
- package/dist/esm/codecs/metadata/docs.mjs.map +1 -0
- package/dist/esm/codecs/metadata/lookup.mjs +72 -0
- package/dist/esm/codecs/metadata/lookup.mjs.map +1 -0
- package/dist/esm/codecs/metadata/metadata.mjs +35 -0
- package/dist/esm/codecs/metadata/metadata.mjs.map +1 -0
- package/dist/esm/codecs/metadata/pallets.mjs +66 -0
- package/dist/esm/codecs/metadata/pallets.mjs.map +1 -0
- package/dist/esm/codecs/metadata/runtime-api.mjs +32 -0
- package/dist/esm/codecs/metadata/runtime-api.mjs.map +1 -0
- package/dist/esm/codecs/metadata/v14.mjs +39 -0
- package/dist/esm/codecs/metadata/v14.mjs.map +1 -0
- package/dist/esm/codecs/metadata/v15.mjs +44 -0
- package/dist/esm/codecs/metadata/v15.mjs.map +1 -0
- package/dist/esm/codecs/scale/AccountId.mjs +21 -0
- package/dist/esm/codecs/scale/AccountId.mjs.map +1 -0
- package/dist/esm/codecs/scale/Binary.mjs +62 -0
- package/dist/esm/codecs/scale/Binary.mjs.map +1 -0
- package/dist/esm/codecs/scale/Hex.mjs +17 -0
- package/dist/esm/codecs/scale/Hex.mjs.map +1 -0
- package/dist/esm/codecs/scale/Self.mjs +26 -0
- package/dist/esm/codecs/scale/Self.mjs.map +1 -0
- package/dist/esm/codecs/scale/Variant.mjs +30 -0
- package/dist/esm/codecs/scale/Variant.mjs.map +1 -0
- package/dist/esm/codecs/scale/bitSequence.mjs +24 -0
- package/dist/esm/codecs/scale/bitSequence.mjs.map +1 -0
- package/dist/esm/codecs/scale/char.mjs +10 -0
- package/dist/esm/codecs/scale/char.mjs.map +1 -0
- package/dist/esm/codecs/scale/compact.mjs +7 -0
- package/dist/esm/codecs/scale/compact.mjs.map +1 -0
- package/dist/esm/codecs/scale/ethAccount.mjs +32 -0
- package/dist/esm/codecs/scale/ethAccount.mjs.map +1 -0
- package/dist/esm/codecs/scale/fixed-str.mjs +12 -0
- package/dist/esm/codecs/scale/fixed-str.mjs.map +1 -0
- package/dist/esm/hashes/blake2.mjs +11 -0
- package/dist/esm/hashes/blake2.mjs.map +1 -0
- package/dist/esm/hashes/blake3.mjs +9 -0
- package/dist/esm/hashes/blake3.mjs.map +1 -0
- package/dist/esm/hashes/h64.mjs +134 -0
- package/dist/esm/hashes/h64.mjs.map +1 -0
- package/dist/esm/hashes/identity.mjs +4 -0
- package/dist/esm/hashes/identity.mjs.map +1 -0
- package/dist/esm/hashes/twoX.mjs +24 -0
- package/dist/esm/hashes/twoX.mjs.map +1 -0
- package/dist/esm/index.mjs +24 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/storage.mjs +53 -0
- package/dist/esm/storage.mjs.map +1 -0
- package/dist/esm/types/enum.mjs +29 -0
- package/dist/esm/types/enum.mjs.map +1 -0
- package/dist/esm/utils/ss58-util.mjs +55 -0
- package/dist/esm/utils/ss58-util.mjs.map +1 -0
- package/dist/index.d.ts +9 -6
- package/dist/index.js +406 -422
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/dist/index.d.mts +0 -1091
- package/dist/index.mjs +0 -916
- package/dist/index.mjs.map +0 -1
- package/dist/min/index.d.ts +0 -1091
- package/dist/min/index.js +0 -2
- package/dist/min/index.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,136 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var __publicField = (obj, key, value) => {
|
|
21
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
|
-
return value;
|
|
23
|
-
};
|
|
24
|
-
var __accessCheck = (obj, member, msg) => {
|
|
25
|
-
if (!member.has(obj))
|
|
26
|
-
throw TypeError("Cannot " + msg);
|
|
27
|
-
};
|
|
28
|
-
var __privateGet = (obj, member, getter) => {
|
|
29
|
-
__accessCheck(obj, member, "read from private field");
|
|
30
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
31
|
-
};
|
|
32
|
-
var __privateAdd = (obj, member, value) => {
|
|
33
|
-
if (member.has(obj))
|
|
34
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
35
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
36
|
-
};
|
|
37
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
38
|
-
__accessCheck(obj, member, "write to private field");
|
|
39
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
40
|
-
return value;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// src/index.ts
|
|
44
|
-
var src_exports = {};
|
|
45
|
-
__export(src_exports, {
|
|
46
|
-
AccountId: () => AccountId,
|
|
47
|
-
Bin: () => Bin,
|
|
48
|
-
Binary: () => Binary,
|
|
49
|
-
Blake2128: () => Blake2128,
|
|
50
|
-
Blake2128Concat: () => Blake2128Concat,
|
|
51
|
-
Blake2256: () => Blake2256,
|
|
52
|
-
Bytes: () => import_scale_ts8.Bytes,
|
|
53
|
-
Enum: () => Enum,
|
|
54
|
-
FixedSizeBinary: () => FixedSizeBinary,
|
|
55
|
-
Hex: () => Hex,
|
|
56
|
-
Identity: () => Identity,
|
|
57
|
-
Option: () => import_scale_ts8.Option,
|
|
58
|
-
Result: () => import_scale_ts8.Result,
|
|
59
|
-
Self: () => Self,
|
|
60
|
-
Storage: () => Storage,
|
|
61
|
-
Struct: () => import_scale_ts8.Struct,
|
|
62
|
-
Tuple: () => import_scale_ts8.Tuple,
|
|
63
|
-
Twox128: () => Twox128,
|
|
64
|
-
Twox256: () => Twox256,
|
|
65
|
-
Twox64Concat: () => Twox64Concat,
|
|
66
|
-
Variant: () => Variant,
|
|
67
|
-
Vector: () => import_scale_ts8.Vector,
|
|
68
|
-
_Enum: () => _Enum,
|
|
69
|
-
_void: () => import_scale_ts8._void,
|
|
70
|
-
bitSequence: () => bitSequence,
|
|
71
|
-
blockHeader: () => blockHeader,
|
|
72
|
-
bool: () => import_scale_ts8.bool,
|
|
73
|
-
char: () => char,
|
|
74
|
-
compact: () => import_scale_ts8.compact,
|
|
75
|
-
compactBn: () => compactBn,
|
|
76
|
-
compactNumber: () => compactNumber,
|
|
77
|
-
createCodec: () => import_scale_ts8.createCodec,
|
|
78
|
-
createDecoder: () => import_scale_ts8.createDecoder,
|
|
79
|
-
enhanceCodec: () => import_scale_ts8.enhanceCodec,
|
|
80
|
-
enhanceDecoder: () => import_scale_ts8.enhanceDecoder,
|
|
81
|
-
enhanceEncoder: () => import_scale_ts8.enhanceEncoder,
|
|
82
|
-
ethAccount: () => ethAccount,
|
|
83
|
-
fixedStr: () => fixedStr,
|
|
84
|
-
fromBufferToBase58: () => fromBufferToBase58,
|
|
85
|
-
getSs58AddressInfo: () => getSs58AddressInfo,
|
|
86
|
-
h64: () => h64,
|
|
87
|
-
i128: () => import_scale_ts8.i128,
|
|
88
|
-
i16: () => import_scale_ts8.i16,
|
|
89
|
-
i256: () => import_scale_ts8.i256,
|
|
90
|
-
i32: () => import_scale_ts8.i32,
|
|
91
|
-
i64: () => import_scale_ts8.i64,
|
|
92
|
-
i8: () => import_scale_ts8.i8,
|
|
93
|
-
metadata: () => metadata,
|
|
94
|
-
selfDecoder: () => selfDecoder,
|
|
95
|
-
selfEncoder: () => selfEncoder,
|
|
96
|
-
str: () => import_scale_ts8.str,
|
|
97
|
-
u128: () => import_scale_ts8.u128,
|
|
98
|
-
u16: () => import_scale_ts8.u16,
|
|
99
|
-
u256: () => import_scale_ts8.u256,
|
|
100
|
-
u32: () => import_scale_ts8.u32,
|
|
101
|
-
u64: () => import_scale_ts8.u64,
|
|
102
|
-
u8: () => import_scale_ts8.u8,
|
|
103
|
-
v14: () => v14,
|
|
104
|
-
v15: () => v15
|
|
105
|
-
});
|
|
106
|
-
module.exports = __toCommonJS(src_exports);
|
|
107
|
-
|
|
108
|
-
// src/codecs/scale/AccountId.ts
|
|
109
|
-
var import_scale_ts = require("scale-ts");
|
|
110
|
-
|
|
111
|
-
// src/utils/ss58-util.ts
|
|
112
|
-
var import_base = require("@scure/base");
|
|
113
|
-
var import_blake2b = require("@noble/hashes/blake2b");
|
|
114
|
-
var SS58_PREFIX = new TextEncoder().encode("SS58PRE");
|
|
115
|
-
var CHECKSUM_LENGTH = 2;
|
|
116
|
-
var getSs58AddressInfo = (address) => {
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var scaleTs = require('scale-ts');
|
|
4
|
+
var base = require('@scure/base');
|
|
5
|
+
var blake2b = require('@noble/hashes/blake2b');
|
|
6
|
+
var utils = require('@polkadot-api/utils');
|
|
7
|
+
var sha3 = require('@noble/hashes/sha3');
|
|
8
|
+
var blake3 = require('@noble/hashes/blake3');
|
|
9
|
+
|
|
10
|
+
const SS58_PREFIX = new TextEncoder().encode("SS58PRE");
|
|
11
|
+
const CHECKSUM_LENGTH = 2;
|
|
12
|
+
const getSs58AddressInfo = (address) => {
|
|
117
13
|
try {
|
|
118
|
-
const decoded =
|
|
14
|
+
const decoded = base.base58.decode(address);
|
|
119
15
|
const prefixBytes = decoded.subarray(0, decoded[0] & 64 ? 2 : 1);
|
|
120
16
|
const publicKey = decoded.subarray(
|
|
121
17
|
prefixBytes.length,
|
|
122
18
|
decoded.length - CHECKSUM_LENGTH
|
|
123
19
|
);
|
|
124
20
|
const checksum = decoded.subarray(prefixBytes.length + publicKey.length);
|
|
125
|
-
const expectedChecksum =
|
|
21
|
+
const expectedChecksum = blake2b.blake2b(
|
|
126
22
|
Uint8Array.of(...SS58_PREFIX, ...prefixBytes, ...publicKey),
|
|
127
23
|
{
|
|
128
24
|
dkLen: 64
|
|
129
25
|
}
|
|
130
26
|
).subarray(0, CHECKSUM_LENGTH);
|
|
131
27
|
const isChecksumValid = checksum[0] === expectedChecksum[0] && checksum[1] === expectedChecksum[1];
|
|
132
|
-
if (!isChecksumValid)
|
|
133
|
-
return { isValid: false };
|
|
28
|
+
if (!isChecksumValid) return { isValid: false };
|
|
134
29
|
return {
|
|
135
30
|
isValid: true,
|
|
136
31
|
ss58Format: prefixBytesToNumber(prefixBytes),
|
|
@@ -140,67 +35,72 @@ var getSs58AddressInfo = (address) => {
|
|
|
140
35
|
return { isValid: false };
|
|
141
36
|
}
|
|
142
37
|
};
|
|
143
|
-
|
|
38
|
+
const prefixBytesToNumber = (bytes) => {
|
|
144
39
|
const dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
145
40
|
return dv.byteLength === 1 ? dv.getUint8(0) : dv.getUint16(0);
|
|
146
41
|
};
|
|
147
|
-
|
|
42
|
+
const fromBufferToBase58 = (ss58Format) => {
|
|
148
43
|
const prefixBytes = ss58Format < 64 ? Uint8Array.of(ss58Format) : Uint8Array.of(
|
|
149
44
|
(ss58Format & 252) >> 2 | 64,
|
|
150
45
|
ss58Format >> 8 | (ss58Format & 3) << 6
|
|
151
46
|
);
|
|
152
47
|
return (publicKey) => {
|
|
153
|
-
const checksum =
|
|
48
|
+
const checksum = blake2b.blake2b(
|
|
154
49
|
Uint8Array.of(...SS58_PREFIX, ...prefixBytes, ...publicKey),
|
|
155
50
|
{
|
|
156
51
|
dkLen: 64
|
|
157
52
|
}
|
|
158
53
|
).subarray(0, CHECKSUM_LENGTH);
|
|
159
|
-
return
|
|
54
|
+
return base.base58.encode(
|
|
160
55
|
Uint8Array.of(...prefixBytes, ...publicKey, ...checksum)
|
|
161
56
|
);
|
|
162
57
|
};
|
|
163
58
|
};
|
|
164
59
|
|
|
165
|
-
// src/codecs/scale/AccountId.ts
|
|
166
60
|
function fromBase58ToBuffer(nBytes, _ss58Format) {
|
|
167
61
|
return (address) => {
|
|
168
62
|
const info = getSs58AddressInfo(address);
|
|
169
|
-
if (!info.isValid)
|
|
170
|
-
throw new Error("Invalid checksum");
|
|
63
|
+
if (!info.isValid) throw new Error("Invalid checksum");
|
|
171
64
|
const { publicKey } = info;
|
|
172
65
|
if (publicKey.length !== nBytes)
|
|
173
66
|
throw new Error("Invalid public key length");
|
|
174
67
|
return publicKey;
|
|
175
68
|
};
|
|
176
69
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
fromBase58ToBuffer(nBytes
|
|
70
|
+
const AccountId = (ss58Format = 42, nBytes = 32) => scaleTs.enhanceCodec(
|
|
71
|
+
scaleTs.Bytes(nBytes),
|
|
72
|
+
fromBase58ToBuffer(nBytes),
|
|
180
73
|
fromBufferToBase58(ss58Format)
|
|
181
74
|
);
|
|
182
75
|
|
|
183
|
-
|
|
184
|
-
var
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
var
|
|
76
|
+
var __defProp = Object.defineProperty;
|
|
77
|
+
var __typeError = (msg) => {
|
|
78
|
+
throw TypeError(msg);
|
|
79
|
+
};
|
|
80
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
81
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
82
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
83
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
84
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
85
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
188
86
|
var _bytes, _hex, _str;
|
|
189
|
-
|
|
87
|
+
const textEncoder$3 = new TextEncoder();
|
|
88
|
+
const textDecoder$2 = new TextDecoder();
|
|
89
|
+
const _Binary = class _Binary {
|
|
190
90
|
constructor(data) {
|
|
191
|
-
__privateAdd(this, _bytes
|
|
91
|
+
__privateAdd(this, _bytes);
|
|
192
92
|
__privateAdd(this, _hex, null);
|
|
193
93
|
__privateAdd(this, _str, null);
|
|
194
|
-
__publicField(this, "asText", () => __privateGet(this, _str) === null ? __privateSet(this, _str, textDecoder.decode(__privateGet(this, _bytes))) : __privateGet(this, _str));
|
|
195
|
-
__publicField(this, "asHex", () => __privateGet(this, _hex) === null ? __privateSet(this, _hex,
|
|
94
|
+
__publicField(this, "asText", () => __privateGet(this, _str) === null ? __privateSet(this, _str, textDecoder$2.decode(__privateGet(this, _bytes))) : __privateGet(this, _str));
|
|
95
|
+
__publicField(this, "asHex", () => __privateGet(this, _hex) === null ? __privateSet(this, _hex, utils.toHex(__privateGet(this, _bytes))) : __privateGet(this, _hex));
|
|
196
96
|
__publicField(this, "asBytes", () => __privateGet(this, _bytes));
|
|
197
97
|
__privateSet(this, _bytes, data);
|
|
198
98
|
}
|
|
199
99
|
static fromText(input) {
|
|
200
|
-
return new _Binary(textEncoder.encode(input));
|
|
100
|
+
return new _Binary(textEncoder$3.encode(input));
|
|
201
101
|
}
|
|
202
102
|
static fromHex(input) {
|
|
203
|
-
return new _Binary(
|
|
103
|
+
return new _Binary(utils.fromHex(input));
|
|
204
104
|
}
|
|
205
105
|
static fromBytes(input) {
|
|
206
106
|
return new _Binary(input);
|
|
@@ -209,43 +109,37 @@ var _Binary = class _Binary {
|
|
|
209
109
|
_bytes = new WeakMap();
|
|
210
110
|
_hex = new WeakMap();
|
|
211
111
|
_str = new WeakMap();
|
|
212
|
-
|
|
213
|
-
|
|
112
|
+
let Binary = _Binary;
|
|
113
|
+
class FixedSizeBinary extends Binary {
|
|
214
114
|
constructor(data) {
|
|
215
115
|
super(data);
|
|
216
116
|
}
|
|
217
117
|
static fromArray(input) {
|
|
218
|
-
return new
|
|
118
|
+
return new FixedSizeBinary(new Uint8Array(input));
|
|
219
119
|
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
const _enc =
|
|
120
|
+
}
|
|
121
|
+
const enc$1 = (nBytes) => {
|
|
122
|
+
const _enc = scaleTs.Bytes.enc(nBytes);
|
|
223
123
|
return (value) => _enc(value.asBytes());
|
|
224
124
|
};
|
|
225
|
-
|
|
226
|
-
const _dec =
|
|
125
|
+
const dec$1 = (nBytes) => {
|
|
126
|
+
const _dec = scaleTs.Bytes.dec(nBytes);
|
|
227
127
|
return (value) => Binary.fromBytes(_dec(value));
|
|
228
128
|
};
|
|
229
|
-
|
|
230
|
-
Bin.enc = enc;
|
|
231
|
-
Bin.dec = dec;
|
|
129
|
+
const Bin = (nBytes) => scaleTs.createCodec(enc$1(nBytes), dec$1(nBytes));
|
|
130
|
+
Bin.enc = enc$1;
|
|
131
|
+
Bin.dec = dec$1;
|
|
232
132
|
|
|
233
|
-
|
|
234
|
-
|
|
133
|
+
const compactNumber = scaleTs.compact;
|
|
134
|
+
const compactBn = scaleTs.compact;
|
|
235
135
|
|
|
236
|
-
|
|
237
|
-
var import_scale_ts3 = require("scale-ts");
|
|
238
|
-
var compactNumber = import_scale_ts3.compact;
|
|
239
|
-
var compactBn = import_scale_ts3.compact;
|
|
240
|
-
|
|
241
|
-
// src/codecs/scale/bitSequence.ts
|
|
242
|
-
var bitSequenceDecoder = (0, import_scale_ts4.createDecoder)((data) => {
|
|
136
|
+
const bitSequenceDecoder = scaleTs.createDecoder((data) => {
|
|
243
137
|
const bitsLen = compactNumber.dec(data);
|
|
244
138
|
const bytesLen = Math.ceil(bitsLen / 8);
|
|
245
|
-
const bytes =
|
|
139
|
+
const bytes = scaleTs.Bytes(bytesLen).dec(data);
|
|
246
140
|
return { bytes, bitsLen };
|
|
247
141
|
});
|
|
248
|
-
|
|
142
|
+
const bitSequenceEncoder = (input) => {
|
|
249
143
|
if (input.bitsLen > input.bytes.length * 8)
|
|
250
144
|
throw new Error(
|
|
251
145
|
`Not enough bytes. (bitsLen:${input.bitsLen}, bytesLen:${input.bytes.length})`
|
|
@@ -256,47 +150,35 @@ var bitSequenceEncoder = (input) => {
|
|
|
256
150
|
result.set(input.bytes, lenEncoded.length);
|
|
257
151
|
return result;
|
|
258
152
|
};
|
|
259
|
-
|
|
153
|
+
const bitSequence$1 = scaleTs.createCodec(bitSequenceEncoder, bitSequenceDecoder);
|
|
260
154
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
import_scale_ts5.u8,
|
|
265
|
-
(str8) => str8.charCodeAt(0),
|
|
155
|
+
const char = scaleTs.enhanceCodec(
|
|
156
|
+
scaleTs.u8,
|
|
157
|
+
(str) => str.charCodeAt(0),
|
|
266
158
|
String.fromCharCode
|
|
267
159
|
);
|
|
268
160
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
var enc2 = (nBytes) => {
|
|
273
|
-
const _enc = import_scale_ts6.Bytes.enc(nBytes);
|
|
274
|
-
return (value) => _enc((0, import_utils2.fromHex)(value));
|
|
161
|
+
const enc = (nBytes) => {
|
|
162
|
+
const _enc = scaleTs.Bytes.enc(nBytes);
|
|
163
|
+
return (value) => _enc(utils.fromHex(value));
|
|
275
164
|
};
|
|
276
|
-
|
|
277
|
-
const _dec =
|
|
278
|
-
return (value) =>
|
|
165
|
+
const dec = (nBytes) => {
|
|
166
|
+
const _dec = scaleTs.Bytes.dec(nBytes);
|
|
167
|
+
return (value) => utils.toHex(_dec(value));
|
|
279
168
|
};
|
|
280
|
-
|
|
281
|
-
Hex.enc =
|
|
282
|
-
Hex.dec =
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
(
|
|
290
|
-
(str8) => textEncoder2.encode(str8),
|
|
291
|
-
(bytes) => textDecoder2.decode(bytes)
|
|
169
|
+
const Hex = (nBytes) => scaleTs.createCodec(enc(nBytes), dec(nBytes));
|
|
170
|
+
Hex.enc = enc;
|
|
171
|
+
Hex.dec = dec;
|
|
172
|
+
|
|
173
|
+
const textEncoder$2 = new TextEncoder();
|
|
174
|
+
const textDecoder$1 = new TextDecoder();
|
|
175
|
+
const fixedStr = (nBytes) => scaleTs.enhanceCodec(
|
|
176
|
+
scaleTs.Bytes(nBytes),
|
|
177
|
+
(str) => textEncoder$2.encode(str),
|
|
178
|
+
(bytes) => textDecoder$1.decode(bytes)
|
|
292
179
|
);
|
|
293
180
|
|
|
294
|
-
|
|
295
|
-
var import_scale_ts8 = require("scale-ts");
|
|
296
|
-
|
|
297
|
-
// src/codecs/scale/Self.ts
|
|
298
|
-
var import_scale_ts9 = require("scale-ts");
|
|
299
|
-
var selfEncoder = (value) => {
|
|
181
|
+
const selfEncoder = (value) => {
|
|
300
182
|
let cache = (x) => {
|
|
301
183
|
const encoder = value();
|
|
302
184
|
cache = encoder;
|
|
@@ -304,7 +186,7 @@ var selfEncoder = (value) => {
|
|
|
304
186
|
};
|
|
305
187
|
return (x) => cache(x);
|
|
306
188
|
};
|
|
307
|
-
|
|
189
|
+
const selfDecoder = (value) => {
|
|
308
190
|
let cache = (x) => {
|
|
309
191
|
const decoder = value();
|
|
310
192
|
const result = decoder;
|
|
@@ -313,17 +195,12 @@ var selfDecoder = (value) => {
|
|
|
313
195
|
};
|
|
314
196
|
return (x) => cache(x);
|
|
315
197
|
};
|
|
316
|
-
|
|
198
|
+
const Self = (value) => scaleTs.createCodec(
|
|
317
199
|
selfEncoder(() => value().enc),
|
|
318
200
|
selfDecoder(() => value().dec)
|
|
319
201
|
);
|
|
320
202
|
|
|
321
|
-
|
|
322
|
-
var import_scale_ts10 = require("scale-ts");
|
|
323
|
-
var import_utils3 = require("@polkadot-api/utils");
|
|
324
|
-
|
|
325
|
-
// src/types/enum.ts
|
|
326
|
-
var discriminant = {
|
|
203
|
+
const discriminant = {
|
|
327
204
|
is(value, type) {
|
|
328
205
|
return value.type === type;
|
|
329
206
|
},
|
|
@@ -335,13 +212,13 @@ var discriminant = {
|
|
|
335
212
|
return value;
|
|
336
213
|
}
|
|
337
214
|
};
|
|
338
|
-
|
|
215
|
+
const Enum = Object.assign((type, value) => {
|
|
339
216
|
return {
|
|
340
217
|
type,
|
|
341
218
|
value
|
|
342
219
|
};
|
|
343
220
|
}, discriminant);
|
|
344
|
-
|
|
221
|
+
const _Enum = new Proxy(
|
|
345
222
|
{},
|
|
346
223
|
{
|
|
347
224
|
get(_, prop) {
|
|
@@ -350,236 +227,213 @@ var _Enum = new Proxy(
|
|
|
350
227
|
}
|
|
351
228
|
);
|
|
352
229
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
return (v) => enc3({ tag: v.type, value: v.value });
|
|
230
|
+
const VariantEnc = (...args) => {
|
|
231
|
+
const enc = scaleTs.Enum.enc(...args);
|
|
232
|
+
return (v) => enc({ tag: v.type, value: v.value });
|
|
357
233
|
};
|
|
358
|
-
|
|
359
|
-
const
|
|
234
|
+
const VariantDec = (...args) => {
|
|
235
|
+
const dec = scaleTs.Enum.dec(...args);
|
|
360
236
|
return (v) => {
|
|
361
|
-
const { tag, value } =
|
|
237
|
+
const { tag, value } = dec(v);
|
|
362
238
|
return Enum(tag, value);
|
|
363
239
|
};
|
|
364
240
|
};
|
|
365
|
-
|
|
241
|
+
const Variant = (inner, ...args) => scaleTs.createCodec(
|
|
366
242
|
VariantEnc(
|
|
367
|
-
|
|
243
|
+
utils.mapObject(inner, ([encoder]) => encoder),
|
|
368
244
|
...args
|
|
369
245
|
),
|
|
370
246
|
VariantDec(
|
|
371
|
-
|
|
247
|
+
utils.mapObject(inner, ([, decoder]) => decoder),
|
|
372
248
|
...args
|
|
373
249
|
)
|
|
374
250
|
);
|
|
375
251
|
Variant.enc = VariantEnc;
|
|
376
252
|
Variant.dec = VariantDec;
|
|
377
253
|
|
|
378
|
-
|
|
379
|
-
var import_utils4 = require("@polkadot-api/utils");
|
|
380
|
-
var import_scale_ts11 = require("scale-ts");
|
|
381
|
-
var import_sha3 = require("@noble/hashes/sha3");
|
|
382
|
-
var getFormattedAddress = (hexAddress) => {
|
|
254
|
+
const getFormattedAddress = (hexAddress) => {
|
|
383
255
|
const nonChecksum = hexAddress.slice(2);
|
|
384
|
-
const hashedAddress =
|
|
256
|
+
const hashedAddress = utils.toHex(sha3.keccak_256(nonChecksum)).slice(2);
|
|
385
257
|
const result = new Array(40);
|
|
386
258
|
for (let i = 0; i < 40; i++) {
|
|
387
259
|
const checksumVal = parseInt(hashedAddress[i], 16);
|
|
388
|
-
const
|
|
389
|
-
result[i] = checksumVal > 7 ?
|
|
260
|
+
const char = nonChecksum[i];
|
|
261
|
+
result[i] = checksumVal > 7 ? char.toUpperCase() : char;
|
|
390
262
|
}
|
|
391
263
|
return `0x${result.join("")}`;
|
|
392
264
|
};
|
|
393
|
-
|
|
394
|
-
|
|
265
|
+
const bytes20Dec = scaleTs.Bytes(20)[1];
|
|
266
|
+
const ethAccount = scaleTs.createCodec(
|
|
395
267
|
(input) => {
|
|
396
|
-
const bytes =
|
|
268
|
+
const bytes = utils.fromHex(input);
|
|
397
269
|
if (bytes.length !== 20)
|
|
398
270
|
throw new Error(`Invalid length found on EthAddress(${input})`);
|
|
399
|
-
const hexAddress =
|
|
400
|
-
if (input === hexAddress || input === hexAddress.toUpperCase())
|
|
401
|
-
return bytes;
|
|
271
|
+
const hexAddress = utils.toHex(bytes);
|
|
272
|
+
if (input === hexAddress || input === hexAddress.toUpperCase()) return bytes;
|
|
402
273
|
if (getFormattedAddress(hexAddress) !== input)
|
|
403
274
|
throw new Error(`Invalid checksum found on EthAddress(${input})`);
|
|
404
275
|
return bytes;
|
|
405
276
|
},
|
|
406
|
-
|
|
277
|
+
scaleTs.createDecoder((bytes) => getFormattedAddress(utils.toHex(bytes20Dec(bytes))))
|
|
407
278
|
);
|
|
408
279
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
textDecoder3.decode.bind(textDecoder3)
|
|
280
|
+
const textEncoder$1 = new TextEncoder();
|
|
281
|
+
const textDecoder = new TextDecoder();
|
|
282
|
+
const fourChars = scaleTs.enhanceCodec(
|
|
283
|
+
scaleTs.Bytes(4),
|
|
284
|
+
textEncoder$1.encode.bind(textEncoder$1),
|
|
285
|
+
textDecoder.decode.bind(textDecoder)
|
|
416
286
|
);
|
|
417
|
-
|
|
287
|
+
const diggestVal = scaleTs.Struct({
|
|
418
288
|
engine: fourChars,
|
|
419
289
|
payload: Hex()
|
|
420
290
|
});
|
|
421
|
-
|
|
291
|
+
const diggest = Variant(
|
|
422
292
|
{
|
|
423
293
|
consensus: diggestVal,
|
|
424
294
|
seal: diggestVal,
|
|
425
295
|
preRuntime: diggestVal,
|
|
426
|
-
runtimeUpdated:
|
|
296
|
+
runtimeUpdated: scaleTs._void
|
|
427
297
|
},
|
|
428
298
|
[4, 5, 6, 8]
|
|
429
299
|
);
|
|
430
|
-
|
|
431
|
-
|
|
300
|
+
const hex32 = Hex(32);
|
|
301
|
+
const blockHeader = scaleTs.Struct({
|
|
432
302
|
parentHash: hex32,
|
|
433
303
|
number: compactNumber,
|
|
434
304
|
stateRoot: hex32,
|
|
435
305
|
extrinsicRoot: hex32,
|
|
436
|
-
digests:
|
|
306
|
+
digests: scaleTs.Vector(diggest)
|
|
437
307
|
});
|
|
438
308
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
u64: import_scale_ts13._void,
|
|
462
|
-
u128: import_scale_ts13._void,
|
|
463
|
-
u256: import_scale_ts13._void,
|
|
464
|
-
i8: import_scale_ts13._void,
|
|
465
|
-
i16: import_scale_ts13._void,
|
|
466
|
-
i32: import_scale_ts13._void,
|
|
467
|
-
i64: import_scale_ts13._void,
|
|
468
|
-
i128: import_scale_ts13._void,
|
|
469
|
-
i256: import_scale_ts13._void
|
|
470
|
-
});
|
|
471
|
-
var fields = (0, import_scale_ts13.Vector)(
|
|
472
|
-
(0, import_scale_ts13.Struct)({
|
|
309
|
+
const docs = scaleTs.Vector(scaleTs.str);
|
|
310
|
+
|
|
311
|
+
const oStr = scaleTs.Option(scaleTs.str);
|
|
312
|
+
const primitive = scaleTs.Enum({
|
|
313
|
+
bool: scaleTs._void,
|
|
314
|
+
char: scaleTs._void,
|
|
315
|
+
str: scaleTs._void,
|
|
316
|
+
u8: scaleTs._void,
|
|
317
|
+
u16: scaleTs._void,
|
|
318
|
+
u32: scaleTs._void,
|
|
319
|
+
u64: scaleTs._void,
|
|
320
|
+
u128: scaleTs._void,
|
|
321
|
+
u256: scaleTs._void,
|
|
322
|
+
i8: scaleTs._void,
|
|
323
|
+
i16: scaleTs._void,
|
|
324
|
+
i32: scaleTs._void,
|
|
325
|
+
i64: scaleTs._void,
|
|
326
|
+
i128: scaleTs._void,
|
|
327
|
+
i256: scaleTs._void
|
|
328
|
+
});
|
|
329
|
+
const fields = scaleTs.Vector(
|
|
330
|
+
scaleTs.Struct({
|
|
473
331
|
name: oStr,
|
|
474
332
|
type: compactNumber,
|
|
475
333
|
typeName: oStr,
|
|
476
334
|
docs
|
|
477
335
|
})
|
|
478
336
|
);
|
|
479
|
-
|
|
480
|
-
len:
|
|
337
|
+
const arr = scaleTs.Struct({
|
|
338
|
+
len: scaleTs.u32,
|
|
481
339
|
type: compactNumber
|
|
482
340
|
});
|
|
483
|
-
|
|
341
|
+
const bitSequence = scaleTs.Struct({
|
|
484
342
|
bitStoreType: compactNumber,
|
|
485
343
|
bitOrderType: compactNumber
|
|
486
344
|
});
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
name:
|
|
345
|
+
const variant = scaleTs.Vector(
|
|
346
|
+
scaleTs.Struct({
|
|
347
|
+
name: scaleTs.str,
|
|
490
348
|
fields,
|
|
491
|
-
index:
|
|
349
|
+
index: scaleTs.u8,
|
|
492
350
|
docs
|
|
493
351
|
})
|
|
494
352
|
);
|
|
495
|
-
|
|
353
|
+
const def = scaleTs.Enum({
|
|
496
354
|
composite: fields,
|
|
497
355
|
variant,
|
|
498
356
|
sequence: compactNumber,
|
|
499
357
|
array: arr,
|
|
500
|
-
tuple:
|
|
358
|
+
tuple: scaleTs.Vector(compactNumber),
|
|
501
359
|
primitive,
|
|
502
360
|
compact: compactNumber,
|
|
503
|
-
bitSequence
|
|
361
|
+
bitSequence
|
|
504
362
|
});
|
|
505
|
-
|
|
506
|
-
name:
|
|
507
|
-
type:
|
|
363
|
+
const param = scaleTs.Struct({
|
|
364
|
+
name: scaleTs.str,
|
|
365
|
+
type: scaleTs.Option(compactNumber)
|
|
508
366
|
});
|
|
509
|
-
|
|
510
|
-
|
|
367
|
+
const params = scaleTs.Vector(param);
|
|
368
|
+
const entry = scaleTs.Struct({
|
|
511
369
|
id: compactNumber,
|
|
512
370
|
path: docs,
|
|
513
371
|
params,
|
|
514
372
|
def,
|
|
515
373
|
docs
|
|
516
374
|
});
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
var hashers = (0, import_scale_ts14.Vector)(hashType);
|
|
531
|
-
var storageMap = (0, import_scale_ts14.Struct)({
|
|
375
|
+
const lookup = scaleTs.Vector(entry);
|
|
376
|
+
|
|
377
|
+
const hashType = scaleTs.Enum({
|
|
378
|
+
Blake2128: scaleTs._void,
|
|
379
|
+
Blake2256: scaleTs._void,
|
|
380
|
+
Blake2128Concat: scaleTs._void,
|
|
381
|
+
Twox128: scaleTs._void,
|
|
382
|
+
Twox256: scaleTs._void,
|
|
383
|
+
Twox64Concat: scaleTs._void,
|
|
384
|
+
Identity: scaleTs._void
|
|
385
|
+
});
|
|
386
|
+
const hashers = scaleTs.Vector(hashType);
|
|
387
|
+
const storageMap = scaleTs.Struct({
|
|
532
388
|
hashers,
|
|
533
389
|
key: compactNumber,
|
|
534
390
|
value: compactNumber
|
|
535
391
|
});
|
|
536
|
-
|
|
537
|
-
name:
|
|
538
|
-
modifier:
|
|
539
|
-
type:
|
|
392
|
+
const storageItem = scaleTs.Struct({
|
|
393
|
+
name: scaleTs.str,
|
|
394
|
+
modifier: scaleTs.u8,
|
|
395
|
+
type: scaleTs.Enum({
|
|
540
396
|
plain: compactNumber,
|
|
541
397
|
map: storageMap
|
|
542
398
|
}),
|
|
543
399
|
fallback: Hex(),
|
|
544
400
|
docs
|
|
545
401
|
});
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
prefix:
|
|
549
|
-
items:
|
|
402
|
+
const storage = scaleTs.Option(
|
|
403
|
+
scaleTs.Struct({
|
|
404
|
+
prefix: scaleTs.str,
|
|
405
|
+
items: scaleTs.Vector(storageItem)
|
|
550
406
|
})
|
|
551
407
|
);
|
|
552
|
-
|
|
553
|
-
name:
|
|
408
|
+
const v14Pallet = {
|
|
409
|
+
name: scaleTs.str,
|
|
554
410
|
storage,
|
|
555
|
-
calls:
|
|
556
|
-
events:
|
|
557
|
-
constants:
|
|
558
|
-
|
|
559
|
-
name:
|
|
411
|
+
calls: scaleTs.Option(compactNumber),
|
|
412
|
+
events: scaleTs.Option(compactNumber),
|
|
413
|
+
constants: scaleTs.Vector(
|
|
414
|
+
scaleTs.Struct({
|
|
415
|
+
name: scaleTs.str,
|
|
560
416
|
type: compactNumber,
|
|
561
417
|
value: Hex(),
|
|
562
418
|
docs
|
|
563
419
|
})
|
|
564
420
|
),
|
|
565
|
-
errors:
|
|
566
|
-
index:
|
|
421
|
+
errors: scaleTs.Option(compactNumber),
|
|
422
|
+
index: scaleTs.u8
|
|
567
423
|
};
|
|
568
|
-
|
|
424
|
+
const v15Pallet = {
|
|
569
425
|
...v14Pallet,
|
|
570
426
|
docs
|
|
571
427
|
};
|
|
572
428
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
(0, import_scale_ts15.Struct)({
|
|
582
|
-
name: import_scale_ts15.str,
|
|
429
|
+
const runtimeApi = scaleTs.Struct({
|
|
430
|
+
name: scaleTs.str,
|
|
431
|
+
methods: scaleTs.Vector(
|
|
432
|
+
scaleTs.Struct({
|
|
433
|
+
name: scaleTs.str,
|
|
434
|
+
inputs: scaleTs.Vector(
|
|
435
|
+
scaleTs.Struct({
|
|
436
|
+
name: scaleTs.str,
|
|
583
437
|
type: compactNumber
|
|
584
438
|
})
|
|
585
439
|
),
|
|
@@ -590,72 +444,68 @@ var runtimeApi = (0, import_scale_ts15.Struct)({
|
|
|
590
444
|
docs
|
|
591
445
|
});
|
|
592
446
|
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
version: import_scale_ts16.u8,
|
|
447
|
+
const extrinsic$1 = scaleTs.Struct({
|
|
448
|
+
version: scaleTs.u8,
|
|
596
449
|
address: compactNumber,
|
|
597
450
|
call: compactNumber,
|
|
598
451
|
signature: compactNumber,
|
|
599
452
|
extra: compactNumber,
|
|
600
|
-
signedExtensions:
|
|
601
|
-
|
|
602
|
-
identifier:
|
|
453
|
+
signedExtensions: scaleTs.Vector(
|
|
454
|
+
scaleTs.Struct({
|
|
455
|
+
identifier: scaleTs.str,
|
|
603
456
|
type: compactNumber,
|
|
604
457
|
additionalSigned: compactNumber
|
|
605
458
|
})
|
|
606
459
|
)
|
|
607
460
|
});
|
|
608
|
-
|
|
461
|
+
const v15 = scaleTs.Struct({
|
|
609
462
|
lookup,
|
|
610
|
-
pallets:
|
|
611
|
-
extrinsic,
|
|
463
|
+
pallets: scaleTs.Vector(scaleTs.Struct(v15Pallet)),
|
|
464
|
+
extrinsic: extrinsic$1,
|
|
612
465
|
type: compactNumber,
|
|
613
|
-
apis:
|
|
614
|
-
outerEnums:
|
|
466
|
+
apis: scaleTs.Vector(runtimeApi),
|
|
467
|
+
outerEnums: scaleTs.Struct({
|
|
615
468
|
call: compactNumber,
|
|
616
469
|
event: compactNumber,
|
|
617
470
|
error: compactNumber
|
|
618
471
|
}),
|
|
619
|
-
custom:
|
|
472
|
+
custom: scaleTs.Vector(scaleTs.Tuple(scaleTs.str, scaleTs.Struct({ type: compactNumber, value: Hex() })))
|
|
620
473
|
});
|
|
621
474
|
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
var empty = new Uint8Array();
|
|
625
|
-
var Always = (value) => (0, import_scale_ts17.createCodec)(
|
|
475
|
+
const empty = new Uint8Array();
|
|
476
|
+
const Always = (value) => scaleTs.createCodec(
|
|
626
477
|
() => empty,
|
|
627
478
|
() => value
|
|
628
479
|
);
|
|
629
|
-
|
|
480
|
+
const extrinsic = scaleTs.Struct({
|
|
630
481
|
type: compactNumber,
|
|
631
|
-
version:
|
|
632
|
-
signedExtensions:
|
|
633
|
-
|
|
634
|
-
identifier:
|
|
482
|
+
version: scaleTs.u8,
|
|
483
|
+
signedExtensions: scaleTs.Vector(
|
|
484
|
+
scaleTs.Struct({
|
|
485
|
+
identifier: scaleTs.str,
|
|
635
486
|
type: compactNumber,
|
|
636
487
|
additionalSigned: compactNumber
|
|
637
488
|
})
|
|
638
489
|
)
|
|
639
490
|
});
|
|
640
|
-
|
|
491
|
+
const v14 = scaleTs.Struct({
|
|
641
492
|
lookup,
|
|
642
|
-
pallets:
|
|
643
|
-
extrinsic
|
|
493
|
+
pallets: scaleTs.Vector(scaleTs.Struct({ ...v14Pallet, docs: Always([]) })),
|
|
494
|
+
extrinsic,
|
|
644
495
|
type: compactNumber,
|
|
645
496
|
apis: Always([])
|
|
646
497
|
});
|
|
647
498
|
|
|
648
|
-
|
|
649
|
-
var unsupportedFn = () => {
|
|
499
|
+
const unsupportedFn = () => {
|
|
650
500
|
throw new Error("Unsupported metadata version!");
|
|
651
501
|
};
|
|
652
|
-
|
|
502
|
+
const unsupported = scaleTs.createCodec(
|
|
653
503
|
unsupportedFn,
|
|
654
504
|
unsupportedFn
|
|
655
505
|
);
|
|
656
|
-
|
|
657
|
-
magicNumber:
|
|
658
|
-
metadata:
|
|
506
|
+
const metadata = scaleTs.Struct({
|
|
507
|
+
magicNumber: scaleTs.u32,
|
|
508
|
+
metadata: scaleTs.Enum({
|
|
659
509
|
v0: unsupported,
|
|
660
510
|
v1: unsupported,
|
|
661
511
|
v2: unsupported,
|
|
@@ -675,33 +525,28 @@ var metadata = (0, import_scale_ts18.Struct)({
|
|
|
675
525
|
})
|
|
676
526
|
});
|
|
677
527
|
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
var PRIME64_1 = 11400714785074694791n;
|
|
701
|
-
var PRIME64_2 = 14029467366897019727n;
|
|
702
|
-
var PRIME64_3 = 1609587929392839161n;
|
|
703
|
-
var PRIME64_4 = 9650029242287828579n;
|
|
704
|
-
var PRIME64_5 = 2870177450012600261n;
|
|
528
|
+
const len32$1 = { dkLen: 32 };
|
|
529
|
+
const Blake2256 = (encoded) => blake2b.blake2b(encoded, len32$1);
|
|
530
|
+
const len16 = { dkLen: 16 };
|
|
531
|
+
const Blake2128 = (encoded) => blake2b.blake2b(encoded, len16);
|
|
532
|
+
const Blake2128Concat = (encoded) => utils.mergeUint8(Blake2128(encoded), encoded);
|
|
533
|
+
|
|
534
|
+
const len32 = { dkLen: 32 };
|
|
535
|
+
const Blake3256 = (encoded) => blake3.blake3(encoded, len32);
|
|
536
|
+
const Blake3256Concat = (encoded) => utils.mergeUint8(Blake3256(encoded), encoded);
|
|
537
|
+
|
|
538
|
+
const Identity = (encoded) => encoded;
|
|
539
|
+
|
|
540
|
+
const bigintFromU16 = (v0, v1, v2, v3) => new DataView(new Uint16Array([v0, v1, v2, v3]).buffer).getBigUint64(0, true);
|
|
541
|
+
const MASK_64 = 2n ** 64n - 1n;
|
|
542
|
+
const rotl = (input, nBits) => input << nBits & MASK_64 | input >> 64n - nBits;
|
|
543
|
+
const multiply = (a, b) => a * b & MASK_64;
|
|
544
|
+
const add = (a, b) => a + b & MASK_64;
|
|
545
|
+
const PRIME64_1 = 11400714785074694791n;
|
|
546
|
+
const PRIME64_2 = 14029467366897019727n;
|
|
547
|
+
const PRIME64_3 = 1609587929392839161n;
|
|
548
|
+
const PRIME64_4 = 9650029242287828579n;
|
|
549
|
+
const PRIME64_5 = 2870177450012600261n;
|
|
705
550
|
function h64(input, seed = 0n) {
|
|
706
551
|
let v1 = add(add(seed, PRIME64_1), PRIME64_2);
|
|
707
552
|
let v2 = add(seed, PRIME64_2);
|
|
@@ -713,8 +558,7 @@ function h64(input, seed = 0n) {
|
|
|
713
558
|
(function update() {
|
|
714
559
|
let p2 = 0;
|
|
715
560
|
let bEnd = p2 + totalLen;
|
|
716
|
-
if (!totalLen)
|
|
717
|
-
return;
|
|
561
|
+
if (!totalLen) return;
|
|
718
562
|
memory = new Uint8Array(32);
|
|
719
563
|
if (totalLen < 32) {
|
|
720
564
|
memory.set(input.subarray(0, totalLen), memsize);
|
|
@@ -825,15 +669,14 @@ function h64(input, seed = 0n) {
|
|
|
825
669
|
return result;
|
|
826
670
|
}
|
|
827
671
|
|
|
828
|
-
|
|
829
|
-
var Twox128 = (input) => {
|
|
672
|
+
const Twox128 = (input) => {
|
|
830
673
|
const result = new Uint8Array(16);
|
|
831
674
|
const dv = new DataView(result.buffer);
|
|
832
675
|
dv.setBigUint64(0, h64(input), true);
|
|
833
676
|
dv.setBigUint64(8, h64(input, 1n), true);
|
|
834
677
|
return result;
|
|
835
678
|
};
|
|
836
|
-
|
|
679
|
+
const Twox256 = (input) => {
|
|
837
680
|
const result = new Uint8Array(32);
|
|
838
681
|
const dv = new DataView(result.buffer);
|
|
839
682
|
dv.setBigUint64(0, h64(input), true);
|
|
@@ -842,26 +685,21 @@ var Twox256 = (input) => {
|
|
|
842
685
|
dv.setBigUint64(24, h64(input, 3n), true);
|
|
843
686
|
return result;
|
|
844
687
|
};
|
|
845
|
-
|
|
688
|
+
const Twox64Concat = (encoded) => utils.mergeUint8(scaleTs.u64.enc(h64(encoded)), encoded);
|
|
846
689
|
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
return (name, dec3, ...encoders) => {
|
|
853
|
-
const palletItemEncoded = (0, import_utils7.mergeUint8)(
|
|
690
|
+
const textEncoder = new TextEncoder();
|
|
691
|
+
const Storage = (pallet) => {
|
|
692
|
+
const palledEncoded = Twox128(textEncoder.encode(pallet));
|
|
693
|
+
return (name, dec, ...encoders) => {
|
|
694
|
+
const palletItemEncoded = utils.mergeUint8(
|
|
854
695
|
palledEncoded,
|
|
855
|
-
Twox128(
|
|
696
|
+
Twox128(textEncoder.encode(name))
|
|
856
697
|
);
|
|
857
|
-
const palletItemEncodedHex =
|
|
698
|
+
const palletItemEncodedHex = utils.toHex(palletItemEncoded);
|
|
858
699
|
const bytesToSkip = encoders.map((e) => e[1]).map((x) => {
|
|
859
|
-
if (x === Identity)
|
|
860
|
-
|
|
861
|
-
if (x ===
|
|
862
|
-
return 8;
|
|
863
|
-
if (x === Blake2128Concat)
|
|
864
|
-
return 16;
|
|
700
|
+
if (x === Identity) return 0;
|
|
701
|
+
if (x === Twox64Concat) return 8;
|
|
702
|
+
if (x === Blake2128Concat) return 16;
|
|
865
703
|
return null;
|
|
866
704
|
}).filter(Boolean);
|
|
867
705
|
const keyDecoder = (key) => {
|
|
@@ -869,8 +707,7 @@ var Storage = (pallet) => {
|
|
|
869
707
|
throw new Error(`key does not match this storage (${pallet}.${name})`);
|
|
870
708
|
if (bytesToSkip.length !== encoders.length)
|
|
871
709
|
throw new Error("Impossible to decode this key");
|
|
872
|
-
if (encoders.length === 0)
|
|
873
|
-
return [];
|
|
710
|
+
if (encoders.length === 0) return [];
|
|
874
711
|
const argsKey = key.slice(palletItemEncodedHex.length);
|
|
875
712
|
const result = new Array(encoders.length);
|
|
876
713
|
for (let i = 0, cur = 0; i < bytesToSkip.length; i++) {
|
|
@@ -882,16 +719,163 @@ var Storage = (pallet) => {
|
|
|
882
719
|
return result;
|
|
883
720
|
};
|
|
884
721
|
const fns = encoders.map(
|
|
885
|
-
([{ enc:
|
|
722
|
+
([{ enc: enc2 }, hash]) => (val) => hash(enc2(val))
|
|
886
723
|
);
|
|
887
|
-
const
|
|
888
|
-
|
|
724
|
+
const enc = (...args) => utils.toHex(
|
|
725
|
+
utils.mergeUint8(palletItemEncoded, ...args.map((val, idx) => fns[idx](val)))
|
|
889
726
|
);
|
|
890
727
|
return {
|
|
891
|
-
enc
|
|
892
|
-
dec
|
|
728
|
+
enc,
|
|
729
|
+
dec,
|
|
893
730
|
keyDecoder
|
|
894
731
|
};
|
|
895
732
|
};
|
|
896
733
|
};
|
|
897
|
-
|
|
734
|
+
|
|
735
|
+
Object.defineProperty(exports, "Bytes", {
|
|
736
|
+
enumerable: true,
|
|
737
|
+
get: function () { return scaleTs.Bytes; }
|
|
738
|
+
});
|
|
739
|
+
Object.defineProperty(exports, "Option", {
|
|
740
|
+
enumerable: true,
|
|
741
|
+
get: function () { return scaleTs.Option; }
|
|
742
|
+
});
|
|
743
|
+
Object.defineProperty(exports, "Result", {
|
|
744
|
+
enumerable: true,
|
|
745
|
+
get: function () { return scaleTs.Result; }
|
|
746
|
+
});
|
|
747
|
+
Object.defineProperty(exports, "ScaleEnum", {
|
|
748
|
+
enumerable: true,
|
|
749
|
+
get: function () { return scaleTs.Enum; }
|
|
750
|
+
});
|
|
751
|
+
Object.defineProperty(exports, "Struct", {
|
|
752
|
+
enumerable: true,
|
|
753
|
+
get: function () { return scaleTs.Struct; }
|
|
754
|
+
});
|
|
755
|
+
Object.defineProperty(exports, "Tuple", {
|
|
756
|
+
enumerable: true,
|
|
757
|
+
get: function () { return scaleTs.Tuple; }
|
|
758
|
+
});
|
|
759
|
+
Object.defineProperty(exports, "Vector", {
|
|
760
|
+
enumerable: true,
|
|
761
|
+
get: function () { return scaleTs.Vector; }
|
|
762
|
+
});
|
|
763
|
+
Object.defineProperty(exports, "_void", {
|
|
764
|
+
enumerable: true,
|
|
765
|
+
get: function () { return scaleTs._void; }
|
|
766
|
+
});
|
|
767
|
+
Object.defineProperty(exports, "bool", {
|
|
768
|
+
enumerable: true,
|
|
769
|
+
get: function () { return scaleTs.bool; }
|
|
770
|
+
});
|
|
771
|
+
Object.defineProperty(exports, "compact", {
|
|
772
|
+
enumerable: true,
|
|
773
|
+
get: function () { return scaleTs.compact; }
|
|
774
|
+
});
|
|
775
|
+
Object.defineProperty(exports, "createCodec", {
|
|
776
|
+
enumerable: true,
|
|
777
|
+
get: function () { return scaleTs.createCodec; }
|
|
778
|
+
});
|
|
779
|
+
Object.defineProperty(exports, "createDecoder", {
|
|
780
|
+
enumerable: true,
|
|
781
|
+
get: function () { return scaleTs.createDecoder; }
|
|
782
|
+
});
|
|
783
|
+
Object.defineProperty(exports, "enhanceCodec", {
|
|
784
|
+
enumerable: true,
|
|
785
|
+
get: function () { return scaleTs.enhanceCodec; }
|
|
786
|
+
});
|
|
787
|
+
Object.defineProperty(exports, "enhanceDecoder", {
|
|
788
|
+
enumerable: true,
|
|
789
|
+
get: function () { return scaleTs.enhanceDecoder; }
|
|
790
|
+
});
|
|
791
|
+
Object.defineProperty(exports, "enhanceEncoder", {
|
|
792
|
+
enumerable: true,
|
|
793
|
+
get: function () { return scaleTs.enhanceEncoder; }
|
|
794
|
+
});
|
|
795
|
+
Object.defineProperty(exports, "i128", {
|
|
796
|
+
enumerable: true,
|
|
797
|
+
get: function () { return scaleTs.i128; }
|
|
798
|
+
});
|
|
799
|
+
Object.defineProperty(exports, "i16", {
|
|
800
|
+
enumerable: true,
|
|
801
|
+
get: function () { return scaleTs.i16; }
|
|
802
|
+
});
|
|
803
|
+
Object.defineProperty(exports, "i256", {
|
|
804
|
+
enumerable: true,
|
|
805
|
+
get: function () { return scaleTs.i256; }
|
|
806
|
+
});
|
|
807
|
+
Object.defineProperty(exports, "i32", {
|
|
808
|
+
enumerable: true,
|
|
809
|
+
get: function () { return scaleTs.i32; }
|
|
810
|
+
});
|
|
811
|
+
Object.defineProperty(exports, "i64", {
|
|
812
|
+
enumerable: true,
|
|
813
|
+
get: function () { return scaleTs.i64; }
|
|
814
|
+
});
|
|
815
|
+
Object.defineProperty(exports, "i8", {
|
|
816
|
+
enumerable: true,
|
|
817
|
+
get: function () { return scaleTs.i8; }
|
|
818
|
+
});
|
|
819
|
+
Object.defineProperty(exports, "str", {
|
|
820
|
+
enumerable: true,
|
|
821
|
+
get: function () { return scaleTs.str; }
|
|
822
|
+
});
|
|
823
|
+
Object.defineProperty(exports, "u128", {
|
|
824
|
+
enumerable: true,
|
|
825
|
+
get: function () { return scaleTs.u128; }
|
|
826
|
+
});
|
|
827
|
+
Object.defineProperty(exports, "u16", {
|
|
828
|
+
enumerable: true,
|
|
829
|
+
get: function () { return scaleTs.u16; }
|
|
830
|
+
});
|
|
831
|
+
Object.defineProperty(exports, "u256", {
|
|
832
|
+
enumerable: true,
|
|
833
|
+
get: function () { return scaleTs.u256; }
|
|
834
|
+
});
|
|
835
|
+
Object.defineProperty(exports, "u32", {
|
|
836
|
+
enumerable: true,
|
|
837
|
+
get: function () { return scaleTs.u32; }
|
|
838
|
+
});
|
|
839
|
+
Object.defineProperty(exports, "u64", {
|
|
840
|
+
enumerable: true,
|
|
841
|
+
get: function () { return scaleTs.u64; }
|
|
842
|
+
});
|
|
843
|
+
Object.defineProperty(exports, "u8", {
|
|
844
|
+
enumerable: true,
|
|
845
|
+
get: function () { return scaleTs.u8; }
|
|
846
|
+
});
|
|
847
|
+
exports.AccountId = AccountId;
|
|
848
|
+
exports.Bin = Bin;
|
|
849
|
+
exports.Binary = Binary;
|
|
850
|
+
exports.Blake2128 = Blake2128;
|
|
851
|
+
exports.Blake2128Concat = Blake2128Concat;
|
|
852
|
+
exports.Blake2256 = Blake2256;
|
|
853
|
+
exports.Blake3256 = Blake3256;
|
|
854
|
+
exports.Blake3256Concat = Blake3256Concat;
|
|
855
|
+
exports.Enum = Enum;
|
|
856
|
+
exports.FixedSizeBinary = FixedSizeBinary;
|
|
857
|
+
exports.Hex = Hex;
|
|
858
|
+
exports.Identity = Identity;
|
|
859
|
+
exports.Self = Self;
|
|
860
|
+
exports.Storage = Storage;
|
|
861
|
+
exports.Twox128 = Twox128;
|
|
862
|
+
exports.Twox256 = Twox256;
|
|
863
|
+
exports.Twox64Concat = Twox64Concat;
|
|
864
|
+
exports.Variant = Variant;
|
|
865
|
+
exports._Enum = _Enum;
|
|
866
|
+
exports.bitSequence = bitSequence$1;
|
|
867
|
+
exports.blockHeader = blockHeader;
|
|
868
|
+
exports.char = char;
|
|
869
|
+
exports.compactBn = compactBn;
|
|
870
|
+
exports.compactNumber = compactNumber;
|
|
871
|
+
exports.ethAccount = ethAccount;
|
|
872
|
+
exports.fixedStr = fixedStr;
|
|
873
|
+
exports.fromBufferToBase58 = fromBufferToBase58;
|
|
874
|
+
exports.getSs58AddressInfo = getSs58AddressInfo;
|
|
875
|
+
exports.h64 = h64;
|
|
876
|
+
exports.metadata = metadata;
|
|
877
|
+
exports.selfDecoder = selfDecoder;
|
|
878
|
+
exports.selfEncoder = selfEncoder;
|
|
879
|
+
exports.v14 = v14;
|
|
880
|
+
exports.v15 = v15;
|
|
881
|
+
//# sourceMappingURL=index.js.map
|