Beefing up registration and activation of the service worker.
This commit is contained in:
55
package-lock.json
generated
55
package-lock.json
generated
@@ -75,13 +75,13 @@
|
||||
"@vue/cli-service": "~5.0.8",
|
||||
"@vue/eslint-config-typescript": "^11.0.3",
|
||||
"autoprefixer": "^10.4.15",
|
||||
"eslint": "^8.48.0",
|
||||
"eslint": "^8.53.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-plugin-prettier": "^5.0.0",
|
||||
"eslint-plugin-vue": "^9.17.0",
|
||||
"leaflet": "^1.9.4",
|
||||
"postcss": "^8.4.29",
|
||||
"prettier": "^3.0.3",
|
||||
"prettier": "^3.1.0",
|
||||
"tailwindcss": "^3.3.3",
|
||||
"typescript": "~5.2.2"
|
||||
}
|
||||
@@ -2824,9 +2824,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@eslint/eslintrc": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.1.2.tgz",
|
||||
"integrity": "sha512-+wvgpDsrB1YqAMdEUCcnTlpfVBH7Vqn6A/NT3D8WVXFIaKMlErPIZT3oCIAVCOtarRpMtelZLqJeU3t7WY6X6g==",
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.1.3.tgz",
|
||||
"integrity": "sha512-yZzuIG+jnVu6hNSzFEN07e8BxF3uAzYtQb6uDkaYZLo6oYZDCq454c5kB8zxnzfCYyP4MIuyBn10L0DqwujTmA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"ajv": "^6.12.4",
|
||||
@@ -2874,9 +2874,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@eslint/js": {
|
||||
"version": "8.51.0",
|
||||
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.51.0.tgz",
|
||||
"integrity": "sha512-HxjQ8Qn+4SI3/AFv6sOrDB+g6PpUTDwSJiQqOrnneEk8L71161srI9gjzzZvYVbzHiVg/BvcH95+cK/zfIt4pg==",
|
||||
"version": "8.53.0",
|
||||
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.53.0.tgz",
|
||||
"integrity": "sha512-Kn7K8dx/5U6+cT1yEhpX1w4PCSg0M+XyRILPgvwcEBjerFWCwQj5sbr3/VmxqV0JGHCBCzyd6LxypEuehypY1w==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
@@ -5501,12 +5501,12 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@humanwhocodes/config-array": {
|
||||
"version": "0.11.11",
|
||||
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.11.tgz",
|
||||
"integrity": "sha512-N2brEuAadi0CcdeMXUkhbZB84eskAc8MEX1By6qEchoVywSgXPIjou4rYsl0V3Hj0ZnuGycGCjdNgockbzeWNA==",
|
||||
"version": "0.11.13",
|
||||
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.13.tgz",
|
||||
"integrity": "sha512-JSBDMiDKSzQVngfRjOdFXgFfklaXI4K9nLF49Auh21lmBWRLIK3+xTErTWD4KU54pb6coM6ESE7Awz/FNU3zgQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@humanwhocodes/object-schema": "^1.2.1",
|
||||
"@humanwhocodes/object-schema": "^2.0.1",
|
||||
"debug": "^4.1.1",
|
||||
"minimatch": "^3.0.5"
|
||||
},
|
||||
@@ -5528,9 +5528,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@humanwhocodes/object-schema": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz",
|
||||
"integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==",
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.1.tgz",
|
||||
"integrity": "sha512-dvuCeX5fC9dXgJn9t+X5atfmgQAzUOWqS1254Gh0m6i8wKd10ebXkfNKiRK+1GWi/yTvvLDHpoxLr0xxxeslWw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@jest/create-cache-key-function": {
|
||||
@@ -9225,6 +9225,12 @@
|
||||
"url": "https://opencollective.com/typescript-eslint"
|
||||
}
|
||||
},
|
||||
"node_modules/@ungap/structured-clone": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz",
|
||||
"integrity": "sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@unimodules/core": {
|
||||
"version": "7.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@unimodules/core/-/core-7.1.2.tgz",
|
||||
@@ -14239,18 +14245,19 @@
|
||||
}
|
||||
},
|
||||
"node_modules/eslint": {
|
||||
"version": "8.51.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.51.0.tgz",
|
||||
"integrity": "sha512-2WuxRZBrlwnXi+/vFSJyjMqrNjtJqiasMzehF0shoLaW7DzS3/9Yvrmq5JiT66+pNjiX4UBnLDiKHcWAr/OInA==",
|
||||
"version": "8.53.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.53.0.tgz",
|
||||
"integrity": "sha512-N4VuiPjXDUa4xVeV/GC/RV3hQW9Nw+Y463lkWaKKXKYMvmRiRDAtfpuPFLN+E1/6ZhyR8J2ig+eVREnYgUsiag==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@eslint-community/eslint-utils": "^4.2.0",
|
||||
"@eslint-community/regexpp": "^4.6.1",
|
||||
"@eslint/eslintrc": "^2.1.2",
|
||||
"@eslint/js": "8.51.0",
|
||||
"@humanwhocodes/config-array": "^0.11.11",
|
||||
"@eslint/eslintrc": "^2.1.3",
|
||||
"@eslint/js": "8.53.0",
|
||||
"@humanwhocodes/config-array": "^0.11.13",
|
||||
"@humanwhocodes/module-importer": "^1.0.1",
|
||||
"@nodelib/fs.walk": "^1.2.8",
|
||||
"@ungap/structured-clone": "^1.2.0",
|
||||
"ajv": "^6.12.4",
|
||||
"chalk": "^4.0.0",
|
||||
"cross-spawn": "^7.0.2",
|
||||
@@ -23164,9 +23171,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/prettier": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz",
|
||||
"integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==",
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.1.0.tgz",
|
||||
"integrity": "sha512-TQLvXjq5IAibjh8EpBIkNKxO749UEWABoiIZehEPiY4GNpVdhaFKqSTu+QrlU6D2dPAfubRmtJTi4K4YkQ5eXw==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"prettier": "bin/prettier.cjs"
|
||||
|
||||
@@ -75,13 +75,13 @@
|
||||
"@vue/cli-service": "~5.0.8",
|
||||
"@vue/eslint-config-typescript": "^11.0.3",
|
||||
"autoprefixer": "^10.4.15",
|
||||
"eslint": "^8.48.0",
|
||||
"eslint": "^8.53.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-plugin-prettier": "^5.0.0",
|
||||
"eslint-plugin-vue": "^9.17.0",
|
||||
"leaflet": "^1.9.4",
|
||||
"postcss": "^8.4.29",
|
||||
"prettier": "^3.0.3",
|
||||
"prettier": "^3.1.0",
|
||||
"tailwindcss": "^3.3.3",
|
||||
"typescript": "~5.2.2"
|
||||
}
|
||||
|
||||
@@ -295,6 +295,9 @@ export default class App extends Vue {
|
||||
.then((response: VapidResponse) => {
|
||||
this.b64 = response.data.vapidKey;
|
||||
console.log(this.b64);
|
||||
navigator.serviceWorker.addEventListener("controllerchange", () => {
|
||||
console.log("New service worker is now controlling the page");
|
||||
});
|
||||
})
|
||||
.catch((error: AxiosError) => {
|
||||
console.error("API error", error);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { register } from "register-service-worker";
|
||||
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
register(`${process.env.BASE_URL}service-worker.js`, {
|
||||
register("/additional-scripts.js", {
|
||||
ready() {
|
||||
console.log(
|
||||
"App is being served from cache by a service worker.\n" +
|
||||
|
||||
@@ -1,12 +1,26 @@
|
||||
/* eslint-env serviceworker */
|
||||
/* global workbox */
|
||||
importScripts(
|
||||
"https://storage.googleapis.com/workbox-cdn/releases/6.4.1/workbox-sw.js",
|
||||
);
|
||||
|
||||
self.addEventListener("install", (event) => {
|
||||
event.waitUntil(
|
||||
(async () => {
|
||||
importScripts("safari-notifications.js");
|
||||
})(),
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener("push", function (event) {
|
||||
event.waitUntil((async () => {
|
||||
event.waitUntil(
|
||||
(async () => {
|
||||
try {
|
||||
let payload;
|
||||
if (event.data) {
|
||||
payload = JSON.parse(event.data.text());
|
||||
}
|
||||
let value = await self.getNotificationCount();
|
||||
const value = await self.getNotificationCount();
|
||||
const title = payload ? payload.title : "Custom Title";
|
||||
const options = {
|
||||
body: payload ? value : "SAMPLE",
|
||||
@@ -15,16 +29,27 @@ self.addEventListener("push", function (event) {
|
||||
};
|
||||
await self.registration.showNotification(title, options);
|
||||
} catch (error) {
|
||||
console.error('Error in processing the push event:', error);
|
||||
console.error("Error in processing the push event:", error);
|
||||
}
|
||||
})());
|
||||
})(),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
self.addEventListener('message', event => {
|
||||
if (event.data && event.data.type === 'SEND_LOCAL_DATA') {
|
||||
self.addEventListener("message", (event) => {
|
||||
if (event.data && event.data.type === "SEND_LOCAL_DATA") {
|
||||
self.secret = event.data.data;
|
||||
console.log('Data stored in service worker:', self.secret);
|
||||
console.log("Data stored in service worker:", self.secret);
|
||||
event.ports[0].postMessage({ success: true });
|
||||
}
|
||||
});
|
||||
|
||||
self.addEventListener("activate", (event) => {
|
||||
event.waitUntil(clients.claim());
|
||||
console.log("Service worker activated", event);
|
||||
});
|
||||
|
||||
self.addEventListener("fetch", (event) => {
|
||||
console.log(event.request);
|
||||
});
|
||||
|
||||
workbox.precaching.precacheAndRoute(self.__WB_MANIFEST);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,43 +1,48 @@
|
||||
|
||||
async function generateSHA256Hash(data) {
|
||||
const buffer = new TextEncoder().encode(data);
|
||||
const hashBuffer = await crypto.subtle.digest('SHA-256', buffer);
|
||||
const hashBuffer = await crypto.subtle.digest("SHA-256", buffer);
|
||||
const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
|
||||
const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, '0')).join('');
|
||||
const hashHex = hashArray
|
||||
.map((byte) => byte.toString(16).padStart(2, "0"))
|
||||
.join("");
|
||||
return hashHex;
|
||||
}
|
||||
|
||||
function validateBase64(s) {
|
||||
if (!(/^(?:[A-Za-z0-9+\/]{2}[A-Za-z0-9+\/]{2})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/.test(s))) {
|
||||
throw new TypeError('invalid encoding');
|
||||
if (
|
||||
!/^(?:[A-Za-z0-9+\/]{2}[A-Za-z0-9+\/]{2})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/.test(
|
||||
s,
|
||||
)
|
||||
) {
|
||||
throw new TypeError("invalid encoding");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function decodeBase64(s) {
|
||||
validateBase64(s);
|
||||
var i, d = atob(s), b = new Uint8Array(d.length);
|
||||
var i,
|
||||
d = atob(s),
|
||||
b = new Uint8Array(d.length);
|
||||
for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i);
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
async function getSettingById(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let openRequest = indexedDB.open('TimeSafari');
|
||||
let openRequest = indexedDB.open("TimeSafari");
|
||||
|
||||
openRequest.onupgradeneeded = (event) => {
|
||||
// Handle database setup if necessary
|
||||
let db = event.target.result;
|
||||
if (!db.objectStoreNames.contains('settings')) {
|
||||
db.createObjectStore('settings', { keyPath: 'id' });
|
||||
if (!db.objectStoreNames.contains("settings")) {
|
||||
db.createObjectStore("settings", { keyPath: "id" });
|
||||
}
|
||||
};
|
||||
|
||||
openRequest.onsuccess = (event) => {
|
||||
let db = event.target.result;
|
||||
let transaction = db.transaction('settings', 'readonly');
|
||||
let objectStore = transaction.objectStore('settings');
|
||||
let transaction = db.transaction("settings", "readonly");
|
||||
let objectStore = transaction.objectStore("settings");
|
||||
let getRequest = objectStore.get(id);
|
||||
|
||||
getRequest.onsuccess = () => resolve(getRequest.result);
|
||||
@@ -48,22 +53,21 @@ async function getSettingById(id) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async function fetchAllAccounts() {
|
||||
return new Promise((resolve, reject) => {
|
||||
let openRequest = indexedDB.open('TimeSafariAccounts');
|
||||
let openRequest = indexedDB.open("TimeSafariAccounts");
|
||||
|
||||
openRequest.onupgradeneeded = function (event) {
|
||||
let db = event.target.result;
|
||||
if (!db.objectStoreNames.contains('accounts')) {
|
||||
db.createObjectStore('accounts', { keyPath: 'id' });
|
||||
if (!db.objectStoreNames.contains("accounts")) {
|
||||
db.createObjectStore("accounts", { keyPath: "id" });
|
||||
}
|
||||
};
|
||||
|
||||
openRequest.onsuccess = function (event) {
|
||||
let db = event.target.result;
|
||||
let transaction = db.transaction('accounts', 'readonly');
|
||||
let objectStore = transaction.objectStore('accounts');
|
||||
let transaction = db.transaction("accounts", "readonly");
|
||||
let objectStore = transaction.objectStore("accounts");
|
||||
let getAllRequest = objectStore.getAll();
|
||||
|
||||
getAllRequest.onsuccess = function () {
|
||||
@@ -80,18 +84,18 @@ async function fetchAllAccounts() {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async function getNotificationCount() {
|
||||
let secret = null;
|
||||
if ('secret' in self) {
|
||||
let accounts = [];
|
||||
if ("secret" in self) {
|
||||
secret = self.secret;
|
||||
const secretUint8Array = self.decodeBase64(secret);
|
||||
const settings = await getSettingById(1);
|
||||
const activeDid = settings['activeDid'];
|
||||
/**
|
||||
const accounts = await fetchAllAccounts();
|
||||
const activeDid = settings["activeDid"];
|
||||
accounts = await fetchAllAccounts();
|
||||
let did = null;
|
||||
let result = null;
|
||||
/**
|
||||
for (var i = 0; i < accounts.length; i++) {
|
||||
let account = accounts[i];
|
||||
let did = account['did'];
|
||||
@@ -105,9 +109,8 @@ async function getNotificationCount() {
|
||||
}
|
||||
**/
|
||||
}
|
||||
}
|
||||
return secret;
|
||||
return accounts.length;
|
||||
}
|
||||
|
||||
self.getNotificationCount = getNotificationCount;
|
||||
self.decodeBase64 = decodeBase64
|
||||
self.decodeBase64 = decodeBase64;
|
||||
|
||||
@@ -1,95 +1,107 @@
|
||||
(function () {
|
||||
|
||||
randomBytes = length => self.crypto.getRandomValues(new Uint8Array(length))
|
||||
self.Secp256k1 = exports = {}
|
||||
randomBytes = (length) => self.crypto.getRandomValues(new Uint8Array(length));
|
||||
self.Secp256k1 = exports = {};
|
||||
|
||||
function uint256(x, base) {
|
||||
return new BN(x, base)
|
||||
return new BN(x, base);
|
||||
}
|
||||
|
||||
function rnd(P) {
|
||||
return uint256(randomBytes(32)).umod(P)//TODO red
|
||||
return uint256(randomBytes(32)).umod(P); //TODO red
|
||||
}
|
||||
|
||||
const A = uint256(0)
|
||||
const B = uint256(7)
|
||||
const GX = uint256("79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", 16)
|
||||
const GY = uint256("483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8", 16)
|
||||
const P = uint256("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F", 16)
|
||||
const N = uint256("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", 16)
|
||||
const A = uint256(0);
|
||||
const B = uint256(7);
|
||||
const GX = uint256(
|
||||
"79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798",
|
||||
16,
|
||||
);
|
||||
const GY = uint256(
|
||||
"483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8",
|
||||
16,
|
||||
);
|
||||
const P = uint256(
|
||||
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F",
|
||||
16,
|
||||
);
|
||||
const N = uint256(
|
||||
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141",
|
||||
16,
|
||||
);
|
||||
//const RED = BN.red(P)
|
||||
const _0 = uint256(0)
|
||||
const _1 = uint256(1)
|
||||
const _0 = uint256(0);
|
||||
const _1 = uint256(1);
|
||||
|
||||
// function for elliptic curve multiplication in jacobian coordinates using Double-and-add method
|
||||
function ecmul(_p, _d) {
|
||||
let R = [_0,_0,_0]
|
||||
let R = [_0, _0, _0];
|
||||
|
||||
//return (0,0) if d=0 or (x1,y1)=(0,0)
|
||||
if (_d == 0 || ((_p[0] == 0) && (_p[1] == 0)) ) {
|
||||
return R
|
||||
if (_d == 0 || (_p[0] == 0 && _p[1] == 0)) {
|
||||
return R;
|
||||
}
|
||||
let T = [
|
||||
_p[0], //x-coordinate temp
|
||||
_p[1], //y-coordinate temp
|
||||
_p[2], //z-coordinate temp
|
||||
]
|
||||
];
|
||||
|
||||
const d = _d.clone()
|
||||
const d = _d.clone();
|
||||
while (d != 0) {
|
||||
if (d.testn(0)) { //if last bit is 1 add T to result
|
||||
R = ecadd(T,R)
|
||||
if (d.testn(0)) {
|
||||
//if last bit is 1 add T to result
|
||||
R = ecadd(T, R);
|
||||
}
|
||||
T = ecdouble(T); //double temporary coordinates
|
||||
d.iushrn(1); //"cut off" last bit
|
||||
}
|
||||
|
||||
return R
|
||||
return R;
|
||||
}
|
||||
|
||||
function mulmod(a, b, P) {
|
||||
return a.mul(b).umod(P)//TODO red
|
||||
return a.mul(b).umod(P); //TODO red
|
||||
}
|
||||
|
||||
function addmod(a, b, P) {
|
||||
return a.add(b).umod(P)//TODO red
|
||||
return a.add(b).umod(P); //TODO red
|
||||
}
|
||||
|
||||
function invmod(a, P) {
|
||||
return a.invm(P)//TODO redq
|
||||
return a.invm(P); //TODO redq
|
||||
}
|
||||
|
||||
function mulG(k) {
|
||||
const GinJ = AtoJ(GX, GY)
|
||||
const PUBinJ = ecmul(GinJ, k)
|
||||
return JtoA(PUBinJ)
|
||||
const GinJ = AtoJ(GX, GY);
|
||||
const PUBinJ = ecmul(GinJ, k);
|
||||
return JtoA(PUBinJ);
|
||||
}
|
||||
|
||||
function assert(cond, msg) {
|
||||
if (!cond) {
|
||||
throw Error("assertion failed: " + msg)
|
||||
throw Error("assertion failed: " + msg);
|
||||
}
|
||||
}
|
||||
|
||||
function ecsign(d, z) {
|
||||
assert(d != 0, "d must not be 0")
|
||||
assert(z != 0, "z must not be 0")
|
||||
assert(d != 0, "d must not be 0");
|
||||
assert(z != 0, "z must not be 0");
|
||||
while (true) {
|
||||
const k = rnd(P)
|
||||
const R = mulG(k)
|
||||
if (R[0] == 0) continue
|
||||
const s = mulmod(invmod(k, N), addmod(z, mulmod(R[0], d, N), N), N)
|
||||
if (s == 0) continue
|
||||
const k = rnd(P);
|
||||
const R = mulG(k);
|
||||
if (R[0] == 0) continue;
|
||||
const s = mulmod(invmod(k, N), addmod(z, mulmod(R[0], d, N), N), N);
|
||||
if (s == 0) continue;
|
||||
//FIXME: why do I need this
|
||||
if (s.testn(255)) continue
|
||||
return {r: toHex(R[0]), s: toHex(s), v: R[1].testn(0) ? 1 : 0}
|
||||
if (s.testn(255)) continue;
|
||||
return { r: toHex(R[0]), s: toHex(s), v: R[1].testn(0) ? 1 : 0 };
|
||||
}
|
||||
}
|
||||
|
||||
function JtoA(p) {
|
||||
const zInv = invmod(p[2], P)
|
||||
const zInv2 = mulmod(zInv, zInv, P)
|
||||
return [mulmod(p[0], zInv2, P), mulmod(p[1], mulmod(zInv, zInv2, P), P)]
|
||||
const zInv = invmod(p[2], P);
|
||||
const zInv2 = mulmod(zInv, zInv, P);
|
||||
return [mulmod(p[0], zInv2, P), mulmod(p[1], mulmod(zInv, zInv2, P), P)];
|
||||
}
|
||||
|
||||
//point doubling for elliptic curve in jacobian coordinates
|
||||
@@ -97,100 +109,114 @@
|
||||
function ecdouble(_p) {
|
||||
if (_p[1] == 0) {
|
||||
//return point at infinity
|
||||
return [_1, _1, _0]
|
||||
return [_1, _1, _0];
|
||||
}
|
||||
|
||||
const z2 = mulmod(_p[2], _p[2], P)
|
||||
const m = addmod(mulmod(A, mulmod(z2, z2, P), P), mulmod(uint256(3), mulmod(_p[0], _p[0], P), P), P)
|
||||
const y2 = mulmod(_p[1], _p[1], P)
|
||||
const s = mulmod(uint256(4), mulmod(_p[0], y2, P), P)
|
||||
const z2 = mulmod(_p[2], _p[2], P);
|
||||
const m = addmod(
|
||||
mulmod(A, mulmod(z2, z2, P), P),
|
||||
mulmod(uint256(3), mulmod(_p[0], _p[0], P), P),
|
||||
P,
|
||||
);
|
||||
const y2 = mulmod(_p[1], _p[1], P);
|
||||
const s = mulmod(uint256(4), mulmod(_p[0], y2, P), P);
|
||||
|
||||
const x = addmod(mulmod(m, m, P), negmod(mulmod(s, uint256(2), P), P), P)
|
||||
const x = addmod(mulmod(m, m, P), negmod(mulmod(s, uint256(2), P), P), P);
|
||||
return [
|
||||
x,
|
||||
addmod(mulmod(m, addmod(s, negmod(x, P), P), P), negmod(mulmod(uint256(8), mulmod(y2, y2, P), P), P), P),
|
||||
mulmod(uint256(2), mulmod(_p[1], _p[2], P), P)
|
||||
]
|
||||
addmod(
|
||||
mulmod(m, addmod(s, negmod(x, P), P), P),
|
||||
negmod(mulmod(uint256(8), mulmod(y2, y2, P), P), P),
|
||||
P,
|
||||
),
|
||||
mulmod(uint256(2), mulmod(_p[1], _p[2], P), P),
|
||||
];
|
||||
}
|
||||
|
||||
function negmod(a, P) {
|
||||
return P.sub(a)
|
||||
return P.sub(a);
|
||||
}
|
||||
|
||||
// point addition for elliptic curve in jacobian coordinates
|
||||
// formula from https://en.wikibooks.org/wiki/Cryptography/Prime_Curve/Jacobian_Coordinates
|
||||
function ecadd(_p, _q) {
|
||||
if (_q[0] == 0 && _q[1] == 0 && _q[2] == 0) {
|
||||
return _p
|
||||
return _p;
|
||||
}
|
||||
|
||||
let z2 = mulmod(_q[2], _q[2], P)
|
||||
const u1 = mulmod(_p[0], z2, P)
|
||||
const s1 = mulmod(_p[1], mulmod(z2, _q[2], P), P)
|
||||
z2 = mulmod(_p[2], _p[2], P)
|
||||
let u2 = mulmod(_q[0], z2, P)
|
||||
let s2 = mulmod(_q[1], mulmod(z2, _p[2], P), P)
|
||||
let z2 = mulmod(_q[2], _q[2], P);
|
||||
const u1 = mulmod(_p[0], z2, P);
|
||||
const s1 = mulmod(_p[1], mulmod(z2, _q[2], P), P);
|
||||
z2 = mulmod(_p[2], _p[2], P);
|
||||
let u2 = mulmod(_q[0], z2, P);
|
||||
let s2 = mulmod(_q[1], mulmod(z2, _p[2], P), P);
|
||||
|
||||
if (u1.eq(u2)) {
|
||||
if (!s1.eq(s2)) {
|
||||
//return point at infinity
|
||||
return [_1, _1, _0]
|
||||
}
|
||||
else {
|
||||
return ecdouble(_p)
|
||||
return [_1, _1, _0];
|
||||
} else {
|
||||
return ecdouble(_p);
|
||||
}
|
||||
}
|
||||
|
||||
u2 = addmod(u2, negmod(u1, P), P)
|
||||
z2 = mulmod(u2, u2, P)
|
||||
const t2 = mulmod(u1, z2, P)
|
||||
z2 = mulmod(u2, z2, P)
|
||||
s2 = addmod(s2, negmod(s1, P), P)
|
||||
const x = addmod(addmod(mulmod(s2, s2, P), negmod(z2, P), P), negmod(mulmod(uint256(2), t2, P), P), P)
|
||||
u2 = addmod(u2, negmod(u1, P), P);
|
||||
z2 = mulmod(u2, u2, P);
|
||||
const t2 = mulmod(u1, z2, P);
|
||||
z2 = mulmod(u2, z2, P);
|
||||
s2 = addmod(s2, negmod(s1, P), P);
|
||||
const x = addmod(
|
||||
addmod(mulmod(s2, s2, P), negmod(z2, P), P),
|
||||
negmod(mulmod(uint256(2), t2, P), P),
|
||||
P,
|
||||
);
|
||||
return [
|
||||
x,
|
||||
addmod(mulmod(s2, addmod(t2, negmod(x, P), P), P), negmod(mulmod(s1, z2, P), P), P),
|
||||
mulmod(u2, mulmod(_p[2], _q[2], P), P)
|
||||
]
|
||||
addmod(
|
||||
mulmod(s2, addmod(t2, negmod(x, P), P), P),
|
||||
negmod(mulmod(s1, z2, P), P),
|
||||
P,
|
||||
),
|
||||
mulmod(u2, mulmod(_p[2], _q[2], P), P),
|
||||
];
|
||||
}
|
||||
|
||||
function AtoJ(x, y) {
|
||||
return [
|
||||
uint256(x),
|
||||
uint256(y),
|
||||
_1
|
||||
]
|
||||
return [uint256(x), uint256(y), _1];
|
||||
}
|
||||
|
||||
function isValidPoint(x, y) {
|
||||
const yy = addmod(mulmod(mulmod(x, x, P), x, P), B, P)
|
||||
return yy.eq(mulmod(y, y, P))
|
||||
const yy = addmod(mulmod(mulmod(x, x, P), x, P), B, P);
|
||||
return yy.eq(mulmod(y, y, P));
|
||||
}
|
||||
|
||||
function toHex(bn) {
|
||||
return ('00000000000000000000000000000000000000000000000000000000000000000000000000000000' + bn.toString(16)).slice(-64)
|
||||
return (
|
||||
"00000000000000000000000000000000000000000000000000000000000000000000000000000000" +
|
||||
bn.toString(16)
|
||||
).slice(-64);
|
||||
}
|
||||
|
||||
function decompressKey(x, yBit) {
|
||||
let redP = BN.red('k256');
|
||||
x = x.toRed(redP)
|
||||
const y = x.redMul(x).redMul(x).redAdd(B.toRed(redP)).redSqrt()
|
||||
const sign = y.testn(0)
|
||||
return (sign != yBit ? y.redNeg() : y).fromRed()
|
||||
let redP = BN.red("k256");
|
||||
x = x.toRed(redP);
|
||||
const y = x.redMul(x).redMul(x).redAdd(B.toRed(redP)).redSqrt();
|
||||
const sign = y.testn(0);
|
||||
return (sign != yBit ? y.redNeg() : y).fromRed();
|
||||
}
|
||||
|
||||
function generatePublicKeyFromPrivateKeyData(pk) {
|
||||
const p = mulG(pk)
|
||||
return {x: toHex(p[0]), y: toHex(p[1])}
|
||||
const p = mulG(pk);
|
||||
return { x: toHex(p[0]), y: toHex(p[1]) };
|
||||
}
|
||||
|
||||
function ecrecover(recId, sigr, sigs, message) {
|
||||
assert(recId >= 0 && recId <= 3, "recId must be 0..3")
|
||||
assert(sigr != 0, "sigr must not be 0")
|
||||
assert(sigs != 0, "sigs must not be 0")
|
||||
assert(recId >= 0 && recId <= 3, "recId must be 0..3");
|
||||
assert(sigr != 0, "sigr must not be 0");
|
||||
assert(sigs != 0, "sigs must not be 0");
|
||||
// 1.0 For j from 0 to h (h == recId here and the loop is outside this function)
|
||||
// 1.1 Let x = r + jn
|
||||
const x = addmod(uint256(sigr), P.muln(recId >> 1), P)
|
||||
const x = addmod(uint256(sigr), P.muln(recId >> 1), P);
|
||||
// 1.2. Convert the integer x to an octet string X of length mlen using the conversion routine
|
||||
// specified in Section 2.3.7, where mlen = ⌈(log2 p)/8⌉ or mlen = ⌈m/8⌉.
|
||||
// 1.3. Convert the octet string (16 set binary digits)||X to an elliptic curve point R using the
|
||||
@@ -200,16 +226,16 @@
|
||||
// More concisely, what these points mean is to use X as a compressed public key.
|
||||
if (x.gte(P)) {
|
||||
// Cannot have point co-ordinates larger than this as everything takes place modulo Q.
|
||||
return null
|
||||
return null;
|
||||
}
|
||||
// Compressed keys require you to know an extra bit of data about the y-coord as there are two possibilities.
|
||||
// So it's encoded in the recId.
|
||||
const y = decompressKey(x, (recId & 1) == 1)
|
||||
const y = decompressKey(x, (recId & 1) == 1);
|
||||
// 1.4. If nR != point at infinity, then do another iteration of Step 1 (callers responsibility).
|
||||
// if (!R.mul(N).isInfinity())
|
||||
// return null
|
||||
// 1.5. Compute e from M using Steps 2 and 3 of ECDSA signature verification.
|
||||
const e = uint256(message)
|
||||
const e = uint256(message);
|
||||
// 1.6. For k from 1 to 2 do the following. (loop is outside this function via iterating recId)
|
||||
// 1.6.1. Compute a candidate public key as:
|
||||
// Q = mi(r) * (sR - eG)
|
||||
@@ -221,36 +247,37 @@
|
||||
//
|
||||
// We can find the additive inverse by subtracting e from zero then taking the mod. For example the additive
|
||||
// inverse of 3 modulo 11 is 8 because 3 + 8 mod 11 = 0, and -3 mod 11 = 8.
|
||||
const eNeg = negmod(e, N)
|
||||
const rInv = invmod(sigr, N)
|
||||
const srInv = mulmod(rInv, sigs, N)
|
||||
const eNegrInv = mulmod(rInv, eNeg, N)
|
||||
const R = AtoJ(x, y)
|
||||
const G = AtoJ(GX, GY)
|
||||
const qinJ = ecadd(ecmul(G, eNegrInv), ecmul(R, srInv))
|
||||
const p = JtoA(qinJ)
|
||||
return {x: toHex(p[0]), y: toHex(p[1])}
|
||||
const eNeg = negmod(e, N);
|
||||
const rInv = invmod(sigr, N);
|
||||
const srInv = mulmod(rInv, sigs, N);
|
||||
const eNegrInv = mulmod(rInv, eNeg, N);
|
||||
const R = AtoJ(x, y);
|
||||
const G = AtoJ(GX, GY);
|
||||
const qinJ = ecadd(ecmul(G, eNegrInv), ecmul(R, srInv));
|
||||
const p = JtoA(qinJ);
|
||||
return { x: toHex(p[0]), y: toHex(p[1]) };
|
||||
}
|
||||
|
||||
function ecverify(Qx, Qy, sigr, sigs, z) {
|
||||
if (sigs == 0 || sigr == 0) {
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
const w = invmod(sigs, N)
|
||||
const u1 = mulmod(z, w, N)
|
||||
const u2 = mulmod(sigr, w, N)
|
||||
const Q = AtoJ(Qx, Qy)
|
||||
const G = AtoJ(GX, GY)
|
||||
const RinJ = ecadd(ecmul(G, u1), ecmul(Q, u2))
|
||||
const r = JtoA(RinJ)
|
||||
return sigr.eq(r[0])
|
||||
const w = invmod(sigs, N);
|
||||
const u1 = mulmod(z, w, N);
|
||||
const u2 = mulmod(sigr, w, N);
|
||||
const Q = AtoJ(Qx, Qy);
|
||||
const G = AtoJ(GX, GY);
|
||||
const RinJ = ecadd(ecmul(G, u1), ecmul(Q, u2));
|
||||
const r = JtoA(RinJ);
|
||||
return sigr.eq(r[0]);
|
||||
}
|
||||
|
||||
exports.uint256 = uint256
|
||||
exports.ecsign = ecsign
|
||||
exports.ecrecover = ecrecover
|
||||
exports.generatePublicKeyFromPrivateKeyData = generatePublicKeyFromPrivateKeyData
|
||||
exports.decompressKey = decompressKey
|
||||
exports.isValidPoint = isValidPoint
|
||||
exports.ecverify = ecverify
|
||||
})()
|
||||
exports.uint256 = uint256;
|
||||
exports.ecsign = ecsign;
|
||||
exports.ecrecover = ecrecover;
|
||||
exports.generatePublicKeyFromPrivateKeyData =
|
||||
generatePublicKeyFromPrivateKeyData;
|
||||
exports.decompressKey = decompressKey;
|
||||
exports.isValidPoint = isValidPoint;
|
||||
exports.ecverify = ecverify;
|
||||
})();
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
(function (exports) {
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
// Utils
|
||||
function assert(val, msg) {
|
||||
if (!val) throw new Error(msg || 'Assertion failed');
|
||||
if (!val) throw new Error(msg || "Assertion failed");
|
||||
}
|
||||
|
||||
// Could use `inherits` module, but don't want to move from single file
|
||||
@@ -31,12 +31,12 @@
|
||||
this.red = null;
|
||||
|
||||
if (number !== null) {
|
||||
if (base === 'le' || base === 'be') {
|
||||
if (base === "le" || base === "be") {
|
||||
endian = base;
|
||||
base = 10;
|
||||
}
|
||||
|
||||
this._init(number || 0, base || 10, endian || 'be');
|
||||
this._init(number || 0, base || 10, endian || "be");
|
||||
}
|
||||
}
|
||||
exports.BN = BN;
|
||||
@@ -46,21 +46,24 @@
|
||||
|
||||
var Buffer;
|
||||
try {
|
||||
if (typeof window !== 'undefined' && typeof window.Buffer !== 'undefined') {
|
||||
if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") {
|
||||
Buffer = window.Buffer;
|
||||
} else {
|
||||
Buffer = require('buffer').Buffer;
|
||||
}
|
||||
} catch (e) {
|
||||
Buffer = require("buffer").Buffer;
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
BN.isBN = function isBN(num) {
|
||||
if (num instanceof BN) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return num !== null && typeof num === 'object' &&
|
||||
num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
|
||||
return (
|
||||
num !== null &&
|
||||
typeof num === "object" &&
|
||||
num.constructor.wordSize === BN.wordSize &&
|
||||
Array.isArray(num.words)
|
||||
);
|
||||
};
|
||||
|
||||
BN.max = function max(left, right) {
|
||||
@@ -74,22 +77,22 @@
|
||||
};
|
||||
|
||||
BN.prototype._init = function init(number, base, endian) {
|
||||
if (typeof number === 'number') {
|
||||
if (typeof number === "number") {
|
||||
return this._initNumber(number, base, endian);
|
||||
}
|
||||
|
||||
if (typeof number === 'object') {
|
||||
if (typeof number === "object") {
|
||||
return this._initArray(number, base, endian);
|
||||
}
|
||||
|
||||
if (base === 'hex') {
|
||||
if (base === "hex") {
|
||||
base = 16;
|
||||
}
|
||||
assert(base === (base | 0) && base >= 2 && base <= 36);
|
||||
|
||||
number = number.toString().replace(/\s+/g, '');
|
||||
number = number.toString().replace(/\s+/g, "");
|
||||
var start = 0;
|
||||
if (number[0] === '-') {
|
||||
if (number[0] === "-") {
|
||||
start++;
|
||||
this.negative = 1;
|
||||
}
|
||||
@@ -99,7 +102,7 @@
|
||||
this._parseHex(number, start, endian);
|
||||
} else {
|
||||
this._parseBase(number, base, start);
|
||||
if (endian === 'le') {
|
||||
if (endian === "le") {
|
||||
this._initArray(this.toArray(), base, endian);
|
||||
}
|
||||
}
|
||||
@@ -115,22 +118,15 @@
|
||||
this.words = [number & 0x3ffffff];
|
||||
this.length = 1;
|
||||
} else if (number < 0x10000000000000) {
|
||||
this.words = [
|
||||
number & 0x3ffffff,
|
||||
(number / 0x4000000) & 0x3ffffff
|
||||
];
|
||||
this.words = [number & 0x3ffffff, (number / 0x4000000) & 0x3ffffff];
|
||||
this.length = 2;
|
||||
} else {
|
||||
assert(number < 0x20000000000000); // 2 ^ 53 (unsafe)
|
||||
this.words = [
|
||||
number & 0x3ffffff,
|
||||
(number / 0x4000000) & 0x3ffffff,
|
||||
1
|
||||
];
|
||||
this.words = [number & 0x3ffffff, (number / 0x4000000) & 0x3ffffff, 1];
|
||||
this.length = 3;
|
||||
}
|
||||
|
||||
if (endian !== 'le') return;
|
||||
if (endian !== "le") return;
|
||||
|
||||
// Reverse the bytes
|
||||
this._initArray(this.toArray(), base, endian);
|
||||
@@ -138,7 +134,7 @@
|
||||
|
||||
BN.prototype._initArray = function _initArray(number, base, endian) {
|
||||
// Perhaps a Uint8Array
|
||||
assert(typeof number.length === 'number');
|
||||
assert(typeof number.length === "number");
|
||||
if (number.length <= 0) {
|
||||
this.words = [0];
|
||||
this.length = 1;
|
||||
@@ -153,7 +149,7 @@
|
||||
|
||||
var j, w;
|
||||
var off = 0;
|
||||
if (endian === 'be') {
|
||||
if (endian === "be") {
|
||||
for (i = number.length - 1, j = 0; i >= 0; i -= 3) {
|
||||
w = number[i] | (number[i - 1] << 8) | (number[i - 2] << 16);
|
||||
this.words[j] |= (w << off) & 0x3ffffff;
|
||||
@@ -164,7 +160,7 @@
|
||||
j++;
|
||||
}
|
||||
}
|
||||
} else if (endian === 'le') {
|
||||
} else if (endian === "le") {
|
||||
for (i = 0, j = 0; i < number.length; i += 3) {
|
||||
w = number[i] | (number[i + 1] << 8) | (number[i + 2] << 16);
|
||||
this.words[j] |= (w << off) & 0x3ffffff;
|
||||
@@ -191,7 +187,7 @@
|
||||
} else if (c >= 97 && c <= 102) {
|
||||
return c - 87;
|
||||
} else {
|
||||
assert(false, 'Invalid character in ' + string);
|
||||
assert(false, "Invalid character in " + string);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,7 +212,7 @@
|
||||
var j = 0;
|
||||
|
||||
var w;
|
||||
if (endian === 'be') {
|
||||
if (endian === "be") {
|
||||
for (i = number.length - 1; i >= start; i -= 2) {
|
||||
w = parseHexByte(number, start, i) << off;
|
||||
this.words[j] |= w & 0x3ffffff;
|
||||
@@ -230,7 +226,11 @@
|
||||
}
|
||||
} else {
|
||||
var parseLength = number.length - start;
|
||||
for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) {
|
||||
for (
|
||||
i = parseLength % 2 === 0 ? start + 1 : start;
|
||||
i < number.length;
|
||||
i += 2
|
||||
) {
|
||||
w = parseHexByte(number, start, i) << off;
|
||||
this.words[j] |= w & 0x3ffffff;
|
||||
if (off >= 18) {
|
||||
@@ -267,7 +267,7 @@
|
||||
} else {
|
||||
b = c;
|
||||
}
|
||||
assert(c >= 0 && b < mul, 'Invalid character');
|
||||
assert(c >= 0 && b < mul, "Invalid character");
|
||||
r += b;
|
||||
}
|
||||
return r;
|
||||
@@ -372,9 +372,9 @@
|
||||
|
||||
// Check Symbol.for because not everywhere where Symbol defined
|
||||
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol#Browser_compatibility
|
||||
if (typeof Symbol !== 'undefined' && typeof Symbol.for === 'function') {
|
||||
if (typeof Symbol !== "undefined" && typeof Symbol.for === "function") {
|
||||
try {
|
||||
BN.prototype[Symbol.for('nodejs.util.inspect.custom')] = inspect;
|
||||
BN.prototype[Symbol.for("nodejs.util.inspect.custom")] = inspect;
|
||||
} catch (e) {
|
||||
BN.prototype.inspect = inspect;
|
||||
}
|
||||
@@ -383,7 +383,7 @@
|
||||
}
|
||||
|
||||
function inspect() {
|
||||
return (this.red ? '<BN-R: ' : '<BN: ') + this.toString(16) + '>';
|
||||
return (this.red ? "<BN-R: " : "<BN: ") + this.toString(16) + ">";
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -417,50 +417,45 @@
|
||||
*/
|
||||
|
||||
var zeros = [
|
||||
'',
|
||||
'0',
|
||||
'00',
|
||||
'000',
|
||||
'0000',
|
||||
'00000',
|
||||
'000000',
|
||||
'0000000',
|
||||
'00000000',
|
||||
'000000000',
|
||||
'0000000000',
|
||||
'00000000000',
|
||||
'000000000000',
|
||||
'0000000000000',
|
||||
'00000000000000',
|
||||
'000000000000000',
|
||||
'0000000000000000',
|
||||
'00000000000000000',
|
||||
'000000000000000000',
|
||||
'0000000000000000000',
|
||||
'00000000000000000000',
|
||||
'000000000000000000000',
|
||||
'0000000000000000000000',
|
||||
'00000000000000000000000',
|
||||
'000000000000000000000000',
|
||||
'0000000000000000000000000'
|
||||
"",
|
||||
"0",
|
||||
"00",
|
||||
"000",
|
||||
"0000",
|
||||
"00000",
|
||||
"000000",
|
||||
"0000000",
|
||||
"00000000",
|
||||
"000000000",
|
||||
"0000000000",
|
||||
"00000000000",
|
||||
"000000000000",
|
||||
"0000000000000",
|
||||
"00000000000000",
|
||||
"000000000000000",
|
||||
"0000000000000000",
|
||||
"00000000000000000",
|
||||
"000000000000000000",
|
||||
"0000000000000000000",
|
||||
"00000000000000000000",
|
||||
"000000000000000000000",
|
||||
"0000000000000000000000",
|
||||
"00000000000000000000000",
|
||||
"000000000000000000000000",
|
||||
"0000000000000000000000000",
|
||||
];
|
||||
|
||||
var groupSizes = [
|
||||
0, 0,
|
||||
25, 16, 12, 11, 10, 9, 8,
|
||||
8, 7, 7, 7, 7, 6, 6,
|
||||
6, 6, 6, 6, 6, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5
|
||||
0, 0, 25, 16, 12, 11, 10, 9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
];
|
||||
|
||||
var groupBases = [
|
||||
0, 0,
|
||||
33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216,
|
||||
0, 0, 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216,
|
||||
43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625,
|
||||
16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632,
|
||||
6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149,
|
||||
24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176
|
||||
16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, 6436343,
|
||||
7962624, 9765625, 11881376, 14348907, 17210368, 20511149, 24300000,
|
||||
28629151, 33554432, 39135393, 45435424, 52521875, 60466176,
|
||||
];
|
||||
|
||||
BN.prototype.toString = function toString(base, padding) {
|
||||
@@ -468,8 +463,8 @@
|
||||
padding = padding | 0 || 1;
|
||||
|
||||
var out;
|
||||
if (base === 16 || base === 'hex') {
|
||||
out = '';
|
||||
if (base === 16 || base === "hex") {
|
||||
out = "";
|
||||
var off = 0;
|
||||
var carry = 0;
|
||||
for (var i = 0; i < this.length; i++) {
|
||||
@@ -491,10 +486,10 @@
|
||||
out = carry.toString(16) + out;
|
||||
}
|
||||
while (out.length % padding !== 0) {
|
||||
out = '0' + out;
|
||||
out = "0" + out;
|
||||
}
|
||||
if (this.negative !== 0) {
|
||||
out = '-' + out;
|
||||
out = "-" + out;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -504,7 +499,7 @@
|
||||
var groupSize = groupSizes[base];
|
||||
// var groupBase = Math.pow(base, groupSize);
|
||||
var groupBase = groupBases[base];
|
||||
out = '';
|
||||
out = "";
|
||||
var c = this.clone();
|
||||
c.negative = 0;
|
||||
while (!c.isZero()) {
|
||||
@@ -518,18 +513,18 @@
|
||||
}
|
||||
}
|
||||
if (this.isZero()) {
|
||||
out = '0' + out;
|
||||
out = "0" + out;
|
||||
}
|
||||
while (out.length % padding !== 0) {
|
||||
out = '0' + out;
|
||||
out = "0" + out;
|
||||
}
|
||||
if (this.negative !== 0) {
|
||||
out = '-' + out;
|
||||
out = "-" + out;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
assert(false, 'Base should be between 2 and 36');
|
||||
assert(false, "Base should be between 2 and 36");
|
||||
};
|
||||
|
||||
BN.prototype.toNumber = function toNumber() {
|
||||
@@ -538,11 +533,11 @@
|
||||
ret += this.words[1] * 0x4000000;
|
||||
} else if (this.length === 3 && this.words[2] === 0x01) {
|
||||
// NOTE: at this stage it is known that the top bit is set
|
||||
ret += 0x10000000000000 + (this.words[1] * 0x4000000);
|
||||
ret += 0x10000000000000 + this.words[1] * 0x4000000;
|
||||
} else if (this.length > 2) {
|
||||
assert(false, 'Number can only safely store up to 53 bits');
|
||||
assert(false, "Number can only safely store up to 53 bits");
|
||||
}
|
||||
return (this.negative !== 0) ? -ret : ret;
|
||||
return this.negative !== 0 ? -ret : ret;
|
||||
};
|
||||
|
||||
BN.prototype.toJSON = function toJSON() {
|
||||
@@ -571,12 +566,12 @@
|
||||
|
||||
var byteLength = this.byteLength();
|
||||
var reqLength = length || Math.max(1, byteLength);
|
||||
assert(byteLength <= reqLength, 'byte array longer than desired length');
|
||||
assert(reqLength > 0, 'Requested array length <= 0');
|
||||
assert(byteLength <= reqLength, "byte array longer than desired length");
|
||||
assert(reqLength > 0, "Requested array length <= 0");
|
||||
|
||||
var res = allocate(ArrayType, reqLength);
|
||||
var postfix = endian === 'le' ? 'LE' : 'BE';
|
||||
this['_toArrayLike' + postfix](res, byteLength);
|
||||
var postfix = endian === "le" ? "LE" : "BE";
|
||||
this["_toArrayLike" + postfix](res, byteLength);
|
||||
return res;
|
||||
};
|
||||
|
||||
@@ -886,7 +881,7 @@
|
||||
|
||||
// Not ``this`` with ``width`` bitwidth
|
||||
BN.prototype.inotn = function inotn(width) {
|
||||
assert(typeof width === 'number' && width >= 0);
|
||||
assert(typeof width === "number" && width >= 0);
|
||||
|
||||
var bytesNeeded = Math.ceil(width / 26) | 0;
|
||||
var bitsLeft = width % 26;
|
||||
@@ -918,7 +913,7 @@
|
||||
|
||||
// Set `bit` of `this`
|
||||
BN.prototype.setn = function setn(bit, val) {
|
||||
assert(typeof bit === 'number' && bit >= 0);
|
||||
assert(typeof bit === "number" && bit >= 0);
|
||||
|
||||
var off = (bit / 26) | 0;
|
||||
var wbit = bit % 26;
|
||||
@@ -1812,8 +1807,8 @@
|
||||
for (var s = 1; s < N; s <<= 1) {
|
||||
var l = s << 1;
|
||||
|
||||
var rtwdf = Math.cos(2 * Math.PI / l);
|
||||
var itwdf = Math.sin(2 * Math.PI / l);
|
||||
var rtwdf = Math.cos((2 * Math.PI) / l);
|
||||
var itwdf = Math.sin((2 * Math.PI) / l);
|
||||
|
||||
for (var p = 0; p < N; p += l) {
|
||||
var rtwdf_ = rtwdf;
|
||||
@@ -1853,11 +1848,11 @@
|
||||
var N = Math.max(m, n) | 1;
|
||||
var odd = N & 1;
|
||||
var i = 0;
|
||||
for (N = N / 2 | 0; N; N = N >>> 1) {
|
||||
for (N = (N / 2) | 0; N; N = N >>> 1) {
|
||||
i++;
|
||||
}
|
||||
|
||||
return 1 << i + 1 + odd;
|
||||
return 1 << (i + 1 + odd);
|
||||
};
|
||||
|
||||
FFTM.prototype.conjugate = function conjugate(rws, iws, N) {
|
||||
@@ -1879,7 +1874,8 @@
|
||||
FFTM.prototype.normalize13b = function normalize13b(ws, N) {
|
||||
var carry = 0;
|
||||
for (var i = 0; i < N / 2; i++) {
|
||||
var w = Math.round(ws[2 * i + 1] / N) * 0x2000 +
|
||||
var w =
|
||||
Math.round(ws[2 * i + 1] / N) * 0x2000 +
|
||||
Math.round(ws[2 * i] / N) +
|
||||
carry;
|
||||
|
||||
@@ -1888,7 +1884,7 @@
|
||||
if (w < 0x4000000) {
|
||||
carry = 0;
|
||||
} else {
|
||||
carry = w / 0x4000000 | 0;
|
||||
carry = (w / 0x4000000) | 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1900,8 +1896,10 @@
|
||||
for (var i = 0; i < len; i++) {
|
||||
carry = carry + (ws[i] | 0);
|
||||
|
||||
rws[2 * i] = carry & 0x1fff; carry = carry >>> 13;
|
||||
rws[2 * i + 1] = carry & 0x1fff; carry = carry >>> 13;
|
||||
rws[2 * i] = carry & 0x1fff;
|
||||
carry = carry >>> 13;
|
||||
rws[2 * i + 1] = carry & 0x1fff;
|
||||
carry = carry >>> 13;
|
||||
}
|
||||
|
||||
// Pad with zeroes
|
||||
@@ -1985,7 +1983,7 @@
|
||||
var isNegNum = num < 0;
|
||||
if (isNegNum) num = -num;
|
||||
|
||||
assert(typeof num === 'number');
|
||||
assert(typeof num === "number");
|
||||
assert(num < 0x4000000);
|
||||
|
||||
// Carry
|
||||
@@ -2046,7 +2044,7 @@
|
||||
|
||||
// Shift-left in-place
|
||||
BN.prototype.iushln = function iushln(bits) {
|
||||
assert(typeof bits === 'number' && bits >= 0);
|
||||
assert(typeof bits === "number" && bits >= 0);
|
||||
var r = bits % 26;
|
||||
var s = (bits - r) / 26;
|
||||
var carryMask = (0x3ffffff >>> (26 - r)) << (26 - r);
|
||||
@@ -2093,7 +2091,7 @@
|
||||
// NOTE: `hint` is a lowest bit before trailing zeroes
|
||||
// NOTE: if `extended` is present - it will be filled with destroyed bits
|
||||
BN.prototype.iushrn = function iushrn(bits, hint, extended) {
|
||||
assert(typeof bits === 'number' && bits >= 0);
|
||||
assert(typeof bits === "number" && bits >= 0);
|
||||
var h;
|
||||
if (hint) {
|
||||
h = (hint - (hint % 26)) / 26;
|
||||
@@ -2175,7 +2173,7 @@
|
||||
|
||||
// Test if n bit is set
|
||||
BN.prototype.testn = function testn(bit) {
|
||||
assert(typeof bit === 'number' && bit >= 0);
|
||||
assert(typeof bit === "number" && bit >= 0);
|
||||
var r = bit % 26;
|
||||
var s = (bit - r) / 26;
|
||||
var q = 1 << r;
|
||||
@@ -2191,11 +2189,11 @@
|
||||
|
||||
// Return only lowers bits of number (in-place)
|
||||
BN.prototype.imaskn = function imaskn(bits) {
|
||||
assert(typeof bits === 'number' && bits >= 0);
|
||||
assert(typeof bits === "number" && bits >= 0);
|
||||
var r = bits % 26;
|
||||
var s = (bits - r) / 26;
|
||||
|
||||
assert(this.negative === 0, 'imaskn works only with positive numbers');
|
||||
assert(this.negative === 0, "imaskn works only with positive numbers");
|
||||
|
||||
if (this.length <= s) {
|
||||
return this;
|
||||
@@ -2221,7 +2219,7 @@
|
||||
|
||||
// Add plain number `num` to `this`
|
||||
BN.prototype.iaddn = function iaddn(num) {
|
||||
assert(typeof num === 'number');
|
||||
assert(typeof num === "number");
|
||||
assert(num < 0x4000000);
|
||||
if (num < 0) return this.isubn(-num);
|
||||
|
||||
@@ -2262,7 +2260,7 @@
|
||||
|
||||
// Subtract plain number `num` from `this`
|
||||
BN.prototype.isubn = function isubn(num) {
|
||||
assert(typeof num === 'number');
|
||||
assert(typeof num === "number");
|
||||
assert(num < 0x4000000);
|
||||
if (num < 0) return this.iaddn(-num);
|
||||
|
||||
@@ -2363,7 +2361,7 @@
|
||||
var m = a.length - b.length;
|
||||
var q;
|
||||
|
||||
if (mode !== 'mod') {
|
||||
if (mode !== "mod") {
|
||||
q = new BN(null);
|
||||
q.length = m + 1;
|
||||
q.words = new Array(q.length);
|
||||
@@ -2381,7 +2379,8 @@
|
||||
}
|
||||
|
||||
for (var j = m - 1; j >= 0; j--) {
|
||||
var qj = (a.words[b.length + j] | 0) * 0x4000000 +
|
||||
var qj =
|
||||
(a.words[b.length + j] | 0) * 0x4000000 +
|
||||
(a.words[b.length + j - 1] | 0);
|
||||
|
||||
// NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max
|
||||
@@ -2407,13 +2406,13 @@
|
||||
a._strip();
|
||||
|
||||
// Denormalize
|
||||
if (mode !== 'div' && shift !== 0) {
|
||||
if (mode !== "div" && shift !== 0) {
|
||||
a.iushrn(shift);
|
||||
}
|
||||
|
||||
return {
|
||||
div: q || null,
|
||||
mod: a
|
||||
mod: a,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -2427,7 +2426,7 @@
|
||||
if (this.isZero()) {
|
||||
return {
|
||||
div: new BN(0),
|
||||
mod: new BN(0)
|
||||
mod: new BN(0),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2435,11 +2434,11 @@
|
||||
if (this.negative !== 0 && num.negative === 0) {
|
||||
res = this.neg().divmod(num, mode);
|
||||
|
||||
if (mode !== 'mod') {
|
||||
if (mode !== "mod") {
|
||||
div = res.div.neg();
|
||||
}
|
||||
|
||||
if (mode !== 'div') {
|
||||
if (mode !== "div") {
|
||||
mod = res.mod.neg();
|
||||
if (positive && mod.negative !== 0) {
|
||||
mod.iadd(num);
|
||||
@@ -2448,27 +2447,27 @@
|
||||
|
||||
return {
|
||||
div: div,
|
||||
mod: mod
|
||||
mod: mod,
|
||||
};
|
||||
}
|
||||
|
||||
if (this.negative === 0 && num.negative !== 0) {
|
||||
res = this.divmod(num.neg(), mode);
|
||||
|
||||
if (mode !== 'mod') {
|
||||
if (mode !== "mod") {
|
||||
div = res.div.neg();
|
||||
}
|
||||
|
||||
return {
|
||||
div: div,
|
||||
mod: res.mod
|
||||
mod: res.mod,
|
||||
};
|
||||
}
|
||||
|
||||
if ((this.negative & num.negative) !== 0) {
|
||||
res = this.neg().divmod(num.neg(), mode);
|
||||
|
||||
if (mode !== 'div') {
|
||||
if (mode !== "div") {
|
||||
mod = res.mod.neg();
|
||||
if (positive && mod.negative !== 0) {
|
||||
mod.isub(num);
|
||||
@@ -2477,7 +2476,7 @@
|
||||
|
||||
return {
|
||||
div: res.div,
|
||||
mod: mod
|
||||
mod: mod,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2487,29 +2486,29 @@
|
||||
if (num.length > this.length || this.cmp(num) < 0) {
|
||||
return {
|
||||
div: new BN(0),
|
||||
mod: this
|
||||
mod: this,
|
||||
};
|
||||
}
|
||||
|
||||
// Very short reduction
|
||||
if (num.length === 1) {
|
||||
if (mode === 'div') {
|
||||
if (mode === "div") {
|
||||
return {
|
||||
div: this.divn(num.words[0]),
|
||||
mod: null
|
||||
mod: null,
|
||||
};
|
||||
}
|
||||
|
||||
if (mode === 'mod') {
|
||||
if (mode === "mod") {
|
||||
return {
|
||||
div: null,
|
||||
mod: new BN(this.modrn(num.words[0]))
|
||||
mod: new BN(this.modrn(num.words[0])),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
div: this.divn(num.words[0]),
|
||||
mod: new BN(this.modrn(num.words[0]))
|
||||
mod: new BN(this.modrn(num.words[0])),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2518,16 +2517,16 @@
|
||||
|
||||
// Find `this` / `num`
|
||||
BN.prototype.div = function div(num) {
|
||||
return this.divmod(num, 'div', false).div;
|
||||
return this.divmod(num, "div", false).div;
|
||||
};
|
||||
|
||||
// Find `this` % `num`
|
||||
BN.prototype.mod = function mod(num) {
|
||||
return this.divmod(num, 'mod', false).mod;
|
||||
return this.divmod(num, "mod", false).mod;
|
||||
};
|
||||
|
||||
BN.prototype.umod = function umod(num) {
|
||||
return this.divmod(num, 'mod', true).mod;
|
||||
return this.divmod(num, "mod", true).mod;
|
||||
};
|
||||
|
||||
// Find Round(`this` / `num`)
|
||||
@@ -2667,7 +2666,7 @@
|
||||
return {
|
||||
a: C,
|
||||
b: D,
|
||||
gcd: y.iushln(g)
|
||||
gcd: y.iushln(g),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -2799,7 +2798,7 @@
|
||||
|
||||
// Increment at the bit position in-line
|
||||
BN.prototype.bincn = function bincn(bit) {
|
||||
assert(typeof bit === 'number');
|
||||
assert(typeof bit === "number");
|
||||
var r = bit % 26;
|
||||
var s = (bit - r) / 26;
|
||||
var q = 1 << r;
|
||||
@@ -2847,7 +2846,7 @@
|
||||
num = -num;
|
||||
}
|
||||
|
||||
assert(num <= 0x3ffffff, 'Number is too big');
|
||||
assert(num <= 0x3ffffff, "Number is too big");
|
||||
|
||||
var w = this.words[0] | 0;
|
||||
res = w === num ? 0 : w < num ? -1 : 1;
|
||||
@@ -2940,13 +2939,13 @@
|
||||
};
|
||||
|
||||
BN.prototype.toRed = function toRed(ctx) {
|
||||
assert(!this.red, 'Already a number in reduction context');
|
||||
assert(this.negative === 0, 'red works only with positives');
|
||||
assert(!this.red, "Already a number in reduction context");
|
||||
assert(this.negative === 0, "red works only with positives");
|
||||
return ctx.convertTo(this)._forceRed(ctx);
|
||||
};
|
||||
|
||||
BN.prototype.fromRed = function fromRed() {
|
||||
assert(this.red, 'fromRed works only with numbers in reduction context');
|
||||
assert(this.red, "fromRed works only with numbers in reduction context");
|
||||
return this.red.convertFrom(this);
|
||||
};
|
||||
|
||||
@@ -2956,81 +2955,81 @@
|
||||
};
|
||||
|
||||
BN.prototype.forceRed = function forceRed(ctx) {
|
||||
assert(!this.red, 'Already a number in reduction context');
|
||||
assert(!this.red, "Already a number in reduction context");
|
||||
return this._forceRed(ctx);
|
||||
};
|
||||
|
||||
BN.prototype.redAdd = function redAdd(num) {
|
||||
assert(this.red, 'redAdd works only with red numbers');
|
||||
assert(this.red, "redAdd works only with red numbers");
|
||||
return this.red.add(this, num);
|
||||
};
|
||||
|
||||
BN.prototype.redIAdd = function redIAdd(num) {
|
||||
assert(this.red, 'redIAdd works only with red numbers');
|
||||
assert(this.red, "redIAdd works only with red numbers");
|
||||
return this.red.iadd(this, num);
|
||||
};
|
||||
|
||||
BN.prototype.redSub = function redSub(num) {
|
||||
assert(this.red, 'redSub works only with red numbers');
|
||||
assert(this.red, "redSub works only with red numbers");
|
||||
return this.red.sub(this, num);
|
||||
};
|
||||
|
||||
BN.prototype.redISub = function redISub(num) {
|
||||
assert(this.red, 'redISub works only with red numbers');
|
||||
assert(this.red, "redISub works only with red numbers");
|
||||
return this.red.isub(this, num);
|
||||
};
|
||||
|
||||
BN.prototype.redShl = function redShl(num) {
|
||||
assert(this.red, 'redShl works only with red numbers');
|
||||
assert(this.red, "redShl works only with red numbers");
|
||||
return this.red.shl(this, num);
|
||||
};
|
||||
|
||||
BN.prototype.redMul = function redMul(num) {
|
||||
assert(this.red, 'redMul works only with red numbers');
|
||||
assert(this.red, "redMul works only with red numbers");
|
||||
this.red._verify2(this, num);
|
||||
return this.red.mul(this, num);
|
||||
};
|
||||
|
||||
BN.prototype.redIMul = function redIMul(num) {
|
||||
assert(this.red, 'redMul works only with red numbers');
|
||||
assert(this.red, "redMul works only with red numbers");
|
||||
this.red._verify2(this, num);
|
||||
return this.red.imul(this, num);
|
||||
};
|
||||
|
||||
BN.prototype.redSqr = function redSqr() {
|
||||
assert(this.red, 'redSqr works only with red numbers');
|
||||
assert(this.red, "redSqr works only with red numbers");
|
||||
this.red._verify1(this);
|
||||
return this.red.sqr(this);
|
||||
};
|
||||
|
||||
BN.prototype.redISqr = function redISqr() {
|
||||
assert(this.red, 'redISqr works only with red numbers');
|
||||
assert(this.red, "redISqr works only with red numbers");
|
||||
this.red._verify1(this);
|
||||
return this.red.isqr(this);
|
||||
};
|
||||
|
||||
// Square root over p
|
||||
BN.prototype.redSqrt = function redSqrt() {
|
||||
assert(this.red, 'redSqrt works only with red numbers');
|
||||
assert(this.red, "redSqrt works only with red numbers");
|
||||
this.red._verify1(this);
|
||||
return this.red.sqrt(this);
|
||||
};
|
||||
|
||||
BN.prototype.redInvm = function redInvm() {
|
||||
assert(this.red, 'redInvm works only with red numbers');
|
||||
assert(this.red, "redInvm works only with red numbers");
|
||||
this.red._verify1(this);
|
||||
return this.red.invm(this);
|
||||
};
|
||||
|
||||
// Return negative clone of `this` % `red modulo`
|
||||
BN.prototype.redNeg = function redNeg() {
|
||||
assert(this.red, 'redNeg works only with red numbers');
|
||||
assert(this.red, "redNeg works only with red numbers");
|
||||
this.red._verify1(this);
|
||||
return this.red.neg(this);
|
||||
};
|
||||
|
||||
BN.prototype.redPow = function redPow(num) {
|
||||
assert(this.red && !num.red, 'redPow(normalNum)');
|
||||
assert(this.red && !num.red, "redPow(normalNum)");
|
||||
this.red._verify1(this);
|
||||
return this.red.pow(this, num);
|
||||
};
|
||||
@@ -3040,7 +3039,7 @@
|
||||
k256: null,
|
||||
p224: null,
|
||||
p192: null,
|
||||
p25519: null
|
||||
p25519: null,
|
||||
};
|
||||
|
||||
// Pseudo-Mersenne prime
|
||||
@@ -3103,8 +3102,9 @@
|
||||
function K256() {
|
||||
MPrime.call(
|
||||
this,
|
||||
'k256',
|
||||
'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f');
|
||||
"k256",
|
||||
"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f",
|
||||
);
|
||||
}
|
||||
inherits(K256, MPrime);
|
||||
|
||||
@@ -3170,16 +3170,18 @@
|
||||
function P224() {
|
||||
MPrime.call(
|
||||
this,
|
||||
'p224',
|
||||
'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001');
|
||||
"p224",
|
||||
"ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001",
|
||||
);
|
||||
}
|
||||
inherits(P224, MPrime);
|
||||
|
||||
function P192() {
|
||||
MPrime.call(
|
||||
this,
|
||||
'p192',
|
||||
'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff');
|
||||
"p192",
|
||||
"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff",
|
||||
);
|
||||
}
|
||||
inherits(P192, MPrime);
|
||||
|
||||
@@ -3187,8 +3189,9 @@
|
||||
// 2 ^ 255 - 19
|
||||
MPrime.call(
|
||||
this,
|
||||
'25519',
|
||||
'7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed');
|
||||
"25519",
|
||||
"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",
|
||||
);
|
||||
}
|
||||
inherits(P25519, MPrime);
|
||||
|
||||
@@ -3215,16 +3218,16 @@
|
||||
if (primes[name]) return primes[name];
|
||||
|
||||
var prime;
|
||||
if (name === 'k256') {
|
||||
if (name === "k256") {
|
||||
prime = new K256();
|
||||
} else if (name === 'p224') {
|
||||
} else if (name === "p224") {
|
||||
prime = new P224();
|
||||
} else if (name === 'p192') {
|
||||
} else if (name === "p192") {
|
||||
prime = new P192();
|
||||
} else if (name === 'p25519') {
|
||||
} else if (name === "p25519") {
|
||||
prime = new P25519();
|
||||
} else {
|
||||
throw new Error('Unknown prime ' + name);
|
||||
throw new Error("Unknown prime " + name);
|
||||
}
|
||||
primes[name] = prime;
|
||||
|
||||
@@ -3235,26 +3238,25 @@
|
||||
// Base reduction engine
|
||||
//
|
||||
function Red(m) {
|
||||
if (typeof m === 'string') {
|
||||
if (typeof m === "string") {
|
||||
var prime = BN._prime(m);
|
||||
this.m = prime.p;
|
||||
this.prime = prime;
|
||||
} else {
|
||||
assert(m.gtn(1), 'modulus must be greater than 1');
|
||||
assert(m.gtn(1), "modulus must be greater than 1");
|
||||
this.m = m;
|
||||
this.prime = null;
|
||||
}
|
||||
}
|
||||
|
||||
Red.prototype._verify1 = function _verify1(a) {
|
||||
assert(a.negative === 0, 'red works only with positives');
|
||||
assert(a.red, 'red works only with red numbers');
|
||||
assert(a.negative === 0, "red works only with positives");
|
||||
assert(a.red, "red works only with red numbers");
|
||||
};
|
||||
|
||||
Red.prototype._verify2 = function _verify2(a, b) {
|
||||
assert((a.negative | b.negative) === 0, 'red works only with positives');
|
||||
assert(a.red && a.red === b.red,
|
||||
'red works only with red numbers');
|
||||
assert((a.negative | b.negative) === 0, "red works only with positives");
|
||||
assert(a.red && a.red === b.red, "red works only with red numbers");
|
||||
};
|
||||
|
||||
Red.prototype.imod = function imod(a) {
|
||||
|
||||
@@ -11,13 +11,9 @@ module.exports = defineConfig({
|
||||
iconPaths: {
|
||||
faviconSVG: "img/icons/safari-pinned-tab.svg",
|
||||
},
|
||||
workboxPluginMode: "InjectManifest",
|
||||
workboxOptions: {
|
||||
importScripts: [
|
||||
"additional-scripts.js",
|
||||
"safari-notifications.js",
|
||||
"nacl.js",
|
||||
"sw-bn.js",
|
||||
],
|
||||
swSrc: "./sw_scripts/additional-scripts.js",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user