w3pk 0.8.8 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -28,6 +28,12 @@ await w3pk.login()
28
28
  // Sign messages (EIP-191, SIWE, EIP-712, rawHash)
29
29
  const signature = await w3pk.signMessage('Hello World')
30
30
 
31
+ // Send transactions on-chain
32
+ const tx = await w3pk.sendTransaction({ to: '0x...', value: 1n * 10n**18n, chainId: 1 })
33
+
34
+ // EIP-1193 provider (ethers, viem, wagmi, RainbowKit)
35
+ const eip1193 = w3pk.getEIP1193Provider({ chainId: 1 })
36
+
31
37
  // Derive wallets (STANDARD/STRICT/YOLO modes)
32
38
  const wallet = await w3pk.deriveWallet('STANDARD', 'GAMING')
33
39
 
@@ -43,13 +49,17 @@ const endpoints = await w3pk.getEndpoints(1)
43
49
  - HD wallet generation (BIP39/BIP44)
44
50
  - Multi-address derivation with security modes (STANDARD/STRICT/YOLO)
45
51
  - Multiple signing methods (EIP-191, SIWE/EIP-4361, EIP-712, rawHash)
52
+ - On-chain transaction sending with automatic RPC resolution (`sendTransaction`)
53
+ - EIP-1193 provider for ethers, viem, wagmi, RainbowKit (`getEIP1193Provider`)
46
54
  - ERC-5564 stealth addresses (opt-in)
47
55
  - ZK primitives (zero-knowledge proof generation and verification)
48
56
  - Chainlist support (2390+ networks)
49
57
  - EIP-7702 network detection (329+ networks)
58
+ - External wallet integration (delegate MetaMask/Ledger to w3pk via EIP-7702)
50
59
  - EIP-7951 PRIMARY mode (P-256 passkey signing)
51
- - Build verification (IPFS CIDv1 hashing)
60
+ - Build verification (IPFS CID hashing + DAO-maintained onchain registry)
52
61
  - Three-layer backup & recovery (passkey sync, encrypted backups, social recovery)
62
+ - AI-powered host app inspection
53
63
 
54
64
  ## API
55
65
 
@@ -124,6 +134,82 @@ const sensitiveSig = await w3pk.signMessage('Transfer $1000', {
124
134
  })
125
135
  ```
126
136
 
137
+ ### Sending Transactions
138
+
139
+ ```typescript
140
+ // Check which address will be used before sending
141
+ const from = await w3pk.getAddress('STANDARD', 'MAIN')
142
+ console.log('sending from:', from)
143
+
144
+ // Send ETH — defaults to STANDARD mode, MAIN tag, current origin
145
+ // sender = getOriginSpecificAddress(mnemonic, window.location.origin, 'STANDARD', 'MAIN')
146
+ const result = await w3pk.sendTransaction({
147
+ to: '0xRecipient...',
148
+ value: 1n * 10n**18n, // 1 ETH in wei
149
+ chainId: 1
150
+ })
151
+ console.log('tx hash:', result.hash)
152
+ console.log('from:', result.from) // same address as `from` above
153
+ console.log('mode:', result.mode) // 'STANDARD'
154
+
155
+ // Send contract call with custom RPC and STRICT auth
156
+ const callResult = await w3pk.sendTransaction(
157
+ { to: '0xContract...', data: '0xabcd...', chainId: 10 },
158
+ { mode: 'STRICT', rpcUrl: 'https://mainnet.optimism.io' }
159
+ )
160
+
161
+ // YOLO mode — app-specific isolated address
162
+ const yoloTx = await w3pk.sendTransaction(
163
+ { to: '0x...', value: 5n * 10n**17n, chainId: 8453 },
164
+ { mode: 'YOLO', tag: 'GAMING' }
165
+ )
166
+ ```
167
+
168
+ **Mode behaviour:**
169
+
170
+ | Mode | Auth on send | Gas source |
171
+ |------|-------------|------------|
172
+ | STANDARD | Session (auto) | Sender address |
173
+ | STRICT | Always (biometric) | Sender address |
174
+ | YOLO | Session (auto) | Sender address |
175
+ | PRIMARY | — (not supported, throws) | Requires bundler |
176
+
177
+ ### EIP-1193 Provider
178
+
179
+ Use w3pk with any EIP-1193 consumer — ethers, viem, wagmi, RainbowKit — without exposing private keys.
180
+
181
+ ```typescript
182
+ const eip1193 = w3pk.getEIP1193Provider({ chainId: 1 })
183
+ ```
184
+
185
+ **ethers v6**
186
+ ```typescript
187
+ import { BrowserProvider } from 'ethers'
188
+ const provider = new BrowserProvider(eip1193)
189
+ const signer = await provider.getSigner()
190
+ const tx = await signer.sendTransaction({ to: '0x...', value: parseEther('1') })
191
+ ```
192
+
193
+ **viem**
194
+ ```typescript
195
+ import { createWalletClient, custom } from 'viem'
196
+ import { mainnet } from 'viem/chains'
197
+ const client = createWalletClient({ chain: mainnet, transport: custom(eip1193) })
198
+ const [address] = await client.getAddresses()
199
+ const hash = await client.sendTransaction({ to: '0x...', value: parseEther('1') })
200
+ ```
201
+
202
+ **Supported JSON-RPC methods:**
203
+
204
+ | Method | Action |
205
+ |--------|--------|
206
+ | `eth_accounts` / `eth_requestAccounts` | Returns derived address |
207
+ | `eth_chainId` | Returns active chain as hex |
208
+ | `eth_sendTransaction` | Delegates to `sendTransaction()` |
209
+ | `personal_sign` / `eth_sign` | EIP-191 message signing |
210
+ | `eth_signTypedData_v4` | EIP-712 typed data signing |
211
+ | `wallet_switchEthereumChain` | Updates active chainId, emits `chainChanged` |
212
+
127
213
  ### Session Management
128
214
 
129
215
  ```typescript
