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.
Files changed (131) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/core/Hash.d.ts +36 -0
  3. package/dist/core/Hash.d.ts.map +1 -1
  4. package/dist/core/Hash.js +35 -0
  5. package/dist/core/Hash.js.map +1 -1
  6. package/dist/node/Hash.d.ts +3 -3
  7. package/dist/node/Hash.js +3 -3
  8. package/dist/trusted-setups/Paths.d.ts +1 -0
  9. package/dist/trusted-setups/Paths.d.ts.map +1 -1
  10. package/dist/trusted-setups/Paths.js +1 -0
  11. package/dist/trusted-setups/Paths.js.map +1 -1
  12. package/dist/trusted-setups/Setups.d.ts +35 -0
  13. package/dist/trusted-setups/Setups.d.ts.map +1 -0
  14. package/dist/trusted-setups/Setups.js +29 -0
  15. package/dist/trusted-setups/Setups.js.map +1 -0
  16. package/dist/trusted-setups/index.d.ts +20 -0
  17. package/dist/trusted-setups/index.d.ts.map +1 -1
  18. package/dist/trusted-setups/index.js +20 -0
  19. package/dist/trusted-setups/index.js.map +1 -1
  20. package/dist/trusted-setups/internal/paths.d.ts.map +1 -1
  21. package/dist/trusted-setups/internal/paths.js +1 -1
  22. package/dist/trusted-setups/internal/paths.js.map +1 -1
  23. package/dist/trusted-setups/internal/setups/mainnet.d.ts +7 -0
  24. package/dist/trusted-setups/internal/setups/mainnet.d.ts.map +1 -0
  25. package/dist/trusted-setups/internal/setups/mainnet.js +11 -0
  26. package/dist/trusted-setups/internal/setups/mainnet.js.map +1 -0
  27. package/dist/wasm/Engine.d.ts +3 -2
  28. package/dist/wasm/Engine.d.ts.map +1 -1
  29. package/dist/wasm/Engine.js +5 -5
  30. package/dist/wasm/Engine.js.map +1 -1
  31. package/dist/wasm/Keystore.d.ts +23 -9
  32. package/dist/wasm/Keystore.d.ts.map +1 -1
  33. package/dist/wasm/Keystore.js +30 -13
  34. package/dist/wasm/Keystore.js.map +1 -1
  35. package/dist/wasm/Kzg.d.ts +112 -0
  36. package/dist/wasm/Kzg.d.ts.map +1 -0
  37. package/dist/wasm/Kzg.js +333 -0
  38. package/dist/wasm/Kzg.js.map +1 -0
  39. package/dist/wasm/Secp256k1.d.ts +55 -0
  40. package/dist/wasm/Secp256k1.d.ts.map +1 -0
  41. package/dist/wasm/Secp256k1.js +181 -0
  42. package/dist/wasm/Secp256k1.js.map +1 -0
  43. package/dist/wasm/index.d.ts +44 -1
  44. package/dist/wasm/index.d.ts.map +1 -1
  45. package/dist/wasm/index.js +44 -1
  46. package/dist/wasm/index.js.map +1 -1
  47. package/dist/wasm/internal/instantiate.d.ts +12 -0
  48. package/dist/wasm/internal/instantiate.d.ts.map +1 -1
  49. package/dist/wasm/internal/instantiate.js +23 -7
  50. package/dist/wasm/internal/instantiate.js.map +1 -1
  51. package/dist/wasm/internal/keystore.d.ts +10 -0
  52. package/dist/wasm/internal/keystore.d.ts.map +1 -0
  53. package/dist/wasm/internal/keystore.js +10 -0
  54. package/dist/wasm/internal/keystore.js.map +1 -0
  55. package/dist/wasm/internal/kzg.d.ts +17 -0
  56. package/dist/wasm/internal/kzg.d.ts.map +1 -0
  57. package/dist/wasm/internal/kzg.js +8 -0
  58. package/dist/wasm/internal/kzg.js.map +1 -0
  59. package/dist/wasm/internal/kzg.wasm.d.ts +3 -0
  60. package/dist/wasm/internal/kzg.wasm.d.ts.map +1 -0
  61. package/dist/wasm/internal/kzg.wasm.js +10 -0
  62. package/dist/wasm/internal/kzg.wasm.js.map +1 -0
  63. package/dist/wasm/internal/scrypt.d.ts +16 -0
  64. package/dist/wasm/internal/scrypt.d.ts.map +1 -0
  65. package/dist/wasm/internal/scrypt.js +78 -0
  66. package/dist/wasm/internal/scrypt.js.map +1 -0
  67. package/dist/wasm/internal/scrypt.wasm.d.ts +7 -0
  68. package/dist/wasm/internal/scrypt.wasm.d.ts.map +1 -0
  69. package/dist/wasm/internal/scrypt.wasm.js +14 -0
  70. package/dist/wasm/internal/scrypt.wasm.js.map +1 -0
  71. package/dist/wasm/internal/secp256k1.d.ts +16 -0
  72. package/dist/wasm/internal/secp256k1.d.ts.map +1 -0
  73. package/dist/wasm/internal/secp256k1.js +20 -0
  74. package/dist/wasm/internal/secp256k1.js.map +1 -0
  75. package/dist/wasm/internal/secp256k1.wasm.d.ts +3 -0
  76. package/dist/wasm/internal/secp256k1.wasm.d.ts.map +1 -0
  77. package/dist/wasm/internal/secp256k1.wasm.js +10 -0
  78. package/dist/wasm/internal/secp256k1.wasm.js.map +1 -0
  79. package/package.json +19 -2
  80. package/src/core/Hash.ts +59 -0
  81. package/src/core/_test/Block.test.ts +9 -2
  82. package/src/core/_test/Hash.test-d.ts +18 -0
  83. package/src/core/_test/Hash.test.ts +100 -1
  84. package/src/core/_test/Hash.vectors.test.ts +1 -2
  85. package/src/core/_test/Transaction.test.ts +11 -2
  86. package/src/node/Hash.ts +3 -3
  87. package/src/node/_test/Hash.test-d.ts +1 -0
  88. package/src/trusted-setups/Paths.ts +1 -0
  89. package/src/trusted-setups/README.md +39 -0
  90. package/src/trusted-setups/Setups.ts +46 -0
  91. package/src/trusted-setups/_test/Paths.test.ts +16 -0
  92. package/src/trusted-setups/_test/Setups.test-d.ts +7 -0
  93. package/src/trusted-setups/_test/Setups.test.ts +43 -0
  94. package/src/trusted-setups/_test/index.test.ts +1 -0
  95. package/src/trusted-setups/index.ts +21 -0
  96. package/src/trusted-setups/internal/paths.ts +4 -1
  97. package/src/trusted-setups/internal/setups/mainnet.source.json +7 -0
  98. package/src/trusted-setups/internal/setups/mainnet.ts +16 -0
  99. package/src/version.ts +1 -1
  100. package/src/wasm/Engine.ts +8 -6
  101. package/src/wasm/Keystore.bench.ts +26 -0
  102. package/src/wasm/Keystore.ts +32 -14
  103. package/src/wasm/Kzg.bench.ts +63 -0
  104. package/src/wasm/Kzg.ts +518 -0
  105. package/src/wasm/Secp256k1.bench.ts +79 -0
  106. package/src/wasm/Secp256k1.ts +248 -0
  107. package/src/wasm/_test/Engine.test-d.ts +1 -0
  108. package/src/wasm/_test/Hash.browser.test.ts +3 -0
  109. package/src/wasm/_test/Hash.test-d.ts +1 -0
  110. package/src/wasm/_test/Hash.test.ts +2 -2
  111. package/src/wasm/_test/Keystore.browser.test.ts +31 -0
  112. package/src/wasm/_test/Keystore.fuzz.ts +50 -0
  113. package/src/wasm/_test/Keystore.test-d.ts +10 -1
  114. package/src/wasm/_test/Keystore.test.ts +289 -4
  115. package/src/wasm/_test/Kzg.test-d.ts +19 -0
  116. package/src/wasm/_test/Kzg.test.ts +220 -0
  117. package/src/wasm/_test/Runtime.test.ts +9 -0
  118. package/src/wasm/_test/Secp256k1.test-d.ts +35 -0
  119. package/src/wasm/_test/Secp256k1.test.ts +354 -0
  120. package/src/wasm/index.ts +46 -1
  121. package/src/wasm/internal/instantiate.ts +29 -9
  122. package/src/wasm/internal/keystore.ts +19 -0
  123. package/src/wasm/internal/kzg.ts +50 -0
  124. package/src/wasm/internal/kzg.wasm.ts +11 -0
  125. package/src/wasm/internal/scrypt.ts +131 -0
  126. package/src/wasm/internal/scrypt.wasm.ts +17 -0
  127. package/src/wasm/internal/secp256k1.ts +62 -0
  128. package/src/wasm/internal/secp256k1.wasm.ts +11 -0
  129. package/wasm/vendor/c-kzg-4844/LICENSE +201 -0
  130. package/wasm/vendor/c-kzg-4844/blst/LICENSE +201 -0
  131. package/src/trusted-setups/internal/setups/mainnet.txt +0 -4163
