Skip to content

Commit

Permalink
backup: export getBackupId/getBackupLevel for node
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny-signal authored Oct 3, 2024
1 parent 5b5864f commit 8ae1a5d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions node/Native.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ export function AuthCredentialPresentation_GetUuidCiphertext(presentationBytes:
export function AuthCredentialWithPniResponse_CheckValidContents(bytes: Buffer): void;
export function AuthCredentialWithPni_CheckValidContents(bytes: Buffer): void;
export function BackupAuthCredentialPresentation_CheckValidContents(presentationBytes: Buffer): void;
export function BackupAuthCredentialPresentation_GetBackupId(presentationBytes: Buffer): Buffer;
export function BackupAuthCredentialPresentation_GetBackupLevel(presentationBytes: Buffer): number;
export function BackupAuthCredentialPresentation_Verify(presentationBytes: Buffer, now: Timestamp, serverParamsBytes: Buffer): void;
export function BackupAuthCredentialRequestContext_CheckValidContents(contextBytes: Buffer): void;
export function BackupAuthCredentialRequestContext_GetRequest(contextBytes: Buffer): Buffer;
Expand Down
6 changes: 6 additions & 0 deletions node/ts/test/ZKGroup-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,12 @@ describe('ZKGroup', () => {
);
assert.equal(backupLevel, credential.getBackupLevel());
assertArrayEquals(SERIALIZED_BACKUP_ID, credential.getBackupId());

const presentation = credential.present(
serverSecretParams.getPublicParams()
);
assert.equal(backupLevel, presentation.getBackupLevel());
assertArrayEquals(SERIALIZED_BACKUP_ID, presentation.getBackupId());
});

it('testIntegration', () => {
Expand Down
15 changes: 15 additions & 0 deletions node/ts/zkgroup/backups/BackupAuthCredentialPresentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ByteArray from '../internal/ByteArray';
import * as Native from '../../../Native';

import GenericServerSecretParams from '../GenericServerSecretParams';
import BackupLevel from './BackupLevel';

export default class BackupAuthCredentialPresentation extends ByteArray {
private readonly __type?: never;
Expand All @@ -25,4 +26,18 @@ export default class BackupAuthCredentialPresentation extends ByteArray {
serverParams.contents
);
}

getBackupId(): Buffer {
return Native.BackupAuthCredentialPresentation_GetBackupId(this.contents);
}

getBackupLevel(): BackupLevel {
const n: number = Native.BackupAuthCredentialPresentation_GetBackupLevel(
this.contents
);
if (!(n in BackupLevel)) {
throw new TypeError(`Invalid BackupLevel ${n}`);
}
return n;
}
}
4 changes: 2 additions & 2 deletions rust/bridge/shared/src/zkgroup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,14 +1024,14 @@ fn BackupAuthCredentialPresentation_Verify(
presentation.verify(now, &server_params)
}

#[bridge_fn(ffi = false, node = false)]
#[bridge_fn(ffi = false)]
fn BackupAuthCredentialPresentation_GetBackupId(presentation_bytes: &[u8]) -> [u8; 16] {
let presentation = bincode::deserialize::<BackupAuthCredentialPresentation>(presentation_bytes)
.expect("should have been parsed previously");
presentation.backup_id()
}

#[bridge_fn(ffi = false, node = false)]
#[bridge_fn(ffi = false)]
fn BackupAuthCredentialPresentation_GetBackupLevel(presentation_bytes: &[u8]) -> u8 {
let presentation = bincode::deserialize::<BackupAuthCredentialPresentation>(presentation_bytes)
.expect("should have been parsed previously");
Expand Down

0 comments on commit 8ae1a5d

Please sign in to comment.