Skip to content

Commit

Permalink
Merge branch 'main' into eng-1441
Browse files Browse the repository at this point in the history
  • Loading branch information
turnekybc committed Dec 9, 2024
2 parents a2b4c77 + 9ac15aa commit 45ec70a
Show file tree
Hide file tree
Showing 71 changed files with 3,585 additions and 390 deletions.
5 changes: 0 additions & 5 deletions .changeset/itchy-jeans-try.md

This file was deleted.

3 changes: 2 additions & 1 deletion .codesandbox/ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"packages/wallet-stamper",
"packages/iframe-stamper",
"packages/crypto",
"packages/react-native-passkey-stamper"
"packages/react-native-passkey-stamper",
"packages/telegram-cloud-storage-stamper"
],
"sandboxes": [],
"node": "18"
Expand Down
154 changes: 103 additions & 51 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/kitchen-sink/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@turnkey/kitchen-sink",
"version": "0.1.2",
"version": "0.1.4",
"private": true,
"scripts": {
"start-sdk-server": "tsx sdkServerClient.ts",
Expand Down
18 changes: 18 additions & 0 deletions examples/with-biconomy-aa/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# @turnkey/with-biconomy-aa

## 0.2.0

- Add support for Nexus (latest offering from Biconomy) with Turnkey and Viem.
- Use v2 of jiffyscan everywhere
- Several resources to learn more about Nexus here:
- https://github.com/bcnmy/nexus/wiki
- https://docs.biconomy.io/nexus-client
- https://docs.biconomy.io/overview#what-is-nexus
- https://docs.biconomy.io/quickstart#sending-your-first-transaction-with-nexus-sdk-%EF%B8%8F
- https://docs.biconomy.io/tutorials/gasless#set-up-nexus-client-with-paymaster

## 0.1.0

Initial release

- Add integration between Turnkey, Biconomy smart accounts, and both Viem and Ethers.
60 changes: 58 additions & 2 deletions examples/with-biconomy-aa/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,67 @@ Sent 0.0000001 Ether to 0x08d2b0a37F869FF76BACB5Bab3278E26ab7067B7:
https://sepolia.etherscan.io/tx/0x2f2d996d6b262ebf0263b432ca3e6d621ba42d60b92344f31cf3ed94d09f49c4
User Ops can be found here:
https://jiffyscan.xyz/bundle/0x2f2d996d6b262ebf0263b432ca3e6d621ba42d60b92344f31cf3ed94d09f49c4?network=sepolia&pageNo=0&pageSize=10
https://v2.jiffyscan.xyz/tx/0x2f2d996d6b262ebf0263b432ca3e6d621ba42d60b92344f31cf3ed94d09f49c4?network=sepolia&pageNo=0&pageSize=10
```

#### Viem + Nexus

```bash
$ pnpm start-viem-nexus
```

This script will do the following:

1. instantiate a Turnkey Viem wallet client
2. instantiate a Viem public client (to be used to fetch onchain data)
3. connect the wallet client to Biconomy Nexus
4. send ETH (via type 2 EIP-1559 transaction)

Note: this script must be used specifically with Base's Sepolia testnet.

See the following for a sample output:

Network:
base-sepolia (chain ID 84532)

Signer address:
0xDC608F098255C89B36da905D9132A9Ee3DD266D9

Smart wallet address:
0xC00f5dCe7E266553cb3FBCd0BeDD11e290D551Fd

Balance:
0.009998258337028736 Ether

Transaction count:
1

Nonce:
106650284489225899116705470776299986053547585411730459514530106938958242906112

✔ Amount to send (wei). Default to 0.0000001 ETH … 100000000000
✔ Destination address (default to TKHQ warchest) … 0x08d2b0a37F869FF76BACB5Bab3278E26ab7067B7
Sent 0.0000001 Ether to 0x08d2b0a37F869FF76BACB5Bab3278E26ab7067B7:
https://sepolia.basescan.org/tx/0x453781ffcf1b4f5f98952347bcef14a0e7d6cbf7f9992b2a31163f67278625c6

User Ops can be found here:
https://v2.jiffyscan.xyz/tx/0x453781ffcf1b4f5f98952347bcef14a0e7d6cbf7f9992b2a31163f67278625c6?network=base-sepolia&pageNo=0&pageSize=10

#### Ethers

```bash
$ pnpm start-ethers
```

This script will do the following:

1. instantiate a Turnkey Ethers wallet client
2. instantiate a Ethers provider (to be used to fetch onchain data)
3. connect the wallet client to the Biconomy paymaster
4. send ETH (via type 2 EIP-1559 transaction)

See the following for a sample output:

```
Network:
sepolia (chain ID 11155111)
Expand All @@ -127,5 +183,5 @@ Sent 0.0000001 Ether to 0x08d2b0a37F869FF76BACB5Bab3278E26ab7067B7:
https://sepolia.etherscan.io/tx/0x0f0d5346ba726f7ccf80142ae295f28bf3873b0aeb7b29488b1e3dfb949d5ba6
User Ops can be found here:
https://jiffyscan.xyz/bundle/0x0f0d5346ba726f7ccf80142ae295f28bf3873b0aeb7b29488b1e3dfb949d5ba6?network=sepolia&pageNo=0&pageSize=10
https://v2.jiffyscan.xyz/tx/0x0f0d5346ba726f7ccf80142ae295f28bf3873b0aeb7b29488b1e3dfb949d5ba6?network=sepolia&pageNo=0&pageSize=10
```
5 changes: 4 additions & 1 deletion examples/with-biconomy-aa/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{
"name": "@turnkey/example-with-biconomy-aa",
"version": "0.1.0",
"version": "0.2.0",
"private": true,
"scripts": {
"start-ethers": "tsx src/ethers.ts",
"start-viem": "tsx src/viem.ts",
"start-nexus-viem": "tsx src/nexus-viem.ts",
"clean": "rimraf ./dist ./.cache",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@biconomy/account": "^4.5.6",
"@biconomy/sdk": "^0.0.10",
"@rhinestone/module-sdk": "^0.1.28",
"@turnkey/ethers": "workspace:*",
"@turnkey/sdk-server": "workspace:*",
"@turnkey/viem": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion examples/with-biconomy-aa/src/ethers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ async function main() {

print(
`User Ops can be found here:`,
`https://jiffyscan.xyz/bundle/${transactionHash}?network=${network}&pageNo=0&pageSize=10`
`https://v2.jiffyscan.xyz/tx/${transactionHash}?network=${network}&pageNo=0&pageSize=10`
);
}

