@hashgraphonline/standards-sdk 0.0.69 → 0.0.70
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/README.md +13 -0
- package/dist/es/fees/fee-config-builder.d.ts +93 -45
- package/dist/es/fees/fee-config-builder.d.ts.map +1 -1
- package/dist/es/fees/types.d.ts +14 -12
- package/dist/es/fees/types.d.ts.map +1 -1
- package/dist/es/hcs-10/base-client.d.ts +8 -1
- package/dist/es/hcs-10/base-client.d.ts.map +1 -1
- package/dist/es/hcs-10/browser.d.ts.map +1 -1
- package/dist/es/hcs-10/sdk.d.ts +9 -1
- package/dist/es/hcs-10/sdk.d.ts.map +1 -1
- package/dist/es/services/mirror-node.d.ts +74 -1
- package/dist/es/services/mirror-node.d.ts.map +1 -1
- package/dist/es/services/types.d.ts +29 -0
- package/dist/es/services/types.d.ts.map +1 -1
- package/dist/es/standards-sdk.es.js +2 -0
- package/dist/es/standards-sdk.es.js.map +1 -1
- package/dist/es/standards-sdk.es100.js +60 -3
- package/dist/es/standards-sdk.es100.js.map +1 -1
- package/dist/es/standards-sdk.es101.js +1288 -3
- package/dist/es/standards-sdk.es101.js.map +1 -1
- package/dist/es/standards-sdk.es102.js +146 -14
- package/dist/es/standards-sdk.es102.js.map +1 -1
- package/dist/es/standards-sdk.es103.js +90 -4
- package/dist/es/standards-sdk.es103.js.map +1 -1
- package/dist/es/standards-sdk.es104.js +84 -39
- package/dist/es/standards-sdk.es104.js.map +1 -1
- package/dist/es/standards-sdk.es105.js +28 -36
- package/dist/es/standards-sdk.es105.js.map +1 -1
- package/dist/es/standards-sdk.es106.js +6 -37
- package/dist/es/standards-sdk.es106.js.map +1 -1
- package/dist/es/standards-sdk.es107.js +150 -69
- package/dist/es/standards-sdk.es107.js.map +1 -1
- package/dist/es/standards-sdk.es108.js +23 -3
- package/dist/es/standards-sdk.es108.js.map +1 -1
- package/dist/es/standards-sdk.es109.js +793 -2
- package/dist/es/standards-sdk.es109.js.map +1 -1
- package/dist/es/standards-sdk.es110.js +174 -2
- package/dist/es/standards-sdk.es110.js.map +1 -1
- package/dist/es/standards-sdk.es111.js +142 -33
- package/dist/es/standards-sdk.es111.js.map +1 -1
- package/dist/es/standards-sdk.es112.js +20 -32
- package/dist/es/standards-sdk.es112.js.map +1 -1
- package/dist/es/standards-sdk.es113.js +27 -9
- package/dist/es/standards-sdk.es113.js.map +1 -1
- package/dist/es/standards-sdk.es114.js +25 -33
- package/dist/es/standards-sdk.es114.js.map +1 -1
- package/dist/es/standards-sdk.es115.js +41 -0
- package/dist/es/standards-sdk.es115.js.map +1 -0
- package/dist/es/standards-sdk.es14.js +1 -1
- package/dist/es/standards-sdk.es18.js +91 -3
- package/dist/es/standards-sdk.es18.js.map +1 -1
- package/dist/es/standards-sdk.es19.js +127 -67
- package/dist/es/standards-sdk.es19.js.map +1 -1
- package/dist/es/standards-sdk.es20.js +7 -1041
- package/dist/es/standards-sdk.es20.js.map +1 -1
- package/dist/es/standards-sdk.es23.js +17 -17
- package/dist/es/standards-sdk.es24.js +2 -2
- package/dist/es/standards-sdk.es25.js +1 -1
- package/dist/es/standards-sdk.es27.js +1041 -5
- package/dist/es/standards-sdk.es27.js.map +1 -1
- package/dist/es/standards-sdk.es29.js +5 -419
- package/dist/es/standards-sdk.es29.js.map +1 -1
- package/dist/es/standards-sdk.es30.js +419 -2
- package/dist/es/standards-sdk.es30.js.map +1 -1
- package/dist/es/standards-sdk.es31.js +2 -120
- package/dist/es/standards-sdk.es31.js.map +1 -1
- package/dist/es/standards-sdk.es32.js +120 -3
- package/dist/es/standards-sdk.es32.js.map +1 -1
- package/dist/es/standards-sdk.es33.js +3 -164
- package/dist/es/standards-sdk.es33.js.map +1 -1
- package/dist/es/standards-sdk.es34.js +164 -2
- package/dist/es/standards-sdk.es34.js.map +1 -1
- package/dist/es/standards-sdk.es35.js +3 -194
- package/dist/es/standards-sdk.es35.js.map +1 -1
- package/dist/es/standards-sdk.es36.js +334 -408
- package/dist/es/standards-sdk.es36.js.map +1 -1
- package/dist/es/standards-sdk.es37.js +5 -24
- package/dist/es/standards-sdk.es37.js.map +1 -1
- package/dist/es/standards-sdk.es38.js +165 -125
- package/dist/es/standards-sdk.es38.js.map +1 -1
- package/dist/es/standards-sdk.es39.js +76 -13
- package/dist/es/standards-sdk.es39.js.map +1 -1
- package/dist/es/standards-sdk.es4.js +1 -1
- package/dist/es/standards-sdk.es40.js +111 -26
- package/dist/es/standards-sdk.es40.js.map +1 -1
- package/dist/es/standards-sdk.es41.js +47 -24
- package/dist/es/standards-sdk.es41.js.map +1 -1
- package/dist/es/standards-sdk.es42.js +9 -20
- package/dist/es/standards-sdk.es42.js.map +1 -1
- package/dist/es/standards-sdk.es43.js +90 -37
- package/dist/es/standards-sdk.es43.js.map +1 -1
- package/dist/es/standards-sdk.es44.js +3 -17
- package/dist/es/standards-sdk.es44.js.map +1 -1
- package/dist/es/standards-sdk.es45.js +2 -61
- package/dist/es/standards-sdk.es45.js.map +1 -1
- package/dist/es/standards-sdk.es46.js +107 -1283
- package/dist/es/standards-sdk.es46.js.map +1 -1
- package/dist/es/standards-sdk.es47.js +69 -143
- package/dist/es/standards-sdk.es47.js.map +1 -1
- package/dist/es/standards-sdk.es48.js +5 -90
- package/dist/es/standards-sdk.es48.js.map +1 -1
- package/dist/es/standards-sdk.es49.js +4 -83
- package/dist/es/standards-sdk.es49.js.map +1 -1
- package/dist/es/standards-sdk.es5.js +17 -0
- package/dist/es/standards-sdk.es5.js.map +1 -1
- package/dist/es/standards-sdk.es50.js +215 -26
- package/dist/es/standards-sdk.es50.js.map +1 -1
- package/dist/es/standards-sdk.es51.js +58 -6
- package/dist/es/standards-sdk.es51.js.map +1 -1
- package/dist/es/standards-sdk.es52.js +69 -159
- package/dist/es/standards-sdk.es52.js.map +1 -1
- package/dist/es/standards-sdk.es53.js +100 -22
- package/dist/es/standards-sdk.es53.js.map +1 -1
- package/dist/es/standards-sdk.es54.js +2 -793
- package/dist/es/standards-sdk.es54.js.map +1 -1
- package/dist/es/standards-sdk.es55.js +15 -173
- package/dist/es/standards-sdk.es55.js.map +1 -1
- package/dist/es/standards-sdk.es56.js +400 -134
- package/dist/es/standards-sdk.es56.js.map +1 -1
- package/dist/es/standards-sdk.es57.js +31 -3
- package/dist/es/standards-sdk.es57.js.map +1 -1
- package/dist/es/standards-sdk.es58.js +58 -16
- package/dist/es/standards-sdk.es58.js.map +1 -1
- package/dist/es/standards-sdk.es59.js +47 -24
- package/dist/es/standards-sdk.es59.js.map +1 -1
- package/dist/es/standards-sdk.es60.js +8 -24
- package/dist/es/standards-sdk.es60.js.map +1 -1
- package/dist/es/standards-sdk.es61.js +63 -36
- package/dist/es/standards-sdk.es61.js.map +1 -1
- package/dist/es/standards-sdk.es62.js +5 -363
- package/dist/es/standards-sdk.es62.js.map +1 -1
- package/dist/es/standards-sdk.es63.js +14 -5
- package/dist/es/standards-sdk.es63.js.map +1 -1
- package/dist/es/standards-sdk.es64.js +7 -179
- package/dist/es/standards-sdk.es64.js.map +1 -1
- package/dist/es/standards-sdk.es65.js +42 -78
- package/dist/es/standards-sdk.es65.js.map +1 -1
- package/dist/es/standards-sdk.es66.js +2 -114
- package/dist/es/standards-sdk.es66.js.map +1 -1
- package/dist/es/standards-sdk.es67.js +135 -51
- package/dist/es/standards-sdk.es67.js.map +1 -1
- package/dist/es/standards-sdk.es68.js +171 -9
- package/dist/es/standards-sdk.es68.js.map +1 -1
- package/dist/es/standards-sdk.es69.js +2282 -97
- package/dist/es/standards-sdk.es69.js.map +1 -1
- package/dist/es/standards-sdk.es7.js +93 -37
- package/dist/es/standards-sdk.es7.js.map +1 -1
- package/dist/es/standards-sdk.es70.js +13 -4
- package/dist/es/standards-sdk.es70.js.map +1 -1
- package/dist/es/standards-sdk.es71.js +13 -2
- package/dist/es/standards-sdk.es71.js.map +1 -1
- package/dist/es/standards-sdk.es72.js +30 -111
- package/dist/es/standards-sdk.es72.js.map +1 -1
- package/dist/es/standards-sdk.es73.js +14 -73
- package/dist/es/standards-sdk.es73.js.map +1 -1
- package/dist/es/standards-sdk.es74.js +3 -5
- package/dist/es/standards-sdk.es74.js.map +1 -1
- package/dist/es/standards-sdk.es75.js +3 -4
- package/dist/es/standards-sdk.es75.js.map +1 -1
- package/dist/es/standards-sdk.es76.js +14 -219
- package/dist/es/standards-sdk.es76.js.map +1 -1
- package/dist/es/standards-sdk.es77.js +5 -58
- package/dist/es/standards-sdk.es77.js.map +1 -1
- package/dist/es/standards-sdk.es78.js +38 -68
- package/dist/es/standards-sdk.es78.js.map +1 -1
- package/dist/es/standards-sdk.es79.js +37 -98
- package/dist/es/standards-sdk.es79.js.map +1 -1
- package/dist/es/standards-sdk.es8.js +0 -1
- package/dist/es/standards-sdk.es8.js.map +1 -1
- package/dist/es/standards-sdk.es80.js +37 -2
- package/dist/es/standards-sdk.es80.js.map +1 -1
- package/dist/es/standards-sdk.es81.js +78 -16
- package/dist/es/standards-sdk.es81.js.map +1 -1
- package/dist/es/standards-sdk.es82.js +3 -409
- package/dist/es/standards-sdk.es82.js.map +1 -1
- package/dist/es/standards-sdk.es83.js +2 -32
- package/dist/es/standards-sdk.es83.js.map +1 -1
- package/dist/es/standards-sdk.es84.js +2 -63
- package/dist/es/standards-sdk.es84.js.map +1 -1
- package/dist/es/standards-sdk.es85.js +2 -50
- package/dist/es/standards-sdk.es85.js.map +1 -1
- package/dist/es/standards-sdk.es86.js +33 -9
- package/dist/es/standards-sdk.es86.js.map +1 -1
- package/dist/es/standards-sdk.es87.js +28 -60
- package/dist/es/standards-sdk.es87.js.map +1 -1
- package/dist/es/standards-sdk.es88.js +9 -6
- package/dist/es/standards-sdk.es88.js.map +1 -1
- package/dist/es/standards-sdk.es89.js +33 -14
- package/dist/es/standards-sdk.es89.js.map +1 -1
- package/dist/es/standards-sdk.es90.js +194 -6
- package/dist/es/standards-sdk.es90.js.map +1 -1
- package/dist/es/standards-sdk.es91.js +432 -39
- package/dist/es/standards-sdk.es91.js.map +1 -1
- package/dist/es/standards-sdk.es92.js +25 -2
- package/dist/es/standards-sdk.es92.js.map +1 -1
- package/dist/es/standards-sdk.es93.js +127 -124
- package/dist/es/standards-sdk.es93.js.map +1 -1
- package/dist/es/standards-sdk.es94.js +14 -168
- package/dist/es/standards-sdk.es94.js.map +1 -1
- package/dist/es/standards-sdk.es95.js +29 -2282
- package/dist/es/standards-sdk.es95.js.map +1 -1
- package/dist/es/standards-sdk.es96.js +29 -13
- package/dist/es/standards-sdk.es96.js.map +1 -1
- package/dist/es/standards-sdk.es97.js +21 -13
- package/dist/es/standards-sdk.es97.js.map +1 -1
- package/dist/es/standards-sdk.es98.js +43 -31
- package/dist/es/standards-sdk.es98.js.map +1 -1
- package/dist/es/standards-sdk.es99.js +17 -14
- package/dist/es/standards-sdk.es99.js.map +1 -1
- package/dist/es/utils/index.d.ts +1 -0
- package/dist/es/utils/index.d.ts.map +1 -1
- package/dist/es/utils/types.d.ts +3 -0
- package/dist/es/utils/types.d.ts.map +1 -1
- package/dist/umd/fees/fee-config-builder.d.ts +93 -45
- package/dist/umd/fees/fee-config-builder.d.ts.map +1 -1
- package/dist/umd/fees/types.d.ts +14 -12
- package/dist/umd/fees/types.d.ts.map +1 -1
- package/dist/umd/hcs-10/base-client.d.ts +8 -1
- package/dist/umd/hcs-10/base-client.d.ts.map +1 -1
- package/dist/umd/hcs-10/browser.d.ts.map +1 -1
- package/dist/umd/hcs-10/sdk.d.ts +9 -1
- package/dist/umd/hcs-10/sdk.d.ts.map +1 -1
- package/dist/umd/services/mirror-node.d.ts +74 -1
- package/dist/umd/services/mirror-node.d.ts.map +1 -1
- package/dist/umd/services/types.d.ts +29 -0
- package/dist/umd/services/types.d.ts.map +1 -1
- package/dist/umd/standards-sdk.umd.js +1 -1
- package/dist/umd/standards-sdk.umd.js.map +1 -1
- package/dist/umd/utils/index.d.ts +1 -0
- package/dist/umd/utils/index.d.ts.map +1 -1
- package/dist/umd/utils/types.d.ts +3 -0
- package/dist/umd/utils/types.d.ts.map +1 -1
- package/package.json +2 -1
|
@@ -1,37 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
read(name) {
|
|
15
|
-
const match = document.cookie.match(new RegExp("(^|;\\s*)(" + name + ")=([^;]*)"));
|
|
16
|
-
return match ? decodeURIComponent(match[3]) : null;
|
|
17
|
-
},
|
|
18
|
-
remove(name) {
|
|
19
|
-
this.write(name, "", Date.now() - 864e5);
|
|
20
|
-
}
|
|
1
|
+
const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
2
|
+
const _32n = /* @__PURE__ */ BigInt(32);
|
|
3
|
+
function fromBig(n, le = false) {
|
|
4
|
+
if (le)
|
|
5
|
+
return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
|
|
6
|
+
return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
7
|
+
}
|
|
8
|
+
function split(lst, le = false) {
|
|
9
|
+
let Ah = new Uint32Array(lst.length);
|
|
10
|
+
let Al = new Uint32Array(lst.length);
|
|
11
|
+
for (let i = 0; i < lst.length; i++) {
|
|
12
|
+
const { h, l } = fromBig(lst[i], le);
|
|
13
|
+
[Ah[i], Al[i]] = [h, l];
|
|
21
14
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return null;
|
|
29
|
-
},
|
|
30
|
-
remove() {
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
);
|
|
15
|
+
return [Ah, Al];
|
|
16
|
+
}
|
|
17
|
+
const rotlSH = (h, l, s) => h << s | l >>> 32 - s;
|
|
18
|
+
const rotlSL = (h, l, s) => l << s | h >>> 32 - s;
|
|
19
|
+
const rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
|
|
20
|
+
const rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
|
|
34
21
|
export {
|
|
35
|
-
|
|
22
|
+
fromBig,
|
|
23
|
+
rotlBH,
|
|
24
|
+
rotlBL,
|
|
25
|
+
rotlSH,
|
|
26
|
+
rotlSL,
|
|
27
|
+
split
|
|
36
28
|
};
|
|
37
29
|
//# sourceMappingURL=standards-sdk.es114.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es114.js","sources":["../../node_modules/
|
|
1
|
+
{"version":3,"file":"standards-sdk.es114.js","sources":["../../node_modules/@noble/hashes/esm/_u64.js"],"sourcesContent":["const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);\nconst _32n = /* @__PURE__ */ BigInt(32);\n// We are not using BigUint64Array, because they are extremely slow as per 2022\nfunction fromBig(n, le = false) {\n if (le)\n return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };\n return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };\n}\nfunction split(lst, le = false) {\n let Ah = new Uint32Array(lst.length);\n let Al = new Uint32Array(lst.length);\n for (let i = 0; i < lst.length; i++) {\n const { h, l } = fromBig(lst[i], le);\n [Ah[i], Al[i]] = [h, l];\n }\n return [Ah, Al];\n}\nconst toBig = (h, l) => (BigInt(h >>> 0) << _32n) | BigInt(l >>> 0);\n// for Shift in [0, 32)\nconst shrSH = (h, _l, s) => h >>> s;\nconst shrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);\n// Right rotate for Shift in [1, 32)\nconst rotrSH = (h, l, s) => (h >>> s) | (l << (32 - s));\nconst rotrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);\n// Right rotate for Shift in (32, 64), NOTE: 32 is special case.\nconst rotrBH = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32));\nconst rotrBL = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s));\n// Right rotate for shift===32 (just swaps l&h)\nconst rotr32H = (_h, l) => l;\nconst rotr32L = (h, _l) => h;\n// Left rotate for Shift in [1, 32)\nconst rotlSH = (h, l, s) => (h << s) | (l >>> (32 - s));\nconst rotlSL = (h, l, s) => (l << s) | (h >>> (32 - s));\n// Left rotate for Shift in (32, 64), NOTE: 32 is special case.\nconst rotlBH = (h, l, s) => (l << (s - 32)) | (h >>> (64 - s));\nconst rotlBL = (h, l, s) => (h << (s - 32)) | (l >>> (64 - s));\n// JS uses 32-bit signed integers for bitwise operations which means we cannot\n// simple take carry out of low bit sum by shift, we need to use division.\nfunction add(Ah, Al, Bh, Bl) {\n const l = (Al >>> 0) + (Bl >>> 0);\n return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };\n}\n// Addition with more than 2 elements\nconst add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);\nconst add3H = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;\nconst add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);\nconst add4H = (low, Ah, Bh, Ch, Dh) => (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0;\nconst add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);\nconst add5H = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;\n// prettier-ignore\nexport { fromBig, split, toBig, shrSH, shrSL, rotrSH, rotrSL, rotrBH, rotrBL, rotr32H, rotr32L, rotlSH, rotlSL, rotlBH, rotlBL, add, add3L, add3H, add4L, add4H, add5H, add5L, };\n// prettier-ignore\nconst u64 = {\n fromBig, split, toBig,\n shrSH, shrSL,\n rotrSH, rotrSL, rotrBH, rotrBL,\n rotr32H, rotr32L,\n rotlSH, rotlSL, rotlBH, rotlBL,\n add, add3L, add3H, add4L, add4H, add5H, add5L,\n};\nexport default u64;\n//# sourceMappingURL=_u64.js.map"],"names":[],"mappings":"AAAA,MAAM,aAA6B,uBAAO,KAAK,KAAK,CAAC;AACrD,MAAM,OAAuB,uBAAO,EAAE;AAEtC,SAAS,QAAQ,GAAG,KAAK,OAAO;AAC5B,MAAI;AACA,WAAO,EAAE,GAAG,OAAO,IAAI,UAAU,GAAG,GAAG,OAAQ,KAAK,OAAQ,UAAU,EAAG;AAC7E,SAAO,EAAE,GAAG,OAAQ,KAAK,OAAQ,UAAU,IAAI,GAAG,GAAG,OAAO,IAAI,UAAU,IAAI,EAAG;AACrF;AACA,SAAS,MAAM,KAAK,KAAK,OAAO;AAC5B,MAAI,KAAK,IAAI,YAAY,IAAI,MAAM;AACnC,MAAI,KAAK,IAAI,YAAY,IAAI,MAAM;AACnC,WAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;AACjC,UAAM,EAAE,GAAG,EAAG,IAAG,QAAQ,IAAI,CAAC,GAAG,EAAE;AACnC,KAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;AAAA,EAC9B;AACI,SAAO,CAAC,IAAI,EAAE;AAClB;AAeK,MAAC,SAAS,CAAC,GAAG,GAAG,MAAO,KAAK,IAAM,MAAO,KAAK;AAC/C,MAAC,SAAS,CAAC,GAAG,GAAG,MAAO,KAAK,IAAM,MAAO,KAAK;AAE/C,MAAC,SAAS,CAAC,GAAG,GAAG,MAAO,KAAM,IAAI,KAAQ,MAAO,KAAK;AACtD,MAAC,SAAS,CAAC,GAAG,GAAG,MAAO,KAAM,IAAI,KAAQ,MAAO,KAAK;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
2
|
+
const u8a = (a) => a instanceof Uint8Array;
|
|
3
|
+
const u32 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
4
|
+
const isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
5
|
+
if (!isLE)
|
|
6
|
+
throw new Error("Non little-endian hardware is not supported");
|
|
7
|
+
function utf8ToBytes(str) {
|
|
8
|
+
if (typeof str !== "string")
|
|
9
|
+
throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
|
|
10
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
|
11
|
+
}
|
|
12
|
+
function toBytes(data) {
|
|
13
|
+
if (typeof data === "string")
|
|
14
|
+
data = utf8ToBytes(data);
|
|
15
|
+
if (!u8a(data))
|
|
16
|
+
throw new Error(`expected Uint8Array, got ${typeof data}`);
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
class Hash {
|
|
20
|
+
// Safe version that clones internal state
|
|
21
|
+
clone() {
|
|
22
|
+
return this._cloneInto();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function wrapConstructor(hashCons) {
|
|
26
|
+
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
27
|
+
const tmp = hashCons();
|
|
28
|
+
hashC.outputLen = tmp.outputLen;
|
|
29
|
+
hashC.blockLen = tmp.blockLen;
|
|
30
|
+
hashC.create = () => hashCons();
|
|
31
|
+
return hashC;
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
Hash,
|
|
35
|
+
isLE,
|
|
36
|
+
toBytes,
|
|
37
|
+
u32,
|
|
38
|
+
utf8ToBytes,
|
|
39
|
+
wrapConstructor
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=standards-sdk.es115.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standards-sdk.es115.js","sources":["../../node_modules/@noble/hashes/esm/utils.js"],"sourcesContent":["/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */\n// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.\n// node.js versions earlier than v19 don't declare it in global scope.\n// For node.js, package.json#exports field mapping rewrites import\n// from `crypto` to `cryptoNode`, which imports native module.\n// Makes the utils un-importable in browsers without a bundler.\n// Once node.js 18 is deprecated, we can just drop the import.\nimport { crypto } from '@noble/hashes/crypto';\nconst u8a = (a) => a instanceof Uint8Array;\n// Cast array to different type\nexport const u8 = (arr) => new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);\nexport const u32 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));\n// Cast array to view\nexport const createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);\n// The rotate right (circular right shift) operation for uint32\nexport const rotr = (word, shift) => (word << (32 - shift)) | (word >>> shift);\n// big-endian hardware is rare. Just in case someone still decides to run hashes:\n// early-throw an error because we don't support BE yet.\nexport const isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;\nif (!isLE)\n throw new Error('Non little-endian hardware is not supported');\nconst hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));\n/**\n * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'\n */\nexport function bytesToHex(bytes) {\n if (!u8a(bytes))\n throw new Error('Uint8Array expected');\n // pre-caching improves the speed 6x\n let hex = '';\n for (let i = 0; i < bytes.length; i++) {\n hex += hexes[bytes[i]];\n }\n return hex;\n}\n/**\n * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])\n */\nexport function hexToBytes(hex) {\n if (typeof hex !== 'string')\n throw new Error('hex string expected, got ' + typeof hex);\n const len = hex.length;\n if (len % 2)\n throw new Error('padded hex string expected, got unpadded hex of length ' + len);\n const array = new Uint8Array(len / 2);\n for (let i = 0; i < array.length; i++) {\n const j = i * 2;\n const hexByte = hex.slice(j, j + 2);\n const byte = Number.parseInt(hexByte, 16);\n if (Number.isNaN(byte) || byte < 0)\n throw new Error('Invalid byte sequence');\n array[i] = byte;\n }\n return array;\n}\n// There is no setImmediate in browser and setTimeout is slow.\n// call of async fn will return Promise, which will be fullfiled only on\n// next scheduler queue processing step and this is exactly what we need.\nexport const nextTick = async () => { };\n// Returns control to thread each 'tick' ms to avoid blocking\nexport async function asyncLoop(iters, tick, cb) {\n let ts = Date.now();\n for (let i = 0; i < iters; i++) {\n cb(i);\n // Date.now() is not monotonic, so in case if clock goes backwards we return return control too\n const diff = Date.now() - ts;\n if (diff >= 0 && diff < tick)\n continue;\n await nextTick();\n ts += diff;\n }\n}\n/**\n * @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])\n */\nexport function utf8ToBytes(str) {\n if (typeof str !== 'string')\n throw new Error(`utf8ToBytes expected string, got ${typeof str}`);\n return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809\n}\n/**\n * Normalizes (non-hex) string or Uint8Array to Uint8Array.\n * Warning: when Uint8Array is passed, it would NOT get copied.\n * Keep in mind for future mutable operations.\n */\nexport function toBytes(data) {\n if (typeof data === 'string')\n data = utf8ToBytes(data);\n if (!u8a(data))\n throw new Error(`expected Uint8Array, got ${typeof data}`);\n return data;\n}\n/**\n * Copies several Uint8Arrays into one.\n */\nexport function concatBytes(...arrays) {\n const r = new Uint8Array(arrays.reduce((sum, a) => sum + a.length, 0));\n let pad = 0; // walk through each item, ensure they have proper type\n arrays.forEach((a) => {\n if (!u8a(a))\n throw new Error('Uint8Array expected');\n r.set(a, pad);\n pad += a.length;\n });\n return r;\n}\n// For runtime check if class implements interface\nexport class Hash {\n // Safe version that clones internal state\n clone() {\n return this._cloneInto();\n }\n}\nconst toStr = {}.toString;\nexport function checkOpts(defaults, opts) {\n if (opts !== undefined && toStr.call(opts) !== '[object Object]')\n throw new Error('Options should be object or undefined');\n const merged = Object.assign(defaults, opts);\n return merged;\n}\nexport function wrapConstructor(hashCons) {\n const hashC = (msg) => hashCons().update(toBytes(msg)).digest();\n const tmp = hashCons();\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = () => hashCons();\n return hashC;\n}\nexport function wrapConstructorWithOpts(hashCons) {\n const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();\n const tmp = hashCons({});\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = (opts) => hashCons(opts);\n return hashC;\n}\nexport function wrapXOFConstructorWithOpts(hashCons) {\n const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();\n const tmp = hashCons({});\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = (opts) => hashCons(opts);\n return hashC;\n}\n/**\n * Secure PRNG. Uses `crypto.getRandomValues`, which defers to OS.\n */\nexport function randomBytes(bytesLength = 32) {\n if (crypto && typeof crypto.getRandomValues === 'function') {\n return crypto.getRandomValues(new Uint8Array(bytesLength));\n }\n throw new Error('crypto.getRandomValues must be defined');\n}\n//# sourceMappingURL=utils.js.map"],"names":[],"mappings":"AAAA;AAQA,MAAM,MAAM,CAAC,MAAM,aAAa;AAGpB,MAAC,MAAM,CAAC,QAAQ,IAAI,YAAY,IAAI,QAAQ,IAAI,YAAY,KAAK,MAAM,IAAI,aAAa,CAAC,CAAC;AAO1F,MAAC,OAAO,IAAI,WAAW,IAAI,YAAY,CAAC,SAAU,CAAC,EAAE,MAAM,EAAE,CAAC,MAAM;AAChF,IAAI,CAAC;AACD,QAAM,IAAI,MAAM,6CAA6C;AAuD1D,SAAS,YAAY,KAAK;AAC7B,MAAI,OAAO,QAAQ;AACf,UAAM,IAAI,MAAM,oCAAoC,OAAO,GAAG,EAAE;AACpE,SAAO,IAAI,WAAW,IAAI,YAAa,EAAC,OAAO,GAAG,CAAC;AACvD;AAMO,SAAS,QAAQ,MAAM;AAC1B,MAAI,OAAO,SAAS;AAChB,WAAO,YAAY,IAAI;AAC3B,MAAI,CAAC,IAAI,IAAI;AACT,UAAM,IAAI,MAAM,4BAA4B,OAAO,IAAI,EAAE;AAC7D,SAAO;AACX;AAgBO,MAAM,KAAK;AAAA;AAAA,EAEd,QAAQ;AACJ,WAAO,KAAK,WAAY;AAAA,EAChC;AACA;AAQO,SAAS,gBAAgB,UAAU;AACtC,QAAM,QAAQ,CAAC,QAAQ,SAAU,EAAC,OAAO,QAAQ,GAAG,CAAC,EAAE,OAAQ;AAC/D,QAAM,MAAM,SAAU;AACtB,QAAM,YAAY,IAAI;AACtB,QAAM,WAAW,IAAI;AACrB,QAAM,SAAS,MAAM,SAAU;AAC/B,SAAO;AACX;","x_google_ignoreList":[0]}
|
|
@@ -16,6 +16,12 @@ class HederaMirrorNode {
|
|
|
16
16
|
getBaseUrl() {
|
|
17
17
|
return this.baseUrl;
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves the public key for a given account ID from the mirror node.
|
|
21
|
+
* @param accountId The ID of the account to retrieve the public key for.
|
|
22
|
+
* @returns A promise that resolves to the public key for the given account.
|
|
23
|
+
* @throws An error if the account ID is invalid or the public key cannot be retrieved.
|
|
24
|
+
*/
|
|
19
25
|
async getPublicKey(accountId) {
|
|
20
26
|
this.logger.info(`Getting public key for account ${accountId}`);
|
|
21
27
|
const accountInfo = await this.requestAccount(accountId);
|
|
@@ -32,6 +38,12 @@ class HederaMirrorNode {
|
|
|
32
38
|
);
|
|
33
39
|
}
|
|
34
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Retrieves the memo for a given account ID from the mirror node.
|
|
43
|
+
* @param accountId The ID of the account to retrieve the memo for.
|
|
44
|
+
* @returns A promise that resolves to the memo for the given account.
|
|
45
|
+
* @throws An error if the account ID is invalid or the memo cannot be retrieved.
|
|
46
|
+
*/
|
|
35
47
|
async getAccountMemo(accountId) {
|
|
36
48
|
const maxRetries = 3;
|
|
37
49
|
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
@@ -57,6 +69,12 @@ class HederaMirrorNode {
|
|
|
57
69
|
}
|
|
58
70
|
return null;
|
|
59
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Retrieves topic information for a given topic ID from the mirror node.
|
|
74
|
+
* @param topicId The ID of the topic to retrieve information for.
|
|
75
|
+
* @returns A promise that resolves to the topic information.
|
|
76
|
+
* @throws An error if the topic ID is invalid or the information cannot be retrieved.
|
|
77
|
+
*/
|
|
60
78
|
async getTopicInfo(topicId) {
|
|
61
79
|
try {
|
|
62
80
|
const topicInfoUrl = `${this.baseUrl}/api/v1/topics/${topicId}`;
|
|
@@ -67,6 +85,12 @@ class HederaMirrorNode {
|
|
|
67
85
|
throw new Error(`Failed to retrieve topic information: ${error.message}`);
|
|
68
86
|
}
|
|
69
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Retrieves custom fees for a given topic ID from the mirror node.
|
|
90
|
+
* @param topicId The ID of the topic to retrieve custom fees for.
|
|
91
|
+
* @returns A promise that resolves to the custom fees for the given topic.
|
|
92
|
+
* @throws An error if the topic ID is invalid or the custom fees cannot be retrieved.
|
|
93
|
+
*/
|
|
70
94
|
async getTopicFees(topicId) {
|
|
71
95
|
try {
|
|
72
96
|
const topicInfo = await this.getTopicInfo(topicId);
|
|
@@ -76,6 +100,12 @@ class HederaMirrorNode {
|
|
|
76
100
|
return null;
|
|
77
101
|
}
|
|
78
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Retrieves the current HBAR price from the mirror node.
|
|
105
|
+
* @param date The date to retrieve the HBAR price for.
|
|
106
|
+
* @returns A promise that resolves to the HBAR price for the given date.
|
|
107
|
+
* @throws An error if the date is invalid or the price cannot be retrieved.
|
|
108
|
+
*/
|
|
79
109
|
async getHBARPrice(date) {
|
|
80
110
|
try {
|
|
81
111
|
const timestamp = Timestamp.fromDate(date).toString();
|
|
@@ -89,6 +119,36 @@ class HederaMirrorNode {
|
|
|
89
119
|
return null;
|
|
90
120
|
}
|
|
91
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Retrieves token information for a given token ID from the mirror node.
|
|
124
|
+
* @param tokenId The ID of the token to retrieve information for.
|
|
125
|
+
* @returns A promise that resolves to the token information.
|
|
126
|
+
* @throws An error if the token ID is invalid or the information cannot be retrieved.
|
|
127
|
+
*/
|
|
128
|
+
async getTokenInfo(tokenId) {
|
|
129
|
+
this.logger.debug(`Fetching token info for ${tokenId}`);
|
|
130
|
+
try {
|
|
131
|
+
const tokenInfoUrl = `${this.baseUrl}/api/v1/tokens/${tokenId}`;
|
|
132
|
+
const response = await axios.get(tokenInfoUrl);
|
|
133
|
+
if (response.data) {
|
|
134
|
+
this.logger.trace(`Token info found for ${tokenId}:`, response.data);
|
|
135
|
+
return response.data;
|
|
136
|
+
}
|
|
137
|
+
this.logger.warn(`No token info found for ${tokenId}`);
|
|
138
|
+
return null;
|
|
139
|
+
} catch (error) {
|
|
140
|
+
this.logger.error(
|
|
141
|
+
`Error fetching token info for ${tokenId}: ${error.message}`
|
|
142
|
+
);
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Retrieves messages for a given topic ID from the mirror node.
|
|
148
|
+
* @param topicId The ID of the topic to retrieve messages for.
|
|
149
|
+
* @returns A promise that resolves to the messages for the given topic.
|
|
150
|
+
* @throws An error if the topic ID is invalid or the messages cannot be retrieved.
|
|
151
|
+
*/
|
|
92
152
|
async getTopicMessages(topicId) {
|
|
93
153
|
this.logger.trace(`Querying messages for topic ${topicId}`);
|
|
94
154
|
let nextUrl = `${this.baseUrl}/api/v1/topics/${topicId}/messages`;
|
|
@@ -136,9 +196,7 @@ class HederaMirrorNode {
|
|
|
136
196
|
...messageJson,
|
|
137
197
|
consensus_timestamp: message.consensus_timestamp,
|
|
138
198
|
sequence_number: message.sequence_number,
|
|
139
|
-
created: new Date(
|
|
140
|
-
Number(message.consensus_timestamp) * 1e3
|
|
141
|
-
)
|
|
199
|
+
created: new Date(Number(message.consensus_timestamp) * 1e3)
|
|
142
200
|
});
|
|
143
201
|
} catch (error) {
|
|
144
202
|
this.logger.error(`Error processing message: ${error.message}`);
|
|
@@ -153,6 +211,12 @@ class HederaMirrorNode {
|
|
|
153
211
|
}
|
|
154
212
|
return messages;
|
|
155
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* Requests account information for a given account ID from the mirror node.
|
|
216
|
+
* @param accountId The ID of the account to retrieve information for.
|
|
217
|
+
* @returns A promise that resolves to the account information.
|
|
218
|
+
* @throws An error if the account ID is invalid or the information cannot be retrieved.
|
|
219
|
+
*/
|
|
156
220
|
async requestAccount(accountId) {
|
|
157
221
|
try {
|
|
158
222
|
const accountInfoUrl = `${this.baseUrl}/api/v1/accounts/${accountId}`;
|
|
@@ -168,6 +232,12 @@ class HederaMirrorNode {
|
|
|
168
232
|
throw new Error(`Failed to fetch account: ${error.message}`);
|
|
169
233
|
}
|
|
170
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* Checks if a user has access to a given key list.
|
|
237
|
+
* @param keyBytes The key list to check access for.
|
|
238
|
+
* @param userPublicKey The public key of the user to check access for.
|
|
239
|
+
* @returns A promise that resolves to true if the user has access, false otherwise.
|
|
240
|
+
*/
|
|
171
241
|
async checkKeyListAccess(keyBytes, userPublicKey) {
|
|
172
242
|
try {
|
|
173
243
|
const key = proto.Key.decode(keyBytes);
|
|
@@ -179,6 +249,12 @@ class HederaMirrorNode {
|
|
|
179
249
|
return false;
|
|
180
250
|
}
|
|
181
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* Evaluates the access of a given key to a user's public key.
|
|
254
|
+
* @param key The key to evaluate access for.
|
|
255
|
+
* @param userPublicKey The public key of the user to evaluate access for.
|
|
256
|
+
* @returns A promise that resolves to true if the key has access, false otherwise.
|
|
257
|
+
*/
|
|
182
258
|
async evaluateKeyAccess(key, userPublicKey) {
|
|
183
259
|
if (key.ed25519) {
|
|
184
260
|
return this.compareEd25519Key(key.ed25519, userPublicKey);
|
|
@@ -191,6 +267,12 @@ class HederaMirrorNode {
|
|
|
191
267
|
}
|
|
192
268
|
return false;
|
|
193
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* Evaluates the access of a given key list to a user's public key.
|
|
272
|
+
* @param keyList The key list to evaluate access for.
|
|
273
|
+
* @param userPublicKey The public key of the user to evaluate access for.
|
|
274
|
+
* @returns A promise that resolves to true if the key list has access, false otherwise.
|
|
275
|
+
*/
|
|
194
276
|
async evaluateKeyList(keyList, userPublicKey) {
|
|
195
277
|
const keys = keyList.keys || [];
|
|
196
278
|
for (const listKey of keys) {
|
|
@@ -221,6 +303,12 @@ class HederaMirrorNode {
|
|
|
221
303
|
}
|
|
222
304
|
return false;
|
|
223
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* Compares an Ed25519 key with a user's public key.
|
|
308
|
+
* @param keyData The Ed25519 key data to compare.
|
|
309
|
+
* @param userPublicKey The public key of the user to compare with.
|
|
310
|
+
* @returns A boolean indicating whether the key matches the user's public key.
|
|
311
|
+
*/
|
|
224
312
|
compareEd25519Key(keyData, userPublicKey) {
|
|
225
313
|
try {
|
|
226
314
|
const decodedKey = PublicKey.fromBytes(Buffer.from(keyData));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es18.js","sources":["../../src/services/mirror-node.ts"],"sourcesContent":["import { PublicKey, Timestamp } from '@hashgraph/sdk';\nimport axios from 'axios';\nimport { Logger } from '../utils/logger';\nimport { HCSMessage } from '../hcs-10/base-client';\nimport { proto } from '@hashgraph/proto';\nimport {\n AccountResponse,\n CustomFees,\n HBARPrice,\n TopicMessagesResponse,\n TopicResponse,\n} from './types';\nimport { NetworkType } from '../utils/types';\nexport class HederaMirrorNode {\n private network: NetworkType;\n private baseUrl: string;\n private logger: Logger;\n private isServerEnvironment: boolean;\n\n constructor(network: NetworkType, logger: Logger) {\n this.network = network;\n this.baseUrl = this.getMirrorNodeUrl();\n this.logger = logger;\n this.isServerEnvironment = typeof window === 'undefined';\n }\n\n private getMirrorNodeUrl(): string {\n return this.network === 'mainnet'\n ? 'https://mainnet-public.mirrornode.hedera.com'\n : 'https://testnet.mirrornode.hedera.com';\n }\n\n getBaseUrl(): string {\n return this.baseUrl;\n }\n\n async getPublicKey(accountId: string): Promise<PublicKey> {\n this.logger.info(`Getting public key for account ${accountId}`);\n\n const accountInfo = await this.requestAccount(accountId);\n\n try {\n if (!accountInfo || !accountInfo.key) {\n throw new Error(\n `Failed to retrieve public key for account ID: ${accountId}`\n );\n }\n\n return PublicKey.fromString(accountInfo.key.key);\n } catch (error: any) {\n throw new Error(\n `Error fetching public key from Mirror Node: ${error.message}`\n );\n }\n }\n\n async getAccountMemo(accountId: string): Promise<string | null> {\n const maxRetries = 3;\n\n for (let attempt = 0; attempt < maxRetries; attempt++) {\n try {\n const accountInfoUrl = `${this.baseUrl}/api/v1/accounts/${accountId}`;\n\n const response = await axios.get(accountInfoUrl);\n const accountInfo = response.data;\n\n if (accountInfo && accountInfo.memo) {\n return accountInfo.memo;\n }\n\n this.logger.error(`No memo found for account ${accountId}`);\n\n if (attempt < maxRetries - 1) {\n await new Promise((resolve) => setTimeout(resolve, 2000));\n }\n } catch (error: any) {\n this.logger.error(\n `Error getting account memo (attempt ${attempt + 1}): ${\n error.message\n }`\n );\n\n if (attempt < maxRetries - 1) {\n await new Promise((resolve) => setTimeout(resolve, 2000));\n }\n }\n }\n\n return null;\n }\n\n async getTopicInfo(topicId: string): Promise<TopicResponse> {\n try {\n const topicInfoUrl = `${this.baseUrl}/api/v1/topics/${topicId}`;\n const response = await axios.get(topicInfoUrl);\n return response.data;\n } catch (error: any) {\n this.logger.error(`Error retrieving topic information: ${error.message}`);\n throw new Error(`Failed to retrieve topic information: ${error.message}`);\n }\n }\n\n async getTopicFees(topicId: string): Promise<CustomFees | null> {\n try {\n const topicInfo = await this.getTopicInfo(topicId);\n return topicInfo.custom_fees;\n } catch (error: any) {\n this.logger.error(`Error retrieving topic fees: ${error.message}`);\n return null;\n }\n }\n\n async getHBARPrice(date: Date): Promise<number | null> {\n try {\n const timestamp = Timestamp.fromDate(date).toString();\n\n const request = await fetch(\n `https://mainnet-public.mirrornode.hedera.com/api/v1/network/exchangerate?timestamp=${timestamp}`\n );\n const response = (await request.json()) as HBARPrice;\n\n const usdPrice =\n Number(response?.current_rate?.cent_equivalent) /\n Number(response?.current_rate?.hbar_equivalent) /\n 100;\n\n return usdPrice;\n } catch (e) {\n return null;\n }\n }\n\n async getTopicMessages(topicId: string): Promise<HCSMessage[]> {\n this.logger.trace(`Querying messages for topic ${topicId}`);\n\n let nextUrl = `${this.baseUrl}/api/v1/topics/${topicId}/messages`;\n const messages: HCSMessage[] = [];\n\n while (nextUrl) {\n try {\n const response = await axios.get<TopicMessagesResponse>(nextUrl);\n const data = response.data;\n\n if (data.messages && data.messages.length > 0) {\n for (const message of data.messages) {\n try {\n if (!message.message) {\n continue;\n }\n\n let messageContent: string;\n try {\n if (this.isServerEnvironment) {\n messageContent = Buffer.from(\n message.message,\n 'base64'\n ).toString('utf-8');\n } else {\n messageContent = new TextDecoder().decode(\n Uint8Array.from(atob(message.message), (c) =>\n c.charCodeAt(0)\n )\n );\n }\n } catch (error) {\n this.logger.error(`Error decoding message: ${error}`);\n continue;\n }\n\n let messageJson;\n try {\n messageJson = JSON.parse(messageContent);\n } catch (error) {\n this.logger.error(\n `Invalid JSON message content: ${messageContent}`\n );\n return;\n }\n\n messageJson.sequence_number = message.sequence_number;\n messages.push({\n ...messageJson,\n consensus_timestamp: message.consensus_timestamp,\n sequence_number: message.sequence_number,\n created: new Date(\n Number(message.consensus_timestamp) * 1000\n ),\n });\n } catch (error: any) {\n this.logger.error(`Error processing message: ${error.message}`);\n }\n }\n }\n\n nextUrl = data.links?.next ? `${this.baseUrl}${data.links.next}` : '';\n } catch (error: any) {\n this.logger.error(`Error querying topic messages: ${error.message}`);\n throw new Error(`Failed to query topic messages: ${error.message}`);\n }\n }\n\n return messages;\n }\n\n async requestAccount(accountId: string): Promise<AccountResponse> {\n try {\n const accountInfoUrl = `${this.baseUrl}/api/v1/accounts/${accountId}`;\n const response = await axios.get(accountInfoUrl);\n if (!response.data) {\n throw new Error(\n `Failed to make request to mirror node for account: ${accountId}`\n );\n }\n return response.data;\n } catch (error: any) {\n this.logger.error(`Failed to fetch account: ${error.message}`);\n throw new Error(`Failed to fetch account: ${error.message}`);\n }\n }\n\n async checkKeyListAccess(\n keyBytes: Buffer,\n userPublicKey: PublicKey\n ): Promise<boolean> {\n try {\n const key = proto.Key.decode(keyBytes);\n return this.evaluateKeyAccess(key, userPublicKey);\n } catch (error) {\n this.logger.error(\n `Error decoding protobuf key: ${\n error instanceof Error ? error.message : String(error)\n }`\n );\n return false;\n }\n }\n\n private async evaluateKeyAccess(\n key: proto.IKey,\n userPublicKey: PublicKey\n ): Promise<boolean> {\n if (key.ed25519) {\n return this.compareEd25519Key(key.ed25519, userPublicKey);\n }\n\n if (key.keyList) {\n return this.evaluateKeyList(key.keyList, userPublicKey);\n }\n\n if (key.thresholdKey && key.thresholdKey.keys) {\n return this.evaluateKeyList(key.thresholdKey.keys, userPublicKey);\n }\n\n return false;\n }\n\n private async evaluateKeyList(\n keyList: proto.IKeyList,\n userPublicKey: PublicKey\n ): Promise<boolean> {\n const keys = keyList.keys || [];\n\n for (const listKey of keys) {\n if (!listKey) continue;\n\n if (listKey.ed25519) {\n if (this.compareEd25519Key(listKey.ed25519, userPublicKey)) {\n return true;\n }\n } else if (listKey.keyList || listKey.thresholdKey) {\n try {\n const nestedKeyBytes = proto.Key.encode({\n ...(listKey.keyList ? { keyList: listKey.keyList } : {}),\n ...(listKey.thresholdKey\n ? { thresholdKey: listKey.thresholdKey }\n : {}),\n }).finish();\n\n const hasNestedAccess = await this.checkKeyListAccess(\n Buffer.from(nestedKeyBytes),\n userPublicKey\n );\n\n if (hasNestedAccess) {\n return true;\n }\n } catch (err) {\n this.logger.debug(\n `Error in nested key: ${\n err instanceof Error ? err.message : String(err)\n }`\n );\n }\n }\n }\n\n return false;\n }\n\n private compareEd25519Key(\n keyData: Uint8Array,\n userPublicKey: PublicKey\n ): boolean {\n try {\n const decodedKey = PublicKey.fromBytes(Buffer.from(keyData));\n return decodedKey.toString() === userPublicKey.toString();\n } catch (err) {\n return false;\n }\n }\n}\n"],"names":[],"mappings":";;;;;AAaO,MAAM,iBAAiB;AAAA,EAM5B,YAAY,SAAsB,QAAgB;AAChD,SAAK,UAAU;AACV,SAAA,UAAU,KAAK,iBAAiB;AACrC,SAAK,SAAS;AACT,SAAA,sBAAsB,OAAO,WAAW;AAAA,EAAA;AAAA,EAGvC,mBAA2B;AAC1B,WAAA,KAAK,YAAY,YACpB,iDACA;AAAA,EAAA;AAAA,EAGN,aAAqB;AACnB,WAAO,KAAK;AAAA,EAAA;AAAA,EAGd,MAAM,aAAa,WAAuC;AACxD,SAAK,OAAO,KAAK,kCAAkC,SAAS,EAAE;AAE9D,UAAM,cAAc,MAAM,KAAK,eAAe,SAAS;AAEnD,QAAA;AACF,UAAI,CAAC,eAAe,CAAC,YAAY,KAAK;AACpC,cAAM,IAAI;AAAA,UACR,iDAAiD,SAAS;AAAA,QAC5D;AAAA,MAAA;AAGF,aAAO,UAAU,WAAW,YAAY,IAAI,GAAG;AAAA,aACxC,OAAY;AACnB,YAAM,IAAI;AAAA,QACR,+CAA+C,MAAM,OAAO;AAAA,MAC9D;AAAA,IAAA;AAAA,EACF;AAAA,EAGF,MAAM,eAAe,WAA2C;AAC9D,UAAM,aAAa;AAEnB,aAAS,UAAU,GAAG,UAAU,YAAY,WAAW;AACjD,UAAA;AACF,cAAM,iBAAiB,GAAG,KAAK,OAAO,oBAAoB,SAAS;AAEnE,cAAM,WAAW,MAAM,MAAM,IAAI,cAAc;AAC/C,cAAM,cAAc,SAAS;AAEzB,YAAA,eAAe,YAAY,MAAM;AACnC,iBAAO,YAAY;AAAA,QAAA;AAGrB,aAAK,OAAO,MAAM,6BAA6B,SAAS,EAAE;AAEtD,YAAA,UAAU,aAAa,GAAG;AAC5B,gBAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAI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AAC;AAE9B,eAAW,WAAW,MAAM;AAC1B,UAAI,CAAC,QAAS;AAEd,UAAI,QAAQ,SAAS;AACnB,YAAI,KAAK,kBAAkB,QAAQ,SAAS,aAAa,GAAG;AACnD,iBAAA;AAAA,QAAA;AAAA,MAEA,WAAA,QAAQ,WAAW,QAAQ,cAAc;AAC9C,YAAA;AACI,gBAAA,iBAAiB,MAAM,IAAI,OAAO;AAAA,YACtC,GAAI,QAAQ,UAAU,EAAE,SAAS,QAAQ,QAAA,IAAY,CAAC;AAAA,YACtD,GAAI,QAAQ,eACR,EAAE,cAAc,QAAQ,aAAA,IACxB,CAAA;AAAA,UACL,CAAA,EAAE,OAAO;AAEJ,gBAAA,kBAAkB,MAAM,KAAK;AAAA,YACjC,OAAO,KAAK,cAAc;AAAA,YAC1B;AAAA,UACF;AAEA,cAAI,iBAAiB;AACZ,mBAAA;AAAA,UAAA;AAAA,iBAEF,KAAK;AACZ,eAAK,OAAO;AAAA,YACV,wBACE,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,CACjD;AAAA,UACF;AAAA,QAAA;AAAA,MACF;AAAA,IACF;AAGK,WAAA;AAAA,EAAA;AAAA,EAGD,kBACN,SACA,eACS;AACL,QAAA;AACF,YAAM,aAAa,UAAU,UAAU,OAAO,KAAK,OAAO,CAAC;AAC3D,aAAO,WAAW,eAAe,cAAc,SAAS;AAAA,aACjD,KAAK;AACL,aAAA;AAAA,IAAA;AAAA,EACT;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"standards-sdk.es18.js","sources":["../../src/services/mirror-node.ts"],"sourcesContent":["import { PublicKey, Timestamp } from '@hashgraph/sdk';\nimport axios from 'axios';\nimport { Logger } from '../utils/logger';\nimport { HCSMessage } from '../hcs-10/base-client';\nimport { proto } from '@hashgraph/proto';\nimport {\n AccountResponse,\n CustomFees,\n HBARPrice,\n TokenInfoResponse,\n TopicMessagesResponse,\n TopicResponse,\n} from './types';\nimport { NetworkType } from '../utils/types';\nexport class HederaMirrorNode {\n private network: NetworkType;\n private baseUrl: string;\n private logger: Logger;\n private isServerEnvironment: boolean;\n\n constructor(network: NetworkType, logger: Logger) {\n this.network = network;\n this.baseUrl = this.getMirrorNodeUrl();\n this.logger = logger;\n this.isServerEnvironment = typeof window === 'undefined';\n }\n\n private getMirrorNodeUrl(): string {\n return this.network === 'mainnet'\n ? 'https://mainnet-public.mirrornode.hedera.com'\n : 'https://testnet.mirrornode.hedera.com';\n }\n\n getBaseUrl(): string {\n return this.baseUrl;\n }\n\n /**\n * Retrieves the public key for a given account ID from the mirror node.\n * @param accountId The ID of the account to retrieve the public key for.\n * @returns A promise that resolves to the public key for the given account.\n * @throws An error if the account ID is invalid or the public key cannot be retrieved.\n */\n async getPublicKey(accountId: string): Promise<PublicKey> {\n this.logger.info(`Getting public key for account ${accountId}`);\n\n const accountInfo = await this.requestAccount(accountId);\n\n try {\n if (!accountInfo || !accountInfo.key) {\n throw new Error(\n `Failed to retrieve public key for account ID: ${accountId}`\n );\n }\n\n return PublicKey.fromString(accountInfo.key.key);\n } catch (error: any) {\n throw new Error(\n `Error fetching public key from Mirror Node: ${error.message}`\n );\n }\n }\n\n /**\n * Retrieves the memo for a given account ID from the mirror node.\n * @param accountId The ID of the account to retrieve the memo for.\n * @returns A promise that resolves to the memo for the given account.\n * @throws An error if the account ID is invalid or the memo cannot be retrieved.\n */\n async getAccountMemo(accountId: string): Promise<string | null> {\n const maxRetries = 3;\n\n for (let attempt = 0; attempt < maxRetries; attempt++) {\n try {\n const accountInfoUrl = `${this.baseUrl}/api/v1/accounts/${accountId}`;\n\n const response = await axios.get(accountInfoUrl);\n const accountInfo = response.data;\n\n if (accountInfo && accountInfo.memo) {\n return accountInfo.memo;\n }\n\n this.logger.error(`No memo found for account ${accountId}`);\n\n if (attempt < maxRetries - 1) {\n await new Promise((resolve) => setTimeout(resolve, 2000));\n }\n } catch (error: any) {\n this.logger.error(\n `Error getting account memo (attempt ${attempt + 1}): ${\n error.message\n }`\n );\n\n if (attempt < maxRetries - 1) {\n await new Promise((resolve) => setTimeout(resolve, 2000));\n }\n }\n }\n\n return null;\n }\n\n /**\n * Retrieves topic information for a given topic ID from the mirror node.\n * @param topicId The ID of the topic to retrieve information for.\n * @returns A promise that resolves to the topic information.\n * @throws An error if the topic ID is invalid or the information cannot be retrieved.\n */\n async getTopicInfo(topicId: string): Promise<TopicResponse> {\n try {\n const topicInfoUrl = `${this.baseUrl}/api/v1/topics/${topicId}`;\n const response = await axios.get(topicInfoUrl);\n return response.data;\n } catch (error: any) {\n this.logger.error(`Error retrieving topic information: ${error.message}`);\n throw new Error(`Failed to retrieve topic information: ${error.message}`);\n }\n }\n\n /**\n * Retrieves custom fees for a given topic ID from the mirror node.\n * @param topicId The ID of the topic to retrieve custom fees for.\n * @returns A promise that resolves to the custom fees for the given topic.\n * @throws An error if the topic ID is invalid or the custom fees cannot be retrieved.\n */\n async getTopicFees(topicId: string): Promise<CustomFees | null> {\n try {\n const topicInfo = await this.getTopicInfo(topicId);\n return topicInfo.custom_fees;\n } catch (error: any) {\n this.logger.error(`Error retrieving topic fees: ${error.message}`);\n return null;\n }\n }\n\n /**\n * Retrieves the current HBAR price from the mirror node.\n * @param date The date to retrieve the HBAR price for.\n * @returns A promise that resolves to the HBAR price for the given date.\n * @throws An error if the date is invalid or the price cannot be retrieved.\n */\n async getHBARPrice(date: Date): Promise<number | null> {\n try {\n const timestamp = Timestamp.fromDate(date).toString();\n\n const request = await fetch(\n `https://mainnet-public.mirrornode.hedera.com/api/v1/network/exchangerate?timestamp=${timestamp}`\n );\n const response = (await request.json()) as HBARPrice;\n\n const usdPrice =\n Number(response?.current_rate?.cent_equivalent) /\n Number(response?.current_rate?.hbar_equivalent) /\n 100;\n\n return usdPrice;\n } catch (e) {\n return null;\n }\n }\n\n /**\n * Retrieves token information for a given token ID from the mirror node.\n * @param tokenId The ID of the token to retrieve information for.\n * @returns A promise that resolves to the token information.\n * @throws An error if the token ID is invalid or the information cannot be retrieved.\n */\n async getTokenInfo(tokenId: string): Promise<TokenInfoResponse | null> {\n this.logger.debug(`Fetching token info for ${tokenId}`);\n try {\n const tokenInfoUrl = `${this.baseUrl}/api/v1/tokens/${tokenId}`;\n const response = await axios.get<TokenInfoResponse>(tokenInfoUrl);\n if (response.data) {\n this.logger.trace(`Token info found for ${tokenId}:`, response.data);\n return response.data;\n }\n this.logger.warn(`No token info found for ${tokenId}`);\n return null;\n } catch (error: any) {\n this.logger.error(\n `Error fetching token info for ${tokenId}: ${error.message}`\n );\n\n return null;\n }\n }\n\n /**\n * Retrieves messages for a given topic ID from the mirror node.\n * @param topicId The ID of the topic to retrieve messages for.\n * @returns A promise that resolves to the messages for the given topic.\n * @throws An error if the topic ID is invalid or the messages cannot be retrieved.\n */\n async getTopicMessages(topicId: string): Promise<HCSMessage[]> {\n this.logger.trace(`Querying messages for topic ${topicId}`);\n\n let nextUrl = `${this.baseUrl}/api/v1/topics/${topicId}/messages`;\n const messages: HCSMessage[] = [];\n\n while (nextUrl) {\n try {\n const response = await axios.get<TopicMessagesResponse>(nextUrl);\n const data = response.data;\n\n if (data.messages && data.messages.length > 0) {\n for (const message of data.messages) {\n try {\n if (!message.message) {\n continue;\n }\n\n let messageContent: string;\n try {\n if (this.isServerEnvironment) {\n messageContent = Buffer.from(\n message.message,\n 'base64'\n ).toString('utf-8');\n } else {\n messageContent = new TextDecoder().decode(\n Uint8Array.from(atob(message.message), (c) =>\n c.charCodeAt(0)\n )\n );\n }\n } catch (error) {\n this.logger.error(`Error decoding message: ${error}`);\n continue;\n }\n\n let messageJson;\n try {\n messageJson = JSON.parse(messageContent);\n } catch (error) {\n this.logger.error(\n `Invalid JSON message content: ${messageContent}`\n );\n return;\n }\n\n messageJson.sequence_number = message.sequence_number;\n messages.push({\n ...messageJson,\n consensus_timestamp: message.consensus_timestamp,\n sequence_number: message.sequence_number,\n created: new Date(Number(message.consensus_timestamp) * 1000),\n });\n } catch (error: any) {\n this.logger.error(`Error processing message: ${error.message}`);\n }\n }\n }\n\n nextUrl = data.links?.next ? `${this.baseUrl}${data.links.next}` : '';\n } catch (error: any) {\n this.logger.error(`Error querying topic messages: ${error.message}`);\n throw new Error(`Failed to query topic messages: ${error.message}`);\n }\n }\n\n return messages;\n }\n\n /**\n * Requests account information for a given account ID from the mirror node.\n * @param accountId The ID of the account to retrieve information for.\n * @returns A promise that resolves to the account information.\n * @throws An error if the account ID is invalid or the information cannot be retrieved.\n */\n async requestAccount(accountId: string): Promise<AccountResponse> {\n try {\n const accountInfoUrl = `${this.baseUrl}/api/v1/accounts/${accountId}`;\n const response = await axios.get(accountInfoUrl);\n if (!response.data) {\n throw new Error(\n `Failed to make request to mirror node for account: ${accountId}`\n );\n }\n return response.data;\n } catch (error: any) {\n this.logger.error(`Failed to fetch account: ${error.message}`);\n throw new Error(`Failed to fetch account: ${error.message}`);\n }\n }\n\n /**\n * Checks if a user has access to a given key list.\n * @param keyBytes The key list to check access for.\n * @param userPublicKey The public key of the user to check access for.\n * @returns A promise that resolves to true if the user has access, false otherwise.\n */\n async checkKeyListAccess(\n keyBytes: Buffer,\n userPublicKey: PublicKey\n ): Promise<boolean> {\n try {\n const key = proto.Key.decode(keyBytes);\n return this.evaluateKeyAccess(key, userPublicKey);\n } catch (error) {\n this.logger.error(\n `Error decoding protobuf key: ${\n error instanceof Error ? error.message : String(error)\n }`\n );\n return false;\n }\n }\n\n /**\n * Evaluates the access of a given key to a user's public key.\n * @param key The key to evaluate access for.\n * @param userPublicKey The public key of the user to evaluate access for.\n * @returns A promise that resolves to true if the key has access, false otherwise.\n */\n private async evaluateKeyAccess(\n key: proto.IKey,\n userPublicKey: PublicKey\n ): Promise<boolean> {\n if (key.ed25519) {\n return this.compareEd25519Key(key.ed25519, userPublicKey);\n }\n\n if (key.keyList) {\n return this.evaluateKeyList(key.keyList, userPublicKey);\n }\n\n if (key.thresholdKey && key.thresholdKey.keys) {\n return this.evaluateKeyList(key.thresholdKey.keys, userPublicKey);\n }\n\n return false;\n }\n\n /**\n * Evaluates the access of a given key list to a user's public key.\n * @param keyList The key list to evaluate access for.\n * @param userPublicKey The public key of the user to evaluate access for.\n * @returns A promise that resolves to true if the key list has access, false otherwise.\n */\n private async evaluateKeyList(\n keyList: proto.IKeyList,\n userPublicKey: PublicKey\n ): Promise<boolean> {\n const keys = keyList.keys || [];\n\n for (const listKey of keys) {\n if (!listKey) continue;\n\n if (listKey.ed25519) {\n if (this.compareEd25519Key(listKey.ed25519, userPublicKey)) {\n return true;\n }\n } else if (listKey.keyList || listKey.thresholdKey) {\n try {\n const nestedKeyBytes = proto.Key.encode({\n ...(listKey.keyList ? { keyList: listKey.keyList } : {}),\n ...(listKey.thresholdKey\n ? { thresholdKey: listKey.thresholdKey }\n : {}),\n }).finish();\n\n const hasNestedAccess = await this.checkKeyListAccess(\n Buffer.from(nestedKeyBytes),\n userPublicKey\n );\n\n if (hasNestedAccess) {\n return true;\n }\n } catch (err) {\n this.logger.debug(\n `Error in nested key: ${\n err instanceof Error ? err.message : String(err)\n }`\n );\n }\n }\n }\n\n return false;\n }\n\n /**\n * Compares an Ed25519 key with a user's public key.\n * @param keyData The Ed25519 key data to compare.\n * @param userPublicKey The public key of the user to compare with.\n * @returns A boolean indicating whether the key matches the user's public key.\n */\n private compareEd25519Key(\n keyData: Uint8Array,\n userPublicKey: PublicKey\n ): boolean {\n try {\n const decodedKey = PublicKey.fromBytes(Buffer.from(keyData));\n return decodedKey.toString() === userPublicKey.toString();\n } catch (err) {\n return false;\n }\n }\n}\n"],"names":[],"mappings":";;;;;AAcO,MAAM,iBAAiB;AAAA,EAM5B,YAAY,SAAsB,QAAgB;AAChD,SAAK,UAAU;AACV,SAAA,UAAU,KAAK,iBAAiB;AACrC,SAAK,SAAS;AACT,SAAA,sBAAsB,OAAO,WAAW;AAAA,EAAA;AAAA,EAGvC,mBAA2B;AAC1B,WAAA,KAAK,YAAY,YACpB,iDACA;AAAA,EAAA;AAAA,EAGN,aAAqB;AACnB,WAAO,KAAK;AAAA,EAAA;AAAA;AAAA;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AAU,OAAO,KAAK,OAAO,CAAC;AAC3D,aAAO,WAAW,eAAe,cAAc,SAAS;AAAA,aACjD,KAAK;AACL,aAAA;AAAA,IAAA;AAAA,EACT;AAEJ;"}
|
|
@@ -1,94 +1,154 @@
|
|
|
1
|
+
import { CustomFeeType } from "./standards-sdk.es20.js";
|
|
2
|
+
import { HederaMirrorNode } from "./standards-sdk.es18.js";
|
|
1
3
|
class FeeConfigBuilder {
|
|
2
|
-
constructor() {
|
|
3
|
-
this.
|
|
4
|
-
this.
|
|
5
|
-
this.
|
|
6
|
-
this.
|
|
4
|
+
constructor(options) {
|
|
5
|
+
this.customFees = [];
|
|
6
|
+
this.logger = options.logger;
|
|
7
|
+
this.mirrorNode = new HederaMirrorNode(options.network, options.logger);
|
|
8
|
+
this.defaultCollectorAccountId = options.defaultCollectorAccountId || "";
|
|
7
9
|
}
|
|
8
10
|
/**
|
|
9
|
-
* Static factory method to create a
|
|
10
|
-
* @param hbarAmount Amount in HBAR
|
|
11
|
-
* @param collectorAccountId
|
|
12
|
-
* @param
|
|
13
|
-
* @
|
|
11
|
+
* Static factory method to create a FeeConfigBuilder with a single HBAR fee.
|
|
12
|
+
* @param hbarAmount Amount in HBAR.
|
|
13
|
+
* @param collectorAccountId Optional account ID to collect the fee. If omitted or undefined, defaults to the agent's own account ID during topic creation.
|
|
14
|
+
* @param network Network type ('mainnet' or 'testnet').
|
|
15
|
+
* @param logger Logger instance.
|
|
16
|
+
* @param exemptAccounts Optional array of account IDs exempt from this fee.
|
|
17
|
+
* @returns A configured FeeConfigBuilder instance.
|
|
14
18
|
*/
|
|
15
|
-
static forHbar(hbarAmount, collectorAccountId, exemptAccounts = []) {
|
|
16
|
-
|
|
19
|
+
static forHbar(hbarAmount, collectorAccountId, network, logger, exemptAccounts = []) {
|
|
20
|
+
const builder = new FeeConfigBuilder({
|
|
21
|
+
network,
|
|
22
|
+
logger,
|
|
23
|
+
defaultCollectorAccountId: collectorAccountId
|
|
24
|
+
});
|
|
25
|
+
return builder.addHbarFee(hbarAmount, collectorAccountId, exemptAccounts);
|
|
17
26
|
}
|
|
18
27
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @
|
|
28
|
+
* Static factory method to create a FeeConfigBuilder with a single token fee.
|
|
29
|
+
* Automatically fetches token decimals if not provided.
|
|
30
|
+
* @param tokenAmount Amount of tokens.
|
|
31
|
+
* @param feeTokenId Token ID for the fee.
|
|
32
|
+
* @param collectorAccountId Optional account ID to collect the fee. If omitted or undefined, defaults to the agent's own account ID during topic creation.
|
|
33
|
+
* @param network Network type ('mainnet' or 'testnet').
|
|
34
|
+
* @param logger Logger instance.
|
|
35
|
+
* @param exemptAccounts Optional array of account IDs exempt from this fee.
|
|
36
|
+
* @param decimals Optional decimals for the token (fetched if omitted).
|
|
37
|
+
* @returns A Promise resolving to a configured FeeConfigBuilder instance.
|
|
22
38
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
setFeeAmount(amount, decimals = 0) {
|
|
38
|
-
this.feeAmount = amount;
|
|
39
|
-
this.decimals = decimals;
|
|
40
|
-
return this;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Sets the Hedera account ID that will collect the fees
|
|
44
|
-
* @param accountId The fee collector's account ID (e.g., '0.0.12345')
|
|
45
|
-
* @returns This builder instance for method chaining
|
|
46
|
-
*/
|
|
47
|
-
setFeeCollector(accountId) {
|
|
48
|
-
this.feeCollectorAccountId = accountId;
|
|
49
|
-
return this;
|
|
39
|
+
static async forToken(tokenAmount, feeTokenId, collectorAccountId, network, logger, exemptAccounts = [], decimals) {
|
|
40
|
+
const builder = new FeeConfigBuilder({
|
|
41
|
+
network,
|
|
42
|
+
logger,
|
|
43
|
+
defaultCollectorAccountId: collectorAccountId
|
|
44
|
+
});
|
|
45
|
+
await builder.addTokenFee(
|
|
46
|
+
tokenAmount,
|
|
47
|
+
feeTokenId,
|
|
48
|
+
collectorAccountId,
|
|
49
|
+
decimals,
|
|
50
|
+
exemptAccounts
|
|
51
|
+
);
|
|
52
|
+
return builder;
|
|
50
53
|
}
|
|
51
54
|
/**
|
|
52
|
-
* Adds an
|
|
53
|
-
*
|
|
54
|
-
* @
|
|
55
|
+
* Adds an HBAR fee configuration to the builder.
|
|
56
|
+
* Allows chaining multiple fee additions.
|
|
57
|
+
* @param hbarAmount The amount in HBAR (e.g., 0.5).
|
|
58
|
+
* @param collectorAccountId Optional. The account ID to collect this fee. If omitted, defaults to the agent's own account ID during topic creation.
|
|
59
|
+
* @param exemptAccountIds Optional. Accounts specifically exempt from *this* HBAR fee.
|
|
60
|
+
* @returns This FeeConfigBuilder instance for chaining.
|
|
55
61
|
*/
|
|
56
|
-
|
|
57
|
-
if (
|
|
58
|
-
|
|
62
|
+
addHbarFee(hbarAmount, collectorAccountId, exemptAccountIds = []) {
|
|
63
|
+
if (hbarAmount <= 0) {
|
|
64
|
+
throw new Error("HBAR amount must be greater than zero");
|
|
59
65
|
}
|
|
66
|
+
this.customFees.push({
|
|
67
|
+
feeAmount: {
|
|
68
|
+
amount: hbarAmount * 1e8,
|
|
69
|
+
decimals: 0
|
|
70
|
+
},
|
|
71
|
+
feeCollectorAccountId: collectorAccountId || "",
|
|
72
|
+
feeTokenId: void 0,
|
|
73
|
+
exemptAccounts: [...exemptAccountIds],
|
|
74
|
+
type: CustomFeeType.FIXED_FEE
|
|
75
|
+
});
|
|
60
76
|
return this;
|
|
61
77
|
}
|
|
62
78
|
/**
|
|
63
|
-
* Adds
|
|
64
|
-
*
|
|
65
|
-
*
|
|
79
|
+
* Adds a token fee configuration to the builder.
|
|
80
|
+
* Allows chaining multiple fee additions.
|
|
81
|
+
* Fetches token decimals automatically if not provided.
|
|
82
|
+
* @param tokenAmount The amount of the specified token.
|
|
83
|
+
* @param feeTokenId The ID of the token to charge the fee in.
|
|
84
|
+
* @param collectorAccountId Optional. The account ID to collect this fee. If omitted, defaults to the agent's own account ID during topic creation.
|
|
85
|
+
* @param decimals Optional. The number of decimals for the token. If omitted, it will be fetched from the mirror node.
|
|
86
|
+
* @param exemptAccountIds Optional. Accounts specifically exempt from *this* token fee.
|
|
87
|
+
* @returns A Promise resolving to this FeeConfigBuilder instance for chaining.
|
|
66
88
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
89
|
+
async addTokenFee(tokenAmount, feeTokenId, collectorAccountId, decimals, exemptAccountIds = []) {
|
|
90
|
+
if (tokenAmount <= 0) {
|
|
91
|
+
throw new Error("Token amount must be greater than zero");
|
|
92
|
+
}
|
|
93
|
+
if (!feeTokenId) {
|
|
94
|
+
throw new Error("Fee token ID is required when adding a token fee");
|
|
70
95
|
}
|
|
96
|
+
let finalDecimals = decimals;
|
|
97
|
+
if (finalDecimals === void 0) {
|
|
98
|
+
try {
|
|
99
|
+
const tokenInfo = await this.mirrorNode.getTokenInfo(feeTokenId);
|
|
100
|
+
if (tokenInfo?.decimals) {
|
|
101
|
+
finalDecimals = parseInt(tokenInfo.decimals, 10);
|
|
102
|
+
this.logger.info(
|
|
103
|
+
`Fetched decimals for ${feeTokenId}: ${finalDecimals}`
|
|
104
|
+
);
|
|
105
|
+
} else {
|
|
106
|
+
this.logger.warn(
|
|
107
|
+
`Could not fetch decimals for ${feeTokenId}, defaulting to 0.`
|
|
108
|
+
);
|
|
109
|
+
finalDecimals = 0;
|
|
110
|
+
}
|
|
111
|
+
} catch (error) {
|
|
112
|
+
this.logger.error(
|
|
113
|
+
`Error fetching decimals for ${feeTokenId}, defaulting to 0: ${error}`
|
|
114
|
+
);
|
|
115
|
+
finalDecimals = 0;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
this.customFees.push({
|
|
119
|
+
feeAmount: {
|
|
120
|
+
amount: tokenAmount * 10 ** finalDecimals,
|
|
121
|
+
decimals: finalDecimals
|
|
122
|
+
},
|
|
123
|
+
feeCollectorAccountId: collectorAccountId || "",
|
|
124
|
+
feeTokenId,
|
|
125
|
+
exemptAccounts: [...exemptAccountIds],
|
|
126
|
+
type: CustomFeeType.FIXED_FEE
|
|
127
|
+
});
|
|
71
128
|
return this;
|
|
72
129
|
}
|
|
73
130
|
/**
|
|
74
|
-
* Builds
|
|
75
|
-
* @
|
|
76
|
-
* @
|
|
131
|
+
* Builds the final TopicFeeConfig object.
|
|
132
|
+
* @returns The TopicFeeConfig containing all added custom fees and a consolidated list of unique exempt accounts.
|
|
133
|
+
* @throws Error if no fees have been added.
|
|
134
|
+
* @throws Error if more than 10 fees have been added.
|
|
77
135
|
*/
|
|
78
136
|
build() {
|
|
79
|
-
if (
|
|
80
|
-
throw new Error(
|
|
137
|
+
if (this.customFees.length === 0) {
|
|
138
|
+
throw new Error(
|
|
139
|
+
"At least one fee must be added using addHbarFee/addTokenFee or created using forHbar/forToken"
|
|
140
|
+
);
|
|
81
141
|
}
|
|
82
|
-
if (this.
|
|
83
|
-
throw new Error("
|
|
142
|
+
if (this.customFees.length > 10) {
|
|
143
|
+
throw new Error("Maximum of 10 custom fees per topic allowed");
|
|
84
144
|
}
|
|
145
|
+
const allExemptAccounts = /* @__PURE__ */ new Set();
|
|
146
|
+
this.customFees.forEach((fee) => {
|
|
147
|
+
fee.exemptAccounts.forEach((account) => allExemptAccounts.add(account));
|
|
148
|
+
});
|
|
85
149
|
return {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
decimals: this.decimals
|
|
89
|
-
},
|
|
90
|
-
feeCollectorAccountId: this.feeCollectorAccountId,
|
|
91
|
-
exemptAccounts: this.exemptAccountIds
|
|
150
|
+
customFees: this.customFees,
|
|
151
|
+
exemptAccounts: Array.from(allExemptAccounts)
|
|
92
152
|
};
|
|
93
153
|
}
|
|
94
154
|
}
|