@ecency/sdk 1.5.19 → 1.5.21

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.
@@ -2901,7 +2901,18 @@ function useAccountUpdateKeyAuths(username, options) {
2901
2901
  const { data: accountData } = reactQuery.useQuery(getAccountFullQueryOptions(username));
2902
2902
  return reactQuery.useMutation({
2903
2903
  mutationKey: ["accounts", "keys-update", username],
2904
- mutationFn: async ({ keys, keepCurrent = false, currentKey }) => {
2904
+ mutationFn: async ({
2905
+ keys,
2906
+ keepCurrent = false,
2907
+ currentKey,
2908
+ keysToRevoke = [],
2909
+ keysToRevokeByAuthority = {}
2910
+ }) => {
2911
+ if (keys.length === 0) {
2912
+ throw new Error(
2913
+ "[SDK][Update password] \u2013 no new keys provided"
2914
+ );
2915
+ }
2905
2916
  if (!accountData) {
2906
2917
  throw new Error(
2907
2918
  "[SDK][Update password] \u2013 cannot update keys for anon user"
@@ -2909,8 +2920,14 @@ function useAccountUpdateKeyAuths(username, options) {
2909
2920
  }
2910
2921
  const prepareAuth = (keyName) => {
2911
2922
  const auth = R4__namespace.clone(accountData[keyName]);
2923
+ const keysToRevokeForAuthority = keysToRevokeByAuthority[keyName] || [];
2924
+ const allKeysToRevoke = [
2925
+ ...keysToRevokeForAuthority,
2926
+ ...keysToRevokeByAuthority[keyName] === void 0 ? keysToRevoke : []
2927
+ ];
2928
+ const existingKeys = keepCurrent ? auth.key_auths.filter(([key]) => !allKeysToRevoke.includes(key.toString())) : [];
2912
2929
  auth.key_auths = dedupeAndSortKeyAuths(
2913
- keepCurrent ? auth.key_auths : [],
2930
+ existingKeys,
2914
2931
  keys.map(
2915
2932
  (values, i) => [values[keyName].createPublic().toString(), i + 1]
2916
2933
  )
@@ -2924,7 +2941,8 @@ function useAccountUpdateKeyAuths(username, options) {
2924
2941
  owner: prepareAuth("owner"),
2925
2942
  active: prepareAuth("active"),
2926
2943
  posting: prepareAuth("posting"),
2927
- memo_key: keepCurrent ? accountData.memo_key : keys[0].memo_key.createPublic().toString()
2944
+ // Always use new memo key when adding new keys
2945
+ memo_key: keys[0].memo_key.createPublic().toString()
2928
2946
  },
2929
2947
  currentKey
2930
2948
  );