@@ -193,6 +279,13 @@ const authorization = await w3pk.signAuthorization({
193
279
  nonce: 0n
194
280
  })
195
281
  // Returns: { chainId, address, nonce, yParity, r, s }
282
+
283
+ // Delegate external wallet (MetaMask, Ledger, etc.) to w3pk account
284
+ const auth = await w3pk.requestExternalWalletDelegation({
285
+ chainId: 1,
286
+ nonce: 0n
287
+ })
288
+ // User's external wallet account now controlled by w3pk WebAuthn
196
289
  ```
197
290
 
198
291
  ### EIP-7951 PRIMARY Mode
@@ -269,49 +362,98 @@ const invite = await w3pk.generateGuardianInvite(guardianShare)
269
362
  const { mnemonic } = await w3pk.recoverFromGuardians([share1, share2])
270
363
 
271
364
  // Restore from backup file
272
- await w3pk.restoreFromBackup(encryptedData, password)
365
+ await w3pk.restoreFromBackupFile(encryptedData, password)
273
366
 
274
367
  // Simulate recovery scenarios
275
368
  const result = await w3pk.simulateRecoveryScenario({
276
369
  type: 'lost-device',
277
- hasBackup: true,
278
- hasSocialRecovery: true
370
+ description: 'Device lost with iCloud Keychain enabled'
279
371
  })
280
372
  ```
281
373
 
282
374
  ### Build Verification
283
375
 
284
376
  ```typescript
285
- import { getCurrentBuildHash, verifyBuildHash } from 'w3pk'
377
+ import { getCurrentBuildHash } from 'w3pk'
378
+ import { ethers } from 'ethers'
379
+ import packageJson from './package.json'
380
+
381
+ // Get installed w3pk version from package.json
382
+ const installedVersion = packageJson.dependencies['w3pk'].replace(/^[~^]/, '') // Remove ^ or ~
286
383
 
287
384
  // Get IPFS hash of installed build
288
385
  const hash = await getCurrentBuildHash()
386
+ console.log('Installed version:', installedVersion)
387
+ console.log('Local build hash:', hash)
388
+
389
+ // Verify against DAO-maintained onchain registry (OP Mainnet)
390
+ const REGISTRY = '0xAF48C2DB335eD5da14A2C36a59Bc34407C63e01a'
391
+ const ABI = ['function getCidByVersion(string version) view returns (string)']
392
+ const provider = new ethers.JsonRpcProvider('https://mainnet.optimism.io')
393
+ const registry = new ethers.Contract(REGISTRY, ABI, provider)
394
+
395
+ // Query registry for the specific installed version (note: "v" prefix required)
396
+ const onchainCid = await registry.getCidByVersion(`v${installedVersion}`)
397
+ const isValid = hash === onchainCid
289
398
 
290
- // Verify against trusted hash
291
- const TRUSTED_HASH = 'bafybeig2xoiu2hfcjexz6cwtjcjf4u4vwxzcm66zhnqivhh6jvi7nx2qa4'
292
- const isValid = await verifyBuildHash(TRUSTED_HASH)
399
+ console.log('Onchain CID:', onchainCid)
400
+ console.log('Verified:', isValid ? '' : '❌')
293
401
  ```
294
402
 
295
- ## Security & Verification
403
+ ### Security Inspection
296
404
 
297
- ### Current Build Hash (v0.8.8)
405
+ Analyze web3 applications to understand their transaction and signing methods:
298
406
 
