-
Notifications
You must be signed in to change notification settings - Fork 207
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
feat: default to uncompressed keys #2165
Open
berendsliedrecht
wants to merge
9
commits into
openwallet-foundation:main
Choose a base branch
from
berendsliedrecht:key-compression
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
042e184
feat: default to uncompressed keys
berendsliedrecht d06d931
fix(x509): parse compressed and uncompressed correctly
berendsliedrecht 87d47a7
fix: tests compare uint8array with uint8array
berendsliedrecht b52ec3d
chore: run linter
berendsliedrecht c499267
chore: return uint8array for coordinates in JWK
berendsliedrecht 9ff76c6
chore: convert buffer into uint8array
berendsliedrecht d037fbc
chore: remove usage of bn libraries
berendsliedrecht 4758e8b
chore: resolve feedback
berendsliedrecht 30ff14a
docs(changeset): - Remove usage of Big Number libraries and rely on n…
berendsliedrecht File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
'@credo-ts/anoncreds': patch | ||
'@credo-ts/askar': patch | ||
'@credo-ts/core': patch | ||
--- | ||
|
||
- Remove usage of Big Number libraries and rely on native implementations | ||
- By default rely on uncompressed keys instead of compressed (for P256, P384, P521 and K256) | ||
- Utilze Uint8Array more instead of Buffer (i.e. for internally representing a key) | ||
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
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
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,30 @@ | ||
import type { KeyType } from './KeyType' | ||
|
||
import { Buffer, MultiBaseEncoder, TypedArrayEncoder, VarintEncoder } from '../utils' | ||
import { MultiBaseEncoder, TypedArrayEncoder, VarintEncoder } from '../utils' | ||
|
||
import { compressIfPossible, expandPublicKeyIfPossible } from './jose/jwk/ecCompression' | ||
import { isEncryptionSupportedForKeyType, isSigningSupportedForKeyType } from './keyUtils' | ||
import { getKeyTypeByMultiCodecPrefix, getMultiCodecPrefixByKeyType } from './multiCodecKey' | ||
|
||
export class Key { | ||
public readonly publicKey: Buffer | ||
public readonly publicKey: Uint8Array | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is quite a big breaking change. Can you add the needed changeset entry? |
||
public readonly keyType: KeyType | ||
|
||
public constructor(publicKey: Uint8Array, keyType: KeyType) { | ||
this.publicKey = Buffer.from(publicKey) | ||
this.publicKey = expandPublicKeyIfPossible(publicKey, keyType) | ||
this.keyType = keyType | ||
} | ||
|
||
public get compressedPublicKey() { | ||
return compressIfPossible(this.publicKey, this.keyType) | ||
} | ||
|
||
public static fromPublicKey(publicKey: Uint8Array, keyType: KeyType) { | ||
return new Key(Buffer.from(publicKey), keyType) | ||
return new Key(publicKey, keyType) | ||
} | ||
|
||
public static fromPublicKeyBase58(publicKey: string, keyType: KeyType) { | ||
const publicKeyBytes = TypedArrayEncoder.fromBase58(publicKey) | ||
const publicKeyBytes = Uint8Array.from(TypedArrayEncoder.fromBase58(publicKey)) | ||
|
||
return Key.fromPublicKey(publicKeyBytes, keyType) | ||
} | ||
|
@@ -28,7 +33,7 @@ export class Key { | |
const { data } = MultiBaseEncoder.decode(fingerprint) | ||
const [code, byteLength] = VarintEncoder.decode(data) | ||
|
||
const publicKey = Buffer.from(data.slice(byteLength)) | ||
const publicKey = data.slice(byteLength) | ||
const keyType = getKeyTypeByMultiCodecPrefix(code) | ||
|
||
return new Key(publicKey, keyType) | ||
|
@@ -40,8 +45,11 @@ export class Key { | |
// Create Buffer with length of the prefix bytes, then use varint to fill the prefix bytes | ||
const prefixBytes = VarintEncoder.encode(multiCodecPrefix) | ||
|
||
// Multicodec requires compressable keys to be compressed | ||
const possiblyCompressedKey = compressIfPossible(this.publicKey, this.keyType) | ||
|
||
// Combine prefix with public key | ||
return Buffer.concat([prefixBytes, this.publicKey]) | ||
return new Uint8Array([...prefixBytes, ...possiblyCompressedKey]) | ||
} | ||
|
||
public get fingerprint() { | ||
|
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
These two should be marked as minor (due to breaking changes)