Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hwrdtm committed Jun 24, 2023
1 parent 0384238 commit 958d035
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 974 deletions.
2 changes: 1 addition & 1 deletion apps/demo-locked-express-app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ app.get('/', function(req, res) {
app.get('/protected-path-1', async function(req: Request, res: Response) {
const jwt = req.query?.jwt || req.cookies?.jwt;

console.log("JWT is ", jwt, jwt == "eyJhbGciOiJCTFMxMi0zODEiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJMSVQiLCJzdWIiOiIweDQyNTllNDQ2NzAwNTM0OTFlN2I0ZmU0YTEyMGM3MGJlMWVhZDY0NmIiLCJjaGFpbiI6ImV0aGVyZXVtIiwiaWF0IjoxNjg3NTg0MTY0LCJleHAiOjE2ODc2MjczNjQsImFjY2Vzc0NvbnRyb2xDb25kaXRpb25zIjpbeyJjb250cmFjdEFkZHJlc3MiOiIiLCJjaGFpbiI6ImV0aGVyZXVtIiwic3RhbmRhcmRDb250cmFjdFR5cGUiOiIiLCJtZXRob2QiOiIiLCJwYXJhbWV0ZXJzIjpbIjp1c2VyQWRkcmVzcyJdLCJyZXR1cm5WYWx1ZVRlc3QiOnsiY29tcGFyYXRvciI6Ij0iLCJ2YWx1ZSI6IjB4NDI1OUU0NDY3MDA1MzQ5MUU3YjRGRTRBMTIwQzcwYmUxZUFENjQ2YiJ9fV0sImV2bUNvbnRyYWN0Q29uZGl0aW9ucyI6bnVsbCwic29sUnBjQ29uZGl0aW9ucyI6bnVsbCwidW5pZmllZEFjY2Vzc0NvbnRyb2xDb25kaXRpb25zIjpudWxsfQ.oymXPMn_DDRl/s50GBFfFVpLzZ6EurN/kGVvlrHIYNU599EInb7MmW-pXzo0loF1BnTp81wGxIzu20KGe7Kw7Xh7a/Oha+fGVTlDySOUv8uSoAoOEVGwnlRgePllWhEK");
console.log("JWT is", jwt);

if (!jwt) {
res.status(401).send("Unauthorized");
Expand Down
119 changes: 0 additions & 119 deletions apps/html/manual_tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -850,122 +850,6 @@
});
};

var SignChainData = async () => {
const testName = 'SignChainData';
document.getElementById('status').innerText = `Testing ${testName}...`;
document.getElementById('humanized').innerText = '';

const aggregatorV3InterfaceABI = [
{
inputs: [],
name: 'decimals',
outputs: [{ internalType: 'uint8', name: '', type: 'uint8' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'description',
outputs: [{ internalType: 'string', name: '', type: 'string' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{ internalType: 'uint80', name: '_roundId', type: 'uint80' },
],
name: 'getRoundData',
outputs: [
{ internalType: 'uint80', name: 'roundId', type: 'uint80' },
{ internalType: 'int256', name: 'answer', type: 'int256' },
{ internalType: 'uint256', name: 'startedAt', type: 'uint256' },
{ internalType: 'uint256', name: 'updatedAt', type: 'uint256' },
{
internalType: 'uint80',
name: 'answeredInRound',
type: 'uint80',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'latestRoundData',
outputs: [
{ internalType: 'uint80', name: 'roundId', type: 'uint80' },
{ internalType: 'int256', name: 'answer', type: 'int256' },
{ internalType: 'uint256', name: 'startedAt', type: 'uint256' },
{ internalType: 'uint256', name: 'updatedAt', type: 'uint256' },
{
internalType: 'uint80',
name: 'answeredInRound',
type: 'uint80',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'version',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
];
// this is the address for the chainlink eth/usd price oracle
const addr = '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419';

const callData = LitJsSdk.encodeCallData({
abi: aggregatorV3InterfaceABI,
functionName: 'latestRoundData',
functionParams: [],
});

const callRequests = [{ to: addr, data: callData }];
console.log('callRequests', callRequests);

const chain = 'ethereum';

const jwt = await litNodeClient.getSignedChainDataToken({
callRequests,
chain,
});

console.log('jwt', jwt);

const { verified, header, payload, signature } = LitJsSdk.verifyJwt({
jwt,
});

console.log('jwt payload: ', payload);

// const decoded = iface.decodeFunctionResult(
// "latestRoundData",
// payload.callResponses[0]
// );
const decoded = LitJsSdk.decodeCallResult({
abi: aggregatorV3InterfaceABI,
functionName: 'latestRoundData',
data: payload.callResponses[0],
});

console.log('decoded', decoded);
const answer = decoded.answer
.div(ethers.BigNumber.from('10').pow(ethers.BigNumber.from('8')))
.toString();
console.log('answer: ', answer);

if (jwt && verified) {
document.getElementById(
'status'
).innerText = `${testName}: Success - ETH Price is $${answer}`;
} else {
document.getElementById('status').innerText = `${testName}: Failure`;
}
};

var SendBadRequestToNodes = async () => {
const testName = 'SendBadRequestToNodes';
document.getElementById('status').innerText = `Testing ${testName}...`;
Expand Down Expand Up @@ -1770,9 +1654,6 @@ <h1>Manual tests</h1>
</button>
<br />
<br />
<button onclick="SignChainData()">Sign Chain Data</button>
<br />
<br />
<button onclick="SendBadRequestToNodes()">
Send a bad request to the nodes
</button>
Expand Down
Loading

0 comments on commit 958d035

Please sign in to comment.