@deserialize/multi-vm-wallet 1.0.12 → 1.0.21

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.
Files changed (48) hide show
  1. package/dist/IChainWallet.d.ts +17 -0
  2. package/dist/IChainWallet.js +23 -0
  3. package/dist/IChainWallet.js.map +1 -0
  4. package/dist/bip32.d.ts +11 -0
  5. package/dist/bip32.js +100 -0
  6. package/dist/bip32.js.map +1 -0
  7. package/dist/evm/evm.d.ts +39 -0
  8. package/dist/evm/evm.js +234 -0
  9. package/dist/evm/evm.js.map +1 -0
  10. package/dist/evm/index.d.ts +2 -0
  11. package/dist/evm/index.js +19 -0
  12. package/dist/evm/index.js.map +1 -0
  13. package/dist/evm/utils.d.ts +207 -0
  14. package/dist/evm/utils.js +538 -0
  15. package/dist/evm/utils.js.map +1 -0
  16. package/dist/index.d.ts +7 -0
  17. package/dist/index.js +24 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/svm/index.d.ts +1 -0
  20. package/dist/svm/index.js +18 -0
  21. package/dist/svm/index.js.map +1 -0
  22. package/dist/svm/svm.d.ts +36 -0
  23. package/dist/svm/svm.js +167 -0
  24. package/dist/svm/svm.js.map +1 -0
  25. package/dist/svm/transactionSender.d.ts +8 -0
  26. package/dist/svm/transactionSender.js +84 -0
  27. package/dist/svm/transactionSender.js.map +1 -0
  28. package/dist/svm/utils.d.ts +85 -0
  29. package/dist/svm/utils.js +305 -0
  30. package/dist/svm/utils.js.map +1 -0
  31. package/dist/tsconfig.tsbuildinfo +1 -1
  32. package/dist/types.d.ts +44 -0
  33. package/dist/types.js +10 -0
  34. package/dist/types.js.map +1 -0
  35. package/dist/utils/evm/evm.d.ts +4 -3
  36. package/dist/utils/evm/evm.js +18 -6
  37. package/dist/utils/svm/svm.d.ts +3 -2
  38. package/dist/utils/svm/svm.js +17 -5
  39. package/dist/utils/vm.d.ts +2 -3
  40. package/dist/utils/vm.js +5 -6
  41. package/dist/vm.d.ts +12 -0
  42. package/dist/vm.js +49 -0
  43. package/dist/vm.js.map +1 -0
  44. package/package.json +1 -1
  45. package/tsconfig.json +11 -111
  46. package/utils/evm/evm.ts +22 -10
  47. package/utils/svm/svm.ts +17 -5
  48. package/utils/vm.ts +5 -5
@@ -0,0 +1,44 @@
1
+ import BN from "bn.js";
2
+ import { EVMVM } from "./evm";
3
+ import { SVMVM } from "./svm";
4
+ export interface ChainWalletConfig {
5
+ chainId: string | number;
6
+ name: string;
7
+ rpcUrl: string;
8
+ explorerUrl: string;
9
+ nativeToken: {
10
+ name: string;
11
+ symbol: string;
12
+ decimals: number;
13
+ };
14
+ confirmationNo?: number;
15
+ testnet?: boolean;
16
+ }
17
+ export interface TokenInfo {
18
+ address: string;
19
+ name: string;
20
+ symbol: string;
21
+ decimals: number;
22
+ }
23
+ export interface NFTInfo {
24
+ tokenId: string;
25
+ contractAddress: string;
26
+ name?: string;
27
+ description?: string;
28
+ image?: string;
29
+ }
30
+ export interface TransactionResult {
31
+ hash: string;
32
+ success: boolean;
33
+ error?: string;
34
+ }
35
+ export interface Balance {
36
+ balance: BN;
37
+ formatted: number;
38
+ decimal: number;
39
+ }
40
+ export declare const SUPPORTED_VM: {
41
+ readonly EVM: typeof EVMVM;
42
+ readonly SVM: typeof SVMVM;
43
+ };
44
+ export type vmTypes = keyof typeof SUPPORTED_VM;
package/dist/types.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SUPPORTED_VM = void 0;
4
+ const evm_1 = require("./evm");
5
+ const svm_1 = require("./svm");
6
+ exports.SUPPORTED_VM = {
7
+ 'EVM': evm_1.EVMVM,
8
+ 'SVM': svm_1.SVMVM
9
+ };
10
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../utils/types.ts"],"names":[],"mappings":";;;AACA,+BAA8B;AAC9B,+BAA8B;AA6CjB,QAAA,YAAY,GAAG;IACxB,KAAK,EAAE,WAAK;IACZ,KAAK,EAAE,WAAK;CACN,CAAC"}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  *
3
3
  * @param phrase this is the pass phrase for this vm
