@shadow-corp/nearconnect 1.0.0 → 1.0.4
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/build/NearConnector.d.ts +29 -0
- package/build/NearConnector.js +96 -0
- package/build/NearConnector.js.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.js +7 -2
- package/build/index.js.map +1 -1
- package/build/types.d.ts +5 -0
- package/build/wallets/external/manager.js +24 -14
- package/build/wallets/external/manager.js.map +1 -1
- package/build/wallets/injected/adapter.d.ts +47 -0
- package/build/wallets/injected/adapter.js +233 -0
- package/build/wallets/injected/adapter.js.map +1 -0
- package/build/wallets/injected/detector.d.ts +82 -0
- package/build/wallets/injected/detector.js +237 -0
- package/build/wallets/injected/detector.js.map +1 -0
- package/build/wallets/injected/index.d.ts +10 -0
- package/build/wallets/injected/index.js +15 -0
- package/build/wallets/injected/index.js.map +1 -0
- package/build/wallets/injected/manager.d.ts +51 -0
- package/build/wallets/injected/manager.js +94 -0
- package/build/wallets/injected/manager.js.map +1 -0
- package/package.json +12 -4
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Injected Wallet Adapter
|
|
4
|
+
*
|
|
5
|
+
* Normalizes the different APIs each injected wallet uses into
|
|
6
|
+
* a consistent interface matching NearWalletBase.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.InjectedWalletAdapter = void 0;
|
|
10
|
+
class InjectedWalletAdapter {
|
|
11
|
+
manifest;
|
|
12
|
+
provider;
|
|
13
|
+
cachedAccounts = [];
|
|
14
|
+
constructor(wallet) {
|
|
15
|
+
this.provider = wallet.provider;
|
|
16
|
+
// Build manifest from detected wallet info
|
|
17
|
+
this.manifest = {
|
|
18
|
+
id: wallet.info.id,
|
|
19
|
+
name: wallet.info.name,
|
|
20
|
+
icon: wallet.info.icon,
|
|
21
|
+
website: wallet.info.website,
|
|
22
|
+
description: `${wallet.info.name} browser extension`,
|
|
23
|
+
type: 'injected',
|
|
24
|
+
version: '1.0.0',
|
|
25
|
+
executor: '',
|
|
26
|
+
permissions: {
|
|
27
|
+
storage: true,
|
|
28
|
+
external: [wallet.info.id],
|
|
29
|
+
},
|
|
30
|
+
features: {
|
|
31
|
+
signMessage: typeof this.provider.signMessage === 'function',
|
|
32
|
+
signTransaction: true,
|
|
33
|
+
signAndSendTransaction: typeof this.provider.signAndSendTransaction === 'function',
|
|
34
|
+
signAndSendTransactions: typeof this.provider.signAndSendTransactions === 'function' ||
|
|
35
|
+
typeof this.provider.requestSignTransactions === 'function',
|
|
36
|
+
signInWithoutAddKey: true,
|
|
37
|
+
mainnet: true,
|
|
38
|
+
testnet: true,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Sign in to the wallet
|
|
44
|
+
*/
|
|
45
|
+
async signIn(data) {
|
|
46
|
+
let result;
|
|
47
|
+
// Different wallets use different method names
|
|
48
|
+
if (typeof this.provider.connect === 'function') {
|
|
49
|
+
result = await this.provider.connect({
|
|
50
|
+
contractId: data?.contractId,
|
|
51
|
+
methodNames: data?.methodNames,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else if (typeof this.provider.signIn === 'function') {
|
|
55
|
+
result = await this.provider.signIn({
|
|
56
|
+
contractId: data?.contractId,
|
|
57
|
+
methodNames: data?.methodNames,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
else if (typeof this.provider.requestSignIn === 'function') {
|
|
61
|
+
result = await this.provider.requestSignIn({
|
|
62
|
+
contractId: data?.contractId,
|
|
63
|
+
methodNames: data?.methodNames,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
else if (typeof this.provider.enable === 'function') {
|
|
67
|
+
result = await this.provider.enable();
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
throw new Error(`Unknown connect method for ${this.manifest.name}`);
|
|
71
|
+
}
|
|
72
|
+
// Normalize and cache accounts
|
|
73
|
+
this.cachedAccounts = this.normalizeAccounts(result);
|
|
74
|
+
// If connect didn't return accounts, try to fetch them
|
|
75
|
+
if (this.cachedAccounts.length === 0) {
|
|
76
|
+
this.cachedAccounts = await this.getAccounts(data);
|
|
77
|
+
}
|
|
78
|
+
return this.cachedAccounts;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Sign out from the wallet
|
|
82
|
+
*/
|
|
83
|
+
async signOut(_data) {
|
|
84
|
+
if (typeof this.provider.disconnect === 'function') {
|
|
85
|
+
await this.provider.disconnect();
|
|
86
|
+
}
|
|
87
|
+
else if (typeof this.provider.signOut === 'function') {
|
|
88
|
+
await this.provider.signOut();
|
|
89
|
+
}
|
|
90
|
+
this.cachedAccounts = [];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get connected accounts
|
|
94
|
+
*/
|
|
95
|
+
async getAccounts(_data) {
|
|
96
|
+
// Try various account retrieval methods
|
|
97
|
+
if (typeof this.provider.getAccounts === 'function') {
|
|
98
|
+
const accounts = await this.provider.getAccounts();
|
|
99
|
+
this.cachedAccounts = this.normalizeAccounts(accounts);
|
|
100
|
+
}
|
|
101
|
+
else if (typeof this.provider.getAccountId === 'function') {
|
|
102
|
+
const accountId = await this.provider.getAccountId();
|
|
103
|
+
if (accountId) {
|
|
104
|
+
this.cachedAccounts = [{ accountId }];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else if (typeof this.provider.account === 'function') {
|
|
108
|
+
const account = await this.provider.account();
|
|
109
|
+
if (account?.accountId) {
|
|
110
|
+
this.cachedAccounts = [
|
|
111
|
+
{ accountId: account.accountId, publicKey: account.publicKey },
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else if (this.provider.accountId) {
|
|
116
|
+
this.cachedAccounts = [{ accountId: this.provider.accountId }];
|
|
117
|
+
}
|
|
118
|
+
return this.cachedAccounts;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Sign and send a single transaction
|
|
122
|
+
*/
|
|
123
|
+
async signAndSendTransaction(params) {
|
|
124
|
+
if (typeof this.provider.signAndSendTransaction === 'function') {
|
|
125
|
+
return await this.provider.signAndSendTransaction(params);
|
|
126
|
+
}
|
|
127
|
+
// Some wallets nest params differently
|
|
128
|
+
if (typeof this.provider.signAndSendTransaction === 'function') {
|
|
129
|
+
return await this.provider.signAndSendTransaction({
|
|
130
|
+
receiverId: params.receiverId,
|
|
131
|
+
actions: params.actions,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
throw new Error(`${this.manifest.name} does not support signAndSendTransaction`);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Sign and send multiple transactions
|
|
138
|
+
*/
|
|
139
|
+
async signAndSendTransactions(params) {
|
|
140
|
+
if (typeof this.provider.signAndSendTransactions === 'function') {
|
|
141
|
+
return await this.provider.signAndSendTransactions(params);
|
|
142
|
+
}
|
|
143
|
+
if (typeof this.provider.requestSignTransactions === 'function') {
|
|
144
|
+
return await this.provider.requestSignTransactions(params);
|
|
145
|
+
}
|
|
146
|
+
// Fall back to sequential signing
|
|
147
|
+
const results = [];
|
|
148
|
+
for (const tx of params.transactions) {
|
|
149
|
+
const result = await this.signAndSendTransaction({
|
|
150
|
+
...tx,
|
|
151
|
+
network: params.network,
|
|
152
|
+
signerId: params.signerId,
|
|
153
|
+
callbackUrl: params.callbackUrl,
|
|
154
|
+
});
|
|
155
|
+
results.push(result);
|
|
156
|
+
}
|
|
157
|
+
return results;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Sign a message (NEP-413)
|
|
161
|
+
*/
|
|
162
|
+
async signMessage(params) {
|
|
163
|
+
if (typeof this.provider.signMessage === 'function') {
|
|
164
|
+
return await this.provider.signMessage(params);
|
|
165
|
+
}
|
|
166
|
+
// Some wallets use verifyOwner for message signing
|
|
167
|
+
if (typeof this.provider.verifyOwner === 'function') {
|
|
168
|
+
const result = await this.provider.verifyOwner({
|
|
169
|
+
message: params.message,
|
|
170
|
+
});
|
|
171
|
+
return {
|
|
172
|
+
accountId: result.accountId,
|
|
173
|
+
publicKey: result.publicKey,
|
|
174
|
+
signature: result.signature,
|
|
175
|
+
message: params.message,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
throw new Error(`${this.manifest.name} does not support message signing`);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Check if connected
|
|
182
|
+
*/
|
|
183
|
+
async isConnected() {
|
|
184
|
+
if (typeof this.provider.isConnected === 'function') {
|
|
185
|
+
return await this.provider.isConnected();
|
|
186
|
+
}
|
|
187
|
+
if (typeof this.provider.isSignedIn === 'function') {
|
|
188
|
+
return await this.provider.isSignedIn();
|
|
189
|
+
}
|
|
190
|
+
return this.cachedAccounts.length > 0;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Normalize different account response formats to Account[]
|
|
194
|
+
*/
|
|
195
|
+
normalizeAccounts(response) {
|
|
196
|
+
if (!response)
|
|
197
|
+
return [];
|
|
198
|
+
// Array of accounts
|
|
199
|
+
if (Array.isArray(response)) {
|
|
200
|
+
return response.map((acc) => {
|
|
201
|
+
if (typeof acc === 'string') {
|
|
202
|
+
return { accountId: acc };
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
accountId: acc.accountId || acc.account_id || acc.id,
|
|
206
|
+
publicKey: acc.publicKey || acc.public_key,
|
|
207
|
+
};
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
// Single account object
|
|
211
|
+
if (typeof response === 'object') {
|
|
212
|
+
if (response.accountId || response.account_id) {
|
|
213
|
+
return [
|
|
214
|
+
{
|
|
215
|
+
accountId: response.accountId || response.account_id,
|
|
216
|
+
publicKey: response.publicKey || response.public_key,
|
|
217
|
+
},
|
|
218
|
+
];
|
|
219
|
+
}
|
|
220
|
+
// Accounts nested in response
|
|
221
|
+
if (response.accounts) {
|
|
222
|
+
return this.normalizeAccounts(response.accounts);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// Single account string
|
|
226
|
+
if (typeof response === 'string') {
|
|
227
|
+
return [{ accountId: response }];
|
|
228
|
+
}
|
|
229
|
+
return [];
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
exports.InjectedWalletAdapter = InjectedWalletAdapter;
|
|
233
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../../src/wallets/injected/adapter.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAiBH,MAAa,qBAAqB;IACvB,QAAQ,CAAiB;IAC1B,QAAQ,CAAM;IACd,cAAc,GAAc,EAAE,CAAC;IAEvC,YAAY,MAAsB;QAChC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAEhC,2CAA2C;QAC3C,IAAI,CAAC,QAAQ,GAAG;YACd,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE;YAClB,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI;YACtB,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI;YACtB,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO;YAC5B,WAAW,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,oBAAoB;YACpD,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE,OAAO;YAChB,QAAQ,EAAE,EAAE;YACZ,WAAW,EAAE;gBACX,OAAO,EAAE,IAAI;gBACb,QAAQ,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;aAC3B;YACD,QAAQ,EAAE;gBACR,WAAW,EAAE,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,KAAK,UAAU;gBAC5D,eAAe,EAAE,IAAI;gBACrB,sBAAsB,EACpB,OAAO,IAAI,CAAC,QAAQ,CAAC,sBAAsB,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CAAC;QAED,wBAAwB;QACxB,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACjC,IAAI,QAAQ,CAAC,SAAS,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC;gBAC9C,OAAO;oBACL;wBACE,SAAS,EAAE,QAAQ,CAAC,SAAS,IAAI,QAAQ,CAAC,UAAU;wBACpD,SAAS,EAAE,QAAQ,CAAC,SAAS,IAAI,QAAQ,CAAC,UAAU;qBACrD;iBACF,CAAC;YACJ,CAAC;YACD,8BAA8B;YAC9B,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;gBACtB,OAAO,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YACnD,CAAC;QACH,CAAC;QAED,wBAAwB;QACxB,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACjC,OAAO,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC;QACnC,CAAC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AArPD,sDAqPC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Injected Wallet Detector
|
|
3
|
+
*
|
|
4
|
+
* Hybrid detection that:
|
|
5
|
+
* 1. Listens for near-wallet-injected events (compliant wallets)
|
|
6
|
+
* 2. Probes known window globals (non-compliant wallets)
|
|
7
|
+
* 3. Retries detection for slow-loading extensions
|
|
8
|
+
*/
|
|
9
|
+
export interface InjectedWalletInfo {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
icon: string;
|
|
13
|
+
/** Primary global property to check */
|
|
14
|
+
globalKey: string;
|
|
15
|
+
/** Alternative keys (some wallets use multiple) */
|
|
16
|
+
altKeys?: string[];
|
|
17
|
+
/** Website URL */
|
|
18
|
+
website: string;
|
|
19
|
+
}
|
|
20
|
+
export interface DetectedWallet {
|
|
21
|
+
info: InjectedWalletInfo;
|
|
22
|
+
provider: unknown;
|
|
23
|
+
}
|
|
24
|
+
export type DetectionCallback = (wallets: DetectedWallet[]) => void;
|
|
25
|
+
export declare class InjectedWalletDetector {
|
|
26
|
+
private detected;
|
|
27
|
+
private listeners;
|
|
28
|
+
private isScanning;
|
|
29
|
+
private eventCleanup;
|
|
30
|
+
/**
|
|
31
|
+
* Start detection - combines event listening and global probing
|
|
32
|
+
*/
|
|
33
|
+
detect(timeout?: number): Promise<DetectedWallet[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Listen for wallets that use the event protocol
|
|
36
|
+
*/
|
|
37
|
+
private listenForWalletEvents;
|
|
38
|
+
/**
|
|
39
|
+
* Announce that we're ready to receive wallet injections
|
|
40
|
+
*/
|
|
41
|
+
private announceReady;
|
|
42
|
+
/**
|
|
43
|
+
* Directly probe window globals for known wallets
|
|
44
|
+
*/
|
|
45
|
+
private probeGlobals;
|
|
46
|
+
/**
|
|
47
|
+
* Find provider by checking global key and alternatives
|
|
48
|
+
*/
|
|
49
|
+
private findProvider;
|
|
50
|
+
/**
|
|
51
|
+
* Validate that this looks like a wallet provider
|
|
52
|
+
*/
|
|
53
|
+
private isValidProvider;
|
|
54
|
+
/**
|
|
55
|
+
* Probe with retries for slow-loading extensions
|
|
56
|
+
*/
|
|
57
|
+
private probeWithRetry;
|
|
58
|
+
/**
|
|
59
|
+
* Add a detected wallet
|
|
60
|
+
*/
|
|
61
|
+
private addDetected;
|
|
62
|
+
/**
|
|
63
|
+
* Subscribe to detection updates
|
|
64
|
+
*/
|
|
65
|
+
onDetected(callback: DetectionCallback): () => void;
|
|
66
|
+
/**
|
|
67
|
+
* Get specific wallet if detected
|
|
68
|
+
*/
|
|
69
|
+
getWallet(id: string): DetectedWallet | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Check if specific wallet is available
|
|
72
|
+
*/
|
|
73
|
+
isAvailable(id: string): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Get all detected wallets
|
|
76
|
+
*/
|
|
77
|
+
getAll(): DetectedWallet[];
|
|
78
|
+
/**
|
|
79
|
+
* Cleanup event listeners
|
|
80
|
+
*/
|
|
81
|
+
destroy(): void;
|
|
82
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Injected Wallet Detector
|
|
4
|
+
*
|
|
5
|
+
* Hybrid detection that:
|
|
6
|
+
* 1. Listens for near-wallet-injected events (compliant wallets)
|
|
7
|
+
* 2. Probes known window globals (non-compliant wallets)
|
|
8
|
+
* 3. Retries detection for slow-loading extensions
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.InjectedWalletDetector = void 0;
|
|
12
|
+
/** Known NEAR wallet extensions and their injection patterns */
|
|
13
|
+
const KNOWN_INJECTED_WALLETS = [
|
|
14
|
+
{
|
|
15
|
+
id: 'meteor-wallet',
|
|
16
|
+
name: 'Meteor Wallet',
|
|
17
|
+
icon: 'https://wallet.meteorwallet.app/assets/logo.svg',
|
|
18
|
+
globalKey: 'meteorWallet',
|
|
19
|
+
altKeys: ['near'],
|
|
20
|
+
website: 'https://wallet.meteorwallet.app',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: 'sender',
|
|
24
|
+
name: 'Sender Wallet',
|
|
25
|
+
icon: 'https://sender.org/logo.svg',
|
|
26
|
+
globalKey: 'near',
|
|
27
|
+
altKeys: ['sender'],
|
|
28
|
+
website: 'https://sender.org',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: 'here-wallet',
|
|
32
|
+
name: 'HERE Wallet',
|
|
33
|
+
icon: 'https://herewallet.app/logo.svg',
|
|
34
|
+
globalKey: 'here',
|
|
35
|
+
altKeys: ['hereWallet'],
|
|
36
|
+
website: 'https://herewallet.app',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: 'nightly',
|
|
40
|
+
name: 'Nightly Wallet',
|
|
41
|
+
icon: 'https://nightly.app/logo.svg',
|
|
42
|
+
globalKey: 'nightly',
|
|
43
|
+
altKeys: ['nightlyNear'],
|
|
44
|
+
website: 'https://nightly.app',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: 'mynearwallet',
|
|
48
|
+
name: 'MyNearWallet',
|
|
49
|
+
icon: 'https://mynearwallet.com/logo.svg',
|
|
50
|
+
globalKey: 'nearWallet',
|
|
51
|
+
website: 'https://mynearwallet.com',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
id: 'welldone',
|
|
55
|
+
name: 'WELLDONE Wallet',
|
|
56
|
+
icon: 'https://welldone.xyz/logo.svg',
|
|
57
|
+
globalKey: 'dapp',
|
|
58
|
+
website: 'https://welldone.xyz',
|
|
59
|
+
},
|
|
60
|
+
];
|
|
61
|
+
class InjectedWalletDetector {
|
|
62
|
+
detected = new Map();
|
|
63
|
+
listeners = new Set();
|
|
64
|
+
isScanning = false;
|
|
65
|
+
eventCleanup = null;
|
|
66
|
+
/**
|
|
67
|
+
* Start detection - combines event listening and global probing
|
|
68
|
+
*/
|
|
69
|
+
async detect(timeout = 2000) {
|
|
70
|
+
if (typeof window === 'undefined') {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
if (this.isScanning) {
|
|
74
|
+
return Array.from(this.detected.values());
|
|
75
|
+
}
|
|
76
|
+
this.isScanning = true;
|
|
77
|
+
// Method 1: Listen for compliant wallets via events
|
|
78
|
+
this.listenForWalletEvents();
|
|
79
|
+
// Method 2: Announce we're ready (triggers compliant wallets)
|
|
80
|
+
this.announceReady();
|
|
81
|
+
// Method 3: Probe globals immediately
|
|
82
|
+
this.probeGlobals();
|
|
83
|
+
// Method 4: Probe again with retries (for slow extensions)
|
|
84
|
+
await this.probeWithRetry(timeout);
|
|
85
|
+
this.isScanning = false;
|
|
86
|
+
return Array.from(this.detected.values());
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Listen for wallets that use the event protocol
|
|
90
|
+
*/
|
|
91
|
+
listenForWalletEvents() {
|
|
92
|
+
const handler = ((event) => {
|
|
93
|
+
const detail = event.detail;
|
|
94
|
+
if (detail?.id && detail?.provider) {
|
|
95
|
+
// Find matching known wallet or create generic entry
|
|
96
|
+
const knownWallet = KNOWN_INJECTED_WALLETS.find((w) => w.id === detail.id);
|
|
97
|
+
const walletInfo = knownWallet || {
|
|
98
|
+
id: detail.id,
|
|
99
|
+
name: detail.name || detail.id,
|
|
100
|
+
icon: detail.icon || '',
|
|
101
|
+
globalKey: detail.id,
|
|
102
|
+
website: detail.website || '',
|
|
103
|
+
};
|
|
104
|
+
this.addDetected(walletInfo, detail.provider);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
window.addEventListener('near-wallet-injected', handler);
|
|
108
|
+
this.eventCleanup = () => {
|
|
109
|
+
window.removeEventListener('near-wallet-injected', handler);
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Announce that we're ready to receive wallet injections
|
|
114
|
+
*/
|
|
115
|
+
announceReady() {
|
|
116
|
+
// Different wallets listen for different event names
|
|
117
|
+
window.dispatchEvent(new CustomEvent('near-selector-ready'));
|
|
118
|
+
window.dispatchEvent(new CustomEvent('near-wallet-selector-ready'));
|
|
119
|
+
window.dispatchEvent(new CustomEvent('near:ready'));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Directly probe window globals for known wallets
|
|
123
|
+
*/
|
|
124
|
+
probeGlobals() {
|
|
125
|
+
for (const wallet of KNOWN_INJECTED_WALLETS) {
|
|
126
|
+
// Skip if already detected
|
|
127
|
+
if (this.detected.has(wallet.id))
|
|
128
|
+
continue;
|
|
129
|
+
const provider = this.findProvider(wallet);
|
|
130
|
+
if (provider) {
|
|
131
|
+
this.addDetected(wallet, provider);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Find provider by checking global key and alternatives
|
|
137
|
+
*/
|
|
138
|
+
findProvider(wallet) {
|
|
139
|
+
const win = window;
|
|
140
|
+
// Check primary key
|
|
141
|
+
if (win[wallet.globalKey] && this.isValidProvider(win[wallet.globalKey])) {
|
|
142
|
+
return win[wallet.globalKey];
|
|
143
|
+
}
|
|
144
|
+
// Check alternative keys
|
|
145
|
+
if (wallet.altKeys) {
|
|
146
|
+
for (const key of wallet.altKeys) {
|
|
147
|
+
if (win[key] && this.isValidProvider(win[key])) {
|
|
148
|
+
return win[key];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Validate that this looks like a wallet provider
|
|
156
|
+
*/
|
|
157
|
+
isValidProvider(obj) {
|
|
158
|
+
if (!obj || typeof obj !== 'object')
|
|
159
|
+
return false;
|
|
160
|
+
const provider = obj;
|
|
161
|
+
// Most wallet providers have at least one of these methods
|
|
162
|
+
return (typeof provider.connect === 'function' ||
|
|
163
|
+
typeof provider.signIn === 'function' ||
|
|
164
|
+
typeof provider.requestSignIn === 'function' ||
|
|
165
|
+
typeof provider.signAndSendTransaction === 'function' ||
|
|
166
|
+
typeof provider.isConnected === 'function' ||
|
|
167
|
+
typeof provider.enable === 'function');
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Probe with retries for slow-loading extensions
|
|
171
|
+
*/
|
|
172
|
+
async probeWithRetry(timeout) {
|
|
173
|
+
const intervals = [100, 250, 500, 1000];
|
|
174
|
+
let elapsed = 0;
|
|
175
|
+
for (const interval of intervals) {
|
|
176
|
+
if (elapsed >= timeout)
|
|
177
|
+
break;
|
|
178
|
+
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
179
|
+
elapsed += interval;
|
|
180
|
+
this.probeGlobals();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Add a detected wallet
|
|
185
|
+
*/
|
|
186
|
+
addDetected(info, provider) {
|
|
187
|
+
if (this.detected.has(info.id))
|
|
188
|
+
return;
|
|
189
|
+
const detected = { info, provider };
|
|
190
|
+
this.detected.set(info.id, detected);
|
|
191
|
+
console.log(`[NearConnect] Detected injected wallet: ${info.name}`);
|
|
192
|
+
// Notify listeners
|
|
193
|
+
this.listeners.forEach((cb) => cb(Array.from(this.detected.values())));
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Subscribe to detection updates
|
|
197
|
+
*/
|
|
198
|
+
onDetected(callback) {
|
|
199
|
+
this.listeners.add(callback);
|
|
200
|
+
// Immediately call with current detections
|
|
201
|
+
if (this.detected.size > 0) {
|
|
202
|
+
callback(Array.from(this.detected.values()));
|
|
203
|
+
}
|
|
204
|
+
return () => this.listeners.delete(callback);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Get specific wallet if detected
|
|
208
|
+
*/
|
|
209
|
+
getWallet(id) {
|
|
210
|
+
return this.detected.get(id);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Check if specific wallet is available
|
|
214
|
+
*/
|
|
215
|
+
isAvailable(id) {
|
|
216
|
+
return this.detected.has(id);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Get all detected wallets
|
|
220
|
+
*/
|
|
221
|
+
getAll() {
|
|
222
|
+
return Array.from(this.detected.values());
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Cleanup event listeners
|
|
226
|
+
*/
|
|
227
|
+
destroy() {
|
|
228
|
+
if (this.eventCleanup) {
|
|
229
|
+
this.eventCleanup();
|
|
230
|
+
this.eventCleanup = null;
|
|
231
|
+
}
|
|
232
|
+
this.listeners.clear();
|
|
233
|
+
this.detected.clear();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
exports.InjectedWalletDetector = InjectedWalletDetector;
|
|
237
|
+
//# sourceMappingURL=detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detector.js","sourceRoot":"","sources":["../../../src/wallets/injected/detector.ts"],"names":[],"mappings":";AAAA;;;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,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,IAAI,CAAC,YAAY,EAAE,CAAC;YACpB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QAC3B,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACvB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CACF;AArND,wDAqNC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Injected Wallet Module
|
|
3
|
+
*
|
|
4
|
+
* Exports for browser extension wallet detection and management.
|
|
5
|
+
*/
|
|
6
|
+
export { InjectedWalletDetector } from './detector';
|
|
7
|
+
export type { InjectedWalletInfo, DetectedWallet, DetectionCallback } from './detector';
|
|
8
|
+
export { InjectedWalletAdapter } from './adapter';
|
|
9
|
+
export { InjectedWalletManager } from './manager';
|
|
10
|
+
export type { InjectedWalletManagerConfig } from './manager';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Injected Wallet Module
|
|
4
|
+
*
|
|
5
|
+
* Exports for browser extension wallet detection and management.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.InjectedWalletManager = exports.InjectedWalletAdapter = exports.InjectedWalletDetector = void 0;
|
|
9
|
+
var detector_1 = require("./detector");
|
|
10
|
+
Object.defineProperty(exports, "InjectedWalletDetector", { enumerable: true, get: function () { return detector_1.InjectedWalletDetector; } });
|
|
11
|
+
var adapter_1 = require("./adapter");
|
|
12
|
+
Object.defineProperty(exports, "InjectedWalletAdapter", { enumerable: true, get: function () { return adapter_1.InjectedWalletAdapter; } });
|
|
13
|
+
var manager_1 = require("./manager");
|
|
14
|
+
Object.defineProperty(exports, "InjectedWalletManager", { enumerable: true, get: function () { return manager_1.InjectedWalletManager; } });
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/wallets/injected/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,uCAAoD;AAA3C,kHAAA,sBAAsB,OAAA;AAG/B,qCAAkD;AAAzC,gHAAA,qBAAqB,OAAA;AAE9B,qCAAkD;AAAzC,gHAAA,qBAAqB,OAAA"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Injected Wallet Manager
|
|
3
|
+
*
|
|
4
|
+
* Manages detection and interaction with browser extension wallets.
|
|
5
|
+
*/
|
|
6
|
+
import type { NearWalletBase } from '../../types';
|
|
7
|
+
export interface InjectedWalletManagerConfig {
|
|
8
|
+
/** Detection timeout in ms (default: 2000) */
|
|
9
|
+
detectionTimeout?: number;
|
|
10
|
+
/** Callback when wallets are detected */
|
|
11
|
+
onDetected?: (wallets: NearWalletBase[]) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare class InjectedWalletManager {
|
|
14
|
+
private detector;
|
|
15
|
+
private adapters;
|
|
16
|
+
private config;
|
|
17
|
+
private initialized;
|
|
18
|
+
constructor(config?: InjectedWalletManagerConfig);
|
|
19
|
+
/**
|
|
20
|
+
* Initialize detection
|
|
21
|
+
*/
|
|
22
|
+
init(): Promise<NearWalletBase[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Add an adapter for a detected wallet
|
|
25
|
+
*/
|
|
26
|
+
private addAdapter;
|
|
27
|
+
/**
|
|
28
|
+
* Get all detected wallets as NearWalletBase
|
|
29
|
+
*/
|
|
30
|
+
getWallets(): NearWalletBase[];
|
|
31
|
+
/**
|
|
32
|
+
* Get a specific wallet by ID
|
|
33
|
+
*/
|
|
34
|
+
getWallet(walletId: string): NearWalletBase | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Check if wallet ID is an injected wallet
|
|
37
|
+
*/
|
|
38
|
+
isInjectedWallet(walletId: string): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Check if any injected wallets were detected
|
|
41
|
+
*/
|
|
42
|
+
hasWallets(): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Get count of detected wallets
|
|
45
|
+
*/
|
|
46
|
+
get count(): number;
|
|
47
|
+
/**
|
|
48
|
+
* Cleanup
|
|
49
|
+
*/
|
|
50
|
+
destroy(): void;
|
|
51
|
+
}
|