Skip to content

Commit

Permalink
store seed credential
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <[email protected]>
  • Loading branch information
Berend Sliedrecht committed Jul 30, 2024
1 parent 0db993d commit 703befe
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/funke/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ExpoConstants from 'expo-constants'

export const FUNKE_WALLET_SEED_CREDENTIAL_RECORD_ID = 'FUNKE_WALLET_SEED_CREDENTIAL_RECORD_ID '
export const FUNKE_WALLET_INSTANCE_LONG_TERM_AES_KEY_ID = 'FUNKE_WALLET_INSTANCE_LONG_TERM_AES_KEY_ID'

const TRUSTED_CERTIFICATES = ExpoConstants.expoConfig?.extra?.trustedCertificates as [string, ...string[]] | undefined
Expand Down
1 change: 1 addition & 0 deletions apps/funke/storage/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './seedCredential'
18 changes: 18 additions & 0 deletions apps/funke/storage/seedCredential.ts
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),
}
1 change: 1 addition & 0 deletions packages/agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ export {
} from './format/formatPresentation'
export * from './mediation'
export * from './crypto'
export * from './storage'
1 change: 1 addition & 0 deletions packages/agent/src/storage/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './walletJsonStore'
28 changes: 28 additions & 0 deletions packages/agent/src/storage/walletJsonStore.ts
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,
}

0 comments on commit 703befe

Please sign in to comment.