@polkadot-api/merkleize-metadata 1.1.0 → 1.1.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/dist/esm/codecs.mjs +122 -0
- package/dist/esm/codecs.mjs.map +1 -0
- package/dist/esm/decode-and-collect.mjs +94 -0
- package/dist/esm/decode-and-collect.mjs.map +1 -0
- package/dist/esm/get-accessible-types.mjs +52 -0
- package/dist/esm/get-accessible-types.mjs.map +1 -0
- package/dist/esm/get-lookup.mjs +103 -0
- package/dist/esm/get-lookup.mjs.map +1 -0
- package/dist/esm/get-metadata.mjs +36 -0
- package/dist/esm/get-metadata.mjs.map +1 -0
- package/dist/esm/index.mjs +3 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/main.mjs +140 -0
- package/dist/esm/main.mjs.map +1 -0
- package/dist/esm/proof.mjs +47 -0
- package/dist/esm/proof.mjs.map +1 -0
- package/dist/esm/utils.mjs +27 -0
- package/dist/esm/utils.mjs.map +1 -0
- package/dist/index.js +179 -213
- package/dist/index.js.map +1 -1
- package/package.json +11 -10
- package/dist/index.d.mts +0 -1239
- package/dist/index.mjs +0 -655
- package/dist/index.mjs.map +0 -1
- package/dist/min/index.d.ts +0 -1239
- package/dist/min/index.js +0 -2
- package/dist/min/index.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,160 +1,127 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
var
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
extraInfo: () => extraInfo,
|
|
24
|
-
extrinsicMetadata: () => extrinsicMetadata,
|
|
25
|
-
hash: () => hash,
|
|
26
|
-
lookup: () => lookup,
|
|
27
|
-
lookupType: () => lookupType,
|
|
28
|
-
merkleizeMetadata: () => merkleizeMetadata,
|
|
29
|
-
proof: () => proof
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(src_exports);
|
|
32
|
-
|
|
33
|
-
// src/main.ts
|
|
34
|
-
var import_substrate_bindings4 = require("@polkadot-api/substrate-bindings");
|
|
3
|
+
var substrateBindings = require('@polkadot-api/substrate-bindings');
|
|
4
|
+
var utils = require('@polkadot-api/utils');
|
|
35
5
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
decimals: import_substrate_bindings.u8,
|
|
43
|
-
tokenSymbol: import_substrate_bindings.str
|
|
6
|
+
const extraInfoInner = {
|
|
7
|
+
specVersion: substrateBindings.u32,
|
|
8
|
+
specName: substrateBindings.str,
|
|
9
|
+
base58Prefix: substrateBindings.u16,
|
|
10
|
+
decimals: substrateBindings.u8,
|
|
11
|
+
tokenSymbol: substrateBindings.str
|
|
44
12
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
V0:
|
|
49
|
-
V1:
|
|
13
|
+
const extraInfo = substrateBindings.Struct(extraInfoInner);
|
|
14
|
+
const hash = substrateBindings.Bytes(32);
|
|
15
|
+
const metadataDigest = substrateBindings.ScaleEnum({
|
|
16
|
+
V0: substrateBindings._void,
|
|
17
|
+
V1: substrateBindings.Struct({
|
|
50
18
|
typeInformationTreeRoot: hash,
|
|
51
19
|
extrinsicMetadataHash: hash,
|
|
52
20
|
...extraInfoInner
|
|
53
21
|
})
|
|
54
22
|
});
|
|
55
|
-
|
|
56
|
-
bool:
|
|
57
|
-
char:
|
|
58
|
-
str:
|
|
59
|
-
u8:
|
|
60
|
-
u16:
|
|
61
|
-
u32:
|
|
62
|
-
u64:
|
|
63
|
-
u128:
|
|
64
|
-
u256:
|
|
65
|
-
i8:
|
|
66
|
-
i16:
|
|
67
|
-
i32:
|
|
68
|
-
i64:
|
|
69
|
-
i128:
|
|
70
|
-
i256:
|
|
23
|
+
substrateBindings.ScaleEnum({
|
|
24
|
+
bool: substrateBindings._void,
|
|
25
|
+
char: substrateBindings._void,
|
|
26
|
+
str: substrateBindings._void,
|
|
27
|
+
u8: substrateBindings._void,
|
|
28
|
+
u16: substrateBindings._void,
|
|
29
|
+
u32: substrateBindings._void,
|
|
30
|
+
u64: substrateBindings._void,
|
|
31
|
+
u128: substrateBindings._void,
|
|
32
|
+
u256: substrateBindings._void,
|
|
33
|
+
i8: substrateBindings._void,
|
|
34
|
+
i16: substrateBindings._void,
|
|
35
|
+
i32: substrateBindings._void,
|
|
36
|
+
i64: substrateBindings._void,
|
|
37
|
+
i128: substrateBindings._void,
|
|
38
|
+
i256: substrateBindings._void
|
|
71
39
|
});
|
|
72
|
-
|
|
73
|
-
bool:
|
|
74
|
-
char:
|
|
75
|
-
str:
|
|
76
|
-
u8:
|
|
77
|
-
u16:
|
|
78
|
-
u32:
|
|
79
|
-
u64:
|
|
80
|
-
u128:
|
|
81
|
-
u256:
|
|
82
|
-
i8:
|
|
83
|
-
i16:
|
|
84
|
-
i32:
|
|
85
|
-
i64:
|
|
86
|
-
i128:
|
|
87
|
-
i256:
|
|
88
|
-
compactU8:
|
|
89
|
-
compactU16:
|
|
90
|
-
compactU32:
|
|
91
|
-
compactU64:
|
|
92
|
-
compactU128:
|
|
93
|
-
compactU256:
|
|
94
|
-
void:
|
|
95
|
-
perId:
|
|
40
|
+
const typeRef = substrateBindings.ScaleEnum({
|
|
41
|
+
bool: substrateBindings._void,
|
|
42
|
+
char: substrateBindings._void,
|
|
43
|
+
str: substrateBindings._void,
|
|
44
|
+
u8: substrateBindings._void,
|
|
45
|
+
u16: substrateBindings._void,
|
|
46
|
+
u32: substrateBindings._void,
|
|
47
|
+
u64: substrateBindings._void,
|
|
48
|
+
u128: substrateBindings._void,
|
|
49
|
+
u256: substrateBindings._void,
|
|
50
|
+
i8: substrateBindings._void,
|
|
51
|
+
i16: substrateBindings._void,
|
|
52
|
+
i32: substrateBindings._void,
|
|
53
|
+
i64: substrateBindings._void,
|
|
54
|
+
i128: substrateBindings._void,
|
|
55
|
+
i256: substrateBindings._void,
|
|
56
|
+
compactU8: substrateBindings._void,
|
|
57
|
+
compactU16: substrateBindings._void,
|
|
58
|
+
compactU32: substrateBindings._void,
|
|
59
|
+
compactU64: substrateBindings._void,
|
|
60
|
+
compactU128: substrateBindings._void,
|
|
61
|
+
compactU256: substrateBindings._void,
|
|
62
|
+
void: substrateBindings._void,
|
|
63
|
+
perId: substrateBindings.compactNumber
|
|
96
64
|
});
|
|
97
|
-
|
|
98
|
-
name:
|
|
65
|
+
const field = substrateBindings.Struct({
|
|
66
|
+
name: substrateBindings.Option(substrateBindings.str),
|
|
99
67
|
ty: typeRef,
|
|
100
|
-
typeName:
|
|
68
|
+
typeName: substrateBindings.Option(substrateBindings.str)
|
|
101
69
|
});
|
|
102
|
-
|
|
103
|
-
composite:
|
|
104
|
-
enumeration:
|
|
105
|
-
name:
|
|
106
|
-
fields:
|
|
107
|
-
index:
|
|
70
|
+
const typeDef = substrateBindings.ScaleEnum({
|
|
71
|
+
composite: substrateBindings.Vector(field),
|
|
72
|
+
enumeration: substrateBindings.Struct({
|
|
73
|
+
name: substrateBindings.str,
|
|
74
|
+
fields: substrateBindings.Vector(field),
|
|
75
|
+
index: substrateBindings.compactNumber
|
|
108
76
|
}),
|
|
109
77
|
sequence: typeRef,
|
|
110
|
-
array:
|
|
111
|
-
len:
|
|
78
|
+
array: substrateBindings.Struct({
|
|
79
|
+
len: substrateBindings.u32,
|
|
112
80
|
typeParam: typeRef
|
|
113
81
|
}),
|
|
114
|
-
tuple:
|
|
115
|
-
bitSequence:
|
|
116
|
-
numBytes:
|
|
117
|
-
leastSignificantBitFirst:
|
|
82
|
+
tuple: substrateBindings.Vector(typeRef),
|
|
83
|
+
bitSequence: substrateBindings.Struct({
|
|
84
|
+
numBytes: substrateBindings.u8,
|
|
85
|
+
leastSignificantBitFirst: substrateBindings.bool
|
|
118
86
|
})
|
|
119
87
|
});
|
|
120
|
-
|
|
121
|
-
path:
|
|
88
|
+
const lookupType = substrateBindings.Struct({
|
|
89
|
+
path: substrateBindings.Vector(substrateBindings.str),
|
|
122
90
|
typeDef,
|
|
123
|
-
typeId:
|
|
91
|
+
typeId: substrateBindings.compactNumber
|
|
124
92
|
});
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
version:
|
|
93
|
+
const lookup = substrateBindings.Vector(lookupType);
|
|
94
|
+
const extrinsicMetadata = substrateBindings.Struct({
|
|
95
|
+
version: substrateBindings.u8,
|
|
128
96
|
addressTy: typeRef,
|
|
129
97
|
callTy: typeRef,
|
|
130
98
|
signatureTy: typeRef,
|
|
131
|
-
signedExtensions:
|
|
132
|
-
|
|
133
|
-
identifier:
|
|
99
|
+
signedExtensions: substrateBindings.Vector(
|
|
100
|
+
substrateBindings.Struct({
|
|
101
|
+
identifier: substrateBindings.str,
|
|
134
102
|
includedInExtrinsic: typeRef,
|
|
135
103
|
includedInSignedData: typeRef
|
|
136
104
|
})
|
|
137
105
|
)
|
|
138
106
|
});
|
|
139
|
-
|
|
107
|
+
const versionDecoder = substrateBindings.enhanceDecoder(substrateBindings.u8[1], (value) => ({
|
|
140
108
|
version: value & ~(1 << 7),
|
|
141
109
|
signed: !!(value & 1 << 7)
|
|
142
110
|
}));
|
|
143
|
-
|
|
144
|
-
|
|
111
|
+
const extrinsicDec = substrateBindings.Tuple.dec(
|
|
112
|
+
substrateBindings.compact[1],
|
|
145
113
|
versionDecoder,
|
|
146
|
-
|
|
114
|
+
substrateBindings.Bytes(Infinity)[1]
|
|
147
115
|
);
|
|
148
|
-
|
|
116
|
+
const proof = substrateBindings.Struct({
|
|
149
117
|
leaves: lookup,
|
|
150
|
-
leafIdxs:
|
|
151
|
-
proofs:
|
|
118
|
+
leafIdxs: substrateBindings.Vector(substrateBindings.u32),
|
|
119
|
+
proofs: substrateBindings.Vector(hash),
|
|
152
120
|
extrinsic: extrinsicMetadata,
|
|
153
121
|
info: extraInfo
|
|
154
122
|
});
|
|
155
123
|
|
|
156
|
-
|
|
157
|
-
var getAccessibleTypes = (metadata2, definitions) => {
|
|
124
|
+
const getAccessibleTypes = (metadata, definitions) => {
|
|
158
125
|
const types = /* @__PURE__ */ new Set();
|
|
159
126
|
const collectTypesFromId = (id) => {
|
|
160
127
|
if (types.has(id)) return;
|
|
@@ -193,10 +160,10 @@ var getAccessibleTypes = (metadata2, definitions) => {
|
|
|
193
160
|
types.add(id);
|
|
194
161
|
}
|
|
195
162
|
};
|
|
196
|
-
collectTypesFromId(
|
|
197
|
-
collectTypesFromId(
|
|
198
|
-
collectTypesFromId(
|
|
199
|
-
|
|
163
|
+
collectTypesFromId(metadata.extrinsic.call);
|
|
164
|
+
collectTypesFromId(metadata.extrinsic.address);
|
|
165
|
+
collectTypesFromId(metadata.extrinsic.signature);
|
|
166
|
+
metadata.extrinsic.signedExtensions.forEach(({ type, additionalSigned }) => {
|
|
200
167
|
collectTypesFromId(type);
|
|
201
168
|
collectTypesFromId(additionalSigned);
|
|
202
169
|
});
|
|
@@ -204,14 +171,13 @@ var getAccessibleTypes = (metadata2, definitions) => {
|
|
|
204
171
|
return new Map(sortedTypes.map((value, idx) => [value, idx]));
|
|
205
172
|
};
|
|
206
173
|
|
|
207
|
-
|
|
208
|
-
var bitSequenceBytes = {
|
|
174
|
+
const bitSequenceBytes = {
|
|
209
175
|
u8: 1,
|
|
210
176
|
u16: 2,
|
|
211
177
|
u32: 4,
|
|
212
178
|
u64: 8
|
|
213
179
|
};
|
|
214
|
-
|
|
180
|
+
const constructTypeDef = (definitions, getTypeRef, getPrimitive, frameId) => {
|
|
215
181
|
const {
|
|
216
182
|
def: { tag, value }
|
|
217
183
|
} = definitions.get(frameId);
|
|
@@ -283,16 +249,16 @@ var constructTypeDef = (definitions, getTypeRef, getPrimitive, frameId) => {
|
|
|
283
249
|
}
|
|
284
250
|
throw new Error(`FrameId(${frameId}) should have been filtered out`);
|
|
285
251
|
};
|
|
286
|
-
|
|
252
|
+
const getLookup = (definitions, accessibleTypes, getTypeRef, getPrimitive) => {
|
|
287
253
|
const typeTree = [];
|
|
288
254
|
[...accessibleTypes.entries()].forEach(([frameId, typeId]) => {
|
|
289
255
|
const { path } = definitions.get(frameId);
|
|
290
256
|
constructTypeDef(definitions, getTypeRef, getPrimitive, frameId).forEach(
|
|
291
|
-
(
|
|
257
|
+
(typeDef) => {
|
|
292
258
|
typeTree.push({
|
|
293
259
|
path,
|
|
294
260
|
typeId,
|
|
295
|
-
typeDef
|
|
261
|
+
typeDef
|
|
296
262
|
});
|
|
297
263
|
}
|
|
298
264
|
);
|
|
@@ -306,31 +272,29 @@ var getLookup = (definitions, accessibleTypes, getTypeRef, getPrimitive) => {
|
|
|
306
272
|
return typeTree;
|
|
307
273
|
};
|
|
308
274
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
var opaqueOpaqueBytes = (0, import_substrate_bindings2.Tuple)(import_substrate_bindings2.compact, opaqueBytes);
|
|
314
|
-
var getAnyMetadata = (input) => {
|
|
275
|
+
const opaqueBytes = substrateBindings.Bytes();
|
|
276
|
+
const optionOpaque = substrateBindings.Option(opaqueBytes);
|
|
277
|
+
const opaqueOpaqueBytes = substrateBindings.Tuple(substrateBindings.compact, opaqueBytes);
|
|
278
|
+
const getAnyMetadata = (input) => {
|
|
315
279
|
try {
|
|
316
|
-
return
|
|
280
|
+
return substrateBindings.metadata.dec(input);
|
|
317
281
|
} catch (_) {
|
|
318
282
|
}
|
|
319
283
|
try {
|
|
320
|
-
return
|
|
284
|
+
return substrateBindings.metadata.dec(optionOpaque.dec(input));
|
|
321
285
|
} catch (_) {
|
|
322
286
|
}
|
|
323
287
|
try {
|
|
324
|
-
return
|
|
288
|
+
return substrateBindings.metadata.dec(opaqueBytes.dec(input));
|
|
325
289
|
} catch (_) {
|
|
326
290
|
}
|
|
327
291
|
try {
|
|
328
|
-
return
|
|
292
|
+
return substrateBindings.metadata.dec(opaqueOpaqueBytes.dec(input)[1]);
|
|
329
293
|
} catch (_) {
|
|
330
294
|
}
|
|
331
295
|
throw null;
|
|
332
296
|
};
|
|
333
|
-
|
|
297
|
+
const getMetadata = (input) => {
|
|
334
298
|
try {
|
|
335
299
|
const { metadata: metadata2 } = getAnyMetadata(input);
|
|
336
300
|
if (metadata2.tag !== "v15") throw new Error("Wrong metadata version");
|
|
@@ -340,9 +304,7 @@ var getMetadata = (input) => {
|
|
|
340
304
|
}
|
|
341
305
|
};
|
|
342
306
|
|
|
343
|
-
|
|
344
|
-
var import_utils = require("@polkadot-api/utils");
|
|
345
|
-
var mergeUint8 = (inputs) => {
|
|
307
|
+
const mergeUint8 = (inputs) => {
|
|
346
308
|
const len = inputs.length;
|
|
347
309
|
let totalLen = 0;
|
|
348
310
|
for (let i = 0; i < len; i++) totalLen += inputs[i].byteLength;
|
|
@@ -354,8 +316,8 @@ var mergeUint8 = (inputs) => {
|
|
|
354
316
|
}
|
|
355
317
|
return result;
|
|
356
318
|
};
|
|
357
|
-
|
|
358
|
-
|
|
319
|
+
const toBytes = (input) => typeof input === "string" ? utils.fromHex(input) : input;
|
|
320
|
+
const compactTypeRefs = {
|
|
359
321
|
null: "void",
|
|
360
322
|
u8: "compactU8",
|
|
361
323
|
u16: "compactU16",
|
|
@@ -365,49 +327,47 @@ var compactTypeRefs = {
|
|
|
365
327
|
u256: "compactU256"
|
|
366
328
|
};
|
|
367
329
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
compactU128: import_substrate_bindings3.compact,
|
|
392
|
-
compactU256: import_substrate_bindings3.compact
|
|
330
|
+
const typeRefDecoders = {
|
|
331
|
+
bool: substrateBindings.u8,
|
|
332
|
+
char: substrateBindings.u8,
|
|
333
|
+
str: substrateBindings.str,
|
|
334
|
+
u8: substrateBindings.u8,
|
|
335
|
+
u16: substrateBindings.u16,
|
|
336
|
+
u32: substrateBindings.u32,
|
|
337
|
+
u64: substrateBindings.u64,
|
|
338
|
+
u128: substrateBindings.u128,
|
|
339
|
+
u256: substrateBindings.u256,
|
|
340
|
+
i8: substrateBindings.i8,
|
|
341
|
+
i16: substrateBindings.i16,
|
|
342
|
+
i32: substrateBindings.i32,
|
|
343
|
+
i64: substrateBindings.i64,
|
|
344
|
+
i128: substrateBindings.i128,
|
|
345
|
+
i256: substrateBindings.i256,
|
|
346
|
+
void: substrateBindings._void,
|
|
347
|
+
compactU8: substrateBindings.compact,
|
|
348
|
+
compactU16: substrateBindings.compact,
|
|
349
|
+
compactU32: substrateBindings.compact,
|
|
350
|
+
compactU64: substrateBindings.compact,
|
|
351
|
+
compactU128: substrateBindings.compact,
|
|
352
|
+
compactU256: substrateBindings.compact
|
|
393
353
|
};
|
|
394
|
-
|
|
395
|
-
if (
|
|
396
|
-
typeRefDecoders[
|
|
354
|
+
const innerDecodeAndCollect = (input, typeRef, idToLookups, lookup, collected) => {
|
|
355
|
+
if (typeRef.tag !== "perId") {
|
|
356
|
+
typeRefDecoders[typeRef.tag][1](input);
|
|
397
357
|
return;
|
|
398
358
|
}
|
|
399
|
-
const handleTypeRef = (
|
|
400
|
-
innerDecodeAndCollect(input,
|
|
359
|
+
const handleTypeRef = (typeRef2) => {
|
|
360
|
+
innerDecodeAndCollect(input, typeRef2, idToLookups, lookup, collected);
|
|
401
361
|
};
|
|
402
|
-
const lookupIdxs = idToLookups.get(
|
|
362
|
+
const lookupIdxs = idToLookups.get(typeRef.value);
|
|
403
363
|
const [currentIdx] = lookupIdxs;
|
|
404
|
-
const current =
|
|
364
|
+
const current = lookup[currentIdx];
|
|
405
365
|
if (lookupIdxs.length === 1) collected.add(currentIdx);
|
|
406
366
|
switch (current.typeDef.tag) {
|
|
407
367
|
case "enumeration": {
|
|
408
|
-
const selectedIdx =
|
|
368
|
+
const selectedIdx = substrateBindings.u8.dec(input);
|
|
409
369
|
const [selected, collectedIdx] = lookupIdxs.map(
|
|
410
|
-
(lookupIdx) => [
|
|
370
|
+
(lookupIdx) => [lookup[lookupIdx].typeDef, lookupIdx]
|
|
411
371
|
).find(([x]) => x.value.index === selectedIdx);
|
|
412
372
|
collected.add(collectedIdx);
|
|
413
373
|
selected.value.fields.forEach(({ ty }) => {
|
|
@@ -416,7 +376,7 @@ var innerDecodeAndCollect = (input, typeRef2, idToLookups, lookup2, collected) =
|
|
|
416
376
|
break;
|
|
417
377
|
}
|
|
418
378
|
case "sequence": {
|
|
419
|
-
const len =
|
|
379
|
+
const len = substrateBindings.compact.dec(input);
|
|
420
380
|
for (let i = 0; i < len; i++) handleTypeRef(current.typeDef.value);
|
|
421
381
|
break;
|
|
422
382
|
}
|
|
@@ -439,27 +399,26 @@ var innerDecodeAndCollect = (input, typeRef2, idToLookups, lookup2, collected) =
|
|
|
439
399
|
throw new Error("bitSequence is not supported");
|
|
440
400
|
}
|
|
441
401
|
};
|
|
442
|
-
|
|
402
|
+
const decodeAndCollectKnownLeafs = (data, typeRefs, lookup) => {
|
|
443
403
|
let input = new Uint8Array();
|
|
444
|
-
|
|
404
|
+
substrateBindings.createDecoder((_input) => {
|
|
445
405
|
input = _input;
|
|
446
406
|
})(data);
|
|
447
407
|
const idToLookups = /* @__PURE__ */ new Map();
|
|
448
|
-
|
|
449
|
-
const arr = idToLookups.get(
|
|
408
|
+
lookup.forEach((lookup2, idx) => {
|
|
409
|
+
const arr = idToLookups.get(lookup2.typeId);
|
|
450
410
|
if (arr) arr.push(idx);
|
|
451
|
-
else idToLookups.set(
|
|
411
|
+
else idToLookups.set(lookup2.typeId, [idx]);
|
|
452
412
|
});
|
|
453
413
|
const result = /* @__PURE__ */ new Set();
|
|
454
|
-
typeRefs.forEach((
|
|
455
|
-
innerDecodeAndCollect(input,
|
|
414
|
+
typeRefs.forEach((typeRef) => {
|
|
415
|
+
innerDecodeAndCollect(input, typeRef, idToLookups, lookup, result);
|
|
456
416
|
});
|
|
457
417
|
return [...result].sort((a, b) => a - b);
|
|
458
418
|
};
|
|
459
419
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
var getAncestorIdx = (from, nLevels) => (from + 1 >> nLevels) - 1;
|
|
420
|
+
const getLevelFromIdx = (idx) => Math.log2(idx + 1) | 0;
|
|
421
|
+
const getAncestorIdx = (from, nLevels) => (from + 1 >> nLevels) - 1;
|
|
463
422
|
function getProofData(leaves, knownLeavesIdxs) {
|
|
464
423
|
const knownLeaves = knownLeavesIdxs.map((idx) => leaves[idx]);
|
|
465
424
|
const startingIdx = leaves.length - 1;
|
|
@@ -503,13 +462,12 @@ function getProofData(leaves, knownLeavesIdxs) {
|
|
|
503
462
|
};
|
|
504
463
|
}
|
|
505
464
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
const metadata2 = getMetadata(metadataBytes);
|
|
465
|
+
const merkleizeMetadata = (metadataBytes, info) => {
|
|
466
|
+
const metadata = getMetadata(metadataBytes);
|
|
509
467
|
const definitions = new Map(
|
|
510
|
-
|
|
468
|
+
metadata.lookup.map((value) => [value.id, value])
|
|
511
469
|
);
|
|
512
|
-
const accessibleTypes = getAccessibleTypes(
|
|
470
|
+
const accessibleTypes = getAccessibleTypes(metadata, definitions);
|
|
513
471
|
const getPrimitive = (frameId) => {
|
|
514
472
|
const {
|
|
515
473
|
def: { tag, value }
|
|
@@ -531,23 +489,23 @@ var merkleizeMetadata = (metadataBytes, info) => {
|
|
|
531
489
|
return accessibleTypes.has(frameId) ? { tag: "perId", value: accessibleTypes.get(frameId) } : { tag: "void", value: void 0 };
|
|
532
490
|
};
|
|
533
491
|
const extrinsic = {
|
|
534
|
-
version:
|
|
535
|
-
addressTy: getTypeRef(
|
|
536
|
-
callTy: getTypeRef(
|
|
537
|
-
signatureTy: getTypeRef(
|
|
538
|
-
signedExtensions:
|
|
492
|
+
version: metadata.extrinsic.version,
|
|
493
|
+
addressTy: getTypeRef(metadata.extrinsic.address),
|
|
494
|
+
callTy: getTypeRef(metadata.extrinsic.call),
|
|
495
|
+
signatureTy: getTypeRef(metadata.extrinsic.signature),
|
|
496
|
+
signedExtensions: metadata.extrinsic.signedExtensions.map((se) => ({
|
|
539
497
|
identifier: se.identifier,
|
|
540
498
|
includedInExtrinsic: getTypeRef(se.type),
|
|
541
499
|
includedInSignedData: getTypeRef(se.additionalSigned)
|
|
542
500
|
}))
|
|
543
501
|
};
|
|
544
|
-
const
|
|
502
|
+
const lookup = getLookup(
|
|
545
503
|
definitions,
|
|
546
504
|
accessibleTypes,
|
|
547
505
|
getTypeRef,
|
|
548
506
|
getPrimitive
|
|
549
507
|
);
|
|
550
|
-
const lookupEncoded =
|
|
508
|
+
const lookupEncoded = lookup.map(lookupType.enc);
|
|
551
509
|
let hashTree;
|
|
552
510
|
const getHashTree = () => {
|
|
553
511
|
if (hashTree) return hashTree;
|
|
@@ -555,9 +513,9 @@ var merkleizeMetadata = (metadataBytes, info) => {
|
|
|
555
513
|
hashTree = new Array(lookupEncoded.length * 2 - 1);
|
|
556
514
|
let leavesStartIdx = lookupEncoded.length - 1;
|
|
557
515
|
for (let i = 0; i < lookupEncoded.length; i++)
|
|
558
|
-
hashTree[leavesStartIdx + i] =
|
|
516
|
+
hashTree[leavesStartIdx + i] = substrateBindings.Blake3256(lookupEncoded[i]);
|
|
559
517
|
for (let i = hashTree.length - 2; i > 0; i -= 2)
|
|
560
|
-
hashTree[(i - 1) / 2] =
|
|
518
|
+
hashTree[(i - 1) / 2] = substrateBindings.Blake3256(
|
|
561
519
|
mergeUint8([hashTree[i], hashTree[i + 1]])
|
|
562
520
|
);
|
|
563
521
|
return hashTree;
|
|
@@ -570,22 +528,22 @@ var merkleizeMetadata = (metadataBytes, info) => {
|
|
|
570
528
|
tag: "V1",
|
|
571
529
|
value: {
|
|
572
530
|
typeInformationTreeRoot: rootLookupHash,
|
|
573
|
-
extrinsicMetadataHash:
|
|
531
|
+
extrinsicMetadataHash: substrateBindings.Blake3256(extrinsicMetadata.enc(extrinsic)),
|
|
574
532
|
...info
|
|
575
533
|
}
|
|
576
534
|
};
|
|
577
|
-
return digested =
|
|
535
|
+
return digested = substrateBindings.Blake3256(metadataDigest.enc(digest2));
|
|
578
536
|
};
|
|
579
537
|
const generateProof = (knownIndexes) => {
|
|
580
538
|
const proofData = getProofData(lookupEncoded, knownIndexes);
|
|
581
539
|
const hashTree2 = getHashTree();
|
|
582
540
|
const proofs = proofData.proofIdxs.map((idx) => hashTree2[idx]);
|
|
583
541
|
return mergeUint8([
|
|
584
|
-
|
|
542
|
+
substrateBindings.compact.enc(proofData.leaves.length),
|
|
585
543
|
...proofData.leaves,
|
|
586
|
-
|
|
587
|
-
...proofData.leafIdxs.map((x) =>
|
|
588
|
-
|
|
544
|
+
substrateBindings.compact.enc(proofData.leafIdxs.length),
|
|
545
|
+
...proofData.leafIdxs.map((x) => substrateBindings.u32.enc(x)),
|
|
546
|
+
substrateBindings.compact.enc(proofs.length),
|
|
589
547
|
...proofs,
|
|
590
548
|
extrinsicMetadata.enc(extrinsic),
|
|
591
549
|
extraInfo.enc(info)
|
|
@@ -598,7 +556,7 @@ var merkleizeMetadata = (metadataBytes, info) => {
|
|
|
598
556
|
...extrinsic.signedExtensions.map((x) => x.includedInSignedData)
|
|
599
557
|
];
|
|
600
558
|
return generateProof(
|
|
601
|
-
decodeAndCollectKnownLeafs(extrinsicPayload, typeRefs,
|
|
559
|
+
decodeAndCollectKnownLeafs(extrinsicPayload, typeRefs, lookup)
|
|
602
560
|
);
|
|
603
561
|
};
|
|
604
562
|
const getProofForExtrinsicParts = (callData, includedInExtrinsic, includedInSignedData) => {
|
|
@@ -623,7 +581,7 @@ var merkleizeMetadata = (metadataBytes, info) => {
|
|
|
623
581
|
...extrinsic.signedExtensions.map((x) => x.includedInSignedData)
|
|
624
582
|
);
|
|
625
583
|
}
|
|
626
|
-
return generateProof(decodeAndCollectKnownLeafs(bytes, typeRefs,
|
|
584
|
+
return generateProof(decodeAndCollectKnownLeafs(bytes, typeRefs, lookup));
|
|
627
585
|
};
|
|
628
586
|
return {
|
|
629
587
|
digest,
|
|
@@ -632,4 +590,12 @@ var merkleizeMetadata = (metadataBytes, info) => {
|
|
|
632
590
|
getProofForExtrinsicPayload
|
|
633
591
|
};
|
|
634
592
|
};
|
|
635
|
-
|
|
593
|
+
|
|
594
|
+
exports.extraInfo = extraInfo;
|
|
595
|
+
exports.extrinsicMetadata = extrinsicMetadata;
|
|
596
|
+
exports.hash = hash;
|
|
597
|
+
exports.lookup = lookup;
|
|
598
|
+
exports.lookupType = lookupType;
|
|
599
|
+
exports.merkleizeMetadata = merkleizeMetadata;
|
|
600
|
+
exports.proof = proof;
|
|
601
|
+
//# sourceMappingURL=index.js.map
|