Skip to content

Commit

Permalink
Broke the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oed committed Nov 24, 2023
1 parent cb642f5 commit ee57f90
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
23 changes: 22 additions & 1 deletion packages/varsig/src/__tests__/eip712-secp256k1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Decoder } from '../decoder'
import * as uint8arrays from 'uint8arrays'
import { CanonicalizationKind } from '../canonicalization.js'
import { Eip712, EIP712_DOMAIN, fromOriginal } from '../canons/eip712.js'
import { toOriginal } from '../varsig.js'
import { verify, toOriginal } from '../varsig.js'
import { klona } from 'klona'

const factory = new CARFactory()
Expand Down Expand Up @@ -71,3 +71,24 @@ test('eip712-secp256k1.car', async () => {
}
}
})

test('eip712-secp256k1.car verify signature', async () => {
const carFilepath = new URL('./__vectors__/eip712-secp256k1.car', import.meta.url)
const carBytes = await readFile(carFilepath)
const 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
const entries = root.entries as Array<CID>
for (const entryCID of entries) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const entry = car.get(entryCID)
const node = car.get(entry.node)
console.log('time', node)

const verificationKey = entry.signer.address || uint8arrays.fromString(entry.signer.publicKey.slice(2))

expect(await verify(node, verificationKey)).toEqual(entry.valid)
}
})
5 changes: 3 additions & 2 deletions packages/varsig/src/varsig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Decoder } from './decoder.js'
import { CanonicalizationKind } from './canonicalization.js'
import { BytesTape } from './bytes-tape.js'
import { CanonicalizationKind } from './canonicalization.js'
import { klona } from 'klona'

export { Eip712 } from './canons/eip712'
Expand All @@ -19,8 +19,9 @@ export async function verify(
node: VarsigNode,
verificationKey: PublicKey | EthAddress
): Promise<boolean> {
const tape = new BytesTape(node._sig)
// @ts-ignore
const { canonicalization, signing, signature } = new Decoder(node._sig).read()
const { canonicalization, signing, signature } = new Decoder(tape).read()

// @ts-ignore
delete node._sig
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ee57f90

Please sign in to comment.