Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df36e27f32 | ||
|
|
8c0dc9c880 | ||
|
|
074a3eb01c | ||
|
|
a5d0be939a | ||
|
|
5ec0f064d2 | ||
|
|
becbb63736 | ||
|
|
5ee700e804 | ||
|
|
67b145b94d | ||
|
|
c0a6d2f182 | ||
|
|
fd9816556f | ||
|
|
2a3cd62dc9 | ||
|
|
c9bf4f05c1 | ||
|
|
9f5adc5c5c | ||
|
|
d01e6396d1 | ||
|
|
2283d21027 | ||
|
|
ab36d84f1c | ||
|
|
a9f2ff73c9 | ||
|
|
9a7b2098ee | ||
|
|
2b96f71e19 | ||
|
|
3b6b0746b3 | ||
|
|
b0ec1d8083 |
@@ -1,5 +1,19 @@
|
|||||||
# @thirdweb-dev/auth
|
# @thirdweb-dev/auth
|
||||||
|
|
||||||
|
## 3.2.25
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`a9f2ff73`](https://github.com/thirdweb-dev/js/commit/a9f2ff73c9f83f05c3e2d3c53b23b2843e8a2576), [`fd981655`](https://github.com/thirdweb-dev/js/commit/fd9816556fe595b0c764e34dbcf15b0ad1677edb)]:
|
||||||
|
- @thirdweb-dev/wallets@1.1.8
|
||||||
|
|
||||||
|
## 3.2.24
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`3b6b0746`](https://github.com/thirdweb-dev/js/commit/3b6b0746b3fc792f4c5092814a7abfabcbc9801e), [`b0ec1d80`](https://github.com/thirdweb-dev/js/commit/b0ec1d80839efccad11b50afbf2216c2c132cf7e)]:
|
||||||
|
- @thirdweb-dev/wallets@1.1.7
|
||||||
|
|
||||||
## 3.2.23
|
## 3.2.23
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/auth",
|
"name": "@thirdweb-dev/auth",
|
||||||
"version": "3.2.23",
|
"version": "3.2.25",
|
||||||
"main": "dist/thirdweb-dev-auth.cjs.js",
|
"main": "dist/thirdweb-dev-auth.cjs.js",
|
||||||
"module": "dist/thirdweb-dev-auth.esm.js",
|
"module": "dist/thirdweb-dev-auth.esm.js",
|
||||||
"browser": {
|
"browser": {
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
# @thirdweb-dev/chains
|
# @thirdweb-dev/chains
|
||||||
|
|
||||||
|
## 0.1.41
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#1436](https://github.com/thirdweb-dev/js/pull/1436) [`fd981655`](https://github.com/thirdweb-dev/js/commit/fd9816556fe595b0c764e34dbcf15b0ad1677edb) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Updated chains
|
||||||
|
|
||||||
|
- [#1432](https://github.com/thirdweb-dev/js/pull/1432) [`9f5adc5c`](https://github.com/thirdweb-dev/js/commit/9f5adc5c5c2782ffb878759df481e5fb1e1740e5) Thanks [@jnsdls](https://github.com/jnsdls)! - update chains
|
||||||
|
|
||||||
## 0.1.40
|
## 0.1.40
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { Chain } from "../src/types";
|
import type { Chain } from "../src/types";
|
||||||
export default {
|
export default {
|
||||||
"name": "Kalar Chain Mainnet",
|
"name": "Kalar Chain",
|
||||||
"chain": "KLC",
|
"chain": "KLC",
|
||||||
"icon": {
|
"icon": {
|
||||||
"url": "ipfs://bafkreihfoy2kgf2rebaoicso7z5h7ju46z6gtr64mskkths3qbfkrtnkjm",
|
"url": "ipfs://bafkreihfoy2kgf2rebaoicso7z5h7ju46z6gtr64mskkths3qbfkrtnkjm",
|
||||||
@@ -10,7 +10,7 @@ export default {
|
|||||||
},
|
},
|
||||||
"rpc": [
|
"rpc": [
|
||||||
"https://kalar-chain.rpc.thirdweb.com/${THIRDWEB_API_KEY}",
|
"https://kalar-chain.rpc.thirdweb.com/${THIRDWEB_API_KEY}",
|
||||||
"http://rpc-api.kalarchain.tech"
|
"https://rpc-api.kalarchain.tech"
|
||||||
],
|
],
|
||||||
"faucets": [],
|
"faucets": [],
|
||||||
"nativeCurrency": {
|
"nativeCurrency": {
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import type { Chain } from "../src/types";
|
||||||
|
export default {
|
||||||
|
"name": "WhiteBIT Network",
|
||||||
|
"chain": "WBT",
|
||||||
|
"rpc": [
|
||||||
|
"https://whitebit-network.rpc.thirdweb.com/${THIRDWEB_API_KEY}",
|
||||||
|
"https://rpc.whitebit.network"
|
||||||
|
],
|
||||||
|
"faucets": [],
|
||||||
|
"nativeCurrency": {
|
||||||
|
"name": "WhiteBIT Coin",
|
||||||
|
"symbol": "WBT",
|
||||||
|
"decimals": 18
|
||||||
|
},
|
||||||
|
"infoURL": "https://whitebit.network",
|
||||||
|
"shortName": "wbt",
|
||||||
|
"chainId": 1875,
|
||||||
|
"networkId": 1875,
|
||||||
|
"icon": {
|
||||||
|
"url": "ipfs://Qmbi6cqsQyDjkQSoxbNTTUy8WGyVEFqCtATX2aF4KLmCcZ",
|
||||||
|
"width": 512,
|
||||||
|
"height": 512,
|
||||||
|
"format": "png"
|
||||||
|
},
|
||||||
|
"explorers": [
|
||||||
|
{
|
||||||
|
"name": "wb-explorer",
|
||||||
|
"url": "https://explorer.whitebit.network",
|
||||||
|
"standard": "EIP3091"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"testnet": false,
|
||||||
|
"slug": "whitebit-network"
|
||||||
|
} as const satisfies Chain;
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import type { Chain } from "../src/types";
|
||||||
|
export default {
|
||||||
|
"name": "Manta Pacific Testnet",
|
||||||
|
"chain": "Manta Pacific",
|
||||||
|
"rpc": [
|
||||||
|
"https://manta-pacific-testnet.rpc.thirdweb.com/${THIRDWEB_API_KEY}",
|
||||||
|
"https://manta-testnet.calderachain.xyz/http"
|
||||||
|
],
|
||||||
|
"faucets": [],
|
||||||
|
"nativeCurrency": {
|
||||||
|
"name": "Manta",
|
||||||
|
"symbol": "MANTA",
|
||||||
|
"decimals": 18
|
||||||
|
},
|
||||||
|
"features": [
|
||||||
|
{
|
||||||
|
"name": "EIP155"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "EIP1559"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"infoURL": "https://manta-testnet.caldera.dev/",
|
||||||
|
"shortName": "manta",
|
||||||
|
"chainId": 3441005,
|
||||||
|
"networkId": 3441005,
|
||||||
|
"icon": {
|
||||||
|
"url": "ipfs://QmTckcVTViRZ3NqT36MTt8AvgBSmudrbgU3pi8AaNtthoV",
|
||||||
|
"width": 834,
|
||||||
|
"height": 834,
|
||||||
|
"format": "png"
|
||||||
|
},
|
||||||
|
"explorers": [
|
||||||
|
{
|
||||||
|
"name": "manta-testnet Explorer",
|
||||||
|
"url": "https://manta-testnet.calderaexplorer.xyz",
|
||||||
|
"standard": "EIP3091"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"testnet": true,
|
||||||
|
"slug": "manta-pacific-testnet"
|
||||||
|
} as const satisfies Chain;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/chains",
|
"name": "@thirdweb-dev/chains",
|
||||||
"version": "0.1.40",
|
"version": "0.1.41",
|
||||||
"main": "dist/thirdweb-dev-chains.cjs.js",
|
"main": "dist/thirdweb-dev-chains.cjs.js",
|
||||||
"module": "dist/thirdweb-dev-chains.esm.js",
|
"module": "dist/thirdweb-dev-chains.esm.js",
|
||||||
"browser": {
|
"browser": {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1,5 +1,25 @@
|
|||||||
# thirdweb
|
# thirdweb
|
||||||
|
|
||||||
|
## 0.11.8
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#1443](https://github.com/thirdweb-dev/js/pull/1443) [`8c0dc9c8`](https://github.com/thirdweb-dev/js/commit/8c0dc9c88084efcd184a416ed372c50c2fb8a209) Thanks [@nessup](https://github.com/nessup)! - Switch IPFS download domain used in CLI
|
||||||
|
|
||||||
|
- Updated dependencies [[`a5d0be93`](https://github.com/thirdweb-dev/js/commit/a5d0be939a143095e769b68cf86360bfe4720744), [`c0a6d2f1`](https://github.com/thirdweb-dev/js/commit/c0a6d2f18231310d143c9b0cb1b2ff59315087a4), [`becbb637`](https://github.com/thirdweb-dev/js/commit/becbb637367285ed3d8d7d131e1020bf23e38298), [`fd981655`](https://github.com/thirdweb-dev/js/commit/fd9816556fe595b0c764e34dbcf15b0ad1677edb), [`c9bf4f05`](https://github.com/thirdweb-dev/js/commit/c9bf4f05c161707c6eb799ecef82f462e4a82405), [`67b145b9`](https://github.com/thirdweb-dev/js/commit/67b145b94dafb2fb1d90553ed4829f0ed22e2907), [`5ee700e8`](https://github.com/thirdweb-dev/js/commit/5ee700e80438650fa253c25c0bee6658ce68d2cf), [`9f5adc5c`](https://github.com/thirdweb-dev/js/commit/9f5adc5c5c2782ffb878759df481e5fb1e1740e5)]:
|
||||||
|
- @thirdweb-dev/sdk@3.10.44
|
||||||
|
- @thirdweb-dev/chains@0.1.41
|
||||||
|
|
||||||
|
## 0.11.7
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#1419](https://github.com/thirdweb-dev/js/pull/1419) [`2b96f71e`](https://github.com/thirdweb-dev/js/commit/2b96f71e191d7f69c2c75f9c6a9ee4537bac65aa) Thanks [@Marfuen](https://github.com/Marfuen)! - Fix path of cache to work with windows.
|
||||||
|
|
||||||
|
- Updated dependencies [[`3b6b0746`](https://github.com/thirdweb-dev/js/commit/3b6b0746b3fc792f4c5092814a7abfabcbc9801e)]:
|
||||||
|
- @thirdweb-dev/storage@1.2.3
|
||||||
|
- @thirdweb-dev/sdk@3.10.43
|
||||||
|
|
||||||
## 0.11.6
|
## 0.11.6
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "thirdweb",
|
"name": "thirdweb",
|
||||||
"main": "dist/cli/index.js",
|
"main": "dist/cli/index.js",
|
||||||
"version": "0.11.6",
|
"version": "0.11.8",
|
||||||
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/cli",
|
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/cli",
|
||||||
"author": "thirdweb eng <[email protected]>",
|
"author": "thirdweb eng <[email protected]>",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ const main = async () => {
|
|||||||
const skipIntro = process.env.THIRDWEB_CLI_SKIP_INTRO === "true";
|
const skipIntro = process.env.THIRDWEB_CLI_SKIP_INTRO === "true";
|
||||||
|
|
||||||
const program = new Command();
|
const program = new Command();
|
||||||
const cache = new Cache("thirdweb:cli", {
|
const cache = new Cache("thirdweb-cli", {
|
||||||
location: path.join(os.homedir(), ".thirdweb", "creds"),
|
location: path.join(os.homedir(), ".thirdweb", "creds"),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -70,10 +70,7 @@ export async function deployApp(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const uri = await upload(storage, distPath);
|
const uri = await upload(storage, distPath);
|
||||||
return `${uri.replace(
|
return storage.resolveScheme(uri);
|
||||||
"ipfs://",
|
|
||||||
"https://ipfs-public.thirdwebcdn.com/ipfs/",
|
|
||||||
)}`;
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Can't upload project", err);
|
console.error("Can't upload project", err);
|
||||||
return Promise.reject("Can't upload project");
|
return Promise.reject("Can't upload project");
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
# @thirdweb-dev/contracts-js
|
# @thirdweb-dev/contracts-js
|
||||||
|
|
||||||
|
## 1.3.11
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#1432](https://github.com/thirdweb-dev/js/pull/1432) [`9f5adc5c`](https://github.com/thirdweb-dev/js/commit/9f5adc5c5c2782ffb878759df481e5fb1e1740e5) Thanks [@jnsdls](https://github.com/jnsdls)! - upgrade contracts package
|
||||||
|
|
||||||
## 1.3.10
|
## 1.3.10
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"main": "dist/thirdweb-dev-contracts-js-factories-TWRegistryLegacy__factory.cjs.js",
|
|
||||||
"module": "dist/thirdweb-dev-contracts-js-factories-TWRegistryLegacy__factory.esm.js"
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/contracts-js",
|
"name": "@thirdweb-dev/contracts-js",
|
||||||
"version": "1.3.10",
|
"version": "1.3.11",
|
||||||
"main": "dist/thirdweb-dev-contracts-js.cjs.js",
|
"main": "dist/thirdweb-dev-contracts-js.cjs.js",
|
||||||
"module": "dist/thirdweb-dev-contracts-js.esm.js",
|
"module": "dist/thirdweb-dev-contracts-js.esm.js",
|
||||||
"browser": {
|
"browser": {
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/contracts-js",
|
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/contracts-js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@thirdweb-dev/contracts": "3.8.1-0"
|
"@thirdweb-dev/contracts": "3.8.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/preset-env": "^7.22.9",
|
"@babel/preset-env": "^7.22.9",
|
||||||
|
|||||||
@@ -1,5 +1,29 @@
|
|||||||
# @thirdweb-dev/react-core
|
# @thirdweb-dev/react-core
|
||||||
|
|
||||||
|
## 3.14.25
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#1423](https://github.com/thirdweb-dev/js/pull/1423) [`2283d210`](https://github.com/thirdweb-dev/js/commit/2283d21027503e047c25df5ebb21bdde0734be9e) Thanks [@nkrishang](https://github.com/nkrishang)! - Create useAccountAdmins hook
|
||||||
|
|
||||||
|
- [#1429](https://github.com/thirdweb-dev/js/pull/1429) [`ab36d84f`](https://github.com/thirdweb-dev/js/commit/ab36d84f1ce5647fa52475b4a35ea29d5007ad9b) Thanks [@iketw](https://github.com/iketw)! - Pass secretKey in the React SDK for server-side rendering
|
||||||
|
|
||||||
|
- [#1437](https://github.com/thirdweb-dev/js/pull/1437) [`5ee700e8`](https://github.com/thirdweb-dev/js/commit/5ee700e80438650fa253c25c0bee6658ce68d2cf) Thanks [@farhanW3](https://github.com/farhanW3)! - Updated the error messages
|
||||||
|
|
||||||
|
- Updated dependencies [[`a5d0be93`](https://github.com/thirdweb-dev/js/commit/a5d0be939a143095e769b68cf86360bfe4720744), [`c0a6d2f1`](https://github.com/thirdweb-dev/js/commit/c0a6d2f18231310d143c9b0cb1b2ff59315087a4), [`a9f2ff73`](https://github.com/thirdweb-dev/js/commit/a9f2ff73c9f83f05c3e2d3c53b23b2843e8a2576), [`fd981655`](https://github.com/thirdweb-dev/js/commit/fd9816556fe595b0c764e34dbcf15b0ad1677edb), [`becbb637`](https://github.com/thirdweb-dev/js/commit/becbb637367285ed3d8d7d131e1020bf23e38298), [`fd981655`](https://github.com/thirdweb-dev/js/commit/fd9816556fe595b0c764e34dbcf15b0ad1677edb), [`c9bf4f05`](https://github.com/thirdweb-dev/js/commit/c9bf4f05c161707c6eb799ecef82f462e4a82405), [`67b145b9`](https://github.com/thirdweb-dev/js/commit/67b145b94dafb2fb1d90553ed4829f0ed22e2907), [`5ee700e8`](https://github.com/thirdweb-dev/js/commit/5ee700e80438650fa253c25c0bee6658ce68d2cf), [`9f5adc5c`](https://github.com/thirdweb-dev/js/commit/9f5adc5c5c2782ffb878759df481e5fb1e1740e5)]:
|
||||||
|
- @thirdweb-dev/sdk@3.10.44
|
||||||
|
- @thirdweb-dev/wallets@1.1.8
|
||||||
|
- @thirdweb-dev/chains@0.1.41
|
||||||
|
|
||||||
|
## 3.14.24
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`3b6b0746`](https://github.com/thirdweb-dev/js/commit/3b6b0746b3fc792f4c5092814a7abfabcbc9801e), [`b0ec1d80`](https://github.com/thirdweb-dev/js/commit/b0ec1d80839efccad11b50afbf2216c2c132cf7e)]:
|
||||||
|
- @thirdweb-dev/storage@1.2.3
|
||||||
|
- @thirdweb-dev/wallets@1.1.7
|
||||||
|
- @thirdweb-dev/sdk@3.10.43
|
||||||
|
|
||||||
## 3.14.23
|
## 3.14.23
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/react-core",
|
"name": "@thirdweb-dev/react-core",
|
||||||
"version": "3.14.23",
|
"version": "3.14.25",
|
||||||
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react-core",
|
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react-core",
|
||||||
"author": "thirdweb eng <[email protected]>",
|
"author": "thirdweb eng <[email protected]>",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
|
|||||||
@@ -161,6 +161,7 @@ export const ThirdwebProviderCore = <TChains extends Chain[]>({
|
|||||||
storageInterface={props.storageInterface}
|
storageInterface={props.storageInterface}
|
||||||
authConfig={props.authConfig}
|
authConfig={props.authConfig}
|
||||||
clientId={props.clientId}
|
clientId={props.clientId}
|
||||||
|
secretKey={props.secretKey}
|
||||||
>
|
>
|
||||||
<ThirdwebAuthProvider value={props.authConfig}>
|
<ThirdwebAuthProvider value={props.authConfig}>
|
||||||
{props.children}
|
{props.children}
|
||||||
|
|||||||
@@ -321,6 +321,7 @@ export function ThirdwebWalletProvider(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.error("Failed to auto connect wallet");
|
||||||
console.error(e);
|
console.error(e);
|
||||||
setConnectionStatus("disconnected");
|
setConnectionStatus("disconnected");
|
||||||
return;
|
return;
|
||||||
@@ -349,6 +350,7 @@ export function ThirdwebWalletProvider(
|
|||||||
});
|
});
|
||||||
setConnectedWallet(wallet, walletInfo.connectParams, true);
|
setConnectedWallet(wallet, walletInfo.connectParams, true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.error("Failed to auto connect wallet");
|
||||||
console.error(e);
|
console.error(e);
|
||||||
lastConnectedWalletStorage.removeItem(
|
lastConnectedWalletStorage.removeItem(
|
||||||
LAST_CONNECTED_WALLET_STORAGE_KEY,
|
LAST_CONNECTED_WALLET_STORAGE_KEY,
|
||||||
|
|||||||
@@ -21,13 +21,14 @@ import type {
|
|||||||
SmartContract,
|
SmartContract,
|
||||||
} from "@thirdweb-dev/sdk";
|
} from "@thirdweb-dev/sdk";
|
||||||
import invariant from "tiny-invariant";
|
import invariant from "tiny-invariant";
|
||||||
|
import { WalletAddress } from "../../types";
|
||||||
|
|
||||||
/** **********************/
|
/** **********************/
|
||||||
/** READ HOOKS **/
|
/** READ HOOKS **/
|
||||||
/** **********************/
|
/** **********************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all accounts
|
* Get all signers of account
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```javascript
|
* ```javascript
|
||||||
@@ -50,7 +51,7 @@ export function useAccountSigners(
|
|||||||
requiredParamInvariant(contract, "No Contract instance provided");
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
invariant(
|
invariant(
|
||||||
contract.account.getAllSigners,
|
contract.account.getAllSigners,
|
||||||
"Contract instance does not support contract.account.getSignersWithRestrictions",
|
"Contract instance does not support contract.account.getAllSigners",
|
||||||
);
|
);
|
||||||
return contract.account.getAllSigners();
|
return contract.account.getAllSigners();
|
||||||
},
|
},
|
||||||
@@ -58,6 +59,71 @@ export function useAccountSigners(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all admins of account
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```javascript
|
||||||
|
* const { data: accounts, isLoading, error } = useAccountSigners(contract);
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param contract - an instance of a account
|
||||||
|
* @returns a response object that includes an array of all admins of the provided account
|
||||||
|
* @twfeature Account
|
||||||
|
* @see {@link https://portal.thirdweb.com/react/react.useaccountadmins?utm_source=sdk | Documentation}
|
||||||
|
* @beta
|
||||||
|
*/
|
||||||
|
export function useAccountAdmins(
|
||||||
|
contract: RequiredParam<SmartContract>,
|
||||||
|
): UseQueryResult<WalletAddress[]> {
|
||||||
|
const contractAddress = contract?.getAddress();
|
||||||
|
return useQueryWithNetwork(
|
||||||
|
cacheKeys.contract.account.signers(contractAddress),
|
||||||
|
() => {
|
||||||
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
|
invariant(
|
||||||
|
contract.account.getAllAdmins,
|
||||||
|
"Contract instance does not support contract.account.getAllAdmins",
|
||||||
|
);
|
||||||
|
return contract.account.getAllAdmins();
|
||||||
|
},
|
||||||
|
{ enabled: !!contract },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all signers and admins of account
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```javascript
|
||||||
|
* const { data: accounts, isLoading, error } = useAccountSigners(contract);
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param contract - an instance of a account
|
||||||
|
* @returns a response object that includes an array of all admins of the provided account
|
||||||
|
* @twfeature Account
|
||||||
|
* @see {@link https://portal.thirdweb.com/react/react.useaccountadmins?utm_source=sdk | Documentation}
|
||||||
|
* @beta
|
||||||
|
*/
|
||||||
|
export function useAccountAdminsAndSigners(
|
||||||
|
contract: RequiredParam<SmartContract>,
|
||||||
|
): UseQueryResult<SignerWithPermissions[]> {
|
||||||
|
const contractAddress = contract?.getAddress();
|
||||||
|
return useQueryWithNetwork(
|
||||||
|
cacheKeys.contract.account.signers(contractAddress),
|
||||||
|
() => {
|
||||||
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
|
invariant(
|
||||||
|
contract.account.getAllAdminsAndSigners,
|
||||||
|
"Contract instance does not support contract.account.getAllAdminsAndSigners",
|
||||||
|
);
|
||||||
|
|
||||||
|
return contract.account.getAllAdminsAndSigners();
|
||||||
|
},
|
||||||
|
{ enabled: !!contract },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/** **********************/
|
/** **********************/
|
||||||
/** WRITE HOOKS **/
|
/** WRITE HOOKS **/
|
||||||
/** **********************/
|
/** **********************/
|
||||||
|
|||||||
@@ -203,7 +203,12 @@ export {
|
|||||||
} from "./hooks/async/account-factory";
|
} from "./hooks/async/account-factory";
|
||||||
|
|
||||||
// account
|
// account
|
||||||
export { useAccountSigners, useSetAccountSigners } from "./hooks/async/account";
|
export {
|
||||||
|
useAccountSigners,
|
||||||
|
useSetAccountSigners,
|
||||||
|
useAccountAdmins,
|
||||||
|
useAccountAdminsAndSigners,
|
||||||
|
} from "./hooks/async/account";
|
||||||
|
|
||||||
// thirdweb hooks (work as long as at least `<ThirdwebSdkProvider>` is used)
|
// thirdweb hooks (work as long as at least `<ThirdwebSdkProvider>` is used)
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ const WrappedThirdwebSDKProvider = <TChains extends Chain[]>({
|
|||||||
signer,
|
signer,
|
||||||
children,
|
children,
|
||||||
clientId,
|
clientId,
|
||||||
|
secretKey,
|
||||||
}: React.PropsWithChildren<
|
}: React.PropsWithChildren<
|
||||||
{ supportedChains: Readonly<TChains> } & Omit<
|
{ supportedChains: Readonly<TChains> } & Omit<
|
||||||
ThirdwebSDKProviderProps<TChains>,
|
ThirdwebSDKProviderProps<TChains>,
|
||||||
@@ -92,7 +93,7 @@ const WrappedThirdwebSDKProvider = <TChains extends Chain[]>({
|
|||||||
// sdk from chainId
|
// sdk from chainId
|
||||||
sdk_ = new ThirdwebSDK(
|
sdk_ = new ThirdwebSDK(
|
||||||
chainId,
|
chainId,
|
||||||
{ ...mergedOptions, clientId },
|
{ ...mergedOptions, clientId, secretKey },
|
||||||
storageInterface,
|
storageInterface,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -113,7 +114,14 @@ const WrappedThirdwebSDKProvider = <TChains extends Chain[]>({
|
|||||||
(sdk_ as any)._chainId = chainId;
|
(sdk_ as any)._chainId = chainId;
|
||||||
|
|
||||||
return sdk_;
|
return sdk_;
|
||||||
}, [activeChainId, supportedChains, sdkOptions, storageInterface, clientId]);
|
}, [
|
||||||
|
activeChainId,
|
||||||
|
supportedChains,
|
||||||
|
sdkOptions,
|
||||||
|
storageInterface,
|
||||||
|
clientId,
|
||||||
|
secretKey,
|
||||||
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// if we have an sdk and a signer update the signer
|
// if we have an sdk and a signer update the signer
|
||||||
@@ -163,7 +171,7 @@ export const ThirdwebSDKProvider = <TChains extends Chain[]>({
|
|||||||
}: React.PropsWithChildren<ThirdwebSDKProviderProps<TChains>>) => {
|
}: React.PropsWithChildren<ThirdwebSDKProviderProps<TChains>>) => {
|
||||||
if (!clientId) {
|
if (!clientId) {
|
||||||
checkClientIdOrSecretKey(
|
checkClientIdOrSecretKey(
|
||||||
"No clientId provided in ThirdwebSDK. You will have limited access to thirdweb's services for storage, RPC, and account abstraction. You can get a clientId from https://thirdweb.com/create-api-key",
|
"No API key. Please provide a clientId. It is required to access thirdweb's services. You can create a key at https://thirdweb.com/create-api-key",
|
||||||
clientId,
|
clientId,
|
||||||
undefined,
|
undefined,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -45,4 +45,7 @@ export interface ThirdwebSDKProviderProps<TChains extends Chain[]>
|
|||||||
|
|
||||||
// client Id for thirdweb services
|
// client Id for thirdweb services
|
||||||
clientId?: string;
|
clientId?: string;
|
||||||
|
|
||||||
|
// pass in a secret key when doing server side rendering
|
||||||
|
secretKey?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
# @thirdweb-dev/react-native-compat
|
# @thirdweb-dev/react-native-compat
|
||||||
|
|
||||||
|
## 0.2.44
|
||||||
|
|
||||||
|
## 0.2.43
|
||||||
|
|
||||||
## 0.2.42
|
## 0.2.42
|
||||||
|
|
||||||
## 0.2.41
|
## 0.2.41
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/react-native-compat",
|
"name": "@thirdweb-dev/react-native-compat",
|
||||||
"description": "Shims for Thirdweb in React Native Projects",
|
"description": "Shims for Thirdweb in React Native Projects",
|
||||||
"version": "0.2.42",
|
"version": "0.2.44",
|
||||||
"author": "thirdweb eng <[email protected]>",
|
"author": "thirdweb eng <[email protected]>",
|
||||||
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react-native-compat",
|
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react-native-compat",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
|
|||||||
@@ -1,5 +1,27 @@
|
|||||||
# @thirdweb-dev/react-native
|
# @thirdweb-dev/react-native
|
||||||
|
|
||||||
|
## 0.2.44
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#1429](https://github.com/thirdweb-dev/js/pull/1429) [`ab36d84f`](https://github.com/thirdweb-dev/js/commit/ab36d84f1ce5647fa52475b4a35ea29d5007ad9b) Thanks [@iketw](https://github.com/iketw)! - Pass secretKey in the React SDK for server-side rendering
|
||||||
|
|
||||||
|
- Updated dependencies [[`a5d0be93`](https://github.com/thirdweb-dev/js/commit/a5d0be939a143095e769b68cf86360bfe4720744), [`c0a6d2f1`](https://github.com/thirdweb-dev/js/commit/c0a6d2f18231310d143c9b0cb1b2ff59315087a4), [`a9f2ff73`](https://github.com/thirdweb-dev/js/commit/a9f2ff73c9f83f05c3e2d3c53b23b2843e8a2576), [`fd981655`](https://github.com/thirdweb-dev/js/commit/fd9816556fe595b0c764e34dbcf15b0ad1677edb), [`becbb637`](https://github.com/thirdweb-dev/js/commit/becbb637367285ed3d8d7d131e1020bf23e38298), [`2283d210`](https://github.com/thirdweb-dev/js/commit/2283d21027503e047c25df5ebb21bdde0734be9e), [`fd981655`](https://github.com/thirdweb-dev/js/commit/fd9816556fe595b0c764e34dbcf15b0ad1677edb), [`ab36d84f`](https://github.com/thirdweb-dev/js/commit/ab36d84f1ce5647fa52475b4a35ea29d5007ad9b), [`c9bf4f05`](https://github.com/thirdweb-dev/js/commit/c9bf4f05c161707c6eb799ecef82f462e4a82405), [`67b145b9`](https://github.com/thirdweb-dev/js/commit/67b145b94dafb2fb1d90553ed4829f0ed22e2907), [`5ee700e8`](https://github.com/thirdweb-dev/js/commit/5ee700e80438650fa253c25c0bee6658ce68d2cf), [`9f5adc5c`](https://github.com/thirdweb-dev/js/commit/9f5adc5c5c2782ffb878759df481e5fb1e1740e5)]:
|
||||||
|
- @thirdweb-dev/sdk@3.10.44
|
||||||
|
- @thirdweb-dev/wallets@1.1.8
|
||||||
|
- @thirdweb-dev/react-core@3.14.25
|
||||||
|
- @thirdweb-dev/chains@0.1.41
|
||||||
|
|
||||||
|
## 0.2.43
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`3b6b0746`](https://github.com/thirdweb-dev/js/commit/3b6b0746b3fc792f4c5092814a7abfabcbc9801e), [`b0ec1d80`](https://github.com/thirdweb-dev/js/commit/b0ec1d80839efccad11b50afbf2216c2c132cf7e)]:
|
||||||
|
- @thirdweb-dev/storage@1.2.3
|
||||||
|
- @thirdweb-dev/wallets@1.1.7
|
||||||
|
- @thirdweb-dev/sdk@3.10.43
|
||||||
|
- @thirdweb-dev/react-core@3.14.24
|
||||||
|
|
||||||
## 0.2.42
|
## 0.2.42
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/react-native",
|
"name": "@thirdweb-dev/react-native",
|
||||||
"version": "0.2.42",
|
"version": "0.2.44",
|
||||||
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react-native",
|
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react-native",
|
||||||
"author": "thirdweb eng <[email protected]>",
|
"author": "thirdweb eng <[email protected]>",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
|
|||||||
@@ -18,7 +18,10 @@ import { walletIds } from "@thirdweb-dev/wallets";
|
|||||||
import { ThirdwebStorage } from "../../core/storage/storage";
|
import { ThirdwebStorage } from "../../core/storage/storage";
|
||||||
|
|
||||||
interface ThirdwebProviderProps<TChains extends Chain[]>
|
interface ThirdwebProviderProps<TChains extends Chain[]>
|
||||||
extends Omit<ThirdwebProviderCoreProps<TChains>, "supportedWallets"> {
|
extends Omit<
|
||||||
|
ThirdwebProviderCoreProps<TChains>,
|
||||||
|
"supportedWallets" | "secretKey"
|
||||||
|
> {
|
||||||
/**
|
/**
|
||||||
* Wallets that will be supported by the dApp
|
* Wallets that will be supported by the dApp
|
||||||
* @defaultValue [MetaMaskWallet, CoinbaseWallet]
|
* @defaultValue [MetaMaskWallet, CoinbaseWallet]
|
||||||
|
|||||||
@@ -1,5 +1,28 @@
|
|||||||
# @thirdweb-dev/react
|
# @thirdweb-dev/react
|
||||||
|
|
||||||
|
## 3.14.25
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#1429](https://github.com/thirdweb-dev/js/pull/1429) [`ab36d84f`](https://github.com/thirdweb-dev/js/commit/ab36d84f1ce5647fa52475b4a35ea29d5007ad9b) Thanks [@iketw](https://github.com/iketw)! - Pass secretKey in the React SDK for server-side rendering
|
||||||
|
|
||||||
|
- [#1430](https://github.com/thirdweb-dev/js/pull/1430) [`a9f2ff73`](https://github.com/thirdweb-dev/js/commit/a9f2ff73c9f83f05c3e2d3c53b23b2843e8a2576) Thanks [@MananTank](https://github.com/MananTank)! - - Add base-gor as a valid safe address prefix
|
||||||
|
- Log failed to autoconnect error on react-core too
|
||||||
|
- Updated dependencies [[`a5d0be93`](https://github.com/thirdweb-dev/js/commit/a5d0be939a143095e769b68cf86360bfe4720744), [`c0a6d2f1`](https://github.com/thirdweb-dev/js/commit/c0a6d2f18231310d143c9b0cb1b2ff59315087a4), [`a9f2ff73`](https://github.com/thirdweb-dev/js/commit/a9f2ff73c9f83f05c3e2d3c53b23b2843e8a2576), [`fd981655`](https://github.com/thirdweb-dev/js/commit/fd9816556fe595b0c764e34dbcf15b0ad1677edb), [`becbb637`](https://github.com/thirdweb-dev/js/commit/becbb637367285ed3d8d7d131e1020bf23e38298), [`2283d210`](https://github.com/thirdweb-dev/js/commit/2283d21027503e047c25df5ebb21bdde0734be9e), [`fd981655`](https://github.com/thirdweb-dev/js/commit/fd9816556fe595b0c764e34dbcf15b0ad1677edb), [`ab36d84f`](https://github.com/thirdweb-dev/js/commit/ab36d84f1ce5647fa52475b4a35ea29d5007ad9b), [`c9bf4f05`](https://github.com/thirdweb-dev/js/commit/c9bf4f05c161707c6eb799ecef82f462e4a82405), [`67b145b9`](https://github.com/thirdweb-dev/js/commit/67b145b94dafb2fb1d90553ed4829f0ed22e2907), [`5ee700e8`](https://github.com/thirdweb-dev/js/commit/5ee700e80438650fa253c25c0bee6658ce68d2cf), [`9f5adc5c`](https://github.com/thirdweb-dev/js/commit/9f5adc5c5c2782ffb878759df481e5fb1e1740e5)]:
|
||||||
|
- @thirdweb-dev/sdk@3.10.44
|
||||||
|
- @thirdweb-dev/wallets@1.1.8
|
||||||
|
- @thirdweb-dev/react-core@3.14.25
|
||||||
|
- @thirdweb-dev/chains@0.1.41
|
||||||
|
|
||||||
|
## 3.14.24
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`3b6b0746`](https://github.com/thirdweb-dev/js/commit/3b6b0746b3fc792f4c5092814a7abfabcbc9801e), [`b0ec1d80`](https://github.com/thirdweb-dev/js/commit/b0ec1d80839efccad11b50afbf2216c2c132cf7e)]:
|
||||||
|
- @thirdweb-dev/wallets@1.1.7
|
||||||
|
- @thirdweb-dev/sdk@3.10.43
|
||||||
|
- @thirdweb-dev/react-core@3.14.24
|
||||||
|
|
||||||
## 3.14.23
|
## 3.14.23
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/react",
|
"name": "@thirdweb-dev/react",
|
||||||
"version": "3.14.23",
|
"version": "3.14.25",
|
||||||
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react",
|
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react",
|
||||||
"author": "thirdweb eng <[email protected]>",
|
"author": "thirdweb eng <[email protected]>",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ interface ThirdwebProviderProps<TChains extends Chain[]>
|
|||||||
export const ThirdwebProvider = <
|
export const ThirdwebProvider = <
|
||||||
TChains extends Chain[] = typeof defaultChains,
|
TChains extends Chain[] = typeof defaultChains,
|
||||||
>({
|
>({
|
||||||
clientId: clientId,
|
|
||||||
supportedWallets,
|
supportedWallets,
|
||||||
theme,
|
theme,
|
||||||
children,
|
children,
|
||||||
@@ -69,7 +68,6 @@ export const ThirdwebProvider = <
|
|||||||
<ThemeProvider theme={theme === "dark" ? darkTheme : lightTheme}>
|
<ThemeProvider theme={theme === "dark" ? darkTheme : lightTheme}>
|
||||||
<ThirdwebProviderCore
|
<ThirdwebProviderCore
|
||||||
theme={theme}
|
theme={theme}
|
||||||
clientId={clientId}
|
|
||||||
supportedWallets={wallets}
|
supportedWallets={wallets}
|
||||||
{...restProps}
|
{...restProps}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ export const gnosisAddressPrefixToChainId = {
|
|||||||
bnb: 56,
|
bnb: 56,
|
||||||
oeth: 10,
|
oeth: 10,
|
||||||
gor: 5,
|
gor: 5,
|
||||||
|
"base-gor": 84531,
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export const SelectAccount: React.FC<{
|
export const SelectAccount: React.FC<{
|
||||||
|
|||||||
@@ -1,5 +1,34 @@
|
|||||||
# @thirdweb-dev/sdk
|
# @thirdweb-dev/sdk
|
||||||
|
|
||||||
|
## 3.10.44
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#1444](https://github.com/thirdweb-dev/js/pull/1444) [`a5d0be93`](https://github.com/thirdweb-dev/js/commit/a5d0be939a143095e769b68cf86360bfe4720744) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Optimize claimConditions.getAll()
|
||||||
|
|
||||||
|
- [#1438](https://github.com/thirdweb-dev/js/pull/1438) [`c0a6d2f1`](https://github.com/thirdweb-dev/js/commit/c0a6d2f18231310d143c9b0cb1b2ff59315087a4) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Add sdk.deployer.deployOpenEdition() convenience function
|
||||||
|
|
||||||
|
- [#1441](https://github.com/thirdweb-dev/js/pull/1441) [`becbb637`](https://github.com/thirdweb-dev/js/commit/becbb637367285ed3d8d7d131e1020bf23e38298) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Sanitize NFT description input strings
|
||||||
|
|
||||||
|
- [#1433](https://github.com/thirdweb-dev/js/pull/1433) [`c9bf4f05`](https://github.com/thirdweb-dev/js/commit/c9bf4f05c161707c6eb799ecef82f462e4a82405) Thanks [@iketw](https://github.com/iketw)! - Pass empty string when clientId is undefined
|
||||||
|
|
||||||
|
- [#1439](https://github.com/thirdweb-dev/js/pull/1439) [`67b145b9`](https://github.com/thirdweb-dev/js/commit/67b145b94dafb2fb1d90553ed4829f0ed22e2907) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Expose deployPublishContract alias
|
||||||
|
|
||||||
|
- [#1437](https://github.com/thirdweb-dev/js/pull/1437) [`5ee700e8`](https://github.com/thirdweb-dev/js/commit/5ee700e80438650fa253c25c0bee6658ce68d2cf) Thanks [@farhanW3](https://github.com/farhanW3)! - Updated the error messages
|
||||||
|
|
||||||
|
- Updated dependencies [[`fd981655`](https://github.com/thirdweb-dev/js/commit/fd9816556fe595b0c764e34dbcf15b0ad1677edb), [`9f5adc5c`](https://github.com/thirdweb-dev/js/commit/9f5adc5c5c2782ffb878759df481e5fb1e1740e5), [`9f5adc5c`](https://github.com/thirdweb-dev/js/commit/9f5adc5c5c2782ffb878759df481e5fb1e1740e5)]:
|
||||||
|
- @thirdweb-dev/chains@0.1.41
|
||||||
|
- @thirdweb-dev/contracts-js@1.3.11
|
||||||
|
|
||||||
|
## 3.10.43
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#1411](https://github.com/thirdweb-dev/js/pull/1411) [`3b6b0746`](https://github.com/thirdweb-dev/js/commit/3b6b0746b3fc792f4c5092814a7abfabcbc9801e) Thanks [@jnsdls](https://github.com/jnsdls)! - add auth token
|
||||||
|
|
||||||
|
- Updated dependencies [[`3b6b0746`](https://github.com/thirdweb-dev/js/commit/3b6b0746b3fc792f4c5092814a7abfabcbc9801e)]:
|
||||||
|
- @thirdweb-dev/storage@1.2.3
|
||||||
|
|
||||||
## 3.10.42
|
## 3.10.42
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/sdk",
|
"name": "@thirdweb-dev/sdk",
|
||||||
"version": "3.10.42",
|
"version": "3.10.44",
|
||||||
"description": "The main thirdweb SDK.",
|
"description": "The main thirdweb SDK.",
|
||||||
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/sdk",
|
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/sdk",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
|
|||||||
@@ -12,12 +12,41 @@ import { z } from "zod";
|
|||||||
export const BasicNFTInput = /* @__PURE__ */ (() =>
|
export const BasicNFTInput = /* @__PURE__ */ (() =>
|
||||||
z.object({
|
z.object({
|
||||||
name: z.union([z.string(), z.number()]).optional().nullable(),
|
name: z.union([z.string(), z.number()]).optional().nullable(),
|
||||||
description: z.string().nullable().optional().nullable(),
|
description: z
|
||||||
|
.string()
|
||||||
|
.nullable()
|
||||||
|
.optional()
|
||||||
|
.nullable()
|
||||||
|
.transform((i) => {
|
||||||
|
return sanitizeJSONString(i);
|
||||||
|
}),
|
||||||
image: FileOrBufferOrStringSchema.nullable().optional(),
|
image: FileOrBufferOrStringSchema.nullable().optional(),
|
||||||
|
|
||||||
animation_url: FileOrBufferOrStringSchema.optional().nullable(),
|
animation_url: FileOrBufferOrStringSchema.optional().nullable(),
|
||||||
}))();
|
}))();
|
||||||
|
|
||||||
|
function sanitizeJSONString(val: string | undefined | null) {
|
||||||
|
if (!val) {
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
return JSON.parse(JSON.stringify(val, escape));
|
||||||
|
}
|
||||||
|
|
||||||
|
function escape(key: string, val: any) {
|
||||||
|
if (typeof val !== "string") {
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
return val
|
||||||
|
.replace(/[\"]/g, '\\"')
|
||||||
|
.replace(/[\\]/g, "\\\\")
|
||||||
|
.replace(/[\/]/g, "\\/")
|
||||||
|
.replace(/[\b]/g, "\\b")
|
||||||
|
.replace(/[\f]/g, "\\f")
|
||||||
|
.replace(/[\n]/g, "\\n")
|
||||||
|
.replace(/[\r]/g, "\\r")
|
||||||
|
.replace(/[\t]/g, "\\t");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ export function getChainProvider(
|
|||||||
// if we still don't have an url fall back to just using the chainId or slug in the rpc and try that
|
// if we still don't have an url fall back to just using the chainId or slug in the rpc and try that
|
||||||
if (!rpcUrl) {
|
if (!rpcUrl) {
|
||||||
rpcUrl = `https://${chainId || network}.rpc.thirdweb.com/${
|
rpcUrl = `https://${chainId || network}.rpc.thirdweb.com/${
|
||||||
options.clientId
|
options.clientId || ""
|
||||||
}`;
|
}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +158,7 @@ export function getProviderFromRpcUrl(
|
|||||||
chainId?: number,
|
chainId?: number,
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const headers: Record<string, string> = {};
|
const headers: HeadersInit = {};
|
||||||
if (isTwUrl(rpcUrl)) {
|
if (isTwUrl(rpcUrl)) {
|
||||||
if (sdkOptions?.clientId) {
|
if (sdkOptions?.clientId) {
|
||||||
headers["x-client-id"] = sdkOptions?.clientId;
|
headers["x-client-id"] = sdkOptions?.clientId;
|
||||||
@@ -173,6 +173,12 @@ export function getProviderFromRpcUrl(
|
|||||||
} else if (sdkOptions?.secretKey) {
|
} else if (sdkOptions?.secretKey) {
|
||||||
headers["x-secret-key"] = sdkOptions?.secretKey;
|
headers["x-secret-key"] = sdkOptions?.secretKey;
|
||||||
}
|
}
|
||||||
|
// if we have a tw auth token on global context add it to the headers
|
||||||
|
if (typeof globalThis !== "undefined" && "TW_AUTH_TOKEN" in globalThis) {
|
||||||
|
headers["authorization"] = `Bearer ${
|
||||||
|
(globalThis as any).TW_AUTH_TOKEN as string
|
||||||
|
}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const match = rpcUrl.match(/^(ws|http)s?:/i);
|
const match = rpcUrl.match(/^(ws|http)s?:/i);
|
||||||
// Try the JSON batch provider if available
|
// Try the JSON batch provider if available
|
||||||
|
|||||||
@@ -270,6 +270,39 @@ export class Account<TContract extends IAccountCore>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all admins and non-admin signers with permissions to use the account.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```javascript
|
||||||
|
* const allAdminsAndSigners = await contract.account.getAllAdminsAndSigners();
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @returns all admins and non-admin signers with permissions to use the account.
|
||||||
|
*
|
||||||
|
* @twfeature Account
|
||||||
|
*/
|
||||||
|
public async getAllAdminsAndSigners(): Promise<SignerWithPermissions[]> {
|
||||||
|
const allAdmins = await this.getAllAdmins();
|
||||||
|
const transformedAdmins: SignerWithPermissions[] = allAdmins.map(
|
||||||
|
(admin) => {
|
||||||
|
return {
|
||||||
|
isAdmin: true,
|
||||||
|
signer: admin,
|
||||||
|
permissions: {
|
||||||
|
startDate: new Date(0),
|
||||||
|
expirationDate: new Date(0),
|
||||||
|
nativeTokenLimitPerTransaction: BigNumber.from(0),
|
||||||
|
approvedCallTargets: [],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
);
|
||||||
|
const allSigners = await this.getAllSigners();
|
||||||
|
|
||||||
|
return [...transformedAdmins, ...allSigners];
|
||||||
|
}
|
||||||
|
|
||||||
/*********************************
|
/*********************************
|
||||||
* WRITE FUNCTIONS
|
* WRITE FUNCTIONS
|
||||||
********************************/
|
********************************/
|
||||||
|
|||||||
@@ -158,14 +158,17 @@ export class DropClaimConditions<
|
|||||||
await this.contractWrapper.readContract.claimCondition();
|
await this.contractWrapper.readContract.claimCondition();
|
||||||
const startId = currentStartId.toNumber();
|
const startId = currentStartId.toNumber();
|
||||||
const count = countBn.toNumber();
|
const count = countBn.toNumber();
|
||||||
const conditions: AbstractClaimConditionContractStruct[] = [];
|
const conditions: Promise<AbstractClaimConditionContractStruct>[] = [];
|
||||||
for (let i = startId; i < startId + count; i++) {
|
for (let i = startId; i < startId + count; i++) {
|
||||||
conditions.push(await this.get(i));
|
conditions.push(this.get(i));
|
||||||
}
|
}
|
||||||
const metadata = await this.metadata.get();
|
const [metadata, decimals, ...fetchedConditions] = await Promise.all([
|
||||||
const decimals = await this.getTokenDecimals();
|
this.metadata.get(),
|
||||||
|
this.getTokenDecimals(),
|
||||||
|
...conditions,
|
||||||
|
]);
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
conditions.map((c) =>
|
fetchedConditions.map((c) =>
|
||||||
transformResultToClaimCondition(
|
transformResultToClaimCondition(
|
||||||
c,
|
c,
|
||||||
decimals,
|
decimals,
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ import type {
|
|||||||
DeployOptions,
|
DeployOptions,
|
||||||
DeployMetadata,
|
DeployMetadata,
|
||||||
DeployEvent,
|
DeployEvent,
|
||||||
|
OpenEditionContractDeployMetadata,
|
||||||
} from "../types/deploy";
|
} from "../types/deploy";
|
||||||
import type { ContractWithMetadata } from "../types/registry";
|
import type { ContractWithMetadata } from "../types/registry";
|
||||||
import { DeploySchemaForPrebuiltContractType } from "../contracts";
|
import { DeploySchemaForPrebuiltContractType } from "../contracts";
|
||||||
@@ -113,6 +114,7 @@ import { LoyaltyCardContractDeploy } from "../schema/contracts/loyalty-card";
|
|||||||
import { getDefaultTrustedForwarders } from "../constants";
|
import { getDefaultTrustedForwarders } from "../constants";
|
||||||
import { checkClientIdOrSecretKey } from "../../core/utils/apiKey";
|
import { checkClientIdOrSecretKey } from "../../core/utils/apiKey";
|
||||||
import { getProcessEnv } from "../../core/utils/process";
|
import { getProcessEnv } from "../../core/utils/process";
|
||||||
|
import { DropErc721ContractSchema } from "../schema";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main entry point for the thirdweb SDK
|
* The main entry point for the thirdweb SDK
|
||||||
@@ -263,11 +265,11 @@ export class ThirdwebSDK extends RPCConnectionHandler {
|
|||||||
storage?: IThirdwebStorage,
|
storage?: IThirdwebStorage,
|
||||||
) {
|
) {
|
||||||
const apiKeyType = typeof window !== "undefined" ? "clientId" : "secretKey";
|
const apiKeyType = typeof window !== "undefined" ? "clientId" : "secretKey";
|
||||||
checkClientIdOrSecretKey(
|
let warnMessage = `No API key. Please provide a ${apiKeyType}. It is required to access thirdweb's services. You can create a key at https://thirdweb.com/create-api-key`;
|
||||||
`No ${apiKeyType} provided in ThirdwebSDK. You will have limited access to thirdweb's services for storage, RPC, and account abstraction. You can get a ${apiKeyType} from https://thirdweb.com/create-api-key`,
|
if (typeof window === "undefined" && !options.secretKey) {
|
||||||
options.clientId,
|
warnMessage = `Please provide a secret key instead of the clientId. Create a new API Key at https://thirdweb.com/create-api-key`;
|
||||||
options.secretKey,
|
}
|
||||||
);
|
checkClientIdOrSecretKey(warnMessage, options.clientId, options.secretKey);
|
||||||
|
|
||||||
if (isChainConfig(network)) {
|
if (isChainConfig(network)) {
|
||||||
options = {
|
options = {
|
||||||
@@ -1021,6 +1023,63 @@ export class ContractDeployer extends RPCConnectionHandler {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deploys a new OpenEditionERC721 contract
|
||||||
|
*
|
||||||
|
* @remarks Deploys a OpenEdition contract and returns the address of the deployed contract
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```javascript
|
||||||
|
* const contractAddress = await sdk.deployer.deployOpenEdition({
|
||||||
|
* name: "My Open Edition",
|
||||||
|
* primary_sale_recipient: "your-address",
|
||||||
|
* });
|
||||||
|
* ```
|
||||||
|
* @param metadata - the contract metadata
|
||||||
|
* @returns the address of the deployed contract
|
||||||
|
*/
|
||||||
|
deployOpenEdition = /* @__PURE__ */ buildDeployTransactionFunction(
|
||||||
|
async (
|
||||||
|
metadata: OpenEditionContractDeployMetadata,
|
||||||
|
options?: DeployOptions,
|
||||||
|
): Promise<DeployTransaction> => {
|
||||||
|
const parsedMetadata = await DropErc721ContractSchema.deploy.parseAsync(
|
||||||
|
metadata,
|
||||||
|
);
|
||||||
|
const contractURI = await this.storage.upload(parsedMetadata);
|
||||||
|
|
||||||
|
const chainId = (await this.getProvider().getNetwork()).chainId;
|
||||||
|
const trustedForwarders = getDefaultTrustedForwarders(chainId);
|
||||||
|
// add default forwarders to any custom forwarders passed in
|
||||||
|
if (
|
||||||
|
metadata.trusted_forwarders &&
|
||||||
|
metadata.trusted_forwarders.length > 0
|
||||||
|
) {
|
||||||
|
trustedForwarders.push(...metadata.trusted_forwarders);
|
||||||
|
}
|
||||||
|
|
||||||
|
const signerAddress = await this.getSigner()?.getAddress();
|
||||||
|
|
||||||
|
const deployArgs = [
|
||||||
|
signerAddress,
|
||||||
|
parsedMetadata.name,
|
||||||
|
parsedMetadata.symbol,
|
||||||
|
contractURI,
|
||||||
|
trustedForwarders,
|
||||||
|
parsedMetadata.primary_sale_recipient,
|
||||||
|
parsedMetadata.fee_recipient,
|
||||||
|
parsedMetadata.seller_fee_basis_points,
|
||||||
|
];
|
||||||
|
|
||||||
|
return await this.deployReleasedContract.prepare(
|
||||||
|
THIRDWEB_DEPLOYER,
|
||||||
|
"OpenEditionERC721",
|
||||||
|
deployArgs,
|
||||||
|
options,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deploys a new SignatureDrop contract
|
* Deploys a new SignatureDrop contract
|
||||||
*
|
*
|
||||||
@@ -1457,6 +1516,8 @@ export class ContractDeployer extends RPCConnectionHandler {
|
|||||||
* @param publisherAddress the address of the publisher
|
* @param publisherAddress the address of the publisher
|
||||||
* @param contractName the name of the contract to deploy
|
* @param contractName the name of the contract to deploy
|
||||||
* @param constructorParams the constructor params to pass to the contract
|
* @param constructorParams the constructor params to pass to the contract
|
||||||
|
*
|
||||||
|
* @deprecated use deployPublishedContract instead
|
||||||
*/
|
*/
|
||||||
deployReleasedContract = /* @__PURE__ */ buildDeployTransactionFunction(
|
deployReleasedContract = /* @__PURE__ */ buildDeployTransactionFunction(
|
||||||
async (
|
async (
|
||||||
@@ -1479,6 +1540,16 @@ export class ContractDeployer extends RPCConnectionHandler {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deploy any published contract by its name
|
||||||
|
* @param publisherAddress the address of the publisher
|
||||||
|
* @param contractName the name of the contract to deploy
|
||||||
|
* @param constructorParams the constructor params to pass to the contract
|
||||||
|
* @param version Optional: the version of the contract to deploy or "latest"
|
||||||
|
* @param options Optional: the deploy options
|
||||||
|
*/
|
||||||
|
deployPublishedContract = this.deployReleasedContract;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deploy a proxy contract of a given implementation via the given factory
|
* Deploy a proxy contract of a given implementation via the given factory
|
||||||
* @param factoryAddress
|
* @param factoryAddress
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ export type SignerPermissionsInput = z.input<typeof SignerPermissionsSchema>;
|
|||||||
export type SignerPermissionsOutput = z.output<typeof SignerPermissionsSchema>;
|
export type SignerPermissionsOutput = z.output<typeof SignerPermissionsSchema>;
|
||||||
|
|
||||||
export type SignerWithPermissions = {
|
export type SignerWithPermissions = {
|
||||||
|
isAdmin?: boolean;
|
||||||
signer: string;
|
signer: string;
|
||||||
permissions: SignerPermissions;
|
permissions: SignerPermissions;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -58,6 +58,53 @@ export interface NFTContractDeployMetadata {
|
|||||||
app_uri?: string;
|
app_uri?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for deploying an OpenEdition contract
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export interface OpenEditionContractDeployMetadata {
|
||||||
|
/**
|
||||||
|
* name of the contract
|
||||||
|
*/
|
||||||
|
name: string;
|
||||||
|
/**
|
||||||
|
* Optional description of the contract
|
||||||
|
*/
|
||||||
|
description?: string;
|
||||||
|
/**
|
||||||
|
* Optional image for the contract
|
||||||
|
*/
|
||||||
|
image?: FileOrBufferOrString;
|
||||||
|
/**
|
||||||
|
* Optional url for the contract
|
||||||
|
*/
|
||||||
|
external_link?: string;
|
||||||
|
/**
|
||||||
|
* Symbol for the NFTs
|
||||||
|
*/
|
||||||
|
symbol?: string;
|
||||||
|
/**
|
||||||
|
* Custom gasless trusted forwarder addresses
|
||||||
|
*/
|
||||||
|
trusted_forwarders?: AddressOrEns[];
|
||||||
|
/**
|
||||||
|
* The address that will receive the proceeds from primary sales
|
||||||
|
*/
|
||||||
|
primary_sale_recipient: AddressOrEns;
|
||||||
|
/**
|
||||||
|
* The address that will receive the proceeds from secondary sales (royalties)
|
||||||
|
*/
|
||||||
|
fee_recipient?: AddressOrEns;
|
||||||
|
/**
|
||||||
|
* The percentage (in basis points) of royalties for secondary sales
|
||||||
|
*/
|
||||||
|
seller_fee_basis_points?: number;
|
||||||
|
/**
|
||||||
|
* The default app for this contract
|
||||||
|
*/
|
||||||
|
app_uri?: string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Options for deploying a Token contract
|
* Options for deploying a Token contract
|
||||||
* @public
|
* @public
|
||||||
|
|||||||
@@ -1,5 +1,25 @@
|
|||||||
# @thirdweb-dev/service-utils
|
# @thirdweb-dev/service-utils
|
||||||
|
|
||||||
|
## 0.3.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- [#1424](https://github.com/thirdweb-dev/js/pull/1424) [`d01e6396`](https://github.com/thirdweb-dev/js/commit/d01e6396d176a162aaacb10792f0d9abade62a1f) Thanks [@arcoraven](https://github.com/arcoraven)! - Add helper to publish usage events from backend services
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#1440](https://github.com/thirdweb-dev/js/pull/1440) [`5ec0f064`](https://github.com/thirdweb-dev/js/commit/5ec0f064d27acbd5225934dfe8ea2cd2c5af3997) Thanks [@arcoraven](https://github.com/arcoraven)! - [service-utils] Switch to aws4fetch to call AWS services
|
||||||
|
|
||||||
|
- [#1437](https://github.com/thirdweb-dev/js/pull/1437) [`5ee700e8`](https://github.com/thirdweb-dev/js/commit/5ee700e80438650fa253c25c0bee6658ce68d2cf) Thanks [@farhanW3](https://github.com/farhanW3)! - Updated the error messages
|
||||||
|
|
||||||
|
- [#1435](https://github.com/thirdweb-dev/js/pull/1435) [`2a3cd62d`](https://github.com/thirdweb-dev/js/commit/2a3cd62dc9af6accae5c2c48ef4956d139a637e4) Thanks [@arcoraven](https://github.com/arcoraven)! - Use string type for gasPricePerUnit
|
||||||
|
|
||||||
|
## 0.2.5
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#1411](https://github.com/thirdweb-dev/js/pull/1411) [`3b6b0746`](https://github.com/thirdweb-dev/js/commit/3b6b0746b3fc792f4c5092814a7abfabcbc9801e) Thanks [@jnsdls](https://github.com/jnsdls)! - allow account level auth via jwt
|
||||||
|
|
||||||
## 0.2.4
|
## 0.2.4
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1 +1,7 @@
|
|||||||
### todo
|
# Service Utils
|
||||||
|
|
||||||
|
This repository contains utilities that handle common requirements for thirdweb services.
|
||||||
|
|
||||||
|
- `/cf-worker`: for use only in Cloudflare Worker services
|
||||||
|
- `/node`: for use in self-hosted services
|
||||||
|
- `/core`: for use in any service
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/service-utils",
|
"name": "@thirdweb-dev/service-utils",
|
||||||
"version": "0.2.4",
|
"version": "0.3.0",
|
||||||
"main": "dist/thirdweb-dev-service-utils.cjs.js",
|
"main": "dist/thirdweb-dev-service-utils.cjs.js",
|
||||||
"module": "dist/thirdweb-dev-service-utils.esm.js",
|
"module": "dist/thirdweb-dev-service-utils.esm.js",
|
||||||
"exports": {
|
"exports": {
|
||||||
@@ -41,6 +41,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@cloudflare/workers-types": "^4.20230724.0",
|
"@cloudflare/workers-types": "^4.20230724.0",
|
||||||
"@preconstruct/cli": "2.7.0",
|
"@preconstruct/cli": "2.7.0",
|
||||||
|
"@smithy/types": "^2.0.2",
|
||||||
"@thirdweb-dev/tsconfig": "workspace:*",
|
"@thirdweb-dev/tsconfig": "workspace:*",
|
||||||
"@types/jest": "^29.5.3",
|
"@types/jest": "^29.5.3",
|
||||||
"@types/node": "^18.17.1",
|
"@types/node": "^18.17.1",
|
||||||
@@ -61,5 +62,9 @@
|
|||||||
"build": "tsc && preconstruct build",
|
"build": "tsc && preconstruct build",
|
||||||
"push": "yalc push",
|
"push": "yalc push",
|
||||||
"test": "jest"
|
"test": "jest"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"aws4fetch": "^1.0.17",
|
||||||
|
"zod": "^3.20.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import type { ExecutionContext, KVNamespace } from "@cloudflare/workers-types";
|
import type { ExecutionContext, KVNamespace } from "@cloudflare/workers-types";
|
||||||
import type { ApiKeyMetadata, CoreServiceConfig } from "../core/api";
|
import type {
|
||||||
|
ApiKeyMetadata,
|
||||||
|
AccountMetadata,
|
||||||
|
CoreServiceConfig,
|
||||||
|
} from "../core/api";
|
||||||
import { authorize } from "../core/authorize";
|
import { authorize } from "../core/authorize";
|
||||||
|
|
||||||
import type { Request } from "@cloudflare/workers-types";
|
import type { Request } from "@cloudflare/workers-types";
|
||||||
@@ -8,6 +12,7 @@ import type { AuthorizationResult } from "../core/authorize/types";
|
|||||||
import type { CoreAuthInput } from "../core/types";
|
import type { CoreAuthInput } from "../core/types";
|
||||||
|
|
||||||
export * from "../core/services";
|
export * from "../core/services";
|
||||||
|
export * from "./usage";
|
||||||
|
|
||||||
type WorkerServiceConfig = CoreServiceConfig & {
|
type WorkerServiceConfig = CoreServiceConfig & {
|
||||||
kvStore: KVNamespace;
|
kvStore: KVNamespace;
|
||||||
@@ -47,7 +52,7 @@ export async function authorizeWorker(
|
|||||||
|
|
||||||
return await authorize(authData, serviceConfig, {
|
return await authorize(authData, serviceConfig, {
|
||||||
get: async (clientId: string) => serviceConfig.kvStore.get(clientId),
|
get: async (clientId: string) => serviceConfig.kvStore.get(clientId),
|
||||||
put: (clientId: string, apiKeyMeta: ApiKeyMetadata) =>
|
put: (clientId: string, apiKeyMeta: ApiKeyMetadata | AccountMetadata) =>
|
||||||
serviceConfig.ctx.waitUntil(
|
serviceConfig.ctx.waitUntil(
|
||||||
serviceConfig.kvStore.put(
|
serviceConfig.kvStore.put(
|
||||||
clientId,
|
clientId,
|
||||||
@@ -124,7 +129,20 @@ async function extractAuthorizationData(
|
|||||||
clientId = derivedClientId;
|
clientId = derivedClientId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let jwt: string | null = null;
|
||||||
|
if (headers.has("authorization")) {
|
||||||
|
const authHeader = headers.get("authorization");
|
||||||
|
if (authHeader) {
|
||||||
|
const [type, token] = authHeader.split(" ");
|
||||||
|
if (type.toLowerCase() === "bearer") {
|
||||||
|
jwt = token;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
jwt,
|
||||||
|
hashedJWT: jwt ? await hashSecretKey(jwt) : null,
|
||||||
secretKey,
|
secretKey,
|
||||||
clientId,
|
clientId,
|
||||||
origin,
|
origin,
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
import { AwsClient } from "aws4fetch";
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
// Initialize a singleton for aws usage.
|
||||||
|
let _aws: AwsClient | undefined;
|
||||||
|
function getAws(options: ConstructorParameters<typeof AwsClient>[0]) {
|
||||||
|
if (!_aws) {
|
||||||
|
_aws = new AwsClient(options);
|
||||||
|
}
|
||||||
|
return _aws;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Types
|
||||||
|
*/
|
||||||
|
const usageEventSchema = z.object({
|
||||||
|
source: z.enum([
|
||||||
|
"wallet",
|
||||||
|
"rpc",
|
||||||
|
"storage",
|
||||||
|
"bundler",
|
||||||
|
"paymaster",
|
||||||
|
"relayer",
|
||||||
|
]),
|
||||||
|
action: z.string(),
|
||||||
|
accountId: z.string(),
|
||||||
|
|
||||||
|
// Optional
|
||||||
|
apiKeyId: z.string().optional(),
|
||||||
|
creatorWalletAddress: z.string().optional(),
|
||||||
|
clientId: z.string().optional(),
|
||||||
|
walletAddress: z.string().optional(),
|
||||||
|
chainId: z.number().int().positive().optional(),
|
||||||
|
provider: z.string().optional(),
|
||||||
|
mimeType: z.string().optional(),
|
||||||
|
fileSize: z.number().int().nonnegative().optional(),
|
||||||
|
fileCid: z.string().optional(),
|
||||||
|
transactionHash: z.string().optional(),
|
||||||
|
gasLimit: z.number().nonnegative().optional(),
|
||||||
|
gasPricePerUnit: z.string().optional(),
|
||||||
|
});
|
||||||
|
export type UsageEvent = z.infer<typeof usageEventSchema>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Publish usage events. Provide the relevant fields for your application.
|
||||||
|
*
|
||||||
|
* Usage in Cloudflare Workers:
|
||||||
|
* ctx.waitUntil(
|
||||||
|
* publishUsageEvents(
|
||||||
|
* [event1, event2],
|
||||||
|
* { queueUrl, accessKeyId, secretAccessKey },
|
||||||
|
* )
|
||||||
|
* )
|
||||||
|
*
|
||||||
|
* @param usageEvents
|
||||||
|
* @param config
|
||||||
|
*/
|
||||||
|
export async function publishUsageEvents(
|
||||||
|
usageEvents: UsageEvent[],
|
||||||
|
config: {
|
||||||
|
queueUrl: string;
|
||||||
|
accessKeyId: string;
|
||||||
|
secretAccessKey: string;
|
||||||
|
region?: string;
|
||||||
|
},
|
||||||
|
): Promise<string> {
|
||||||
|
const {
|
||||||
|
queueUrl,
|
||||||
|
accessKeyId,
|
||||||
|
secretAccessKey,
|
||||||
|
region = "us-west-2",
|
||||||
|
} = config;
|
||||||
|
|
||||||
|
const entries = usageEvents.map((event) => ({
|
||||||
|
Id: crypto.randomUUID(),
|
||||||
|
MessageBody: JSON.stringify(event),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const aws = getAws({
|
||||||
|
accessKeyId,
|
||||||
|
secretAccessKey,
|
||||||
|
region,
|
||||||
|
});
|
||||||
|
const res = await aws.fetch(`https://sqs.${region}.amazonaws.com`, {
|
||||||
|
headers: {
|
||||||
|
"X-Amz-Target": "AmazonSQS.SendMessageBatch",
|
||||||
|
"X-Amz-Date": new Date().toISOString(),
|
||||||
|
"Content-Type": "application/x-amz-json-1.0",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
QueueUrl: queueUrl,
|
||||||
|
Entries: entries,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
return await res.text();
|
||||||
|
}
|
||||||
@@ -24,6 +24,12 @@ export type ApiKeyMetadata = {
|
|||||||
}[];
|
}[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type AccountMetadata = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
creatorWalletAddress: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type ApiResponse = {
|
export type ApiResponse = {
|
||||||
data: ApiKeyMetadata | null;
|
data: ApiKeyMetadata | null;
|
||||||
error: {
|
error: {
|
||||||
@@ -33,6 +39,15 @@ export type ApiResponse = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ApiAccountResponse = {
|
||||||
|
data: AccountMetadata | null;
|
||||||
|
error: {
|
||||||
|
code: string;
|
||||||
|
statusCode: number;
|
||||||
|
message: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export async function fetchKeyMetadataFromApi(
|
export async function fetchKeyMetadataFromApi(
|
||||||
clientId: string,
|
clientId: string,
|
||||||
config: CoreServiceConfig,
|
config: CoreServiceConfig,
|
||||||
@@ -53,3 +68,23 @@ export async function fetchKeyMetadataFromApi(
|
|||||||
}
|
}
|
||||||
return (await response.json()) as ApiResponse;
|
return (await response.json()) as ApiResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function fetchAccountFromApi(
|
||||||
|
jwt: string,
|
||||||
|
config: CoreServiceConfig,
|
||||||
|
): Promise<ApiAccountResponse> {
|
||||||
|
const { apiUrl, serviceApiKey } = config;
|
||||||
|
const url = `${apiUrl}/v1/account/me`;
|
||||||
|
const response = await fetch(url, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"x-service-api-key": serviceApiKey,
|
||||||
|
"content-type": "application/json",
|
||||||
|
authorization: `Bearer ${jwt}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Error fetching account from API: ${response.statusText}`);
|
||||||
|
}
|
||||||
|
return (await response.json()) as ApiAccountResponse;
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ describe("authorizeClient", () => {
|
|||||||
origin: null,
|
origin: null,
|
||||||
bundleId: null,
|
bundleId: null,
|
||||||
secretKeyHash: null,
|
secretKeyHash: null,
|
||||||
|
hashedJWT: null,
|
||||||
|
jwt: null,
|
||||||
},
|
},
|
||||||
validServiceConfig,
|
validServiceConfig,
|
||||||
)) as any;
|
)) as any;
|
||||||
@@ -33,6 +35,8 @@ describe("authorizeClient", () => {
|
|||||||
origin: null,
|
origin: null,
|
||||||
bundleId: null,
|
bundleId: null,
|
||||||
secretKeyHash: null,
|
secretKeyHash: null,
|
||||||
|
hashedJWT: null,
|
||||||
|
jwt: null,
|
||||||
},
|
},
|
||||||
{ ...validServiceConfig, enforceAuth: true },
|
{ ...validServiceConfig, enforceAuth: true },
|
||||||
)) as any;
|
)) as any;
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ describe("authorizeClient", () => {
|
|||||||
const validApiKeyMeta: ApiKeyMetadata = {
|
const validApiKeyMeta: ApiKeyMetadata = {
|
||||||
id: "1",
|
id: "1",
|
||||||
key: "your-api-key",
|
key: "your-api-key",
|
||||||
accountId: "account-id",
|
|
||||||
creatorWalletAddress: "creator-address",
|
creatorWalletAddress: "creator-address",
|
||||||
secretHash: "secret-hash",
|
secretHash: "secret-hash",
|
||||||
walletAddresses: [],
|
walletAddresses: [],
|
||||||
domains: ["example.com", "*.example.com"],
|
domains: ["example.com", "*.example.com"],
|
||||||
bundleIds: ["com.example.app"],
|
bundleIds: ["com.example.app"],
|
||||||
services: [],
|
services: [],
|
||||||
|
accountId: "test-account-id",
|
||||||
};
|
};
|
||||||
|
|
||||||
const validAuthOptions: ClientAuthorizationPayload = {
|
const validAuthOptions: ClientAuthorizationPayload = {
|
||||||
@@ -41,6 +41,26 @@ describe("authorizeClient", () => {
|
|||||||
expect(result.apiKeyMeta).toEqual(validApiKeyMeta);
|
expect(result.apiKeyMeta).toEqual(validApiKeyMeta);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should authorize client with any domain w/o origin check", () => {
|
||||||
|
const authOptionsWithAnyDomain: ClientAuthorizationPayload = {
|
||||||
|
secretKeyHash: null,
|
||||||
|
bundleId: null,
|
||||||
|
origin: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
const validApiKeyMetaAnyDomain = {
|
||||||
|
...validApiKeyMeta,
|
||||||
|
domains: ["*"],
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = authorizeClient(
|
||||||
|
authOptionsWithAnyDomain,
|
||||||
|
validApiKeyMetaAnyDomain,
|
||||||
|
) as any;
|
||||||
|
expect(result.authorized).toBe(true);
|
||||||
|
expect(result.apiKeyMeta).toEqual(validApiKeyMetaAnyDomain);
|
||||||
|
});
|
||||||
|
|
||||||
it("should not authorize client with non-matching bundle id", () => {
|
it("should not authorize client with non-matching bundle id", () => {
|
||||||
const authOptionsWithBundleId: ClientAuthorizationPayload = {
|
const authOptionsWithBundleId: ClientAuthorizationPayload = {
|
||||||
secretKeyHash: null,
|
secretKeyHash: null,
|
||||||
@@ -54,7 +74,7 @@ describe("authorizeClient", () => {
|
|||||||
) as any;
|
) as any;
|
||||||
expect(result.authorized).toBe(false);
|
expect(result.authorized).toBe(false);
|
||||||
expect(result.errorMessage).toBe(
|
expect(result.errorMessage).toBe(
|
||||||
"The bundleId: com.foo.bar, is not authorized for this key. Please update your key permissions on the thirdweb dashboard",
|
"Invalid request: Unauthorized Bundle ID: com.foo.bar. You can view the restrictions on this API key at https://thirdweb.com/create-api-key",
|
||||||
);
|
);
|
||||||
expect(result.errorCode).toBe("BUNDLE_UNAUTHORIZED");
|
expect(result.errorCode).toBe("BUNDLE_UNAUTHORIZED");
|
||||||
expect(result.status).toBe(401);
|
expect(result.status).toBe(401);
|
||||||
@@ -73,7 +93,7 @@ describe("authorizeClient", () => {
|
|||||||
) as any;
|
) as any;
|
||||||
expect(result.authorized).toBe(false);
|
expect(result.authorized).toBe(false);
|
||||||
expect(result.errorMessage).toBe(
|
expect(result.errorMessage).toBe(
|
||||||
"The secret is invalid. Please check you secret-key",
|
"Incorrect key provided. You can view your active API keys at https://thirdweb.com/dashboard/settings",
|
||||||
);
|
);
|
||||||
expect(result.errorCode).toBe("SECRET_INVALID");
|
expect(result.errorCode).toBe("SECRET_INVALID");
|
||||||
expect(result.status).toBe(401);
|
expect(result.status).toBe(401);
|
||||||
@@ -92,7 +112,7 @@ describe("authorizeClient", () => {
|
|||||||
) as any;
|
) as any;
|
||||||
expect(result.authorized).toBe(false);
|
expect(result.authorized).toBe(false);
|
||||||
expect(result.errorMessage).toBe(
|
expect(result.errorMessage).toBe(
|
||||||
"The domain: unauthorized.com, is not authorized for this key. Please update your key permissions on the thirdweb dashboard",
|
"Invalid request: Unauthorized domain: unauthorized.com. You can view the restrictions on this API key at https://thirdweb.com/create-api-key",
|
||||||
);
|
);
|
||||||
expect(result.errorCode).toBe("ORIGIN_UNAUTHORIZED");
|
expect(result.errorCode).toBe("ORIGIN_UNAUTHORIZED");
|
||||||
expect(result.status).toBe(401);
|
expect(result.status).toBe(401);
|
||||||
|
|||||||
@@ -14,28 +14,35 @@ export function authorizeClient(
|
|||||||
const { origin, bundleId, secretKeyHash: providedSecretHash } = authOptions;
|
const { origin, bundleId, secretKeyHash: providedSecretHash } = authOptions;
|
||||||
const { domains, bundleIds, secretHash } = apiKeyMeta;
|
const { domains, bundleIds, secretHash } = apiKeyMeta;
|
||||||
|
|
||||||
|
const authResult: AuthorizationResult = {
|
||||||
|
authorized: true,
|
||||||
|
apiKeyMeta,
|
||||||
|
accountMeta: {
|
||||||
|
id: apiKeyMeta.accountId,
|
||||||
|
// TODO update this later
|
||||||
|
name: "",
|
||||||
|
creatorWalletAddress: apiKeyMeta.creatorWalletAddress,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// check for public restrictions
|
||||||
|
if (domains.includes("*")) {
|
||||||
|
return authResult;
|
||||||
|
}
|
||||||
|
|
||||||
// check for secretHash
|
// check for secretHash
|
||||||
if (providedSecretHash) {
|
if (providedSecretHash) {
|
||||||
if (secretHash !== providedSecretHash) {
|
if (secretHash !== providedSecretHash) {
|
||||||
return {
|
return {
|
||||||
authorized: false,
|
authorized: false,
|
||||||
errorMessage: "The secret is invalid. Please check you secret-key",
|
errorMessage:
|
||||||
|
"Incorrect key provided. You can view your active API keys at https://thirdweb.com/dashboard/settings",
|
||||||
errorCode: "SECRET_INVALID",
|
errorCode: "SECRET_INVALID",
|
||||||
status: 401,
|
status: 401,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {
|
|
||||||
authorized: true,
|
|
||||||
apiKeyMeta,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// check for public restrictions
|
return authResult;
|
||||||
if (domains.includes("*")) {
|
|
||||||
return {
|
|
||||||
authorized: true,
|
|
||||||
apiKeyMeta,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate domains
|
// validate domains
|
||||||
@@ -43,14 +50,22 @@ export function authorizeClient(
|
|||||||
if (
|
if (
|
||||||
// find matching domain, or if all domains allowed
|
// find matching domain, or if all domains allowed
|
||||||
domains.find((d) => {
|
domains.find((d) => {
|
||||||
|
// if any domain is allowed, we'll return true
|
||||||
if (d === "*") {
|
if (d === "*") {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// special rule for `localhost`
|
||||||
|
// if the domain is localhost, we'll allow any origin that starts with localhost
|
||||||
|
if (d === "localhost" && origin.startsWith("localhost")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// If the allowedDomain has a wildcard,
|
// If the allowedDomain has a wildcard,
|
||||||
// we'll check that the ending of our domain matches the wildcard
|
// we'll check that the ending of our domain matches the wildcard
|
||||||
if (d.startsWith("*.")) {
|
if (d.startsWith("*.")) {
|
||||||
const domainRoot = d.slice(2);
|
// get rid of the * and check if it ends with the `.<domain>.<tld>`
|
||||||
|
const domainRoot = d.slice(1);
|
||||||
return origin.endsWith(domainRoot);
|
return origin.endsWith(domainRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,15 +73,12 @@ export function authorizeClient(
|
|||||||
return d === origin;
|
return d === origin;
|
||||||
})
|
})
|
||||||
) {
|
) {
|
||||||
return {
|
return authResult;
|
||||||
authorized: true,
|
|
||||||
apiKeyMeta,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
authorized: false,
|
authorized: false,
|
||||||
errorMessage: `The domain: ${origin}, is not authorized for this key. Please update your key permissions on the thirdweb dashboard`,
|
errorMessage: `Invalid request: Unauthorized domain: ${origin}. You can view the restrictions on this API key at https://thirdweb.com/create-api-key`,
|
||||||
errorCode: "ORIGIN_UNAUTHORIZED",
|
errorCode: "ORIGIN_UNAUTHORIZED",
|
||||||
status: 401,
|
status: 401,
|
||||||
};
|
};
|
||||||
@@ -84,15 +96,12 @@ export function authorizeClient(
|
|||||||
return b === bundleId;
|
return b === bundleId;
|
||||||
})
|
})
|
||||||
) {
|
) {
|
||||||
return {
|
return authResult;
|
||||||
authorized: true,
|
|
||||||
apiKeyMeta,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
authorized: false,
|
authorized: false,
|
||||||
errorMessage: `The bundleId: ${bundleId}, is not authorized for this key. Please update your key permissions on the thirdweb dashboard`,
|
errorMessage: `Invalid request: Unauthorized Bundle ID: ${bundleId}. You can view the restrictions on this API key at https://thirdweb.com/create-api-key`,
|
||||||
errorCode: "BUNDLE_UNAUTHORIZED",
|
errorCode: "BUNDLE_UNAUTHORIZED",
|
||||||
status: 401,
|
status: 401,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import {
|
import {
|
||||||
|
AccountMetadata,
|
||||||
ApiKeyMetadata,
|
ApiKeyMetadata,
|
||||||
CoreServiceConfig,
|
CoreServiceConfig,
|
||||||
|
fetchAccountFromApi,
|
||||||
fetchKeyMetadataFromApi,
|
fetchKeyMetadataFromApi,
|
||||||
} from "../api";
|
} from "../api";
|
||||||
import { authorizeClient } from "./client";
|
import { authorizeClient } from "./client";
|
||||||
@@ -13,36 +15,124 @@ export type AuthorizationInput = {
|
|||||||
origin: string | null;
|
origin: string | null;
|
||||||
bundleId: string | null;
|
bundleId: string | null;
|
||||||
secretKeyHash: string | null;
|
secretKeyHash: string | null;
|
||||||
|
jwt: string | null;
|
||||||
|
hashedJWT: string | null;
|
||||||
targetAddress?: string | string[];
|
targetAddress?: string | string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
type CacheOptions = {
|
type CacheOptions = {
|
||||||
get: (clientId: string) => Promise<string | null>;
|
get: (clientId: string) => Promise<string | null>;
|
||||||
put: (clientId: string, data: ApiKeyMetadata) => Promise<void> | void;
|
put: (
|
||||||
|
clientId: string,
|
||||||
|
data: ApiKeyMetadata | AccountMetadata,
|
||||||
|
) => Promise<void> | void;
|
||||||
cacheTtlSeconds: number;
|
cacheTtlSeconds: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
type CacheWithPossibleTtl =
|
type ApiKeyCacheWithPossibleTTL =
|
||||||
| {
|
| {
|
||||||
apiKeyMeta: ApiKeyMetadata;
|
apiKeyMeta: ApiKeyMetadata;
|
||||||
updatedAt: number;
|
updatedAt: number;
|
||||||
}
|
}
|
||||||
| ApiKeyMetadata;
|
| ApiKeyMetadata;
|
||||||
|
|
||||||
|
type AccountCacheWithPossibleTTL =
|
||||||
|
| {
|
||||||
|
apiKeyMeta: AccountMetadata;
|
||||||
|
updatedAt: number;
|
||||||
|
}
|
||||||
|
| AccountMetadata;
|
||||||
|
|
||||||
export async function authorize(
|
export async function authorize(
|
||||||
authData: AuthorizationInput,
|
authData: AuthorizationInput,
|
||||||
serviceConfig: CoreServiceConfig,
|
serviceConfig: CoreServiceConfig,
|
||||||
cacheOptions?: CacheOptions,
|
cacheOptions?: CacheOptions,
|
||||||
): Promise<AuthorizationResult> {
|
): Promise<AuthorizationResult> {
|
||||||
const { clientId, targetAddress, secretKeyHash } = authData;
|
const { clientId, targetAddress, secretKeyHash, jwt, hashedJWT } = authData;
|
||||||
const { enforceAuth } = serviceConfig;
|
const { enforceAuth } = serviceConfig;
|
||||||
|
|
||||||
// BACKWARDS COMPAT: if auth not enforced and
|
// BACKWARDS COMPAT: if auth not enforced and we don't have auth credentials bypass
|
||||||
// we don't have auth credentials bypass
|
|
||||||
if (!enforceAuth && !clientId && !secretKeyHash) {
|
if (!enforceAuth && !clientId && !secretKeyHash) {
|
||||||
return {
|
return {
|
||||||
authorized: true,
|
authorized: true,
|
||||||
apiKeyMeta: null,
|
apiKeyMeta: null,
|
||||||
|
accountMeta: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// if we come in with a JWT then we only check the account is valid
|
||||||
|
if (jwt && hashedJWT) {
|
||||||
|
let accountMeta: AccountMetadata | null = null;
|
||||||
|
if (cacheOptions) {
|
||||||
|
try {
|
||||||
|
const cachedAccountInfo = await cacheOptions.get(hashedJWT);
|
||||||
|
if (cachedAccountInfo) {
|
||||||
|
const parsed = JSON.parse(
|
||||||
|
cachedAccountInfo,
|
||||||
|
) as AccountCacheWithPossibleTTL;
|
||||||
|
if ("updatedAt" in parsed) {
|
||||||
|
// we want to compare the updatedAt time to the current time
|
||||||
|
// if the difference is greater than the cacheTtl we want to ignore the cached data
|
||||||
|
const now = Date.now();
|
||||||
|
const diff = now - parsed.updatedAt;
|
||||||
|
const cacheTtl = cacheOptions.cacheTtlSeconds * 1000;
|
||||||
|
// only if the diff is less than the cacheTtl do we want to use the cached key
|
||||||
|
if (diff < cacheTtl * 1000) {
|
||||||
|
accountMeta = parsed.apiKeyMeta;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
accountMeta = parsed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
// ignore errors, proceed as if not in cache
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!accountMeta) {
|
||||||
|
try {
|
||||||
|
const { data, error } = await fetchAccountFromApi(jwt, serviceConfig);
|
||||||
|
if (error) {
|
||||||
|
return {
|
||||||
|
authorized: false,
|
||||||
|
errorCode: error.code,
|
||||||
|
errorMessage: error.message,
|
||||||
|
status: error.statusCode,
|
||||||
|
};
|
||||||
|
} else if (!data) {
|
||||||
|
return {
|
||||||
|
authorized: false,
|
||||||
|
errorCode: "NO_ACCOUNT",
|
||||||
|
errorMessage: "No error but also no account returned.",
|
||||||
|
status: 500,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
accountMeta = data;
|
||||||
|
if (cacheOptions) {
|
||||||
|
await cacheOptions.put(hashedJWT, accountMeta);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.warn("failed to fetch account from api", err);
|
||||||
|
return {
|
||||||
|
authorized: false,
|
||||||
|
status: 500,
|
||||||
|
errorMessage: "Failed to account information.",
|
||||||
|
errorCode: "FAILED_TO_ACCOUNT",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if we still don't have an accountMeta at this point we can't authorize
|
||||||
|
if (!accountMeta) {
|
||||||
|
return {
|
||||||
|
authorized: false,
|
||||||
|
status: 401,
|
||||||
|
errorMessage: "Missing account information.",
|
||||||
|
errorCode: "MISSING_ACCOUNT",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// otherwise we want to return early with the accountMeta
|
||||||
|
return {
|
||||||
|
authorized: true,
|
||||||
|
apiKeyMeta: null,
|
||||||
|
accountMeta,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +152,7 @@ export async function authorize(
|
|||||||
try {
|
try {
|
||||||
const cachedKey = await cacheOptions.get(clientId);
|
const cachedKey = await cacheOptions.get(clientId);
|
||||||
if (cachedKey) {
|
if (cachedKey) {
|
||||||
const parsed = JSON.parse(cachedKey) as CacheWithPossibleTtl;
|
const parsed = JSON.parse(cachedKey) as ApiKeyCacheWithPossibleTTL;
|
||||||
if ("updatedAt" in parsed) {
|
if ("updatedAt" in parsed) {
|
||||||
// we want to compare the updatedAt time to the current time
|
// we want to compare the updatedAt time to the current time
|
||||||
// if the difference is greater than the cacheTtl we want to ignore the cached data
|
// if the difference is greater than the cacheTtl we want to ignore the cached data
|
||||||
@@ -161,5 +251,11 @@ export async function authorize(
|
|||||||
return {
|
return {
|
||||||
authorized: true,
|
authorized: true,
|
||||||
apiKeyMeta,
|
apiKeyMeta,
|
||||||
|
accountMeta: {
|
||||||
|
id: apiKeyMeta.accountId,
|
||||||
|
// TODO update this later
|
||||||
|
name: "",
|
||||||
|
creatorWalletAddress: apiKeyMeta.creatorWalletAddress,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ describe("authorizeService", () => {
|
|||||||
const validApiKeyMeta: ApiKeyMetadata = {
|
const validApiKeyMeta: ApiKeyMetadata = {
|
||||||
id: "1",
|
id: "1",
|
||||||
key: "your-api-key",
|
key: "your-api-key",
|
||||||
accountId: "account-id",
|
|
||||||
creatorWalletAddress: "creator-address",
|
creatorWalletAddress: "creator-address",
|
||||||
secretHash: "secret-hash",
|
secretHash: "secret-hash",
|
||||||
walletAddresses: [],
|
walletAddresses: [],
|
||||||
domains: [],
|
domains: [],
|
||||||
bundleIds: [],
|
bundleIds: [],
|
||||||
|
accountId: "test-account-id",
|
||||||
services: [
|
services: [
|
||||||
{
|
{
|
||||||
name: "storage",
|
name: "storage",
|
||||||
@@ -80,7 +80,7 @@ describe("authorizeService", () => {
|
|||||||
) as any;
|
) as any;
|
||||||
expect(result.authorized).toBe(false);
|
expect(result.authorized).toBe(false);
|
||||||
expect(result.errorMessage).toBe(
|
expect(result.errorMessage).toBe(
|
||||||
'The service "rpc" is not authorized for this key. Please update your key permissions on the thirdweb dashboard.',
|
"Invalid request: Unauthorized service: rpc. You can view the restrictions on this API key in your dashboard: https://thirdweb.com/create-api-key",
|
||||||
);
|
);
|
||||||
expect(result.errorCode).toBe("SERVICE_UNAUTHORIZED");
|
expect(result.errorCode).toBe("SERVICE_UNAUTHORIZED");
|
||||||
expect(result.status).toBe(403);
|
expect(result.status).toBe(403);
|
||||||
@@ -101,7 +101,7 @@ describe("authorizeService", () => {
|
|||||||
) as any;
|
) as any;
|
||||||
expect(result.authorized).toBe(false);
|
expect(result.authorized).toBe(false);
|
||||||
expect(result.errorMessage).toBe(
|
expect(result.errorMessage).toBe(
|
||||||
'The service "storage" action "unauthorized-action" is not authorized for this key. Please update your key permissions on the thirdweb dashboard.',
|
"Invalid request: Unauthorized action: storage unauthorized-action. You can view the restrictions on this API key in your dashboard: https://thirdweb.com/create-api-key",
|
||||||
);
|
);
|
||||||
expect(result.errorCode).toBe("SERVICE_ACTION_UNAUTHORIZED");
|
expect(result.errorCode).toBe("SERVICE_ACTION_UNAUTHORIZED");
|
||||||
expect(result.status).toBe(403);
|
expect(result.status).toBe(403);
|
||||||
@@ -119,7 +119,7 @@ describe("authorizeService", () => {
|
|||||||
) as any;
|
) as any;
|
||||||
expect(result.authorized).toBe(false);
|
expect(result.authorized).toBe(false);
|
||||||
expect(result.errorMessage).toBe(
|
expect(result.errorMessage).toBe(
|
||||||
'The target address: unauthorized-target, for service "storage" is not authorized for this key. Please update your key permissions on the thirdweb dashboard.',
|
"Invalid request: Unauthorized address: storage unauthorized-target. You can view the restrictions on this API key in your dashboard: https://thirdweb.com/create-api-key",
|
||||||
);
|
);
|
||||||
expect(result.errorCode).toBe("SERVICE_TARGET_ADDRESS_UNAUTHORIZED");
|
expect(result.errorCode).toBe("SERVICE_TARGET_ADDRESS_UNAUTHORIZED");
|
||||||
expect(result.status).toBe(403);
|
expect(result.status).toBe(403);
|
||||||
@@ -137,7 +137,7 @@ describe("authorizeService", () => {
|
|||||||
) as any;
|
) as any;
|
||||||
expect(result.authorized).toBe(false);
|
expect(result.authorized).toBe(false);
|
||||||
expect(result.errorMessage).toBe(
|
expect(result.errorMessage).toBe(
|
||||||
'The target address: target1,target2,target3, for service "storage" is not authorized for this key. Please update your key permissions on the thirdweb dashboard.',
|
"Invalid request: Unauthorized address: storage target1,target2,target3. You can view the restrictions on this API key in your dashboard: https://thirdweb.com/create-api-key",
|
||||||
);
|
);
|
||||||
expect(result.errorCode).toBe("SERVICE_TARGET_ADDRESS_UNAUTHORIZED");
|
expect(result.errorCode).toBe("SERVICE_TARGET_ADDRESS_UNAUTHORIZED");
|
||||||
expect(result.status).toBe(403);
|
expect(result.status).toBe(403);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export function authorizeService(
|
|||||||
if (!service) {
|
if (!service) {
|
||||||
return {
|
return {
|
||||||
authorized: false,
|
authorized: false,
|
||||||
errorMessage: `The service "${serviceConfig.serviceScope}" is not authorized for this key. Please update your key permissions on the thirdweb dashboard.`,
|
errorMessage: `Invalid request: Unauthorized service: ${serviceConfig.serviceScope}. You can view the restrictions on this API key in your dashboard: https://thirdweb.com/create-api-key`,
|
||||||
errorCode: "SERVICE_UNAUTHORIZED",
|
errorCode: "SERVICE_UNAUTHORIZED",
|
||||||
status: 403,
|
status: 403,
|
||||||
};
|
};
|
||||||
@@ -30,7 +30,7 @@ export function authorizeService(
|
|||||||
if (!isActionAllowed) {
|
if (!isActionAllowed) {
|
||||||
return {
|
return {
|
||||||
authorized: false,
|
authorized: false,
|
||||||
errorMessage: `The service "${serviceConfig.serviceScope}" action "${serviceConfig.serviceAction}" is not authorized for this key. Please update your key permissions on the thirdweb dashboard.`,
|
errorMessage: `Invalid request: Unauthorized action: ${serviceConfig.serviceScope} ${serviceConfig.serviceAction}. You can view the restrictions on this API key in your dashboard: https://thirdweb.com/create-api-key`,
|
||||||
errorCode: "SERVICE_ACTION_UNAUTHORIZED",
|
errorCode: "SERVICE_ACTION_UNAUTHORIZED",
|
||||||
status: 403,
|
status: 403,
|
||||||
};
|
};
|
||||||
@@ -52,7 +52,7 @@ export function authorizeService(
|
|||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
authorized: false,
|
authorized: false,
|
||||||
errorMessage: `The target address: ${checkedAddresses}, for service "${serviceConfig.serviceScope}" is not authorized for this key. Please update your key permissions on the thirdweb dashboard.`,
|
errorMessage: `Invalid request: Unauthorized address: ${serviceConfig.serviceScope} ${checkedAddresses}. You can view the restrictions on this API key in your dashboard: https://thirdweb.com/create-api-key`,
|
||||||
errorCode: "SERVICE_TARGET_ADDRESS_UNAUTHORIZED",
|
errorCode: "SERVICE_TARGET_ADDRESS_UNAUTHORIZED",
|
||||||
status: 403,
|
status: 403,
|
||||||
};
|
};
|
||||||
@@ -61,6 +61,11 @@ export function authorizeService(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
authorized: true,
|
authorized: true,
|
||||||
|
accountMeta: {
|
||||||
|
id: apiKeyMetadata.accountId,
|
||||||
|
name: "",
|
||||||
|
creatorWalletAddress: apiKeyMetadata.creatorWalletAddress,
|
||||||
|
},
|
||||||
apiKeyMeta: apiKeyMetadata,
|
apiKeyMeta: apiKeyMetadata,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { ApiKeyMetadata } from "../api";
|
import { AccountMetadata, ApiKeyMetadata } from "../api";
|
||||||
|
|
||||||
export type AuthorizationResult =
|
export type AuthorizationResult =
|
||||||
| {
|
| {
|
||||||
authorized: true;
|
authorized: true;
|
||||||
apiKeyMeta: ApiKeyMetadata | null;
|
apiKeyMeta: ApiKeyMetadata | null;
|
||||||
|
accountMeta: AccountMetadata | null;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
authorized: false;
|
authorized: false;
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
// only exports the public service definitions
|
// Exports the public service definitions.
|
||||||
export * from "./core/services";
|
export * from "./core/services";
|
||||||
|
|||||||
@@ -118,7 +118,19 @@ export function extractAuthorizationData(
|
|||||||
clientId = derivedClientId;
|
clientId = derivedClientId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let jwt: null | string = null;
|
||||||
|
// check for authorization header on the request
|
||||||
|
const authorizationHeader = getHeader(headers, "authorization");
|
||||||
|
if (authorizationHeader) {
|
||||||
|
const [type, token] = authorizationHeader.split(" ");
|
||||||
|
if (type.toLowerCase() === "bearer") {
|
||||||
|
jwt = token;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
jwt,
|
||||||
|
hashedJWT: jwt ? hashSecretKey(jwt) : null,
|
||||||
secretKeyHash,
|
secretKeyHash,
|
||||||
secretKey,
|
secretKey,
|
||||||
clientId,
|
clientId,
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
# @thirdweb-dev/storage
|
# @thirdweb-dev/storage
|
||||||
|
|
||||||
|
## 1.2.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#1411](https://github.com/thirdweb-dev/js/pull/1411) [`3b6b0746`](https://github.com/thirdweb-dev/js/commit/3b6b0746b3fc792f4c5092814a7abfabcbc9801e) Thanks [@jnsdls](https://github.com/jnsdls)! - add auth token
|
||||||
|
|
||||||
## 1.2.2
|
## 1.2.2
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/storage",
|
"name": "@thirdweb-dev/storage",
|
||||||
"version": "1.2.2",
|
"version": "1.2.3",
|
||||||
"main": "dist/thirdweb-dev-storage.cjs.js",
|
"main": "dist/thirdweb-dev-storage.cjs.js",
|
||||||
"module": "dist/thirdweb-dev-storage.esm.js",
|
"module": "dist/thirdweb-dev-storage.esm.js",
|
||||||
"browser": {
|
"browser": {
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ export class StorageDownloader implements IStorageDownloader {
|
|||||||
console.warn(`Retrying download with backup gateway URL: ${resolvedUri}`);
|
console.warn(`Retrying download with backup gateway URL: ${resolvedUri}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let headers;
|
let headers: HeadersInit = {};
|
||||||
if (isTwGatewayUrl(resolvedUri)) {
|
if (isTwGatewayUrl(resolvedUri)) {
|
||||||
if (this.secretKey) {
|
if (this.secretKey) {
|
||||||
headers = { "x-secret-key": this.secretKey };
|
headers = { "x-secret-key": this.secretKey };
|
||||||
@@ -87,6 +87,15 @@ export class StorageDownloader implements IStorageDownloader {
|
|||||||
"x-client-Id": this.clientId,
|
"x-client-Id": this.clientId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
// if we have a authorization token on global context then add that to the headers
|
||||||
|
if (typeof globalThis !== "undefined" && "TW_AUTH_TOKEN" in globalThis) {
|
||||||
|
headers = {
|
||||||
|
...headers,
|
||||||
|
authorization: `Bearer ${
|
||||||
|
(globalThis as any).TW_AUTH_TOKEN as string
|
||||||
|
}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isTooManyRequests(resolvedUri)) {
|
if (isTooManyRequests(resolvedUri)) {
|
||||||
|
|||||||
@@ -270,18 +270,27 @@ export class IpfsUploader implements IStorageUploader<IpfsUploadBatchOptions> {
|
|||||||
|
|
||||||
xhr.open("POST", `${TW_UPLOAD_SERVER_URL}/ipfs/upload`);
|
xhr.open("POST", `${TW_UPLOAD_SERVER_URL}/ipfs/upload`);
|
||||||
|
|
||||||
if (this.secretKey && this.clientId) {
|
|
||||||
throw new Error(
|
|
||||||
"Cannot use both secret key and client ID. Please use secretKey for server-side applications and clientId for client-side applications.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.secretKey) {
|
if (this.secretKey) {
|
||||||
xhr.setRequestHeader("x-secret-key", this.secretKey);
|
xhr.setRequestHeader("x-secret-key", this.secretKey);
|
||||||
} else if (this.clientId) {
|
} else if (this.clientId) {
|
||||||
xhr.setRequestHeader("x-client-id", this.clientId);
|
xhr.setRequestHeader("x-client-id", this.clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof globalThis !== "undefined" && "APP_BUNDLE_ID" in globalThis) {
|
||||||
|
xhr.setRequestHeader(
|
||||||
|
"x-bundle-id",
|
||||||
|
(globalThis as any).APP_BUNDLE_ID as string,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if we have a authorization token on global context then add that to the headers
|
||||||
|
if (typeof globalThis !== "undefined" && "TW_AUTH_TOKEN" in globalThis) {
|
||||||
|
xhr.setRequestHeader(
|
||||||
|
"authorization",
|
||||||
|
`Bearer ${(globalThis as any).TW_AUTH_TOKEN as string}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
xhr.send(form as any);
|
xhr.send(form as any);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -295,12 +304,6 @@ export class IpfsUploader implements IStorageUploader<IpfsUploadBatchOptions> {
|
|||||||
console.warn("The onProgress option is only supported in the browser");
|
console.warn("The onProgress option is only supported in the browser");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.secretKey && this.clientId) {
|
|
||||||
throw new Error(
|
|
||||||
"Cannot use both secret key and client ID. Please use secretKey for server-side applications and clientId for client-side applications.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const headers: HeadersInit = {};
|
const headers: HeadersInit = {};
|
||||||
if (this.secretKey) {
|
if (this.secretKey) {
|
||||||
headers["x-secret-key"] = this.secretKey;
|
headers["x-secret-key"] = this.secretKey;
|
||||||
@@ -308,6 +311,18 @@ export class IpfsUploader implements IStorageUploader<IpfsUploadBatchOptions> {
|
|||||||
headers["x-client-id"] = this.clientId;
|
headers["x-client-id"] = this.clientId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if we have a bundle id on global context then add that to the headers
|
||||||
|
if (typeof globalThis !== "undefined" && "APP_BUNDLE_ID" in globalThis) {
|
||||||
|
headers["x-bundle-id"] = (globalThis as any).APP_BUNDLE_ID as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if we have a authorization token on global context then add that to the headers
|
||||||
|
if (typeof globalThis !== "undefined" && "TW_AUTH_TOKEN" in globalThis) {
|
||||||
|
headers["authorization"] = `Bearer ${
|
||||||
|
(globalThis as any).TW_AUTH_TOKEN as string
|
||||||
|
}`;
|
||||||
|
}
|
||||||
|
|
||||||
const res = await fetch(`${TW_UPLOAD_SERVER_URL}/ipfs/upload`, {
|
const res = await fetch(`${TW_UPLOAD_SERVER_URL}/ipfs/upload`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -1,5 +1,25 @@
|
|||||||
# @thirdweb-dev/unity-js-bridge
|
# @thirdweb-dev/unity-js-bridge
|
||||||
|
|
||||||
|
## 0.2.62
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`a5d0be93`](https://github.com/thirdweb-dev/js/commit/a5d0be939a143095e769b68cf86360bfe4720744), [`c0a6d2f1`](https://github.com/thirdweb-dev/js/commit/c0a6d2f18231310d143c9b0cb1b2ff59315087a4), [`a9f2ff73`](https://github.com/thirdweb-dev/js/commit/a9f2ff73c9f83f05c3e2d3c53b23b2843e8a2576), [`fd981655`](https://github.com/thirdweb-dev/js/commit/fd9816556fe595b0c764e34dbcf15b0ad1677edb), [`becbb637`](https://github.com/thirdweb-dev/js/commit/becbb637367285ed3d8d7d131e1020bf23e38298), [`fd981655`](https://github.com/thirdweb-dev/js/commit/fd9816556fe595b0c764e34dbcf15b0ad1677edb), [`c9bf4f05`](https://github.com/thirdweb-dev/js/commit/c9bf4f05c161707c6eb799ecef82f462e4a82405), [`67b145b9`](https://github.com/thirdweb-dev/js/commit/67b145b94dafb2fb1d90553ed4829f0ed22e2907), [`5ee700e8`](https://github.com/thirdweb-dev/js/commit/5ee700e80438650fa253c25c0bee6658ce68d2cf), [`9f5adc5c`](https://github.com/thirdweb-dev/js/commit/9f5adc5c5c2782ffb878759df481e5fb1e1740e5)]:
|
||||||
|
- @thirdweb-dev/sdk@3.10.44
|
||||||
|
- @thirdweb-dev/wallets@1.1.8
|
||||||
|
- @thirdweb-dev/chains@0.1.41
|
||||||
|
- @thirdweb-dev/auth@3.2.25
|
||||||
|
|
||||||
|
## 0.2.61
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`3b6b0746`](https://github.com/thirdweb-dev/js/commit/3b6b0746b3fc792f4c5092814a7abfabcbc9801e), [`b0ec1d80`](https://github.com/thirdweb-dev/js/commit/b0ec1d80839efccad11b50afbf2216c2c132cf7e)]:
|
||||||
|
- @thirdweb-dev/storage@1.2.3
|
||||||
|
- @thirdweb-dev/wallets@1.1.7
|
||||||
|
- @thirdweb-dev/sdk@3.10.43
|
||||||
|
- @thirdweb-dev/auth@3.2.24
|
||||||
|
|
||||||
## 0.2.60
|
## 0.2.60
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/unity-js-bridge",
|
"name": "@thirdweb-dev/unity-js-bridge",
|
||||||
"version": "0.2.60",
|
"version": "0.2.62",
|
||||||
"main": "dist/thirdweb-unity-bridge.js",
|
"main": "dist/thirdweb-unity-bridge.js",
|
||||||
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/unity-js-bridge",
|
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/unity-js-bridge",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
["@babel/preset-env", { "targets": "defaults, not ie 11" }]
|
["@babel/preset-env", { "targets": "defaults, not ie 11" }]
|
||||||
],
|
],
|
||||||
"plugins": [
|
"plugins": [
|
||||||
|
"@babel/plugin-transform-flow-strip-types",
|
||||||
"@babel/plugin-transform-private-methods",
|
"@babel/plugin-transform-private-methods",
|
||||||
"@babel/plugin-proposal-class-properties"
|
"@babel/plugin-proposal-class-properties"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,5 +1,29 @@
|
|||||||
# @thirdweb-dev/wallets
|
# @thirdweb-dev/wallets
|
||||||
|
|
||||||
|
## 1.1.8
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#1430](https://github.com/thirdweb-dev/js/pull/1430) [`a9f2ff73`](https://github.com/thirdweb-dev/js/commit/a9f2ff73c9f83f05c3e2d3c53b23b2843e8a2576) Thanks [@MananTank](https://github.com/MananTank)! - Handle error on Metamask Disconnect properly
|
||||||
|
|
||||||
|
- [#1436](https://github.com/thirdweb-dev/js/pull/1436) [`fd981655`](https://github.com/thirdweb-dev/js/commit/fd9816556fe595b0c764e34dbcf15b0ad1677edb) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Better gas estimations pre account deploy
|
||||||
|
|
||||||
|
- Updated dependencies [[`a5d0be93`](https://github.com/thirdweb-dev/js/commit/a5d0be939a143095e769b68cf86360bfe4720744), [`c0a6d2f1`](https://github.com/thirdweb-dev/js/commit/c0a6d2f18231310d143c9b0cb1b2ff59315087a4), [`becbb637`](https://github.com/thirdweb-dev/js/commit/becbb637367285ed3d8d7d131e1020bf23e38298), [`fd981655`](https://github.com/thirdweb-dev/js/commit/fd9816556fe595b0c764e34dbcf15b0ad1677edb), [`c9bf4f05`](https://github.com/thirdweb-dev/js/commit/c9bf4f05c161707c6eb799ecef82f462e4a82405), [`67b145b9`](https://github.com/thirdweb-dev/js/commit/67b145b94dafb2fb1d90553ed4829f0ed22e2907), [`5ee700e8`](https://github.com/thirdweb-dev/js/commit/5ee700e80438650fa253c25c0bee6658ce68d2cf), [`9f5adc5c`](https://github.com/thirdweb-dev/js/commit/9f5adc5c5c2782ffb878759df481e5fb1e1740e5), [`9f5adc5c`](https://github.com/thirdweb-dev/js/commit/9f5adc5c5c2782ffb878759df481e5fb1e1740e5)]:
|
||||||
|
- @thirdweb-dev/sdk@3.10.44
|
||||||
|
- @thirdweb-dev/chains@0.1.41
|
||||||
|
- @thirdweb-dev/contracts-js@1.3.11
|
||||||
|
|
||||||
|
## 1.1.7
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#1411](https://github.com/thirdweb-dev/js/pull/1411) [`3b6b0746`](https://github.com/thirdweb-dev/js/commit/3b6b0746b3fc792f4c5092814a7abfabcbc9801e) Thanks [@jnsdls](https://github.com/jnsdls)! - add auth token
|
||||||
|
|
||||||
|
- [#1425](https://github.com/thirdweb-dev/js/pull/1425) [`b0ec1d80`](https://github.com/thirdweb-dev/js/commit/b0ec1d80839efccad11b50afbf2216c2c132cf7e) Thanks [@iketw](https://github.com/iketw)! - Adding plugin-transform-flow-strip-types plugin to solve issues with RN FlatList
|
||||||
|
|
||||||
|
- Updated dependencies [[`3b6b0746`](https://github.com/thirdweb-dev/js/commit/3b6b0746b3fc792f4c5092814a7abfabcbc9801e)]:
|
||||||
|
- @thirdweb-dev/sdk@3.10.43
|
||||||
|
|
||||||
## 1.1.6
|
## 1.1.6
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/wallets",
|
"name": "@thirdweb-dev/wallets",
|
||||||
"version": "1.1.6",
|
"version": "1.1.8",
|
||||||
"main": "dist/thirdweb-dev-wallets.cjs.js",
|
"main": "dist/thirdweb-dev-wallets.cjs.js",
|
||||||
"module": "dist/thirdweb-dev-wallets.esm.js",
|
"module": "dist/thirdweb-dev-wallets.esm.js",
|
||||||
"types": "dist/thirdweb-dev-wallets.cjs.d.ts",
|
"types": "dist/thirdweb-dev-wallets.cjs.d.ts",
|
||||||
@@ -396,6 +396,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@aws-sdk/client-secrets-manager": "^3.378.0",
|
"@aws-sdk/client-secrets-manager": "^3.378.0",
|
||||||
|
"@babel/plugin-transform-flow-strip-types": "^7.22.5",
|
||||||
"@babel/plugin-transform-private-methods": "7.22.5",
|
"@babel/plugin-transform-private-methods": "7.22.5",
|
||||||
"@babel/plugin-proposal-class-properties": "7.18.6",
|
"@babel/plugin-proposal-class-properties": "7.18.6",
|
||||||
"@noble/ed25519": "^1.7.1",
|
"@noble/ed25519": "^1.7.1",
|
||||||
|
|||||||
@@ -417,9 +417,13 @@ export class InjectedConnector extends WagmiConnector<
|
|||||||
if ((error as ProviderRpcError).code === 1013) {
|
if ((error as ProviderRpcError).code === 1013) {
|
||||||
const provider = await this.getProvider();
|
const provider = await this.getProvider();
|
||||||
if (provider) {
|
if (provider) {
|
||||||
const isAuthorized = await this.getAccount();
|
try {
|
||||||
if (isAuthorized) {
|
const isAuthorized = await this.getAccount();
|
||||||
return;
|
if (isAuthorized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// If we can't get the account anymore, continue with disconnect
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -206,9 +206,16 @@ export abstract class BaseAccountAPI {
|
|||||||
let callGasLimit;
|
let callGasLimit;
|
||||||
const isPhantom = await this.checkAccountPhantom();
|
const isPhantom = await this.checkAccountPhantom();
|
||||||
if (isPhantom) {
|
if (isPhantom) {
|
||||||
// when the account is not deployed yet, the estimation will return something like 25k gas (revert cost)
|
// when the account is not deployed yet, we simulate the call to the target contract directly
|
||||||
// there's no way to know the actual cost, so we just use a fixed value of 500k which should cover most txcosts.
|
callGasLimit = await this.provider.estimateGas({
|
||||||
callGasLimit = BigNumber.from(500_000);
|
from: this.getAccountAddress(),
|
||||||
|
to: detailsForUserOp.target,
|
||||||
|
data: detailsForUserOp.data,
|
||||||
|
});
|
||||||
|
// if the estimation is too low, we use a fixed value of 500k
|
||||||
|
if (callGasLimit.lt(30000)) {
|
||||||
|
callGasLimit = BigNumber.from(500000);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
callGasLimit =
|
callGasLimit =
|
||||||
parseNumber(detailsForUserOp.gasLimit) ??
|
parseNumber(detailsForUserOp.gasLimit) ??
|
||||||
|
|||||||
@@ -45,6 +45,12 @@ export class HttpRpcClient {
|
|||||||
headers["x-bundle-id"] = (globalThis as any).APP_BUNDLE_ID as string;
|
headers["x-bundle-id"] = (globalThis as any).APP_BUNDLE_ID as string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof globalThis !== "undefined" && "TW_AUTH_TOKEN" in globalThis) {
|
||||||
|
headers["authorization"] = `Bearer ${
|
||||||
|
(globalThis as any).TW_AUTH_TOKEN as string
|
||||||
|
}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.userOpJsonRpcProvider = new providers.JsonRpcProvider(
|
this.userOpJsonRpcProvider = new providers.JsonRpcProvider(
|
||||||
|
|||||||
@@ -34,12 +34,6 @@ class VerifyingPaymasterAPI extends PaymasterAPI {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (isTwUrl(this.paymasterUrl)) {
|
if (isTwUrl(this.paymasterUrl)) {
|
||||||
if (this.secretKey && this.clientId) {
|
|
||||||
throw new Error(
|
|
||||||
"Cannot use both secret key and client ID. Please use secretKey for server-side applications and clientId for client-side applications.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.secretKey) {
|
if (this.secretKey) {
|
||||||
headers["x-secret-key"] = this.secretKey;
|
headers["x-secret-key"] = this.secretKey;
|
||||||
} else if (this.clientId) {
|
} else if (this.clientId) {
|
||||||
@@ -52,6 +46,11 @@ class VerifyingPaymasterAPI extends PaymasterAPI {
|
|||||||
headers["x-bundle-id"] = (globalThis as any).APP_BUNDLE_ID as string;
|
headers["x-bundle-id"] = (globalThis as any).APP_BUNDLE_ID as string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (typeof globalThis !== "undefined" && "TW_AUTH_TOKEN" in globalThis) {
|
||||||
|
headers["authorization"] = `Bearer ${
|
||||||
|
(globalThis as any).TW_AUTH_TOKEN as string
|
||||||
|
}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ask the paymaster to sign the transaction and return a valid paymasterAndData value.
|
// Ask the paymaster to sign the transaction and return a valid paymasterAndData value.
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
export function isTwUrl(url: string): boolean {
|
export function isTwUrl(url: string): boolean {
|
||||||
return new URL(url).hostname.endsWith('.thirdweb.com');
|
const host = new URL(url).hostname;
|
||||||
}
|
return (
|
||||||
|
host.endsWith(".thirdweb.com") || host === "localhost" || host === "0.0.0.0"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Generated
+270
-2547
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user