Skip to content

Commit

Permalink
feat: replace crypto api with sha-js
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal Klesse committed Dec 20, 2024
1 parent f04036f commit 6f462ba
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 41 deletions.
66 changes: 36 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@
"@nuxt/kit": "3.14.1592",
"@pinia/nuxt": "0.9.0",
"gql-query-builder": "3.8.0",
"graphql": "16.9.0",
"graphql": "16.10.0",
"graphql-tag": "2.12.6",
"graphql-tools": "9.0.6",
"graphql-tools": "9.0.8",
"graphql-ws": "5.16.0",
"js-sha256": "0.11.0",
"jwt-decode": "4.0.0",
"nuxi": "3.16.0",
"nuxi": "3.17.1",
"nuxt-graphql-request": "^8.1.1",
"vue": "3.5.13"
},
Expand All @@ -55,7 +56,7 @@
"@nuxt/module-builder": "0.8.4",
"@nuxt/schema": "3.14.1592",
"@nuxt/test-utils": "3.15.1",
"@types/node": "22.10.1",
"@types/node": "22.10.2",
"eslint": "8.57.1",
"nuxt": "3.14.1592",
"prettier": "3.4.2",
Expand Down
10 changes: 3 additions & 7 deletions src/runtime/functions/graphql-meta.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { buildClientSchema, getIntrospectionQuery } from 'graphql';
import { sha256 } from 'js-sha256';
import { ofetch } from 'ofetch';

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

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

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

/**
Expand Down

0 comments on commit 6f462ba

Please sign in to comment.