Skip to content

Commit

Permalink
Merge pull request #694 from magiclabs/rominhalltari-sc-91675-error-t…
Browse files Browse the repository at this point in the history
…hrown-when-spinning-up-local-app

Fix: use default import of crypto-js to fix unresolved imports after build
  • Loading branch information
romin-halltari authored Dec 26, 2023
2 parents 4e202e0 + 710e68f commit cb4cfa3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 5 additions & 7 deletions packages/@magic-ext/oauth/src/crypto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { WordArray } from 'crypto-js';
import SHA256 from 'crypto-js/sha256';
import Base64 from 'crypto-js/enc-base64';
import Crypto from 'crypto-js';

const CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~';
const HAS_CRYPTO = typeof window !== 'undefined' && !!(window.crypto as any);
Expand All @@ -19,9 +17,9 @@ function bytesToVerifierString(bytes: Uint8Array) {
* Stringifies argument (as CryptoJS `WordArray` or EcmaScript `ArrayBuffer`)
* and encodes to URL-safe Base64.
*/
function base64URLEncodeFromByteArray(wordArray: WordArray): string;
function base64URLEncodeFromByteArray(wordArray: Crypto.WordArray): string;
function base64URLEncodeFromByteArray(arrayBuffer: ArrayBuffer): string;
function base64URLEncodeFromByteArray(arg: WordArray | ArrayBuffer): string {
function base64URLEncodeFromByteArray(arg: Crypto.WordArray | ArrayBuffer): string {
const makeURLSafe = (base64: string) => {
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
};
Expand All @@ -36,7 +34,7 @@ function base64URLEncodeFromByteArray(arg: WordArray | ArrayBuffer): string {
return makeURLSafe(base64);
}

return makeURLSafe(Base64.stringify(arg));
return makeURLSafe(Crypto.enc.Base64.stringify(arg));
}

/**
Expand All @@ -50,7 +48,7 @@ async function sha256(message: string) {
return crypto.subtle.digest('SHA-256', bytes).then(base64URLEncodeFromByteArray);
}

return base64URLEncodeFromByteArray(SHA256(message));
return base64URLEncodeFromByteArray(Crypto.SHA256(message));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2950,7 +2950,7 @@ __metadata:
languageName: unknown
linkType: soft

"@magic-ext/oauth@^15.4.1, @magic-ext/oauth@workspace:packages/@magic-ext/oauth":
"@magic-ext/oauth@^15.5.0, @magic-ext/oauth@workspace:packages/@magic-ext/oauth":
version: 0.0.0-use.local
resolution: "@magic-ext/oauth@workspace:packages/@magic-ext/oauth"
dependencies:
Expand Down Expand Up @@ -3087,7 +3087,7 @@ __metadata:
"@babel/core": ^7.9.6
"@babel/plugin-proposal-optional-chaining": ^7.9.0
"@babel/runtime": ^7.9.6
"@magic-ext/oauth": ^15.4.1
"@magic-ext/oauth": ^15.5.0
magic-sdk: ^21.4.1
languageName: unknown
linkType: soft
Expand Down

0 comments on commit cb4cfa3

Please sign in to comment.