@pezkuwi/wasm-crypto 7.5.6 → 7.5.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/Cargo.toml +50 -0
  2. package/README.md +5 -5
  3. package/Xargo.toml +2 -0
  4. package/package.json +19 -165
  5. package/src/bundle.ts +247 -0
  6. package/src/index.ts +6 -0
  7. package/{init.d.ts → src/init.ts} +11 -2
  8. package/{initNone.js → src/initNone.ts} +10 -4
  9. package/{initOnlyAsm.js → src/initOnlyAsm.ts} +10 -4
  10. package/{initOnlyWasm.js → src/initOnlyWasm.ts} +10 -4
  11. package/{initWasmAsm.js → src/initWasmAsm.ts} +10 -4
  12. package/src/lib.rs +24 -0
  13. package/src/mod.ts +4 -0
  14. package/{packageDetect.js → src/packageDetect.ts} +8 -0
  15. package/src/packageInfo.ts +6 -0
  16. package/src/rs/.editorconfig +10 -0
  17. package/src/rs/bip39.rs +139 -0
  18. package/src/rs/ed25519.rs +142 -0
  19. package/src/rs/hashing.rs +322 -0
  20. package/src/rs/secp256k1.rs +150 -0
  21. package/src/rs/sr25519.rs +331 -0
  22. package/src/rs/vrf.rs +144 -0
  23. package/test/all/bip39.js +86 -0
  24. package/test/all/ed25519.js +84 -0
  25. package/test/all/hashing.js +138 -0
  26. package/test/all/index.js +126 -0
  27. package/test/all/secp256k1.js +105 -0
  28. package/test/all/sr25519.js +211 -0
  29. package/test/all/vrf.js +74 -0
  30. package/test/asm.js +10 -0
  31. package/test/deno.ts +37 -0
  32. package/test/jest.spec.ts +24 -0
  33. package/test/loader-build.js +39 -0
  34. package/test/wasm.js +8 -0
  35. package/tsconfig.build.json +19 -0
  36. package/tsconfig.spec.json +16 -0
  37. package/LICENSE +0 -201
  38. package/bundle-polkadot-wasm-crypto.js +0 -661
  39. package/bundle.js +0 -165
  40. package/cjs/bundle.d.ts +0 -37
  41. package/cjs/bundle.js +0 -171
  42. package/cjs/index.js +0 -5
  43. package/cjs/init.js +0 -21
  44. package/cjs/initNone.js +0 -20
  45. package/cjs/initOnlyAsm.js +0 -20
  46. package/cjs/initOnlyWasm.js +0 -20
  47. package/cjs/initWasmAsm.js +0 -20
  48. package/cjs/package.json +0 -3
  49. package/cjs/packageDetect.js +0 -10
  50. package/cjs/packageInfo.js +0 -4
  51. package/index.d.ts +0 -2
  52. package/index.js +0 -2
  53. package/init.js +0 -17
  54. package/initNone.d.ts +0 -10
  55. package/initOnlyAsm.d.ts +0 -10
  56. package/initOnlyWasm.d.ts +0 -10
  57. package/initWasmAsm.d.ts +0 -10
  58. package/packageDetect.d.ts +0 -1
  59. package/packageInfo.d.ts +0 -6
  60. package/packageInfo.js +0 -1
  61. /package/{bundle.d.ts → build/bundle.d.ts} +0 -0
  62. /package/{cjs → build}/index.d.ts +0 -0
  63. /package/{cjs → build}/init.d.ts +0 -0
  64. /package/{cjs → build}/initNone.d.ts +0 -0
  65. /package/{cjs → build}/initOnlyAsm.d.ts +0 -0
  66. /package/{cjs → build}/initOnlyWasm.d.ts +0 -0
  67. /package/{cjs → build}/initWasmAsm.d.ts +0 -0
  68. /package/{cjs → build}/packageDetect.d.ts +0 -0
  69. /package/{cjs → build}/packageInfo.d.ts +0 -0
