-
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
fadad1a
commit 7a63e71
Showing
7 changed files
with
3,052 additions
and
2,941 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 { AgentContext } from '@credo-ts/core' | ||
import { walletJsonStore } from '@package/agent' | ||
import { FUNKE_WALLET_SEED_CREDENTIAL_RECORD_ID } from '../constants' | ||
|
||
export const seedCredentialStorage = { | ||
store: async (context: AgentContext, seedCredential: string) => | ||
walletJsonStore.store(context, FUNKE_WALLET_SEED_CREDENTIAL_RECORD_ID, { | ||
seedCredential, | ||
}), | ||
|
||
replace: async (context: AgentContext, seedCredential: string) => | ||
walletJsonStore.replace(context, FUNKE_WALLET_SEED_CREDENTIAL_RECORD_ID, { | ||
seedCredential, | ||
}), | ||
|
||
getById: async (context: AgentContext) => | ||
walletJsonStore.getById<{ seedCredential: string }>(context, 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,54 @@ | ||
import { assertAskarWallet } from '@credo-ts/askar/build/utils/assertAskarWallet' | ||
import type { AgentContext } from '@credo-ts/core' | ||
|
||
const store = async (context: AgentContext, id: string, value: Record<string, unknown>) => { | ||
const wallet = context.wallet | ||
assertAskarWallet(wallet) | ||
|
||
wallet.withSession(async (session) => { | ||
session.insert({ | ||
name: id, | ||
value: JSON.stringify(value), | ||
category: 'genericStorageRecord', | ||
}) | ||
}) | ||
} | ||
|
||
const replace = async (context: AgentContext, id: string, value: Record<string, unknown>) => { | ||
const wallet = context.wallet | ||
assertAskarWallet(wallet) | ||
|
||
wallet.withSession(async (session) => { | ||
session.replace({ | ||
name: id, | ||
value: JSON.stringify(value), | ||
category: 'genericStorageRecord', | ||
}) | ||
}) | ||
} | ||
|
||
const getById = async <T extends Record<string, unknown>>(context: AgentContext, id: string): Promise<T> => { | ||
const wallet = context.wallet | ||
assertAskarWallet(wallet) | ||
|
||
const item = await wallet.withSession(async (session) => | ||
session.fetch({ | ||
name: id, | ||
category: 'genericStorageRecord', | ||
}) | ||
) | ||
|
||
if (!item) { | ||
throw new Error(`No generic item with id: ${id} found`) | ||
} | ||
|
||
const transformedValue = item.value === 'string' ? JSON.parse(item.value) : item.value | ||
|
||
return transformedValue as T | ||
} | ||
|
||
export const walletJsonStore = { | ||
store, | ||
getById, | ||
replace, | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.