Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.3.77

### Patch Changes

- SDK: update useAccountUpdateRecovery to use AuthContextV2 adapter (#1376)

## 2.3.76

### Patch Changes
Expand Down
8 changes: 4 additions & 4 deletions packages/sdk/dist/browser/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ declare function useBroadcastMutation<T>(mutationKey: MutationKey | undefined, u
broadcastMode?: BroadcastMode;
}): _tanstack_react_query.UseMutationResult<unknown, Error, T, unknown>;

declare function broadcastJson<T>(username: string | undefined, id: string, payload: T, auth?: AuthContext): Promise<any>;
declare function broadcastJson<T>(username: string | undefined, id: string, payload: T, auth?: AuthContextV2): Promise<any>;

/**
* Delay (ms) before invalidating chain-derived queries after an async
Expand Down Expand Up @@ -2255,7 +2255,7 @@ interface CommonPayload$1 {
type RevokePostingOptions = Pick<UseMutationOptions<unknown, Error, CommonPayload$1>, "onSuccess" | "onError"> & {
hsCallbackUrl?: string;
};
declare function useAccountRevokePosting(username: string | undefined, options: RevokePostingOptions, auth?: AuthContext): _tanstack_react_query.UseMutationResult<unknown, Error, CommonPayload$1, unknown>;
declare function useAccountRevokePosting(username: string | undefined, options: RevokePostingOptions, auth?: AuthContextV2): _tanstack_react_query.UseMutationResult<string | void | TransactionConfirmation, Error, CommonPayload$1, unknown>;

type SignType = "key" | "keychain" | "hivesigner" | "ecency";
interface CommonPayload {
Expand All @@ -2267,7 +2267,7 @@ interface CommonPayload {
type UpdateRecoveryOptions = Pick<UseMutationOptions<unknown, Error, CommonPayload>, "onSuccess" | "onError"> & {
hsCallbackUrl?: string;
};
declare function useAccountUpdateRecovery(username: string | undefined, code: string | undefined, options: UpdateRecoveryOptions, auth?: AuthContext): _tanstack_react_query.UseMutationResult<unknown, Error, CommonPayload, unknown>;
declare function useAccountUpdateRecovery(username: string | undefined, code: string | undefined, options: UpdateRecoveryOptions, auth?: AuthContextV2): _tanstack_react_query.UseMutationResult<string | void | Response | TransactionConfirmation, Error, CommonPayload, unknown>;

interface Payload {
currentKey: PrivateKey;
Expand Down Expand Up @@ -3028,7 +3028,7 @@ declare function useSignOperationByKey(username: string | undefined): _tanstack_
keyOrSeed: string;
}, unknown>;

declare function useSignOperationByKeychain(username: string | undefined, auth?: AuthContext, keyType?: "owner" | "active" | "posting" | "memo"): _tanstack_react_query.UseMutationResult<unknown, Error, {
declare function useSignOperationByKeychain(username: string | undefined, auth?: AuthContextV2, keyType?: "owner" | "active" | "posting" | "memo"): _tanstack_react_query.UseMutationResult<TransactionConfirmation, Error, {
operation: Operation;
}, unknown>;

Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/dist/browser/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/sdk/dist/browser/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/sdk/dist/node/index.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/sdk/dist/node/index.cjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/sdk/dist/node/index.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/sdk/dist/node/index.mjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ecency/sdk",
"private": false,
"version": "2.3.76",
"version": "2.3.77",
"description": "Ecency SDK",
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { getAccountFullQueryOptions } from "../queries";
import { FullAccount } from "../types";
import hs from "hivesigner";
import type { AuthContext } from "@/modules/core/types";
import type { AuthContextV2 } from "@/modules/core/types";
import { broadcastOperations } from "@/modules/core/hive-tx";

type SignType = "key" | "keychain" | "hivesigner";
Expand All @@ -29,7 +29,7 @@ type RevokePostingOptions = Pick<
export function useAccountRevokePosting(
username: string | undefined,
options: RevokePostingOptions,
auth?: AuthContext
auth?: AuthContextV2
) {
const queryClient = useQueryClient();

Expand Down Expand Up @@ -60,10 +60,14 @@ export function useAccountRevokePosting(
if (type === "key" && key) {
return broadcastOperations([["account_update", operationBody]], key);
} else if (type === "keychain") {
if (!auth?.broadcast) {
if (!auth?.adapter?.broadcastWithKeychain) {
throw new Error("[SDK][Accounts] – missing keychain broadcaster");
}
return auth.broadcast([["account_update", operationBody]], "active");
return auth.adapter.broadcastWithKeychain(
data.name,
[["account_update", operationBody]],
"active"
);
} else {
if (!options.hsCallbackUrl && process.env.NODE_ENV === "development") {
console.warn("[SDK][Accounts] hsCallbackUrl not provided for HiveSigner revoke-posting; user will not be redirected after signing.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "@tanstack/react-query";
import hs from "hivesigner";
import { getAccountFullQueryOptions } from "../queries";
import type { AuthContext } from "@/modules/core/types";
import type { AuthContextV2 } from "@/modules/core/types";
import { broadcastOperations } from "@/modules/core/hive-tx";

type SignType = "key" | "keychain" | "hivesigner" | "ecency";
Expand All @@ -30,7 +30,7 @@ export function useAccountUpdateRecovery(
username: string | undefined,
code: string | undefined,
options: UpdateRecoveryOptions,
auth?: AuthContext
auth?: AuthContextV2
) {
const { data } = useQuery(getAccountFullQueryOptions(username));

Expand Down Expand Up @@ -86,10 +86,10 @@ export function useAccountUpdateRecovery(
key
);
} else if (type === "keychain") {
if (!auth?.broadcast) {
if (!auth?.adapter?.broadcastWithKeychain) {
throw new Error("[SDK][Accounts] – missing keychain broadcaster");
}
return auth.broadcast([["change_recovery_account", operationBody]], "owner");
return auth.adapter.broadcastWithKeychain(data.name, [["change_recovery_account", operationBody]], "owner");
} else {
if (!options.hsCallbackUrl && process.env.NODE_ENV === "development") {
console.warn("[SDK][Accounts] hsCallbackUrl not provided for HiveSigner update-recovery; user will not be redirected after signing.");
Expand Down
30 changes: 28 additions & 2 deletions packages/sdk/src/modules/core/mutations/broadcast-json.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { PrivateKey } from "../../../hive-tx";
import { broadcastOperations } from "@/modules/core/hive-tx";
import hs from "hivesigner";
import type { AuthContext } from "@/modules/core/types";
import type { AuthContextV2 } from "@/modules/core/types";

export async function broadcastJson<T>(
username: string | undefined,
id: string,
payload: T,
auth?: AuthContext
auth?: AuthContextV2
) {
if (!username) {
throw new Error(
Expand Down Expand Up @@ -44,6 +44,32 @@ export async function broadcastJson<T>(
return response.result;
}

/*
* Adapter, as a last resort rather than first.
*
* `auth.broadcast` above is the deprecated V1 field, and an AuthContextV2
* does not carry it, so a Keychain user whose posting key is not stored and
* who has no HiveSigner token reached the throw below instead of being asked
* to sign. The web app passes V2 everywhere (`getSdkAuthContext`), so this is
* reachable today from follow and unfollow.
*
* Placed last on purpose: every branch above already works for the sessions
* that reach it, and reordering would change which method signs for people
* it currently serves. This only claims cases that were previously errors.
*/
const adapter = auth?.adapter;
if (adapter) {
const ops: Parameters<NonNullable<typeof adapter.broadcastWithKeychain>>[1] =
[["custom_json", jjson]];

if (auth?.loginType === "keychain" && adapter.broadcastWithKeychain) {
return adapter.broadcastWithKeychain(username, ops, "posting");
}
if (auth?.loginType === "hiveauth" && adapter.broadcastWithHiveAuth) {
return adapter.broadcastWithHiveAuth(username, ops, "posting");
}
}

