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

fix(vc): change pubKey input from Buffer to Uint8Array #935

Merged

Conversation

karimStekelenburg
Copy link
Contributor

This PR addresses an issue that occurred when running the deriveProof test case in the W3cCredentialService tests. Strangely enough this issue only occurred when running in a NodeJS environment (which uses node-bbs-signatures) instead of the WASM fallback.

Huge thanks to @blu3beri for helping debug this issue. This one wasn't easy to catch.

Signed-off-by: Karim [email protected]

@karimStekelenburg karimStekelenburg requested a review from a team as a code owner July 5, 2022 20:14
@codecov-commenter
Copy link

codecov-commenter commented Jul 5, 2022

Codecov Report

Merging #935 (49c35d4) into 0.3.0-pre (65579dd) will decrease coverage by 1.95%.
The diff coverage is n/a.

@@              Coverage Diff              @@
##           0.3.0-pre     #935      +/-   ##
=============================================
- Coverage      86.65%   84.69%   -1.96%     
=============================================
  Files            515      517       +2     
  Lines          12552    12573      +21     
  Branches        2132     2136       +4     
=============================================
- Hits           10877    10649     -228     
- Misses          1580     1793     +213     
- Partials          95      131      +36     
Impacted Files Coverage Δ
...c/signature-suites/bbs/BbsBlsSignatureProof2020.ts 9.52% <ø> (-68.26%) ⬇️
...les/vc/signature-suites/bbs/BbsBlsSignature2020.ts 6.61% <0.00%> (-81.00%) ⬇️
packages/core/src/crypto/BbsService.ts 38.23% <0.00%> (-52.95%) ⬇️
packages/core/src/modules/vc/jsonldUtil.ts 42.50% <0.00%> (-27.50%) ⬇️
...src/modules/vc/signature-suites/bbs/deriveProof.ts 16.21% <0.00%> (-16.22%) ⬇️
packages/core/src/crypto/WalletKeyPair.ts 78.72% <0.00%> (-8.52%) ⬇️
packages/core/src/utils/validators.ts 60.71% <0.00%> (-7.15%) ⬇️
packages/core/src/wallet/IndyWallet.ts 57.76% <0.00%> (-6.38%) ⬇️
...ckages/core/src/modules/vc/W3cCredentialService.ts 71.42% <0.00%> (-4.52%) ⬇️
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 65579dd...49c35d4. Read the comment docs.

@karimStekelenburg
Copy link
Contributor Author

Tests seem to fail for Node 17. It doesn't look like it's related to the changes in this PR. @TimoGlastra, does this error look familiar to you by any chance?

@berendsliedrecht
Copy link
Contributor

I have ran the tests again, and node 18 now failed. Locally it works (m1 Mac), so it might be some issue with the node-addon.

@TimoGlastra
Copy link
Contributor

TimoGlastra commented Jul 6, 2022

We're having some issues with flaky tests from the credentials tests with events listener being started after the action has been performed resulting in a race condition. This is often if the CI randomly fails. I made a start at it here, but there's more test we need to fix: #893

Not sure if this is it, but migth be related

@TimoGlastra TimoGlastra linked an issue Jul 6, 2022 that may be closed by this pull request
@TimoGlastra
Copy link
Contributor

Hmm after looking at it again, this looks like a different issue than the flaky tests as it's only failing on BBS tests. Maybe a linux + node 18 issue?

@karimStekelenburg
Copy link
Contributor Author

As discussed in the WG call today, we will work around this issue for now by forcing the library to use the WASM environment. We can do this by setting an environment variable called BBS_SIGNATURES_MODE to WASM. I will add this to the CI for now, which should make sure it succeeds.

However, this does open up the possibility for confusion. If an unknowing developer runs AFJ in Node 17 or 18, it will use node-bbs-signatures instead of the WASM build and cause errors. I'm not totally sure how we should deal with this, I guess documenting it is a start...

@karimStekelenburg
Copy link
Contributor Author

