Skip to content

Commit 2547ca0

Browse files
cleanup
1 parent f544086 commit 2547ca0

File tree

3 files changed

+132
-2
lines changed

3 files changed

+132
-2
lines changed

packages/engine/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
"type": "git",
66
"url": "git+https://github.com/thirdweb-dev/js.git#main"
77
},
8+
"author": "thirdweb eng <[email protected]>",
89
"type": "module",
10+
"main": "./dist/cjs/exports/thirdweb.js",
11+
"module": "./dist/esm/exports/thirdweb.js",
912
"types": "./dist/types/exports/thirdweb.d.ts",
1013
"typings": "./dist/types/exports/thirdweb.d.ts",
1114
"license": "Apache-2.0",
@@ -20,8 +23,8 @@
2023
},
2124
"exports": {
2225
".": {
23-
"import": "./dist/esm/exports/thirdweb.js",
2426
"types": "./dist/types/exports/thirdweb.d.ts",
27+
"import": "./dist/esm/exports/thirdweb.js",
2528
"default": "./dist/cjs/exports/thirdweb.js"
2629
},
2730
"./package.json": "./package.json"

packages/thirdweb/src/wallets/in-app/core/authentication/backend.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export async function backendAuthenticate(args: {
3131
});
3232

3333
if (!res.ok) {
34-
throw new Error("Failed to generate backend account");
34+
const error = await res.text();
35+
throw new Error(`Failed to generate backend account: ${error}`);
3536
}
3637

3738
return (await res.json()) satisfies AuthStoredTokenWithCookieReturnType;
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import { sendTransaction, signMessage } from "@thirdweb-dev/engine";
2+
import { beforeAll, describe, expect, it } from "vitest";
3+
import { TEST_CLIENT } from "~test/test-clients.js";
4+
import { sepolia } from "../../../../chains/chain-definitions/sepolia.js";
5+
import { createThirdwebClient } from "../../../../client/client.js";
6+
import { waitForTransactionHash } from "../../../../engine/wait-for-tx-hash.js";
7+
import {
8+
getThirdwebBaseUrl,
9+
setThirdwebDomains,
10+
} from "../../../../utils/domains.js";
11+
import { getClientFetch } from "../../../../utils/fetch.js";
12+
import { stringify } from "../../../../utils/json.js";
13+
import type { Account } from "../../../interfaces/wallet.js";
14+
import { inAppWallet } from "../in-app.js";
15+
16+
// TODO: productionize this test
17+
describe
18+
.runIf(process.env.TW_SECRET_KEY)
19+
.skip("InAppWallet Gateway Tests", () => {
20+
let account: Account;
21+
let authToken: string | null | undefined;
22+
const clientIdFetch = getClientFetch(
23+
createThirdwebClient({
24+
clientId: TEST_CLIENT.clientId,
25+
}),
26+
);
27+
28+
beforeAll(async () => {
29+
setThirdwebDomains({
30+
bundler: "bundler.thirdweb-dev.com",
31+
engineCloud: "engine.thirdweb-dev.com",
32+
inAppWallet: "embedded-wallet.thirdweb-dev.com",
33+
rpc: "rpc.thirdweb-dev.com",
34+
});
35+
const wallet = inAppWallet();
36+
account = await wallet.connect({
37+
client: TEST_CLIENT,
38+
strategy: "backend",
39+
walletSecret: "test-secret",
40+
});
41+
authToken = wallet.getAuthToken?.();
42+
expect(authToken).toBeDefined();
43+
});
44+
45+
it("should sign a message with backend strategy", async () => {
46+
const rawSignature = await account.signMessage({
47+
message: "Hello, world!",
48+
});
49+
50+
// sign via api
51+
const signResult = await signMessage({
52+
baseUrl: getThirdwebBaseUrl("engineCloud"),
53+
body: {
54+
params: [
55+
{
56+
format: "text",
57+
message: "Hello, world!",
58+
},
59+
],
60+
signingOptions: {
61+
from: account.address,
62+
type: "eoa",
63+
},
64+
},
65+
bodySerializer: stringify,
66+
fetch: clientIdFetch,
67+
headers: {
68+
"x-wallet-access-token": authToken,
69+
},
70+
});
71+
72+
const signatureResult = signResult.data?.result?.results[0];
73+
if (signatureResult && "result" in signatureResult) {
74+
expect(signatureResult.result.signature).toEqual(rawSignature);
75+
} else {
76+
throw new Error(
77+
`Failed to sign message: ${stringify(signatureResult?.error) || "Unknown error"}`,
78+
);
79+
}
80+
});
81+
82+
it("should queue a 4337 transaction", async () => {
83+
const body = {
84+
executionOptions: {
85+
chainId: sepolia.id,
86+
from: account.address,
87+
type: "auto" as const,
88+
},
89+
params: [
90+
{
91+
data: "0x",
92+
to: account.address,
93+
value: "0",
94+
},
95+
],
96+
};
97+
const result = await sendTransaction({
98+
baseUrl: getThirdwebBaseUrl("engineCloud"),
99+
body,
100+
bodySerializer: stringify,
101+
fetch: clientIdFetch,
102+
headers: {
103+
"x-wallet-access-token": authToken,
104+
},
105+
});
106+
if (result.error) {
107+
throw new Error(
108+
`Error sending transaction: ${stringify(result.error)}`,
109+
);
110+
}
111+
112+
const txId = result.data?.result.transactions[0]?.id;
113+
console.log(txId);
114+
if (!txId) {
115+
throw new Error("No transaction ID found");
116+
}
117+
118+
const tx = await waitForTransactionHash({
119+
client: TEST_CLIENT,
120+
transactionId: txId,
121+
});
122+
123+
console.log(tx);
124+
expect(tx.transactionHash).toBeDefined();
125+
});
126+
});

0 commit comments

Comments
 (0)