Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The global state refactor #422

Merged
merged 108 commits into from
Nov 24, 2022
Merged

The global state refactor #422

merged 108 commits into from
Nov 24, 2022

Conversation

icidasset
Copy link
Contributor

@icidasset icidasset commented Sep 15, 2022

Summary

This refactor gets rid of the global state throughout webnative. Things such as the setup object and dependency injection now work entirely different. Instead of accessing a global object, we now create Program instances which have pointers to various instances of components that we pass to functions. For example, we create a crypto component and that is passed to a function that does crypto things.

See CHANGELOG.md for more info.

Tasks

  • Remove global state
  • Component system
  • Refactor crypto
  • Refactor auth component to make it compatible with walletauth
  • Extract lobby functionality into a component (confidences)
  • Extract IPFS functionality into a component (depot)
  • Abstract functionality of cid log and ucan storage (now called repositories)
  • Create new component called reference (dns + did lookup/update + data lookup/update + repos)
  • Create new component called manners (responsible for config dependent behaviours, eg. debug loggging)
  • Merge entrypoints and add customisable component behaviour for program entrypoint
  • Explain the different auth implementations, the role of the lobby, and the component system (see code docs in index.ts)
  • Implement sessions
  • Make webnative independent (ie. not tied to Fission infra)
  • No longer store root key in localstorage, only keystore.
  • Abstract root key functionality
  • Namespacing all the things! Allow for multiple apps on the same domain (better experience on localstorage)
  • Add ability to load multiple filesystems at the same time (ie. avoid identifier clash)
  • Remove global references from the filesystem and make instances with components
  • Refactor "apps platform" code (publishing apps via webnative, etc)
  • Finish refactor of filesystem creating/loading (partially done, removed "bootstrap filesystem" function) (see Refactor load filesystem #424 for more info)
  • Refactor UCAN creation & DID validation (depends on crypto component, should we remove automatic setting of iss and have the dev always set it?)
  • Remove references to IPFS specific code in the filesystem and use the depot component instead. Use Uint8Arrays as much as possible.
  • Backwards compatibility. We'll need to copy over data/keys from the correct locations. See https://talk.fission.codes/t/webnative-state-management-initialization-refactor/3363#backwards-compatibility-considerations-3 for specifics.
  • Refactor linking code (use components, remove keystore-idb, etc)
  • Eliminate impossible states on initialise #131
  • Easy way to use Fission staging?
  • Fix tests
  • Test compatibility with older webnative apps
  • Write new README
  • Ensure compatibility with walletauth

Code quality checks

  • keystore-idb code is only used in the Crypto implementation code and nowhere else. SymmAlg should only be imported from components/crypto/implementation
  • IPFS is not used/mentioned anywhere except in the Depot implementation, everything else should be Depot + DAGs /IPLD + CIDs

Manual testing

  • Loading old filesystem
  • Backwards compatibility (use old webnative on same domain, upgrade to newer)
  • Linking
  • Sharing private data
  • Fission Drive

Will need updating

Test with alpha version before release.

  • Fission Dashboard
  • Fission Drive
  • Webnative Elm
  • Webnative Walletauth

Closes issues

Closes #418, #283, #274

@matheus23 matheus23 self-requested a review September 19, 2022 17:00
@icidasset icidasset force-pushed the icidasset/state-refactor branch 2 times, most recently from 7b3efbd to d38edfa Compare September 23, 2022 16:32
@bgins bgins mentioned this pull request Oct 13, 2022
7 tasks
CHANGELOG.md Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
"prebuild": "rimraf lib dist && node scripts/gen-version.js",
"build": "yarn run build:ipfs && tsc && yarn run build:minified",
"build": "tsc && npm run build:minified",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced yarn with npm.

})

import pkg from "../package.json" assert { type: "json" };
import lock from "../package-lock.json" assert { type: "json" };
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May need Node v18.

