diff --git a/.changeset/wacky-windows-buy.md b/.changeset/wacky-windows-buy.md new file mode 100644 index 0000000..5b2a7f6 --- /dev/null +++ b/.changeset/wacky-windows-buy.md @@ -0,0 +1,5 @@ +--- +"chainwright": patch +--- + +Add example folders for wallet setup diff --git a/examples/custom-extension-source/custom-download-url.ts b/examples/custom-extension-source/custom-download-url.ts new file mode 100644 index 0000000..2851332 --- /dev/null +++ b/examples/custom-extension-source/custom-download-url.ts @@ -0,0 +1,18 @@ +import { defineWalletSetup } from "chainwright/core"; + +const PASSWORD = "test1234"; +const EXTENSION_DOWNLOAD_URL = "https://example.com/metamask-extension.zip"; +const EXTENSION_SHA256 = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"; + +export default defineWalletSetup( + PASSWORD, + async () => { + //.. Onboarding logi. here + }, + { + extensionSource: { + downloadUrl: EXTENSION_DOWNLOAD_URL, + sha256: EXTENSION_SHA256, + }, + }, +); diff --git a/examples/custom-extension-source/local-path.ts b/examples/custom-extension-source/local-path.ts new file mode 100644 index 0000000..193101e --- /dev/null +++ b/examples/custom-extension-source/local-path.ts @@ -0,0 +1,17 @@ +import { defineWalletSetup } from "chainwright/core"; + +const PASSWORD = "test1234"; +//const LOCAL_EXTENSION_ZIP = path.resolve(process.cwd(), "your path") +const LOCAL_EXTENSION_ZIP = "/absolute/path/to/metamask-extension.zip"; + +export default defineWalletSetup( + PASSWORD, + async () => { + //... Onboarding logic here + }, + { + extensionSource: { + localPath: LOCAL_EXTENSION_ZIP, + }, + }, +); diff --git a/examples/custom-profile/fixture.ts b/examples/custom-profile/fixture.ts new file mode 100644 index 0000000..7ed6c8c --- /dev/null +++ b/examples/custom-profile/fixture.ts @@ -0,0 +1,13 @@ +import { testWithChainwright } from "chainwright/core"; +import { metamaskFixture } from "chainwright/metamask"; + +export const testWithTeamProfile = testWithChainwright( + metamaskFixture({ + profileName: "team-profile", + }), +); + +// Your Fixture here! +export const customFixture = testWithTeamProfile.extend({ + // fixture properties +}); diff --git a/examples/custom-profile/metamask.ts b/examples/custom-profile/metamask.ts new file mode 100644 index 0000000..4d01843 --- /dev/null +++ b/examples/custom-profile/metamask.ts @@ -0,0 +1,19 @@ +import { defineWalletSetup } from "chainwright/core"; +import { Metamask } from "chainwright/metamask"; + +const PASSWORD = "test1234"; +const SECRET_RECOVERY_PHRASE = "Your secret phrase"; + +export default defineWalletSetup( + PASSWORD, + async ({ walletPage }) => { + const metamask = new Metamask(walletPage); + + await metamask.onboard({ + mode: "import", + secretRecoveryPhrase: SECRET_RECOVERY_PHRASE, + mainAccountName: "Team profile", + }); + }, + { profileName: "team-profile" }, +); diff --git a/examples/custom-profile/meteor.ts b/examples/custom-profile/meteor.ts new file mode 100644 index 0000000..c1cf025 --- /dev/null +++ b/examples/custom-profile/meteor.ts @@ -0,0 +1,36 @@ +import { defineWalletSetup } from "chainwright/core"; +import { Meteor } from "chainwright/meteor"; + +const PASSWORD = "test1234"; +const DEFAULT_PRIVATE_KEY = "Your private key"; +const TESTNET_PRIVATE_KEY = "Your private key"; +const MAINNET_PRIVATE_KEY = "Your private key"; + +export default defineWalletSetup( + PASSWORD, + async ({ walletPage }) => { + const meteor = new Meteor(walletPage); + + await meteor.onboard({ + mode: "privateKey", + privateKey: DEFAULT_PRIVATE_KEY, + accountName: "Default", + network: "Testnet", + additionalAccounts: [ + { + mode: "privateKey", + privateKey: TESTNET_PRIVATE_KEY, + accountName: "Testnet account", + network: "Testnet", + }, + { + mode: "privateKey", + privateKey: MAINNET_PRIVATE_KEY, + accountName: "Mainnet account", + network: "Mainnet", + }, + ], + }); + }, + { profileName: "multiple-network" }, +); diff --git a/examples/multiple-accounts/keplr.ts b/examples/multiple-accounts/keplr.ts new file mode 100644 index 0000000..0d65c7f --- /dev/null +++ b/examples/multiple-accounts/keplr.ts @@ -0,0 +1,25 @@ +import { defineWalletSetup } from "chainwright/core"; +import { Keplr } from "chainwright/keplr"; + +const PASSWORD = "test1234"; +const FIRST_PRIVATE_KEY = "Your private key"; +const SECOND_PRIVATE_KEY = "Your private key"; + +export default defineWalletSetup(PASSWORD, async ({ walletPage }) => { + const keplr = new Keplr(walletPage); + + await keplr.onboard([ + { + mode: "privateKey", + privateKey: FIRST_PRIVATE_KEY, + walletName: "Default", + chains: ["Injective", "Injective (Testnet)"], + }, + { + mode: "privateKey", + privateKey: SECOND_PRIVATE_KEY, + walletName: "Trading", + chains: ["Injective", "Injective (Testnet)"], + }, + ]); +}); diff --git a/examples/multiple-accounts/meteor.ts b/examples/multiple-accounts/meteor.ts new file mode 100644 index 0000000..9bb2f98 --- /dev/null +++ b/examples/multiple-accounts/meteor.ts @@ -0,0 +1,32 @@ +import { defineWalletSetup } from "chainwright/core"; +import { Meteor } from "chainwright/meteor"; + +const PASSWORD = "test1234"; +const DEFAULT_PRIVATE_KEY = "Your private key"; +const TESTNET_PRIVATE_KEY = "Your private key"; +const MAINNET_PRIVATE_KEY = "Your private key"; + +export default defineWalletSetup(PASSWORD, async ({ walletPage }) => { + const meteor = new Meteor(walletPage); + + await meteor.onboard({ + mode: "privateKey", + privateKey: DEFAULT_PRIVATE_KEY, + accountName: "Default", + network: "Testnet", + additionalAccounts: [ + { + mode: "privateKey", + privateKey: TESTNET_PRIVATE_KEY, + accountName: "Testnet account", + network: "Testnet", + }, + { + mode: "privateKey", + privateKey: MAINNET_PRIVATE_KEY, + accountName: "Mainnet account", + network: "Mainnet", + }, + ], + }); +}); diff --git a/examples/multiple-accounts/petra.ts b/examples/multiple-accounts/petra.ts new file mode 100644 index 0000000..c45e090 --- /dev/null +++ b/examples/multiple-accounts/petra.ts @@ -0,0 +1,24 @@ +import { defineWalletSetup } from "chainwright/core"; +import { Petra } from "chainwright/petra"; + +const PASSWORD = "PlayerPetra45!!"; +const SECRET_RECOVERY_PHRASE = "Your secret phrase"; +const SECOND_PRIVATE_KEY = "Your private key"; + +export default defineWalletSetup(PASSWORD, async ({ walletPage }) => { + const petra = new Petra(walletPage); + + await petra.onboard({ + mode: "importMnemonic", + secretRecoveryPhrase: SECRET_RECOVERY_PHRASE, + accountName: "Default", + network: "Testnet", + additionalAccounts: [ + { + mode: "privateKey", + privateKey: SECOND_PRIVATE_KEY, + accountName: "Imported account", + }, + ], + }); +}); diff --git a/examples/multiple-accounts/phantom.ts b/examples/multiple-accounts/phantom.ts new file mode 100644 index 0000000..6f5c737 --- /dev/null +++ b/examples/multiple-accounts/phantom.ts @@ -0,0 +1,28 @@ +import { defineWalletSetup } from "chainwright/core"; +import { Phantom } from "chainwright/phantom"; + +const PASSWORD = "test1234"; +const SECRET_RECOVERY_PHRASE = "Your secret phrase"; +const ETHEREUM_PRIVATE_KEY = "Your private key"; + +export default defineWalletSetup(PASSWORD, async ({ walletPage }) => { + const phantom = new Phantom(walletPage); + + await phantom.onboard({ + mode: "recovery phrase", + secretRecoveryPhrase: SECRET_RECOVERY_PHRASE, + accountName: "Default", + toggleNetworkMode: { + mode: "on", + chain: "Solana", + network: "Solana Devnet", + }, + additionalAccounts: [ + { + accountName: "Ethereum account", + chain: "Ethereum", + privateKey: ETHEREUM_PRIVATE_KEY, + }, + ], + }); +}); diff --git a/examples/multiple-accounts/solflare.ts b/examples/multiple-accounts/solflare.ts new file mode 100644 index 0000000..ca9b170 --- /dev/null +++ b/examples/multiple-accounts/solflare.ts @@ -0,0 +1,22 @@ +import { defineWalletSetup } from "chainwright/core"; +import { Solflare } from "chainwright/solflare"; + +const PASSWORD = "test1234"; +const RECOVERY_PHRASE = "Your secret phrase"; +const SECOND_PRIVATE_KEY = "Your private key"; + +export default defineWalletSetup(PASSWORD, async ({ walletPage }) => { + const solflare = new Solflare(walletPage); + + await solflare.onboard({ + recoveryPhrase: RECOVERY_PHRASE, + walletName: "Default", + network: "Devnet", + additionalAccounts: [ + { + walletName: "Imported account", + privateKey: SECOND_PRIVATE_KEY, + }, + ], + }); +}); diff --git a/examples/single-account/keplr.ts b/examples/single-account/keplr.ts new file mode 100644 index 0000000..01869ae --- /dev/null +++ b/examples/single-account/keplr.ts @@ -0,0 +1,18 @@ +import { defineWalletSetup } from "chainwright/core"; +import { Keplr } from "chainwright/keplr"; + +const PASSWORD = "test1234"; +const PRIVATE_KEY = "Your private key"; + +export default defineWalletSetup(PASSWORD, async ({ walletPage }) => { + const keplr = new Keplr(walletPage); + + await keplr.onboard([ + { + mode: "privateKey", + privateKey: PRIVATE_KEY, + walletName: "Default", + chains: ["Injective", "Injective (Testnet)"], + }, + ]); +}); diff --git a/examples/single-account/metamask.ts b/examples/single-account/metamask.ts new file mode 100644 index 0000000..d668f7d --- /dev/null +++ b/examples/single-account/metamask.ts @@ -0,0 +1,28 @@ +import { defineWalletSetup } from "chainwright/core"; +import { Metamask } from "chainwright/metamask"; + +/** + * Setting up MetaMask. + * + * MetaMask uses an Hierarchical Deterministic (HD) wallet model: the seed phrase + * is the root secret, and accounts are deterministically derived from it using + * derivative paths like m/44'/60'/0'/0/n. + * + * So, when you import an account using the seed phrase, MetaMask can recreate the + * same sequence of addresses by deriving the already existing accounts in the wallet. + * This is why we don't need an "additionalAccounts" argument in the onboarding action + * for the MetaMask wallet. + */ + +const PASSWORD = "test1234"; + +export default defineWalletSetup(PASSWORD, async ({ walletPage }) => { + const metamask = new Metamask(walletPage); + const seedPhrase = "Your secret phrase"; + + await metamask.onboard({ + mode: "import", + secretRecoveryPhrase: seedPhrase, + mainAccountName: "Test", + }); +}); diff --git a/examples/single-account/meteor.ts b/examples/single-account/meteor.ts new file mode 100644 index 0000000..2d10262 --- /dev/null +++ b/examples/single-account/meteor.ts @@ -0,0 +1,16 @@ +import { defineWalletSetup } from "chainwright/core"; +import { Meteor } from "chainwright/meteor"; + +const PASSWORD = "test1234"; +const PRIVATE_KEY = "Your private key"; + +export default defineWalletSetup(PASSWORD, async ({ walletPage }) => { + const meteor = new Meteor(walletPage); + + await meteor.onboard({ + mode: "privateKey", + privateKey: PRIVATE_KEY, + accountName: "Default", + network: "Testnet", + }); +}); diff --git a/examples/single-account/petra.ts b/examples/single-account/petra.ts new file mode 100644 index 0000000..e44c558 --- /dev/null +++ b/examples/single-account/petra.ts @@ -0,0 +1,16 @@ +import { defineWalletSetup } from "chainwright/core"; +import { Petra } from "chainwright/petra"; + +const PASSWORD = "TestPetra45!!"; +const SECRET_RECOVERY_PHRASE = "Your secret phrase"; + +export default defineWalletSetup(PASSWORD, async ({ walletPage }) => { + const petra = new Petra(walletPage); + + await petra.onboard({ + mode: "importMnemonic", + secretRecoveryPhrase: SECRET_RECOVERY_PHRASE, + accountName: "Default", + network: "Testnet", + }); +}); diff --git a/examples/single-account/phantom.ts b/examples/single-account/phantom.ts new file mode 100644 index 0000000..8c8cda8 --- /dev/null +++ b/examples/single-account/phantom.ts @@ -0,0 +1,20 @@ +import { defineWalletSetup } from "chainwright/core"; +import { Phantom } from "chainwright/phantom"; + +const PASSWORD = "test1234"; +const SECRET_RECOVERY_PHRASE = "Your secret phrase"; + +export default defineWalletSetup(PASSWORD, async ({ walletPage }) => { + const phantom = new Phantom(walletPage); + + await phantom.onboard({ + mode: "recovery phrase", + secretRecoveryPhrase: SECRET_RECOVERY_PHRASE, + accountName: "Default", + toggleNetworkMode: { + mode: "on", + chain: "Solana", + network: "Solana Devnet", + }, + }); +}); diff --git a/examples/single-account/solflare.ts b/examples/single-account/solflare.ts new file mode 100644 index 0000000..766cb9a --- /dev/null +++ b/examples/single-account/solflare.ts @@ -0,0 +1,15 @@ +import { defineWalletSetup } from "chainwright/core"; +import { Solflare } from "chainwright/solflare"; + +const PASSWORD = "test1234"; +const RECOVERY_PHRASE = "Your secret phrase"; + +export default defineWalletSetup(PASSWORD, async ({ walletPage }) => { + const solflare = new Solflare(walletPage); + + await solflare.onboard({ + recoveryPhrase: RECOVERY_PHRASE, + walletName: "Default", + network: "Devnet", + }); +});