@ocap/merkle-tree 1.30.26 → 1.31.0

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/esm/index.mjs CHANGED
@@ -95,7 +95,10 @@ var MerkleTree = class MerkleTree {
95
95
  this.encodePacked = encodePacked;
96
96
  }
97
97
  static {
98
- this.getListHash = (list) => list.length ? keccak256(list.map((x) => x.startsWith("0x") ? x : `0x${x}`).reduce((acc, x) => encodePacked({
98
+ this.getListHash = (list) => list.length ? keccak256(list.map((x) => {
99
+ if (/^(0x)?[0-9a-f]+$/i.test(x) && x.replace(/^0x/i, "").length % 2 === 0) return x.startsWith("0x") ? x : `0x${x}`;
100
+ return `0x${Buffer.from(x, "utf8").toString("hex")}`;
101
+ }).reduce((acc, x) => encodePacked({
99
102
  type: "bytes",
100
103
  value: acc
101
104
  }, {
@@ -119,16 +122,23 @@ var MerkleTree = class MerkleTree {
119
122
  })) : "";
120
123
  }
121
124
  static {
122
- this.getBlockMerkleTree = (txs) => txs.length ? new MerkleTree(txs.map((x) => encodePacked({
123
- type: "bytes32",
124
- value: x.hash.startsWith("0x") ? x.hash : `0x${x.hash}`
125
- }, {
126
- type: "address",
127
- value: x.to
128
- }, {
129
- type: "uint256",
130
- value: x.amount
131
- }))) : {
125
+ this.getBlockMerkleTree = (txs) => txs.length ? new MerkleTree(txs.map((x) => {
126
+ const toVal = x.to || "";
127
+ const isEvmAddr = /^(0x)?[0-9a-f]{40}$/i.test(toVal);
128
+ return encodePacked({
129
+ type: "bytes32",
130
+ value: x.hash.startsWith("0x") ? x.hash : `0x${x.hash}`
131
+ }, isEvmAddr ? {
132
+ type: "address",
133
+ value: toVal
134
+ } : {
135
+ type: "string",
136
+ value: toVal
137
+ }, {
138
+ type: "uint256",
139
+ value: x.amount
140
+ });
141
+ })) : {
132
142
  getHexRoot: () => "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
133
143
  getHexProof: () => [],
134
144
  elements: [],
package/lib/index.cjs CHANGED
@@ -96,7 +96,10 @@ var MerkleTree = class MerkleTree {
96
96
  this.encodePacked = require_abi.encodePacked;
97
97
  }
98
98
  static {
99
- this.getListHash = (list) => list.length ? keccak256(list.map((x) => x.startsWith("0x") ? x : `0x${x}`).reduce((acc, x) => require_abi.encodePacked({
99
+ this.getListHash = (list) => list.length ? keccak256(list.map((x) => {
100
+ if (/^(0x)?[0-9a-f]+$/i.test(x) && x.replace(/^0x/i, "").length % 2 === 0) return x.startsWith("0x") ? x : `0x${x}`;
101
+ return `0x${Buffer.from(x, "utf8").toString("hex")}`;
102
+ }).reduce((acc, x) => require_abi.encodePacked({
100
103
  type: "bytes",
101
104
  value: acc
102
105
  }, {
@@ -120,16 +123,23 @@ var MerkleTree = class MerkleTree {
120
123
  })) : "";
121
124
  }
122
125
  static {
123
- this.getBlockMerkleTree = (txs) => txs.length ? new MerkleTree(txs.map((x) => require_abi.encodePacked({
124
- type: "bytes32",
125
- value: x.hash.startsWith("0x") ? x.hash : `0x${x.hash}`
126
- }, {
127
- type: "address",
128
- value: x.to
129
- }, {
130
- type: "uint256",
131
- value: x.amount
132
- }))) : {
126
+ this.getBlockMerkleTree = (txs) => txs.length ? new MerkleTree(txs.map((x) => {
127
+ const toVal = x.to || "";
128
+ const isEvmAddr = /^(0x)?[0-9a-f]{40}$/i.test(toVal);
129
+ return require_abi.encodePacked({
130
+ type: "bytes32",
131
+ value: x.hash.startsWith("0x") ? x.hash : `0x${x.hash}`
132
+ }, isEvmAddr ? {
133
+ type: "address",
134
+ value: toVal
135
+ } : {
136
+ type: "string",
137
+ value: toVal
138
+ }, {
139
+ type: "uint256",
140
+ value: x.amount
141
+ });
142
+ })) : {
133
143
  getHexRoot: () => "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
134
144
  getHexProof: () => [],
135
145
  elements: [],
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.30.26",
6
+ "version": "1.31.0",
7
7
  "description": "Merkle tree implementation that powers DID Rollup",
8
8
  "main": "./lib/index.cjs",
9
9
  "module": "./esm/index.mjs",
@@ -36,7 +36,7 @@
36
36
  "tsdown": "^0.18.4"
37
37
  },
38
38
  "dependencies": {
39
- "@ocap/mcrypto": "1.30.26",
40
- "@ocap/util": "1.30.26"
39
+ "@ocap/mcrypto": "1.31.0",
40
+ "@ocap/util": "1.31.0"
41
41
  }
42
42
  }