Skip to content

Commit 2f80518

Browse files
committed
feat(sdk-core): improve removePasskeyFromAccount and use public-types
- Add device.id validation before DELETE call - Add edge-case tests for missing device.id - Replace local WebAuthnOtpDevice with @bitgo/public-types@6.1.0 WCN-191
1 parent adc3442 commit 2f80518

4 files changed

Lines changed: 21 additions & 9 deletions

File tree

modules/sdk-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
]
4141
},
4242
"dependencies": {
43-
"@bitgo/public-types": "5.97.0",
43+
"@bitgo/public-types": "6.1.0",
4444
"@bitgo/sdk-lib-mpc": "^10.11.1",
4545
"@bitgo/secp256k1": "^1.11.0",
4646
"@bitgo/sjcl": "^1.1.0",

modules/sdk-core/src/bitgo/passkey/removePasskeyFromAccount.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ import { WebAuthnOtpDevice } from './types';
77
*/
88
export async function removePasskeyFromAccount(params: { bitgo: BitGoBase; device: WebAuthnOtpDevice }): Promise<void> {
99
const { bitgo, device } = params;
10+
if (!device.id) {
11+
throw new Error('device.id is required to remove a passkey from the account');
12+
}
1013
await bitgo.del(bitgo.url(`/user/otp/${device.id}`)).result();
1114
}
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
// TODO: replace with: export type { WebAuthnOtpDevice } from '@bitgo/public-types'
2-
export interface WebAuthnOtpDevice {
3-
id: string; // serialized MongoDB _id — used for DELETE
4-
credentialId: string; // from authenticatorInfo.credID
5-
prfSalt?: string;
6-
isPasskey?: boolean;
7-
extensions?: Record<string, boolean>;
8-
}
1+
export type { WebAuthnOtpDevice } from '@bitgo/public-types';

modules/sdk-core/test/unit/bitgo/passkey/removePasskeyFromAccount.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,20 @@ describe('removePasskeyFromAccount', function () {
4949
const result = await removePasskeyFromAccount({ bitgo: mockBitGo as any, device });
5050
assert.strictEqual(result, undefined);
5151
});
52+
53+
it('should throw if device.id is empty', async function () {
54+
const badDevice: WebAuthnOtpDevice = { ...device, id: '' };
55+
await assert.rejects(() => removePasskeyFromAccount({ bitgo: mockBitGo as any, device: badDevice }), {
56+
message: 'device.id is required to remove a passkey from the account',
57+
});
58+
assert.strictEqual(mockBitGo.del.called, false);
59+
});
60+
61+
it('should throw if device.id is undefined', async function () {
62+
const badDevice = { ...device, id: undefined } as unknown as WebAuthnOtpDevice;
63+
await assert.rejects(() => removePasskeyFromAccount({ bitgo: mockBitGo as any, device: badDevice }), {
64+
message: 'device.id is required to remove a passkey from the account',
65+
});
66+
assert.strictEqual(mockBitGo.del.called, false);
67+
});
5268
});

0 commit comments

Comments
 (0)