|
| 1 | +import { log } from '@lit-protocol/misc'; |
| 2 | +import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; |
| 3 | +import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; |
| 4 | + |
| 5 | +/** |
| 6 | + * Test Commands: |
| 7 | + * ✅ NETWORK=datil-dev yarn test:local --filter=testPkpSessionSigsDomain |
| 8 | + * ✅ NETWORK=datil-test yarn test:local --filter=testPkpSessionSigsDomain |
| 9 | + * ✅ NETWORK=custom yarn test:local --filter=testPkpSessionSigsDomain |
| 10 | + */ |
| 11 | +export const testPkpSessionSigsDomain = async (devEnv: TinnyEnvironment) => { |
| 12 | + const alice = await devEnv.createRandomPerson(); |
| 13 | + const testDomain = 'test.domain.com'; |
| 14 | + |
| 15 | + // AuthNeededCallback props: |
| 16 | + // props: { |
| 17 | + // chain: 'ethereum', |
| 18 | + // statement: 'I further authorize the stated URI to perform the following actions on my behalf:', |
| 19 | + // resources: [ 'urn:recap:eyJhdHQiOnt9LCJwcmYiOltdfQ' ], |
| 20 | + // expiration: '2025-02-01T16:51:50.358Z', |
| 21 | + // uri: 'lit:session:e43c4bdff81bb83e7bedf079f5546f237d6e1344c9981735fe8d3a0bbc07c371', |
| 22 | + // sessionKey: { |
| 23 | + // publicKey: 'e43c4bdff81bb83e7bedf079f5546f237d6e1344c9981735fe8d3a0bbc07c371', |
| 24 | + // secretKey: 'a5f43862612394a59f64708a847825255d66839fd6972d3538cb5dffce7228aee43c4bdff81bb83e7bedf079f5546f237d6e1344c9981735fe8d3a0bbc07c371' |
| 25 | + // }, |
| 26 | + // nonce: '0x53e14ac177c02e4b460432ef2bd639519c589137f16136027505c58793608ef7', |
| 27 | + // domain: 'test.domain.com', |
| 28 | + // resourceAbilityRequests: [ |
| 29 | + // { resource: [LitPKPResource], ability: 'pkp-signing' }, |
| 30 | + // { resource: [LitActionResource], ability: 'lit-action-execution' } |
| 31 | + // ] |
| 32 | + // } |
| 33 | + const pkpSessionSigs = await getPkpSessionSigs( |
| 34 | + devEnv, |
| 35 | + alice, |
| 36 | + undefined, |
| 37 | + undefined, |
| 38 | + testDomain |
| 39 | + ); |
| 40 | + |
| 41 | + // Get the first session sig to verify |
| 42 | + const firstNodeAddress = Object.keys(pkpSessionSigs)[0]; |
| 43 | + const firstSessionSig = pkpSessionSigs[firstNodeAddress]; |
| 44 | + |
| 45 | + // Parse the signed message to verify domain |
| 46 | + const signedMessage = firstSessionSig.signedMessage; |
| 47 | + |
| 48 | + // Verify that the domain is present in the signed message |
| 49 | + if (!signedMessage.includes(testDomain)) { |
| 50 | + throw new Error( |
| 51 | + `Expected domain "${testDomain}" in signed message, but it was not found. Signed message: ${signedMessage}` |
| 52 | + ); |
| 53 | + } |
| 54 | + |
| 55 | + log('✅ Domain parameter successfully passed through in sessionSigs'); |
| 56 | + |
| 57 | + // Clean up |
| 58 | + devEnv.releasePrivateKeyFromUser(alice); |
| 59 | +}; |
0 commit comments