@ecency/sdk 1.5.20 → 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.
@@ -463,6 +463,8 @@ interface Payload$2 {
463
463
  keepCurrent?: boolean;
464
464
  currentKey: PrivateKey;
465
465
  keys: Keys[];
466
+ keysToRevoke?: string[];
467
+ keysToRevokeByAuthority?: Partial<Record<keyof Keys, string[]>>;
466
468
  }
467
469
  declare function dedupeAndSortKeyAuths(existing: AuthorityType["key_auths"], additions: [string, number][]): AuthorityType["key_auths"];
468
470
  type UpdateKeyAuthsOptions = Pick<UseMutationOptions<unknown, Error, Payload$2>, "onSuccess" | "onError">;
@@ -2876,7 +2876,18 @@ function useAccountUpdateKeyAuths(username, options) {
2876
2876
  const { data: accountData } = useQuery(getAccountFullQueryOptions(username));
2877
2877
  return useMutation({
2878
2878
  mutationKey: ["accounts", "keys-update", username],
2879
- mutationFn: async ({ keys, keepCurrent = false, currentKey }) => {
2879
+ mutationFn: async ({
2880
+ keys,
2881
+ keepCurrent = false,
2882
+ currentKey,
2883
+ keysToRevoke = [],
2884
+ keysToRevokeByAuthority = {}
2885
+ }) => {
2886
+ if (keys.length === 0) {
2887
+ throw new Error(
2888
+ "[SDK][Update password] \u2013 no new keys provided"
2889
+ );
2890
+ }
2880
2891
  if (!accountData) {
2881
2892
  throw new Error(
2882
2893
  "[SDK][Update password] \u2013 cannot update keys for anon user"
@@ -2884,8 +2895,14 @@ function useAccountUpdateKeyAuths(username, options) {
2884
2895
  }
2885
2896
  const prepareAuth = (keyName) => {
2886
2897
  const auth = R4.clone(accountData[keyName]);
2898
+ const keysToRevokeForAuthority = keysToRevokeByAuthority[keyName] || [];
2899
+ const allKeysToRevoke = [
2900
+ ...keysToRevokeForAuthority,
2901
+ ...keysToRevokeByAuthority[keyName] === void 0 ? keysToRevoke : []
2902
+ ];
2903
+ const existingKeys = keepCurrent ? auth.key_auths.filter(([key]) => !allKeysToRevoke.includes(key.toString())) : [];
2887
2904
  auth.key_auths = dedupeAndSortKeyAuths(
2888
- keepCurrent ? auth.key_auths : [],
2905
+ existingKeys,
2889
2906
  keys.map(
2890
2907
  (values, i) => [values[keyName].createPublic().toString(), i + 1]
2891
2908
  )
@@ -2899,7 +2916,8 @@ function useAccountUpdateKeyAuths(username, options) {
2899
2916
  owner: prepareAuth("owner"),
2900
2917
  active: prepareAuth("active"),
2901
2918
  posting: prepareAuth("posting"),
2902
- memo_key: keepCurrent ? accountData.memo_key : keys[0].memo_key.createPublic().toString()
2919
+ // Always use new memo key when adding new keys
2920
+ memo_key: keys[0].memo_key.createPublic().toString()
2903
2921
  },
2904
2922
  currentKey
2905
2923
  );