Compare commits

..
Author SHA1 Message Date
github-actions[bot]GitHubgithub-actions[bot] <github-actions[bot]@users.noreply.github.com>
1d32b299a0 Version Packages (#1337)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-07-13 16:02:54 -07:00
Tair AsimandGitHub cfa7ecbc9a service-utils: remove crypt + unfetch (#1339) 2023-07-13 22:20:42 +00:00
Jonas DanielsandGitHub 8dd7540c45 [storage] - remove HEAD request pre upload (#1338) 2023-07-13 21:57:30 +00:00
07c7d97c28 [service-utils] - initially add package (#1333)
Co-authored-by: Tair Asim <[email protected]>
2023-07-13 20:51:55 +00:00
github-actions[bot]GitHubgithub-actions[bot] <github-actions[bot]@users.noreply.github.com>
47e931e0dd Version Packages (#1336)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-07-13 09:25:13 -07:00
Jonas DanielsandGitHub 0407b2c2f3 [chains] update chains (#1335) 2023-07-13 16:01:04 +00:00
github-actions[bot]GitHubgithub-actions[bot] <github-actions[bot]@users.noreply.github.com>
55ffb176f2 Version Packages (#1331)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-07-12 19:28:04 -07:00
Adam MajmudarandGitHub a9093bcf28 Override binance chain slug (#1330) 2023-07-12 19:17:58 -07:00
48 changed files with 1730 additions and 568 deletions
+21
View File
@@ -1,5 +1,26 @@
# @thirdweb-dev/auth
## 3.2.15
### Patch Changes
- Updated dependencies []:
- @thirdweb-dev/wallets@1.0.11
## 3.2.14
### Patch Changes
- Updated dependencies []:
- @thirdweb-dev/wallets@1.0.10
## 3.2.13
### Patch Changes
- Updated dependencies []:
- @thirdweb-dev/wallets@1.0.9
## 3.2.12
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/auth",
"version": "3.2.12",
"version": "3.2.15",
"main": "dist/thirdweb-dev-auth.cjs.js",
"module": "dist/thirdweb-dev-auth.esm.js",
"browser": {
+18
View File
@@ -1,5 +1,23 @@
# @thirdweb-dev/chains
## 0.1.34
### Patch Changes
- [#1338](https://github.com/thirdweb-dev/js/pull/1338) [`8dd7540c`](https://github.com/thirdweb-dev/js/commit/8dd7540c455aa70534f6d29986537592fd12169b) Thanks [@jnsdls](https://github.com/jnsdls)! - update chains
## 0.1.33
### Patch Changes
- [#1335](https://github.com/thirdweb-dev/js/pull/1335) [`0407b2c2`](https://github.com/thirdweb-dev/js/commit/0407b2c2f39b5f3fa06e613e671623b5644b3a28) Thanks [@jnsdls](https://github.com/jnsdls)! - update chains again
## 0.1.32
### Patch Changes
- [#1330](https://github.com/thirdweb-dev/js/pull/1330) [`a9093bcf`](https://github.com/thirdweb-dev/js/commit/a9093bcf287c01e3335fd780e2ccbfdb3380bf95) Thanks [@adam-maj](https://github.com/adam-maj)! - Override binance slug
## 0.1.31
### Patch Changes
+36
View File
@@ -0,0 +1,36 @@
import type { Chain } from "../src/types";
export default {
"name": "Antofy Testnet",
"chain": "ABN",
"icon": {
"url": "ipfs://QmdTfku81ohnG9ECU1Xswmeumt678cBhwHWuFYZ7i1Qsto",
"width": 400,
"height": 400,
"format": "png"
},
"rpc": [
"https://antofy-testnet.rpc.thirdweb.com/${THIRDWEB_API_KEY}",
"https://testnet-rpc.antofy.io"
],
"faucets": [
"https://faucet.antofy.io"
],
"nativeCurrency": {
"name": "Antofy",
"symbol": "ABN",
"decimals": 18
},
"infoURL": "https://antofy.io",
"shortName": "ABNt",
"chainId": 23006,
"networkId": 23006,
"explorers": [
{
"name": "Antofy Testnet",
"url": "https://test.antofyscan.com",
"standard": "EIP3091"
}
],
"testnet": true,
"slug": "antofy-testnet"
} as const satisfies Chain;
+1 -4
View File
@@ -2,10 +2,7 @@ import type { Chain } from "../src/types";
export default {
"name": "Neon EVM MainNet",
"chain": "Solana",
"rpc": [
"https://neon-evm.rpc.thirdweb.com/${THIRDWEB_API_KEY}",
"https://mainnet.neonevm.org"
],
"rpc": [],
"faucets": [],
"icon": {
"url": "ipfs://Qmcxevb3v8PEvnvfYgcG3bCBuPhe5YAdsHeaufDChSSR3Q",
+2 -2
View File
@@ -3,7 +3,7 @@ export default {
"name": "BNB Smart Chain Mainnet",
"chain": "BSC",
"rpc": [
"https://bnb-smart-chain.rpc.thirdweb.com/${THIRDWEB_API_KEY}",
"https://binance.rpc.thirdweb.com/${THIRDWEB_API_KEY}",
"wss://bsc-ws-node.nariox.org",
"https://bsc.publicnode.com",
"https://bsc-dataseed4.ninicoin.io",
@@ -46,5 +46,5 @@ export default {
"format": "png"
},
"testnet": false,
"slug": "bnb-smart-chain"
"slug": "binance"
} as const satisfies Chain;
+15 -2
View File
@@ -3,7 +3,8 @@ export default {
"name": "Base",
"chain": "ETH",
"rpc": [
"https://base.rpc.thirdweb.com/${THIRDWEB_API_KEY}"
"https://base.rpc.thirdweb.com/${THIRDWEB_API_KEY}",
"https://developer-access-mainnet.base.org/"
],
"faucets": [],
"nativeCurrency": {
@@ -15,13 +16,25 @@ export default {
"shortName": "base",
"chainId": 8453,
"networkId": 8453,
"status": "incubating",
"icon": {
"url": "ipfs://QmW5Vn15HeRkScMfPcW12ZdZcC2yUASpu6eCsECRdEmjjj/base-512.png",
"height": 512,
"width": 512,
"format": "png"
},
"explorers": [
{
"name": "basescout",
"url": "https://base.blockscout.com",
"standard": "none"
},
{
"name": "basescan",
"url": "https://basescan.org",
"standard": "none"
}
],
"status": "active",
"testnet": false,
"slug": "base"
} as const satisfies Chain;
+6 -6
View File
@@ -18,6 +18,12 @@ export default {
"shortName": "basegor",
"chainId": 84531,
"networkId": 84531,
"icon": {
"url": "ipfs://QmW5Vn15HeRkScMfPcW12ZdZcC2yUASpu6eCsECRdEmjjj/base-512.png",
"height": 512,
"width": 512,
"format": "png"
},
"explorers": [
{
"name": "basescout",
@@ -31,11 +37,5 @@ export default {
}
],
"testnet": true,
"icon": {
"url": "ipfs://QmW5Vn15HeRkScMfPcW12ZdZcC2yUASpu6eCsECRdEmjjj/base-512.png",
"height": 512,
"width": 512,
"format": "png"
},
"slug": "base-goerli"
} as const satisfies Chain;
+2 -2
View File
@@ -3,7 +3,7 @@ export default {
"name": "BNB Smart Chain Testnet",
"chain": "BSC",
"rpc": [
"https://bnb-smart-chain-testnet.rpc.thirdweb.com/${THIRDWEB_API_KEY}",
"https://binance-testnet.rpc.thirdweb.com/${THIRDWEB_API_KEY}",
"https://bsc-testnet.publicnode.com",
"https://data-seed-prebsc-2-s3.bnbchain.org:8545",
"https://data-seed-prebsc-1-s3.bnbchain.org:8545",
@@ -38,5 +38,5 @@ export default {
"format": "png"
},
"testnet": true,
"slug": "bnb-smart-chain-testnet"
"slug": "binance-testnet"
} as const satisfies Chain;
+1
View File
@@ -11,4 +11,5 @@ export default {
format: "png",
},
rpc: ["https://base.rpc.thirdweb.com/${THIRDWEB_API_KEY}"],
status: "active",
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/chains",
"version": "0.1.31",
"version": "0.1.34",
"main": "dist/thirdweb-dev-chains.cjs.js",
"module": "dist/thirdweb-dev-chains.esm.js",
"browser": {
+2 -2
View File
@@ -164,10 +164,10 @@ function findSlug(chain) {
if (slug === "arbitrum-one") {
slug = "arbitrum";
}
if (slug === "binance-smart-chain") {
if (slug === "bnb-smart-chain") {
slug = "binance";
}
if (slug === "binance-smart-chain-testnet") {
if (slug === "bnb-smart-chain-testnet") {
slug = "binance-testnet";
}
if (slug === "base-goerli-testnet") {
File diff suppressed because one or more lines are too long
+25
View File
@@ -1,5 +1,30 @@
# thirdweb
## 0.10.36
### Patch Changes
- Updated dependencies [[`8dd7540c`](https://github.com/thirdweb-dev/js/commit/8dd7540c455aa70534f6d29986537592fd12169b), [`8dd7540c`](https://github.com/thirdweb-dev/js/commit/8dd7540c455aa70534f6d29986537592fd12169b)]:
- @thirdweb-dev/storage@1.1.9
- @thirdweb-dev/chains@0.1.34
- @thirdweb-dev/sdk@3.10.35
## 0.10.35
### Patch Changes
- Updated dependencies [[`0407b2c2`](https://github.com/thirdweb-dev/js/commit/0407b2c2f39b5f3fa06e613e671623b5644b3a28)]:
- @thirdweb-dev/chains@0.1.33
- @thirdweb-dev/sdk@3.10.34
## 0.10.34
### Patch Changes
- Updated dependencies [[`a9093bcf`](https://github.com/thirdweb-dev/js/commit/a9093bcf287c01e3335fd780e2ccbfdb3380bf95)]:
- @thirdweb-dev/chains@0.1.32
- @thirdweb-dev/sdk@3.10.33
## 0.10.33
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "thirdweb",
"main": "dist/cli/index.js",
"version": "0.10.33",
"version": "0.10.36",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/cli",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
+28
View File
@@ -1,5 +1,33 @@
# @thirdweb-dev/react-core
## 3.14.15
### Patch Changes
- Updated dependencies [[`8dd7540c`](https://github.com/thirdweb-dev/js/commit/8dd7540c455aa70534f6d29986537592fd12169b), [`8dd7540c`](https://github.com/thirdweb-dev/js/commit/8dd7540c455aa70534f6d29986537592fd12169b)]:
- @thirdweb-dev/storage@1.1.9
- @thirdweb-dev/chains@0.1.34
- @thirdweb-dev/sdk@3.10.35
- @thirdweb-dev/wallets@1.0.11
## 3.14.14
### Patch Changes
- Updated dependencies [[`0407b2c2`](https://github.com/thirdweb-dev/js/commit/0407b2c2f39b5f3fa06e613e671623b5644b3a28)]:
- @thirdweb-dev/chains@0.1.33
- @thirdweb-dev/sdk@3.10.34
- @thirdweb-dev/wallets@1.0.10
## 3.14.13
### Patch Changes
- Updated dependencies [[`a9093bcf`](https://github.com/thirdweb-dev/js/commit/a9093bcf287c01e3335fd780e2ccbfdb3380bf95)]:
- @thirdweb-dev/chains@0.1.32
- @thirdweb-dev/sdk@3.10.33
- @thirdweb-dev/wallets@1.0.9
## 3.14.12
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/react-core",
"version": "3.14.12",
"version": "3.14.15",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react-core",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
@@ -1,5 +1,11 @@
# @thirdweb-dev/react-native-compat
## 0.2.34
## 0.2.33
## 0.2.32
## 0.2.31
## 0.2.30
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@thirdweb-dev/react-native-compat",
"description": "Shims for Thirdweb in React Native Projects",
"version": "0.2.31",
"version": "0.2.34",
"author": "thirdweb eng <[email protected]>",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react-native-compat",
"license": "Apache-2.0",
+31
View File
@@ -1,5 +1,36 @@
# @thirdweb-dev/react-native
## 0.2.34
### Patch Changes
- Updated dependencies [[`8dd7540c`](https://github.com/thirdweb-dev/js/commit/8dd7540c455aa70534f6d29986537592fd12169b), [`8dd7540c`](https://github.com/thirdweb-dev/js/commit/8dd7540c455aa70534f6d29986537592fd12169b)]:
- @thirdweb-dev/storage@1.1.9
- @thirdweb-dev/chains@0.1.34
- @thirdweb-dev/react-core@3.14.15
- @thirdweb-dev/sdk@3.10.35
- @thirdweb-dev/wallets@1.0.11
## 0.2.33
### Patch Changes
- Updated dependencies [[`0407b2c2`](https://github.com/thirdweb-dev/js/commit/0407b2c2f39b5f3fa06e613e671623b5644b3a28)]:
- @thirdweb-dev/chains@0.1.33
- @thirdweb-dev/react-core@3.14.14
- @thirdweb-dev/sdk@3.10.34
- @thirdweb-dev/wallets@1.0.10
## 0.2.32
### Patch Changes
- Updated dependencies [[`a9093bcf`](https://github.com/thirdweb-dev/js/commit/a9093bcf287c01e3335fd780e2ccbfdb3380bf95)]:
- @thirdweb-dev/chains@0.1.32
- @thirdweb-dev/react-core@3.14.13
- @thirdweb-dev/sdk@3.10.33
- @thirdweb-dev/wallets@1.0.9
## 0.2.31
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/react-native",
"version": "0.2.31",
"version": "0.2.34",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react-native",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
+30
View File
@@ -1,5 +1,35 @@
# @thirdweb-dev/react
## 3.14.15
### Patch Changes
- Updated dependencies [[`8dd7540c`](https://github.com/thirdweb-dev/js/commit/8dd7540c455aa70534f6d29986537592fd12169b)]:
- @thirdweb-dev/chains@0.1.34
- @thirdweb-dev/react-core@3.14.15
- @thirdweb-dev/sdk@3.10.35
- @thirdweb-dev/wallets@1.0.11
## 3.14.14
### Patch Changes
- Updated dependencies [[`0407b2c2`](https://github.com/thirdweb-dev/js/commit/0407b2c2f39b5f3fa06e613e671623b5644b3a28)]:
- @thirdweb-dev/chains@0.1.33
- @thirdweb-dev/react-core@3.14.14
- @thirdweb-dev/sdk@3.10.34
- @thirdweb-dev/wallets@1.0.10
## 3.14.13
### Patch Changes
- Updated dependencies [[`a9093bcf`](https://github.com/thirdweb-dev/js/commit/a9093bcf287c01e3335fd780e2ccbfdb3380bf95)]:
- @thirdweb-dev/chains@0.1.32
- @thirdweb-dev/react-core@3.14.13
- @thirdweb-dev/sdk@3.10.33
- @thirdweb-dev/wallets@1.0.9
## 3.14.12
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/react",
"version": "3.14.12",
"version": "3.14.15",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
+22
View File
@@ -1,5 +1,27 @@
# @thirdweb-dev/sdk
## 3.10.35
### Patch Changes
- Updated dependencies [[`8dd7540c`](https://github.com/thirdweb-dev/js/commit/8dd7540c455aa70534f6d29986537592fd12169b), [`8dd7540c`](https://github.com/thirdweb-dev/js/commit/8dd7540c455aa70534f6d29986537592fd12169b)]:
- @thirdweb-dev/storage@1.1.9
- @thirdweb-dev/chains@0.1.34
## 3.10.34
### Patch Changes
- Updated dependencies [[`0407b2c2`](https://github.com/thirdweb-dev/js/commit/0407b2c2f39b5f3fa06e613e671623b5644b3a28)]:
- @thirdweb-dev/chains@0.1.33
## 3.10.33
### Patch Changes
- Updated dependencies [[`a9093bcf`](https://github.com/thirdweb-dev/js/commit/a9093bcf287c01e3335fd780e2ccbfdb3380bf95)]:
- @thirdweb-dev/chains@0.1.32
## 3.10.32
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/sdk",
"version": "3.10.32",
"version": "3.10.35",
"description": "The main thirdweb SDK.",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/sdk",
"license": "Apache-2.0",
+6
View File
@@ -0,0 +1,6 @@
{
"presets": [
"@babel/preset-typescript",
["@babel/preset-env", { "targets": "defaults, not ie 11" }]
]
}
+4
View File
@@ -0,0 +1,4 @@
# folders
dist/
# files
+4
View File
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ["thirdweb"],
};
+11
View File
@@ -0,0 +1,11 @@
# @thirdweb-dev/service-utils
## 0.1.0
### Minor Changes
- [#1333](https://github.com/thirdweb-dev/js/pull/1333) [`07c7d97c`](https://github.com/thirdweb-dev/js/commit/07c7d97c288063f7a5a65819e37ebe3f51095faf) Thanks [@jnsdls](https://github.com/jnsdls)! - add package
### Patch Changes
- [#1339](https://github.com/thirdweb-dev/js/pull/1339) [`cfa7ecbc`](https://github.com/thirdweb-dev/js/commit/cfa7ecbc9ab8f1c5031f82d5c23a6ee0a800c9f4) Thanks [@assimovt](https://github.com/assimovt)! - Remove crypto and unfetch node dependencies
+1
View File
@@ -0,0 +1 @@
### todo
+53
View File
@@ -0,0 +1,53 @@
{
"name": "@thirdweb-dev/service-utils",
"version": "0.1.0",
"main": "dist/thirdweb-dev-service-utils.cjs.js",
"module": "dist/thirdweb-dev-service-utils.esm.js",
"exports": {
".": {
"module": "./dist/thirdweb-dev-service-utils.esm.js",
"default": "./dist/thirdweb-dev-service-utils.cjs.js"
},
"./package.json": "./package.json"
},
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/pay",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/thirdweb-dev/js/issues"
},
"author": "thirdweb eng <[email protected]>",
"files": [
"dist/"
],
"preconstruct": {
"entrypoints": [
"index.ts"
],
"exports": true
},
"sideEffects": false,
"devDependencies": {
"@cloudflare/workers-types": "^4.20230710.0",
"@types/node": "^20.4.1",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.44.0",
"eslint-config-prettier": "^8.8.0",
"lint-staged": "^13.2.3",
"prettier": "^3.0.0",
"sort-package-json": "^2.5.1",
"ts-node": "^10.9.1",
"@preconstruct/cli": "^2.7.0",
"@thirdweb-dev/tsconfig": "workspace:*",
"eslint-config-thirdweb": "workspace:*",
"typescript": "^5.1.6"
},
"scripts": {
"format": "prettier --write 'src/**/*'",
"lint": "eslint src/",
"fix": "eslint src/ --fix",
"clean": "rm -rf dist/",
"build": "tsc && preconstruct build",
"push": "yalc push"
}
}
+253
View File
@@ -0,0 +1,253 @@
import {
ApiKey,
ApiResponse,
ServiceConfiguration,
AuthorizationResponse,
AuthorizationValidations,
AuthorizeCFWorkerOptions,
AuthorizeNodeServiceOptions,
AuthOptions,
} from "./types";
export async function authorizeCFWorkerService(
options: AuthorizeCFWorkerOptions,
) {
const { kvStore, ctx, authOptions, serviceConfig, validations } = options;
const { clientId } = authOptions;
let cachedKey;
// first, check if the key is in KV
try {
const kvKey = await kvStore.get(clientId);
if (kvKey) {
cachedKey = JSON.parse(kvKey) as ApiKey;
}
} catch (err) {
// ignore JSON parse, assuming not valid
}
const updateKv = async (keyData: ApiKey) => {
kvStore.put(clientId as string, JSON.stringify(keyData), {
expirationTtl: serviceConfig.cacheTtl || 60,
});
};
return authorize({
authOptions,
serviceConfig: {
...serviceConfig,
cachedKey,
onRefetchComplete: (keyData: ApiKey) => {
ctx.waitUntil(updateKv(keyData));
},
},
validations,
});
}
export async function authorizeNodeService(
options: AuthorizeNodeServiceOptions,
) {
const { authOptions, serviceConfig, validations } = options;
return authorize({
authOptions,
serviceConfig,
validations,
});
}
/**
* Authorizes a request for a given client ID
*
* @returns The Promise AuthorizationResponse
*/
async function authorize(options: {
authOptions: AuthOptions;
serviceConfig: ServiceConfiguration;
validations: AuthorizationValidations;
}): Promise<AuthorizationResponse> {
try {
const { authOptions, serviceConfig, validations } = options;
const { clientId } = authOptions;
const { apiUrl, scope, serviceKey, cachedKey, onRefetchComplete } =
serviceConfig;
let keyData = cachedKey;
// no cached key, re-fetch from API
if (!keyData) {
const response = await fetch(
`${apiUrl}/v1/keys/use/?scope=${scope}&clientId=${clientId}`,
{
method: "GET",
headers: {
"x-service-api-key": serviceKey,
"content-type": "application/json",
},
},
);
const apiResponse = (await response.json()) as ApiResponse;
if (!response.ok) {
const { error } = apiResponse;
return {
authorized: false,
errorMessage: error.message,
errorCode: error.code || "",
statusCode: error.statusCode || 401,
};
}
keyData = apiResponse.data as ApiKey;
if (onRefetchComplete) {
onRefetchComplete(keyData);
}
}
//
// Run validations
//
const authResponse = authAccess(authOptions, keyData);
if (!authResponse?.authorized) {
return authResponse;
}
const authzResponse = authzServices(validations, keyData, scope);
if (!authzResponse?.authorized) {
return authzResponse;
}
// FIXME: validate bundleId
return {
authorized: true,
data: keyData,
};
} catch (err) {
console.error("Failed to authorize this key.", err);
return {
authorized: false,
errorMessage: "Internal error",
errorCode: "INTERNAL_ERROR",
statusCode: 500,
};
}
}
function authAccess(authOptions: AuthOptions, apiKey: ApiKey) {
const { origin, secretHash: providedSecretHash } = authOptions;
const { domains, secretHash } = apiKey;
if (providedSecretHash) {
if (secretHash !== providedSecretHash) {
return {
authorized: false,
errorMessage: "The secret is invalid.",
errorCode: "SECRET_INVALID",
statusCode: 401,
};
}
return {
authorized: true,
};
}
// validate domains
if (origin) {
if (
// find matching domain, or if all domains allowed
domains.find((d) => {
if (d === "*") {
return true;
}
// If the allowedDomain has a wildcard,
// we'll check that the ending of our domain matches the wildcard
if (d.startsWith("*.")) {
const domainRoot = d.slice(2);
return origin.endsWith(domainRoot);
}
// If there's no wildcard, we'll check for an exact match
return d === origin;
})
) {
return {
authorized: true,
};
}
return {
authorized: false,
errorMessage: "The origin is not authorized for this key.",
errorCode: "ORIGIN_UNAUTHORIZED",
statusCode: 401,
};
}
// FIXME: validate bundle id
return {
authorized: false,
errorMessage: "The keys are invalid.",
errorCode: "UNAUTHORIZED",
statusCode: 401,
};
}
function authzServices(
validations: AuthorizationValidations,
apiKey: ApiKey,
scope: string,
) {
const { services } = apiKey;
const { serviceTargetAddresses, serviceAction } = validations;
// validate services
const service = services.find((srv) => srv.name === scope);
if (!service) {
return {
authorized: false,
errorMessage: `The service "${scope}" is not authorized for this key.`,
errorCode: "SERVICE_UNAUTHORIZED",
statusCode: 403,
};
}
// validate service actions
if (serviceAction) {
if (!service.actions.includes(serviceAction)) {
return {
authorized: false,
errorMessage: `The service "${scope}" action "${serviceAction}" is not authorized for this key.`,
errorCode: "SERVICE_ACTION_UNAUTHORIZED",
statusCode: 403,
};
}
}
// validate service target addresses
if (
serviceTargetAddresses &&
!service.targetAddresses.find(
(addr) => addr === "*" || serviceTargetAddresses.includes(addr),
)
) {
return {
authorized: false,
errorMessage: `The service "${scope}" target address is not authorized for this key.`,
errorCode: "SERVICE_TARGET_ADDRESS_UNAUTHORIZED",
statusCode: 403,
};
}
return {
authorized: true,
};
}
+68
View File
@@ -0,0 +1,68 @@
import { KVNamespace, ExecutionContext } from "@cloudflare/workers-types";
import { ServiceName } from "../types";
export interface AuthOptions {
clientId: string;
secretHash?: string;
bundleId?: string;
origin?: string;
}
export interface AuthorizeCFWorkerOptions {
ctx: ExecutionContext;
kvStore: KVNamespace<string>;
authOptions: AuthOptions;
serviceConfig: ServiceConfiguration;
validations: AuthorizationValidations;
}
export interface AuthorizeNodeServiceOptions {
authOptions: AuthOptions;
serviceConfig: ServiceConfiguration;
validations: AuthorizationValidations;
}
export interface ServiceConfiguration {
apiUrl: string;
scope: ServiceName;
serviceKey: string;
cachedKey?: ApiKey;
cacheTtl?: number;
onRefetchComplete?: (key: ApiKey) => void;
}
export interface AuthorizationValidations {
serviceTargetAddresses?: string[];
serviceAction?: string;
}
export interface AuthorizationResponse {
authorized: boolean;
errorMessage?: string;
errorCode?: string;
statusCode?: number;
data?: ApiKey;
}
export interface ApiResponse {
data: ApiKey | null;
error: {
code: string;
statusCode: number;
message: string;
};
}
export interface ApiKey {
id: string;
key: string;
secretHash: string;
walletAddresses: string[];
domains: string[];
bundleIds: string[];
services: {
name: string;
targetAddresses: string[];
actions: string[];
}[];
}
+8
View File
@@ -0,0 +1,8 @@
import { SERVICES } from "./types";
export function getServiceByName(name: string) {
return SERVICES.find((srv) => srv.name === name);
}
export * from "./types";
export * from "./auth";
+50
View File
@@ -0,0 +1,50 @@
export const SERVICE_NAMES = ["bundler", "rpc", "storage"] as const;
export const SERVICES: Service[] = [
{
name: "storage",
title: "Storage",
description: "IPFS Upload and Download",
actions: [
{
name: "read",
title: "Download",
description: "Download a file from Storage",
},
{
name: "write",
title: "Upload",
description: "Upload a file to Storage",
},
],
},
{
name: "rpc",
title: "RPC",
description: "Accelerated RPC Edge",
// all actions allowed
actions: [],
},
{
name: "bundler",
title: "Smart Wallets",
description: "Bundler & Paymaster services",
// all actions allowed
actions: [],
},
];
export type ServiceName = (typeof SERVICE_NAMES)[number];
export interface ServiceAction {
name: string;
title: string;
description?: string;
}
export interface Service {
name: ServiceName;
title: string;
description?: string;
actions: ServiceAction[];
}
+5
View File
@@ -0,0 +1,5 @@
{
"extends": "@thirdweb-dev/tsconfig/sdk.json",
"include": ["src", "types"],
"exclude": ["dist", "build", "node_modules"]
}
+6
View File
@@ -1,5 +1,11 @@
# @thirdweb-dev/storage
## 1.1.9
### Patch Changes
- [#1338](https://github.com/thirdweb-dev/js/pull/1338) [`8dd7540c`](https://github.com/thirdweb-dev/js/commit/8dd7540c455aa70534f6d29986537592fd12169b) Thanks [@jnsdls](https://github.com/jnsdls)! - no longer check if file exists on gateway before uploading, always upload
## 1.1.8
### Patch Changes
+1 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/storage",
"version": "1.1.8",
"version": "1.1.9",
"main": "dist/thirdweb-dev-storage.cjs.js",
"module": "dist/thirdweb-dev-storage.esm.js",
"browser": {
@@ -67,7 +67,6 @@
"cid-tool": "^3.0.0",
"cross-fetch": "^3.1.6",
"form-data": "^4.0.0",
"ipfs-unixfs-importer": "^7.0.1",
"uuid": "^9.0.0"
}
}
-79
View File
@@ -1,79 +0,0 @@
import { FileOrBufferOrString } from "../types";
import { DEFAULT_GATEWAY_URLS, getGatewayUrlForCid } from "./urls";
import { isBufferOrStringWithName } from "./utils";
import fetch from "cross-fetch";
import { importer } from "ipfs-unixfs-importer";
type CIDVersion = 0 | 1;
type ContentWithPath = {
path?: string;
content: Uint8Array;
};
export async function getCIDForUpload(
data: FileOrBufferOrString[],
fileNames: string[],
wrapWithDirectory = true,
cidVersion: CIDVersion = 0,
) {
const contentWithPath: ContentWithPath[] = await Promise.all(
data.map(async (file, i) => {
const path = fileNames[i];
let content: Uint8Array;
if (typeof file === "string") {
content = new TextEncoder().encode(file);
} else if (isBufferOrStringWithName(file)) {
if (typeof file.data === "string") {
content = new TextEncoder().encode(file.data);
} else {
content = file.data as Uint8Array;
}
} else if (Buffer.isBuffer(file)) {
content = file as Uint8Array;
} else {
const buffer = await file.arrayBuffer();
content = new Uint8Array(buffer);
}
return { path, content };
}),
);
return getCID(contentWithPath, wrapWithDirectory, cidVersion);
}
export async function getCID(
content: ContentWithPath[],
wrapWithDirectory = true,
cidVersion: CIDVersion = 0,
) {
const options = { onlyHash: true, wrapWithDirectory, cidVersion };
const dummyBlockstore = {
put: async () => {},
};
let lastCid;
for await (const { cid } of importer(
content as any,
dummyBlockstore as any,
options,
)) {
lastCid = cid;
}
return `${lastCid}`;
}
export async function isUploaded(cid: string) {
const url = getGatewayUrlForCid(DEFAULT_GATEWAY_URLS["ipfs://"][0], cid);
const res = await fetch(url, {
method: "HEAD",
headers: {
// tell the gateway to skip fetching from origin in order to fail fast on 404s and just re-upload in those cases
"x-skip-origin": "true",
},
});
return res.ok;
}
-1
View File
@@ -1,3 +1,2 @@
export * from "./urls";
export * from "./utils";
export * from "./cid";
@@ -1,4 +1,3 @@
import { getCIDForUpload, isUploaded } from "../../common";
import { PINATA_IPFS_URL, TW_IPFS_SERVER_URL } from "../../common/urls";
import {
isBrowser,
@@ -57,30 +56,6 @@ export class IpfsUploader implements IStorageUploader<IpfsUploadBatchOptions> {
const formData = new FormData();
const { form, fileNames } = this.buildFormData(formData, data, options);
try {
const cid = await getCIDForUpload(
data,
fileNames.map((name) => decodeURIComponent(name)),
!options?.uploadWithoutDirectory,
);
if ((await isUploaded(cid)) && !options?.alwaysUpload) {
if (options?.onProgress) {
options?.onProgress({
progress: 100,
total: 100,
});
}
if (options?.uploadWithoutDirectory) {
return [`ipfs://${cid}`];
} else {
return fileNames.map((name) => `ipfs://${cid}/${name}`);
}
}
} catch {
// no-op
}
if (isBrowser()) {
return this.uploadBatchBrowser(form, fileNames, options);
} else {
-30
View File
@@ -1,30 +0,0 @@
import { getCID } from "../src";
import { expect } from "chai";
import fs from "fs";
describe("CID", async () => {
it("Should correctly get CID of a string", async () => {
const cid = await getCID(
[{ content: new TextEncoder().encode("hello world") }],
false,
);
expect(cid).to.equal("Qmf412jQZiuVUtdgnB36FXFX7xg5V6KEbSJ4dpQuhkLyfD");
});
it("Should correctly get CID of a file", async () => {
const cid = await getCID(
[{ content: fs.readFileSync("test/files/0.jpg") }],
false,
);
expect(cid).to.equal("QmSBs7aGB52CF2kXdQaHS6kvQuFACufCbfMKjrB5gSytiT");
});
it("Should correctly upload directory", async () => {
const files = [
{ path: "0.jpg", content: fs.readFileSync("test/files/0.jpg") },
{ path: "1.jpg", content: fs.readFileSync("test/files/1.jpg") },
];
const cid = await getCID(files);
expect(cid).to.equal("QmYtBTkEnTGrzkns2L8R4rL3keowVg3nGcBhPbwrbAWTRP");
});
});
+31
View File
@@ -1,5 +1,36 @@
# @thirdweb-dev/unity-js-bridge
## 0.2.52
### Patch Changes
- Updated dependencies [[`8dd7540c`](https://github.com/thirdweb-dev/js/commit/8dd7540c455aa70534f6d29986537592fd12169b), [`8dd7540c`](https://github.com/thirdweb-dev/js/commit/8dd7540c455aa70534f6d29986537592fd12169b)]:
- @thirdweb-dev/storage@1.1.9
- @thirdweb-dev/chains@0.1.34
- @thirdweb-dev/sdk@3.10.35
- @thirdweb-dev/wallets@1.0.11
- @thirdweb-dev/auth@3.2.15
## 0.2.51
### Patch Changes
- Updated dependencies [[`0407b2c2`](https://github.com/thirdweb-dev/js/commit/0407b2c2f39b5f3fa06e613e671623b5644b3a28)]:
- @thirdweb-dev/chains@0.1.33
- @thirdweb-dev/sdk@3.10.34
- @thirdweb-dev/wallets@1.0.10
- @thirdweb-dev/auth@3.2.14
## 0.2.50
### Patch Changes
- Updated dependencies [[`a9093bcf`](https://github.com/thirdweb-dev/js/commit/a9093bcf287c01e3335fd780e2ccbfdb3380bf95)]:
- @thirdweb-dev/chains@0.1.32
- @thirdweb-dev/sdk@3.10.33
- @thirdweb-dev/wallets@1.0.9
- @thirdweb-dev/auth@3.2.13
## 0.2.49
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/unity-js-bridge",
"version": "0.2.49",
"version": "0.2.52",
"main": "dist/thirdweb-unity-bridge.js",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/unity-js-bridge",
"license": "Apache-2.0",
@@ -17,6 +17,7 @@ esbuild.build({
splitting: false,
write: true,
sourcemap: false,
inject: [require.resolve("node-stdlib-browser/helpers/esbuild/shim")],
define: {
process: JSON.stringify({
+24
View File
@@ -1,5 +1,29 @@
# @thirdweb-dev/wallets
## 1.0.11
### Patch Changes
- Updated dependencies [[`8dd7540c`](https://github.com/thirdweb-dev/js/commit/8dd7540c455aa70534f6d29986537592fd12169b)]:
- @thirdweb-dev/chains@0.1.34
- @thirdweb-dev/sdk@3.10.35
## 1.0.10
### Patch Changes
- Updated dependencies [[`0407b2c2`](https://github.com/thirdweb-dev/js/commit/0407b2c2f39b5f3fa06e613e671623b5644b3a28)]:
- @thirdweb-dev/chains@0.1.33
- @thirdweb-dev/sdk@3.10.34
## 1.0.9
### Patch Changes
- Updated dependencies [[`a9093bcf`](https://github.com/thirdweb-dev/js/commit/a9093bcf287c01e3335fd780e2ccbfdb3380bf95)]:
- @thirdweb-dev/chains@0.1.32
- @thirdweb-dev/sdk@3.10.33
## 1.0.8
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/wallets",
"version": "1.0.8",
"version": "1.0.11",
"main": "dist/thirdweb-dev-wallets.cjs.js",
"module": "dist/thirdweb-dev-wallets.esm.js",
"types": "dist/thirdweb-dev-wallets.cjs.d.ts",
+939 -398
View File
File diff suppressed because it is too large Load Diff