@ecency/sdk 1.5.28 → 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.
@@ -258,67 +258,210 @@ function isNetworkError(error) {
258
258
  const { type } = parseChainError(error);
259
259
  return type === "network" /* NETWORK */ || type === "timeout" /* TIMEOUT */;
260
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
+ }
261
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
+ }
262
383
  const chain = auth?.fallbackChain ?? ["key", "hiveauth", "hivesigner", "keychain", "custom"];
263
384
  const errors = /* @__PURE__ */ new Map();
264
- const adapter = auth?.adapter;
265
385
  for (const method of chain) {
266
386
  try {
387
+ let shouldSkip = false;
388
+ let skipReason = "";
389
+ let prefetchedKey;
390
+ let prefetchedToken;
267
391
  switch (method) {
268
- case "key": {
392
+ case "key":
269
393
  if (!adapter) {
270
- errors.set(method, new Error("Skipped: No adapter provided"));
271
- break;
272
- }
273
- let key;
274
- if (authority === "active" && adapter.getActiveKey) {
275
- key = await adapter.getActiveKey(username);
276
- } else if (authority === "posting") {
277
- key = await adapter.getPostingKey(username);
278
- }
279
- if (!key) {
280
- errors.set(method, new Error(`Skipped: No ${authority} key available`));
281
- break;
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
+ }
282
425
  }
283
- const privateKey = dhive.PrivateKey.fromString(key);
284
- return await CONFIG.hiveClient.broadcast.sendOperations(ops2, privateKey);
285
- }
286
- case "hiveauth": {
426
+ break;
427
+ case "hiveauth":
287
428
  if (!adapter?.broadcastWithHiveAuth) {
288
- errors.set(method, new Error("Skipped: HiveAuth not supported by adapter"));
289
- break;
429
+ shouldSkip = true;
430
+ skipReason = "HiveAuth not supported by adapter";
290
431
  }
291
- return await adapter.broadcastWithHiveAuth(username, ops2, authority);
292
- }
293
- case "hivesigner": {
432
+ break;
433
+ case "hivesigner":
294
434
  if (!adapter) {
295
- errors.set(method, new Error("Skipped: No adapter provided"));
296
- break;
297
- }
298
- const token = await adapter.getAccessToken(username);
299
- if (!token) {
300
- errors.set(method, new Error("Skipped: No access token available"));
301
- break;
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
+ }
302
445
  }
303
- const client = new hs__default.default.Client({ accessToken: token });
304
- const response = await client.broadcast(ops2);
305
- return response.result;
306
- }
307
- case "keychain": {
446
+ break;
447
+ case "keychain":
308
448
  if (!adapter?.broadcastWithKeychain) {
309
- errors.set(method, new Error("Skipped: Keychain not supported by adapter"));
310
- break;
449
+ shouldSkip = true;
450
+ skipReason = "Keychain not supported by adapter";
311
451
  }
312
- return await adapter.broadcastWithKeychain(username, ops2, authority);
313
- }
314
- case "custom": {
452
+ break;
453
+ case "custom":
315
454
  if (!auth?.broadcast) {
316
- errors.set(method, new Error("Skipped: No custom broadcast function provided"));
317
- break;
455
+ shouldSkip = true;
456
+ skipReason = "No custom broadcast function provided";
318
457
  }
319
- return await auth.broadcast(ops2, authority);
320
- }
458
+ break;
321
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);
322
465
  } catch (error) {
323
466
  errors.set(method, error);
324
467
  if (!shouldTriggerAuthFallback(error)) {
@@ -360,6 +503,11 @@ function useBroadcastMutation(mutationKey = [], username, operations, onSuccess
360
503
  }
361
504
  const postingKey = auth?.postingKey;
362
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
+ }
363
511
  const privateKey = dhive.PrivateKey.fromString(postingKey);
364
512
  return CONFIG.hiveClient.broadcast.sendOperations(
365
513
  ops2,
@@ -3130,1542 +3278,1670 @@ function useAccountRelationsUpdate(reference, target, auth, onSuccess, onError)
3130
3278
  }
3131
3279
  });
3132
3280
  }
3133
- function useBookmarkAdd(username, code, onSuccess, onError) {
3134
- return reactQuery.useMutation({
3135
- mutationKey: ["accounts", "bookmarks", "add", username],
3136
- mutationFn: async ({ author, permlink }) => {
3137
- if (!username || !code) {
3138
- throw new Error("[SDK][Account][Bookmarks] \u2013 missing auth");
3139
- }
3140
- const fetchApi = getBoundFetch();
3141
- const response = await fetchApi(
3142
- CONFIG.privateApiHost + "/private-api/bookmarks-add",
3143
- {
3144
- method: "POST",
3145
- headers: {
3146
- "Content-Type": "application/json"
3147
- },
3148
- body: JSON.stringify({
3149
- author,
3150
- permlink,
3151
- code
3152
- })
3153
- }
3154
- );
3155
- return response.json();
3156
- },
3157
- onSuccess: () => {
3158
- onSuccess();
3159
- getQueryClient().invalidateQueries({
3160
- queryKey: ["accounts", "bookmarks", username]
3161
- });
3162
- },
3163
- onError
3164
- });
3165
- }
3166
- function useBookmarkDelete(username, code, onSuccess, onError) {
3167
- return reactQuery.useMutation({
3168
- mutationKey: ["accounts", "bookmarks", "delete", username],
3169
- mutationFn: async (bookmarkId) => {
3170
- if (!username || !code) {
3171
- throw new Error("[SDK][Account][Bookmarks] \u2013 missing auth");
3172
- }
3173
- const fetchApi = getBoundFetch();
3174
- const response = await fetchApi(
3175
- CONFIG.privateApiHost + "/private-api/bookmarks-delete",
3176
- {
3177
- method: "POST",
3178
- headers: {
3179
- "Content-Type": "application/json"
3180
- },
3181
- body: JSON.stringify({
3182
- id: bookmarkId,
3183
- code
3184
- })
3185
- }
3186
- );
3187
- return response.json();
3188
- },
3189
- onSuccess: () => {
3190
- onSuccess();
3191
- getQueryClient().invalidateQueries({
3192
- queryKey: ["accounts", "bookmarks", username]
3193
- });
3194
- },
3195
- onError
3196
- });
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
+ ];
3197
3299
  }
3198
- function useAccountFavouriteAdd(username, code, onSuccess, onError) {
3199
- return reactQuery.useMutation({
3200
- mutationKey: ["accounts", "favourites", "add", username],
3201
- mutationFn: async (account) => {
3202
- if (!username || !code) {
3203
- throw new Error("[SDK][Account][Bookmarks] \u2013 missing auth");
3204
- }
3205
- const fetchApi = getBoundFetch();
3206
- const response = await fetchApi(
3207
- CONFIG.privateApiHost + "/private-api/favorites-add",
3208
- {
3209
- method: "POST",
3210
- headers: {
3211
- "Content-Type": "application/json"
3212
- },
3213
- body: JSON.stringify({
3214
- account,
3215
- code
3216
- })
3217
- }
3218
- );
3219
- return response.json();
3220
- },
3221
- onSuccess: () => {
3222
- onSuccess();
3223
- getQueryClient().invalidateQueries({
3224
- queryKey: ["accounts", "favourites", username]
3225
- });
3226
- },
3227
- onError
3228
- });
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
+ ];
3229
3316
  }
3230
- function useAccountFavouriteDelete(username, code, onSuccess, onError) {
3231
- return reactQuery.useMutation({
3232
- mutationKey: ["accounts", "favourites", "add", username],
3233
- mutationFn: async (account) => {
3234
- if (!username || !code) {
3235
- throw new Error("[SDK][Account][Bookmarks] \u2013 missing auth");
3236
- }
3237
- const fetchApi = getBoundFetch();
3238
- const response = await fetchApi(
3239
- CONFIG.privateApiHost + "/private-api/favorites-delete",
3240
- {
3241
- method: "POST",
3242
- headers: {
3243
- "Content-Type": "application/json"
3244
- },
3245
- body: JSON.stringify({
3246
- account,
3247
- code
3248
- })
3249
- }
3250
- );
3251
- return response.json();
3252
- },
3253
- onSuccess: () => {
3254
- onSuccess();
3255
- getQueryClient().invalidateQueries({
3256
- queryKey: ["accounts", "favourites", username]
3257
- });
3258
- },
3259
- onError
3260
- });
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
+ ];
3261
3333
  }
