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

ethr-did-resolver

Package Overview
Dependencies
Maintainers
2
Versions
84
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.1.1 to 0.1.3

402

lib/__tests__/register-test.js

@@ -66,2 +66,46 @@ 'use strict';

var stopMining = function stopMining() {
return new _promise2.default(function (resolve, reject) {
return web3.currentProvider.send({
jsonrpc: '2.0',
method: 'miner_stop',
id: new Date().getTime()
}, function (e, val) {
if (e) reject(e);
return resolve(val);
});
});
};
var startMining = function startMining() {
new _promise2.default(function () {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(resolve, reject) {
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
web3.currentProvider.send({
jsonrpc: '2.0',
method: 'miner_start',
params: [1],
id: new Date().getTime()
}, function (e, val) {
if (e) reject(e);
return resolve(val);
});
case 1:
case 'end':
return _context.stop();
}
}
}, _callee, undefined);
}));
return function (_x, _x2) {
return _ref.apply(this, arguments);
};
}());
};
var registry = void 0,

@@ -75,12 +119,12 @@ accounts = void 0,

beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
return _regenerator2.default.wrap(function _callee$(_context) {
beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() {
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context.prev = _context.next) {
switch (_context2.prev = _context2.next) {
case 0:
_context.next = 2;
_context2.next = 2;
return getAccounts();
case 2:
accounts = _context.sent;
accounts = _context2.sent;

@@ -93,3 +137,3 @@ identity = accounts[1];

_context.next = 10;
_context2.next = 10;
return DidReg.new({

@@ -102,3 +146,3 @@ from: accounts[0],

case 10:
registry = _context.sent;
registry = _context2.sent;

@@ -109,6 +153,6 @@ (0, _register2.default)({ provider: provider, registry: registry.address });

case 'end':
return _context.stop();
return _context2.stop();
}
}
}, _callee, undefined);
}, _callee2, undefined);
})));

@@ -136,8 +180,8 @@

describe('owner changed', function () {
beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() {
return _regenerator2.default.wrap(function _callee2$(_context2) {
beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3() {
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context2.prev = _context2.next) {
switch (_context3.prev = _context3.next) {
case 0:
_context2.next = 2;
_context3.next = 2;
return registry.changeOwner(identity, owner, { from: identity });

@@ -147,6 +191,6 @@

case 'end':
return _context2.stop();
return _context3.stop();
}
}
}, _callee2, undefined);
}, _callee3, undefined);
})));

@@ -174,8 +218,8 @@

describe('add signing delegate', function () {
beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3() {
return _regenerator2.default.wrap(function _callee3$(_context3) {
beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4() {
return _regenerator2.default.wrap(function _callee4$(_context4) {
while (1) {
switch (_context3.prev = _context3.next) {
switch (_context4.prev = _context4.next) {
case 0:
_context3.next = 2;
_context4.next = 2;
return registry.addDelegate(identity, Secp256k1VerificationKey2018, delegate1, 2, { from: owner });

@@ -185,6 +229,6 @@

case 'end':
return _context3.stop();
return _context4.stop();
}
}
}, _callee3, undefined);
}, _callee4, undefined);
})));

@@ -216,8 +260,8 @@

describe('add auth delegate', function () {
beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4() {
return _regenerator2.default.wrap(function _callee4$(_context4) {
beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5() {
return _regenerator2.default.wrap(function _callee5$(_context5) {
while (1) {
switch (_context4.prev = _context4.next) {
switch (_context5.prev = _context5.next) {
case 0:
_context4.next = 2;
_context5.next = 2;
return registry.addDelegate(identity, Secp256k1SignatureAuthentication2018, delegate2, 10, { from: owner });

@@ -227,6 +271,6 @@

case 'end':
return _context4.stop();
return _context5.stop();
}
}
}, _callee4, undefined);
}, _callee5, undefined);
})));

@@ -266,8 +310,8 @@

describe('expire automatically', function () {
beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5() {
return _regenerator2.default.wrap(function _callee5$(_context5) {
beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6() {
return _regenerator2.default.wrap(function _callee6$(_context6) {
while (1) {
switch (_context5.prev = _context5.next) {
switch (_context6.prev = _context6.next) {
case 0:
_context5.next = 2;
_context6.next = 2;
return sleep(3);

@@ -277,6 +321,6 @@

case 'end':
return _context5.stop();
return _context6.stop();
}
}
}, _callee5, undefined);
}, _callee6, undefined);
})));

@@ -311,12 +355,12 @@

describe('revokes delegate', function () {
beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6() {
return _regenerator2.default.wrap(function _callee6$(_context6) {
beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee7() {
return _regenerator2.default.wrap(function _callee7$(_context7) {
while (1) {
switch (_context6.prev = _context6.next) {
switch (_context7.prev = _context7.next) {
case 0:
_context6.next = 2;
_context7.next = 2;
return registry.revokeDelegate(identity, Secp256k1SignatureAuthentication2018, delegate2, { from: owner });
case 2:
_context6.next = 4;
_context7.next = 4;
return sleep(1);

@@ -326,6 +370,6 @@

case 'end':
return _context6.stop();
return _context7.stop();
}
}
}, _callee6, undefined);
}, _callee7, undefined);
})));

@@ -352,12 +396,12 @@

describe('re-add auth delegate', function () {
beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee7() {
return _regenerator2.default.wrap(function _callee7$(_context7) {
beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8() {
return _regenerator2.default.wrap(function _callee8$(_context8) {
while (1) {
switch (_context7.prev = _context7.next) {
switch (_context8.prev = _context8.next) {
case 0:
_context7.next = 2;
_context8.next = 2;
return sleep(3);
case 2:
_context7.next = 4;
_context8.next = 4;
return registry.addDelegate(identity, Secp256k1SignatureAuthentication2018, delegate2, 86400, { from: owner });

@@ -367,6 +411,6 @@

case 'end':
return _context7.stop();
return _context8.stop();
}
}
}, _callee7, undefined);
}, _callee8, undefined);
})));

@@ -402,10 +446,10 @@

describe('attributes', function () {
describe('publicKey', function () {
describe('add publicKey', function () {
describe('Secp256k1VerificationKey2018', function () {
beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8() {
return _regenerator2.default.wrap(function _callee8$(_context8) {
beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee9() {
return _regenerator2.default.wrap(function _callee9$(_context9) {
while (1) {
switch (_context8.prev = _context8.next) {
switch (_context9.prev = _context9.next) {
case 0:
_context8.next = 2;
_context9.next = 2;
return registry.setAttribute(identity, (0, _register.stringToBytes32)('did/pub/Secp256k1/veriKey'), '0x02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71', 10, { from: owner });

@@ -415,6 +459,6 @@

case 'end':
return _context8.stop();
return _context9.stop();
}
}
}, _callee8, undefined);
}, _callee9, undefined);
})));

@@ -453,8 +497,8 @@ it('resolves document', function () {

describe('Ed25519VerificationKey2018', function () {
beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee9() {
return _regenerator2.default.wrap(function _callee9$(_context9) {
beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee10() {
return _regenerator2.default.wrap(function _callee10$(_context10) {
while (1) {
switch (_context9.prev = _context9.next) {
switch (_context10.prev = _context10.next) {
case 0:
_context9.next = 2;
_context10.next = 2;
return registry.setAttribute(identity, (0, _register.stringToBytes32)('did/pub/Ed25519/veriKey/base64'), '0x02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71', 10, { from: owner });

@@ -464,6 +508,6 @@

case 'end':
return _context9.stop();
return _context10.stop();
}
}
}, _callee9, undefined);
}, _callee10, undefined);
})));

@@ -508,10 +552,10 @@

describe('service endpoints', function () {
describe('add service endpoints', function () {
describe('HubService', function () {
beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee10() {
return _regenerator2.default.wrap(function _callee10$(_context10) {
beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee11() {
return _regenerator2.default.wrap(function _callee11$(_context11) {
while (1) {
switch (_context10.prev = _context10.next) {
switch (_context11.prev = _context11.next) {
case 0:
_context10.next = 2;
_context11.next = 2;
return registry.setAttribute(identity, (0, _register.stringToBytes32)('did/svc/HubService'), 'https://hubs.uport.me', 10, { from: owner });

@@ -521,6 +565,6 @@

case 'end':
return _context10.stop();
return _context11.stop();
}
}
}, _callee10, undefined);
}, _callee11, undefined);
})));

@@ -567,4 +611,228 @@ it('resolves document', function () {

});
describe('revoke publicKey', function () {
describe('Secp256k1VerificationKey2018', function () {
beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee12() {
return _regenerator2.default.wrap(function _callee12$(_context12) {
while (1) {
switch (_context12.prev = _context12.next) {
case 0:
_context12.next = 2;
return registry.revokeAttribute(identity, (0, _register.stringToBytes32)('did/pub/Secp256k1/veriKey'), '0x02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71', { from: owner });
case 2:
sleep(1);
case 3:
case 'end':
return _context12.stop();
}
}
}, _callee12, undefined);
})));
it('resolves document', function () {
return expect((0, _didResolver2.default)(did)).resolves.toEqual({
'@context': 'https://w3id.org/did/v1',
id: did,
publicKey: [{
id: did + '#owner',
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner
}, {
id: did + '#delegate-1',
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate2
}, {
id: did + '#delegate-3',
type: 'Ed25519VerificationKey2018',
owner: did,
publicKeyBase64: Buffer.from('02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71', 'hex').toString('base64')
}],
authentication: [{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: did + '#owner'
}, {
type: 'Secp256k1SignatureAuthentication2018',
publicKey: did + '#delegate-1'
}],
service: [{
type: 'HubService',
serviceEndpoint: 'https://hubs.uport.me'
}]
});
});
});
describe('Ed25519VerificationKey2018', function () {
beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee13() {
return _regenerator2.default.wrap(function _callee13$(_context13) {
while (1) {
switch (_context13.prev = _context13.next) {
case 0:
_context13.next = 2;
return registry.revokeAttribute(identity, (0, _register.stringToBytes32)('did/pub/Ed25519/veriKey/base64'), '0x02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71', { from: owner });
case 2:
sleep(1);
case 3:
case 'end':
return _context13.stop();
}
}
}, _callee13, undefined);
})));
it('resolves document', function () {
return expect((0, _didResolver2.default)(did)).resolves.toEqual({
'@context': 'https://w3id.org/did/v1',
id: did,
publicKey: [{
id: did + '#owner',
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner
}, {
id: did + '#delegate-1',
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate2
}],
authentication: [{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: did + '#owner'
}, {
type: 'Secp256k1SignatureAuthentication2018',
publicKey: did + '#delegate-1'
}],
service: [{
type: 'HubService',
serviceEndpoint: 'https://hubs.uport.me'
}]
});
});
});
});
describe('revoke service endpoints', function () {
describe('HubService', function () {
beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee14() {
return _regenerator2.default.wrap(function _callee14$(_context14) {
while (1) {
switch (_context14.prev = _context14.next) {
case 0:
_context14.next = 2;
return registry.revokeAttribute(identity, (0, _register.stringToBytes32)('did/svc/HubService'), 'https://hubs.uport.me', { from: owner });
case 2:
sleep(1);
case 3:
case 'end':
return _context14.stop();
}
}
}, _callee14, undefined);
})));
it('resolves document', function () {
return expect((0, _didResolver2.default)(did)).resolves.toEqual({
'@context': 'https://w3id.org/did/v1',
id: did,
publicKey: [{
id: did + '#owner',
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner
}, {
id: did + '#delegate-1',
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate2
}],
authentication: [{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: did + '#owner'
}, {
type: 'Secp256k1SignatureAuthentication2018',
publicKey: did + '#delegate-1'
}]
});
});
});
});
});
describe('multiple events in one block', function () {
beforeAll((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee15() {
return _regenerator2.default.wrap(function _callee15$(_context15) {
while (1) {
switch (_context15.prev = _context15.next) {
case 0:
_context15.next = 2;
return stopMining();
case 2:
_context15.next = 4;
return _promise2.default.all([registry.setAttribute(identity, (0, _register.stringToBytes32)('did/svc/TestService'), 'https://test.uport.me', 10, { from: owner }), registry.setAttribute(identity, (0, _register.stringToBytes32)('did/svc/TestService'), 'https://test.uport.me', 10, { from: owner }), sleep(1).then(function () {
return startMining();
})]);
case 4:
case 'end':
return _context15.stop();
}
}
}, _callee15, undefined);
})));
it('resolves document', (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee16() {
return _regenerator2.default.wrap(function _callee16$(_context16) {
while (1) {
switch (_context16.prev = _context16.next) {
case 0:
_context16.t0 = expect;
_context16.next = 3;
return (0, _didResolver2.default)(did);
case 3:
_context16.t1 = _context16.sent;
_context16.t2 = {
'@context': 'https://w3id.org/did/v1',
id: did,
publicKey: [{
id: did + '#owner',
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner
}, {
id: did + '#delegate-1',
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate2
}],
authentication: [{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: did + '#owner'
}, {
type: 'Secp256k1SignatureAuthentication2018',
publicKey: did + '#delegate-1'
}],
service: [{
type: 'TestService',
serviceEndpoint: 'https://test.uport.me'
}]
};
(0, _context16.t0)(_context16.t1).toEqual(_context16.t2);
case 6:
case 'end':
return _context16.stop();
}
}
}, _callee16, undefined);
})));
});
describe('error handling', function () {

@@ -571,0 +839,0 @@ it('rejects promise', function () {

65

lib/register.js

@@ -112,4 +112,4 @@ 'use strict';

delegateCount++;
var _delegateType = bytes32toString(event.delegateType);
switch (_delegateType) {
var delegateType = bytes32toString(event.delegateType);
switch (delegateType) {
case 'sigAuth':

@@ -163,3 +163,6 @@ auth[key] = {

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

@@ -170,3 +173,3 @@ }

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

@@ -222,3 +225,3 @@ delete pks[key];

var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(identity) {
var history, previousChange, logs, events, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, event;
var history, previousChange, blockNumber, logs, events, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, event;

@@ -238,10 +241,16 @@ return _regenerator2.default.wrap(function _callee2$(_context2) {

if (!previousChange) {
_context2.next = 31;
_context2.next = 32;
break;
}
_context2.next = 7;
return eth.getLogs({ address: registryAddress, topics: [null, '0x000000000000000000000000' + identity.slice(2)], fromBlock: previousChange, toBlock: previousChange });
blockNumber = previousChange;
_context2.next = 8;
return eth.getLogs({
address: registryAddress,
topics: [null, '0x000000000000000000000000' + identity.slice(2)],
fromBlock: previousChange,
toBlock: previousChange
});
case 7:
case 8:
logs = _context2.sent;

@@ -254,3 +263,3 @@ events = logDecoder(logs);

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

@@ -260,16 +269,18 @@ event = _step2.value;

history.unshift(event);
previousChange = event.previousChange;
if (event.previousChange.lt(blockNumber)) {
previousChange = event.previousChange;
}
}
_context2.next = 21;
_context2.next = 22;
break;
case 17:
_context2.prev = 17;
_context2.t0 = _context2['catch'](13);
case 18:
_context2.prev = 18;
_context2.t0 = _context2['catch'](14);
_didIteratorError2 = true;
_iteratorError2 = _context2.t0;
case 21:
_context2.prev = 21;
case 22:
_context2.prev = 22;
_context2.prev = 23;

@@ -280,7 +291,7 @@ if (!_iteratorNormalCompletion2 && _iterator2.return) {

case 24:
_context2.prev = 24;
case 25:
_context2.prev = 25;
if (!_didIteratorError2) {
_context2.next = 27;
_context2.next = 28;
break;

@@ -291,16 +302,16 @@ }

case 27:
return _context2.finish(24);
case 28:
return _context2.finish(21);
return _context2.finish(25);
case 29:
return _context2.finish(22);
case 30:
_context2.next = 4;
break;
case 31:
case 32:
return _context2.abrupt('return', history);
case 32:
case 33:
case 'end':

@@ -310,3 +321,3 @@ return _context2.stop();

}
}, _callee2, this, [[13, 17, 21, 29], [22,, 24, 28]]);
}, _callee2, this, [[14, 18, 22, 30], [23,, 25, 29]]);
}));

@@ -313,0 +324,0 @@

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

@@ -5,0 +5,0 @@ "main": "lib/register.js",

---
title: "Ethr DID Resolver"
index: 7
category: "reference"
type: "content"
category: "ethr-did-resolver"
type: "reference"
source: "https://github.com/uport-project/ethr-did-resolver/blob/develop/README.md"

@@ -7,0 +7,0 @@ ---

@@ -8,5 +8,8 @@ import resolve from 'did-resolver'

const { Secp256k1SignatureAuthentication2018, Secp256k1VerificationKey2018 } = delegateTypes
const {
Secp256k1SignatureAuthentication2018,
Secp256k1VerificationKey2018,
} = delegateTypes
function sleep (seconds) {
function sleep(seconds) {
return new Promise((resolve, reject) => setTimeout(resolve, seconds * 1000))

@@ -21,5 +24,42 @@ }

web3.setProvider(provider)
const getAccounts = () => new Promise((resolve, reject) => web3.eth.getAccounts((error, accounts) => error ? reject(error) : resolve(accounts)))
const getAccounts = () =>
new Promise((resolve, reject) =>
web3.eth.getAccounts(
(error, accounts) => (error ? reject(error) : resolve(accounts))
)
)
DidReg.setProvider(provider)
const stopMining = () =>
new Promise((resolve, reject) =>
web3.currentProvider.send(
{
jsonrpc: '2.0',
method: 'miner_stop',
id: new Date().getTime(),
},
(e, val) => {
if (e) reject(e)
return resolve(val)
}
)
)
const startMining = () => {
new Promise(async (resolve, reject) => {
web3.currentProvider.send(
{
jsonrpc: '2.0',
method: 'miner_start',
params: [1],
id: new Date().getTime(),
},
(e, val) => {
if (e) reject(e)
return resolve(val)
}
)
})
}
let registry, accounts, did, identity, owner, delegate1, delegate2

@@ -38,5 +78,5 @@

gasPrice: 100000000000,
gas: 4712388 //1779962
gas: 4712388, //1779962
})
register({provider, registry: registry.address})
register({ provider, registry: registry.address })
})

@@ -49,12 +89,16 @@

id: did,
publicKey: [{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: identity
}],
authentication: [{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`
}]
publicKey: [
{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: identity,
},
],
authentication: [
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`,
},
],
})

@@ -66,3 +110,3 @@ })

beforeAll(async () => {
await registry.changeOwner(identity, owner, {from: identity})
await registry.changeOwner(identity, owner, { from: identity })
})

@@ -74,12 +118,16 @@

id: did,
publicKey: [{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner
}],
authentication: [{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`
}]
publicKey: [
{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner,
},
],
authentication: [
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`,
},
],
})

@@ -92,3 +140,9 @@ })

beforeAll(async () => {
await registry.addDelegate(identity, Secp256k1VerificationKey2018, delegate1, 2, {from: owner})
await registry.addDelegate(
identity,
Secp256k1VerificationKey2018,
delegate1,
2,
{ from: owner }
)
})

@@ -100,17 +154,22 @@

id: did,
publicKey: [{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner
}, {
id: `${did}#delegate-1`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate1
}],
authentication: [{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`
}]
publicKey: [
{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner,
},
{
id: `${did}#delegate-1`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate1,
},
],
authentication: [
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`,
},
],
})

@@ -122,3 +181,9 @@ })

beforeAll(async () => {
await registry.addDelegate(identity, Secp256k1SignatureAuthentication2018, delegate2, 10, {from: owner})
await registry.addDelegate(
identity,
Secp256k1SignatureAuthentication2018,
delegate2,
10,
{ from: owner }
)
})

@@ -130,25 +195,32 @@

id: did,
publicKey: [{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner
}, {
id: `${did}#delegate-1`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate1
}, {
id: `${did}#delegate-2`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate2
}],
authentication: [{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`
}, {
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#delegate-2`
}]
publicKey: [
{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner,
},
{
id: `${did}#delegate-1`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate1,
},
{
id: `${did}#delegate-2`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate2,
},
],
authentication: [
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`,
},
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#delegate-2`,
},
],
})

@@ -167,20 +239,26 @@ })

id: did,
publicKey: [{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner
}, {
id: `${did}#delegate-1`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate2
}],
authentication: [{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`
}, {
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#delegate-1`
}]
publicKey: [
{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner,
},
{
id: `${did}#delegate-1`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate2,
},
],
authentication: [
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`,
},
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#delegate-1`,
},
],
})

@@ -192,3 +270,8 @@ })

beforeAll(async () => {
await registry.revokeDelegate(identity, Secp256k1SignatureAuthentication2018, delegate2, {from: owner})
await registry.revokeDelegate(
identity,
Secp256k1SignatureAuthentication2018,
delegate2,
{ from: owner }
)
await sleep(1)

@@ -201,12 +284,16 @@ })

id: did,
publicKey: [{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner
}],
authentication: [{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`
}]
publicKey: [
{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner,
},
],
authentication: [
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`,
},
],
})

@@ -219,3 +306,9 @@ })

await sleep(3)
await registry.addDelegate(identity, Secp256k1SignatureAuthentication2018, delegate2, 86400, {from: owner})
await registry.addDelegate(
identity,
Secp256k1SignatureAuthentication2018,
delegate2,
86400,
{ from: owner }
)
})

@@ -227,20 +320,26 @@

id: did,
publicKey: [{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner
}, {
id: `${did}#delegate-1`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate2
}],
authentication: [{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`
}, {
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#delegate-1`
}]
publicKey: [
{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner,
},
{
id: `${did}#delegate-1`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate2,
},
],
authentication: [
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`,
},
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#delegate-1`,
},
],
})

@@ -252,6 +351,12 @@ })

describe('attributes', () => {
describe('publicKey', () => {
describe('add publicKey', () => {
describe('Secp256k1VerificationKey2018', () => {
beforeAll(async () => {
await registry.setAttribute(identity, stringToBytes32('did/pub/Secp256k1/veriKey'), '0x02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71', 10, {from: owner})
await registry.setAttribute(
identity,
stringToBytes32('did/pub/Secp256k1/veriKey'),
'0x02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71',
10,
{ from: owner }
)
})

@@ -262,25 +367,33 @@ it('resolves document', () => {

id: did,
publicKey: [{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner
}, {
id: `${did}#delegate-1`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate2
}, {
id: `${did}#delegate-2`,
type: 'Secp256k1VerificationKey2018',
owner: did,
publicKeyHex: '02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71'
}],
authentication: [{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`
}, {
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#delegate-1`
}]
publicKey: [
{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner,
},
{
id: `${did}#delegate-1`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate2,
},
{
id: `${did}#delegate-2`,
type: 'Secp256k1VerificationKey2018',
owner: did,
publicKeyHex:
'02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71',
},
],
authentication: [
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`,
},
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#delegate-1`,
},
],
})

@@ -292,5 +405,11 @@ })

beforeAll(async () => {
await registry.setAttribute(identity, stringToBytes32('did/pub/Ed25519/veriKey/base64'), '0x02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71', 10, {from: owner})
await registry.setAttribute(
identity,
stringToBytes32('did/pub/Ed25519/veriKey/base64'),
'0x02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71',
10,
{ from: owner }
)
})
it('resolves document', () => {

@@ -300,30 +419,42 @@ return expect(resolve(did)).resolves.toEqual({

id: did,
publicKey: [{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner
}, {
id: `${did}#delegate-1`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate2
}, {
id: `${did}#delegate-2`,
type: 'Secp256k1VerificationKey2018',
owner: did,
publicKeyHex: '02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71'
}, {
id: `${did}#delegate-3`,
type: 'Ed25519VerificationKey2018',
owner: did,
publicKeyBase64: Buffer.from('02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71', 'hex').toString('base64')
}],
authentication: [{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`
}, {
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#delegate-1`
}]
publicKey: [
{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner,
},
{
id: `${did}#delegate-1`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate2,
},
{
id: `${did}#delegate-2`,
type: 'Secp256k1VerificationKey2018',
owner: did,
publicKeyHex:
'02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71',
},
{
id: `${did}#delegate-3`,
type: 'Ed25519VerificationKey2018',
owner: did,
publicKeyBase64: Buffer.from(
'02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71',
'hex'
).toString('base64'),
},
],
authentication: [
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`,
},
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#delegate-1`,
},
],
})

@@ -334,6 +465,12 @@ })

describe('service endpoints', () => {
describe('add service endpoints', () => {
describe('HubService', () => {
beforeAll(async () => {
await registry.setAttribute(identity, stringToBytes32('did/svc/HubService'), 'https://hubs.uport.me', 10, {from: owner})
await registry.setAttribute(
identity,
stringToBytes32('did/svc/HubService'),
'https://hubs.uport.me',
10,
{ from: owner }
)
})

@@ -344,46 +481,277 @@ it('resolves document', () => {

id: did,
publicKey: [{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner
}, {
id: `${did}#delegate-1`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate2
}, {
id: `${did}#delegate-2`,
type: 'Secp256k1VerificationKey2018',
owner: did,
publicKeyHex: '02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71'
}, {
id: `${did}#delegate-3`,
type: 'Ed25519VerificationKey2018',
owner: did,
publicKeyBase64: Buffer.from('02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71', 'hex').toString('base64')
}],
authentication: [{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`
}, {
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#delegate-1`
}],
service: [{
type: 'HubService',
serviceEndpoint: 'https://hubs.uport.me'
}]
publicKey: [
{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner,
},
{
id: `${did}#delegate-1`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate2,
},
{
id: `${did}#delegate-2`,
type: 'Secp256k1VerificationKey2018',
owner: did,
publicKeyHex:
'02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71',
},
{
id: `${did}#delegate-3`,
type: 'Ed25519VerificationKey2018',
owner: did,
publicKeyBase64: Buffer.from(
'02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71',
'hex'
).toString('base64'),
},
],
authentication: [
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`,
},
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#delegate-1`,
},
],
service: [
{
type: 'HubService',
serviceEndpoint: 'https://hubs.uport.me',
},
],
})
})
})
})
describe('revoke publicKey', () => {
describe('Secp256k1VerificationKey2018', () => {
beforeAll(async () => {
await registry.revokeAttribute(
identity,
stringToBytes32('did/pub/Secp256k1/veriKey'),
'0x02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71',
{ from: owner }
)
sleep(1)
})
it('resolves document', () => {
return expect(resolve(did)).resolves.toEqual({
'@context': 'https://w3id.org/did/v1',
id: did,
publicKey: [
{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner,
},
{
id: `${did}#delegate-1`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate2,
},
{
id: `${did}#delegate-3`,
type: 'Ed25519VerificationKey2018',
owner: did,
publicKeyBase64: Buffer.from(
'02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71',
'hex'
).toString('base64'),
},
],
authentication: [
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`,
},
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#delegate-1`,
},
],
service: [
{
type: 'HubService',
serviceEndpoint: 'https://hubs.uport.me',
},
],
})
})
})
describe('Ed25519VerificationKey2018', () => {
beforeAll(async () => {
await registry.revokeAttribute(
identity,
stringToBytes32('did/pub/Ed25519/veriKey/base64'),
'0x02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71',
{ from: owner }
)
sleep(1)
})
it('resolves document', () => {
return expect(resolve(did)).resolves.toEqual({
'@context': 'https://w3id.org/did/v1',
id: did,
publicKey: [
{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner,
},
{
id: `${did}#delegate-1`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate2,
},
],
authentication: [
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`,
},
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#delegate-1`,
},
],
service: [
{
type: 'HubService',
serviceEndpoint: 'https://hubs.uport.me',
},
],
})
})
})
})
describe('revoke service endpoints', () => {
describe('HubService', () => {
beforeAll(async () => {
await registry.revokeAttribute(
identity,
stringToBytes32('did/svc/HubService'),
'https://hubs.uport.me',
{ from: owner }
)
sleep(1)
})
it('resolves document', () => {
return expect(resolve(did)).resolves.toEqual({
'@context': 'https://w3id.org/did/v1',
id: did,
publicKey: [
{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner,
},
{
id: `${did}#delegate-1`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate2,
},
],
authentication: [
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`,
},
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#delegate-1`,
},
],
})
})
})
})
})
describe('multiple events in one block', () => {
beforeAll(async () => {
await stopMining()
await Promise.all([
registry.setAttribute(
identity,
stringToBytes32('did/svc/TestService'),
'https://test.uport.me',
10,
{ from: owner }
),
registry.setAttribute(
identity,
stringToBytes32('did/svc/TestService'),
'https://test.uport.me',
10,
{ from: owner }
),
sleep(1).then(() => startMining()),
])
})
it('resolves document', async () => {
expect(await resolve(did)).toEqual({
'@context': 'https://w3id.org/did/v1',
id: did,
publicKey: [
{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner,
},
{
id: `${did}#delegate-1`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: delegate2,
},
],
authentication: [
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`,
},
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#delegate-1`,
},
],
service: [
{
type: 'TestService',
serviceEndpoint: 'https://test.uport.me',
},
],
})
})
})
describe('error handling', () => {
it('rejects promise', () => {
return expect(resolve('did:ethr:2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqX')).rejects.toEqual(new Error('Not a valid ethr DID: did:ethr:2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqX'))
return expect(
resolve('did:ethr:2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqX')
).rejects.toEqual(
new Error(
'Not a valid ethr DID: did:ethr:2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqX'
)
)
})
})
})

