@arcblock/did-util 1.6.3 → 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 +5 -5
- package/lib/index.d.ts +30 -0
- package/lib/index.js +40 -2
- package/package.json +21 -23
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/prettier/prettier)
|
|
4
4
|
[](https://docs.arcblock.io)
|
|
5
|
-
[](https://gitter.im/ArcBlock/community?utm_source=badge
|
|
5
|
+
[](https://gitter.im/ArcBlock/community?utm_source=badge\&utm_medium=badge\&utm_campaign=pr-badge)
|
|
6
6
|
|
|
7
7
|
> Helper functions to calculate did
|
|
8
8
|
|
|
@@ -61,11 +61,11 @@ module.exports = new Authenticator({
|
|
|
61
61
|
|
|
62
62
|
## Documentation
|
|
63
63
|
|
|
64
|
-
For full documentation, checkout [https://
|
|
64
|
+
For full documentation, checkout [https://asset-chain.netlify.com](https://asset-chain.netlify.com/)
|
|
65
65
|
|
|
66
66
|
|
|
67
67
|
## Contributors
|
|
68
68
|
|
|
69
|
-
| Name | Website
|
|
70
|
-
| -------------- |
|
|
71
|
-
| **wangshijun** | <https://
|
|
69
|
+
| Name | Website |
|
|
70
|
+
| -------------- | ------------------------------- |
|
|
71
|
+
| **wangshijun** | <https://github.com/wangshijun> |
|
package/lib/index.d.ts
CHANGED
|
@@ -86,6 +86,33 @@ declare function toTetherAddress(hash: string): string;
|
|
|
86
86
|
* @returns {string} swap address without `did:abt:` prefix
|
|
87
87
|
*/
|
|
88
88
|
declare function toSwapAddress(hash: string): string;
|
|
89
|
+
/**
|
|
90
|
+
* Create an token address
|
|
91
|
+
*
|
|
92
|
+
* @public
|
|
93
|
+
* @static
|
|
94
|
+
* @param {object} itx - an object of `CreateTokenTx`
|
|
95
|
+
* @returns {string} token address without `did:abt:` prefix
|
|
96
|
+
*/
|
|
97
|
+
declare function toTokenAddress(itx: any): string;
|
|
98
|
+
/**
|
|
99
|
+
* Create an factory address
|
|
100
|
+
*
|
|
101
|
+
* @public
|
|
102
|
+
* @static
|
|
103
|
+
* @param {object} itx - an object of `CreateFactoryTx`
|
|
104
|
+
* @returns {string} factory address without `did:abt:` prefix
|
|
105
|
+
*/
|
|
106
|
+
declare function toFactoryAddress(itx: any): string;
|
|
107
|
+
/**
|
|
108
|
+
* Create an rollup address
|
|
109
|
+
*
|
|
110
|
+
* @public
|
|
111
|
+
* @static
|
|
112
|
+
* @param {object} itx - an object of `CreateRollupTx`
|
|
113
|
+
* @returns {string} rollup address without `did:abt:` prefix
|
|
114
|
+
*/
|
|
115
|
+
declare function toRollupAddress(itx: any): string;
|
|
89
116
|
declare const _Lib: _Lib.T100;
|
|
90
117
|
declare namespace _Lib {
|
|
91
118
|
export interface T100 {
|
|
@@ -98,6 +125,9 @@ declare namespace _Lib {
|
|
|
98
125
|
toStakeDid: typeof toStakeDid;
|
|
99
126
|
toTetherAddress: typeof toTetherAddress;
|
|
100
127
|
toSwapAddress: typeof toSwapAddress;
|
|
128
|
+
toTokenAddress: typeof toTokenAddress;
|
|
129
|
+
toFactoryAddress: typeof toFactoryAddress;
|
|
130
|
+
toRollupAddress: typeof toRollupAddress;
|
|
101
131
|
}
|
|
102
132
|
}
|
|
103
133
|
export = _Lib;
|
package/lib/index.js
CHANGED
|
@@ -25,6 +25,30 @@ function toAssetAddress(itx) {
|
|
|
25
25
|
return toItxAddress(itx, 'CreateAssetTx', types.RoleType.ROLE_ASSET);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Create an factory address
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
* @static
|
|
33
|
+
* @param {object} itx - an object of `CreateFactoryTx`
|
|
34
|
+
* @returns {string} factory address without `did:abt:` prefix
|
|
35
|
+
*/
|
|
36
|
+
function toFactoryAddress(itx) {
|
|
37
|
+
return toItxAddress(itx, 'CreateFactoryTx', types.RoleType.ROLE_FACTORY);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Create an token address
|
|
42
|
+
*
|
|
43
|
+
* @public
|
|
44
|
+
* @static
|
|
45
|
+
* @param {object} itx - an object of `CreateTokenTx`
|
|
46
|
+
* @returns {string} token address without `did:abt:` prefix
|
|
47
|
+
*/
|
|
48
|
+
function toTokenAddress(itx) {
|
|
49
|
+
return toItxAddress(itx, 'CreateTokenTx', types.RoleType.ROLE_TOKEN);
|
|
50
|
+
}
|
|
51
|
+
|
|
28
52
|
/**
|
|
29
53
|
* Create an asset did
|
|
30
54
|
*
|
|
@@ -53,7 +77,6 @@ function toItxAddress(itx, type, role = types.RoleType.ROLE_TX) {
|
|
|
53
77
|
}
|
|
54
78
|
|
|
55
79
|
const message = createMessage(type, itx);
|
|
56
|
-
// console.log({ message: message.toObject(), itx });
|
|
57
80
|
const itxBytes = message.serializeBinary();
|
|
58
81
|
const hash = Hasher.SHA3.hash256(itxBytes);
|
|
59
82
|
const address = fromHash(hash, role);
|
|
@@ -103,7 +126,7 @@ function toDelegateAddress(addr1, addr2) {
|
|
|
103
126
|
const addr2Buffer = Buffer.from(addr2);
|
|
104
127
|
const buffer = Buffer.concat([addr1Buffer, addr2Buffer]);
|
|
105
128
|
const hash = Hasher.SHA3.hash256(buffer);
|
|
106
|
-
return fromHash(hash, types.RoleType.
|
|
129
|
+
return fromHash(hash, types.RoleType.ROLE_DELEGATION);
|
|
107
130
|
}
|
|
108
131
|
|
|
109
132
|
/**
|
|
@@ -143,6 +166,18 @@ function toStakeDid(sender, receiver) {
|
|
|
143
166
|
toDid(toStakeAddress(sender, receiver));
|
|
144
167
|
}
|
|
145
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Create an rollup address
|
|
171
|
+
*
|
|
172
|
+
* @public
|
|
173
|
+
* @static
|
|
174
|
+
* @param {object} itx - an object of `CreateRollupTx`
|
|
175
|
+
* @returns {string} rollup address without `did:abt:` prefix
|
|
176
|
+
*/
|
|
177
|
+
function toRollupAddress(itx) {
|
|
178
|
+
return toItxAddress(itx, 'CreateRollupTx', types.RoleType.ROLE_ROLLUP);
|
|
179
|
+
}
|
|
180
|
+
|
|
146
181
|
module.exports = {
|
|
147
182
|
toAssetAddress,
|
|
148
183
|
toAssetDid,
|
|
@@ -153,4 +188,7 @@ module.exports = {
|
|
|
153
188
|
toStakeDid,
|
|
154
189
|
toTetherAddress,
|
|
155
190
|
toSwapAddress,
|
|
191
|
+
toTokenAddress,
|
|
192
|
+
toFactoryAddress,
|
|
193
|
+
toRollupAddress,
|
|
156
194
|
};
|
package/package.json
CHANGED
|
@@ -1,49 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/did-util",
|
|
3
3
|
"description": "Helper function to calculate did",
|
|
4
|
-
"version": "1.6.
|
|
4
|
+
"version": "1.6.10",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "wangshijun",
|
|
7
7
|
"email": "shijun@arcblock.io",
|
|
8
8
|
"url": "https://github.com/wangshijun"
|
|
9
9
|
},
|
|
10
10
|
"bugs": {
|
|
11
|
-
"url": "https://github.com/ArcBlock/
|
|
11
|
+
"url": "https://github.com/ArcBlock/asset-chain/issues",
|
|
12
12
|
"email": "shijun@arcblock.io"
|
|
13
13
|
},
|
|
14
14
|
"publishConfig": {
|
|
15
15
|
"access": "public"
|
|
16
16
|
},
|
|
17
17
|
"contributors": [
|
|
18
|
-
"wangshijun <shijun@arcblock.io> (https://
|
|
18
|
+
"wangshijun <shijun@arcblock.io> (https://github.com/wangshijun)"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@arcblock/did": "
|
|
22
|
-
"@ocap/mcrypto": "
|
|
23
|
-
"@ocap/message": "
|
|
24
|
-
"@ocap/proto": "
|
|
25
|
-
"@ocap/util": "
|
|
26
|
-
"@ocap/wallet": "
|
|
21
|
+
"@arcblock/did": "1.6.10",
|
|
22
|
+
"@ocap/mcrypto": "1.6.10",
|
|
23
|
+
"@ocap/message": "1.6.10",
|
|
24
|
+
"@ocap/proto": "1.6.10",
|
|
25
|
+
"@ocap/util": "1.6.10",
|
|
26
|
+
"@ocap/wallet": "1.6.10"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"jest": "^
|
|
30
|
-
"remark-cli": "^
|
|
31
|
-
"remark-preset-github": "^
|
|
29
|
+
"jest": "^27.3.1",
|
|
30
|
+
"remark-cli": "^10.0.1",
|
|
31
|
+
"remark-preset-github": "^4.0.1"
|
|
32
32
|
},
|
|
33
33
|
"remarkConfig": {
|
|
34
34
|
"plugins": [
|
|
35
35
|
"preset-github",
|
|
36
36
|
[
|
|
37
|
-
"validate-links",
|
|
38
37
|
{
|
|
39
|
-
"repository": "ArcBlock/
|
|
38
|
+
"repository": "ArcBlock/asset-chain"
|
|
40
39
|
}
|
|
41
40
|
]
|
|
42
41
|
]
|
|
43
42
|
},
|
|
44
|
-
"homepage": "https://github.com/ArcBlock/
|
|
43
|
+
"homepage": "https://github.com/ArcBlock/asset-chain/tree/master/did/did-util",
|
|
45
44
|
"keywords": [
|
|
46
|
-
"forge",
|
|
47
45
|
"blockchain",
|
|
48
46
|
"arcblock",
|
|
49
47
|
"sdk",
|
|
@@ -56,18 +54,18 @@
|
|
|
56
54
|
],
|
|
57
55
|
"repository": {
|
|
58
56
|
"type": "git",
|
|
59
|
-
"url": "https://github.com/ArcBlock/
|
|
57
|
+
"url": "https://github.com/ArcBlock/asset-chain/tree/master/did/did-util"
|
|
60
58
|
},
|
|
61
59
|
"scripts": {
|
|
62
60
|
"lint": "eslint lib tests",
|
|
63
61
|
"lint:fix": "eslint --fix lib tests",
|
|
64
|
-
"docs": "yarn
|
|
65
|
-
"cleanup-docs": "node ../../
|
|
66
|
-
"
|
|
67
|
-
"
|
|
62
|
+
"docs": "yarn gen-dts && yarn gen-docs && yarn cleanup-docs && yarn format-docs",
|
|
63
|
+
"cleanup-docs": "node ../../scripts/cleanup-docs.js docs/README.md $npm_package_name",
|
|
64
|
+
"gen-docs": "jsdoc2md lib/index.js > docs/README.md",
|
|
65
|
+
"gen-dts": "j2d lib/index.js",
|
|
68
66
|
"format-docs": "remark . -o",
|
|
69
|
-
"test": "
|
|
67
|
+
"test": "jest --forceExit --detectOpenHandles",
|
|
70
68
|
"coverage": "yarn test -- --coverage"
|
|
71
69
|
},
|
|
72
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "ab272e8db3a15c6571cc7fae7cc3d3e0fdd4bdb1"
|
|
73
71
|
}
|