@@ -158,7 +158,11 @@ describe('fromRpc', () => {
158
158
  })
159
159
  .then(Transaction.fromRpc)
160
160
 
161
- expect(transaction).toMatchInlineSnapshot(`
161
+ const { blockTimestamp: _, ...transaction_ } = {
162
+ blockTimestamp: undefined,
163
+ ...transaction,
164
+ }
165
+ expect(transaction_).toMatchInlineSnapshot(`
162
166
  {
163
167
  "blockHash": "0x8299a290ae51a8958965987e2caf178a09b8ecde01b737b5f9a8badbacb407cb",
164
168
  "blockNumber": 1110749n,
@@ -411,7 +415,12 @@ describe('fromRpc', () => {
411
415
  ],
412
416
  })
413
417
  .then(Transaction.fromRpc)
414
- expect(transaction).toMatchInlineSnapshot(`
418
+
419
+ const { blockTimestamp: _, ...transaction_ } = {
420
+ blockTimestamp: undefined,
421
+ ...transaction,
422
+ }
423
+ expect(transaction_).toMatchInlineSnapshot(`
415
424
  {
416
425
  "accessList": [],
417
426
  "blockHash": "0xc350d807505fb835650f0013632c5515592987ba169bbc6626d9fc54d91f0f0b",
package/src/node/Hash.ts CHANGED
@@ -12,9 +12,9 @@ export * from '../core/Hash.js'
12
12
  * which installs every implementation this entrypoint provides. Reach for this
13
13
  * to install or hold the `Hash` slot on its own.
14
14
  *
15
- * Node's `sha3-256` is not Ethereum Keccak256, so this engine deliberately
16
- * omits `keccak256`. Any earlier override remains installed; otherwise Ox uses
17
- * 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.
18
18
  *
19
19
  * @example
20
20
  * ```ts twoslash
@@ -27,6 +27,7 @@ test('the result is the raw slot, so `Engine.install` accepts it', () => {
27
27
  })
28
28
 
29
29
  test('the Node namespace exposes the public Hash API', () => {
30
+ expectTypeOf(NodeHash.blake3).toEqualTypeOf(CoreHash.blake3)
30
31
  expectTypeOf(NodeHash.sha256).toEqualTypeOf(CoreHash.sha256)
31
32
  expectTypeOf<typeof NodeHash>().not.toHaveProperty('create')
32
33
  })
@@ -1,3 +1,4 @@
1
1
  import { path } from './internal/paths.js'
2
2
 
3
+ /** File-system path to the Ethereum mainnet trusted setup. */
3
4
  export const mainnet = path('mainnet')
@@ -0,0 +1,39 @@
1
+ # Trusted setup maintenance
2
+
3
+ Ox bundles the finalized Ethereum KZG ceremony output. This setup is not a
4
+ rolling network parameter, so a new `c-kzg-4844` release does not normally
5
+ change its points.
6
+
7
+ The committed `mainnet.source.json` records the reviewed `c-kzg-4844` release
8
+ tag, source path, source SHA-256, and generated JSON SHA-256.
9
+
10
+ ## Refresh from c-kzg
11
+
12
+ 1. Review the latest official
13
+ [`c-kzg-4844` release](https://github.com/ethereum/c-kzg-4844/releases/latest)
14
+ and its `src/trusted_setup.txt` changes. Do not update from a moving branch.
15
+ 2. Pass the selected release tag explicitly:
16
+
17
+ ```bash
18
+ pnpm trusted-setups:update v2.1.8
19
+ ```
20
+
21
+ The command downloads that tagged file, requires 4,096 G1 Lagrange points,
22
+ 4,096 G1 monomial points, and 65 G2 monomial points, then regenerates the
23
+ canonical JSON, source metadata, and packed TypeScript artifact.
24
+
25
+ 3. Inspect the setup and metadata diff. Treat any point change as
26
+ security-sensitive. An implementation-only `c-kzg-4844` release should
27
+ change only the recorded tag when the source bytes are identical.
28
+ 4. Verify the generated artifacts and KZG conformance:
29
+
30
+ ```bash
31
+ pnpm trusted-setups:check
32
+ SKIP_GLOBAL_SETUP=1 pnpm test --project core --bail=1 \
33
+ src/trusted-setups src/wasm/_test/Kzg.test.ts
34
+ pnpm check:types
35
+ ```
36
+
37
+ `mainnet.json` remains available for file-based consumers through
38
+ `Paths.mainnet`. `mainnet.ts` is the independently tree-shakeable packed
39
+ artifact behind `Setups.mainnet`.
@@ -0,0 +1,46 @@
1
+ import * as Base64 from '../core/Base64.js'
2
+ import type * as Bytes from '../core/Bytes.js'
3
+ import {
4
+ g1Lagrange,
5
+ g1Monomial,
6
+ g2Monomial,
7
+ } from './internal/setups/mainnet.js'
8
+
9
+ /**
10
+ * Trusted setup points for EIP-4844 and EIP-7594 KZG operations.
11
+ */
12
+ export type TrustedSetup = {
13
+ /** G1 points in Lagrange form. */
14
+ readonly g1_lagrange: Bytes.Bytes
15
+ /** G1 points in monomial form. */
16
+ readonly g1_monomial: Bytes.Bytes
17
+ /** G2 points in monomial form. */
18
+ readonly g2_monomial: Bytes.Bytes
19
+ }
20
+
21
+ /**
22
+ * Ethereum mainnet trusted setup for EIP-4844 and EIP-7594.
23
+ *
24
+ * The setup stores packed points and is safe to reuse across `Kzg.create`
25
+ * calls. `Kzg.create` copies every field before asynchronous initialization.
26
+ *
27
+ * Treat the exported byte arrays as read-only.
28
+ *
29
+ * @example
30
+ * ```ts twoslash
31
+ * // @noErrors
32
+ * import { Setups } from 'ox/trusted-setups'
33
+ * import { Kzg } from 'ox/wasm'
34
+ *
35
+ * const kzg = await Kzg.create({
36
+ * trustedSetup: Setups.mainnet
37
+ * })
38
+ *
39
+ * kzg.dispose()
40
+ * ```
41
+ */
42
+ export const mainnet: TrustedSetup = /* @__PURE__ */ Object.freeze({
43
+ g1_lagrange: /* @__PURE__ */ Base64.toBytes(g1Lagrange),
44
+ g1_monomial: /* @__PURE__ */ Base64.toBytes(g1Monomial),
45
+ g2_monomial: /* @__PURE__ */ Base64.toBytes(g2Monomial),
46
+ })
@@ -1,3 +1,4 @@
1
+ import { readFileSync } from 'node:fs'
1
2
  import { expect, test } from 'vp/test'
2
3
  import * as Module from '../Paths.js'
3
4
 
@@ -8,3 +9,18 @@ test('exports', () => {
8
9
  ]
9
10
  `)
10
11
  })
