diff --git a/packages/auto-id/src/certificateManager.ts b/packages/auto-id/src/certificateManager.ts index 3d83526a..940f7365 100644 --- a/packages/auto-id/src/certificateManager.ts +++ b/packages/auto-id/src/certificateManager.ts @@ -1,13 +1,17 @@ //! For key generation, management, `keyManagement.ts` file is used using "crypto" library. //! And for certificate related, used "@peculiar/x509" library. -import { blake2b_256, concatenateUint8Arrays, stringToUint8Array } from '@autonomys/auto-utils' +import { + blake2b_256, + concatenateUint8Arrays, + save, + stringToUint8Array, +} from '@autonomys/auto-utils' import { AsnConvert } from '@peculiar/asn1-schema' import { AttributeTypeAndValue, GeneralNames } from '@peculiar/asn1-x509' import { Crypto } from '@peculiar/webcrypto' import * as x509 from '@peculiar/x509' import { KeyObject, createPublicKey } from 'crypto' -import fs from 'fs' import { doPublicKeysMatch, pemToPublicKey } from './keyManagement' import { randomSerialNumber } from './utils' @@ -317,13 +321,13 @@ export class CertificateManager { return certificate } - saveCertificate(filePath: string): void { + async saveCertificate(filePath: string): Promise { if (!this.certificate) { throw new Error('No certificate available to save.') } const certificatePem = CertificateManager.certificateToPem(this.certificate) - fs.writeFileSync(filePath, certificatePem, 'utf8') + await save(filePath, certificatePem) } } diff --git a/packages/auto-utils/src/save.ts b/packages/auto-utils/src/save.ts index 5fa575a6..27a2718c 100644 --- a/packages/auto-utils/src/save.ts +++ b/packages/auto-utils/src/save.ts @@ -16,7 +16,7 @@ export const saveOnFileSystem = async (key: string, value: any) => { // save on file system const fs = await import('fs/promises') // Check if value is already a string to avoid unnecessary JSON string conversion - const data = typeof value === 'string' ? value : JSON.stringify(value); + const data = typeof value === 'string' ? value : JSON.stringify(value) await fs.writeFile(key, JSON.stringify(data)) } else throw new Error('This function can only be used in node') -} \ No newline at end of file +}