@miden-sdk/para 0.0.0-bootstrap → 0.16.0-rc.6

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.
@@ -0,0 +1,111 @@
1
+ import { hexToBytes, utf8ToBytes } from "@noble/hashes/utils.js";
2
+ const fromHexSig = (hexString) => {
3
+ if (hexString.length % 2 !== 0) {
4
+ throw new Error("Invalid string len");
5
+ }
6
+ const sigBytes = hexToBytes(hexString);
7
+ const serialized = new Uint8Array(sigBytes.length + 2);
8
+ serialized[0] = 1;
9
+ serialized.set(sigBytes, 1);
10
+ return serialized;
11
+ };
12
+ const accountSeedFromStr = (str) => {
13
+ if (!str) return;
14
+ const buffer = new Uint8Array(32);
15
+ const bytes = utf8ToBytes(str);
16
+ buffer.set(bytes.slice(0, 32));
17
+ return buffer;
18
+ };
19
+ const evmPkToCommitment = async (uncompressedPublicKey) => {
20
+ const { Felt, Poseidon2, FeltArray } = await import("@miden-sdk/miden-sdk");
21
+ const withoutPrefix = uncompressedPublicKey.slice(4);
22
+ const x = withoutPrefix.slice(0, 64);
23
+ const y = withoutPrefix.slice(64);
24
+ const felts = [...coordToLimbs(x), ...coordToLimbs(y)].map(
25
+ (limb) => new Felt(BigInt(limb))
26
+ );
27
+ return Poseidon2.hashElements(new FeltArray(felts));
28
+ };
29
+ const coordToLimbs = (hex) => {
30
+ const bytes = hexToBytes(hex);
31
+ if (bytes.length !== 32) {
32
+ throw new Error(`Expected a 32-byte coordinate, got ${bytes.length}`);
33
+ }
34
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
35
+ const limbs = [];
36
+ for (let i = 7; i >= 0; i--) {
37
+ limbs.push(view.getUint32(i * 4, false));
38
+ }
39
+ return limbs;
40
+ };
41
+ const getUncompressedPublicKeyFromWallet = async (para, wallet) => {
42
+ if (wallet.publicKey) {
43
+ return wallet.publicKey;
44
+ }
45
+ const { token } = await para.issueJwt();
46
+ const payload = JSON.parse(window.atob(token.split(".")[1]));
47
+ const wallets = payload.data?.connectedWallets;
48
+ if (!wallets) {
49
+ throw new Error("Got invalid jwt token");
50
+ }
51
+ const w = wallets.find((connected) => connected.id === wallet.id);
52
+ if (!w) {
53
+ throw new Error("Wallet Not Found in jwt data");
54
+ }
55
+ if (!w.publicKey) {
56
+ throw new Error("Wallet in jwt data has no public key");
57
+ }
58
+ return w.publicKey;
59
+ };
60
+ const txSummaryToJson = (txSummary) => {
61
+ const inputNotes = txSummary.inputNotes().notes().map((inputNote) => ({
62
+ id: inputNote.id().toString(),
63
+ assets: inputNote.note().assets().fungibleAssets().map((asset) => {
64
+ return {
65
+ assetId: asset.faucetId().toString(),
66
+ amount: asset.amount().toString()
67
+ };
68
+ }),
69
+ sender: inputNote.note().metadata().sender().toString()
70
+ }));
71
+ const outputNotes = txSummary.outputNotes().notes().map((outputNote) => {
72
+ const assets = outputNote.assets();
73
+ if (!assets) {
74
+ throw new Error(
75
+ `Output note ${outputNote.id().toString()} carries no asset data; refusing to summarize a transaction whose assets are unknown`
76
+ );
77
+ }
78
+ return {
79
+ id: outputNote.id().toString(),
80
+ assets: assets.fungibleAssets().map((asset) => {
81
+ return {
82
+ assetId: asset.faucetId().toString(),
83
+ amount: asset.amount().toString()
84
+ };
85
+ }),
86
+ noteType: noteTypeToString(outputNote.metadata().noteType())
87
+ };
88
+ });
89
+ return {
90
+ inputNotes,
91
+ outputNotes
92
+ };
93
+ };
94
+ function noteTypeToString(noteType) {
95
+ switch (noteType) {
96
+ case 1:
97
+ return "public";
98
+ case 0:
99
+ return "private";
100
+ default:
101
+ return "UNKNOWN";
102
+ }
103
+ }
104
+ export {
105
+ accountSeedFromStr,
106
+ evmPkToCommitment,
107
+ fromHexSig,
108
+ getUncompressedPublicKeyFromWallet,
109
+ hexToBytes,
110
+ txSummaryToJson
111
+ };
package/package.json CHANGED
@@ -1,18 +1,76 @@
1
1
  {
2
2
  "name": "@miden-sdk/para",
3
- "version": "0.0.0-bootstrap",
4
- "description": "Reserved name. Placeholder published only to allow an npm trusted publisher to be attached; do not install.",
3
+ "version": "0.16.0-rc.6",
4
+ "type": "commonjs",
5
+ "description": "Miden x Para Integration",
5
6
  "license": "MIT",
6
7
  "author": "Miden Contributors",
7
8
  "repository": {
8
9
  "type": "git",
9
- "url": "git+https://github.com/0xMiden/web-sdk.git"
10
+ "url": "git+https://github.com/0xMiden/web-sdk.git",
11
+ "directory": "packages/para/core"
10
12
  },
13
+ "homepage": "https://github.com/0xMiden/web-sdk",
14
+ "readmeFilename": "README.md",
11
15
  "bugs": {
12
16
  "url": "https://github.com/0xMiden/web-sdk/issues"
13
17
  },
14
- "homepage": "https://github.com/0xMiden/web-sdk",
18
+ "dependencies": {
19
+ "@noble/hashes": "^2.0.1"
20
+ },
21
+ "devDependencies": {
22
+ "@getpara/web-sdk": "^2.11.0",
23
+ "@types/react": "^19.0.0",
24
+ "esbuild": "^0.24.0",
25
+ "eslint": "^9.39.1",
26
+ "glob": "^11.0.1",
27
+ "prettier": "^3.7.3",
28
+ "puppeteer": "^24.4.0",
29
+ "react": "^19.2.0",
30
+ "react-test-renderer": "^19.2.0",
31
+ "typescript": "^5.8.3",
32
+ "@miden-sdk/miden-sdk": "0.16.0-rc.6"
33
+ },
34
+ "peerDependencies": {
35
+ "@getpara/web-sdk": "^2.11.0",
36
+ "@miden-sdk/miden-sdk": "^0.16.0-rc.6"
37
+ },
38
+ "exports": {
39
+ ".": {
40
+ "import": {
41
+ "types": "./dist/esm/index.d.ts",
42
+ "default": "./dist/esm/index.js"
43
+ },
44
+ "require": {
45
+ "types": "./dist/cjs/index.d.ts",
46
+ "default": "./dist/cjs/index.js"
47
+ }
48
+ }
49
+ },
15
50
  "files": [
16
- "README.md"
17
- ]
18
- }
51
+ "dist",
52
+ "package.json",
53
+ "docs/INTEGRATIONS.md"
54
+ ],
55
+ "main": "dist/cjs/index.js",
56
+ "module": "dist/esm/index.js",
57
+ "sideEffects": false,
58
+ "types": "dist/cjs/index.d.ts",
59
+ "typings": "dist/cjs/index.d.ts",
60
+ "keywords": [
61
+ "miden",
62
+ "para",
63
+ "zk",
64
+ "wallet"
65
+ ],
66
+ "publishConfig": {
67
+ "access": "public"
68
+ },
69
+ "scripts": {
70
+ "test": "node --test",
71
+ "build": "rm -rf dist && node ./scripts/build.mjs && npm run build:types",
72
+ "build:types": "tsc --module es2020 --declarationDir dist/esm --emitDeclarationOnly --declaration && tsc --module commonjs --declarationDir dist/cjs --emitDeclarationOnly --declaration",
73
+ "format": "pnpm exec prettier \"**/*.{js,jsx,ts,tsx}\" --write && pnpm exec eslint . --fix",
74
+ "format-check": "pnpm exec prettier \"**/*.{js,jsx,ts,tsx}\" && pnpm exec eslint"
75
+ }
76
+ }