@credo-ts/react-native 0.7.0-alpha-20260218222221 → 0.7.0-alpha-20260401141348

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.
@@ -1,8 +1,9 @@
1
- import { Buffer, CredoError, TypedArrayEncoder, getDirFromFilePath } from "@credo-ts/core";
1
+ import { rnfs } from "./rnfs.mjs";
2
+ import { CredoError, TypedArrayEncoder, getDirFromFilePath } from "@credo-ts/core";
2
3
  import { Platform } from "react-native";
3
- import * as RNFS from "react-native-fs";
4
4
 
5
5
  //#region src/ReactNativeFileSystem.ts
6
+ const RNFS = rnfs();
6
7
  var ReactNativeFileSystem = class {
7
8
  /**
8
9
  * Create new ReactNativeFileSystem class instance.
@@ -17,7 +18,7 @@ var ReactNativeFileSystem = class {
17
18
  * Files will be created under baseTempPath/.afj directory. If not specified, it will be set to
18
19
  * RNFS.TemporaryDirectoryPath
19
20
  *
20
- * @see https://github.com/itinance/react-native-fs#constants
21
+ * @see https://github.com/birdofpreyru/react-native-fs#constants
21
22
  */
22
23
  constructor(options) {
23
24
  this.dataPath = `${options?.baseDataPath ?? RNFS.DocumentDirectoryPath}/.afj`;
@@ -53,8 +54,8 @@ var ReactNativeFileSystem = class {
53
54
  await promise;
54
55
  if (options?.verifyHash) {
55
56
  const fileHash = await RNFS.hash(path, options.verifyHash.algorithm);
56
- const fileHashBuffer = Buffer.from(fileHash, "hex");
57
- if (fileHashBuffer.compare(options.verifyHash.hash) !== 0) {
57
+ const fileHashBuffer = TypedArrayEncoder.fromHex(fileHash);
58
+ if (!TypedArrayEncoder.equals(fileHashBuffer, options.verifyHash.hash)) {
58
59
  await RNFS.unlink(path);
59
60
  throw new CredoError(`Hash of downloaded file does not match expected hash. Expected: ${TypedArrayEncoder.toBase58(options.verifyHash.hash)}, Actual: ${TypedArrayEncoder.toBase58(fileHashBuffer)}`);
60
61
  }
@@ -1 +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"}
1
+ {"version":3,"file":"ReactNativeFileSystem.mjs","names":[],"sources":["../src/ReactNativeFileSystem.ts"],"sourcesContent":["import type { DownloadToFileOptions, FileSystem } from '@credo-ts/core'\nimport { CredoError, getDirFromFilePath, TypedArrayEncoder } from '@credo-ts/core'\nimport { Platform } from 'react-native'\nimport { rnfs } from './rnfs'\n\nconst RNFS = rnfs()\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/birdofpreyru/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 = TypedArrayEncoder.fromHex(fileHash)\n\n // If hash doesn't match, remove file and throw error\n if (!TypedArrayEncoder.equals(fileHashBuffer, options.verifyHash.hash)) {\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":";;;;;AAKA,MAAM,OAAO,MAAM;AAEnB,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,kBAAkB,QAAQ,SAAS;AAG1D,OAAI,CAAC,kBAAkB,OAAO,gBAAgB,QAAQ,WAAW,KAAK,EAAE;AACtE,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,8 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
3
+ if (typeof require !== "undefined") return require.apply(this, arguments);
4
+ throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
5
+ });
6
+
7
+ //#endregion
8
+ export { __require };
@@ -1 +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,YAC1B,QAAO;AAGT,SAAO;;CAGT,AAAO,YAAY,eAA6B,UAA+D;AAC7G,QAAM,IAAI,IAAI,mBAAmB,yDAAyD,KAAK,QAAQ,GAAG;;CAG5G,MAAa,aAAa,eAA6B,OAAiD;AACtG,MAAI;AACF,UAAO,MAAM,KAAK,eAAe,MAAM;WAChC,OAAO;AACd,OAAI,iBAAiB,IAAI,8BAA+B,QAAO;AAC/D,SAAM;;;CAIV,MAAa,YAAgE;AAC3E,QAAM,IAAI,IAAI,mBAAmB,iDAAiD,KAAK,QAAQ,GAAG;;CAGpG,MAAa,UAAU,eAA6B,SAAoD;EACtG,MAAM,oBAAoB,MAAM,KAAK;AACrC,MAAI;AACF,SAAM,kBAAkB,UAAU,QAAQ,MAAM;AAChD,UAAO;WACA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;AACd,OAAI,iBAAiB,kBAAkB,iBACrC,OAAM,IAAI,IAAI,8BAA8B,QAAQ,OAAO,CAAC,KAAK,QAAQ,CAAC;AAG5E,SAAM,IAAI,IAAI,mBAAmB,0BAA0B,EAAE,OAAO,OAAO,CAAC;;;CAIhF,MAAa,SAAuC;AAClD,QAAM,IAAI,IAAI,mBAAmB,4DAA4D,KAAK,QAAQ,GAAG;;CAG/G,AAAQ,4BAA4B,KAAoB,OAAe;AAOrE,SAAO;GACL,GAPgB,IAAI,UAAU,cAA8C;IAC5E,KAAK;IACL,KAAK;IACL,WAAW;IACZ,CAAC,CAAC,QAAQ;GAIT,KAAK;GACN;;CAGH,MAAc,eAAe,OAAe;EAC1C,MAAM,oBAAoB,MAAM,KAAK;AAErC,MAAI;GACF,MAAM,iBAAkB,MAAM,kBAAkB,uBAAuB,MAAM;AAC7E,UAAO,KAAK,4BAA4B,gBAAgB,MAAM;WACvD,OAAO;AACd,OAAI,iBAAiB,kBAAkB,iBACrC,OAAM,IAAI,IAAI,8BAA8B,OAAO,CAAC,KAAK,QAAQ,CAAC;AAGpE,SAAM,IAAI,IAAI,mBAAmB,iCAAiC,MAAM,iBAAiB,KAAK,WAAW,EACvG,OAAO,OACR,CAAC"}
1
+ {"version":3,"file":"SecureEnvironmentKeyManagementService.mjs","names":[],"sources":["../../src/kms/SecureEnvironmentKeyManagementService.ts"],"sourcesContent":["import type { AgentContext } 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)\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: Uint8Array, 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)\n return this.publicJwkFromPublicKeyBytes(publicKeyBytes, keyId)\n } catch (error) {\n if (error instanceof secureEnvironment.KeyNotFoundError) {\n throw new Kms.KeyManagementKeyNotFoundError(keyId, [this.backend])\n }\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AIT,KAAK;GACN;;CAGH,MAAc,eAAe,OAAe;EAC1C,MAAM,oBAAoB,MAAM,KAAK;AAErC,MAAI;GACF,MAAM,iBAAiB,MAAM,kBAAkB,uBAAuB,MAAM;AAC5E,UAAO,KAAK,4BAA4B,gBAAgB,MAAM;WACvD,OAAO;AACd,OAAI,iBAAiB,kBAAkB,iBACrC,OAAM,IAAI,IAAI,8BAA8B,OAAO,CAAC,KAAK,QAAQ,CAAC;AAGpE,SAAM,IAAI,IAAI,mBAAmB,iCAAiC,MAAM,iBAAiB,KAAK,WAAW,EACvG,OAAO,OACR,CAAC"}
package/build/rnfs.mjs ADDED
@@ -0,0 +1,17 @@
1
+
2
+ //#region src/rnfs.ts
3
+ const rnfs = () => {
4
+ try {
5
+ return require("@dr.pogodin/react-native-fs");
6
+ } catch {
7
+ try {
8
+ return require("react-native-fs");
9
+ } catch {
10
+ throw new Error(`Could not find '@dr.pogodin/react-native-fs' or 'react-native-fs' as a peerDependency. Make sure to add either one of them`);
11
+ }
12
+ }
13
+ };
14
+
15
+ //#endregion
16
+ export { rnfs };
17
+ //# sourceMappingURL=rnfs.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rnfs.mjs","names":[],"sources":["../src/rnfs.ts"],"sourcesContent":["export const rnfs = () => {\n try {\n return require('@dr.pogodin/react-native-fs')\n } catch {\n try {\n return require('react-native-fs')\n } catch {\n throw new Error(\n `Could not find '@dr.pogodin/react-native-fs' or 'react-native-fs' as a peerDependency. Make sure to add either one of them`\n )\n }\n }\n}\n"],"mappings":";;;AAAA,MAAa,aAAa;AACxB,KAAI;AACF,mBAAe,8BAA8B;SACvC;AACN,MAAI;AACF,oBAAe,kBAAkB;UAC3B;AACN,SAAM,IAAI,MACR,6HACD"}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  ".": "./build/index.mjs",
5
5
  "./package.json": "./package.json"
6
6
  },
7
- "version": "0.7.0-alpha-20260218222221",
7
+ "version": "0.7.0-alpha-20260401141348",
8
8
  "files": [
9
9
  "build"
10
10
  ],
@@ -20,11 +20,12 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "events": "^3.3.0",
23
- "@credo-ts/core": "0.7.0-alpha-20260218222221"
23
+ "@credo-ts/core": "0.7.0-alpha-20260401141348"
24
24
  },
25
25
  "devDependencies": {
26
- "react-native": "^0.83.1",
26
+ "react-native": "^0.84.1",
27
27
  "react-native-fs": "^2.20.0",
28
+ "@dr.pogodin/react-native-fs": "^2.37.0",
28
29
  "react-native-get-random-values": "^2.0.0",
29
30
  "typescript": "~5.9.3"
30
31
  },
@@ -32,12 +33,19 @@
32
33
  "@animo-id/expo-secure-environment": "^0.1.1",
33
34
  "expo-crypto": "^15.0.7",
34
35
  "react-native": ">=0.71.4",
35
- "react-native-fs": "^2.20.0",
36
+ "@dr.pogodin/react-native-fs": ">= 2.37.0",
37
+ "react-native-fs": ">= 2",
36
38
  "react-native-get-random-values": ">=1.11.0 <3.0.0"
37
39
  },
38
40
  "peerDependenciesMeta": {
39
41
  "@animo-id/expo-secure-environment": {
40
42
  "optional": true
43
+ },
44
+ "react-native-fs": {
45
+ "optional": true
46
+ },
47
+ "@dr.pogodin/react-native-fs": {
48
+ "optional": true
41
49
  }
42
50
  },
43
51
  "scripts": {