Skip to content

Commit 6f462ba

Browse files
author
Pascal Klesse
committed
feat: replace crypto api with sha-js
1 parent f04036f commit 6f462ba

File tree

3 files changed

+44
-41
lines changed

3 files changed

+44
-41
lines changed

package-lock.json

Lines changed: 36 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@
4141
"@nuxt/kit": "3.14.1592",
4242
"@pinia/nuxt": "0.9.0",
4343
"gql-query-builder": "3.8.0",
44-
"graphql": "16.9.0",
44+
"graphql": "16.10.0",
4545
"graphql-tag": "2.12.6",
46-
"graphql-tools": "9.0.6",
46+
"graphql-tools": "9.0.8",
4747
"graphql-ws": "5.16.0",
48+
"js-sha256": "0.11.0",
4849
"jwt-decode": "4.0.0",
49-
"nuxi": "3.16.0",
50+
"nuxi": "3.17.1",
5051
"nuxt-graphql-request": "^8.1.1",
5152
"vue": "3.5.13"
5253
},
@@ -55,7 +56,7 @@
5556
"@nuxt/module-builder": "0.8.4",
5657
"@nuxt/schema": "3.14.1592",
5758
"@nuxt/test-utils": "3.15.1",
58-
"@types/node": "22.10.1",
59+
"@types/node": "22.10.2",
5960
"eslint": "8.57.1",
6061
"nuxt": "3.14.1592",
6162
"prettier": "3.4.2",

src/runtime/functions/graphql-meta.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { buildClientSchema, getIntrospectionQuery } from 'graphql';
2+
import { sha256 } from 'js-sha256';
23
import { ofetch } from 'ofetch';
34

45
import type { GraphQLMeta } from '../../generate';
@@ -10,7 +11,7 @@ export async function loadMeta(config: Partial<{ public: { host: string; schema?
1011
setTimeout(() => controller.abort(), 5000);
1112

1213
return new Promise(async (resolve, reject) => {
13-
const { data: result } = await ofetch(config.public.gqlHost, {
14+
const { data: result } = await ofetch(config.public?.gqlHost, {
1415
body: JSON.stringify({
1516
query: getIntrospectionQuery({ descriptions: false }),
1617
variables: {},
@@ -30,14 +31,9 @@ export async function loadMeta(config: Partial<{ public: { host: string; schema?
3031

3132
/**
3233
* Hash a string with SHA-256
33-
* see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#converting_a_digest_to_a_hex_string
3434
*/
3535
export async function hash(string: string): Promise<string> {
36-
const utf8 = new TextEncoder().encode(string);
37-
const hashBuffer = await crypto.subtle.digest('SHA-256', utf8);
38-
const hashArray = Array.from(new Uint8Array(hashBuffer));
39-
const hashHex = hashArray.map((bytes) => bytes.toString(16).padStart(2, '0')).join('');
40-
return hashHex;
36+
return sha256(string);
4137
}
4238

4339
/**

0 commit comments

Comments
 (0)