eth-crypto-ts 0.0.3 → 0.0.6

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,16 +1,17 @@
1
+ export declare const DEFAULT_ENTROPY_BYTES = 32;
2
+ export declare const MINIMUM_SHANNON_ENTROPY = 4;
1
3
  /**
2
- * create a privateKey from the given entropy or a new one
3
- * @param {Buffer} entropy
4
- * @return {string}
4
+ * creates a new private key
5
+ * @param { Uint8Array } entropy - optional entropy to create the private key
6
+ * @returns a new private key
5
7
  */
6
- export declare function createPrivateKey(entropy?: Buffer): string;
8
+ export declare const createPrivateKey: (entropy?: Uint8Array) => string;
7
9
  /**
8
- * creates a new object with
9
- * private-, public-Key and address
10
- * @param {Buffer?} entropy if provided, will use that as single random-source
10
+ * creates a new identity
11
+ * @param { Uint8Array } entropy - optional entropy to create the private key
12
+ * @returns a new pair of private and public key
11
13
  */
12
- export declare function createIdentity(entropy?: Buffer): {
14
+ export declare const createIdentity: (entropy?: Uint8Array) => {
13
15
  privateKey: string;
14
16
  publicKey: string;
15
- address: string;
16
17
  };
@@ -1,2 +1,2 @@
1
- import { Encrypted } from '../types';
2
- export declare function decryptWithPrivateKey(privateKey: string, encrypted: Encrypted | any): Promise<string>;
1
+ import { Encrypted } from './types';
2
+ export declare const decryptWithPrivateKey: (privateKey: string, encrypted: Encrypted) => string;
@@ -0,0 +1,2 @@
1
+ import { EncryptionOptions } from './types';
2
+ export declare const encryptWithPublicKey: (publicKey: string, message: string, options?: EncryptionOptions) => import("./types").Encrypted;
@@ -0,0 +1,18 @@
1
+ import { Encrypted, EncryptionOptions } from './types';
2
+ /**
3
+ * See https://github.com/bitchan/eccrypto for the original implementation that eth-crypto used, it's ancient and not maintained.
4
+ */
5
+ /**
6
+ * Encrypts a message using the recipient's public key.
7
+ * @param {string} publicKeyTo - The recipient's public key.
8
+ * @param {string} msg - The message to encrypt.
9
+ * @returns {Encrypted} The encrypted message.
10
+ */
11
+ export declare const encrypt: (publicKeyTo: string, msg: string, options?: EncryptionOptions) => Encrypted;
12
+ /**
13
+ * Decrypts an encrypted message using the recipient's private key.
14
+ * @param {string} privateKey - The recipient's private key.
15
+ * @param {Encrypted} opts - The encrypted message.
16
+ * @returns {string} The decrypted message.
17
+ */
18
+ export declare const decrypt: (privateKey: string, opts: Encrypted) => string;
@@ -0,0 +1 @@
1
+ export declare const keccak256: (params: string) => string;
@@ -0,0 +1,27 @@
1
+ import { createIdentity } from './create-identity';
2
+ import { sign } from './sign';
3
+ import { encryptWithPublicKey } from './encrypt-with-public-key';
4
+ import { decryptWithPrivateKey } from './decrypt-with-private-key';
5
+ import { keccak256 } from './hash';
6
+ import { publicKeyByPrivateKey } from './public-key-by-private-key';
7
+ import { recoverPublicKey } from './recoverPublicKey';
8
+ declare const hash: {
9
+ keccak256: (params: string) => string;
10
+ };
11
+ export { createIdentity, decryptWithPrivateKey, encryptWithPublicKey, hash, keccak256, publicKeyByPrivateKey, recoverPublicKey, sign, };
12
+ declare const _default: {
13
+ createIdentity: (entropy?: Uint8Array) => {
14
+ privateKey: string;
15
+ publicKey: string;
16
+ };
17
+ decryptWithPrivateKey: (privateKey: string, encrypted: import("./types").Encrypted) => string;
18
+ encryptWithPublicKey: (publicKey: string, message: string, options?: import("./types").EncryptionOptions) => import("./types").Encrypted;
19
+ hash: {
20
+ keccak256: (params: string) => string;
21
+ };
22
+ keccak256: (params: string) => string;
23
+ publicKeyByPrivateKey: (privateKey: string) => string;
24
+ recoverPublicKey: (signature: string, hash: string) => string;
25
+ sign: (privateKey: string, hash: string) => string;
26
+ };
27
+ export default _default;
@@ -2,7 +2,6 @@
2
2
  * Generate publicKey from the privateKey.
3
3
  * This creates the uncompressed publicKey,
4
4
  * where 04 has stripped from left
5
- * @param {string} privateKey
6
5
  * @returns {string}
7
6
  */
8
- export declare function publicKeyByPrivateKey(privateKey: string): string;
7
+ export declare const publicKeyByPrivateKey: (privateKey: string) => string;
@@ -4,4 +4,4 @@
4
4
  * @param {string} hash
5
5
  * @return {string} publicKey
6
6
  */
7
- export declare function recoverPublicKey(signature: string, hash: string): string;
7
+ export declare const recoverPublicKey: (signature: string, hash: string) => string;
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * signs the given message
3
- * we do not use sign from eth-lib because the pure secp256k1-version is 90% faster
4
3
  * @param {string} privateKey
5
4
  * @param {string} hash
6
5
  * @return {string} hexString
7
6
  */
8
- export declare function sign(privateKey: string, hash: string): string;
7
+ export declare const sign: (privateKey: string, hash: string) => string;
8
+ export declare const hmacSha256Sign: (key: Uint8Array, msg: Uint8Array) => Uint8Array;
@@ -4,7 +4,6 @@ export type Encrypted = {
4
4
  ciphertext: string;
5
5
  mac: string;
6
6
  };
7
- export type EncryptOptions = {
8
- iv?: Buffer;
9
- ephemPrivateKey?: Buffer;
7
+ export type EncryptionOptions = {
8
+ ephemPrivateKey?: string;
10
9
  };
@@ -1,4 +1,37 @@
1
- export declare function removeLeading0x(str: string): string;
2
- export declare function addLeading0x(str: string): string;
3
- export declare function uint8ArrayToHex(arr: any[] | Uint8Array): string;
4
- export declare function hexToUnit8Array(str: string): Uint8Array;
1
+ /**
2
+ * Returns a `Boolean` on whether or not the a `String` starts with '0x'
3
+ * @param str the string input value
4
+ * @return a boolean if it is or is not hex prefixed
5
+ * @throws if the str input is not a string
6
+ */
7
+ export declare const isHexPrefixed: (str: string) => boolean;
8
+ /**
9
+ * Removes '0x' from a given `String` if present
10
+ * @param str the string value
11
+ * @returns the string without 0x prefix
12
+ */
13
+ export declare const stripHexPrefix: (str: string) => string;
14
+ /**
15
+ * Is the string a hex string.
16
+ *
17
+ * @param value
18
+ * @param length
19
+ * @returns output the string is a hex string
20
+ */
21
+ export declare const isHexString: (value: string, length?: number) => boolean;
22
+ /**
23
+ * Adds '0x' to a given `String` if not present
24
+ * @param str the string input value
25
+ * @return the string with a 0x prefix
26
+ */
27
+ export declare const addLeading0x: (str: string) => string;
28
+ export declare const decompress: (startsWith02Or03: string) => string;
29
+ /** Helper function to concat UInt8Arrays mimicking the behaviour of the
30
+ * Buffer.concat function in Node.js
31
+ */
32
+ export declare const concatUint8Arrays: (uint8arrays: Uint8Array[]) => Uint8Array;
33
+ /**
34
+ * Converts a UTF-8 string to a Uint8Array without using TextEncoder, which is not available in mobile
35
+ * @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
36
+ */
37
+ export declare const utf8ToBytes: (str: string) => Uint8Array;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eth-crypto-ts",
3
- "version": "0.0.3",
3
+ "version": "0.0.6",
4
4
  "description": "eth-crypto library with typescript",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "module": "./dist/index.esm.js",
@@ -22,18 +22,22 @@
22
22
  "build": "rollup --config --sourcemap --validate --bundleConfigAsCjs",
23
23
  "build:prod": "npm run build --compact --environment production",
24
24
  "build:dev": "rollup --config --bundleConfigAsCjs --watch",
25
- "test": "NODE_ENV=test jest",
25
+ "test": "NODE_ENV=test jest --runInBand --detectOpenHandles --coverage",
26
26
  "test:watch": "NODE_ENV=test jest --watch",
27
27
  "lint": "eslint",
28
+ "lint:fix": "eslint --fix",
28
29
  "audit-ci": "audit-ci --config audit-ci.jsonc",
29
30
  "release": "npm publish --access-public"
30
31
  },
31
- "author": "",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/tarekbeb/eth-crypto-ts"
35
+ },
36
+ "author": "tarekbeb",
32
37
  "license": "ISC",
