@arcblock/did 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
  > Javascript library to manipulate ArcBlock DID: <https://github.com/ArcBlock/abt-did-spec>
8
8
 
@@ -49,4 +49,4 @@ console.log(`abt:did:${userDID}`);
49
49
 
50
50
  ## Documentation
51
51
 
52
- For full documentation, checkout [https://ocap-js.netlify.com](https://ocap-js.netlify.com/)
52
+ For full documentation, checkout [https://asset-chain.netlify.com](https://asset-chain.netlify.com/)
package/lib/index.d.ts CHANGED
@@ -1,5 +1,13 @@
1
1
  // Generate by [js2dts@0.3.3](https://github.com/whxaxes/js2dts#readme)
2
2
 
3
+ /**
4
+ * Ensure the hex length is even number, 2, 4, 6, 8
5
+ *
6
+ * @param {string} hex
7
+ * @param {number} length
8
+ * @returns {string} hex
9
+ */
10
+ declare function toStrictHex(hex: string, length: number): string;
3
11
  /**
4
12
  * Convert did to address: remove `did:abt:` prefix
5
13
  *
@@ -18,6 +26,34 @@ declare function toAddress(did: string): string;
18
26
  * @returns {string}
19
27
  */
20
28
  declare function toDid(address: any): string;
29
+ /**
30
+ * Checks if the given string is an address
31
+ *
32
+ * @method isEthereumDid
33
+ * @param {String} address the given HEX address
34
+ * @return {Boolean}
35
+ */
36
+ declare function isEthereumDid(did: any): boolean;
37
+ declare function isEthereumType(type: any): any;
38
+ /**
39
+ * Get type info from did (base58 format)
40
+ *
41
+ * @public
42
+ * @static
43
+ * @param {string} did - address string
44
+ * @param {boolean} [returnString=true]
45
+ * @returns {object} wallet type {@see @arcblock/did#DidType}
46
+ */
47
+ declare function toTypeInfo(did: string, returnString?: boolean): object;
48
+ /**
49
+ * Convert type info object to hex string
50
+ *
51
+ * @public
52
+ * @static
53
+ * @param {object} type - wallet type, {@see @arcblock/did#DidType}
54
+ * @returns string
55
+ */
56
+ declare function fromTypeInfo(type: object): string;
21
57
  /**
22
58
  * The structure of a forge wallet type
23
59
  *
@@ -48,21 +84,12 @@ declare function toDid(address: any): string;
48
84
  * hash: types.HashType.SHA3,
49
85
  * });
50
86
  */
51
- declare function DidType(type?: string | DidType_1): any;
52
- declare const _Lib: _Lib.T102;
87
+ declare function DidType(type?: DidType | string): object;
88
+ declare const _Lib: _Lib.T100;
53
89
  declare namespace _Lib {
54
90
  export interface T100 {
55
- [key: string]: any;
56
- }
57
- export interface T101 {
58
- role: any;
59
- pk: any;
60
- hash: any;
61
- address: any;
62
- }
63
- export interface T102 {
64
91
  types: any;
65
- toStrictHex: (hex: string, length: number) => string;
92
+ toStrictHex: typeof toStrictHex;
66
93
  fromSecretKey: (sk: string, type: any) => string;
67
94
  fromPublicKey: (pk: string, type: any) => string;
68
95
  fromPublicKeyHash: (buffer: any, type: any) => string;
@@ -71,11 +98,13 @@ declare namespace _Lib {
71
98
  toDid: typeof toDid;
72
99
  isFromPublicKey: (did: string, pk: string) => boolean;
73
100
  isValid: (did: string) => boolean;
74
- toTypeInfo: (did: string, returnString?: boolean) => any;
75
- fromTypeInfo: (type: any) => string;
101
+ isEthereumDid: typeof isEthereumDid;
102
+ isEthereumType: typeof isEthereumType;
103
+ toTypeInfo: typeof toTypeInfo;
104
+ fromTypeInfo: typeof fromTypeInfo;
76
105
  DidType: typeof DidType;
77
- DID_TYPE_FORGE: _Lib.T101;
78
- DID_TYPE_ETHEREUM: _Lib.T101;
106
+ DID_TYPE_ARCBLOCK: typeof DID_TYPE_ARCBLOCK;
107
+ DID_TYPE_ETHEREUM: typeof DID_TYPE_ETHEREUM;
79
108
  }
80
109
  }
81
110
  export = _Lib;
package/lib/index.js CHANGED
@@ -14,7 +14,7 @@ const {
14
14
  fromTypeInfo,
15
15
  isEthereumType,
16
16
  isEthereumDid,
17
- DID_TYPE_FORGE,
17
+ DID_TYPE_ARCBLOCK,
18
18
  DID_TYPE_ETHEREUM,
19
19
  toChecksumAddress,
20
20
  } = require('./type');
@@ -173,9 +173,12 @@ module.exports = {
173
173
  isFromPublicKey,
174
174
  isValid,
175
175
 
176
+ isEthereumDid,
177
+ isEthereumType,
178
+
176
179
  toTypeInfo,
177
180
  fromTypeInfo,
178
181
  DidType,
179
- DID_TYPE_FORGE,
182
+ DID_TYPE_ARCBLOCK,
180
183
  DID_TYPE_ETHEREUM,
181
184
  };
package/lib/type.d.ts ADDED
@@ -0,0 +1,103 @@
1
+ /**
2
+ * The structure of a forge wallet type
3
+ */
4
+ export type DidType = {
5
+ /**
6
+ * - Enum field to identify wallet role type
7
+ */
8
+ role: number;
9
+ /**
10
+ * - Crypto algorithm to derive publicKey from the secretKey
11
+ */
12
+ pk: number;
13
+ /**
14
+ * - Hash algorithm used to hash data before sign them
15
+ */
16
+ hash: number;
17
+ };
18
+ export namespace DID_TYPE_ARCBLOCK {
19
+ const role: any;
20
+ const pk: any;
21
+ const hash: any;
22
+ const address: any;
23
+ }
24
+ export namespace DID_TYPE_ETHEREUM {
25
+ const role_1: any;
26
+ export { role_1 as role };
27
+ const pk_1: any;
28
+ export { pk_1 as pk };
29
+ const hash_1: any;
30
+ export { hash_1 as hash };
31
+ const address_1: any;
32
+ export { address_1 as address };
33
+ }
34
+ /**
35
+ * Convert type info object to hex string
36
+ *
37
+ * @public
38
+ * @static
39
+ * @param {object} type - wallet type, {@see @arcblock/did#DidType}
40
+ * @returns string
41
+ */
42
+ export function fromTypeInfo(type: object): string;
43
+ /**
44
+ * Get type info from did (base58 format)
45
+ *
46
+ * @public
47
+ * @static
48
+ * @param {string} did - address string
49
+ * @param {boolean} [returnString=true]
50
+ * @returns {object} wallet type {@see @arcblock/did#DidType}
51
+ */
52
+ export function toTypeInfo(did: string, returnString?: boolean): object;
53
+ export function isEthereumType(type: any): any;
54
+ /**
55
+ * Checks if the given string is an address
56
+ *
57
+ * @method isEthereumDid
58
+ * @param {String} address the given HEX address
59
+ * @return {Boolean}
60
+ */
61
+ export function isEthereumDid(did: any): boolean;
62
+ /**
63
+ * Converts to a checksum address
64
+ *
65
+ * @method toChecksumAddress
66
+ * @param {String} address the given HEX address
67
+ * @return {String}
68
+ */
69
+ export function toChecksumAddress(address: string): string;
70
+ /**
71
+ * The structure of a forge wallet type
72
+ *
73
+ * @public
74
+ * @static
75
+ * @global
76
+ * @typedef {Object} DidType
77
+ * @prop {number} role - Enum field to identify wallet role type
78
+ * @prop {number} pk - Crypto algorithm to derive publicKey from the secretKey
79
+ * @prop {number} hash - Hash algorithm used to hash data before sign them
80
+ */
81
+ /**
82
+ * Create an wallet type object that be used as param to create a new wallet
83
+ *
84
+ * @public
85
+ * @static
86
+ * @param {DidType|string} [type='default']
87
+ * @returns {object}
88
+ * @example
89
+ * const assert = require('assert');
90
+ * const { DidType } = require('@arcblock/did');
91
+ * const { types } = require('@ocap/mcrypto');
92
+ *
93
+ * const type = DidType({
94
+ * role: types.RoleType.ROLE_APPLICATION,
95
+ * pk: types.KeyType.ED25519,
96
+ * hash: types.HashType.SHA3,
97
+ * });
98
+ */
99
+ export function DidType(type?: DidType | string): object;
100
+ export namespace DidType {
101
+ function toJSON(type: any): {};
102
+ function fromJSON(json: any): {};
103
+ }
package/lib/type.js CHANGED
@@ -1,4 +1,4 @@
1
- const BN = require('bn.js');
1
+ const { BN } = require('@ocap/util');
2
2
  const upperFirst = require('lodash/upperFirst');
3
3
  const isEqual = require('lodash/isEqual');
4
4
  const pick = require('lodash/pick');
@@ -14,7 +14,7 @@ const mapping = {
14
14
  address: 'encoding',
15
15
  };
16
16
 
17
- const DID_TYPE_FORGE = {
17
+ const DID_TYPE_ARCBLOCK = {
18
18
  role: types.RoleType.ROLE_ACCOUNT,
19
19
  pk: types.KeyType.ED25519,
20
20
  hash: types.HashType.SHA3,
@@ -146,11 +146,11 @@ const toChecksumAddress = (address) => {
146
146
  function DidType(type = 'default') {
147
147
  let input = null;
148
148
  if (type === 'default' || type === 'forge') {
149
- input = DID_TYPE_FORGE;
149
+ input = DID_TYPE_ARCBLOCK;
150
150
  } else if (type === 'eth') {
151
151
  input = DID_TYPE_ETHEREUM;
152
152
  } else {
153
- input = { ...DID_TYPE_FORGE, ...type };
153
+ input = { ...DID_TYPE_ARCBLOCK, ...type };
154
154
  }
155
155
 
156
156
  const { role, pk, hash, address } = input;
@@ -269,7 +269,7 @@ const toTypeInfo = (did, returnString = false) => {
269
269
  };
270
270
 
271
271
  module.exports = {
272
- DID_TYPE_FORGE,
272
+ DID_TYPE_ARCBLOCK,
273
273
  DID_TYPE_ETHEREUM,
274
274
  fromTypeInfo,
275
275
  toTypeInfo,
package/lib/util.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ export const DID_PREFIX: "did:abt:";
2
+ /**
3
+ * Convert number to bit string with predefined length
4
+ *
5
+ * @param {string} decimal
6
+ * @param {number} length
7
+ * @returns String
8
+ */
9
+ export function toBits(decimal: string, length: number): any;
10
+ /**
11
+ * Convert did to bytes with length of 26
12
+ *
13
+ * @param {string} did
14
+ * @returns {Buffer}
15
+ */
16
+ export function toBytes(did: string): Buffer;
17
+ /**
18
+ * Ensure the hex length is even number, 2, 4, 6, 8
19
+ *
20
+ * @param {string} hex
21
+ * @param {number} length
22
+ * @returns {string} hex
23
+ */
24
+ export function toStrictHex(hex: string, length: number): string;
package/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
2
  "name": "@arcblock/did",
3
- "version": "1.6.5",
3
+ "version": "1.6.10",
4
4
  "description": "Javascript lib to work with ArcBlock DID",
5
5
  "keywords": [
6
- "forge",
7
6
  "arcblock",
8
7
  "blockchain",
9
8
  "did",
@@ -17,39 +16,42 @@
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/did/did",
19
+ "contributors": [
20
+ "wangshijun <shijun@arcblock.io> (https://github.com/wangshijun)"
21
+ ],
22
+ "homepage": "https://github.com/ArcBlock/asset-chain/tree/master/did/did",
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": "^24.8.0"
29
+ "jest": "^27.3.1"
28
30
  },
29
31
  "repository": {
30
32
  "type": "git",
31
- "url": "git+https://github.com/ArcBlock/ocap-js.git"
33
+ "url": "git+https://github.com/ArcBlock/asset-chain.git"
32
34
  },
33
35
  "scripts": {
34
36
  "lint": "eslint tests lib",
35
37
  "lint:fix": "eslint --fix tests lib",
36
38
  "docs": "yarn gen-dts && yarn gen-docs && yarn cleanup-docs && yarn format-docs",
37
- "cleanup-docs": "node ../../tools/cleanup-docs.js docs/README.md $npm_package_name",
39
+ "cleanup-docs": "node ../../scripts/cleanup-docs.js docs/README.md $npm_package_name",
38
40
  "gen-docs": "jsdoc2md lib/index.js > docs/README.md",
39
41
  "gen-dts": "j2d lib/index.js",
40
42
  "format-docs": "remark . -o",
41
- "test": "node tools/jest.js",
43
+ "test": "jest --forceExit --detectOpenHandles",
42
44
  "coverage": "yarn test -- --coverage"
43
45
  },
44
46
  "bugs": {
45
- "url": "https://github.com/ArcBlock/ocap-js/issues"
47
+ "url": "https://github.com/ArcBlock/asset-chain/issues"
46
48
  },
47
49
  "dependencies": {
48
- "@ocap/mcrypto": "^1.6.5",
49
- "@ocap/util": "^1.6.5",
50
- "bn.js": "^5.1.3",
51
- "debug": "^4.3.1",
52
- "lodash": "^4.17.20"
50
+ "@ocap/mcrypto": "1.6.10",
51
+ "@ocap/util": "1.6.10",
52
+ "bn.js": "^5.2.0",
53
+ "debug": "^4.3.3",
54
+ "lodash": "^4.17.21"
53
55
  },
54
- "gitHead": "5779448f13824de38978df3c84c9da0c1e1ad989"
56
+ "gitHead": "ab272e8db3a15c6571cc7fae7cc3d3e0fdd4bdb1"
55
57
  }