3262
- function dedupeAndSortKeyAuths(existing, additions) {
3263
- const merged = /* @__PURE__ */ new Map();
3264
- existing.forEach(([key, weight]) => {
3265
- merged.set(key.toString(), weight);
3266
- });
3267
- additions.forEach(([key, weight]) => {
3268
- merged.set(key.toString(), weight);
3269
- });
3270
- return Array.from(merged.entries()).sort(([keyA], [keyB]) => keyA.localeCompare(keyB)).map(([key, weight]) => [key, weight]);
3271
- }
3272
- function useAccountUpdateKeyAuths(username, options) {
3273
- const { data: accountData } = reactQuery.useQuery(getAccountFullQueryOptions(username));
3274
- return reactQuery.useMutation({
3275
- mutationKey: ["accounts", "keys-update", username],
3276
- mutationFn: async ({
3277
- keys,
3278
- keepCurrent = false,
3279
- currentKey,
3280
- keysToRevoke = [],
3281
- keysToRevokeByAuthority = {}
3282
- }) => {
3283
- if (keys.length === 0) {
3284
- throw new Error(
3285
- "[SDK][Update password] \u2013 no new keys provided"
3286
- );
3287
- }
3288
- if (!accountData) {
3289
- throw new Error(
3290
- "[SDK][Update password] \u2013 cannot update keys for anon user"
3291
- );
3292
- }
3293
- const prepareAuth = (keyName) => {
3294
- const auth = R4__namespace.clone(accountData[keyName]);
3295
- const keysToRevokeForAuthority = keysToRevokeByAuthority[keyName] || [];
3296
- const allKeysToRevoke = [
3297
- ...keysToRevokeForAuthority,
3298
- ...keysToRevokeByAuthority[keyName] === void 0 ? keysToRevoke : []
3299
- ];
3300
- const existingKeys = keepCurrent ? auth.key_auths.filter(([key]) => !allKeysToRevoke.includes(key.toString())) : [];
3301
- auth.key_auths = dedupeAndSortKeyAuths(
3302
- existingKeys,
3303
- keys.map(
3304
- (values, i) => [values[keyName].createPublic().toString(), i + 1]
3305
- )
3306
- );
3307
- return auth;
3308
- };
3309
- return CONFIG.hiveClient.broadcast.updateAccount(
3310
- {
3311
- account: username,
3312
- json_metadata: accountData.json_metadata,
3313
- owner: prepareAuth("owner"),
3314
- active: prepareAuth("active"),
3315
- posting: prepareAuth("posting"),
3316
- // Always use new memo key when adding new keys
3317
- memo_key: keys[0].memo_key.createPublic().toString()
3318
- },
3319
- currentKey
3320
- );
3321
- },
3322
- ...options
3323
- });
3324
- }
3325
- function useAccountUpdatePassword(username, options) {
3326
- const { data: accountData } = reactQuery.useQuery(getAccountFullQueryOptions(username));
3327
- const { mutateAsync: updateKeys } = useAccountUpdateKeyAuths(username);
3328
- return reactQuery.useMutation({
3329
- mutationKey: ["accounts", "password-update", username],
3330
- mutationFn: async ({
3331
- newPassword,
3332
- currentPassword,
3333
- keepCurrent
3334
- }) => {
3335
- if (!accountData) {
3336
- throw new Error(
3337
- "[SDK][Update password] \u2013 cannot update password for anon user"
3338
- );
3339
- }
3340
- const currentKey = dhive.PrivateKey.fromLogin(
3341
- username,
3342
- currentPassword,
3343
- "owner"
3344
- );
3345
- return updateKeys({
3346
- currentKey,
3347
- keepCurrent,
3348
- keys: [
3349
- {
3350
- owner: dhive.PrivateKey.fromLogin(username, newPassword, "owner"),
3351
- active: dhive.PrivateKey.fromLogin(username, newPassword, "active"),
3352
- posting: dhive.PrivateKey.fromLogin(username, newPassword, "posting"),
3353
- memo_key: dhive.PrivateKey.fromLogin(username, newPassword, "memo")
3354
- }
3355
- ]
3356
- });
3357
- },
3358
- ...options
3359
- });
3360
- }
3361
- function useAccountRevokePosting(username, options, auth) {
3362
- const queryClient = reactQuery.useQueryClient();
3363
- const { data } = reactQuery.useQuery(getAccountFullQueryOptions(username));
3364
- return reactQuery.useMutation({
3365
- mutationKey: ["accounts", "revoke-posting", data?.name],
3366
- mutationFn: async ({ accountName, type, key }) => {
3367
- if (!data) {
3368
- throw new Error(
3369
- "[SDK][Accounts] \u2013\xA0cannot revoke posting for anonymous user"
3370
- );
3371
- }
3372
- const posting = R4__namespace.pipe(
3373
- {},
3374
- R4__namespace.mergeDeep(data.posting)
3375
- );
3376
- posting.account_auths = posting.account_auths.filter(
3377
- ([account]) => account !== accountName
3378
- );
3379
- const operationBody = {
3380
- account: data.name,
3381
- posting,
3382
- memo_key: data.memo_key,
3383
- json_metadata: data.json_metadata
3384
- };
3385
- if (type === "key" && key) {
3386
- return CONFIG.hiveClient.broadcast.updateAccount(operationBody, key);
3387
- } else if (type === "keychain") {
3388
- if (!auth?.broadcast) {
3389
- throw new Error("[SDK][Accounts] \u2013 missing keychain broadcaster");
3390
- }
3391
- return auth.broadcast([["account_update", operationBody]], "active");
3392
- } else {
3393
- const params = {
3394
- callback: `https://ecency.com/@${data.name}/permissions`
3395
- };
3396
- return hs__default.default.sendOperation(
3397
- ["account_update", operationBody],
3398
- params,
3399
- () => {
3400
- }
3401
- );
3402
- }
3403
- },
3404
- onError: options.onError,
3405
- onSuccess: (resp, payload, ctx) => {
3406
- options.onSuccess?.(resp, payload, ctx);
3407
- queryClient.setQueryData(
3408
- getAccountFullQueryOptions(username).queryKey,
3409
- (data2) => ({
3410
- ...data2,
3411
- posting: {
3412
- ...data2?.posting,
3413
- account_auths: data2?.posting?.account_auths?.filter(
3414
- ([account]) => account !== payload.accountName
3415
- ) ?? []
3416
- }
3417
- })
3418
- );
3419
- }
3420
- });
3421
- }
3422
- function useAccountUpdateRecovery(username, code, options, auth) {
3423
- const { data } = reactQuery.useQuery(getAccountFullQueryOptions(username));
3424
- return reactQuery.useMutation({
3425
- mutationKey: ["accounts", "recovery", data?.name],
3426
- mutationFn: async ({ accountName, type, key, email }) => {
3427
- if (!data) {
3428
- throw new Error(
3429
- "[SDK][Accounts] \u2013\xA0cannot change recovery for anonymous user"
3430
- );
3431
- }
3432
- const operationBody = {
3433
- account_to_recover: data.name,
3434
- new_recovery_account: accountName,
3435
- extensions: []
3436
- };
3437
- if (type === "ecency") {
3438
- if (!code) {
3439
- throw new Error("[SDK][Accounts] \u2013 missing access token");
3440
- }
3441
- const fetchApi = getBoundFetch();
3442
- return fetchApi(CONFIG.privateApiHost + "/private-api/recoveries-add", {
3443
- method: "POST",
3444
- body: JSON.stringify({
3445
- code,
3446
- email,
3447
- publicKeys: [
3448
- ...data.owner.key_auths,
3449
- ...data.active.key_auths,
3450
- ...data.posting.key_auths,
3451
- data.memo_key
3452
- ]
3453
- })
3454
- });
3455
- } else if (type === "key" && key) {
3456
- return CONFIG.hiveClient.broadcast.sendOperations(
3457
- [["change_recovery_account", operationBody]],
3458
- key
3459
- );
3460
- } else if (type === "keychain") {
3461
- if (!auth?.broadcast) {
3462
- throw new Error("[SDK][Accounts] \u2013 missing keychain broadcaster");
3463
- }
3464
- return auth.broadcast([["change_recovery_account", operationBody]], "owner");
3465
- } else {
3466
- const params = {
3467
- callback: `https://ecency.com/@${data.name}/permissions`
3468
- };
3469
- return hs__default.default.sendOperation(
3470
- ["change_recovery_account", operationBody],
3471
- params,
3472
- () => {
3473
- }
3474
- );
3475
- }
3476
- },
3477
- onError: options.onError,
3478
- onSuccess: options.onSuccess
3479
- });
3480
- }
3481
- function useAccountRevokeKey(username, options) {
3482
- const { data: accountData } = reactQuery.useQuery(getAccountFullQueryOptions(username));
3483
- return reactQuery.useMutation({
3484
- mutationKey: ["accounts", "revoke-key", accountData?.name],
3485
- mutationFn: async ({ currentKey, revokingKey }) => {
3486
- if (!accountData) {
3487
- throw new Error(
3488
- "[SDK][Update password] \u2013 cannot update keys for anon user"
3489
- );
3490
- }
3491
- const prepareAuth = (keyName) => {
3492
- const auth = R4__namespace.clone(accountData[keyName]);
3493
- auth.key_auths = auth.key_auths.filter(
3494
- ([key]) => key !== revokingKey.toString()
3495
- );
3496
- return auth;
3497
- };
3498
- return CONFIG.hiveClient.broadcast.updateAccount(
3499
- {
3500
- account: accountData.name,
3501
- json_metadata: accountData.json_metadata,
3502
- owner: prepareAuth("owner"),
3503
- active: prepareAuth("active"),
3504
- posting: prepareAuth("posting"),
3505
- memo_key: accountData.memo_key
3506
- },
3507
- currentKey
3508
- );
3509
- },
3510
- ...options
3511
- });
3512
- }
3513
-
3514
- // src/modules/accounts/utils/account-power.ts
3515
- var HIVE_VOTING_MANA_REGENERATION_SECONDS = 5 * 60 * 60 * 24;
3516
- function vestsToRshares(vests, votingPowerValue, votePerc) {
3517
- const vestingShares = vests * 1e6;
3518
- const power = votingPowerValue * votePerc / 1e4 / 50 + 1;
3519
- return power * vestingShares / 1e4;
3520
- }
3521
- function toDhiveAccountForVotingMana(account) {
3522
- return {
3523
- id: 0,
3524
- name: account.name,
3525
- owner: account.owner,
3526
- active: account.active,
3527
- posting: account.posting,
3528
- memo_key: account.memo_key,
3529
- json_metadata: account.json_metadata,
3530
- posting_json_metadata: account.posting_json_metadata,
3531
- proxy: account.proxy ?? "",
3532
- last_owner_update: "",
3533
- last_account_update: "",
3534
- created: account.created,
3535
- mined: false,
3536
- owner_challenged: false,
3537
- active_challenged: false,
3538
- last_owner_proved: "",
3539
- last_active_proved: "",
3540
- recovery_account: account.recovery_account ?? "",
3541
- reset_account: "",
3542
- last_account_recovery: "",
3543
- comment_count: 0,
3544
- lifetime_vote_count: 0,
3545
- post_count: account.post_count,
3546
- can_vote: true,
3547
- voting_power: account.voting_power,
3548
- last_vote_time: account.last_vote_time,
3549
- voting_manabar: account.voting_manabar,
3550
- balance: account.balance,
3551
- savings_balance: account.savings_balance,
3552
- hbd_balance: account.hbd_balance,
3553
- hbd_seconds: "0",
3554
- hbd_seconds_last_update: "",
3555
- hbd_last_interest_payment: "",
3556
- savings_hbd_balance: account.savings_hbd_balance,
3557
- savings_hbd_seconds: account.savings_hbd_seconds,
3558
- savings_hbd_seconds_last_update: account.savings_hbd_seconds_last_update,
3559
- savings_hbd_last_interest_payment: account.savings_hbd_last_interest_payment,
3560
- savings_withdraw_requests: 0,
3561
- reward_hbd_balance: account.reward_hbd_balance,
3562
- reward_hive_balance: account.reward_hive_balance,
3563
- reward_vesting_balance: account.reward_vesting_balance,
3564
- reward_vesting_hive: account.reward_vesting_hive,
3565
- curation_rewards: 0,
3566
- posting_rewards: 0,
3567
- vesting_shares: account.vesting_shares,
3568
- delegated_vesting_shares: account.delegated_vesting_shares,
3569
- received_vesting_shares: account.received_vesting_shares,
3570
- vesting_withdraw_rate: account.vesting_withdraw_rate,
3571
- next_vesting_withdrawal: account.next_vesting_withdrawal,
3572
- withdrawn: account.withdrawn,
3573
- to_withdraw: account.to_withdraw,
3574
- withdraw_routes: 0,
3575
- proxied_vsf_votes: account.proxied_vsf_votes ?? [],
3576
- witnesses_voted_for: 0,
3577
- average_bandwidth: 0,
3578
- lifetime_bandwidth: 0,
3579
- last_bandwidth_update: "",
3580
- average_market_bandwidth: 0,
3581
- lifetime_market_bandwidth: 0,
3582
- last_market_bandwidth_update: "",
3583
- last_post: account.last_post,
3584
- last_root_post: ""
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
3585
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
+ ];
3586
3367
  }
3587
- function votingPower(account) {
3588
- const calc = CONFIG.hiveClient.rc.calculateVPMana(
3589
- toDhiveAccountForVotingMana(account)
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)
3590
3391
  );
3591
- return calc.percentage / 100;
3592
3392
  }
