Skip to content
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.

feat: add iagon storage and general improvements. #80

Merged
merged 1 commit into from
Jan 19, 2024
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
20 changes: 19 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,29 @@
],
"type": "node"
},
{
"name": "IAGON",
"program": "${workspaceFolder}/examples/node/src/iagon.js",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"type": "node",
"env": {
"IAGON_API_KEY": "ll.IAG-SN.-.rediF-afIHyqB/Vt=O.uPm+Xpnc4-kfqD8+2^hCQOd8SyChEfcW3+/cf+kuxRj",
"IAGON_PW": "elribonazo"
}
},
{
"command": "npm run test",
"cwd": "${workspaceFolder}/packages/iagon",
"name": "TEST",
"request": "launch",
"type": "node-terminal"
"type": "node-terminal",
"env": {
"IAGON_API_KEY": "ll.IAG-SN.-.rediF-afIHyqB/Vt=O.uPm+Xpnc4-kfqD8+2^hCQOd8SyChEfcW3+/cf+kuxRj",
"IAGON_PW": "elribonazo"
}
}
]
}
837 changes: 616 additions & 221 deletions examples/node/package-lock.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions examples/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
"license": "ISC",
"type": "module",
"dependencies": {
"@atala/prism-wallet-sdk": "^3.2.0",
"@pluto-encrypted/database": "^1.2.3",
"@pluto-encrypted/inmemory": "^1.3.1",
"@pluto-encrypted/leveldb": "^1.3.1",
"@atala/prism-wallet-sdk": "^4.0.0-rc.1",
"@pluto-encrypted/database": "^1.14.2",
"@pluto-encrypted/iagon": "^0.0.0-beta.18",
"@pluto-encrypted/inmemory": "^1.11.2",
"@pluto-encrypted/leveldb": "^1.11.2",
"fake-indexeddb": "^5.0.1",
"prettier": "^3.0.2"
},
Expand Down
91 changes: 91 additions & 0 deletions examples/node/src/iagon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
if (!process.env.IAGON_API_KEY) {
throw new Error("Please add IAGON_API_KEY env var with your IagonAPI")
}

if (!process.env.IAGON_PW) {
throw new Error("Please add IAGON_PW env var with your IagonAPI")
}
import { getDefaultCollections } from '@pluto-encrypted/schemas';

async function createTestScenario() {

const { Database } = await import('@pluto-encrypted/database')
const { createIagonStorage } = await import("@pluto-encrypted/iagon")
const { default: SDK } = await import("@atala/prism-wallet-sdk");
const defaultPassword = new Uint8Array(32).fill(1);
const mediatorDID = SDK.Domain.DID.fromString(
"did:peer:2.Ez6LSghwSE437wnDE1pt3X6hVDUQzSjsHzinpX3XFvMjRAm7y.Vz6Mkhh1e5CEYYq6JBUcTZ6Cp2ranCWRrv7Yax3Le4N59R6dd.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9iZXRhLW1lZGlhdG9yLmF0YWxhcHJpc20uaW8iLCJyIjpbXSwiYSI6WyJkaWRjb21tL3YyIl19"
);
const apollo = new SDK.Apollo();
const api = new SDK.ApiImpl();
const castor = new SDK.Castor(apollo);
const storage = createIagonStorage({
apiKey: process.env.IAGON_API_KEY,
password: process.env.IAGON_PW
});
const pluto = await Database.createEncrypted(
{
name: `pluto-encrypted`,
encryptionKey: defaultPassword,
storage: storage,
collections: getDefaultCollections()
}
);
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 {
SDK,
apollo,
seed,
agent,
mercury,
pluto,
castor,
};
}

(async () => {


const { seed, agent, SDK } = await createTestScenario();

agent.addListener(SDK.ListenerKey.MESSAGE, (message) => {
console.log("Got new message", message);
});

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.",
);
}
})();
4 changes: 3 additions & 1 deletion examples/node/src/inmemory.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { getDefaultCollections } from '@pluto-encrypted/schemas';

async function createTestScenario() {

const PlutoEncrypted = await import('@pluto-encrypted/database')
const { default: InMemory } = await import("@pluto-encrypted/inmemory")
const SDK = await import("@atala/prism-wallet-sdk");
const { default: SDK } = await import("@atala/prism-wallet-sdk");

const { Database } = PlutoEncrypted;
const defaultPassword = new Uint8Array(32).fill(1);
Expand All @@ -18,6 +19,7 @@ async function createTestScenario() {
name: `my-db`,
encryptionKey: defaultPassword,
storage: InMemory,
collections: getDefaultCollections()
}
);
const didcomm = new SDK.DIDCommWrapper(apollo, castor, pluto);
Expand Down
Loading
Loading