-
Notifications
You must be signed in to change notification settings - Fork 72
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
LIT-3995 - (wrapped-keys) - Add signTransaction functionality to supported actions for batchGeneratePrivateKeys
#702
base: master
Are you sure you want to change the base?
Changes from 5 commits
3c9161f
7ec8416
2c075d6
780ebc4
8f8cc8e
a7ef988
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MaximusHaximus we don't wanna allow fetching nonce, gas, etc or anything from the RPC. It should all be provided by the user either as a serialized tx or as params and we could construct the transaction inside the LA but we should not fetch anything from the RPC we can remove this fetching altogether |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
import { encryptPrivateKey } from '../../internal/common/encryptKey'; | ||
import { generateEthereumPrivateKey } from '../../internal/ethereum/generatePrivateKey'; | ||
import { signMessageEthereumKey } from '../../internal/ethereum/signMessage'; | ||
import { | ||
getValidatedUnsignedTx, | ||
signTransactionEthereumKey, | ||
} from '../../internal/ethereum/signTransaction'; | ||
import { generateSolanaPrivateKey } from '../../internal/solana/generatePrivateKey'; | ||
import { signMessageSolanaKey } from '../../internal/solana/signMessage'; | ||
import { signTransactionSolanaKey } from '../../internal/solana/signTransaction'; | ||
|
||
interface Action { | ||
network: 'evm' | 'solana'; | ||
import type { UnsignedTransaction as UnsignedTransactionEthereum } from '../../internal/ethereum/signTransaction'; | ||
import type { UnsignedTransaction as UnsignedTransactionSolana } from '../../internal/solana/signTransaction'; | ||
|
||
interface BaseAction { | ||
generateKeyParams: { | ||
memo: string; | ||
}; | ||
|
@@ -14,6 +21,24 @@ interface Action { | |
}; | ||
} | ||
|
||
interface ActionSolana extends BaseAction { | ||
network: 'solana'; | ||
signTransactionParams?: { | ||
unsignedTransaction: UnsignedTransactionSolana; | ||
broadcast: boolean; | ||
}; | ||
} | ||
|
||
interface ActionEthereum extends BaseAction { | ||
network: 'evm'; | ||
signTransactionParams?: { | ||
unsignedTransaction: UnsignedTransactionEthereum; | ||
broadcast: boolean; | ||
}; | ||
} | ||
|
||
type Action = ActionSolana | ActionEthereum; | ||
|
||
export interface BatchGenerateEncryptedKeysParams { | ||
actions: Action[]; | ||
accessControlConditions: string; | ||
|
@@ -23,27 +48,38 @@ async function processEthereumAction({ | |
action, | ||
accessControlConditions, | ||
}: { | ||
action: Action; | ||
action: ActionEthereum; | ||
accessControlConditions: string; | ||
}) { | ||
const { network, generateKeyParams } = action; | ||
const messageToSign = action.signMessageParams?.messageToSign; | ||
const unsignedTransaction = action.signTransactionParams?.unsignedTransaction; | ||
|
||
const ethereumKey = generateEthereumPrivateKey(); | ||
|
||
const [generatedPrivateKey, messageSignature] = await Promise.all([ | ||
encryptPrivateKey({ | ||
accessControlConditions, | ||
publicKey: ethereumKey.publicKey, | ||
privateKey: ethereumKey.privateKey, | ||
}), | ||
messageToSign | ||
? signMessageEthereumKey({ | ||
messageToSign: messageToSign, | ||
privateKey: ethereumKey.privateKey, | ||
}) | ||
: Promise.resolve(), | ||
]); | ||
const [generatedPrivateKey, messageSignature, transactionSignature] = | ||
await Promise.all([ | ||
encryptPrivateKey({ | ||
accessControlConditions, | ||
publicKey: ethereumKey.publicKey, | ||
privateKey: ethereumKey.privateKey, | ||
}), | ||
messageToSign | ||
? signMessageEthereumKey({ | ||
messageToSign: messageToSign, | ||
privateKey: ethereumKey.privateKey, | ||
}) | ||
: Promise.resolve(), | ||
|
||
unsignedTransaction | ||
? signTransactionEthereumKey({ | ||
unsignedTransaction, | ||
broadcast: action.signTransactionParams?.broadcast || false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't allow broadcast in the batchGenerate function as it uses RPC which can take arbitrary amounts of time? |
||
privateKey: ethereumKey.privateKey, | ||
validatedTx: getValidatedUnsignedTx(unsignedTransaction), | ||
}) | ||
: Promise.resolve(), | ||
]); | ||
|
||
return { | ||
network, | ||
|
@@ -54,35 +90,47 @@ async function processEthereumAction({ | |
...(messageSignature | ||
? { signMessage: { signature: messageSignature } } | ||
: {}), | ||
...(transactionSignature | ||
? { signTransaction: { signature: transactionSignature } } | ||
: {}), | ||
}; | ||
} | ||
|
||
async function processSolanaAction({ | ||
action, | ||
accessControlConditions, | ||
}: { | ||
action: Action; | ||
action: ActionSolana; | ||
accessControlConditions: string; | ||
}) { | ||
const { network, generateKeyParams } = action; | ||
|
||
const messageToSign = action.signMessageParams?.messageToSign; | ||
const unsignedTransaction = action.signTransactionParams?.unsignedTransaction; | ||
|
||
const solanaKey = generateSolanaPrivateKey(); | ||
|
||
const [generatedPrivateKey, messageSignature] = await Promise.all([ | ||
encryptPrivateKey({ | ||
accessControlConditions, | ||
publicKey: solanaKey.publicKey, | ||
privateKey: solanaKey.privateKey, | ||
}), | ||
messageToSign | ||
? signMessageSolanaKey({ | ||
messageToSign: messageToSign, | ||
privateKey: solanaKey.privateKey, | ||
}) | ||
: Promise.resolve(), | ||
]); | ||
const [generatedPrivateKey, messageSignature, transactionSignature] = | ||
await Promise.all([ | ||
encryptPrivateKey({ | ||
accessControlConditions, | ||
publicKey: solanaKey.publicKey, | ||
privateKey: solanaKey.privateKey, | ||
}), | ||
messageToSign | ||
? signMessageSolanaKey({ | ||
messageToSign: messageToSign, | ||
privateKey: solanaKey.privateKey, | ||
}) | ||
: Promise.resolve(), | ||
unsignedTransaction | ||
? signTransactionSolanaKey({ | ||
broadcast: action.signTransactionParams?.broadcast || false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't allow broadcast? |
||
unsignedTransaction, | ||
privateKey: solanaKey.privateKey, | ||
}) | ||
: Promise.resolve(), | ||
]); | ||
|
||
return { | ||
network, | ||
|
@@ -93,6 +141,9 @@ async function processSolanaAction({ | |
...(messageSignature | ||
? { signMessage: { signature: messageSignature } } | ||
: {}), | ||
...(transactionSignature | ||
? { signTransaction: { signature: transactionSignature } } | ||
: {}), | ||
}; | ||
} | ||
|
||
|
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.
Can we verify that the signed tx is from the the generated wallet?