@thirdweb-dev/service-utils 0.0.0-dev-7953a1c-20230713221245 → 0.1.0-nightly-8dd7540c-20230713220435

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.
@@ -1,4 +1,6 @@
1
1
  import { AuthorizationResponse, AuthorizeCFWorkerOptions, AuthorizeNodeServiceOptions } from "./types";
2
2
  export declare function authorizeCFWorkerService(options: AuthorizeCFWorkerOptions): Promise<AuthorizationResponse>;
3
3
  export declare function authorizeNodeService(options: AuthorizeNodeServiceOptions): Promise<AuthorizationResponse>;
4
+ export declare function hashSecret(secret: string): string;
5
+ export declare function hashClientId(secret: string): string;
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"../../../../src/auth","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,qBAAqB,EAErB,wBAAwB,EACxB,2BAA2B,EAE5B,MAAM,SAAS,CAAC;AAEjB,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,wBAAwB,kCAkClC;AAED,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,2BAA2B,kCASrC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"../../../../src/auth","sources":["index.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,qBAAqB,EAErB,wBAAwB,EACxB,2BAA2B,EAE5B,MAAM,SAAS,CAAC;AAGjB,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,wBAAwB,kCAkClC;AAED,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,2BAA2B,kCASrC;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,UAExC;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,UAG1C"}
@@ -2,6 +2,13 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var fetch = require('isomorphic-unfetch');
6
+ var crypto = require('crypto');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
9
+
10
+ var fetch__default = /*#__PURE__*/_interopDefault(fetch);
11
+
5
12
  const SERVICE_NAMES = ["bundler", "rpc", "storage"];
6
13
  const SERVICES = [{
7
14
  name: "storage",
@@ -81,6 +88,13 @@ async function authorizeNodeService(options) {
81
88
  validations
82
89
  });
83
90
  }
91
+ function hashSecret(secret) {
92
+ return crypto.createHash("sha256").update(secret).digest("hex");
93
+ }
94
+ function hashClientId(secret) {
95
+ const hashed = crypto.createHash("sha256").update(secret).digest("hex");
96
+ return hashed.slice(0, 32);
97
+ }
84
98
 
85
99
  /**
86
100
  * Authorizes a request for a given client ID
@@ -108,7 +122,7 @@ async function authorize(options) {
108
122
 
109
123
  // no cached key, re-fetch from API
110
124
  if (!keyData) {
111
- const response = await fetch(`${apiUrl}/v1/keys/use/?scope=${scope}&clientId=${clientId}`, {
125
+ const response = await fetch__default["default"](`${apiUrl}/v1/keys/use/?scope=${scope}&clientId=${clientId}`, {
112
126
  method: "GET",
113
127
  headers: {
114
128
  "x-service-api-key": serviceKey,
@@ -277,3 +291,5 @@ exports.SERVICE_NAMES = SERVICE_NAMES;
277
291
  exports.authorizeCFWorkerService = authorizeCFWorkerService;
278
292
  exports.authorizeNodeService = authorizeNodeService;
279
293
  exports.getServiceByName = getServiceByName;
294
+ exports.hashClientId = hashClientId;
295
+ exports.hashSecret = hashSecret;
@@ -2,6 +2,13 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var fetch = require('isomorphic-unfetch');
6
+ var crypto = require('crypto');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
9
+
10
+ var fetch__default = /*#__PURE__*/_interopDefault(fetch);
11
+
5
12
  const SERVICE_NAMES = ["bundler", "rpc", "storage"];
6
13
  const SERVICES = [{
7
14
  name: "storage",
@@ -81,6 +88,13 @@ async function authorizeNodeService(options) {
81
88
  validations
82
89
  });
83
90
  }
91
+ function hashSecret(secret) {
92
+ return crypto.createHash("sha256").update(secret).digest("hex");
93
+ }
94
+ function hashClientId(secret) {
95
+ const hashed = crypto.createHash("sha256").update(secret).digest("hex");
96
+ return hashed.slice(0, 32);
97
+ }
84
98
 
85
99
  /**
86
100
  * Authorizes a request for a given client ID
@@ -108,7 +122,7 @@ async function authorize(options) {
108
122
 
109
123
  // no cached key, re-fetch from API
110
124
  if (!keyData) {
111
- const response = await fetch(`${apiUrl}/v1/keys/use/?scope=${scope}&clientId=${clientId}`, {
125
+ const response = await fetch__default["default"](`${apiUrl}/v1/keys/use/?scope=${scope}&clientId=${clientId}`, {
112
126
  method: "GET",
113
127
  headers: {
114
128
  "x-service-api-key": serviceKey,
@@ -277,3 +291,5 @@ exports.SERVICE_NAMES = SERVICE_NAMES;
277
291
  exports.authorizeCFWorkerService = authorizeCFWorkerService;
278
292
  exports.authorizeNodeService = authorizeNodeService;
279
293
  exports.getServiceByName = getServiceByName;
294
+ exports.hashClientId = hashClientId;
295
+ exports.hashSecret = hashSecret;
@@ -1,3 +1,6 @@
1
+ import fetch from 'isomorphic-unfetch';
2
+ import { createHash } from 'crypto';
3
+
1
4
  const SERVICE_NAMES = ["bundler", "rpc", "storage"];
2
5
  const SERVICES = [{
3
6
  name: "storage",
@@ -77,6 +80,13 @@ async function authorizeNodeService(options) {
77
80
  validations
78
81
  });
79
82
  }
83
+ function hashSecret(secret) {
84
+ return createHash("sha256").update(secret).digest("hex");
85
+ }
86
+ function hashClientId(secret) {
87
+ const hashed = createHash("sha256").update(secret).digest("hex");
88
+ return hashed.slice(0, 32);
89
+ }
80
90
 
81
91
  /**
82
92
  * Authorizes a request for a given client ID
@@ -268,4 +278,4 @@ function getServiceByName(name) {
268
278
  return SERVICES.find(srv => srv.name === name);
269
279
  }
270
280
 
271
- export { SERVICES, SERVICE_NAMES, authorizeCFWorkerService, authorizeNodeService, getServiceByName };
281
+ export { SERVICES, SERVICE_NAMES, authorizeCFWorkerService, authorizeNodeService, getServiceByName, hashClientId, hashSecret };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thirdweb-dev/service-utils",
3
- "version": "0.0.0-dev-7953a1c-20230713221245",
3
+ "version": "0.1.0-nightly-8dd7540c-20230713220435",
4
4
  "main": "dist/thirdweb-dev-service-utils.cjs.js",
5
5
  "module": "dist/thirdweb-dev-service-utils.esm.js",
6
6
  "exports": {
@@ -42,6 +42,9 @@
42
42
  "eslint-config-thirdweb": "^0.1.5",
43
43
  "typescript": "^5.1.6"
44
44
  },
45
+ "dependencies": {
46
+ "isomorphic-unfetch": "^4.0.2"
47
+ },
45
48
  "scripts": {
46
49
  "format": "prettier --write 'src/**/*'",
47
50
  "lint": "eslint src/",