-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Berend Sliedrecht <[email protected]>
- Loading branch information
Berend Sliedrecht
committed
Jul 30, 2024
1 parent
0db993d
commit 703befe
Showing
6 changed files
with
50 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './seedCredential' |
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,18 @@ | ||
import type { Agent } from '@credo-ts/core' | ||
import { walletJsonStore } from '@package/agent' | ||
import { FUNKE_WALLET_SEED_CREDENTIAL_RECORD_ID } from '../constants' | ||
|
||
export const seedCredentialStorage = { | ||
store: async (agent: Agent, seedCredential: string) => | ||
walletJsonStore.store(agent, FUNKE_WALLET_SEED_CREDENTIAL_RECORD_ID, { | ||
seedCredential, | ||
}), | ||
|
||
update: async (agent: Agent, seedCredential: string) => | ||
walletJsonStore.update(agent, FUNKE_WALLET_SEED_CREDENTIAL_RECORD_ID, { | ||
seedCredential, | ||
}), | ||
|
||
getById: async (agent: Agent) => | ||
walletJsonStore.getById<{ seedCredential: string }>(agent, FUNKE_WALLET_SEED_CREDENTIAL_RECORD_ID), | ||
} |
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 @@ | ||
export * from './walletJsonStore' |
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,28 @@ | ||
import type { Agent } from '@credo-ts/core' | ||
import { GenericRecord } from '@credo-ts/core/build/modules/generic-records/repository/GenericRecord' | ||
|
||
const store = async (agent: Agent, id: string, value: Record<string, unknown>) => { | ||
const record = new GenericRecord({ id, content: value }) | ||
await agent.genericRecords.save(record) | ||
} | ||
|
||
const update = async (agent: Agent, id: string, value: Record<string, unknown>) => { | ||
const record = new GenericRecord({ id, content: value }) | ||
await agent.genericRecords.update(record) | ||
} | ||
|
||
const getById = async <T extends Record<string, unknown>>(agent: Agent, id: string): Promise<T> => { | ||
const record = await agent.genericRecords.findById(id) | ||
|
||
if (!record) { | ||
throw Error(`Record with id: ${id} not found`) | ||
} | ||
|
||
return record.content as T | ||
} | ||
|
||
export const walletJsonStore = { | ||
store, | ||
getById, | ||
update, | ||
} |