@arcium-hq/client 0.6.2 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.cjs CHANGED
@@ -499,7 +499,11 @@ function randMatrix(field, nrows, ncols) {
499
499
  /**
500
500
  * Curve25519 base field as an IField instance.
501
501
  */
502
- const CURVE25519_BASE_FIELD = ed25519.ed25519.CURVE.Fp;
502
+ const CURVE25519_BASE_FIELD = ed25519.ed25519.Point.Fp;
503
+ /**
504
+ * Curve25519 scalar field as an IField instance.
505
+ */
506
+ const CURVE25519_SCALAR_FIELD = ed25519.ed25519.Point.Fn;
503
507
  // Security level for the block cipher.
504
508
  const SECURITY_LEVEL_BLOCK_CIPHER = 128;
505
509
  // Security level for the hash function.
@@ -895,8 +899,8 @@ class RescuePrimeHash {
895
899
  /**
896
900
  * Constructs a RescuePrimeHash instance with rate = 7 and capacity = 5.
897
901
  */
898
- constructor() {
899
- this.desc = new RescueDesc(CURVE25519_BASE_FIELD, { kind: 'hash', m: 12, capacity: 5 });
902
+ constructor(field) {
903
+ this.desc = new RescueDesc(field, { kind: 'hash', m: 12, capacity: 5 });
900
904
  this.rate = 7;
901
905
  this.digestLength = 5;
902
906
  }
@@ -950,15 +954,32 @@ const RESCUE_CIPHER_BLOCK_SIZE = 5;
950
954
  * The Rescue cipher in Counter (CTR) mode, with a fixed block size m = 5.
951
955
  * See: https://tosc.iacr.org/index.php/ToSC/article/view/8695/8287
952
956
  */
953
- class RescueCipher {
957
+ class RescueCipherCommon {
954
958
  desc;
955
959
  /**
956
- * Constructs a RescueCipher instance using a shared secret.
960
+ * Constructs a RescueCipherCommon instance using a shared secret.
957
961
  * The key is derived using RescuePrimeHash and used to initialize the RescueDesc.
958
962
  * @param sharedSecret - The shared secret to derive the cipher key from.
959
963
  */
960
- constructor(sharedSecret) {
961
- const hasher = new RescuePrimeHash();
964
+ constructor(sharedSecret, field) {
965
+ if (sharedSecret.length != 32) {
966
+ throw Error(`sharedSecret must be of length 32 (found ${sharedSecret.length})`);
967
+ }
968
+ const hasher = new RescuePrimeHash(field);
969
+ // In case `field` is different from CURVE25519_BASE_FIELD we need to injectively map sharedSecret
970
+ // to a vector of elements over `field`.
971
+ const converted = [];
972
+ if (field === CURVE25519_BASE_FIELD) {
973
+ converted.push(deserializeLE(sharedSecret));
974
+ }
975
+ else {
976
+ // We chunk sharedSecret by field.BYTES - 1 and convert.
977
+ const chunkSize = field.BYTES - 1;
978
+ const nChunks = Math.ceil(sharedSecret.length / chunkSize);
979
+ for (let i = 0; i < nChunks; ++i) {
980
+ converted.push(deserializeLE(sharedSecret.slice(i * chunkSize, (i + 1) * chunkSize)));
981
+ }
982
+ }
962
983
  // We follow [Section 4, Option 1.](https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-56Cr2.pdf).
963
984
  // For our choice of hash function, we have:
964
985
  // - H_outputBits = hasher.digestLength = RESCUE_CIPHER_BLOCK_SIZE
@@ -967,9 +988,9 @@ class RescueCipher {
967
988
  // - L = RESCUE_CIPHER_BLOCK_SIZE.
968
989
  // Build the vector `counter || Z || FixedInfo` (we only have i = 1, since reps = 1).
969
990
  // For the FixedInfo we simply take L.
970
- const counter = [1n, deserializeLE(sharedSecret), BigInt(RESCUE_CIPHER_BLOCK_SIZE)];
991
+ const counter = [1n, ...converted, BigInt(RESCUE_CIPHER_BLOCK_SIZE)];
971
992
  const rescueKey = hasher.digest(counter);
972
- this.desc = new RescueDesc(CURVE25519_BASE_FIELD, { kind: 'cipher', key: rescueKey });
993
+ this.desc = new RescueDesc(field, { kind: 'cipher', key: rescueKey });
973
994
  }
974
995
  /**
975
996
  * Encrypts the plaintext vector in Counter (CTR) mode (raw, returns bigints).
@@ -991,7 +1012,7 @@ class RescueCipher {
991
1012
  const ciphertext = [];
992
1013
  for (let i = 0; i < ptxt.length; ++i) {
993
1014
  if (!verifyBinSize(ptxt[i], binSize - 1n) || ctSignBit(ptxt[i], binSize) || !ctLt(ptxt[i], desc.field.ORDER, binSize)) {
994
- throw Error(`plaintext must be non-negative and at most ${desc.field.ORDER}`);
1015
+ throw Error(`plaintext must be non-negative and less than ${desc.field.ORDER}`);
995
1016
  }
996
1017
  const sum = ctAdd(ptxt[i], encryptedCounter.data[i][0], binSize);
997
1018
  ciphertext.push(ctSelect(ctLt(sum, desc.field.ORDER, binSize), sum, ctSub(sum, desc.field.ORDER, binSize), binSize));
@@ -1089,6 +1110,74 @@ function getCounter(nonce, nBlocks) {
1089
1110
  return counter;
1090
1111
  }
1091
1112
 
1113
+ /**
1114
+ * The Rescue cipher over Curve25519's base field in Counter (CTR) mode, with a fixed block size m = 5.
1115
+ * See: https://tosc.iacr.org/index.php/ToSC/article/view/8695/8287
1116
+ */
1117
+ class RescueCipher {
1118
+ cipher;
1119
+ /**
1120
+ * Constructs a RescueCipher instance using a shared secret.
1121
+ * The key is derived using RescuePrimeHash and used to initialize the RescueDesc.
1122
+ * @param sharedSecret - The shared secret to derive the cipher key from.
1123
+ */
1124
+ constructor(sharedSecret) {
1125
+ this.cipher = new RescueCipherCommon(sharedSecret, CURVE25519_BASE_FIELD);
1126
+ }
1127
+ /**
1128
+ * Encrypts the plaintext vector in Counter (CTR) mode and serializes each block.
1129
+ * @param plaintext - The array of plaintext bigints to encrypt.
1130
+ * @param nonce - A 16-byte nonce for CTR mode.
1131
+ * @returns The ciphertext as an array of arrays of numbers (each 32 bytes).
1132
+ */
1133
+ encrypt(plaintext, nonce) {
1134
+ return this.cipher.encrypt(plaintext, nonce);
1135
+ }
1136
+ /**
1137
+ * Deserializes and decrypts the ciphertext vector in Counter (CTR) mode.
1138
+ * @param ciphertext - The array of arrays of numbers (each 32 bytes) to decrypt.
1139
+ * @param nonce - A 16-byte nonce for CTR mode.
1140
+ * @returns The decrypted plaintext as an array of bigints.
1141
+ */
1142
+ decrypt(ciphertext, nonce) {
1143
+ return this.cipher.decrypt(ciphertext, nonce);
1144
+ }
1145
+ }
1146
+
1147
+ /**
1148
+ * The Rescue cipher over Curve25519's scalar field in Counter (CTR) mode, with a fixed block size m = 5.
1149
+ * See: https://tosc.iacr.org/index.php/ToSC/article/view/8695/8287
1150
+ */
1151
+ class CSplRescueCipher {
1152
+ cipher;
1153
+ /**
1154
+ * Constructs a RescueCipher instance using a shared secret.
1155
+ * The key is derived using RescuePrimeHash and used to initialize the RescueDesc.
1156
+ * @param sharedSecret - The shared secret to derive the cipher key from.
1157
+ */
1158
+ constructor(sharedSecret) {
1159
+ this.cipher = new RescueCipherCommon(sharedSecret, CURVE25519_SCALAR_FIELD);
1160
+ }
1161
+ /**
1162
+ * Encrypts the plaintext vector in Counter (CTR) mode and serializes each block.
1163
+ * @param plaintext - The array of plaintext bigints to encrypt.
1164
+ * @param nonce - A 16-byte nonce for CTR mode.
1165
+ * @returns The ciphertext as an array of arrays of numbers (each 32 bytes).
1166
+ */
1167
+ encrypt(plaintext, nonce) {
1168
+ return this.cipher.encrypt(plaintext, nonce);
1169
+ }
1170
+ /**
1171
+ * Deserializes and decrypts the ciphertext vector in Counter (CTR) mode.
1172
+ * @param ciphertext - The array of arrays of numbers (each 32 bytes) to decrypt.
1173
+ * @param nonce - A 16-byte nonce for CTR mode.
1174
+ * @returns The decrypted plaintext as an array of bigints.
1175
+ */
1176
+ decrypt(ciphertext, nonce) {
1177
+ return this.cipher.decrypt(ciphertext, nonce);
1178
+ }
1179
+ }
1180
+
1092
1181
  // The arcisEd25519 signature scheme. This is essentially ed25519 but we use the hash function
1093
1182
  // SHA3-512 instead of SHA-512 since its multiplicative depth is much lower, which
1094
1183
  // makes it much better suited to be evaluated in MPC.
@@ -1720,7 +1809,7 @@ function createPacker(fields, typeName = 'Packer') {
1720
1809
  var address = "Arcj82pX7HxYKLR92qvgZUAd7vGS1k4hQvAFcPATFdEQ";
1721
1810
  var metadata = {
1722
1811
  name: "arcium",
1723
- version: "0.6.2",
1812
+ version: "0.6.3",
1724
1813
  spec: "0.1.0",
1725
1814
  description: "The Arcium program"
1726
1815
  };
@@ -2808,6 +2897,10 @@ var instructions = [
2808
2897
  {
2809
2898
  name: "mxe_program",
2810
2899
  type: "pubkey"
2900
+ },
2901
+ {
2902
+ name: "output_len_bytes",
2903
+ type: "u32"
2811
2904
  }
2812
2905
  ]
2813
2906
  },
@@ -3582,6 +3675,55 @@ var instructions = [
3582
3675
  }
3583
3676
  ]
3584
3677
  }
3678
+ },
3679
+ {
3680
+ name: "comp_def_raw",
3681
+ docs: [
3682
+ "At least the first raw circuit account must exist before finalizing"
3683
+ ],
3684
+ pda: {
3685
+ seeds: [
3686
+ {
3687
+ kind: "const",
3688
+ value: [
3689
+ 67,
3690
+ 111,
3691
+ 109,
3692
+ 112,
3693
+ 117,
3694
+ 116,
3695
+ 97,
3696
+ 116,
3697
+ 105,
3698
+ 111,
3699
+ 110,
3700
+ 68,
3701
+ 101,
3702
+ 102,
3703
+ 105,
3704
+ 110,
3705
+ 105,
3706
+ 116,
3707
+ 105,
3708
+ 111,
3709
+ 110,
3710
+ 82,
3711
+ 97,
3712
+ 119
3713
+ ]
3714
+ },
3715
+ {
3716
+ kind: "account",
3717
+ path: "comp_def_acc"
3718
+ },
3719
+ {
3720
+ kind: "const",
3721
+ value: [
3722
+ 0
3723
+ ]
3724
+ }
3725
+ ]
3726
+ }
3585
3727
  }
3586
3728
  ],
3587
3729
  args: [
@@ -13634,7 +13776,9 @@ exports.Aes256Cipher = Aes256Cipher;
13634
13776
  exports.ArcisModule = ArcisModule;
13635
13777
  exports.ArcisType = ArcisType;
13636
13778
  exports.ArcisValueField = ArcisValueField;
13779
+ exports.CSplRescueCipher = CSplRescueCipher;
13637
13780
  exports.CURVE25519_BASE_FIELD = CURVE25519_BASE_FIELD;
13781
+ exports.CURVE25519_SCALAR_FIELD = CURVE25519_SCALAR_FIELD;
13638
13782
  exports.CURVE25519_SCALAR_FIELD_MODULUS = CURVE25519_SCALAR_FIELD_MODULUS;
13639
13783
  exports.IntegerInfo = IntegerInfo;
13640
13784
  exports.Matrix = Matrix;
package/build/index.d.ts CHANGED
@@ -99,13 +99,17 @@ type HashFunction = {
99
99
  capacity: number;
100
100
  };
101
101
  /**
102
- * Field type for Curve25519 base field.
102
+ * Field type.
103
103
  */
104
104
  type FpField = IField<bigint>;
105
105
  /**
106
106
  * Curve25519 base field as an IField instance.
107
107
  */
108
108
  declare const CURVE25519_BASE_FIELD: FpField;
109
+ /**
110
+ * Curve25519 scalar field as an IField instance.
111
+ */
112
+ declare const CURVE25519_SCALAR_FIELD: FpField;
109
113
  /**
110
114
  * Description and parameters for the Rescue cipher or hash function, including round constants, MDS matrix, and key schedule.
111
115
  * See: https://tosc.iacr.org/index.php/ToSC/article/view/8695/8287
@@ -152,14 +156,14 @@ declare function toVec(data: bigint[]): bigint[][];
152
156
  * The Rescue cipher in Counter (CTR) mode, with a fixed block size m = 5.
153
157
  * See: https://tosc.iacr.org/index.php/ToSC/article/view/8695/8287
154
158
  */
155
- declare class RescueCipher {
159
+ declare class RescueCipherCommon {
156
160
  desc: RescueDesc;
157
161
  /**
158
- * Constructs a RescueCipher instance using a shared secret.
162
+ * Constructs a RescueCipherCommon instance using a shared secret.
159
163
  * The key is derived using RescuePrimeHash and used to initialize the RescueDesc.
160
164
  * @param sharedSecret - The shared secret to derive the cipher key from.
161
165
  */
162
- constructor(sharedSecret: Uint8Array);
166
+ constructor(sharedSecret: Uint8Array, field: FpField);
163
167
  /**
164
168
  * Encrypts the plaintext vector in Counter (CTR) mode (raw, returns bigints).
165
169
  * @param plaintext - The array of plaintext bigints to encrypt.
@@ -192,6 +196,62 @@ declare class RescueCipher {
192
196
  decrypt(ciphertext: number[][], nonce: Uint8Array): bigint[];
193
197
  }
194
198
 
199
+ /**
200
+ * The Rescue cipher over Curve25519's base field in Counter (CTR) mode, with a fixed block size m = 5.
201
+ * See: https://tosc.iacr.org/index.php/ToSC/article/view/8695/8287
202
+ */
203
+ declare class RescueCipher {
204
+ cipher: RescueCipherCommon;
205
+ /**
206
+ * Constructs a RescueCipher instance using a shared secret.
207
+ * The key is derived using RescuePrimeHash and used to initialize the RescueDesc.
208
+ * @param sharedSecret - The shared secret to derive the cipher key from.
209
+ */
210
+ constructor(sharedSecret: Uint8Array);
211
+ /**
212
+ * Encrypts the plaintext vector in Counter (CTR) mode and serializes each block.
213
+ * @param plaintext - The array of plaintext bigints to encrypt.
214
+ * @param nonce - A 16-byte nonce for CTR mode.
215
+ * @returns The ciphertext as an array of arrays of numbers (each 32 bytes).
216
+ */
217
+ encrypt(plaintext: bigint[], nonce: Uint8Array): number[][];
218
+ /**
219
+ * Deserializes and decrypts the ciphertext vector in Counter (CTR) mode.
220
+ * @param ciphertext - The array of arrays of numbers (each 32 bytes) to decrypt.
221
+ * @param nonce - A 16-byte nonce for CTR mode.
222
+ * @returns The decrypted plaintext as an array of bigints.
223
+ */
224
+ decrypt(ciphertext: number[][], nonce: Uint8Array): bigint[];
225
+ }
226
+
227
+ /**
228
+ * The Rescue cipher over Curve25519's scalar field in Counter (CTR) mode, with a fixed block size m = 5.
229
+ * See: https://tosc.iacr.org/index.php/ToSC/article/view/8695/8287
230
+ */
231
+ declare class CSplRescueCipher {
232
+ cipher: RescueCipherCommon;
233
+ /**
234
+ * Constructs a RescueCipher instance using a shared secret.
235
+ * The key is derived using RescuePrimeHash and used to initialize the RescueDesc.
236
+ * @param sharedSecret - The shared secret to derive the cipher key from.
237
+ */
238
+ constructor(sharedSecret: Uint8Array);
239
+ /**
240
+ * Encrypts the plaintext vector in Counter (CTR) mode and serializes each block.
241
+ * @param plaintext - The array of plaintext bigints to encrypt.
242
+ * @param nonce - A 16-byte nonce for CTR mode.
243
+ * @returns The ciphertext as an array of arrays of numbers (each 32 bytes).
244
+ */
245
+ encrypt(plaintext: bigint[], nonce: Uint8Array): number[][];
246
+ /**
247
+ * Deserializes and decrypts the ciphertext vector in Counter (CTR) mode.
248
+ * @param ciphertext - The array of arrays of numbers (each 32 bytes) to decrypt.
249
+ * @param nonce - A 16-byte nonce for CTR mode.
250
+ * @returns The decrypted plaintext as an array of bigints.
251
+ */
252
+ decrypt(ciphertext: number[][], nonce: Uint8Array): bigint[];
253
+ }
254
+
195
255
  /**
196
256
  * The Rescue-Prime hash function, as described in https://eprint.iacr.org/2020/1143.pdf, offering 256 bits
197
257
  * of security against collision, preimage and second-preimage attacks for any field of size at least 102 bits.
@@ -205,7 +265,7 @@ declare class RescuePrimeHash {
205
265
  /**
206
266
  * Constructs a RescuePrimeHash instance with rate = 7 and capacity = 5.
207
267
  */
208
- constructor();
268
+ constructor(field: FpField);
209
269
  /**
210
270
  * Computes the Rescue-Prime hash of a message, with padding as described in Algorithm 2 of the paper.
211
271
  * @param message - The input message as an array of bigints.
@@ -396,7 +456,7 @@ type Arcium = {
396
456
  "address": "Arcj82pX7HxYKLR92qvgZUAd7vGS1k4hQvAFcPATFdEQ";
397
457
  "metadata": {
398
458
  "name": "arcium";
399
- "version": "0.6.2";
459
+ "version": "0.6.3";
400
460
  "spec": "0.1.0";
401
461
  "description": "The Arcium program";
402
462
  };
@@ -1484,6 +1544,10 @@ type Arcium = {
1484
1544
  {
1485
1545
  "name": "mxeProgram";
1486
1546
  "type": "pubkey";
1547
+ },
1548
+ {
1549
+ "name": "outputLenBytes";
1550
+ "type": "u32";
1487
1551
  }
1488
1552
  ];
1489
1553
  },
@@ -2257,6 +2321,55 @@ type Arcium = {
2257
2321
  }
2258
2322
  ];
2259
2323
  };
2324
+ },
2325
+ {
2326
+ "name": "compDefRaw";
2327
+ "docs": [
2328
+ "At least the first raw circuit account must exist before finalizing"
2329
+ ];
2330
+ "pda": {
2331
+ "seeds": [
2332
+ {
2333
+ "kind": "const";
2334
+ "value": [
2335
+ 67,
2336
+ 111,
2337
+ 109,
2338
+ 112,
2339
+ 117,
2340
+ 116,
2341
+ 97,
2342
+ 116,
2343
+ 105,
2344
+ 111,
2345
+ 110,
2346
+ 68,
2347
+ 101,
2348
+ 102,
2349
+ 105,
2350
+ 110,
2351
+ 105,
2352
+ 116,
2353
+ 105,
2354
+ 111,
2355
+ 110,
2356
+ 82,
2357
+ 97,
2358
+ 119
2359
+ ];
2360
+ },
2361
+ {
2362
+ "kind": "account";
2363
+ "path": "compDefAcc";
2364
+ },
2365
+ {
2366
+ "kind": "const";
2367
+ "value": [
2368
+ 0
2369
+ ];
2370
+ }
2371
+ ];
2372
+ };
2260
2373
  }
2261
2374
  ];
2262
2375
  "args": [
@@ -11691,5 +11804,5 @@ declare function getRecoveryClusterAccAddress(mxeProgramId: PublicKey): PublicKe
11691
11804
  */
11692
11805
  declare function getMxeRecoveryAccAddress(backupMxeProgramId: PublicKey, originalMxeProgramId: PublicKey): PublicKey;
11693
11806
 
11694
- export { ARCIUM_ADDR, ARCIUM_IDL, Aes128Cipher, Aes192Cipher, Aes256Cipher, ArcisModule, ArcisType, ArcisValueField, CURVE25519_BASE_FIELD, CURVE25519_SCALAR_FIELD_MODULUS, IntegerInfo, Matrix, RescueCipher, RescueDesc, RescuePrimeHash, arcisEd25519, awaitComputationFinalization, buildFinalizeCompDefTx, createPacker, deserializeLE, finalizeKeyRecoveryExecution, generateRandomFieldElem, getArciumAccountBaseSeed, getArciumEnv, getArciumProgram, getArciumProgramId, getArxNodeAccAddress, getClockAccAddress, getClusterAccAddress, getCompDefAccAddress, getCompDefAccOffset, getComputationAccAddress, getComputationsInMempool, getExecutingPoolAccAddress, getExecutingPoolAccInfo, getFeePoolAccAddress, getMXEAccAddress, getMXEArcisEd25519VerifyingKey, getMXEPublicKey, getMempoolAccAddress, getMempoolAccInfo, getMempoolPriorityFeeStats, getMxeRecoveryAccAddress, getRecoveryClusterAccAddress, initKeyRecoveryExecution, initMxePart1, initMxePart2, isNullRef, positiveModulo, queueKeyRecoveryInit, randMatrix, recoverMxe, serializeLE, sha256, submitKeyRecoveryShare, toVec, uploadCircuit };
11807
+ export { ARCIUM_ADDR, ARCIUM_IDL, Aes128Cipher, Aes192Cipher, Aes256Cipher, ArcisModule, ArcisType, ArcisValueField, CSplRescueCipher, CURVE25519_BASE_FIELD, CURVE25519_SCALAR_FIELD, CURVE25519_SCALAR_FIELD_MODULUS, IntegerInfo, Matrix, RescueCipher, RescueDesc, RescuePrimeHash, arcisEd25519, awaitComputationFinalization, buildFinalizeCompDefTx, createPacker, deserializeLE, finalizeKeyRecoveryExecution, generateRandomFieldElem, getArciumAccountBaseSeed, getArciumEnv, getArciumProgram, getArciumProgramId, getArxNodeAccAddress, getClockAccAddress, getClusterAccAddress, getCompDefAccAddress, getCompDefAccOffset, getComputationAccAddress, getComputationsInMempool, getExecutingPoolAccAddress, getExecutingPoolAccInfo, getFeePoolAccAddress, getMXEAccAddress, getMXEArcisEd25519VerifyingKey, getMXEPublicKey, getMempoolAccAddress, getMempoolAccInfo, getMempoolPriorityFeeStats, getMxeRecoveryAccAddress, getRecoveryClusterAccAddress, initKeyRecoveryExecution, initMxePart1, initMxePart2, isNullRef, positiveModulo, queueKeyRecoveryInit, randMatrix, recoverMxe, serializeLE, sha256, submitKeyRecoveryShare, toVec, uploadCircuit };
11695
11808
  export type { Arcium as ArciumIdlType, ArciumLocalEnv, ComputationErrorType, ComputationReference, ExecutingPoolAccount, FieldInfo, FpField, MempoolAccount, MempoolPriorityFeeStats, Packer };
package/build/index.mjs CHANGED
@@ -480,7 +480,11 @@ function randMatrix(field, nrows, ncols) {
480
480
  /**
481
481
  * Curve25519 base field as an IField instance.
482
482
  */
483
- const CURVE25519_BASE_FIELD = ed25519.CURVE.Fp;
483
+ const CURVE25519_BASE_FIELD = ed25519.Point.Fp;
484
+ /**
485
+ * Curve25519 scalar field as an IField instance.
486
+ */
487
+ const CURVE25519_SCALAR_FIELD = ed25519.Point.Fn;
484
488
  // Security level for the block cipher.
485
489
  const SECURITY_LEVEL_BLOCK_CIPHER = 128;
486
490
  // Security level for the hash function.
@@ -876,8 +880,8 @@ class RescuePrimeHash {
876
880
  /**
877
881
  * Constructs a RescuePrimeHash instance with rate = 7 and capacity = 5.
878
882
  */
879
- constructor() {
880
- this.desc = new RescueDesc(CURVE25519_BASE_FIELD, { kind: 'hash', m: 12, capacity: 5 });
883
+ constructor(field) {
884
+ this.desc = new RescueDesc(field, { kind: 'hash', m: 12, capacity: 5 });
881
885
  this.rate = 7;
882
886
  this.digestLength = 5;
883
887
  }
@@ -931,15 +935,32 @@ const RESCUE_CIPHER_BLOCK_SIZE = 5;
931
935
  * The Rescue cipher in Counter (CTR) mode, with a fixed block size m = 5.
932
936
  * See: https://tosc.iacr.org/index.php/ToSC/article/view/8695/8287
933
937
  */
934
- class RescueCipher {
938
+ class RescueCipherCommon {
935
939
  desc;
936
940
  /**
937
- * Constructs a RescueCipher instance using a shared secret.
941
+ * Constructs a RescueCipherCommon instance using a shared secret.
938
942
  * The key is derived using RescuePrimeHash and used to initialize the RescueDesc.
939
943
  * @param sharedSecret - The shared secret to derive the cipher key from.
940
944
  */
941
- constructor(sharedSecret) {
942
- const hasher = new RescuePrimeHash();
945
+ constructor(sharedSecret, field) {
946
+ if (sharedSecret.length != 32) {
947
+ throw Error(`sharedSecret must be of length 32 (found ${sharedSecret.length})`);
948
+ }
949
+ const hasher = new RescuePrimeHash(field);
950
+ // In case `field` is different from CURVE25519_BASE_FIELD we need to injectively map sharedSecret
951
+ // to a vector of elements over `field`.
952
+ const converted = [];
953
+ if (field === CURVE25519_BASE_FIELD) {
954
+ converted.push(deserializeLE(sharedSecret));
955
+ }
956
+ else {
957
+ // We chunk sharedSecret by field.BYTES - 1 and convert.
958
+ const chunkSize = field.BYTES - 1;
959
+ const nChunks = Math.ceil(sharedSecret.length / chunkSize);
960
+ for (let i = 0; i < nChunks; ++i) {
961
+ converted.push(deserializeLE(sharedSecret.slice(i * chunkSize, (i + 1) * chunkSize)));
962
+ }
963
+ }
943
964
  // We follow [Section 4, Option 1.](https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-56Cr2.pdf).
944
965
  // For our choice of hash function, we have:
945
966
  // - H_outputBits = hasher.digestLength = RESCUE_CIPHER_BLOCK_SIZE
@@ -948,9 +969,9 @@ class RescueCipher {
948
969
  // - L = RESCUE_CIPHER_BLOCK_SIZE.
949
970
  // Build the vector `counter || Z || FixedInfo` (we only have i = 1, since reps = 1).
950
971
  // For the FixedInfo we simply take L.
951
- const counter = [1n, deserializeLE(sharedSecret), BigInt(RESCUE_CIPHER_BLOCK_SIZE)];
972
+ const counter = [1n, ...converted, BigInt(RESCUE_CIPHER_BLOCK_SIZE)];
952
973
  const rescueKey = hasher.digest(counter);
953
- this.desc = new RescueDesc(CURVE25519_BASE_FIELD, { kind: 'cipher', key: rescueKey });
974
+ this.desc = new RescueDesc(field, { kind: 'cipher', key: rescueKey });
954
975
  }
955
976
  /**
956
977
  * Encrypts the plaintext vector in Counter (CTR) mode (raw, returns bigints).
@@ -972,7 +993,7 @@ class RescueCipher {
972
993
  const ciphertext = [];
973
994
  for (let i = 0; i < ptxt.length; ++i) {
974
995
  if (!verifyBinSize(ptxt[i], binSize - 1n) || ctSignBit(ptxt[i], binSize) || !ctLt(ptxt[i], desc.field.ORDER, binSize)) {
975
- throw Error(`plaintext must be non-negative and at most ${desc.field.ORDER}`);
996
+ throw Error(`plaintext must be non-negative and less than ${desc.field.ORDER}`);
976
997
  }
977
998
  const sum = ctAdd(ptxt[i], encryptedCounter.data[i][0], binSize);
978
999
  ciphertext.push(ctSelect(ctLt(sum, desc.field.ORDER, binSize), sum, ctSub(sum, desc.field.ORDER, binSize), binSize));
@@ -1070,6 +1091,74 @@ function getCounter(nonce, nBlocks) {
1070
1091
  return counter;
1071
1092
  }
1072
1093
 
1094
+ /**
1095
+ * The Rescue cipher over Curve25519's base field in Counter (CTR) mode, with a fixed block size m = 5.
1096
+ * See: https://tosc.iacr.org/index.php/ToSC/article/view/8695/8287
1097
+ */
1098
+ class RescueCipher {
1099
+ cipher;
1100
+ /**
1101
+ * Constructs a RescueCipher instance using a shared secret.
1102
+ * The key is derived using RescuePrimeHash and used to initialize the RescueDesc.
1103
+ * @param sharedSecret - The shared secret to derive the cipher key from.
1104
+ */
1105
+ constructor(sharedSecret) {
1106
+ this.cipher = new RescueCipherCommon(sharedSecret, CURVE25519_BASE_FIELD);
1107
+ }
1108
+ /**
1109
+ * Encrypts the plaintext vector in Counter (CTR) mode and serializes each block.
1110
+ * @param plaintext - The array of plaintext bigints to encrypt.
1111
+ * @param nonce - A 16-byte nonce for CTR mode.
1112
+ * @returns The ciphertext as an array of arrays of numbers (each 32 bytes).
1113
+ */
1114
+ encrypt(plaintext, nonce) {
1115
+ return this.cipher.encrypt(plaintext, nonce);
1116
+ }
1117
+ /**
1118
+ * Deserializes and decrypts the ciphertext vector in Counter (CTR) mode.
1119
+ * @param ciphertext - The array of arrays of numbers (each 32 bytes) to decrypt.
1120
+ * @param nonce - A 16-byte nonce for CTR mode.
1121
+ * @returns The decrypted plaintext as an array of bigints.
1122
+ */
1123
+ decrypt(ciphertext, nonce) {
1124
+ return this.cipher.decrypt(ciphertext, nonce);
1125
+ }
1126
+ }
1127
+
1128
+ /**
1129
+ * The Rescue cipher over Curve25519's scalar field in Counter (CTR) mode, with a fixed block size m = 5.
1130
+ * See: https://tosc.iacr.org/index.php/ToSC/article/view/8695/8287
1131
+ */
1132
+ class CSplRescueCipher {
1133
+ cipher;
1134
+ /**
1135
+ * Constructs a RescueCipher instance using a shared secret.
1136
+ * The key is derived using RescuePrimeHash and used to initialize the RescueDesc.
1137
+ * @param sharedSecret - The shared secret to derive the cipher key from.
1138
+ */
1139
+ constructor(sharedSecret) {
1140
+ this.cipher = new RescueCipherCommon(sharedSecret, CURVE25519_SCALAR_FIELD);
1141
+ }
1142
+ /**
1143
+ * Encrypts the plaintext vector in Counter (CTR) mode and serializes each block.
1144
+ * @param plaintext - The array of plaintext bigints to encrypt.
1145
+ * @param nonce - A 16-byte nonce for CTR mode.
1146
+ * @returns The ciphertext as an array of arrays of numbers (each 32 bytes).
1147
+ */
1148
+ encrypt(plaintext, nonce) {
1149
+ return this.cipher.encrypt(plaintext, nonce);
1150
+ }
1151
+ /**
1152
+ * Deserializes and decrypts the ciphertext vector in Counter (CTR) mode.
1153
+ * @param ciphertext - The array of arrays of numbers (each 32 bytes) to decrypt.
1154
+ * @param nonce - A 16-byte nonce for CTR mode.
1155
+ * @returns The decrypted plaintext as an array of bigints.
1156
+ */
1157
+ decrypt(ciphertext, nonce) {
1158
+ return this.cipher.decrypt(ciphertext, nonce);
1159
+ }
1160
+ }
1161
+
1073
1162
  // The arcisEd25519 signature scheme. This is essentially ed25519 but we use the hash function
1074
1163
  // SHA3-512 instead of SHA-512 since its multiplicative depth is much lower, which
1075
1164
  // makes it much better suited to be evaluated in MPC.
@@ -1701,7 +1790,7 @@ function createPacker(fields, typeName = 'Packer') {
1701
1790
  var address = "Arcj82pX7HxYKLR92qvgZUAd7vGS1k4hQvAFcPATFdEQ";
1702
1791
  var metadata = {
1703
1792
  name: "arcium",
1704
- version: "0.6.2",
1793
+ version: "0.6.3",
1705
1794
  spec: "0.1.0",
1706
1795
  description: "The Arcium program"
1707
1796
  };
@@ -2789,6 +2878,10 @@ var instructions = [
2789
2878
  {
2790
2879
  name: "mxe_program",
2791
2880
  type: "pubkey"
2881
+ },
2882
+ {
2883
+ name: "output_len_bytes",
2884
+ type: "u32"
2792
2885
  }
2793
2886
  ]
2794
2887
  },
@@ -3563,6 +3656,55 @@ var instructions = [
3563
3656
  }
3564
3657
  ]
3565
3658
  }
3659
+ },
3660
+ {
3661
+ name: "comp_def_raw",
3662
+ docs: [
3663
+ "At least the first raw circuit account must exist before finalizing"
3664
+ ],
3665
+ pda: {
3666
+ seeds: [
3667
+ {
3668
+ kind: "const",
3669
+ value: [
3670
+ 67,
3671
+ 111,
3672
+ 109,
3673
+ 112,
3674
+ 117,
3675
+ 116,
3676
+ 97,
3677
+ 116,
3678
+ 105,
3679
+ 111,
3680
+ 110,
3681
+ 68,
3682
+ 101,
3683
+ 102,
3684
+ 105,
3685
+ 110,
3686
+ 105,
3687
+ 116,
3688
+ 105,
3689
+ 111,
3690
+ 110,
3691
+ 82,
3692
+ 97,
3693
+ 119
3694
+ ]
3695
+ },
3696
+ {
3697
+ kind: "account",
3698
+ path: "comp_def_acc"
3699
+ },
3700
+ {
3701
+ kind: "const",
3702
+ value: [
3703
+ 0
3704
+ ]
3705
+ }
3706
+ ]
3707
+ }
3566
3708
  }
3567
3709
  ],
3568
3710
  args: [
@@ -13603,4 +13745,4 @@ async function awaitEvent(eventListener, eventName, eventCheck, commitment = 'co
13603
13745
  return { event: foundEvent[0], sig: foundEvent[1] };
13604
13746
  }
13605
13747
 
13606
- export { ARCIUM_ADDR, ARCIUM_IDL, Aes128Cipher, Aes192Cipher, Aes256Cipher, ArcisModule, ArcisType, ArcisValueField, CURVE25519_BASE_FIELD, CURVE25519_SCALAR_FIELD_MODULUS, IntegerInfo, Matrix, RescueCipher, RescueDesc, RescuePrimeHash, arcisEd25519, awaitComputationFinalization, buildFinalizeCompDefTx, createPacker, deserializeLE, finalizeKeyRecoveryExecution, generateRandomFieldElem, getArciumAccountBaseSeed, getArciumEnv, getArciumProgram, getArciumProgramId, getArxNodeAccAddress, getClockAccAddress, getClusterAccAddress, getCompDefAccAddress, getCompDefAccOffset, getComputationAccAddress, getComputationsInMempool, getExecutingPoolAccAddress, getExecutingPoolAccInfo, getFeePoolAccAddress, getMXEAccAddress, getMXEArcisEd25519VerifyingKey, getMXEPublicKey, getMempoolAccAddress, getMempoolAccInfo, getMempoolPriorityFeeStats, getMxeRecoveryAccAddress, getRecoveryClusterAccAddress, initKeyRecoveryExecution, initMxePart1, initMxePart2, isNullRef, positiveModulo, queueKeyRecoveryInit, randMatrix, recoverMxe, serializeLE, sha256, submitKeyRecoveryShare, toVec, uploadCircuit };
13748
+ export { ARCIUM_ADDR, ARCIUM_IDL, Aes128Cipher, Aes192Cipher, Aes256Cipher, ArcisModule, ArcisType, ArcisValueField, CSplRescueCipher, CURVE25519_BASE_FIELD, CURVE25519_SCALAR_FIELD, CURVE25519_SCALAR_FIELD_MODULUS, IntegerInfo, Matrix, RescueCipher, RescueDesc, RescuePrimeHash, arcisEd25519, awaitComputationFinalization, buildFinalizeCompDefTx, createPacker, deserializeLE, finalizeKeyRecoveryExecution, generateRandomFieldElem, getArciumAccountBaseSeed, getArciumEnv, getArciumProgram, getArciumProgramId, getArxNodeAccAddress, getClockAccAddress, getClusterAccAddress, getCompDefAccAddress, getCompDefAccOffset, getComputationAccAddress, getComputationsInMempool, getExecutingPoolAccAddress, getExecutingPoolAccInfo, getFeePoolAccAddress, getMXEAccAddress, getMXEArcisEd25519VerifyingKey, getMXEPublicKey, getMempoolAccAddress, getMempoolAccInfo, getMempoolPriorityFeeStats, getMxeRecoveryAccAddress, getRecoveryClusterAccAddress, initKeyRecoveryExecution, initMxePart1, initMxePart2, isNullRef, positiveModulo, queueKeyRecoveryInit, randMatrix, recoverMxe, serializeLE, sha256, submitKeyRecoveryShare, toVec, uploadCircuit };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcium-hq/client",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "Client SDK for interacting with encrypted Solana programs",
5
5
  "author": "Arcium",
6
6
  "license": "GPL-3.0-only",