@@ -11,8 +11,14 @@ import { registerMethod } from 'did-resolver'

export function bytes32toString (bytes32) {
return Buffer.from(bytes32.slice(2), 'hex').toString('utf8').replace(/\0+$/, '')
export function bytes32toString(bytes32) {
return Buffer.from(bytes32.slice(2), 'hex')
.toString('utf8')
.replace(/\0+$/, '')
}
export function stringToBytes32 (str) {
const buffstr = '0x' + Buffer.from(str).slice(0, 32).toString('hex')
export function stringToBytes32(str) {
const buffstr =
'0x' +
Buffer.from(str)
.slice(0, 32)
.toString('hex')
return buffstr + '0'.repeat(66 - buffstr.length)

@@ -23,3 +29,3 @@ }

Secp256k1SignatureAuthentication2018: stringToBytes32('sigAuth'),
Secp256k1VerificationKey2018: stringToBytes32('veriKey')
Secp256k1VerificationKey2018: stringToBytes32('veriKey'),
}

@@ -29,19 +35,23 @@

sigAuth: 'SignatureAuthentication2018',
veriKey: 'VerificationKey2018'
veriKey: 'VerificationKey2018',
}
export function wrapDidDocument (did, owner, history) {
export function wrapDidDocument(did, owner, history) {
const now = new BN(Math.floor(new Date().getTime() / 1000))
// const expired = {}
const publicKey = [{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner
}]
const publicKey = [
{
id: `${did}#owner`,
type: 'Secp256k1VerificationKey2018',
owner: did,
ethereumAddress: owner,
},
]
const authentication = [{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`
}]
const authentication = [
{
type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#owner`,
},
]

@@ -54,3 +64,4 @@ let delegateCount = 0

let validTo = event.validTo
const key = `${event._eventName}-${event.delegateType || event.name}-${event.delegate || event.value}`
const key = `${event._eventName}-${event.delegateType ||
event.name}-${event.delegate || event.value}`
if (validTo && validTo.gte(now)) {

@@ -64,3 +75,3 @@ if (event._eventName === 'DIDDelegateChanged') {

type: 'Secp256k1SignatureAuthentication2018',
publicKey: `${did}#delegate-${delegateCount}`
publicKey: `${did}#delegate-${delegateCount}`,
}

@@ -72,3 +83,3 @@ case 'veriKey':

owner: did,
ethereumAddress: event.delegate
ethereumAddress: event.delegate,
}

@@ -79,3 +90,5 @@ break

const name = bytes32toString(event.name)
const match = name.match(/^did\/(pub|auth|svc)\/(\w+)(\/(\w+))?(\/(\w+))?$/)
const match = name.match(
/^did\/(pub|auth|svc)\/(\w+)(\/(\w+))?(\/(\w+))?$/
)
if (match) {

@@ -92,3 +105,3 @@ const section = match[1]

type: `${algo}${type}`,
owner: did
owner: did,
}

@@ -102,6 +115,12 @@ switch (encoding) {

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

@@ -114,3 +133,9 @@ default:

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

@@ -121,3 +146,10 @@ }

} else {
if (delegateCount > 0 && (event._eventName === 'DIDDelegateChanged' || (event._eventName === 'DIDAttributeChanged' && delegateType.match(/^did\/publicKey\//))) && validTo.lt(now)) delegateCount--
if (
delegateCount > 0 &&
(event._eventName === 'DIDDelegateChanged' ||
(event._eventName === 'DIDAttributeChanged' &&
bytes32toString(event.name).match(/^did\/pub\//))) &&
validTo.lt(now)
)
delegateCount--
delete auth[key]

@@ -133,3 +165,3 @@ delete pks[key]

publicKey: publicKey.concat(Object.values(pks)),
authentication: authentication.concat(Object.values(auth))
authentication: authentication.concat(Object.values(auth)),
}

@@ -143,3 +175,3 @@ if (Object.values(services).length > 0) {

function configureProvider (conf = {}) {
function configureProvider(conf = {}) {
if (conf.provider) {

@@ -154,3 +186,3 @@ return conf.provider

export default function register (conf = {}) {
export default function register(conf = {}) {
const provider = configureProvider(conf)

@@ -163,3 +195,3 @@ const eth = new Eth(provider)

const lastChanged = async (identity) => {
const lastChanged = async identity => {
const result = await didReg.changed(identity)

@@ -170,7 +202,13 @@ if (result) {

}
async function changeLog (identity) {
async function changeLog(identity) {
const history = []
let previousChange = await lastChanged(identity)
while (previousChange) {
const logs = await eth.getLogs({address: registryAddress, topics: [null, `0x000000000000000000000000${identity.slice(2)}`], fromBlock: previousChange, toBlock: previousChange})
const blockNumber = previousChange
const logs = await eth.getLogs({
address: registryAddress,
topics: [null, `0x000000000000000000000000${identity.slice(2)}`],
fromBlock: previousChange,
toBlock: previousChange,
})
const events = logDecoder(logs)

@@ -180,3 +218,5 @@ previousChange = undefined

history.unshift(event)
previousChange = event.previousChange
if (event.previousChange.lt(blockNumber)) {
previousChange = event.previousChange
}
}

@@ -186,4 +226,5 @@ }

}
async function resolve (did, parsed) {
if (!parsed.id.match(/^0x[0-9a-fA-F]{40}$/)) throw new Error(`Not a valid ethr DID: ${did}`)
async function resolve(did, parsed) {
if (!parsed.id.match(/^0x[0-9a-fA-F]{40}$/))
throw new Error(`Not a valid ethr DID: ${did}`)
const owner = await didReg.identityOwner(parsed.id)

@@ -190,0 +231,0 @@ const history = await changeLog(parsed.id)

Sorry, the diff of this file is too big to display

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