@arcblock/did 1.29.27 → 1.30.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/type.mjs +2 -9
- package/esm/util.mjs +2 -3
- package/lib/index.cjs +0 -1
- package/lib/type.cjs +7 -18
- package/lib/util.cjs +2 -5
- package/package.json +4 -5
- package/lib/_virtual/rolldown_runtime.cjs +0 -29
package/esm/type.mjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { toBits, toBytes, toStrictHex } from "./util.mjs";
|
|
2
2
|
import { Hasher, types } from "@ocap/mcrypto";
|
|
3
3
|
import { BN, isHex, numberToHex, stripHexPrefix, toAddress } from "@ocap/util";
|
|
4
|
-
import isEqual from "lodash/isEqual.js";
|
|
5
|
-
import pick from "lodash/pick.js";
|
|
6
|
-
import upperFirst from "lodash/upperFirst.js";
|
|
7
4
|
|
|
8
5
|
//#region src/type.ts
|
|
6
|
+
const upperFirst = (str) => str ? str[0].toUpperCase() + str.slice(1) : "";
|
|
9
7
|
const mapping = {
|
|
10
8
|
pk: "key",
|
|
11
9
|
address: "encoding"
|
|
@@ -29,12 +27,7 @@ const DID_TYPE_ETHEREUM = {
|
|
|
29
27
|
address: types.EncodingType.BASE16
|
|
30
28
|
};
|
|
31
29
|
const isEthereumType = (type) => {
|
|
32
|
-
|
|
33
|
-
"pk",
|
|
34
|
-
"hash",
|
|
35
|
-
"address"
|
|
36
|
-
];
|
|
37
|
-
return isEqual(pick(type, props), pick(DID_TYPE_ETHEREUM, props));
|
|
30
|
+
return type.pk === DID_TYPE_ETHEREUM.pk && type.hash === DID_TYPE_ETHEREUM.hash && type.address === DID_TYPE_ETHEREUM.address;
|
|
38
31
|
};
|
|
39
32
|
/**
|
|
40
33
|
* Checks if the given string is an address
|
package/esm/util.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { fromBase58, isHexStrict, stripHexPrefix, toBN } from "@ocap/util";
|
|
2
|
-
import padStart from "lodash/padStart.js";
|
|
3
2
|
|
|
4
3
|
//#region src/util.ts
|
|
5
4
|
const DID_PREFIX = "did:abt:";
|
|
@@ -22,7 +21,7 @@ const toBytes = (did) => {
|
|
|
22
21
|
/**
|
|
23
22
|
* Convert number to bit string with predefined length
|
|
24
23
|
*/
|
|
25
|
-
const toBits = (number, length) =>
|
|
24
|
+
const toBits = (number, length) => String(toBN(number).toString(2)).padStart(length, "0");
|
|
26
25
|
/**
|
|
27
26
|
* Ensure the hex length is even number, 2, 4, 6, 8
|
|
28
27
|
*
|
|
@@ -32,7 +31,7 @@ const toBits = (number, length) => padStart(toBN(number).toString(2), length, "0
|
|
|
32
31
|
*/
|
|
33
32
|
const toStrictHex = (hex, length) => {
|
|
34
33
|
const str = hex.replace(/^0x/i, "");
|
|
35
|
-
if (typeof length === "number" && length % 2 === 0) return padStart(
|
|
34
|
+
if (typeof length === "number" && length % 2 === 0) return String(hex).padStart(length, "0");
|
|
36
35
|
return str.length % 2 === 0 ? str : `0${str}`;
|
|
37
36
|
};
|
|
38
37
|
|
package/lib/index.cjs
CHANGED
package/lib/type.cjs
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
1
|
const require_util = require('./util.cjs');
|
|
3
2
|
let _ocap_mcrypto = require("@ocap/mcrypto");
|
|
4
3
|
let _ocap_util = require("@ocap/util");
|
|
5
|
-
let lodash_isEqual = require("lodash/isEqual");
|
|
6
|
-
lodash_isEqual = require_rolldown_runtime.__toESM(lodash_isEqual);
|
|
7
|
-
let lodash_pick = require("lodash/pick");
|
|
8
|
-
lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
|
|
9
|
-
let lodash_upperFirst = require("lodash/upperFirst");
|
|
10
|
-
lodash_upperFirst = require_rolldown_runtime.__toESM(lodash_upperFirst);
|
|
11
4
|
|
|
12
5
|
//#region src/type.ts
|
|
6
|
+
const upperFirst = (str) => str ? str[0].toUpperCase() + str.slice(1) : "";
|
|
13
7
|
const mapping = {
|
|
14
8
|
pk: "key",
|
|
15
9
|
address: "encoding"
|
|
@@ -33,12 +27,7 @@ const DID_TYPE_ETHEREUM = {
|
|
|
33
27
|
address: _ocap_mcrypto.types.EncodingType.BASE16
|
|
34
28
|
};
|
|
35
29
|
const isEthereumType = (type) => {
|
|
36
|
-
|
|
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));
|
|
30
|
+
return type.pk === DID_TYPE_ETHEREUM.pk && type.hash === DID_TYPE_ETHEREUM.hash && type.address === DID_TYPE_ETHEREUM.address;
|
|
42
31
|
};
|
|
43
32
|
/**
|
|
44
33
|
* Checks if the given string is an address
|
|
@@ -97,7 +86,7 @@ function DidType(type = {}) {
|
|
|
97
86
|
};
|
|
98
87
|
const { role, pk, hash, address } = input;
|
|
99
88
|
Object.keys(input).forEach((x) => {
|
|
100
|
-
const key = (
|
|
89
|
+
const key = upperFirst(`${mapping[x] || x}Type`);
|
|
101
90
|
if (Object.values(_ocap_mcrypto.types[key]).includes(input[x]) === false) throw new Error(`Unsupported ${x} type: ${input[x]}`);
|
|
102
91
|
});
|
|
103
92
|
const output = {
|
|
@@ -117,12 +106,12 @@ function DidType(type = {}) {
|
|
|
117
106
|
return output;
|
|
118
107
|
}
|
|
119
108
|
DidType.toJSON = (type) => Object.keys(type).reduce((acc, x) => {
|
|
120
|
-
const key = (
|
|
109
|
+
const key = upperFirst(`${mapping[x] || x}Type`);
|
|
121
110
|
acc[x] = Object.keys(_ocap_mcrypto.types[key])[Object.values(_ocap_mcrypto.types[key]).indexOf(type[x])];
|
|
122
111
|
return acc;
|
|
123
112
|
}, {});
|
|
124
113
|
DidType.fromJSON = (json) => Object.keys(json).reduce((acc, x) => {
|
|
125
|
-
const key = (
|
|
114
|
+
const key = upperFirst(`${mapping[x] || x}Type`);
|
|
126
115
|
const typeStr = Object.keys(_ocap_mcrypto.types[key]);
|
|
127
116
|
acc[x] = Object.values(_ocap_mcrypto.types[key])[typeStr.indexOf(json[x])];
|
|
128
117
|
return acc;
|
|
@@ -161,7 +150,7 @@ const toTypeInfo = (did) => {
|
|
|
161
150
|
};
|
|
162
151
|
}
|
|
163
152
|
Object.keys(type).forEach((x) => {
|
|
164
|
-
if (Object.values(_ocap_mcrypto.types[`${(
|
|
153
|
+
if (Object.values(_ocap_mcrypto.types[`${upperFirst(mapping[x] || x)}Type`]).includes(type[x]) === false) delete type[x];
|
|
165
154
|
});
|
|
166
155
|
return type;
|
|
167
156
|
} catch {
|
|
@@ -171,7 +160,7 @@ const toTypeInfo = (did) => {
|
|
|
171
160
|
const toTypeInfoStr = (did) => {
|
|
172
161
|
const type = toTypeInfo(did);
|
|
173
162
|
return Object.keys(type).reduce((acc, x) => {
|
|
174
|
-
const enums = _ocap_mcrypto.types[`${(
|
|
163
|
+
const enums = _ocap_mcrypto.types[`${upperFirst(mapping[x] || x)}Type`];
|
|
175
164
|
acc[x] = Object.keys(enums).find((d) => enums[d] === type[x]);
|
|
176
165
|
return acc;
|
|
177
166
|
}, {});
|
package/lib/util.cjs
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
1
|
let _ocap_util = require("@ocap/util");
|
|
3
|
-
let lodash_padStart = require("lodash/padStart");
|
|
4
|
-
lodash_padStart = require_rolldown_runtime.__toESM(lodash_padStart);
|
|
5
2
|
|
|
6
3
|
//#region src/util.ts
|
|
7
4
|
const DID_PREFIX = "did:abt:";
|
|
@@ -24,7 +21,7 @@ const toBytes = (did) => {
|
|
|
24
21
|
/**
|
|
25
22
|
* Convert number to bit string with predefined length
|
|
26
23
|
*/
|
|
27
|
-
const toBits = (number, length) => (
|
|
24
|
+
const toBits = (number, length) => String((0, _ocap_util.toBN)(number).toString(2)).padStart(length, "0");
|
|
28
25
|
/**
|
|
29
26
|
* Ensure the hex length is even number, 2, 4, 6, 8
|
|
30
27
|
*
|
|
@@ -34,7 +31,7 @@ const toBits = (number, length) => (0, lodash_padStart.default)((0, _ocap_util.t
|
|
|
34
31
|
*/
|
|
35
32
|
const toStrictHex = (hex, length) => {
|
|
36
33
|
const str = hex.replace(/^0x/i, "");
|
|
37
|
-
if (typeof length === "number" && length % 2 === 0) return (
|
|
34
|
+
if (typeof length === "number" && length % 2 === 0) return String(hex).padStart(length, "0");
|
|
38
35
|
return str.length % 2 === 0 ? str : `0${str}`;
|
|
39
36
|
};
|
|
40
37
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/did",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.30.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Javascript lib to work with ArcBlock DID",
|
|
6
6
|
"keywords": [
|
|
@@ -69,10 +69,9 @@
|
|
|
69
69
|
"url": "https://github.com/ArcBlock/blockchain/issues"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@ocap/mcrypto": "1.
|
|
73
|
-
"@ocap/util": "1.
|
|
72
|
+
"@ocap/mcrypto": "1.30.0",
|
|
73
|
+
"@ocap/util": "1.30.0",
|
|
74
74
|
"bn.js": "5.2.3",
|
|
75
|
-
"debug": "^4.4.3"
|
|
76
|
-
"lodash": "^4.17.23"
|
|
75
|
+
"debug": "^4.4.3"
|
|
77
76
|
}
|
|
78
77
|
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
//#region rolldown:runtime
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
-
__defProp(to, key, {
|
|
14
|
-
get: ((k) => from[k]).bind(null, key),
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
-
value: mod,
|
|
24
|
-
enumerable: true
|
|
25
|
-
}) : target, mod));
|
|
26
|
-
|
|
27
|
-
//#endregion
|
|
28
|
-
|
|
29
|
-
exports.__toESM = __toESM;
|