@kohaku-eth/tornado-cash 0.1.0-alpha.26 → 0.1.0-alpha.27

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/dist/index.js CHANGED
@@ -843,20 +843,20 @@ function canonicalRS(sig) {
843
843
  const sLow = sValue > SECP256K1_HALF_N ? SECP256K1_N - sValue : sValue;
844
844
  return concat([toBytes(r, { size: 32 }), toBytes(sLow, { size: 32 })]);
845
845
  }
846
- function trunc31(tag, chainId, poolAddress, sig) {
846
+ function trunc31(tag, poolAddress, sig) {
847
847
  const digest = keccak256(concat([
848
848
  stringToBytes(tag),
849
- numberToBytesLE(chainId, 8),
850
849
  toBytes(poolAddress, { size: 20 }),
851
850
  canonicalRS(sig)
852
851
  ]));
853
852
  return hexToBytes(slice(digest, 0, 31));
854
853
  }
855
- function buildNoteEnvelope(nonce) {
854
+ function buildNoteEnvelope(nonce, chainId) {
856
855
  return {
857
856
  domain: {
858
857
  name: "TornadoCash Keychain",
859
858
  version: "1",
859
+ chainId,
860
860
  salt: TORNADO_DOMAIN_SALT
861
861
  },
862
862
  types: NOTE_TYPES,
@@ -883,20 +883,21 @@ async function SignatureSecretManager({
883
883
  }) {
884
884
  const envelopeSigner = signer ?? new KeystoreEnvelopeSigner(host.keystore, accountIndex);
885
885
  const sigCache = /* @__PURE__ */ new Map();
886
- const signNonce = (nonce) => {
887
- const hit = sigCache.get(nonce);
886
+ const signNonce = (nonce, chainId) => {
887
+ const key = `${chainId}:${nonce}`;
888
+ const hit = sigCache.get(key);
888
889
  if (hit) return hit;
889
- const pending = envelopeSigner.signEnvelope(buildNoteEnvelope(nonce)).catch((err) => {
890
- sigCache.delete(nonce);
890
+ const pending = envelopeSigner.signEnvelope(buildNoteEnvelope(nonce, chainId)).catch((err) => {
891
+ sigCache.delete(key);
891
892
  throw err;
892
893
  });
893
- sigCache.set(nonce, pending);
894
+ sigCache.set(key, pending);
894
895
  return pending;
895
896
  };
896
897
  const getSignatureSecrets = async ({ nonce, chainId, poolAddress }) => {
897
- const sig = await signNonce(nonce);
898
- const nullifierBytes = trunc31("nullifier", chainId, poolAddress, sig);
899
- const secretBytes = trunc31("secret", chainId, poolAddress, sig);
898
+ const sig = await signNonce(nonce, chainId);
899
+ const nullifierBytes = trunc31("nullifier", poolAddress, sig);
900
+ const secretBytes = trunc31("secret", poolAddress, sig);
900
901
  const preimage = new Uint8Array(62);
901
902
  preimage.set(nullifierBytes, 0);
902
903
  preimage.set(secretBytes, 31);
@@ -908,8 +909,8 @@ async function SignatureSecretManager({
908
909
  };
909
910
  };
910
911
  const deriveSignatureEphemeralSigner = async ({ nonce, chainId, poolAddress }) => {
911
- const sig = await signNonce(nonce);
912
- const key = trunc31("signer", chainId, poolAddress, sig);
912
+ const sig = await signNonce(nonce, chainId);
913
+ const key = trunc31("signer", poolAddress, sig);
913
914
  return `0x00${bytesToHex(key)}`;
914
915
  };
915
916
  return { getSignatureSecrets, deriveSignatureEphemeralSigner };
@@ -17518,20 +17518,20 @@ function canonicalRS(sig) {
17518
17518
  const sLow = sValue > SECP256K1_HALF_N ? SECP256K1_N - sValue : sValue;
17519
17519
  return concat([toBytes2(r, { size: 32 }), toBytes2(sLow, { size: 32 })]);
17520
17520
  }
17521
- function trunc31(tag, chainId, poolAddress, sig) {
17521
+ function trunc31(tag, poolAddress, sig) {
17522
17522
  const digest = keccak256(concat([
17523
17523
  stringToBytes(tag),
17524
- numberToBytesLE(chainId, 8),
17525
17524
  toBytes2(poolAddress, { size: 20 }),
17526
17525
  canonicalRS(sig)
17527
17526
  ]));
17528
17527
  return hexToBytes4(slice(digest, 0, 31));
17529
17528
  }
17530
- function buildNoteEnvelope(nonce) {
17529
+ function buildNoteEnvelope(nonce, chainId) {
17531
17530
  return {
17532
17531
  domain: {
17533
17532
  name: "TornadoCash Keychain",
17534
17533
  version: "1",
17534
+ chainId,
17535
17535
  salt: TORNADO_DOMAIN_SALT
17536
17536
  },
17537
17537
  types: NOTE_TYPES,
@@ -17558,20 +17558,21 @@ async function SignatureSecretManager({
17558
17558
  }) {
17559
17559
  const envelopeSigner = signer ?? new KeystoreEnvelopeSigner(host.keystore, accountIndex);
17560
17560
  const sigCache = /* @__PURE__ */ new Map();
17561
- const signNonce = (nonce) => {
17562
- const hit = sigCache.get(nonce);
17561
+ const signNonce = (nonce, chainId) => {
17562
+ const key = `${chainId}:${nonce}`;
17563
+ const hit = sigCache.get(key);
17563
17564
  if (hit) return hit;
17564
- const pending = envelopeSigner.signEnvelope(buildNoteEnvelope(nonce)).catch((err) => {
17565
- sigCache.delete(nonce);
17565
+ const pending = envelopeSigner.signEnvelope(buildNoteEnvelope(nonce, chainId)).catch((err) => {
17566
+ sigCache.delete(key);
17566
17567
  throw err;
17567
17568
  });
17568
- sigCache.set(nonce, pending);
17569
+ sigCache.set(key, pending);
17569
17570
  return pending;
17570
17571
  };
17571
17572
  const getSignatureSecrets = async ({ nonce, chainId, poolAddress }) => {
17572
- const sig = await signNonce(nonce);
17573
- const nullifierBytes = trunc31("nullifier", chainId, poolAddress, sig);
17574
- const secretBytes = trunc31("secret", chainId, poolAddress, sig);
17573
+ const sig = await signNonce(nonce, chainId);
17574
+ const nullifierBytes = trunc31("nullifier", poolAddress, sig);
17575
+ const secretBytes = trunc31("secret", poolAddress, sig);
17575
17576
  const preimage = new Uint8Array(62);
17576
17577
  preimage.set(nullifierBytes, 0);
17577
17578
  preimage.set(secretBytes, 31);
@@ -17583,8 +17584,8 @@ async function SignatureSecretManager({
17583
17584
  };
17584
17585
  };
17585
17586
  const deriveSignatureEphemeralSigner = async ({ nonce, chainId, poolAddress }) => {
17586
- const sig = await signNonce(nonce);
17587
- const key = trunc31("signer", chainId, poolAddress, sig);
17587
+ const sig = await signNonce(nonce, chainId);
17588
+ const key = trunc31("signer", poolAddress, sig);
17588
17589
  return `0x00${bytesToHex2(key)}`;
17589
17590
  };
17590
17591
  return { getSignatureSecrets, deriveSignatureEphemeralSigner };
@@ -17090,20 +17090,20 @@ function canonicalRS(sig) {
17090
17090
  const sLow = sValue > SECP256K1_HALF_N ? SECP256K1_N - sValue : sValue;
17091
17091
  return concat([toBytes2(r, { size: 32 }), toBytes2(sLow, { size: 32 })]);
17092
17092
  }
17093
- function trunc31(tag, chainId, poolAddress, sig) {
17093
+ function trunc31(tag, poolAddress, sig) {
17094
17094
  const digest = keccak256(concat([
17095
17095
  stringToBytes(tag),
17096
- numberToBytesLE(chainId, 8),
17097
17096
  toBytes2(poolAddress, { size: 20 }),
17098
17097
  canonicalRS(sig)
17099
17098
  ]));
17100
17099
  return hexToBytes4(slice(digest, 0, 31));
17101
17100
  }
17102
- function buildNoteEnvelope(nonce) {
17101
+ function buildNoteEnvelope(nonce, chainId) {
17103
17102
  return {
17104
17103
  domain: {
17105
17104
  name: "TornadoCash Keychain",
17106
17105
  version: "1",
17106
+ chainId,
17107
17107
  salt: TORNADO_DOMAIN_SALT
17108
17108
  },
17109
17109
  types: NOTE_TYPES,
@@ -17130,20 +17130,21 @@ async function SignatureSecretManager({
17130
17130
  }) {
17131
17131
  const envelopeSigner = signer ?? new KeystoreEnvelopeSigner(host.keystore, accountIndex);
17132
17132
  const sigCache = /* @__PURE__ */ new Map();
17133
- const signNonce = (nonce) => {
17134
- const hit = sigCache.get(nonce);
17133
+ const signNonce = (nonce, chainId) => {
17134
+ const key = `${chainId}:${nonce}`;
17135
+ const hit = sigCache.get(key);
17135
17136
  if (hit) return hit;
17136
- const pending = envelopeSigner.signEnvelope(buildNoteEnvelope(nonce)).catch((err) => {
17137
- sigCache.delete(nonce);
17137
+ const pending = envelopeSigner.signEnvelope(buildNoteEnvelope(nonce, chainId)).catch((err) => {
17138
+ sigCache.delete(key);
17138
17139
  throw err;
17139
17140
  });
17140
- sigCache.set(nonce, pending);
17141
+ sigCache.set(key, pending);
17141
17142
  return pending;
17142
17143
  };
17143
17144
  const getSignatureSecrets = async ({ nonce, chainId, poolAddress }) => {
17144
- const sig = await signNonce(nonce);
17145
- const nullifierBytes = trunc31("nullifier", chainId, poolAddress, sig);
17146
- const secretBytes = trunc31("secret", chainId, poolAddress, sig);
17145
+ const sig = await signNonce(nonce, chainId);
17146
+ const nullifierBytes = trunc31("nullifier", poolAddress, sig);
17147
+ const secretBytes = trunc31("secret", poolAddress, sig);
17147
17148
  const preimage = new Uint8Array(62);
17148
17149
  preimage.set(nullifierBytes, 0);
17149
17150
  preimage.set(secretBytes, 31);
@@ -17155,8 +17156,8 @@ async function SignatureSecretManager({
17155
17156
  };
17156
17157
  };
17157
17158
  const deriveSignatureEphemeralSigner = async ({ nonce, chainId, poolAddress }) => {
17158
- const sig = await signNonce(nonce);
17159
- const key = trunc31("signer", chainId, poolAddress, sig);
17159
+ const sig = await signNonce(nonce, chainId);
17160
+ const key = trunc31("signer", poolAddress, sig);
17160
17161
  return `0x00${bytesToHex2(key)}`;
17161
17162
  };
17162
17163
  return { getSignatureSecrets, deriveSignatureEphemeralSigner };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kohaku-eth/tornado-cash",
3
- "version": "0.1.0-alpha.26",
3
+ "version": "0.1.0-alpha.27",
4
4
  "description": "Tornado Cash Shielded Pool Kohaku Plugin",
5
5
  "type": "module",
6
6
  "private": false,