ox 1.1.2 → 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 +27 -0
- 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/node/Hash.d.ts +3 -3
- package/dist/node/Hash.js +3 -3
- 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/Engine.d.ts +3 -2
- package/dist/wasm/Engine.d.ts.map +1 -1
- package/dist/wasm/Engine.js +5 -5
- package/dist/wasm/Engine.js.map +1 -1
- package/dist/wasm/Keystore.d.ts +23 -9
- package/dist/wasm/Keystore.d.ts.map +1 -1
- package/dist/wasm/Keystore.js +30 -13
- package/dist/wasm/Keystore.js.map +1 -1
- 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/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/index.d.ts +44 -1
- package/dist/wasm/index.d.ts.map +1 -1
- package/dist/wasm/index.js +44 -1
- package/dist/wasm/index.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/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/package.json +19 -2
- package/src/core/Hash.ts +59 -0
- package/src/core/_test/Block.test.ts +9 -2
- 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 +1 -2
- package/src/core/_test/Transaction.test.ts +11 -2
- package/src/node/Hash.ts +3 -3
- package/src/node/_test/Hash.test-d.ts +1 -0
- 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/Engine.ts +8 -6
- package/src/wasm/Keystore.bench.ts +26 -0
- package/src/wasm/Keystore.ts +32 -14
- package/src/wasm/Kzg.bench.ts +63 -0
- package/src/wasm/Kzg.ts +518 -0
- package/src/wasm/Secp256k1.bench.ts +79 -0
- package/src/wasm/Secp256k1.ts +248 -0
- package/src/wasm/_test/Engine.test-d.ts +1 -0
- package/src/wasm/_test/Hash.browser.test.ts +3 -0
- package/src/wasm/_test/Hash.test-d.ts +1 -0
- package/src/wasm/_test/Hash.test.ts +2 -2
- package/src/wasm/_test/Keystore.browser.test.ts +31 -0
- package/src/wasm/_test/Keystore.fuzz.ts +50 -0
- package/src/wasm/_test/Keystore.test-d.ts +10 -1
- package/src/wasm/_test/Keystore.test.ts +289 -4
- package/src/wasm/_test/Kzg.test-d.ts +19 -0
- package/src/wasm/_test/Kzg.test.ts +220 -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/index.ts +46 -1
- 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/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/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/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** @internal */
|
|
2
|
-
export const version = '1.
|
|
2
|
+
export const version = '1.2.0'
|
package/src/wasm/Engine.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as CoreEngine from '../core/Engine.js'
|
|
|
2
2
|
import type * as Errors from '../core/Errors.js'
|
|
3
3
|
import * as Ed25519 from './Ed25519.js'
|
|
4
4
|
import * as Hash from './Hash.js'
|
|
5
|
-
import * as
|
|
5
|
+
import * as keystore from './internal/keystore.js'
|
|
6
6
|
import * as Mnemonic from './Mnemonic.js'
|
|
7
7
|
import * as X25519 from './X25519.js'
|
|
8
8
|
import type * as internal from './internal/instantiate.js'
|
|
@@ -54,7 +54,7 @@ export async function install(): Promise<install.ReturnType> {
|
|
|
54
54
|
return CoreEngine.install({
|
|
55
55
|
Ed25519: Ed25519.engine(),
|
|
56
56
|
Hash: Hash.engine(),
|
|
57
|
-
Keystore:
|
|
57
|
+
Keystore: keystore.engine(),
|
|
58
58
|
Mnemonic: Mnemonic.engine(),
|
|
59
59
|
X25519: X25519.engine(),
|
|
60
60
|
})
|
|
@@ -91,17 +91,17 @@ export declare namespace install {
|
|
|
91
91
|
* @returns An engine, ready to install.
|
|
92
92
|
*/
|
|
93
93
|
export async function engine(): Promise<engine.ReturnType> {
|
|
94
|
-
const [ed25519, hash,
|
|
94
|
+
const [ed25519, hash, keystoreEngine, mnemonic, x25519] = await Promise.all([
|
|
95
95
|
Ed25519.engine(),
|
|
96
96
|
Hash.engine(),
|
|
97
|
-
|
|
97
|
+
keystore.engine(),
|
|
98
98
|
Mnemonic.engine(),
|
|
99
99
|
X25519.engine(),
|
|
100
100
|
])
|
|
101
101
|
return {
|
|
102
102
|
Ed25519: ed25519,
|
|
103
103
|
Hash: hash,
|
|
104
|
-
Keystore:
|
|
104
|
+
Keystore: keystoreEngine,
|
|
105
105
|
Mnemonic: mnemonic,
|
|
106
106
|
X25519: x25519,
|
|
107
107
|
}
|
|
@@ -112,7 +112,9 @@ export declare namespace engine {
|
|
|
112
112
|
type ReturnType = {
|
|
113
113
|
Ed25519: Ed25519.engine.ReturnType
|
|
114
114
|
Hash: Hash.engine.ReturnType
|
|
115
|
-
Keystore:
|
|
115
|
+
Keystore: {
|
|
116
|
+
pbkdf2Sha256: NonNullable<CoreEngine.Keystore['pbkdf2Sha256']>
|
|
117
|
+
}
|
|
116
118
|
Mnemonic: Mnemonic.engine.ReturnType
|
|
117
119
|
X25519: X25519.engine.ReturnType
|
|
118
120
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { scrypt as scrypt_noble } from '@noble/hashes/scrypt.js'
|
|
2
|
+
import { bench, describe } from 'vp/test'
|
|
3
|
+
import { engine as wasmEngine } from './Keystore.js'
|
|
4
|
+
|
|
5
|
+
// Run `pnpm bench --project core src/wasm/Keystore.bench.ts`. These cases expose
|
|
6
|
+
// the effect of block size, parallelization, and the public defaults.
|
|
7
|
+
const cases = [
|
|
8
|
+
{ N: 1024, dkLen: 32, p: 1, r: 1 },
|
|
9
|
+
{ N: 16_384, dkLen: 32, p: 1, r: 8 },
|
|
10
|
+
{ N: 262_144, dkLen: 32, p: 8, r: 1 },
|
|
11
|
+
] as const
|
|
12
|
+
|
|
13
|
+
const wasm = await wasmEngine()
|
|
14
|
+
const password = new Uint8Array(16).fill(0x5a)
|
|
15
|
+
const salt = new Uint8Array(32).fill(0xa5)
|
|
16
|
+
|
|
17
|
+
for (const options of cases)
|
|
18
|
+
describe(`scrypt (N=${options.N}, r=${options.r}, p=${options.p})`, () => {
|
|
19
|
+
bench('ox', () => {
|
|
20
|
+
scrypt_noble(password, salt, options)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
bench('ox/wasm', () => {
|
|
24
|
+
wasm.scrypt(password, salt, options)
|
|
25
|
+
})
|
|
26
|
+
})
|
package/src/wasm/Keystore.ts
CHANGED
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
import type * as Engine from '../core/Engine.js'
|
|
2
2
|
import type * as Errors from '../core/Errors.js'
|
|
3
|
-
import * as hashes from './internal/hashes.js'
|
|
4
3
|
import * as internal from './internal/instantiate.js'
|
|
5
|
-
import * as
|
|
4
|
+
import * as keystore from './internal/keystore.js'
|
|
5
|
+
import * as scrypt from './internal/scrypt.js'
|
|
6
6
|
|
|
7
7
|
export * from '../core/Keystore.js'
|
|
8
8
|
export { MemoryError } from './internal/instantiate.js'
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Compiles the WASM
|
|
12
|
-
*
|
|
11
|
+
* Compiles the WASM implementations of the [`Keystore`](/api/Keystore)
|
|
12
|
+
* synchronous key-derivation primitives, without installing them.
|
|
13
13
|
*
|
|
14
|
-
* Most callers
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* and
|
|
14
|
+
* Most callers can use [`Engine.install`](/wasm/crypto/Engine/install).
|
|
15
|
+
* Install this factory explicitly when an application has benchmarked and
|
|
16
|
+
* selected WASM scrypt.
|
|
17
|
+
*
|
|
18
|
+
* This provider stays synchronous and leaves AES and asynchronous key
|
|
19
|
+
* derivation on Ox's default implementation.
|
|
20
|
+
*
|
|
21
|
+
* Scrypt uses a standalone artifact and grows memory only when called.
|
|
22
|
+
* WebAssembly cannot shrink that capacity. The provider clears its contents
|
|
23
|
+
* and enforces Noble's 1 GiB temporary-workspace limit.
|
|
24
|
+
*
|
|
25
|
+
* The aggregate [`Engine.install`](/wasm/crypto/Engine/install) installs only
|
|
26
|
+
* PBKDF2 from this provider. Install this factory explicitly to opt into
|
|
27
|
+
* scrypt, whose relative performance depends on its parameters and runtime.
|
|
28
|
+
*
|
|
29
|
+
* Copied inputs, derived output, and the complete workspace are cleared after
|
|
30
|
+
* every return or trap.
|
|
19
31
|
*
|
|
20
32
|
* @example
|
|
21
33
|
* ```ts twoslash
|
|
@@ -25,16 +37,21 @@ export { MemoryError } from './internal/instantiate.js'
|
|
|
25
37
|
*
|
|
26
38
|
* await Engine.install({ Keystore: Keystore.engine() })
|
|
27
39
|
*
|
|
28
|
-
* Keystore.
|
|
40
|
+
* Keystore.scrypt({ password: 'testpassword' })
|
|
29
41
|
* ```
|
|
30
42
|
*
|
|
31
|
-
* @returns The WASM
|
|
43
|
+
* @returns The WASM implementations of synchronous PBKDF2-HMAC-SHA256 and
|
|
44
|
+
* scrypt.
|
|
32
45
|
*/
|
|
33
46
|
export async function engine(): Promise<engine.ReturnType> {
|
|
34
|
-
const
|
|
47
|
+
const [keystoreEngine, scryptModule] = await Promise.all([
|
|
48
|
+
keystore.engine(),
|
|
49
|
+
scrypt.load(),
|
|
50
|
+
])
|
|
35
51
|
return {
|
|
36
|
-
|
|
37
|
-
|
|
52
|
+
...keystoreEngine,
|
|
53
|
+
scrypt: (password, salt, options) =>
|
|
54
|
+
scrypt.derive(scryptModule, password, salt, options),
|
|
38
55
|
}
|
|
39
56
|
}
|
|
40
57
|
|
|
@@ -42,6 +59,7 @@ export declare namespace engine {
|
|
|
42
59
|
/** The WASM `Keystore` primitives this module implements. */
|
|
43
60
|
type ReturnType = {
|
|
44
61
|
pbkdf2Sha256: NonNullable<Engine.Keystore['pbkdf2Sha256']>
|
|
62
|
+
scrypt: NonNullable<Engine.Keystore['scrypt']>
|
|
45
63
|
}
|
|
46
64
|
|
|
47
65
|
type ErrorType = internal.MemoryError | Errors.GlobalErrorType
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { afterAll, bench, describe } from 'vp/test'
|
|
2
|
+
import { mainnet as trustedSetup } from '../trusted-setups/Setups.js'
|
|
3
|
+
import { create } from './Kzg.js'
|
|
4
|
+
|
|
5
|
+
const once = {
|
|
6
|
+
iterations: 1,
|
|
7
|
+
time: 0,
|
|
8
|
+
warmupIterations: 0,
|
|
9
|
+
warmupTime: 0,
|
|
10
|
+
} as const
|
|
11
|
+
|
|
12
|
+
describe('create', () => {
|
|
13
|
+
bench(
|
|
14
|
+
'precompute 0',
|
|
15
|
+
async () => {
|
|
16
|
+
const kzg = await create({ trustedSetup })
|
|
17
|
+
kzg.dispose()
|
|
18
|
+
},
|
|
19
|
+
once,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
bench(
|
|
23
|
+
'precompute 8',
|
|
24
|
+
async () => {
|
|
25
|
+
const kzg = await create({ precompute: 8, trustedSetup })
|
|
26
|
+
kzg.dispose()
|
|
27
|
+
},
|
|
28
|
+
once,
|
|
29
|
+
)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const kzg = await create({ trustedSetup })
|
|
33
|
+
const blob = new Uint8Array(131_072)
|
|
34
|
+
const commitment = kzg.blobToKzgCommitment(blob)
|
|
35
|
+
const { cells, proofs } = kzg.computeCellsAndKzgProofs(blob)
|
|
36
|
+
const indices = cells.map((_, index) => index)
|
|
37
|
+
const commitments = cells.map(() => commitment)
|
|
38
|
+
const partialIndices = indices.filter((index) => index % 2 === 0)
|
|
39
|
+
const partialCells = cells.filter((_, index) => index % 2 === 0)
|
|
40
|
+
|
|
41
|
+
afterAll(() => kzg.dispose())
|
|
42
|
+
|
|
43
|
+
describe('operations', () => {
|
|
44
|
+
bench('blobToKzgCommitment', () => {
|
|
45
|
+
kzg.blobToKzgCommitment(blob)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
bench('computeCells', () => {
|
|
49
|
+
kzg.computeCells(blob)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
bench('computeCellsAndKzgProofs', () => {
|
|
53
|
+
kzg.computeCellsAndKzgProofs(blob)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
bench('recoverCellsAndKzgProofs', () => {
|
|
57
|
+
kzg.recoverCellsAndKzgProofs(partialIndices, partialCells)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
bench('verifyCellKzgProofBatch', () => {
|
|
61
|
+
kzg.verifyCellKzgProofBatch(commitments, indices, cells, proofs)
|
|
62
|
+
})
|
|
63
|
+
})
|