3593
- function powerRechargeTime(power) {
3594
- if (!Number.isFinite(power)) {
3595
- throw new TypeError("Voting power must be a finite number");
3393
+ function buildRecurrentTransferOp(from, to, amount, memo, recurrence, executions) {
3394
+ if (!from || !to || !amount) {
3395
+ throw new Error("[SDK][buildRecurrentTransferOp] Missing required parameters");
3596
3396
  }
3597
- if (power < 0 || power > 100) {
3598
- throw new RangeError("Voting power must be between 0 and 100");
3397
+ if (recurrence < 24) {
3398
+ throw new Error("[SDK][buildRecurrentTransferOp] Recurrence must be at least 24 hours");
3599
3399
  }
3600
- const missingPower = 100 - power;
3601
- return missingPower * 100 * HIVE_VOTING_MANA_REGENERATION_SECONDS / 1e4;
3400
+ return [
3401
+ "recurrent_transfer",
3402
+ {
3403
+ from,
3404
+ to,
3405
+ amount,
3406
+ memo: memo || "",
3407
+ recurrence,
3408
+ executions,
3409
+ extensions: []
3410
+ }
3411
+ ];
3602
3412
  }
3603
- function downVotingPower(account) {
3604
- const totalShares = parseFloat(account.vesting_shares) + parseFloat(account.received_vesting_shares) - parseFloat(account.delegated_vesting_shares);
3605
- const elapsed = Math.floor(Date.now() / 1e3) - account.downvote_manabar.last_update_time;
3606
- const maxMana = totalShares * 1e6 / 4;
3607
- if (maxMana <= 0) {
3608
- return 0;
3609
- }
3610
- let currentMana = parseFloat(account.downvote_manabar.current_mana.toString()) + elapsed * maxMana / HIVE_VOTING_MANA_REGENERATION_SECONDS;
3611
- if (currentMana > maxMana) {
3612
- currentMana = maxMana;
3413
+ function buildTransferToSavingsOp(from, to, amount, memo) {
3414
+ if (!from || !to || !amount) {
3415
+ throw new Error("[SDK][buildTransferToSavingsOp] Missing required parameters");
3613
3416
  }
3614
- const currentManaPerc = currentMana * 100 / maxMana;
3615
- if (isNaN(currentManaPerc)) {
3616
- return 0;
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");
3617
3430
  }
3618
- if (currentManaPerc > 100) {
3619
- return 100;
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");
3620
3445
  }
3621
- return currentManaPerc;
3446
+ return [
3447
+ "cancel_transfer_from_savings",
3448
+ {
3449
+ from,
3450
+ request_id: requestId
3451
+ }
3452
+ ];
3622
3453
  }
3623
- function rcPower(account) {
3624
- const calc = CONFIG.hiveClient.rc.calculateRCMana(account);
3625
- return calc.percentage / 100;
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
+ ];
3626
3462
  }
3627
- function votingValue(account, dynamicProps, votingPowerValue, weight = 1e4) {
3628
- if (!Number.isFinite(votingPowerValue) || !Number.isFinite(weight)) {
3629
- return 0;
3463
+ function buildTransferToVestingOp(from, to, amount) {
3464
+ if (!from || !to || !amount) {
3465
+ throw new Error("[SDK][buildTransferToVestingOp] Missing required parameters");
3630
3466
  }
3631
- const { fundRecentClaims, fundRewardBalance, base, quote } = dynamicProps;
3632
- if (!Number.isFinite(fundRecentClaims) || !Number.isFinite(fundRewardBalance) || !Number.isFinite(base) || !Number.isFinite(quote)) {
3633
- return 0;
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");
3634
3479
  }
3635
- if (fundRecentClaims === 0 || quote === 0) {
3636
- return 0;
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");
3637
3491
  }
3638
- let totalVests = 0;
3639
- try {
3640
- const vesting = parseAsset(account.vesting_shares).amount;
3641
- const received = parseAsset(account.received_vesting_shares).amount;
3642
- const delegated = parseAsset(account.delegated_vesting_shares).amount;
3643
- if (![vesting, received, delegated].every(Number.isFinite)) {
3644
- return 0;
3492
+ return [
3493
+ "delegate_vesting_shares",
3494
+ {
3495
+ delegator,
3496
+ delegatee,
3497
+ vesting_shares: vestingShares
3645
3498
  }
3646
- totalVests = vesting + received - delegated;
3647
- } catch {
3648
- return 0;
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");
3649
3504
  }
3650
- if (!Number.isFinite(totalVests)) {
3651
- return 0;
3505
+ if (percent < 0 || percent > 1e4) {
3506
+ throw new Error("[SDK][buildSetWithdrawVestingRouteOp] Percent must be between 0 and 10000");
3652
3507
  }
3653
- const rShares = vestsToRshares(totalVests, votingPowerValue, weight);
3654
- if (!Number.isFinite(rShares)) {
3655
- return 0;
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");
3656
3534
  }
3657
- return rShares / fundRecentClaims * fundRewardBalance * (base / quote);
3535
+ return [
3536
+ "collateralized_convert",
3537
+ {
3538
+ owner,
3539
+ amount,
3540
+ requestid: requestId
3541
+ }
3542
+ ];
3658
3543
  }
3659
-
3660
- // src/modules/operations/builders/content.ts
3661
- function buildVoteOp(voter, author, permlink, weight) {
3662
- if (!voter || !author || !permlink) {
3663
- throw new Error("[SDK][buildVoteOp] Missing required parameters");
3664
- }
3665
- if (weight < -1e4 || weight > 1e4) {
3666
- throw new Error("[SDK][buildVoteOp] Weight must be between -10000 and 10000");
3544
+ function buildDelegateRcOp(from, delegatees, maxRc) {
3545
+ if (!from || !delegatees || maxRc === void 0) {
3546
+ throw new Error("[SDK][buildDelegateRcOp] Missing required parameters");
3667
3547
  }
3548
+ const delegateeArray = delegatees.includes(",") ? delegatees.split(",").map((d) => d.trim()) : [delegatees];
3668
3549
  return [
3669
- "vote",
3550
+ "custom_json",
3670
3551
  {
3671
- voter,
3672
- author,
3673
- permlink,
3674
- weight
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]
3675
3563
  }
3676
3564
  ];
3677
3565
  }
3678
- function buildCommentOp(author, permlink, parentAuthor, parentPermlink, title, body, jsonMetadata) {
3679
- if (!author || !permlink || parentPermlink === void 0 || !body) {
3680
- throw new Error("[SDK][buildCommentOp] Missing required parameters");
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");
3681
3571
  }
3682
3572
  return [
3683
- "comment",
3573
+ "custom_json",
3684
3574
  {
3685
- parent_author: parentAuthor,
3686
- parent_permlink: parentPermlink,
3687
- author,
3688
- permlink,
3689
- title,
3690
- body,
3691
- json_metadata: JSON.stringify(jsonMetadata)
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]
3692
3586
  }
3693
3587
  ];
3694
3588
  }
3695
- function buildCommentOptionsOp(author, permlink, maxAcceptedPayout, percentHbd, allowVotes, allowCurationRewards, extensions) {
3696
- if (!author || !permlink) {
3697
- throw new Error("[SDK][buildCommentOptionsOp] Missing required parameters");
3589
+ function buildUnfollowOp(follower, following) {
3590
+ if (!follower || !following) {
3591
+ throw new Error("[SDK][buildUnfollowOp] Missing required parameters");
3698
3592
  }
3699
3593
  return [
3700
- "comment_options",
3594
+ "custom_json",
3701
3595
  {
3702
- author,
3703
- permlink,
3704
- max_accepted_payout: maxAcceptedPayout,
3705
- percent_hbd: percentHbd,
3706
- allow_votes: allowVotes,
3707
- allow_curation_rewards: allowCurationRewards,
3708
- extensions
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]
3709
3607
  }
3710
3608
  ];
3711
3609
  }
3712
- function buildDeleteCommentOp(author, permlink) {
3713
- if (!author || !permlink) {
3714
- throw new Error("[SDK][buildDeleteCommentOp] Missing required parameters");
3610
+ function buildIgnoreOp(follower, following) {
3611
+ if (!follower || !following) {
3612
+ throw new Error("[SDK][buildIgnoreOp] Missing required parameters");
3715
3613
  }
3716
3614
  return [
3717
- "delete_comment",
3615
+ "custom_json",
3718
3616
  {
3719
- author,
3720
- permlink
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]
3721
3628
  }
3722
3629
  ];
3723
3630
  }
3724
- function buildReblogOp(account, author, permlink, deleteReblog = false) {
3725
- if (!account || !author || !permlink) {
3726
- throw new Error("[SDK][buildReblogOp] Missing required parameters");
3631
+ function buildUnignoreOp(follower, following) {
3632
+ if (!follower || !following) {
3633
+ throw new Error("[SDK][buildUnignoreOp] Missing required parameters");
3727
3634
  }
3728
- const json = {
3729
- account,
3730
- author,
3731
- permlink
3732
- };
3733
- if (deleteReblog) {
3734
- json.delete = "delete";
3635
+ return buildUnfollowOp(follower, following);
3636
+ }
3637
+ function buildSetLastReadOps(username, date) {
3638
+ if (!username) {
3639
+ throw new Error("[SDK][buildSetLastReadOps] Missing required parameters");
3735
3640
  }
3736
- return [
3641
+ const lastReadDate = date || (/* @__PURE__ */ new Date()).toISOString().split(".")[0];
3642
+ const notifyOp = [
3737
3643
  "custom_json",
3738
3644
  {
3739
- id: "follow",
3740
- json: JSON.stringify(["reblog", json]),
3645
+ id: "notify",
3646
+ json: JSON.stringify(["setLastRead", { date: lastReadDate }]),
3741
3647
  required_auths: [],
3742
- required_posting_auths: [account]
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]
3743
3658
  }
3744
3659
  ];
3660
+ return [notifyOp, ecencyNotifyOp];
3745
3661
  }
3746
3662
 
3747
- // src/modules/operations/builders/wallet.ts
3748
- function buildTransferOp(from, to, amount, memo) {
3749
- if (!from || !to || !amount) {
3750
- throw new Error("[SDK][buildTransferOp] Missing required parameters");
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");
3751
3667
  }
3752
3668
  return [
3753
- "transfer",
3669
+ "account_witness_vote",
3754
3670
  {
3755
- from,
3756
- to,
3757
- amount,
3758
- memo: memo || ""
3671
+ account,
3672
+ witness,
3673
+ approve
3759
3674
  }
3760
3675
  ];
3761
3676
  }
3762
- function buildMultiTransferOps(from, destinations, amount, memo) {
3763
- if (!from || !destinations || !amount) {
3764
- throw new Error("[SDK][buildMultiTransferOps] Missing required parameters");
3677
+ function buildWitnessProxyOp(account, proxy) {
3678
+ if (!account || proxy === void 0) {
3679
+ throw new Error("[SDK][buildWitnessProxyOp] Missing required parameters");
3765
3680
  }
3766
- const destArray = destinations.trim().split(/[\s,]+/).filter(Boolean);
3767
- return destArray.map(
3768
- (dest) => buildTransferOp(from, dest.trim(), amount, memo)
3769
- );
3681
+ return [
3682
+ "account_witness_proxy",
3683
+ {
3684
+ account,
3685
+ proxy
3686
+ }
3687
+ ];
3770
3688
  }
3771
- function buildRecurrentTransferOp(from, to, amount, memo, recurrence, executions) {
3772
- if (!from || !to || !amount) {
3773
- throw new Error("[SDK][buildRecurrentTransferOp] Missing required parameters");
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");
3774
3692
  }
3775
- if (recurrence < 24) {
3776
- throw new Error("[SDK][buildRecurrentTransferOp] Recurrence must be at least 24 hours");
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
+ );
3777
3699
  }
3778
3700
  return [
3779
- "recurrent_transfer",
3701
+ "create_proposal",
3780
3702
  {
3781
- from,
3782
- to,
3783
- amount,
3784
- memo: memo || "",
3785
- recurrence,
3786
- executions,
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,
3787
3710
  extensions: []
3788
3711
  }
3789
3712
  ];
3790
3713
  }
3791
- function buildTransferToSavingsOp(from, to, amount, memo) {
3792
- if (!from || !to || !amount) {
3793
- throw new Error("[SDK][buildTransferToSavingsOp] Missing required parameters");
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");
3794
3717
  }
3795
3718
  return [
3796
- "transfer_to_savings",
3719
+ "update_proposal_votes",
3797
3720
  {
3798
- from,
3799
- to,
3800
- amount,
3801
- memo: memo || ""
3721
+ voter,
3722
+ proposal_ids: proposalIds,
3723
+ approve,
3724
+ extensions: []
3802
3725
  }
3803
3726
  ];
3804
3727
  }
3805
- function buildTransferFromSavingsOp(from, to, amount, memo, requestId) {
3806
- if (!from || !to || !amount || requestId === void 0) {
3807
- throw new Error("[SDK][buildTransferFromSavingsOp] Missing required parameters");
3728
+ function buildRemoveProposalOp(proposalOwner, proposalIds) {
3729
+ if (!proposalOwner || !proposalIds || proposalIds.length === 0) {
3730
+ throw new Error("[SDK][buildRemoveProposalOp] Missing required parameters");
3808
3731
  }
3809
3732
  return [
3810
- "transfer_from_savings",
3733
+ "remove_proposal",
3811
3734
  {
3812
- from,
3813
- to,
3814
- amount,
3815
- memo: memo || "",
3816
- request_id: requestId
3735
+ proposal_owner: proposalOwner,
3736
+ proposal_ids: proposalIds,
3737
+ extensions: []
3817
3738
  }
3818
3739
  ];
3819
3740
  }
3820
- function buildCancelTransferFromSavingsOp(from, requestId) {
3821
- if (!from || requestId === void 0) {
3822
- throw new Error("[SDK][buildCancelTransferFromSavingsOp] Missing required parameters");
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");
3823
3744
  }
3824
3745
  return [
3825
- "cancel_transfer_from_savings",
3826
- {
3827
- from,
3828
- request_id: requestId
3746
+ "update_proposal",
3747
+ {
3748
+ proposal_id: proposalId,
3749
+ creator,
3750
+ daily_pay: dailyPay,
3751
+ subject,
3752
+ permlink,
3753
+ extensions: []
3829
3754
  }
3830
3755
  ];
3831
3756
  }
3832
- function buildClaimInterestOps(from, to, amount, memo, requestId) {
3833
- if (!from || !to || !amount || requestId === void 0) {
3834
- throw new Error("[SDK][buildClaimInterestOps] Missing required parameters");
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");
3835
3762
  }
3836
3763
  return [
3837
- buildTransferFromSavingsOp(from, to, amount, memo, requestId),
3838
- buildCancelTransferFromSavingsOp(from, requestId)
3764
+ "custom_json",
3765
+ {
3766
+ id: "community",
3767
+ json: JSON.stringify(["subscribe", { community }]),
3768
+ required_auths: [],
3769
+ required_posting_auths: [username]
3770
+ }
3839
3771
  ];
3840
3772
  }
3841
- function buildTransferToVestingOp(from, to, amount) {
3842
- if (!from || !to || !amount) {
3843
- throw new Error("[SDK][buildTransferToVestingOp] Missing required parameters");
3773
+ function buildUnsubscribeOp(username, community) {
3774
+ if (!username || !community) {
3775
+ throw new Error("[SDK][buildUnsubscribeOp] Missing required parameters");
3844
3776
  }
3845
3777
  return [
3846
- "transfer_to_vesting",
3778
+ "custom_json",
3847
3779
  {
3848
- from,
3849
- to,
3850
- amount
3780
+ id: "community",
3781
+ json: JSON.stringify(["unsubscribe", { community }]),
3782
+ required_auths: [],
3783
+ required_posting_auths: [username]
3851
3784
  }
3852
3785
  ];
3853
3786
  }
3854
- function buildWithdrawVestingOp(account, vestingShares) {
3855
- if (!account || !vestingShares) {
3856
- throw new Error("[SDK][buildWithdrawVestingOp] Missing required parameters");
3787
+ function buildSetRoleOp(username, community, account, role) {
3788
+ if (!username || !community || !account || !role) {
3789
+ throw new Error("[SDK][buildSetRoleOp] Missing required parameters");
3857
3790
  }
3858
3791
  return [
3859
- "withdraw_vesting",
3792
+ "custom_json",
3860
3793
  {
3861
- account,
3862
- vesting_shares: vestingShares
3794
+ id: "community",
3795
+ json: JSON.stringify(["setRole", { community, account, role }]),
3796
+ required_auths: [],
3797
+ required_posting_auths: [username]
3863
3798
  }
3864
3799
  ];
3865
3800
  }
3866
- function buildDelegateVestingSharesOp(delegator, delegatee, vestingShares) {
3867
- if (!delegator || !delegatee || !vestingShares) {
3868
- throw new Error("[SDK][buildDelegateVestingSharesOp] Missing required parameters");
3801
+ function buildUpdateCommunityOp(username, community, props) {
3802
+ if (!username || !community || !props) {
3803
+ throw new Error("[SDK][buildUpdateCommunityOp] Missing required parameters");
3869
3804
  }
3870
3805
  return [
3871
- "delegate_vesting_shares",
3806
+ "custom_json",
3872
3807
  {
3873
- delegator,
3874
- delegatee,
3875
- vesting_shares: vestingShares
3808
+ id: "community",
3809
+ json: JSON.stringify(["updateProps", { community, props }]),
3810
+ required_auths: [],
3811
+ required_posting_auths: [username]
3876
3812
  }
3877
3813
  ];
3878
3814
  }
3879
- function buildSetWithdrawVestingRouteOp(fromAccount, toAccount, percent, autoVest) {
3880
- if (!fromAccount || !toAccount || percent === void 0) {
3881
- throw new Error("[SDK][buildSetWithdrawVestingRouteOp] Missing required parameters");
3882
- }
3883
- if (percent < 0 || percent > 1e4) {
3884
- throw new Error("[SDK][buildSetWithdrawVestingRouteOp] Percent must be between 0 and 10000");
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");
3885
3818
  }
3819
+ const action = pin ? "pinPost" : "unpinPost";
3886
3820
  return [
3887
- "set_withdraw_vesting_route",
3821
+ "custom_json",
3888
3822
  {
3889
- from_account: fromAccount,
3890
- to_account: toAccount,
3891
- percent,
3892
- auto_vest: autoVest
3823
+ id: "community",
3824
+ json: JSON.stringify([action, { community, account, permlink }]),
3825
+ required_auths: [],
3826
+ required_posting_auths: [username]
3893
3827
  }
3894
3828
  ];
3895
3829
  }
3896
- function buildConvertOp(owner, amount, requestId) {
3897
- if (!owner || !amount || requestId === void 0) {
3898
- throw new Error("[SDK][buildConvertOp] Missing required parameters");
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");
3899
3833
  }
3834
+ const action = mute ? "mutePost" : "unmutePost";
3900
3835
  return [
3901
- "convert",
3836
+ "custom_json",
3902
3837
  {
3903
- owner,
3904
- amount,
3905
- requestid: requestId
3838
+ id: "community",
3839
+ json: JSON.stringify([action, { community, account, permlink, notes }]),
3840
+ required_auths: [],
3841
+ required_posting_auths: [username]
3906
3842
  }
3907
3843
  ];
3908
3844
  }
3909
- function buildCollateralizedConvertOp(owner, amount, requestId) {
3910
- if (!owner || !amount || requestId === void 0) {
3911
- throw new Error("[SDK][buildCollateralizedConvertOp] Missing required parameters");
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");
3912
3848
  }
3849
+ const action = mute ? "muteUser" : "unmuteUser";
3913
3850
  return [
3914
- "collateralized_convert",
3851
+ "custom_json",
3915
3852
  {
3916
- owner,
3917
- amount,
3918
- requestid: requestId
3853
+ id: "community",
3854
+ json: JSON.stringify([action, { community, account, notes }]),
3855
+ required_auths: [],
3856
+ required_posting_auths: [username]
3919
3857
  }
3920
3858
  ];
3921
3859
  }
3922
- function buildDelegateRcOp(from, delegatees, maxRc) {
3923
- if (!from || !delegatees || maxRc === void 0) {
3924
- throw new Error("[SDK][buildDelegateRcOp] Missing required parameters");
3860
+ function buildFlagPostOp(username, community, account, permlink, notes) {
3861
+ if (!username || !community || !account || !permlink) {
3862
+ throw new Error("[SDK][buildFlagPostOp] Missing required parameters");
3925
3863
  }
3926
- const delegateeArray = delegatees.includes(",") ? delegatees.split(",").map((d) => d.trim()) : [delegatees];
3927
3864
  return [
3928
3865
  "custom_json",
3929
3866
  {
3930
- id: "rc",
3931
- json: JSON.stringify([
3932
- "delegate_rc",
3933
- {
3934
- from,
3935
- delegatees: delegateeArray,
3936
- max_rc: maxRc
3937
- }
3938
- ]),
3867
+ id: "community",
3868
+ json: JSON.stringify(["flagPost", { community, account, permlink, notes }]),
3939
3869
  required_auths: [],
3940
- required_posting_auths: [from]
3870
+ required_posting_auths: [username]
3941
3871
  }
3942
3872
  ];
3943
3873
  }
3944
3874
 
3945
- // src/modules/operations/builders/social.ts
3946
- function buildFollowOp(follower, following) {
3947
- if (!follower || !following) {
3948
- throw new Error("[SDK][buildFollowOp] Missing required parameters");
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");
3949
3889
  }
3950
3890
  return [
3951
- "custom_json",
3891
+ "limit_order_create",
3952
3892
  {
3953
- id: "follow",
3954
- json: JSON.stringify([
3955
- "follow",
3956
- {
3957
- follower,
3958
- following,
3959
- what: ["blog"]
3960
- }
3961
- ]),
3962
- required_auths: [],
3963
- required_posting_auths: [follower]
3893
+ owner,
3894
+ orderid: orderId,
3895
+ amount_to_sell: amountToSell,
3896
+ min_to_receive: minToReceive,
3897
+ fill_or_kill: fillOrKill,
3898
+ expiration
3964
3899
  }
3965
3900
  ];
3966
3901
  }
3967
- function buildUnfollowOp(follower, following) {
3968
- if (!follower || !following) {
3969
- throw new Error("[SDK][buildUnfollowOp] Missing required parameters");
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");
3970
3929
  }
3971
3930
  return [
3972
- "custom_json",
3931
+ "limit_order_cancel",
3973
3932
  {
3974
- id: "follow",
3975
- json: JSON.stringify([
3976
- "follow",
3977
- {
3978
- follower,
3979
- following,
3980
- what: []
3981
- }
3982
- ]),
3983
- required_auths: [],
3984
- required_posting_auths: [follower]
3933
+ owner,
3934
+ orderid: orderId
3985
3935
  }
3986
3936
  ];
3987
3937
  }
3988
- function buildIgnoreOp(follower, following) {
3989
- if (!follower || !following) {
3990
- throw new Error("[SDK][buildIgnoreOp] Missing required parameters");
3938
+ function buildClaimRewardBalanceOp(account, rewardHive, rewardHbd, rewardVests) {
3939
+ if (!account || !rewardHive || !rewardHbd || !rewardVests) {
3940
+ throw new Error("[SDK][buildClaimRewardBalanceOp] Missing required parameters");
3991
3941
  }
3992
3942
  return [
3993
- "custom_json",
3943
+ "claim_reward_balance",
3994
3944
  {
3995
- id: "follow",
3996
- json: JSON.stringify([
3997
- "follow",
3998
- {
3999
- follower,
4000
- following,
4001
- what: ["ignore"]
4002
- }
4003
- ]),
4004
- required_auths: [],
4005
- required_posting_auths: [follower]
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
4006
3967
  }
4007
3968
  ];
4008
3969
  }
4009
- function buildUnignoreOp(follower, following) {
4010
- if (!follower || !following) {
4011
- throw new Error("[SDK][buildUnignoreOp] Missing required parameters");
4012
- }
4013
- return buildUnfollowOp(follower, following);
4014
- }
4015
- function buildSetLastReadOps(username, date) {
4016
- if (!username) {
4017
- throw new Error("[SDK][buildSetLastReadOps] Missing required parameters");
3970
+ function buildAccountUpdate2Op(account, jsonMetadata, postingJsonMetadata, extensions) {
3971
+ if (!account || postingJsonMetadata === void 0) {
3972
+ throw new Error("[SDK][buildAccountUpdate2Op] Missing required parameters");
4018
3973
  }
4019
- const lastReadDate = date || (/* @__PURE__ */ new Date()).toISOString().split(".")[0];
4020
- const notifyOp = [
4021
- "custom_json",
3974
+ return [
3975
+ "account_update2",
4022
3976
  {
4023
- id: "notify",
4024
- json: JSON.stringify(["setLastRead", { date: lastReadDate }]),
4025
- required_auths: [],
4026
- required_posting_auths: [username]
3977
+ account,
3978
+ json_metadata: jsonMetadata || "",
3979
+ posting_json_metadata: postingJsonMetadata,
3980
+ extensions: extensions || []
4027
3981
  }
4028
3982
  ];
4029
- const ecencyNotifyOp = [
4030
- "custom_json",
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",
4031
4005
  {
4032
- id: "ecency_notify",
4033
- json: JSON.stringify(["setLastRead", { date: lastReadDate }]),
4034
- required_auths: [],
4035
- required_posting_auths: [username]
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
4036
4015
  }
4037
4016
  ];
4038
- return [notifyOp, ecencyNotifyOp];
4039
4017
  }
4040
-
4041
- // src/modules/operations/builders/governance.ts
4042
- function buildWitnessVoteOp(account, witness, approve) {
4043
- if (!account || !witness || approve === void 0) {
4044
- throw new Error("[SDK][buildWitnessVoteOp] Missing required parameters");
4018
+ function buildCreateClaimedAccountOp(creator, newAccountName, keys) {
4019
+ if (!creator || !newAccountName || !keys) {
4020
+ throw new Error("[SDK][buildCreateClaimedAccountOp] Missing required parameters");
4045
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
+ };
4046
4037
  return [
4047
- "account_witness_vote",
4038
+ "create_claimed_account",
4048
4039
  {
4049
- account,
4050
- witness,
4051
- approve
4040
+ creator,
4041
+ new_account_name: newAccountName,
4042
+ owner,
4043
+ active,
4044
+ posting,
4045
+ memo_key: keys.memoPublicKey,
4046
+ json_metadata: "",
4047
+ extensions: []
4052
4048
  }
4053
4049
  ];
4054
4050
  }
4055
- function buildWitnessProxyOp(account, proxy) {
4056
- if (!account || proxy === void 0) {
4057
- throw new Error("[SDK][buildWitnessProxyOp] Missing required parameters");
4051
+ function buildClaimAccountOp(creator, fee) {
4052
+ if (!creator || !fee) {
4053
+ throw new Error("[SDK][buildClaimAccountOp] Missing required parameters");
4058
4054
  }
4059
4055
  return [
4060
- "account_witness_proxy",
4056
+ "claim_account",
4061
4057
  {
4062
- account,
4063
- proxy
4058
+ creator,
4059
+ fee,
4060
+ extensions: []
4064
4061
  }
4065
4062
  ];
4066
4063
  }
4067
- function buildProposalCreateOp(creator, payload) {
4068
- if (!creator || !payload.receiver || !payload.subject || !payload.permlink || !payload.start || !payload.end || !payload.dailyPay) {
4069
- throw new Error("[SDK][buildProposalCreateOp] Missing required parameters");
4064
+ function buildGrantPostingPermissionOp(account, currentPosting, grantedAccount, weightThreshold, memoKey, jsonMetadata) {
4065
+ if (!account || !currentPosting || !grantedAccount || !memoKey) {
4066
+ throw new Error("[SDK][buildGrantPostingPermissionOp] Missing required parameters");
4070
4067
  }
4071
- const startDate = new Date(payload.start);
4072
- const endDate = new Date(payload.end);
4073
- if (startDate.toString() === "Invalid Date" || endDate.toString() === "Invalid Date") {
4074
- throw new Error(
4075
- "[SDK][buildProposalCreateOp] Invalid date format: start and end must be valid ISO date strings"
4076
- );
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]);
4077
4076
  }
4077
+ const newPosting = {
4078
+ ...currentPosting,
4079
+ account_auths: newAccountAuths
4080
+ };
4081
+ newPosting.account_auths.sort((a, b) => a[0] > b[0] ? 1 : -1);
4078
4082
  return [
4079
- "create_proposal",
4083
+ "account_update",
4080
4084
  {
4081
- creator,
4082
- receiver: payload.receiver,
4083
- start_date: payload.start,
4084
- end_date: payload.end,
4085
- daily_pay: payload.dailyPay,
4086
- subject: payload.subject,
4087
- permlink: payload.permlink,
4088
- extensions: []
4085
+ account,
4086
+ posting: newPosting,
4087
+ memo_key: memoKey,
4088
+ json_metadata: jsonMetadata
4089
4089
  }
4090
4090
  ];
4091
4091
  }
4092
- function buildProposalVoteOp(voter, proposalIds, approve) {
4093
- if (!voter || !proposalIds || proposalIds.length === 0 || approve === void 0) {
4094
- throw new Error("[SDK][buildProposalVoteOp] Missing required parameters");
4092
+ function buildRevokePostingPermissionOp(account, currentPosting, revokedAccount, memoKey, jsonMetadata) {
4093
+ if (!account || !currentPosting || !revokedAccount || !memoKey) {
4094
+ throw new Error("[SDK][buildRevokePostingPermissionOp] Missing required parameters");
4095
4095
  }
4096
+ const newPosting = {
4097
+ ...currentPosting,
4098
+ account_auths: currentPosting.account_auths.filter(
4099
+ ([acc]) => acc !== revokedAccount
4100
+ )
4101
+ };
4096
4102
  return [
4097
- "update_proposal_votes",
4103
+ "account_update",
4098
4104
  {
4099
- voter,
4100
- proposal_ids: proposalIds,
4101
- approve,
4102
- extensions: []
4105
+ account,
4106
+ posting: newPosting,
4107
+ memo_key: memoKey,
4108
+ json_metadata: jsonMetadata
4103
4109
  }
4104
4110
  ];
4105
4111
  }
4106
- function buildRemoveProposalOp(proposalOwner, proposalIds) {
4107
- if (!proposalOwner || !proposalIds || proposalIds.length === 0) {
4108
- throw new Error("[SDK][buildRemoveProposalOp] Missing required parameters");
4112
+ function buildChangeRecoveryAccountOp(accountToRecover, newRecoveryAccount, extensions = []) {
4113
+ if (!accountToRecover || !newRecoveryAccount) {
4114
+ throw new Error("[SDK][buildChangeRecoveryAccountOp] Missing required parameters");
4109
4115
  }
4110
4116
  return [
4111
- "remove_proposal",
4117
+ "change_recovery_account",
4112
4118
  {
4113
- proposal_owner: proposalOwner,
4114
- proposal_ids: proposalIds,
4115
- extensions: []
4119
+ account_to_recover: accountToRecover,
4120
+ new_recovery_account: newRecoveryAccount,
4121
+ extensions
4116
4122
  }
4117
4123
  ];
4118
4124
  }
4119
- function buildUpdateProposalOp(proposalId, creator, dailyPay, subject, permlink) {
4120
- if (proposalId === void 0 || proposalId === null || typeof proposalId !== "number" || !creator || !dailyPay || !subject || !permlink) {
4121
- throw new Error("[SDK][buildUpdateProposalOp] Missing required parameters");
4125
+ function buildRequestAccountRecoveryOp(recoveryAccount, accountToRecover, newOwnerAuthority, extensions = []) {
4126
+ if (!recoveryAccount || !accountToRecover || !newOwnerAuthority) {
4127
+ throw new Error("[SDK][buildRequestAccountRecoveryOp] Missing required parameters");
4122
4128
  }
4123
4129
  return [
4124
- "update_proposal",
4130
+ "request_account_recovery",
4125
4131
  {
4126
- proposal_id: proposalId,
4127
- creator,
4128
- daily_pay: dailyPay,
4129
- subject,
4130
- permlink,
4131
- extensions: []
4132
+ recovery_account: recoveryAccount,
4133
+ account_to_recover: accountToRecover,
4134
+ new_owner_authority: newOwnerAuthority,
4135
+ extensions
4132
4136
  }
4133
4137
  ];
4134
4138
  }
4135
-
4136
- // src/modules/operations/builders/community.ts
4137
- function buildSubscribeOp(username, community) {
4138
- if (!username || !community) {
4139
- throw new Error("[SDK][buildSubscribeOp] Missing required parameters");
4139
+ function buildRecoverAccountOp(accountToRecover, newOwnerAuthority, recentOwnerAuthority, extensions = []) {
4140
+ if (!accountToRecover || !newOwnerAuthority || !recentOwnerAuthority) {
4141
+ throw new Error("[SDK][buildRecoverAccountOp] Missing required parameters");
4140
4142
  }
4141
4143
  return [
4142
- "custom_json",
4144
+ "recover_account",
4143
4145
  {
4144
- id: "community",
4145
- json: JSON.stringify(["subscribe", { community }]),
4146
- required_auths: [],
4147
- required_posting_auths: [username]
4146
+ account_to_recover: accountToRecover,
4147
+ new_owner_authority: newOwnerAuthority,
4148
+ recent_owner_authority: recentOwnerAuthority,
4149
+ extensions
4148
4150
  }
4149
4151
  ];
4150
4152
  }
4151
- function buildUnsubscribeOp(username, community) {
4152
- if (!username || !community) {
4153
- throw new Error("[SDK][buildUnsubscribeOp] Missing required parameters");
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");
4154
4158
  }
4155
4159
  return [
4156
4160
  "custom_json",
4157
4161
  {
4158
- id: "community",
4159
- json: JSON.stringify(["unsubscribe", { community }]),
4160
- required_auths: [],
4161
- required_posting_auths: [username]
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: []
4162
4171
  }
4163
4172
  ];
4164
4173
  }
4165
- function buildSetRoleOp(username, community, account, role) {
4166
- if (!username || !community || !account || !role) {
4167
- throw new Error("[SDK][buildSetRoleOp] Missing required parameters");
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");
4168
4183
  }
4169
4184
  return [
4170
4185
  "custom_json",
4171
4186
  {
4172
- id: "community",
4173
- json: JSON.stringify(["setRole", { community, account, role }]),
4174
- required_auths: [],
4175
- required_posting_auths: [username]
4187
+ id: "ecency_boost_plus",
4188
+ json: JSON.stringify({
4189
+ user,
4190
+ account,
4191
+ duration
4192
+ }),
4193
+ required_auths: [user],
4194
+ required_posting_auths: []
4176
4195
  }
4177
4196
  ];
4178
4197
  }
4179
- function buildUpdateCommunityOp(username, community, props) {
4180
- if (!username || !community || !props) {
4181
- throw new Error("[SDK][buildUpdateCommunityOp] Missing required parameters");
4198
+ function buildPromoteOp(user, author, permlink, duration) {
4199
+ if (!user || !author || !permlink || !Number.isFinite(duration)) {
4200
+ throw new Error("[SDK][buildPromoteOp] Missing required parameters");
4182
4201
  }
4183
4202
  return [
4184
4203
  "custom_json",
4185
4204
  {
4186
- id: "community",
4187
- json: JSON.stringify(["updateProps", { community, props }]),
4188
- required_auths: [],
4189
- required_posting_auths: [username]
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: []
4190
4214
  }
4191
4215
  ];
4192
4216
  }
4193
- function buildPinPostOp(username, community, account, permlink, pin) {
4194
- if (!username || !community || !account || !permlink || pin === void 0) {
4195
- throw new Error("[SDK][buildPinPostOp] Missing required parameters");
4217
+ function buildPointTransferOp(sender, receiver, amount, memo) {
4218
+ if (!sender || !receiver || !amount) {
4219
+ throw new Error("[SDK][buildPointTransferOp] Missing required parameters");
4196
4220
  }
4197
- const action = pin ? "pinPost" : "unpinPost";
4198
4221
  return [
4199
4222
  "custom_json",
4200
4223
  {
4201
- id: "community",
4202
- json: JSON.stringify([action, { community, account, permlink }]),
4203
- required_auths: [],
4204
- required_posting_auths: [username]
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: []
4205
4233
  }
4206
4234
  ];
4207
4235
  }
4208
- function buildMutePostOp(username, community, account, permlink, notes, mute) {
4209
- if (!username || !community || !account || !permlink || mute === void 0) {
4210
- throw new Error("[SDK][buildMutePostOp] Missing required parameters");
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");
4211
4251
  }
4212
- const action = mute ? "mutePost" : "unmutePost";
4213
4252
  return [
4214
4253
  "custom_json",
4215
4254
  {
4216
- id: "community",
4217
- json: JSON.stringify([action, { community, account, permlink, notes }]),
4218
- required_auths: [],
4219
- required_posting_auths: [username]
4255
+ id: "ecency_registration",
4256
+ json: JSON.stringify({
4257
+ name
4258
+ }),
4259
+ required_auths: [name],
4260
+ required_posting_auths: []
4220
4261
  }
4221
4262
  ];
4222
4263
  }
4223
- function buildMuteUserOp(username, community, account, notes, mute) {
4224
- if (!username || !community || !account || mute === void 0) {
4225
- throw new Error("[SDK][buildMuteUserOp] Missing required parameters");
4264
+ function buildActiveCustomJsonOp(username, operationId, json) {
4265
+ if (!username || !operationId || !json) {
4266
+ throw new Error("[SDK][buildActiveCustomJsonOp] Missing required parameters");
4226
4267
  }
4227
- const action = mute ? "muteUser" : "unmuteUser";
4228
4268
  return [
4229
4269
  "custom_json",
4230
4270
  {
4231
- id: "community",
4232
- json: JSON.stringify([action, { community, account, notes }]),
4233
- required_auths: [],
4234
- required_posting_auths: [username]
4271
+ id: operationId,
4272
+ json: JSON.stringify(json),
4273
+ required_auths: [username],
4274
+ required_posting_auths: []
4235
4275
  }
4236
4276
  ];
4237
4277
  }
4238
- function buildFlagPostOp(username, community, account, permlink, notes) {
4239
- if (!username || !community || !account || !permlink) {
4240
- throw new Error("[SDK][buildFlagPostOp] Missing required parameters");
4278
+ function buildPostingCustomJsonOp(username, operationId, json) {
4279
+ if (!username || !operationId || !json) {
4280
+ throw new Error("[SDK][buildPostingCustomJsonOp] Missing required parameters");
4241
4281
  }
4242
4282
  return [
4243
4283
  "custom_json",
4244
4284
  {
4245
- id: "community",
4246
- json: JSON.stringify(["flagPost", { community, account, permlink, notes }]),
4285
+ id: operationId,
4286
+ json: JSON.stringify(json),
4247
4287
  required_auths: [],
4248
4288
  required_posting_auths: [username]
4249
4289
  }
4250
4290
  ];
4251
4291
  }
4252
4292
 
4253
- // src/modules/operations/builders/market.ts
4254
- var BuySellTransactionType = /* @__PURE__ */ ((BuySellTransactionType2) => {
4255
- BuySellTransactionType2["Buy"] = "buy";
4256
- BuySellTransactionType2["Sell"] = "sell";
4257
- return BuySellTransactionType2;
4258
- })(BuySellTransactionType || {});
4259
- var OrderIdPrefix = /* @__PURE__ */ ((OrderIdPrefix2) => {
4260
- OrderIdPrefix2["EMPTY"] = "";
4261
- OrderIdPrefix2["SWAP"] = "9";
4262
- return OrderIdPrefix2;
4263
- })(OrderIdPrefix || {});
4264
- function buildLimitOrderCreateOp(owner, amountToSell, minToReceive, fillOrKill, expiration, orderId) {
4265
- if (!owner || !amountToSell || !minToReceive || !expiration || orderId === void 0) {
4266
- throw new Error("[SDK][buildLimitOrderCreateOp] Missing required parameters");
4267
- }
4268
- return [
4269
- "limit_order_create",
4270
- {
4271
- owner,
4272
- orderid: orderId,
4273
- amount_to_sell: amountToSell,
4274
- min_to_receive: minToReceive,
4275
- fill_or_kill: fillOrKill,
4276
- expiration
4277
- }
4278
- ];
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
+ );
4279
4311
  }
4280
- function formatNumber(value, decimals = 3) {
4281
- return value.toFixed(decimals);
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
+ },
4426
+ onError
4427
+ });
4282
4428
  }
4283
- function buildLimitOrderCreateOpWithType(owner, amountToSell, minToReceive, orderType, idPrefix = "" /* EMPTY */) {
4284
- if (!owner || orderType === void 0 || !Number.isFinite(amountToSell) || amountToSell <= 0 || !Number.isFinite(minToReceive) || minToReceive <= 0) {
4285
- throw new Error("[SDK][buildLimitOrderCreateOpWithType] Missing or invalid parameters");
4286
- }
4287
- const expiration = new Date(Date.now());
4288
- expiration.setDate(expiration.getDate() + 27);
4289
- const expirationStr = expiration.toISOString().split(".")[0];
4290
- const orderId = Number(
4291
- `${idPrefix}${Math.floor(Date.now() / 1e3).toString().slice(2)}`
4292
- );
4293
- const formattedAmountToSell = orderType === "buy" /* Buy */ ? `${formatNumber(amountToSell, 3)} HBD` : `${formatNumber(amountToSell, 3)} HIVE`;
4294
- const formattedMinToReceive = orderType === "buy" /* Buy */ ? `${formatNumber(minToReceive, 3)} HIVE` : `${formatNumber(minToReceive, 3)} HBD`;
4295
- return buildLimitOrderCreateOp(
4296
- owner,
4297
- formattedAmountToSell,
4298
- formattedMinToReceive,
4299
- false,
4300
- expirationStr,
4301
- orderId
4302
- );
4429
+ function useAccountFavouriteDelete(username, code, onSuccess, onError) {
4430
+ return reactQuery.useMutation({
4431
+ mutationKey: ["accounts", "favourites", "add", username],
4432
+ mutationFn: async (account) => {
4433
+ if (!username || !code) {
4434
+ throw new Error("[SDK][Account][Bookmarks] \u2013 missing auth");
4435
+ }
4436
+ const fetchApi = getBoundFetch();
4437
+ const response = await fetchApi(
4438
+ CONFIG.privateApiHost + "/private-api/favorites-delete",
4439
+ {
4440
+ method: "POST",
4441
+ headers: {
4442
+ "Content-Type": "application/json"
4443
+ },
4444
+ body: JSON.stringify({
4445
+ account,
4446
+ code
4447
+ })
4448
+ }
4449
+ );
4450
+ return response.json();
4451
+ },
4452
+ onSuccess: () => {
4453
+ onSuccess();
4454
+ getQueryClient().invalidateQueries({
4455
+ queryKey: ["accounts", "favourites", username]
4456
+ });
4457
+ },
4458
+ onError
4459
+ });
4303
4460
  }
4304
- function buildLimitOrderCancelOp(owner, orderId) {
4305
- if (!owner || orderId === void 0) {
4306
- throw new Error("[SDK][buildLimitOrderCancelOp] Missing required parameters");
4307
- }
4308
- return [
4309
- "limit_order_cancel",
4310
- {
4311
- owner,
4312
- orderid: orderId
4313
- }
4314
- ];
4461
+ function dedupeAndSortKeyAuths(existing, additions) {
4462
+ const merged = /* @__PURE__ */ new Map();
4463
+ existing.forEach(([key, weight]) => {
4464
+ merged.set(key.toString(), weight);
4465
+ });
4466
+ additions.forEach(([key, weight]) => {
4467
+ merged.set(key.toString(), weight);
4468
+ });
4469
+ return Array.from(merged.entries()).sort(([keyA], [keyB]) => keyA.localeCompare(keyB)).map(([key, weight]) => [key, weight]);
4315
4470
  }
4316
- function buildClaimRewardBalanceOp(account, rewardHive, rewardHbd, rewardVests) {
4317
- if (!account || !rewardHive || !rewardHbd || !rewardVests) {
4318
- throw new Error("[SDK][buildClaimRewardBalanceOp] Missing required parameters");
4319
- }
4320
- return [
4321
- "claim_reward_balance",
4322
- {
4323
- account,
4324
- reward_hive: rewardHive,
4325
- reward_hbd: rewardHbd,
4326
- reward_vests: rewardVests
4327
- }
4328
- ];
4471
+ function useAccountUpdateKeyAuths(username, options) {
4472
+ const { data: accountData } = reactQuery.useQuery(getAccountFullQueryOptions(username));
4473
+ return reactQuery.useMutation({
4474
+ mutationKey: ["accounts", "keys-update", username],
4475
+ mutationFn: async ({
4476
+ keys,
4477
+ keepCurrent = false,
4478
+ currentKey,
4479
+ keysToRevoke = [],
4480
+ keysToRevokeByAuthority = {}
4481
+ }) => {
4482
+ if (keys.length === 0) {
4483
+ throw new Error(
4484
+ "[SDK][Update password] \u2013 no new keys provided"
4485
+ );
4486
+ }
4487
+ if (!accountData) {
4488
+ throw new Error(
4489
+ "[SDK][Update password] \u2013 cannot update keys for anon user"
4490
+ );
4491
+ }
4492
+ const prepareAuth = (keyName) => {
4493
+ const auth = R4__namespace.clone(accountData[keyName]);
4494
+ const keysToRevokeForAuthority = keysToRevokeByAuthority[keyName] || [];
4495
+ const allKeysToRevoke = [
4496
+ ...keysToRevokeForAuthority,
4497
+ ...keysToRevokeByAuthority[keyName] === void 0 ? keysToRevoke : []
4498
+ ];
4499
+ const existingKeys = keepCurrent ? auth.key_auths.filter(([key]) => !allKeysToRevoke.includes(key.toString())) : [];
4500
+ auth.key_auths = dedupeAndSortKeyAuths(
4501
+ existingKeys,
4502
+ keys.map(
4503
+ (values, i) => [values[keyName].createPublic().toString(), i + 1]
4504
+ )
4505
+ );
4506
+ return auth;
4507
+ };
4508
+ return CONFIG.hiveClient.broadcast.updateAccount(
4509
+ {
4510
+ account: username,
4511
+ json_metadata: accountData.json_metadata,
4512
+ owner: prepareAuth("owner"),
4513
+ active: prepareAuth("active"),
4514
+ posting: prepareAuth("posting"),
4515
+ // Always use new memo key when adding new keys
4516
+ memo_key: keys[0].memo_key.createPublic().toString()
4517
+ },
4518
+ currentKey
4519
+ );
4520
+ },
4521
+ ...options
4522
+ });
4329
4523
  }
4330
-
4331
- // src/modules/operations/builders/account.ts
4332
- function buildAccountUpdateOp(account, owner, active, posting, memoKey, jsonMetadata) {
4333
- if (!account || !memoKey) {
4334
- throw new Error("[SDK][buildAccountUpdateOp] Missing required parameters");
4335
- }
4336
- return [
4337
- "account_update",
4338
- {
4339
- account,
4340
- owner,
4341
- active,
4342
- posting,
4343
- memo_key: memoKey,
4344
- json_metadata: jsonMetadata
4345
- }
4346
- ];
4524
+ function useAccountUpdatePassword(username, options) {
4525
+ const { data: accountData } = reactQuery.useQuery(getAccountFullQueryOptions(username));
4526
+ const { mutateAsync: updateKeys } = useAccountUpdateKeyAuths(username);
4527
+ return reactQuery.useMutation({
4528
+ mutationKey: ["accounts", "password-update", username],
4529
+ mutationFn: async ({
4530
+ newPassword,
4531
+ currentPassword,
4532
+ keepCurrent
4533
+ }) => {
4534
+ if (!accountData) {
4535
+ throw new Error(
4536
+ "[SDK][Update password] \u2013 cannot update password for anon user"
4537
+ );
4538
+ }
4539
+ const currentKey = dhive.PrivateKey.fromLogin(
4540
+ username,
4541
+ currentPassword,
4542
+ "owner"
4543
+ );
4544
+ return updateKeys({
4545
+ currentKey,
4546
+ keepCurrent,
4547
+ keys: [
4548
+ {
4549
+ owner: dhive.PrivateKey.fromLogin(username, newPassword, "owner"),
4550
+ active: dhive.PrivateKey.fromLogin(username, newPassword, "active"),
4551
+ posting: dhive.PrivateKey.fromLogin(username, newPassword, "posting"),
4552
+ memo_key: dhive.PrivateKey.fromLogin(username, newPassword, "memo")
4553
+ }
4554
+ ]
4555
+ });
4556
+ },
4557
+ ...options
4558
+ });
4347
4559
  }
4348
- function buildAccountUpdate2Op(account, jsonMetadata, postingJsonMetadata, extensions) {
4349
- if (!account || postingJsonMetadata === void 0) {
4350
- throw new Error("[SDK][buildAccountUpdate2Op] Missing required parameters");
4351
- }
4352
- return [
4353
- "account_update2",
4354
- {
4355
- account,
4356
- json_metadata: jsonMetadata || "",
4357
- posting_json_metadata: postingJsonMetadata,
4358
- extensions: extensions || []
4560
+ function useAccountRevokePosting(username, options, auth) {
4561
+ const queryClient = reactQuery.useQueryClient();
4562
+ const { data } = reactQuery.useQuery(getAccountFullQueryOptions(username));
4563
+ return reactQuery.useMutation({
4564
+ mutationKey: ["accounts", "revoke-posting", data?.name],
4565
+ mutationFn: async ({ accountName, type, key }) => {
4566
+ if (!data) {
4567
+ throw new Error(
4568
+ "[SDK][Accounts] \u2013\xA0cannot revoke posting for anonymous user"
4569
+ );
4570
+ }
4571
+ const posting = R4__namespace.pipe(
4572
+ {},
4573
+ R4__namespace.mergeDeep(data.posting)
4574
+ );
4575
+ posting.account_auths = posting.account_auths.filter(
4576
+ ([account]) => account !== accountName
4577
+ );
4578
+ const operationBody = {
4579
+ account: data.name,
4580
+ posting,
4581
+ memo_key: data.memo_key,
4582
+ json_metadata: data.json_metadata
4583
+ };
4584
+ if (type === "key" && key) {
4585
+ return CONFIG.hiveClient.broadcast.updateAccount(operationBody, key);
4586
+ } else if (type === "keychain") {
4587
+ if (!auth?.broadcast) {
4588
+ throw new Error("[SDK][Accounts] \u2013 missing keychain broadcaster");
4589
+ }
4590
+ return auth.broadcast([["account_update", operationBody]], "active");
4591
+ } else {
4592
+ const params = {
4593
+ callback: `https://ecency.com/@${data.name}/permissions`
4594
+ };
4595
+ return hs__default.default.sendOperation(
4596
+ ["account_update", operationBody],
4597
+ params,
4598
+ () => {
4599
+ }
4600
+ );
4601
+ }
4602
+ },
4603
+ onError: options.onError,
4604
+ onSuccess: (resp, payload, ctx) => {
4605
+ options.onSuccess?.(resp, payload, ctx);
4606
+ queryClient.setQueryData(
4607
+ getAccountFullQueryOptions(username).queryKey,
4608
+ (data2) => ({
4609
+ ...data2,
4610
+ posting: {
4611
+ ...data2?.posting,
4612
+ account_auths: data2?.posting?.account_auths?.filter(
4613
+ ([account]) => account !== payload.accountName
4614
+ ) ?? []
4615
+ }
4616
+ })
4617
+ );
4359
4618
  }
4360
- ];
4619
+ });
4361
4620
  }
4362
- function buildAccountCreateOp(creator, newAccountName, keys, fee) {
4363
- if (!creator || !newAccountName || !keys || !fee) {
4364
- throw new Error("[SDK][buildAccountCreateOp] Missing required parameters");
4365
- }
4366
- const owner = {
4367
- weight_threshold: 1,
4368
- account_auths: [],
4369
- key_auths: [[keys.ownerPublicKey, 1]]
4370
- };
4371
- const active = {
4372
- weight_threshold: 1,
4373
- account_auths: [],
4374
- key_auths: [[keys.activePublicKey, 1]]
4375
- };
4376
- const posting = {
4377
- weight_threshold: 1,
4378
- account_auths: [["ecency.app", 1]],
4379
- key_auths: [[keys.postingPublicKey, 1]]
4380
- };
4381
- return [
4382
- "account_create",
4383
- {
4384
- creator,
4385
- new_account_name: newAccountName,
4386
- owner,
4387
- active,
4388
- posting,
4389
- memo_key: keys.memoPublicKey,
4390
- json_metadata: "",
4391
- extensions: [],
4392
- fee
4393
- }
4394
- ];
4621
+ function useAccountUpdateRecovery(username, code, options, auth) {
4622
+ const { data } = reactQuery.useQuery(getAccountFullQueryOptions(username));
4623
+ return reactQuery.useMutation({
4624
+ mutationKey: ["accounts", "recovery", data?.name],
4625
+ mutationFn: async ({ accountName, type, key, email }) => {
4626
+ if (!data) {
4627
+ throw new Error(
4628
+ "[SDK][Accounts] \u2013\xA0cannot change recovery for anonymous user"
4629
+ );
4630
+ }
4631
+ const operationBody = {
4632
+ account_to_recover: data.name,
4633
+ new_recovery_account: accountName,
4634
+ extensions: []
4635
+ };
4636
+ if (type === "ecency") {
4637
+ if (!code) {
4638
+ throw new Error("[SDK][Accounts] \u2013 missing access token");
4639
+ }
4640
+ const fetchApi = getBoundFetch();
4641
+ return fetchApi(CONFIG.privateApiHost + "/private-api/recoveries-add", {
4642
+ method: "POST",
4643
+ body: JSON.stringify({
4644
+ code,
4645
+ email,
4646
+ publicKeys: [
4647
+ ...data.owner.key_auths,
4648
+ ...data.active.key_auths,
4649
+ ...data.posting.key_auths,
4650
+ data.memo_key
4651
+ ]
4652
+ })
4653
+ });
4654
+ } else if (type === "key" && key) {
4655
+ return CONFIG.hiveClient.broadcast.sendOperations(
4656
+ [["change_recovery_account", operationBody]],
4657
+ key
4658
+ );
4659
+ } else if (type === "keychain") {
4660
+ if (!auth?.broadcast) {
4661
+ throw new Error("[SDK][Accounts] \u2013 missing keychain broadcaster");
4662
+ }
4663
+ return auth.broadcast([["change_recovery_account", operationBody]], "owner");
4664
+ } else {
4665
+ const params = {
4666
+ callback: `https://ecency.com/@${data.name}/permissions`
4667
+ };
4668
+ return hs__default.default.sendOperation(
4669
+ ["change_recovery_account", operationBody],
4670
+ params,
4671
+ () => {
4672
+ }
4673
+ );
4674
+ }
4675
+ },
4676
+ onError: options.onError,
4677
+ onSuccess: options.onSuccess
4678
+ });
4395
4679
  }
4396
- function buildCreateClaimedAccountOp(creator, newAccountName, keys) {
4397
- if (!creator || !newAccountName || !keys) {
4398
- throw new Error("[SDK][buildCreateClaimedAccountOp] Missing required parameters");
4399
- }
4400
- const owner = {
4401
- weight_threshold: 1,
4402
- account_auths: [],
4403
- key_auths: [[keys.ownerPublicKey, 1]]
4404
- };
4405
- const active = {
4406
- weight_threshold: 1,
4407
- account_auths: [],
4408
- key_auths: [[keys.activePublicKey, 1]]
4409
- };
4410
- const posting = {
4411
- weight_threshold: 1,
4412
- account_auths: [["ecency.app", 1]],
4413
- key_auths: [[keys.postingPublicKey, 1]]
4414
- };
4415
- return [
4416
- "create_claimed_account",
4417
- {
4418
- creator,
4419
- new_account_name: newAccountName,
4420
- owner,
4421
- active,
4422
- posting,
4423
- memo_key: keys.memoPublicKey,
4424
- json_metadata: "",
4425
- extensions: []
4426
- }
4427
- ];
4680
+ function useAccountRevokeKey(username, options) {
4681
+ const { data: accountData } = reactQuery.useQuery(getAccountFullQueryOptions(username));
4682
+ return reactQuery.useMutation({
4683
+ mutationKey: ["accounts", "revoke-key", accountData?.name],
4684
+ mutationFn: async ({ currentKey, revokingKey }) => {
4685
+ if (!accountData) {
4686
+ throw new Error(
4687
+ "[SDK][Update password] \u2013 cannot update keys for anon user"
4688
+ );
4689
+ }
4690
+ const prepareAuth = (keyName) => {
4691
+ const auth = R4__namespace.clone(accountData[keyName]);
4692
+ auth.key_auths = auth.key_auths.filter(
4693
+ ([key]) => key !== revokingKey.toString()
4694
+ );
4695
+ return auth;
4696
+ };
4697
+ return CONFIG.hiveClient.broadcast.updateAccount(
4698
+ {
4699
+ account: accountData.name,
4700
+ json_metadata: accountData.json_metadata,
4701
+ owner: prepareAuth("owner"),
4702
+ active: prepareAuth("active"),
4703
+ posting: prepareAuth("posting"),
4704
+ memo_key: accountData.memo_key
4705
+ },
4706
+ currentKey
4707
+ );
4708
+ },
4709
+ ...options
4710
+ });
4428
4711
  }
4429
- function buildClaimAccountOp(creator, fee) {
4430
- if (!creator || !fee) {
4431
- throw new Error("[SDK][buildClaimAccountOp] Missing required parameters");
4432
- }
4433
- return [
4434
- "claim_account",
4435
- {
4436
- creator,
4437
- fee,
4438
- extensions: []
4439
- }
4440
- ];
4712
+
4713
+ // src/modules/accounts/utils/account-power.ts
4714
+ var HIVE_VOTING_MANA_REGENERATION_SECONDS = 5 * 60 * 60 * 24;
4715
+ function vestsToRshares(vests, votingPowerValue, votePerc) {
4716
+ const vestingShares = vests * 1e6;
4717
+ const power = votingPowerValue * votePerc / 1e4 / 50 + 1;
4718
+ return power * vestingShares / 1e4;
4441
4719
  }
4442
- function buildGrantPostingPermissionOp(account, currentPosting, grantedAccount, weightThreshold, memoKey, jsonMetadata) {
4443
- if (!account || !currentPosting || !grantedAccount || !memoKey) {
4444
- throw new Error("[SDK][buildGrantPostingPermissionOp] Missing required parameters");
4445
- }
4446
- const existingIndex = currentPosting.account_auths.findIndex(
4447
- ([acc]) => acc === grantedAccount
4448
- );
4449
- const newAccountAuths = [...currentPosting.account_auths];
4450
- if (existingIndex >= 0) {
4451
- newAccountAuths[existingIndex] = [grantedAccount, weightThreshold];
4452
- } else {
4453
- newAccountAuths.push([grantedAccount, weightThreshold]);
4454
- }
4455
- const newPosting = {
4456
- ...currentPosting,
4457
- account_auths: newAccountAuths
4720
+ function toDhiveAccountForVotingMana(account) {
4721
+ return {
4722
+ id: 0,
4723
+ name: account.name,
4724
+ owner: account.owner,
4725
+ active: account.active,
4726
+ posting: account.posting,
4727
+ memo_key: account.memo_key,
4728
+ json_metadata: account.json_metadata,
4729
+ posting_json_metadata: account.posting_json_metadata,
4730
+ proxy: account.proxy ?? "",
4731
+ last_owner_update: "",
4732
+ last_account_update: "",
4733
+ created: account.created,
4734
+ mined: false,
4735
+ owner_challenged: false,
4736
+ active_challenged: false,
4737
+ last_owner_proved: "",
4738
+ last_active_proved: "",
4739
+ recovery_account: account.recovery_account ?? "",
4740
+ reset_account: "",
4741
+ last_account_recovery: "",
4742
+ comment_count: 0,
4743
+ lifetime_vote_count: 0,
4744
+ post_count: account.post_count,
4745
+ can_vote: true,
4746
+ voting_power: account.voting_power,
4747
+ last_vote_time: account.last_vote_time,
4748
+ voting_manabar: account.voting_manabar,
4749
+ balance: account.balance,
4750
+ savings_balance: account.savings_balance,
4751
+ hbd_balance: account.hbd_balance,
4752
+ hbd_seconds: "0",
4753
+ hbd_seconds_last_update: "",
4754
+ hbd_last_interest_payment: "",
4755
+ savings_hbd_balance: account.savings_hbd_balance,
4756
+ savings_hbd_seconds: account.savings_hbd_seconds,
4757
+ savings_hbd_seconds_last_update: account.savings_hbd_seconds_last_update,
4758
+ savings_hbd_last_interest_payment: account.savings_hbd_last_interest_payment,
4759
+ savings_withdraw_requests: 0,
4760
+ reward_hbd_balance: account.reward_hbd_balance,
4761
+ reward_hive_balance: account.reward_hive_balance,
4762
+ reward_vesting_balance: account.reward_vesting_balance,
4763
+ reward_vesting_hive: account.reward_vesting_hive,
4764
+ curation_rewards: 0,
4765
+ posting_rewards: 0,
4766
+ vesting_shares: account.vesting_shares,
4767
+ delegated_vesting_shares: account.delegated_vesting_shares,
4768
+ received_vesting_shares: account.received_vesting_shares,
4769
+ vesting_withdraw_rate: account.vesting_withdraw_rate,
4770
+ next_vesting_withdrawal: account.next_vesting_withdrawal,
4771
+ withdrawn: account.withdrawn,
4772
+ to_withdraw: account.to_withdraw,
4773
+ withdraw_routes: 0,
4774
+ proxied_vsf_votes: account.proxied_vsf_votes ?? [],
4775
+ witnesses_voted_for: 0,
4776
+ average_bandwidth: 0,
4777
+ lifetime_bandwidth: 0,
4778
+ last_bandwidth_update: "",
4779
+ average_market_bandwidth: 0,
4780
+ lifetime_market_bandwidth: 0,
4781
+ last_market_bandwidth_update: "",
4782
+ last_post: account.last_post,
4783
+ last_root_post: ""
4458
4784
  };
4459
- newPosting.account_auths.sort((a, b) => a[0] > b[0] ? 1 : -1);
4460
- return [
4461
- "account_update",
4462
- {
4463
- account,
4464
- posting: newPosting,
4465
- memo_key: memoKey,
4466
- json_metadata: jsonMetadata
4467
- }
4468
- ];
4469
4785
  }
4470
- function buildRevokePostingPermissionOp(account, currentPosting, revokedAccount, memoKey, jsonMetadata) {
4471
- if (!account || !currentPosting || !revokedAccount || !memoKey) {
4472
- throw new Error("[SDK][buildRevokePostingPermissionOp] Missing required parameters");
4473
- }
4474
- const newPosting = {
4475
- ...currentPosting,
4476
- account_auths: currentPosting.account_auths.filter(
4477
- ([acc]) => acc !== revokedAccount
4478
- )
4479
- };
4480
- return [
4481
- "account_update",
4482
- {
4483
- account,
4484
- posting: newPosting,
4485
- memo_key: memoKey,
4486
- json_metadata: jsonMetadata
4487
- }
4488
- ];
4786
+ function votingPower(account) {
4787
+ const calc = CONFIG.hiveClient.rc.calculateVPMana(
4788
+ toDhiveAccountForVotingMana(account)
4789
+ );
4790
+ return calc.percentage / 100;
4489
4791
  }
4490
- function buildChangeRecoveryAccountOp(accountToRecover, newRecoveryAccount, extensions = []) {
4491
- if (!accountToRecover || !newRecoveryAccount) {
4492
- throw new Error("[SDK][buildChangeRecoveryAccountOp] Missing required parameters");
4792
+ function powerRechargeTime(power) {
4793
+ if (!Number.isFinite(power)) {
4794
+ throw new TypeError("Voting power must be a finite number");
4493
4795
  }
4494
- return [
4495
- "change_recovery_account",
4496
- {
4497
- account_to_recover: accountToRecover,
4498
- new_recovery_account: newRecoveryAccount,
4499
- extensions
4500
- }
4501
- ];
4502
- }
4503
- function buildRequestAccountRecoveryOp(recoveryAccount, accountToRecover, newOwnerAuthority, extensions = []) {
4504
- if (!recoveryAccount || !accountToRecover || !newOwnerAuthority) {
4505
- throw new Error("[SDK][buildRequestAccountRecoveryOp] Missing required parameters");
4796
+ if (power < 0 || power > 100) {
4797
+ throw new RangeError("Voting power must be between 0 and 100");
4506
4798
  }
4507
- return [
4508
- "request_account_recovery",
4509
- {
4510
- recovery_account: recoveryAccount,
4511
- account_to_recover: accountToRecover,
4512
- new_owner_authority: newOwnerAuthority,
4513
- extensions
4514
- }
4515
- ];
4799
+ const missingPower = 100 - power;
4800
+ return missingPower * 100 * HIVE_VOTING_MANA_REGENERATION_SECONDS / 1e4;
4516
4801
  }
4517
- function buildRecoverAccountOp(accountToRecover, newOwnerAuthority, recentOwnerAuthority, extensions = []) {
4518
- if (!accountToRecover || !newOwnerAuthority || !recentOwnerAuthority) {
4519
- throw new Error("[SDK][buildRecoverAccountOp] Missing required parameters");
4802
+ function downVotingPower(account) {
4803
+ const totalShares = parseFloat(account.vesting_shares) + parseFloat(account.received_vesting_shares) - parseFloat(account.delegated_vesting_shares);
4804
+ const elapsed = Math.floor(Date.now() / 1e3) - account.downvote_manabar.last_update_time;
4805
+ const maxMana = totalShares * 1e6 / 4;
4806
+ if (maxMana <= 0) {
4807
+ return 0;
4520
4808
  }
4521
- return [
4522
- "recover_account",
4523
- {
4524
- account_to_recover: accountToRecover,
4525
- new_owner_authority: newOwnerAuthority,
4526
- recent_owner_authority: recentOwnerAuthority,
4527
- extensions
4528
- }
4529
- ];
4530
- }
4531
-
4532
- // src/modules/operations/builders/ecency.ts
4533
- function buildBoostOp(user, author, permlink, amount) {
4534
- if (!user || !author || !permlink || !amount) {
4535
- throw new Error("[SDK][buildBoostOp] Missing required parameters");
4809
+ let currentMana = parseFloat(account.downvote_manabar.current_mana.toString()) + elapsed * maxMana / HIVE_VOTING_MANA_REGENERATION_SECONDS;
4810
+ if (currentMana > maxMana) {
4811
+ currentMana = maxMana;
4536
4812
  }
4537
- return [
4538
- "custom_json",
4539
- {
4540
- id: "ecency_boost",
4541
- json: JSON.stringify({
4542
- user,
4543
- author,
4544
- permlink,
4545
- amount
4546
- }),
4547
- required_auths: [user],
4548
- required_posting_auths: []
4549
- }
4550
- ];
4551
- }
4552
- function buildBoostOpWithPoints(user, author, permlink, points) {
4553
- if (!user || !author || !permlink || !Number.isFinite(points)) {
4554
- throw new Error("[SDK][buildBoostOpWithPoints] Missing required parameters");
4813
+ const currentManaPerc = currentMana * 100 / maxMana;
4814
+ if (isNaN(currentManaPerc)) {
4815
+ return 0;
4555
4816
  }
4556
- return buildBoostOp(user, author, permlink, `${points.toFixed(3)} POINT`);
4557
- }
4558
- function buildBoostPlusOp(user, account, duration) {
4559
- if (!user || !account || !Number.isFinite(duration)) {
4560
- throw new Error("[SDK][buildBoostPlusOp] Missing required parameters");
4817
+ if (currentManaPerc > 100) {
4818
+ return 100;
4561
4819
  }
4562
- return [
4563
- "custom_json",
4564
- {
4565
- id: "ecency_boost_plus",
4566
- json: JSON.stringify({
4567
- user,
4568
- account,
4569
- duration
4570
- }),
4571
- required_auths: [user],
4572
- required_posting_auths: []
4573
- }
4574
- ];
4820
+ return currentManaPerc;
4575
4821
  }
4576
- function buildPromoteOp(user, author, permlink, duration) {
4577
- if (!user || !author || !permlink || !Number.isFinite(duration)) {
4578
- throw new Error("[SDK][buildPromoteOp] Missing required parameters");
4579
- }
4580
- return [
4581
- "custom_json",
4582
- {
4583
- id: "ecency_promote",
4584
- json: JSON.stringify({
4585
- user,
4586
- author,
4587
- permlink,
4588
- duration
4589
- }),
4590
- required_auths: [user],
4591
- required_posting_auths: []
4592
- }
4593
- ];
4822
+ function rcPower(account) {
4823
+ const calc = CONFIG.hiveClient.rc.calculateRCMana(account);
4824
+ return calc.percentage / 100;
4594
4825
  }
4595
- function buildPointTransferOp(sender, receiver, amount, memo) {
4596
- if (!sender || !receiver || !amount) {
4597
- throw new Error("[SDK][buildPointTransferOp] Missing required parameters");
4826
+ function votingValue(account, dynamicProps, votingPowerValue, weight = 1e4) {
4827
+ if (!Number.isFinite(votingPowerValue) || !Number.isFinite(weight)) {
4828
+ return 0;
4598
4829
  }
4599
- return [
4600
- "custom_json",
4601
- {
4602
- id: "ecency_point_transfer",
4603
- json: JSON.stringify({
4604
- sender,
4605
- receiver,
4606
- amount,
4607
- memo: memo || ""
4608
- }),
4609
- required_auths: [sender],
4610
- required_posting_auths: []
4830
+ const { fundRecentClaims, fundRewardBalance, base, quote } = dynamicProps;
4831
+ if (!Number.isFinite(fundRecentClaims) || !Number.isFinite(fundRewardBalance) || !Number.isFinite(base) || !Number.isFinite(quote)) {
4832
+ return 0;
4833
+ }
4834
+ if (fundRecentClaims === 0 || quote === 0) {
4835
+ return 0;
4836
+ }
4837
+ let totalVests = 0;
4838
+ try {
4839
+ const vesting = parseAsset(account.vesting_shares).amount;
4840
+ const received = parseAsset(account.received_vesting_shares).amount;
4841
+ const delegated = parseAsset(account.delegated_vesting_shares).amount;
4842
+ if (![vesting, received, delegated].every(Number.isFinite)) {
4843
+ return 0;
4611
4844
  }
4612
- ];
4613
- }
4614
- function buildMultiPointTransferOps(sender, destinations, amount, memo) {
4615
- if (!sender || !destinations || !amount) {
4616
- throw new Error("[SDK][buildMultiPointTransferOps] Missing required parameters");
4845
+ totalVests = vesting + received - delegated;
4846
+ } catch {
4847
+ return 0;
4617
4848
  }
4618
- const destArray = destinations.trim().split(/[\s,]+/).filter(Boolean);
4619
- if (destArray.length === 0) {
4620
- throw new Error("[SDK][buildMultiPointTransferOps] Missing valid destinations");
4849
+ if (!Number.isFinite(totalVests)) {
4850
+ return 0;
4621
4851
  }
4622
- return destArray.map(
4623
- (dest) => buildPointTransferOp(sender, dest.trim(), amount, memo)
4624
- );
4852
+ const rShares = vestsToRshares(totalVests, votingPowerValue, weight);
4853
+ if (!Number.isFinite(rShares)) {
4854
+ return 0;
4855
+ }
4856
+ return rShares / fundRecentClaims * fundRewardBalance * (base / quote);
4625
4857
  }
4626
- function buildCommunityRegistrationOp(name) {
4627
- if (!name) {
4628
- throw new Error("[SDK][buildCommunityRegistrationOp] Missing required parameters");
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");
4629
4906
  }
4630
- return [
4631
- "custom_json",
4632
- {
4633
- id: "ecency_registration",
4634
- json: JSON.stringify({
4635
- name
4636
- }),
4637
- required_auths: [name],
4638
- required_posting_auths: []
4639
- }
4640
- ];
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";
4641
4915
  }
4642
- function buildActiveCustomJsonOp(username, operationId, json) {
4643
- if (!username || !operationId || !json) {
4644
- throw new Error("[SDK][buildActiveCustomJsonOp] Missing required parameters");
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");
4645
4920
  }
4646
- return [
4647
- "custom_json",
4648
- {
4649
- id: operationId,
4650
- json: JSON.stringify(json),
4651
- required_auths: [username],
4652
- required_posting_auths: []
4653
- }
4654
- ];
4921
+ return "active";
4655
4922
  }
4656
- function buildPostingCustomJsonOp(username, operationId, json) {
4657
- if (!username || !operationId || !json) {
4658
- throw new Error("[SDK][buildPostingCustomJsonOp] Missing required parameters");
4923
+ function getOperationAuthority(op) {
4924
+ const opType = op[0];
4925
+ if (opType === "custom_json") {
4926
+ return getCustomJsonAuthority(op);
4659
4927
  }
4660
- return [
4661
- "custom_json",
4662
- {
4663
- id: operationId,
4664
- json: JSON.stringify(json),
4665
- required_auths: [],
4666
- required_posting_auths: [username]
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";
4667
4939
  }
4668
- ];
4940
+ if (authority === "active" && highestAuthority === "posting") {
4941
+ highestAuthority = "active";
4942
+ }
4943
+ }
4944
+ return highestAuthority;
4669
4945
  }
4670
4946
  function useSignOperationByKey(username) {
4671
4947
  return reactQuery.useMutation({
@@ -5458,7 +5734,9 @@ function useComment(username, auth) {
5458
5734
  if (auth?.adapter?.invalidateQueries) {
5459
5735
  const queriesToInvalidate = [
5460
5736
  ["posts", "feed", username],
5461
- ["posts", "blog", username]
5737
+ ["posts", "blog", username],
5738
+ ["account", username, "rc"]
5739
+ // RC decreases after posting/commenting
5462
5740
  ];
5463
5741
  if (!isPost) {
5464
5742
  queriesToInvalidate.push([
@@ -7671,6 +7949,7 @@ exports.NaiMap = NaiMap;
7671
7949
  exports.NotificationFilter = NotificationFilter;
7672
7950
  exports.NotificationViewType = NotificationViewType;
7673
7951
  exports.NotifyTypes = NotifyTypes;
7952
+ exports.OPERATION_AUTHORITY_MAP = OPERATION_AUTHORITY_MAP;
7674
7953
  exports.OrderIdPrefix = OrderIdPrefix;
7675
7954
  exports.ROLES = ROLES;
7676
7955
  exports.SortOrder = SortOrder;
@@ -7792,6 +8071,7 @@ exports.getCurrencyRate = getCurrencyRate;
7792
8071
  exports.getCurrencyRates = getCurrencyRates;
7793
8072
  exports.getCurrencyTokenRate = getCurrencyTokenRate;
7794
8073
  exports.getCurrentMedianHistoryPriceQueryOptions = getCurrentMedianHistoryPriceQueryOptions;
8074
+ exports.getCustomJsonAuthority = getCustomJsonAuthority;
7795
8075
  exports.getDeletedEntryQueryOptions = getDeletedEntryQueryOptions;
7796
8076
  exports.getDiscoverCurationQueryOptions = getDiscoverCurationQueryOptions;
7797
8077
  exports.getDiscoverLeaderboardQueryOptions = getDiscoverLeaderboardQueryOptions;
@@ -7841,6 +8121,7 @@ exports.getNotificationsInfiniteQueryOptions = getNotificationsInfiniteQueryOpti
7841
8121
  exports.getNotificationsSettingsQueryOptions = getNotificationsSettingsQueryOptions;
7842
8122
  exports.getNotificationsUnreadCountQueryOptions = getNotificationsUnreadCountQueryOptions;
7843
8123
  exports.getOpenOrdersQueryOptions = getOpenOrdersQueryOptions;
8124
+ exports.getOperationAuthority = getOperationAuthority;
7844
8125
  exports.getOrderBookQueryOptions = getOrderBookQueryOptions;
7845
8126
  exports.getOutgoingRcDelegationsInfiniteQueryOptions = getOutgoingRcDelegationsInfiniteQueryOptions;
7846
8127
  exports.getPageStatsQueryOptions = getPageStatsQueryOptions;
@@ -7859,6 +8140,7 @@ exports.getProfilesQueryOptions = getProfilesQueryOptions;
7859
8140
  exports.getPromotePriceQueryOptions = getPromotePriceQueryOptions;
7860
8141
  exports.getPromotedPost = getPromotedPost;
7861
8142
  exports.getPromotedPostsQuery = getPromotedPostsQuery;
8143
+ exports.getProposalAuthority = getProposalAuthority;
7862
8144
  exports.getProposalQueryOptions = getProposalQueryOptions;
7863
8145
  exports.getProposalVotesInfiniteQueryOptions = getProposalVotesInfiniteQueryOptions;
7864
8146
  exports.getProposalsQueryOptions = getProposalsQueryOptions;
@@ -7872,6 +8154,7 @@ exports.getReferralsInfiniteQueryOptions = getReferralsInfiniteQueryOptions;
7872
8154
  exports.getReferralsStatsQueryOptions = getReferralsStatsQueryOptions;
7873
8155
  exports.getRelationshipBetweenAccounts = getRelationshipBetweenAccounts;
7874
8156
  exports.getRelationshipBetweenAccountsQueryOptions = getRelationshipBetweenAccountsQueryOptions;
8157
+ exports.getRequiredAuthority = getRequiredAuthority;
7875
8158
  exports.getRewardFundQueryOptions = getRewardFundQueryOptions;
7876
8159
  exports.getRewardedCommunitiesQueryOptions = getRewardedCommunitiesQueryOptions;
7877
8160
  exports.getSavingsWithdrawFromQueryOptions = getSavingsWithdrawFromQueryOptions;
@@ -7960,6 +8243,7 @@ exports.useDeleteDraft = useDeleteDraft;
7960
8243
  exports.useDeleteImage = useDeleteImage;
7961
8244
  exports.useDeleteSchedule = useDeleteSchedule;
7962
8245
  exports.useEditFragment = useEditFragment;
8246
+ exports.useFollow = useFollow;
7963
8247
  exports.useGameClaim = useGameClaim;
7964
8248
  exports.useMarkNotificationsRead = useMarkNotificationsRead;
7965
8249
  exports.useMoveSchedule = useMoveSchedule;
@@ -7971,6 +8255,7 @@ exports.useSignOperationByHivesigner = useSignOperationByHivesigner;
7971
8255
  exports.useSignOperationByKey = useSignOperationByKey;
7972
8256
  exports.useSignOperationByKeychain = useSignOperationByKeychain;
7973
8257
  exports.useTransfer = useTransfer;
8258
+ exports.useUnfollow = useUnfollow;
7974
8259
  exports.useUpdateDraft = useUpdateDraft;
7975
8260
  exports.useUploadImage = useUploadImage;
7976
8261
  exports.useVote = useVote;