@blocklet/meta
Advanced tools
Comparing version 1.1.7 to 1.1.8
@@ -1,7 +0,4 @@ | ||
const hdkey = require('@wangshijun/hdkey'); | ||
const Mcrypto = require('@arcblock/mcrypto'); | ||
const { fromSecretKey } = require('@arcblock/forge-wallet'); | ||
const { toBN, isHexStrict, toHex, stripHexPrefix } = require('@arcblock/forge-util'); | ||
const { isValid } = require('@arcblock/did'); | ||
const { toBits, toBytes } = require('@arcblock/did/lib/util'); | ||
const { fromAppDid } = require('@arcblock/did-ext'); | ||
@@ -25,3 +22,3 @@ const { types } = Mcrypto; | ||
if (!isValid(blockletDid)) { | ||
return null; | ||
throw new Error('Cannot get blocklet wallet with invalid blocklet did'); | ||
} | ||
@@ -33,34 +30,5 @@ | ||
const hash = Mcrypto.Hasher.SHA3.hash256(toBytes(blockletDid)); | ||
const hashSlice = stripHexPrefix(hash).slice(0, 16); | ||
const s1 = hashSlice.slice(0, 8); | ||
const s2 = hashSlice.slice(8, 16); | ||
// We have to ensure the number parsed from s1, s2 to be a valid index | ||
const b1 = toBits(toBN(s1).toTwos(), 8, '0').split(''); | ||
const b2 = toBits(toBN(s2).toTwos(), 8, '0').split(''); | ||
// set highest bit to zero, since s1 and s2 are 32 bits long | ||
b1[0] = 0; | ||
b2[0] = 0; | ||
const n1 = parseInt(b1.join(''), 2); | ||
const n2 = parseInt(b2.join(''), 2); | ||
const seedHex = stripHexPrefix(isHexStrict(nodeSk) ? nodeSk : toHex(nodeSk)); | ||
const master = hdkey.fromMasterSeed(Buffer.from(seedHex, 'hex')); | ||
const derivePath = `m/44'/260'/${n1}'/${n2}'/${index}`; | ||
const child = master.derive(derivePath); | ||
const { pk = types.KeyType.ED25519 } = type; | ||
let sk; | ||
if (pk === types.KeyType.ED25519) { | ||
const keyPair = Mcrypto.Signer.Ed25519.genKeyPair(child.privateKey); | ||
sk = keyPair.secretKey; | ||
} else { | ||
sk = child.privateKey; | ||
} | ||
return fromSecretKey(sk, type); | ||
return fromAppDid(blockletDid, nodeSk, type, index); | ||
}; | ||
module.exports = getBlockletWallet; |
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "1.1.7", | ||
"version": "1.1.8", | ||
"description": "Library to parse/validate/fix blocklet meta", | ||
@@ -22,7 +22,6 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@arcblock/did": "^1.4.8", | ||
"@arcblock/forge-util": "^1.4.8", | ||
"@arcblock/forge-wallet": "^1.4.8", | ||
"@arcblock/mcrypto": "^1.4.8", | ||
"@wangshijun/hdkey": "^2.0.4", | ||
"@arcblock/did": "^1.5.1", | ||
"@arcblock/did-ext": "^1.5.1", | ||
"@arcblock/forge-util": "^1.5.1", | ||
"@arcblock/mcrypto": "^1.5.1", | ||
"axios": "^0.21.0", | ||
@@ -41,3 +40,3 @@ "debug": "^4.2.0", | ||
}, | ||
"gitHead": "00aeec83ce23db91206774f4776911ab9df578cc" | ||
"gitHead": "5957931df6266433e56b29df1b4713df282cce3d" | ||
} |
12
29411
831
+ Added@arcblock/did-ext@^1.5.1
+ Added@arcblock/did-ext@1.19.6(transitive)
+ Added@ocap/wallet@1.19.6(transitive)
- Removed@arcblock/forge-wallet@^1.4.8
- Removed@wangshijun/hdkey@^2.0.4
- Removed@arcblock/forge-wallet@1.7.1(transitive)
Updated@arcblock/did@^1.5.1
Updated@arcblock/forge-util@^1.5.1
Updated@arcblock/mcrypto@^1.5.1