@thirdweb-dev/service-utils 0.4.30 → 0.4.31-nightly-a5db9a330f0eb85406074fcff9b454fa7cd073d8-20240609150319

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. package/cf-worker/dist/thirdweb-dev-service-utils-cf-worker.cjs.dev.js +6 -6
  2. package/cf-worker/dist/thirdweb-dev-service-utils-cf-worker.cjs.prod.js +6 -6
  3. package/cf-worker/dist/thirdweb-dev-service-utils-cf-worker.esm.js +3 -3
  4. package/dist/client-43ffd386.cjs.prod.js +203 -0
  5. package/dist/client-8a85ab05.esm.js +195 -0
  6. package/dist/client-e805236b.cjs.dev.js +203 -0
  7. package/dist/declarations/src/core/authorize/client.d.ts +8 -0
  8. package/dist/declarations/src/core/authorize/client.d.ts.map +1 -1
  9. package/dist/declarations/src/index.d.ts +1 -0
  10. package/dist/declarations/src/index.d.ts.map +1 -1
  11. package/dist/declarations/src/node/index.d.ts +2 -3
  12. package/dist/declarations/src/node/index.d.ts.map +1 -1
  13. package/dist/{index-1fdaaa60.cjs.dev.js → index-0d9dbeb2.cjs.dev.js} +3 -111
  14. package/dist/{index-1216f784.esm.js → index-8cff5ac3.esm.js} +2 -110
  15. package/dist/{index-9b21f405.cjs.prod.js → index-fecf7702.cjs.prod.js} +3 -111
  16. package/dist/thirdweb-dev-service-utils.cjs.dev.js +7 -5
  17. package/dist/thirdweb-dev-service-utils.cjs.prod.js +7 -5
  18. package/dist/thirdweb-dev-service-utils.esm.js +1 -1
  19. package/node/dist/thirdweb-dev-service-utils-node.cjs.dev.js +6 -6
  20. package/node/dist/thirdweb-dev-service-utils-node.cjs.prod.js +6 -6
  21. package/node/dist/thirdweb-dev-service-utils-node.esm.js +3 -3
  22. package/package.json +1 -1
  23. package/dist/services-5ebf68d5.esm.js +0 -65
  24. package/dist/services-628562db.cjs.prod.js +0 -70
  25. package/dist/services-97e0f9a0.cjs.dev.js +0 -70
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-1fdaaa60.cjs.dev.js');
5
+ var index = require('../../dist/index-0d9dbeb2.cjs.dev.js');
6
6
  var aws4fetch = require('aws4fetch');
7
7
  var zod = require('zod');
8
- var services = require('../../dist/services-97e0f9a0.cjs.dev.js');
8
+ var client = require('../../dist/client-e805236b.cjs.dev.js');
9
9
 
10
10
  // Initialize a singleton for AWS usage.
11
11
  let _aws;