407
+ **Browser (analyze current page):**
408
+ ```typescript
409
+ import { inspect, inspectNow } from 'w3pk'
410
+
411
+ // Full inspection with custom options
412
+ const result = await inspect({
413
+ appUrl: 'https://example.com',
414
+ rukhUrl: 'https://rukh.w3hc.org',
415
+ model: 'anthropic',
416
+ focusMode: 'transactions'
417
+ })
418
+ console.log(result.report)
419
+
420
+ // Quick console inspection
421
+ await inspectNow() // Logs report directly to console
299
422
  ```
300
- bafybeig2xoiu2hfcjexz6cwtjcjf4u4vwxzcm66zhnqivhh6jvi7nx2qa4
423
+
424
+ **Node.js (analyze local files):**
425
+ ```typescript
426
+ import { inspect, gatherCode } from 'w3pk/inspect/node'
427
+
428
+ // Generate security report via Rukh API
429
+ const report = await inspect(
430
+ '../my-dapp', // App path
431
+ 'https://rukh.w3hc.org', // Rukh API URL
432
+ 'w3pk', // Context
433
+ 'anthropic', // Model
434
+ 'transactions' // Focus mode
435
+ )
436
+
437
+ // Or just gather code for analysis
438
+ const result = await gatherCode({
439
+ appPath: '../my-dapp',
440
+ focusMode: 'transactions',
441
+ maxFileSizeKB: 500
442
+ })
443
+ console.log(`Analyzed ${result.includedFiles.length} files`)
301
444
  ```
302
445
 
303
- **Verify package integrity:**
446
+ ## Security & Verification
304
447
 
