Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: bluesky-social/atproto
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: fa90c3f6a2052e1adbdae0b59fd4953c96bc0bd4
Choose a base ref
..
head repository: bluesky-social/atproto
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5241de05730af38806dbe69159086ed01b793feb
Choose a head ref
Showing with 12 additions and 14 deletions.
  1. +12 −14 packages/jwk-webcrypto/src/util.ts
26 changes: 12 additions & 14 deletions packages/jwk-webcrypto/src/util.ts
Original file line number Diff line number Diff line change
@@ -142,28 +142,26 @@ export async function generateKeypair(
throw new AggregateError(errors, 'Failed to generate keypair')
}

const PREFERED_FAMILY = ['ES', 'PS', 'RS']
/**
* 256K > ES (256 > 384 > 512) > PS (256 > 384 > 512) > RS (256 > 384 > 512) > other (in original order)
*/
function compareAlgos(a: string, b: string): number {
if (a === 'ES256K') return -1
if (b === 'ES256K') return 1

const aFam = a.slice(0, 2)
const bFam = b.slice(0, 2)
for (const prefix of ['ES', 'PS', 'RS']) {
if (a.startsWith(prefix)) {
if (b.startsWith(prefix)) {
const aLen = parseInt(a.slice(2, 5))
const bLen = parseInt(b.slice(2, 5))

const aFamIdx = PREFERED_FAMILY.indexOf(aFam)
const bFamIdx = PREFERED_FAMILY.indexOf(bFam)
if (aFamIdx !== -1 || bFamIdx !== -1) {
if (aFamIdx === -1) return 1
if (bFamIdx === -1) return -1
if (aFamIdx !== bFamIdx) return aFamIdx - bFamIdx

// Prefer shorter key lengths
const aLen = parseInt(a.slice(2, 5))
const bLen = parseInt(b.slice(2, 5))
return aLen - bLen
// Prefer shorter key lengths
return aLen - bLen
}
return -1
} else if (b.startsWith(prefix)) {
return 1
}
}

// Don't know how to compare, keep original order