@@ -265,10 +265,10 @@ async function logHttpRequest(_ref) {
265
265
 
266
266
  exports.rateLimit = index.rateLimit;
267
267
  exports.usageLimit = index.usageLimit;
268
- exports.SERVICES = services.SERVICES;
269
- exports.SERVICE_DEFINITIONS = services.SERVICE_DEFINITIONS;
270
- exports.SERVICE_NAMES = services.SERVICE_NAMES;
271
- exports.getServiceByName = services.getServiceByName;
268
+ exports.SERVICES = client.SERVICES;
269
+ exports.SERVICE_DEFINITIONS = client.SERVICE_DEFINITIONS;
270
+ exports.SERVICE_NAMES = client.SERVICE_NAMES;
271
+ exports.getServiceByName = client.getServiceByName;
272
272
  exports.authorizeWorker = authorizeWorker;
273
273
  exports.deriveClientIdFromSecretKeyHash = deriveClientIdFromSecretKeyHash;
274
274
  exports.extractAuthorizationData = extractAuthorizationData;
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-9b21f405.cjs.prod.js');
5
+ var index = require('../../dist/index-fecf7702.cjs.prod.js');
6
6
  var aws4fetch = require('aws4fetch');
7
7
  var zod = require('zod');
8
- var services = require('../../dist/services-628562db.cjs.prod.js');
8
+ var client = require('../../dist/client-43ffd386.cjs.prod.js');
9
9
 
10
10
  // Initialize a singleton for AWS usage.
11
11
  let _aws;
@@ -265,10 +265,10 @@ async function logHttpRequest(_ref) {
265
265
 
266
266
  exports.rateLimit = index.rateLimit;
267
267
  exports.usageLimit = index.usageLimit;
268
- exports.SERVICES = services.SERVICES;
269
- exports.SERVICE_DEFINITIONS = services.SERVICE_DEFINITIONS;
270
- exports.SERVICE_NAMES = services.SERVICE_NAMES;
271
- exports.getServiceByName = services.getServiceByName;
268
+ exports.SERVICES = client.SERVICES;
269
+ exports.SERVICE_DEFINITIONS = client.SERVICE_DEFINITIONS;
270
+ exports.SERVICE_NAMES = client.SERVICE_NAMES;
271
+ exports.getServiceByName = client.getServiceByName;
272
272
  exports.authorizeWorker = authorizeWorker;
273
273
  exports.deriveClientIdFromSecretKeyHash = deriveClientIdFromSecretKeyHash;
274
274
  exports.extractAuthorizationData = extractAuthorizationData;
@@ -1,8 +1,8 @@
1
- import { a as authorize } from '../../dist/index-1216f784.esm.js';
2
- export { r as rateLimit, u as usageLimit } from '../../dist/index-1216f784.esm.js';
1
+ import { a as authorize } from '../../dist/index-8cff5ac3.esm.js';
2
+ export { r as rateLimit, u as usageLimit } from '../../dist/index-8cff5ac3.esm.js';
3
3
  import { AwsClient } from 'aws4fetch';
4
4
  import { z } from 'zod';
5
- export { b as SERVICES, S as SERVICE_DEFINITIONS, a as SERVICE_NAMES, g as getServiceByName } from '../../dist/services-5ebf68d5.esm.js';
5
+ export { d as SERVICES, S as SERVICE_DEFINITIONS, c as SERVICE_NAMES, g as getServiceByName } from '../../dist/client-8a85ab05.esm.js';
6
6
 
7
7
  // Initialize a singleton for AWS usage.
8
8
  let _aws;
@@ -0,0 +1,203 @@
1
+ 'use strict';
2
+
3
+ const SERVICE_DEFINITIONS = {
4
+ storage: {
5
+ name: "storage",
6
+ title: "Storage",
7
+ description: "IPFS Upload and Download",
8
+ actions: [{
9
+ name: "read",
10
+ title: "Download",
11
+ description: "Download a file from Storage"
12
+ }, {
13
+ name: "write",
14
+ title: "Upload",
15
+ description: "Upload a file to Storage"
16
+ }]
17
+ },
18
+ rpc: {
19
+ name: "rpc",
20
+ title: "RPC",
21
+ description: "Accelerated RPC Edge",
22
+ // all actions allowed
23
+ actions: []
24
+ },
25
+ bundler: {
26
+ name: "bundler",
27
+ title: "Account Abstraction",
28
+ description: "Bundler & Paymaster services",
29
+ // all actions allowed
30
+ actions: []
31
+ },
32
+ relayer: {
33
+ name: "relayer",
34
+ title: "Gasless Relayer",
35
+ description: "Enable gasless transactions",
36
+ // all actions allowed
37
+ actions: []
38
+ },
39
+ embeddedWallets: {
40
+ name: "embeddedWallets",
41
+ title: "In-App Wallets",
42
+ description: "E-mail and social login wallets for easy web3 onboarding",
43
+ // all actions allowed
44
+ actions: []
45
+ },
46
+ checkout: {
47
+ name: "checkout",
48
+ title: "Checkouts",
49
+ description: "NFT Checkouts for easy web3 onboarding",
50
+ // all actions allowed
51
+ actions: []
52
+ },
53
+ pay: {
54
+ name: "pay",
55
+ title: "Pay",
56
+ description: "Pay for a blockchain transaction with any currency",
57
+ // all actions allowed
58
+ actions: []
59
+ }
60
+ };
61
+ const SERVICE_NAMES = Object.keys(SERVICE_DEFINITIONS);
62
+ const SERVICES = Object.values(SERVICE_DEFINITIONS);
63
+ function getServiceByName(name) {
64
+ return SERVICE_DEFINITIONS[name];
65
+ }
66
+
67
+ function authorizeClient(authOptions, apiKeyMeta) {
68
+ const {
69
+ origin,
70
+ bundleId,
71
+ secretKeyHash: providedSecretHash
72
+ } = authOptions;
73
+ const {
74
+ domains,
75
+ bundleIds,
76
+ secretHash
77
+ } = apiKeyMeta;
78
+ const authResult = {
79
+ authorized: true,
80
+ apiKeyMeta,
81
+ accountMeta: {
82
+ id: apiKeyMeta.accountId,
83
+ // TODO update this later
84
+ name: "",
85
+ creatorWalletAddress: apiKeyMeta.creatorWalletAddress,
86
+ limits: apiKeyMeta.limits,
87
+ rateLimits: apiKeyMeta.rateLimits,
88
+ usage: apiKeyMeta.usage
89
+ }
90
+ };
91
+
92
+ // check for public restrictions
93
+ if (domains.includes("*")) {
94
+ return authResult;
95
+ }
96
+
97
+ // check for secretHash
98
+ if (providedSecretHash) {
99
+ if (secretHash !== providedSecretHash) {
100
+ return {
101
+ authorized: false,
102
+ errorMessage: "Incorrect key provided. You can view your active API keys at https://thirdweb.com/dashboard/settings",
103
+ errorCode: "SECRET_INVALID",
104
+ status: 401
105
+ };
106
+ }
107
+ return authResult;
108
+ }
109
+
110
+ // validate domains
111
+ if (origin) {
112
+ if (authorizeDomain({
113
+ domains,
114
+ origin
115
+ })) {
116
+ return authResult;
117
+ }
118
+ return {
119
+ authorized: false,
120
+ errorMessage: `Invalid request: Unauthorized domain: ${origin}. You can view the restrictions on this API key at https://thirdweb.com/create-api-key`,
121
+ errorCode: "ORIGIN_UNAUTHORIZED",
122
+ status: 401
123
+ };
124
+ }
125
+
126
+ // validate bundleId
127
+ if (bundleId) {
128
+ if (authorizeBundleId({
129
+ bundleIds,
130
+ bundleId
131
+ })) {
132
+ return authResult;
133
+ }
134
+ return {
135
+ authorized: false,
136
+ errorMessage: `Invalid request: Unauthorized Bundle ID: ${bundleId}. You can view the restrictions on this API key at https://thirdweb.com/create-api-key`,
137
+ errorCode: "BUNDLE_UNAUTHORIZED",
138
+ status: 401
139
+ };
140
+ }
141
+ return {
142
+ authorized: false,
143
+ errorMessage: "The keys are invalid. Please check the secret-key/clientId and try again.",
144
+ errorCode: "UNAUTHORIZED",
145
+ status: 401
146
+ };
147
+ }
148
+
149
+ // Exposed for use in validating ecosystem partners settings
150
+ function authorizeDomain(_ref) {
151
+ let {
152
+ domains,
153
+ origin
154
+ } = _ref;
155
+ // find matching domain, or if all domains allowed
156
+ // embedded-wallet.thirdweb(-dev).com is automatically allowed
157
+ // because the rpc is passed from user's domain to embedded-wallet.thirdweb.com iframe for use.
158
+ // Note this doesn't allow embedded-wallets from being used if it's disabled. The service check that runs after enforces that.
159
+ return !![...domains, "embedded-wallet.thirdweb.com", "embedded-wallet.thirdweb-dev.com"].find(d => {
160
+ // if any domain is allowed, we'll return true
161
+ if (d === "*") {
162
+ return true;
163
+ }
164
+
165
+ // special rule for `localhost`
166
+ // if the domain is localhost, we'll allow any origin that starts with localhost
167
+ if (d === "localhost" && origin.startsWith("localhost")) {
168
+ return true;
169
+ }
170
+
171
+ // If the allowedDomain has a wildcard,
172
+ // we'll check that the ending of our domain matches the wildcard
173
+ if (d.startsWith("*.")) {
174
+ // get rid of the * and check if it ends with the `.<domain>.<tld>`
175
+ const domainRoot = d.slice(1);
176
+ return origin.endsWith(domainRoot);
177
+ }
178
+
179
+ // If there's no wildcard, we'll check for an exact match
180
+ return d === origin;
181
+ });
182
+ }
183
+ function authorizeBundleId(_ref2) {
184
+ let {
185
+ bundleIds,
186
+ bundleId
187
+ } = _ref2;
188
+ // find matching bundle id, or if all bundles allowed
189
+ return !!bundleIds.find(b => {
190
+ if (b === "*") {
191
+ return true;
192
+ }
193
+ return b === bundleId;
194
+ });
195
+ }
196
+
197
+ exports.SERVICES = SERVICES;
198
+ exports.SERVICE_DEFINITIONS = SERVICE_DEFINITIONS;
199
+ exports.SERVICE_NAMES = SERVICE_NAMES;
200
+ exports.authorizeBundleId = authorizeBundleId;
201
+ exports.authorizeClient = authorizeClient;
202
+ exports.authorizeDomain = authorizeDomain;
203
+ exports.getServiceByName = getServiceByName;
@@ -0,0 +1,195 @@
1
+ const SERVICE_DEFINITIONS = {
2
+ storage: {
3
+ name: "storage",
4
+ title: "Storage",
5
+ description: "IPFS Upload and Download",
6
+ actions: [{
7
+ name: "read",
8
+ title: "Download",
9
+ description: "Download a file from Storage"
10
+ }, {
11
+ name: "write",
12
+ title: "Upload",
13
+ description: "Upload a file to Storage"
14
+ }]
15
+ },
16
+ rpc: {
17
+ name: "rpc",
18
+ title: "RPC",
19
+ description: "Accelerated RPC Edge",
20
+ // all actions allowed
21
+ actions: []
22
+ },
23
+ bundler: {
24
+ name: "bundler",
25
+ title: "Account Abstraction",
26
+ description: "Bundler & Paymaster services",
27
+ // all actions allowed
28
+ actions: []
29
+ },
30
+ relayer: {
31
+ name: "relayer",
32
+ title: "Gasless Relayer",
33
+ description: "Enable gasless transactions",
34
+ // all actions allowed
35
+ actions: []
36
+ },
37
+ embeddedWallets: {
38
+ name: "embeddedWallets",
39
+ title: "In-App Wallets",
40
+ description: "E-mail and social login wallets for easy web3 onboarding",
41
+ // all actions allowed
42
+ actions: []
43
+ },
44
+ checkout: {
45
+ name: "checkout",
46
+ title: "Checkouts",
47
+ description: "NFT Checkouts for easy web3 onboarding",
48
+ // all actions allowed
49
+ actions: []
50
+ },
51
+ pay: {
52
+ name: "pay",
53
+ title: "Pay",
54
+ description: "Pay for a blockchain transaction with any currency",
55
+ // all actions allowed
56
+ actions: []
57
+ }
58
+ };
59
+ const SERVICE_NAMES = Object.keys(SERVICE_DEFINITIONS);
60
+ const SERVICES = Object.values(SERVICE_DEFINITIONS);
61
+ function getServiceByName(name) {
62
+ return SERVICE_DEFINITIONS[name];
63
+ }
64
+
65
+ function authorizeClient(authOptions, apiKeyMeta) {
66
+ const {
67
+ origin,
68
+ bundleId,
69
+ secretKeyHash: providedSecretHash
70
+ } = authOptions;
71
+ const {
72
+ domains,
73
+ bundleIds,
74
+ secretHash
75
+ } = apiKeyMeta;
76
+ const authResult = {
77
+ authorized: true,
78
+ apiKeyMeta,
79
+ accountMeta: {
80
+ id: apiKeyMeta.accountId,
81
+ // TODO update this later
82
+ name: "",
83
+ creatorWalletAddress: apiKeyMeta.creatorWalletAddress,
84
+ limits: apiKeyMeta.limits,
85
+ rateLimits: apiKeyMeta.rateLimits,
86
+ usage: apiKeyMeta.usage
87
+ }
88
+ };
89
+
90
+ // check for public restrictions
91
+ if (domains.includes("*")) {
92
+ return authResult;
93
+ }
94
+
95
+ // check for secretHash
96
+ if (providedSecretHash) {
97
+ if (secretHash !== providedSecretHash) {
98
+ return {
99
+ authorized: false,
100
+ errorMessage: "Incorrect key provided. You can view your active API keys at https://thirdweb.com/dashboard/settings",
101
+ errorCode: "SECRET_INVALID",
102
+ status: 401
103
+ };
104
+ }
105
+ return authResult;
106
+ }
107
+
108
+ // validate domains
109
+ if (origin) {
110
+ if (authorizeDomain({
111
+ domains,
112
+ origin
113
+ })) {
114
+ return authResult;
115
+ }
116
+ return {
117
+ authorized: false,
118
+ errorMessage: `Invalid request: Unauthorized domain: ${origin}. You can view the restrictions on this API key at https://thirdweb.com/create-api-key`,
119
+ errorCode: "ORIGIN_UNAUTHORIZED",
120
+ status: 401
121
+ };
122
+ }
123
+
124
+ // validate bundleId
125
+ if (bundleId) {
126
+ if (authorizeBundleId({
127
+ bundleIds,
128
+ bundleId
129
+ })) {
130
+ return authResult;
131
+ }
132
+ return {
133
+ authorized: false,
134
+ errorMessage: `Invalid request: Unauthorized Bundle ID: ${bundleId}. You can view the restrictions on this API key at https://thirdweb.com/create-api-key`,
135
+ errorCode: "BUNDLE_UNAUTHORIZED",
136
+ status: 401
137
+ };
138
+ }
139
+ return {
140
+ authorized: false,
141
+ errorMessage: "The keys are invalid. Please check the secret-key/clientId and try again.",
142
+ errorCode: "UNAUTHORIZED",
143
+ status: 401
144
+ };
145
+ }
146
+
147
+ // Exposed for use in validating ecosystem partners settings
148
+ function authorizeDomain(_ref) {
149
+ let {
150
+ domains,
151
+ origin
152
+ } = _ref;
153
+ // find matching domain, or if all domains allowed
154
+ // embedded-wallet.thirdweb(-dev).com is automatically allowed
155
+ // because the rpc is passed from user's domain to embedded-wallet.thirdweb.com iframe for use.
156
+ // Note this doesn't allow embedded-wallets from being used if it's disabled. The service check that runs after enforces that.
157
+ return !![...domains, "embedded-wallet.thirdweb.com", "embedded-wallet.thirdweb-dev.com"].find(d => {
158
+ // if any domain is allowed, we'll return true
159
+ if (d === "*") {
160
+ return true;
161
+ }
162
+
163
+ // special rule for `localhost`
164
+ // if the domain is localhost, we'll allow any origin that starts with localhost
165
+ if (d === "localhost" && origin.startsWith("localhost")) {
166
+ return true;
167
+ }
168
+
169
+ // If the allowedDomain has a wildcard,
170
+ // we'll check that the ending of our domain matches the wildcard
171
+ if (d.startsWith("*.")) {
172
+ // get rid of the * and check if it ends with the `.<domain>.<tld>`
173
+ const domainRoot = d.slice(1);
174
+ return origin.endsWith(domainRoot);
175
+ }
176
+
177
+ // If there's no wildcard, we'll check for an exact match
178
+ return d === origin;
179
+ });
180
+ }
181
+ function authorizeBundleId(_ref2) {
182
+ let {
183
+ bundleIds,
184
+ bundleId
185
+ } = _ref2;
186
+ // find matching bundle id, or if all bundles allowed
187
+ return !!bundleIds.find(b => {
188
+ if (b === "*") {
189
+ return true;
190
+ }
191
+ return b === bundleId;
192
+ });
193
+ }
194
+
195
+ export { SERVICE_DEFINITIONS as S, authorizeBundleId as a, authorizeDomain as b, SERVICE_NAMES as c, SERVICES as d, authorizeClient as e, getServiceByName as g };
@@ -0,0 +1,203 @@
1
+ 'use strict';
2
+
3
+ const SERVICE_DEFINITIONS = {
4
+ storage: {
5
+ name: "storage",
6
+ title: "Storage",
7
+ description: "IPFS Upload and Download",
8
+ actions: [{
9
+ name: "read",
10
+ title: "Download",
11
+ description: "Download a file from Storage"
12
+ }, {
13
+ name: "write",
14
+ title: "Upload",
15
+ description: "Upload a file to Storage"
16
+ }]
17
+ },
18
+ rpc: {
19
+ name: "rpc",
20
+ title: "RPC",
21
+ description: "Accelerated RPC Edge",
22
+ // all actions allowed
23
+ actions: []
24
+ },
25
+ bundler: {
26
+ name: "bundler",
27
+ title: "Account Abstraction",
28
+ description: "Bundler & Paymaster services",
29
+ // all actions allowed
30
+ actions: []
31
+ },
32
+ relayer: {
33
+ name: "relayer",
34
+ title: "Gasless Relayer",
35
+ description: "Enable gasless transactions",
36
+ // all actions allowed
37
+ actions: []
38
+ },
39
+ embeddedWallets: {
40
+ name: "embeddedWallets",
41
+ title: "In-App Wallets",
42
+ description: "E-mail and social login wallets for easy web3 onboarding",
43
+ // all actions allowed
44
+ actions: []
45
+ },
46
+ checkout: {
47
+ name: "checkout",
48
+ title: "Checkouts",
49
+ description: "NFT Checkouts for easy web3 onboarding",
50
+ // all actions allowed
51
+ actions: []
52
+ },
53
+ pay: {
54
+ name: "pay",
55
+ title: "Pay",
56
+ description: "Pay for a blockchain transaction with any currency",
57
+ // all actions allowed
58
+ actions: []
59
+ }
60
+ };
61
+ const SERVICE_NAMES = Object.keys(SERVICE_DEFINITIONS);
62
+ const SERVICES = Object.values(SERVICE_DEFINITIONS);
63
+ function getServiceByName(name) {
64
+ return SERVICE_DEFINITIONS[name];
65
+ }
66
+
67
+ function authorizeClient(authOptions, apiKeyMeta) {
68
+ const {
69
+ origin,
70
+ bundleId,
71
+ secretKeyHash: providedSecretHash
72
+ } = authOptions;
73
+ const {
74
+ domains,
75
+ bundleIds,
76
+ secretHash
77
+ } = apiKeyMeta;
78
+ const authResult = {
79
+ authorized: true,
80
+ apiKeyMeta,
81
+ accountMeta: {
82
+ id: apiKeyMeta.accountId,
83
+ // TODO update this later
84
+ name: "",
85
+ creatorWalletAddress: apiKeyMeta.creatorWalletAddress,
86
+ limits: apiKeyMeta.limits,
87
+ rateLimits: apiKeyMeta.rateLimits,
88
+ usage: apiKeyMeta.usage
89
+ }
90
+ };
91
+
92
+ // check for public restrictions
93
+ if (domains.includes("*")) {
94
+ return authResult;
95
+ }
96
+
97
+ // check for secretHash
98
+ if (providedSecretHash) {
99
+ if (secretHash !== providedSecretHash) {
100
+ return {
101
+ authorized: false,
102
+ errorMessage: "Incorrect key provided. You can view your active API keys at https://thirdweb.com/dashboard/settings",
103
+ errorCode: "SECRET_INVALID",
104
+ status: 401
105
+ };
106
+ }
107
+ return authResult;
108
+ }
109
+
110
+ // validate domains
111
+ if (origin) {
112
+ if (authorizeDomain({
113
+ domains,
114
+ origin
115
+ })) {
116
+ return authResult;
117
+ }
118
+ return {
119
+ authorized: false,
120
+ errorMessage: `Invalid request: Unauthorized domain: ${origin}. You can view the restrictions on this API key at https://thirdweb.com/create-api-key`,
121
+ errorCode: "ORIGIN_UNAUTHORIZED",
122
+ status: 401
123
+ };
124
+ }
125
+
126
+ // validate bundleId
127
+ if (bundleId) {
128
+ if (authorizeBundleId({
129
+ bundleIds,
130
+ bundleId
131
+ })) {
132
+ return authResult;
133
+ }
134
+ return {
135
+ authorized: false,
136
+ errorMessage: `Invalid request: Unauthorized Bundle ID: ${bundleId}. You can view the restrictions on this API key at https://thirdweb.com/create-api-key`,
137
+ errorCode: "BUNDLE_UNAUTHORIZED",
138
+ status: 401
139
+ };
140
+ }
141
+ return {
142
+ authorized: false,
143
+ errorMessage: "The keys are invalid. Please check the secret-key/clientId and try again.",
144
+ errorCode: "UNAUTHORIZED",
145
+ status: 401
146
+ };
147
+ }
148
+
149
+ // Exposed for use in validating ecosystem partners settings
150
+ function authorizeDomain(_ref) {
151
+ let {
152
+ domains,
153
+ origin
154
+ } = _ref;
155
+ // find matching domain, or if all domains allowed
156
+ // embedded-wallet.thirdweb(-dev).com is automatically allowed
157
+ // because the rpc is passed from user's domain to embedded-wallet.thirdweb.com iframe for use.
158
+ // Note this doesn't allow embedded-wallets from being used if it's disabled. The service check that runs after enforces that.
159
+ return !![...domains, "embedded-wallet.thirdweb.com", "embedded-wallet.thirdweb-dev.com"].find(d => {
160
+ // if any domain is allowed, we'll return true
161
+ if (d === "*") {
162
+ return true;
163
+ }
164
+
165
+ // special rule for `localhost`
166
+ // if the domain is localhost, we'll allow any origin that starts with localhost
167
+ if (d === "localhost" && origin.startsWith("localhost")) {
168
+ return true;
169
+ }
170
+
171
+ // If the allowedDomain has a wildcard,
172
+ // we'll check that the ending of our domain matches the wildcard
173
+ if (d.startsWith("*.")) {
174
+ // get rid of the * and check if it ends with the `.<domain>.<tld>`
175
+ const domainRoot = d.slice(1);
176
+ return origin.endsWith(domainRoot);
177
+ }
178
+
179
+ // If there's no wildcard, we'll check for an exact match
180
+ return d === origin;
181
+ });
182
+ }
183
+ function authorizeBundleId(_ref2) {
184
+ let {
185
+ bundleIds,
186
+ bundleId
187
+ } = _ref2;
188
+ // find matching bundle id, or if all bundles allowed
189
+ return !!bundleIds.find(b => {
190
+ if (b === "*") {
191
+ return true;
192
+ }
193
+ return b === bundleId;
194
+ });
195
+ }
196
+
197
+ exports.SERVICES = SERVICES;
198
+ exports.SERVICE_DEFINITIONS = SERVICE_DEFINITIONS;
199
+ exports.SERVICE_NAMES = SERVICE_NAMES;
200
+ exports.authorizeBundleId = authorizeBundleId;
201
+ exports.authorizeClient = authorizeClient;
202
+ exports.authorizeDomain = authorizeDomain;
203
+ exports.getServiceByName = getServiceByName;
@@ -6,4 +6,12 @@ export type ClientAuthorizationPayload = {
6
6
  origin: string | null;
7
7
  };
8
8
  export declare function authorizeClient(authOptions: ClientAuthorizationPayload, apiKeyMeta: ApiKeyMetadata): AuthorizationResult;
9
+ export declare function authorizeDomain({ domains, origin, }: {
10
+ domains: string[];
11
+ origin: string;
12
+ }): boolean;
13
+ export declare function authorizeBundleId({ bundleIds, bundleId, }: {
14
+ bundleIds: string[];
15
+ bundleId: string;
16
+ }): boolean;
9
17
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"../../../../../src/core/authorize","sources":["client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD,MAAM,MAAM,0BAA0B,GAAG;IACvC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,CAAC;AAEF,wBAAgB,eAAe,CAC7B,WAAW,EAAE,0BAA0B,EACvC,UAAU,EAAE,cAAc,GACzB,mBAAmB,CAkHrB"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"../../../../../src/core/authorize","sources":["client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD,MAAM,MAAM,0BAA0B,GAAG;IACvC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,CAAC;AAEF,wBAAgB,eAAe,CAC7B,WAAW,EAAE,0BAA0B,EACvC,UAAU,EAAE,cAAc,GACzB,mBAAmB,CAmFrB;AAGD,wBAAgB,eAAe,CAAC,EAC9B,OAAO,EACP,MAAM,GACP,EAAE;IAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAgCjD;AAED,wBAAgB,iBAAiB,CAAC,EAChC,SAAS,EACT,QAAQ,GACT,EAAE;IAAE,SAAS,EAAE,MAAM,EAAE,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CASrD"}
@@ -1,2 +1,3 @@
1
1
  export * from "./core/services";
2
+ export { authorizeBundleId, authorizeDomain, } from "./core/authorize/client";
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"../../../src","sources":["index.ts"],"names":[],"mappings":"AACA,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"../../../src","sources":["index.ts"],"names":[],"mappings":"AACA,cAAc,iBAAiB,CAAC;AAEhC,OAAO,EACL,iBAAiB,EACjB,eAAe,GAChB,MAAM,yBAAyB,CAAC"}