@hashgraphonline/standards-sdk 0.1.168 → 0.1.170

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.
Files changed (276) hide show
  1. package/README.md +1 -0
  2. package/dist/browser/hcs-11/client.d.ts.map +1 -1
  3. package/dist/browser/hcs-21/sdk.d.ts.map +1 -1
  4. package/dist/browser/hcs-27/base-client.d.ts +41 -0
  5. package/dist/browser/hcs-27/base-client.d.ts.map +1 -0
  6. package/dist/browser/hcs-27/index.d.ts +6 -0
  7. package/dist/browser/hcs-27/index.d.ts.map +1 -0
  8. package/dist/browser/hcs-27/memos.d.ts +5 -0
  9. package/dist/browser/hcs-27/memos.d.ts.map +1 -0
  10. package/dist/browser/hcs-27/merkle.d.ts +23 -0
  11. package/dist/browser/hcs-27/merkle.d.ts.map +1 -0
  12. package/dist/browser/hcs-27/sdk.d.ts +23 -0
  13. package/dist/browser/hcs-27/sdk.d.ts.map +1 -0
  14. package/dist/browser/hcs-27/types.d.ts +1611 -0
  15. package/dist/browser/hcs-27/types.d.ts.map +1 -0
  16. package/dist/browser/index.d.ts +1 -0
  17. package/dist/browser/index.d.ts.map +1 -1
  18. package/dist/browser/standards-sdk.browser.js +29 -5
  19. package/dist/browser/standards-sdk.browser.js.map +1 -1
  20. package/dist/browser/utils/key-type-detector.d.ts.map +1 -1
  21. package/dist/cjs/hcs-11/client.d.ts.map +1 -1
  22. package/dist/cjs/hcs-21/sdk.d.ts.map +1 -1
  23. package/dist/cjs/hcs-27/base-client.d.ts +41 -0
  24. package/dist/cjs/hcs-27/base-client.d.ts.map +1 -0
  25. package/dist/cjs/hcs-27/index.d.ts +6 -0
  26. package/dist/cjs/hcs-27/index.d.ts.map +1 -0
  27. package/dist/cjs/hcs-27/memos.d.ts +5 -0
  28. package/dist/cjs/hcs-27/memos.d.ts.map +1 -0
  29. package/dist/cjs/hcs-27/merkle.d.ts +23 -0
  30. package/dist/cjs/hcs-27/merkle.d.ts.map +1 -0
  31. package/dist/cjs/hcs-27/sdk.d.ts +23 -0
  32. package/dist/cjs/hcs-27/sdk.d.ts.map +1 -0
  33. package/dist/cjs/hcs-27/types.d.ts +1611 -0
  34. package/dist/cjs/hcs-27/types.d.ts.map +1 -0
  35. package/dist/cjs/index.d.ts +1 -0
  36. package/dist/cjs/index.d.ts.map +1 -1
  37. package/dist/cjs/standards-sdk.cjs +2 -2
  38. package/dist/cjs/standards-sdk.cjs.map +1 -1
  39. package/dist/cjs/utils/key-type-detector.d.ts.map +1 -1
  40. package/dist/es/hcs-11/client.d.ts.map +1 -1
  41. package/dist/es/hcs-21/sdk.d.ts.map +1 -1
  42. package/dist/es/hcs-27/base-client.d.ts +41 -0
  43. package/dist/es/hcs-27/base-client.d.ts.map +1 -0
  44. package/dist/es/hcs-27/index.d.ts +6 -0
  45. package/dist/es/hcs-27/index.d.ts.map +1 -0
  46. package/dist/es/hcs-27/memos.d.ts +5 -0
  47. package/dist/es/hcs-27/memos.d.ts.map +1 -0
  48. package/dist/es/hcs-27/merkle.d.ts +23 -0
  49. package/dist/es/hcs-27/merkle.d.ts.map +1 -0
  50. package/dist/es/hcs-27/sdk.d.ts +23 -0
  51. package/dist/es/hcs-27/sdk.d.ts.map +1 -0
  52. package/dist/es/hcs-27/types.d.ts +1611 -0
  53. package/dist/es/hcs-27/types.d.ts.map +1 -0
  54. package/dist/es/index.d.ts +1 -0
  55. package/dist/es/index.d.ts.map +1 -1
  56. package/dist/es/standards-sdk.es.js +67 -38
  57. package/dist/es/standards-sdk.es.js.map +1 -1
  58. package/dist/es/standards-sdk.es101.js +2 -2
  59. package/dist/es/standards-sdk.es103.js +2 -2
  60. package/dist/es/standards-sdk.es104.js +1 -1
  61. package/dist/es/standards-sdk.es106.js +1 -1
  62. package/dist/es/standards-sdk.es108.js +2 -2
  63. package/dist/es/standards-sdk.es11.js +1 -1
  64. package/dist/es/standards-sdk.es110.js +1 -1
  65. package/dist/es/standards-sdk.es111.js +2 -2
  66. package/dist/es/standards-sdk.es112.js +151 -234
  67. package/dist/es/standards-sdk.es112.js.map +1 -1
  68. package/dist/es/standards-sdk.es113.js +20 -471
  69. package/dist/es/standards-sdk.es113.js.map +1 -1
  70. package/dist/es/standards-sdk.es114.js +263 -104
  71. package/dist/es/standards-sdk.es114.js.map +1 -1
  72. package/dist/es/standards-sdk.es115.js +167 -138
  73. package/dist/es/standards-sdk.es115.js.map +1 -1
  74. package/dist/es/standards-sdk.es116.js +315 -29
  75. package/dist/es/standards-sdk.es116.js.map +1 -1
  76. package/dist/es/standards-sdk.es117.js +250 -10
  77. package/dist/es/standards-sdk.es117.js.map +1 -1
  78. package/dist/es/standards-sdk.es118.js +448 -152
  79. package/dist/es/standards-sdk.es118.js.map +1 -1
  80. package/dist/es/standards-sdk.es119.js +101 -25
  81. package/dist/es/standards-sdk.es119.js.map +1 -1
  82. package/dist/es/standards-sdk.es12.js +1 -1
  83. package/dist/es/standards-sdk.es120.js +155 -17
  84. package/dist/es/standards-sdk.es120.js.map +1 -1
  85. package/dist/es/standards-sdk.es121.js +29 -155
  86. package/dist/es/standards-sdk.es121.js.map +1 -1
  87. package/dist/es/standards-sdk.es122.js +9 -200
  88. package/dist/es/standards-sdk.es122.js.map +1 -1
  89. package/dist/es/standards-sdk.es123.js +146 -754
  90. package/dist/es/standards-sdk.es123.js.map +1 -1
  91. package/dist/es/standards-sdk.es124.js +27 -11
  92. package/dist/es/standards-sdk.es124.js.map +1 -1
  93. package/dist/es/standards-sdk.es125.js +19 -564
  94. package/dist/es/standards-sdk.es125.js.map +1 -1
  95. package/dist/es/standards-sdk.es126.js +140 -582
  96. package/dist/es/standards-sdk.es126.js.map +1 -1
  97. package/dist/es/standards-sdk.es127.js +202 -12
  98. package/dist/es/standards-sdk.es127.js.map +1 -1
  99. package/dist/es/standards-sdk.es128.js +790 -2
  100. package/dist/es/standards-sdk.es128.js.map +1 -1
  101. package/dist/es/standards-sdk.es129.js +10 -84
  102. package/dist/es/standards-sdk.es129.js.map +1 -1
  103. package/dist/es/standards-sdk.es13.js +1 -1
  104. package/dist/es/standards-sdk.es130.js +567 -40
  105. package/dist/es/standards-sdk.es130.js.map +1 -1
  106. package/dist/es/standards-sdk.es131.js +626 -2
  107. package/dist/es/standards-sdk.es131.js.map +1 -1
  108. package/dist/es/standards-sdk.es132.js +12 -234
  109. package/dist/es/standards-sdk.es132.js.map +1 -1
  110. package/dist/es/standards-sdk.es133.js +2 -1140
  111. package/dist/es/standards-sdk.es133.js.map +1 -1
  112. package/dist/es/standards-sdk.es134.js +73 -292
  113. package/dist/es/standards-sdk.es134.js.map +1 -1
  114. package/dist/es/standards-sdk.es135.js +36 -418
  115. package/dist/es/standards-sdk.es135.js.map +1 -1
  116. package/dist/es/standards-sdk.es136.js +2 -355
  117. package/dist/es/standards-sdk.es136.js.map +1 -1
  118. package/dist/es/standards-sdk.es137.js +198 -1079
  119. package/dist/es/standards-sdk.es137.js.map +1 -1
  120. package/dist/es/standards-sdk.es138.js +1107 -175
  121. package/dist/es/standards-sdk.es138.js.map +1 -1
  122. package/dist/es/standards-sdk.es139.js +218 -1479
  123. package/dist/es/standards-sdk.es139.js.map +1 -1
  124. package/dist/es/standards-sdk.es14.js +1 -1
  125. package/dist/es/standards-sdk.es140.js +422 -1500
  126. package/dist/es/standards-sdk.es140.js.map +1 -1
  127. package/dist/es/standards-sdk.es141.js +351 -13
  128. package/dist/es/standards-sdk.es141.js.map +1 -1
  129. package/dist/es/standards-sdk.es142.js +1102 -73
  130. package/dist/es/standards-sdk.es142.js.map +1 -1
  131. package/dist/es/standards-sdk.es143.js +203 -76
  132. package/dist/es/standards-sdk.es143.js.map +1 -1
  133. package/dist/es/standards-sdk.es144.js +1459 -830
  134. package/dist/es/standards-sdk.es144.js.map +1 -1
  135. package/dist/es/standards-sdk.es145.js +1499 -59
  136. package/dist/es/standards-sdk.es145.js.map +1 -1
  137. package/dist/es/standards-sdk.es146.js +14 -156
  138. package/dist/es/standards-sdk.es146.js.map +1 -1
  139. package/dist/es/standards-sdk.es147.js +87 -7
  140. package/dist/es/standards-sdk.es147.js.map +1 -1
  141. package/dist/es/standards-sdk.es148.js +74 -79
  142. package/dist/es/standards-sdk.es148.js.map +1 -1
  143. package/dist/es/standards-sdk.es149.js +934 -61
  144. package/dist/es/standards-sdk.es149.js.map +1 -1
  145. package/dist/es/standards-sdk.es15.js +1 -1
  146. package/dist/es/standards-sdk.es150.js +60 -30
  147. package/dist/es/standards-sdk.es150.js.map +1 -1
  148. package/dist/es/standards-sdk.es151.js +159 -34
  149. package/dist/es/standards-sdk.es151.js.map +1 -1
  150. package/dist/es/standards-sdk.es152.js +7 -48
  151. package/dist/es/standards-sdk.es152.js.map +1 -1
  152. package/dist/es/standards-sdk.es153.js +70 -122
  153. package/dist/es/standards-sdk.es153.js.map +1 -1
  154. package/dist/es/standards-sdk.es154.js +58 -35
  155. package/dist/es/standards-sdk.es154.js.map +1 -1
  156. package/dist/es/standards-sdk.es155.js +30 -56
  157. package/dist/es/standards-sdk.es155.js.map +1 -1
  158. package/dist/es/standards-sdk.es156.js +34 -84
  159. package/dist/es/standards-sdk.es156.js.map +1 -1
  160. package/dist/es/standards-sdk.es157.js +48 -81
  161. package/dist/es/standards-sdk.es157.js.map +1 -1
  162. package/dist/es/standards-sdk.es158.js +124 -186
  163. package/dist/es/standards-sdk.es158.js.map +1 -1
  164. package/dist/es/standards-sdk.es159.js +34 -12474
  165. package/dist/es/standards-sdk.es159.js.map +1 -1
  166. package/dist/es/standards-sdk.es16.js +5 -5
  167. package/dist/es/standards-sdk.es160.js +12477 -12
  168. package/dist/es/standards-sdk.es160.js.map +1 -1
  169. package/dist/es/standards-sdk.es161.js +51 -68
  170. package/dist/es/standards-sdk.es161.js.map +1 -1
  171. package/dist/es/standards-sdk.es162.js +67 -533
  172. package/dist/es/standards-sdk.es162.js.map +1 -1
  173. package/dist/es/standards-sdk.es163.js +70 -161
  174. package/dist/es/standards-sdk.es163.js.map +1 -1
  175. package/dist/es/standards-sdk.es164.js +187 -309
  176. package/dist/es/standards-sdk.es164.js.map +1 -1
  177. package/dist/es/standards-sdk.es165.js +13 -342
  178. package/dist/es/standards-sdk.es165.js.map +1 -1
  179. package/dist/es/standards-sdk.es166.js +538 -441
  180. package/dist/es/standards-sdk.es166.js.map +1 -1
  181. package/dist/es/standards-sdk.es167.js +142 -301
  182. package/dist/es/standards-sdk.es167.js.map +1 -1
  183. package/dist/es/standards-sdk.es168.js +310 -64
  184. package/dist/es/standards-sdk.es168.js.map +1 -1
  185. package/dist/es/standards-sdk.es169.js +332 -158
  186. package/dist/es/standards-sdk.es169.js.map +1 -1
  187. package/dist/es/standards-sdk.es170.js +441 -210
  188. package/dist/es/standards-sdk.es170.js.map +1 -1
  189. package/dist/es/standards-sdk.es171.js +314 -222
  190. package/dist/es/standards-sdk.es171.js.map +1 -1
  191. package/dist/es/standards-sdk.es172.js +65 -108
  192. package/dist/es/standards-sdk.es172.js.map +1 -1
  193. package/dist/es/standards-sdk.es173.js +61 -114
  194. package/dist/es/standards-sdk.es173.js.map +1 -1
  195. package/dist/es/standards-sdk.es174.js +151 -140
  196. package/dist/es/standards-sdk.es174.js.map +1 -1
  197. package/dist/es/standards-sdk.es175.js +193 -156
  198. package/dist/es/standards-sdk.es175.js.map +1 -1
  199. package/dist/es/standards-sdk.es176.js +221 -121
  200. package/dist/es/standards-sdk.es176.js.map +1 -1
  201. package/dist/es/standards-sdk.es177.js +81 -293
  202. package/dist/es/standards-sdk.es177.js.map +1 -1
  203. package/dist/es/standards-sdk.es178.js +114 -247
  204. package/dist/es/standards-sdk.es178.js.map +1 -1
  205. package/dist/es/standards-sdk.es179.js +119 -110
  206. package/dist/es/standards-sdk.es179.js.map +1 -1
  207. package/dist/es/standards-sdk.es18.js +12 -12
  208. package/dist/es/standards-sdk.es180.js +188 -0
  209. package/dist/es/standards-sdk.es180.js.map +1 -0
  210. package/dist/es/standards-sdk.es181.js +142 -0
  211. package/dist/es/standards-sdk.es181.js.map +1 -0
  212. package/dist/es/standards-sdk.es182.js +334 -0
  213. package/dist/es/standards-sdk.es182.js.map +1 -0
  214. package/dist/es/standards-sdk.es183.js +262 -0
  215. package/dist/es/standards-sdk.es183.js.map +1 -0
  216. package/dist/es/standards-sdk.es184.js +155 -0
  217. package/dist/es/standards-sdk.es184.js.map +1 -0
  218. package/dist/es/standards-sdk.es19.js +9 -9
  219. package/dist/es/standards-sdk.es2.js +2 -2
  220. package/dist/es/standards-sdk.es20.js +1 -1
  221. package/dist/es/standards-sdk.es21.js +1 -1
  222. package/dist/es/standards-sdk.es22.js +1 -1
  223. package/dist/es/standards-sdk.es23.js +1 -1
  224. package/dist/es/standards-sdk.es24.js +1 -1
  225. package/dist/es/standards-sdk.es25.js +1 -1
  226. package/dist/es/standards-sdk.es26.js +1 -1
  227. package/dist/es/standards-sdk.es27.js +12 -12
  228. package/dist/es/standards-sdk.es27.js.map +1 -1
  229. package/dist/es/standards-sdk.es30.js +2 -2
  230. package/dist/es/standards-sdk.es31.js +4 -4
  231. package/dist/es/standards-sdk.es32.js +1 -1
  232. package/dist/es/standards-sdk.es35.js +6 -6
  233. package/dist/es/standards-sdk.es36.js +4 -4
  234. package/dist/es/standards-sdk.es37.js +2 -2
  235. package/dist/es/standards-sdk.es38.js +2 -2
  236. package/dist/es/standards-sdk.es39.js +1 -1
  237. package/dist/es/standards-sdk.es4.js +2 -2
  238. package/dist/es/standards-sdk.es40.js +1 -1
  239. package/dist/es/standards-sdk.es41.js +2 -2
  240. package/dist/es/standards-sdk.es46.js +1 -1
  241. package/dist/es/standards-sdk.es5.js +2 -2
  242. package/dist/es/standards-sdk.es51.js +1 -1
  243. package/dist/es/standards-sdk.es53.js +1 -1
  244. package/dist/es/standards-sdk.es56.js +2 -2
  245. package/dist/es/standards-sdk.es59.js +1 -1
  246. package/dist/es/standards-sdk.es6.js +2 -2
  247. package/dist/es/standards-sdk.es60.js +1 -1
  248. package/dist/es/standards-sdk.es62.js +1 -1
  249. package/dist/es/standards-sdk.es63.js +2 -2
  250. package/dist/es/standards-sdk.es64.js +1 -1
  251. package/dist/es/standards-sdk.es65.js +1 -1
  252. package/dist/es/standards-sdk.es66.js +1 -1
  253. package/dist/es/standards-sdk.es67.js +7 -7
  254. package/dist/es/standards-sdk.es69.js +1 -1
  255. package/dist/es/standards-sdk.es7.js +1 -1
  256. package/dist/es/standards-sdk.es71.js +2 -2
  257. package/dist/es/standards-sdk.es72.js +3 -3
  258. package/dist/es/standards-sdk.es75.js +5 -5
  259. package/dist/es/standards-sdk.es76.js +3 -3
  260. package/dist/es/standards-sdk.es77.js +2 -2
  261. package/dist/es/standards-sdk.es78.js +1 -1
  262. package/dist/es/standards-sdk.es81.js +2 -2
  263. package/dist/es/standards-sdk.es83.js +2 -2
  264. package/dist/es/standards-sdk.es84.js +4 -4
  265. package/dist/es/standards-sdk.es85.js +1 -1
  266. package/dist/es/standards-sdk.es88.js +1 -1
  267. package/dist/es/standards-sdk.es89.js +2 -2
  268. package/dist/es/standards-sdk.es9.js +2 -2
  269. package/dist/es/standards-sdk.es90.js +4 -4
  270. package/dist/es/standards-sdk.es90.js.map +1 -1
  271. package/dist/es/standards-sdk.es94.js +3 -3
  272. package/dist/es/standards-sdk.es96.js +2 -2
  273. package/dist/es/standards-sdk.es98.js +1 -1
  274. package/dist/es/standards-sdk.es99.js +3 -3
  275. package/dist/es/utils/key-type-detector.d.ts.map +1 -1
  276. package/package.json +1 -1
