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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mainnet.js","sourceRoot":"","sources":["../../../../src/trusted-setups/internal/setups/mainnet.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,EAAE;AACF,+DAA+D;AAC/D,+EAA+E;AAE/E,iDAAiD;AACjD,MAAM,CAAC,MAAM,UAAU,GACrB,kggQAAkggQ,CAAA;AAEpggQ,iDAAiD;AACjD,MAAM,CAAC,MAAM,UAAU,GACrB,kggQAAkggQ,CAAA;AAEpggQ,iDAAiD;AACjD,MAAM,CAAC,MAAM,UAAU,GACrB,koQAAkoQ,CAAA"}
|
package/dist/wasm/Engine.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ 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 Keystore from './Keystore.js';
|
|
6
5
|
import * as Mnemonic from './Mnemonic.js';
|
|
7
6
|
import * as X25519 from './X25519.js';
|
|
8
7
|
import type * as internal from './internal/instantiate.js';
|
|
@@ -62,7 +61,9 @@ export declare namespace engine {
|
|
|
62
61
|
type ReturnType = {
|
|
63
62
|
Ed25519: Ed25519.engine.ReturnType;
|
|
64
63
|
Hash: Hash.engine.ReturnType;
|
|
65
|
-
Keystore:
|
|
64
|
+
Keystore: {
|
|
65
|
+
pbkdf2Sha256: NonNullable<CoreEngine.Keystore['pbkdf2Sha256']>;
|
|
66
|
+
};
|
|
66
67
|
Mnemonic: Mnemonic.engine.ReturnType;
|
|
67
68
|
X25519: X25519.engine.ReturnType;
|
|
68
69
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Engine.d.ts","sourceRoot":"","sources":["../../src/wasm/Engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"Engine.d.ts","sourceRoot":"","sources":["../../src/wasm/Engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,KAAK,QAAQ,MAAM,2BAA2B,CAAA;AAE1D,OAAO,EACL,eAAe,EACf,GAAG,EACH,qBAAqB,EACrB,KAAK,EACL,GAAG,EACH,qBAAqB,EACrB,gBAAgB,EAChB,IAAI,GACL,MAAM,mBAAmB,CAAA;AAC1B,YAAY,EACV,GAAG,EACH,IAAI,EACJ,KAAK,EACL,KAAK,EACL,MAAM,EACN,IAAI,EACJ,QAAQ,EACR,QAAQ,GACT,MAAM,mBAAmB,CAAA;AAE1B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAQ3D;AAED,MAAM,CAAC,OAAO,WAAW,OAAO,CAAC;IAC/B,KAAK,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;IAEnC,KAAK,SAAS,GACV,MAAM,CAAC,SAAS,GAChB,UAAU,CAAC,OAAO,CAAC,SAAS,GAC5B,MAAM,CAAC,eAAe,CAAA;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAezD;AAED,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,6EAA6E;IAC7E,KAAK,UAAU,GAAG;QAChB,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,CAAA;QAClC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,CAAA;QAC5B,QAAQ,EAAE;YACR,YAAY,EAAE,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAA;SAC/D,CAAA;QACD,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAA;QACpC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAA;KACjC,CAAA;IAED,KAAK,SAAS,GAAG,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,eAAe,CAAA;CAC/D"}
|
package/dist/wasm/Engine.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as CoreEngine from '../core/Engine.js';
|
|
2
2
|
import * as Ed25519 from './Ed25519.js';
|
|
3
3
|
import * as Hash from './Hash.js';
|
|
4
|
-
import * as
|
|
4
|
+
import * as keystore from './internal/keystore.js';
|
|
5
5
|
import * as Mnemonic from './Mnemonic.js';
|
|
6
6
|
import * as X25519 from './X25519.js';
|
|
7
7
|
export { AsyncScopeError, get, InvalidSlotValueError, reset, set, UnknownPrimitiveError, UnknownSlotError, with, } from '../core/Engine.js';
|
|
@@ -31,7 +31,7 @@ export async function install() {
|
|
|
31
31
|
return CoreEngine.install({
|
|
32
32
|
Ed25519: Ed25519.engine(),
|
|
33
33
|
Hash: Hash.engine(),
|
|
34
|
-
Keystore:
|
|
34
|
+
Keystore: keystore.engine(),
|
|
35
35
|
Mnemonic: Mnemonic.engine(),
|
|
36
36
|
X25519: X25519.engine(),
|
|
37
37
|
});
|
|
@@ -58,17 +58,17 @@ export async function install() {
|
|
|
58
58
|
* @returns An engine, ready to install.
|
|
59
59
|
*/
|
|
60
60
|
export async function engine() {
|
|
61
|
-
const [ed25519, hash,
|
|
61
|
+
const [ed25519, hash, keystoreEngine, mnemonic, x25519] = await Promise.all([
|
|
62
62
|
Ed25519.engine(),
|
|
63
63
|
Hash.engine(),
|
|
64
|
-
|
|
64
|
+
keystore.engine(),
|
|
65
65
|
Mnemonic.engine(),
|
|
66
66
|
X25519.engine(),
|
|
67
67
|
]);
|
|
68
68
|
return {
|
|
69
69
|
Ed25519: ed25519,
|
|
70
70
|
Hash: hash,
|
|
71
|
-
Keystore:
|
|
71
|
+
Keystore: keystoreEngine,
|
|
72
72
|
Mnemonic: mnemonic,
|
|
73
73
|
X25519: x25519,
|
|
74
74
|
};
|
package/dist/wasm/Engine.js.map
CHANGED
|
@@ -1 +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,
|
|
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,wBAAwB,CAAA;AAClD,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,cAAc,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC1E,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,cAAc;QACxB,QAAQ,EAAE,QAAQ;QAClB,MAAM,EAAE,MAAM;KACf,CAAA;AACH,CAAC"}
|
package/dist/wasm/Keystore.d.ts
CHANGED
|
@@ -4,14 +4,26 @@ import * as internal from './internal/instantiate.js';
|
|
|
4
4
|
export * from '../core/Keystore.js';
|
|
5
5
|
export { MemoryError } from './internal/instantiate.js';
|
|
6
6
|
/**
|
|
7
|
-
* Compiles the WASM
|
|
8
|
-
*
|
|
7
|
+
* Compiles the WASM implementations of the [`Keystore`](/api/Keystore)
|
|
8
|
+
* synchronous key-derivation primitives, without installing them.
|
|
9
9
|
*
|
|
10
|
-
* Most callers
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* and
|
|
10
|
+
* Most callers can use [`Engine.install`](/wasm/crypto/Engine/install).
|
|
11
|
+
* Install this factory explicitly when an application has benchmarked and
|
|
12
|
+
* selected WASM scrypt.
|
|
13
|
+
*
|
|
14
|
+
* This provider stays synchronous and leaves AES and asynchronous key
|
|
15
|
+
* derivation on Ox's default implementation.
|
|
16
|
+
*
|
|
17
|
+
* Scrypt uses a standalone artifact and grows memory only when called.
|
|
18
|
+
* WebAssembly cannot shrink that capacity. The provider clears its contents
|
|
19
|
+
* and enforces Noble's 1 GiB temporary-workspace limit.
|
|
20
|
+
*
|
|
21
|
+
* The aggregate [`Engine.install`](/wasm/crypto/Engine/install) installs only
|
|
22
|
+
* PBKDF2 from this provider. Install this factory explicitly to opt into
|
|
23
|
+
* scrypt, whose relative performance depends on its parameters and runtime.
|
|
24
|
+
*
|
|
25
|
+
* Copied inputs, derived output, and the complete workspace are cleared after
|
|
26
|
+
* every return or trap.
|
|
15
27
|
*
|
|
16
28
|
* @example
|
|
17
29
|
* ```ts twoslash
|
|
@@ -21,16 +33,18 @@ export { MemoryError } from './internal/instantiate.js';
|
|
|
21
33
|
*
|
|
22
34
|
* await Engine.install({ Keystore: Keystore.engine() })
|
|
23
35
|
*
|
|
24
|
-
* Keystore.
|
|
36
|
+
* Keystore.scrypt({ password: 'testpassword' })
|
|
25
37
|
* ```
|
|
26
38
|
*
|
|
27
|
-
* @returns The WASM
|
|
39
|
+
* @returns The WASM implementations of synchronous PBKDF2-HMAC-SHA256 and
|
|
40
|
+
* scrypt.
|
|
28
41
|
*/
|
|
29
42
|
export declare function engine(): Promise<engine.ReturnType>;
|
|
30
43
|
export declare namespace engine {
|
|
31
44
|
/** The WASM `Keystore` primitives this module implements. */
|
|
32
45
|
type ReturnType = {
|
|
33
46
|
pbkdf2Sha256: NonNullable<Engine.Keystore['pbkdf2Sha256']>;
|
|
47
|
+
scrypt: NonNullable<Engine.Keystore['scrypt']>;
|
|
34
48
|
};
|
|
35
49
|
type ErrorType = internal.MemoryError | Errors.GlobalErrorType;
|
|
36
50
|
}
|
|
@@ -1 +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;
|
|
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;AAChD,OAAO,KAAK,QAAQ,MAAM,2BAA2B,CAAA;AAIrD,cAAc,qBAAqB,CAAA;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAsB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAUzD;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;QAC1D,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"}
|
package/dist/wasm/Keystore.js
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
1
|
+
import * as keystore from './internal/keystore.js';
|
|
2
|
+
import * as scrypt from './internal/scrypt.js';
|
|
3
3
|
export * from '../core/Keystore.js';
|
|
4
4
|
export { MemoryError } from './internal/instantiate.js';
|
|
5
5
|
/**
|
|
6
|
-
* Compiles the WASM
|
|
7
|
-
*
|
|
6
|
+
* Compiles the WASM implementations of the [`Keystore`](/api/Keystore)
|
|
7
|
+
* synchronous key-derivation primitives, without installing them.
|
|
8
8
|
*
|
|
9
|
-
* Most callers
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* and
|
|
9
|
+
* Most callers can use [`Engine.install`](/wasm/crypto/Engine/install).
|
|
10
|
+
* Install this factory explicitly when an application has benchmarked and
|
|
11
|
+
* selected WASM scrypt.
|
|
12
|
+
*
|
|
13
|
+
* This provider stays synchronous and leaves AES and asynchronous key
|
|
14
|
+
* derivation on Ox's default implementation.
|
|
15
|
+
*
|
|
16
|
+
* Scrypt uses a standalone artifact and grows memory only when called.
|
|
17
|
+
* WebAssembly cannot shrink that capacity. The provider clears its contents
|
|
18
|
+
* and enforces Noble's 1 GiB temporary-workspace limit.
|
|
19
|
+
*
|
|
20
|
+
* The aggregate [`Engine.install`](/wasm/crypto/Engine/install) installs only
|
|
21
|
+
* PBKDF2 from this provider. Install this factory explicitly to opt into
|
|
22
|
+
* scrypt, whose relative performance depends on its parameters and runtime.
|
|
23
|
+
*
|
|
24
|
+
* Copied inputs, derived output, and the complete workspace are cleared after
|
|
25
|
+
* every return or trap.
|
|
14
26
|
*
|
|
15
27
|
* @example
|
|
16
28
|
* ```ts twoslash
|
|
@@ -20,15 +32,20 @@ export { MemoryError } from './internal/instantiate.js';
|
|
|
20
32
|
*
|
|
21
33
|
* await Engine.install({ Keystore: Keystore.engine() })
|
|
22
34
|
*
|
|
23
|
-
* Keystore.
|
|
35
|
+
* Keystore.scrypt({ password: 'testpassword' })
|
|
24
36
|
* ```
|
|
25
37
|
*
|
|
26
|
-
* @returns The WASM
|
|
38
|
+
* @returns The WASM implementations of synchronous PBKDF2-HMAC-SHA256 and
|
|
39
|
+
* scrypt.
|
|
27
40
|
*/
|
|
28
41
|
export async function engine() {
|
|
29
|
-
const
|
|
42
|
+
const [keystoreEngine, scryptModule] = await Promise.all([
|
|
43
|
+
keystore.engine(),
|
|
44
|
+
scrypt.load(),
|
|
45
|
+
]);
|
|
30
46
|
return {
|
|
31
|
-
|
|
47
|
+
...keystoreEngine,
|
|
48
|
+
scrypt: (password, salt, options) => scrypt.derive(scryptModule, password, salt, options),
|
|
32
49
|
};
|
|
33
50
|
}
|
|
34
51
|
//# sourceMappingURL=Keystore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Keystore.js","sourceRoot":"","sources":["../../src/wasm/Keystore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Keystore.js","sourceRoot":"","sources":["../../src/wasm/Keystore.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAA;AAClD,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAA;AAE9C,cAAc,qBAAqB,CAAA;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM;IAC1B,MAAM,CAAC,cAAc,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACvD,QAAQ,CAAC,MAAM,EAAE;QACjB,MAAM,CAAC,IAAI,EAAE;KACd,CAAC,CAAA;IACF,OAAO;QACL,GAAG,cAAc;QACjB,MAAM,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAClC,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC;KACvD,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import * as Bytes from '../core/Bytes.js';
|
|
2
|
+
import * as Errors from '../core/Errors.js';
|
|
3
|
+
import type * as CoreKzg from '../core/Kzg.js';
|
|
4
|
+
export * from '../core/Kzg.js';
|
|
5
|
+
/**
|
|
6
|
+
* Trusted setup points accepted by `create`.
|
|
7
|
+
*
|
|
8
|
+
* Point arrays use the established Ethereum trusted-setup field names. Each
|
|
9
|
+
* field may also be supplied as one packed byte array.
|
|
10
|
+
*/
|
|
11
|
+
export type TrustedSetup = {
|
|
12
|
+
/** 4,096 G1 points in Lagrange form. */
|
|
13
|
+
readonly g1_lagrange: Bytes.Bytes | readonly string[];
|
|
14
|
+
/** 4,096 G1 points in monomial form. */
|
|
15
|
+
readonly g1_monomial: Bytes.Bytes | readonly string[];
|
|
16
|
+
/** 65 G2 points in monomial form. */
|
|
17
|
+
readonly g2_monomial: Bytes.Bytes | readonly string[];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Creates an independently owned WASM implementation of [`Kzg.Kzg`](/api/Kzg).
|
|
21
|
+
*
|
|
22
|
+
* The factory compiles the c-kzg artifact once per JavaScript realm. Every call
|
|
23
|
+
* instantiates separate WASM memory and trusted-setup state. Call `dispose` when
|
|
24
|
+
* the instance is no longer needed.
|
|
25
|
+
*
|
|
26
|
+
* Operations on an instance are synchronous and run to completion. JavaScript
|
|
27
|
+
* workers do not share an instance, so create one in each worker that needs KZG.
|
|
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
|
+
* // Pass `kzg` anywhere that accepts `Kzg.Kzg`.
|
|
39
|
+
*
|
|
40
|
+
* kzg.dispose()
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @param options - Trusted setup and precomputation options.
|
|
44
|
+
* @returns An initialized KZG implementation with explicit disposal.
|
|
45
|
+
*/
|
|
46
|
+
export declare function create(options: create.Options): Promise<create.ReturnType>;
|
|
47
|
+
export declare namespace create {
|
|
48
|
+
/** Options for `create`. */
|
|
49
|
+
type Options = {
|
|
50
|
+
/**
|
|
51
|
+
* Fixed-base MSM window from 0 through 8.
|
|
52
|
+
*
|
|
53
|
+
* `0` performs no fixed-base precomputation and uses the least memory.
|
|
54
|
+
* Larger values improve proof generation at an exponential memory cost.
|
|
55
|
+
*
|
|
56
|
+
* @default 0
|
|
57
|
+
*/
|
|
58
|
+
precompute?: number | undefined;
|
|
59
|
+
/** Ethereum trusted-setup points. */
|
|
60
|
+
trustedSetup: TrustedSetup;
|
|
61
|
+
};
|
|
62
|
+
/** An initialized KZG implementation with explicit lifecycle ownership. */
|
|
63
|
+
type ReturnType = CoreKzg.Kzg & {
|
|
64
|
+
/**
|
|
65
|
+
* Releases the trusted setup and makes every operation throw.
|
|
66
|
+
*
|
|
67
|
+
* Disposal is idempotent.
|
|
68
|
+
*/
|
|
69
|
+
dispose(): void;
|
|
70
|
+
};
|
|
71
|
+
type ErrorType = DisposedError | InvalidInputError | InvalidPrecomputeError | InvalidTrustedSetupError | MemoryError | WasmError | Errors.GlobalErrorType;
|
|
72
|
+
}
|
|
73
|
+
/** Thrown when an operation is called after its KZG instance was disposed. */
|
|
74
|
+
export declare class DisposedError extends Errors.BaseError {
|
|
75
|
+
readonly name = "Kzg.DisposedError";
|
|
76
|
+
constructor();
|
|
77
|
+
}
|
|
78
|
+
/** Thrown when a KZG operation receives malformed input. */
|
|
79
|
+
export declare class InvalidInputError extends Errors.BaseError {
|
|
80
|
+
readonly name = "Kzg.InvalidInputError";
|
|
81
|
+
constructor({ message }: {
|
|
82
|
+
message: string;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/** Thrown when `precompute` is outside the supported memory bound. */
|
|
86
|
+
export declare class InvalidPrecomputeError extends Errors.BaseError {
|
|
87
|
+
readonly name = "Kzg.InvalidPrecomputeError";
|
|
88
|
+
constructor({ precompute }: {
|
|
89
|
+
precompute: number;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/** Thrown when c-kzg rejects the trusted setup. */
|
|
93
|
+
export declare class InvalidTrustedSetupError extends Errors.BaseError {
|
|
94
|
+
readonly name = "Kzg.InvalidTrustedSetupError";
|
|
95
|
+
constructor(options?: {
|
|
96
|
+
message?: string | undefined;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/** Thrown when the KZG artifact reaches its 128 MiB memory limit. */
|
|
100
|
+
export declare class MemoryError extends Errors.BaseError {
|
|
101
|
+
readonly name = "Kzg.MemoryError";
|
|
102
|
+
constructor();
|
|
103
|
+
}
|
|
104
|
+
/** Thrown when the KZG artifact traps or reports an internal error. */
|
|
105
|
+
export declare class WasmError extends Errors.BaseError<Error | undefined> {
|
|
106
|
+
readonly name = "Kzg.WasmError";
|
|
107
|
+
constructor(options?: {
|
|
108
|
+
cause?: Error | undefined;
|
|
109
|
+
operation?: string | undefined;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=Kzg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Kzg.d.ts","sourceRoot":"","sources":["../../src/wasm/Kzg.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAE3C,OAAO,KAAK,KAAK,OAAO,MAAM,gBAAgB,CAAA;AAG9C,cAAc,gBAAgB,CAAA;AAU9B;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,wCAAwC;IACxC,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC,KAAK,GAAG,SAAS,MAAM,EAAE,CAAA;IACrD,wCAAwC;IACxC,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC,KAAK,GAAG,SAAS,MAAM,EAAE,CAAA;IACrD,qCAAqC;IACrC,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC,KAAK,GAAG,SAAS,MAAM,EAAE,CAAA;CACtD,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,MAAM,CAC1B,OAAO,EAAE,MAAM,CAAC,OAAO,GACtB,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAiN5B;AAED,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,4BAA4B;IAC5B,KAAK,OAAO,GAAG;QACb;;;;;;;WAOG;QACH,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QAC/B,qCAAqC;QACrC,YAAY,EAAE,YAAY,CAAA;KAC3B,CAAA;IAED,2EAA2E;IAC3E,KAAK,UAAU,GAAG,OAAO,CAAC,GAAG,GAAG;QAC9B;;;;WAIG;QACH,OAAO,IAAI,IAAI,CAAA;KAChB,CAAA;IAED,KAAK,SAAS,GACV,aAAa,GACb,iBAAiB,GACjB,sBAAsB,GACtB,wBAAwB,GACxB,WAAW,GACX,SAAS,GACT,MAAM,CAAC,eAAe,CAAA;CAC3B;AAkJD,8EAA8E;AAC9E,qBAAa,aAAc,SAAQ,MAAM,CAAC,SAAS;IACjD,SAAkB,IAAI,uBAAsB;;CAK7C;AAED,4DAA4D;AAC5D,qBAAa,iBAAkB,SAAQ,MAAM,CAAC,SAAS;IACrD,SAAkB,IAAI,2BAA0B;gBAEpC,EAAE,OAAO,EAAE,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE;CAG7C;AAED,sEAAsE;AACtE,qBAAa,sBAAuB,SAAQ,MAAM,CAAC,SAAS;IAC1D,SAAkB,IAAI,gCAA+B;gBAEzC,EAAE,UAAU,EAAE,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE;CAKnD;AAED,mDAAmD;AACnD,qBAAa,wBAAyB,SAAQ,MAAM,CAAC,SAAS;IAC5D,SAAkB,IAAI,kCAAiC;gBAE3C,OAAO,GAAE;QAAE,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAO;CAG3D;AAED,qEAAqE;AACrE,qBAAa,WAAY,SAAQ,MAAM,CAAC,SAAS;IAC/C,SAAkB,IAAI,qBAAoB;;CAU3C;AAED,uEAAuE;AACvE,qBAAa,SAAU,SAAQ,MAAM,CAAC,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC;IAChE,SAAkB,IAAI,mBAAkB;gBAGtC,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAO;CAS9E"}
|
package/dist/wasm/Kzg.js
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import * as Errors from '../core/Errors.js';
|
|
2
|
+
import * as Hex from '../core/Hex.js';
|
|
3
|
+
export * from '../core/Kzg.js';
|
|
4
|
+
const blobSize = 131_072;
|
|
5
|
+
const cellSize = 2_048;
|
|
6
|
+
const cellsPerBlob = 128;
|
|
7
|
+
const commitmentSize = 48;
|
|
8
|
+
const g1Points = 4_096;
|
|
9
|
+
const g2Points = 65;
|
|
10
|
+
const proofSize = 48;
|
|
11
|
+
/**
|
|
12
|
+
* Creates an independently owned WASM implementation of [`Kzg.Kzg`](/api/Kzg).
|
|
13
|
+
*
|
|
14
|
+
* The factory compiles the c-kzg artifact once per JavaScript realm. Every call
|
|
15
|
+
* instantiates separate WASM memory and trusted-setup state. Call `dispose` when
|
|
16
|
+
* the instance is no longer needed.
|
|
17
|
+
*
|
|
18
|
+
* Operations on an instance are synchronous and run to completion. JavaScript
|
|
19
|
+
* workers do not share an instance, so create one in each worker that needs KZG.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts twoslash
|
|
23
|
+
* // @noErrors
|
|
24
|
+
* import { Setups } from 'ox/trusted-setups'
|
|
25
|
+
* import { Kzg } from 'ox/wasm'
|
|
26
|
+
*
|
|
27
|
+
* const kzg = await Kzg.create({
|
|
28
|
+
* trustedSetup: Setups.mainnet
|
|
29
|
+
* })
|
|
30
|
+
* // Pass `kzg` anywhere that accepts `Kzg.Kzg`.
|
|
31
|
+
*
|
|
32
|
+
* kzg.dispose()
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @param options - Trusted setup and precomputation options.
|
|
36
|
+
* @returns An initialized KZG implementation with explicit disposal.
|
|
37
|
+
*/
|
|
38
|
+
export async function create(options) {
|
|
39
|
+
const { trustedSetup } = options;
|
|
40
|
+
const precompute = options.precompute ?? 0;
|
|
41
|
+
if (!Number.isInteger(precompute) || precompute < 0 || precompute > 8)
|
|
42
|
+
throw new InvalidPrecomputeError({ precompute });
|
|
43
|
+
const setup = {
|
|
44
|
+
g1Lagrange: normalizePoints(trustedSetup.g1_lagrange, g1Points, commitmentSize, 'g1_lagrange'),
|
|
45
|
+
g1Monomial: normalizePoints(trustedSetup.g1_monomial, g1Points, commitmentSize, 'g1_monomial'),
|
|
46
|
+
g2Monomial: normalizePoints(trustedSetup.g2_monomial, g2Points, 96, 'g2_monomial'),
|
|
47
|
+
};
|
|
48
|
+
const { instantiate } = await import('./internal/kzg.js');
|
|
49
|
+
let module = await instantiate();
|
|
50
|
+
const getModule = () => {
|
|
51
|
+
if (!module)
|
|
52
|
+
throw new DisposedError();
|
|
53
|
+
return module;
|
|
54
|
+
};
|
|
55
|
+
try {
|
|
56
|
+
const initialized = getModule();
|
|
57
|
+
withBuffers(initialized, [setup.g1Monomial, setup.g1Lagrange, setup.g2Monomial], [], ([g1Monomial, g1Lagrange, g2Monomial]) => {
|
|
58
|
+
assertReturn(initialized.exports.kzg_initialize(g1Monomial, g1Lagrange, g2Monomial, precompute), 'initialize');
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
module?.exports.kzg_dispose();
|
|
63
|
+
module = undefined;
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
const instance = {
|
|
67
|
+
blobToKzgCommitment(blob) {
|
|
68
|
+
assertBytes(blob, blobSize, 'blob');
|
|
69
|
+
return withBuffers(getModule(), [blob], [commitmentSize], ([blob], [out]) => {
|
|
70
|
+
const module = getModule();
|
|
71
|
+
assertReturn(module.exports.kzg_blob_to_kzg_commitment(out, blob), 'blobToKzgCommitment');
|
|
72
|
+
})[0];
|
|
73
|
+
},
|
|
74
|
+
computeCells(blob) {
|
|
75
|
+
assertBytes(blob, blobSize, 'blob');
|
|
76
|
+
const bytes = withBuffers(getModule(), [blob], [cellsPerBlob * cellSize], ([blob], [cells]) => {
|
|
77
|
+
const module = getModule();
|
|
78
|
+
assertReturn(module.exports.kzg_compute_cells(cells, blob), 'computeCells');
|
|
79
|
+
})[0];
|
|
80
|
+
return split(bytes, cellSize);
|
|
81
|
+
},
|
|
82
|
+
computeCellsAndKzgProofs(blob) {
|
|
83
|
+
assertBytes(blob, blobSize, 'blob');
|
|
84
|
+
const [cells, proofs] = withBuffers(getModule(), [blob], [cellsPerBlob * cellSize, cellsPerBlob * proofSize], ([blob], [cells, proofs]) => {
|
|
85
|
+
const module = getModule();
|
|
86
|
+
assertReturn(module.exports.kzg_compute_cells_and_kzg_proofs(cells, proofs, blob), 'computeCellsAndKzgProofs');
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
cells: split(cells, cellSize),
|
|
90
|
+
proofs: split(proofs, proofSize),
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
dispose() {
|
|
94
|
+
if (!module)
|
|
95
|
+
return;
|
|
96
|
+
const initialized = module;
|
|
97
|
+
module = undefined;
|
|
98
|
+
initialized.exports.kzg_dispose();
|
|
99
|
+
},
|
|
100
|
+
recoverCellsAndKzgProofs(cellIndices, cells) {
|
|
101
|
+
if (cellIndices.length !== cells.length)
|
|
102
|
+
throw new InvalidInputError({
|
|
103
|
+
message: '`cellIndices` and `cells` must have the same length.',
|
|
104
|
+
});
|
|
105
|
+
if (cells.length < 64 || cells.length > cellsPerBlob)
|
|
106
|
+
throw new InvalidInputError({
|
|
107
|
+
message: '`cells` must contain between 64 and 128 cells.',
|
|
108
|
+
});
|
|
109
|
+
assertCellIndices(cellIndices, true);
|
|
110
|
+
for (const cell of cells)
|
|
111
|
+
assertBytes(cell, cellSize, 'cell');
|
|
112
|
+
const values = cellIndices
|
|
113
|
+
.map((index, i) => ({ cell: cells[i], index }))
|
|
114
|
+
.sort((a, b) => a.index - b.index);
|
|
115
|
+
const indices = values.map(({ index }) => index);
|
|
116
|
+
const sortedCells = values.map(({ cell }) => cell);
|
|
117
|
+
const [recoveredCells, proofs] = withBuffers(getModule(), [encodeIndices(indices), concat(sortedCells)], [cellsPerBlob * cellSize, cellsPerBlob * proofSize], ([indices, cells], [recoveredCells, proofs]) => {
|
|
118
|
+
const module = getModule();
|
|
119
|
+
assertReturn(module.exports.kzg_recover_cells_and_kzg_proofs(recoveredCells, proofs, indices, cells, values.length), 'recoverCellsAndKzgProofs');
|
|
120
|
+
});
|
|
121
|
+
return {
|
|
122
|
+
cells: split(recoveredCells, cellSize),
|
|
123
|
+
proofs: split(proofs, proofSize),
|
|
124
|
+
};
|
|
125
|
+
},
|
|
126
|
+
verifyCellKzgProofBatch(commitments, cellIndices, cells, proofs) {
|
|
127
|
+
const count = commitments.length;
|
|
128
|
+
if (count === 0 ||
|
|
129
|
+
cellIndices.length !== count ||
|
|
130
|
+
cells.length !== count ||
|
|
131
|
+
proofs.length !== count)
|
|
132
|
+
throw new InvalidInputError({
|
|
133
|
+
message: '`commitments`, `cellIndices`, `cells`, and `proofs` must have the same non-zero length.',
|
|
134
|
+
});
|
|
135
|
+
assertCellIndices(cellIndices, false);
|
|
136
|
+
for (const commitment of commitments)
|
|
137
|
+
assertBytes(commitment, commitmentSize, 'commitment');
|
|
138
|
+
for (const cell of cells)
|
|
139
|
+
assertBytes(cell, cellSize, 'cell');
|
|
140
|
+
for (const proof of proofs)
|
|
141
|
+
assertBytes(proof, proofSize, 'proof');
|
|
142
|
+
return (withBuffers(getModule(), [
|
|
143
|
+
concat(commitments),
|
|
144
|
+
encodeIndices(cellIndices),
|
|
145
|
+
concat(cells),
|
|
146
|
+
concat(proofs),
|
|
147
|
+
], [4], ([commitments, indices, cells, proofs], [verified]) => {
|
|
148
|
+
const module = getModule();
|
|
149
|
+
assertReturn(module.exports.kzg_verify_cell_kzg_proof_batch(verified, commitments, indices, cells, proofs, count), 'verifyCellKzgProofBatch');
|
|
150
|
+
})[0][0] === 1);
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
return instance;
|
|
154
|
+
}
|
|
155
|
+
function assertBytes(value, size, name) {
|
|
156
|
+
if (!(value instanceof Uint8Array) || value.length !== size)
|
|
157
|
+
throw new InvalidInputError({
|
|
158
|
+
message: `\`${name}\` must contain exactly ${size} bytes.`,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
function assertCellIndices(indices, unique) {
|
|
162
|
+
const seen = new Set();
|
|
163
|
+
for (const index of indices) {
|
|
164
|
+
if (!Number.isInteger(index) || index < 0 || index >= cellsPerBlob)
|
|
165
|
+
throw new InvalidInputError({
|
|
166
|
+
message: '`cellIndices` must contain integers from 0 through 127.',
|
|
167
|
+
});
|
|
168
|
+
if (unique && seen.has(index))
|
|
169
|
+
throw new InvalidInputError({
|
|
170
|
+
message: '`cellIndices` must not contain duplicate indices.',
|
|
171
|
+
});
|
|
172
|
+
seen.add(index);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function assertReturn(value, operation) {
|
|
176
|
+
if (value === 0)
|
|
177
|
+
return;
|
|
178
|
+
if (value === 1)
|
|
179
|
+
throw operation === 'initialize'
|
|
180
|
+
? new InvalidTrustedSetupError()
|
|
181
|
+
: new InvalidInputError({ message: `c-kzg rejected \`${operation}\`.` });
|
|
182
|
+
if (value === 3)
|
|
183
|
+
throw new MemoryError();
|
|
184
|
+
throw new WasmError({ operation });
|
|
185
|
+
}
|
|
186
|
+
function concat(values) {
|
|
187
|
+
const size = values.reduce((size, value) => size + value.length, 0);
|
|
188
|
+
const result = new Uint8Array(size);
|
|
189
|
+
let offset = 0;
|
|
190
|
+
for (const value of values) {
|
|
191
|
+
result.set(value, offset);
|
|
192
|
+
offset += value.length;
|
|
193
|
+
}
|
|
194
|
+
return result;
|
|
195
|
+
}
|
|
196
|
+
function encodeIndices(indices) {
|
|
197
|
+
const bytes = new Uint8Array(indices.length * 8);
|
|
198
|
+
const view = new DataView(bytes.buffer);
|
|
199
|
+
for (let i = 0; i < indices.length; i++)
|
|
200
|
+
view.setBigUint64(i * 8, BigInt(indices[i]), true);
|
|
201
|
+
return bytes;
|
|
202
|
+
}
|
|
203
|
+
function normalizePoints(value, count, size, name) {
|
|
204
|
+
const expected = count * size;
|
|
205
|
+
if (value instanceof Uint8Array) {
|
|
206
|
+
if (value.length !== expected)
|
|
207
|
+
throw new InvalidTrustedSetupError({
|
|
208
|
+
message: `\`${name}\` must contain exactly ${expected} bytes.`,
|
|
209
|
+
});
|
|
210
|
+
return Uint8Array.from(value);
|
|
211
|
+
}
|
|
212
|
+
if (!Array.isArray(value) || value.length !== count)
|
|
213
|
+
throw new InvalidTrustedSetupError({
|
|
214
|
+
message: `\`${name}\` must contain exactly ${count} points.`,
|
|
215
|
+
});
|
|
216
|
+
const result = new Uint8Array(expected);
|
|
217
|
+
for (let i = 0; i < value.length; i++) {
|
|
218
|
+
const point = value[i];
|
|
219
|
+
try {
|
|
220
|
+
const bytes = Hex.toBytes(point);
|
|
221
|
+
if (bytes.length !== size)
|
|
222
|
+
throw new Error();
|
|
223
|
+
result.set(bytes, i * size);
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
throw new InvalidTrustedSetupError({
|
|
227
|
+
message: `\`${name}[${i}]\` must be a ${size}-byte hex value.`,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return result;
|
|
232
|
+
}
|
|
233
|
+
function split(value, size) {
|
|
234
|
+
const result = [];
|
|
235
|
+
for (let offset = 0; offset < value.length; offset += size)
|
|
236
|
+
result.push(value.slice(offset, offset + size));
|
|
237
|
+
return result;
|
|
238
|
+
}
|
|
239
|
+
function withBuffers(module, inputs, outputs, call) {
|
|
240
|
+
const inputPointers = [];
|
|
241
|
+
const outputPointers = [];
|
|
242
|
+
try {
|
|
243
|
+
for (const input of inputs)
|
|
244
|
+
inputPointers.push(allocate(module, input.length));
|
|
245
|
+
for (const size of outputs)
|
|
246
|
+
outputPointers.push(allocate(module, size));
|
|
247
|
+
const view = module.view();
|
|
248
|
+
for (let i = 0; i < inputs.length; i++)
|
|
249
|
+
view.set(inputs[i], inputPointers[i]);
|
|
250
|
+
call(inputPointers, outputPointers);
|
|
251
|
+
return outputs.map((size, i) => module.view().slice(outputPointers[i], outputPointers[i] + size));
|
|
252
|
+
}
|
|
253
|
+
catch (cause) {
|
|
254
|
+
if (cause instanceof Errors.BaseError)
|
|
255
|
+
throw cause;
|
|
256
|
+
throw new WasmError({ cause: cause });
|
|
257
|
+
}
|
|
258
|
+
finally {
|
|
259
|
+
for (let i = 0; i < inputs.length; i++) {
|
|
260
|
+
const pointer = inputPointers[i];
|
|
261
|
+
if (!pointer)
|
|
262
|
+
continue;
|
|
263
|
+
module.exports.zero(pointer, inputs[i].length);
|
|
264
|
+
module.exports.dealloc(pointer);
|
|
265
|
+
}
|
|
266
|
+
for (let i = 0; i < outputs.length; i++) {
|
|
267
|
+
const pointer = outputPointers[i];
|
|
268
|
+
if (!pointer)
|
|
269
|
+
continue;
|
|
270
|
+
module.exports.zero(pointer, outputs[i]);
|
|
271
|
+
module.exports.dealloc(pointer);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
function allocate(module, size) {
|
|
276
|
+
const pointer = module.exports.alloc(size);
|
|
277
|
+
if (!pointer)
|
|
278
|
+
throw new MemoryError();
|
|
279
|
+
return pointer;
|
|
280
|
+
}
|
|
281
|
+
/** Thrown when an operation is called after its KZG instance was disposed. */
|
|
282
|
+
export class DisposedError extends Errors.BaseError {
|
|
283
|
+
name = 'Kzg.DisposedError';
|
|
284
|
+
constructor() {
|
|
285
|
+
super('KZG instance has been disposed.');
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
/** Thrown when a KZG operation receives malformed input. */
|
|
289
|
+
export class InvalidInputError extends Errors.BaseError {
|
|
290
|
+
name = 'Kzg.InvalidInputError';
|
|
291
|
+
constructor({ message }) {
|
|
292
|
+
super(message);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
/** Thrown when `precompute` is outside the supported memory bound. */
|
|
296
|
+
export class InvalidPrecomputeError extends Errors.BaseError {
|
|
297
|
+
name = 'Kzg.InvalidPrecomputeError';
|
|
298
|
+
constructor({ precompute }) {
|
|
299
|
+
super(`\`precompute\` must be an integer from 0 through 8. Got ${precompute}.`);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
/** Thrown when c-kzg rejects the trusted setup. */
|
|
303
|
+
export class InvalidTrustedSetupError extends Errors.BaseError {
|
|
304
|
+
name = 'Kzg.InvalidTrustedSetupError';
|
|
305
|
+
constructor(options = {}) {
|
|
306
|
+
super(options.message ?? 'c-kzg rejected the trusted setup.');
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
/** Thrown when the KZG artifact reaches its 128 MiB memory limit. */
|
|
310
|
+
export class MemoryError extends Errors.BaseError {
|
|
311
|
+
name = 'Kzg.MemoryError';
|
|
312
|
+
constructor() {
|
|
313
|
+
super('KZG WASM memory limit was exceeded.', {
|
|
314
|
+
metaMessages: [
|
|
315
|
+
'The artifact grows memory on demand up to 128 MiB.',
|
|
316
|
+
'Use a smaller `precompute` value or batch fewer proofs.',
|
|
317
|
+
],
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
/** Thrown when the KZG artifact traps or reports an internal error. */
|
|
322
|
+
export class WasmError extends Errors.BaseError {
|
|
323
|
+
name = 'Kzg.WasmError';
|
|
324
|
+
constructor(options = {}) {
|
|
325
|
+
super('KZG WASM operation failed.', {
|
|
326
|
+
cause: options.cause,
|
|
327
|
+
metaMessages: options.operation
|
|
328
|
+
? [`Operation: ${options.operation}`]
|
|
329
|
+
: undefined,
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
//# sourceMappingURL=Kzg.js.map
|