did-resolver
Advanced tools
Comparing version 0.0.5 to 0.0.6-alpha1
@@ -24,2 +24,3 @@ 'use strict'; | ||
expect((0, _resolver.parse)('did:uport:2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqX/some/path#fragment=123')).toEqual({ method: 'uport', id: '2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqX', did: 'did:uport:2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqX/some/path#fragment=123', path: '/some/path', fragment: 'fragment=123' }); | ||
expect((0, _resolver.parse)('did:nacl:Md8JiMIwsapml_FtQ2ngnGftNP5UmVCAUuhnLyAsPxI')).toEqual({ method: 'nacl', id: 'Md8JiMIwsapml_FtQ2ngnGftNP5UmVCAUuhnLyAsPxI', did: 'did:nacl:Md8JiMIwsapml_FtQ2ngnGftNP5UmVCAUuhnLyAsPxI' }); | ||
}); | ||
@@ -26,0 +27,0 @@ |
@@ -1,50 +0,75 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _promise = require('babel-runtime/core-js/promise'); | ||
var _promise2 = _interopRequireDefault(_promise); | ||
exports.registerMethod = registerMethod; | ||
exports.parse = parse; | ||
exports.resolve = resolve; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var REGISTRY = {}; | ||
function registerMethod(method, resolver) { | ||
REGISTRY[method] = resolver; | ||
REGISTRY[method] = resolver; | ||
} | ||
exports.registerMethod = registerMethod; | ||
function parse(did) { | ||
if (!did || did === '') throw new Error('Missing DID'); | ||
var sections = did.match(/^did:([a-zA-Z0-9]+):([[a-zA-Z0-9.-]+)(\/[^#]*)?(#.*)?$/); | ||
if (sections) { | ||
var parts = { did: sections[0], method: sections[1], id: sections[2] }; | ||
if (sections[3]) parts.path = sections[3]; | ||
if (sections[4]) parts.fragment = sections[4].slice(1); | ||
return parts; | ||
} | ||
throw new Error('Invalid DID ' + did); | ||
if (!did || did === '') | ||
throw new Error('Missing DID'); | ||
var sections = did.match(/^did:([a-zA-Z0-9_]+):([[a-zA-Z0-9_.-]+)(\/[^#]*)?(#.*)?$/); | ||
if (sections) { | ||
var parts = { did: sections[0], method: sections[1], id: sections[2] }; | ||
if (sections[3]) | ||
parts.path = sections[3]; | ||
if (sections[4]) | ||
parts.fragment = sections[4].slice(1); | ||
return parts; | ||
} | ||
throw new Error("Invalid DID " + did); | ||
} | ||
exports.parse = parse; | ||
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); | ||
} | ||
reject(new Error('Unsupported DID method: \'' + parsed.method + '\'')); | ||
}); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var parsed, resolver; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
parsed = parse(did); | ||
resolver = REGISTRY[parsed.method]; | ||
if (!resolver) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, resolver(did, parsed)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
case 2: throw new Error("Unsupported DID method: '" + parsed.method + "'"); | ||
} | ||
}); | ||
}); | ||
} | ||
exports.default = resolve; | ||
resolve.registerMethod = registerMethod; | ||
resolve.parse = parse; | ||
module.exports = resolve; | ||
//# sourceMappingURL=resolver.js.map |
{ | ||
"name": "did-resolver", | ||
"version": "0.0.5", | ||
"version": "0.0.6-alpha1", | ||
"description": "Resolve DID documents", | ||
"main": "lib/resolver.js", | ||
"types": "lib/resolver.d.ts", | ||
"repository": { | ||
@@ -18,40 +19,37 @@ "type": "git", | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "jest", | ||
"build:es5": "./node_modules/.bin/babel src -d lib", | ||
"build": "yarn build:es5 && yarn test" | ||
"dev": "tsc --watch", | ||
"format": "prettier" | ||
}, | ||
"jest": { | ||
"coverageDirectory": "./coverage/", | ||
"collectCoverage": true | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-core": "^6.26.0", | ||
"babel-jest": "^22.4.0", | ||
"babel-plugin-transform-es2015-modules-umd": "^6.24.1", | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"babel-preset-env": "^1.6.0", | ||
"jest": "^22.4.0", | ||
"regenerator-runtime": "^0.11.1", | ||
"sinon": "^4.0.1", | ||
"standard": "^11.0.0" | ||
"@types/jest": "^23.3.10", | ||
"jest": "^23.6.0", | ||
"prettier": "^1.15.3", | ||
"regenerator-runtime": "^0.12.1", | ||
"ts-jest": "^23.10.5", | ||
"tslint": "^5.12.0", | ||
"tslint-config-prettier": "^1.17.0", | ||
"tslint-eslint-rules": "^5.4.0", | ||
"typescript": "^3.2.2" | ||
}, | ||
"dependencies": { | ||
"babel-runtime": "^6.26.0" | ||
}, | ||
"standard": { | ||
"ignore": [ | ||
"lib/**" | ||
"jest": { | ||
"transform": { | ||
"^.+\\.tsx?$": "ts-jest" | ||
}, | ||
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", | ||
"moduleFileExtensions": [ | ||
"ts", | ||
"tsx", | ||
"js", | ||
"jsx", | ||
"json" | ||
], | ||
"globals": [ | ||
"it", | ||
"describe", | ||
"expect", | ||
"jest", | ||
"beforeAll", | ||
"beforeEach", | ||
"afterAll", | ||
"afterEach" | ||
"coverageDirectory": "./coverage/", | ||
"collectCoverageFrom": [ | ||
"src/**/*.{ts,tsx}", | ||
"!src/**/*.d.ts", | ||
"!**/node_modules/**" | ||
] | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
19764
0
9
9
306
1
- Removedbabel-runtime@^6.26.0
- Removedbabel-runtime@6.26.0(transitive)
- Removedcore-js@2.6.12(transitive)
- Removedregenerator-runtime@0.11.1(transitive)