diff --git a/local-tests/tests/testDelegatingCapacityCreditsNFTToAnotherWalletToPkpSign.ts b/local-tests/tests/testDelegatingCapacityCreditsNFTToAnotherWalletToPkpSign.ts index 44ddf4e64..d5f67581b 100644 --- a/local-tests/tests/testDelegatingCapacityCreditsNFTToAnotherWalletToPkpSign.ts +++ b/local-tests/tests/testDelegatingCapacityCreditsNFTToAnotherWalletToPkpSign.ts @@ -1,3 +1,5 @@ +import { ethers } from 'ethers'; + import { getEoaSessionSigsWithCapacityDelegations } from 'local-tests/setup/session-sigs/get-eoa-session-sigs'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; @@ -92,5 +94,21 @@ export const testDelegatingCapacityCreditsNFTToAnotherWalletToPkpSign = async ( throw new Error(`Expected "recid" to be parseable as a number`); } + const signature = ethers.utils.joinSignature({ + r: '0x' + res.r, + s: '0x' + res.s, + recoveryParam: res.recid, + }); + const recoveredPubKey = ethers.utils.recoverPublicKey( + alice.loveLetter, + signature + ); + if (recoveredPubKey !== `0x${res.publicKey.toLowerCase()}`) { + throw new Error(`Expected recovered public key to match res.publicKey`); + } + if (recoveredPubKey !== `0x${bob.pkp.publicKey.toLowerCase()}`) { + throw new Error(`Expected recovered public key to match bob.pkp.publicKey`); + } + console.log('✅ res:', res); }; diff --git a/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedCapacityTokenIdToPkpSign.ts b/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedCapacityTokenIdToPkpSign.ts index 8daefbec5..e8ad746c2 100644 --- a/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedCapacityTokenIdToPkpSign.ts +++ b/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedCapacityTokenIdToPkpSign.ts @@ -1,3 +1,5 @@ +import { ethers } from 'ethers'; + import { getEoaSessionSigsWithCapacityDelegations } from 'local-tests/setup/session-sigs/get-eoa-session-sigs'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; @@ -94,5 +96,23 @@ export const testUseCapacityDelegationAuthSigWithUnspecifiedCapacityTokenIdToPkp throw new Error(`Expected "recid" to be parseable as a number`); } + const signature = ethers.utils.joinSignature({ + r: '0x' + res.r, + s: '0x' + res.s, + recoveryParam: res.recid, + }); + const recoveredPubKey = ethers.utils.recoverPublicKey( + alice.loveLetter, + signature + ); + if (recoveredPubKey !== `0x${res.publicKey.toLowerCase()}`) { + throw new Error(`Expected recovered public key to match res.publicKey`); + } + if (recoveredPubKey !== `0x${bob.pkp.publicKey.toLowerCase()}`) { + throw new Error( + `Expected recovered public key to match bob.pkp.publicKey` + ); + } + console.log('✅ res:', res); }; diff --git a/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedDelegateesToPkpSign.ts b/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedDelegateesToPkpSign.ts index e479d9c3a..ba68e4258 100644 --- a/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedDelegateesToPkpSign.ts +++ b/local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedDelegateesToPkpSign.ts @@ -1,3 +1,5 @@ +import { ethers } from 'ethers'; + import { getEoaSessionSigsWithCapacityDelegations } from 'local-tests/setup/session-sigs/get-eoa-session-sigs'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; @@ -86,6 +88,26 @@ export const testUseCapacityDelegationAuthSigWithUnspecifiedDelegateesToPkpSign throw new Error(`Expected "signature" to start with 0x`); } + const signature = ethers.utils.joinSignature({ + r: '0x' + runWithSessionSigs.r, + s: '0x' + runWithSessionSigs.s, + recoveryParam: runWithSessionSigs.recid, + }); + const recoveredPubKey = ethers.utils.recoverPublicKey( + alice.loveLetter, + signature + ); + if (recoveredPubKey !== `0x${runWithSessionSigs.publicKey.toLowerCase()}`) { + throw new Error( + `Expected recovered public key to match runWithSessionSigs.publicKey` + ); + } + if (recoveredPubKey !== `0x${bob.pkp.publicKey.toLowerCase()}`) { + throw new Error( + `Expected recovered public key to match bob.pkp.publicKey` + ); + } + // recid must be parseable as a number if (isNaN(runWithSessionSigs.recid)) { throw new Error(`Expected "recid" to be parseable as a number`); diff --git a/local-tests/tests/testUseEoaSessionSigsToPkpSign.ts b/local-tests/tests/testUseEoaSessionSigsToPkpSign.ts index 1b217f3e5..56566bdd9 100644 --- a/local-tests/tests/testUseEoaSessionSigsToPkpSign.ts +++ b/local-tests/tests/testUseEoaSessionSigsToPkpSign.ts @@ -1,3 +1,5 @@ +import { ethers } from 'ethers'; + import { log } from '@lit-protocol/misc'; import { getEoaSessionSigs } from 'local-tests/setup/session-sigs/get-eoa-session-sigs'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; @@ -58,5 +60,25 @@ export const testUseEoaSessionSigsToPkpSign = async ( throw new Error(`Expected "recid" to be parseable as a number`); } + const signature = ethers.utils.joinSignature({ + r: '0x' + runWithSessionSigs.r, + s: '0x' + runWithSessionSigs.s, + recoveryParam: runWithSessionSigs.recid, + }); + const recoveredPubKey = ethers.utils.recoverPublicKey( + alice.loveLetter, + signature + ); + if (recoveredPubKey !== `0x${runWithSessionSigs.publicKey.toLowerCase()}`) { + throw new Error( + `Expected recovered public key to match runWithSessionSigs.publicKey` + ); + } + if (recoveredPubKey !== `0x${alice.pkp.publicKey.toLowerCase()}`) { + throw new Error( + `Expected recovered public key to match alice.pkp.publicKey` + ); + } + log('✅ testUseEoaSessionSigsToPkpSign'); }; diff --git a/local-tests/tests/testUsePkpSessionSigsToPkpSign.ts b/local-tests/tests/testUsePkpSessionSigsToPkpSign.ts index 27986b20f..0dc62eed7 100644 --- a/local-tests/tests/testUsePkpSessionSigsToPkpSign.ts +++ b/local-tests/tests/testUsePkpSessionSigsToPkpSign.ts @@ -1,3 +1,5 @@ +import { ethers } from 'ethers'; + import { log } from '@lit-protocol/misc'; import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; @@ -58,5 +60,25 @@ export const testUsePkpSessionSigsToPkpSign = async ( throw new Error(`Expected "recid" to be parseable as a number`); } + const signature = ethers.utils.joinSignature({ + r: '0x' + res.r, + s: '0x' + res.s, + recoveryParam: res.recid, + }); + const recoveredPubKey = ethers.utils.recoverPublicKey( + alice.loveLetter, + signature + ); + if (recoveredPubKey !== `0x${res.publicKey.toLowerCase()}`) { + throw new Error(`Expected recovered public key to match res.publicKey`); + } + if ( + recoveredPubKey !== `0x${alice.authMethodOwnedPkp.publicKey.toLowerCase()}` + ) { + throw new Error( + `Expected recovered public key to match alice.authMethodOwnedPkp.publicKey` + ); + } + log('✅ res:', res); }; diff --git a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToPkpSign.ts b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToPkpSign.ts index 9ae59420e..966736aa8 100644 --- a/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToPkpSign.ts +++ b/local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToPkpSign.ts @@ -1,3 +1,5 @@ +import { ethers } from 'ethers'; + import { log } from '@lit-protocol/misc'; import { LIT_NETWORK } from '@lit-protocol/constants'; import { getLitActionSessionSigs } from 'local-tests/setup/session-sigs/get-lit-action-session-sigs'; @@ -58,5 +60,25 @@ export const testUseValidLitActionCodeGeneratedSessionSigsToPkpSign = async ( throw new Error(`Expected "recid" to be parseable as a number`); } + const signature = ethers.utils.joinSignature({ + r: '0x' + res.r, + s: '0x' + res.s, + recoveryParam: res.recid, + }); + const recoveredPubKey = ethers.utils.recoverPublicKey( + alice.loveLetter, + signature + ); + if (recoveredPubKey !== `0x${res.publicKey.toLowerCase()}`) { + throw new Error(`Expected recovered public key to match res.publicKey`); + } + if ( + recoveredPubKey !== `0x${alice.authMethodOwnedPkp.publicKey.toLowerCase()}` + ) { + throw new Error( + `Expected recovered public key to match alice.authMethodOwnedPkp.publicKey` + ); + } + log('✅ res:', res); }; diff --git a/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign.ts b/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign.ts index ab59dd5f0..779bf6930 100644 --- a/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign.ts +++ b/local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign.ts @@ -1,3 +1,5 @@ +import { ethers } from 'ethers'; + import { log } from '@lit-protocol/misc'; import { getLitActionSessionSigsUsingIpfsId } from 'local-tests/setup/session-sigs/get-lit-action-session-sigs'; import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; @@ -66,5 +68,26 @@ export const testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign = throw new Error(`Expected "recid" to be parseable as a number`); } + const signature = ethers.utils.joinSignature({ + r: '0x' + res.r, + s: '0x' + res.s, + recoveryParam: res.recid, + }); + const recoveredPubKey = ethers.utils.recoverPublicKey( + alice.loveLetter, + signature + ); + if (recoveredPubKey !== `0x${res.publicKey.toLowerCase()}`) { + throw new Error(`Expected recovered public key to match res.publicKey`); + } + if ( + recoveredPubKey !== + `0x${alice.authMethodOwnedPkp.publicKey.toLowerCase()}` + ) { + throw new Error( + `Expected recovered public key to match alice.authMethodOwnedPkp.publicKey` + ); + } + log('✅ res:', res); };