Ok, I've added the environment variable in 49c35d4 which should hopefully make sure the tests succeed for all Node versions (waiting on CI to finish atm, wish me luck 😄). One thing I'd like to double check: in order to not have to overhaul the entire workflow structure, I've added the environment variable top level. This means that the tests for Node 14 and 16 (which did succeed using node-bbs-signatures) will also use the WASM build.

Please let me know if there are any objections regarding this.

@TimoGlastra, @blu3beri, would love to hear your thoughts on this.

@TimoGlastra
Copy link
Contributor

Documenting would be good. In addition I think there's two approaches here (maybe more):

  • set the environment variable by default before importing the bbs library
  • logging a warning if the node version is used and we're in node 17/18. The hard part is, how do we know which version is used? We could check if the node bbs signatures install succeeded (by trying to import it) and then logging the warning
  • logging a warning if the env variable is not set and we're in node 17/18. This will push the user to always set the env variable explicitly

@TimoGlastra
Copy link
Contributor

Could you maybe open an issue in the node bbs signatures repo so the maintainers are aware of the issue?

@karimStekelenburg
Copy link
Contributor Author

Documenting would be good. In addition I think there's two approaches here (maybe more):

  • set the environment variable by default before importing the bbs library
  • logging a warning if the node version is used and we're in node 17/18. The hard part is, how do we know which version is used? We could check if the node bbs signatures install succeeded (by trying to import it) and then logging the warning
  • logging a warning if the env variable is not set and we're in node 17/18. This will push the user to always set the env variable explicitly

Since usability and simplicity are primary goals of AFJ, I'm personally in favour of the first option. I'd like to minimise the amount of edge cases a user has to handle by themselves, as that increases the amount of gotcha's.

Could you maybe open an issue in the node bbs signatures repo so the maintainers are aware of the issue?

Good point, I will raise this issue to make them aware.


Just to be sure before I move on to the next issue, how do you feel about the top level environment variable in the CI? If we go with the first option you mentioned this isn't needed anymore, but just in case we take the logging & documentation route..

@karimStekelenburg
Copy link
Contributor Author

Ahh great! Now we broke Node 14 again! 💯

@TimoGlastra
Copy link
Contributor

Ahh great! Now we broke Node 14 again! 💯

Lol. Maybe we should take the first route and only set it for node 17 & 18?

@karimStekelenburg
Copy link
Contributor Author

karimStekelenburg commented Jul 7, 2022

Ahh great! Now we broke Node 14 again! 💯

Lol. Maybe we should take the first route and only set it for node 17 & 18?

Yeah... I tried running the tests on my machine (M1) locally with 14 and it succeeds. I will try to run it with Node 14 on an Ubuntu system now, just to get a better understanding where the problem lies, but I agree, that solution is probably better.

However, should we really set this environment variable just before importing the package? Isn't it cleaner to do this more 'top level', e.g. in the Agent class?

@TimoGlastra
Copy link
Contributor

Ahh great! Now we broke Node 14 again! 💯

Lol. Maybe we should take the first route and only set it for node 17 & 18?

Yeah... I tried running the tests on my machine (M1) locally with 14 and it succeeds. I will try to run it with Node 14 on an Ubuntu system now, just to get a better understanding where the problem lies, but I agree, that solution is probably better.

However, should we really set this environment variable just before importing the package? Isn't it cleaner to do this more 'top level', e.g. in the Agent class?

If we do it in the agent class the bbs library is probably already imported in which case setting the env variable doesn't matter anymore. So we need to make sure it happens before the import of bbs library

@berendsliedrecht
Copy link
Contributor

I will try to debug the issue tomorrow with the node library, however a temporary fix would be best for now.

WASM should not be that much slower so it's for sure not the end of the world.

@karimStekelenburg
Copy link
Contributor Author

Ahh great! Now we broke Node 14 again! 💯

Lol. Maybe we should take the first route and only set it for node 17 & 18?

