@rolly-dev/wasm-signer 0.1.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/README.md +115 -0
- package/dist/node/README.md +115 -0
- package/dist/node/package.json +1 -0
- package/dist/node/rolly_wasm_signer.d.ts +120 -0
- package/dist/node/rolly_wasm_signer.js +328 -0
- package/dist/node/rolly_wasm_signer_bg.wasm +0 -0
- package/dist/node/rolly_wasm_signer_bg.wasm.d.ts +15 -0
- package/dist/web/README.md +115 -0
- package/dist/web/rolly_wasm_signer.d.ts +160 -0
- package/dist/web/rolly_wasm_signer.js +415 -0
- package/dist/web/rolly_wasm_signer_bg.wasm +0 -0
- package/dist/web/rolly_wasm_signer_bg.wasm.d.ts +15 -0
- package/js/browser.mjs +13 -0
- package/js/node.cjs +15 -0
- package/js/node.mjs +16 -0
- package/js/react.mjs +57 -0
- package/package.json +52 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const compute_server_seed_hash: (a: number, b: number, c: number) => void;
|
|
5
|
+
export const create_bet_auth: (a: number, b: number, c: number, d: bigint, e: bigint) => void;
|
|
6
|
+
export const derive_session_key: (a: number, b: number, c: number) => void;
|
|
7
|
+
export const goldilocks_reduce: (a: bigint) => bigint;
|
|
8
|
+
export const poseidon2_hash: (a: number, b: number, c: number) => void;
|
|
9
|
+
export const poseidon2_two_to_one: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
10
|
+
export const seed_hash_truncated: (a: number, b: number, c: number) => void;
|
|
11
|
+
export const session_public_key: (a: number, b: number, c: number) => void;
|
|
12
|
+
export const goldilocks_modulus: () => bigint;
|
|
13
|
+
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
14
|
+
export const __wbindgen_export: (a: number, b: number) => number;
|
|
15
|
+
export const __wbindgen_export2: (a: number, b: number, c: number) => void;
|
package/js/browser.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { default as init } from '../dist/web/rolly_wasm_signer.js';
|
|
2
|
+
|
|
3
|
+
export {
|
|
4
|
+
poseidon2_hash,
|
|
5
|
+
poseidon2_two_to_one,
|
|
6
|
+
derive_session_key,
|
|
7
|
+
session_public_key,
|
|
8
|
+
create_bet_auth,
|
|
9
|
+
compute_server_seed_hash,
|
|
10
|
+
seed_hash_truncated,
|
|
11
|
+
goldilocks_modulus,
|
|
12
|
+
goldilocks_reduce,
|
|
13
|
+
} from '../dist/web/rolly_wasm_signer.js';
|
package/js/node.cjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const wasm = require('../dist/node/rolly_wasm_signer.js');
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
poseidon2_hash: wasm.poseidon2_hash,
|
|
7
|
+
poseidon2_two_to_one: wasm.poseidon2_two_to_one,
|
|
8
|
+
derive_session_key: wasm.derive_session_key,
|
|
9
|
+
session_public_key: wasm.session_public_key,
|
|
10
|
+
create_bet_auth: wasm.create_bet_auth,
|
|
11
|
+
compute_server_seed_hash: wasm.compute_server_seed_hash,
|
|
12
|
+
seed_hash_truncated: wasm.seed_hash_truncated,
|
|
13
|
+
goldilocks_modulus: wasm.goldilocks_modulus,
|
|
14
|
+
goldilocks_reduce: wasm.goldilocks_reduce,
|
|
15
|
+
};
|
package/js/node.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
const wasm = require('../dist/node/rolly_wasm_signer.js');
|
|
5
|
+
|
|
6
|
+
export const {
|
|
7
|
+
poseidon2_hash,
|
|
8
|
+
poseidon2_two_to_one,
|
|
9
|
+
derive_session_key,
|
|
10
|
+
session_public_key,
|
|
11
|
+
create_bet_auth,
|
|
12
|
+
compute_server_seed_hash,
|
|
13
|
+
seed_hash_truncated,
|
|
14
|
+
goldilocks_modulus,
|
|
15
|
+
goldilocks_reduce,
|
|
16
|
+
} = wasm;
|
package/js/react.mjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import init, {
|
|
3
|
+
poseidon2_hash,
|
|
4
|
+
poseidon2_two_to_one,
|
|
5
|
+
derive_session_key,
|
|
6
|
+
session_public_key,
|
|
7
|
+
create_bet_auth,
|
|
8
|
+
compute_server_seed_hash,
|
|
9
|
+
seed_hash_truncated,
|
|
10
|
+
goldilocks_modulus,
|
|
11
|
+
goldilocks_reduce,
|
|
12
|
+
} from '../dist/web/rolly_wasm_signer.js';
|
|
13
|
+
|
|
14
|
+
let _ready = false;
|
|
15
|
+
let _promise = null;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* React hook that initialises the WASM module once (singleton) and
|
|
19
|
+
* returns `{ ready, error, ...wasmFunctions }`.
|
|
20
|
+
*
|
|
21
|
+
* Functions are `null` until `ready === true`.
|
|
22
|
+
*
|
|
23
|
+
* ```jsx
|
|
24
|
+
* const { ready, poseidon2_hash } = useRollyWasm();
|
|
25
|
+
* if (!ready) return <Spinner />;
|
|
26
|
+
* const h = poseidon2_hash(BigUint64Array.from([1n, 2n]));
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export function useRollyWasm() {
|
|
30
|
+
const [ready, setReady] = useState(_ready);
|
|
31
|
+
const [error, setError] = useState(null);
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (_ready) {
|
|
35
|
+
setReady(true);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (!_promise) {
|
|
39
|
+
_promise = init().then(() => { _ready = true; });
|
|
40
|
+
}
|
|
41
|
+
_promise.then(() => setReady(true)).catch(setError);
|
|
42
|
+
}, []);
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
ready,
|
|
46
|
+
error,
|
|
47
|
+
poseidon2_hash: ready ? poseidon2_hash : null,
|
|
48
|
+
poseidon2_two_to_one: ready ? poseidon2_two_to_one : null,
|
|
49
|
+
derive_session_key: ready ? derive_session_key : null,
|
|
50
|
+
session_public_key: ready ? session_public_key : null,
|
|
51
|
+
create_bet_auth: ready ? create_bet_auth : null,
|
|
52
|
+
compute_server_seed_hash: ready ? compute_server_seed_hash : null,
|
|
53
|
+
seed_hash_truncated: ready ? seed_hash_truncated : null,
|
|
54
|
+
goldilocks_modulus: ready ? goldilocks_modulus : null,
|
|
55
|
+
goldilocks_reduce: ready ? goldilocks_reduce : null,
|
|
56
|
+
};
|
|
57
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rolly-dev/wasm-signer",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Poseidon2 hashing & bet signing for Rolly ZK-Rollup (WASM, Goldilocks field)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"node": {
|
|
9
|
+
"require": "./js/node.cjs",
|
|
10
|
+
"import": "./js/node.mjs"
|
|
11
|
+
},
|
|
12
|
+
"browser": "./js/browser.mjs",
|
|
13
|
+
"default": "./js/browser.mjs"
|
|
14
|
+
},
|
|
15
|
+
"./react": {
|
|
16
|
+
"default": "./js/react.mjs"
|
|
17
|
+
},
|
|
18
|
+
"./init": {
|
|
19
|
+
"default": "./dist/web/rolly_wasm_signer.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"main": "./js/node.cjs",
|
|
23
|
+
"module": "./js/browser.mjs",
|
|
24
|
+
"types": "./dist/node/rolly_wasm_signer.d.ts",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist/",
|
|
27
|
+
"js/"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "bash build.sh",
|
|
31
|
+
"prepublishOnly": "npm run build",
|
|
32
|
+
"test": "node test.js"
|
|
33
|
+
},
|
|
34
|
+
"sideEffects": false,
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"react": ">=17.0.0"
|
|
37
|
+
},
|
|
38
|
+
"peerDependenciesMeta": {
|
|
39
|
+
"react": {
|
|
40
|
+
"optional": true
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"wasm",
|
|
45
|
+
"poseidon2",
|
|
46
|
+
"goldilocks",
|
|
47
|
+
"zk-rollup",
|
|
48
|
+
"signing",
|
|
49
|
+
"plonky2"
|
|
50
|
+
],
|
|
51
|
+
"license": "MIT"
|
|
52
|
+
}
|