@octaflowlabs/onchain-sdk 1.3.0 → 1.3.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.
@@ -1,6 +1,7 @@
1
1
  export interface NetworkField {
2
2
  id: string;
3
3
  name: string;
4
+ nameForDisplay: string;
4
5
  chainId: number;
5
6
  rpcUrl: string;
6
7
  explorerUrl: string;
@@ -7,7 +7,8 @@ exports.NETWORKS_REGISTRY = [
7
7
  networks: [
8
8
  {
9
9
  id: 'ethereum-mainnet',
10
- name: 'Ethereum Mainnet',
10
+ name: 'eth-mainnet',
11
+ nameForDisplay: 'Ethereum Mainnet',
11
12
  chainId: 1,
12
13
  rpcUrl: 'https://ethereum-rpc.publicnode.com',
13
14
  explorerUrl: 'https://etherscan.io',
@@ -17,7 +18,8 @@ exports.NETWORKS_REGISTRY = [
17
18
  },
18
19
  {
19
20
  id: 'bnb-smart-chain',
20
- name: 'BNB Smart Chain',
21
+ name: 'bnb-mainnet',
22
+ nameForDisplay: 'BNB Smart Chain',
21
23
  chainId: 56,
22
24
  rpcUrl: 'https://bsc-dataseed.bnbchain.org',
23
25
  explorerUrl: 'https://bscscan.com/',
@@ -27,7 +29,8 @@ exports.NETWORKS_REGISTRY = [
27
29
  },
28
30
  {
29
31
  id: 'polygon-mainnet',
30
- name: 'Polygon Mainnet',
32
+ name: 'polygon-mainnet',
33
+ nameForDisplay: 'Polygon Mainnet',
31
34
  iconUrl: 'https://assets.coingecko.com/coins/images/4713/large/matic-token-icon.png',
32
35
  chainId: 137,
33
36
  rpcUrl: 'https://polygon.publicnode.com',
@@ -37,7 +40,8 @@ exports.NETWORKS_REGISTRY = [
37
40
  },
38
41
  {
39
42
  id: 'arbitrum-mainnet',
40
- name: 'Arbitrum Mainnet',
43
+ name: 'arb-mainnet',
44
+ nameForDisplay: 'Arbitrum Mainnet',
41
45
  chainId: 42161,
42
46
  rpcUrl: 'https://public-arb-mainnet.fastnode.io',
43
47
  explorerUrl: 'https://arbiscan.io',
@@ -52,7 +56,8 @@ exports.NETWORKS_REGISTRY = [
52
56
  networks: [
53
57
  {
54
58
  id: 'sepolia-eth',
55
- name: 'Sepolia Testnet',
59
+ name: 'eth-sepolia',
60
+ nameForDisplay: 'ETH Sepolia Testnet',
56
61
  chainId: 11155111,
57
62
  rpcUrl: 'https://ethereum-sepolia-rpc.publicnode.com',
58
63
  explorerUrl: 'https://sepolia.etherscan.io',
@@ -20,6 +20,10 @@ export declare class EvmWalletService {
20
20
  generateMultipleWallets(mnemonic: string, count: number, startIndex?: number): EvmDerivedWallet[];
21
21
  deriveWalletFromMnemonic(mnemonic: string, accountIndex?: number, customPath?: string): EvmDerivedWallet;
22
22
  deriveFromPrivateKey(privateKey: string): Omit<EvmDerivedWallet, 'path'>;
23
+ getFirstAvailableIndexForMnemonicImport(mnemonic: string, existingAddresses: string[], maxIndicesToCheck?: number): {
24
+ index: number;
25
+ wallet: EvmDerivedWallet;
26
+ } | null;
23
27
  signMessage(privateKey: string, message: string): Promise<string>;
24
28
  isValidMnemonic(mnemonic: string): boolean;
25
29
  private validateMnemonic;
@@ -58,6 +58,18 @@ class EvmWalletService {
58
58
  publicKey: wallet.signingKey.publicKey,
59
59
  };
60
60
  }
61
+ getFirstAvailableIndexForMnemonicImport(mnemonic, existingAddresses, maxIndicesToCheck = 20) {
62
+ this.validateMnemonic(mnemonic);
63
+ const existingSet = new Set(existingAddresses.map((addr) => (0, ethers_1.getAddress)(addr)));
64
+ for (let i = 0; i < maxIndicesToCheck; i++) {
65
+ const wallet = this.deriveWalletFromMnemonic(mnemonic, i);
66
+ const normalizedAddress = (0, ethers_1.getAddress)(wallet.address);
67
+ if (!existingSet.has(normalizedAddress)) {
68
+ return { index: i, wallet };
69
+ }
70
+ }
71
+ return null;
72
+ }
61
73
  async signMessage(privateKey, message) {
62
74
  const wallet = new ethers_1.Wallet(privateKey);
63
75
  return await wallet.signMessage(message);
@@ -72,9 +84,8 @@ class EvmWalletService {
72
84
  }
73
85
  }
74
86
  validateMnemonic(mnemonic) {
75
- if (!this.isValidMnemonic(mnemonic)) {
87
+ if (!this.isValidMnemonic(mnemonic))
76
88
  throw new Error('Invalid mnemonic phrase');
77
- }
78
89
  }
79
90
  getEntropyForWordCount(wordCount) {
80
91
  const entropyMap = {
@@ -1,6 +1,7 @@
1
1
  export interface NetworkField {
2
2
  id: string;
3
3
  name: string;
4
+ nameForDisplay: string;
4
5
  chainId: number;
5
6
  rpcUrl: string;
6
7
  explorerUrl: string;
@@ -4,7 +4,8 @@ export const NETWORKS_REGISTRY = [
4
4
  networks: [
5
5
  {
6
6
  id: 'ethereum-mainnet',
7
- name: 'Ethereum Mainnet',
7
+ name: 'eth-mainnet',
8
+ nameForDisplay: 'Ethereum Mainnet',
8
9
  chainId: 1,
9
10
  rpcUrl: 'https://ethereum-rpc.publicnode.com',
10
11
  explorerUrl: 'https://etherscan.io',
@@ -14,7 +15,8 @@ export const NETWORKS_REGISTRY = [
14
15
  },
15
16
  {
16
17
  id: 'bnb-smart-chain',
17
- name: 'BNB Smart Chain',
18
+ name: 'bnb-mainnet',
19
+ nameForDisplay: 'BNB Smart Chain',
18
20
  chainId: 56,
19
21
  rpcUrl: 'https://bsc-dataseed.bnbchain.org',
20
22
  explorerUrl: 'https://bscscan.com/',
@@ -24,7 +26,8 @@ export const NETWORKS_REGISTRY = [
24
26
  },
25
27
  {
26
28
  id: 'polygon-mainnet',
27
- name: 'Polygon Mainnet',
29
+ name: 'polygon-mainnet',
30
+ nameForDisplay: 'Polygon Mainnet',
28
31
  iconUrl: 'https://assets.coingecko.com/coins/images/4713/large/matic-token-icon.png',
29
32
  chainId: 137,
30
33
  rpcUrl: 'https://polygon.publicnode.com',
@@ -34,7 +37,8 @@ export const NETWORKS_REGISTRY = [
34
37
  },
35
38
  {
36
39
  id: 'arbitrum-mainnet',
37
- name: 'Arbitrum Mainnet',
40
+ name: 'arb-mainnet',
41
+ nameForDisplay: 'Arbitrum Mainnet',
38
42
  chainId: 42161,
39
43
  rpcUrl: 'https://public-arb-mainnet.fastnode.io',
40
44
  explorerUrl: 'https://arbiscan.io',
@@ -49,7 +53,8 @@ export const NETWORKS_REGISTRY = [
49
53
  networks: [
50
54
  {
51
55
  id: 'sepolia-eth',
52
- name: 'Sepolia Testnet',
56
+ name: 'eth-sepolia',
57
+ nameForDisplay: 'ETH Sepolia Testnet',
53
58
  chainId: 11155111,
54
59
  rpcUrl: 'https://ethereum-sepolia-rpc.publicnode.com',
55
60
  explorerUrl: 'https://sepolia.etherscan.io',
@@ -20,6 +20,10 @@ export declare class EvmWalletService {
20
20
  generateMultipleWallets(mnemonic: string, count: number, startIndex?: number): EvmDerivedWallet[];
21
21
  deriveWalletFromMnemonic(mnemonic: string, accountIndex?: number, customPath?: string): EvmDerivedWallet;
22
22
  deriveFromPrivateKey(privateKey: string): Omit<EvmDerivedWallet, 'path'>;
23
+ getFirstAvailableIndexForMnemonicImport(mnemonic: string, existingAddresses: string[], maxIndicesToCheck?: number): {
24
+ index: number;
25
+ wallet: EvmDerivedWallet;
26
+ } | null;
23
27
  signMessage(privateKey: string, message: string): Promise<string>;
24
28
  isValidMnemonic(mnemonic: string): boolean;
25
29
  private validateMnemonic;
@@ -1,5 +1,5 @@
1
1
  /** npm imports */
2
- import { Wallet, HDNodeWallet, Mnemonic } from 'ethers';
2
+ import { Wallet, HDNodeWallet, Mnemonic, getAddress } from 'ethers';
3
3
  export class EvmWalletService {
4
4
  constructor(entropy) {
5
5
  this.entropy = entropy;
@@ -55,6 +55,18 @@ export class EvmWalletService {
55
55
  publicKey: wallet.signingKey.publicKey,
56
56
  };
57
57
  }
58
+ getFirstAvailableIndexForMnemonicImport(mnemonic, existingAddresses, maxIndicesToCheck = 20) {
59
+ this.validateMnemonic(mnemonic);
60
+ const existingSet = new Set(existingAddresses.map((addr) => getAddress(addr)));
61
+ for (let i = 0; i < maxIndicesToCheck; i++) {
62
+ const wallet = this.deriveWalletFromMnemonic(mnemonic, i);
63
+ const normalizedAddress = getAddress(wallet.address);
64
+ if (!existingSet.has(normalizedAddress)) {
65
+ return { index: i, wallet };
66
+ }
67
+ }
68
+ return null;
69
+ }
58
70
  async signMessage(privateKey, message) {
59
71
  const wallet = new Wallet(privateKey);
60
72
  return await wallet.signMessage(message);
@@ -69,9 +81,8 @@ export class EvmWalletService {
69
81
  }
70
82
  }
71
83
  validateMnemonic(mnemonic) {
72
- if (!this.isValidMnemonic(mnemonic)) {
84
+ if (!this.isValidMnemonic(mnemonic))
73
85
  throw new Error('Invalid mnemonic phrase');
74
- }
75
86
  }
76
87
  getEntropyForWordCount(wordCount) {
77
88
  const entropyMap = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octaflowlabs/onchain-sdk",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "onchain methods for web3",
5
5
  "repository": "https://github.com/crisramb665/onchain-sdk.git",
6
6
  "license": "MIT",