dwn-sdk-js
dwn-sdk-js copied to clipboard
Web app/browser usage of library
I'm attempting to rely on the library in an Angular project and not able to get it working when importing through the code base. Made another attempt by loading the full bundle, but that has some eval() calls which I won't allow in my key-management app.
The issue by importing the library directly, is related to use of import using JSON files. The resolveJsonModule and esModuleInterop options for TypeScript is not enough to make it work, unfortunately.

For anyone else looking into this and allows eval execution, you can include the bundle in angular.json using the scripts section:
"scripts": ["./node_modules/@tbd54566975/dwn-sdk-js/dist/bundles/index.cjs"],

Right now the library is used to host DWN instance and I don't think the focus is on consumer library yet? Is the plan to split some of the logic in a separate library that is cross-compatible with Node.js/Web and doesn't include the service-processing logic of the DWN instance?
This was intended to be cross-env, so let's see if we can get that eval-using lib out of the deps.
For TypeScript, I needed to set "module": "ESNext" in tsconfig.json under compilerOptions. See if that helps.
For TypeScript, I needed to set
"module": "ESNext"intsconfig.jsonundercompilerOptions. See if that helps.
Already tried that with no luck. I have previously used the import JSON feature within the same app, but this is first time I have an external dependency that does it and not sure why it fails. I'll make a small repo that reproduce the problem with basic skeleton of an Angular app.
Repo of basic Angular app that imports the dwn-sdk-js and fails to compile: https://github.com/sondreb/angular-dwn
Hey @sondreb, I am looking into this issue. I published a temporary release 0.0.10-unstable-20221028-2 to work around the assertion issue, but also saw the following issue when ng build:

Did you ever work around the polyfill issue above?
A workaround would be to just:
npm install util
The main issue is that the whole repo depends on Node.js packages that won't run properly in the web browser, like levelup which includes C++ binding for LevelDB. I don't know which other dependencies won't run in the browser, but that doesn't have to be an issue as especially the ESM versions should allow for tree-shaking for consumers of the library, but I'm not 100% sure. Best would be to have separate library for the core DID/JWS/CID, etc.
Hi @sondreb, @mistermoe checked in a PR to fix the package bundle meant to be used in the browser.
I have made a PR against your repo which shows that the issue is fixed https://github.com/sondreb/angular-dwn/pull/1 (I hope) with dummy usage of the DWN which should use browser-level under the hood.
The next SDK release will include this fix.
Great work, thanks a lot! And I just noticed that the leveldb works cross-platform (Node/Web) as well, that's fantastic:
