@polkadot/wasm-bridge
Advanced tools
Comparing version 6.1.2-6 to 6.1.2-7
import type { BridgeBase, InitFn, WasmBaseInstance } from './types'; | ||
/** | ||
* @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 declare class Bridge<C extends WasmBaseInstance> implements BridgeBase<C> { | ||
#private; | ||
constructor(createWasm: InitFn<C>); | ||
/** @description Returns the init error */ | ||
get error(): string | null; | ||
/** @description Returns the init type */ | ||
get type(): 'asm' | 'wasm' | 'none'; | ||
/** @description Returns the created wbg interface */ | ||
get wbg(): WebAssembly.ModuleImports; | ||
/** @description Returns the created wasm interface */ | ||
get wasm(): C | null; | ||
/** @description Performs the wasm initialization */ | ||
init(createWasm?: InitFn<C>): Promise<C | null>; | ||
/** @description Gets an object from the heap */ | ||
getObject(idx: number): unknown; | ||
/** @description Removes an object from the heap */ | ||
dropObject(idx: number): void; | ||
/** @description Retrieves and removes an object to the heap */ | ||
takeObject(idx: number): unknown; | ||
/** @description Adds an object to the heap */ | ||
addObject(obj: unknown): number; | ||
/** @description Retrieve an Int32 in the WASM interface */ | ||
getInt32(): Int32Array; | ||
/** @description Retrieve an Uint8Array in the WASM interface */ | ||
getUint8(): Uint8Array; | ||
/** @description Retrieves an Uint8Array in the WASM interface */ | ||
getU8a(ptr: number, len: number): Uint8Array; | ||
/** @description Retrieves a string in the WASM interface */ | ||
getString(ptr: number, len: number): string; | ||
/** @description Allocates an Uint8Array in the WASM interface */ | ||
allocU8a(arg: Uint8Array): [number, number]; | ||
/** @description Allocates a string in the WASM interface */ | ||
allocString(arg: string): [number, number]; | ||
/** @description Retrieves an Uint8Array from the WASM interface */ | ||
resultU8a(): Uint8Array; | ||
/** @description Retrieve a string from the WASM interface */ | ||
resultString(): string; | ||
} |
// 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 | ||
@@ -7,2 +11,12 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
import { Wbg } from "./wbg.js"; | ||
/** | ||
* @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 { | ||
@@ -33,19 +47,29 @@ #cachegetInt32; | ||
} | ||
/** @description Returns the init error */ | ||
get error() { | ||
return this.#wasmError; | ||
} | ||
/** @description Returns the init type */ | ||
get type() { | ||
return this.#type; | ||
} | ||
/** @description Returns the created wbg interface */ | ||
get wbg() { | ||
return this.#wbg; | ||
} | ||
/** @description Returns the created wasm interface */ | ||
get wasm() { | ||
return this.#wasm; | ||
} | ||
/** @description Performs the wasm initialization */ | ||
async init(createWasm) { | ||
@@ -66,7 +90,11 @@ if (!this.#wasmPromise || createWasm) { | ||
} | ||
/** @description Gets an object from the heap */ | ||
getObject(idx) { | ||
return this.#heap[idx]; | ||
} | ||
/** @description Removes an object from the heap */ | ||
dropObject(idx) { | ||
@@ -80,3 +108,5 @@ if (idx < 36) { | ||
} | ||
/** @description Retrieves and removes an object to the heap */ | ||
takeObject(idx) { | ||
@@ -87,3 +117,5 @@ const ret = this.getObject(idx); | ||
} | ||
/** @description Adds an object to the heap */ | ||
addObject(obj) { | ||
@@ -99,3 +131,5 @@ if (this.#heapNext === this.#heap.length) { | ||
} | ||
/** @description Retrieve an Int32 in the WASM interface */ | ||
getInt32() { | ||
@@ -108,3 +142,5 @@ if (this.#cachegetInt32 === null || this.#cachegetInt32.buffer !== this.#wasm.memory.buffer) { | ||
} | ||
/** @description Retrieve an Uint8Array in the WASM interface */ | ||
getUint8() { | ||
@@ -117,11 +153,17 @@ if (this.#cachegetUint8 === null || this.#cachegetUint8.buffer !== this.#wasm.memory.buffer) { | ||
} | ||
/** @description Retrieves an Uint8Array in the WASM interface */ | ||
getU8a(ptr, len) { | ||
return this.getUint8().subarray(ptr / 1, ptr / 1 + len); | ||
} | ||
/** @description Retrieves a string in the WASM interface */ | ||
getString(ptr, len) { | ||
return u8aToString(this.getU8a(ptr, len)); | ||
} | ||
/** @description Allocates an Uint8Array in the WASM interface */ | ||
allocU8a(arg) { | ||
@@ -133,7 +175,11 @@ const ptr = this.#wasm.__wbindgen_malloc(arg.length * 1); | ||
} | ||
/** @description Allocates a string in the WASM interface */ | ||
allocString(arg) { | ||
return this.allocU8a(stringToU8a(arg)); | ||
} | ||
/** @description Retrieves an Uint8Array from the WASM interface */ | ||
resultU8a() { | ||
@@ -148,3 +194,5 @@ const r0 = this.getInt32()[8 / 4 + 0]; | ||
} | ||
/** @description Retrieve a string from the WASM interface */ | ||
resultString() { | ||
@@ -151,0 +199,0 @@ return u8aToString(this.resultU8a()); |
export * from './bridge'; | ||
export * from './init'; | ||
export * from './wbg'; |
// Copyright 2019-2022 @polkadot/wasm-bridge authors & contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
export * from "./bridge.js"; | ||
export * from "./init.js"; | ||
export * from "./wbg.js"; | ||
export * from "./init.js"; |
@@ -14,4 +14,18 @@ "use strict"; | ||
// 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 */ | ||
/** | ||
* @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. | ||
*/ | ||
class Bridge { | ||
@@ -42,19 +56,29 @@ #cachegetInt32; | ||
} | ||
/** @description Returns the init error */ | ||
get error() { | ||
return this.#wasmError; | ||
} | ||
/** @description Returns the init type */ | ||
get type() { | ||
return this.#type; | ||
} | ||
/** @description Returns the created wbg interface */ | ||
get wbg() { | ||
return this.#wbg; | ||
} | ||
/** @description Returns the created wasm interface */ | ||
get wasm() { | ||
return this.#wasm; | ||
} | ||
/** @description Performs the wasm initialization */ | ||
async init(createWasm) { | ||
@@ -75,7 +99,11 @@ if (!this.#wasmPromise || createWasm) { | ||
} | ||
/** @description Gets an object from the heap */ | ||
getObject(idx) { | ||
return this.#heap[idx]; | ||
} | ||
/** @description Removes an object from the heap */ | ||
dropObject(idx) { | ||
@@ -89,3 +117,5 @@ if (idx < 36) { | ||
} | ||
/** @description Retrieves and removes an object to the heap */ | ||
takeObject(idx) { | ||
@@ -96,3 +126,5 @@ const ret = this.getObject(idx); | ||
} | ||
/** @description Adds an object to the heap */ | ||
addObject(obj) { | ||
@@ -108,3 +140,5 @@ if (this.#heapNext === this.#heap.length) { | ||
} | ||
/** @description Retrieve an Int32 in the WASM interface */ | ||
getInt32() { | ||
@@ -117,3 +151,5 @@ if (this.#cachegetInt32 === null || this.#cachegetInt32.buffer !== this.#wasm.memory.buffer) { | ||
} | ||
/** @description Retrieve an Uint8Array in the WASM interface */ | ||
getUint8() { | ||
@@ -126,11 +162,17 @@ if (this.#cachegetUint8 === null || this.#cachegetUint8.buffer !== this.#wasm.memory.buffer) { | ||
} | ||
/** @description Retrieves an Uint8Array in the WASM interface */ | ||
getU8a(ptr, len) { | ||
return this.getUint8().subarray(ptr / 1, ptr / 1 + len); | ||
} | ||
/** @description Retrieves a string in the WASM interface */ | ||
getString(ptr, len) { | ||
return (0, _util.u8aToString)(this.getU8a(ptr, len)); | ||
} | ||
/** @description Allocates an Uint8Array in the WASM interface */ | ||
allocU8a(arg) { | ||
@@ -142,7 +184,11 @@ const ptr = this.#wasm.__wbindgen_malloc(arg.length * 1); | ||
} | ||
/** @description Allocates a string in the WASM interface */ | ||
allocString(arg) { | ||
return this.allocU8a((0, _util.stringToU8a)(arg)); | ||
} | ||
/** @description Retrieves an Uint8Array from the WASM interface */ | ||
resultU8a() { | ||
@@ -157,3 +203,5 @@ const r0 = this.getInt32()[8 / 4 + 0]; | ||
} | ||
/** @description Retrieve a string from the WASM interface */ | ||
resultString() { | ||
@@ -160,0 +208,0 @@ return (0, _util.u8aToString)(this.resultU8a()); |
@@ -31,15 +31,2 @@ "use strict"; | ||
}); | ||
}); | ||
var _wbg = require("./wbg"); | ||
Object.keys(_wbg).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (key in exports && exports[key] === _wbg[key]) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _wbg[key]; | ||
} | ||
}); | ||
}); |
@@ -12,2 +12,11 @@ "use strict"; | ||
// SPDX-License-Identifier: Apache-2.0 | ||
/** | ||
* @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. | ||
*/ | ||
function createWasmFn(root, wasmBytes, asmFn) { | ||
@@ -14,0 +23,0 @@ return async wbg => { |
@@ -14,4 +14,4 @@ "use strict"; | ||
type: 'cjs', | ||
version: '6.1.2-6' | ||
version: '6.1.2-7' | ||
}; | ||
exports.packageInfo = packageInfo; |
@@ -18,2 +18,12 @@ "use strict"; | ||
}; | ||
/** | ||
* @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. | ||
*/ | ||
@@ -26,30 +36,48 @@ class Wbg { | ||
} | ||
/** @internal */ | ||
abort = () => { | ||
throw new Error('abort'); | ||
}; | ||
/** @internal */ | ||
__wbindgen_is_undefined = idx => { | ||
return this.#bridge.getObject(idx) === undefined; | ||
}; | ||
/** @internal */ | ||
__wbindgen_throw = (ptr, len) => { | ||
throw new Error(this.#bridge.getString(ptr, len)); | ||
}; | ||
/** @internal */ | ||
__wbg_self_1b7a39e3a92c949c = () => { | ||
return this.#bridge.addObject(DEFAULT_SELF); | ||
}; | ||
/** @internal */ | ||
__wbg_require_604837428532a733 = (ptr, len) => { | ||
throw new Error(`Unable to require ${this.#bridge.getString(ptr, len)}`); | ||
}; // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
}; | ||
/** @internal */ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
__wbg_crypto_968f1772287e2df0 = _idx => { | ||
return this.#bridge.addObject(DEFAULT_CRYPTO); | ||
}; // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
}; | ||
/** @internal */ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
__wbg_getRandomValues_a3d34b4fee3c2869 = _idx => { | ||
return this.#bridge.addObject(DEFAULT_CRYPTO.getRandomValues); | ||
}; // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
}; | ||
/** @internal */ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
__wbg_getRandomValues_f5e14ab7ac8e995d = (_arg0, ptr, len) => { | ||
DEFAULT_CRYPTO.getRandomValues(this.#bridge.getU8a(ptr, len)); | ||
}; // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
}; | ||
/** @internal */ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
@@ -59,2 +87,4 @@ __wbg_randomFillSync_d5bd2d655fdf256a = (_idx, _ptr, _len) => { | ||
}; | ||
/** @internal */ | ||
__wbindgen_object_drop_ref = idx => { | ||
@@ -61,0 +91,0 @@ this.#bridge.takeObject(idx); |
import type { InitFn, WasmBaseInstance } from './types'; | ||
/** | ||
* @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 declare function createWasmFn<C extends WasmBaseInstance>(root: string, wasmBytes: null | Uint8Array, asmFn: null | ((wbg: WebAssembly.ModuleImports) => C)): InitFn<C>; |
// Copyright 2019-2022 @polkadot/wasm-bundle authors & contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
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(root, wasmBytes, asmFn) { | ||
@@ -5,0 +14,0 @@ return async wbg => { |
@@ -23,3 +23,3 @@ { | ||
"type": "module", | ||
"version": "6.1.2-6", | ||
"version": "6.1.2-7", | ||
"main": "./cjs/index.js", | ||
@@ -26,0 +26,0 @@ "module": "./index.js", |
@@ -8,3 +8,3 @@ // Copyright 2017-2022 @polkadot/wasm-bridge authors & contributors | ||
type: 'esm', | ||
version: '6.1.2-6' | ||
version: '6.1.2-7' | ||
}; |
20
wbg.d.ts
import type { BridgeBase, WasmBaseInstance } from './types'; | ||
/** | ||
* @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 declare class Wbg<C extends WasmBaseInstance> { | ||
#private; | ||
constructor(bridge: BridgeBase<C>); | ||
/** @internal */ | ||
abort: () => never; | ||
/** @internal */ | ||
__wbindgen_is_undefined: (idx: number) => boolean; | ||
/** @internal */ | ||
__wbindgen_throw: (ptr: number, len: number) => boolean; | ||
/** @internal */ | ||
__wbg_self_1b7a39e3a92c949c: () => number; | ||
/** @internal */ | ||
__wbg_require_604837428532a733: (ptr: number, len: number) => never; | ||
/** @internal */ | ||
__wbg_crypto_968f1772287e2df0: (_idx: number) => number; | ||
/** @internal */ | ||
__wbg_getRandomValues_a3d34b4fee3c2869: (_idx: number) => number; | ||
/** @internal */ | ||
__wbg_getRandomValues_f5e14ab7ac8e995d: (_arg0: number, ptr: number, len: number) => void; | ||
/** @internal */ | ||
__wbg_randomFillSync_d5bd2d655fdf256a: (_idx: number, _ptr: number, _len: number) => never; | ||
/** @internal */ | ||
__wbindgen_object_drop_ref: (idx: number) => void; | ||
} |
39
wbg.js
@@ -10,2 +10,13 @@ // Copyright 2019-2022 @polkadot/wasm-bridge authors & contributors | ||
}; | ||
/** | ||
* @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 { | ||
@@ -17,30 +28,48 @@ #bridge; | ||
} | ||
/** @internal */ | ||
abort = () => { | ||
throw new Error('abort'); | ||
}; | ||
/** @internal */ | ||
__wbindgen_is_undefined = idx => { | ||
return this.#bridge.getObject(idx) === undefined; | ||
}; | ||
/** @internal */ | ||
__wbindgen_throw = (ptr, len) => { | ||
throw new Error(this.#bridge.getString(ptr, len)); | ||
}; | ||
/** @internal */ | ||
__wbg_self_1b7a39e3a92c949c = () => { | ||
return this.#bridge.addObject(DEFAULT_SELF); | ||
}; | ||
/** @internal */ | ||
__wbg_require_604837428532a733 = (ptr, len) => { | ||
throw new Error(`Unable to require ${this.#bridge.getString(ptr, len)}`); | ||
}; // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
}; | ||
/** @internal */ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
__wbg_crypto_968f1772287e2df0 = _idx => { | ||
return this.#bridge.addObject(DEFAULT_CRYPTO); | ||
}; // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
}; | ||
/** @internal */ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
__wbg_getRandomValues_a3d34b4fee3c2869 = _idx => { | ||
return this.#bridge.addObject(DEFAULT_CRYPTO.getRandomValues); | ||
}; // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
}; | ||
/** @internal */ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
__wbg_getRandomValues_f5e14ab7ac8e995d = (_arg0, ptr, len) => { | ||
DEFAULT_CRYPTO.getRandomValues(this.#bridge.getU8a(ptr, len)); | ||
}; // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
}; | ||
/** @internal */ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
@@ -50,2 +79,4 @@ __wbg_randomFillSync_d5bd2d655fdf256a = (_idx, _ptr, _len) => { | ||
}; | ||
/** @internal */ | ||
__wbindgen_object_drop_ref = idx => { | ||
@@ -52,0 +83,0 @@ this.#bridge.takeObject(idx); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39266
745