Skip to content

Instantly share code, notes, and snippets.

@Jviejo
Created March 11, 2023 10:58
Show Gist options
  • Save Jviejo/e8e4417575645c59f988b84db917b94a to your computer and use it in GitHub Desktop.
Save Jviejo/e8e4417575645c59f988b84db917b94a to your computer and use it in GitHub Desktop.
import { AskarModule } from '@aries-framework/askar';
import {
Agent, ConsoleLogger, DidsModule, HttpOutboundTransport,
InitConfig, KeyDidResolver, LogLevel,
PeerDidResolver, WsOutboundTransport
} from "@aries-framework/core";
import { agentDependencies } from "@aries-framework/node";
import { AskarWalletPostgresStorageConfig } from "@aries-framework/askar/build/wallet";
const storageConfig: AskarWalletPostgresStorageConfig = {
type: 'postgres',
config: {
host: 'localhost:5432',
},
credentials: {
account: 'postgres',
password: 'postgres',
},
}
const logger = new ConsoleLogger(LogLevel.debug)
export async function initializeAgent(
mediatorInvitationUrl: string, label
) {
const agentLabel = label
const agentId = label
const agentKey = label
const config: InitConfig = {
label: agentLabel,
walletConfig: {
id: agentId,
key: agentKey,
storage: storageConfig,
},
autoAcceptConnections: true,
mediatorConnectionsInvite: mediatorInvitationUrl,
autoUpdateStorageOnStartup: true,
logger
}
const ariesAgent = new Agent({
config,
dependencies: agentDependencies,
modules: await getAskarAnonCredsIndyModules(mediatorInvitationUrl),
})
// ariesAgent.registerInboundTransport(new HttpInboundTransport({ port: port }))
ariesAgent.registerOutboundTransport(new WsOutboundTransport())
// Register a simple `Http` outbound transport
ariesAgent.registerOutboundTransport(new HttpOutboundTransport())
logger.debug("Initializing agent...")
await ariesAgent.initialize()
logger.debug("Agent initialized...")
return ariesAgent
}
export function getAskarAnonCredsIndyModules(mediatorInvitationUrl) {
return {
dids: new DidsModule({
resolvers: [new PeerDidResolver(), new KeyDidResolver()],
}),
askar: new AskarModule(),
} as const
}
const mediatorInvitationUrl = "https://public.mediator.indiciotech.io?c_i=eyJAdHlwZSI6ICJkaWQ6c292OkJ6Q2JzTlloTXJqSGlxWkRUVUFTSGc7c3BlYy9jb25uZWN0aW9ucy8xLjAvaW52aXRhdGlvbiIsICJAaWQiOiAiMDVlYzM5NDItYTEyOS00YWE3LWEzZDQtYTJmNDgwYzNjZThhIiwgInNlcnZpY2VFbmRwb2ludCI6ICJodHRwczovL3B1YmxpYy5tZWRpYXRvci5pbmRpY2lvdGVjaC5pbyIsICJyZWNpcGllbnRLZXlzIjogWyJDc2dIQVpxSktuWlRmc3h0MmRIR3JjN3U2M3ljeFlEZ25RdEZMeFhpeDIzYiJdLCAibGFiZWwiOiAiSW5kaWNpbyBQdWJsaWMgTWVkaWF0b3IifQ=="
async function main() {
logger.debug(mediatorInvitationUrl)
const agent2 = await initializeAgent(mediatorInvitationUrl, "bob")
const agent1 = await initializeAgent(mediatorInvitationUrl, "alice")
const registroInvitacion = await agent1.oob.createInvitation();
const inviUrl = registroInvitacion.outOfBandInvitation.toUrl({ domain: "" })
const { connectionRecord } = await agent2.oob.receiveInvitationFromUrl(inviUrl)
await agent2.connections.returnWhenIsConnected(connectionRecord.id)
let c = 0;
setInterval(async () => {
const basicMessageRecord = await agent2.basicMessages.sendMessage(connectionRecord.id, "jose viejo huerta " + c++)
console.log(basicMessageRecord)
}, 7000)
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment