did-resolver
Advanced tools
Comparing version 0.0.2 to 0.0.3
'use strict'; | ||
var _regenerator = require('babel-runtime/regenerator'); | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); | ||
var _resolver = require('../resolver'); | ||
@@ -9,4 +17,2 @@ | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
describe('resolver', function () { | ||
@@ -47,15 +53,32 @@ describe('parse()', function () { | ||
describe('resolve', function () { | ||
(0, _resolver.registerMethod)('example', function (did, parsed) { | ||
return { | ||
'@context': 'https://w3id.org/did/v1', | ||
id: did | ||
(0, _resolver.registerMethod)('example', function () { | ||
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(did, parsed) { | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
return _context.abrupt('return', { | ||
'@context': 'https://w3id.org/did/v1', | ||
id: did | ||
}); | ||
case 1: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, undefined); | ||
})); | ||
return function (_x, _x2) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}); | ||
}()); | ||
it('fails on unhandled methods', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
it('fails on unhandled methods', (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 expect((0, _resolver2.default)('did:borg:2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqX')).rejects.toEqual(new Error('Unsupported DID method: \'borg\'')); | ||
@@ -65,13 +88,13 @@ | ||
case 'end': | ||
return _context.stop(); | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee, undefined); | ||
}, _callee2, undefined); | ||
}))); | ||
it('fails on parse error', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() { | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
it('fails on parse error', (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 expect((0, _resolver2.default)('did:borg:')).rejects.toEqual(new Error('Invalid DID did:borg:')); | ||
@@ -81,14 +104,14 @@ | ||
case 'end': | ||
return _context2.stop(); | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee2, undefined); | ||
}, _callee3, undefined); | ||
}))); | ||
it('resolves did document', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() { | ||
return regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
it('resolves did document', (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 expect((0, _resolver2.default)('did:example:123456789')).resolves.toEqual({ | ||
@@ -101,8 +124,8 @@ '@context': 'https://w3id.org/did/v1', | ||
case 'end': | ||
return _context3.stop(); | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _callee3, undefined); | ||
}, _callee4, undefined); | ||
}))); | ||
}); | ||
}); |
@@ -7,39 +7,11 @@ 'use strict'; | ||
var resolve = exports.resolve = function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(did) { | ||
var parsed, resolver; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
parsed = parse(did); | ||
resolver = REGISTRY[parsed.method]; | ||
var _promise = require('babel-runtime/core-js/promise'); | ||
if (!resolver) { | ||
_context.next = 4; | ||
break; | ||
} | ||
var _promise2 = _interopRequireDefault(_promise); | ||
return _context.abrupt('return', resolver(did, parsed)); | ||
case 4: | ||
throw new Error('Unsupported DID method: \'' + parsed.method + '\''); | ||
case 5: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
return function resolve(_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
exports.registerMethod = registerMethod; | ||
exports.parse = parse; | ||
exports.resolve = resolve; | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -64,2 +36,17 @@ var REGISTRY = {}; | ||
exports.default = resolve; | ||
function resolve(did) { | ||
return new _promise2.default(function (resolve, reject) { | ||
var parsed = parse(did); | ||
var resolver = REGISTRY[parsed.method]; | ||
if (resolver) { | ||
return resolver(did, parsed).then(resolve); | ||
} | ||
reject(new Error('Unsupported DID method: \'' + parsed.method + '\'')); | ||
}); | ||
} | ||
exports.default = resolve; | ||
resolve.registerMethod = registerMethod; | ||
resolve.parse = parse; | ||
module.exports = resolve; |
{ | ||
"name": "did-resolver", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Resolve DID documents", | ||
@@ -5,0 +5,0 @@ "main": "lib/resolver.js", |
@@ -24,3 +24,3 @@ import resolve, {parse, registerMethod} from '../resolver' | ||
describe('resolve', () => { | ||
registerMethod('example', (did, parsed) => ({ | ||
registerMethod('example', async (did, parsed) => ({ | ||
'@context': 'https://w3id.org/did/v1', | ||
@@ -27,0 +27,0 @@ id: did |
@@ -20,11 +20,16 @@ | ||
export async function resolve (did) { | ||
const parsed = parse(did) | ||
const resolver = REGISTRY[parsed.method] | ||
if (resolver) { | ||
return resolver(did, parsed) | ||
} | ||
throw new Error(`Unsupported DID method: '${parsed.method}'`) | ||
export function resolve (did) { | ||
return new Promise((resolve, reject) => { | ||
const parsed = parse(did) | ||
const resolver = REGISTRY[parsed.method] | ||
if (resolver) { | ||
return resolver(did, parsed).then(resolve) | ||
} | ||
reject(new Error(`Unsupported DID method: '${parsed.method}'`)) | ||
}) | ||
} | ||
export default resolve | ||
resolve.registerMethod = registerMethod | ||
resolve.parse = parse | ||
module.exports = resolve |
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
215
14364