@ecency/sdk 1.5.27 → 2.0.0

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.
@@ -33,8 +33,458 @@ var __export = (target, all) => {
33
33
  for (var name in all)
34
34
  __defProp(target, name, { get: all[name], enumerable: true });
35
35
  };
36
+
37
+ // src/modules/core/errors/chain-errors.ts
38
+ var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
39
+ ErrorType2["COMMON"] = "common";
40
+ ErrorType2["INFO"] = "info";
41
+ ErrorType2["INSUFFICIENT_RESOURCE_CREDITS"] = "insufficient_resource_credits";
42
+ ErrorType2["MISSING_AUTHORITY"] = "missing_authority";
43
+ ErrorType2["TOKEN_EXPIRED"] = "token_expired";
44
+ ErrorType2["NETWORK"] = "network";
45
+ ErrorType2["TIMEOUT"] = "timeout";
46
+ ErrorType2["VALIDATION"] = "validation";
47
+ return ErrorType2;
48
+ })(ErrorType || {});
49
+ function parseChainError(error) {
50
+ const errorDescription = error?.error_description ? String(error.error_description) : "";
51
+ const errorMessage = error?.message ? String(error.message) : "";
52
+ const errorString = errorDescription || errorMessage || String(error || "");
53
+ const testPattern = (pattern) => {
54
+ if (errorDescription && pattern.test(errorDescription)) return true;
55
+ if (errorMessage && pattern.test(errorMessage)) return true;
56
+ if (errorString && pattern.test(errorString)) return true;
57
+ return false;
58
+ };
59
+ if (testPattern(/please wait to transact/i) || testPattern(/insufficient rc/i) || testPattern(/rc mana|rc account|resource credits/i)) {
60
+ return {
61
+ message: "Insufficient Resource Credits. Please wait or power up.",
62
+ type: "insufficient_resource_credits" /* INSUFFICIENT_RESOURCE_CREDITS */,
63
+ originalError: error
64
+ };
65
+ }
66
+ if (testPattern(/you may only post once every/i)) {
67
+ return {
68
+ message: "Please wait before posting again (minimum 3 second interval between comments).",
69
+ type: "common" /* COMMON */,
70
+ originalError: error
71
+ };
72
+ }
73
+ if (testPattern(/your current vote on this comment is identical/i)) {
74
+ return {
75
+ message: "You have already voted with the same weight.",
76
+ type: "info" /* INFO */,
77
+ originalError: error
78
+ };
79
+ }
80
+ if (testPattern(/must claim something/i)) {
81
+ return {
82
+ message: "You must claim rewards before performing this action.",
83
+ type: "info" /* INFO */,
84
+ originalError: error
85
+ };
86
+ }
87
+ if (testPattern(/cannot claim that much vests/i)) {
88
+ return {
89
+ message: "Cannot claim that amount. Please check your pending rewards.",
90
+ type: "info" /* INFO */,
91
+ originalError: error
92
+ };
93
+ }
94
+ if (testPattern(/cannot delete a comment with net positive/i)) {
95
+ return {
96
+ message: "Cannot delete a comment with positive votes.",
97
+ type: "info" /* INFO */,
98
+ originalError: error
99
+ };
100
+ }
101
+ if (testPattern(/children == 0/i)) {
102
+ return {
103
+ message: "Cannot delete a comment with replies.",
104
+ type: "common" /* COMMON */,
105
+ originalError: error
106
+ };
107
+ }
108
+ if (testPattern(/comment_cashout/i)) {
109
+ return {
110
+ message: "Cannot modify a comment that has already been paid out.",
111
+ type: "common" /* COMMON */,
112
+ originalError: error
113
+ };
114
+ }
115
+ if (testPattern(/votes evaluating for comment that is paid out is forbidden/i)) {
116
+ return {
117
+ message: "Cannot vote on posts that have already been paid out.",
118
+ type: "common" /* COMMON */,
119
+ originalError: error
120
+ };
121
+ }
122
+ if (testPattern(/missing active authority/i)) {
123
+ return {
124
+ message: "Missing active authority. This operation requires your active key.",
125
+ type: "missing_authority" /* MISSING_AUTHORITY */,
126
+ originalError: error
127
+ };
128
+ }
129
+ if (testPattern(/missing owner authority/i)) {
130
+ return {
131
+ message: "Missing owner authority. This operation requires your owner key.",
132
+ type: "missing_authority" /* MISSING_AUTHORITY */,
133
+ originalError: error
134
+ };
135
+ }
136
+ if (testPattern(/missing (required )?posting authority/i)) {
137
+ return {
138
+ message: "Missing posting authority. Please check your login method.",
139
+ type: "missing_authority" /* MISSING_AUTHORITY */,
140
+ originalError: error
141
+ };
142
+ }
143
+ if (testPattern(/token expired/i) || testPattern(/invalid token/i)) {
144
+ return {
145
+ message: "Authentication token expired. Please log in again.",
146
+ type: "token_expired" /* TOKEN_EXPIRED */,
147
+ originalError: error
148
+ };
149
+ }
150
+ if (testPattern(/has already reblogged/i) || testPattern(/already reblogged this post/i)) {
151
+ return {
152
+ message: "You have already reblogged this post.",
153
+ type: "info" /* INFO */,
154
+ originalError: error
155
+ };
156
+ }
157
+ if (testPattern(/duplicate transaction/i)) {
158
+ return {
159
+ message: "This transaction has already been processed.",
160
+ type: "info" /* INFO */,
161
+ originalError: error
162
+ };
163
+ }
164
+ if (testPattern(/econnrefused/i) || testPattern(/connection refused/i) || testPattern(/failed to fetch/i) || testPattern(/\bnetwork[-\s]?(request|error|timeout|unreachable|down|failed)\b/i)) {
165
+ return {
166
+ message: "Network error. Please check your connection and try again.",
167
+ type: "network" /* NETWORK */,
168
+ originalError: error
169
+ };
170
+ }
171
+ if (testPattern(/timeout/i) || testPattern(/timed out/i)) {
172
+ return {
173
+ message: "Request timed out. Please try again.",
174
+ type: "timeout" /* TIMEOUT */,
175
+ originalError: error
176
+ };
177
+ }
178
+ if (testPattern(/account.*does not exist/i) || testPattern(/account not found/i)) {
179
+ return {
180
+ message: "Account not found. Please check the username.",
181
+ type: "validation" /* VALIDATION */,
182
+ originalError: error
183
+ };
184
+ }
185
+ if (testPattern(/invalid memo key/i)) {
186
+ return {
187
+ message: "Invalid memo key. Cannot encrypt message.",
188
+ type: "validation" /* VALIDATION */,
189
+ originalError: error
190
+ };
191
+ }
192
+ if (testPattern(/(?:insufficient.*(?:funds|balance)|(?:funds|balance).*insufficient)/i)) {
193
+ return {
194
+ message: "Insufficient funds for this transaction.",
195
+ type: "validation" /* VALIDATION */,
196
+ originalError: error
197
+ };
198
+ }
199
+ if (testPattern(/\b(invalid|validation)\b/i)) {
200
+ const message2 = (error?.message || errorString).substring(0, 150) || "Validation error occurred";
201
+ return {
202
+ message: message2,
203
+ type: "validation" /* VALIDATION */,
204
+ originalError: error
205
+ };
206
+ }
207
+ if (error?.error_description && typeof error.error_description === "string") {
208
+ return {
209
+ message: error.error_description.substring(0, 150),
210
+ type: "common" /* COMMON */,
211
+ originalError: error
212
+ };
213
+ }
214
+ if (error?.message && typeof error.message === "string") {
215
+ return {
216
+ message: error.message.substring(0, 150),
217
+ type: "common" /* COMMON */,
218
+ originalError: error
219
+ };
220
+ }
221
+ let message;
222
+ if (typeof error === "object" && error !== null) {
223
+ if (error.error_description) {
224
+ message = String(error.error_description);
225
+ } else if (error.code) {
226
+ message = `Error code: ${error.code}`;
227
+ } else if (errorString && errorString !== "[object Object]") {
228
+ message = errorString.substring(0, 150);
229
+ } else {
230
+ message = "Unknown error occurred";
231
+ }
232
+ } else {
233
+ message = errorString.substring(0, 150) || "Unknown error occurred";
234
+ }
235
+ return {
236
+ message,
237
+ type: "common" /* COMMON */,
238
+ originalError: error
239
+ };
240
+ }
241
+ function formatError(error) {
242
+ const parsed = parseChainError(error);
243
+ return [parsed.message, parsed.type];
244
+ }
245
+ function shouldTriggerAuthFallback(error) {
246
+ const { type } = parseChainError(error);
247
+ return type === "missing_authority" /* MISSING_AUTHORITY */ || type === "token_expired" /* TOKEN_EXPIRED */;
248
+ }
249
+ function isResourceCreditsError(error) {
250
+ const { type } = parseChainError(error);
251
+ return type === "insufficient_resource_credits" /* INSUFFICIENT_RESOURCE_CREDITS */;
252
+ }
253
+ function isInfoError(error) {
254
+ const { type } = parseChainError(error);
255
+ return type === "info" /* INFO */;
256
+ }
257
+ function isNetworkError(error) {
258
+ const { type } = parseChainError(error);
259
+ return type === "network" /* NETWORK */ || type === "timeout" /* TIMEOUT */;
260
+ }
261
+ async function broadcastWithMethod(method, username, ops2, auth, authority = "posting", fetchedKey, fetchedToken) {
262
+ const adapter = auth?.adapter;
263
+ switch (method) {
264
+ case "key": {
265
+ if (!adapter) {
266
+ throw new Error("No adapter provided for key-based auth");
267
+ }
268
+ let key = fetchedKey;
269
+ if (key === void 0) {
270
+ switch (authority) {
271
+ case "owner":
272
+ if (adapter.getOwnerKey) {
273
+ key = await adapter.getOwnerKey(username);
274
+ } else {
275
+ throw new Error(
276
+ `Owner key not supported by adapter. Owner operations (like account recovery) require master password login or manual key entry.`
277
+ );
278
+ }
279
+ break;
280
+ case "active":
281
+ if (adapter.getActiveKey) {
282
+ key = await adapter.getActiveKey(username);
283
+ }
284
+ break;
285
+ case "memo":
286
+ if (adapter.getMemoKey) {
287
+ key = await adapter.getMemoKey(username);
288
+ } else {
289
+ throw new Error(
290
+ `Memo key not supported by adapter. Use memo encryption methods instead.`
291
+ );
292
+ }
293
+ break;
294
+ case "posting":
295
+ default:
296
+ key = await adapter.getPostingKey(username);
297
+ break;
298
+ }
299
+ }
300
+ if (!key) {
301
+ throw new Error(`No ${authority} key available for ${username}`);
302
+ }
303
+ const privateKey = dhive.PrivateKey.fromString(key);
304
+ return await CONFIG.hiveClient.broadcast.sendOperations(ops2, privateKey);
305
+ }
306
+ case "hiveauth": {
307
+ if (!adapter?.broadcastWithHiveAuth) {
308
+ throw new Error("HiveAuth not supported by adapter");
309
+ }
310
+ return await adapter.broadcastWithHiveAuth(username, ops2, authority);
311
+ }
312
+ case "hivesigner": {
313
+ if (!adapter) {
314
+ throw new Error("No adapter provided for HiveSigner auth");
315
+ }
316
+ const token = fetchedToken !== void 0 ? fetchedToken : await adapter.getAccessToken(username);
317
+ if (!token) {
318
+ throw new Error(`No access token available for ${username}`);
319
+ }
320
+ const client = new hs__default.default.Client({ accessToken: token });
321
+ const response = await client.broadcast(ops2);
322
+ return response.result;
323
+ }
324
+ case "keychain": {
325
+ if (!adapter?.broadcastWithKeychain) {
326
+ throw new Error("Keychain not supported by adapter");
327
+ }
328
+ return await adapter.broadcastWithKeychain(username, ops2, authority);
329
+ }
330
+ case "custom": {
331
+ if (!auth?.broadcast) {
332
+ throw new Error("No custom broadcast function provided");
333
+ }
334
+ return await auth.broadcast(ops2, authority);
335
+ }
336
+ default:
337
+ throw new Error(`Unknown auth method: ${method}`);
338
+ }
339
+ }
340
+ async function broadcastWithFallback(username, ops2, auth, authority = "posting") {
341
+ const adapter = auth?.adapter;
342
+ if (adapter?.getLoginType) {
343
+ const loginType = await adapter.getLoginType(username);
344
+ if (loginType) {
345
+ const hasPostingAuth = adapter.hasPostingAuthorization ? await adapter.hasPostingAuthorization(username) : false;
346
+ if (authority === "posting" && hasPostingAuth && loginType === "key") {
347
+ try {
348
+ return await broadcastWithMethod("hivesigner", username, ops2, auth, authority);
349
+ } catch (error) {
350
+ if (!shouldTriggerAuthFallback(error)) {
351
+ throw error;
352
+ }
353
+ console.warn("[SDK] HiveSigner token auth failed, falling back to key:", error);
354
+ }
355
+ }
356
+ if (authority === "posting" && hasPostingAuth && loginType === "hiveauth") {
357
+ try {
358
+ return await broadcastWithMethod("hivesigner", username, ops2, auth, authority);
359
+ } catch (error) {
360
+ if (!shouldTriggerAuthFallback(error)) {
361
+ throw error;
362
+ }
363
+ console.warn("[SDK] HiveSigner token auth failed, falling back to HiveAuth:", error);
364
+ }
365
+ }
366
+ try {
367
+ return await broadcastWithMethod(loginType, username, ops2, auth, authority);
368
+ } catch (error) {
369
+ if (shouldTriggerAuthFallback(error)) {
370
+ if (adapter.showAuthUpgradeUI && (authority === "posting" || authority === "active")) {
371
+ const operationName = ops2.length > 0 ? ops2[0][0] : "unknown";
372
+ const selectedMethod = await adapter.showAuthUpgradeUI(authority, operationName);
373
+ if (!selectedMethod) {
374
+ throw new Error(`Operation requires ${authority} authority. User declined alternate auth.`);
375
+ }
376
+ return await broadcastWithMethod(selectedMethod, username, ops2, auth, authority);
377
+ }
378
+ }
379
+ throw error;
380
+ }
381
+ }
382
+ }
383
+ const chain = auth?.fallbackChain ?? ["key", "hiveauth", "hivesigner", "keychain", "custom"];
384
+ const errors = /* @__PURE__ */ new Map();
385
+ for (const method of chain) {
386
+ try {
387
+ let shouldSkip = false;
388
+ let skipReason = "";
389
+ let prefetchedKey;
390
+ let prefetchedToken;
391
+ switch (method) {
392
+ case "key":
393
+ if (!adapter) {
394
+ shouldSkip = true;
395
+ skipReason = "No adapter provided";
396
+ } else {
397
+ let key;
398
+ switch (authority) {
399
+ case "owner":
400
+ if (adapter.getOwnerKey) {
401
+ key = await adapter.getOwnerKey(username);
402
+ }
403
+ break;
404
+ case "active":
405
+ if (adapter.getActiveKey) {
406
+ key = await adapter.getActiveKey(username);
407
+ }
408
+ break;
409
+ case "memo":
410
+ if (adapter.getMemoKey) {
411
+ key = await adapter.getMemoKey(username);
412
+ }
413
+ break;
414
+ case "posting":
415
+ default:
416
+ key = await adapter.getPostingKey(username);
417
+ break;
418
+ }
419
+ if (!key) {
420
+ shouldSkip = true;
421
+ skipReason = `No ${authority} key available`;
422
+ } else {
423
+ prefetchedKey = key;
424
+ }
425
+ }
426
+ break;
427
+ case "hiveauth":
428
+ if (!adapter?.broadcastWithHiveAuth) {
429
+ shouldSkip = true;
430
+ skipReason = "HiveAuth not supported by adapter";
431
+ }
432
+ break;
433
+ case "hivesigner":
434
+ if (!adapter) {
435
+ shouldSkip = true;
436
+ skipReason = "No adapter provided";
437
+ } else {
438
+ const token = await adapter.getAccessToken(username);
439
+ if (!token) {
440
+ shouldSkip = true;
441
+ skipReason = "No access token available";
442
+ } else {
443
+ prefetchedToken = token;
444
+ }
445
+ }
446
+ break;
447
+ case "keychain":
448
+ if (!adapter?.broadcastWithKeychain) {
449
+ shouldSkip = true;
450
+ skipReason = "Keychain not supported by adapter";
451
+ }
452
+ break;
453
+ case "custom":
454
+ if (!auth?.broadcast) {
455
+ shouldSkip = true;
456
+ skipReason = "No custom broadcast function provided";
457
+ }
458
+ break;
459
+ }
460
+ if (shouldSkip) {
461
+ errors.set(method, new Error(`Skipped: ${skipReason}`));
462
+ continue;
463
+ }
464
+ return await broadcastWithMethod(method, username, ops2, auth, authority, prefetchedKey, prefetchedToken);
465
+ } catch (error) {
466
+ errors.set(method, error);
467
+ if (!shouldTriggerAuthFallback(error)) {
468
+ throw error;
469
+ }
470
+ }
471
+ }
472
+ const hasRealAttempts = Array.from(errors.values()).some(
473
+ (error) => !error.message.startsWith("Skipped:")
474
+ );
475
+ if (!hasRealAttempts) {
476
+ const skipReasons = Array.from(errors.entries()).map(([method, error]) => `${method}: ${error.message}`).join(", ");
477
+ throw new Error(
478
+ `[SDK][Broadcast] No auth methods attempted for ${username}. ${skipReasons}`
479
+ );
480
+ }
481
+ const errorMessages = Array.from(errors.entries()).map(([method, error]) => `${method}: ${error.message}`).join(", ");
482
+ throw new Error(
483
+ `[SDK][Broadcast] All auth methods failed for ${username}. Errors: ${errorMessages}`
484
+ );
485
+ }
36
486
  function useBroadcastMutation(mutationKey = [], username, operations, onSuccess = () => {
37
- }, auth) {
487
+ }, auth, authority = "posting") {
38
488
  return reactQuery.useMutation({
39
489
  onSuccess,
40
490
  mutationKey: [...mutationKey, username],
@@ -44,20 +494,28 @@ function useBroadcastMutation(mutationKey = [], username, operations, onSuccess
44
494
  "[Core][Broadcast] Attempted to call broadcast API with anon user"
45
495
  );
46
496
  }
497
+ const ops2 = operations(payload);
498
+ if (auth?.enableFallback !== false && auth?.adapter) {
499
+ return broadcastWithFallback(username, ops2, auth, authority);
500
+ }
47
501
  if (auth?.broadcast) {
48
- return auth.broadcast(operations(payload), "posting");
502
+ return auth.broadcast(ops2, authority);
49
503
  }
50
504
  const postingKey = auth?.postingKey;
51
505
  if (postingKey) {
506
+ if (authority !== "posting") {
507
+ throw new Error(
508
+ `[SDK][Broadcast] Legacy auth only supports posting authority, but '${authority}' was requested. Use AuthContextV2 with an adapter for ${authority} operations.`
509
+ );
510
+ }
52
511
  const privateKey = dhive.PrivateKey.fromString(postingKey);
53
512
  return CONFIG.hiveClient.broadcast.sendOperations(
54
- operations(payload),
513
+ ops2,
55
514
  privateKey
56
515
  );
57
516
  }
58
517
  const accessToken = auth?.accessToken;
59
518
  if (accessToken) {
60
- const ops2 = operations(payload);
61
519
  const client = new hs__default.default.Client({ accessToken });
62
520
  const response = await client.broadcast(ops2);
63
521
  return response.result;
@@ -2820,100 +3278,1151 @@ function useAccountRelationsUpdate(reference, target, auth, onSuccess, onError)
2820
3278
  }
2821
3279
  });