package/Cargo.toml ADDED
@@ -0,0 +1,50 @@
1
+ # name & version is only used internally, doesn't need to be adjusted. In the case of
2
+ # name keep it consistent at "wasm" since the scripts (for re-use purposes) expect that
3
+
4
+ [package]
5
+ authors = ["Jaco Greeff <jacogr@gmail.com>"]
6
+ description = "WASM bindings to Rust crypto libraries."
7
+ edition = "2018"
8
+ license = "Apache-2.0"
9
+ name = "wasm"
10
+ publish = false
11
+ repository = "https://github.com/pezkuwichain/pezkuwi-wasm/"
12
+ resolver = "2"
13
+ version = "0.0.0"
14
+
15
+ [lib]
16
+ crate-type = ["cdylib"]
17
+
18
+ [dependencies]
19
+ blake2-rfc = "0.2.18"
20
+ byteorder = "1.3.1"
21
+ curve25519-dalek = { version = "2.1.0", default-features = false }
22
+ ed25519-dalek = { version = "1.0.0-pre.4", features = [] }
23
+ getrandom = { version="0.2.3", features = ["js"] }
24
+ hmac = "0.7.0"
25
+ secp256k1 = { version = "0.21.2", default-features = false, features = ["recovery", "global-context"] }
26
+ merlin = { version = "2.0", default-features = false }
27
+ pbkdf2 = { version = "0.3.0", default-features = false }
28
+ rand = { version="0.7.3", default-features = false, features = ["wasm-bindgen"] }
29
+ schnorrkel = { version = "0.9.1", features = ["preaudit_deprecated", "u64_backend"] }
30
+ scrypt = { version = "0.2", default-features = false }
31
+ sha2 = "0.8.1"
32
+ tiny-bip39 = { version = "0.7", default-features = false }
33
+ tiny-keccak = { version = "2.0.1", features = ["keccak"] }
34
+ twox-hash = "1.5.0"
35
+ wasm-bindgen = "=0.2.90"
36
+ wee_alloc = "0.4.3"
37
+
38
+ [dev-dependencies]
39
+ hex-literal = "0.2.0"
40
+ rand = { version = "0.7.3", features = ["wasm-bindgen"] }
41
+
42
+ [profile.release]
43
+ codegen-units = 1
44
+ debug = false
45
+ debug-assertions = false
46
+ incremental = false
47
+ lto = true
48
+ opt-level = "z"
49
+ panic = "abort"
50
+ rpath = false
package/README.md CHANGED
@@ -1,18 +1,18 @@
1
- # @polkadot/wasm-crypto
1
+ # @pezkuwi/wasm-crypto
2
2
 
3
3
  Wrapper around crypto hashing functions
4
4
 
5
5
  ## Usage
6
6
 
7
- Install the package (also requires `@polkadot/util` for `TextEncoder` polyfills - not included here as a dependency to keep the tree lean)
7
+ Install the package (also requires `@pezkuwi/util` for `TextEncoder` polyfills - not included here as a dependency to keep the tree lean)
8
8
 
9
- `yarn add @polkadot/wasm-crypto @polkadot/util`
9
+ `yarn add @pezkuwi/wasm-crypto @pezkuwi/util`
10
10
 
11
11
  Use it -
12
12
 
