@arcblock/did-ext 1.30.23 → 1.30.25

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.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Hasher, Signer, types } from "@ocap/mcrypto";
2
- import { isHexStrict, stripHexPrefix, toBuffer, toHex } from "@ocap/util";
2
+ import { isHexStrict, stripHexPrefix, toBuffer, toHex, toUint8Array } from "@ocap/util";
3
3
  import { WalletType, fromSecretKey } from "@ocap/wallet";
4
4
  import { HDKey } from "@scure/bip32";
5
5
 
@@ -11,12 +11,14 @@ import { HDKey } from "@scure/bip32";
11
11
  */
12
12
  const fromAppDid = (appDid, rootSk, type = { role: types.RoleType.ROLE_ACCOUNT }, index = 0) => {
13
13
  if (!rootSk) throw new Error("Cannot get user wallet with empty root sk");
14
+ if (typeof appDid !== "string") throw new Error("Invalid appDid: must be a string");
15
+ if (!Number.isInteger(index) || index < 0 || index >= 2147483648) throw new Error("Invalid index: must be a non-negative 31-bit integer");
14
16
  const hashSlice = stripHexPrefix(Hasher.SHA3.hash256(toBuffer(appDid))).slice(0, 16);
15
17
  const s1 = hashSlice.slice(0, 8);
16
18
  const s2 = hashSlice.slice(8, 16);
17
19
  const n1 = Number.parseInt(Number(`0x${s1}`).toString(), 10) & 2147483647;
18
20
  const n2 = Number.parseInt(Number(`0x${s2}`).toString(), 10) & 2147483647;
19
- const seedHex = stripHexPrefix(isHexStrict(rootSk) ? rootSk : toHex(rootSk));
21
+ const seedHex = stripHexPrefix(isHexStrict(rootSk) ? rootSk : toHex(toUint8Array(rootSk)));
20
22
  const master = HDKey.fromMasterSeed(Buffer.from(seedHex, "hex"));
21
23
  const derivePath = `m/44'/260'/${n1}'/${n2}'/${index}`;
22
24
  const child = master.derive(derivePath);
package/lib/index.cjs CHANGED
@@ -11,12 +11,14 @@ let _scure_bip32 = require("@scure/bip32");
11
11
  */
12
12
  const fromAppDid = (appDid, rootSk, type = { role: _ocap_mcrypto.types.RoleType.ROLE_ACCOUNT }, index = 0) => {
13
13
  if (!rootSk) throw new Error("Cannot get user wallet with empty root sk");
14
+ if (typeof appDid !== "string") throw new Error("Invalid appDid: must be a string");
15
+ if (!Number.isInteger(index) || index < 0 || index >= 2147483648) throw new Error("Invalid index: must be a non-negative 31-bit integer");
14
16
  const hashSlice = (0, _ocap_util.stripHexPrefix)(_ocap_mcrypto.Hasher.SHA3.hash256((0, _ocap_util.toBuffer)(appDid))).slice(0, 16);
15
17
  const s1 = hashSlice.slice(0, 8);
16
18
  const s2 = hashSlice.slice(8, 16);
17
19
  const n1 = Number.parseInt(Number(`0x${s1}`).toString(), 10) & 2147483647;
18
20
  const n2 = Number.parseInt(Number(`0x${s2}`).toString(), 10) & 2147483647;
19
- const seedHex = (0, _ocap_util.stripHexPrefix)((0, _ocap_util.isHexStrict)(rootSk) ? rootSk : (0, _ocap_util.toHex)(rootSk));
21
+ const seedHex = (0, _ocap_util.stripHexPrefix)((0, _ocap_util.isHexStrict)(rootSk) ? rootSk : (0, _ocap_util.toHex)((0, _ocap_util.toUint8Array)(rootSk)));
20
22
  const master = _scure_bip32.HDKey.fromMasterSeed(Buffer.from(seedHex, "hex"));
21
23
  const derivePath = `m/44'/260'/${n1}'/${n2}'/${index}`;
22
24
  const child = master.derive(derivePath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/did-ext",
3
- "version": "1.30.23",
3
+ "version": "1.30.25",
4
4
  "description": "Extension to work with ArcBlock DID",
5
5
  "keywords": [
6
6
  "arcblock",
@@ -57,10 +57,10 @@
57
57
  "url": "https://github.com/ArcBlock/blockchain/issues"
58
58
  },
59
59
  "dependencies": {
60
- "@arcblock/did": "1.30.23",
61
- "@ocap/mcrypto": "1.30.23",
62
- "@ocap/util": "1.30.23",
63
- "@ocap/wallet": "1.30.23",
60
+ "@arcblock/did": "1.30.25",
61
+ "@ocap/mcrypto": "1.30.25",
62
+ "@ocap/util": "1.30.25",
63
+ "@ocap/wallet": "1.30.25",
64
64
  "@scure/bip32": "^2.0.1"
65
65
  }
66
66
  }