@tokamak-private-dapps/private-state-cli 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/CHANGELOG.md +5 -0
- package/LICENSE +8 -0
- package/README.md +79 -0
- package/cli-assistant.html +1869 -0
- package/lib/private-state-cli-shared.mjs +94 -0
- package/package.json +54 -0
- package/private-state-bridge-cli.mjs +5127 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import {
|
|
3
|
+
ethers,
|
|
4
|
+
getAddress,
|
|
5
|
+
keccak256,
|
|
6
|
+
} from "ethers";
|
|
7
|
+
import {
|
|
8
|
+
deriveL2KeysFromSignature,
|
|
9
|
+
fromEdwardsToAddress,
|
|
10
|
+
} from "tokamak-l2js";
|
|
11
|
+
|
|
12
|
+
export const L2_PASSWORD_SIGNING_DOMAIN = "Tokamak private-state L2 password binding";
|
|
13
|
+
export const CHANNEL_BOUND_L2_DERIVATION_MODE = "channel-name-plus-password-v1";
|
|
14
|
+
|
|
15
|
+
export function slugifyPathComponent(value) {
|
|
16
|
+
return String(value)
|
|
17
|
+
.replace(/[^a-zA-Z0-9]+/g, "-")
|
|
18
|
+
.replace(/^-+|-+$/g, "")
|
|
19
|
+
.toLowerCase();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function deriveChannelIdFromName(channelName) {
|
|
23
|
+
return ethers.toBigInt(keccak256(ethers.toUtf8Bytes(channelName)));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function buildL2PasswordSigningMessage({ channelName, password }) {
|
|
27
|
+
if (typeof channelName !== "string" || channelName.length === 0) {
|
|
28
|
+
throw new Error("Missing channel name for L2 identity derivation.");
|
|
29
|
+
}
|
|
30
|
+
return [
|
|
31
|
+
L2_PASSWORD_SIGNING_DOMAIN,
|
|
32
|
+
`channel:${channelName}`,
|
|
33
|
+
`password:${String(password)}`,
|
|
34
|
+
].join("\n");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function deriveParticipantIdentityFromSigner({ channelName, password, signer }) {
|
|
38
|
+
const seedSignature = await signer.signMessage(buildL2PasswordSigningMessage({ channelName, password }));
|
|
39
|
+
const keySet = deriveL2KeysFromSignature(seedSignature);
|
|
40
|
+
const l2Address = getAddress(fromEdwardsToAddress(keySet.publicKey).toString());
|
|
41
|
+
return {
|
|
42
|
+
seedSignature,
|
|
43
|
+
l2PrivateKey: keySet.privateKey,
|
|
44
|
+
l2PublicKey: keySet.publicKey,
|
|
45
|
+
l2Address,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function walletNameForChannelAndAddress(channelName, l1Address) {
|
|
50
|
+
return `${channelName}-${getAddress(l1Address)}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function parseWalletName(walletName) {
|
|
54
|
+
const match = /^(.*)-(0x[a-fA-F0-9]{40})$/.exec(String(walletName));
|
|
55
|
+
if (!match || match[1].length === 0) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
[
|
|
58
|
+
`Unable to derive the channel name from wallet ${walletName}.`,
|
|
59
|
+
"Expected the deterministic <channelName>-<l1Address> format.",
|
|
60
|
+
].join(" "),
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
channelName: match[1],
|
|
65
|
+
l1Address: getAddress(match[2]),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function workspaceNetworkDir(workspaceRoot, networkName) {
|
|
70
|
+
return path.join(workspaceRoot, slugifyPathComponent(networkName));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function workspaceDirForName(workspaceRoot, networkName, workspaceName) {
|
|
74
|
+
return path.join(
|
|
75
|
+
workspaceNetworkDir(workspaceRoot, networkName),
|
|
76
|
+
slugifyPathComponent(workspaceName),
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function workspaceChannelDir(workspaceDir) {
|
|
81
|
+
return path.join(workspaceDir, "channel");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function workspaceWalletsDir(workspaceDir) {
|
|
85
|
+
return path.join(workspaceDir, "wallets");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function walletDirForName(walletsRoot, walletName) {
|
|
89
|
+
return path.join(walletsRoot, slugifyPathComponent(walletName));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function walletMetadataPathForDir(walletDir) {
|
|
93
|
+
return path.join(walletDir, "wallet.metadata.json");
|
|
94
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tokamak-private-dapps/private-state-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Command-line client for the Tokamak private-state DApp.",
|
|
5
|
+
"license": "MIT OR Apache-2.0",
|
|
6
|
+
"author": "Tokamak Network",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/tokamak-network/Tokamak-zk-EVM-contracts.git",
|
|
10
|
+
"directory": "packages/apps/private-state/cli"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/tokamak-network/Tokamak-zk-EVM-contracts/tree/main/packages/apps/private-state/cli#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/tokamak-network/Tokamak-zk-EVM-contracts/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"tokamak",
|
|
18
|
+
"private-dapps",
|
|
19
|
+
"private-state",
|
|
20
|
+
"zk-evm",
|
|
21
|
+
"cli"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
24
|
+
"bin": {
|
|
25
|
+
"private-state-cli": "private-state-bridge-cli.mjs"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"README.md",
|
|
29
|
+
"CHANGELOG.md",
|
|
30
|
+
"LICENSE",
|
|
31
|
+
"private-state-bridge-cli.mjs",
|
|
32
|
+
"cli-assistant.html",
|
|
33
|
+
"lib"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"release:check": "node ../../../../scripts/release-readiness.cjs"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public",
|
|
40
|
+
"registry": "https://registry.npmjs.org/"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@ethereumjs/util": "^10.1.1",
|
|
44
|
+
"@noble/curves": "^1.2.0",
|
|
45
|
+
"@tokamak-private-dapps/common-library": "^0.1.0",
|
|
46
|
+
"@tokamak-private-dapps/groth16": "^0.1.0",
|
|
47
|
+
"@tokamak-zk-evm/cli": "^2.0.8",
|
|
48
|
+
"ethers": "^6.14.1",
|
|
49
|
+
"tokamak-l2js": "^0.1.3"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=18"
|
|
53
|
+
}
|
|
54
|
+
}
|