Skip to content

Commit 224fb3e

Browse files
committed
feat: add tests over the recovered public key from pkpSign signature
1 parent 236ca19 commit 224fb3e

7 files changed

+149
-0
lines changed

local-tests/tests/testDelegatingCapacityCreditsNFTToAnotherWalletToPkpSign.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ethers } from 'ethers';
2+
13
import { getEoaSessionSigsWithCapacityDelegations } from 'local-tests/setup/session-sigs/get-eoa-session-sigs';
24
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
35

@@ -92,5 +94,21 @@ export const testDelegatingCapacityCreditsNFTToAnotherWalletToPkpSign = async (
9294
throw new Error(`Expected "recid" to be parseable as a number`);
9395
}
9496

97+
const signature = ethers.utils.joinSignature({
98+
r: '0x' + res.r,
99+
s: '0x' + res.s,
100+
recoveryParam: res.recid,
101+
});
102+
const recoveredPubKey = ethers.utils.recoverPublicKey(
103+
alice.loveLetter,
104+
signature
105+
);
106+
if (recoveredPubKey !== `0x${res.publicKey.toLowerCase()}`) {
107+
throw new Error(`Expected recovered public key to match res.publicKey`);
108+
}
109+
if (recoveredPubKey !== `0x${bob.pkp.publicKey.toLowerCase()}`) {
110+
throw new Error(`Expected recovered public key to match bob.pkp.publicKey`);
111+
}
112+
95113
console.log('✅ res:', res);
96114
};

local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedCapacityTokenIdToPkpSign.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ethers } from 'ethers';
2+
13
import { getEoaSessionSigsWithCapacityDelegations } from 'local-tests/setup/session-sigs/get-eoa-session-sigs';
24
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
35

@@ -94,5 +96,23 @@ export const testUseCapacityDelegationAuthSigWithUnspecifiedCapacityTokenIdToPkp
9496
throw new Error(`Expected "recid" to be parseable as a number`);
9597
}
9698

99+
const signature = ethers.utils.joinSignature({
100+
r: '0x' + res.r,
101+
s: '0x' + res.s,
102+
recoveryParam: res.recid,
103+
});
104+
const recoveredPubKey = ethers.utils.recoverPublicKey(
105+
alice.loveLetter,
106+
signature
107+
);
108+
if (recoveredPubKey !== `0x${res.publicKey.toLowerCase()}`) {
109+
throw new Error(`Expected recovered public key to match res.publicKey`);
110+
}
111+
if (recoveredPubKey !== `0x${bob.pkp.publicKey.toLowerCase()}`) {
112+
throw new Error(
113+
`Expected recovered public key to match bob.pkp.publicKey`
114+
);
115+
}
116+
97117
console.log('✅ res:', res);
98118
};

local-tests/tests/testUseCapacityDelegationAuthSigWithUnspecifiedDelegateesToPkpSign.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ethers } from 'ethers';
2+
13
import { getEoaSessionSigsWithCapacityDelegations } from 'local-tests/setup/session-sigs/get-eoa-session-sigs';
24
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
35

@@ -86,6 +88,26 @@ export const testUseCapacityDelegationAuthSigWithUnspecifiedDelegateesToPkpSign
8688
throw new Error(`Expected "signature" to start with 0x`);
8789
}
8890

91+
const signature = ethers.utils.joinSignature({
92+
r: '0x' + runWithSessionSigs.r,
93+
s: '0x' + runWithSessionSigs.s,
94+
recoveryParam: runWithSessionSigs.recid,
95+
});
96+
const recoveredPubKey = ethers.utils.recoverPublicKey(
97+
alice.loveLetter,
98+
signature
99+
);
100+
if (recoveredPubKey !== `0x${runWithSessionSigs.publicKey.toLowerCase()}`) {
101+
throw new Error(
102+
`Expected recovered public key to match runWithSessionSigs.publicKey`
103+
);
104+
}
105+
if (recoveredPubKey !== `0x${bob.pkp.publicKey.toLowerCase()}`) {
106+
throw new Error(
107+
`Expected recovered public key to match bob.pkp.publicKey`
108+
);
109+
}
110+
89111
// recid must be parseable as a number
90112
if (isNaN(runWithSessionSigs.recid)) {
91113
throw new Error(`Expected "recid" to be parseable as a number`);

local-tests/tests/testUseEoaSessionSigsToPkpSign.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ethers } from 'ethers';
2+
13
import { log } from '@lit-protocol/misc';
24
import { getEoaSessionSigs } from 'local-tests/setup/session-sigs/get-eoa-session-sigs';
35
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
@@ -58,5 +60,25 @@ export const testUseEoaSessionSigsToPkpSign = async (
5860
throw new Error(`Expected "recid" to be parseable as a number`);
5961
}
6062