Expand Down
166 changes: 166 additions & 0 deletions examples/with-biconomy-aa/src/nexus-viem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import * as path from "path";
import * as dotenv from "dotenv";
import prompts, { PromptType } from "prompts";
import {
createWalletClient,
createPublicClient,
http,
type Account,
formatEther,
} from "viem";
import { baseSepolia } from "viem/chains";
import { createNexusClient, createBicoPaymasterClient } from "@biconomy/sdk";

// Load environment variables from `.env.local`
dotenv.config({ path: path.resolve(process.cwd(), ".env.local") });

import { createAccount } from "@turnkey/viem";
import { Turnkey as TurnkeyServerSDK } from "@turnkey/sdk-server";
import { createNewWallet } from "./createNewWallet";
import { print } from "./util";

async function main() {
if (!process.env.SIGN_WITH) {
// If you don't specify a `SIGN_WITH`, we'll create a new wallet for you via calling the Turnkey API.
await createNewWallet();
return;
}

const turnkeyClient = new TurnkeyServerSDK({
apiBaseUrl: process.env.BASE_URL!,
apiPrivateKey: process.env.API_PRIVATE_KEY!,
apiPublicKey: process.env.API_PUBLIC_KEY!,
defaultOrganizationId: process.env.ORGANIZATION_ID!,
});

// Initialize a Turnkey-powered Viem Account
const turnkeyAccount = await createAccount({
client: turnkeyClient.apiClient(),
organizationId: process.env.ORGANIZATION_ID!,
signWith: process.env.SIGN_WITH!,
});

// Network must be base-sepolia at the moment
const network = "base-sepolia";
const bundlerUrl =
"https://bundler.biconomy.io/api/v3/84532/nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44";
const paymasterUrl =
"https://paymaster.biconomy.io/api/v2/84532/F7wyL1clz.75a64804-3e97-41fa-ba1e-33e98c2cc703";
const providerUrl = `https://${network}.infura.io/v3/${process.env
.INFURA_KEY!}`;

// Bring your own provider
const client = createWalletClient({
account: turnkeyAccount as Account,
chain: baseSepolia,
transport: http(providerUrl),
});

const publicClient = createPublicClient({
chain: baseSepolia,
transport: http(providerUrl),
});

const nexusClient = await createNexusClient({
signer: turnkeyAccount,
chain: baseSepolia,
transport: http(),
bundlerTransport: http(bundlerUrl),
paymaster: createBicoPaymasterClient({
paymasterUrl,
}),
});

const smartAccount = nexusClient.account;
const smartAccountAddress = nexusClient.account.address;

const chainId = client.chain.id;
const signerAddress = client.account.address; // signer

const transactionCount = await publicClient.getTransactionCount({
address: smartAccountAddress,
});
const nonce = await smartAccount.getNonce();
let balance =
(await publicClient.getBalance({ address: smartAccountAddress })) ?? 0;

print("Network:", `${network} (chain ID ${chainId})`);
print("Signer address:", signerAddress);
print("Smart wallet address:", smartAccountAddress);
print("Balance:", `${formatEther(balance)} Ether`);
print("Transaction count:", `${transactionCount}`);
print("Nonce:", `${nonce}`);

while (balance === 0n) {
console.log(
[
`\n💸 Your onchain balance is at 0! To continue this demo you'll need testnet funds! You can use:`,
`- Any online faucet (e.g. https://www.alchemy.com/faucets/)`,
`\nTo check your balance: https://${network}.etherscan.io/address/${smartAccountAddress}`,
`\n--------`,
].join("\n")
);

const { continue: _ } = await prompts([
{
type: "text" as PromptType,
name: "continue",
message: "Ready to continue? y/n",
initial: "y",
},
]);

balance = await publicClient.getBalance({
address: smartAccountAddress,
})!;
}

const { amount, destination } = await prompts([
{
type: "number" as PromptType,
name: "amount",
message: "Amount to send (wei). Default to 0.0000001 ETH",
initial: 100000000000,
},
{
type: "text" as PromptType,
name: "destination",
message: "Destination address (default to TKHQ warchest)",
initial: "0x08d2b0a37F869FF76BACB5Bab3278E26ab7067B7",
},
]);
const transactionRequest = {
to: destination,
value: amount,
type: 2,
};

const hash = await nexusClient.sendTransaction({
calls: [
{
to: destination,
value: amount,
},
],
});
const { transactionHash } = await nexusClient.waitForTransactionReceipt({
hash,
});

print(
`Sent ${formatEther(transactionRequest.value)} Ether to ${
transactionRequest.to
}:`,
`https://sepolia.basescan.org/tx/${transactionHash}`
);

print(
`User Ops can be found here:`,
`https://v2.jiffyscan.xyz/tx/${transactionHash}?network=${network}&pageNo=0&pageSize=10`
);
}

