Skip to content

Commit

Permalink
Use GCP KMS wallet from SDK (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-maj authored Sep 27, 2023
1 parent e1eb437 commit 33f0576
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 57 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@thirdweb-dev/chains": "^0.1.46",
"@thirdweb-dev/sdk": "0.0.0-dev-b1d4b3b-20230922050105",
"@thirdweb-dev/service-utils": "^0.4.2",
"@thirdweb-dev/wallets": "^1.1.23",
"@thirdweb-dev/wallets": "0.0.0-dev-d86829b-20230927000710",
"body-parser": "^1.20.2",
"cookie": "^0.5.0",
"copyfiles": "^2.4.1",
Expand Down
7 changes: 3 additions & 4 deletions server/utils/cache/getWallet.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { EVMWallet, EthersWallet } from "@thirdweb-dev/wallets";
import { EVMWallet } from "@thirdweb-dev/wallets";
import { getAwsKmsWallet } from "../../../server/utils/wallets/getAwsKmsWallet";
import { getGcpKmsSigner } from "../../../server/utils/wallets/getGcpKmsSigner";
import { getLocalWallet } from "../../../server/utils/wallets/getLocalWallet";
import { getWalletDetails } from "../../../src/db/wallets/getWalletDetails";
import { PrismaTransaction } from "../../../src/schema/prisma";
import { WalletType } from "../../../src/schema/wallet";
import { getGcpKmsWallet } from "../wallets/getGcpKmsWallet";
import { getSmartWallet } from "../wallets/getSmartWallet";

const walletsCache = new Map<string, EVMWallet>();
Expand Down Expand Up @@ -46,11 +46,10 @@ export const getWallet = async <TWallet extends EVMWallet>({
});
break;
case WalletType.gcpKms:
const signer = getGcpKmsSigner({
wallet = getGcpKmsWallet({
gcpKmsKeyId: walletDetails.gcpKmsKeyId!,
gcpKmsKeyVersionId: walletDetails.gcpKmsKeyVersionId!,
});
wallet = new EthersWallet(signer);
break;
case WalletType.local:
wallet = await getLocalWallet({ chainId, walletAddress });
Expand Down
6 changes: 3 additions & 3 deletions server/utils/wallets/createGcpKmsWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { KeyManagementServiceClient } from "@google-cloud/kms";
import { createWalletDetails } from "../../../src/db/wallets/createWalletDetails";
import { WalletType } from "../../../src/schema/wallet";
import { env } from "../../../src/utils/env";
import { getGcpKmsSigner } from "./getGcpKmsSigner";
import { getGcpKmsWallet } from "./getGcpKmsWallet";

export const createGcpKmsWallet = async (): Promise<string> => {
if (env.WALLET_CONFIGURATION.type !== WalletType.gcpKms) {
Expand Down Expand Up @@ -37,12 +37,12 @@ export const createGcpKmsWallet = async (): Promise<string> => {

await client.close();

const signer = getGcpKmsSigner({
const wallet = getGcpKmsWallet({
gcpKmsKeyId: cryptoKeyId,
gcpKmsKeyVersionId: "1",
});

const walletAddress = await signer.getAddress();
const walletAddress = await wallet.getAddress();
await createWalletDetails({
type: WalletType.gcpKms,
address: walletAddress,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { GcpKmsSigner } from "ethers-gcp-kms-signer";
import { GcpKmsWallet } from "@thirdweb-dev/wallets/evm/wallets/gcp-kms";
import { WalletType } from "../../../src/schema/wallet";
import { env } from "../../../src/utils/env";

interface GetGcpKmsSignerParams {
interface GetGcpKmsWalletParams {
gcpKmsKeyId: string;
gcpKmsKeyVersionId: string;
}

export const getGcpKmsSigner = ({
export const getGcpKmsWallet = ({
gcpKmsKeyId,
gcpKmsKeyVersionId,
}: GetGcpKmsSignerParams) => {
}: GetGcpKmsWalletParams) => {
if (env.WALLET_CONFIGURATION.type !== WalletType.gcpKms) {
throw new Error(`Server was not configured for GCP KMS.`);
}

return new GcpKmsSigner({
return new GcpKmsWallet({
projectId: env.WALLET_CONFIGURATION.gcpApplicationProjectId,
locationId: env.WALLET_CONFIGURATION.gcpKmsLocationId,
keyRingId: env.WALLET_CONFIGURATION.gcpKmsKeyRingId,
Expand Down
6 changes: 3 additions & 3 deletions server/utils/wallets/importGcpKmsWallet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createWalletDetails } from "../../../src/db/wallets/createWalletDetails";
import { WalletType } from "../../../src/schema/wallet";
import { env } from "../../../src/utils/env";
import { getGcpKmsSigner } from "./getGcpKmsSigner";
import { getGcpKmsWallet } from "./getGcpKmsWallet";

interface ImportGcpKmsWalletParams {
gcpKmsKeyId: string;
Expand All @@ -17,9 +17,9 @@ export const importGcpKmsWallet = async ({
}

const gcpKmsResourcePath = `projects/${env.WALLET_CONFIGURATION.gcpApplicationProjectId}/locations/${env.WALLET_CONFIGURATION.gcpKmsLocationId}/keyRings/${env.WALLET_CONFIGURATION.gcpKmsKeyRingId}/cryptoKeys/${gcpKmsKeyId}/cryptoKeysVersion/${gcpKmsKeyVersionId}`;
const signer = getGcpKmsSigner({ gcpKmsKeyId, gcpKmsKeyVersionId });
const wallet = getGcpKmsWallet({ gcpKmsKeyId, gcpKmsKeyVersionId });

const walletAddress = await signer.getAddress();
const walletAddress = await wallet.getAddress();
await createWalletDetails({
type: WalletType.gcpKms,
address: walletAddress,
Expand Down
65 changes: 24 additions & 41 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1958,18 +1958,18 @@
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.3.3.tgz#ff6ee919fc2a1abaf72b22814bfb72ed129ec137"
integrity sha512-tDBopO1c98Yk7Cv/PZlHqrvtVjlgK5R4J6jxLwoO7qxK4xqOiZG+zSkIvGFpPZ0ikc3QOED3plgdqjgNTnBc7g==

"@paperxyz/embedded-wallet-service-sdk@^1.1.3":
version "1.1.3"
resolved "https://registry.yarnpkg.com/@paperxyz/embedded-wallet-service-sdk/-/embedded-wallet-service-sdk-1.1.3.tgz#f2a65f27843a04dd6ada21f15924b502d296401b"
integrity sha512-3lPiUjFYTikj/amsBo+TlTDd+jFIUZ0+4BVFmROwM6qL4zecB2LQojcUq3I0Td8ho9yevdI+EQ57p6XWaq18yg==
"@paperxyz/embedded-wallet-service-sdk@^1.2.4":
version "1.2.4"
resolved "https://registry.yarnpkg.com/@paperxyz/embedded-wallet-service-sdk/-/embedded-wallet-service-sdk-1.2.4.tgz#2f7f33f7b237ca36b0ac762563bd110c08712c4b"
integrity sha512-yCOvGB6aEQB06UWowBgu0+thXOwxcHLF3j+e0YgiWtvEpZ8EgbfqbuL9NHN0zJJsTNjF05T39haDQMOBgrMpYA==
dependencies:
"@ethersproject/abstract-signer" "^5.7.0"
"@ethersproject/bytes" "^5.7.0"
"@ethersproject/properties" "^5.7.0"
"@ethersproject/providers" "^5.7.2"
"@paperxyz/sdk-common-utilities" "*"

"@paperxyz/sdk-common-utilities@*":
"@paperxyz/sdk-common-utilities@*", "@paperxyz/sdk-common-utilities@^0.1.0":
version "0.1.0"
resolved "https://registry.yarnpkg.com/@paperxyz/sdk-common-utilities/-/sdk-common-utilities-0.1.0.tgz#a948ef20d080b63e8bc0caa3ef337177a782f370"
integrity sha512-+zE2wp9gI5kjI6yHdrigeqLRDueAFz70v6hUKOT98Nyy4yL8YUR3OvXFAnAyZLXrr0v1uLlDYQdBz0fI2StmGg==
Expand Down Expand Up @@ -2795,23 +2795,16 @@
resolved "https://registry.yarnpkg.com/@thirdweb-dev/chains/-/chains-0.0.0-dev-b1d4b3b-20230922050105.tgz#dc628c6189af628a9cb05af07201b0f79794fbd2"
integrity sha512-lvZfKqjcl3puCAe/WFLOcxCGq+X/U+6NbJPr2fZHihIunvegHv/43evP7FIWuFBJzN8QLmgsaG9ufHy6ePoqyw==

"@thirdweb-dev/chains@0.1.50":
version "0.1.50"
resolved "https://registry.yarnpkg.com/@thirdweb-dev/chains/-/chains-0.1.50.tgz#857ce24a30821497974e55d75e721905cb35ca33"
integrity sha512-0rpBdFVgTE5mjgbafoBkpUnq0izx9NZz0mfFammQXWb08eQZUueuBHOVNhK2pRQT346SpQLtf65Oqag82+zZoA==
"@thirdweb-dev/chains@0.0.0-dev-d86829b-20230927000710":
version "0.0.0-dev-d86829b-20230927000710"
resolved "https://registry.yarnpkg.com/@thirdweb-dev/chains/-/chains-0.0.0-dev-d86829b-20230927000710.tgz#2035236423bf0ff2a47683185e0f1a1bc5104255"
integrity sha512-V6AGRv4XqHoHJuBwSj4rhautLoZnM6LkRBnFSQsqXxfmZwsK0IU79+Rxf/EWtSI+XEM/mTekme//q0HVp4YJUg==

"@thirdweb-dev/chains@^0.1.46":
version "0.1.46"
resolved "https://registry.yarnpkg.com/@thirdweb-dev/chains/-/chains-0.1.46.tgz#d115c0b8efb02e74ee38ef8c1237bdf476e62717"
integrity sha512-AVDLJZ6ttFY8jPzQTKe3mRMnCAQcUzK6eX5vjs9A5CqUCdq7mBmuMM4x3fRs/80FR4vRdEaEYkdRv6HCjCHxGw==

"@thirdweb-dev/[email protected]":
version "1.3.12"
resolved "https://registry.yarnpkg.com/@thirdweb-dev/contracts-js/-/contracts-js-1.3.12.tgz#57aa2ad364ad78a2816cd045f5a555514fee4891"
integrity sha512-CBgxCYea7fst4bSS1dXDDOOB2rb9FsgFCAUzQPSQIlpqajOJES1fEPZc/TlFz7u444AYxA/9NoHesQ9RipQUgA==
dependencies:
"@thirdweb-dev/contracts" "3.8.5"

"@thirdweb-dev/[email protected]":
version "1.3.13"
resolved "https://registry.yarnpkg.com/@thirdweb-dev/contracts-js/-/contracts-js-1.3.13.tgz#17b07f7ead147177aa979dd8f850030d4b31bc68"
Expand All @@ -2830,17 +2823,6 @@
"@thirdweb-dev/dynamic-contracts" "^1.1.2"
erc721a-upgradeable "^3.3.0"

"@thirdweb-dev/[email protected]":
version "3.8.5"
resolved "https://registry.yarnpkg.com/@thirdweb-dev/contracts/-/contracts-3.8.5.tgz#7c9e95808c74a43830408cb1c8a2f477c45cc371"
integrity sha512-JUAeJJlNLw+Lb/8StER8k74VEi5kXDaQx6Ko3cyJnKTWHpZ28xvGIPphkgOFaLw6cG/q4xB423crcZnQZw9YLQ==
dependencies:
"@chainlink/contracts" "^0.6.1"
"@openzeppelin/contracts" "4.7.3"
"@openzeppelin/contracts-upgradeable" "4.7.3"
"@thirdweb-dev/dynamic-contracts" "^1.1.2"
erc721a-upgradeable "^3.3.0"

"@thirdweb-dev/dynamic-contracts@^1.1.2":
version "1.1.4"
resolved "https://registry.yarnpkg.com/@thirdweb-dev/dynamic-contracts/-/dynamic-contracts-1.1.4.tgz#f14de117bad647d0f32073325627f4b31963446f"
Expand Down Expand Up @@ -2874,13 +2856,13 @@
yaml "^2.3.1"
zod "^3.20.2"

"@thirdweb-dev/sdk@3.10.59":
version "3.10.59"
resolved "https://registry.yarnpkg.com/@thirdweb-dev/sdk/-/sdk-3.10.59.tgz#9f820ee511a5bf20d865958961a125be05b7acb6"
integrity sha512-uDGc2yavYRiXP1+etUaDNLJdzaTSFRPQNoKNqzbR1HMHMHb/KHHPXHKO50AuKpc5pMw8/f+OmCphF0qTMTZu1Q==
"@thirdweb-dev/sdk@0.0.0-dev-d86829b-20230927000710":
version "0.0.0-dev-d86829b-20230927000710"
resolved "https://registry.yarnpkg.com/@thirdweb-dev/sdk/-/sdk-0.0.0-dev-d86829b-20230927000710.tgz#5bfbae7eee26bc67684434740925ab5c99e31d0d"
integrity sha512-629sIYKBKN78N5Sv2bHfjUqJU5XUYYC8WEPW4gLe7IT72aK/F+VzpUtuM36JNsRf7uGbtb2tgpDUh6vdl7JGCw==
dependencies:
"@thirdweb-dev/chains" "0.1.50"
"@thirdweb-dev/contracts-js" "1.3.12"
"@thirdweb-dev/chains" "0.0.0-dev-d86829b-20230927000710"
"@thirdweb-dev/contracts-js" "1.3.13"
"@thirdweb-dev/generated-abis" "0.0.1"
"@thirdweb-dev/storage" "1.2.10"
abitype "^0.2.5"
Expand Down Expand Up @@ -2915,10 +2897,10 @@
form-data "^4.0.0"
uuid "^9.0.0"

"@thirdweb-dev/wallets@^1.1.23":
version "1.1.23"
resolved "https://registry.yarnpkg.com/@thirdweb-dev/wallets/-/wallets-1.1.23.tgz#c6d30dea71a477a7a18f91c8745b5afab84443a3"
integrity sha512-xwFdUK3izhFdfJFq1NZnjrG03rHjxteSfxi8VV1TNL7izl36WLFbW/IkLMYnxQ8Yb90l8E7ET29mXS6VQHChjQ==
"@thirdweb-dev/wallets@0.0.0-dev-d86829b-20230927000710":
version "0.0.0-dev-d86829b-20230927000710"
resolved "https://registry.yarnpkg.com/@thirdweb-dev/wallets/-/wallets-0.0.0-dev-d86829b-20230927000710.tgz#aec384d6f3bbe3c4bb206a3c8bf58a0040d0fdb7"
integrity sha512-j2/381RERxTjDgX4eHp/yeAxbq0KTCcbwlE9uMPEO+YBd5+fa4zWF0RDTZCB+WjkLk9q0iFEEPPHPtkZGe173Q==
dependencies:
"@account-abstraction/contracts" "^0.5.0"
"@account-abstraction/sdk" "^0.5.0"
Expand All @@ -2928,13 +2910,14 @@
"@magic-ext/connect" "^6.7.2"
"@magic-ext/oauth" "^7.6.2"
"@magic-sdk/provider" "^13.6.2"
"@paperxyz/embedded-wallet-service-sdk" "^1.1.3"
"@paperxyz/embedded-wallet-service-sdk" "^1.2.4"
"@paperxyz/sdk-common-utilities" "^0.1.0"
"@safe-global/safe-core-sdk" "^3.3.4"
"@safe-global/safe-ethers-adapters" "0.1.0-alpha.17"
"@safe-global/safe-ethers-lib" "^1.9.4"
"@thirdweb-dev/chains" "0.1.50"
"@thirdweb-dev/contracts-js" "1.3.12"
"@thirdweb-dev/sdk" "3.10.59"
"@thirdweb-dev/chains" "0.0.0-dev-d86829b-20230927000710"
"@thirdweb-dev/contracts-js" "1.3.13"
"@thirdweb-dev/sdk" "0.0.0-dev-d86829b-20230927000710"
"@walletconnect/core" "^2.9.1"
"@walletconnect/ethereum-provider" "^2.9.1"
"@walletconnect/jsonrpc-utils" "^1.0.8"
Expand Down

0 comments on commit 33f0576

Please sign in to comment.