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

chore: release v0.0.1-alpha.0 #3

Merged
merged 4 commits into from
Oct 5, 2023
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
3 changes: 2 additions & 1 deletion .release-it.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"git": {
"commitMessage": "chore: release v${version}"
"commitMessage": "chore: release v${version} [skip ci]",
"commitArgs": ["--signoff"]
},
"github": {
"release": true
Expand Down
2 changes: 1 addition & 1 deletion packages/ssi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adeya/ssi",
"version": "0.0.0",
"version": "0.0.1-alpha.1",
"license": "Apache-2.0",
"main": "build/index",
"source": "src/index",
Expand Down
5 changes: 4 additions & 1 deletion packages/ssi/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ import { anoncreds } from '@hyperledger/anoncreds-react-native'
import { ariesAskar } from '@hyperledger/aries-askar-react-native'
import { indyVdr } from '@hyperledger/indy-vdr-react-native'

const getAgentModules = (mediatorInvitationUrl: string, indyNetworks: [IndyVdrPoolConfig, ...IndyVdrPoolConfig[]]) => {
export const getAgentModules = (
mediatorInvitationUrl: string,
indyNetworks: [IndyVdrPoolConfig, ...IndyVdrPoolConfig[]]
) => {
return {
askar: new AskarModule({
ariesAskar
Expand Down
5 changes: 3 additions & 2 deletions packages/ssi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ import { LogLevel, ConsoleLogger } from '@aries-framework/core'
// Indy VDR
import { IndyVdrPoolConfig } from '@aries-framework/indy-vdr'

export { initializeAgent, AdeyaAgent } from './agent'
export { LogLevel, ConsoleLogger, InitConfig, IndyVdrPoolConfig }
export * from './providers'
export * from './hooks'
export * from './wallet'
export { initializeAgent, AdeyaAgent } from './agent'
export { LogLevel, ConsoleLogger, InitConfig, IndyVdrPoolConfig }
export {
V1RequestPresentationMessage,
AnonCredsCredentialOffer,
Expand Down
3 changes: 3 additions & 0 deletions packages/ssi/src/wallet/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { importWalletWithAgent, isWalletImportable, isWalletPinCorrect } from './wallet'

export { importWalletWithAgent, isWalletImportable, isWalletPinCorrect }
109 changes: 109 additions & 0 deletions packages/ssi/src/wallet/wallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// NOTE: We need to import these to be able to use the AskarWallet in this file.
import '@hyperledger/aries-askar-react-native'

import type { InitConfig } from '@aries-framework/core'
import type { IndyVdrPoolConfig } from '@aries-framework/indy-vdr'

import { AskarWallet } from '@aries-framework/askar'
import {
Agent,
ConsoleLogger,
HttpOutboundTransport,
LogLevel,
SigningProviderRegistry,
WsOutboundTransport,
type WalletConfig,
type WalletExportImportConfig
} from '@aries-framework/core'
import { agentDependencies } from '@aries-framework/react-native'

import { getAgentModules } from '../agent'

interface WalletImportConfigWithAgent {
agentConfig: InitConfig
importConfig: WalletExportImportConfig
mediatorInvitationUrl: string
indyNetworks: [IndyVdrPoolConfig, ...IndyVdrPoolConfig[]]
}

export const isWalletPinCorrect = async (walletConfig: WalletConfig) => {
try {
// NOTE: a custom wallet is used to check if the wallet key is correct. This is different from the wallet used in the rest of the app.
// We create an AskarWallet instance and open the wallet with the given secret.
const askarWallet = new AskarWallet(
new ConsoleLogger(LogLevel.off),
new agentDependencies.FileSystem(),
new SigningProviderRegistry([])
)
await askarWallet.open(walletConfig)

await askarWallet.close()
return true
} catch (e) {
// eslint-disable-next-line no-console
console.log('Error opening wallet', e)
return false
}
}

export const isWalletImportable = async (
walletConfig: WalletConfig,
importConfig: WalletExportImportConfig
): Promise<boolean> => {
const fileSystem = new agentDependencies.FileSystem()
try {
const tempImportPath = fileSystem.tempPath + '/importTemp'
// Add temp path to wallet config
walletConfig.storage = {
type: 'sqlite',
path: tempImportPath
}
// NOTE: a custom wallet is used to check if the wallet passphrase is correct and can be imported successfully.
const askarWallet = new AskarWallet(new ConsoleLogger(LogLevel.off), fileSystem, new SigningProviderRegistry([]))
await askarWallet.import(walletConfig, importConfig)

await fileSystem.delete(importConfig.path)
return true
} catch (e) {
// eslint-disable-next-line no-console
console.log('Error importing wallet', e)
await fileSystem.delete(importConfig.path)
return false
}
}

export const importWalletWithAgent = async ({
importConfig,
agentConfig,
mediatorInvitationUrl,
indyNetworks
}: WalletImportConfigWithAgent) => {
if (!agentConfig.walletConfig?.id || !agentConfig.walletConfig.key) {
// Cannot find wallet id/key in agent config, so we cannot import the wallet
return
}

if (!importConfig.key || !importConfig.path) {
throw new Error('Please enter a valid passphrase')
}

const agent = new Agent({
dependencies: agentDependencies,
config: {
autoUpdateStorageOnStartup: true,
...agentConfig
},
modules: getAgentModules(mediatorInvitationUrl, indyNetworks)
})

agent.registerOutboundTransport(new HttpOutboundTransport())
agent.registerOutboundTransport(new WsOutboundTransport())

await agent.wallet.import(agentConfig.walletConfig, importConfig)

await agent.wallet.initialize(agentConfig.walletConfig)

await agent.initialize()

return agent
}