pwc-sdk-wallet 0.7.5 → 0.7.7
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 +86 -141
- package/dist/index.d.ts +0 -2
- package/dist/index.js +2 -8
- package/package.json +2 -4
- package/dist/connectors/PWCWalletConnector.d.ts +0 -107
- package/dist/connectors/PWCWalletConnector.js +0 -195
- package/dist/utils/wagmi-config.d.ts +0 -12
- package/dist/utils/wagmi-config.js +0 -21
package/README.md
CHANGED
|
@@ -55,15 +55,15 @@ A comprehensive, secure, and user-friendly wallet SDK for React Native applicati
|
|
|
55
55
|
- [Validate QR Code](#validate-qr-code)
|
|
56
56
|
- [Generate EIP-681 Compatible Address QR (for Metamask, Binance, Trust Wallet)](#generate-eip-681-compatible-address-qr-for-metamask-binance-trust-wallet)
|
|
57
57
|
|
|
58
|
-
### 🌐 DApp Browser Integration
|
|
58
|
+
### 🌐 DApp Browser Integration
|
|
59
59
|
- [Key Benefits](#key-benefits)
|
|
60
|
-
- [Quick Start (
|
|
60
|
+
- [Quick Start (Direct Provider Injection)](#quick-start-direct-provider-injection)
|
|
61
61
|
- [What This Achieves](#what-this-achieves)
|
|
62
|
-
- [Components](#dapp-browser-components)
|
|
63
|
-
- [Services](#dapp-browser-services)
|
|
64
|
-
- [
|
|
65
|
-
- [Hooks](#dapp-browser-hooks)
|
|
66
|
-
- [Examples](#dapp-browser-examples)
|
|
62
|
+
- [DApp Browser Components](#dapp-browser-components)
|
|
63
|
+
- [DApp Browser Services](#dapp-browser-services)
|
|
64
|
+
- [Provider Injection (Core Feature)](#provider-injection-core-feature)
|
|
65
|
+
- [DApp Browser Hooks](#dapp-browser-hooks)
|
|
66
|
+
- [DApp Browser Examples](#dapp-browser-examples)
|
|
67
67
|
- [Summary: Universal dApp Compatibility](#summary-universal-dapp-compatibility)
|
|
68
68
|
|
|
69
69
|
### 🖼️ NFT Functionality
|
|
@@ -704,14 +704,14 @@ console.log('Transaction History:', history);
|
|
|
704
704
|
// Returns array of: { hash, from, to, blockNumber, timestamp, type }
|
|
705
705
|
```
|
|
706
706
|
|
|
707
|
-
## 🌐 DApp Browser Integration
|
|
707
|
+
## 🌐 DApp Browser Integration
|
|
708
708
|
|
|
709
|
-
The PWC Wallet SDK provides a complete DApp Browser integration with **
|
|
709
|
+
The PWC Wallet SDK provides a complete DApp Browser integration with **direct provider injection**, ensuring that PWC Wallet appears as a connection option in **all dApps**. This integration follows the same patterns as popular wallets like MetaMask Mobile, Trust Wallet, and Rainbow Wallet.
|
|
710
710
|
|
|
711
|
-
###
|
|
711
|
+
### Key Benefits
|
|
712
712
|
|
|
713
|
-
- **Universal dApp Compatibility** - PWC Wallet appears in ALL dApps
|
|
714
|
-
- **One-Click Integration** - Simple setup with `
|
|
713
|
+
- **Universal dApp Compatibility** - PWC Wallet appears in ALL dApps automatically
|
|
714
|
+
- **One-Click Integration** - Simple setup with `DAppBrowser` component
|
|
715
715
|
- **Built-in WebView Browser** - Complete browser with navigation controls
|
|
716
716
|
- **Automatic Provider Injection** - PWC Wallet provider automatically injected
|
|
717
717
|
- **Transaction Approval UI** - Beautiful transaction approval modals
|
|
@@ -719,79 +719,58 @@ The PWC Wallet SDK provides a complete DApp Browser integration with **Wagmi sup
|
|
|
719
719
|
- **Multi-chain Support** - Support for Ethereum and other EVM chains
|
|
720
720
|
- **Security Features** - Transaction validation and user confirmation
|
|
721
721
|
|
|
722
|
-
###
|
|
722
|
+
### Quick Start (Direct Provider Injection)
|
|
723
723
|
|
|
724
724
|
```typescript
|
|
725
725
|
import React from 'react';
|
|
726
|
-
import {
|
|
727
|
-
import { DAppBrowser, createWagmiConfig } from 'pwc-wallet-sdk';
|
|
726
|
+
import { DAppBrowser } from 'pwc-wallet-sdk';
|
|
728
727
|
|
|
729
728
|
const WalletApp = () => {
|
|
730
729
|
const vault = new Vault(); // Your vault instance
|
|
731
730
|
|
|
732
|
-
// Create Wagmi config with PWC Wallet connector
|
|
733
|
-
const wagmiConfig = createWagmiConfig({
|
|
734
|
-
vault: vault,
|
|
735
|
-
pwcWalletName: 'PWC Wallet',
|
|
736
|
-
pwcWalletIcon: 'https://pwc-wallet.com/icon.png'
|
|
737
|
-
});
|
|
738
|
-
|
|
739
731
|
return (
|
|
740
|
-
<
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
/>
|
|
754
|
-
</WagmiConfig>
|
|
732
|
+
<DAppBrowser
|
|
733
|
+
vault={vault}
|
|
734
|
+
initialUrl="https://paywithcrypto.io/"
|
|
735
|
+
onTransaction={(transaction) => {
|
|
736
|
+
console.log('Transaction requested:', transaction);
|
|
737
|
+
}}
|
|
738
|
+
onConnection={(dAppInfo) => {
|
|
739
|
+
console.log('Connection requested:', dAppInfo);
|
|
740
|
+
}}
|
|
741
|
+
onError={(error) => {
|
|
742
|
+
console.error('Browser error:', error);
|
|
743
|
+
}}
|
|
744
|
+
/>
|
|
755
745
|
);
|
|
756
746
|
};
|
|
757
747
|
```
|
|
758
748
|
|
|
759
|
-
###
|
|
749
|
+
### What This Achieves
|
|
760
750
|
|
|
761
751
|
With this setup, PWC Wallet will appear as a connection option in:
|
|
762
752
|
|
|
763
753
|
- ✅ **PancakeSwap** - "Connect Wallet" → PWC Wallet option
|
|
764
754
|
- ✅ **Uniswap** - "Connect Wallet" → PWC Wallet option
|
|
765
755
|
- ✅ **OpenSea** - "Connect Wallet" → PWC Wallet option
|
|
766
|
-
- ✅ **All dApps
|
|
767
|
-
- ✅ **All dApps using ConnectKit** - "Connect Wallet" → PWC Wallet option
|
|
768
|
-
- ✅ **All dApps using RainbowKit** - "Connect Wallet" → PWC Wallet option
|
|
756
|
+
- ✅ **All dApps** - "Connect Wallet" → PWC Wallet option
|
|
769
757
|
|
|
770
758
|
### DApp Browser Components
|
|
771
759
|
|
|
772
760
|
#### DAppBrowser
|
|
773
761
|
|
|
774
|
-
The main component that provides a complete WebView browser with PWC Wallet integration.
|
|
762
|
+
The main component that provides a complete WebView browser with PWC Wallet integration.
|
|
775
763
|
|
|
776
764
|
```typescript
|
|
777
|
-
import {
|
|
778
|
-
import { DAppBrowser, createWagmiConfig } from 'pwc-wallet-sdk';
|
|
765
|
+
import { DAppBrowser } from 'pwc-wallet-sdk';
|
|
779
766
|
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
<DAppBrowser
|
|
788
|
-
vault={vault}
|
|
789
|
-
initialUrl="https://paywithcrypto.io/"
|
|
790
|
-
onTransaction={handleTransaction}
|
|
791
|
-
onConnection={handleConnection}
|
|
792
|
-
onError={handleError}
|
|
793
|
-
/>
|
|
794
|
-
</WagmiConfig>
|
|
767
|
+
<DAppBrowser
|
|
768
|
+
vault={vault}
|
|
769
|
+
initialUrl="https://paywithcrypto.io/"
|
|
770
|
+
onTransaction={handleTransaction}
|
|
771
|
+
onConnection={handleConnection}
|
|
772
|
+
onError={handleError}
|
|
773
|
+
/>
|
|
795
774
|
```
|
|
796
775
|
|
|
797
776
|
#### TransactionModal
|
|
@@ -859,37 +838,27 @@ const transactionHandler = new TransactionHandler(vault);
|
|
|
859
838
|
const details = await transactionHandler.processTransaction(transaction);
|
|
860
839
|
```
|
|
861
840
|
|
|
862
|
-
###
|
|
841
|
+
### Provider Injection (Core Feature)
|
|
863
842
|
|
|
864
|
-
####
|
|
843
|
+
#### How It Works
|
|
865
844
|
|
|
866
|
-
The **core
|
|
845
|
+
The **core mechanism** that makes PWC Wallet appear in all dApps. The SDK automatically injects the PWC Wallet provider into the WebView, making it available to all dApps.
|
|
867
846
|
|
|
868
847
|
```typescript
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
icon: 'https://pwc-wallet.com/icon.png'
|
|
876
|
-
});
|
|
877
|
-
|
|
878
|
-
// Create complete Wagmi config
|
|
879
|
-
const config = createWagmiConfig({
|
|
880
|
-
vault: vault,
|
|
881
|
-
appName: 'PWC Wallet',
|
|
882
|
-
pwcWalletName: 'PWC Wallet',
|
|
883
|
-
pwcWalletIcon: 'https://pwc-wallet.com/icon.png'
|
|
884
|
-
});
|
|
848
|
+
// Automatically injected into WebView
|
|
849
|
+
window.ethereum = window.pwcWallet = {
|
|
850
|
+
request: async (request) => { /* handle requests */ },
|
|
851
|
+
on: (event, callback) => { /* event listeners */ },
|
|
852
|
+
// ... other provider methods
|
|
853
|
+
};
|
|
885
854
|
```
|
|
886
855
|
|
|
887
856
|
#### Why This Matters
|
|
888
857
|
|
|
889
|
-
- **Universal Compatibility** - PWC Wallet appears in ALL dApps
|
|
858
|
+
- **Universal Compatibility** - PWC Wallet appears in ALL dApps automatically
|
|
890
859
|
- **No dApp Changes Required** - dApps don't need to add PWC Wallet manually
|
|
891
|
-
- **Industry Standard** - Follows the same pattern as MetaMask,
|
|
892
|
-
- **Future-Proof** - Works with any
|
|
860
|
+
- **Industry Standard** - Follows the same pattern as MetaMask, Trust Wallet
|
|
861
|
+
- **Future-Proof** - Works with any dApp that uses standard Web3 providers
|
|
893
862
|
|
|
894
863
|
### DApp Browser Hooks
|
|
895
864
|
|
|
@@ -915,41 +884,31 @@ const {
|
|
|
915
884
|
|
|
916
885
|
### DApp Browser Examples
|
|
917
886
|
|
|
918
|
-
#### Complete Wallet App
|
|
887
|
+
#### Complete Wallet App
|
|
919
888
|
|
|
920
889
|
```typescript
|
|
921
890
|
import React, { useState } from 'react';
|
|
922
891
|
import { View, Text, TouchableOpacity } from 'react-native';
|
|
923
|
-
import {
|
|
924
|
-
import { DAppBrowser, usePWCWallet, Vault, createWagmiConfig } from 'pwc-wallet-sdk';
|
|
892
|
+
import { DAppBrowser, usePWCWallet, Vault } from 'pwc-wallet-sdk';
|
|
925
893
|
|
|
926
894
|
const WalletApp = () => {
|
|
927
895
|
const [activeTab, setActiveTab] = useState<'wallet' | 'browser'>('wallet');
|
|
928
896
|
const vault = new Vault(); // Your vault instance
|
|
929
897
|
|
|
930
|
-
// Create Wagmi config for universal dApp compatibility
|
|
931
|
-
const wagmiConfig = createWagmiConfig({
|
|
932
|
-
vault: vault,
|
|
933
|
-
pwcWalletName: 'PWC Wallet',
|
|
934
|
-
pwcWalletIcon: 'https://pwc-wallet.com/icon.png'
|
|
935
|
-
});
|
|
936
|
-
|
|
937
898
|
const { accounts, currentAccount, isConnected, connect, disconnect } = usePWCWallet({ vault });
|
|
938
899
|
|
|
939
900
|
if (activeTab === 'browser') {
|
|
940
901
|
return (
|
|
941
|
-
<
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
/>
|
|
952
|
-
</WagmiConfig>
|
|
902
|
+
<DAppBrowser
|
|
903
|
+
vault={vault}
|
|
904
|
+
initialUrl="https://paywithcrypto.io/"
|
|
905
|
+
onTransaction={(transaction) => {
|
|
906
|
+
console.log('Transaction:', transaction);
|
|
907
|
+
}}
|
|
908
|
+
onConnection={(dAppInfo) => {
|
|
909
|
+
console.log('Connection:', dAppInfo);
|
|
910
|
+
}}
|
|
911
|
+
/>
|
|
953
912
|
);
|
|
954
913
|
}
|
|
955
914
|
|
|
@@ -980,39 +939,31 @@ const WalletApp = () => {
|
|
|
980
939
|
|
|
981
940
|
```typescript
|
|
982
941
|
import React from 'react';
|
|
983
|
-
import {
|
|
984
|
-
import { DAppBrowser, createWagmiConfig } from 'pwc-wallet-sdk';
|
|
942
|
+
import { DAppBrowser } from 'pwc-wallet-sdk';
|
|
985
943
|
|
|
986
944
|
const PancakeSwapExample = () => {
|
|
987
945
|
const vault = new Vault();
|
|
988
|
-
|
|
989
|
-
const wagmiConfig = createWagmiConfig({
|
|
990
|
-
vault: vault,
|
|
991
|
-
pwcWalletName: 'PWC Wallet'
|
|
992
|
-
});
|
|
993
946
|
|
|
994
947
|
return (
|
|
995
|
-
<
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
/>
|
|
1006
|
-
</WagmiConfig>
|
|
948
|
+
<DAppBrowser
|
|
949
|
+
vault={vault}
|
|
950
|
+
initialUrl="https://pancakeswap.finance/"
|
|
951
|
+
onTransaction={(transaction) => {
|
|
952
|
+
console.log('PancakeSwap transaction:', transaction);
|
|
953
|
+
}}
|
|
954
|
+
onConnection={(dAppInfo) => {
|
|
955
|
+
console.log('PancakeSwap connection:', dAppInfo);
|
|
956
|
+
}}
|
|
957
|
+
/>
|
|
1007
958
|
);
|
|
1008
959
|
};
|
|
1009
960
|
```
|
|
1010
961
|
|
|
1011
962
|
**Result:** When user clicks "Connect Wallet" on PancakeSwap, they will see "PWC Wallet" as an option! 🎯
|
|
1012
963
|
|
|
1013
|
-
###
|
|
964
|
+
### Summary: Universal dApp Compatibility
|
|
1014
965
|
|
|
1015
|
-
The PWC Wallet SDK with
|
|
966
|
+
The PWC Wallet SDK with direct provider injection provides **universal dApp compatibility**:
|
|
1016
967
|
|
|
1017
968
|
#### ✅ **Works with ALL dApps:**
|
|
1018
969
|
- **PancakeSwap** - "Connect Wallet" → PWC Wallet option
|
|
@@ -1020,30 +971,26 @@ The PWC Wallet SDK with Wagmi integration provides **universal dApp compatibilit
|
|
|
1020
971
|
- **OpenSea** - "Connect Wallet" → PWC Wallet option
|
|
1021
972
|
- **Aave** - "Connect Wallet" → PWC Wallet option
|
|
1022
973
|
- **Compound** - "Connect Wallet" → PWC Wallet option
|
|
1023
|
-
- **Any dApp
|
|
974
|
+
- **Any dApp** - "Connect Wallet" → PWC Wallet option
|
|
1024
975
|
|
|
1025
976
|
#### ✅ **One Setup, Universal Access:**
|
|
1026
977
|
```typescript
|
|
1027
978
|
// Mobile dev chỉ cần setup 1 lần
|
|
1028
|
-
|
|
1029
|
-
vault
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
<WagmiConfig config={wagmiConfig}>
|
|
1034
|
-
<DAppBrowser vault={vault} />
|
|
1035
|
-
</WagmiConfig>
|
|
979
|
+
<DAppBrowser
|
|
980
|
+
vault={vault}
|
|
981
|
+
initialUrl="https://pancakeswap.finance/"
|
|
982
|
+
/>
|
|
1036
983
|
```
|
|
1037
984
|
|
|
1038
985
|
#### ✅ **No dApp Changes Required:**
|
|
1039
986
|
- dApps don't need to add PWC Wallet manually
|
|
1040
987
|
- Works with existing dApp code
|
|
1041
|
-
- Follows industry standards (MetaMask,
|
|
988
|
+
- Follows industry standards (MetaMask, Trust Wallet)
|
|
1042
989
|
|
|
1043
|
-
#### ✅ **No
|
|
990
|
+
#### ✅ **No External Dependencies:**
|
|
1044
991
|
- PWC Wallet uses built-in browser (WebView)
|
|
1045
|
-
- No need for
|
|
1046
|
-
- Direct connection
|
|
992
|
+
- No need for external services or bridges
|
|
993
|
+
- Direct connection through provider injection
|
|
1047
994
|
|
|
1048
995
|
For detailed documentation, see [DApp Browser Integration Guide](./docs/DAPP_BROWSER_INTEGRATION.md).
|
|
1049
996
|
|
|
@@ -1435,15 +1382,13 @@ npm install pwc-wallet-sdk
|
|
|
1435
1382
|
For DApp Browser functionality with universal dApp compatibility:
|
|
1436
1383
|
|
|
1437
1384
|
```bash
|
|
1438
|
-
npm install pwc-wallet-sdk react-native-webview
|
|
1385
|
+
npm install pwc-wallet-sdk react-native-webview
|
|
1439
1386
|
```
|
|
1440
1387
|
|
|
1441
1388
|
**Required Dependencies:**
|
|
1442
1389
|
- `react-native-webview` - For WebView browser functionality
|
|
1443
|
-
- `wagmi` - For universal dApp compatibility
|
|
1444
|
-
- `connectkit` - For modern wallet connection UI
|
|
1445
1390
|
|
|
1446
|
-
**Note:**
|
|
1391
|
+
**Note:** This is a peer dependency. Mobile developers need to install it to use the DApp Browser features.
|
|
1447
1392
|
|
|
1448
1393
|
## Quick Start
|
|
1449
1394
|
|
package/dist/index.d.ts
CHANGED
|
@@ -26,6 +26,4 @@ export * from './services/nft/NFTService';
|
|
|
26
26
|
export { DAppBrowser } from './components/DAppBrowser';
|
|
27
27
|
export { TransactionModal } from './components/TransactionModal';
|
|
28
28
|
export { ConnectionModal } from './components/ConnectionModal';
|
|
29
|
-
export { PWCWalletConnector } from './connectors/PWCWalletConnector';
|
|
30
29
|
export { usePWCWallet } from './hooks/usePWCWallet';
|
|
31
|
-
export { createWagmiConfig } from './utils/wagmi-config';
|
package/dist/index.js
CHANGED
|
@@ -16,7 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.TransactionModal = exports.DAppBrowser = exports.TransactionHandler = exports.MessageBridgeService = exports.BrowserProviderService = exports.QRCodeService = exports.BatchProcessor = exports.MultiTransferService = exports.EncryptionService = exports.SolanaChainService = exports.ChainService = exports.SolanaKeyring = exports.SimpleKeyring = exports.HDKeyring = exports.getEnvVarBoolean = exports.getEnvVarBigInt = exports.getEnvVarNumber = exports.getEnvVar = exports.validateEnvironmentConfig = exports.getEnvironmentConfig = exports.VALIDATION_CONFIG = exports.CACHE_CONFIG = exports.NETWORK_CONFIG = exports.SECURITY_CONFIG = exports.VANITY_WALLET_CONFIG = exports.clearGlobalGasConfigs = exports.getGasConfig = exports.setGlobalNetworkGasConfig = exports.setGlobalGasConfig = exports.calculateOptimalGasPrice = exports.getNetworkGasConfig = exports.NETWORK_GAS_CONFIG = exports.GAS_CONFIG = exports.clearGlobalConfigs = exports.setGlobalExplorerConfig = exports.setGlobalRPCConfig = exports.getOverrides = exports.getCustomChains = exports.clearOverride = exports.clearOverrides = exports.clearCustomChains = exports.getAllAvailableChains = exports.setupChainConfigs = exports.getChainConfig = exports.overrideChains = exports.overrideChain = exports.registerCustomChain = exports.DERIVATION_PATHS = exports.SUPPORTED_CHAINS = exports.Vault = void 0;
|
|
19
|
-
exports.
|
|
19
|
+
exports.usePWCWallet = exports.ConnectionModal = void 0;
|
|
20
20
|
// The primary `Vault` class is the main entry point for interacting with the SDK.
|
|
21
21
|
var Vault_1 = require("./Vault");
|
|
22
22
|
Object.defineProperty(exports, "Vault", { enumerable: true, get: function () { return Vault_1.Vault; } });
|
|
@@ -109,12 +109,6 @@ var TransactionModal_1 = require("./components/TransactionModal");
|
|
|
109
109
|
Object.defineProperty(exports, "TransactionModal", { enumerable: true, get: function () { return TransactionModal_1.TransactionModal; } });
|
|
110
110
|
var ConnectionModal_1 = require("./components/ConnectionModal");
|
|
111
111
|
Object.defineProperty(exports, "ConnectionModal", { enumerable: true, get: function () { return ConnectionModal_1.ConnectionModal; } });
|
|
112
|
-
//
|
|
113
|
-
var PWCWalletConnector_1 = require("./connectors/PWCWalletConnector");
|
|
114
|
-
Object.defineProperty(exports, "PWCWalletConnector", { enumerable: true, get: function () { return PWCWalletConnector_1.PWCWalletConnector; } });
|
|
115
|
-
// React Native hooks
|
|
112
|
+
// DApp Browser Hooks
|
|
116
113
|
var usePWCWallet_1 = require("./hooks/usePWCWallet");
|
|
117
114
|
Object.defineProperty(exports, "usePWCWallet", { enumerable: true, get: function () { return usePWCWallet_1.usePWCWallet; } });
|
|
118
|
-
// Utilities
|
|
119
|
-
var wagmi_config_1 = require("./utils/wagmi-config");
|
|
120
|
-
Object.defineProperty(exports, "createWagmiConfig", { enumerable: true, get: function () { return wagmi_config_1.createWagmiConfig; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pwc-sdk-wallet",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.7",
|
|
4
4
|
"description": "A comprehensive wallet SDK for React Native (pwc), supporting multi-chain and multi-account features.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -56,9 +56,7 @@
|
|
|
56
56
|
"react": "*",
|
|
57
57
|
"react-native": "*",
|
|
58
58
|
"react-native-get-random-values": "^1.9.0",
|
|
59
|
-
"react-native-keychain": "^8.2.0"
|
|
60
|
-
"wagmi": "^1.0.0",
|
|
61
|
-
"connectkit": "^1.0.0"
|
|
59
|
+
"react-native-keychain": "^8.2.0"
|
|
62
60
|
},
|
|
63
61
|
"devDependencies": {
|
|
64
62
|
"@types/crypto-js": "^4.2.2",
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'events';
|
|
2
|
-
import { Vault } from '../Vault';
|
|
3
|
-
interface ConnectorData {
|
|
4
|
-
account: string;
|
|
5
|
-
chain: {
|
|
6
|
-
id: number;
|
|
7
|
-
unsupported: boolean;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
declare abstract class Connector extends EventEmitter {
|
|
11
|
-
abstract readonly id: string;
|
|
12
|
-
abstract readonly name: string;
|
|
13
|
-
abstract readonly ready: boolean;
|
|
14
|
-
abstract connect(): Promise<ConnectorData>;
|
|
15
|
-
abstract disconnect(): Promise<void>;
|
|
16
|
-
abstract getAccount(): Promise<string | undefined>;
|
|
17
|
-
abstract getChainId(): Promise<number>;
|
|
18
|
-
abstract getProvider(): Promise<any>;
|
|
19
|
-
abstract getSigner(): Promise<any>;
|
|
20
|
-
abstract isAuthorized(): Promise<boolean>;
|
|
21
|
-
abstract switchChain(chainId: number): Promise<{
|
|
22
|
-
id: number;
|
|
23
|
-
unsupported: boolean;
|
|
24
|
-
}>;
|
|
25
|
-
}
|
|
26
|
-
export interface PWCWalletConnectorOptions {
|
|
27
|
-
vault: Vault;
|
|
28
|
-
name?: string;
|
|
29
|
-
icon?: string;
|
|
30
|
-
}
|
|
31
|
-
export declare class PWCWalletConnector extends Connector {
|
|
32
|
-
readonly id = "pwc-wallet";
|
|
33
|
-
readonly name: string;
|
|
34
|
-
readonly ready = true;
|
|
35
|
-
readonly icon?: string;
|
|
36
|
-
private vault;
|
|
37
|
-
private accounts;
|
|
38
|
-
constructor({ vault, name, icon }: PWCWalletConnectorOptions);
|
|
39
|
-
/**
|
|
40
|
-
* Connect to PWC Wallet
|
|
41
|
-
*/
|
|
42
|
-
connect(): Promise<ConnectorData>;
|
|
43
|
-
/**
|
|
44
|
-
* Disconnect from PWC Wallet
|
|
45
|
-
*/
|
|
46
|
-
disconnect(): Promise<void>;
|
|
47
|
-
/**
|
|
48
|
-
* Get current account
|
|
49
|
-
*/
|
|
50
|
-
getAccount(): Promise<string | undefined>;
|
|
51
|
-
/**
|
|
52
|
-
* Get current chain ID
|
|
53
|
-
*/
|
|
54
|
-
getChainId(): Promise<number>;
|
|
55
|
-
/**
|
|
56
|
-
* Get provider
|
|
57
|
-
*/
|
|
58
|
-
getProvider(): Promise<any>;
|
|
59
|
-
/**
|
|
60
|
-
* Get signer
|
|
61
|
-
*/
|
|
62
|
-
getSigner(): Promise<any>;
|
|
63
|
-
/**
|
|
64
|
-
* Check if wallet is connected
|
|
65
|
-
*/
|
|
66
|
-
isAuthorized(): Promise<boolean>;
|
|
67
|
-
/**
|
|
68
|
-
* Switch chain
|
|
69
|
-
*/
|
|
70
|
-
switchChain(chainId: number): Promise<{
|
|
71
|
-
id: number;
|
|
72
|
-
unsupported: boolean;
|
|
73
|
-
}>;
|
|
74
|
-
/**
|
|
75
|
-
* Watch account
|
|
76
|
-
*/
|
|
77
|
-
protected onAccountsChanged(accounts: string[]): void;
|
|
78
|
-
/**
|
|
79
|
-
* Watch chain
|
|
80
|
-
*/
|
|
81
|
-
protected onChainChanged(chainId: string | number): void;
|
|
82
|
-
/**
|
|
83
|
-
* Watch disconnect
|
|
84
|
-
*/
|
|
85
|
-
protected onDisconnect(): void;
|
|
86
|
-
/**
|
|
87
|
-
* Handle provider requests
|
|
88
|
-
*/
|
|
89
|
-
private handleProviderRequest;
|
|
90
|
-
/**
|
|
91
|
-
* Get account balance
|
|
92
|
-
*/
|
|
93
|
-
private getBalance;
|
|
94
|
-
/**
|
|
95
|
-
* Send transaction
|
|
96
|
-
*/
|
|
97
|
-
private sendTransaction;
|
|
98
|
-
/**
|
|
99
|
-
* Sign message
|
|
100
|
-
*/
|
|
101
|
-
private signMessage;
|
|
102
|
-
/**
|
|
103
|
-
* Sign transaction
|
|
104
|
-
*/
|
|
105
|
-
private signTransaction;
|
|
106
|
-
}
|
|
107
|
-
export {};
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PWCWalletConnector = void 0;
|
|
4
|
-
const events_1 = require("events");
|
|
5
|
-
class Connector extends events_1.EventEmitter {
|
|
6
|
-
}
|
|
7
|
-
class PWCWalletConnector extends Connector {
|
|
8
|
-
constructor({ vault, name = 'PWC Wallet', icon }) {
|
|
9
|
-
super();
|
|
10
|
-
this.id = 'pwc-wallet';
|
|
11
|
-
this.ready = true;
|
|
12
|
-
this.accounts = [];
|
|
13
|
-
this.vault = vault;
|
|
14
|
-
this.name = name;
|
|
15
|
-
this.icon = icon;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Connect to PWC Wallet
|
|
19
|
-
*/
|
|
20
|
-
async connect() {
|
|
21
|
-
try {
|
|
22
|
-
// Get accounts from vault
|
|
23
|
-
const vaultAccounts = await this.vault.getAccounts();
|
|
24
|
-
this.accounts = vaultAccounts.map(account => account.address);
|
|
25
|
-
if (this.accounts.length === 0) {
|
|
26
|
-
throw new Error('No accounts found in PWC Wallet');
|
|
27
|
-
}
|
|
28
|
-
// Get chain ID (default to Ethereum mainnet)
|
|
29
|
-
const chainId = 1; // Ethereum mainnet
|
|
30
|
-
return {
|
|
31
|
-
account: this.accounts[0],
|
|
32
|
-
chain: {
|
|
33
|
-
id: chainId,
|
|
34
|
-
unsupported: false,
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
throw new Error(`Failed to connect to PWC Wallet: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Disconnect from PWC Wallet
|
|
44
|
-
*/
|
|
45
|
-
async disconnect() {
|
|
46
|
-
this.accounts = [];
|
|
47
|
-
this.emit('disconnect');
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Get current account
|
|
51
|
-
*/
|
|
52
|
-
async getAccount() {
|
|
53
|
-
return this.accounts[0];
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Get current chain ID
|
|
57
|
-
*/
|
|
58
|
-
async getChainId() {
|
|
59
|
-
return 1; // Default to Ethereum mainnet
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Get provider
|
|
63
|
-
*/
|
|
64
|
-
async getProvider() {
|
|
65
|
-
// Return a mock provider that delegates to PWC Wallet
|
|
66
|
-
return {
|
|
67
|
-
request: async (request) => {
|
|
68
|
-
return this.handleProviderRequest(request);
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Get signer
|
|
74
|
-
*/
|
|
75
|
-
async getSigner() {
|
|
76
|
-
const provider = await this.getProvider();
|
|
77
|
-
return {
|
|
78
|
-
provider,
|
|
79
|
-
getAddress: async () => this.accounts[0],
|
|
80
|
-
signMessage: async (message) => {
|
|
81
|
-
return this.signMessage(message);
|
|
82
|
-
},
|
|
83
|
-
signTransaction: async (transaction) => {
|
|
84
|
-
return this.signTransaction(transaction);
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Check if wallet is connected
|
|
90
|
-
*/
|
|
91
|
-
async isAuthorized() {
|
|
92
|
-
return this.accounts.length > 0;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Switch chain
|
|
96
|
-
*/
|
|
97
|
-
async switchChain(chainId) {
|
|
98
|
-
// For now, only support Ethereum mainnet
|
|
99
|
-
if (chainId !== 1) {
|
|
100
|
-
throw new Error('Chain not supported');
|
|
101
|
-
}
|
|
102
|
-
return {
|
|
103
|
-
id: chainId,
|
|
104
|
-
unsupported: false,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Watch account
|
|
109
|
-
*/
|
|
110
|
-
onAccountsChanged(accounts) {
|
|
111
|
-
if (accounts.length === 0) {
|
|
112
|
-
this.emit('disconnect');
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
this.accounts = accounts;
|
|
116
|
-
this.emit('change', { account: accounts[0] });
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Watch chain
|
|
121
|
-
*/
|
|
122
|
-
onChainChanged(chainId) {
|
|
123
|
-
this.emit('change', { chain: { id: Number(chainId), unsupported: false } });
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Watch disconnect
|
|
127
|
-
*/
|
|
128
|
-
onDisconnect() {
|
|
129
|
-
this.emit('disconnect');
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Handle provider requests
|
|
133
|
-
*/
|
|
134
|
-
async handleProviderRequest(request) {
|
|
135
|
-
const { method, params = [] } = request;
|
|
136
|
-
switch (method) {
|
|
137
|
-
case 'eth_accounts':
|
|
138
|
-
return this.accounts;
|
|
139
|
-
case 'eth_chainId':
|
|
140
|
-
return '0x1'; // Ethereum mainnet
|
|
141
|
-
case 'eth_getBalance':
|
|
142
|
-
const [address, blockTag] = params;
|
|
143
|
-
return await this.getBalance(address, blockTag);
|
|
144
|
-
case 'eth_sendTransaction':
|
|
145
|
-
const [transaction] = params;
|
|
146
|
-
return await this.sendTransaction(transaction);
|
|
147
|
-
case 'personal_sign':
|
|
148
|
-
const [message, account] = params;
|
|
149
|
-
return await this.signMessage(message, account);
|
|
150
|
-
case 'eth_signTransaction':
|
|
151
|
-
const [txToSign] = params;
|
|
152
|
-
return await this.signTransaction(txToSign);
|
|
153
|
-
case 'wallet_requestAccounts':
|
|
154
|
-
return this.accounts;
|
|
155
|
-
case 'wallet_addEthereumChain':
|
|
156
|
-
return null;
|
|
157
|
-
case 'wallet_switchEthereumChain':
|
|
158
|
-
return null;
|
|
159
|
-
default:
|
|
160
|
-
throw new Error(`Method ${method} not supported`);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Get account balance
|
|
165
|
-
*/
|
|
166
|
-
async getBalance(address, blockTag = 'latest') {
|
|
167
|
-
// This would integrate with actual blockchain RPC
|
|
168
|
-
return '0x0';
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Send transaction
|
|
172
|
-
*/
|
|
173
|
-
async sendTransaction(transaction) {
|
|
174
|
-
// This will trigger transaction approval modal
|
|
175
|
-
// For now, return a placeholder
|
|
176
|
-
return '0x1234567890abcdef';
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Sign message
|
|
180
|
-
*/
|
|
181
|
-
async signMessage(message, account) {
|
|
182
|
-
// This will trigger message signing approval
|
|
183
|
-
// For now, return a placeholder
|
|
184
|
-
return '0x1234567890abcdef';
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Sign transaction
|
|
188
|
-
*/
|
|
189
|
-
async signTransaction(transaction) {
|
|
190
|
-
// This will trigger transaction signing approval
|
|
191
|
-
// For now, return a placeholder
|
|
192
|
-
return '0x1234567890abcdef';
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
exports.PWCWalletConnector = PWCWalletConnector;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { PWCWalletConnector } from '../connectors/PWCWalletConnector';
|
|
2
|
-
import { Vault } from '../Vault';
|
|
3
|
-
export interface WagmiConfigOptions {
|
|
4
|
-
vault: Vault;
|
|
5
|
-
appName?: string;
|
|
6
|
-
pwcWalletName?: string;
|
|
7
|
-
pwcWalletIcon?: string;
|
|
8
|
-
}
|
|
9
|
-
export declare const createWagmiConfig: (options: WagmiConfigOptions) => {
|
|
10
|
-
appName: string;
|
|
11
|
-
connectors: PWCWalletConnector[];
|
|
12
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createWagmiConfig = void 0;
|
|
4
|
-
const PWCWalletConnector_1 = require("../connectors/PWCWalletConnector");
|
|
5
|
-
const createWagmiConfig = (options) => {
|
|
6
|
-
const { vault, appName = 'PWC Wallet', pwcWalletName = 'PWC Wallet', pwcWalletIcon, } = options;
|
|
7
|
-
// Create PWC Wallet connector
|
|
8
|
-
const pwcWalletConnector = new PWCWalletConnector_1.PWCWalletConnector({
|
|
9
|
-
vault,
|
|
10
|
-
name: pwcWalletName,
|
|
11
|
-
icon: pwcWalletIcon,
|
|
12
|
-
});
|
|
13
|
-
// Return configuration object for PWC Wallet
|
|
14
|
-
// Note: No projectId needed since PWC Wallet uses built-in browser, not WalletConnect
|
|
15
|
-
return {
|
|
16
|
-
appName,
|
|
17
|
-
connectors: [pwcWalletConnector],
|
|
18
|
-
// Add other Wagmi configuration options as needed
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
exports.createWagmiConfig = createWagmiConfig;
|