@arcblock/did-util 1.27.15 → 1.28.0
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/esm/index.d.ts +14 -9
- package/esm/index.js +49 -49
- package/lib/index.d.ts +14 -9
- package/lib/index.js +49 -52
- package/package.json +26 -15
package/esm/index.d.ts
CHANGED
|
@@ -1,33 +1,38 @@
|
|
|
1
|
-
import { TCreateAssetTx, TCreateFactoryTx, TCreateRollupTx, TCreateTokenTx
|
|
1
|
+
import { CreateTokenFactoryTx, TCreateAssetTx, TCreateFactoryTx, TCreateRollupTx, TCreateTokenTx } from "@ocap/types";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Create an itx address
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
declare function toItxAddress(itx: object, type: string, role?: number): string;
|
|
6
9
|
/**
|
|
7
10
|
* Create an asset address
|
|
8
11
|
*/
|
|
9
|
-
|
|
12
|
+
declare function toAssetAddress(itx: Partial<TCreateAssetTx>): string;
|
|
10
13
|
/**
|
|
11
14
|
* Create an asset factory address
|
|
12
15
|
*/
|
|
13
|
-
|
|
16
|
+
declare function toFactoryAddress(itx: Partial<TCreateFactoryTx>): string;
|
|
14
17
|
/**
|
|
15
18
|
* Create an token address
|
|
16
19
|
*/
|
|
17
|
-
|
|
20
|
+
declare function toTokenAddress(itx: Partial<TCreateTokenTx>): string;
|
|
18
21
|
/**
|
|
19
22
|
* Create a token factory address
|
|
20
23
|
*/
|
|
21
|
-
|
|
24
|
+
declare function toTokenFactoryAddress(itx: Partial<CreateTokenFactoryTx>): string;
|
|
22
25
|
/**
|
|
23
26
|
* Create an rollup address
|
|
24
27
|
*/
|
|
25
|
-
|
|
28
|
+
declare function toRollupAddress(itx: Partial<TCreateRollupTx>): string;
|
|
26
29
|
/**
|
|
27
30
|
* Generate an stake address, eg: the did of the stake
|
|
28
31
|
*/
|
|
29
|
-
|
|
32
|
+
declare function toStakeAddress(sender: string, receiver: string, nonce?: string): string;
|
|
30
33
|
/**
|
|
31
34
|
* Generate an delegate address, eg: the did of the delegation
|
|
32
35
|
*/
|
|
33
|
-
|
|
36
|
+
declare function toDelegateAddress(delegator: string, delegatee: string): string;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { toAssetAddress, toDelegateAddress, toFactoryAddress, toItxAddress, toRollupAddress, toStakeAddress, toTokenAddress, toTokenFactoryAddress };
|
package/esm/index.js
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { fromHash } from
|
|
3
|
-
import { createMessage } from
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { Hasher, types } from "@ocap/mcrypto";
|
|
2
|
+
import { fromHash } from "@arcblock/did";
|
|
3
|
+
import { createMessage } from "@ocap/message";
|
|
4
|
+
import { transactions } from "@ocap/proto";
|
|
5
|
+
|
|
6
|
+
//#region src/index.ts
|
|
6
7
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const message = createMessage(type, itx);
|
|
14
|
-
// @ts-ignore FIXME:
|
|
15
|
-
const itxBytes = message.serializeBinary();
|
|
16
|
-
const hash = Hasher.SHA3.hash256(itxBytes);
|
|
17
|
-
const address = fromHash(hash, role);
|
|
18
|
-
return address;
|
|
8
|
+
* Create an itx address
|
|
9
|
+
*/
|
|
10
|
+
function toItxAddress(itx, type, role = types.RoleType.ROLE_TX) {
|
|
11
|
+
if (transactions.indexOf(type) === -1) throw new Error(`Unsupported itx type ${type}`);
|
|
12
|
+
const itxBytes = createMessage(type, itx).serializeBinary();
|
|
13
|
+
return fromHash(Hasher.SHA3.hash256(itxBytes), role);
|
|
19
14
|
}
|
|
20
15
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
* Create an asset address
|
|
17
|
+
*/
|
|
18
|
+
function toAssetAddress(itx) {
|
|
19
|
+
return toItxAddress(itx, "CreateAssetTx", types.RoleType.ROLE_ASSET);
|
|
25
20
|
}
|
|
26
21
|
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
* Create an asset factory address
|
|
23
|
+
*/
|
|
24
|
+
function toFactoryAddress(itx) {
|
|
25
|
+
return toItxAddress(itx, "CreateFactoryTx", types.RoleType.ROLE_FACTORY);
|
|
31
26
|
}
|
|
32
27
|
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
* Create an token address
|
|
29
|
+
*/
|
|
30
|
+
function toTokenAddress(itx) {
|
|
31
|
+
return toItxAddress(itx, "CreateTokenTx", types.RoleType.ROLE_TOKEN);
|
|
37
32
|
}
|
|
38
33
|
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
* Create a token factory address
|
|
35
|
+
*/
|
|
36
|
+
function toTokenFactoryAddress(itx) {
|
|
37
|
+
return toItxAddress(itx, "CreateTokenFactoryTx", types.RoleType.ROLE_TOKEN_FACTORY);
|
|
43
38
|
}
|
|
44
39
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
* Create an rollup address
|
|
41
|
+
*/
|
|
42
|
+
function toRollupAddress(itx) {
|
|
43
|
+
return toItxAddress(itx, "CreateRollupTx", types.RoleType.ROLE_ROLLUP);
|
|
49
44
|
}
|
|
50
45
|
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
46
|
+
* Generate an stake address, eg: the did of the stake
|
|
47
|
+
*/
|
|
48
|
+
function toStakeAddress(sender, receiver, nonce) {
|
|
49
|
+
const buffer = Buffer.concat([
|
|
50
|
+
sender,
|
|
51
|
+
receiver,
|
|
52
|
+
nonce
|
|
53
|
+
].filter(Boolean).map((x) => Buffer.from(x)));
|
|
54
|
+
return fromHash(Hasher.SHA3.hash256(buffer), types.RoleType.ROLE_STAKE);
|
|
57
55
|
}
|
|
58
56
|
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return fromHash(hash, types.RoleType.ROLE_DELEGATION);
|
|
57
|
+
* Generate an delegate address, eg: the did of the delegation
|
|
58
|
+
*/
|
|
59
|
+
function toDelegateAddress(delegator, delegatee) {
|
|
60
|
+
const buffer = Buffer.concat([Buffer.from(delegator), Buffer.from(delegatee)]);
|
|
61
|
+
return fromHash(Hasher.SHA3.hash256(buffer), types.RoleType.ROLE_DELEGATION);
|
|
65
62
|
}
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
export { toAssetAddress, toDelegateAddress, toFactoryAddress, toItxAddress, toRollupAddress, toStakeAddress, toTokenAddress, toTokenFactoryAddress };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,33 +1,38 @@
|
|
|
1
|
-
import { TCreateAssetTx, TCreateFactoryTx, TCreateRollupTx, TCreateTokenTx
|
|
1
|
+
import { CreateTokenFactoryTx, TCreateAssetTx, TCreateFactoryTx, TCreateRollupTx, TCreateTokenTx } from "@ocap/types";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Create an itx address
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
declare function toItxAddress(itx: object, type: string, role?: number): string;
|
|
6
9
|
/**
|
|
7
10
|
* Create an asset address
|
|
8
11
|
*/
|
|
9
|
-
|
|
12
|
+
declare function toAssetAddress(itx: Partial<TCreateAssetTx>): string;
|
|
10
13
|
/**
|
|
11
14
|
* Create an asset factory address
|
|
12
15
|
*/
|
|
13
|
-
|
|
16
|
+
declare function toFactoryAddress(itx: Partial<TCreateFactoryTx>): string;
|
|
14
17
|
/**
|
|
15
18
|
* Create an token address
|
|
16
19
|
*/
|
|
17
|
-
|
|
20
|
+
declare function toTokenAddress(itx: Partial<TCreateTokenTx>): string;
|
|
18
21
|
/**
|
|
19
22
|
* Create a token factory address
|
|
20
23
|
*/
|
|
21
|
-
|
|
24
|
+
declare function toTokenFactoryAddress(itx: Partial<CreateTokenFactoryTx>): string;
|
|
22
25
|
/**
|
|
23
26
|
* Create an rollup address
|
|
24
27
|
*/
|
|
25
|
-
|
|
28
|
+
declare function toRollupAddress(itx: Partial<TCreateRollupTx>): string;
|
|
26
29
|
/**
|
|
27
30
|
* Generate an stake address, eg: the did of the stake
|
|
28
31
|
*/
|
|
29
|
-
|
|
32
|
+
declare function toStakeAddress(sender: string, receiver: string, nonce?: string): string;
|
|
30
33
|
/**
|
|
31
34
|
* Generate an delegate address, eg: the did of the delegation
|
|
32
35
|
*/
|
|
33
|
-
|
|
36
|
+
declare function toDelegateAddress(delegator: string, delegatee: string): string;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { toAssetAddress, toDelegateAddress, toFactoryAddress, toItxAddress, toRollupAddress, toStakeAddress, toTokenAddress, toTokenFactoryAddress };
|
package/lib/index.js
CHANGED
|
@@ -1,75 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.toTokenFactoryAddress = toTokenFactoryAddress;
|
|
8
|
-
exports.toRollupAddress = toRollupAddress;
|
|
9
|
-
exports.toStakeAddress = toStakeAddress;
|
|
10
|
-
exports.toDelegateAddress = toDelegateAddress;
|
|
11
|
-
const mcrypto_1 = require("@ocap/mcrypto");
|
|
12
|
-
const did_1 = require("@arcblock/did");
|
|
13
|
-
const message_1 = require("@ocap/message");
|
|
14
|
-
// @ts-ignore FIXME:
|
|
15
|
-
const proto_1 = require("@ocap/proto");
|
|
1
|
+
let _ocap_mcrypto = require("@ocap/mcrypto");
|
|
2
|
+
let _arcblock_did = require("@arcblock/did");
|
|
3
|
+
let _ocap_message = require("@ocap/message");
|
|
4
|
+
let _ocap_proto = require("@ocap/proto");
|
|
5
|
+
|
|
6
|
+
//#region src/index.ts
|
|
16
7
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function toItxAddress(itx, type, role =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const message = (0, message_1.createMessage)(type, itx);
|
|
24
|
-
// @ts-ignore FIXME:
|
|
25
|
-
const itxBytes = message.serializeBinary();
|
|
26
|
-
const hash = mcrypto_1.Hasher.SHA3.hash256(itxBytes);
|
|
27
|
-
const address = (0, did_1.fromHash)(hash, role);
|
|
28
|
-
return address;
|
|
8
|
+
* Create an itx address
|
|
9
|
+
*/
|
|
10
|
+
function toItxAddress(itx, type, role = _ocap_mcrypto.types.RoleType.ROLE_TX) {
|
|
11
|
+
if (_ocap_proto.transactions.indexOf(type) === -1) throw new Error(`Unsupported itx type ${type}`);
|
|
12
|
+
const itxBytes = (0, _ocap_message.createMessage)(type, itx).serializeBinary();
|
|
13
|
+
return (0, _arcblock_did.fromHash)(_ocap_mcrypto.Hasher.SHA3.hash256(itxBytes), role);
|
|
29
14
|
}
|
|
30
15
|
/**
|
|
31
|
-
|
|
32
|
-
|
|
16
|
+
* Create an asset address
|
|
17
|
+
*/
|
|
33
18
|
function toAssetAddress(itx) {
|
|
34
|
-
|
|
19
|
+
return toItxAddress(itx, "CreateAssetTx", _ocap_mcrypto.types.RoleType.ROLE_ASSET);
|
|
35
20
|
}
|
|
36
21
|
/**
|
|
37
|
-
|
|
38
|
-
|
|
22
|
+
* Create an asset factory address
|
|
23
|
+
*/
|
|
39
24
|
function toFactoryAddress(itx) {
|
|
40
|
-
|
|
25
|
+
return toItxAddress(itx, "CreateFactoryTx", _ocap_mcrypto.types.RoleType.ROLE_FACTORY);
|
|
41
26
|
}
|
|
42
27
|
/**
|
|
43
|
-
|
|
44
|
-
|
|
28
|
+
* Create an token address
|
|
29
|
+
*/
|
|
45
30
|
function toTokenAddress(itx) {
|
|
46
|
-
|
|
31
|
+
return toItxAddress(itx, "CreateTokenTx", _ocap_mcrypto.types.RoleType.ROLE_TOKEN);
|
|
47
32
|
}
|
|
48
33
|
/**
|
|
49
|
-
|
|
50
|
-
|
|
34
|
+
* Create a token factory address
|
|
35
|
+
*/
|
|
51
36
|
function toTokenFactoryAddress(itx) {
|
|
52
|
-
|
|
37
|
+
return toItxAddress(itx, "CreateTokenFactoryTx", _ocap_mcrypto.types.RoleType.ROLE_TOKEN_FACTORY);
|
|
53
38
|
}
|
|
54
39
|
/**
|
|
55
|
-
|
|
56
|
-
|
|
40
|
+
* Create an rollup address
|
|
41
|
+
*/
|
|
57
42
|
function toRollupAddress(itx) {
|
|
58
|
-
|
|
43
|
+
return toItxAddress(itx, "CreateRollupTx", _ocap_mcrypto.types.RoleType.ROLE_ROLLUP);
|
|
59
44
|
}
|
|
60
45
|
/**
|
|
61
|
-
|
|
62
|
-
|
|
46
|
+
* Generate an stake address, eg: the did of the stake
|
|
47
|
+
*/
|
|
63
48
|
function toStakeAddress(sender, receiver, nonce) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
49
|
+
const buffer = Buffer.concat([
|
|
50
|
+
sender,
|
|
51
|
+
receiver,
|
|
52
|
+
nonce
|
|
53
|
+
].filter(Boolean).map((x) => Buffer.from(x)));
|
|
54
|
+
return (0, _arcblock_did.fromHash)(_ocap_mcrypto.Hasher.SHA3.hash256(buffer), _ocap_mcrypto.types.RoleType.ROLE_STAKE);
|
|
67
55
|
}
|
|
68
56
|
/**
|
|
69
|
-
|
|
70
|
-
|
|
57
|
+
* Generate an delegate address, eg: the did of the delegation
|
|
58
|
+
*/
|
|
71
59
|
function toDelegateAddress(delegator, delegatee) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return (0, did_1.fromHash)(hash, mcrypto_1.types.RoleType.ROLE_DELEGATION);
|
|
60
|
+
const buffer = Buffer.concat([Buffer.from(delegator), Buffer.from(delegatee)]);
|
|
61
|
+
return (0, _arcblock_did.fromHash)(_ocap_mcrypto.Hasher.SHA3.hash256(buffer), _ocap_mcrypto.types.RoleType.ROLE_DELEGATION);
|
|
75
62
|
}
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
exports.toAssetAddress = toAssetAddress;
|
|
66
|
+
exports.toDelegateAddress = toDelegateAddress;
|
|
67
|
+
exports.toFactoryAddress = toFactoryAddress;
|
|
68
|
+
exports.toItxAddress = toItxAddress;
|
|
69
|
+
exports.toRollupAddress = toRollupAddress;
|
|
70
|
+
exports.toStakeAddress = toStakeAddress;
|
|
71
|
+
exports.toTokenAddress = toTokenAddress;
|
|
72
|
+
exports.toTokenFactoryAddress = toTokenFactoryAddress;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/did-util",
|
|
3
3
|
"description": "Helper function to calculate did",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.28.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "wangshijun",
|
|
7
7
|
"email": "shijun@arcblock.io",
|
|
@@ -18,16 +18,30 @@
|
|
|
18
18
|
"wangshijun <shijun@arcblock.io> (https://github.com/wangshijun)"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@arcblock/did": "1.
|
|
22
|
-
"@ocap/mcrypto": "1.
|
|
23
|
-
"@ocap/
|
|
24
|
-
"@ocap/
|
|
25
|
-
"@ocap/types": "1.
|
|
26
|
-
"@ocap/
|
|
27
|
-
"@ocap/
|
|
21
|
+
"@arcblock/did": "1.28.0",
|
|
22
|
+
"@ocap/mcrypto": "1.28.0",
|
|
23
|
+
"@ocap/proto": "1.28.0",
|
|
24
|
+
"@ocap/message": "1.28.0",
|
|
25
|
+
"@ocap/types": "1.28.0",
|
|
26
|
+
"@ocap/wallet": "1.28.0",
|
|
27
|
+
"@ocap/util": "1.28.0"
|
|
28
28
|
},
|
|
29
|
+
"sideEffects": false,
|
|
29
30
|
"main": "./lib/index.js",
|
|
30
|
-
"
|
|
31
|
+
"module": "./esm/index.js",
|
|
32
|
+
"types": "./esm/index.d.ts",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"import": {
|
|
36
|
+
"types": "./esm/index.d.ts",
|
|
37
|
+
"default": "./esm/index.js"
|
|
38
|
+
},
|
|
39
|
+
"require": {
|
|
40
|
+
"types": "./lib/index.d.ts",
|
|
41
|
+
"default": "./lib/index.js"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
31
45
|
"files": [
|
|
32
46
|
"lib",
|
|
33
47
|
"esm"
|
|
@@ -39,6 +53,7 @@
|
|
|
39
53
|
"eslint": "^8.57.0",
|
|
40
54
|
"jest": "^29.7.0",
|
|
41
55
|
"ts-jest": "^29.2.5",
|
|
56
|
+
"tsdown": "^0.18.4",
|
|
42
57
|
"typescript": "^5.6.2"
|
|
43
58
|
},
|
|
44
59
|
"homepage": "https://github.com/ArcBlock/blockchain/tree/master/did/did-util",
|
|
@@ -56,11 +71,7 @@
|
|
|
56
71
|
"lint:fix": "npm run lint -- --fix",
|
|
57
72
|
"test": "jest --forceExit --detectOpenHandles",
|
|
58
73
|
"coverage": "npm run test -- --coverage",
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
62
|
-
"build:esm": "tsc -p tsconfig.esm.json",
|
|
63
|
-
"build": "npm run build:cjs && npm run build:esm",
|
|
64
|
-
"build:watch": "npm run build -- -w"
|
|
74
|
+
"build": "tsdown",
|
|
75
|
+
"build:watch": "tsdown --watch"
|
|
65
76
|
}
|
|
66
77
|
}
|