12
+
13
+ test('mainnet resolves to the packaged trusted setup', () => {
14
+ const setup = JSON.parse(readFileSync(Module.mainnet, 'utf8'))
15
+ expect({
16
+ g1Lagrange: setup.g1_lagrange.length,
17
+ g1Monomial: setup.g1_monomial.length,
18
+ g2Monomial: setup.g2_monomial.length,
19
+ }).toMatchInlineSnapshot(`
20
+ {
21
+ "g1Lagrange": 4096,
22
+ "g1Monomial": 4096,
23
+ "g2Monomial": 65,
24
+ }
25
+ `)
26
+ })
@@ -0,0 +1,7 @@
1
+ import { expectTypeOf, test } from 'vp/test'
2
+ import type * as WasmKzg from '../../wasm/Kzg.js'
3
+ import * as Setups from '../Setups.js'
4
+
5
+ test('mainnet satisfies the WASM KZG trusted setup', () => {
6
+ expectTypeOf(Setups.mainnet).toMatchTypeOf<WasmKzg.TrustedSetup>()
7
+ })
@@ -0,0 +1,43 @@
1
+ import { describe, expect, test } from 'vp/test'
2
+ import * as Hex from '../../core/Hex.js'
3
+ import * as Setups from '../Setups.js'
4
+
5
+ describe('mainnet', () => {
6
+ test('exports the canonical PeerDAS setup as packed points', () => {
7
+ expect({
8
+ g1Lagrange: {
9
+ bytes: Setups.mainnet.g1_lagrange.length,
10
+ first: Hex.fromBytes(Setups.mainnet.g1_lagrange.slice(0, 48)),
11
+ last: Hex.fromBytes(Setups.mainnet.g1_lagrange.slice(-48)),
12
+ },
13
+ g1Monomial: {
14
+ bytes: Setups.mainnet.g1_monomial.length,
15
+ first: Hex.fromBytes(Setups.mainnet.g1_monomial.slice(0, 48)),
16
+ last: Hex.fromBytes(Setups.mainnet.g1_monomial.slice(-48)),
17
+ },
18
+ g2Monomial: {
19
+ bytes: Setups.mainnet.g2_monomial.length,
20
+ first: Hex.fromBytes(Setups.mainnet.g2_monomial.slice(0, 96)),
21
+ last: Hex.fromBytes(Setups.mainnet.g2_monomial.slice(-96)),
22
+ },
23
+ }).toMatchInlineSnapshot(`
24
+ {
25
+ "g1Lagrange": {
26
+ "bytes": 196608,
27
+ "first": "0xa0413c0dcafec6dbc9f47d66785cf1e8c981044f7d13cfe3e4fcbb71b5408dfde6312493cb3c1d30516cb3ca88c03654",
28
+ "last": "0x825a6f586726c68d45f00ad0f5a4436523317939a47713f78fd4fe81cd74236fdac1b04ecd97c2d0267d6f4981d7beb1",
29
+ },
30
+ "g1Monomial": {
31
+ "bytes": 196608,
32
+ "first": "0x97f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb",
33
+ "last": "0xb0bfaf56a5aa59b48960aa7c1617e832e65c823523fb2a5cd44ba606800501cf873e8db1d0dda64065285743dc40786e",
34
+ },
35
+ "g2Monomial": {
36
+ "bytes": 6240,
37
+ "first": "0x93e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8",
38
+ "last": "0x92dcc5a1c8c3e1b28b1524e3dd6dbecd63017c9201da9dbe077f1b82adc08c50169f56fc7b5a3b28ec6b89254de3e2fd12838a761053437883c3e01ba616670cea843754548ef84bcc397de2369adcca2ab54cd73c55dc68d87aec3fc2fe4f10",
39
+ },
40
+ }
41
+ `)
42
+ })
43
+ })
@@ -5,6 +5,7 @@ test('exports', () => {
5
5
  expect(Object.keys(Module)).toMatchInlineSnapshot(`
6
6
  [
7
7
  "Paths",
8
+ "Setups",
8
9
  ]
9
10
  `)
10
11
  })
