@ocap/mcrypto 1.6.5 → 1.6.10

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.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
4
4
  [![docs](https://img.shields.io/badge/powered%20by-arcblock-green.svg)](https://docs.arcblock.io)
5
- [![Gitter](https://badges.gitter.im/ArcBlock/community.svg)](https://gitter.im/ArcBlock/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
5
+ [![Gitter](https://badges.gitter.im/ArcBlock/community.svg)](https://gitter.im/ArcBlock/community?utm_source=badge\&utm_medium=badge\&utm_campaign=pr-badge)
6
6
 
7
7
  > Forge [mcrypto](https://github.com/ArcBlock/mcrypto) implementation for javascript, just a wrapper around existing javascript crypto libraries.
8
8
 
@@ -37,21 +37,21 @@ const hash = Hasher.SHA2.hash256(message);
37
37
 
38
38
  ## Documentation
39
39
 
40
- For full documentation, checkout [https://ocap-js.netlify.com](https://ocap-js.netlify.com/)
40
+ For full documentation, checkout [https://asset-chain.netlify.com](https://asset-chain.netlify.com/)
41
41
 
42
42
  ## Implementation
43
43
 
44
44
  ### Hasher
45
45
 
46
- - keccakf1600: js-sha3
47
- - sha2: hash.js
48
- - sha3: js-sha3
46
+ * keccakf1600: js-sha3
47
+ * sha2: hash.js
48
+ * sha3: js-sha3
49
49
 
50
50
  ### Signer
51
51
 
52
- - [`ed25519`](https://github.com/ArcBlock/ocap-js/commit/ed25519): tweetnacl
53
- - secp256k1: elliptic
52
+ * [`ed25519`](https://github.com/ArcBlock/asset-chain/commit/ed25519): tweetnacl
53
+ * secp256k1: elliptic
54
54
 
55
55
  ### Crypter
56
56
 
57
- - aes-cbc-256: crypto-js
57
+ * aes-cbc-256: crypto-js
@@ -0,0 +1,2 @@
1
+ declare function _exports(data: any, encoding?: string): any;
2
+ export = _exports;
package/lib/index.js CHANGED
@@ -148,10 +148,13 @@ const Mcrypto = (module.exports = {
148
148
  ROLE_TX: 10,
149
149
  ROLE_TETHER: 11,
150
150
  ROLE_SWAP: 12,
151
- ROLE_DELEGATE: 13,
151
+ ROLE_DELEGATION: 13,
152
152
  ROLE_VC: 14, // verifiable credential
153
153
  ROLE_BLOCKLET: 15, // blocklet
154
154
  ROLE_REGISTRY: 16, // blocklet registry
155
+ ROLE_TOKEN: 17,
156
+ ROLE_FACTORY: 18,
157
+ ROLE_ROLLUP: 19,
155
158
  ROLE_ANY: 63,
156
159
  },
157
160
 
@@ -34,7 +34,7 @@ class Ed25519Signer extends Signer {
34
34
  * @memberof Ed25519Signer
35
35
  */
36
36
  genKeyPair(userSeed, encoding = 'hex') {
37
- const seed = userSeed ? toUint8Array(userSeed) : Uint8Array.from(randomBytes(32));
37
+ const seed = userSeed ? toUint8Array(userSeed) : new Uint8Array(randomBytes(32));
38
38
  if (seed.byteLength !== 32) {
39
39
  throw new Error('Invalid seed to generate key pair');
40
40
  }
@@ -1,5 +1,9 @@
1
1
  /* eslint-disable class-methods-use-this */
2
2
  /* eslint-disable no-useless-constructor */
3
+ const Account = require('eth-lib/lib/account');
4
+ const Hash = require('eth-lib/lib/hash');
5
+ const { isHexStrict, utf8ToHex, hexToBytes } = require('@ocap/util');
6
+
3
7
  const { Secp256k1Signer } = require('./secp256k1');
4
8
 
5
9
  /**
@@ -12,6 +16,24 @@ class EthereumSigner extends Secp256k1Signer {
12
16
  super();
13
17
  this.pkHasFormatPrefix = false;
14
18
  }
19
+
20
+ ethHash(data) {
21
+ const messageHex = isHexStrict(data) ? data : utf8ToHex(data);
22
+ const messageBytes = hexToBytes(messageHex);
23
+ const messageBuffer = Buffer.from(messageBytes);
24
+ const preamble = `\x19Ethereum Signed Message:\n${messageBytes.length}`;
25
+ const preambleBuffer = Buffer.from(preamble);
26
+ const ethMessage = Buffer.concat([preambleBuffer, messageBuffer]);
27
+ return Hash.keccak256s(ethMessage);
28
+ }
29
+
30
+ ethSign(data, privateKey) {
31
+ return Account.sign(data, privateKey);
32
+ }
33
+
34
+ ethRecover(data, signature) {
35
+ return Account.recover(data, signature);
36
+ }
15
37
  }
16
38
 
17
39
  module.exports = new EthereumSigner();
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable class-methods-use-this */
2
2
  /* eslint-disable no-useless-constructor */
3
3
  const EC = require('elliptic').ec;
4
- const BN = require('bn.js');
4
+ const { BN } = require('@ocap/util');
5
5
  const randomBytes = require('randombytes');
6
6
  const { stripHexPrefix, toHex, toBuffer, toUint8Array } = require('@ocap/util');
7
7
  const Signer = require('../protocols/signer');
@@ -44,7 +44,7 @@ class Secp256k1Signer extends Signer {
44
44
  genKeyPair(encoding = 'hex') {
45
45
  let sk = null;
46
46
  do {
47
- sk = Uint8Array.from(randomBytes(32));
47
+ sk = new Uint8Array(randomBytes(32));
48
48
  } while (!this.isValidSK(sk));
49
49
  const pk = this.getPublicKey(toHex(sk));
50
50
  return { secretKey: encode(sk, encoding), publicKey: encode(pk, encoding) };
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "@ocap/mcrypto",
3
- "version": "1.6.5",
3
+ "version": "1.6.10",
4
4
  "description": "Crypto lib that provides signer,crypter,hasher interface",
5
5
  "keywords": [
6
6
  "crypto",
7
- "forge",
8
7
  "arcblock",
9
8
  "blockchain",
10
9
  "sdk"
@@ -17,40 +16,44 @@
17
16
  "email": "shijun@arcblock.io",
18
17
  "url": "https://github.com/wangshijun"
19
18
  },
20
- "homepage": "https://github.com/ArcBlock/ocap-js/tree/master/core/mcrypto",
19
+ "contributors": [
20
+ "wangshijun <shijun@arcblock.io> (https://github.com/wangshijun)"
21
+ ],
22
+ "homepage": "https://github.com/ArcBlock/asset-chain/tree/master/core/mcrypto",
21
23
  "license": "Apache-2.0",
22
24
  "main": "lib/index.js",
23
25
  "files": [
24
26
  "lib"
25
27
  ],
26
28
  "devDependencies": {
27
- "jest": "^26.6.3",
28
- "jsdoc-to-markdown": "^5.0.0"
29
+ "jest": "^27.3.1",
30
+ "jsdoc-to-markdown": "^7.1.1"
29
31
  },
30
32
  "repository": {
31
33
  "type": "git",
32
- "url": "git+https://github.com/ArcBlock/ocap-js.git"
34
+ "url": "git+https://github.com/ArcBlock/asset-chain.git"
33
35
  },
34
36
  "scripts": {
35
37
  "lint": "eslint tests lib",
36
38
  "lint:fix": "eslint --fix tests lib",
37
- "docs": "yarn generate-dts && yarn generate-docs && yarn cleanup-docs && yarn format-docs",
38
- "cleanup-docs": "node ../../tools/cleanup-docs.js docs/README.md $npm_package_name",
39
- "generate-dts": "j2d lib/index.js",
39
+ "docs": "yarn gen-dts && yarn gen-docs && yarn cleanup-docs && yarn format-docs",
40
+ "cleanup-docs": "node ../../scripts/cleanup-docs.js docs/README.md $npm_package_name",
41
+ "gen-dts": "j2d lib/index.js",
40
42
  "prepush": "CI=1 yarn test",
41
- "test": "node tools/jest.js",
43
+ "test": "jest --forceExit --detectOpenHandles",
42
44
  "format-docs": "remark . -o",
43
- "generate-docs": "jsdoc2md lib/index.js > docs/README.md",
45
+ "gen-docs": "jsdoc2md lib/index.js > docs/README.md",
44
46
  "coverage": "yarn test -- --coverage"
45
47
  },
46
48
  "bugs": {
47
- "url": "https://github.com/ArcBlock/ocap-js/issues"
49
+ "url": "https://github.com/ArcBlock/asset-chain/issues"
48
50
  },
49
51
  "dependencies": {
50
- "@ocap/util": "^1.6.5",
51
- "bn.js": "5.1.3",
52
+ "@ocap/util": "1.6.10",
53
+ "bn.js": "5.2.0",
52
54
  "crypto-js": "^4.0.0",
53
55
  "elliptic": "^6.5.3",
56
+ "eth-lib": "^0.2.8",
54
57
  "hash.js": "^1.1.7",
55
58
  "interface": "^1.2.1",
56
59
  "js-sha3": "^0.8.0",
@@ -58,8 +61,8 @@
58
61
  "tweetnacl": "^1.0.3"
59
62
  },
60
63
  "resolutions": {
61
- "bn.js": "5.1.3",
64
+ "bn.js": "5.2.0",
62
65
  "elliptic": "6.5.3"
63
66
  },
64
- "gitHead": "5779448f13824de38978df3c84c9da0c1e1ad989"
67
+ "gitHead": "ab272e8db3a15c6571cc7fae7cc3d3e0fdd4bdb1"
65
68
  }