Skip to content

Commit

Permalink
Feat/lit 1826 send challenge for attestation and check it as well (#247)
Browse files Browse the repository at this point in the history
* it all works, yay

* gen contracts

* fix up tests

* remove unused thing

* add checkNodeAttestation boolean config option

* better attestation

* remove custom code to test on internaldev

* check ip and port against report

* check ip and port against attestation report

* remove unused params

* moving to get certs in js

* i built stuff

* it works

* fully working in nodejs and also browser

* fix valid cert test

* sync package version

* push readme changes

* add back attestation checking from bad merge

* add default for cayenne for attestation check

* add explicit attestation check disable in e2e tests

* fmt

---------

Co-authored-by: Josh Long <[email protected]>
  • Loading branch information
glitch003 and Josh Long authored Nov 28, 2023
1 parent f4e3027 commit b5e7514
Show file tree
Hide file tree
Showing 218 changed files with 76,613 additions and 129 deletions.
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
59 changes: 29 additions & 30 deletions README.md

Large diffs are not rendered by default.

77 changes: 75 additions & 2 deletions apps/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<script src="dist/packages/pkp-ethers-vanilla/pkp-ethers.js"></script>
<script src="dist/packages/pkp-sui-vanilla/pkp-sui.js"></script>
<script src="dist/packages/pkp-walletconnect-vanilla/pkp-walletconnect.js"></script>
<script src="dist/packages/sev-snp-utils-sdk-vanilla/sev-snp-utils-sdk.js"></script>
<script src="dist/packages/types-vanilla/types.js"></script>
<script src="dist/packages/uint8arrays-vanilla/uint8arrays.js"></script>

Expand Down Expand Up @@ -1749,7 +1750,79 @@ <h1>LitJsSdk_pkpWalletconnect has ${entries.length} functions</h1>
</script>


<!-- (24): TYPES -->
<!-- (24): SEVSNPUTILSSDK -->
<script>
if(typeof LitJsSdk_sevSnpUtilsSdk === 'undefined') {
console.error("LitJsSdk_sevSnpUtilsSdk:", LitJsSdk_sevSnpUtilsSdk);
}else{
console.warn("LitJsSdk_sevSnpUtilsSdk:", LitJsSdk_sevSnpUtilsSdk);
window.LitJsSdk_sevSnpUtilsSdk = LitJsSdk_sevSnpUtilsSdk;
}
window.addEventListener('load', function() {

var root = document.getElementById('root');
var result = document.getElementById('result');
var entries = Object.entries(LitJsSdk_sevSnpUtilsSdk);
var lis = entries.map(([key, value]) => `
<li>
<div id="LitJsSdk_sevSnpUtilsSdk_${key}" class="key" onClick="(async (e) => {
var fn = LitJsSdk_sevSnpUtilsSdk['${key}'];
var fnType = typeof fn;
console.warn('[${key}] is type of [' + fnType + ']');
if ( fnType === 'string' ) return;
if( fnType === 'function' ){
try{
console.log('params:', globalThis.params);
var res;
try{
res = new fn(globalThis.params);
}catch{
res = await fn(globalThis.params);
}
window.output = res;
res = JSON.stringify(res, null, 2);
result.innerText = res;
console.log(res);
}catch(e){
console.error('Please set the [params] variable in the console then click again');
console.log(e);
}
return;
}
if( fnType === 'object' ){
var res = await fn;
window.output = res;
res = JSON.stringify(res, null, 2);
result.innerText = res;
console.log(res);
return;
}
})();">${key}</div>
<pre class="code">
<code>${(typeof value === 'function' ? value : JSON.stringify(value, null, 2))}</code>
</pre>
</li>`);
lis = lis.join(' ');
var template = `
<div class="cat">
<h1>LitJsSdk_sevSnpUtilsSdk has ${entries.length} functions</h1>
<ul>
${ lis }
</ul>
</div>
`;
root.insertAdjacentHTML('beforeend', template);
});
</script>


<!-- (25): TYPES -->
<script>
if(typeof LitJsSdk_types === 'undefined') {
console.error("LitJsSdk_types:", LitJsSdk_types);
Expand Down Expand Up @@ -1821,7 +1894,7 @@ <h1>LitJsSdk_types has ${entries.length} functions</h1>
</script>


<!-- (25): UINT8ARRAYS -->
<!-- (26): UINT8ARRAYS -->
<script>
if(typeof LitJsSdk_uint8arrays === 'undefined') {
console.error("LitJsSdk_uint8arrays:", LitJsSdk_uint8arrays);
Expand Down
22 changes: 22 additions & 0 deletions apps/html/manual_tests_claim_pkp.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@
const litNodeClient = new LitNodeClient({
debug: true
});


// // for testing against InternalDev
// const litNodeClient = new LitJsSdk.LitNodeClient({
// debug: true,
// litNetwork: 'custom',
// "minNodeCount": 6,
// "bootstrapUrls": [
// "https://199.115.117.113",
// "https://199.115.117.114",
// "https://108.62.0.105",
// "https://64.131.85.106",
// "https://64.131.85.108",
// "https://167.114.17.201",
// "https://167.114.17.202",
// "https://167.114.17.203",
// "https://167.114.17.204",
// "https://167.114.17.205",
// ],
// });

window.litNodeClient = litNodeClient; // for messing around in the browser console
litNodeClient.connect();

const client = new StytchUIClient('public-token-live-8b3531cd-fd4b-4400-ae15-310fa8b659e2');
Expand Down
2 changes: 2 additions & 0 deletions apps/nodejs/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import * as pkpCosmos from '@lit-protocol/pkp-cosmos';
import * as pkpEthers from '@lit-protocol/pkp-ethers';
import * as pkpSui from '@lit-protocol/pkp-sui';
import * as pkpWalletconnect from '@lit-protocol/pkp-walletconnect';
import * as sevSnpUtilsSdk from '@lit-protocol/sev-snp-utils-sdk';
import * as types from '@lit-protocol/types';
import * as uint8arrays from '@lit-protocol/uint8arrays';

Expand All @@ -52,6 +53,7 @@ console.log("pkpCosmos:", hasItems(pkpCosmos));
console.log("pkpEthers:", hasItems(pkpEthers));
console.log("pkpSui:", hasItems(pkpSui));
console.log("pkpWalletconnect:", hasItems(pkpWalletconnect));
console.log("sevSnpUtilsSdk:", hasItems(sevSnpUtilsSdk));
console.log("types:", hasItems(types));
console.log("uint8arrays:", hasItems(uint8arrays));

Expand Down
29 changes: 25 additions & 4 deletions apps/nodejs/manual-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,29 @@ const mintPkpAndSign = async () => {
// use cayenne
client = new LitJsSdk.LitNodeClient({
litNetwork: 'cayenne',
debug: true
debug: true,
checkNodeAttestation: false
});

// for testing against InternalDev
// client = new LitJsSdk.LitNodeClient({
// debug: true,
// litNetwork: 'custom',
// "minNodeCount": 6,
// "bootstrapUrls": [
// "https://199.115.117.113",
// "https://199.115.117.114",
// "https://108.62.0.105",
// "https://64.131.85.106",
// "https://64.131.85.108",
// "https://167.114.17.201",
// "https://167.114.17.202",
// "https://167.114.17.203",
// "https://167.114.17.204",
// "https://167.114.17.205",
// ],
// checkNodeAttestation: true
// });
}

await client.connect();
Expand All @@ -313,9 +334,9 @@ const mintPkpAndSign = async () => {
const wallet = new ethers.Wallet(privateKey, provider);
const authSig = await getAuthSig(wallet);

console.log('Sleeping for 30 seconds so that the chronicle node replica can sync up');
// Sleep for 30 seconds
await new Promise(resolve => setTimeout(resolve, 30000));
// console.log('Sleeping for 5 seconds so that the chronicle node replica can sync up');
// Sleep for 5 seconds
// await new Promise(resolve => setTimeout(resolve, 5000));


let startTime = Date.now();
Expand Down
3 changes: 3 additions & 0 deletions apps/react/src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import * as LitJsSdk_pkpCosmos from 'dist/packages/pkp-cosmos';
import * as LitJsSdk_pkpEthers from 'dist/packages/pkp-ethers';
import * as LitJsSdk_pkpSui from 'dist/packages/pkp-sui';
import * as LitJsSdk_pkpWalletconnect from 'dist/packages/pkp-walletconnect';
import * as LitJsSdk_sevSnpUtilsSdk from 'dist/packages/sev-snp-utils-sdk';
import * as LitJsSdk_types from 'dist/packages/types';
import * as LitJsSdk_uint8arrays from 'dist/packages/uint8arrays';

Expand Down Expand Up @@ -52,6 +53,7 @@ declare global {
LitJsSdk_pkpEthers: any;
LitJsSdk_pkpSui: any;
LitJsSdk_pkpWalletconnect: any;
LitJsSdk_sevSnpUtilsSdk: any;
LitJsSdk_types: any;
LitJsSdk_uint8arrays: any;
}
Expand Down Expand Up @@ -1651,6 +1653,7 @@ export function App() {






if(typeof LitJsSdk_uint8arrays === 'undefined') {
Expand Down
8 changes: 5 additions & 3 deletions cypress/e2e/spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,16 +554,18 @@ describe('Lit Action', () => {
});

it('Handshake with Sgx', async () => {
const params: HandshakeWithSgx = {
const params: HandshakeWithNode = {
url: 'https://cayenne.litgateway.com:7371',
challenge: "deadbeef"
};
const res = await savedParams.litNodeClient.handshakeWithSgx(params);
const res = await savedParams.litNodeClient.handshakeWithNode(params);
expect(res).to.have.keys(
'clientSdkVersion',
'networkPublicKey',
'networkPublicKeySet',
'serverPublicKey',
'subnetPublicKey'
'subnetPublicKey',
'attestation'
);
});
});
Expand Down
1 change: 1 addition & 0 deletions e2e-nodejs/00-setup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const client = new LitNodeClient({
litNetwork: LITCONFIG.TEST_ENV.litNetwork,
debug: process.env.DEBUG === 'true' ?? LITCONFIG.TEST_ENV.debug,
minNodeCount: LITCONFIG.TEST_ENV.minNodeCount,
checkNodeAttestation: false,
});
await client.connect();

Expand Down
Loading

0 comments on commit b5e7514

Please sign in to comment.