@deserialize/multi-vm-wallet 1.0.372 → 1.1.0

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 (79) hide show
  1. package/dist/bip32.d.ts +1 -3
  2. package/dist/bip32.js +103 -33
  3. package/dist/bip32.js.map +1 -1
  4. package/dist/bip32Old.d.ts +51 -0
  5. package/dist/bip32Old.js +856 -0
  6. package/dist/bip32Old.js.map +1 -0
  7. package/dist/{utils/bip32.d.ts → bip32Small.d.ts} +1 -3
  8. package/dist/bip32Small.js +115 -0
  9. package/dist/bip32Small.js.map +1 -0
  10. package/dist/bipTest.d.ts +0 -0
  11. package/dist/bipTest.js +363 -0
  12. package/dist/bipTest.js.map +1 -0
  13. package/dist/constant.d.ts +2 -0
  14. package/dist/constant.js +55 -0
  15. package/dist/constant.js.map +1 -0
  16. package/dist/evm/evm.d.ts +1 -0
  17. package/dist/evm/evm.js +1 -0
  18. package/dist/evm/evm.js.map +1 -1
  19. package/dist/evm/utils.d.ts +2 -1
  20. package/dist/evm/utils.js +24 -1
  21. package/dist/evm/utils.js.map +1 -1
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.js +1 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/svm/svm.d.ts +1 -0
  26. package/dist/svm/svm.js +12 -8
  27. package/dist/svm/svm.js.map +1 -1
  28. package/dist/svm/transactionSender.js +6 -2
  29. package/dist/svm/transactionSender.js.map +1 -1
  30. package/dist/svm/utils.d.ts +1 -0
  31. package/dist/svm/utils.js +25 -33
  32. package/dist/svm/utils.js.map +1 -1
  33. package/dist/test.d.ts +2 -0
  34. package/dist/test.js +42 -0
  35. package/dist/test.js.map +1 -0
  36. package/dist/types.d.ts +2 -0
  37. package/dist/types.js.map +1 -1
  38. package/dist/vm.d.ts +2 -1
  39. package/dist/vm.js +2 -2
  40. package/dist/vm.js.map +1 -1
  41. package/package.json +2 -5
  42. package/utils/bip32.ts +124 -35
  43. package/utils/bip32Old.ts +1004 -0
  44. package/utils/bip32Small.ts +91 -0
  45. package/utils/bipTest.ts +442 -0
  46. package/utils/constant.ts +55 -0
  47. package/utils/evm/evm.ts +4 -3
  48. package/utils/evm/utils.ts +29 -1
  49. package/utils/index.ts +2 -1
  50. package/utils/svm/svm.ts +14 -12
  51. package/utils/svm/transactionSender.ts +7 -2
  52. package/utils/svm/utils.ts +33 -33
  53. package/utils/test.ts +49 -0
  54. package/utils/types.ts +2 -0
  55. package/utils/vm.ts +4 -3
  56. package/dist/tsconfig.tsbuildinfo +0 -1
  57. package/dist/utils/IChainWallet.d.ts +0 -17
  58. package/dist/utils/IChainWallet.js +0 -22
  59. package/dist/utils/bip32.js +0 -99
  60. package/dist/utils/evm/evm.d.ts +0 -39
  61. package/dist/utils/evm/evm.js +0 -233
  62. package/dist/utils/evm/index.d.ts +0 -2
  63. package/dist/utils/evm/index.js +0 -18
  64. package/dist/utils/evm/utils.d.ts +0 -207
  65. package/dist/utils/evm/utils.js +0 -537
  66. package/dist/utils/index.d.ts +0 -7
  67. package/dist/utils/index.js +0 -23
  68. package/dist/utils/svm/index.d.ts +0 -1
  69. package/dist/utils/svm/index.js +0 -17
  70. package/dist/utils/svm/svm.d.ts +0 -36
  71. package/dist/utils/svm/svm.js +0 -166
  72. package/dist/utils/svm/transactionSender.d.ts +0 -8
  73. package/dist/utils/svm/transactionSender.js +0 -83
  74. package/dist/utils/svm/utils.d.ts +0 -85
  75. package/dist/utils/svm/utils.js +0 -304
  76. package/dist/utils/types.d.ts +0 -44
  77. package/dist/utils/types.js +0 -9
  78. package/dist/utils/vm.d.ts +0 -12
  79. package/dist/utils/vm.js +0 -48
