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

ethr-did-resolver

Package Overview
Dependencies
Maintainers
1
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ethr-did-resolver - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

contracts/ethr-did-registry.json

218

lib/register.js

@@ -16,6 +16,2 @@ 'use strict';

var _promise = require('babel-runtime/core-js/promise');
var _promise2 = _interopRequireDefault(_promise);
var _getIterator2 = require('babel-runtime/core-js/get-iterator');

@@ -30,18 +26,25 @@

exports.wrapDidDocument = wrapDidDocument;
exports.configureRegistry = configureRegistry;
var _didResolver = require('did-resolver');
var _truffleContract = require('truffle-contract');
var _ethjsProviderHttp = require('ethjs-provider-http');
var _truffleContract2 = _interopRequireDefault(_truffleContract);
var _ethjsProviderHttp2 = _interopRequireDefault(_ethjsProviderHttp);
var _ethrDidRegistry = require('ethr-did-registry');
var _ethjsQuery = require('ethjs-query');
var _ethrDidRegistry2 = _interopRequireDefault(_ethrDidRegistry);
var _ethjsQuery2 = _interopRequireDefault(_ethjsQuery);
var _web = require('web3');
var _ethjsAbi = require('ethjs-abi');
var _web2 = _interopRequireDefault(_web);
var _ethjsAbi2 = _interopRequireDefault(_ethjsAbi);
var _ethjsContract = require('ethjs-contract');
var _ethjsContract2 = _interopRequireDefault(_ethjsContract);
var _ethrDidRegistry = require('../contracts/ethr-did-registry.json');
var _ethrDidRegistry2 = _interopRequireDefault(_ethrDidRegistry);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -54,3 +57,2 @@

