Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/sdk/InputVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export class InputVerifier {
'function eip712Domain() view returns (bytes1 fields, string name, string version, uint256 chainId, address verifyingContract, bytes32 salt, uint256[] extensions)',
] as const;

static readonly #constructorGuard: unique symbol = Symbol(
'InputVerifier.constructorGuard',
);

static {
Object.freeze(InputVerifier.#abi);
}
Expand All @@ -24,12 +28,20 @@ export class InputVerifier {
readonly #coprocessorSigners: ChecksummedAddress[];
readonly #coprocessorSignerThreshold: number;

private constructor(params: {
address: ChecksummedAddress;
eip712Domain: CoprocessorEIP712DomainType;
coprocessorSigners: ChecksummedAddress[];
coprocessorSignerThreshold: number;
}) {
private constructor(
guard: symbol,
params: {
address: ChecksummedAddress;
eip712Domain: CoprocessorEIP712DomainType;
coprocessorSigners: ChecksummedAddress[];
coprocessorSignerThreshold: number;
},
) {
if (guard !== InputVerifier.#constructorGuard) {
throw new Error(
'InputVerifier cannot be constructed directly. Use InputVerifier.loadFromChain() or createInstance() instead.',
);
}
this.#address = params.address;
this.#eip712Domain = { ...params.eip712Domain };
this.#coprocessorSigners = [...params.coprocessorSigners];
Expand Down Expand Up @@ -144,7 +156,7 @@ export class InputVerifier {
);
}

const inputVerifier = new InputVerifier({
const inputVerifier = new InputVerifier(InputVerifier.#constructorGuard, {
address: params.inputVerifierContractAddress,
eip712Domain: eip712Domain,
coprocessorSignerThreshold: Number(threshold),
Expand Down
26 changes: 19 additions & 7 deletions src/sdk/KMSVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export class KMSVerifier {
'function eip712Domain() view returns (bytes1 fields, string name, string version, uint256 chainId, address verifyingContract, bytes32 salt, uint256[] extensions)',
] as const;

static readonly #constructorGuard: unique symbol = Symbol(
'KMSVerifier.constructorGuard',
);

static {
Object.freeze(KMSVerifier.#abi);
}
Expand All @@ -25,12 +29,20 @@ export class KMSVerifier {
readonly #kmsSigners: ChecksummedAddress[];
readonly #kmsSignerThreshold: number;

private constructor(params: {
address: ChecksummedAddress;
eip712Domain: KmsEIP712DomainType;
kmsSigners: ChecksummedAddress[];
kmsSignerThreshold: number;
}) {
private constructor(
guard: symbol,
params: {
address: ChecksummedAddress;
eip712Domain: KmsEIP712DomainType;
kmsSigners: ChecksummedAddress[];
kmsSignerThreshold: number;
},
) {
if (guard !== KMSVerifier.#constructorGuard) {
throw new Error(
'KMSVerifier cannot be constructed directly. Use KMSVerifier.loadFromChain() or createInstance() instead.',
);
}
this.#address = params.address;
this.#verifyingContractAddressDecryption =
params.eip712Domain.verifyingContract;
Expand Down Expand Up @@ -139,7 +151,7 @@ export class KMSVerifier {
);
}

const kmsVerifier = new KMSVerifier({
const kmsVerifier = new KMSVerifier(KMSVerifier.#constructorGuard, {
address: params.kmsContractAddress,
eip712Domain: eip712Domain,
kmsSignerThreshold: Number(kmsSignerThreshold),
Expand Down
Loading