Skip to content

Commit 891f34a

Browse files
author
ikethirdweb
committed
Merge branch 'main' into ike/i18n
2 parents fdc2daa + 6d1eabe commit 891f34a

File tree

12 files changed

+55
-17
lines changed

12 files changed

+55
-17
lines changed

.changeset/funny-eels-watch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/auth": patch
3+
---
4+
5+
Update to call uuidv4 to generate jti

.changeset/slimy-bees-greet.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/auth": patch
3+
---
4+
5+
Expose buildJWT function

.changeset/two-plants-approve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/sdk": patch
3+
---
4+
5+
[SDK] Various small improvements

.changeset/wise-boats-perform.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/auth": patch
3+
---
4+
5+
Update to use uuidv4 for default jti

packages/auth/src/core/functions/jwt.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ function base64decode(data: string): string {
3838
/**
3939
* Build JWT token based on the authentication payload
4040
*/
41-
async function buildJWT({ wallet, payload }: BuildJwtParams): Promise<string> {
41+
export async function buildJWT({
42+
wallet,
43+
payload,
44+
}: BuildJwtParams): Promise<string> {
4245
const payloadData = AuthenticationPayloadDataSchema.parse(payload);
4346

4447
const message = JSON.stringify(payloadData);

packages/auth/src/core/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export { ThirdwebAuth } from "./auth";
33

44
// Export individual auth functions
55
export {
6+
buildJWT,
67
generateJWT,
78
parseJWT,
89
refreshJWT,

packages/auth/src/core/schema/authenticate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const AuthenticationPayloadDataSchema = z.object({
99
exp: RawDateSchema,
1010
nbf: RawDateSchema,
1111
iat: RawDateSchema,
12-
jti: z.string().default(uuidv4()),
12+
jti: z.string().default(() => uuidv4()),
1313
ctx: JsonSchema.optional(),
1414
});
1515

packages/auth/src/core/schema/login.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const LoginPayloadDataSchema = z.object({
4444
uri: z.string().optional(),
4545
version: z.string().default("1"),
4646
chain_id: z.string().optional(),
47-
nonce: z.string().default(uuidv4()),
47+
nonce: z.string().default(() => uuidv4()),
4848
issued_at: z
4949
.date()
5050
.default(new Date())

packages/sdk/src/evm/common/legacy.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ export async function getPrebuiltInfo(
77
): Promise<{ type: string; version: number } | undefined> {
88
try {
99
const contract = new Contract(address, IThirdwebContractABI, provider);
10-
const [type, version] = await Promise.all([
11-
utils
12-
.toUtf8String(await contract.contractType()) // eslint-disable-next-line no-control-regex
13-
.replace(/\x00/g, ""),
14-
await contract.contractVersion(),
10+
const [_type, version] = await Promise.all([
11+
contract.contractType(),
12+
contract.contractVersion(),
1513
]);
14+
const type = utils
15+
.toUtf8String(_type) // eslint-disable-next-line no-control-regex
16+
.replace(/\x00/g, "");
1617
return {
1718
type,
1819
version,

packages/sdk/src/evm/common/parseSnapshotInputs.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ export async function parseSnapshotInputs(inputs: SnapshotInput) {
99
);
1010

1111
const results = [];
12-
for (const chunk of chunks) {
13-
results.push(...(await SnapshotInputSchema.parseAsync(chunk)));
12+
const parsedChunks = await Promise.all(
13+
chunks.map((chunk) => SnapshotInputSchema.parseAsync(chunk)),
14+
);
15+
for (const chunk of parsedChunks) {
16+
results.push(...chunk);
1417
}
1518

1619
return results;

packages/sdk/src/evm/common/permit.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,19 @@ export async function signDAIPermit(
131131
deadline?: BigNumberish,
132132
nonce?: BigNumberish,
133133
) {
134+
const [name, chainId, signerNonce] = await Promise.all([
135+
getTokenName(signer, currencyAddress),
136+
signer.getChainId(),
137+
getSignerNonce(signer, currencyAddress),
138+
]);
134139
const domain = await getChainDomainSeperator(signer, {
135-
name: await getTokenName(signer, currencyAddress),
140+
name,
136141
version: "1",
137-
chainId: await signer.getChainId(),
142+
chainId,
138143
verifyingContract: currencyAddress,
139144
});
140145

141-
nonce = nonce || (await getSignerNonce(signer, currencyAddress)).toString();
146+
nonce = nonce || signerNonce.toString();
142147
deadline = deadline || constants.MaxUint256;
143148

144149
const message = {
@@ -186,14 +191,19 @@ export async function signEIP2612Permit(
186191
deadline?: BigNumberish,
187192
nonce?: BigNumberish,
188193
) {
194+
const [name, chainId, signerNonce] = await Promise.all([
195+
getTokenName(signer, currencyAddress),
196+
signer.getChainId(),
197+
getSignerNonce(signer, currencyAddress),
198+
]);
189199
const domain = await getChainDomainSeperator(signer, {
190-
name: await getTokenName(signer, currencyAddress),
200+
name,
191201
version: "1",
192-
chainId: await signer.getChainId(),
202+
chainId,
193203
verifyingContract: currencyAddress,
194204
});
195205

196-
nonce = nonce || (await getSignerNonce(signer, currencyAddress)).toString();
206+
nonce = nonce || signerNonce.toString();
197207
deadline = deadline || constants.MaxUint256;
198208

199209
const message = {

packages/sdk/src/evm/common/sign.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export async function signTypedDataInternal(
5555
// an indirect way for accessing walletconnect's underlying provider
5656
if ((provider as any)?.provider?.isWalletConnect) {
5757
signature = await provider.send("eth_signTypedData", [
58-
(await signer.getAddress()).toLowerCase(),
58+
signerAddress,
5959
JSON.stringify(payload),
6060
]);
6161
} else {

0 commit comments

Comments
 (0)