@layerzerolabs/onesig-core 0.0.2 → 0.0.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/dist/index.d.ts CHANGED
@@ -1,14 +1,13 @@
1
1
  import { BigNumber } from 'ethers';
2
2
  import { MerkleTree } from 'merkletreejs';
3
+ export { MerkleTree } from 'merkletreejs';
3
4
  import { TypedDataSigner } from '@ethersproject/abstract-signer';
4
5
 
5
- interface BaseLeafData<Target = string, Call = {
6
- [key: string]: any;
7
- }> {
8
- nonce: number;
9
- chainId: number;
10
- target: Target;
11
- calls: Call[];
6
+ interface BaseLeafData<TargetAddressType = unknown, CallData = unknown> {
7
+ nonce: bigint;
8
+ chainId: bigint;
9
+ targetOneSigAddress: TargetAddressType;
10
+ calls: CallData[];
12
11
  }
13
12
  type SigningOptions = {
14
13
  seed: string | Uint8Array;
@@ -19,7 +18,8 @@ interface GenerateLeafsResult<Leaf extends BaseLeafData> {
19
18
  leafs: Leaf[];
20
19
  }
21
20
  declare function makeOneSigTree(input: GenerateLeafsResult<any>[]): MerkleTree;
21
+ declare function compareAddresses(a: string, b: string): number;
22
22
  declare function mergeOneSigSignatures(signatures: string[]): Promise<string>;
23
23
  declare function signOneSigTree(tree: MerkleTree, _signers: TypedDataSigner[] | TypedDataSigner, { seed, expiry }: SigningOptions): Promise<string>;
24
24
 
25
- export { type BaseLeafData, type GenerateLeafsResult, type SigningOptions, makeOneSigTree, mergeOneSigSignatures, signOneSigTree };
25
+ export { type BaseLeafData, type GenerateLeafsResult, type SigningOptions, compareAddresses, makeOneSigTree, mergeOneSigSignatures, signOneSigTree };
package/dist/index.js CHANGED
@@ -15459,6 +15459,8 @@ var require_dist = __commonJS({
15459
15459
  // src/index.ts
15460
15460
  var src_exports = {};
15461
15461
  __export(src_exports, {
15462
+ MerkleTree: () => import_merkletreejs.MerkleTree,
15463
+ compareAddresses: () => compareAddresses,
15462
15464
  makeOneSigTree: () => makeOneSigTree,
15463
15465
  mergeOneSigSignatures: () => mergeOneSigSignatures,
15464
15466
  signOneSigTree: () => signOneSigTree
@@ -33944,12 +33946,6 @@ var Reader2 = class _Reader {
33944
33946
  }
33945
33947
  };
33946
33948
 
33947
- // ../../node_modules/.pnpm/@ethersproject+keccak256@5.7.0/node_modules/@ethersproject/keccak256/lib.esm/index.js
33948
- var import_js_sha32 = __toESM(require_sha3());
33949
- function keccak2562(data) {
33950
- return "0x" + import_js_sha32.default.keccak_256(arrayify2(data));
33951
- }
33952
-
33953
33949
  // ../../node_modules/.pnpm/@ethersproject+rlp@5.7.0/node_modules/@ethersproject/rlp/lib.esm/index.js
33954
33950
  var lib_exports4 = {};
33955
33951
  __export(lib_exports4, {
@@ -34085,7 +34081,7 @@ function getChecksumAddress2(address) {
34085
34081
  for (let i = 0; i < 40; i++) {
34086
34082
  expanded[i] = chars[i].charCodeAt(0);
34087
34083
  }
34088
- const hashed = arrayify2(keccak2562(expanded));
34084
+ const hashed = arrayify2(keccak256(expanded));
34089
34085
  for (let i = 0; i < 40; i += 2) {
34090
34086
  if (hashed[i >> 1] >> 4 >= 8) {
34091
34087
  chars[i] = chars[i].toUpperCase();
@@ -34177,7 +34173,7 @@ function getContractAddress2(transaction) {
34177
34173
  logger54.throwArgumentError("missing from address", "transaction", transaction);
34178
34174
  }
34179
34175
  const nonce = stripZeros2(arrayify2(BigNumber2.from(transaction.nonce).toHexString()));
34180
- return getAddress2(hexDataSlice2(keccak2562(encode4([from, nonce])), 12));
34176
+ return getAddress2(hexDataSlice2(keccak256(encode4([from, nonce])), 12));
34181
34177
  }
34182
34178
  function getCreate2Address(from, salt, initCodeHash) {
34183
34179
  if (hexDataLength2(salt) !== 32) {
@@ -34186,7 +34182,7 @@ function getCreate2Address(from, salt, initCodeHash) {
34186
34182
  if (hexDataLength2(initCodeHash) !== 32) {
34187
34183
  logger54.throwArgumentError("initCodeHash must be 32 bytes", "initCodeHash", initCodeHash);
34188
34184
  }
34189
- return getAddress2(hexDataSlice2(keccak2562(concat2(["0xff", getAddress2(from), salt, initCodeHash])), 12));
34185
+ return getAddress2(hexDataSlice2(keccak256(concat2(["0xff", getAddress2(from), salt, initCodeHash])), 12));
34190
34186
  }
34191
34187
 
34192
34188
  // ../../node_modules/.pnpm/@ethersproject+abi@5.7.0/node_modules/@ethersproject/abi/lib.esm/coders/address.js
@@ -35427,7 +35423,7 @@ var Interface2 = class {
35427
35423
  if (param.type === "string") {
35428
35424
  return id2(value);
35429
35425
  } else if (param.type === "bytes") {
35430
- return keccak2562(hexlify2(value));
35426
+ return keccak256(hexlify2(value));
35431
35427
  }
35432
35428
  if (param.type === "bool" && typeof value === "boolean") {
35433
35429
  value = value ? "0x01" : "0x00";
@@ -35482,7 +35478,7 @@ var Interface2 = class {
35482
35478
  if (param.type === "string") {
35483
35479
  topics.push(id2(value));
35484
35480
  } else if (param.type === "bytes") {
35485
- topics.push(keccak2562(value));
35481
+ topics.push(keccak256(value));
35486
35482
  } else if (param.baseType === "tuple" || param.baseType === "array") {
35487
35483
  throw new Error("not implemented");
35488
35484
  } else {
@@ -36064,6 +36060,12 @@ function getJsonWalletAddress2(json) {
36064
36060
  return null;
36065
36061
  }
36066
36062
 
36063
+ // ../../node_modules/.pnpm/@ethersproject+keccak256@5.7.0/node_modules/@ethersproject/keccak256/lib.esm/index.js
36064
+ var import_js_sha32 = __toESM(require_sha3());
36065
+ function keccak2562(data) {
36066
+ return "0x" + import_js_sha32.default.keccak_256(arrayify2(data));
36067
+ }
36068
+
36067
36069
  // ../../node_modules/.pnpm/@ethersproject+sha2@5.7.0/node_modules/@ethersproject/sha2/lib.esm/sha2.js
36068
36070
  var import_hash10 = __toESM(require_hash());
36069
36071
 
@@ -36177,7 +36179,7 @@ function pack3(types, values) {
36177
36179
  return hexlify2(concat2(tight));
36178
36180
  }
36179
36181
  function keccak2563(types, values) {
36180
- return keccak2562(pack3(types, values));
36182
+ return keccak256(pack3(types, values));
36181
36183
  }
36182
36184
  function sha2563(types, values) {
36183
36185
  return sha2562(pack3(types, values));
@@ -38233,7 +38235,7 @@ var allowedTransactionKeys6 = {
38233
38235
  };
38234
38236
  function computeAddress2(key3) {
38235
38237
  const publicKey = computePublicKey2(key3);
38236
- return getAddress2(hexDataSlice2(keccak2562(hexDataSlice2(publicKey, 1)), 12));
38238
+ return getAddress2(hexDataSlice2(keccak256(hexDataSlice2(publicKey, 1)), 12));
38237
38239
  }
38238
38240
  function recoverAddress2(digest, signature3) {
38239
38241
  return computeAddress2(recoverPublicKey2(arrayify2(digest), signature3));
@@ -38419,7 +38421,7 @@ function _parseEipSignature2(tx, fields, serialize4) {
38419
38421
  tx.r = hexZeroPad2(fields[1], 32);
38420
38422
  tx.s = hexZeroPad2(fields[2], 32);
38421
38423
  try {
38422
- const digest = keccak2562(serialize4(tx));
38424
+ const digest = keccak256(serialize4(tx));
38423
38425
  tx.from = recoverAddress2(digest, { r: tx.r, s: tx.s, recoveryParam: tx.v });
38424
38426
  } catch (error) {
38425
38427
  }
@@ -38447,7 +38449,7 @@ function _parseEip15592(payload) {
38447
38449
  if (transaction.length === 9) {
38448
38450
  return tx;
38449
38451
  }
38450
- tx.hash = keccak2562(payload);
38452
+ tx.hash = keccak256(payload);
38451
38453
  _parseEipSignature2(tx, transaction.slice(9), _serializeEip15592);
38452
38454
  return tx;
38453
38455
  }
@@ -38470,7 +38472,7 @@ function _parseEip29302(payload) {
38470
38472
  if (transaction.length === 8) {
38471
38473
  return tx;
38472
38474
  }
38473
- tx.hash = keccak2562(payload);
38475
+ tx.hash = keccak256(payload);
38474
38476
  _parseEipSignature2(tx, transaction.slice(8), _serializeEip29302);
38475
38477
  return tx;
38476
38478
  }
@@ -38514,12 +38516,12 @@ function _parse2(rawTransaction) {
38514
38516
  raw.push("0x");
38515
38517
  recoveryParam -= tx.chainId * 2 + 8;
38516
38518
  }
38517
- const digest = keccak2562(encode4(raw));
38519
+ const digest = keccak256(encode4(raw));
38518
38520
  try {
38519
38521
  tx.from = recoverAddress2(digest, { r: hexlify2(tx.r), s: hexlify2(tx.s), recoveryParam });
38520
38522
  } catch (error) {
38521
38523
  }
38522
- tx.hash = keccak2562(rawTransaction);
38524
+ tx.hash = keccak256(rawTransaction);
38523
38525
  }
38524
38526
  tx.type = null;
38525
38527
  return tx;
@@ -39117,6 +39119,17 @@ function makeOneSigTree(input) {
39117
39119
  const tree = new import_merkletreejs.MerkleTree(leaves, ethers_exports.utils.keccak256, { sortPairs: true });
39118
39120
  return tree;
39119
39121
  }
39122
+ function compareAddresses(a, b) {
39123
+ const aNumeric = BigInt(a);
39124
+ const bNumeric = BigInt(b);
39125
+ if (aNumeric === bNumeric) {
39126
+ return 0;
39127
+ } else if (aNumeric < bNumeric) {
39128
+ return -1;
39129
+ } else {
39130
+ return 1;
39131
+ }
39132
+ }
39120
39133
  async function mergeOneSigSignatures(signatures) {
39121
39134
  const signaturesWithoutStart = signatures.map(function(signature3) {
39122
39135
  return signature3.replace("0x", "");
@@ -39160,6 +39173,8 @@ async function signOneSigTree(tree, _signers, { seed, expiry }) {
39160
39173
  }
39161
39174
  // Annotate the CommonJS export names for ESM import in node:
39162
39175
  0 && (module.exports = {
39176
+ MerkleTree,
39177
+ compareAddresses,
39163
39178
  makeOneSigTree,
39164
39179
  mergeOneSigSignatures,
39165
39180
  signOneSigTree
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layerzerolabs/onesig-core",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": {