@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.
- package/dist/browser/index.d.ts +2 -0
- package/dist/browser/index.js +21 -3
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +21 -3
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +21 -3
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.d.ts
CHANGED
|
@@ -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">;
|
package/dist/browser/index.js
CHANGED
|
@@ -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 ({
|
|
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
|
-
|
|
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
|
-
|
|
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
|
);
|