This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gozala
commented
Jun 29, 2021
@@ -34,6 +43,7 @@ module.exports = async (cipherType, hash, secret) => { | |||
throw errcode(new Error('missing hash type'), 'ERR_MISSING_HASH_TYPE') | |||
} | |||
|
|||
// @ts-expect-error - Blowfish has no keySize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vasco-santos this seems like a bug that needs addressing
Gozala
commented
Jun 29, 2021
const buffer = new forge.util.ByteBuffer(this.marshal()) | ||
const asn1 = forge.asn1.fromDer(buffer) | ||
const privateKey = forge.pki.privateKeyFromAsn1(asn1) | ||
|
||
const options = { | ||
return forge.pki.encryptRsaPrivateKey(privateKey, password, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: This allows TS to infer literals instead of treating them as strings.
Next steps:
|
2021-11-12 update: we do still want this work, but it needs to be looked at in a couple weeks as part of larger js-libp2p typing changes that will be occurring. |
JS triage note: closing, no longer relevant as we converted to TypeScript recently |
For reference, the push to TS in js-libp2p is happening in libp2p/js-libp2p#1021 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is fallout of the libp2p/js-libp2p#955 effort. More specifically it types everything via crypto interfaces definitions from libp2p/js-libp2p-interfaces#100 which is necode to eded to align it with a pull that integrates interfaces in js-libp2p
Reviewer notes
new Uint8Array(buffer, buffer.byteOffset, buffer.byteLength)
wherebuffer
was instance ofArrayBuffer
which does not havebyteOffset
property. It worked correctly becauseundefined
was triggering same code path asnew Uint8Array(buffer)
algorithm
property (introduced by interface) which follows the same pattern as base encoders, hashers and block codecs (in multiformats). This allows narrow down type without resorting toinstanceof
, which is not a thing when embracing interfaces as opposed to implementations.CurveType | string
style args, now they are strict and just takeCurveType
which enables type checker to catch problems at compile time. Users generally can cast string to specific literals when needed.src/keys/keys.d.ts
is generated now viapbjs
require('node-forge')
is so that we can avoid pulling unnecessary code, if that is not the case maybe we should switch to using it instead.Secp256k1PublicKey
/Secp256k1PrivateKey
because TS doesn't support non static (generate) classes as their type can't really be expressed. I would personally not even expose classes which would also address the issue, but that seemed to invasive change.generateKeyPairFromSeed
no longer takes 3rd parameter because nothing was using it.genSecret
method. It made little sense to me so I've omitted it from the interface (no other key implements it) and created a static function on the module which is what test is using now. I kept the method around just in case, but type checker will complain if you try to use it.Suggestions
I feel like
src/keys/index.js
attempts to provide a generic API where it makes no sense. E.g.generateKeyPairFromSeed
can only be used byEd25519
keys, so it throws in all other cases.generateKeyPair
ignores bits whensecp256k1
is used.All this is just suggests that those APIs aren't generic, it would make a lot more sense to just use
ed25519.generateKeyPairFromSeed
and not have generic equivalent. I think same is true forgenerateKeyPair
there is questionable value in indirection here:Which is also true for
generateKeyPair
.I think export function on private keys is another source of indirection that complicates things instead of simplifying them more on this in Proposal: Separate key export functionality #190