@zama-fhe/relayer-sdk 0.2.0-3 → 0.2.0-5

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.
Binary file
package/lib/node.cjs CHANGED
@@ -616,6 +616,7 @@ function checkDeadlineValidity(startTimestamp, durationDays) {
616
616
  }
617
617
  }
618
618
  const userDecryptRequest = (kmsSigners, gatewayChainId, chainId, verifyingContractAddress, aclContractAddress, relayerUrl, provider, options) => async (_handles, privateKey, publicKey, signature, contractAddresses, userAddress, startTimestamp, durationDays) => {
619
+ const extraData = '0x00';
619
620
  let pubKey;
620
621
  let privKey;
621
622
  try {
@@ -671,6 +672,7 @@ const userDecryptRequest = (kmsSigners, gatewayChainId, chainId, verifyingContra
671
672
  userAddress: getAddress$1(userAddress),
672
673
  signature: signatureSanitized,
673
674
  publicKey: publicKeySanitized,
675
+ extraData,
674
676
  };
675
677
  const json = await fetchRelayerJsonRpcPost('USER_DECRYPT', `${relayerUrl}/v1/user-decrypt`, payloadForRequest, options);
676
678
  // assume the KMS Signers have the correct order
@@ -1007,6 +1009,7 @@ const createRelayerEncryptedInput = (aclContractAddress, verifyingContractAddres
1007
1009
  return input.getBits();
1008
1010
  },
1009
1011
  encrypt: async (options) => {
1012
+ const extraData = '0x00';
1010
1013
  const bits = input.getBits();
1011
1014
  const ciphertext = input.encrypt();
1012
1015
  const payload = {
@@ -1014,6 +1017,7 @@ const createRelayerEncryptedInput = (aclContractAddress, verifyingContractAddres
1014
1017
  userAddress: getAddress(userAddress),
1015
1018
  ciphertextWithInputVerification: toHexString(ciphertext),
1016
1019
  contractChainId: ('0x' + chainId.toString(16)),
1020
+ extraData,
1017
1021
  };
1018
1022
  const json = await fetchRelayerJsonRpcPost('INPUT_PROOF', `${relayerUrl}/v1/input-proof`, payload, options);
1019
1023
  if (!isFhevmRelayerInputProofResponse(json)) {
@@ -1050,6 +1054,7 @@ const createRelayerEncryptedInput = (aclContractAddress, verifyingContractAddres
1050
1054
  { name: 'userAddress', type: 'address' },
1051
1055
  { name: 'contractAddress', type: 'address' },
1052
1056
  { name: 'contractChainId', type: 'uint256' },
1057
+ { name: 'extraData', type: 'bytes' },
1053
1058
  ],
1054
1059
  };
1055
1060
  const recoveredAddresses = signatures.map((signature) => {
@@ -1059,6 +1064,7 @@ const createRelayerEncryptedInput = (aclContractAddress, verifyingContractAddres
1059
1064
  userAddress,
1060
1065
  contractAddress,
1061
1066
  contractChainId: chainId,
1067
+ extraData,
1062
1068
  }, sig);
1063
1069
  return recoveredAddress;
1064
1070
  });
@@ -1073,6 +1079,8 @@ const createRelayerEncryptedInput = (aclContractAddress, verifyingContractAddres
1073
1079
  const listHandlesStr = handles.map((i) => toHexString(i));
1074
1080
  listHandlesStr.map((handle) => (inputProof += handle));
1075
1081
  signatures.map((signature) => (inputProof += signature.slice(2))); // removes the '0x' prefix from the `signature` string
1082
+ // Append the extra data to the input proof
1083
+ inputProof += extraData.slice(2);
1076
1084
  return {
1077
1085
  handles,
1078
1086
  inputProof: fromHexString(inputProof),
@@ -1134,6 +1142,7 @@ function deserializeDecryptedResult(handles, decryptedResult) {
1134
1142
  return results;
1135
1143
  }
1136
1144
  const publicDecryptRequest = (kmsSigners, thresholdSigners, gatewayChainId, verifyingContractAddress, aclContractAddress, relayerUrl, provider, options) => async (_handles) => {
1145
+ const extraData = '0x00';
1137
1146
  const acl = new ethers.ethers.Contract(aclContractAddress, aclABI, provider);
1138
1147
  let handles;
1139
1148
  try {
@@ -1155,6 +1164,7 @@ const publicDecryptRequest = (kmsSigners, thresholdSigners, gatewayChainId, veri
1155
1164
  checkEncryptedBits(handles);
1156
1165
  const payloadForRequest = {
1157
1166
  ciphertextHandles: handles,
1167
+ extraData,
1158
1168
  };
1159
1169
  const json = await fetchRelayerJsonRpcPost('PUBLIC_DECRYPT', `${relayerUrl}/v1/public-decrypt`, payloadForRequest, options);
1160
1170
  // verify signatures on decryption:
@@ -1168,6 +1178,7 @@ const publicDecryptRequest = (kmsSigners, thresholdSigners, gatewayChainId, veri
1168
1178
  PublicDecryptVerification: [
1169
1179
  { name: 'ctHandles', type: 'bytes32[]' },
1170
1180
  { name: 'decryptedResult', type: 'bytes' },
1181
+ { name: 'extraData', type: 'bytes' },
1171
1182
  ],
1172
1183
  };
1173
1184
  const result = json.response[0];
@@ -1177,7 +1188,7 @@ const publicDecryptRequest = (kmsSigners, thresholdSigners, gatewayChainId, veri
1177
1188
  const signatures = result.signatures;
1178
1189
  const recoveredAddresses = signatures.map((signature) => {
1179
1190
  const sig = signature.startsWith('0x') ? signature : `0x${signature}`;
1180
- const recoveredAddress = ethers.ethers.verifyTypedData(domain, types, { ctHandles: handles, decryptedResult }, sig);
1191
+ const recoveredAddress = ethers.ethers.verifyTypedData(domain, types, { ctHandles: handles, decryptedResult, extraData }, sig);
1181
1192
  return recoveredAddress;
1182
1193
  });
1183
1194
  const thresholdReached = isThresholdReached(kmsSigners, recoveredAddresses, thresholdSigners);
@@ -1198,9 +1209,11 @@ const publicDecryptRequest = (kmsSigners, thresholdSigners, gatewayChainId, veri
1198
1209
  * @param contractsChainId - The chain ID where the contracts are deployed
1199
1210
  * @param startTimestamp - The timestamp when the decryption permission becomes valid
1200
1211
  * @param durationDays - How many days the decryption permission remains valid
1212
+ * @param delegatedAccount - Optional delegated account address
1201
1213
  * @returns EIP712 typed data structure for user decryption
1202
1214
  */
1203
1215
  const createEIP712 = (verifyingContract, contractsChainId) => (publicKey, contractAddresses, startTimestamp, durationDays, delegatedAccount) => {
1216
+ const extraData = '0x00';
1204
1217
  if (delegatedAccount && !ethers.isAddress(delegatedAccount))
1205
1218
  throw new Error('Invalid delegated account.');
1206
1219
  if (!ethers.isAddress(verifyingContract)) {
@@ -1242,6 +1255,7 @@ const createEIP712 = (verifyingContract, contractsChainId) => (publicKey, contra
1242
1255
  { name: 'contractsChainId', type: 'uint256' },
1243
1256
  { name: 'startTimestamp', type: 'uint256' },
1244
1257
  { name: 'durationDays', type: 'uint256' },
1258
+ { name: 'extraData', type: 'bytes' },
1245
1259
  {
1246
1260
  name: 'delegatedAccount',
1247
1261
  type: 'address',
@@ -1256,6 +1270,7 @@ const createEIP712 = (verifyingContract, contractsChainId) => (publicKey, contra
1256
1270
  contractsChainId,
1257
1271
  startTimestamp: formattedStartTimestamp,
1258
1272
  durationDays: formattedDurationDays,
1273
+ extraData,
1259
1274
  delegatedAccount: delegatedAccount,
1260
1275
  },
1261
1276
  };
@@ -1269,6 +1284,7 @@ const createEIP712 = (verifyingContract, contractsChainId) => (publicKey, contra
1269
1284
  { name: 'contractsChainId', type: 'uint256' },
1270
1285
  { name: 'startTimestamp', type: 'uint256' },
1271
1286
  { name: 'durationDays', type: 'uint256' },
1287
+ { name: 'extraData', type: 'bytes' },
1272
1288
  ],
1273
1289
  },
1274
1290
  primaryType: 'UserDecryptRequestVerification',
@@ -1279,6 +1295,7 @@ const createEIP712 = (verifyingContract, contractsChainId) => (publicKey, contra
1279
1295
  contractsChainId,
1280
1296
  startTimestamp: formattedStartTimestamp,
1281
1297
  durationDays: formattedDurationDays,
1298
+ extraData,
1282
1299
  },
1283
1300
  };
1284
1301
  };
package/lib/node.d.ts CHANGED
@@ -13,6 +13,7 @@ import { TfheCompactPublicKey } from 'node-tfhe';
13
13
  * @param contractsChainId - The chain ID where the contracts are deployed
14
14
  * @param startTimestamp - The timestamp when the decryption permission becomes valid
15
15
  * @param durationDays - How many days the decryption permission remains valid
16
+ * @param delegatedAccount - Optional delegated account address
16
17
  * @returns EIP712 typed data structure for user decryption
17
18
  */
18
19
  export declare const createEIP712: (verifyingContract: string, contractsChainId: number) => (publicKey: string | Uint8Array, contractAddresses: string[], startTimestamp: string | number, durationDays: string | number, delegatedAccount?: string) => EIP712;
package/lib/node.js CHANGED
@@ -595,6 +595,7 @@ function checkDeadlineValidity(startTimestamp, durationDays) {
595
595
  }
596
596
  }
597
597
  const userDecryptRequest = (kmsSigners, gatewayChainId, chainId, verifyingContractAddress, aclContractAddress, relayerUrl, provider, options) => async (_handles, privateKey, publicKey, signature, contractAddresses, userAddress, startTimestamp, durationDays) => {
598
+ const extraData = '0x00';
598
599
  let pubKey;
599
600
  let privKey;
600
601
  try {
@@ -650,6 +651,7 @@ const userDecryptRequest = (kmsSigners, gatewayChainId, chainId, verifyingContra
650
651
  userAddress: getAddress$1(userAddress),
651
652
  signature: signatureSanitized,
652
653
  publicKey: publicKeySanitized,
654
+ extraData,
653
655
  };
654
656
  const json = await fetchRelayerJsonRpcPost('USER_DECRYPT', `${relayerUrl}/v1/user-decrypt`, payloadForRequest, options);
655
657
  // assume the KMS Signers have the correct order
@@ -986,6 +988,7 @@ const createRelayerEncryptedInput = (aclContractAddress, verifyingContractAddres
986
988
  return input.getBits();
987
989
  },
988
990
  encrypt: async (options) => {
991
+ const extraData = '0x00';
989
992
  const bits = input.getBits();
990
993
  const ciphertext = input.encrypt();
991
994
  const payload = {
@@ -993,6 +996,7 @@ const createRelayerEncryptedInput = (aclContractAddress, verifyingContractAddres
993
996
  userAddress: getAddress(userAddress),
994
997
  ciphertextWithInputVerification: toHexString(ciphertext),
995
998
  contractChainId: ('0x' + chainId.toString(16)),
999
+ extraData,
996
1000
  };
997
1001
  const json = await fetchRelayerJsonRpcPost('INPUT_PROOF', `${relayerUrl}/v1/input-proof`, payload, options);
998
1002
  if (!isFhevmRelayerInputProofResponse(json)) {
@@ -1029,6 +1033,7 @@ const createRelayerEncryptedInput = (aclContractAddress, verifyingContractAddres
1029
1033
  { name: 'userAddress', type: 'address' },
1030
1034
  { name: 'contractAddress', type: 'address' },
1031
1035
  { name: 'contractChainId', type: 'uint256' },
1036
+ { name: 'extraData', type: 'bytes' },
1032
1037
  ],
1033
1038
  };
1034
1039
  const recoveredAddresses = signatures.map((signature) => {
@@ -1038,6 +1043,7 @@ const createRelayerEncryptedInput = (aclContractAddress, verifyingContractAddres
1038
1043
  userAddress,
1039
1044
  contractAddress,
1040
1045
  contractChainId: chainId,
1046
+ extraData,
1041
1047
  }, sig);
1042
1048
  return recoveredAddress;
1043
1049
  });
@@ -1052,6 +1058,8 @@ const createRelayerEncryptedInput = (aclContractAddress, verifyingContractAddres
1052
1058
  const listHandlesStr = handles.map((i) => toHexString(i));
1053
1059
  listHandlesStr.map((handle) => (inputProof += handle));
1054
1060
  signatures.map((signature) => (inputProof += signature.slice(2))); // removes the '0x' prefix from the `signature` string
1061
+ // Append the extra data to the input proof
1062
+ inputProof += extraData.slice(2);
1055
1063
  return {
1056
1064
  handles,
1057
1065
  inputProof: fromHexString(inputProof),
@@ -1113,6 +1121,7 @@ function deserializeDecryptedResult(handles, decryptedResult) {
1113
1121
  return results;
1114
1122
  }
1115
1123
  const publicDecryptRequest = (kmsSigners, thresholdSigners, gatewayChainId, verifyingContractAddress, aclContractAddress, relayerUrl, provider, options) => async (_handles) => {
1124
+ const extraData = '0x00';
1116
1125
  const acl = new ethers.Contract(aclContractAddress, aclABI, provider);
1117
1126
  let handles;
1118
1127
  try {
@@ -1134,6 +1143,7 @@ const publicDecryptRequest = (kmsSigners, thresholdSigners, gatewayChainId, veri
1134
1143
  checkEncryptedBits(handles);
1135
1144
  const payloadForRequest = {
1136
1145
  ciphertextHandles: handles,
1146
+ extraData,
1137
1147
  };
1138
1148
  const json = await fetchRelayerJsonRpcPost('PUBLIC_DECRYPT', `${relayerUrl}/v1/public-decrypt`, payloadForRequest, options);
1139
1149
  // verify signatures on decryption:
@@ -1147,6 +1157,7 @@ const publicDecryptRequest = (kmsSigners, thresholdSigners, gatewayChainId, veri
1147
1157
  PublicDecryptVerification: [
1148
1158
  { name: 'ctHandles', type: 'bytes32[]' },
1149
1159
  { name: 'decryptedResult', type: 'bytes' },
1160
+ { name: 'extraData', type: 'bytes' },
1150
1161
  ],
1151
1162
  };
1152
1163
  const result = json.response[0];
@@ -1156,7 +1167,7 @@ const publicDecryptRequest = (kmsSigners, thresholdSigners, gatewayChainId, veri
1156
1167
  const signatures = result.signatures;
1157
1168
  const recoveredAddresses = signatures.map((signature) => {
1158
1169
  const sig = signature.startsWith('0x') ? signature : `0x${signature}`;
1159
- const recoveredAddress = ethers.verifyTypedData(domain, types, { ctHandles: handles, decryptedResult }, sig);
1170
+ const recoveredAddress = ethers.verifyTypedData(domain, types, { ctHandles: handles, decryptedResult, extraData }, sig);
1160
1171
  return recoveredAddress;
1161
1172
  });
1162
1173
  const thresholdReached = isThresholdReached(kmsSigners, recoveredAddresses, thresholdSigners);
@@ -1177,9 +1188,11 @@ const publicDecryptRequest = (kmsSigners, thresholdSigners, gatewayChainId, veri
1177
1188
  * @param contractsChainId - The chain ID where the contracts are deployed
1178
1189
  * @param startTimestamp - The timestamp when the decryption permission becomes valid
1179
1190
  * @param durationDays - How many days the decryption permission remains valid
1191
+ * @param delegatedAccount - Optional delegated account address
1180
1192
  * @returns EIP712 typed data structure for user decryption
1181
1193
  */
1182
1194
  const createEIP712 = (verifyingContract, contractsChainId) => (publicKey, contractAddresses, startTimestamp, durationDays, delegatedAccount) => {
1195
+ const extraData = '0x00';
1183
1196
  if (delegatedAccount && !isAddress(delegatedAccount))
1184
1197
  throw new Error('Invalid delegated account.');
1185
1198
  if (!isAddress(verifyingContract)) {
@@ -1221,6 +1234,7 @@ const createEIP712 = (verifyingContract, contractsChainId) => (publicKey, contra
1221
1234
  { name: 'contractsChainId', type: 'uint256' },
1222
1235
  { name: 'startTimestamp', type: 'uint256' },
1223
1236
  { name: 'durationDays', type: 'uint256' },
1237
+ { name: 'extraData', type: 'bytes' },
1224
1238
  {
1225
1239
  name: 'delegatedAccount',
1226
1240
  type: 'address',
@@ -1235,6 +1249,7 @@ const createEIP712 = (verifyingContract, contractsChainId) => (publicKey, contra
1235
1249
  contractsChainId,
1236
1250
  startTimestamp: formattedStartTimestamp,
1237
1251
  durationDays: formattedDurationDays,
1252
+ extraData,
1238
1253
  delegatedAccount: delegatedAccount,
1239
1254
  },
1240
1255
  };
@@ -1248,6 +1263,7 @@ const createEIP712 = (verifyingContract, contractsChainId) => (publicKey, contra
1248
1263
  { name: 'contractsChainId', type: 'uint256' },
1249
1264
  { name: 'startTimestamp', type: 'uint256' },
1250
1265
  { name: 'durationDays', type: 'uint256' },
1266
+ { name: 'extraData', type: 'bytes' },
1251
1267
  ],
1252
1268
  },
1253
1269
  primaryType: 'UserDecryptRequestVerification',
@@ -1258,6 +1274,7 @@ const createEIP712 = (verifyingContract, contractsChainId) => (publicKey, contra
1258
1274
  contractsChainId,
1259
1275
  startTimestamp: formattedStartTimestamp,
1260
1276
  durationDays: formattedDurationDays,
1277
+ extraData,
1261
1278
  },
1262
1279
  };
1263
1280
  };
package/lib/web.d.ts CHANGED
@@ -12,6 +12,7 @@ import { InitInput as TFHEInput } from 'tfhe';
12
12
  * @param contractsChainId - The chain ID where the contracts are deployed
13
13
  * @param startTimestamp - The timestamp when the decryption permission becomes valid
14
14
  * @param durationDays - How many days the decryption permission remains valid
15
+ * @param delegatedAccount - Optional delegated account address
15
16
  * @returns EIP712 typed data structure for user decryption
16
17
  */
17
18
  export declare const createEIP712: (verifyingContract: string, contractsChainId: number) => (publicKey: string | Uint8Array, contractAddresses: string[], startTimestamp: string | number, durationDays: string | number, delegatedAccount?: string) => EIP712;
package/lib/web.js CHANGED
@@ -15065,7 +15065,8 @@ function u8vec_to_ml_kem_pke_sk(v) {
15065
15065
  * [
15066
15066
  * {
15067
15067
  * signature: '69e7e040cab157aa819015b321c012dccb1545ffefd325b359b492653f0347517e28e66c572cdc299e259024329859ff9fcb0096e1ce072af0b6e1ca1fe25ec6',
15068
- * payload: '0100000029...'
15068
+ * payload: '0100000029...',
15069
+ * extra_data: '01234...',
15069
15070
  * }
15070
15071
  * ]
15071
15072
  * ```
@@ -15571,7 +15572,8 @@ class UserDecryptionResponse {
15571
15572
  * struct UserDecryptResponseVerification {
15572
15573
  * bytes publicKey;
15573
15574
  * uint256\[\] ctHandles;
15574
- * bytes userDecryptedShare;
15575
+ * bytes userDecryptedShare; // serialization of payload
15576
+ * bytes extraData;
15575
15577
  * }
15576
15578
  * @returns {Uint8Array}
15577
15579
  */
@@ -15587,7 +15589,8 @@ class UserDecryptionResponse {
15587
15589
  * struct UserDecryptResponseVerification {
15588
15590
  * bytes publicKey;
15589
15591
  * uint256\[\] ctHandles;
15590
- * bytes userDecryptedShare;
15592
+ * bytes userDecryptedShare; // serialization of payload
15593
+ * bytes extraData;
15591
15594
  * }
15592
15595
  * @param {Uint8Array} arg0
15593
15596
  */
@@ -15616,6 +15619,25 @@ class UserDecryptionResponse {
15616
15619
  }
15617
15620
  wasm.__wbg_set_userdecryptionresponse_payload(this.__wbg_ptr, ptr0);
15618
15621
  }
15622
+ /**
15623
+ * Extra data used in the EIP712 signature - external_signature.
15624
+ * @returns {Uint8Array}
15625
+ */
15626
+ get extra_data() {
15627
+ const ret = wasm.__wbg_get_userdecryptionresponse_extra_data(this.__wbg_ptr);
15628
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
15629
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
15630
+ return v1;
15631
+ }
15632
+ /**
15633
+ * Extra data used in the EIP712 signature - external_signature.
15634
+ * @param {Uint8Array} arg0
15635
+ */
15636
+ set extra_data(arg0) {
15637
+ const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
15638
+ const len0 = WASM_VECTOR_LEN;
15639
+ wasm.__wbg_set_eip712domainmsg_chain_id(this.__wbg_ptr, ptr0, len0);
15640
+ }
15619
15641
  }
15620
15642
 
15621
15643
  const UserDecryptionResponsePayloadFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -16704,6 +16726,7 @@ function checkDeadlineValidity(startTimestamp, durationDays) {
16704
16726
  }
16705
16727
  }
16706
16728
  const userDecryptRequest = (kmsSigners, gatewayChainId, chainId, verifyingContractAddress, aclContractAddress, relayerUrl, provider, options) => async (_handles, privateKey, publicKey, signature, contractAddresses, userAddress, startTimestamp, durationDays) => {
16729
+ const extraData = '0x00';
16707
16730
  let pubKey;
16708
16731
  let privKey;
16709
16732
  try {
@@ -16759,6 +16782,7 @@ const userDecryptRequest = (kmsSigners, gatewayChainId, chainId, verifyingContra
16759
16782
  userAddress: getAddress$1(userAddress),
16760
16783
  signature: signatureSanitized,
16761
16784
  publicKey: publicKeySanitized,
16785
+ extraData,
16762
16786
  };
16763
16787
  const json = await fetchRelayerJsonRpcPost('USER_DECRYPT', `${relayerUrl}/v1/user-decrypt`, payloadForRequest, options);
16764
16788
  // assume the KMS Signers have the correct order
@@ -17095,6 +17119,7 @@ const createRelayerEncryptedInput = (aclContractAddress, verifyingContractAddres
17095
17119
  return input.getBits();
17096
17120
  },
17097
17121
  encrypt: async (options) => {
17122
+ const extraData = '0x00';
17098
17123
  const bits = input.getBits();
17099
17124
  const ciphertext = input.encrypt();
17100
17125
  const payload = {
@@ -17102,6 +17127,7 @@ const createRelayerEncryptedInput = (aclContractAddress, verifyingContractAddres
17102
17127
  userAddress: getAddress(userAddress),
17103
17128
  ciphertextWithInputVerification: toHexString(ciphertext),
17104
17129
  contractChainId: ('0x' + chainId.toString(16)),
17130
+ extraData,
17105
17131
  };
17106
17132
  const json = await fetchRelayerJsonRpcPost('INPUT_PROOF', `${relayerUrl}/v1/input-proof`, payload, options);
17107
17133
  if (!isFhevmRelayerInputProofResponse(json)) {
@@ -17138,6 +17164,7 @@ const createRelayerEncryptedInput = (aclContractAddress, verifyingContractAddres
17138
17164
  { name: 'userAddress', type: 'address' },
17139
17165
  { name: 'contractAddress', type: 'address' },
17140
17166
  { name: 'contractChainId', type: 'uint256' },
17167
+ { name: 'extraData', type: 'bytes' },
17141
17168
  ],
17142
17169
  };
17143
17170
  const recoveredAddresses = signatures.map((signature) => {
@@ -17147,6 +17174,7 @@ const createRelayerEncryptedInput = (aclContractAddress, verifyingContractAddres
17147
17174
  userAddress,
17148
17175
  contractAddress,
17149
17176
  contractChainId: chainId,
17177
+ extraData,
17150
17178
  }, sig);
17151
17179
  return recoveredAddress;
17152
17180
  });
@@ -17161,6 +17189,8 @@ const createRelayerEncryptedInput = (aclContractAddress, verifyingContractAddres
17161
17189
  const listHandlesStr = handles.map((i) => toHexString(i));
17162
17190
  listHandlesStr.map((handle) => (inputProof += handle));
17163
17191
  signatures.map((signature) => (inputProof += signature.slice(2))); // removes the '0x' prefix from the `signature` string
17192
+ // Append the extra data to the input proof
17193
+ inputProof += extraData.slice(2);
17164
17194
  return {
17165
17195
  handles,
17166
17196
  inputProof: fromHexString(inputProof),
@@ -17222,6 +17252,7 @@ function deserializeDecryptedResult(handles, decryptedResult) {
17222
17252
  return results;
17223
17253
  }
17224
17254
  const publicDecryptRequest = (kmsSigners, thresholdSigners, gatewayChainId, verifyingContractAddress, aclContractAddress, relayerUrl, provider, options) => async (_handles) => {
17255
+ const extraData = '0x00';
17225
17256
  const acl = new ethers.Contract(aclContractAddress, aclABI, provider);
17226
17257
  let handles;
17227
17258
  try {
@@ -17243,6 +17274,7 @@ const publicDecryptRequest = (kmsSigners, thresholdSigners, gatewayChainId, veri
17243
17274
  checkEncryptedBits(handles);
17244
17275
  const payloadForRequest = {
17245
17276
  ciphertextHandles: handles,
17277
+ extraData,
17246
17278
  };
17247
17279
  const json = await fetchRelayerJsonRpcPost('PUBLIC_DECRYPT', `${relayerUrl}/v1/public-decrypt`, payloadForRequest, options);
17248
17280
  // verify signatures on decryption:
@@ -17256,6 +17288,7 @@ const publicDecryptRequest = (kmsSigners, thresholdSigners, gatewayChainId, veri
17256
17288
  PublicDecryptVerification: [
17257
17289
  { name: 'ctHandles', type: 'bytes32[]' },
17258
17290
  { name: 'decryptedResult', type: 'bytes' },
17291
+ { name: 'extraData', type: 'bytes' },
17259
17292
  ],
17260
17293
  };
17261
17294
  const result = json.response[0];
@@ -17265,7 +17298,7 @@ const publicDecryptRequest = (kmsSigners, thresholdSigners, gatewayChainId, veri
17265
17298
  const signatures = result.signatures;
17266
17299
  const recoveredAddresses = signatures.map((signature) => {
17267
17300
  const sig = signature.startsWith('0x') ? signature : `0x${signature}`;
17268
- const recoveredAddress = ethers.verifyTypedData(domain, types, { ctHandles: handles, decryptedResult }, sig);
17301
+ const recoveredAddress = ethers.verifyTypedData(domain, types, { ctHandles: handles, decryptedResult, extraData }, sig);
17269
17302
  return recoveredAddress;
17270
17303
  });
17271
17304
  const thresholdReached = isThresholdReached(kmsSigners, recoveredAddresses, thresholdSigners);
@@ -17286,9 +17319,11 @@ const publicDecryptRequest = (kmsSigners, thresholdSigners, gatewayChainId, veri
17286
17319
  * @param contractsChainId - The chain ID where the contracts are deployed
17287
17320
  * @param startTimestamp - The timestamp when the decryption permission becomes valid
17288
17321
  * @param durationDays - How many days the decryption permission remains valid
17322
+ * @param delegatedAccount - Optional delegated account address
17289
17323
  * @returns EIP712 typed data structure for user decryption
17290
17324
  */
17291
17325
  const createEIP712 = (verifyingContract, contractsChainId) => (publicKey, contractAddresses, startTimestamp, durationDays, delegatedAccount) => {
17326
+ const extraData = '0x00';
17292
17327
  if (delegatedAccount && !isAddress(delegatedAccount))
17293
17328
  throw new Error('Invalid delegated account.');
17294
17329
  if (!isAddress(verifyingContract)) {
@@ -17330,6 +17365,7 @@ const createEIP712 = (verifyingContract, contractsChainId) => (publicKey, contra
17330
17365
  { name: 'contractsChainId', type: 'uint256' },
17331
17366
  { name: 'startTimestamp', type: 'uint256' },
17332
17367
  { name: 'durationDays', type: 'uint256' },
17368
+ { name: 'extraData', type: 'bytes' },
17333
17369
  {
17334
17370
  name: 'delegatedAccount',
17335
17371
  type: 'address',
@@ -17344,6 +17380,7 @@ const createEIP712 = (verifyingContract, contractsChainId) => (publicKey, contra
17344
17380
  contractsChainId,
17345
17381
  startTimestamp: formattedStartTimestamp,
17346
17382
  durationDays: formattedDurationDays,
17383
+ extraData,
17347
17384
  delegatedAccount: delegatedAccount,
17348
17385
  },
17349
17386
  };
@@ -17357,6 +17394,7 @@ const createEIP712 = (verifyingContract, contractsChainId) => (publicKey, contra
17357
17394
  { name: 'contractsChainId', type: 'uint256' },
17358
17395
  { name: 'startTimestamp', type: 'uint256' },
17359
17396
  { name: 'durationDays', type: 'uint256' },
17397
+ { name: 'extraData', type: 'bytes' },
17360
17398
  ],
17361
17399
  },
17362
17400
  primaryType: 'UserDecryptRequestVerification',
@@ -17367,6 +17405,7 @@ const createEIP712 = (verifyingContract, contractsChainId) => (publicKey, contra
17367
17405
  contractsChainId,
17368
17406
  startTimestamp: formattedStartTimestamp,
17369
17407
  durationDays: formattedDurationDays,
17408
+ extraData,
17370
17409
  },
17371
17410
  };
17372
17411
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zama-fhe/relayer-sdk",
3
- "version": "0.2.0-3",
3
+ "version": "0.2.0-5",
4
4
  "description": "fhevm Relayer SDK",
5
5
  "main": "lib/node.js",
6
6
  "types": "lib/node.d.ts",
@@ -64,8 +64,8 @@
64
64
  "wasm-feature-detect": "^1.8.0",
65
65
  "node-tfhe": "1.3.0",
66
66
  "tfhe": "1.3.0",
67
- "node-tkms": "0.11.0-24",
68
- "tkms": "0.11.0-24"
67
+ "node-tkms": "0.11.0-26",
68
+ "tkms": "0.11.0-26"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@fetch-mock/jest": "0.2.16",