@octaflowlabs/onchain-sdk 1.0.0-test15 → 1.0.0-test17

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.
@@ -4,11 +4,15 @@ export { ERC20_TOKEN_CONTRACT_ABI };
4
4
  /** constants exports */
5
5
  export { GAS_LIMIT_PER_TX_TYPE } from './constants/constants';
6
6
  /** basic blockchain exports */
7
- export { buildMaxNativeTransferTx, buildUnsignedTransferTx } from './blockchain/buildUnsignedTransferTx';
7
+ export { buildMaxNativeTransferTx, buildUnsignedTransferTx, } from './blockchain/buildUnsignedTransferTx';
8
8
  export { broadcastTransaction } from './blockchain/broadcastTransaction';
9
9
  export { estimateGasLimitFromProvider } from './blockchain/estimateGasLimitFromProvider';
10
10
  export { getProvider } from './blockchain/getProvider';
11
11
  export { txStatus } from './blockchain/txStatus';
12
+ /** services exports */
13
+ export { EvmWalletService, EvmGeneratedWallet, EvmDerivedWallet, } from './services/evm-wallet-core/evmWalletService';
14
+ export { EntropySource } from './services/evm-wallet-core/entropy';
15
+ export { createWallet, signMessage, signTransaction } from './services/evm-wallet-core/signer';
12
16
  /** utils exports */
13
17
  export { getShortenTransactionHash } from './utils/getShortenTxHash';
14
18
  export { transformBigInt } from './utils/transformBigInt';
package/dist/cjs/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.NATIVE_TOKENS = exports.transformBigInt = exports.getShortenTransactionHash = exports.txStatus = exports.getProvider = exports.estimateGasLimitFromProvider = exports.broadcastTransaction = exports.buildUnsignedTransferTx = exports.buildMaxNativeTransferTx = exports.GAS_LIMIT_PER_TX_TYPE = exports.ERC20_TOKEN_CONTRACT_ABI = void 0;
6
+ exports.NATIVE_TOKENS = exports.transformBigInt = exports.getShortenTransactionHash = exports.signTransaction = exports.signMessage = exports.createWallet = exports.EvmWalletService = exports.txStatus = exports.getProvider = exports.estimateGasLimitFromProvider = exports.broadcastTransaction = exports.buildUnsignedTransferTx = exports.buildMaxNativeTransferTx = exports.GAS_LIMIT_PER_TX_TYPE = exports.ERC20_TOKEN_CONTRACT_ABI = void 0;
7
7
  /** ABIs exports */
8
8
  const ERC20_TOKEN_CONTRACT_ABI_1 = __importDefault(require("./ABIs/ERC20_TOKEN_CONTRACT_ABI"));
9
9
  exports.ERC20_TOKEN_CONTRACT_ABI = ERC20_TOKEN_CONTRACT_ABI_1.default;
@@ -22,6 +22,13 @@ var getProvider_1 = require("./blockchain/getProvider");
22
22
  Object.defineProperty(exports, "getProvider", { enumerable: true, get: function () { return getProvider_1.getProvider; } });
23
23
  var txStatus_1 = require("./blockchain/txStatus");
24
24
  Object.defineProperty(exports, "txStatus", { enumerable: true, get: function () { return txStatus_1.txStatus; } });
25
+ /** services exports */
26
+ var evmWalletService_1 = require("./services/evm-wallet-core/evmWalletService");
27
+ Object.defineProperty(exports, "EvmWalletService", { enumerable: true, get: function () { return evmWalletService_1.EvmWalletService; } });
28
+ var signer_1 = require("./services/evm-wallet-core/signer");
29
+ Object.defineProperty(exports, "createWallet", { enumerable: true, get: function () { return signer_1.createWallet; } });
30
+ Object.defineProperty(exports, "signMessage", { enumerable: true, get: function () { return signer_1.signMessage; } });
31
+ Object.defineProperty(exports, "signTransaction", { enumerable: true, get: function () { return signer_1.signTransaction; } });
25
32
  /** utils exports */
26
33
  var getShortenTxHash_1 = require("./utils/getShortenTxHash");
