-
Notifications
You must be signed in to change notification settings - Fork 586
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
refactor(crypto): remove circular dependency #1942
Closed
matthieusieben
wants to merge
5
commits into
bluesky-social:main
from
matthieusieben:fix-crypto-circular-dep
Closed
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ef961a9
refactor(crypto): remove circular dependency
matthieusieben 64270cf
refactor(crypto): expose compress/decompress as part of the DidKeyPlu…
matthieusieben bfce7cb
fix(crypto): remove import from private file
matthieusieben f192f19
style(crypto): rename imports from uint8arrays
matthieusieben 6e499a9
Merge remote-tracking branch 'origin/main' into fix-crypto-circular-dep
matthieusieben 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
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,11 +1,16 @@ | ||
import * as operations from './operations' | ||
import { verifyDidSig } from './operations' | ||
import { compressPubkey, decompressPubkey } from './encoding' | ||
|
||
import { DidKeyPlugin } from '../types' | ||
import { P256_DID_PREFIX, P256_JWT_ALG } from '../const' | ||
|
||
export const p256Plugin: DidKeyPlugin = { | ||
prefix: P256_DID_PREFIX, | ||
jwtAlg: P256_JWT_ALG, | ||
verifySignature: operations.verifyDidSig, | ||
verifySignature: verifyDidSig, | ||
|
||
compressPubkey, | ||
decompressPubkey, | ||
} | ||
|
||
export default p256Plugin |
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,11 +1,16 @@ | ||
import * as operations from './operations' | ||
import { verifyDidSig } from './operations' | ||
import { compressPubkey, decompressPubkey } from './encoding' | ||
|
||
import { DidKeyPlugin } from '../types' | ||
import { SECP256K1_DID_PREFIX, SECP256K1_JWT_ALG } from '../const' | ||
|
||
export const secp256k1Plugin: DidKeyPlugin = { | ||
prefix: SECP256K1_DID_PREFIX, | ||
jwtAlg: SECP256K1_JWT_ALG, | ||
verifySignature: operations.verifyDidSig, | ||
verifySignature: verifyDidSig, | ||
|
||
compressPubkey, | ||
decompressPubkey, | ||
} | ||
|
||
export default secp256k1Plugin |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as uint8arrays from 'uint8arrays' | ||
import { BASE58_MULTIBASE_PREFIX, DID_KEY_PREFIX } from './const' | ||
|
||
export const extractMultikey = (did: string): string => { | ||
if (!did.startsWith(DID_KEY_PREFIX)) { | ||
throw new Error(`Incorrect prefix for did:key: ${did}`) | ||
} | ||
return did.slice(DID_KEY_PREFIX.length) | ||
} | ||
|
||
export const extractPrefixedBytes = (multikey: string): Uint8Array => { | ||
if (!multikey.startsWith(BASE58_MULTIBASE_PREFIX)) { | ||
throw new Error(`Incorrect prefix for multikey: ${multikey}`) | ||
} | ||
return uint8arrays.fromString( | ||
multikey.slice(BASE58_MULTIBASE_PREFIX.length), | ||
'base58btc', | ||
) | ||
} | ||
|
||
export const hasPrefix = (bytes: Uint8Array, prefix: Uint8Array): boolean => { | ||
return uint8arrays.equals(prefix, bytes.subarray(0, prefix.byteLength)) | ||
} |
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.
is there a reason to import this as just
toString
? if so I think it'd be nice to import it as something likeui8ToString
or similar. otherwisetoString
is pretty generic & gotta check imports to see what it's coming from