@arcblock/did
Advanced tools
Comparing version 0.26.0 to 0.26.10
// Generate by [js2dts@0.3.2](https://github.com/whxaxes/js2dts#readme) | ||
/** | ||
* Convert did to address: remove `did:abt:` prefix if exists | ||
* | ||
* @public | ||
* @static | ||
* @param {string} did - address string | ||
* @returns {string} | ||
*/ | ||
declare function toAddress(did: string): string; | ||
/** | ||
* Convert address to did: prepend `did:abt:` prefix | ||
* | ||
* @public | ||
* @static | ||
* @param {string} did - address string | ||
* @returns {string} | ||
*/ | ||
declare function toDid(address: any): string; | ||
declare const _Lib: _Lib.T100; | ||
@@ -8,6 +26,7 @@ declare namespace _Lib { | ||
toStrictHex: (hex: string, length: number) => string; | ||
fromAppDID: (appDID: string, seed: string, type?: any, index?: number) => any; | ||
fromSecretKey: (sk: string, type: any) => any; | ||
fromPublicKey: (pk: string, type: any) => any; | ||
fromSecretKey: (sk: string, type: any) => string; | ||
fromPublicKey: (pk: string, type: any) => string; | ||
toTypeInfo: (did: string, returnString?: boolean) => any; | ||
toAddress: typeof toAddress; | ||
toDid: typeof toDid; | ||
fromTypeInfo: (type: any) => string; | ||
@@ -17,6 +36,6 @@ isFromPublicKey: (did: string, pk: string) => boolean; | ||
jwtSign: (did: string, sk: string, payload?: any) => string; | ||
jwtVerify: (token: string, pk: string) => boolean; | ||
jwtDecode: (token: any, payloadOnly?: boolean) => any; | ||
jwtVerify: (token: string, pk: string, tolerance?: number) => boolean; | ||
jwtDecode: (token: string, payloadOnly?: boolean) => any; | ||
} | ||
} | ||
export = _Lib; |
@@ -13,4 +13,3 @@ /** | ||
const base64 = require('base64-url'); | ||
const hdkey = require('hdkey'); | ||
const { toBN, toHex, numberToHex, isHexStrict, stripHexPrefix } = require('@arcblock/forge-util'); | ||
const { toHex, numberToHex, stripHexPrefix } = require('@arcblock/forge-util'); | ||
const { DID_PREFIX, toBits, toBytes, toStrictHex } = require('./util'); | ||
@@ -24,52 +23,2 @@ const { types, getSigner, getHasher } = Mcrypto; | ||
/** | ||
* Gen DID from appDID and seed | ||
* | ||
* Spec: https://github.com/ArcBlock/ABT-DID-Protocol#request-did-authentication | ||
* | ||
* @public | ||
* @static | ||
* @param {string} appDID | ||
* @param {string} seed | ||
* @param {object} [type={}] | ||
* @param {number} [index=0] | ||
* @returns {string} DID string | ||
*/ | ||
const fromAppDID = (appDID, seed, type = {}, index = 0) => { | ||
if (!isValid(appDID)) { | ||
return null; | ||
} | ||
const hash = Mcrypto.Hasher.SHA3.hash256(toBytes(appDID)); | ||
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(seed) ? seed : toHex(seed)); | ||
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) { | ||
// HACK: because tweetnacl requires a 64 byte sk | ||
sk = Buffer.concat([child.privateKey, child.chainCode]); | ||
} else { | ||
sk = child.privateKey; | ||
} | ||
return fromSecretKey(sk, type); | ||
}; | ||
/** | ||
* Gen DID from private key and type config | ||
@@ -400,3 +349,2 @@ * | ||
toStrictHex, | ||
fromAppDID, | ||
fromSecretKey, | ||
@@ -403,0 +351,0 @@ fromPublicKey, |
{ | ||
"name": "@arcblock/did", | ||
"version": "0.26.0", | ||
"version": "0.26.10", | ||
"description": "Javascript lib to work with ArcBlock DID", | ||
@@ -36,2 +36,3 @@ "keywords": [ | ||
"generate-docs": "jsdoc2md lib/index.js > docs/README.md", | ||
"generate-dts": "j2d lib/index.js", | ||
"format-docs": "remark . -o", | ||
@@ -47,13 +48,11 @@ "precommit": "CI=1 yarn test", | ||
"dependencies": { | ||
"@arcblock/forge-util": "^0.26.0", | ||
"@arcblock/mcrypto": "^0.26.0", | ||
"@arcblock/forge-util": "^0.26.10", | ||
"@arcblock/mcrypto": "^0.26.10", | ||
"base64-url": "^2.2.0", | ||
"debug": "^4.1.1", | ||
"hdkey": "^1.1.1", | ||
"json-stable-stringify": "^1.0.1", | ||
"lodash": "^4.17.11", | ||
"multibase": "^0.6.0", | ||
"randombytes": "^2.0.6" | ||
"multibase": "^0.6.0" | ||
}, | ||
"gitHead": "24cf584797dd865d86517a400d9b2c08c138e793" | ||
"gitHead": "c9300e0f82d22e20a0e32d3fb4beb761b6e37023" | ||
} |
@@ -13,3 +13,2 @@ # `@arcblock/did` | ||
const Mcrypto = require('@arcblock/mcrypto'); | ||
const randomBytes = require('randombytes'); | ||
const { fromSecretKey, fromPublicKey, fromAppDID } = require('@arcblock/did'); | ||
@@ -16,0 +15,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7
15032
409
49
- Removedhdkey@^1.1.1
- Removedrandombytes@^2.0.6
- Removedbindings@1.5.0(transitive)
- Removedbip66@1.1.5(transitive)
- Removedbrowserify-aes@1.2.0(transitive)
- Removedbs58@4.0.1(transitive)
- Removedbs58check@2.1.2(transitive)
- Removedbuffer-xor@1.0.3(transitive)
- Removedcipher-base@1.0.4(transitive)
- Removedcreate-hash@1.2.0(transitive)
- Removedcreate-hmac@1.1.7(transitive)
- Removeddrbg.js@1.0.1(transitive)
- Removedevp_bytestokey@1.0.3(transitive)
- Removedfile-uri-to-path@1.0.0(transitive)
- Removedhash-base@3.1.0(transitive)
- Removedhdkey@1.1.2(transitive)
- Removedmd5.js@1.3.5(transitive)
- Removednan@2.20.0(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedripemd160@2.0.2(transitive)
- Removedsecp256k1@3.8.0(transitive)
- Removedsha.js@2.4.11(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
Updated@arcblock/mcrypto@^0.26.10