From 26c1f35918b4b5040d3a8ff5f764686bfc0fa8bd Mon Sep 17 00:00:00 2001 From: Swen Date: Sat, 14 Jan 2023 12:38:36 +0000 Subject: [PATCH 1/3] test: husky auto-fmt hook precommit --- light-sdk-ts/.prettierrc | 5 +++++ light-sdk-ts/husky/pre-commit | 6 ++++++ light-sdk-ts/package-lock.json | 22 ++++++++++++++++++++++ light-sdk-ts/package.json | 9 ++++++++- 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 light-sdk-ts/.prettierrc create mode 100644 light-sdk-ts/husky/pre-commit diff --git a/light-sdk-ts/.prettierrc b/light-sdk-ts/.prettierrc new file mode 100644 index 0000000000..36e5a584cc --- /dev/null +++ b/light-sdk-ts/.prettierrc @@ -0,0 +1,5 @@ +{ + "trailingComma": "all", + "tabWidth": 2, + "singleQuote": false +} diff --git a/light-sdk-ts/husky/pre-commit b/light-sdk-ts/husky/pre-commit new file mode 100644 index 0000000000..76c30c9531 --- /dev/null +++ b/light-sdk-ts/husky/pre-commit @@ -0,0 +1,6 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" +cd light-sdk-ts +npx format-staged +exit 1 # Commit will be aborted + diff --git a/light-sdk-ts/package-lock.json b/light-sdk-ts/package-lock.json index d7e9037fde..0cb99e131e 100644 --- a/light-sdk-ts/package-lock.json +++ b/light-sdk-ts/package-lock.json @@ -27,6 +27,7 @@ "@types/mocha": "^9.0.0", "@types/node-fetch": "^2.6.2", "chai": "^4.3.4", + "husky": "^8.0.3", "lodash": "^4.17.21", "mocha": "^10.2.0", "prettier": "^2.6.2", @@ -1997,6 +1998,21 @@ "ms": "^2.0.0" } }, + "node_modules/husky": { + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/husky/-/husky-8.0.3.tgz", + "integrity": "sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg==", + "dev": true, + "bin": { + "husky": "lib/bin.js" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/typicode" + } + }, "node_modules/ieee754": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", @@ -4589,6 +4605,12 @@ "ms": "^2.0.0" } }, + "husky": { + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/husky/-/husky-8.0.3.tgz", + "integrity": "sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg==", + "dev": true + }, "ieee754": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", diff --git a/light-sdk-ts/package.json b/light-sdk-ts/package.json index f79cbc6468..ad930e341f 100644 --- a/light-sdk-ts/package.json +++ b/light-sdk-ts/package.json @@ -8,7 +8,13 @@ "build": "tsc", "format": "prettier --write \"src/**/*.{ts,js}\"", "lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w", - "lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check" + "lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check", + "prepare": "cd .. && husky install ./light-sdk-ts/husky" + }, + "format-staged": { + "**/*.{js,jsx}": [ + "prettier --write" + ] }, "keywords": [ "sdk", @@ -36,6 +42,7 @@ "@types/mocha": "^9.0.0", "@types/node-fetch": "^2.6.2", "chai": "^4.3.4", + "husky": "^8.0.3", "lodash": "^4.17.21", "mocha": "^10.2.0", "prettier": "^2.6.2", From a35fc44a2e9dea4afa14e1aaaea9b8f03e3e5e43 Mon Sep 17 00:00:00 2001 From: Swen Date: Sat, 14 Jan 2023 12:44:58 +0000 Subject: [PATCH 2/3] test husky config --- light-sdk-ts/husky/pre-commit | 2 +- light-sdk-ts/src/constants.ts | 34 +- light-sdk-ts/src/idls/merkle_tree_program.ts | 96 ++--- light-sdk-ts/src/idls/verifier_program_one.ts | 16 +- light-sdk-ts/src/idls/verifier_program_two.ts | 6 +- .../src/idls/verifier_program_zero.ts | 10 +- light-sdk-ts/src/keypair.ts | 10 +- light-sdk-ts/src/merkleTree/merkleTree.ts | 8 +- .../src/merkleTree/merkleTreeConfig.ts | 80 ++-- .../src/merkleTree/merkleTreeUpdater.ts | 12 +- light-sdk-ts/src/merkleTree/solMerkleTree.ts | 86 +++-- light-sdk-ts/src/relayer.ts | 2 +- .../src/test-utils/constants_market_place.ts | 10 +- .../test-utils/constants_system_verifier.ts | 14 +- light-sdk-ts/src/test-utils/createAccounts.ts | 34 +- .../src/test-utils/initLookUpTable.ts | 22 +- .../src/test-utils/setUpMerkleTree.ts | 6 +- light-sdk-ts/src/test-utils/testChecks.ts | 50 +-- .../src/test-utils/testTransactions.ts | 76 ++-- light-sdk-ts/src/transaction.ts | 342 +++++++++--------- light-sdk-ts/src/utils.ts | 4 +- light-sdk-ts/src/utxo.ts | 14 +- light-sdk-ts/src/verifiers/index.ts | 2 +- light-sdk-ts/src/verifiers/verifierOne.ts | 17 +- light-sdk-ts/src/verifiers/verifierTwo.ts | 6 +- light-sdk-ts/src/verifiers/verifierZero.ts | 12 +- light-sdk-ts/src/wallet/buildBalance.ts | 11 +- light-sdk-ts/src/wallet/user.ts | 3 +- 28 files changed, 505 insertions(+), 480 deletions(-) mode change 100644 => 100755 light-sdk-ts/husky/pre-commit diff --git a/light-sdk-ts/husky/pre-commit b/light-sdk-ts/husky/pre-commit old mode 100644 new mode 100755 index 76c30c9531..18ca502898 --- a/light-sdk-ts/husky/pre-commit +++ b/light-sdk-ts/husky/pre-commit @@ -1,6 +1,6 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" cd light-sdk-ts -npx format-staged +npm run format exit 1 # Commit will be aborted diff --git a/light-sdk-ts/src/constants.ts b/light-sdk-ts/src/constants.ts index 964d17485f..d78b18f218 100644 --- a/light-sdk-ts/src/constants.ts +++ b/light-sdk-ts/src/constants.ts @@ -27,7 +27,7 @@ export const CONSTANT_SECRET_AUTHKEY: Uint8Array = Uint8Array.from([ ]); export const FIELD_SIZE = new anchor.BN( - "21888242871839275222246405745257275088548364400416034343698204186575808495617" + "21888242871839275222246405745257275088548364400416034343698204186575808495617", ); export const MERKLE_TREE_SIGNER_AUTHORITY = new PublicKey([ 59, 42, 227, 2, 155, 13, 249, 77, 6, 97, 72, 159, 190, 119, 46, 110, 226, 42, @@ -38,16 +38,16 @@ export const TYPE_SEED = { defined: "&[u8]" }; export const TYPE_INIT_DATA = { array: ["u8", 642] }; export const merkleTreeProgramId = new PublicKey( - "JA5cjkRJ1euVi9xLWsCJVzsRzEkT8vcC4rqw9sVAo5d6" + "JA5cjkRJ1euVi9xLWsCJVzsRzEkT8vcC4rqw9sVAo5d6", ); export const verifierProgramZeroProgramId = new PublicKey( - "J1RRetZ4ujphU75LP8RadjXMf3sA12yC2R44CF7PmU7i" + "J1RRetZ4ujphU75LP8RadjXMf3sA12yC2R44CF7PmU7i", ); export const verifierProgramOneProgramId = new PublicKey( - "3KS2k14CmtnuVv2fvYcvdrNgC94Y11WETBpMUGgXyWZL" + "3KS2k14CmtnuVv2fvYcvdrNgC94Y11WETBpMUGgXyWZL", ); export const verifierProgramTwoProgramId = new PublicKey( - "GFDwN8PXuKZG2d2JLxRhbggXYe9eQHoGYoYK5K3G5tV8" + "GFDwN8PXuKZG2d2JLxRhbggXYe9eQHoGYoYK5K3G5tV8", ); export type merkleTreeProgram = Program; @@ -85,41 +85,41 @@ export const DEFAULT_PROGRAMS = { // TODO: make account object with important accounts export const MERKLE_TREE_KEY = new PublicKey( - "DCxUdYgqjE6AR9m13VvqpkxJqGJYnk8jn8NEeD3QY3BU" + "DCxUdYgqjE6AR9m13VvqpkxJqGJYnk8jn8NEeD3QY3BU", ); export const REGISTERED_VERIFIER_PDA = new PublicKey( - "Eo3jtUstuMCvapqXdWiYvoUJS1PJDtKVf6LdsMPdyoNn" + "Eo3jtUstuMCvapqXdWiYvoUJS1PJDtKVf6LdsMPdyoNn", ); export const REGISTERED_VERIFIER_ONE_PDA = new PublicKey( - "CqUS5VyuGscwLMTbfUSAA1grmJYzDAkSR39zpbwW2oV5" + "CqUS5VyuGscwLMTbfUSAA1grmJYzDAkSR39zpbwW2oV5", ); export const REGISTERED_VERIFIER_TWO_PDA = new PublicKey( - "7RCgKAJkaR4Qsgve8D7Q3MrVt8nVY5wdKsmTYVswtJWn" + "7RCgKAJkaR4Qsgve8D7Q3MrVt8nVY5wdKsmTYVswtJWn", ); export const AUTHORITY = new PublicKey( - "KitaXMAzb8GPZcc6NW6mE7P6gV2fY3Bp8NqZWfeUwqM" + "KitaXMAzb8GPZcc6NW6mE7P6gV2fY3Bp8NqZWfeUwqM", ); export const AUTHORITY_ONE = new PublicKey( - "EjGpk73m5KxndbUVXcoT3UQsPLp5eK4h1H8kXVHEbf3f" + "EjGpk73m5KxndbUVXcoT3UQsPLp5eK4h1H8kXVHEbf3f", ); export const PRE_INSERTED_LEAVES_INDEX = new PublicKey( - "2MQ7XkirVZZhRQQKcaDiJsrXHCuRHjbu72sUEeW4eZjq" + "2MQ7XkirVZZhRQQKcaDiJsrXHCuRHjbu72sUEeW4eZjq", ); export const TOKEN_AUTHORITY = new PublicKey( - "GUqBxNbKyB9SBnbBKYR5dajwuWTjTRUhWrZgeFkJND55" + "GUqBxNbKyB9SBnbBKYR5dajwuWTjTRUhWrZgeFkJND55", ); export const REGISTERED_POOL_PDA_SPL = new PublicKey( - "2q4tXrgpsDffibmjfTGHU1gWCjYUfhwFnMyLX6dAhhr4" + "2q4tXrgpsDffibmjfTGHU1gWCjYUfhwFnMyLX6dAhhr4", ); export const REGISTERED_POOL_PDA_SPL_TOKEN = new PublicKey( - "2mobV36eNyFGaMTKCHW1Jeoq64tUGuXqA4zGtY8SbxKh" + "2mobV36eNyFGaMTKCHW1Jeoq64tUGuXqA4zGtY8SbxKh", ); export const REGISTERED_POOL_PDA_SOL = new PublicKey( - "Eti4Rjkx7ow88XkaFbxRStmwadTp8p9J2nSv7NhtuqDU" + "Eti4Rjkx7ow88XkaFbxRStmwadTp8p9J2nSv7NhtuqDU", ); export const POOL_TYPE = new Uint8Array(32).fill(0); export const MERKLE_TREE_AUTHORITY_PDA = new PublicKey( - "5EMc8sCbHeb1HtRFifcbCiXN66kX6Wddrd61EkdJun6Y" + "5EMc8sCbHeb1HtRFifcbCiXN66kX6Wddrd61EkdJun6Y", ); export const FEE_ASSET = anchor.web3.SystemProgram.programId; diff --git a/light-sdk-ts/src/idls/merkle_tree_program.ts b/light-sdk-ts/src/idls/merkle_tree_program.ts index fd472e929b..e4df1d1a2b 100644 --- a/light-sdk-ts/src/idls/merkle_tree_program.ts +++ b/light-sdk-ts/src/idls/merkle_tree_program.ts @@ -40,7 +40,7 @@ export type MerkleTreeProgramIdl = { { array: ["u8", 32]; }, - 19 + 19, ]; }; value: "[[40 , 66 , 58 , 227 , 48 , 224 , 249 , 227 , 188 , 18 , 133 , 168 , 156 , 214 , 220 , 144 , 244 , 144 , 67 , 82 , 76 , 6 , 135 , 78 , 64 , 186 , 52 , 113 , 234 , 47 , 27 , 32 ,] , [227 , 42 , 164 , 149 , 188 , 70 , 170 , 8 , 197 , 44 , 134 , 162 , 211 , 186 , 50 , 238 , 97 , 71 , 25 , 130 , 77 , 70 , 37 , 128 , 172 , 154 , 54 , 111 , 93 , 193 , 105 , 27 ,] , [25 , 241 , 255 , 33 , 65 , 214 , 48 , 229 , 38 , 116 , 134 , 103 , 44 , 146 , 163 , 214 , 31 , 238 , 148 , 206 , 34 , 137 , 144 , 221 , 184 , 11 , 5 , 213 , 10 , 188 , 143 , 18 ,] , [211 , 61 , 251 , 33 , 128 , 34 , 4 , 100 , 229 , 47 , 99 , 121 , 109 , 204 , 224 , 90 , 200 , 149 , 219 , 20 , 48 , 206 , 210 , 177 , 161 , 66 , 44 , 10 , 169 , 56 , 248 , 8 ,] , [200 , 15 , 65 , 80 , 151 , 74 , 72 , 69 , 229 , 131 , 25 , 215 , 86 , 36 , 195 , 74 , 67 , 59 , 117 , 179 , 51 , 60 , 181 , 13 , 242 , 192 , 228 , 228 , 189 , 238 , 70 , 8 ,] , [171 , 62 , 122 , 81 , 181 , 197 , 22 , 238 , 224 , 40 , 154 , 231 , 127 , 202 , 201 , 169 , 196 , 109 , 244 , 175 , 117 , 101 , 23 , 67 , 103 , 57 , 127 , 200 , 37 , 43 , 111 , 7 ,] , [59 , 78 , 126 , 104 , 199 , 143 , 213 , 10 , 2 , 158 , 64 , 78 , 153 , 25 , 107 , 190 , 32 , 122 , 123 , 211 , 116 , 179 , 175 , 172 , 70 , 54 , 175 , 59 , 201 , 120 , 64 , 44 ,] , [110 , 91 , 92 , 81 , 205 , 89 , 122 , 223 , 55 , 163 , 42 , 227 , 109 , 54 , 38 , 22 , 110 , 217 , 29 , 148 , 107 , 99 , 128 , 106 , 146 , 47 , 239 , 41 , 55 , 157 , 155 , 22 ,] , [18 , 231 , 42 , 5 , 245 , 159 , 211 , 227 , 239 , 89 , 35 , 142 , 223 , 69 , 166 , 224 , 14 , 114 , 128 , 14 , 123 , 123 , 215 , 2 , 241 , 185 , 191 , 60 , 252 , 61 , 146 , 12 ,] , [231 , 0 , 84 , 227 , 127 , 64 , 158 , 7 , 171 , 179 , 137 , 231 , 92 , 87 , 25 , 221 , 156 , 229 , 53 , 208 , 194 , 201 , 12 , 165 , 105 , 150 , 41 , 142 , 29 , 205 , 136 , 29 ,] , [195 , 2 , 103 , 231 , 62 , 207 , 214 , 105 , 214 , 210 , 108 , 23 , 28 , 151 , 77 , 100 , 78 , 194 , 210 , 29 , 227 , 14 , 17 , 242 , 211 , 50 , 33 , 194 , 106 , 18 , 246 , 45 ,] , [131 , 178 , 24 , 157 , 251 , 247 , 103 , 69 , 101 , 229 , 194 , 14 , 167 , 57 , 158 , 128 , 212 , 19 , 140 , 234 , 69 , 37 , 10 , 156 , 249 , 96 , 152 , 52 , 97 , 96 , 119 , 41 ,] , [30 , 223 , 20 , 181 , 108 , 110 , 112 , 102 , 234 , 54 , 99 , 29 , 213 , 3 , 55 , 225 , 125 , 185 , 223 , 234 , 188 , 108 , 83 , 89 , 27 , 3 , 100 , 6 , 65 , 107 , 3 , 24 ,] , [167 , 32 , 85 , 233 , 205 , 253 , 154 , 214 , 236 , 82 , 147 , 75 , 252 , 144 , 109 , 73 , 63 , 167 , 77 , 233 , 12 , 201 , 150 , 242 , 103 , 15 , 158 , 83 , 137 , 24 , 170 , 16 ,] , [45 , 98 , 238 , 69 , 136 , 141 , 101 , 226 , 94 , 209 , 58 , 215 , 212 , 14 , 210 , 135 , 110 , 96 , 52 , 16 , 101 , 177 , 121 , 109 , 134 , 81 , 189 , 146 , 113 , 243 , 97 , 42 ,] , [71 , 51 , 251 , 48 , 95 , 193 , 94 , 26 , 180 , 17 , 124 , 203 , 48 , 98 , 55 , 17 , 60 , 104 , 186 , 175 , 213 , 189 , 7 , 239 , 92 , 175 , 16 , 5 , 220 , 168 , 70 , 21 ,] , [35 , 92 , 72 , 197 , 23 , 142 , 16 , 200 , 136 , 38 , 44 , 255 , 162 , 115 , 11 , 1 , 248 , 182 , 236 , 78 , 90 , 24 , 128 , 245 , 168 , 17 , 130 , 2 , 73 , 51 , 196 , 6 ,] , [89 , 178 , 154 , 246 , 236 , 130 , 30 , 100 , 27 , 230 , 24 , 196 , 8 , 172 , 176 , 196 , 197 , 13 , 157 , 194 , 169 , 106 , 207 , 70 , 66 , 117 , 69 , 53 , 56 , 154 , 78 , 0 ,] , [231 , 174 , 226 , 37 , 211 , 160 , 187 , 178 , 149 , 82 , 17 , 60 , 110 , 116 , 28 , 61 , 58 , 145 , 58 , 71 , 25 , 42 , 67 , 46 , 189 , 214 , 248 , 234 , 182 , 251 , 238 , 34 ,] ,]"; @@ -121,7 +121,7 @@ export type MerkleTreeProgramIdl = { defined: "&[u8]"; }; value: 'b"spl"'; - } + }, ]; instructions: [ { @@ -156,13 +156,13 @@ export type MerkleTreeProgramIdl = { name: "merkleTreeAuthorityPda"; isMut: true; isSigner: false; - } + }, ]; args: [ { name: "lockDuration"; type: "u64"; - } + }, ]; }, { @@ -187,7 +187,7 @@ export type MerkleTreeProgramIdl = { name: "rent"; isMut: false; isSigner: false; - } + }, ]; args: []; }, @@ -208,7 +208,7 @@ export type MerkleTreeProgramIdl = { name: "newAuthority"; isMut: false; isSigner: false; - } + }, ]; args: []; }, @@ -229,13 +229,13 @@ export type MerkleTreeProgramIdl = { name: "merkleTree"; isMut: true; isSigner: false; - } + }, ]; args: [ { name: "lockDuration"; type: "u64"; - } + }, ]; }, { @@ -250,13 +250,13 @@ export type MerkleTreeProgramIdl = { name: "authority"; isMut: false; isSigner: true; - } + }, ]; args: [ { name: "enablePermissionless"; type: "bool"; - } + }, ]; }, { @@ -271,13 +271,13 @@ export type MerkleTreeProgramIdl = { name: "authority"; isMut: false; isSigner: true; - } + }, ]; args: [ { name: "enablePermissionless"; type: "bool"; - } + }, ]; }, { @@ -307,13 +307,13 @@ export type MerkleTreeProgramIdl = { name: "rent"; isMut: false; isSigner: false; - } + }, ]; args: [ { name: "verifierPubkey"; type: "publicKey"; - } + }, ]; }, { @@ -343,7 +343,7 @@ export type MerkleTreeProgramIdl = { name: "merkleTreeAuthorityPda"; isMut: false; isSigner: false; - } + }, ]; args: [ { @@ -351,7 +351,7 @@ export type MerkleTreeProgramIdl = { type: { array: ["u8", 32]; }; - } + }, ]; }, { @@ -406,7 +406,7 @@ export type MerkleTreeProgramIdl = { name: "merkleTreeAuthorityPda"; isMut: true; isSigner: false; - } + }, ]; args: []; }, @@ -442,7 +442,7 @@ export type MerkleTreeProgramIdl = { name: "merkleTreeAuthorityPda"; isMut: true; isSigner: false; - } + }, ]; args: []; }, @@ -473,7 +473,7 @@ export type MerkleTreeProgramIdl = { name: "rent"; isMut: false; isSigner: false; - } + }, ]; args: []; }, @@ -494,13 +494,13 @@ export type MerkleTreeProgramIdl = { name: "merkleTree"; isMut: true; isSigner: false; - } + }, ]; args: [ { name: "bump"; type: "u64"; - } + }, ]; }, { @@ -520,13 +520,13 @@ export type MerkleTreeProgramIdl = { name: "merkleTree"; isMut: true; isSigner: false; - } + }, ]; args: [ { name: "bump"; type: "u64"; - } + }, ]; }, { @@ -541,7 +541,7 @@ export type MerkleTreeProgramIdl = { name: "merkleTreeUpdateState"; isMut: true; isSigner: false; - } + }, ]; args: []; }, @@ -572,7 +572,7 @@ export type MerkleTreeProgramIdl = { name: "registeredVerifierPda"; isMut: false; isSigner: false; - } + }, ]; args: [ { @@ -596,7 +596,7 @@ export type MerkleTreeProgramIdl = { { name: "merkleTreePdaPubkey"; type: "publicKey"; - } + }, ]; }, { @@ -621,13 +621,13 @@ export type MerkleTreeProgramIdl = { name: "recipient"; isMut: true; isSigner: false; - } + }, ]; args: [ { name: "amount"; type: "u64"; - } + }, ]; }, { @@ -662,13 +662,13 @@ export type MerkleTreeProgramIdl = { name: "registeredVerifierPda"; isMut: false; isSigner: false; - } + }, ]; args: [ { name: "amount"; type: "u64"; - } + }, ]; }, { @@ -688,7 +688,7 @@ export type MerkleTreeProgramIdl = { name: "registeredVerifierPda"; isMut: false; isSigner: false; - } + }, ]; args: [ { @@ -696,9 +696,9 @@ export type MerkleTreeProgramIdl = { type: { vec: "bytes"; }; - } + }, ]; - } + }, ]; accounts: [ { @@ -719,7 +719,7 @@ export type MerkleTreeProgramIdl = { { name: "index"; type: "u64"; - } + }, ]; }; }, @@ -733,7 +733,7 @@ export type MerkleTreeProgramIdl = { type: { array: ["u8", 32]; }; - } + }, ]; }; }, @@ -765,7 +765,7 @@ export type MerkleTreeProgramIdl = { { name: "enablePermissionlessMerkleTreeRegistration"; type: "bool"; - } + }, ]; }; }, @@ -777,7 +777,7 @@ export type MerkleTreeProgramIdl = { { name: "pubkey"; type: "publicKey"; - } + }, ]; }; }, @@ -796,7 +796,7 @@ export type MerkleTreeProgramIdl = { { name: "nextIndex"; type: "u64"; - } + }, ]; }; }, @@ -812,7 +812,7 @@ export type MerkleTreeProgramIdl = { { array: ["u8", 32]; }, - 18 + 18, ]; }; }, @@ -831,7 +831,7 @@ export type MerkleTreeProgramIdl = { { array: ["u8", 32]; }, - 256 + 256, ]; }; }, @@ -854,7 +854,7 @@ export type MerkleTreeProgramIdl = { { name: "lockDuration"; type: "u64"; - } + }, ]; }; }, @@ -888,7 +888,7 @@ export type MerkleTreeProgramIdl = { { name: "leftLeafIndex"; type: "u64"; - } + }, ]; }; }, @@ -972,7 +972,7 @@ export type MerkleTreeProgramIdl = { { array: ["u8", 32]; }, - 18 + 18, ]; }; }, @@ -985,10 +985,10 @@ export type MerkleTreeProgramIdl = { { array: ["u8", 32]; }, - 2 + 2, ]; }, - 16 + 16, ]; }; }, @@ -999,10 +999,10 @@ export type MerkleTreeProgramIdl = { { name: "insertLeavesIndex"; type: "u8"; - } + }, ]; }; - } + }, ]; errors: [ { @@ -1094,7 +1094,7 @@ export type MerkleTreeProgramIdl = { code: 6017; name: "InvalidVerifier"; msg: "InvalidVerifier"; - } + }, ]; }; export const MerkleTreeProgram: MerkleTreeProgramIdl = { diff --git a/light-sdk-ts/src/idls/verifier_program_one.ts b/light-sdk-ts/src/idls/verifier_program_one.ts index 16b4341d6e..14ccf18175 100644 --- a/light-sdk-ts/src/idls/verifier_program_one.ts +++ b/light-sdk-ts/src/idls/verifier_program_one.ts @@ -196,7 +196,7 @@ export type VerifierProgramOneIdl = { name: "verifierState"; isMut: true; isSigner: false; - } + }, ]; args: [ { @@ -210,7 +210,7 @@ export type VerifierProgramOneIdl = { { array: ["u8", 32]; }, - 10 + 10, ]; }; }, @@ -221,7 +221,7 @@ export type VerifierProgramOneIdl = { { array: ["u8", 32]; }, - 2 + 2, ]; }; }, @@ -240,7 +240,7 @@ export type VerifierProgramOneIdl = { { name: "encryptedUtxos"; type: "bytes"; - } + }, ]; }, { @@ -325,13 +325,13 @@ export type VerifierProgramOneIdl = { name: "registeredVerifierPda"; isMut: true; isSigner: false; - } + }, ]; args: [ { name: "proof"; type: "bytes"; - } + }, ]; }, { @@ -346,10 +346,10 @@ export type VerifierProgramOneIdl = { name: "verifierState"; isMut: true; isSigner: false; - } + }, ]; args: []; - } + }, ]; }; export default VerifierProgramOne; diff --git a/light-sdk-ts/src/idls/verifier_program_two.ts b/light-sdk-ts/src/idls/verifier_program_two.ts index 3a8b954439..e60664bcd0 100644 --- a/light-sdk-ts/src/idls/verifier_program_two.ts +++ b/light-sdk-ts/src/idls/verifier_program_two.ts @@ -89,7 +89,7 @@ export type VerifierProgramTwoIdl = { name: "invokingVerifier"; isMut: false; isSigner: false; - } + }, ]; args: [ { @@ -99,9 +99,9 @@ export type VerifierProgramTwoIdl = { { name: "appHash"; type: "bytes"; - } + }, ]; - } + }, ]; }; export const VerifierProgramTwo: VerifierProgramTwoIdl = { diff --git a/light-sdk-ts/src/idls/verifier_program_zero.ts b/light-sdk-ts/src/idls/verifier_program_zero.ts index e001a82cb2..72e828baf9 100644 --- a/light-sdk-ts/src/idls/verifier_program_zero.ts +++ b/light-sdk-ts/src/idls/verifier_program_zero.ts @@ -213,7 +213,7 @@ export type VerifierProgramZeroIdl = { name: "registeredVerifierPda"; isMut: true; isSigner: false; - } + }, ]; args: [ { @@ -231,7 +231,7 @@ export type VerifierProgramZeroIdl = { { array: ["u8", 32]; }, - 2 + 2, ]; }; }, @@ -242,7 +242,7 @@ export type VerifierProgramZeroIdl = { { array: ["u8", 32]; }, - 2 + 2, ]; }; }, @@ -261,9 +261,9 @@ export type VerifierProgramZeroIdl = { { name: "encryptedUtxos"; type: "bytes"; - } + }, ]; - } + }, ]; }; export default VerifierProgramZero; diff --git a/light-sdk-ts/src/keypair.ts b/light-sdk-ts/src/keypair.ts index bb467866bf..fdc1b0c3da 100644 --- a/light-sdk-ts/src/keypair.ts +++ b/light-sdk-ts/src/keypair.ts @@ -47,14 +47,14 @@ export class Keypair { this.encPrivateKey = Keypair.getEncryptionKeyPair(seed).secretKey; this.pubkey = Keypair.generateShieldedPublicKey( this.privkey, - this.poseidon + this.poseidon, ); } else if (privateKey) { this.privkey = privateKey; this.encryptionPublicKey = new Uint8Array(); this.pubkey = Keypair.generateShieldedPublicKey( this.privkey, - this.poseidon + this.poseidon, ); } else if (publicKey) { this.pubkey = publicKey; @@ -66,7 +66,7 @@ export class Keypair { this.encPrivateKey = Keypair.getEncryptionKeyPair(seed).secretKey; this.pubkey = Keypair.generateShieldedPublicKey( this.privkey, - this.poseidon + this.poseidon, ); } } @@ -88,7 +88,7 @@ export class Keypair { this.privkey.toString(), commitment.toString(), merklePath, - ]) + ]), ); } @@ -129,7 +129,7 @@ export class Keypair { static generateShieldedPrivateKey(seed: String): BN { const privkeySeed = seed + "shielded"; const privateKey = new BN( - blake2b.create(b2params).update(privkeySeed).digest() + blake2b.create(b2params).update(privkeySeed).digest(), ); return privateKey; } diff --git a/light-sdk-ts/src/merkleTree/merkleTree.ts b/light-sdk-ts/src/merkleTree/merkleTree.ts index 6cdeb23a25..d4470f4d44 100644 --- a/light-sdk-ts/src/merkleTree/merkleTree.ts +++ b/light-sdk-ts/src/merkleTree/merkleTree.ts @@ -28,7 +28,7 @@ export class MerkleTree { levels: number, poseidonHash2: any, elements: any[] = [], - { zeroElement = DEFAULT_ZERO } = {} + { zeroElement = DEFAULT_ZERO } = {}, ) { this.levels = levels; this.capacity = 2 ** levels; @@ -44,7 +44,7 @@ export class MerkleTree { for (let i = 1; i <= levels; i++) { this._zeros[i] = this._hash.F.toString( - this._hash([this._zeros[i - 1], this._zeros[i - 1]]) + this._hash([this._zeros[i - 1], this._zeros[i - 1]]), ); } this._rebuild(); @@ -60,7 +60,7 @@ export class MerkleTree { i * 2 + 1 < this._layers[level - 1].length ? this._layers[level - 1][i * 2 + 1] : this._zeros[level - 1], - ]) + ]), ); } } @@ -122,7 +122,7 @@ export class MerkleTree { this._layers[level - 1][index * 2], index * 2 + 1 < this._layers[level - 1].length ? this._layers[level - 1][index * 2 + 1] - : this._zeros[level - 1] + : this._zeros[level - 1], ); } } diff --git a/light-sdk-ts/src/merkleTree/merkleTreeConfig.ts b/light-sdk-ts/src/merkleTree/merkleTreeConfig.ts index 2c2fe5781c..bfd655c440 100644 --- a/light-sdk-ts/src/merkleTree/merkleTreeConfig.ts +++ b/light-sdk-ts/src/merkleTree/merkleTreeConfig.ts @@ -39,7 +39,7 @@ export class MerkleTreeConfig { this.payer = payer; this.merkleTreeProgram = new Program( MerkleTreeProgram, - merkleTreeProgramId + merkleTreeProgramId, ); // TODO: reorg pool pdas, have one object per pool type and then an array with registered pools of this type this.poolPdas = []; @@ -51,7 +51,7 @@ export class MerkleTreeConfig { async getPreInsertedLeavesIndex() { this.preInsertedLeavesIndex = PublicKey.findProgramAddressSync( [this.merkleTreePubkey.toBuffer()], - this.merkleTreeProgram.programId + this.merkleTreeProgram.programId, )[0]; return this.preInsertedLeavesIndex; } @@ -83,11 +83,11 @@ export class MerkleTreeConfig { async checkMerkleTreeIsInitialized() { var merkleTreeAccountInfo = await this.merkleTreeProgram.account.merkleTree.fetch( - this.merkleTreePubkey + this.merkleTreePubkey, ); assert( merkleTreeAccountInfo != null, - "merkleTreeAccountInfo not initialized" + "merkleTreeAccountInfo not initialized", ); // zero values // index == 0 @@ -99,12 +99,12 @@ export class MerkleTreeConfig { async checkPreInsertedLeavesIndexIsInitialized() { var preInsertedLeavesIndexAccountInfo = await this.merkleTreeProgram.account.preInsertedLeavesIndex.fetch( - this.preInsertedLeavesIndex + this.preInsertedLeavesIndex, ); assert( preInsertedLeavesIndexAccountInfo != null, - "preInsertedLeavesIndexAccountInfo not initialized" + "preInsertedLeavesIndexAccountInfo not initialized", ); assert(preInsertedLeavesIndexAccountInfo.nextIndex.toString() == "0"); } @@ -112,7 +112,7 @@ export class MerkleTreeConfig { async printMerkleTree() { var merkleTreeAccountInfo = await this.merkleTreeProgram.account.merkleTree.fetch( - this.merkleTreePubkey + this.merkleTreePubkey, ); console.log("merkleTreeAccountInfo ", merkleTreeAccountInfo); } @@ -120,7 +120,7 @@ export class MerkleTreeConfig { async getMerkleTreeAuthorityPda() { this.merkleTreeAuthorityPda = PublicKey.findProgramAddressSync( [anchor.utils.bytes.utf8.encode("MERKLE_TREE_AUTHORITY")], - this.merkleTreeProgram.programId + this.merkleTreeProgram.programId, )[0]; return this.merkleTreeAuthorityPda; } @@ -148,18 +148,18 @@ export class MerkleTreeConfig { assert( this.connection.getAccountInfo( this.merkleTreeAuthorityPda, - "confirmed" + "confirmed", ) != null, - "init authority failed" + "init authority failed", ); let merkleTreeAuthority = await this.merkleTreeProgram.account.merkleTreeAuthority.fetch( - this.merkleTreeAuthorityPda + this.merkleTreeAuthorityPda, ); assert(merkleTreeAuthority.enablePermissionlessSplTokens == false); assert(merkleTreeAuthority.enableNfts == false); assert( - merkleTreeAuthority.pubkey.toBase58() == authority.publicKey.toBase58() + merkleTreeAuthority.pubkey.toBase58() == authority.publicKey.toBase58(), ); assert(merkleTreeAuthority.registeredAssetIndex.toString() == "0"); @@ -174,7 +174,7 @@ export class MerkleTreeConfig { if (test != true) { merkleTreeAuthorityPrior = await this.merkleTreeProgram.account.merkleTreeAuthority.fetch( - this.merkleTreeAuthorityPda + this.merkleTreeAuthorityPda, ); if (merkleTreeAuthorityPrior == null) { throw `Merkle tree authority ${this.merkleTreeAuthorityPda.toBase58()} not initialized`; @@ -195,15 +195,15 @@ export class MerkleTreeConfig { if (test != true) { let merkleTreeAuthority = await this.merkleTreeProgram.account.merkleTreeAuthority.fetch( - this.merkleTreeAuthorityPda + this.merkleTreeAuthorityPda, ); assert( merkleTreeAuthority.enablePermissionlessSplTokens == - merkleTreeAuthorityPrior.enablePermissionlessSplTokens + merkleTreeAuthorityPrior.enablePermissionlessSplTokens, ); assert( - merkleTreeAuthority.enableNfts == merkleTreeAuthorityPrior.enableNfts + merkleTreeAuthority.enableNfts == merkleTreeAuthorityPrior.enableNfts, ); assert(merkleTreeAuthority.pubkey.toBase58() == newAuthority.toBase58()); } @@ -225,7 +225,7 @@ export class MerkleTreeConfig { .rpc(confirmConfig); let merkleTreeAuthority = await this.merkleTreeProgram.account.merkleTreeAuthority.fetch( - this.merkleTreeAuthorityPda + this.merkleTreeAuthorityPda, ); assert(merkleTreeAuthority.enableNfts == configValue); @@ -247,7 +247,7 @@ export class MerkleTreeConfig { .rpc(confirmConfig); let merkleTreeAuthority = await this.merkleTreeProgram.account.merkleTreeAuthority.fetch( - this.merkleTreeAuthorityPda + this.merkleTreeAuthorityPda, ); assert(merkleTreeAuthority.enablePermissionlessSplTokens == configValue); return tx; @@ -269,7 +269,7 @@ export class MerkleTreeConfig { .signers([this.payer]) .rpc(confirmConfig); let merkleTree = await this.merkleTreeProgram.account.merkleTree.fetch( - this.merkleTreePubkey + this.merkleTreePubkey, ); assert(merkleTree.lockDuration == lockDuration); console.log("lock duration updated to: ", lockDuration); @@ -282,7 +282,7 @@ export class MerkleTreeConfig { this.registeredVerifierPdas.push({ registeredVerifierPda: PublicKey.findProgramAddressSync( [verifierPubkey.toBuffer()], - this.merkleTreeProgram.programId + this.merkleTreeProgram.programId, )[0], verifierPubkey: verifierPubkey, }); @@ -296,7 +296,7 @@ export class MerkleTreeConfig { if (!registeredVerifierPda) { registeredVerifierPda = await this.getRegisteredVerifierPda( - verifierPubkey + verifierPubkey, ); } @@ -323,13 +323,13 @@ export class MerkleTreeConfig { var registeredVerifierAccountInfo = await this.merkleTreeProgram.account.registeredVerifier.fetch( - registeredVerifierPda.registeredVerifierPda + registeredVerifierPda.registeredVerifierPda, ); assert(registeredVerifierAccountInfo != null); assert( registeredVerifierAccountInfo.pubkey.toBase58() == - verifierPubkey.toBase58() + verifierPubkey.toBase58(), ); } @@ -342,7 +342,7 @@ export class MerkleTreeConfig { this.poolTypes.push({ poolPda: PublicKey.findProgramAddressSync( [poolType, anchor.utils.bytes.utf8.encode("pooltype")], - this.merkleTreeProgram.programId + this.merkleTreeProgram.programId, )[0], poolType: poolType, }); @@ -374,45 +374,45 @@ export class MerkleTreeConfig { async checkPoolRegistered(poolPda, poolType, mint: PublicKey | null = null) { var registeredTokenConfigAccount = await this.merkleTreeProgram.account.registeredAssetPool.fetch( - poolPda.pda + poolPda.pda, ); var merkleTreeAuthorityPdaAccountInfo = await this.merkleTreeProgram.account.merkleTreeAuthority.fetch( - this.merkleTreeAuthorityPda + this.merkleTreeAuthorityPda, ); assert( - registeredTokenConfigAccount.poolType.toString() == poolType.toString() + registeredTokenConfigAccount.poolType.toString() == poolType.toString(), ); assert( registeredTokenConfigAccount.index.toString() == - (merkleTreeAuthorityPdaAccountInfo.registeredAssetIndex - 1).toString() + (merkleTreeAuthorityPdaAccountInfo.registeredAssetIndex - 1).toString(), ); if (mint !== null) { assert( registeredTokenConfigAccount.assetPoolPubkey.toBase58() == - poolPda.token.toBase58() + poolPda.token.toBase58(), ); var registeredTokenAccount = await token.getAccount( this.connection, poolPda.token, - { commitment: "confirmed", preflightCommitment: "confirmed" } + { commitment: "confirmed", preflightCommitment: "confirmed" }, ); assert(registeredTokenAccount != null); assert(registeredTokenAccount.mint.toBase58() == mint.toBase58()); } else { assert( registeredTokenConfigAccount.assetPoolPubkey.toBase58() == - poolPda.pda.toBase58() + poolPda.pda.toBase58(), ); } } static getSolPoolPda( programId: PublicKey, - poolType: Uint8Array = new Uint8Array(32) + poolType: Uint8Array = new Uint8Array(32), ) { return { pda: PublicKey.findProgramAddressSync( @@ -421,7 +421,7 @@ export class MerkleTreeConfig { poolType, anchor.utils.bytes.utf8.encode("pool-config"), ], - programId + programId, )[0], poolType: poolType, }; @@ -437,7 +437,7 @@ export class MerkleTreeConfig { } let solPoolPda = MerkleTreeConfig.getSolPoolPda( this.merkleTreeProgram.programId, - poolType + poolType, ); const tx = await this.merkleTreeProgram.methods @@ -461,18 +461,18 @@ export class MerkleTreeConfig { static getSplPoolPdaToken( mint: PublicKey, programId: PublicKey, - poolType: Uint8Array = new Uint8Array(32).fill(0) + poolType: Uint8Array = new Uint8Array(32).fill(0), ) { let pda = PublicKey.findProgramAddressSync( [mint.toBytes(), poolType, anchor.utils.bytes.utf8.encode("pool")], - programId + programId, )[0]; return pda; } async getSplPoolPda( mint: PublicKey, - poolType: Uint8Array = new Uint8Array(32).fill(0) + poolType: Uint8Array = new Uint8Array(32).fill(0), ) { this.poolPdas.push({ pda: PublicKey.findProgramAddressSync( @@ -481,13 +481,13 @@ export class MerkleTreeConfig { new Uint8Array(32).fill(0), anchor.utils.bytes.utf8.encode("pool-config"), ], - this.merkleTreeProgram.programId + this.merkleTreeProgram.programId, )[0], poolType: poolType, token: await MerkleTreeConfig.getSplPoolPdaToken( mint, this.merkleTreeProgram.programId, - poolType + poolType, ), }); return this.poolPdas[this.poolPdas.length - 1]; @@ -496,7 +496,7 @@ export class MerkleTreeConfig { async getTokenAuthority() { this.tokenAuthority = PublicKey.findProgramAddressSync( [anchor.utils.bytes.utf8.encode("spl")], - this.merkleTreeProgram.programId + this.merkleTreeProgram.programId, )[0]; return this.tokenAuthority; } diff --git a/light-sdk-ts/src/merkleTree/merkleTreeUpdater.ts b/light-sdk-ts/src/merkleTree/merkleTreeUpdater.ts index fa1d68f41f..691f5aa93f 100644 --- a/light-sdk-ts/src/merkleTree/merkleTreeUpdater.ts +++ b/light-sdk-ts/src/merkleTree/merkleTreeUpdater.ts @@ -23,7 +23,7 @@ export async function executeUpdateMerkleTreeTransactions({ provider, }) { var merkleTreeAccountPrior = await merkleTreeProgram.account.merkleTree.fetch( - merkle_tree_pubkey + merkle_tree_pubkey, ); let merkleTreeUpdateState = ( await PublicKey.findProgramAddressSync( @@ -31,7 +31,7 @@ export async function executeUpdateMerkleTreeTransactions({ Buffer.from(new Uint8Array(signer.publicKey.toBytes())), anchor.utils.bytes.utf8.encode("storage"), ], - merkleTreeProgram.programId + merkleTreeProgram.programId, ) )[0]; @@ -137,7 +137,7 @@ export async function executeMerkleTreeUpdateTransactions({ for (let ix_id = 0; ix_id < numberOfTransactions; ix_id++) { const transaction = new Transaction(); transaction.add( - ComputeBudgetProgram.setComputeUnitLimit({ units: 1_400_000 }) + ComputeBudgetProgram.setComputeUnitLimit({ units: 1_400_000 }), ); transaction.add( await merkleTreeProgram.methods @@ -147,7 +147,7 @@ export async function executeMerkleTreeUpdateTransactions({ merkleTreeUpdateState: merkleTreeUpdateState, merkleTree: merkle_tree_pubkey, }) - .instruction() + .instruction(), ); i += 1; transaction.add( @@ -158,7 +158,7 @@ export async function executeMerkleTreeUpdateTransactions({ merkleTreeUpdateState: merkleTreeUpdateState, merkleTree: merkle_tree_pubkey, }) - .instruction() + .instruction(), ); i += 1; @@ -173,7 +173,7 @@ export async function executeMerkleTreeUpdateTransactions({ console.log(e); error = e; } - }) + }), ); return error; } diff --git a/light-sdk-ts/src/merkleTree/solMerkleTree.ts b/light-sdk-ts/src/merkleTree/solMerkleTree.ts index bd5ca13a6d..e29085d451 100644 --- a/light-sdk-ts/src/merkleTree/solMerkleTree.ts +++ b/light-sdk-ts/src/merkleTree/solMerkleTree.ts @@ -1,6 +1,10 @@ import { Program } from "@coral-xyz/anchor"; -import {PublicKey } from "@solana/web3.js"; -import { merkleTreeProgramId, MerkleTreeProgramIdl, MERKLE_TREE_HEIGHT } from "../index"; +import { PublicKey } from "@solana/web3.js"; +import { + merkleTreeProgramId, + MerkleTreeProgramIdl, + MERKLE_TREE_HEIGHT, +} from "../index"; import { MerkleTreeProgram } from "../idls/merkle_tree_program"; import { MerkleTree } from "./merkleTree"; const anchor = require("@coral-xyz/anchor"); @@ -9,16 +13,16 @@ const { unstringifyBigInts, leInt2Buff } = ffjavascript.utils; // TODO: once we have multiple trees add merkleTree[] and fetchTree(pubkey); export class SolMerkleTree { - merkleTree:MerkleTree; + merkleTree: MerkleTree; pubkey: PublicKey; constructor({ pubkey, poseidon, - merkleTree = new MerkleTree(MERKLE_TREE_HEIGHT, poseidon) + merkleTree = new MerkleTree(MERKLE_TREE_HEIGHT, poseidon), }: { - poseidon?: any, - merkleTree?:MerkleTree; + poseidon?: any; + merkleTree?: MerkleTree; pubkey: PublicKey; }) { this.pubkey = pubkey; @@ -28,31 +32,32 @@ export class SolMerkleTree { static async getLeaves(merkleTreePubkey: PublicKey) { const merkleTreeProgram: Program = new Program( MerkleTreeProgram, - merkleTreeProgramId + merkleTreeProgramId, ); const mtFetched = await merkleTreeProgram.account.merkleTree.fetch( - merkleTreePubkey + merkleTreePubkey, ); const merkleTreeIndex = mtFetched.nextIndex; var leaveAccounts: Array<{ pubkey: PublicKey; account: Account; }> = await merkleTreeProgram.account.twoLeavesBytesPda.all(); - return {leaveAccounts, merkleTreeIndex, mtFetched}; + return { leaveAccounts, merkleTreeIndex, mtFetched }; } - static async build ({ + static async build({ pubkey, poseidon, }: { pubkey: PublicKey; // pubkey to bytes poseidon: any; }) { - const {leaveAccounts, merkleTreeIndex, mtFetched} = await SolMerkleTree.getLeaves(pubkey); + const { leaveAccounts, merkleTreeIndex, mtFetched } = + await SolMerkleTree.getLeaves(pubkey); leaveAccounts.sort( (a, b) => - a.account.leftLeafIndex.toNumber() - b.account.leftLeafIndex.toNumber() + a.account.leftLeafIndex.toNumber() - b.account.leftLeafIndex.toNumber(), ); const leaves: string[] = []; @@ -66,15 +71,15 @@ export class SolMerkleTree { new anchor.BN( leaveAccounts[i].account.nodeLeft, undefined, - "le" - ).toString() + "le", + ).toString(), ); // .reverse() leaves.push( new anchor.BN( leaveAccounts[i].account.nodeRight, undefined, - "le" - ).toString() + "le", + ).toString(), ); } } @@ -83,59 +88,74 @@ export class SolMerkleTree { let fetchedMerkleTree = new MerkleTree( MERKLE_TREE_HEIGHT, poseidon, - leaves + leaves, ); if ( Array.from( - leInt2Buff(unstringifyBigInts(fetchedMerkleTree.root()), 32) + leInt2Buff(unstringifyBigInts(fetchedMerkleTree.root()), 32), ).toString() != mtFetched.roots[mtFetched.currentRootIndex].toString() ) { throw new Error( `building merkle tree from chain failed: root local ${Array.from( - leInt2Buff(unstringifyBigInts(fetchedMerkleTree.root()), 32) + leInt2Buff(unstringifyBigInts(fetchedMerkleTree.root()), 32), ).toString()} != root fetched ${ mtFetched.roots[mtFetched.currentRootIndex] - }` + }`, ); } - return new SolMerkleTree({merkleTree: fetchedMerkleTree, pubkey}); + return new SolMerkleTree({ merkleTree: fetchedMerkleTree, pubkey }); } static async getUninsertedLeaves(merkleTreePubkey: PublicKey) { - const {leaveAccounts, merkleTreeIndex} = await SolMerkleTree.getLeaves(merkleTreePubkey); + const { leaveAccounts, merkleTreeIndex } = await SolMerkleTree.getLeaves( + merkleTreePubkey, + ); let filteredLeaves = leaveAccounts .filter((pda) => { - if(pda.account.merkleTreePubkey.toBase58() === merkleTreePubkey.toBase58()) { - return pda.account.leftLeafIndex.toNumber() >= merkleTreeIndex.toNumber(); + if ( + pda.account.merkleTreePubkey.toBase58() === + merkleTreePubkey.toBase58() + ) { + return ( + pda.account.leftLeafIndex.toNumber() >= merkleTreeIndex.toNumber() + ); } }) .sort( (a, b) => - a.account.leftLeafIndex.toNumber() - b.account.leftLeafIndex.toNumber() + a.account.leftLeafIndex.toNumber() - + b.account.leftLeafIndex.toNumber(), ); - + return filteredLeaves.map((pda) => { return { isSigner: false, isWritable: false, pubkey: pda.publicKey }; }); } - static async getInsertedLeaves(merkleTreePubkey: PublicKey) /*: Promise<{ pubkey: PublicKey; account: Account; }[]>*/ { - const {leaveAccounts, merkleTreeIndex} = await SolMerkleTree.getLeaves(merkleTreePubkey); + static async getInsertedLeaves( + merkleTreePubkey: PublicKey, + ) /*: Promise<{ pubkey: PublicKey; account: Account; }[]>*/ { + const { leaveAccounts, merkleTreeIndex } = await SolMerkleTree.getLeaves( + merkleTreePubkey, + ); console.log("Total nr of accounts. ", leaveAccounts.length); - + let filteredLeaves = leaveAccounts .filter((pda) => { - return pda.account.leftLeafIndex.toNumber() < merkleTreeIndex.toNumber(); + return ( + pda.account.leftLeafIndex.toNumber() < merkleTreeIndex.toNumber() + ); }) .sort( (a, b) => - a.account.leftLeafIndex.toNumber() - b.account.leftLeafIndex.toNumber() + a.account.leftLeafIndex.toNumber() - + b.account.leftLeafIndex.toNumber(), ); - + return filteredLeaves; } -} \ No newline at end of file +} diff --git a/light-sdk-ts/src/relayer.ts b/light-sdk-ts/src/relayer.ts index c27d31557c..5342101d60 100644 --- a/light-sdk-ts/src/relayer.ts +++ b/light-sdk-ts/src/relayer.ts @@ -13,7 +13,7 @@ export class Relayer { relayerPubkey: PublicKey, lookUpTable: PublicKey, relayerRecipient?: PublicKey, - relayerFee: BN = new BN(0) + relayerFee: BN = new BN(0), ) { if (relayerRecipient) { this.accounts = { diff --git a/light-sdk-ts/src/test-utils/constants_market_place.ts b/light-sdk-ts/src/test-utils/constants_market_place.ts index 1e241f785a..f37173a9bb 100644 --- a/light-sdk-ts/src/test-utils/constants_market_place.ts +++ b/light-sdk-ts/src/test-utils/constants_market_place.ts @@ -4,29 +4,29 @@ export const offerBurnerPrivkey = new BN( Buffer.from([ 237, 38, 4, 149, 204, 158, 213, 144, 83, 16, 191, 94, 68, 105, 127, 237, 66, 153, 151, 133, 243, 205, 71, 208, 223, 215, 88, 171, 195, 137, 213, 159, - ]) + ]), ); export const offerAuthorityPrivkey = new BN( Buffer.from([ 42, 150, 26, 78, 235, 21, 149, 49, 116, 215, 34, 161, 176, 34, 26, 16, 147, 30, 65, 203, 209, 221, 162, 85, 222, 209, 157, 53, 59, 28, 2, 253, - ]) + ]), ); export const bidderPrivkey = new BN( Buffer.from([ 226, 46, 122, 35, 45, 227, 24, 192, 49, 124, 94, 100, 208, 151, 189, 53, 30, 52, 105, 191, 89, 191, 222, 95, 10, 224, 189, 95, 68, 242, 176, 69, - ]) + ]), ); export const feeRecipientPrivkey = new BN( Buffer.from([ 133, 230, 53, 81, 251, 24, 235, 119, 96, 245, 17, 219, 97, 119, 70, 122, 172, 42, 13, 100, 232, 118, 151, 231, 230, 195, 140, 146, 220, 191, 89, 100, - ]) + ]), ); export const feeRecipient1Privkey = new BN( Buffer.from([ 77, 196, 121, 16, 173, 229, 13, 169, 130, 94, 253, 3, 131, 221, 238, 47, 210, 118, 92, 100, 150, 225, 205, 67, 196, 129, 33, 132, 118, 54, 216, 209, - ]) + ]), ); diff --git a/light-sdk-ts/src/test-utils/constants_system_verifier.ts b/light-sdk-ts/src/test-utils/constants_system_verifier.ts index a768dfdc40..fe8454ef88 100644 --- a/light-sdk-ts/src/test-utils/constants_system_verifier.ts +++ b/light-sdk-ts/src/test-utils/constants_system_verifier.ts @@ -17,7 +17,7 @@ export const USER_TOKEN_ACCOUNT = Keypair.fromSecretKey( 242, 95, 5, 9, 102, 7, 50, 204, 117, 74, 106, 114, 106, 225, 37, 203, 222, 28, 100, 182, 147, 102, 98, 110, 249, 219, 249, 24, 50, 149, 18, 75, 184, 183, 246, 83, 13, 66, 226, 103, 241, 88, 135, 253, 226, 32, 41, 186, - ]) + ]), ); export const RECIPIENT_TOKEN_ACCOUNT = Keypair.fromSecretKey( @@ -26,12 +26,12 @@ export const RECIPIENT_TOKEN_ACCOUNT = Keypair.fromSecretKey( 113, 227, 43, 76, 83, 234, 5, 93, 242, 182, 158, 40, 141, 213, 16, 229, 254, 86, 86, 250, 191, 38, 191, 237, 255, 198, 0, 140, 74, 85, 247, 85, 30, 34, 76, 42, 114, 252, 102, 230, 216, 107, 44, 225, 133, 40, 17, 6, - ]) + ]), ); export var KEYPAIR_PRIVKEY = new BN( "d67b402d88fe6eb59004f4ab53b06a4b9dc72c74a05e60c31a07148eafa95896", - "hex" + "hex", ); export const MINT_PRIVATE_KEY = new Uint8Array([ @@ -59,16 +59,16 @@ export const MERKLE_TREE_INIT_AUTHORITY = [ ]; export const ADMIN_AUTH_KEY: PublicKey = new PublicKey( - new Uint8Array(MERKLE_TREE_INIT_AUTHORITY) + new Uint8Array(MERKLE_TREE_INIT_AUTHORITY), ); export const ADMIN_AUTH_KEYPAIR: Keypair = Keypair.fromSecretKey( - new Uint8Array(PRIVATE_KEY) + new Uint8Array(PRIVATE_KEY), ); export const userTokenAccount = new PublicKey( - "CfyD2mSomGrjnyMKWrgNEk1ApaaUvKRDsnQngGkCVTFk" + "CfyD2mSomGrjnyMKWrgNEk1ApaaUvKRDsnQngGkCVTFk", ); export const recipientTokenAccount = new PublicKey( - "6RtYrpXTyH98dvTf9ufivkyDG8mF48oMDbhiRW9r5KjD" + "6RtYrpXTyH98dvTf9ufivkyDG8mF48oMDbhiRW9r5KjD", ); diff --git a/light-sdk-ts/src/test-utils/createAccounts.ts b/light-sdk-ts/src/test-utils/createAccounts.ts index fe048e326d..7b95bb8e8e 100644 --- a/light-sdk-ts/src/test-utils/createAccounts.ts +++ b/light-sdk-ts/src/test-utils/createAccounts.ts @@ -41,11 +41,11 @@ const sleep = (ms) => { export const newAccountWithLamports = async ( connection: Connection, account = solana.Keypair.generate(), - lamports = 1e10 + lamports = 1e10, ) => { let x = await connection.confirmTransaction( await connection.requestAirdrop(account.publicKey, lamports), - "confirmed" + "confirmed", ); console.log("newAccountWithLamports ", account.publicKey.toBase58()); return account; @@ -54,7 +54,7 @@ export const newAccountWithLamports = async ( export const newAddressWithLamports = async ( connection: Connection, address = new anchor.web3.Account().publicKey, - lamports = 1e11 + lamports = 1e11, ) => { let retries = 30; await connection.requestAirdrop(address, lamports); @@ -88,7 +88,7 @@ export const newProgramOwnedAccount = async ({ try { await connection.confirmTransaction( await connection.requestAirdrop(payer.publicKey, 1e7), - "confirmed" + "confirmed", ); const tx = new solana.Transaction().add( @@ -98,7 +98,7 @@ export const newProgramOwnedAccount = async ({ space: 0, lamports: await connection.getMinimumBalanceForRentExemption(1), Id: owner.programId, - }) + }), ); tx.feePayer = payer.publicKey; @@ -110,7 +110,7 @@ export const newProgramOwnedAccount = async ({ { commitment: "confirmed", preflightCommitment: "confirmed", - } + }, ); return account; } catch {} @@ -133,7 +133,7 @@ export async function newAccountWithTokens({ connection, ADMIN_AUTH_KEYPAIR, MINT, - userAccount.publicKey + userAccount.publicKey, // userAccount ); @@ -150,7 +150,7 @@ export async function newAccountWithTokens({ tokenAccount, ADMIN_AUTH_KEYPAIR.publicKey, amount, - [] + [], ); } catch (e) { console.log(e); @@ -186,20 +186,20 @@ export async function createMintWrapper({ newAccountPubkey: mintKeypair.publicKey, programId: TOKEN_PROGRAM_ID, space: space, - }) + }), ); let res = await sendAndConfirmTransaction( connection, txCreateAccount, [authorityKeypair, mintKeypair], - confirmConfig + confirmConfig, ); assert( (await connection.getTransaction(res, { commitment: "confirmed", })) != null, - "create mint account failed" + "create mint account failed", ); let mint = await createMint( connection, @@ -207,11 +207,11 @@ export async function createMintWrapper({ authorityKeypair.publicKey, null, // freez auth decimals, //2, - mintKeypair + mintKeypair, ); assert( (await connection.getAccountInfo(mint)) != null, - "create mint failed" + "create mint failed", ); return mintKeypair.publicKey; } catch (e) { @@ -244,20 +244,20 @@ export async function createTestAccounts(connection: Connection) { fromPubkey: ADMIN_AUTH_KEYPAIR.publicKey, toPubkey: AUTHORITY, lamports: 1_000_000_000, - }) + }), ); await sendAndConfirmTransaction( connection, txTransfer1, [ADMIN_AUTH_KEYPAIR], - confirmConfig + confirmConfig, ); } if ( (await connection.getBalance( solana.Keypair.fromSecretKey(MINT_PRIVATE_KEY).publicKey, - "confirmed" + "confirmed", )) == 0 ) { await createMintWrapper({ @@ -275,7 +275,7 @@ export async function createTestAccounts(connection: Connection) { connection, userTokenAccount, "confirmed", - TOKEN_PROGRAM_ID + TOKEN_PROGRAM_ID, ); } catch (e) {} diff --git a/light-sdk-ts/src/test-utils/initLookUpTable.ts b/light-sdk-ts/src/test-utils/initLookUpTable.ts index 364f329205..552c9e2579 100644 --- a/light-sdk-ts/src/test-utils/initLookUpTable.ts +++ b/light-sdk-ts/src/test-utils/initLookUpTable.ts @@ -39,19 +39,19 @@ import VerifierProgramZero, { export async function initLookUpTableFromFile( provider: anchor.Provider, path: PathOrFileDescriptor = `lookUpTable.txt`, - extraAccounts?: Array + extraAccounts?: Array, ) /*: Promise*/ { const recentSlot = (await provider.connection.getSlot("confirmed")) - 10; const payerPubkey = ADMIN_AUTH_KEYPAIR.publicKey; var [lookUpTable] = await PublicKey.findProgramAddress( [payerPubkey.toBuffer(), new anchor.BN(recentSlot).toBuffer("le", 8)], - AddressLookupTableProgram.programId + AddressLookupTableProgram.programId, ); try { let lookUpTableRead = new PublicKey(readFileSync(path, "utf8")); let lookUpTableInfoInit = await provider.connection.getAccountInfo( - lookUpTableRead + lookUpTableRead, ); if (lookUpTableInfoInit) { lookUpTable = lookUpTableRead; @@ -64,7 +64,7 @@ export async function initLookUpTableFromFile( provider, lookUpTable, recentSlot, - extraAccounts + extraAccounts, ); writeFile(path, LOOK_UP_TABLE.toString(), function (err) { @@ -80,12 +80,12 @@ export async function initLookUpTable( provider: Provider, lookupTableAddress: PublicKey, recentSlot: number, - extraAccounts?: Array + extraAccounts?: Array, ): Promise { var lookUpTableInfoInit = null; if (lookupTableAddress != undefined) { lookUpTableInfoInit = await provider.connection.getAccountInfo( - lookupTableAddress + lookupTableAddress, ); } @@ -100,12 +100,12 @@ export async function initLookUpTable( })[0]; const verifierProgramZero: Program = new Program( VerifierProgramZero, - verifierProgramZeroProgramId + verifierProgramZeroProgramId, ); let escrows = ( await PublicKey.findProgramAddress( [anchor.utils.bytes.utf8.encode("escrow")], - verifierProgramZero.programId + verifierProgramZero.programId, ) )[0]; @@ -149,7 +149,7 @@ export async function initLookUpTable( transaction.add(ix0); // transaction.add(ix1); let recentBlockhash = await provider.connection.getRecentBlockhash( - "confirmed" + "confirmed", ); transaction.feePayer = payerPubkey; transaction.recentBlockhash = recentBlockhash; @@ -159,7 +159,7 @@ export async function initLookUpTable( provider.connection, transaction, [ADMIN_AUTH_KEYPAIR], - confirmConfig + confirmConfig, ); } catch (e) { console.log("e : ", e); @@ -168,7 +168,7 @@ export async function initLookUpTable( console.log("lookupTableAddress: ", lookupTableAddress.toBase58()); let lookupTableAccount = await provider.connection.getAccountInfo( lookupTableAddress, - "confirmed" + "confirmed", ); assert(lookupTableAccount != null); } diff --git a/light-sdk-ts/src/test-utils/setUpMerkleTree.ts b/light-sdk-ts/src/test-utils/setUpMerkleTree.ts index 2a6dba4890..d8d000e4da 100644 --- a/light-sdk-ts/src/test-utils/setUpMerkleTree.ts +++ b/light-sdk-ts/src/test-utils/setUpMerkleTree.ts @@ -36,7 +36,7 @@ export async function setUpMerkleTree(provider: anchor.Provider) { new anchor.Program(VerifierProgramTwo, verifierProgramTwoProgramId); var merkleTreeAccountInfoInit = await provider.connection.getAccountInfo( - MERKLE_TREE_KEY + MERKLE_TREE_KEY, ); // console.log("merkleTreeAccountInfoInit ", merkleTreeAccountInfoInit); // console.log("MERKLE_TREE_KEY ", MERKLE_TREE_KEY); @@ -65,7 +65,7 @@ export async function setUpMerkleTree(provider: anchor.Provider) { console.log( "verifierProgramZero.programId: ", - Array.from(verifierProgramZero.programId.toBytes()) + Array.from(verifierProgramZero.programId.toBytes()), ); console.log("MERKLE_TREE_KEY: ", MERKLE_TREE_KEY.toBase58()); console.log("MERKLE_TREE_KEY: ", Array.from(MERKLE_TREE_KEY.toBytes())); @@ -78,7 +78,7 @@ export async function setUpMerkleTree(provider: anchor.Provider) { (await provider.connection.getTransaction(ix, { commitment: "confirmed", })) != null, - "init failed" + "init failed", ); } catch (e) { console.log(e); diff --git a/light-sdk-ts/src/test-utils/testChecks.ts b/light-sdk-ts/src/test-utils/testChecks.ts index 611d282fc9..3aa07cf6f3 100644 --- a/light-sdk-ts/src/test-utils/testChecks.ts +++ b/light-sdk-ts/src/test-utils/testChecks.ts @@ -31,57 +31,57 @@ export async function checkMerkleTreeUpdateStateCreated({ }) { var merkleTreeTmpAccountInfo = await connection.getAccountInfo( merkleTreeUpdateState, - CONFIRMATION + CONFIRMATION, ); assert( merkleTreeTmpAccountInfo.owner.toBase58() === merkleTreeProgram.programId.toBase58(), - "merkle tree pda owner wrong after initializing" + "merkle tree pda owner wrong after initializing", ); const merkleTreeUpdateStateData = merkleTreeProgram.account.preInsertedLeavesIndex._coder.accounts.decode( "MerkleTreeUpdateState", - merkleTreeTmpAccountInfo.data + merkleTreeTmpAccountInfo.data, ); var MerkleTreeAccountInfo = await merkleTreeProgram.account.merkleTree.fetch( - MerkleTree + MerkleTree, ); // console.log("merkleTreeUpdateStateData.leaves ", merkleTreeUpdateStateData.leaves); console.log( "merkleTreeUpdateStateData.numberOfLeaves ", - merkleTreeUpdateStateData.numberOfLeaves + merkleTreeUpdateStateData.numberOfLeaves, ); console.log("leavesPdas.length ", leavesPdas.length); console.log( "merkleTreeUpdateStateData.currentInstructionIndex ", - merkleTreeUpdateStateData.currentInstructionIndex + merkleTreeUpdateStateData.currentInstructionIndex, ); console.log("current_instruction_index ", current_instruction_index); assert( merkleTreeUpdateStateData.relayer.toBase58() == relayer.toBase58(), - "The incorrect signer has been saved" + "The incorrect signer has been saved", ); assert( merkleTreeUpdateStateData.merkleTreePdaPubkey.toBase58() == MerkleTree.toBase58(), - "the incorrect merkle tree pubkey was saved" + "the incorrect merkle tree pubkey was saved", ); assert( merkleTreeUpdateStateData.numberOfLeaves == leavesPdas.length, - "The incorrect number of leaves was saved" + "The incorrect number of leaves was saved", ); assert( merkleTreeUpdateStateData.currentInstructionIndex == current_instruction_index, - "The instruction index is wrong" + "The instruction index is wrong", ); assert( MerkleTreeAccountInfo.pubkeyLocked.toBase58() == - merkleTreeUpdateState.toBase58() + merkleTreeUpdateState.toBase58(), ); // assert(U64.readLE(MerkleTreeAccountInfo.data.slice(16658-8,16658), 0) >= (await connection.getSlot()) - 5, "Lock has not been taken at this or in the 5 prior slots"); console.log("checkMerkleTreeUpdateStateCreated: success"); @@ -98,27 +98,27 @@ export async function checkMerkleTreeBatchUpdateSuccess({ merkleTreeProgram, }) { var merkleTreeTmpStateAccount = await connection.getAccountInfo( - merkleTreeUpdateState + merkleTreeUpdateState, ); assert( merkleTreeTmpStateAccount === null, - "Shielded transaction failed merkleTreeTmpStateAccount is not closed" + "Shielded transaction failed merkleTreeTmpStateAccount is not closed", ); var merkleTreeAccount = await merkleTreeProgram.account.merkleTree.fetch( - merkle_tree_pubkey + merkle_tree_pubkey, ); // Merkle tree is locked by merkleTreeUpdateState assert( merkleTreeAccount.pubkeyLocked.toBase58() == - new solana.PublicKey(new Uint8Array(32).fill(0)).toBase58() + new solana.PublicKey(new Uint8Array(32).fill(0)).toBase58(), ); console.log("merkleTreeAccount.time_locked ", merkleTreeAccount.timeLocked); assert( merkleTreeAccount.timeLocked == 0, - "Lock has not been taken within prior 20 slots" + "Lock has not been taken within prior 20 slots", ); let merkle_tree_prior_leaves_index = merkleTreeAccountPrior.nextIndex; //U64.readLE(merkleTreeAccountPrior.data.slice(594, 594 + 8),0); @@ -128,18 +128,18 @@ export async function checkMerkleTreeBatchUpdateSuccess({ let current_root_index = merkleTreeAccount.currentRootIndex; //tU64.readLE(merkleTreeAccount.data.slice(594 - 8, 594),0).toNumber() console.log( "merkle_tree_prior_current_root_index: ", - merkle_tree_prior_current_root_index + merkle_tree_prior_current_root_index, ); console.log("current_root_index: ", current_root_index); console.log( `${merkle_tree_prior_current_root_index.add( - new anchor.BN("1") - )} == ${current_root_index}` + new anchor.BN("1"), + )} == ${current_root_index}`, ); assert( merkle_tree_prior_current_root_index.add(new anchor.BN("1")).toString() === - current_root_index.toString() + current_root_index.toString(), ); let current_root_start_range = 610 + current_root_index * 32; let current_root_end_range = 610 + (current_root_index + 1) * 32; @@ -152,13 +152,13 @@ export async function checkMerkleTreeBatchUpdateSuccess({ console.log( `${merkle_tree_prior_leaves_index.add(new anchor.BN(numberOfLeaves))} == ${ merkleTreeAccount.nextIndex - }` + }`, ); assert( merkle_tree_prior_leaves_index .add(new anchor.BN(numberOfLeaves)) - .toString() == merkleTreeAccount.nextIndex.toString() + .toString() == merkleTreeAccount.nextIndex.toString(), ); //U64.readLE(merkleTreeAccount.data.slice(594, 594 + 8), 0).toString()) // let leavesPdasPubkeys = [] @@ -189,18 +189,18 @@ export async function checkMerkleTreeBatchUpdateSuccess({ export async function checkRentExemption({ connection, account }) { let requiredBalance = await connection.getMinimumBalanceForRentExemption( - account.data.length + account.data.length, ); if (account.lamports < requiredBalance) { throw Error( - `Account of size ${account.data.length} not rentexempt balance ${account.lamports} should be${requiredBalance}` + `Account of size ${account.data.length} not rentexempt balance ${account.lamports} should be${requiredBalance}`, ); } } export async function checkNfInserted( pubkeys: PublicKey[], - connection: Connection + connection: Connection, ) { for (var i = 0; i < pubkeys.length; i++) { var accountInfo = await connection.getAccountInfo(pubkeys[i]); diff --git a/light-sdk-ts/src/test-utils/testTransactions.ts b/light-sdk-ts/src/test-utils/testTransactions.ts index b1a4f27b77..e69db4b032 100644 --- a/light-sdk-ts/src/test-utils/testTransactions.ts +++ b/light-sdk-ts/src/test-utils/testTransactions.ts @@ -38,7 +38,7 @@ export async function testTransaction({ const shieldedTxBackUp: Transaction = _.cloneDeep(transaction); console.log( "transaction.publicInputs.publicAmount ", - transaction.publicInputs.publicAmount + transaction.publicInputs.publicAmount, ); // Wrong pub amount @@ -54,11 +54,11 @@ export async function testTransaction({ console.log( "Wrong wrongPubAmount", - e.logs.includes("Program log: error ProofVerificationFailed") + e.logs.includes("Program log: error ProofVerificationFailed"), ); assert(e.logs.includes("Program log: error ProofVerificationFailed") == true); transaction.publicInputs.publicAmount = _.cloneDeep( - shieldedTxBackUp.publicInputs.publicAmount + shieldedTxBackUp.publicInputs.publicAmount, ); await checkNfInserted(transaction.nullifierPdaPubkeys, provider.connection); // Wrong feeAmount @@ -72,7 +72,7 @@ export async function testTransaction({ e = await transaction.sendTransaction(); console.log( "Wrong feeAmount", - e.logs.includes("Program log: error ProofVerificationFailed") + e.logs.includes("Program log: error ProofVerificationFailed"), ); assert(e.logs.includes("Program log: error ProofVerificationFailed") == true); transaction.publicInputs = _.cloneDeep(shieldedTxBackUp.publicInputs); @@ -97,7 +97,7 @@ export async function testTransaction({ e = await transaction.sendTransaction(); console.log( "Wrong wrongMint", - e.logs.includes("Program log: error ProofVerificationFailed") + e.logs.includes("Program log: error ProofVerificationFailed"), ); assert(e.logs.includes("Program log: error ProofVerificationFailed") == true); transaction = _.cloneDeep(shieldedTxBackUp); @@ -110,7 +110,7 @@ export async function testTransaction({ e = await transaction.sendTransaction(); console.log( "Wrong encryptedUtxos", - e.logs.includes("Program log: error ProofVerificationFailed") + e.logs.includes("Program log: error ProofVerificationFailed"), ); assert(e.logs.includes("Program log: error ProofVerificationFailed") == true); transaction.encryptedUtxos = _.cloneDeep(shieldedTxBackUp.encryptedUtxos); @@ -122,7 +122,7 @@ export async function testTransaction({ e = await transaction.sendTransaction(); console.log( "Wrong relayerFee", - e.logs.includes("Program log: error ProofVerificationFailed") + e.logs.includes("Program log: error ProofVerificationFailed"), ); assert(e.logs.includes("Program log: error ProofVerificationFailed") == true); transaction.relayerFee = _.cloneDeep(shieldedTxBackUp.relayerFee); @@ -135,10 +135,10 @@ export async function testTransaction({ "Wrong nullifier ", i, " ", - e.logs.includes("Program log: error ProofVerificationFailed") + e.logs.includes("Program log: error ProofVerificationFailed"), ); assert( - e.logs.includes("Program log: error ProofVerificationFailed") == true + e.logs.includes("Program log: error ProofVerificationFailed") == true, ); transaction = _.cloneDeep(shieldedTxBackUp); await checkNfInserted(transaction.nullifierPdaPubkeys, provider.connection); @@ -150,10 +150,10 @@ export async function testTransaction({ e = await transaction.sendTransaction(); console.log( "Wrong leafLeft", - e.logs.includes("Program log: error ProofVerificationFailed") + e.logs.includes("Program log: error ProofVerificationFailed"), ); assert( - e.logs.includes("Program log: error ProofVerificationFailed") == true + e.logs.includes("Program log: error ProofVerificationFailed") == true, ); transaction.publicInputs.leaves[i] = _.cloneDeep(shieldedTxBackUp).publicInputs.leaves[i]; @@ -201,10 +201,10 @@ export async function testTransaction({ console.log( "Wrong recipientFee", - e.logs.includes("Program log: error ProofVerificationFailed") + e.logs.includes("Program log: error ProofVerificationFailed"), ); assert( - e.logs.includes("Program log: error ProofVerificationFailed") == true + e.logs.includes("Program log: error ProofVerificationFailed") == true, ); transaction.recipientFee = _.cloneDeep(shieldedTxBackUp.recipientFee); } else { @@ -212,10 +212,10 @@ export async function testTransaction({ e = await transaction.sendTransaction(); console.log( "Wrong sender", - e.logs.includes("Program log: error ProofVerificationFailed") + e.logs.includes("Program log: error ProofVerificationFailed"), ); assert( - e.logs.includes("Program log: error ProofVerificationFailed") == true + e.logs.includes("Program log: error ProofVerificationFailed") == true, ); transaction.sender = _.cloneDeep(shieldedTxBackUp.sender); await checkNfInserted(transaction.nullifierPdaPubkeys, provider.connection); @@ -229,13 +229,13 @@ export async function testTransaction({ console.log( "Wrong senderFee", e.logs.includes( - "Program log: AnchorError thrown in src/light_transaction.rs:696. Error Code: InvalidSenderorRecipient. Error Number: 6011. Error Message: InvalidSenderorRecipient." - ) + "Program log: AnchorError thrown in src/light_transaction.rs:696. Error Code: InvalidSenderorRecipient. Error Number: 6011. Error Message: InvalidSenderorRecipient.", + ), ); assert( e.logs.includes( - "Program log: AnchorError thrown in src/light_transaction.rs:696. Error Code: InvalidSenderorRecipient. Error Number: 6011. Error Message: InvalidSenderorRecipient." - ) == true + "Program log: AnchorError thrown in src/light_transaction.rs:696. Error Code: InvalidSenderorRecipient. Error Number: 6011. Error Message: InvalidSenderorRecipient.", + ) == true, ); transaction.senderFee = _.cloneDeep(shieldedTxBackUp.senderFee); await checkNfInserted(transaction.nullifierPdaPubkeys, provider.connection); @@ -244,7 +244,7 @@ export async function testTransaction({ console.log("Wrong registeredVerifierPda "); console.log( "transaction.verifier.registeredVerifierPda ", - transaction.verifier.registeredVerifierPda + transaction.verifier.registeredVerifierPda, ); console.log("REGISTERED_VERIFIER_ONE_PDA ", REGISTERED_VERIFIER_ONE_PDA); @@ -265,11 +265,11 @@ export async function testTransaction({ console.log("Wrong registeredVerifierPda", e); assert( e.logs.includes( - "Program log: AnchorError caused by account: registered_verifier_pda. Error Code: ConstraintSeeds. Error Number: 2006. Error Message: A seeds constraint was violated." - ) == true + "Program log: AnchorError caused by account: registered_verifier_pda. Error Code: ConstraintSeeds. Error Number: 2006. Error Message: A seeds constraint was violated.", + ) == true, ); transaction.registeredVerifierPda = _.cloneDeep( - shieldedTxBackUp.registeredVerifierPda + shieldedTxBackUp.registeredVerifierPda, ); await checkNfInserted(transaction.nullifierPdaPubkeys, provider.connection); @@ -282,16 +282,16 @@ export async function testTransaction({ console.log( "Wrong authority1 ", e.logs.includes( - "Program log: AnchorError caused by account: authority. Error Code: ConstraintSeeds. Error Number: 2006. Error Message: A seeds constraint was violated." - ) + "Program log: AnchorError caused by account: authority. Error Code: ConstraintSeeds. Error Number: 2006. Error Message: A seeds constraint was violated.", + ), ); assert( e.logs.includes( - "Program log: AnchorError caused by account: authority. Error Code: ConstraintSeeds. Error Number: 2006. Error Message: A seeds constraint was violated." - ) == true + "Program log: AnchorError caused by account: authority. Error Code: ConstraintSeeds. Error Number: 2006. Error Message: A seeds constraint was violated.", + ) == true, ); transaction.signerAuthorityPubkey = _.cloneDeep( - shieldedTxBackUp.signerAuthorityPubkey + shieldedTxBackUp.signerAuthorityPubkey, ); await checkNfInserted(transaction.nullifierPdaPubkeys, provider.connection); @@ -306,7 +306,7 @@ export async function testTransaction({ for (var j = 0; j < transaction.nullifierPdaPubkeys.length; j++) { console.log( "transaction.nullifierPdaPubkeys.length ", - transaction.nullifierPdaPubkeys.length + transaction.nullifierPdaPubkeys.length, ); // Wrong authority @@ -316,13 +316,13 @@ export async function testTransaction({ ]; assert( transaction.nullifierPdaPubkeys[j] != - shieldedTxBackUp.nullifierPdaPubkeys[j] + shieldedTxBackUp.nullifierPdaPubkeys[j], ); e = await transaction.sendTransaction(); console.log(e); console.log( "transaction.nullifierPdaPubkeys[i] ", - transaction.nullifierPdaPubkeys[j] + transaction.nullifierPdaPubkeys[j], ); console.log( @@ -330,26 +330,26 @@ export async function testTransaction({ j, " ", e.logs.includes( - "Program log: Passed-in pda pubkey != on-chain derived pda pubkey." - ) + "Program log: Passed-in pda pubkey != on-chain derived pda pubkey.", + ), ); assert( e.logs.includes( - "Program log: Passed-in pda pubkey != on-chain derived pda pubkey." - ) == true + "Program log: Passed-in pda pubkey != on-chain derived pda pubkey.", + ) == true, ); transaction.nullifierPdaPubkeys = _.cloneDeep( - shieldedTxBackUp.nullifierPdaPubkeys + shieldedTxBackUp.nullifierPdaPubkeys, ); assert( transaction.nullifierPdaPubkeys[j] == - shieldedTxBackUp.nullifierPdaPubkeys[j] + shieldedTxBackUp.nullifierPdaPubkeys[j], ); console.log( "transaction.nullifierPdaPubkeys[j] ", - transaction.nullifierPdaPubkeys[j] + transaction.nullifierPdaPubkeys[j], ); } } diff --git a/light-sdk-ts/src/transaction.ts b/light-sdk-ts/src/transaction.ts index bdc6e960fd..04a656fea8 100644 --- a/light-sdk-ts/src/transaction.ts +++ b/light-sdk-ts/src/transaction.ts @@ -23,15 +23,17 @@ import { } from "@solana/web3.js"; import { TOKEN_PROGRAM_ID, getAccount } from "@solana/spl-token"; import { BN, Program, Provider } from "@coral-xyz/anchor"; -import { - PRE_INSERTED_LEAVES_INDEX, - confirmConfig, -} from "./constants"; +import { PRE_INSERTED_LEAVES_INDEX, confirmConfig } from "./constants"; import { N_ASSETS, N_ASSET_PUBKEYS, Utxo } from "./utxo"; import { PublicInputs, Verifier } from "./verifiers"; import { checkRentExemption } from "./test-utils/testChecks"; import { MerkleTreeConfig } from "./merkleTree/merkleTreeConfig"; -import { FIELD_SIZE, merkleTreeProgramId, Relayer, SolMerkleTree } from "./index"; +import { + FIELD_SIZE, + merkleTreeProgramId, + Relayer, + SolMerkleTree, +} from "./index"; import { MerkleTreeProgram, MerkleTreeProgramIdl, @@ -118,7 +120,7 @@ export class TransactionParameters implements transactionParameters { }) { this.merkleTreeProgram = new Program( MerkleTreeProgram, - merkleTreeProgramId + merkleTreeProgramId, ); this.accounts = { systemProgramId: SystemProgram.programId, @@ -126,11 +128,11 @@ export class TransactionParameters implements transactionParameters { merkleTree: merkleTreePubkey, registeredVerifierPda: Transaction.getRegisteredVerifierPda( this.merkleTreeProgram.programId, - verifier.verifierProgram.programId + verifier.verifierProgram.programId, ), authority: Transaction.getSignerAuthorityPda( this.merkleTreeProgram.programId, - verifier.verifierProgram.programId + verifier.verifierProgram.programId, ), preInsertedLeavesIndex: PRE_INSERTED_LEAVES_INDEX, sender: sender, @@ -202,7 +204,7 @@ export class Transaction { * @param shuffleEnabled */ -constructor({ + constructor({ instance, relayer, payer, @@ -230,12 +232,16 @@ constructor({ } // Returns serialized instructions - async proveAndCreateInstructionsJson(params: TransactionParameters): Promise { + async proveAndCreateInstructionsJson( + params: TransactionParameters, + ): Promise { await this.compileAndProve(params); return await this.getInstructionsJson(); } - async proveAndCreateInstructions(params: TransactionParameters): Promise { + async proveAndCreateInstructions( + params: TransactionParameters, + ): Promise { await this.compileAndProve(params); return await this.params.verifier.getInstructions(this); } @@ -257,11 +263,11 @@ constructor({ this.assetPubkeysCircuit = pubkeys.assetPubkeysCircuit; this.params.inputUtxos = this.addEmptyUtxos( params.inputUtxos, - params.verifier.config.in + params.verifier.config.in, ); this.params.outputUtxos = this.addEmptyUtxos( params.outputUtxos, - params.verifier.config.out + params.verifier.config.out, ); this.shuffleUtxos(this.params.inputUtxos); this.shuffleUtxos(this.params.outputUtxos); @@ -305,18 +311,18 @@ constructor({ inIndices: this.getIndices(this.params.inputUtxos), outIndices: this.getIndices(this.params.outputUtxos), inInstructionType: this.params.inputUtxos?.map( - (x) => x.instructionType + (x) => x.instructionType, ), outInstructionType: this.params.outputUtxos?.map( - (x) => x.instructionType + (x) => x.instructionType, ), inPoolType: this.params.inputUtxos?.map((x) => x.poolType), outPoolType: this.params.outputUtxos?.map((x) => x.poolType), inVerifierPubkey: this.params.inputUtxos?.map( - (x) => x.verifierAddressCircuit + (x) => x.verifierAddressCircuit, ), outVerifierPubkey: this.params.outputUtxos?.map( - (x) => x.verifierAddressCircuit + (x) => x.verifierAddressCircuit, ), }; } else { @@ -342,12 +348,12 @@ constructor({ console.time("Proof generation"); let wtns = await witnessCalculator.calculateWTNSBin( stringifyBigInts(this.proofInput), - 0 + 0, ); const { proof, publicSignals } = await snarkjs.groth16.prove( `${this.params.verifier.zkeyPath}.zkey`, - wtns + wtns, ); const proofJson = JSON.stringify(proof, null, 1); @@ -355,7 +361,7 @@ constructor({ console.timeEnd("Proof generation"); const vKey = await snarkjs.zKey.exportVerificationKey( - `${this.params.verifier.zkeyPath}.zkey` + `${this.params.verifier.zkeyPath}.zkey`, ); const res = await snarkjs.groth16.verify(vKey, publicSignals, proof); if (res === true) { @@ -368,7 +374,7 @@ constructor({ this.publicInputsBytes = JSON.parse(publicInputsJson.toString()); for (var i in this.publicInputsBytes) { this.publicInputsBytes[i] = Array.from( - leInt2Buff(unstringifyBigInts(this.publicInputsBytes[i]), 32) + leInt2Buff(unstringifyBigInts(this.publicInputsBytes[i]), 32), ).reverse(); } // console.log("publicInputsBytes ", this.publicInputsBytes); @@ -392,7 +398,7 @@ constructor({ } this.params.accounts.sender = MerkleTreeConfig.getSplPoolPdaToken( this.assetPubkeys[1], - merkleTreeProgramId + merkleTreeProgramId, ); this.params.accounts.senderFee = MerkleTreeConfig.getSolPoolPda(merkleTreeProgramId).pda; @@ -401,7 +407,7 @@ constructor({ this.params.accounts.recipient = SystemProgram.programId; if (this.publicAmount != new BN(0)) { throw new Error( - "sth is wrong assignAccounts !params.accounts.recipient" + "sth is wrong assignAccounts !params.accounts.recipient", ); } } @@ -409,7 +415,7 @@ constructor({ this.params.accounts.recipientFee = SystemProgram.programId; if (this.feeAmount != new BN(0)) { throw new Error( - "sth is wrong assignAccounts !params.accounts.recipientFee" + "sth is wrong assignAccounts !params.accounts.recipientFee", ); } } @@ -420,7 +426,7 @@ constructor({ this.params.accounts.recipient = MerkleTreeConfig.getSplPoolPdaToken( this.assetPubkeys[1], - merkleTreeProgramId + merkleTreeProgramId, ); this.params.accounts.recipientFee = MerkleTreeConfig.getSolPoolPda(merkleTreeProgramId).pda; @@ -428,7 +434,7 @@ constructor({ this.params.accounts.sender = SystemProgram.programId; if (this.publicAmount != new BN(0)) { throw new Error( - "sth is wrong assignAccounts !params.accounts.sender" + "sth is wrong assignAccounts !params.accounts.sender", ); } } @@ -436,7 +442,7 @@ constructor({ this.params.accounts.senderFee = SystemProgram.programId; if (this.feeAmount != new BN(0)) { throw new Error( - "sth is wrong assignAccounts !params.accounts.senderFee" + "sth is wrong assignAccounts !params.accounts.senderFee", ); } } @@ -448,7 +454,7 @@ constructor({ getAssetPubkeys( inputUtxos?: Utxo[], - outputUtxos?: Utxo[] + outputUtxos?: Utxo[], ): { assetPubkeysCircuit: BN[]; assetPubkeys: PublicKey[] } { let assetPubkeysCircuit: BN[] = [new BN(0)]; let assetPubkeys: PublicKey[] = [SystemProgram.programId]; @@ -471,15 +477,14 @@ constructor({ }); } - if (assetPubkeys.length == 0) { throw new Error("No utxos provided."); } if (assetPubkeys.length > N_ASSET_PUBKEYS) { throw new Error("Utxos contain too many different assets."); } - while(assetPubkeysCircuit.length < N_ASSET_PUBKEYS) { - assetPubkeysCircuit.push(new BN(0)) + while (assetPubkeysCircuit.length < N_ASSET_PUBKEYS) { + assetPubkeysCircuit.push(new BN(0)); } return { assetPubkeysCircuit, assetPubkeys }; @@ -489,13 +494,18 @@ constructor({ if (this.instance.provider && this.instance.solMerkleTree.merkleTree) { this.merkleTreeProgram = new Program( MerkleTreeProgram, - merkleTreeProgramId + merkleTreeProgramId, ); let root = Uint8Array.from( - leInt2Buff(unstringifyBigInts(this.instance.solMerkleTree.merkleTree.root()), 32) + leInt2Buff( + unstringifyBigInts(this.instance.solMerkleTree.merkleTree.root()), + 32, + ), ); let merkle_tree_account_data = - await this.merkleTreeProgram.account.merkleTree.fetch(this.instance.solMerkleTree.pubkey); + await this.merkleTreeProgram.account.merkleTree.fetch( + this.instance.solMerkleTree.pubkey, + ); merkle_tree_account_data.roots.map((x, index) => { if (x.toString() === root.toString()) { @@ -504,7 +514,7 @@ constructor({ }); } else { console.log( - "provider not defined did not fetch rootIndex set root index to 0" + "provider not defined did not fetch rootIndex set root index to 0", ); this.rootIndex = 0; } @@ -517,7 +527,7 @@ constructor({ } } else { throw new Error( - `input utxos ${utxos}, config ${this.params.verifier.config}` + `input utxos ${utxos}, config ${this.params.verifier.config}`, ); } return utxos; @@ -548,8 +558,8 @@ constructor({ (sum, utxo) => // add all utxos of the same asset sum.add(utxo.amounts[assetIndex]), - new anchor.BN(0) - ) + new anchor.BN(0), + ), ) .sub( this.params.inputUtxos @@ -561,14 +571,14 @@ constructor({ }) .reduce( (sum, utxo) => sum.add(utxo.amounts[assetIndex]), - new anchor.BN(0) - ) + new anchor.BN(0), + ), ) .add(FIELD_SIZE) .mod(FIELD_SIZE); } else { new Error( - `this.params.inputUtxos ${this.params.inputUtxos} && this.params.outputUtxos ${this.params.outputUtxos} && this.assetPubkeysCircuit ${this.assetPubkeysCircuit}` + `this.params.inputUtxos ${this.params.inputUtxos} && this.params.outputUtxos ${this.params.outputUtxos} && this.assetPubkeysCircuit ${this.assetPubkeysCircuit}`, ); } } @@ -577,12 +587,12 @@ constructor({ // TODO: make this work for edge case of two 2 different assets plus fee asset in the same transaction getIndices(utxos: Utxo[]): string[][][] { let inIndices: string[][][] = []; - + utxos.map((utxo) => { let tmpInIndices: String[][] = []; for (var a = 0; a < utxo.assets.length; a++) { let tmpInIndices1: String[] = []; - + for (var i = 0; i < N_ASSET_PUBKEYS; i++) { try { if ( @@ -598,7 +608,6 @@ constructor({ } catch (error) { tmpInIndices1.push("0"); } - } tmpInIndices.push(tmpInIndices1); } @@ -618,24 +627,25 @@ constructor({ inputUtxo.amounts[1] > new BN(0) ) { inputUtxo.index = this.instance.solMerkleTree.merkleTree.indexOf( - inputUtxo.getCommitment() + inputUtxo.getCommitment(), ); if (inputUtxo.index || inputUtxo.index == 0) { if (inputUtxo.index < 0) { throw new Error( - `Input commitment ${inputUtxo.getCommitment()} was not found` + `Input commitment ${inputUtxo.getCommitment()} was not found`, ); } this.inputMerklePathIndices.push(inputUtxo.index); this.inputMerklePathElements.push( - this.instance.solMerkleTree.merkleTree.path(inputUtxo.index).pathElements + this.instance.solMerkleTree.merkleTree.path(inputUtxo.index) + .pathElements, ); } } else { this.inputMerklePathIndices.push(0); this.inputMerklePathElements.push( - new Array(this.instance.solMerkleTree.merkleTree.levels).fill(0) + new Array(this.instance.solMerkleTree.merkleTree.levels).fill(0), ); } } @@ -648,7 +658,7 @@ constructor({ !this.relayer.relayerFee ) { throw new Error( - `getTxIntegrityHash: recipient ${this.params.accounts.recipient} recipientFee ${this.params.accounts.recipientFee} relayerFee ${this.relayer.relayerFee}` + `getTxIntegrityHash: recipient ${this.params.accounts.recipient} recipientFee ${this.params.accounts.recipientFee} relayerFee ${this.relayer.relayerFee}`, ); } else { this.encryptedUtxos = this.encryptOutUtxos(); @@ -678,7 +688,7 @@ constructor({ encryptedOutputs = Array.from(encryptedUtxos); } else { this.params.outputUtxos.map((utxo, index) => - encryptedOutputs.push(utxo.encrypt()) + encryptedOutputs.push(utxo.encrypt()), ); if (this.params.verifier.config.out == 2) { @@ -696,8 +706,8 @@ constructor({ if (tmpArray.length < 512) { tmpArray.push( new Array( - this.params.verifier.config.out * 128 - tmpArray.length - ).fill(0) + this.params.verifier.config.out * 128 - tmpArray.length, + ).fill(0), ); } return new Uint8Array(tmpArray.flat()); @@ -713,7 +723,7 @@ constructor({ ...bytes, ...this.encryptedUtxos.slice( offSet + bytes.length, - this.encryptedUtxos.length + this.encryptedUtxos.length, ), ]); } @@ -732,7 +742,7 @@ constructor({ await getAccount( this.instance.provider.connection, this.params.accounts.recipient, - TOKEN_PROGRAM_ID + TOKEN_PROGRAM_ID, ) ).amount; } catch (e) { @@ -740,49 +750,49 @@ constructor({ try { this.recipientBalancePriorTx = await this.instance.provider.connection.getBalance( - this.params.accounts.recipient + this.params.accounts.recipient, ); } catch (e) {} } try { this.recipientFeeBalancePriorTx = await this.instance.provider.connection.getBalance( - this.params.accounts.recipientFee + this.params.accounts.recipientFee, ); } catch (error) { console.log( "this.recipientFeeBalancePriorTx fetch failed ", - this.params.accounts.recipientFee + this.params.accounts.recipientFee, ); } this.senderFeeBalancePriorTx = await this.instance.provider.connection.getBalance( - this.params.accounts.senderFee + this.params.accounts.senderFee, ); this.relayerRecipientAccountBalancePriorLastTx = await this.instance.provider.connection.getBalance( - this.relayer.accounts.relayerRecipient + this.relayer.accounts.relayerRecipient, ); } static getSignerAuthorityPda( merkleTreeProgramId: PublicKey, - verifierProgramId: PublicKey + verifierProgramId: PublicKey, ) { return PublicKey.findProgramAddressSync( [merkleTreeProgramId.toBytes()], - verifierProgramId + verifierProgramId, )[0]; } static getRegisteredVerifierPda( merkleTreeProgramId: PublicKey, - verifierProgramId: PublicKey + verifierProgramId: PublicKey, ) { return PublicKey.findProgramAddressSync( [verifierProgramId.toBytes()], - merkleTreeProgramId + merkleTreeProgramId, )[0]; } @@ -814,11 +824,11 @@ constructor({ const lookupTableAccount = await this.instance.provider.connection.getAccountInfo( this.relayer.accounts.lookUpTable, - "confirmed" + "confirmed", ); const unpackedLookupTableAccount = AddressLookupTableAccount.deserialize( - lookupTableAccount.data + lookupTableAccount.data, ); const compiledTx = txMsg.compileToV0Message([ @@ -846,7 +856,7 @@ constructor({ res = await this.instance.provider.connection.sendRawTransaction( serializedTx, - confirmConfig + confirmConfig, ); retries = 0; console.log(res); @@ -874,7 +884,7 @@ constructor({ if (txTmp) { await this.instance.provider?.connection.confirmTransaction( txTmp, - "confirmed" + "confirmed", ); tx = txTmp; } else { @@ -888,20 +898,20 @@ constructor({ let publicSignals = [ leBuff2int(Buffer.from(this.publicInputs.root.reverse())).toString(), leBuff2int( - Buffer.from(this.publicInputs.publicAmount.reverse()) + Buffer.from(this.publicInputs.publicAmount.reverse()), ).toString(), leBuff2int( - Buffer.from(this.publicInputs.extDataHash.reverse()) + Buffer.from(this.publicInputs.extDataHash.reverse()), ).toString(), leBuff2int(Buffer.from(this.publicInputs.feeAmount.reverse())).toString(), leBuff2int( - Buffer.from(this.publicInputs.mintPubkey.reverse()) + Buffer.from(this.publicInputs.mintPubkey.reverse()), ).toString(), leBuff2int( - Buffer.from(this.publicInputs.nullifiers[0].reverse()) + Buffer.from(this.publicInputs.nullifiers[0].reverse()), ).toString(), leBuff2int( - Buffer.from(this.publicInputs.nullifiers[1].reverse()) + Buffer.from(this.publicInputs.nullifiers[1].reverse()), ).toString(), leBuff2int(Buffer.from(this.publicInputs.leaves[0].reverse())).toString(), leBuff2int(Buffer.from(this.publicInputs.leaves[1].reverse())).toString(), @@ -911,10 +921,10 @@ constructor({ let proof = { pi_a: [ leBuff2int( - Buffer.from(this.proofBytes.slice(0, 32).reverse()) + Buffer.from(this.proofBytes.slice(0, 32).reverse()), ).toString(), leBuff2int( - Buffer.from(this.proofBytes.slice(32, 64).reverse()) + Buffer.from(this.proofBytes.slice(32, 64).reverse()), ).toString(), "1", ], @@ -931,10 +941,10 @@ constructor({ ], pi_c: [ leBuff2int( - Buffer.from(this.proofBytes.slice(192, 224).reverse()) + Buffer.from(this.proofBytes.slice(192, 224).reverse()), ).toString(), leBuff2int( - Buffer.from(this.proofBytes.slice(224, 256).reverse()) + Buffer.from(this.proofBytes.slice(224, 256).reverse()), ).toString(), "1", ], @@ -943,7 +953,7 @@ constructor({ }; const vKey = await snarkjs.zKey.exportVerificationKey( - `${this.params.verifier.zkeyPath}.zkey` + `${this.params.verifier.zkeyPath}.zkey`, ); const res = await snarkjs.groth16.verify(vKey, publicSignals, proof); if (res === true) { @@ -967,7 +977,7 @@ constructor({ isWritable: true, pubkey: PublicKey.findProgramAddressSync( [Buffer.from(nullifiers[i]), anchor.utils.bytes.utf8.encode("nf")], - merkleTreeProgram.programId + merkleTreeProgram.programId, )[0], }); } @@ -982,27 +992,27 @@ constructor({ Buffer.from(Array.from(this.publicInputs.leaves[i][0]).reverse()), anchor.utils.bytes.utf8.encode("leaves"), ], - merkleTreeProgram.programId + merkleTreeProgram.programId, )[0], }); } this.params.accounts.escrow = PublicKey.findProgramAddressSync( [anchor.utils.bytes.utf8.encode("escrow")], - this.params.verifier.verifierProgram.programId + this.params.verifier.verifierProgram.programId, )[0]; this.params.accounts.verifierState = PublicKey.findProgramAddressSync( [signer.toBytes(), anchor.utils.bytes.utf8.encode("VERIFIER_STATE")], - this.params.verifier.verifierProgram.programId + this.params.verifier.verifierProgram.programId, )[0]; this.params.accounts.tokenAuthority = PublicKey.findProgramAddressSync( [anchor.utils.bytes.utf8.encode("spl")], - merkleTreeProgram.programId + merkleTreeProgram.programId, )[0]; } else { throw new Error( - `${this.params} && ${this.publicInputs} && ${this.merkleTreeProgram}` + `${this.params} && ${this.publicInputs} && ${this.merkleTreeProgram}`, ); } } @@ -1017,7 +1027,7 @@ constructor({ this.params.nullifierPdaPubkeys[i].pubkey, { commitment: "confirmed", - } + }, ); await checkRentExemption({ @@ -1031,23 +1041,23 @@ constructor({ for (var i in this.params.leavesPdaPubkeys) { leavesAccountData = await this.merkleTreeProgram.account.twoLeavesBytesPda.fetch( - this.params.leavesPdaPubkeys[i].pubkey + this.params.leavesPdaPubkeys[i].pubkey, ); assert( leavesAccountData.nodeLeft.toString() == this.publicInputs.leaves[i][0].reverse().toString(), - "left leaf not inserted correctly" + "left leaf not inserted correctly", ); assert( leavesAccountData.nodeRight.toString() == this.publicInputs.leaves[i][1].reverse().toString(), - "right leaf not inserted correctly" + "right leaf not inserted correctly", ); assert( leavesAccountData.merkleTreePubkey.toBase58() == this.instance.solMerkleTree.pubkey.toBase58(), - "merkleTreePubkey not inserted correctly" + "merkleTreePubkey not inserted correctly", ); for (var j = 0; j < this.encryptedUtxos.length / 256; j++) { @@ -1073,34 +1083,34 @@ constructor({ const utxoEqual = (utxo0: Utxo, utxo1: Utxo) => { assert.equal( utxo0.amounts[0].toString(), - utxo1.amounts[0].toString() + utxo1.amounts[0].toString(), ); assert.equal( utxo0.amounts[1].toString(), - utxo1.amounts[1].toString() + utxo1.amounts[1].toString(), ); assert.equal(utxo0.assets[0].toString(), utxo1.assets[0].toString()); assert.equal(utxo0.assets[1].toString(), utxo1.assets[1].toString()); assert.equal( utxo0.assetsCircuit[0].toString(), - utxo1.assetsCircuit[0].toString() + utxo1.assetsCircuit[0].toString(), ); assert.equal( utxo0.assetsCircuit[1].toString(), - utxo1.assetsCircuit[1].toString() + utxo1.assetsCircuit[1].toString(), ); assert.equal( utxo0.instructionType.toString(), - utxo1.instructionType.toString() + utxo1.instructionType.toString(), ); assert.equal(utxo0.poolType.toString(), utxo1.poolType.toString()); assert.equal( utxo0.verifierAddress.toString(), - utxo1.verifierAddress.toString() + utxo1.verifierAddress.toString(), ); assert.equal( utxo0.verifierAddressCircuit.toString(), - utxo1.verifierAddressCircuit.toString() + utxo1.verifierAddressCircuit.toString(), ); }; // console.log("decryptedUtxo ", decryptedUtxo1); @@ -1115,28 +1125,28 @@ constructor({ try { var preInsertedLeavesIndexAccount = await this.instance.provider.connection.getAccountInfo( - PRE_INSERTED_LEAVES_INDEX + PRE_INSERTED_LEAVES_INDEX, ); const preInsertedLeavesIndexAccountAfterUpdate = this.merkleTreeProgram.account.preInsertedLeavesIndex._coder.accounts.decode( "PreInsertedLeavesIndex", - preInsertedLeavesIndexAccount.data + preInsertedLeavesIndexAccount.data, ); console.log( "Number(preInsertedLeavesIndexAccountAfterUpdate.nextIndex) ", - Number(preInsertedLeavesIndexAccountAfterUpdate.nextIndex) + Number(preInsertedLeavesIndexAccountAfterUpdate.nextIndex), ); console.log( `${Number(leavesAccountData.leftLeafIndex)} + ${ this.params.leavesPdaPubkeys.length * 2 - }` + }`, ); assert( Number(preInsertedLeavesIndexAccountAfterUpdate.nextIndex) == Number(leavesAccountData.leftLeafIndex) + - this.params.leavesPdaPubkeys.length * 2 + this.params.leavesPdaPubkeys.length * 2, ); } catch (e) { console.log("preInsertedLeavesIndex: ", e); @@ -1145,14 +1155,14 @@ constructor({ if (this.action == "DEPOSIT" && this.is_token == false) { var recipientAccount = await this.instance.provider.connection.getAccountInfo( - this.params.accounts.recipient + this.params.accounts.recipient, ); assert( recipientAccount.lamports == I64(this.recipientBalancePriorTx) .add(this.publicAmount.toString()) .toString(), - "amount not transferred correctly" + "amount not transferred correctly", ); } else if (this.action == "DEPOSIT" && this.is_token == true) { console.log("DEPOSIT and token"); @@ -1160,84 +1170,84 @@ constructor({ var recipientAccount = await getAccount( this.instance.provider.connection, this.params.accounts.recipient, - TOKEN_PROGRAM_ID + TOKEN_PROGRAM_ID, ); var recipientFeeAccountBalance = await this.instance.provider.connection.getBalance( - this.params.accounts.recipientFee + this.params.accounts.recipientFee, ); // console.log(`Balance now ${senderAccount.amount} balance beginning ${senderAccountBalancePriorLastTx}`) // assert(senderAccount.lamports == (I64(senderAccountBalancePriorLastTx) - I64.readLE(this.extAmount, 0)).toString(), "amount not transferred correctly"); console.log( - `Balance now ${recipientAccount.amount} balance beginning ${this.recipientBalancePriorTx}` + `Balance now ${recipientAccount.amount} balance beginning ${this.recipientBalancePriorTx}`, ); console.log( `Balance now ${recipientAccount.amount} balance beginning ${ Number(this.recipientBalancePriorTx) + Number(this.publicAmount) - }` + }`, ); assert( recipientAccount.amount == ( Number(this.recipientBalancePriorTx) + Number(this.publicAmount) ).toString(), - "amount not transferred correctly" + "amount not transferred correctly", ); console.log( `Blanace now ${recipientFeeAccountBalance} ${ Number(this.recipientFeeBalancePriorTx) + Number(this.feeAmount) - }` + }`, ); console.log("fee amount: ", this.feeAmount); console.log( "fee amount from inputs. ", - new anchor.BN(this.publicInputs.feeAmount.slice(24, 32)).toString() + new anchor.BN(this.publicInputs.feeAmount.slice(24, 32)).toString(), ); console.log( "pub amount from inputs. ", - new anchor.BN(this.publicInputs.publicAmount.slice(24, 32)).toString() + new anchor.BN(this.publicInputs.publicAmount.slice(24, 32)).toString(), ); console.log( "recipientFeeBalancePriorTx: ", - this.recipientFeeBalancePriorTx + this.recipientFeeBalancePriorTx, ); var senderFeeAccountBalance = await this.instance.provider.connection.getBalance( - this.params.accounts.senderFee + this.params.accounts.senderFee, ); console.log("senderFeeAccountBalance: ", senderFeeAccountBalance); console.log( "this.senderFeeBalancePriorTx: ", - this.senderFeeBalancePriorTx + this.senderFeeBalancePriorTx, ); assert( recipientFeeAccountBalance == - Number(this.recipientFeeBalancePriorTx) + Number(this.feeAmount) + Number(this.recipientFeeBalancePriorTx) + Number(this.feeAmount), ); console.log( `${Number(this.senderFeeBalancePriorTx)} - ${Number( - this.feeAmount - )} == ${senderFeeAccountBalance}` + this.feeAmount, + )} == ${senderFeeAccountBalance}`, ); assert( Number(this.senderFeeBalancePriorTx) - Number(this.feeAmount) - 5000 * this.params.verifier.instructions?.length == - Number(senderFeeAccountBalance) + Number(senderFeeAccountBalance), ); } else if (this.action == "WITHDRAWAL" && this.is_token == false) { var senderAccount = await this.instance.provider.connection.getAccountInfo( - this.params.accounts.sender + this.params.accounts.sender, ); var recipientAccount = await this.instance.provider.connection.getAccountInfo( - this.params.accounts.recipient + this.params.accounts.recipient, ); // console.log("senderAccount.lamports: ", senderAccount.lamports) // console.log("I64(senderAccountBalancePriorLastTx): ", I64(senderAccountBalancePriorLastTx).toString()) @@ -1249,7 +1259,7 @@ constructor({ .add(I64.readLE(this.extAmount, 0)) .sub(I64(relayerFee)) .toString(), - "amount not transferred correctly" + "amount not transferred correctly", ); var recipientAccount = @@ -1261,53 +1271,53 @@ constructor({ I64(Number(this.recipientBalancePriorTx)) .sub(I64.readLE(this.extAmount, 0)) .toString(), - "amount not transferred correctly" + "amount not transferred correctly", ); } else if (this.action == "WITHDRAWAL" && this.is_token == true) { var senderAccount = await getAccount( this.instance.provider.connection, this.params.accounts.sender, - TOKEN_PROGRAM_ID + TOKEN_PROGRAM_ID, ); var recipientAccount = await getAccount( this.instance.provider.connection, this.params.accounts.recipient, - TOKEN_PROGRAM_ID + TOKEN_PROGRAM_ID, ); // assert(senderAccount.amount == ((I64(Number(senderAccountBalancePriorLastTx)).add(I64.readLE(this.extAmount, 0))).sub(I64(relayerFee))).toString(), "amount not transferred correctly"); console.log( "this.recipientBalancePriorTx ", - this.recipientBalancePriorTx + this.recipientBalancePriorTx, ); console.log("this.publicAmount ", this.publicAmount); console.log( "this.publicAmount ", - this.publicAmount?.sub(FIELD_SIZE).mod(FIELD_SIZE) + this.publicAmount?.sub(FIELD_SIZE).mod(FIELD_SIZE), ); console.log( `${recipientAccount.amount}, ${new anchor.BN( - this.recipientBalancePriorTx + this.recipientBalancePriorTx, ) .sub(this.publicAmount?.sub(FIELD_SIZE).mod(FIELD_SIZE)) - .toString()}` + .toString()}`, ); assert.equal( recipientAccount.amount.toString(), new anchor.BN(this.recipientBalancePriorTx) .sub(this.publicAmount?.sub(FIELD_SIZE).mod(FIELD_SIZE)) .toString(), - "amount not transferred correctly" + "amount not transferred correctly", ); var relayerAccount = await this.instance.provider.connection.getBalance( - this.relayer.accounts.relayerRecipient + this.relayer.accounts.relayerRecipient, ); var recipientFeeAccount = await this.instance.provider.connection.getBalance( - this.params.accounts.recipientFee + this.params.accounts.recipientFee, ); // console.log("recipientFeeAccount ", recipientFeeAccount); // console.log("this.feeAmount: ", this.feeAmount); @@ -1322,31 +1332,31 @@ constructor({ .add(new anchor.BN("5000")) .toString()} == ${new anchor.BN(this.recipientFeeBalancePriorTx) .sub(this.feeAmount?.sub(FIELD_SIZE).mod(FIELD_SIZE)) - .toString()}` + .toString()}`, ); // console.log("relayerAccount ", relayerAccount); // console.log("this.relayer.relayerFee: ", this.relayer.relayerFee); console.log( "relayerRecipientAccountBalancePriorLastTx ", - this.relayerRecipientAccountBalancePriorLastTx + this.relayerRecipientAccountBalancePriorLastTx, ); console.log( `relayerFeeAccount ${new anchor.BN(relayerAccount) .sub(this.relayer.relayerFee) .toString()} == ${new anchor.BN( - this.relayerRecipientAccountBalancePriorLastTx - )}` + this.relayerRecipientAccountBalancePriorLastTx, + )}`, ); console.log( `relayerAccount ${new anchor.BN( - relayerAccount + relayerAccount, ).toString()} == ${new anchor.BN( - this.relayerRecipientAccountBalancePriorLastTx + this.relayerRecipientAccountBalancePriorLastTx, ) .sub(new anchor.BN(this.relayer.relayerFee)) - .toString()}` + .toString()}`, ); console.log( @@ -1354,7 +1364,7 @@ constructor({ .add(new anchor.BN(this.relayer.relayerFee.toString())) .toString()} == ${new anchor.BN(this.recipientFeeBalancePriorTx) .sub(this.feeAmount?.sub(FIELD_SIZE).mod(FIELD_SIZE)) - .toString()}` + .toString()}`, ); assert.equal( @@ -1363,7 +1373,7 @@ constructor({ .toString(), new anchor.BN(this.recipientFeeBalancePriorTx) .sub(this.feeAmount?.sub(FIELD_SIZE).mod(FIELD_SIZE)) - .toString() + .toString(), ); // console.log(`this.relayer.relayerFee ${this.relayer.relayerFee} new anchor.BN(relayerAccount) ${new anchor.BN(relayerAccount)}`); @@ -1372,7 +1382,7 @@ constructor({ .sub(this.relayer.relayerFee) // .add(new anchor.BN("5000")) .toString(), - this.relayerRecipientAccountBalancePriorLastTx?.toString() + this.relayerRecipientAccountBalancePriorLastTx?.toString(), ); } else { throw Error("mode not supplied"); @@ -1407,35 +1417,33 @@ constructor({ } // also converts lE to BE - static async parseProofToBytesArray (data: any) { - var mydata = JSON.parse(data.toString()); - - for (var i in mydata) { - if (i == "pi_a" || i == "pi_c") { - for (var j in mydata[i]) { - mydata[i][j] = Array.from( - leInt2Buff(unstringifyBigInts(mydata[i][j]), 32) - ).reverse(); - } - } else if (i == "pi_b") { - for (var j in mydata[i]) { - for (var z in mydata[i][j]) { - mydata[i][j][z] = Array.from( - leInt2Buff(unstringifyBigInts(mydata[i][j][z]), 32) - ); + static async parseProofToBytesArray(data: any) { + var mydata = JSON.parse(data.toString()); + + for (var i in mydata) { + if (i == "pi_a" || i == "pi_c") { + for (var j in mydata[i]) { + mydata[i][j] = Array.from( + leInt2Buff(unstringifyBigInts(mydata[i][j]), 32), + ).reverse(); + } + } else if (i == "pi_b") { + for (var j in mydata[i]) { + for (var z in mydata[i][j]) { + mydata[i][j][z] = Array.from( + leInt2Buff(unstringifyBigInts(mydata[i][j][z]), 32), + ); + } } } } + return [ + mydata.pi_a[0], + mydata.pi_a[1], + mydata.pi_b[0].flat().reverse(), + mydata.pi_b[1].flat().reverse(), + mydata.pi_c[0], + mydata.pi_c[1], + ].flat(); } - return [ - mydata.pi_a[0], - mydata.pi_a[1], - mydata.pi_b[0].flat().reverse(), - mydata.pi_b[1].flat().reverse(), - mydata.pi_c[0], - mydata.pi_c[1], - ].flat(); -}; } - - diff --git a/light-sdk-ts/src/utils.ts b/light-sdk-ts/src/utils.ts index 8c9573ddb0..1bff2ddd63 100644 --- a/light-sdk-ts/src/utils.ts +++ b/light-sdk-ts/src/utils.ts @@ -13,7 +13,7 @@ export function hashAndTruncateToCircuit(data: Uint8Array) { .digest() .slice(1, 32), undefined, - "be" + "be", ); } @@ -35,7 +35,7 @@ export async function getAssetLookUpId({ let registeredAssets = await mtConf.merkleTreeProgram.account.registeredAssetPool.fetch( - pubkey.pda + pubkey.pda, ); return registeredAssets.index; } diff --git a/light-sdk-ts/src/utxo.ts b/light-sdk-ts/src/utxo.ts index 52680a56ca..0ba3f4ac8b 100644 --- a/light-sdk-ts/src/utxo.ts +++ b/light-sdk-ts/src/utxo.ts @@ -154,7 +154,7 @@ export class Utxo { } else { this.verifierAddress = new BN(verifierAddress.toBytes()); this.verifierAddressCircuit = hashAndTruncateToCircuit( - verifierAddress.toBytes() + verifierAddress.toBytes(), ); } } @@ -280,7 +280,7 @@ export class Utxo { if (!this._commitment) { let amountHash = this.poseidon.F.toString(this.poseidon(this.amounts)); let assetHash = this.poseidon.F.toString( - this.poseidon(this.assetsCircuit) + this.poseidon(this.assetsCircuit), ); // console.log("amountHash ", amountHash.toString()); @@ -299,7 +299,7 @@ export class Utxo { this.instructionType.toString(), this.poolType, this.verifierAddressCircuit, - ]) + ]), ); } return this._commitment; @@ -321,7 +321,7 @@ export class Utxo { this.keypair.privkey === null) ) { throw new Error( - "Can not compute nullifier without utxo index or private key" + "Can not compute nullifier without utxo index or private key", ); } @@ -333,7 +333,7 @@ export class Utxo { // console.log("signature ", signature); this._nullifier = this.poseidon.F.toString( - this.poseidon([this.getCommitment(), this.index || 0, signature]) + this.poseidon([this.getCommitment(), this.index || 0, signature]), ); } // console.log("this._nullifier ", this._nullifier); @@ -358,7 +358,7 @@ export class Utxo { bytes_message, nonce, this.keypair.encryptionPublicKey, - CONSTANT_SECRET_AUTHKEY + CONSTANT_SECRET_AUTHKEY, ); return new Uint8Array([...ciphertext, ...nonce]); @@ -382,7 +382,7 @@ export class Utxo { encryptedUtxo, nonce, nacl.box.keyPair.fromSecretKey(CONSTANT_SECRET_AUTHKEY).publicKey, - keypair.encPrivateKey + keypair.encPrivateKey, ); if (!cleartext) { return null; diff --git a/light-sdk-ts/src/verifiers/index.ts b/light-sdk-ts/src/verifiers/index.ts index 60ca9dbdc0..1c8317877a 100644 --- a/light-sdk-ts/src/verifiers/index.ts +++ b/light-sdk-ts/src/verifiers/index.ts @@ -38,6 +38,6 @@ export interface Verifier { instructions?: web3.TransactionInstruction[]; parsePublicInputsFromArray(transaction: Transaction): PublicInputs; getInstructions( - transaction: Transaction + transaction: Transaction, ): Promise; } diff --git a/light-sdk-ts/src/verifiers/verifierOne.ts b/light-sdk-ts/src/verifiers/verifierOne.ts index 6b7bcf62d8..5e01e8bac1 100644 --- a/light-sdk-ts/src/verifiers/verifierOne.ts +++ b/light-sdk-ts/src/verifiers/verifierOne.ts @@ -18,11 +18,12 @@ export class VerifierOne implements Verifier { instructions?: anchor.web3.TransactionInstruction[]; constructor() { - try {this.verifierProgram = new Program( - VerifierProgramOne, - verifierProgramOneProgramId - ); - } catch(e) {} + try { + this.verifierProgram = new Program( + VerifierProgramOne, + verifierProgramOneProgramId, + ); + } catch (e) {} this.wtnsGenPath = "./build-circuits/transactionMasp10_js/transactionMasp10"; this.zkeyPath = "./build-circuits/transactionMasp10"; @@ -52,7 +53,7 @@ export class VerifierOne implements Verifier { } async getInstructions( - transaction: Transaction + transaction: Transaction, ): Promise { if ( transaction.params && @@ -70,7 +71,7 @@ export class VerifierOne implements Verifier { Buffer.from(transaction.publicInputs.feeAmount), new anchor.BN(transaction.rootIndex.toString()), new anchor.BN(transaction.relayer.relayerFee.toString()), - Buffer.from(transaction.encryptedUtxos) + Buffer.from(transaction.encryptedUtxos), ) .accounts({ ...transaction.params.accounts, @@ -94,7 +95,7 @@ export class VerifierOne implements Verifier { return this.instructions; } else { throw new Error( - "transaction.params, nullifierPdaPubkeys or leavesPdaPubkeys undefined" + "transaction.params, nullifierPdaPubkeys or leavesPdaPubkeys undefined", ); } } diff --git a/light-sdk-ts/src/verifiers/verifierTwo.ts b/light-sdk-ts/src/verifiers/verifierTwo.ts index 678427ad14..a634abce3f 100644 --- a/light-sdk-ts/src/verifiers/verifierTwo.ts +++ b/light-sdk-ts/src/verifiers/verifierTwo.ts @@ -36,7 +36,7 @@ export class VerifierTwo implements Verifier { constructor() { this.verifierProgram = new Program( VerifierProgramTwo, - verifierProgramTwoProgramId + verifierProgramTwoProgramId, ); this.wtnsGenPath = "./build-circuits/transactionMasp2_js/transactionMasp2"; @@ -59,7 +59,7 @@ export class VerifierTwo implements Verifier { checkedParams: Array.from(transaction.publicInputsBytes.slice(5, 9)), nullifiers: Array.from(transaction.publicInputsBytes.slice(9, 13)), leaves: Array.from( - transaction.publicInputsBytes.slice(13, this.nrPublicInputs) + transaction.publicInputsBytes.slice(13, this.nrPublicInputs), ), }; } else { @@ -70,7 +70,7 @@ export class VerifierTwo implements Verifier { initVerifierProgram(): void { this.verifierProgram = new Program( VerifierProgramTwo, - verifierProgramTwoProgramId + verifierProgramTwoProgramId, ); } diff --git a/light-sdk-ts/src/verifiers/verifierZero.ts b/light-sdk-ts/src/verifiers/verifierZero.ts index 063361cc6f..85b111b447 100644 --- a/light-sdk-ts/src/verifiers/verifierZero.ts +++ b/light-sdk-ts/src/verifiers/verifierZero.ts @@ -21,11 +21,9 @@ export class VerifierZero implements Verifier { try { this.verifierProgram = new Program( VerifierProgramZero, - verifierProgramZeroProgramId + verifierProgramZeroProgramId, ); - } catch (error) { - - } + } catch (error) {} this.wtnsGenPath = "./build-circuits/transactionMasp2_js/transactionMasp2"; this.zkeyPath = `./build-circuits/transactionMasp2`; @@ -62,7 +60,7 @@ export class VerifierZero implements Verifier { } async getInstructions( - transaction: Transaction + transaction: Transaction, ): Promise { if ( transaction.params && @@ -82,7 +80,7 @@ export class VerifierZero implements Verifier { Buffer.from(transaction.publicInputs.feeAmount), new anchor.BN(transaction.rootIndex.toString()), new anchor.BN(transaction.relayer.relayerFee.toString()), - Buffer.from(transaction.encryptedUtxos.slice(0, 190)) // remaining bytes can be used once tx sizes increase + Buffer.from(transaction.encryptedUtxos.slice(0, 190)), // remaining bytes can be used once tx sizes increase ) .accounts({ ...transaction.params.accounts, @@ -97,7 +95,7 @@ export class VerifierZero implements Verifier { return [ix]; } else { throw new Error( - "transaction.params, nullifierPdaPubkeys or leavesPdaPubkeys undefined" + "transaction.params, nullifierPdaPubkeys or leavesPdaPubkeys undefined", ); } } diff --git a/light-sdk-ts/src/wallet/buildBalance.ts b/light-sdk-ts/src/wallet/buildBalance.ts index c2e02a2341..effd587fa0 100644 --- a/light-sdk-ts/src/wallet/buildBalance.ts +++ b/light-sdk-ts/src/wallet/buildBalance.ts @@ -1,6 +1,6 @@ import { Utxo } from "../utxo"; import * as anchor from "@coral-xyz/anchor"; -import { PublicKey} from "@solana/web3.js"; +import { PublicKey } from "@solana/web3.js"; export async function getUnspentUtxo( leavesPdas, @@ -10,7 +10,7 @@ export async function getUnspentUtxo( FEE_ASSET, mint, POSEIDON, - merkleTreeProgram: MerkleTreeProgram + merkleTreeProgram: MerkleTreeProgram, ) { let decryptedUtxo1; for (var i = 0; i < leavesPdas.length; i++) { @@ -20,7 +20,7 @@ export async function getUnspentUtxo( decryptedUtxo1 = Utxo.decrypt({ poseidon: POSEIDON, encBytes: new Uint8Array( - Array.from(leavesPdas[i].account.encryptedUtxos) + Array.from(leavesPdas[i].account.encryptedUtxos), ), keypair: KEYPAIR, }); @@ -33,11 +33,11 @@ export async function getUnspentUtxo( new anchor.BN(nullifier.toString()).toBuffer(), anchor.utils.bytes.utf8.encode("nf"), ], - merkleTreeProgram.programId + merkleTreeProgram.programId, ) )[0]; let accountInfo = await provider.connection.getAccountInfo( - nullifierPubkey + nullifierPubkey, ); if ( @@ -55,4 +55,3 @@ export async function getUnspentUtxo( } } } - diff --git a/light-sdk-ts/src/wallet/user.ts b/light-sdk-ts/src/wallet/user.ts index eeb20e5bfb..27a89670ff 100644 --- a/light-sdk-ts/src/wallet/user.ts +++ b/light-sdk-ts/src/wallet/user.ts @@ -21,7 +21,7 @@ export class User { // Fetch utxos should probably be a function such the user object is not occupied while fetching // but it would probably be more logical to fetch utxos here as well addUtxos() {} - + // TODO: evaluate where do we create outUtxos? selectUtxos(amount) {} @@ -37,7 +37,6 @@ export class User { appInteraction() {} - /* * *return { From bd53e5bad656c38d601bb775d6c8ebfdc6948903 Mon Sep 17 00:00:00 2001 From: Swen Date: Sat, 14 Jan 2023 12:48:05 +0000 Subject: [PATCH 3/3] updated readme --- README.md | 35 +++++++++++++++++++++-------------- light-sdk-ts/husky/pre-commit | 2 +- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index f131ac96c2..0b5b884a95 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,16 @@ # Light Protocol Program V3 +## Setup + +- In order to properly execute the prettier format pre-commit hook, you may first need to configure light-sdk-ts/husky/pre-commit as executable: +- `chmod ug+x ./light-sdk-ts/husky/* ` + ## Tests -*Requirements:* +_Requirements:_ + - solana cli v1.11.10 or higher - - ``sh -c "$(curl -sSfL https://release.solana.com/v1.11.10/install)"`` + - `sh -c "$(curl -sSfL https://release.solana.com/v1.11.10/install)"` - clone of [solana](), checked out on `master` branch (the `alt_bn128` syscall is not released yet) - to be sure that no recent changes can break the workflow, you can check out commit @@ -13,23 +19,25 @@ - `git checkout 656b150e575a4d16cfa9c9ff63b16edcf94f2e0d` - anchor cli https://project-serum.github.io/anchor/getting-started/installation.html - - ``npm i -g @project-serum/anchor-cli`` + - `npm i -g @project-serum/anchor-cli` - node v14 -*Unit Tests:* -- ``cd anchor_programs/`` -- ``cargo test`` -- ``cd groth16-solana/`` -- ``cargo test`` -- ``cd light-verifier-sdk/`` -- ``cargo test`` +_Unit Tests:_ -*Anchor tests:* +- `cd anchor_programs/` +- `cargo test` +- `cd groth16-solana/` +- `cargo test` +- `cd light-verifier-sdk/` +- `cargo test` + +_Anchor tests:_ Tests are located in tests/ and will take several minutes to complete. Several tests are skipped to decrease the overall testing time. By default a deposit merkle tree update and withdrawal are executed with random values for deposits and fees. It is recommended to restart the validator before rerunning tests. Further tests are: + - Initialize Merkle Tree Test tests the configuration instructions and merkle tree initialization - Deposit 10 utxos @@ -39,7 +47,7 @@ Further tests are: - Withdraw 10 utxos tests and runs a withdrawal with 10 input utxos -- ``npm install`` +- `npm install` - Assuming that your clones of `solana` and `light-protocol-onchain` git repoitories share the same parent directory and you are currently in the @@ -55,7 +63,6 @@ Further tests are: --bpf-program 3KS2k14CmtnuVv2fvYcvdrNgC94Y11WETBpMUGgXyWZL ./light-system-programs/target/deploy/verifier_program_one.so ``` -- ``anchor test --skip-build --skip-deploy --skip-local-validator`` - +- `anchor test --skip-build --skip-deploy --skip-local-validator` Check logs in anchor_programs/.anchor/program-logs diff --git a/light-sdk-ts/husky/pre-commit b/light-sdk-ts/husky/pre-commit index 18ca502898..12799c4280 100755 --- a/light-sdk-ts/husky/pre-commit +++ b/light-sdk-ts/husky/pre-commit @@ -2,5 +2,5 @@ . "$(dirname "$0")/_/husky.sh" cd light-sdk-ts npm run format -exit 1 # Commit will be aborted +# exit 1