share.spec.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. ///<reference path="server/index.d.ts"/>
  2. import { expect, test } from "@playwright/test";
  3. const url = "http://localhost:8085";
  4. test.beforeEach(async ({ page }) => {
  5. await page.goto(url);
  6. await page.waitForFunction(() => window.setup != null);
  7. });
  8. test.describe("Share", () => {
  9. test("share and recieve share", async ({ page }) => {
  10. const result = await page.evaluate(async () => {
  11. const {
  12. wnfs: { PrivateForest, Name, NameAccumulator, share, createShareName, receiveShare },
  13. mock: {
  14. MemoryBlockStore,
  15. Rng,
  16. createSharerDir,
  17. createRecipientExchangeRoot,
  18. ExchangeKey,
  19. },
  20. } = await window.setup();
  21. // @ts-ignore
  22. globalThis.ExchangeKey = ExchangeKey;
  23. const rng = new Rng();
  24. var forest = new PrivateForest(rng);
  25. const sharerRootDid = "did:key:z6MkqZjY";
  26. const store = new MemoryBlockStore();
  27. var { rootDir: sharerDir, forest } = await createSharerDir(
  28. forest,
  29. store,
  30. rng
  31. );
  32. const [recipientKey, recipientExchRoot] =
  33. await createRecipientExchangeRoot(store);
  34. const recipientExchRootCid = await recipientExchRoot.store(store);
  35. var [accessKey, forest2] = await sharerDir
  36. .asNode()
  37. .store(forest, store, rng);
  38. var forest2 = await share(
  39. accessKey,
  40. 0,
  41. sharerRootDid,
  42. recipientExchRootCid,
  43. forest2,
  44. store
  45. );
  46. const modulus = await recipientKey.getPublicKey().getPublicKeyModulus();
  47. const shareLabel = createShareName(0, sharerRootDid, modulus, forest2);
  48. const shareLabelSerialized = shareLabel.toNameAccumulator(forest2).toBytes();
  49. const shareLabelDeserialized = new Name(NameAccumulator.fromBytes(shareLabelSerialized));
  50. const sharedNode = await receiveShare(
  51. shareLabelDeserialized,
  52. recipientKey,
  53. forest2,
  54. store
  55. );
  56. console.log("sharedNode", sharedNode);
  57. return sharedNode;
  58. });
  59. expect(result).toBeDefined();
  60. });
  61. });