ox 1.0.5 → 1.1.2
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/CHANGELOG.md +77 -0
- package/dist/core/Base64.d.ts +10 -21
- package/dist/core/Base64.d.ts.map +1 -1
- package/dist/core/Base64.js +8 -127
- package/dist/core/Base64.js.map +1 -1
- package/dist/core/BinaryStateTree.d.ts.map +1 -1
- package/dist/core/BinaryStateTree.js +2 -2
- package/dist/core/BinaryStateTree.js.map +1 -1
- package/dist/core/Bls.d.ts.map +1 -1
- package/dist/core/Bls.js +19 -44
- package/dist/core/Bls.js.map +1 -1
- package/dist/core/Ed25519.d.ts.map +1 -1
- package/dist/core/Ed25519.js +7 -6
- package/dist/core/Ed25519.js.map +1 -1
- package/dist/core/Engine.d.ts +156 -0
- package/dist/core/Engine.d.ts.map +1 -0
- package/dist/core/Engine.js +210 -0
- package/dist/core/Engine.js.map +1 -0
- package/dist/core/Hash.d.ts +4 -4
- package/dist/core/Hash.d.ts.map +1 -1
- package/dist/core/Hash.js +9 -12
- package/dist/core/Hash.js.map +1 -1
- package/dist/core/Keystore.d.ts.map +1 -1
- package/dist/core/Keystore.js +15 -10
- package/dist/core/Keystore.js.map +1 -1
- package/dist/core/Mnemonic.d.ts.map +1 -1
- package/dist/core/Mnemonic.js +3 -2
- package/dist/core/Mnemonic.js.map +1 -1
- package/dist/core/P256.d.ts.map +1 -1
- package/dist/core/P256.js +8 -9
- package/dist/core/P256.js.map +1 -1
- package/dist/core/Secp256k1.d.ts.map +1 -1
- package/dist/core/Secp256k1.js +8 -9
- package/dist/core/Secp256k1.js.map +1 -1
- package/dist/core/WebCryptoP256.d.ts.map +1 -1
- package/dist/core/WebCryptoP256.js +2 -2
- package/dist/core/WebCryptoP256.js.map +1 -1
- package/dist/core/X25519.d.ts.map +1 -1
- package/dist/core/X25519.js +4 -3
- package/dist/core/X25519.js.map +1 -1
- package/dist/core/internal/bls.d.ts +12 -0
- package/dist/core/internal/bls.d.ts.map +1 -0
- package/dist/core/internal/bls.js +79 -0
- package/dist/core/internal/bls.js.map +1 -0
- package/dist/core/internal/codec/base64.d.ts +84 -0
- package/dist/core/internal/codec/base64.d.ts.map +1 -0
- package/dist/core/internal/codec/base64.js +177 -0
- package/dist/core/internal/codec/base64.js.map +1 -0
- package/dist/core/internal/codec/hex.d.ts +49 -4
- package/dist/core/internal/codec/hex.d.ts.map +1 -1
- package/dist/core/internal/codec/hex.js +109 -35
- package/dist/core/internal/codec/hex.js.map +1 -1
- package/dist/core/internal/curves.d.ts +17 -0
- package/dist/core/internal/curves.d.ts.map +1 -0
- package/dist/core/internal/curves.js +17 -0
- package/dist/core/internal/curves.js.map +1 -0
- package/dist/core/internal/ed25519.d.ts +14 -0
- package/dist/core/internal/ed25519.d.ts.map +1 -0
- package/dist/core/internal/ed25519.js +29 -0
- package/dist/core/internal/ed25519.js.map +1 -0
- package/dist/core/internal/engine.d.ts +278 -0
- package/dist/core/internal/engine.d.ts.map +1 -0
- package/dist/core/internal/engine.js +131 -0
- package/dist/core/internal/engine.js.map +1 -0
- package/dist/core/internal/hash.d.ts +12 -0
- package/dist/core/internal/hash.d.ts.map +1 -0
- package/dist/core/internal/hash.js +30 -0
- package/dist/core/internal/hash.js.map +1 -0
- package/dist/core/internal/keystore.d.ts +14 -0
- package/dist/core/internal/keystore.d.ts.map +1 -0
- package/dist/core/internal/keystore.js +32 -0
- package/dist/core/internal/keystore.js.map +1 -0
- package/dist/core/internal/mnemonic.d.ts +4 -0
- package/dist/core/internal/mnemonic.d.ts.map +1 -0
- package/dist/core/internal/mnemonic.js +14 -0
- package/dist/core/internal/mnemonic.js.map +1 -0
- package/dist/core/internal/p256.d.ts +14 -0
- package/dist/core/internal/p256.d.ts.map +1 -0
- package/dist/core/internal/p256.js +36 -0
- package/dist/core/internal/p256.js.map +1 -0
- package/dist/core/internal/secp256k1.d.ts +14 -0
- package/dist/core/internal/secp256k1.d.ts.map +1 -0
- package/dist/core/internal/secp256k1.js +36 -0
- package/dist/core/internal/secp256k1.js.map +1 -0
- package/dist/core/internal/x25519.d.ts +8 -0
- package/dist/core/internal/x25519.d.ts.map +1 -0
- package/dist/core/internal/x25519.js +20 -0
- package/dist/core/internal/x25519.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.docs.d.ts +2 -0
- package/dist/index.docs.d.ts.map +1 -1
- package/dist/index.docs.js +2 -0
- package/dist/index.docs.js.map +1 -1
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -1
- package/dist/node/Ed25519.d.ts +33 -0
- package/dist/node/Ed25519.d.ts.map +1 -0
- package/dist/node/Ed25519.js +67 -0
- package/dist/node/Ed25519.js.map +1 -0
- package/dist/node/Engine.d.ts +68 -0
- package/dist/node/Engine.d.ts.map +1 -0
- package/dist/node/Engine.js +75 -0
- package/dist/node/Engine.js.map +1 -0
- package/dist/node/Hash.d.ts +37 -0
- package/dist/node/Hash.d.ts.map +1 -0
- package/dist/node/Hash.js +35 -0
- package/dist/node/Hash.js.map +1 -0
- package/dist/node/Keystore.d.ts +36 -0
- package/dist/node/Keystore.d.ts.map +1 -0
- package/dist/node/Keystore.js +72 -0
- package/dist/node/Keystore.js.map +1 -0
- package/dist/node/Mnemonic.d.ts +35 -0
- package/dist/node/Mnemonic.d.ts.map +1 -0
- package/dist/node/Mnemonic.js +46 -0
- package/dist/node/Mnemonic.js.map +1 -0
- package/dist/node/P256.d.ts +32 -0
- package/dist/node/P256.d.ts.map +1 -0
- package/dist/node/P256.js +34 -0
- package/dist/node/P256.js.map +1 -0
- package/dist/node/X25519.d.ts +31 -0
- package/dist/node/X25519.d.ts.map +1 -0
- package/dist/node/X25519.js +71 -0
- package/dist/node/X25519.js.map +1 -0
- package/dist/node/index.d.ts +126 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +126 -0
- package/dist/node/index.js.map +1 -0
- package/dist/tempo/VirtualMaster.d.ts +2 -0
- package/dist/tempo/VirtualMaster.d.ts.map +1 -1
- package/dist/tempo/VirtualMaster.js +19 -5
- package/dist/tempo/VirtualMaster.js.map +1 -1
- package/dist/tempo/internal/mine.wasm.d.ts +2 -4
- package/dist/tempo/internal/mine.wasm.d.ts.map +1 -1
- package/dist/tempo/internal/mine.wasm.js +7 -12
- package/dist/tempo/internal/mine.wasm.js.map +1 -1
- package/dist/tempo/internal/virtualMasterPool.js +4 -1
- package/dist/tempo/internal/virtualMasterPool.js.map +1 -1
- package/dist/wasm/Ed25519.d.ts +35 -0
- package/dist/wasm/Ed25519.d.ts.map +1 -0
- package/dist/wasm/Ed25519.js +88 -0
- package/dist/wasm/Ed25519.js.map +1 -0
- package/dist/wasm/Engine.d.ts +71 -0
- package/dist/wasm/Engine.d.ts.map +1 -0
- package/dist/wasm/Engine.js +76 -0
- package/dist/wasm/Engine.js.map +1 -0
- package/dist/wasm/Hash.d.ts +43 -0
- package/dist/wasm/Hash.d.ts.map +1 -0
- package/dist/wasm/Hash.js +64 -0
- package/dist/wasm/Hash.js.map +1 -0
- package/dist/wasm/Keystore.d.ts +37 -0
- package/dist/wasm/Keystore.d.ts.map +1 -0
- package/dist/wasm/Keystore.js +34 -0
- package/dist/wasm/Keystore.js.map +1 -0
- package/dist/wasm/Mnemonic.d.ts +33 -0
- package/dist/wasm/Mnemonic.d.ts.map +1 -0
- package/dist/wasm/Mnemonic.js +30 -0
- package/dist/wasm/Mnemonic.js.map +1 -0
- package/dist/wasm/X25519.d.ts +33 -0
- package/dist/wasm/X25519.d.ts.map +1 -0
- package/dist/wasm/X25519.js +53 -0
- package/dist/wasm/X25519.js.map +1 -0
- package/dist/wasm/index.d.ts +115 -0
- package/dist/wasm/index.d.ts.map +1 -0
- package/dist/wasm/index.js +115 -0
- package/dist/wasm/index.js.map +1 -0
- package/dist/wasm/internal/blake3.d.ts +11 -0
- package/dist/wasm/internal/blake3.d.ts.map +1 -0
- package/dist/wasm/internal/blake3.js +31 -0
- package/dist/wasm/internal/blake3.js.map +1 -0
- package/dist/wasm/internal/blake3.wasm.d.ts +3 -0
- package/dist/wasm/internal/blake3.wasm.d.ts.map +1 -0
- package/dist/wasm/internal/blake3.wasm.js +10 -0
- package/dist/wasm/internal/blake3.wasm.js.map +1 -0
- package/dist/wasm/internal/crypto25519.d.ts +16 -0
- package/dist/wasm/internal/crypto25519.d.ts.map +1 -0
- package/dist/wasm/internal/crypto25519.js +5 -0
- package/dist/wasm/internal/crypto25519.js.map +1 -0
- package/dist/wasm/internal/crypto25519.wasm.d.ts +3 -0
- package/dist/wasm/internal/crypto25519.wasm.d.ts.map +1 -0
- package/dist/wasm/internal/crypto25519.wasm.js +10 -0
- package/dist/wasm/internal/crypto25519.wasm.js.map +1 -0
- package/dist/wasm/internal/ed25519.d.ts +4 -0
- package/dist/wasm/internal/ed25519.d.ts.map +1 -0
- package/dist/wasm/internal/ed25519.js +21 -0
- package/dist/wasm/internal/ed25519.js.map +1 -0
- package/dist/wasm/internal/hash.d.ts +9 -0
- package/dist/wasm/internal/hash.d.ts.map +1 -0
- package/dist/wasm/internal/hash.js +26 -0
- package/dist/wasm/internal/hash.js.map +1 -0
- package/dist/wasm/internal/hashes.d.ts +12 -0
- package/dist/wasm/internal/hashes.d.ts.map +1 -0
- package/dist/wasm/internal/hashes.js +8 -0
- package/dist/wasm/internal/hashes.js.map +1 -0
- package/dist/wasm/internal/hashes.wasm.d.ts +7 -0
- package/dist/wasm/internal/hashes.wasm.d.ts.map +1 -0
- package/dist/wasm/internal/hashes.wasm.js +14 -0
- package/dist/wasm/internal/hashes.wasm.js.map +1 -0
- package/dist/wasm/internal/instantiate.d.ts +56 -0
- package/dist/wasm/internal/instantiate.d.ts.map +1 -0
- package/dist/wasm/internal/instantiate.js +92 -0
- package/dist/wasm/internal/instantiate.js.map +1 -0
- package/dist/wasm/internal/mnemonic.d.ts +4 -0
- package/dist/wasm/internal/mnemonic.d.ts.map +1 -0
- package/dist/wasm/internal/mnemonic.js +45 -0
- package/dist/wasm/internal/mnemonic.js.map +1 -0
- package/dist/wasm/internal/pbkdf2.d.ts +12 -0
- package/dist/wasm/internal/pbkdf2.d.ts.map +1 -0
- package/dist/wasm/internal/pbkdf2.js +51 -0
- package/dist/wasm/internal/pbkdf2.js.map +1 -0
- package/dist/wasm/internal/x25519.d.ts +4 -0
- package/dist/wasm/internal/x25519.d.ts.map +1 -0
- package/dist/wasm/internal/x25519.js +21 -0
- package/dist/wasm/internal/x25519.js.map +1 -0
- package/dist/zod/TypedData.d.ts +12 -12
- package/package.json +81 -1
- package/src/core/Base64.ts +19 -166
- package/src/core/BinaryStateTree.ts +2 -3
- package/src/core/Bls.ts +27 -77
- package/src/core/Ed25519.ts +7 -7
- package/src/core/Engine.ts +308 -0
- package/src/core/Hash.ts +9 -12
- package/src/core/Keystore.ts +17 -17
- package/src/core/Mnemonic.ts +3 -6
- package/src/core/P256.ts +15 -24
- package/src/core/Rlp_tx.bench.ts +2 -4
- package/src/core/Secp256k1.ts +9 -14
- package/src/core/TxEnvelopeEip1559.bench.ts +0 -5
- package/src/core/WebCryptoP256.ts +2 -2
- package/src/core/X25519.ts +4 -3
- package/src/core/_test/AbiParameters.adversarial.fuzz.ts +1 -2
- package/src/core/_test/AbiParameters.fuzz.ts +1 -2
- package/src/core/_test/Base.fuzz.ts +1 -2
- package/src/core/_test/Cbor.fuzz.ts +1 -2
- package/src/core/_test/Engine.fuzz.ts +293 -0
- package/src/core/_test/Engine.test-d.ts +140 -0
- package/src/core/_test/Engine.test.ts +618 -0
- package/src/core/_test/Hash.vectors.test.ts +64 -0
- package/src/core/_test/Hex.fuzz.ts +1 -2
- package/src/core/_test/Rlp.fuzz.ts +1 -2
- package/src/core/_test/Signature.fuzz.ts +1 -2
- package/src/core/_test/curves.test.ts +7 -0
- package/src/core/_test/index.test.ts +1 -0
- package/src/core/internal/bls.ts +121 -0
- package/src/core/internal/codec/_test/base64.conformance.ts +156 -0
- package/src/core/internal/codec/_test/hex.conformance.ts +204 -0
- package/src/core/internal/codec/_test/hex.fuzz.ts +234 -0
- package/src/core/internal/codec/_test/hex.test.ts +124 -0
- package/src/core/internal/codec/base64.ts +222 -0
- package/src/core/internal/codec/hex.ts +115 -34
- package/src/core/internal/curves.ts +18 -0
- package/src/core/internal/ed25519.ts +64 -0
- package/src/core/internal/engine.ts +410 -0
- package/src/core/internal/hash.ts +48 -0
- package/src/core/internal/keystore.ts +107 -0
- package/src/core/internal/mnemonic.ts +18 -0
- package/src/core/internal/p256.ts +91 -0
- package/src/core/internal/secp256k1.ts +91 -0
- package/src/core/internal/x25519.ts +40 -0
- package/src/index.docs.ts +2 -0
- package/src/index.ts +39 -0
- package/src/node/Ed25519.ts +87 -0
- package/src/node/Engine.ts +125 -0
- package/src/node/Hash.ts +51 -0
- package/src/node/Keystore.ts +103 -0
- package/src/node/Mnemonic.ts +68 -0
- package/src/node/P256.ts +48 -0
- package/src/node/X25519.ts +93 -0
- package/src/node/_test/Curves.fuzz.ts +76 -0
- package/src/node/_test/Ed25519.test-d.ts +35 -0
- package/src/node/_test/Ed25519.test.ts +220 -0
- package/src/node/_test/Engine.test-d.ts +28 -0
- package/src/node/_test/Engine.test.ts +102 -0
- package/src/node/_test/Hash.test-d.ts +32 -0
- package/src/node/_test/Hash.test.ts +101 -0
- package/src/node/_test/Keystore.fuzz.ts +58 -0
- package/src/node/_test/Keystore.test-d.ts +43 -0
- package/src/node/_test/Keystore.test.ts +198 -0
- package/src/node/_test/Mnemonic.fuzz.ts +31 -0
- package/src/node/_test/Mnemonic.test-d.ts +21 -0
- package/src/node/_test/Mnemonic.test.ts +98 -0
- package/src/node/_test/P256.test-d.ts +29 -0
- package/src/node/_test/P256.test.ts +102 -0
- package/src/node/_test/X25519.test-d.ts +28 -0
- package/src/node/_test/X25519.test.ts +239 -0
- package/src/node/index.ts +132 -0
- package/src/tempo/VirtualMaster.test.ts +75 -0
- package/src/tempo/VirtualMaster.ts +28 -6
- package/src/tempo/internal/mine.wasm.ts +7 -13
- package/src/tempo/internal/virtualMasterPool.ts +4 -1
- package/src/tsconfig.json +2 -1
- package/src/version.ts +1 -1
- package/src/wasm/Ed25519.ts +114 -0
- package/src/wasm/Engine.ts +121 -0
- package/src/wasm/Hash.bench.ts +60 -0
- package/src/wasm/Hash.ts +88 -0
- package/src/wasm/Keystore.ts +48 -0
- package/src/wasm/Mnemonic.ts +44 -0
- package/src/wasm/X25519.ts +70 -0
- package/src/wasm/_test/Crypto25519.conformance.ts +57 -0
- package/src/wasm/_test/Crypto25519.fuzz.ts +187 -0
- package/src/wasm/_test/Ed25519.test-d.ts +28 -0
- package/src/wasm/_test/Ed25519.test.ts +168 -0
- package/src/wasm/_test/Ed25519.vectors.test.ts +73 -0
- package/src/wasm/_test/Engine.test-d.ts +28 -0
- package/src/wasm/_test/Engine.test.ts +96 -0
- package/src/wasm/_test/Hash.browser.test.ts +54 -0
- package/src/wasm/_test/Hash.fuzz.ts +223 -0
- package/src/wasm/_test/Hash.test-d.ts +33 -0
- package/src/wasm/_test/Hash.test.ts +311 -0
- package/src/wasm/_test/Hash.vectors.test.ts +124 -0
- package/src/wasm/_test/Keystore.browser.test.ts +42 -0
- package/src/wasm/_test/Keystore.fuzz.ts +113 -0
- package/src/wasm/_test/Keystore.test-d.ts +33 -0
- package/src/wasm/_test/Keystore.test.ts +192 -0
- package/src/wasm/_test/Keystore.vectors.test.ts +21 -0
- package/src/wasm/_test/Mnemonic.test-d.ts +17 -0
- package/src/wasm/_test/Mnemonic.test.ts +110 -0
- package/src/wasm/_test/Runtime.test.ts +21 -0
- package/src/wasm/_test/X25519.test-d.ts +21 -0
- package/src/wasm/_test/X25519.test.ts +194 -0
- package/src/wasm/_test/fixtures.ts +4 -0
- package/src/wasm/_test/runtime.wasm.ts +11 -0
- package/src/wasm/index.ts +120 -0
- package/src/wasm/internal/blake3.ts +45 -0
- package/src/wasm/internal/blake3.wasm.ts +11 -0
- package/src/wasm/internal/crypto25519.ts +43 -0
- package/src/wasm/internal/crypto25519.wasm.ts +11 -0
- package/src/wasm/internal/ed25519.ts +31 -0
- package/src/wasm/internal/hash.ts +50 -0
- package/src/wasm/internal/hashes.ts +29 -0
- package/src/wasm/internal/hashes.wasm.ts +17 -0
- package/src/wasm/internal/instantiate.ts +135 -0
- package/src/wasm/internal/mnemonic.ts +56 -0
- package/src/wasm/internal/pbkdf2.ts +86 -0
- package/src/wasm/internal/x25519.ts +29 -0
- package/src/tempo/internal/mine.c +0 -182
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as CoreEngine from '../core/Engine.js';
|
|
2
|
+
import * as Ed25519 from './Ed25519.js';
|
|
3
|
+
import * as Hash from './Hash.js';
|
|
4
|
+
import * as Keystore from './Keystore.js';
|
|
5
|
+
import * as Mnemonic from './Mnemonic.js';
|
|
6
|
+
import * as X25519 from './X25519.js';
|
|
7
|
+
export { AsyncScopeError, get, InvalidSlotValueError, reset, set, UnknownPrimitiveError, UnknownSlotError, with, } from '../core/Engine.js';
|
|
8
|
+
/**
|
|
9
|
+
* Compiles and installs every WASM implementation this entrypoint provides.
|
|
10
|
+
*
|
|
11
|
+
* Slot compilation starts concurrently. Nothing is installed until every slot
|
|
12
|
+
* resolves successfully.
|
|
13
|
+
*
|
|
14
|
+
* Call this once, during startup, before any crypto call. Ox resolves the
|
|
15
|
+
* engine at call time, so values computed beforehand used whatever was
|
|
16
|
+
* installed then.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts twoslash
|
|
20
|
+
* // @noErrors
|
|
21
|
+
* import { Engine, Hash } from 'ox/wasm'
|
|
22
|
+
*
|
|
23
|
+
* await Engine.install()
|
|
24
|
+
*
|
|
25
|
+
* Hash.sha256('0xdeadbeef')
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @returns The engine that was installed.
|
|
29
|
+
*/
|
|
30
|
+
export async function install() {
|
|
31
|
+
return CoreEngine.install({
|
|
32
|
+
Ed25519: Ed25519.engine(),
|
|
33
|
+
Hash: Hash.engine(),
|
|
34
|
+
Keystore: Keystore.engine(),
|
|
35
|
+
Mnemonic: Mnemonic.engine(),
|
|
36
|
+
X25519: X25519.engine(),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Compiles every WASM implementation this entrypoint provides, without
|
|
41
|
+
* installing it.
|
|
42
|
+
*
|
|
43
|
+
* Reach for this where an engine has to exist as a value, such as a benchmark
|
|
44
|
+
* or an [`Engine.with`](/api/Engine/with) scope. Use the individual module's
|
|
45
|
+
* `engine` function to select only some slots.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts twoslash
|
|
49
|
+
* // @noErrors
|
|
50
|
+
* import { Engine, Hash } from 'ox'
|
|
51
|
+
* import { Engine as Wasm } from 'ox/wasm'
|
|
52
|
+
*
|
|
53
|
+
* const wasm = await Wasm.engine()
|
|
54
|
+
*
|
|
55
|
+
* Engine.with(wasm, () => Hash.sha256('0xdeadbeef'))
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @returns An engine, ready to install.
|
|
59
|
+
*/
|
|
60
|
+
export async function engine() {
|
|
61
|
+
const [ed25519, hash, keystore, mnemonic, x25519] = await Promise.all([
|
|
62
|
+
Ed25519.engine(),
|
|
63
|
+
Hash.engine(),
|
|
64
|
+
Keystore.engine(),
|
|
65
|
+
Mnemonic.engine(),
|
|
66
|
+
X25519.engine(),
|
|
67
|
+
]);
|
|
68
|
+
return {
|
|
69
|
+
Ed25519: ed25519,
|
|
70
|
+
Hash: hash,
|
|
71
|
+
Keystore: keystore,
|
|
72
|
+
Mnemonic: mnemonic,
|
|
73
|
+
X25519: x25519,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=Engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Engine.js","sourceRoot":"","sources":["../../src/wasm/Engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAE/C,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAGrC,OAAO,EACL,eAAe,EACf,GAAG,EACH,qBAAqB,EACrB,KAAK,EACL,GAAG,EACH,qBAAqB,EACrB,gBAAgB,EAChB,IAAI,GACL,MAAM,mBAAmB,CAAA;AAY1B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO;IAC3B,OAAO,UAAU,CAAC,OAAO,CAAC;QACxB,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE;QACzB,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;QACnB,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE;QAC3B,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE;QAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;KACxB,CAAC,CAAA;AACJ,CAAC;AAWD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM;IAC1B,MAAM,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACpE,OAAO,CAAC,MAAM,EAAE;QAChB,IAAI,CAAC,MAAM,EAAE;QACb,QAAQ,CAAC,MAAM,EAAE;QACjB,QAAQ,CAAC,MAAM,EAAE;QACjB,MAAM,CAAC,MAAM,EAAE;KAChB,CAAC,CAAA;IACF,OAAO;QACL,OAAO,EAAE,OAAO;QAChB,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,QAAQ;QAClB,QAAQ,EAAE,QAAQ;QAClB,MAAM,EAAE,MAAM;KACf,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type * as Engine from '../core/Engine.js';
|
|
2
|
+
import type * as Errors from '../core/Errors.js';
|
|
3
|
+
import * as internal from './internal/instantiate.js';
|
|
4
|
+
export * from '../core/Hash.js';
|
|
5
|
+
export { MemoryError } from './internal/instantiate.js';
|
|
6
|
+
/**
|
|
7
|
+
* Compiles the WASM implementation of the [`Hash`](/api/Hash) primitives,
|
|
8
|
+
* without installing it.
|
|
9
|
+
*
|
|
10
|
+
* Most callers want
|
|
11
|
+
* [`Engine.install`](/wasm/crypto/Engine/install) instead, which compiles every
|
|
12
|
+
* implementation this entrypoint provides and installs them in one call. Reach
|
|
13
|
+
* for this to take the `Hash` slot on its own, or to hold the implementation
|
|
14
|
+
* without touching the installed engine.
|
|
15
|
+
*
|
|
16
|
+
* :::note
|
|
17
|
+
* Performance varies by primitive, input size, runtime, and processor. Run
|
|
18
|
+
* `pnpm bench:engines` to compare Ox's default, Node, WASM, and Alloy
|
|
19
|
+
* implementations on your target machine.
|
|
20
|
+
* :::
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts twoslash
|
|
24
|
+
* // @noErrors
|
|
25
|
+
* import { Engine } from 'ox'
|
|
26
|
+
* import { Hash } from 'ox/wasm'
|
|
27
|
+
*
|
|
28
|
+
* await Engine.install({ Hash: Hash.engine() })
|
|
29
|
+
*
|
|
30
|
+
* Hash.keccak256('0xdeadbeef')
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @returns The WASM implementation of the `Hash` slot.
|
|
34
|
+
*/
|
|
35
|
+
export declare function engine(): Promise<engine.ReturnType>;
|
|
36
|
+
export declare namespace engine {
|
|
37
|
+
/** Every `Hash` primitive this module implements. */
|
|
38
|
+
type ReturnType = {
|
|
39
|
+
[key in 'blake3' | 'hmacSha256' | 'keccak256' | 'ripemd160' | 'sha256']-?: NonNullable<Engine.Hash[key]>;
|
|
40
|
+
};
|
|
41
|
+
type ErrorType = internal.MemoryError | Errors.GlobalErrorType;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=Hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Hash.d.ts","sourceRoot":"","sources":["../../src/wasm/Hash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAIhD,OAAO,KAAK,QAAQ,MAAM,2BAA2B,CAAA;AAErD,cAAc,iBAAiB,CAAA;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAKvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CA+BzD;AAED,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,qDAAqD;IACrD,KAAK,UAAU,GAAG;SACf,GAAG,IACA,QAAQ,GACR,YAAY,GACZ,WAAW,GACX,WAAW,GACX,QAAQ,CAAC,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KAC/C,CAAA;IAED,KAAK,SAAS,GAAG,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,eAAe,CAAA;CAC/D"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as blake3 from './internal/blake3.js';
|
|
2
|
+
import * as hash from './internal/hash.js';
|
|
3
|
+
import * as hashes from './internal/hashes.js';
|
|
4
|
+
export * from '../core/Hash.js';
|
|
5
|
+
export { MemoryError } from './internal/instantiate.js';
|
|
6
|
+
/** Digest sizes, in bytes. */
|
|
7
|
+
const digestSize = { keccak256: 32, ripemd160: 20, sha256: 32 };
|
|
8
|
+
/**
|
|
9
|
+
* Compiles the WASM implementation of the [`Hash`](/api/Hash) primitives,
|
|
10
|
+
* without installing it.
|
|
11
|
+
*
|
|
12
|
+
* Most callers want
|
|
13
|
+
* [`Engine.install`](/wasm/crypto/Engine/install) instead, which compiles every
|
|
14
|
+
* implementation this entrypoint provides and installs them in one call. Reach
|
|
15
|
+
* for this to take the `Hash` slot on its own, or to hold the implementation
|
|
16
|
+
* without touching the installed engine.
|
|
17
|
+
*
|
|
18
|
+
* :::note
|
|
19
|
+
* Performance varies by primitive, input size, runtime, and processor. Run
|
|
20
|
+
* `pnpm bench:engines` to compare Ox's default, Node, WASM, and Alloy
|
|
21
|
+
* implementations on your target machine.
|
|
22
|
+
* :::
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts twoslash
|
|
26
|
+
* // @noErrors
|
|
27
|
+
* import { Engine } from 'ox'
|
|
28
|
+
* import { Hash } from 'ox/wasm'
|
|
29
|
+
*
|
|
30
|
+
* await Engine.install({ Hash: Hash.engine() })
|
|
31
|
+
*
|
|
32
|
+
* Hash.keccak256('0xdeadbeef')
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @returns The WASM implementation of the `Hash` slot.
|
|
36
|
+
*/
|
|
37
|
+
export async function engine() {
|
|
38
|
+
{
|
|
39
|
+
const [blake3Module, module] = await Promise.all([
|
|
40
|
+
blake3.load(),
|
|
41
|
+
hashes.load(),
|
|
42
|
+
]);
|
|
43
|
+
// Copies `input` in, runs `hash`, and copies the digest back out.
|
|
44
|
+
function call(hash, input) {
|
|
45
|
+
const out = digestSize[hash];
|
|
46
|
+
module.reserve(input.length + out);
|
|
47
|
+
const inputPtr = module.heapBase;
|
|
48
|
+
const outPtr = inputPtr + input.length;
|
|
49
|
+
module.view().set(input, inputPtr);
|
|
50
|
+
module.exports[hash](inputPtr, input.length, outPtr);
|
|
51
|
+
// `slice`, not `subarray`: the result must not alias WASM memory, which the
|
|
52
|
+
// next call overwrites and a `grow` detaches entirely.
|
|
53
|
+
return module.view().slice(outPtr, outPtr + out);
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
blake3: (input) => blake3.hash(blake3Module, input),
|
|
57
|
+
hmacSha256: (key, message) => hash.hmacSha256(module, key, message),
|
|
58
|
+
keccak256: (input) => call('keccak256', input),
|
|
59
|
+
ripemd160: (input) => call('ripemd160', input),
|
|
60
|
+
sha256: (input) => call('sha256', input),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=Hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Hash.js","sourceRoot":"","sources":["../../src/wasm/Hash.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAA;AAC9C,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC1C,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAA;AAG9C,cAAc,iBAAiB,CAAA;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAEvD,8BAA8B;AAC9B,MAAM,UAAU,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAA;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM;IAC1B,CAAC;QACC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YAC/C,MAAM,CAAC,IAAI,EAAE;YACb,MAAM,CAAC,IAAI,EAAE;SACd,CAAC,CAAA;QAEF,kEAAkE;QAClE,SAAS,IAAI,CACX,IAA0C,EAC1C,KAAiB;YAEjB,MAAM,GAAG,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;YAC5B,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG,CAAC,CAAA;YAClC,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAA;YAChC,MAAM,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAA;YACtC,MAAM,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;YAClC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;YACpD,4EAA4E;YAC5E,uDAAuD;YACvD,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,CAAA;QAClD,CAAC;QAED,OAAO;YACL,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC;YACnD,UAAU,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC;YACnE,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC;YAC9C,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC;YAC9C,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC;SACzC,CAAA;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type * as Engine from '../core/Engine.js';
|
|
2
|
+
import type * as Errors from '../core/Errors.js';
|
|
3
|
+
import * as internal from './internal/instantiate.js';
|
|
4
|
+
export * from '../core/Keystore.js';
|
|
5
|
+
export { MemoryError } from './internal/instantiate.js';
|
|
6
|
+
/**
|
|
7
|
+
* Compiles the WASM implementation of the [`Keystore`](/api/Keystore) PBKDF2
|
|
8
|
+
* primitive, without installing it.
|
|
9
|
+
*
|
|
10
|
+
* Most callers want
|
|
11
|
+
* [`Engine.install`](/wasm/crypto/Engine/install) instead, which compiles every
|
|
12
|
+
* implementation this entrypoint provides and installs them in one call. This
|
|
13
|
+
* provider deliberately stays synchronous and leaves AES, asynchronous PBKDF2,
|
|
14
|
+
* and scrypt on Ox's default implementation.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts twoslash
|
|
18
|
+
* // @noErrors
|
|
19
|
+
* import { Engine } from 'ox'
|
|
20
|
+
* import { Keystore } from 'ox/wasm'
|
|
21
|
+
*
|
|
22
|
+
* await Engine.install({ Keystore: Keystore.engine() })
|
|
23
|
+
*
|
|
24
|
+
* Keystore.pbkdf2({ password: 'testpassword' })
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @returns The WASM implementation of synchronous PBKDF2-HMAC-SHA256.
|
|
28
|
+
*/
|
|
29
|
+
export declare function engine(): Promise<engine.ReturnType>;
|
|
30
|
+
export declare namespace engine {
|
|
31
|
+
/** The WASM `Keystore` primitives this module implements. */
|
|
32
|
+
type ReturnType = {
|
|
33
|
+
pbkdf2Sha256: NonNullable<Engine.Keystore['pbkdf2Sha256']>;
|
|
34
|
+
};
|
|
35
|
+
type ErrorType = internal.MemoryError | Errors.GlobalErrorType;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=Keystore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Keystore.d.ts","sourceRoot":"","sources":["../../src/wasm/Keystore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAEhD,OAAO,KAAK,QAAQ,MAAM,2BAA2B,CAAA;AAGrD,cAAc,qBAAqB,CAAA;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAEvD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAMzD;AAED,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,6DAA6D;IAC7D,KAAK,UAAU,GAAG;QAChB,YAAY,EAAE,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAA;KAC3D,CAAA;IAED,KAAK,SAAS,GAAG,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,eAAe,CAAA;CAC/D"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as hashes from './internal/hashes.js';
|
|
2
|
+
import * as pbkdf2 from './internal/pbkdf2.js';
|
|
3
|
+
export * from '../core/Keystore.js';
|
|
4
|
+
export { MemoryError } from './internal/instantiate.js';
|
|
5
|
+
/**
|
|
6
|
+
* Compiles the WASM implementation of the [`Keystore`](/api/Keystore) PBKDF2
|
|
7
|
+
* primitive, without installing it.
|
|
8
|
+
*
|
|
9
|
+
* Most callers want
|
|
10
|
+
* [`Engine.install`](/wasm/crypto/Engine/install) instead, which compiles every
|
|
11
|
+
* implementation this entrypoint provides and installs them in one call. This
|
|
12
|
+
* provider deliberately stays synchronous and leaves AES, asynchronous PBKDF2,
|
|
13
|
+
* and scrypt on Ox's default implementation.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts twoslash
|
|
17
|
+
* // @noErrors
|
|
18
|
+
* import { Engine } from 'ox'
|
|
19
|
+
* import { Keystore } from 'ox/wasm'
|
|
20
|
+
*
|
|
21
|
+
* await Engine.install({ Keystore: Keystore.engine() })
|
|
22
|
+
*
|
|
23
|
+
* Keystore.pbkdf2({ password: 'testpassword' })
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @returns The WASM implementation of synchronous PBKDF2-HMAC-SHA256.
|
|
27
|
+
*/
|
|
28
|
+
export async function engine() {
|
|
29
|
+
const module = await hashes.load();
|
|
30
|
+
return {
|
|
31
|
+
pbkdf2Sha256: (password, salt, options) => pbkdf2.pbkdf2Sha256(module, password, salt, options),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=Keystore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Keystore.js","sourceRoot":"","sources":["../../src/wasm/Keystore.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAA;AAE9C,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAA;AAE9C,cAAc,qBAAqB,CAAA;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAEvD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM;IAC1B,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;IAClC,OAAO;QACL,YAAY,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CACxC,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC;KACvD,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type * as Engine from '../core/Engine.js';
|
|
2
|
+
import type * as Errors from '../core/Errors.js';
|
|
3
|
+
import * as internal from './internal/instantiate.js';
|
|
4
|
+
export * from '../core/Mnemonic.js';
|
|
5
|
+
export { MemoryError } from './internal/instantiate.js';
|
|
6
|
+
/**
|
|
7
|
+
* Compiles the WASM implementation of [`Mnemonic.toSeed`](/api/Mnemonic/toSeed),
|
|
8
|
+
* without installing it.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts twoslash
|
|
12
|
+
* // @noErrors
|
|
13
|
+
* import { Engine } from 'ox'
|
|
14
|
+
* import { Mnemonic } from 'ox/wasm'
|
|
15
|
+
*
|
|
16
|
+
* await Engine.install({ Mnemonic: Mnemonic.engine() })
|
|
17
|
+
*
|
|
18
|
+
* Mnemonic.toSeed(
|
|
19
|
+
* 'test test test test test test test test test test test junk'
|
|
20
|
+
* )
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @returns The WASM implementation of the `Mnemonic` slot.
|
|
24
|
+
*/
|
|
25
|
+
export declare function engine(): Promise<engine.ReturnType>;
|
|
26
|
+
export declare namespace engine {
|
|
27
|
+
/** Every `Mnemonic` primitive this module implements. */
|
|
28
|
+
type ReturnType = {
|
|
29
|
+
toSeed: NonNullable<Engine.Mnemonic['toSeed']>;
|
|
30
|
+
};
|
|
31
|
+
type ErrorType = internal.MemoryError | Errors.GlobalErrorType;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=Mnemonic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Mnemonic.d.ts","sourceRoot":"","sources":["../../src/wasm/Mnemonic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAEhD,OAAO,KAAK,QAAQ,MAAM,2BAA2B,CAAA;AAGrD,cAAc,qBAAqB,CAAA;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAEvD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAMzD;AAED,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,yDAAyD;IACzD,KAAK,UAAU,GAAG;QAChB,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAA;KAC/C,CAAA;IAED,KAAK,SAAS,GAAG,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,eAAe,CAAA;CAC/D"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as crypto25519 from './internal/crypto25519.js';
|
|
2
|
+
import * as mnemonic from './internal/mnemonic.js';
|
|
3
|
+
export * from '../core/Mnemonic.js';
|
|
4
|
+
export { MemoryError } from './internal/instantiate.js';
|
|
5
|
+
/**
|
|
6
|
+
* Compiles the WASM implementation of [`Mnemonic.toSeed`](/api/Mnemonic/toSeed),
|
|
7
|
+
* without installing it.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts twoslash
|
|
11
|
+
* // @noErrors
|
|
12
|
+
* import { Engine } from 'ox'
|
|
13
|
+
* import { Mnemonic } from 'ox/wasm'
|
|
14
|
+
*
|
|
15
|
+
* await Engine.install({ Mnemonic: Mnemonic.engine() })
|
|
16
|
+
*
|
|
17
|
+
* Mnemonic.toSeed(
|
|
18
|
+
* 'test test test test test test test test test test test junk'
|
|
19
|
+
* )
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @returns The WASM implementation of the `Mnemonic` slot.
|
|
23
|
+
*/
|
|
24
|
+
export async function engine() {
|
|
25
|
+
const module = await crypto25519.load();
|
|
26
|
+
return {
|
|
27
|
+
toSeed: (value, passphrase) => mnemonic.toSeed(module, value, passphrase),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=Mnemonic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Mnemonic.js","sourceRoot":"","sources":["../../src/wasm/Mnemonic.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,WAAW,MAAM,2BAA2B,CAAA;AAExD,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAA;AAElD,cAAc,qBAAqB,CAAA;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAEvD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM;IAC1B,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,IAAI,EAAE,CAAA;IAEvC,OAAO;QACL,MAAM,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC;KAC1E,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type * as Engine from '../core/Engine.js';
|
|
2
|
+
import type * as Errors from '../core/Errors.js';
|
|
3
|
+
import * as internal from './internal/instantiate.js';
|
|
4
|
+
export * from '../core/X25519.js';
|
|
5
|
+
export { MemoryError } from './internal/instantiate.js';
|
|
6
|
+
/**
|
|
7
|
+
* Compiles WASM implementations of selected [`X25519`](/api/X25519)
|
|
8
|
+
* primitives, without installing them.
|
|
9
|
+
*
|
|
10
|
+
* Random key generation remains on Ox's default implementation.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts twoslash
|
|
14
|
+
* // @noErrors
|
|
15
|
+
* import { Engine } from 'ox'
|
|
16
|
+
* import { X25519 } from 'ox/wasm'
|
|
17
|
+
*
|
|
18
|
+
* await Engine.install({ X25519: X25519.engine() })
|
|
19
|
+
*
|
|
20
|
+
* X25519.getPublicKey({ privateKey: '0x...' })
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @returns The WASM implementation of part of the `X25519` slot.
|
|
24
|
+
*/
|
|
25
|
+
export declare function engine(): Promise<engine.ReturnType>;
|
|
26
|
+
export declare namespace engine {
|
|
27
|
+
/** Every `X25519` primitive this module implements. */
|
|
28
|
+
type ReturnType = {
|
|
29
|
+
[key in 'getPublicKey' | 'getSharedSecret']-?: NonNullable<Engine.Ecdh[key]>;
|
|
30
|
+
};
|
|
31
|
+
type ErrorType = internal.MemoryError | Errors.GlobalErrorType;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=X25519.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"X25519.d.ts","sourceRoot":"","sources":["../../src/wasm/X25519.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAEhD,OAAO,KAAK,QAAQ,MAAM,2BAA2B,CAAA;AAGrD,cAAc,mBAAmB,CAAA;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAIvD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAuBzD;AAED,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,uDAAuD;IACvD,KAAK,UAAU,GAAG;SACf,GAAG,IAAI,cAAc,GAAG,iBAAiB,CAAC,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KAC7E,CAAA;IAED,KAAK,SAAS,GAAG,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,eAAe,CAAA;CAC/D"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as crypto25519 from './internal/crypto25519.js';
|
|
2
|
+
import * as x25519 from './internal/x25519.js';
|
|
3
|
+
export * from '../core/X25519.js';
|
|
4
|
+
export { MemoryError } from './internal/instantiate.js';
|
|
5
|
+
const keySize = 32;
|
|
6
|
+
/**
|
|
7
|
+
* Compiles WASM implementations of selected [`X25519`](/api/X25519)
|
|
8
|
+
* primitives, without installing them.
|
|
9
|
+
*
|
|
10
|
+
* Random key generation remains on Ox's default implementation.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts twoslash
|
|
14
|
+
* // @noErrors
|
|
15
|
+
* import { Engine } from 'ox'
|
|
16
|
+
* import { X25519 } from 'ox/wasm'
|
|
17
|
+
*
|
|
18
|
+
* await Engine.install({ X25519: X25519.engine() })
|
|
19
|
+
*
|
|
20
|
+
* X25519.getPublicKey({ privateKey: '0x...' })
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @returns The WASM implementation of part of the `X25519` slot.
|
|
24
|
+
*/
|
|
25
|
+
export async function engine() {
|
|
26
|
+
const module = await crypto25519.load();
|
|
27
|
+
return {
|
|
28
|
+
getPublicKey(privateKey) {
|
|
29
|
+
assertLength(privateKey, 'private');
|
|
30
|
+
module.reserve(keySize * 2);
|
|
31
|
+
const privateKeyPtr = module.heapBase;
|
|
32
|
+
const publicKeyPtr = privateKeyPtr + keySize;
|
|
33
|
+
try {
|
|
34
|
+
module.view().set(privateKey, privateKeyPtr);
|
|
35
|
+
module.exports.x25519_get_public_key(privateKeyPtr, publicKeyPtr);
|
|
36
|
+
return module.view().slice(publicKeyPtr, publicKeyPtr + keySize);
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
module.exports.zero(privateKeyPtr, keySize * 2);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
getSharedSecret(privateKey, publicKey) {
|
|
43
|
+
assertLength(privateKey, 'private');
|
|
44
|
+
assertLength(publicKey, 'public');
|
|
45
|
+
return x25519.getSharedSecret(module, privateKey, publicKey);
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function assertLength(key, type) {
|
|
50
|
+
if (key.length !== keySize)
|
|
51
|
+
throw new RangeError(`X25519 ${type} key must be ${keySize} bytes, got ${key.length}`);
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=X25519.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"X25519.js","sourceRoot":"","sources":["../../src/wasm/X25519.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,WAAW,MAAM,2BAA2B,CAAA;AAExD,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAA;AAE9C,cAAc,mBAAmB,CAAA;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAEvD,MAAM,OAAO,GAAG,EAAE,CAAA;AAElB;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM;IAC1B,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,IAAI,EAAE,CAAA;IAEvC,OAAO;QACL,YAAY,CAAC,UAAU;YACrB,YAAY,CAAC,UAAU,EAAE,SAAS,CAAC,CAAA;YACnC,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG,CAAC,CAAC,CAAA;YAC3B,MAAM,aAAa,GAAG,MAAM,CAAC,QAAQ,CAAA;YACrC,MAAM,YAAY,GAAG,aAAa,GAAG,OAAO,CAAA;YAC5C,IAAI,CAAC;gBACH,MAAM,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,UAAU,EAAE,aAAa,CAAC,CAAA;gBAC5C,MAAM,CAAC,OAAO,CAAC,qBAAqB,CAAC,aAAa,EAAE,YAAY,CAAC,CAAA;gBACjE,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,CAAA;YAClE,CAAC;oBAAS,CAAC;gBACT,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,GAAG,CAAC,CAAC,CAAA;YACjD,CAAC;QACH,CAAC;QACD,eAAe,CAAC,UAAU,EAAE,SAAS;YACnC,YAAY,CAAC,UAAU,EAAE,SAAS,CAAC,CAAA;YACnC,YAAY,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;YACjC,OAAO,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,CAAC,CAAA;QAC9D,CAAC;KACF,CAAA;AACH,CAAC;AAWD,SAAS,YAAY,CAAC,GAAe,EAAE,IAA0B;IAC/D,IAAI,GAAG,CAAC,MAAM,KAAK,OAAO;QACxB,MAAM,IAAI,UAAU,CAClB,UAAU,IAAI,gBAAgB,OAAO,eAAe,GAAG,CAAC,MAAM,EAAE,CACjE,CAAA;AACL,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/** @entrypointCategory WASM */
|
|
2
|
+
/**
|
|
3
|
+
* WASM implementations of Ox's supported cryptographic primitives, compiled
|
|
4
|
+
* from C.
|
|
5
|
+
*
|
|
6
|
+
* Install it during startup. WASM must be compiled asynchronously, so the
|
|
7
|
+
* `await` lives there. Every cryptographic call afterwards is synchronous.
|
|
8
|
+
*
|
|
9
|
+
* :::note
|
|
10
|
+
* Performance varies by primitive, input size, runtime, and processor. Run
|
|
11
|
+
* `pnpm bench:engines` to compare the available implementations on your target
|
|
12
|
+
* machine.
|
|
13
|
+
* :::
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts twoslash
|
|
17
|
+
* // @noErrors
|
|
18
|
+
* import { Engine, Hash } from 'ox/wasm'
|
|
19
|
+
*
|
|
20
|
+
* await Engine.install()
|
|
21
|
+
*
|
|
22
|
+
* Hash.sha256('0xdeadbeef')
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @category Crypto
|
|
26
|
+
*/
|
|
27
|
+
export * as Engine from './Engine.js';
|
|
28
|
+
/**
|
|
29
|
+
* WASM implementations of Ox's supported Ed25519 primitives.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts twoslash
|
|
33
|
+
* // @noErrors
|
|
34
|
+
* import { Engine } from 'ox'
|
|
35
|
+
* import { Ed25519 } from 'ox/wasm'
|
|
36
|
+
*
|
|
37
|
+
* await Engine.install({ Ed25519: Ed25519.engine() })
|
|
38
|
+
*
|
|
39
|
+
* Ed25519.getPublicKey({ privateKey: '0x...' })
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @category Crypto
|
|
43
|
+
*/
|
|
44
|
+
export * as Ed25519 from './Ed25519.js';
|
|
45
|
+
/**
|
|
46
|
+
* WASM implementations of Ox's supported hash primitives.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts twoslash
|
|
50
|
+
* // @noErrors
|
|
51
|
+
* import { Engine } from 'ox'
|
|
52
|
+
* import { Hash } from 'ox/wasm'
|
|
53
|
+
*
|
|
54
|
+
* await Engine.install({ Hash: Hash.engine() })
|
|
55
|
+
*
|
|
56
|
+
* Hash.sha256('0xdeadbeef')
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @category Crypto
|
|
60
|
+
*/
|
|
61
|
+
export * as Hash from './Hash.js';
|
|
62
|
+
/**
|
|
63
|
+
* WASM implementation of Ox's synchronous PBKDF2-HMAC-SHA256 primitive.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts twoslash
|
|
67
|
+
* // @noErrors
|
|
68
|
+
* import { Engine } from 'ox'
|
|
69
|
+
* import { Keystore } from 'ox/wasm'
|
|
70
|
+
*
|
|
71
|
+
* await Engine.install({ Keystore: Keystore.engine() })
|
|
72
|
+
*
|
|
73
|
+
* Keystore.pbkdf2({ password: 'testpassword' })
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @category Crypto
|
|
77
|
+
*/
|
|
78
|
+
export * as Keystore from './Keystore.js';
|
|
79
|
+
/**
|
|
80
|
+
* WASM implementation of Ox's BIP-39 seed derivation.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts twoslash
|
|
84
|
+
* // @noErrors
|
|
85
|
+
* import { Engine } from 'ox'
|
|
86
|
+
* import { Mnemonic } from 'ox/wasm'
|
|
87
|
+
*
|
|
88
|
+
* await Engine.install({ Mnemonic: Mnemonic.engine() })
|
|
89
|
+
*
|
|
90
|
+
* Mnemonic.toSeed(
|
|
91
|
+
* 'test test test test test test test test test test test junk'
|
|
92
|
+
* )
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @category Crypto
|
|
96
|
+
*/
|
|
97
|
+
export * as Mnemonic from './Mnemonic.js';
|
|
98
|
+
/**
|
|
99
|
+
* WASM implementations of Ox's supported X25519 primitives.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts twoslash
|
|
103
|
+
* // @noErrors
|
|
104
|
+
* import { Engine } from 'ox'
|
|
105
|
+
* import { X25519 } from 'ox/wasm'
|
|
106
|
+
*
|
|
107
|
+
* await Engine.install({ X25519: X25519.engine() })
|
|
108
|
+
*
|
|
109
|
+
* X25519.getPublicKey({ privateKey: '0x...' })
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* @category Crypto
|
|
113
|
+
*/
|
|
114
|
+
export * as X25519 from './X25519.js';
|
|
115
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wasm/index.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAEzC;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAEzC;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA"}
|