Skip to content

Commit f5a838f

Browse files
committed
feat: preSigningValidator
1 parent 3c625fd commit f5a838f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/interfaces.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,3 +495,5 @@ export interface Secp256k1PrecomputedClient {
495495
client: Client;
496496
serverCoeffs: Record<string, string>;
497497
}
498+
499+
export type PreSigningValidatorType = (params: { data: Uint8Array; hashed: boolean }) => Promise<{ success: boolean; error?: string; data?: string }>;

src/mpcCoreKit.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
JWTLoginParams,
4444
MPCKeyDetails,
4545
OAuthLoginParams,
46+
PreSigningValidatorType,
4647
Secp256k1PrecomputedClient,
4748
SessionData,
4849
SubVerifierDetailsParams,
@@ -99,6 +100,8 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
99100

100101
private atomicCallStackCounter: number = 0;
101102

103+
private preSigningValidator?: PreSigningValidatorType;
104+
102105
constructor(options: Web3AuthOptions) {
103106
if (!options.web3AuthClientId) {
104107
throw CoreKitError.clientIdInvalid();
@@ -456,6 +459,10 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
456459
}
457460
}
458461

462+
setPreSigningValidator(preSigningValidator: PreSigningValidatorType) {
463+
this.preSigningValidator = preSigningValidator;
464+
}
465+
459466
public async handleRedirectResult(): Promise<void> {
460467
this.checkReady();
461468

@@ -778,6 +785,12 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
778785
}
779786

780787
public async sign(data: Buffer, hashed: boolean = false, secp256k1Precompute?: Secp256k1PrecomputedClient): Promise<Buffer> {
788+
if (this.preSigningValidator) {
789+
const result = await this.preSigningValidator({ data, hashed });
790+
if (!result.success || result.error) {
791+
throw Error(result.error);
792+
}
793+
}
781794
this.wasmLib = await this.loadTssWasm();
782795
if (this.keyType === KeyType.secp256k1) {
783796
const sig = await this.sign_ECDSA_secp256k1(data, hashed, secp256k1Precompute);

0 commit comments

Comments
 (0)