Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
shamilovtim committed Apr 4, 2024
1 parent accd137 commit b7357c0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 54 deletions.
2 changes: 1 addition & 1 deletion tests/reactnative/package.json
Expand Up @@ -9,7 +9,7 @@
"web": "expo start --web",
"pods": "cd ios;pod install;cd ..",
"build:tests": "yarn pods && yarn detox build --configuration ios.sim.debug",
"test": "concurrently --success first -k -n 'Detox,Metro' -c 'cyan,magenta' 'yarn detox test --configuration ios.sim.debug --retries 1 --cleanup --headless --record-logs failing --take-screenshots failing --record-videos failing --loglevel verbose' 'yarn start'",
"test": "concurrently --success first -k -n 'Detox,Metro' -c 'cyan,magenta' 'yarn detox test --configuration ios.sim.debug --retries 1 --cleanup --headless --record-logs failing --take-screenshots failing --record-videos failing' 'yarn start'",
"postinstall": "patch-package"
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions tests/reactnative/src/App.tsx
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from "react";
import { StyleSheet, Text, View } from "react-native";
import { DwnNoWeb5 } from "./DwnNoWeb5";
import { getWeb5 } from "./Web5";
import { initWeb5 } from "./Web5";
import testWeb5 from "./util/web5-test";

export default function App() {
Expand All @@ -10,7 +10,7 @@ export default function App() {

useEffect(() => {
const runWeb5Tests = async () => {
const web5 = await getWeb5();
const web5 = await initWeb5();

try {
const {
Expand Down
102 changes: 51 additions & 51 deletions tests/reactnative/src/Web5.ts
Expand Up @@ -29,56 +29,8 @@ import { MemoryStore } from "@web5/common";

let agent: Web5IdentityAgent;

export const getWeb5 = async () => {
export const initWeb5 = async () => {
console.info("initializing agent...");
await initAgent();
console.info("agent initialized!");

const serviceEndpointNodes = await getTechPreviewDwnEndpoints();

console.info("creating identity...!!!");
// Generate a new Identity for the end-user.
const identity = await agent.identity.create({
didMethod: "dht",
metadata: { name: "Social" },
didOptions: {
services: [
{
id: "dwn",
type: "DecentralizedWebNode",
serviceEndpoint: serviceEndpointNodes,
enc: "#enc",
sig: "#sig",
},
],
verificationMethods: [
{
algorithm: "Ed25519",
id: "sig",
purposes: ["assertionMethod", "authentication"],
},
{
algorithm: "secp256k1",
id: "enc",
purposes: ["keyAgreement"],
},
],
},
});

await agent.identity.manage({ portableIdentity: await identity.export() });

console.info("identity created!");

const web5 = new Web5({ agent, connectedDid: identity.did.uri });

console.info(`web5 initialized for ${identity.did.uri} `);

return web5;
};

const initAgent = async () => {
// agentVault
const agentVault = new HdIdentityVault({
keyDerivationWorkFactor: 210_000,
store: new MemoryStore<string, string>(),
Expand All @@ -88,6 +40,7 @@ const initAgent = async () => {
const didApi = new AgentDidApi({
didMethods: [DidDht, DidJwk],
resolverCache: new DidResolverCacheMemory(),
store: new DwnDidStore(),
});

// syncApi
Expand Down Expand Up @@ -124,8 +77,56 @@ const initAgent = async () => {
syncApi,
});

await agent.start({ password: "unprotectedpass" });
console.info("agent created!");

const serviceEndpointNodes = await getTechPreviewDwnEndpoints();

// create
console.info("creating identity...!!!");
const identity = await agent.identity.create({
didMethod: "dht",
metadata: { name: "Social" },
didOptions: {
services: [
{
id: "dwn",
type: "DecentralizedWebNode",
serviceEndpoint: serviceEndpointNodes,
enc: "#enc",
sig: "#sig",
},
],
verificationMethods: [
{
algorithm: "Ed25519",
id: "sig",
purposes: ["assertionMethod", "authentication"],
},
{
algorithm: "secp256k1",
id: "enc",
purposes: ["keyAgreement"],
},
],
},
});

await agent.identity.manage({ portableIdentity: await identity.export() });
await agent.sync.registerIdentity({ did: identity.did.uri });

// init
await agent.initialize({ password: "example" });
await agent.start({ password: "example" });
console.log("MYDID", agent.agentDid);
await startSync();

console.info("identity created!");

const web5 = new Web5({ agent, connectedDid: identity.did.uri });

console.info(`web5 initialized for ${identity.did.uri} `);

return web5;
};

const startSync = async () => {
Expand All @@ -135,7 +136,6 @@ const startSync = async () => {
agent.agentDid,
...managedIdentities.map((i) => i.did),
];
console.info("registering DIDs for sync", { didsToRegister });

await Promise.all(
didsToRegister.map((did) => agent.sync.registerIdentity({ did: did.uri }))
Expand Down

0 comments on commit b7357c0

Please sign in to comment.