export async function bareNameFilter(
{ crypto, accountDID, path }: Arguments
): Promise<string> {
return `wnfs:${accountDID}:bareNameFilter:${await pathHash(crypto, path)}`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File systems are namespaced by account DID, allows for multiple filesystems to be loaded at the same time and temporary filesystems.

src/components/depot/implementation.ts Show resolved Hide resolved
import { CID } from "multiformats/cid"


export type Implementation = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preparation for CAR mirror/pool, allows us to switch out js-ipfs.

export const inMemoryDepot: Record<string, Uint8Array> = {}


const depot: Depot.Implementation = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This avoids us having to use js-ipfs in the tests.
Bit hacky I guess because I shove large chunked files inside a single block, but it works.

tests/helpers/components.ts Outdated Show resolved Hide resolved
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%

*/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most important file, everything comes together here. The documentation should be self-explanatory, note if anything is not clear or missing.

src/index.ts Outdated Show resolved Hide resolved

const authedUsername = await common.authenticatedUsername()
// PREDEFINED COMPONENT COMBINATIONS
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See this section for a detailed explanation on the components and how they work together. A short explanation is located in the changelog.

@icidasset
Copy link
Contributor Author

Left a bunch of comments here, some thoughts, questions and additional notes for other people to read.

src/index.ts Outdated
{
implementation: Auth.Implementation<Components>

accountConsumer: (username: string) => Promise<AccountLinkingConsumer>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to separate the functions that a user/dev directly uses from the implementation. Mixing the implementation functions in here would be confusing, for example, linkDevice does not fully link a device, you have to create an account linking consumer & producer.

*
* See `assemble` for more information.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we somehow make it so that typedoc inserts a link here to the documentation of this assemble function?

src/components/auth/implementation/base.ts Show resolved Hide resolved
src/components/depot/implementation.ts Outdated Show resolved Hide resolved
src/components/reference/implementation/fission-base.ts Outdated Show resolved Hide resolved
src/components/storage/implementation/memory.ts Outdated Show resolved Hide resolved
Co-authored-by: Brian Ginsburg <7957636+bgins@users.noreply.github.com>
Signed-off-by: Steven Vandevelde <icid.asset@gmail.com>
@matheus23
Copy link
Contributor

There's some remaining usage of "confidences" in the README and CHANGELOG ✌️ @icidasset

src/fs/filesystem.ts Outdated Show resolved Hide resolved
src/linking/consumer.test.ts Outdated Show resolved Hide resolved
icidasset and others added 3 commits November 22, 2022 22:50
Co-authored-by: Brian Ginsburg <7957636+bgins@users.noreply.github.com>
Signed-off-by: Steven Vandevelde <icid.asset@gmail.com>
@icidasset
Copy link
Contributor Author

There's some remaining usage of "confidences" in the README and CHANGELOG

Thanks for spotting that!

Copy link
Member

@bgins bgins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.



Amazing work! So much accomplished here. It's looking great! 💯 🎉

As a summary, here are the things I have tested manually:

  • webnative.compositions with staging set to true
  • Account linking (tested in the Webnative app template on staging and production)
  • Backwards compatibility (tested with staging and production)
  • Custom manners component with alterations to logging
  • Custom manners component with filesystem hooks (using Add file system hooks #428)
  • Tested with the Stored Wasm example which uses capabilities and the Fission Auth Lobby

Thanks for all these changes! Excited to start using them in our apps. 🕺

src/permissions.ts Outdated Show resolved Hide resolved
src/permissions.ts Outdated Show resolved Hide resolved
icidasset and others added 8 commits November 24, 2022 10:40
* Add file system hooks

* Use FileSystem interface instead of type arg

* Less changes

* Add Properties interface

* Pass CID to beforeLoadExisting hook

* Re-export CID from common/cid

* Provide the data flow components as arguments

* Remove unnecessary cast to Uint8Array

* Pass AssociatedIdentity to hooks

* Remove Exchange interface

* Don't add sample data by default

* DataFlowComponents -> DataComponents
Co-authored-by: Brian Ginsburg <7957636+bgins@users.noreply.github.com>
Signed-off-by: Steven Vandevelde <icid.asset@gmail.com>
src/filesystem.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@matheus23 matheus23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked through quite a bit of this PR and I got a feel for the refactor when working a bit on the dashboard.

I'd say we can go ahead and :shipit: :)

scripts/build-minified.js Show resolved Hide resolved
src/common/hex.node.test.ts Outdated Show resolved Hide resolved
src/common/type-checks.ts Show resolved Hide resolved
icidasset and others added 5 commits November 24, 2022 16:31
Co-authored-by: Philipp Krüger <philipp.krueger1@gmail.com>
Signed-off-by: Steven Vandevelde <icid.asset@gmail.com>
Co-authored-by: Philipp Krüger <philipp.krueger1@gmail.com>
Signed-off-by: Steven Vandevelde <icid.asset@gmail.com>
@icidasset icidasset merged commit db89623 into main Nov 24, 2022
@icidasset icidasset deleted the icidasset/state-refactor branch November 24, 2022 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve read key management and errors
6 participants