Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@arcblock/abt-did

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arcblock/abt-did - npm Package Compare versions

Comparing version 0.14.3 to 0.15.0

lib/index.d.ts

37

lib/index.js
const upperFirst = require('lodash/upperFirst');
const { toBN, toHex, numberToHex, isHexStrict, stripHexPrefix } = require('@arcblock/forge-util');
const stringify = require('json-stable-stringify');
const Mcrypto = require('@arcblock/mcrypto');

@@ -7,2 +7,3 @@ const multibase = require('multibase');

const hdkey = require('hdkey');
const { toBN, toHex, numberToHex, isHexStrict, stripHexPrefix } = require('@arcblock/forge-util');
const { DID_PREFIX, toBits, toBytes, toStrictHex } = require('./util');

@@ -252,4 +253,2 @@ const { types, getSigner, getHasher } = Mcrypto;

})
// sort keys
.sort()
.reduce((acc, x) => {

@@ -260,3 +259,3 @@ acc[x] = body[x];

const bodyB64 = base64.escape(base64.encode(JSON.stringify(body)));
const bodyB64 = base64.escape(base64.encode(stringify(body)));

@@ -272,2 +271,20 @@ // make signature

/**
* Decode info from jwt token
*
* @param {*} token
* @param {boolean} [payloadOnly=false]
* @returns
*/
const jwtDecode = (token, payloadOnly = true) => {
const [headerB64, bodyB64, sigB64] = token.split('.');
const header = JSON.parse(base64.decode(base64.unescape(headerB64)));
const body = JSON.parse(base64.decode(base64.unescape(bodyB64)));
const sig = Buffer.from(base64.unescape(sigB64), 'base64').toString('hex');
if (payloadOnly) {
return body;
}
return { header, body, signature: `0x${toStrictHex(sig)}` };
};
/**
* Verify a jwt token signed with pk and certain issuer

@@ -281,8 +298,5 @@ *

try {
const [headerB64, bodyB64, sigB64] = token.split('.');
const header = JSON.parse(base64.decode(base64.unescape(headerB64)));
const body = JSON.parse(base64.decode(base64.unescape(bodyB64)));
const signature = Buffer.from(base64.unescape(sigB64), 'base64').toString('hex');
const sigHex = `0x${toStrictHex(signature)}`;
if (!sigHex) {
const [headerB64, bodyB64] = token.split('.');
const { header, body, signature } = jwtDecode(token, false);
if (!signature) {
return false;

@@ -311,3 +325,3 @@ }

const msgHex = toHex(`${headerB64}.${bodyB64}`);
return signers[alg].verify(msgHex, sigHex, pk);
return signers[alg].verify(msgHex, signature, pk);
}

@@ -337,2 +351,3 @@

jwtVerify,
jwtDecode,
};
{
"name": "@arcblock/abt-did",
"version": "0.14.3",
"version": "0.15.0",
"description": "Javascript lib to work with ArcBlock DID",

@@ -40,7 +40,8 @@ "keywords": [

"dependencies": {
"@arcblock/forge-util": "^0.14.3",
"@arcblock/mcrypto": "^0.14.3",
"@arcblock/forge-util": "^0.15.0",
"@arcblock/mcrypto": "^0.15.0",
"base64-url": "^2.2.0",
"debug": "^4.1.1",
"hdkey": "^1.1.1",
"json-stable-stringify": "^1.0.1",
"lodash": "^4.17.11",

@@ -50,3 +51,3 @@ "multibase": "^0.6.0",

},
"gitHead": "6f1b372879894a6a68f08c53116faa4c527e4110"
"gitHead": "4ef4154c785ba27f71f5af2d66e67270857b4750"
}
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