-
Notifications
You must be signed in to change notification settings - Fork 76
Fetch gasPrice
and estimate gas in Wrapped Keys LA if not provided
#501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
DashKash54
merged 16 commits into
feature/lit-3125-sdk-for-wrapping-up-walletx-2
from
wyatt/fetch-gas-price-la
Jun 16, 2024
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3e49141
Update LA to fetch gasPrice and gas estimate. Init test
spacesailor24 94925f2
Fix bugs
spacesailor24 81c2237
Add gasLimit for Chronicle
spacesailor24 5a5317d
Debugging
spacesailor24 eca4744
Rename test file
spacesailor24 cdb4049
Update LA code to have syntax highlighting
spacesailor24 95dca48
Update test cmd statuses
spacesailor24 de8c6d9
Solve merge conflicts
spacesailor24 b5650a0
Merge branch 'feature/lit-3125-sdk-for-wrapping-up-walletx-2' into wy…
spacesailor24 0a81eb4
Rename test and add hexlify for gasPrice and gasLimit
spacesailor24 f3c373f
Add from to tx within LA before signing
spacesailor24 e9c58c8
Remove runOnce from gasPrice and gasLimit. Small refactors
spacesailor24 9770e85
Convert other functions
spacesailor24 3f2be78
feat: Autogen on yarn build
DashKash54 58d3b7b
feat: Additional error handling for Lit Action opcodes
DashKash54 d542ef5
test: Decryption fails in Lit Action due to mismatch owner
DashKash54 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
88 changes: 88 additions & 0 deletions
88
local-tests/tests/testEthereumBroadcastWrappedKeyWithFetchGasParams.ts
This file contains hidden or 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,88 @@ | ||
import { log } from '@lit-protocol/misc'; | ||
import { ethers } from 'ethers'; | ||
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; | ||
import { | ||
importPrivateKey, | ||
EthereumLitTransaction, | ||
signTransactionWithEthereumEncryptedKeyLitAction, | ||
signTransactionWithEncryptedKey, | ||
} from '@lit-protocol/wrapped-keys'; | ||
import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; | ||
|
||
/** | ||
* Test Commands: | ||
* ✅ NETWORK=cayenne yarn test:local --filter=testEthereumBroadcastWrappedKeyWithFetchGasParams | ||
* ❌ NETWORK=manzano yarn test:local --filter=testEthereumBroadcastWrappedKeyWithFetchGasParams Fails with Error: Error: There should be exactly 1 element in the capabilities array but there are: 2 | ||
* ❌ NETWORK=localchain yarn test:local --filter=testEthereumBroadcastWrappedKeyWithFetchGasParams | ||
*/ | ||
export const testEthereumBroadcastWrappedKeyWithFetchGasParams = async ( | ||
devEnv: TinnyEnvironment | ||
) => { | ||
const alice = await devEnv.createRandomPerson(); | ||
|
||
const pkpSessionSigs = await getPkpSessionSigs( | ||
devEnv, | ||
alice, | ||
null, | ||
new Date(Date.now() + 1000 * 60 * 10).toISOString() | ||
); // 10 mins expiry | ||
|
||
console.log(pkpSessionSigs); | ||
|
||
const wrappedKeysWallet = ethers.Wallet.createRandom(); | ||
const wrappedKeysWalletPrivateKey = wrappedKeysWallet.privateKey; | ||
|
||
const wrappedKeysWalletAddress = wrappedKeysWallet.address; | ||
console.log(`Sending funds to ${wrappedKeysWalletAddress}`); | ||
await devEnv.getFunds(wrappedKeysWallet.address, '0.005'); | ||
|
||
const pkpAddress = await importPrivateKey({ | ||
pkpSessionSigs, | ||
privateKey: wrappedKeysWalletPrivateKey, | ||
litNodeClient: devEnv.litNodeClient, | ||
}); | ||
|
||
const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; | ||
if (pkpAddress !== alicePkpAddress) { | ||
throw new Error( | ||
`Received address: ${pkpAddress} doesn't match Alice's PKP address: ${alicePkpAddress}` | ||
); | ||
} | ||
|
||
const pkpSessionSigsSigning = await getPkpSessionSigs( | ||
devEnv, | ||
alice, | ||
null, | ||
new Date(Date.now() + 1000 * 60 * 10).toISOString() | ||
); // 10 mins expiry | ||
|
||
console.log(pkpSessionSigsSigning); | ||
|
||
const unsignedTransaction: EthereumLitTransaction = { | ||
toAddress: alice.wallet.address, | ||
value: '0.0001', // in ethers (Lit tokens) | ||
chainId: 175177, // Chronicle | ||
dataHex: ethers.utils.hexlify( | ||
ethers.utils.toUtf8Bytes('Test transaction from Alice to bob') | ||
), | ||
chain: 'chronicleTestnet', | ||
}; | ||
|
||
const signedTx = await signTransactionWithEncryptedKey({ | ||
pkpSessionSigs: pkpSessionSigsSigning, | ||
litActionCode: signTransactionWithEthereumEncryptedKeyLitAction, | ||
unsignedTransaction, | ||
broadcast: true, | ||
litNodeClient: devEnv.litNodeClient, | ||
}); | ||
|
||
console.log('signedTx'); | ||
console.log(signedTx); | ||
|
||
// TODO!: Convert hex signedTx to UTF-8 and assert that it contains "Test transaction from Alice to bob" | ||
if (!ethers.utils.isHexString(signedTx)) { | ||
throw new Error(`signedTx isn't hex: ${signedTx}`); | ||
} | ||
|
||
log('✅ testEthereumBroadcastWrappedKeyWithDefaultGasParams'); | ||
}; |
86 changes: 86 additions & 0 deletions
86
local-tests/tests/testFailEthereumSignTransactionWrappedKeyInvalidDecryption.ts
This file contains hidden or 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,86 @@ | ||
import { log } from '@lit-protocol/misc'; | ||
import { ethers } from 'ethers'; | ||
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment'; | ||
import { | ||
EthereumLitTransaction, | ||
signTransactionWithEthereumEncryptedKeyLitAction, | ||
} from '@lit-protocol/wrapped-keys'; | ||
import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs'; | ||
import { getPkpAccessControlCondition } from 'packages/wrapped-keys/src/lib/utils'; | ||
import { encryptString } from '@lit-protocol/encryption'; | ||
import { LIT_PREFIX } from 'packages/wrapped-keys/src/lib/constants'; | ||
|
||
/** | ||
* Test Commands: | ||
* ✅ NETWORK=cayenne yarn test:local --filter=testFailEthereumSignTransactionWrappedKeyInvalidDecryption | ||
* ✅ NETWORK=manzano yarn test:local --filter=testFailEthereumSignTransactionWrappedKeyInvalidDecryption | ||
* ✅ NETWORK=localchain yarn test:local --filter=testFailEthereumSignTransactionWrappedKeyInvalidDecryption | ||
*/ | ||
export const testFailEthereumSignTransactionWrappedKeyInvalidDecryption = | ||
async (devEnv: TinnyEnvironment) => { | ||
const alice = await devEnv.createRandomPerson(); | ||
const privateKey = ethers.Wallet.createRandom().privateKey; | ||
const alicePkpAddress = alice.authMethodOwnedPkp.ethAddress; | ||
const decryptionAccessControlConditions = | ||
getPkpAccessControlCondition(alicePkpAddress); | ||
const { ciphertext, dataToEncryptHash } = await encryptString( | ||
{ | ||
accessControlConditions: decryptionAccessControlConditions, | ||
dataToEncrypt: LIT_PREFIX + privateKey, | ||
}, | ||
devEnv.litNodeClient | ||
); | ||
|
||
const bob = await devEnv.createRandomPerson(); | ||
const pkpSessionSigsSigning = await getPkpSessionSigs( | ||
devEnv, | ||
bob, | ||
null, | ||
new Date(Date.now() + 1000 * 60 * 10).toISOString() | ||
); // 10 mins expiry | ||
console.log(pkpSessionSigsSigning); | ||
|
||
const unsignedTransaction: EthereumLitTransaction = { | ||
toAddress: alice.wallet.address, | ||
value: '0.0001', // in ethers (Lit tokens) | ||
chainId: 175177, // Chronicle | ||
gasPrice: '50', | ||
gasLimit: 21000, | ||
dataHex: ethers.utils.hexlify( | ||
ethers.utils.toUtf8Bytes('Test transaction from Alice to bob') | ||
), | ||
chain: 'chronicleTestnet', | ||
}; | ||
|
||
try { | ||
const _res = await devEnv.litNodeClient.executeJs({ | ||
sessionSigs: pkpSessionSigsSigning, | ||
code: signTransactionWithEthereumEncryptedKeyLitAction, | ||
jsParams: { | ||
ciphertext, | ||
dataToEncryptHash, | ||
unsignedTransaction, | ||
accessControlConditions: decryptionAccessControlConditions, | ||
}, | ||
}); | ||
} catch (e: any) { | ||
console.log('❌ THIS IS EXPECTED: ', e); | ||
console.log(e.message); | ||
|
||
// TODO!: Add appropriate assertions based on the above error message | ||
// if ( | ||
// e.message.includes( | ||
// 'Error executing the Signing Lit Action: Error: When signing transaction- processing response' | ||
// ) && | ||
// e.message.includes('insufficient FPE funds for gas * price + value') | ||
// ) { | ||
// console.log( | ||
// '✅ testFailEthereumBroadcastTransactionWrappedKeysInsufficientFunds is expected to have an error' | ||
// ); | ||
// } else { | ||
// throw e; | ||
// } | ||
} | ||
|
||
log('✅ testFailEthereumSignTransactionWrappedKeyInvalidDecryption'); | ||
}; |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I'll fix it in the SDK and then there's corr fix in the Lambda as well @MaximusHaximus