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