@koralabs/kora-labs-common 6.9.1 → 6.9.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/mpt/index.d.ts +26 -12
- package/mpt/index.js +27 -15
- package/package.json +1 -1
package/mpt/index.d.ts
CHANGED
|
@@ -3,27 +3,41 @@ import * as labelSet from './labelSet';
|
|
|
3
3
|
import * as registryValue from './registryValue';
|
|
4
4
|
export { labelSet, registryValue };
|
|
5
5
|
export { Trie };
|
|
6
|
+
/**
|
|
7
|
+
* A minting-data MPT entry. A bare string is shorthand for a handle with no registry value
|
|
8
|
+
* (value = ""). The object form carries the registry value the on-chain validator stores at the
|
|
9
|
+
* key: `registryValue.encode(freeNames, labels)`.
|
|
10
|
+
* - `freeNames`: a ROOT's currently-claimed FREE private-virtual sub names (the free-virtual
|
|
11
|
+
* allowance). The DeMi free-virtual mint/burn path writes this into the root key's value, so it
|
|
12
|
+
* MUST be supplied or the off-chain root drifts from chain on every root holding a free virtual.
|
|
13
|
+
* - `labels`: the sorted CIP-67 label set (001-004). The in-band `MintLabelAssets` path is NOT
|
|
14
|
+
* yet deployed on-chain, so callers pass "" today; flip to the real label set when it ships.
|
|
15
|
+
*/
|
|
16
|
+
export interface MintingDataEntry {
|
|
17
|
+
name: string;
|
|
18
|
+
freeNames?: string[];
|
|
19
|
+
labels?: string;
|
|
20
|
+
}
|
|
21
|
+
type MintingDataInput = ReadonlyArray<string | MintingDataEntry>;
|
|
6
22
|
/**
|
|
7
23
|
* THE canonical minting-data MPT (a real {@link Trie}, for proof generation during mint/burn).
|
|
8
24
|
* Consumers that only need the root hash should use {@link computeMintingDataRoot}; consumers that
|
|
9
|
-
* generate proofs (the minting engine's verifyRootHash) keep the returned Trie.
|
|
10
|
-
*
|
|
25
|
+
* generate proofs (the minting engine's verifyRootHash) keep the returned Trie.
|
|
26
|
+
*
|
|
27
|
+
* The value at each key is `registryValue.encode(freeNames, labels)` — byte-identical to what the
|
|
28
|
+
* on-chain `demimntmpt` validator stores (`mpt.update` verifies the old bytes). A handle with no
|
|
29
|
+
* free names and no labels encodes to "" (the legacy `update_root` `mpt.insert(root, name, #"")`
|
|
30
|
+
* case), so passing bare strings reproduces the empty-valued root exactly.
|
|
11
31
|
*/
|
|
12
|
-
export declare const buildMintingDataTrie: (
|
|
32
|
+
export declare const buildMintingDataTrie: (handles: MintingDataInput) => Promise<Trie>;
|
|
13
33
|
/**
|
|
14
34
|
* THE canonical minting-data MPT root. Every Node service (api.handle.me, the minting engine,
|
|
15
35
|
* handle.me/bff) and the on-chain mirror (@koralabs/handles-decentralized-minting) MUST compute
|
|
16
36
|
* the root through this one function, so the off-chain root can never drift from what the
|
|
17
|
-
* validator maintains. (It drifted before because api + engine each re-derived it independently
|
|
18
|
-
*
|
|
19
|
-
* Value = "" (empty) per the legacy/DeMi mint validator's `update_root`:
|
|
20
|
-
* `mpt.insert(root, handle_name, #"", proof)`
|
|
21
|
-
* Labels (001/002…) are NOT in the root until the in-band `MintLabelAssets` path is deployed;
|
|
22
|
-
* until then the off-chain root MUST use empty values or it diverges from chain on every labeled
|
|
23
|
-
* handle. When labels go in-band, change ONLY this function (accept a registry arg, set
|
|
24
|
-
* value = registryValue.encode(freeNames, labels)) and every consumer moves in lockstep.
|
|
37
|
+
* validator maintains. (It drifted before because api + engine each re-derived it independently —
|
|
38
|
+
* and again when this function ignored the free-virtual registry value the contract writes.)
|
|
25
39
|
*
|
|
26
40
|
* Order-independent (MPT root is determined by the key/value set), so callers need not sort;
|
|
27
41
|
* duplicate keys are de-duped to avoid a Trie insert throw.
|
|
28
42
|
*/
|
|
29
|
-
export declare const computeMintingDataRoot: (
|
|
43
|
+
export declare const computeMintingDataRoot: (handles: MintingDataInput) => Promise<string>;
|
package/mpt/index.js
CHANGED
|
@@ -38,33 +38,45 @@ const EMPTY_ROOT_HEX = Buffer.alloc(32).toString('hex');
|
|
|
38
38
|
/**
|
|
39
39
|
* THE canonical minting-data MPT (a real {@link Trie}, for proof generation during mint/burn).
|
|
40
40
|
* Consumers that only need the root hash should use {@link computeMintingDataRoot}; consumers that
|
|
41
|
-
* generate proofs (the minting engine's verifyRootHash) keep the returned Trie.
|
|
42
|
-
*
|
|
41
|
+
* generate proofs (the minting engine's verifyRootHash) keep the returned Trie.
|
|
42
|
+
*
|
|
43
|
+
* The value at each key is `registryValue.encode(freeNames, labels)` — byte-identical to what the
|
|
44
|
+
* on-chain `demimntmpt` validator stores (`mpt.update` verifies the old bytes). A handle with no
|
|
45
|
+
* free names and no labels encodes to "" (the legacy `update_root` `mpt.insert(root, name, #"")`
|
|
46
|
+
* case), so passing bare strings reproduces the empty-valued root exactly.
|
|
43
47
|
*/
|
|
44
|
-
const buildMintingDataTrie = async (
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
const buildMintingDataTrie = async (handles) => {
|
|
49
|
+
var _a, _b;
|
|
50
|
+
const seen = new Set();
|
|
51
|
+
const entries = [];
|
|
52
|
+
for (const handle of handles) {
|
|
53
|
+
const name = typeof handle === 'string' ? handle : handle.name;
|
|
54
|
+
if (!name || seen.has(name))
|
|
55
|
+
continue;
|
|
56
|
+
seen.add(name);
|
|
57
|
+
const freeNames = typeof handle === 'string' ? [] : (_a = handle.freeNames) !== null && _a !== void 0 ? _a : [];
|
|
58
|
+
const labels = typeof handle === 'string' ? '' : (_b = handle.labels) !== null && _b !== void 0 ? _b : '';
|
|
59
|
+
const encoded = registryValue.encode(freeNames, labels);
|
|
60
|
+
// MPF treats string values as UTF-8; supply the decoded bytes for a non-empty registry
|
|
61
|
+
// value, and "" (an empty value) for the common no-registry case.
|
|
62
|
+
entries.push({ key: name, value: encoded ? Buffer.from(encoded, 'hex') : '' });
|
|
63
|
+
}
|
|
64
|
+
return merkle_patricia_forestry_1.Trie.fromList(entries);
|
|
47
65
|
};
|
|
48
66
|
exports.buildMintingDataTrie = buildMintingDataTrie;
|
|
49
67
|
/**
|
|
50
68
|
* THE canonical minting-data MPT root. Every Node service (api.handle.me, the minting engine,
|
|
51
69
|
* handle.me/bff) and the on-chain mirror (@koralabs/handles-decentralized-minting) MUST compute
|
|
52
70
|
* the root through this one function, so the off-chain root can never drift from what the
|
|
53
|
-
* validator maintains. (It drifted before because api + engine each re-derived it independently
|
|
54
|
-
*
|
|
55
|
-
* Value = "" (empty) per the legacy/DeMi mint validator's `update_root`:
|
|
56
|
-
* `mpt.insert(root, handle_name, #"", proof)`
|
|
57
|
-
* Labels (001/002…) are NOT in the root until the in-band `MintLabelAssets` path is deployed;
|
|
58
|
-
* until then the off-chain root MUST use empty values or it diverges from chain on every labeled
|
|
59
|
-
* handle. When labels go in-band, change ONLY this function (accept a registry arg, set
|
|
60
|
-
* value = registryValue.encode(freeNames, labels)) and every consumer moves in lockstep.
|
|
71
|
+
* validator maintains. (It drifted before because api + engine each re-derived it independently —
|
|
72
|
+
* and again when this function ignored the free-virtual registry value the contract writes.)
|
|
61
73
|
*
|
|
62
74
|
* Order-independent (MPT root is determined by the key/value set), so callers need not sort;
|
|
63
75
|
* duplicate keys are de-duped to avoid a Trie insert throw.
|
|
64
76
|
*/
|
|
65
|
-
const computeMintingDataRoot = async (
|
|
77
|
+
const computeMintingDataRoot = async (handles) => {
|
|
66
78
|
var _a, _b;
|
|
67
|
-
const trie = await (0, exports.buildMintingDataTrie)(
|
|
79
|
+
const trie = await (0, exports.buildMintingDataTrie)(handles);
|
|
68
80
|
return (_b = (_a = trie.hash) === null || _a === void 0 ? void 0 : _a.toString('hex')) !== null && _b !== void 0 ? _b : EMPTY_ROOT_HEX;
|
|
69
81
|
};
|
|
70
82
|
exports.computeMintingDataRoot = computeMintingDataRoot;
|