305
- ```typescript
306
- import { verifyBuildHash } from 'w3pk'
448
+ ### Onchain Build Registry
307
449
 
308
- const TRUSTED_HASH = 'bafybeig2xoiu2hfcjexz6cwtjcjf4u4vwxzcm66zhnqivhh6jvi7nx2qa4'
309
- const isValid = await verifyBuildHash(TRUSTED_HASH)
450
+ W3PK maintains a DAO-controlled onchain registry of verified build hashes on OP Mainnet:
310
451
 
311
- if (!isValid) {
312
- throw new Error('Package integrity check failed!')
313
- }
314
- ```
452
+ - **Registry Contract:** [`0xAF48C2DB335eD5da14A2C36a59Bc34407C63e01a`](https://optimistic.etherscan.io/address/0xAF48C2DB335eD5da14A2C36a59Bc34407C63e01a)
453
+ - **Network:** OP Mainnet (Chain ID: 10)
454
+ - **Purpose:** Immutable source of truth for official W3PK releases
455
+
456
+ Host applications should verify their installed W3PK build against this registry. See [Build Verification](./docs/BUILD_VERIFICATION.md) for implementation details.
315
457
 
316
458
  ## Documentation
317
459
 
@@ -319,9 +461,11 @@ if (!isValid) {
319
461
  - [Integration Guidelines](./docs/INTEGRATION_GUIDELINES.md)
320
462
  - [API Reference](./docs/API_REFERENCE.md)
321
463
  - [Build Verification](./docs/BUILD_VERIFICATION.md)
464
+ - [Security Inspection](./docs/INSPECTION.md)
322
465
  - [EIP-7951](./docs/EIP-7951.md)
323
466
  - [Security Architecture](./docs/SECURITY.md)
324
467
  - [Recovery & Backup System](./docs/RECOVERY.md)
468
+ - [Portability Guide](./docs/PORTABILITY.md)
325
469
  - [ZK Proofs](./docs/ZK.md)
326
470
  - [Browser Compatibility](./docs/BROWSER_COMPATIBILITY.md)
327
471
 
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Chainlist types
3
+ */
4
+ interface Chain {
5
+ name: string;
6
+ chain: string;
7
+ icon?: string;
8
+ rpc: string[];
9
+ features?: Array<{
10
+ name: string;
11
+ }>;
12
+ faucets: string[];
13
+ nativeCurrency: {
14
+ name: string;
15
+ symbol: string;
16
+ decimals: number;
17
+ };
18
+ infoURL: string;
19
+ shortName: string;
20
+ chainId: number;
21
+ networkId: number;
22
+ slip44?: number;
23
+ ens?: {
24
+ registry: string;
25
+ };
26
+ explorers?: Array<{
27
+ name: string;
28
+ url: string;
29
+ icon?: string;
30
+ standard: string;
31
+ }>;
32
+ title?: string;
33
+ status?: string;
34
+ redFlags?: string[];
35
+ }
36
+ interface ChainlistOptions {
37
+ /**
38
+ * Custom URL for chains.json data
39
+ * @default 'https://chainid.network/chains.json'
40
+ */
41
+ chainsJsonUrl?: string;
42
+ /**
43
+ * Cache duration in milliseconds
44
+ * @default 3600000 (1 hour)
45
+ */
46
+ cacheDuration?: number;
47
+ }
48
+
49
+ /**
50
+ * Chainlist module for fetching RPC endpoints
51
+ */
52
+
53
+ /**
54
+ * Get RPC endpoints for a specific chain ID, excluding those that require API keys
55
+ *
56
+ * @param chainId - The chain ID to get endpoints for
57
+ * @param options - Optional configuration
58
+ * @returns Array of RPC URLs that don't require API keys
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * import { getEndpoints } from 'w3pk/chainlist'
63
+ *
64
+ * // Get Ethereum mainnet RPCs
65
+ * const endpoints = await getEndpoints(1)
66
+ * console.log(endpoints)
67
+ * // [
68
+ * // "https://api.mycryptoapi.com/eth",
69
+ * // "https://cloudflare-eth.com",
70
+ * // "https://ethereum-rpc.publicnode.com",
71
+ * // ...
72
+ * // ]
73
+ * ```
74
+ */
75
+ declare function getEndpoints(chainId: number, options?: ChainlistOptions): Promise<string[]>;
76
+ /**
77
+ * Get all available chains
78
+ *
79
+ * @param options - Optional configuration
80
+ * @returns Array of all chains
81
+ */
82
+ declare function getAllChains(options?: ChainlistOptions): Promise<Chain[]>;
83
+ /**
84
+ * Get chain information by chain ID
85
+ *
86
+ * @param chainId - The chain ID to get information for
87
+ * @param options - Optional configuration
88
+ * @returns Chain information or undefined if not found
89
+ */
90
+ declare function getChainById(chainId: number, options?: ChainlistOptions): Promise<Chain | undefined>;
91
+ /**
92
+ * Clear the chains data cache
93
+ */
94
+ declare function clearCache(): void;
95
+
96
+ export { type Chain, type ChainlistOptions, clearCache, getAllChains, getChainById, getEndpoints };
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Chainlist types
3
+ */
4
+ interface Chain {
5
+ name: string;
6
+ chain: string;
7
+ icon?: string;
8
+ rpc: string[];
9
+ features?: Array<{
10
+ name: string;
11
+ }>;
12
+ faucets: string[];
13
+ nativeCurrency: {
14
+ name: string;
15
+ symbol: string;
16
+ decimals: number;
17
+ };
18
+ infoURL: string;
19
+ shortName: string;
20
+ chainId: number;
21
+ networkId: number;
22
+ slip44?: number;
23
+ ens?: {
24
+ registry: string;
25
+ };
26
+ explorers?: Array<{
27
+ name: string;
28
+ url: string;
29
+ icon?: string;
30
+ standard: string;
31
+ }>;
32
+ title?: string;
33
+ status?: string;
34
+ redFlags?: string[];
35
+ }
36
+ interface ChainlistOptions {
37
+ /**
38
+ * Custom URL for chains.json data
39
+ * @default 'https://chainid.network/chains.json'
40
+ */
41
+ chainsJsonUrl?: string;
42
+ /**
43
+ * Cache duration in milliseconds
44
+ * @default 3600000 (1 hour)
45
+ */
46
+ cacheDuration?: number;
47
+ }
48
+
49
+ /**
50
+ * Chainlist module for fetching RPC endpoints
51
+ */
52
+
53
+ /**
54
+ * Get RPC endpoints for a specific chain ID, excluding those that require API keys
55
+ *
56
+ * @param chainId - The chain ID to get endpoints for
57
+ * @param options - Optional configuration
58
+ * @returns Array of RPC URLs that don't require API keys
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * import { getEndpoints } from 'w3pk/chainlist'
63
+ *
64
+ * // Get Ethereum mainnet RPCs
65
+ * const endpoints = await getEndpoints(1)
66
+ * console.log(endpoints)
67
+ * // [
68
+ * // "https://api.mycryptoapi.com/eth",
69
+ * // "https://cloudflare-eth.com",
70
+ * // "https://ethereum-rpc.publicnode.com",
71
+ * // ...
72
+ * // ]
73
+ * ```
74
+ */
75
+ declare function getEndpoints(chainId: number, options?: ChainlistOptions): Promise<string[]>;
76
+ /**
77
+ * Get all available chains
78
+ *
79
+ * @param options - Optional configuration
80
+ * @returns Array of all chains
81
+ */
82
+ declare function getAllChains(options?: ChainlistOptions): Promise<Chain[]>;
83
+ /**
84
+ * Get chain information by chain ID
85
+ *
86
+ * @param chainId - The chain ID to get information for
87
+ * @param options - Optional configuration
88
+ * @returns Chain information or undefined if not found
89
+ */
90
+ declare function getChainById(chainId: number, options?: ChainlistOptions): Promise<Chain | undefined>;
91
+ /**
92
+ * Clear the chains data cache
93
+ */
94
+ declare function clearCache(): void;
95
+
96
+ export { type Chain, type ChainlistOptions, clearCache, getAllChains, getChainById, getEndpoints };