Skip to content

Commit

Permalink
Fix encryption in browser by bumping encointer-js and removing the po…
Browse files Browse the repository at this point in the history
…lyfills (#13)

* polyfills are correctly resolved now, but some crypto polyfill is unimplemented

* bump encointer-js

* bump encointer-js fix assert transform error

* set ssr: false in nuxt.config

* remove polyfills try with encointer-js' webcrypto approach

* bump encointer-js; fix crypto issue

* [Readme] add note about webcrypto api

* remove unnecessary changes in nuxt config
  • Loading branch information
clangenb authored May 2, 2024
1 parent 2a39d4a commit 35dbfe3
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 46 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

Look at the [Nuxt 3 documentation](https://nuxt.com/docs/getting-started/introduction) to learn more.

## Note
The `@encointer/worker-api` uses the browser's built-in `webcrypto` api. This library is only available in secure
secure contexts. Hence, in local development you must use `localhost`. `webcrypto` is undefined on `127.0.0.1` and
`0.0.0.0`.

## Setup

Make sure to install the dependencies:
Expand Down
4 changes: 0 additions & 4 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { defineNuxtConfig } from 'nuxt/config'

// Add polyfills: https://github.com/nuxt/nuxt/pull/25028
import { Buffer } from 'node:buffer'
import process from 'node:process'

export default defineNuxtConfig({
app: {
head: {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
"nuxt": "^3.11.2",
"postcss": "^8.4.38",
"tailwindcss": "^3.4.3",
"unenv": "^1.9.0",
"vite": "^5.2.10",
"vue": "^3.4.26",
"vue-router": "^4.3.2"
},
"dependencies": {
"@encointer/worker-api": "^0.12.4",
"@encointer/worker-api": "^0.12.5",
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@material-tailwind/html": "^2.2.2",
"@nuxt/content": "^2.12.1",
Expand Down
133 changes: 93 additions & 40 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -485,51 +485,51 @@ __metadata:
languageName: node
linkType: hard

"@encointer/node-api@npm:^0.12.4":
version: 0.12.4
resolution: "@encointer/node-api@npm:0.12.4"
"@encointer/node-api@npm:^0.12.5":
version: 0.12.5
resolution: "@encointer/node-api@npm:0.12.5"
dependencies:
"@encointer/types": "npm:^0.12.4"
"@encointer/types": "npm:^0.12.5"
"@polkadot/api": "npm:^10.9.1"
tslib: "npm:^2.5.3"
checksum: 10c0/7a9c15edfb49b757ebb7ca6341a0e1d533dd48834242db9da8a1f77091d380f4966b0aa8d53f2c27b2b96716c5e49e39e083f403b22e4072d80f8c799b94a181
checksum: 10c0/6b37a8d14e41c0ea6fe4a412577ef6b1cd9821456af7ebc8a5ee1696cbde8d6b946fe6cb3c55382ca7b535f277f1576e3e783007fb09e53722fd9db98f7db953
languageName: node
linkType: hard

"@encointer/types@npm:^0.12.4":
version: 0.12.4
resolution: "@encointer/types@npm:0.12.4"
"@encointer/types@npm:^0.12.5":
version: 0.12.5
resolution: "@encointer/types@npm:0.12.5"
dependencies:
"@polkadot/api": "npm:^10.9.1"
"@polkadot/types": "npm:^10.9.1"
"@polkadot/types-codec": "npm:^10.9.1"
"@polkadot/util": "npm:^12.3.2"
checksum: 10c0/2263d64e704257c4ceb018dd84ad8133c04f4f1ce3dfe6490cfdbb84f9b50fda35303bc073010a85ef10f050c0ea0d0c1800ef80587e680d6501ad710e3cd158
checksum: 10c0/f6459bf8894e3b8ff410a5e9548fec96da9ea5203858f911e0b49dd67b2bdab0d71d571a1f6d868dea7f4c70e2a115a008717746e789bf9e7fd3f23e89a82751
languageName: node
linkType: hard

"@encointer/util@npm:^0.12.4":
version: 0.12.4
resolution: "@encointer/util@npm:0.12.4"
"@encointer/util@npm:^0.12.5":
version: 0.12.5
resolution: "@encointer/util@npm:0.12.5"
dependencies:
"@babel/runtime": "npm:^7.18.9"
"@polkadot/util": "npm:^12.3.2"
"@polkadot/util-crypto": "npm:^12.3.2"
"@types/bn.js": "npm:^5.1.1"
assert: "npm:^2.0.0"
bn.js: "npm:^5.2.1"
checksum: 10c0/d3e1981d9990ff4ca3e86c9b44b69c3634d5c045fea48bfe6eeed56c6a51ad77543abb3bd6d057a8e8b3c5ded05ddccd852a390ae3a2b550a5a5528537500786
checksum: 10c0/c7a7d5ae3c246e67963361c85b3658211271185096e0051f9af02165cede144d0310c86197e6dd1cfee1068f4786323b9e7b5724a8929981dab7f1f26c9789d0
languageName: node
linkType: hard

"@encointer/worker-api@npm:^0.12.4":
version: 0.12.4
resolution: "@encointer/worker-api@npm:0.12.4"
"@encointer/worker-api@npm:^0.12.5":
version: 0.12.5
resolution: "@encointer/worker-api@npm:0.12.5"
dependencies:
"@encointer/node-api": "npm:^0.12.4"
"@encointer/types": "npm:^0.12.4"
"@encointer/util": "npm:^0.12.4"
"@learntheropes/node-rsa": "npm:^1.1.3"
"@encointer/node-api": "npm:^0.12.5"
"@encointer/types": "npm:^0.12.5"
"@encointer/util": "npm:^0.12.5"
"@peculiar/webcrypto": "npm:^1.4.6"
"@polkadot/api": "npm:^10.9.1"
"@polkadot/keyring": "npm:^12.3.2"
"@polkadot/types": "npm:^10.9.1"
Expand All @@ -542,7 +542,7 @@ __metadata:
websocket-as-promised: "npm:^2.0.1"
peerDependencies:
"@polkadot/x-randomvalues": ^12.3.2
checksum: 10c0/e720c1fbdb4f6467e48b0bbbda1649c26fe68639e8e19ab3007f87ee75ea009d0becf75f5644cb3b3ac1e8ae1dc8957174994957239cf387ec59ae2ec9a25905
checksum: 10c0/55a2c92f1cc989094a5ae5406505c89233cb94c7e3e126a54d60678fb3c6de5300b81bffca1e30a4f026f9e21037816eb847d2cea1aaed5b9a70532da5366746
languageName: node
linkType: hard

Expand Down Expand Up @@ -912,16 +912,6 @@ __metadata:
languageName: node
linkType: hard

"@learntheropes/node-rsa@npm:^1.1.3":
version: 1.1.3
resolution: "@learntheropes/node-rsa@npm:1.1.3"
dependencies:
asn1: "npm:^0.2.4"
buffer: "npm:^6.0.3"
checksum: 10c0/d96d934ae9e76e9d46d609a10dfddc5a28cadf3a757ac4284b91f6cc6939420660aff70ee3eaffc3bf90cfbab9110388a6604f32ce96c765ebaa36de42b5ac03
languageName: node
linkType: hard

"@mapbox/node-pre-gyp@npm:^1.0.5":
version: 1.0.11
resolution: "@mapbox/node-pre-gyp@npm:1.0.11"
Expand Down Expand Up @@ -1648,6 +1638,39 @@ __metadata:
languageName: node
linkType: hard

"@peculiar/asn1-schema@npm:^2.3.8":
version: 2.3.8
resolution: "@peculiar/asn1-schema@npm:2.3.8"
dependencies:
asn1js: "npm:^3.0.5"
pvtsutils: "npm:^1.3.5"
tslib: "npm:^2.6.2"
checksum: 10c0/65f16b2a7eb91365b6dac47730ffcad4617ef04b821e0a4286c379ac7283588b0a6744032ee686e0914a0886c2a055108ed945b9c4d22821a3b123640b61f3b2
languageName: node
linkType: hard

"@peculiar/json-schema@npm:^1.1.12":
version: 1.1.12
resolution: "@peculiar/json-schema@npm:1.1.12"
dependencies:
tslib: "npm:^2.0.0"
checksum: 10c0/202132c66dcc6b6aca5d0af971c015be2e163da2f7f992910783c5d39c8a7db59b6ec4f4ce419459a1f954b7e1d17b6b253f0e60072c1b3d254079f4eaebc311
languageName: node
linkType: hard

"@peculiar/webcrypto@npm:^1.4.6":
version: 1.4.6
resolution: "@peculiar/webcrypto@npm:1.4.6"
dependencies:
"@peculiar/asn1-schema": "npm:^2.3.8"
"@peculiar/json-schema": "npm:^1.1.12"
pvtsutils: "npm:^1.3.5"
tslib: "npm:^2.6.2"
webcrypto-core: "npm:^1.7.9"
checksum: 10c0/b9c80b1a0a3e3ebbf045bd5167fe99ec4a83b170e9aa15a5952a9138afc278210d772306dcc57101d9407c3f9c70dbf6bfb4d8b3f20996ad35c650bb0fe6a90c
languageName: node
linkType: hard

"@pinia/nuxt@npm:^0.5.1":
version: 0.5.1
resolution: "@pinia/nuxt@npm:0.5.1"
Expand Down Expand Up @@ -3522,12 +3545,14 @@ __metadata:
languageName: node
linkType: hard

"asn1@npm:^0.2.4":
version: 0.2.6
resolution: "asn1@npm:0.2.6"
"asn1js@npm:^3.0.1, asn1js@npm:^3.0.5":
version: 3.0.5
resolution: "asn1js@npm:3.0.5"
dependencies:
safer-buffer: "npm:~2.1.0"
checksum: 10c0/00c8a06c37e548762306bcb1488388d2f76c74c36f70c803f0c081a01d3bdf26090fc088cd812afc5e56a6d49e33765d451a5f8a68ab9c2b087eba65d2e980e0
pvtsutils: "npm:^1.3.2"
pvutils: "npm:^1.1.3"
tslib: "npm:^2.4.0"
checksum: 10c0/bb8eaf4040c8f49dd475566874986f5976b81bae65a6b5526e2208a13cdca323e69ce297bcd435fdda3eb6933defe888e71974d705b6fcb14f2734a907f8aed4
languageName: node
linkType: hard

Expand Down Expand Up @@ -8588,7 +8613,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "nuxt-app@workspace:."
dependencies:
"@encointer/worker-api": "npm:^0.12.4"
"@encointer/worker-api": "npm:^0.12.5"
"@esbuild-plugins/node-globals-polyfill": "npm:^0.2.3"
"@material-tailwind/html": "npm:^2.2.2"
"@nuxt/content": "npm:^2.12.1"
Expand Down Expand Up @@ -8622,7 +8647,6 @@ __metadata:
postcss: "npm:^8.4.38"
sass: "npm:^1.75.0"
tailwindcss: "npm:^3.4.3"
unenv: "npm:^1.9.0"
vite: "npm:^5.2.10"
vue: "npm:^3.4.26"
vue-router: "npm:^4.3.2"
Expand Down Expand Up @@ -9696,6 +9720,22 @@ __metadata:
languageName: node
linkType: hard

"pvtsutils@npm:^1.3.2, pvtsutils@npm:^1.3.5":
version: 1.3.5
resolution: "pvtsutils@npm:1.3.5"
dependencies:
tslib: "npm:^2.6.1"
checksum: 10c0/d425aed316907e0b447a459bfb97c55d22270c3cfdba5a07ec90da0737b0e40f4f1771a444636f85bb6a453de90ff8c6b5f4f6ddba7597977166af49974b4534
languageName: node
linkType: hard

"pvutils@npm:^1.1.3":
version: 1.1.3
resolution: "pvutils@npm:1.1.3"
checksum: 10c0/23489e6b3c76b6afb6964a20f891d6bef092939f401c78bba186b2bfcdc7a13904a0af0a78f7933346510f8c1228d5ab02d3c80e968fd84d3c76ff98d8ec9aac
languageName: node
linkType: hard

"queue-microtask@npm:^1.2.2":
version: 1.2.3
resolution: "queue-microtask@npm:1.2.3"
Expand Down Expand Up @@ -10238,7 +10278,7 @@ __metadata:
languageName: node
linkType: hard

"safer-buffer@npm:>= 2.1.2 < 3.0.0, safer-buffer@npm:~2.1.0":
"safer-buffer@npm:>= 2.1.2 < 3.0.0":
version: 2.1.2
resolution: "safer-buffer@npm:2.1.2"
checksum: 10c0/7e3c8b2e88a1841c9671094bbaeebd94448111dd90a81a1f606f3f67708a6ec57763b3b47f06da09fc6054193e0e6709e77325415dc8422b04497a8070fa02d4
Expand Down Expand Up @@ -11157,7 +11197,7 @@ __metadata:
languageName: node
linkType: hard

"tslib@npm:^2.1.0, tslib@npm:^2.5.3, tslib@npm:^2.6.2":
"tslib@npm:^2.0.0, tslib@npm:^2.1.0, tslib@npm:^2.4.0, tslib@npm:^2.5.3, tslib@npm:^2.6.1, tslib@npm:^2.6.2":
version: 2.6.2
resolution: "tslib@npm:2.6.2"
checksum: 10c0/e03a8a4271152c8b26604ed45535954c0a45296e32445b4b87f8a5abdb2421f40b59b4ca437c4346af0f28179780d604094eb64546bee2019d903d01c6c19bdb
Expand Down Expand Up @@ -12092,6 +12132,19 @@ __metadata:
languageName: node
linkType: hard

"webcrypto-core@npm:^1.7.9":
version: 1.7.9
resolution: "webcrypto-core@npm:1.7.9"
dependencies:
"@peculiar/asn1-schema": "npm:^2.3.8"
"@peculiar/json-schema": "npm:^1.1.12"
asn1js: "npm:^3.0.1"
pvtsutils: "npm:^1.3.5"
tslib: "npm:^2.6.2"
checksum: 10c0/29075c0fd6afdd11473dcf98623b929fae6a0861a54725af109df824e3c55c00580103a2f934baabff52d588e9c6c3892db80346061fd835c55e0a83264c19f5
languageName: node
linkType: hard

"webidl-conversions@npm:^3.0.0":
version: 3.0.1
resolution: "webidl-conversions@npm:3.0.1"
Expand Down

0 comments on commit 35dbfe3

Please sign in to comment.