@arcium-hq/client 0.6.1 → 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.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.1",
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
  },
@@ -2874,18 +2967,24 @@ var instructions = [
2874
2967
  {
2875
2968
  kind: "const",
2876
2969
  value: [
2877
- 109,
2970
+ 77,
2878
2971
  120,
2879
2972
  101,
2880
- 95,
2881
- 114,
2973
+ 82,
2882
2974
  101,
2883
2975
  99,
2884
2976
  111,
2885
2977
  118,
2886
2978
  101,
2887
2979
  114,
2888
- 121
2980
+ 121,
2981
+ 65,
2982
+ 99,
2983
+ 99,
2984
+ 111,
2985
+ 117,
2986
+ 110,
2987
+ 116
2889
2988
  ]
2890
2989
  },
2891
2990
  {
@@ -3557,6 +3656,55 @@ var instructions = [
3557
3656
  }
3558
3657
  ]
3559
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
+ }
3560
3708
  }
3561
3709
  ],
3562
3710
  args: [
@@ -3651,18 +3799,24 @@ var instructions = [
3651
3799
  {
3652
3800
  kind: "const",
3653
3801
  value: [
3654
- 109,
3802
+ 77,
3655
3803
  120,
3656
3804
  101,
3657
- 95,
3658
- 114,
3805
+ 82,
3659
3806
  101,
3660
3807
  99,
3661
3808
  111,
3662
3809
  118,
3663
3810
  101,
3664
3811
  114,
3665
- 121
3812
+ 121,
3813
+ 65,
3814
+ 99,
3815
+ 99,
3816
+ 111,
3817
+ 117,
3818
+ 110,
3819
+ 116
3666
3820
  ]
3667
3821
  },
3668
3822
  {
@@ -4006,18 +4160,24 @@ var instructions = [
4006
4160
  {
4007
4161
  kind: "const",
4008
4162
  value: [
4009
- 109,
4163
+ 77,
4010
4164
  120,
4011
4165
  101,
4012
- 95,
4013
- 114,
4166
+ 82,
4014
4167
  101,
4015
4168
  99,
4016
4169
  111,
4017
4170
  118,
4018
4171
  101,
4019
4172
  114,
4020
- 121
4173
+ 121,
4174
+ 65,
4175
+ 99,
4176
+ 99,
4177
+ 111,
4178
+ 117,
4179
+ 110,
4180
+ 116
4021
4181
  ]
4022
4182
  },
4023
4183
  {
@@ -5120,18 +5280,24 @@ var instructions = [
5120
5280
  {
5121
5281
  kind: "const",
5122
5282
  value: [
5123
- 109,
5283
+ 77,
5124
5284
  120,
5125
5285
  101,
5126
- 95,
5127
- 114,
5286
+ 82,
5128
5287
  101,
5129
5288
  99,
5130
5289
  111,
5131
5290
  118,
5132
5291
  101,
5133
5292
  114,
5134
- 121
5293
+ 121,
5294
+ 65,
5295
+ 99,
5296
+ 99,
5297
+ 111,
5298
+ 117,
5299
+ 110,
5300
+ 116
5135
5301
  ]
5136
5302
  },
5137
5303
  {
@@ -5293,18 +5459,24 @@ var instructions = [
5293
5459
  {
5294
5460
  kind: "const",
5295
5461
  value: [
5296
- 109,
5462
+ 77,
5297
5463
  120,
5298
5464
  101,
5299
- 95,
5300
- 114,
5465
+ 82,
5301
5466
  101,
5302
5467
  99,
5303
5468
  111,
5304
5469
  118,
5305
5470
  101,
5306
5471
  114,
5307
- 121
5472
+ 121,
5473
+ 65,
5474
+ 99,
5475
+ 99,
5476
+ 111,
5477
+ 117,
5478
+ 110,
5479
+ 116
5308
5480
  ]
5309
5481
  },
5310
5482
  {
@@ -7461,18 +7633,24 @@ var instructions = [
7461
7633
  {
7462
7634
  kind: "const",
7463
7635
  value: [
7464
- 109,
7636
+ 77,
7465
7637
  120,
7466
7638
  101,
7467
- 95,
7468
- 114,
7639
+ 82,
7469
7640
  101,
7470
7641
  99,
7471
7642
  111,
7472
7643
  118,
7473
7644
  101,
7474
7645
  114,
7475
- 121
7646
+ 121,
7647
+ 65,
7648
+ 99,
7649
+ 99,
7650
+ 111,
7651
+ 117,
7652
+ 110,
7653
+ 116
7476
7654
  ]
7477
7655
  },
7478
7656
  {
@@ -8701,18 +8879,24 @@ var instructions = [
8701
8879
  {
8702
8880
  kind: "const",
8703
8881
  value: [
8704
- 109,
8882
+ 77,
8705
8883
  120,
8706
8884
  101,
8707
- 95,
8708
- 114,
8885
+ 82,
8709
8886
  101,
8710
8887
  99,
8711
8888
  111,
8712
8889
  118,
8713
8890
  101,
8714
8891
  114,
8715
- 121
8892
+ 121,
8893
+ 65,
8894
+ 99,
8895
+ 99,
8896
+ 111,
8897
+ 117,
8898
+ 110,
8899
+ 116
8716
8900
  ]
8717
8901
  },
8718
8902
  {
@@ -9826,6 +10010,11 @@ var errors = [
9826
10010
  code: 6713,
9827
10011
  name: "BackupClusterNotSet",
9828
10012
  msg: "Backup MXE cluster is not set"
10013
+ },
10014
+ {
10015
+ code: 6714,
10016
+ name: "ShareAlreadySubmitted",
10017
+ msg: "Share already submitted"
9829
10018
  }
9830
10019
  ];
9831
10020
  var types = [
@@ -11686,17 +11875,11 @@ var types = [
11686
11875
  kind: "struct",
11687
11876
  fields: [
11688
11877
  {
11689
- name: "bitmap",
11878
+ name: "key_recovery_finalize_offset",
11690
11879
  docs: [
11691
- "Bitmap tracking which peers have uploaded their shares.",
11692
- "Bit index corresponds to the index in the original MXE's recovery_peers array."
11880
+ "The computation offset for the queued key_recovery_finalize circuit."
11693
11881
  ],
11694
- type: {
11695
- array: [
11696
- "u8",
11697
- 13
11698
- ]
11699
- }
11882
+ type: "u64"
11700
11883
  },
11701
11884
  {
11702
11885
  name: "shares",
@@ -11722,52 +11905,32 @@ var types = [
11722
11905
  }
11723
11906
  },
11724
11907
  {
11725
- name: "is_finalized",
11726
- docs: [
11727
- "Whether the recovery has been finalized (threshold met and marked ready)."
11728
- ],
11729
- type: "u8"
11908
+ name: "original_mxe_pubkey",
11909
+ type: "pubkey"
11730
11910
  },
11731
11911
  {
11732
- name: "_padding1",
11733
- docs: [
11734
- "Padding for u64 alignment (need 5 bytes to align key_recovery_final_offset at 8-byte",
11735
- "boundary)"
11736
- ],
11737
- type: {
11738
- array: [
11739
- "u8",
11740
- 2
11741
- ]
11742
- }
11912
+ name: "backup_mxe_pubkey",
11913
+ type: "pubkey"
11743
11914
  },
11744
11915
  {
11745
- name: "key_recovery_finalize_offset",
11916
+ name: "is_finalized",
11746
11917
  docs: [
11747
- "The computation offset for the queued key_recovery_finalize circuit."
11918
+ "Whether the recovery has been finalized (threshold met and marked ready)."
11748
11919
  ],
11749
- type: "u64"
11920
+ type: "u8"
11750
11921
  },
11751
11922
  {
11752
11923
  name: "_padding2",
11753
11924
  docs: [
11754
- "Padding to ensure struct size is multiple of 8 (for zero_copy alignment after bump field)"
11925
+ "Padding to ensure struct size is u64 aligned (6 bytes)"
11755
11926
  ],
11756
11927
  type: {
11757
11928
  array: [
11758
11929
  "u8",
11759
- 7
11930
+ 6
11760
11931
  ]
11761
11932
  }
11762
11933
  },
11763
- {
11764
- name: "original_mxe_pubkey",
11765
- type: "pubkey"
11766
- },
11767
- {
11768
- name: "backup_mxe_pubkey",
11769
- type: "pubkey"
11770
- },
11771
11934
  {
11772
11935
  name: "bump",
11773
11936
  type: "u8"
@@ -12756,7 +12919,7 @@ const RECOVERY_CLUSTER_ACC_SEED = 'RecoveryClusterAccount';
12756
12919
  * Seed for MxeRecoveryAccount PDA
12757
12920
  * @constant {string}
12758
12921
  */
12759
- const MXE_RECOVERY_ACC_SEED = 'mxe_recovery';
12922
+ const MXE_RECOVERY_ACC_SEED = 'MxeRecoveryAccount';
12760
12923
  /**
12761
12924
  * Maximum number of bytes that can be reallocated per instruction.
12762
12925
  * @constant {number}
@@ -13582,4 +13745,4 @@ async function awaitEvent(eventListener, eventName, eventCheck, commitment = 'co
13582
13745
  return { event: foundEvent[0], sig: foundEvent[1] };
13583
13746
  }
13584
13747
 
13585
- 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.1",
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",