27
34
  Object.defineProperty(exports, "getShortenTransactionHash", { enumerable: true, get: function () { return getShortenTxHash_1.getShortenTransactionHash; } });
@@ -0,0 +1,3 @@
1
+ export interface EntropySource {
2
+ randomBytes(length: number): Uint8Array;
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,27 @@
1
+ /** local imports */
2
+ import { EntropySource } from './entropy';
3
+ export interface EvmGeneratedWallet {
4
+ address: string;
5
+ mnemonic: string;
6
+ privateKey: string;
7
+ path: string;
8
+ }
9
+ export interface EvmDerivedWallet {
10
+ address: string;
11
+ privateKey: string;
12
+ path: string;
13
+ publicKey: string;
14
+ }
15
+ export declare class EvmWalletService {
16
+ private entropy;
17
+ private readonly DEFAULT_DERIVATION_PATH;
18
+ constructor(entropy: EntropySource);
19
+ generateNewWallet(accountIndex?: number, wordCount?: 12 | 15 | 18 | 21 | 24): EvmGeneratedWallet;
20
+ generateMultipleWallets(mnemonic: string, count: number, startIndex?: number): EvmDerivedWallet[];
21
+ deriveWalletFromMnemonic(mnemonic: string, accountIndex?: number, customPath?: string): EvmDerivedWallet;
22
+ deriveFromPrivateKey(privateKey: string): Omit<EvmDerivedWallet, 'path'>;
23
+ signMessage(privateKey: string, message: string): Promise<string>;
24
+ isValidMnemonic(mnemonic: string): boolean;
25
+ private validateMnemonic;
26
+ private getEntropyForWordCount;
27
+ }
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EvmWalletService = void 0;
4
+ /** npm imports */
5
+ const ethers_1 = require("ethers");
6
+ class EvmWalletService {
7
+ constructor(entropy) {
8
+ this.entropy = entropy;
9
+ this.DEFAULT_DERIVATION_PATH = "m/44'/60'/0'/0";
10
+ }
11
+ generateNewWallet(accountIndex = 0, wordCount = 12) {
12
+ const entropy = this.getEntropyForWordCount(wordCount);
13
+ const randomBytesArray = this.entropy.randomBytes(entropy);
14
+ const customMnemonic = ethers_1.Mnemonic.fromEntropy(randomBytesArray);
15
+ const path = `${this.DEFAULT_DERIVATION_PATH}/${accountIndex}`;
16
+ const hdNode = ethers_1.HDNodeWallet.fromMnemonic(customMnemonic, path);
17
+ return {
18
+ address: hdNode.address,
19
+ mnemonic: customMnemonic.phrase,
20
+ privateKey: hdNode.privateKey,
21
+ path,
22
+ };
23
+ }
24
+ generateMultipleWallets(mnemonic, count, startIndex = 0) {
25
+ this.validateMnemonic(mnemonic);
26
+ const wallets = [];
27
+ const mnemonicObject = ethers_1.Mnemonic.fromPhrase(mnemonic);
28
+ for (let i = 0; i < count; i++) {
29
+ const accountIndex = startIndex + i;
30
+ const path = `${this.DEFAULT_DERIVATION_PATH}/${accountIndex}`;
31
+ const hdNode = ethers_1.HDNodeWallet.fromMnemonic(mnemonicObject, path);
32
+ wallets.push({
33
+ address: hdNode.address,
34
+ privateKey: hdNode.privateKey,
35
+ path,
36
+ publicKey: hdNode.publicKey,
37
+ });
38
+ }
39
+ return wallets;
40
+ }
41
+ deriveWalletFromMnemonic(mnemonic, accountIndex = 0, customPath) {
42
+ this.validateMnemonic(mnemonic);
43
+ const path = customPath || `${this.DEFAULT_DERIVATION_PATH}/${accountIndex}`;
44
+ const mnemonicObject = ethers_1.Mnemonic.fromPhrase(mnemonic);
45
+ const hdNode = ethers_1.HDNodeWallet.fromMnemonic(mnemonicObject, path);
46
+ return {
47
+ address: hdNode.address,
48
+ privateKey: hdNode.privateKey,
49
+ path,
50
+ publicKey: hdNode.publicKey,
51
+ };
52
+ }
53
+ deriveFromPrivateKey(privateKey) {
54
+ const wallet = new ethers_1.Wallet(privateKey);
55
+ return {
56
+ address: wallet.address,
57
+ privateKey: wallet.privateKey,
58
+ publicKey: wallet.signingKey.publicKey,
59
+ };
60
+ }
61
+ async signMessage(privateKey, message) {
62
+ const wallet = new ethers_1.Wallet(privateKey);
63
+ return await wallet.signMessage(message);
64
+ }
65
+ isValidMnemonic(mnemonic) {
66
+ try {
67
+ ethers_1.Mnemonic.fromPhrase(mnemonic);
68
+ return true;
69
+ }
70
+ catch {
71
+ return false;
72
+ }
73
+ }
74
+ validateMnemonic(mnemonic) {
75
+ if (!this.isValidMnemonic(mnemonic)) {
76
+ throw new Error('Invalid mnemonic phrase');
77
+ }
78
+ }
79
+ getEntropyForWordCount(wordCount) {
80
+ const entropyMap = {
81
+ 12: 16, // 128 bits
82
+ 15: 20, // 160 bits
83
+ 18: 24, // 192 bits
84
+ 21: 28, // 224 bits
85
+ 24: 32, // 256 bits
86
+ };
87
+ return entropyMap[wordCount];
88
+ }
89
+ }
90
+ exports.EvmWalletService = EvmWalletService;
@@ -0,0 +1,5 @@
1
+ /** npm imports */
2
+ import { Wallet, TransactionRequest } from 'ethers';
3
+ export declare const createWallet: (privateKey: string, rpcUrl?: string) => Wallet;
4
+ export declare const signMessage: (privateKey: string, message: string) => Promise<string>;
5
+ export declare const signTransaction: (privateKey: string, tx: TransactionRequest, rpcUrl?: string) => Promise<string>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.signTransaction = exports.signMessage = exports.createWallet = void 0;
4
+ /** npm imports */
5
+ const ethers_1 = require("ethers");
6
+ const createWallet = (privateKey, rpcUrl) => new ethers_1.Wallet(privateKey, rpcUrl ? new ethers_1.JsonRpcProvider(rpcUrl) : undefined);
7
+ exports.createWallet = createWallet;
8
+ const signMessage = async (privateKey, message) => {
9
+ const wallet = (0, exports.createWallet)(privateKey);
10
+ return wallet.signMessage(message);
11
+ };
12
+ exports.signMessage = signMessage;
13
+ const signTransaction = async (privateKey, tx, rpcUrl) => {
14
+ const wallet = (0, exports.createWallet)(privateKey, rpcUrl);
15
+ return wallet.signTransaction(tx);
16
+ };
17
+ exports.signTransaction = signTransaction;
package/dist/index.d.ts CHANGED
@@ -4,11 +4,15 @@ export { ERC20_TOKEN_CONTRACT_ABI };
4
4
  /** constants exports */
5
5
  export { GAS_LIMIT_PER_TX_TYPE } from './constants/constants';
6
6
  /** basic blockchain exports */
7
- export { buildMaxNativeTransferTx, buildUnsignedTransferTx } from './blockchain/buildUnsignedTransferTx';
7
+ export { buildMaxNativeTransferTx, buildUnsignedTransferTx, } from './blockchain/buildUnsignedTransferTx';
8
8
  export { broadcastTransaction } from './blockchain/broadcastTransaction';
9
9
  export { estimateGasLimitFromProvider } from './blockchain/estimateGasLimitFromProvider';
10
10
  export { getProvider } from './blockchain/getProvider';
11
11
  export { txStatus } from './blockchain/txStatus';
12
+ /** services exports */
13
+ export { EvmWalletService, EvmGeneratedWallet, EvmDerivedWallet, } from './services/evm-wallet-core/evmWalletService';
14
+ export { EntropySource } from './services/evm-wallet-core/entropy';
15
+ export { createWallet, signMessage, signTransaction } from './services/evm-wallet-core/signer';
12
16
  /** utils exports */
13
17
  export { getShortenTransactionHash } from './utils/getShortenTxHash';
14
18
  export { transformBigInt } from './utils/transformBigInt';
package/dist/index.js CHANGED
@@ -4,11 +4,14 @@ export { ERC20_TOKEN_CONTRACT_ABI };
4
4
  /** constants exports */
5
5
  export { GAS_LIMIT_PER_TX_TYPE } from './constants/constants';
6
6
  /** basic blockchain exports */
7
- export { buildMaxNativeTransferTx, buildUnsignedTransferTx } from './blockchain/buildUnsignedTransferTx';
7
+ export { buildMaxNativeTransferTx, buildUnsignedTransferTx, } from './blockchain/buildUnsignedTransferTx';
8
8
  export { broadcastTransaction } from './blockchain/broadcastTransaction';
9
9
  export { estimateGasLimitFromProvider } from './blockchain/estimateGasLimitFromProvider';
10
10
  export { getProvider } from './blockchain/getProvider';
11
11
  export { txStatus } from './blockchain/txStatus';
12
+ /** services exports */
13
+ export { EvmWalletService, } from './services/evm-wallet-core/evmWalletService';
14
+ export { createWallet, signMessage, signTransaction } from './services/evm-wallet-core/signer';
12
15
  /** utils exports */
13
16
  export { getShortenTransactionHash } from './utils/getShortenTxHash';
14
17
  export { transformBigInt } from './utils/transformBigInt';
@@ -0,0 +1,3 @@
1
+ export interface EntropySource {
2
+ randomBytes(length: number): Uint8Array;
3
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ /** local imports */
2
+ import { EntropySource } from './entropy';
3
+ export interface EvmGeneratedWallet {
4
+ address: string;
5
+ mnemonic: string;
6
+ privateKey: string;
7
+ path: string;
8
+ }
9
+ export interface EvmDerivedWallet {
10
+ address: string;
11
+ privateKey: string;
12
+ path: string;
13
+ publicKey: string;
14
+ }
15
+ export declare class EvmWalletService {
16
+ private entropy;
17
+ private readonly DEFAULT_DERIVATION_PATH;
18
+ constructor(entropy: EntropySource);
19
+ generateNewWallet(accountIndex?: number, wordCount?: 12 | 15 | 18 | 21 | 24): EvmGeneratedWallet;
20
+ generateMultipleWallets(mnemonic: string, count: number, startIndex?: number): EvmDerivedWallet[];
21
+ deriveWalletFromMnemonic(mnemonic: string, accountIndex?: number, customPath?: string): EvmDerivedWallet;
22
+ deriveFromPrivateKey(privateKey: string): Omit<EvmDerivedWallet, 'path'>;
23
+ signMessage(privateKey: string, message: string): Promise<string>;
24
+ isValidMnemonic(mnemonic: string): boolean;
25
+ private validateMnemonic;
26
+ private getEntropyForWordCount;
27
+ }
@@ -0,0 +1,86 @@
1
+ /** npm imports */
2
+ import { Wallet, HDNodeWallet, Mnemonic } from 'ethers';
3
+ export class EvmWalletService {
4
+ constructor(entropy) {
5
+ this.entropy = entropy;
6
+ this.DEFAULT_DERIVATION_PATH = "m/44'/60'/0'/0";
7
+ }
8
+ generateNewWallet(accountIndex = 0, wordCount = 12) {
9
+ const entropy = this.getEntropyForWordCount(wordCount);
10
+ const randomBytesArray = this.entropy.randomBytes(entropy);
11
+ const customMnemonic = Mnemonic.fromEntropy(randomBytesArray);
12
+ const path = `${this.DEFAULT_DERIVATION_PATH}/${accountIndex}`;
13
+ const hdNode = HDNodeWallet.fromMnemonic(customMnemonic, path);
14
+ return {
15
+ address: hdNode.address,
16
+ mnemonic: customMnemonic.phrase,
17
+ privateKey: hdNode.privateKey,
18
+ path,
19
+ };
20
+ }
21
+ generateMultipleWallets(mnemonic, count, startIndex = 0) {
22
+ this.validateMnemonic(mnemonic);
23
+ const wallets = [];
24
+ const mnemonicObject = Mnemonic.fromPhrase(mnemonic);
25
+ for (let i = 0; i < count; i++) {
26
+ const accountIndex = startIndex + i;
27
+ const path = `${this.DEFAULT_DERIVATION_PATH}/${accountIndex}`;
28
+ const hdNode = HDNodeWallet.fromMnemonic(mnemonicObject, path);
29
+ wallets.push({
30
+ address: hdNode.address,
31
+ privateKey: hdNode.privateKey,
32
+ path,
33
+ publicKey: hdNode.publicKey,
34
+ });
35
+ }
36
+ return wallets;
37
+ }
38
+ deriveWalletFromMnemonic(mnemonic, accountIndex = 0, customPath) {
39
+ this.validateMnemonic(mnemonic);
40
+ const path = customPath || `${this.DEFAULT_DERIVATION_PATH}/${accountIndex}`;
41
+ const mnemonicObject = Mnemonic.fromPhrase(mnemonic);
42
+ const hdNode = HDNodeWallet.fromMnemonic(mnemonicObject, path);
43
+ return {
44
+ address: hdNode.address,
45
+ privateKey: hdNode.privateKey,
46
+ path,
47
+ publicKey: hdNode.publicKey,
48
+ };
49
+ }
50
+ deriveFromPrivateKey(privateKey) {
51
+ const wallet = new Wallet(privateKey);
52
+ return {
53
+ address: wallet.address,
54
+ privateKey: wallet.privateKey,
55
+ publicKey: wallet.signingKey.publicKey,
56
+ };
57
+ }
58
+ async signMessage(privateKey, message) {
59
+ const wallet = new Wallet(privateKey);
60
+ return await wallet.signMessage(message);
61
+ }
62
+ isValidMnemonic(mnemonic) {
63
+ try {
64
+ Mnemonic.fromPhrase(mnemonic);
65
+ return true;
66
+ }
67
+ catch {
68
+ return false;
69
+ }
70
+ }
71
+ validateMnemonic(mnemonic) {
72
+ if (!this.isValidMnemonic(mnemonic)) {
73
+ throw new Error('Invalid mnemonic phrase');
74
+ }
75
+ }
76
+ getEntropyForWordCount(wordCount) {
77
+ const entropyMap = {
78
+ 12: 16, // 128 bits
79
+ 15: 20, // 160 bits
80
+ 18: 24, // 192 bits
81
+ 21: 28, // 224 bits
82
+ 24: 32, // 256 bits
83
+ };
84
+ return entropyMap[wordCount];
85
+ }
86
+ }
@@ -0,0 +1,5 @@
1
+ /** npm imports */
2
+ import { Wallet, TransactionRequest } from 'ethers';
3
+ export declare const createWallet: (privateKey: string, rpcUrl?: string) => Wallet;
4
+ export declare const signMessage: (privateKey: string, message: string) => Promise<string>;
5
+ export declare const signTransaction: (privateKey: string, tx: TransactionRequest, rpcUrl?: string) => Promise<string>;
@@ -0,0 +1,11 @@
1
+ /** npm imports */
2
+ import { Wallet, JsonRpcProvider } from 'ethers';
3
+ export const createWallet = (privateKey, rpcUrl) => new Wallet(privateKey, rpcUrl ? new JsonRpcProvider(rpcUrl) : undefined);
4
+ export const signMessage = async (privateKey, message) => {
5
+ const wallet = createWallet(privateKey);
6
+ return wallet.signMessage(message);
7
+ };
8
+ export const signTransaction = async (privateKey, tx, rpcUrl) => {
9
+ const wallet = createWallet(privateKey, rpcUrl);
10
+ return wallet.signTransaction(tx);
11
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octaflowlabs/onchain-sdk",
3
- "version": "1.0.0-test15",
3
+ "version": "1.0.0-test17",
4
4
  "description": "onchain methods for web3",
5
5
  "repository": "https://github.com/crisramb665/onchain-sdk.git",
6
6
  "license": "MIT",