Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f9b5b9f55f | ||
|
|
25d9e21b38 | ||
|
|
77641fc43d | ||
|
|
90865fe9c1 | ||
|
|
15fbfc3c51 | ||
|
|
340b6a0cd6 | ||
|
|
064e13268a | ||
|
|
641ea0f9d8 | ||
|
|
98bc7147e3 | ||
|
|
3d9e5d49b8 | ||
|
|
8bdcfbb049 | ||
|
|
13dcd606ea | ||
|
|
6576688f92 | ||
|
|
33e63df4ad | ||
|
|
e910e9fc77 | ||
|
|
a00b36d50d | ||
|
|
0f6e143a6f | ||
|
|
854d209be8 | ||
|
|
3f50efb951 | ||
|
|
aceaa90466 | ||
|
|
63622edcf4 |
+4
-1
@@ -1,4 +1,7 @@
|
|||||||
4
|
4
|
||||||
|
|
||||||
3.2.2
|
3.2.2
|
||||||
3.2.3
|
3.2.3
|
||||||
|
3.2.4
|
||||||
|
|
||||||
|
4.0.2
|
||||||
File diff suppressed because one or more lines are too long
+1
-1
@@ -10,4 +10,4 @@ plugins:
|
|||||||
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
|
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
|
||||||
spec: "@yarnpkg/plugin-version"
|
spec: "@yarnpkg/plugin-version"
|
||||||
|
|
||||||
yarnPath: .yarn/releases/yarn-2.4.0.cjs
|
yarnPath: .yarn/releases/yarn-2.4.1.cjs
|
||||||
|
|||||||
@@ -1,5 +1,28 @@
|
|||||||
# CHANGELOG
|
# CHANGELOG
|
||||||
|
|
||||||
|
## 4.0.2 Mar 5, 2021
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Add import indirection for both CJS & ESM (where generated source file is commonjs)
|
||||||
|
|
||||||
|
|
||||||
|
## 4.0.1 Mar 4, 2021
|
||||||
|
|
||||||
|
**Important** In the 4.0 version the default package type has been changed to ESM modules by default. This should not affect usage, however since the output formats changed, a new major version is required.
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Build to ESM by default (with cjs versions via export map)
|
||||||
|
|
||||||
|
|
||||||
|
## 3.2.4 Feb 24, 2021
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
|
||||||
|
- Cleanup implicit dependencies, perform base64 decoding using base64-js
|
||||||
|
|
||||||
|
|
||||||
## 3.2.3 Feb 16, 2021
|
## 3.2.3 Feb 16, 2021
|
||||||
|
|
||||||
Changes:
|
Changes:
|
||||||
|
|||||||
@@ -15,5 +15,5 @@ module.exports = Object.assign({}, config, {
|
|||||||
'<rootDir>/packages/wasm-crypto-wasm/build',
|
'<rootDir>/packages/wasm-crypto-wasm/build',
|
||||||
'<rootDir>/packages/wasm-crypto/build'
|
'<rootDir>/packages/wasm-crypto/build'
|
||||||
],
|
],
|
||||||
resolver: '@polkadot/dev/config/jest-resolver.cjs'
|
transformIgnorePatterns: ['/node_modules/(?!@polkadot|@babel/runtime/helpers/esm/)']
|
||||||
});
|
});
|
||||||
+6
-6
@@ -7,7 +7,7 @@
|
|||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
"typescript": "^4.1.5"
|
"typescript": "^4.2.2"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "yarn build:wasm",
|
"build": "yarn build:wasm",
|
||||||
@@ -19,14 +19,14 @@
|
|||||||
"test": "yarn test:wasm:rust",
|
"test": "yarn test:wasm:rust",
|
||||||
"test:wasm:js": "yarn test:wasm:js:jest && yarn test:wasm:js:node",
|
"test:wasm:js": "yarn test:wasm:js:jest && yarn test:wasm:js:node",
|
||||||
"test:wasm:js:jest": "polkadot-dev-run-test ./test/jest.spec.js",
|
"test:wasm:js:jest": "polkadot-dev-run-test ./test/jest.spec.js",
|
||||||
"test:wasm:js:node": "cd packages/wasm-crypto && node ./test/wasm.js && node ./test/asm.js",
|
"test:wasm:js:node": "cd packages/wasm-crypto && node ./test/wasm.cjs && node ./test/asm.cjs",
|
||||||
"test:wasm:rust": "cd packages/wasm-crypto && RUST_BACKTRACE=full cargo test --release -- --nocapture"
|
"test:wasm:rust": "cd packages/wasm-crypto && RUST_BACKTRACE=full cargo test --release -- --nocapture"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.12.16",
|
"@babel/core": "^7.13.8",
|
||||||
"@polkadot/dev": "^0.61.26",
|
"@polkadot/dev": "^0.62.5",
|
||||||
"fflate": "^0.6.3",
|
"fflate": "^0.6.7",
|
||||||
"override-require": "^1.1.1"
|
"override-require": "^1.1.1"
|
||||||
},
|
},
|
||||||
"version": "3.2.3"
|
"version": "4.0.2"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/wasm-crypto-asmjs",
|
"name": "@polkadot/wasm-crypto-asmjs",
|
||||||
"version": "3.2.3",
|
"version": "4.0.2",
|
||||||
|
"type": "module",
|
||||||
"description": "Asm.js content for wasm-crypto",
|
"description": "Asm.js content for wasm-crypto",
|
||||||
"browser": "empty.js",
|
"browser": "empty.js",
|
||||||
"main": "empty.js",
|
"main": "empty.js",
|
||||||
@@ -13,6 +14,6 @@
|
|||||||
"bugs": "https://github.com/polkadot-js/wasm/issues",
|
"bugs": "https://github.com/polkadot-js/wasm/issues",
|
||||||
"homepage": "https://github.com/polkadot-js/wasm",
|
"homepage": "https://github.com/polkadot-js/wasm",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.12.13"
|
"@babel/runtime": "^7.13.9"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export declare const asmJsInit: null;
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const asmJsInit = null;
|
||||||
|
|
||||||
|
exports.asmJsInit = asmJsInit;
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"type": "commonjs"
|
||||||
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
// Copyright 2019-2021 @polkadot/wasm-crypto-asmjs authors & contributors
|
// Copyright 2019-2021 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
export const asmJsInit = null;
|
import { asmJsInit as _asmJsInit } from './cjs/data.js';
|
||||||
|
|
||||||
|
export const asmJsInit = _asmJsInit;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Copyright 2017-2021 @polkadot/dev authors & contributors
|
// Copyright 2017-2021 @polkadot/wasm-crypto-asmjs authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
// Auto-generated by @polkadot/dev, do not edit
|
// Auto-generated by @polkadot/dev, do not edit
|
||||||
|
|
||||||
export const packageInfo = { name: '@polkadot/wasm-crypto-asmjs', version: '3.2.3' };
|
export const packageInfo = { name: '@polkadot/wasm-crypto-asmjs', version: '4.0.2' };
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/wasm-crypto-wasm",
|
"name": "@polkadot/wasm-crypto-wasm",
|
||||||
"version": "3.2.3",
|
"version": "4.0.2",
|
||||||
|
"type": "module",
|
||||||
"description": "Wasm content for wasm-crypto",
|
"description": "Wasm content for wasm-crypto",
|
||||||
"browser": "data.js",
|
"browser": "data.js",
|
||||||
"main": "data.js",
|
"main": "data.js",
|
||||||
@@ -13,6 +14,6 @@
|
|||||||
"bugs": "https://github.com/polkadot-js/wasm/issues",
|
"bugs": "https://github.com/polkadot-js/wasm/issues",
|
||||||
"homepage": "https://github.com/polkadot-js/wasm",
|
"homepage": "https://github.com/polkadot-js/wasm",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.12.13"
|
"@babel/runtime": "^7.13.9"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 Jameson Little
|
||||||
|
//
|
||||||
|
// https://github.com/beatgammit/base64-js/blob/88957c9943c7e2a0f03cdf73e71d579e433627d3/index.js
|
||||||
|
// This only contains the toByteArray function (no encoding)
|
||||||
|
//
|
||||||
|
// Only tweaks make here are some TS adjustments (we use strict null checks), the code is otherwise as-is with
|
||||||
|
// only the single required function provided
|
||||||
|
|
||||||
|
const CODE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
||||||
|
|
||||||
|
const lookup: string[] = [];
|
||||||
|
const revLookup: number[] = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < CODE.length; ++i) {
|
||||||
|
lookup[i] = CODE[i];
|
||||||
|
revLookup[CODE.charCodeAt(i)] = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Support decoding URL-safe base64 strings, as Node.js does.
|
||||||
|
// See: https://en.wikipedia.org/wiki/Base64#URL_applications
|
||||||
|
revLookup['-'.charCodeAt(0)] = 62;
|
||||||
|
revLookup['_'.charCodeAt(0)] = 63;
|
||||||
|
|
||||||
|
function getLens (b64: string): [number, number] {
|
||||||
|
const len = b64.length;
|
||||||
|
|
||||||
|
if (len % 4 > 0) {
|
||||||
|
throw new Error('Invalid string. Length must be a multiple of 4');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trim off extra bytes after placeholder bytes are found
|
||||||
|
// See: https://github.com/beatgammit/base64-js/issues/42
|
||||||
|
const validLen = b64.indexOf('=');
|
||||||
|
|
||||||
|
return validLen === -1
|
||||||
|
? [len, 0]
|
||||||
|
: [validLen, 4 - (validLen % 4)];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function toByteArray (b64: string): Uint8Array {
|
||||||
|
const [validLen, placeHoldersLen] = getLens(b64);
|
||||||
|
const arr = new Uint8Array(((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen);
|
||||||
|
let curByte = 0;
|
||||||
|
let i;
|
||||||
|
let tmp;
|
||||||
|
|
||||||
|
// if there are placeholders, only get up to the last complete 4 chars
|
||||||
|
const len = placeHoldersLen > 0
|
||||||
|
? validLen - 4
|
||||||
|
: validLen;
|
||||||
|
|
||||||
|
for (i = 0; i < len; i += 4) {
|
||||||
|
tmp =
|
||||||
|
(revLookup[b64.charCodeAt(i)] << 18) |
|
||||||
|
(revLookup[b64.charCodeAt(i + 1)] << 12) |
|
||||||
|
(revLookup[b64.charCodeAt(i + 2)] << 6) |
|
||||||
|
revLookup[b64.charCodeAt(i + 3)];
|
||||||
|
|
||||||
|
arr[curByte++] = (tmp >> 16) & 0xFF;
|
||||||
|
arr[curByte++] = (tmp >> 8) & 0xFF;
|
||||||
|
arr[curByte++] = tmp & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (placeHoldersLen === 2) {
|
||||||
|
tmp =
|
||||||
|
(revLookup[b64.charCodeAt(i)] << 2) |
|
||||||
|
(revLookup[b64.charCodeAt(i + 1)] >> 4);
|
||||||
|
|
||||||
|
arr[curByte++] = tmp & 0xFF;
|
||||||
|
} else if (placeHoldersLen === 1) {
|
||||||
|
tmp =
|
||||||
|
(revLookup[b64.charCodeAt(i)] << 10) |
|
||||||
|
(revLookup[b64.charCodeAt(i + 1)] << 4) |
|
||||||
|
(revLookup[b64.charCodeAt(i + 2)] >> 2);
|
||||||
|
|
||||||
|
arr[curByte++] = (tmp >> 8) & 0xFF;
|
||||||
|
arr[curByte++] = tmp & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import { bytes as _bytes, sizeCompressed as _sizeCompressed, sizeUncompressed as _sizeUncompressed } from './cjs/bytes';
|
||||||
|
|
||||||
|
export const bytes = _bytes;
|
||||||
|
|
||||||
|
export const sizeCompressed = _sizeCompressed;
|
||||||
|
|
||||||
|
export const sizeUncompressed = _sizeUncompressed;
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
export declare const bytes = '';
|
||||||
|
export declare const sizeCompressed = 0;
|
||||||
|
export declare const sizeUncompressed = 0;
|
||||||
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
|
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
export const buffer = Buffer.from([]);
|
exports.bytes = '';
|
||||||
|
|
||||||
export const sizeCompressed = 0;
|
exports.sizeCompressed = 0;
|
||||||
|
|
||||||
export const sizeUncompressed = 0;
|
exports.sizeUncompressed = 0;
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"type": "commonjs"
|
||||||
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
|
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
import { buffer, sizeUncompressed } from './buffer';
|
import { toByteArray } from './base64';
|
||||||
|
import { bytes, sizeUncompressed } from './bytes';
|
||||||
import { unzlibSync } from './fflate';
|
import { unzlibSync } from './fflate';
|
||||||
|
|
||||||
export const wasmBytes = unzlibSync(buffer, new Uint8Array(sizeUncompressed));
|
export const wasmBytes = unzlibSync(toByteArray(bytes), new Uint8Array(sizeUncompressed));
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
|
// Copyright 2019-2021 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
export const wasmBytes = null;
|
export const bytes = null;
|
||||||
|
|
||||||
|
export const sizeCompressed = 0;
|
||||||
|
|
||||||
|
export const sizeUncompressed = 0;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Copyright 2017-2021 @polkadot/dev authors & contributors
|
// Copyright 2017-2021 @polkadot/wasm-crypto-wasm authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
// Auto-generated by @polkadot/dev, do not edit
|
// Auto-generated by @polkadot/dev, do not edit
|
||||||
|
|
||||||
export const packageInfo = { name: '@polkadot/wasm-crypto-wasm', version: '3.2.3' };
|
export const packageInfo = { name: '@polkadot/wasm-crypto-wasm', version: '4.0.2' };
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/wasm-crypto",
|
"name": "@polkadot/wasm-crypto",
|
||||||
"version": "3.2.3",
|
"version": "4.0.2",
|
||||||
|
"type": "module",
|
||||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"sideEffects": [
|
"sideEffects": [
|
||||||
"./detectPackage.js",
|
"./detectPackage.js",
|
||||||
"./detectPackage.mjs"
|
"./detectPackage.cjs"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.12.13",
|
"@babel/runtime": "^7.13.9",
|
||||||
"@polkadot/wasm-crypto-asmjs": "^3.2.3",
|
"@polkadot/wasm-crypto-asmjs": "^4.0.2",
|
||||||
"@polkadot/wasm-crypto-wasm": "^3.2.3"
|
"@polkadot/wasm-crypto-wasm": "^4.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@polkadot/util": "^5.6.2",
|
"@polkadot/util": "^6.0.1-6",
|
||||||
"@polkadot/x-randomvalues": "^5.6.2"
|
"@polkadot/x-randomvalues": "^6.0.1-6"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@polkadot/util": "*",
|
"@polkadot/util": "*",
|
||||||
|
|||||||
@@ -1,25 +1,10 @@
|
|||||||
// Copyright 2017-2021 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2017-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
// For esm, this should be import.meta.url or to get the same behavior as __dirname, we can use
|
|
||||||
//
|
|
||||||
// new URL(import.meta.url).pathname)
|
|
||||||
//
|
|
||||||
// The issue is the WP4 has "some" issues with import.meta.url. So because of bundlers, we can't have
|
|
||||||
// nice things... In this case it is even worse since import.meta.url won't even make it compile, so
|
|
||||||
// there is a complete dead end with usage thereof
|
|
||||||
//
|
|
||||||
// When that is fixed, a solution is to have both .js & .mjs files, with the following content -
|
|
||||||
//
|
|
||||||
// cjs: util.detectPackage(packageInfo, () => __dirname);
|
|
||||||
// esm: detectPackage(packageInfo, () => import.meta.url);
|
|
||||||
//
|
|
||||||
// With the above we additionally need a .d.ts to just export the packageInfo
|
|
||||||
|
|
||||||
import { detectPackage } from '@polkadot/util';
|
import { detectPackage } from '@polkadot/util';
|
||||||
|
import { packageInfo as asmInfo } from '@polkadot/wasm-crypto-asmjs/packageInfo';
|
||||||
|
import { packageInfo as wasmInfo } from '@polkadot/wasm-crypto-wasm/packageInfo';
|
||||||
|
|
||||||
import { packageInfo } from './packageInfo';
|
import { packageInfo } from './packageInfo';
|
||||||
|
|
||||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname);
|
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, [asmInfo, wasmInfo]);
|
||||||
|
|
||||||
export { packageInfo };
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import { wasmBytes } from '@polkadot/wasm-crypto-wasm';
|
|||||||
import { allocString, allocU8a, getWasm, initWasm, resultString, resultU8a, withWasm } from './bridge';
|
import { allocString, allocU8a, getWasm, initWasm, resultString, resultU8a, withWasm } from './bridge';
|
||||||
import * as imports from './imports';
|
import * as imports from './imports';
|
||||||
|
|
||||||
|
export { packageInfo } from './packageInfo';
|
||||||
|
|
||||||
const wasmPromise = initWasm(wasmBytes, asmJsInit, imports).catch(() => null);
|
const wasmPromise = initWasm(wasmBytes, asmJsInit, imports).catch(() => null);
|
||||||
|
|
||||||
export const bip39Generate = withWasm((wasm) =>
|
export const bip39Generate = withWasm((wasm) =>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Copyright 2017-2021 @polkadot/dev authors & contributors
|
// Copyright 2017-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
// Auto-generated by @polkadot/dev, do not edit
|
// Auto-generated by @polkadot/dev, do not edit
|
||||||
|
|
||||||
export const packageInfo = { name: '@polkadot/wasm-crypto', version: '3.2.3' };
|
export const packageInfo = { name: '@polkadot/wasm-crypto', version: '4.0.2' };
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const rootIncl = ['@polkadot/wasm-crypto-asmjs', '@polkadot/wasm-crypto-wasm'];
|
||||||
|
const detcIncl = rootIncl.map((p) => `${p}/packageInfo`);
|
||||||
|
|
||||||
|
require('override-require')(
|
||||||
|
(request) =>
|
||||||
|
rootIncl.some((p) => request.endsWith(p)) ||
|
||||||
|
detcIncl.some((p) => request.endsWith(p)),
|
||||||
|
(request) =>
|
||||||
|
rootIncl.some((p) => request.endsWith(p))
|
||||||
|
? require(`${rootIncl.find((p) => request.endsWith(p))}/build/data.cjs`)
|
||||||
|
: require(`${detcIncl.find((p) => request.endsWith(p)).replace('packageInfo', 'build/packageInfo.cjs')}`)
|
||||||
|
);
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
require('override-require')(
|
|
||||||
(request) =>
|
|
||||||
request.endsWith('@polkadot/wasm-crypto-asmjs') ||
|
|
||||||
request.endsWith('@polkadot/wasm-crypto-wasm'),
|
|
||||||
(request) =>
|
|
||||||
request.endsWith('@polkadot/wasm-crypto-asmjs')
|
|
||||||
? require('../../wasm-crypto-asmjs/build/data')
|
|
||||||
: require('../../wasm-crypto-wasm/build/empty')
|
|
||||||
);
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
const wasm = require('../../build/index');
|
const wasm = require('../../build/index.cjs');
|
||||||
const bip39 = require('./bip39');
|
const bip39 = require('./bip39.cjs');
|
||||||
const ed25519 = require('./ed25519');
|
const ed25519 = require('./ed25519.cjs');
|
||||||
const hashing = require('./hashing');
|
const hashing = require('./hashing.cjs');
|
||||||
const sr25519 = require('./sr25519');
|
const sr25519 = require('./sr25519.cjs');
|
||||||
const vrf = require('./vrf');
|
const vrf = require('./vrf.cjs');
|
||||||
|
|
||||||
const tests = {
|
const tests = {
|
||||||
...bip39,
|
...bip39,
|
||||||
@@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
global.WebAssembly = null;
|
global.WebAssembly = null;
|
||||||
|
|
||||||
require('./alias-imports');
|
require('./alias-imports.cjs');
|
||||||
|
|
||||||
const { runUnassisted } = require('./all');
|
const { runUnassisted } = require('./all/index.cjs');
|
||||||
|
|
||||||
runUnassisted();
|
runUnassisted();
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
// override-require in jest.config.js
|
// override-require in jest.config.js
|
||||||
|
|
||||||
const { beforeAll, tests, wasm } = require('./all');
|
import { beforeAll, tests, wasm } from './all/index.cjs';
|
||||||
|
|
||||||
describe('wasm-crypto', () => {
|
describe('wasm-crypto', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
// Copyright 2019-2021 @polkadot/wasm-crypto authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
require('./alias-imports');
|
require('./alias-imports.cjs');
|
||||||
|
|
||||||
const { runUnassisted } = require('./all');
|
const { runUnassisted } = require('./all/index.cjs');
|
||||||
|
|
||||||
runUnassisted();
|
runUnassisted();
|
||||||
@@ -10,7 +10,7 @@ RUST_VER=nightly-2020-10-25
|
|||||||
|
|
||||||
WSM=bytes/wasm_bg.wasm
|
WSM=bytes/wasm_bg.wasm
|
||||||
OPT=bytes/wasm_opt.wasm
|
OPT=bytes/wasm_opt.wasm
|
||||||
ASM=wasm-crypto-asmjs/build/data.js
|
ASM=wasm-crypto-asmjs/build/cjs/data.js
|
||||||
|
|
||||||
# build new via wasm-pack
|
# build new via wasm-pack
|
||||||
echo "*** Building Rust sources"
|
echo "*** Building Rust sources"
|
||||||
@@ -30,7 +30,7 @@ echo "*** Optimising WASM output"
|
|||||||
|
|
||||||
# convert wasm to base64 structure
|
# convert wasm to base64 structure
|
||||||
echo "*** Packing WASM into baseX"
|
echo "*** Packing WASM into baseX"
|
||||||
node ../scripts/pack-wasm-base.js
|
node ../scripts/pack-wasm-base.cjs
|
||||||
|
|
||||||
# build asmjs version from the input (optimised) WASM
|
# build asmjs version from the input (optimised) WASM
|
||||||
echo "*** Building asm.js version"
|
echo "*** Building asm.js version"
|
||||||
@@ -44,5 +44,5 @@ sed -i -e 's/var retasmFunc = /const asmJsInit = (wbg) => /' $ASM
|
|||||||
echo "module.exports = { asmJsInit };" >> $ASM
|
echo "module.exports = { asmJsInit };" >> $ASM
|
||||||
|
|
||||||
# cleanups
|
# cleanups
|
||||||
rm -rf wasm-crypto-asmjs/build/*-e
|
rm -rf wasm-crypto-asmjs/build/cjs/*-e
|
||||||
rm -rf wasm-crypto-wasm/build/*-e
|
rm -rf wasm-crypto-wasm/build/cjs/*-e
|
||||||
|
|||||||
@@ -26,11 +26,6 @@ unamestr=`uname`
|
|||||||
rustup toolchain install $RUST_VER -c rust-src -t wasm32-unknown-unknown
|
rustup toolchain install $RUST_VER -c rust-src -t wasm32-unknown-unknown
|
||||||
cargo install xargo
|
cargo install xargo
|
||||||
|
|
||||||
# if ! [ -x "$(command -v wasm-pack)" ]; then
|
|
||||||
# echo "*** Installing wasm-pack"
|
|
||||||
# curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
|
||||||
# fi
|
|
||||||
|
|
||||||
if [[ "$unamestr" == 'Linux' ]]; then
|
if [[ "$unamestr" == 'Linux' ]]; then
|
||||||
echo "*** Detected Linux"
|
echo "*** Detected Linux"
|
||||||
BINARYEN_ZIP=binaryen-$BINARYEN_VER-x86_64-linux
|
BINARYEN_ZIP=binaryen-$BINARYEN_VER-x86_64-linux
|
||||||
@@ -59,9 +54,3 @@ if [ ! -d "bindgen" ]; then
|
|||||||
mv $BINDGEN_ZIP bindgen
|
mv $BINDGEN_ZIP bindgen
|
||||||
ls -alR bindgen
|
ls -alR bindgen
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# if [ ! -d "wabt" ]; then
|
|
||||||
# echo "*** Downloading wabt"
|
|
||||||
# curl -L $WABT_REPO/releases/download/$WABT_VER/$WABT_ZIP.tar.gz | tar xz
|
|
||||||
# mv wabt-$WABT_VER wabt
|
|
||||||
# fi
|
|
||||||
|
|||||||
Executable
+44
@@ -0,0 +1,44 @@
|
|||||||
|
// Copyright 2019-2021 @polkadot/wasm authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
const fflate = require('fflate/node');
|
||||||
|
const fs = require('fs');
|
||||||
|
const { formatNumber } = require('@polkadot/util');
|
||||||
|
|
||||||
|
// const A_NAME = 'wasm-crypto-asmjs';
|
||||||
|
const W_NAME = 'wasm-crypto-wasm';
|
||||||
|
|
||||||
|
function hdr (package) {
|
||||||
|
return `// Copyright 2019-2021 @polkadot/${package} authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
// Generated as part of the build, do not edit
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getWasmBuffer () {
|
||||||
|
const data = fs.readFileSync('./bytes/wasm_opt.wasm');
|
||||||
|
const compressed = Buffer.from(fflate.zlibSync(data, { level: 9 }));
|
||||||
|
|
||||||
|
console.log(`*** Compressed WASM: ${formatNumber(data.length)} -> ${formatNumber(compressed.length)} (${(100 * compressed.length / data.length).toFixed(2)}%)`);
|
||||||
|
|
||||||
|
return { compressed, sizeUncompressed: data.length };
|
||||||
|
}
|
||||||
|
|
||||||
|
// fs.writeFileSync(`./${A_NAME}/build/data.js`, `${hdr(A_NAME)}
|
||||||
|
// export { asmJsInit } from './data.cjs';
|
||||||
|
// `);
|
||||||
|
|
||||||
|
// fs.writeFileSync(`./${W_NAME}/build/bytes.js`, `${hdr(W_NAME)}
|
||||||
|
// export { bytes, sizeCompressed, sizeUncompressed } from './bytes.cjs';
|
||||||
|
// `);
|
||||||
|
|
||||||
|
const { compressed, sizeUncompressed } = getWasmBuffer();
|
||||||
|
|
||||||
|
fs.writeFileSync(`./${W_NAME}/build/cjs/bytes.js`, `${hdr(W_NAME)}
|
||||||
|
const sizeCompressed = ${compressed.length};
|
||||||
|
const sizeUncompressed = ${sizeUncompressed};
|
||||||
|
const bytes = '${compressed.toString('base64')}';
|
||||||
|
|
||||||
|
module.exports = { bytes, sizeCompressed, sizeUncompressed };
|
||||||
|
`);
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
// Copyright 2019-2021 @polkadot/wasm authors & contributors
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
const fs = require('fs');
|
|
||||||
const { formatNumber } = require('@polkadot/util');
|
|
||||||
|
|
||||||
const A_NAME = 'wasm-crypto-asmjs';
|
|
||||||
const W_NAME = 'wasm-crypto-wasm';
|
|
||||||
|
|
||||||
function hdr (package) {
|
|
||||||
return `// Copyright 2019-2021 @polkadot/${package} authors & contributors
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
// Generated as part of the build, do not edit
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// only one of the deps are included, here are the details for package.json -
|
|
||||||
// "fflate": "^0.4.2"
|
|
||||||
// "lz4js": "^0.2.0"
|
|
||||||
function getWasmBuffer (lib = 'fflate') {
|
|
||||||
const data = fs.readFileSync('./bytes/wasm_opt.wasm');
|
|
||||||
const compressed = lib === 'fflate'
|
|
||||||
? Buffer.from(require('fflate/node').zlibSync(data, { level: 9 }))
|
|
||||||
: Buffer.from(require('lz4js').compress(data));
|
|
||||||
|
|
||||||
console.log(`*** Compressed WASM via ${lib}: ${formatNumber(data.length)} -> ${formatNumber(compressed.length)} (${(100 * compressed.length / data.length).toFixed(2)}%)`);
|
|
||||||
|
|
||||||
return { compressed, sizeUncompressed: data.length };
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.writeFileSync(`./${A_NAME}/build/data.mjs`, `${hdr(A_NAME)}
|
|
||||||
export { asmJsInit } from './data.js';
|
|
||||||
`);
|
|
||||||
|
|
||||||
fs.writeFileSync(`./${W_NAME}/build/buffer.mjs`, `${hdr(W_NAME)}
|
|
||||||
export { buffer, sizeCompressed, sizeUncompressed } from './buffer.js';
|
|
||||||
`);
|
|
||||||
|
|
||||||
const { compressed, sizeUncompressed } = getWasmBuffer();
|
|
||||||
|
|
||||||
fs.writeFileSync(`./${W_NAME}/build/buffer.js`, `${hdr(W_NAME)}
|
|
||||||
const sizeCompressed = ${compressed.length};
|
|
||||||
const sizeUncompressed = ${sizeUncompressed};
|
|
||||||
const buffer = Buffer.from('${compressed.toString('base64')}', 'base64');
|
|
||||||
|
|
||||||
module.exports = { buffer, sizeCompressed, sizeUncompressed };
|
|
||||||
`);
|
|
||||||
@@ -7,7 +7,9 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
|
"@polkadot/wasm-crypto-asmjs/packageInfo": [ "packages/wasm-crypto-asmjs/src/packageInfo" ],
|
||||||
"@polkadot/wasm-crypto-asmjs": [ "packages/wasm-crypto-asmjs/src/data" ],
|
"@polkadot/wasm-crypto-asmjs": [ "packages/wasm-crypto-asmjs/src/data" ],
|
||||||
|
"@polkadot/wasm-crypto-wasm/packageInfo": [ "packages/wasm-crypto-wasm/src/packageInfo" ],
|
||||||
"@polkadot/wasm-crypto-wasm": [ "packages/wasm-crypto-wasm/src/data" ],
|
"@polkadot/wasm-crypto-wasm": [ "packages/wasm-crypto-wasm/src/data" ],
|
||||||
"@polkadot/wasm-crypto": [ "packages/wasm-crypto/src" ]
|
"@polkadot/wasm-crypto": [ "packages/wasm-crypto/src" ]
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user