@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 CHANGED
@@ -1,33 +1,38 @@
1
- import { TCreateAssetTx, TCreateFactoryTx, TCreateRollupTx, TCreateTokenTx, CreateTokenFactoryTx } from '@ocap/types';
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
- export declare function toItxAddress(itx: object, type: string, role?: number): string;
8
+ declare function toItxAddress(itx: object, type: string, role?: number): string;
6
9
  /**
7
10
  * Create an asset address
8
11
  */
9
- export declare function toAssetAddress(itx: Partial<TCreateAssetTx>): string;
12
+ declare function toAssetAddress(itx: Partial<TCreateAssetTx>): string;
10
13
  /**
11
14
  * Create an asset factory address
12
15
  */
13
- export declare function toFactoryAddress(itx: Partial<TCreateFactoryTx>): string;
16
+ declare function toFactoryAddress(itx: Partial<TCreateFactoryTx>): string;
14
17
  /**
15
18
  * Create an token address
16
19
  */
17
- export declare function toTokenAddress(itx: Partial<TCreateTokenTx>): string;
20
+ declare function toTokenAddress(itx: Partial<TCreateTokenTx>): string;
18
21
  /**
19
22
  * Create a token factory address
20
23
  */
21
- export declare function toTokenFactoryAddress(itx: Partial<CreateTokenFactoryTx>): string;
24
+ declare function toTokenFactoryAddress(itx: Partial<CreateTokenFactoryTx>): string;
22
25
  /**
23
26
  * Create an rollup address
24
27
  */
