Typescript/Deno port
This commit is contained in:
parent
6ad1e32cf2
commit
a2a97b106e
58 changed files with 3991 additions and 15028 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -1,6 +0,0 @@
|
||||||
.DS_Store
|
|
||||||
.vscode
|
|
||||||
.cache
|
|
||||||
node_modules
|
|
||||||
coverage
|
|
||||||
package-lock.json
|
|
30
.travis.yml
30
.travis.yml
|
@ -1,30 +0,0 @@
|
||||||
language: node_js
|
|
||||||
node_js:
|
|
||||||
- node
|
|
||||||
before_script:
|
|
||||||
- yarn install
|
|
||||||
script:
|
|
||||||
- yarn lint
|
|
||||||
- yarn test
|
|
||||||
- yarn build
|
|
||||||
after_success:
|
|
||||||
- yarn coverage
|
|
||||||
- yarn docs
|
|
||||||
notifications:
|
|
||||||
slack:
|
|
||||||
secure: Kwe1KBh4SMzgXaj6GQg3ZmopRYcDR3Vnd4C/gyiEOJsXzKRlU5dA7WwM/mbyOe9+ZvWDyp+g2CoQYYyvLR0SHEy1m0gn6M8fBzgSZQlWxOxAJxkwVsyxUNwAy2FylMpS+ugpw/fBMSbnSFqfZSa/tGB3KhBc0yA7V9wVS0hnwBfICqKKlFdLPcp+Us4zpXRUmcL1e0BVwm2klJi0CoKlOmTa4lI3tUa/YiuuMpgk89/PioMEr6/PP+5OfWV624djw2gznoualvcwdfZniC/oxkdTUbcu4nbTf+bFk5uwwW+XBpUhm9rMUoftngYCrWdtYHS6qenyzmflO5bgCDg5W8onv3qgMcDTEHDjlO8JMoEQLC2o27Hsyukrh2Iu0Hn2k4S10ZIDWLUZXf8ERKdU7v8o5xaiCrP7NO8fJlyGbWwYxwpFi9dpacb8qWuWw53k8+ld9orl2Zu5t1Y1QJCvT0DP0iGYSxbbICfex7im0fgh3A+MHTfhxxiGQtFJRUxqO5wGCIsT4dJJkYwRJ1HoCPyLT1x1WT8iy4lr8ivRhanEwQ5g2OmuRKz522yCrm2DPaRR/LDhqK9xghJqqh4RNx9Be5xNaxSxKs4Hcya4ZXrGaU9tzGTehRkNQksKUHq9PpdY85Mbk84wEq7zKLhtLPTn17DQePFm2DbdX4392o4=
|
|
||||||
deploy:
|
|
||||||
- provider: releases
|
|
||||||
api_key:
|
|
||||||
secure: XnNnfgiLx07D6SuAXtxzyt1aqdmDq3BkQVvOSgkFEF5RL+wJGqCAtVgy3eCK+kHRM8tzXHV00jG3FEQ0VoKg9iBX94VUdVS73cxGNgh7Vq1mZLVK+rDVxuPxzDrWmxihtX0BtHd/hi6zcETSWgdyfcSpJYZtChwByWC05BzXuiAow39/GfC4ZtIWZb3UmbWWCZLm+O7LTLeAO4Q2Ws+c6cLipnSS9DMgIoaFOouzXIgn34bCjLtBqfbEhwcxPEvTbwmDpIDFM/wpCu3rrpFlVxnmwcwmT/U2ktQi58OXiGIl3xyeAU4PWu9SMxNtt+QnPqgeTcwwRxzeoCVgfHbeALoYdQd+dgJVYZs2O8qQrb+6mKrkn8ntP25slbEUFnjtekUpwNxG6KLexbhDkWwyPTmpcpyxNf5TKXepAGUjwyU5fBbLt1Z3FFnBgwoxH+zkoIeujt4w+eikjodaQlU22SdYfe6fVOEtHp8RhWZCuZRNAxxvkCoE+0z3exEtzxIONM7rrpZOfuZrfwrI4ycZnRJmJ5EJOPhCmcQ4tXV9ZtVFBc3LqkHLE4UWXgQGLsAFJ8DUgyz72IyCOUOURFrWom57KDfJxC7cnQ4e/qtasUai1XFnrUxe3e9Ht4qefCMMRCOqH+fiAIWHcJbmQTG8DQUQJhrsow53IyeOkpvGbH8=
|
|
||||||
file: dist/octo.js
|
|
||||||
on:
|
|
||||||
tags: true
|
|
||||||
- provider: pages
|
|
||||||
keep-history: true
|
|
||||||
skip_cleanup: true
|
|
||||||
github_token:
|
|
||||||
secure: IOkxgeT9v83fj7XDnQirhlFjxH2BsqF04taAKxYWoshrMJVS33txjLE4tsm9wwD8pAX7mYz+ym9WdNAnrpv7yOOm2t+DO2xKs+xWf15diHA0p2vqcDV0w6+fqLERt9/cZNo/TNEd5en6JABAJZQb1HQQFOQDMz6y6vbFPoN2O+rpku8pIUDwsjTSxY+Ocf4IDy6ka/cteWjsOpAxlR5hvVxOtNwW80CA+W6Xx5wif5lyJW/dP7zdQx2NPn//FCViNUTJH82OsCrex53kfxQyCrcsZzxwwHy4iB41eMF1TQcSVnLlu7Id0rw1N2K7IpXkzxC/GhQe36hrY4vLe03tIClwcHY/aWPi/gD45ebEeOYsQ+nLB8q8Rz9uD7/x0yVhM5OyTJbjD6zDx2HYcjgkolvXWXzsjxvsWdzBBzmuYafYAidj/YPjLf0wLcEk5zGK4aDLufn8m9Sjprdp91pf0/zDZ8DY0Hzv+ZNyKyqeC9gWbn0gDE6YQVh5sKizenBq9aTk/0gKwofGPF+iLX/bWxXnqMd6UFbsoW7qaCsF1kwrnJK2FRHCcA3bF7w5Rc7KcZS1X/Y9vsVAsGGrTx8pPlMvE2czrSToxA6SrRk1gXL0Vl9s23JYHphoMQFwGkqE6k0CT0XRR6Y5hg7mv/6C0tN29+VGSH2vNeUZSS28qnQ=
|
|
||||||
on:
|
|
||||||
branch: master
|
|
||||||
local_dir: docs/
|
|
1
index.js
1
index.js
|
@ -1 +0,0 @@
|
||||||
module.exports = require('./lib/')
|
|
11
lib/index.js
11
lib/index.js
|
@ -1,11 +0,0 @@
|
||||||
const logger = require('./logging')
|
|
||||||
const make = require('./make')
|
|
||||||
const random = require('./random')
|
|
||||||
const utils = require('./utils')
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
logger,
|
|
||||||
random,
|
|
||||||
make,
|
|
||||||
utils
|
|
||||||
}
|
|
|
@ -1,87 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
const utils = require('../utils')
|
|
||||||
|
|
||||||
let websocket = null
|
|
||||||
|
|
||||||
const sep = '\n/* ### NEXT TESTCASE ############################## */'
|
|
||||||
const color = {
|
|
||||||
red: '\u{1b}[1;31m',
|
|
||||||
green: '\u{1b}[1;32m',
|
|
||||||
clear: '\u{1b}[0m'
|
|
||||||
}
|
|
||||||
if (utils.platform.name.isWindows) {
|
|
||||||
color.red = ''
|
|
||||||
color.green = ''
|
|
||||||
color.clear = ''
|
|
||||||
}
|
|
||||||
|
|
||||||
class logger {
|
|
||||||
static console (msg) {
|
|
||||||
if (websocket) {
|
|
||||||
websocket.send(msg)
|
|
||||||
}
|
|
||||||
if (typeof window === 'undefined') {
|
|
||||||
try {
|
|
||||||
print(msg) // eslint-disable-line no-undef
|
|
||||||
} catch (e) {
|
|
||||||
console.log(msg)
|
|
||||||
}
|
|
||||||
} else if (window.dump) {
|
|
||||||
dump(msg) // eslint-disable-line no-undef
|
|
||||||
} else if (window.console && window.console.log) {
|
|
||||||
console.log(msg)
|
|
||||||
} else {
|
|
||||||
throw new Error('Unable to run console logger.')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static dump (msg) {
|
|
||||||
this.console(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
static dumpln (msg) {
|
|
||||||
this.dump(`${msg}\n`)
|
|
||||||
}
|
|
||||||
|
|
||||||
static log (msg) {
|
|
||||||
this.dumpln(`/*L*/ ${utils.script.safely(msg)}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
static info (msg) {
|
|
||||||
this.dumpln(`/*L*/ /* ${msg} */`)
|
|
||||||
}
|
|
||||||
|
|
||||||
static error (msg) {
|
|
||||||
this.dumpln(color.red + msg + color.clear)
|
|
||||||
}
|
|
||||||
|
|
||||||
static ok (msg) { // eslint-disable-line no-unused-vars
|
|
||||||
this.dumpln(color.green + msg + color.green)
|
|
||||||
}
|
|
||||||
|
|
||||||
static JSError (msg) {
|
|
||||||
this.error(`/* ERROR: ${msg} */`)
|
|
||||||
}
|
|
||||||
|
|
||||||
static comment (msg) {
|
|
||||||
this.dumpln(`/*L*/ // ${msg}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
static separator () {
|
|
||||||
this.dumpln(color.green + sep + color.clear)
|
|
||||||
}
|
|
||||||
|
|
||||||
static traceback () {
|
|
||||||
this.error('===[ Traceback ] ===')
|
|
||||||
try {
|
|
||||||
throw new Error()
|
|
||||||
} catch (e) {
|
|
||||||
this.dump(e.stack || e.stacktrace || '')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = logger
|
|
|
@ -1,22 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
const make = require('../make')
|
|
||||||
const random = require('../random')
|
|
||||||
|
|
||||||
class alignment extends make {
|
|
||||||
static horizontal () {
|
|
||||||
return random.item(['left', 'right', 'justify', 'center'])
|
|
||||||
}
|
|
||||||
|
|
||||||
static vertical () {
|
|
||||||
return random.item(['top', 'bottom', 'middle', 'baseline'])
|
|
||||||
}
|
|
||||||
|
|
||||||
static any () {
|
|
||||||
return random.pick([this.horizontal, this.vertical])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = alignment
|
|
19
lib/make/alignment.ts
Normal file
19
lib/make/alignment.ts
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
import random from "../random/random.ts";
|
||||||
|
|
||||||
|
export default class alignment {
|
||||||
|
static horizontal() {
|
||||||
|
return random.item(["left", "right", "justify", "center"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static vertical() {
|
||||||
|
return random.item(["top", "bottom", "middle", "baseline"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static any() {
|
||||||
|
return random.pick([this.horizontal, this.vertical]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,17 +2,17 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
const make = require('../make')
|
import random from "../random/random.ts";
|
||||||
const random = require('../random')
|
import numbers from "./numbers.ts";
|
||||||
|
|
||||||
class arrays extends make {
|
export default class arrays {
|
||||||
/**
|
/**
|
||||||
* Returns an array containing random values generated by the supplied function
|
* Returns an array containing random values generated by the supplied function
|
||||||
* @param {Function} fn - Function used to generate values
|
* @param {Function} fn - Function used to generate values
|
||||||
* @param {number} limit - Length of the array
|
* @param {number} limit - Length of the array
|
||||||
* @returns {Array}
|
* @returns {Array}
|
||||||
*/
|
*/
|
||||||
static filledArray (fn, limit = make.number.tiny()) {
|
static filledArray (fn, limit = numbers.tiny()) {
|
||||||
const array = []
|
const array = []
|
||||||
|
|
||||||
for (let i = 0; i < limit; i++) {
|
for (let i = 0; i < limit; i++) {
|
||||||
|
@ -26,4 +26,3 @@ class arrays extends make {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = arrays
|
|
|
@ -1,90 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
const make = require('../make')
|
|
||||||
const random = require('../random')
|
|
||||||
|
|
||||||
class colors extends make {
|
|
||||||
static any () {
|
|
||||||
return random.pick([
|
|
||||||
colors.rgb,
|
|
||||||
colors.hsl,
|
|
||||||
colors.keyword
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static rgb () {
|
|
||||||
let values
|
|
||||||
|
|
||||||
switch (random.number(4)) {
|
|
||||||
case 0:
|
|
||||||
// Rgb functional notation
|
|
||||||
if (random.bool()) {
|
|
||||||
// Ints
|
|
||||||
values = [random.number(255), random.number(255), random.number(255)]
|
|
||||||
} else {
|
|
||||||
// Percents
|
|
||||||
values = [`%${random.number(255)}`, `%${random.number(255)}`, `%${random.number(255)}`]
|
|
||||||
}
|
|
||||||
return `rgba(${values.join(',')})`
|
|
||||||
case 1:
|
|
||||||
// Rgba functional notation
|
|
||||||
values = [random.number(255), random.number(255), random.number(255), random.float()]
|
|
||||||
return `rgba(${values.join(',')})`
|
|
||||||
case 2:
|
|
||||||
// 4 char hex
|
|
||||||
return `#${random.hex(4)}`
|
|
||||||
default:
|
|
||||||
// 8 char hex
|
|
||||||
return `#${random.hex(8)}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static hsl () {
|
|
||||||
let values, opt
|
|
||||||
|
|
||||||
switch (random.number(4)) {
|
|
||||||
case 0:
|
|
||||||
values = [random.number(255), `%${random.number(255)}`, `%${random.number(255)}`]
|
|
||||||
return `hsl(${values.join(',')})`
|
|
||||||
case 1:
|
|
||||||
values = [random.number(255), `%${random.number(255)}`, `%${random.number(255)}`, `%${random.number(255)}`]
|
|
||||||
return `hsl(${values.join(',')})`
|
|
||||||
case 2:
|
|
||||||
opt = random.pick(['deg', 'rad', 'grad', 'turn'])
|
|
||||||
values = [random.number(255) + opt, `%${random.number(255)}`, `%${random.number(255)}`, `%${random.number(255)}`]
|
|
||||||
return `hsl(${values.join(',')})`
|
|
||||||
default:
|
|
||||||
values = [random.number(255), `%${random.number(255)}`, `%${random.number(255)}`, random.float()]
|
|
||||||
return `hsl(${values.join(',')})`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static keyword () {
|
|
||||||
return random.pick([
|
|
||||||
'lime', 'red', 'blue', 'invert', 'currentColor', 'ActiveBorder', 'ActiveCaption',
|
|
||||||
'AppWorkspace', 'Background', 'ButtonFace', 'ButtonHighlight', 'ButtonShadow',
|
|
||||||
'ButtonText', 'CaptionText', 'GrayText', 'Highlight', 'HighlightText',
|
|
||||||
'InactiveBorder', 'InactiveCaption', 'InactiveCaptionText', 'InfoBackground',
|
|
||||||
'InfoText', 'Menu', 'MenuText', 'Scrollbar', 'ThreeDDarkShadow', 'ThreeDFace',
|
|
||||||
'ThreeDHighlight', 'ThreeDLightShadow', 'ThreeDShadow', 'Window', 'WindowFrame',
|
|
||||||
'WindowText', '-moz-ButtonDefault', '-moz-ButtonHoverFace', '-moz-ButtonHoverText',
|
|
||||||
'-moz-CellHighlight', '-moz-CellHighlightText', '-moz-Combobox', '-moz-ComboboxText',
|
|
||||||
'-moz-Dialog', '-moz-DialogText', '-moz-dragtargetzone', '-moz-EvenTreeRow',
|
|
||||||
'-moz-Field', '-moz-FieldText', '-moz-html-CellHighlight',
|
|
||||||
'-moz-html-CellHighlightText', '-moz-mac-accentdarkestshadow',
|
|
||||||
'-moz-mac-accentdarkshadow', '-moz-mac-accentface',
|
|
||||||
'-moz-mac-accentlightesthighlight', '-moz-mac-accentlightshadow',
|
|
||||||
'-moz-mac-accentregularhighlight', '-moz-mac-accentregularshadow',
|
|
||||||
'-moz-mac-chrome-active', '-moz-mac-chrome-inactive', '-moz-mac-focusring',
|
|
||||||
'-moz-mac-menuselect', '-moz-mac-menushadow', '-moz-mac-menutextselect',
|
|
||||||
'-moz-MenuHover', '-moz-MenuHoverText', '-moz-MenuBarText', '-moz-MenuBarHoverText',
|
|
||||||
'-moz-nativehyperlinktext', '-moz-OddTreeRow', '-moz-win-communicationstext',
|
|
||||||
'-moz-win-mediatext', '-moz-activehyperlinktext', '-moz-default-background-color',
|
|
||||||
'-moz-default-color', '-moz-hyperlinktext', '-moz-visitedhyperlinktext'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = colors
|
|
165
lib/make/colors.ts
Normal file
165
lib/make/colors.ts
Normal file
|
@ -0,0 +1,165 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
import random from "../random/random.ts";
|
||||||
|
|
||||||
|
export default class colors {
|
||||||
|
static any() {
|
||||||
|
return random.pick([colors.rgb, colors.hsl, colors.keyword]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static rgb() {
|
||||||
|
let values;
|
||||||
|
|
||||||
|
switch (random.number(4)) {
|
||||||
|
case 0:
|
||||||
|
// Rgb functional notation
|
||||||
|
if (random.bool()) {
|
||||||
|
// Ints
|
||||||
|
values = [random.number(255), random.number(255), random.number(255)];
|
||||||
|
} else {
|
||||||
|
// Percents
|
||||||
|
values = [
|
||||||
|
`%${random.number(255)}`,
|
||||||
|
`%${random.number(255)}`,
|
||||||
|
`%${random.number(255)}`
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return `rgba(${values.join(",")})`;
|
||||||
|
case 1:
|
||||||
|
// Rgba functional notation
|
||||||
|
values = [
|
||||||
|
random.number(255),
|
||||||
|
random.number(255),
|
||||||
|
random.number(255),
|
||||||
|
random.float()
|
||||||
|
];
|
||||||
|
return `rgba(${values.join(",")})`;
|
||||||
|
case 2:
|
||||||
|
// 4 char hex
|
||||||
|
return `#${random.hex(4)}`;
|
||||||
|
default:
|
||||||
|
// 8 char hex
|
||||||
|
return `#${random.hex(8)}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static hsl() {
|
||||||
|
let values, opt;
|
||||||
|
|
||||||
|
switch (random.number(4)) {
|
||||||
|
case 0:
|
||||||
|
values = [
|
||||||
|
random.number(255),
|
||||||
|
`%${random.number(255)}`,
|
||||||
|
`%${random.number(255)}`
|
||||||
|
];
|
||||||
|
return `hsl(${values.join(",")})`;
|
||||||
|
case 1:
|
||||||
|
values = [
|
||||||
|
random.number(255),
|
||||||
|
`%${random.number(255)}`,
|
||||||
|
`%${random.number(255)}`,
|
||||||
|
`%${random.number(255)}`
|
||||||
|
];
|
||||||
|
return `hsl(${values.join(",")})`;
|
||||||
|
case 2:
|
||||||
|
opt = random.pick(["deg", "rad", "grad", "turn"]);
|
||||||
|
values = [
|
||||||
|
random.number(255) + opt,
|
||||||
|
`%${random.number(255)}`,
|
||||||
|
`%${random.number(255)}`,
|
||||||
|
`%${random.number(255)}`
|
||||||
|
];
|
||||||
|
return `hsl(${values.join(",")})`;
|
||||||
|
default:
|
||||||
|
values = [
|
||||||
|
random.number(255),
|
||||||
|
`%${random.number(255)}`,
|
||||||
|
`%${random.number(255)}`,
|
||||||
|
random.float()
|
||||||
|
];
|
||||||
|
return `hsl(${values.join(",")})`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static keyword() {
|
||||||
|
return random.pick([
|
||||||
|
"lime",
|
||||||
|
"red",
|
||||||
|
"blue",
|
||||||
|
"invert",
|
||||||
|
"currentColor",
|
||||||
|
"ActiveBorder",
|
||||||
|
"ActiveCaption",
|
||||||
|
"AppWorkspace",
|
||||||
|
"Background",
|
||||||
|
"ButtonFace",
|
||||||
|
"ButtonHighlight",
|
||||||
|
"ButtonShadow",
|
||||||
|
"ButtonText",
|
||||||
|
"CaptionText",
|
||||||
|
"GrayText",
|
||||||
|
"Highlight",
|
||||||
|
"HighlightText",
|
||||||
|
"InactiveBorder",
|
||||||
|
"InactiveCaption",
|
||||||
|
"InactiveCaptionText",
|
||||||
|
"InfoBackground",
|
||||||
|
"InfoText",
|
||||||
|
"Menu",
|
||||||
|
"MenuText",
|
||||||
|
"Scrollbar",
|
||||||
|
"ThreeDDarkShadow",
|
||||||
|
"ThreeDFace",
|
||||||
|
"ThreeDHighlight",
|
||||||
|
"ThreeDLightShadow",
|
||||||
|
"ThreeDShadow",
|
||||||
|
"Window",
|
||||||
|
"WindowFrame",
|
||||||
|
"WindowText",
|
||||||
|
"-moz-ButtonDefault",
|
||||||
|
"-moz-ButtonHoverFace",
|
||||||
|
"-moz-ButtonHoverText",
|
||||||
|
"-moz-CellHighlight",
|
||||||
|
"-moz-CellHighlightText",
|
||||||
|
"-moz-Combobox",
|
||||||
|
"-moz-ComboboxText",
|
||||||
|
"-moz-Dialog",
|
||||||
|
"-moz-DialogText",
|
||||||
|
"-moz-dragtargetzone",
|
||||||
|
"-moz-EvenTreeRow",
|
||||||
|
"-moz-Field",
|
||||||
|
"-moz-FieldText",
|
||||||
|
"-moz-html-CellHighlight",
|
||||||
|
"-moz-html-CellHighlightText",
|
||||||
|
"-moz-mac-accentdarkestshadow",
|
||||||
|
"-moz-mac-accentdarkshadow",
|
||||||
|
"-moz-mac-accentface",
|
||||||
|
"-moz-mac-accentlightesthighlight",
|
||||||
|
"-moz-mac-accentlightshadow",
|
||||||
|
"-moz-mac-accentregularhighlight",
|
||||||
|
"-moz-mac-accentregularshadow",
|
||||||
|
"-moz-mac-chrome-active",
|
||||||
|
"-moz-mac-chrome-inactive",
|
||||||
|
"-moz-mac-focusring",
|
||||||
|
"-moz-mac-menuselect",
|
||||||
|
"-moz-mac-menushadow",
|
||||||
|
"-moz-mac-menutextselect",
|
||||||
|
"-moz-MenuHover",
|
||||||
|
"-moz-MenuHoverText",
|
||||||
|
"-moz-MenuBarText",
|
||||||
|
"-moz-MenuBarHoverText",
|
||||||
|
"-moz-nativehyperlinktext",
|
||||||
|
"-moz-OddTreeRow",
|
||||||
|
"-moz-win-communicationstext",
|
||||||
|
"-moz-win-mediatext",
|
||||||
|
"-moz-activehyperlinktext",
|
||||||
|
"-moz-default-background-color",
|
||||||
|
"-moz-default-color",
|
||||||
|
"-moz-hyperlinktext",
|
||||||
|
"-moz-visitedhyperlinktext"
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,69 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
const make = require('../make')
|
|
||||||
const random = require('../random')
|
|
||||||
|
|
||||||
class command extends make {
|
|
||||||
static data () {
|
|
||||||
return {
|
|
||||||
'backcolor': () => make.colors.any(),
|
|
||||||
'bold': null,
|
|
||||||
'contentReadOnly': () => random.bool(),
|
|
||||||
'copy': null,
|
|
||||||
'createlink': () => make.uri.any(),
|
|
||||||
'cut': null,
|
|
||||||
'decreasefontsize': null,
|
|
||||||
'delete': null,
|
|
||||||
'enableInlineTableEditing': () => random.bool(),
|
|
||||||
'enableObjectResizing': () => random.bool(),
|
|
||||||
'fontname': () => make.font.family(),
|
|
||||||
'fontsize': () => make.font.relativeSize(),
|
|
||||||
'formatblock': ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ol', 'ul', 'pre', 'address', 'blockquote', 'dl', 'div'],
|
|
||||||
'forwarddelete': null,
|
|
||||||
'forecolor': () => make.colors.any(),
|
|
||||||
'gethtml': null,
|
|
||||||
'heading': null,
|
|
||||||
'hilitecolor': () => make.colors.any(),
|
|
||||||
'increasefontsize': null,
|
|
||||||
'indent': null,
|
|
||||||
'insertBrOnReturn': () => random.bool(),
|
|
||||||
'inserthorizontalrule': null,
|
|
||||||
// 'inserthtml': function () { },
|
|
||||||
'insertlinebreak': null,
|
|
||||||
'insertimage': () => make.uri.any(),
|
|
||||||
'insertorderedlist': null,
|
|
||||||
'insertparagraph': null,
|
|
||||||
'inserttext': () => make.text.any(),
|
|
||||||
'insertunorderedlist': null,
|
|
||||||
'italic': null,
|
|
||||||
'justifycenter': null,
|
|
||||||
'justifyfull': null,
|
|
||||||
'justifyleft': null,
|
|
||||||
'justifyright': null,
|
|
||||||
'outdent': null,
|
|
||||||
'paste': null,
|
|
||||||
'redo': null,
|
|
||||||
'removeformat': null,
|
|
||||||
'selectall': null,
|
|
||||||
'strikethrough': null,
|
|
||||||
'styleWithCSS': () => random.bool(),
|
|
||||||
'subscript': null,
|
|
||||||
'superscript': null,
|
|
||||||
'underline': null,
|
|
||||||
'undo': null,
|
|
||||||
'unlink': null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static name () {
|
|
||||||
return random.item(Object.keys(command.data()))
|
|
||||||
}
|
|
||||||
|
|
||||||
static value (name) {
|
|
||||||
return random.pick(command.data()[name])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = command
|
|
85
lib/make/command.ts
Normal file
85
lib/make/command.ts
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
import random from "../random/random.ts";
|
||||||
|
import colors from "./colors.ts";
|
||||||
|
import uri from "./uri.ts";
|
||||||
|
import font from "./fonts.ts";
|
||||||
|
import text from "./text.ts";
|
||||||
|
|
||||||
|
export default class command {
|
||||||
|
static data() {
|
||||||
|
return {
|
||||||
|
backcolor: () => colors.any(),
|
||||||
|
bold: null,
|
||||||
|
contentReadOnly: () => random.bool(),
|
||||||
|
copy: null,
|
||||||
|
createlink: () => uri.any(),
|
||||||
|
cut: null,
|
||||||
|
decreasefontsize: null,
|
||||||
|
delete: null,
|
||||||
|
enableInlineTableEditing: () => random.bool(),
|
||||||
|
enableObjectResizing: () => random.bool(),
|
||||||
|
fontname: () => font.family(),
|
||||||
|
fontsize: () => font.relativeSize(),
|
||||||
|
formatblock: [
|
||||||
|
"p",
|
||||||
|
"h1",
|
||||||
|
"h2",
|
||||||
|
"h3",
|
||||||
|
"h4",
|
||||||
|
"h5",
|
||||||
|
"h6",
|
||||||
|
"ol",
|
||||||
|
"ul",
|
||||||
|
"pre",
|
||||||
|
"address",
|
||||||
|
"blockquote",
|
||||||
|
"dl",
|
||||||
|
"div"
|
||||||
|
],
|
||||||
|
forwarddelete: null,
|
||||||
|
forecolor: () => colors.any(),
|
||||||
|
gethtml: null,
|
||||||
|
heading: null,
|
||||||
|
hilitecolor: () => colors.any(),
|
||||||
|
increasefontsize: null,
|
||||||
|
indent: null,
|
||||||
|
insertBrOnReturn: () => random.bool(),
|
||||||
|
inserthorizontalrule: null,
|
||||||
|
// 'inserthtml': function () { },
|
||||||
|
insertlinebreak: null,
|
||||||
|
insertimage: () => uri.any(),
|
||||||
|
insertorderedlist: null,
|
||||||
|
insertparagraph: null,
|
||||||
|
inserttext: () => text.any(),
|
||||||
|
insertunorderedlist: null,
|
||||||
|
italic: null,
|
||||||
|
justifycenter: null,
|
||||||
|
justifyfull: null,
|
||||||
|
justifyleft: null,
|
||||||
|
justifyright: null,
|
||||||
|
outdent: null,
|
||||||
|
paste: null,
|
||||||
|
redo: null,
|
||||||
|
removeformat: null,
|
||||||
|
selectall: null,
|
||||||
|
strikethrough: null,
|
||||||
|
styleWithCSS: () => random.bool(),
|
||||||
|
subscript: null,
|
||||||
|
superscript: null,
|
||||||
|
underline: null,
|
||||||
|
undo: null,
|
||||||
|
unlink: null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static commandName() {
|
||||||
|
return random.item(Object.keys(command.data()));
|
||||||
|
}
|
||||||
|
|
||||||
|
static value(name) {
|
||||||
|
return random.pick(command.data()[name]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,915 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
const random = require('../random')
|
|
||||||
const make = require('../make')
|
|
||||||
const utils = require('../utils')
|
|
||||||
|
|
||||||
class crypto extends make {
|
|
||||||
static get keyFormats () {
|
|
||||||
return [
|
|
||||||
'raw',
|
|
||||||
'spki',
|
|
||||||
'pkcs8',
|
|
||||||
'jwk'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
static randomKeyFormat () {
|
|
||||||
return random.item(crypto.keyFormats)
|
|
||||||
}
|
|
||||||
|
|
||||||
static get keyTypes () {
|
|
||||||
return [
|
|
||||||
'public',
|
|
||||||
'private',
|
|
||||||
'secret'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
static randomKeyType () {
|
|
||||||
return random.item(crypto.keyTypes)
|
|
||||||
}
|
|
||||||
|
|
||||||
static get keyUsages () {
|
|
||||||
return [
|
|
||||||
'encrypt',
|
|
||||||
'decrypt',
|
|
||||||
'sign',
|
|
||||||
'verify',
|
|
||||||
'deriveKey',
|
|
||||||
'deriveBits',
|
|
||||||
'wrapKey',
|
|
||||||
'unwrapKey'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomKeyUsage () {
|
|
||||||
return random.subset(crypto.keyUsages)
|
|
||||||
}
|
|
||||||
|
|
||||||
static get curves () {
|
|
||||||
return [
|
|
||||||
'P-256',
|
|
||||||
'P-384',
|
|
||||||
'P-521'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomCurve () {
|
|
||||||
return random.item(crypto.curves)
|
|
||||||
}
|
|
||||||
|
|
||||||
static get jwkUsages () {
|
|
||||||
return [
|
|
||||||
'enc',
|
|
||||||
'sig'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomJwkUsage () {
|
|
||||||
return random.subset(crypto.keyUsages)
|
|
||||||
}
|
|
||||||
|
|
||||||
static get jwkKeyTypes () {
|
|
||||||
return [
|
|
||||||
'oct',
|
|
||||||
'RSA',
|
|
||||||
'EC'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomJwkKeyType () {
|
|
||||||
return random.subset(crypto.jwkKeyTypes)
|
|
||||||
}
|
|
||||||
|
|
||||||
static get algorithmNames () {
|
|
||||||
// https://www.w3.org/TR/WebCryptoAPI/#algorithm-overview
|
|
||||||
return {
|
|
||||||
sign: [
|
|
||||||
'RSASSA-PKCS1-v1_5',
|
|
||||||
'RSA-PSS',
|
|
||||||
'ECDSA',
|
|
||||||
'HMAC'
|
|
||||||
],
|
|
||||||
verify: [
|
|
||||||
'RSASSA-PKCS1-v1_5',
|
|
||||||
'RSA-PSS',
|
|
||||||
'ECDSA',
|
|
||||||
'HMAC'
|
|
||||||
],
|
|
||||||
generateKey: [
|
|
||||||
'RSASSA-PKCS1-v1_5',
|
|
||||||
'RSA-PSS',
|
|
||||||
'RSA-OAEP',
|
|
||||||
'ECDSA',
|
|
||||||
'ECDH',
|
|
||||||
'AES-CTR',
|
|
||||||
'AES-CBC',
|
|
||||||
'AES-GCM',
|
|
||||||
'AES-KW',
|
|
||||||
'HMAC'
|
|
||||||
],
|
|
||||||
importKey: [
|
|
||||||
'RSASSA-PKCS1-v1_5',
|
|
||||||
'RSA-PSS',
|
|
||||||
'RSA-OAEP',
|
|
||||||
'ECDSA',
|
|
||||||
'ECDH',
|
|
||||||
'AES-CTR',
|
|
||||||
'AES-CBC',
|
|
||||||
'AES-GCM',
|
|
||||||
'AES-KW',
|
|
||||||
'HMAC',
|
|
||||||
'HKDF',
|
|
||||||
'PBKDF2'
|
|
||||||
],
|
|
||||||
exportKey: [
|
|
||||||
'RSASSA-PKCS1-v1_5',
|
|
||||||
'RSA-PSS',
|
|
||||||
'RSA-OAEP',
|
|
||||||
'ECDSA',
|
|
||||||
'ECDH',
|
|
||||||
'AES-CTR',
|
|
||||||
'AES-CBC',
|
|
||||||
'AES-GCM',
|
|
||||||
'AES-KW',
|
|
||||||
'HMAC'
|
|
||||||
],
|
|
||||||
encrypt: [
|
|
||||||
'RSA-OAEP',
|
|
||||||
'AES-CTR',
|
|
||||||
'AES-CBC',
|
|
||||||
'AES-GCM'
|
|
||||||
],
|
|
||||||
decrypt: [
|
|
||||||
'RSA-OAEP',
|
|
||||||
'AES-CTR',
|
|
||||||
'AES-CBC',
|
|
||||||
'AES-GCM'
|
|
||||||
],
|
|
||||||
deriveBits: [
|
|
||||||
'ECDH',
|
|
||||||
'HKDF',
|
|
||||||
'PBKDF2'
|
|
||||||
],
|
|
||||||
deriveKey: [
|
|
||||||
'ECDH',
|
|
||||||
'HKDF',
|
|
||||||
'PBKDF2'
|
|
||||||
],
|
|
||||||
wrapKey: [
|
|
||||||
'RSA-OAEP',
|
|
||||||
'AES-CTR',
|
|
||||||
'AES-CBC',
|
|
||||||
'AES-GCM',
|
|
||||||
'AES-KW'
|
|
||||||
],
|
|
||||||
unwrapKey: [
|
|
||||||
'RSA-OAEP',
|
|
||||||
'AES-CTR',
|
|
||||||
'AES-CBC',
|
|
||||||
'AES-GCM',
|
|
||||||
'AES-KW'
|
|
||||||
],
|
|
||||||
digest: [
|
|
||||||
'SHA-1',
|
|
||||||
'SHA-256',
|
|
||||||
'SHA-384',
|
|
||||||
'SHA-512'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomAlgorithmName (method) {
|
|
||||||
return random.item(crypto.algorithmNames[method])
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomDigestName () {
|
|
||||||
return random.item(crypto.algorithmNames.digest)
|
|
||||||
}
|
|
||||||
|
|
||||||
static get algorithms () {
|
|
||||||
return {
|
|
||||||
/* (Unsupported as of 30/01/2017)
|
|
||||||
-------------------------------
|
|
||||||
| | Firefox | Chrome |
|
|
||||||
----------------------------- |
|
|
||||||
| AES-CMAC | x | x |
|
|
||||||
| AES-CFB | x | x |
|
|
||||||
| CONCAT | x | x |
|
|
||||||
| HKDF-CTR | x | x |
|
|
||||||
| DH | | x |
|
|
||||||
-------------------------------
|
|
||||||
*/
|
|
||||||
'RSASSA-PKCS1-v1_5': {
|
|
||||||
// RSASA-PKCS1_v1_5 algorithm, using a SHA hash function.
|
|
||||||
keyUsages: ['sign', 'verify'],
|
|
||||||
length: function (len) {
|
|
||||||
return len || random.item([1, 256, 384, 512])
|
|
||||||
},
|
|
||||||
alg: function (len) {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'RSASSA-PKCS1-v1_5',
|
|
||||||
hash: {
|
|
||||||
name: 'SHA-${this.length(len)}'
|
|
||||||
},
|
|
||||||
modulusLength: ${random.item([1024, 2048, 4096])},
|
|
||||||
publicExponent: new Uint8Array([0x01, 0x00, 0x01])
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
jwk: function (len) {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
kty: 'RSA',
|
|
||||||
alg: 'RS${this.length(len)}'
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
generateKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
importKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
sign: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
verify: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
presets: {
|
|
||||||
raw: {},
|
|
||||||
jwk: [
|
|
||||||
{
|
|
||||||
kty: 'RSA',
|
|
||||||
e: 'AQAB',
|
|
||||||
n: 'vGO3eU16ag9zRkJ4AK8ZUZrjbtp5xWK0LyFMNT8933evJoHeczexMUzSiXaLrEFSyQZortk81zJH3y41MBO_UFDO_X0crAquNrkjZDrf9Scc5-MdxlWU2Jl7Gc4Z18AC9aNibWVmXhgvHYkEoFdLCFG-2Sq-qIyW4KFkjan05IE',
|
|
||||||
alg: 'RS256',
|
|
||||||
ext: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
kty: 'RSA',
|
|
||||||
e: 'AQAB',
|
|
||||||
d: 'n_dIVw9MD_04lANi5KnKJPoRfxKy7cGHYLG0hU5DGpsFNfx2yH0Uz9j8uU7ZARai1iHECBxcxhpi3wbckQtjmbkCUKvs4G0gKLT9UuNHcCbh0WfvadfPPec52n4z6s4zwisbgWCNbT2L-SyHt1yuFmLAYXkg0swk3y5Bt_ilA8E',
|
|
||||||
dp: '2RNM_uiYEQMcATQaUu3AwdeJpenCPykbQHkwAylvXqlHB6W7m5XX0k-SutkbXAijmGTC-Oh8NexsLGHxOACb8Q',
|
|
||||||
dq: 'rHabkI3_XVGieLqHujpWaWe9YD03fJY0KbbQX0fIoNdNU4GcmUftzIWLSajPKKsiyfR6Xk2AEtBmBPE5qaoV6Q',
|
|
||||||
n: 'vGO3eU16ag9zRkJ4AK8ZUZrjbtp5xWK0LyFMNT8933evJoHeczexMUzSiXaLrEFSyQZortk81zJH3y41MBO_UFDO_X0crAquNrkjZDrf9Scc5-MdxlWU2Jl7Gc4Z18AC9aNibWVmXhgvHYkEoFdLCFG-2Sq-qIyW4KFkjan05IE',
|
|
||||||
p: '5Y4ynodegqC9kgGmfZeSrojGmLyYR8HIvKVEAIjjMUQjyvKWpWsXfPg67mTdqVpjSpQLQlRfES2nUvZ27KrU6Q',
|
|
||||||
q: '0hd_U9PcNpMe77nhsTgoVNgMB34cqfrfu4fPuJ-7NvvMkKIELDLy-m8qg1MBbgf2i5546A9B5Exsuj4D2Vwz2Q',
|
|
||||||
qi: 'R3CkCGVAESy_hChmDvUaLMT-R1xk6kK7RLIUQKXATPQbnDqWBMgm-vcawFVhKJ-ICJsPfmRUsv7Wt1bJ01wLGQ',
|
|
||||||
alg: 'RS256',
|
|
||||||
ext: true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
spki: 'new Uint8Array([48, 129, 159, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 3, 129, 141, 0, 48, 129, 137, 2, 129, 129, 0, 182, 93, 35, 213, 252, 204, 20, 103, 91, 238, 105, 199, 53, 114, 24, 221, 114, 210, 137, 173, 88, 76, 205, 113, 148, 148, 79, 80, 59, 208, 60, 75, 231, 248, 78, 125, 12, 30, 237, 226, 63, 146, 157, 203, 239, 60, 138, 123, 234, 50, 23, 174, 216, 33, 122, 16, 53, 246, 140, 254, 75, 246, 205, 204, 117, 204, 115, 29, 178, 102, 139, 201, 74, 177, 45, 131, 183, 166, 234, 61, 124, 75, 110, 3, 70, 202, 148, 95, 45, 228, 94, 95, 148, 2, 162, 79, 146, 137, 29, 189, 102, 75, 207, 214, 116, 58, 63, 171, 219, 27, 5, 9, 108, 16, 218, 23, 169, 43, 181, 119, 31, 172, 95, 205, 180, 18, 255, 203, 2, 3, 1, 0, 1])',
|
|
||||||
pkcs8: 'new Uint8Array([48, 130, 2, 118, 2, 1, 0, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 4, 130, 2, 96, 48, 130, 2, 92, 2, 1, 0, 2, 129, 129, 0, 217, 78, 147, 218, 221, 152, 10, 66, 75, 127, 242, 108, 182, 142, 157, 44, 93, 58, 176, 193, 135, 103, 216, 179, 69, 72, 38, 115, 144, 244, 12, 139, 0, 245, 48, 115, 204, 234, 158, 193, 231, 127, 178, 240, 244, 203, 35, 229, 203, 245, 110, 215, 199, 19, 98, 183, 164, 223, 159, 203, 128, 123, 173, 26, 12, 172, 250, 99, 254, 35, 225, 221, 39, 51, 62, 3, 139, 35, 38, 164, 71, 238, 240, 73, 139, 214, 68, 172, 204, 253, 171, 244, 14, 186, 152, 159, 225, 133, 229, 140, 99, 50, 183, 242, 217, 248, 86, 233, 20, 117, 42, 136, 55, 8, 65, 124, 244, 65, 29, 15, 194, 255, 78, 31, 189, 146, 105, 161, 2, 3, 1, 0, 1, 2, 129, 128, 26, 88, 13, 82, 166, 52, 141, 97, 214, 23, 79, 195, 96, 42, 79, 225, 149, 247, 204, 127, 217, 179, 124, 48, 215, 128, 84, 177, 3, 236, 162, 44, 163, 212, 21, 168, 164, 57, 249, 63, 22, 154, 131, 141, 244, 143, 63, 237, 214, 217, 13, 51, 249, 125, 95, 37, 86, 70, 137, 239, 184, 198, 197, 136, 62, 183, 41, 78, 118, 234, 57, 195, 161, 219, 173, 234, 61, 11, 165, 109, 209, 9, 3, 22, 186, 114, 32, 135, 147, 74, 6, 106, 190, 214, 36, 208, 32, 220, 61, 12, 41, 105, 251, 247, 18, 159, 3, 198, 28, 228, 36, 44, 189, 125, 45, 72, 233, 199, 12, 72, 91, 106, 165, 246, 217, 58, 168, 53, 2, 65, 0, 241, 112, 53, 166, 98, 11, 38, 73, 58, 156, 84, 190, 118, 74, 247, 229, 85, 178, 83, 231, 53, 137, 237, 228, 246, 12, 32, 206, 157, 198, 152, 70, 11, 185, 234, 30, 112, 23, 115, 249, 68, 176, 159, 108, 247, 249, 207, 152, 145, 166, 246, 79, 176, 219, 163, 111, 243, 4, 49, 3, 239, 242, 63, 147, 2, 65, 0, 230, 105, 200, 1, 208, 201, 237, 225, 85, 27, 39, 216, 193, 1, 253, 168, 88, 15, 242, 166, 70, 106, 235, 2, 92, 24, 130, 66, 176, 176, 220, 238, 66, 12, 159, 26, 24, 40, 19, 213, 138, 98, 238, 98, 220, 65, 148, 116, 146, 21, 0, 25, 6, 177, 57, 216, 70, 51, 149, 244, 157, 153, 106, 123, 2, 64, 127, 92, 254, 48, 67, 80, 54, 102, 50, 240, 253, 19, 108, 59, 168, 1, 230, 239, 39, 171, 180, 102, 138, 132, 89, 247, 147, 230, 234, 252, 52, 159, 222, 215, 184, 85, 78, 52, 81, 13, 145, 218, 202, 127, 37, 97, 54, 205, 249, 39, 230, 143, 171, 112, 114, 11, 64, 91, 89, 176, 6, 7, 248, 217, 2, 65, 0, 220, 94, 95, 132, 29, 4, 132, 22, 247, 38, 185, 189, 125, 27, 66, 87, 55, 162, 73, 24, 238, 80, 99, 228, 37, 224, 234, 244, 141, 185, 26, 20, 101, 231, 92, 99, 192, 166, 212, 17, 112, 1, 158, 173, 190, 170, 154, 41, 195, 109, 130, 98, 109, 28, 35, 142, 205, 213, 152, 158, 19, 253, 30, 241, 2, 64, 15, 148, 8, 16, 189, 122, 55, 109, 203, 175, 173, 24, 222, 36, 130, 130, 179, 87, 189, 32, 141, 149, 30, 115, 211, 227, 79, 234, 78, 202, 253, 48, 173, 95, 167, 203, 20, 193, 160, 30, 146, 33, 109, 4, 221, 25, 212, 216, 183, 100, 18, 46, 184, 52, 65, 146, 249, 68, 225, 10, 84, 38, 98, 133])'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'RSA-PSS': {
|
|
||||||
keyUsages: ['sign', 'verify'],
|
|
||||||
length: function (len) {
|
|
||||||
return len || random.item([1, 256, 384, 512])
|
|
||||||
},
|
|
||||||
alg: function (len) {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'RSA-PSS',
|
|
||||||
hash: {
|
|
||||||
name: 'SHA-${this.length(len)}'
|
|
||||||
},
|
|
||||||
modulusLength: ${random.item([1024, 2048, 4096])},
|
|
||||||
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
|
|
||||||
saltLength: 8
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
jwk: function (len) {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
kty: 'RSA',
|
|
||||||
alg: 'PS${this.length(len)}'
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
generateKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
importKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
sign: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
verify: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
presets: {
|
|
||||||
raw: {},
|
|
||||||
jwk: [
|
|
||||||
{
|
|
||||||
kty: 'RSA',
|
|
||||||
e: 'AQAB',
|
|
||||||
n: 'vGO3eU16ag9zRkJ4AK8ZUZrjbtp5xWK0LyFMNT8933evJoHeczexMUzSiXaLrEFSyQZortk81zJH3y41MBO_UFDO_X0crAquNrkjZDrf9Scc5-MdxlWU2Jl7Gc4Z18AC9aNibWVmXhgvHYkEoFdLCFG-2Sq-qIyW4KFkjan05IE',
|
|
||||||
alg: 'RS256',
|
|
||||||
ext: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
kty: 'RSA',
|
|
||||||
e: 'AQAB',
|
|
||||||
d: 'n_dIVw9MD_04lANi5KnKJPoRfxKy7cGHYLG0hU5DGpsFNfx2yH0Uz9j8uU7ZARai1iHECBxcxhpi3wbckQtjmbkCUKvs4G0gKLT9UuNHcCbh0WfvadfPPec52n4z6s4zwisbgWCNbT2L-SyHt1yuFmLAYXkg0swk3y5Bt_ilA8E',
|
|
||||||
dp: '2RNM_uiYEQMcATQaUu3AwdeJpenCPykbQHkwAylvXqlHB6W7m5XX0k-SutkbXAijmGTC-Oh8NexsLGHxOACb8Q',
|
|
||||||
dq: 'rHabkI3_XVGieLqHujpWaWe9YD03fJY0KbbQX0fIoNdNU4GcmUftzIWLSajPKKsiyfR6Xk2AEtBmBPE5qaoV6Q',
|
|
||||||
n: 'vGO3eU16ag9zRkJ4AK8ZUZrjbtp5xWK0LyFMNT8933evJoHeczexMUzSiXaLrEFSyQZortk81zJH3y41MBO_UFDO_X0crAquNrkjZDrf9Scc5-MdxlWU2Jl7Gc4Z18AC9aNibWVmXhgvHYkEoFdLCFG-2Sq-qIyW4KFkjan05IE',
|
|
||||||
p: '5Y4ynodegqC9kgGmfZeSrojGmLyYR8HIvKVEAIjjMUQjyvKWpWsXfPg67mTdqVpjSpQLQlRfES2nUvZ27KrU6Q',
|
|
||||||
q: '0hd_U9PcNpMe77nhsTgoVNgMB34cqfrfu4fPuJ-7NvvMkKIELDLy-m8qg1MBbgf2i5546A9B5Exsuj4D2Vwz2Q',
|
|
||||||
qi: 'R3CkCGVAESy_hChmDvUaLMT-R1xk6kK7RLIUQKXATPQbnDqWBMgm-vcawFVhKJ-ICJsPfmRUsv7Wt1bJ01wLGQ',
|
|
||||||
alg: 'PS256',
|
|
||||||
ext: true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
spki: 'new Uint8Array([48, 129, 159, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 3, 129, 141, 0, 48, 129, 137, 2, 129, 129, 0, 180, 31, 227, 200, 37, 227, 65, 238, 23, 91, 226, 130, 51, 32, 165, 245, 1, 24, 244, 5, 184, 42, 181, 155, 23, 142, 249, 220, 222, 131, 175, 54, 117, 135, 64, 232, 120, 90, 160, 221, 18, 31, 200, 41, 23, 174, 18, 172, 247, 166, 90, 37, 156, 229, 2, 70, 169, 165, 93, 246, 120, 117, 59, 202, 3, 102, 44, 119, 154, 54, 28, 198, 111, 39, 144, 73, 69, 251, 179, 74, 41, 215, 115, 186, 124, 200, 105, 75, 104, 158, 156, 158, 238, 214, 14, 81, 95, 130, 155, 146, 114, 125, 88, 158, 212, 44, 65, 236, 228, 194, 105, 96, 211, 155, 60, 71, 134, 90, 151, 202, 68, 20, 228, 105, 249, 202, 170, 155, 2, 3, 1, 0, 1])',
|
|
||||||
plcs8: 'new Uint8Array([48, 130, 2, 119, 2, 1, 0, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 4, 130, 2, 97, 48, 130, 2, 93, 2, 1, 0, 2, 129, 129, 0, 180, 31, 227, 200, 37, 227, 65, 238, 23, 91, 226, 130, 51, 32, 165, 245, 1, 24, 244, 5, 184, 42, 181, 155, 23, 142, 249, 220, 222, 131, 175, 54, 117, 135, 64, 232, 120, 90, 160, 221, 18, 31, 200, 41, 23, 174, 18, 172, 247, 166, 90, 37, 156, 229, 2, 70, 169, 165, 93, 246, 120, 117, 59, 202, 3, 102, 44, 119, 154, 54, 28, 198, 111, 39, 144, 73, 69, 251, 179, 74, 41, 215, 115, 186, 124, 200, 105, 75, 104, 158, 156, 158, 238, 214, 14, 81, 95, 130, 155, 146, 114, 125, 88, 158, 212, 44, 65, 236, 228, 194, 105, 96, 211, 155, 60, 71, 134, 90, 151, 202, 68, 20, 228, 105, 249, 202, 170, 155, 2, 3, 1, 0, 1, 2, 129, 128, 102, 251, 236, 161, 220, 119, 168, 148, 86, 42, 164, 192, 200, 54, 156, 108, 14, 42, 148, 42, 72, 247, 178, 73, 112, 24, 192, 230, 245, 25, 217, 45, 139, 216, 190, 213, 171, 42, 53, 218, 239, 167, 216, 43, 22, 108, 226, 36, 158, 155, 47, 227, 93, 102, 217, 252, 72, 182, 81, 152, 191, 154, 87, 137, 219, 194, 236, 53, 200, 123, 61, 10, 59, 231, 41, 18, 116, 77, 148, 50, 170, 116, 221, 110, 170, 190, 158, 108, 217, 38, 73, 84, 183, 51, 122, 179, 217, 143, 255, 87, 82, 80, 223, 188, 84, 134, 146, 150, 169, 64, 30, 168, 104, 8, 123, 162, 46, 59, 47, 232, 0, 35, 202, 42, 195, 141, 6, 1, 2, 65, 0, 237, 171, 148, 110, 241, 19, 152, 216, 206, 77, 109, 215, 21, 144, 110, 96, 34, 61, 46, 214, 148, 70, 238, 119, 206, 128, 32, 24, 136, 197, 185, 254, 209, 35, 235, 231, 122, 246, 167, 183, 117, 176, 51, 133, 169, 47, 130, 178, 40, 225, 145, 219, 48, 56, 21, 46, 198, 18, 85, 218, 194, 150, 141, 27, 2, 65, 0, 194, 4, 41, 152, 43, 246, 147, 7, 229, 244, 215, 110, 143, 7, 184, 187, 22, 166, 113, 217, 81, 52, 205, 54, 73, 202, 244, 24, 24, 219, 254, 243, 230, 230, 212, 172, 225, 218, 112, 95, 118, 103, 144, 223, 248, 164, 19, 228, 204, 204, 64, 91, 76, 77, 4, 206, 89, 173, 154, 162, 134, 113, 176, 129, 2, 64, 58, 4, 78, 97, 158, 155, 200, 13, 244, 158, 86, 23, 208, 253, 198, 211, 212, 199, 214, 173, 46, 216, 249, 209, 105, 41, 65, 172, 123, 134, 184, 214, 137, 59, 25, 149, 18, 33, 47, 227, 202, 232, 206, 74, 236, 119, 218, 145, 159, 5, 33, 83, 190, 59, 146, 128, 46, 125, 191, 83, 125, 120, 190, 205, 2, 65, 0, 134, 6, 204, 25, 20, 29, 180, 250, 90, 207, 229, 214, 185, 53, 211, 86, 98, 210, 62, 137, 170, 128, 120, 86, 205, 105, 71, 112, 50, 20, 31, 174, 171, 206, 192, 18, 97, 191, 61, 171, 164, 166, 236, 188, 220, 13, 180, 180, 117, 9, 144, 87, 193, 128, 223, 22, 17, 123, 76, 252, 131, 53, 156, 129, 2, 65, 0, 178, 29, 141, 176, 179, 203, 180, 190, 224, 34, 134, 226, 151, 73, 139, 163, 47, 17, 179, 117, 167, 200, 255, 174, 67, 114, 158, 96, 195, 176, 163, 241, 96, 24, 72, 35, 38, 18, 132, 176, 76, 235, 8, 29, 225, 138, 155, 191, 97, 158, 3, 22, 114, 133, 176, 213, 207, 120, 33, 55, 52, 135, 79, 161])'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'RSA-OAEP': {
|
|
||||||
// RSAES-OAEP algorithm using a SHA hash functions and a MGF1 mask generating function.
|
|
||||||
keyUsages: ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey'],
|
|
||||||
length: function (len) {
|
|
||||||
return len || random.item([1, 256, 384, 512])
|
|
||||||
},
|
|
||||||
alg: function (len) {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'RSA-OAEP',
|
|
||||||
hash: {
|
|
||||||
name: 'SHA-${this.length(len)}'
|
|
||||||
},
|
|
||||||
modulusLength: ${random.item([1024, 2048, 4096])},
|
|
||||||
publicExponent: new Uint8Array([0x01, 0x00, 0x01])
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
jwk: function (len) {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
kty: 'RSA',
|
|
||||||
alg: 'RSA-OAEP-${this.length(len)}'
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
generateKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
importKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
encrypt: function () {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'RSA-OAEP',
|
|
||||||
hash: {
|
|
||||||
name: 'SHA-${this.length()}'
|
|
||||||
},
|
|
||||||
modulusLength: ${random.item([1024, 2048, 4096])},
|
|
||||||
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
|
|
||||||
label: crypto.getRandomValues(new Uint8Array(16))
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
decrypt: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
unwrapKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
wrapKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
presets: {
|
|
||||||
raw: {},
|
|
||||||
jkw: [
|
|
||||||
{
|
|
||||||
kty: 'RSA',
|
|
||||||
e: 'AQAB',
|
|
||||||
n: 'vGO3eU16ag9zRkJ4AK8ZUZrjbtp5xWK0LyFMNT8933evJoHeczexMUzSiXaLrEFSyQZortk81zJH3y41MBO_UFDO_X0crAquNrkjZDrf9Scc5-MdxlWU2Jl7Gc4Z18AC9aNibWVmXhgvHYkEoFdLCFG-2Sq-qIyW4KFkjan05IE',
|
|
||||||
alg: 'RSA-OAEP-256',
|
|
||||||
ext: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
kty: 'RSA',
|
|
||||||
e: 'AQAB',
|
|
||||||
d: 'e-Nm1CB_F7j0p4Cb-T4WmFTh7RbxUthC3j8xnlXwHgWYwaPs9ZRkicgNCfmjEb-qJ-m0ho1Cz4WzlL1CtTKEdr2w0P6L_IQPvWkFYwUm0rpY9doxnOKkzq53dhP5zdc6N8aOLk4cmAcVjw4o_csc85H-0fxzQxsTP0_jhJn7SNE',
|
|
||||||
dp: 'JuZmXNBY9uGGfx3w3ysmFumGBLooNjMwwgMduVS6T8S-0tZkBU-iwJPzXAkKhwINEv1EnygjwmJLBdoHROeEeQ',
|
|
||||||
dq: 'KaKOFHxm9104WNwqTth04O9ogaDz_W0wkeHnxOxbWgdtFxsarnImiMlI3Hphv9JuHD5awzNAkaj9P7wDVew-5Q',
|
|
||||||
n: 'x-Do39ky8RVFrFplFfAuOQGLr-rqY3h9OiNHVMe34LoVG4Aofps11ycyw5ka3Ls_yA-oRouGmaMjaiPUoaU_Lm5-CMSoVwyeANLZ4b2S7V-srXFS-Qpe6aD7NpzoUL9knwTnZFIGZlxSXB-NXL5kq18UuO1LQGe1To16ijXKNxc',
|
|
||||||
p: '4ss3ZAQMdmOk1BRQXwM9YHAoxVDkHDnSV9u89tUb3RbPXlV3fLlhRYtZ7u3FYaTzy08s8Ty2hV1KZ7xXhKEtuQ',
|
|
||||||
q: '4Z5ejmIJTwsgxN5pI6mLxwXqQwFDERYDnwU9_vyToWXMEPAphWpS9ET00YrdHsgIGao1Slc0jp4OUxaLfhtzTw',
|
|
||||||
qi: 'R1aKNnhUiTjoCHfOVHZ6Qv5R7So-F5mtjDKCBvCi8190U3E25DiKRvDqHZ0bHMRbdQPLLknxHVnuETw6gddHUg',
|
|
||||||
alg: 'RSA-OAEP-256',
|
|
||||||
ext: true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
spki: 'new Uint8Array([48, 129, 159, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 3, 129, 141, 0, 48, 129, 137, 2, 129, 129, 0, 182, 93, 35, 213, 252, 204, 20, 103, 91, 238, 105, 199, 53, 114, 24, 221, 114, 210, 137, 173, 88, 76, 205, 113, 148, 148, 79, 80, 59, 208, 60, 75, 231, 248, 78, 125, 12, 30, 237, 226, 63, 146, 157, 203, 239, 60, 138, 123, 234, 50, 23, 174, 216, 33, 122, 16, 53, 246, 140, 254, 75, 246, 205, 204, 117, 204, 115, 29, 178, 102, 139, 201, 74, 177, 45, 131, 183, 166, 234, 61, 124, 75, 110, 3, 70, 202, 148, 95, 45, 228, 94, 95, 148, 2, 162, 79, 146, 137, 29, 189, 102, 75, 207, 214, 116, 58, 63, 171, 219, 27, 5, 9, 108, 16, 218, 23, 169, 43, 181, 119, 31, 172, 95, 205, 180, 18, 255, 203, 2, 3, 1, 0, 1])',
|
|
||||||
pkcs8: 'new Uint8Array([48, 130, 2, 118, 2, 1, 0, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 4, 130, 2, 96, 48, 130, 2, 92, 2, 1, 0, 2, 129, 129, 0, 217, 78, 147, 218, 221, 152, 10, 66, 75, 127, 242, 108, 182, 142, 157, 44, 93, 58, 176, 193, 135, 103, 216, 179, 69, 72, 38, 115, 144, 244, 12, 139, 0, 245, 48, 115, 204, 234, 158, 193, 231, 127, 178, 240, 244, 203, 35, 229, 203, 245, 110, 215, 199, 19, 98, 183, 164, 223, 159, 203, 128, 123, 173, 26, 12, 172, 250, 99, 254, 35, 225, 221, 39, 51, 62, 3, 139, 35, 38, 164, 71, 238, 240, 73, 139, 214, 68, 172, 204, 253, 171, 244, 14, 186, 152, 159, 225, 133, 229, 140, 99, 50, 183, 242, 217, 248, 86, 233, 20, 117, 42, 136, 55, 8, 65, 124, 244, 65, 29, 15, 194, 255, 78, 31, 189, 146, 105, 161, 2, 3, 1, 0, 1, 2, 129, 128, 26, 88, 13, 82, 166, 52, 141, 97, 214, 23, 79, 195, 96, 42, 79, 225, 149, 247, 204, 127, 217, 179, 124, 48, 215, 128, 84, 177, 3, 236, 162, 44, 163, 212, 21, 168, 164, 57, 249, 63, 22, 154, 131, 141, 244, 143, 63, 237, 214, 217, 13, 51, 249, 125, 95, 37, 86, 70, 137, 239, 184, 198, 197, 136, 62, 183, 41, 78, 118, 234, 57, 195, 161, 219, 173, 234, 61, 11, 165, 109, 209, 9, 3, 22, 186, 114, 32, 135, 147, 74, 6, 106, 190, 214, 36, 208, 32, 220, 61, 12, 41, 105, 251, 247, 18, 159, 3, 198, 28, 228, 36, 44, 189, 125, 45, 72, 233, 199, 12, 72, 91, 106, 165, 246, 217, 58, 168, 53, 2, 65, 0, 241, 112, 53, 166, 98, 11, 38, 73, 58, 156, 84, 190, 118, 74, 247, 229, 85, 178, 83, 231, 53, 137, 237, 228, 246, 12, 32, 206, 157, 198, 152, 70, 11, 185, 234, 30, 112, 23, 115, 249, 68, 176, 159, 108, 247, 249, 207, 152, 145, 166, 246, 79, 176, 219, 163, 111, 243, 4, 49, 3, 239, 242, 63, 147, 2, 65, 0, 230, 105, 200, 1, 208, 201, 237, 225, 85, 27, 39, 216, 193, 1, 253, 168, 88, 15, 242, 166, 70, 106, 235, 2, 92, 24, 130, 66, 176, 176, 220, 238, 66, 12, 159, 26, 24, 40, 19, 213, 138, 98, 238, 98, 220, 65, 148, 116, 146, 21, 0, 25, 6, 177, 57, 216, 70, 51, 149, 244, 157, 153, 106, 123, 2, 64, 127, 92, 254, 48, 67, 80, 54, 102, 50, 240, 253, 19, 108, 59, 168, 1, 230, 239, 39, 171, 180, 102, 138, 132, 89, 247, 147, 230, 234, 252, 52, 159, 222, 215, 184, 85, 78, 52, 81, 13, 145, 218, 202, 127, 37, 97, 54, 205, 249, 39, 230, 143, 171, 112, 114, 11, 64, 91, 89, 176, 6, 7, 248, 217, 2, 65, 0, 220, 94, 95, 132, 29, 4, 132, 22, 247, 38, 185, 189, 125, 27, 66, 87, 55, 162, 73, 24, 238, 80, 99, 228, 37, 224, 234, 244, 141, 185, 26, 20, 101, 231, 92, 99, 192, 166, 212, 17, 112, 1, 158, 173, 190, 170, 154, 41, 195, 109, 130, 98, 109, 28, 35, 142, 205, 213, 152, 158, 19, 253, 30, 241, 2, 64, 15, 148, 8, 16, 189, 122, 55, 109, 203, 175, 173, 24, 222, 36, 130, 130, 179, 87, 189, 32, 141, 149, 30, 115, 211, 227, 79, 234, 78, 202, 253, 48, 173, 95, 167, 203, 20, 193, 160, 30, 146, 33, 109, 4, 221, 25, 212, 216, 183, 100, 18, 46, 184, 52, 65, 146, 249, 68, 225, 10, 84, 38, 98, 133])'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'ECDSA': {
|
|
||||||
keyUsages: ['sign', 'verify'],
|
|
||||||
length: function (len) {
|
|
||||||
return len || random.item([256, 384, 512])
|
|
||||||
},
|
|
||||||
alg: function (len) {
|
|
||||||
len = this.length(len)
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'ECDSA',
|
|
||||||
namedCurve: 'P-${len}',
|
|
||||||
hash: {
|
|
||||||
name: 'SHA-${len}'
|
|
||||||
}
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
jwk: function (len) {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
kty: 'EC',
|
|
||||||
alg: 'ES${this.length(len)}'
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
generateKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
importKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
sign: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
verify: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
presets: {
|
|
||||||
raw: {},
|
|
||||||
jwk: [
|
|
||||||
{
|
|
||||||
kty: 'EC',
|
|
||||||
crv: 'P-256',
|
|
||||||
x: 'A5fQnBdBSgBhTjMr1Atpzvh5SKYQ4aQRJ9WTCG5U4m4',
|
|
||||||
y: '8YF98byzMljHX3T5ORLYTDbcwG-_eq3f23JtTE6lOe0',
|
|
||||||
ext: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
kty: 'EC',
|
|
||||||
crv: 'P-256',
|
|
||||||
x: 'A5fQnBdBSgBhTjMr1Atpzvh5SKYQ4aQRJ9WTCG5U4m4',
|
|
||||||
y: '8YF98byzMljHX3T5ORLYTDbcwG-_eq3f23JtTE6lOe0',
|
|
||||||
d: '4DvC-hxpv8myZLNeMY-8nq55MhdfA4obM1lGG3hF_yo',
|
|
||||||
ext: true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
spki: 'new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, 3, 151, 208, 156, 23, 65, 74, 0, 97, 78, 51, 43, 212, 11, 105, 206, 248, 121, 72, 166, 16, 225, 164, 17, 39, 213, 147, 8, 110, 84, 226, 110, 241, 129, 125, 241, 188, 179, 50, 88, 199, 95, 116, 249, 57, 18, 216, 76, 54, 220, 192, 111, 191, 122, 173, 223, 219, 114, 109, 76, 78, 165, 57, 237])',
|
|
||||||
pkcs8: 'new Uint8Array([48, 129, 135, 2, 1, 0, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 4, 109, 48, 107, 2, 1, 1, 4, 32, 224, 59, 194, 250, 28, 105, 191, 201, 178, 100, 179, 94, 49, 143, 188, 158, 174, 121, 50, 23, 95, 3, 138, 27, 51, 89, 70, 27, 120, 69, 255, 42, 161, 68, 3, 66, 0, 4, 3, 151, 208, 156, 23, 65, 74, 0, 97, 78, 51, 43, 212, 11, 105, 206, 248, 121, 72, 166, 16, 225, 164, 17, 39, 213, 147, 8, 110, 84, 226, 110, 241, 129, 125, 241, 188, 179, 50, 88, 199, 95, 116, 249, 57, 18, 216, 76, 54, 220, 192, 111, 191, 122, 173, 223, 219, 114, 109, 76, 78, 165, 57, 237])'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'ECDH': {
|
|
||||||
keyUsages: ['deriveKey', 'deriveBits'],
|
|
||||||
length: function (len) {
|
|
||||||
return len || random.item([256, 384, 512])
|
|
||||||
},
|
|
||||||
alg: function (len) {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'ECDSA',
|
|
||||||
namedCurve: 'P-${this.length(len)}'
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
jwk: function () {
|
|
||||||
return {}
|
|
||||||
},
|
|
||||||
generateKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
importKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
deriveKey: function (key) {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'ECDSA',
|
|
||||||
namedCurve: 'P-${this.length()}',
|
|
||||||
${key}
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
deriveBits: function (key) {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'ECDSA',
|
|
||||||
namedCurve: 'P-${this.length()}',
|
|
||||||
${key}
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
presets: {
|
|
||||||
raw: {},
|
|
||||||
jwk: [
|
|
||||||
{
|
|
||||||
kty: 'EC',
|
|
||||||
crv: 'P-256',
|
|
||||||
x: 'kgR_PqO07L8sZOBbw6rvv7O_f7clqDeiE3WnMkb5EoI',
|
|
||||||
y: 'djI-XqCqSyO9GFk_QT_stROMCAROIvU8KOORBgQUemE',
|
|
||||||
ext: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
kty: 'EC',
|
|
||||||
crv: 'P-256',
|
|
||||||
x: 'kgR_PqO07L8sZOBbw6rvv7O_f7clqDeiE3WnMkb5EoI',
|
|
||||||
y: 'djI-XqCqSyO9GFk_QT_stROMCAROIvU8KOORBgQUemE',
|
|
||||||
d: '5aPFSt0UFVXYGu-ZKyC9FQIUOAMmnjzdIwkxCMe3Iok',
|
|
||||||
ext: true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
spki: 'new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, 146, 4, 127, 62, 163, 180, 236, 191, 44, 100, 224, 91, 195, 170, 239, 191, 179, 191, 127, 183, 37, 168, 55, 162, 19, 117, 167, 50, 70, 249, 18, 130, 118, 50, 62, 94, 160, 170, 75, 35, 189, 24, 89, 63, 65, 63, 236, 181, 19, 140, 8, 4, 78, 34, 245, 60, 40, 227, 145, 6, 4, 20, 122, 97])',
|
|
||||||
pkcs8: 'new Uint8Array([48, 129, 135, 2, 1, 0, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 4, 109, 48, 107, 2, 1, 1, 4, 32, 229, 163, 197, 74, 221, 20, 21, 85, 216, 26, 239, 153, 43, 32, 189, 21, 2, 20, 56, 3, 38, 158, 60, 221, 35, 9, 49, 8, 199, 183, 34, 137, 161, 68, 3, 66, 0, 4, 146, 4, 127, 62, 163, 180, 236, 191, 44, 100, 224, 91, 195, 170, 239, 191, 179, 191, 127, 183, 37, 168, 55, 162, 19, 117, 167, 50, 70, 249, 18, 130, 118, 50, 62, 94, 160, 170, 75, 35, 189, 24, 89, 63, 65, 63, 236, 181, 19, 140, 8, 4, 78, 34, 245, 60, 40, 227, 145, 6, 4, 20, 122, 97])'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'AES-CTR': {
|
|
||||||
// AES in Counter Mode.
|
|
||||||
keyUsages: ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey'],
|
|
||||||
length: function (len) {
|
|
||||||
return len || random.item([128, 192, 256])
|
|
||||||
},
|
|
||||||
alg: function (len) {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'AES-CTR',
|
|
||||||
length: '${this.length(len)}'
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
jwk: function (len) {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
kty: 'oct',
|
|
||||||
alg: 'A${this.length(len)}CTR'
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
generateKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
importKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
encrypt: function () {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'AES-CTR',
|
|
||||||
length: ${this.length()},
|
|
||||||
counter: new Uint8Array(16)
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
decrypt: function () {
|
|
||||||
return this.encrypt()
|
|
||||||
},
|
|
||||||
wrapKey: function () {
|
|
||||||
return this.encrypt()
|
|
||||||
},
|
|
||||||
unwrapKey: function () {
|
|
||||||
return this.encrypt()
|
|
||||||
},
|
|
||||||
presets: {
|
|
||||||
raw: 'new Uint8Array([122, 94, 39, 230, 46, 23, 151, 80, 131, 230, 3, 101, 80, 234, 143, 9, 251, 152, 229, 228, 89, 222, 31, 135, 214, 104, 55, 68, 67, 59, 5, 51])',
|
|
||||||
jwk: [
|
|
||||||
{
|
|
||||||
kty: 'oct',
|
|
||||||
k: 'Y0zt37HgOx-BY7SQjYVmrqhPkO44Ii2Jcb9yydUDPfE',
|
|
||||||
alg: 'A256CTR',
|
|
||||||
ext: true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
spki: {},
|
|
||||||
pkcs8: {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'AES-CBC': {
|
|
||||||
// AES in Cipher Block Chaining mode.
|
|
||||||
keyUsages: ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey'],
|
|
||||||
length: function (len) {
|
|
||||||
return len || random.item([128, 192, 256])
|
|
||||||
},
|
|
||||||
alg: function (len) {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'AES-CBC',
|
|
||||||
length: ${this.length(len)}
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
jwk: function (len) {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
kty: 'oct',
|
|
||||||
alg: 'A${this.length(len)}CBC'
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
generateKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
importKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
encrypt: function () {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'AES-CBC',
|
|
||||||
length: ${this.length()},
|
|
||||||
iv: crypto.getRandomValues(new Uint8Array(16))
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
decrypt: function () {
|
|
||||||
return this.encrypt()
|
|
||||||
},
|
|
||||||
wrapKey: function () {
|
|
||||||
return this.encrypt()
|
|
||||||
},
|
|
||||||
unwrapKey: function () {
|
|
||||||
return this.encrypt()
|
|
||||||
},
|
|
||||||
presets: {
|
|
||||||
raw: 'new Uint8Array([122, 94, 39, 230, 46, 23, 151, 80, 131, 230, 3, 101, 80, 234, 143, 9, 251, 152, 229, 228, 89, 222, 31, 135, 214, 104, 55, 68, 67, 59, 5, 51])',
|
|
||||||
jwk: [
|
|
||||||
{
|
|
||||||
kty: 'oct',
|
|
||||||
k: 'KfKY5nueRX7eBrOddn9IerHLv1r-T7qpggaCF3MfSR4',
|
|
||||||
alg: 'A256CBC',
|
|
||||||
ext: true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
spki: {},
|
|
||||||
pkcs8: {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'AES-GCM': {
|
|
||||||
// AES in Galois/Counter Mode.
|
|
||||||
keyUsages: ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey'],
|
|
||||||
length: function (len) {
|
|
||||||
return len || random.item([128, 192, 256])
|
|
||||||
},
|
|
||||||
alg: function (len) {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'AES-GCM',
|
|
||||||
length: ${this.length(len)}
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
jwk: function (len) {
|
|
||||||
if (random.chance(4)) {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
kty: 'oct',
|
|
||||||
alg: 'A${this.length(len)}GCMKW'
|
|
||||||
}`)
|
|
||||||
} else {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
kty: 'oct',
|
|
||||||
alg: 'A${this.length(len)}GCM'
|
|
||||||
}`)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
generateKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
importKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
encrypt: function () {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'AES-GCM',
|
|
||||||
iv: crypto.getRandomValues(new Uint8Array(12)),
|
|
||||||
additionalData: crypto.getRandomValues(new Uint8Array(256)),
|
|
||||||
tagLength: ${random.item([32, 64, 96, 104, 112, 120, 128])}
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
decrypt: function () {
|
|
||||||
return this.encrypt()
|
|
||||||
},
|
|
||||||
wrapKey: function () {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'AES-GCM',
|
|
||||||
iv: crypto.getRandomValues(new Uint8Array(16))
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
unwrapKey: function () {
|
|
||||||
return this.wrapKey()
|
|
||||||
},
|
|
||||||
presets: {
|
|
||||||
raw: 'new Uint8Array([122, 94, 39, 230, 46, 23, 151, 80, 131, 230, 3, 101, 80, 234, 143, 9, 251, 152, 229, 228, 89, 222, 31, 135, 214, 104, 55, 68, 67, 59, 5, 51])',
|
|
||||||
jwk: [
|
|
||||||
{
|
|
||||||
kty: 'oct',
|
|
||||||
k: 'KfKY5nueRX7eBrOddn9IerHLv1r-T7qpggaCF3MfSR4',
|
|
||||||
alg: 'A256GCM',
|
|
||||||
ext: true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
spki: {},
|
|
||||||
pkcs8: {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'AES-KW': {
|
|
||||||
// Key wrapping in AES algorithm.
|
|
||||||
keyUsages: ['wrapKey', 'unwrapKey'],
|
|
||||||
length: function (len) {
|
|
||||||
return len || random.item([128, 192, 256])
|
|
||||||
},
|
|
||||||
alg: function (len) {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'AES-KW',
|
|
||||||
length: ${this.length(len)}
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
jwk: function (len) {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
kty: 'oct',
|
|
||||||
alg: 'A${this.length(len)}KW'
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
generateKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
importKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
wrapKey: function () {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'AES-KW'
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
unwrapKey: function () {
|
|
||||||
return this.wrapKey()
|
|
||||||
},
|
|
||||||
presets: {
|
|
||||||
raw: 'new Uint8Array([122, 94, 39, 230, 46, 23, 151, 80, 131, 230, 3, 101, 80, 234, 143, 9, 251, 152, 229, 228, 89, 222, 31, 135, 214, 104, 55, 68, 67, 59, 5, 51])',
|
|
||||||
jwk: [
|
|
||||||
{
|
|
||||||
kty: 'oct',
|
|
||||||
k: 'KfKY5nueRX7eBrOddn9IerHLv1r-T7qpggaCF3MfSR4',
|
|
||||||
alg: 'A256KW',
|
|
||||||
ext: true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
spki: {},
|
|
||||||
pkcs8: {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'HMAC': {
|
|
||||||
// Hash-based message authentication method using SHA hash functions.
|
|
||||||
keyUsages: ['sign', 'verify'],
|
|
||||||
length: function (len) {
|
|
||||||
return len || random.item([1, 256, 384, 512])
|
|
||||||
},
|
|
||||||
alg: function (len) {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'HMAC',
|
|
||||||
hash: {
|
|
||||||
name: 'SHA-${this.length(len)}'
|
|
||||||
}
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
jwk: function (len) {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
kty: 'oct',
|
|
||||||
alg: 'HS${this.length(len)}'
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
generateKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
importKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
sign: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
verify: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
presets: {
|
|
||||||
raw: 'new Uint8Array([122, 94, 39, 230, 46, 23, 151, 80, 131, 230, 3, 101, 80, 234, 143, 9, 251, 152, 229, 228, 89, 222, 31, 135, 214, 104, 55, 68, 67, 59, 5, 51])',
|
|
||||||
jwk: {
|
|
||||||
kty: 'oct',
|
|
||||||
k: 'KfKY5nueRX7eBrOddn9IerHLv1r-T7qpggaCF3MfSR4',
|
|
||||||
alg: 'HS256',
|
|
||||||
ext: true
|
|
||||||
},
|
|
||||||
spki: {},
|
|
||||||
pkcs8: {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'HKDF': {
|
|
||||||
// Key derivation using the extraction-then-expansion approach and using the SHA hash functions.
|
|
||||||
keyUsages: ['deriveKey', 'deriveBits'],
|
|
||||||
alg: function () {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'HKDF'
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
jwk: function () {
|
|
||||||
return utils.common.mockup(`{}`)
|
|
||||||
},
|
|
||||||
generateKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
importKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
deriveBits: function () {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'HKDF',
|
|
||||||
hash: {
|
|
||||||
name: '${make.crypto.randomDigestName()}'
|
|
||||||
},
|
|
||||||
salt: crypto.getRandomValues(new Uint8Array(16)),
|
|
||||||
info: crypto.getRandomValues(new Uint8Array(16))
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
deriveKey: function () {
|
|
||||||
return this.deriveBits()
|
|
||||||
},
|
|
||||||
presets: {
|
|
||||||
raw: 'crypto.getRandomValues(new Uint8Array(16))',
|
|
||||||
jwk: {},
|
|
||||||
spki: {},
|
|
||||||
pkcs8: {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'PBKDF2': {
|
|
||||||
// Key derivation using the PKCS#5 password-based key derivation function v2.0.
|
|
||||||
keyUsages: ['deriveKey', 'deriveBits'],
|
|
||||||
alg: function () {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'PBKDF2'
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
jwk: function () {
|
|
||||||
return utils.common.mockup(`{}`)
|
|
||||||
},
|
|
||||||
generateKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
importKey: function () {
|
|
||||||
return this.alg()
|
|
||||||
},
|
|
||||||
deriveBits: function () {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'PBKDF2',
|
|
||||||
hash: {
|
|
||||||
name: '${make.crypto.randomDigestName()}'
|
|
||||||
},
|
|
||||||
salt: crypto.getRandomValues(new Uint8Array(16)),
|
|
||||||
iterations: ${random.number(1000)}
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
deriveKey: function () {
|
|
||||||
return this.deriveBits()
|
|
||||||
},
|
|
||||||
presets: {
|
|
||||||
raw: 'crypto.getRandomValues(new Uint8Array(16))',
|
|
||||||
jwk: {},
|
|
||||||
spki: {},
|
|
||||||
pkcs8: {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'DH': {
|
|
||||||
keyUsages: ['deriveKey', 'deriveBits'],
|
|
||||||
alg: function () {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'DH'
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
jwk: function () {
|
|
||||||
return utils.common.mockup(`{}`)
|
|
||||||
},
|
|
||||||
generateKey: function () {
|
|
||||||
return utils.common.mockup(`{
|
|
||||||
name: 'DH',
|
|
||||||
prime: new Uint8Array([255, 255, 255, 255, 255, 255, 255, 255, 201, 15, 218, 162, 33, 104, 194, 52, 196, 198, 98, 139, 128, 220, 28, 209, 41, 2, 78, 8, 138, 103, 204, 116, 2, 11, 190, 166, 59, 19, 155, 34, 81, 74, 8, 121, 142, 52, 4, 221, 239, 149, 25, 179, 205, 58, 67, 27, 48, 43, 10, 109, 242, 95, 20, 55, 79, 225, 53, 109, 109, 81, 194, 69, 228, 133, 181, 118, 98, 94, 126, 198, 244, 76, 66, 233, 166, 55, 237, 107, 11, 255, 92, 182, 244, 6, 183, 237, 238, 56, 107, 251, 90, 137, 159, 165, 174, 159, 36, 17, 124, 75, 31, 230, 73, 40, 102, 81, 236, 228, 91, 61, 194, 0, 124, 184, 161, 99, 191, 5, 152, 218, 72, 54, 28, 85, 211, 154, 105, 22, 63, 168, 253, 36, 207, 95, 131, 101, 93, 35, 220, 163, 173, 150, 28, 98, 243, 86, 32, 133, 82, 187, 158, 213, 41, 7, 112, 150, 150, 109, 103, 12, 53, 78, 74, 188, 152, 4, 241, 116, 108, 8, 202, 35, 115, 39, 255, 255, 255, 255, 255, 255, 255, 255]),
|
|
||||||
generator: new Uint8Array([2])
|
|
||||||
}`)
|
|
||||||
},
|
|
||||||
importKey: function () {
|
|
||||||
return this.generateKey()
|
|
||||||
},
|
|
||||||
deriveKey: function (key) {
|
|
||||||
// return Object.assign(this.generateKey(),key)
|
|
||||||
return utils.common.mockup(`
|
|
||||||
name: 'DH',
|
|
||||||
prime: new Uint8Array([255, 255, 255, 255, 255, 255, 255, 255, 201, 15, 218, 162, 33, 104, 194, 52, 196, 198, 98, 139, 128, 220, 28, 209, 41, 2, 78, 8, 138, 103, 204, 116, 2, 11, 190, 166, 59, 19, 155, 34, 81, 74, 8, 121, 142, 52, 4, 221, 239, 149, 25, 179, 205, 58, 67, 27, 48, 43, 10, 109, 242, 95, 20, 55, 79, 225, 53, 109, 109, 81, 194, 69, 228, 133, 181, 118, 98, 94, 126, 198, 244, 76, 66, 233, 166, 55, 237, 107, 11, 255, 92, 182, 244, 6, 183, 237, 238, 56, 107, 251, 90, 137, 159, 165, 174, 159, 36, 17, 124, 75, 31, 230, 73, 40, 102, 81, 236, 228, 91, 61, 194, 0, 124, 184, 161, 99, 191, 5, 152, 218, 72, 54, 28, 85, 211, 154, 105, 22, 63, 168, 253, 36, 207, 95, 131, 101, 93, 35, 220, 163, 173, 150, 28, 98, 243, 86, 32, 133, 82, 187, 158, 213, 41, 7, 112, 150, 150, 109, 103, 12, 53, 78, 74, 188, 152, 4, 241, 116, 108, 8, 202, 35, 115, 39, 255, 255, 255, 255, 255, 255, 255, 255]),
|
|
||||||
generator: new Uint8Array([2]),
|
|
||||||
${key}
|
|
||||||
`)
|
|
||||||
},
|
|
||||||
deriveBits: function (key) {
|
|
||||||
return utils.common.mockup(`
|
|
||||||
name: 'DH',
|
|
||||||
prime: new Uint8Array([255, 255, 255, 255, 255, 255, 255, 255, 201, 15, 218, 162, 33, 104, 194, 52, 196, 198, 98, 139, 128, 220, 28, 209, 41, 2, 78, 8, 138, 103, 204, 116, 2, 11, 190, 166, 59, 19, 155, 34, 81, 74, 8, 121, 142, 52, 4, 221, 239, 149, 25, 179, 205, 58, 67, 27, 48, 43, 10, 109, 242, 95, 20, 55, 79, 225, 53, 109, 109, 81, 194, 69, 228, 133, 181, 118, 98, 94, 126, 198, 244, 76, 66, 233, 166, 55, 237, 107, 11, 255, 92, 182, 244, 6, 183, 237, 238, 56, 107, 251, 90, 137, 159, 165, 174, 159, 36, 17, 124, 75, 31, 230, 73, 40, 102, 81, 236, 228, 91, 61, 194, 0, 124, 184, 161, 99, 191, 5, 152, 218, 72, 54, 28, 85, 211, 154, 105, 22, 63, 168, 253, 36, 207, 95, 131, 101, 93, 35, 220, 163, 173, 150, 28, 98, 243, 86, 32, 133, 82, 187, 158, 213, 41, 7, 112, 150, 150, 109, 103, 12, 53, 78, 74, 188, 152, 4, 241, 116, 108, 8, 202, 35, 115, 39, 255, 255, 255, 255, 255, 255, 255, 255]),
|
|
||||||
generator: new Uint8Array([2]),
|
|
||||||
${key}
|
|
||||||
`)
|
|
||||||
},
|
|
||||||
presets: {
|
|
||||||
raw: {},
|
|
||||||
jwk: {},
|
|
||||||
spki: {},
|
|
||||||
pkcs8: {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static supportedAlgorithms () {
|
|
||||||
Object.keys(make.crypto.algorithms)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomAlgorithm () {
|
|
||||||
return make.crypto.algorithms[random.item(Object.keys(make.crypto.algorithms))]
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomCandidate (operation) {
|
|
||||||
// Find and return a random algorithm suitable for a given operation.
|
|
||||||
return make.crypto.algorithms[make.crypto.randomAlgorithmName(operation)]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = crypto
|
|
891
lib/make/crypto.ts
Normal file
891
lib/make/crypto.ts
Normal file
|
@ -0,0 +1,891 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
import random from "../random/random.ts";
|
||||||
|
|
||||||
|
const mockup = obj =>
|
||||||
|
obj
|
||||||
|
.split("\n")
|
||||||
|
.map(ln => ln.trim())
|
||||||
|
.join("");
|
||||||
|
|
||||||
|
export default class crypto {
|
||||||
|
static get keyFormats() {
|
||||||
|
return ["raw", "spki", "pkcs8", "jwk"];
|
||||||
|
}
|
||||||
|
static randomKeyFormat() {
|
||||||
|
return random.item(crypto.keyFormats);
|
||||||
|
}
|
||||||
|
|
||||||
|
static get keyTypes() {
|
||||||
|
return ["public", "private", "secret"];
|
||||||
|
}
|
||||||
|
static randomKeyType() {
|
||||||
|
return random.item(crypto.keyTypes);
|
||||||
|
}
|
||||||
|
|
||||||
|
static get keyUsages() {
|
||||||
|
return [
|
||||||
|
"encrypt",
|
||||||
|
"decrypt",
|
||||||
|
"sign",
|
||||||
|
"verify",
|
||||||
|
"deriveKey",
|
||||||
|
"deriveBits",
|
||||||
|
"wrapKey",
|
||||||
|
"unwrapKey"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomKeyUsage() {
|
||||||
|
return random.subset(crypto.keyUsages);
|
||||||
|
}
|
||||||
|
|
||||||
|
static get curves() {
|
||||||
|
return ["P-256", "P-384", "P-521"];
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomCurve() {
|
||||||
|
return random.item(crypto.curves);
|
||||||
|
}
|
||||||
|
|
||||||
|
static get jwkUsages() {
|
||||||
|
return ["enc", "sig"];
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomJwkUsage() {
|
||||||
|
return random.subset(crypto.keyUsages);
|
||||||
|
}
|
||||||
|
|
||||||
|
static get jwkKeyTypes() {
|
||||||
|
return ["oct", "RSA", "EC"];
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomJwkKeyType() {
|
||||||
|
return random.subset(crypto.jwkKeyTypes);
|
||||||
|
}
|
||||||
|
|
||||||
|
static get algorithmNames() {
|
||||||
|
// https://www.w3.org/TR/WebCryptoAPI/#algorithm-overview
|
||||||
|
return {
|
||||||
|
sign: ["RSASSA-PKCS1-v1_5", "RSA-PSS", "ECDSA", "HMAC"],
|
||||||
|
verify: ["RSASSA-PKCS1-v1_5", "RSA-PSS", "ECDSA", "HMAC"],
|
||||||
|
generateKey: [
|
||||||
|
"RSASSA-PKCS1-v1_5",
|
||||||
|
"RSA-PSS",
|
||||||
|
"RSA-OAEP",
|
||||||
|
"ECDSA",
|
||||||
|
"ECDH",
|
||||||
|
"AES-CTR",
|
||||||
|
"AES-CBC",
|
||||||
|
"AES-GCM",
|
||||||
|
"AES-KW",
|
||||||
|
"HMAC"
|
||||||
|
],
|
||||||
|
importKey: [
|
||||||
|
"RSASSA-PKCS1-v1_5",
|
||||||
|
"RSA-PSS",
|
||||||
|
"RSA-OAEP",
|
||||||
|
"ECDSA",
|
||||||
|
"ECDH",
|
||||||
|
"AES-CTR",
|
||||||
|
"AES-CBC",
|
||||||
|
"AES-GCM",
|
||||||
|
"AES-KW",
|
||||||
|
"HMAC",
|
||||||
|
"HKDF",
|
||||||
|
"PBKDF2"
|
||||||
|
],
|
||||||
|
exportKey: [
|
||||||
|
"RSASSA-PKCS1-v1_5",
|
||||||
|
"RSA-PSS",
|
||||||
|
"RSA-OAEP",
|
||||||
|
"ECDSA",
|
||||||
|
"ECDH",
|
||||||
|
"AES-CTR",
|
||||||
|
"AES-CBC",
|
||||||
|
"AES-GCM",
|
||||||
|
"AES-KW",
|
||||||
|
"HMAC"
|
||||||
|
],
|
||||||
|
encrypt: ["RSA-OAEP", "AES-CTR", "AES-CBC", "AES-GCM"],
|
||||||
|
decrypt: ["RSA-OAEP", "AES-CTR", "AES-CBC", "AES-GCM"],
|
||||||
|
deriveBits: ["ECDH", "HKDF", "PBKDF2"],
|
||||||
|
deriveKey: ["ECDH", "HKDF", "PBKDF2"],
|
||||||
|
wrapKey: ["RSA-OAEP", "AES-CTR", "AES-CBC", "AES-GCM", "AES-KW"],
|
||||||
|
unwrapKey: ["RSA-OAEP", "AES-CTR", "AES-CBC", "AES-GCM", "AES-KW"],
|
||||||
|
digest: ["SHA-1", "SHA-256", "SHA-384", "SHA-512"]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomAlgorithmName(method: string) {
|
||||||
|
return random.item(crypto.algorithmNames[method] as string[]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomDigestName() {
|
||||||
|
return random.item(crypto.algorithmNames.digest);
|
||||||
|
}
|
||||||
|
|
||||||
|
static get algorithms() {
|
||||||
|
return {
|
||||||
|
/* (Unsupported as of 30/01/2017)
|
||||||
|
-------------------------------
|
||||||
|
| | Firefox | Chrome |
|
||||||
|
----------------------------- |
|
||||||
|
| AES-CMAC | x | x |
|
||||||
|
| AES-CFB | x | x |
|
||||||
|
| CONCAT | x | x |
|
||||||
|
| HKDF-CTR | x | x |
|
||||||
|
| DH | | x |
|
||||||
|
-------------------------------
|
||||||
|
*/
|
||||||
|
"RSASSA-PKCS1-v1_5": {
|
||||||
|
// RSASA-PKCS1_v1_5 algorithm, using a SHA hash function.
|
||||||
|
keyUsages: ["sign", "verify"],
|
||||||
|
length: function(len) {
|
||||||
|
return len || random.item([1, 256, 384, 512]);
|
||||||
|
},
|
||||||
|
alg: function(len) {
|
||||||
|
return mockup(`{
|
||||||
|
name: 'RSASSA-PKCS1-v1_5',
|
||||||
|
hash: {
|
||||||
|
name: 'SHA-${this.length(len)}'
|
||||||
|
},
|
||||||
|
modulusLength: ${random.item([1024, 2048, 4096])},
|
||||||
|
publicExponent: new Uint8Array([0x01, 0x00, 0x01])
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
jwk: function(len) {
|
||||||
|
return mockup(`{
|
||||||
|
kty: 'RSA',
|
||||||
|
alg: 'RS${this.length(len)}'
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
generateKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
importKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
sign: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
verify: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
presets: {
|
||||||
|
raw: {},
|
||||||
|
jwk: [
|
||||||
|
{
|
||||||
|
kty: "RSA",
|
||||||
|
e: "AQAB",
|
||||||
|
n:
|
||||||
|
"vGO3eU16ag9zRkJ4AK8ZUZrjbtp5xWK0LyFMNT8933evJoHeczexMUzSiXaLrEFSyQZortk81zJH3y41MBO_UFDO_X0crAquNrkjZDrf9Scc5-MdxlWU2Jl7Gc4Z18AC9aNibWVmXhgvHYkEoFdLCFG-2Sq-qIyW4KFkjan05IE",
|
||||||
|
alg: "RS256",
|
||||||
|
ext: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
kty: "RSA",
|
||||||
|
e: "AQAB",
|
||||||
|
d:
|
||||||
|
"n_dIVw9MD_04lANi5KnKJPoRfxKy7cGHYLG0hU5DGpsFNfx2yH0Uz9j8uU7ZARai1iHECBxcxhpi3wbckQtjmbkCUKvs4G0gKLT9UuNHcCbh0WfvadfPPec52n4z6s4zwisbgWCNbT2L-SyHt1yuFmLAYXkg0swk3y5Bt_ilA8E",
|
||||||
|
dp:
|
||||||
|
"2RNM_uiYEQMcATQaUu3AwdeJpenCPykbQHkwAylvXqlHB6W7m5XX0k-SutkbXAijmGTC-Oh8NexsLGHxOACb8Q",
|
||||||
|
dq:
|
||||||
|
"rHabkI3_XVGieLqHujpWaWe9YD03fJY0KbbQX0fIoNdNU4GcmUftzIWLSajPKKsiyfR6Xk2AEtBmBPE5qaoV6Q",
|
||||||
|
n:
|
||||||
|
"vGO3eU16ag9zRkJ4AK8ZUZrjbtp5xWK0LyFMNT8933evJoHeczexMUzSiXaLrEFSyQZortk81zJH3y41MBO_UFDO_X0crAquNrkjZDrf9Scc5-MdxlWU2Jl7Gc4Z18AC9aNibWVmXhgvHYkEoFdLCFG-2Sq-qIyW4KFkjan05IE",
|
||||||
|
p:
|
||||||
|
"5Y4ynodegqC9kgGmfZeSrojGmLyYR8HIvKVEAIjjMUQjyvKWpWsXfPg67mTdqVpjSpQLQlRfES2nUvZ27KrU6Q",
|
||||||
|
q:
|
||||||
|
"0hd_U9PcNpMe77nhsTgoVNgMB34cqfrfu4fPuJ-7NvvMkKIELDLy-m8qg1MBbgf2i5546A9B5Exsuj4D2Vwz2Q",
|
||||||
|
qi:
|
||||||
|
"R3CkCGVAESy_hChmDvUaLMT-R1xk6kK7RLIUQKXATPQbnDqWBMgm-vcawFVhKJ-ICJsPfmRUsv7Wt1bJ01wLGQ",
|
||||||
|
alg: "RS256",
|
||||||
|
ext: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
spki:
|
||||||
|
"new Uint8Array([48, 129, 159, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 3, 129, 141, 0, 48, 129, 137, 2, 129, 129, 0, 182, 93, 35, 213, 252, 204, 20, 103, 91, 238, 105, 199, 53, 114, 24, 221, 114, 210, 137, 173, 88, 76, 205, 113, 148, 148, 79, 80, 59, 208, 60, 75, 231, 248, 78, 125, 12, 30, 237, 226, 63, 146, 157, 203, 239, 60, 138, 123, 234, 50, 23, 174, 216, 33, 122, 16, 53, 246, 140, 254, 75, 246, 205, 204, 117, 204, 115, 29, 178, 102, 139, 201, 74, 177, 45, 131, 183, 166, 234, 61, 124, 75, 110, 3, 70, 202, 148, 95, 45, 228, 94, 95, 148, 2, 162, 79, 146, 137, 29, 189, 102, 75, 207, 214, 116, 58, 63, 171, 219, 27, 5, 9, 108, 16, 218, 23, 169, 43, 181, 119, 31, 172, 95, 205, 180, 18, 255, 203, 2, 3, 1, 0, 1])",
|
||||||
|
pkcs8:
|
||||||
|
"new Uint8Array([48, 130, 2, 118, 2, 1, 0, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 4, 130, 2, 96, 48, 130, 2, 92, 2, 1, 0, 2, 129, 129, 0, 217, 78, 147, 218, 221, 152, 10, 66, 75, 127, 242, 108, 182, 142, 157, 44, 93, 58, 176, 193, 135, 103, 216, 179, 69, 72, 38, 115, 144, 244, 12, 139, 0, 245, 48, 115, 204, 234, 158, 193, 231, 127, 178, 240, 244, 203, 35, 229, 203, 245, 110, 215, 199, 19, 98, 183, 164, 223, 159, 203, 128, 123, 173, 26, 12, 172, 250, 99, 254, 35, 225, 221, 39, 51, 62, 3, 139, 35, 38, 164, 71, 238, 240, 73, 139, 214, 68, 172, 204, 253, 171, 244, 14, 186, 152, 159, 225, 133, 229, 140, 99, 50, 183, 242, 217, 248, 86, 233, 20, 117, 42, 136, 55, 8, 65, 124, 244, 65, 29, 15, 194, 255, 78, 31, 189, 146, 105, 161, 2, 3, 1, 0, 1, 2, 129, 128, 26, 88, 13, 82, 166, 52, 141, 97, 214, 23, 79, 195, 96, 42, 79, 225, 149, 247, 204, 127, 217, 179, 124, 48, 215, 128, 84, 177, 3, 236, 162, 44, 163, 212, 21, 168, 164, 57, 249, 63, 22, 154, 131, 141, 244, 143, 63, 237, 214, 217, 13, 51, 249, 125, 95, 37, 86, 70, 137, 239, 184, 198, 197, 136, 62, 183, 41, 78, 118, 234, 57, 195, 161, 219, 173, 234, 61, 11, 165, 109, 209, 9, 3, 22, 186, 114, 32, 135, 147, 74, 6, 106, 190, 214, 36, 208, 32, 220, 61, 12, 41, 105, 251, 247, 18, 159, 3, 198, 28, 228, 36, 44, 189, 125, 45, 72, 233, 199, 12, 72, 91, 106, 165, 246, 217, 58, 168, 53, 2, 65, 0, 241, 112, 53, 166, 98, 11, 38, 73, 58, 156, 84, 190, 118, 74, 247, 229, 85, 178, 83, 231, 53, 137, 237, 228, 246, 12, 32, 206, 157, 198, 152, 70, 11, 185, 234, 30, 112, 23, 115, 249, 68, 176, 159, 108, 247, 249, 207, 152, 145, 166, 246, 79, 176, 219, 163, 111, 243, 4, 49, 3, 239, 242, 63, 147, 2, 65, 0, 230, 105, 200, 1, 208, 201, 237, 225, 85, 27, 39, 216, 193, 1, 253, 168, 88, 15, 242, 166, 70, 106, 235, 2, 92, 24, 130, 66, 176, 176, 220, 238, 66, 12, 159, 26, 24, 40, 19, 213, 138, 98, 238, 98, 220, 65, 148, 116, 146, 21, 0, 25, 6, 177, 57, 216, 70, 51, 149, 244, 157, 153, 106, 123, 2, 64, 127, 92, 254, 48, 67, 80, 54, 102, 50, 240, 253, 19, 108, 59, 168, 1, 230, 239, 39, 171, 180, 102, 138, 132, 89, 247, 147, 230, 234, 252, 52, 159, 222, 215, 184, 85, 78, 52, 81, 13, 145, 218, 202, 127, 37, 97, 54, 205, 249, 39, 230, 143, 171, 112, 114, 11, 64, 91, 89, 176, 6, 7, 248, 217, 2, 65, 0, 220, 94, 95, 132, 29, 4, 132, 22, 247, 38, 185, 189, 125, 27, 66, 87, 55, 162, 73, 24, 238, 80, 99, 228, 37, 224, 234, 244, 141, 185, 26, 20, 101, 231, 92, 99, 192, 166, 212, 17, 112, 1, 158, 173, 190, 170, 154, 41, 195, 109, 130, 98, 109, 28, 35, 142, 205, 213, 152, 158, 19, 253, 30, 241, 2, 64, 15, 148, 8, 16, 189, 122, 55, 109, 203, 175, 173, 24, 222, 36, 130, 130, 179, 87, 189, 32, 141, 149, 30, 115, 211, 227, 79, 234, 78, 202, 253, 48, 173, 95, 167, 203, 20, 193, 160, 30, 146, 33, 109, 4, 221, 25, 212, 216, 183, 100, 18, 46, 184, 52, 65, 146, 249, 68, 225, 10, 84, 38, 98, 133])"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"RSA-PSS": {
|
||||||
|
keyUsages: ["sign", "verify"],
|
||||||
|
length: function(len) {
|
||||||
|
return len || random.item([1, 256, 384, 512]);
|
||||||
|
},
|
||||||
|
alg: function(len) {
|
||||||
|
return mockup(`{
|
||||||
|
name: 'RSA-PSS',
|
||||||
|
hash: {
|
||||||
|
name: 'SHA-${this.length(len)}'
|
||||||
|
},
|
||||||
|
modulusLength: ${random.item([1024, 2048, 4096])},
|
||||||
|
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
|
||||||
|
saltLength: 8
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
jwk: function(len) {
|
||||||
|
return mockup(`{
|
||||||
|
kty: 'RSA',
|
||||||
|
alg: 'PS${this.length(len)}'
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
generateKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
importKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
sign: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
verify: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
presets: {
|
||||||
|
raw: {},
|
||||||
|
jwk: [
|
||||||
|
{
|
||||||
|
kty: "RSA",
|
||||||
|
e: "AQAB",
|
||||||
|
n:
|
||||||
|
"vGO3eU16ag9zRkJ4AK8ZUZrjbtp5xWK0LyFMNT8933evJoHeczexMUzSiXaLrEFSyQZortk81zJH3y41MBO_UFDO_X0crAquNrkjZDrf9Scc5-MdxlWU2Jl7Gc4Z18AC9aNibWVmXhgvHYkEoFdLCFG-2Sq-qIyW4KFkjan05IE",
|
||||||
|
alg: "RS256",
|
||||||
|
ext: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
kty: "RSA",
|
||||||
|
e: "AQAB",
|
||||||
|
d:
|
||||||
|
"n_dIVw9MD_04lANi5KnKJPoRfxKy7cGHYLG0hU5DGpsFNfx2yH0Uz9j8uU7ZARai1iHECBxcxhpi3wbckQtjmbkCUKvs4G0gKLT9UuNHcCbh0WfvadfPPec52n4z6s4zwisbgWCNbT2L-SyHt1yuFmLAYXkg0swk3y5Bt_ilA8E",
|
||||||
|
dp:
|
||||||
|
"2RNM_uiYEQMcATQaUu3AwdeJpenCPykbQHkwAylvXqlHB6W7m5XX0k-SutkbXAijmGTC-Oh8NexsLGHxOACb8Q",
|
||||||
|
dq:
|
||||||
|
"rHabkI3_XVGieLqHujpWaWe9YD03fJY0KbbQX0fIoNdNU4GcmUftzIWLSajPKKsiyfR6Xk2AEtBmBPE5qaoV6Q",
|
||||||
|
n:
|
||||||
|
"vGO3eU16ag9zRkJ4AK8ZUZrjbtp5xWK0LyFMNT8933evJoHeczexMUzSiXaLrEFSyQZortk81zJH3y41MBO_UFDO_X0crAquNrkjZDrf9Scc5-MdxlWU2Jl7Gc4Z18AC9aNibWVmXhgvHYkEoFdLCFG-2Sq-qIyW4KFkjan05IE",
|
||||||
|
p:
|
||||||
|
"5Y4ynodegqC9kgGmfZeSrojGmLyYR8HIvKVEAIjjMUQjyvKWpWsXfPg67mTdqVpjSpQLQlRfES2nUvZ27KrU6Q",
|
||||||
|
q:
|
||||||
|
"0hd_U9PcNpMe77nhsTgoVNgMB34cqfrfu4fPuJ-7NvvMkKIELDLy-m8qg1MBbgf2i5546A9B5Exsuj4D2Vwz2Q",
|
||||||
|
qi:
|
||||||
|
"R3CkCGVAESy_hChmDvUaLMT-R1xk6kK7RLIUQKXATPQbnDqWBMgm-vcawFVhKJ-ICJsPfmRUsv7Wt1bJ01wLGQ",
|
||||||
|
alg: "PS256",
|
||||||
|
ext: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
spki:
|
||||||
|
"new Uint8Array([48, 129, 159, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 3, 129, 141, 0, 48, 129, 137, 2, 129, 129, 0, 180, 31, 227, 200, 37, 227, 65, 238, 23, 91, 226, 130, 51, 32, 165, 245, 1, 24, 244, 5, 184, 42, 181, 155, 23, 142, 249, 220, 222, 131, 175, 54, 117, 135, 64, 232, 120, 90, 160, 221, 18, 31, 200, 41, 23, 174, 18, 172, 247, 166, 90, 37, 156, 229, 2, 70, 169, 165, 93, 246, 120, 117, 59, 202, 3, 102, 44, 119, 154, 54, 28, 198, 111, 39, 144, 73, 69, 251, 179, 74, 41, 215, 115, 186, 124, 200, 105, 75, 104, 158, 156, 158, 238, 214, 14, 81, 95, 130, 155, 146, 114, 125, 88, 158, 212, 44, 65, 236, 228, 194, 105, 96, 211, 155, 60, 71, 134, 90, 151, 202, 68, 20, 228, 105, 249, 202, 170, 155, 2, 3, 1, 0, 1])",
|
||||||
|
plcs8:
|
||||||
|
"new Uint8Array([48, 130, 2, 119, 2, 1, 0, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 4, 130, 2, 97, 48, 130, 2, 93, 2, 1, 0, 2, 129, 129, 0, 180, 31, 227, 200, 37, 227, 65, 238, 23, 91, 226, 130, 51, 32, 165, 245, 1, 24, 244, 5, 184, 42, 181, 155, 23, 142, 249, 220, 222, 131, 175, 54, 117, 135, 64, 232, 120, 90, 160, 221, 18, 31, 200, 41, 23, 174, 18, 172, 247, 166, 90, 37, 156, 229, 2, 70, 169, 165, 93, 246, 120, 117, 59, 202, 3, 102, 44, 119, 154, 54, 28, 198, 111, 39, 144, 73, 69, 251, 179, 74, 41, 215, 115, 186, 124, 200, 105, 75, 104, 158, 156, 158, 238, 214, 14, 81, 95, 130, 155, 146, 114, 125, 88, 158, 212, 44, 65, 236, 228, 194, 105, 96, 211, 155, 60, 71, 134, 90, 151, 202, 68, 20, 228, 105, 249, 202, 170, 155, 2, 3, 1, 0, 1, 2, 129, 128, 102, 251, 236, 161, 220, 119, 168, 148, 86, 42, 164, 192, 200, 54, 156, 108, 14, 42, 148, 42, 72, 247, 178, 73, 112, 24, 192, 230, 245, 25, 217, 45, 139, 216, 190, 213, 171, 42, 53, 218, 239, 167, 216, 43, 22, 108, 226, 36, 158, 155, 47, 227, 93, 102, 217, 252, 72, 182, 81, 152, 191, 154, 87, 137, 219, 194, 236, 53, 200, 123, 61, 10, 59, 231, 41, 18, 116, 77, 148, 50, 170, 116, 221, 110, 170, 190, 158, 108, 217, 38, 73, 84, 183, 51, 122, 179, 217, 143, 255, 87, 82, 80, 223, 188, 84, 134, 146, 150, 169, 64, 30, 168, 104, 8, 123, 162, 46, 59, 47, 232, 0, 35, 202, 42, 195, 141, 6, 1, 2, 65, 0, 237, 171, 148, 110, 241, 19, 152, 216, 206, 77, 109, 215, 21, 144, 110, 96, 34, 61, 46, 214, 148, 70, 238, 119, 206, 128, 32, 24, 136, 197, 185, 254, 209, 35, 235, 231, 122, 246, 167, 183, 117, 176, 51, 133, 169, 47, 130, 178, 40, 225, 145, 219, 48, 56, 21, 46, 198, 18, 85, 218, 194, 150, 141, 27, 2, 65, 0, 194, 4, 41, 152, 43, 246, 147, 7, 229, 244, 215, 110, 143, 7, 184, 187, 22, 166, 113, 217, 81, 52, 205, 54, 73, 202, 244, 24, 24, 219, 254, 243, 230, 230, 212, 172, 225, 218, 112, 95, 118, 103, 144, 223, 248, 164, 19, 228, 204, 204, 64, 91, 76, 77, 4, 206, 89, 173, 154, 162, 134, 113, 176, 129, 2, 64, 58, 4, 78, 97, 158, 155, 200, 13, 244, 158, 86, 23, 208, 253, 198, 211, 212, 199, 214, 173, 46, 216, 249, 209, 105, 41, 65, 172, 123, 134, 184, 214, 137, 59, 25, 149, 18, 33, 47, 227, 202, 232, 206, 74, 236, 119, 218, 145, 159, 5, 33, 83, 190, 59, 146, 128, 46, 125, 191, 83, 125, 120, 190, 205, 2, 65, 0, 134, 6, 204, 25, 20, 29, 180, 250, 90, 207, 229, 214, 185, 53, 211, 86, 98, 210, 62, 137, 170, 128, 120, 86, 205, 105, 71, 112, 50, 20, 31, 174, 171, 206, 192, 18, 97, 191, 61, 171, 164, 166, 236, 188, 220, 13, 180, 180, 117, 9, 144, 87, 193, 128, 223, 22, 17, 123, 76, 252, 131, 53, 156, 129, 2, 65, 0, 178, 29, 141, 176, 179, 203, 180, 190, 224, 34, 134, 226, 151, 73, 139, 163, 47, 17, 179, 117, 167, 200, 255, 174, 67, 114, 158, 96, 195, 176, 163, 241, 96, 24, 72, 35, 38, 18, 132, 176, 76, 235, 8, 29, 225, 138, 155, 191, 97, 158, 3, 22, 114, 133, 176, 213, 207, 120, 33, 55, 52, 135, 79, 161])"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"RSA-OAEP": {
|
||||||
|
// RSAES-OAEP algorithm using a SHA hash functions and a MGF1 mask generating function.
|
||||||
|
keyUsages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"],
|
||||||
|
length: function(len) {
|
||||||
|
return len || random.item([1, 256, 384, 512]);
|
||||||
|
},
|
||||||
|
alg: function(len) {
|
||||||
|
return mockup(`{
|
||||||
|
name: 'RSA-OAEP',
|
||||||
|
hash: {
|
||||||
|
name: 'SHA-${this.length(len)}'
|
||||||
|
},
|
||||||
|
modulusLength: ${random.item([1024, 2048, 4096])},
|
||||||
|
publicExponent: new Uint8Array([0x01, 0x00, 0x01])
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
jwk: function(len) {
|
||||||
|
return mockup(`{
|
||||||
|
kty: 'RSA',
|
||||||
|
alg: 'RSA-OAEP-${this.length(len)}'
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
generateKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
importKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
encrypt: function() {
|
||||||
|
return mockup(`{
|
||||||
|
name: 'RSA-OAEP',
|
||||||
|
hash: {
|
||||||
|
name: 'SHA-${this.length()}'
|
||||||
|
},
|
||||||
|
modulusLength: ${random.item([1024, 2048, 4096])},
|
||||||
|
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
|
||||||
|
label: crypto.getRandomValues(new Uint8Array(16))
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
decrypt: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
unwrapKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
wrapKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
presets: {
|
||||||
|
raw: {},
|
||||||
|
jkw: [
|
||||||
|
{
|
||||||
|
kty: "RSA",
|
||||||
|
e: "AQAB",
|
||||||
|
n:
|
||||||
|
"vGO3eU16ag9zRkJ4AK8ZUZrjbtp5xWK0LyFMNT8933evJoHeczexMUzSiXaLrEFSyQZortk81zJH3y41MBO_UFDO_X0crAquNrkjZDrf9Scc5-MdxlWU2Jl7Gc4Z18AC9aNibWVmXhgvHYkEoFdLCFG-2Sq-qIyW4KFkjan05IE",
|
||||||
|
alg: "RSA-OAEP-256",
|
||||||
|
ext: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
kty: "RSA",
|
||||||
|
e: "AQAB",
|
||||||
|
d:
|
||||||
|
"e-Nm1CB_F7j0p4Cb-T4WmFTh7RbxUthC3j8xnlXwHgWYwaPs9ZRkicgNCfmjEb-qJ-m0ho1Cz4WzlL1CtTKEdr2w0P6L_IQPvWkFYwUm0rpY9doxnOKkzq53dhP5zdc6N8aOLk4cmAcVjw4o_csc85H-0fxzQxsTP0_jhJn7SNE",
|
||||||
|
dp:
|
||||||
|
"JuZmXNBY9uGGfx3w3ysmFumGBLooNjMwwgMduVS6T8S-0tZkBU-iwJPzXAkKhwINEv1EnygjwmJLBdoHROeEeQ",
|
||||||
|
dq:
|
||||||
|
"KaKOFHxm9104WNwqTth04O9ogaDz_W0wkeHnxOxbWgdtFxsarnImiMlI3Hphv9JuHD5awzNAkaj9P7wDVew-5Q",
|
||||||
|
n:
|
||||||
|
"x-Do39ky8RVFrFplFfAuOQGLr-rqY3h9OiNHVMe34LoVG4Aofps11ycyw5ka3Ls_yA-oRouGmaMjaiPUoaU_Lm5-CMSoVwyeANLZ4b2S7V-srXFS-Qpe6aD7NpzoUL9knwTnZFIGZlxSXB-NXL5kq18UuO1LQGe1To16ijXKNxc",
|
||||||
|
p:
|
||||||
|
"4ss3ZAQMdmOk1BRQXwM9YHAoxVDkHDnSV9u89tUb3RbPXlV3fLlhRYtZ7u3FYaTzy08s8Ty2hV1KZ7xXhKEtuQ",
|
||||||
|
q:
|
||||||
|
"4Z5ejmIJTwsgxN5pI6mLxwXqQwFDERYDnwU9_vyToWXMEPAphWpS9ET00YrdHsgIGao1Slc0jp4OUxaLfhtzTw",
|
||||||
|
qi:
|
||||||
|
"R1aKNnhUiTjoCHfOVHZ6Qv5R7So-F5mtjDKCBvCi8190U3E25DiKRvDqHZ0bHMRbdQPLLknxHVnuETw6gddHUg",
|
||||||
|
alg: "RSA-OAEP-256",
|
||||||
|
ext: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
spki:
|
||||||
|
"new Uint8Array([48, 129, 159, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 3, 129, 141, 0, 48, 129, 137, 2, 129, 129, 0, 182, 93, 35, 213, 252, 204, 20, 103, 91, 238, 105, 199, 53, 114, 24, 221, 114, 210, 137, 173, 88, 76, 205, 113, 148, 148, 79, 80, 59, 208, 60, 75, 231, 248, 78, 125, 12, 30, 237, 226, 63, 146, 157, 203, 239, 60, 138, 123, 234, 50, 23, 174, 216, 33, 122, 16, 53, 246, 140, 254, 75, 246, 205, 204, 117, 204, 115, 29, 178, 102, 139, 201, 74, 177, 45, 131, 183, 166, 234, 61, 124, 75, 110, 3, 70, 202, 148, 95, 45, 228, 94, 95, 148, 2, 162, 79, 146, 137, 29, 189, 102, 75, 207, 214, 116, 58, 63, 171, 219, 27, 5, 9, 108, 16, 218, 23, 169, 43, 181, 119, 31, 172, 95, 205, 180, 18, 255, 203, 2, 3, 1, 0, 1])",
|
||||||
|
pkcs8:
|
||||||
|
"new Uint8Array([48, 130, 2, 118, 2, 1, 0, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 4, 130, 2, 96, 48, 130, 2, 92, 2, 1, 0, 2, 129, 129, 0, 217, 78, 147, 218, 221, 152, 10, 66, 75, 127, 242, 108, 182, 142, 157, 44, 93, 58, 176, 193, 135, 103, 216, 179, 69, 72, 38, 115, 144, 244, 12, 139, 0, 245, 48, 115, 204, 234, 158, 193, 231, 127, 178, 240, 244, 203, 35, 229, 203, 245, 110, 215, 199, 19, 98, 183, 164, 223, 159, 203, 128, 123, 173, 26, 12, 172, 250, 99, 254, 35, 225, 221, 39, 51, 62, 3, 139, 35, 38, 164, 71, 238, 240, 73, 139, 214, 68, 172, 204, 253, 171, 244, 14, 186, 152, 159, 225, 133, 229, 140, 99, 50, 183, 242, 217, 248, 86, 233, 20, 117, 42, 136, 55, 8, 65, 124, 244, 65, 29, 15, 194, 255, 78, 31, 189, 146, 105, 161, 2, 3, 1, 0, 1, 2, 129, 128, 26, 88, 13, 82, 166, 52, 141, 97, 214, 23, 79, 195, 96, 42, 79, 225, 149, 247, 204, 127, 217, 179, 124, 48, 215, 128, 84, 177, 3, 236, 162, 44, 163, 212, 21, 168, 164, 57, 249, 63, 22, 154, 131, 141, 244, 143, 63, 237, 214, 217, 13, 51, 249, 125, 95, 37, 86, 70, 137, 239, 184, 198, 197, 136, 62, 183, 41, 78, 118, 234, 57, 195, 161, 219, 173, 234, 61, 11, 165, 109, 209, 9, 3, 22, 186, 114, 32, 135, 147, 74, 6, 106, 190, 214, 36, 208, 32, 220, 61, 12, 41, 105, 251, 247, 18, 159, 3, 198, 28, 228, 36, 44, 189, 125, 45, 72, 233, 199, 12, 72, 91, 106, 165, 246, 217, 58, 168, 53, 2, 65, 0, 241, 112, 53, 166, 98, 11, 38, 73, 58, 156, 84, 190, 118, 74, 247, 229, 85, 178, 83, 231, 53, 137, 237, 228, 246, 12, 32, 206, 157, 198, 152, 70, 11, 185, 234, 30, 112, 23, 115, 249, 68, 176, 159, 108, 247, 249, 207, 152, 145, 166, 246, 79, 176, 219, 163, 111, 243, 4, 49, 3, 239, 242, 63, 147, 2, 65, 0, 230, 105, 200, 1, 208, 201, 237, 225, 85, 27, 39, 216, 193, 1, 253, 168, 88, 15, 242, 166, 70, 106, 235, 2, 92, 24, 130, 66, 176, 176, 220, 238, 66, 12, 159, 26, 24, 40, 19, 213, 138, 98, 238, 98, 220, 65, 148, 116, 146, 21, 0, 25, 6, 177, 57, 216, 70, 51, 149, 244, 157, 153, 106, 123, 2, 64, 127, 92, 254, 48, 67, 80, 54, 102, 50, 240, 253, 19, 108, 59, 168, 1, 230, 239, 39, 171, 180, 102, 138, 132, 89, 247, 147, 230, 234, 252, 52, 159, 222, 215, 184, 85, 78, 52, 81, 13, 145, 218, 202, 127, 37, 97, 54, 205, 249, 39, 230, 143, 171, 112, 114, 11, 64, 91, 89, 176, 6, 7, 248, 217, 2, 65, 0, 220, 94, 95, 132, 29, 4, 132, 22, 247, 38, 185, 189, 125, 27, 66, 87, 55, 162, 73, 24, 238, 80, 99, 228, 37, 224, 234, 244, 141, 185, 26, 20, 101, 231, 92, 99, 192, 166, 212, 17, 112, 1, 158, 173, 190, 170, 154, 41, 195, 109, 130, 98, 109, 28, 35, 142, 205, 213, 152, 158, 19, 253, 30, 241, 2, 64, 15, 148, 8, 16, 189, 122, 55, 109, 203, 175, 173, 24, 222, 36, 130, 130, 179, 87, 189, 32, 141, 149, 30, 115, 211, 227, 79, 234, 78, 202, 253, 48, 173, 95, 167, 203, 20, 193, 160, 30, 146, 33, 109, 4, 221, 25, 212, 216, 183, 100, 18, 46, 184, 52, 65, 146, 249, 68, 225, 10, 84, 38, 98, 133])"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ECDSA: {
|
||||||
|
keyUsages: ["sign", "verify"],
|
||||||
|
length: function(len) {
|
||||||
|
return len || random.item([256, 384, 512]);
|
||||||
|
},
|
||||||
|
alg: function(len) {
|
||||||
|
len = this.length(len);
|
||||||
|
return mockup(`{
|
||||||
|
name: 'ECDSA',
|
||||||
|
namedCurve: 'P-${len}',
|
||||||
|
hash: {
|
||||||
|
name: 'SHA-${len}'
|
||||||
|
}
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
jwk: function(len) {
|
||||||
|
return mockup(`{
|
||||||
|
kty: 'EC',
|
||||||
|
alg: 'ES${this.length(len)}'
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
generateKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
importKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
sign: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
verify: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
presets: {
|
||||||
|
raw: {},
|
||||||
|
jwk: [
|
||||||
|
{
|
||||||
|
kty: "EC",
|
||||||
|
crv: "P-256",
|
||||||
|
x: "A5fQnBdBSgBhTjMr1Atpzvh5SKYQ4aQRJ9WTCG5U4m4",
|
||||||
|
y: "8YF98byzMljHX3T5ORLYTDbcwG-_eq3f23JtTE6lOe0",
|
||||||
|
ext: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
kty: "EC",
|
||||||
|
crv: "P-256",
|
||||||
|
x: "A5fQnBdBSgBhTjMr1Atpzvh5SKYQ4aQRJ9WTCG5U4m4",
|
||||||
|
y: "8YF98byzMljHX3T5ORLYTDbcwG-_eq3f23JtTE6lOe0",
|
||||||
|
d: "4DvC-hxpv8myZLNeMY-8nq55MhdfA4obM1lGG3hF_yo",
|
||||||
|
ext: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
spki:
|
||||||
|
"new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, 3, 151, 208, 156, 23, 65, 74, 0, 97, 78, 51, 43, 212, 11, 105, 206, 248, 121, 72, 166, 16, 225, 164, 17, 39, 213, 147, 8, 110, 84, 226, 110, 241, 129, 125, 241, 188, 179, 50, 88, 199, 95, 116, 249, 57, 18, 216, 76, 54, 220, 192, 111, 191, 122, 173, 223, 219, 114, 109, 76, 78, 165, 57, 237])",
|
||||||
|
pkcs8:
|
||||||
|
"new Uint8Array([48, 129, 135, 2, 1, 0, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 4, 109, 48, 107, 2, 1, 1, 4, 32, 224, 59, 194, 250, 28, 105, 191, 201, 178, 100, 179, 94, 49, 143, 188, 158, 174, 121, 50, 23, 95, 3, 138, 27, 51, 89, 70, 27, 120, 69, 255, 42, 161, 68, 3, 66, 0, 4, 3, 151, 208, 156, 23, 65, 74, 0, 97, 78, 51, 43, 212, 11, 105, 206, 248, 121, 72, 166, 16, 225, 164, 17, 39, 213, 147, 8, 110, 84, 226, 110, 241, 129, 125, 241, 188, 179, 50, 88, 199, 95, 116, 249, 57, 18, 216, 76, 54, 220, 192, 111, 191, 122, 173, 223, 219, 114, 109, 76, 78, 165, 57, 237])"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ECDH: {
|
||||||
|
keyUsages: ["deriveKey", "deriveBits"],
|
||||||
|
length: function(len) {
|
||||||
|
return len || random.item([256, 384, 512]);
|
||||||
|
},
|
||||||
|
alg: function(len) {
|
||||||
|
return mockup(`{
|
||||||
|
name: 'ECDSA',
|
||||||
|
namedCurve: 'P-${this.length(len)}'
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
jwk: function() {
|
||||||
|
return {};
|
||||||
|
},
|
||||||
|
generateKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
importKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
deriveKey: function(key) {
|
||||||
|
return mockup(`{
|
||||||
|
name: 'ECDSA',
|
||||||
|
namedCurve: 'P-${this.length()}',
|
||||||
|
${key}
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
deriveBits: function(key) {
|
||||||
|
return mockup(`{
|
||||||
|
name: 'ECDSA',
|
||||||
|
namedCurve: 'P-${this.length()}',
|
||||||
|
${key}
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
presets: {
|
||||||
|
raw: {},
|
||||||
|
jwk: [
|
||||||
|
{
|
||||||
|
kty: "EC",
|
||||||
|
crv: "P-256",
|
||||||
|
x: "kgR_PqO07L8sZOBbw6rvv7O_f7clqDeiE3WnMkb5EoI",
|
||||||
|
y: "djI-XqCqSyO9GFk_QT_stROMCAROIvU8KOORBgQUemE",
|
||||||
|
ext: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
kty: "EC",
|
||||||
|
crv: "P-256",
|
||||||
|
x: "kgR_PqO07L8sZOBbw6rvv7O_f7clqDeiE3WnMkb5EoI",
|
||||||
|
y: "djI-XqCqSyO9GFk_QT_stROMCAROIvU8KOORBgQUemE",
|
||||||
|
d: "5aPFSt0UFVXYGu-ZKyC9FQIUOAMmnjzdIwkxCMe3Iok",
|
||||||
|
ext: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
spki:
|
||||||
|
"new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, 146, 4, 127, 62, 163, 180, 236, 191, 44, 100, 224, 91, 195, 170, 239, 191, 179, 191, 127, 183, 37, 168, 55, 162, 19, 117, 167, 50, 70, 249, 18, 130, 118, 50, 62, 94, 160, 170, 75, 35, 189, 24, 89, 63, 65, 63, 236, 181, 19, 140, 8, 4, 78, 34, 245, 60, 40, 227, 145, 6, 4, 20, 122, 97])",
|
||||||
|
pkcs8:
|
||||||
|
"new Uint8Array([48, 129, 135, 2, 1, 0, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 4, 109, 48, 107, 2, 1, 1, 4, 32, 229, 163, 197, 74, 221, 20, 21, 85, 216, 26, 239, 153, 43, 32, 189, 21, 2, 20, 56, 3, 38, 158, 60, 221, 35, 9, 49, 8, 199, 183, 34, 137, 161, 68, 3, 66, 0, 4, 146, 4, 127, 62, 163, 180, 236, 191, 44, 100, 224, 91, 195, 170, 239, 191, 179, 191, 127, 183, 37, 168, 55, 162, 19, 117, 167, 50, 70, 249, 18, 130, 118, 50, 62, 94, 160, 170, 75, 35, 189, 24, 89, 63, 65, 63, 236, 181, 19, 140, 8, 4, 78, 34, 245, 60, 40, 227, 145, 6, 4, 20, 122, 97])"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AES-CTR": {
|
||||||
|
// AES in Counter Mode.
|
||||||
|
keyUsages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"],
|
||||||
|
length: function(len) {
|
||||||
|
return len || random.item([128, 192, 256]);
|
||||||
|
},
|
||||||
|
alg: function(len) {
|
||||||
|
return mockup(`{
|
||||||
|
name: 'AES-CTR',
|
||||||
|
length: '${this.length(len)}'
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
jwk: function(len) {
|
||||||
|
return mockup(`{
|
||||||
|
kty: 'oct',
|
||||||
|
alg: 'A${this.length(len)}CTR'
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
generateKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
importKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
encrypt: function() {
|
||||||
|
return mockup(`{
|
||||||
|
name: 'AES-CTR',
|
||||||
|
length: ${this.length()},
|
||||||
|
counter: new Uint8Array(16)
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
decrypt: function() {
|
||||||
|
return this.encrypt();
|
||||||
|
},
|
||||||
|
wrapKey: function() {
|
||||||
|
return this.encrypt();
|
||||||
|
},
|
||||||
|
unwrapKey: function() {
|
||||||
|
return this.encrypt();
|
||||||
|
},
|
||||||
|
presets: {
|
||||||
|
raw:
|
||||||
|
"new Uint8Array([122, 94, 39, 230, 46, 23, 151, 80, 131, 230, 3, 101, 80, 234, 143, 9, 251, 152, 229, 228, 89, 222, 31, 135, 214, 104, 55, 68, 67, 59, 5, 51])",
|
||||||
|
jwk: [
|
||||||
|
{
|
||||||
|
kty: "oct",
|
||||||
|
k: "Y0zt37HgOx-BY7SQjYVmrqhPkO44Ii2Jcb9yydUDPfE",
|
||||||
|
alg: "A256CTR",
|
||||||
|
ext: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
spki: {},
|
||||||
|
pkcs8: {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AES-CBC": {
|
||||||
|
// AES in Cipher Block Chaining mode.
|
||||||
|
keyUsages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"],
|
||||||
|
length: function(len) {
|
||||||
|
return len || random.item([128, 192, 256]);
|
||||||
|
},
|
||||||
|
alg: function(len) {
|
||||||
|
return mockup(`{
|
||||||
|
name: 'AES-CBC',
|
||||||
|
length: ${this.length(len)}
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
jwk: function(len) {
|
||||||
|
return mockup(`{
|
||||||
|
kty: 'oct',
|
||||||
|
alg: 'A${this.length(len)}CBC'
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
generateKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
importKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
encrypt: function() {
|
||||||
|
return mockup(`{
|
||||||
|
name: 'AES-CBC',
|
||||||
|
length: ${this.length()},
|
||||||
|
iv: crypto.getRandomValues(new Uint8Array(16))
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
decrypt: function() {
|
||||||
|
return this.encrypt();
|
||||||
|
},
|
||||||
|
wrapKey: function() {
|
||||||
|
return this.encrypt();
|
||||||
|
},
|
||||||
|
unwrapKey: function() {
|
||||||
|
return this.encrypt();
|
||||||
|
},
|
||||||
|
presets: {
|
||||||
|
raw:
|
||||||
|
"new Uint8Array([122, 94, 39, 230, 46, 23, 151, 80, 131, 230, 3, 101, 80, 234, 143, 9, 251, 152, 229, 228, 89, 222, 31, 135, 214, 104, 55, 68, 67, 59, 5, 51])",
|
||||||
|
jwk: [
|
||||||
|
{
|
||||||
|
kty: "oct",
|
||||||
|
k: "KfKY5nueRX7eBrOddn9IerHLv1r-T7qpggaCF3MfSR4",
|
||||||
|
alg: "A256CBC",
|
||||||
|
ext: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
spki: {},
|
||||||
|
pkcs8: {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AES-GCM": {
|
||||||
|
// AES in Galois/Counter Mode.
|
||||||
|
keyUsages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"],
|
||||||
|
length: function(len) {
|
||||||
|
return len || random.item([128, 192, 256]);
|
||||||
|
},
|
||||||
|
alg: function(len) {
|
||||||
|
return mockup(`{
|
||||||
|
name: 'AES-GCM',
|
||||||
|
length: ${this.length(len)}
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
jwk: function(len) {
|
||||||
|
if (random.chance(4)) {
|
||||||
|
return mockup(`{
|
||||||
|
kty: 'oct',
|
||||||
|
alg: 'A${this.length(len)}GCMKW'
|
||||||
|
}`);
|
||||||
|
} else {
|
||||||
|
return mockup(`{
|
||||||
|
kty: 'oct',
|
||||||
|
alg: 'A${this.length(len)}GCM'
|
||||||
|
}`);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
generateKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
importKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
encrypt: function() {
|
||||||
|
return mockup(`{
|
||||||
|
name: 'AES-GCM',
|
||||||
|
iv: crypto.getRandomValues(new Uint8Array(12)),
|
||||||
|
additionalData: crypto.getRandomValues(new Uint8Array(256)),
|
||||||
|
tagLength: ${random.item([32, 64, 96, 104, 112, 120, 128])}
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
decrypt: function() {
|
||||||
|
return this.encrypt();
|
||||||
|
},
|
||||||
|
wrapKey: function() {
|
||||||
|
return mockup(`{
|
||||||
|
name: 'AES-GCM',
|
||||||
|
iv: crypto.getRandomValues(new Uint8Array(16))
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
unwrapKey: function() {
|
||||||
|
return this.wrapKey();
|
||||||
|
},
|
||||||
|
presets: {
|
||||||
|
raw:
|
||||||
|
"new Uint8Array([122, 94, 39, 230, 46, 23, 151, 80, 131, 230, 3, 101, 80, 234, 143, 9, 251, 152, 229, 228, 89, 222, 31, 135, 214, 104, 55, 68, 67, 59, 5, 51])",
|
||||||
|
jwk: [
|
||||||
|
{
|
||||||
|
kty: "oct",
|
||||||
|
k: "KfKY5nueRX7eBrOddn9IerHLv1r-T7qpggaCF3MfSR4",
|
||||||
|
alg: "A256GCM",
|
||||||
|
ext: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
spki: {},
|
||||||
|
pkcs8: {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AES-KW": {
|
||||||
|
// Key wrapping in AES algorithm.
|
||||||
|
keyUsages: ["wrapKey", "unwrapKey"],
|
||||||
|
length: function(len) {
|
||||||
|
return len || random.item([128, 192, 256]);
|
||||||
|
},
|
||||||
|
alg: function(len) {
|
||||||
|
return mockup(`{
|
||||||
|
name: 'AES-KW',
|
||||||
|
length: ${this.length(len)}
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
jwk: function(len) {
|
||||||
|
return mockup(`{
|
||||||
|
kty: 'oct',
|
||||||
|
alg: 'A${this.length(len)}KW'
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
generateKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
importKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
wrapKey: function() {
|
||||||
|
return mockup(`{
|
||||||
|
name: 'AES-KW'
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
unwrapKey: function() {
|
||||||
|
return this.wrapKey();
|
||||||
|
},
|
||||||
|
presets: {
|
||||||
|
raw:
|
||||||
|
"new Uint8Array([122, 94, 39, 230, 46, 23, 151, 80, 131, 230, 3, 101, 80, 234, 143, 9, 251, 152, 229, 228, 89, 222, 31, 135, 214, 104, 55, 68, 67, 59, 5, 51])",
|
||||||
|
jwk: [
|
||||||
|
{
|
||||||
|
kty: "oct",
|
||||||
|
k: "KfKY5nueRX7eBrOddn9IerHLv1r-T7qpggaCF3MfSR4",
|
||||||
|
alg: "A256KW",
|
||||||
|
ext: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
spki: {},
|
||||||
|
pkcs8: {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
HMAC: {
|
||||||
|
// Hash-based message authentication method using SHA hash functions.
|
||||||
|
keyUsages: ["sign", "verify"],
|
||||||
|
length: function(len) {
|
||||||
|
return len || random.item([1, 256, 384, 512]);
|
||||||
|
},
|
||||||
|
alg: function(len) {
|
||||||
|
return mockup(`{
|
||||||
|
name: 'HMAC',
|
||||||
|
hash: {
|
||||||
|
name: 'SHA-${this.length(len)}'
|
||||||
|
}
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
jwk: function(len) {
|
||||||
|
return mockup(`{
|
||||||
|
kty: 'oct',
|
||||||
|
alg: 'HS${this.length(len)}'
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
generateKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
importKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
sign: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
verify: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
presets: {
|
||||||
|
raw:
|
||||||
|
"new Uint8Array([122, 94, 39, 230, 46, 23, 151, 80, 131, 230, 3, 101, 80, 234, 143, 9, 251, 152, 229, 228, 89, 222, 31, 135, 214, 104, 55, 68, 67, 59, 5, 51])",
|
||||||
|
jwk: {
|
||||||
|
kty: "oct",
|
||||||
|
k: "KfKY5nueRX7eBrOddn9IerHLv1r-T7qpggaCF3MfSR4",
|
||||||
|
alg: "HS256",
|
||||||
|
ext: true
|
||||||
|
},
|
||||||
|
spki: {},
|
||||||
|
pkcs8: {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
HKDF: {
|
||||||
|
// Key derivation using the extraction-then-expansion approach and using the SHA hash functions.
|
||||||
|
keyUsages: ["deriveKey", "deriveBits"],
|
||||||
|
alg: function() {
|
||||||
|
return mockup(`{
|
||||||
|
name: 'HKDF'
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
jwk: function() {
|
||||||
|
return mockup(`{}`);
|
||||||
|
},
|
||||||
|
generateKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
importKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
deriveBits: function() {
|
||||||
|
return mockup(`{
|
||||||
|
name: 'HKDF',
|
||||||
|
hash: {
|
||||||
|
name: '${crypto.randomDigestName()}'
|
||||||
|
},
|
||||||
|
salt: crypto.getRandomValues(new Uint8Array(16)),
|
||||||
|
info: crypto.getRandomValues(new Uint8Array(16))
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
deriveKey: function() {
|
||||||
|
return this.deriveBits();
|
||||||
|
},
|
||||||
|
presets: {
|
||||||
|
raw: "crypto.getRandomValues(new Uint8Array(16))",
|
||||||
|
jwk: {},
|
||||||
|
spki: {},
|
||||||
|
pkcs8: {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
PBKDF2: {
|
||||||
|
// Key derivation using the PKCS#5 password-based key derivation function v2.0.
|
||||||
|
keyUsages: ["deriveKey", "deriveBits"],
|
||||||
|
alg: function() {
|
||||||
|
return mockup(`{
|
||||||
|
name: 'PBKDF2'
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
jwk: function() {
|
||||||
|
return mockup(`{}`);
|
||||||
|
},
|
||||||
|
generateKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
importKey: function() {
|
||||||
|
return this.alg();
|
||||||
|
},
|
||||||
|
deriveBits: function() {
|
||||||
|
return mockup(`{
|
||||||
|
name: 'PBKDF2',
|
||||||
|
hash: {
|
||||||
|
name: '${crypto.randomDigestName()}'
|
||||||
|
},
|
||||||
|
salt: crypto.getRandomValues(new Uint8Array(16)),
|
||||||
|
iterations: ${random.number(1000)}
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
deriveKey: function() {
|
||||||
|
return this.deriveBits();
|
||||||
|
},
|
||||||
|
presets: {
|
||||||
|
raw: "crypto.getRandomValues(new Uint8Array(16))",
|
||||||
|
jwk: {},
|
||||||
|
spki: {},
|
||||||
|
pkcs8: {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
DH: {
|
||||||
|
keyUsages: ["deriveKey", "deriveBits"],
|
||||||
|
alg: function() {
|
||||||
|
return mockup(`{
|
||||||
|
name: 'DH'
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
jwk: function() {
|
||||||
|
return mockup(`{}`);
|
||||||
|
},
|
||||||
|
generateKey: function() {
|
||||||
|
return mockup(`{
|
||||||
|
name: 'DH',
|
||||||
|
prime: new Uint8Array([255, 255, 255, 255, 255, 255, 255, 255, 201, 15, 218, 162, 33, 104, 194, 52, 196, 198, 98, 139, 128, 220, 28, 209, 41, 2, 78, 8, 138, 103, 204, 116, 2, 11, 190, 166, 59, 19, 155, 34, 81, 74, 8, 121, 142, 52, 4, 221, 239, 149, 25, 179, 205, 58, 67, 27, 48, 43, 10, 109, 242, 95, 20, 55, 79, 225, 53, 109, 109, 81, 194, 69, 228, 133, 181, 118, 98, 94, 126, 198, 244, 76, 66, 233, 166, 55, 237, 107, 11, 255, 92, 182, 244, 6, 183, 237, 238, 56, 107, 251, 90, 137, 159, 165, 174, 159, 36, 17, 124, 75, 31, 230, 73, 40, 102, 81, 236, 228, 91, 61, 194, 0, 124, 184, 161, 99, 191, 5, 152, 218, 72, 54, 28, 85, 211, 154, 105, 22, 63, 168, 253, 36, 207, 95, 131, 101, 93, 35, 220, 163, 173, 150, 28, 98, 243, 86, 32, 133, 82, 187, 158, 213, 41, 7, 112, 150, 150, 109, 103, 12, 53, 78, 74, 188, 152, 4, 241, 116, 108, 8, 202, 35, 115, 39, 255, 255, 255, 255, 255, 255, 255, 255]),
|
||||||
|
generator: new Uint8Array([2])
|
||||||
|
}`);
|
||||||
|
},
|
||||||
|
importKey: function() {
|
||||||
|
return this.generateKey();
|
||||||
|
},
|
||||||
|
deriveKey: function(key) {
|
||||||
|
// return Object.assign(this.generateKey(),key)
|
||||||
|
return mockup(`
|
||||||
|
name: 'DH',
|
||||||
|
prime: new Uint8Array([255, 255, 255, 255, 255, 255, 255, 255, 201, 15, 218, 162, 33, 104, 194, 52, 196, 198, 98, 139, 128, 220, 28, 209, 41, 2, 78, 8, 138, 103, 204, 116, 2, 11, 190, 166, 59, 19, 155, 34, 81, 74, 8, 121, 142, 52, 4, 221, 239, 149, 25, 179, 205, 58, 67, 27, 48, 43, 10, 109, 242, 95, 20, 55, 79, 225, 53, 109, 109, 81, 194, 69, 228, 133, 181, 118, 98, 94, 126, 198, 244, 76, 66, 233, 166, 55, 237, 107, 11, 255, 92, 182, 244, 6, 183, 237, 238, 56, 107, 251, 90, 137, 159, 165, 174, 159, 36, 17, 124, 75, 31, 230, 73, 40, 102, 81, 236, 228, 91, 61, 194, 0, 124, 184, 161, 99, 191, 5, 152, 218, 72, 54, 28, 85, 211, 154, 105, 22, 63, 168, 253, 36, 207, 95, 131, 101, 93, 35, 220, 163, 173, 150, 28, 98, 243, 86, 32, 133, 82, 187, 158, 213, 41, 7, 112, 150, 150, 109, 103, 12, 53, 78, 74, 188, 152, 4, 241, 116, 108, 8, 202, 35, 115, 39, 255, 255, 255, 255, 255, 255, 255, 255]),
|
||||||
|
generator: new Uint8Array([2]),
|
||||||
|
${key}
|
||||||
|
`);
|
||||||
|
},
|
||||||
|
deriveBits: function(key) {
|
||||||
|
return mockup(`
|
||||||
|
name: 'DH',
|
||||||
|
prime: new Uint8Array([255, 255, 255, 255, 255, 255, 255, 255, 201, 15, 218, 162, 33, 104, 194, 52, 196, 198, 98, 139, 128, 220, 28, 209, 41, 2, 78, 8, 138, 103, 204, 116, 2, 11, 190, 166, 59, 19, 155, 34, 81, 74, 8, 121, 142, 52, 4, 221, 239, 149, 25, 179, 205, 58, 67, 27, 48, 43, 10, 109, 242, 95, 20, 55, 79, 225, 53, 109, 109, 81, 194, 69, 228, 133, 181, 118, 98, 94, 126, 198, 244, 76, 66, 233, 166, 55, 237, 107, 11, 255, 92, 182, 244, 6, 183, 237, 238, 56, 107, 251, 90, 137, 159, 165, 174, 159, 36, 17, 124, 75, 31, 230, 73, 40, 102, 81, 236, 228, 91, 61, 194, 0, 124, 184, 161, 99, 191, 5, 152, 218, 72, 54, 28, 85, 211, 154, 105, 22, 63, 168, 253, 36, 207, 95, 131, 101, 93, 35, 220, 163, 173, 150, 28, 98, 243, 86, 32, 133, 82, 187, 158, 213, 41, 7, 112, 150, 150, 109, 103, 12, 53, 78, 74, 188, 152, 4, 241, 116, 108, 8, 202, 35, 115, 39, 255, 255, 255, 255, 255, 255, 255, 255]),
|
||||||
|
generator: new Uint8Array([2]),
|
||||||
|
${key}
|
||||||
|
`);
|
||||||
|
},
|
||||||
|
presets: {
|
||||||
|
raw: {},
|
||||||
|
jwk: {},
|
||||||
|
spki: {},
|
||||||
|
pkcs8: {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static supportedAlgorithms() {
|
||||||
|
Object.keys(crypto.algorithms);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomAlgorithm() {
|
||||||
|
return crypto.algorithms[random.item(Object.keys(crypto.algorithms))];
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomCandidate(operation) {
|
||||||
|
// Find and return a random algorithm suitable for a given operation.
|
||||||
|
return crypto.algorithms[crypto.randomAlgorithmName(operation)];
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
|
@ -1,107 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
const make = require('../make')
|
|
||||||
const random = require('../random')
|
|
||||||
|
|
||||||
class font extends make {
|
|
||||||
static globalValue () {
|
|
||||||
return random.pick(['inherit', 'initial', 'unset'])
|
|
||||||
}
|
|
||||||
|
|
||||||
static style () {
|
|
||||||
return random.pick(['italic', 'normal', 'oblique', 'inherit'])
|
|
||||||
}
|
|
||||||
|
|
||||||
static variant () {
|
|
||||||
return random.pick(['normal', 'small-caps', 'inherit'])
|
|
||||||
}
|
|
||||||
|
|
||||||
static weight () {
|
|
||||||
return random.pick([
|
|
||||||
/* standard */
|
|
||||||
['normal', 'bold'],
|
|
||||||
/* Relative to the parent */
|
|
||||||
['bolder', 'lighter'],
|
|
||||||
/* numeric values */
|
|
||||||
[100, 200, 300, 400, 500, 600, 700, 800, 900]
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static size () {
|
|
||||||
return random.pick([
|
|
||||||
/* <absolute-size> values */
|
|
||||||
['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'],
|
|
||||||
/* <relative-size> values */
|
|
||||||
['larger', 'smaller'],
|
|
||||||
/* <length> values */
|
|
||||||
make.number.unsigned() + make.unit.unit(),
|
|
||||||
/* <percentage> values */
|
|
||||||
make.unit.percent()
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static relativeSize () {
|
|
||||||
let value = random.number(8)
|
|
||||||
return random.item(['', '+', '-']) + value
|
|
||||||
}
|
|
||||||
|
|
||||||
static genericFamily () {
|
|
||||||
return random.pick(['serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'])
|
|
||||||
}
|
|
||||||
|
|
||||||
static familyName () {
|
|
||||||
return random.pick(['Times New Roman', 'Arial', 'Courier', 'Helvetica'])
|
|
||||||
}
|
|
||||||
|
|
||||||
static family () {
|
|
||||||
let s = random.pick(font.familyName)
|
|
||||||
if (random.chance(8)) {
|
|
||||||
s += `, ${random.pick(font.genericFamily)}`
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
static registeredFontFeatures () {
|
|
||||||
return random.pick([
|
|
||||||
'aalt', 'abvf', 'abvm', 'abvs', 'afrc', 'akhn', 'blwf', 'blwm', 'blws',
|
|
||||||
'calt', 'case', 'ccmp', 'cfar', 'cjct', 'clig', 'cpct', 'cpsp', 'cswh',
|
|
||||||
'curs', 'cv01-cv99', 'c2pc', 'c2sc', 'dist', 'dlig', 'dnom', 'expt',
|
|
||||||
'falt', 'fin2', 'fin3', 'fina', 'frac', 'fwid', 'half', 'haln', 'halt',
|
|
||||||
'hist', 'hkna', 'hlig', 'hngl', 'hojo', 'hwid', 'init', 'isol', 'ital',
|
|
||||||
'jalt', 'jp78', 'jp83', 'jp90', 'jp04', 'kern', 'lfbd', 'liga', 'ljmo',
|
|
||||||
'lnum', 'locl', 'ltra', 'ltrm', 'mark', 'med2', 'medi', 'mgrk', 'mkmk',
|
|
||||||
'mset', 'nalt', 'nlck', 'nukt', 'numr', 'onum', 'opbd', 'ordn', 'ornm',
|
|
||||||
'palt', 'pcap', 'pkna', 'pnum', 'pref', 'pres', 'pstf', 'psts', 'pwid',
|
|
||||||
'qwid', 'rand', 'rkrf', 'rlig', 'rphf', 'rtbd', 'rtla', 'rtlm', 'ruby',
|
|
||||||
'salt', 'sinf', 'size', 'smcp', 'smpl', 'ss01', 'ss02', 'ss03', 'ss04',
|
|
||||||
'ss05', 'ss06', 'ss07', 'ss08', 'ss09', 'ss10', 'ss11', 'ss12', 'ss13',
|
|
||||||
'ss14', 'ss15', 'ss16', 'ss17', 'ss18', 'ss19', 'ss20', 'subs', 'sups',
|
|
||||||
'swsh', 'titl', 'tjmo', 'tnam', 'tnum', 'trad', 'twid', 'unic', 'valt',
|
|
||||||
'vatu', 'vert', 'vhal', 'vjmo', 'vkna', 'vkrn', 'vpal', 'vrt2', 'zero'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static font () {
|
|
||||||
let s = ''
|
|
||||||
if (random.chance(4)) {
|
|
||||||
s += `${random.pick(font.style)} `
|
|
||||||
}
|
|
||||||
if (random.chance(4)) {
|
|
||||||
s += `${random.pick(font.variant)} `
|
|
||||||
}
|
|
||||||
if (random.chance(4)) {
|
|
||||||
s += `${random.pick(font.weight)} `
|
|
||||||
}
|
|
||||||
if (random.chance(4)) {
|
|
||||||
s += `${make.number.any()}/`
|
|
||||||
}
|
|
||||||
s += font.size()
|
|
||||||
s += ' '
|
|
||||||
s += font.family()
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = font
|
|
239
lib/make/fonts.ts
Normal file
239
lib/make/fonts.ts
Normal file
|
@ -0,0 +1,239 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
import random from "../random/random.ts";
|
||||||
|
import numbers from "./numbers.ts";
|
||||||
|
import unit from "./units.ts";
|
||||||
|
|
||||||
|
export default class font {
|
||||||
|
static globalValue() {
|
||||||
|
return random.pick(["inherit", "initial", "unset"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static style() {
|
||||||
|
return random.pick(["italic", "normal", "oblique", "inherit"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static variant() {
|
||||||
|
return random.pick(["normal", "small-caps", "inherit"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static weight() {
|
||||||
|
return random.pick([
|
||||||
|
/* standard */
|
||||||
|
["normal", "bold"],
|
||||||
|
/* Relative to the parent */
|
||||||
|
["bolder", "lighter"],
|
||||||
|
/* numeric values */
|
||||||
|
[100, 200, 300, 400, 500, 600, 700, 800, 900]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static size() {
|
||||||
|
return random.pick([
|
||||||
|
/* <absolute-size> values */
|
||||||
|
[
|
||||||
|
"xx-small",
|
||||||
|
"x-small",
|
||||||
|
"small",
|
||||||
|
"medium",
|
||||||
|
"large",
|
||||||
|
"x-large",
|
||||||
|
"xx-large"
|
||||||
|
],
|
||||||
|
/* <relative-size> values */
|
||||||
|
["larger", "smaller"],
|
||||||
|
/* <length> values */
|
||||||
|
numbers.unsigned() + unit.unit(),
|
||||||
|
/* <percentage> values */
|
||||||
|
unit.percent()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static relativeSize() {
|
||||||
|
let value = random.number(8);
|
||||||
|
return random.item(["", "+", "-"]) + value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static genericFamily() {
|
||||||
|
return random.pick([
|
||||||
|
"serif",
|
||||||
|
"sans-serif",
|
||||||
|
"cursive",
|
||||||
|
"fantasy",
|
||||||
|
"monospace"
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static familyName() {
|
||||||
|
return random.pick(["Times New Roman", "Arial", "Courier", "Helvetica"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static family() {
|
||||||
|
let s = random.pick(font.familyName);
|
||||||
|
if (random.chance(8)) {
|
||||||
|
s += `, ${random.pick(font.genericFamily)}`;
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
static registeredFontFeatures() {
|
||||||
|
return random.pick([
|
||||||
|
"aalt",
|
||||||
|
"abvf",
|
||||||
|
"abvm",
|
||||||
|
"abvs",
|
||||||
|
"afrc",
|
||||||
|
"akhn",
|
||||||
|
"blwf",
|
||||||
|
"blwm",
|
||||||
|
"blws",
|
||||||
|
"calt",
|
||||||
|
"case",
|
||||||
|
"ccmp",
|
||||||
|
"cfar",
|
||||||
|
"cjct",
|
||||||
|
"clig",
|
||||||
|
"cpct",
|
||||||
|
"cpsp",
|
||||||
|
"cswh",
|
||||||
|
"curs",
|
||||||
|
"cv01-cv99",
|
||||||
|
"c2pc",
|
||||||
|
"c2sc",
|
||||||
|
"dist",
|
||||||
|
"dlig",
|
||||||
|
"dnom",
|
||||||
|
"expt",
|
||||||
|
"falt",
|
||||||
|
"fin2",
|
||||||
|
"fin3",
|
||||||
|
"fina",
|
||||||
|
"frac",
|
||||||
|
"fwid",
|
||||||
|
"half",
|
||||||
|
"haln",
|
||||||
|
"halt",
|
||||||
|
"hist",
|
||||||
|
"hkna",
|
||||||
|
"hlig",
|
||||||
|
"hngl",
|
||||||
|
"hojo",
|
||||||
|
"hwid",
|
||||||
|
"init",
|
||||||
|
"isol",
|
||||||
|
"ital",
|
||||||
|
"jalt",
|
||||||
|
"jp78",
|
||||||
|
"jp83",
|
||||||
|
"jp90",
|
||||||
|
"jp04",
|
||||||
|
"kern",
|
||||||
|
"lfbd",
|
||||||
|
"liga",
|
||||||
|
"ljmo",
|
||||||
|
"lnum",
|
||||||
|
"locl",
|
||||||
|
"ltra",
|
||||||
|
"ltrm",
|
||||||
|
"mark",
|
||||||
|
"med2",
|
||||||
|
"medi",
|
||||||
|
"mgrk",
|
||||||
|
"mkmk",
|
||||||
|
"mset",
|
||||||
|
"nalt",
|
||||||
|
"nlck",
|
||||||
|
"nukt",
|
||||||
|
"numr",
|
||||||
|
"onum",
|
||||||
|
"opbd",
|
||||||
|
"ordn",
|
||||||
|
"ornm",
|
||||||
|
"palt",
|
||||||
|
"pcap",
|
||||||
|
"pkna",
|
||||||
|
"pnum",
|
||||||
|
"pref",
|
||||||
|
"pres",
|
||||||
|
"pstf",
|
||||||
|
"psts",
|
||||||
|
"pwid",
|
||||||
|
"qwid",
|
||||||
|
"rand",
|
||||||
|
"rkrf",
|
||||||
|
"rlig",
|
||||||
|
"rphf",
|
||||||
|
"rtbd",
|
||||||
|
"rtla",
|
||||||
|
"rtlm",
|
||||||
|
"ruby",
|
||||||
|
"salt",
|
||||||
|
"sinf",
|
||||||
|
"size",
|
||||||
|
"smcp",
|
||||||
|
"smpl",
|
||||||
|
"ss01",
|
||||||
|
"ss02",
|
||||||
|
"ss03",
|
||||||
|
"ss04",
|
||||||
|
"ss05",
|
||||||
|
"ss06",
|
||||||
|
"ss07",
|
||||||
|
"ss08",
|
||||||
|
"ss09",
|
||||||
|
"ss10",
|
||||||
|
"ss11",
|
||||||
|
"ss12",
|
||||||
|
"ss13",
|
||||||
|
"ss14",
|
||||||
|
"ss15",
|
||||||
|
"ss16",
|
||||||
|
"ss17",
|
||||||
|
"ss18",
|
||||||
|
"ss19",
|
||||||
|
"ss20",
|
||||||
|
"subs",
|
||||||
|
"sups",
|
||||||
|
"swsh",
|
||||||
|
"titl",
|
||||||
|
"tjmo",
|
||||||
|
"tnam",
|
||||||
|
"tnum",
|
||||||
|
"trad",
|
||||||
|
"twid",
|
||||||
|
"unic",
|
||||||
|
"valt",
|
||||||
|
"vatu",
|
||||||
|
"vert",
|
||||||
|
"vhal",
|
||||||
|
"vjmo",
|
||||||
|
"vkna",
|
||||||
|
"vkrn",
|
||||||
|
"vpal",
|
||||||
|
"vrt2",
|
||||||
|
"zero"
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static font() {
|
||||||
|
let s = "";
|
||||||
|
if (random.chance(4)) {
|
||||||
|
s += `${random.pick(font.style)} `;
|
||||||
|
}
|
||||||
|
if (random.chance(4)) {
|
||||||
|
s += `${random.pick(font.variant)} `;
|
||||||
|
}
|
||||||
|
if (random.chance(4)) {
|
||||||
|
s += `${random.pick(font.weight)} `;
|
||||||
|
}
|
||||||
|
if (random.chance(4)) {
|
||||||
|
s += `${numbers.any()}/`;
|
||||||
|
}
|
||||||
|
s += font.size();
|
||||||
|
s += " ";
|
||||||
|
s += font.family();
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,26 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
const make = require('../make')
|
|
||||||
const random = require('../random')
|
|
||||||
|
|
||||||
class html extends make {
|
|
||||||
static tag () {
|
|
||||||
return random.item(['a', 'abbr', 'acronym', 'address', 'applet', 'area', 'article', 'aside', 'audio', 'b', 'base', 'basefont', 'bdi', 'bdo', 'bgsound', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'command', 'content', 'data', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'embed', 'fieldset', 'figcaption', 'figure', 'font', 'foo', 'footer', 'form', 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'iframe', 'image', 'img', 'input', 'ins', 'isindex', 'kbd', 'keygen', 'label', 'legend', 'li', 'link', 'listing', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meta', 'meter', 'multicol', 'nav', 'nobr', 'noembed', 'noframes', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'param', 'picture', 'plaintext', 'pre', 'progress', 'q', 'rb', 'rp', 'rt', 'rtc', 'ruby', 's', 'samp', 'script', 'section', 'select', 'shadow', 'slot', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr', 'xmp'])
|
|
||||||
}
|
|
||||||
|
|
||||||
static attribute () {
|
|
||||||
return random.item(['accept', 'accept-charset', 'accesskey', 'action', 'align', 'alt', 'async', 'autocomplete', 'autofocus', 'autoplay', 'autosave', 'bgcolor', 'border', 'buffered', 'challenge', 'charset', 'checked', 'cite', 'class', 'code', 'codebase', 'color', 'cols', 'colspan', 'content', 'contenteditable', 'contextmenu', 'controls', 'coords', 'crossorigin', 'data', 'data-*', 'datetime', 'default', 'defer', 'dir', 'dirname', 'disabled', 'download', 'draggable', 'dropzone', 'enctype', 'for', 'form', 'formaction', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'http-equiv', 'icon', 'id', 'integrity', 'ismap', 'itemprop', 'keytype', 'kind', 'label', 'lang', 'language', 'list', 'loop', 'low', 'manifest', 'max', 'maxlength', 'minlength', 'media', 'method', 'min', 'multiple', 'muted', 'name', 'novalidate', 'open', 'optimum', 'pattern', 'ping', 'placeholder', 'poster', 'preload', 'radiogroup', 'readonly', 'rel', 'required', 'reversed', 'rows', 'rowspan', 'sandbox', 'scope', 'scoped', 'seamless', 'selected', 'shape', 'size', 'sizes', 'slot', 'span', 'spellcheck', 'src', 'srcdoc', 'srclang', 'srcset', 'start', 'step', 'style', 'summary', 'tabindex', 'target', 'title', 'type', 'usemap', 'value', 'width'])
|
|
||||||
}
|
|
||||||
|
|
||||||
static interfaceName () {
|
|
||||||
return random.pick(['HTMLBRElement', 'HTMLTableSectionElement', 'HTMLDataListElement', 'HTMLTableElement', 'HTMLOListElement', 'HTMLFontElement', 'HTMLMapElement', 'HTMLButtonElement', 'HTMLFrameSetElement', 'HTMLDataElement', 'HTMLOptGroupElement', 'HTMLAnchorElement', 'HTMLLinkElement', 'HTMLObjectElement', 'HTMLHeadElement', 'HTMLProgressElement', 'HTMLFrameElement', 'HTMLTimeElement', 'HTMLTableCaptionElement', 'HTMLDivElement', 'HTMLDListElement', 'HTMLBodyElement', 'HTMLImageElement', 'HTMLTableRowElement', 'HTMLScriptElement', 'HTMLInputElement', 'HTMLMeterElement', 'HTMLFieldSetElement', 'HTMLHtmlElement', 'HTMLStyleElement', 'HTMLDetailsElement', 'HTMLTrackElement', 'HTMLBaseElement', 'HTMLTableColElement', 'HTMLSourceElement', 'HTMLPictureElement', 'HTMLSelectElement', 'HTMLLegendElement', 'HTMLHRElement', 'HTMLModElement', 'HTMLTemplateElement', 'HTMLAreaElement', 'HTMLFormElement', 'HTMLEmbedElement', 'HTMLSpanElement', 'HTMLParagraphElement', 'HTMLIFrameElement', 'HTMLTableCellElement', 'HTMLElement', 'HTMLMenuElement', 'HTMLTextAreaElement', 'HTMLHeadingElement', 'HTMLCanvasElement', 'HTMLOutputElement', 'HTMLQuoteElement', 'HTMLOptionElement', 'HTMLLIElement', 'HTMLAudioElement', 'HTMLMenuItemElement', 'HTMLParamElement', 'HTMLUListElement', 'HTMLLabelElement', 'HTMLDirectoryElement', 'HTMLTitleElement', 'HTMLPreElement', 'HTMLMetaElement', 'HTMLVideoElement'])
|
|
||||||
}
|
|
||||||
|
|
||||||
static className () {
|
|
||||||
return random.item(['class_1', 'class_2', 'class_3', 'class_4'])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = html
|
|
354
lib/make/html.ts
Normal file
354
lib/make/html.ts
Normal file
|
@ -0,0 +1,354 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
import random from "../random/random.ts";
|
||||||
|
|
||||||
|
export default class html {
|
||||||
|
static tag() {
|
||||||
|
return random.item([
|
||||||
|
"a",
|
||||||
|
"abbr",
|
||||||
|
"acronym",
|
||||||
|
"address",
|
||||||
|
"applet",
|
||||||
|
"area",
|
||||||
|
"article",
|
||||||
|
"aside",
|
||||||
|
"audio",
|
||||||
|
"b",
|
||||||
|
"base",
|
||||||
|
"basefont",
|
||||||
|
"bdi",
|
||||||
|
"bdo",
|
||||||
|
"bgsound",
|
||||||
|
"big",
|
||||||
|
"blink",
|
||||||
|
"blockquote",
|
||||||
|
"body",
|
||||||
|
"br",
|
||||||
|
"button",
|
||||||
|
"canvas",
|
||||||
|
"caption",
|
||||||
|
"center",
|
||||||
|
"cite",
|
||||||
|
"code",
|
||||||
|
"col",
|
||||||
|
"colgroup",
|
||||||
|
"command",
|
||||||
|
"content",
|
||||||
|
"data",
|
||||||
|
"datalist",
|
||||||
|
"dd",
|
||||||
|
"del",
|
||||||
|
"details",
|
||||||
|
"dfn",
|
||||||
|
"dialog",
|
||||||
|
"dir",
|
||||||
|
"div",
|
||||||
|
"dl",
|
||||||
|
"dt",
|
||||||
|
"element",
|
||||||
|
"em",
|
||||||
|
"embed",
|
||||||
|
"fieldset",
|
||||||
|
"figcaption",
|
||||||
|
"figure",
|
||||||
|
"font",
|
||||||
|
"foo",
|
||||||
|
"footer",
|
||||||
|
"form",
|
||||||
|
"frame",
|
||||||
|
"frameset",
|
||||||
|
"h1",
|
||||||
|
"h2",
|
||||||
|
"h3",
|
||||||
|
"h4",
|
||||||
|
"h5",
|
||||||
|
"h6",
|
||||||
|
"head",
|
||||||
|
"header",
|
||||||
|
"hgroup",
|
||||||
|
"hr",
|
||||||
|
"html",
|
||||||
|
"i",
|
||||||
|
"iframe",
|
||||||
|
"image",
|
||||||
|
"img",
|
||||||
|
"input",
|
||||||
|
"ins",
|
||||||
|
"isindex",
|
||||||
|
"kbd",
|
||||||
|
"keygen",
|
||||||
|
"label",
|
||||||
|
"legend",
|
||||||
|
"li",
|
||||||
|
"link",
|
||||||
|
"listing",
|
||||||
|
"main",
|
||||||
|
"map",
|
||||||
|
"mark",
|
||||||
|
"marquee",
|
||||||
|
"menu",
|
||||||
|
"menuitem",
|
||||||
|
"meta",
|
||||||
|
"meter",
|
||||||
|
"multicol",
|
||||||
|
"nav",
|
||||||
|
"nobr",
|
||||||
|
"noembed",
|
||||||
|
"noframes",
|
||||||
|
"noscript",
|
||||||
|
"object",
|
||||||
|
"ol",
|
||||||
|
"optgroup",
|
||||||
|
"option",
|
||||||
|
"output",
|
||||||
|
"p",
|
||||||
|
"param",
|
||||||
|
"picture",
|
||||||
|
"plaintext",
|
||||||
|
"pre",
|
||||||
|
"progress",
|
||||||
|
"q",
|
||||||
|
"rb",
|
||||||
|
"rp",
|
||||||
|
"rt",
|
||||||
|
"rtc",
|
||||||
|
"ruby",
|
||||||
|
"s",
|
||||||
|
"samp",
|
||||||
|
"script",
|
||||||
|
"section",
|
||||||
|
"select",
|
||||||
|
"shadow",
|
||||||
|
"slot",
|
||||||
|
"small",
|
||||||
|
"source",
|
||||||
|
"spacer",
|
||||||
|
"span",
|
||||||
|
"strike",
|
||||||
|
"strong",
|
||||||
|
"style",
|
||||||
|
"sub",
|
||||||
|
"summary",
|
||||||
|
"sup",
|
||||||
|
"table",
|
||||||
|
"tbody",
|
||||||
|
"td",
|
||||||
|
"template",
|
||||||
|
"textarea",
|
||||||
|
"tfoot",
|
||||||
|
"th",
|
||||||
|
"thead",
|
||||||
|
"time",
|
||||||
|
"title",
|
||||||
|
"tr",
|
||||||
|
"track",
|
||||||
|
"tt",
|
||||||
|
"u",
|
||||||
|
"ul",
|
||||||
|
"var",
|
||||||
|
"video",
|
||||||
|
"wbr",
|
||||||
|
"xmp"
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static attribute() {
|
||||||
|
return random.item([
|
||||||
|
"accept",
|
||||||
|
"accept-charset",
|
||||||
|
"accesskey",
|
||||||
|
"action",
|
||||||
|
"align",
|
||||||
|
"alt",
|
||||||
|
"async",
|
||||||
|
"autocomplete",
|
||||||
|
"autofocus",
|
||||||
|
"autoplay",
|
||||||
|
"autosave",
|
||||||
|
"bgcolor",
|
||||||
|
"border",
|
||||||
|
"buffered",
|
||||||
|
"challenge",
|
||||||
|
"charset",
|
||||||
|
"checked",
|
||||||
|
"cite",
|
||||||
|
"class",
|
||||||
|
"code",
|
||||||
|
"codebase",
|
||||||
|
"color",
|
||||||
|
"cols",
|
||||||
|
"colspan",
|
||||||
|
"content",
|
||||||
|
"contenteditable",
|
||||||
|
"contextmenu",
|
||||||
|
"controls",
|
||||||
|
"coords",
|
||||||
|
"crossorigin",
|
||||||
|
"data",
|
||||||
|
"data-*",
|
||||||
|
"datetime",
|
||||||
|
"default",
|
||||||
|
"defer",
|
||||||
|
"dir",
|
||||||
|
"dirname",
|
||||||
|
"disabled",
|
||||||
|
"download",
|
||||||
|
"draggable",
|
||||||
|
"dropzone",
|
||||||
|
"enctype",
|
||||||
|
"for",
|
||||||
|
"form",
|
||||||
|
"formaction",
|
||||||
|
"headers",
|
||||||
|
"height",
|
||||||
|
"hidden",
|
||||||
|
"high",
|
||||||
|
"href",
|
||||||
|
"hreflang",
|
||||||
|
"http-equiv",
|
||||||
|
"icon",
|
||||||
|
"id",
|
||||||
|
"integrity",
|
||||||
|
"ismap",
|
||||||
|
"itemprop",
|
||||||
|
"keytype",
|
||||||
|
"kind",
|
||||||
|
"label",
|
||||||
|
"lang",
|
||||||
|
"language",
|
||||||
|
"list",
|
||||||
|
"loop",
|
||||||
|
"low",
|
||||||
|
"manifest",
|
||||||
|
"max",
|
||||||
|
"maxlength",
|
||||||
|
"minlength",
|
||||||
|
"media",
|
||||||
|
"method",
|
||||||
|
"min",
|
||||||
|
"multiple",
|
||||||
|
"muted",
|
||||||
|
"name",
|
||||||
|
"novalidate",
|
||||||
|
"open",
|
||||||
|
"optimum",
|
||||||
|
"pattern",
|
||||||
|
"ping",
|
||||||
|
"placeholder",
|
||||||
|
"poster",
|
||||||
|
"preload",
|
||||||
|
"radiogroup",
|
||||||
|
"readonly",
|
||||||
|
"rel",
|
||||||
|
"required",
|
||||||
|
"reversed",
|
||||||
|
"rows",
|
||||||
|
"rowspan",
|
||||||
|
"sandbox",
|
||||||
|
"scope",
|
||||||
|
"scoped",
|
||||||
|
"seamless",
|
||||||
|
"selected",
|
||||||
|
"shape",
|
||||||
|
"size",
|
||||||
|
"sizes",
|
||||||
|
"slot",
|
||||||
|
"span",
|
||||||
|
"spellcheck",
|
||||||
|
"src",
|
||||||
|
"srcdoc",
|
||||||
|
"srclang",
|
||||||
|
"srcset",
|
||||||
|
"start",
|
||||||
|
"step",
|
||||||
|
"style",
|
||||||
|
"summary",
|
||||||
|
"tabindex",
|
||||||
|
"target",
|
||||||
|
"title",
|
||||||
|
"type",
|
||||||
|
"usemap",
|
||||||
|
"value",
|
||||||
|
"width"
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static interfaceName() {
|
||||||
|
return random.pick([
|
||||||
|
"HTMLBRElement",
|
||||||
|
"HTMLTableSectionElement",
|
||||||
|
"HTMLDataListElement",
|
||||||
|
"HTMLTableElement",
|
||||||
|
"HTMLOListElement",
|
||||||
|
"HTMLFontElement",
|
||||||
|
"HTMLMapElement",
|
||||||
|
"HTMLButtonElement",
|
||||||
|
"HTMLFrameSetElement",
|
||||||
|
"HTMLDataElement",
|
||||||
|
"HTMLOptGroupElement",
|
||||||
|
"HTMLAnchorElement",
|
||||||
|
"HTMLLinkElement",
|
||||||
|
"HTMLObjectElement",
|
||||||
|
"HTMLHeadElement",
|
||||||
|
"HTMLProgressElement",
|
||||||
|
"HTMLFrameElement",
|
||||||
|
"HTMLTimeElement",
|
||||||
|
"HTMLTableCaptionElement",
|
||||||
|
"HTMLDivElement",
|
||||||
|
"HTMLDListElement",
|
||||||
|
"HTMLBodyElement",
|
||||||
|
"HTMLImageElement",
|
||||||
|
"HTMLTableRowElement",
|
||||||
|
"HTMLScriptElement",
|
||||||
|
"HTMLInputElement",
|
||||||
|
"HTMLMeterElement",
|
||||||
|
"HTMLFieldSetElement",
|
||||||
|
"HTMLHtmlElement",
|
||||||
|
"HTMLStyleElement",
|
||||||
|
"HTMLDetailsElement",
|
||||||
|
"HTMLTrackElement",
|
||||||
|
"HTMLBaseElement",
|
||||||
|
"HTMLTableColElement",
|
||||||
|
"HTMLSourceElement",
|
||||||
|
"HTMLPictureElement",
|
||||||
|
"HTMLSelectElement",
|
||||||
|
"HTMLLegendElement",
|
||||||
|
"HTMLHRElement",
|
||||||
|
"HTMLModElement",
|
||||||
|
"HTMLTemplateElement",
|
||||||
|
"HTMLAreaElement",
|
||||||
|
"HTMLFormElement",
|
||||||
|
"HTMLEmbedElement",
|
||||||
|
"HTMLSpanElement",
|
||||||
|
"HTMLParagraphElement",
|
||||||
|
"HTMLIFrameElement",
|
||||||
|
"HTMLTableCellElement",
|
||||||
|
"HTMLElement",
|
||||||
|
"HTMLMenuElement",
|
||||||
|
"HTMLTextAreaElement",
|
||||||
|
"HTMLHeadingElement",
|
||||||
|
"HTMLCanvasElement",
|
||||||
|
"HTMLOutputElement",
|
||||||
|
"HTMLQuoteElement",
|
||||||
|
"HTMLOptionElement",
|
||||||
|
"HTMLLIElement",
|
||||||
|
"HTMLAudioElement",
|
||||||
|
"HTMLMenuItemElement",
|
||||||
|
"HTMLParamElement",
|
||||||
|
"HTMLUListElement",
|
||||||
|
"HTMLLabelElement",
|
||||||
|
"HTMLDirectoryElement",
|
||||||
|
"HTMLTitleElement",
|
||||||
|
"HTMLPreElement",
|
||||||
|
"HTMLMetaElement",
|
||||||
|
"HTMLVideoElement"
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static className() {
|
||||||
|
return random.item(["class_1", "class_2", "class_3", "class_4"]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,87 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
class make {
|
|
||||||
static get number () {
|
|
||||||
return require('./numbers')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get alignment () {
|
|
||||||
return require('./alignment')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get arrays () {
|
|
||||||
return require('./arrays')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get colors () {
|
|
||||||
return require('./colors')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get command () {
|
|
||||||
return require('./command')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get crypto () {
|
|
||||||
return require('./crypto')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get files () {
|
|
||||||
return require('./files')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get font () {
|
|
||||||
return require('./fonts')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get html () {
|
|
||||||
return require('./html')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get mime () {
|
|
||||||
return require('./mime')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get network () {
|
|
||||||
return require('./network')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get shaders () {
|
|
||||||
return require('./shaders')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get style () {
|
|
||||||
return require('./style')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get text () {
|
|
||||||
return require('./text')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get time () {
|
|
||||||
return require('./time')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get typed () {
|
|
||||||
return require('./typed')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get types () {
|
|
||||||
return require('./types')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get unit () {
|
|
||||||
return require('./units')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get uri () {
|
|
||||||
return require('./uri')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get webgl () {
|
|
||||||
return require('./webgl')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = make
|
|
|
@ -1,77 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
const make = require('../make')
|
|
||||||
const random = require('../random')
|
|
||||||
|
|
||||||
class mime extends make {
|
|
||||||
static any () {
|
|
||||||
return random.pick([
|
|
||||||
mime.standard,
|
|
||||||
mime.xml,
|
|
||||||
mime.image,
|
|
||||||
mime.media,
|
|
||||||
mime.form
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static standard () {
|
|
||||||
return random.pick([
|
|
||||||
'text/html',
|
|
||||||
'text/html; charset=utf-8',
|
|
||||||
'text/plain',
|
|
||||||
'text/css',
|
|
||||||
'text/javascript',
|
|
||||||
'foo/bar',
|
|
||||||
'application/octet-stream',
|
|
||||||
'application/x-shockwave-flash',
|
|
||||||
'application/x-test'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static xml () {
|
|
||||||
return random.pick([
|
|
||||||
'application/xml',
|
|
||||||
'text/xml',
|
|
||||||
'application/xhtml+xml',
|
|
||||||
'image/svg+xml',
|
|
||||||
'application/vnd.mozilla.xul+xml',
|
|
||||||
'application/rss+xml',
|
|
||||||
'application/rdf+xml',
|
|
||||||
'application/xslt+xml'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static image () {
|
|
||||||
return random.pick([
|
|
||||||
'image/jpeg',
|
|
||||||
'image/gif',
|
|
||||||
'image/png',
|
|
||||||
'image/mng',
|
|
||||||
'image/*'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static media () {
|
|
||||||
return random.pick([
|
|
||||||
'audio/mpeg',
|
|
||||||
'audio/ogg',
|
|
||||||
'audio/ogg; codecs=vorbis',
|
|
||||||
'video/ogg',
|
|
||||||
'video/ogg; codecs="theora, vorbis"',
|
|
||||||
'video/mp4',
|
|
||||||
'video/mp4; codecs="avc1.42E01E, mp4a.40.2"'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static form () {
|
|
||||||
return random.pick([
|
|
||||||
'application/x-www-form-urlencoded',
|
|
||||||
'multipart/form-data',
|
|
||||||
'text/plain'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = mime
|
|
74
lib/make/mime.ts
Normal file
74
lib/make/mime.ts
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
import random from "../random/random.ts";
|
||||||
|
|
||||||
|
export default class mime {
|
||||||
|
static any() {
|
||||||
|
return random.pick([
|
||||||
|
mime.standard,
|
||||||
|
mime.xml,
|
||||||
|
mime.image,
|
||||||
|
mime.media,
|
||||||
|
mime.form
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static standard() {
|
||||||
|
return random.pick([
|
||||||
|
"text/html",
|
||||||
|
"text/html; charset=utf-8",
|
||||||
|
"text/plain",
|
||||||
|
"text/css",
|
||||||
|
"text/javascript",
|
||||||
|
"foo/bar",
|
||||||
|
"application/octet-stream",
|
||||||
|
"application/x-shockwave-flash",
|
||||||
|
"application/x-test"
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static xml() {
|
||||||
|
return random.pick([
|
||||||
|
"application/xml",
|
||||||
|
"text/xml",
|
||||||
|
"application/xhtml+xml",
|
||||||
|
"image/svg+xml",
|
||||||
|
"application/vnd.mozilla.xul+xml",
|
||||||
|
"application/rss+xml",
|
||||||
|
"application/rdf+xml",
|
||||||
|
"application/xslt+xml"
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static image() {
|
||||||
|
return random.pick([
|
||||||
|
"image/jpeg",
|
||||||
|
"image/gif",
|
||||||
|
"image/png",
|
||||||
|
"image/mng",
|
||||||
|
"image/*"
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static media() {
|
||||||
|
return random.pick([
|
||||||
|
"audio/mpeg",
|
||||||
|
"audio/ogg",
|
||||||
|
"audio/ogg; codecs=vorbis",
|
||||||
|
"video/ogg",
|
||||||
|
'video/ogg; codecs="theora, vorbis"',
|
||||||
|
"video/mp4",
|
||||||
|
'video/mp4; codecs="avc1.42E01E, mp4a.40.2"'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static form() {
|
||||||
|
return random.pick([
|
||||||
|
"application/x-www-form-urlencoded",
|
||||||
|
"multipart/form-data",
|
||||||
|
"text/plain"
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,240 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
const make = require('../make')
|
|
||||||
const random = require('../random')
|
|
||||||
const utils = require('../utils')
|
|
||||||
|
|
||||||
class network extends make {
|
|
||||||
static sdp () {
|
|
||||||
// session description protocol template
|
|
||||||
return [
|
|
||||||
'v=0',
|
|
||||||
'o=Mozilla-SIPUA 23597 0 IN IP4 0.0.0.0',
|
|
||||||
's=SIP Call',
|
|
||||||
't=0 0',
|
|
||||||
'a=ice-ufrag:f5fda439',
|
|
||||||
'a=ice-pwd:d0df8e2904bdbd29587966e797655970',
|
|
||||||
'a=fingerprint:sha-256 DF:69:78:20:8D:2E:08:CE:49:82:A3:11:79:1D:BF:B5:49:49:2D:32:82:2F:0D:88:84:A7:C6:63:23:63:A9:0F',
|
|
||||||
'm=audio 52757 RTP/SAVPF 109 0 8 101',
|
|
||||||
'c=IN IP4 192.168.129.33',
|
|
||||||
'a=rtpmap:109 opus/48000/2',
|
|
||||||
'a=ptime:20',
|
|
||||||
'a=rtpmap:0 PCMU/8000',
|
|
||||||
'a=rtpmap:8 PCMA/8000',
|
|
||||||
'a=rtpmap:101 telephone-event/8000',
|
|
||||||
'a=fmtp:101 0-15',
|
|
||||||
'a=sendrecv',
|
|
||||||
'a=candidate:0 1 UDP 2113601791 192.168.129.33 52757 typ host',
|
|
||||||
'a=candidate:0 2 UDP 2113601790 192.168.129.33 59738 typ host',
|
|
||||||
'm=video 63901 RTP/SAVPF 120',
|
|
||||||
'c=IN IP4 192.168.129.33',
|
|
||||||
'a=rtpmap:120 VP8/90000',
|
|
||||||
'a=sendrecv',
|
|
||||||
'a=candidate:0 1 UDP 2113601791 192.168.129.33 63901 typ host',
|
|
||||||
'a=candidate:0 2 UDP 2113601790 192.168.129.33 54165 typ host',
|
|
||||||
'm=application 65080 SCTP/DTLS 5000',
|
|
||||||
'c=IN IP4 192.168.129.33',
|
|
||||||
'a=fmtp:5000 protocol=webrtc-datachannel;streams=16',
|
|
||||||
'a=sendrecv',
|
|
||||||
'a=candidate:0 1 UDP 2113601791 192.168.129.33 65080 typ host',
|
|
||||||
'a=candidate:0 2 UDP 2113601790 192.168.129.33 62658 typ host'
|
|
||||||
].join('\n')
|
|
||||||
}
|
|
||||||
|
|
||||||
static IceCandidate () {
|
|
||||||
// https://tools.ietf.org/html/rfc5245#section-15
|
|
||||||
// candidate=
|
|
||||||
return utils.block.block([
|
|
||||||
random.pick([0, 1, make.number.any]),
|
|
||||||
' ',
|
|
||||||
random.pick([0, 1, make.number.any]),
|
|
||||||
' ',
|
|
||||||
random.pick(['UDP', 'TCP', 'SCTP']),
|
|
||||||
random.pick(['', `/${random.pick(['DTLS', 'DTLS-SRTP'])}`]),
|
|
||||||
' ',
|
|
||||||
random.pick([make.number.any]),
|
|
||||||
' ',
|
|
||||||
random.pick([network.goodHostnames]),
|
|
||||||
' ',
|
|
||||||
random.pick([56187, make.number.any]),
|
|
||||||
' ',
|
|
||||||
'type',
|
|
||||||
' ',
|
|
||||||
random.pick([
|
|
||||||
'host',
|
|
||||||
utils.block.block([
|
|
||||||
random.pick(['srflx', 'prflx', 'relay']),
|
|
||||||
' ',
|
|
||||||
random.pick(['raddr']),
|
|
||||||
' ',
|
|
||||||
random.pick([network.goodHostnames]),
|
|
||||||
' ',
|
|
||||||
random.pick(['rport']),
|
|
||||||
random.use([utils.block.block([' ', make.number.any])])
|
|
||||||
])
|
|
||||||
])
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static SdpMid () {
|
|
||||||
// m=
|
|
||||||
return utils.block.block([
|
|
||||||
random.pick(['application', 'video', 'audio']),
|
|
||||||
' ',
|
|
||||||
make.number.any,
|
|
||||||
' ',
|
|
||||||
random.pick(['RTP/AVP', 'RTP/SAVPF', 'RTP/SAVP', 'SCTP/DTLS']),
|
|
||||||
' ',
|
|
||||||
make.number.any
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static Turn () {
|
|
||||||
// https://tools.ietf.org/html/rfc7065#section-3.1
|
|
||||||
return utils.block.block([
|
|
||||||
// scheme
|
|
||||||
random.pick(network.PeerConnectionProtocols),
|
|
||||||
':',
|
|
||||||
// turn-host
|
|
||||||
random.pick([
|
|
||||||
network.any,
|
|
||||||
network.hostname
|
|
||||||
]),
|
|
||||||
// turn-port
|
|
||||||
random.use([utils.block.block([':', make.number.any])]),
|
|
||||||
random.use([utils.block.block(['/', make.text.any])]),
|
|
||||||
'?',
|
|
||||||
random.pick(['transport']),
|
|
||||||
'=',
|
|
||||||
random.pick(['udp', 'tcp', make.text.any])
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static PeerConnectionProtocols () {
|
|
||||||
return ['turn', 'turns', 'stun', 'stuns']
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomIPv4 () {
|
|
||||||
function octet () {
|
|
||||||
return random.pick([random.number(255), make.number.any])
|
|
||||||
}
|
|
||||||
|
|
||||||
return `${octet()}.${octet()}.${octet()}.${octet()}.`
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomIPv6 () {
|
|
||||||
let parts = []
|
|
||||||
|
|
||||||
for (let i = 0; i < 8; i++) {
|
|
||||||
parts.push(random.hex(4))
|
|
||||||
}
|
|
||||||
|
|
||||||
return parts.join(':')
|
|
||||||
}
|
|
||||||
|
|
||||||
static iceServer () {
|
|
||||||
return random.pick([
|
|
||||||
'stun:23.21.150.121'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static dtmf () {
|
|
||||||
let count = make.number.tiny()
|
|
||||||
const values = []
|
|
||||||
while (count--) {
|
|
||||||
values.push(random.item(['*', '#', 'A', 'B', 'C', 'D', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']))
|
|
||||||
}
|
|
||||||
|
|
||||||
return values.join('')
|
|
||||||
}
|
|
||||||
|
|
||||||
static goodHostnames () {
|
|
||||||
return [
|
|
||||||
'0.0.0.0',
|
|
||||||
'127.0.0.1:8080'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
static badHostnames () {
|
|
||||||
return [
|
|
||||||
'google.org:8080',
|
|
||||||
'::1',
|
|
||||||
'[::192.9.5.5]:42',
|
|
||||||
'2001:db8:85a3::8a2e:370:3478',
|
|
||||||
'2001:db8:85a3:0:0:8a2e:370:3478',
|
|
||||||
'::ffff:192.0.2.1',
|
|
||||||
'0000:0000:0000:0000:0000:0000:0000:0001',
|
|
||||||
'::192.0.2.128',
|
|
||||||
'::ffff:192.0.2.128',
|
|
||||||
'2001:db8::1:2',
|
|
||||||
'2001:db8::1:1:1:1:1'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
static hostname () {
|
|
||||||
return random.pick([
|
|
||||||
network.randomIPv4,
|
|
||||||
network.randomIPv6,
|
|
||||||
network.goodHostnames,
|
|
||||||
network.badHostnames
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static port () {
|
|
||||||
return random.pick([80, 443, 21, 23, 9310])
|
|
||||||
}
|
|
||||||
|
|
||||||
static hash () {
|
|
||||||
return random.pick([
|
|
||||||
'',
|
|
||||||
'#',
|
|
||||||
'#main-content',
|
|
||||||
() => `#${make.text.any()}`
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static path () {
|
|
||||||
return random.pick([
|
|
||||||
'',
|
|
||||||
'/',
|
|
||||||
'/index.html',
|
|
||||||
() => `/${make.text.any()}`
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static protocol () {
|
|
||||||
return `${random.pick([
|
|
||||||
'http',
|
|
||||||
'https',
|
|
||||||
'ftp',
|
|
||||||
'telnet',
|
|
||||||
'chrome',
|
|
||||||
'resource'
|
|
||||||
])}:`
|
|
||||||
}
|
|
||||||
|
|
||||||
static search () {
|
|
||||||
return random.pick([
|
|
||||||
'',
|
|
||||||
'?',
|
|
||||||
'?foo=bar',
|
|
||||||
() => `?${make.text.any()}`
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomBitmask (list) {
|
|
||||||
if (list.length <= 1) {
|
|
||||||
return list.join('')
|
|
||||||
}
|
|
||||||
let max = random.range(2, list.length)
|
|
||||||
let mask = random.pick(list)
|
|
||||||
for (let i = 1; i < max; i++) {
|
|
||||||
mask += `|${random.pick(list)}`
|
|
||||||
}
|
|
||||||
return mask
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = network
|
|
271
lib/make/network.ts
Normal file
271
lib/make/network.ts
Normal file
|
@ -0,0 +1,271 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
import random from "../random/random.ts";
|
||||||
|
import numbers from "./numbers.ts";
|
||||||
|
import text from "./text.ts";
|
||||||
|
|
||||||
|
class block {
|
||||||
|
static block (list, optional?) {
|
||||||
|
if (optional === true) {
|
||||||
|
if (random.chance(6)) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function deeper (item) {
|
||||||
|
if (item === null || item === undefined) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
if (typeof (item) === 'function') {
|
||||||
|
return item()
|
||||||
|
}
|
||||||
|
if (typeof (item) === 'string') {
|
||||||
|
return item
|
||||||
|
}
|
||||||
|
if (Array.isArray(item)) {
|
||||||
|
let s = ''
|
||||||
|
for (let i = 0; i < item.length; i++) {
|
||||||
|
s += deeper(item[i])
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
return item
|
||||||
|
}
|
||||||
|
|
||||||
|
let asString = ''
|
||||||
|
for (let i = 0; i < list.length; i++) {
|
||||||
|
asString += deeper(list[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
return asString
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class network {
|
||||||
|
static sdp() {
|
||||||
|
// session description protocol template
|
||||||
|
return [
|
||||||
|
"v=0",
|
||||||
|
"o=Mozilla-SIPUA 23597 0 IN IP4 0.0.0.0",
|
||||||
|
"s=SIP Call",
|
||||||
|
"t=0 0",
|
||||||
|
"a=ice-ufrag:f5fda439",
|
||||||
|
"a=ice-pwd:d0df8e2904bdbd29587966e797655970",
|
||||||
|
"a=fingerprint:sha-256 DF:69:78:20:8D:2E:08:CE:49:82:A3:11:79:1D:BF:B5:49:49:2D:32:82:2F:0D:88:84:A7:C6:63:23:63:A9:0F",
|
||||||
|
"m=audio 52757 RTP/SAVPF 109 0 8 101",
|
||||||
|
"c=IN IP4 192.168.129.33",
|
||||||
|
"a=rtpmap:109 opus/48000/2",
|
||||||
|
"a=ptime:20",
|
||||||
|
"a=rtpmap:0 PCMU/8000",
|
||||||
|
"a=rtpmap:8 PCMA/8000",
|
||||||
|
"a=rtpmap:101 telephone-event/8000",
|
||||||
|
"a=fmtp:101 0-15",
|
||||||
|
"a=sendrecv",
|
||||||
|
"a=candidate:0 1 UDP 2113601791 192.168.129.33 52757 typ host",
|
||||||
|
"a=candidate:0 2 UDP 2113601790 192.168.129.33 59738 typ host",
|
||||||
|
"m=video 63901 RTP/SAVPF 120",
|
||||||
|
"c=IN IP4 192.168.129.33",
|
||||||
|
"a=rtpmap:120 VP8/90000",
|
||||||
|
"a=sendrecv",
|
||||||
|
"a=candidate:0 1 UDP 2113601791 192.168.129.33 63901 typ host",
|
||||||
|
"a=candidate:0 2 UDP 2113601790 192.168.129.33 54165 typ host",
|
||||||
|
"m=application 65080 SCTP/DTLS 5000",
|
||||||
|
"c=IN IP4 192.168.129.33",
|
||||||
|
"a=fmtp:5000 protocol=webrtc-datachannel;streams=16",
|
||||||
|
"a=sendrecv",
|
||||||
|
"a=candidate:0 1 UDP 2113601791 192.168.129.33 65080 typ host",
|
||||||
|
"a=candidate:0 2 UDP 2113601790 192.168.129.33 62658 typ host"
|
||||||
|
].join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static IceCandidate() {
|
||||||
|
// https://tools.ietf.org/html/rfc5245#section-15
|
||||||
|
// candidate=
|
||||||
|
return block.block([
|
||||||
|
random.pick([0, 1, numbers.any]),
|
||||||
|
" ",
|
||||||
|
random.pick([0, 1, numbers.any]),
|
||||||
|
" ",
|
||||||
|
random.pick(["UDP", "TCP", "SCTP"]),
|
||||||
|
random.pick(["", `/${random.pick(["DTLS", "DTLS-SRTP"])}`]),
|
||||||
|
" ",
|
||||||
|
random.pick([numbers.any]),
|
||||||
|
" ",
|
||||||
|
random.pick([network.goodHostnames]),
|
||||||
|
" ",
|
||||||
|
random.pick([56187, numbers.any]),
|
||||||
|
" ",
|
||||||
|
"type",
|
||||||
|
" ",
|
||||||
|
random.pick([
|
||||||
|
"host",
|
||||||
|
block.block([
|
||||||
|
random.pick(["srflx", "prflx", "relay"]),
|
||||||
|
" ",
|
||||||
|
random.pick(["raddr"]),
|
||||||
|
" ",
|
||||||
|
random.pick([network.goodHostnames]),
|
||||||
|
" ",
|
||||||
|
random.pick(["rport"]),
|
||||||
|
random.use([block.block([" ", numbers.any])])
|
||||||
|
])
|
||||||
|
])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static SdpMid() {
|
||||||
|
// m=
|
||||||
|
return block.block([
|
||||||
|
random.pick(["application", "video", "audio"]),
|
||||||
|
" ",
|
||||||
|
numbers.any,
|
||||||
|
" ",
|
||||||
|
random.pick(["RTP/AVP", "RTP/SAVPF", "RTP/SAVP", "SCTP/DTLS"]),
|
||||||
|
" ",
|
||||||
|
numbers.any
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Turn() {
|
||||||
|
// https://tools.ietf.org/html/rfc7065#section-3.1
|
||||||
|
return block.block([
|
||||||
|
// scheme
|
||||||
|
random.pick(network.PeerConnectionProtocols),
|
||||||
|
":",
|
||||||
|
// turn-host
|
||||||
|
random.pick(["1.2.3.4", network.hostname]),
|
||||||
|
// turn-port
|
||||||
|
random.use([block.block([":", numbers.any])]),
|
||||||
|
random.use([block.block(["/", text.any])]),
|
||||||
|
"?",
|
||||||
|
random.pick(["transport"]),
|
||||||
|
"=",
|
||||||
|
random.pick(["udp", "tcp", text.any])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static PeerConnectionProtocols() {
|
||||||
|
return ["turn", "turns", "stun", "stuns"];
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomIPv4() {
|
||||||
|
function octet() {
|
||||||
|
return random.pick([random.number(255), numbers.any]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${octet()}.${octet()}.${octet()}.${octet()}.`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomIPv6() {
|
||||||
|
let parts = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < 8; i++) {
|
||||||
|
parts.push(random.hex(4));
|
||||||
|
}
|
||||||
|
|
||||||
|
return parts.join(":");
|
||||||
|
}
|
||||||
|
|
||||||
|
static iceServer() {
|
||||||
|
return random.pick(["stun:23.21.150.121"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static dtmf() {
|
||||||
|
let count = numbers.tiny();
|
||||||
|
const values = [];
|
||||||
|
while (count--) {
|
||||||
|
values.push(
|
||||||
|
random.item([
|
||||||
|
"*",
|
||||||
|
"#",
|
||||||
|
"A",
|
||||||
|
"B",
|
||||||
|
"C",
|
||||||
|
"D",
|
||||||
|
"0",
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"3",
|
||||||
|
"4",
|
||||||
|
"5",
|
||||||
|
"6",
|
||||||
|
"7",
|
||||||
|
"8",
|
||||||
|
"9"
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return values.join("");
|
||||||
|
}
|
||||||
|
|
||||||
|
static goodHostnames() {
|
||||||
|
return ["0.0.0.0", "127.0.0.1:8080"];
|
||||||
|
}
|
||||||
|
|
||||||
|
static badHostnames() {
|
||||||
|
return [
|
||||||
|
"google.org:8080",
|
||||||
|
"::1",
|
||||||
|
"[::192.9.5.5]:42",
|
||||||
|
"2001:db8:85a3::8a2e:370:3478",
|
||||||
|
"2001:db8:85a3:0:0:8a2e:370:3478",
|
||||||
|
"::ffff:192.0.2.1",
|
||||||
|
"0000:0000:0000:0000:0000:0000:0000:0001",
|
||||||
|
"::192.0.2.128",
|
||||||
|
"::ffff:192.0.2.128",
|
||||||
|
"2001:db8::1:2",
|
||||||
|
"2001:db8::1:1:1:1:1"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
static hostname() {
|
||||||
|
return random.pick([
|
||||||
|
network.randomIPv4,
|
||||||
|
network.randomIPv6,
|
||||||
|
network.goodHostnames,
|
||||||
|
network.badHostnames
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static port() {
|
||||||
|
return random.pick([80, 443, 21, 23, 9310]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static hash() {
|
||||||
|
return random.pick(["", "#", "#main-content", () => `#${text.any()}`]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static path() {
|
||||||
|
return random.pick(["", "/", "/index.html", () => `/${text.any()}`]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static protocol() {
|
||||||
|
return `${random.pick([
|
||||||
|
"http",
|
||||||
|
"https",
|
||||||
|
"ftp",
|
||||||
|
"telnet",
|
||||||
|
"chrome",
|
||||||
|
"resource"
|
||||||
|
])}:`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static search() {
|
||||||
|
return random.pick(["", "?", "?foo=bar", () => `?${text.any()}`]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomBitmask(list) {
|
||||||
|
if (list.length <= 1) {
|
||||||
|
return list.join("");
|
||||||
|
}
|
||||||
|
let max = random.range(2, list.length);
|
||||||
|
let mask = random.pick(list);
|
||||||
|
for (let i = 1; i < max; i++) {
|
||||||
|
mask += `|${random.pick(list)}`;
|
||||||
|
}
|
||||||
|
return mask;
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,10 +2,9 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
const make = require('../make')
|
import random from "../random/random.ts";
|
||||||
const random = require('../random')
|
|
||||||
|
|
||||||
class number extends make {
|
export default class numbers {
|
||||||
/**
|
/**
|
||||||
* Returns a number that is more likely to exceed the supplied boundary
|
* Returns a number that is more likely to exceed the supplied boundary
|
||||||
* @param value {number}
|
* @param value {number}
|
||||||
|
@ -33,7 +32,7 @@ class number extends make {
|
||||||
*/
|
*/
|
||||||
static int8 (bypass = false) {
|
static int8 (bypass = false) {
|
||||||
if (bypass || random.chance(50)) {
|
if (bypass || random.chance(50)) {
|
||||||
return number._exceed(random.choose([
|
return numbers._exceed(random.choose([
|
||||||
[1, -128],
|
[1, -128],
|
||||||
[10, 127]
|
[10, 127]
|
||||||
]))
|
]))
|
||||||
|
@ -49,7 +48,7 @@ class number extends make {
|
||||||
*/
|
*/
|
||||||
static uint8 (bypass = false) {
|
static uint8 (bypass = false) {
|
||||||
if (bypass || random.chance(50)) {
|
if (bypass || random.chance(50)) {
|
||||||
return number._exceed(255)
|
return numbers._exceed(255)
|
||||||
}
|
}
|
||||||
|
|
||||||
return random.range(0, 255)
|
return random.range(0, 255)
|
||||||
|
@ -62,7 +61,7 @@ class number extends make {
|
||||||
*/
|
*/
|
||||||
static int16 (bypass = false) {
|
static int16 (bypass = false) {
|
||||||
if (bypass || random.chance(50)) {
|
if (bypass || random.chance(50)) {
|
||||||
return number._exceed(random.choose([
|
return numbers._exceed(random.choose([
|
||||||
[1, -32768],
|
[1, -32768],
|
||||||
[10, 32767]
|
[10, 32767]
|
||||||
]))
|
]))
|
||||||
|
@ -78,7 +77,7 @@ class number extends make {
|
||||||
*/
|
*/
|
||||||
static uint16 (bypass = false) {
|
static uint16 (bypass = false) {
|
||||||
if (bypass || random.chance(50)) {
|
if (bypass || random.chance(50)) {
|
||||||
return number._exceed(65535)
|
return numbers._exceed(65535)
|
||||||
}
|
}
|
||||||
|
|
||||||
return random.range(-0, 65535)
|
return random.range(-0, 65535)
|
||||||
|
@ -91,7 +90,7 @@ class number extends make {
|
||||||
*/
|
*/
|
||||||
static int32 (bypass = false) {
|
static int32 (bypass = false) {
|
||||||
if (bypass || random.chance(50)) {
|
if (bypass || random.chance(50)) {
|
||||||
return number._exceed(random.choose([
|
return numbers._exceed(random.choose([
|
||||||
[1, -2147483648],
|
[1, -2147483648],
|
||||||
[10, 2147483647]
|
[10, 2147483647]
|
||||||
]))
|
]))
|
||||||
|
@ -107,7 +106,7 @@ class number extends make {
|
||||||
*/
|
*/
|
||||||
static uint32 (bypass = false) {
|
static uint32 (bypass = false) {
|
||||||
if (bypass || random.chance(50)) {
|
if (bypass || random.chance(50)) {
|
||||||
return number._exceed(4294967295)
|
return numbers._exceed(4294967295)
|
||||||
}
|
}
|
||||||
|
|
||||||
return random.range(0, 4294967295)
|
return random.range(0, 4294967295)
|
||||||
|
@ -161,11 +160,11 @@ class number extends make {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a random number adjacent to the supplied number
|
* Returns a random number adjacent to the supplied number
|
||||||
* @param {number} number
|
* @param {num} number
|
||||||
* @returns {number}
|
* @returns {num}
|
||||||
*/
|
*/
|
||||||
static even (number) {
|
static even (num) {
|
||||||
return number % 2 === 1 ? ++number : number
|
return num % 2 === 1 ? ++num : num
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -186,9 +185,9 @@ class number extends make {
|
||||||
*/
|
*/
|
||||||
static signed () {
|
static signed () {
|
||||||
return random.choose([
|
return random.choose([
|
||||||
[50, [number.int8]],
|
[50, [numbers.int8]],
|
||||||
[30, [number.int16]],
|
[30, [numbers.int16]],
|
||||||
[1, [number.int32]]
|
[1, [numbers.int32]]
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,9 +197,9 @@ class number extends make {
|
||||||
*/
|
*/
|
||||||
static unsigned () {
|
static unsigned () {
|
||||||
return random.choose([
|
return random.choose([
|
||||||
[50, [number.uint8]],
|
[50, [numbers.uint8]],
|
||||||
[30, [number.uint16]],
|
[30, [numbers.uint16]],
|
||||||
[1, [number.uint32]]
|
[1, [numbers.uint32]]
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,11 +209,10 @@ class number extends make {
|
||||||
*/
|
*/
|
||||||
static any () {
|
static any () {
|
||||||
return random.choose([
|
return random.choose([
|
||||||
[50, [number.int8, number.uint8]],
|
[50, [numbers.int8, numbers.uint8]],
|
||||||
[30, [number.int16, number.uint16]],
|
[30, [numbers.int16, numbers.uint16]],
|
||||||
[1, [number.int32, number.uint32]]
|
[1, [numbers.int32, numbers.uint32]]
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = number
|
|
|
@ -1,156 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
const random = require('../random')
|
|
||||||
const make = require('../make')
|
|
||||||
const utils = require('../utils')
|
|
||||||
|
|
||||||
class shaders extends make {
|
|
||||||
static get fragment1 () {
|
|
||||||
return [
|
|
||||||
[
|
|
||||||
'#ifdef GL_ES',
|
|
||||||
'precision mediump float;',
|
|
||||||
'#endif',
|
|
||||||
'varying vec4 vColor;',
|
|
||||||
'void main() {',
|
|
||||||
'gl_FragColor=vColor;',
|
|
||||||
'}'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'varying highp vec2 vTextureCoord;',
|
|
||||||
'varying highp vec3 vLighting;',
|
|
||||||
'uniform sampler2D uSampler;',
|
|
||||||
'void main(void) {',
|
|
||||||
'highp vec4 texelColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));',
|
|
||||||
'gl_FragColor = vec4(texelColor.rgb * vLighting, texelColor.a);',
|
|
||||||
'}'
|
|
||||||
]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
static get vertex1 () {
|
|
||||||
return [
|
|
||||||
[
|
|
||||||
'attribute vec4 aVertex;',
|
|
||||||
'attribute vec4 aColor;',
|
|
||||||
'varying vec4 vColor;',
|
|
||||||
'void main(){',
|
|
||||||
'vColor=aColor;',
|
|
||||||
'gl_Position=aVertex;',
|
|
||||||
'}'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'attribute highp vec3 aVertexNormal;',
|
|
||||||
'attribute highp vec3 aVertexPosition;',
|
|
||||||
'attribute highp vec2 aTextureCoord;',
|
|
||||||
'uniform highp mat4 uNormalMatrix;',
|
|
||||||
'uniform highp mat4 uMVMatrix;',
|
|
||||||
'uniform highp mat4 uPMatrix;',
|
|
||||||
'varying highp vec2 vTextureCoord;',
|
|
||||||
'varying highp vec3 vLighting;',
|
|
||||||
'void main(void) {',
|
|
||||||
'gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);',
|
|
||||||
'vTextureCoord = aTextureCoord;',
|
|
||||||
'highp vec3 ambientLight = vec3(0.6, 0.6, 0.6);',
|
|
||||||
'highp vec3 directionalLightColor = vec3(0.5, 0.5, 0.75);',
|
|
||||||
'highp vec3 directionalVector = vec3(0.85, 0.8, 0.75);',
|
|
||||||
'highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0);',
|
|
||||||
'highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0);',
|
|
||||||
'vLighting = ambientLight + (directionalLightColor * directional);',
|
|
||||||
'}'
|
|
||||||
]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
static get fragment2 () {
|
|
||||||
return [
|
|
||||||
[
|
|
||||||
'varying highp vec2 vTextureCoord;',
|
|
||||||
'varying highp vec3 vLighting;',
|
|
||||||
'uniform sampler2D uSampler;',
|
|
||||||
'void main(void) {',
|
|
||||||
'highp vec4 texelColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));',
|
|
||||||
'gl_FragColor = vec4(texelColor.rgb * vLighting, texelColor.a);',
|
|
||||||
'}'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'#version proto-200',
|
|
||||||
'uniform sampler2D albedoMap;',
|
|
||||||
'uniform sampler2D normalMap;',
|
|
||||||
'varying vec3 varyingTangent;',
|
|
||||||
'varying vec3 varyingBitangent;',
|
|
||||||
'varying vec3 varyingNormal;',
|
|
||||||
'varying vec2 varyingUV;',
|
|
||||||
'void main(void) {',
|
|
||||||
'vec3 albedo=texture2D(albedoMap,varyingUV).rgb;',
|
|
||||||
'vec3 normal=texture2D(normalMap,varyingUV).rgb*2.0-1.0;',
|
|
||||||
'float specularFactor=pow((albedo.r+albedo.g+albedo.b)*0.33,2.0);',
|
|
||||||
'float specularHardness=2.0;',
|
|
||||||
'vec3 spaceNormal=varyingTangent*normal.x+varyingBitangent*normal.y+varyingNormal*normal.z;',
|
|
||||||
'gl_FragData[0]=vec4(albedo,1.0);',
|
|
||||||
'gl_FragData[1]=vec4(spaceNormal*0.5 +0.5,1.0);',
|
|
||||||
'gl_FragData[2]=vec4(specularFactor,specularHardness*0.1,0.0,1.0);',
|
|
||||||
'}'
|
|
||||||
]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
static get vertex2 () {
|
|
||||||
return [
|
|
||||||
[
|
|
||||||
'attribute highp vec3 aVertexNormal;',
|
|
||||||
'attribute highp vec3 aVertexPosition;',
|
|
||||||
'attribute highp vec2 aTextureCoord;',
|
|
||||||
'uniform highp mat4 uNormalMatrix;',
|
|
||||||
'uniform highp mat4 uMVMatrix;',
|
|
||||||
'uniform highp mat4 uPMatrix;',
|
|
||||||
'varying highp vec2 vTextureCoord;',
|
|
||||||
'varying highp vec3 vLighting;',
|
|
||||||
'void main(void) {',
|
|
||||||
'gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);',
|
|
||||||
'vTextureCoord = aTextureCoord;',
|
|
||||||
'highp vec3 ambientLight = vec3(0.6, 0.6, 0.6);',
|
|
||||||
'highp vec3 directionalLightColor = vec3(0.5, 0.5, 0.75);',
|
|
||||||
'highp vec3 directionalVector = vec3(0.85, 0.8, 0.75);',
|
|
||||||
'highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0);',
|
|
||||||
'highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0);',
|
|
||||||
'vLighting = ambientLight + (directionalLightColor * directional);',
|
|
||||||
'}'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'#version proto-200',
|
|
||||||
'attribute vec3 vertexPosition;',
|
|
||||||
'attribute vec3 vertexTangent;',
|
|
||||||
'attribute vec3 vertexBitangent;',
|
|
||||||
'attribute vec3 vertexNormal;',
|
|
||||||
'attribute vec2 vertexUV;',
|
|
||||||
'uniform mat4 modelMatrix;',
|
|
||||||
'uniform mat4 viewMatrix;',
|
|
||||||
'varying vec3 varyingTangent;',
|
|
||||||
'varying vec3 varyingBitangent;',
|
|
||||||
'varying vec3 varyingNormal;',
|
|
||||||
'varying vec2 varyingUV;',
|
|
||||||
'void main(void){',
|
|
||||||
'gl_Position=viewMatrix*(modelMatrix*vec4(vertexPosition,1.0));',
|
|
||||||
'gl_Position.xy=gl_Position.xy*0.5+(float(gl_InstanceID)-0.5);',
|
|
||||||
'varyingTangent=(modelMatrix*vec4(vertexTangent,0.0)).xyz;',
|
|
||||||
'varyingBitangent=(modelMatrix*vec4(vertexBitangent,0.0)).xyz;',
|
|
||||||
'varyingNormal=(modelMatrix*vec4(vertexNormal,0.0)).xyz;',
|
|
||||||
'varyingUV = vertexUV;',
|
|
||||||
'}'
|
|
||||||
]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
static shaderPair (v, f) {
|
|
||||||
let i = random.number(v.length)
|
|
||||||
return {
|
|
||||||
vertex: utils.common.quote(v[i].join(' ')),
|
|
||||||
fragment: utils.common.quote(f[i].join(' '))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = shaders
|
|
152
lib/make/shaders.ts
Normal file
152
lib/make/shaders.ts
Normal file
|
@ -0,0 +1,152 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
import random from "../random/random.ts";
|
||||||
|
|
||||||
|
export default class shaders {
|
||||||
|
static get fragment1() {
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
"#ifdef GL_ES",
|
||||||
|
"precision mediump float;",
|
||||||
|
"#endif",
|
||||||
|
"varying vec4 vColor;",
|
||||||
|
"void main() {",
|
||||||
|
"gl_FragColor=vColor;",
|
||||||
|
"}"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"varying highp vec2 vTextureCoord;",
|
||||||
|
"varying highp vec3 vLighting;",
|
||||||
|
"uniform sampler2D uSampler;",
|
||||||
|
"void main(void) {",
|
||||||
|
"highp vec4 texelColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));",
|
||||||
|
"gl_FragColor = vec4(texelColor.rgb * vLighting, texelColor.a);",
|
||||||
|
"}"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
static get vertex1() {
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
"attribute vec4 aVertex;",
|
||||||
|
"attribute vec4 aColor;",
|
||||||
|
"varying vec4 vColor;",
|
||||||
|
"void main(){",
|
||||||
|
"vColor=aColor;",
|
||||||
|
"gl_Position=aVertex;",
|
||||||
|
"}"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"attribute highp vec3 aVertexNormal;",
|
||||||
|
"attribute highp vec3 aVertexPosition;",
|
||||||
|
"attribute highp vec2 aTextureCoord;",
|
||||||
|
"uniform highp mat4 uNormalMatrix;",
|
||||||
|
"uniform highp mat4 uMVMatrix;",
|
||||||
|
"uniform highp mat4 uPMatrix;",
|
||||||
|
"varying highp vec2 vTextureCoord;",
|
||||||
|
"varying highp vec3 vLighting;",
|
||||||
|
"void main(void) {",
|
||||||
|
"gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);",
|
||||||
|
"vTextureCoord = aTextureCoord;",
|
||||||
|
"highp vec3 ambientLight = vec3(0.6, 0.6, 0.6);",
|
||||||
|
"highp vec3 directionalLightColor = vec3(0.5, 0.5, 0.75);",
|
||||||
|
"highp vec3 directionalVector = vec3(0.85, 0.8, 0.75);",
|
||||||
|
"highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0);",
|
||||||
|
"highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0);",
|
||||||
|
"vLighting = ambientLight + (directionalLightColor * directional);",
|
||||||
|
"}"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
static get fragment2() {
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
"varying highp vec2 vTextureCoord;",
|
||||||
|
"varying highp vec3 vLighting;",
|
||||||
|
"uniform sampler2D uSampler;",
|
||||||
|
"void main(void) {",
|
||||||
|
"highp vec4 texelColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));",
|
||||||
|
"gl_FragColor = vec4(texelColor.rgb * vLighting, texelColor.a);",
|
||||||
|
"}"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"#version proto-200",
|
||||||
|
"uniform sampler2D albedoMap;",
|
||||||
|
"uniform sampler2D normalMap;",
|
||||||
|
"varying vec3 varyingTangent;",
|
||||||
|
"varying vec3 varyingBitangent;",
|
||||||
|
"varying vec3 varyingNormal;",
|
||||||
|
"varying vec2 varyingUV;",
|
||||||
|
"void main(void) {",
|
||||||
|
"vec3 albedo=texture2D(albedoMap,varyingUV).rgb;",
|
||||||
|
"vec3 normal=texture2D(normalMap,varyingUV).rgb*2.0-1.0;",
|
||||||
|
"float specularFactor=pow((albedo.r+albedo.g+albedo.b)*0.33,2.0);",
|
||||||
|
"float specularHardness=2.0;",
|
||||||
|
"vec3 spaceNormal=varyingTangent*normal.x+varyingBitangent*normal.y+varyingNormal*normal.z;",
|
||||||
|
"gl_FragData[0]=vec4(albedo,1.0);",
|
||||||
|
"gl_FragData[1]=vec4(spaceNormal*0.5 +0.5,1.0);",
|
||||||
|
"gl_FragData[2]=vec4(specularFactor,specularHardness*0.1,0.0,1.0);",
|
||||||
|
"}"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
static get vertex2() {
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
"attribute highp vec3 aVertexNormal;",
|
||||||
|
"attribute highp vec3 aVertexPosition;",
|
||||||
|
"attribute highp vec2 aTextureCoord;",
|
||||||
|
"uniform highp mat4 uNormalMatrix;",
|
||||||
|
"uniform highp mat4 uMVMatrix;",
|
||||||
|
"uniform highp mat4 uPMatrix;",
|
||||||
|
"varying highp vec2 vTextureCoord;",
|
||||||
|
"varying highp vec3 vLighting;",
|
||||||
|
"void main(void) {",
|
||||||
|
"gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);",
|
||||||
|
"vTextureCoord = aTextureCoord;",
|
||||||
|
"highp vec3 ambientLight = vec3(0.6, 0.6, 0.6);",
|
||||||
|
"highp vec3 directionalLightColor = vec3(0.5, 0.5, 0.75);",
|
||||||
|
"highp vec3 directionalVector = vec3(0.85, 0.8, 0.75);",
|
||||||
|
"highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0);",
|
||||||
|
"highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0);",
|
||||||
|
"vLighting = ambientLight + (directionalLightColor * directional);",
|
||||||
|
"}"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"#version proto-200",
|
||||||
|
"attribute vec3 vertexPosition;",
|
||||||
|
"attribute vec3 vertexTangent;",
|
||||||
|
"attribute vec3 vertexBitangent;",
|
||||||
|
"attribute vec3 vertexNormal;",
|
||||||
|
"attribute vec2 vertexUV;",
|
||||||
|
"uniform mat4 modelMatrix;",
|
||||||
|
"uniform mat4 viewMatrix;",
|
||||||
|
"varying vec3 varyingTangent;",
|
||||||
|
"varying vec3 varyingBitangent;",
|
||||||
|
"varying vec3 varyingNormal;",
|
||||||
|
"varying vec2 varyingUV;",
|
||||||
|
"void main(void){",
|
||||||
|
"gl_Position=viewMatrix*(modelMatrix*vec4(vertexPosition,1.0));",
|
||||||
|
"gl_Position.xy=gl_Position.xy*0.5+(float(gl_InstanceID)-0.5);",
|
||||||
|
"varyingTangent=(modelMatrix*vec4(vertexTangent,0.0)).xyz;",
|
||||||
|
"varyingBitangent=(modelMatrix*vec4(vertexBitangent,0.0)).xyz;",
|
||||||
|
"varyingNormal=(modelMatrix*vec4(vertexNormal,0.0)).xyz;",
|
||||||
|
"varyingUV = vertexUV;",
|
||||||
|
"}"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
static shaderPair(v, f) {
|
||||||
|
let i = random.number(v.length);
|
||||||
|
return {
|
||||||
|
vertex: v[i].join(" "),
|
||||||
|
fragment: f[i].join(" ")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,25 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
const make = require('../make')
|
|
||||||
const random = require('../random')
|
|
||||||
|
|
||||||
class style extends make {
|
|
||||||
static pseudoElement () {
|
|
||||||
return random.item([
|
|
||||||
'::after',
|
|
||||||
'::before',
|
|
||||||
'::cue',
|
|
||||||
'::first-letter',
|
|
||||||
'::first-line',
|
|
||||||
'::selection',
|
|
||||||
'::backdrop',
|
|
||||||
'::placeholder',
|
|
||||||
'::marker',
|
|
||||||
'::spelling-error',
|
|
||||||
'::grammar-error'])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = style
|
|
23
lib/make/style.ts
Normal file
23
lib/make/style.ts
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
import random from "../random/random.ts";
|
||||||
|
|
||||||
|
export default class style {
|
||||||
|
static pseudoElement() {
|
||||||
|
return random.item([
|
||||||
|
"::after",
|
||||||
|
"::before",
|
||||||
|
"::cue",
|
||||||
|
"::first-letter",
|
||||||
|
"::first-line",
|
||||||
|
"::selection",
|
||||||
|
"::backdrop",
|
||||||
|
"::placeholder",
|
||||||
|
"::marker",
|
||||||
|
"::spelling-error",
|
||||||
|
"::grammar-error"
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
340
lib/make/text.js
340
lib/make/text.js
|
@ -1,340 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
const random = require('../random')
|
|
||||||
const make = require('../make')
|
|
||||||
const utils = require('../utils')
|
|
||||||
|
|
||||||
class text extends make {
|
|
||||||
/**
|
|
||||||
* Generate a random alphabetic character
|
|
||||||
*/
|
|
||||||
static alpha () {
|
|
||||||
return String.fromCharCode(random.range('A'.charCodeAt(0), 'z'.charCodeAt(0)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a random alphanumeric character
|
|
||||||
*/
|
|
||||||
static alphanum () {
|
|
||||||
return String.fromCharCode(random.range('0'.charCodeAt(0), 'z'.charCodeAt(0)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a random assignment operator
|
|
||||||
*/
|
|
||||||
static assignmentOperator () {
|
|
||||||
return random.pick([
|
|
||||||
'=', '+=', '-=', '*=', '/=', '%=', '**=', '<<=', '>>=', '>>>=', '&=', '^=', '|='
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a random arithmetic operator
|
|
||||||
*/
|
|
||||||
static arithmeticOperator () {
|
|
||||||
return random.pick([
|
|
||||||
'%', '-', '+', '*', '/'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a random control character
|
|
||||||
*/
|
|
||||||
static controlChar () {
|
|
||||||
return random.pick([
|
|
||||||
'\b', '\t', '\n', '\v', '\f', '\r', '\0', '\c', '\a', '\e' // eslint-disable-line no-useless-escape
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a random digit
|
|
||||||
*/
|
|
||||||
static digit () {
|
|
||||||
return String.fromCharCode(random.range('0'.charCodeAt(0), '9'.charCodeAt(0)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a random line ending
|
|
||||||
*/
|
|
||||||
static lineEnd () {
|
|
||||||
return random.pick([
|
|
||||||
'\n', '\r', '\r\n', '\n\r'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a random token
|
|
||||||
*/
|
|
||||||
static token () {
|
|
||||||
return random.pick([
|
|
||||||
'*', '+', '%', '-', '!', '^', ':', '|', '&', '<', '>', '.', '"',
|
|
||||||
'#', ' ', ';', ',', '{', '}', '(', ')', '[', ']', '/', '\\', '/*', '*/'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static charset () {
|
|
||||||
return random.pick([
|
|
||||||
'UTF-8', 'ISO-8859-1'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static language () {
|
|
||||||
return random.pick([
|
|
||||||
// special casing for i, I, dotted/dotless variants
|
|
||||||
['tr', 'az', 'crh', 'tt', 'ba'],
|
|
||||||
// special casing rules: https://developer.mozilla.org/en/CSS/text-transform
|
|
||||||
['nl', 'el', 'ga'],
|
|
||||||
// special justification rules
|
|
||||||
['ja', 'zh'],
|
|
||||||
// tend to be RTL
|
|
||||||
['ar', 'he'],
|
|
||||||
// http://mxr.mozilla.org/mozilla-central/source/gfx/thebes/gfxAtomList.h
|
|
||||||
['en', 'x-unicode', 'x-western', 'ja', 'ko', 'zh-cn', 'zh-hk', 'zh-tw', 'x-cyrillic', 'el', 'tr', 'he', 'ar', 'x-baltic', 'th', 'x-devanagari', 'x-tamil', 'x-armn', 'x-beng', 'x-cans', 'x-ethi', 'x-geor', 'x-gujr', 'x-guru', 'x-khmr', 'x-knda', 'x-mlym', 'x-orya', 'x-sinh', 'x-telu', 'x-tibt', 'ko-xxx', 'x-central-euro', 'x-symbol', 'x-user-def', 'az', 'ba', 'crh', 'tt'],
|
|
||||||
// Seen in mxr
|
|
||||||
['en-US', 'fr', 'fra', 'de', 'ru', 'en-us', 'is-IS', 'xyzzy']
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a random character that may affect layout
|
|
||||||
*/
|
|
||||||
static layoutCharCodes () {
|
|
||||||
return String.fromCodePoint(
|
|
||||||
random.pick([
|
|
||||||
0, // null
|
|
||||||
160, // non-breaking space
|
|
||||||
0x005C, // backslash, but in some countries, represents local currency symbol (e.g. yen)
|
|
||||||
0x00AD, // soft hyphen
|
|
||||||
0x0BCC, // a Tamil character that is displayed as three glyphs
|
|
||||||
// http://unicode.org/charts/PDF/U2000.pdf
|
|
||||||
0x200B, // zero-width space
|
|
||||||
0x200C, // zero-width non-joiner
|
|
||||||
0x200D, // zero-width joiner
|
|
||||||
0x200E, // left-to-right mark
|
|
||||||
0x200F, // right-to-left mark
|
|
||||||
0x2011, // non-breaking hyphen
|
|
||||||
0x2027, // hyphenation point
|
|
||||||
0x2028, // line separator
|
|
||||||
0x2029, // paragraph separator
|
|
||||||
0x202A, // left-to-right embedding
|
|
||||||
0x202B, // right-to-left embedding
|
|
||||||
0x202C, // pop directional formatting
|
|
||||||
0x202D, // left-to-right override
|
|
||||||
0x202E, // right-to-left override
|
|
||||||
0x202F, // narrow no-break space
|
|
||||||
0x2060, // word joiner
|
|
||||||
0x2061, // function application (one of several invisible mathematical operators)
|
|
||||||
// http://unicode.org/charts/PDF/U3000.pdf
|
|
||||||
0x3000, // ideographic space (CJK)
|
|
||||||
// http://unicode.org/charts/PDF/U0300.pdf
|
|
||||||
0x0301, // combining acute accent (if it appears after "a", it turns into "a" with an accent)
|
|
||||||
// Arabic has the interesting property that most letters connect to the next letter.
|
|
||||||
// Some code calls this "shaping".
|
|
||||||
0x0643, // arabic letter kaf
|
|
||||||
0x0645, // arabic letter meem
|
|
||||||
0x06CD, // arabic letter yeh with tail
|
|
||||||
0xFDDE, // invalid unicode? but somehow associated with arabic.
|
|
||||||
// http://unicode.org/reports/tr36/tr36-7.html#Buffer_Overflows
|
|
||||||
// Characters with especially high expansion factors when they go through various unicode "normalizations"
|
|
||||||
0x1F82,
|
|
||||||
0xFDFA,
|
|
||||||
0xFB2C,
|
|
||||||
0x0390,
|
|
||||||
// 0x1D160, // hmm, need surrogates
|
|
||||||
// Characters with especially high expansion factors when lowercased or uppercased
|
|
||||||
0x023A,
|
|
||||||
0x0041,
|
|
||||||
0xDC1D, // a low surrogate
|
|
||||||
0xDB00, // a high surrogate
|
|
||||||
// UFFF0.pdf
|
|
||||||
0xFFF9, // interlinear annotation anchor
|
|
||||||
0xFFFA, // interlinear annotation seperator
|
|
||||||
0xFFFB, // interlinear annotation terminator
|
|
||||||
0xFFFC, // object replacement character
|
|
||||||
0xFFFD, // replacement character
|
|
||||||
0xFEFF, // zero width no-break space
|
|
||||||
0xFFFF, // not a character
|
|
||||||
0x00A0, // no-break space
|
|
||||||
0x2426,
|
|
||||||
0x003F,
|
|
||||||
0x00BF,
|
|
||||||
0xDC80,
|
|
||||||
0xDCFF,
|
|
||||||
// http://en.wikipedia.org/wiki/Mapping_of_Unicode_characters
|
|
||||||
0x205F, // mathematical space
|
|
||||||
0x2061, // mathematical function application
|
|
||||||
0x2064, // mathematical invisible separator
|
|
||||||
0x2044 // fraction slash character
|
|
||||||
])
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a random character that affects bidi layout
|
|
||||||
*/
|
|
||||||
static bidiCharCodes () {
|
|
||||||
return String.fromCodePoint(
|
|
||||||
random.pick([
|
|
||||||
0x0660, // START_HINDI_DIGITS
|
|
||||||
0x0669, // END_HINDI_DIGITS
|
|
||||||
0x066A, // START_ARABIC_SEPARATOR
|
|
||||||
0x066B, // END_ARABIC_SEPARATOR
|
|
||||||
0x0030, // START_ARABIC_DIGITS
|
|
||||||
0x0039, // END_ARABIC_DIGITS
|
|
||||||
0x06f0, // START_FARSI_DIGITS
|
|
||||||
0x06f9 // END_FARSI_DIGITS
|
|
||||||
])
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a random unicode combining character
|
|
||||||
* http://www.unicode.org/Public/6.0.0/ucd/UnicodeData.txt
|
|
||||||
*/
|
|
||||||
static unicodeCombiningCharacter () {
|
|
||||||
return String.fromCodePoint(
|
|
||||||
random.range(
|
|
||||||
...random.item([
|
|
||||||
[0x0300, 0x036F], // Combining Diacritical Marks
|
|
||||||
[0x0483, 0x0489],
|
|
||||||
[0x07EB, 0x07F3],
|
|
||||||
[0x135D, 0x135F],
|
|
||||||
[0x1A7F, 0x1A7F],
|
|
||||||
[0x1B6B, 0x1B73],
|
|
||||||
[0x1DC0, 0x1DFF], // Combining Diacritical Marks Supplement
|
|
||||||
[0x20D0, 0x2DFF],
|
|
||||||
[0x3099, 0x309A],
|
|
||||||
[0xA66F, 0xA6F1],
|
|
||||||
[0xA8E0, 0xA8F1],
|
|
||||||
[0xFE20, 0xFE26], // Combining Half Marks
|
|
||||||
[0x101FD, 0x101FD],
|
|
||||||
[0x1D165, 0x1D169],
|
|
||||||
[0x1D16D, 0x1D172],
|
|
||||||
[0x1D17B, 0x1D18B],
|
|
||||||
[0x1D1AA, 0x1D1AD],
|
|
||||||
[0x1D242, 0x1D244]
|
|
||||||
])
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a random basic multilingual plane character
|
|
||||||
*/
|
|
||||||
static unicodeBMP () {
|
|
||||||
return String.fromCodePoint(
|
|
||||||
random.range(0x0000, 0xFFFF)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a random supplementary multilingual plane character
|
|
||||||
*/
|
|
||||||
static unicodeSMP () {
|
|
||||||
return String.fromCodePoint(
|
|
||||||
random.range(
|
|
||||||
...random.item([
|
|
||||||
[0x10000, 0x13FFF],
|
|
||||||
[0x16000, 0x16FFF],
|
|
||||||
[0x1B000, 0x1BFFF],
|
|
||||||
[0x1D000, 0x1DFFF],
|
|
||||||
[0x1F000, 0x1FFFF]
|
|
||||||
])
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a random supplementary ideographic plane character
|
|
||||||
*/
|
|
||||||
static unicodeSIP () {
|
|
||||||
return String.fromCodePoint(
|
|
||||||
random.range(
|
|
||||||
...random.item([
|
|
||||||
[0x20000, 0x2BFFF],
|
|
||||||
[0x2F000, 0x2FFFF]
|
|
||||||
])
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a random supplementary special-purpose plane character
|
|
||||||
*/
|
|
||||||
static unicodeSSP () {
|
|
||||||
return String.fromCodePoint(
|
|
||||||
random.range(0xE0000, 0xE0FFF)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
static currency () {
|
|
||||||
return random.pick([
|
|
||||||
// https://en.wikipedia.org/wiki/ISO_4217
|
|
||||||
'USD', 'USS', 'USN', 'EUR', 'CHF', 'GBP', 'XAG', 'XBA', 'XBB', 'XBC',
|
|
||||||
'XBD', 'XSU', 'XTS', 'XXX'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static fromBlocks (set, maxlen) {
|
|
||||||
let s = ''
|
|
||||||
|
|
||||||
for (let i = 0; i < random.number(maxlen || 255); i++) {
|
|
||||||
s += random.pick(set)
|
|
||||||
}
|
|
||||||
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
static quotedString () {
|
|
||||||
return utils.common.quote(text.any())
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapper for all text generators
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
static random () {
|
|
||||||
return random.choose([
|
|
||||||
[1, text.alpha],
|
|
||||||
[1, text.alphanum],
|
|
||||||
[1, text.arithmeticOperator],
|
|
||||||
[1, text.assignmentOperator],
|
|
||||||
[1, text.controlChar],
|
|
||||||
[1, text.digit],
|
|
||||||
[1, text.lineEnd],
|
|
||||||
[1, text.token],
|
|
||||||
[3, text.layoutCharCodes],
|
|
||||||
[3, text.bidiCharCodes],
|
|
||||||
[3, text.unicodeCombiningCharacter],
|
|
||||||
[3, text.unicodeBMP],
|
|
||||||
[3, text.unicodeSMP],
|
|
||||||
[3, text.unicodeSIP],
|
|
||||||
[3, text.unicodeSSP]
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a single character
|
|
||||||
*/
|
|
||||||
static character () {
|
|
||||||
return text.random().charAt(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate string comprised of random generators
|
|
||||||
*/
|
|
||||||
static any () {
|
|
||||||
let s = ''
|
|
||||||
let len = random.range(1, 126)
|
|
||||||
|
|
||||||
while (len--) {
|
|
||||||
s += make.text.random()
|
|
||||||
}
|
|
||||||
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = text
|
|
423
lib/make/text.ts
Normal file
423
lib/make/text.ts
Normal file
|
@ -0,0 +1,423 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
import random from "../random/random.ts";
|
||||||
|
|
||||||
|
export default class text {
|
||||||
|
/**
|
||||||
|
* Generate a random alphabetic character
|
||||||
|
*/
|
||||||
|
static alpha() {
|
||||||
|
return String.fromCharCode(
|
||||||
|
random.range("A".charCodeAt(0), "z".charCodeAt(0))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a random alphanumeric character
|
||||||
|
*/
|
||||||
|
static alphanum() {
|
||||||
|
return String.fromCharCode(
|
||||||
|
random.range("0".charCodeAt(0), "z".charCodeAt(0))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a random assignment operator
|
||||||
|
*/
|
||||||
|
static assignmentOperator() {
|
||||||
|
return random.pick([
|
||||||
|
"=",
|
||||||
|
"+=",
|
||||||
|
"-=",
|
||||||
|
"*=",
|
||||||
|
"/=",
|
||||||
|
"%=",
|
||||||
|
"**=",
|
||||||
|
"<<=",
|
||||||
|
">>=",
|
||||||
|
">>>=",
|
||||||
|
"&=",
|
||||||
|
"^=",
|
||||||
|
"|="
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a random arithmetic operator
|
||||||
|
*/
|
||||||
|
static arithmeticOperator() {
|
||||||
|
return random.pick(["%", "-", "+", "*", "/"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a random control character
|
||||||
|
*/
|
||||||
|
static controlChar() {
|
||||||
|
return random.pick([
|
||||||
|
"\b",
|
||||||
|
"\t",
|
||||||
|
"\n",
|
||||||
|
"\v",
|
||||||
|
"\f",
|
||||||
|
"\r",
|
||||||
|
"\0",
|
||||||
|
"c",
|
||||||
|
"a",
|
||||||
|
"e" // eslint-disable-line no-useless-escape
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a random digit
|
||||||
|
*/
|
||||||
|
static digit() {
|
||||||
|
return String.fromCharCode(
|
||||||
|
random.range("0".charCodeAt(0), "9".charCodeAt(0))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a random line ending
|
||||||
|
*/
|
||||||
|
static lineEnd() {
|
||||||
|
return random.pick(["\n", "\r", "\r\n", "\n\r"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a random token
|
||||||
|
*/
|
||||||
|
static token() {
|
||||||
|
return random.pick([
|
||||||
|
"*",
|
||||||
|
"+",
|
||||||
|
"%",
|
||||||
|
"-",
|
||||||
|
"!",
|
||||||
|
"^",
|
||||||
|
":",
|
||||||
|
"|",
|
||||||
|
"&",
|
||||||
|
"<",
|
||||||
|
">",
|
||||||
|
".",
|
||||||
|
'"',
|
||||||
|
"#",
|
||||||
|
" ",
|
||||||
|
";",
|
||||||
|
",",
|
||||||
|
"{",
|
||||||
|
"}",
|
||||||
|
"(",
|
||||||
|
")",
|
||||||
|
"[",
|
||||||
|
"]",
|
||||||
|
"/",
|
||||||
|
"\\",
|
||||||
|
"/*",
|
||||||
|
"*/"
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static charset() {
|
||||||
|
return random.pick(["UTF-8", "ISO-8859-1"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static language() {
|
||||||
|
return random.pick([
|
||||||
|
// special casing for i, I, dotted/dotless variants
|
||||||
|
["tr", "az", "crh", "tt", "ba"],
|
||||||
|
// special casing rules: https://developer.mozilla.org/en/CSS/text-transform
|
||||||
|
["nl", "el", "ga"],
|
||||||
|
// special justification rules
|
||||||
|
["ja", "zh"],
|
||||||
|
// tend to be RTL
|
||||||
|
["ar", "he"],
|
||||||
|
// http://mxr.mozilla.org/mozilla-central/source/gfx/thebes/gfxAtomList.h
|
||||||
|
[
|
||||||
|
"en",
|
||||||
|
"x-unicode",
|
||||||
|
"x-western",
|
||||||
|
"ja",
|
||||||
|
"ko",
|
||||||
|
"zh-cn",
|
||||||
|
"zh-hk",
|
||||||
|
"zh-tw",
|
||||||
|
"x-cyrillic",
|
||||||
|
"el",
|
||||||
|
"tr",
|
||||||
|
"he",
|
||||||
|
"ar",
|
||||||
|
"x-baltic",
|
||||||
|
"th",
|
||||||
|
"x-devanagari",
|
||||||
|
"x-tamil",
|
||||||
|
"x-armn",
|
||||||
|
"x-beng",
|
||||||
|
"x-cans",
|
||||||
|
"x-ethi",
|
||||||
|
"x-geor",
|
||||||
|
"x-gujr",
|
||||||
|
"x-guru",
|
||||||
|
"x-khmr",
|
||||||
|
"x-knda",
|
||||||
|
"x-mlym",
|
||||||
|
"x-orya",
|
||||||
|
"x-sinh",
|
||||||
|
"x-telu",
|
||||||
|
"x-tibt",
|
||||||
|
"ko-xxx",
|
||||||
|
"x-central-euro",
|
||||||
|
"x-symbol",
|
||||||
|
"x-user-def",
|
||||||
|
"az",
|
||||||
|
"ba",
|
||||||
|
"crh",
|
||||||
|
"tt"
|
||||||
|
],
|
||||||
|
// Seen in mxr
|
||||||
|
["en-US", "fr", "fra", "de", "ru", "en-us", "is-IS", "xyzzy"]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a random character that may affect layout
|
||||||
|
*/
|
||||||
|
static layoutCharCodes() {
|
||||||
|
return String.fromCodePoint(
|
||||||
|
random.pick([
|
||||||
|
0, // null
|
||||||
|
160, // non-breaking space
|
||||||
|
0x005c, // backslash, but in some countries, represents local currency symbol (e.g. yen)
|
||||||
|
0x00ad, // soft hyphen
|
||||||
|
0x0bcc, // a Tamil character that is displayed as three glyphs
|
||||||
|
// http://unicode.org/charts/PDF/U2000.pdf
|
||||||
|
0x200b, // zero-width space
|
||||||
|
0x200c, // zero-width non-joiner
|
||||||
|
0x200d, // zero-width joiner
|
||||||
|
0x200e, // left-to-right mark
|
||||||
|
0x200f, // right-to-left mark
|
||||||
|
0x2011, // non-breaking hyphen
|
||||||
|
0x2027, // hyphenation point
|
||||||
|
0x2028, // line separator
|
||||||
|
0x2029, // paragraph separator
|
||||||
|
0x202a, // left-to-right embedding
|
||||||
|
0x202b, // right-to-left embedding
|
||||||
|
0x202c, // pop directional formatting
|
||||||
|
0x202d, // left-to-right override
|
||||||
|
0x202e, // right-to-left override
|
||||||
|
0x202f, // narrow no-break space
|
||||||
|
0x2060, // word joiner
|
||||||
|
0x2061, // function application (one of several invisible mathematical operators)
|
||||||
|
// http://unicode.org/charts/PDF/U3000.pdf
|
||||||
|
0x3000, // ideographic space (CJK)
|
||||||
|
// http://unicode.org/charts/PDF/U0300.pdf
|
||||||
|
0x0301, // combining acute accent (if it appears after "a", it turns into "a" with an accent)
|
||||||
|
// Arabic has the interesting property that most letters connect to the next letter.
|
||||||
|
// Some code calls this "shaping".
|
||||||
|
0x0643, // arabic letter kaf
|
||||||
|
0x0645, // arabic letter meem
|
||||||
|
0x06cd, // arabic letter yeh with tail
|
||||||
|
0xfdde, // invalid unicode? but somehow associated with arabic.
|
||||||
|
// http://unicode.org/reports/tr36/tr36-7.html#Buffer_Overflows
|
||||||
|
// Characters with especially high expansion factors when they go through various unicode "normalizations"
|
||||||
|
0x1f82,
|
||||||
|
0xfdfa,
|
||||||
|
0xfb2c,
|
||||||
|
0x0390,
|
||||||
|
// 0x1D160, // hmm, need surrogates
|
||||||
|
// Characters with especially high expansion factors when lowercased or uppercased
|
||||||
|
0x023a,
|
||||||
|
0x0041,
|
||||||
|
0xdc1d, // a low surrogate
|
||||||
|
0xdb00, // a high surrogate
|
||||||
|
// UFFF0.pdf
|
||||||
|
0xfff9, // interlinear annotation anchor
|
||||||
|
0xfffa, // interlinear annotation seperator
|
||||||
|
0xfffb, // interlinear annotation terminator
|
||||||
|
0xfffc, // object replacement character
|
||||||
|
0xfffd, // replacement character
|
||||||
|
0xfeff, // zero width no-break space
|
||||||
|
0xffff, // not a character
|
||||||
|
0x00a0, // no-break space
|
||||||
|
0x2426,
|
||||||
|
0x003f,
|
||||||
|
0x00bf,
|
||||||
|
0xdc80,
|
||||||
|
0xdcff,
|
||||||
|
// http://en.wikipedia.org/wiki/Mapping_of_Unicode_characters
|
||||||
|
0x205f, // mathematical space
|
||||||
|
0x2061, // mathematical function application
|
||||||
|
0x2064, // mathematical invisible separator
|
||||||
|
0x2044 // fraction slash character
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a random character that affects bidi layout
|
||||||
|
*/
|
||||||
|
static bidiCharCodes() {
|
||||||
|
return String.fromCodePoint(
|
||||||
|
random.pick([
|
||||||
|
0x0660, // START_HINDI_DIGITS
|
||||||
|
0x0669, // END_HINDI_DIGITS
|
||||||
|
0x066a, // START_ARABIC_SEPARATOR
|
||||||
|
0x066b, // END_ARABIC_SEPARATOR
|
||||||
|
0x0030, // START_ARABIC_DIGITS
|
||||||
|
0x0039, // END_ARABIC_DIGITS
|
||||||
|
0x06f0, // START_FARSI_DIGITS
|
||||||
|
0x06f9 // END_FARSI_DIGITS
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a random unicode combining character
|
||||||
|
* http://www.unicode.org/Public/6.0.0/ucd/UnicodeData.txt
|
||||||
|
*/
|
||||||
|
static unicodeCombiningCharacter() {
|
||||||
|
return String.fromCodePoint(
|
||||||
|
random.range.apply(random, random.item([
|
||||||
|
[0x0300, 0x036f], // Combining Diacritical Marks
|
||||||
|
[0x0483, 0x0489],
|
||||||
|
[0x07eb, 0x07f3],
|
||||||
|
[0x135d, 0x135f],
|
||||||
|
[0x1a7f, 0x1a7f],
|
||||||
|
[0x1b6b, 0x1b73],
|
||||||
|
[0x1dc0, 0x1dff], // Combining Diacritical Marks Supplement
|
||||||
|
[0x20d0, 0x2dff],
|
||||||
|
[0x3099, 0x309a],
|
||||||
|
[0xa66f, 0xa6f1],
|
||||||
|
[0xa8e0, 0xa8f1],
|
||||||
|
[0xfe20, 0xfe26], // Combining Half Marks
|
||||||
|
[0x101fd, 0x101fd],
|
||||||
|
[0x1d165, 0x1d169],
|
||||||
|
[0x1d16d, 0x1d172],
|
||||||
|
[0x1d17b, 0x1d18b],
|
||||||
|
[0x1d1aa, 0x1d1ad],
|
||||||
|
[0x1d242, 0x1d244]
|
||||||
|
])
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a random basic multilingual plane character
|
||||||
|
*/
|
||||||
|
static unicodeBMP() {
|
||||||
|
return String.fromCodePoint(random.range(0x0000, 0xffff));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a random supplementary multilingual plane character
|
||||||
|
*/
|
||||||
|
static unicodeSMP() {
|
||||||
|
return String.fromCodePoint(
|
||||||
|
random.range.apply(random, random.item([
|
||||||
|
[0x10000, 0x13fff],
|
||||||
|
[0x16000, 0x16fff],
|
||||||
|
[0x1b000, 0x1bfff],
|
||||||
|
[0x1d000, 0x1dfff],
|
||||||
|
[0x1f000, 0x1ffff]
|
||||||
|
])
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a random supplementary ideographic plane character
|
||||||
|
*/
|
||||||
|
static unicodeSIP() {
|
||||||
|
return String.fromCodePoint(
|
||||||
|
random.range.apply(random, random.item([
|
||||||
|
[0x20000, 0x2bfff],
|
||||||
|
[0x2f000, 0x2ffff]
|
||||||
|
])
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a random supplementary special-purpose plane character
|
||||||
|
*/
|
||||||
|
static unicodeSSP() {
|
||||||
|
return String.fromCodePoint(random.range(0xe0000, 0xe0fff));
|
||||||
|
}
|
||||||
|
|
||||||
|
static currency() {
|
||||||
|
return random.pick([
|
||||||
|
// https://en.wikipedia.org/wiki/ISO_4217
|
||||||
|
"USD",
|
||||||
|
"USS",
|
||||||
|
"USN",
|
||||||
|
"EUR",
|
||||||
|
"CHF",
|
||||||
|
"GBP",
|
||||||
|
"XAG",
|
||||||
|
"XBA",
|
||||||
|
"XBB",
|
||||||
|
"XBC",
|
||||||
|
"XBD",
|
||||||
|
"XSU",
|
||||||
|
"XTS",
|
||||||
|
"XXX"
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static fromBlocks(set, maxlen) {
|
||||||
|
let s = "";
|
||||||
|
|
||||||
|
for (let i = 0; i < random.number(maxlen || 255); i++) {
|
||||||
|
s += random.pick(set);
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper for all text generators
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
static random() {
|
||||||
|
return random.choose([
|
||||||
|
[1, text.alpha],
|
||||||
|
[1, text.alphanum],
|
||||||
|
[1, text.arithmeticOperator],
|
||||||
|
[1, text.assignmentOperator],
|
||||||
|
[1, text.controlChar],
|
||||||
|
[1, text.digit],
|
||||||
|
[1, text.lineEnd],
|
||||||
|
[1, text.token],
|
||||||
|
[3, text.layoutCharCodes],
|
||||||
|
[3, text.bidiCharCodes],
|
||||||
|
[3, text.unicodeCombiningCharacter],
|
||||||
|
[3, text.unicodeBMP],
|
||||||
|
[3, text.unicodeSMP],
|
||||||
|
[3, text.unicodeSIP],
|
||||||
|
[3, text.unicodeSSP]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a single character
|
||||||
|
*/
|
||||||
|
static character() {
|
||||||
|
return text.random().charAt(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate string comprised of random generators
|
||||||
|
*/
|
||||||
|
static any() {
|
||||||
|
let s = "";
|
||||||
|
let len = random.range(1, 126);
|
||||||
|
|
||||||
|
while (len--) {
|
||||||
|
s += text.random();
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,45 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
const make = require('../make')
|
|
||||||
const random = require('../random')
|
|
||||||
|
|
||||||
class time extends make {
|
|
||||||
static unit () {
|
|
||||||
return random.pick([
|
|
||||||
's', 'ms'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static datetime () {
|
|
||||||
switch (random.number(2)) {
|
|
||||||
case 0:
|
|
||||||
return new Date(new Date().getTime() + random.number())
|
|
||||||
case 1:
|
|
||||||
return new Date(new Date().getTime() - random.number())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static date () {
|
|
||||||
return time.datetime().toDateString()
|
|
||||||
}
|
|
||||||
|
|
||||||
static time () {
|
|
||||||
return time.datetime().toTimeString()
|
|
||||||
}
|
|
||||||
|
|
||||||
static iso () {
|
|
||||||
return time.datetime().toISOString()
|
|
||||||
}
|
|
||||||
|
|
||||||
static epoch () {
|
|
||||||
return Math.floor(time.datetime() / 1000)
|
|
||||||
}
|
|
||||||
|
|
||||||
static any () {
|
|
||||||
return make.number.any() + time.unit()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = time
|
|
41
lib/make/time.ts
Normal file
41
lib/make/time.ts
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
import random from "../random/random.ts";
|
||||||
|
import numbers from "./numbers.ts";
|
||||||
|
|
||||||
|
export default class time {
|
||||||
|
static unit() {
|
||||||
|
return random.pick(["s", "ms"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static datetime() {
|
||||||
|
switch (random.number(2)) {
|
||||||
|
case 0:
|
||||||
|
return new Date(new Date().getTime() + random.number());
|
||||||
|
case 1:
|
||||||
|
return new Date(new Date().getTime() - random.number());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static date() {
|
||||||
|
return time.datetime().toDateString();
|
||||||
|
}
|
||||||
|
|
||||||
|
static time() {
|
||||||
|
return time.datetime().toTimeString();
|
||||||
|
}
|
||||||
|
|
||||||
|
static iso() {
|
||||||
|
return time.datetime().toISOString();
|
||||||
|
}
|
||||||
|
|
||||||
|
static epoch() {
|
||||||
|
return Math.floor(time.datetime().getTime() / 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
static any() {
|
||||||
|
return numbers.any() + time.unit();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,130 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
const make = require('../make')
|
|
||||||
const random = require('../random')
|
|
||||||
|
|
||||||
class typed extends make {
|
|
||||||
static byte (limit = null) {
|
|
||||||
// [-128, 127]
|
|
||||||
let value = (limit !== null) ? random.number(limit) : random.number(129)
|
|
||||||
value = random.chance(10) ? -value : value
|
|
||||||
return `new Uint8Array([${value}])[0]`
|
|
||||||
}
|
|
||||||
|
|
||||||
static octet (limit = null) {
|
|
||||||
// [0, 255]
|
|
||||||
let value = (limit !== null) ? random.number(limit) : random.number(256)
|
|
||||||
return `new Int8Array([${value}])[0]`
|
|
||||||
}
|
|
||||||
|
|
||||||
static short (limit = null) {
|
|
||||||
// [-32768, 32767]
|
|
||||||
let value = (limit !== null) ? random.number(limit) : random.number(32769)
|
|
||||||
value = random.chance(10) ? -value : value
|
|
||||||
return `new Int16Array([${value}])[0]`
|
|
||||||
}
|
|
||||||
|
|
||||||
static unsignedShort (limit = null) {
|
|
||||||
// [0, 65535]
|
|
||||||
let value = (limit !== null) ? random.number(limit) : random.number(65535)
|
|
||||||
return `new Uint16Array([${value}])[0]`
|
|
||||||
}
|
|
||||||
|
|
||||||
static long (limit = null) {
|
|
||||||
// [-2147483648, 2147483647]
|
|
||||||
let value = (limit !== null) ? random.number(limit) : random.number(2147483649)
|
|
||||||
value = random.chance(10) ? -value : value
|
|
||||||
return `new Int32Array([${value}])[0]`
|
|
||||||
}
|
|
||||||
|
|
||||||
static unsignedLong (limit = null) {
|
|
||||||
// [0, 4294967295]
|
|
||||||
let value = (limit !== null) ? random.number(limit) : random.number(4294967296)
|
|
||||||
return `new Uint32Array([${value}])[0]`
|
|
||||||
}
|
|
||||||
|
|
||||||
static float (limit = null) {
|
|
||||||
let base = (limit !== null) ? random.number(limit) : random.number()
|
|
||||||
let value = random.chance(10) ? -(base + random.float()) : (base + random.float())
|
|
||||||
return `new Float32Array([${value}])[0]`
|
|
||||||
}
|
|
||||||
|
|
||||||
static unrestrictedFloat (limit = null) {
|
|
||||||
if (random.chance(100)) {
|
|
||||||
return random.pick([NaN, +Infinity, -Infinity])
|
|
||||||
} else {
|
|
||||||
let base = (limit !== null) ? random.number(limit) : random.number()
|
|
||||||
return `new Float32Array([${base + random.float()}])[0]`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static double (limit = null) {
|
|
||||||
let base = (limit !== null) ? random.number(limit) : random.number()
|
|
||||||
let value = random.chance(10) ? -(base + random.float()) : (base + random.float())
|
|
||||||
return `new Float64Array([${value}])[0]`
|
|
||||||
}
|
|
||||||
|
|
||||||
static unrestrictedDouble (limit = null) {
|
|
||||||
if (random.chance(100)) {
|
|
||||||
return random.pick([NaN, +Infinity, -Infinity])
|
|
||||||
} else {
|
|
||||||
let base = (limit !== null) ? random.number(limit) : random.number()
|
|
||||||
let value = random.chance(10) ? -(base + random.float()) : (base + random.float())
|
|
||||||
return `new Float64Array([${value}])[0]`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static any () {
|
|
||||||
return random.choose([
|
|
||||||
[1, [typed.byte, typed.octet]],
|
|
||||||
[1, [typed.short, typed.unsignedShort]],
|
|
||||||
[1, [typed.long, typed.unsignedLong]],
|
|
||||||
[1, [typed.float, typed.unrestrictedFloat]],
|
|
||||||
[1, [typed.double, typed.unrestrictedDouble]]
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static arrayBuffer (byteLength = null) {
|
|
||||||
let length = (byteLength !== null) ? byteLength : typed.unsignedShort()
|
|
||||||
return `new ArrayBuffer(${length})`
|
|
||||||
}
|
|
||||||
|
|
||||||
static dataView (byteLength = null) {
|
|
||||||
let length = (byteLength !== null) ? byteLength : typed.unsignedShort()
|
|
||||||
return `new DataView(${typed.arrayBuffer(length)})`
|
|
||||||
}
|
|
||||||
|
|
||||||
static typedArray (byteLength = null) {
|
|
||||||
let length = (byteLength !== null) ? byteLength : typed.unsignedShort()
|
|
||||||
let arrType = random.item([
|
|
||||||
'Int8', 'Uint8', 'Uint8Clamped',
|
|
||||||
'Int16', 'Uint16',
|
|
||||||
'Int32', 'Uint32',
|
|
||||||
'Float32', 'Float64'
|
|
||||||
])
|
|
||||||
let method = `new ${arrType}Array`
|
|
||||||
switch (random.number(16)) {
|
|
||||||
case 0:
|
|
||||||
return `${method}()`
|
|
||||||
case 1:
|
|
||||||
return `${method}(${this.typedArray()})`
|
|
||||||
default:
|
|
||||||
return `${method}(${length})`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bufferSource () {
|
|
||||||
switch (random.number(4)) {
|
|
||||||
case 0:
|
|
||||||
return typed.arrayBuffer()
|
|
||||||
case 1:
|
|
||||||
return typed.dataView()
|
|
||||||
default:
|
|
||||||
return typed.typedArray()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = typed
|
|
140
lib/make/typed.ts
Normal file
140
lib/make/typed.ts
Normal file
|
@ -0,0 +1,140 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
import random from "../random/random.ts";
|
||||||
|
|
||||||
|
export default class typed {
|
||||||
|
static byte(limit = null) {
|
||||||
|
// [-128, 127]
|
||||||
|
let value = limit !== null ? random.number(limit) : random.number(129);
|
||||||
|
value = random.chance(10) ? -value : value;
|
||||||
|
return `new Uint8Array([${value}])[0]`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static octet(limit = null) {
|
||||||
|
// [0, 255]
|
||||||
|
let value = limit !== null ? random.number(limit) : random.number(256);
|
||||||
|
return `new Int8Array([${value}])[0]`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static short(limit = null) {
|
||||||
|
// [-32768, 32767]
|
||||||
|
let value = limit !== null ? random.number(limit) : random.number(32769);
|
||||||
|
value = random.chance(10) ? -value : value;
|
||||||
|
return `new Int16Array([${value}])[0]`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsignedShort(limit = null) {
|
||||||
|
// [0, 65535]
|
||||||
|
let value = limit !== null ? random.number(limit) : random.number(65535);
|
||||||
|
return `new Uint16Array([${value}])[0]`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static long(limit = null) {
|
||||||
|
// [-2147483648, 2147483647]
|
||||||
|
let value =
|
||||||
|
limit !== null ? random.number(limit) : random.number(2147483649);
|
||||||
|
value = random.chance(10) ? -value : value;
|
||||||
|
return `new Int32Array([${value}])[0]`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsignedLong(limit = null) {
|
||||||
|
// [0, 4294967295]
|
||||||
|
let value =
|
||||||
|
limit !== null ? random.number(limit) : random.number(4294967296);
|
||||||
|
return `new Uint32Array([${value}])[0]`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static float(limit = null) {
|
||||||
|
let base = limit !== null ? random.number(limit) : random.number();
|
||||||
|
let value = random.chance(10)
|
||||||
|
? -(base + random.float())
|
||||||
|
: base + random.float();
|
||||||
|
return `new Float32Array([${value}])[0]`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static unrestrictedFloat(limit = null) {
|
||||||
|
if (random.chance(100)) {
|
||||||
|
return random.pick([NaN, +Infinity, -Infinity]);
|
||||||
|
} else {
|
||||||
|
let base = limit !== null ? random.number(limit) : random.number();
|
||||||
|
return `new Float32Array([${base + random.float()}])[0]`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static double(limit = null) {
|
||||||
|
let base = limit !== null ? random.number(limit) : random.number();
|
||||||
|
let value = random.chance(10)
|
||||||
|
? -(base + random.float())
|
||||||
|
: base + random.float();
|
||||||
|
return `new Float64Array([${value}])[0]`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static unrestrictedDouble(limit = null) {
|
||||||
|
if (random.chance(100)) {
|
||||||
|
return random.pick([NaN, +Infinity, -Infinity]);
|
||||||
|
} else {
|
||||||
|
let base = limit !== null ? random.number(limit) : random.number();
|
||||||
|
let value = random.chance(10)
|
||||||
|
? -(base + random.float())
|
||||||
|
: base + random.float();
|
||||||
|
return `new Float64Array([${value}])[0]`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static any() {
|
||||||
|
return random.choose([
|
||||||
|
[1, [typed.byte, typed.octet]],
|
||||||
|
[1, [typed.short, typed.unsignedShort]],
|
||||||
|
[1, [typed.long, typed.unsignedLong]],
|
||||||
|
[1, [typed.float, typed.unrestrictedFloat]],
|
||||||
|
[1, [typed.double, typed.unrestrictedDouble]]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static arrayBuffer(byteLength = null) {
|
||||||
|
let length = byteLength !== null ? byteLength : typed.unsignedShort();
|
||||||
|
return `new ArrayBuffer(${length})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static dataView(byteLength = null) {
|
||||||
|
let length = byteLength !== null ? byteLength : typed.unsignedShort();
|
||||||
|
return `new DataView(${typed.arrayBuffer(length)})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static typedArray(byteLength = null) {
|
||||||
|
let length = byteLength !== null ? byteLength : typed.unsignedShort();
|
||||||
|
let arrType = random.item([
|
||||||
|
"Int8",
|
||||||
|
"Uint8",
|
||||||
|
"Uint8Clamped",
|
||||||
|
"Int16",
|
||||||
|
"Uint16",
|
||||||
|
"Int32",
|
||||||
|
"Uint32",
|
||||||
|
"Float32",
|
||||||
|
"Float64"
|
||||||
|
]);
|
||||||
|
let method = `new ${arrType}Array`;
|
||||||
|
switch (random.number(16)) {
|
||||||
|
case 0:
|
||||||
|
return `${method}()`;
|
||||||
|
case 1:
|
||||||
|
return `${method}(${this.typedArray()})`;
|
||||||
|
default:
|
||||||
|
return `${method}(${length})`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bufferSource() {
|
||||||
|
switch (random.number(4)) {
|
||||||
|
case 0:
|
||||||
|
return typed.arrayBuffer();
|
||||||
|
case 1:
|
||||||
|
return typed.dataView();
|
||||||
|
default:
|
||||||
|
return typed.typedArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,23 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
const make = require('../make')
|
|
||||||
const random = require('../random')
|
|
||||||
|
|
||||||
class types extends make {
|
|
||||||
static random () {
|
|
||||||
return random.item([
|
|
||||||
'true',
|
|
||||||
'null',
|
|
||||||
'(new Object())',
|
|
||||||
'undefined',
|
|
||||||
'{}',
|
|
||||||
'[]',
|
|
||||||
'\'\'',
|
|
||||||
'function() {}'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = types
|
|
20
lib/make/types.ts
Normal file
20
lib/make/types.ts
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
import random from "../random/random.ts";
|
||||||
|
|
||||||
|
export default class types {
|
||||||
|
static random() {
|
||||||
|
return random.item([
|
||||||
|
"true",
|
||||||
|
"null",
|
||||||
|
"(new Object())",
|
||||||
|
"undefined",
|
||||||
|
"{}",
|
||||||
|
"[]",
|
||||||
|
"''",
|
||||||
|
"function() {}"
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,23 +2,21 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
const make = require('../make')
|
import random from "../random/random.ts";
|
||||||
const random = require('../random')
|
import numbers from "./numbers";
|
||||||
|
|
||||||
class unit extends make {
|
export default class unit{
|
||||||
static unit () {
|
static unit () {
|
||||||
return random.pick([
|
return random.pick([
|
||||||
'px', 'em', 'ex', 'ch', 'rem', 'mm', 'cm', 'in', 'pt', 'pc', '%'
|
'px', 'em', 'ex', 'ch', 'rem', 'mm', 'cm', 'in', 'pt', 'pc', '%'
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
static length () {
|
static len () {
|
||||||
return make.number.any() + make.unit.unit()
|
return numbers.any() + unit.unit()
|
||||||
}
|
}
|
||||||
|
|
||||||
static percent () {
|
static percent () {
|
||||||
return `${make.number.any()}%`
|
return `${numbers.any()}%`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = unit
|
|
|
@ -1,55 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
const make = require('../make')
|
|
||||||
const random = require('../random')
|
|
||||||
|
|
||||||
class uri extends make {
|
|
||||||
static problematic () {
|
|
||||||
return random.item([
|
|
||||||
'aim:yaz', // Often triggers an 'external protocol request' dialog
|
|
||||||
'foop:yaz', // Often triggers an unknown protocol
|
|
||||||
'about:memory', // Content is not allowed to link or load
|
|
||||||
'ws://localhost/' // WebSocket protocol
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static standard () {
|
|
||||||
return random.item([
|
|
||||||
'about:blank',
|
|
||||||
'about:srcdoc',
|
|
||||||
'about:mozilla',
|
|
||||||
'about:rights',
|
|
||||||
'data:text/html,',
|
|
||||||
'data:image/png,',
|
|
||||||
'data:',
|
|
||||||
'javascript:5555',
|
|
||||||
`javascript:"QQQQ${String.fromCharCode(0)}UUUU"`,
|
|
||||||
'http://a.invalid/',
|
|
||||||
'http://localhost:6/',
|
|
||||||
'https://localhost:6/',
|
|
||||||
'ftp://localhost:6/',
|
|
||||||
'http://localhost:25/'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static namespace () {
|
|
||||||
return random.item([
|
|
||||||
'http://www.w3.org/1999/xhtml',
|
|
||||||
'http://www.w3.org/2000/svg',
|
|
||||||
'http://www.w3.org/1998/Math/MathML'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
static any () {
|
|
||||||
return random.choose([
|
|
||||||
[1, uri.problematic],
|
|
||||||
[10, uri.standard],
|
|
||||||
[10, uri.namespace],
|
|
||||||
[10, make.files.any]
|
|
||||||
])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = uri
|
|
53
lib/make/uri.ts
Normal file
53
lib/make/uri.ts
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
import random from "../random/random.ts";
|
||||||
|
import files from "./files.ts";
|
||||||
|
|
||||||
|
export default class uri {
|
||||||
|
static problematic() {
|
||||||
|
return random.item([
|
||||||
|
"aim:yaz", // Often triggers an 'external protocol request' dialog
|
||||||
|
"foop:yaz", // Often triggers an unknown protocol
|
||||||
|
"about:memory", // Content is not allowed to link or load
|
||||||
|
"ws://localhost/" // WebSocket protocol
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static standard() {
|
||||||
|
return random.item([
|
||||||
|
"about:blank",
|
||||||
|
"about:srcdoc",
|
||||||
|
"about:mozilla",
|
||||||
|
"about:rights",
|
||||||
|
"data:text/html,",
|
||||||
|
"data:image/png,",
|
||||||
|
"data:",
|
||||||
|
"javascript:5555",
|
||||||
|
`javascript:"QQQQ${String.fromCharCode(0)}UUUU"`,
|
||||||
|
"http://a.invalid/",
|
||||||
|
"http://localhost:6/",
|
||||||
|
"https://localhost:6/",
|
||||||
|
"ftp://localhost:6/",
|
||||||
|
"http://localhost:25/"
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static namespace() {
|
||||||
|
return random.item([
|
||||||
|
"http://www.w3.org/1999/xhtml",
|
||||||
|
"http://www.w3.org/2000/svg",
|
||||||
|
"http://www.w3.org/1998/Math/MathML"
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static any() {
|
||||||
|
return random.choose([
|
||||||
|
[1, uri.problematic],
|
||||||
|
[10, uri.standard],
|
||||||
|
[10, uri.namespace],
|
||||||
|
[10, files.any]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,855 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
const make = require('../make')
|
|
||||||
const random = require('../random')
|
|
||||||
|
|
||||||
class webgl extends make {
|
|
||||||
static get internalFormat () {
|
|
||||||
return {
|
|
||||||
'RGB': { format: 'RGB', type: ['UNSIGNED_BYTE', 'UNSIGNED_SHORT_5_6_5'] },
|
|
||||||
'RGBA': { format: 'RGBA', type: ['UNSIGNED_BYTE', 'UNSIGNED_SHORT_4_4_4_4', 'UNSIGNED_SHORT_5_5_5_1'] },
|
|
||||||
'LUMINANCE_ALPHA': { format: 'LUMINANCE_ALPHA', type: ['UNSIGNED_BYTE'] },
|
|
||||||
'LUMINANCE': { format: 'LUMINANCE', type: ['UNSIGNED_BYTE'] },
|
|
||||||
'ALPHA': { format: 'ALPHA', type: ['UNSIGNED_BYTE'] },
|
|
||||||
'R8': { format: 'RED', type: ['UNSIGNED_BYTE'] },
|
|
||||||
'R16F': { format: 'RED', type: ['HALF_FLOAT', 'FLOAT'] },
|
|
||||||
'R32F': { format: 'RED', type: ['FLOAT'] },
|
|
||||||
'R8UI': { format: 'RED_INTEGER', type: ['UNSIGNED_BYTE'] },
|
|
||||||
'RG8': { format: 'RG', type: ['UNSIGNED_BYTE'] },
|
|
||||||
'RG16F': { format: 'RG', type: ['HALF_FLOAT', 'FLOAT'] },
|
|
||||||
'RG32F': { format: 'RG', type: ['FLOAT'] },
|
|
||||||
'RG8UI': { format: 'RG_INTEGER', type: ['UNSIGNED_BYTE'] },
|
|
||||||
'RGB8': { format: 'RGB', type: ['UNSIGNED_BYTE'] },
|
|
||||||
'SRGB8': { format: 'RGB', type: ['UNSIGNED_BYTE'] },
|
|
||||||
'RGB565': { format: 'RGB', type: ['RGB', 'UNSIGNED_BYTE', 'UNSIGNED_SHORT_5_6_5'] },
|
|
||||||
'R11F_G11F_B10F': { format: 'RGB', type: ['UNSIGNED_INT_10F_11F_11F_REV', 'HALF_FLOAT', 'FLOAT'] },
|
|
||||||
'RGB9_E5': { format: 'RGB', type: ['HALF_FLOAT', 'FLOAT'] },
|
|
||||||
'RGB16F': { format: 'RGB', type: ['HALF_FLOAT', 'FLOAT'] },
|
|
||||||
'RGB32F': { format: 'RGB', type: ['FLOAT'] },
|
|
||||||
'RGB8UI': { format: 'RGB_INTEGER', type: ['UNSIGNED_BYTE'] },
|
|
||||||
'RGBA8': { format: 'RGBA', type: ['UNSIGNED_BYTE'] },
|
|
||||||
'SRGB8_ALPHA8': { format: 'RGBA', type: ['UNSIGNED_BYTE'] },
|
|
||||||
'RGB5_A1': { format: 'RGBA', type: ['UNSIGNED_BYTE', 'UNSIGNED_SHORT_5_5_5_1'] },
|
|
||||||
'RGB10_A2': { format: 'RGBA', type: ['UNSIGNED_INT_2_10_10_10_REV'] },
|
|
||||||
'RGBA4': { format: 'RGBA', type: ['UNSIGNED_BYTE', 'UNSIGNED_SHORT_4_4_4_4'] },
|
|
||||||
'RGBA16F': { format: 'RGBA', type: ['HALF_FLOAT', 'FLOAT'] },
|
|
||||||
'RGBA32F': { format: 'RGBA', type: ['FLOAT'] },
|
|
||||||
'RGBA8UI': { format: 'RGBA_INTEGER', type: ['UNSIGNED_BYTE'] }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static WebGLFormat () {
|
|
||||||
let internalformat = random.item(Object.keys(webgl.internalFormat))
|
|
||||||
let format = webgl.internalFormat[internalformat].format
|
|
||||||
let type = random.item(webgl.internalFormat[internalformat].type)
|
|
||||||
return [internalformat, format, type]
|
|
||||||
}
|
|
||||||
|
|
||||||
static textureSources () {
|
|
||||||
let sources = [
|
|
||||||
'HTMLCanvasElement',
|
|
||||||
'HTMLImageElement',
|
|
||||||
'HTMLVideoElement',
|
|
||||||
'ImageData'
|
|
||||||
]
|
|
||||||
return random.item(sources)
|
|
||||||
}
|
|
||||||
|
|
||||||
static match (shader, regex, group = 1) {
|
|
||||||
let matches = []
|
|
||||||
while (true) {
|
|
||||||
let match = regex.exec(shader)
|
|
||||||
if (match) {
|
|
||||||
matches.push(match[group])
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return matches
|
|
||||||
}
|
|
||||||
|
|
||||||
static parseUniforms (shader, group = 1) {
|
|
||||||
/* Todo: Parse their individual data types into categories. */
|
|
||||||
return webgl.match(shader, /uniform .+? (\w+)(?=[\[;])/gm, group) // eslint-disable-line no-useless-escape
|
|
||||||
}
|
|
||||||
|
|
||||||
static parseAttributes (shader, group = 1) {
|
|
||||||
return webgl.match(shader, /attribute .+? (\w+)(?=;)/gm, group)
|
|
||||||
}
|
|
||||||
|
|
||||||
static parseVaryings (shader, group = 1) {
|
|
||||||
return webgl.match(shader, /varying .+? (\w+)(?=;)/gm, group)
|
|
||||||
}
|
|
||||||
|
|
||||||
static parseFragDatav2 (shader, group = 1) {
|
|
||||||
// #version 200
|
|
||||||
return webgl.match(shader, /(gl_Frag[^[ =]+)/gm, group)
|
|
||||||
}
|
|
||||||
|
|
||||||
static parseFragDatav3 (shader, group = 1) {
|
|
||||||
// #version 300
|
|
||||||
return webgl.match(shader, /out .+? (\w+)(?=[\[;])/gm, group) // eslint-disable-line no-useless-escape
|
|
||||||
}
|
|
||||||
|
|
||||||
static parseFrag (shader, group = 1) {
|
|
||||||
let matches = webgl.parseFragDatav2(shader)
|
|
||||||
if (matches.length) {
|
|
||||||
return matches
|
|
||||||
}
|
|
||||||
return webgl.parseFragDatav3(shader)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomBitmask () {
|
|
||||||
const values = []
|
|
||||||
for (let i = 0; i < 8; i++) {
|
|
||||||
values.push(random.item([1, 0]))
|
|
||||||
}
|
|
||||||
|
|
||||||
return parseInt(values.join(''))
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomBufferTarget (isWebGL2) {
|
|
||||||
let target = [
|
|
||||||
'ARRAY_BUFFER',
|
|
||||||
'ELEMENT_ARRAY_BUFFER'
|
|
||||||
]
|
|
||||||
if (isWebGL2) {
|
|
||||||
target.extend([
|
|
||||||
'COPY_READ_BUFFER',
|
|
||||||
'COPY_WRITE_BUFFER',
|
|
||||||
'TRANSFORM_FEEDBACK_BUFFER',
|
|
||||||
'UNIFORM_BUFFER',
|
|
||||||
'PIXEL_PACK_BUFFER',
|
|
||||||
'PIXEL_UNPACK_BUFFER'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
return random.item(target)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomTexParameter (isWebGL2) {
|
|
||||||
let pname = [
|
|
||||||
'TEXTURE_MAG_FILTER',
|
|
||||||
'TEXTURE_MIN_FILTER',
|
|
||||||
'TEXTURE_WRAP_S',
|
|
||||||
'TEXTURE_WRAP_T'
|
|
||||||
]
|
|
||||||
if (isWebGL2) {
|
|
||||||
pname.extend([
|
|
||||||
'TEXTURE_BASE_LEVEL',
|
|
||||||
'TEXTURE_COMPARE_FUNC',
|
|
||||||
'TEXTURE_COMPARE_MODE',
|
|
||||||
'TEXTURE_MAX_LEVEL',
|
|
||||||
'TEXTURE_MAX_LOD',
|
|
||||||
'TEXTURE_MIN_LOD',
|
|
||||||
'TEXTURE_WRAP_R'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
return random.item(pname)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomTexParameterValue (isWebGL2) {
|
|
||||||
let pnameparam = {
|
|
||||||
'TEXTURE_MAG_FILTER': [
|
|
||||||
'LINEAR',
|
|
||||||
'NEAREST'
|
|
||||||
],
|
|
||||||
'TEXTURE_MIN_FILTER': [
|
|
||||||
'LINEAR',
|
|
||||||
'NEAREST',
|
|
||||||
'NEAREST_MIPMAP_NEAREST',
|
|
||||||
'LINEAR_MIPMAP_NEAREST',
|
|
||||||
'NEAREST_MIPMAP_LINEA',
|
|
||||||
'LINEAR_MIPMAP_LINEAR'
|
|
||||||
],
|
|
||||||
'TEXTURE_WRAP_S': [
|
|
||||||
'REPEAT',
|
|
||||||
'CLAMP_TO_EDGE',
|
|
||||||
'MIRRORED_REPEAT'
|
|
||||||
],
|
|
||||||
'TEXTURE_WRAP_T': [
|
|
||||||
'REPEAT',
|
|
||||||
'CLAMP_TO_EDGE',
|
|
||||||
'MIRRORED_REPEAT'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
if (isWebGL2) {
|
|
||||||
pnameparam = Object.assign(
|
|
||||||
pnameparam,
|
|
||||||
{
|
|
||||||
'TEXTURE_BASE_LEVEL': [
|
|
||||||
make.number.any()
|
|
||||||
],
|
|
||||||
'TEXTURE_COMPARE_FUNC': [
|
|
||||||
'LEQUAL',
|
|
||||||
'GEQUAL',
|
|
||||||
'LESS',
|
|
||||||
'GREATER',
|
|
||||||
'EQUAL',
|
|
||||||
'NOTEQUAL',
|
|
||||||
'ALWAYS',
|
|
||||||
'NEVER'
|
|
||||||
],
|
|
||||||
'TEXTURE_COMPARE_MODE': [
|
|
||||||
'NONE',
|
|
||||||
'COMPARE_REF_TO_TEXTURE'
|
|
||||||
],
|
|
||||||
'TEXTURE_MAX_LEVEL': [
|
|
||||||
make.number.any()
|
|
||||||
],
|
|
||||||
'TEXTURE_MAX_LOD': [
|
|
||||||
make.number.float()
|
|
||||||
],
|
|
||||||
'TEXTURE_MIN_LOD': [
|
|
||||||
make.number.float()
|
|
||||||
],
|
|
||||||
'TEXTURE_WRAP_R': [
|
|
||||||
'REPEAT',
|
|
||||||
'CLAMP_TO_EDGE',
|
|
||||||
'MIRRORED_REPEAT'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
let pname = random.item(Object.keys(pnameparam))
|
|
||||||
let param = random.item(pnameparam[pname])
|
|
||||||
return [pname, param]
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomBlendMode (isWebGL2) {
|
|
||||||
let mode = [
|
|
||||||
'FUNC_ADD',
|
|
||||||
'FUNC_SUBTRACT',
|
|
||||||
'FUNC_REVERSE_SUBTRACT'
|
|
||||||
]
|
|
||||||
if (isWebGL2) {
|
|
||||||
mode.extend([
|
|
||||||
'MIN',
|
|
||||||
'MAX'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
return random.item(mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomBlendFactor (isWebGL2) {
|
|
||||||
let factor = [
|
|
||||||
'ZERO',
|
|
||||||
'ONE',
|
|
||||||
'SRC_COLOR',
|
|
||||||
'ONE_MINUS_SRC_COLOR',
|
|
||||||
'DST_COLOR',
|
|
||||||
'ONE_MINUS_DST_COLOR',
|
|
||||||
'SRC_ALPHA',
|
|
||||||
'ONE_MINUS_SRC_ALPHA',
|
|
||||||
'DST_ALPHA',
|
|
||||||
'ONE_MINUS_DST_ALPHA',
|
|
||||||
'CONSTANT_COLOR',
|
|
||||||
'ONE_MINUS_CONSTANT_COLOR',
|
|
||||||
'CONSTANT_ALPHA',
|
|
||||||
'ONE_MINUS_CONSTANT_ALPHA',
|
|
||||||
'SRC_ALPHA_SATURATE'
|
|
||||||
]
|
|
||||||
return random.item(factor)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomFace (isWebGL2) {
|
|
||||||
let mode = [
|
|
||||||
'FRONT',
|
|
||||||
'BACK',
|
|
||||||
'FRONT_AND_BACK'
|
|
||||||
]
|
|
||||||
return random.item(mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomTexImage2DTarget (isWebGL2) {
|
|
||||||
let target = [
|
|
||||||
'TEXTURE_2D',
|
|
||||||
'TEXTURE_CUBE_MAP_POSITIVE_X',
|
|
||||||
'TEXTURE_CUBE_MAP_NEGATIVE_X',
|
|
||||||
'TEXTURE_CUBE_MAP_POSITIVE_Y',
|
|
||||||
'TEXTURE_CUBE_MAP_NEGATIVE_Y',
|
|
||||||
'TEXTURE_CUBE_MAP_POSITIVE_Z',
|
|
||||||
'TEXTURE_CUBE_MAP_NEGATIVE_Z'
|
|
||||||
]
|
|
||||||
return random.item(target)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomTextureTarget (isWebGL2) {
|
|
||||||
let target = [
|
|
||||||
'TEXTURE_2D',
|
|
||||||
'TEXTURE_CUBE_MAP'
|
|
||||||
]
|
|
||||||
if (isWebGL2) {
|
|
||||||
target.extend([
|
|
||||||
'TEXTURE_3D',
|
|
||||||
'TEXTURE_2D_ARRAY'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
return random.item(target)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomFunc (isWebGL2) {
|
|
||||||
let func = [
|
|
||||||
'NEVER',
|
|
||||||
'LESS',
|
|
||||||
'EQUAL',
|
|
||||||
'LEQUAL',
|
|
||||||
'GREATER',
|
|
||||||
'NOTEQUAL',
|
|
||||||
'GEQUAL',
|
|
||||||
'ALWAYS'
|
|
||||||
]
|
|
||||||
return random.item(func)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomCap (isWebGL2) {
|
|
||||||
let cap = [
|
|
||||||
'BLEND',
|
|
||||||
'CULL_FACE',
|
|
||||||
'DEPTH_TEST',
|
|
||||||
'DITHER',
|
|
||||||
'POLYGON_OFFSET_FILL',
|
|
||||||
'SAMPLE_ALPHA_TO_COVERAGE',
|
|
||||||
'SAMPLE_COVERAGE',
|
|
||||||
'SCISSOR_TEST',
|
|
||||||
'STENCIL_TEST'
|
|
||||||
]
|
|
||||||
if (isWebGL2) {
|
|
||||||
cap.extend([
|
|
||||||
'RASTERIZER_DISCARD'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
return random.item(cap)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomPrimitive (isWebGL2) {
|
|
||||||
let mode = [
|
|
||||||
'POINTS',
|
|
||||||
'LINE_STRIP',
|
|
||||||
'LINE_LOOP',
|
|
||||||
'LINES',
|
|
||||||
'TRIANGLE_STRIP',
|
|
||||||
'TRIANGLE_FAN',
|
|
||||||
'TRIANGLES'
|
|
||||||
]
|
|
||||||
return random.item(mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomTextureAttachment (isWebGL2) {
|
|
||||||
let attachment = [
|
|
||||||
'COLOR_ATTACHMENT0',
|
|
||||||
'DEPTH_ATTACHMENT',
|
|
||||||
'STENCIL_ATTACHMENT',
|
|
||||||
'DEPTH_STENCIL_ATTACHMENT'
|
|
||||||
]
|
|
||||||
if (isWebGL2) {
|
|
||||||
attachment.extend([
|
|
||||||
`COLOR_ATTACHMENT${random.range(0, 15)}`
|
|
||||||
])
|
|
||||||
}
|
|
||||||
return random.item(attachment)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomAttachmentQuery (isWebGL2) {
|
|
||||||
let pname = [
|
|
||||||
'FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE',
|
|
||||||
'FRAMEBUFFER_ATTACHMENT_OBJECT_NAME',
|
|
||||||
'FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL',
|
|
||||||
'FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE'
|
|
||||||
]
|
|
||||||
if (isWebGL2) {
|
|
||||||
pname.extend([
|
|
||||||
'FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE',
|
|
||||||
'FRAMEBUFFER_ATTACHMENT_BLUE_SIZE',
|
|
||||||
'FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING',
|
|
||||||
'FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE',
|
|
||||||
'FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE',
|
|
||||||
'FRAMEBUFFER_ATTACHMENT_GREEN_SIZE',
|
|
||||||
'FRAMEBUFFER_ATTACHMENT_RED_SIZE',
|
|
||||||
'FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE',
|
|
||||||
'FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
return random.item(pname)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomShaderPrecision (isWebGL2) {
|
|
||||||
let precisiontype = [
|
|
||||||
'LOW_FLOAT',
|
|
||||||
'MEDIUM_FLOAT',
|
|
||||||
'HIGH_FLOAT',
|
|
||||||
'LOW_INT',
|
|
||||||
'MEDIUM_INT',
|
|
||||||
'HIGH_INT'
|
|
||||||
]
|
|
||||||
return random.item(precisiontype)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomStencilRefParameter (isWebGL2) {
|
|
||||||
let param = [
|
|
||||||
'STENCIL_FUNC',
|
|
||||||
'STENCIL_VALUE_MASK',
|
|
||||||
'STENCIL_REF',
|
|
||||||
'STENCIL_BACK_FUNC',
|
|
||||||
'STENCIL_BACK_VALUE_MASK',
|
|
||||||
'STENCIL_BACK_REF',
|
|
||||||
'STENCIL_BITS'
|
|
||||||
]
|
|
||||||
return random.item(param)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomStencilMaskParameter (isWebGL2) {
|
|
||||||
let param = [
|
|
||||||
'STENCIL_WRITEMASK',
|
|
||||||
'STENCIL_BACK_WRITEMASK',
|
|
||||||
'STENCIL_BITS'
|
|
||||||
]
|
|
||||||
return random.item(param)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomVertexAttribParameter (isWebGL2) {
|
|
||||||
let pname = [
|
|
||||||
'VERTEX_ATTRIB_ARRAY_BUFFER_BINDING',
|
|
||||||
'VERTEX_ATTRIB_ARRAY_ENABLED',
|
|
||||||
'VERTEX_ATTRIB_ARRAY_SIZE',
|
|
||||||
'VERTEX_ATTRIB_ARRAY_STRIDE',
|
|
||||||
'VERTEX_ATTRIB_ARRAY_TYPE',
|
|
||||||
'VERTEX_ATTRIB_ARRAY_NORMALIZED',
|
|
||||||
'CURRENT_VERTEX_ATTRIB'
|
|
||||||
]
|
|
||||||
if (isWebGL2) {
|
|
||||||
pname.extend([
|
|
||||||
'VERTEX_ATTRIB_ARRAY_INTEGER',
|
|
||||||
'VERTEX_ATTRIB_ARRAY_DIVISOR',
|
|
||||||
'VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
return random.item(pname)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomHint (isWebGL2) {
|
|
||||||
let target = [
|
|
||||||
'GENERATE_MIPMAP_HINT'
|
|
||||||
]
|
|
||||||
if (isWebGL2) {
|
|
||||||
target.extend([
|
|
||||||
'FRAGMENT_SHADER_DERIVATIVE_HINT'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
return random.item(target)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomHintMode (isWebGL2) {
|
|
||||||
let mode = [
|
|
||||||
'FASTEST',
|
|
||||||
'NICEST',
|
|
||||||
'DONT_CARE'
|
|
||||||
]
|
|
||||||
return random.item(mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomPixelStorage (isWebGL2) {
|
|
||||||
let pname = {
|
|
||||||
'PACK_ALIGNMENT': random.item([1, 2, 4, 8]),
|
|
||||||
'UNPACK_ALIGNMENT': random.item([1, 2, 4, 8]),
|
|
||||||
'UNPACK_FLIP_Y_WEBGL': random.bool(),
|
|
||||||
'UNPACK_PREMULTIPLY_ALPHA_WEBGL': random.bool(),
|
|
||||||
'UNPACK_COLORSPACE_CONVERSION_WEBGL': random.item([0, 0x9244])
|
|
||||||
}
|
|
||||||
if (isWebGL2) {
|
|
||||||
Object.assign(
|
|
||||||
pname,
|
|
||||||
{
|
|
||||||
'PACK_ROW_LENGTH': make.number.any(),
|
|
||||||
'PACK_SKIP_PIXELS': make.number.any(),
|
|
||||||
'PACK_SKIP_ROWS': make.number.any(),
|
|
||||||
'UNPACK_ROW_LENGTH': make.number.any(),
|
|
||||||
'UNPACK_IMAGE_HEIGHT': make.number.any(),
|
|
||||||
'UNPACK_SKIP_PIXELS': make.number.any(),
|
|
||||||
'UNPACK_SKIP_ROWS': make.number.any(),
|
|
||||||
'UNPACK_SKIP_IMAGES': make.number.any()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
let name = random.item(Object.keys(pname))
|
|
||||||
return [name, pname[name]]
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomStencilAction (isWebGL2) {
|
|
||||||
let action = [
|
|
||||||
'KEEP',
|
|
||||||
'ZERO',
|
|
||||||
'REPLACE',
|
|
||||||
'INCR',
|
|
||||||
'INCR_WRAP',
|
|
||||||
'DECR',
|
|
||||||
'DECR_WRAP',
|
|
||||||
'INVERT'
|
|
||||||
]
|
|
||||||
return random.item(action)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomQueryTarget (isWebGL2) {
|
|
||||||
let target = [
|
|
||||||
'ANY_SAMPLES_PASSED',
|
|
||||||
'ANY_SAMPLES_PASSED_CONSERVATIVE',
|
|
||||||
'TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN'
|
|
||||||
]
|
|
||||||
return random.item(target)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomQueryPname (isWebGL2) {
|
|
||||||
let pname = [
|
|
||||||
'CURRENT_QUERY',
|
|
||||||
'QUERY_RESULT',
|
|
||||||
'QUERY_RESULT_AVAILABLE'
|
|
||||||
]
|
|
||||||
return random.item(pname)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomSamplerParameter (isWebGL2) {
|
|
||||||
let pname = [
|
|
||||||
'TEXTURE_MAG_FILTER',
|
|
||||||
'TEXTURE_MIN_FILTER',
|
|
||||||
'TEXTURE_WRAP_S',
|
|
||||||
'TEXTURE_WRAP_T',
|
|
||||||
'TEXTURE_BASE_LEVEL',
|
|
||||||
'TEXTURE_COMPARE_FUNC',
|
|
||||||
'TEXTURE_COMPARE_MODE',
|
|
||||||
'TEXTURE_MAX_LEVEL',
|
|
||||||
'TEXTURE_WRAP_R',
|
|
||||||
'TEXTURE_MAX_LOD',
|
|
||||||
'TEXTURE_MIN_LOD',
|
|
||||||
'TEXTURE_MAX_ANISOTROPY_EXT'
|
|
||||||
]
|
|
||||||
return random.item(pname)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomSyncParameter (isWebGL2) {
|
|
||||||
let pname = [
|
|
||||||
'OBJECT_TYPE',
|
|
||||||
'SYNC_STATUS',
|
|
||||||
'SYNC_CONDITION',
|
|
||||||
'SYNC_FLAGS'
|
|
||||||
]
|
|
||||||
return random.item(pname)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomClearBuffer (isWebGL2) {
|
|
||||||
let buffer = [
|
|
||||||
'COLOR',
|
|
||||||
'DEPTH',
|
|
||||||
'STENCIL',
|
|
||||||
'DEPTH_STENCIL'
|
|
||||||
]
|
|
||||||
return random.item(buffer)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomBindBufferTarget (isWebGL2) {
|
|
||||||
let target = [
|
|
||||||
'TRANSFORM_FEEDBACK_BUFFER',
|
|
||||||
'UNIFORM_BUFFER'
|
|
||||||
]
|
|
||||||
return random.item(target)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomIndexedParameterTarget (isWebGL2) {
|
|
||||||
let target = [
|
|
||||||
'TRANSFORM_FEEDBACK_BUFFER_BINDING',
|
|
||||||
'TRANSFORM_FEEDBACK_BUFFER_SIZE',
|
|
||||||
'TRANSFORM_FEEDBACK_BUFFER_START',
|
|
||||||
'UNIFORM_BUFFER_BINDING',
|
|
||||||
'UNIFORM_BUFFER_SIZE',
|
|
||||||
'UNIFORM_BUFFER_START'
|
|
||||||
]
|
|
||||||
return random.item(target)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomUniformParameter (isWebGL2) {
|
|
||||||
let pname = [
|
|
||||||
'UNIFORM_TYPE',
|
|
||||||
'UNIFORM_SIZE',
|
|
||||||
'UNIFORM_BLOCK_INDEX',
|
|
||||||
'UNIFORM_OFFSET',
|
|
||||||
'UNIFORM_ARRAY_STRIDE',
|
|
||||||
'UNIFORM_MATRIX_STRIDE',
|
|
||||||
'UNIFORM_IS_ROW_MAJOR'
|
|
||||||
]
|
|
||||||
return random.item(pname)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomUniformBlockParameter (isWebGL2) {
|
|
||||||
let pname = [
|
|
||||||
'UNIFORM_BLOCK_BINDING',
|
|
||||||
'UNIFORM_BLOCK_DATA_SIZE',
|
|
||||||
'UNIFORM_BLOCK_ACTIVE_UNIFORMS',
|
|
||||||
'UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES',
|
|
||||||
'UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER',
|
|
||||||
'UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER'
|
|
||||||
]
|
|
||||||
return random.item(pname)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomPixelDatatype (isWebGL2) {
|
|
||||||
let type = [
|
|
||||||
'UNSIGNED_BYTE',
|
|
||||||
'UNSIGNED_SHORT',
|
|
||||||
'UNSIGNED_SHORT_5_6_5',
|
|
||||||
'UNSIGNED_SHORT_4_4_4_4',
|
|
||||||
'UNSIGNED_SHORT_5_5_5_1',
|
|
||||||
'UNSIGNED_INT',
|
|
||||||
'FLOAT'
|
|
||||||
]
|
|
||||||
return random.item(type)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomBufferUsage (isWebGL2) {
|
|
||||||
let usage = [
|
|
||||||
'STATIC_DRAW',
|
|
||||||
'DYNAMIC_DRAW',
|
|
||||||
'STREAM_DRAW'
|
|
||||||
]
|
|
||||||
if (isWebGL2) {
|
|
||||||
usage.extend([
|
|
||||||
'STATIC_READ',
|
|
||||||
'DYNAMIC_READ',
|
|
||||||
'STREAM_READ',
|
|
||||||
'STATIC_COPY',
|
|
||||||
'DYNAMIC_COPY',
|
|
||||||
'STREAM_COPY'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
return random.item(usage)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomParameter (isWebGL2) {
|
|
||||||
let pname = [
|
|
||||||
'ACTIVE_TEXTURE',
|
|
||||||
'ALIASED_LINE_WIDTH_RANGE',
|
|
||||||
'ALIASED_POINT_SIZE_RANGE',
|
|
||||||
'ALPHA_BITS',
|
|
||||||
'ARRAY_BUFFER_BINDING',
|
|
||||||
'BLEND',
|
|
||||||
'BLEND_COLOR',
|
|
||||||
'BLEND_DST_ALPHA',
|
|
||||||
'BLEND_DST_RGB',
|
|
||||||
'BLEND_EQUATION_ALPHA',
|
|
||||||
'BLEND_EQUATION_RGB',
|
|
||||||
'BLEND_SRC_ALPHA',
|
|
||||||
'BLEND_SRC_RGB',
|
|
||||||
'BLUE_BITS',
|
|
||||||
'COLOR_CLEAR_VALUE',
|
|
||||||
'COLOR_WRITEMASK',
|
|
||||||
'COMPRESSED_TEXTURE_FORMATS',
|
|
||||||
'CULL_FACE',
|
|
||||||
'CULL_FACE_MODE',
|
|
||||||
'CURRENT_PROGRAM',
|
|
||||||
'DEPTH_BITS',
|
|
||||||
'DEPTH_CLEAR_VALUE',
|
|
||||||
'DEPTH_FUNC',
|
|
||||||
'DEPTH_RANGE',
|
|
||||||
'DEPTH_TEST',
|
|
||||||
'DEPTH_WRITEMASK',
|
|
||||||
'DITHER',
|
|
||||||
'ELEMENT_ARRAY_BUFFER_BINDING',
|
|
||||||
'FRAMEBUFFER_BINDING',
|
|
||||||
'FRONT_FACE',
|
|
||||||
'GENERATE_MIPMAP_HINT',
|
|
||||||
'GREEN_BITS',
|
|
||||||
'IMPLEMENTATION_COLOR_READ_FORMAT',
|
|
||||||
'IMPLEMENTATION_COLOR_READ_TYPE',
|
|
||||||
'LINE_WIDTH',
|
|
||||||
'MAX_COMBINED_TEXTURE_IMAGE_UNITS',
|
|
||||||
'MAX_CUBE_MAP_TEXTURE_SIZE',
|
|
||||||
'MAX_FRAGMENT_UNIFORM_VECTORS',
|
|
||||||
'MAX_RENDERBUFFER_SIZE',
|
|
||||||
'MAX_TEXTURE_IMAGE_UNITS',
|
|
||||||
'MAX_TEXTURE_SIZE',
|
|
||||||
'MAX_VARYING_VECTORS',
|
|
||||||
'MAX_VERTEX_ATTRIBS',
|
|
||||||
'MAX_VERTEX_TEXTURE_IMAGE_UNITS',
|
|
||||||
'MAX_VERTEX_UNIFORM_VECTORS',
|
|
||||||
'MAX_VIEWPORT_DIMS',
|
|
||||||
'PACK_ALIGNMENT',
|
|
||||||
'POLYGON_OFFSET_FACTOR',
|
|
||||||
'POLYGON_OFFSET_FILL',
|
|
||||||
'POLYGON_OFFSET_UNITS',
|
|
||||||
'RED_BITS',
|
|
||||||
'RENDERBUFFER_BINDING',
|
|
||||||
'RENDERER',
|
|
||||||
'SAMPLE_ALPHA_TO_COVERAGE',
|
|
||||||
'SAMPLE_BUFFERS',
|
|
||||||
'SAMPLE_COVERAGE',
|
|
||||||
'SAMPLE_COVERAGE_INVERT',
|
|
||||||
'SAMPLE_COVERAGE_VALUE',
|
|
||||||
'SAMPLES',
|
|
||||||
'SCISSOR_BOX',
|
|
||||||
'SCISSOR_TEST',
|
|
||||||
'SHADING_LANGUAGE_VERSION',
|
|
||||||
'STENCIL_BACK_FAIL',
|
|
||||||
'STENCIL_BACK_FUNC',
|
|
||||||
'STENCIL_BACK_PASS_DEPTH_FAIL',
|
|
||||||
'STENCIL_BACK_PASS_DEPTH_PASS',
|
|
||||||
'STENCIL_BACK_REF',
|
|
||||||
'STENCIL_BACK_VALUE_MASK',
|
|
||||||
'STENCIL_BACK_WRITEMASK',
|
|
||||||
'STENCIL_BITS',
|
|
||||||
'STENCIL_CLEAR_VALUE',
|
|
||||||
'STENCIL_FAIL',
|
|
||||||
'STENCIL_FUNC',
|
|
||||||
'STENCIL_PASS_DEPTH_FAIL',
|
|
||||||
'STENCIL_PASS_DEPTH_PASS',
|
|
||||||
'STENCIL_REF',
|
|
||||||
'STENCIL_TEST',
|
|
||||||
'STENCIL_VALUE_MASK',
|
|
||||||
'STENCIL_WRITEMASK',
|
|
||||||
'SUBPIXEL_BITS',
|
|
||||||
'TEXTURE_BINDING_2D',
|
|
||||||
'TEXTURE_BINDING_CUBE_MAP',
|
|
||||||
'UNPACK_ALIGNMENT',
|
|
||||||
'UNPACK_COLORSPACE_CONVERSION_WEBGL',
|
|
||||||
'UNPACK_FLIP_Y_WEBGL',
|
|
||||||
'UNPACK_PREMULTIPLY_ALPHA_WEBGL',
|
|
||||||
'VENDOR',
|
|
||||||
'VERSION',
|
|
||||||
'VIEWPORT',
|
|
||||||
'VERSION',
|
|
||||||
'SHADING_LANGUAGE_VERSION',
|
|
||||||
'VENDOR',
|
|
||||||
'RENDERER'
|
|
||||||
]
|
|
||||||
|
|
||||||
if (isWebGL2) {
|
|
||||||
pname.extend([
|
|
||||||
'COPY_READ_BUFFER_BINDING',
|
|
||||||
'COPY_WRITE_BUFFER_BINDING',
|
|
||||||
'DRAW_BUFFERi',
|
|
||||||
'DRAW_FRAMEBUFFER_BINDING',
|
|
||||||
'FRAGMENT_SHADER_DERIVATIVE_HINT',
|
|
||||||
'MAX_3D_TEXTURE_SIZE',
|
|
||||||
'MAX_ARRAY_TEXTURE_LAYERS',
|
|
||||||
'MAX_CLIENT_WAIT_TIMEOUT_WEBGL',
|
|
||||||
'MAX_COLOR_ATTACHMENTS',
|
|
||||||
'MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS',
|
|
||||||
'MAX_COMBINED_UNIFORM_BLOCKS',
|
|
||||||
'MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS',
|
|
||||||
'MAX_DRAW_BUFFERS',
|
|
||||||
'MAX_ELEMENT_INDEX',
|
|
||||||
'MAX_ELEMENTS_INDICE',
|
|
||||||
'MAX_ELEMENTS_VERTICES',
|
|
||||||
'MAX_FRAGMENT_INPUT_COMPONENTS',
|
|
||||||
'MAX_FRAGMENT_UNIFORM_BLOCKS',
|
|
||||||
'MAX_FRAGMENT_UNIFORM_COMPONENTS',
|
|
||||||
'MAX_PROGRAM_TEXEL_OFFSET',
|
|
||||||
'MAX_SAMPLES',
|
|
||||||
'MAX_SERVER_WAIT_TIMEOUT',
|
|
||||||
'MAX_TEXTURE_LOD_BIAS',
|
|
||||||
'MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS',
|
|
||||||
'MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS',
|
|
||||||
'MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS',
|
|
||||||
'MAX_UNIFORM_BLOCK_SIZE',
|
|
||||||
'MAX_UNIFORM_BUFFER_BINDINGS',
|
|
||||||
'MAX_VARYING_COMPONENTS',
|
|
||||||
'MAX_VERTEX_OUTPUT_COMPONENTS',
|
|
||||||
'MAX_VERTEX_UNIFORM_BLOCKS',
|
|
||||||
'MAX_VERTEX_UNIFORM_COMPONENTS',
|
|
||||||
'MIN_PROGRAM_TEXEL_OFFSET',
|
|
||||||
'PACK_ROW_LENGTH',
|
|
||||||
'PACK_SKIP_PIXELS',
|
|
||||||
'PACK_SKIP_ROWS',
|
|
||||||
'PIXEL_PACK_BUFFER_BINDING',
|
|
||||||
'PIXEL_UNPACK_BUFFER_BINDING',
|
|
||||||
'RASTERIZER_DISCARD',
|
|
||||||
'READ_BUFFER',
|
|
||||||
'READ_FRAMEBUFFER_BINDING',
|
|
||||||
'SAMPLER_BINDING',
|
|
||||||
'TEXTURE_BINDING_2D_ARRAY',
|
|
||||||
'TEXTURE_BINDING_3D',
|
|
||||||
'TRANSFORM_FEEDBACK_ACTIVE',
|
|
||||||
'TRANSFORM_FEEDBACK_BINDING',
|
|
||||||
'TRANSFORM_FEEDBACK_BUFFER_BINDING',
|
|
||||||
'TRANSFORM_FEEDBACK_PAUSED',
|
|
||||||
'UNIFORM_BUFFER_BINDING',
|
|
||||||
'UNIFORM_BUFFER_OFFSET_ALIGNMENT',
|
|
||||||
'UNPACK_IMAGE_HEIGHT',
|
|
||||||
'UNPACK_ROW_LENGTH',
|
|
||||||
'UNPACK_SKIP_IMAGES',
|
|
||||||
'UNPACK_SKIP_PIXELS',
|
|
||||||
'UNPACK_SKIP_ROWS',
|
|
||||||
'VERTEX_ARRAY_BINDING'
|
|
||||||
])
|
|
||||||
}
|
|
||||||
return random.item(pname)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomProgramParameter () {
|
|
||||||
let pname = [
|
|
||||||
'DELETE_STATUS',
|
|
||||||
'LINK_STATUS',
|
|
||||||
'VALIDATE_STATUS',
|
|
||||||
'ATTACHED_SHADERS',
|
|
||||||
'ACTIVE_ATTRIBUTES',
|
|
||||||
'ACTIVE_UNIFORMS',
|
|
||||||
'TRANSFORM_FEEDBACK_BUFFER_MODE',
|
|
||||||
'TRANSFORM_FEEDBACK_VARYINGS',
|
|
||||||
'ACTIVE_UNIFORM_BLOCKS'
|
|
||||||
]
|
|
||||||
return random.item(pname)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomRenderBufferParameter () {
|
|
||||||
let pname = [
|
|
||||||
'RENDERBUFFER_WIDTH',
|
|
||||||
'RENDERBUFFER_HEIGHT',
|
|
||||||
'RENDERBUFFER_INTERNAL_FORMAT',
|
|
||||||
'RENDERBUFFER_RED_SIZE',
|
|
||||||
'RENDERBUFFER_GREEN_SIZE',
|
|
||||||
'RENDERBUFFER_BLUE_SIZE',
|
|
||||||
'RENDERBUFFER_ALPHA_SIZE',
|
|
||||||
'RENDERBUFFER_DEPTH_SIZE',
|
|
||||||
'RENDERBUFFER_STENCIL_SIZE'
|
|
||||||
]
|
|
||||||
return random.item(pname)
|
|
||||||
}
|
|
||||||
|
|
||||||
static randomExtension (pattern) {
|
|
||||||
let extensions = [
|
|
||||||
'ANGLE_instanced_arrays',
|
|
||||||
'EXT_blend_minmax',
|
|
||||||
'EXT_color_buffer_half_float',
|
|
||||||
'EXT_frag_depth',
|
|
||||||
'EXT_sRGB',
|
|
||||||
'EXT_shader_texture_lod',
|
|
||||||
'EXT_texture_filter_anisotropic',
|
|
||||||
'EXT_disjoint_timer_query',
|
|
||||||
'OES_element_index_uint',
|
|
||||||
'OES_standard_derivatives',
|
|
||||||
'OES_texture_float',
|
|
||||||
'OES_texture_float_linear',
|
|
||||||
'OES_texture_half_float',
|
|
||||||
'OES_texture_half_float_linear',
|
|
||||||
'OES_vertex_array_object',
|
|
||||||
'WEBGL_color_buffer_float',
|
|
||||||
'WEBGL_compressed_texture_s3tc',
|
|
||||||
'WEBGL_compressed_texture_s3tc_srgb',
|
|
||||||
'WEBGL_debug_renderer_info',
|
|
||||||
'WEBGL_debug_shaders',
|
|
||||||
'WEBGL_depth_texture',
|
|
||||||
'WEBGL_draw_buffers',
|
|
||||||
'WEBGL_lose_context'
|
|
||||||
]
|
|
||||||
|
|
||||||
if (pattern) {
|
|
||||||
let candidates = []
|
|
||||||
extensions.forEach((ext) => ext.includes(pattern) ? candidates.push(ext) : '')
|
|
||||||
if (candidates.length >= 0) {
|
|
||||||
return random.item(candidates)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return random.item(extensions)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = webgl
|
|
791
lib/make/webgl.ts
Normal file
791
lib/make/webgl.ts
Normal file
|
@ -0,0 +1,791 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
import random from "../random/random.ts";
|
||||||
|
import numbers from "./numbers.ts";
|
||||||
|
|
||||||
|
export default class webgl {
|
||||||
|
static get internalFormat() {
|
||||||
|
return {
|
||||||
|
RGB: { format: "RGB", type: ["UNSIGNED_BYTE", "UNSIGNED_SHORT_5_6_5"] },
|
||||||
|
RGBA: {
|
||||||
|
format: "RGBA",
|
||||||
|
type: [
|
||||||
|
"UNSIGNED_BYTE",
|
||||||
|
"UNSIGNED_SHORT_4_4_4_4",
|
||||||
|
"UNSIGNED_SHORT_5_5_5_1"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
LUMINANCE_ALPHA: { format: "LUMINANCE_ALPHA", type: ["UNSIGNED_BYTE"] },
|
||||||
|
LUMINANCE: { format: "LUMINANCE", type: ["UNSIGNED_BYTE"] },
|
||||||
|
ALPHA: { format: "ALPHA", type: ["UNSIGNED_BYTE"] },
|
||||||
|
R8: { format: "RED", type: ["UNSIGNED_BYTE"] },
|
||||||
|
R16F: { format: "RED", type: ["HALF_FLOAT", "FLOAT"] },
|
||||||
|
R32F: { format: "RED", type: ["FLOAT"] },
|
||||||
|
R8UI: { format: "RED_INTEGER", type: ["UNSIGNED_BYTE"] },
|
||||||
|
RG8: { format: "RG", type: ["UNSIGNED_BYTE"] },
|
||||||
|
RG16F: { format: "RG", type: ["HALF_FLOAT", "FLOAT"] },
|
||||||
|
RG32F: { format: "RG", type: ["FLOAT"] },
|
||||||
|
RG8UI: { format: "RG_INTEGER", type: ["UNSIGNED_BYTE"] },
|
||||||
|
RGB8: { format: "RGB", type: ["UNSIGNED_BYTE"] },
|
||||||
|
SRGB8: { format: "RGB", type: ["UNSIGNED_BYTE"] },
|
||||||
|
RGB565: {
|
||||||
|
format: "RGB",
|
||||||
|
type: ["RGB", "UNSIGNED_BYTE", "UNSIGNED_SHORT_5_6_5"]
|
||||||
|
},
|
||||||
|
R11F_G11F_B10F: {
|
||||||
|
format: "RGB",
|
||||||
|
type: ["UNSIGNED_INT_10F_11F_11F_REV", "HALF_FLOAT", "FLOAT"]
|
||||||
|
},
|
||||||
|
RGB9_E5: { format: "RGB", type: ["HALF_FLOAT", "FLOAT"] },
|
||||||
|
RGB16F: { format: "RGB", type: ["HALF_FLOAT", "FLOAT"] },
|
||||||
|
RGB32F: { format: "RGB", type: ["FLOAT"] },
|
||||||
|
RGB8UI: { format: "RGB_INTEGER", type: ["UNSIGNED_BYTE"] },
|
||||||
|
RGBA8: { format: "RGBA", type: ["UNSIGNED_BYTE"] },
|
||||||
|
SRGB8_ALPHA8: { format: "RGBA", type: ["UNSIGNED_BYTE"] },
|
||||||
|
RGB5_A1: {
|
||||||
|
format: "RGBA",
|
||||||
|
type: ["UNSIGNED_BYTE", "UNSIGNED_SHORT_5_5_5_1"]
|
||||||
|
},
|
||||||
|
RGB10_A2: { format: "RGBA", type: ["UNSIGNED_INT_2_10_10_10_REV"] },
|
||||||
|
RGBA4: {
|
||||||
|
format: "RGBA",
|
||||||
|
type: ["UNSIGNED_BYTE", "UNSIGNED_SHORT_4_4_4_4"]
|
||||||
|
},
|
||||||
|
RGBA16F: { format: "RGBA", type: ["HALF_FLOAT", "FLOAT"] },
|
||||||
|
RGBA32F: { format: "RGBA", type: ["FLOAT"] },
|
||||||
|
RGBA8UI: { format: "RGBA_INTEGER", type: ["UNSIGNED_BYTE"] }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static WebGLFormat() {
|
||||||
|
let internalformat = random.item(Object.keys(webgl.internalFormat));
|
||||||
|
let format = webgl.internalFormat[internalformat].format;
|
||||||
|
let type = random.item(webgl.internalFormat[internalformat].type);
|
||||||
|
return [internalformat, format, type];
|
||||||
|
}
|
||||||
|
|
||||||
|
static textureSources() {
|
||||||
|
let sources = [
|
||||||
|
"HTMLCanvasElement",
|
||||||
|
"HTMLImageElement",
|
||||||
|
"HTMLVideoElement",
|
||||||
|
"ImageData"
|
||||||
|
];
|
||||||
|
return random.item(sources);
|
||||||
|
}
|
||||||
|
|
||||||
|
static match(shader, regex, group = 1) {
|
||||||
|
let matches = [];
|
||||||
|
while (true) {
|
||||||
|
let match = regex.exec(shader);
|
||||||
|
if (match) {
|
||||||
|
matches.push(match[group]);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
static parseUniforms(shader, group = 1) {
|
||||||
|
/* Todo: Parse their individual data types into categories. */
|
||||||
|
return webgl.match(shader, /uniform .+? (\w+)(?=[\[;])/gm, group); // eslint-disable-line no-useless-escape
|
||||||
|
}
|
||||||
|
|
||||||
|
static parseAttributes(shader, group = 1) {
|
||||||
|
return webgl.match(shader, /attribute .+? (\w+)(?=;)/gm, group);
|
||||||
|
}
|
||||||
|
|
||||||
|
static parseVaryings(shader, group = 1) {
|
||||||
|
return webgl.match(shader, /varying .+? (\w+)(?=;)/gm, group);
|
||||||
|
}
|
||||||
|
|
||||||
|
static parseFragDatav2(shader, group = 1) {
|
||||||
|
// #version 200
|
||||||
|
return webgl.match(shader, /(gl_Frag[^[ =]+)/gm, group);
|
||||||
|
}
|
||||||
|
|
||||||
|
static parseFragDatav3(shader, group = 1) {
|
||||||
|
// #version 300
|
||||||
|
return webgl.match(shader, /out .+? (\w+)(?=[\[;])/gm, group); // eslint-disable-line no-useless-escape
|
||||||
|
}
|
||||||
|
|
||||||
|
static parseFrag(shader, group = 1) {
|
||||||
|
let matches = webgl.parseFragDatav2(shader);
|
||||||
|
if (matches.length) {
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
return webgl.parseFragDatav3(shader);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomBitmask() {
|
||||||
|
const values = [];
|
||||||
|
for (let i = 0; i < 8; i++) {
|
||||||
|
values.push(random.item([1, 0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseInt(values.join(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomBufferTarget(isWebGL2) {
|
||||||
|
let target = ["ARRAY_BUFFER", "ELEMENT_ARRAY_BUFFER"];
|
||||||
|
if (isWebGL2) {
|
||||||
|
target = [
|
||||||
|
...target,
|
||||||
|
"COPY_READ_BUFFER",
|
||||||
|
"COPY_WRITE_BUFFER",
|
||||||
|
"TRANSFORM_FEEDBACK_BUFFER",
|
||||||
|
"UNIFORM_BUFFER",
|
||||||
|
"PIXEL_PACK_BUFFER",
|
||||||
|
"PIXEL_UNPACK_BUFFER"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return random.item(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomTexParameter(isWebGL2) {
|
||||||
|
let pname = [
|
||||||
|
"TEXTURE_MAG_FILTER",
|
||||||
|
"TEXTURE_MIN_FILTER",
|
||||||
|
"TEXTURE_WRAP_S",
|
||||||
|
"TEXTURE_WRAP_T"
|
||||||
|
];
|
||||||
|
if (isWebGL2) {
|
||||||
|
pname = [
|
||||||
|
...pname,
|
||||||
|
"TEXTURE_BASE_LEVEL",
|
||||||
|
"TEXTURE_COMPARE_FUNC",
|
||||||
|
"TEXTURE_COMPARE_MODE",
|
||||||
|
"TEXTURE_MAX_LEVEL",
|
||||||
|
"TEXTURE_MAX_LOD",
|
||||||
|
"TEXTURE_MIN_LOD",
|
||||||
|
"TEXTURE_WRAP_R"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return random.item(pname);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomTexParameterValue(isWebGL2) {
|
||||||
|
let pnameparam = {
|
||||||
|
TEXTURE_MAG_FILTER: ["LINEAR", "NEAREST"],
|
||||||
|
TEXTURE_MIN_FILTER: [
|
||||||
|
"LINEAR",
|
||||||
|
"NEAREST",
|
||||||
|
"NEAREST_MIPMAP_NEAREST",
|
||||||
|
"LINEAR_MIPMAP_NEAREST",
|
||||||
|
"NEAREST_MIPMAP_LINEA",
|
||||||
|
"LINEAR_MIPMAP_LINEAR"
|
||||||
|
],
|
||||||
|
TEXTURE_WRAP_S: ["REPEAT", "CLAMP_TO_EDGE", "MIRRORED_REPEAT"],
|
||||||
|
TEXTURE_WRAP_T: ["REPEAT", "CLAMP_TO_EDGE", "MIRRORED_REPEAT"]
|
||||||
|
};
|
||||||
|
if (isWebGL2) {
|
||||||
|
pnameparam = Object.assign(pnameparam, {
|
||||||
|
TEXTURE_BASE_LEVEL: [numbers.any()],
|
||||||
|
TEXTURE_COMPARE_FUNC: [
|
||||||
|
"LEQUAL",
|
||||||
|
"GEQUAL",
|
||||||
|
"LESS",
|
||||||
|
"GREATER",
|
||||||
|
"EQUAL",
|
||||||
|
"NOTEQUAL",
|
||||||
|
"ALWAYS",
|
||||||
|
"NEVER"
|
||||||
|
],
|
||||||
|
TEXTURE_COMPARE_MODE: ["NONE", "COMPARE_REF_TO_TEXTURE"],
|
||||||
|
TEXTURE_MAX_LEVEL: [numbers.any()],
|
||||||
|
TEXTURE_MAX_LOD: [numbers.float()],
|
||||||
|
TEXTURE_MIN_LOD: [numbers.float()],
|
||||||
|
TEXTURE_WRAP_R: ["REPEAT", "CLAMP_TO_EDGE", "MIRRORED_REPEAT"]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let pname = random.item(Object.keys(pnameparam));
|
||||||
|
let param = random.item(pnameparam[pname]);
|
||||||
|
return [pname, param];
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomBlendMode(isWebGL2) {
|
||||||
|
let mode = ["FUNC_ADD", "FUNC_SUBTRACT", "FUNC_REVERSE_SUBTRACT"];
|
||||||
|
if (isWebGL2) {
|
||||||
|
mode = [...mode, "MIN", "MAX"];
|
||||||
|
}
|
||||||
|
return random.item(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomBlendFactor(isWebGL2) {
|
||||||
|
let factor = [
|
||||||
|
"ZERO",
|
||||||
|
"ONE",
|
||||||
|
"SRC_COLOR",
|
||||||
|
"ONE_MINUS_SRC_COLOR",
|
||||||
|
"DST_COLOR",
|
||||||
|
"ONE_MINUS_DST_COLOR",
|
||||||
|
"SRC_ALPHA",
|
||||||
|
"ONE_MINUS_SRC_ALPHA",
|
||||||
|
"DST_ALPHA",
|
||||||
|
"ONE_MINUS_DST_ALPHA",
|
||||||
|
"CONSTANT_COLOR",
|
||||||
|
"ONE_MINUS_CONSTANT_COLOR",
|
||||||
|
"CONSTANT_ALPHA",
|
||||||
|
"ONE_MINUS_CONSTANT_ALPHA",
|
||||||
|
"SRC_ALPHA_SATURATE"
|
||||||
|
];
|
||||||
|
return random.item(factor);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomFace(isWebGL2) {
|
||||||
|
let mode = ["FRONT", "BACK", "FRONT_AND_BACK"];
|
||||||
|
return random.item(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomTexImage2DTarget(isWebGL2) {
|
||||||
|
let target = [
|
||||||
|
"TEXTURE_2D",
|
||||||
|
"TEXTURE_CUBE_MAP_POSITIVE_X",
|
||||||
|
"TEXTURE_CUBE_MAP_NEGATIVE_X",
|
||||||
|
"TEXTURE_CUBE_MAP_POSITIVE_Y",
|
||||||
|
"TEXTURE_CUBE_MAP_NEGATIVE_Y",
|
||||||
|
"TEXTURE_CUBE_MAP_POSITIVE_Z",
|
||||||
|
"TEXTURE_CUBE_MAP_NEGATIVE_Z"
|
||||||
|
];
|
||||||
|
return random.item(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomTextureTarget(isWebGL2) {
|
||||||
|
let target = ["TEXTURE_2D", "TEXTURE_CUBE_MAP"];
|
||||||
|
if (isWebGL2) {
|
||||||
|
target = [...target, "TEXTURE_3D", "TEXTURE_2D_ARRAY"];
|
||||||
|
}
|
||||||
|
return random.item(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomFunc(isWebGL2) {
|
||||||
|
let func = [
|
||||||
|
"NEVER",
|
||||||
|
"LESS",
|
||||||
|
"EQUAL",
|
||||||
|
"LEQUAL",
|
||||||
|
"GREATER",
|
||||||
|
"NOTEQUAL",
|
||||||
|
"GEQUAL",
|
||||||
|
"ALWAYS"
|
||||||
|
];
|
||||||
|
return random.item(func);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomCap(isWebGL2) {
|
||||||
|
let cap = [
|
||||||
|
"BLEND",
|
||||||
|
"CULL_FACE",
|
||||||
|
"DEPTH_TEST",
|
||||||
|
"DITHER",
|
||||||
|
"POLYGON_OFFSET_FILL",
|
||||||
|
"SAMPLE_ALPHA_TO_COVERAGE",
|
||||||
|
"SAMPLE_COVERAGE",
|
||||||
|
"SCISSOR_TEST",
|
||||||
|
"STENCIL_TEST"
|
||||||
|
];
|
||||||
|
if (isWebGL2) {
|
||||||
|
cap = [...cap, "RASTERIZER_DISCARD"];
|
||||||
|
}
|
||||||
|
return random.item(cap);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomPrimitive(isWebGL2) {
|
||||||
|
let mode = [
|
||||||
|
"POINTS",
|
||||||
|
"LINE_STRIP",
|
||||||
|
"LINE_LOOP",
|
||||||
|
"LINES",
|
||||||
|
"TRIANGLE_STRIP",
|
||||||
|
"TRIANGLE_FAN",
|
||||||
|
"TRIANGLES"
|
||||||
|
];
|
||||||
|
return random.item(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomTextureAttachment(isWebGL2) {
|
||||||
|
let attachment = [
|
||||||
|
"COLOR_ATTACHMENT0",
|
||||||
|
"DEPTH_ATTACHMENT",
|
||||||
|
"STENCIL_ATTACHMENT",
|
||||||
|
"DEPTH_STENCIL_ATTACHMENT"
|
||||||
|
];
|
||||||
|
if (isWebGL2) {
|
||||||
|
attachment = [...attachment, `COLOR_ATTACHMENT${random.range(0, 15)}`];
|
||||||
|
}
|
||||||
|
return random.item(attachment);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomAttachmentQuery(isWebGL2) {
|
||||||
|
let pname = [
|
||||||
|
"FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE",
|
||||||
|
"FRAMEBUFFER_ATTACHMENT_OBJECT_NAME",
|
||||||
|
"FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL",
|
||||||
|
"FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE"
|
||||||
|
];
|
||||||
|
if (isWebGL2) {
|
||||||
|
pname = [
|
||||||
|
...pname,
|
||||||
|
"FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE",
|
||||||
|
"FRAMEBUFFER_ATTACHMENT_BLUE_SIZE",
|
||||||
|
"FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING",
|
||||||
|
"FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE",
|
||||||
|
"FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE",
|
||||||
|
"FRAMEBUFFER_ATTACHMENT_GREEN_SIZE",
|
||||||
|
"FRAMEBUFFER_ATTACHMENT_RED_SIZE",
|
||||||
|
"FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE",
|
||||||
|
"FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return random.item(pname);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomShaderPrecision(isWebGL2) {
|
||||||
|
let precisiontype = [
|
||||||
|
"LOW_FLOAT",
|
||||||
|
"MEDIUM_FLOAT",
|
||||||
|
"HIGH_FLOAT",
|
||||||
|
"LOW_INT",
|
||||||
|
"MEDIUM_INT",
|
||||||
|
"HIGH_INT"
|
||||||
|
];
|
||||||
|
return random.item(precisiontype);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomStencilRefParameter(isWebGL2) {
|
||||||
|
let param = [
|
||||||
|
"STENCIL_FUNC",
|
||||||
|
"STENCIL_VALUE_MASK",
|
||||||
|
"STENCIL_REF",
|
||||||
|
"STENCIL_BACK_FUNC",
|
||||||
|
"STENCIL_BACK_VALUE_MASK",
|
||||||
|
"STENCIL_BACK_REF",
|
||||||
|
"STENCIL_BITS"
|
||||||
|
];
|
||||||
|
return random.item(param);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomStencilMaskParameter(isWebGL2) {
|
||||||
|
let param = ["STENCIL_WRITEMASK", "STENCIL_BACK_WRITEMASK", "STENCIL_BITS"];
|
||||||
|
return random.item(param);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomVertexAttribParameter(isWebGL2) {
|
||||||
|
let pname = [
|
||||||
|
"VERTEX_ATTRIB_ARRAY_BUFFER_BINDING",
|
||||||
|
"VERTEX_ATTRIB_ARRAY_ENABLED",
|
||||||
|
"VERTEX_ATTRIB_ARRAY_SIZE",
|
||||||
|
"VERTEX_ATTRIB_ARRAY_STRIDE",
|
||||||
|
"VERTEX_ATTRIB_ARRAY_TYPE",
|
||||||
|
"VERTEX_ATTRIB_ARRAY_NORMALIZED",
|
||||||
|
"CURRENT_VERTEX_ATTRIB"
|
||||||
|
];
|
||||||
|
if (isWebGL2) {
|
||||||
|
pname = [
|
||||||
|
...pname,
|
||||||
|
"VERTEX_ATTRIB_ARRAY_INTEGER",
|
||||||
|
"VERTEX_ATTRIB_ARRAY_DIVISOR",
|
||||||
|
"VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return random.item(pname);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomHint(isWebGL2) {
|
||||||
|
let target = ["GENERATE_MIPMAP_HINT"];
|
||||||
|
if (isWebGL2) {
|
||||||
|
target = [...target, "FRAGMENT_SHADER_DERIVATIVE_HINT"];
|
||||||
|
}
|
||||||
|
return random.item(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomHintMode(isWebGL2) {
|
||||||
|
let mode = ["FASTEST", "NICEST", "DONT_CARE"];
|
||||||
|
return random.item(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomPixelStorage(isWebGL2) {
|
||||||
|
let pname = {
|
||||||
|
PACK_ALIGNMENT: random.item([1, 2, 4, 8]),
|
||||||
|
UNPACK_ALIGNMENT: random.item([1, 2, 4, 8]),
|
||||||
|
UNPACK_FLIP_Y_WEBGL: random.bool(),
|
||||||
|
UNPACK_PREMULTIPLY_ALPHA_WEBGL: random.bool(),
|
||||||
|
UNPACK_COLORSPACE_CONVERSION_WEBGL: random.item([0, 0x9244])
|
||||||
|
};
|
||||||
|
if (isWebGL2) {
|
||||||
|
Object.assign(pname, {
|
||||||
|
PACK_ROW_LENGTH: numbers.any(),
|
||||||
|
PACK_SKIP_PIXELS: numbers.any(),
|
||||||
|
PACK_SKIP_ROWS: numbers.any(),
|
||||||
|
UNPACK_ROW_LENGTH: numbers.any(),
|
||||||
|
UNPACK_IMAGE_HEIGHT: numbers.any(),
|
||||||
|
UNPACK_SKIP_PIXELS: numbers.any(),
|
||||||
|
UNPACK_SKIP_ROWS: numbers.any(),
|
||||||
|
UNPACK_SKIP_IMAGES: numbers.any()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let name = random.item(Object.keys(pname));
|
||||||
|
return [name, pname[name]];
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomStencilAction(isWebGL2) {
|
||||||
|
let action = [
|
||||||
|
"KEEP",
|
||||||
|
"ZERO",
|
||||||
|
"REPLACE",
|
||||||
|
"INCR",
|
||||||
|
"INCR_WRAP",
|
||||||
|
"DECR",
|
||||||
|
"DECR_WRAP",
|
||||||
|
"INVERT"
|
||||||
|
];
|
||||||
|
return random.item(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomQueryTarget(isWebGL2) {
|
||||||
|
let target = [
|
||||||
|
"ANY_SAMPLES_PASSED",
|
||||||
|
"ANY_SAMPLES_PASSED_CONSERVATIVE",
|
||||||
|
"TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN"
|
||||||
|
];
|
||||||
|
return random.item(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomQueryPname(isWebGL2) {
|
||||||
|
let pname = ["CURRENT_QUERY", "QUERY_RESULT", "QUERY_RESULT_AVAILABLE"];
|
||||||
|
return random.item(pname);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomSamplerParameter(isWebGL2) {
|
||||||
|
let pname = [
|
||||||
|
"TEXTURE_MAG_FILTER",
|
||||||
|
"TEXTURE_MIN_FILTER",
|
||||||
|
"TEXTURE_WRAP_S",
|
||||||
|
"TEXTURE_WRAP_T",
|
||||||
|
"TEXTURE_BASE_LEVEL",
|
||||||
|
"TEXTURE_COMPARE_FUNC",
|
||||||
|
"TEXTURE_COMPARE_MODE",
|
||||||
|
"TEXTURE_MAX_LEVEL",
|
||||||
|
"TEXTURE_WRAP_R",
|
||||||
|
"TEXTURE_MAX_LOD",
|
||||||
|
"TEXTURE_MIN_LOD",
|
||||||
|
"TEXTURE_MAX_ANISOTROPY_EXT"
|
||||||
|
];
|
||||||
|
return random.item(pname);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomSyncParameter(isWebGL2) {
|
||||||
|
let pname = ["OBJECT_TYPE", "SYNC_STATUS", "SYNC_CONDITION", "SYNC_FLAGS"];
|
||||||
|
return random.item(pname);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomClearBuffer(isWebGL2) {
|
||||||
|
let buffer = ["COLOR", "DEPTH", "STENCIL", "DEPTH_STENCIL"];
|
||||||
|
return random.item(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomBindBufferTarget(isWebGL2) {
|
||||||
|
let target = ["TRANSFORM_FEEDBACK_BUFFER", "UNIFORM_BUFFER"];
|
||||||
|
return random.item(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomIndexedParameterTarget(isWebGL2) {
|
||||||
|
let target = [
|
||||||
|
"TRANSFORM_FEEDBACK_BUFFER_BINDING",
|
||||||
|
"TRANSFORM_FEEDBACK_BUFFER_SIZE",
|
||||||
|
"TRANSFORM_FEEDBACK_BUFFER_START",
|
||||||
|
"UNIFORM_BUFFER_BINDING",
|
||||||
|
"UNIFORM_BUFFER_SIZE",
|
||||||
|
"UNIFORM_BUFFER_START"
|
||||||
|
];
|
||||||
|
return random.item(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomUniformParameter(isWebGL2) {
|
||||||
|
let pname = [
|
||||||
|
"UNIFORM_TYPE",
|
||||||
|
"UNIFORM_SIZE",
|
||||||
|
"UNIFORM_BLOCK_INDEX",
|
||||||
|
"UNIFORM_OFFSET",
|
||||||
|
"UNIFORM_ARRAY_STRIDE",
|
||||||
|
"UNIFORM_MATRIX_STRIDE",
|
||||||
|
"UNIFORM_IS_ROW_MAJOR"
|
||||||
|
];
|
||||||
|
return random.item(pname);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomUniformBlockParameter(isWebGL2) {
|
||||||
|
let pname = [
|
||||||
|
"UNIFORM_BLOCK_BINDING",
|
||||||
|
"UNIFORM_BLOCK_DATA_SIZE",
|
||||||
|
"UNIFORM_BLOCK_ACTIVE_UNIFORMS",
|
||||||
|
"UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES",
|
||||||
|
"UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER",
|
||||||
|
"UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER"
|
||||||
|
];
|
||||||
|
return random.item(pname);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomPixelDatatype(isWebGL2) {
|
||||||
|
let type = [
|
||||||
|
"UNSIGNED_BYTE",
|
||||||
|
"UNSIGNED_SHORT",
|
||||||
|
"UNSIGNED_SHORT_5_6_5",
|
||||||
|
"UNSIGNED_SHORT_4_4_4_4",
|
||||||
|
"UNSIGNED_SHORT_5_5_5_1",
|
||||||
|
"UNSIGNED_INT",
|
||||||
|
"FLOAT"
|
||||||
|
];
|
||||||
|
return random.item(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomBufferUsage(isWebGL2) {
|
||||||
|
let usage = ["STATIC_DRAW", "DYNAMIC_DRAW", "STREAM_DRAW"];
|
||||||
|
if (isWebGL2) {
|
||||||
|
usage = [
|
||||||
|
...usage,
|
||||||
|
"STATIC_READ",
|
||||||
|
"DYNAMIC_READ",
|
||||||
|
"STREAM_READ",
|
||||||
|
"STATIC_COPY",
|
||||||
|
"DYNAMIC_COPY",
|
||||||
|
"STREAM_COPY"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return random.item(usage);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomParameter(isWebGL2) {
|
||||||
|
let pname = [
|
||||||
|
"ACTIVE_TEXTURE",
|
||||||
|
"ALIASED_LINE_WIDTH_RANGE",
|
||||||
|
"ALIASED_POINT_SIZE_RANGE",
|
||||||
|
"ALPHA_BITS",
|
||||||
|
"ARRAY_BUFFER_BINDING",
|
||||||
|
"BLEND",
|
||||||
|
"BLEND_COLOR",
|
||||||
|
"BLEND_DST_ALPHA",
|
||||||
|
"BLEND_DST_RGB",
|
||||||
|
"BLEND_EQUATION_ALPHA",
|
||||||
|
"BLEND_EQUATION_RGB",
|
||||||
|
"BLEND_SRC_ALPHA",
|
||||||
|
"BLEND_SRC_RGB",
|
||||||
|
"BLUE_BITS",
|
||||||
|
"COLOR_CLEAR_VALUE",
|
||||||
|
"COLOR_WRITEMASK",
|
||||||
|
"COMPRESSED_TEXTURE_FORMATS",
|
||||||
|
"CULL_FACE",
|
||||||
|
"CULL_FACE_MODE",
|
||||||
|
"CURRENT_PROGRAM",
|
||||||
|
"DEPTH_BITS",
|
||||||
|
"DEPTH_CLEAR_VALUE",
|
||||||
|
"DEPTH_FUNC",
|
||||||
|
"DEPTH_RANGE",
|
||||||
|
"DEPTH_TEST",
|
||||||
|
"DEPTH_WRITEMASK",
|
||||||
|
"DITHER",
|
||||||
|
"ELEMENT_ARRAY_BUFFER_BINDING",
|
||||||
|
"FRAMEBUFFER_BINDING",
|
||||||
|
"FRONT_FACE",
|
||||||
|
"GENERATE_MIPMAP_HINT",
|
||||||
|
"GREEN_BITS",
|
||||||
|
"IMPLEMENTATION_COLOR_READ_FORMAT",
|
||||||
|
"IMPLEMENTATION_COLOR_READ_TYPE",
|
||||||
|
"LINE_WIDTH",
|
||||||
|
"MAX_COMBINED_TEXTURE_IMAGE_UNITS",
|
||||||
|
"MAX_CUBE_MAP_TEXTURE_SIZE",
|
||||||
|
"MAX_FRAGMENT_UNIFORM_VECTORS",
|
||||||
|
"MAX_RENDERBUFFER_SIZE",
|
||||||
|
"MAX_TEXTURE_IMAGE_UNITS",
|
||||||
|
"MAX_TEXTURE_SIZE",
|
||||||
|
"MAX_VARYING_VECTORS",
|
||||||
|
"MAX_VERTEX_ATTRIBS",
|
||||||
|
"MAX_VERTEX_TEXTURE_IMAGE_UNITS",
|
||||||
|
"MAX_VERTEX_UNIFORM_VECTORS",
|
||||||
|
"MAX_VIEWPORT_DIMS",
|
||||||
|
"PACK_ALIGNMENT",
|
||||||
|
"POLYGON_OFFSET_FACTOR",
|
||||||
|
"POLYGON_OFFSET_FILL",
|
||||||
|
"POLYGON_OFFSET_UNITS",
|
||||||
|
"RED_BITS",
|
||||||
|
"RENDERBUFFER_BINDING",
|
||||||
|
"RENDERER",
|
||||||
|
"SAMPLE_ALPHA_TO_COVERAGE",
|
||||||
|
"SAMPLE_BUFFERS",
|
||||||
|
"SAMPLE_COVERAGE",
|
||||||
|
"SAMPLE_COVERAGE_INVERT",
|
||||||
|
"SAMPLE_COVERAGE_VALUE",
|
||||||
|
"SAMPLES",
|
||||||
|
"SCISSOR_BOX",
|
||||||
|
"SCISSOR_TEST",
|
||||||
|
"SHADING_LANGUAGE_VERSION",
|
||||||
|
"STENCIL_BACK_FAIL",
|
||||||
|
"STENCIL_BACK_FUNC",
|
||||||
|
"STENCIL_BACK_PASS_DEPTH_FAIL",
|
||||||
|
"STENCIL_BACK_PASS_DEPTH_PASS",
|
||||||
|
"STENCIL_BACK_REF",
|
||||||
|
"STENCIL_BACK_VALUE_MASK",
|
||||||
|
"STENCIL_BACK_WRITEMASK",
|
||||||
|
"STENCIL_BITS",
|
||||||
|
"STENCIL_CLEAR_VALUE",
|
||||||
|
"STENCIL_FAIL",
|
||||||
|
"STENCIL_FUNC",
|
||||||
|
"STENCIL_PASS_DEPTH_FAIL",
|
||||||
|
"STENCIL_PASS_DEPTH_PASS",
|
||||||
|
"STENCIL_REF",
|
||||||
|
"STENCIL_TEST",
|
||||||
|
"STENCIL_VALUE_MASK",
|
||||||
|
"STENCIL_WRITEMASK",
|
||||||
|
"SUBPIXEL_BITS",
|
||||||
|
"TEXTURE_BINDING_2D",
|
||||||
|
"TEXTURE_BINDING_CUBE_MAP",
|
||||||
|
"UNPACK_ALIGNMENT",
|
||||||
|
"UNPACK_COLORSPACE_CONVERSION_WEBGL",
|
||||||
|
"UNPACK_FLIP_Y_WEBGL",
|
||||||
|
"UNPACK_PREMULTIPLY_ALPHA_WEBGL",
|
||||||
|
"VENDOR",
|
||||||
|
"VERSION",
|
||||||
|
"VIEWPORT",
|
||||||
|
"VERSION",
|
||||||
|
"SHADING_LANGUAGE_VERSION",
|
||||||
|
"VENDOR",
|
||||||
|
"RENDERER"
|
||||||
|
];
|
||||||
|
|
||||||
|
if (isWebGL2) {
|
||||||
|
pname = [
|
||||||
|
...pname,
|
||||||
|
"COPY_READ_BUFFER_BINDING",
|
||||||
|
"COPY_WRITE_BUFFER_BINDING",
|
||||||
|
"DRAW_BUFFERi",
|
||||||
|
"DRAW_FRAMEBUFFER_BINDING",
|
||||||
|
"FRAGMENT_SHADER_DERIVATIVE_HINT",
|
||||||
|
"MAX_3D_TEXTURE_SIZE",
|
||||||
|
"MAX_ARRAY_TEXTURE_LAYERS",
|
||||||
|
"MAX_CLIENT_WAIT_TIMEOUT_WEBGL",
|
||||||
|
"MAX_COLOR_ATTACHMENTS",
|
||||||
|
"MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS",
|
||||||
|
"MAX_COMBINED_UNIFORM_BLOCKS",
|
||||||
|
"MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS",
|
||||||
|
"MAX_DRAW_BUFFERS",
|
||||||
|
"MAX_ELEMENT_INDEX",
|
||||||
|
"MAX_ELEMENTS_INDICE",
|
||||||
|
"MAX_ELEMENTS_VERTICES",
|
||||||
|
"MAX_FRAGMENT_INPUT_COMPONENTS",
|
||||||
|
"MAX_FRAGMENT_UNIFORM_BLOCKS",
|
||||||
|
"MAX_FRAGMENT_UNIFORM_COMPONENTS",
|
||||||
|
"MAX_PROGRAM_TEXEL_OFFSET",
|
||||||
|
"MAX_SAMPLES",
|
||||||
|
"MAX_SERVER_WAIT_TIMEOUT",
|
||||||
|
"MAX_TEXTURE_LOD_BIAS",
|
||||||
|
"MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS",
|
||||||
|
"MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS",
|
||||||
|
"MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS",
|
||||||
|
"MAX_UNIFORM_BLOCK_SIZE",
|
||||||
|
"MAX_UNIFORM_BUFFER_BINDINGS",
|
||||||
|
"MAX_VARYING_COMPONENTS",
|
||||||
|
"MAX_VERTEX_OUTPUT_COMPONENTS",
|
||||||
|
"MAX_VERTEX_UNIFORM_BLOCKS",
|
||||||
|
"MAX_VERTEX_UNIFORM_COMPONENTS",
|
||||||
|
"MIN_PROGRAM_TEXEL_OFFSET",
|
||||||
|
"PACK_ROW_LENGTH",
|
||||||
|
"PACK_SKIP_PIXELS",
|
||||||
|
"PACK_SKIP_ROWS",
|
||||||
|
"PIXEL_PACK_BUFFER_BINDING",
|
||||||
|
"PIXEL_UNPACK_BUFFER_BINDING",
|
||||||
|
"RASTERIZER_DISCARD",
|
||||||
|
"READ_BUFFER",
|
||||||
|
"READ_FRAMEBUFFER_BINDING",
|
||||||
|
"SAMPLER_BINDING",
|
||||||
|
"TEXTURE_BINDING_2D_ARRAY",
|
||||||
|
"TEXTURE_BINDING_3D",
|
||||||
|
"TRANSFORM_FEEDBACK_ACTIVE",
|
||||||
|
"TRANSFORM_FEEDBACK_BINDING",
|
||||||
|
"TRANSFORM_FEEDBACK_BUFFER_BINDING",
|
||||||
|
"TRANSFORM_FEEDBACK_PAUSED",
|
||||||
|
"UNIFORM_BUFFER_BINDING",
|
||||||
|
"UNIFORM_BUFFER_OFFSET_ALIGNMENT",
|
||||||
|
"UNPACK_IMAGE_HEIGHT",
|
||||||
|
"UNPACK_ROW_LENGTH",
|
||||||
|
"UNPACK_SKIP_IMAGES",
|
||||||
|
"UNPACK_SKIP_PIXELS",
|
||||||
|
"UNPACK_SKIP_ROWS",
|
||||||
|
"VERTEX_ARRAY_BINDING"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return random.item(pname);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomProgramParameter() {
|
||||||
|
let pname = [
|
||||||
|
"DELETE_STATUS",
|
||||||
|
"LINK_STATUS",
|
||||||
|
"VALIDATE_STATUS",
|
||||||
|
"ATTACHED_SHADERS",
|
||||||
|
"ACTIVE_ATTRIBUTES",
|
||||||
|
"ACTIVE_UNIFORMS",
|
||||||
|
"TRANSFORM_FEEDBACK_BUFFER_MODE",
|
||||||
|
"TRANSFORM_FEEDBACK_VARYINGS",
|
||||||
|
"ACTIVE_UNIFORM_BLOCKS"
|
||||||
|
];
|
||||||
|
return random.item(pname);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomRenderBufferParameter() {
|
||||||
|
let pname = [
|
||||||
|
"RENDERBUFFER_WIDTH",
|
||||||
|
"RENDERBUFFER_HEIGHT",
|
||||||
|
"RENDERBUFFER_INTERNAL_FORMAT",
|
||||||
|
"RENDERBUFFER_RED_SIZE",
|
||||||
|
"RENDERBUFFER_GREEN_SIZE",
|
||||||
|
"RENDERBUFFER_BLUE_SIZE",
|
||||||
|
"RENDERBUFFER_ALPHA_SIZE",
|
||||||
|
"RENDERBUFFER_DEPTH_SIZE",
|
||||||
|
"RENDERBUFFER_STENCIL_SIZE"
|
||||||
|
];
|
||||||
|
return random.item(pname);
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomExtension(pattern) {
|
||||||
|
let extensions = [
|
||||||
|
"ANGLE_instanced_arrays",
|
||||||
|
"EXT_blend_minmax",
|
||||||
|
"EXT_color_buffer_half_float",
|
||||||
|
"EXT_frag_depth",
|
||||||
|
"EXT_sRGB",
|
||||||
|
"EXT_shader_texture_lod",
|
||||||
|
"EXT_texture_filter_anisotropic",
|
||||||
|
"EXT_disjoint_timer_query",
|
||||||
|
"OES_element_index_uint",
|
||||||
|
"OES_standard_derivatives",
|
||||||
|
"OES_texture_float",
|
||||||
|
"OES_texture_float_linear",
|
||||||
|
"OES_texture_half_float",
|
||||||
|
"OES_texture_half_float_linear",
|
||||||
|
"OES_vertex_array_object",
|
||||||
|
"WEBGL_color_buffer_float",
|
||||||
|
"WEBGL_compressed_texture_s3tc",
|
||||||
|
"WEBGL_compressed_texture_s3tc_srgb",
|
||||||
|
"WEBGL_debug_renderer_info",
|
||||||
|
"WEBGL_debug_shaders",
|
||||||
|
"WEBGL_depth_texture",
|
||||||
|
"WEBGL_draw_buffers",
|
||||||
|
"WEBGL_lose_context"
|
||||||
|
];
|
||||||
|
|
||||||
|
if (pattern) {
|
||||||
|
let candidates = [];
|
||||||
|
extensions.forEach(ext =>
|
||||||
|
ext.includes(pattern) ? candidates.push(ext) : ""
|
||||||
|
);
|
||||||
|
if (candidates.length >= 0) {
|
||||||
|
return random.item(candidates);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return random.item(extensions);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,92 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
/* eslint-env jest */
|
|
||||||
const MersenneTwister = require('../mersennetwister')
|
|
||||||
|
|
||||||
describe('MersenneTwister', () => {
|
|
||||||
test('uniform distribution', () => {
|
|
||||||
const N = Math.pow(2, 18)
|
|
||||||
const TRIES = 10
|
|
||||||
const XSQ = 293.25 // quantile of chi-square dist. k=255, p=.05
|
|
||||||
|
|
||||||
let mt = new MersenneTwister()
|
|
||||||
mt.seed(Math.random() * 0x100000000)
|
|
||||||
|
|
||||||
const _test = () => {
|
|
||||||
let tries = []
|
|
||||||
for (let attempt = 0; attempt < TRIES; ++attempt) {
|
|
||||||
let data = new Uint32Array(N)
|
|
||||||
let sh
|
|
||||||
for (let i = 0; i < data.length; ++i) {
|
|
||||||
data[i] = mt.int32()
|
|
||||||
}
|
|
||||||
for (sh = 0; sh <= 24; ++sh) {
|
|
||||||
let bins = new Uint32Array(256)
|
|
||||||
for (let b of data) {
|
|
||||||
++bins[(b >>> sh) & 0xff]
|
|
||||||
}
|
|
||||||
let xsq = bins.reduce((a, v) => {
|
|
||||||
let e = N / bins.length
|
|
||||||
return a + Math.pow(v - e, 2) / e
|
|
||||||
}, 0)
|
|
||||||
/*
|
|
||||||
* XSQ = scipy.stats.chi2.isf(.05, 255)
|
|
||||||
* if xsq > XSQ, the result is biased at 95% significance
|
|
||||||
*/
|
|
||||||
if (xsq < XSQ) {
|
|
||||||
console.log(`Expected x^2 to be < ${XSQ}, got ${xsq} on attempt #${attempt + 1}`)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
tries.push(xsq)
|
|
||||||
}
|
|
||||||
if (sh === 25) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(_test()).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('float distribution', () => {
|
|
||||||
const N = Math.pow(2, 18)
|
|
||||||
const TRIES = 3
|
|
||||||
const XSQ = 564.7 // quantile of chi-square dist. k=511, p=.05
|
|
||||||
|
|
||||||
let mt = new MersenneTwister()
|
|
||||||
mt.seed(Math.random() * 0x100000000)
|
|
||||||
|
|
||||||
const _test = () => {
|
|
||||||
let tries = []
|
|
||||||
for (let attempt = 0; attempt < TRIES; ++attempt) {
|
|
||||||
let bins = new Uint32Array(512)
|
|
||||||
for (let i = 0; i < N; ++i) {
|
|
||||||
let tmp = (mt.real2() * bins.length) >>> 0
|
|
||||||
if (tmp >= bins.length) {
|
|
||||||
throw new Error('random.float() >= 1.0')
|
|
||||||
}
|
|
||||||
++bins[tmp]
|
|
||||||
}
|
|
||||||
let xsq = bins.reduce((a, v) => {
|
|
||||||
let e = N / bins.length
|
|
||||||
return a + Math.pow(v - e, 2) / e
|
|
||||||
}, 0)
|
|
||||||
/*
|
|
||||||
* XSQ = scipy.stats.chi2.isf(.05, 511)
|
|
||||||
* if xsq > XSQ, the result is biased at 95% significance
|
|
||||||
*/
|
|
||||||
if (xsq < XSQ) {
|
|
||||||
console.log(`Expected x^2 to be < ${XSQ}, got ${xsq} on attempt #${attempt + 1}`)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
tries.push(xsq)
|
|
||||||
}
|
|
||||||
// assert.ok(false, "Failed in " + TRIES + " attempts to get xsq lower than " + XSQ + ": " + tries)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
expect(_test()).toBe(true)
|
|
||||||
})
|
|
||||||
})
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,5 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
module.exports = require('./random')
|
|
|
@ -1,89 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* JavaScript version of Mersenne Twister
|
|
||||||
*
|
|
||||||
* @author Yasuharu Okada
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
class MersenneTwister {
|
|
||||||
constructor () {
|
|
||||||
this.N = 624
|
|
||||||
this.M = 397
|
|
||||||
this.UPPER_MASK = 0x80000000
|
|
||||||
this.LOWER_MASK = 0x7fffffff
|
|
||||||
this.MAG01 = new Int32Array([0, 0x9908b0df])
|
|
||||||
|
|
||||||
this.mt = new Int32Array(this.N)
|
|
||||||
this.mti = 625 // The array for the state vector.
|
|
||||||
}
|
|
||||||
|
|
||||||
seed (s) {
|
|
||||||
this.mt[0] = s | 0
|
|
||||||
for (this.mti = 1; this.mti < this.N; this.mti++) {
|
|
||||||
this.mt[this.mti] = Math.imul(1812433253, this.mt[this.mti - 1] ^ (this.mt[this.mti - 1] >>> 30)) + this.mti
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export_state () { // eslint-disable-line camelcase
|
|
||||||
return [this.mt, this.mti]
|
|
||||||
}
|
|
||||||
|
|
||||||
import_state (s) { // eslint-disable-line camelcase
|
|
||||||
this.mt = s[0]
|
|
||||||
this.mti = s[1]
|
|
||||||
}
|
|
||||||
|
|
||||||
export_mta () { // eslint-disable-line camelcase
|
|
||||||
return this.mt
|
|
||||||
}
|
|
||||||
|
|
||||||
import_mta (_mta) { // eslint-disable-line camelcase
|
|
||||||
this.mt = _mta
|
|
||||||
}
|
|
||||||
|
|
||||||
export_mti () { // eslint-disable-line camelcase
|
|
||||||
return this.mti
|
|
||||||
}
|
|
||||||
|
|
||||||
import_mti (_mti) { // eslint-disable-line camelcase
|
|
||||||
this.mti = _mti
|
|
||||||
}
|
|
||||||
|
|
||||||
int32 () {
|
|
||||||
let y, kk
|
|
||||||
|
|
||||||
if (this.mti >= this.N) { /* generate N words at one time */
|
|
||||||
for (kk = 0; kk < this.N - this.M; kk++) {
|
|
||||||
y = ((this.mt[kk] & this.UPPER_MASK) | (this.mt[kk + 1] & this.LOWER_MASK))
|
|
||||||
this.mt[kk] = (this.mt[kk + this.M] ^ (y >>> 1) ^ this.MAG01[y & 0x1])
|
|
||||||
}
|
|
||||||
for (; kk < this.N - 1; kk++) {
|
|
||||||
y = ((this.mt[kk] & this.UPPER_MASK) | (this.mt[kk + 1] & this.LOWER_MASK))
|
|
||||||
this.mt[kk] = (this.mt[kk + (this.M - this.N)] ^ (y >>> 1) ^ this.MAG01[y & 0x1])
|
|
||||||
}
|
|
||||||
y = ((this.mt[this.N - 1] & this.UPPER_MASK) | (this.mt[0] & this.LOWER_MASK))
|
|
||||||
this.mt[this.N - 1] = (this.mt[this.M - 1] ^ (y >>> 1) ^ this.MAG01[y & 0x1])
|
|
||||||
this.mti = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
y = this.mt[this.mti++]
|
|
||||||
|
|
||||||
/* Tempering */
|
|
||||||
y = y ^ (y >>> 11)
|
|
||||||
y = y ^ ((y << 7) & 0x9d2c5680)
|
|
||||||
y = y ^ ((y << 15) & 0xefc60000)
|
|
||||||
y = y ^ (y >>> 18)
|
|
||||||
|
|
||||||
return y >>> 0
|
|
||||||
}
|
|
||||||
|
|
||||||
real2 () {
|
|
||||||
return ((this.int32() >>> 5) * 67108864.0 + (this.int32() >>> 6)) / 9007199254740992.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = MersenneTwister
|
|
106
lib/random/mersennetwister.ts
Normal file
106
lib/random/mersennetwister.ts
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* JavaScript version of Mersenne Twister
|
||||||
|
*
|
||||||
|
* @author Yasuharu Okada
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
export default class MersenneTwister {
|
||||||
|
N = 624;
|
||||||
|
M = 397;
|
||||||
|
UPPER_MASK = 0x80000000;
|
||||||
|
LOWER_MASK = 0x7fffffff;
|
||||||
|
MAG01 = new Int32Array([0, 0x9908b0df]);
|
||||||
|
mt = new Int32Array(this.N);
|
||||||
|
mti = 625; // The array for the state vector.
|
||||||
|
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
|
seed(s) {
|
||||||
|
this.mt[0] = s | 0;
|
||||||
|
for (this.mti = 1; this.mti < this.N; this.mti++) {
|
||||||
|
this.mt[this.mti] =
|
||||||
|
Math.imul(
|
||||||
|
1812433253,
|
||||||
|
this.mt[this.mti - 1] ^ (this.mt[this.mti - 1] >>> 30)
|
||||||
|
) + this.mti;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export_state() {
|
||||||
|
// eslint-disable-line camelcase
|
||||||
|
return [this.mt, this.mti];
|
||||||
|
}
|
||||||
|
|
||||||
|
import_state(s) {
|
||||||
|
// eslint-disable-line camelcase
|
||||||
|
this.mt = s[0];
|
||||||
|
this.mti = s[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
export_mta() {
|
||||||
|
// eslint-disable-line camelcase
|
||||||
|
return this.mt;
|
||||||
|
}
|
||||||
|
|
||||||
|
import_mta(_mta) {
|
||||||
|
// eslint-disable-line camelcase
|
||||||
|
this.mt = _mta;
|
||||||
|
}
|
||||||
|
|
||||||
|
export_mti() {
|
||||||
|
// eslint-disable-line camelcase
|
||||||
|
return this.mti;
|
||||||
|
}
|
||||||
|
|
||||||
|
import_mti(_mti) {
|
||||||
|
// eslint-disable-line camelcase
|
||||||
|
this.mti = _mti;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32() {
|
||||||
|
let y, kk;
|
||||||
|
|
||||||
|
if (this.mti >= this.N) {
|
||||||
|
/* generate N words at one time */
|
||||||
|
for (kk = 0; kk < this.N - this.M; kk++) {
|
||||||
|
y =
|
||||||
|
(this.mt[kk] & this.UPPER_MASK) | (this.mt[kk + 1] & this.LOWER_MASK);
|
||||||
|
this.mt[kk] = this.mt[kk + this.M] ^ (y >>> 1) ^ this.MAG01[y & 0x1];
|
||||||
|
}
|
||||||
|
for (; kk < this.N - 1; kk++) {
|
||||||
|
y =
|
||||||
|
(this.mt[kk] & this.UPPER_MASK) | (this.mt[kk + 1] & this.LOWER_MASK);
|
||||||
|
this.mt[kk] =
|
||||||
|
this.mt[kk + (this.M - this.N)] ^ (y >>> 1) ^ this.MAG01[y & 0x1];
|
||||||
|
}
|
||||||
|
y =
|
||||||
|
(this.mt[this.N - 1] & this.UPPER_MASK) |
|
||||||
|
(this.mt[0] & this.LOWER_MASK);
|
||||||
|
this.mt[this.N - 1] =
|
||||||
|
this.mt[this.M - 1] ^ (y >>> 1) ^ this.MAG01[y & 0x1];
|
||||||
|
this.mti = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
y = this.mt[this.mti++];
|
||||||
|
|
||||||
|
/* Tempering */
|
||||||
|
y = y ^ (y >>> 11);
|
||||||
|
y = y ^ ((y << 7) & 0x9d2c5680);
|
||||||
|
y = y ^ ((y << 15) & 0xefc60000);
|
||||||
|
y = y ^ (y >>> 18);
|
||||||
|
|
||||||
|
return y >>> 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
real2() {
|
||||||
|
return (
|
||||||
|
((this.int32() >>> 5) * 67108864.0 + (this.int32() >>> 6)) /
|
||||||
|
9007199254740992.0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,20 +2,21 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
const MersenneTwister = require('./mersennetwister')
|
import MersenneTwister from "./mersennetwister.ts";
|
||||||
const logger = require('../logging')
|
|
||||||
|
export default class random {
|
||||||
|
static twister: MersenneTwister;
|
||||||
|
|
||||||
class random {
|
|
||||||
/**
|
/**
|
||||||
* Must be called before any other methods can be called to initialize MersenneTwister
|
* Must be called before any other methods can be called to initialize MersenneTwister
|
||||||
* @param {?number} seed - Value to initialize MersenneTwister
|
* @param {?number} seed - Value to initialize MersenneTwister
|
||||||
*/
|
*/
|
||||||
static init(seed = null) {
|
static init(seed = null) {
|
||||||
if (seed === null) {
|
if (seed === null) {
|
||||||
seed = new Date().getTime()
|
seed = new Date().getTime();
|
||||||
}
|
}
|
||||||
random.twister = new MersenneTwister()
|
random.twister = new MersenneTwister();
|
||||||
random.twister.seed(seed)
|
random.twister.seed(seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,16 +25,16 @@ class random {
|
||||||
*/
|
*/
|
||||||
static number(limit = 0xffffffff) {
|
static number(limit = 0xffffffff) {
|
||||||
if (!random.twister) {
|
if (!random.twister) {
|
||||||
throw new Error('random.init must be called first.')
|
throw new Error("random.init must be called first.");
|
||||||
}
|
}
|
||||||
|
|
||||||
let x = (0x100000000 / limit) >>> 0
|
let x = (0x100000000 / limit) >>> 0;
|
||||||
let y = (x * limit) >>> 0
|
let y = (x * limit) >>> 0;
|
||||||
let r
|
let r;
|
||||||
do {
|
do {
|
||||||
r = random.twister.int32()
|
r = random.twister.int32();
|
||||||
} while (y && r >= y) // eslint-disable-line no-unmodified-loop-condition
|
} while (y && r >= y); // eslint-disable-line no-unmodified-loop-condition
|
||||||
return (r / x) >>> 0
|
return (r / x) >>> 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,10 +42,10 @@ class random {
|
||||||
*/
|
*/
|
||||||
static float() {
|
static float() {
|
||||||
if (!random.twister) {
|
if (!random.twister) {
|
||||||
throw new Error('random.init must be called first.')
|
throw new Error("random.init must be called first.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return random.twister.real2()
|
return random.twister.real2();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,15 +55,16 @@ class random {
|
||||||
*/
|
*/
|
||||||
static range(start, limit) {
|
static range(start, limit) {
|
||||||
if (!random.twister) {
|
if (!random.twister) {
|
||||||
throw new Error('random.init must be called first.')
|
throw new Error("random.init must be called first.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNaN(start) || isNaN(limit)) {
|
if (isNaN(start) || isNaN(limit)) {
|
||||||
logger.traceback()
|
throw new TypeError(
|
||||||
throw new TypeError(`random.range() received non-number type: (${start}, ${limit})`)
|
`random.range() received non-number type: (${start}, ${limit})`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return random.number(limit - start + 1) + start
|
return random.number(limit - start + 1) + start;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,7 +72,7 @@ class random {
|
||||||
* @param {number} limit
|
* @param {number} limit
|
||||||
*/
|
*/
|
||||||
static ludOneTo(limit) {
|
static ludOneTo(limit) {
|
||||||
return Math.exp(random.float() * Math.log(limit))
|
return Math.exp(random.float() * Math.log(limit));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,13 +80,12 @@ class random {
|
||||||
* @param {Array} list
|
* @param {Array} list
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
static item (list) {
|
static item<T>(list: T[]): T {
|
||||||
if (!Array.isArray(list)) {
|
if (!Array.isArray(list)) {
|
||||||
logger.traceback()
|
throw new TypeError(`random.item() received invalid object: (${list})`);
|
||||||
throw new TypeError(`random.item() received invalid object: (${list})`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return list[random.number(list.length)]
|
return list[random.number(list.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,14 +93,14 @@ class random {
|
||||||
* @param {Object} obj
|
* @param {Object} obj
|
||||||
*/
|
*/
|
||||||
static key(obj) {
|
static key(obj) {
|
||||||
return random.item(Object.keys(obj))
|
return random.item(Object.keys(obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a random Boolean value
|
* Return a random Boolean value
|
||||||
*/
|
*/
|
||||||
static bool() {
|
static bool() {
|
||||||
return random.item([true, false])
|
return random.item([true, false]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -109,13 +110,13 @@ class random {
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
static pick(obj) {
|
static pick(obj) {
|
||||||
if (typeof obj === 'function') {
|
if (typeof obj === "function") {
|
||||||
return obj()
|
return obj();
|
||||||
} else if (Array.isArray(obj)) {
|
} else if (Array.isArray(obj)) {
|
||||||
return random.pick(random.item(obj))
|
return random.pick(random.item(obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,11 +126,12 @@ class random {
|
||||||
*/
|
*/
|
||||||
static chance(limit = 2) {
|
static chance(limit = 2) {
|
||||||
if (isNaN(limit)) {
|
if (isNaN(limit)) {
|
||||||
logger.traceback()
|
throw new TypeError(
|
||||||
throw new TypeError(`random.chance() received non-number type: (${limit})`)
|
`random.chance() received non-number type: (${limit})`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return random.number(limit) === 1
|
return random.number(limit) === 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -139,23 +141,22 @@ class random {
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
static choose(list, flat = false) {
|
static choose(list, flat = false) {
|
||||||
if (!(Array.isArray(list))) {
|
if (!Array.isArray(list)) {
|
||||||
logger.traceback()
|
throw new TypeError(`random.choose() received non-array type: (${list})`);
|
||||||
throw new TypeError(`random.choose() received non-array type: (${list})`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const expanded = []
|
const expanded = [];
|
||||||
list.forEach(([weight, value]) => {
|
list.forEach(([weight, value]) => {
|
||||||
while (weight--) {
|
while (weight--) {
|
||||||
expanded.push(value)
|
expanded.push(value);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
if (flat) {
|
if (flat) {
|
||||||
return random.item(expanded)
|
return random.item(expanded);
|
||||||
}
|
}
|
||||||
|
|
||||||
return random.pick(expanded)
|
return random.pick(expanded);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -165,18 +166,18 @@ class random {
|
||||||
* @param {Array}
|
* @param {Array}
|
||||||
*/
|
*/
|
||||||
static weighted(list) {
|
static weighted(list) {
|
||||||
const expanded = []
|
const expanded = [];
|
||||||
list.forEach((item) => {
|
list.forEach(item => {
|
||||||
while (item.w--) {
|
while (item.w--) {
|
||||||
expanded.push(item.v)
|
expanded.push(item.v);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
return expanded
|
return expanded;
|
||||||
}
|
}
|
||||||
|
|
||||||
static use(obj) {
|
static use(obj) {
|
||||||
return random.bool() ? obj : ''
|
return random.bool() ? obj : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -184,12 +185,12 @@ class random {
|
||||||
* @param arr
|
* @param arr
|
||||||
*/
|
*/
|
||||||
static shuffle(arr) {
|
static shuffle(arr) {
|
||||||
let i = arr.length
|
let i = arr.length;
|
||||||
while (i--) {
|
while (i--) {
|
||||||
let p = random.number(i + 1)
|
let p = random.number(i + 1);
|
||||||
let t = arr[i]
|
let t = arr[i];
|
||||||
arr[i] = arr[p]
|
arr[i] = arr[p];
|
||||||
arr[p] = t
|
arr[p] = t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,9 +200,9 @@ class random {
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
static shuffled(arr) {
|
static shuffled(arr) {
|
||||||
let newArray = arr.slice()
|
let newArray = arr.slice();
|
||||||
random.shuffle(newArray)
|
random.shuffle(newArray);
|
||||||
return newArray
|
return newArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -210,24 +211,23 @@ class random {
|
||||||
* @param limit
|
* @param limit
|
||||||
* @returns {Array}
|
* @returns {Array}
|
||||||
*/
|
*/
|
||||||
static subset (list, limit) {
|
static subset(list, limit?) {
|
||||||
if (!(Array.isArray(list))) {
|
if (!Array.isArray(list)) {
|
||||||
logger.traceback()
|
throw new TypeError(`random.subset() received non-array type: (${list})`);
|
||||||
throw new TypeError(`random.subset() received non-array type: (${list})`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof limit !== 'number') {
|
if (typeof limit !== "number") {
|
||||||
limit = random.number(list.length + 1)
|
limit = random.number(list.length + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deepclone list
|
// Deepclone list
|
||||||
const temp = JSON.parse(JSON.stringify(list))
|
const temp = JSON.parse(JSON.stringify(list));
|
||||||
const result = []
|
const result = [];
|
||||||
while (limit--) {
|
while (limit--) {
|
||||||
result.push(random.pop(temp))
|
result.push(random.pop(temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -235,18 +235,16 @@ class random {
|
||||||
* @param {*} arr
|
* @param {*} arr
|
||||||
*/
|
*/
|
||||||
static pop(arr) {
|
static pop(arr) {
|
||||||
let i, obj
|
let i, obj;
|
||||||
|
|
||||||
i = random.number(arr.length)
|
i = random.number(arr.length);
|
||||||
obj = arr[i]
|
obj = arr[i];
|
||||||
arr.splice(i, 1)
|
arr.splice(i, 1);
|
||||||
|
|
||||||
return obj
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
static hex(len) {
|
static hex(len) {
|
||||||
return random.number(Math.pow(2, len * 4)).toString(16)
|
return random.number(Math.pow(2, len * 4)).toString(16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = random
|
|
|
@ -1,45 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
const random = require('../random')
|
|
||||||
const utils = require('../utils')
|
|
||||||
|
|
||||||
class block extends utils {
|
|
||||||
static block (list, optional) {
|
|
||||||
if (optional === true) {
|
|
||||||
if (random.chance(6)) {
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function deeper (item) {
|
|
||||||
if (item === null || item === undefined) {
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
if (typeof (item) === 'function') {
|
|
||||||
return item()
|
|
||||||
}
|
|
||||||
if (typeof (item) === 'string') {
|
|
||||||
return item
|
|
||||||
}
|
|
||||||
if (Array.isArray(item)) {
|
|
||||||
let s = ''
|
|
||||||
for (let i = 0; i < item.length; i++) {
|
|
||||||
s += deeper(item[i])
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
return item
|
|
||||||
}
|
|
||||||
|
|
||||||
let asString = ''
|
|
||||||
for (let i = 0; i < list.length; i++) {
|
|
||||||
asString += deeper(list[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
return asString
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = block
|
|
|
@ -1,134 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
const entities = new (require('html-entities').XmlEntities)()
|
|
||||||
const jsesc = require('jsesc')
|
|
||||||
const utils = require('../utils')
|
|
||||||
|
|
||||||
class common extends utils {
|
|
||||||
/**
|
|
||||||
* Escape and quote a string
|
|
||||||
* @param s - String to be quoted
|
|
||||||
* @param {boolean} html - Identifies whether the string must be HTML safe
|
|
||||||
* @returns {*}
|
|
||||||
*/
|
|
||||||
static quote (s, html = false) {
|
|
||||||
const options = {
|
|
||||||
minimal: true,
|
|
||||||
isScriptContext: html
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof s === 'string') {
|
|
||||||
return `'${jsesc(s, options)}'`
|
|
||||||
} else {
|
|
||||||
return jsesc(s, options)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove quotes and escape sequence from string
|
|
||||||
* @param {string} s
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
static unquote (s) {
|
|
||||||
return s.replace(/\\'/g, '\'')
|
|
||||||
.replace(/\\"/g, '"')
|
|
||||||
.replace(/\\0/g, '\0')
|
|
||||||
.replace(/\\\\/g, '\\')
|
|
||||||
.replace(/(^['|"])(.*)\1$/gm, '$2')
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unicode safe b64 encoding
|
|
||||||
* https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem
|
|
||||||
* @param {string} str
|
|
||||||
* @returns {*}
|
|
||||||
*/
|
|
||||||
static b64encode (str) {
|
|
||||||
if (process.browser) {
|
|
||||||
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
|
|
||||||
function toSolidBytes (match, p1) {
|
|
||||||
// noinspection JSCheckFunctionSignatures
|
|
||||||
return String.fromCharCode(`0x${p1}`)
|
|
||||||
})
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
return Buffer.from(str).toString('base64')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unicode safe b64 decoding
|
|
||||||
* https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem
|
|
||||||
* @param {string} str
|
|
||||||
* @returns {*}
|
|
||||||
*/
|
|
||||||
static b64decode (str) {
|
|
||||||
if (process.browser) {
|
|
||||||
return decodeURIComponent(atob(str).split('').map(function (c) {
|
|
||||||
return `%${('00' + c.charCodeAt(0).toString(16)).slice(-2)}`
|
|
||||||
}).join(''))
|
|
||||||
} else {
|
|
||||||
return Buffer.from(str, 'base64').toString('ascii')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Escape special characters using HTML entities
|
|
||||||
* @param {string} str
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
static htmlEscape (str) {
|
|
||||||
return entities.encode(str)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove HTML entities from string
|
|
||||||
* @param {string} str
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
static htmlUnescape (str) {
|
|
||||||
return entities.decode(str)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove duplicate items from a list
|
|
||||||
* @param {Array} list
|
|
||||||
* @returns {Array}
|
|
||||||
*/
|
|
||||||
static uniqueList (list) {
|
|
||||||
return list.filter((v, i, a) => a.indexOf(v) === i)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Merge two objects recursively
|
|
||||||
* @param {Object} obj1
|
|
||||||
* @param {Object} obj2
|
|
||||||
* @returns {*}
|
|
||||||
*/
|
|
||||||
static mergeHash (obj1, obj2) {
|
|
||||||
for (let p in obj2) {
|
|
||||||
try {
|
|
||||||
if (obj2[p].constructor === Object) {
|
|
||||||
obj1[p] = utils.common.mergeHash(obj1[p], obj2[p])
|
|
||||||
} else {
|
|
||||||
obj1[p] = obj2[p]
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
obj1[p] = obj2[p]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return obj1
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Template string beautifier
|
|
||||||
* @param {Object} obj
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
static mockup (obj) {
|
|
||||||
return obj.split('\n').map((ln) => ln.trim()).join('')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = common
|
|
|
@ -1,31 +0,0 @@
|
||||||
class utils {
|
|
||||||
static get common () {
|
|
||||||
return require('./common')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get block () {
|
|
||||||
return require('./block')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get mutate () {
|
|
||||||
return require('./mutate')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get objects () {
|
|
||||||
return require('./objects')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get platform () {
|
|
||||||
return require('./platform')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get script () {
|
|
||||||
return require('./script')
|
|
||||||
}
|
|
||||||
|
|
||||||
static get prototypes () {
|
|
||||||
return require('./prototypes')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = utils
|
|
|
@ -1,64 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
const make = require('../make')
|
|
||||||
const utils = require('../utils')
|
|
||||||
const random = require('../random')
|
|
||||||
|
|
||||||
class mutate extends utils {
|
|
||||||
static text (str) {
|
|
||||||
let mutator = function (m) {
|
|
||||||
return random.chance(4) ? m : make.text.any()
|
|
||||||
}
|
|
||||||
return str.replace(/[a-zA-Z]+?/g, mutator)
|
|
||||||
}
|
|
||||||
|
|
||||||
static numbers (str) {
|
|
||||||
let mutator = function (m) {
|
|
||||||
return random.chance(4) ? m : make.number.any()
|
|
||||||
}
|
|
||||||
return str.replace(/-?\d+(\.\d+)?/g, mutator)
|
|
||||||
}
|
|
||||||
|
|
||||||
static units (str) {
|
|
||||||
let mutator = function (m, p1) {
|
|
||||||
if (random.chance(4)) {
|
|
||||||
return m
|
|
||||||
} else {
|
|
||||||
return p1 + make.unit.unit()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return str.replace(/(\d+)(px|em|ex|ch|rem|mm|cm|in|pt|pc|%')/g, mutator)
|
|
||||||
}
|
|
||||||
|
|
||||||
static random (str) {
|
|
||||||
let mutator = function (m) {
|
|
||||||
if (random.chance(20)) {
|
|
||||||
if (str.match(/[0-9]/g)) {
|
|
||||||
return make.number.any()
|
|
||||||
} else {
|
|
||||||
return make.text.any()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return str.replace(/./g, mutator)
|
|
||||||
}
|
|
||||||
|
|
||||||
static any (str) {
|
|
||||||
switch (random.number(4)) {
|
|
||||||
case 0:
|
|
||||||
return utils.mutate.text(str)
|
|
||||||
case 1:
|
|
||||||
return utils.mutate.numbers(str)
|
|
||||||
case 2:
|
|
||||||
return utils.mutate.units(str)
|
|
||||||
case 3:
|
|
||||||
return utils.mutate.random(str)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = mutate
|
|
|
@ -1,119 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
const random = require('../random')
|
|
||||||
const logger = require('../logging')
|
|
||||||
|
|
||||||
var o = null // eslint-disable-line no-unused-vars
|
|
||||||
|
|
||||||
class Objects {
|
|
||||||
constructor () {
|
|
||||||
this.counter = 0
|
|
||||||
this.container = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
add (category, member) {
|
|
||||||
if (!member) {
|
|
||||||
member = 'o' + this.counter
|
|
||||||
}
|
|
||||||
if (!this.has(category)) {
|
|
||||||
this.container[category] = []
|
|
||||||
}
|
|
||||||
this.container[category].push({ type: category, name: member })
|
|
||||||
++this.counter
|
|
||||||
return this.container[category].slice(-1)[0].name
|
|
||||||
}
|
|
||||||
|
|
||||||
get (category, last) {
|
|
||||||
if (!(category in this.container)) {
|
|
||||||
// return {type:null, name:null};
|
|
||||||
logger.traceback()
|
|
||||||
throw new Error(`${category} is not available.`)
|
|
||||||
}
|
|
||||||
if (last) {
|
|
||||||
return this.container[category].slice(-1)[0]
|
|
||||||
}
|
|
||||||
return random.pick(this.container[category])
|
|
||||||
}
|
|
||||||
|
|
||||||
pick (category, last) {
|
|
||||||
try {
|
|
||||||
return this.get(category, last).name
|
|
||||||
} catch (e) {
|
|
||||||
logger.traceback()
|
|
||||||
throw logger.JSError(`Error: pick('${category}') is undefined.`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pop (objectName) {
|
|
||||||
let self = this
|
|
||||||
Object.keys(this.container).forEach(function (category) {
|
|
||||||
self.container[category].forEach(function (obj) {
|
|
||||||
if (obj.name === objectName) {
|
|
||||||
self.container[category].splice(self.container[category].indexOf(obj), 1)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
contains (categoryNames) {
|
|
||||||
let categories = []
|
|
||||||
let self = this
|
|
||||||
categoryNames.forEach(function (name) {
|
|
||||||
if (self.has(name)) {
|
|
||||||
categories.push(name)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return (categories.length === 0) ? null : categories
|
|
||||||
}
|
|
||||||
|
|
||||||
show (category) {
|
|
||||||
return (category in this.container) ? this.container[category] : this.container
|
|
||||||
}
|
|
||||||
|
|
||||||
count (category) {
|
|
||||||
return (category in this.container) ? this.container[category].length : 0
|
|
||||||
}
|
|
||||||
|
|
||||||
has (category) {
|
|
||||||
if (category in this.container) {
|
|
||||||
this.check(category)
|
|
||||||
return this.container[category].length > 0
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
valid () {
|
|
||||||
let items = []
|
|
||||||
let self = this
|
|
||||||
Object.keys(self.container).forEach(function (category) {
|
|
||||||
self.check(category)
|
|
||||||
})
|
|
||||||
Object.keys(self.container).forEach(function (category) {
|
|
||||||
for (let i = 0; i < self.container[category].length; i++) {
|
|
||||||
items.push(self.container[category][i].name)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return items
|
|
||||||
}
|
|
||||||
|
|
||||||
check (category) {
|
|
||||||
let self = this
|
|
||||||
self.container[category].forEach(function (object) {
|
|
||||||
try {
|
|
||||||
let x = /* frame.contentWindow. */ eval(object.name) // eslint-disable-line no-eval
|
|
||||||
if (x === undefined || x === null) {
|
|
||||||
self.pop(object.name)
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
self.pop(object.name)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
o,
|
|
||||||
Objects
|
|
||||||
}
|
|
|
@ -1,113 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
const utils = require('../utils')
|
|
||||||
|
|
||||||
class platform extends utils {
|
|
||||||
static get name () {
|
|
||||||
let platform = {}
|
|
||||||
|
|
||||||
/* In case we are running in Node. */
|
|
||||||
if (typeof window === 'undefined') {
|
|
||||||
return platform
|
|
||||||
}
|
|
||||||
|
|
||||||
const userAgent = (navigator.userAgent).toLowerCase()
|
|
||||||
const language = navigator.language || navigator.browserLanguage
|
|
||||||
|
|
||||||
const version = platform.version = (userAgent.match(/.*(?:rv|chrome|webkit|opera|ie)[/: ](.+?)([ );]|$)/) || [])[1]
|
|
||||||
const webkitVersion = (userAgent.match(/webkit\/(.+?) /) || [])[1]
|
|
||||||
|
|
||||||
platform.windows = platform.isWindows = !!/windows/.test(userAgent)
|
|
||||||
platform.mac = platform.isMac = !!/macintosh/.test(userAgent) || (/mac os x/.test(userAgent) && !/like mac os x/.test(userAgent))
|
|
||||||
platform.lion = platform.isLion = !!(/mac os x 10_7/.test(userAgent) && !/like mac os x 10_7/.test(userAgent))
|
|
||||||
platform.iPhone = platform.isiPhone = !!/iphone/.test(userAgent)
|
|
||||||
platform.iPod = platform.isiPod = !!/ipod/.test(userAgent)
|
|
||||||
platform.iPad = platform.isiPad = !!/ipad/.test(userAgent)
|
|
||||||
platform.iOS = platform.isiOS = platform.iPhone || platform.iPod || platform.iPad
|
|
||||||
platform.android = platform.isAndroid = !!/android/.test(userAgent)
|
|
||||||
platform.opera = /opera/.test(userAgent) ? version : 0
|
|
||||||
platform.isOpera = !!platform.opera
|
|
||||||
platform.msie = /msie/.test(userAgent) && !platform.opera ? version : 0
|
|
||||||
platform.isIE = !!platform.msie
|
|
||||||
platform.isIE8OrLower = !!(platform.msie && parseInt(platform.msie, 10) <= 8)
|
|
||||||
platform.mozilla = /mozilla/.test(userAgent) && !/(compatible|webkit|msie)/.test(userAgent) ? version : 0
|
|
||||||
platform.isMozilla = !!platform.mozilla
|
|
||||||
platform.webkit = /webkit/.test(userAgent) ? webkitVersion : 0
|
|
||||||
platform.isWebkit = !!platform.webkit
|
|
||||||
platform.chrome = /chrome/.test(userAgent) ? version : 0
|
|
||||||
platform.isChrome = !!platform.chrome
|
|
||||||
platform.mobileSafari = /apple.*mobile/.test(userAgent) && platform.iOS ? webkitVersion : 0
|
|
||||||
platform.isMobileSafari = !!platform.mobileSafari
|
|
||||||
platform.iPadSafari = platform.iPad && platform.isMobileSafari ? webkitVersion : 0
|
|
||||||
platform.isiPadSafari = !!platform.iPadSafari
|
|
||||||
platform.iPhoneSafari = platform.iPhone && platform.isMobileSafari ? webkitVersion : 0
|
|
||||||
platform.isiPhoneSafari = !!platform.iphoneSafari
|
|
||||||
platform.iPodSafari = platform.iPod && platform.isMobileSafari ? webkitVersion : 0
|
|
||||||
platform.isiPodSafari = !!platform.iPodSafari
|
|
||||||
platform.isiOSHomeScreen = platform.isMobileSafari && !/apple.*mobile.*safari/.test(userAgent)
|
|
||||||
platform.safari = platform.webkit && !platform.chrome && !platform.iOS && !platform.android ? webkitVersion : 0
|
|
||||||
platform.isSafari = !!platform.safari
|
|
||||||
platform.language = language.split('-', 1)[0]
|
|
||||||
platform.current =
|
|
||||||
platform.msie ? 'msie' : platform.mozilla ? 'mozilla' : platform.chrome ? 'chrome' : platform.safari ? 'safari' : platform.opera ? 'opera' : platform.mobileSafari ? 'mobile-safari' : platform.android ? 'android' : 'unknown'
|
|
||||||
|
|
||||||
function platformName (candidates) {
|
|
||||||
for (let i = 0; i < candidates.length; i++) {
|
|
||||||
if (candidates[i] in window) {
|
|
||||||
return `window.${candidates[i]}`
|
|
||||||
}
|
|
||||||
if (candidates[i] in navigator) {
|
|
||||||
return `navigator.${candidates[i]}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
platform.GUM = platformName(['getUserMedia', 'webkitGetUserMedia', 'mozGetUserMedia', 'msGetUserMedia', 'getGUM'])
|
|
||||||
platform.PeerConnection = platformName(['webkitRTCPeerConnection', 'mozRTCPeerConnection', 'msPeerConnection'])
|
|
||||||
platform.IceCandidate = platformName(['mozRTCIceCandidate', 'RTCIceCandidate'])
|
|
||||||
platform.SessionDescription = platformName(['mozRTCSessionDescription', 'RTCSessionDescription'])
|
|
||||||
platform.URL = platformName(['URL', 'webkitURL'])
|
|
||||||
platform.AudioContext = platformName(['AudioContext', 'webkitAudioContext'])
|
|
||||||
platform.OfflineAudioContext = platformName(['OfflineAudioContext', 'webkitOfflineAudioContext'])
|
|
||||||
platform.MediaSource = platformName(['MediaSource', 'WebKitMediaSource'])
|
|
||||||
|
|
||||||
platform.SpeechRecognition = platformName(['SpeechRecognition', 'webkitSpeechRecognition'])
|
|
||||||
platform.SpeechGrammarList = platformName(['SpeechGrammarList', 'webkitSpeechGrammarList'])
|
|
||||||
platform.SpeechGrammar = platformName(['SpeechGrammar'])
|
|
||||||
|
|
||||||
/*
|
|
||||||
function findWebGLContextName (candidates) {
|
|
||||||
var canvas = document.createElement('canvas')
|
|
||||||
for (var i = 0; i < candidates.length; i++) {
|
|
||||||
var name = candidates[i]
|
|
||||||
try {
|
|
||||||
if (canvas.getContext(name)) {
|
|
||||||
return name
|
|
||||||
}
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
platform.WebGL = 'webgl' // findWebGLContextName(["webgl", "experimental-webgl", "webkit-3d"]);
|
|
||||||
platform.WebGL2 = 'webgl2' // findWebGLContextName(["webgl2", "experimental-webgl2"]);
|
|
||||||
|
|
||||||
platform.captureStreamUntilEnded = 'captureStreamUntilEnded'
|
|
||||||
if (platform.isMozilla) {
|
|
||||||
platform.captureStreamUntilEnded = 'mozCaptureStreamUntilEnded'
|
|
||||||
}
|
|
||||||
|
|
||||||
platform.srcObject = 'srcObject'
|
|
||||||
if (platform.isMozilla) {
|
|
||||||
platform.srcObject = 'mozSrcObject'
|
|
||||||
}
|
|
||||||
|
|
||||||
return platform
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = platform
|
|
53
lib/utils/prototypes.js
vendored
53
lib/utils/prototypes.js
vendored
|
@ -1,53 +0,0 @@
|
||||||
/* eslint no-extend-native: ["error", { "exceptions": ["String", "Array"] }] */
|
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
const utils = require('../utils')
|
|
||||||
|
|
||||||
class prototypes extends utils {
|
|
||||||
static enable () {
|
|
||||||
if (!String.prototype.hasOwnProperty('insert')) {
|
|
||||||
Object.defineProperty(String.prototype, 'insert', {
|
|
||||||
value: function (data, i) {
|
|
||||||
return this.slice(0, i) + data + this.slice(i, this.length)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Array.prototype.hasOwnProperty('has')) {
|
|
||||||
Object.defineProperty(Array.prototype, 'has', {
|
|
||||||
value: function (v) {
|
|
||||||
return this.indexOf(v) !== -1
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Array.prototype.hasOwnProperty('extend')) {
|
|
||||||
Object.defineProperty(Array.prototype, 'extend', {
|
|
||||||
value: function (obj) {
|
|
||||||
if (Array.isArray(obj)) {
|
|
||||||
obj.forEach(function (v) {
|
|
||||||
if (typeof v !== 'undefined') {
|
|
||||||
this.push(v)
|
|
||||||
}
|
|
||||||
}, this)
|
|
||||||
} else {
|
|
||||||
this.push(obj)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Object.hasOwnProperty('isObject')) {
|
|
||||||
Object.defineProperty(Object, 'isObject', {
|
|
||||||
value: function (obj) {
|
|
||||||
return (obj !== null && typeof obj === 'object' &&
|
|
||||||
Object.prototype.toString.call(obj) === '[object Object]')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = prototypes
|
|
|
@ -1,136 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
const random = require('../random')
|
|
||||||
const make = require('../make')
|
|
||||||
const utils = require('../utils')
|
|
||||||
|
|
||||||
class script extends utils {
|
|
||||||
/**
|
|
||||||
* Helper method for appending an element to body or documentElement
|
|
||||||
* @param {string} name - Element identifier
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
static addElementToBody (name) {
|
|
||||||
return `(document.body || document.documentElement).appendChild(${name})`
|
|
||||||
}
|
|
||||||
|
|
||||||
static makeArray (type, arrayLength, cb) {
|
|
||||||
if (type === null || type === undefined) {
|
|
||||||
type = random.item(['Uint8', 'Float32'])
|
|
||||||
}
|
|
||||||
switch (random.number(8)) {
|
|
||||||
case 0:
|
|
||||||
let src = `function() { let buffer = new ${type}Array(${arrayLength});`
|
|
||||||
src += script.makeLoop(`buffer[i] = ${cb()};`, arrayLength)
|
|
||||||
src += 'return buffer;}()'
|
|
||||||
return src
|
|
||||||
case 1:
|
|
||||||
return `new ${type}Array([${make.arrays.filledArray(cb, arrayLength)}])`
|
|
||||||
default:
|
|
||||||
return `new ${type}Array(${arrayLength})`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static makeConstraint (keys, values) {
|
|
||||||
const dict = {}
|
|
||||||
let n = random.range(0, keys.length)
|
|
||||||
while (n--) {
|
|
||||||
dict[random.pick(keys)] = random.pick(values)
|
|
||||||
}
|
|
||||||
return dict
|
|
||||||
}
|
|
||||||
|
|
||||||
static makeLoop (s, max) {
|
|
||||||
return `for (let i = 0; i < ${max || make.number.tiny()}; i++) {${s}}`
|
|
||||||
}
|
|
||||||
|
|
||||||
static makeRandomOptions (baseObject) {
|
|
||||||
const dict = {}
|
|
||||||
let unique = random.subset(Object.keys(baseObject))
|
|
||||||
for (let i = 0; i < unique.length; i++) {
|
|
||||||
dict[unique[i]] = random.pick(baseObject[unique[i]])
|
|
||||||
}
|
|
||||||
return JSON.stringify(dict)
|
|
||||||
}
|
|
||||||
|
|
||||||
static methodCall (objectName, methodHash) {
|
|
||||||
if (!Object.keys(methodHash).length || !objectName) {
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
let methodName = random.key(methodHash)
|
|
||||||
let methodArgs = methodHash[methodName]
|
|
||||||
if (typeof (methodArgs) === 'function') { // Todo: Hmmmm..
|
|
||||||
return methodArgs()
|
|
||||||
}
|
|
||||||
return `${objectName}.${methodName}${script.methodHead(methodArgs)}`
|
|
||||||
}
|
|
||||||
|
|
||||||
static methodHead (list, numOptional) {
|
|
||||||
if (isNaN(numOptional)) {
|
|
||||||
numOptional = 0
|
|
||||||
}
|
|
||||||
let arity = list.length - random.number(numOptional)
|
|
||||||
let params = []
|
|
||||||
for (let i = 0; i < arity; i++) {
|
|
||||||
params.push(random.pick([list[i]]))
|
|
||||||
}
|
|
||||||
return `(${params.join(', ')})`
|
|
||||||
}
|
|
||||||
|
|
||||||
static offset (s) {
|
|
||||||
return `(${random.number()} % ${s})`
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrap command(s) in setInterval, setTimeout, loop or run directly
|
|
||||||
* @param {string|string[]} cmds - Command(s) to be executed
|
|
||||||
* @returns {array}
|
|
||||||
*/
|
|
||||||
static runner (cmds) {
|
|
||||||
cmds = (Array.isArray(cmds)) ? cmds : [cmds]
|
|
||||||
cmds = cmds.filter((i) => i !== undefined)
|
|
||||||
if (cmds.length) {
|
|
||||||
// Wrap each command in try/catch for use in setInterval, setTimeout, repeater
|
|
||||||
switch (random.number(50)) {
|
|
||||||
case 0:
|
|
||||||
return [`setInterval(function () { ${script.safely(cmds)} }, ${random.range(100, 400)} )`]
|
|
||||||
case 1:
|
|
||||||
return [`setTimeout(function () { ${script.safely(cmds)} }, ${random.range(100, 400)} )`]
|
|
||||||
case 2:
|
|
||||||
return [`for (let i = 0; i < ${random.number(random.number(30))}; i++) { ${script.safely(cmds)} }`]
|
|
||||||
default:
|
|
||||||
return cmds
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static safely (obj) {
|
|
||||||
if (Array.isArray(obj)) {
|
|
||||||
return obj.map(s => utils.script.safely(s)).join(' ')
|
|
||||||
} else {
|
|
||||||
return `try { ${obj} } catch(e) { }`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static setAttribute (objectName, attributeHash) {
|
|
||||||
if (!Object.keys(attributeHash).length || !objectName) {
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
let attributeName = random.key(attributeHash)
|
|
||||||
let attributeValue = random.pick(attributeHash[attributeName])
|
|
||||||
let operator = ' = '
|
|
||||||
/*
|
|
||||||
if (typeof(attributeValue) == "number" && Random.chance(8)) {
|
|
||||||
operator = " " + Make.randomAssignmentOperator() + " ";
|
|
||||||
}
|
|
||||||
if (typeof(attributeValue) == "string") {
|
|
||||||
attributeValue = "'" + attributeValue + "'";
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
return `${objectName}.${attributeName}${operator}${attributeValue};`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = script
|
|
92
package.json
92
package.json
|
@ -1,92 +0,0 @@
|
||||||
{
|
|
||||||
"name": "@mozillasecurity/octo",
|
|
||||||
"version": "2.0.0",
|
|
||||||
"description": "A unified shared library which aids in building fuzzers for browsers or as complement for an existing fuzzing framework.",
|
|
||||||
"keywords": [
|
|
||||||
"fuzzing",
|
|
||||||
"browser",
|
|
||||||
"firefox",
|
|
||||||
"random",
|
|
||||||
"javascript",
|
|
||||||
"node",
|
|
||||||
"library"
|
|
||||||
],
|
|
||||||
"homepage": "https://github.com/mozillasecurity/octo",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/mozillasecurity/octo.git"
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/mozillasecurity/octo/issues",
|
|
||||||
"email": "cdiehl@mozilla.com"
|
|
||||||
},
|
|
||||||
"author": "Christoph Diehl <cdiehl@mozilla.com>",
|
|
||||||
"license": "MPL-2.0",
|
|
||||||
"scripts": {
|
|
||||||
"build": "parcel build index.js --out-file=octo.js --no-source-maps",
|
|
||||||
"test": "jest --silent",
|
|
||||||
"coverage": "cross-env NODE_ENV=test jest --silent --coverage --collectCoverageFrom=lib/**/*.js",
|
|
||||||
"coveralls": "yarn coverage && cat ./coverage/lcov.info | coveralls",
|
|
||||||
"lint": "standard --verbose",
|
|
||||||
"lint:fix": "standard --fix --verbose",
|
|
||||||
"docs": "esdoc",
|
|
||||||
"pre-commit": "lint-staged",
|
|
||||||
"release": "np"
|
|
||||||
},
|
|
||||||
"lint-staged": {
|
|
||||||
"*.js": [
|
|
||||||
"yarn lint:fix",
|
|
||||||
"git add"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"standard": {
|
|
||||||
"ignore": [
|
|
||||||
"dist/"
|
|
||||||
],
|
|
||||||
"envs": {
|
|
||||||
"browser": true,
|
|
||||||
"node": true,
|
|
||||||
"es6": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"jest": {
|
|
||||||
"verbose": true
|
|
||||||
},
|
|
||||||
"esdoc": {
|
|
||||||
"source": "./lib",
|
|
||||||
"destination": "./docs",
|
|
||||||
"plugins": [
|
|
||||||
{
|
|
||||||
"name": "esdoc-standard-plugin",
|
|
||||||
"option": {
|
|
||||||
"lint": {
|
|
||||||
"enable": true
|
|
||||||
},
|
|
||||||
"coverage": {
|
|
||||||
"enable": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "esdoc-node"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"coveralls": "^3.0.2",
|
|
||||||
"cross-env": "^5.2.0",
|
|
||||||
"esdoc": "^1.1.0",
|
|
||||||
"esdoc-node": "^1.0.3",
|
|
||||||
"esdoc-standard-plugin": "^1.0.0",
|
|
||||||
"husky": "^1.0.0-rc.14",
|
|
||||||
"jest": "^23.6.0",
|
|
||||||
"lint-staged": "^7.2.2",
|
|
||||||
"np": "^3.0.4",
|
|
||||||
"parcel": "^1.12.4",
|
|
||||||
"standard": "^12.0.1"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"html-entities": "^1.2.1",
|
|
||||||
"jsesc": "^2.5.2"
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue