Skip to content

Commit

Permalink
pacify linter pt2
Browse files Browse the repository at this point in the history
  • Loading branch information
ukstv committed Nov 24, 2023
1 parent 329437b commit 6a60f69
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/varsig/src/canons/jws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ export function prepareCanonicalization(
): CanonicalizationAlgo {
const protectedLength = tape.readVarint()
const protectedBytes = tape.read(protectedLength)
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const protected1 = JSON.parse(uint8arrays.toString(protectedBytes))

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const keyTypeFromProtected = findKeyType(protected1)
if (keyType !== keyTypeFromProtected)
throw new Error(`Key type missmatch: ${keyType}, ${keyTypeFromProtected}`)
Expand All @@ -62,12 +64,14 @@ export function prepareCanonicalization(

export function fromOriginal(jws: string): IpldNodeSigned {
const [protectedB64u, payloadB64u, signatureB64u] = jws.split('.')
const node = decode(fromB64u(payloadB64u))
const node = decode<Record<string, any>>(fromB64u(payloadB64u))
const protectedBytes = fromB64u(protectedB64u)
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const protected1 = JSON.parse(uint8arrays.toString(protectedBytes))
const protectedLength = varintes.encode(protectedBytes.length)[0]
const signature = fromB64u(signatureB64u)

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const keyType = findKeyType(protected1)
const hashType = HASH_BY_KEY_TYPE[keyType]

Expand All @@ -81,6 +85,7 @@ export function fromOriginal(jws: string): IpldNodeSigned {
protectedBytes,
signature,
])
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return { ...node, _sig: varsig }
}

Expand All @@ -92,6 +97,6 @@ interface ProtectedHeader {
function findKeyType({ alg, crv }: ProtectedHeader): number {
if (!alg) throw new Error(`Missing alg in protected header`)
const keyType = KEY_TYPE_BY_ALG_CRV[alg][crv || 'default']
if (!keyType) throw new Error(`Unsupported alg: ${alg}, or crv: ${crv}`)
if (!keyType) throw new Error(`Unsupported alg: ${alg}, or crv: ${String(crv)}`)
return keyType
}

0 comments on commit 6a60f69

Please sign in to comment.