@@ -1 +1,22 @@
1
+ /**
2
+ * File-system paths for trusted setup files bundled with Ox.
3
+ */
1
4
  export * as Paths from './Paths.js'
5
+
6
+ /**
7
+ * Trusted setup data bundled with Ox.
8
+ *
9
+ * @example
10
+ * ```ts twoslash
11
+ * // @noErrors
12
+ * import { Setups } from 'ox/trusted-setups'
13
+ * import { Kzg } from 'ox/wasm'
14
+ *
15
+ * const kzg = await Kzg.create({
16
+ * trustedSetup: Setups.mainnet
17
+ * })
18
+ *
19
+ * kzg.dispose()
20
+ * ```
21
+ */
22
+ export * as Setups from './Setups.js'
@@ -10,5 +10,8 @@ export function path(name: string) {
10
10
  import.meta.url,
11
11
  )
12
12
  const __dirname = dirname(__filename)
13
- return resolve(__dirname, `./setups/${name}.json`)
13
+ return resolve(
14
+ __dirname,
15
+ `../../../src/trusted-setups/internal/setups/${name}.json`,
16
+ )
14
17
  }
@@ -0,0 +1,7 @@
1
+ {
2
+ "path": "src/trusted_setup.txt",
3
+ "repository": "https://github.com/ethereum/c-kzg-4844",
4
+ "setupSha256": "c4732d98dd1452318e1f1943e240fa4c202a8973a44c24e68c937f86b00f9cb2",
5
+ "sourceSha256": "d39b9f2d047cc9dca2de58f264b6a09448ccd34db967881a6713eacacf0f26b7",
6
+ "tag": "v2.1.8"
7
+ }