-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Including examples for cjs, esm, typescript and browser.
- Loading branch information
1 parent
c475b5b
commit ee72e91
Showing
16 changed files
with
8,965 additions
and
402 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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,18 @@ | ||
{ | ||
"name": "cjs", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "./src/index.js", | ||
"type": "commonjs", | ||
"scripts": { | ||
"start": "node ./src/index.js" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@atala/prism-wallet-sdk": "file:../..", | ||
"@pluto-encrypted/database": "^0.0.8", | ||
"@pluto-encrypted/inmemory": "^0.0.7", | ||
"@pluto-encrypted/leveldb": "^0.0.6" | ||
} | ||
} |
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,85 @@ | ||
const SDK = require("@atala/prism-wallet-sdk"); | ||
const InMemory = require("@pluto-encrypted/inmemory"); | ||
const Database = require("@pluto-encrypted/database").Database; | ||
|
||
const defaultPassword = new Uint8Array(32).fill(1); | ||
|
||
let database; | ||
|
||
async function createTestScenario(mediatorDID) { | ||
database = await Database.createEncrypted( | ||
{ | ||
name: `my-db`, | ||
encryptionKey: defaultPassword, | ||
storage: InMemory, | ||
} | ||
); | ||
const apollo = new SDK.Apollo(); | ||
const api = new SDK.ApiImpl(); | ||
const castor = new SDK.Castor(apollo); | ||
const pluto = database; | ||
const didcomm = new SDK.DIDCommWrapper(apollo, castor, pluto); | ||
const mercury = new SDK.Mercury(castor, didcomm, api); | ||
const store = new SDK.PublicMediatorStore(pluto); | ||
const handler = new SDK.BasicMediatorHandler(mediatorDID, mercury, store); | ||
const manager = new SDK.ConnectionsManager(castor, mercury, pluto, handler); | ||
const seed = apollo.createRandomSeed(); | ||
const agent = new SDK.Agent( | ||
apollo, | ||
castor, | ||
pluto, | ||
mercury, | ||
handler, | ||
manager, | ||
seed.seed, | ||
); | ||
return { | ||
apollo, | ||
seed, | ||
agent, | ||
mercury, | ||
pluto, | ||
castor, | ||
}; | ||
} | ||
|
||
(async () => { | ||
const mediatorDID = SDK.Domain.DID.fromString( | ||
"did:peer:2.Ez6LSghwSE437wnDE1pt3X6hVDUQzSjsHzinpX3XFvMjRAm7y.Vz6Mkhh1e5CEYYq6JBUcTZ6Cp2ranCWRrv7Yax3Le4N59R6dd.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9iZXRhLW1lZGlhdG9yLmF0YWxhcHJpc20uaW8iLCJyIjpbXSwiYSI6WyJkaWRjb21tL3YyIl19" | ||
); | ||
|
||
const { seed, agent } = await createTestScenario(mediatorDID); | ||
|
||
agent.addListener(SDK.ListenerKey.MESSAGE, async (message) => { | ||
console.log("Got new message", message); | ||
if (database) { | ||
const content = await database.backup(); | ||
console.log(content); | ||
} | ||
}); | ||
|
||
await agent.start(); | ||
console.log( | ||
`Welcome to PrismEdge Agent, state ${agent.state | ||
} with mnemonics ${seed.mnemonics.join(", ")}`, | ||
); | ||
|
||
try { | ||
const secondaryDID = await agent.createNewPeerDID([], true); | ||
const message = new SDK.BasicMessage( | ||
{ content: "Test Message" }, | ||
secondaryDID, | ||
secondaryDID, | ||
); | ||
|
||
await agent.sendMessage(message.makeMessage()); | ||
await agent.sendMessage(message.makeMessage()); | ||
console.log("Sent"); | ||
|
||
|
||
} catch (err) { | ||
console.log( | ||
"Safe to ignore, mediator returns null on successfully receiving the message, unpack fails.", | ||
); | ||
} | ||
})(); |
Oops, something went wrong.