throw new Error(
"[SDK][Broadcast] – cannot broadcast w/o posting key or token"
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Operation } from "../../../hive-tx";
import { useMutation } from "@tanstack/react-query";
import type { AuthContext } from "@/modules/core/types";
import type { AuthContextV2 } from "@/modules/core/types";

export function useSignOperationByKeychain(
username: string | undefined,
auth?: AuthContext,
auth?: AuthContextV2,
keyType: "owner" | "active" | "posting" | "memo" = "active"
) {
return useMutation({
Expand All @@ -15,11 +15,11 @@ export function useSignOperationByKeychain(
"[SDK][Keychain] – cannot sign operation with anon user"
);
}
if (!auth?.broadcast) {
if (!auth?.adapter?.broadcastWithKeychain) {
throw new Error("[SDK][Keychain] – missing keychain broadcaster");
}

return auth.broadcast([operation], keyType);
return auth.adapter.broadcastWithKeychain(username, [operation], keyType);
},
});
}
7 changes: 7 additions & 0 deletions packages/wallets/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @ecency/wallets

## 5.0.77

### Patch Changes

- Updated dependencies []:
- @ecency/sdk@2.3.77

## 5.0.76

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ecency/wallets",
"private": false,
"version": "5.0.76",
"version": "5.0.77",
"description": "Ecency wallets",
"repository": {
"type": "git",
Expand Down