@pezkuwi/wasm-crypto 7.5.9 → 7.5.10

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/LICENSE +201 -0
  2. package/bundle-pezkuwi-wasm-crypto.js +777 -0
  3. package/bundle.d.ts +37 -0
  4. package/bundle.js +165 -0
  5. package/cjs/bundle.d.ts +37 -0
  6. package/cjs/bundle.js +171 -0
  7. package/cjs/index.js +5 -0
  8. package/cjs/init.js +21 -0
  9. package/cjs/initNone.js +20 -0
  10. package/cjs/initOnlyAsm.js +20 -0
  11. package/cjs/initOnlyWasm.js +20 -0
  12. package/cjs/initWasmAsm.js +20 -0
  13. package/cjs/package.json +3 -0
  14. package/cjs/packageDetect.js +10 -0
  15. package/cjs/packageInfo.js +4 -0
  16. package/index.d.ts +2 -0
  17. package/index.js +2 -0
  18. package/{src/init.ts → init.d.ts} +2 -11
  19. package/init.js +17 -0
  20. package/initNone.d.ts +10 -0
  21. package/{src/initNone.ts → initNone.js} +4 -10
  22. package/initOnlyAsm.d.ts +10 -0
  23. package/{src/initOnlyAsm.ts → initOnlyAsm.js} +4 -10
  24. package/initOnlyWasm.d.ts +10 -0
  25. package/{src/initOnlyWasm.ts → initOnlyWasm.js} +4 -10
  26. package/initWasmAsm.d.ts +10 -0
  27. package/{src/initWasmAsm.ts → initWasmAsm.js} +4 -10
  28. package/package.json +162 -16
  29. package/packageDetect.d.ts +1 -0
  30. package/{src/packageDetect.ts → packageDetect.js} +0 -8
  31. package/packageInfo.d.ts +6 -0
  32. package/packageInfo.js +1 -0
  33. package/Cargo.toml +0 -50
  34. package/Xargo.toml +0 -2
  35. package/build/bundle.d.ts +0 -37
  36. package/src/bundle.ts +0 -247
  37. package/src/index.ts +0 -6
  38. package/src/lib.rs +0 -24
  39. package/src/mod.ts +0 -4
  40. package/src/packageInfo.ts +0 -6
  41. package/src/rs/.editorconfig +0 -10
  42. package/src/rs/bip39.rs +0 -139
  43. package/src/rs/ed25519.rs +0 -142
  44. package/src/rs/hashing.rs +0 -322
  45. package/src/rs/secp256k1.rs +0 -150
  46. package/src/rs/sr25519.rs +0 -331
  47. package/src/rs/vrf.rs +0 -144
  48. package/test/all/bip39.js +0 -86
  49. package/test/all/ed25519.js +0 -84
  50. package/test/all/hashing.js +0 -138
  51. package/test/all/index.js +0 -126
  52. package/test/all/secp256k1.js +0 -105
  53. package/test/all/sr25519.js +0 -211
  54. package/test/all/vrf.js +0 -74
  55. package/test/asm.js +0 -10
  56. package/test/deno.ts +0 -37
  57. package/test/jest.spec.ts +0 -24
  58. package/test/loader-build.js +0 -39
  59. package/test/wasm.js +0 -8
  60. package/tsconfig.build.json +0 -19
  61. package/tsconfig.spec.json +0 -16
  62. /package/{build → cjs}/index.d.ts +0 -0
  63. /package/{build → cjs}/init.d.ts +0 -0
  64. /package/{build → cjs}/initNone.d.ts +0 -0
  65. /package/{build → cjs}/initOnlyAsm.d.ts +0 -0
  66. /package/{build → cjs}/initOnlyWasm.d.ts +0 -0
  67. /package/{build → cjs}/initWasmAsm.d.ts +0 -0
  68. /package/{build → cjs}/packageDetect.d.ts +0 -0
  69. /package/{build → cjs}/packageInfo.d.ts +0 -0
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @name initWasm
3
+ * @description
4
+ * For historic purposes and for tighter control on init, specifically performing
5
+ * a WASM initialization with only ASM.js
6
+ *
7
+ * Generally should not be used unless you want explicit control over which
8
+ * interfaces are initialized.
9
+ */
10
+ export declare function initWasm(): Promise<void>;
@@ -1,10 +1,5 @@
1
- // Copyright 2019-2026 @pezkuwi/wasm-crypto authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
1
  import { createWasm } from '@pezkuwi/wasm-crypto-init/asm';