4
- * this is a class that will be responsible for creating several evm wallets
4
+ * this is a class that will be responsible for creating several evm wallets code
5
5
  */
6
6
  import { ChainWallet } from "../IChainWallet";
7
7
  import { Balance, ChainWalletConfig, TokenInfo, TransactionResult } from "../types";
@@ -10,11 +10,12 @@ import { JsonRpcProvider, Wallet } from "ethers";
10
10
  export declare const createEvmVmPrivateKey: (phrase: string) => void;
11
11
  export declare class EVMVM extends VM<string, string, JsonRpcProvider> {
12
12
  derivationPath: string;
13
- constructor(mnemonic: string);
14
- generatePrivateKey(index: number, seedPhrase?: string, derivationPath?: string): {
13
+ constructor(seed: string);
14
+ generatePrivateKey(index: number, seed?: string, mnemonic?: string, derivationPath?: string): {
15
15
  privateKey: string;
16
16
  index: number;
17
17
  };
18
+ static fromMnemonic(seed: string): VM<string, string, JsonRpcProvider>;
18
19
  validateAddress(address: string): boolean;
19
20
  static getNativeBalance(address: string, connection: JsonRpcProvider): Promise<Balance>;
20
21
  static getTokenBalance(address: string, tokenAddress: string, connection: JsonRpcProvider): Promise<Balance>;
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  *
4
4
  * @param phrase this is the pass phrase for this vm
5
- * this is a class that will be responsible for creating several evm wallets
5
+ * this is a class that will be responsible for creating several evm wallets code
6
6
  */
7
7
  var __importDefault = (this && this.__importDefault) || function (mod) {
8
8
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -18,15 +18,27 @@ const utils_1 = require("./utils");
18
18
  const createEvmVmPrivateKey = (phrase) => { };
19
19
  exports.createEvmVmPrivateKey = createEvmVmPrivateKey;
20
20
  class EVMVM extends vm_1.VM {
21
- constructor(mnemonic) {
22
- super(mnemonic, "EVM");
21
+ constructor(seed) {
22
+ super(seed, "EVM");
23
23
  this.derivationPath = "m/44'/60'/0'/0/"; // Default EVM derivation path
24
24
  }
25
- generatePrivateKey(index, seedPhrase = this.mnemonic, derivationPath = this.derivationPath) {
26
- const seed = this.mnemonicToSeed(seedPhrase);
27
- const privateKey = (0, bip32_1.EVMDeriveChildPrivateKey)(seed, index, derivationPath).privateKey;
25
+ generatePrivateKey(index, seed, mnemonic, derivationPath = this.derivationPath) {
26
+ let _seed;
27
+ if (seed) {
28
+ _seed = seed;
29
+ }
30
+ else if (mnemonic) {
31
+ _seed = vm_1.VM.mnemonicToSeed(mnemonic);
32
+ }
33
+ else {
34
+ _seed = this.seed;
35
+ }
36
+ const privateKey = (0, bip32_1.EVMDeriveChildPrivateKey)(_seed, index, derivationPath).privateKey;
28
37
  return { privateKey, index };
29
38
  }
39
+ static fromMnemonic(seed) {
40
+ return new EVMVM(seed);
41
+ }
30
42
  validateAddress(address) {
31
43
  return ethers_1.ethers.isAddress(address);
32
44
  }
@@ -5,15 +5,16 @@ import { Balance, ChainWalletConfig, TokenInfo, TransactionResult } from "../typ
5
5
  import { JupiterQuoteResponse } from "./utils";
6
6
  export declare class SVMVM extends VM<PublicKey, Keypair, Connection> {
7
7
  derivationPath: string;
8
- constructor(mnemonic: string);
8
+ constructor(seed: string);
9
9
  static validateAddress(address: PublicKey): boolean;
10
10
  static getNativeBalance(address: PublicKey, connection: Connection): Promise<Balance>;
11
11
  static getTokenBalance(address: PublicKey, tokenAddress: PublicKey, connection: Connection): Promise<Balance>;
12
12
  static signAndSendTransaction: (transaction: import("@solana/web3.js").VersionedTransaction, connection: Connection, signers: Keypair[]) => Promise<string>;
13
- generatePrivateKey(index: number, seedPhrase?: string, derivationPath?: string): {
13
+ generatePrivateKey(index: number, seed?: string, mnemonic?: string, derivationPath?: string): {
14
14
  privateKey: Keypair;
15
15
  index: number;
16
16
  };
17
+ static fromMnemonic(seed: string): VM<PublicKey, Keypair, Connection>;
17
18
  }
18
19
  export declare class SVMChainWallet extends ChainWallet<PublicKey, Keypair, Connection> {
19
20
  constructor(config: ChainWalletConfig, privateKey: Keypair, index: number);
@@ -11,8 +11,8 @@ const IChainWallet_1 = require("../IChainWallet");
11
11
  const utils_1 = require("./utils");
12
12
  const bn_js_1 = __importDefault(require("bn.js"));
13
13
  class SVMVM extends vm_1.VM {
14
- constructor(mnemonic) {
15
- super(mnemonic, "SVM");
14
+ constructor(seed) {
15
+ super(seed, "SVM");
16
16
  this.derivationPath = "m/44'/501'/"; // Default SVM derivation path
17
17
  }
18
18
  static validateAddress(address) {
@@ -28,11 +28,23 @@ class SVMVM extends vm_1.VM {
28
28
  }
29
29
  return { balance: new bn_js_1.default(balance.amount), formatted: balance.uiAmount || parseInt(balance.amount) / 10 ** balance.decimals, decimal: balance.decimals };
30
30
  }
31
- generatePrivateKey(index, seedPhrase = this.mnemonic, derivationPath = this.derivationPath) {
32
- const seed = this.mnemonicToSeed(seedPhrase);
33
- const privateKey = (0, bip32_1.SVMDeriveChildPrivateKey)(seed, index, derivationPath);
31
+ generatePrivateKey(index, seed, mnemonic, derivationPath = this.derivationPath) {
32
+ let _seed;
33
+ if (seed) {
34
+ _seed = seed;
35
+ }
36
+ else if (mnemonic) {
37
+ _seed = vm_1.VM.mnemonicToSeed(mnemonic);
38
+ }
39
+ else {
40
+ _seed = this.seed;
41
+ }
42
+ const privateKey = (0, bip32_1.SVMDeriveChildPrivateKey)(_seed, index, derivationPath);
34
43
  return { privateKey, index };
35
44
  }
45
+ static fromMnemonic(seed) {
46
+ return new SVMVM(seed);
47
+ }
36
48
  }
37
49
  exports.SVMVM = SVMVM;
38
50
  SVMVM.signAndSendTransaction = utils_1.signAndSendTransaction;
@@ -1,10 +1,9 @@
1
1
  import { vmTypes } from "./types";
2
2
  export declare abstract class VM<AddressType, PrivateKeyType, ConnectionType> {
3
- protected mnemonic: string;
4
3
  protected seed: string;
5
4
  type: vmTypes;
6
- constructor(mnemonic: string, vm: vmTypes);
7
- mnemonicToSeed: (mnemonic: string) => string;
5
+ constructor(seed: string, vm: vmTypes);
6
+ static mnemonicToSeed: (mnemonic: string) => string;
8
7
  abstract derivationPath: string;
9
8
  abstract generatePrivateKey(index: number, mnemonic?: string, derivationPath?: string): {
10
9
  privateKey: PrivateKeyType;
package/dist/utils/vm.js CHANGED
@@ -37,13 +37,12 @@ exports.VM = void 0;
37
37
  const bip39 = __importStar(require("bip39"));
38
38
  // Abstract Base Classes
39
39
  class VM {
40
- constructor(mnemonic, vm) {
41
- this.mnemonicToSeed = (mnemonic) => {
42
- return bip39.mnemonicToSeedSync(mnemonic).toString("hex");
43
- };
44
- this.mnemonic = mnemonic;
40
+ constructor(seed, vm) {
45
41
  this.type = vm;
46
- this.seed = this.mnemonicToSeed(this.mnemonic);
42
+ this.seed = seed;
47
43
  }
48
44
  }
49
45
  exports.VM = VM;
46
+ VM.mnemonicToSeed = (mnemonic) => {
47
+ return bip39.mnemonicToSeedSync(mnemonic).toString("hex");
48
+ };
package/dist/vm.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { vmTypes } from "./types";
2
+ export declare abstract class VM<AddressType, PrivateKeyType, ConnectionType> {
3
+ protected seed: string;
4
+ type: vmTypes;
5
+ constructor(seed: string, vm: vmTypes);
6
+ static mnemonicToSeed: (mnemonic: string) => string;
7
+ abstract derivationPath: string;
8
+ abstract generatePrivateKey(index: number, mnemonic?: string, derivationPath?: string): {
9
+ privateKey: PrivateKeyType;
10
+ index: number;
11
+ };
12
+ }
package/dist/vm.js ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.VM = void 0;
37
+ const bip39 = __importStar(require("bip39"));
38
+ // Abstract Base Classes
39
+ class VM {
40
+ constructor(seed, vm) {
41
+ this.type = vm;
42
+ this.seed = seed;
43
+ }
44
+ }
45
+ exports.VM = VM;
46
+ VM.mnemonicToSeed = (mnemonic) => {
47
+ return bip39.mnemonicToSeedSync(mnemonic).toString("hex");
48
+ };
49
+ //# sourceMappingURL=vm.js.map
package/dist/vm.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vm.js","sourceRoot":"","sources":["../utils/vm.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,6CAA+B;AAE/B,wBAAwB;AACxB,MAAsB,EAAE;IAIpB,YAAY,IAAY,EAAE,EAAW;QACjC,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IACpB,CAAC;;AAPL,gBAoBC;AAZU,iBAAc,GAAG,CAAC,QAAgB,EAAE,EAAE;IACzC,OAAO,KAAK,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC9D,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deserialize/multi-vm-wallet",
3
- "version": "1.0.12",
3
+ "version": "1.0.21",
4
4
  "devDependencies": {
5
5
  "@types/bn.js": "^5.2.0",
6
6
  "@types/node": "^24.2.1",
package/tsconfig.json CHANGED
@@ -1,115 +1,15 @@
1
1
  {
2
2
  "compilerOptions": {
3
- /* Visit https://aka.ms/tsconfig to read more about this file */
4
-
5
- /* Projects */
6
- // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
7
- "composite": true /* Enable constraints that allow a TypeScript project to be used with project references. */,
8
- // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
9
- // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
10
- // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11
- // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
-
13
- /* Language and Environment */
14
- "target": "es2020" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
15
- // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
- // "jsx": "preserve", /* Specify what JSX code is generated. */
17
- // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
18
- // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
- // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
20
- // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21
- // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
22
- // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
23
- // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24
- // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
25
- // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26
-
27
- /* Modules */
28
- "module": "commonjs" /* Specify what module code is generated. */,
29
- // "rootDir": "./", /* Specify the root folder within your source files. */
30
- "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
31
- "baseUrl": "./" /* Specify the base directory to resolve non-relative module names. */,
32
- // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
33
- // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
34
- "typeRoots": [
35
- "./node_modules/@types",
36
- "./src/types"
37
- ] /* Specify multiple folders that act like './node_modules/@types'. */,
38
- // "types": [], /* Specify type package names to be included without being referenced in a source file. */
39
- // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
40
- // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
41
- // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
42
- // "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
43
- // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
44
- // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
45
- // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
46
- // "noUncheckedSideEffectImports": true, /* Check side effect imports. */
47
- "resolveJsonModule": true /* Enable importing .json files. */,
48
- // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
49
- // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
50
-
51
- /* JavaScript Support */
52
- "allowJs": true /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */,
53
- "checkJs": false /* Enable error reporting in type-checked JavaScript files. */,
54
- // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
55
-
56
- /* Emit */
57
- "declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
58
- // "declarationMap": true, /* Create sourcemaps for d.ts files. */
59
- // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
60
- // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
61
- // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
62
- // "noEmit": true, /* Disable emitting files from a compilation. */
63
- // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
64
- "outDir": "./dist" /* Specify an output folder for all emitted files. */,
65
- // "removeComments": true, /* Disable emitting comments. */
66
- // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
67
- // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
68
- // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
69
- // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
70
- // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
71
- // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
72
- // "newLine": "crlf", /* Set the newline character for emitting files. */
73
- // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
74
- // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
75
- // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
76
- // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
77
- // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
78
-
79
- /* Interop Constraints */
80
- // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
81
- // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
82
- // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
83
- // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
84
- "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
85
- "preserveSymlinks": true /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */,
86
- "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
87
-
88
- /* Type Checking */
89
- // "strict": true /* Enable all strict type-checking options. */,
90
- // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
91
- // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
92
- // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
93
- // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
94
- // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
95
- // "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
96
- // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
97
- // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
98
- // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
99
- // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
100
- // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
101
- // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
102
- // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
103
- // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
104
- // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
105
- // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
106
- // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
107
- // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
108
- // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
109
-
110
- /* Completeness */
111
- // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
112
- "skipLibCheck": true /* Skip type checking all .d.ts files. */
3
+ "target": "ES2020", // or your preferred target
4
+ "module": "commonjs", // or "ESNext" if you prefer
5
+ "declaration": true, // generate .d.ts files
6
+ "outDir": "./dist", // output directory for compiled files
7
+ "strict": true, // enable all strict type-checking options
8
+ "esModuleInterop": true, // for compatibility with commonJS modules
9
+ "skipLibCheck": true, // skip type checking of declaration files
10
+ "forceConsistentCasingInFileNames": true,
11
+ "sourceMap": true // generate source maps (optional)
113
12
  },
114
- "exclude": ["node_modules", "dist"]
13
+ "include": ["utils/**/*"], // adjust if your source files are in a different folder
14
+ "exclude": ["node_modules", "**/*.spec.ts"] // exclude tests and node_modules
115
15
  }
package/utils/evm/evm.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  *
3
3
  * @param phrase this is the pass phrase for this vm
4
- * this is a class that will be responsible for creating several evm wallets
4
+ * this is a class that will be responsible for creating several evm wallets code
5
5
  */
6
6
 
7
7
  import { EVMDeriveChildPrivateKey, getSeedNode } from "../bip32";
@@ -30,14 +30,26 @@ export const createEvmVmPrivateKey = (phrase: string) => { }
30
30
  export class EVMVM extends VM<string, string, JsonRpcProvider> {
31
31
  derivationPath = "m/44'/60'/0'/0/"; // Default EVM derivation path
32
32
 
33
- constructor(mnemonic: string) {
34
- super(mnemonic, "EVM");
33
+ constructor(seed: string) {
34
+ super(seed, "EVM");
35
35
  }
36
- generatePrivateKey(index: number, seedPhrase = this.mnemonic, derivationPath = this.derivationPath) {
37
- const seed = this.mnemonicToSeed(seedPhrase);
38
- const privateKey = EVMDeriveChildPrivateKey(seed, index, derivationPath).privateKey;
36
+
37
+ generatePrivateKey(index: number, seed?: string, mnemonic?: string, derivationPath = this.derivationPath) {
38
+ let _seed: string
39
+
40
+ if (seed) {
41
+ _seed = seed
42
+ } else if (mnemonic) {
43
+ _seed = VM.mnemonicToSeed(mnemonic)
44
+ } else {
45
+ _seed = this.seed
46
+ }
47
+ const privateKey = EVMDeriveChildPrivateKey(_seed, index, derivationPath).privateKey;
39
48
  return { privateKey, index };
40
49
  }
50
+ static fromMnemonic(seed: string): VM<string, string, JsonRpcProvider> {
51
+ return new EVMVM(seed)
52
+ }
41
53
 
42
54
  validateAddress(address: string): boolean {
43
55
  return ethers.isAddress(address);
@@ -141,9 +153,9 @@ export class EVMChainWallet extends ChainWallet<string, string, JsonRpcProvider>
141
153
  }
142
154
 
143
155
  const isNativeIn = tokenIn.address === 'native' ||
144
- tokenIn.address.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
156
+ tokenIn.address.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
145
157
  const isNativeOut = tokenOut.address === 'native' ||
146
- tokenOut.address.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
158
+ tokenOut.address.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
147
159
 
148
160
  let tokenInDecimals = 18;
149
161
  if (!isNativeIn && tokenIn.decimals) {
@@ -273,9 +285,9 @@ export class EVMChainWallet extends ChainWallet<string, string, JsonRpcProvider>
273
285
  }
274
286
 
275
287
  const isNativeIn = tokenIn.address === 'native' ||
276
- tokenIn.address.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
288
+ tokenIn.address.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
277
289
  const isNativeOut = tokenOut.address === 'native' ||
278
- tokenOut.address.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
290
+ tokenOut.address.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
279
291
 
280
292
  let tokenInDecimals = 18;
281
293
  if (!isNativeIn && tokenIn.decimals) {
package/utils/svm/svm.ts CHANGED
@@ -21,8 +21,8 @@ import BN from "bn.js";
21
21
  export class SVMVM extends VM<PublicKey, Keypair, Connection> {
22
22
  derivationPath = "m/44'/501'/"; // Default SVM derivation path
23
23
 
24
- constructor(mnemonic: string) {
25
- super(mnemonic, "SVM");
24
+ constructor(seed: string) {
25
+ super(seed, "SVM");
26
26
  }
27
27
  static validateAddress(address: PublicKey): boolean {
28
28
  return PublicKey.isOnCurve(address.toBuffer());
@@ -39,11 +39,23 @@ export class SVMVM extends VM<PublicKey, Keypair, Connection> {
39
39
  }
40
40
 
41
41
  static signAndSendTransaction = signAndSendTransaction
42
- generatePrivateKey(index: number, seedPhrase = this.mnemonic, derivationPath = this.derivationPath) {
43
- const seed = this.mnemonicToSeed(seedPhrase);
44
- const privateKey = SVMDeriveChildPrivateKey(seed, index, derivationPath);
42
+ generatePrivateKey(index: number, seed?: string, mnemonic?: string, derivationPath = this.derivationPath) {
43
+ let _seed: string
44
+
45
+ if (seed) {
46
+ _seed = seed
47
+ } else if (mnemonic) {
48
+ _seed = VM.mnemonicToSeed(mnemonic)
49
+ } else {
50
+ _seed = this.seed
51
+ }
52
+ const privateKey = SVMDeriveChildPrivateKey(_seed, index, derivationPath);
45
53
  return { privateKey, index };
46
54
  }
55
+ static fromMnemonic(seed: string): VM<PublicKey, Keypair, Connection> {
56
+ return new SVMVM(seed)
57
+ }
58
+
47
59
 
48
60
  }
49
61
 
package/utils/vm.ts CHANGED
@@ -4,23 +4,23 @@ import * as bip39 from "bip39";
4
4
 
5
5
  // Abstract Base Classes
6
6
  export abstract class VM<AddressType, PrivateKeyType, ConnectionType> {
7
- protected mnemonic: string;
8
7
  protected seed: string;
9
8
  type: vmTypes
10
9
 
11
- constructor(mnemonic: string, vm: vmTypes) {
12
- this.mnemonic = mnemonic;
10
+ constructor(seed: string, vm: vmTypes) {
13
11
  this.type = vm;
14
- this.seed = this.mnemonicToSeed(this.mnemonic);
12
+ this.seed = seed
15
13
  }
16
- mnemonicToSeed = (mnemonic: string) => {
14
+ static mnemonicToSeed = (mnemonic: string) => {
17
15
  return bip39.mnemonicToSeedSync(mnemonic).toString("hex");
18
16
  }
17
+
19
18
  abstract derivationPath: string
20
19
 
21
20
 
22
21
 
23
22
  abstract generatePrivateKey(index: number, mnemonic?: string, derivationPath?: string): { privateKey: PrivateKeyType, index: number };
23
+
24
24
  // abstract validateAddress(address: AddressType): boolean;
25
25
  // abstract getNativeBalance(address: AddressType, connection: ConnectionType): Promise<Balance>;
26
26
  }