Compare commits

...
41 Commits
Author SHA1 Message Date
github-actions[bot] 5b3158cb15 [CI Skip] release/stable 6.1.4
skip-checks: true
2022-06-22 05:59:18 +00:00
Jaco baa3439646 6.1.4 (#373) 2022-06-22 08:54:08 +03:00
github-actions[bot] ac040bd62b [CI Skip] release/beta 6.1.4-0
skip-checks: true
2022-06-21 17:39:22 +00:00
Jaco e0a9e33623 Adjust cjs -> deno path rewrites (#372) 2022-06-21 20:33:07 +03:00
github-actions[bot] b29f959dda [CI Skip] release/stable 6.1.3
skip-checks: true
2022-06-21 16:09:09 +00:00
Jaco 7a5ec9d347 6.1.3 (#371) 2022-06-21 19:03:53 +03:00
github-actions[bot] 28ddad0549 [CI Skip] release/stable 6.1.2
skip-checks: true
2022-06-21 15:42:22 +00:00
Jaco 615746a323 6.1.2 (#370) 2022-06-21 18:36:19 +03:00
Jaco e49d5a3219 6.1.2 (#369) 2022-06-21 18:22:51 +03:00
github-actions[bot] a31f7cac0d [CI Skip] release/beta 6.1.2-15
skip-checks: true
2022-06-21 13:41:20 +00:00
Jaco 9b65fe6c86 CHANGELOG & additional comments (#368) 2022-06-21 16:35:45 +03:00
github-actions[bot] 3b5dcd41d9 [CI Skip] release/beta 6.1.2-14
skip-checks: true
2022-06-21 12:49:22 +00:00
Jaco f4db1385fc Bump dev (w/ stable deno publish) (#367) 2022-06-21 15:43:49 +03:00
github-actions[bot] 1b844254fe [CI Skip] release/beta 6.1.2-13
skip-checks: true
2022-06-21 05:26:46 +00:00
Jaco bf924e5da0 Adjust WebAssembly init (#365)
* Adjust WebAssembly init

* Adjust

* Re-add length check
2022-06-21 08:21:29 +03:00
github-actions[bot] da37be391e [CI Skip] release/beta 6.1.2-12
skip-checks: true
2022-06-21 04:54:13 +00:00
Jaco 2a44054387 Bump TS to 4.7.4 (#364) 2022-06-21 07:47:51 +03:00
github-actions[bot] 4c85c4d336 [CI Skip] release/beta 6.1.2-11
skip-checks: true
2022-06-18 10:33:32 +00:00
Jaco 03030ae93f Adjust assert inside withWasm (#363) 2022-06-18 13:26:50 +03:00
github-actions[bot] ed438e8877 [CI Skip] release/beta 6.1.2-10
skip-checks: true
2022-06-13 19:27:43 +00:00
Jaco e7700787b2 Bump dev (#362) 2022-06-13 22:22:41 +03:00
github-actions[bot] 6cccb7b9b0 [CI Skip] release/beta 6.1.2-9
skip-checks: true
2022-06-13 05:23:33 +00:00
Jaco f8678ed024 Bump dev deps (#361) 2022-06-13 08:18:37 +03:00
github-actions[bot] 9b48e3dd36 [CI Skip] release/beta 6.1.2-8
skip-checks: true
2022-06-12 08:20:04 +00:00
Jaco f5db698705 Update issue template (#360) 2022-06-12 11:15:01 +03:00
github-actions[bot] 2a24642220 [CI Skip] release/beta 6.1.2-7
skip-checks: true
2022-06-11 07:20:21 +00:00
Jaco 5cd8ea6926 Sprinkle in comments on the actual code (#359) 2022-06-11 10:15:03 +03:00
github-actions[bot] 633b33430a [CI Skip] release/beta 6.1.2-6
skip-checks: true
2022-06-11 05:27:28 +00:00
Jaco 341e57eeb5 Bump deps (w/ issue template) (#358)
* Bump deps (w/ issue template)

* Adjust

* Adjust
2022-06-11 08:22:18 +03:00
github-actions[bot] 2a9b79f086 [CI Skip] release/beta 6.1.2-5
skip-checks: true
2022-06-04 05:22:54 +00:00
Jaco fc5a7bf9ce Bump @polkadot/util (#357) 2022-06-04 08:17:13 +03:00
github-actions[bot] fbb57dc9ca [CI Skip] release/beta 6.1.2-4
skip-checks: true
2022-06-04 04:51:04 +00:00
Jaco 2358984605 Bump deps (#356) 2022-06-04 07:45:46 +03:00
github-actions[bot] 28ae0b8963 [CI Skip] release/beta 6.1.2-3
skip-checks: true
2022-05-30 07:32:00 +00:00
Jaco 4e316440b9 Bump TS (#355) 2022-05-30 10:26:43 +03:00
github-actions[bot] f9c65c8fb2 [CI Skip] release/beta 6.1.2-2
skip-checks: true
2022-05-29 08:57:09 +00:00
Jaco d3c5d1a617 Adjust eslint ignore (#354)
* Adjust eslint ignore

* Update .eslintrc.js
2022-05-29 11:50:17 +03:00
github-actions[bot] b57cdaef14 [CI Skip] release/beta 6.1.2-1
skip-checks: true
2022-05-29 08:37:22 +00:00
Jaco 1f2ad4ea36 Bump deps (#353) 2022-05-29 11:32:02 +03:00
github-actions[bot] 4c3537d869 [CI Skip] release/beta 6.1.2-0
skip-checks: true
2022-05-13 19:38:44 +00:00
Jaco 6f1ff9f276 Bump base common (#351) 2022-05-13 22:32:01 +03:00
50 changed files with 1512 additions and 1104 deletions
+4
View File
@@ -6,3 +6,7 @@
4.0.2
4.1.2
6.1.2
6.1.3
6.1.4
+1 -1
View File
@@ -8,7 +8,7 @@ module.exports = {
ignorePatterns: [
...base.ignorePatterns,
'**/target/*',
'packages/bytes/*'
'**/build-wasm/*'
],
parserOptions: {
...base.parserOptions,
+50
View File
@@ -0,0 +1,50 @@
<!--
For general support, howto, coding and bundling questions, please use the Substrate & Polkadot StackExchange at https://substrate.stackexchange.com/ and get other ecosystem developers involved. This issues in this repository are meant for the tracking of feature requests and bug reports.
While all issues are looked at non-bug and non-features would take quite a bit longer to get to and may yield less than satisfactory responses in this format.
Additionally, please ensure you have done a search on the existing and closed issues before logging a new request. This saves time on all sides.
-->
* **I'm submitting a ...**
<!--- Try and classify your actual report -->
- [ ] Bug report
- [ ] Feature request
- [ ] Support request (please bear the comments above in mind)
- [ ] Other
* **What is the current behavior and expected behavior?**
<!--- If you're describing a bug, tell us what should happen -->
<!--- If you're suggesting a change/improvement, tell us how it should work -->
* **What is the motivation for changing the behavior?**
<!--- Not obligatory, but suggest a motivation for the request -->
<!--- or ideas how to implement the addition or change -->
* **Please tell us about your environment:**
<!--- Include as many relevant details about the environment you experienced the issue in -->
<!--- Also snsure that you have tested against the latest stable releases if a bug -->
- Version:
- Environment:
- [ ] Node.js
- [ ] Browser
- [ ] Other (limited support for other environments available)
- Language:
- [ ] JavaScript
- [ ] TypeScript
- [ ] Other
+1
View File
@@ -3,6 +3,7 @@ bindgen/
build/
build-cjs/
build-esm/
build-deno/
build-docs/
build-wasm/
bytes/
+22
View File
@@ -1,5 +1,27 @@
# CHANGELOG
## 6.1.4 Jun 22, 2022
Changes:
- Adjust build outputs for Deno targets
## 6.1.3 Jun 21, 2022
Changes:
- Fix bundle publish (from dev bump)
## 6.1.2 Jun 21, 2022
Changes:
- Adjust assert usage in all internal non-test code
- Additional comments where missing
## 6.1.1 May 13, 2022
Changes:
+1 -1
View File
@@ -1,4 +1,4 @@
417 Jaco 6.1.1 (#350)
438 Jaco 6.1.4 (#373)
1 Evgeny Fixed type (#121)
1 Shunfan Zhou Support sr25519 agreement (#209)
1 Steve Degosserie Expose Schnorrkel's VRF capabilities (#170)
+4 -4
View File
@@ -10,7 +10,7 @@
"url": "https://github.com/polkadot-js/wasm.git"
},
"sideEffects": false,
"version": "6.1.1",
"version": "6.1.4",
"workspaces": [
"packages/*"
],
@@ -31,12 +31,12 @@
"test:wasm-crypto:rust": "cd packages/wasm-crypto && RUST_BACKTRACE=full cargo test --release -- --test-threads=1 --nocapture"
},
"devDependencies": {
"@babel/core": "^7.17.10",
"@polkadot/dev": "^0.66.21",
"@babel/core": "^7.18.5",
"@polkadot/dev": "^0.67.23",
"fflate": "^0.7.3",
"override-require": "^1.1.1"
},
"resolutions": {
"typescript": "^4.6.4"
"typescript": "^4.7.4"
}
}
+4 -4
View File
@@ -20,14 +20,14 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "6.1.1",
"version": "6.1.4",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.17.9"
"@babel/runtime": "^7.18.3"
},
"devDependencies": {
"@polkadot/util": "^9.1.1",
"@polkadot/x-randomvalues": "^9.1.1"
"@polkadot/util": "^9.5.1",
"@polkadot/x-randomvalues": "^9.5.1"
},
"peerDependencies": {
"@polkadot/util": "*",
+66
View File
@@ -1,6 +1,10 @@
// Copyright 2019-2022 @polkadot/wasm-bridge authors & contributors
// SPDX-License-Identifier: Apache-2.0
// A number of functions are "unsafe" and purposefully so - it is
// assumed that where the bridge is used, it is correctly wrapped
// in a safeguard (see withWasm in the wasm-crypto package) which
// then ensures that the internal wasm instance here is available
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import type { BridgeBase, InitFn, InitPromise, WasmBaseInstance } from './types';
@@ -9,6 +13,15 @@ import { stringToU8a, u8aToString } from '@polkadot/util';
import { Wbg } from './wbg';
/**
* @name Bridge
* @description
* Creates a bridge between the JS and WASM environments.
*
* For any bridge it is passed an function white is then called internally at the
* time of initialization. This affectively implements the layer between WASM and
* the native environment, providing all the plumbing needed for the Wbg classes.
*/
export class Bridge<C extends WasmBaseInstance> implements BridgeBase<C> {
#cachegetInt32: Int32Array | null;
#cachegetUint8: Uint8Array | null;
@@ -36,22 +49,27 @@ export class Bridge<C extends WasmBaseInstance> implements BridgeBase<C> {
this.#wbg = { ...new Wbg(this) };
}
/** @description Returns the init error */
get error (): string | null {
return this.#wasmError;
}
/** @description Returns the init type */
get type (): 'asm' | 'wasm' | 'none' {
return this.#type;
}
/** @description Returns the created wbg interface */
get wbg (): WebAssembly.ModuleImports {
return this.#wbg;
}
/** @description Returns the created wasm interface */
get wasm (): C | null {
return this.#wasm;
}
/** @description Performs the wasm initialization */
async init (createWasm?: InitFn<C>): Promise<C | null> {
if (!this.#wasmPromise || createWasm) {
this.#wasmPromise = (createWasm || this.#createWasm)(this.#wbg);
@@ -66,10 +84,18 @@ export class Bridge<C extends WasmBaseInstance> implements BridgeBase<C> {
return this.#wasm;
}
/**
* @internal
* @description Gets an object from the heap
*/
getObject (idx: number): unknown {
return this.#heap[idx];
}
/**
* @internal
* @description Removes an object from the heap
*/
dropObject (idx: number) {
if (idx < 36) {
return;
@@ -79,6 +105,10 @@ export class Bridge<C extends WasmBaseInstance> implements BridgeBase<C> {
this.#heapNext = idx;
}
/**
* @internal
* @description Retrieves and removes an object to the heap
*/
takeObject (idx: number): unknown {
const ret = this.getObject(idx);
@@ -87,6 +117,10 @@ export class Bridge<C extends WasmBaseInstance> implements BridgeBase<C> {
return ret;
}
/**
* @internal
* @description Adds an object to the heap
*/
addObject (obj: unknown): number {
if (this.#heapNext === this.#heap.length) {
this.#heap.push(this.#heap.length + 1);
@@ -100,6 +134,10 @@ export class Bridge<C extends WasmBaseInstance> implements BridgeBase<C> {
return idx;
}
/**
* @internal
* @description Retrieve an Int32 in the WASM interface
*/
getInt32 (): Int32Array {
if (this.#cachegetInt32 === null || this.#cachegetInt32.buffer !== this.#wasm!.memory.buffer) {
this.#cachegetInt32 = new Int32Array(this.#wasm!.memory.buffer);
@@ -108,6 +146,10 @@ export class Bridge<C extends WasmBaseInstance> implements BridgeBase<C> {
return this.#cachegetInt32;
}
/**
* @internal
* @description Retrieve an Uint8Array in the WASM interface
*/
getUint8 (): Uint8Array {
if (this.#cachegetUint8 === null || this.#cachegetUint8.buffer !== this.#wasm!.memory.buffer) {
this.#cachegetUint8 = new Uint8Array(this.#wasm!.memory.buffer);
@@ -116,14 +158,26 @@ export class Bridge<C extends WasmBaseInstance> implements BridgeBase<C> {
return this.#cachegetUint8;
}
/**
* @internal
* @description Retrieves an Uint8Array in the WASM interface
*/
getU8a (ptr: number, len: number): Uint8Array {
return this.getUint8().subarray(ptr / 1, ptr / 1 + len);
}
/**
* @internal
* @description Retrieves a string in the WASM interface
*/
getString (ptr: number, len: number): string {
return u8aToString(this.getU8a(ptr, len));
}
/**
* @internal
* @description Allocates an Uint8Array in the WASM interface
*/
allocU8a (arg: Uint8Array): [number, number] {
const ptr = this.#wasm!.__wbindgen_malloc(arg.length * 1);
@@ -132,10 +186,18 @@ export class Bridge<C extends WasmBaseInstance> implements BridgeBase<C> {
return [ptr, arg.length];
}
/**
* @internal
* @description Allocates a string in the WASM interface
*/
allocString (arg: string): [number, number] {
return this.allocU8a(stringToU8a(arg));
}
/**
* @internal
* @description Retrieves an Uint8Array from the WASM interface
*/
resultU8a (): Uint8Array {
const r0 = this.getInt32()[8 / 4 + 0];
const r1 = this.getInt32()[8 / 4 + 1];
@@ -146,6 +208,10 @@ export class Bridge<C extends WasmBaseInstance> implements BridgeBase<C> {
return ret;
}
/**
* @internal
* @description Retrieve a string from the WASM interface
*/
resultString (): string {
return u8aToString(this.resultU8a());
}
-1
View File
@@ -3,4 +3,3 @@
export * from './bridge';
export * from './init';
export * from './wbg';
+14 -4
View File
@@ -3,8 +3,14 @@
import type { InitFn, InitPromise, InitResult, WasmBaseInstance } from './types';
import { assert } from '@polkadot/util';
/**
* @name createWasmFn
* @description
* Create a WASM (or ASM.js) creator interface based on the supplied information.
*
* It will attempt to create a WASM interface first and if this fails or is not available in
* the environment, will fallback to attempting to create an ASM.js interface.
*/
export function createWasmFn <C extends WasmBaseInstance> (root: string, wasmBytes: null | Uint8Array, asmFn: null | ((wbg: WebAssembly.ModuleImports) => C)): InitFn<C> {
return async (wbg: WebAssembly.ModuleImports): InitPromise<C> => {
const result: InitResult<C> = {
@@ -14,7 +20,11 @@ export function createWasmFn <C extends WasmBaseInstance> (root: string, wasmByt
};
try {
assert(typeof WebAssembly === 'object' && typeof WebAssembly.instantiate === 'function' && wasmBytes && wasmBytes.length, 'WebAssembly is not available in your environment');
if (!wasmBytes || !wasmBytes.length) {
throw new Error('No WebAssembly provided for initialization');
} else if (typeof WebAssembly !== 'object' || typeof WebAssembly.instantiate !== 'function') {
throw new Error('WebAssembly is not available in your environment');
}
const source = await WebAssembly.instantiate(wasmBytes, { wbg });
@@ -22,7 +32,7 @@ export function createWasmFn <C extends WasmBaseInstance> (root: string, wasmByt
result.type = 'wasm';
} catch (error) {
// if we have a valid supplied asm.js, return that
if (asmFn) {
if (typeof asmFn === 'function') {
result.wasm = asmFn(wbg);
result.type = 'asm';
} else {
+4
View File
@@ -0,0 +1,4 @@
// Copyright 2019-2022 @polkadot/wasm-bridge authors & contributors
// SPDX-License-Identifier: Apache-2.0
export * from './index';
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/wasm-bridge', path: 'auto', type: 'auto', version: '6.1.1' };
export const packageInfo = { name: '@polkadot/wasm-bridge', path: 'auto', type: 'auto', version: '6.1.4' };
-2
View File
@@ -1,8 +1,6 @@
// Copyright 2019-2022 @polkadot/wasm-bridge authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable camelcase */
export declare interface InitResult<C extends WasmBaseInstance> {
error: string | null;
type: 'asm' | 'wasm' | 'none';
+21 -4
View File
@@ -8,6 +8,17 @@ import { getRandomValues } from '@polkadot/x-randomvalues';
const DEFAULT_CRYPTO = { getRandomValues };
const DEFAULT_SELF = { crypto: DEFAULT_CRYPTO };
/**
* @name Wbg
* @description
* This defines the internal interfaces that wasm-bindgen used to communicate
* with the host layer. None of these functions are available to the user, rather
* they are called internally from the WASM code itself.
*
* The interfaces here are exposed in the imports on the created WASM interfaces.
*
* Internally the implementation does a thin layer into the supplied bridge.
*/
export class Wbg<C extends WasmBaseInstance> {
#bridge: BridgeBase<C>;
@@ -15,41 +26,50 @@ export class Wbg<C extends WasmBaseInstance> {
this.#bridge = bridge;
}
/** @internal */
abort = (): never => {
throw new Error('abort');
};
/** @internal */
__wbindgen_is_undefined = (idx: number): boolean => {
return this.#bridge.getObject(idx) === undefined;
};
/** @internal */
__wbindgen_throw = (ptr: number, len: number): boolean => {
throw new Error(this.#bridge.getString(ptr, len));
};
/** @internal */
__wbg_self_1b7a39e3a92c949c = (): number => {
return this.#bridge.addObject(DEFAULT_SELF);
};
/** @internal */
__wbg_require_604837428532a733 = (ptr: number, len: number): never => {
throw new Error(`Unable to require ${this.#bridge.getString(ptr, len)}`);
};
/** @internal */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
__wbg_crypto_968f1772287e2df0 = (_idx: number): number => {
return this.#bridge.addObject(DEFAULT_CRYPTO);
};
/** @internal */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
__wbg_getRandomValues_a3d34b4fee3c2869 = (_idx: number): number => {
return this.#bridge.addObject(DEFAULT_CRYPTO.getRandomValues);
};
/** @internal */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
__wbg_getRandomValues_f5e14ab7ac8e995d = (_arg0: number, ptr: number, len: number): void => {
DEFAULT_CRYPTO.getRandomValues(this.#bridge.getU8a(ptr, len));
};
/** @internal */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
__wbg_randomFillSync_d5bd2d655fdf256a = (_idx: number, _ptr: number, _len: number): never => {
throw new Error('randomFillsync is not available');
@@ -57,11 +77,8 @@ export class Wbg<C extends WasmBaseInstance> {
// getObject(idx).randomFillSync(getU8a(ptr, len));
};
/** @internal */
__wbindgen_object_drop_ref = (idx: number): void => {
this.#bridge.takeObject(idx);
};
}
export function initWbg <C extends WasmBaseInstance> (bridge: BridgeBase<C>): Wbg<C> {
return new Wbg(bridge);
}
+3 -3
View File
@@ -17,13 +17,13 @@
},
"sideEffects": false,
"type": "module",
"version": "6.1.1",
"version": "6.1.4",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.17.9"
"@babel/runtime": "^7.18.3"
},
"devDependencies": {
"@polkadot/util": "^9.1.1"
"@polkadot/util": "^9.5.1"
},
"peerDependencies": {
"@polkadot/util": "*"
+4
View File
@@ -0,0 +1,4 @@
// Copyright 2019-2022 @polkadot/wasm-crypto-asmjs authors & contributors
// SPDX-License-Identifier: Apache-2.0
export declare const asmJsInit: null;
@@ -0,0 +1,4 @@
// Copyright 2019-2022 @polkadot/wasm-crypto-asmjs authors & contributors
// SPDX-License-Identifier: Apache-2.0
export const asmJsInit = null;
+4
View File
@@ -0,0 +1,4 @@
// Copyright 2019-2022 @polkadot/wasm-crypto-asmjs authors & contributors
// SPDX-License-Identifier: Apache-2.0
export * from './index';
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/wasm-crypto-asmjs', path: 'auto', type: 'auto', version: '6.1.1' };
export const packageInfo = { name: '@polkadot/wasm-crypto-asmjs', path: 'auto', type: 'auto', version: '6.1.4' };
+6 -6
View File
@@ -20,18 +20,18 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "6.1.1",
"version": "6.1.4",
"browser": "wasm.js",
"main": "wasm.js",
"react-native": "asm.js",
"dependencies": {
"@babel/runtime": "^7.17.9",
"@polkadot/wasm-bridge": "6.1.1",
"@polkadot/wasm-crypto-asmjs": "6.1.1",
"@polkadot/wasm-crypto-wasm": "6.1.1"
"@babel/runtime": "^7.18.3",
"@polkadot/wasm-bridge": "6.1.4",
"@polkadot/wasm-crypto-asmjs": "6.1.4",
"@polkadot/wasm-crypto-wasm": "6.1.4"
},
"devDependencies": {
"@polkadot/util": "^9.1.1"
"@polkadot/util": "^9.5.1"
},
"peerDependencies": {
"@polkadot/util": "*"
+5
View File
@@ -9,4 +9,9 @@ import { asmJsInit } from '@polkadot/wasm-crypto-asmjs';
export { packageInfo } from './packageInfo';
/**
* @name createWasm
* @description
* Creates an interface using only ASM.js
*/
export const createWasm: InitFn<WasmCryptoInstance> = createWasmFn('crypto', null, asmJsInit);
+5
View File
@@ -10,4 +10,9 @@ import { wasmBytes } from '@polkadot/wasm-crypto-wasm';
export { packageInfo } from './packageInfo';
/**
* @name createWasm
* @description
* Creates an interface using WASM and a fallback ASM.js
*/
export const createWasm: InitFn<WasmCryptoInstance> = createWasmFn('crypto', wasmBytes, asmJsInit);
+4
View File
@@ -0,0 +1,4 @@
// Copyright 2019-2022 @polkadot/wasm-crypto-init authors & contributors
// SPDX-License-Identifier: Apache-2.0
export * from './wasm';
+5
View File
@@ -8,4 +8,9 @@ import { createWasmFn } from '@polkadot/wasm-bridge';
export { packageInfo } from './packageInfo';
/**
* @name createWasm
* @description
* Creates an interface using no WASM and no ASM.js
*/
export const createWasm: InitFn<WasmCryptoInstance> = createWasmFn('crypto', null, null);
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/wasm-crypto-init', path: 'auto', type: 'auto', version: '6.1.1' };
export const packageInfo = { name: '@polkadot/wasm-crypto-init', path: 'auto', type: 'auto', version: '6.1.4' };
+5
View File
@@ -9,4 +9,9 @@ import { wasmBytes } from '@polkadot/wasm-crypto-wasm';
export { packageInfo } from './packageInfo';
/**
* @name createWasm
* @description
* Creates an interface using only WASM
*/
export const createWasm: InitFn<WasmCryptoInstance> = createWasmFn('crypto', wasmBytes, null);
+4 -4
View File
@@ -17,14 +17,14 @@
},
"sideEffects": false,
"type": "module",
"version": "6.1.1",
"version": "6.1.4",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.17.9",
"@polkadot/wasm-util": "6.1.1"
"@babel/runtime": "^7.18.3",
"@polkadot/wasm-util": "6.1.4"
},
"devDependencies": {
"@polkadot/util": "^9.1.1"
"@polkadot/util": "^9.5.1"
},
"peerDependencies": {
"@polkadot/util": "*"
+10 -1
View File
@@ -3,8 +3,17 @@
import { base64Decode, unzlibSync } from '@polkadot/wasm-util';
import { bytes, sizeUncompressed } from './cjs/bytes';
import { bytes, sizeUncompressed } from './cjs/bytes.js';
export { packageInfo } from './packageInfo';
/**
* @name wasmBytes
* @description
* The decoded WASM interface as exposed by this package.
*
* The build process will output into cjs/* into a compressed base64 format.
* Upon loading the exposed bytes will be decoded and decompressed form this
* specific format and returned.
*/
export const wasmBytes = unzlibSync(base64Decode(bytes), new Uint8Array(sizeUncompressed));
+5 -3
View File
@@ -1,6 +1,8 @@
// Copyright 2019-2022 @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;
export declare const bytes: string;
export declare const sizeCompressed: number;
export declare const sizeUncompressed: number;
+8
View File
@@ -0,0 +1,8 @@
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
// SPDX-License-Identifier: Apache-2.0
export declare const bytes: string;
export declare const sizeCompressed: number;
export declare const sizeUncompressed: number;
@@ -0,0 +1,8 @@
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
// SPDX-License-Identifier: Apache-2.0
export const bytes = '';
export const sizeCompressed = 0;
export const sizeUncompressed = 0;
+4
View File
@@ -0,0 +1,4 @@
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
// SPDX-License-Identifier: Apache-2.0
export * from './index';
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/wasm-crypto-wasm', path: 'auto', type: 'auto', version: '6.1.1' };
export const packageInfo = { name: '@polkadot/wasm-crypto-wasm', path: 'auto', type: 'auto', version: '6.1.4' };
+8 -8
View File
@@ -28,18 +28,18 @@
"./initWasmAsm.cjs"
],
"type": "module",
"version": "6.1.1",
"version": "6.1.4",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.17.9",
"@polkadot/wasm-bridge": "6.1.1",
"@polkadot/wasm-crypto-asmjs": "6.1.1",
"@polkadot/wasm-crypto-init": "6.1.1",
"@polkadot/wasm-crypto-wasm": "6.1.1",
"@polkadot/wasm-util": "6.1.1"
"@babel/runtime": "^7.18.3",
"@polkadot/wasm-bridge": "6.1.4",
"@polkadot/wasm-crypto-asmjs": "6.1.4",
"@polkadot/wasm-crypto-init": "6.1.4",
"@polkadot/wasm-crypto-wasm": "6.1.4",
"@polkadot/wasm-util": "6.1.4"
},
"devDependencies": {
"@polkadot/util": "^9.1.1"
"@polkadot/util": "^9.5.1"
},
"peerDependencies": {
"@polkadot/util": "*"
+20 -3
View File
@@ -3,21 +3,38 @@
import type { WasmCryptoInstance } from '@polkadot/wasm-crypto-init/types';
import { assert } from '@polkadot/util';
import { bridge, initBridge } from './init';
export { packageInfo } from './packageInfo';
export { bridge };
// Removes the first parameter (expected as WasmCryptoInstance) and leaves the
// rest of the parameters in-tack. This allows us to dynamically create a function
// return from the withWasm helper
type PopFirst<T extends unknown[]> =
T extends [WasmCryptoInstance, ...infer N]
? N
: [];
/**
* @internal
* @description
* This create an extenal interface function from the signature, all the while checking
* the actual bridge wasm interface to ensure it has been initialized.
*
* This means that we can call it
*
* withWasm(wasm: WasmCryptoInstance, a: number, b: string) => Uint8Array
*
* and in this case it will create an interface function with the signarure
*
* (a: number, b: string) => Uint8Array
*/
function withWasm <T, F extends (wasm: WasmCryptoInstance, ...params: never[]) => T> (fn: F): (...params: PopFirst<Parameters<F>>) => ReturnType<F> {
return (...params: PopFirst<Parameters<F>>): ReturnType<F> => {
assert(bridge.wasm, 'The WASM interface has not been initialized. Ensure that you wait for the initialization Promise with waitReady() from @polkadot/wasm-crypto (or cryptoWaitReady() from @polkadot/util-crypto) before attempting to use WASM-only interfaces.');
if (!bridge.wasm) {
throw new Error('The WASM interface has not been initialized. Ensure that you wait for the initialization Promise with waitReady() from @polkadot/wasm-crypto (or cryptoWaitReady() from @polkadot/util-crypto) before attempting to use WASM-only interfaces.');
}
return fn(bridge.wasm, ...params) as ReturnType<F>;
};
+11
View File
@@ -7,8 +7,19 @@ import type { WasmCryptoInstance } from '@polkadot/wasm-crypto-init/types';
import { Bridge } from '@polkadot/wasm-bridge';
import { createWasm } from '@polkadot/wasm-crypto-init';
/**
* @name bridge
* @description
* The JS <-> WASM bridge that is in operation. For the specific package
* it is a global, i.e. all operations happens on this specific bridge
*/
export const bridge = new Bridge<WasmCryptoInstance>(createWasm);
/**
* @name initBridge
* @description
* Creates a new bridge interface with the (optional) initialization function
*/
export async function initBridge (createWasm?: InitFn<WasmCryptoInstance>): Promise<WasmCryptoInstance | null> {
return bridge.init(createWasm);
}
+9
View File
@@ -5,6 +5,15 @@ import { createWasm } from '@polkadot/wasm-crypto-init/none';
import { initBridge } from './init';
/**
* @name initWasm
* @description
* For historic purposes and for tighter control on init, specifically performing
* a WASM initialization with no interface whatsoever (no WASM, no ASM.js)
*
* Generally should not be used unless you want explicit control over which
* interfaces are initialized.
*/
export async function initWasm (): Promise<void> {
await initBridge(createWasm);
}
+9
View File
@@ -5,6 +5,15 @@ import { createWasm } from '@polkadot/wasm-crypto-init/asm';
import { initBridge } from './init';
/**
* @name initWasm
* @description
* For historic purposes and for tighter control on init, specifically performing
* a WASM initialization with only ASM.js
*
* Generally should not be used unless you want explicit control over which
* interfaces are initialized.
*/
export async function initWasm (): Promise<void> {
await initBridge(createWasm);
}
+9
View File
@@ -5,6 +5,15 @@ import { createWasm } from '@polkadot/wasm-crypto-init/wasm';
import { initBridge } from './init';
/**
* @name initWasm
* @description
* For historic purposes and for tighter control on init, specifically performing
* a WASM initialization with only WASM (generally the default for most platforms)
*
* Generally should not be used unless you want explicit control over which
* interfaces are initialized.
*/
export async function initWasm (): Promise<void> {
await initBridge(createWasm);
}
+9
View File
@@ -5,6 +5,15 @@ import { createWasm } from '@polkadot/wasm-crypto-init/both';
import { initBridge } from './init';
/**
* @name initWasm
* @description
* For historic purposes and for tighter control on init, specifically performing
* a WASM initialization with ASM and an ASM.js fallback
*
* Generally should not be used unless you want explicit control over which
* interfaces are initialized.
*/
export async function initWasm (): Promise<void> {
await initBridge(createWasm);
}
+4
View File
@@ -0,0 +1,4 @@
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
export * from './index';
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/wasm-crypto', path: 'auto', type: 'auto', version: '6.1.1' };
export const packageInfo = { name: '@polkadot/wasm-crypto', path: 'auto', type: 'auto', version: '6.1.4' };
+3 -3
View File
@@ -20,13 +20,13 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "6.1.1",
"version": "6.1.4",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.17.9"
"@babel/runtime": "^7.18.3"
},
"devDependencies": {
"@polkadot/util": "^9.1.1"
"@polkadot/util": "^9.5.1"
},
"peerDependencies": {
"@polkadot/util": "*"
+9
View File
@@ -3,7 +3,16 @@
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
/**
* @name base64Decode
* @description
* A fail-safe base64Decoding function that operates in all environments. Unlike
* decoding from Buffer (Node.js only) or atob (browser-only) this implementation
* is slightly slower, but it is platform independent.
*/
export function base64Decode (data: string): Uint8Array {
// TODO: For Node.js speedups, we could add an explicit base64Node.ts implementation
// that would be (via export maps) be available in that environment only
const bytes = [];
let byte = 0;
let bits = 0;
+4
View File
@@ -0,0 +1,4 @@
// Copyright 2019-2022 @polkadot/wasm-util authors & contributors
// SPDX-License-Identifier: Apache-2.0
export * from './index';
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/wasm-util', path: 'auto', type: 'auto', version: '6.1.1' };
export const packageInfo = { name: '@polkadot/wasm-util', path: 'auto', type: 'auto', version: '6.1.4' };
+13
View File
@@ -10,6 +10,8 @@ source ../scripts/rust-version.sh
WSM=$PKG_NAME/build-wasm/wasm_bg.wasm
OPT=$PKG_NAME/build-wasm/wasm_opt.wasm
ASM=$PKG_NAME-asmjs/build/cjs/data.js
DENO_DIR=$PKG_NAME-asmjs/build-deno/deno
DENO_ASM=$DENO_DIR/data.js
# build new via wasm-pack
echo "*** Building Rust sources"
@@ -36,11 +38,22 @@ node ../scripts/pack-wasm-base.cjs
echo "*** Building asm.js version"
../binaryen/bin/wasm2js -Oz --output $ASM $OPT
# copy the deno version
mkdir -p $DENO_DIR
cp $ASM $DENO_ASM
# cleanup the generated asm, converting to cjs
sed -i -e '/import {/d' $ASM
sed -i -e '1,/var retasmFunc = /!d' $ASM
sed -i -e 's/var retasmFunc = .*/const asmJsInit = (wbg) => asmFunc(wbg);\n\nmodule.exports = { asmJsInit };/g' $ASM
# same as the cjs version, this time for deno
sed -i -e '/import {/d' $DENO_ASM
sed -i -e '1,/var retasmFunc = /!d' $DENO_ASM
sed -i -e 's/var retasmFunc = .*/export const asmJsInit = (wbg) => asmFunc(wbg);/g' $DENO_ASM
# cleanups
rm -rf $PKG_NAME-asmjs/build/cjs/*-e
rm -rf $PKG_NAME-asmjs/build-deno/deno/*-e
rm -rf $PKG_NAME-wasm/build/cjs/*-e
rm -rf $PKG_NAME-wasm/build-deno/deno/*-e
+16
View File
@@ -3,13 +3,17 @@
const fflate = require('fflate/node');
const fs = require('fs');
const mkdirp = require('mkdirp');
const { formatNumber } = require('@polkadot/util');
const data = fs.readFileSync(`./${process.env.PKG_NAME}/build-wasm/wasm_opt.wasm`);
const compressed = Buffer.from(fflate.zlibSync(data, { level: 9 }));
const denoDir = `./${process.env.PKG_NAME}-wasm/build-deno/deno`;
console.log(`*** Compressed WASM: ${formatNumber(data.length)} -> ${formatNumber(compressed.length)} (${(100 * compressed.length / data.length).toFixed(2)}%)`);
mkdirp.sync(denoDir);
fs.writeFileSync(`./${process.env.PKG_NAME}-wasm/build/cjs/bytes.js`, `// Copyright 2019-${new Date().getFullYear()} @polkadot/${process.env.PKG_NAME}-wasm authors & contributors
// SPDX-License-Identifier: Apache-2.0
@@ -21,3 +25,15 @@ const bytes = '${compressed.toString('base64')}';
module.exports = { bytes, sizeCompressed, sizeUncompressed };
`);
fs.writeFileSync(`${denoDir}/bytes.js`, `// Copyright 2019-${new Date().getFullYear()} @polkadot/${process.env.PKG_NAME}-wasm authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Generated as part of the build, do not edit
export const sizeCompressed = ${compressed.length};
export const sizeUncompressed = ${data.length};
export const bytes = '${compressed.toString('base64')}';
`);
+1106 -1046
View File
File diff suppressed because it is too large Load Diff