Skip to content

Commit

Permalink
Merge pull request #58 from serenity-kit/fix-ready-in-default-export
Browse files Browse the repository at this point in the history
Fix ready in default export
  • Loading branch information
nikgraf authored Nov 30, 2023
2 parents 27bff9e + 8474de9 commit 4b5687d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 30 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"react-native": "0.71.6",
"react-native-builder-bob": "^0.20.0",
"release-it": "^15.0.0",
"typescript": "^4.5.2"
"typescript": "^5.3.2"
},
"resolutions": {
"@types/react": "17.0.21"
Expand Down
40 changes: 17 additions & 23 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export type {
StringSecretBox,
Uint8ArrayOutputFormat,
} from 'libsodium-wrappers';
import * as hkdf from '@noble/hashes/hkdf';
import { sha256 } from '@noble/hashes/sha256';
import type {
CryptoBox,
CryptoKX,
Expand All @@ -32,8 +30,20 @@ import type {
StringSecretBox,
Uint8ArrayOutputFormat,
} from 'libsodium-wrappers';
import * as hkdf from '@noble/hashes/hkdf';
import { sha256 } from '@noble/hashes/sha256';

type SodiumPackage = typeof import('libsodium-wrappers') & {
let isLoadSumoVersion = false;

export const loadSumoVersion = () => {
isLoadSumoVersion = true;
};

let lib: typeof import('libsodium-wrappers');

// @ts-expect-error this is a proxy and basically can fail if loading is not complete
let sodium: typeof import('libsodium-wrappers') & {
loadSumoVersion: () => void;
CryptoBox: CryptoBox;
CryptoKX: CryptoKX;
KeyPair: KeyPair;
Expand All @@ -48,30 +58,16 @@ type SodiumPackage = typeof import('libsodium-wrappers') & {
StringOutputFormat: StringOutputFormat;
StringSecretBox: StringSecretBox;
Uint8ArrayOutputFormat: Uint8ArrayOutputFormat;
loadSumoVersion: () => void;
};

type Sodium = {
// needed to overwrite so the readonly properties can be re-assigned
-readonly [key in keyof SodiumPackage]: SodiumPackage[key];
};

let isLoadSumoVersion = false;

export const loadSumoVersion = () => {
isLoadSumoVersion = true;
};

let lib: typeof import('libsodium-wrappers');

// @ts-expect-error this is a proxy and basically can fail if loading is not complete
let sodium: Sodium = new Proxy(
} = new Proxy(
{},
{
get(_, prop) {
if (prop === 'loadSumoVersion') {
return loadSumoVersion;
}
if (prop === 'ready') {
return ready;
}
if (lib) {
// @ts-expect-error
return lib[prop];
Expand Down Expand Up @@ -351,8 +347,6 @@ export const ready = new Promise<void>(async (resolve) => {
resolve(undefined);
});

sodium.ready = ready;

export default sodium;

export let add = sodium.add;
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"esModuleInterop": true,
"importsNotUsedAsValues": "error",
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"lib": ["esnext"],
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9707,16 +9707,16 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==

typescript@^4.5.2:
version "4.9.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a"
integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==

"typescript@^4.6.4 || ^5.0.0":
version "5.0.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.4.tgz#b217fd20119bd61a94d4011274e0ab369058da3b"
integrity sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==

typescript@^5.3.2:
version "5.3.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.2.tgz#00d1c7c1c46928c5845c1ee8d0cc2791031d4c43"
integrity sha512-6l+RyNy7oAHDfxC4FzSJcz9vnjTKxrLpDG5M2Vu4SHRVNg6xzqZp6LYSR9zjqQTu8DU/f5xwxUdADOkbrIX2gQ==

uglify-es@^3.1.9:
version "3.3.9"
resolved "https://registry.yarnpkg.com/uglify-es/-/uglify-es-3.3.9.tgz#0c1c4f0700bed8dbc124cdb304d2592ca203e677"
Expand Down

0 comments on commit 4b5687d

Please sign in to comment.