Skip to content

Commit

Permalink
Modify the dynamic save function for client/server side rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
abhi3700 committed Jun 19, 2024
1 parent d11cefa commit ac70441
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions packages/auto-id/src/certificateManager.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -317,13 +321,13 @@ export class CertificateManager {
return certificate
}

saveCertificate(filePath: string): void {
async saveCertificate(filePath: string): Promise<void> {
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)
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/auto-utils/src/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
}

0 comments on commit ac70441

Please sign in to comment.