@phantom/embedded-provider-core 1.0.2 → 1.0.3
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/dist/index.d.mts +4 -8
- package/dist/index.d.ts +4 -8
- package/dist/index.js +21 -44
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +21 -44
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
package/dist/index.mjs
CHANGED
|
@@ -24,21 +24,19 @@ var EmbeddedSolanaChain = class {
|
|
|
24
24
|
constructor(provider) {
|
|
25
25
|
this.provider = provider;
|
|
26
26
|
this.currentNetworkId = NetworkId.SOLANA_MAINNET;
|
|
27
|
-
this._connected = false;
|
|
28
27
|
this._publicKey = null;
|
|
29
28
|
this.eventEmitter = new EventEmitter();
|
|
30
29
|
this.setupEventListeners();
|
|
31
30
|
this.syncInitialState();
|
|
32
31
|
}
|
|
33
|
-
// Wallet adapter compliant properties
|
|
34
|
-
get connected() {
|
|
35
|
-
return this._connected;
|
|
36
|
-
}
|
|
37
32
|
get publicKey() {
|
|
38
33
|
return this._publicKey;
|
|
39
34
|
}
|
|
35
|
+
get isConnected() {
|
|
36
|
+
return this._publicKey !== null;
|
|
37
|
+
}
|
|
40
38
|
ensureConnected() {
|
|
41
|
-
if (!this.
|
|
39
|
+
if (!this.isConnected) {
|
|
42
40
|
throw new Error("Solana chain not available. Ensure SDK is connected.");
|
|
43
41
|
}
|
|
44
42
|
}
|
|
@@ -96,7 +94,7 @@ var EmbeddedSolanaChain = class {
|
|
|
96
94
|
const solanaAddr = addresses.find((a) => a.addressType === "Solana");
|
|
97
95
|
if (!solanaAddr)
|
|
98
96
|
throw new Error("No Solana address found");
|
|
99
|
-
this.
|
|
97
|
+
this._publicKey = solanaAddr.address;
|
|
100
98
|
return Promise.resolve({ publicKey: solanaAddr.address });
|
|
101
99
|
}
|
|
102
100
|
async disconnect() {
|
|
@@ -106,41 +104,25 @@ var EmbeddedSolanaChain = class {
|
|
|
106
104
|
this.currentNetworkId = network === "mainnet" ? NetworkId.SOLANA_MAINNET : NetworkId.SOLANA_DEVNET;
|
|
107
105
|
return Promise.resolve();
|
|
108
106
|
}
|
|
109
|
-
getPublicKey() {
|
|
110
|
-
if (!this.provider.isConnected())
|
|
111
|
-
return Promise.resolve(null);
|
|
112
|
-
const addresses = this.provider.getAddresses();
|
|
113
|
-
const solanaAddr = addresses.find((a) => a.addressType === "Solana");
|
|
114
|
-
return Promise.resolve(solanaAddr?.address || null);
|
|
115
|
-
}
|
|
116
|
-
isConnected() {
|
|
117
|
-
return this._connected && this.provider.isConnected();
|
|
118
|
-
}
|
|
119
107
|
setupEventListeners() {
|
|
120
108
|
this.provider.on("connect", (data) => {
|
|
121
109
|
const solanaAddress = data.addresses?.find((addr) => addr.addressType === "Solana");
|
|
122
110
|
if (solanaAddress) {
|
|
123
|
-
this.
|
|
111
|
+
this._publicKey = solanaAddress.address;
|
|
124
112
|
this.eventEmitter.emit("connect", solanaAddress.address);
|
|
125
113
|
}
|
|
126
114
|
});
|
|
127
115
|
this.provider.on("disconnect", () => {
|
|
128
|
-
this.
|
|
116
|
+
this._publicKey = null;
|
|
129
117
|
this.eventEmitter.emit("disconnect");
|
|
130
118
|
});
|
|
131
119
|
}
|
|
132
120
|
syncInitialState() {
|
|
133
|
-
if (this.provider.isConnected())
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
updateConnectionState(connected, publicKey) {
|
|
142
|
-
this._connected = connected;
|
|
143
|
-
this._publicKey = publicKey;
|
|
121
|
+
if (!this.provider.isConnected())
|
|
122
|
+
return;
|
|
123
|
+
const addresses = this.provider.getAddresses();
|
|
124
|
+
const solanaAddr = addresses.find((a) => a.addressType === "Solana");
|
|
125
|
+
this._publicKey = solanaAddr?.address || null;
|
|
144
126
|
}
|
|
145
127
|
// Event methods for interface compliance
|
|
146
128
|
on(event, listener) {
|
|
@@ -158,16 +140,11 @@ var EmbeddedEthereumChain = class {
|
|
|
158
140
|
constructor(provider) {
|
|
159
141
|
this.provider = provider;
|
|
160
142
|
this.currentNetworkId = NetworkId2.ETHEREUM_MAINNET;
|
|
161
|
-
this._connected = false;
|
|
162
143
|
this._accounts = [];
|
|
163
144
|
this.eventEmitter = new EventEmitter2();
|
|
164
145
|
this.setupEventListeners();
|
|
165
146
|
this.syncInitialState();
|
|
166
147
|
}
|
|
167
|
-
// EIP-1193 compliant properties
|
|
168
|
-
get connected() {
|
|
169
|
-
return this._connected;
|
|
170
|
-
}
|
|
171
148
|
get chainId() {
|
|
172
149
|
const chainId = networkIdToChainId(this.currentNetworkId) || 1;
|
|
173
150
|
return `0x${chainId.toString(16)}`;
|
|
@@ -191,7 +168,7 @@ var EmbeddedEthereumChain = class {
|
|
|
191
168
|
}
|
|
192
169
|
const addresses = this.provider.getAddresses();
|
|
193
170
|
const ethAddresses = addresses.filter((a) => a.addressType === "Ethereum").map((a) => a.address);
|
|
194
|
-
this.updateConnectionState(
|
|
171
|
+
this.updateConnectionState(ethAddresses);
|
|
195
172
|
return Promise.resolve(ethAddresses);
|
|
196
173
|
}
|
|
197
174
|
async disconnect() {
|
|
@@ -257,19 +234,19 @@ var EmbeddedEthereumChain = class {
|
|
|
257
234
|
return this.request({ method: "eth_accounts" });
|
|
258
235
|
}
|
|
259
236
|
isConnected() {
|
|
260
|
-
return this.
|
|
237
|
+
return this.provider.isConnected() && this._accounts.length > 0;
|
|
261
238
|
}
|
|
262
239
|
setupEventListeners() {
|
|
263
240
|
this.provider.on("connect", (data) => {
|
|
264
241
|
const ethAddresses = data.addresses?.filter((addr) => addr.addressType === "Ethereum")?.map((addr) => addr.address) || [];
|
|
265
242
|
if (ethAddresses.length > 0) {
|
|
266
|
-
this.updateConnectionState(
|
|
243
|
+
this.updateConnectionState(ethAddresses);
|
|
267
244
|
this.eventEmitter.emit("connect", { chainId: this.chainId });
|
|
268
245
|
this.eventEmitter.emit("accountsChanged", ethAddresses);
|
|
269
246
|
}
|
|
270
247
|
});
|
|
271
248
|
this.provider.on("disconnect", () => {
|
|
272
|
-
this.updateConnectionState(
|
|
249
|
+
this.updateConnectionState([]);
|
|
273
250
|
this.eventEmitter.emit("disconnect", { code: 4900, message: "Provider disconnected" });
|
|
274
251
|
this.eventEmitter.emit("accountsChanged", []);
|
|
275
252
|
});
|
|
@@ -279,12 +256,11 @@ var EmbeddedEthereumChain = class {
|
|
|
279
256
|
const addresses = this.provider.getAddresses();
|
|
280
257
|
const ethAddresses = addresses.filter((a) => a.addressType === "Ethereum").map((a) => a.address);
|
|
281
258
|
if (ethAddresses.length > 0) {
|
|
282
|
-
this.updateConnectionState(
|
|
259
|
+
this.updateConnectionState(ethAddresses);
|
|
283
260
|
}
|
|
284
261
|
}
|
|
285
262
|
}
|
|
286
|
-
updateConnectionState(
|
|
287
|
-
this._connected = connected;
|
|
263
|
+
updateConnectionState(accounts) {
|
|
288
264
|
this._accounts = accounts;
|
|
289
265
|
}
|
|
290
266
|
async handleEmbeddedRequest(args) {
|
|
@@ -748,7 +724,7 @@ var EmbeddedProvider = class {
|
|
|
748
724
|
authenticatorName: `auth-${shortPubKey}`,
|
|
749
725
|
authenticatorKind: "keypair",
|
|
750
726
|
publicKey: base64urlPublicKey,
|
|
751
|
-
algorithm:
|
|
727
|
+
algorithm: this.stamper.algorithm,
|
|
752
728
|
expiresInMs
|
|
753
729
|
}
|
|
754
730
|
]
|
|
@@ -1204,8 +1180,9 @@ var EmbeddedProvider = class {
|
|
|
1204
1180
|
// OAuth session management - defaults to allowing refresh unless user explicitly logged out
|
|
1205
1181
|
clearPreviousSession: shouldClearPreviousSession,
|
|
1206
1182
|
// true only after logout
|
|
1207
|
-
allowRefresh: !shouldClearPreviousSession
|
|
1183
|
+
allowRefresh: !shouldClearPreviousSession,
|
|
1208
1184
|
// false only after logout
|
|
1185
|
+
algorithm: this.stamper.algorithm
|
|
1209
1186
|
});
|
|
1210
1187
|
if (authResult && "walletId" in authResult) {
|
|
1211
1188
|
this.logger.info("EMBEDDED_PROVIDER", "Authentication completed after redirect", {
|