-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initializing readers and writers outside of the API request handlers
- Loading branch information
Showing
3 changed files
with
38 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { PointsWriter, PointsReader } from '@ceramic-solutions/points' | ||
import { getAuthenticatedDID } from '@ceramic-solutions/key-did' | ||
import { fromString } from 'uint8arrays' | ||
|
||
const CERAMIC_PRIVATE_KEY: string = process.env.CERAMIC_PRIVATE_KEY ?? '' | ||
const aggregationModelID: string | undefined = process.env.AGGREGATION_ID ?? undefined | ||
|
||
//eslint-disable-next-line | ||
const seed = fromString(CERAMIC_PRIVATE_KEY, 'base16') as Uint8Array | ||
|
||
// create a context writer | ||
const contextWriter = await PointsWriter.fromSeed({ | ||
aggregationModelID, | ||
seed, | ||
}) | ||
|
||
// create a total writer | ||
const writer = await PointsWriter.fromSeed({ | ||
seed, | ||
}) | ||
|
||
// generate issuer for reader context | ||
const issuer = await getAuthenticatedDID(seed) | ||
|
||
//create a context reader | ||
const contextReader = PointsReader.create({ | ||
issuer: issuer.id, | ||
aggregationModelID, | ||
}) | ||
|
||
//create a total reader | ||
const reader = PointsReader.create({ | ||
issuer: issuer.id, | ||
}) | ||
|
||
export { contextWriter, writer, contextReader, reader } |