Split into common wasm-bridge package (#346)
* Split into common wasm-bridge package * README * Adjust rollup bundling * Adjust * Adjust * Adjust, full re-usable * Cleanup deps * Restore initWasm exports from init* * Split base64 & fflate into wasm-util * sideEffects for wasm-util * Dedupe types * Additional * Adjust * Expose error on InitResult * Bump deps * CHANGELOG * Re-usable rollup config
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
Changes:
|
||||
|
||||
- Adjust init, allow RN with default ASM.js-only fallback
|
||||
- Split `wasm-{bridge, util}` packages for internal re-use
|
||||
|
||||
|
||||
## 6.0.1 Apr 9, 2022
|
||||
|
||||
+1
-1
@@ -8,6 +8,6 @@ module.exports = {
|
||||
moduleNameMapper: {
|
||||
'@polkadot/wasm-crypto-(init|asmjs|wasm)(.*)$': '<rootDir>/packages/wasm-crypto-$1/build/$2',
|
||||
// eslint-disable-next-line sort-keys
|
||||
'@polkadot/wasm-crypto(.*)$': '<rootDir>/packages/wasm-crypto/build/$1'
|
||||
'@polkadot/wasm-(bridge|crypto|util)(.*)$': '<rootDir>/packages/wasm-$1/build/$2'
|
||||
}
|
||||
};
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.17.10",
|
||||
"@polkadot/dev": "^0.66.20",
|
||||
"@polkadot/dev": "^0.66.21",
|
||||
"fflate": "^0.7.3",
|
||||
"override-require": "^1.1.1"
|
||||
},
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -0,0 +1 @@
|
||||
# @polkadot/wasm-bridge
|
||||
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"bugs": "https://github.com/polkadot-js/wasm/issues",
|
||||
"contributors": [],
|
||||
"description": "A bridge layer between JS and Wasm",
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/wasm/tree/master/packages/wasm-bridge#readme",
|
||||
"license": "Apache-2.0",
|
||||
"maintainers": [],
|
||||
"name": "@polkadot/wasm-bridge",
|
||||
"repository": {
|
||||
"directory": "packages/wasm-bridge",
|
||||
"type": "git",
|
||||
"url": "https://github.com/polkadot-js/wasm.git"
|
||||
},
|
||||
"sideEffects": [
|
||||
"./detectPackage.js",
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "6.0.2-12",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.17.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/util": "^9.1.1",
|
||||
"@polkadot/x-randomvalues": "^9.1.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "*",
|
||||
"@polkadot/x-randomvalues": "*"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-bridge authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
import type { BridgeBase, InitFn, InitPromise, WasmBaseInstance } from './types';
|
||||
|
||||
import { stringToU8a, u8aToString } from '@polkadot/util';
|
||||
|
||||
export class Bridge<C extends WasmBaseInstance> implements BridgeBase<C> {
|
||||
#cachegetInt32: Int32Array | null;
|
||||
#cachegetUint8: Uint8Array | null;
|
||||
#defaultInit: (wbg: WebAssembly.ModuleImports) => InitPromise<C>;
|
||||
#heap: unknown[];
|
||||
#heapNext: number;
|
||||
#wasm: C | null;
|
||||
#wasmError: string | null;
|
||||
#wasmPromise: InitPromise<C> | null;
|
||||
#wbg: WebAssembly.ModuleImports;
|
||||
#type: 'asm' | 'wasm' | 'none';
|
||||
|
||||
constructor (createWbg: (bridge: Bridge<C>) => WebAssembly.ModuleImports, createWasm: InitFn<C>) {
|
||||
this.#defaultInit = createWasm;
|
||||
this.#cachegetInt32 = null;
|
||||
this.#cachegetUint8 = null;
|
||||
this.#heap = new Array(32)
|
||||
.fill(undefined)
|
||||
.concat(undefined, null, true, false);
|
||||
this.#heapNext = this.#heap.length;
|
||||
this.#type = 'none';
|
||||
this.#wasm = null;
|
||||
this.#wasmError = null;
|
||||
this.#wasmPromise = null;
|
||||
this.#wbg = createWbg(this);
|
||||
}
|
||||
|
||||
get error (): string | null {
|
||||
return this.#wasmError;
|
||||
}
|
||||
|
||||
get type (): 'asm' | 'wasm' | 'none' {
|
||||
return this.#type;
|
||||
}
|
||||
|
||||
get wbg (): WebAssembly.ModuleImports {
|
||||
return this.#wbg;
|
||||
}
|
||||
|
||||
get wasm (): C | null {
|
||||
return this.#wasm;
|
||||
}
|
||||
|
||||
async init (override?: InitFn<C>): Promise<C | null> {
|
||||
if (!this.#wasmPromise || override) {
|
||||
this.#wasmPromise = (override || this.#defaultInit)(this.#wbg);
|
||||
}
|
||||
|
||||
const { error, type, wasm } = await this.#wasmPromise;
|
||||
|
||||
this.#type = type;
|
||||
this.#wasm = wasm;
|
||||
this.#wasmError = error;
|
||||
|
||||
return this.#wasm;
|
||||
}
|
||||
|
||||
getObject (idx: number): unknown {
|
||||
return this.#heap[idx];
|
||||
}
|
||||
|
||||
dropObject (idx: number) {
|
||||
if (idx < 36) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.#heap[idx] = this.#heapNext;
|
||||
this.#heapNext = idx;
|
||||
}
|
||||
|
||||
takeObject (idx: number): unknown {
|
||||
const ret = this.getObject(idx);
|
||||
|
||||
this.dropObject(idx);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
addObject (obj: unknown): number {
|
||||
if (this.#heapNext === this.#heap.length) {
|
||||
this.#heap.push(this.#heap.length + 1);
|
||||
}
|
||||
|
||||
const idx = this.#heapNext;
|
||||
|
||||
this.#heapNext = this.#heap[idx] as number;
|
||||
this.#heap[idx] = obj;
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
getInt32 (): Int32Array {
|
||||
if (this.#cachegetInt32 === null || this.#cachegetInt32.buffer !== this.#wasm!.memory.buffer) {
|
||||
this.#cachegetInt32 = new Int32Array(this.#wasm!.memory.buffer);
|
||||
}
|
||||
|
||||
return this.#cachegetInt32;
|
||||
}
|
||||
|
||||
getUint8 (): Uint8Array {
|
||||
if (this.#cachegetUint8 === null || this.#cachegetUint8.buffer !== this.#wasm!.memory.buffer) {
|
||||
this.#cachegetUint8 = new Uint8Array(this.#wasm!.memory.buffer);
|
||||
}
|
||||
|
||||
return this.#cachegetUint8;
|
||||
}
|
||||
|
||||
getU8a (ptr: number, len: number): Uint8Array {
|
||||
return this.getUint8().subarray(ptr / 1, ptr / 1 + len);
|
||||
}
|
||||
|
||||
getString (ptr: number, len: number): string {
|
||||
return u8aToString(this.getU8a(ptr, len));
|
||||
}
|
||||
|
||||
allocU8a (arg: Uint8Array): [number, number] {
|
||||
const ptr = this.#wasm!.__wbindgen_malloc(arg.length * 1);
|
||||
|
||||
this.getUint8().set(arg, ptr / 1);
|
||||
|
||||
return [ptr, arg.length];
|
||||
}
|
||||
|
||||
allocString (arg: string): [number, number] {
|
||||
return this.allocU8a(stringToU8a(arg));
|
||||
}
|
||||
|
||||
resultU8a (): Uint8Array {
|
||||
const r0 = this.getInt32()[8 / 4 + 0];
|
||||
const r1 = this.getInt32()[8 / 4 + 1];
|
||||
const ret = this.getU8a(r0, r1).slice();
|
||||
|
||||
this.#wasm!.__wbindgen_free(r0, r1 * 1);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
resultString (): string {
|
||||
return u8aToString(this.resultU8a());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-bridge authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from './bridge';
|
||||
export * from './init';
|
||||
export * from './wbg';
|
||||
@@ -0,0 +1,4 @@
|
||||
// Copyright 2017-2022 @polkadot/wasm-bridge authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export default [];
|
||||
@@ -0,0 +1,11 @@
|
||||
// Copyright 2017-2022 @polkadot/wasm-bridge authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
import { detectPackage } from '@polkadot/util';
|
||||
|
||||
import others from './detectOther';
|
||||
import { packageInfo } from './packageInfo';
|
||||
|
||||
detectPackage(packageInfo, null, others);
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-bridge authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import './detectPackage';
|
||||
|
||||
export * from './bundle';
|
||||
@@ -0,0 +1,37 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-bundle authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { InitFn, InitPromise, InitResult, WasmBaseInstance } from './types';
|
||||
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
export function initWasm <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> = {
|
||||
error: null,
|
||||
type: 'none',
|
||||
wasm: null
|
||||
};
|
||||
|
||||
try {
|
||||
assert(typeof WebAssembly === 'object' && typeof WebAssembly.instantiate === 'function' && wasmBytes && wasmBytes.length, 'WebAssembly is not available in your environment');
|
||||
|
||||
const source = await WebAssembly.instantiate(wasmBytes, { wbg });
|
||||
|
||||
result.wasm = source.instance.exports as unknown as C;
|
||||
result.type = 'wasm';
|
||||
} catch (error) {
|
||||
// if we have a valid supplied asm.js, return that
|
||||
if (asmFn) {
|
||||
result.wasm = asmFn(wbg);
|
||||
result.type = 'asm';
|
||||
} else {
|
||||
result.error = `FATAL: Unable to initialize @polkadot/wasm-${root}:: ${(error as Error).message}`;
|
||||
|
||||
console.error(result.error);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2017-2022 @polkadot/wasm-bridge authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/wasm-bridge', path: 'auto', type: 'auto', version: '6.0.2-12' };
|
||||
@@ -0,0 +1,43 @@
|
||||
// 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';
|
||||
wasm: C | null;
|
||||
}
|
||||
|
||||
export type InitPromise <C extends WasmBaseInstance> = Promise<InitResult<C>>;
|
||||
|
||||
export type InitFn <C extends WasmBaseInstance> = (wgb: WebAssembly.ModuleImports) => InitPromise<C>;
|
||||
|
||||
export interface BridgeBase<C extends WasmBaseInstance> extends InitResult<C> {
|
||||
wbg: WebAssembly.ModuleImports;
|
||||
|
||||
init (initOverride?: InitFn<C>): Promise<C | null>;
|
||||
getObject (idx: number): unknown;
|
||||
dropObject (idx: number): void;
|
||||
takeObject (idx: number): unknown;
|
||||
addObject (obj: unknown): number;
|
||||
getInt32 (): Int32Array;
|
||||
getUint8 (): Uint8Array;
|
||||
getU8a (ptr: number, len: number): Uint8Array;
|
||||
getString (ptr: number, len: number): string;
|
||||
allocU8a (arg: Uint8Array): [number, number];
|
||||
allocString (arg: string): [number, number];
|
||||
resultU8a (): Uint8Array;
|
||||
resultString (): string;
|
||||
}
|
||||
|
||||
export interface WasmBaseInstance {
|
||||
memory: WebAssembly.Memory;
|
||||
|
||||
// wbindgen functions (required and used internally)
|
||||
|
||||
__wbindgen_exn_store (a: number): void;
|
||||
__wbindgen_free (a: number, b: number): void;
|
||||
__wbindgen_malloc (a: number): number;
|
||||
__wbindgen_realloc (a: number, b: number, c: number): number;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-bridge authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { BridgeBase, WasmBaseInstance } from './types';
|
||||
|
||||
import { getRandomValues } from '@polkadot/x-randomvalues';
|
||||
|
||||
const DEFAULT_CRYPTO = { getRandomValues };
|
||||
const DEFAULT_SELF = { crypto: DEFAULT_CRYPTO };
|
||||
|
||||
export class Wbg<C extends WasmBaseInstance> {
|
||||
#bridge: BridgeBase<C>;
|
||||
|
||||
constructor (bridge: BridgeBase<C>) {
|
||||
this.#bridge = bridge;
|
||||
}
|
||||
|
||||
abort = (): never => {
|
||||
throw new Error('abort');
|
||||
};
|
||||
|
||||
__wbindgen_is_undefined = (idx: number): boolean => {
|
||||
return this.#bridge.getObject(idx) === undefined;
|
||||
};
|
||||
|
||||
__wbindgen_throw = (ptr: number, len: number): boolean => {
|
||||
throw new Error(this.#bridge.getString(ptr, len));
|
||||
};
|
||||
|
||||
__wbg_self_1b7a39e3a92c949c = (): number => {
|
||||
return this.#bridge.addObject(DEFAULT_SELF);
|
||||
};
|
||||
|
||||
__wbg_require_604837428532a733 = (ptr: number, len: number): never => {
|
||||
throw new Error(`Unable to require ${this.#bridge.getString(ptr, len)}`);
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
__wbg_crypto_968f1772287e2df0 = (_idx: number): number => {
|
||||
return this.#bridge.addObject(DEFAULT_CRYPTO);
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
__wbg_getRandomValues_a3d34b4fee3c2869 = (_idx: number): number => {
|
||||
return this.#bridge.addObject(DEFAULT_CRYPTO.getRandomValues);
|
||||
};
|
||||
|
||||
// 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));
|
||||
};
|
||||
|
||||
// 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');
|
||||
|
||||
// getObject(idx).randomFillSync(getU8a(ptr, len));
|
||||
};
|
||||
|
||||
__wbindgen_object_drop_ref = (idx: number): void => {
|
||||
this.#bridge.takeObject(idx);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "..",
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"references": [
|
||||
]
|
||||
}
|
||||
@@ -26,6 +26,7 @@
|
||||
"react-native": "asm.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.17.9",
|
||||
"@polkadot/wasm-bridge": "6.0.2-12",
|
||||
"@polkadot/wasm-crypto-asmjs": "6.0.2-12",
|
||||
"@polkadot/wasm-crypto-wasm": "6.0.2-12"
|
||||
},
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto-init authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { InitFn } from './types';
|
||||
import type { InitFn } from '@polkadot/wasm-bridge/types';
|
||||
import type { WasmCryptoInstance } from './types';
|
||||
|
||||
import { initWasm } from '@polkadot/wasm-bridge';
|
||||
import { asmJsInit } from '@polkadot/wasm-crypto-asmjs';
|
||||
|
||||
import { createInitFn } from './util';
|
||||
|
||||
export { packageInfo } from './packageInfo';
|
||||
|
||||
export const init: InitFn = createInitFn(null, asmJsInit);
|
||||
export const init: InitFn<WasmCryptoInstance> = initWasm('crypto', null, asmJsInit);
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto-init authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { InitFn } from './types';
|
||||
import type { InitFn } from '@polkadot/wasm-bridge/types';
|
||||
import type { WasmCryptoInstance } from './types';
|
||||
|
||||
import { initWasm } from '@polkadot/wasm-bridge';
|
||||
import { asmJsInit } from '@polkadot/wasm-crypto-asmjs';
|
||||
import { wasmBytes } from '@polkadot/wasm-crypto-wasm';
|
||||
|
||||
import { createInitFn } from './util';
|
||||
|
||||
export { packageInfo } from './packageInfo';
|
||||
|
||||
export const init: InitFn = createInitFn(wasmBytes, asmJsInit);
|
||||
export const init: InitFn<WasmCryptoInstance> = initWasm('crypto', wasmBytes, asmJsInit);
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto-init authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from './wasm';
|
||||
@@ -1,7 +1,8 @@
|
||||
// Copyright 2017-2022 @polkadot/wasm-crypto-init authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { packageInfo as bridgeInfo } from '@polkadot/wasm-bridge/packageInfo';
|
||||
import { packageInfo as asmInfo } from '@polkadot/wasm-crypto-asmjs/packageInfo';
|
||||
import { packageInfo as wasmInfo } from '@polkadot/wasm-crypto-wasm/packageInfo';
|
||||
|
||||
export default [asmInfo, wasmInfo];
|
||||
export default [bridgeInfo, asmInfo, wasmInfo];
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto-init authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { InitFn } from './types';
|
||||
import type { InitFn } from '@polkadot/wasm-bridge/types';
|
||||
import type { WasmCryptoInstance } from './types';
|
||||
|
||||
import { createInitFn } from './util';
|
||||
import { initWasm } from '@polkadot/wasm-bridge';
|
||||
|
||||
export { packageInfo } from './packageInfo';
|
||||
|
||||
export const init: InitFn = createInitFn(null, null);
|
||||
export const init: InitFn<WasmCryptoInstance> = initWasm('crypto', null, null);
|
||||
|
||||
@@ -1,9 +1,75 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto-init authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export declare interface InitResult {
|
||||
type: 'wasm' | 'asm';
|
||||
wasm: unknown;
|
||||
}
|
||||
import type { WasmBaseInstance } from '@polkadot/wasm-bridge/types';
|
||||
|
||||
export type InitFn = (wbg: WebAssembly.ModuleImports) => Promise<InitResult>;
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
// wasm-pack build output (formatted) from pkg/wasm_bg.d.ts
|
||||
export interface WasmCryptoInstance extends WasmBaseInstance {
|
||||
// exposed functions
|
||||
|
||||
ext_bip39_generate(resLen: 8, words: number): void;
|
||||
|
||||
ext_bip39_to_entropy(resLen: 8, ptrPhrase: number, lenPhrase: number): void;
|
||||
|
||||
ext_bip39_to_mini_secret(resLen: 8, ptrPhrase: number, lenPhrase: number, ptrPass: number, lenPass: number): void;
|
||||
|
||||
ext_bip39_to_seed(resLen: 8, ptrPhrase: number, lenPhrase: number, ptrPass: number, lenPass: number): void;
|
||||
|
||||
ext_bip39_validate(ptrPhrase: number, lenPhrase: number): number;
|
||||
|
||||
ext_ed_from_seed(resLen: 8, ptrSeed: number, lenSeed: number): void;
|
||||
|
||||
ext_ed_sign(resLen: 8, ptrPub: number, lenPub: number, ptrSec: number, lenSec: number, ptrMsg: number, lenMsg: number): void;
|
||||
|
||||
ext_ed_verify(ptrSig: number, lenSig: number, ptrMsg: number, lenMsg: number, ptrPub: number, lenPub: number): number;
|
||||
|
||||
ext_blake2b(resLen: 8, ptrData: number, lenData: number, ptrKey: number, lenKey: number, size: number): void;
|
||||
|
||||
ext_hmac_sha256(resLen: 8, ptrKey: number, lenKey: number, ptrData: number, lenData: number): void;
|
||||
|
||||
ext_hmac_sha512(resLen: 8, ptrKey: number, lenKey: number, ptrData: number, lenData: number): void;
|
||||
|
||||
ext_keccak256(resLen: 8, ptrData: number, lenData: number): void;
|
||||
|
||||
ext_keccak512(resLen: 8, ptrData: number, lenData: number): void;
|
||||
|
||||
ext_pbkdf2(resLen: 8, ptrData: number, lenData: number, ptrSalt: number, lenSalt: number, rounds: number): void;
|
||||
|
||||
ext_scrypt(resLen: 8, ptrPass: number, lenPass: number, ptrSalt: number, lenSalt: number, log2n: number, r: number, p: number): void;
|
||||
|
||||
ext_sha256(resLen: 8, ptrData: number, lenData: number): void;
|
||||
|
||||
ext_sha512(resLen: 8, ptrData: number, lenData: number): void;
|
||||
|
||||
ext_twox(resLen: 8, ptrData: number, lenData: number, rounds: number): void;
|
||||
|
||||
ext_secp_from_seed(reslen: 8, ptrSec: number, lenSec: number): void;
|
||||
|
||||
ext_secp_pub_compress(resLen: 8, ptrPub: number, lenPub: number): void;
|
||||
|
||||
ext_secp_pub_expand(resLen: 8, ptrPub: number, lenPub: number): void;
|
||||
|
||||
ext_secp_recover(resLen: 8, ptrMsgHash: number, lenMsgHash: number, ptrSig: number, lenSig: number, recovery: number): void;
|
||||
|
||||
ext_secp_sign(resLen: 8, ptrMsgHash: number, lenMsgHash: number, ptrSec: number, lenSec: number): void;
|
||||
|
||||
ext_sr_derive_keypair_hard(resLen: 8, ptrPair: number, lenPair: number, ptrCc: number, lenCc: number): void;
|
||||
|
||||
ext_sr_derive_keypair_soft(resLen: 8, ptrPub: number, lenPub: number, ptrCc: number, lenCc: number): void;
|
||||
|
||||
ext_sr_derive_public_soft(resLen: 8, ptrPub: number, lenPub: number, ptrCc: number, lenCc: number): void;
|
||||
|
||||
ext_sr_from_seed(resLen: 8, ptrSeed: number, lenSeed: number): void;
|
||||
|
||||
ext_sr_sign(resLen: 8, ptrPub: number, lenPub: number, ptrSec: number, lenSec: number, ptrMsg: number, lenMsg: number): void;
|
||||
|
||||
ext_sr_verify(ptrSig: number, lenSig: number, ptrMsg: number, lenMsg: number, ptrPub: number, lenPub: number): number;
|
||||
|
||||
ext_sr_agree(resLen: 8, ptrPub: number, lenPub: number, ptrSec: number, lenSec: number): void;
|
||||
|
||||
ext_vrf_sign(resLen: 8, ptrSec: number, lenSec: number, ptrCtx: number, lenCtx: number, ptrMsg: number, lenMsg: number, ptrExtra: number, lenExtra: number): void;
|
||||
|
||||
ext_vrf_verify(ptrPub: number, lenPub: number, ptrCtx: number, lenCtx: number, ptrMsg: number, lenMsg: number, ptrExtra: number, lenExtra: number, ptrProof: number, lenProof: number): number;
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto-init authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { InitFn, InitResult } from './types';
|
||||
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
export function createInitFn (wasmBytes: null | Uint8Array, asmFn: null | ((wbg: WebAssembly.ModuleImports) => unknown)): InitFn {
|
||||
return async (wbg: WebAssembly.ModuleImports): Promise<InitResult> => {
|
||||
const result: InitResult = {
|
||||
type: 'wasm',
|
||||
wasm: null
|
||||
};
|
||||
|
||||
try {
|
||||
assert(typeof WebAssembly === 'object' && typeof WebAssembly.instantiate === 'function' && wasmBytes && wasmBytes.length, 'WebAssembly is not available in your environment');
|
||||
|
||||
const source = await WebAssembly.instantiate(wasmBytes, { wbg });
|
||||
|
||||
result.wasm = source.instance.exports;
|
||||
} catch (error) {
|
||||
// if we have a valid supplied asm.js, return that
|
||||
if (asmFn) {
|
||||
result.type = 'asm';
|
||||
result.wasm = asmFn(wbg);
|
||||
} else {
|
||||
console.error(`FATAL: Unable to initialize @polkadot/wasm-crypto:: ${(error as Error).message}`);
|
||||
|
||||
result.wasm = null;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto-init authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { InitFn } from './types';
|
||||
import type { InitFn } from '@polkadot/wasm-bridge/types';
|
||||
import type { WasmCryptoInstance } from './types';
|
||||
|
||||
import { initWasm } from '@polkadot/wasm-bridge';
|
||||
import { wasmBytes } from '@polkadot/wasm-crypto-wasm';
|
||||
|
||||
import { createInitFn } from './util';
|
||||
|
||||
export { packageInfo } from './packageInfo';
|
||||
|
||||
export const init: InitFn = createInitFn(wasmBytes, null);
|
||||
export const init: InitFn<WasmCryptoInstance> = initWasm('crypto', wasmBytes, null);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"references": [
|
||||
{ "path": "../wasm-bridge/tsconfig.build.json" },
|
||||
{ "path": "../wasm-crypto-asmjs/tsconfig.build.json" },
|
||||
{ "path": "../wasm-crypto-wasm/tsconfig.build.json" }
|
||||
]
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
"version": "6.0.2-12",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.17.9"
|
||||
"@babel/runtime": "^7.17.9",
|
||||
"@polkadot/wasm-util": "6.0.2-12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/util": "^9.1.1"
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto-wasm authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { base64Decode, unzlibSync } from '@polkadot/wasm-util';
|
||||
|
||||
import { bytes, sizeUncompressed } from './cjs/bytes';
|
||||
import { base64Decode } from './base64';
|
||||
import { unzlibSync } from './fflate';
|
||||
|
||||
export { packageInfo } from './packageInfo';
|
||||
|
||||
|
||||
@@ -5,5 +5,7 @@
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"references": []
|
||||
"references": [
|
||||
{ "path": "../wasm-util/tsconfig.build.json" }
|
||||
]
|
||||
}
|
||||
|
||||
@@ -32,16 +32,16 @@
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.17.9",
|
||||
"@polkadot/wasm-bridge": "6.0.2-12",
|
||||
"@polkadot/wasm-crypto-asmjs": "6.0.2-12",
|
||||
"@polkadot/wasm-crypto-init": "6.0.2-12",
|
||||
"@polkadot/wasm-crypto-wasm": "6.0.2-12"
|
||||
"@polkadot/wasm-crypto-wasm": "6.0.2-12",
|
||||
"@polkadot/wasm-util": "6.0.2-12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/util": "^9.1.1",
|
||||
"@polkadot/x-randomvalues": "^9.1.1"
|
||||
"@polkadot/util": "^9.1.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "*",
|
||||
"@polkadot/x-randomvalues": "*"
|
||||
"@polkadot/util": "*"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
import type { CreatePromise, WasmCryptoInstance } from './types';
|
||||
|
||||
import { assert, stringToU8a, u8aToString } from '@polkadot/util';
|
||||
|
||||
type PopFirst<T extends unknown[]> =
|
||||
T extends [WasmCryptoInstance, ...infer N]
|
||||
? N
|
||||
: [];
|
||||
|
||||
interface Bridge {
|
||||
cachegetInt32: Int32Array | null;
|
||||
cachegetUint8: Uint8Array | null;
|
||||
type: 'asm' | 'wasm';
|
||||
wasm: WasmCryptoInstance | null;
|
||||
wasmPromise: CreatePromise | null;
|
||||
}
|
||||
|
||||
export const __bridge: Bridge = {
|
||||
cachegetInt32: null,
|
||||
cachegetUint8: null,
|
||||
type: 'wasm',
|
||||
wasm: null,
|
||||
wasmPromise: null
|
||||
};
|
||||
|
||||
export 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.');
|
||||
|
||||
return fn(__bridge.wasm, ...params) as ReturnType<F>;
|
||||
};
|
||||
}
|
||||
|
||||
export function getWasm (): WasmCryptoInstance {
|
||||
return __bridge.wasm!;
|
||||
}
|
||||
|
||||
export function getInt32 (): Int32Array {
|
||||
if (__bridge.cachegetInt32 === null || __bridge.cachegetInt32.buffer !== __bridge.wasm!.memory.buffer) {
|
||||
__bridge.cachegetInt32 = new Int32Array(__bridge.wasm!.memory.buffer);
|
||||
}
|
||||
|
||||
return __bridge.cachegetInt32;
|
||||
}
|
||||
|
||||
export function getUint8 (): Uint8Array {
|
||||
if (__bridge.cachegetUint8 === null || __bridge.cachegetUint8.buffer !== __bridge.wasm!.memory.buffer) {
|
||||
__bridge.cachegetUint8 = new Uint8Array(__bridge.wasm!.memory.buffer);
|
||||
}
|
||||
|
||||
return __bridge.cachegetUint8;
|
||||
}
|
||||
|
||||
export function getU8a (ptr: number, len: number): Uint8Array {
|
||||
return getUint8().subarray(ptr / 1, ptr / 1 + len);
|
||||
}
|
||||
|
||||
export function getString (ptr: number, len: number): string {
|
||||
return u8aToString(getU8a(ptr, len));
|
||||
}
|
||||
|
||||
export function allocU8a (arg: Uint8Array): [number, number] {
|
||||
const ptr = __bridge.wasm!.__wbindgen_malloc(arg.length * 1);
|
||||
|
||||
getUint8().set(arg, ptr / 1);
|
||||
|
||||
return [ptr, arg.length];
|
||||
}
|
||||
|
||||
export function allocString (arg: string): [number, number] {
|
||||
return allocU8a(stringToU8a(arg));
|
||||
}
|
||||
|
||||
export function resultU8a (): Uint8Array {
|
||||
const r0 = getInt32()[8 / 4 + 0];
|
||||
const r1 = getInt32()[8 / 4 + 1];
|
||||
const ret = getU8a(r0, r1).slice();
|
||||
|
||||
__bridge.wasm!.__wbindgen_free(r0, r1 * 1);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
export function resultString (): string {
|
||||
return u8aToString(resultU8a());
|
||||
}
|
||||
@@ -1,213 +1,229 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { __bridge, allocString, allocU8a, getWasm, resultString, resultU8a, withWasm } from './bridge';
|
||||
import { initWasm } from './init';
|
||||
import type { WasmCryptoInstance } from '@polkadot/wasm-crypto-init/types';
|
||||
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
import { bridge, initBase } from './init';
|
||||
|
||||
export { packageInfo } from './packageInfo';
|
||||
export { __bridge };
|
||||
export { bridge };
|
||||
|
||||
type PopFirst<T extends unknown[]> =
|
||||
T extends [WasmCryptoInstance, ...infer N]
|
||||
? N
|
||||
: [];
|
||||
|
||||
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.');
|
||||
|
||||
return fn(bridge.wasm, ...params) as ReturnType<F>;
|
||||
};
|
||||
}
|
||||
|
||||
export const bip39Generate = withWasm((wasm, words: 12 | 15 | 18 | 21 | 24): string => {
|
||||
wasm.ext_bip39_generate(8, words);
|
||||
|
||||
return resultString();
|
||||
return bridge.resultString();
|
||||
});
|
||||
|
||||
export const bip39ToEntropy = withWasm((wasm, phrase: string): Uint8Array => {
|
||||
wasm.ext_bip39_to_entropy(8, ...allocString(phrase));
|
||||
wasm.ext_bip39_to_entropy(8, ...bridge.allocString(phrase));
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const bip39ToMiniSecret = withWasm((wasm, phrase: string, password: string): Uint8Array => {
|
||||
wasm.ext_bip39_to_mini_secret(8, ...allocString(phrase), ...allocString(password));
|
||||
wasm.ext_bip39_to_mini_secret(8, ...bridge.allocString(phrase), ...bridge.allocString(password));
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const bip39ToSeed = withWasm((wasm, phrase: string, password: string): Uint8Array => {
|
||||
wasm.ext_bip39_to_seed(8, ...allocString(phrase), ...allocString(password));
|
||||
wasm.ext_bip39_to_seed(8, ...bridge.allocString(phrase), ...bridge.allocString(password));
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const bip39Validate = withWasm((wasm, phrase: string): boolean => {
|
||||
const ret = wasm.ext_bip39_validate(...allocString(phrase));
|
||||
const ret = wasm.ext_bip39_validate(...bridge.allocString(phrase));
|
||||
|
||||
return ret !== 0;
|
||||
});
|
||||
|
||||
export const ed25519KeypairFromSeed = withWasm((wasm, seed: Uint8Array): Uint8Array => {
|
||||
wasm.ext_ed_from_seed(8, ...allocU8a(seed));
|
||||
wasm.ext_ed_from_seed(8, ...bridge.allocU8a(seed));
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const ed25519Sign = withWasm((wasm, pubkey: Uint8Array, seckey: Uint8Array, message: Uint8Array): Uint8Array => {
|
||||
wasm.ext_ed_sign(8, ...allocU8a(pubkey), ...allocU8a(seckey), ...allocU8a(message));
|
||||
wasm.ext_ed_sign(8, ...bridge.allocU8a(pubkey), ...bridge.allocU8a(seckey), ...bridge.allocU8a(message));
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const ed25519Verify = withWasm((wasm, signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
|
||||
const ret = wasm.ext_ed_verify(...allocU8a(signature), ...allocU8a(message), ...allocU8a(pubkey));
|
||||
const ret = wasm.ext_ed_verify(...bridge.allocU8a(signature), ...bridge.allocU8a(message), ...bridge.allocU8a(pubkey));
|
||||
|
||||
return ret !== 0;
|
||||
});
|
||||
|
||||
export const secp256k1FromSeed = withWasm((wasm, seckey: Uint8Array): Uint8Array => {
|
||||
wasm.ext_secp_from_seed(8, ...allocU8a(seckey));
|
||||
wasm.ext_secp_from_seed(8, ...bridge.allocU8a(seckey));
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const secp256k1Compress = withWasm((wasm, pubkey: Uint8Array): Uint8Array => {
|
||||
wasm.ext_secp_pub_compress(8, ...allocU8a(pubkey));
|
||||
wasm.ext_secp_pub_compress(8, ...bridge.allocU8a(pubkey));
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const secp256k1Expand = withWasm((wasm, pubkey: Uint8Array): Uint8Array => {
|
||||
wasm.ext_secp_pub_expand(8, ...allocU8a(pubkey));
|
||||
wasm.ext_secp_pub_expand(8, ...bridge.allocU8a(pubkey));
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const secp256k1Recover = withWasm((wasm, msgHash: Uint8Array, sig: Uint8Array, recovery: number): Uint8Array => {
|
||||
wasm.ext_secp_recover(8, ...allocU8a(msgHash), ...allocU8a(sig), recovery);
|
||||
wasm.ext_secp_recover(8, ...bridge.allocU8a(msgHash), ...bridge.allocU8a(sig), recovery);
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const secp256k1Sign = withWasm((wasm, msgHash: Uint8Array, seckey: Uint8Array): Uint8Array => {
|
||||
wasm.ext_secp_sign(8, ...allocU8a(msgHash), ...allocU8a(seckey));
|
||||
wasm.ext_secp_sign(8, ...bridge.allocU8a(msgHash), ...bridge.allocU8a(seckey));
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const sr25519DeriveKeypairHard = withWasm((wasm, pair: Uint8Array, cc: Uint8Array): Uint8Array => {
|
||||
wasm.ext_sr_derive_keypair_hard(8, ...allocU8a(pair), ...allocU8a(cc));
|
||||
wasm.ext_sr_derive_keypair_hard(8, ...bridge.allocU8a(pair), ...bridge.allocU8a(cc));
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const sr25519DeriveKeypairSoft = withWasm((wasm, pair: Uint8Array, cc: Uint8Array): Uint8Array => {
|
||||
wasm.ext_sr_derive_keypair_soft(8, ...allocU8a(pair), ...allocU8a(cc));
|
||||
wasm.ext_sr_derive_keypair_soft(8, ...bridge.allocU8a(pair), ...bridge.allocU8a(cc));
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const sr25519DerivePublicSoft = withWasm((wasm, pubkey: Uint8Array, cc: Uint8Array): Uint8Array => {
|
||||
wasm.ext_sr_derive_public_soft(8, ...allocU8a(pubkey), ...allocU8a(cc));
|
||||
wasm.ext_sr_derive_public_soft(8, ...bridge.allocU8a(pubkey), ...bridge.allocU8a(cc));
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const sr25519KeypairFromSeed = withWasm((wasm, seed: Uint8Array): Uint8Array => {
|
||||
wasm.ext_sr_from_seed(8, ...allocU8a(seed));
|
||||
wasm.ext_sr_from_seed(8, ...bridge.allocU8a(seed));
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const sr25519Sign = withWasm((wasm, pubkey: Uint8Array, secret: Uint8Array, message: Uint8Array): Uint8Array => {
|
||||
wasm.ext_sr_sign(8, ...allocU8a(pubkey), ...allocU8a(secret), ...allocU8a(message));
|
||||
wasm.ext_sr_sign(8, ...bridge.allocU8a(pubkey), ...bridge.allocU8a(secret), ...bridge.allocU8a(message));
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const sr25519Verify = withWasm((wasm, signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
|
||||
const ret = wasm.ext_sr_verify(...allocU8a(signature), ...allocU8a(message), ...allocU8a(pubkey));
|
||||
const ret = wasm.ext_sr_verify(...bridge.allocU8a(signature), ...bridge.allocU8a(message), ...bridge.allocU8a(pubkey));
|
||||
|
||||
return ret !== 0;
|
||||
});
|
||||
|
||||
export const sr25519Agree = withWasm((wasm, pubkey: Uint8Array, secret: Uint8Array): Uint8Array => {
|
||||
wasm.ext_sr_agree(8, ...allocU8a(pubkey), ...allocU8a(secret));
|
||||
wasm.ext_sr_agree(8, ...bridge.allocU8a(pubkey), ...bridge.allocU8a(secret));
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const vrfSign = withWasm((wasm, secret: Uint8Array, context: Uint8Array, message: Uint8Array, extra: Uint8Array): Uint8Array => {
|
||||
wasm.ext_vrf_sign(8, ...allocU8a(secret), ...allocU8a(context), ...allocU8a(message), ...allocU8a(extra));
|
||||
wasm.ext_vrf_sign(8, ...bridge.allocU8a(secret), ...bridge.allocU8a(context), ...bridge.allocU8a(message), ...bridge.allocU8a(extra));
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const vrfVerify = withWasm((wasm, pubkey: Uint8Array, context: Uint8Array, message: Uint8Array, extra: Uint8Array, outAndProof: Uint8Array): boolean => {
|
||||
const ret = wasm.ext_vrf_verify(...allocU8a(pubkey), ...allocU8a(context), ...allocU8a(message), ...allocU8a(extra), ...allocU8a(outAndProof));
|
||||
const ret = wasm.ext_vrf_verify(...bridge.allocU8a(pubkey), ...bridge.allocU8a(context), ...bridge.allocU8a(message), ...bridge.allocU8a(extra), ...bridge.allocU8a(outAndProof));
|
||||
|
||||
return ret !== 0;
|
||||
});
|
||||
|
||||
export const blake2b = withWasm((wasm, data: Uint8Array, key: Uint8Array, size: number): Uint8Array => {
|
||||
wasm.ext_blake2b(8, ...allocU8a(data), ...allocU8a(key), size);
|
||||
wasm.ext_blake2b(8, ...bridge.allocU8a(data), ...bridge.allocU8a(key), size);
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const hmacSha256 = withWasm((wasm, key: Uint8Array, data: Uint8Array): Uint8Array => {
|
||||
wasm.ext_hmac_sha256(8, ...allocU8a(key), ...allocU8a(data));
|
||||
wasm.ext_hmac_sha256(8, ...bridge.allocU8a(key), ...bridge.allocU8a(data));
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const hmacSha512 = withWasm((wasm, key: Uint8Array, data: Uint8Array): Uint8Array => {
|
||||
wasm.ext_hmac_sha512(8, ...allocU8a(key), ...allocU8a(data));
|
||||
wasm.ext_hmac_sha512(8, ...bridge.allocU8a(key), ...bridge.allocU8a(data));
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const keccak256 = withWasm((wasm, data: Uint8Array): Uint8Array => {
|
||||
wasm.ext_keccak256(8, ...allocU8a(data));
|
||||
wasm.ext_keccak256(8, ...bridge.allocU8a(data));
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const keccak512 = withWasm((wasm, data: Uint8Array): Uint8Array => {
|
||||
wasm.ext_keccak512(8, ...allocU8a(data));
|
||||
wasm.ext_keccak512(8, ...bridge.allocU8a(data));
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const pbkdf2 = withWasm((wasm, data: Uint8Array, salt: Uint8Array, rounds: number): Uint8Array => {
|
||||
wasm.ext_pbkdf2(8, ...allocU8a(data), ...allocU8a(salt), rounds);
|
||||
wasm.ext_pbkdf2(8, ...bridge.allocU8a(data), ...bridge.allocU8a(salt), rounds);
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const scrypt = withWasm((wasm, password: Uint8Array, salt: Uint8Array, log2n: number, r: number, p: number): Uint8Array => {
|
||||
wasm.ext_scrypt(8, ...allocU8a(password), ...allocU8a(salt), log2n, r, p);
|
||||
wasm.ext_scrypt(8, ...bridge.allocU8a(password), ...bridge.allocU8a(salt), log2n, r, p);
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const sha256 = withWasm((wasm, data: Uint8Array): Uint8Array => {
|
||||
wasm.ext_sha256(8, ...allocU8a(data));
|
||||
wasm.ext_sha256(8, ...bridge.allocU8a(data));
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const sha512 = withWasm((wasm, data: Uint8Array): Uint8Array => {
|
||||
wasm.ext_sha512(8, ...allocU8a(data));
|
||||
wasm.ext_sha512(8, ...bridge.allocU8a(data));
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export const twox = withWasm((wasm, data: Uint8Array, rounds: number) => {
|
||||
wasm.ext_twox(8, ...allocU8a(data), rounds);
|
||||
wasm.ext_twox(8, ...bridge.allocU8a(data), rounds);
|
||||
|
||||
return resultU8a();
|
||||
return bridge.resultU8a();
|
||||
});
|
||||
|
||||
export function isReady (): boolean {
|
||||
return !!getWasm();
|
||||
return !!bridge.wasm;
|
||||
}
|
||||
|
||||
export async function waitReady (): Promise<boolean> {
|
||||
try {
|
||||
await initWasm();
|
||||
const wasm = await initBase();
|
||||
|
||||
return isReady();
|
||||
return !!wasm;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
// Copyright 2017-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { packageInfo as bridgeInfo } from '@polkadot/wasm-bridge/packageInfo';
|
||||
import { packageInfo as asmInfo } from '@polkadot/wasm-crypto-asmjs/packageInfo';
|
||||
import { packageInfo as initInfo } from '@polkadot/wasm-crypto-init/packageInfo';
|
||||
import { packageInfo as wasmInfo } from '@polkadot/wasm-crypto-wasm/packageInfo';
|
||||
import { packageInfo as utilInfo } from '@polkadot/wasm-util/packageInfo';
|
||||
|
||||
export default [asmInfo, initInfo, wasmInfo];
|
||||
export default [bridgeInfo, asmInfo, initInfo, wasmInfo, utilInfo];
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
import { getRandomValues } from '@polkadot/x-randomvalues';
|
||||
|
||||
import { getString, getU8a } from './bridge';
|
||||
|
||||
const DEFAULT_CRYPTO = { getRandomValues };
|
||||
const DEFAULT_SELF = { crypto: DEFAULT_CRYPTO };
|
||||
|
||||
const heap: Array<unknown> = new Array(32).fill(undefined).concat(undefined, null, true, false);
|
||||
let heapNext = heap.length;
|
||||
|
||||
function getObject (idx: number): unknown {
|
||||
return heap[idx];
|
||||
}
|
||||
|
||||
function dropObject (idx: number) {
|
||||
if (idx < 36) {
|
||||
return;
|
||||
}
|
||||
|
||||
heap[idx] = heapNext;
|
||||
heapNext = idx;
|
||||
}
|
||||
|
||||
function takeObject (idx: number): unknown {
|
||||
const ret = getObject(idx);
|
||||
|
||||
dropObject(idx);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
function addObject (obj: unknown): number {
|
||||
if (heapNext === heap.length) {
|
||||
heap.push(heap.length + 1);
|
||||
}
|
||||
|
||||
const idx = heapNext;
|
||||
|
||||
heapNext = heap[idx] as number;
|
||||
heap[idx] = obj;
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
export function __wbindgen_is_undefined (idx: number): boolean {
|
||||
return getObject(idx) === undefined;
|
||||
}
|
||||
|
||||
export function __wbindgen_throw (ptr: number, len: number): boolean {
|
||||
throw new Error(getString(ptr, len));
|
||||
}
|
||||
|
||||
export function __wbg_self_1b7a39e3a92c949c (): number {
|
||||
return addObject(DEFAULT_SELF);
|
||||
}
|
||||
|
||||
export function __wbg_require_604837428532a733 (ptr: number, len: number): never {
|
||||
throw new Error(`Unable to require ${getString(ptr, len)}`);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function __wbg_crypto_968f1772287e2df0 (_idx: number): number {
|
||||
return addObject(DEFAULT_CRYPTO);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function __wbg_getRandomValues_a3d34b4fee3c2869 (_idx: number): number {
|
||||
return addObject(DEFAULT_CRYPTO.getRandomValues);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function __wbg_getRandomValues_f5e14ab7ac8e995d (_arg0: number, ptr: number, len: number): void {
|
||||
DEFAULT_CRYPTO.getRandomValues(getU8a(ptr, len));
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function __wbg_randomFillSync_d5bd2d655fdf256a (_idx: number, _ptr: number, _len: number): never {
|
||||
throw new Error('randomFillsync is not available');
|
||||
|
||||
// getObject(idx).randomFillSync(getU8a(ptr, len));
|
||||
}
|
||||
|
||||
export function __wbindgen_object_drop_ref (idx: number): void {
|
||||
takeObject(idx);
|
||||
}
|
||||
|
||||
export function abort (): never {
|
||||
throw new Error('abort');
|
||||
}
|
||||
@@ -1,20 +1,14 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { CreatePromise, WasmCryptoInstance } from './types';
|
||||
import type { InitPromise } from '@polkadot/wasm-bridge/types';
|
||||
import type { WasmCryptoInstance } from '@polkadot/wasm-crypto-init/types';
|
||||
|
||||
import { Bridge, Wbg } from '@polkadot/wasm-bridge';
|
||||
import { init } from '@polkadot/wasm-crypto-init';
|
||||
|
||||
import { __bridge } from './bridge';
|
||||
import * as wbg from './imports';
|
||||
export const bridge = new Bridge<WasmCryptoInstance>((b) => ({ ...new Wbg(b) }), init);
|
||||
|
||||
export async function initWasm (initOverride?: (wbg: WebAssembly.ModuleImports) => CreatePromise): Promise<void> {
|
||||
if (!__bridge.wasmPromise || initOverride) {
|
||||
__bridge.wasmPromise = (initOverride || init)(wbg);
|
||||
}
|
||||
|
||||
const { type, wasm } = await __bridge.wasmPromise;
|
||||
|
||||
__bridge.type = type;
|
||||
__bridge.wasm = wasm as WasmCryptoInstance;
|
||||
export async function initBase (override?: (wbg: WebAssembly.ModuleImports) => InitPromise<WasmCryptoInstance>): Promise<WasmCryptoInstance | null> {
|
||||
return bridge.init(override);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
|
||||
import { init } from '@polkadot/wasm-crypto-init/none';
|
||||
|
||||
import { initWasm } from './init';
|
||||
import { initBase } from './init';
|
||||
|
||||
initWasm(init).catch(undefined);
|
||||
export async function initWasm (): Promise<void> {
|
||||
await initBase(init);
|
||||
}
|
||||
|
||||
initWasm().catch(undefined);
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
|
||||
import { init } from '@polkadot/wasm-crypto-init/asm';
|
||||
|
||||
import { initWasm } from './init';
|
||||
import { initBase } from './init';
|
||||
|
||||
initWasm(init).catch(undefined);
|
||||
export async function initWasm (): Promise<void> {
|
||||
await initBase(init);
|
||||
}
|
||||
|
||||
initWasm().catch(undefined);
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
|
||||
import { init } from '@polkadot/wasm-crypto-init/wasm';
|
||||
|
||||
import { initWasm } from './init';
|
||||
import { initBase } from './init';
|
||||
|
||||
initWasm(init).catch(undefined);
|
||||
export async function initWasm (): Promise<void> {
|
||||
await initBase(init);
|
||||
}
|
||||
|
||||
initWasm().catch(undefined);
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
|
||||
import { init } from '@polkadot/wasm-crypto-init/both';
|
||||
|
||||
import { initWasm } from './init';
|
||||
import { initBase } from './init';
|
||||
|
||||
initWasm(init).catch(undefined);
|
||||
export async function initWasm (): Promise<void> {
|
||||
await initBase(init);
|
||||
}
|
||||
|
||||
initWasm().catch(undefined);
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { InitResult } from '@polkadot/wasm-crypto-init/types';
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
// wasm-pack build output (formatted) from pkg/wasm_bg.d.ts
|
||||
export interface WasmCryptoInstance {
|
||||
memory: WebAssembly.Memory;
|
||||
|
||||
// wbindgen functions (required and used internally)
|
||||
|
||||
__wbindgen_free(a: number, b: number): void;
|
||||
|
||||
__wbindgen_malloc(a: number): number;
|
||||
|
||||
__wbindgen_realloc(a: number, b: number, c: number): number;
|
||||
|
||||
__wbindgen_exn_store(a: number): void;
|
||||
|
||||
// exposed functions
|
||||
|
||||
ext_bip39_generate(resLen: 8, words: number): void;
|
||||
|
||||
ext_bip39_to_entropy(resLen: 8, ptrPhrase: number, lenPhrase: number): void;
|
||||
|
||||
ext_bip39_to_mini_secret(resLen: 8, ptrPhrase: number, lenPhrase: number, ptrPass: number, lenPass: number): void;
|
||||
|
||||
ext_bip39_to_seed(resLen: 8, ptrPhrase: number, lenPhrase: number, ptrPass: number, lenPass: number): void;
|
||||
|
||||
ext_bip39_validate(ptrPhrase: number, lenPhrase: number): number;
|
||||
|
||||
ext_ed_from_seed(resLen: 8, ptrSeed: number, lenSeed: number): void;
|
||||
|
||||
ext_ed_sign(resLen: 8, ptrPub: number, lenPub: number, ptrSec: number, lenSec: number, ptrMsg: number, lenMsg: number): void;
|
||||
|
||||
ext_ed_verify(ptrSig: number, lenSig: number, ptrMsg: number, lenMsg: number, ptrPub: number, lenPub: number): number;
|
||||
|
||||
ext_blake2b(resLen: 8, ptrData: number, lenData: number, ptrKey: number, lenKey: number, size: number): void;
|
||||
|
||||
ext_hmac_sha256(resLen: 8, ptrKey: number, lenKey: number, ptrData: number, lenData: number): void;
|
||||
|
||||
ext_hmac_sha512(resLen: 8, ptrKey: number, lenKey: number, ptrData: number, lenData: number): void;
|
||||
|
||||
ext_keccak256(resLen: 8, ptrData: number, lenData: number): void;
|
||||
|
||||
ext_keccak512(resLen: 8, ptrData: number, lenData: number): void;
|
||||
|
||||
ext_pbkdf2(resLen: 8, ptrData: number, lenData: number, ptrSalt: number, lenSalt: number, rounds: number): void;
|
||||
|
||||
ext_scrypt(resLen: 8, ptrPass: number, lenPass: number, ptrSalt: number, lenSalt: number, log2n: number, r: number, p: number): void;
|
||||
|
||||
ext_sha256(resLen: 8, ptrData: number, lenData: number): void;
|
||||
|
||||
ext_sha512(resLen: 8, ptrData: number, lenData: number): void;
|
||||
|
||||
ext_twox(resLen: 8, ptrData: number, lenData: number, rounds: number): void;
|
||||
|
||||
ext_secp_from_seed(reslen: 8, ptrSec: number, lenSec: number): void;
|
||||
|
||||
ext_secp_pub_compress(resLen: 8, ptrPub: number, lenPub: number): void;
|
||||
|
||||
ext_secp_pub_expand(resLen: 8, ptrPub: number, lenPub: number): void;
|
||||
|
||||
ext_secp_recover(resLen: 8, ptrMsgHash: number, lenMsgHash: number, ptrSig: number, lenSig: number, recovery: number): void;
|
||||
|
||||
ext_secp_sign(resLen: 8, ptrMsgHash: number, lenMsgHash: number, ptrSec: number, lenSec: number): void;
|
||||
|
||||
ext_sr_derive_keypair_hard(resLen: 8, ptrPair: number, lenPair: number, ptrCc: number, lenCc: number): void;
|
||||
|
||||
ext_sr_derive_keypair_soft(resLen: 8, ptrPub: number, lenPub: number, ptrCc: number, lenCc: number): void;
|
||||
|
||||
ext_sr_derive_public_soft(resLen: 8, ptrPub: number, lenPub: number, ptrCc: number, lenCc: number): void;
|
||||
|
||||
ext_sr_from_seed(resLen: 8, ptrSeed: number, lenSeed: number): void;
|
||||
|
||||
ext_sr_sign(resLen: 8, ptrPub: number, lenPub: number, ptrSec: number, lenSec: number, ptrMsg: number, lenMsg: number): void;
|
||||
|
||||
ext_sr_verify(ptrSig: number, lenSig: number, ptrMsg: number, lenMsg: number, ptrPub: number, lenPub: number): number;
|
||||
|
||||
ext_sr_agree(resLen: 8, ptrPub: number, lenPub: number, ptrSec: number, lenSec: number): void;
|
||||
|
||||
ext_vrf_sign(resLen: 8, ptrSec: number, lenSec: number, ptrCtx: number, lenCtx: number, ptrMsg: number, lenMsg: number, ptrExtra: number, lenExtra: number): void;
|
||||
|
||||
ext_vrf_verify(ptrPub: number, lenPub: number, ptrCtx: number, lenCtx: number, ptrMsg: number, lenMsg: number, ptrExtra: number, lenExtra: number, ptrProof: number, lenProof: number): number;
|
||||
}
|
||||
|
||||
export type AsmCreator = (wbg: Record<string, WebAssembly.ImportValue>) => WasmCryptoInstance;
|
||||
|
||||
export type CreatePromise = Promise<InitResult>;
|
||||
@@ -2,10 +2,12 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const rootIncl = [
|
||||
'@polkadot/wasm-bridge',
|
||||
'@polkadot/wasm-crypto',
|
||||
'@polkadot/wasm-crypto-init',
|
||||
'@polkadot/wasm-crypto-asmjs',
|
||||
'@polkadot/wasm-crypto-wasm'
|
||||
'@polkadot/wasm-crypto-wasm',
|
||||
'@polkadot/wasm-util'
|
||||
];
|
||||
|
||||
const detcIncl = [
|
||||
|
||||
@@ -26,9 +26,9 @@ const tests = {
|
||||
async function beforeAll (name) {
|
||||
const result = await wasm.waitReady();
|
||||
|
||||
console.log(`*** waitReady()=${result} for ${wasm.__bridge.type}`);
|
||||
console.log(`*** waitReady()=${result} for ${wasm.bridge.type}`);
|
||||
|
||||
assert(name.toLowerCase() === wasm.__bridge.type, `Incorrect environment laucnhed, expected ${name.toLowerCase()}, found ${wasm.__bridge.type}`);
|
||||
assert(name.toLowerCase() === wasm.bridge.type, `Incorrect environment laucnhed, expected ${name.toLowerCase()}, found ${wasm.bridge.type}`);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"references": [
|
||||
{ "path": "../wasm-bridge/tsconfig.build.json" },
|
||||
{ "path": "../wasm-crypto-init/tsconfig.build.json" },
|
||||
{ "path": "../wasm-crypto-asmjs/tsconfig.build.json" },
|
||||
{ "path": "../wasm-crypto-wasm/tsconfig.build.json" }
|
||||
{ "path": "../wasm-crypto-wasm/tsconfig.build.json" },
|
||||
{ "path": "../wasm-util/tsconfig.build.json" }
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
## @polkadot/wasm-util
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"bugs": "https://github.com/polkadot-js/wasm/issues",
|
||||
"contributors": [],
|
||||
"description": "Utilities used exclusively inside Wasm decoding",
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/wasm/tree/master/packages/wasm-util#readme",
|
||||
"license": "Apache-2.0",
|
||||
"maintainers": [],
|
||||
"name": "@polkadot/wasm-util",
|
||||
"repository": {
|
||||
"directory": "packages/wasm-util",
|
||||
"type": "git",
|
||||
"url": "https://github.com/polkadot-js/wasm.git"
|
||||
},
|
||||
"sideEffects": [
|
||||
"./detectPackage.js",
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "6.0.2-12",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.17.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/util": "^9.1.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "*"
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { base64Decode } from './base64';
|
||||
export { unzlibSync } from './fflate';
|
||||
export { packageInfo } from './packageInfo';
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { packageInfo as utilInfo } from '@polkadot/wasm-util/packageInfo';
|
||||
|
||||
export default [utilInfo];
|
||||
@@ -0,0 +1,11 @@
|
||||
// Copyright 2017-2022 @polkadot/wasm-util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
import { detectPackage } from '@polkadot/util';
|
||||
|
||||
import others from './detectOther';
|
||||
import { packageInfo } from './packageInfo';
|
||||
|
||||
detectPackage(packageInfo, null, others);
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
|
||||
// Copyright 2019-2022 @polkadot/wasm-util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// MIT License
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2019-2022 @polkadot/wasm-util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import './detectPackage';
|
||||
|
||||
export * from './bundle';
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2017-2022 @polkadot/wasm-util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/wasm-util', path: 'auto', type: 'auto', version: '6.0.2-12' };
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "..",
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"references": []
|
||||
}
|
||||
+14
-8
@@ -12,15 +12,21 @@ const external = [
|
||||
'@polkadot/util'
|
||||
];
|
||||
|
||||
const overrides = {
|
||||
'@polkadot/wasm-crypto': {
|
||||
entries: {
|
||||
'@polkadot/wasm-crypto-init': '../../wasm-crypto-init/build',
|
||||
'@polkadot/wasm-crypto-asmjs': '../../../wasm-crypto-asmjs/build',
|
||||
'@polkadot/wasm-crypto-wasm': '../../../wasm-crypto-wasm/build',
|
||||
const overrides = pkgs
|
||||
.map((n) => n.replace('@polkadot/wasm-', ''))
|
||||
.reduce((map, n) => ({
|
||||
...map,
|
||||
[`@polkadot/wasm-${n}`]: {
|
||||
entries: [
|
||||
'bridge',
|
||||
'util',
|
||||
...['init', 'asmjs', 'wasm'].map((p) => `${n}-${p}`)
|
||||
].reduce((all, p) => ({
|
||||
...all,
|
||||
[`@polkadot/wasm-${p}`]: `../../wasm-${p}/build/bundle.js`
|
||||
}), {})
|
||||
}
|
||||
}
|
||||
};
|
||||
}), {});
|
||||
|
||||
export default pkgs.map((pkg) =>
|
||||
createBundle({
|
||||
|
||||
+8
-9
@@ -3,18 +3,17 @@
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"paths": {
|
||||
"@polkadot/wasm-crypto-asmjs/packageInfo": ["wasm-crypto-asmjs/src/packageInfo"],
|
||||
"@polkadot/wasm-bridge": ["wasm-bridge/src"],
|
||||
"@polkadot/wasm-bridge/*": ["wasm-bridge/src/*"],
|
||||
"@polkadot/wasm-crypto-asmjs": ["wasm-crypto-asmjs/src"],
|
||||
"@polkadot/wasm-crypto-wasm/packageInfo": ["wasm-crypto-wasm/src/packageInfo"],
|
||||
"@polkadot/wasm-crypto-asmjs/*": ["wasm-crypto-asmjs/src/*"],
|
||||
"@polkadot/wasm-crypto-wasm": ["wasm-crypto-wasm/src"],
|
||||
"@polkadot/wasm-crypto-init/asm": ["wasm-crypto-init/src/asm"],
|
||||
"@polkadot/wasm-crypto-init/both": ["wasm-crypto-init/src/both"],
|
||||
"@polkadot/wasm-crypto-init/none": ["wasm-crypto-init/src/none"],
|
||||
"@polkadot/wasm-crypto-init/wasm": ["wasm-crypto-init/src/wasm"],
|
||||
"@polkadot/wasm-crypto-init/types": ["wasm-crypto-init/src/types"],
|
||||
"@polkadot/wasm-crypto-init/packageInfo": ["wasm-crypto-init/src/packageInfo"],
|
||||
"@polkadot/wasm-crypto-wasm/*": ["wasm-crypto-wasm/src/*"],
|
||||
"@polkadot/wasm-crypto-init": ["wasm-crypto-init/src/wasm"],
|
||||
"@polkadot/wasm-crypto": ["wasm-crypto/src"]
|
||||
"@polkadot/wasm-crypto-init/*": ["wasm-crypto-init/src/*"],
|
||||
"@polkadot/wasm-crypto": ["wasm-crypto/src"],
|
||||
"@polkadot/wasm-util": ["wasm-util/src"],
|
||||
"@polkadot/wasm-util/*": ["wasm-util/src/*"],
|
||||
},
|
||||
"skipLibCheck": true
|
||||
}
|
||||
|
||||
+2
-1
@@ -7,6 +7,7 @@
|
||||
{ "path": "./packages/wasm-crypto/tsconfig.build.json" },
|
||||
{ "path": "./packages/wasm-crypto-init/tsconfig.build.json" },
|
||||
{ "path": "./packages/wasm-crypto-asmjs/tsconfig.build.json" },
|
||||
{ "path": "./packages/wasm-crypto-wasm/tsconfig.build.json" }
|
||||
{ "path": "./packages/wasm-crypto-wasm/tsconfig.build.json" },
|
||||
{ "path": "./packages/wasm-util/tsconfig.build.json" }
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1923,9 +1923,9 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/dev@npm:^0.66.20":
|
||||
version: 0.66.20
|
||||
resolution: "@polkadot/dev@npm:0.66.20"
|
||||
"@polkadot/dev@npm:^0.66.21":
|
||||
version: 0.66.21
|
||||
resolution: "@polkadot/dev@npm:0.66.21"
|
||||
dependencies:
|
||||
"@babel/cli": ^7.17.10
|
||||
"@babel/core": ^7.17.10
|
||||
@@ -1971,7 +1971,7 @@ __metadata:
|
||||
eslint-plugin-simple-import-sort: ^7.0.0
|
||||
eslint-plugin-sort-destructure-keys: ^1.4.0
|
||||
fs-extra: ^10.1.0
|
||||
gh-pages: ^3.2.3
|
||||
gh-pages: ^4.0.0
|
||||
gh-release: ^6.0.4
|
||||
glob: ^8.0.1
|
||||
glob2base: ^0.0.12
|
||||
@@ -1989,7 +1989,7 @@ __metadata:
|
||||
rollup: ^2.72.1
|
||||
rollup-plugin-cleanup: ^3.2.1
|
||||
typescript: ^4.6.4
|
||||
yargs: ^17.4.1
|
||||
yargs: ^17.5.0
|
||||
bin:
|
||||
polkadot-ci-ghact-build: scripts/polkadot-ci-ghact-build.mjs
|
||||
polkadot-ci-ghact-docs: scripts/polkadot-ci-ghact-docs.mjs
|
||||
@@ -2012,7 +2012,7 @@ __metadata:
|
||||
polkadot-exec-rollup: scripts/polkadot-exec-rollup.mjs
|
||||
polkadot-exec-tsc: scripts/polkadot-exec-tsc.mjs
|
||||
polkadot-exec-webpack: scripts/polkadot-exec-webpack.mjs
|
||||
checksum: 0106f37f7dc024a7f35873e2abe46e222b31bec064a27f1668c256ef123557df79fcf3e0be6abcfb817a5e70cc58093c9edc4244afa37f494db77176426e2f92
|
||||
checksum: cb6ccd29809128a997dd30b866b949dba19170a6ed1e9bcfee5450e52ec67e9b6d8a47b7640f407771037a092f0e6a3938bc4993c80fb53f75b67fa9f0338766
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -2032,6 +2032,19 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/wasm-bridge@6.0.2-12, @polkadot/wasm-bridge@workspace:packages/wasm-bridge":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@polkadot/wasm-bridge@workspace:packages/wasm-bridge"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.17.9
|
||||
"@polkadot/util": ^9.1.1
|
||||
"@polkadot/x-randomvalues": ^9.1.1
|
||||
peerDependencies:
|
||||
"@polkadot/util": "*"
|
||||
"@polkadot/x-randomvalues": "*"
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@polkadot/wasm-crypto-asmjs@6.0.2-12, @polkadot/wasm-crypto-asmjs@workspace:packages/wasm-crypto-asmjs":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@polkadot/wasm-crypto-asmjs@workspace:packages/wasm-crypto-asmjs"
|
||||
@@ -2049,6 +2062,7 @@ __metadata:
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.17.9
|
||||
"@polkadot/util": ^9.1.1
|
||||
"@polkadot/wasm-bridge": 6.0.2-12
|
||||
"@polkadot/wasm-crypto-asmjs": 6.0.2-12
|
||||
"@polkadot/wasm-crypto-wasm": 6.0.2-12
|
||||
peerDependencies:
|
||||
@@ -2062,6 +2076,7 @@ __metadata:
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.17.9
|
||||
"@polkadot/util": ^9.1.1
|
||||
"@polkadot/wasm-util": 6.0.2-12
|
||||
peerDependencies:
|
||||
"@polkadot/util": "*"
|
||||
languageName: unknown
|
||||
@@ -2073,13 +2088,24 @@ __metadata:
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.17.9
|
||||
"@polkadot/util": ^9.1.1
|
||||
"@polkadot/wasm-bridge": 6.0.2-12
|
||||
"@polkadot/wasm-crypto-asmjs": 6.0.2-12
|
||||
"@polkadot/wasm-crypto-init": 6.0.2-12
|
||||
"@polkadot/wasm-crypto-wasm": 6.0.2-12
|
||||
"@polkadot/x-randomvalues": ^9.1.1
|
||||
"@polkadot/wasm-util": 6.0.2-12
|
||||
peerDependencies:
|
||||
"@polkadot/util": "*"
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@polkadot/wasm-util@6.0.2-12, @polkadot/wasm-util@workspace:packages/wasm-util":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@polkadot/wasm-util@workspace:packages/wasm-util"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.17.9
|
||||
"@polkadot/util": ^9.1.1
|
||||
peerDependencies:
|
||||
"@polkadot/util": "*"
|
||||
"@polkadot/x-randomvalues": "*"
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
@@ -5209,9 +5235,9 @@ fsevents@~2.1.2:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"gh-pages@npm:^3.2.3":
|
||||
version: 3.2.3
|
||||
resolution: "gh-pages@npm:3.2.3"
|
||||
"gh-pages@npm:^4.0.0":
|
||||
version: 4.0.0
|
||||
resolution: "gh-pages@npm:4.0.0"
|
||||
dependencies:
|
||||
async: ^2.6.1
|
||||
commander: ^2.18.0
|
||||
@@ -5223,7 +5249,7 @@ fsevents@~2.1.2:
|
||||
bin:
|
||||
gh-pages: bin/gh-pages.js
|
||||
gh-pages-clean: bin/gh-pages-clean.js
|
||||
checksum: 0a6e92180ce8fac6f244403d1c8af6d004615b96c7bafdc25da0022eab34f84470895587c618d440ae77b4b4ce1c1b85442ddf3184f53a522f87974da5a41760
|
||||
checksum: 255648eb272104465586393be8a3112d928916a6b35b2b3ffc202c1e55b1c25b1e54e4b5fe83afbf1b1f8e7d37521c0d7b9c7b3db9ff899474db710581662154
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -8503,7 +8529,7 @@ resolve@^2.0.0-next.3:
|
||||
resolution: "root-workspace-0b6124@workspace:."
|
||||
dependencies:
|
||||
"@babel/core": ^7.17.10
|
||||
"@polkadot/dev": ^0.66.20
|
||||
"@polkadot/dev": ^0.66.21
|
||||
fflate: ^0.7.3
|
||||
override-require: ^1.1.1
|
||||
languageName: unknown
|
||||
@@ -9813,9 +9839,9 @@ resolve@^2.0.0-next.3:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"yargs@npm:^17.0.0, yargs@npm:^17.3.1, yargs@npm:^17.4.1":
|
||||
version: 17.4.1
|
||||
resolution: "yargs@npm:17.4.1"
|
||||
"yargs@npm:^17.0.0, yargs@npm:^17.3.1, yargs@npm:^17.5.0":
|
||||
version: 17.5.0
|
||||
resolution: "yargs@npm:17.5.0"
|
||||
dependencies:
|
||||
cliui: ^7.0.2
|
||||
escalade: ^3.1.1
|
||||
@@ -9824,6 +9850,6 @@ resolve@^2.0.0-next.3:
|
||||
string-width: ^4.2.3
|
||||
y18n: ^5.0.5
|
||||
yargs-parser: ^21.0.0
|
||||
checksum: e9012322870d7e4e912a6ae1f63b203e365f911c0cf158be92c36edefddfb3bd38ce17eb9ef0d18858a4777f047c50589ea22dacb44bd949169ba37dc6d34bee
|
||||
checksum: e2c662a7a63aa125a162cc0d77e38bdfe2a0dd5121a0d485a464499cd7782c5198b57103aed4608df96a017d01cb6a834bc22d4a1f20b92649fa82983d53522b
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
Reference in New Issue
Block a user