13
13
  ```js
14
- import { u8aToHex } from '@polkadot/util';
15
- import { bip39Generate, bip39ToSeed, waitReady } from '@polkadot/wasm-crypto';
14
+ import { u8aToHex } from '@pezkuwi/util';
15
+ import { bip39Generate, bip39ToSeed, waitReady } from '@pezkuwi/wasm-crypto';
16
16
 
17
17
  // first wait until the WASM has been loaded (async init)
18
18
  await waitReady();
package/Xargo.toml ADDED
@@ -0,0 +1,2 @@
1
+ [dependencies]
2
+ std = { default-features = false, features = ["panic_immediate_abort"] }
package/package.json CHANGED
@@ -1,191 +1,45 @@
1
1
  {
2
2
  "author": "Jaco Greeff <jacogr@gmail.com>",
3
- "bugs": "https://github.com/pezkuwi-js/wasm/issues",
3
+ "bugs": "https://github.com/pezkuwichain/pezkuwi-wasm/issues",
4
4
  "description": "A wasm interface layer for use by @pezkuwi/util-crypto",
5
5
  "engines": {
6
6
  "node": ">=18"
7
7
  },
8
- "homepage": "https://github.com/pezkuwi-js/wasm/tree/master/packages/wasm-crypto#readme",
8
+ "homepage": "https://github.com/pezkuwichain/pezkuwi-wasm/tree/master/packages/wasm-crypto#readme",
9
9
  "license": "Apache-2.0",
10
10
  "name": "@pezkuwi/wasm-crypto",
11
11
  "repository": {
12
12
  "directory": "packages/wasm-crypto",
13
13
  "type": "git",
14
- "url": "https://github.com/pezkuwi-js/wasm.git"
14
+ "url": "https://github.com/pezkuwichain/pezkuwi-wasm.git"
15
15
  },
16
16
  "sideEffects": [
17
17
  "./initNone.js",
18
- "./cjs/initNone.js",
18
+ "./initNone.cjs",
19
19
  "./initOnlyAsm.js",
20
- "./cjs/initOnlyAsm.js",
20
+ "./initOnlyAsm.cjs",
21
21
  "./initOnlyWasm.js",
22
- "./cjs/initOnlyWasm.js",
22
+ "./initOnlyWasm.cjs",
23
23
  "./initWasmAsm.js",
24
- "./cjs/initWasmAsm.js",
24
+ "./initWasmAsm.cjs",
25
25
  "./packageDetect.js",
26
- "./cjs/packageDetect.js"
26
+ "./packageDetect.cjs"
27
27
  ],
28
28
  "type": "module",
29
- "version": "7.5.6",
30
- "main": "./cjs/index.js",
31
- "module": "./index.js",
32
- "types": "./index.d.ts",
33
- "exports": {
34
- "./cjs/package.json": "./cjs/package.json",
35
- "./cjs/*": "./cjs/*.js",
36
- ".": {
37
- "module": {
38
- "types": "./index.d.ts",
39
- "default": "./index.js"
40
- },
41
- "require": {
42
- "types": "./cjs/index.d.ts",
43
- "default": "./cjs/index.js"
44
- },
45
- "default": {
46
- "types": "./index.d.ts",
47
- "default": "./index.js"
48
- }
49
- },
50
- "./bundle": {
51
- "module": {
52
- "types": "./bundle.d.ts",
53
- "default": "./bundle.js"
54
- },
55
- "require": {
56
- "types": "./cjs/bundle.d.ts",
57
- "default": "./cjs/bundle.js"
58
- },
59
- "default": {
60
- "types": "./bundle.d.ts",
61
- "default": "./bundle.js"
62
- }
63
- },
64
- "./init": {
65
- "module": {
66
- "types": "./init.d.ts",
67
- "default": "./init.js"
68
- },
69
- "require": {
70
- "types": "./cjs/init.d.ts",
71
- "default": "./cjs/init.js"
72
- },
73
- "default": {
74
- "types": "./init.d.ts",
75
- "default": "./init.js"
76
- }
77
- },
78
- "./initNone": {
79
- "module": {
80
- "types": "./initNone.d.ts",
81
- "default": "./initNone.js"
82
- },
83
- "require": {
84
- "types": "./cjs/initNone.d.ts",
85
- "default": "./cjs/initNone.js"
86
- },
87
- "default": {
88
- "types": "./initNone.d.ts",
89
- "default": "./initNone.js"
90
- }
91
- },
92
- "./initOnlyAsm": {
93
- "module": {
94
- "types": "./initOnlyAsm.d.ts",
95
- "default": "./initOnlyAsm.js"
96
- },
97
- "require": {
98
- "types": "./cjs/initOnlyAsm.d.ts",
99
- "default": "./cjs/initOnlyAsm.js"
100
- },
101
- "default": {
102
- "types": "./initOnlyAsm.d.ts",
103
- "default": "./initOnlyAsm.js"
104
- }
105
- },
106
- "./initOnlyWasm": {
107
- "module": {
108
- "types": "./initOnlyWasm.d.ts",
109
- "default": "./initOnlyWasm.js"
110
- },
111
- "require": {
112
- "types": "./cjs/initOnlyWasm.d.ts",
113
- "default": "./cjs/initOnlyWasm.js"
114
- },
115
- "default": {
116
- "types": "./initOnlyWasm.d.ts",
117
- "default": "./initOnlyWasm.js"
118
- }
119
- },
120
- "./initWasmAsm": {
121
- "module": {
122
- "types": "./initWasmAsm.d.ts",
123
- "default": "./initWasmAsm.js"
124
- },
125
- "require": {
126
- "types": "./cjs/initWasmAsm.d.ts",
127
- "default": "./cjs/initWasmAsm.js"
128
- },
129
- "default": {
130
- "types": "./initWasmAsm.d.ts",
131
- "default": "./initWasmAsm.js"
132
- }
133
- },
134
- "./package.json": {
135
- "require": "./cjs/package.json",
136
- "default": "./package.json"
137
- },
138
- "./packageDetect": {
139
- "module": {
140
- "types": "./packageDetect.d.ts",
141
- "default": "./packageDetect.js"
142
- },
143
- "require": {
144
- "types": "./cjs/packageDetect.d.ts",
145
- "default": "./cjs/packageDetect.js"
146
- },
147
- "default": {
148
- "types": "./packageDetect.d.ts",
149
- "default": "./packageDetect.js"
150
- }
151
- },
152
- "./packageInfo.js": {
153
- "module": {
154
- "types": "./packageInfo.d.ts",
155
- "default": "./packageInfo.js"
156
- },
157
- "require": {
158
- "types": "./cjs/packageInfo.d.ts",
159
- "default": "./cjs/packageInfo.js"
160
- },
161
- "default": {
162
- "types": "./packageInfo.d.ts",
163
- "default": "./packageInfo.js"
164
- }
165
- },
166
- "./packageInfo": {
167
- "module": {
168
- "types": "./packageInfo.d.ts",
169
- "default": "./packageInfo.js"
170
- },
171
- "require": {
172
- "types": "./cjs/packageInfo.d.ts",
173
- "default": "./cjs/packageInfo.js"
174
- },
175
- "default": {
176
- "types": "./packageInfo.d.ts",
177
- "default": "./packageInfo.js"
178
- }
179
- }
180
- },
29
+ "version": "7.5.8",
30
+ "main": "index.js",
181
31
  "dependencies": {
182
- "@pezkuwi/wasm-bridge": "7.5.6",
183
- "@pezkuwi/wasm-crypto-asmjs": "7.5.6",
184
- "@pezkuwi/wasm-crypto-init": "7.5.6",
185
- "@pezkuwi/wasm-crypto-wasm": "7.5.6",
186
- "@pezkuwi/wasm-util": "7.5.6",
32
+ "@pezkuwi/wasm-bridge": "7.5.8",
33
+ "@pezkuwi/wasm-crypto-asmjs": "7.5.8",
34
+ "@pezkuwi/wasm-crypto-init": "7.5.8",
35
+ "@pezkuwi/wasm-crypto-wasm": "7.5.8",
36
+ "@pezkuwi/wasm-util": "7.5.8",
187
37
  "tslib": "^2.7.0"
188
38
  },
39
+ "devDependencies": {
40
+ "@pezkuwi/util": "^14.0.1",
41
+ "@pezkuwi/x-randomvalues": "^14.0.1"
42
+ },
189
43
  "peerDependencies": {
190
44
  "@pezkuwi/util": "*",
191
45
  "@pezkuwi/x-randomvalues": "*"
package/src/bundle.ts ADDED
@@ -0,0 +1,247 @@
1
+ // Copyright 2019-2026 @pezkuwi/wasm-crypto authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { WasmCryptoInstance } from '@pezkuwi/wasm-crypto-init/types';
5
+
6
+ import { bridge, initBridge } from './init.js';
7
+
8
+ export { packageInfo } from './packageInfo.js';
9
+ export { bridge };
10
+
11
+ // Removes the first parameter (expected as WasmCryptoInstance) and leaves the
12
+ // rest of the parameters in-tack. This allows us to dynamically create a function
13
+ // return from the withWasm helper
14
+ type PopFirst<T extends unknown[]> =
15
+ T extends [WasmCryptoInstance, ...infer N]
16
+ ? N
17
+ : [];
18
+
19
+ /**
20
+ * @internal
21
+ * @description
22
+ * This create an extenal interface function from the signature, all the while checking
23
+ * the actual bridge wasm interface to ensure it has been initialized.
24
+ *
25
+ * This means that we can call it
26
+ *
27
+ * withWasm(wasm: WasmCryptoInstance, a: number, b: string) => Uint8Array
28
+ *
29
+ * and in this case it will create an interface function with the signarure
30
+ *
31
+ * (a: number, b: string) => Uint8Array
32
+ */
33
+ function withWasm <T, F extends (wasm: WasmCryptoInstance, ...params: never[]) => T> (fn: F): (...params: PopFirst<Parameters<F>>) => ReturnType<F> {
34
+ return (...params: PopFirst<Parameters<F>>): ReturnType<F> => {
35
+ if (!bridge.wasm) {
36
+ throw new Error('The WASM interface has not been initialized. Ensure that you wait for the initialization Promise with waitReady() from @pezkuwi/wasm-crypto (or cryptoWaitReady() from @pezkuwi/util-crypto) before attempting to use WASM-only interfaces.');
37
+ }
38
+
39
+ return fn(bridge.wasm, ...params) as ReturnType<F>;
40
+ };
41
+ }
42
+
43
+ export const bip39Generate = /*#__PURE__*/ withWasm((wasm, words: 12 | 15 | 18 | 21 | 24): string => {
44
+ wasm.ext_bip39_generate(8, words);
45
+
46
+ return bridge.resultString();
47
+ });
48
+
49
+ export const bip39ToEntropy = /*#__PURE__*/ withWasm((wasm, phrase: string): Uint8Array => {
50
+ wasm.ext_bip39_to_entropy(8, ...bridge.allocString(phrase));
51
+
52
+ return bridge.resultU8a();
53
+ });
54
+
55
+ export const bip39ToMiniSecret = /*#__PURE__*/ withWasm((wasm, phrase: string, password: string): Uint8Array => {
56
+ wasm.ext_bip39_to_mini_secret(8, ...bridge.allocString(phrase), ...bridge.allocString(password));
57
+
58
+ return bridge.resultU8a();
59
+ });
60
+
61
+ export const bip39ToSeed = /*#__PURE__*/ withWasm((wasm, phrase: string, password: string): Uint8Array => {
62
+ wasm.ext_bip39_to_seed(8, ...bridge.allocString(phrase), ...bridge.allocString(password));
63
+
64
+ return bridge.resultU8a();
65
+ });
66
+
67
+ export const bip39Validate = /*#__PURE__*/ withWasm((wasm, phrase: string): boolean => {
68
+ const ret = wasm.ext_bip39_validate(...bridge.allocString(phrase));
69
+
70
+ return ret !== 0;
71
+ });
72
+
73
+ export const ed25519KeypairFromSeed = /*#__PURE__*/ withWasm((wasm, seed: Uint8Array): Uint8Array => {
74
+ wasm.ext_ed_from_seed(8, ...bridge.allocU8a(seed));
75
+
76
+ return bridge.resultU8a();
77
+ });
78
+
79
+ export const ed25519Sign = /*#__PURE__*/ withWasm((wasm, pubkey: Uint8Array, seckey: Uint8Array, message: Uint8Array): Uint8Array => {
80
+ wasm.ext_ed_sign(8, ...bridge.allocU8a(pubkey), ...bridge.allocU8a(seckey), ...bridge.allocU8a(message));
81
+
82
+ return bridge.resultU8a();
83
+ });
84
+
85
+ export const ed25519Verify = /*#__PURE__*/ withWasm((wasm, signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
86
+ const ret = wasm.ext_ed_verify(...bridge.allocU8a(signature), ...bridge.allocU8a(message), ...bridge.allocU8a(pubkey));
87
+
88
+ return ret !== 0;
89
+ });
90
+
91
+ export const secp256k1FromSeed = /*#__PURE__*/ withWasm((wasm, seckey: Uint8Array): Uint8Array => {
92
+ wasm.ext_secp_from_seed(8, ...bridge.allocU8a(seckey));
93
+
94
+ return bridge.resultU8a();
95
+ });
96
+
97
+ export const secp256k1Compress = /*#__PURE__*/ withWasm((wasm, pubkey: Uint8Array): Uint8Array => {
98
+ wasm.ext_secp_pub_compress(8, ...bridge.allocU8a(pubkey));
99
+
100
+ return bridge.resultU8a();
101
+ });
102
+
103
+ export const secp256k1Expand = /*#__PURE__*/ withWasm((wasm, pubkey: Uint8Array): Uint8Array => {
104
+ wasm.ext_secp_pub_expand(8, ...bridge.allocU8a(pubkey));
105
+
106
+ return bridge.resultU8a();
107
+ });
108
+
109
+ export const secp256k1Recover = /*#__PURE__*/ withWasm((wasm, msgHash: Uint8Array, sig: Uint8Array, recovery: number): Uint8Array => {
110
+ wasm.ext_secp_recover(8, ...bridge.allocU8a(msgHash), ...bridge.allocU8a(sig), recovery);
111
+
112
+ return bridge.resultU8a();
113
+ });
114
+
115
+ export const secp256k1Sign = /*#__PURE__*/ withWasm((wasm, msgHash: Uint8Array, seckey: Uint8Array): Uint8Array => {
116
+ wasm.ext_secp_sign(8, ...bridge.allocU8a(msgHash), ...bridge.allocU8a(seckey));
117
+
118
+ return bridge.resultU8a();
119
+ });
120
+
121
+ export const sr25519DeriveKeypairHard = /*#__PURE__*/ withWasm((wasm, pair: Uint8Array, cc: Uint8Array): Uint8Array => {
122
+ wasm.ext_sr_derive_keypair_hard(8, ...bridge.allocU8a(pair), ...bridge.allocU8a(cc));
123
+
124
+ return bridge.resultU8a();
125
+ });
126
+
127
+ export const sr25519DeriveKeypairSoft = /*#__PURE__*/ withWasm((wasm, pair: Uint8Array, cc: Uint8Array): Uint8Array => {
128
+ wasm.ext_sr_derive_keypair_soft(8, ...bridge.allocU8a(pair), ...bridge.allocU8a(cc));
129
+
130
+ return bridge.resultU8a();
131
+ });
132
+
133
+ export const sr25519DerivePublicSoft = /*#__PURE__*/ withWasm((wasm, pubkey: Uint8Array, cc: Uint8Array): Uint8Array => {
134
+ wasm.ext_sr_derive_public_soft(8, ...bridge.allocU8a(pubkey), ...bridge.allocU8a(cc));
135
+
136
+ return bridge.resultU8a();
137
+ });
138
+
139
+ export const sr25519KeypairFromSeed = /*#__PURE__*/ withWasm((wasm, seed: Uint8Array): Uint8Array => {
140
+ wasm.ext_sr_from_seed(8, ...bridge.allocU8a(seed));
141
+
142
+ return bridge.resultU8a();
143
+ });
144
+
145
+ export const sr25519Sign = /*#__PURE__*/ withWasm((wasm, pubkey: Uint8Array, secret: Uint8Array, message: Uint8Array): Uint8Array => {
146
+ wasm.ext_sr_sign(8, ...bridge.allocU8a(pubkey), ...bridge.allocU8a(secret), ...bridge.allocU8a(message));
147
+
148
+ return bridge.resultU8a();
149
+ });
150
+
151
+ export const sr25519Verify = /*#__PURE__*/ withWasm((wasm, signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): boolean => {
152
+ const ret = wasm.ext_sr_verify(...bridge.allocU8a(signature), ...bridge.allocU8a(message), ...bridge.allocU8a(pubkey));
153
+
154
+ return ret !== 0;
155
+ });
156
+
157
+ export const sr25519Agree = /*#__PURE__*/ withWasm((wasm, pubkey: Uint8Array, secret: Uint8Array): Uint8Array => {
158
+ wasm.ext_sr_agree(8, ...bridge.allocU8a(pubkey), ...bridge.allocU8a(secret));
159
+
160
+ return bridge.resultU8a();
161
+ });
162
+
163
+ export const vrfSign = /*#__PURE__*/ withWasm((wasm, secret: Uint8Array, context: Uint8Array, message: Uint8Array, extra: Uint8Array): Uint8Array => {
164
+ wasm.ext_vrf_sign(8, ...bridge.allocU8a(secret), ...bridge.allocU8a(context), ...bridge.allocU8a(message), ...bridge.allocU8a(extra));
165
+
166
+ return bridge.resultU8a();
167
+ });
168
+
169
+ export const vrfVerify = /*#__PURE__*/ withWasm((wasm, pubkey: Uint8Array, context: Uint8Array, message: Uint8Array, extra: Uint8Array, outAndProof: Uint8Array): boolean => {
170
+ const ret = wasm.ext_vrf_verify(...bridge.allocU8a(pubkey), ...bridge.allocU8a(context), ...bridge.allocU8a(message), ...bridge.allocU8a(extra), ...bridge.allocU8a(outAndProof));
171
+
172
+ return ret !== 0;
173
+ });
174
+
175
+ export const blake2b = /*#__PURE__*/ withWasm((wasm, data: Uint8Array, key: Uint8Array, size: number): Uint8Array => {
176
+ wasm.ext_blake2b(8, ...bridge.allocU8a(data), ...bridge.allocU8a(key), size);
177
+
178
+ return bridge.resultU8a();
179
+ });
180
+
181
+ export const hmacSha256 = /*#__PURE__*/ withWasm((wasm, key: Uint8Array, data: Uint8Array): Uint8Array => {
182
+ wasm.ext_hmac_sha256(8, ...bridge.allocU8a(key), ...bridge.allocU8a(data));
183
+
184
+ return bridge.resultU8a();
185
+ });
186
+
187
+ export const hmacSha512 = /*#__PURE__*/ withWasm((wasm, key: Uint8Array, data: Uint8Array): Uint8Array => {
188
+ wasm.ext_hmac_sha512(8, ...bridge.allocU8a(key), ...bridge.allocU8a(data));
189
+
190
+ return bridge.resultU8a();
191
+ });
192
+
193
+ export const keccak256 = /*#__PURE__*/ withWasm((wasm, data: Uint8Array): Uint8Array => {
194
+ wasm.ext_keccak256(8, ...bridge.allocU8a(data));
195
+
196
+ return bridge.resultU8a();
197
+ });
198
+
199
+ export const keccak512 = /*#__PURE__*/ withWasm((wasm, data: Uint8Array): Uint8Array => {
200
+ wasm.ext_keccak512(8, ...bridge.allocU8a(data));
201
+
202
+ return bridge.resultU8a();
203
+ });
204
+
205
+ export const pbkdf2 = /*#__PURE__*/ withWasm((wasm, data: Uint8Array, salt: Uint8Array, rounds: number): Uint8Array => {
206
+ wasm.ext_pbkdf2(8, ...bridge.allocU8a(data), ...bridge.allocU8a(salt), rounds);
207
+
208
+ return bridge.resultU8a();
209
+ });
210
+
211
+ export const scrypt = /*#__PURE__*/ withWasm((wasm, password: Uint8Array, salt: Uint8Array, log2n: number, r: number, p: number): Uint8Array => {
212
+ wasm.ext_scrypt(8, ...bridge.allocU8a(password), ...bridge.allocU8a(salt), log2n, r, p);
213
+
214
+ return bridge.resultU8a();
215
+ });
216
+
217
+ export const sha256 = /*#__PURE__*/ withWasm((wasm, data: Uint8Array): Uint8Array => {
218
+ wasm.ext_sha256(8, ...bridge.allocU8a(data));
219
+
220
+ return bridge.resultU8a();
221
+ });
222
+
223
+ export const sha512 = /*#__PURE__*/ withWasm((wasm, data: Uint8Array): Uint8Array => {
224
+ wasm.ext_sha512(8, ...bridge.allocU8a(data));
225
+
226
+ return bridge.resultU8a();
227
+ });
228
+
229
+ export const twox = /*#__PURE__*/ withWasm((wasm, data: Uint8Array, rounds: number) => {
230
+ wasm.ext_twox(8, ...bridge.allocU8a(data), rounds);
231
+
232
+ return bridge.resultU8a();
233
+ });
234
+
235
+ export function isReady (): boolean {
236
+ return !!bridge.wasm;
237
+ }
238
+
239
+ export async function waitReady (): Promise<boolean> {
240
+ try {
241
+ const wasm = await initBridge();
242
+
243
+ return !!wasm;
244
+ } catch {
245
+ return false;
246
+ }
247
+ }
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ // Copyright 2019-2026 @pezkuwi/wasm-crypto authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import './packageDetect.js';
5
+
6
+ export * from './bundle.js';
@@ -1,16 +1,25 @@
1
+ // Copyright 2019-2026 @pezkuwi/wasm-crypto authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
1
4
  import type { InitFn } from '@pezkuwi/wasm-bridge/types';
2
5
  import type { WasmCryptoInstance } from '@pezkuwi/wasm-crypto-init/types';
6
+
3
7
  import { Bridge } from '@pezkuwi/wasm-bridge';
8
+ import { createWasm } from '@pezkuwi/wasm-crypto-init';
9
+
4
10
  /**
5
11
  * @name bridge
6
12
  * @description
7
13
  * The JS <-> WASM bridge that is in operation. For the specific package
8
14
  * it is a global, i.e. all operations happens on this specific bridge
9
15
  */
10
- export declare const bridge: Bridge<WasmCryptoInstance>;
16
+ export const bridge = new Bridge<WasmCryptoInstance>(createWasm);
17
+
11
18
  /**
12
19
  * @name initBridge
13
20
  * @description
14
21
  * Creates a new bridge interface with the (optional) initialization function
15
22
  */
16
- export declare function initBridge(createWasm?: InitFn<WasmCryptoInstance>): Promise<WasmCryptoInstance | null>;
23
+ export async function initBridge (createWasm?: InitFn<WasmCryptoInstance>): Promise<WasmCryptoInstance | null> {
24
+ return bridge.init(createWasm);
25
+ }
@@ -1,5 +1,10 @@
1
+ // Copyright 2019-2026 @pezkuwi/wasm-crypto authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
1
4
  import { createWasm } from '@pezkuwi/wasm-crypto-init/none';
5
+
2
6
  import { initBridge } from './init.js';
7
+
3
8
  /**
4
9
  * @name initWasm
5
10
  * @description
@@ -9,9 +14,10 @@ import { initBridge } from './init.js';
9
14
  * Generally should not be used unless you want explicit control over which
10
15
  * interfaces are initialized.
11
16
  */
12
- export async function initWasm() {
13
- await initBridge(createWasm);
17
+ export async function initWasm (): Promise<void> {
18
+ await initBridge(createWasm);
14
19
  }
15
- initWasm().catch(() => {
16
- // cannot happen, initWasm doesn't throw
20
+
21
+ initWasm().catch((): void => {
22
+ // cannot happen, initWasm doesn't throw
17
23
  });
@@ -1,5 +1,10 @@
1
+ // Copyright 2019-2026 @pezkuwi/wasm-crypto authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
1
4
  import { createWasm } from '@pezkuwi/wasm-crypto-init/asm';
5
+
2
6
  import { initBridge } from './init.js';
7
+
3
8
  /**
4
9
  * @name initWasm
5
10
  * @description
@@ -9,9 +14,10 @@ import { initBridge } from './init.js';
9
14
  * Generally should not be used unless you want explicit control over which
10
15
  * interfaces are initialized.
11
16
  */
12
- export async function initWasm() {
13
- await initBridge(createWasm);
17
+ export async function initWasm (): Promise<void> {
18
+ await initBridge(createWasm);
14
19
  }
15
- initWasm().catch(() => {
16
- // cannot happen, initWasm doesn't throw
20
+
21
+ initWasm().catch((): void => {
22
+ // cannot happen, initWasm doesn't throw
17
23
  });
@@ -1,5 +1,10 @@
1
+ // Copyright 2019-2026 @pezkuwi/wasm-crypto authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
1
4
  import { createWasm } from '@pezkuwi/wasm-crypto-init/wasm';
5
+
2
6
  import { initBridge } from './init.js';
7
+
3
8
  /**
4
9
  * @name initWasm
5
10
  * @description
@@ -9,9 +14,10 @@ import { initBridge } from './init.js';
9
14
  * Generally should not be used unless you want explicit control over which
10
15
  * interfaces are initialized.
11
16
  */
12
- export async function initWasm() {
13
- await initBridge(createWasm);
17
+ export async function initWasm (): Promise<void> {
18
+ await initBridge(createWasm);
14
19
  }
15
- initWasm().catch(() => {
16
- // cannot happen, initWasm doesn't throw
20
+
21
+ initWasm().catch((): void => {
22
+ // cannot happen, initWasm doesn't throw
17
23
  });
@@ -1,5 +1,10 @@
1
+ // Copyright 2019-2026 @pezkuwi/wasm-crypto authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
1
4
  import { createWasm } from '@pezkuwi/wasm-crypto-init/both';
5
+
2
6
  import { initBridge } from './init.js';
7
+
3
8
  /**
4
9
  * @name initWasm
5
10
  * @description
@@ -9,9 +14,10 @@ import { initBridge } from './init.js';
9
14
  * Generally should not be used unless you want explicit control over which
10
15
  * interfaces are initialized.
11
16
  */
12
- export async function initWasm() {
13
- await initBridge(createWasm);
17
+ export async function initWasm (): Promise<void> {
18
+ await initBridge(createWasm);
14
19
  }
15
- initWasm().catch(() => {
16
- // cannot happen, initWasm doesn't throw
20
+
21
+ initWasm().catch((): void => {
22
+ // cannot happen, initWasm doesn't throw
17
23
  });