diff --git a/packages/pkp-base/src/lib/pkp-base.ts b/packages/pkp-base/src/lib/pkp-base.ts index 509e1700f..072b06f8c 100644 --- a/packages/pkp-base/src/lib/pkp-base.ts +++ b/packages/pkp-base/src/lib/pkp-base.ts @@ -242,17 +242,18 @@ export class PKPBase { throw new Error('pkpPubKey (aka. uncompressPubKey) is required'); } - // If no authSig or sessionSigs are provided, throw error - if (!this.controllerAuthSig && !this.controllerSessionSigs) { - throw new Error('controllerAuthSig or controllerSessionSigs is required'); - } - - if (this.controllerAuthSig && this.controllerSessionSigs) { - throw new Error( - 'controllerAuthSig and controllerSessionSigs both defined, can only use one authorization type' - ); - } - + if ( + [ + this.controllerAuthSig, + this.controllerSessionSigs, + this.controllerAuthMethods, + ].filter((val, index, arr) => val !== undefined).length > 1 + ) { + throw new Error( + 'controllerAuthSig, controllerSessionSigs and controllerAuthMethod are defined, can only use one authorization type' + ); + } + // If session sigs are provided, they must be an object if ( this.controllerSessionSigs && @@ -343,14 +344,15 @@ export class PKPBase { throw new Error('pkpPubKey (aka. uncompressPubKey) is required'); } - // If no authSig or sessionSigs are provided, throw error - if (!this.controllerAuthSig && !this.controllerSessionSigs) { - throw new Error('controllerAuthSig or controllerSessionSigs is required'); - } - - if (this.controllerAuthSig && this.controllerSessionSigs) { + if ( + [ + this.controllerAuthSig, + this.controllerSessionSigs, + this.controllerAuthMethods, + ].filter((val, index, arr) => val !== undefined).length > 1 + ) { throw new Error( - 'controllerAuthSig and controllerSessionSigs both defined, can only use one authorization type' + 'controllerAuthSig, controllerSessionSigs and controllerAuthMethod are defined, can only use one authorization type' ); } @@ -361,14 +363,20 @@ export class PKPBase { toSign: toSign, pubKey: this.uncompressedPubKey, authSig: this.controllerAuthSig as AuthSig, - authMethods: [] + authMethods: [], }); } else if (this.controllerSessionSigs) { sig = await this.litNodeClient.pkpSign({ toSign, pubKey: this.uncompressedPubKey, authMethods: this.controllerAuthMethods ?? [], - sessionSigs: this.controllerSessionSigs + sessionSigs: this.controllerSessionSigs, + }); + } else if (this.controllerAuthMethods) { + sig = await this.litNodeClient.pkpSign({ + toSign, + pubKey: this.uncompressedPubKey, + authMethods: this.controllerAuthMethods, }); }