// const expired = {}
// console.log(history)
var publicKey = [{

@@ -78,12 +80,10 @@ id: did + '#owner',

for (var _iterator = (0, _getIterator3.default)(history), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _ref = _step.value;
var event = _ref.event;
var args = _ref.args;
var event = _step.value;
// console.log(`validTo: ${args.validTo.toNumber()} and now: ${now}`)
var key = event + '-' + (args.delegateType || args.name) + '-' + (args.delegate || args.value);
if (args.validTo && args.validTo.toNumber() >= now) {
if (event === 'DIDDelegateChanged') {
// console.log(`validTo: ${event.validTo.toNumber()} and now: ${now}`)
var key = event._eventName + '-' + (event.delegateType || event.name) + '-' + (event.delegate || event.value);
if (event.validTo && event.validTo.toNumber() >= now) {
if (event._eventName === 'DIDDelegateChanged') {
delegateCount++;
switch (args.delegateType) {
switch (event.delegateType) {
case 'Secp256k1SignatureAuthentication2018':

@@ -99,8 +99,8 @@ auth[key] = {

owner: did,
ethereumAddress: args.delegate
ethereumAddress: event.delegate
};
break;
}
} else if (event === 'DIDAttributeChanged') {
var match = args.name.match(/^did\/(publicKey|authentication|service)\/(\w+)(\/(\w+))?$/);
} else if (event._eventName === 'DIDAttributeChanged') {
var match = event.name.match(/^did\/(publicKey|authentication|service)\/(\w+)(\/(\w+))?$/);
if (match) {

@@ -122,12 +122,12 @@ var section = match[1];

case 'publicKeyHex':
pk.publicKeyHex = args.value.slice(2);
pk.publicKeyHex = event.value.slice(2);
break;
case 'publicKeyBase64':
pk.publicKeyBase64 = Buffer.from(args.value.slice(2), 'hex').toString('base64');
pk.publicKeyBase64 = Buffer.from(event.value.slice(2), 'hex').toString('base64');
break;
case 'publicKeyBase58':
pk.publicKeyBase58 = Buffer.from(args.value.slice(2), 'hex').toString('base58');
pk.publicKeyBase58 = Buffer.from(event.value.slice(2), 'hex').toString('base58');
break;
default:
pk.value = args.value;
pk.value = event.value;
}

@@ -137,3 +137,3 @@ pks[key] = pk;

case 'service':
services[key] = { type: type, serviceEndpoint: Buffer.from(args.value.slice(2), 'hex').toString() };
services[key] = { type: type, serviceEndpoint: Buffer.from(event.value.slice(2), 'hex').toString() };
break;

@@ -144,3 +144,3 @@ }

} else {
if ((event === 'DIDDelegateChanged' || event === 'DIDAttributeChanged' && args.name.match(/^did\/publicKey\//)) && args.validTo.toNumber() === 0) delegateCount--;
if ((event._eventName === 'DIDDelegateChanged' || event._eventName === 'DIDAttributeChanged' && event.name.match(/^did\/publicKey\//)) && event.validTo.toNumber() === 0) delegateCount--;
delete auth[key];

@@ -187,57 +187,37 @@ delete pks[key];

} else {
return new _web2.default.providers.HttpProvider(conf.rpcUrl || 'https://mainnet.infura.io/ethr-did');
return new _ethjsProviderHttp2.default(conf.rpcUrl || 'https://mainnet.infura.io/ethr-did');
}
}
function configureRegistry() {
var conf = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
function register() {
var _this = this;
var registryAddress = conf.registry || REGISTRY;
var DidReg = (0, _truffleContract2.default)(_ethrDidRegistry2.default);
DidReg.setProvider(configureProvider(conf));
return DidReg.at(registryAddress);
}
function getLogs(filter) {
return new _promise2.default(function (resolve, reject) {
filter.get(function (error, events) {
if (error) return reject(error);
resolve(events);
});
});
}
function register() {
var changeLog = function () {
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(identity) {
var history, previousChange, filter, events, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, event;
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(identity) {
var history, previousChange, logs, events, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, event;
return _regenerator2.default.wrap(function _callee$(_context) {
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context.prev = _context.next) {
switch (_context2.prev = _context2.next) {
case 0:
history = [];
_context.next = 3;
return didReg.changed(identity);
_context2.next = 3;
return lastChanged(identity);
case 3:
previousChange = _context.sent;
previousChange = _context2.sent;
case 4:
if (!previousChange) {
_context.next = 33;
_context2.next = 31;
break;
}
_context.next = 7;
return didReg.allEvents({ topics: [identity], fromBlock: previousChange, toBlock: previousChange });
_context2.next = 7;
return eth.getLogs({ address: registryAddress, fromBlock: previousChange, toBlock: previousChange });
case 7:
filter = _context.sent;
_context.next = 10;
return getLogs(filter);
logs = _context2.sent;
events = logDecoder(logs);
case 10:
events = _context.sent;
previousChange = undefined;

@@ -247,3 +227,3 @@ _iteratorNormalCompletion2 = true;

_iteratorError2 = undefined;
_context.prev = 15;
_context2.prev = 13;
for (_iterator2 = (0, _getIterator3.default)(events); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {

@@ -253,16 +233,16 @@ event = _step2.value;

history.unshift(event);
previousChange = event.args.previousChange;
previousChange = event.previousChange;
}
_context.next = 23;
_context2.next = 21;
break;
case 19:
_context.prev = 19;
_context.t0 = _context['catch'](15);
case 17:
_context2.prev = 17;
_context2.t0 = _context2['catch'](13);
_didIteratorError2 = true;
_iteratorError2 = _context.t0;
_iteratorError2 = _context2.t0;
case 23:
_context.prev = 23;
_context.prev = 24;
case 21:
_context2.prev = 21;
_context2.prev = 22;

@@ -273,7 +253,7 @@ if (!_iteratorNormalCompletion2 && _iterator2.return) {

case 26:
_context.prev = 26;
case 24:
_context2.prev = 24;
if (!_didIteratorError2) {
_context.next = 29;
_context2.next = 27;
break;

@@ -284,21 +264,21 @@ }

case 29:
return _context.finish(26);
case 27:
return _context2.finish(24);
case 30:
return _context.finish(23);
case 28:
return _context2.finish(21);
case 31:
_context.next = 4;
case 29:
_context2.next = 4;
break;
case 33:
return _context.abrupt('return', history);
case 31:
return _context2.abrupt('return', history);
case 34:
case 32:
case 'end':
return _context.stop();
return _context2.stop();
}
}
}, _callee, this, [[15, 19, 23, 31], [24,, 26, 30]]);
}, _callee2, this, [[13, 17, 21, 29], [22,, 24, 28]]);
}));

@@ -312,10 +292,10 @@

var resolve = function () {
var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(did, parsed) {
var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(did, parsed) {
var owner, history;
return _regenerator2.default.wrap(function _callee2$(_context2) {
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context2.prev = _context2.next) {
switch (_context3.prev = _context3.next) {
case 0:
if (parsed.id.match(/^0x[0-9a-fA-F]{40}$/)) {
_context2.next = 2;
_context3.next = 2;
break;

@@ -327,20 +307,20 @@ }

case 2:
_context2.next = 4;
_context3.next = 4;
return didReg.identityOwner(parsed.id);
case 4:
owner = _context2.sent;
_context2.next = 7;
owner = _context3.sent;
_context3.next = 7;
return changeLog(parsed.id);
case 7:
history = _context2.sent;
return _context2.abrupt('return', wrapDidDocument(did, owner, history));
history = _context3.sent;
return _context3.abrupt('return', wrapDidDocument(did, owner['0'], history));
case 9:
case 'end':
return _context2.stop();
return _context3.stop();
}
}
}, _callee2, this);
}, _callee3, this);
}));

@@ -355,4 +335,42 @@

var didReg = configureRegistry(conf);
var provider = configureProvider(conf);
var eth = new _ethjsQuery2.default(provider);
var registryAddress = conf.registry || REGISTRY;
var DidReg = new _ethjsContract2.default(eth)(_ethrDidRegistry2.default);
var didReg = DidReg.at(registryAddress);
var logDecoder = _ethjsAbi2.default.logDecoder(_ethrDidRegistry2.default, false);
var lastChanged = function () {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(identity) {
var result;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return didReg.changed(identity);
case 2:
result = _context.sent;
if (!result) {
_context.next = 5;
break;
}
return _context.abrupt('return', result['0']);
case 5:
case 'end':
return _context.stop();
}
}
}, _callee, _this);
}));
return function lastChanged(_x3) {
return _ref.apply(this, arguments);
};
}();
(0, _didResolver.registerMethod)('ethr', resolve);

@@ -359,0 +377,0 @@ }

{
"name": "ethr-did-resolver",
"version": "0.0.5",
"version": "0.0.6",
"description": "Resolve DID documents around ethereum addresses",

@@ -13,2 +13,3 @@ "main": "lib/register.js",

"lib",
"contracts",
"src",

@@ -24,3 +25,4 @@ "LICENSE",

"build:es5": "./node_modules/.bin/babel src -d lib",
"build": "yarn build:es5 && yarn test"
"build:webpack": "./node_modules/.bin/webpack lib/register.js",
"build": "yarn build:es5 && yarn test && yarn build:webpack"
},

@@ -41,3 +43,6 @@ "jest": {

"regenerator-runtime": "^0.11.1",
"standard": "^11.0.0"
"standard": "^11.0.0",
"truffle-contract": "^3.0.4",
"webpack": "^4.5.0",
"webpack-cli": "^2.0.14"
},

@@ -48,4 +53,7 @@ "dependencies": {

"did-resolver": "^0.0.4",
"ethr-did-registry": "^0.0.2",
"truffle-contract": "^3.0.4"
"ethjs-abi": "^0.2.1",
"ethjs-contract": "^0.1.9",
"ethjs-provider-http": "^0.1.6",
"ethjs-query": "^0.3.5",
"ethr-did-registry": "^0.0.2"
},

@@ -52,0 +60,0 @@ "standard": {

import { registerMethod } from 'did-resolver'
import Contract from 'truffle-contract'
import DidRegistryContract from 'ethr-did-registry'
import Web3 from 'web3'
import HttpProvider from 'ethjs-provider-http'
import Eth from 'ethjs-query'
import abi from 'ethjs-abi'
import EthContract from 'ethjs-contract'
import DidRegistryContract from '../contracts/ethr-did-registry.json'

@@ -11,3 +13,2 @@ export const REGISTRY = '0xc1b66dea11f8f321b7981e1666fdaf3637fe0f61'

// const expired = {}
// console.log(history)
const publicKey = [{

@@ -29,9 +30,9 @@ id: `${did}#owner`,

const services = {}
for (let {event, args} of history) {
// console.log(`validTo: ${args.validTo.toNumber()} and now: ${now}`)
const key = `${event}-${args.delegateType||args.name}-${args.delegate||args.value}`
if (args.validTo && args.validTo.toNumber() >= now) {
if (event === 'DIDDelegateChanged') {
for (let event of history) {
// console.log(`validTo: ${event.validTo.toNumber()} and now: ${now}`)
const key = `${event._eventName}-${event.delegateType||event.name}-${event.delegate||event.value}`
if (event.validTo && event.validTo.toNumber() >= now) {
if (event._eventName === 'DIDDelegateChanged') {
delegateCount++
switch (args.delegateType) {
switch (event.delegateType) {
case 'Secp256k1SignatureAuthentication2018':

@@ -47,8 +48,8 @@ auth[key] = {

owner: did,
ethereumAddress: args.delegate
ethereumAddress: event.delegate
}
break
}
} else if (event === 'DIDAttributeChanged') {
const match = args.name.match(/^did\/(publicKey|authentication|service)\/(\w+)(\/(\w+))?$/)
} else if (event._eventName === 'DIDAttributeChanged') {
const match = event.name.match(/^did\/(publicKey|authentication|service)\/(\w+)(\/(\w+))?$/)
if (match) {

@@ -70,12 +71,12 @@ const section = match[1]

case 'publicKeyHex':
pk.publicKeyHex = args.value.slice(2)
pk.publicKeyHex = event.value.slice(2)
break
case 'publicKeyBase64':
pk.publicKeyBase64 = Buffer.from(args.value.slice(2), 'hex').toString('base64')
pk.publicKeyBase64 = Buffer.from(event.value.slice(2), 'hex').toString('base64')
break
case 'publicKeyBase58':
pk.publicKeyBase58 = Buffer.from(args.value.slice(2), 'hex').toString('base58')
pk.publicKeyBase58 = Buffer.from(event.value.slice(2), 'hex').toString('base58')
break
default:
pk.value = args.value
pk.value = event.value
}

@@ -85,3 +86,3 @@ pks[key] = pk

case 'service':
services[key] = {type, serviceEndpoint: Buffer.from(args.value.slice(2), 'hex').toString()}
services[key] = {type, serviceEndpoint: Buffer.from(event.value.slice(2), 'hex').toString()}
break

@@ -92,3 +93,3 @@ }

} else {
if ((event === 'DIDDelegateChanged' || (event === 'DIDAttributeChanged' && args.name.match(/^did\/publicKey\//))) && args.validTo.toNumber() === 0) delegateCount--
if ((event._eventName === 'DIDDelegateChanged' || (event._eventName === 'DIDAttributeChanged' && event.name.match(/^did\/publicKey\//))) && event.validTo.toNumber() === 0) delegateCount--
delete auth[key]

@@ -119,35 +120,30 @@ delete pks[key]

} else {
return new Web3.providers.HttpProvider(conf.rpcUrl || 'https://mainnet.infura.io/ethr-did')
return new HttpProvider(conf.rpcUrl || 'https://mainnet.infura.io/ethr-did')
}
}
export function configureRegistry (conf = {}) {
function register (conf = {}) {
const provider = configureProvider(conf)
const eth = new Eth(provider)
const registryAddress = conf.registry || REGISTRY
const DidReg = Contract(DidRegistryContract)
DidReg.setProvider(configureProvider(conf))
return DidReg.at(registryAddress)
}
const DidReg = new EthContract(eth)(DidRegistryContract)
const didReg = DidReg.at(registryAddress)
const logDecoder = abi.logDecoder(DidRegistryContract, false)
function getLogs (filter) {
return new Promise((resolve, reject) => {
filter.get((error, events) => {
if (error) return reject(error)
resolve(events)
})
})
}
function register (conf = {}) {
const didReg = configureRegistry(conf)
const lastChanged = async (identity) => {
const result = await didReg.changed(identity)
if (result) {
return result['0']
}
}
async function changeLog (identity) {
const history = []
let previousChange = await didReg.changed(identity)
let previousChange = await lastChanged(identity)
while (previousChange) {
const filter = await didReg.allEvents({topics: [identity], fromBlock: previousChange, toBlock: previousChange})
const events = await getLogs(filter)
const logs = await eth.getLogs({address: registryAddress, fromBlock: previousChange, toBlock: previousChange})
const events = logDecoder(logs)
previousChange = undefined
for (let event of events) {
history.unshift(event)
previousChange = event.args.previousChange
previousChange = event.previousChange
}

@@ -161,3 +157,3 @@ }

const history = await changeLog(parsed.id)
return wrapDidDocument(did, owner, history)
return wrapDidDocument(did, owner['0'], history)
}

@@ -164,0 +160,0 @@ registerMethod('ethr', resolve)

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