Socket
Socket
Sign inDemoInstall

@arcblock/did

Package Overview
Dependencies
Maintainers
1
Versions
518
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arcblock/did - npm Package Compare versions

Comparing version 0.26.0 to 0.26.10

29

lib/index.d.ts
// 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;

54

lib/index.js

@@ -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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc