-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
205 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToExecuteJsSigning.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { LitActionResource, LitPKPResource } from '@lit-protocol/auth-helpers'; | ||
import { log } from '@lit-protocol/misc'; | ||
import { LitAbility } from '@lit-protocol/types'; | ||
import { getLitActionSessionSigsUsingIpfsId } from 'local-tests/setup/session-sigs/get-lit-action-session-sigs'; | ||
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; | ||
|
||
/** | ||
* Test Commands: | ||
* ✅ NETWORK=cayenne yarn test:local --filter=testUseValidLitActionIpfsCodeGeneratedSessionSigsToExecuteJsSigning | ||
* ❌ NOT AVAILABLE IN HABANERO | ||
* ✅ NETWORK=localchain yarn test:local --filter=testUseValidLitActionIpfsCodeGeneratedSessionSigsToExecuteJsSigning | ||
*/ | ||
export const testUseValidLitActionIpfsCodeGeneratedSessionSigsToExecuteJsSigning = | ||
async (devEnv: TinnyEnvironment) => { | ||
const alice = await devEnv.createRandomPerson(); | ||
const litActionSessionSigs = await getLitActionSessionSigsUsingIpfsId( | ||
devEnv, | ||
alice, | ||
[ | ||
{ | ||
resource: new LitPKPResource('*'), | ||
ability: LitAbility.PKPSigning, | ||
}, | ||
{ | ||
resource: new LitActionResource('*'), | ||
ability: LitAbility.LitActionExecution, | ||
}, | ||
] | ||
); | ||
|
||
const res = await devEnv.litNodeClient.executeJs({ | ||
sessionSigs: litActionSessionSigs, | ||
code: `(async () => { | ||
const sigShare = await LitActions.signEcdsa({ | ||
toSign: dataToSign, | ||
publicKey, | ||
sigName: "sig", | ||
}); | ||
})();`, | ||
jsParams: { | ||
dataToSign: alice.loveLetter, | ||
publicKey: alice.authMethodOwnedPkp.publicKey, | ||
}, | ||
}); | ||
|
||
// -- Expected output: | ||
// { | ||
// claims: {}, | ||
// signatures: { | ||
// sig: { | ||
// r: "6d5ce6f948ff763939c204fc0f1b750fa0267ed567ed59581082d0cbf283feef", | ||
// s: "4957ece75c60388500c4b7aa38a5fbafb7c20427db181aff7806af54c16ee145", | ||
// recid: 1, | ||
// signature: "0x6d5ce6f948ff763939c204fc0f1b750fa0267ed567ed59581082d0cbf283feef4957ece75c60388500c4b7aa38a5fbafb7c20427db181aff7806af54c16ee1451c", | ||
// publicKey: "04D10D941B04491FDC99B048E2252A69137333254C482511D6CCDD401C080AF4F51BF65D9AE2413FCE066E326D7F0CED9C139DD9BA2D1C6334FD8C14CA4DD7F3D0", | ||
// dataSigned: "7D87C5EA75F7378BB701E404C50639161AF3EFF66293E9F375B5F17EB50476F4", | ||
// }, | ||
// }, | ||
// decryptions: [], | ||
// response: undefined, | ||
// logs: "", | ||
// } | ||
|
||
// -- assertions | ||
if (!res.signatures.sig.r) { | ||
throw new Error(`Expected "r" in res.signatures.sig`); | ||
} | ||
if (!res.signatures.sig.s) { | ||
throw new Error(`Expected "s" in res.signatures.sig`); | ||
} | ||
|
||
if (!res.signatures.sig.dataSigned) { | ||
throw new Error(`Expected "dataSigned" in res.signatures.sig`); | ||
} | ||
|
||
if (!res.signatures.sig.publicKey) { | ||
throw new Error(`Expected "publicKey" in res.signatures.sig`); | ||
} | ||
|
||
log('✅ res:', res); | ||
}; |
62 changes: 62 additions & 0 deletions
62
local-tests/tests/testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
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'; | ||
|
||
/** | ||
* Test Commands: | ||
* ✅ NETWORK=cayenne yarn test:local --filter=testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign | ||
* ❌ NOT AVAILABLE IN HABANERO | ||
* ✅ NETWORK=localchain yarn test:local --filter=testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign | ||
* | ||
**/ | ||
export const testUseValidLitActionIpfsCodeGeneratedSessionSigsToPkpSign = | ||
async (devEnv: TinnyEnvironment) => { | ||
const alice = await devEnv.createRandomPerson(); | ||
const litActionSessionSigs = await getLitActionSessionSigsUsingIpfsId( | ||
devEnv, | ||
alice | ||
); | ||
|
||
const res = await devEnv.litNodeClient.pkpSign({ | ||
toSign: alice.loveLetter, | ||
pubKey: alice.authMethodOwnedPkp.publicKey, | ||
sessionSigs: litActionSessionSigs, | ||
}); | ||
|
||
// -- Expected output: | ||
// { | ||
// r: "ab2cef959db920d56f001c3b05637ee49af4c4441f2867ea067c413594a4c87b", | ||
// s: "4bf11e17b4bb618aa6ed75cbf0406e6babfd953c5b201da697077c5fbf5b542e", | ||
// recid: 1, | ||
// signature: "0xab2cef959db920d56f001c3b05637ee49af4c4441f2867ea067c413594a4c87b4bf11e17b4bb618aa6ed75cbf0406e6babfd953c5b201da697077c5fbf5b542e1c", | ||
// publicKey: "04400AD53C2F8BA11EBC69F05D1076D5BEE4EAE668CD66BABADE2E0770F756FDEEFC2C1D20F9A698EA3FEC6E9C944FF9FAFC2DC339B8E9392AFB9CC8AE75C5E5EC", | ||
// dataSigned: "7D87C5EA75F7378BB701E404C50639161AF3EFF66293E9F375B5F17EB50476F4", | ||
// } | ||
|
||
// -- assertions | ||
// r, s, dataSigned, and public key should be present | ||
if (!res.r) { | ||
throw new Error(`Expected "r" in res`); | ||
} | ||
if (!res.s) { | ||
throw new Error(`Expected "s" in res`); | ||
} | ||
if (!res.dataSigned) { | ||
throw new Error(`Expected "dataSigned" in res`); | ||
} | ||
if (!res.publicKey) { | ||
throw new Error(`Expected "publicKey" in res`); | ||
} | ||
|
||
// signature must start with 0x | ||
if (!res.signature.startsWith('0x')) { | ||
throw new Error(`Expected "signature" to start with 0x`); | ||
} | ||
|
||
// recid must be parseable as a number | ||
if (isNaN(res.recid)) { | ||
throw new Error(`Expected "recid" to be parseable as a number`); | ||
} | ||
|
||
log('✅ res:', res); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters