-
Notifications
You must be signed in to change notification settings - Fork 73
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
Open
MaximusHaximus
wants to merge
7
commits into
master
Choose a base branch
from
LIT-3995-batchGenKeysAddSignTx
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3c9161f
feat(wrapped-keys-lit-actions): LIT-3995 - Add sign transaction capab…
MaximusHaximus 7ec8416
chore: Import type in dedicated import block
MaximusHaximus 2c075d6
feat(wrapped-keys): LIT-3995 - Add sign transaction capability to `ba…
MaximusHaximus 780ebc4
chore(wrapped-keys): LIT-3995 - signTransactionParams should be optional
MaximusHaximus 8f8cc8e
fix(wrapped-keys-lit-actions): LIT-3995 - Add test for signing tx wit…
MaximusHaximus a7ef988
Merge branch 'master' into LIT-3995-batchGenKeysAddSignTx
Ansonhkg 7d306c4
Merge branch 'master' into LIT-3995-batchGenKeysAddSignTx
Ansonhkg 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 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
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
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 } } | ||
: {}), | ||
}; | ||
} | ||
|
||
|
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.
Can we verify that the signed tx is from the the generated wallet?