25
- export declare function toRollupAddress(itx: Partial<TCreateRollupTx>): string;
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
- export declare function toStakeAddress(sender: string, receiver: string, nonce?: string): string;
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
- export declare function toDelegateAddress(delegator: string, delegatee: string): string;
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 { 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';
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
- * 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;
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
- * Create an asset address
22
- */
23
- export function toAssetAddress(itx) {
24
- return toItxAddress(itx, 'CreateAssetTx', types.RoleType.ROLE_ASSET);
16
+ * Create an asset address
17
+ */
18
+ function toAssetAddress(itx) {
19
+ return toItxAddress(itx, "CreateAssetTx", types.RoleType.ROLE_ASSET);
25
20
  }
26
21
  /**
27
- * Create an asset factory address
28
- */
29
- export function toFactoryAddress(itx) {
30
- return toItxAddress(itx, 'CreateFactoryTx', types.RoleType.ROLE_FACTORY);
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
- * Create an token address
34
- */
35
- export function toTokenAddress(itx) {
36
- return toItxAddress(itx, 'CreateTokenTx', types.RoleType.ROLE_TOKEN);
28
+ * Create an token address
29
+ */
30
+ function toTokenAddress(itx) {
31
+ return toItxAddress(itx, "CreateTokenTx", types.RoleType.ROLE_TOKEN);
37
32
  }
38
33
  /**
39
- * Create a token factory address
40
- */
41
- export function toTokenFactoryAddress(itx) {
42
- return toItxAddress(itx, 'CreateTokenFactoryTx', types.RoleType.ROLE_TOKEN_FACTORY);
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
- * Create an rollup address
46
- */
47
- export function toRollupAddress(itx) {
48
- return toItxAddress(itx, 'CreateRollupTx', types.RoleType.ROLE_ROLLUP);
40
+ * Create an rollup address
41
+ */
42
+ function toRollupAddress(itx) {
43
+ return toItxAddress(itx, "CreateRollupTx", types.RoleType.ROLE_ROLLUP);
49
44
  }
50
45
  /**
51
- * Generate an stake address, eg: the did of the stake
52
- */
53
- export function toStakeAddress(sender, receiver, nonce) {
54
- const buffer = Buffer.concat([sender, receiver, nonce].filter(Boolean).map((x) => Buffer.from(x)));
55
- const hash = Hasher.SHA3.hash256(buffer);
56
- return fromHash(hash, types.RoleType.ROLE_STAKE);
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
- * Generate an delegate address, eg: the did of the delegation
60
- */
61
- export function toDelegateAddress(delegator, delegatee) {
62
- const buffer = Buffer.concat([Buffer.from(delegator), Buffer.from(delegatee)]);
63
- const hash = Hasher.SHA3.hash256(buffer);
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, CreateTokenFactoryTx } from '@ocap/types';
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
- export declare function toItxAddress(itx: object, type: string, role?: number): string;
8
+ declare function toItxAddress(itx: object, type: string, role?: number): string;
6
9
  /**
7
10
  * Create an asset address
8
11
  */
9
- export declare function toAssetAddress(itx: Partial<TCreateAssetTx>): string;
12
+ declare function toAssetAddress(itx: Partial<TCreateAssetTx>): string;
10
13
  /**
11
14
  * Create an asset factory address
12
15
  */
13
- export declare function toFactoryAddress(itx: Partial<TCreateFactoryTx>): string;
16
+ declare function toFactoryAddress(itx: Partial<TCreateFactoryTx>): string;
14
17
  /**
15
18
  * Create an token address
16
19
  */
17
- export declare function toTokenAddress(itx: Partial<TCreateTokenTx>): string;
20
+ declare function toTokenAddress(itx: Partial<TCreateTokenTx>): string;
18
21
  /**
19
22
  * Create a token factory address
20
23
  */
21
- export declare function toTokenFactoryAddress(itx: Partial<CreateTokenFactoryTx>): string;
24
+ declare function toTokenFactoryAddress(itx: Partial<CreateTokenFactoryTx>): string;
22
25
  /**
23
26
  * Create an rollup address
24
27
  */
25
- export declare function toRollupAddress(itx: Partial<TCreateRollupTx>): string;
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
- export declare function toStakeAddress(sender: string, receiver: string, nonce?: string): string;
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
- export declare function toDelegateAddress(delegator: string, delegatee: string): string;
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toItxAddress = toItxAddress;
4
- exports.toAssetAddress = toAssetAddress;
5
- exports.toFactoryAddress = toFactoryAddress;
6
- exports.toTokenAddress = toTokenAddress;
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
- * Create an itx address
18
- */
19
- function toItxAddress(itx, type, role = mcrypto_1.types.RoleType.ROLE_TX) {
20
- if (proto_1.transactions.indexOf(type) === -1) {
21
- throw new Error(`Unsupported itx type ${type}`);
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
- * Create an asset address
32
- */
16
+ * Create an asset address
17
+ */
33
18
  function toAssetAddress(itx) {
34
- return toItxAddress(itx, 'CreateAssetTx', mcrypto_1.types.RoleType.ROLE_ASSET);
19
+ return toItxAddress(itx, "CreateAssetTx", _ocap_mcrypto.types.RoleType.ROLE_ASSET);
35
20
  }
36
21
  /**
37
- * Create an asset factory address
38
- */
22
+ * Create an asset factory address
23
+ */
39
24
  function toFactoryAddress(itx) {
40
- return toItxAddress(itx, 'CreateFactoryTx', mcrypto_1.types.RoleType.ROLE_FACTORY);
25
+ return toItxAddress(itx, "CreateFactoryTx", _ocap_mcrypto.types.RoleType.ROLE_FACTORY);
41
26
  }
42
27
  /**
43
- * Create an token address
44
- */
28
+ * Create an token address
29
+ */
45
30
  function toTokenAddress(itx) {
46
- return toItxAddress(itx, 'CreateTokenTx', mcrypto_1.types.RoleType.ROLE_TOKEN);
31
+ return toItxAddress(itx, "CreateTokenTx", _ocap_mcrypto.types.RoleType.ROLE_TOKEN);
47
32
  }
48
33
  /**
49
- * Create a token factory address
50
- */
34
+ * Create a token factory address
35
+ */
51
36
  function toTokenFactoryAddress(itx) {
52
- return toItxAddress(itx, 'CreateTokenFactoryTx', mcrypto_1.types.RoleType.ROLE_TOKEN_FACTORY);
37
+ return toItxAddress(itx, "CreateTokenFactoryTx", _ocap_mcrypto.types.RoleType.ROLE_TOKEN_FACTORY);
53
38
  }
54
39
  /**
55
- * Create an rollup address
56
- */
40
+ * Create an rollup address
41
+ */
57
42
  function toRollupAddress(itx) {
58
- return toItxAddress(itx, 'CreateRollupTx', mcrypto_1.types.RoleType.ROLE_ROLLUP);
43
+ return toItxAddress(itx, "CreateRollupTx", _ocap_mcrypto.types.RoleType.ROLE_ROLLUP);
59
44
  }
60
45
  /**
61
- * Generate an stake address, eg: the did of the stake
62
- */
46
+ * Generate an stake address, eg: the did of the stake
47
+ */
63
48
  function toStakeAddress(sender, receiver, nonce) {
64
- const buffer = Buffer.concat([sender, receiver, nonce].filter(Boolean).map((x) => Buffer.from(x)));
65
- const hash = mcrypto_1.Hasher.SHA3.hash256(buffer);
66
- return (0, did_1.fromHash)(hash, mcrypto_1.types.RoleType.ROLE_STAKE);
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
- * Generate an delegate address, eg: the did of the delegation
70
- */
57
+ * Generate an delegate address, eg: the did of the delegation
58
+ */
71
59
  function toDelegateAddress(delegator, delegatee) {
72
- const buffer = Buffer.concat([Buffer.from(delegator), Buffer.from(delegatee)]);
73
- const hash = mcrypto_1.Hasher.SHA3.hash256(buffer);
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.27.15",
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.27.15",
22
- "@ocap/mcrypto": "1.27.15",
23
- "@ocap/message": "1.27.15",
24
- "@ocap/proto": "1.27.15",
25
- "@ocap/types": "1.27.15",
26
- "@ocap/util": "1.27.15",
27
- "@ocap/wallet": "1.27.15"
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
- "types": "./lib/index.d.ts",
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
- "clean": "rm -fr lib esm",
60
- "prebuild": "npm run clean",
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
  }