(username: string)
| 165 | } |
| 166 | |
| 167 | export async function register(username: string): Promise<boolean> { |
| 168 | try { |
| 169 | const publicKey = (await getPublicKey( |
| 170 | username, |
| 171 | true |
| 172 | )) as PublicKeyCredentialCreationOptions |
| 173 | console.log('registration response:', publicKey.user, typeof publicKey.user) |
| 174 | publicKey.user.id = asArrayBuffer(publicKey.user.id as unknown as string) |
| 175 | publicKey.challenge = asArrayBuffer( |
| 176 | publicKey.challenge as unknown as string |
| 177 | ) |
| 178 | const creds = await navigator.credentials.create({ publicKey }) |
| 179 | await post(username, creds as PublicKeyCredential, true) |
| 180 | return true |
| 181 | } catch (error) { |
| 182 | if (error instanceof Error) { |
| 183 | // TODO: this is hacky but works |
| 184 | if (error.toString().includes('User already exists')) { |
| 185 | return false |
| 186 | } |
| 187 | throw error |
| 188 | } else { |
| 189 | throw new TypeError(`Unkown error: ${String(error)}`) |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | export async function auth(username: string): Promise<boolean> { |
| 195 | const publicKey = (await getPublicKey( |
nothing calls this directly
no test coverage detected