Yeah... I tried running the tests on my machine (M1) locally with 14 and it succeeds. I will try to run it with Node 14 on an Ubuntu system now, just to get a better understanding where the problem lies, but I agree, that solution is probably better.
However, should we really set this environment variable just before importing the package? Isn't it cleaner to do this more 'top level', e.g. in the Agent class?

If we do it in the agent class the bbs library is probably already imported in which case setting the env variable doesn't matter anymore. So we need to make sure it happens before the import of bbs library

Even if we do this at the very top of the Agent class (before importing any of the containers)? I'm OK with anything tho, but this seems like a more evident place. I just want to avoid forgetting this in the future because it's being done in a deeply nested file.

Anyhow, will do it right before the import for now. We can change it in a follow up PR :)

@TimoGlastra
Copy link
Contributor

Maybe the index.ts file is a better suited place? That's the entry point of the framework. I'm almost certain the agent class won't work

@karimStekelenburg
Copy link
Contributor Author

Ok, I ran some local tests. I ran it on Ubuntu hoping to reproduce the error, and on macOs (M1) for future reference. On both platforms all tests succeeded. This is going to be fun!

Ubuntu

Specs

CleanShot 2022-07-08 at 03 06 55

Results for Node v14.19.3

CleanShot 2022-07-08 at 02 52 42

Results for Node v16.16.0

CleanShot 2022-07-08 at 02 55 12

Results for Node v17.9.1

CleanShot 2022-07-08 at 02 57 11

Results for Node v18.5.0

CleanShot 2022-07-08 at 03 12 44

macOs (M1)

Specs

CleanShot 2022-07-08 at 03 14 21

Results for Node v14.20.0

CleanShot 2022-07-08 at 03 16 40

Results for Node v16.16.0

CleanShot 2022-07-08 at 03 18 27

Results for Node v17.9.1

CleanShot 2022-07-08 at 03 20 11

Results for Node v18.5.0

CleanShot 2022-07-08 at 03 21 54

@TimoGlastra
Copy link
Contributor

TimoGlastra commented Jul 8, 2022

Ok, I ran some local tests. I ran it on Ubuntu hoping to reproduce the error, and on macOs (M1) for future reference. On both platforms all tests succeeded. This is going to be fun!

Ubuntu

Specs

CleanShot 2022-07-08 at 03 06 55

Results for Node v14.19.3

CleanShot 2022-07-08 at 02 52 42

Results for Node v16.16.0

CleanShot 2022-07-08 at 02 55 12

Results for Node v17.9.1

CleanShot 2022-07-08 at 02 57 11

Results for Node v18.5.0

CleanShot 2022-07-08 at 03 12 44

macOs (M1)

Specs

CleanShot 2022-07-08 at 03 14 21

Results for Node v14.20.0

CleanShot 2022-07-08 at 03 16 40

Results for Node v16.16.0

CleanShot 2022-07-08 at 03 18 27

Results for Node v17.9.1

CleanShot 2022-07-08 at 03 20 11

Results for Node v18.5.0

CleanShot 2022-07-08 at 03 21 54

But isn't that expected with WASM? We're having issues with the node js bbs package Or do I mistunderstand the issue?

@karimStekelenburg
Copy link
Contributor Author

Since we have a dedicated issue for the CI failure now, can we merge this in? This problem seems to be beyond the scope of this PR alone.

@TimoGlastra TimoGlastra changed the title fix: change pubKey input from Buffer to Uint8Array fix(vc): change pubKey input from Buffer to Uint8Array Jul 21, 2022
@TimoGlastra TimoGlastra merged commit e2e98d2 into openwallet-foundation:0.3.0-pre Jul 21, 2022
@TimoGlastra TimoGlastra deleted the fix/bbs-derive-proof branch July 21, 2022 12:23
TimoGlastra pushed a commit that referenced this pull request Aug 11, 2022
TimoGlastra pushed a commit that referenced this pull request Aug 26, 2022
TimoGlastra pushed a commit that referenced this pull request Aug 26, 2022
genaris pushed a commit to 2060-io/aries-framework-javascript that referenced this pull request Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CI is broken in 0.3.0-pre branch
4 participants