2822
3280
  }
2823
- function useBookmarkAdd(username, code, onSuccess, onError) {
2824
- return reactQuery.useMutation({
2825
- mutationKey: ["accounts", "bookmarks", "add", username],
2826
- mutationFn: async ({ author, permlink }) => {
2827
- if (!username || !code) {
2828
- throw new Error("[SDK][Account][Bookmarks] \u2013 missing auth");
2829
- }
2830
- const fetchApi = getBoundFetch();
2831
- const response = await fetchApi(
2832
- CONFIG.privateApiHost + "/private-api/bookmarks-add",
2833
- {
2834
- method: "POST",
2835
- headers: {
2836
- "Content-Type": "application/json"
2837
- },
2838
- body: JSON.stringify({
2839
- author,
2840
- permlink,
2841
- code
2842
- })
2843
- }
2844
- );
2845
- return response.json();
2846
- },
2847
- onSuccess: () => {
2848
- onSuccess();
2849
- getQueryClient().invalidateQueries({
2850
- queryKey: ["accounts", "bookmarks", username]
2851
- });
2852
- },
2853
- onError
2854
- });
3281
+
3282
+ // src/modules/operations/builders/content.ts
3283
+ function buildVoteOp(voter, author, permlink, weight) {
3284
+ if (!voter || !author || !permlink) {
3285
+ throw new Error("[SDK][buildVoteOp] Missing required parameters");
3286
+ }
3287
+ if (weight < -1e4 || weight > 1e4) {
3288
+ throw new Error("[SDK][buildVoteOp] Weight must be between -10000 and 10000");
3289
+ }
3290
+ return [
3291
+ "vote",
3292
+ {
3293
+ voter,
3294
+ author,
3295
+ permlink,
3296
+ weight
3297
+ }
3298
+ ];
2855
3299
  }
2856
- function useBookmarkDelete(username, code, onSuccess, onError) {
2857
- return reactQuery.useMutation({
2858
- mutationKey: ["accounts", "bookmarks", "delete", username],
2859
- mutationFn: async (bookmarkId) => {
2860
- if (!username || !code) {
2861
- throw new Error("[SDK][Account][Bookmarks] \u2013 missing auth");
2862
- }
2863
- const fetchApi = getBoundFetch();
2864
- const response = await fetchApi(
2865
- CONFIG.privateApiHost + "/private-api/bookmarks-delete",
2866
- {
2867
- method: "POST",
2868
- headers: {
2869
- "Content-Type": "application/json"
2870
- },
2871
- body: JSON.stringify({
2872
- id: bookmarkId,
2873
- code
2874
- })
2875
- }
2876
- );
2877
- return response.json();
2878
- },
2879
- onSuccess: () => {
2880
- onSuccess();
2881
- getQueryClient().invalidateQueries({
2882
- queryKey: ["accounts", "bookmarks", username]
2883
- });
2884
- },
2885
- onError
2886
- });
3300
+ function buildCommentOp(author, permlink, parentAuthor, parentPermlink, title, body, jsonMetadata) {
3301
+ if (!author || !permlink || parentPermlink === void 0 || !body) {
3302
+ throw new Error("[SDK][buildCommentOp] Missing required parameters");
3303
+ }
3304
+ return [
3305
+ "comment",
3306
+ {
3307
+ parent_author: parentAuthor,
3308
+ parent_permlink: parentPermlink,
3309
+ author,
3310
+ permlink,
3311
+ title,
3312
+ body,
3313
+ json_metadata: JSON.stringify(jsonMetadata)
3314
+ }
3315
+ ];
2887
3316
  }
2888
- function useAccountFavouriteAdd(username, code, onSuccess, onError) {
2889
- return reactQuery.useMutation({
2890
- mutationKey: ["accounts", "favourites", "add", username],
2891
- mutationFn: async (account) => {
2892
- if (!username || !code) {
2893
- throw new Error("[SDK][Account][Bookmarks] \u2013 missing auth");
2894
- }
2895
- const fetchApi = getBoundFetch();
2896
- const response = await fetchApi(
2897
- CONFIG.privateApiHost + "/private-api/favorites-add",
2898
- {
2899
- method: "POST",
2900
- headers: {
2901
- "Content-Type": "application/json"
2902
- },
2903
- body: JSON.stringify({
2904
- account,
2905
- code
2906
- })
2907
- }
2908
- );
2909
- return response.json();
2910
- },
2911
- onSuccess: () => {
2912
- onSuccess();
2913
- getQueryClient().invalidateQueries({
2914
- queryKey: ["accounts", "favourites", username]
2915
- });
2916
- },
3317
+ function buildCommentOptionsOp(author, permlink, maxAcceptedPayout, percentHbd, allowVotes, allowCurationRewards, extensions) {
3318
+ if (!author || !permlink) {
3319
+ throw new Error("[SDK][buildCommentOptionsOp] Missing required parameters");
3320
+ }
3321
+ return [
3322
+ "comment_options",
3323
+ {
3324
+ author,
3325
+ permlink,
3326
+ max_accepted_payout: maxAcceptedPayout,
3327
+ percent_hbd: percentHbd,
3328
+ allow_votes: allowVotes,
3329
+ allow_curation_rewards: allowCurationRewards,
3330
+ extensions
3331
+ }
3332
+ ];
3333
+ }
3334
+ function buildDeleteCommentOp(author, permlink) {
3335
+ if (!author || !permlink) {
3336
+ throw new Error("[SDK][buildDeleteCommentOp] Missing required parameters");
3337
+ }
3338
+ return [
3339
+ "delete_comment",
3340
+ {
3341
+ author,
3342
+ permlink
3343
+ }
3344
+ ];
3345
+ }
3346
+ function buildReblogOp(account, author, permlink, deleteReblog = false) {
3347
+ if (!account || !author || !permlink) {
3348
+ throw new Error("[SDK][buildReblogOp] Missing required parameters");
3349
+ }
3350
+ const json = {
3351
+ account,
3352
+ author,
3353
+ permlink
3354
+ };
3355
+ if (deleteReblog) {
3356
+ json.delete = "delete";
3357
+ }
3358
+ return [
3359
+ "custom_json",
3360
+ {
3361
+ id: "follow",
3362
+ json: JSON.stringify(["reblog", json]),
3363
+ required_auths: [],
3364
+ required_posting_auths: [account]
3365
+ }
3366
+ ];
3367
+ }
3368
+
3369
+ // src/modules/operations/builders/wallet.ts
3370
+ function buildTransferOp(from, to, amount, memo) {
3371
+ if (!from || !to || !amount) {
3372
+ throw new Error("[SDK][buildTransferOp] Missing required parameters");
3373
+ }
3374
+ return [
3375
+ "transfer",
3376
+ {
3377
+ from,
3378
+ to,
3379
+ amount,
3380
+ memo: memo || ""
3381
+ }
3382
+ ];
3383
+ }
3384
+ function buildMultiTransferOps(from, destinations, amount, memo) {
3385
+ if (!from || !destinations || !amount) {
3386
+ throw new Error("[SDK][buildMultiTransferOps] Missing required parameters");
3387
+ }
3388
+ const destArray = destinations.trim().split(/[\s,]+/).filter(Boolean);
3389
+ return destArray.map(
3390
+ (dest) => buildTransferOp(from, dest.trim(), amount, memo)
3391
+ );
3392
+ }
3393
+ function buildRecurrentTransferOp(from, to, amount, memo, recurrence, executions) {
3394
+ if (!from || !to || !amount) {
3395
+ throw new Error("[SDK][buildRecurrentTransferOp] Missing required parameters");
3396
+ }
3397
+ if (recurrence < 24) {
3398
+ throw new Error("[SDK][buildRecurrentTransferOp] Recurrence must be at least 24 hours");
3399
+ }
3400
+ return [
3401
+ "recurrent_transfer",
3402
+ {
3403
+ from,
3404
+ to,
3405
+ amount,
3406
+ memo: memo || "",
3407
+ recurrence,
3408
+ executions,
3409
+ extensions: []
3410
+ }
3411
+ ];
3412
+ }
3413
+ function buildTransferToSavingsOp(from, to, amount, memo) {
3414
+ if (!from || !to || !amount) {
3415
+ throw new Error("[SDK][buildTransferToSavingsOp] Missing required parameters");
3416
+ }
3417
+ return [
3418
+ "transfer_to_savings",
3419
+ {
3420
+ from,
3421
+ to,
3422
+ amount,
3423
+ memo: memo || ""
3424
+ }
3425
+ ];
3426
+ }
3427
+ function buildTransferFromSavingsOp(from, to, amount, memo, requestId) {
3428
+ if (!from || !to || !amount || requestId === void 0) {
3429
+ throw new Error("[SDK][buildTransferFromSavingsOp] Missing required parameters");
3430
+ }
3431
+ return [
3432
+ "transfer_from_savings",
3433
+ {
3434
+ from,
3435
+ to,
3436
+ amount,
3437
+ memo: memo || "",
3438
+ request_id: requestId
3439
+ }
3440
+ ];
3441
+ }
3442
+ function buildCancelTransferFromSavingsOp(from, requestId) {
3443
+ if (!from || requestId === void 0) {
3444
+ throw new Error("[SDK][buildCancelTransferFromSavingsOp] Missing required parameters");
3445
+ }
3446
+ return [
3447
+ "cancel_transfer_from_savings",
3448
+ {
3449
+ from,
3450
+ request_id: requestId
3451
+ }
3452
+ ];
3453
+ }
3454
+ function buildClaimInterestOps(from, to, amount, memo, requestId) {
3455
+ if (!from || !to || !amount || requestId === void 0) {
3456
+ throw new Error("[SDK][buildClaimInterestOps] Missing required parameters");
3457
+ }
3458
+ return [
3459
+ buildTransferFromSavingsOp(from, to, amount, memo, requestId),
3460
+ buildCancelTransferFromSavingsOp(from, requestId)
3461
+ ];
3462
+ }
3463
+ function buildTransferToVestingOp(from, to, amount) {
3464
+ if (!from || !to || !amount) {
3465
+ throw new Error("[SDK][buildTransferToVestingOp] Missing required parameters");
3466
+ }
3467
+ return [
3468
+ "transfer_to_vesting",
3469
+ {
3470
+ from,
3471
+ to,
3472
+ amount
3473
+ }
3474
+ ];
3475
+ }
3476
+ function buildWithdrawVestingOp(account, vestingShares) {
3477
+ if (!account || !vestingShares) {
3478
+ throw new Error("[SDK][buildWithdrawVestingOp] Missing required parameters");
3479
+ }
3480
+ return [
3481
+ "withdraw_vesting",
3482
+ {
3483
+ account,
3484
+ vesting_shares: vestingShares
3485
+ }
3486
+ ];
3487
+ }
3488
+ function buildDelegateVestingSharesOp(delegator, delegatee, vestingShares) {
3489
+ if (!delegator || !delegatee || !vestingShares) {
3490
+ throw new Error("[SDK][buildDelegateVestingSharesOp] Missing required parameters");
3491
+ }
3492
+ return [
3493
+ "delegate_vesting_shares",
3494
+ {
3495
+ delegator,
3496
+ delegatee,
3497
+ vesting_shares: vestingShares
3498
+ }
3499
+ ];
3500
+ }
3501
+ function buildSetWithdrawVestingRouteOp(fromAccount, toAccount, percent, autoVest) {
3502
+ if (!fromAccount || !toAccount || percent === void 0) {
3503
+ throw new Error("[SDK][buildSetWithdrawVestingRouteOp] Missing required parameters");
3504
+ }
3505
+ if (percent < 0 || percent > 1e4) {
3506
+ throw new Error("[SDK][buildSetWithdrawVestingRouteOp] Percent must be between 0 and 10000");
3507
+ }
3508
+ return [
3509
+ "set_withdraw_vesting_route",
3510
+ {
3511
+ from_account: fromAccount,
3512
+ to_account: toAccount,
3513
+ percent,
3514
+ auto_vest: autoVest
3515
+ }
3516
+ ];
3517
+ }
3518
+ function buildConvertOp(owner, amount, requestId) {
3519
+ if (!owner || !amount || requestId === void 0) {
3520
+ throw new Error("[SDK][buildConvertOp] Missing required parameters");
3521
+ }
3522
+ return [
3523
+ "convert",
3524
+ {
3525
+ owner,
3526
+ amount,
3527
+ requestid: requestId
3528
+ }
3529
+ ];
3530
+ }
3531
+ function buildCollateralizedConvertOp(owner, amount, requestId) {
3532
+ if (!owner || !amount || requestId === void 0) {
3533
+ throw new Error("[SDK][buildCollateralizedConvertOp] Missing required parameters");
3534
+ }
3535
+ return [
3536
+ "collateralized_convert",
3537
+ {
3538
+ owner,
3539
+ amount,
3540
+ requestid: requestId
3541
+ }
3542
+ ];
3543
+ }
3544
+ function buildDelegateRcOp(from, delegatees, maxRc) {
3545
+ if (!from || !delegatees || maxRc === void 0) {
3546
+ throw new Error("[SDK][buildDelegateRcOp] Missing required parameters");
3547
+ }
3548
+ const delegateeArray = delegatees.includes(",") ? delegatees.split(",").map((d) => d.trim()) : [delegatees];
3549
+ return [
3550
+ "custom_json",
3551
+ {
3552
+ id: "rc",
3553
+ json: JSON.stringify([
3554
+ "delegate_rc",
3555
+ {
3556
+ from,
3557
+ delegatees: delegateeArray,
3558
+ max_rc: maxRc
3559
+ }
3560
+ ]),
3561
+ required_auths: [],
3562
+ required_posting_auths: [from]
3563
+ }
3564
+ ];
3565
+ }
3566
+
3567
+ // src/modules/operations/builders/social.ts
3568
+ function buildFollowOp(follower, following) {
3569
+ if (!follower || !following) {
3570
+ throw new Error("[SDK][buildFollowOp] Missing required parameters");
3571
+ }
3572
+ return [
3573
+ "custom_json",
3574
+ {
3575
+ id: "follow",
3576
+ json: JSON.stringify([
3577
+ "follow",
3578
+ {
3579
+ follower,
3580
+ following,
3581
+ what: ["blog"]
3582
+ }
3583
+ ]),
3584
+ required_auths: [],
3585
+ required_posting_auths: [follower]
3586
+ }
3587
+ ];
3588
+ }
3589
+ function buildUnfollowOp(follower, following) {
3590
+ if (!follower || !following) {
3591
+ throw new Error("[SDK][buildUnfollowOp] Missing required parameters");
3592
+ }
3593
+ return [
3594
+ "custom_json",
3595
+ {
3596
+ id: "follow",
3597
+ json: JSON.stringify([
3598
+ "follow",
3599
+ {
3600
+ follower,
3601
+ following,
3602
+ what: []
3603
+ }
3604
+ ]),
3605
+ required_auths: [],
3606
+ required_posting_auths: [follower]
3607
+ }
3608
+ ];
3609
+ }
3610
+ function buildIgnoreOp(follower, following) {
3611
+ if (!follower || !following) {
3612
+ throw new Error("[SDK][buildIgnoreOp] Missing required parameters");
3613
+ }
3614
+ return [
3615
+ "custom_json",
3616
+ {
3617
+ id: "follow",
3618
+ json: JSON.stringify([
3619
+ "follow",
3620
+ {
3621
+ follower,
3622
+ following,
3623
+ what: ["ignore"]
3624
+ }
3625
+ ]),
3626
+ required_auths: [],
3627
+ required_posting_auths: [follower]
3628
+ }
3629
+ ];
3630
+ }
3631
+ function buildUnignoreOp(follower, following) {
3632
+ if (!follower || !following) {
3633
+ throw new Error("[SDK][buildUnignoreOp] Missing required parameters");
3634
+ }
3635
+ return buildUnfollowOp(follower, following);
3636
+ }
3637
+ function buildSetLastReadOps(username, date) {
3638
+ if (!username) {
3639
+ throw new Error("[SDK][buildSetLastReadOps] Missing required parameters");
3640
+ }
3641
+ const lastReadDate = date || (/* @__PURE__ */ new Date()).toISOString().split(".")[0];
3642
+ const notifyOp = [
3643
+ "custom_json",
3644
+ {
3645
+ id: "notify",
3646
+ json: JSON.stringify(["setLastRead", { date: lastReadDate }]),
3647
+ required_auths: [],
3648
+ required_posting_auths: [username]
3649
+ }
3650
+ ];
3651
+ const ecencyNotifyOp = [
3652
+ "custom_json",
3653
+ {
3654
+ id: "ecency_notify",
3655
+ json: JSON.stringify(["setLastRead", { date: lastReadDate }]),
3656
+ required_auths: [],
3657
+ required_posting_auths: [username]
3658
+ }
3659
+ ];
3660
+ return [notifyOp, ecencyNotifyOp];
3661
+ }
3662
+
3663
+ // src/modules/operations/builders/governance.ts
3664
+ function buildWitnessVoteOp(account, witness, approve) {
3665
+ if (!account || !witness || approve === void 0) {
3666
+ throw new Error("[SDK][buildWitnessVoteOp] Missing required parameters");
3667
+ }
3668
+ return [
3669
+ "account_witness_vote",
3670
+ {
3671
+ account,
3672
+ witness,
3673
+ approve
3674
+ }
3675
+ ];
3676
+ }
3677
+ function buildWitnessProxyOp(account, proxy) {
3678
+ if (!account || proxy === void 0) {
3679
+ throw new Error("[SDK][buildWitnessProxyOp] Missing required parameters");
3680
+ }
3681
+ return [
3682
+ "account_witness_proxy",
3683
+ {
3684
+ account,
3685
+ proxy
3686
+ }
3687
+ ];
3688
+ }
3689
+ function buildProposalCreateOp(creator, payload) {
3690
+ if (!creator || !payload.receiver || !payload.subject || !payload.permlink || !payload.start || !payload.end || !payload.dailyPay) {
3691
+ throw new Error("[SDK][buildProposalCreateOp] Missing required parameters");
3692
+ }
3693
+ const startDate = new Date(payload.start);
3694
+ const endDate = new Date(payload.end);
3695
+ if (startDate.toString() === "Invalid Date" || endDate.toString() === "Invalid Date") {
3696
+ throw new Error(
3697
+ "[SDK][buildProposalCreateOp] Invalid date format: start and end must be valid ISO date strings"
3698
+ );
3699
+ }
3700
+ return [
3701
+ "create_proposal",
3702
+ {
3703
+ creator,
3704
+ receiver: payload.receiver,
3705
+ start_date: payload.start,
3706
+ end_date: payload.end,
3707
+ daily_pay: payload.dailyPay,
3708
+ subject: payload.subject,
3709
+ permlink: payload.permlink,
3710
+ extensions: []
3711
+ }
3712
+ ];
3713
+ }
3714
+ function buildProposalVoteOp(voter, proposalIds, approve) {
3715
+ if (!voter || !proposalIds || proposalIds.length === 0 || approve === void 0) {
3716
+ throw new Error("[SDK][buildProposalVoteOp] Missing required parameters");
3717
+ }
3718
+ return [
3719
+ "update_proposal_votes",
3720
+ {
3721
+ voter,
3722
+ proposal_ids: proposalIds,
3723
+ approve,
3724
+ extensions: []
3725
+ }
3726
+ ];
3727
+ }
3728
+ function buildRemoveProposalOp(proposalOwner, proposalIds) {
3729
+ if (!proposalOwner || !proposalIds || proposalIds.length === 0) {
3730
+ throw new Error("[SDK][buildRemoveProposalOp] Missing required parameters");
3731
+ }
3732
+ return [
3733
+ "remove_proposal",
3734
+ {
3735
+ proposal_owner: proposalOwner,
3736
+ proposal_ids: proposalIds,
3737
+ extensions: []
3738
+ }
3739
+ ];
3740
+ }
3741
+ function buildUpdateProposalOp(proposalId, creator, dailyPay, subject, permlink) {
3742
+ if (proposalId === void 0 || proposalId === null || typeof proposalId !== "number" || !creator || !dailyPay || !subject || !permlink) {
3743
+ throw new Error("[SDK][buildUpdateProposalOp] Missing required parameters");
3744
+ }
3745
+ return [
3746
+ "update_proposal",
3747
+ {
3748
+ proposal_id: proposalId,
3749
+ creator,
3750
+ daily_pay: dailyPay,
3751
+ subject,
3752
+ permlink,
3753
+ extensions: []
3754
+ }
3755
+ ];
3756
+ }
3757
+
3758
+ // src/modules/operations/builders/community.ts
3759
+ function buildSubscribeOp(username, community) {
3760
+ if (!username || !community) {
3761
+ throw new Error("[SDK][buildSubscribeOp] Missing required parameters");
3762
+ }
3763
+ return [
3764
+ "custom_json",
3765
+ {
3766
+ id: "community",
3767
+ json: JSON.stringify(["subscribe", { community }]),
3768
+ required_auths: [],
3769
+ required_posting_auths: [username]
3770
+ }
3771
+ ];
3772
+ }
3773
+ function buildUnsubscribeOp(username, community) {
3774
+ if (!username || !community) {
3775
+ throw new Error("[SDK][buildUnsubscribeOp] Missing required parameters");
3776
+ }
3777
+ return [
3778
+ "custom_json",
3779
+ {
3780
+ id: "community",
3781
+ json: JSON.stringify(["unsubscribe", { community }]),
3782
+ required_auths: [],
3783
+ required_posting_auths: [username]
3784
+ }
3785
+ ];
3786
+ }
3787
+ function buildSetRoleOp(username, community, account, role) {
3788
+ if (!username || !community || !account || !role) {
3789
+ throw new Error("[SDK][buildSetRoleOp] Missing required parameters");
3790
+ }
3791
+ return [
3792
+ "custom_json",
3793
+ {
3794
+ id: "community",
3795
+ json: JSON.stringify(["setRole", { community, account, role }]),
3796
+ required_auths: [],
3797
+ required_posting_auths: [username]
3798
+ }
3799
+ ];
3800
+ }
3801
+ function buildUpdateCommunityOp(username, community, props) {
3802
+ if (!username || !community || !props) {
3803
+ throw new Error("[SDK][buildUpdateCommunityOp] Missing required parameters");
3804
+ }
3805
+ return [
3806
+ "custom_json",
3807
+ {
3808
+ id: "community",
3809
+ json: JSON.stringify(["updateProps", { community, props }]),
3810
+ required_auths: [],
3811
+ required_posting_auths: [username]
3812
+ }
3813
+ ];
3814
+ }
3815
+ function buildPinPostOp(username, community, account, permlink, pin) {
3816
+ if (!username || !community || !account || !permlink || pin === void 0) {
3817
+ throw new Error("[SDK][buildPinPostOp] Missing required parameters");
3818
+ }
3819
+ const action = pin ? "pinPost" : "unpinPost";
3820
+ return [
3821
+ "custom_json",
3822
+ {
3823
+ id: "community",
3824
+ json: JSON.stringify([action, { community, account, permlink }]),
3825
+ required_auths: [],
3826
+ required_posting_auths: [username]
3827
+ }
3828
+ ];
3829
+ }
3830
+ function buildMutePostOp(username, community, account, permlink, notes, mute) {
3831
+ if (!username || !community || !account || !permlink || mute === void 0) {
3832
+ throw new Error("[SDK][buildMutePostOp] Missing required parameters");
3833
+ }
3834
+ const action = mute ? "mutePost" : "unmutePost";
3835
+ return [
3836
+ "custom_json",
3837
+ {
3838
+ id: "community",
3839
+ json: JSON.stringify([action, { community, account, permlink, notes }]),
3840
+ required_auths: [],
3841
+ required_posting_auths: [username]
3842
+ }
3843
+ ];
3844
+ }
3845
+ function buildMuteUserOp(username, community, account, notes, mute) {
3846
+ if (!username || !community || !account || mute === void 0) {
3847
+ throw new Error("[SDK][buildMuteUserOp] Missing required parameters");
3848
+ }
3849
+ const action = mute ? "muteUser" : "unmuteUser";
3850
+ return [
3851
+ "custom_json",
3852
+ {
3853
+ id: "community",
3854
+ json: JSON.stringify([action, { community, account, notes }]),
3855
+ required_auths: [],
3856
+ required_posting_auths: [username]
3857
+ }
3858
+ ];
3859
+ }
3860
+ function buildFlagPostOp(username, community, account, permlink, notes) {
3861
+ if (!username || !community || !account || !permlink) {
3862
+ throw new Error("[SDK][buildFlagPostOp] Missing required parameters");
3863
+ }
3864
+ return [
3865
+ "custom_json",
3866
+ {
3867
+ id: "community",
3868
+ json: JSON.stringify(["flagPost", { community, account, permlink, notes }]),
3869
+ required_auths: [],
3870
+ required_posting_auths: [username]
3871
+ }
3872
+ ];
3873
+ }
3874
+
3875
+ // src/modules/operations/builders/market.ts
3876
+ var BuySellTransactionType = /* @__PURE__ */ ((BuySellTransactionType2) => {
3877
+ BuySellTransactionType2["Buy"] = "buy";
3878
+ BuySellTransactionType2["Sell"] = "sell";
3879
+ return BuySellTransactionType2;
3880
+ })(BuySellTransactionType || {});
3881
+ var OrderIdPrefix = /* @__PURE__ */ ((OrderIdPrefix2) => {
3882
+ OrderIdPrefix2["EMPTY"] = "";
3883
+ OrderIdPrefix2["SWAP"] = "9";
3884
+ return OrderIdPrefix2;
3885
+ })(OrderIdPrefix || {});
3886
+ function buildLimitOrderCreateOp(owner, amountToSell, minToReceive, fillOrKill, expiration, orderId) {
3887
+ if (!owner || !amountToSell || !minToReceive || !expiration || orderId === void 0) {
3888
+ throw new Error("[SDK][buildLimitOrderCreateOp] Missing required parameters");
3889
+ }
3890
+ return [
3891
+ "limit_order_create",
3892
+ {
3893
+ owner,
3894
+ orderid: orderId,
3895
+ amount_to_sell: amountToSell,
3896
+ min_to_receive: minToReceive,
3897
+ fill_or_kill: fillOrKill,
3898
+ expiration
3899
+ }
3900
+ ];
3901
+ }
3902
+ function formatNumber(value, decimals = 3) {
3903
+ return value.toFixed(decimals);
3904
+ }
3905
+ function buildLimitOrderCreateOpWithType(owner, amountToSell, minToReceive, orderType, idPrefix = "" /* EMPTY */) {
3906
+ if (!owner || orderType === void 0 || !Number.isFinite(amountToSell) || amountToSell <= 0 || !Number.isFinite(minToReceive) || minToReceive <= 0) {
3907
+ throw new Error("[SDK][buildLimitOrderCreateOpWithType] Missing or invalid parameters");
3908
+ }
3909
+ const expiration = new Date(Date.now());
3910
+ expiration.setDate(expiration.getDate() + 27);
3911
+ const expirationStr = expiration.toISOString().split(".")[0];
3912
+ const orderId = Number(
3913
+ `${idPrefix}${Math.floor(Date.now() / 1e3).toString().slice(2)}`
3914
+ );
3915
+ const formattedAmountToSell = orderType === "buy" /* Buy */ ? `${formatNumber(amountToSell, 3)} HBD` : `${formatNumber(amountToSell, 3)} HIVE`;
3916
+ const formattedMinToReceive = orderType === "buy" /* Buy */ ? `${formatNumber(minToReceive, 3)} HIVE` : `${formatNumber(minToReceive, 3)} HBD`;
3917
+ return buildLimitOrderCreateOp(
3918
+ owner,
3919
+ formattedAmountToSell,
3920
+ formattedMinToReceive,
3921
+ false,
3922
+ expirationStr,
3923
+ orderId
3924
+ );
3925
+ }
3926
+ function buildLimitOrderCancelOp(owner, orderId) {
3927
+ if (!owner || orderId === void 0) {
3928
+ throw new Error("[SDK][buildLimitOrderCancelOp] Missing required parameters");
3929
+ }
3930
+ return [
3931
+ "limit_order_cancel",
3932
+ {
3933
+ owner,
3934
+ orderid: orderId
3935
+ }
3936
+ ];
3937
+ }
3938
+ function buildClaimRewardBalanceOp(account, rewardHive, rewardHbd, rewardVests) {
3939
+ if (!account || !rewardHive || !rewardHbd || !rewardVests) {
3940
+ throw new Error("[SDK][buildClaimRewardBalanceOp] Missing required parameters");
3941
+ }
3942
+ return [
3943
+ "claim_reward_balance",
3944
+ {
3945
+ account,
3946
+ reward_hive: rewardHive,
3947
+ reward_hbd: rewardHbd,
3948
+ reward_vests: rewardVests
3949
+ }
3950
+ ];
3951
+ }
3952
+
3953
+ // src/modules/operations/builders/account.ts
3954
+ function buildAccountUpdateOp(account, owner, active, posting, memoKey, jsonMetadata) {
3955
+ if (!account || !memoKey) {
3956
+ throw new Error("[SDK][buildAccountUpdateOp] Missing required parameters");
3957
+ }
3958
+ return [
3959
+ "account_update",
3960
+ {
3961
+ account,
3962
+ owner,
3963
+ active,
3964
+ posting,
3965
+ memo_key: memoKey,
3966
+ json_metadata: jsonMetadata
3967
+ }
3968
+ ];
3969
+ }
3970
+ function buildAccountUpdate2Op(account, jsonMetadata, postingJsonMetadata, extensions) {
3971
+ if (!account || postingJsonMetadata === void 0) {
3972
+ throw new Error("[SDK][buildAccountUpdate2Op] Missing required parameters");
3973
+ }
3974
+ return [
3975
+ "account_update2",
3976
+ {
3977
+ account,
3978
+ json_metadata: jsonMetadata || "",
3979
+ posting_json_metadata: postingJsonMetadata,
3980
+ extensions: extensions || []
3981
+ }
3982
+ ];
3983
+ }
3984
+ function buildAccountCreateOp(creator, newAccountName, keys, fee) {
3985
+ if (!creator || !newAccountName || !keys || !fee) {
3986
+ throw new Error("[SDK][buildAccountCreateOp] Missing required parameters");
3987
+ }
3988
+ const owner = {
3989
+ weight_threshold: 1,
3990
+ account_auths: [],
3991
+ key_auths: [[keys.ownerPublicKey, 1]]
3992
+ };
3993
+ const active = {
3994
+ weight_threshold: 1,
3995
+ account_auths: [],
3996
+ key_auths: [[keys.activePublicKey, 1]]
3997
+ };
3998
+ const posting = {
3999
+ weight_threshold: 1,
4000
+ account_auths: [["ecency.app", 1]],
4001
+ key_auths: [[keys.postingPublicKey, 1]]
4002
+ };
4003
+ return [
4004
+ "account_create",
4005
+ {
4006
+ creator,
4007
+ new_account_name: newAccountName,
4008
+ owner,
4009
+ active,
4010
+ posting,
4011
+ memo_key: keys.memoPublicKey,
4012
+ json_metadata: "",
4013
+ extensions: [],
4014
+ fee
4015
+ }
4016
+ ];
4017
+ }
4018
+ function buildCreateClaimedAccountOp(creator, newAccountName, keys) {
4019
+ if (!creator || !newAccountName || !keys) {
4020
+ throw new Error("[SDK][buildCreateClaimedAccountOp] Missing required parameters");
4021
+ }
4022
+ const owner = {
4023
+ weight_threshold: 1,
4024
+ account_auths: [],
4025
+ key_auths: [[keys.ownerPublicKey, 1]]
4026
+ };
4027
+ const active = {
4028
+ weight_threshold: 1,
4029
+ account_auths: [],
4030
+ key_auths: [[keys.activePublicKey, 1]]
4031
+ };
4032
+ const posting = {
4033
+ weight_threshold: 1,
4034
+ account_auths: [["ecency.app", 1]],
4035
+ key_auths: [[keys.postingPublicKey, 1]]
4036
+ };
4037
+ return [
4038
+ "create_claimed_account",
4039
+ {
4040
+ creator,
4041
+ new_account_name: newAccountName,
4042
+ owner,
4043
+ active,
4044
+ posting,
4045
+ memo_key: keys.memoPublicKey,
4046
+ json_metadata: "",
4047
+ extensions: []
4048
+ }
4049
+ ];
4050
+ }
4051
+ function buildClaimAccountOp(creator, fee) {
4052
+ if (!creator || !fee) {
4053
+ throw new Error("[SDK][buildClaimAccountOp] Missing required parameters");
4054
+ }
4055
+ return [
4056
+ "claim_account",
4057
+ {
4058
+ creator,
4059
+ fee,
4060
+ extensions: []
4061
+ }
4062
+ ];
4063
+ }
4064
+ function buildGrantPostingPermissionOp(account, currentPosting, grantedAccount, weightThreshold, memoKey, jsonMetadata) {
4065
+ if (!account || !currentPosting || !grantedAccount || !memoKey) {
4066
+ throw new Error("[SDK][buildGrantPostingPermissionOp] Missing required parameters");
4067
+ }
4068
+ const existingIndex = currentPosting.account_auths.findIndex(
4069
+ ([acc]) => acc === grantedAccount
4070
+ );
4071
+ const newAccountAuths = [...currentPosting.account_auths];
4072
+ if (existingIndex >= 0) {
4073
+ newAccountAuths[existingIndex] = [grantedAccount, weightThreshold];
4074
+ } else {
4075
+ newAccountAuths.push([grantedAccount, weightThreshold]);
4076
+ }
4077
+ const newPosting = {
4078
+ ...currentPosting,
4079
+ account_auths: newAccountAuths
4080
+ };
4081
+ newPosting.account_auths.sort((a, b) => a[0] > b[0] ? 1 : -1);
4082
+ return [
4083
+ "account_update",
4084
+ {
4085
+ account,
4086
+ posting: newPosting,
4087
+ memo_key: memoKey,
4088
+ json_metadata: jsonMetadata
4089
+ }
4090
+ ];
4091
+ }
4092
+ function buildRevokePostingPermissionOp(account, currentPosting, revokedAccount, memoKey, jsonMetadata) {
4093
+ if (!account || !currentPosting || !revokedAccount || !memoKey) {
4094
+ throw new Error("[SDK][buildRevokePostingPermissionOp] Missing required parameters");
4095
+ }
4096
+ const newPosting = {
4097
+ ...currentPosting,
4098
+ account_auths: currentPosting.account_auths.filter(
4099
+ ([acc]) => acc !== revokedAccount
4100
+ )
4101
+ };
4102
+ return [
4103
+ "account_update",
4104
+ {
4105
+ account,
4106
+ posting: newPosting,
4107
+ memo_key: memoKey,
4108
+ json_metadata: jsonMetadata
4109
+ }
4110
+ ];
4111
+ }
4112
+ function buildChangeRecoveryAccountOp(accountToRecover, newRecoveryAccount, extensions = []) {
4113
+ if (!accountToRecover || !newRecoveryAccount) {
4114
+ throw new Error("[SDK][buildChangeRecoveryAccountOp] Missing required parameters");
4115
+ }
4116
+ return [
4117
+ "change_recovery_account",
4118
+ {
4119
+ account_to_recover: accountToRecover,
4120
+ new_recovery_account: newRecoveryAccount,
4121
+ extensions
4122
+ }
4123
+ ];
4124
+ }
4125
+ function buildRequestAccountRecoveryOp(recoveryAccount, accountToRecover, newOwnerAuthority, extensions = []) {
4126
+ if (!recoveryAccount || !accountToRecover || !newOwnerAuthority) {
4127
+ throw new Error("[SDK][buildRequestAccountRecoveryOp] Missing required parameters");
4128
+ }
4129
+ return [
4130
+ "request_account_recovery",
4131
+ {
4132
+ recovery_account: recoveryAccount,
4133
+ account_to_recover: accountToRecover,
4134
+ new_owner_authority: newOwnerAuthority,
4135
+ extensions
4136
+ }
4137
+ ];
4138
+ }
4139
+ function buildRecoverAccountOp(accountToRecover, newOwnerAuthority, recentOwnerAuthority, extensions = []) {
4140
+ if (!accountToRecover || !newOwnerAuthority || !recentOwnerAuthority) {
4141
+ throw new Error("[SDK][buildRecoverAccountOp] Missing required parameters");
4142
+ }
4143
+ return [
4144
+ "recover_account",
4145
+ {
4146
+ account_to_recover: accountToRecover,
4147
+ new_owner_authority: newOwnerAuthority,
4148
+ recent_owner_authority: recentOwnerAuthority,
4149
+ extensions
4150
+ }
4151
+ ];
4152
+ }
4153
+
4154
+ // src/modules/operations/builders/ecency.ts
4155
+ function buildBoostOp(user, author, permlink, amount) {
4156
+ if (!user || !author || !permlink || !amount) {
4157
+ throw new Error("[SDK][buildBoostOp] Missing required parameters");
4158
+ }
4159
+ return [
4160
+ "custom_json",
4161
+ {
4162
+ id: "ecency_boost",
4163
+ json: JSON.stringify({
4164
+ user,
4165
+ author,
4166
+ permlink,
4167
+ amount
4168
+ }),
4169
+ required_auths: [user],
4170
+ required_posting_auths: []
4171
+ }
4172
+ ];
4173
+ }
4174
+ function buildBoostOpWithPoints(user, author, permlink, points) {
4175
+ if (!user || !author || !permlink || !Number.isFinite(points)) {
4176
+ throw new Error("[SDK][buildBoostOpWithPoints] Missing required parameters");
4177
+ }
4178
+ return buildBoostOp(user, author, permlink, `${points.toFixed(3)} POINT`);
4179
+ }
4180
+ function buildBoostPlusOp(user, account, duration) {
4181
+ if (!user || !account || !Number.isFinite(duration)) {
4182
+ throw new Error("[SDK][buildBoostPlusOp] Missing required parameters");
4183
+ }
4184
+ return [
4185
+ "custom_json",
4186
+ {
4187
+ id: "ecency_boost_plus",
4188
+ json: JSON.stringify({
4189
+ user,
4190
+ account,
4191
+ duration
4192
+ }),
4193
+ required_auths: [user],
4194
+ required_posting_auths: []
4195
+ }
4196
+ ];
4197
+ }
4198
+ function buildPromoteOp(user, author, permlink, duration) {
4199
+ if (!user || !author || !permlink || !Number.isFinite(duration)) {
4200
+ throw new Error("[SDK][buildPromoteOp] Missing required parameters");
4201
+ }
4202
+ return [
4203
+ "custom_json",
4204
+ {
4205
+ id: "ecency_promote",
4206
+ json: JSON.stringify({
4207
+ user,
4208
+ author,
4209
+ permlink,
4210
+ duration
4211
+ }),
4212
+ required_auths: [user],
4213
+ required_posting_auths: []
4214
+ }
4215
+ ];
4216
+ }
4217
+ function buildPointTransferOp(sender, receiver, amount, memo) {
4218
+ if (!sender || !receiver || !amount) {
4219
+ throw new Error("[SDK][buildPointTransferOp] Missing required parameters");
4220
+ }
4221
+ return [
4222
+ "custom_json",
4223
+ {
4224
+ id: "ecency_point_transfer",
4225
+ json: JSON.stringify({
4226
+ sender,
4227
+ receiver,
4228
+ amount,
4229
+ memo: memo || ""
4230
+ }),
4231
+ required_auths: [sender],
4232
+ required_posting_auths: []
4233
+ }
4234
+ ];
4235
+ }
4236
+ function buildMultiPointTransferOps(sender, destinations, amount, memo) {
4237
+ if (!sender || !destinations || !amount) {
4238
+ throw new Error("[SDK][buildMultiPointTransferOps] Missing required parameters");
4239
+ }
4240
+ const destArray = destinations.trim().split(/[\s,]+/).filter(Boolean);
4241
+ if (destArray.length === 0) {
4242
+ throw new Error("[SDK][buildMultiPointTransferOps] Missing valid destinations");
4243
+ }
4244
+ return destArray.map(
4245
+ (dest) => buildPointTransferOp(sender, dest.trim(), amount, memo)
4246
+ );
4247
+ }
4248
+ function buildCommunityRegistrationOp(name) {
4249
+ if (!name) {
4250
+ throw new Error("[SDK][buildCommunityRegistrationOp] Missing required parameters");
4251
+ }
4252
+ return [
4253
+ "custom_json",
4254
+ {
4255
+ id: "ecency_registration",
4256
+ json: JSON.stringify({
4257
+ name
4258
+ }),
4259
+ required_auths: [name],
4260
+ required_posting_auths: []
4261
+ }
4262
+ ];
4263
+ }
4264
+ function buildActiveCustomJsonOp(username, operationId, json) {
4265
+ if (!username || !operationId || !json) {
4266
+ throw new Error("[SDK][buildActiveCustomJsonOp] Missing required parameters");
4267
+ }
4268
+ return [
4269
+ "custom_json",
4270
+ {
4271
+ id: operationId,
4272
+ json: JSON.stringify(json),
4273
+ required_auths: [username],
4274
+ required_posting_auths: []
4275
+ }
4276
+ ];
4277
+ }
4278
+ function buildPostingCustomJsonOp(username, operationId, json) {
4279
+ if (!username || !operationId || !json) {
4280
+ throw new Error("[SDK][buildPostingCustomJsonOp] Missing required parameters");
4281
+ }
4282
+ return [
4283
+ "custom_json",
4284
+ {
4285
+ id: operationId,
4286
+ json: JSON.stringify(json),
4287
+ required_auths: [],
4288
+ required_posting_auths: [username]
4289
+ }
4290
+ ];
4291
+ }
4292
+
4293
+ // src/modules/accounts/mutations/use-follow.ts
4294
+ function useFollow(username, auth) {
4295
+ return useBroadcastMutation(
4296
+ ["accounts", "follow"],
4297
+ username,
4298
+ ({ following }) => [
4299
+ buildFollowOp(username, following)
4300
+ ],
4301
+ async (_result, variables) => {
4302
+ if (auth?.adapter?.invalidateQueries) {
4303
+ await auth.adapter.invalidateQueries([
4304
+ ["accounts", "relations", username, variables.following],
4305
+ ["accounts", "full", variables.following]
4306
+ ]);
4307
+ }
4308
+ },
4309
+ auth
4310
+ );
4311
+ }
4312
+
4313
+ // src/modules/accounts/mutations/use-unfollow.ts
4314
+ function useUnfollow(username, auth) {
4315
+ return useBroadcastMutation(
4316
+ ["accounts", "unfollow"],
4317
+ username,
4318
+ ({ following }) => [
4319
+ buildUnfollowOp(username, following)
4320
+ ],
4321
+ async (_result, variables) => {
4322
+ if (auth?.adapter?.invalidateQueries) {
4323
+ await auth.adapter.invalidateQueries([
4324
+ ["accounts", "relations", username, variables.following],
4325
+ ["accounts", "full", variables.following]
4326
+ ]);
4327
+ }
4328
+ },
4329
+ auth
4330
+ );
4331
+ }
4332
+ function useBookmarkAdd(username, code, onSuccess, onError) {
4333
+ return reactQuery.useMutation({
4334
+ mutationKey: ["accounts", "bookmarks", "add", username],
4335
+ mutationFn: async ({ author, permlink }) => {
4336
+ if (!username || !code) {
4337
+ throw new Error("[SDK][Account][Bookmarks] \u2013 missing auth");
4338
+ }
4339
+ const fetchApi = getBoundFetch();
4340
+ const response = await fetchApi(
4341
+ CONFIG.privateApiHost + "/private-api/bookmarks-add",
4342
+ {
4343
+ method: "POST",
4344
+ headers: {
4345
+ "Content-Type": "application/json"
4346
+ },
4347
+ body: JSON.stringify({
4348
+ author,
4349
+ permlink,
4350
+ code
4351
+ })
4352
+ }
4353
+ );
4354
+ return response.json();
4355
+ },
4356
+ onSuccess: () => {
4357
+ onSuccess();
4358
+ getQueryClient().invalidateQueries({
4359
+ queryKey: ["accounts", "bookmarks", username]
4360
+ });
4361
+ },
4362
+ onError
4363
+ });
4364
+ }
4365
+ function useBookmarkDelete(username, code, onSuccess, onError) {
4366
+ return reactQuery.useMutation({
4367
+ mutationKey: ["accounts", "bookmarks", "delete", username],
4368
+ mutationFn: async (bookmarkId) => {
4369
+ if (!username || !code) {
4370
+ throw new Error("[SDK][Account][Bookmarks] \u2013 missing auth");
4371
+ }
4372
+ const fetchApi = getBoundFetch();
4373
+ const response = await fetchApi(
4374
+ CONFIG.privateApiHost + "/private-api/bookmarks-delete",
4375
+ {
4376
+ method: "POST",
4377
+ headers: {
4378
+ "Content-Type": "application/json"
4379
+ },
4380
+ body: JSON.stringify({
4381
+ id: bookmarkId,
4382
+ code
4383
+ })
4384
+ }
4385
+ );
4386
+ return response.json();
4387
+ },
4388
+ onSuccess: () => {
4389
+ onSuccess();
4390
+ getQueryClient().invalidateQueries({
4391
+ queryKey: ["accounts", "bookmarks", username]
4392
+ });
4393
+ },
4394
+ onError
4395
+ });
4396
+ }
4397
+ function useAccountFavouriteAdd(username, code, onSuccess, onError) {
4398
+ return reactQuery.useMutation({
4399
+ mutationKey: ["accounts", "favourites", "add", username],
4400
+ mutationFn: async (account) => {
4401
+ if (!username || !code) {
4402
+ throw new Error("[SDK][Account][Bookmarks] \u2013 missing auth");
4403
+ }
4404
+ const fetchApi = getBoundFetch();
4405
+ const response = await fetchApi(
4406
+ CONFIG.privateApiHost + "/private-api/favorites-add",
4407
+ {
4408
+ method: "POST",
4409
+ headers: {
4410
+ "Content-Type": "application/json"
4411
+ },
4412
+ body: JSON.stringify({
4413
+ account,
4414
+ code
4415
+ })
4416
+ }
4417
+ );
4418
+ return response.json();
4419
+ },
4420
+ onSuccess: () => {
4421
+ onSuccess();
4422
+ getQueryClient().invalidateQueries({
4423
+ queryKey: ["accounts", "favourites", username]
4424
+ });
4425
+ },
2917
4426
  onError
2918
4427
  });
2919
4428
  }
@@ -3346,6 +4855,94 @@ function votingValue(account, dynamicProps, votingPowerValue, weight = 1e4) {
3346
4855
  }
3347
4856
  return rShares / fundRecentClaims * fundRewardBalance * (base / quote);
3348
4857
  }
4858
+
4859
+ // src/modules/operations/authority-map.ts
4860
+ var OPERATION_AUTHORITY_MAP = {
4861
+ // Posting authority operations
4862
+ vote: "posting",
4863
+ comment: "posting",
4864
+ delete_comment: "posting",
4865
+ comment_options: "posting",
4866
+ claim_reward_balance: "posting",
4867
+ // Active authority operations - Financial
4868
+ cancel_transfer_from_savings: "active",
4869
+ collateralized_convert: "active",
4870
+ convert: "active",
4871
+ delegate_vesting_shares: "active",
4872
+ recurrent_transfer: "active",
4873
+ set_withdraw_vesting_route: "active",
4874
+ transfer: "active",
4875
+ transfer_from_savings: "active",
4876
+ transfer_to_savings: "active",
4877
+ transfer_to_vesting: "active",
4878
+ withdraw_vesting: "active",
4879
+ // Active authority operations - Market
4880
+ limit_order_create: "active",
4881
+ limit_order_cancel: "active",
4882
+ // Active authority operations - Account Management
4883
+ account_update: "active",
4884
+ account_update2: "active",
4885
+ create_claimed_account: "active",
4886
+ // Active authority operations - Governance
4887
+ account_witness_proxy: "active",
4888
+ account_witness_vote: "active",
4889
+ remove_proposal: "active",
4890
+ update_proposal_votes: "active",
4891
+ // Owner authority operations - Security & Account Recovery
4892
+ change_recovery_account: "owner",
4893
+ request_account_recovery: "owner",
4894
+ recover_account: "owner",
4895
+ reset_account: "owner",
4896
+ set_reset_account: "owner"
4897
+ // Note: Some operations are handled separately via content inspection:
4898
+ // - custom_json: via getCustomJsonAuthority() - posting or active based on required_auths
4899
+ // - create_proposal/update_proposal: via getProposalAuthority() - typically active
4900
+ };
4901
+ function getCustomJsonAuthority(customJsonOp) {
4902
+ const opType = customJsonOp[0];
4903
+ const payload = customJsonOp[1];
4904
+ if (opType !== "custom_json") {
4905
+ throw new Error("Operation is not a custom_json operation");
4906
+ }
4907
+ const customJson = payload;
4908
+ if (customJson.required_auths && customJson.required_auths.length > 0) {
4909
+ return "active";
4910
+ }
4911
+ if (customJson.required_posting_auths && customJson.required_posting_auths.length > 0) {
4912
+ return "posting";
4913
+ }
4914
+ return "posting";
4915
+ }
4916
+ function getProposalAuthority(proposalOp) {
4917
+ const opType = proposalOp[0];
4918
+ if (opType !== "create_proposal" && opType !== "update_proposal") {
4919
+ throw new Error("Operation is not a proposal operation");
4920
+ }
4921
+ return "active";
4922
+ }
4923
+ function getOperationAuthority(op) {
4924
+ const opType = op[0];
4925
+ if (opType === "custom_json") {
4926
+ return getCustomJsonAuthority(op);
4927
+ }
4928
+ if (opType === "create_proposal" || opType === "update_proposal") {
4929
+ return getProposalAuthority(op);
4930
+ }
4931
+ return OPERATION_AUTHORITY_MAP[opType] ?? "posting";
4932
+ }
4933
+ function getRequiredAuthority(ops2) {
4934
+ let highestAuthority = "posting";
4935
+ for (const op of ops2) {
4936
+ const authority = getOperationAuthority(op);
4937
+ if (authority === "owner") {
4938
+ return "owner";
4939
+ }
4940
+ if (authority === "active" && highestAuthority === "posting") {
4941
+ highestAuthority = "active";
4942
+ }
4943
+ }
4944
+ return highestAuthority;
4945
+ }
3349
4946
  function useSignOperationByKey(username) {
3350
4947
  return reactQuery.useMutation({
3351
4948
  mutationKey: ["operations", "sign", username],
@@ -4023,6 +5620,138 @@ function useUploadImage(onSuccess, onError) {
4023
5620
  });
4024
5621
  }
4025
5622
 
5623
+ // src/modules/posts/mutations/use-vote.ts
5624
+ function useVote(username, auth) {
5625
+ return useBroadcastMutation(
5626
+ ["posts", "vote"],
5627
+ username,
5628
+ ({ author, permlink, weight }) => [
5629
+ buildVoteOp(username, author, permlink, weight)
5630
+ ],
5631
+ async (result, variables) => {
5632
+ if (auth?.adapter?.recordActivity && result?.block_num && result?.id) {
5633
+ await auth.adapter.recordActivity(120, result.block_num, result.id);
5634
+ }
5635
+ if (auth?.adapter?.invalidateQueries) {
5636
+ await auth.adapter.invalidateQueries([
5637
+ ["posts", "entry", `/@${variables.author}/${variables.permlink}`],
5638
+ ["account", username, "votingPower"]
5639
+ ]);
5640
+ }
5641
+ },
5642
+ auth
5643
+ );
5644
+ }
5645
+
5646
+ // src/modules/posts/mutations/use-reblog.ts
5647
+ function useReblog(username, auth) {
5648
+ return useBroadcastMutation(
5649
+ ["posts", "reblog"],
5650
+ username,
5651
+ ({ author, permlink, deleteReblog }) => [
5652
+ buildReblogOp(username, author, permlink, deleteReblog ?? false)
5653
+ ],
5654
+ async (result, variables) => {
5655
+ if (auth?.adapter?.recordActivity && result?.block_num && result?.id) {
5656
+ await auth.adapter.recordActivity(130, result.block_num, result.id);
5657
+ }
5658
+ if (auth?.adapter?.invalidateQueries) {
5659
+ await auth.adapter.invalidateQueries([
5660
+ ["posts", "blog", username],
5661
+ ["posts", "entry", `/@${variables.author}/${variables.permlink}`]
5662
+ ]);
5663
+ }
5664
+ },
5665
+ auth
5666
+ );
5667
+ }
5668
+
5669
+ // src/modules/posts/mutations/use-comment.ts
5670
+ function useComment(username, auth) {
5671
+ return useBroadcastMutation(
5672
+ ["posts", "comment"],
5673
+ username,
5674
+ (payload) => {
5675
+ const operations = [];
5676
+ operations.push(
5677
+ buildCommentOp(
5678
+ payload.author,
5679
+ payload.permlink,
5680
+ payload.parentAuthor,
5681
+ payload.parentPermlink,
5682
+ payload.title,
5683
+ payload.body,
5684
+ payload.jsonMetadata
5685
+ )
5686
+ );
5687
+ if (payload.options) {
5688
+ const {
5689
+ maxAcceptedPayout = "1000000.000 HBD",
5690
+ percentHbd = 1e4,
5691
+ allowVotes = true,
5692
+ allowCurationRewards = true,
5693
+ beneficiaries = []
5694
+ } = payload.options;
5695
+ const extensions = [];
5696
+ if (beneficiaries.length > 0) {
5697
+ const sortedBeneficiaries = [...beneficiaries].sort(
5698
+ (a, b) => a.account.localeCompare(b.account)
5699
+ );
5700
+ extensions.push([
5701
+ 0,
5702
+ {
5703
+ beneficiaries: sortedBeneficiaries.map((b) => ({
5704
+ account: b.account,
5705
+ weight: b.weight
5706
+ }))
5707
+ }
5708
+ ]);
5709
+ }
5710
+ operations.push(
5711
+ buildCommentOptionsOp(
5712
+ payload.author,
5713
+ payload.permlink,
5714
+ maxAcceptedPayout,
5715
+ percentHbd,
5716
+ allowVotes,
5717
+ allowCurationRewards,
5718
+ extensions
5719
+ )
5720
+ );
5721
+ }
5722
+ return operations;
5723
+ },
5724
+ async (result, variables) => {
5725
+ const isPost = !variables.parentAuthor;
5726
+ const activityType = isPost ? 100 : 110;
5727
+ if (auth?.adapter?.recordActivity && result?.block_num && result?.id) {
5728
+ try {
5729
+ await auth.adapter.recordActivity(activityType, result.block_num, result.id);
5730
+ } catch (err) {
5731
+ console.warn("[useComment] Failed to record activity:", err);
5732
+ }
5733
+ }
5734
+ if (auth?.adapter?.invalidateQueries) {
5735
+ const queriesToInvalidate = [
5736
+ ["posts", "feed", username],
5737
+ ["posts", "blog", username],
5738
+ ["account", username, "rc"]
5739
+ // RC decreases after posting/commenting
5740
+ ];
5741
+ if (!isPost) {
5742
+ queriesToInvalidate.push([
5743
+ "posts",
5744
+ "entry",
5745
+ `/@${variables.parentAuthor}/${variables.parentPermlink}`
5746
+ ]);
5747
+ }
5748
+ await auth.adapter.invalidateQueries(queriesToInvalidate);
5749
+ }
5750
+ },
5751
+ auth
5752
+ );
5753
+ }
5754
+
4026
5755
  // src/modules/posts/utils/validate-post-creating.ts
4027
5756
  var DEFAULT_VALIDATE_POST_DELAYS = [3e3, 3e3, 3e3];
4028
5757
  var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -4884,6 +6613,35 @@ function getUserProposalVotesQueryOptions(voter) {
4884
6613
  }
4885
6614
  });
4886
6615
  }
6616
+
6617
+ // src/modules/proposals/mutations/use-proposal-vote.ts
6618
+ function useProposalVote(username, auth) {
6619
+ return useBroadcastMutation(
6620
+ ["proposals", "vote"],
6621
+ username,
6622
+ ({ proposalIds, approve }) => [
6623
+ buildProposalVoteOp(username, proposalIds, approve)
6624
+ ],
6625
+ async (result) => {
6626
+ try {
6627
+ if (auth?.adapter?.recordActivity && result?.block_num && result?.id) {
6628
+ await auth.adapter.recordActivity(150, result.block_num, result.id);
6629
+ }
6630
+ if (auth?.adapter?.invalidateQueries) {
6631
+ await auth.adapter.invalidateQueries([
6632
+ ["proposals", "list"],
6633
+ ["proposals", "votes", username]
6634
+ ]);
6635
+ }
6636
+ } catch (error) {
6637
+ console.warn("[useProposalVote] Post-broadcast side-effect failed:", error);
6638
+ }
6639
+ },
6640
+ auth,
6641
+ "active"
6642
+ // Use active authority for proposal votes (required by blockchain)
6643
+ );
6644
+ }
4887
6645
  function getVestingDelegationsQueryOptions(username, limit = 50) {
4888
6646
  return reactQuery.infiniteQueryOptions({
4889
6647
  queryKey: ["wallet", "vesting-delegations", username, limit],
@@ -5174,6 +6932,110 @@ function getPortfolioQueryOptions(username, currency = "usd", onlyEnabled = true
5174
6932
  }
5175
6933
  });
5176
6934
  }
6935
+ async function broadcastTransferWithFallback(username, ops2, auth) {
6936
+ const chain = auth?.fallbackChain ?? ["key", "hiveauth", "hivesigner", "keychain"];
6937
+ const errors = /* @__PURE__ */ new Map();
6938
+ const adapter = auth?.adapter;
6939
+ for (const method of chain) {
6940
+ try {
6941
+ switch (method) {
6942
+ case "key": {
6943
+ if (!adapter) break;
6944
+ const key = await adapter.getActiveKey?.(username);
6945
+ if (key) {
6946
+ const privateKey = dhive.PrivateKey.fromString(key);
6947
+ return await CONFIG.hiveClient.broadcast.sendOperations(ops2, privateKey);
6948
+ }
6949
+ break;
6950
+ }
6951
+ case "hiveauth": {
6952
+ if (adapter?.broadcastWithHiveAuth) {
6953
+ return await adapter.broadcastWithHiveAuth(username, ops2, "active");
6954
+ }
6955
+ break;
6956
+ }
6957
+ case "hivesigner": {
6958
+ if (!adapter) break;
6959
+ const token = await adapter.getAccessToken(username);
6960
+ if (token) {
6961
+ const client = new hs__default.default.Client({ accessToken: token });
6962
+ const response = await client.broadcast(ops2);
6963
+ return response.result;
6964
+ }
6965
+ break;
6966
+ }
6967
+ case "keychain": {
6968
+ if (adapter?.broadcastWithKeychain) {
6969
+ return await adapter.broadcastWithKeychain(username, ops2, "active");
6970
+ }
6971
+ break;
6972
+ }
6973
+ case "custom": {
6974
+ if (auth?.broadcast) {
6975
+ return await auth.broadcast(ops2, "active");
6976
+ }
6977
+ break;
6978
+ }
6979
+ }
6980
+ } catch (error) {
6981
+ errors.set(method, error);
6982
+ if (!shouldTriggerAuthFallback(error)) {
6983
+ throw error;
6984
+ }
6985
+ }
6986
+ }
6987
+ const errorMessages = Array.from(errors.entries()).map(([method, error]) => `${method}: ${error.message}`).join(", ");
6988
+ throw new Error(
6989
+ `[SDK][Transfer] All auth methods failed for ${username}. Errors: ${errorMessages}`
6990
+ );
6991
+ }
6992
+ function useTransfer(username, auth) {
6993
+ return reactQuery.useMutation({
6994
+ mutationKey: ["wallet", "transfer", username],
6995
+ mutationFn: async (payload) => {
6996
+ if (!username) {
6997
+ throw new Error(
6998
+ "[SDK][Transfer] Attempted to call transfer API with anon user"
6999
+ );
7000
+ }
7001
+ const ops2 = [buildTransferOp(username, payload.to, payload.amount, payload.memo)];
7002
+ if (auth?.enableFallback !== false && auth?.adapter) {
7003
+ return broadcastTransferWithFallback(username, ops2, auth);
7004
+ }
7005
+ if (auth?.broadcast) {
7006
+ return auth.broadcast(ops2, "active");
7007
+ }
7008
+ if (auth?.adapter?.getActiveKey) {
7009
+ const activeKey = await auth.adapter.getActiveKey(username);
7010
+ if (activeKey) {
7011
+ const privateKey = dhive.PrivateKey.fromString(activeKey);
7012
+ return CONFIG.hiveClient.broadcast.sendOperations(ops2, privateKey);
7013
+ }
7014
+ }
7015
+ const accessToken = auth?.accessToken;
7016
+ if (accessToken) {
7017
+ const client = new hs__default.default.Client({ accessToken });
7018
+ const response = await client.broadcast(ops2);
7019
+ return response.result;
7020
+ }
7021
+ throw new Error(
7022
+ "[SDK][Transfer] \u2013 cannot broadcast transfer w/o active key or token"
7023
+ );
7024
+ },
7025
+ onSuccess: async (result, variables) => {
7026
+ if (auth?.adapter?.recordActivity && result?.block_num && result?.id) {
7027
+ await auth.adapter.recordActivity(140, result.block_num, result.id);
7028
+ }
7029
+ if (auth?.adapter?.invalidateQueries) {
7030
+ await auth.adapter.invalidateQueries([
7031
+ ["wallet", "balances", username],
7032
+ ["wallet", "balances", variables.to],
7033
+ ["wallet", "transactions", username]
7034
+ ]);
7035
+ }
7036
+ }
7037
+ });
7038
+ }
5177
7039
  function getWitnessesInfiniteQueryOptions(limit) {
5178
7040
  return reactQuery.infiniteQueryOptions({
5179
7041
  queryKey: ["witnesses", "list", limit],
@@ -6078,13 +7940,17 @@ async function getSpkMarkets() {
6078
7940
  exports.ACCOUNT_OPERATION_GROUPS = ACCOUNT_OPERATION_GROUPS;
6079
7941
  exports.ALL_ACCOUNT_OPERATIONS = ALL_ACCOUNT_OPERATIONS;
6080
7942
  exports.ALL_NOTIFY_TYPES = ALL_NOTIFY_TYPES;
7943
+ exports.BuySellTransactionType = BuySellTransactionType;
6081
7944
  exports.CONFIG = CONFIG;
6082
7945
  exports.EcencyAnalytics = mutations_exports;
7946
+ exports.ErrorType = ErrorType;
6083
7947
  exports.HiveSignerIntegration = HiveSignerIntegration;
6084
7948
  exports.NaiMap = NaiMap;
6085
7949
  exports.NotificationFilter = NotificationFilter;
6086
7950
  exports.NotificationViewType = NotificationViewType;
6087
7951
  exports.NotifyTypes = NotifyTypes;
7952
+ exports.OPERATION_AUTHORITY_MAP = OPERATION_AUTHORITY_MAP;
7953
+ exports.OrderIdPrefix = OrderIdPrefix;
6088
7954
  exports.ROLES = ROLES;
6089
7955
  exports.SortOrder = SortOrder;
6090
7956
  exports.Symbol = Symbol2;
@@ -6094,7 +7960,68 @@ exports.addImage = addImage;
6094
7960
  exports.addSchedule = addSchedule;
6095
7961
  exports.bridgeApiCall = bridgeApiCall;
6096
7962
  exports.broadcastJson = broadcastJson;
7963
+ exports.buildAccountCreateOp = buildAccountCreateOp;
7964
+ exports.buildAccountUpdate2Op = buildAccountUpdate2Op;
7965
+ exports.buildAccountUpdateOp = buildAccountUpdateOp;
7966
+ exports.buildActiveCustomJsonOp = buildActiveCustomJsonOp;
7967
+ exports.buildBoostOp = buildBoostOp;
7968
+ exports.buildBoostOpWithPoints = buildBoostOpWithPoints;
7969
+ exports.buildBoostPlusOp = buildBoostPlusOp;
7970
+ exports.buildCancelTransferFromSavingsOp = buildCancelTransferFromSavingsOp;
7971
+ exports.buildChangeRecoveryAccountOp = buildChangeRecoveryAccountOp;
7972
+ exports.buildClaimAccountOp = buildClaimAccountOp;
7973
+ exports.buildClaimInterestOps = buildClaimInterestOps;
7974
+ exports.buildClaimRewardBalanceOp = buildClaimRewardBalanceOp;
7975
+ exports.buildCollateralizedConvertOp = buildCollateralizedConvertOp;
7976
+ exports.buildCommentOp = buildCommentOp;
7977
+ exports.buildCommentOptionsOp = buildCommentOptionsOp;
7978
+ exports.buildCommunityRegistrationOp = buildCommunityRegistrationOp;
7979
+ exports.buildConvertOp = buildConvertOp;
7980
+ exports.buildCreateClaimedAccountOp = buildCreateClaimedAccountOp;
7981
+ exports.buildDelegateRcOp = buildDelegateRcOp;
7982
+ exports.buildDelegateVestingSharesOp = buildDelegateVestingSharesOp;
7983
+ exports.buildDeleteCommentOp = buildDeleteCommentOp;
7984
+ exports.buildFlagPostOp = buildFlagPostOp;
7985
+ exports.buildFollowOp = buildFollowOp;
7986
+ exports.buildGrantPostingPermissionOp = buildGrantPostingPermissionOp;
7987
+ exports.buildIgnoreOp = buildIgnoreOp;
7988
+ exports.buildLimitOrderCancelOp = buildLimitOrderCancelOp;
7989
+ exports.buildLimitOrderCreateOp = buildLimitOrderCreateOp;
7990
+ exports.buildLimitOrderCreateOpWithType = buildLimitOrderCreateOpWithType;
7991
+ exports.buildMultiPointTransferOps = buildMultiPointTransferOps;
7992
+ exports.buildMultiTransferOps = buildMultiTransferOps;
7993
+ exports.buildMutePostOp = buildMutePostOp;
7994
+ exports.buildMuteUserOp = buildMuteUserOp;
7995
+ exports.buildPinPostOp = buildPinPostOp;
7996
+ exports.buildPointTransferOp = buildPointTransferOp;
7997
+ exports.buildPostingCustomJsonOp = buildPostingCustomJsonOp;
6097
7998
  exports.buildProfileMetadata = buildProfileMetadata;
7999
+ exports.buildPromoteOp = buildPromoteOp;
8000
+ exports.buildProposalCreateOp = buildProposalCreateOp;
8001
+ exports.buildProposalVoteOp = buildProposalVoteOp;
8002
+ exports.buildReblogOp = buildReblogOp;
8003
+ exports.buildRecoverAccountOp = buildRecoverAccountOp;
8004
+ exports.buildRecurrentTransferOp = buildRecurrentTransferOp;
8005
+ exports.buildRemoveProposalOp = buildRemoveProposalOp;
8006
+ exports.buildRequestAccountRecoveryOp = buildRequestAccountRecoveryOp;
8007
+ exports.buildRevokePostingPermissionOp = buildRevokePostingPermissionOp;
8008
+ exports.buildSetLastReadOps = buildSetLastReadOps;
8009
+ exports.buildSetRoleOp = buildSetRoleOp;
8010
+ exports.buildSetWithdrawVestingRouteOp = buildSetWithdrawVestingRouteOp;
8011
+ exports.buildSubscribeOp = buildSubscribeOp;
8012
+ exports.buildTransferFromSavingsOp = buildTransferFromSavingsOp;
8013
+ exports.buildTransferOp = buildTransferOp;
8014
+ exports.buildTransferToSavingsOp = buildTransferToSavingsOp;
8015
+ exports.buildTransferToVestingOp = buildTransferToVestingOp;
8016
+ exports.buildUnfollowOp = buildUnfollowOp;
8017
+ exports.buildUnignoreOp = buildUnignoreOp;
8018
+ exports.buildUnsubscribeOp = buildUnsubscribeOp;
8019
+ exports.buildUpdateCommunityOp = buildUpdateCommunityOp;
8020
+ exports.buildUpdateProposalOp = buildUpdateProposalOp;
8021
+ exports.buildVoteOp = buildVoteOp;
8022
+ exports.buildWithdrawVestingOp = buildWithdrawVestingOp;
8023
+ exports.buildWitnessProxyOp = buildWitnessProxyOp;
8024
+ exports.buildWitnessVoteOp = buildWitnessVoteOp;
6098
8025
  exports.checkFavouriteQueryOptions = checkFavouriteQueryOptions;
6099
8026
  exports.checkUsernameWalletsPendingQueryOptions = checkUsernameWalletsPendingQueryOptions;
6100
8027
  exports.decodeObj = decodeObj;
@@ -6105,6 +8032,7 @@ exports.deleteSchedule = deleteSchedule;
6105
8032
  exports.downVotingPower = downVotingPower;
6106
8033
  exports.encodeObj = encodeObj;
6107
8034
  exports.extractAccountProfile = extractAccountProfile;
8035
+ exports.formatError = formatError;
6108
8036
  exports.getAccountFullQueryOptions = getAccountFullQueryOptions;
6109
8037
  exports.getAccountNotificationsInfiniteQueryOptions = getAccountNotificationsInfiniteQueryOptions;
6110
8038
  exports.getAccountPendingRecoveryQueryOptions = getAccountPendingRecoveryQueryOptions;
@@ -6143,6 +8071,7 @@ exports.getCurrencyRate = getCurrencyRate;
6143
8071
  exports.getCurrencyRates = getCurrencyRates;
6144
8072
  exports.getCurrencyTokenRate = getCurrencyTokenRate;
6145
8073
  exports.getCurrentMedianHistoryPriceQueryOptions = getCurrentMedianHistoryPriceQueryOptions;
8074
+ exports.getCustomJsonAuthority = getCustomJsonAuthority;
6146
8075
  exports.getDeletedEntryQueryOptions = getDeletedEntryQueryOptions;
6147
8076
  exports.getDiscoverCurationQueryOptions = getDiscoverCurationQueryOptions;
6148
8077
  exports.getDiscoverLeaderboardQueryOptions = getDiscoverLeaderboardQueryOptions;
@@ -6192,6 +8121,7 @@ exports.getNotificationsInfiniteQueryOptions = getNotificationsInfiniteQueryOpti
6192
8121
  exports.getNotificationsSettingsQueryOptions = getNotificationsSettingsQueryOptions;
6193
8122
  exports.getNotificationsUnreadCountQueryOptions = getNotificationsUnreadCountQueryOptions;
6194
8123
  exports.getOpenOrdersQueryOptions = getOpenOrdersQueryOptions;
8124
+ exports.getOperationAuthority = getOperationAuthority;
6195
8125
  exports.getOrderBookQueryOptions = getOrderBookQueryOptions;
6196
8126
  exports.getOutgoingRcDelegationsInfiniteQueryOptions = getOutgoingRcDelegationsInfiniteQueryOptions;
6197
8127
  exports.getPageStatsQueryOptions = getPageStatsQueryOptions;
@@ -6210,6 +8140,7 @@ exports.getProfilesQueryOptions = getProfilesQueryOptions;
6210
8140
  exports.getPromotePriceQueryOptions = getPromotePriceQueryOptions;
6211
8141
  exports.getPromotedPost = getPromotedPost;
6212
8142
  exports.getPromotedPostsQuery = getPromotedPostsQuery;
8143
+ exports.getProposalAuthority = getProposalAuthority;
6213
8144
  exports.getProposalQueryOptions = getProposalQueryOptions;
6214
8145
  exports.getProposalVotesInfiniteQueryOptions = getProposalVotesInfiniteQueryOptions;
6215
8146
  exports.getProposalsQueryOptions = getProposalsQueryOptions;
@@ -6223,6 +8154,7 @@ exports.getReferralsInfiniteQueryOptions = getReferralsInfiniteQueryOptions;
6223
8154
  exports.getReferralsStatsQueryOptions = getReferralsStatsQueryOptions;
6224
8155
  exports.getRelationshipBetweenAccounts = getRelationshipBetweenAccounts;
6225
8156
  exports.getRelationshipBetweenAccountsQueryOptions = getRelationshipBetweenAccountsQueryOptions;
8157
+ exports.getRequiredAuthority = getRequiredAuthority;
6226
8158
  exports.getRewardFundQueryOptions = getRewardFundQueryOptions;
6227
8159
  exports.getRewardedCommunitiesQueryOptions = getRewardedCommunitiesQueryOptions;
6228
8160
  exports.getSavingsWithdrawFromQueryOptions = getSavingsWithdrawFromQueryOptions;
@@ -6256,6 +8188,9 @@ exports.getWithdrawRoutesQueryOptions = getWithdrawRoutesQueryOptions;
6256
8188
  exports.getWitnessesInfiniteQueryOptions = getWitnessesInfiniteQueryOptions;
6257
8189
  exports.hsTokenRenew = hsTokenRenew;
6258
8190
  exports.isCommunity = isCommunity;
8191
+ exports.isInfoError = isInfoError;
8192
+ exports.isNetworkError = isNetworkError;
8193
+ exports.isResourceCreditsError = isResourceCreditsError;
6259
8194
  exports.isWrappedResponse = isWrappedResponse;
6260
8195
  exports.lookupAccountsQueryOptions = lookupAccountsQueryOptions;
6261
8196
  exports.makeQueryClient = makeQueryClient;
@@ -6268,6 +8203,7 @@ exports.normalizeWaveEntryFromApi = normalizeWaveEntryFromApi;
6268
8203
  exports.onboardEmail = onboardEmail;
6269
8204
  exports.parseAccounts = parseAccounts;
6270
8205
  exports.parseAsset = parseAsset;
8206
+ exports.parseChainError = parseChainError;
6271
8207
  exports.parseProfileMetadata = parseProfileMetadata;
6272
8208
  exports.powerRechargeTime = powerRechargeTime;
6273
8209
  exports.rcPower = rcPower;
@@ -6279,6 +8215,7 @@ exports.searchAccount = searchAccount;
6279
8215
  exports.searchPath = searchPath;
6280
8216
  exports.searchQueryOptions = searchQueryOptions;
6281
8217
  exports.searchTag = searchTag;
8218
+ exports.shouldTriggerAuthFallback = shouldTriggerAuthFallback;
6282
8219
  exports.signUp = signUp;
6283
8220
  exports.sortDiscussions = sortDiscussions;
6284
8221
  exports.subscribeEmail = subscribeEmail;
@@ -6301,20 +8238,27 @@ exports.useAddSchedule = useAddSchedule;
6301
8238
  exports.useBookmarkAdd = useBookmarkAdd;
6302
8239
  exports.useBookmarkDelete = useBookmarkDelete;
6303
8240
  exports.useBroadcastMutation = useBroadcastMutation;
8241
+ exports.useComment = useComment;
6304
8242
  exports.useDeleteDraft = useDeleteDraft;
6305
8243
  exports.useDeleteImage = useDeleteImage;
6306
8244
  exports.useDeleteSchedule = useDeleteSchedule;
6307
8245
  exports.useEditFragment = useEditFragment;
8246
+ exports.useFollow = useFollow;
6308
8247
  exports.useGameClaim = useGameClaim;
6309
8248
  exports.useMarkNotificationsRead = useMarkNotificationsRead;
6310
8249
  exports.useMoveSchedule = useMoveSchedule;
8250
+ exports.useProposalVote = useProposalVote;
8251
+ exports.useReblog = useReblog;
6311
8252
  exports.useRecordActivity = useRecordActivity;
6312
8253
  exports.useRemoveFragment = useRemoveFragment;
6313
8254
  exports.useSignOperationByHivesigner = useSignOperationByHivesigner;
6314
8255
  exports.useSignOperationByKey = useSignOperationByKey;
6315
8256
  exports.useSignOperationByKeychain = useSignOperationByKeychain;
8257
+ exports.useTransfer = useTransfer;
8258
+ exports.useUnfollow = useUnfollow;
6316
8259
  exports.useUpdateDraft = useUpdateDraft;
6317
8260
  exports.useUploadImage = useUploadImage;
8261
+ exports.useVote = useVote;
6318
8262
  exports.usrActivity = usrActivity;
6319
8263
  exports.validatePostCreating = validatePostCreating;
6320
8264
  exports.votingPower = votingPower;