uuid 3.4.0 → 8.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +154 -44
- package/CONTRIBUTING.md +18 -0
- package/LICENSE.md +4 -16
- package/README.md +384 -155
- package/dist/bin/uuid +2 -0
- package/dist/esm-browser/index.js +9 -0
- package/{lib/md5-browser.js → dist/esm-browser/md5.js} +70 -71
- package/dist/esm-browser/nil.js +1 -0
- package/dist/esm-browser/parse.js +35 -0
- package/dist/esm-browser/regex.js +1 -0
- package/dist/esm-browser/rng.js +19 -0
- package/dist/esm-browser/sha1.js +96 -0
- package/dist/esm-browser/stringify.js +30 -0
- package/{v1.js → dist/esm-browser/v1.js} +36 -50
- package/dist/esm-browser/v3.js +4 -0
- package/dist/esm-browser/v35.js +64 -0
- package/dist/esm-browser/v4.js +24 -0
- package/dist/esm-browser/v5.js +4 -0
- package/dist/esm-browser/validate.js +7 -0
- package/dist/esm-browser/version.js +11 -0
- package/dist/esm-node/index.js +9 -0
- package/dist/esm-node/md5.js +13 -0
- package/dist/esm-node/nil.js +1 -0
- package/dist/esm-node/parse.js +35 -0
- package/dist/esm-node/regex.js +1 -0
- package/dist/esm-node/rng.js +12 -0
- package/dist/esm-node/sha1.js +13 -0
- package/dist/esm-node/stringify.js +29 -0
- package/dist/esm-node/v1.js +95 -0
- package/dist/esm-node/v3.js +4 -0
- package/dist/esm-node/v35.js +64 -0
- package/dist/esm-node/v4.js +24 -0
- package/dist/esm-node/v5.js +4 -0
- package/dist/esm-node/validate.js +7 -0
- package/dist/esm-node/version.js +11 -0
- package/dist/index.js +79 -0
- package/dist/md5-browser.js +223 -0
- package/dist/md5.js +23 -0
- package/dist/nil.js +8 -0
- package/dist/parse.js +45 -0
- package/dist/regex.js +8 -0
- package/dist/rng-browser.js +26 -0
- package/dist/rng.js +24 -0
- package/dist/sha1-browser.js +104 -0
- package/dist/sha1.js +23 -0
- package/dist/stringify.js +39 -0
- package/dist/umd/uuid.min.js +1 -0
- package/dist/umd/uuidNIL.min.js +1 -0
- package/dist/umd/uuidParse.min.js +1 -0
- package/dist/umd/uuidStringify.min.js +1 -0
- package/dist/umd/uuidValidate.min.js +1 -0
- package/dist/umd/uuidVersion.min.js +1 -0
- package/dist/umd/uuidv1.min.js +1 -0
- package/dist/umd/uuidv3.min.js +1 -0
- package/dist/umd/uuidv4.min.js +1 -0
- package/dist/umd/uuidv5.min.js +1 -0
- package/dist/uuid-bin.js +85 -0
- package/dist/v1.js +107 -0
- package/dist/v3.js +16 -0
- package/dist/v35.js +78 -0
- package/dist/v4.js +37 -0
- package/dist/v5.js +16 -0
- package/dist/validate.js +17 -0
- package/dist/version.js +21 -0
- package/package.json +105 -19
- package/wrapper.mjs +10 -0
- package/AUTHORS +0 -5
- package/bin/uuid +0 -65
- package/index.js +0 -8
- package/lib/bytesToUuid.js +0 -26
- package/lib/md5.js +0 -25
- package/lib/rng-browser.js +0 -34
- package/lib/rng.js +0 -8
- package/lib/sha1-browser.js +0 -89
- package/lib/sha1.js +0 -25
- package/lib/v35.js +0 -57
- package/v3.js +0 -4
- package/v4.js +0 -29
- package/v5.js +0 -3
package/dist/v4.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _rng = _interopRequireDefault(require("./rng.js"));
|
|
9
|
+
|
|
10
|
+
var _stringify = _interopRequireDefault(require("./stringify.js"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
function v4(options, buf, offset) {
|
|
15
|
+
options = options || {};
|
|
16
|
+
|
|
17
|
+
const rnds = options.random || (options.rng || _rng.default)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
rnds[6] = rnds[6] & 0x0f | 0x40;
|
|
21
|
+
rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
|
|
22
|
+
|
|
23
|
+
if (buf) {
|
|
24
|
+
offset = offset || 0;
|
|
25
|
+
|
|
26
|
+
for (let i = 0; i < 16; ++i) {
|
|
27
|
+
buf[offset + i] = rnds[i];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return buf;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return (0, _stringify.default)(rnds);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var _default = v4;
|
|
37
|
+
exports.default = _default;
|
package/dist/v5.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _v = _interopRequireDefault(require("./v35.js"));
|
|
9
|
+
|
|
10
|
+
var _sha = _interopRequireDefault(require("./sha1.js"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
const v5 = (0, _v.default)('v5', 0x50, _sha.default);
|
|
15
|
+
var _default = v5;
|
|
16
|
+
exports.default = _default;
|
package/dist/validate.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _regex = _interopRequireDefault(require("./regex.js"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
function validate(uuid) {
|
|
13
|
+
return typeof uuid === 'string' && _regex.default.test(uuid);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
var _default = validate;
|
|
17
|
+
exports.default = _default;
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _validate = _interopRequireDefault(require("./validate.js"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
function version(uuid) {
|
|
13
|
+
if (!(0, _validate.default)(uuid)) {
|
|
14
|
+
throw TypeError('Invalid UUID');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return parseInt(uuid.substr(14, 1), 16);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
var _default = version;
|
|
21
|
+
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uuid",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "8.3.2",
|
|
4
4
|
"description": "RFC4122 (v1, v4, and v5) UUIDs",
|
|
5
5
|
"commitlint": {
|
|
6
6
|
"extends": [
|
|
@@ -14,28 +14,100 @@
|
|
|
14
14
|
],
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"bin": {
|
|
17
|
-
"uuid": "./bin/uuid"
|
|
17
|
+
"uuid": "./dist/bin/uuid"
|
|
18
18
|
},
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"node": {
|
|
24
|
+
"module": "./dist/esm-node/index.js",
|
|
25
|
+
"require": "./dist/index.js",
|
|
26
|
+
"import": "./wrapper.mjs"
|
|
27
|
+
},
|
|
28
|
+
"default": "./dist/esm-browser/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"module": "./dist/esm-node/index.js",
|
|
33
|
+
"browser": {
|
|
34
|
+
"./dist/md5.js": "./dist/md5-browser.js",
|
|
35
|
+
"./dist/rng.js": "./dist/rng-browser.js",
|
|
36
|
+
"./dist/sha1.js": "./dist/sha1-browser.js",
|
|
37
|
+
"./dist/esm-node/index.js": "./dist/esm-browser/index.js"
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"CHANGELOG.md",
|
|
41
|
+
"CONTRIBUTING.md",
|
|
42
|
+
"LICENSE.md",
|
|
43
|
+
"README.md",
|
|
44
|
+
"dist",
|
|
45
|
+
"wrapper.mjs"
|
|
46
|
+
],
|
|
19
47
|
"devDependencies": {
|
|
20
|
-
"@
|
|
21
|
-
"@
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
48
|
+
"@babel/cli": "7.11.6",
|
|
49
|
+
"@babel/core": "7.11.6",
|
|
50
|
+
"@babel/preset-env": "7.11.5",
|
|
51
|
+
"@commitlint/cli": "11.0.0",
|
|
52
|
+
"@commitlint/config-conventional": "11.0.0",
|
|
53
|
+
"@rollup/plugin-node-resolve": "9.0.0",
|
|
54
|
+
"babel-eslint": "10.1.0",
|
|
55
|
+
"bundlewatch": "0.3.1",
|
|
56
|
+
"eslint": "7.10.0",
|
|
57
|
+
"eslint-config-prettier": "6.12.0",
|
|
58
|
+
"eslint-config-standard": "14.1.1",
|
|
59
|
+
"eslint-plugin-import": "2.22.1",
|
|
60
|
+
"eslint-plugin-node": "11.1.0",
|
|
61
|
+
"eslint-plugin-prettier": "3.1.4",
|
|
62
|
+
"eslint-plugin-promise": "4.2.1",
|
|
63
|
+
"eslint-plugin-standard": "4.0.1",
|
|
64
|
+
"husky": "4.3.0",
|
|
65
|
+
"jest": "25.5.4",
|
|
66
|
+
"lint-staged": "10.4.0",
|
|
67
|
+
"npm-run-all": "4.1.5",
|
|
68
|
+
"optional-dev-dependency": "2.0.1",
|
|
69
|
+
"prettier": "2.1.2",
|
|
70
|
+
"random-seed": "0.3.0",
|
|
71
|
+
"rollup": "2.28.2",
|
|
72
|
+
"rollup-plugin-terser": "7.0.2",
|
|
73
|
+
"runmd": "1.3.2",
|
|
74
|
+
"standard-version": "9.0.0"
|
|
75
|
+
},
|
|
76
|
+
"optionalDevDependencies": {
|
|
77
|
+
"@wdio/browserstack-service": "6.4.0",
|
|
78
|
+
"@wdio/cli": "6.4.0",
|
|
79
|
+
"@wdio/jasmine-framework": "6.4.0",
|
|
80
|
+
"@wdio/local-runner": "6.4.0",
|
|
81
|
+
"@wdio/spec-reporter": "6.4.0",
|
|
82
|
+
"@wdio/static-server-service": "6.4.0",
|
|
83
|
+
"@wdio/sync": "6.4.0"
|
|
27
84
|
},
|
|
28
85
|
"scripts": {
|
|
29
|
-
"
|
|
30
|
-
"
|
|
86
|
+
"examples:browser:webpack:build": "cd examples/browser-webpack && npm install && npm run build",
|
|
87
|
+
"examples:browser:rollup:build": "cd examples/browser-rollup && npm install && npm run build",
|
|
88
|
+
"examples:node:commonjs:test": "cd examples/node-commonjs && npm install && npm test",
|
|
89
|
+
"examples:node:esmodules:test": "cd examples/node-esmodules && npm install && npm test",
|
|
90
|
+
"lint": "npm run eslint:check && npm run prettier:check",
|
|
91
|
+
"eslint:check": "eslint src/ test/ examples/ *.js",
|
|
92
|
+
"eslint:fix": "eslint --fix src/ test/ examples/ *.js",
|
|
93
|
+
"pretest": "[ -n $CI ] || npm run build",
|
|
94
|
+
"test": "BABEL_ENV=commonjs node --throw-deprecation node_modules/.bin/jest test/unit/",
|
|
95
|
+
"pretest:browser": "optional-dev-dependency && npm run build && npm-run-all --parallel examples:browser:**",
|
|
96
|
+
"test:browser": "wdio run ./wdio.conf.js",
|
|
97
|
+
"pretest:node": "npm run build",
|
|
98
|
+
"test:node": "npm-run-all --parallel examples:node:**",
|
|
99
|
+
"test:pack": "./scripts/testpack.sh",
|
|
100
|
+
"pretest:benchmark": "npm run build",
|
|
101
|
+
"test:benchmark": "cd examples/benchmark && npm install && npm test",
|
|
102
|
+
"prettier:check": "prettier --ignore-path .prettierignore --check '**/*.{js,jsx,json,md}'",
|
|
103
|
+
"prettier:fix": "prettier --ignore-path .prettierignore --write '**/*.{js,jsx,json,md}'",
|
|
104
|
+
"bundlewatch": "npm run pretest:browser && bundlewatch --config bundlewatch.config.json",
|
|
31
105
|
"md": "runmd --watch --output=README.md README_js.md",
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
"./lib/sha1.js": "./lib/sha1-browser.js",
|
|
38
|
-
"./lib/md5.js": "./lib/md5-browser.js"
|
|
106
|
+
"docs": "( node --version | grep -q 'v12' ) && ( npm run build && runmd --output=README.md README_js.md )",
|
|
107
|
+
"docs:diff": "npm run docs && git diff --quiet README.md",
|
|
108
|
+
"build": "./scripts/build.sh",
|
|
109
|
+
"prepack": "npm run build",
|
|
110
|
+
"release": "standard-version --no-verify"
|
|
39
111
|
},
|
|
40
112
|
"repository": {
|
|
41
113
|
"type": "git",
|
|
@@ -43,7 +115,21 @@
|
|
|
43
115
|
},
|
|
44
116
|
"husky": {
|
|
45
117
|
"hooks": {
|
|
46
|
-
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
|
118
|
+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
|
|
119
|
+
"pre-commit": "lint-staged"
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
"lint-staged": {
|
|
123
|
+
"*.{js,jsx,json,md}": [
|
|
124
|
+
"prettier --write"
|
|
125
|
+
],
|
|
126
|
+
"*.{js,jsx}": [
|
|
127
|
+
"eslint --fix"
|
|
128
|
+
]
|
|
129
|
+
},
|
|
130
|
+
"standard-version": {
|
|
131
|
+
"scripts": {
|
|
132
|
+
"postchangelog": "prettier --write CHANGELOG.md"
|
|
47
133
|
}
|
|
48
134
|
}
|
|
49
135
|
}
|
package/wrapper.mjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import uuid from './dist/index.js';
|
|
2
|
+
export const v1 = uuid.v1;
|
|
3
|
+
export const v3 = uuid.v3;
|
|
4
|
+
export const v4 = uuid.v4;
|
|
5
|
+
export const v5 = uuid.v5;
|
|
6
|
+
export const NIL = uuid.NIL;
|
|
7
|
+
export const version = uuid.version;
|
|
8
|
+
export const validate = uuid.validate;
|
|
9
|
+
export const stringify = uuid.stringify;
|
|
10
|
+
export const parse = uuid.parse;
|
package/AUTHORS
DELETED
package/bin/uuid
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
var assert = require('assert');
|
|
3
|
-
|
|
4
|
-
function usage() {
|
|
5
|
-
console.log('Usage:');
|
|
6
|
-
console.log(' uuid');
|
|
7
|
-
console.log(' uuid v1');
|
|
8
|
-
console.log(' uuid v3 <name> <namespace uuid>');
|
|
9
|
-
console.log(' uuid v4');
|
|
10
|
-
console.log(' uuid v5 <name> <namespace uuid>');
|
|
11
|
-
console.log(' uuid --help');
|
|
12
|
-
console.log('\nNote: <namespace uuid> may be "URL" or "DNS" to use the corresponding UUIDs defined by RFC4122');
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
var args = process.argv.slice(2);
|
|
16
|
-
|
|
17
|
-
if (args.indexOf('--help') >= 0) {
|
|
18
|
-
usage();
|
|
19
|
-
process.exit(0);
|
|
20
|
-
}
|
|
21
|
-
var version = args.shift() || 'v4';
|
|
22
|
-
|
|
23
|
-
switch (version) {
|
|
24
|
-
case 'v1':
|
|
25
|
-
var uuidV1 = require('../v1');
|
|
26
|
-
console.log(uuidV1());
|
|
27
|
-
break;
|
|
28
|
-
|
|
29
|
-
case 'v3':
|
|
30
|
-
var uuidV3 = require('../v3');
|
|
31
|
-
|
|
32
|
-
var name = args.shift();
|
|
33
|
-
var namespace = args.shift();
|
|
34
|
-
assert(name != null, 'v3 name not specified');
|
|
35
|
-
assert(namespace != null, 'v3 namespace not specified');
|
|
36
|
-
|
|
37
|
-
if (namespace == 'URL') namespace = uuidV3.URL;
|
|
38
|
-
if (namespace == 'DNS') namespace = uuidV3.DNS;
|
|
39
|
-
|
|
40
|
-
console.log(uuidV3(name, namespace));
|
|
41
|
-
break;
|
|
42
|
-
|
|
43
|
-
case 'v4':
|
|
44
|
-
var uuidV4 = require('../v4');
|
|
45
|
-
console.log(uuidV4());
|
|
46
|
-
break;
|
|
47
|
-
|
|
48
|
-
case 'v5':
|
|
49
|
-
var uuidV5 = require('../v5');
|
|
50
|
-
|
|
51
|
-
var name = args.shift();
|
|
52
|
-
var namespace = args.shift();
|
|
53
|
-
assert(name != null, 'v5 name not specified');
|
|
54
|
-
assert(namespace != null, 'v5 namespace not specified');
|
|
55
|
-
|
|
56
|
-
if (namespace == 'URL') namespace = uuidV5.URL;
|
|
57
|
-
if (namespace == 'DNS') namespace = uuidV5.DNS;
|
|
58
|
-
|
|
59
|
-
console.log(uuidV5(name, namespace));
|
|
60
|
-
break;
|
|
61
|
-
|
|
62
|
-
default:
|
|
63
|
-
usage();
|
|
64
|
-
process.exit(1);
|
|
65
|
-
}
|
package/index.js
DELETED
package/lib/bytesToUuid.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Convert array of 16 byte values to UUID string format of the form:
|
|
3
|
-
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
|
4
|
-
*/
|
|
5
|
-
var byteToHex = [];
|
|
6
|
-
for (var i = 0; i < 256; ++i) {
|
|
7
|
-
byteToHex[i] = (i + 0x100).toString(16).substr(1);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function bytesToUuid(buf, offset) {
|
|
11
|
-
var i = offset || 0;
|
|
12
|
-
var bth = byteToHex;
|
|
13
|
-
// join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4
|
|
14
|
-
return ([
|
|
15
|
-
bth[buf[i++]], bth[buf[i++]],
|
|
16
|
-
bth[buf[i++]], bth[buf[i++]], '-',
|
|
17
|
-
bth[buf[i++]], bth[buf[i++]], '-',
|
|
18
|
-
bth[buf[i++]], bth[buf[i++]], '-',
|
|
19
|
-
bth[buf[i++]], bth[buf[i++]], '-',
|
|
20
|
-
bth[buf[i++]], bth[buf[i++]],
|
|
21
|
-
bth[buf[i++]], bth[buf[i++]],
|
|
22
|
-
bth[buf[i++]], bth[buf[i++]]
|
|
23
|
-
]).join('');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
module.exports = bytesToUuid;
|
package/lib/md5.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var crypto = require('crypto');
|
|
4
|
-
|
|
5
|
-
function md5(bytes) {
|
|
6
|
-
if (typeof Buffer.from === 'function') {
|
|
7
|
-
// Modern Buffer API
|
|
8
|
-
if (Array.isArray(bytes)) {
|
|
9
|
-
bytes = Buffer.from(bytes);
|
|
10
|
-
} else if (typeof bytes === 'string') {
|
|
11
|
-
bytes = Buffer.from(bytes, 'utf8');
|
|
12
|
-
}
|
|
13
|
-
} else {
|
|
14
|
-
// Pre-v4 Buffer API
|
|
15
|
-
if (Array.isArray(bytes)) {
|
|
16
|
-
bytes = new Buffer(bytes);
|
|
17
|
-
} else if (typeof bytes === 'string') {
|
|
18
|
-
bytes = new Buffer(bytes, 'utf8');
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return crypto.createHash('md5').update(bytes).digest();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
module.exports = md5;
|
package/lib/rng-browser.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// Unique ID creation requires a high quality random # generator. In the
|
|
2
|
-
// browser this is a little complicated due to unknown quality of Math.random()
|
|
3
|
-
// and inconsistent support for the `crypto` API. We do the best we can via
|
|
4
|
-
// feature-detection
|
|
5
|
-
|
|
6
|
-
// getRandomValues needs to be invoked in a context where "this" is a Crypto
|
|
7
|
-
// implementation. Also, find the complete implementation of crypto on IE11.
|
|
8
|
-
var getRandomValues = (typeof(crypto) != 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto)) ||
|
|
9
|
-
(typeof(msCrypto) != 'undefined' && typeof window.msCrypto.getRandomValues == 'function' && msCrypto.getRandomValues.bind(msCrypto));
|
|
10
|
-
|
|
11
|
-
if (getRandomValues) {
|
|
12
|
-
// WHATWG crypto RNG - http://wiki.whatwg.org/wiki/Crypto
|
|
13
|
-
var rnds8 = new Uint8Array(16); // eslint-disable-line no-undef
|
|
14
|
-
|
|
15
|
-
module.exports = function whatwgRNG() {
|
|
16
|
-
getRandomValues(rnds8);
|
|
17
|
-
return rnds8;
|
|
18
|
-
};
|
|
19
|
-
} else {
|
|
20
|
-
// Math.random()-based (RNG)
|
|
21
|
-
//
|
|
22
|
-
// If all else fails, use Math.random(). It's fast, but is of unspecified
|
|
23
|
-
// quality.
|
|
24
|
-
var rnds = new Array(16);
|
|
25
|
-
|
|
26
|
-
module.exports = function mathRNG() {
|
|
27
|
-
for (var i = 0, r; i < 16; i++) {
|
|
28
|
-
if ((i & 0x03) === 0) r = Math.random() * 0x100000000;
|
|
29
|
-
rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return rnds;
|
|
33
|
-
};
|
|
34
|
-
}
|
package/lib/rng.js
DELETED
package/lib/sha1-browser.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
// Adapted from Chris Veness' SHA1 code at
|
|
2
|
-
// http://www.movable-type.co.uk/scripts/sha1.html
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
function f(s, x, y, z) {
|
|
6
|
-
switch (s) {
|
|
7
|
-
case 0: return (x & y) ^ (~x & z);
|
|
8
|
-
case 1: return x ^ y ^ z;
|
|
9
|
-
case 2: return (x & y) ^ (x & z) ^ (y & z);
|
|
10
|
-
case 3: return x ^ y ^ z;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function ROTL(x, n) {
|
|
15
|
-
return (x << n) | (x>>> (32 - n));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function sha1(bytes) {
|
|
19
|
-
var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
|
|
20
|
-
var H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
|
|
21
|
-
|
|
22
|
-
if (typeof(bytes) == 'string') {
|
|
23
|
-
var msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
|
|
24
|
-
bytes = new Array(msg.length);
|
|
25
|
-
for (var i = 0; i < msg.length; i++) bytes[i] = msg.charCodeAt(i);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
bytes.push(0x80);
|
|
29
|
-
|
|
30
|
-
var l = bytes.length/4 + 2;
|
|
31
|
-
var N = Math.ceil(l/16);
|
|
32
|
-
var M = new Array(N);
|
|
33
|
-
|
|
34
|
-
for (var i=0; i<N; i++) {
|
|
35
|
-
M[i] = new Array(16);
|
|
36
|
-
for (var j=0; j<16; j++) {
|
|
37
|
-
M[i][j] =
|
|
38
|
-
bytes[i * 64 + j * 4] << 24 |
|
|
39
|
-
bytes[i * 64 + j * 4 + 1] << 16 |
|
|
40
|
-
bytes[i * 64 + j * 4 + 2] << 8 |
|
|
41
|
-
bytes[i * 64 + j * 4 + 3];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
M[N - 1][14] = ((bytes.length - 1) * 8) /
|
|
46
|
-
Math.pow(2, 32); M[N - 1][14] = Math.floor(M[N - 1][14]);
|
|
47
|
-
M[N - 1][15] = ((bytes.length - 1) * 8) & 0xffffffff;
|
|
48
|
-
|
|
49
|
-
for (var i=0; i<N; i++) {
|
|
50
|
-
var W = new Array(80);
|
|
51
|
-
|
|
52
|
-
for (var t=0; t<16; t++) W[t] = M[i][t];
|
|
53
|
-
for (var t=16; t<80; t++) {
|
|
54
|
-
W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
var a = H[0];
|
|
58
|
-
var b = H[1];
|
|
59
|
-
var c = H[2];
|
|
60
|
-
var d = H[3];
|
|
61
|
-
var e = H[4];
|
|
62
|
-
|
|
63
|
-
for (var t=0; t<80; t++) {
|
|
64
|
-
var s = Math.floor(t/20);
|
|
65
|
-
var T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t] >>> 0;
|
|
66
|
-
e = d;
|
|
67
|
-
d = c;
|
|
68
|
-
c = ROTL(b, 30) >>> 0;
|
|
69
|
-
b = a;
|
|
70
|
-
a = T;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
H[0] = (H[0] + a) >>> 0;
|
|
74
|
-
H[1] = (H[1] + b) >>> 0;
|
|
75
|
-
H[2] = (H[2] + c) >>> 0;
|
|
76
|
-
H[3] = (H[3] + d) >>> 0;
|
|
77
|
-
H[4] = (H[4] + e) >>> 0;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return [
|
|
81
|
-
H[0] >> 24 & 0xff, H[0] >> 16 & 0xff, H[0] >> 8 & 0xff, H[0] & 0xff,
|
|
82
|
-
H[1] >> 24 & 0xff, H[1] >> 16 & 0xff, H[1] >> 8 & 0xff, H[1] & 0xff,
|
|
83
|
-
H[2] >> 24 & 0xff, H[2] >> 16 & 0xff, H[2] >> 8 & 0xff, H[2] & 0xff,
|
|
84
|
-
H[3] >> 24 & 0xff, H[3] >> 16 & 0xff, H[3] >> 8 & 0xff, H[3] & 0xff,
|
|
85
|
-
H[4] >> 24 & 0xff, H[4] >> 16 & 0xff, H[4] >> 8 & 0xff, H[4] & 0xff
|
|
86
|
-
];
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
module.exports = sha1;
|
package/lib/sha1.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var crypto = require('crypto');
|
|
4
|
-
|
|
5
|
-
function sha1(bytes) {
|
|
6
|
-
if (typeof Buffer.from === 'function') {
|
|
7
|
-
// Modern Buffer API
|
|
8
|
-
if (Array.isArray(bytes)) {
|
|
9
|
-
bytes = Buffer.from(bytes);
|
|
10
|
-
} else if (typeof bytes === 'string') {
|
|
11
|
-
bytes = Buffer.from(bytes, 'utf8');
|
|
12
|
-
}
|
|
13
|
-
} else {
|
|
14
|
-
// Pre-v4 Buffer API
|
|
15
|
-
if (Array.isArray(bytes)) {
|
|
16
|
-
bytes = new Buffer(bytes);
|
|
17
|
-
} else if (typeof bytes === 'string') {
|
|
18
|
-
bytes = new Buffer(bytes, 'utf8');
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return crypto.createHash('sha1').update(bytes).digest();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
module.exports = sha1;
|
package/lib/v35.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
var bytesToUuid = require('./bytesToUuid');
|
|
2
|
-
|
|
3
|
-
function uuidToBytes(uuid) {
|
|
4
|
-
// Note: We assume we're being passed a valid uuid string
|
|
5
|
-
var bytes = [];
|
|
6
|
-
uuid.replace(/[a-fA-F0-9]{2}/g, function(hex) {
|
|
7
|
-
bytes.push(parseInt(hex, 16));
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
return bytes;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function stringToBytes(str) {
|
|
14
|
-
str = unescape(encodeURIComponent(str)); // UTF8 escape
|
|
15
|
-
var bytes = new Array(str.length);
|
|
16
|
-
for (var i = 0; i < str.length; i++) {
|
|
17
|
-
bytes[i] = str.charCodeAt(i);
|
|
18
|
-
}
|
|
19
|
-
return bytes;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
module.exports = function(name, version, hashfunc) {
|
|
23
|
-
var generateUUID = function(value, namespace, buf, offset) {
|
|
24
|
-
var off = buf && offset || 0;
|
|
25
|
-
|
|
26
|
-
if (typeof(value) == 'string') value = stringToBytes(value);
|
|
27
|
-
if (typeof(namespace) == 'string') namespace = uuidToBytes(namespace);
|
|
28
|
-
|
|
29
|
-
if (!Array.isArray(value)) throw TypeError('value must be an array of bytes');
|
|
30
|
-
if (!Array.isArray(namespace) || namespace.length !== 16) throw TypeError('namespace must be uuid string or an Array of 16 byte values');
|
|
31
|
-
|
|
32
|
-
// Per 4.3
|
|
33
|
-
var bytes = hashfunc(namespace.concat(value));
|
|
34
|
-
bytes[6] = (bytes[6] & 0x0f) | version;
|
|
35
|
-
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
36
|
-
|
|
37
|
-
if (buf) {
|
|
38
|
-
for (var idx = 0; idx < 16; ++idx) {
|
|
39
|
-
buf[off+idx] = bytes[idx];
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return buf || bytesToUuid(bytes);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// Function#name is not settable on some platforms (#270)
|
|
47
|
-
try {
|
|
48
|
-
generateUUID.name = name;
|
|
49
|
-
} catch (err) {
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Pre-defined namespaces, per Appendix C
|
|
53
|
-
generateUUID.DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
|
|
54
|
-
generateUUID.URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
|
|
55
|
-
|
|
56
|
-
return generateUUID;
|
|
57
|
-
};
|
package/v3.js
DELETED
package/v4.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
var rng = require('./lib/rng');
|
|
2
|
-
var bytesToUuid = require('./lib/bytesToUuid');
|
|
3
|
-
|
|
4
|
-
function v4(options, buf, offset) {
|
|
5
|
-
var i = buf && offset || 0;
|
|
6
|
-
|
|
7
|
-
if (typeof(options) == 'string') {
|
|
8
|
-
buf = options === 'binary' ? new Array(16) : null;
|
|
9
|
-
options = null;
|
|
10
|
-
}
|
|
11
|
-
options = options || {};
|
|
12
|
-
|
|
13
|
-
var rnds = options.random || (options.rng || rng)();
|
|
14
|
-
|
|
15
|
-
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
16
|
-
rnds[6] = (rnds[6] & 0x0f) | 0x40;
|
|
17
|
-
rnds[8] = (rnds[8] & 0x3f) | 0x80;
|
|
18
|
-
|
|
19
|
-
// Copy bytes to buffer, if provided
|
|
20
|
-
if (buf) {
|
|
21
|
-
for (var ii = 0; ii < 16; ++ii) {
|
|
22
|
-
buf[i + ii] = rnds[ii];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return buf || bytesToUuid(rnds);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports = v4;
|
package/v5.js
DELETED