@newwallet/wallet-passkey
v0.8.4-alpha.6
Published
NewWallet SDK for web applications with blockchain and passkey integration
Maintainers
Readme
NewWallet Passkey SDK
A secure multi-chain hierarchical deterministic (HD) wallet library with passkey authentication for Ethereum, Solana, BSC, Base, Polygon, Arbitrum and other blockchain ecosystems.
Features
- Multi-Network Support: Single wallet instance managing all blockchain networks
- Passkey Authentication: Secure wallet access using WebAuthn passkeys
- Account Sharing: EVM-compatible chains (Ethereum, BSC, Base, Polygon, Arbitrum) share the same accounts
- HD Wallet Generation: Create multiple accounts from a single secure seed phrase
- Transaction Signing: Sign transactions for any supported blockchain
- Message Signing: Sign messages for both EVM and Solana chains
- Account Management: Create, rename, and manage accounts across all networks
Installation
npm install @newwallet/wallet-passkeyyarn add @newwallet/wallet-passkeyQuick Start
import { WalletPass } from "@newwallet/wallet-passkey";
// Initialize wallet with multiple networks
async function createWallet() {
const encryptionKey = new Uint8Array(32);
crypto.getRandomValues(encryptionKey);
const credentialID = "device-001";
// Create wallet supporting multiple networks
const networks = [
"ETHEREUM_MAINNET",
"BSC_MAINNET",
"BASE_MAINNET",
"SOLANA_MAINNET",
];
const { wallet, deviceCrypto } = await WalletPass.createNewWallet(
"[email protected]",
networks,
encryptionKey,
credentialID,
);
// Add an account (creates for all networks)
const accounts = await wallet.addAccount(
"Main Account",
credentialID,
encryptionKey,
);
console.log("Created accounts:");
accounts.forEach((account, coinType) => {
console.log(` CoinType ${coinType}: ${account.address}`);
});
return wallet;
}Core Concepts
Network Architecture
The wallet supports multiple blockchain networks in a single instance. Networks are grouped by their coin type:
- CoinType 60 (EVM): Ethereum, BSC, Base, and other EVM-compatible chains share accounts
- CoinType 501 (Solana): Solana maintains separate accounts
Account Management
When you create an account, it's automatically available across all networks:
// Add account - creates for both EVM and Solana
const newAccounts = await wallet.addAccount(
"Trading Account",
credentialID,
encryptionKey,
);
// Get accounts for specific network
const ethAccounts = wallet.getAccountsForNetwork("ETHEREUM_MAINNET");
const solAccounts = wallet.getAccountsForNetwork("SOLANA_MAINNET");
// EVM networks share accounts
const bscAccounts = wallet.getAccountsForNetwork("BSC_MAINNET");
console.log(ethAccounts === bscAccounts); // true (same accounts)Working with Networks
Supported Networks
// Get all supported networks
const networks = wallet.getSupportedNetworks();
// ["ETHEREUM_MAINNET", "BSC_MAINNET", "BASE_MAINNET", "SOLANA_MAINNET"]
// Get network information
const ethInfo = wallet.getNetworkInfo("ETHEREUM_MAINNET");
console.log(ethInfo);
// {
// networkName: "Ethereum",
// chainId: 1,
// coinType: 60,
// symbol: "ETH",
// rpcUrl: "https://ethereum-rpc.publicnode.com",
// isTestnet: false
// }Adding Networks
// Add testnet to existing wallet
await wallet.addNetwork("ETHEREUM_SEPOLIA", credentialID, encryptionKey);
// Testnet shares accounts with mainnet (same coinType)
const mainnetAccounts = wallet.getAccountsForNetwork("ETHEREUM_MAINNET");
const testnetAccounts = wallet.getAccountsForNetwork("ETHEREUM_SEPOLIA");
// Same addresses!Transaction Signing
Ethereum/EVM Transaction
import { ethers } from "ethers";
const transaction = {
to: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
value: ethers.parseEther("0.1"),
gasLimit: 21000,
gasPrice: ethers.parseUnits("20", "gwei"),
nonce: 0,
chainId: 1,
};
const signedTx = await wallet.signTransaction(
"ETHEREUM_MAINNET",
transaction,
accountAddress,
credentialID,
encryptionKey,
);Solana Transaction
import { Transaction, SystemProgram, PublicKey } from "@solana/web3.js";
const transaction = new Transaction().add(
SystemProgram.transfer({
fromPubkey: new PublicKey(solanaAccount.address),
toPubkey: new PublicKey(recipientAddress),
lamports: 100000000, // 0.1 SOL
}),
);
transaction.recentBlockhash = "..."; // Get from network
transaction.feePayer = new PublicKey(solanaAccount.address);
const signedTx = await wallet.signTransaction(
"SOLANA_MAINNET",
transaction,
solanaAccount.address,
credentialID,
encryptionKey,
);Message Signing
const message = "Hello Blockchain!";
// Sign with Ethereum
const ethSignature = await wallet.callBlockchainMethod(
"ETHEREUM_MAINNET",
"signMessage",
[message],
ethAccount.address,
credentialID,
encryptionKey,
);
// Sign with Solana
const solSignature = await wallet.callBlockchainMethod(
"SOLANA_MAINNET",
"signMessage",
[message],
solAccount.address,
credentialID,
encryptionKey,
);Export & Import
Export Wallet
// Export to JSON (without sensitive data)
const jsonData = wallet.exportToJSON();
fs.writeFileSync("wallet_backup.json", jsonData);
// Export mnemonic (requires authentication)
const mnemonic = await wallet.exportMnemonic(credentialID, encryptionKey);Import Wallet
// Import from JSON
const jsonData = fs.readFileSync("wallet_backup.json", "utf-8");
const importedWallet = WalletPass.importFromJSON(jsonData);
// Add device after import
const deviceCrypto = {
credentialID: "new-device",
encryptedData: "...", // Encrypted mnemonic
};
importedWallet.updateDevices([deviceCrypto]);Advanced Features
Multiple Devices
// Add new device to existing wallet
const newDevice = await wallet.addNewDevice(
existingCredentialID,
existingEncryptionKey,
newCredentialID,
newEncryptionKey,
);Private Key Export
// Export private key for specific account
const privateKey = await wallet.exportPrivateKey(
"ETHEREUM_MAINNET",
accountAddress,
credentialID,
encryptionKey,
);Account Operations
// Rename account
wallet.renameAccount("ETHEREUM_MAINNET", accountAddress, "New Name");
// Remove account (removes from all networks)
wallet.removeAccount(accountIndex);
// Get all accounts grouped by coinType
const allAccounts = wallet.getAllAccounts();Complete Example
import { WalletPass } from "@newwallet/wallet-passkey";
async function walletExample() {
// Setup
const encryptionKey = new Uint8Array(32);
crypto.getRandomValues(encryptionKey);
const credentialID = "device-001";
// 1. Create multi-network wallet
const { wallet } = await WalletPass.createNewWallet(
"[email protected]",
["ETHEREUM_MAINNET", "BSC_MAINNET", "SOLANA_MAINNET"],
encryptionKey,
credentialID,
);
// 2. Add accounts
await wallet.addAccount("Main", credentialID, encryptionKey);
await wallet.addAccount("Trading", credentialID, encryptionKey);
// 3. Get accounts
const ethAccounts = wallet.getAccountsForNetwork("ETHEREUM_MAINNET");
const solAccounts = wallet.getAccountsForNetwork("SOLANA_MAINNET");
console.log(`Ethereum accounts: ${ethAccounts.length}`);
console.log(`Solana accounts: ${solAccounts.length}`);
// 4. Sign transaction
const tx = { to: "0x...", value: "1000000000000000000" };
const signed = await wallet.signTransaction(
"ETHEREUM_MAINNET",
tx,
ethAccounts[0].address,
credentialID,
encryptionKey,
);
// 5. Save wallet
wallet.saveToFile("my_wallet.json");
return wallet;
}Network Support
| Network | CoinType | Mainnet | Testnet | | ------------------- | -------- | ------------------- | ------------------- | | Ethereum | 60 | ✅ ETHEREUM_MAINNET | ✅ ETHEREUM_SEPOLIA | | Binance Smart Chain | 60 | ✅ BSC_MAINNET | ✅ BSC_TESTNET | | Base | 60 | ✅ BASE_MAINNET | ✅ BASE_SEPOLIA | | Solana | 501 | ✅ SOLANA_MAINNET | ✅ SOLANA_TESTNET | | Polygon | 60 | ✅ POLYGON_MAINNET | ✅ POLYGON_AMOY | | Arbitrum | 60 | ✅ ARBITRUM_ONE | ✅ ARBITRUM_SEPOLIA |
Security
- Encryption: All sensitive data is encrypted using AES-GCM
- Passkey: WebAuthn integration for secure authentication
- HD Wallet: BIP39/BIP44 standard for key derivation
- No Plain Text: Private keys and mnemonics are never stored in plain text
License
ISC
