Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53,345 changes: 37,722 additions & 15,623 deletions package-lock.json

Large diffs are not rendered by default.

71 changes: 36 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@loopring-web/loopring-sdk",
"version": "3.3.29-1",
"version": "3.3.37",
"author": "Loopring Dev Team",
"description": "Loopring SDK",
"license": "SEE LICENSE IN LICENSE",
Expand All @@ -11,25 +11,26 @@
"dist"
],
"dependencies": {
"@ethereumjs/common": "^2.4.0",
"@ethereumjs/tx": "^3.3.0",
"@ethersproject/bignumber": "5.7.0",
"@ethereumjs/common": "^3.2.0",
"@ethereumjs/tx": "^4.2.0",
"@types/jsbn": "^1.2.30",
"axios": "^0.21.1",
"bignumber.js": "^9.0.1",
"axios": "^1.4.0",
"bignumber.js": "^9.1.1",
"blake-hash": "^2.0.0",
"blake2b": "^2.1.3",
"bn.js": "^5.1.3",
"bn.js": "^5.2.1",
"buffer": "^6.0.3",
"crypto-js": "^4.0.0",
"eth-sig-util": "2.3.0",
"@metamask/eth-sig-util": "^5.1.0",
"ethereumjs-abi": "0.6.8",
"ethereumjs-util": "5.2.0",
"ethers": "^5.6.2",
"ethereumjs-util": "^7.1.5",
"ethers": "^6.6.1",
"js-sha3": "^0.8.0",
"js-sha512": "^0.8.0",
"jsbn": "^1.1.0",
"web-encoding": "^1.1.5",
"web3": "1.8.0"
"web3": "^4.0.1"
},
"build": {
"files": [
Expand Down Expand Up @@ -74,46 +75,46 @@
"**/*": "prettier --write --ignore-unknown"
},
"devDependencies": {
"@babel/plugin-transform-typescript": "^7.14.6",
"@babel/preset-env": "^7.14.5",
"@babel/preset-typescript": "^7.14.5",
"@microsoft/tsdoc": "^0.13.2",
"@babel/plugin-transform-typescript": "^7.22.5",
"@babel/preset-env": "^7.22.5",
"@babel/preset-typescript": "^7.22.5",
"@microsoft/tsdoc": "^0.14.2",
"@types/bignumber.js": "^5.0.0",
"@types/classnames": "^2.2.11",
"@types/collections": "^5.1.2",
"@types/crypto-js": "^4.0.1",
"@types/eth-sig-util": "^2.1.0",
"@types/ethereumjs-abi": "^0.6.3",
"@types/ethereumjs-tx": "^2.0.0",
"@types/ethereumjs-util": "5.2.0",
"@types/jest": "^26.0.23",
"@types/lodash": "^4.14.168",
"@types/mocha": "^8.2.2",
"@types/ethereumjs-util": "^6.1.0",
"@types/jest": "^29.5.2",
"@types/lodash": "^4.14.195",
"@types/mocha": "^10.0.1",
"@types/ms": "^0.7.31",
"@types/node": "^12.0.0",
"@types/node": "^20.3.1",
"@types/node-fetch": "^3.0.3",
"@types/request": "^2.48.6",
"@types/request-promise": "^4.1.48",
"@typescript-eslint/eslint-plugin": "^4.6.0",
"@typescript-eslint/parser": "^4.6.0",
"async": "^3.2.0",
"babel-jest": "^26.6.3",
"babel-plugin-import": "^1.13.3",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"async": "^3.2.4",
"babel-jest": "^29.5.0",
"babel-plugin-import": "^1.13.6",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-env": "^1.7.0",
"chai": "^4.3.4",
"gh-pages": "^3.2.3",
"honkit": "^3.6.20",
"jest": "^26.6.3",
"mocha": "^8.3.2",
"prettier": "2.5.1",
"chai": "^4.3.7",
"gh-pages": "^5.0.0",
"honkit": "^4.0.7",
"jest": "^29.5.0",
"mocha": "^10.2.0",
"prettier": "^2.8.8",
"request-promise": "^4.2.6",
"truffle-privatekey-provider": "1.5.0",
"ts-node": "^10.0.0",
"ts-node": "^10.9.1",
"tsdx": "^0.14.1",
"tslib": "^2.3.0",
"typedoc": "^0.22.9",
"typedoc-plugin-markdown": "^3.11.7",
"typescript": "^4.1.2"
"tslib": "^2.5.3",
"typedoc": "^0.24.8",
"typedoc-plugin-markdown": "^3.15.3",
"typescript": "^5.1.3"
}
}
6 changes: 2 additions & 4 deletions src/api/base_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { myLog } from "../utils/log_tools";
import ABI from "./ethereum/contracts";
import { AxiosResponse } from "axios";
import * as ethUtil from "ethereumjs-util";
import { Contract } from "ethers";
import { isContract } from "./contract_api";
// import contractWalletAbi from "../../config/abis/contractWallet.json";