main().catch((error) => {
console.error(error);
process.exit(1);
});
2 changes: 1 addition & 1 deletion examples/with-biconomy-aa/src/viem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ async function main() {

print(
`User Ops can be found here:`,
`https://jiffyscan.xyz/bundle/${transactionHash}?network=${network}&pageNo=0&pageSize=10`
`https://v2.jiffyscan.xyz/tx/${transactionHash}?network=${network}&pageNo=0&pageSize=10`
);
}

Expand Down
2 changes: 1 addition & 1 deletion examples/with-eth-passkeys-galore/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@turnkey/with-eth-passkey-signers",
"version": "0.2.2",
"version": "0.2.4",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { Turnkey, TurnkeyApiTypes } from "@turnkey/sdk-server";
import { refineNonNull } from "@/utils";
import { TWalletDetails } from "@/types";

Expand All @@ -9,7 +8,11 @@ import { TWalletDetails } from "@/types";
// - Purpose is a constant set to 44' following the BIP43 recommendation.
// - Coin type is set to 60 (ETH) -- see https://github.com/satoshilabs/slips/blob/master/slip-0044.md
// - Account, Change, and Address Index are set to 0
import { DEFAULT_ETHEREUM_ACCOUNTS } from "@turnkey/sdk-server";
import {
Turnkey,
TurnkeyApiTypes,
DEFAULT_ETHEREUM_ACCOUNTS,
} from "@turnkey/sdk-server";

type TAttestation = TurnkeyApiTypes["v1Attestation"];

Expand Down
2 changes: 1 addition & 1 deletion examples/with-eth-passkeys-galore/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export default function Home() {
const { transactionHash } = await userOpResponse.waitForTxHash();

setSignedTransaction(
`https://jiffyscan.xyz/bundle/${transactionHash}?network=sepolia&pageNo=0&pageSize=10`
`https://v2.jiffyscan.xyz/tx/${transactionHash}?network=sepolia&pageNo=0&pageSize=10`
);
};

Expand Down
2 changes: 1 addition & 1 deletion examples/with-solana-passkeys/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@turnkey/with-solana-passkeys",
"version": "0.1.3",
"version": "0.1.6",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
2 changes: 1 addition & 1 deletion examples/with-wallet-stamper/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "with-wallet-stamper",
"version": "0.1.3",
"version": "0.1.6",
"private": true,
"type": "module",
"scripts": {
Expand Down
Binary file added img/sdk-map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/sdk-web-diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions packages/cosmjs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# @turnkey/cosmjs

## 0.6.5

### Patch Changes

- @turnkey/sdk-browser@1.10.2

## 0.6.4

### Patch Changes

- Updated dependencies [78bc39c]
- @turnkey/sdk-server@1.7.0
- @turnkey/http@2.17.0
- @turnkey/sdk-browser@1.10.1

## 0.6.3

### Patch Changes
Expand Down
Loading

0 comments on commit 45ec70a

Please sign in to comment.