Compare commits

..
Author SHA1 Message Date
github-actions[bot]GitHubgithub-actions[bot] <github-actions[bot]@users.noreply.github.com>
6cc38b0680 Version Packages (#1970)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-11-18 14:30:05 -08:00
Joaquim VergesandGitHub 7abb36a7ec [Wallets] Enforce authenticated users when getting EW signers (#1978) 2023-11-18 17:21:15 +00:00
Joaquim VergesandGitHub 6832b19fc5 [Wallets] Fix potential embedded wallet autoconnect race condition (#1977) 2023-11-18 07:18:30 +00:00
nkrishangandGitHub 1c4cbedb6a Override signMessage for SmartWallet class (#1953) 2023-11-18 06:04:02 +00:00
Phillip HoandGitHub 8ff87be631 fix: Reuse response body in service utils helper (#1976) 2023-11-18 01:50:37 +00:00
YashandGitHub e43beec36a [SDK] Resolve diamond pattern facets abi (#1935) 2023-11-17 15:56:29 +00:00
28 changed files with 224 additions and 43 deletions
+7
View File
@@ -1,5 +1,12 @@
# @thirdweb-dev/auth
## 4.1.10
### Patch Changes
- Updated dependencies [[`6832b19f`](https://github.com/thirdweb-dev/js/commit/6832b19fc5eedc7c17e69940a361840de0a84881), [`7abb36a7`](https://github.com/thirdweb-dev/js/commit/7abb36a7ec39766dd7da03015ccef401ef7a7863), [`1c4cbedb`](https://github.com/thirdweb-dev/js/commit/1c4cbedb6a3c9f9014ffbf83c02b998768958d96)]:
- @thirdweb-dev/wallets@2.1.7
## 4.1.9
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/auth",
"version": "4.1.9",
"version": "4.1.10",
"main": "dist/thirdweb-dev-auth.cjs.js",
"module": "dist/thirdweb-dev-auth.esm.js",
"browser": {
+9
View File
@@ -1,5 +1,14 @@
# thirdweb
## 0.13.18
### Patch Changes
- Updated dependencies [[`6832b19f`](https://github.com/thirdweb-dev/js/commit/6832b19fc5eedc7c17e69940a361840de0a84881), [`7abb36a7`](https://github.com/thirdweb-dev/js/commit/7abb36a7ec39766dd7da03015ccef401ef7a7863), [`1c4cbedb`](https://github.com/thirdweb-dev/js/commit/1c4cbedb6a3c9f9014ffbf83c02b998768958d96), [`e43beec3`](https://github.com/thirdweb-dev/js/commit/e43beec36a569211b6fe708107aa7dc04bff08ec)]:
- @thirdweb-dev/wallets@2.1.7
- @thirdweb-dev/sdk@4.0.15
- @thirdweb-dev/auth@4.1.10
## 0.13.17
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "thirdweb",
"main": "dist/cli/index.js",
"version": "0.13.17",
"version": "0.13.18",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/cli",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
+9
View File
@@ -1,5 +1,14 @@
# @thirdweb-dev/react-core
## 4.1.8
### Patch Changes
- Updated dependencies [[`6832b19f`](https://github.com/thirdweb-dev/js/commit/6832b19fc5eedc7c17e69940a361840de0a84881), [`7abb36a7`](https://github.com/thirdweb-dev/js/commit/7abb36a7ec39766dd7da03015ccef401ef7a7863), [`1c4cbedb`](https://github.com/thirdweb-dev/js/commit/1c4cbedb6a3c9f9014ffbf83c02b998768958d96), [`e43beec3`](https://github.com/thirdweb-dev/js/commit/e43beec36a569211b6fe708107aa7dc04bff08ec)]:
- @thirdweb-dev/wallets@2.1.7
- @thirdweb-dev/sdk@4.0.15
- @thirdweb-dev/auth@4.1.10
## 4.1.7
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/react-core",
"version": "4.1.7",
"version": "4.1.8",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react-core",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
@@ -1,5 +1,7 @@
# @thirdweb-dev/react-native-compat
## 0.4.8
## 0.4.7
## 0.4.6
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@thirdweb-dev/react-native-compat",
"description": "Shims for Thirdweb in React Native Projects",
"version": "0.4.7",
"version": "0.4.8",
"author": "thirdweb eng <[email protected]>",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react-native-compat",
"license": "Apache-2.0",
+9
View File
@@ -1,5 +1,14 @@
# @thirdweb-dev/react-native
## 0.4.8
### Patch Changes
- Updated dependencies [[`6832b19f`](https://github.com/thirdweb-dev/js/commit/6832b19fc5eedc7c17e69940a361840de0a84881), [`7abb36a7`](https://github.com/thirdweb-dev/js/commit/7abb36a7ec39766dd7da03015ccef401ef7a7863), [`1c4cbedb`](https://github.com/thirdweb-dev/js/commit/1c4cbedb6a3c9f9014ffbf83c02b998768958d96), [`e43beec3`](https://github.com/thirdweb-dev/js/commit/e43beec36a569211b6fe708107aa7dc04bff08ec)]:
- @thirdweb-dev/wallets@2.1.7
- @thirdweb-dev/sdk@4.0.15
- @thirdweb-dev/react-core@4.1.8
## 0.4.7
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/react-native",
"version": "0.4.7",
"version": "0.4.8",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react-native",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
+9
View File
@@ -1,5 +1,14 @@
# @thirdweb-dev/react
## 4.1.8
### Patch Changes
- Updated dependencies [[`6832b19f`](https://github.com/thirdweb-dev/js/commit/6832b19fc5eedc7c17e69940a361840de0a84881), [`7abb36a7`](https://github.com/thirdweb-dev/js/commit/7abb36a7ec39766dd7da03015ccef401ef7a7863), [`1c4cbedb`](https://github.com/thirdweb-dev/js/commit/1c4cbedb6a3c9f9014ffbf83c02b998768958d96), [`e43beec3`](https://github.com/thirdweb-dev/js/commit/e43beec36a569211b6fe708107aa7dc04bff08ec)]:
- @thirdweb-dev/wallets@2.1.7
- @thirdweb-dev/sdk@4.0.15
- @thirdweb-dev/react-core@4.1.8
## 4.1.7
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/react",
"version": "4.1.7",
"version": "4.1.8",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
+6
View File
@@ -1,5 +1,11 @@
# @thirdweb-dev/sdk
## 4.0.15
### Patch Changes
- [#1935](https://github.com/thirdweb-dev/js/pull/1935) [`e43beec3`](https://github.com/thirdweb-dev/js/commit/e43beec36a569211b6fe708107aa7dc04bff08ec) Thanks [@kumaryash90](https://github.com/kumaryash90)! - Resolve diamond pattern facets ABIs
## 4.0.14
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/sdk",
"version": "4.0.14",
"version": "4.0.15",
"description": "The main thirdweb SDK.",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/sdk",
"license": "Apache-2.0",
@@ -7,7 +7,7 @@ import { Abi, AbiSchema } from "../../schema/contracts/custom";
import { SDKOptions } from "../../schema/sdk-options";
import { isExtensionEnabled } from "../feature-detection/isFeatureEnabled";
import { ThirdwebStorage } from "@thirdweb-dev/storage";
import { providers } from "ethers";
import { Contract, providers } from "ethers";
import { joinABIs } from "./joinABIs";
import { getPluginABI } from "./getPluginABI";
@@ -24,7 +24,7 @@ export async function getCompositeABI(
let pluginABIs: Abi[] = [];
try {
// check if contract is plugin-pattern
// check if contract is plugin-pattern / dynamic
const isPluginRouter: boolean = isExtensionEnabled(
AbiSchema.parse(abi),
"PluginRouter",
@@ -33,6 +33,13 @@ export async function getCompositeABI(
AbiSchema.parse(abi),
"DynamicContract",
);
// check if the contract has fallback function - we'll further check for diamond pattern if needed
const isFallback: boolean = isExtensionEnabled(
AbiSchema.parse(abi),
"Fallback",
);
if (isbaseRouter) {
const contract = new ContractWrapper(
provider,
@@ -68,6 +75,21 @@ export async function getCompositeABI(
// get ABIs of extension contracts
pluginABIs = await getPluginABI(plugins as any[], provider, storage);
} else if (isFallback) {
// check if diamond pattern
const dimaondAbi = [
"function facets() external view returns (tuple(address,bytes4[])[])",
];
const contract = new Contract(address, dimaondAbi, provider);
// get facets
const facets = await contract.facets();
// filter facet addresses
const facetAddresses = facets.map((item: any) => item[0]);
// get ABI of facets
pluginABIs = await getPluginABI(facetAddresses, provider, storage);
}
} catch (err) {}
@@ -74,6 +74,7 @@ import {
FEATURE_ACCOUNT_FACTORY,
FEATURE_ACCOUNT_PERMISSIONS,
FEATURE_ACCOUNT_PERMISSIONS_V1,
FEATURE_FALLBACK,
} from "./thirdweb-features";
/**
@@ -148,7 +149,8 @@ export type Feature =
| typeof FEATURE_ACCOUNT
| typeof FEATURE_ACCOUNT_PERMISSIONS
| typeof FEATURE_ACCOUNT_PERMISSIONS_V1
| typeof FEATURE_ACCOUNT_FACTORY;
| typeof FEATURE_ACCOUNT_FACTORY
| typeof FEATURE_FALLBACK;
export type Extension = Feature;
@@ -197,4 +199,5 @@ export const SUPPORTED_FEATURES: Record<string, Feature> = /* @__PURE__ */ {
[FEATURE_ACCOUNT.name]: FEATURE_ACCOUNT,
[FEATURE_NFT_LOYALTY_CARD.name]: FEATURE_NFT_LOYALTY_CARD,
[FEATURE_NFT_UPDATABLE_METADATA.name]: FEATURE_NFT_UPDATABLE_METADATA,
[FEATURE_FALLBACK.name]: FEATURE_FALLBACK,
};
@@ -19,6 +19,13 @@ import IAccountPermissions from "@thirdweb-dev/contracts-js/dist/abis/IAccountPe
import IAccountPermissionsV1 from "@thirdweb-dev/contracts-js/dist/abis/IAccountPermissions_V1.json";
import IAccount from "@thirdweb-dev/contracts-js/dist/abis/IAccount.json";
export const fallbackAbi = [
{
stateMutability: "payable",
type: "fallback",
},
];
export const getAllPluginsAbi = [
{
inputs: [],
@@ -370,3 +377,14 @@ export const FEATURE_AIRDROP_ERC1155 = {
abis: [IAirdropERC1155],
features: {},
} as const;
export const FEATURE_FALLBACK = {
name: "Fallback",
namespace: "fallback",
docLinks: {
sdk: "",
contracts: "",
},
abis: [fallbackAbi],
features: {},
} as const;
+1
View File
@@ -173,6 +173,7 @@ export { fetchSnapshotEntryForAddress } from "./common/claim-conditions/fetchSna
export { getCachedAbiForContract } from "./common/abi";
export * from "./common/ens/resolveEns";
export * from "./common/ens/resolveAddress";
export * from "./common/sign";
//#endregion @r/packages/sdk/src/evm/common/*
//#region @r/packages/sdk/src/evm/constants/*
+6
View File
@@ -1,5 +1,11 @@
# @thirdweb-dev/service-utils
## 0.4.9
### Patch Changes
- [#1976](https://github.com/thirdweb-dev/js/pull/1976) [`8ff87be6`](https://github.com/thirdweb-dev/js/commit/8ff87be631f1754b15e7ec4556d51e8eec5cbd18) Thanks [@arcoraven](https://github.com/arcoraven)! - Handle if error parsing JSON response in authorization helper
## 0.4.8
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/service-utils",
"version": "0.4.8",
"version": "0.4.9",
"main": "dist/thirdweb-dev-service-utils.cjs.js",
"module": "dist/thirdweb-dev-service-utils.esm.js",
"exports": {
+10 -12
View File
@@ -80,17 +80,16 @@ export async function fetchKeyMetadataFromApi(
"content-type": "application/json",
},
});
let json: ApiResponse;
let text = "";
try {
json = await response.json();
text = await response.text();
return JSON.parse(text);
} catch (e) {
throw new Error(
`Error fetching key metadata from API: ${response.status} - ${
response.statusText
} - ${await response.text()}`,
`Error fetching key metadata from API: ${response.status} - ${text}`,
);
}
return json;
}
export async function fetchAccountFromApi(
@@ -110,17 +109,16 @@ export async function fetchAccountFromApi(
authorization: `Bearer ${jwt}`,
},
});
let json: ApiAccountResponse;
let text = "";
try {
json = await response.json();
text = await response.text();
return JSON.parse(text);
} catch (e) {
throw new Error(
`Error fetching account from API: ${response.status} - ${
response.statusText
} - ${await response.text()}`,
`Error fetching account from API: ${response.status} - ${text}`,
);
}
return json;
}
export async function updateRateLimitedAt(
+9
View File
@@ -1,5 +1,14 @@
# @thirdweb-dev/unity-js-bridge
## 0.2.104
### Patch Changes
- Updated dependencies [[`6832b19f`](https://github.com/thirdweb-dev/js/commit/6832b19fc5eedc7c17e69940a361840de0a84881), [`7abb36a7`](https://github.com/thirdweb-dev/js/commit/7abb36a7ec39766dd7da03015ccef401ef7a7863), [`1c4cbedb`](https://github.com/thirdweb-dev/js/commit/1c4cbedb6a3c9f9014ffbf83c02b998768958d96), [`e43beec3`](https://github.com/thirdweb-dev/js/commit/e43beec36a569211b6fe708107aa7dc04bff08ec)]:
- @thirdweb-dev/wallets@2.1.7
- @thirdweb-dev/sdk@4.0.15
- @thirdweb-dev/auth@4.1.10
## 0.2.103
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/unity-js-bridge",
"version": "0.2.103",
"version": "0.2.104",
"main": "dist/thirdweb-unity-bridge.js",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/unity-js-bridge",
"license": "Apache-2.0",
+13
View File
@@ -1,5 +1,18 @@
# @thirdweb-dev/wallets
## 2.1.7
### Patch Changes
- [#1977](https://github.com/thirdweb-dev/js/pull/1977) [`6832b19f`](https://github.com/thirdweb-dev/js/commit/6832b19fc5eedc7c17e69940a361840de0a84881) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Fix potential auto connection race condition
- [#1978](https://github.com/thirdweb-dev/js/pull/1978) [`7abb36a7`](https://github.com/thirdweb-dev/js/commit/7abb36a7ec39766dd7da03015ccef401ef7a7863) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Enforce authenticated users when getting embedded wallet signers
- [#1953](https://github.com/thirdweb-dev/js/pull/1953) [`1c4cbedb`](https://github.com/thirdweb-dev/js/commit/1c4cbedb6a3c9f9014ffbf83c02b998768958d96) Thanks [@nkrishang](https://github.com/nkrishang)! - Patched smart wallet signatures for updated eip-1271 sig verification
- Updated dependencies [[`e43beec3`](https://github.com/thirdweb-dev/js/commit/e43beec36a569211b6fe708107aa7dc04bff08ec)]:
- @thirdweb-dev/sdk@4.0.15
## 2.1.6
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/wallets",
"version": "2.1.6",
"version": "2.1.7",
"main": "dist/thirdweb-dev-wallets.cjs.js",
"module": "dist/thirdweb-dev-wallets.esm.js",
"browser": {
@@ -89,7 +89,7 @@ export class EmbeddedWalletConnector extends Connector<EmbeddedWalletConnectionA
if (!this.user) {
throw new Error("Embedded Wallet is not connected");
}
return this.user.walletAddress;
return await this.getSigner().then((signer) => signer.getAddress());
}
async isConnected(): Promise<boolean> {
@@ -115,7 +115,7 @@ export class EmbeddedWalletConnector extends Connector<EmbeddedWalletConnectionA
}
const user = await this.getUser();
const signer = await user?.wallet.getEthersJsSigner({
const signer = await user.wallet.getEthersJsSigner({
rpcEndpoint: this.options.chain.rpc[0] || "", // TODO: handle chain.rpc being empty array
});
@@ -180,11 +180,11 @@ export class EmbeddedWalletConnector extends Connector<EmbeddedWalletConnectionA
this.emit("disconnect");
};
async getUser(): Promise<InitializedUser | null> {
private async getUser(): Promise<InitializedUser> {
if (
!this.user ||
!this.user.wallet ||
typeof this.user.wallet.getEthersJsSigner !== "function"
!this.user.wallet.getEthersJsSigner // when serializing, functions are lost, need to rehydrate
) {
const embeddedWalletSdk = this.getEmbeddedWalletSDK();
const user = await embeddedWalletSdk.getUser();
@@ -193,27 +193,25 @@ export class EmbeddedWalletConnector extends Connector<EmbeddedWalletConnectionA
this.user = user;
break;
}
default: {
// if logged out or unitialized, we can't get a signer, so throw an error
throw new Error(
"Embedded Wallet is not authenticated, please authenticate first",
);
}
}
}
return this.user;
}
async getEmail() {
// implicit call to set the user
await this.getSigner();
if (!this.user) {
throw new Error("No user found, Embedded Wallet is not connected");
}
return this.user.authDetails.email;
const user = await this.getUser();
return user.authDetails.email;
}
async getRecoveryInformation() {
// implicit call to set the user
await this.getSigner();
if (!this.user) {
throw new Error("No user found, Embedded Wallet is not connected");
}
return this.user.authDetails;
const user = await this.getUser();
return user.authDetails;
}
async sendVerificationEmail({
@@ -64,5 +64,4 @@ export type AuthResult = {
user?: InitializedUser;
isNewUser?: boolean;
needsRecoveryCode?: boolean;
verifyOTP?: (otp: string, recoveryCode?: string) => Promise<AuthResult>;
};
@@ -1,4 +1,5 @@
import { AbstractClientWallet, WalletOptions } from "./base";
import { checkContractWalletSignature } from "./abstract";
import type { ConnectParams } from "../interfaces/connector";
import type {
SmartWalletConfig,
@@ -14,7 +15,8 @@ import {
} from "@thirdweb-dev/sdk";
import { walletIds } from "../constants/walletIds";
import { getValidChainRPCs } from "@thirdweb-dev/chains";
import { providers, utils } from "ethers";
import { providers, utils, Bytes, Signer } from "ethers";
import { signTypedDataInternal } from "@thirdweb-dev/sdk";
// export types and utils for convenience
export type * from "../connectors/smart-wallet/types";
@@ -76,6 +78,67 @@ export class SmartWallet extends AbstractClientWallet<
return this.connector?.personalWallet;
}
/**
* @returns the signature of the message
*/
public async signMessage(message: Bytes | string): Promise<string> {
// Deploy smart wallet if needed
const connector = await this.getConnector();
await connector.deployIfNeeded();
const erc4337Signer = await this.getSigner();
const chainId = await erc4337Signer.getChainId();
const address = await connector.getAddress();
/**
* We first try to sign the EIP-712 typed data i.e. the message mixed with the smart wallet's domain separator.
* If this fails, we fallback to the legacy signing method.
*/
try {
const result = await signTypedDataInternal(
erc4337Signer,
{
name: "Account",
version: "1",
chainId,
verifyingContract: address,
},
{ AccountMessage: [{ name: "message", type: "bytes" }] },
{
message: utils.defaultAbiCoder.encode(
["bytes32"],
[utils.hashMessage(message)],
),
},
);
const isValid = await checkContractWalletSignature(
message as string,
result.signature,
address,
chainId,
);
if (!isValid) {
throw new Error("Invalid signature");
}
return result.signature;
} catch {
return await this.signMessageLegacy(erc4337Signer, message);
}
}
/**
* @returns the signature of the message (for legacy EIP-1271 signature verification)
*/
private async signMessageLegacy(
signer: Signer,
message: Bytes | string,
): Promise<string> {
return await signer.signMessage(message);
}
/**
* Check whether the connected signer can execute a given transaction using the smart wallet.
* @param transaction - the transaction to execute using the smart wallet.