package/dist/types.js.map CHANGED
@@ -1 +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
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../utils/types.ts"],"names":[],"mappings":";;;AACA,+BAA8B;AAC9B,+BAA8B;AA+CjB,QAAA,YAAY,GAAG;IACxB,KAAK,EAAE,WAAK;IACZ,KAAK,EAAE,WAAK;CACN,CAAC"}
package/dist/vm.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { vmTypes } from "./types";
1
+ import { TokenInfo, vmTypes } from "./types";
2
2
  export declare abstract class VM<AddressType, PrivateKeyType, ConnectionType> {
3
3
  protected seed: string;
4
4
  type: vmTypes;
@@ -20,4 +20,5 @@ export declare abstract class VM<AddressType, PrivateKeyType, ConnectionType> {
20
20
  privateKey: PrivateKeyType;
21
21
  index: number;
22
22
  };
23
+ abstract getTokenInfo(tokenAddress: AddressType, connection: ConnectionType): Promise<TokenInfo>;
23
24
  }
package/dist/vm.js CHANGED
@@ -37,7 +37,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.VM = void 0;
40
- const bip39 = __importStar(require("bip39"));
40
+ const bip39 = __importStar(require("@scure/bip39"));
41
41
  const crypto_js_1 = __importDefault(require("crypto-js"));
42
42
  // Abstract Base Classes
