From 8926d4ee6ac57a60fe096b39a9fbc7bd618dae87 Mon Sep 17 00:00:00 2001 From: Mikhail <16622558+mmv08@users.noreply.github.com> Date: Wed, 28 Aug 2024 13:35:10 +0200 Subject: [PATCH] "Update imports to use 'cbor-web' functions directly" --- modules/passkey/src/utils/webauthn.ts | 6 +++--- modules/passkey/test/utils/webauthnShim.ts | 6 +++--- modules/passkey/test/webauthn/WebAuthnShim.spec.ts | 4 ++-- modules/passkey/tsconfig.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/passkey/src/utils/webauthn.ts b/modules/passkey/src/utils/webauthn.ts index 6e804a312..cbf39d560 100644 --- a/modules/passkey/src/utils/webauthn.ts +++ b/modules/passkey/src/utils/webauthn.ts @@ -1,4 +1,4 @@ -import CBOR from 'cbor-web' +import { decode as cborDecode } from 'cbor-web' /** * Returns the flag for the user verification requirement. @@ -40,7 +40,7 @@ export function base64UrlEncode(data: string | Uint8Array | ArrayBuffer): string * @returns The x and y coordinates of the public key. */ export function decodePublicKey(response: Pick): { x: bigint; y: bigint } { - const attestationObject = CBOR.decode(response.attestationObject) + const attestationObject = cborDecode(response.attestationObject) const authData = new DataView( attestationObject.authData.buffer, attestationObject.authData.byteOffset, @@ -48,7 +48,7 @@ export function decodePublicKey(response: Pick = CBOR.decode(cosePublicKey) + const key: Map = cborDecode(cosePublicKey) const bn = (bytes: Uint8Array) => BigInt('0x' + toHexString(bytes)) return { x: bn(key.get(-2) as Uint8Array), diff --git a/modules/passkey/test/utils/webauthnShim.ts b/modules/passkey/test/utils/webauthnShim.ts index 612fe8178..4ce46a734 100644 --- a/modules/passkey/test/utils/webauthnShim.ts +++ b/modules/passkey/test/utils/webauthnShim.ts @@ -10,7 +10,7 @@ import { p256 } from '@noble/curves/p256' import { ethers } from 'ethers' import type { BytesLike } from 'ethers' -import CBOR from 'cbor-web' +import { encode as cborEncode } from 'cbor-web' import { base64UrlEncode, userVerificationFlag } from '../../src/utils/webauthn' function b2ab(buf: Uint8Array): ArrayBuffer { @@ -135,7 +135,7 @@ class Credential { key.set(1, 2) // kty = EC2 key.set(3, -7) // alg = ES256 (Elliptic curve signature with SHA-256) - return ethers.hexlify(CBOR.encode(key)) + return ethers.hexlify(cborEncode(key)) } } @@ -191,7 +191,7 @@ export class WebAuthnCredentials { rawId: credential.rawId.slice(), response: { clientDataJSON: b2ab(ethers.toUtf8Bytes(JSON.stringify(clientData))), - attestationObject: b2ab(CBOR.encode(attestationObject)), + attestationObject: b2ab(cborEncode(attestationObject)), }, type: 'public-key', } diff --git a/modules/passkey/test/webauthn/WebAuthnShim.spec.ts b/modules/passkey/test/webauthn/WebAuthnShim.spec.ts index 933b7844f..6aae803ec 100644 --- a/modules/passkey/test/webauthn/WebAuthnShim.spec.ts +++ b/modules/passkey/test/webauthn/WebAuthnShim.spec.ts @@ -9,7 +9,7 @@ import { verifyRegistrationResponse, } from '@simplewebauthn/server' import { expect } from 'chai' -import CBOR from 'cbor-web' +import { decode as cborDecode } from 'cbor-web' import { ethers } from 'ethers' import { WebAuthnCredentials } from '../../test/utils/webauthnShim' import { base64UrlEncode } from '../../src/utils/webauthn' @@ -90,7 +90,7 @@ describe('WebAuthn Shim', () => { }, }) - const attestationObject = CBOR.decode(credential.response.attestationObject) + const attestationObject = cborDecode(credential.response.attestationObject) const authData = new DataView( attestationObject.authData.buffer, attestationObject.authData.byteOffset, diff --git a/modules/passkey/tsconfig.json b/modules/passkey/tsconfig.json index 611ba1587..70e136833 100644 --- a/modules/passkey/tsconfig.json +++ b/modules/passkey/tsconfig.json @@ -10,5 +10,5 @@ "skipLibCheck": true, "resolveJsonModule": true }, - "include": ["bin", "src/**/*.ts", "hardhat.config.ts", "test", "typechain-types"] + "include": ["bin", "src/**/*.ts", "hardhat.config.ts", "test/**/*.ts", "typechain-types"] }