From 51c4f2b2ef4a27e779c60277a309b8b3eaad2551 Mon Sep 17 00:00:00 2001 From: Andrew Min Date: Wed, 18 Oct 2023 07:41:20 -0400 Subject: [PATCH 1/6] bump viem version --- .../src/pages/index.tsx | 4 +- examples/with-viem/package.json | 3 +- packages/viem/package.json | 4 +- pnpm-lock.yaml | 128 ++++++++++++++---- 4 files changed, 109 insertions(+), 30 deletions(-) diff --git a/examples/with-viem-and-passkeys/src/pages/index.tsx b/examples/with-viem-and-passkeys/src/pages/index.tsx index c89b2e1a3..f01a551c7 100644 --- a/examples/with-viem-and-passkeys/src/pages/index.tsx +++ b/examples/with-viem-and-passkeys/src/pages/index.tsx @@ -6,7 +6,7 @@ import { useForm } from "react-hook-form"; import axios from "axios"; import { WebauthnStamper } from "@turnkey/webauthn-stamper"; import { useState } from "react"; -import { createWalletClient, http } from "viem"; +import { createWalletClient, http, type Account } from "viem"; import { sepolia } from "viem/chains"; type subOrgFormData = { @@ -114,7 +114,7 @@ export default function Home() { }); const viemClient = createWalletClient({ - account: viemAccount, + account: viemAccount as Account, chain: sepolia, transport: http(), }); diff --git a/examples/with-viem/package.json b/examples/with-viem/package.json index 17e85f322..56caf1c83 100644 --- a/examples/with-viem/package.json +++ b/examples/with-viem/package.json @@ -5,6 +5,7 @@ "scripts": { "start": "pnpm -w run build-all && tsx src/index.ts", "start-advanced": "pnpm -w run build-all && tsx src/advanced.ts", + "start-contracts": "pnpm -w run build-all && tsx src/contracts.ts", "clean": "rimraf ./dist ./.cache", "typecheck": "tsc --noEmit" }, @@ -18,6 +19,6 @@ "dotenv": "^16.0.3", "fetch": "^1.1.0", "typescript": "5.1", - "viem": "^1.10.0" + "viem": "^1.16.6" } } diff --git a/packages/viem/package.json b/packages/viem/package.json index 3f17643ec..fd2ca6bb5 100644 --- a/packages/viem/package.json +++ b/packages/viem/package.json @@ -43,7 +43,7 @@ "compile:contracts": "hardhat compile" }, "peerDependencies": { - "viem": "^1.10.0" + "viem": "^1.16.6" }, "dependencies": { "@turnkey/api-key-stamper": "workspace:*", @@ -54,7 +54,7 @@ "devDependencies": { "@types/jest": "^29.5.3", "jest": "^29.3.1", - "viem": "^1.10.0" + "viem": "^1.16.6" }, "engines": { "node": ">=18.0.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fb25d8fd5..4afabf578 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -501,8 +501,8 @@ importers: specifier: '5.1' version: 5.1.3 viem: - specifier: ^1.10.0 - version: 1.10.0(typescript@5.1.3) + specifier: ^1.16.6 + version: 1.16.6(typescript@5.1.3) examples/with-viem-and-passkeys: dependencies: @@ -676,8 +676,8 @@ importers: specifier: ^29.3.1 version: 29.4.3(@types/node@16.18.12) viem: - specifier: ^1.10.0 - version: 1.10.0(typescript@5.1.5) + specifier: ^1.16.6 + version: 1.16.6(typescript@5.1.5) packages/webauthn-stamper: dependencies: @@ -694,6 +694,10 @@ packages: /@adraffy/ens-normalize@1.9.0: resolution: {integrity: sha512-iowxq3U30sghZotgl4s/oJRci6WPBfNO5YYgk2cIOMCHr3LeGPcsZjCEr+33Q4N+oV3OABDAtA+pyvWjbvBifQ==} + dev: false + + /@adraffy/ens-normalize@1.9.4: + resolution: {integrity: sha512-UK0bHA7hh9cR39V+4gl2/NnBBjoXIxkuWAPCaY4X7fbH4L/azIi7ilWOCjMUYfpJgraLUAqkRi2BqrjME8Rynw==} /@ampproject/remapping@2.2.0: resolution: {integrity: sha512-qRmjj8nj9qmLTQXXmaR1cck3UXSRMPrbsLJAasZpF+t3riI71BXed5ebIOYwQntykeZuhjsdweEc9BxH5Jc26w==} @@ -2329,7 +2333,7 @@ packages: /@confio/ics23@0.6.8: resolution: {integrity: sha512-wB6uo+3A50m0sW/EWcU64xpV/8wShZ6bMTa7pF8eYsTrSkQA7oLUIJcs/wb8g4y2Oyq701BaGiO6n/ak5WXO1w==} dependencies: - '@noble/hashes': 1.3.1 + '@noble/hashes': 1.3.2 protobufjs: 7.2.4 dev: false @@ -3660,21 +3664,34 @@ packages: resolution: {integrity: sha512-2upgEu0iLiDVDZkNLeFV2+ht0BAVgQnEmCk6JsOch9Rp8xfkMCbvbAZlA2pBHQc73dbl+vFOXfqkf4uemdn0bw==} dependencies: '@noble/hashes': 1.3.0 + dev: false /@noble/curves@1.1.0: resolution: {integrity: sha512-091oBExgENk/kGj3AZmtBDMpxQPDtxQABR2B9lb1JbVTs6ytdzZNwvhxQ4MWasRNEzlbEH8jCWFCwhF/Obj5AA==} dependencies: '@noble/hashes': 1.3.1 + dev: false + + /@noble/curves@1.2.0: + resolution: {integrity: sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==} + dependencies: + '@noble/hashes': 1.3.2 /@noble/hashes@1.2.0: resolution: {integrity: sha512-FZfhjEDbT5GRswV3C6uvLPHMiVD6lQBmpoX5+eSiPaMTXte/IKqI5dykDxzZB/WBeK/CDuQRBWarPdi3FNY2zQ==} /@noble/hashes@1.3.0: resolution: {integrity: sha512-ilHEACi9DwqJB0pw7kv+Apvh50jiiSyR/cQ3y4W7lOR5mhvn/50FLUfsnfJz0BDZtl/RR16kXvptiv6q1msYZg==} + dev: false /@noble/hashes@1.3.1: resolution: {integrity: sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==} engines: {node: '>= 16'} + dev: false + + /@noble/hashes@1.3.2: + resolution: {integrity: sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==} + engines: {node: '>= 16'} /@noble/secp256k1@1.7.1: resolution: {integrity: sha512-hOUk6AyBFmqVrv7k5WAw/LpszxVbj9gGN4JRkIX52fdFAj1UA61KXmZDvqVEm+pOyec3+fIeZB02LYa/pWOArw==} @@ -4325,30 +4342,48 @@ packages: /@scure/base@1.1.1: resolution: {integrity: sha512-ZxOhsSyxYwLJj3pLZCefNitxsj093tb2vq90mp2txoYeBqbcjDjqFhyM8eUjq/uFm6zJ+mUuqxlS2FkuSY1MTA==} + /@scure/base@1.1.3: + resolution: {integrity: sha512-/+SgoRjLq7Xlf0CWuLHq2LUZeL/w65kfzAPG5NH9pcmBhs+nunQTn4gvdwgMTIXnt9b2C/1SeL2XiysZEyIC9Q==} + /@scure/bip32@1.1.5: resolution: {integrity: sha512-XyNh1rB0SkEqd3tXcXMi+Xe1fvg+kUIcoRIEujP1Jgv7DqW2r9lg3Ah0NkFaCs9sTkQAQA8kw7xiRXzENi9Rtw==} dependencies: '@noble/hashes': 1.2.0 '@noble/secp256k1': 1.7.1 - '@scure/base': 1.1.1 + '@scure/base': 1.1.3 /@scure/bip32@1.3.0: resolution: {integrity: sha512-bcKpo1oj54hGholplGLpqPHRbIsnbixFtc06nwuNM5/dwSXOq/AAYoIBRsBmnZJSdfeNW5rnff7NTAz3ZCqR9Q==} dependencies: '@noble/curves': 1.0.0 - '@noble/hashes': 1.3.1 + '@noble/hashes': 1.3.2 '@scure/base': 1.1.1 + dev: false + + /@scure/bip32@1.3.2: + resolution: {integrity: sha512-N1ZhksgwD3OBlwTv3R6KFEcPojl/W4ElJOeCZdi+vuI5QmTFwLq3OFf2zd2ROpKvxFdgZ6hUpb0dx9bVNEwYCA==} + dependencies: + '@noble/curves': 1.2.0 + '@noble/hashes': 1.3.2 + '@scure/base': 1.1.3 /@scure/bip39@1.1.1: resolution: {integrity: sha512-t+wDck2rVkh65Hmv280fYdVdY25J9YeEUIgn2LG1WM6gxFkGzcksoDiUkWVpVp3Oex9xGC68JU2dSbUfwZ2jPg==} dependencies: '@noble/hashes': 1.2.0 - '@scure/base': 1.1.1 + '@scure/base': 1.1.3 /@scure/bip39@1.2.0: resolution: {integrity: sha512-SX/uKq52cuxm4YFXWFaVByaSHJh2w3BnokVSeUJVCv6K7WulT9u2BuNRBhuFl8vAuYnzx9bEu9WgpcNYTrYieg==} dependencies: - '@noble/hashes': 1.3.1 + '@noble/hashes': 1.3.2 + '@scure/base': 1.1.1 + dev: false + + /@scure/bip39@1.2.1: + resolution: {integrity: sha512-Z3/Fsz1yr904dduJD0NpiyRHhRYHdcnyh73FZWiV+/qhWi83wNJ3NWolYqCEN+ZWsUz2TWwajJggcRE9r1zUYg==} + dependencies: + '@noble/hashes': 1.3.2 '@scure/base': 1.1.1 /@sentry/core@5.30.0: @@ -4645,6 +4680,7 @@ packages: resolution: {integrity: sha512-lwhs8hktwxSjf9UaZ9tG5M03PGogvFaH8gUgLNbN9HKIg0dvv6q+gkSuJ8HN4/VbyxkuLzCjlN7GquQ0gUJfIg==} dependencies: '@types/node': 16.18.12 + dev: false /@types/yargs-parser@21.0.0: resolution: {integrity: sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==} @@ -4879,8 +4915,22 @@ packages: typescript: 5.1.3 dev: false - /abitype@0.9.3(typescript@5.1.5): - resolution: {integrity: sha512-dz4qCQLurx97FQhnb/EIYTk/ldQ+oafEDUqC0VVIeQS1Q48/YWt/9YNfMmp9SLFqN41ktxny3c8aYxHjmFIB/w==} + /abitype@0.9.8(typescript@5.1.3): + resolution: {integrity: sha512-puLifILdm+8sjyss4S+fsUN09obiT1g2YW6CtcQF+QDzxR0euzgEB29MZujC6zMk2a6SVmtttq1fc6+YFA7WYQ==} + peerDependencies: + typescript: '>=5.0.4' + zod: ^3 >=3.19.1 + peerDependenciesMeta: + typescript: + optional: true + zod: + optional: true + dependencies: + typescript: 5.1.3 + dev: false + + /abitype@0.9.8(typescript@5.1.5): + resolution: {integrity: sha512-puLifILdm+8sjyss4S+fsUN09obiT1g2YW6CtcQF+QDzxR0euzgEB29MZujC6zMk2a6SVmtttq1fc6+YFA7WYQ==} peerDependencies: typescript: '>=5.0.4' zod: ^3 >=3.19.1 @@ -5449,7 +5499,6 @@ packages: requiresBuild: true dependencies: node-gyp-build: 4.6.0 - dev: false /bundle-name@3.0.0: resolution: {integrity: sha512-PKA4BeSvBpQKQ8iPOGCSiell+N8P+Tf1DlwqmYhpe2gAhKPHn8EYOxVT+ShuGmhg8lN8XiSlS80yiExKXrURlw==} @@ -7571,6 +7620,14 @@ packages: ws: '*' dependencies: ws: 8.12.0 + dev: false + + /isows@1.0.3(ws@8.13.0): + resolution: {integrity: sha512-2cKei4vlmg2cxEjm3wVSqn8pcoRF/LX/wpifuuNquFO4SQmPwarClT+SUCA2lt+l581tTeZIPIZuIDo2jWN1fg==} + peerDependencies: + ws: '*' + dependencies: + ws: 8.13.0(bufferutil@4.0.7)(utf-8-validate@5.0.10) /istanbul-lib-coverage@3.2.0: resolution: {integrity: sha512-eOeJ5BHCmHYvQK7xt9GkdHuzuCGS1Y6g9Gvnx3Ym33fz/HpLRYxiS0wHNr+m/MBC8B647Xt608vCDEvhl9c6Mw==} @@ -10039,7 +10096,6 @@ packages: requiresBuild: true dependencies: node-gyp-build: 4.6.0 - dev: false /utf8@3.0.0: resolution: {integrity: sha512-E8VjFIQ/TyQgp+TZfS6l8yp/xWppSAHzidGiRrqe4bK4XP9pTRyKFgGJpO3SN7zdX4DeomTrwaseCHovfpFcqQ==} @@ -10102,24 +10158,46 @@ packages: - zod dev: false - /viem@1.10.0(typescript@5.1.5): - resolution: {integrity: sha512-uV8ICcgu+3BghTpzsSiYtpyPUrZpTYgPjBkwhPoM6WsF34JAKdV7HVWiWKxrrkP5GqIRJhkT5lRflJrdv5ftng==} + /viem@1.16.6(typescript@5.1.3): + resolution: {integrity: sha512-jcWcFQ+xzIfDwexwPJRvCuCRJKEkK9iHTStG7mpU5MmuSBpACs4nATBDyXNFtUiyYTFzLlVEwWkt68K0nCSImg==} peerDependencies: typescript: '>=5.0.4' peerDependenciesMeta: typescript: optional: true dependencies: - '@adraffy/ens-normalize': 1.9.0 - '@noble/curves': 1.1.0 - '@noble/hashes': 1.3.0 - '@scure/bip32': 1.3.0 - '@scure/bip39': 1.2.0 - '@types/ws': 8.5.5 - abitype: 0.9.3(typescript@5.1.5) - isomorphic-ws: 5.0.0(ws@8.12.0) + '@adraffy/ens-normalize': 1.9.4 + '@noble/curves': 1.2.0 + '@noble/hashes': 1.3.2 + '@scure/bip32': 1.3.2 + '@scure/bip39': 1.2.1 + abitype: 0.9.8(typescript@5.1.3) + isows: 1.0.3(ws@8.13.0) + typescript: 5.1.3 + ws: 8.13.0(bufferutil@4.0.7)(utf-8-validate@5.0.10) + transitivePeerDependencies: + - bufferutil + - utf-8-validate + - zod + dev: false + + /viem@1.16.6(typescript@5.1.5): + resolution: {integrity: sha512-jcWcFQ+xzIfDwexwPJRvCuCRJKEkK9iHTStG7mpU5MmuSBpACs4nATBDyXNFtUiyYTFzLlVEwWkt68K0nCSImg==} + peerDependencies: + typescript: '>=5.0.4' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@adraffy/ens-normalize': 1.9.4 + '@noble/curves': 1.2.0 + '@noble/hashes': 1.3.2 + '@scure/bip32': 1.3.2 + '@scure/bip39': 1.2.1 + abitype: 0.9.8(typescript@5.1.5) + isows: 1.0.3(ws@8.13.0) typescript: 5.1.5 - ws: 8.12.0 + ws: 8.13.0(bufferutil@4.0.7)(utf-8-validate@5.0.10) transitivePeerDependencies: - bufferutil - utf-8-validate @@ -10396,6 +10474,7 @@ packages: optional: true utf-8-validate: optional: true + dev: false /ws@8.13.0(bufferutil@4.0.7)(utf-8-validate@5.0.10): resolution: {integrity: sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==} @@ -10411,7 +10490,6 @@ packages: dependencies: bufferutil: 4.0.7 utf-8-validate: 5.0.10 - dev: false /xstream@11.14.0: resolution: {integrity: sha512-1bLb+kKKtKPbgTK6i/BaoAn03g47PpFstlbe1BA+y3pNS/LfvcaghS5BFf9+EE1J+KwSQsEpfJvFN5GqFtiNmw==} From 2816599cd0a9e793b313d97f27a4142c22ad837d Mon Sep 17 00:00:00 2001 From: Andrew Min Date: Wed, 18 Oct 2023 07:41:28 -0400 Subject: [PATCH 2/6] add getAddresses() test --- packages/viem/src/__tests__/index-test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/viem/src/__tests__/index-test.ts b/packages/viem/src/__tests__/index-test.ts index 48637a12d..47a1a0d25 100644 --- a/packages/viem/src/__tests__/index-test.ts +++ b/packages/viem/src/__tests__/index-test.ts @@ -111,6 +111,13 @@ describe("TurnkeyAccount", () => { }); }); + testCase("it is connected to the right address", async () => { + const addresses = await walletClient.getAddresses(); + + expect(turnkeyAccount.address).toEqual(expectedEthAddress); + expect(addresses).toEqual([expectedEthAddress]); + }); + testCase("it signs transactions", async () => { const request = await walletClient.prepareTransactionRequest({ account: turnkeyAccount, From 552b25338788828abd3d813984748ea82ec21269 Mon Sep 17 00:00:00 2001 From: Andrew Min Date: Wed, 18 Oct 2023 07:56:12 -0400 Subject: [PATCH 3/6] add contract and simulate examples --- examples/with-viem/src/contracts.ts | 81 ++++++++++ .../src/createNewEthereumPrivateKey.ts | 79 +++++++++ examples/with-viem/src/weth-contract-abi.json | 153 ++++++++++++++++++ 3 files changed, 313 insertions(+) create mode 100644 examples/with-viem/src/contracts.ts create mode 100644 examples/with-viem/src/createNewEthereumPrivateKey.ts create mode 100644 examples/with-viem/src/weth-contract-abi.json diff --git a/examples/with-viem/src/contracts.ts b/examples/with-viem/src/contracts.ts new file mode 100644 index 000000000..4bca5f26c --- /dev/null +++ b/examples/with-viem/src/contracts.ts @@ -0,0 +1,81 @@ +import * as path from "path"; +import * as dotenv from "dotenv"; + +import { createAccount } from "@turnkey/viem"; +import { TurnkeyClient } from "@turnkey/http"; +import { ApiKeyStamper } from "@turnkey/api-key-stamper"; +import { + createWalletClient, + createPublicClient, + http, + type Account, +} from "viem"; +import { goerli } from "viem/chains"; +import { print } from "./util"; +import { createNewEthereumPrivateKey } from "./createNewEthereumPrivateKey"; +import WETH_TOKEN_ABI from "./weth-contract-abi.json"; +const WETH_TOKEN_ADDRESS_GOERLI = "0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6"; + +// Load environment variables from `.env.local` +dotenv.config({ path: path.resolve(process.cwd(), ".env.local") }); + +async function main() { + if (!process.env.PRIVATE_KEY_ID) { + // If you don't specify a `PRIVATE_KEY_ID`, we'll create one for you via calling the Turnkey API. + await createNewEthereumPrivateKey(); + return; + } + + const turnkeyClient = new TurnkeyClient( + { + baseUrl: process.env.BASE_URL!, + }, + new ApiKeyStamper({ + apiPublicKey: process.env.API_PUBLIC_KEY!, + apiPrivateKey: process.env.API_PRIVATE_KEY!, + }) + ); + + const turnkeyAccount = await createAccount({ + client: turnkeyClient, + organizationId: process.env.ORGANIZATION_ID!, + privateKeyId: process.env.PRIVATE_KEY_ID!, + }); + + const client = createWalletClient({ + account: turnkeyAccount as Account, + chain: goerli, + transport: http( + `https://goerli.infura.io/v3/${process.env.INFURA_API_KEY!}` + ), + }); + + const address = client.account.address; + print("Address:", address); + + const publicClient = createPublicClient({ + transport: http("https://rpc.ankr.com/eth_goerli"), + chain: goerli, + }); + + const { request } = await publicClient.simulateContract({ + abi: WETH_TOKEN_ABI, + address: WETH_TOKEN_ADDRESS_GOERLI, + functionName: "deposit", + chain: goerli, + value: 1n, + account: client.account, + }); + + const hash = await client.writeContract(request); + + print( + "Successfully wrapped ETH 🥳. Transaction:", + `https://goerli.etherscan.io/tx/${hash}` + ); +} + +main().catch((error) => { + console.error(error); + process.exit(1); +}); diff --git a/examples/with-viem/src/createNewEthereumPrivateKey.ts b/examples/with-viem/src/createNewEthereumPrivateKey.ts new file mode 100644 index 000000000..894b680ed --- /dev/null +++ b/examples/with-viem/src/createNewEthereumPrivateKey.ts @@ -0,0 +1,79 @@ +import { TurnkeyClient, createActivityPoller, TurnkeyActivityError } from "@turnkey/http"; +import { ApiKeyStamper } from "@turnkey/api-key-stamper"; +import * as crypto from "crypto"; + +export async function createNewEthereumPrivateKey() { + console.log("creating a new Ethereum private key on Turnkey...\n"); + + const privateKeyName = `ETH Key ${crypto.randomBytes(2).toString("hex")}`; + + try { + const turnkeyClient = new TurnkeyClient( + { baseUrl: process.env.BASE_URL! }, + new ApiKeyStamper({ + apiPublicKey: process.env.API_PUBLIC_KEY!, + apiPrivateKey: process.env.API_PRIVATE_KEY!, + }) + ); + + const activityPoller = createActivityPoller({ + client: turnkeyClient, + requestFn: turnkeyClient.createPrivateKeys, + }); + + const completedActivity = await activityPoller({ + type: "ACTIVITY_TYPE_CREATE_PRIVATE_KEYS_V2", + timestampMs: String(Date.now()), + organizationId: process.env.ORGANIZATION_ID!, + parameters: { + privateKeys: [ + { + privateKeyName, + curve: "CURVE_SECP256K1", + addressFormats: ["ADDRESS_FORMAT_ETHEREUM"], + privateKeyTags: [], + }, + ], + }, + }); + + const privateKey = refineNonNull( + completedActivity.result.createPrivateKeysResultV2?.privateKeys?.[0] + ); + const privateKeyId = refineNonNull(privateKey.privateKeyId); + const address = refineNonNull(privateKey.addresses?.[0]?.address); + + // Success! + console.log( + [ + `New Ethereum private key created!`, + `- Name: ${privateKeyName}`, + `- Private key ID: ${privateKeyId}`, + `- Address: ${address}`, + ``, + "Now you can take the private key ID, put it in `.env.local`, then re-run the script.", + ].join("\n") + ); + } catch (error) { + // If needed, you can read from `TurnkeyActivityError` to find out why the activity didn't succeed + if (error instanceof TurnkeyActivityError) { + throw error; + } + + throw new TurnkeyActivityError({ + message: "Failed to create a new Ethereum private key", + cause: error as Error, + }); + } +} + +export function refineNonNull( + input: T | null | undefined, + errorMessage?: string +): T { + if (input == null) { + throw new Error(errorMessage ?? `Unexpected ${JSON.stringify(input)}`); + } + + return input; +} diff --git a/examples/with-viem/src/weth-contract-abi.json b/examples/with-viem/src/weth-contract-abi.json new file mode 100644 index 000000000..4827e8723 --- /dev/null +++ b/examples/with-viem/src/weth-contract-abi.json @@ -0,0 +1,153 @@ +[ + { + "constant": true, + "inputs": [], + "name": "name", + "outputs": [{ "name": "", "type": "string" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "guy", "type": "address" }, + { "name": "wad", "type": "uint256" } + ], + "name": "approve", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "src", "type": "address" }, + { "name": "dst", "type": "address" }, + { "name": "wad", "type": "uint256" } + ], + "name": "transferFrom", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "wad", "type": "uint256" }], + "name": "withdraw", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "decimals", + "outputs": [{ "name": "", "type": "uint8" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "", "type": "address" }], + "name": "balanceOf", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "symbol", + "outputs": [{ "name": "", "type": "string" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "dst", "type": "address" }, + { "name": "wad", "type": "uint256" } + ], + "name": "transfer", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "deposit", + "outputs": [], + "payable": true, + "stateMutability": "payable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { "name": "", "type": "address" }, + { "name": "", "type": "address" } + ], + "name": "allowance", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { "payable": true, "stateMutability": "payable", "type": "fallback" }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "src", "type": "address" }, + { "indexed": true, "name": "guy", "type": "address" }, + { "indexed": false, "name": "wad", "type": "uint256" } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "src", "type": "address" }, + { "indexed": true, "name": "dst", "type": "address" }, + { "indexed": false, "name": "wad", "type": "uint256" } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "dst", "type": "address" }, + { "indexed": false, "name": "wad", "type": "uint256" } + ], + "name": "Deposit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "src", "type": "address" }, + { "indexed": false, "name": "wad", "type": "uint256" } + ], + "name": "Withdrawal", + "type": "event" + } +] From 7b6aceac1d2d60581db8a2cb0e0e2b74e412eba1 Mon Sep 17 00:00:00 2001 From: Andrew Min Date: Wed, 18 Oct 2023 07:57:37 -0400 Subject: [PATCH 4/6] add private key checks --- examples/with-viem/src/advanced.ts | 7 +++++++ examples/with-viem/src/index.ts | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/examples/with-viem/src/advanced.ts b/examples/with-viem/src/advanced.ts index e4fbe51c7..7dcaf7441 100644 --- a/examples/with-viem/src/advanced.ts +++ b/examples/with-viem/src/advanced.ts @@ -15,11 +15,18 @@ import { } from "viem"; import { sepolia } from "viem/chains"; import { print, assertEqual } from "./util"; +import { createNewEthereumPrivateKey } from "./createNewEthereumPrivateKey"; // Load environment variables from `.env.local` dotenv.config({ path: path.resolve(process.cwd(), ".env.local") }); async function main() { + if (!process.env.PRIVATE_KEY_ID) { + // If you don't specify a `PRIVATE_KEY_ID`, we'll create one for you via calling the Turnkey API. + await createNewEthereumPrivateKey(); + return; + } + const turnkeyClient = new TurnkeyClient( { baseUrl: process.env.BASE_URL!, diff --git a/examples/with-viem/src/index.ts b/examples/with-viem/src/index.ts index 60f1908d5..dcabcaa73 100644 --- a/examples/with-viem/src/index.ts +++ b/examples/with-viem/src/index.ts @@ -7,11 +7,18 @@ import { ApiKeyStamper } from "@turnkey/api-key-stamper"; import { createWalletClient, http, recoverMessageAddress } from "viem"; import { sepolia } from "viem/chains"; import { print, assertEqual } from "./util"; +import { createNewEthereumPrivateKey } from "./createNewEthereumPrivateKey"; // Load environment variables from `.env.local` dotenv.config({ path: path.resolve(process.cwd(), ".env.local") }); async function main() { + if (!process.env.PRIVATE_KEY_ID) { + // If you don't specify a `PRIVATE_KEY_ID`, we'll create one for you via calling the Turnkey API. + await createNewEthereumPrivateKey(); + return; + } + const turnkeyClient = new TurnkeyClient( { baseUrl: process.env.BASE_URL!, From da7c9605969cff3f5aadb81bee7469791093ef06 Mon Sep 17 00:00:00 2001 From: Andrew Min Date: Wed, 18 Oct 2023 09:38:14 -0700 Subject: [PATCH 5/6] add changeset --- .changeset/rude-turtles-refuse.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/rude-turtles-refuse.md diff --git a/.changeset/rude-turtles-refuse.md b/.changeset/rude-turtles-refuse.md new file mode 100644 index 000000000..e502a5a9f --- /dev/null +++ b/.changeset/rude-turtles-refuse.md @@ -0,0 +1,5 @@ +--- +"@turnkey/viem": patch +--- + +Bump Viem dependency to fix `getAddresses()` for LocalAccount From a5a284379dd1ba56546e5cf0b331f1fe99dd0d2d Mon Sep 17 00:00:00 2001 From: Andrew Min Date: Wed, 18 Oct 2023 09:51:34 -0700 Subject: [PATCH 6/6] prettier --- examples/with-viem/src/createNewEthereumPrivateKey.ts | 6 +++++- examples/with-viem/src/index.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/with-viem/src/createNewEthereumPrivateKey.ts b/examples/with-viem/src/createNewEthereumPrivateKey.ts index 894b680ed..d9a155fbc 100644 --- a/examples/with-viem/src/createNewEthereumPrivateKey.ts +++ b/examples/with-viem/src/createNewEthereumPrivateKey.ts @@ -1,4 +1,8 @@ -import { TurnkeyClient, createActivityPoller, TurnkeyActivityError } from "@turnkey/http"; +import { + TurnkeyClient, + createActivityPoller, + TurnkeyActivityError, +} from "@turnkey/http"; import { ApiKeyStamper } from "@turnkey/api-key-stamper"; import * as crypto from "crypto"; diff --git a/examples/with-viem/src/index.ts b/examples/with-viem/src/index.ts index dcabcaa73..ee40c09e4 100644 --- a/examples/with-viem/src/index.ts +++ b/examples/with-viem/src/index.ts @@ -18,7 +18,7 @@ async function main() { await createNewEthereumPrivateKey(); return; } - + const turnkeyClient = new TurnkeyClient( { baseUrl: process.env.BASE_URL!,