-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
269780a
commit fb7d155
Showing
12 changed files
with
428 additions
and
136 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
This file was deleted.
Oops, something went wrong.
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,77 @@ | ||
import blessed, { Widgets } from 'blessed' | ||
import { IMessage, VerifiableCredential } from 'daf-core' | ||
import { shortDate, shortDid } from './utils' | ||
import { ConfiguredAgent } from '../setup' | ||
import { styles } from './styles' | ||
|
||
export const getCredentialsTable = async (agent: ConfiguredAgent, screen: Widgets.Screen) => { | ||
screen.title = 'Credentials' | ||
|
||
const credentialsTable = blessed.listtable({ | ||
top: '0', | ||
left: '0', | ||
border: 'line', | ||
align: 'left', | ||
tags: true, | ||
keys: true, | ||
width: '100%', | ||
height: '100%', | ||
mouse: true, | ||
style: styles.listtable, | ||
}) | ||
|
||
const credentials = await agent.dataStoreORMGetVerifiableCredentials() | ||
credentialsTable.setData( | ||
[['Created', 'Type', 'From', 'To']].concat( | ||
credentials.map((m) => [ | ||
shortDate(m.issuanceDate), | ||
m.type.join(','), | ||
shortDid(m.issuer.id), | ||
shortDid(m.credentialSubject.id), | ||
]), | ||
), | ||
) | ||
|
||
credentialsTable.on('select', async function (data) { | ||
const i = credentialsTable.getItemIndex(data) | ||
showCredential(credentials[i - 1]) | ||
}) | ||
|
||
function showCredential(message: VerifiableCredential) { | ||
const credentialBox = blessed.box({ | ||
label: 'Credential', | ||
top: 'center', | ||
left: 'center', | ||
height: '90%', | ||
width: '90%', | ||
border: 'line', | ||
shadow: true, | ||
mouse: true, | ||
keys: true, | ||
scrollable: true, | ||
vi: true, | ||
alwaysScroll: true, | ||
scrollbar: { | ||
ch: ' ', | ||
track: { | ||
bg: 'grey', | ||
}, | ||
style: { | ||
inverse: false, | ||
}, | ||
}, | ||
|
||
content: JSON.stringify(message, null, 2), | ||
}) | ||
credentialBox.key(['escape'], function (ch, key) { | ||
credentialBox.destroy() | ||
screen.render() | ||
}) | ||
|
||
credentialBox.focus() | ||
screen.append(credentialBox) | ||
screen.render() | ||
} | ||
|
||
return credentialsTable | ||
} |
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,11 @@ | ||
import { getAgent } from '../setup' | ||
import program from 'commander' | ||
import { renderMainScreen } from './main' | ||
|
||
program | ||
.command('data-explorer') | ||
.description('Data explorer') | ||
.action(async (cmd) => { | ||
const agent = getAgent(program.config) | ||
await renderMainScreen(agent) | ||
}) |
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,65 @@ | ||
import blessed from 'blessed' | ||
import { IMessage } from 'daf-core' | ||
import { ConfiguredAgent } from '../setup' | ||
import { styles } from './styles' | ||
|
||
import { getManagedIdentitiesTable } from './managed-identities' | ||
import { getMessagesTable } from './messages' | ||
import { getCredentialsTable } from './credentials' | ||
import { getPresentationsTable } from './presentations' | ||
|
||
const defaultScreenTitle = 'Agent' | ||
|
||
export const renderMainScreen = async (agent: ConfiguredAgent) => { | ||
// Create a screen object. | ||
const screen = blessed.screen({ | ||
smartCSR: true, | ||
}) | ||
|
||
screen.title = defaultScreenTitle | ||
|
||
const mainMenuItems = [ | ||
{ title: 'Managed identities', getComponent: getManagedIdentitiesTable }, | ||
{ title: 'Messages', getComponent: getMessagesTable }, | ||
{ title: 'Credentials', getComponent: getCredentialsTable }, | ||
{ title: 'Presentations', getComponent: getPresentationsTable }, | ||
] | ||
|
||
const menu = blessed.list({ | ||
label: 'Agent', | ||
top: 'center', | ||
left: 'center', | ||
border: 'line', | ||
align: 'center', | ||
keys: true, | ||
width: 'shrink', | ||
height: '70%', | ||
vi: true, | ||
mouse: true, | ||
style: styles.list, | ||
items: mainMenuItems.map((i) => i.title), | ||
}) | ||
|
||
menu.on('select', async function (data) { | ||
const i = menu.getItemIndex(data) | ||
const component = await mainMenuItems[i].getComponent(agent, screen) | ||
|
||
component.key(['escape'], function (ch, key) { | ||
component.destroy() | ||
screen.title = defaultScreenTitle | ||
screen.render() | ||
}) | ||
|
||
screen.append(component) | ||
component.focus() | ||
screen.render() | ||
}) | ||
|
||
screen.append(menu) | ||
menu.focus() | ||
|
||
screen.key(['q', 'C-c'], function (ch, key) { | ||
return process.exit(0) | ||
}) | ||
screen.render() | ||
} |
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,67 @@ | ||
import blessed, { Widgets } from 'blessed' | ||
import { IIdentity } from 'daf-core' | ||
import { ConfiguredAgent } from '../setup' | ||
import { styles } from './styles' | ||
|
||
export const getManagedIdentitiesTable = async (agent: ConfiguredAgent, screen: Widgets.Screen) => { | ||
screen.title = 'Managed identities' | ||
|
||
const managedIdentitiesTable = blessed.listtable({ | ||
top: '0', | ||
left: '0', | ||
border: 'line', | ||
align: 'left', | ||
tags: true, | ||
keys: true, | ||
width: '100%', | ||
height: '100%', | ||
mouse: true, | ||
style: styles.listtable, | ||
}) | ||
|
||
const identities = await agent.identityManagerGetIdentities() | ||
managedIdentitiesTable.setData([['DID', 'Alias']].concat(identities.map((i) => [i.did, i.alias || '']))) | ||
|
||
managedIdentitiesTable.on('select', async function (data) { | ||
const i = managedIdentitiesTable.getItemIndex(data) | ||
showIdentity(identities[i - 1]) | ||
}) | ||
|
||
function showIdentity(identity: IIdentity) { | ||
const identityBox = blessed.box({ | ||
label: identity.did, | ||
top: 'center', | ||
left: 'center', | ||
height: '90%', | ||
width: '90%', | ||
border: 'line', | ||
shadow: true, | ||
mouse: true, | ||
keys: true, | ||
scrollable: true, | ||
vi: true, | ||
alwaysScroll: true, | ||
scrollbar: { | ||
ch: ' ', | ||
track: { | ||
bg: 'grey', | ||
}, | ||
style: { | ||
inverse: false, | ||
}, | ||
}, | ||
|
||
content: JSON.stringify(identity, null, 2), | ||
}) | ||
identityBox.key(['escape'], function (ch, key) { | ||
identityBox.destroy() | ||
screen.render() | ||
}) | ||
|
||
identityBox.focus() | ||
screen.append(identityBox) | ||
screen.render() | ||
} | ||
|
||
return managedIdentitiesTable | ||
} |
Oops, something went wrong.