-
Notifications
You must be signed in to change notification settings - Fork 73
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
Base58Matcher and Base64Matcher Conflict #222
Comments
Using the python math library, I have print (math.log((256**32),58)) = 43.70 which puts the length between 43 an 44. |
I added some tests for parseKey.change the matcher by switching between commenting out one of the base58matchers in util.ts 764f89f |
The base58 string I am matching is only 43 characters long. I will see if I can add some padding to get the matcher to work. |
I thought that maybe Gqzym8nfnxR5ZYZ3wZo8rvTwKTqGn5cJsbHnEhUZDPo could be rewritten as 1Gqzym8nfnxR5ZYZ3wZo8rvTwKTqGn5cJsbHnEhUZDPo . The first attempt to get this to work was not successful. I will have to try again. |
This test does not seem to care that I just tack on a leading zero (in base58): Matcher: const base58Matcher = /^([1-9A-HJ-NP-Za-km-z]{44}|[1-9A-HJ-NP-Za-km-z]{88})$/ From: describe('parseKey test #2', () => { To: |
/^([1-9A-HJ-NP-Za-km-z]{44}|[1-9A-HJ-NP-Za-km-z]{88})$/.test('1Gqzym8nfnxR5ZYZ3wZo8rvTwKTqGn5cJsbHnEhUZDPo') evaluates to true in the browser. I might need to dig into the code some more and see how the extra zero in front (the 1 in base58) is causing a problem. Maybe it is causing an unexpected length elsewhere?? |
Actually you have stumbled upon a larger issue here.
BUT, that matcher is used in an heuristic to differentiate between different key encodings and the fact that there are valid encodings 43 character long, means that the logic there is broken, since that string could also represent a base64 encoding. So because of this ambiguity we should either remove one of the base58btc or base64 encodings from the heuristic, or have This is a classic example of some convenience code coming back to byte :) |
Fixing this will affect the private key inputs accepted by the signers (ES256KSigner, EdDSASigner, etc). We have a couple of options to fix this:
All of these are breaking changes so fixing this will bump us to a new major version. If you are following this repository, please weigh in with your opinion. |
I announced it here https://lists.w3.org/Archives/Public/public-credentials/2022Mar/0321.html and on the ceramic discord. This is for the matchers used by @oed , is it better that I just tag you on GitHub? [1] https://github.com/decentralized-identity/did-jwt/blob/master/src/util.ts |
For reference, this is in Orie Steele's code: getSigner the JsonWebKey2020 or CryptoKey . CryptoKey is an interface from the Web Cryptograpy API. The jws code is here: https://github.com/transmute-industries/verifiable-data/blob/5f5d9289191b1844200fd03bbd0054608811719f/packages/web-crypto-key-pair/src/signatures/jws.ts#L20-L36 . In jws.ts in the webcrypto-key-pairs package in jws.ts there is a snippet of code (L140-148):
Maybe there is something going with this subject area in the WG that I don't know about. Will need to find out. Checking out Mattr: Parameters: Name | Type | Description "KeyLike are runtime-specific classes representing asymmetric keys or symmetric secrets. These are instances of CryptoKey and additionally KeyObject in Node.js runtime. Uint8Array instances are also accepted as symmetric secret representation only." |
Option 3 sticks out at me, and after some review of code in the wild it still does.
|
yeah, it seems like the cleanest approach to me too. |
Working on Ceramic, which uses did-jwt library extensively. IMO, using Uint8Arrays (option 3) trumps every other variant by removing unnecessary stringly-typed ambiguity. |
# [6.0.0](5.12.4...6.0.0) (2022-04-04) ### Bug Fixes * remove parseKey, change ES256K and Ed25519 signers to Uint8Array only ([#224](#224)) ([9132caf](9132caf)), closes [#222](#222) ### BREAKING CHANGES * The Signer classes exported by this library no longer accept private keys with string encodings, only `Uint8Array`. This reduces the potential ambiguity between different formats. Some utility methods are exported that allow users to convert some popular encodings to raw `Uint8Array`.
🎉 This issue has been resolved in version 6.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Use the hex to base58 tool here:
https://appdevtools.com/base58-encoder-decoder
040f1dbf0a2ca86875447a7c010b0fc6d39d76859c458fbe8f2bf775a40ad74a hex
====>
Gqzym8nfnxR5ZYZ3wZo8rvTwKTqGn5cJsbHnEhUZDPo base58
Try the Existing base58Matcher:
/^([1-9A-HJ-NP-Za-km-z]{44}|[1-9A-HJ-NP-Za-km-z]{88})$/.test('Gqzym8nfnxR5ZYZ3wZo8rvTwKTqGn5cJsbHnEhUZDPo')
false
Refactor, and use a new base58Matcher:
/^([1-9A-HJ-NP-Za-km-z]{43,44}|[1-9A-HJ-NP-Za-km-z]{86,88})$/.test('Gqzym8nfnxR5ZYZ3wZo8rvTwKTqGn5cJsbHnEhUZDPo')
true
For reference see code: https://github.com/decentralized-identity/did-jwt/blob/master/src/util.ts#L87-L115
The text was updated successfully, but these errors were encountered: