-
Notifications
You must be signed in to change notification settings - Fork 105
Smart Backend Wallets #709
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
Changes from 9 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
68c21b6
smart backend wallet creation + initial flow
d4mr 05491fe
Merge branch 'main' into pb/sbw
d4mr 082b54a
refactor wallet detail decryption
d4mr 1b87760
change names
d4mr fc12095
Merge branch 'main' into pb/sbw
d4mr aaa5691
Refactor import statement for TransactionReceipt in sdk.ts
d4mr dbc567f
Refactor biome.json to ignore the "sdk" directory
d4mr 941e55d
Fix smart backend wallet functionality for both v4 and v5 SDK
d4mr 51bd785
use v6 factory default
d4mr 17245a1
consistent naming
d4mr 7bb1b80
remove redundant comment
d4mr a6ece2b
entrypoint updates
d4mr 8984844
chainId in sign + thirdweb client in e2e tests
d4mr f4ec6f9
worker refactors
d4mr 550dc14
more tests
d4mr 3256832
consistent naming
d4mr 38b46c6
Merge branch 'main' into pb/sbw
d4mr 3a47e77
conditionally require chainId for signing smart account messsages
d4mr a3957ba
naming consistencies
d4mr ef64f4c
reject transaction if unsupported chain
d4mr b5503b9
fix userop tests
d4mr b64dff4
fix: only transform QueuedTransaction if sbw
d4mr c1986ef
Refactor SWRCache to log errors during cache revalidation
d4mr 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,5 +26,8 @@ | |
| "noStaticOnlyClass": "off" | ||
| } | ||
| } | ||
| }, | ||
| "files": { | ||
| "ignore": ["sdk"] | ||
| } | ||
| } | ||
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
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
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
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
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
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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import type { Address } from "thirdweb"; | ||
| import type { PrismaTransaction } from "../../schema/prisma"; | ||
| import { encrypt } from "../../utils/crypto"; | ||
| import { getPrismaWithPostgresTx } from "../client"; | ||
|
|
@@ -8,13 +9,17 @@ type CreateWalletDetailsParams = { | |
| address: string; | ||
| label?: string; | ||
| } & ( | ||
| | { | ||
| type: "local"; | ||
| encryptedJson: string; // ENCRYPTION IS NOT HANDLED HERE, process privatekey with legacyLocalCrytpo before passing to this function | ||
| } | ||
| | { | ||
| type: "aws-kms"; | ||
| awsKmsKeyId?: string; // depcrecated and unused, todo: remove with next breaking change | ||
| awsKmsArn: string; | ||
|
|
||
| awsKmsSecretAccessKey?: string; // will be encrypted and stored, pass plaintext to this function | ||
| awsKmsAccessKeyId?: string; | ||
| awsKmsSecretAccessKey: string; // will be encrypted and stored, pass plaintext to this function | ||
| awsKmsAccessKeyId: string; | ||
| } | ||
| | { | ||
| type: "gcp-kms"; | ||
|
|
@@ -24,11 +29,39 @@ type CreateWalletDetailsParams = { | |
| gcpKmsKeyVersionId?: string; // depcrecated and unused, todo: remove with next breaking change | ||
| gcpKmsLocationId?: string; // depcrecated and unused, todo: remove with next breaking change | ||
|
|
||
| gcpApplicationCredentialPrivateKey?: string; // encrypted | ||
| gcpApplicationCredentialEmail?: string; | ||
| gcpApplicationCredentialPrivateKey: string; // will be encrypted and stored, pass plaintext to this function | ||
| gcpApplicationCredentialEmail: string; | ||
| } | ||
| | { | ||
| type: "smart:aws-kms"; | ||
| awsKmsArn: string; | ||
| awsKmsSecretAccessKey: string; // will be encrypted and stored, pass plaintext to this function | ||
| awsKmsAccessKeyId: string; | ||
| accountSignerAddress: Address; | ||
|
|
||
| accountFactoryAddress?: Address; | ||
| } | ||
| | { | ||
| type: "smart:gcp-kms"; | ||
| gcpKmsResourcePath: string; | ||
| gcpApplicationCredentialPrivateKey: string; // will be encrypted and stored, pass plaintext to this function | ||
| gcpApplicationCredentialEmail: string; | ||
| accountSignerAddress: Address; | ||
|
|
||
| accountFactoryAddress?: Address; | ||
| } | ||
arcoraven marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| | { | ||
| type: "smart:local"; | ||
| encryptedJson: string; // ENCRYPTION IS NOT HANDLED HERE, process privatekey with legacyLocalCrytpo before passing to this function | ||
| accountSignerAddress: Address; | ||
|
|
||
| accountFactoryAddress?: Address; | ||
| } | ||
| ); | ||
|
|
||
| /** | ||
| * Create a new WalletDetails row in DB | ||
| */ | ||
| export const createWalletDetails = async ({ | ||
| pgtx, | ||
| ...walletDetails | ||
|
|
@@ -47,15 +80,23 @@ export const createWalletDetails = async ({ | |
| ); | ||
| } | ||
|
|
||
| if (walletDetails.type === "local") { | ||
| return prisma.walletDetails.create({ | ||
| data: { | ||
| ...walletDetails, | ||
| address: walletDetails.address.toLowerCase(), | ||
| encryptedJson: walletDetails.encryptedJson, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| if (walletDetails.type === "aws-kms") { | ||
| return prisma.walletDetails.create({ | ||
| data: { | ||
| ...walletDetails, | ||
| address: walletDetails.address.toLowerCase(), | ||
|
|
||
| awsKmsSecretAccessKey: walletDetails.awsKmsSecretAccessKey | ||
| ? encrypt(walletDetails.awsKmsSecretAccessKey) | ||
| : undefined, | ||
| awsKmsSecretAccessKey: encrypt(walletDetails.awsKmsSecretAccessKey), | ||
| }, | ||
| }); | ||
| } | ||
|
|
@@ -66,11 +107,60 @@ export const createWalletDetails = async ({ | |
| ...walletDetails, | ||
| address: walletDetails.address.toLowerCase(), | ||
|
|
||
| gcpApplicationCredentialPrivateKey: | ||
| walletDetails.gcpApplicationCredentialPrivateKey | ||
| ? encrypt(walletDetails.gcpApplicationCredentialPrivateKey) | ||
| : undefined, | ||
| gcpApplicationCredentialPrivateKey: encrypt( | ||
| walletDetails.gcpApplicationCredentialPrivateKey, | ||
| ), | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| if (walletDetails.type === "smart:aws-kms") { | ||
| return prisma.walletDetails.create({ | ||
| data: { | ||
| ...walletDetails, | ||
|
|
||
| address: walletDetails.address.toLowerCase(), | ||
| awsKmsSecretAccessKey: encrypt(walletDetails.awsKmsSecretAccessKey), | ||
| accountSignerAddress: walletDetails.accountSignerAddress.toLowerCase(), | ||
|
|
||
| accountFactoryAddress: | ||
| walletDetails.accountFactoryAddress?.toLowerCase(), | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| if (walletDetails.type === "smart:gcp-kms") { | ||
| return prisma.walletDetails.create({ | ||
| data: { | ||
| ...walletDetails, | ||
|
|
||
| address: walletDetails.address.toLowerCase(), | ||
| accountSignerAddress: walletDetails.accountSignerAddress.toLowerCase(), | ||
|
|
||
| gcpApplicationCredentialPrivateKey: encrypt( | ||
| walletDetails.gcpApplicationCredentialPrivateKey, | ||
| ), | ||
|
|
||
| accountFactoryAddress: | ||
| walletDetails.accountFactoryAddress?.toLowerCase(), | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| if (walletDetails.type === "smart:local") { | ||
| return prisma.walletDetails.create({ | ||
| data: { | ||
| ...walletDetails, | ||
| address: walletDetails.address.toLowerCase(), | ||
| accountSignerAddress: walletDetails.accountSignerAddress.toLowerCase(), | ||
|
|
||
| accountFactoryAddress: | ||
| walletDetails.accountFactoryAddress?.toLowerCase(), | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| // we will never reach here | ||
| // this helps typescript understand that this function will always return | ||
|
||
| throw new Error("Unsupported wallet type"); | ||
| }; | ||
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.
Won't making these fields non-optional be a breaking change? We could ofc update the dashboard, but it'll impact anyone in the slim chance they're automating KMS backend wallet creation.
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.
We decided to always denormalize and store credentials in the DB row, regardless of it being an override or coming from config. Users don't have to pass it in, the route fills in this from the config.