@credo-ts/react-native 0.6.1-pr-2091-20241119140918 → 0.6.2-alpha-20251210145840
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/build/ReactNativeFileSystem.mjs +70 -0
- package/build/ReactNativeFileSystem.mjs.map +1 -0
- package/build/index.d.mts +9 -0
- package/build/index.d.mts.map +1 -0
- package/build/index.mjs +16 -0
- package/build/index.mjs.map +1 -0
- package/build/kms/SecureEnvironmentKeyManagementService.d.mts +22 -0
- package/build/kms/SecureEnvironmentKeyManagementService.d.mts.map +1 -0
- package/build/kms/SecureEnvironmentKeyManagementService.mjs +100 -0
- package/build/kms/SecureEnvironmentKeyManagementService.mjs.map +1 -0
- package/build/kms/secureEnvironment.mjs +12 -0
- package/build/kms/secureEnvironment.mjs.map +1 -0
- package/package.json +21 -15
- package/build/ReactNativeFileSystem.d.ts +0 -34
- package/build/ReactNativeFileSystem.js +0 -104
- package/build/ReactNativeFileSystem.js.map +0 -1
- package/build/index.d.ts +0 -5
- package/build/index.js +0 -17
- package/build/index.js.map +0 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Buffer, CredoError, TypedArrayEncoder, getDirFromFilePath } from "@credo-ts/core";
|
|
2
|
+
import { Platform } from "react-native";
|
|
3
|
+
import * as RNFS from "react-native-fs";
|
|
4
|
+
|
|
5
|
+
//#region src/ReactNativeFileSystem.ts
|
|
6
|
+
var ReactNativeFileSystem = class {
|
|
7
|
+
/**
|
|
8
|
+
* Create new ReactNativeFileSystem class instance.
|
|
9
|
+
*
|
|
10
|
+
* @param baseDataPath The base path to use for reading and writing data files used within the framework.
|
|
11
|
+
* Files will be created under baseDataPath/.afj directory. If not specified, it will be set to
|
|
12
|
+
* RNFS.DocumentDirectoryPath
|
|
13
|
+
* @param baseCachePath The base path to use for reading and writing cache files used within the framework.
|
|
14
|
+
* Files will be created under baseCachePath/.afj directory. If not specified, it will be set to
|
|
15
|
+
* RNFS.CachesDirectoryPath
|
|
16
|
+
* @param baseTempPath The base path to use for reading and writing temporary files within the framework.
|
|
17
|
+
* Files will be created under baseTempPath/.afj directory. If not specified, it will be set to
|
|
18
|
+
* RNFS.TemporaryDirectoryPath
|
|
19
|
+
*
|
|
20
|
+
* @see https://github.com/itinance/react-native-fs#constants
|
|
21
|
+
*/
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.dataPath = `${options?.baseDataPath ?? RNFS.DocumentDirectoryPath}/.afj`;
|
|
24
|
+
this.cachePath = options?.baseCachePath ? `${options?.baseCachePath}/.afj` : `${RNFS.CachesDirectoryPath}/.afj${Platform.OS === "android" ? "/cache" : ""}`;
|
|
25
|
+
this.tempPath = options?.baseTempPath ? `${options?.baseTempPath}/.afj` : `${RNFS.TemporaryDirectoryPath}/.afj${Platform.OS === "android" ? "/temp" : ""}`;
|
|
26
|
+
}
|
|
27
|
+
async exists(path) {
|
|
28
|
+
return RNFS.exists(path);
|
|
29
|
+
}
|
|
30
|
+
async createDirectory(path) {
|
|
31
|
+
await RNFS.mkdir(getDirFromFilePath(path));
|
|
32
|
+
}
|
|
33
|
+
async copyFile(sourcePath, destinationPath) {
|
|
34
|
+
await RNFS.copyFile(sourcePath, destinationPath);
|
|
35
|
+
}
|
|
36
|
+
async write(path, data) {
|
|
37
|
+
await RNFS.mkdir(getDirFromFilePath(path));
|
|
38
|
+
return RNFS.writeFile(path, data, "utf8");
|
|
39
|
+
}
|
|
40
|
+
async read(path) {
|
|
41
|
+
return RNFS.readFile(path, "utf8");
|
|
42
|
+
}
|
|
43
|
+
async delete(path) {
|
|
44
|
+
await RNFS.unlink(path);
|
|
45
|
+
}
|
|
46
|
+
async downloadToFile(url, path, options) {
|
|
47
|
+
await RNFS.mkdir(getDirFromFilePath(path));
|
|
48
|
+
const fromUrl = this.encodeUriIfRequired(url);
|
|
49
|
+
const { promise } = RNFS.downloadFile({
|
|
50
|
+
fromUrl,
|
|
51
|
+
toFile: path
|
|
52
|
+
});
|
|
53
|
+
await promise;
|
|
54
|
+
if (options?.verifyHash) {
|
|
55
|
+
const fileHash = await RNFS.hash(path, options.verifyHash.algorithm);
|
|
56
|
+
const fileHashBuffer = Buffer.from(fileHash, "hex");
|
|
57
|
+
if (fileHashBuffer.compare(options.verifyHash.hash) !== 0) {
|
|
58
|
+
await RNFS.unlink(path);
|
|
59
|
+
throw new CredoError(`Hash of downloaded file does not match expected hash. Expected: ${TypedArrayEncoder.toBase58(options.verifyHash.hash)}, Actual: ${TypedArrayEncoder.toBase58(fileHashBuffer)}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
encodeUriIfRequired(uri) {
|
|
64
|
+
return uri === decodeURI(uri) ? encodeURI(uri) : uri;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
export { ReactNativeFileSystem };
|
|
70
|
+
//# sourceMappingURL=ReactNativeFileSystem.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactNativeFileSystem.mjs","names":[],"sources":["../src/ReactNativeFileSystem.ts"],"sourcesContent":["import type { DownloadToFileOptions, FileSystem } from '@credo-ts/core'\n\nimport { Buffer, CredoError, getDirFromFilePath, TypedArrayEncoder } from '@credo-ts/core'\nimport { Platform } from 'react-native'\nimport * as RNFS from 'react-native-fs'\n\nexport class ReactNativeFileSystem implements FileSystem {\n public readonly dataPath\n public readonly cachePath\n public readonly tempPath\n\n /**\n * Create new ReactNativeFileSystem class instance.\n *\n * @param baseDataPath The base path to use for reading and writing data files used within the framework.\n * Files will be created under baseDataPath/.afj directory. If not specified, it will be set to\n * RNFS.DocumentDirectoryPath\n * @param baseCachePath The base path to use for reading and writing cache files used within the framework.\n * Files will be created under baseCachePath/.afj directory. If not specified, it will be set to\n * RNFS.CachesDirectoryPath\n * @param baseTempPath The base path to use for reading and writing temporary files within the framework.\n * Files will be created under baseTempPath/.afj directory. If not specified, it will be set to\n * RNFS.TemporaryDirectoryPath\n *\n * @see https://github.com/itinance/react-native-fs#constants\n */\n public constructor(options?: { baseDataPath?: string; baseCachePath?: string; baseTempPath?: string }) {\n this.dataPath = `${options?.baseDataPath ?? RNFS.DocumentDirectoryPath}/.afj`\n // In Android, TemporaryDirectoryPath falls back to CachesDirectoryPath\n this.cachePath = options?.baseCachePath\n ? `${options?.baseCachePath}/.afj`\n : `${RNFS.CachesDirectoryPath}/.afj${Platform.OS === 'android' ? '/cache' : ''}`\n this.tempPath = options?.baseTempPath\n ? `${options?.baseTempPath}/.afj`\n : `${RNFS.TemporaryDirectoryPath}/.afj${Platform.OS === 'android' ? '/temp' : ''}`\n }\n\n public async exists(path: string): Promise<boolean> {\n return RNFS.exists(path)\n }\n\n public async createDirectory(path: string): Promise<void> {\n await RNFS.mkdir(getDirFromFilePath(path))\n }\n\n public async copyFile(sourcePath: string, destinationPath: string): Promise<void> {\n await RNFS.copyFile(sourcePath, destinationPath)\n }\n\n public async write(path: string, data: string): Promise<void> {\n // Make sure parent directories exist\n await RNFS.mkdir(getDirFromFilePath(path))\n\n return RNFS.writeFile(path, data, 'utf8')\n }\n\n public async read(path: string): Promise<string> {\n return RNFS.readFile(path, 'utf8')\n }\n\n public async delete(path: string): Promise<void> {\n await RNFS.unlink(path)\n }\n\n public async downloadToFile(url: string, path: string, options?: DownloadToFileOptions) {\n // Make sure parent directories exist\n await RNFS.mkdir(getDirFromFilePath(path))\n\n const fromUrl = this.encodeUriIfRequired(url)\n\n const { promise } = RNFS.downloadFile({\n fromUrl,\n toFile: path,\n })\n\n await promise\n\n if (options?.verifyHash) {\n // RNFS returns hash as HEX\n const fileHash = await RNFS.hash(path, options.verifyHash.algorithm)\n const fileHashBuffer = Buffer.from(fileHash, 'hex')\n\n // If hash doesn't match, remove file and throw error\n if (fileHashBuffer.compare(options.verifyHash.hash) !== 0) {\n await RNFS.unlink(path)\n throw new CredoError(\n `Hash of downloaded file does not match expected hash. Expected: ${TypedArrayEncoder.toBase58(\n options.verifyHash.hash\n )}, Actual: ${TypedArrayEncoder.toBase58(fileHashBuffer)}`\n )\n }\n }\n }\n\n private encodeUriIfRequired(uri: string) {\n // Some characters in the URL might be invalid for\n // the native os to handle. Only encode if necessary.\n return uri === decodeURI(uri) ? encodeURI(uri) : uri\n }\n}\n"],"mappings":";;;;;AAMA,IAAa,wBAAb,MAAyD;;;;;;;;;;;;;;;;CAoBvD,AAAO,YAAY,SAAoF;AACrG,OAAK,WAAW,GAAG,SAAS,gBAAgB,KAAK,sBAAsB;AAEvE,OAAK,YAAY,SAAS,gBACtB,GAAG,SAAS,cAAc,SAC1B,GAAG,KAAK,oBAAoB,OAAO,SAAS,OAAO,YAAY,WAAW;AAC9E,OAAK,WAAW,SAAS,eACrB,GAAG,SAAS,aAAa,SACzB,GAAG,KAAK,uBAAuB,OAAO,SAAS,OAAO,YAAY,UAAU;;CAGlF,MAAa,OAAO,MAAgC;AAClD,SAAO,KAAK,OAAO,KAAK;;CAG1B,MAAa,gBAAgB,MAA6B;AACxD,QAAM,KAAK,MAAM,mBAAmB,KAAK,CAAC;;CAG5C,MAAa,SAAS,YAAoB,iBAAwC;AAChF,QAAM,KAAK,SAAS,YAAY,gBAAgB;;CAGlD,MAAa,MAAM,MAAc,MAA6B;AAE5D,QAAM,KAAK,MAAM,mBAAmB,KAAK,CAAC;AAE1C,SAAO,KAAK,UAAU,MAAM,MAAM,OAAO;;CAG3C,MAAa,KAAK,MAA+B;AAC/C,SAAO,KAAK,SAAS,MAAM,OAAO;;CAGpC,MAAa,OAAO,MAA6B;AAC/C,QAAM,KAAK,OAAO,KAAK;;CAGzB,MAAa,eAAe,KAAa,MAAc,SAAiC;AAEtF,QAAM,KAAK,MAAM,mBAAmB,KAAK,CAAC;EAE1C,MAAM,UAAU,KAAK,oBAAoB,IAAI;EAE7C,MAAM,EAAE,YAAY,KAAK,aAAa;GACpC;GACA,QAAQ;GACT,CAAC;AAEF,QAAM;AAEN,MAAI,SAAS,YAAY;GAEvB,MAAM,WAAW,MAAM,KAAK,KAAK,MAAM,QAAQ,WAAW,UAAU;GACpE,MAAM,iBAAiB,OAAO,KAAK,UAAU,MAAM;AAGnD,OAAI,eAAe,QAAQ,QAAQ,WAAW,KAAK,KAAK,GAAG;AACzD,UAAM,KAAK,OAAO,KAAK;AACvB,UAAM,IAAI,WACR,mEAAmE,kBAAkB,SACnF,QAAQ,WAAW,KACpB,CAAC,YAAY,kBAAkB,SAAS,eAAe,GACzD;;;;CAKP,AAAQ,oBAAoB,KAAa;AAGvC,SAAO,QAAQ,UAAU,IAAI,GAAG,UAAU,IAAI,GAAG"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SecureEnvironmentKeyManagementService } from "./kms/SecureEnvironmentKeyManagementService.mjs";
|
|
2
|
+
import "react-native-get-random-values";
|
|
3
|
+
import { AgentDependencies } from "@credo-ts/core";
|
|
4
|
+
|
|
5
|
+
//#region src/index.d.ts
|
|
6
|
+
declare const agentDependencies: AgentDependencies;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { SecureEnvironmentKeyManagementService, agentDependencies };
|
|
9
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;cAaM,mBAAmB"}
|
package/build/index.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ReactNativeFileSystem } from "./ReactNativeFileSystem.mjs";
|
|
2
|
+
import { SecureEnvironmentKeyManagementService } from "./kms/SecureEnvironmentKeyManagementService.mjs";
|
|
3
|
+
import "react-native-get-random-values";
|
|
4
|
+
import { EventEmitter } from "events";
|
|
5
|
+
|
|
6
|
+
//#region src/index.ts
|
|
7
|
+
const agentDependencies = {
|
|
8
|
+
FileSystem: ReactNativeFileSystem,
|
|
9
|
+
fetch: global.fetch,
|
|
10
|
+
EventEmitterClass: EventEmitter,
|
|
11
|
+
WebSocketClass: global.WebSocket
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { SecureEnvironmentKeyManagementService, agentDependencies };
|
|
16
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["agentDependencies: AgentDependencies"],"sources":["../src/index.ts"],"sourcesContent":["import 'react-native-get-random-values'\n\nimport type { AgentDependencies } from '@credo-ts/core'\n\nimport { EventEmitter } from 'events'\n\nimport { ReactNativeFileSystem } from './ReactNativeFileSystem'\n\nexport { SecureEnvironmentKeyManagementService } from './kms/SecureEnvironmentKeyManagementService'\n\nconst fetch = global.fetch as unknown as AgentDependencies['fetch']\nconst WebSocket = global.WebSocket as unknown as AgentDependencies['WebSocketClass']\n\nconst agentDependencies: AgentDependencies = {\n FileSystem: ReactNativeFileSystem,\n fetch,\n EventEmitterClass: EventEmitter,\n WebSocketClass: WebSocket,\n}\n\nexport { agentDependencies }\n"],"mappings":";;;;;;AAaA,MAAMA,oBAAuC;CAC3C,YAAY;CACZ,OALY,OAAO;CAMnB,mBAAmB;CACnB,gBANgB,OAAO;CAOxB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AgentContext, Kms } from "@credo-ts/core";
|
|
2
|
+
|
|
3
|
+
//#region src/kms/SecureEnvironmentKeyManagementService.d.ts
|
|
4
|
+
declare class SecureEnvironmentKeyManagementService implements Kms.KeyManagementService {
|
|
5
|
+
readonly backend = "secureEnvironment";
|
|
6
|
+
private readonly secureEnvironment;
|
|
7
|
+
isOperationSupported(_agentContext: AgentContext, operation: Kms.KmsOperation): boolean;
|
|
8
|
+
randomBytes(_agentContext: AgentContext, _options: Kms.KmsRandomBytesOptions): Kms.KmsRandomBytesReturn;
|
|
9
|
+
getPublicKey(_agentContext: AgentContext, keyId: string): Promise<Kms.KmsJwkPublic | null>;
|
|
10
|
+
importKey(): Promise<Kms.KmsImportKeyReturn<Kms.KmsJwkPrivate>>;
|
|
11
|
+
deleteKey(_agentContext: AgentContext, options: Kms.KmsDeleteKeyOptions): Promise<boolean>;
|
|
12
|
+
encrypt(): Promise<Kms.KmsEncryptReturn>;
|
|
13
|
+
decrypt(): Promise<Kms.KmsDecryptReturn>;
|
|
14
|
+
createKey(_agentContext: AgentContext, options: Kms.KmsCreateKeyOptions): Promise<Kms.KmsCreateKeyReturn>;
|
|
15
|
+
sign(_agentContext: AgentContext, options: Kms.KmsSignOptions): Promise<Kms.KmsSignReturn>;
|
|
16
|
+
verify(): Promise<Kms.KmsVerifyReturn>;
|
|
17
|
+
private publicJwkFromPublicKeyBytes;
|
|
18
|
+
private getKeyAsserted;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { SecureEnvironmentKeyManagementService };
|
|
22
|
+
//# sourceMappingURL=SecureEnvironmentKeyManagementService.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SecureEnvironmentKeyManagementService.d.mts","names":[],"sources":["../../src/kms/SecureEnvironmentKeyManagementService.ts"],"sourcesContent":[],"mappings":";;;cAMa,qCAAA,YAAiD,GAAA,CAAI;EAArD,SAAA,OAAA,GAAA,mBAAA;EAIgC,iBAAA,iBAAA;EAAyB,oBAAI,CAAA,aAAA,EAA7B,YAA6B,EAAA,SAAA,EAAJ,GAAA,CAAI,YAAA,CAAA,EAAA,OAAA;EAgBtC,WAAA,CAAA,aAAA,EAAA,YAAA,EAAA,QAAA,EAAwB,GAAA,CAAI,qBAA5B,CAAA,EAAoD,GAAA,CAAI,oBAAxD;EAAwB,YAAI,CAAA,aAAA,EAIrB,YAJqB,EAAA,KAAA,EAAA,MAAA,CAAA,EAIS,OAJT,CAIiB,GAAA,CAAI,YAJrB,GAAA,IAAA,CAAA;EAAwB,SAAI,CAAA,CAAA,EAahE,OAbgE,CAaxD,GAAA,CAAI,kBAboD,CAajC,GAAA,CAAI,aAb6B,CAAA,CAAA;EAIjD,SAAA,CAAA,aAAA,EAaH,YAbG,EAAA,OAAA,EAaoB,GAAA,CAAI,mBAbxB,CAAA,EAa8C,OAb9C,CAAA,OAAA,CAAA;EAAsC,OAAI,CAAA,CAAA,EA6B3D,OA7B2D,CA6BnD,GAAA,CAAI,gBA7B+C,CAAA;EAAZ,OAAA,CAAA,CAAA,EAiC/C,OAjC+C,CAiCvC,GAAA,CAAI,gBAjCmC,CAAA;EASd,SAAI,CAAA,aAAA,EA6B5C,YA7B4C,EAAA,OAAA,EA8BlD,GAAA,CAAI,mBA9B8C,CAAA,EA+B1D,OA/B0D,CA+BlD,GAAA,CAAI,kBA/B8C,CAAA;EAA3B,IAAI,CAAA,aAAA,EAiEL,YAjEK,EAAA,OAAA,EAiEkB,GAAA,CAAI,cAjEtB,CAAA,EAiEuC,OAjEvC,CAiE+C,GAAA,CAAI,aAjEnD,CAAA;EAAZ,MAAA,CAAA,CAAA,EA8FH,OA9FG,CA8FK,GAAA,CAAI,eA9FT,CAAA;EAIY,QAAA,2BAAA;EAAuB,QAAI,cAAA"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { importSecureEnvironment } from "./secureEnvironment.mjs";
|
|
2
|
+
import { Kms, utils } from "@credo-ts/core";
|
|
3
|
+
|
|
4
|
+
//#region src/kms/SecureEnvironmentKeyManagementService.ts
|
|
5
|
+
var SecureEnvironmentKeyManagementService = class {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.backend = "secureEnvironment";
|
|
8
|
+
this.secureEnvironment = importSecureEnvironment();
|
|
9
|
+
}
|
|
10
|
+
isOperationSupported(_agentContext, operation) {
|
|
11
|
+
if (operation.operation === "createKey") return operation.type.kty === "EC" && operation.type.crv === "P-256";
|
|
12
|
+
if (operation.operation === "sign") return operation.algorithm === "ES256";
|
|
13
|
+
if (operation.operation === "deleteKey") return true;
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
randomBytes(_agentContext, _options) {
|
|
17
|
+
throw new Kms.KeyManagementError(`Generating random bytes is not supported for backend '${this.backend}'`);
|
|
18
|
+
}
|
|
19
|
+
async getPublicKey(_agentContext, keyId) {
|
|
20
|
+
try {
|
|
21
|
+
return await this.getKeyAsserted(keyId);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
if (error instanceof Kms.KeyManagementKeyNotFoundError) return null;
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async importKey() {
|
|
28
|
+
throw new Kms.KeyManagementError(`Importing a key is not supported for backend '${this.backend}'`);
|
|
29
|
+
}
|
|
30
|
+
async deleteKey(_agentContext, options) {
|
|
31
|
+
const secureEnvironment = await this.secureEnvironment;
|
|
32
|
+
try {
|
|
33
|
+
await secureEnvironment.deleteKey(options.keyId);
|
|
34
|
+
return true;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (error instanceof secureEnvironment.KeyNotFoundError) return false;
|
|
37
|
+
throw new Kms.KeyManagementError(`Error deleting key with id '${options.keyId}' in backend '${this.backend}'`, { cause: error });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async encrypt() {
|
|
41
|
+
throw new Kms.KeyManagementError(`Encryption is not supported for backend '${this.backend}'`);
|
|
42
|
+
}
|
|
43
|
+
async decrypt() {
|
|
44
|
+
throw new Kms.KeyManagementError(`Decryption is not supported for backend '${this.backend}'`);
|
|
45
|
+
}
|
|
46
|
+
async createKey(_agentContext, options) {
|
|
47
|
+
if (options.type.kty !== "EC") throw new Kms.KeyManagementAlgorithmNotSupportedError(`kty ${options.type.kty}. Only EC P-256 supported.`, this.backend);
|
|
48
|
+
if (options.type.crv !== "P-256") throw new Kms.KeyManagementAlgorithmNotSupportedError(`kty ${options.type.kty} with crv ${options.type.crv}. Only EC P-256 supported.`, this.backend);
|
|
49
|
+
const keyId = options.keyId ?? utils.uuid();
|
|
50
|
+
const secureEnvironment = await this.secureEnvironment;
|
|
51
|
+
try {
|
|
52
|
+
await secureEnvironment.generateKeypair(keyId);
|
|
53
|
+
return {
|
|
54
|
+
keyId,
|
|
55
|
+
publicJwk: await this.getKeyAsserted(keyId)
|
|
56
|
+
};
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (error instanceof Kms.KeyManagementError) throw error;
|
|
59
|
+
if (error instanceof secureEnvironment.KeyAlreadyExistsError) throw new Kms.KeyManagementKeyExistsError(keyId, this.backend);
|
|
60
|
+
throw new Kms.KeyManagementError("Error creating key", { cause: error });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async sign(_agentContext, options) {
|
|
64
|
+
if (options.algorithm !== "ES256") throw new Kms.KeyManagementAlgorithmNotSupportedError(`algorithm '${options.algorithm}'. Only 'ES256' supported.`, this.backend);
|
|
65
|
+
const secureEnvironment = await this.secureEnvironment;
|
|
66
|
+
try {
|
|
67
|
+
return { signature: await secureEnvironment.sign(options.keyId, options.data) };
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (error instanceof secureEnvironment.KeyNotFoundError) throw new Kms.KeyManagementKeyNotFoundError(options.keyId, [this.backend]);
|
|
70
|
+
throw new Kms.KeyManagementError("Error signing with key", { cause: error });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async verify() {
|
|
74
|
+
throw new Kms.KeyManagementError(`verification of signatures is not supported for backend '${this.backend}'`);
|
|
75
|
+
}
|
|
76
|
+
publicJwkFromPublicKeyBytes(key, keyId) {
|
|
77
|
+
return {
|
|
78
|
+
...Kms.PublicJwk.fromPublicKey({
|
|
79
|
+
kty: "EC",
|
|
80
|
+
crv: "P-256",
|
|
81
|
+
publicKey: key
|
|
82
|
+
}).toJson(),
|
|
83
|
+
kid: keyId
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
async getKeyAsserted(keyId) {
|
|
87
|
+
const secureEnvironment = await this.secureEnvironment;
|
|
88
|
+
try {
|
|
89
|
+
const publicKeyBytes = await secureEnvironment.getPublicBytesForKeyId(keyId);
|
|
90
|
+
return this.publicJwkFromPublicKeyBytes(publicKeyBytes, keyId);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
if (error instanceof secureEnvironment.KeyNotFoundError) throw new Kms.KeyManagementKeyNotFoundError(keyId, [this.backend]);
|
|
93
|
+
throw new Kms.KeyManagementError(`Error retrieving key with id '${keyId}' from backend ${this.backend}`, { cause: error });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
99
|
+
export { SecureEnvironmentKeyManagementService };
|
|
100
|
+
//# sourceMappingURL=SecureEnvironmentKeyManagementService.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SecureEnvironmentKeyManagementService.mjs","names":[],"sources":["../../src/kms/SecureEnvironmentKeyManagementService.ts"],"sourcesContent":["import type { AgentContext, AnyUint8Array, Uint8ArrayBuffer } from '@credo-ts/core'\n\nimport { Kms, utils } from '@credo-ts/core'\n\nimport { importSecureEnvironment } from './secureEnvironment'\n\nexport class SecureEnvironmentKeyManagementService implements Kms.KeyManagementService {\n public readonly backend = 'secureEnvironment'\n private readonly secureEnvironment = importSecureEnvironment()\n\n public isOperationSupported(_agentContext: AgentContext, operation: Kms.KmsOperation): boolean {\n if (operation.operation === 'createKey') {\n return operation.type.kty === 'EC' && operation.type.crv === 'P-256'\n }\n\n if (operation.operation === 'sign') {\n return operation.algorithm === 'ES256'\n }\n\n if (operation.operation === 'deleteKey') {\n return true\n }\n\n return false\n }\n\n public randomBytes(_agentContext: AgentContext, _options: Kms.KmsRandomBytesOptions): Kms.KmsRandomBytesReturn {\n throw new Kms.KeyManagementError(`Generating random bytes is not supported for backend '${this.backend}'`)\n }\n\n public async getPublicKey(_agentContext: AgentContext, keyId: string): Promise<Kms.KmsJwkPublic | null> {\n try {\n return await this.getKeyAsserted(keyId)\n } catch (error) {\n if (error instanceof Kms.KeyManagementKeyNotFoundError) return null\n throw error\n }\n }\n\n public async importKey(): Promise<Kms.KmsImportKeyReturn<Kms.KmsJwkPrivate>> {\n throw new Kms.KeyManagementError(`Importing a key is not supported for backend '${this.backend}'`)\n }\n\n public async deleteKey(_agentContext: AgentContext, options: Kms.KmsDeleteKeyOptions): Promise<boolean> {\n const secureEnvironment = await this.secureEnvironment\n try {\n await secureEnvironment.deleteKey(options.keyId)\n return true\n } catch (error) {\n if (error instanceof secureEnvironment.KeyNotFoundError) {\n return false\n }\n\n throw new Kms.KeyManagementError(`Error deleting key with id '${options.keyId}' in backend '${this.backend}'`, {\n cause: error,\n })\n }\n }\n\n public async encrypt(): Promise<Kms.KmsEncryptReturn> {\n throw new Kms.KeyManagementError(`Encryption is not supported for backend '${this.backend}'`)\n }\n\n public async decrypt(): Promise<Kms.KmsDecryptReturn> {\n throw new Kms.KeyManagementError(`Decryption is not supported for backend '${this.backend}'`)\n }\n\n public async createKey(\n _agentContext: AgentContext,\n options: Kms.KmsCreateKeyOptions\n ): Promise<Kms.KmsCreateKeyReturn> {\n if (options.type.kty !== 'EC') {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `kty ${options.type.kty}. Only EC P-256 supported.`,\n this.backend\n )\n }\n if (options.type.crv !== 'P-256') {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `kty ${options.type.kty} with crv ${options.type.crv}. Only EC P-256 supported.`,\n this.backend\n )\n }\n\n const keyId = options.keyId ?? utils.uuid()\n const secureEnvironment = await this.secureEnvironment\n\n try {\n await secureEnvironment.generateKeypair(keyId)\n\n return {\n keyId,\n publicJwk: await this.getKeyAsserted(keyId),\n }\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n if (error instanceof secureEnvironment.KeyAlreadyExistsError) {\n throw new Kms.KeyManagementKeyExistsError(keyId, this.backend)\n }\n\n throw new Kms.KeyManagementError('Error creating key', { cause: error })\n }\n }\n\n public async sign(_agentContext: AgentContext, options: Kms.KmsSignOptions): Promise<Kms.KmsSignReturn> {\n if (options.algorithm !== 'ES256') {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `algorithm '${options.algorithm}'. Only 'ES256' supported.`,\n this.backend\n )\n }\n\n const secureEnvironment = await this.secureEnvironment\n\n try {\n // TODO: can we store something like 'use' for the key in secure environment?\n // Kms.assertKeyAllowsSign(publicJwk)\n\n // Perform the signing operation\n const signature = (await secureEnvironment.sign(options.keyId, options.data)) as Uint8ArrayBuffer\n\n return {\n signature,\n }\n } catch (error) {\n if (error instanceof secureEnvironment.KeyNotFoundError) {\n throw new Kms.KeyManagementKeyNotFoundError(options.keyId, [this.backend])\n }\n\n throw new Kms.KeyManagementError('Error signing with key', { cause: error })\n }\n }\n\n public async verify(): Promise<Kms.KmsVerifyReturn> {\n throw new Kms.KeyManagementError(`verification of signatures is not supported for backend '${this.backend}'`)\n }\n\n private publicJwkFromPublicKeyBytes(key: AnyUint8Array, keyId: string) {\n const publicJwk = Kms.PublicJwk.fromPublicKey<Kms.P256PublicJwk['publicKey']>({\n kty: 'EC',\n crv: 'P-256',\n publicKey: key,\n }).toJson()\n\n return {\n ...publicJwk,\n kid: keyId,\n } satisfies Kms.KmsJwkPublicEc\n }\n\n private async getKeyAsserted(keyId: string) {\n const secureEnvironment = await this.secureEnvironment\n\n try {\n const publicKeyBytes = (await secureEnvironment.getPublicBytesForKeyId(keyId)) as Uint8ArrayBuffer\n return this.publicJwkFromPublicKeyBytes(publicKeyBytes, keyId)\n } catch (error) {\n if (error instanceof secureEnvironment.KeyNotFoundError) {\n throw new Kms.KeyManagementKeyNotFoundError(keyId, [this.backend])\n }\n\n throw new Kms.KeyManagementError(`Error retrieving key with id '${keyId}' from backend ${this.backend}`, {\n cause: error,\n })\n }\n }\n}\n"],"mappings":";;;;AAMA,IAAa,wCAAb,MAAuF;;OACrE,UAAU;OACT,oBAAoB,yBAAyB;;CAE9D,AAAO,qBAAqB,eAA6B,WAAsC;AAC7F,MAAI,UAAU,cAAc,YAC1B,QAAO,UAAU,KAAK,QAAQ,QAAQ,UAAU,KAAK,QAAQ;AAG/D,MAAI,UAAU,cAAc,OAC1B,QAAO,UAAU,cAAc;AAGjC,MAAI,UAAU,cAAc,YAC1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O,OACR,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/kms/secureEnvironment.ts
|
|
2
|
+
async function importSecureEnvironment() {
|
|
3
|
+
try {
|
|
4
|
+
return await import("@animo-id/expo-secure-environment");
|
|
5
|
+
} catch (_error) {
|
|
6
|
+
throw new Error("@animo-id/expo-secure-environment must be installed as a peer dependency");
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { importSecureEnvironment };
|
|
12
|
+
//# sourceMappingURL=secureEnvironment.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secureEnvironment.mjs","names":[],"sources":["../../src/kms/secureEnvironment.ts"],"sourcesContent":["export async function importSecureEnvironment() {\n try {\n const secureEnvironment = await import('@animo-id/expo-secure-environment')\n return secureEnvironment\n } catch (_error) {\n throw new Error('@animo-id/expo-secure-environment must be installed as a peer dependency')\n }\n}\n"],"mappings":";AAAA,eAAsB,0BAA0B;AAC9C,KAAI;AAEF,SAD0B,MAAM,OAAO;UAEhC,QAAQ;AACf,QAAM,IAAI,MAAM,2EAA2E"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@credo-ts/react-native",
|
|
3
|
-
"
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
"exports": {
|
|
4
|
+
".": "./build/index.mjs",
|
|
5
|
+
"./package.json": "./package.json"
|
|
6
|
+
},
|
|
7
|
+
"version": "0.6.2-alpha-20251210145840",
|
|
6
8
|
"files": [
|
|
7
9
|
"build"
|
|
8
10
|
],
|
|
@@ -17,26 +19,30 @@
|
|
|
17
19
|
"directory": "packages/react-native"
|
|
18
20
|
},
|
|
19
21
|
"dependencies": {
|
|
20
|
-
"@azure/core-asynciterator-polyfill": "^1.0.2",
|
|
21
22
|
"events": "^3.3.0",
|
|
22
|
-
"@credo-ts/core": "0.6.
|
|
23
|
+
"@credo-ts/core": "0.6.2-alpha-20251210145840"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
|
-
"react-native": "^0.
|
|
26
|
+
"react-native": "^0.82.1",
|
|
26
27
|
"react-native-fs": "^2.20.0",
|
|
27
|
-
"react-native-get-random-values": "^
|
|
28
|
-
"
|
|
29
|
-
"typescript": "~5.5.2"
|
|
28
|
+
"react-native-get-random-values": "^2.0.0",
|
|
29
|
+
"typescript": "~5.9.3"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
+
"@animo-id/expo-secure-environment": "^0.1.1",
|
|
33
|
+
"expo-crypto": "^15.0.7",
|
|
32
34
|
"react-native": ">=0.71.4",
|
|
33
35
|
"react-native-fs": "^2.20.0",
|
|
34
|
-
"react-native-get-random-values": "
|
|
36
|
+
"react-native-get-random-values": ">=1.11.0 <3.0.0"
|
|
37
|
+
},
|
|
38
|
+
"peerDependenciesMeta": {
|
|
39
|
+
"@animo-id/expo-secure-environment": {
|
|
40
|
+
"optional": true
|
|
41
|
+
}
|
|
35
42
|
},
|
|
36
43
|
"scripts": {
|
|
37
|
-
"build": "
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
44
|
+
"build": "tsdown --config-loader unconfig"
|
|
45
|
+
},
|
|
46
|
+
"types": "./build/index.d.mts",
|
|
47
|
+
"module": "./build/index.mjs"
|
|
42
48
|
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { FileSystem, DownloadToFileOptions } from '@credo-ts/core';
|
|
2
|
-
export declare class ReactNativeFileSystem implements FileSystem {
|
|
3
|
-
readonly dataPath: string;
|
|
4
|
-
readonly cachePath: string;
|
|
5
|
-
readonly tempPath: string;
|
|
6
|
-
/**
|
|
7
|
-
* Create new ReactNativeFileSystem class instance.
|
|
8
|
-
*
|
|
9
|
-
* @param baseDataPath The base path to use for reading and writing data files used within the framework.
|
|
10
|
-
* Files will be created under baseDataPath/.afj directory. If not specified, it will be set to
|
|
11
|
-
* RNFS.DocumentDirectoryPath
|
|
12
|
-
* @param baseCachePath The base path to use for reading and writing cache files used within the framework.
|
|
13
|
-
* Files will be created under baseCachePath/.afj directory. If not specified, it will be set to
|
|
14
|
-
* RNFS.CachesDirectoryPath
|
|
15
|
-
* @param baseTempPath The base path to use for reading and writing temporary files within the framework.
|
|
16
|
-
* Files will be created under baseTempPath/.afj directory. If not specified, it will be set to
|
|
17
|
-
* RNFS.TemporaryDirectoryPath
|
|
18
|
-
*
|
|
19
|
-
* @see https://github.com/itinance/react-native-fs#constants
|
|
20
|
-
*/
|
|
21
|
-
constructor(options?: {
|
|
22
|
-
baseDataPath?: string;
|
|
23
|
-
baseCachePath?: string;
|
|
24
|
-
baseTempPath?: string;
|
|
25
|
-
});
|
|
26
|
-
exists(path: string): Promise<boolean>;
|
|
27
|
-
createDirectory(path: string): Promise<void>;
|
|
28
|
-
copyFile(sourcePath: string, destinationPath: string): Promise<void>;
|
|
29
|
-
write(path: string, data: string): Promise<void>;
|
|
30
|
-
read(path: string): Promise<string>;
|
|
31
|
-
delete(path: string): Promise<void>;
|
|
32
|
-
downloadToFile(url: string, path: string, options?: DownloadToFileOptions): Promise<void>;
|
|
33
|
-
private encodeUriIfRequired;
|
|
34
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.ReactNativeFileSystem = void 0;
|
|
27
|
-
const core_1 = require("@credo-ts/core");
|
|
28
|
-
const react_native_1 = require("react-native");
|
|
29
|
-
const RNFS = __importStar(require("react-native-fs"));
|
|
30
|
-
class ReactNativeFileSystem {
|
|
31
|
-
/**
|
|
32
|
-
* Create new ReactNativeFileSystem class instance.
|
|
33
|
-
*
|
|
34
|
-
* @param baseDataPath The base path to use for reading and writing data files used within the framework.
|
|
35
|
-
* Files will be created under baseDataPath/.afj directory. If not specified, it will be set to
|
|
36
|
-
* RNFS.DocumentDirectoryPath
|
|
37
|
-
* @param baseCachePath The base path to use for reading and writing cache files used within the framework.
|
|
38
|
-
* Files will be created under baseCachePath/.afj directory. If not specified, it will be set to
|
|
39
|
-
* RNFS.CachesDirectoryPath
|
|
40
|
-
* @param baseTempPath The base path to use for reading and writing temporary files within the framework.
|
|
41
|
-
* Files will be created under baseTempPath/.afj directory. If not specified, it will be set to
|
|
42
|
-
* RNFS.TemporaryDirectoryPath
|
|
43
|
-
*
|
|
44
|
-
* @see https://github.com/itinance/react-native-fs#constants
|
|
45
|
-
*/
|
|
46
|
-
constructor(options) {
|
|
47
|
-
var _a;
|
|
48
|
-
this.dataPath = `${(_a = options === null || options === void 0 ? void 0 : options.baseDataPath) !== null && _a !== void 0 ? _a : RNFS.DocumentDirectoryPath}/.afj`;
|
|
49
|
-
// In Android, TemporaryDirectoryPath falls back to CachesDirectoryPath
|
|
50
|
-
this.cachePath = (options === null || options === void 0 ? void 0 : options.baseCachePath)
|
|
51
|
-
? `${options === null || options === void 0 ? void 0 : options.baseCachePath}/.afj`
|
|
52
|
-
: `${RNFS.CachesDirectoryPath}/.afj${react_native_1.Platform.OS === 'android' ? '/cache' : ''}`;
|
|
53
|
-
this.tempPath = (options === null || options === void 0 ? void 0 : options.baseTempPath)
|
|
54
|
-
? `${options === null || options === void 0 ? void 0 : options.baseTempPath}/.afj`
|
|
55
|
-
: `${RNFS.TemporaryDirectoryPath}/.afj${react_native_1.Platform.OS === 'android' ? '/temp' : ''}`;
|
|
56
|
-
}
|
|
57
|
-
async exists(path) {
|
|
58
|
-
return RNFS.exists(path);
|
|
59
|
-
}
|
|
60
|
-
async createDirectory(path) {
|
|
61
|
-
await RNFS.mkdir((0, core_1.getDirFromFilePath)(path));
|
|
62
|
-
}
|
|
63
|
-
async copyFile(sourcePath, destinationPath) {
|
|
64
|
-
await RNFS.copyFile(sourcePath, destinationPath);
|
|
65
|
-
}
|
|
66
|
-
async write(path, data) {
|
|
67
|
-
// Make sure parent directories exist
|
|
68
|
-
await RNFS.mkdir((0, core_1.getDirFromFilePath)(path));
|
|
69
|
-
return RNFS.writeFile(path, data, 'utf8');
|
|
70
|
-
}
|
|
71
|
-
async read(path) {
|
|
72
|
-
return RNFS.readFile(path, 'utf8');
|
|
73
|
-
}
|
|
74
|
-
async delete(path) {
|
|
75
|
-
await RNFS.unlink(path);
|
|
76
|
-
}
|
|
77
|
-
async downloadToFile(url, path, options) {
|
|
78
|
-
// Make sure parent directories exist
|
|
79
|
-
await RNFS.mkdir((0, core_1.getDirFromFilePath)(path));
|
|
80
|
-
const fromUrl = this.encodeUriIfRequired(url);
|
|
81
|
-
const { promise } = RNFS.downloadFile({
|
|
82
|
-
fromUrl,
|
|
83
|
-
toFile: path,
|
|
84
|
-
});
|
|
85
|
-
await promise;
|
|
86
|
-
if (options === null || options === void 0 ? void 0 : options.verifyHash) {
|
|
87
|
-
// RNFS returns hash as HEX
|
|
88
|
-
const fileHash = await RNFS.hash(path, options.verifyHash.algorithm);
|
|
89
|
-
const fileHashBuffer = core_1.Buffer.from(fileHash, 'hex');
|
|
90
|
-
// If hash doesn't match, remove file and throw error
|
|
91
|
-
if (fileHashBuffer.compare(options.verifyHash.hash) !== 0) {
|
|
92
|
-
await RNFS.unlink(path);
|
|
93
|
-
throw new core_1.CredoError(`Hash of downloaded file does not match expected hash. Expected: ${core_1.TypedArrayEncoder.toBase58(options.verifyHash.hash)}, Actual: ${core_1.TypedArrayEncoder.toBase58(fileHashBuffer)}`);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
encodeUriIfRequired(uri) {
|
|
98
|
-
// Some characters in the URL might be invalid for
|
|
99
|
-
// the native os to handle. Only encode if necessary.
|
|
100
|
-
return uri === decodeURI(uri) ? encodeURI(uri) : uri;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
exports.ReactNativeFileSystem = ReactNativeFileSystem;
|
|
104
|
-
//# sourceMappingURL=ReactNativeFileSystem.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ReactNativeFileSystem.js","sourceRoot":"","sources":["../src/ReactNativeFileSystem.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,yCAA0F;AAC1F,+CAAuC;AACvC,sDAAuC;AAEvC,MAAa,qBAAqB;IAKhC;;;;;;;;;;;;;;OAcG;IACH,YAAmB,OAAkF;;QACnG,IAAI,CAAC,QAAQ,GAAG,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,mCAAI,IAAI,CAAC,qBAAqB,OAAO,CAAA;QAC7E,uEAAuE;QACvE,IAAI,CAAC,SAAS,GAAG,CAAA,OAAO,aAAP,OAAO,uB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AAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAA;IACtD,CAAC;CACF;AA7FD,sDA6FC"}
|
package/build/index.d.ts
DELETED
package/build/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.agentDependencies = void 0;
|
|
4
|
-
require("react-native-get-random-values");
|
|
5
|
-
require("@azure/core-asynciterator-polyfill");
|
|
6
|
-
const events_1 = require("events");
|
|
7
|
-
const ReactNativeFileSystem_1 = require("./ReactNativeFileSystem");
|
|
8
|
-
const fetch = global.fetch;
|
|
9
|
-
const WebSocket = global.WebSocket;
|
|
10
|
-
const agentDependencies = {
|
|
11
|
-
FileSystem: ReactNativeFileSystem_1.ReactNativeFileSystem,
|
|
12
|
-
fetch,
|
|
13
|
-
EventEmitterClass: events_1.EventEmitter,
|
|
14
|
-
WebSocketClass: WebSocket,
|
|
15
|
-
};
|
|
16
|
-
exports.agentDependencies = agentDependencies;
|
|
17
|
-
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,0CAAuC;AACvC,8CAA2C;AAI3C,mCAAqC;AAErC,mEAA+D;AAE/D,MAAM,KAAK,GAAG,MAAM,CAAC,KAA8C,CAAA;AACnE,MAAM,SAAS,GAAG,MAAM,CAAC,SAA2D,CAAA;AAEpF,MAAM,iBAAiB,GAAsB;IAC3C,UAAU,EAAE,6CAAqB;IACjC,KAAK;IACL,iBAAiB,EAAE,qBAAY;IAC/B,cAAc,EAAE,SAAS;CAC1B,CAAA;AAEQ,8CAAiB"}
|