63+
const signature = ethers.utils.joinSignature({
64+
r: '0x' + runWithSessionSigs.r,
65+
s: '0x' + runWithSessionSigs.s,
66+
recoveryParam: runWithSessionSigs.recid,
67+
});
68+
const recoveredPubKey = ethers.utils.recoverPublicKey(
69+
alice.loveLetter,
70+
signature
71+
);
72+
if (recoveredPubKey !== `0x${runWithSessionSigs.publicKey.toLowerCase()}`) {
73+
throw new Error(
74+
`Expected recovered public key to match runWithSessionSigs.publicKey`
75+
);
76+
}
77+
if (recoveredPubKey !== `0x${alice.pkp.publicKey.toLowerCase()}`) {
78+
throw new Error(
79+
`Expected recovered public key to match alice.pkp.publicKey`
80+
);
81+
}
82+
6183
log('✅ testUseEoaSessionSigsToPkpSign');
6284
};

local-tests/tests/testUsePkpSessionSigsToPkpSign.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ethers } from 'ethers';
2+
13
import { log } from '@lit-protocol/misc';
24
import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs';
35
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
@@ -58,5 +60,25 @@ export const testUsePkpSessionSigsToPkpSign = async (
5860
throw new Error(`Expected "recid" to be parseable as a number`);
5961
}
6062

63+
const signature = ethers.utils.joinSignature({
64+
r: '0x' + res.r,
65+
s: '0x' + res.s,
66+
recoveryParam: res.recid,
67+
});
68+
const recoveredPubKey = ethers.utils.recoverPublicKey(
69+
alice.loveLetter,
70+
signature
71+
);
72+
if (recoveredPubKey !== `0x${res.publicKey.toLowerCase()}`) {
73+
throw new Error(`Expected recovered public key to match res.publicKey`);
74+
}
75+
if (
76+
recoveredPubKey !== `0x${alice.authMethodOwnedPkp.publicKey.toLowerCase()}`
77+
) {
78+
throw new Error(
79+
`Expected recovered public key to match alice.authMethodOwnedPkp.publicKey`
80+
);
81+
}
82+
6183
log('✅ res:', res);
6284
};

local-tests/tests/testUseValidLitActionCodeGeneratedSessionSigsToPkpSign.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ethers } from 'ethers';
2+
13
import { log } from '@lit-protocol/misc';
24
import { LIT_NETWORK } from '@lit-protocol/constants';
35
import { getLitActionSessionSigs } from 'local-tests/setup/session-sigs/get-lit-action-session-sigs';
@@ -58,5 +60,25 @@ export const testUseValidLitActionCodeGeneratedSessionSigsToPkpSign = async (
5860
throw new Error(`Expected "recid" to be parseable as a number`);
5961
}
6062

63+
const signature = ethers.utils.joinSignature({
64+
r: '0x' + res.r,
65+
s: '0x' + res.s,
66+
recoveryParam: res.recid,
67+
});
68+
const recoveredPubKey = ethers.utils.recoverPublicKey(
69+
alice.loveLetter,
70+
signature
71+
);
72+
if (recoveredPubKey !== `0x${res.publicKey.toLowerCase()}`) {
73+
throw new Error(`Expected recovered public key to match res.publicKey`);
74+
}
75+
if (
76+
recoveredPubKey !== `0x${alice.authMethodOwnedPkp.publicKey.toLowerCase()}`
77+
) {
78+
throw new Error(
79+
`Expected recovered public key to match alice.authMethodOwnedPkp.publicKey`
80+
);
81+
}
82+
6183
log('✅ res:', res);
6284
};

local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ethers } from 'ethers';
2+
13
import { log } from '@lit-protocol/misc';
24
import { getLitActionSessionSigsUsingIpfsId } from 'local-tests/setup/session-sigs/get-lit-action-session-sigs';
35
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
@@ -66,5 +68,26 @@ export const testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign =
6668
throw new Error(`Expected "recid" to be parseable as a number`);
6769
}
6870

71+
const signature = ethers.utils.joinSignature({
72+
r: '0x' + res.r,
73+
s: '0x' + res.s,
74+
recoveryParam: res.recid,
75+
});
76+
const recoveredPubKey = ethers.utils.recoverPublicKey(
77+
alice.loveLetter,
78+
signature
79+
);
80+
if (recoveredPubKey !== `0x${res.publicKey.toLowerCase()}`) {
81+
throw new Error(`Expected recovered public key to match res.publicKey`);
82+
}
83+
if (
84+
recoveredPubKey !==
85+
`0x${alice.authMethodOwnedPkp.publicKey.toLowerCase()}`
86+
) {
87+
throw new Error(
88+
`Expected recovered public key to match alice.authMethodOwnedPkp.publicKey`
89+
);
90+
}
91+
6992
log('✅ res:', res);
7093
};

0 commit comments

Comments
 (0)