Skip to content

Commit

Permalink
Node: Force nominal typing for zkgroup ByteArray subclasses
Browse files Browse the repository at this point in the history
Without this, two ByteArray types without any additional operations
are structurally equivalent, and so TypeScript permits passing one as
the other. (Thanks, Fedor!)
  • Loading branch information
jrose-signal committed Jun 17, 2022
1 parent 395e36e commit 9e6343b
Showing 32 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions node/ts/zkgroup/NotarySignature.ts
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import ByteArray from './internal/ByteArray';

export default class NotarySignature extends ByteArray {
private readonly __type?: never;
static SIZE = 64;

constructor(contents: Buffer) {
2 changes: 2 additions & 0 deletions node/ts/zkgroup/ServerPublicParams.ts
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@ import * as Native from '../../Native';
import NotarySignature from './NotarySignature';

export default class ServerPublicParams extends ByteArray {
private readonly __type?: never;

constructor(contents: Buffer) {
super(contents, Native.ServerPublicParams_CheckValidContents);
}
2 changes: 2 additions & 0 deletions node/ts/zkgroup/ServerSecretParams.ts
Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@ import ServerPublicParams from './ServerPublicParams';
import NotarySignature from './NotarySignature';

export default class ServerSecretParams extends ByteArray {
private readonly __type?: never;

static generate(): ServerSecretParams {
const random = randomBytes(RANDOM_LENGTH);

2 changes: 2 additions & 0 deletions node/ts/zkgroup/auth/AuthCredential.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ import ByteArray from '../internal/ByteArray';
import * as Native from '../../../Native';

export default class AuthCredential extends ByteArray {
private readonly __type?: never;

constructor(contents: Buffer) {
super(contents, Native.AuthCredential_CheckValidContents);
}
2 changes: 2 additions & 0 deletions node/ts/zkgroup/auth/AuthCredentialPresentation.ts
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@ import * as Native from '../../../Native';
import UuidCiphertext from '../groups/UuidCiphertext';

export default class AuthCredentialPresentation extends ByteArray {
private readonly __type?: never;

constructor(contents: Buffer) {
super(contents, Native.AuthCredentialPresentation_CheckValidContents);
}
3 changes: 3 additions & 0 deletions node/ts/zkgroup/auth/AuthCredentialResponse.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,10 @@

import ByteArray from '../internal/ByteArray';
import * as Native from '../../../Native';

export default class AuthCredentialResponse extends ByteArray {
private readonly __type?: never;

constructor(contents: Buffer) {
super(contents, Native.AuthCredentialResponse_CheckValidContents);
}
1 change: 1 addition & 0 deletions node/ts/zkgroup/groups/GroupIdentifier.ts
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import ByteArray from '../internal/ByteArray';

export default class GroupIdentifier extends ByteArray {
private readonly __type?: never;
static SIZE = 32;

constructor(contents: Buffer) {
1 change: 1 addition & 0 deletions node/ts/zkgroup/groups/GroupMasterKey.ts
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import ByteArray from '../internal/ByteArray';

export default class GroupMasterKey extends ByteArray {
private readonly __type?: never;
static SIZE = 32;

constructor(contents: Buffer) {
2 changes: 2 additions & 0 deletions node/ts/zkgroup/groups/GroupPublicParams.ts
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@ import * as Native from '../../../Native';
import GroupIdentifier from './GroupIdentifier';

export default class GroupPublicParams extends ByteArray {
private readonly __type?: never;

constructor(contents: Buffer) {
super(contents, Native.GroupPublicParams_CheckValidContents);
}
2 changes: 2 additions & 0 deletions node/ts/zkgroup/groups/GroupSecretParams.ts
Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@ import GroupMasterKey from './GroupMasterKey';
import GroupPublicParams from './GroupPublicParams';

export default class GroupSecretParams extends ByteArray {
private readonly __type?: never;

static generate(): GroupSecretParams {
const random = randomBytes(RANDOM_LENGTH);

2 changes: 2 additions & 0 deletions node/ts/zkgroup/groups/ProfileKeyCiphertext.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ import ByteArray from '../internal/ByteArray';
import * as Native from '../../../Native';

export default class ProfileKeyCiphertext extends ByteArray {
private readonly __type?: never;

constructor(contents: Buffer) {
super(contents, Native.ProfileKeyCiphertext_CheckValidContents);
}
2 changes: 2 additions & 0 deletions node/ts/zkgroup/groups/UuidCiphertext.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ import ByteArray from '../internal/ByteArray';
import * as Native from '../../../Native';

export default class UuidCiphertext extends ByteArray {
private readonly __type?: never;

constructor(contents: Buffer) {
super(contents, Native.UuidCiphertext_CheckValidContents);
}
2 changes: 2 additions & 0 deletions node/ts/zkgroup/profiles/ExpiringProfileKeyCredential.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ import ByteArray from '../internal/ByteArray';
import * as Native from '../../../Native';

export default class ExpiringProfileKeyCredential extends ByteArray {
private readonly __type?: never;

constructor(contents: Buffer) {
super(contents, Native.ExpiringProfileKeyCredential_CheckValidContents);
}
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ import ByteArray from '../internal/ByteArray';
import * as Native from '../../../Native';

export default class ExpiringProfileKeyCredentialResponse extends ByteArray {
private readonly __type?: never;

constructor(contents: Buffer) {
super(
contents,
2 changes: 2 additions & 0 deletions node/ts/zkgroup/profiles/PniCredential.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ import ByteArray from '../internal/ByteArray';
import * as Native from '../../../Native';

export default class PniCredential extends ByteArray {
private readonly __type?: never;

constructor(contents: Buffer) {
super(contents, Native.PniCredential_CheckValidContents);
}
2 changes: 2 additions & 0 deletions node/ts/zkgroup/profiles/PniCredentialPresentation.ts
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@ import UuidCiphertext from '../groups/UuidCiphertext';
import ProfileKeyCiphertext from '../groups/ProfileKeyCiphertext';

export default class PniCredentialPresentation extends ByteArray {
private readonly __type?: never;

constructor(contents: Buffer) {
super(contents, Native.PniCredentialPresentation_CheckValidContents);
}
2 changes: 2 additions & 0 deletions node/ts/zkgroup/profiles/PniCredentialRequestContext.ts
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@ import * as Native from '../../../Native';
import ProfileKeyCredentialRequest from './ProfileKeyCredentialRequest';

export default class PniCredentialRequestContext extends ByteArray {
private readonly __type?: never;

constructor(contents: Buffer) {
super(contents, Native.PniCredentialRequestContext_CheckValidContents);
}
2 changes: 2 additions & 0 deletions node/ts/zkgroup/profiles/PniCredentialResponse.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ import ByteArray from '../internal/ByteArray';
import * as Native from '../../../Native';

export default class PniCredentialResponse extends ByteArray {
private readonly __type?: never;

constructor(contents: Buffer) {
super(contents, Native.PniCredentialResponse_CheckValidContents);
}
1 change: 1 addition & 0 deletions node/ts/zkgroup/profiles/ProfileKey.ts
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ import ProfileKeyVersion from './ProfileKeyVersion';
import { UUIDType, fromUUID } from '../internal/UUIDUtil';

export default class ProfileKey extends ByteArray {
private readonly __type?: never;
static SIZE = 32;

constructor(contents: Buffer) {
2 changes: 2 additions & 0 deletions node/ts/zkgroup/profiles/ProfileKeyCommitment.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ import ByteArray from '../internal/ByteArray';
import * as Native from '../../../Native';

export default class ProfileKeyCommitment extends ByteArray {
private readonly __type?: never;

constructor(contents: Buffer) {
super(contents, Native.ProfileKeyCommitment_CheckValidContents);
}
2 changes: 2 additions & 0 deletions node/ts/zkgroup/profiles/ProfileKeyCredential.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ import ByteArray from '../internal/ByteArray';
import * as Native from '../../../Native';

export default class ProfileKeyCredential extends ByteArray {
private readonly __type?: never;

constructor(contents: Buffer) {
super(contents, Native.ProfileKeyCredential_CheckValidContents);
}
2 changes: 2 additions & 0 deletions node/ts/zkgroup/profiles/ProfileKeyCredentialPresentation.ts
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@ import UuidCiphertext from '../groups/UuidCiphertext';
import ProfileKeyCiphertext from '../groups/ProfileKeyCiphertext';

export default class ProfileKeyCredentialPresentation extends ByteArray {
private readonly __type?: never;

constructor(contents: Buffer) {
super(contents, Native.ProfileKeyCredentialPresentation_CheckValidContents);
}
2 changes: 2 additions & 0 deletions node/ts/zkgroup/profiles/ProfileKeyCredentialRequest.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ import ByteArray from '../internal/ByteArray';
import * as Native from '../../../Native';

export default class ProfileKeyCredentialRequest extends ByteArray {
private readonly __type?: never;

constructor(contents: Buffer) {
super(contents, Native.ProfileKeyCredentialRequest_CheckValidContents);
}
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@ import * as Native from '../../../Native';
import ProfileKeyCredentialRequest from './ProfileKeyCredentialRequest';

export default class ProfileKeyCredentialRequestContext extends ByteArray {
private readonly __type?: never;

constructor(contents: Buffer) {
super(
contents,
2 changes: 2 additions & 0 deletions node/ts/zkgroup/profiles/ProfileKeyCredentialResponse.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ import ByteArray from '../internal/ByteArray';
import * as Native from '../../../Native';

export default class ProfileKeyCredentialResponse extends ByteArray {
private readonly __type?: never;

constructor(contents: Buffer) {
super(contents, Native.ProfileKeyCredentialResponse_CheckValidContents);
}
1 change: 1 addition & 0 deletions node/ts/zkgroup/profiles/ProfileKeyVersion.ts
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import ByteArray from '../internal/ByteArray';

export default class ProfileKeyVersion extends ByteArray {
private readonly __type?: never;
static SIZE = 64;

constructor(contents: Buffer | string) {
2 changes: 2 additions & 0 deletions node/ts/zkgroup/receipts/ReceiptCredential.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ import ByteArray from '../internal/ByteArray';
import * as Native from '../../../Native';

export default class ReceiptCredential extends ByteArray {
private readonly __type?: never;

constructor(contents: Buffer) {
super(contents, Native.ReceiptCredential_CheckValidContents);
}
1 change: 1 addition & 0 deletions node/ts/zkgroup/receipts/ReceiptCredentialPresentation.ts
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import * as Native from '../../../Native';
import ReceiptSerial from './ReceiptSerial';

export default class ReceiptCredentialPresentation extends ByteArray {
private readonly __type?: never;
static SIZE = 329;

constructor(contents: Buffer) {
2 changes: 2 additions & 0 deletions node/ts/zkgroup/receipts/ReceiptCredentialRequest.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ import ByteArray from '../internal/ByteArray';
import * as Native from '../../../Native';

export default class ReceiptCredentialRequest extends ByteArray {
private readonly __type?: never;

constructor(contents: Buffer) {
super(contents, Native.ReceiptCredentialRequest_CheckValidContents);
}
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import * as Native from '../../../Native';
import ReceiptCredentialRequest from './ReceiptCredentialRequest';

export default class ReceiptCredentialRequestContext extends ByteArray {
private readonly __type?: never;
static SIZE = 177;

constructor(contents: Buffer) {
2 changes: 2 additions & 0 deletions node/ts/zkgroup/receipts/ReceiptCredentialResponse.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ import ByteArray from '../internal/ByteArray';
import * as Native from '../../../Native';

export default class ReceiptCredentialResponse extends ByteArray {
private readonly __type?: never;

constructor(contents: Buffer) {
super(contents, Native.ReceiptCredentialResponse_CheckValidContents);
}
1 change: 1 addition & 0 deletions node/ts/zkgroup/receipts/ReceiptSerial.ts
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import ByteArray from '../internal/ByteArray';

export default class ReceiptSerial extends ByteArray {
private readonly __type?: never;
static SIZE = 16;

constructor(contents: Buffer) {

0 comments on commit 9e6343b

Please sign in to comment.