Skip to content

[SDK] Expose getAuthToken from inApp and ecosystem wallets #7683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
5 changes: 5 additions & 0 deletions .changeset/brown-ends-strive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Expose getAuthToken from inapp and ecosystem wallets
9 changes: 9 additions & 0 deletions packages/thirdweb/src/wallets/in-app/core/wallet/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { ThirdwebClient } from "../../../../client/client.js";
import type { SupportedSmsCountry } from "../../../../react/web/wallets/in-app/supported-sms-countries.js";
import type { AsyncStorage } from "../../../../utils/storage/AsyncStorage.js";
import type { Prettify } from "../../../../utils/type-utils.js";
import type { Wallet } from "../../../interfaces/wallet.js";
import type { SmartWalletOptions } from "../../../smart/types.js";
import type {
AuthOption,
Expand All @@ -17,6 +18,14 @@ import type {
} from "../authentication/types.js";
import type { UserStatus } from "./enclave-wallet.js";

export type InAppWallet = Wallet<"inApp"> & {
getAuthToken: () => string | null;
};

export type EcosystemWallet = Wallet<EcosystemWalletId> & {
getAuthToken: () => string | null;
};

export type Ecosystem = {
id: EcosystemWalletId;
partnerId?: string;
Expand Down
6 changes: 3 additions & 3 deletions packages/thirdweb/src/wallets/in-app/native/ecosystem.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { ThirdwebClient } from "../../../client/client.js";
import type { Wallet } from "../../interfaces/wallet.js";
import type {
CreateWalletArgs,
EcosystemWalletId,
} from "../../wallet-types.js";
import { createInAppWallet } from "../core/wallet/in-app-core.js";
import type { EcosystemWallet } from "../core/wallet/types.js";

/**
* Creates an [Ecosystem Wallet](https://portal.thirdweb.com/connect/ecosystems/overview) based on various authentication methods.
Expand Down Expand Up @@ -63,7 +63,7 @@ import { createInAppWallet } from "../core/wallet/in-app-core.js";
*/
export function ecosystemWallet(
...args: CreateWalletArgs<EcosystemWalletId>
): Wallet<EcosystemWalletId> {
): EcosystemWallet {
const [ecosystemId, createOptions] = args;
const ecosystem = {
id: ecosystemId,
Expand All @@ -87,5 +87,5 @@ export function ecosystemWallet(
partnerId: createOptions?.partnerId,
},
ecosystem,
}) as Wallet<EcosystemWalletId>;
}) as EcosystemWallet;
}
10 changes: 6 additions & 4 deletions packages/thirdweb/src/wallets/in-app/native/in-app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { ThirdwebClient } from "../../../client/client.js";
import type { Wallet } from "../../interfaces/wallet.js";
import { createInAppWallet } from "../core/wallet/in-app-core.js";
import type { InAppWalletCreationOptions } from "../core/wallet/types.js";
import type {
InAppWallet,
InAppWalletCreationOptions,
} from "../core/wallet/types.js";

/**
* Creates an in-app wallet.
Expand Down Expand Up @@ -57,7 +59,7 @@ import type { InAppWalletCreationOptions } from "../core/wallet/types.js";
*/
export function inAppWallet(
createOptions?: InAppWalletCreationOptions,
): Wallet<"inApp"> {
): InAppWallet {
return createInAppWallet({
connectorFactory: async (client: ThirdwebClient) => {
const { InAppNativeConnector } = await import("./native-connector.js");
Expand All @@ -68,5 +70,5 @@ export function inAppWallet(
});
},
createOptions,
}) as Wallet<"inApp">;
}) as InAppWallet;
}
6 changes: 3 additions & 3 deletions packages/thirdweb/src/wallets/in-app/web/ecosystem.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { ThirdwebClient } from "../../../client/client.js";
import type { Wallet } from "../../interfaces/wallet.js";
import type {
CreateWalletArgs,
EcosystemWalletId,
} from "../../wallet-types.js";
import { createInAppWallet } from "../core/wallet/in-app-core.js";
import type { EcosystemWallet } from "../core/wallet/types.js";

/**
* Creates an [Ecosystem Wallet](https://portal.thirdweb.com/connect/wallet/overview) based on various authentication methods. Full list of available authentication methods [here](/connect/wallet/sign-in-methods/configure).
Expand Down Expand Up @@ -53,7 +53,7 @@ import { createInAppWallet } from "../core/wallet/in-app-core.js";
*/
export function ecosystemWallet(
...args: CreateWalletArgs<EcosystemWalletId>
): Wallet<EcosystemWalletId> {
): EcosystemWallet {
const [ecosystemId, createOptions] = args;
const ecosystem = {
id: ecosystemId,
Expand All @@ -76,5 +76,5 @@ export function ecosystemWallet(
partnerId: ecosystem.partnerId,
},
ecosystem,
}) as Wallet<EcosystemWalletId>;
}) as EcosystemWallet;
}
10 changes: 6 additions & 4 deletions packages/thirdweb/src/wallets/in-app/web/in-app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { ThirdwebClient } from "../../../client/client.js";
import type { Wallet } from "../../interfaces/wallet.js";
import { createInAppWallet } from "../core/wallet/in-app-core.js";
import type { InAppWalletCreationOptions } from "../core/wallet/types.js";
import type {
InAppWallet,
InAppWalletCreationOptions,
} from "../core/wallet/types.js";

/**
* Creates an app scoped wallet for users based on various authentication methods. Full list of available authentication methods [here](https://portal.thirdweb.com/connect/wallet/sign-in-methods/configure).
Expand Down Expand Up @@ -302,7 +304,7 @@ import type { InAppWalletCreationOptions } from "../core/wallet/types.js";
*/
export function inAppWallet(
createOptions?: InAppWalletCreationOptions,
): Wallet<"inApp"> {
): InAppWallet {
return createInAppWallet({
connectorFactory: async (client: ThirdwebClient) => {
const { InAppWebConnector } = await import("./lib/web-connector.js");
Expand All @@ -313,5 +315,5 @@ export function inAppWallet(
});
},
createOptions,
}) as Wallet<"inApp">;
}) as InAppWallet;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe
strategy: "backend",
walletSecret: "test-secret",
});
authToken = wallet.getAuthToken?.();
authToken = wallet.getAuthToken();
expect(authToken).toBeDefined();
});

Expand All @@ -59,7 +59,7 @@ describe
],
signingOptions: {
from: account.address,
type: "eoa",
type: "EOA",
},
},
bodySerializer: stringify,
Expand All @@ -69,7 +69,7 @@ describe
},
});

const signatureResult = signResult.data?.result?.results[0];
const signatureResult = signResult.data?.result[0];
if (signatureResult && "result" in signatureResult) {
expect(signatureResult.result.signature).toEqual(rawSignature);
} else {
Expand All @@ -79,7 +79,7 @@ describe
}
});

it("should queue a 4337 transaction", async () => {
it("should queue a 7702 transaction", async () => {
const body = {
executionOptions: {
chainId: sepolia.id,
Expand Down Expand Up @@ -120,7 +120,7 @@ describe
transactionId: txId,
});

console.log(tx);
console.log(tx.transactionHash);
expect(tx.transactionHash).toBeDefined();
});
});
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading