Skip to content

Commit

Permalink
test: Safari 17 now supports Ed25519
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Oct 2, 2023
1 parent 5e59705 commit 9cda901
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
9 changes: 8 additions & 1 deletion tap/cookbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import jwsVectors from '../cookbook/jws.mjs'
// @ts-ignore
import jweVectors from '../cookbook/jwe.mjs'

// TODO: raise in issue in WebKit
if (env.isWebKit) {
// @ts-ignore
const ed25519 = jwsVectors.find((vector) => vector.title.includes('Ed25519'))
ed25519.reproducible = false
}

export default (QUnit: QUnit, lib: typeof jose) => {
const { module, test } = QUnit

Expand Down Expand Up @@ -34,7 +41,7 @@ export default (QUnit: QUnit, lib: typeof jose) => {
return !env.isDeno
}
if (vector.input.alg === 'EdDSA') {
return !env.isBrowser
return (env.isWebKit && env.isWebKitAbove17) || !env.isBrowser
}
return true
}
Expand Down
17 changes: 15 additions & 2 deletions tap/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,27 @@ export const isWorkerd =

const BOWSER = 'https://cdn.jsdelivr.net/npm/[email protected]/src/bowser.js'

async function isEngine(engine: string) {
let parsedUserAgent: any
async function parseUserAgent() {
const { default: Bowser } = await import(BOWSER)
return Bowser.parse(window.navigator.userAgent).engine.name === engine
parsedUserAgent || (parsedUserAgent = Bowser.parse(window.navigator.userAgent))
return parsedUserAgent
}

async function isEngine(engine: string) {
const userAgentData = await parseUserAgent()
return userAgentData.engine.name === engine
}

async function isVersionAtLeast(version: number) {
const userAgentData = await parseUserAgent()
return parseInt(userAgentData.browser.version.split('.')[0], 10) >= version
}

export const isBlink = isBrowser && (await isEngine('Blink'))

export const isWebKit = isBrowser && (await isEngine('WebKit'))
export const isWebKitAbove17 = isBrowser && isWebKit && (await isVersionAtLeast(17))

export const isGecko = isBrowser && (await isEngine('Gecko'))

Expand Down
2 changes: 1 addition & 1 deletion tap/jwk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default (QUnit: QUnit, lib: typeof jose) => {
env.isDeno,
],
['ECDH-ES', KEYS.X448.jwk, env.isNode || env.isEdgeRuntime],
['EdDSA', KEYS.Ed25519.jwk, !env.isBrowser],
['EdDSA', KEYS.Ed25519.jwk, (env.isWebKit && env.isWebKitAbove17) || !env.isBrowser],
['EdDSA', KEYS.Ed448.jwk, env.isNode || env.isEdgeRuntime],
['ES256', KEYS.P256.jwk, true],
['ES256K', KEYS.secp256k1.jwk, env.isNodeCrypto],
Expand Down
2 changes: 1 addition & 1 deletion tap/jws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default (QUnit: QUnit, lib: typeof jose) => {

type Vector = [string, boolean] | [string, boolean, jose.GenerateKeyPairOptions]
const algorithms: Vector[] = [
['EdDSA', !env.isBrowser],
['EdDSA', (env.isWebKit && env.isWebKitAbove17) || !env.isBrowser],
['EdDSA', env.isNode || env.isEdgeRuntime, { crv: 'Ed448' }],
['ES256', true],
['ES256K', env.isNodeCrypto],
Expand Down
18 changes: 15 additions & 3 deletions tap/pem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,21 @@ export default (QUnit: QUnit, lib: typeof jose) => {
],
[['ECDH-ES', 'X448'], KEYS.X448.pkcs8, env.isNode || env.isEdgeRuntime],
[['ECDH-ES', 'X448'], KEYS.X448.spki, env.isNode || env.isEdgeRuntime],
[['EdDSA', 'Ed25519'], KEYS.Ed25519.pkcs8, !env.isBrowser],
[['EdDSA', 'Ed25519'], KEYS.Ed25519.spki, !env.isBrowser],
[['EdDSA', 'Ed25519'], KEYS.Ed25519.x509, !env.isBrowser],
[
['EdDSA', 'Ed25519'],
KEYS.Ed25519.pkcs8,
(env.isWebKit && env.isWebKitAbove17) || !env.isBrowser,
],
[
['EdDSA', 'Ed25519'],
KEYS.Ed25519.spki,
(env.isWebKit && env.isWebKitAbove17) || !env.isBrowser,
],
[
['EdDSA', 'Ed25519'],
KEYS.Ed25519.x509,
(env.isWebKit && env.isWebKitAbove17) || !env.isBrowser,
],
[['EdDSA', 'Ed448'], KEYS.Ed448.pkcs8, env.isNode || env.isEdgeRuntime],
[['EdDSA', 'Ed448'], KEYS.Ed448.spki, env.isNode || env.isEdgeRuntime],
[['EdDSA', 'Ed448'], KEYS.Ed448.x509, env.isNode || env.isEdgeRuntime],
Expand Down

0 comments on commit 9cda901

Please sign in to comment.