@phantom/embedded-provider-core 1.0.0-beta.1 → 1.0.0-beta.2
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 +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +74 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
package/dist/index.d.mts
CHANGED
|
@@ -115,6 +115,10 @@ interface SignMessageParams {
|
|
|
115
115
|
}
|
|
116
116
|
interface SignMessageResult extends ParsedSignatureResult {
|
|
117
117
|
}
|
|
118
|
+
interface SignTransactionParams {
|
|
119
|
+
transaction: any;
|
|
120
|
+
networkId: NetworkId;
|
|
121
|
+
}
|
|
118
122
|
interface SignAndSendTransactionParams {
|
|
119
123
|
transaction: any;
|
|
120
124
|
networkId: NetworkId;
|
|
@@ -170,6 +174,7 @@ declare class EmbeddedProvider {
|
|
|
170
174
|
connect(authOptions?: AuthOptions): Promise<ConnectResult>;
|
|
171
175
|
disconnect(): Promise<void>;
|
|
172
176
|
signMessage(params: SignMessageParams): Promise<ParsedSignatureResult>;
|
|
177
|
+
signTransaction(params: SignTransactionParams): Promise<ParsedTransactionResult>;
|
|
173
178
|
signAndSendTransaction(params: SignAndSendTransactionParams): Promise<ParsedTransactionResult>;
|
|
174
179
|
getAddresses(): WalletAddress[];
|
|
175
180
|
isConnected(): boolean;
|
|
@@ -207,7 +212,7 @@ declare class EmbeddedSolanaChain implements ISolanaChain {
|
|
|
207
212
|
signature: Uint8Array;
|
|
208
213
|
publicKey: string;
|
|
209
214
|
}>;
|
|
210
|
-
signTransaction<T>(
|
|
215
|
+
signTransaction<T>(transaction: T): Promise<T>;
|
|
211
216
|
signAndSendTransaction<T>(transaction: T): Promise<{
|
|
212
217
|
signature: string;
|
|
213
218
|
}>;
|
|
@@ -250,6 +255,7 @@ declare class EmbeddedEthereumChain implements IEthereumChain {
|
|
|
250
255
|
disconnect(): Promise<void>;
|
|
251
256
|
signPersonalMessage(message: string, address: string): Promise<string>;
|
|
252
257
|
signTypedData(typedData: any, address: string): Promise<string>;
|
|
258
|
+
signTransaction(transaction: EthTransactionRequest): Promise<string>;
|
|
253
259
|
sendTransaction(transaction: EthTransactionRequest): Promise<string>;
|
|
254
260
|
switchChain(chainId: number): Promise<void>;
|
|
255
261
|
getChainId(): Promise<number>;
|
|
@@ -279,4 +285,4 @@ declare const AUTHENTICATOR_EXPIRATION_TIME_MS: number;
|
|
|
279
285
|
*/
|
|
280
286
|
declare const AUTHENTICATOR_RENEWAL_WINDOW_MS: number;
|
|
281
287
|
|
|
282
|
-
export { AUTHENTICATOR_EXPIRATION_TIME_MS, AUTHENTICATOR_RENEWAL_WINDOW_MS, AuthOptions, AuthProvider, AuthResult, ConnectResult, DebugLogger, EmbeddedEthereumChain, EmbeddedProvider, EmbeddedProviderConfig, EmbeddedProviderEvent, EmbeddedSolanaChain, EmbeddedStorage, EventCallback, JWTAuth, JWTAuthOptions, Keypair, PhantomConnectOptions, PlatformAdapter, Session, SignAndSendTransactionParams, SignMessageParams, SignMessageResult, SignedTransaction, StamperInfo, URLParamsAccessor, WalletAddress, generateSessionId, retryWithBackoff };
|
|
288
|
+
export { AUTHENTICATOR_EXPIRATION_TIME_MS, AUTHENTICATOR_RENEWAL_WINDOW_MS, AuthOptions, AuthProvider, AuthResult, ConnectResult, DebugLogger, EmbeddedEthereumChain, EmbeddedProvider, EmbeddedProviderConfig, EmbeddedProviderEvent, EmbeddedSolanaChain, EmbeddedStorage, EventCallback, JWTAuth, JWTAuthOptions, Keypair, PhantomConnectOptions, PlatformAdapter, Session, SignAndSendTransactionParams, SignMessageParams, SignMessageResult, SignTransactionParams, SignedTransaction, StamperInfo, URLParamsAccessor, WalletAddress, generateSessionId, retryWithBackoff };
|
package/dist/index.d.ts
CHANGED
|
@@ -115,6 +115,10 @@ interface SignMessageParams {
|
|
|
115
115
|
}
|
|
116
116
|
interface SignMessageResult extends ParsedSignatureResult {
|
|
117
117
|
}
|
|
118
|
+
interface SignTransactionParams {
|
|
119
|
+
transaction: any;
|
|
120
|
+
networkId: NetworkId;
|
|
121
|
+
}
|
|
118
122
|
interface SignAndSendTransactionParams {
|
|
119
123
|
transaction: any;
|
|
120
124
|
networkId: NetworkId;
|
|
@@ -170,6 +174,7 @@ declare class EmbeddedProvider {
|
|
|
170
174
|
connect(authOptions?: AuthOptions): Promise<ConnectResult>;
|
|
171
175
|
disconnect(): Promise<void>;
|
|
172
176
|
signMessage(params: SignMessageParams): Promise<ParsedSignatureResult>;
|
|
177
|
+
signTransaction(params: SignTransactionParams): Promise<ParsedTransactionResult>;
|
|
173
178
|
signAndSendTransaction(params: SignAndSendTransactionParams): Promise<ParsedTransactionResult>;
|
|
174
179
|
getAddresses(): WalletAddress[];
|
|
175
180
|
isConnected(): boolean;
|
|
@@ -207,7 +212,7 @@ declare class EmbeddedSolanaChain implements ISolanaChain {
|
|
|
207
212
|
signature: Uint8Array;
|
|
208
213
|
publicKey: string;
|
|
209
214
|
}>;
|
|
210
|
-
signTransaction<T>(
|
|
215
|
+
signTransaction<T>(transaction: T): Promise<T>;
|
|
211
216
|
signAndSendTransaction<T>(transaction: T): Promise<{
|
|
212
217
|
signature: string;
|
|
213
218
|
}>;
|
|
@@ -250,6 +255,7 @@ declare class EmbeddedEthereumChain implements IEthereumChain {
|
|
|
250
255
|
disconnect(): Promise<void>;
|
|
251
256
|
signPersonalMessage(message: string, address: string): Promise<string>;
|
|
252
257
|
signTypedData(typedData: any, address: string): Promise<string>;
|
|
258
|
+
signTransaction(transaction: EthTransactionRequest): Promise<string>;
|
|
253
259
|
sendTransaction(transaction: EthTransactionRequest): Promise<string>;
|
|
254
260
|
switchChain(chainId: number): Promise<void>;
|
|
255
261
|
getChainId(): Promise<number>;
|
|
@@ -279,4 +285,4 @@ declare const AUTHENTICATOR_EXPIRATION_TIME_MS: number;
|
|
|
279
285
|
*/
|
|
280
286
|
declare const AUTHENTICATOR_RENEWAL_WINDOW_MS: number;
|
|
281
287
|
|
|
282
|
-
export { AUTHENTICATOR_EXPIRATION_TIME_MS, AUTHENTICATOR_RENEWAL_WINDOW_MS, AuthOptions, AuthProvider, AuthResult, ConnectResult, DebugLogger, EmbeddedEthereumChain, EmbeddedProvider, EmbeddedProviderConfig, EmbeddedProviderEvent, EmbeddedSolanaChain, EmbeddedStorage, EventCallback, JWTAuth, JWTAuthOptions, Keypair, PhantomConnectOptions, PlatformAdapter, Session, SignAndSendTransactionParams, SignMessageParams, SignMessageResult, SignedTransaction, StamperInfo, URLParamsAccessor, WalletAddress, generateSessionId, retryWithBackoff };
|
|
288
|
+
export { AUTHENTICATOR_EXPIRATION_TIME_MS, AUTHENTICATOR_RENEWAL_WINDOW_MS, AuthOptions, AuthProvider, AuthResult, ConnectResult, DebugLogger, EmbeddedEthereumChain, EmbeddedProvider, EmbeddedProviderConfig, EmbeddedProviderEvent, EmbeddedSolanaChain, EmbeddedStorage, EventCallback, JWTAuth, JWTAuthOptions, Keypair, PhantomConnectOptions, PlatformAdapter, Session, SignAndSendTransactionParams, SignMessageParams, SignMessageResult, SignTransactionParams, SignedTransaction, StamperInfo, URLParamsAccessor, WalletAddress, generateSessionId, retryWithBackoff };
|
package/dist/index.js
CHANGED
|
@@ -43,9 +43,9 @@ module.exports = __toCommonJS(src_exports);
|
|
|
43
43
|
|
|
44
44
|
// src/embedded-provider.ts
|
|
45
45
|
var import_client = require("@phantom/client");
|
|
46
|
-
var
|
|
47
|
-
var
|
|
48
|
-
var
|
|
46
|
+
var import_base64url2 = require("@phantom/base64url");
|
|
47
|
+
var import_bs582 = __toESM(require("bs58"));
|
|
48
|
+
var import_parsers2 = require("@phantom/parsers");
|
|
49
49
|
|
|
50
50
|
// src/constants.ts
|
|
51
51
|
var AUTHENTICATOR_EXPIRATION_TIME_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
@@ -171,7 +171,8 @@ async function retryWithBackoff(operation, operationName, logger, maxRetries = 3
|
|
|
171
171
|
// src/chains/SolanaChain.ts
|
|
172
172
|
var import_eventemitter3 = require("eventemitter3");
|
|
173
173
|
var import_constants = require("@phantom/constants");
|
|
174
|
-
var
|
|
174
|
+
var import_bs58 = __toESM(require("bs58"));
|
|
175
|
+
var import_parsers = require("@phantom/parsers");
|
|
175
176
|
var EmbeddedSolanaChain = class {
|
|
176
177
|
constructor(provider) {
|
|
177
178
|
this.provider = provider;
|
|
@@ -202,15 +203,20 @@ var EmbeddedSolanaChain = class {
|
|
|
202
203
|
message: messageStr,
|
|
203
204
|
networkId: this.currentNetworkId
|
|
204
205
|
});
|
|
205
|
-
const signature = typeof result.signature === "string" ? new Uint8Array(
|
|
206
|
+
const signature = typeof result.signature === "string" ? new Uint8Array(import_bs58.default.decode(result.signature)) : result.signature;
|
|
206
207
|
return {
|
|
207
208
|
signature,
|
|
208
209
|
publicKey: this._publicKey || ""
|
|
209
210
|
};
|
|
210
211
|
}
|
|
211
|
-
signTransaction(
|
|
212
|
+
async signTransaction(transaction) {
|
|
212
213
|
this.ensureConnected();
|
|
213
|
-
|
|
214
|
+
const result = await this.provider.signTransaction({
|
|
215
|
+
transaction,
|
|
216
|
+
networkId: this.currentNetworkId
|
|
217
|
+
});
|
|
218
|
+
const signatureResult = (0, import_parsers.parseSolanaTransactionSignature)(result.rawTransaction);
|
|
219
|
+
return signatureResult.signature;
|
|
214
220
|
}
|
|
215
221
|
async signAndSendTransaction(transaction) {
|
|
216
222
|
this.ensureConnected();
|
|
@@ -293,6 +299,8 @@ var EmbeddedSolanaChain = class {
|
|
|
293
299
|
// src/chains/EthereumChain.ts
|
|
294
300
|
var import_eventemitter32 = require("eventemitter3");
|
|
295
301
|
var import_constants2 = require("@phantom/constants");
|
|
302
|
+
var import_base64url = require("@phantom/base64url");
|
|
303
|
+
var import_buffer = require("buffer");
|
|
296
304
|
var EmbeddedEthereumChain = class {
|
|
297
305
|
constructor(provider) {
|
|
298
306
|
this.provider = provider;
|
|
@@ -349,6 +357,18 @@ var EmbeddedEthereumChain = class {
|
|
|
349
357
|
params: [address, JSON.stringify(typedData)]
|
|
350
358
|
});
|
|
351
359
|
}
|
|
360
|
+
async signTransaction(transaction) {
|
|
361
|
+
const result = await this.provider.signTransaction({
|
|
362
|
+
transaction,
|
|
363
|
+
networkId: this.currentNetworkId
|
|
364
|
+
});
|
|
365
|
+
try {
|
|
366
|
+
const signatureBytes = (0, import_base64url.base64urlDecode)(result.rawTransaction);
|
|
367
|
+
return "0x" + import_buffer.Buffer.from(signatureBytes).toString("hex");
|
|
368
|
+
} catch (error) {
|
|
369
|
+
return result.rawTransaction.startsWith("0x") ? result.rawTransaction : "0x" + result.rawTransaction;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
352
372
|
async sendTransaction(transaction) {
|
|
353
373
|
const result = await this.provider.signAndSendTransaction({
|
|
354
374
|
transaction,
|
|
@@ -426,6 +446,17 @@ var EmbeddedEthereumChain = class {
|
|
|
426
446
|
});
|
|
427
447
|
return typedDataResult.signature;
|
|
428
448
|
}
|
|
449
|
+
case "eth_signTransaction": {
|
|
450
|
+
const [transaction] = args.params;
|
|
451
|
+
const networkIdFromTx = transaction.chainId ? (0, import_constants2.chainIdToNetworkId)(
|
|
452
|
+
typeof transaction.chainId === "number" ? transaction.chainId : parseInt(transaction.chainId, 16)
|
|
453
|
+
) : null;
|
|
454
|
+
const signResult = await this.provider.signTransaction({
|
|
455
|
+
transaction,
|
|
456
|
+
networkId: networkIdFromTx || this.currentNetworkId
|
|
457
|
+
});
|
|
458
|
+
return signResult.rawTransaction;
|
|
459
|
+
}
|
|
429
460
|
case "eth_sendTransaction": {
|
|
430
461
|
const [transaction] = args.params;
|
|
431
462
|
const networkIdFromTx = transaction.chainId ? (0, import_constants2.chainIdToNetworkId)(
|
|
@@ -759,7 +790,7 @@ var EmbeddedProvider = class {
|
|
|
759
790
|
publicKey: stamperInfo.publicKey,
|
|
760
791
|
platform: platformName
|
|
761
792
|
});
|
|
762
|
-
const base64urlPublicKey = (0,
|
|
793
|
+
const base64urlPublicKey = (0, import_base64url2.base64urlEncode)(import_bs582.default.decode(stamperInfo.publicKey));
|
|
763
794
|
const expiresAtMs = Date.now() + AUTHENTICATOR_EXPIRATION_TIME_MS;
|
|
764
795
|
const username = `user-${shortPubKey}`;
|
|
765
796
|
const { organizationId } = await tempClient.createOrganization(organizationName, [
|
|
@@ -892,7 +923,7 @@ var EmbeddedProvider = class {
|
|
|
892
923
|
walletId: this.walletId,
|
|
893
924
|
message: params.message
|
|
894
925
|
});
|
|
895
|
-
const parsedMessage = (0,
|
|
926
|
+
const parsedMessage = (0, import_parsers2.parseMessage)(params.message);
|
|
896
927
|
const session = await this.storage.getSession();
|
|
897
928
|
const derivationIndex = session?.accountDerivationIndex ?? 0;
|
|
898
929
|
const rawResponse = await this.client.signMessage({
|
|
@@ -905,7 +936,37 @@ var EmbeddedProvider = class {
|
|
|
905
936
|
walletId: this.walletId,
|
|
906
937
|
message: params.message
|
|
907
938
|
});
|
|
908
|
-
return (0,
|
|
939
|
+
return (0, import_parsers2.parseSignMessageResponse)(rawResponse, params.networkId);
|
|
940
|
+
}
|
|
941
|
+
async signTransaction(params) {
|
|
942
|
+
if (!this.client || !this.walletId) {
|
|
943
|
+
throw new Error("Not connected");
|
|
944
|
+
}
|
|
945
|
+
await this.ensureValidAuthenticator();
|
|
946
|
+
this.logger.info("EMBEDDED_PROVIDER", "Signing transaction", {
|
|
947
|
+
walletId: this.walletId,
|
|
948
|
+
networkId: params.networkId
|
|
949
|
+
});
|
|
950
|
+
const parsedTransaction = await (0, import_parsers2.parseTransactionToBase64Url)(params.transaction, params.networkId);
|
|
951
|
+
const session = await this.storage.getSession();
|
|
952
|
+
const derivationIndex = session?.accountDerivationIndex ?? 0;
|
|
953
|
+
this.logger.log("EMBEDDED_PROVIDER", "Parsed transaction for signing", {
|
|
954
|
+
walletId: this.walletId,
|
|
955
|
+
transaction: parsedTransaction,
|
|
956
|
+
derivationIndex
|
|
957
|
+
});
|
|
958
|
+
const rawResponse = await this.client.signTransaction({
|
|
959
|
+
walletId: this.walletId,
|
|
960
|
+
transaction: parsedTransaction.base64url,
|
|
961
|
+
networkId: params.networkId,
|
|
962
|
+
derivationIndex
|
|
963
|
+
});
|
|
964
|
+
this.logger.info("EMBEDDED_PROVIDER", "Transaction signed successfully", {
|
|
965
|
+
walletId: this.walletId,
|
|
966
|
+
networkId: params.networkId,
|
|
967
|
+
rawTransaction: rawResponse.rawTransaction
|
|
968
|
+
});
|
|
969
|
+
return await (0, import_parsers2.parseTransactionResponse)(rawResponse.rawTransaction, params.networkId);
|
|
909
970
|
}
|
|
910
971
|
async signAndSendTransaction(params) {
|
|
911
972
|
if (!this.client || !this.walletId) {
|
|
@@ -916,7 +977,7 @@ var EmbeddedProvider = class {
|
|
|
916
977
|
walletId: this.walletId,
|
|
917
978
|
networkId: params.networkId
|
|
918
979
|
});
|
|
919
|
-
const parsedTransaction = await (0,
|
|
980
|
+
const parsedTransaction = await (0, import_parsers2.parseTransactionToBase64Url)(params.transaction, params.networkId);
|
|
920
981
|
const session = await this.storage.getSession();
|
|
921
982
|
const derivationIndex = session?.accountDerivationIndex ?? 0;
|
|
922
983
|
this.logger.log("EMBEDDED_PROVIDER", "Parsed transaction for signing", {
|
|
@@ -936,7 +997,7 @@ var EmbeddedProvider = class {
|
|
|
936
997
|
hash: rawResponse.hash,
|
|
937
998
|
rawTransaction: rawResponse.rawTransaction
|
|
938
999
|
});
|
|
939
|
-
return await (0,
|
|
1000
|
+
return await (0, import_parsers2.parseTransactionResponse)(rawResponse.rawTransaction, params.networkId, rawResponse.hash);
|
|
940
1001
|
}
|
|
941
1002
|
getAddresses() {
|
|
942
1003
|
return this.addresses;
|
|
@@ -1190,7 +1251,7 @@ var EmbeddedProvider = class {
|
|
|
1190
1251
|
newKeyId: newKeyInfo.keyId,
|
|
1191
1252
|
newPublicKey: newKeyInfo.publicKey
|
|
1192
1253
|
});
|
|
1193
|
-
const base64urlPublicKey = (0,
|
|
1254
|
+
const base64urlPublicKey = (0, import_base64url2.base64urlEncode)(import_bs582.default.decode(newKeyInfo.publicKey));
|
|
1194
1255
|
const expiresAtMs = Date.now() + AUTHENTICATOR_EXPIRATION_TIME_MS;
|
|
1195
1256
|
let authenticatorResult;
|
|
1196
1257
|
try {
|