mindoodb 0.0.2 → 0.0.3
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.
- package/README.md +92 -19
- package/dist/__mocks__/expo-standard-web-crypto.d.ts +10 -0
- package/dist/__mocks__/expo-standard-web-crypto.d.ts.map +1 -0
- package/dist/__mocks__/expo-standard-web-crypto.js +22 -0
- package/dist/__mocks__/expo-standard-web-crypto.js.map +1 -0
- package/dist/appendonlystores/BasicOnDiskContentAddressedStoreFactory.d.ts +8 -0
- package/dist/appendonlystores/BasicOnDiskContentAddressedStoreFactory.d.ts.map +1 -0
- package/dist/appendonlystores/BasicOnDiskContentAddressedStoreFactory.js +16 -0
- package/dist/appendonlystores/BasicOnDiskContentAddressedStoreFactory.js.map +1 -0
- package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.d.ts +1 -1
- package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.d.ts.map +1 -1
- package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.js +2 -2
- package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.js.map +1 -1
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts +11 -1
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts.map +1 -1
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js +94 -0
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js.map +1 -1
- package/dist/appendonlystores/network/HttpTransport.d.ts +13 -2
- package/dist/appendonlystores/network/HttpTransport.d.ts.map +1 -1
- package/dist/appendonlystores/network/HttpTransport.js +86 -0
- package/dist/appendonlystores/network/HttpTransport.js.map +1 -1
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts +19 -2
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts.map +1 -1
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js +96 -0
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js.map +1 -1
- package/dist/appendonlystores/network/index.d.ts +1 -1
- package/dist/appendonlystores/network/index.d.ts.map +1 -1
- package/dist/appendonlystores/network/index.js.map +1 -1
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStore.d.ts +61 -0
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStore.d.ts.map +1 -0
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStore.js +685 -0
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStore.js.map +1 -0
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStoreFactory.d.ts +25 -0
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStoreFactory.d.ts.map +1 -0
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStoreFactory.js +41 -0
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStoreFactory.js.map +1 -0
- package/dist/browser/index.d.ts +5 -0
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +13 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/core/BaseMindooDB.d.ts +12 -0
- package/dist/core/BaseMindooDB.d.ts.map +1 -1
- package/dist/core/BaseMindooDB.js +210 -108
- package/dist/core/BaseMindooDB.js.map +1 -1
- package/dist/core/BaseMindooTenant.d.ts +40 -6
- package/dist/core/BaseMindooTenant.d.ts.map +1 -1
- package/dist/core/BaseMindooTenant.js +179 -21
- package/dist/core/BaseMindooTenant.js.map +1 -1
- package/dist/core/BaseMindooTenantDirectory.d.ts.map +1 -1
- package/dist/core/BaseMindooTenantDirectory.js +10 -0
- package/dist/core/BaseMindooTenantDirectory.js.map +1 -1
- package/dist/core/BaseMindooTenantFactory.d.ts +22 -28
- package/dist/core/BaseMindooTenantFactory.d.ts.map +1 -1
- package/dist/core/BaseMindooTenantFactory.js +161 -65
- package/dist/core/BaseMindooTenantFactory.js.map +1 -1
- package/dist/core/appendonlystores/BasicOnDiskContentAddressedStore.d.ts +68 -0
- package/dist/core/appendonlystores/BasicOnDiskContentAddressedStore.d.ts.map +1 -0
- package/dist/core/appendonlystores/BasicOnDiskContentAddressedStore.js +659 -0
- package/dist/core/appendonlystores/BasicOnDiskContentAddressedStore.js.map +1 -0
- package/dist/core/appendonlystores/InMemoryContentAddressedStore.d.ts +43 -3
- package/dist/core/appendonlystores/InMemoryContentAddressedStore.d.ts.map +1 -1
- package/dist/core/appendonlystores/InMemoryContentAddressedStore.js +162 -23
- package/dist/core/appendonlystores/InMemoryContentAddressedStore.js.map +1 -1
- package/dist/core/appendonlystores/bloom.d.ts +85 -0
- package/dist/core/appendonlystores/bloom.d.ts.map +1 -0
- package/dist/core/appendonlystores/bloom.js +228 -0
- package/dist/core/appendonlystores/bloom.js.map +1 -0
- package/dist/core/appendonlystores/network/NetworkTransport.d.ts +22 -2
- package/dist/core/appendonlystores/network/NetworkTransport.d.ts.map +1 -1
- package/dist/core/appendonlystores/network/types.d.ts +10 -0
- package/dist/core/appendonlystores/network/types.d.ts.map +1 -1
- package/dist/core/appendonlystores/network/types.js.map +1 -1
- package/dist/core/appendonlystores/types.d.ts +123 -0
- package/dist/core/appendonlystores/types.d.ts.map +1 -1
- package/dist/core/automerge-adapter.d.ts +15 -0
- package/dist/core/automerge-adapter.d.ts.map +1 -0
- package/dist/core/automerge-adapter.js +73 -0
- package/dist/core/automerge-adapter.js.map +1 -0
- package/dist/core/crypto/pbkdf2Iterations.d.ts +12 -0
- package/dist/core/crypto/pbkdf2Iterations.d.ts.map +1 -0
- package/dist/core/crypto/pbkdf2Iterations.js +55 -0
- package/dist/core/crypto/pbkdf2Iterations.js.map +1 -0
- package/dist/core/index.d.ts +7 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +30 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/keys/KeyBag.d.ts +32 -12
- package/dist/core/keys/KeyBag.d.ts.map +1 -1
- package/dist/core/keys/KeyBag.js +86 -26
- package/dist/core/keys/KeyBag.js.map +1 -1
- package/dist/core/keys/KeyContext.d.ts +4 -0
- package/dist/core/keys/KeyContext.d.ts.map +1 -0
- package/dist/core/keys/KeyContext.js +11 -0
- package/dist/core/keys/KeyContext.js.map +1 -0
- package/dist/core/types.d.ts +218 -50
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -1
- package/dist/core/uri/MindooURI.d.ts +58 -0
- package/dist/core/uri/MindooURI.d.ts.map +1 -0
- package/dist/core/uri/MindooURI.js +169 -0
- package/dist/core/uri/MindooURI.js.map +1 -0
- package/dist/core/userid/index.d.ts +0 -10
- package/dist/core/userid/index.d.ts.map +1 -1
- package/dist/node/appendonlystores/BasicOnDiskContentAddressedStore.d.ts +541 -0
- package/dist/node/appendonlystores/BasicOnDiskContentAddressedStore.d.ts.map +1 -0
- package/dist/node/appendonlystores/BasicOnDiskContentAddressedStore.js +1334 -0
- package/dist/node/appendonlystores/BasicOnDiskContentAddressedStore.js.map +1 -0
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +5 -1
- package/dist/node/index.js.map +1 -1
- package/dist/reactnative/crypto/AESAdapter.d.ts +18 -0
- package/dist/reactnative/crypto/AESAdapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/AESAdapter.js +112 -0
- package/dist/reactnative/crypto/AESAdapter.js.map +1 -0
- package/dist/reactnative/crypto/Ed25519Adapter.d.ts +34 -0
- package/dist/reactnative/crypto/Ed25519Adapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/Ed25519Adapter.js +386 -0
- package/dist/reactnative/crypto/Ed25519Adapter.js.map +1 -0
- package/dist/reactnative/crypto/ExpoGoCryptoAdapter.d.ts +23 -0
- package/dist/reactnative/crypto/ExpoGoCryptoAdapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/ExpoGoCryptoAdapter.js +51 -0
- package/dist/reactnative/crypto/ExpoGoCryptoAdapter.js.map +1 -0
- package/dist/reactnative/crypto/HMACAdapter.d.ts +13 -0
- package/dist/reactnative/crypto/HMACAdapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/HMACAdapter.js +50 -0
- package/dist/reactnative/crypto/HMACAdapter.js.map +1 -0
- package/dist/reactnative/crypto/KeyFormatConverter.d.ts +21 -0
- package/dist/reactnative/crypto/KeyFormatConverter.d.ts.map +1 -0
- package/dist/reactnative/crypto/KeyFormatConverter.js +72 -0
- package/dist/reactnative/crypto/KeyFormatConverter.js.map +1 -0
- package/dist/reactnative/crypto/PBKDF2Adapter.d.ts +19 -0
- package/dist/reactnative/crypto/PBKDF2Adapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/PBKDF2Adapter.js +67 -0
- package/dist/reactnative/crypto/PBKDF2Adapter.js.map +1 -0
- package/dist/reactnative/crypto/QuickCryptoAdapter.d.ts +37 -0
- package/dist/reactnative/crypto/QuickCryptoAdapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/QuickCryptoAdapter.js +72 -0
- package/dist/reactnative/crypto/QuickCryptoAdapter.js.map +1 -0
- package/dist/reactnative/crypto/RSAAdapter.d.ts +38 -0
- package/dist/reactnative/crypto/RSAAdapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/RSAAdapter.js +184 -0
- package/dist/reactnative/crypto/RSAAdapter.js.map +1 -0
- package/dist/reactnative/crypto/ReactNativeCryptoAdapter.d.ts +33 -0
- package/dist/reactnative/crypto/ReactNativeCryptoAdapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/ReactNativeCryptoAdapter.js +61 -0
- package/dist/reactnative/crypto/ReactNativeCryptoAdapter.js.map +1 -0
- package/dist/reactnative/crypto/SHA256Adapter.d.ts +9 -0
- package/dist/reactnative/crypto/SHA256Adapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/SHA256Adapter.js +29 -0
- package/dist/reactnative/crypto/SHA256Adapter.js.map +1 -0
- package/dist/reactnative/crypto/SubtleCryptoPolyfill.d.ts +63 -0
- package/dist/reactnative/crypto/SubtleCryptoPolyfill.d.ts.map +1 -0
- package/dist/reactnative/crypto/SubtleCryptoPolyfill.js +350 -0
- package/dist/reactnative/crypto/SubtleCryptoPolyfill.js.map +1 -0
- package/dist/reactnative/index.d.ts +8 -0
- package/dist/reactnative/index.d.ts.map +1 -0
- package/dist/reactnative/index.js +38 -0
- package/dist/reactnative/index.js.map +1 -0
- package/package.json +51 -6
- package/patches/PATCHES.md +111 -0
- package/patches/react-native+0.76.9.patch +34 -0
- package/patches/react-native-quick-crypto+1.0.7.patch +42 -0
- package/scripts/cli.js +21 -0
- package/scripts/setup-react-native.js +228 -0
- package/templates/reactnative/App.js +252 -0
- package/templates/reactnative/app.json +29 -0
- package/templates/reactnative/babel.config.js +6 -0
- package/templates/reactnative/index.js +26 -0
- package/templates/reactnative/metro.config.snippet.js +39 -0
- package/templates/reactnative/mindoodb-polyfills.js +116 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PBKDF2 Key Derivation Adapter
|
|
3
|
+
* Implements PBKDF2 key derivation using node-forge
|
|
4
|
+
*/
|
|
5
|
+
export interface PBKDF2Params {
|
|
6
|
+
name: "PBKDF2";
|
|
7
|
+
salt: BufferSource;
|
|
8
|
+
iterations: number;
|
|
9
|
+
hash: "SHA-256";
|
|
10
|
+
}
|
|
11
|
+
export interface DeriveKeyParams {
|
|
12
|
+
name: "AES-GCM";
|
|
13
|
+
length: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Derive a key using PBKDF2
|
|
17
|
+
*/
|
|
18
|
+
export declare function pbkdf2DeriveKey(params: PBKDF2Params, baseKey: ArrayBuffer, derivedKeyParams: DeriveKeyParams): Promise<CryptoKey>;
|
|
19
|
+
//# sourceMappingURL=PBKDF2Adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PBKDF2Adapter.d.ts","sourceRoot":"","sources":["../../../src/reactnative/crypto/PBKDF2Adapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,EAAE,YAAY,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,WAAW,EACpB,gBAAgB,EAAE,eAAe,GAChC,OAAO,CAAC,SAAS,CAAC,CA2DpB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* PBKDF2 Key Derivation Adapter
|
|
4
|
+
* Implements PBKDF2 key derivation using node-forge
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.pbkdf2DeriveKey = pbkdf2DeriveKey;
|
|
11
|
+
const node_forge_1 = __importDefault(require("node-forge"));
|
|
12
|
+
/**
|
|
13
|
+
* Derive a key using PBKDF2
|
|
14
|
+
*/
|
|
15
|
+
async function pbkdf2DeriveKey(params, baseKey, derivedKeyParams) {
|
|
16
|
+
// Ensure salt is a proper ArrayBuffer
|
|
17
|
+
let saltBytes;
|
|
18
|
+
if (params.salt instanceof Uint8Array) {
|
|
19
|
+
saltBytes = params.salt;
|
|
20
|
+
}
|
|
21
|
+
else if (params.salt instanceof ArrayBuffer) {
|
|
22
|
+
saltBytes = new Uint8Array(params.salt);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
// ArrayBufferView - copy to ensure we have ArrayBuffer
|
|
26
|
+
const view = params.salt;
|
|
27
|
+
const copy = new Uint8Array(view.byteLength);
|
|
28
|
+
copy.set(new Uint8Array(view.buffer, view.byteOffset, view.byteLength));
|
|
29
|
+
saltBytes = copy;
|
|
30
|
+
}
|
|
31
|
+
// Ensure baseKey is a proper ArrayBuffer
|
|
32
|
+
let baseKeyBuffer;
|
|
33
|
+
if (baseKey instanceof ArrayBuffer) {
|
|
34
|
+
baseKeyBuffer = baseKey;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const view = new Uint8Array(baseKey);
|
|
38
|
+
const copy = new Uint8Array(view.length);
|
|
39
|
+
copy.set(view);
|
|
40
|
+
baseKeyBuffer = copy.buffer;
|
|
41
|
+
}
|
|
42
|
+
// Derive key using PBKDF2
|
|
43
|
+
// node-forge pbkdf2 expects password as string and salt as string
|
|
44
|
+
// Convert buffers to binary strings using getBytes()
|
|
45
|
+
const baseKeyBuf = node_forge_1.default.util.createBuffer(baseKeyBuffer);
|
|
46
|
+
const baseKeyStr = baseKeyBuf.getBytes();
|
|
47
|
+
const saltBuf = node_forge_1.default.util.createBuffer(saltBytes.buffer);
|
|
48
|
+
const saltStr = saltBuf.getBytes();
|
|
49
|
+
const keyLength = derivedKeyParams.length / 8; // Convert bits to bytes
|
|
50
|
+
const derivedKey = node_forge_1.default.pkcs5.pbkdf2(baseKeyStr, saltStr, params.iterations, keyLength, node_forge_1.default.md.sha256.create());
|
|
51
|
+
// Convert string to Uint8Array
|
|
52
|
+
// derivedKey is a binary string, convert to bytes
|
|
53
|
+
const keyMaterial = new Uint8Array(keyLength);
|
|
54
|
+
for (let i = 0; i < keyLength && i < derivedKey.length; i++) {
|
|
55
|
+
keyMaterial[i] = derivedKey.charCodeAt(i) & 0xff;
|
|
56
|
+
}
|
|
57
|
+
// Return a CryptoKey-like object that can be used for encryption/decryption
|
|
58
|
+
return {
|
|
59
|
+
type: "secret",
|
|
60
|
+
extractable: false,
|
|
61
|
+
algorithm: derivedKeyParams,
|
|
62
|
+
usages: ["encrypt", "decrypt"],
|
|
63
|
+
// Store raw key material for use in encryption/decryption
|
|
64
|
+
_rawKey: keyMaterial.buffer,
|
|
65
|
+
};
|
|
66
|
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
2
|
+
* Quick Crypto Adapter
|
|
3
|
+
* Wrapper for react-native-quick-crypto native module
|
|
4
|
+
* Provides high-performance crypto operations for React Native native builds
|
|
5
|
+
*/
|
|
6
|
+
import type { CryptoAdapter } from "../../core/crypto/CryptoAdapter";
|
|
7
|
+
/**
|
|
8
|
+
* Interface for the react-native-quick-crypto module
|
|
9
|
+
*/
|
|
10
|
+
interface QuickCryptoModule {
|
|
11
|
+
subtle: SubtleCrypto;
|
|
12
|
+
getRandomValues?: (array: Uint8Array) => Uint8Array;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Quick Crypto Adapter
|
|
16
|
+
* Uses react-native-quick-crypto for native crypto operations
|
|
17
|
+
* This provides significantly better performance than the JS-only ExpoGoCryptoAdapter
|
|
18
|
+
*/
|
|
19
|
+
export declare class QuickCryptoAdapter implements CryptoAdapter {
|
|
20
|
+
private quickCrypto;
|
|
21
|
+
constructor(quickCrypto: QuickCryptoModule);
|
|
22
|
+
/**
|
|
23
|
+
* Get the SubtleCrypto interface from react-native-quick-crypto
|
|
24
|
+
*/
|
|
25
|
+
getSubtle(): SubtleCrypto;
|
|
26
|
+
/**
|
|
27
|
+
* Get random values using react-native-quick-crypto
|
|
28
|
+
*/
|
|
29
|
+
getRandomValues(array: Uint8Array): Uint8Array;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Check if react-native-quick-crypto is available
|
|
33
|
+
* @returns true if the module is available and functional
|
|
34
|
+
*/
|
|
35
|
+
export declare function isQuickCryptoAvailable(): boolean;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=QuickCryptoAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QuickCryptoAdapter.d.ts","sourceRoot":"","sources":["../../../src/reactnative/crypto/QuickCryptoAdapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAErE;;GAEG;AACH,UAAU,iBAAiB;IACzB,MAAM,EAAE,YAAY,CAAC;IACrB,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,UAAU,CAAC;CACrD;AAED;;;;GAIG;AACH,qBAAa,kBAAmB,YAAW,aAAa;IACtD,OAAO,CAAC,WAAW,CAAoB;gBAE3B,WAAW,EAAE,iBAAiB;IAU1C;;OAEG;IACH,SAAS,IAAI,YAAY;IAIzB;;OAEG;IACH,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU;CAS/C;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,OAAO,CA0BhD"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Quick Crypto Adapter
|
|
4
|
+
* Wrapper for react-native-quick-crypto native module
|
|
5
|
+
* Provides high-performance crypto operations for React Native native builds
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.QuickCryptoAdapter = void 0;
|
|
9
|
+
exports.isQuickCryptoAvailable = isQuickCryptoAvailable;
|
|
10
|
+
/**
|
|
11
|
+
* Quick Crypto Adapter
|
|
12
|
+
* Uses react-native-quick-crypto for native crypto operations
|
|
13
|
+
* This provides significantly better performance than the JS-only ExpoGoCryptoAdapter
|
|
14
|
+
*/
|
|
15
|
+
class QuickCryptoAdapter {
|
|
16
|
+
constructor(quickCrypto) {
|
|
17
|
+
if (!quickCrypto || !quickCrypto.subtle) {
|
|
18
|
+
throw new Error("react-native-quick-crypto subtle API is not available. " +
|
|
19
|
+
"Make sure you have a development build with react-native-quick-crypto installed.");
|
|
20
|
+
}
|
|
21
|
+
this.quickCrypto = quickCrypto;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get the SubtleCrypto interface from react-native-quick-crypto
|
|
25
|
+
*/
|
|
26
|
+
getSubtle() {
|
|
27
|
+
return this.quickCrypto.subtle;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get random values using react-native-quick-crypto
|
|
31
|
+
*/
|
|
32
|
+
getRandomValues(array) {
|
|
33
|
+
if (this.quickCrypto.getRandomValues) {
|
|
34
|
+
return this.quickCrypto.getRandomValues(array);
|
|
35
|
+
}
|
|
36
|
+
if (typeof global !== "undefined" && global.crypto?.getRandomValues) {
|
|
37
|
+
return global.crypto.getRandomValues(array);
|
|
38
|
+
}
|
|
39
|
+
throw new Error("react-native-quick-crypto getRandomValues is not available");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.QuickCryptoAdapter = QuickCryptoAdapter;
|
|
43
|
+
/**
|
|
44
|
+
* Check if react-native-quick-crypto is available
|
|
45
|
+
* @returns true if the module is available and functional
|
|
46
|
+
*/
|
|
47
|
+
function isQuickCryptoAvailable() {
|
|
48
|
+
try {
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
50
|
+
const quickCrypto = require("react-native-quick-crypto");
|
|
51
|
+
if (!quickCrypto || !quickCrypto.subtle || typeof quickCrypto.subtle.generateKey !== "function") {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
const hasRandomValues = typeof quickCrypto.getRandomValues === "function" ||
|
|
55
|
+
(typeof global !== "undefined" && typeof global.crypto?.getRandomValues === "function");
|
|
56
|
+
if (!hasRandomValues) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
// Ensure the native Hash implementation is actually available.
|
|
60
|
+
// In Expo Go or a misbuilt dev client, these can throw "Not implemented".
|
|
61
|
+
if (typeof quickCrypto.createHash === "function") {
|
|
62
|
+
const hash = quickCrypto.createHash("sha256");
|
|
63
|
+
hash.update("mindoodb-quick-crypto-test");
|
|
64
|
+
hash.digest();
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=QuickCryptoAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QuickCryptoAdapter.js","sourceRoot":"","sources":["../../../src/reactnative/crypto/QuickCryptoAdapter.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAuDH,wDA0BC;AArED;;;;GAIG;AACH,MAAa,kBAAkB;IAG7B,YAAY,WAA8B;QACxC,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CACb,yDAAyD;gBACzD,kFAAkF,CACnF,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,eAAe,CAAC,KAAiB;QAC/B,IAAI,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE,CAAC;YACrC,OAAO,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QACjD,CAAC;QACD,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,eAAe,EAAE,CAAC;YACpE,OAAO,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QAC9C,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;IAChF,CAAC;CACF;AAhCD,gDAgCC;AAED;;;GAGG;AACH,SAAgB,sBAAsB;IACpC,IAAI,CAAC;QACH,8DAA8D;QAC9D,MAAM,WAAW,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;QACzD,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,CAAC,MAAM,IAAI,OAAO,WAAW,CAAC,MAAM,CAAC,WAAW,KAAK,UAAU,EAAE,CAAC;YAChG,OAAO,KAAK,CAAC;QACf,CAAC;QACD,MAAM,eAAe,GACnB,OAAO,WAAW,CAAC,eAAe,KAAK,UAAU;YACjD,CAAC,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,MAAM,EAAE,eAAe,KAAK,UAAU,CAAC,CAAC;QAC1F,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,OAAO,KAAK,CAAC;QACf,CAAC;QAED,+DAA+D;QAC/D,0EAA0E;QAC1E,IAAI,OAAO,WAAW,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;YACjD,MAAM,IAAI,GAAG,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;YAC9C,IAAI,CAAC,MAAM,CAAC,4BAA4B,CAAC,CAAC;YAC1C,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RSA-OAEP Adapter
|
|
3
|
+
* Implements RSA-OAEP encryption/decryption using node-forge
|
|
4
|
+
*/
|
|
5
|
+
export interface RSAOAEPParams {
|
|
6
|
+
name: "RSA-OAEP";
|
|
7
|
+
label?: BufferSource;
|
|
8
|
+
}
|
|
9
|
+
export interface RSAKeyGenParams {
|
|
10
|
+
name: "RSA-OAEP";
|
|
11
|
+
modulusLength: number;
|
|
12
|
+
publicExponent: Uint8Array;
|
|
13
|
+
hash: "SHA-256";
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Generate RSA-OAEP key pair
|
|
17
|
+
*/
|
|
18
|
+
export declare function rsaGenerateKey(algorithm: RSAKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKeyPair>;
|
|
19
|
+
/**
|
|
20
|
+
* Import RSA key from SPKI (public) or PKCS8 (private) format
|
|
21
|
+
*/
|
|
22
|
+
export declare function rsaImportKey(format: "spki" | "pkcs8", keyData: ArrayBuffer, algorithm: {
|
|
23
|
+
name: "RSA-OAEP";
|
|
24
|
+
hash: "SHA-256";
|
|
25
|
+
}, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKey>;
|
|
26
|
+
/**
|
|
27
|
+
* Export RSA key to SPKI (public) or PKCS8 (private) format
|
|
28
|
+
*/
|
|
29
|
+
export declare function rsaExportKey(format: "spki" | "pkcs8", key: CryptoKey): Promise<ArrayBuffer>;
|
|
30
|
+
/**
|
|
31
|
+
* Encrypt data with RSA-OAEP
|
|
32
|
+
*/
|
|
33
|
+
export declare function rsaEncrypt(algorithm: RSAOAEPParams, key: CryptoKey, data: ArrayBuffer | Uint8Array): Promise<ArrayBuffer>;
|
|
34
|
+
/**
|
|
35
|
+
* Decrypt data with RSA-OAEP
|
|
36
|
+
*/
|
|
37
|
+
export declare function rsaDecrypt(algorithm: RSAOAEPParams, key: CryptoKey, data: ArrayBuffer | Uint8Array): Promise<ArrayBuffer>;
|
|
38
|
+
//# sourceMappingURL=RSAAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RSAAdapter.d.ts","sourceRoot":"","sources":["../../../src/reactnative/crypto/RSAAdapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,UAAU,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,UAAU,CAAC;IAC3B,IAAI,EAAE,SAAS,CAAC;CACjB;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,SAAS,EAAE,eAAe,EAC1B,WAAW,EAAE,OAAO,EACpB,SAAS,EAAE,QAAQ,EAAE,GACpB,OAAO,CAAC,aAAa,CAAC,CA8CxB;AAED;;GAEG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,MAAM,GAAG,OAAO,EACxB,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,SAAS,CAAA;CAAE,EAChD,WAAW,EAAE,OAAO,EACpB,SAAS,EAAE,QAAQ,EAAE,GACpB,OAAO,CAAC,SAAS,CAAC,CAmDpB;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,EAAE,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAcjG;AAED;;GAEG;AACH,wBAAsB,UAAU,CAC9B,SAAS,EAAE,aAAa,EACxB,GAAG,EAAE,SAAS,EACd,IAAI,EAAE,WAAW,GAAG,UAAU,GAC7B,OAAO,CAAC,WAAW,CAAC,CAyBtB;AAED;;GAEG;AACH,wBAAsB,UAAU,CAC9B,SAAS,EAAE,aAAa,EACxB,GAAG,EAAE,SAAS,EACd,IAAI,EAAE,WAAW,GAAG,UAAU,GAC7B,OAAO,CAAC,WAAW,CAAC,CAyBtB"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* RSA-OAEP Adapter
|
|
4
|
+
* Implements RSA-OAEP encryption/decryption using node-forge
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.rsaGenerateKey = rsaGenerateKey;
|
|
11
|
+
exports.rsaImportKey = rsaImportKey;
|
|
12
|
+
exports.rsaExportKey = rsaExportKey;
|
|
13
|
+
exports.rsaEncrypt = rsaEncrypt;
|
|
14
|
+
exports.rsaDecrypt = rsaDecrypt;
|
|
15
|
+
const node_forge_1 = __importDefault(require("node-forge"));
|
|
16
|
+
const KeyFormatConverter_1 = require("./KeyFormatConverter");
|
|
17
|
+
/**
|
|
18
|
+
* Generate RSA-OAEP key pair
|
|
19
|
+
*/
|
|
20
|
+
async function rsaGenerateKey(algorithm, extractable, keyUsages) {
|
|
21
|
+
// Convert public exponent from Uint8Array to bigint
|
|
22
|
+
// Usually [1, 0, 1] = 65537
|
|
23
|
+
let exponent = 0n;
|
|
24
|
+
for (let i = 0; i < algorithm.publicExponent.length; i++) {
|
|
25
|
+
exponent = (exponent << 8n) | BigInt(algorithm.publicExponent[i]);
|
|
26
|
+
}
|
|
27
|
+
// Generate RSA key pair using node-forge
|
|
28
|
+
const keyPair = node_forge_1.default.pki.rsa.generateKeyPair({
|
|
29
|
+
bits: algorithm.modulusLength,
|
|
30
|
+
e: Number(exponent), // Usually 65537
|
|
31
|
+
});
|
|
32
|
+
// Convert to PEM format for storage
|
|
33
|
+
const publicKeyPem = node_forge_1.default.pki.publicKeyToPem(keyPair.publicKey);
|
|
34
|
+
const privateKeyPem = node_forge_1.default.pki.privateKeyToPem(keyPair.privateKey);
|
|
35
|
+
return {
|
|
36
|
+
publicKey: {
|
|
37
|
+
type: "public",
|
|
38
|
+
extractable,
|
|
39
|
+
algorithm: {
|
|
40
|
+
name: "RSA-OAEP",
|
|
41
|
+
modulusLength: algorithm.modulusLength,
|
|
42
|
+
publicExponent: algorithm.publicExponent,
|
|
43
|
+
hash: algorithm.hash,
|
|
44
|
+
},
|
|
45
|
+
usages: keyUsages.filter((u) => u === "encrypt"),
|
|
46
|
+
_forgePublicKey: keyPair.publicKey,
|
|
47
|
+
_pemPublicKey: publicKeyPem,
|
|
48
|
+
},
|
|
49
|
+
privateKey: {
|
|
50
|
+
type: "private",
|
|
51
|
+
extractable,
|
|
52
|
+
algorithm: {
|
|
53
|
+
name: "RSA-OAEP",
|
|
54
|
+
modulusLength: algorithm.modulusLength,
|
|
55
|
+
publicExponent: algorithm.publicExponent,
|
|
56
|
+
hash: algorithm.hash,
|
|
57
|
+
},
|
|
58
|
+
usages: keyUsages.filter((u) => u === "decrypt"),
|
|
59
|
+
_forgePrivateKey: keyPair.privateKey,
|
|
60
|
+
_pemPrivateKey: privateKeyPem,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Import RSA key from SPKI (public) or PKCS8 (private) format
|
|
66
|
+
*/
|
|
67
|
+
async function rsaImportKey(format, keyData, algorithm, extractable, keyUsages) {
|
|
68
|
+
const keyBytes = new Uint8Array(keyData);
|
|
69
|
+
// Convert to PEM format for node-forge
|
|
70
|
+
const pem = (0, KeyFormatConverter_1.arrayBufferToPEM)(keyBytes.buffer, format === "spki" ? "PUBLIC KEY" : "PRIVATE KEY");
|
|
71
|
+
try {
|
|
72
|
+
if (format === "spki") {
|
|
73
|
+
const publicKey = node_forge_1.default.pki.publicKeyFromPem(pem);
|
|
74
|
+
const publicKeyPem = node_forge_1.default.pki.publicKeyToPem(publicKey);
|
|
75
|
+
// Extract modulus length from key
|
|
76
|
+
const modulusLength = publicKey.n.bitLength();
|
|
77
|
+
return {
|
|
78
|
+
type: "public",
|
|
79
|
+
extractable,
|
|
80
|
+
algorithm: {
|
|
81
|
+
name: "RSA-OAEP",
|
|
82
|
+
modulusLength,
|
|
83
|
+
publicExponent: new Uint8Array([1, 0, 1]), // Usually 65537
|
|
84
|
+
hash: algorithm.hash,
|
|
85
|
+
},
|
|
86
|
+
usages: keyUsages.filter((u) => u === "encrypt"),
|
|
87
|
+
_forgePublicKey: publicKey,
|
|
88
|
+
_pemPublicKey: publicKeyPem,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
const privateKey = node_forge_1.default.pki.privateKeyFromPem(pem);
|
|
93
|
+
const privateKeyPem = node_forge_1.default.pki.privateKeyToPem(privateKey);
|
|
94
|
+
// Extract modulus length from key
|
|
95
|
+
const modulusLength = privateKey.n.bitLength();
|
|
96
|
+
return {
|
|
97
|
+
type: "private",
|
|
98
|
+
extractable,
|
|
99
|
+
algorithm: {
|
|
100
|
+
name: "RSA-OAEP",
|
|
101
|
+
modulusLength,
|
|
102
|
+
publicExponent: new Uint8Array([1, 0, 1]), // Usually 65537
|
|
103
|
+
hash: algorithm.hash,
|
|
104
|
+
},
|
|
105
|
+
usages: keyUsages.filter((u) => u === "decrypt"),
|
|
106
|
+
_forgePrivateKey: privateKey,
|
|
107
|
+
_pemPrivateKey: privateKeyPem,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
throw new Error(`Failed to import RSA key: ${error}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Export RSA key to SPKI (public) or PKCS8 (private) format
|
|
117
|
+
*/
|
|
118
|
+
async function rsaExportKey(format, key) {
|
|
119
|
+
if (format === "spki") {
|
|
120
|
+
const pem = key._pemPublicKey;
|
|
121
|
+
if (!pem) {
|
|
122
|
+
throw new Error("Key does not contain public key material");
|
|
123
|
+
}
|
|
124
|
+
return (0, KeyFormatConverter_1.pemToArrayBuffer)(pem);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
const pem = key._pemPrivateKey;
|
|
128
|
+
if (!pem) {
|
|
129
|
+
throw new Error("Key does not contain private key material");
|
|
130
|
+
}
|
|
131
|
+
return (0, KeyFormatConverter_1.pemToArrayBuffer)(pem);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Encrypt data with RSA-OAEP
|
|
136
|
+
*/
|
|
137
|
+
async function rsaEncrypt(algorithm, key, data) {
|
|
138
|
+
const publicKey = key._forgePublicKey;
|
|
139
|
+
if (!publicKey) {
|
|
140
|
+
throw new Error("Key does not contain public key material");
|
|
141
|
+
}
|
|
142
|
+
const dataBytes = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
143
|
+
// RSA-OAEP encryption with SHA-256
|
|
144
|
+
// node-forge encrypt returns a binary string, convert to ArrayBuffer
|
|
145
|
+
const dataBuf = node_forge_1.default.util.createBuffer(dataBytes.buffer);
|
|
146
|
+
const encrypted = publicKey.encrypt(dataBuf.getBytes(), "RSA-OAEP", {
|
|
147
|
+
md: node_forge_1.default.md.sha256.create(),
|
|
148
|
+
mgf1: {
|
|
149
|
+
md: node_forge_1.default.md.sha256.create(),
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
// Convert binary string to ArrayBuffer
|
|
153
|
+
const encryptedBytes = new Uint8Array(encrypted.length);
|
|
154
|
+
for (let i = 0; i < encrypted.length; i++) {
|
|
155
|
+
encryptedBytes[i] = encrypted.charCodeAt(i) & 0xff;
|
|
156
|
+
}
|
|
157
|
+
return encryptedBytes.buffer;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Decrypt data with RSA-OAEP
|
|
161
|
+
*/
|
|
162
|
+
async function rsaDecrypt(algorithm, key, data) {
|
|
163
|
+
const privateKey = key._forgePrivateKey;
|
|
164
|
+
if (!privateKey) {
|
|
165
|
+
throw new Error("Key does not contain private key material");
|
|
166
|
+
}
|
|
167
|
+
const dataBytes = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
168
|
+
// RSA-OAEP decryption with SHA-256
|
|
169
|
+
// node-forge decrypt expects a binary string
|
|
170
|
+
const encryptedStr = node_forge_1.default.util.createBuffer(dataBytes.buffer).getBytes();
|
|
171
|
+
const decrypted = privateKey.decrypt(encryptedStr, "RSA-OAEP", {
|
|
172
|
+
md: node_forge_1.default.md.sha256.create(),
|
|
173
|
+
mgf1: {
|
|
174
|
+
md: node_forge_1.default.md.sha256.create(),
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
// Convert binary string to ArrayBuffer
|
|
178
|
+
const decryptedBytes = new Uint8Array(decrypted.length);
|
|
179
|
+
for (let i = 0; i < decrypted.length; i++) {
|
|
180
|
+
decryptedBytes[i] = decrypted.charCodeAt(i) & 0xff;
|
|
181
|
+
}
|
|
182
|
+
return decryptedBytes.buffer;
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=RSAAdapter.js.map
|
|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CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1C,cAAc,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACrD,CAAC;IAED,OAAO,cAAc,CAAC,MAAM,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Native Crypto Adapter
|
|
3
|
+
* Auto-detects and uses the best available crypto implementation:
|
|
4
|
+
* 1. react-native-quick-crypto (native, fast) - for dev builds and production
|
|
5
|
+
* 2. ExpoGoCryptoAdapter (JS-only, slower) - fallback for Expo Go
|
|
6
|
+
*/
|
|
7
|
+
import type { CryptoAdapter } from "../../core/crypto/CryptoAdapter";
|
|
8
|
+
/**
|
|
9
|
+
* React Native Crypto Adapter
|
|
10
|
+
* Automatically selects the best available crypto implementation
|
|
11
|
+
*/
|
|
12
|
+
export declare class ReactNativeCryptoAdapter implements CryptoAdapter {
|
|
13
|
+
private adapter;
|
|
14
|
+
/**
|
|
15
|
+
* Indicates whether the adapter is using native crypto (react-native-quick-crypto)
|
|
16
|
+
* or the slower JavaScript-only fallback (ExpoGoCryptoAdapter)
|
|
17
|
+
*/
|
|
18
|
+
readonly isUsingNativeCrypto: boolean;
|
|
19
|
+
constructor();
|
|
20
|
+
/**
|
|
21
|
+
* Get the SubtleCrypto interface
|
|
22
|
+
*/
|
|
23
|
+
getSubtle(): SubtleCrypto;
|
|
24
|
+
/**
|
|
25
|
+
* Get random values
|
|
26
|
+
*/
|
|
27
|
+
getRandomValues(array: Uint8Array): Uint8Array;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Factory function to create the ReactNativeCryptoAdapter
|
|
31
|
+
*/
|
|
32
|
+
export declare function createCryptoAdapter(): CryptoAdapter;
|
|
33
|
+
//# sourceMappingURL=ReactNativeCryptoAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactNativeCryptoAdapter.d.ts","sourceRoot":"","sources":["../../../src/reactnative/crypto/ReactNativeCryptoAdapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAIrE;;;GAGG;AACH,qBAAa,wBAAyB,YAAW,aAAa;IAC5D,OAAO,CAAC,OAAO,CAAgB;IAE/B;;;OAGG;IACH,SAAgB,mBAAmB,EAAE,OAAO,CAAC;;IA4B7C;;OAEG;IACH,SAAS,IAAI,YAAY;IAIzB;;OAEG;IACH,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU;CAG/C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,aAAa,CAEnD"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* React Native Crypto Adapter
|
|
4
|
+
* Auto-detects and uses the best available crypto implementation:
|
|
5
|
+
* 1. react-native-quick-crypto (native, fast) - for dev builds and production
|
|
6
|
+
* 2. ExpoGoCryptoAdapter (JS-only, slower) - fallback for Expo Go
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ReactNativeCryptoAdapter = void 0;
|
|
10
|
+
exports.createCryptoAdapter = createCryptoAdapter;
|
|
11
|
+
const ExpoGoCryptoAdapter_1 = require("./ExpoGoCryptoAdapter");
|
|
12
|
+
const QuickCryptoAdapter_1 = require("./QuickCryptoAdapter");
|
|
13
|
+
/**
|
|
14
|
+
* React Native Crypto Adapter
|
|
15
|
+
* Automatically selects the best available crypto implementation
|
|
16
|
+
*/
|
|
17
|
+
class ReactNativeCryptoAdapter {
|
|
18
|
+
constructor() {
|
|
19
|
+
// Try react-native-quick-crypto first, fall back to ExpoGoCryptoAdapter
|
|
20
|
+
if ((0, QuickCryptoAdapter_1.isQuickCryptoAvailable)()) {
|
|
21
|
+
try {
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
23
|
+
const quickCrypto = require("react-native-quick-crypto");
|
|
24
|
+
this.adapter = new QuickCryptoAdapter_1.QuickCryptoAdapter(quickCrypto);
|
|
25
|
+
this.isUsingNativeCrypto = true;
|
|
26
|
+
console.log("[MindooDB] Using react-native-quick-crypto (native crypto)");
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
// Fall through to ExpoGoCryptoAdapter
|
|
31
|
+
console.warn("[MindooDB] Failed to initialize react-native-quick-crypto:", error);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// Fallback to JS-only implementation
|
|
35
|
+
this.adapter = new ExpoGoCryptoAdapter_1.ExpoGoCryptoAdapter();
|
|
36
|
+
this.isUsingNativeCrypto = false;
|
|
37
|
+
console.warn("[MindooDB] react-native-quick-crypto not available. " +
|
|
38
|
+
"Falling back to JavaScript-only crypto (slower). " +
|
|
39
|
+
"For better performance, create a development build with react-native-quick-crypto.");
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get the SubtleCrypto interface
|
|
43
|
+
*/
|
|
44
|
+
getSubtle() {
|
|
45
|
+
return this.adapter.getSubtle();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get random values
|
|
49
|
+
*/
|
|
50
|
+
getRandomValues(array) {
|
|
51
|
+
return this.adapter.getRandomValues(array);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.ReactNativeCryptoAdapter = ReactNativeCryptoAdapter;
|
|
55
|
+
/**
|
|
56
|
+
* Factory function to create the ReactNativeCryptoAdapter
|
|
57
|
+
*/
|
|
58
|
+
function createCryptoAdapter() {
|
|
59
|
+
return new ReactNativeCryptoAdapter();
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=ReactNativeCryptoAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactNativeCryptoAdapter.js","sourceRoot":"","sources":["../../../src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HA-256 hashing using node-forge
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Compute SHA-256 digest of data
|
|
7
|
+
*/
|
|
8
|
+
export declare function sha256Digest(data: ArrayBuffer | Uint8Array): Promise<ArrayBuffer>;
|
|
9
|
+
//# sourceMappingURL=SHA256Adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SHA256Adapter.d.ts","sourceRoot":"","sources":["../../../src/reactnative/crypto/SHA256Adapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;GAEG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,CAevF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SHA-256 Digest Adapter
|
|
4
|
+
* Implements SHA-256 hashing using node-forge
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.sha256Digest = sha256Digest;
|
|
11
|
+
const node_forge_1 = __importDefault(require("node-forge"));
|
|
12
|
+
/**
|
|
13
|
+
* Compute SHA-256 digest of data
|
|
14
|
+
*/
|
|
15
|
+
async function sha256Digest(data) {
|
|
16
|
+
const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
17
|
+
const md = node_forge_1.default.md.sha256.create();
|
|
18
|
+
const dataBuf = node_forge_1.default.util.createBuffer(bytes.buffer);
|
|
19
|
+
md.update(dataBuf.getBytes());
|
|
20
|
+
const hash = md.digest();
|
|
21
|
+
// Convert hash to Uint8Array
|
|
22
|
+
const hashHex = hash.toHex();
|
|
23
|
+
const hashBytes = new Uint8Array(hashHex.length / 2);
|
|
24
|
+
for (let i = 0; i < hashBytes.length; i++) {
|
|
25
|
+
hashBytes[i] = parseInt(hashHex.substr(i * 2, 2), 16);
|
|
26
|
+
}
|
|
27
|
+
return hashBytes.buffer;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=SHA256Adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SHA256Adapter.js","sourceRoot":"","sources":["../../../src/reactnative/crypto/SHA256Adapter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;AAOH,oCAeC;AApBD,4DAA+B;AAE/B;;GAEG;AACI,KAAK,UAAU,YAAY,CAAC,IAA8B;IAC/D,MAAM,KAAK,GAAG,IAAI,YAAY,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;IACvE,MAAM,EAAE,GAAG,oBAAK,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IACpC,MAAM,OAAO,GAAG,oBAAK,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,MAAqB,CAAC,CAAC;IACrE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC9B,MAAM,IAAI,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC;IAEzB,6BAA6B;IAC7B,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;IAC7B,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACrD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1C,SAAS,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACxD,CAAC;IAED,OAAO,SAAS,CAAC,MAAM,CAAC;AAC1B,CAAC"}
|