ox 1.1.0 → 1.2.0
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 +54 -0
- package/dist/core/Engine.d.ts +43 -11
- package/dist/core/Engine.d.ts.map +1 -1
- package/dist/core/Engine.js +40 -10
- package/dist/core/Engine.js.map +1 -1
- package/dist/core/Hash.d.ts +36 -0
- package/dist/core/Hash.d.ts.map +1 -1
- package/dist/core/Hash.js +35 -0
- package/dist/core/Hash.js.map +1 -1
- package/dist/core/internal/engine.d.ts +8 -8
- package/dist/core/internal/engine.d.ts.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- 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 +29 -16
- package/dist/node/Engine.d.ts.map +1 -1
- package/dist/node/Engine.js +38 -14
- package/dist/node/Engine.js.map +1 -1
- package/dist/node/Hash.d.ts +17 -19
- package/dist/node/Hash.d.ts.map +1 -1
- package/dist/node/Hash.js +17 -19
- package/dist/node/Hash.js.map +1 -1
- 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 +95 -8
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +95 -8
- package/dist/node/index.js.map +1 -1
- package/dist/trusted-setups/Paths.d.ts +1 -0
- package/dist/trusted-setups/Paths.d.ts.map +1 -1
- package/dist/trusted-setups/Paths.js +1 -0
- package/dist/trusted-setups/Paths.js.map +1 -1
- package/dist/trusted-setups/Setups.d.ts +35 -0
- package/dist/trusted-setups/Setups.d.ts.map +1 -0
- package/dist/trusted-setups/Setups.js +29 -0
- package/dist/trusted-setups/Setups.js.map +1 -0
- package/dist/trusted-setups/index.d.ts +20 -0
- package/dist/trusted-setups/index.d.ts.map +1 -1
- package/dist/trusted-setups/index.js +20 -0
- package/dist/trusted-setups/index.js.map +1 -1
- package/dist/trusted-setups/internal/paths.d.ts.map +1 -1
- package/dist/trusted-setups/internal/paths.js +1 -1
- package/dist/trusted-setups/internal/paths.js.map +1 -1
- package/dist/trusted-setups/internal/setups/mainnet.d.ts +7 -0
- package/dist/trusted-setups/internal/setups/mainnet.d.ts.map +1 -0
- package/dist/trusted-setups/internal/setups/mainnet.js +11 -0
- package/dist/trusted-setups/internal/setups/mainnet.js.map +1 -0
- 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 +36 -26
- package/dist/wasm/Engine.d.ts.map +1 -1
- package/dist/wasm/Engine.js +44 -25
- package/dist/wasm/Engine.js.map +1 -1
- package/dist/wasm/Hash.d.ts +13 -19
- package/dist/wasm/Hash.d.ts.map +1 -1
- package/dist/wasm/Hash.js +21 -27
- package/dist/wasm/Hash.js.map +1 -1
- package/dist/wasm/Keystore.d.ts +51 -0
- package/dist/wasm/Keystore.d.ts.map +1 -0
- package/dist/wasm/Keystore.js +51 -0
- package/dist/wasm/Keystore.js.map +1 -0
- package/dist/wasm/Kzg.d.ts +112 -0
- package/dist/wasm/Kzg.d.ts.map +1 -0
- package/dist/wasm/Kzg.js +333 -0
- package/dist/wasm/Kzg.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/Secp256k1.d.ts +55 -0
- package/dist/wasm/Secp256k1.d.ts.map +1 -0
- package/dist/wasm/Secp256k1.js +181 -0
- package/dist/wasm/Secp256k1.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 +124 -12
- package/dist/wasm/index.d.ts.map +1 -1
- package/dist/wasm/index.js +124 -12
- package/dist/wasm/index.js.map +1 -1
- 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/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 +4 -2
- package/dist/wasm/internal/hashes.wasm.d.ts.map +1 -1
- package/dist/wasm/internal/hashes.wasm.js +4 -2
- package/dist/wasm/internal/hashes.wasm.js.map +1 -1
- package/dist/wasm/internal/instantiate.d.ts +12 -0
- package/dist/wasm/internal/instantiate.d.ts.map +1 -1
- package/dist/wasm/internal/instantiate.js +23 -7
- package/dist/wasm/internal/instantiate.js.map +1 -1
- package/dist/wasm/internal/keystore.d.ts +10 -0
- package/dist/wasm/internal/keystore.d.ts.map +1 -0
- package/dist/wasm/internal/keystore.js +10 -0
- package/dist/wasm/internal/keystore.js.map +1 -0
- package/dist/wasm/internal/kzg.d.ts +17 -0
- package/dist/wasm/internal/kzg.d.ts.map +1 -0
- package/dist/wasm/internal/kzg.js +8 -0
- package/dist/wasm/internal/kzg.js.map +1 -0
- package/dist/wasm/internal/kzg.wasm.d.ts +3 -0
- package/dist/wasm/internal/kzg.wasm.d.ts.map +1 -0
- package/dist/wasm/internal/kzg.wasm.js +10 -0
- package/dist/wasm/internal/kzg.wasm.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/scrypt.d.ts +16 -0
- package/dist/wasm/internal/scrypt.d.ts.map +1 -0
- package/dist/wasm/internal/scrypt.js +78 -0
- package/dist/wasm/internal/scrypt.js.map +1 -0
- package/dist/wasm/internal/scrypt.wasm.d.ts +7 -0
- package/dist/wasm/internal/scrypt.wasm.d.ts.map +1 -0
- package/dist/wasm/internal/scrypt.wasm.js +14 -0
- package/dist/wasm/internal/scrypt.wasm.js.map +1 -0
- package/dist/wasm/internal/secp256k1.d.ts +16 -0
- package/dist/wasm/internal/secp256k1.d.ts.map +1 -0
- package/dist/wasm/internal/secp256k1.js +20 -0
- package/dist/wasm/internal/secp256k1.js.map +1 -0
- package/dist/wasm/internal/secp256k1.wasm.d.ts +3 -0
- package/dist/wasm/internal/secp256k1.wasm.d.ts.map +1 -0
- package/dist/wasm/internal/secp256k1.wasm.js +10 -0
- package/dist/wasm/internal/secp256k1.wasm.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/package.json +64 -2
- package/src/core/Engine.ts +84 -11
- package/src/core/Hash.ts +59 -0
- package/src/core/_test/Block.test.ts +9 -2
- package/src/core/_test/Engine.test-d.ts +56 -0
- package/src/core/_test/Engine.test.ts +95 -0
- package/src/core/_test/Hash.test-d.ts +18 -0
- package/src/core/_test/Hash.test.ts +100 -1
- package/src/core/_test/Hash.vectors.test.ts +7 -0
- package/src/core/_test/Transaction.test.ts +11 -2
- package/src/core/internal/engine.ts +8 -8
- package/src/index.ts +5 -2
- package/src/node/Ed25519.ts +87 -0
- package/src/node/Engine.ts +79 -23
- package/src/node/Hash.ts +25 -30
- 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 +62 -22
- package/src/node/_test/Hash.test-d.ts +16 -9
- package/src/node/_test/Hash.test.ts +10 -11
- 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 +100 -8
- package/src/trusted-setups/Paths.ts +1 -0
- package/src/trusted-setups/README.md +39 -0
- package/src/trusted-setups/Setups.ts +46 -0
- package/src/trusted-setups/_test/Paths.test.ts +16 -0
- package/src/trusted-setups/_test/Setups.test-d.ts +7 -0
- package/src/trusted-setups/_test/Setups.test.ts +43 -0
- package/src/trusted-setups/_test/index.test.ts +1 -0
- package/src/trusted-setups/index.ts +21 -0
- package/src/trusted-setups/internal/paths.ts +4 -1
- package/src/trusted-setups/internal/setups/mainnet.source.json +7 -0
- package/src/trusted-setups/internal/setups/mainnet.ts +16 -0
- package/src/version.ts +1 -1
- package/src/wasm/Ed25519.ts +114 -0
- package/src/wasm/Engine.ts +78 -31
- package/src/wasm/Hash.bench.ts +2 -2
- package/src/wasm/Hash.ts +29 -50
- package/src/wasm/Keystore.bench.ts +26 -0
- package/src/wasm/Keystore.ts +66 -0
- package/src/wasm/Kzg.bench.ts +63 -0
- package/src/wasm/Kzg.ts +518 -0
- package/src/wasm/Mnemonic.ts +44 -0
- package/src/wasm/Secp256k1.bench.ts +79 -0
- package/src/wasm/Secp256k1.ts +248 -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 +29 -0
- package/src/wasm/_test/Engine.test.ts +59 -25
- package/src/wasm/_test/Hash.browser.test.ts +14 -7
- package/src/wasm/_test/Hash.fuzz.ts +58 -23
- package/src/wasm/_test/Hash.test-d.ts +16 -10
- package/src/wasm/_test/Hash.test.ts +148 -48
- package/src/wasm/_test/Hash.vectors.test.ts +15 -8
- package/src/wasm/_test/Keystore.browser.test.ts +73 -0
- package/src/wasm/_test/Keystore.fuzz.ts +163 -0
- package/src/wasm/_test/Keystore.test-d.ts +42 -0
- package/src/wasm/_test/Keystore.test.ts +477 -0
- package/src/wasm/_test/Keystore.vectors.test.ts +21 -0
- package/src/wasm/_test/Kzg.test-d.ts +19 -0
- package/src/wasm/_test/Kzg.test.ts +220 -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 +9 -0
- package/src/wasm/_test/Secp256k1.test-d.ts +35 -0
- package/src/wasm/_test/Secp256k1.test.ts +354 -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/index.ts +130 -12
- 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/hashes.ts +29 -0
- package/src/wasm/internal/hashes.wasm.ts +5 -2
- package/src/wasm/internal/instantiate.ts +29 -9
- package/src/wasm/internal/keystore.ts +19 -0
- package/src/wasm/internal/kzg.ts +50 -0
- package/src/wasm/internal/kzg.wasm.ts +11 -0
- package/src/wasm/internal/mnemonic.ts +56 -0
- package/src/wasm/internal/pbkdf2.ts +86 -0
- package/src/wasm/internal/scrypt.ts +131 -0
- package/src/wasm/internal/scrypt.wasm.ts +17 -0
- package/src/wasm/internal/secp256k1.ts +62 -0
- package/src/wasm/internal/secp256k1.wasm.ts +11 -0
- package/src/wasm/internal/x25519.ts +29 -0
- package/wasm/vendor/c-kzg-4844/LICENSE +201 -0
- package/wasm/vendor/c-kzg-4844/blst/LICENSE +201 -0
- package/src/trusted-setups/internal/setups/mainnet.txt +0 -4163
package/src/node/Engine.ts
CHANGED
|
@@ -1,40 +1,67 @@
|
|
|
1
1
|
import * as CoreEngine from '../core/Engine.js'
|
|
2
2
|
import type * as Errors from '../core/Errors.js'
|
|
3
|
+
import * as Ed25519 from './Ed25519.js'
|
|
3
4
|
import * as Hash from './Hash.js'
|
|
5
|
+
import * as Keystore from './Keystore.js'
|
|
6
|
+
import * as Mnemonic from './Mnemonic.js'
|
|
7
|
+
import * as P256 from './P256.js'
|
|
8
|
+
import * as X25519 from './X25519.js'
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
AsyncScopeError,
|
|
12
|
+
get,
|
|
13
|
+
InvalidSlotValueError,
|
|
14
|
+
reset,
|
|
15
|
+
set,
|
|
16
|
+
UnknownPrimitiveError,
|
|
17
|
+
UnknownSlotError,
|
|
18
|
+
with,
|
|
19
|
+
} from '../core/Engine.js'
|
|
20
|
+
export type {
|
|
21
|
+
Bls,
|
|
22
|
+
Ecdh,
|
|
23
|
+
Ecdsa,
|
|
24
|
+
Eddsa,
|
|
25
|
+
Engine,
|
|
26
|
+
Hash,
|
|
27
|
+
Keystore,
|
|
28
|
+
Mnemonic,
|
|
29
|
+
} from '../core/Engine.js'
|
|
4
30
|
|
|
5
31
|
/**
|
|
6
|
-
*
|
|
32
|
+
* Installs every Node.js implementation this entrypoint provides.
|
|
7
33
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* startup, before any cryptographic operation.
|
|
34
|
+
* Slots initialize in parallel and are installed atomically. Call this once
|
|
35
|
+
* during startup, before any cryptographic operation.
|
|
11
36
|
*
|
|
12
37
|
* @example
|
|
13
38
|
* ```ts twoslash
|
|
14
39
|
* // @noErrors
|
|
15
|
-
* import { Hash } from 'ox'
|
|
16
|
-
* import { Engine } from 'ox/node'
|
|
40
|
+
* import { Engine, Hash } from 'ox/node'
|
|
17
41
|
*
|
|
18
|
-
* await Engine.
|
|
42
|
+
* await Engine.install()
|
|
19
43
|
*
|
|
20
44
|
* Hash.sha256('0xdeadbeef')
|
|
21
45
|
* ```
|
|
22
46
|
*
|
|
23
47
|
* @returns The engine that was installed.
|
|
24
48
|
*/
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
49
|
+
export function install(): Promise<install.ReturnType> {
|
|
50
|
+
return CoreEngine.install({
|
|
51
|
+
Ed25519: Ed25519.engine(),
|
|
52
|
+
Hash: Hash.engine(),
|
|
53
|
+
Keystore: Keystore.engine(),
|
|
54
|
+
Mnemonic: Mnemonic.engine(),
|
|
55
|
+
P256: P256.engine(),
|
|
56
|
+
X25519: X25519.engine(),
|
|
57
|
+
})
|
|
29
58
|
}
|
|
30
59
|
|
|
31
|
-
export declare namespace
|
|
32
|
-
|
|
60
|
+
export declare namespace install {
|
|
61
|
+
/** Every slot this entrypoint installs, each with its primitives present. */
|
|
62
|
+
type ReturnType = engine.ReturnType
|
|
33
63
|
|
|
34
|
-
type ErrorType =
|
|
35
|
-
| create.ErrorType
|
|
36
|
-
| CoreEngine.set.ErrorType
|
|
37
|
-
| Errors.GlobalErrorType
|
|
64
|
+
type ErrorType = engine.ErrorType | CoreEngine.install.ErrorType
|
|
38
65
|
}
|
|
39
66
|
|
|
40
67
|
/**
|
|
@@ -50,20 +77,49 @@ export declare namespace load {
|
|
|
50
77
|
* import { Engine, Hash } from 'ox'
|
|
51
78
|
* import { Engine as NodeEngine } from 'ox/node'
|
|
52
79
|
*
|
|
53
|
-
* const node = await NodeEngine.
|
|
80
|
+
* const node = await NodeEngine.engine()
|
|
54
81
|
*
|
|
55
82
|
* Engine.with(node, () => Hash.sha256('0xdeadbeef'))
|
|
56
83
|
* ```
|
|
57
84
|
*
|
|
58
85
|
* @returns An engine, ready to install.
|
|
59
86
|
*/
|
|
60
|
-
export async function
|
|
61
|
-
|
|
87
|
+
export async function engine(): Promise<engine.ReturnType> {
|
|
88
|
+
const [ed25519, hash, keystore, mnemonic, p256, x25519] = await Promise.all([
|
|
89
|
+
Ed25519.engine(),
|
|
90
|
+
Hash.engine(),
|
|
91
|
+
Keystore.engine(),
|
|
92
|
+
Mnemonic.engine(),
|
|
93
|
+
P256.engine(),
|
|
94
|
+
X25519.engine(),
|
|
95
|
+
])
|
|
96
|
+
return {
|
|
97
|
+
Ed25519: ed25519,
|
|
98
|
+
Hash: hash,
|
|
99
|
+
Keystore: keystore,
|
|
100
|
+
Mnemonic: mnemonic,
|
|
101
|
+
P256: p256,
|
|
102
|
+
X25519: x25519,
|
|
103
|
+
}
|
|
62
104
|
}
|
|
63
105
|
|
|
64
|
-
export declare namespace
|
|
106
|
+
export declare namespace engine {
|
|
65
107
|
/** Every slot this entrypoint supplies, each with its primitives present. */
|
|
66
|
-
type ReturnType =
|
|
108
|
+
type ReturnType = {
|
|
109
|
+
Ed25519: Ed25519.engine.ReturnType
|
|
110
|
+
Hash: Hash.engine.ReturnType
|
|
111
|
+
Keystore: Keystore.engine.ReturnType
|
|
112
|
+
Mnemonic: Mnemonic.engine.ReturnType
|
|
113
|
+
P256: P256.engine.ReturnType
|
|
114
|
+
X25519: X25519.engine.ReturnType
|
|
115
|
+
}
|
|
67
116
|
|
|
68
|
-
type ErrorType =
|
|
117
|
+
type ErrorType =
|
|
118
|
+
| Ed25519.engine.ErrorType
|
|
119
|
+
| Hash.engine.ErrorType
|
|
120
|
+
| Keystore.engine.ErrorType
|
|
121
|
+
| Mnemonic.engine.ErrorType
|
|
122
|
+
| P256.engine.ErrorType
|
|
123
|
+
| X25519.engine.ErrorType
|
|
124
|
+
| Errors.GlobalErrorType
|
|
69
125
|
}
|
package/src/node/Hash.ts
CHANGED
|
@@ -2,54 +2,49 @@ import * as crypto from 'node:crypto'
|
|
|
2
2
|
import type * as Engine from '../core/Engine.js'
|
|
3
3
|
import type * as Errors from '../core/Errors.js'
|
|
4
4
|
|
|
5
|
+
export * from '../core/Hash.js'
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
|
-
* Creates Node.js
|
|
7
|
-
* installing
|
|
8
|
+
* Creates a Node.js implementation of the [`Hash`](/api/Hash) engine slot,
|
|
9
|
+
* without installing it.
|
|
8
10
|
*
|
|
9
|
-
* Most callers want
|
|
10
|
-
* implementation this entrypoint provides. Reach for this
|
|
11
|
-
*
|
|
12
|
-
* installed engine.
|
|
11
|
+
* Most callers want [`Engine.install`](/node/crypto/Engine/install) instead,
|
|
12
|
+
* which installs every implementation this entrypoint provides. Reach for this
|
|
13
|
+
* to install or hold the `Hash` slot on its own.
|
|
13
14
|
*
|
|
14
|
-
* Node
|
|
15
|
-
* omits `keccak256`. Any earlier override
|
|
16
|
-
* its default implementation.
|
|
15
|
+
* Node does not provide BLAKE3, and its `sha3-256` is not Ethereum Keccak256, so
|
|
16
|
+
* this engine deliberately omits `blake3` and `keccak256`. Any earlier override
|
|
17
|
+
* remains installed; otherwise Ox uses its default implementation.
|
|
17
18
|
*
|
|
18
19
|
* @example
|
|
19
20
|
* ```ts twoslash
|
|
20
21
|
* // @noErrors
|
|
21
|
-
* import { Engine
|
|
22
|
-
* import
|
|
22
|
+
* import { Engine } from 'ox'
|
|
23
|
+
* import { Hash } from 'ox/node'
|
|
23
24
|
*
|
|
24
|
-
* Engine.
|
|
25
|
+
* await Engine.install({ Hash: Hash.engine() })
|
|
25
26
|
*
|
|
26
27
|
* Hash.sha256('0xdeadbeef')
|
|
27
28
|
* ```
|
|
28
29
|
*
|
|
29
|
-
* @returns
|
|
30
|
+
* @returns The raw `Hash` engine slot.
|
|
30
31
|
*/
|
|
31
|
-
export function
|
|
32
|
+
export function engine(): Promise<engine.ReturnType> {
|
|
32
33
|
return Promise.resolve({
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
ripemd160: (input) =>
|
|
39
|
-
new Uint8Array(crypto.hash('ripemd160', input, 'buffer')),
|
|
40
|
-
sha256: (input) => new Uint8Array(crypto.hash('sha256', input, 'buffer')),
|
|
41
|
-
},
|
|
34
|
+
hmacSha256: (key, message) =>
|
|
35
|
+
new Uint8Array(crypto.createHmac('sha256', key).update(message).digest()),
|
|
36
|
+
ripemd160: (input) =>
|
|
37
|
+
new Uint8Array(crypto.hash('ripemd160', input, 'buffer')),
|
|
38
|
+
sha256: (input) => new Uint8Array(crypto.hash('sha256', input, 'buffer')),
|
|
42
39
|
})
|
|
43
40
|
}
|
|
44
41
|
|
|
45
|
-
export declare namespace
|
|
46
|
-
/**
|
|
42
|
+
export declare namespace engine {
|
|
43
|
+
/** Every `Hash` primitive this module implements. */
|
|
47
44
|
type ReturnType = {
|
|
48
|
-
|
|
49
|
-
[key
|
|
50
|
-
|
|
51
|
-
>
|
|
52
|
-
}
|
|
45
|
+
[key in 'hmacSha256' | 'ripemd160' | 'sha256']-?: NonNullable<
|
|
46
|
+
Engine.Hash[key]
|
|
47
|
+
>
|
|
53
48
|
}
|
|
54
49
|
|
|
55
50
|
type ErrorType = Errors.GlobalErrorType
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import * as crypto from 'node:crypto'
|
|
2
|
+
import type * as Engine from '../core/Engine.js'
|
|
3
|
+
import type * as Errors from '../core/Errors.js'
|
|
4
|
+
|
|
5
|
+
export * from '../core/Keystore.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Creates a Node.js implementation of the [`Keystore`](/api/Keystore) engine
|
|
9
|
+
* slot, without installing it.
|
|
10
|
+
*
|
|
11
|
+
* Most callers want [`Engine.install`](/node/crypto/Engine/install) instead,
|
|
12
|
+
* which installs every implementation this entrypoint provides. Reach for this
|
|
13
|
+
* to install or hold the `Keystore` slot on its own.
|
|
14
|
+
*
|
|
15
|
+
* This engine deliberately omits scrypt. OpenSSL rejects Ox's default scrypt
|
|
16
|
+
* parameter shape, so installing it would make valid existing calls fail.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts twoslash
|
|
20
|
+
* // @noErrors
|
|
21
|
+
* import { Engine } from 'ox'
|
|
22
|
+
* import { Keystore } from 'ox/node'
|
|
23
|
+
*
|
|
24
|
+
* await Engine.install({ Keystore: Keystore.engine() })
|
|
25
|
+
*
|
|
26
|
+
* Keystore.pbkdf2({ password: 'testpassword' })
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @returns The raw `Keystore` engine slot.
|
|
30
|
+
*/
|
|
31
|
+
export function engine(): Promise<engine.ReturnType> {
|
|
32
|
+
return Promise.resolve({
|
|
33
|
+
aesCtrDecrypt: (key, iv, data) => {
|
|
34
|
+
const cipher = crypto.createDecipheriv(
|
|
35
|
+
`aes-${key.length * 8}-ctr`,
|
|
36
|
+
key,
|
|
37
|
+
iv,
|
|
38
|
+
)
|
|
39
|
+
return cipherData(cipher, data)
|
|
40
|
+
},
|
|
41
|
+
aesCtrEncrypt: (key, iv, data) => {
|
|
42
|
+
const cipher = crypto.createCipheriv(`aes-${key.length * 8}-ctr`, key, iv)
|
|
43
|
+
return cipherData(cipher, data)
|
|
44
|
+
},
|
|
45
|
+
pbkdf2Sha256: (password, salt, options) =>
|
|
46
|
+
copyAndClear(
|
|
47
|
+
crypto.pbkdf2Sync(password, salt, options.c, options.dkLen, 'sha256'),
|
|
48
|
+
),
|
|
49
|
+
pbkdf2Sha256Async: (password, salt, options) =>
|
|
50
|
+
new Promise((resolve, reject) => {
|
|
51
|
+
crypto.pbkdf2(
|
|
52
|
+
password,
|
|
53
|
+
salt,
|
|
54
|
+
options.c,
|
|
55
|
+
options.dkLen,
|
|
56
|
+
'sha256',
|
|
57
|
+
(error, key) => {
|
|
58
|
+
if (error) return reject(error)
|
|
59
|
+
try {
|
|
60
|
+
resolve(copyAndClear(key))
|
|
61
|
+
} catch (error) {
|
|
62
|
+
reject(error)
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
)
|
|
66
|
+
}),
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export declare namespace engine {
|
|
71
|
+
/** Every `Keystore` primitive this module implements. */
|
|
72
|
+
type ReturnType = {
|
|
73
|
+
[key in
|
|
74
|
+
| 'aesCtrDecrypt'
|
|
75
|
+
| 'aesCtrEncrypt'
|
|
76
|
+
| 'pbkdf2Sha256'
|
|
77
|
+
| 'pbkdf2Sha256Async']-?: NonNullable<Engine.Keystore[key]>
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
type ErrorType = Errors.GlobalErrorType
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function cipherData(
|
|
84
|
+
cipher: crypto.Cipheriv | crypto.Decipheriv,
|
|
85
|
+
data: Uint8Array,
|
|
86
|
+
): Uint8Array {
|
|
87
|
+
const chunks: Buffer[] = []
|
|
88
|
+
try {
|
|
89
|
+
chunks.push(cipher.update(data))
|
|
90
|
+
chunks.push(cipher.final())
|
|
91
|
+
return copyAndClear(Buffer.concat(chunks))
|
|
92
|
+
} finally {
|
|
93
|
+
for (const chunk of chunks) chunk.fill(0)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function copyAndClear(value: Buffer): Uint8Array {
|
|
98
|
+
try {
|
|
99
|
+
return Uint8Array.from(value)
|
|
100
|
+
} finally {
|
|
101
|
+
value.fill(0)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as crypto from 'node:crypto'
|
|
2
|
+
import type * as Engine from '../core/Engine.js'
|
|
3
|
+
import type * as Errors from '../core/Errors.js'
|
|
4
|
+
|
|
5
|
+
export * from '../core/Mnemonic.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Creates a Node.js implementation of the [`Mnemonic`](/api/Mnemonic) engine
|
|
9
|
+
* slot, without installing it.
|
|
10
|
+
*
|
|
11
|
+
* Most callers want [`Engine.install`](/node/crypto/Engine/install) instead,
|
|
12
|
+
* which installs every implementation this entrypoint provides. Reach for this
|
|
13
|
+
* to install or hold the `Mnemonic` slot on its own.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts twoslash
|
|
17
|
+
* // @noErrors
|
|
18
|
+
* import { Engine } from 'ox'
|
|
19
|
+
* import { Mnemonic } from 'ox/node'
|
|
20
|
+
*
|
|
21
|
+
* await Engine.install({ Mnemonic: Mnemonic.engine() })
|
|
22
|
+
*
|
|
23
|
+
* Mnemonic.toSeed(
|
|
24
|
+
* 'test test test test test test test test test test test junk'
|
|
25
|
+
* )
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @returns The raw `Mnemonic` engine slot.
|
|
29
|
+
*/
|
|
30
|
+
export function engine(): Promise<engine.ReturnType> {
|
|
31
|
+
return Promise.resolve({
|
|
32
|
+
toSeed: (mnemonic, passphrase = '') => {
|
|
33
|
+
if (typeof mnemonic !== 'string')
|
|
34
|
+
throw new TypeError(`invalid mnemonic type: ${typeof mnemonic}`)
|
|
35
|
+
|
|
36
|
+
const normalized = mnemonic.normalize('NFKD')
|
|
37
|
+
if (![12, 15, 18, 21, 24].includes(normalized.split(' ').length))
|
|
38
|
+
throw new Error('Invalid mnemonic')
|
|
39
|
+
|
|
40
|
+
return copyAndClear(
|
|
41
|
+
crypto.pbkdf2Sync(
|
|
42
|
+
normalized,
|
|
43
|
+
`mnemonic${passphrase}`.normalize('NFKD'),
|
|
44
|
+
2048,
|
|
45
|
+
64,
|
|
46
|
+
'sha512',
|
|
47
|
+
),
|
|
48
|
+
)
|
|
49
|
+
},
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export declare namespace engine {
|
|
54
|
+
/** Every `Mnemonic` primitive this module implements. */
|
|
55
|
+
type ReturnType = {
|
|
56
|
+
[key in 'toSeed']-?: NonNullable<Engine.Mnemonic[key]>
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
type ErrorType = Errors.GlobalErrorType
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function copyAndClear(value: Buffer): Uint8Array {
|
|
63
|
+
try {
|
|
64
|
+
return Uint8Array.from(value)
|
|
65
|
+
} finally {
|
|
66
|
+
value.fill(0)
|
|
67
|
+
}
|
|
68
|
+
}
|
package/src/node/P256.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as crypto from 'node:crypto'
|
|
2
|
+
import type * as Engine from '../core/Engine.js'
|
|
3
|
+
import type * as Errors from '../core/Errors.js'
|
|
4
|
+
|
|
5
|
+
export * from '../core/P256.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Creates a Node.js implementation of the [`P256`](/api/P256) engine slot,
|
|
9
|
+
* without installing it.
|
|
10
|
+
*
|
|
11
|
+
* Node's other P256 operations do not reproduce Ox's recovered-signature and
|
|
12
|
+
* compressed-shared-point contracts, so they remain on Ox's defaults.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts twoslash
|
|
16
|
+
* // @noErrors
|
|
17
|
+
* import { Engine } from 'ox'
|
|
18
|
+
* import { P256 } from 'ox/node'
|
|
19
|
+
*
|
|
20
|
+
* await Engine.install({ P256: P256.engine() })
|
|
21
|
+
*
|
|
22
|
+
* P256.getPublicKey({ privateKey: '0x...' })
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @returns The raw `P256` engine slot.
|
|
26
|
+
*/
|
|
27
|
+
export function engine(): Promise<engine.ReturnType> {
|
|
28
|
+
return Promise.resolve({
|
|
29
|
+
getPublicKey: (privateKey) => {
|
|
30
|
+
if (privateKey.length !== 32)
|
|
31
|
+
throw new RangeError(
|
|
32
|
+
`P256 private key must be 32 bytes, got ${privateKey.length}`,
|
|
33
|
+
)
|
|
34
|
+
const ecdh = crypto.createECDH('prime256v1')
|
|
35
|
+
ecdh.setPrivateKey(privateKey)
|
|
36
|
+
return new Uint8Array(ecdh.getPublicKey(undefined, 'uncompressed'))
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export declare namespace engine {
|
|
42
|
+
/** Every `P256` primitive this module implements. */
|
|
43
|
+
type ReturnType = {
|
|
44
|
+
getPublicKey: NonNullable<Engine.Ecdsa['getPublicKey']>
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type ErrorType = Errors.GlobalErrorType
|
|
48
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import * as crypto from 'node:crypto'
|
|
2
|
+
import type * as Engine from '../core/Engine.js'
|
|
3
|
+
import type * as Errors from '../core/Errors.js'
|
|
4
|
+
|
|
5
|
+
export * from '../core/X25519.js'
|
|
6
|
+
|
|
7
|
+
const privateKeyPrefix = Buffer.from('302e020100300506032b656e04220420', 'hex')
|
|
8
|
+
const publicKeyPrefix = Buffer.from('302a300506032b656e032100', 'hex')
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Creates a Node.js implementation of the [`X25519`](/api/X25519) engine slot,
|
|
12
|
+
* without installing it.
|
|
13
|
+
*
|
|
14
|
+
* Random key generation remains on Ox's default implementation.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts twoslash
|
|
18
|
+
* // @noErrors
|
|
19
|
+
* import { Engine } from 'ox'
|
|
20
|
+
* import { X25519 } from 'ox/node'
|
|
21
|
+
*
|
|
22
|
+
* await Engine.install({ X25519: X25519.engine() })
|
|
23
|
+
*
|
|
24
|
+
* X25519.getPublicKey({ privateKey: '0x...' })
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @returns The raw `X25519` engine slot.
|
|
28
|
+
*/
|
|
29
|
+
export function engine(): Promise<engine.ReturnType> {
|
|
30
|
+
return Promise.resolve({
|
|
31
|
+
getPublicKey: (privateKey) =>
|
|
32
|
+
rawPublicKey(crypto.createPublicKey(toPrivateKey(privateKey))),
|
|
33
|
+
getSharedSecret: (privateKey, publicKey) =>
|
|
34
|
+
copyAndClear(
|
|
35
|
+
crypto.diffieHellman({
|
|
36
|
+
privateKey: toPrivateKey(privateKey),
|
|
37
|
+
publicKey: toPublicKey(publicKey),
|
|
38
|
+
}),
|
|
39
|
+
),
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export declare namespace engine {
|
|
44
|
+
/** Every `X25519` primitive this module implements. */
|
|
45
|
+
type ReturnType = {
|
|
46
|
+
[key in 'getPublicKey' | 'getSharedSecret']-?: NonNullable<Engine.Ecdh[key]>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
type ErrorType = Errors.GlobalErrorType
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function copyAndClear(value: Buffer): Uint8Array {
|
|
53
|
+
try {
|
|
54
|
+
return Uint8Array.from(value)
|
|
55
|
+
} finally {
|
|
56
|
+
value.fill(0)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function assertLength(key: Uint8Array, type: 'private' | 'public'): void {
|
|
61
|
+
if (key.length !== 32)
|
|
62
|
+
throw new RangeError(
|
|
63
|
+
`X25519 ${type} key must be 32 bytes, got ${key.length}`,
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function rawPublicKey(publicKey: crypto.KeyObject): Uint8Array {
|
|
68
|
+
const der = publicKey.export({ format: 'der', type: 'spki' })
|
|
69
|
+
return Uint8Array.from(der.subarray(-32))
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function toPrivateKey(privateKey: Uint8Array): crypto.KeyObject {
|
|
73
|
+
assertLength(privateKey, 'private')
|
|
74
|
+
const der = Buffer.concat([privateKeyPrefix, privateKey])
|
|
75
|
+
try {
|
|
76
|
+
return crypto.createPrivateKey({
|
|
77
|
+
format: 'der',
|
|
78
|
+
key: der,
|
|
79
|
+
type: 'pkcs8',
|
|
80
|
+
})
|
|
81
|
+
} finally {
|
|
82
|
+
der.fill(0)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function toPublicKey(publicKey: Uint8Array): crypto.KeyObject {
|
|
87
|
+
assertLength(publicKey, 'public')
|
|
88
|
+
return crypto.createPublicKey({
|
|
89
|
+
format: 'der',
|
|
90
|
+
key: Buffer.concat([publicKeyPrefix, publicKey]),
|
|
91
|
+
type: 'spki',
|
|
92
|
+
})
|
|
93
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { fc, test } from '@fast-check/vitest'
|
|
2
|
+
import { ed25519, x25519 } from '@noble/curves/ed25519.js'
|
|
3
|
+
import { p256 } from '@noble/curves/nist.js'
|
|
4
|
+
import { describe, expect } from 'vp/test'
|
|
5
|
+
import { numRuns } from '../../../test/fuzz/numRuns.js'
|
|
6
|
+
import * as Ed25519 from '../Ed25519.js'
|
|
7
|
+
import * as P256 from '../P256.js'
|
|
8
|
+
import * as X25519 from '../X25519.js'
|
|
9
|
+
|
|
10
|
+
const arbitraryBytes = fc.uint8Array({ maxLength: 512 })
|
|
11
|
+
const arbitraryKey = fc.uint8Array({ maxLength: 32, minLength: 32 })
|
|
12
|
+
const arbitraryP256PrivateKey = fc
|
|
13
|
+
.tuple(
|
|
14
|
+
fc.integer({ max: 0xfe, min: 1 }),
|
|
15
|
+
fc.uint8Array({ maxLength: 31, minLength: 31 }),
|
|
16
|
+
)
|
|
17
|
+
.map(([first, rest]) => Uint8Array.of(first, ...rest))
|
|
18
|
+
|
|
19
|
+
describe('Ed25519', () => {
|
|
20
|
+
test.prop({ payload: arbitraryBytes, privateKey: arbitraryKey }, { numRuns })(
|
|
21
|
+
'matches the default for arbitrary offset views',
|
|
22
|
+
async (options) => {
|
|
23
|
+
const engine = await Ed25519.engine()
|
|
24
|
+
const payload = offsetView(options.payload)
|
|
25
|
+
const privateKey = offsetView(options.privateKey)
|
|
26
|
+
|
|
27
|
+
expect(engine.getPublicKey(privateKey)).toEqual(
|
|
28
|
+
ed25519.getPublicKey(privateKey),
|
|
29
|
+
)
|
|
30
|
+
expect(engine.sign(payload, privateKey)).toEqual(
|
|
31
|
+
ed25519.sign(payload, privateKey),
|
|
32
|
+
)
|
|
33
|
+
expect(engine.toMontgomerySecret(privateKey)).toEqual(
|
|
34
|
+
ed25519.utils.toMontgomerySecret(privateKey),
|
|
35
|
+
)
|
|
36
|
+
},
|
|
37
|
+
)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
describe('X25519', () => {
|
|
41
|
+
test.prop(
|
|
42
|
+
{ privateKey: arbitraryKey, publicKeySeed: arbitraryKey },
|
|
43
|
+
{ numRuns },
|
|
44
|
+
)('matches the default for arbitrary offset views', async (options) => {
|
|
45
|
+
const engine = await X25519.engine()
|
|
46
|
+
const privateKey = offsetView(options.privateKey)
|
|
47
|
+
const publicKey = offsetView(x25519.getPublicKey(options.publicKeySeed))
|
|
48
|
+
|
|
49
|
+
expect(engine.getPublicKey(privateKey)).toEqual(
|
|
50
|
+
x25519.getPublicKey(privateKey),
|
|
51
|
+
)
|
|
52
|
+
expect(engine.getSharedSecret(privateKey, publicKey)).toEqual(
|
|
53
|
+
x25519.getSharedSecret(privateKey, publicKey),
|
|
54
|
+
)
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
describe('P256', () => {
|
|
59
|
+
test.prop({ privateKey: arbitraryP256PrivateKey }, { numRuns })(
|
|
60
|
+
'matches the default for arbitrary offset views',
|
|
61
|
+
async (options) => {
|
|
62
|
+
const engine = await P256.engine()
|
|
63
|
+
const privateKey = offsetView(options.privateKey)
|
|
64
|
+
|
|
65
|
+
expect(engine.getPublicKey(privateKey)).toEqual(
|
|
66
|
+
p256.getPublicKey(privateKey, false),
|
|
67
|
+
)
|
|
68
|
+
},
|
|
69
|
+
)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
function offsetView(value: Uint8Array): Uint8Array {
|
|
73
|
+
const bytes = new Uint8Array(value.length + 4).fill(0xff)
|
|
74
|
+
bytes.set(value, 2)
|
|
75
|
+
return bytes.subarray(2, -2)
|
|
76
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { expectTypeOf, test } from 'vp/test'
|
|
2
|
+
import type * as Engine from '../../core/Engine.js'
|
|
3
|
+
import * as core_Ed25519 from '../../core/Ed25519.js'
|
|
4
|
+
import * as NodeEd25519 from '../Ed25519.js'
|
|
5
|
+
|
|
6
|
+
type Slot = Awaited<ReturnType<typeof NodeEd25519.engine>>
|
|
7
|
+
|
|
8
|
+
test('every implemented primitive is present', () => {
|
|
9
|
+
expectTypeOf<Slot['getPublicKey']>().toEqualTypeOf<
|
|
10
|
+
(privateKey: Uint8Array) => Uint8Array
|
|
11
|
+
>()
|
|
12
|
+
expectTypeOf<Slot['sign']>().toEqualTypeOf<
|
|
13
|
+
(payload: Uint8Array, privateKey: Uint8Array) => Uint8Array
|
|
14
|
+
>()
|
|
15
|
+
expectTypeOf<Slot['toMontgomerySecret']>().toEqualTypeOf<
|
|
16
|
+
(privateKey: Uint8Array) => Uint8Array
|
|
17
|
+
>()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test('unsupported primitives are absent', () => {
|
|
21
|
+
expectTypeOf<Slot>().not.toHaveProperty('randomSecretKey')
|
|
22
|
+
expectTypeOf<Slot>().not.toHaveProperty('toMontgomery')
|
|
23
|
+
expectTypeOf<Slot>().not.toHaveProperty('verify')
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('the result is the raw slot', () => {
|
|
27
|
+
expectTypeOf<{ Ed25519: Slot }>().toExtend<Engine.Engine>()
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('the Node namespace exposes the public Ed25519 API', () => {
|
|
31
|
+
expectTypeOf(NodeEd25519.getPublicKey).toEqualTypeOf(
|
|
32
|
+
core_Ed25519.getPublicKey,
|
|
33
|
+
)
|
|
34
|
+
expectTypeOf<typeof NodeEd25519>().not.toHaveProperty('create')
|
|
35
|
+
})
|