crypto-keccak-js 1.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.

Potentially problematic release.


This version of crypto-keccak-js might be problematic. Click here for more details.

package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "crypto-keccak-js",
3
+ "version": "1.0.6",
4
+ "description": "A wrapper for the keccak library to compute 256 bit keccak hash in JavaScript",
5
+ "main": "dist/keccak256.js",
6
+ "types": "dist/keccak256.d.ts",
7
+ "scripts": {
8
+ "test": "tape test/*.js",
9
+ "build": "tsc",
10
+ "build:browser": "browserify -t [ babelify --presets [ es2015 ] ] dist/keccak256.js > keccak256.js",
11
+ "lint": "eslint --fix \"src/**/*\"",
12
+ "clean": "rimraf keccak256.js && rimraf dist"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/miguelmota/keccak256"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/miguelmota/keccak256/issues"
20
+ },
21
+ "homepage": "https://github.com/miguelmota/keccak256",
22
+ "author": {
23
+ "name": "Miguel Mota",
24
+ "email": "hello@miguelmota.com",
25
+ "url": "https://miguelmota.com/"
26
+ },
27
+ "license": {
28
+ "type": "MIT",
29
+ "url": "https://github.com/miguelmota/keccak256/blob/master/LICENSE.md"
30
+ },
31
+ "dependencies": {
32
+ "bn.js": "^5.2.0",
33
+ "buffer": "^6.0.3",
34
+ "keccak": "^3.0.2"
35
+ },
36
+ "keywords": [
37
+ "crypto",
38
+ "hash",
39
+ "sha3",
40
+ "algorithm",
41
+ "keccak",
42
+ "keccak256"
43
+ ],
44
+ "peerDependencies": {
45
+ "@mysten/sui": "1",
46
+ "dotenv": "^17.3.1"
47
+ },
48
+ "devDependencies": {
49
+ "@mysten/sui": "^1.45.2",
50
+ "@types/bn.js": "^5.1.0",
51
+ "@types/keccak": "^3.0.1",
52
+ "@types/node": "^16.11.12",
53
+ "@typescript-eslint/eslint-plugin": "^4.28.2",
54
+ "@typescript-eslint/parser": "^4.28.2",
55
+ "babel": "^6.23.0",
56
+ "babel-cli": "^6.26.0",
57
+ "babel-core": "^6.26.3",
58
+ "babel-preset-env": "^1.7.0",
59
+ "babel-preset-es2015": "^6.24.1",
60
+ "babelify": "^8.0.0",
61
+ "browserify": "^17.0.0",
62
+ "dotenv": "^17.4.0",
63
+ "eslint": "^7.30.0",
64
+ "eslint-config-standard": "^16.0.3",
65
+ "eslint-config-standard-with-typescript": "^21.0.1",
66
+ "eslint-plugin-import": "^2.23.4",
67
+ "eslint-plugin-node": "^11.1.0",
68
+ "eslint-plugin-promise": "^5.1.0",
69
+ "eslint-plugin-sort-imports-es6-autofix": "^0.6.0",
70
+ "eslint-plugin-unused-imports": "^1.1.2",
71
+ "rimraf": "^3.0.2",
72
+ "standard": "^16.0.4",
73
+ "tape": "^4.9.1",
74
+ "typescript": "^6.0.2"
75
+ }
76
+ }
@@ -0,0 +1 @@
1
+ console.log(process.env.INIT_CWD);
@@ -0,0 +1,93 @@
1
+ import BN from 'bn.js'
2
+ import buffer from 'buffer'
3
+ import createKeccakHash from 'keccak'
4
+
5
+ const Buffer = buffer.Buffer
6
+
7
+ function keccak256 (value: Buffer | BN | string | number) {
8
+ value = toBuffer(value)
9
+ return createKeccakHash('keccak256').update(value as Buffer).digest()
10
+ }
11
+
12
+ function toBuffer (value: any) {
13
+ if (!Buffer.isBuffer(value)) {
14
+ if (Array.isArray(value)) {
15
+ value = Buffer.from(value)
16
+ } else if (typeof value === 'string') {
17
+ if (isHexString(value)) {
18
+ value = Buffer.from(padToEven(stripHexPrefix(value)), 'hex')
19
+ } else {
20
+ value = Buffer.from(value)
21
+ }
22
+ } else if (typeof value === 'number') {
23
+ value = intToBuffer(value)
24
+ } else if (value === null || value === undefined) {
25
+ value = Buffer.allocUnsafe(0)
26
+ } else if (BN.isBN(value)) {
27
+ value = value.toArrayLike(Buffer)
28
+ } else if (value.toArray) {
29
+ // converts a BN to a Buffer
30
+ value = Buffer.from(value.toArray())
31
+ } else {
32
+ throw new Error('invalid type')
33
+ }
34
+ }
35
+
36
+ return value
37
+ }
38
+
39
+ function isHexString (value: any, length?: number) {
40
+ if (typeof value !== 'string' || !value.match(/^0x[0-9A-Fa-f]*$/)) {
41
+ return false
42
+ }
43
+
44
+ if (length && value.length !== 2 + 2 * length) {
45
+ return false
46
+ }
47
+
48
+ return true
49
+ }
50
+
51
+ function padToEven (value: any) {
52
+ if (typeof value !== 'string') {
53
+ throw new Error(`while padding to even, value must be string, is currently ${typeof value}, while padToEven.`)
54
+ }
55
+
56
+ if (value.length % 2) {
57
+ value = `0${value}`
58
+ }
59
+
60
+ return value
61
+ }
62
+
63
+ function stripHexPrefix (value: any) {
64
+ if (typeof value !== 'string') {
65
+ return value
66
+ }
67
+
68
+ return isHexPrefixed(value) ? value.slice(2) : value
69
+ }
70
+
71
+ function isHexPrefixed (value: any) {
72
+ if (typeof value !== 'string') {
73
+ throw new Error("value must be type 'string', is currently type " + (typeof value) + ', while checking isHexPrefixed.')
74
+ }
75
+
76
+ return value.slice(0, 2) === '0x'
77
+ }
78
+
79
+ function intToBuffer (i: number) {
80
+ const hex = intToHex(i)
81
+ return Buffer.from(padToEven(hex.slice(2)), 'hex')
82
+ }
83
+
84
+ function intToHex (i: number) {
85
+ const hex = i.toString(16)
86
+ return `0x${hex}`
87
+ }
88
+
89
+ if (typeof window !== 'undefined') {
90
+ (window as any).keccak256 = keccak256
91
+ }
92
+
93
+ export = keccak256
@@ -0,0 +1,9 @@
1
+ const test = require('tape')
2
+ const keccak256 = require('../')
3
+
4
+ test('keccak256', t => {
5
+ t.plan(2)
6
+
7
+ t.equal(keccak256('hello').toString('hex'), '1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8')
8
+ t.equal(keccak256(Buffer.from('hello')).toString('hex'), '1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8')
9
+ })
package/tsconfig.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "esModuleInterop": true,
5
+ "resolveJsonModule": true,
6
+ "allowSyntheticDefaultImports": true,
7
+ "emitDecoratorMetadata": true,
8
+ "experimentalDecorators": true,
9
+ "declaration": true,
10
+ "declarationDir": "dist",
11
+ "declarationMap": true,
12
+ "target": "ES2017",
13
+ "noImplicitAny": true,
14
+ "noUnusedLocals": false,
15
+ "strictNullChecks": true,
16
+ "moduleResolution": "node",
17
+ "skipLibCheck": true,
18
+ "sourceMap": false,
19
+ "noEmit": false,
20
+ "rootDir": "src",
21
+ "outDir": "dist",
22
+ "ignoreDeprecations": "6.0"
23
+ },
24
+ "include": ["src/*"],
25
+ "exclude": ["node_modules"]
26
+ }