@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.
- package/LICENSE +201 -0
- package/bundle-pezkuwi-wasm-crypto.js +777 -0
- package/bundle.d.ts +37 -0
- package/bundle.js +165 -0
- package/cjs/bundle.d.ts +37 -0
- package/cjs/bundle.js +171 -0
- package/cjs/index.js +5 -0
- package/cjs/init.js +21 -0
- package/cjs/initNone.js +20 -0
- package/cjs/initOnlyAsm.js +20 -0
- package/cjs/initOnlyWasm.js +20 -0
- package/cjs/initWasmAsm.js +20 -0
- package/cjs/package.json +3 -0
- package/cjs/packageDetect.js +10 -0
- package/cjs/packageInfo.js +4 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/{src/init.ts → init.d.ts} +2 -11
- package/init.js +17 -0
- package/initNone.d.ts +10 -0
- package/{src/initNone.ts → initNone.js} +4 -10
- package/initOnlyAsm.d.ts +10 -0
- package/{src/initOnlyAsm.ts → initOnlyAsm.js} +4 -10
- package/initOnlyWasm.d.ts +10 -0
- package/{src/initOnlyWasm.ts → initOnlyWasm.js} +4 -10
- package/initWasmAsm.d.ts +10 -0
- package/{src/initWasmAsm.ts → initWasmAsm.js} +4 -10
- package/package.json +162 -16
- package/packageDetect.d.ts +1 -0
- package/{src/packageDetect.ts → packageDetect.js} +0 -8
- package/packageInfo.d.ts +6 -0
- package/packageInfo.js +1 -0
- package/Cargo.toml +0 -50
- package/Xargo.toml +0 -2
- package/build/bundle.d.ts +0 -37
- package/src/bundle.ts +0 -247
- package/src/index.ts +0 -6
- package/src/lib.rs +0 -24
- package/src/mod.ts +0 -4
- package/src/packageInfo.ts +0 -6
- package/src/rs/.editorconfig +0 -10
- package/src/rs/bip39.rs +0 -139
- package/src/rs/ed25519.rs +0 -142
- package/src/rs/hashing.rs +0 -322
- package/src/rs/secp256k1.rs +0 -150
- package/src/rs/sr25519.rs +0 -331
- package/src/rs/vrf.rs +0 -144
- package/test/all/bip39.js +0 -86
- package/test/all/ed25519.js +0 -84
- package/test/all/hashing.js +0 -138
- package/test/all/index.js +0 -126
- package/test/all/secp256k1.js +0 -105
- package/test/all/sr25519.js +0 -211
- package/test/all/vrf.js +0 -74
- package/test/asm.js +0 -10
- package/test/deno.ts +0 -37
- package/test/jest.spec.ts +0 -24
- package/test/loader-build.js +0 -39
- package/test/wasm.js +0 -8
- package/tsconfig.build.json +0 -19
- package/tsconfig.spec.json +0 -16
- /package/{build → cjs}/index.d.ts +0 -0
- /package/{build → cjs}/init.d.ts +0 -0
- /package/{build → cjs}/initNone.d.ts +0 -0
- /package/{build → cjs}/initOnlyAsm.d.ts +0 -0
- /package/{build → cjs}/initOnlyWasm.d.ts +0 -0
- /package/{build → cjs}/initWasmAsm.d.ts +0 -0
- /package/{build → cjs}/packageDetect.d.ts +0 -0
- /package/{build → cjs}/packageInfo.d.ts +0 -0
package/bundle.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
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<ArrayBufferLike>;
|
|
6
|
+
export declare const bip39ToMiniSecret: (phrase: string, password: string) => Uint8Array<ArrayBufferLike>;
|
|
7
|
+
export declare const bip39ToSeed: (phrase: string, password: string) => Uint8Array<ArrayBufferLike>;
|
|
8
|
+
export declare const bip39Validate: (phrase: string) => boolean;
|
|
9
|
+
export declare const ed25519KeypairFromSeed: (seed: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
10
|
+
export declare const ed25519Sign: (pubkey: Uint8Array<ArrayBufferLike>, seckey: Uint8Array<ArrayBufferLike>, message: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
11
|
+
export declare const ed25519Verify: (signature: Uint8Array<ArrayBufferLike>, message: Uint8Array<ArrayBufferLike>, pubkey: Uint8Array<ArrayBufferLike>) => boolean;
|
|
12
|
+
export declare const secp256k1FromSeed: (seckey: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
13
|
+
export declare const secp256k1Compress: (pubkey: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
14
|
+
export declare const secp256k1Expand: (pubkey: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
15
|
+
export declare const secp256k1Recover: (msgHash: Uint8Array<ArrayBufferLike>, sig: Uint8Array<ArrayBufferLike>, recovery: number) => Uint8Array<ArrayBufferLike>;
|
|
16
|
+
export declare const secp256k1Sign: (msgHash: Uint8Array<ArrayBufferLike>, seckey: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
17
|
+
export declare const sr25519DeriveKeypairHard: (pair: Uint8Array<ArrayBufferLike>, cc: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
18
|
+
export declare const sr25519DeriveKeypairSoft: (pair: Uint8Array<ArrayBufferLike>, cc: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
19
|
+
export declare const sr25519DerivePublicSoft: (pubkey: Uint8Array<ArrayBufferLike>, cc: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
20
|
+
export declare const sr25519KeypairFromSeed: (seed: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
21
|
+
export declare const sr25519Sign: (pubkey: Uint8Array<ArrayBufferLike>, secret: Uint8Array<ArrayBufferLike>, message: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
22
|
+
export declare const sr25519Verify: (signature: Uint8Array<ArrayBufferLike>, message: Uint8Array<ArrayBufferLike>, pubkey: Uint8Array<ArrayBufferLike>) => boolean;
|
|
23
|
+
export declare const sr25519Agree: (pubkey: Uint8Array<ArrayBufferLike>, secret: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
24
|
+
export declare const vrfSign: (secret: Uint8Array<ArrayBufferLike>, context: Uint8Array<ArrayBufferLike>, message: Uint8Array<ArrayBufferLike>, extra: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
25
|
+
export declare const vrfVerify: (pubkey: Uint8Array<ArrayBufferLike>, context: Uint8Array<ArrayBufferLike>, message: Uint8Array<ArrayBufferLike>, extra: Uint8Array<ArrayBufferLike>, outAndProof: Uint8Array<ArrayBufferLike>) => boolean;
|
|
26
|
+
export declare const blake2b: (data: Uint8Array<ArrayBufferLike>, key: Uint8Array<ArrayBufferLike>, size: number) => Uint8Array<ArrayBufferLike>;
|
|
27
|
+
export declare const hmacSha256: (key: Uint8Array<ArrayBufferLike>, data: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
28
|
+
export declare const hmacSha512: (key: Uint8Array<ArrayBufferLike>, data: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
29
|
+
export declare const keccak256: (data: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
30
|
+
export declare const keccak512: (data: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
31
|
+
export declare const pbkdf2: (data: Uint8Array<ArrayBufferLike>, salt: Uint8Array<ArrayBufferLike>, rounds: number) => Uint8Array<ArrayBufferLike>;
|
|
32
|
+
export declare const scrypt: (password: Uint8Array<ArrayBufferLike>, salt: Uint8Array<ArrayBufferLike>, log2n: number, r: number, p: number) => Uint8Array<ArrayBufferLike>;
|
|
33
|
+
export declare const sha256: (data: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
34
|
+
export declare const sha512: (data: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
35
|
+
export declare const twox: (data: Uint8Array<ArrayBufferLike>, rounds: number) => Uint8Array<ArrayBufferLike>;
|
|
36
|
+
export declare function isReady(): boolean;
|
|
37
|
+
export declare function waitReady(): Promise<boolean>;
|
package/bundle.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { bridge, initBridge } from './init.js';
|
|
2
|
+
export { packageInfo } from './packageInfo.js';
|
|
3
|
+
export { bridge };
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
* @description
|
|
7
|
+
* This create an extenal interface function from the signature, all the while checking
|
|
8
|
+
* the actual bridge wasm interface to ensure it has been initialized.
|
|
9
|
+
*
|
|
10
|
+
* This means that we can call it
|
|
11
|
+
*
|
|
12
|
+
* withWasm(wasm: WasmCryptoInstance, a: number, b: string) => Uint8Array
|
|
13
|
+
*
|
|
14
|
+
* and in this case it will create an interface function with the signarure
|
|
15
|
+
*
|
|
16
|
+
* (a: number, b: string) => Uint8Array
|
|
17
|
+
*/
|
|
18
|
+
function withWasm(fn) {
|
|
19
|
+
return (...params) => {
|
|
20
|
+
if (!bridge.wasm) {
|
|
21
|
+
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.');
|
|
22
|
+
}
|
|
23
|
+
return fn(bridge.wasm, ...params);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export const bip39Generate = /*#__PURE__*/ withWasm((wasm, words) => {
|
|
27
|
+
wasm.ext_bip39_generate(8, words);
|
|
28
|
+
return bridge.resultString();
|
|
29
|
+
});
|
|
30
|
+
export const bip39ToEntropy = /*#__PURE__*/ withWasm((wasm, phrase) => {
|
|
31
|
+
wasm.ext_bip39_to_entropy(8, ...bridge.allocString(phrase));
|
|
32
|
+
return bridge.resultU8a();
|
|
33
|
+
});
|
|
34
|
+
export const bip39ToMiniSecret = /*#__PURE__*/ withWasm((wasm, phrase, password) => {
|
|
35
|
+
wasm.ext_bip39_to_mini_secret(8, ...bridge.allocString(phrase), ...bridge.allocString(password));
|
|
36
|
+
return bridge.resultU8a();
|
|
37
|
+
});
|
|
38
|
+
export const bip39ToSeed = /*#__PURE__*/ withWasm((wasm, phrase, password) => {
|
|
39
|
+
wasm.ext_bip39_to_seed(8, ...bridge.allocString(phrase), ...bridge.allocString(password));
|
|
40
|
+
return bridge.resultU8a();
|
|
41
|
+
});
|
|
42
|
+
export const bip39Validate = /*#__PURE__*/ withWasm((wasm, phrase) => {
|
|
43
|
+
const ret = wasm.ext_bip39_validate(...bridge.allocString(phrase));
|
|
44
|
+
return ret !== 0;
|
|
45
|
+
});
|
|
46
|
+
export const ed25519KeypairFromSeed = /*#__PURE__*/ withWasm((wasm, seed) => {
|
|
47
|
+
wasm.ext_ed_from_seed(8, ...bridge.allocU8a(seed));
|
|
48
|
+
return bridge.resultU8a();
|
|
49
|
+
});
|
|
50
|
+
export const ed25519Sign = /*#__PURE__*/ withWasm((wasm, pubkey, seckey, message) => {
|
|
51
|
+
wasm.ext_ed_sign(8, ...bridge.allocU8a(pubkey), ...bridge.allocU8a(seckey), ...bridge.allocU8a(message));
|
|
52
|
+
return bridge.resultU8a();
|
|
53
|
+
});
|
|
54
|
+
export const ed25519Verify = /*#__PURE__*/ withWasm((wasm, signature, message, pubkey) => {
|
|
55
|
+
const ret = wasm.ext_ed_verify(...bridge.allocU8a(signature), ...bridge.allocU8a(message), ...bridge.allocU8a(pubkey));
|
|
56
|
+
return ret !== 0;
|
|
57
|
+
});
|
|
58
|
+
export const secp256k1FromSeed = /*#__PURE__*/ withWasm((wasm, seckey) => {
|
|
59
|
+
wasm.ext_secp_from_seed(8, ...bridge.allocU8a(seckey));
|
|
60
|
+
return bridge.resultU8a();
|
|
61
|
+
});
|
|
62
|
+
export const secp256k1Compress = /*#__PURE__*/ withWasm((wasm, pubkey) => {
|
|
63
|
+
wasm.ext_secp_pub_compress(8, ...bridge.allocU8a(pubkey));
|
|
64
|
+
return bridge.resultU8a();
|
|
65
|
+
});
|
|
66
|
+
export const secp256k1Expand = /*#__PURE__*/ withWasm((wasm, pubkey) => {
|
|
67
|
+
wasm.ext_secp_pub_expand(8, ...bridge.allocU8a(pubkey));
|
|
68
|
+
return bridge.resultU8a();
|
|
69
|
+
});
|
|
70
|
+
export const secp256k1Recover = /*#__PURE__*/ withWasm((wasm, msgHash, sig, recovery) => {
|
|
71
|
+
wasm.ext_secp_recover(8, ...bridge.allocU8a(msgHash), ...bridge.allocU8a(sig), recovery);
|
|
72
|
+
return bridge.resultU8a();
|
|
73
|
+
});
|
|
74
|
+
export const secp256k1Sign = /*#__PURE__*/ withWasm((wasm, msgHash, seckey) => {
|
|
75
|
+
wasm.ext_secp_sign(8, ...bridge.allocU8a(msgHash), ...bridge.allocU8a(seckey));
|
|
76
|
+
return bridge.resultU8a();
|
|
77
|
+
});
|
|
78
|
+
export const sr25519DeriveKeypairHard = /*#__PURE__*/ withWasm((wasm, pair, cc) => {
|
|
79
|
+
wasm.ext_sr_derive_keypair_hard(8, ...bridge.allocU8a(pair), ...bridge.allocU8a(cc));
|
|
80
|
+
return bridge.resultU8a();
|
|
81
|
+
});
|
|
82
|
+
export const sr25519DeriveKeypairSoft = /*#__PURE__*/ withWasm((wasm, pair, cc) => {
|
|
83
|
+
wasm.ext_sr_derive_keypair_soft(8, ...bridge.allocU8a(pair), ...bridge.allocU8a(cc));
|
|
84
|
+
return bridge.resultU8a();
|
|
85
|
+
});
|
|
86
|
+
export const sr25519DerivePublicSoft = /*#__PURE__*/ withWasm((wasm, pubkey, cc) => {
|
|
87
|
+
wasm.ext_sr_derive_public_soft(8, ...bridge.allocU8a(pubkey), ...bridge.allocU8a(cc));
|
|
88
|
+
return bridge.resultU8a();
|
|
89
|
+
});
|
|
90
|
+
export const sr25519KeypairFromSeed = /*#__PURE__*/ withWasm((wasm, seed) => {
|
|
91
|
+
wasm.ext_sr_from_seed(8, ...bridge.allocU8a(seed));
|
|
92
|
+
return bridge.resultU8a();
|
|
93
|
+
});
|
|
94
|
+
export const sr25519Sign = /*#__PURE__*/ withWasm((wasm, pubkey, secret, message) => {
|
|
95
|
+
wasm.ext_sr_sign(8, ...bridge.allocU8a(pubkey), ...bridge.allocU8a(secret), ...bridge.allocU8a(message));
|
|
96
|
+
return bridge.resultU8a();
|
|
97
|
+
});
|
|
98
|
+
export const sr25519Verify = /*#__PURE__*/ withWasm((wasm, signature, message, pubkey) => {
|
|
99
|
+
const ret = wasm.ext_sr_verify(...bridge.allocU8a(signature), ...bridge.allocU8a(message), ...bridge.allocU8a(pubkey));
|
|
100
|
+
return ret !== 0;
|
|
101
|
+
});
|
|
102
|
+
export const sr25519Agree = /*#__PURE__*/ withWasm((wasm, pubkey, secret) => {
|
|
103
|
+
wasm.ext_sr_agree(8, ...bridge.allocU8a(pubkey), ...bridge.allocU8a(secret));
|
|
104
|
+
return bridge.resultU8a();
|
|
105
|
+
});
|
|
106
|
+
export const vrfSign = /*#__PURE__*/ withWasm((wasm, secret, context, message, extra) => {
|
|
107
|
+
wasm.ext_vrf_sign(8, ...bridge.allocU8a(secret), ...bridge.allocU8a(context), ...bridge.allocU8a(message), ...bridge.allocU8a(extra));
|
|
108
|
+
return bridge.resultU8a();
|
|
109
|
+
});
|
|
110
|
+
export const vrfVerify = /*#__PURE__*/ withWasm((wasm, pubkey, context, message, extra, outAndProof) => {
|
|
111
|
+
const ret = wasm.ext_vrf_verify(...bridge.allocU8a(pubkey), ...bridge.allocU8a(context), ...bridge.allocU8a(message), ...bridge.allocU8a(extra), ...bridge.allocU8a(outAndProof));
|
|
112
|
+
return ret !== 0;
|
|
113
|
+
});
|
|
114
|
+
export const blake2b = /*#__PURE__*/ withWasm((wasm, data, key, size) => {
|
|
115
|
+
wasm.ext_blake2b(8, ...bridge.allocU8a(data), ...bridge.allocU8a(key), size);
|
|
116
|
+
return bridge.resultU8a();
|
|
117
|
+
});
|
|
118
|
+
export const hmacSha256 = /*#__PURE__*/ withWasm((wasm, key, data) => {
|
|
119
|
+
wasm.ext_hmac_sha256(8, ...bridge.allocU8a(key), ...bridge.allocU8a(data));
|
|
120
|
+
return bridge.resultU8a();
|
|
121
|
+
});
|
|
122
|
+
export const hmacSha512 = /*#__PURE__*/ withWasm((wasm, key, data) => {
|
|
123
|
+
wasm.ext_hmac_sha512(8, ...bridge.allocU8a(key), ...bridge.allocU8a(data));
|
|
124
|
+
return bridge.resultU8a();
|
|
125
|
+
});
|
|
126
|
+
export const keccak256 = /*#__PURE__*/ withWasm((wasm, data) => {
|
|
127
|
+
wasm.ext_keccak256(8, ...bridge.allocU8a(data));
|
|
128
|
+
return bridge.resultU8a();
|
|
129
|
+
});
|
|
130
|
+
export const keccak512 = /*#__PURE__*/ withWasm((wasm, data) => {
|
|
131
|
+
wasm.ext_keccak512(8, ...bridge.allocU8a(data));
|
|
132
|
+
return bridge.resultU8a();
|
|
133
|
+
});
|
|
134
|
+
export const pbkdf2 = /*#__PURE__*/ withWasm((wasm, data, salt, rounds) => {
|
|
135
|
+
wasm.ext_pbkdf2(8, ...bridge.allocU8a(data), ...bridge.allocU8a(salt), rounds);
|
|
136
|
+
return bridge.resultU8a();
|
|
137
|
+
});
|
|
138
|
+
export const scrypt = /*#__PURE__*/ withWasm((wasm, password, salt, log2n, r, p) => {
|
|
139
|
+
wasm.ext_scrypt(8, ...bridge.allocU8a(password), ...bridge.allocU8a(salt), log2n, r, p);
|
|
140
|
+
return bridge.resultU8a();
|
|
141
|
+
});
|
|
142
|
+
export const sha256 = /*#__PURE__*/ withWasm((wasm, data) => {
|
|
143
|
+
wasm.ext_sha256(8, ...bridge.allocU8a(data));
|
|
144
|
+
return bridge.resultU8a();
|
|
145
|
+
});
|
|
146
|
+
export const sha512 = /*#__PURE__*/ withWasm((wasm, data) => {
|
|
147
|
+
wasm.ext_sha512(8, ...bridge.allocU8a(data));
|
|
148
|
+
return bridge.resultU8a();
|
|
149
|
+
});
|
|
150
|
+
export const twox = /*#__PURE__*/ withWasm((wasm, data, rounds) => {
|
|
151
|
+
wasm.ext_twox(8, ...bridge.allocU8a(data), rounds);
|
|
152
|
+
return bridge.resultU8a();
|
|
153
|
+
});
|
|
154
|
+
export function isReady() {
|
|
155
|
+
return !!bridge.wasm;
|
|
156
|
+
}
|
|
157
|
+
export async function waitReady() {
|
|
158
|
+
try {
|
|
159
|
+
const wasm = await initBridge();
|
|
160
|
+
return !!wasm;
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}
|
package/cjs/bundle.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
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<ArrayBufferLike>;
|
|
6
|
+
export declare const bip39ToMiniSecret: (phrase: string, password: string) => Uint8Array<ArrayBufferLike>;
|
|
7
|
+
export declare const bip39ToSeed: (phrase: string, password: string) => Uint8Array<ArrayBufferLike>;
|
|
8
|
+
export declare const bip39Validate: (phrase: string) => boolean;
|
|
9
|
+
export declare const ed25519KeypairFromSeed: (seed: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
10
|
+
export declare const ed25519Sign: (pubkey: Uint8Array<ArrayBufferLike>, seckey: Uint8Array<ArrayBufferLike>, message: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
11
|
+
export declare const ed25519Verify: (signature: Uint8Array<ArrayBufferLike>, message: Uint8Array<ArrayBufferLike>, pubkey: Uint8Array<ArrayBufferLike>) => boolean;
|
|
12
|
+
export declare const secp256k1FromSeed: (seckey: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
13
|
+
export declare const secp256k1Compress: (pubkey: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
14
|
+
export declare const secp256k1Expand: (pubkey: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
15
|
+
export declare const secp256k1Recover: (msgHash: Uint8Array<ArrayBufferLike>, sig: Uint8Array<ArrayBufferLike>, recovery: number) => Uint8Array<ArrayBufferLike>;
|
|
16
|
+
export declare const secp256k1Sign: (msgHash: Uint8Array<ArrayBufferLike>, seckey: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
17
|
+
export declare const sr25519DeriveKeypairHard: (pair: Uint8Array<ArrayBufferLike>, cc: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
18
|
+
export declare const sr25519DeriveKeypairSoft: (pair: Uint8Array<ArrayBufferLike>, cc: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
19
|
+
export declare const sr25519DerivePublicSoft: (pubkey: Uint8Array<ArrayBufferLike>, cc: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
20
|
+
export declare const sr25519KeypairFromSeed: (seed: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
21
|
+
export declare const sr25519Sign: (pubkey: Uint8Array<ArrayBufferLike>, secret: Uint8Array<ArrayBufferLike>, message: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
22
|
+
export declare const sr25519Verify: (signature: Uint8Array<ArrayBufferLike>, message: Uint8Array<ArrayBufferLike>, pubkey: Uint8Array<ArrayBufferLike>) => boolean;
|
|
23
|
+
export declare const sr25519Agree: (pubkey: Uint8Array<ArrayBufferLike>, secret: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
24
|
+
export declare const vrfSign: (secret: Uint8Array<ArrayBufferLike>, context: Uint8Array<ArrayBufferLike>, message: Uint8Array<ArrayBufferLike>, extra: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
25
|
+
export declare const vrfVerify: (pubkey: Uint8Array<ArrayBufferLike>, context: Uint8Array<ArrayBufferLike>, message: Uint8Array<ArrayBufferLike>, extra: Uint8Array<ArrayBufferLike>, outAndProof: Uint8Array<ArrayBufferLike>) => boolean;
|
|
26
|
+
export declare const blake2b: (data: Uint8Array<ArrayBufferLike>, key: Uint8Array<ArrayBufferLike>, size: number) => Uint8Array<ArrayBufferLike>;
|
|
27
|
+
export declare const hmacSha256: (key: Uint8Array<ArrayBufferLike>, data: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
28
|
+
export declare const hmacSha512: (key: Uint8Array<ArrayBufferLike>, data: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
29
|
+
export declare const keccak256: (data: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
30
|
+
export declare const keccak512: (data: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
31
|
+
export declare const pbkdf2: (data: Uint8Array<ArrayBufferLike>, salt: Uint8Array<ArrayBufferLike>, rounds: number) => Uint8Array<ArrayBufferLike>;
|
|
32
|
+
export declare const scrypt: (password: Uint8Array<ArrayBufferLike>, salt: Uint8Array<ArrayBufferLike>, log2n: number, r: number, p: number) => Uint8Array<ArrayBufferLike>;
|
|
33
|
+
export declare const sha256: (data: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
34
|
+
export declare const sha512: (data: Uint8Array<ArrayBufferLike>) => Uint8Array<ArrayBufferLike>;
|
|
35
|
+
export declare const twox: (data: Uint8Array<ArrayBufferLike>, rounds: number) => Uint8Array<ArrayBufferLike>;
|
|
36
|
+
export declare function isReady(): boolean;
|
|
37
|
+
export declare function waitReady(): Promise<boolean>;
|
package/cjs/bundle.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.twox = exports.sha512 = exports.sha256 = exports.scrypt = exports.pbkdf2 = exports.keccak512 = exports.keccak256 = exports.hmacSha512 = exports.hmacSha256 = exports.blake2b = exports.vrfVerify = exports.vrfSign = exports.sr25519Agree = exports.sr25519Verify = exports.sr25519Sign = exports.sr25519KeypairFromSeed = exports.sr25519DerivePublicSoft = exports.sr25519DeriveKeypairSoft = exports.sr25519DeriveKeypairHard = exports.secp256k1Sign = exports.secp256k1Recover = exports.secp256k1Expand = exports.secp256k1Compress = exports.secp256k1FromSeed = exports.ed25519Verify = exports.ed25519Sign = exports.ed25519KeypairFromSeed = exports.bip39Validate = exports.bip39ToSeed = exports.bip39ToMiniSecret = exports.bip39ToEntropy = exports.bip39Generate = exports.bridge = exports.packageInfo = void 0;
|
|
4
|
+
exports.isReady = isReady;
|
|
5
|
+
exports.waitReady = waitReady;
|
|
6
|
+
const init_js_1 = require("./init.js");
|
|
7
|
+
Object.defineProperty(exports, "bridge", { enumerable: true, get: function () { return init_js_1.bridge; } });
|
|
8
|
+
var packageInfo_js_1 = require("./packageInfo.js");
|
|
9
|
+
Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_js_1.packageInfo; } });
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
* @description
|
|
13
|
+
* This create an extenal interface function from the signature, all the while checking
|
|
14
|
+
* the actual bridge wasm interface to ensure it has been initialized.
|
|
15
|
+
*
|
|
16
|
+
* This means that we can call it
|
|
17
|
+
*
|
|
18
|
+
* withWasm(wasm: WasmCryptoInstance, a: number, b: string) => Uint8Array
|
|
19
|
+
*
|
|
20
|
+
* and in this case it will create an interface function with the signarure
|
|
21
|
+
*
|
|
22
|
+
* (a: number, b: string) => Uint8Array
|
|
23
|
+
*/
|
|
24
|
+
function withWasm(fn) {
|
|
25
|
+
return (...params) => {
|
|
26
|
+
if (!init_js_1.bridge.wasm) {
|
|
27
|
+
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.');
|
|
28
|
+
}
|
|
29
|
+
return fn(init_js_1.bridge.wasm, ...params);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
exports.bip39Generate = withWasm((wasm, words) => {
|
|
33
|
+
wasm.ext_bip39_generate(8, words);
|
|
34
|
+
return init_js_1.bridge.resultString();
|
|
35
|
+
});
|
|
36
|
+
exports.bip39ToEntropy = withWasm((wasm, phrase) => {
|
|
37
|
+
wasm.ext_bip39_to_entropy(8, ...init_js_1.bridge.allocString(phrase));
|
|
38
|
+
return init_js_1.bridge.resultU8a();
|
|
39
|
+
});
|
|
40
|
+
exports.bip39ToMiniSecret = withWasm((wasm, phrase, password) => {
|
|
41
|
+
wasm.ext_bip39_to_mini_secret(8, ...init_js_1.bridge.allocString(phrase), ...init_js_1.bridge.allocString(password));
|
|
42
|
+
return init_js_1.bridge.resultU8a();
|
|
43
|
+
});
|
|
44
|
+
exports.bip39ToSeed = withWasm((wasm, phrase, password) => {
|
|
45
|
+
wasm.ext_bip39_to_seed(8, ...init_js_1.bridge.allocString(phrase), ...init_js_1.bridge.allocString(password));
|
|
46
|
+
return init_js_1.bridge.resultU8a();
|
|
47
|
+
});
|
|
48
|
+
exports.bip39Validate = withWasm((wasm, phrase) => {
|
|
49
|
+
const ret = wasm.ext_bip39_validate(...init_js_1.bridge.allocString(phrase));
|
|
50
|
+
return ret !== 0;
|
|
51
|
+
});
|
|
52
|
+
exports.ed25519KeypairFromSeed = withWasm((wasm, seed) => {
|
|
53
|
+
wasm.ext_ed_from_seed(8, ...init_js_1.bridge.allocU8a(seed));
|
|
54
|
+
return init_js_1.bridge.resultU8a();
|
|
55
|
+
});
|
|
56
|
+
exports.ed25519Sign = withWasm((wasm, pubkey, seckey, message) => {
|
|
57
|
+
wasm.ext_ed_sign(8, ...init_js_1.bridge.allocU8a(pubkey), ...init_js_1.bridge.allocU8a(seckey), ...init_js_1.bridge.allocU8a(message));
|
|
58
|
+
return init_js_1.bridge.resultU8a();
|
|
59
|
+
});
|
|
60
|
+
exports.ed25519Verify = withWasm((wasm, signature, message, pubkey) => {
|
|
61
|
+
const ret = wasm.ext_ed_verify(...init_js_1.bridge.allocU8a(signature), ...init_js_1.bridge.allocU8a(message), ...init_js_1.bridge.allocU8a(pubkey));
|
|
62
|
+
return ret !== 0;
|
|
63
|
+
});
|
|
64
|
+
exports.secp256k1FromSeed = withWasm((wasm, seckey) => {
|
|
65
|
+
wasm.ext_secp_from_seed(8, ...init_js_1.bridge.allocU8a(seckey));
|
|
66
|
+
return init_js_1.bridge.resultU8a();
|
|
67
|
+
});
|
|
68
|
+
exports.secp256k1Compress = withWasm((wasm, pubkey) => {
|
|
69
|
+
wasm.ext_secp_pub_compress(8, ...init_js_1.bridge.allocU8a(pubkey));
|
|
70
|
+
return init_js_1.bridge.resultU8a();
|
|
71
|
+
});
|
|
72
|
+
exports.secp256k1Expand = withWasm((wasm, pubkey) => {
|
|
73
|
+
wasm.ext_secp_pub_expand(8, ...init_js_1.bridge.allocU8a(pubkey));
|
|
74
|
+
return init_js_1.bridge.resultU8a();
|
|
75
|
+
});
|
|
76
|
+
exports.secp256k1Recover = withWasm((wasm, msgHash, sig, recovery) => {
|
|
77
|
+
wasm.ext_secp_recover(8, ...init_js_1.bridge.allocU8a(msgHash), ...init_js_1.bridge.allocU8a(sig), recovery);
|
|
78
|
+
return init_js_1.bridge.resultU8a();
|
|
79
|
+
});
|
|
80
|
+
exports.secp256k1Sign = withWasm((wasm, msgHash, seckey) => {
|
|
81
|
+
wasm.ext_secp_sign(8, ...init_js_1.bridge.allocU8a(msgHash), ...init_js_1.bridge.allocU8a(seckey));
|
|
82
|
+
return init_js_1.bridge.resultU8a();
|
|
83
|
+
});
|
|
84
|
+
exports.sr25519DeriveKeypairHard = withWasm((wasm, pair, cc) => {
|
|
85
|
+
wasm.ext_sr_derive_keypair_hard(8, ...init_js_1.bridge.allocU8a(pair), ...init_js_1.bridge.allocU8a(cc));
|
|
86
|
+
return init_js_1.bridge.resultU8a();
|
|
87
|
+
});
|
|
88
|
+
exports.sr25519DeriveKeypairSoft = withWasm((wasm, pair, cc) => {
|
|
89
|
+
wasm.ext_sr_derive_keypair_soft(8, ...init_js_1.bridge.allocU8a(pair), ...init_js_1.bridge.allocU8a(cc));
|
|
90
|
+
return init_js_1.bridge.resultU8a();
|
|
91
|
+
});
|
|
92
|
+
exports.sr25519DerivePublicSoft = withWasm((wasm, pubkey, cc) => {
|
|
93
|
+
wasm.ext_sr_derive_public_soft(8, ...init_js_1.bridge.allocU8a(pubkey), ...init_js_1.bridge.allocU8a(cc));
|
|
94
|
+
return init_js_1.bridge.resultU8a();
|
|
95
|
+
});
|
|
96
|
+
exports.sr25519KeypairFromSeed = withWasm((wasm, seed) => {
|
|
97
|
+
wasm.ext_sr_from_seed(8, ...init_js_1.bridge.allocU8a(seed));
|
|
98
|
+
return init_js_1.bridge.resultU8a();
|
|
99
|
+
});
|
|
100
|
+
exports.sr25519Sign = withWasm((wasm, pubkey, secret, message) => {
|
|
101
|
+
wasm.ext_sr_sign(8, ...init_js_1.bridge.allocU8a(pubkey), ...init_js_1.bridge.allocU8a(secret), ...init_js_1.bridge.allocU8a(message));
|
|
102
|
+
return init_js_1.bridge.resultU8a();
|
|
103
|
+
});
|
|
104
|
+
exports.sr25519Verify = withWasm((wasm, signature, message, pubkey) => {
|
|
105
|
+
const ret = wasm.ext_sr_verify(...init_js_1.bridge.allocU8a(signature), ...init_js_1.bridge.allocU8a(message), ...init_js_1.bridge.allocU8a(pubkey));
|
|
106
|
+
return ret !== 0;
|
|
107
|
+
});
|
|
108
|
+
exports.sr25519Agree = withWasm((wasm, pubkey, secret) => {
|
|
109
|
+
wasm.ext_sr_agree(8, ...init_js_1.bridge.allocU8a(pubkey), ...init_js_1.bridge.allocU8a(secret));
|
|
110
|
+
return init_js_1.bridge.resultU8a();
|
|
111
|
+
});
|
|
112
|
+
exports.vrfSign = withWasm((wasm, secret, context, message, extra) => {
|
|
113
|
+
wasm.ext_vrf_sign(8, ...init_js_1.bridge.allocU8a(secret), ...init_js_1.bridge.allocU8a(context), ...init_js_1.bridge.allocU8a(message), ...init_js_1.bridge.allocU8a(extra));
|
|
114
|
+
return init_js_1.bridge.resultU8a();
|
|
115
|
+
});
|
|
116
|
+
exports.vrfVerify = withWasm((wasm, pubkey, context, message, extra, outAndProof) => {
|
|
117
|
+
const ret = wasm.ext_vrf_verify(...init_js_1.bridge.allocU8a(pubkey), ...init_js_1.bridge.allocU8a(context), ...init_js_1.bridge.allocU8a(message), ...init_js_1.bridge.allocU8a(extra), ...init_js_1.bridge.allocU8a(outAndProof));
|
|
118
|
+
return ret !== 0;
|
|
119
|
+
});
|
|
120
|
+
exports.blake2b = withWasm((wasm, data, key, size) => {
|
|
121
|
+
wasm.ext_blake2b(8, ...init_js_1.bridge.allocU8a(data), ...init_js_1.bridge.allocU8a(key), size);
|
|
122
|
+
return init_js_1.bridge.resultU8a();
|
|
123
|
+
});
|
|
124
|
+
exports.hmacSha256 = withWasm((wasm, key, data) => {
|
|
125
|
+
wasm.ext_hmac_sha256(8, ...init_js_1.bridge.allocU8a(key), ...init_js_1.bridge.allocU8a(data));
|
|
126
|
+
return init_js_1.bridge.resultU8a();
|
|
127
|
+
});
|
|
128
|
+
exports.hmacSha512 = withWasm((wasm, key, data) => {
|
|
129
|
+
wasm.ext_hmac_sha512(8, ...init_js_1.bridge.allocU8a(key), ...init_js_1.bridge.allocU8a(data));
|
|
130
|
+
return init_js_1.bridge.resultU8a();
|
|
131
|
+
});
|
|
132
|
+
exports.keccak256 = withWasm((wasm, data) => {
|
|
133
|
+
wasm.ext_keccak256(8, ...init_js_1.bridge.allocU8a(data));
|
|
134
|
+
return init_js_1.bridge.resultU8a();
|
|
135
|
+
});
|
|
136
|
+
exports.keccak512 = withWasm((wasm, data) => {
|
|
137
|
+
wasm.ext_keccak512(8, ...init_js_1.bridge.allocU8a(data));
|
|
138
|
+
return init_js_1.bridge.resultU8a();
|
|
139
|
+
});
|
|
140
|
+
exports.pbkdf2 = withWasm((wasm, data, salt, rounds) => {
|
|
141
|
+
wasm.ext_pbkdf2(8, ...init_js_1.bridge.allocU8a(data), ...init_js_1.bridge.allocU8a(salt), rounds);
|
|
142
|
+
return init_js_1.bridge.resultU8a();
|
|
143
|
+
});
|
|
144
|
+
exports.scrypt = withWasm((wasm, password, salt, log2n, r, p) => {
|
|
145
|
+
wasm.ext_scrypt(8, ...init_js_1.bridge.allocU8a(password), ...init_js_1.bridge.allocU8a(salt), log2n, r, p);
|
|
146
|
+
return init_js_1.bridge.resultU8a();
|
|
147
|
+
});
|
|
148
|
+
exports.sha256 = withWasm((wasm, data) => {
|
|
149
|
+
wasm.ext_sha256(8, ...init_js_1.bridge.allocU8a(data));
|
|
150
|
+
return init_js_1.bridge.resultU8a();
|
|
151
|
+
});
|
|
152
|
+
exports.sha512 = withWasm((wasm, data) => {
|
|
153
|
+
wasm.ext_sha512(8, ...init_js_1.bridge.allocU8a(data));
|
|
154
|
+
return init_js_1.bridge.resultU8a();
|
|
155
|
+
});
|
|
156
|
+
exports.twox = withWasm((wasm, data, rounds) => {
|
|
157
|
+
wasm.ext_twox(8, ...init_js_1.bridge.allocU8a(data), rounds);
|
|
158
|
+
return init_js_1.bridge.resultU8a();
|
|
159
|
+
});
|
|
160
|
+
function isReady() {
|
|
161
|
+
return !!init_js_1.bridge.wasm;
|
|
162
|
+
}
|
|
163
|
+
async function waitReady() {
|
|
164
|
+
try {
|
|
165
|
+
const wasm = await (0, init_js_1.initBridge)();
|
|
166
|
+
return !!wasm;
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
}
|
package/cjs/index.js
ADDED
package/cjs/init.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bridge = void 0;
|
|
4
|
+
exports.initBridge = initBridge;
|
|
5
|
+
const wasm_bridge_1 = require("@pezkuwi/wasm-bridge");
|
|
6
|
+
const wasm_crypto_init_1 = require("@pezkuwi/wasm-crypto-init");
|
|
7
|
+
/**
|
|
8
|
+
* @name bridge
|
|
9
|
+
* @description
|
|
10
|
+
* The JS <-> WASM bridge that is in operation. For the specific package
|
|
11
|
+
* it is a global, i.e. all operations happens on this specific bridge
|
|
12
|
+
*/
|
|
13
|
+
exports.bridge = new wasm_bridge_1.Bridge(wasm_crypto_init_1.createWasm);
|
|
14
|
+
/**
|
|
15
|
+
* @name initBridge
|
|
16
|
+
* @description
|
|
17
|
+
* Creates a new bridge interface with the (optional) initialization function
|
|
18
|
+
*/
|
|
19
|
+
async function initBridge(createWasm) {
|
|
20
|
+
return exports.bridge.init(createWasm);
|
|
21
|
+
}
|
package/cjs/initNone.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initWasm = initWasm;
|
|
4
|
+
const none_1 = require("@pezkuwi/wasm-crypto-init/none");
|
|
5
|
+
const init_js_1 = require("./init.js");
|
|
6
|
+
/**
|
|
7
|
+
* @name initWasm
|
|
8
|
+
* @description
|
|
9
|
+
* For historic purposes and for tighter control on init, specifically performing
|
|
10
|
+
* a WASM initialization with no interface whatsoever (no WASM, no ASM.js)
|
|
11
|
+
*
|
|
12
|
+
* Generally should not be used unless you want explicit control over which
|
|
13
|
+
* interfaces are initialized.
|
|
14
|
+
*/
|
|
15
|
+
async function initWasm() {
|
|
16
|
+
await (0, init_js_1.initBridge)(none_1.createWasm);
|
|
17
|
+
}
|
|
18
|
+
initWasm().catch(() => {
|
|
19
|
+
// cannot happen, initWasm doesn't throw
|
|
20
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initWasm = initWasm;
|
|
4
|
+
const asm_1 = require("@pezkuwi/wasm-crypto-init/asm");
|
|
5
|
+
const init_js_1 = require("./init.js");
|
|
6
|
+
/**
|
|
7
|
+
* @name initWasm
|
|
8
|
+
* @description
|
|
9
|
+
* For historic purposes and for tighter control on init, specifically performing
|
|
10
|
+
* a WASM initialization with only ASM.js
|
|
11
|
+
*
|
|
12
|
+
* Generally should not be used unless you want explicit control over which
|
|
13
|
+
* interfaces are initialized.
|
|
14
|
+
*/
|
|
15
|
+
async function initWasm() {
|
|
16
|
+
await (0, init_js_1.initBridge)(asm_1.createWasm);
|
|
17
|
+
}
|
|
18
|
+
initWasm().catch(() => {
|
|
19
|
+
// cannot happen, initWasm doesn't throw
|
|
20
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initWasm = initWasm;
|
|
4
|
+
const wasm_1 = require("@pezkuwi/wasm-crypto-init/wasm");
|
|
5
|
+
const init_js_1 = require("./init.js");
|
|
6
|
+
/**
|
|
7
|
+
* @name initWasm
|
|
8
|
+
* @description
|
|
9
|
+
* For historic purposes and for tighter control on init, specifically performing
|
|
10
|
+
* a WASM initialization with only WASM (generally the default for most platforms)
|
|
11
|
+
*
|
|
12
|
+
* Generally should not be used unless you want explicit control over which
|
|
13
|
+
* interfaces are initialized.
|
|
14
|
+
*/
|
|
15
|
+
async function initWasm() {
|
|
16
|
+
await (0, init_js_1.initBridge)(wasm_1.createWasm);
|
|
17
|
+
}
|
|
18
|
+
initWasm().catch(() => {
|
|
19
|
+
// cannot happen, initWasm doesn't throw
|
|
20
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initWasm = initWasm;
|
|
4
|
+
const both_1 = require("@pezkuwi/wasm-crypto-init/both");
|
|
5
|
+
const init_js_1 = require("./init.js");
|
|
6
|
+
/**
|
|
7
|
+
* @name initWasm
|
|
8
|
+
* @description
|
|
9
|
+
* For historic purposes and for tighter control on init, specifically performing
|
|
10
|
+
* a WASM initialization with ASM and an ASM.js fallback
|
|
11
|
+
*
|
|
12
|
+
* Generally should not be used unless you want explicit control over which
|
|
13
|
+
* interfaces are initialized.
|
|
14
|
+
*/
|
|
15
|
+
async function initWasm() {
|
|
16
|
+
await (0, init_js_1.initBridge)(both_1.createWasm);
|
|
17
|
+
}
|
|
18
|
+
initWasm().catch(() => {
|
|
19
|
+
// cannot happen, initWasm doesn't throw
|
|
20
|
+
});
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const util_1 = require("@pezkuwi/util");
|
|
4
|
+
const packageInfo_1 = require("@pezkuwi/wasm-bridge/cjs/packageInfo");
|
|
5
|
+
const packageInfo_2 = require("@pezkuwi/wasm-crypto-asmjs/cjs/packageInfo");
|
|
6
|
+
const packageInfo_3 = require("@pezkuwi/wasm-crypto-init/cjs/packageInfo");
|
|
7
|
+
const packageInfo_4 = require("@pezkuwi/wasm-crypto-wasm/cjs/packageInfo");
|
|
8
|
+
const packageInfo_5 = require("@pezkuwi/wasm-util/cjs/packageInfo");
|
|
9
|
+
const packageInfo_js_1 = require("./packageInfo.js");
|
|
10
|
+
(0, util_1.detectPackage)(packageInfo_js_1.packageInfo, null, [packageInfo_2.packageInfo, packageInfo_1.packageInfo, packageInfo_3.packageInfo, packageInfo_5.packageInfo, packageInfo_4.packageInfo]);
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -1,25 +1,16 @@
|
|
|
1
|
-
// Copyright 2019-2026 @pezkuwi/wasm-crypto authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
1
|
import type { InitFn } from '@pezkuwi/wasm-bridge/types';
|
|
5
2
|
import type { WasmCryptoInstance } from '@pezkuwi/wasm-crypto-init/types';
|
|
6
|
-
|
|
7
3
|
import { Bridge } from '@pezkuwi/wasm-bridge';
|
|
8
|
-
import { createWasm } from '@pezkuwi/wasm-crypto-init';
|
|
9
|
-
|
|
10
4
|
/**
|
|
11
5
|
* @name bridge
|
|
12
6
|
* @description
|
|
13
7
|
* The JS <-> WASM bridge that is in operation. For the specific package
|
|
14
8
|
* it is a global, i.e. all operations happens on this specific bridge
|
|
15
9
|
*/
|
|
16
|
-
export const bridge
|
|
17
|
-
|
|
10
|
+
export declare const bridge: Bridge<WasmCryptoInstance>;
|
|
18
11
|
/**
|
|
19
12
|
* @name initBridge
|
|
20
13
|
* @description
|
|
21
14
|
* Creates a new bridge interface with the (optional) initialization function
|
|
22
15
|
*/
|
|
23
|
-
export
|
|
24
|
-
return bridge.init(createWasm);
|
|
25
|
-
}
|
|
16
|
+
export declare function initBridge(createWasm?: InitFn<WasmCryptoInstance>): Promise<WasmCryptoInstance | null>;
|
package/init.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Bridge } from '@pezkuwi/wasm-bridge';
|
|
2
|
+
import { createWasm } from '@pezkuwi/wasm-crypto-init';
|
|
3
|
+
/**
|
|
4
|
+
* @name bridge
|
|
5
|
+
* @description
|
|
6
|
+
* The JS <-> WASM bridge that is in operation. For the specific package
|
|
7
|
+
* it is a global, i.e. all operations happens on this specific bridge
|
|
8
|
+
*/
|
|
9
|
+
export const bridge = new Bridge(createWasm);
|
|
10
|
+
/**
|
|
11
|
+
* @name initBridge
|
|
12
|
+
* @description
|
|
13
|
+
* Creates a new bridge interface with the (optional) initialization function
|
|
14
|
+
*/
|
|
15
|
+
export async function initBridge(createWasm) {
|
|
16
|
+
return bridge.init(createWasm);
|
|
17
|
+
}
|
package/initNone.d.ts
ADDED
|
@@ -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 no interface whatsoever (no WASM, no 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/none';
|
|
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
|
|
18
|
-
|
|
12
|
+
export async function initWasm() {
|
|
13
|
+
await initBridge(createWasm);
|
|
19
14
|
}
|
|
20
|
-
|
|
21
|
-
initWasm
|
|
22
|
-
// cannot happen, initWasm doesn't throw
|
|
15
|
+
initWasm().catch(() => {
|
|
16
|
+
// cannot happen, initWasm doesn't throw
|
|
23
17
|
});
|