33
38
  "dependencies": {
34
- "eccrypto": "^1.1.6",
35
- "ethereumjs-util": "^7.1.5",
36
- "ethers": "^6.13.1",
39
+ "@noble/hashes": "^1.8.0",
40
+ "ethereum-cryptography": "^3.2.0",
37
41
  "secp256k1": "^5.0.0"
38
42
  },
39
43
  "devDependencies": {
@@ -43,18 +47,28 @@
43
47
  "@rollup/plugin-terser": "^0.4.4",
44
48
  "@rollup/plugin-typescript": "^11.1.6",
45
49
  "@types/eccrypto": "^1.1.6",
46
- "@types/secp256k1": "^4.0.6",
47
50
  "@types/jest": "^29.5.0",
51
+ "@types/secp256k1": "^4.0.6",
52
+ "@typescript-eslint/eslint-plugin": "^8.58.1",
53
+ "@typescript-eslint/parser": "^8.58.1",
48
54
  "audit-ci": "^7.0.1",
49
- "ts-jest": "^29.1.0",
50
- "jest-environment-jsdom": "^29.5.0",
51
55
  "eslint": "^9.5.0",
56
+ "eslint-plugin-prettier": "^5.5.5",
52
57
  "jest": "^29.7.0",
58
+ "jest-environment-jsdom": "^29.5.0",
59
+ "prettier": "^3.8.2",
53
60
  "rimraf": "^5.0.7",
54
61
  "rollup": "^4.18.0",
55
62
  "rollup-plugin-node-builtins": "^2.0.0",
56
63
  "rollup-plugin-node-globals": "^1.4.0",
57
64
  "rollup-plugin-polyfill-node": "^0.13.0",
65
+ "ts-jest": "^29.1.0",
58
66
  "typescript": "^5.5.2"
67
+ },
68
+ "overrides": {
69
+ "serialize-javascript": "^7.0.3",
70
+ "@tootallnate/once": "^3.0.1",
71
+ "semver": "^5.7.2",
72
+ "bl": "^0.9.5"
59
73
  }
60
74
  }
@@ -1,11 +0,0 @@
1
- import { Encrypted } from '../../types';
2
- interface CipherInterface {
3
- stringify(encrypted: Encrypted): string;
4
- parse(string: string): Encrypted;
5
- }
6
- export declare class Cipher implements CipherInterface {
7
- constructor();
8
- stringify(encrypted: Encrypted): string;
9
- parse(str: string): Encrypted;
10
- }
11
- export {};
@@ -1 +0,0 @@
1
- export declare function compress(startsWith04: any): string;
@@ -1 +0,0 @@
1
- export declare function decompress(startsWith02Or03: any): string;
@@ -1,2 +0,0 @@
1
- import { Encrypted, EncryptOptions } from '../types';
2
- export declare function encryptWithPublicKey(publicKey: string, message: string, options?: EncryptOptions): Promise<Encrypted>;
@@ -1,4 +0,0 @@
1
- export declare class Hash {
2
- constructor();
3
- keccak256(params: any | any[]): string;
4
- }