Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store seed credential #129

Merged
merged 5 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}
5,917 changes: 2,976 additions & 2,941 deletions pnpm-lock.yaml

Large diffs are not rendered by default.