@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.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.1",
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
  },
@@ -2893,18 +2986,24 @@ var instructions = [
2893
2986
  {
2894
2987
  kind: "const",
2895
2988
  value: [
2896
- 109,
2989
+ 77,
2897
2990
  120,
2898
2991
  101,
2899
- 95,
2900
- 114,
2992
+ 82,
2901
2993
  101,
2902
2994
  99,
2903
2995
  111,
2904
2996
  118,
2905
2997
  101,
2906
2998
  114,
2907
- 121
2999
+ 121,
3000
+ 65,
3001
+ 99,
3002
+ 99,
3003
+ 111,
3004
+ 117,
3005
+ 110,
3006
+ 116
2908
3007
  ]
2909
3008
  },
2910
3009
  {
@@ -3576,6 +3675,55 @@ var instructions = [
3576
3675
  }
3577
3676
  ]
3578
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
+ }
3579
3727
  }
3580
3728
  ],
3581
3729
  args: [
@@ -3670,18 +3818,24 @@ var instructions = [
3670
3818
  {
3671
3819
  kind: "const",
3672
3820
  value: [
3673
- 109,
3821
+ 77,
3674
3822
  120,
3675
3823
  101,
3676
- 95,
3677
- 114,
3824
+ 82,
3678
3825
  101,
3679
3826
  99,
3680
3827
  111,
3681
3828
  118,
3682
3829
  101,
3683
3830
  114,
3684
- 121
3831
+ 121,
3832
+ 65,
3833
+ 99,
3834
+ 99,
3835
+ 111,
3836
+ 117,
3837
+ 110,
3838
+ 116
3685
3839
  ]
3686
3840
  },
3687
3841
  {
@@ -4025,18 +4179,24 @@ var instructions = [
4025
4179
  {
4026
4180
  kind: "const",
4027
4181
  value: [
4028
- 109,
4182
+ 77,
4029
4183
  120,
4030
4184
  101,
4031
- 95,
4032
- 114,
4185
+ 82,
4033
4186
  101,
4034
4187
  99,
4035
4188
  111,
4036
4189
  118,
4037
4190
  101,
4038
4191
  114,
4039
- 121
4192
+ 121,
4193
+ 65,
4194
+ 99,
4195
+ 99,
4196
+ 111,
4197
+ 117,
4198
+ 110,
4199
+ 116
4040
4200
  ]
4041
4201
  },
4042
4202
  {
@@ -5139,18 +5299,24 @@ var instructions = [
5139
5299
  {
5140
5300
  kind: "const",
5141
5301
  value: [
5142
- 109,
5302
+ 77,
5143
5303
  120,
5144
5304
  101,
5145
- 95,
5146
- 114,
5305
+ 82,
5147
5306
  101,
5148
5307
  99,
5149
5308
  111,
5150
5309
  118,
5151
5310
  101,
5152
5311
  114,
5153
- 121
5312
+ 121,
5313
+ 65,
5314
+ 99,
5315
+ 99,
5316
+ 111,
5317
+ 117,
5318
+ 110,
5319
+ 116
5154
5320
  ]
5155
5321
  },
5156
5322
  {
@@ -5312,18 +5478,24 @@ var instructions = [
5312
5478
  {
5313
5479
  kind: "const",
5314
5480
  value: [
5315
- 109,
5481
+ 77,
5316
5482
  120,
5317
5483
  101,
5318
- 95,
5319
- 114,
5484
+ 82,
5320
5485
  101,
5321
5486
  99,
5322
5487
  111,
5323
5488
  118,
5324
5489
  101,
5325
5490
  114,
5326
- 121
5491
+ 121,
5492
+ 65,
5493
+ 99,
5494
+ 99,
5495
+ 111,
5496
+ 117,
5497
+ 110,
5498
+ 116
5327
5499
  ]
5328
5500
  },
5329
5501
  {
@@ -7480,18 +7652,24 @@ var instructions = [
7480
7652
  {
7481
7653
  kind: "const",
7482
7654
  value: [
7483
- 109,
7655
+ 77,
7484
7656
  120,
7485
7657
  101,
7486
- 95,
7487
- 114,
7658
+ 82,
7488
7659
  101,
7489
7660
  99,
7490
7661
  111,
7491
7662
  118,
7492
7663
  101,
7493
7664
  114,
7494
- 121
7665
+ 121,
7666
+ 65,
7667
+ 99,
7668
+ 99,
7669
+ 111,
7670
+ 117,
7671
+ 110,
7672
+ 116
7495
7673
  ]
7496
7674
  },
7497
7675
  {
@@ -8720,18 +8898,24 @@ var instructions = [
8720
8898
  {
8721
8899
  kind: "const",
8722
8900
  value: [
8723
- 109,
8901
+ 77,
8724
8902
  120,
8725
8903
  101,
8726
- 95,
8727
- 114,
8904
+ 82,
8728
8905
  101,
8729
8906
  99,
8730
8907
  111,
8731
8908
  118,
8732
8909
  101,
8733
8910
  114,
8734
- 121
8911
+ 121,
8912
+ 65,
8913
+ 99,
8914
+ 99,
8915
+ 111,
8916
+ 117,
8917
+ 110,
8918
+ 116
8735
8919
  ]
8736
8920
  },
8737
8921
  {
@@ -9845,6 +10029,11 @@ var errors = [
9845
10029
  code: 6713,
9846
10030
  name: "BackupClusterNotSet",
9847
10031
  msg: "Backup MXE cluster is not set"
10032
+ },
10033
+ {
10034
+ code: 6714,
10035
+ name: "ShareAlreadySubmitted",
10036
+ msg: "Share already submitted"
9848
10037
  }
9849
10038
  ];
9850
10039
  var types = [
@@ -11705,17 +11894,11 @@ var types = [
11705
11894
  kind: "struct",
11706
11895
  fields: [
11707
11896
  {
11708
- name: "bitmap",
11897
+ name: "key_recovery_finalize_offset",
11709
11898
  docs: [
11710
- "Bitmap tracking which peers have uploaded their shares.",
11711
- "Bit index corresponds to the index in the original MXE's recovery_peers array."
11899
+ "The computation offset for the queued key_recovery_finalize circuit."
11712
11900
  ],
11713
- type: {
11714
- array: [
11715
- "u8",
11716
- 13
11717
- ]
11718
- }
11901
+ type: "u64"
11719
11902
  },
11720
11903
  {
11721
11904
  name: "shares",
@@ -11741,52 +11924,32 @@ var types = [
11741
11924
  }
11742
11925
  },
11743
11926
  {
11744
- name: "is_finalized",
11745
- docs: [
11746
- "Whether the recovery has been finalized (threshold met and marked ready)."
11747
- ],
11748
- type: "u8"
11927
+ name: "original_mxe_pubkey",
11928
+ type: "pubkey"
11749
11929
  },
11750
11930
  {
11751
- name: "_padding1",
11752
- docs: [
11753
- "Padding for u64 alignment (need 5 bytes to align key_recovery_final_offset at 8-byte",
11754
- "boundary)"
11755
- ],
11756
- type: {
11757
- array: [
11758
- "u8",
11759
- 2
11760
- ]
11761
- }
11931
+ name: "backup_mxe_pubkey",
11932
+ type: "pubkey"
11762
11933
  },
11763
11934
  {
11764
- name: "key_recovery_finalize_offset",
11935
+ name: "is_finalized",
11765
11936
  docs: [
11766
- "The computation offset for the queued key_recovery_finalize circuit."
11937
+ "Whether the recovery has been finalized (threshold met and marked ready)."
11767
11938
  ],
11768
- type: "u64"
11939
+ type: "u8"
11769
11940
  },
11770
11941
  {
11771
11942
  name: "_padding2",
11772
11943
  docs: [
11773
- "Padding to ensure struct size is multiple of 8 (for zero_copy alignment after bump field)"
11944
+ "Padding to ensure struct size is u64 aligned (6 bytes)"
11774
11945
  ],
11775
11946
  type: {
11776
11947
  array: [
11777
11948
  "u8",
11778
- 7
11949
+ 6
11779
11950
  ]
11780
11951
  }
11781
11952
  },
11782
- {
11783
- name: "original_mxe_pubkey",
11784
- type: "pubkey"
11785
- },
11786
- {
11787
- name: "backup_mxe_pubkey",
11788
- type: "pubkey"
11789
- },
11790
11953
  {
11791
11954
  name: "bump",
11792
11955
  type: "u8"
@@ -12775,7 +12938,7 @@ const RECOVERY_CLUSTER_ACC_SEED = 'RecoveryClusterAccount';
12775
12938
  * Seed for MxeRecoveryAccount PDA
12776
12939
  * @constant {string}
12777
12940
  */
12778
- const MXE_RECOVERY_ACC_SEED = 'mxe_recovery';
12941
+ const MXE_RECOVERY_ACC_SEED = 'MxeRecoveryAccount';
12779
12942
  /**
12780
12943
  * Maximum number of bytes that can be reallocated per instruction.
12781
12944
  * @constant {number}
@@ -13613,7 +13776,9 @@ exports.Aes256Cipher = Aes256Cipher;
13613
13776
  exports.ArcisModule = ArcisModule;
13614
13777
  exports.ArcisType = ArcisType;
13615
13778
  exports.ArcisValueField = ArcisValueField;
13779
+ exports.CSplRescueCipher = CSplRescueCipher;
13616
13780
  exports.CURVE25519_BASE_FIELD = CURVE25519_BASE_FIELD;
13781
+ exports.CURVE25519_SCALAR_FIELD = CURVE25519_SCALAR_FIELD;
13617
13782
  exports.CURVE25519_SCALAR_FIELD_MODULUS = CURVE25519_SCALAR_FIELD_MODULUS;
13618
13783
  exports.IntegerInfo = IntegerInfo;
13619
13784
  exports.Matrix = Matrix;