Skip to content

Commit

Permalink
eslint, plz don't mind my test
Browse files Browse the repository at this point in the history
  • Loading branch information
oed committed Feb 8, 2024
1 parent f4911bb commit d9b24b0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 27 deletions.
7 changes: 5 additions & 2 deletions packages/varsig/src/__tests__/eip712-fixtures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ describe('eip712-secp256k1.car', () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
originalKlone.signature =
'0x' +
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
uint8arrays.toString(uint8arrays.concat([r, s, new Uint8Array([originalKlone.signature.v])]), 'hex')
uint8arrays.toString(
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
uint8arrays.concat([r, s, new Uint8Array([originalKlone.signature.v])]),
'hex',
)
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-argument
Expand Down
20 changes: 1 addition & 19 deletions packages/varsig/src/__tests__/jws-fixtures.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
import { readFile } from 'node:fs/promises'
import { expect, test } from '@jest/globals'
import { CARFactory, type CAR } from 'cartonne'
Expand All @@ -15,10 +16,8 @@ describe('jws.car', () => {
const carFilepath = new URL('./__vectors__/jws.car', import.meta.url)
const carBytes = await readFile(carFilepath)
car = factory.fromBytes(carBytes)
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const root = car.get(car.roots[0])
if (!root) throw new Error(`Empty root`)
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
entries = root.entries as Array<CID>
})

Expand All @@ -28,36 +27,25 @@ describe('jws.car', () => {

test('Verify signatures', async () => {
for (const entryCID of entries) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const entry = car.get(entryCID)
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
const node = car.get(entry.node)

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const verificationKey = entry.signer.verificationKey

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (entry.valid) {
// eslint-disable-next-line jest/no-conditional-expect,@typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
await expect(verify(node, verificationKey)).resolves.toEqual(entry.valid)
} else {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const verificationP = verify(node, verificationKey).catch(() => false)
// eslint-disable-next-line jest/no-conditional-expect
await expect(verificationP).resolves.toEqual(false)
}
}
})

test('Create varsig ipld node', () => {
for (const entryCID of entries) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const entry = car.get(entryCID)
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
if (!entry.original) continue
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument
const original = car.get(entry.original)
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument
const node = car.get(entry.node)
if (entry.valid) {
const varsigNode = JWS.fromOriginal(original)
Expand All @@ -79,18 +67,12 @@ describe('jws.car', () => {

test('Recover original from ipld node', async () => {
for (const entryCID of entries) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const entry = car.get(entryCID)
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
if (!entry.original) continue
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument
const originalExpected = car.get(entry.original)
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
const node = car.get(entry.node)
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const originalKlone = klona(originalExpected)

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-argument
if (entry.valid) {
const originalRecovered = await toOriginal(node)
expect(originalRecovered).toEqual(originalKlone)
Expand Down
7 changes: 5 additions & 2 deletions packages/varsig/src/canons/eip712.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ export function prepareCanonicalization(
hashing: HashingAlgo,
keyType: SigningKind,
): CanonicalizationAlgo {
if (hashing.kind !== SUPPORTED_HASH_TYPE) throw new Error(`Unsupported hash type: ${hashing}`)
if (hashing.kind !== SUPPORTED_HASH_TYPE)
throw new Error(`Unsupported hash type: ${hashing.kind}`)
if (!SUPPORTED_KEY_TYPES.includes(keyType)) throw new Error(`Unsupported key type: ${keyType}`)
const metadataLength = tape.readVarint()
const metadataBytes = tape.read(metadataLength)
Expand All @@ -189,7 +190,9 @@ export function prepareCanonicalization(
const original = (node: IpldNode, signature: Uint8Array, recoveryBit: number | undefined) => {
const message = ipldNodeToMessage(node)

const sigBytes = recoveryBit ? uint8arrays.concat([signature, new Uint8Array([recoveryBit])]) : signature
const sigBytes = recoveryBit
? uint8arrays.concat([signature, new Uint8Array([recoveryBit])])
: signature
const sigHex = `0x${uint8arrays.toString(sigBytes, 'base16')}`
return { ...metadata, message, signature: sigHex }
}
Expand Down
3 changes: 1 addition & 2 deletions packages/varsig/src/signing/ed25519.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import type { BytesTape } from '../bytes-tape.js'

const SIGIL = MAGIC.ED25519

// @ts-ignore
function prepareVerifier(tape: BytesTape): SigningAlgo {
function prepareVerifier(_: BytesTape): SigningAlgo {
return {
kind: SIGIL,
// eslint-disable-next-line @typescript-eslint/require-await
Expand Down
3 changes: 1 addition & 2 deletions packages/varsig/src/signing/p256.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import type { BytesTape } from '../bytes-tape.js'

const SIGIL = MAGIC.ES256

// @ts-ignore
function prepareVerifier(tape: BytesTape): SigningAlgo {
function prepareVerifier(_: BytesTape): SigningAlgo {
return {
kind: SIGIL,
// eslint-disable-next-line @typescript-eslint/require-await
Expand Down

0 comments on commit d9b24b0

Please sign in to comment.