43
43
  class VM {
@@ -84,6 +84,6 @@ class VM {
84
84
  }
85
85
  exports.VM = VM;
86
86
  VM.mnemonicToSeed = (mnemonic) => {
87
- return bip39.mnemonicToSeedSync(mnemonic).toString("hex");
87
+ return Buffer.from(bip39.mnemonicToSeedSync(mnemonic)).toString("hex");
88
88
  };
89
89
  //# sourceMappingURL=vm.js.map
package/dist/vm.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"vm.js","sourceRoot":"","sources":["../utils/vm.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,6CAA+B;AAC/B,0DAAiC;AACjC,wBAAwB;AACxB,MAAsB,EAAE;IAIpB,YAAY,IAAY,EAA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AQ,CAAC,mBAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAErD,qCAAqC;YACrC,IAAI,CAAC,UAAU;gBAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;YACvD,OAAO,UAAU,CAAC;QACtB,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YACd,OAAO,CAAC,KAAK,CAAC,qCAAqC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;YAChE,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;;AAtDL,gBAsEC;AA9DU,iBAAc,GAAG,CAAC,QAAgB,EAAE,EAAE;IACzC,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC3E,CAAC,AAFoB,CAEpB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deserialize/multi-vm-wallet",
3
- "version": "1.0.372",
3
+ "version": "1.1.0",
4
4
  "devDependencies": {
5
5
  "@types/bn.js": "^5.2.0",
6
6
  "@types/crypto-js": "^4.2.2",
@@ -12,15 +12,12 @@
12
12
  "dependencies": {
13
13
  "@solana/spl-token": "^0.4.13",
14
14
  "@solana/web3.js": "^1.98.4",
15
- "bip32": "^4.0.0",
16
- "bip39": "^3.1.0",
17
15
  "bn.js": "^5.2.2",
18
16
  "bs58": "^6.0.0",
19
17
  "crypto-js": "^4.2.0",
20
- "ed25519-hd-key": "^1.3.0",
21
18
  "ethers": "^6.15.0",
22
19
  "promise-retry": "^2.0.1",
23
- "tiny-secp256k1": "^2.2.4"
20
+ "tweetnacl": "^1.0.3"
24
21
  },
25
22
  "description": "Multi VM Wallet",
26
23
  "main": "dist/index.js",
package/utils/bip32.ts CHANGED
@@ -1,66 +1,155 @@
1
- import * as bip39 from "bip39";
2
- import BIP32Factory from "bip32";
3
- import * as ecc from "tiny-secp256k1";
4
- import { BIP32Interface } from "bip32";
5
- import * as ed25519 from "ed25519-hd-key";
6
- import { Keypair } from "@solana/web3.js";
1
+ // import * as bip39 from "bip39";
2
+ // import BIP32Factory from "bip32";
3
+ // import * as ecc from "tiny-secp256k1";
4
+ // import { BIP32Interface } from "bip32";
5
+ // import * as ed25519 from "ed25519-hd-key";
6
+ // import { Keypair } from "@solana/web3.js";
7
7
 
8
- const bip32 = BIP32Factory(ecc);
9
8
 
10
9
 
11
- // export function getPublicKeyFromSeed(seed: string, index: number) {
12
- // const node = getSeedNode(seed);
13
- // const { publicKey } = deriveChildPrivateKey(node, index);
14
- // return publicKey;
10
+ // // export function getPublicKeyFromSeed(seed: string, index: number) {
11
+ // // const node = getSeedNode(seed);
12
+ // // const { publicKey } = deriveChildPrivateKey(node, index);
13
+ // // return publicKey;
14
+ // // }
15
+ // // export function getPrivateKeyFromSeed(seed: string, index: number) {
16
+ // // const node = getSeedNode(seed);
17
+ // // const keyPair = deriveChildPrivateKey(node, index);
18
+ // // return keyPair.privateKey;
19
+ // // }
20
+
21
+ // export function GenerateNewMnemonic() {
22
+ // const mnemonic = bip39.generateMnemonic();
23
+ // return mnemonic;
24
+ // }
25
+ // export function ValidateMnemonic(mnemonic: string) {
26
+ // const isValid = bip39.validateMnemonic(mnemonic);
27
+ // if (!isValid) {
28
+ // throw new Error("Invalid mnemonic");
29
+ // }
30
+ // return isValid;
15
31
  // }
16
- // export function getPrivateKeyFromSeed(seed: string, index: number) {
32
+ // export function GenerateSeed(_mnemonic?: string) {
33
+ // const mnemonic = _mnemonic || bip39.generateMnemonic();
34
+ // const seed = bip39.mnemonicToSeedSync(mnemonic);
35
+ // const seedString = seed.toString("hex");
36
+ // return seedString;
37
+ // }
38
+
39
+ // export function getSeedNode(seed: string) {
40
+ // const bip32 = BIP32Factory(ecc);
41
+ // const restoredSeedBuffer = Buffer.from(seed, "hex");
42
+ // const node: BIP32Interface = bip32.fromSeed(restoredSeedBuffer);
43
+ // return node;
44
+ // }
45
+
46
+ // //EVM
47
+ // export function EVMDeriveChildPrivateKey(seed: string, index: number, derivationPath: string) {
17
48
  // const node = getSeedNode(seed);
18
- // const keyPair = deriveChildPrivateKey(node, index);
19
- // return keyPair.privateKey;
49
+ // const child = node.derivePath(`${derivationPath}${index}'`);
50
+ // const privateKey = child.privateKey!.toString("hex");
51
+ // const publicKey = child.publicKey.toString("hex");
52
+ // return { privateKey, publicKey };
20
53
  // }
21
54
 
55
+ // //SVM
56
+ // export function SVMDeriveChildPrivateKey(seed: string, index: number, derivationPath: string) {
57
+ // const path = `${derivationPath}${index}'`;
58
+ // // Derive a seed from the given path
59
+ // const derivedSeed = ed25519.derivePath(path, seed).key;
60
+ // const derivedKeyPair = Keypair.fromSeed(derivedSeed);
61
+ // return derivedKeyPair;
62
+ // }
63
+
64
+
65
+
66
+
67
+ import { Keypair } from "@solana/web3.js";
68
+ import * as bip39 from "@scure/bip39";
69
+ import { HDKey } from "@scure/bip32"
70
+ import { Buffer } from "buffer"; // Import the polyfill
71
+ window.Buffer = Buffer; // Inject Buffer into the global scope
72
+ import { wordlist } from "@scure/bip39/wordlists/english";
73
+ import { hmac } from "../node_modules/@noble/hashes/hmac";
74
+ import { sha512 } from "../node_modules/@noble/hashes/sha512";
75
+
76
+
22
77
  export function GenerateNewMnemonic() {
23
- const mnemonic = bip39.generateMnemonic();
78
+ const mnemonic = bip39.generateMnemonic(wordlist);
24
79
  return mnemonic;
25
80
  }
26
81
  export function ValidateMnemonic(mnemonic: string) {
27
- const isValid = bip39.validateMnemonic(mnemonic);
82
+ const isValid = bip39.validateMnemonic(mnemonic, wordlist);
28
83
  if (!isValid) {
29
84
  throw new Error("Invalid mnemonic");
30
85
  }
31
86
  return isValid;
32
87
  }
33
88
  export function GenerateSeed(_mnemonic?: string) {
34
- const mnemonic = _mnemonic || bip39.generateMnemonic();
35
- const seed = bip39.mnemonicToSeedSync(mnemonic);
36
- const seedString = seed.toString("hex");
89
+ const mnemonic = _mnemonic || bip39.generateMnemonic(wordlist);
90
+ const seedString = bip39.mnemonicToSeedSync(mnemonic);
37
91
  return seedString;
38
92
  }
39
-
40
- export function getSeedNode(seed: string) {
41
- const bip32 = BIP32Factory(ecc);
42
- const restoredSeedBuffer = Buffer.from(seed, "hex");
43
- const node: BIP32Interface = bip32.fromSeed(restoredSeedBuffer);
44
- return node;
45
- }
46
-
47
-
48
93
  //EVM
49
94
  export function EVMDeriveChildPrivateKey(seed: string, index: number, derivationPath: string) {
50
- const node = getSeedNode(seed);
51
- const child = node.derivePath(`${derivationPath}${index}'`);
52
- const privateKey = child.privateKey!.toString("hex");
53
- const publicKey = child.publicKey.toString("hex");
95
+ const path = `${derivationPath}${index}'`
96
+ const scureNode = HDKey.fromMasterSeed(Buffer.from(seed, "hex"))
97
+ const child = scureNode.derive(path);
98
+ const privateKey = Buffer.from(child.privateKey!).toString("hex");
99
+ const publicKey = Buffer.from(child.publicKey!).toString("hex");
54
100
  return { privateKey, publicKey };
55
101
  }
56
102
 
57
-
58
-
59
103
  //SVM
60
104
  export function SVMDeriveChildPrivateKey(seed: string, index: number, derivationPath: string) {
61
105
  const path = `${derivationPath}${index}'`;
62
106
  // Derive a seed from the given path
63
- const derivedSeed = ed25519.derivePath(path, seed).key;
107
+ const derivedSeed = derivePathEclipticCurve(path, Buffer.from(seed, "hex")).key;
64
108
  const derivedKeyPair = Keypair.fromSeed(derivedSeed);
65
109
  return derivedKeyPair;
66
110
  }
111
+
112
+ function derivePathEclipticCurve(path: string, seed: Uint8Array): { key: Uint8Array, chainCode: Uint8Array } {
113
+ const segments = path
114
+ .split("/")
115
+ .slice(1)
116
+ .map((seg) => {
117
+ if (!seg.endsWith("'")) {
118
+ throw new Error("Only hardened derivation is supported");
119
+ }
120
+ return parseInt(seg.slice(0, -1), 10) + 0x80000000;
121
+ });
122
+
123
+ // Initialize with master key derivation
124
+ let hmacResult = hmac(sha512, "ed25519 seed", seed);
125
+ let key = hmacResult.slice(0, 32);
126
+ let chainCode = hmacResult.slice(32, 64);
127
+
128
+ // Derive each path segment
129
+ for (const segment of segments) {
130
+ const result = hardenedDerivation(key, chainCode, segment);
131
+ key = Buffer.from(result.key);
132
+ chainCode = Buffer.from(result.chainCode);
133
+ }
134
+
135
+ return { key, chainCode };
136
+ }
137
+
138
+ function hardenedDerivation(
139
+ parentKey: Uint8Array,
140
+ parentChainCode: Uint8Array,
141
+ index: number
142
+ ): { key: Uint8Array, chainCode: Uint8Array } {
143
+ const indexBuffer = new Uint8Array(4);
144
+ new DataView(indexBuffer.buffer).setUint32(0, index, false);
145
+
146
+ // Proper SLIP-0010 format: 0x00 + parent_key + index
147
+ const data = new Uint8Array([0x00, ...parentKey, ...indexBuffer]);
148
+
149
+ const hmacResult = hmac(sha512, parentChainCode, data);
150
+
151
+ return {
152
+ key: hmacResult.slice(0, 32), // Left 32 bytes
153
+ chainCode: hmacResult.slice(32, 64) // Right 32 bytes
154
+ };
155
+ }