New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@dynamic-labs/embedded-wallet-evm

Package Overview
Dependencies
Maintainers
0
Versions
203
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dynamic-labs/embedded-wallet-evm - npm Package Compare versions

Comparing version

to
3.0.0-alpha.14

16

package.json
{
"name": "@dynamic-labs/embedded-wallet-evm",
"version": "3.0.0-alpha.13",
"version": "3.0.0-alpha.14",
"repository": {

@@ -35,9 +35,9 @@ "type": "git",

"@turnkey/webauthn-stamper": "0.5.0",
"@dynamic-labs/embedded-wallet": "3.0.0-alpha.13",
"@dynamic-labs/rpc-provider-ethereum": "3.0.0-alpha.13",
"@dynamic-labs/types": "3.0.0-alpha.13",
"@dynamic-labs/utils": "3.0.0-alpha.13",
"@dynamic-labs/viem-utils": "3.0.0-alpha.13",
"@dynamic-labs/wallet-book": "3.0.0-alpha.13",
"@dynamic-labs/wallet-connector-core": "3.0.0-alpha.13"
"@dynamic-labs/embedded-wallet": "3.0.0-alpha.14",
"@dynamic-labs/rpc-provider-ethereum": "3.0.0-alpha.14",
"@dynamic-labs/types": "3.0.0-alpha.14",
"@dynamic-labs/utils": "3.0.0-alpha.14",
"@dynamic-labs/viem-utils": "3.0.0-alpha.14",
"@dynamic-labs/wallet-book": "3.0.0-alpha.14",
"@dynamic-labs/wallet-connector-core": "3.0.0-alpha.14"
},

@@ -44,0 +44,0 @@ "peerDependencies": {

@@ -42,3 +42,3 @@ import { TurnkeyClient } from '@turnkey/http';

getRpcUrl(): string | undefined;
getBalance(): Promise<string | undefined>;
getBalance(address: string): Promise<string | undefined>;
signMessage(messageToSign: string): Promise<string | undefined>;

@@ -50,10 +50,14 @@ getPublicClient(): Promise<void | PublicClient<Transport, ViemChain> | undefined>;

getWalletClient(): WalletClient<Transport, ViemChain, Account> | undefined;
private refreshTurnkeyAccount;
private get currentChainId();
get lastUsedChainId(): number | undefined;
set lastUsedChainId(chainId: number | undefined);
private get networkRpcUrl();
private get currentEvmNetwork();
private internalSignTransaction;
private internalSignTypedData;
private internalSignMessage;
private createTurnkeyAccount;
private refreshTurnkeyAccount;
private getTurnkeyAccount;
get lastUsedChainId(): number | undefined;
set lastUsedChainId(chainId: number | undefined);
createUiTransaction(from: string): Promise<IUITransaction>;
}

@@ -9,2 +9,3 @@ 'use client'

import { http, createPublicClient, formatEther } from 'viem';
import { toAccount } from 'viem/accounts';
import { parseEvmNetworks, getTLD, PlatformService, DynamicError } from '@dynamic-labs/utils';

@@ -85,8 +86,4 @@ import { createWalletClientWithUiConfirmation, getOrMapViemChain, createViemUiTransaction } from '@dynamic-labs/viem-utils';

}
getBalance() {
getBalance(address) {
return __awaiter(this, void 0, void 0, function* () {
const address = this.turnkeyAddress;
if (!address) {
return undefined;
}
const rpcUrl = this.getRpcUrl();

@@ -137,5 +134,2 @@ if (!rpcUrl) {

return __awaiter(this, void 0, void 0, function* () {
if (this.isSessionKeyCompatible()) {
yield this.createOrRestoreSession();
}
yield this.getTurnkeyAccount();

@@ -197,8 +191,2 @@ return this.getWalletClient();

// Private methods
refreshTurnkeyAccount() {
return __awaiter(this, void 0, void 0, function* () {
this._turnkeyAccount = undefined;
return this.getTurnkeyAccount();
});
}
get currentChainId() {

@@ -208,2 +196,32 @@ var _a, _b, _c;

}
get lastUsedChainId() {
const lastUsedChainIdLS = localStorage.getItem(TurnkeyEVMWalletConnector.lastUsedChainIdStorageKey);
if (!lastUsedChainIdLS)
return undefined;
try {
const chainId = parseInt(lastUsedChainIdLS);
if (isNaN(chainId)) {
return undefined;
}
const isChainCurrentlyEnabled = this.evmNetworks.some((network) => network.chainId === chainId);
if (!isChainCurrentlyEnabled) {
const lastUsedChainId = this.evmNetworks[0].chainId;
this.lastUsedChainId = lastUsedChainId;
return this.lastUsedChainId;
}
return chainId;
}
catch (err) {
logger.error(err);
return undefined;
}
}
set lastUsedChainId(chainId) {
if (chainId === undefined) {
localStorage.removeItem(TurnkeyEVMWalletConnector.lastUsedChainIdStorageKey);
}
else {
localStorage.setItem(TurnkeyEVMWalletConnector.lastUsedChainIdStorageKey, chainId.toString());
}
}
get networkRpcUrl() {

@@ -225,2 +243,87 @@ const chainId = this.currentChainId;

}
internalSignTransaction(_a) {
return __awaiter(this, arguments, void 0, function* ({ transaction, args, address, turnkeySubOrganizationId, }) {
yield this.createOrRestoreSession();
const newTurnkeyAccount = yield this.createTurnkeyAccount({
address,
turnkeySubOrganizationId,
});
try {
return yield newTurnkeyAccount.signTransaction(transaction, args);
}
catch (err) {
yield this.removeSessionKeys();
yield this.createOrRestoreSession({
ignoreRestore: true,
});
const newTurnkeyAccount = yield this.createTurnkeyAccount({
address,
turnkeySubOrganizationId,
});
return newTurnkeyAccount.signTransaction(transaction, args);
}
});
}
internalSignTypedData(_a) {
return __awaiter(this, arguments, void 0, function* ({ typedData, address, turnkeySubOrganizationId, }) {
yield this.createOrRestoreSession();
const newTurnkeyAccountRaw = yield this.createTurnkeyAccount({
address,
turnkeySubOrganizationId,
});
try {
return yield newTurnkeyAccountRaw.signTypedData(typedData);
}
catch (err) {
yield this.removeSessionKeys();
yield this.createOrRestoreSession({
ignoreRestore: true,
});
const newTurnkeyAccountRaw = yield this.createTurnkeyAccount({
address,
turnkeySubOrganizationId,
});
return newTurnkeyAccountRaw.signTypedData(typedData);
}
});
}
internalSignMessage(_a) {
return __awaiter(this, arguments, void 0, function* ({ message, address, turnkeySubOrganizationId, }) {
yield this.createOrRestoreSession();
const newTurnkeyAccountRaw = yield this.createTurnkeyAccount({
address,
turnkeySubOrganizationId,
});
try {
return yield newTurnkeyAccountRaw.signMessage({ message });
}
catch (err) {
yield this.removeSessionKeys();
yield this.createOrRestoreSession({
ignoreRestore: true,
});
const newTurnkeyAccountRaw = yield this.createTurnkeyAccount({
address,
turnkeySubOrganizationId,
});
return newTurnkeyAccountRaw.signMessage({ message });
}
});
}
createTurnkeyAccount(_a) {
return __awaiter(this, arguments, void 0, function* ({ address, turnkeySubOrganizationId, }) {
return createAccount({
client: this.getTurnkeyClient(),
ethereumAddress: address,
organizationId: turnkeySubOrganizationId,
signWith: address,
});
});
}
refreshTurnkeyAccount() {
return __awaiter(this, void 0, void 0, function* () {
this._turnkeyAccount = undefined;
return this.getTurnkeyAccount();
});
}
getTurnkeyAccount() {

@@ -237,7 +340,26 @@ return __awaiter(this, void 0, void 0, function* () {

}
this._turnkeyAccount = yield createAccount({
client: this.getTurnkeyClient(),
ethereumAddress: address,
organizationId: turnkeySubOrganizationId,
signWith: address,
this._turnkeyAccount = toAccount({
address: address,
signMessage: (_c) => __awaiter(this, [_c], void 0, function* ({ message, }) {
return this.internalSignMessage({
address: address,
message,
turnkeySubOrganizationId,
});
}),
signTransaction: (transaction, args) => __awaiter(this, void 0, void 0, function* () {
return this.internalSignTransaction({
address: address,
args,
transaction,
turnkeySubOrganizationId,
});
}),
signTypedData: (typedData) => __awaiter(this, void 0, void 0, function* () {
return this.internalSignTypedData({
address: address,
turnkeySubOrganizationId,
typedData,
});
}),
});

@@ -247,32 +369,2 @@ return this._turnkeyAccount;

}
get lastUsedChainId() {
const lastUsedChainIdLS = localStorage.getItem(TurnkeyEVMWalletConnector.lastUsedChainIdStorageKey);
if (!lastUsedChainIdLS)
return undefined;
try {
const chainId = parseInt(lastUsedChainIdLS);
if (isNaN(chainId)) {
return undefined;
}
const isChainCurrentlyEnabled = this.evmNetworks.some((network) => network.chainId === chainId);
if (!isChainCurrentlyEnabled) {
const lastUsedChainId = this.evmNetworks[0].chainId;
this.lastUsedChainId = lastUsedChainId;
return this.lastUsedChainId;
}
return chainId;
}
catch (err) {
logger.error(err);
return undefined;
}
}
set lastUsedChainId(chainId) {
if (chainId === undefined) {
localStorage.removeItem(TurnkeyEVMWalletConnector.lastUsedChainIdStorageKey);
}
else {
localStorage.setItem(TurnkeyEVMWalletConnector.lastUsedChainIdStorageKey, chainId.toString());
}
}
createUiTransaction(from) {

@@ -279,0 +371,0 @@ return __awaiter(this, void 0, void 0, function* () {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet