@arcblock/did 1.27.16 → 1.28.1

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/lib/type.js CHANGED
@@ -1,243 +1,190 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.toChecksumAddress = exports.isEthereumDid = exports.isEthereumType = exports.toTypeInfoStr = exports.toTypeInfo = exports.fromTypeInfo = exports.DID_TYPE_PASSKEY = exports.DID_TYPE_ETHEREUM = exports.DID_TYPE_ARCBLOCK = void 0;
7
- exports.DidType = DidType;
8
- /* eslint-disable @typescript-eslint/no-use-before-define */
9
- /* eslint-disable @typescript-eslint/ban-ts-comment */
10
- const util_1 = require("@ocap/util");
11
- const upperFirst_1 = __importDefault(require("lodash/upperFirst"));
12
- const isEqual_1 = __importDefault(require("lodash/isEqual"));
13
- const pick_1 = __importDefault(require("lodash/pick"));
14
- const mcrypto_1 = require("@ocap/mcrypto");
15
- const util_2 = require("./util");
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.js');
2
+ const require_util = require('./util.js');
3
+ let _ocap_mcrypto = require("@ocap/mcrypto");
4
+ let _ocap_util = require("@ocap/util");
5
+ let lodash_upperFirst = require("lodash/upperFirst");
6
+ lodash_upperFirst = require_rolldown_runtime.__toESM(lodash_upperFirst);
7
+ let lodash_isEqual = require("lodash/isEqual");
8
+ lodash_isEqual = require_rolldown_runtime.__toESM(lodash_isEqual);
9
+ let lodash_pick = require("lodash/pick");
10
+ lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
11
+
12
+ //#region src/type.ts
16
13
  const mapping = {
17
- pk: 'key',
18
- address: 'encoding',
14
+ pk: "key",
15
+ address: "encoding"
19
16
  };
20
17
  const DID_TYPE_ARCBLOCK = {
21
- role: mcrypto_1.types.RoleType.ROLE_ACCOUNT,
22
- pk: mcrypto_1.types.KeyType.ED25519,
23
- hash: mcrypto_1.types.HashType.SHA3,
24
- address: mcrypto_1.types.EncodingType.BASE58,
18
+ role: _ocap_mcrypto.types.RoleType.ROLE_ACCOUNT,
19
+ pk: _ocap_mcrypto.types.KeyType.ED25519,
20
+ hash: _ocap_mcrypto.types.HashType.SHA3,
21
+ address: _ocap_mcrypto.types.EncodingType.BASE58
25
22
  };
26
- exports.DID_TYPE_ARCBLOCK = DID_TYPE_ARCBLOCK;
27
23
  const DID_TYPE_PASSKEY = {
28
- role: mcrypto_1.types.RoleType.ROLE_PASSKEY,
29
- pk: mcrypto_1.types.KeyType.PASSKEY,
30
- hash: mcrypto_1.types.HashType.SHA2,
31
- address: mcrypto_1.types.EncodingType.BASE58,
24
+ role: _ocap_mcrypto.types.RoleType.ROLE_PASSKEY,
25
+ pk: _ocap_mcrypto.types.KeyType.PASSKEY,
26
+ hash: _ocap_mcrypto.types.HashType.SHA2,
27
+ address: _ocap_mcrypto.types.EncodingType.BASE58
32
28
  };
33
- exports.DID_TYPE_PASSKEY = DID_TYPE_PASSKEY;
34
29
  const DID_TYPE_ETHEREUM = {
35
- role: mcrypto_1.types.RoleType.ROLE_ACCOUNT,
36
- pk: mcrypto_1.types.KeyType.ETHEREUM,
37
- hash: mcrypto_1.types.HashType.KECCAK,
38
- address: mcrypto_1.types.EncodingType.BASE16,
30
+ role: _ocap_mcrypto.types.RoleType.ROLE_ACCOUNT,
31
+ pk: _ocap_mcrypto.types.KeyType.ETHEREUM,
32
+ hash: _ocap_mcrypto.types.HashType.KECCAK,
33
+ address: _ocap_mcrypto.types.EncodingType.BASE16
39
34
  };
40
- exports.DID_TYPE_ETHEREUM = DID_TYPE_ETHEREUM;
41
35
  const isEthereumType = (type) => {
42
- const props = ['pk', 'hash', 'address'];
43
- return (0, isEqual_1.default)((0, pick_1.default)(type, props), (0, pick_1.default)(DID_TYPE_ETHEREUM, props));
36
+ const props = [
37
+ "pk",
38
+ "hash",
39
+ "address"
40
+ ];
41
+ return (0, lodash_isEqual.default)((0, lodash_pick.default)(type, props), (0, lodash_pick.default)(DID_TYPE_ETHEREUM, props));
44
42
  };
45
- exports.isEthereumType = isEthereumType;
46
43
  /**
47
- * Checks if the given string is an address
48
- *
49
- * @method isEthereumDid
50
- * @param {String} address the given HEX address
51
- * @return {Boolean}
52
- */
44
+ * Checks if the given string is an address
45
+ *
46
+ * @method isEthereumDid
47
+ * @param {String} address the given HEX address
48
+ * @return {Boolean}
49
+ */
53
50
  const isEthereumDid = (did) => {
54
- const address = (0, util_1.toAddress)(did);
55
- // check if it has the basic requirements of an address
56
- if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) {
57
- return false;
58
- }
59
- // If it's ALL lowercase or ALL upppercase
60
- if (/^(0x|0X)?[0-9a-f]{40}$/.test(address) || /^(0x|0X)?[0-9A-F]{40}$/.test(address)) {
61
- return true;
62
- }
63
- // Otherwise check each case
64
- return checkAddressChecksum(address);
51
+ const address = (0, _ocap_util.toAddress)(did);
52
+ if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) return false;
53
+ if (/^(0x|0X)?[0-9a-f]{40}$/.test(address) || /^(0x|0X)?[0-9A-F]{40}$/.test(address)) return true;
54
+ return checkAddressChecksum(address);
65
55
  };
66
- exports.isEthereumDid = isEthereumDid;
67
56
  /**
68
- * Checks if the given string is a checksummed address
69
- *
70
- * @method checkAddressChecksum
71
- * @param {String} address the given HEX address
72
- * @return {Boolean}
73
- */
57
+ * Checks if the given string is a checksummed address
58
+ *
59
+ * @method checkAddressChecksum
60
+ * @param {String} address the given HEX address
61
+ * @return {Boolean}
62
+ */
74
63
  const checkAddressChecksum = (address) => {
75
- // Check each case
76
- const origin = address.replace(/^0x/i, '');
77
- const addressHash = mcrypto_1.Hasher.Keccak.hash256(origin.toLowerCase()).replace(/^0x/i, '');
78
- for (let i = 0; i < 40; i++) {
79
- // the nth letter should be uppercase if the nth digit of casemap is 1
80
- if ((parseInt(addressHash[i], 16) > 7 && origin[i].toUpperCase() !== origin[i]) ||
81
- (parseInt(addressHash[i], 16) <= 7 && origin[i].toLowerCase() !== origin[i])) {
82
- return false;
83
- }
84
- }
85
- return true;
64
+ const origin = address.replace(/^0x/i, "");
65
+ const addressHash = _ocap_mcrypto.Hasher.Keccak.hash256(origin.toLowerCase()).replace(/^0x/i, "");
66
+ for (let i = 0; i < 40; i++) if (parseInt(addressHash[i], 16) > 7 && origin[i].toUpperCase() !== origin[i] || parseInt(addressHash[i], 16) <= 7 && origin[i].toLowerCase() !== origin[i]) return false;
67
+ return true;
86
68
  };
87
69
  /**
88
- * Converts to a checksum address
89
- *
90
- * @method toChecksumAddress
91
- * @param {String} address the given HEX address
92
- * @return {String}
93
- */
70
+ * Converts to a checksum address
71
+ *
72
+ * @method toChecksumAddress
73
+ * @param {String} address the given HEX address
74
+ * @return {String}
75
+ */
94
76
  const toChecksumAddress = (address) => {
95
- if (typeof address === 'undefined') {
96
- return '';
97
- }
98
- if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) {
99
- throw new Error(`Given address "${address}" is not a valid Ethereum address.`);
100
- }
101
- const lower = address.toLowerCase().replace(/^0x/i, '');
102
- const addressHash = mcrypto_1.Hasher.Keccak.hash256(lower).replace(/^0x/i, '');
103
- let checksumAddress = '0x';
104
- for (let i = 0; i < lower.length; i++) {
105
- // If ith character is 8 to f then make it uppercase
106
- if (parseInt(addressHash[i], 16) > 7) {
107
- checksumAddress += lower[i].toUpperCase();
108
- }
109
- else {
110
- checksumAddress += lower[i];
111
- }
112
- }
113
- return checksumAddress;
77
+ if (typeof address === "undefined") return "";
78
+ if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) throw new Error(`Given address "${address}" is not a valid Ethereum address.`);
79
+ const lower = address.toLowerCase().replace(/^0x/i, "");
80
+ const addressHash = _ocap_mcrypto.Hasher.Keccak.hash256(lower).replace(/^0x/i, "");
81
+ let checksumAddress = "0x";
82
+ for (let i = 0; i < lower.length; i++) if (parseInt(addressHash[i], 16) > 7) checksumAddress += lower[i].toUpperCase();
83
+ else checksumAddress += lower[i];
84
+ return checksumAddress;
114
85
  };
115
- exports.toChecksumAddress = toChecksumAddress;
116
86
  /**
117
- * Create an wallet type object that be used as param to create a new wallet
118
- */
87
+ * Create an wallet type object that be used as param to create a new wallet
88
+ */
119
89
  function DidType(type = {}) {
120
- let input = {};
121
- if (['default', 'arcblock'].includes(type)) {
122
- input = DID_TYPE_ARCBLOCK;
123
- }
124
- else if (['eth', 'ethereum'].includes(type)) {
125
- input = DID_TYPE_ETHEREUM;
126
- }
127
- else if (['passkey'].includes(type)) {
128
- input = DID_TYPE_PASSKEY;
129
- }
130
- else {
131
- input = { ...DID_TYPE_ARCBLOCK, ...type };
132
- }
133
- const { role, pk, hash, address } = input;
134
- Object.keys(input).forEach((x) => {
135
- const key = (0, upperFirst_1.default)(`${mapping[x] || x}Type`);
136
- // @ts-ignore
137
- if (Object.values(mcrypto_1.types[key]).includes(input[x]) === false) {
138
- throw new Error(`Unsupported ${x} type: ${input[x]}`);
139
- }
140
- });
141
- const output = { role, pk, hash, address };
142
- // Overwrite hash methods for some role type if we are not eth-type
143
- if (isEthereumType(output) === false) {
144
- const sha2Roles = [
145
- mcrypto_1.types.RoleType.ROLE_NODE,
146
- mcrypto_1.types.RoleType.ROLE_VALIDATOR,
147
- mcrypto_1.types.RoleType.ROLE_TETHER,
148
- mcrypto_1.types.RoleType.ROLE_SWAP,
149
- ];
150
- if (sha2Roles.includes(output.role)) {
151
- output.hash = mcrypto_1.types.HashType.SHA2;
152
- }
153
- }
154
- return output;
90
+ let input = {};
91
+ if (["default", "arcblock"].includes(type)) input = DID_TYPE_ARCBLOCK;
92
+ else if (["eth", "ethereum"].includes(type)) input = DID_TYPE_ETHEREUM;
93
+ else if (["passkey"].includes(type)) input = DID_TYPE_PASSKEY;
94
+ else input = {
95
+ ...DID_TYPE_ARCBLOCK,
96
+ ...type
97
+ };
98
+ const { role, pk, hash, address } = input;
99
+ Object.keys(input).forEach((x) => {
100
+ const key = (0, lodash_upperFirst.default)(`${mapping[x] || x}Type`);
101
+ if (Object.values(_ocap_mcrypto.types[key]).includes(input[x]) === false) throw new Error(`Unsupported ${x} type: ${input[x]}`);
102
+ });
103
+ const output = {
104
+ role,
105
+ pk,
106
+ hash,
107
+ address
108
+ };
109
+ if (isEthereumType(output) === false) {
110
+ if ([
111
+ _ocap_mcrypto.types.RoleType.ROLE_NODE,
112
+ _ocap_mcrypto.types.RoleType.ROLE_VALIDATOR,
113
+ _ocap_mcrypto.types.RoleType.ROLE_TETHER,
114
+ _ocap_mcrypto.types.RoleType.ROLE_SWAP
115
+ ].includes(output.role)) output.hash = _ocap_mcrypto.types.HashType.SHA2;
116
+ }
117
+ return output;
155
118
  }
156
119
  DidType.toJSON = (type) => Object.keys(type).reduce((acc, x) => {
157
- const key = (0, upperFirst_1.default)(`${mapping[x] || x}Type`);
158
- // @ts-ignore
159
- const typeStr = Object.keys(mcrypto_1.types[key]);
160
- // @ts-ignore
161
- const typeValues = Object.values(mcrypto_1.types[key]);
162
- // @ts-ignore
163
- acc[x] = typeStr[typeValues.indexOf(type[x])];
164
- return acc;
120
+ const key = (0, lodash_upperFirst.default)(`${mapping[x] || x}Type`);
121
+ acc[x] = Object.keys(_ocap_mcrypto.types[key])[Object.values(_ocap_mcrypto.types[key]).indexOf(type[x])];
122
+ return acc;
165
123
  }, {});
166
124
  DidType.fromJSON = (json) => Object.keys(json).reduce((acc, x) => {
167
- const key = (0, upperFirst_1.default)(`${mapping[x] || x}Type`);
168
- // @ts-ignore
169
- const typeStr = Object.keys(mcrypto_1.types[key]);
170
- // @ts-ignore
171
- const typeValues = Object.values(mcrypto_1.types[key]);
172
- // @ts-ignore
173
- acc[x] = typeValues[typeStr.indexOf(json[x])];
174
- return acc;
125
+ const key = (0, lodash_upperFirst.default)(`${mapping[x] || x}Type`);
126
+ const typeStr = Object.keys(_ocap_mcrypto.types[key]);
127
+ acc[x] = Object.values(_ocap_mcrypto.types[key])[typeStr.indexOf(json[x])];
128
+ return acc;
175
129
  }, {});
176
130
  /**
177
- * Convert type info object to hex string
178
- *
179
- * @public
180
- * @static
181
- * @param {object} type - wallet type, {@see @arcblock/did#DidType}
182
- * @returns string
183
- */
131
+ * Convert type info object to hex string
132
+ *
133
+ * @public
134
+ * @static
135
+ * @param {object} type - wallet type, {@see @arcblock/did#DidType}
136
+ * @returns string
137
+ */
184
138
  const fromTypeInfo = (type) => {
185
- const info = DidType(type);
186
- const roleBits = (0, util_2.toBits)(info.role, 6);
187
- const keyBits = (0, util_2.toBits)(info.pk, 5);
188
- const hashBits = (0, util_2.toBits)(info.hash, 5);
189
- const infoBits = `${roleBits}${keyBits}${hashBits}`;
190
- const infoHex = (0, util_1.stripHexPrefix)((0, util_1.numberToHex)(parseInt(infoBits, 2)));
191
- return (0, util_2.toStrictHex)(infoHex, 4);
139
+ const info = DidType(type);
140
+ const infoBits = `${require_util.toBits(info.role, 6)}${require_util.toBits(info.pk, 5)}${require_util.toBits(info.hash, 5)}`;
141
+ return require_util.toStrictHex((0, _ocap_util.stripHexPrefix)((0, _ocap_util.numberToHex)(parseInt(infoBits, 2))), 4);
192
142
  };
193
- exports.fromTypeInfo = fromTypeInfo;
194
143
  /**
195
- * Get type info from did
196
- */
144
+ * Get type info from did
145
+ */
197
146
  const toTypeInfo = (did) => {
198
- let type = {};
199
- try {
200
- if (isEthereumDid(did)) {
201
- type = DID_TYPE_ETHEREUM;
202
- }
203
- else {
204
- const bytes = (0, util_2.toBytes)(did);
205
- const typeBytes = bytes.slice(0, 2);
206
- const typeHex = (0, util_2.toStrictHex)(Buffer.from(typeBytes).toString('hex'));
207
- const typeBits = (0, util_2.toBits)(new util_1.BN(typeHex, 16), 16);
208
- const roleBits = typeBits.slice(0, 6);
209
- const keyBits = typeBits.slice(6, 11);
210
- const hashBits = typeBits.slice(11, 16);
211
- type = {
212
- role: parseInt(roleBits, 2),
213
- pk: parseInt(keyBits, 2),
214
- hash: parseInt(hashBits, 2),
215
- address: (0, util_1.isHex)((0, util_1.toAddress)(did)) ? mcrypto_1.types.EncodingType.BASE16 : mcrypto_1.types.EncodingType.BASE58,
216
- };
217
- }
218
- // remove unsupported types
219
- Object.keys(type).forEach((x) => {
220
- // @ts-ignore
221
- const enums = Object.values(mcrypto_1.types[`${(0, upperFirst_1.default)(mapping[x] || x)}Type`]);
222
- if (enums.includes(type[x]) === false) {
223
- delete type[x];
224
- }
225
- });
226
- return type;
227
- }
228
- catch {
229
- return type;
230
- }
147
+ let type = {};
148
+ try {
149
+ if (isEthereumDid(did)) type = DID_TYPE_ETHEREUM;
150
+ else {
151
+ const typeBytes = require_util.toBytes(did).slice(0, 2);
152
+ const typeBits = require_util.toBits(new _ocap_util.BN(require_util.toStrictHex(Buffer.from(typeBytes).toString("hex")), 16), 16);
153
+ const roleBits = typeBits.slice(0, 6);
154
+ const keyBits = typeBits.slice(6, 11);
155
+ const hashBits = typeBits.slice(11, 16);
156
+ type = {
157
+ role: parseInt(roleBits, 2),
158
+ pk: parseInt(keyBits, 2),
159
+ hash: parseInt(hashBits, 2),
160
+ address: (0, _ocap_util.isHex)((0, _ocap_util.toAddress)(did)) ? _ocap_mcrypto.types.EncodingType.BASE16 : _ocap_mcrypto.types.EncodingType.BASE58
161
+ };
162
+ }
163
+ Object.keys(type).forEach((x) => {
164
+ if (Object.values(_ocap_mcrypto.types[`${(0, lodash_upperFirst.default)(mapping[x] || x)}Type`]).includes(type[x]) === false) delete type[x];
165
+ });
166
+ return type;
167
+ } catch {
168
+ return type;
169
+ }
231
170
  };
232
- exports.toTypeInfo = toTypeInfo;
233
171
  const toTypeInfoStr = (did) => {
234
- const type = toTypeInfo(did);
235
- return Object.keys(type).reduce((acc, x) => {
236
- // @ts-ignore
237
- const enums = mcrypto_1.types[`${(0, upperFirst_1.default)(mapping[x] || x)}Type`];
238
- // @ts-ignore
239
- acc[x] = Object.keys(enums).find((d) => enums[d] === type[x]);
240
- return acc;
241
- }, {});
172
+ const type = toTypeInfo(did);
173
+ return Object.keys(type).reduce((acc, x) => {
174
+ const enums = _ocap_mcrypto.types[`${(0, lodash_upperFirst.default)(mapping[x] || x)}Type`];
175
+ acc[x] = Object.keys(enums).find((d) => enums[d] === type[x]);
176
+ return acc;
177
+ }, {});
242
178
  };
243
- exports.toTypeInfoStr = toTypeInfoStr;
179
+
180
+ //#endregion
181
+ exports.DID_TYPE_ARCBLOCK = DID_TYPE_ARCBLOCK;
182
+ exports.DID_TYPE_ETHEREUM = DID_TYPE_ETHEREUM;
183
+ exports.DID_TYPE_PASSKEY = DID_TYPE_PASSKEY;
184
+ exports.DidType = DidType;
185
+ exports.fromTypeInfo = fromTypeInfo;
186
+ exports.isEthereumDid = isEthereumDid;
187
+ exports.isEthereumType = isEthereumType;
188
+ exports.toChecksumAddress = toChecksumAddress;
189
+ exports.toTypeInfo = toTypeInfo;
190
+ exports.toTypeInfoStr = toTypeInfoStr;
package/lib/util.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- import { BN } from '@ocap/util';
1
+ import { BN } from "@ocap/util";
2
+
3
+ //#region src/util.d.ts
2
4
  declare const DID_PREFIX = "did:abt:";
3
5
  /**
4
6
  * Convert did to bytes with length of 26
@@ -18,5 +20,6 @@ declare const toBits: (number: string | number | BN, length: number) => string;
18
20
  * @param {number} length
19
21
  * @returns {string} hex
20
22
  */
21
- declare const toStrictHex: (hex: string, length?: number) => any;
22
- export { DID_PREFIX, toBits, toBytes, toStrictHex };
23
+ declare const toStrictHex: (hex: string, length?: number) => string;
24
+ //#endregion
25
+ export { DID_PREFIX, toBits, toBytes, toStrictHex };
package/lib/util.js CHANGED
@@ -1,54 +1,45 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.toStrictHex = exports.toBytes = exports.toBits = exports.DID_PREFIX = void 0;
7
- /* eslint-disable @typescript-eslint/ban-ts-comment */
8
- const padStart_1 = __importDefault(require("lodash/padStart"));
9
- const util_1 = require("@ocap/util");
10
- const DID_PREFIX = 'did:abt:';
11
- exports.DID_PREFIX = DID_PREFIX;
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.js');
2
+ let _ocap_util = require("@ocap/util");
3
+ let lodash_padStart = require("lodash/padStart");
4
+ lodash_padStart = require_rolldown_runtime.__toESM(lodash_padStart);
5
+
6
+ //#region src/util.ts
7
+ const DID_PREFIX = "did:abt:";
12
8
  /**
13
- * Convert did to bytes with length of 26
14
- *
15
- * @param {string} did
16
- * @returns {Buffer}
17
- */
9
+ * Convert did to bytes with length of 26
10
+ *
11
+ * @param {string} did
12
+ * @returns {Buffer}
13
+ */
18
14
  const toBytes = (did) => {
19
- try {
20
- if ((0, util_1.isHexStrict)(did)) {
21
- return Buffer.from((0, util_1.stripHexPrefix)(did), 'hex');
22
- }
23
- let bytes = (0, util_1.fromBase58)(did.replace(DID_PREFIX, ''));
24
- while (bytes.length < 26) {
25
- bytes = Buffer.concat([Buffer.from([0]), bytes]);
26
- }
27
- return bytes;
28
- }
29
- catch (err) {
30
- // @ts-ignore
31
- throw new Error(`Cannot convert DID string to byte array: ${err.message}`);
32
- }
15
+ try {
16
+ if ((0, _ocap_util.isHexStrict)(did)) return Buffer.from((0, _ocap_util.stripHexPrefix)(did), "hex");
17
+ let bytes = (0, _ocap_util.fromBase58)(did.replace(DID_PREFIX, ""));
18
+ while (bytes.length < 26) bytes = Buffer.concat([Buffer.from([0]), bytes]);
19
+ return bytes;
20
+ } catch (err) {
21
+ throw new Error(`Cannot convert DID string to byte array: ${err.message}`);
22
+ }
33
23
  };
34
- exports.toBytes = toBytes;
35
24
  /**
36
- * Convert number to bit string with predefined length
37
- */
38
- const toBits = (number, length) => (0, padStart_1.default)((0, util_1.toBN)(number).toString(2), length, '0');
39
- exports.toBits = toBits;
25
+ * Convert number to bit string with predefined length
26
+ */
27
+ const toBits = (number, length) => (0, lodash_padStart.default)((0, _ocap_util.toBN)(number).toString(2), length, "0");
40
28
  /**
41
- * Ensure the hex length is even number, 2, 4, 6, 8
42
- *
43
- * @param {string} hex
44
- * @param {number} length
45
- * @returns {string} hex
46
- */
29
+ * Ensure the hex length is even number, 2, 4, 6, 8
30
+ *
31
+ * @param {string} hex
32
+ * @param {number} length
33
+ * @returns {string} hex
34
+ */
47
35
  const toStrictHex = (hex, length) => {
48
- const str = hex.replace(/^0x/i, '');
49
- if (typeof length === 'number' && length % 2 === 0) {
50
- return (0, padStart_1.default)(hex, length, '0');
51
- }
52
- return str.length % 2 === 0 ? str : `0${str}`;
36
+ const str = hex.replace(/^0x/i, "");
37
+ if (typeof length === "number" && length % 2 === 0) return (0, lodash_padStart.default)(hex, length, "0");
38
+ return str.length % 2 === 0 ? str : `0${str}`;
53
39
  };
54
- exports.toStrictHex = toStrictHex;
40
+
41
+ //#endregion
42
+ exports.DID_PREFIX = DID_PREFIX;
43
+ exports.toBits = toBits;
44
+ exports.toBytes = toBytes;
45
+ exports.toStrictHex = toStrictHex;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/did",
3
- "version": "1.27.16",
3
+ "version": "1.28.1",
4
4
  "description": "Javascript lib to work with ArcBlock DID",
5
5
  "keywords": [
6
6
  "arcblock",
@@ -21,8 +21,22 @@
21
21
  ],
22
22
  "homepage": "https://www.arcblock.io/docs/blockchain-utils",
23
23
  "license": "Apache-2.0",
24
+ "sideEffects": false,
24
25
  "main": "./lib/index.js",
25
- "types": "./lib/index.d.ts",
26
+ "module": "./esm/index.js",
27
+ "types": "./esm/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./esm/index.d.ts",
31
+ "import": "./esm/index.js",
32
+ "default": "./lib/index.js"
33
+ },
34
+ "./lib/*": {
35
+ "types": "./lib/*",
36
+ "import": "./esm/*",
37
+ "default": "./lib/*.js"
38
+ }
39
+ },
26
40
  "files": [
27
41
  "lib",
28
42
  "esm"
@@ -34,6 +48,7 @@
34
48
  "eslint": "^8.57.0",
35
49
  "jest": "^29.7.0",
36
50
  "ts-jest": "^29.2.5",
51
+ "tsdown": "^0.18.4",
37
52
  "type-fest": "^3.1.0",
38
53
  "typescript": "^5.6.2"
39
54
  },
@@ -48,19 +63,15 @@
48
63
  "bn.js": "^5.2.1",
49
64
  "debug": "^4.3.6",
50
65
  "lodash": "^4.17.21",
51
- "@ocap/mcrypto": "1.27.16",
52
- "@ocap/util": "1.27.16"
66
+ "@ocap/mcrypto": "1.28.1",
67
+ "@ocap/util": "1.28.1"
53
68
  },
54
69
  "scripts": {
55
70
  "lint": "eslint src tests",
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 -w"
65
76
  }
66
77
  }