Skip to content

Commit

Permalink
"Update imports to use 'cbor-web' functions directly"
Browse files Browse the repository at this point in the history
  • Loading branch information
mmv08 committed Aug 28, 2024
1 parent 7d6db7f commit 8926d4e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions modules/passkey/src/utils/webauthn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import CBOR from 'cbor-web'
import { decode as cborDecode } from 'cbor-web'

/**
* Returns the flag for the user verification requirement.
Expand Down Expand Up @@ -40,15 +40,15 @@ export function base64UrlEncode(data: string | Uint8Array | ArrayBuffer): string
* @returns The x and y coordinates of the public key.
*/
export function decodePublicKey(response: Pick<AuthenticatorAttestationResponse, 'attestationObject'>): { 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,
attestationObject.authData.byteLength,
)
const credentialIdLength = authData.getUint16(53)
const cosePublicKey = attestationObject.authData.slice(55 + credentialIdLength)
const key: Map<number, unknown> = CBOR.decode(cosePublicKey)
const key: Map<number, unknown> = cborDecode(cosePublicKey)
const bn = (bytes: Uint8Array) => BigInt('0x' + toHexString(bytes))
return {
x: bn(key.get(-2) as Uint8Array),
Expand Down
6 changes: 3 additions & 3 deletions modules/passkey/test/utils/webauthnShim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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',
}
Expand Down
4 changes: 2 additions & 2 deletions modules/passkey/test/webauthn/WebAuthnShim.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion modules/passkey/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}

0 comments on commit 8926d4e

Please sign in to comment.