Skip to content

Commit

Permalink
Fix/controller auth method (#230)
Browse files Browse the repository at this point in the history
* add support for controller auth methods in pkp base

* fix defined checks

Signed-off-by: Bean <josh@litprotocol.com>

---------

Signed-off-by: Bean <josh@litprotocol.com>
  • Loading branch information
joshLong145 committed Oct 10, 2023
1 parent 13e9a1c commit ffbe3ee
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions packages/pkp-base/src/lib/pkp-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,18 @@ export class PKPBase<T = PKPBaseDefaultParams> {
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 &&
Expand Down Expand Up @@ -343,14 +344,15 @@ export class PKPBase<T = PKPBaseDefaultParams> {
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'
);
}

Expand All @@ -361,14 +363,20 @@ export class PKPBase<T = PKPBaseDefaultParams> {
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,
});
}

Expand Down

0 comments on commit ffbe3ee

Please sign in to comment.