@@ -1,605 +1,163 @@
1
- import { PrivateKey } from "@hashgraph/sdk";
2
- var KeyType = /* @__PURE__ */ ((KeyType2) => {
3
- KeyType2["ED25519"] = "ed25519";
4
- KeyType2["ECDSA"] = "ecdsa";
5
- KeyType2["UNKNOWN"] = "unknown";
6
- return KeyType2;
7
- })(KeyType || {});
8
- const _KeyTypeDetector = class _KeyTypeDetector {
9
- /**
10
- * Detects private key type from various input formats without throwing errors
11
- *
12
- * This detector is designed for private keys only. It uses various heuristics to determine
13
- * the key type for ambiguous 32-byte keys, including byte patterns and statistical analysis.
14
- *
15
- * For ambiguous cases (where confidence is 'uncertain'), if you have the associated account ID,
16
- * you can use the Hedera mirror node to confirm the key type.
17
- *
18
- * @param keyInput - The key to detect, can be a string (hex, base64, PEM), Buffer, or Uint8Array
19
- * @returns KeyInfo object containing the detected key type and metadata
20
- *
21
- * @example
22
- * // Detect from hex string
23
- * const info1 = KeyTypeDetector.detect('0x7f96cea0c0d9d5bfb3ab8a42cf0cea44d57f62f2e068f8e5a3251914a9252b04');
24
- *
25
- * // Detect from DER-encoded string
26
- * const info2 = KeyTypeDetector.detect(privateKey.toStringDer());
27
- *
28
- * // Detect from PEM format
29
- * const info3 = KeyTypeDetector.detect(`-----BEGIN PRIVATE KEY-----
30
- * MC4CAQAwBQYDK2VwBCIEIGRchBsQGQduAAGBQ7GAkKCKkmQ3EGCARwHsHiRqTNR9
31
- * -----END PRIVATE KEY-----`);
32
- */
33
- static detect(keyInput) {
34
- try {
35
- let keyBytes;
36
- let originalFormat = "raw";
37
- if (typeof keyInput === "string") {
38
- let trimmed = keyInput.trim();
39
- if (trimmed.includes("-----BEGIN")) {
40
- return this.detectFromPem(trimmed);
41
- }
42
- if (trimmed.toLowerCase().startsWith("0x")) {
43
- trimmed = trimmed.substring(2);
44
- }
45
- if (this.isValidHex(trimmed)) {
46
- keyBytes = this.hexToBytes(trimmed);
47
- originalFormat = "hex";
48
- } else if (this.isBase64(trimmed)) {
49
- keyBytes = Buffer.from(trimmed, "base64");
50
- originalFormat = "der";
51
- } else {
52
- return {
53
- type: "unknown",
54
- format: "raw",
55
- isPrivateKey: false,
56
- confidence: "certain"
57
- };
58
- }
59
- } else if (keyInput instanceof Buffer) {
60
- keyBytes = new Uint8Array(keyInput);
61
- } else {
62
- keyBytes = keyInput;
63
- }
64
- return this.detectFromBytes(keyBytes, originalFormat);
65
- } catch (error) {
66
- return {
67
- type: "unknown",
68
- format: "raw",
69
- isPrivateKey: false,
70
- confidence: "certain"
71
- };
72
- }
73
- }
74
- /**
75
- * Detect key type from raw bytes
76
- *
77
- * @param bytes - The raw bytes of the key
78
- * @param format - The original format of the key
79
- * @returns KeyInfo object with detection results
80
- * @private
81
- */
82
- static detectFromBytes(bytes, format) {
83
- if (this.hasPrefix(bytes, this.ED25519_PUBLIC_KEY_PREFIX)) {
84
- const keyStart = this.ED25519_PUBLIC_KEY_PREFIX.length;
85
- return {
86
- type: "ed25519",
87
- format: "der",
88
- isPrivateKey: false,
89
- rawBytes: bytes.slice(keyStart),
90
- confidence: "certain"
91
- };
92
- }
93
- if (this.hasPrefix(bytes, this.ED25519_PRIVATE_KEY_PREFIX)) {
94
- const keyStart = this.ED25519_PRIVATE_KEY_PREFIX.length;
95
- if (bytes.length >= keyStart + 32) {
96
- return {
97
- type: "ed25519",
98
- format: "der",
99
- isPrivateKey: true,
100
- rawBytes: bytes.slice(keyStart, keyStart + 32),
101
- confidence: "certain"
102
- };
103
- }
104
- }
105
- if (this.hasPrefix(bytes, this.ECDSA_SECP256K1_PUBLIC_KEY_PREFIX)) {
106
- const keyStart = this.ECDSA_SECP256K1_PUBLIC_KEY_PREFIX.length;
107
- return {
108
- type: "ecdsa",
109
- format: "der",
110
- isPrivateKey: false,
111
- rawBytes: bytes.slice(keyStart),
112
- confidence: "certain"
113
- };
114
- }
115
- if (this.hasPrefix(bytes, this.ECDSA_SECP256K1_PRIVATE_KEY_PREFIX_SHORT)) {
116
- const keyStart = this.ECDSA_SECP256K1_PRIVATE_KEY_PREFIX_SHORT.length;
117
- return {
118
- type: "ecdsa",
119
- format: "der",
120
- isPrivateKey: true,
121
- rawBytes: bytes.slice(keyStart),
122
- confidence: "certain"
123
- };
124
- }
125
- if (this.hasPrefix(bytes, this.ECDSA_SECP256K1_PRIVATE_KEY_PREFIX)) {
126
- const keyStart = this.ECDSA_SECP256K1_PRIVATE_KEY_PREFIX.length;
127
- return {
128
- type: "ecdsa",
129
- format: "der",
130
- isPrivateKey: true,
131
- rawBytes: bytes.slice(keyStart, keyStart + 32),
132
- confidence: "certain"
133
- };
134
- }
135
- if (this.hasPrefix(bytes, this.ECDSA_SECP256K1_PRIVATE_KEY_PREFIX_LONG)) {
136
- const keyStart = this.ECDSA_SECP256K1_PRIVATE_KEY_PREFIX_LONG.length;
137
- return {
138
- type: "ecdsa",
139
- format: "der",
140
- isPrivateKey: true,
141
- rawBytes: bytes.slice(keyStart, keyStart + 32),
142
- confidence: "certain"
143
- };
144
- }
145
- if (bytes.length > 36 && this.containsECDSAPrivateKeyPattern(bytes)) {
146
- return {
147
- type: "ecdsa",
148
- format: "der",
149
- isPrivateKey: true,
150
- rawBytes: this.extractECDSAPrivateKey(bytes),
151
- confidence: "certain"
152
- };
153
- }
154
- switch (bytes.length) {
155
- case this.ED25519_PUBLIC_KEY_LENGTH:
156
- if (format === "hex") {
157
- const hexStr = Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
158
- const privateResult = this.tryCreateKey(hexStr);
159
- if (privateResult.type !== "unknown") {
160
- return privateResult;
161
- }
162
- }
163
- return {
164
- type: "unknown",
165
- format,
166
- isPrivateKey: false,
167
- rawBytes: bytes,
168
- confidence: "certain"
169
- };
170
- case this.ED25519_EXPANDED_PRIVATE_KEY_LENGTH:
171
- return {
172
- type: "ed25519",
173
- format,
174
- isPrivateKey: true,
175
- rawBytes: bytes,
176
- confidence: "certain"
177
- };
178
- }
179
- return {
180
- type: "unknown",
181
- format,
182
- isPrivateKey: false,
183
- rawBytes: bytes,
184
- confidence: "certain"
185
- };
1
+ import { Logger } from "./standards-sdk.es123.js";
2
+ class ProgressReporter {
3
+ constructor(options = {}) {
4
+ this.module = options.module || "Progress";
5
+ this.callback = options.callback;
6
+ this.logger = options.logger || new Logger({
7
+ level: "info",
8
+ module: "ProgressReporter"
9
+ });
10
+ this.logProgress = options.logProgress ?? true;
11
+ this.minPercent = options.minPercent ?? 0;
12
+ this.maxPercent = options.maxPercent ?? 100;
13
+ this.lastReportedPercent = -1;
14
+ this.lastReportedTime = 0;
15
+ this.throttleMs = 100;
186
16
  }
187
- /**
188
- * Detect key type from PEM format
189
- *
190
- * @param pem - The PEM-encoded key string
191
- * @returns KeyInfo object with detection results
192
- * @private
193
- */
194
- static detectFromPem(pem) {
195
- const trimmedPem = pem.trim();
196
- const isPrivateKey = trimmedPem.includes("PRIVATE KEY");
197
- const pemTypes = {
198
- EC_PRIVATE: /-----BEGIN EC PRIVATE KEY-----/,
199
- EC_PUBLIC: /-----BEGIN EC PUBLIC KEY-----/,
200
- PRIVATE: /-----BEGIN PRIVATE KEY-----/,
201
- PUBLIC: /-----BEGIN PUBLIC KEY-----/
202
- };
203
- let isECKey = false;
204
- for (const [type, regex] of Object.entries(pemTypes)) {
205
- if (regex.test(trimmedPem) && type.includes("EC")) {
206
- isECKey = true;
207
- break;
17
+ static getInstance(options = {}) {
18
+ if (!ProgressReporter.instance) {
19
+ ProgressReporter.instance = new ProgressReporter(options);
20
+ } else {
21
+ if (options.callback) {
22
+ ProgressReporter.instance.setCallback(options.callback);
208
23
  }
209
- }
210
- const base64Match = trimmedPem.match(
211
- /-----BEGIN[\s\S]+?-----[\r\n]+([\s\S]+?)[\r\n]+-----END/
212
- );
213
- if (!base64Match) {
214
- return {
215
- type: "unknown",
216
- format: "pem",
217
- isPrivateKey,
218
- confidence: "certain"
219
- };
220
- }
221
- const base64Content = base64Match[1].replace(/\s/g, "");
222
- try {
223
- const derBytes = Buffer.from(base64Content, "base64");
224
- const result = this.detectFromBytes(new Uint8Array(derBytes), "der");
225
- if (result.type === "unknown" && isECKey) {
226
- return {
227
- type: "ecdsa",
228
- format: "pem",
229
- isPrivateKey,
230
- rawBytes: derBytes,
231
- confidence: "certain"
232
- };
24
+ if (options.module) {
25
+ ProgressReporter.instance.setModule(options.module);
233
26
  }
234
- return {
235
- ...result,
236
- format: "pem"
237
- };
238
- } catch {
239
- return {
240
- type: "unknown",
241
- format: "pem",
242
- isPrivateKey,
243
- confidence: "certain"
244
- };
245
- }
246
- }
247
- /**
248
- * Try to create a key using Hedera SDK to validate the type
249
- *
250
- * @param keyInput - The key input string or bytes
251
- * @returns KeyInfo object with detection results
252
- * @private
253
- */
254
- static tryCreateKey(keyInput) {
255
- try {
256
- if (typeof keyInput === "string") {
257
- let keyStr = keyInput.trim();
258
- if (keyStr.toLowerCase().startsWith("0x")) {
259
- keyStr = keyStr.substring(2);
260
- }
261
- if (this.isValidHex(keyStr) && keyStr.length === 64) {
262
- const keyBytes = this.hexToBytes(keyStr);
263
- const signatureResult = this.detectBySignature(keyStr);
264
- if (signatureResult.type !== "unknown") {
265
- return {
266
- type: signatureResult.type,
267
- format: "hex",
268
- isPrivateKey: true,
269
- rawBytes: keyBytes,
270
- confidence: signatureResult.confidence,
271
- warning: signatureResult.warning
272
- };
273
- }
274
- return {
275
- type: "unknown",
276
- format: "hex",
277
- isPrivateKey: false,
278
- rawBytes: keyBytes,
279
- confidence: "certain"
280
- };
281
- }
27
+ if (options.logger) {
28
+ ProgressReporter.instance.setLogger(options.logger);
282
29
  }
283
- } catch {
284
- }
285
- return {
286
- type: "unknown",
287
- format: "hex",
288
- isPrivateKey: false,
289
- rawBytes: new Uint8Array(),
290
- confidence: "certain"
291
- };
292
- }
293
- /**
294
- * Detect key type by attempting to sign a message with both algorithms
295
- *
296
- * For ambiguous cases where both algorithms can use the key, this method
297
- * uses heuristics to make a best-effort determination. For production use
298
- * with ambiguous keys, consider using the Hedera mirror node to confirm
299
- * the key type if you have the associated account ID.
300
- *
301
- * @param hexKey - The hex string representation of the key
302
- * @returns Object containing type, confidence level, and optional warning
303
- * @private
304
- */
305
- static detectBySignature(hexKey) {
306
- const keyBigInt = BigInt("0x" + hexKey);
307
- const secp256k1Order = BigInt(
308
- "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"
309
- );
310
- if (keyBigInt === 0n) {
311
- return {
312
- type: "ed25519",
313
- confidence: "certain"
314
- };
315
- }
316
- if (keyBigInt >= secp256k1Order) {
317
- return {
318
- type: "ed25519",
319
- confidence: "certain"
320
- };
321
- }
322
- let ed25519CanSign = false;
323
- let ecdsaCanSign = false;
324
- try {
325
- const ed25519Key = PrivateKey.fromStringED25519(hexKey);
326
- const testMessage = new Uint8Array([1, 2, 3, 4, 5]);
327
- const signature = ed25519Key.sign(testMessage);
328
- if (ed25519Key.publicKey.verify(testMessage, signature)) {
329
- ed25519CanSign = true;
30
+ if (options.minPercent !== void 0) {
31
+ ProgressReporter.instance.setMinPercent(options.minPercent);
330
32
  }
331
- } catch {
332
- }
333
- try {
334
- const ecdsaKey = PrivateKey.fromStringECDSA(hexKey);
335
- const testMessage = new Uint8Array([1, 2, 3, 4, 5]);
336
- const signature = ecdsaKey.sign(testMessage);
337
- if (ecdsaKey.publicKey.verify(testMessage, signature)) {
338
- ecdsaCanSign = true;
33
+ if (options.maxPercent !== void 0) {
34
+ ProgressReporter.instance.setMaxPercent(options.maxPercent);
339
35
  }
340
- } catch {
341
36
  }
342
- if (ed25519CanSign && ecdsaCanSign) {
343
- const keyBytes = this.hexToBytes(hexKey);
344
- if (keyBytes[0] === 168 && keyBytes[1] === 1) {
345
- return {
346
- type: "ed25519",
347
- confidence: "uncertain",
348
- warning: "Detection based on byte pattern heuristic. Both ED25519 and ECDSA accept this key."
349
- };
350
- }
351
- let highBytes = 0;
352
- for (const byte of keyBytes) {
353
- if (byte >= 128) highBytes++;
354
- }
355
- const highByteRatio = highBytes / keyBytes.length;
356
- if (highByteRatio >= 0.4 && highByteRatio <= 0.6) {
357
- return {
358
- type: "ecdsa",
359
- confidence: "uncertain",
360
- warning: "Detection based on entropy heuristic. Both ED25519 and ECDSA accept this key."
361
- };
362
- }
363
- return {
364
- type: "ecdsa",
365
- confidence: "uncertain",
366
- warning: "Detection based on entropy heuristic. Both ED25519 and ECDSA accept this key. Defaulting to ECDSA."
367
- };
368
- }
369
- if (ed25519CanSign && !ecdsaCanSign) {
370
- return {
371
- type: "ed25519",
372
- confidence: "certain"
373
- };
374
- }
375
- if (ecdsaCanSign && !ed25519CanSign) {
376
- return {
377
- type: "ecdsa",
378
- confidence: "certain"
379
- };
380
- }
381
- return {
382
- type: "unknown",
383
- confidence: "certain"
384
- };
37
+ return ProgressReporter.instance;
385
38
  }
386
- /**
387
- * Check if a string is valid hexadecimal with even length
388
- *
389
- * @param str - The string to check
390
- * @returns True if the string is valid hex with even length
391
- * @private
392
- */
393
- static isValidHex(str) {
394
- return /^[0-9a-fA-F]+$/.test(str) && str.length % 2 === 0;
39
+ setCallback(callback) {
40
+ this.callback = callback;
395
41
  }
396
- /**
397
- * Check if a string is valid base64
398
- *
399
- * @param str - The string to check
400
- * @returns True if the string is valid base64
401
- * @private
402
- */
403
- static isBase64(str) {
404
- try {
405
- return Buffer.from(str, "base64").toString("base64") === str;
406
- } catch {
407
- return false;
408
- }
42
+ setModule(module) {
43
+ this.module = module;
409
44
  }
410
- /**
411
- * Convert a hex string to bytes
412
- *
413
- * @param hex - The hex string to convert
414
- * @returns Uint8Array of bytes
415
- * @private
416
- */
417
- static hexToBytes(hex) {
418
- const bytes = new Uint8Array(hex.length / 2);
419
- for (let i = 0; i < hex.length; i += 2) {
420
- bytes[i / 2] = parseInt(hex.substr(i, 2), 16);
421
- }
422
- return bytes;
45
+ setLogger(logger) {
46
+ this.logger = logger;
423
47
  }
424
- /**
425
- * Check if bytes start with a specific prefix
426
- *
427
- * @param bytes - The bytes to check
428
- * @param prefix - The prefix to look for
429
- * @returns True if bytes start with the prefix
430
- * @private
431
- */
432
- static hasPrefix(bytes, prefix) {
433
- if (bytes.length < prefix.length) return false;
434
- for (let i = 0; i < prefix.length; i++) {
435
- if (bytes[i] !== prefix[i]) return false;
436
- }
437
- return true;
438
- }
439
- /**
440
- * Check if bytes contain an ECDSA private key pattern
441
- *
442
- * @param bytes - The bytes to check
443
- * @returns True if ECDSA private key pattern is found
444
- * @private
445
- */
446
- static containsECDSAPrivateKeyPattern(bytes) {
447
- for (let i = 0; i < bytes.length - 7; i++) {
448
- if (bytes[i] === 48 && bytes[i + 1] === 116 && bytes[i + 2] === 2 && bytes[i + 3] === 1 && bytes[i + 4] === 1 && bytes[i + 5] === 4 && bytes[i + 6] === 32) {
449
- return true;
450
- }
451
- }
452
- return false;
48
+ setMinPercent(minPercent) {
49
+ this.minPercent = minPercent;
453
50
  }
454
- /**
455
- * Extract ECDSA private key from DER structure
456
- *
457
- * @param bytes - The DER encoded bytes
458
- * @returns The extracted private key bytes
459
- * @private
460
- */
461
- static extractECDSAPrivateKey(bytes) {
462
- for (let i = 0; i < bytes.length - 32; i++) {
463
- if (bytes[i] === 4 && bytes[i + 1] === 32) {
464
- return bytes.slice(i + 2, i + 34);
465
- }
466
- }
467
- return bytes;
51
+ setMaxPercent(maxPercent) {
52
+ this.maxPercent = maxPercent;
468
53
  }
469
- };
470
- _KeyTypeDetector.ED25519_PUBLIC_KEY_LENGTH = 32;
471
- _KeyTypeDetector.ED25519_EXPANDED_PRIVATE_KEY_LENGTH = 64;
472
- _KeyTypeDetector.ED25519_PUBLIC_KEY_PREFIX = Buffer.from([
473
- 48,
474
- 42,
475
- 48,
476
- 5,
477
- 6,
478
- 3,
479
- 43,
480
- 101,
481
- 112,
482
- 3,
483
- 33,
484
- 0
485
- ]);
486
- _KeyTypeDetector.ED25519_PRIVATE_KEY_PREFIX = Buffer.from([
487
- 48,
488
- 46,
489
- 2,
490
- 1,
491
- 0,
492
- 48,
493
- 5,
494
- 6,
495
- 3,
496
- 43,
497
- 101,
498
- 112,
499
- 4,
500
- 34,
501
- 4,
502
- 32
503
- ]);
504
- _KeyTypeDetector.ECDSA_SECP256K1_PUBLIC_KEY_PREFIX = Buffer.from([
505
- 48,
506
- 86,
507
- 48,
508
- 16,
509
- 6,
510
- 7,
511
- 42,
512
- 134,
513
- 72,
514
- 206,
515
- 61,
516
- 2,
517
- 1,
518
- 6,
519
- 5,
520
- 43,
521
- 129,
522
- 4,
523
- 0,
524
- 10,
525
- 3,
526
- 66,
527
- 0
528
- ]);
529
- _KeyTypeDetector.ECDSA_SECP256K1_PRIVATE_KEY_PREFIX = Buffer.from([
530
- 48,
531
- 116,
532
- 2,
533
- 1,
534
- 1,
535
- 4,
536
- 32
537
- ]);
538
- _KeyTypeDetector.ECDSA_SECP256K1_PRIVATE_KEY_PREFIX_SHORT = Buffer.from([
539
- 48,
540
- 48,
541
- 2,
542
- 1,
543
- 0,
544
- 48,
545
- 7,
546
- 6,
547
- 5,
548
- 43,
549
- 129,
550
- 4,
551
- 0,
552
- 10,
553
- 4,
554
- 34,
555
- 4,
556
- 32
557
- ]);
558
- _KeyTypeDetector.ECDSA_SECP256K1_PRIVATE_KEY_PREFIX_LONG = Buffer.from(
559
- [48, 119, 2, 1, 1, 4, 32]
560
- );
561
- let KeyTypeDetector = _KeyTypeDetector;
562
- function detectKeyTypeFromString(privateKeyString) {
563
- const keyInfo = KeyTypeDetector.detect(privateKeyString);
564
- if (keyInfo.type !== "unknown") {
565
- try {
566
- const privateKey = keyInfo.type === "ecdsa" ? PrivateKey.fromStringECDSA(privateKeyString) : PrivateKey.fromStringED25519(privateKeyString);
567
- const result = {
568
- detectedType: keyInfo.type,
569
- privateKey
570
- };
571
- if (keyInfo.confidence === "uncertain") {
572
- result.warning = `Key type detection is uncertain. If you have the associated account ID, consider using the Hedera mirror node to confirm the key type.`;
54
+ createSubProgress(options) {
55
+ const subReporter = new ProgressReporter({
56
+ module: this.module,
57
+ logger: this.logger,
58
+ logProgress: this.logProgress,
59
+ minPercent: options.minPercent,
60
+ maxPercent: options.maxPercent
61
+ });
62
+ const logPrefix = options.logPrefix || "";
63
+ subReporter.setCallback((data) => {
64
+ const scaledPercent = this.scalePercent(
65
+ data.progressPercent,
66
+ options.minPercent,
67
+ options.maxPercent
68
+ );
69
+ let formattedMessage = data.message;
70
+ if (logPrefix && !formattedMessage.startsWith(logPrefix)) {
71
+ formattedMessage = `${logPrefix}: ${formattedMessage}`;
573
72
  }
574
- return result;
575
- } catch (error) {
576
- }
73
+ this.report({
74
+ stage: data.stage,
75
+ message: formattedMessage,
76
+ progressPercent: scaledPercent,
77
+ details: data.details
78
+ });
79
+ });
80
+ return subReporter;
577
81
  }
578
- try {
579
- const privateKey = PrivateKey.fromStringECDSA(privateKeyString);
580
- return {
581
- detectedType: "ecdsa",
582
- privateKey,
583
- warning: `Using ECDSA as default. If you have the associated account ID, consider using the Hedera mirror node to confirm the key type.`
82
+ report(data) {
83
+ const rawPercent = data.progressPercent;
84
+ const percent = Math.max(0, Math.min(100, rawPercent));
85
+ const scaledPercent = this.scalePercent(percent, 0, 100);
86
+ const now = Date.now();
87
+ if (scaledPercent === this.lastReportedPercent && now - this.lastReportedTime < this.throttleMs && data.stage !== "completed" && data.stage !== "failed") {
88
+ return;
89
+ }
90
+ this.lastReportedPercent = scaledPercent;
91
+ this.lastReportedTime = now;
92
+ const progressData = {
93
+ ...data,
94
+ progressPercent: scaledPercent
584
95
  };
585
- } catch (ecdsaError) {
586
- try {
587
- const privateKey = PrivateKey.fromStringED25519(privateKeyString);
588
- return {
589
- detectedType: "ed25519",
590
- privateKey,
591
- warning: `Using ED25519 as fallback. If you have the associated account ID, consider using the Hedera mirror node to confirm the key type.`
592
- };
593
- } catch (ed25519Error) {
594
- throw new Error(
595
- `Failed to parse private key as either ECDSA or ED25519: ${ecdsaError}`
96
+ if (this.logProgress) {
97
+ this.logger.debug(
98
+ `[${this.module}] [${data.stage.toUpperCase()}] ${data.message} (${scaledPercent.toFixed(1)}%)`,
99
+ data.details
596
100
  );
597
101
  }
102
+ if (this.callback) {
103
+ try {
104
+ this.callback(progressData);
105
+ } catch (err) {
106
+ this.logger.warn(`Error in progress callback: ${err}`);
107
+ }
108
+ }
109
+ }
110
+ scalePercent(percent, sourceMin, sourceMax) {
111
+ const range = this.maxPercent - this.minPercent;
112
+ const sourceRange = sourceMax - sourceMin;
113
+ const scaleFactor = range / sourceRange;
114
+ return this.minPercent + (percent - sourceMin) * scaleFactor;
115
+ }
116
+ preparing(message, percent, details) {
117
+ this.report({
118
+ stage: "preparing",
119
+ message,
120
+ progressPercent: percent,
121
+ details
122
+ });
123
+ }
124
+ submitting(message, percent, details) {
125
+ this.report({
126
+ stage: "submitting",
127
+ message,
128
+ progressPercent: percent,
129
+ details
130
+ });
131
+ }
132
+ confirming(message, percent, details) {
133
+ this.report({
134
+ stage: "confirming",
135
+ message,
136
+ progressPercent: percent,
137
+ details
138
+ });
139
+ }
140
+ verifying(message, percent, details) {
141
+ this.report({
142
+ stage: "verifying",
143
+ message,
144
+ progressPercent: percent,
145
+ details
146
+ });
147
+ }
148
+ completed(message, details) {
149
+ this.report({ stage: "completed", message, progressPercent: 100, details });
150
+ }
151
+ failed(message, details) {
152
+ this.report({
153
+ stage: "failed",
154
+ message,
155
+ progressPercent: this.lastReportedPercent,
156
+ details
157
+ });
598
158
  }
599
159
  }
600
160
  export {
601
- KeyType,
602
- KeyTypeDetector,
603
- detectKeyTypeFromString
161
+ ProgressReporter
604
162
  };
605
163
  //# sourceMappingURL=standards-sdk.es126.js.map