Expand All @@ -42,8 +41,7 @@ export class BaseAPI {
...err,
msg: ConnectorError.HTTP_ERROR,
code: LoopringErrorCode.HTTP_ERROR,
};
err?.message;
} as RESULT_INFO;
} else if (!err || !err?.message) {
return {
message: "unKnown",
Expand All @@ -61,7 +59,7 @@ export class BaseAPI {
...err,
message: key as keyof typeof ConnectorError,
code: LoopringErrorCode[key as keyof typeof ConnectorError],
};
} as RESULT_INFO;
}
return {
...(err instanceof Error
Expand Down
87 changes: 48 additions & 39 deletions src/api/sign/poseidon/EDDSAUtil.ts
Original file line number Diff line number Diff line change
@@ -1,81 +1,90 @@
import { BigNumber } from "ethers";
import { SignatureScheme } from "./eddsa";
import { FQ } from "./field";
import { jubjub } from "./jubjub";
import { babyJub } from "./babyJub";
import { toHex } from "../../../utils";

/**
* BigNumber -> BigInt
* BigNumber.from() -> BigInt() or \dn
* div -> /
* sub -> -
* gt -> >
* lt -> <
* gte -> >=
* eq -> ==
* and -> &&=
*/
export class EDDSAUtil {

static sign(PrivateKey: string | undefined, hash: any) {
const strKey = BigNumber.from(PrivateKey)
const msg = BigNumber.from(hash)
const strKey = BigInt(PrivateKey ?? "");
const msg = BigInt(hash);

// console.log("strKey", strKey.toString())
// console.log("msg", msg.toString())
const copyKey = new FQ(strKey)
const B = SignatureScheme.B()
const signed = SignatureScheme.sign(msg, copyKey, B)
const copyKey = new FQ(strKey);
const B = SignatureScheme.B();
const signed = SignatureScheme.sign(msg, copyKey, B);
// console.log("signed", signed.toStr())
const x = EDDSAUtil.formatted(signed.sig.R.x.n.toHexString().slice(2))
const y = EDDSAUtil.formatted(signed.sig.R.y.n.toHexString().slice(2))
const s = EDDSAUtil.formatted(signed.sig.s.n.toHexString().slice(2))
const result = `0x${x}${y}${s}`
const x = EDDSAUtil.formatted(toHex(signed.sig.R.x.n).slice(2));
const y = EDDSAUtil.formatted(toHex(signed.sig.R.y.n).slice(2));
const s = EDDSAUtil.formatted(toHex(signed.sig.s.n).slice(2));
const result = `0x${x}${y}${s}`;
// console.log("result", result)
return {
"Rx": signed.sig.R.x.n.toString(),
"Ry": signed.sig.R.y.n.toString(),
"s": signed.sig.s.n.toString()
}
Rx: signed.sig.R.x.n.toString(),
Ry: signed.sig.R.y.n.toString(),
s: signed.sig.s.n.toString(),
};
}

static formatted(hexString: string) {
const outputLength = 32 * 2
const more = outputLength - hexString.length
const outputLength = 32 * 2;
const more = outputLength - hexString.length;
if (more > 0) {
for (let i = 0; i < more; i++) {
hexString = "0" + (hexString)
hexString = "0" + hexString;
}
} else {
hexString = hexString.slice(0, outputLength)
hexString = hexString.slice(0, outputLength);
}
return hexString
return hexString;
}

static generateKeyPair(seed: any) {
let bigInt = BigNumber.from(0)
let bigInt = BigInt(0);
for (let i = 0; i < seed.length; i++) {
const item = seed[i]
const itemBigInt = BigNumber.from(item)
const tmp = BigNumber.from("256").pow(BigNumber.from(i))
bigInt = bigInt.add(itemBigInt.mul(tmp))
const item = seed[i];
const itemBigInt = BigInt(item);
const tmp = 256 ** BigInt(i);
bigInt = bigInt + itemBigInt * tmp;
}
// console.log("sum", bigInt.toString())
const secretKey = bigInt.mod(jubjub.JUBJUB_L)
const secretKey = bigInt % jubjub.JUBJUB_L;
// console.log("secretKey", secretKey.toString())

const copySecretKey = BigNumber.from(secretKey.toString())
const copySecretKey = BigInt(secretKey.toString());
// console.log("copySecretKey", copySecretKey.toString())

const B = SignatureScheme.B()
const B = SignatureScheme.B();
// console.log("B", B.toString())

const publicKey = B.mul(copySecretKey)
const publicKey = B.mul(copySecretKey);
// console.log("publicKey", publicKey.x.n.toString(), publicKey.y.n.toString())

const keyPair = {
"publicKeyX": publicKey.x.n.toString(),
"publicKeyY": publicKey.y.n.toString(),
"secretKey": secretKey.toString()
}
publicKeyX: publicKey.x.n.toString(),
publicKeyY: publicKey.y.n.toString(),
secretKey: secretKey.toString(),
};

return keyPair
return keyPair;
}

static pack(publicKeyX: string, publicKeyY: string) {
const P0 = BigNumber.from(publicKeyX)
const P1 = BigNumber.from(publicKeyY)
const newPack = babyJub.packPoint(P0, P1)
return newPack
const P0 = BigInt(publicKeyX);
const P1 = BigInt(publicKeyY);
const newPack = babyJub.packPoint(P0, P1);
return newPack;
}

}
Loading