5
-
6
2
  import { initBridge } from './init.js';
7
-
8
3
  /**
9
4
  * @name initWasm
10
5
  * @description
@@ -14,10 +9,9 @@ import { initBridge } from './init.js';
14
9
  * Generally should not be used unless you want explicit control over which
15
10
  * interfaces are initialized.
16
11
  */
17
- export async function initWasm (): Promise<void> {
18
- await initBridge(createWasm);
12
+ export async function initWasm() {
13
+ await initBridge(createWasm);
19
14
  }
20
-
21
- initWasm().catch((): void => {
22
- // cannot happen, initWasm doesn't throw
15
+ initWasm().catch(() => {
16
+ // cannot happen, initWasm doesn't throw
23
17
  });
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @name initWasm
3
+ * @description
4
+ * For historic purposes and for tighter control on init, specifically performing
5
+ * a WASM initialization with only WASM (generally the default for most platforms)
6
+ *
7
+ * Generally should not be used unless you want explicit control over which
8
+ * interfaces are initialized.
9
+ */
10
+ export declare function initWasm(): Promise<void>;
@@ -1,10 +1,5 @@
1
- // Copyright 2019-2026 @pezkuwi/wasm-crypto authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
1
  import { createWasm } from '@pezkuwi/wasm-crypto-init/wasm';
5
-
6
2
  import { initBridge } from './init.js';
7
-
8
3
  /**
9
4
  * @name initWasm
10
5
  * @description
@@ -14,10 +9,9 @@ import { initBridge } from './init.js';
14
9
  * Generally should not be used unless you want explicit control over which
15
10
  * interfaces are initialized.
16
11
  */
17
- export async function initWasm (): Promise<void> {
18
- await initBridge(createWasm);
12
+ export async function initWasm() {
13
+ await initBridge(createWasm);
19
14
  }
20
-
21
- initWasm().catch((): void => {
22
- // cannot happen, initWasm doesn't throw
15
+ initWasm().catch(() => {
16
+ // cannot happen, initWasm doesn't throw
23
17
  });
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @name initWasm
3
+ * @description
4
+ * For historic purposes and for tighter control on init, specifically performing
5
+ * a WASM initialization with ASM and an ASM.js fallback
6
+ *
7
+ * Generally should not be used unless you want explicit control over which
8
+ * interfaces are initialized.
9
+ */
10
+ export declare function initWasm(): Promise<void>;
@@ -1,10 +1,5 @@
1
- // Copyright 2019-2026 @pezkuwi/wasm-crypto authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
1
  import { createWasm } from '@pezkuwi/wasm-crypto-init/both';
5
-
6
2
  import { initBridge } from './init.js';
7
-
8
3
  /**
9
4
  * @name initWasm
10
5
  * @description
@@ -14,10 +9,9 @@ import { initBridge } from './init.js';
14
9
  * Generally should not be used unless you want explicit control over which
15
10
  * interfaces are initialized.
16
11
  */
17
- export async function initWasm (): Promise<void> {
18
- await initBridge(createWasm);
12
+ export async function initWasm() {
13
+ await initBridge(createWasm);
19
14
  }
20
-
21
- initWasm().catch((): void => {
22
- // cannot happen, initWasm doesn't throw
15
+ initWasm().catch(() => {
16
+ // cannot happen, initWasm doesn't throw
23
17
  });
package/package.json CHANGED
@@ -15,31 +15,177 @@
15
15
  },
16
16
  "sideEffects": [
17
17
  "./initNone.js",
18
- "./initNone.cjs",
18
+ "./cjs/initNone.js",
19
19
  "./initOnlyAsm.js",
20
- "./initOnlyAsm.cjs",
20
+ "./cjs/initOnlyAsm.js",
21
21
  "./initOnlyWasm.js",
22
- "./initOnlyWasm.cjs",
22
+ "./cjs/initOnlyWasm.js",
23
23
  "./initWasmAsm.js",
24
- "./initWasmAsm.cjs",
24
+ "./cjs/initWasmAsm.js",
25
25
  "./packageDetect.js",
26
- "./packageDetect.cjs"
26
+ "./cjs/packageDetect.js"
27
27
  ],
28
28
  "type": "module",
29
- "version": "7.5.9",
30
- "main": "index.js",
29
+ "version": "7.5.10",
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
+ },
31
181
  "dependencies": {
32
- "@pezkuwi/wasm-bridge": "7.5.9",
33
- "@pezkuwi/wasm-crypto-asmjs": "7.5.9",
34
- "@pezkuwi/wasm-crypto-init": "7.5.9",
35
- "@pezkuwi/wasm-crypto-wasm": "7.5.9",
36
- "@pezkuwi/wasm-util": "7.5.9",
182
+ "@pezkuwi/wasm-bridge": "7.5.10",
183
+ "@pezkuwi/wasm-crypto-asmjs": "7.5.10",
184
+ "@pezkuwi/wasm-crypto-init": "7.5.10",
185
+ "@pezkuwi/wasm-crypto-wasm": "7.5.10",
186
+ "@pezkuwi/wasm-util": "7.5.10",
37
187
  "tslib": "^2.7.0"
38
188
  },
39
- "devDependencies": {
40
- "@pezkuwi/util": "^14.0.1",
41
- "@pezkuwi/x-randomvalues": "^14.0.1"
42
- },
43
189
  "peerDependencies": {
44
190
  "@pezkuwi/util": "*",
45
191
  "@pezkuwi/x-randomvalues": "*"
@@ -0,0 +1 @@
1
+ export {};
@@ -1,16 +1,8 @@
1
- // Copyright 2017-2026 @pezkuwi/wasm-crypto authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- // Do not edit, auto-generated by @pezkuwi/dev
5
- // (packageInfo imports will be kept as-is, user-editable)
6
-
7
1
  import { detectPackage } from '@pezkuwi/util';
8
2
  import { packageInfo as bridgeInfo } from '@pezkuwi/wasm-bridge/packageInfo';
9
3
  import { packageInfo as asmInfo } from '@pezkuwi/wasm-crypto-asmjs/packageInfo';
10
4
  import { packageInfo as initInfo } from '@pezkuwi/wasm-crypto-init/packageInfo';
11
5
  import { packageInfo as wasmInfo } from '@pezkuwi/wasm-crypto-wasm/packageInfo';
12
6
  import { packageInfo as utilInfo } from '@pezkuwi/wasm-util/packageInfo';
13
-
14
7
  import { packageInfo } from './packageInfo.js';
15
-
16
8
  detectPackage(packageInfo, null, [asmInfo, bridgeInfo, initInfo, utilInfo, wasmInfo]);
@@ -0,0 +1,6 @@
1
+ export declare const packageInfo: {
2
+ name: string;
3
+ path: string;
4
+ type: string;
5
+ version: string;
6
+ };
package/packageInfo.js ADDED
@@ -0,0 +1 @@
1
+ export const packageInfo = { name: '@pezkuwi/wasm-crypto', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '7.5.10' };
package/Cargo.toml DELETED
@@ -1,50 +0,0 @@
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/Xargo.toml DELETED
@@ -1,2 +0,0 @@
1
- [dependencies]
2
- std = { default-features = false, features = ["panic_immediate_abort"] }
package/build/bundle.d.ts DELETED
@@ -1,37 +0,0 @@
1
- import { bridge } from './init.js';
2
- export { packageInfo } from './packageInfo.js';
3
- export { bridge };
4
- export declare const bip39Generate: (words: 12 | 15 | 18 | 21 | 24) => string;
5
- export declare const bip39ToEntropy: (phrase: string) => Uint8Array;
6
- export declare const bip39ToMiniSecret: (phrase: string, password: string) => Uint8Array;
7
- export declare const bip39ToSeed: (phrase: string, password: string) => Uint8Array;
8
- export declare const bip39Validate: (phrase: string) => boolean;
9
- export declare const ed25519KeypairFromSeed: (seed: Uint8Array) => Uint8Array;
10
- export declare const ed25519Sign: (pubkey: Uint8Array, seckey: Uint8Array, message: Uint8Array) => Uint8Array;
11
- export declare const ed25519Verify: (signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array) => boolean;
12
- export declare const secp256k1FromSeed: (seckey: Uint8Array) => Uint8Array;
13
- export declare const secp256k1Compress: (pubkey: Uint8Array) => Uint8Array;
14
- export declare const secp256k1Expand: (pubkey: Uint8Array) => Uint8Array;
15
- export declare const secp256k1Recover: (msgHash: Uint8Array, sig: Uint8Array, recovery: number) => Uint8Array;
16
- export declare const secp256k1Sign: (msgHash: Uint8Array, seckey: Uint8Array) => Uint8Array;
17
- export declare const sr25519DeriveKeypairHard: (pair: Uint8Array, cc: Uint8Array) => Uint8Array;
18
- export declare const sr25519DeriveKeypairSoft: (pair: Uint8Array, cc: Uint8Array) => Uint8Array;
19
- export declare const sr25519DerivePublicSoft: (pubkey: Uint8Array, cc: Uint8Array) => Uint8Array;
20
- export declare const sr25519KeypairFromSeed: (seed: Uint8Array) => Uint8Array;
21
- export declare const sr25519Sign: (pubkey: Uint8Array, secret: Uint8Array, message: Uint8Array) => Uint8Array;
22
- export declare const sr25519Verify: (signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array) => boolean;
23
- export declare const sr25519Agree: (pubkey: Uint8Array, secret: Uint8Array) => Uint8Array;
24
- export declare const vrfSign: (secret: Uint8Array, context: Uint8Array, message: Uint8Array, extra: Uint8Array) => Uint8Array;
25
- export declare const vrfVerify: (pubkey: Uint8Array, context: Uint8Array, message: Uint8Array, extra: Uint8Array, outAndProof: Uint8Array) => boolean;
26
- export declare const blake2b: (data: Uint8Array, key: Uint8Array, size: number) => Uint8Array;
27
- export declare const hmacSha256: (key: Uint8Array, data: Uint8Array) => Uint8Array;
28
- export declare const hmacSha512: (key: Uint8Array, data: Uint8Array) => Uint8Array;
29
- export declare const keccak256: (data: Uint8Array) => Uint8Array;
30
- export declare const keccak512: (data: Uint8Array) => Uint8Array;
31
- export declare const pbkdf2: (data: Uint8Array, salt: Uint8Array, rounds: number) => Uint8Array;
32
- export declare const scrypt: (password: Uint8Array, salt: Uint8Array, log2n: number, r: number, p: number) => Uint8Array;
33
- export declare const sha256: (data: Uint8Array) => Uint8Array;
34
- export declare const sha512: (data: Uint8Array) => Uint8Array;
35
- export declare const twox: (data: Uint8Array, rounds: number) => Uint8Array;
36
- export declare function isReady(): boolean;
37
- export declare function waitReady(): Promise<boolean>;
package/src/bundle.ts DELETED
@@ -1,247 +0,0 @@
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
- }